109 lines
2.8 KiB
TypeScript
109 lines
2.8 KiB
TypeScript
|
|
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) {}
|
||
|
|
|
||
|
|
async findAll(user_id: string, complex_id: string, pos_id: string) {
|
||
|
|
const defaultWhere: SalesInvoiceWhereInput = {
|
||
|
|
pos_id,
|
||
|
|
pos: {
|
||
|
|
complex: {
|
||
|
|
id: complex_id,
|
||
|
|
business_activity: {
|
||
|
|
user_id,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
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,
|
||
|
|
customer_individuals: {
|
||
|
|
select: {
|
||
|
|
economic_code: true,
|
||
|
|
first_name: true,
|
||
|
|
last_name: true,
|
||
|
|
postal_code: true,
|
||
|
|
national_id: true,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
customer_legals: {
|
||
|
|
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 {}
|
||
|
|
}
|
||
|
|
}
|