2026-05-16 18:00:08 +03:30
|
|
|
import { QUERY_CONSTANTS } from '@/common/queryConstants'
|
|
|
|
|
import { translateEnumValue } from '@/common/utils'
|
|
|
|
|
import { TspProviderResponseStatus } from '@/generated/prisma/enums'
|
2026-04-13 13:21:50 +03:30
|
|
|
import { PrismaService } from '@/prisma/prisma.service'
|
|
|
|
|
import { Injectable } from '@nestjs/common'
|
|
|
|
|
import { ResponseMapper } from 'common/response/response-mapper'
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class StatisticsService {
|
|
|
|
|
constructor(private readonly prisma: PrismaService) {}
|
|
|
|
|
|
2026-05-16 18:00:08 +03:30
|
|
|
private readonly invoiceMapper = (invoice: any) => {
|
|
|
|
|
const { tsp_attempts, ...rest } = invoice || {}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
...rest,
|
|
|
|
|
status: translateEnumValue(
|
|
|
|
|
'TspProviderResponseStatus',
|
|
|
|
|
invoice.tsp_attempts?.[0]?.status || TspProviderResponseStatus.NOT_SEND,
|
|
|
|
|
),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 13:21:50 +03:30
|
|
|
async getInvoices(consumer_id: string) {
|
|
|
|
|
const startOfToday = new Date()
|
|
|
|
|
startOfToday.setHours(0, 0, 0, 0)
|
|
|
|
|
|
|
|
|
|
const invoices = await this.prisma.salesInvoice.findMany({
|
|
|
|
|
where: {
|
|
|
|
|
consumer_account: {
|
|
|
|
|
consumer_id,
|
|
|
|
|
},
|
|
|
|
|
created_at: {
|
|
|
|
|
gte: startOfToday,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
select: {
|
2026-05-16 18:00:08 +03:30
|
|
|
...QUERY_CONSTANTS.SALE_INVOICE.summarySelect,
|
2026-04-13 13:21:50 +03:30
|
|
|
consumer_account: {
|
|
|
|
|
select: {
|
|
|
|
|
role: true,
|
|
|
|
|
account: {
|
|
|
|
|
select: {
|
|
|
|
|
username: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
pos: {
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
name: true,
|
|
|
|
|
complex: {
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
name: true,
|
|
|
|
|
business_activity: {
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
name: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-05-16 23:58:59 +03:30
|
|
|
orderBy: {
|
|
|
|
|
created_at: 'desc',
|
|
|
|
|
},
|
2026-04-13 13:21:50 +03:30
|
|
|
})
|
2026-05-16 18:00:08 +03:30
|
|
|
return ResponseMapper.list(invoices.map(this.invoiceMapper))
|
2026-04-13 13:21:50 +03:30
|
|
|
}
|
|
|
|
|
}
|