change source of account id in prepared token to domain account id, create consumer salesInvoiceModule
This commit is contained in:
@@ -2,9 +2,10 @@ import { PrismaModule } from '@/prisma/prisma.module'
|
||||
import { Module } from '@nestjs/common'
|
||||
import { ComplexPosesController } from './poses.controller'
|
||||
import { ComplexPosesService } from './poses.service'
|
||||
import { ConsumerPosSalesInvoicesModule } from './sales-invoices/sales-invoices.module'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
imports: [PrismaModule, ConsumerPosSalesInvoicesModule],
|
||||
controllers: [ComplexPosesController],
|
||||
providers: [ComplexPosesService],
|
||||
exports: [ComplexPosesService],
|
||||
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
import { ApiProperty, PartialType } from '@nestjs/swagger'
|
||||
import {
|
||||
ArrayMinSize,
|
||||
IsDateString,
|
||||
IsEnum,
|
||||
IsNumber,
|
||||
IsObject,
|
||||
IsOptional,
|
||||
IsString,
|
||||
} from 'class-validator'
|
||||
import type { CustomerIndividual, CustomerLegal } from 'generated/prisma/client'
|
||||
import { CustomerType } from 'generated/prisma/enums'
|
||||
import { CreateSalesInvoiceItemDto } from '../sales-invoice-items/dto/create-sales-invoice-item.dto'
|
||||
|
||||
export class CreateSalesInvoiceDto {
|
||||
// @TODO: totalAmount must calculated instead of get from api
|
||||
@IsNumber()
|
||||
@ApiProperty({ required: true, default: 0 })
|
||||
total_amount: number
|
||||
|
||||
@ApiProperty({ required: true })
|
||||
@IsDateString(
|
||||
{ strict: true },
|
||||
{ message: 'invoice_date must be a valid ISO-8601 string' },
|
||||
)
|
||||
invoice_date: Date
|
||||
|
||||
@ApiProperty({ required: true })
|
||||
@IsObject()
|
||||
payments: {
|
||||
terminal: number
|
||||
cash: number
|
||||
set_off: number
|
||||
}
|
||||
|
||||
@ApiProperty()
|
||||
@ArrayMinSize(1)
|
||||
items: CreateSalesInvoiceItemDto[]
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
notes?: string
|
||||
|
||||
@ApiProperty({ required: true, default: CustomerType.UNKNOWN })
|
||||
@IsEnum(CustomerType)
|
||||
customer_type: CustomerType
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiProperty({ required: false })
|
||||
customer_id?: string
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
@IsOptional()
|
||||
@IsObject()
|
||||
customer?:
|
||||
| {
|
||||
first_name: string
|
||||
last_name: string
|
||||
}
|
||||
| CustomerIndividual
|
||||
| CustomerLegal
|
||||
}
|
||||
|
||||
export class UpdateSalesInvoiceDto extends PartialType(CreateSalesInvoiceDto) {}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
import { ApiProperty, PartialType } from '@nestjs/swagger'
|
||||
import { IsEnum, IsNumber, IsObject, IsOptional, IsString } from 'class-validator'
|
||||
import type { SaleInvoiceType } from 'common/interfaces/sale-invoice-payload'
|
||||
import { UnitType } from 'generated/prisma/enums'
|
||||
|
||||
export class CreateSalesInvoiceItemDto {
|
||||
@IsNumber()
|
||||
@ApiProperty({ required: true })
|
||||
unit_price: number
|
||||
|
||||
@IsNumber()
|
||||
@ApiProperty({ required: true, default: 1 })
|
||||
quantity: number
|
||||
|
||||
@IsNumber()
|
||||
@ApiProperty({ required: true })
|
||||
total_amount: number
|
||||
|
||||
@IsNumber()
|
||||
@ApiProperty({ required: true })
|
||||
discount_amount: number
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({ required: true })
|
||||
invoice_id: string
|
||||
|
||||
@IsEnum(UnitType)
|
||||
@ApiProperty({ enum: Object.values(UnitType) })
|
||||
unit_type: UnitType
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiProperty({ required: false })
|
||||
good_id?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiProperty({ required: false })
|
||||
service_id?: string
|
||||
|
||||
// @IsEnum(SalesInvoiceItemPricingModel)
|
||||
// @ApiProperty({ enum: Object.values(SalesInvoiceItemPricingModel) })
|
||||
// @IsOptional()
|
||||
// pricingModel: SalesInvoiceItemPricingModel
|
||||
|
||||
@IsOptional()
|
||||
@IsObject()
|
||||
@ApiProperty({ required: false, default: {} })
|
||||
payload: SaleInvoiceType
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiProperty({ required: false, default: '' })
|
||||
notes: string
|
||||
}
|
||||
|
||||
export class UpdateSalesInvoiceItemDto extends PartialType(CreateSalesInvoiceItemDto) {}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common'
|
||||
import { SalesInvoiceItemsService } from './sales-invoice-items.service'
|
||||
|
||||
@Controller('sales_invoice_items')
|
||||
export class SalesInvoiceItemsController {
|
||||
constructor(private readonly salesInvoiceItemsService: SalesInvoiceItemsService) {}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.salesInvoiceItemsService.findAll()
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.salesInvoiceItemsService.findOne(+id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Body() data: any) {
|
||||
return this.salesInvoiceItemsService.create(data)
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { SalesInvoiceItemsController } from './sales-invoice-items.controller'
|
||||
import { SalesInvoiceItemsService } from './sales-invoice-items.service'
|
||||
|
||||
@Module({
|
||||
controllers: [SalesInvoiceItemsController],
|
||||
providers: [SalesInvoiceItemsService],
|
||||
})
|
||||
export class SalesInvoiceItemsModule {}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
|
||||
@Injectable()
|
||||
export class SalesInvoiceItemsService {
|
||||
findAll() {
|
||||
// TODO: Implement fetching all sales invoice items
|
||||
return []
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
// TODO: Implement fetching a single sales invoice item
|
||||
return {}
|
||||
}
|
||||
|
||||
create(data: any) {
|
||||
// TODO: Implement sales invoice item creation
|
||||
return data
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
import { ApiProperty, PartialType } from '@nestjs/swagger'
|
||||
import { IsDateString, IsEnum, IsNumber, IsString } from 'class-validator'
|
||||
|
||||
enum PaymentMethodType {
|
||||
CASH = 'CASH',
|
||||
CARD = 'CARD',
|
||||
BANK = 'BANK',
|
||||
CHECK = 'CHECK',
|
||||
OTHER = 'OTHER',
|
||||
}
|
||||
|
||||
export class CreateSalesInvoicePaymentDto {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
invoice_id: string
|
||||
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
amount: number
|
||||
|
||||
@ApiProperty({ enum: PaymentMethodType })
|
||||
@IsEnum(PaymentMethodType)
|
||||
payment_method: PaymentMethodType
|
||||
|
||||
@ApiProperty()
|
||||
@IsDateString()
|
||||
paid_at: string
|
||||
}
|
||||
|
||||
export class UpdateSalesInvoicePaymentDto extends PartialType(
|
||||
CreateSalesInvoicePaymentDto,
|
||||
) {}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common'
|
||||
import { SalesInvoicePaymentsService } from './sales-invoice-payments.service'
|
||||
|
||||
@Controller('sales-invoice-payments')
|
||||
export class SalesInvoicePaymentsController {
|
||||
constructor(
|
||||
private readonly salesInvoicePaymentsService: SalesInvoicePaymentsService,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.salesInvoicePaymentsService.findAll()
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.salesInvoicePaymentsService.findOne(+id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Body() data: any) {
|
||||
return this.salesInvoicePaymentsService.create(data)
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { SalesInvoicePaymentsController } from './sales-invoice-payments.controller'
|
||||
import { SalesInvoicePaymentsService } from './sales-invoice-payments.service'
|
||||
|
||||
@Module({
|
||||
controllers: [SalesInvoicePaymentsController],
|
||||
providers: [SalesInvoicePaymentsService],
|
||||
})
|
||||
export class SalesInvoicePaymentsModule {}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
|
||||
@Injectable()
|
||||
export class SalesInvoicePaymentsService {
|
||||
findAll() {
|
||||
// TODO: Implement fetching all sales invoice payments
|
||||
return []
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
// TODO: Implement fetching a single sales invoice payment
|
||||
return {}
|
||||
}
|
||||
|
||||
create(data: any) {
|
||||
// TODO: Implement sales invoice payment creation
|
||||
return data
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common'
|
||||
|
||||
import { TokenAccount } from '@/common/decorators/tokenInfo.decorator'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { SalesInvoicesService } from './sales-invoices.service'
|
||||
|
||||
@ApiTags('ConsumerComplexPoses')
|
||||
@Controller('consumer/complexes/:complexId/poses/:posId/sales_invoices')
|
||||
export class SalesInvoicesController {
|
||||
constructor(private readonly salesInvoicesService: SalesInvoicesService) {}
|
||||
|
||||
@Get()
|
||||
findAll(
|
||||
@TokenAccount('userId') userId: string,
|
||||
@Param('complexId') complexId: string,
|
||||
@Param('posId') posId: string,
|
||||
) {
|
||||
return this.salesInvoicesService.findAll(userId, complexId, posId)
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(
|
||||
@Param('complexId') complexId: string,
|
||||
@Param('posId') posId: string,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
return this.salesInvoicesService.findOne(complexId, posId, id)
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { SalesInvoicesController } from './sales-invoices.controller'
|
||||
import { SalesInvoicesService } from './sales-invoices.service'
|
||||
|
||||
@Module({
|
||||
controllers: [SalesInvoicesController],
|
||||
providers: [SalesInvoicesService],
|
||||
})
|
||||
export class ConsumerPosSalesInvoicesModule {}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
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 {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user