2026-03-30 13:16:36 +03:30
|
|
|
import { ResponseMapper } from '@/common/response/response-mapper'
|
|
|
|
|
import { SalesInvoiceWhereInput } from '@/generated/prisma/models'
|
|
|
|
|
import { PrismaService } from '@/prisma/prisma.service'
|
|
|
|
|
import { Injectable } from '@nestjs/common'
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class SalesInvoicesService {
|
|
|
|
|
constructor(private prisma: PrismaService) {}
|
|
|
|
|
|
2026-04-11 14:47:05 +03:30
|
|
|
async findAll(consumer_id: string, complex_id: string, pos_id: string) {
|
2026-03-30 13:16:36 +03:30
|
|
|
const defaultWhere: SalesInvoiceWhereInput = {
|
|
|
|
|
pos_id,
|
|
|
|
|
pos: {
|
|
|
|
|
complex: {
|
|
|
|
|
id: complex_id,
|
|
|
|
|
business_activity: {
|
2026-04-11 14:47:05 +03:30
|
|
|
consumer_id,
|
2026-03-30 13:16:36 +03:30
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const pageSize = 10
|
|
|
|
|
const page = 1
|
|
|
|
|
|
|
|
|
|
const [items, count] = await this.prisma.$transaction([
|
|
|
|
|
this.prisma.salesInvoice.findMany({
|
|
|
|
|
where: defaultWhere,
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
code: true,
|
|
|
|
|
invoice_date: true,
|
|
|
|
|
notes: true,
|
|
|
|
|
total_amount: true,
|
|
|
|
|
|
|
|
|
|
items: {
|
|
|
|
|
select: {
|
|
|
|
|
unit_type: true,
|
|
|
|
|
discount: true,
|
|
|
|
|
notes: true,
|
|
|
|
|
quantity: true,
|
|
|
|
|
total_amount: true,
|
|
|
|
|
unit_price: true,
|
|
|
|
|
payload: true,
|
|
|
|
|
good: {
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
name: true,
|
|
|
|
|
sku: true,
|
|
|
|
|
barcode: true,
|
|
|
|
|
local_sku: true,
|
|
|
|
|
pricing_model: true,
|
|
|
|
|
unit_type: true,
|
|
|
|
|
category: {
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
name: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
payments: {
|
|
|
|
|
select: {
|
|
|
|
|
amount: true,
|
|
|
|
|
paid_at: true,
|
|
|
|
|
payment_method: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
customer: {
|
|
|
|
|
select: {
|
|
|
|
|
type: true,
|
2026-04-08 18:15:44 +03:30
|
|
|
customer_individual: {
|
2026-03-30 13:16:36 +03:30
|
|
|
select: {
|
|
|
|
|
economic_code: true,
|
|
|
|
|
first_name: true,
|
|
|
|
|
last_name: true,
|
|
|
|
|
postal_code: true,
|
|
|
|
|
national_id: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-04-08 18:15:44 +03:30
|
|
|
customer_legal: {
|
2026-03-30 13:16:36 +03:30
|
|
|
select: {
|
|
|
|
|
economic_code: true,
|
|
|
|
|
postal_code: true,
|
|
|
|
|
registration_number: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
unknown_customer: true,
|
|
|
|
|
},
|
|
|
|
|
skip: (page - 1) * pageSize,
|
|
|
|
|
take: pageSize,
|
|
|
|
|
}),
|
|
|
|
|
this.prisma.salesInvoice.count({
|
|
|
|
|
where: defaultWhere,
|
|
|
|
|
}),
|
|
|
|
|
])
|
|
|
|
|
return ResponseMapper.paginate(items, { count, page, pageSize })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
findOne(complex_id: string, pos_id: string, id: string) {
|
|
|
|
|
// TODO: Implement fetching a single sales invoice
|
|
|
|
|
return {}
|
|
|
|
|
}
|
|
|
|
|
}
|