feat: implement purchase receipt items management with create, update, find, and delete functionalities

feat: add purchase receipts management with create, update, find, and delete functionalities

feat: implement sales invoice items management with create, update, find, and delete functionalities

feat: add sales invoices management with create, update, find, and delete functionalities

feat: implement stock adjustments management with create, update, find, and delete functionalities

feat: add stock balance retrieval functionality

feat: implement stock movements management with create, update, find, and delete functionalities
This commit is contained in:
2025-12-09 13:59:07 +03:30
parent a782d61890
commit 807f6c2087
98 changed files with 26109 additions and 501 deletions
@@ -0,0 +1,101 @@
import { Injectable } from '@nestjs/common'
import { ResponseMapper } from '../common/response/response-mapper'
import { PrismaService } from '../prisma/prisma.service'
import { CreateInventoryTransferItemDto } from './dto/create-inventory-transfer-item.dto'
@Injectable()
export class InventoryTransferItemsService {
constructor(private prisma: PrismaService) {}
async create(dto: CreateInventoryTransferItemDto) {
const payload: any = { ...dto }
if (Object.prototype.hasOwnProperty.call(payload, 'productId')) {
payload.product = { connect: { id: Number(payload.productId) } }
delete payload.productId
}
if (Object.prototype.hasOwnProperty.call(payload, 'transferId')) {
payload.transfer = { connect: { id: Number(payload.transferId) } }
delete payload.transferId
}
const item = await this.prisma.inventoryTransferItem.create({ data: payload })
return ResponseMapper.create(item)
}
async findAll(transferId?: number) {
const where = transferId ? { transferId: Number(transferId) } : undefined
const items = await this.prisma.inventoryTransferItem.findMany({
where,
include: { product: true },
})
return ResponseMapper.list(items)
}
async findOne(id: number) {
const item = await this.prisma.inventoryTransferItem.findUnique({
where: { id },
include: { product: true, transfer: true },
})
if (!item) return null
return ResponseMapper.single(item)
}
// scoped helpers for nested routes
async createForTransfer(transferId: number, dto: CreateInventoryTransferItemDto) {
const payload: any = { ...dto, transferId }
return this.create(payload)
}
async findAllForTransfer(transferId: number) {
return this.findAll(transferId)
}
async findOneForTransfer(transferId: number, id: number) {
const item = await this.prisma.inventoryTransferItem.findFirst({
where: { id, transferId },
include: { product: true, transfer: true },
})
if (!item) return null
return ResponseMapper.single(item)
}
async update(id: number, data: any) {
const payload: any = { ...data }
if (Object.prototype.hasOwnProperty.call(payload, 'productId')) {
payload.product = { connect: { id: Number(payload.productId) } }
delete payload.productId
}
if (Object.prototype.hasOwnProperty.call(payload, 'transferId')) {
payload.transfer = { connect: { id: Number(payload.transferId) } }
delete payload.transferId
}
const item = await this.prisma.inventoryTransferItem.update({
where: { id },
data: payload,
})
return ResponseMapper.update(item)
}
async updateForTransfer(transferId: number, id: number, data: any) {
// ensure the item belongs to the transfer
const existing = await this.prisma.inventoryTransferItem.findFirst({
where: { id, transferId },
})
if (!existing) return null
return this.update(id, data)
}
async remove(id: number) {
const item = await this.prisma.inventoryTransferItem.delete({ where: { id } })
return ResponseMapper.single(item)
}
async removeForTransfer(transferId: number, id: number) {
const existing = await this.prisma.inventoryTransferItem.findFirst({
where: { id, transferId },
})
if (!existing) return null
return this.remove(id)
}
}