add packing fee
This commit is contained in:
@@ -53,6 +53,12 @@ export class AdminCreateOrderDto {
|
||||
@Min(0)
|
||||
discountAmount?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: 'Packing fee amount', minimum: 0, default: 0 })
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@Min(0)
|
||||
packingFee?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: 'Order description or notes' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
|
||||
@@ -80,6 +80,9 @@ export class Order extends BaseEntity {
|
||||
@Property({ type: 'decimal', precision: 10, scale: 0, default: 0 })
|
||||
deliveryFee: number = 0;
|
||||
|
||||
@Property({ type: 'decimal', precision: 10, scale: 0, default: 0 })
|
||||
packingFee: number = 0;
|
||||
|
||||
@Property({ type: 'decimal', precision: 10, scale: 0 })
|
||||
total!: number;
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ export class OrdersService {
|
||||
subTotal: cart.subTotal || 0,
|
||||
tax: cart.tax || 0,
|
||||
deliveryFee: cart.deliveryFee || 0,
|
||||
packingFee: 0,
|
||||
total: cart.total || 0,
|
||||
totalItems: cart.totalItems || 0,
|
||||
description: cart.description,
|
||||
@@ -169,13 +170,14 @@ export class OrdersService {
|
||||
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 deliveryFee = delivery.deliveryFeeType === DeliveryFeeTypeEnum.FIXED ? Number(delivery.deliveryFee) : 0;
|
||||
const packingFee = dto.packingFee ?? 0;
|
||||
const adminDiscount = dto.discountAmount ?? 0;
|
||||
const maxDiscount = subTotal - itemsDiscount;
|
||||
if (adminDiscount > maxDiscount) {
|
||||
throw new BadRequestException(OrderMessage.DISCOUNT_AMOUNT_EXCEEDS_ORDER_TOTAL);
|
||||
}
|
||||
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 order = await this.em.transactional(async em => {
|
||||
@@ -193,6 +195,7 @@ export class OrdersService {
|
||||
subTotal,
|
||||
tax: 0,
|
||||
deliveryFee,
|
||||
packingFee,
|
||||
total,
|
||||
totalItems,
|
||||
description: dto.description,
|
||||
|
||||
Reference in New Issue
Block a user