From 4cc5794ea586431cc9a19c092521e17e89f8793d Mon Sep 17 00:00:00 2001 From: Fadli Date: Sun, 21 Aug 2022 01:51:46 +0700 Subject: [PATCH] - fix auto update price elang --- src/transaction/transaction.service.ts | 49 +++++++++++++------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index 2444f95..a298328 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -591,34 +591,35 @@ export class TransactionService { let costInventory = product_price.price; - if (hitSupplier.harga != product_price.price) { - console.log("priceupdate1supplier", hitSupplier.harga) - console.log("priceupdate1normal", product_price.price) - product_price.endDate = new Date(); - costInventory = hitSupplier.harga; - const listActivePrice = - await this.productHistoryPriceService.getAllActivePriceByProduct( - product.id, - ); + if (hitSupplier.harga != undefined) { + if (hitSupplier.harga != product_price.price) { + console.log("priceupdate1supplier", hitSupplier.harga) + console.log("priceupdate1normal", product_price.price) + product_price.endDate = new Date(); + costInventory = hitSupplier.harga; + const listActivePrice = + await this.productHistoryPriceService.getAllActivePriceByProduct( + product.id, + ); - await this.productHistoryPriceService.updateEndDate(product.id); + await this.productHistoryPriceService.updateEndDate(product.id); - listActivePrice.map(async (x) => { - const newProductPrice = new ProductHistoryPrice(); + listActivePrice.map(async (x) => { + const newProductPrice = new ProductHistoryPrice(); - newProductPrice.id = uuid.v4(); - newProductPrice.type = x.type; - newProductPrice.price = hitSupplier.harga; - newProductPrice.mark_up_price = x.mark_up_price; - newProductPrice.startDate = new Date(); - newProductPrice.product = product; - newProductPrice.partner = x.partner; - await this.productHistoryPriceService.create(newProductPrice); - - product_price = newProductPrice; - }); - } + newProductPrice.id = uuid.v4(); + newProductPrice.type = x.type; + newProductPrice.price = hitSupplier.harga; + newProductPrice.mark_up_price = x.mark_up_price; + newProductPrice.startDate = new Date(); + newProductPrice.product = product; + newProductPrice.partner = x.partner; + await this.productHistoryPriceService.create(newProductPrice); + product_price = newProductPrice; + }); + } + } try { //TRANSACTION DATA await this.connection.transaction(async (manager) => {