feat: refactor sales invoice services and introduce pagination and filtering
- Added SharedSaleInvoicePaginationService for handling pagination logic. - Introduced SharedSaleInvoiceFilterService to centralize filtering logic for sales invoices. - Updated SalesInvoicesService to utilize the new pagination and filtering services. - Refactored findAll methods in SalesInvoicesService, CustomerSaleInvoicesService, and other related services to support pagination and filtering. - Enhanced DTOs for sales invoice filtering to extend shared filter properties. - Updated module imports to include new services. - Cleaned up redundant code related to filtering and pagination across various services.
This commit is contained in:
@@ -13,6 +13,8 @@ export const summarySelect: SalesInvoiceSelect = {
|
|||||||
created_at: true,
|
created_at: true,
|
||||||
settlement_type: true,
|
settlement_type: true,
|
||||||
unknown_customer: true,
|
unknown_customer: true,
|
||||||
|
last_attempt_no: true,
|
||||||
|
last_tsp_status: true,
|
||||||
customer: {
|
customer: {
|
||||||
select: {
|
select: {
|
||||||
type: true,
|
type: true,
|
||||||
@@ -36,17 +38,6 @@ export const summarySelect: SalesInvoiceSelect = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
tsp_attempts: {
|
|
||||||
orderBy: {
|
|
||||||
created_at: 'desc',
|
|
||||||
},
|
|
||||||
take: 1,
|
|
||||||
select: {
|
|
||||||
status: true,
|
|
||||||
sent_at: true,
|
|
||||||
message: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
reference_invoice: {
|
reference_invoice: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
@@ -61,6 +52,7 @@ export const select: SalesInvoiceSelect = {
|
|||||||
tax_amount: true,
|
tax_amount: true,
|
||||||
updated_at: true,
|
updated_at: true,
|
||||||
unknown_customer: true,
|
unknown_customer: true,
|
||||||
|
|
||||||
pos: {
|
pos: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
@@ -133,19 +125,4 @@ export const select: SalesInvoiceSelect = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
tsp_attempts: {
|
|
||||||
orderBy: {
|
|
||||||
created_at: 'desc',
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
attempt_no: true,
|
|
||||||
status: true,
|
|
||||||
message: true,
|
|
||||||
sent_at: true,
|
|
||||||
received_at: true,
|
|
||||||
created_at: true,
|
|
||||||
},
|
|
||||||
take: 1,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
import { ApiPropertyOptional } from '@nestjs/swagger'
|
||||||
|
import { Type } from 'class-transformer'
|
||||||
|
import {
|
||||||
|
IsDateString,
|
||||||
|
IsEnum,
|
||||||
|
IsNumber,
|
||||||
|
IsOptional,
|
||||||
|
IsString,
|
||||||
|
Min,
|
||||||
|
} from 'class-validator'
|
||||||
|
import { TspProviderResponseStatus } from 'generated/prisma/enums'
|
||||||
|
|
||||||
|
export class SharedSaleInvoicesFilterDto {
|
||||||
|
@ApiPropertyOptional({ default: 1 })
|
||||||
|
@IsOptional()
|
||||||
|
@Type(() => Number)
|
||||||
|
@IsNumber()
|
||||||
|
@Min(1)
|
||||||
|
page?: number
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ default: 10 })
|
||||||
|
@IsOptional()
|
||||||
|
@Type(() => Number)
|
||||||
|
@IsNumber()
|
||||||
|
@Min(1)
|
||||||
|
perPage?: number
|
||||||
|
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
@IsOptional()
|
||||||
|
@IsDateString()
|
||||||
|
invoice_date_from?: string
|
||||||
|
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
@IsOptional()
|
||||||
|
@IsDateString()
|
||||||
|
invoice_date_to?: string
|
||||||
|
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
@IsOptional()
|
||||||
|
@IsDateString()
|
||||||
|
created_at_from?: string
|
||||||
|
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
@IsOptional()
|
||||||
|
@IsDateString()
|
||||||
|
created_at_to?: string
|
||||||
|
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
customer_name?: string
|
||||||
|
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
customer_mobile?: string
|
||||||
|
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
customer_national_id?: string
|
||||||
|
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
customer_economic_code?: string
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ enum: TspProviderResponseStatus })
|
||||||
|
@IsOptional()
|
||||||
|
@IsEnum(TspProviderResponseStatus)
|
||||||
|
status?: TspProviderResponseStatus
|
||||||
|
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
@IsOptional()
|
||||||
|
@Type(() => Number)
|
||||||
|
@IsNumber()
|
||||||
|
total_amount?: number
|
||||||
|
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
@IsOptional()
|
||||||
|
@Type(() => Number)
|
||||||
|
@IsNumber()
|
||||||
|
total_amount_from?: number
|
||||||
|
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
@IsOptional()
|
||||||
|
@Type(() => Number)
|
||||||
|
@IsNumber()
|
||||||
|
total_amount_to?: number
|
||||||
|
}
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
import { TspProviderResponseStatus } from '@/generated/prisma/enums'
|
||||||
|
import { SalesInvoiceWhereInput } from '@/generated/prisma/models'
|
||||||
|
import { Injectable } from '@nestjs/common'
|
||||||
|
import { SharedSaleInvoicesFilterDto } from './sale-invoice-filter.dto'
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class SharedSaleInvoiceFilterService {
|
||||||
|
buildWhere(filter: SharedSaleInvoicesFilterDto): SalesInvoiceWhereInput {
|
||||||
|
const where: SalesInvoiceWhereInput = {}
|
||||||
|
|
||||||
|
if (filter.invoice_date_from || filter.invoice_date_to) {
|
||||||
|
where.invoice_date = {
|
||||||
|
...(filter.invoice_date_from ? { gte: new Date(filter.invoice_date_from) } : {}),
|
||||||
|
...(filter.invoice_date_to ? { lte: new Date(filter.invoice_date_to) } : {}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.created_at_from || filter.created_at_to) {
|
||||||
|
where.created_at = {
|
||||||
|
...(filter.created_at_from ? { gte: new Date(filter.created_at_from) } : {}),
|
||||||
|
...(filter.created_at_to ? { lte: new Date(filter.created_at_to) } : {}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
filter.total_amount !== undefined ||
|
||||||
|
filter.total_amount_from !== undefined ||
|
||||||
|
filter.total_amount_to !== undefined
|
||||||
|
) {
|
||||||
|
where.total_amount = {
|
||||||
|
...(filter.total_amount !== undefined ? { equals: filter.total_amount } : {}),
|
||||||
|
...(filter.total_amount_from !== undefined
|
||||||
|
? { gte: filter.total_amount_from }
|
||||||
|
: {}),
|
||||||
|
...(filter.total_amount_to !== undefined ? { lte: filter.total_amount_to } : {}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
filter.customer_name?.trim() ||
|
||||||
|
filter.customer_mobile?.trim() ||
|
||||||
|
filter.customer_national_id?.trim() ||
|
||||||
|
filter.customer_economic_code?.trim()
|
||||||
|
) {
|
||||||
|
where.customer = {
|
||||||
|
is: {
|
||||||
|
OR: [
|
||||||
|
...(filter.customer_name?.trim()
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
individual: {
|
||||||
|
is: {
|
||||||
|
OR: [
|
||||||
|
{ first_name: { contains: filter.customer_name.trim() } },
|
||||||
|
{ last_name: { contains: filter.customer_name.trim() } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
legal: {
|
||||||
|
is: {
|
||||||
|
name: {
|
||||||
|
contains: filter.customer_name.trim(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: []),
|
||||||
|
...(filter.customer_mobile?.trim()
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
individual: {
|
||||||
|
is: {
|
||||||
|
mobile_number: { contains: filter.customer_mobile.trim() },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: []),
|
||||||
|
...(filter.customer_national_id?.trim()
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
individual: {
|
||||||
|
is: {
|
||||||
|
national_id: { contains: filter.customer_national_id.trim() },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: []),
|
||||||
|
...(filter.customer_economic_code?.trim()
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
legal: {
|
||||||
|
is: {
|
||||||
|
OR: [
|
||||||
|
{
|
||||||
|
economic_code: {
|
||||||
|
contains: filter.customer_economic_code.trim(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
registration_number: {
|
||||||
|
contains: filter.customer_economic_code.trim(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: []),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.status) {
|
||||||
|
if (filter.status === TspProviderResponseStatus.NOT_SEND) {
|
||||||
|
where.OR = [
|
||||||
|
{
|
||||||
|
last_tsp_status: null,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
last_tsp_status: TspProviderResponseStatus.NOT_SEND,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
} else {
|
||||||
|
where.last_tsp_status = filter.status
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return where
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { Injectable } from '@nestjs/common'
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class SharedSaleInvoicePaginationService {
|
||||||
|
normalize(
|
||||||
|
page: number = 1,
|
||||||
|
perPage: number = 10,
|
||||||
|
defaultPerPage: number = 10,
|
||||||
|
maxPerPage: number = 50,
|
||||||
|
) {
|
||||||
|
const normalizedPageValue = Number(page ?? 1)
|
||||||
|
const normalizedPage = Number.isFinite(normalizedPageValue)
|
||||||
|
? Math.max(1, Math.floor(normalizedPageValue))
|
||||||
|
: 1
|
||||||
|
|
||||||
|
const requestedPerPageValue = Number(perPage ?? defaultPerPage)
|
||||||
|
const requestedPerPage = Number.isFinite(requestedPerPageValue)
|
||||||
|
? Math.max(1, Math.floor(requestedPerPageValue))
|
||||||
|
: defaultPerPage
|
||||||
|
const normalizedPerPage = Math.min(requestedPerPage, maxPerPage)
|
||||||
|
|
||||||
|
return {
|
||||||
|
page: normalizedPage,
|
||||||
|
perPage: normalizedPerPage,
|
||||||
|
skip: (normalizedPage - 1) * normalizedPerPage,
|
||||||
|
take: normalizedPerPage,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -71,7 +71,7 @@ export class BusinessActivitiesService {
|
|||||||
|
|
||||||
async findOne(consumer_id: string, id: string) {
|
async findOne(consumer_id: string, id: string) {
|
||||||
const cacheKey = RedisKeyMaker.consumerBusinessActivityInfo(consumer_id, id)
|
const cacheKey = RedisKeyMaker.consumerBusinessActivityInfo(consumer_id, id)
|
||||||
return await this.redisService.getAndSet(cacheKey, 'list', async () => {
|
return await this.redisService.getAndSet(cacheKey, 'single', async () => {
|
||||||
return await this.businessActivitiesQueryService.findOneByConsumer(
|
return await this.businessActivitiesQueryService.findOneByConsumer(
|
||||||
consumer_id,
|
consumer_id,
|
||||||
id,
|
id,
|
||||||
|
|||||||
+4
-2
@@ -1,4 +1,4 @@
|
|||||||
import { Controller, Get, Param, Post } from '@nestjs/common'
|
import { Controller, Get, Param, Post, Query } from '@nestjs/common'
|
||||||
|
|
||||||
import { TokenAccount } from '@/common/decorators/tokenInfo.decorator'
|
import { TokenAccount } from '@/common/decorators/tokenInfo.decorator'
|
||||||
import { ApiTags } from '@nestjs/swagger'
|
import { ApiTags } from '@nestjs/swagger'
|
||||||
@@ -14,8 +14,10 @@ export class SalesInvoicesController {
|
|||||||
@TokenAccount('userId') userId: string,
|
@TokenAccount('userId') userId: string,
|
||||||
@Param('complexId') complexId: string,
|
@Param('complexId') complexId: string,
|
||||||
@Param('posId') posId: string,
|
@Param('posId') posId: string,
|
||||||
|
@Query('page') page: number,
|
||||||
|
@Query('perPage') perPage: number,
|
||||||
) {
|
) {
|
||||||
return this.salesInvoicesService.findAll(userId, complexId, posId)
|
return this.salesInvoicesService.findAll(userId, complexId, posId, page, perPage)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
|
|||||||
+3
-1
@@ -1,5 +1,6 @@
|
|||||||
import { SharedSaleInvoiceActionsService } from '@/common/services/saleInvoices/sale-invoice-actions.service'
|
|
||||||
import { SharedSaleInvoiceAccessService } from '@/common/services/saleInvoices/sale-invoice-access.service'
|
import { SharedSaleInvoiceAccessService } from '@/common/services/saleInvoices/sale-invoice-access.service'
|
||||||
|
import { SharedSaleInvoiceActionsService } from '@/common/services/saleInvoices/sale-invoice-actions.service'
|
||||||
|
import { SharedSaleInvoicePaginationService } from '@/common/services/saleInvoices/sale-invoice-pagination.service'
|
||||||
import { SaleInvoiceTspModule } from '@/modules/tspProviders/sales-invoice-tsp.module'
|
import { SaleInvoiceTspModule } from '@/modules/tspProviders/sales-invoice-tsp.module'
|
||||||
import { Module } from '@nestjs/common'
|
import { Module } from '@nestjs/common'
|
||||||
import { SalesInvoicesController } from './sales-invoices.controller'
|
import { SalesInvoicesController } from './sales-invoices.controller'
|
||||||
@@ -12,6 +13,7 @@ import { SalesInvoicesService } from './sales-invoices.service'
|
|||||||
SalesInvoicesService,
|
SalesInvoicesService,
|
||||||
SharedSaleInvoiceActionsService,
|
SharedSaleInvoiceActionsService,
|
||||||
SharedSaleInvoiceAccessService,
|
SharedSaleInvoiceAccessService,
|
||||||
|
SharedSaleInvoicePaginationService,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class ConsumerPosSalesInvoicesModule {}
|
export class ConsumerPosSalesInvoicesModule {}
|
||||||
|
|||||||
+37
-81
@@ -1,5 +1,8 @@
|
|||||||
|
import { QUERY_CONSTANTS } from '@/common/queryConstants'
|
||||||
import { ResponseMapper } from '@/common/response/response-mapper'
|
import { ResponseMapper } from '@/common/response/response-mapper'
|
||||||
import { SharedSaleInvoiceActionsService } from '@/common/services/saleInvoices/sale-invoice-actions.service'
|
import { SharedSaleInvoiceActionsService } from '@/common/services/saleInvoices/sale-invoice-actions.service'
|
||||||
|
import { SharedSaleInvoicePaginationService } from '@/common/services/saleInvoices/sale-invoice-pagination.service'
|
||||||
|
import { translateEnumValue } from '@/common/utils'
|
||||||
import { SalesInvoiceWhereInput } from '@/generated/prisma/models'
|
import { SalesInvoiceWhereInput } from '@/generated/prisma/models'
|
||||||
import { PrismaService } from '@/prisma/prisma.service'
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
import { Injectable, NotFoundException } from '@nestjs/common'
|
import { Injectable, NotFoundException } from '@nestjs/common'
|
||||||
@@ -9,9 +12,19 @@ export class SalesInvoicesService {
|
|||||||
constructor(
|
constructor(
|
||||||
private prisma: PrismaService,
|
private prisma: PrismaService,
|
||||||
private readonly sharedSaleInvoiceActionsService: SharedSaleInvoiceActionsService,
|
private readonly sharedSaleInvoiceActionsService: SharedSaleInvoiceActionsService,
|
||||||
|
private readonly sharedSaleInvoicePaginationService: SharedSaleInvoicePaginationService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async findAll(consumer_id: string, complex_id: string, pos_id: string) {
|
async findAll(
|
||||||
|
consumer_id: string,
|
||||||
|
complex_id: string,
|
||||||
|
pos_id: string,
|
||||||
|
requestedPage: number = 1,
|
||||||
|
requestedPerPage: number = 10,
|
||||||
|
) {
|
||||||
|
const { page, perPage, skip, take } =
|
||||||
|
this.sharedSaleInvoicePaginationService.normalize(requestedPage, requestedPerPage)
|
||||||
|
|
||||||
const defaultWhere: SalesInvoiceWhereInput = {
|
const defaultWhere: SalesInvoiceWhereInput = {
|
||||||
pos_id,
|
pos_id,
|
||||||
pos: {
|
pos: {
|
||||||
@@ -24,98 +37,41 @@ export class SalesInvoicesService {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const perPage = 10
|
const [saleInvoices, total] = await this.prisma.$transaction([
|
||||||
const page = 1
|
|
||||||
|
|
||||||
const [items, total] = await this.prisma.$transaction([
|
|
||||||
this.prisma.salesInvoice.findMany({
|
this.prisma.salesInvoice.findMany({
|
||||||
where: defaultWhere,
|
where: defaultWhere,
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
...QUERY_CONSTANTS.SALE_INVOICE.select,
|
||||||
code: true,
|
_count: {
|
||||||
invoice_date: true,
|
|
||||||
notes: true,
|
|
||||||
total_amount: true,
|
|
||||||
|
|
||||||
items: {
|
|
||||||
select: {
|
select: {
|
||||||
measure_unit_code: true,
|
items: true,
|
||||||
measure_unit_text: true,
|
|
||||||
sku_code: true,
|
|
||||||
discount_amount: true,
|
|
||||||
tax_amount: true,
|
|
||||||
notes: true,
|
|
||||||
quantity: true,
|
|
||||||
total_amount: true,
|
|
||||||
unit_price: true,
|
|
||||||
payload: true,
|
|
||||||
good: {
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
sku: {
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
barcode: true,
|
|
||||||
local_sku: true,
|
|
||||||
pricing_model: true,
|
|
||||||
measure_unit: {
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
category: {
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
payments: {
|
|
||||||
select: {
|
|
||||||
amount: true,
|
|
||||||
paid_at: true,
|
|
||||||
payment_method: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
customer: {
|
|
||||||
select: {
|
|
||||||
type: true,
|
|
||||||
individual: {
|
|
||||||
select: {
|
|
||||||
economic_code: true,
|
|
||||||
first_name: true,
|
|
||||||
last_name: true,
|
|
||||||
postal_code: true,
|
|
||||||
national_id: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
legal: {
|
|
||||||
select: {
|
|
||||||
economic_code: true,
|
|
||||||
postal_code: true,
|
|
||||||
registration_number: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
unknown_customer: true,
|
|
||||||
},
|
},
|
||||||
skip: (page - 1) * perPage,
|
orderBy: {
|
||||||
take: perPage,
|
created_at: 'desc',
|
||||||
|
},
|
||||||
|
skip,
|
||||||
|
take,
|
||||||
}),
|
}),
|
||||||
this.prisma.salesInvoice.count({
|
this.prisma.salesInvoice.count({
|
||||||
where: defaultWhere,
|
where: defaultWhere,
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
return ResponseMapper.paginate(items, { total, page, perPage })
|
const mappedAccounts = saleInvoices.map(saleInvoice => {
|
||||||
|
const { _count, consumer_account, last_tsp_status, ...rest } = saleInvoice
|
||||||
|
return {
|
||||||
|
...rest,
|
||||||
|
items_count: _count.items,
|
||||||
|
status: translateEnumValue('TspProviderResponseStatus', last_tsp_status),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return ResponseMapper.paginate(mappedAccounts, {
|
||||||
|
total,
|
||||||
|
page,
|
||||||
|
perPage,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
findOne(complex_id: string, pos_id: string, id: string) {
|
findOne(complex_id: string, pos_id: string, id: string) {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { SharedSaleInvoicePaginationService } from '@/common/services/saleInvoices/sale-invoice-pagination.service'
|
||||||
import { PrismaModule } from '@/prisma/prisma.module'
|
import { PrismaModule } from '@/prisma/prisma.module'
|
||||||
import { Module } from '@nestjs/common'
|
import { Module } from '@nestjs/common'
|
||||||
import { consumerCustomersController } from './customers.controller'
|
import { consumerCustomersController } from './customers.controller'
|
||||||
@@ -7,6 +8,6 @@ import { ConsumerSaleInvoicesModule } from './sale-invoices/sale-invoices.module
|
|||||||
@Module({
|
@Module({
|
||||||
imports: [PrismaModule, ConsumerSaleInvoicesModule],
|
imports: [PrismaModule, ConsumerSaleInvoicesModule],
|
||||||
controllers: [consumerCustomersController],
|
controllers: [consumerCustomersController],
|
||||||
providers: [consumerCustomersService],
|
providers: [consumerCustomersService, SharedSaleInvoicePaginationService],
|
||||||
})
|
})
|
||||||
export class ConsumerCustomersModule {}
|
export class ConsumerCustomersModule {}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { SharedSaleInvoicePaginationService } from '@/common/services/saleInvoices/sale-invoice-pagination.service'
|
||||||
import { CustomerSelect, CustomerWhereInput } from '@/generated/prisma/models'
|
import { CustomerSelect, CustomerWhereInput } from '@/generated/prisma/models'
|
||||||
import { PrismaService } from '@/prisma/prisma.service'
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
import { Injectable } from '@nestjs/common'
|
import { Injectable } from '@nestjs/common'
|
||||||
@@ -9,7 +10,10 @@ import {
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class consumerCustomersService {
|
export class consumerCustomersService {
|
||||||
constructor(private readonly prisma: PrismaService) {}
|
constructor(
|
||||||
|
private readonly prisma: PrismaService,
|
||||||
|
private readonly sharedSaleInvoicePaginationService: SharedSaleInvoicePaginationService,
|
||||||
|
) {}
|
||||||
|
|
||||||
defaultSelect: CustomerSelect = {
|
defaultSelect: CustomerSelect = {
|
||||||
id: true,
|
id: true,
|
||||||
@@ -56,13 +60,15 @@ export class consumerCustomersService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(consumer_id: string, page = 1, perPage = 10) {
|
async findAll(consumer_id: string, requestedPage = 1, requestedPerPage = 10) {
|
||||||
|
const { page, perPage, skip, take } =
|
||||||
|
this.sharedSaleInvoicePaginationService.normalize(requestedPage, requestedPerPage)
|
||||||
const [customers, total] = await this.prisma.$transaction(async tx => [
|
const [customers, total] = await this.prisma.$transaction(async tx => [
|
||||||
await tx.customer.findMany({
|
await tx.customer.findMany({
|
||||||
where: this.defaultWhere(consumer_id),
|
where: this.defaultWhere(consumer_id),
|
||||||
select: this.defaultSelect,
|
select: this.defaultSelect,
|
||||||
skip: (page - 1) * perPage,
|
skip,
|
||||||
take: 10,
|
take,
|
||||||
}),
|
}),
|
||||||
await tx.customer.count({
|
await tx.customer.count({
|
||||||
where: this.defaultWhere(consumer_id),
|
where: this.defaultWhere(consumer_id),
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { SharedSaleInvoicePaginationService } from '@/common/services/saleInvoices/sale-invoice-pagination.service'
|
||||||
import { PrismaModule } from '@/prisma/prisma.module'
|
import { PrismaModule } from '@/prisma/prisma.module'
|
||||||
import { Module } from '@nestjs/common'
|
import { Module } from '@nestjs/common'
|
||||||
import { CustomerSaleInvoicesController } from './sale-invoices.controller'
|
import { CustomerSaleInvoicesController } from './sale-invoices.controller'
|
||||||
@@ -6,6 +7,6 @@ import { CustomerSaleInvoicesService } from './sale-invoices.service'
|
|||||||
@Module({
|
@Module({
|
||||||
imports: [PrismaModule],
|
imports: [PrismaModule],
|
||||||
controllers: [CustomerSaleInvoicesController],
|
controllers: [CustomerSaleInvoicesController],
|
||||||
providers: [CustomerSaleInvoicesService],
|
providers: [CustomerSaleInvoicesService, SharedSaleInvoicePaginationService],
|
||||||
})
|
})
|
||||||
export class ConsumerSaleInvoicesModule {}
|
export class ConsumerSaleInvoicesModule {}
|
||||||
|
|||||||
@@ -1,57 +1,28 @@
|
|||||||
import { QUERY_CONSTANTS } from '@/common/queryConstants'
|
import { QUERY_CONSTANTS } from '@/common/queryConstants'
|
||||||
import consumer_mappersUtil from '@/common/utils/mappers/consumer_mappers.util'
|
import { SharedSaleInvoicePaginationService } from '@/common/services/saleInvoices/sale-invoice-pagination.service'
|
||||||
import { SalesInvoiceSelect, SalesInvoiceWhereInput } from '@/generated/prisma/models'
|
import { translateEnumValue } from '@/common/utils'
|
||||||
|
import { TspProviderResponseStatus } from '@/generated/prisma/enums'
|
||||||
|
import { SalesInvoiceWhereInput } from '@/generated/prisma/models'
|
||||||
import { PrismaService } from '@/prisma/prisma.service'
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
import { Injectable } from '@nestjs/common'
|
import { Injectable, NotFoundException } from '@nestjs/common'
|
||||||
import { ResponseMapper } from 'common/response/response-mapper'
|
import { ResponseMapper } from 'common/response/response-mapper'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CustomerSaleInvoicesService {
|
export class CustomerSaleInvoicesService {
|
||||||
constructor(private readonly prisma: PrismaService) {}
|
constructor(
|
||||||
|
private readonly prisma: PrismaService,
|
||||||
|
private readonly sharedSaleInvoicePaginationService: SharedSaleInvoicePaginationService,
|
||||||
|
) {}
|
||||||
|
|
||||||
private readonly defaultSelect: SalesInvoiceSelect = {
|
async findAll(
|
||||||
id: true,
|
consumer_id: string,
|
||||||
code: true,
|
customer_id: string,
|
||||||
invoice_date: true,
|
requestedPage = 1,
|
||||||
notes: true,
|
requestedPerPage = 10,
|
||||||
total_amount: true,
|
) {
|
||||||
pos: {
|
const { page, perPage, skip, take } =
|
||||||
select: {
|
this.sharedSaleInvoicePaginationService.normalize(requestedPage, requestedPerPage)
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
complex: {
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
business_activity: {
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
consumer_account: {
|
|
||||||
select: {
|
|
||||||
role: true,
|
|
||||||
consumer: {
|
|
||||||
select: {
|
|
||||||
...QUERY_CONSTANTS.CONSUMER.infoSelect,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
account: {
|
|
||||||
select: {
|
|
||||||
username: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
created_at: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
async findAll(consumer_id: string, customer_id: string, page = 1, perPage = 10) {
|
|
||||||
const salesWhere: SalesInvoiceWhereInput = {
|
const salesWhere: SalesInvoiceWhereInput = {
|
||||||
customer_id,
|
customer_id,
|
||||||
pos: {
|
pos: {
|
||||||
@@ -67,15 +38,30 @@ export class CustomerSaleInvoicesService {
|
|||||||
await tx.salesInvoice.findMany({
|
await tx.salesInvoice.findMany({
|
||||||
where: salesWhere,
|
where: salesWhere,
|
||||||
select: {
|
select: {
|
||||||
...this.defaultSelect,
|
...QUERY_CONSTANTS.SALE_INVOICE.summarySelect,
|
||||||
|
pos: {
|
||||||
|
select: {
|
||||||
|
name: true,
|
||||||
|
complex: {
|
||||||
|
select: {
|
||||||
|
name: true,
|
||||||
|
business_activity: {
|
||||||
|
select: {
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
_count: {
|
_count: {
|
||||||
select: {
|
select: {
|
||||||
items: true,
|
items: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
skip: (page - 1) * perPage,
|
skip,
|
||||||
take: 10,
|
take,
|
||||||
}),
|
}),
|
||||||
await tx.salesInvoice.count({
|
await tx.salesInvoice.count({
|
||||||
where: salesWhere,
|
where: salesWhere,
|
||||||
@@ -83,16 +69,11 @@ export class CustomerSaleInvoicesService {
|
|||||||
])
|
])
|
||||||
|
|
||||||
const mappedAccounts = saleInvoices.map(saleInvoice => {
|
const mappedAccounts = saleInvoices.map(saleInvoice => {
|
||||||
const { _count, consumer_account, ...rest } = saleInvoice
|
const { _count, consumer_account, last_tsp_status, ...rest } = saleInvoice
|
||||||
const { consumer, ...restConsumerAccount } = consumer_account as any
|
|
||||||
const mappedConsumer = consumer_mappersUtil(consumer)
|
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
items_count: _count.items,
|
items_count: _count.items,
|
||||||
consumer_account: {
|
status: translateEnumValue('TspProviderResponseStatus', last_tsp_status),
|
||||||
...restConsumerAccount,
|
|
||||||
consumer: mappedConsumer,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -104,7 +85,7 @@ export class CustomerSaleInvoicesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findOne(consumer_id: string, customer_id: string, id: string) {
|
async findOne(consumer_id: string, customer_id: string, id: string) {
|
||||||
const saleInvoice = await this.prisma.salesInvoice.findUniqueOrThrow({
|
const invoice = await this.prisma.salesInvoice.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id,
|
id,
|
||||||
customer_id,
|
customer_id,
|
||||||
@@ -117,59 +98,26 @@ export class CustomerSaleInvoicesService {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
...this.defaultSelect,
|
...QUERY_CONSTANTS.SALE_INVOICE.select,
|
||||||
items: {
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
notes: true,
|
|
||||||
unit_price: true,
|
|
||||||
quantity: true,
|
|
||||||
discount_amount: true,
|
|
||||||
tax_amount: true,
|
|
||||||
total_amount: true,
|
|
||||||
payload: true,
|
|
||||||
good: {
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
pricing_model: true,
|
|
||||||
measure_unit: {
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
category: {
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
image_url: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
payments: {
|
|
||||||
select: {
|
|
||||||
amount: true,
|
|
||||||
paid_at: true,
|
|
||||||
payment_method: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
const { _count, consumer_account, ...rest } = saleInvoice
|
|
||||||
const { consumer, ...restConsumerAccount } = consumer_account as any
|
|
||||||
const mappedConsumer = consumer_mappersUtil(consumer)
|
|
||||||
|
|
||||||
return ResponseMapper.single({
|
if (invoice) {
|
||||||
...rest,
|
const { type, ...rest } = invoice
|
||||||
items_count: _count.items,
|
const mappedInvoice = {
|
||||||
consumer_account: {
|
...rest,
|
||||||
...restConsumerAccount,
|
type: translateEnumValue('TspProviderRequestType', type),
|
||||||
consumer: mappedConsumer,
|
status: translateEnumValue(
|
||||||
},
|
'TspProviderResponseStatus',
|
||||||
})
|
invoice.last_tsp_status || TspProviderResponseStatus.NOT_SEND,
|
||||||
|
),
|
||||||
|
settlement_type: translateEnumValue(
|
||||||
|
'InvoiceSettlementType',
|
||||||
|
invoice.settlement_type,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
return ResponseMapper.single(mappedInvoice)
|
||||||
|
}
|
||||||
|
throw new NotFoundException('صورتحساب مورد نظر شما یافت نشد.')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { QUERY_CONSTANTS } from '@/common/queryConstants'
|
|||||||
import { PrismaService } from '@/prisma/prisma.service'
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
import { Injectable } from '@nestjs/common'
|
import { Injectable } from '@nestjs/common'
|
||||||
import { ResponseMapper } from 'common/response/response-mapper'
|
import { ResponseMapper } from 'common/response/response-mapper'
|
||||||
|
import { UpdateBusinessActivityDto } from './dto/poses.dto'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PosesService {
|
export class PosesService {
|
||||||
@@ -43,7 +44,7 @@ export class PosesService {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(consumer_id: string, id: string, data: any) {
|
async update(consumer_id: string, id: string, data: UpdateBusinessActivityDto) {
|
||||||
const pos = await this.prisma.pos.update({
|
const pos = await this.prisma.pos.update({
|
||||||
where: { ...this.defaultWhere(consumer_id), id },
|
where: { ...this.defaultWhere(consumer_id), id },
|
||||||
data,
|
data,
|
||||||
|
|||||||
@@ -1,95 +1,12 @@
|
|||||||
|
import { SharedSaleInvoicesFilterDto } from '@/common/services/saleInvoices/sale-invoice-filter.dto'
|
||||||
import { ApiPropertyOptional } from '@nestjs/swagger'
|
import { ApiPropertyOptional } from '@nestjs/swagger'
|
||||||
import { Type } from 'class-transformer'
|
import { Max } from 'class-validator'
|
||||||
import {
|
|
||||||
IsDateString,
|
|
||||||
IsEnum,
|
|
||||||
IsNumber,
|
|
||||||
IsOptional,
|
|
||||||
IsString,
|
|
||||||
Max,
|
|
||||||
Min,
|
|
||||||
} from 'class-validator'
|
|
||||||
import { TspProviderResponseStatus } from 'generated/prisma/enums'
|
|
||||||
|
|
||||||
export class ConsumerSaleInvoicesFilterDto {
|
|
||||||
@ApiPropertyOptional({ type: Number, example: 1 })
|
|
||||||
@Type(() => Number)
|
|
||||||
@Min(1)
|
|
||||||
@IsOptional()
|
|
||||||
page?: number
|
|
||||||
|
|
||||||
|
export class ConsumerSaleInvoicesFilterDto extends SharedSaleInvoicesFilterDto {
|
||||||
@ApiPropertyOptional({ type: Number, example: 10, description: 'Max value is 50.' })
|
@ApiPropertyOptional({ type: Number, example: 10, description: 'Max value is 50.' })
|
||||||
@Type(() => Number)
|
|
||||||
@Min(1)
|
|
||||||
@Max(50)
|
@Max(50)
|
||||||
@IsOptional()
|
declare perPage?: number
|
||||||
perPage?: number
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
@IsOptional()
|
|
||||||
@IsDateString()
|
|
||||||
invoice_date_from?: string
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@IsDateString()
|
|
||||||
invoice_date_to?: string
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@IsDateString()
|
|
||||||
created_at_from?: string
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@IsDateString()
|
|
||||||
created_at_to?: string
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
code?: string
|
code?: string
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
customer_name?: string
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
customer_mobile?: string
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
customer_national_id?: string
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
customer_economic_code?: string
|
|
||||||
|
|
||||||
@ApiPropertyOptional({ enum: TspProviderResponseStatus })
|
|
||||||
@IsOptional()
|
|
||||||
@IsEnum(TspProviderResponseStatus)
|
|
||||||
status?: TspProviderResponseStatus
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@Type(() => Number)
|
|
||||||
@IsNumber()
|
|
||||||
total_amount?: number
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@Type(() => Number)
|
|
||||||
@IsNumber()
|
|
||||||
total_amount_from?: number
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@Type(() => Number)
|
|
||||||
@IsNumber()
|
|
||||||
total_amount_to?: number
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { SharedSaleInvoiceActionsService } from '@/common/services/saleInvoices/sale-invoice-actions.service'
|
import { SharedSaleInvoiceActionsService } from '@/common/services/saleInvoices/sale-invoice-actions.service'
|
||||||
import { SharedSaleInvoiceAccessService } from '@/common/services/saleInvoices/sale-invoice-access.service'
|
import { SharedSaleInvoiceAccessService } from '@/common/services/saleInvoices/sale-invoice-access.service'
|
||||||
|
import { SharedSaleInvoiceFilterService } from '@/common/services/saleInvoices/sale-invoice-filter.service'
|
||||||
|
import { SharedSaleInvoicePaginationService } from '@/common/services/saleInvoices/sale-invoice-pagination.service'
|
||||||
import { SaleInvoiceTspModule } from '@/modules/tspProviders/sales-invoice-tsp.module'
|
import { SaleInvoiceTspModule } from '@/modules/tspProviders/sales-invoice-tsp.module'
|
||||||
import { PrismaModule } from '@/prisma/prisma.module'
|
import { PrismaModule } from '@/prisma/prisma.module'
|
||||||
import { Module } from '@nestjs/common'
|
import { Module } from '@nestjs/common'
|
||||||
@@ -9,7 +11,13 @@ import { SaleInvoicesService } from './saleInvoices.service'
|
|||||||
@Module({
|
@Module({
|
||||||
imports: [PrismaModule, SaleInvoiceTspModule],
|
imports: [PrismaModule, SaleInvoiceTspModule],
|
||||||
controllers: [StatisticsController],
|
controllers: [StatisticsController],
|
||||||
providers: [SaleInvoicesService, SharedSaleInvoiceActionsService, SharedSaleInvoiceAccessService],
|
providers: [
|
||||||
|
SaleInvoicesService,
|
||||||
|
SharedSaleInvoiceActionsService,
|
||||||
|
SharedSaleInvoiceAccessService,
|
||||||
|
SharedSaleInvoiceFilterService,
|
||||||
|
SharedSaleInvoicePaginationService,
|
||||||
|
],
|
||||||
exports: [SaleInvoicesService],
|
exports: [SaleInvoicesService],
|
||||||
})
|
})
|
||||||
export class ConsumerSaleInvoicesModule {}
|
export class ConsumerSaleInvoicesModule {}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { IPosPayload } from '@/common/models'
|
import { IPosPayload } from '@/common/models'
|
||||||
import { QUERY_CONSTANTS } from '@/common/queryConstants'
|
import { QUERY_CONSTANTS } from '@/common/queryConstants'
|
||||||
import { SharedSaleInvoiceActionsService } from '@/common/services/saleInvoices/sale-invoice-actions.service'
|
import { SharedSaleInvoiceActionsService } from '@/common/services/saleInvoices/sale-invoice-actions.service'
|
||||||
|
import { SharedSaleInvoiceFilterService } from '@/common/services/saleInvoices/sale-invoice-filter.service'
|
||||||
|
import { SharedSaleInvoicePaginationService } from '@/common/services/saleInvoices/sale-invoice-pagination.service'
|
||||||
import { translateEnumValue } from '@/common/utils'
|
import { translateEnumValue } from '@/common/utils'
|
||||||
import { TspProviderResponseStatus } from '@/generated/prisma/enums'
|
import { TspProviderResponseStatus } from '@/generated/prisma/enums'
|
||||||
import {
|
import {
|
||||||
@@ -20,11 +22,10 @@ export class SaleInvoicesService {
|
|||||||
private readonly prisma: PrismaService,
|
private readonly prisma: PrismaService,
|
||||||
private salesInvoiceTaxService: SalesInvoiceTspService,
|
private salesInvoiceTaxService: SalesInvoiceTspService,
|
||||||
private sharedSaleInvoiceActionsService: SharedSaleInvoiceActionsService,
|
private sharedSaleInvoiceActionsService: SharedSaleInvoiceActionsService,
|
||||||
|
private sharedSaleInvoiceFilterService: SharedSaleInvoiceFilterService,
|
||||||
|
private sharedSaleInvoicePaginationService: SharedSaleInvoicePaginationService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
private readonly defaultPerPage = 10
|
|
||||||
private readonly maxPerPage = 50
|
|
||||||
|
|
||||||
private readonly defaultSelect: SalesInvoiceSelect = {
|
private readonly defaultSelect: SalesInvoiceSelect = {
|
||||||
pos: {
|
pos: {
|
||||||
select: {
|
select: {
|
||||||
@@ -47,29 +48,21 @@ export class SaleInvoicesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private readonly invoiceMapper = (invoice: any) => {
|
private readonly invoiceMapper = (invoice: any) => {
|
||||||
const { tsp_attempts, ...rest } = invoice || {}
|
const { last_tsp_status, ...rest } = invoice || {}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
status: translateEnumValue(
|
status: translateEnumValue(
|
||||||
'TspProviderResponseStatus',
|
'TspProviderResponseStatus',
|
||||||
invoice.tsp_attempts?.[0]?.status || TspProviderResponseStatus.NOT_SEND,
|
last_tsp_status || TspProviderResponseStatus.NOT_SEND,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(consumer_id: string, filter: ConsumerSaleInvoicesFilterDto) {
|
async findAll(consumer_id: string, filter: ConsumerSaleInvoicesFilterDto) {
|
||||||
const invoicesWhere = this.buildFindAllWhere(consumer_id, filter)
|
const invoicesWhere = this.buildFindAllWhere(consumer_id, filter)
|
||||||
const normalizedPageValue = Number(filter.page ?? 1)
|
const { page, perPage, skip, take } =
|
||||||
const normalizedPage = Number.isFinite(normalizedPageValue)
|
this.sharedSaleInvoicePaginationService.normalize(filter.page, filter.perPage)
|
||||||
? Math.max(1, Math.floor(normalizedPageValue))
|
|
||||||
: 1
|
|
||||||
|
|
||||||
const requestedPerPageValue = Number(filter.perPage ?? this.defaultPerPage)
|
|
||||||
const requestedPerPage = Number.isFinite(requestedPerPageValue)
|
|
||||||
? Math.max(1, Math.floor(requestedPerPageValue))
|
|
||||||
: this.defaultPerPage
|
|
||||||
const normalizedPerPage = Math.min(requestedPerPage, this.maxPerPage)
|
|
||||||
|
|
||||||
const [invoices, total] = await this.prisma.$transaction(async tx => [
|
const [invoices, total] = await this.prisma.$transaction(async tx => [
|
||||||
await tx.salesInvoice.findMany({
|
await tx.salesInvoice.findMany({
|
||||||
@@ -77,8 +70,8 @@ export class SaleInvoicesService {
|
|||||||
orderBy: {
|
orderBy: {
|
||||||
created_at: 'desc',
|
created_at: 'desc',
|
||||||
},
|
},
|
||||||
skip: (normalizedPage - 1) * normalizedPerPage,
|
skip,
|
||||||
take: normalizedPerPage,
|
take,
|
||||||
select: {
|
select: {
|
||||||
...QUERY_CONSTANTS.SALE_INVOICE.summarySelect,
|
...QUERY_CONSTANTS.SALE_INVOICE.summarySelect,
|
||||||
...this.defaultSelect,
|
...this.defaultSelect,
|
||||||
@@ -89,8 +82,8 @@ export class SaleInvoicesService {
|
|||||||
|
|
||||||
const mappedInvoices = invoices.map(this.invoiceMapper)
|
const mappedInvoices = invoices.map(this.invoiceMapper)
|
||||||
return ResponseMapper.paginate(mappedInvoices, {
|
return ResponseMapper.paginate(mappedInvoices, {
|
||||||
page: normalizedPage,
|
page,
|
||||||
perPage: normalizedPerPage,
|
perPage,
|
||||||
total,
|
total,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -100,9 +93,11 @@ export class SaleInvoicesService {
|
|||||||
filter: ConsumerSaleInvoicesFilterDto,
|
filter: ConsumerSaleInvoicesFilterDto,
|
||||||
): SalesInvoiceWhereInput {
|
): SalesInvoiceWhereInput {
|
||||||
const where: SalesInvoiceWhereInput = {
|
const where: SalesInvoiceWhereInput = {
|
||||||
|
...this.sharedSaleInvoiceFilterService.buildWhere(filter),
|
||||||
consumer_account: {
|
consumer_account: {
|
||||||
consumer_id,
|
consumer_id,
|
||||||
},
|
},
|
||||||
|
referenced_by: null,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter.code?.trim()) {
|
if (filter.code?.trim()) {
|
||||||
@@ -111,127 +106,6 @@ export class SaleInvoicesService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter.invoice_date_from || filter.invoice_date_to) {
|
|
||||||
where.invoice_date = {
|
|
||||||
...(filter.invoice_date_from ? { gte: new Date(filter.invoice_date_from) } : {}),
|
|
||||||
...(filter.invoice_date_to ? { lte: new Date(filter.invoice_date_to) } : {}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.created_at_from || filter.created_at_to) {
|
|
||||||
where.created_at = {
|
|
||||||
...(filter.created_at_from ? { gte: new Date(filter.created_at_from) } : {}),
|
|
||||||
...(filter.created_at_to ? { lte: new Date(filter.created_at_to) } : {}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
filter.total_amount !== undefined ||
|
|
||||||
filter.total_amount_from !== undefined ||
|
|
||||||
filter.total_amount_to !== undefined
|
|
||||||
) {
|
|
||||||
where.total_amount = {
|
|
||||||
...(filter.total_amount !== undefined ? { equals: filter.total_amount } : {}),
|
|
||||||
...(filter.total_amount_from !== undefined
|
|
||||||
? { gte: filter.total_amount_from }
|
|
||||||
: {}),
|
|
||||||
...(filter.total_amount_to !== undefined ? { lte: filter.total_amount_to } : {}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
filter.customer_name?.trim() ||
|
|
||||||
filter.customer_mobile?.trim() ||
|
|
||||||
filter.customer_national_id?.trim() ||
|
|
||||||
filter.customer_economic_code?.trim()
|
|
||||||
) {
|
|
||||||
where.customer = {
|
|
||||||
is: {
|
|
||||||
OR: [
|
|
||||||
...(filter.customer_name?.trim()
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
individual: {
|
|
||||||
is: {
|
|
||||||
OR: [
|
|
||||||
{ first_name: { contains: filter.customer_name.trim() } },
|
|
||||||
{ last_name: { contains: filter.customer_name.trim() } },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
legal: {
|
|
||||||
is: {
|
|
||||||
name: {
|
|
||||||
contains: filter.customer_name.trim(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
...(filter.customer_mobile?.trim()
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
individual: {
|
|
||||||
is: {
|
|
||||||
mobile_number: { contains: filter.customer_mobile.trim() },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
...(filter.customer_national_id?.trim()
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
individual: {
|
|
||||||
is: {
|
|
||||||
national_id: { contains: filter.customer_national_id.trim() },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
...(filter.customer_economic_code?.trim()
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
legal: {
|
|
||||||
is: {
|
|
||||||
OR: [
|
|
||||||
{
|
|
||||||
economic_code: {
|
|
||||||
contains: filter.customer_economic_code.trim(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
registration_number: {
|
|
||||||
contains: filter.customer_economic_code.trim(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.status) {
|
|
||||||
if (filter.status === TspProviderResponseStatus.NOT_SEND) {
|
|
||||||
where.tsp_attempts = undefined
|
|
||||||
} else {
|
|
||||||
where.tsp_attempts = {
|
|
||||||
some: {
|
|
||||||
status: filter.status,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return where
|
return where
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +116,7 @@ export class SaleInvoicesService {
|
|||||||
consumer_id,
|
consumer_id,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const invoice = await this.prisma.salesInvoice.findUniqueOrThrow({
|
const invoice = await this.prisma.salesInvoice.findUnique({
|
||||||
where: invoicesWhere,
|
where: invoicesWhere,
|
||||||
select: {
|
select: {
|
||||||
...QUERY_CONSTANTS.SALE_INVOICE.select,
|
...QUERY_CONSTANTS.SALE_INVOICE.select,
|
||||||
@@ -251,7 +125,20 @@ export class SaleInvoicesService {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (invoice) {
|
if (invoice) {
|
||||||
return ResponseMapper.single(this.invoiceMapper(invoice))
|
const { type, ...rest } = invoice
|
||||||
|
const mappedInvoice = {
|
||||||
|
...rest,
|
||||||
|
type: translateEnumValue('TspProviderRequestType', type),
|
||||||
|
status: translateEnumValue(
|
||||||
|
'TspProviderResponseStatus',
|
||||||
|
invoice.last_tsp_status || TspProviderResponseStatus.NOT_SEND,
|
||||||
|
),
|
||||||
|
settlement_type: translateEnumValue(
|
||||||
|
'InvoiceSettlementType',
|
||||||
|
invoice.settlement_type,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
return ResponseMapper.single(mappedInvoice)
|
||||||
}
|
}
|
||||||
throw new NotFoundException('صورتحساب مورد نظر شما یافت نشد.')
|
throw new NotFoundException('صورتحساب مورد نظر شما یافت نشد.')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,95 +1,10 @@
|
|||||||
|
import { SharedSaleInvoicesFilterDto } from '@/common/services/saleInvoices/sale-invoice-filter.dto'
|
||||||
import { ApiPropertyOptional } from '@nestjs/swagger'
|
import { ApiPropertyOptional } from '@nestjs/swagger'
|
||||||
import { Type } from 'class-transformer'
|
import { IsNumber, IsOptional } from 'class-validator'
|
||||||
import {
|
|
||||||
IsDateString,
|
|
||||||
IsEnum,
|
|
||||||
IsNumber,
|
|
||||||
IsOptional,
|
|
||||||
IsString,
|
|
||||||
Min,
|
|
||||||
} from 'class-validator'
|
|
||||||
import { TspProviderResponseStatus } from 'generated/prisma/enums'
|
|
||||||
|
|
||||||
export class SalesInvoicesFilterDto {
|
|
||||||
@ApiPropertyOptional({ default: 1 })
|
|
||||||
@IsOptional()
|
|
||||||
@Type(() => Number)
|
|
||||||
@IsNumber()
|
|
||||||
@Min(1)
|
|
||||||
page?: number
|
|
||||||
|
|
||||||
@ApiPropertyOptional({ default: 10 })
|
|
||||||
@IsOptional()
|
|
||||||
@Type(() => Number)
|
|
||||||
@IsNumber()
|
|
||||||
@Min(1)
|
|
||||||
perPage?: number
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@IsDateString()
|
|
||||||
invoice_date_from?: string
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@IsDateString()
|
|
||||||
invoice_date_to?: string
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@IsDateString()
|
|
||||||
created_at_from?: string
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@IsDateString()
|
|
||||||
created_at_to?: string
|
|
||||||
|
|
||||||
|
export class SalesInvoicesFilterDto extends SharedSaleInvoicesFilterDto {
|
||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
invoice_number?: number
|
invoice_number?: number
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
customer_name?: string
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
customer_mobile?: string
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
customer_national_id?: string
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
customer_economic_code?: string
|
|
||||||
|
|
||||||
@ApiPropertyOptional({ enum: TspProviderResponseStatus })
|
|
||||||
@IsOptional()
|
|
||||||
@IsEnum(TspProviderResponseStatus)
|
|
||||||
status?: TspProviderResponseStatus
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@Type(() => Number)
|
|
||||||
@IsNumber()
|
|
||||||
total_amount?: number
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@Type(() => Number)
|
|
||||||
@IsNumber()
|
|
||||||
total_amount_from?: number
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@Type(() => Number)
|
|
||||||
@IsNumber()
|
|
||||||
total_amount_to?: number
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { SharedSaleInvoiceCreateService } from '@/common/services/saleInvoices/sale-invoice-create.service'
|
import { SharedSaleInvoiceCreateService } from '@/common/services/saleInvoices/sale-invoice-create.service'
|
||||||
import { SharedSaleInvoiceActionsService } from '@/common/services/saleInvoices/sale-invoice-actions.service'
|
import { SharedSaleInvoiceActionsService } from '@/common/services/saleInvoices/sale-invoice-actions.service'
|
||||||
import { SharedSaleInvoiceAccessService } from '@/common/services/saleInvoices/sale-invoice-access.service'
|
import { SharedSaleInvoiceAccessService } from '@/common/services/saleInvoices/sale-invoice-access.service'
|
||||||
|
import { SharedSaleInvoiceFilterService } from '@/common/services/saleInvoices/sale-invoice-filter.service'
|
||||||
import { SaleInvoiceTspModule } from '@/modules/tspProviders/sales-invoice-tsp.module'
|
import { SaleInvoiceTspModule } from '@/modules/tspProviders/sales-invoice-tsp.module'
|
||||||
import { Module } from '@nestjs/common'
|
import { Module } from '@nestjs/common'
|
||||||
import { SalesInvoicesController } from './sales-invoices.controller'
|
import { SalesInvoicesController } from './sales-invoices.controller'
|
||||||
@@ -14,6 +15,7 @@ import { SalesInvoicesService } from './sales-invoices.service'
|
|||||||
SharedSaleInvoiceCreateService,
|
SharedSaleInvoiceCreateService,
|
||||||
SharedSaleInvoiceActionsService,
|
SharedSaleInvoiceActionsService,
|
||||||
SharedSaleInvoiceAccessService,
|
SharedSaleInvoiceAccessService,
|
||||||
|
SharedSaleInvoiceFilterService,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class PosSalesInvoicesModule {}
|
export class PosSalesInvoicesModule {}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { IPosPayload } from '@/common/models/posPayload.model'
|
|||||||
import { QUERY_CONSTANTS } from '@/common/queryConstants'
|
import { QUERY_CONSTANTS } from '@/common/queryConstants'
|
||||||
import { SharedSaleInvoiceActionsService } from '@/common/services/saleInvoices/sale-invoice-actions.service'
|
import { SharedSaleInvoiceActionsService } from '@/common/services/saleInvoices/sale-invoice-actions.service'
|
||||||
import { SharedSaleInvoiceCreateService } from '@/common/services/saleInvoices/sale-invoice-create.service'
|
import { SharedSaleInvoiceCreateService } from '@/common/services/saleInvoices/sale-invoice-create.service'
|
||||||
|
import { SharedSaleInvoiceFilterService } from '@/common/services/saleInvoices/sale-invoice-filter.service'
|
||||||
import { translateEnumValue } from '@/common/utils'
|
import { translateEnumValue } from '@/common/utils'
|
||||||
import { PrismaService } from '@/prisma/prisma.service'
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
import { Injectable, NotFoundException } from '@nestjs/common'
|
import { Injectable, NotFoundException } from '@nestjs/common'
|
||||||
@@ -22,6 +23,7 @@ export class SalesInvoicesService {
|
|||||||
private salesInvoiceTaxService: SalesInvoiceTspService,
|
private salesInvoiceTaxService: SalesInvoiceTspService,
|
||||||
private sharedSaleInvoiceCreateService: SharedSaleInvoiceCreateService,
|
private sharedSaleInvoiceCreateService: SharedSaleInvoiceCreateService,
|
||||||
private sharedSaleInvoiceActionsService: SharedSaleInvoiceActionsService,
|
private sharedSaleInvoiceActionsService: SharedSaleInvoiceActionsService,
|
||||||
|
private sharedSaleInvoiceFilterService: SharedSaleInvoiceFilterService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async findAll(posInfo: IPosPayload, query: SalesInvoicesFilterDto = {}) {
|
async findAll(posInfo: IPosPayload, query: SalesInvoicesFilterDto = {}) {
|
||||||
@@ -195,6 +197,7 @@ export class SalesInvoicesService {
|
|||||||
|
|
||||||
private buildFindAllWhere(posInfo: IPosPayload, query: SalesInvoicesFilterDto) {
|
private buildFindAllWhere(posInfo: IPosPayload, query: SalesInvoicesFilterDto) {
|
||||||
const where: Prisma.SalesInvoiceWhereInput = {
|
const where: Prisma.SalesInvoiceWhereInput = {
|
||||||
|
...this.sharedSaleInvoiceFilterService.buildWhere(query),
|
||||||
pos: {
|
pos: {
|
||||||
id: posInfo.pos_id,
|
id: posInfo.pos_id,
|
||||||
complex: {
|
complex: {
|
||||||
@@ -208,142 +211,6 @@ export class SalesInvoicesService {
|
|||||||
where.invoice_number = parseInt(query.invoice_number + '')
|
where.invoice_number = parseInt(query.invoice_number + '')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.invoice_date_from || query.invoice_date_to) {
|
|
||||||
where.invoice_date = {
|
|
||||||
...(query.invoice_date_from ? { gte: new Date(query.invoice_date_from) } : {}),
|
|
||||||
...(query.invoice_date_to ? { lte: new Date(query.invoice_date_to) } : {}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query.created_at_from || query.created_at_to) {
|
|
||||||
where.created_at = {
|
|
||||||
...(query.created_at_from ? { gte: new Date(query.created_at_from) } : {}),
|
|
||||||
...(query.created_at_to ? { lte: new Date(query.created_at_to) } : {}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
query.total_amount !== undefined ||
|
|
||||||
query.total_amount_from !== undefined ||
|
|
||||||
query.total_amount_to !== undefined
|
|
||||||
) {
|
|
||||||
where.total_amount = {
|
|
||||||
...(query.total_amount !== undefined ? { equals: query.total_amount } : {}),
|
|
||||||
...(query.total_amount_from !== undefined
|
|
||||||
? { gte: query.total_amount_from }
|
|
||||||
: {}),
|
|
||||||
...(query.total_amount_to !== undefined ? { lte: query.total_amount_to } : {}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
query.customer_name?.trim() ||
|
|
||||||
query.customer_mobile?.trim() ||
|
|
||||||
query.customer_national_id?.trim() ||
|
|
||||||
query.customer_economic_code?.trim()
|
|
||||||
) {
|
|
||||||
where.customer = {
|
|
||||||
is: {
|
|
||||||
OR: [
|
|
||||||
...(query.customer_name?.trim()
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
individual: {
|
|
||||||
is: {
|
|
||||||
OR: [
|
|
||||||
{
|
|
||||||
first_name: {
|
|
||||||
contains: query.customer_name.trim(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
last_name: {
|
|
||||||
contains: query.customer_name.trim(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
legal: {
|
|
||||||
is: {
|
|
||||||
name: {
|
|
||||||
contains: query.customer_name.trim(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
...(query.customer_mobile?.trim()
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
individual: {
|
|
||||||
is: {
|
|
||||||
mobile_number: {
|
|
||||||
contains: query.customer_mobile.trim(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
...(query.customer_national_id?.trim()
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
individual: {
|
|
||||||
is: {
|
|
||||||
national_id: {
|
|
||||||
contains: query.customer_national_id.trim(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
...(query.customer_economic_code?.trim()
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
legal: {
|
|
||||||
is: {
|
|
||||||
OR: [
|
|
||||||
{
|
|
||||||
economic_code: {
|
|
||||||
contains: query.customer_economic_code.trim(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
registration_number: {
|
|
||||||
contains: query.customer_economic_code.trim(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query.status) {
|
|
||||||
if (query.status === TspProviderResponseStatus.NOT_SEND) {
|
|
||||||
where.OR = [
|
|
||||||
{
|
|
||||||
last_tsp_status: null,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
last_tsp_status: TspProviderResponseStatus.NOT_SEND,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
} else {
|
|
||||||
where.last_tsp_status = query.status
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return where
|
return where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -657,6 +657,7 @@ export async function onResult(
|
|||||||
where: { id: invoice_id },
|
where: { id: invoice_id },
|
||||||
data: {
|
data: {
|
||||||
last_tsp_status: attemptUpdatedData.status,
|
last_tsp_status: attemptUpdatedData.status,
|
||||||
|
last_attempt_no: attemptUpdatedData.attempt_no,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return updatedInvoice
|
return updatedInvoice
|
||||||
|
|||||||
Reference in New Issue
Block a user