private void CalculateSubTotal(DataRow detailRow) { decimal qty = ACMS.Convert.ToDecimal(detailRow["nQuantity"]); decimal unitPrice = ACMS.Convert.ToDecimal(detailRow["mUnitPrice"]); decimal subtotal = qty * unitPrice; if (NCategoryID == 10 && myWantToUpgradeMemberPackageTable != null && myWantToUpgradeMemberPackageTable.Rows.Count > 0) { if (ACMS.Convert.ToInt32(myWantToUpgradeMemberPackageTable.Rows[0]["nCategoryID"]) == 1 || ACMS.Convert.ToInt32(myWantToUpgradeMemberPackageTable.Rows[0]["nCategoryID"]) == 2 || ACMS.Convert.ToInt32(myWantToUpgradeMemberPackageTable.Rows[0]["nCategoryID"]) == 3 || ACMS.Convert.ToInt32(myWantToUpgradeMemberPackageTable.Rows[0]["nCategoryID"]) == 5 ) { decimal oldPackagePriceInDtl = ACMS.Convert.ToDecimal(detailRow["OldPackagePrice"]); subtotal -=oldPackagePriceInDtl; decimal oldMemberPackageListPrice = ACMS.Convert.ToDecimal(WantToUpgradeMemberPackageRow["OldMemberPackageListPrice"]); //old package with discount minus // decimal amtNeedToSubtract = 0; // amtNeedToSubtract = oldMemberPackageListPrice >= subtotal ? subtotal : oldMemberPackageListPrice; // subtotal -= amtNeedToSubtract; // oldMemberPackageListPrice = oldMemberPackageListPrice - amtNeedToSubtract; // WantToUpgradeMemberPackageRow["OldMemberPackageListPrice"] = oldMemberPackageListPrice < 0 ? 0 : oldMemberPackageListPrice; // detailRow["OldPackagePrice"] = oldPackagePriceInDtl + amtNeedToSubtract; // // detailRow["OldPackagePrice"] = oldPackagePriceInDtl ; detailRow["OldPackagePrice"]=oldMemberPackageListPrice; } else if (ACMS.Convert.ToInt32(myWantToUpgradeMemberPackageTable.Rows[0]["nCategoryID"]) == 4 || ACMS.Convert.ToInt32(myWantToUpgradeMemberPackageTable.Rows[0]["nCategoryID"]) == 5 || ACMS.Convert.ToInt32(myWantToUpgradeMemberPackageTable.Rows[0]["nCategoryID"]) == 6 ) { if (ACMS.Convert.ToInt32(WantToUpgradeMemberPackageRow["FNew"]) == 0) { decimal oldPackageUsageInDtl = ACMS.Convert.ToDecimal(detailRow["OldPackageUsage"]); subtotal -=oldPackageUsageInDtl; decimal oldMemberPackageUsage = ACMS.Convert.ToDecimal(WantToUpgradeMemberPackageRow["OldMemberPackageUsage"]); decimal amtNeedToSubtract = 0; amtNeedToSubtract = oldMemberPackageUsage >= subtotal ? subtotal : oldMemberPackageUsage; subtotal -= amtNeedToSubtract; oldMemberPackageUsage = oldMemberPackageUsage - amtNeedToSubtract; WantToUpgradeMemberPackageRow["OldMemberPackageUsage"] = oldMemberPackageUsage < 0 ? 0 : oldMemberPackageUsage; detailRow["OldPackageUsage"] = oldPackageUsageInDtl + amtNeedToSubtract; } } if (subtotal < 0) subtotal = 0; } //2006 if (detailRow["strDiscountCode"] != DBNull.Value) { TblPromotion promotion = new TblPromotion(); promotion.StrPromotionCode = detailRow["strDiscountCode"].ToString(); promotion.SelectOne(); decimal discountValue = (decimal)(promotion.DDiscountValue.IsNull ? 0 : promotion.DDiscountValue.Value); decimal discountPercent = (decimal)(promotion.DDiscountPercent.IsNull ? 0 : promotion.DDiscountPercent.Value); decimal discountAmt = 0; if (discountPercent > 0 && discountValue <= 0) { discountAmt = decimal.Round((subtotal * discountPercent / 100), 2); } else { discountAmt = discountValue; } detailRow["DiscountAmt"] = discountAmt; // Get DiscountAmt is this 2 field is empty // No write now coz no time. coz if implement correct, this situation should not happen // if (detailRow["DiscountAmt"] != DBNull.Value) { //decimal discountAmt = ACMS.Convert.ToDecimal(detailRow["DiscountAmt"]); subtotal = (subtotal) - discountAmt; } } detailRow["mSubTotal"] = decimal.Round(subtotal, 2); }
public void RecalculateAll() { decimal nettAmount = 0; decimal subtotal = 0; decimal nettAmountwGST = 0; Boolean isAllPricesWithGST = true; Boolean isAllPricesNoGST = false; //To check all items are with GST price or not, also cannot contain any discount foreach (DataRow r in myReceiptItemsTable.Rows) { if (myCategoryID == 7 || myCategoryID == 36 || myCategoryID == 37) { TblCreditPackage pkg = new TblCreditPackage(); pkg.StrCreditPackageCode = r["strCode"].ToString(); pkg.SelectOne(); if (pkg.MListPriceWGST.IsNull || ACMS.Convert.ToDecimal(pkg.MListPriceWGST) == 0 || r["strDiscountCode"].ToString() != "" || myReceiptMasterTable.Rows[0]["strDiscountCode"].ToString() != "") { isAllPricesWithGST = false; break; } pkg.Dispose(); } if (myCategoryID == 38) { isAllPricesWithGST = false; isAllPricesNoGST = true; break; } else { if (myCategoryID == 8 || myCategoryID == 9) { TblPackageGroup pkg = new TblPackageGroup(); pkg.StrPackageGroupCode = r["strCode"].ToString(); pkg.SelectOne(); if (pkg.MListPriceWGST.IsNull || ACMS.Convert.ToDecimal(pkg.MListPriceWGST) == 0 || r["strDiscountCode"].ToString() != "" || myReceiptMasterTable.Rows[0]["strDiscountCode"].ToString() != "") { isAllPricesWithGST = false; break; } pkg.Dispose(); } else { TblPackage pkg = new TblPackage(); pkg.StrPackageCode = r["strCode"].ToString(); pkg.SelectOne(); if (pkg.MListPriceWGST.IsNull || ACMS.Convert.ToDecimal(pkg.MListPriceWGST) == 0 || r["strDiscountCode"].ToString() != "" || myReceiptMasterTable.Rows[0]["strDiscountCode"].ToString() != "") { isAllPricesWithGST = false; break; } pkg.Dispose(); } } } foreach (DataRow r in myReceiptItemsTable.Rows) { if ((myCategoryID == 7 || myCategoryID == 36 || myCategoryID == 37) && isAllPricesWithGST) { TblCreditPackage pkg = new TblCreditPackage(); pkg.StrCreditPackageCode = r["strCode"].ToString(); pkg.SelectOne(); if (pkg.MListPriceWGST.IsNull == false && ACMS.Convert.ToDecimal(pkg.MListPriceWGST) != 0) { subtotal = ACMS.Convert.ToDecimal(r["nQuantity"]) * ACMS.Convert.ToDecimal(pkg.MListPriceWGST); nettAmountwGST += subtotal; } pkg.Dispose(); } else { if ((myCategoryID == 8 || myCategoryID == 9) && isAllPricesWithGST) { TblPackageGroup pkg = new TblPackageGroup(); pkg.StrPackageGroupCode = r["strCode"].ToString(); pkg.SelectOne(); if (pkg.MListPriceWGST.IsNull == false && ACMS.Convert.ToDecimal(pkg.MListPriceWGST) != 0) { subtotal = ACMS.Convert.ToDecimal(r["nQuantity"]) * ACMS.Convert.ToDecimal(pkg.MListPriceWGST); nettAmountwGST += subtotal; } pkg.Dispose(); } else if (isAllPricesWithGST) { TblPackage pkg = new TblPackage(); pkg.StrPackageCode = r["strCode"].ToString(); pkg.SelectOne(); if (pkg.MListPriceWGST.IsNull == false && ACMS.Convert.ToDecimal(pkg.MListPriceWGST) != 0) { subtotal = ACMS.Convert.ToDecimal(r["nQuantity"]) * ACMS.Convert.ToDecimal(pkg.MListPriceWGST); nettAmountwGST += subtotal; } pkg.Dispose(); } } subtotal = ACMS.Convert.ToDecimal(r["mSubTotal"]); nettAmount += subtotal; } if (myCategoryID == 11 || myCategoryID == 12) { if (nettAmount < 0) nettAmount = 0; } myReceiptMasterTable.Rows[0]["mNettAmount"] = nettAmount; if (StrDiscountCode.HasValue && StrDiscountCode.ToString().Length > 0) { TblPromotion promotion = new TblPromotion(); promotion.StrPromotionCode = myReceiptMasterTable.Rows[0]["strDiscountCode"].ToString(); promotion.SelectOne(); decimal discountValue = (decimal)(promotion.DDiscountValue.IsNull ? 0 : promotion.DDiscountValue.Value); decimal discountPercent = (decimal)(promotion.DDiscountPercent.IsNull ? 0 : promotion.DDiscountPercent.Value); decimal discountAmt = 0; if (discountPercent > 0 && discountValue <= 0) { discountAmt = decimal.Round((MNettAmount * discountPercent / 100), 2); } else { discountAmt = discountValue; } if (discountAmt > ACMS.Convert.ToDecimal(myReceiptMasterTable.Rows[0]["mNettAmount"])) discountAmt = ACMS.Convert.ToDecimal(myReceiptMasterTable.Rows[0]["mNettAmount"]); myReceiptMasterTable.Rows[0]["DiscountAmt"] = discountAmt; myReceiptMasterTable.Rows[0]["mNettAmount"] = ACMS.Convert.ToDecimal(myReceiptMasterTable.Rows[0]["mNettAmount"]) - discountAmt; } if (StrDeposit.ToString() != "") { isAllPricesWithGST = false; TblMemberPackage myPackage = new TblMemberPackage(); myPackage.StrReceiptNo = StrDeposit; DataTable tblMemberPkg = myPackage.SelectOneReceipt(); DataTable tblConverted = new DataTable(); DataTable tblCreditConverted = new DataTable(); if (tblMemberPkg.Rows.Count > 0) tblConverted = myPackage.SelectConvertedPackageID(System.Convert.ToInt32(tblMemberPkg.Rows[0]["nPackageID"])); TblMemberCreditPackage myCreditPackage = new TblMemberCreditPackage(); myCreditPackage.StrReceiptNo = StrDeposit; tblCreditConverted = myCreditPackage.SelectAllWstrReceiptNoLogic(); if (tblCreditConverted.Rows.Count > 0) tblConverted = myPackage.SelectConvertedPackageID(System.Convert.ToInt32(tblCreditConverted.Rows[0]["nCreditPackageID"])); if (tblConverted.Rows.Count > 0) { decimal DepositAmount = System.Convert.ToDecimal(tblConverted.Rows[0]["mConverted"]); myReceiptMasterTable.Rows[0]["mNettAmount"] = ACMS.Convert.ToDecimal(myReceiptMasterTable.Rows[0]["mNettAmount"]) - DepositAmount; myReceiptMasterTable.Rows[0]["strRemarks"] = "Deposit from Convert"; } //else if (tblCreditConverted.Rows.Count > 0) //{ // decimal DepositAmount = System.Convert.ToDecimal(tblCreditConverted.Rows[0]["mConverted"]); // myReceiptMasterTable.Rows[0]["mNettAmount"] = ACMS.Convert.ToDecimal(myReceiptMasterTable.Rows[0]["mNettAmount"]) - DepositAmount; // myReceiptMasterTable.Rows[0]["strRemarks"] = "Deposit from Credit Convert"; //} else { TblReceipt DepositReceipt = new TblReceipt(); DepositReceipt.StrReceiptNo = StrDeposit; DataTable tblDeposit = DepositReceipt.SelectOne(); decimal DepositAmount = (decimal)(DepositReceipt.MNettAmount.IsNull ? 0 : DepositReceipt.MNettAmount.Value); myReceiptMasterTable.Rows[0]["mNettAmount"] = ACMS.Convert.ToDecimal(myReceiptMasterTable.Rows[0]["mNettAmount"]) - decimal.Round(DepositAmount, 2); myReceiptMasterTable.Rows[0]["strRemarks"] = "Deposit from " + StrDeposit; } } //Derek Instalment Plan - Pay OS if (myCategoryID == 0) { myReceiptMasterTable.Rows[0]["mGSTAmount"] = MTotalAmount - MNettAmount; } else { if (isAllPricesNoGST) { myReceiptMasterTable.Rows[0]["mGSTAmount"] = 0; myReceiptMasterTable.Rows[0]["mTotalAmount"] = decimal.Round(MNettAmount, 2); } else { myReceiptMasterTable.Rows[0]["mGSTAmount"] = decimal.Round(MNettAmount * myGSTRate, 2); if (isAllPricesWithGST) { myReceiptMasterTable.Rows[0]["mTotalAmount"] = decimal.Round(nettAmountwGST, 2); } else { myReceiptMasterTable.Rows[0]["mTotalAmount"] = MNettAmount + MGSTAmount; } } } CalculateOutStanding(); if (WantToUpgradeMemberPackageTable.Rows.Count > 0) { double usageBal = 0; double mTotalUsageWGST = 0; //Check convert packages' price all with GST bool isConvertAllPricesWithGST=true; double mTotalUsage = 0; if (isAllPricesWithGST) { double mTotalAmount=0; for (int i = 0; i < WantToUpgradeMemberPackageTable.Rows.Count; i++) { int nCategory = Convert.ToInt32(WantToUpgradeMemberPackageTable.Rows[i]["nCategoryID"]); if (nCategory == 7 || nCategory == 36 || nCategory == 37) { TblCreditPackage pkg = new TblCreditPackage(); pkg.StrCreditPackageCode = WantToUpgradeMemberPackageTable.Rows[i]["strPackageCode"].ToString(); pkg.SelectOne(); if (pkg.MListPriceWGST.IsNull || WantToUpgradeMemberPackageTable.Rows[i]["strDiscountCode"].ToString() != "") { isConvertAllPricesWithGST = false; break; } mTotalAmount += pkg.MCreditAmount.ToDouble(); mTotalUsage += Convert.ToDouble(WantToUpgradeMemberPackageTable.Rows[i]["UsageBalAmt"]); mTotalUsageWGST += pkg.MListPriceWGST.ToDouble(); pkg.Dispose(); } else { TblPackage pkg = new TblPackage(); pkg.StrPackageCode = WantToUpgradeMemberPackageTable.Rows[i]["strPackageCode"].ToString(); pkg.SelectOne(); if (pkg.MListPriceWGST.IsNull || WantToUpgradeMemberPackageTable.Rows[i]["strDiscountCode"].ToString() != "") { isConvertAllPricesWithGST = false; break; } mTotalAmount += pkg.MListPrice.ToDouble(); mTotalUsage += Convert.ToDouble(WantToUpgradeMemberPackageTable.Rows[i]["UsageBalAmt"]); mTotalUsageWGST += pkg.MListPriceWGST.ToDouble(); pkg.Dispose(); } } if (mTotalAmount != mTotalUsage) isConvertAllPricesWithGST = false; } for (int i = 0; i < WantToUpgradeMemberPackageTable.Rows.Count; i++) { int mainSession = Convert.ToInt32(WantToUpgradeMemberPackageTable.Rows[i]["nMaxSession"]) - Convert.ToInt32(WantToUpgradeMemberPackageTable.Rows[i]["nFreeSession"]); int balSession = mainSession - Convert.ToInt32(WantToUpgradeMemberPackageTable.Rows[i]["UsedSession"]); usageBal += Convert.ToDouble(WantToUpgradeMemberPackageTable.Rows[i]["UsageBalAmt"]); } //RecalculateAfterUpgrade(Convert.ToDecimal(usageBal)); if (isConvertAllPricesWithGST && isAllPricesWithGST) { nettAmount = ACMS.Convert.ToDecimal(myReceiptMasterTable.Rows[0]["mNettAmount"]) - Convert.ToDecimal(usageBal); myReceiptMasterTable.Rows[0]["mNettAmount"] = decimal.Round(nettAmount, 2); myReceiptMasterTable.Rows[0]["mGSTAmount"] = decimal.Round(MNettAmount * myGSTRate, 2); myReceiptMasterTable.Rows[0]["mTotalAmount"] = decimal.Round(nettAmountwGST - Convert.ToDecimal(mTotalUsageWGST),2); myReceiptMasterTable.Rows[0]["mOutstandingAmount"] = myReceiptMasterTable.Rows[0]["mTotalAmount"]; } else { nettAmount = ACMS.Convert.ToDecimal(myReceiptMasterTable.Rows[0]["mNettAmount"]) - Convert.ToDecimal(usageBal); myReceiptMasterTable.Rows[0]["mNettAmount"] = decimal.Round(nettAmount, 2); myReceiptMasterTable.Rows[0]["mGSTAmount"] = decimal.Round(MNettAmount * myGSTRate, 2); myReceiptMasterTable.Rows[0]["mTotalAmount"] = MNettAmount + MGSTAmount; myReceiptMasterTable.Rows[0]["mOutstandingAmount"] = myReceiptMasterTable.Rows[0]["mTotalAmount"]; } } }