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,24 @@
|
||||
import { Type } from 'class-transformer'
|
||||
import { IsInt, IsNumber } from 'class-validator'
|
||||
|
||||
export class CreateSalesInvoiceItemDto {
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
count: number
|
||||
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
fee: number
|
||||
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
total: number
|
||||
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
invoiceId: number
|
||||
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
productId: number
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { Type } from 'class-transformer'
|
||||
import { IsInt, IsNumber, IsOptional } from 'class-validator'
|
||||
|
||||
export class UpdateSalesInvoiceItemDto {
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
count?: number
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
fee?: number
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
total?: number
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
invoiceId?: number
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
productId?: number
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { CreateSalesInvoiceItemDto } from './dto/create-sales-invoice-item.dto'
|
||||
import { UpdateSalesInvoiceItemDto } from './dto/update-sales-invoice-item.dto'
|
||||
import { SalesInvoiceItemsService } from './sales-invoice-items.service'
|
||||
|
||||
@Controller('sales-invoices/:invoiceId/items')
|
||||
export class SalesInvoiceItemsController {
|
||||
constructor(private readonly service: SalesInvoiceItemsService) {}
|
||||
|
||||
@Post()
|
||||
create(@Param('invoiceId') invoiceId: string, @Body() dto: CreateSalesInvoiceItemDto) {
|
||||
return this.service.createForInvoice(Number(invoiceId), dto)
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll(@Param('invoiceId') invoiceId: string) {
|
||||
return this.service.findAllForInvoice(Number(invoiceId))
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('invoiceId') invoiceId: string, @Param('id') id: string) {
|
||||
return this.service.findOneForInvoice(Number(invoiceId), Number(id))
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(
|
||||
@Param('invoiceId') invoiceId: string,
|
||||
@Param('id') id: string,
|
||||
@Body() dto: UpdateSalesInvoiceItemDto,
|
||||
) {
|
||||
return this.service.updateForInvoice(Number(invoiceId), Number(id), dto)
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('invoiceId') invoiceId: string, @Param('id') id: string) {
|
||||
return this.service.removeForInvoice(Number(invoiceId), Number(id))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { PrismaModule } from '../prisma/prisma.module'
|
||||
import { SalesInvoiceItemsController } from './sales-invoice-items.controller'
|
||||
import { SalesInvoiceItemsService } from './sales-invoice-items.service'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [SalesInvoiceItemsController],
|
||||
providers: [SalesInvoiceItemsService],
|
||||
})
|
||||
export class SalesInvoiceItemsModule {}
|
||||
@@ -0,0 +1,98 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from '../common/response/response-mapper'
|
||||
import { PrismaService } from '../prisma/prisma.service'
|
||||
import { CreateSalesInvoiceItemDto } from './dto/create-sales-invoice-item.dto'
|
||||
|
||||
@Injectable()
|
||||
export class SalesInvoiceItemsService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async create(dto: CreateSalesInvoiceItemDto) {
|
||||
const payload: any = { ...dto }
|
||||
if (Object.prototype.hasOwnProperty.call(payload, 'invoiceId')) {
|
||||
payload.invoice = { connect: { id: Number(payload.invoiceId) } }
|
||||
delete payload.invoiceId
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(payload, 'productId')) {
|
||||
payload.product = { connect: { id: Number(payload.productId) } }
|
||||
delete payload.productId
|
||||
}
|
||||
|
||||
const item = await this.prisma.salesInvoiceItem.create({ data: payload })
|
||||
return ResponseMapper.create(item)
|
||||
}
|
||||
async findAll(invoiceId?: number) {
|
||||
const where = invoiceId ? { invoiceId: Number(invoiceId) } : undefined
|
||||
const items = await this.prisma.salesInvoiceItem.findMany({
|
||||
where,
|
||||
include: { product: true },
|
||||
})
|
||||
return ResponseMapper.list(items)
|
||||
}
|
||||
|
||||
async findOne(id: number) {
|
||||
const item = await this.prisma.salesInvoiceItem.findUnique({
|
||||
where: { id },
|
||||
include: { product: true, invoice: true },
|
||||
})
|
||||
if (!item) return null
|
||||
return ResponseMapper.single(item)
|
||||
}
|
||||
|
||||
async createForInvoice(invoiceId: number, dto: CreateSalesInvoiceItemDto) {
|
||||
const payload: any = { ...dto, invoiceId }
|
||||
return this.create(payload)
|
||||
}
|
||||
|
||||
async findAllForInvoice(invoiceId: number) {
|
||||
return this.findAll(invoiceId)
|
||||
}
|
||||
|
||||
async findOneForInvoice(invoiceId: number, id: number) {
|
||||
const item = await this.prisma.salesInvoiceItem.findFirst({
|
||||
where: { id, invoiceId },
|
||||
include: { product: true, invoice: 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, 'invoiceId')) {
|
||||
payload.invoice = { connect: { id: Number(payload.invoiceId) } }
|
||||
delete payload.invoiceId
|
||||
}
|
||||
|
||||
const item = await this.prisma.salesInvoiceItem.update({
|
||||
where: { id },
|
||||
data: payload,
|
||||
})
|
||||
return ResponseMapper.update(item)
|
||||
}
|
||||
|
||||
async updateForInvoice(invoiceId: number, id: number, data: any) {
|
||||
const existing = await this.prisma.salesInvoiceItem.findFirst({
|
||||
where: { id, invoiceId },
|
||||
})
|
||||
if (!existing) return null
|
||||
return this.update(id, data)
|
||||
}
|
||||
|
||||
async remove(id: number) {
|
||||
const item = await this.prisma.salesInvoiceItem.delete({ where: { id } })
|
||||
return ResponseMapper.single(item)
|
||||
}
|
||||
|
||||
async removeForInvoice(invoiceId: number, id: number) {
|
||||
const existing = await this.prisma.salesInvoiceItem.findFirst({
|
||||
where: { id, invoiceId },
|
||||
})
|
||||
if (!existing) return null
|
||||
return this.remove(id)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user