invoice item total and subtotal
This commit is contained in:
@@ -88,7 +88,8 @@ export class CreateInvoiceDto {
|
||||
description?: string;
|
||||
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
@Type(() => IAttachmentDto)
|
||||
@ApiProperty({ type: [IAttachmentDto] })
|
||||
attachments: IAttachmentDto[];
|
||||
attachments?: IAttachmentDto[];
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ export class InvoiceItem extends BaseEntity {
|
||||
@Property({
|
||||
type: 'int',
|
||||
columnType: 'int GENERATED ALWAYS AS (COALESCE(unit_price, 0) * quantity) STORED',
|
||||
persist: false,
|
||||
})
|
||||
subTotal!: number & Opt;
|
||||
|
||||
@@ -42,7 +41,6 @@ export class InvoiceItem extends BaseEntity {
|
||||
@Property({
|
||||
type: 'int',
|
||||
columnType: 'int GENERATED ALWAYS AS ((COALESCE(unit_price, 0) * quantity) - COALESCE(discount, 0)) STORED',
|
||||
persist: false
|
||||
})
|
||||
total!: number & Opt;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ export class InvoiceService {
|
||||
private readonly productService: ProductService,
|
||||
private readonly invoiceRepository: InvoiceRepository,
|
||||
private readonly eventEmitter: EventEmitter2,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
|
||||
async create(dto: CreateInvoiceDto) {
|
||||
@@ -59,13 +59,16 @@ export class InvoiceService {
|
||||
...(request && { request }),
|
||||
enableTax,
|
||||
approvalDeadline,
|
||||
// discount,
|
||||
discount: 0,
|
||||
paidAmount: 0,
|
||||
// balance: 0,
|
||||
attachments: [],
|
||||
balance: 0,
|
||||
attachments: dto.attachments ?? [],
|
||||
paymentMethod: dto.paymentMethod,
|
||||
invoiceNumber: 20, // TODO : invoice number
|
||||
description: dto.description
|
||||
description: dto.description,
|
||||
subTotal: 0,
|
||||
taxAmount: 0,
|
||||
total: 0,
|
||||
});
|
||||
em.persist(invoice);
|
||||
|
||||
@@ -95,7 +98,7 @@ export class InvoiceService {
|
||||
// const total = Math.max(0, subTotal - discount + taxAmount);
|
||||
|
||||
// invoice.subTotal = subTotal;
|
||||
invoice.attachments = dto.attachments;
|
||||
// invoice.attachments = dto.attachments;
|
||||
// invoice.taxAmount = taxAmount;
|
||||
// invoice.total = total;
|
||||
// invoice.balance = total - invoice.paidAmount;
|
||||
@@ -114,7 +117,7 @@ export class InvoiceService {
|
||||
await em.flush();
|
||||
return invoice;
|
||||
});
|
||||
// TODO : maybe it is needed to get a fresh instance.
|
||||
// TODO : maybe it is needed to get a fresh instance.
|
||||
this.eventEmitter.emit(
|
||||
InvoiceCreatedEvent.name,
|
||||
new InvoiceCreatedEvent(
|
||||
@@ -184,9 +187,9 @@ export class InvoiceService {
|
||||
if (dto.approvalDeadline !== undefined) {
|
||||
invoice.approvalDeadline = new Date(dto.approvalDeadline);
|
||||
}
|
||||
if(dto.paymentMethod !== undefined) invoice.paymentMethod = dto.paymentMethod;
|
||||
if(dto.description !== undefined) invoice.description = dto.description;
|
||||
if(dto.attachments !== undefined) invoice.attachments = dto.attachments;
|
||||
if (dto.paymentMethod !== undefined) invoice.paymentMethod = dto.paymentMethod;
|
||||
if (dto.description !== undefined) invoice.description = dto.description;
|
||||
if (dto.attachments !== undefined) invoice.attachments = dto.attachments;
|
||||
|
||||
if (dto.items !== undefined) {
|
||||
// Items in dto.items represent the full list: delete any existing items not in the list
|
||||
|
||||
Reference in New Issue
Block a user