internal static double CalculateQuantity(string strFormula, S50cBO18.ItemTransactionDetail TransactionDetail, bool UseQuantityFactor) { S50cUtil18.MathFunctions mathUtil = new S50cUtil18.MathFunctions(); UnitOfMeasure oUnit; S50cBL18.BSOExpressionParser objBSOExpressionParser = new S50cBL18.BSOExpressionParser(); double result = 0; if (!string.IsNullOrEmpty(strFormula)) { result = 0; string tempres = objBSOExpressionParser.ParseFormula(strFormula, TransactionDetail); double.TryParse(tempres, out result); } else { result = TransactionDetail.Quantity; } if (UseQuantityFactor) { if (TransactionDetail.QuantityFactor != 1 && TransactionDetail.QuantityFactor != 0) { result = result / TransactionDetail.QuantityFactor; } } oUnit = APIEngine.DSOCache.UnitOfMeasureProvider.GetUnitOfMeasure(TransactionDetail.UnitOfSaleID); if (oUnit != null) { result = mathUtil.MyRoundEx(result, oUnit.MaximumDecimals); } oUnit = null; objBSOExpressionParser = null; mathUtil = null; return(result); }
internal static S50cBO18.ItemTransactionDetail AddStockDetail(S50cBL18.BSOStockTransaction StockTransaction, short warehouseId, string itemId, double Quantity) { double unitPrice = APIEngine.DSOCache.ItemProvider.GetItemAverageCostPrice(itemId, StockTransaction.Transaction.BaseCurrency); var transDetail = new S50cBO18.ItemTransactionDetail(); transDetail.LineItemID = StockTransaction.Transaction.Details.Count + 1; transDetail.BaseCurrency = StockTransaction.Transaction.BaseCurrency; transDetail.CreateDate = StockTransaction.Transaction.CreateDate; transDetail.ActualDeliveryDate = StockTransaction.Transaction.ActualDeliveryDate; transDetail.PartyTypeCode = StockTransaction.Transaction.PartyTypeCode; transDetail.PartyID = StockTransaction.Transaction.PartyID; transDetail.WarehouseID = warehouseId; transDetail.WarehouseOutgoing = transDetail.WarehouseID; transDetail.WarehouseReceipt = transDetail.WarehouseID; transDetail.PhysicalQtyRule = StockQtyRuleEnum.stkQtyNone; var item = APIEngine.DSOCache.ItemProvider.GetItemForTransactionDetail(itemId, transDetail.BaseCurrency, "", true); if (item != null) { transDetail.ItemID = item.ItemID; transDetail.Description = item.Description; transDetail.TaxableGroupID = item.TaxableGroupID; transDetail.ItemType = item.ItemType; transDetail.FamilyID = item.Family.FamilyID; transDetail.UnitList = item.UnitList.Clone(); transDetail.WeightUnitOfMeasure = item.WeightUnitOfMeasure; transDetail.WeightMeasure = item.WeightMeasure; transDetail.Graduation = item.Graduation; transDetail.ItemTax = item.ItemTax; transDetail.ItemTax2 = item.ItemTax2; transDetail.ItemTax3 = item.ItemTax3; transDetail.PhysicalQtyRule = S50cSys18.StockQtyRuleEnum.stkQtyReceipt; transDetail.ProductCategory = item.ProductCategory; transDetail.ItemExtraInfo.ItemQuantityCalcFormula = item.ItemQuantityCalcFormula; if (item.UnitList.IsInCollection(transDetail.UnitOfSaleID)) { transDetail.UnitOfSaleID = transDetail.UnitOfSaleID; } else { transDetail.UnitOfSaleID = item.GetDefaultUnitForTransaction(StockTransaction.Transaction.TransDocType); } } transDetail.SetUnitOfSaleID(transDetail.UnitOfSaleID); transDetail.SetQuantity(Quantity); transDetail.QntyAvailableBalanceCount = Quantity; //transDetail.Quantity1 = 0; //transDetail.Quantity2 = 0; //transDetail.Quantity3 = 0; //transDetail.Quantity4 = 0; if (StockTransaction.TransactionTaxIncluded) { transDetail.TaxIncludedPrice = unitPrice; transDetail.UnitPrice = APIEngine.DSOCache.TaxesProvider.GetItemNetPrice( transDetail.TaxIncludedPrice, transDetail.TaxableGroupID, APIEngine.SystemSettings.SystemInfo.DefaultCountryID, APIEngine.SystemSettings.SystemInfo.TaxRegionID); } else { transDetail.UnitPrice = unitPrice; transDetail.TaxIncludedPrice = APIEngine.DSOCache.TaxesProvider.GetItemTaxIncludePrice( transDetail.UnitPrice, transDetail.TaxableGroupID, APIEngine.SystemSettings.SystemInfo.DefaultCountryID, APIEngine.SystemSettings.SystemInfo.TaxRegionID); } S50cUtil18.MathFunctions mathUtil = new S50cUtil18.MathFunctions(); if (transDetail.DiscountPercent == 0 && (transDetail.CumulativeDiscountPercent1 != 0 || transDetail.CumulativeDiscountPercent2 != 0 || transDetail.CumulativeDiscountPercent3 != 0)) { transDetail.DiscountPercent = mathUtil.GetCumulativeDiscount(transDetail.CumulativeDiscountPercent1, transDetail.CumulativeDiscountPercent2, transDetail.CumulativeDiscountPercent3); } if (transDetail.DiscountPercent != 0 && (transDetail.CumulativeDiscountPercent1 == 0 && transDetail.CumulativeDiscountPercent2 == 0 && transDetail.CumulativeDiscountPercent3 == 0)) { transDetail.CumulativeDiscountPercent1 = transDetail.DiscountPercent; } item = null; return(transDetail); }