From b45a85c2e480f59d0a8ad384ecdec51ec19df8a2 Mon Sep 17 00:00:00 2001 From: "a.bouhuolia" Date: Wed, 2 Jun 2021 12:31:12 +0200 Subject: [PATCH] fix: inventory item detail bug. --- .../FinancialStatements/CashFlow/CashFlow.ts | 4 +-- .../InventoryDetails/InventoryDetails.ts | 26 ++++++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/server/src/services/FinancialStatements/CashFlow/CashFlow.ts b/server/src/services/FinancialStatements/CashFlow/CashFlow.ts index d000210b8..8fae30434 100644 --- a/server/src/services/FinancialStatements/CashFlow/CashFlow.ts +++ b/server/src/services/FinancialStatements/CashFlow/CashFlow.ts @@ -700,7 +700,7 @@ class CashFlowStatement extends FinancialSheet implements ICashFlowStatement { sections, this.isAccountLeafNoneZero.bind(this), MAP_CONFIG - ); + ) || []; } /** @@ -713,7 +713,7 @@ class CashFlowStatement extends FinancialSheet implements ICashFlowStatement { sections, this.isAccountsSectionHasChildren.bind(this), MAP_CONFIG - ); + ) || []; } /** diff --git a/server/src/services/FinancialStatements/InventoryDetails/InventoryDetails.ts b/server/src/services/FinancialStatements/InventoryDetails/InventoryDetails.ts index 1bdbadc41..08ee86a60 100644 --- a/server/src/services/FinancialStatements/InventoryDetails/InventoryDetails.ts +++ b/server/src/services/FinancialStatements/InventoryDetails/InventoryDetails.ts @@ -191,7 +191,7 @@ export default class InventoryDetails extends FinancialSheet { const quantityMovement = amountMovement(transaction.quantity); const cost = defaultTo(transaction?.costLotAggregated.cost, 0); - // Profit margin. + // Profit margin. const profitMargin = total - cost; // Value from computed cost in `OUT` or from total sell price in `IN` transaction. @@ -268,8 +268,11 @@ export default class InventoryDetails extends FinancialSheet { )[] { const transactions = this.getItemTransactions(item); const openingValuation = this.getItemOpeingValuation(item); - const closingValuation = this.getItemClosingValuation(item, transactions); - + const closingValuation = this.getItemClosingValuation( + item, + transactions, + openingValuation + ); const hasTransactions = transactions.length > 0; const isItemHasOpeningBalance = this.isItemHasOpeningBalance(item.id); @@ -314,17 +317,21 @@ export default class InventoryDetails extends FinancialSheet { */ private getItemClosingValuation( item: IItem, - transactions: IInventoryDetailsItemTransaction[] + transactions: IInventoryDetailsItemTransaction[], + openingValuation: IInventoryDetailsOpening ): IInventoryDetailsOpening { const value = sumBy(transactions, 'valueMovement.number'); const quantity = sumBy(transactions, 'quantityMovement.number'); const profitMargin = sumBy(transactions, 'profitMargin.number'); + const closingQuantity = quantity + openingValuation.quantity.number; + const closingValue = value + openingValuation.value.number; + return { nodeType: INodeTypes.CLOSING_ENTRY, date: this.getDateMeta(this.query.toDate), - quantity: this.getTotalNumberMeta(quantity), - value: this.getTotalNumberMeta(value), + quantity: this.getTotalNumberMeta(closingQuantity), + value: this.getTotalNumberMeta(closingValue), profitMargin: this.getTotalNumberMeta(profitMargin), }; } @@ -385,7 +392,12 @@ export default class InventoryDetails extends FinancialSheet { * @returns {IInventoryDetailsItem[]} */ private filterItemsNodes(items: IInventoryDetailsItem[]) { - return filterDeep(items, this.isFilterNode.bind(this), MAP_CONFIG); + const filtered = filterDeep( + items, + this.isFilterNode.bind(this), + MAP_CONFIG + ); + return defaultTo(filtered, []); } /**