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:
@@ -0,0 +1,23 @@
|
||||
import { Type } from 'class-transformer'
|
||||
import { IsInt, IsNumber, IsOptional, IsString } from 'class-validator'
|
||||
|
||||
export class CreatePurchaseReceiptDto {
|
||||
@IsString()
|
||||
code: string
|
||||
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
totalAmount: number
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string
|
||||
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
supplierId: number
|
||||
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
inventoryId: number
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { Type } from 'class-transformer'
|
||||
import { IsInt, IsNumber, IsOptional, IsString } from 'class-validator'
|
||||
|
||||
export class UpdatePurchaseReceiptDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
code?: string
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
totalAmount?: number
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
supplierId?: number | null
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
inventoryId?: number | null
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { CreatePurchaseReceiptDto } from './dto/create-purchase-receipt.dto'
|
||||
import { UpdatePurchaseReceiptDto } from './dto/update-purchase-receipt.dto'
|
||||
import { PurchaseReceiptsService } from './purchase-receipts.service'
|
||||
|
||||
@Controller('purchase-receipts')
|
||||
export class PurchaseReceiptsController {
|
||||
constructor(private readonly service: PurchaseReceiptsService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() dto: CreatePurchaseReceiptDto) {
|
||||
return this.service.create(dto)
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.service.findAll()
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.service.findOne(Number(id))
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() dto: UpdatePurchaseReceiptDto) {
|
||||
return this.service.update(Number(id), dto)
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.service.remove(Number(id))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { PrismaModule } from '../prisma/prisma.module'
|
||||
import { PurchaseReceiptsController } from './purchase-receipts.controller'
|
||||
import { PurchaseReceiptsService } from './purchase-receipts.service'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [PurchaseReceiptsController],
|
||||
providers: [PurchaseReceiptsService],
|
||||
})
|
||||
export class PurchaseReceiptsModule {}
|
||||
@@ -0,0 +1,65 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from '../common/response/response-mapper'
|
||||
import { PrismaService } from '../prisma/prisma.service'
|
||||
import { CreatePurchaseReceiptDto } from './dto/create-purchase-receipt.dto'
|
||||
|
||||
@Injectable()
|
||||
export class PurchaseReceiptsService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async create(dto: CreatePurchaseReceiptDto) {
|
||||
const payload: any = { ...dto }
|
||||
if (Object.prototype.hasOwnProperty.call(payload, 'supplierId')) {
|
||||
payload.supplier = { connect: { id: Number(payload.supplierId) } }
|
||||
delete payload.supplierId
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(payload, 'inventoryId')) {
|
||||
payload.inventory = { connect: { id: Number(payload.inventoryId) } }
|
||||
delete payload.inventoryId
|
||||
}
|
||||
|
||||
const item = await this.prisma.purchaseReceipt.create({ data: payload })
|
||||
return ResponseMapper.create(item)
|
||||
}
|
||||
|
||||
async findAll() {
|
||||
const items = await this.prisma.purchaseReceipt.findMany({
|
||||
include: { supplier: true, inventory: true },
|
||||
})
|
||||
return ResponseMapper.list(items)
|
||||
}
|
||||
|
||||
async findOne(id: number) {
|
||||
const item = await this.prisma.purchaseReceipt.findUnique({
|
||||
where: { id },
|
||||
include: { supplier: true, inventory: true, items: 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, 'supplierId')) {
|
||||
if (payload.supplierId === null) payload.supplier = { disconnect: true }
|
||||
else payload.supplier = { connect: { id: Number(payload.supplierId) } }
|
||||
delete payload.supplierId
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(payload, 'inventoryId')) {
|
||||
if (payload.inventoryId === null) payload.inventory = { disconnect: true }
|
||||
else payload.inventory = { connect: { id: Number(payload.inventoryId) } }
|
||||
delete payload.inventoryId
|
||||
}
|
||||
|
||||
const item = await this.prisma.purchaseReceipt.update({
|
||||
where: { id },
|
||||
data: payload,
|
||||
})
|
||||
return ResponseMapper.update(item)
|
||||
}
|
||||
|
||||
async remove(id: number) {
|
||||
const item = await this.prisma.purchaseReceipt.delete({ where: { id } })
|
||||
return ResponseMapper.single(item)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user