d98507fc1f
feat: enhance PosAccountsService to include inventoryBankAccount details in responses refactor: modify PosService to return structured inventory and bank account data chore: remove isSettled field from CreatePurchaseReceiptDto and adjust related logic feat: add payments selection in SuppliersService for better payment tracking chore: apply database migrations to adjust decimal types and enforce constraints chore: create index on Pos_Accounts for improved query performance feat: define Supplier and SupplierLedger models in Prisma schema for better data management
115 lines
2.6 KiB
TypeScript
115 lines
2.6 KiB
TypeScript
import { Injectable } from '@nestjs/common'
|
|
import { ResponseMapper } from '../common/response/response-mapper'
|
|
import { PrismaService } from '../prisma/prisma.service'
|
|
|
|
@Injectable()
|
|
export class SuppliersService {
|
|
constructor(private prisma: PrismaService) {}
|
|
async create(data: any) {
|
|
const item = await this.prisma.supplier.create({ data })
|
|
return ResponseMapper.create(item)
|
|
}
|
|
|
|
async findAll() {
|
|
const items = await this.prisma.supplier.findMany()
|
|
return ResponseMapper.list(items)
|
|
}
|
|
|
|
async findOne(id: number) {
|
|
const item = await this.prisma.supplier.findUnique({ where: { id } })
|
|
if (!item) return null
|
|
const receiptsInfo = await this.prisma.purchaseReceipt.aggregate({
|
|
where: {
|
|
supplierId: id,
|
|
},
|
|
_count: true,
|
|
_sum: {
|
|
totalAmount: true,
|
|
},
|
|
})
|
|
|
|
return ResponseMapper.single({
|
|
...item,
|
|
receiptsOverview: {
|
|
totalPayment: receiptsInfo._sum.totalAmount,
|
|
count: receiptsInfo._count,
|
|
},
|
|
})
|
|
}
|
|
|
|
async getInvoices(supplierId: number) {
|
|
const items = await this.prisma.purchaseReceipt.findMany({
|
|
where: {
|
|
supplierId,
|
|
},
|
|
include: {
|
|
inventory: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
},
|
|
},
|
|
items: {
|
|
select: {
|
|
id: true,
|
|
count: true,
|
|
fee: true,
|
|
total: true,
|
|
product: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
sku: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
payments: {
|
|
select: {
|
|
id: true,
|
|
amount: true,
|
|
},
|
|
},
|
|
},
|
|
omit: {
|
|
inventoryId: true,
|
|
supplierId: true,
|
|
},
|
|
})
|
|
return ResponseMapper.list(items)
|
|
}
|
|
|
|
async getInvoice(supplierId: number, invoiceId: number) {
|
|
const invoice = await this.prisma.purchaseReceipt.findUnique({
|
|
where: {
|
|
id: invoiceId,
|
|
supplierId,
|
|
},
|
|
include: {
|
|
inventory: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
},
|
|
},
|
|
items: true,
|
|
},
|
|
omit: {
|
|
inventoryId: true,
|
|
supplierId: true,
|
|
},
|
|
})
|
|
return ResponseMapper.single(invoice)
|
|
}
|
|
|
|
async update(id: number, data: any) {
|
|
const item = await this.prisma.supplier.update({ where: { id }, data })
|
|
return ResponseMapper.update(item)
|
|
}
|
|
|
|
async remove(id: number) {
|
|
const item = await this.prisma.supplier.delete({ where: { id } })
|
|
return ResponseMapper.single(item)
|
|
}
|
|
}
|