add packing fee

This commit is contained in:
2026-07-01 09:54:15 +03:30
parent 77acab935a
commit 2a633a28b4
5 changed files with 38 additions and 1 deletions
+12
View File
@@ -4284,6 +4284,18 @@
"default": "0", "default": "0",
"mappedType": "decimal" "mappedType": "decimal"
}, },
"packing_fee": {
"name": "packing_fee",
"type": "numeric(10,0)",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"precision": 10,
"scale": 0,
"default": "0",
"mappedType": "decimal"
},
"total": { "total": {
"name": "total", "name": "total",
"type": "numeric(10,0)", "type": "numeric(10,0)",
@@ -0,0 +1,13 @@
import { Migration } from '@mikro-orm/migrations';
export class Migration20260701062227_addPackingFeeToOrders extends Migration {
override async up(): Promise<void> {
this.addSql(`alter table "orders" add column "packing_fee" numeric(10,0) not null default 0;`);
}
override async down(): Promise<void> {
this.addSql(`alter table "orders" drop column "packing_fee";`);
}
}
@@ -53,6 +53,12 @@ export class AdminCreateOrderDto {
@Min(0) @Min(0)
discountAmount?: number; discountAmount?: number;
@ApiPropertyOptional({ description: 'Packing fee amount', minimum: 0, default: 0 })
@IsOptional()
@IsNumber()
@Min(0)
packingFee?: number;
@ApiPropertyOptional({ description: 'Order description or notes' }) @ApiPropertyOptional({ description: 'Order description or notes' })
@IsOptional() @IsOptional()
@IsString() @IsString()
@@ -80,6 +80,9 @@ export class Order extends BaseEntity {
@Property({ type: 'decimal', precision: 10, scale: 0, default: 0 }) @Property({ type: 'decimal', precision: 10, scale: 0, default: 0 })
deliveryFee: number = 0; deliveryFee: number = 0;
@Property({ type: 'decimal', precision: 10, scale: 0, default: 0 })
packingFee: number = 0;
@Property({ type: 'decimal', precision: 10, scale: 0 }) @Property({ type: 'decimal', precision: 10, scale: 0 })
total!: number; total!: number;
@@ -83,6 +83,7 @@ export class OrdersService {
subTotal: cart.subTotal || 0, subTotal: cart.subTotal || 0,
tax: cart.tax || 0, tax: cart.tax || 0,
deliveryFee: cart.deliveryFee || 0, deliveryFee: cart.deliveryFee || 0,
packingFee: 0,
total: cart.total || 0, total: cart.total || 0,
totalItems: cart.totalItems || 0, totalItems: cart.totalItems || 0,
description: cart.description, description: cart.description,
@@ -169,13 +170,14 @@ export class OrdersService {
const subTotal = orderItemsData.reduce((sum, item) => sum + item.unitPrice * item.quantity, 0); const subTotal = orderItemsData.reduce((sum, item) => sum + item.unitPrice * item.quantity, 0);
const itemsDiscount = orderItemsData.reduce((sum, item) => sum + item.discount * item.quantity, 0); const itemsDiscount = orderItemsData.reduce((sum, item) => sum + item.discount * item.quantity, 0);
const deliveryFee = delivery.deliveryFeeType === DeliveryFeeTypeEnum.FIXED ? Number(delivery.deliveryFee) : 0; const deliveryFee = delivery.deliveryFeeType === DeliveryFeeTypeEnum.FIXED ? Number(delivery.deliveryFee) : 0;
const packingFee = dto.packingFee ?? 0;
const adminDiscount = dto.discountAmount ?? 0; const adminDiscount = dto.discountAmount ?? 0;
const maxDiscount = subTotal - itemsDiscount; const maxDiscount = subTotal - itemsDiscount;
if (adminDiscount > maxDiscount) { if (adminDiscount > maxDiscount) {
throw new BadRequestException(OrderMessage.DISCOUNT_AMOUNT_EXCEEDS_ORDER_TOTAL); throw new BadRequestException(OrderMessage.DISCOUNT_AMOUNT_EXCEEDS_ORDER_TOTAL);
} }
const totalDiscount = itemsDiscount + adminDiscount; const totalDiscount = itemsDiscount + adminDiscount;
const total = subTotal - totalDiscount + deliveryFee; const total = subTotal - totalDiscount + deliveryFee + packingFee;
const totalItems = orderItemsData.reduce((sum, item) => sum + item.quantity, 0); const totalItems = orderItemsData.reduce((sum, item) => sum + item.quantity, 0);
const order = await this.em.transactional(async em => { const order = await this.em.transactional(async em => {
@@ -193,6 +195,7 @@ export class OrdersService {
subTotal, subTotal,
tax: 0, tax: 0,
deliveryFee, deliveryFee,
packingFee,
total, total,
totalItems, totalItems,
description: dto.description, description: dto.description,