add tax to order

This commit is contained in:
2026-01-24 11:08:54 +03:30
parent e53c574931
commit 49390ce62e
5 changed files with 43 additions and 13 deletions
+17 -6
View File
@@ -1,4 +1,4 @@
import { Injectable, NotFoundException, BadRequestException, Logger } from '@nestjs/common';
import { Injectable, BadRequestException, Logger } from '@nestjs/common';
import { EntityManager } from '@mikro-orm/postgresql';
import { OrderItem } from '../entities/order-item.entity';
import { OrderRepository } from '../repositories/order.repository';
@@ -53,7 +53,8 @@ export class OrderService {
total: 0,
paidAmount: 0,
balance: 0,
status: OrderStatusEnum.DRAFT
status: OrderStatusEnum.DRAFT,
taxAmount: 0
})
em.persist(order)
@@ -128,7 +129,8 @@ export class OrderService {
total,
paidAmount: 0,
balance: total,
status: OrderStatusEnum.INVOICED
status: OrderStatusEnum.INVOICED,
taxAmount: 0
})
em.persist(order)
@@ -200,7 +202,7 @@ export class OrderService {
}
async createInvoice(orderId: string, dto: CreateInvoiceDto) {
const { items } = dto
const { items, enableTax } = dto
const targetOrder = await this.findOneOrFail(orderId)
@@ -236,8 +238,17 @@ export class OrderService {
targetOrder.subTotal = subTotal
targetOrder.discount = totalDiscount
targetOrder.total = subTotal - totalDiscount
targetOrder.balance = subTotal - totalDiscount
const total = subTotal - totalDiscount
let tax = 0
if (enableTax) {
tax = 0.1 * total
}
targetOrder.taxAmount = tax
targetOrder.total = total + tax
targetOrder.balance = total + tax
// change status
targetOrder.status = OrderStatusEnum.INVOICED