Ejemplo n.º 1
0
        public static void InitMemberCreditPackageRowInPOS(DataRow memberCreditPackageRow, string strReceiptNo,
			string strMembershipID, string strCreditPackageCode, bool isFree)
        {
            TblCreditPackage creditPackage = new TblCreditPackage();
            creditPackage.StrCreditPackageCode = strCreditPackageCode;
            creditPackage.SelectOne();

            int validMonths = creditPackage.NValidMonths.IsNull ? 0 : creditPackage.NValidMonths.Value;
            memberCreditPackageRow["strMembershipID"] = strMembershipID;
            memberCreditPackageRow["strCreditPackageCode"] = strCreditPackageCode;
            memberCreditPackageRow["dtPurchaseDate"] = System.DateTime.Today.Date;
            //if (creditPackage.NCategoryID == 7)
            //memberCreditPackageRow["dtExpiryDate"] = System.DateTime.Today.AddMonths(validMonths).AddDays(-1);
            memberCreditPackageRow["fFree"] = isFree ? 1 : 0;
            memberCreditPackageRow["strReceiptNo"] = strReceiptNo;
            memberCreditPackageRow["nStatusID"] = 0;
            memberCreditPackageRow["nEmployeeID"] = ACMSLogic.User.EmployeeID;
            memberCreditPackageRow["dtLastEditDate"] = System.DateTime.Now;
            memberCreditPackageRow["mTopupAmount"] = 0;
        }
Ejemplo n.º 2
0
        public bool SavePOS(ACMSLogic.POS pos)
        {
            ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider();
            //ACMSDAL.ConnectionProvider connProvider1 = new ConnectionProvider();

            try
            {
                DataTable branchReceiptNoTable = new DataTable();
                int latestReceiptNo = GetLatestReceiptNo(connProvider, pos, ref branchReceiptNoTable) + 1;
                string receiptNo = pos.StrBranchCode.ToString().Trim() + pos.NTerminalID.ToString().Trim() + latestReceiptNo.ToString().Trim();

                pos.StrReceiptNo = receiptNo;

                //Derek Instalment Plan Need to Add PaymentPlan Table Here
                //Get pos.NCategoryID here to determine if the item is Pay O/S
                //Here Can get the new Receipt No Value
                //3 Main table that always need to update

                TblReceipt receipt = new TblReceipt();
                TblReceiptEntries receiptEntries = new TblReceiptEntries();
                TblReceiptPayment receiptPayment = new TblReceiptPayment();
                TblPaymentPlan myPaymentPlan = new TblPaymentPlan();

                receipt.MainConnectionProvider = connProvider;
                receiptEntries.MainConnectionProvider = connProvider;
                receiptPayment.MainConnectionProvider = connProvider;
                myPaymentPlan.MainConnectionProvider = connProvider;

                connProvider.OpenConnection();
                connProvider.BeginTransaction("SaveReceipt");

                DataTable receiptTable = pos.ReceiptMasterTable.Copy();
                DataTable receiptEntriesTable = pos.ReceiptItemsTable.Copy();
                DataTable receiptPaymentTable = pos.ReceiptPaymentTable.Copy();
                DataTable freeMemberPackageTable = receipt.FillSchema("Select * From tblMemberPackage"); // use to store the free member package.
                DataTable freeMemberCreditPackageTable = receipt.FillSchema("Select * From tblMemberCreditPackage");

                if (pos.PaymentPlanTable != null && pos.NCategoryID != 0)
                {
                    DataTable paymentPlanTable = pos.PaymentPlanTable.Copy();

                    if (paymentPlanTable != null && paymentPlanTable.Rows.Count > 0)
                    {
                        foreach (DataRow r in paymentPlanTable.Rows)
                        {
                            r["strReceiptNo"] = pos.StrReceiptNo;

                            if (r["nInstalmentNo"].ToString() == "1")
                            {
                                r["strPaymentReceiptNo"] = pos.StrReceiptNo;

                                myPaymentPlan.IPPPrimaryEntry(r["strReceiptNo"].ToString(), Convert.ToInt32(r["nInstalmentNo"]),
                                                                r["strPaymentReceiptNo"].ToString(), Convert.ToDecimal(r["mPaymentPlanAmt"]),
                                                                Convert.ToDecimal(r["mPaidAmount"]), Convert.ToDecimal(r["mAdjustedPaymentPlanAmt"]),
                                                                Convert.ToDecimal(r["mOutstandingAmt"]), Convert.ToDateTime(r["dtPaymentDate"]),
                                                                Convert.ToDateTime(r["dtDueDate"]), Convert.ToDateTime(r["dtFinalDueDate"]),
                                                                Convert.ToInt32(r["nPaymentPlanID"]));

                            }
                            else
                            {
                                myPaymentPlan.IPPSubsequentEntry(r["strReceiptNo"].ToString(), Convert.ToInt32(r["nInstalmentNo"]),
                                                                    Convert.ToDecimal(r["mPaymentPlanAmt"]), Convert.ToDecimal(r["mPaidAmount"]),
                                                                    Convert.ToDecimal(r["mAdjustedPaymentPlanAmt"]), Convert.ToDecimal(r["mOutstandingAmt"]),
                                                                    Convert.ToDateTime(r["dtDueDate"]), Convert.ToDateTime(r["dtFinalDueDate"]),
                                                                    Convert.ToInt32(r["nPaymentPlanID"]));
                            }
                        }
                        paymentPlanTable.AcceptChanges();
                    }
                    pos.PaymentPlanTable.AcceptChanges();

                }
                else if (pos.PaymentPlanTable != null && pos.NCategoryID == 0)
                {
                    DataTable paymentPlanTable = pos.PaymentPlanTable.Copy();

                    if (paymentPlanTable != null && paymentPlanTable.Rows.Count > 0)
                    {
                        foreach (DataRow r in paymentPlanTable.Rows)
                        {
                            if (r["lastestUpdate"].ToString() == "1")
                            {
                                r["strPaymentReceiptNo"] = pos.StrReceiptNo;

                                myPaymentPlan.IPPPrimaryUpdate(Convert.ToInt32(r["nPaymentPlanID"]), r["strReceiptNo"].ToString(),
                                                                Convert.ToInt32(r["nInstalmentNo"]), r["strPaymentReceiptNo"].ToString(),
                                                                Convert.ToDecimal(r["mPaidAmount"]), Convert.ToDecimal(r["mAdjustedPaymentPlanAmt"]),
                                                                Convert.ToDecimal(r["mOutstandingAmt"]), Convert.ToDateTime(r["dtPaymentDate"]));

                            }
                            else
                            {
                                myPaymentPlan.IPPSubsequentUpdate(Convert.ToInt32(r["nPaymentPlanID"]), r["strReceiptNo"].ToString(),
                                                                    Convert.ToInt32(r["nInstalmentNo"]), Convert.ToDecimal(r["mPaidAmount"]),
                                                                    Convert.ToDecimal(r["mAdjustedPaymentPlanAmt"]), Convert.ToDecimal(r["mOutstandingAmt"]));
                            }
                        }

                        //paymentPlanTable.AcceptChanges();
                    }
                    pos.PaymentPlanTable.AcceptChanges();
                }

                receipt.SaveData(receiptTable);
                receiptEntries.SaveData(receiptEntriesTable);
                receiptPayment.SaveData(receiptPaymentTable);

                receiptEntries.StrReceiptNo = pos.StrReceiptNo;
                DataTable savedReceiptEntriesTable = receiptEntries.SelectAllWstrReceiptNoLogic();

                pos.ReceiptMasterTable.AcceptChanges();

                if (pos.StrFreebieCode.HasValue && pos.StrFreebieCode.ToString() != "")
                {
                    //Update Bill Freebie here
                    if (pos.ReceiptFreebieTable.Rows.Count > 0)
                    {
                        TblReceiptFreebie receiptFreebie = new TblReceiptFreebie();
                        receiptFreebie.MainConnectionProvider = connProvider;
                        DataTable receiptFreebieTable = pos.ReceiptFreebieTable.Copy();

                        // Save Bill Receipt Freebie
                        receiptFreebie.SaveData(receiptFreebieTable);

                        //TblProductInventory proInven = new TblProductInventory();
                        //proInven.MainConnectionProvider = connProvider;

                        //// deduct stock
                        //foreach (DataRow r in receiptFreebieTable.Rows)
                        //{
                        //    proInven.IncreaseQuantity(r["strItemCode"].ToString(), pos.StrBranchCode, -1);
                        //}
                    }
                    if (pos.ReceiptPackageTable.Rows.Count > 0)
                    {
                        // update package

                        foreach (DataRow r in pos.ReceiptPackageTable.Rows)
                        {
                            TblCreditPackage p = new TblCreditPackage();
                            p.StrCreditPackageCode = r["strPackageCode"].ToString();
                            p.SelectOne();

                            if (p.StrDescription.ToString() != "Null")
                            {
                                DataRow rowToAdd = freeMemberCreditPackageTable.NewRow();

                                ACMSLogic.MemberPackage.InitMemberCreditPackageRowInPOS(rowToAdd, pos.StrReceiptNo, pos.StrMembershipID,
                                    r["strPackageCode"].ToString(), r["strPromotionCode"].ToString(), true);

                                // Add to freeMemberPackageTable and will save
                                freeMemberCreditPackageTable.Rows.Add(rowToAdd);
                            }
                            else
                            {
                                DataRow rowToAdd = freeMemberPackageTable.NewRow();

                                ACMSLogic.MemberPackage.InitMemberPackageRowInPOS(rowToAdd, pos.StrReceiptNo, pos.StrMembershipID,
                                    r["strPackageCode"].ToString(), r["strPromotionCode"].ToString(), true);

                                // Add to freeMemberPackageTable and will save
                                freeMemberPackageTable.Rows.Add(rowToAdd);
                            }
                        }
                    }
                    //else
                    //{
                    //    throw new Exception("Bill Freebie have no free any product or package although the strFreebieCode is not null");
                    //}
                }

                if (pos.ReceiptItemsFreebiePackageTable.Rows.Count > 0)
                {
                    foreach (DataRow r in pos.ReceiptItemsFreebiePackageTable.Rows)
                    {
                        TblCreditPackage p = new TblCreditPackage();
                        p.StrCreditPackageCode = r["strPackageCode"].ToString();
                        p.SelectOne();

                        if (p.StrDescription.ToString() != "Null")
                        {
                            DataRow rowToAdd = freeMemberCreditPackageTable.NewRow();

                            ACMSLogic.MemberPackage.InitMemberCreditPackageRowInPOS(rowToAdd, pos.StrReceiptNo, pos.StrMembershipID,
                                r["strPackageCode"].ToString(), r["strPromotionCode"].ToString(), true);

                            // Add to freeMemberPackageTable and will save
                            freeMemberCreditPackageTable.Rows.Add(rowToAdd);
                        }
                        else
                        {
                            DataRow rowToAdd = freeMemberPackageTable.NewRow();
                            // Kean Yiap
                            if (pos.NCategoryID == 34)
                            {
                                MemberPackage.InitMemberPackageRowInPOS(rowToAdd, pos.StrReceiptNo, pos.StrMembershipID, r["strPackageCode"].ToString(), "",
                                    true, -1, pos.dtPackageStart, pos.NProrateDays);
                            }
                            else
                            {
                                ACMSLogic.MemberPackage.InitMemberPackageRowInPOS(rowToAdd, pos.StrReceiptNo, pos.StrMembershipID,
                                    r["strPackageCode"].ToString(), r["strPromotionCode"].ToString(), true);
                            }
                            // Add to freeMemberPackageTable and will save
                            freeMemberPackageTable.Rows.Add(rowToAdd);
                        }
                    }
                }

                if (pos.ReceiptItemsFreebieProductTable.Rows.Count > 0)
                {
                    //					Update product
                    TblReceiptFreebie receiptFreebie = new TblReceiptFreebie();
                    receiptFreebie.MainConnectionProvider = connProvider;
                    DataTable receiptItemsFreebieProductTable = pos.ReceiptFreebieTable.Clone(); // i have to use this structure bcoz i wan to save to this table;

                    foreach (DataRow r in pos.ReceiptItemsFreebieProductTable.Rows)
                    {
                        DataRow rowToAdd = receiptItemsFreebieProductTable.NewRow();
                        rowToAdd["strReceiptNo"] = pos.StrReceiptNo;
                        rowToAdd["strItemCode"] = r["strProductCode"];
                        rowToAdd["strPromotionCode"] = r["strPromotionCode"];

                        DataRow[] tempRows = savedReceiptEntriesTable.Select("nTempEntryID = " + r["nEntryID"].ToString(),
                            "", DataViewRowState.CurrentRows);

                        if (tempRows.Length > 0)
                            rowToAdd["nEntryID"] = tempRows[0]["nEntryID"];

                        receiptItemsFreebieProductTable.Rows.Add(rowToAdd);
                    }

                    receiptFreebie.SaveData(receiptItemsFreebieProductTable);

                    //TblProductInventory proInven = new TblProductInventory();
                    //proInven.MainConnectionProvider = connProvider;

                    //foreach (DataRow r in receiptItemsFreebieProductTable.Rows)
                    //{
                    //    proInven.IncreaseQuantity(r["strItemCode"].ToString(), pos.StrBranchCode, -1);
                    //}
                }

                if (freeMemberPackageTable.Rows.Count > 0)
                {
                    // update the member package to database
                    TblMemberPackage memberPackage = new TblMemberPackage();
                    memberPackage.MainConnectionProvider = connProvider;
                    memberPackage.SaveData(freeMemberPackageTable);
                }

                if (freeMemberCreditPackageTable.Rows.Count > 0)
                {
                    // update the member package to database
                    TblMemberCreditPackage memberPackage = new TblMemberCreditPackage();
                    memberPackage.MainConnectionProvider = connProvider;
                    memberPackage.SaveData(freeMemberCreditPackageTable);
                }

            //part 2
                DeleteUselessIPP(connProvider, pos);
                UpdateRegistrationFee(connProvider, pos);
                UpdateOldPackSetDeactivate(connProvider, pos); //Update when upgrade
                PostToMemberCreditPackage(connProvider, pos);
                PostToMemberPackage(connProvider, pos);
                UpdateUsedCashVoucher(connProvider, pos);

                int ParentCategoryID = pos.NCategoryID;

                if (pos.NCategoryID == 10)
                {
                    ParentCategoryID = UpgradePackage(connProvider, pos);
                    if (ParentCategoryID == 10)
                    {
                        ParentCategoryID = UpgradeCreditPackage(connProvider, pos);
                    }
                }

                TopUpCreditPackage(connProvider, pos);
                TopUpSingleTreatmentTransaction(connProvider, pos);
                MakeDeposit(connProvider, pos);

                CashVoucherTransaction(connProvider, pos);
                LockerTransaction(connProvider, pos);
                ForgetCardTransaction(connProvider, pos);
                ReplaceMembershipCardTransaction(connProvider, pos);
                //MineralWaterTransaction(connProvider, pos);
                TblRewards rewardcode = new TblRewards();
                ACMSDAL.TblCategory category = new ACMSDAL.TblCategory();
                category.NCategoryID = pos.NCategoryID;
                category.SelectOne();
                int SalesCategory = ACMS.Convert.ToInt32(category.NSalesCategoryID);

                //Derek Instalment Plan - Here it assigned the Category to the Pay O/S Receipt Record
                if (pos.NCategoryID == 0)
                {
                    ParentCategoryID = PayOutstanding(connProvider, pos);
                    pos.StrRewardsCode = rewardcode.SelectRewards(ParentCategoryID, pos.StrBranchCode);
                }
                else
                    pos.StrRewardsCode = rewardcode.SelectRewards(pos.NCategoryID, pos.StrBranchCode);

                if (pos.StrRewardsCode.HasValue && pos.StrRewardsCode.ToString() != "" && pos.StrRewardsCode.ToString() != "Null")
                {
                    TblRewards rewards = new TblRewards();
                    rewards.StrRewardsCode = pos.StrRewardsCode.ToString();
                    rewards.SelectOne();

                    double dRewardPoint = 0;

                    double dRewardPercent = (rewards.DRewardsPercent.IsNull ? 0 : rewards.DRewardsPercent.Value);
                    double dRewardValue = (rewards.DRewardsValue.IsNull ? 0 : rewards.DRewardsValue.Value);

                    //jackie 23 others give 50% GIRO
                    //if (ParentCategoryID == 23 && pos.MNettAmount > 60)//pos.MNettAmount
                    //{
                    //    dRewardPercent = 50;

                    //}

                    if (dRewardPercent > 0 && dRewardValue == 0)
                    {
                        decimal mnettTotal = 0;

                        if (pos.MOutstandingAmount > 0)
                        {
                            mnettTotal = pos.MNettAmount - (pos.MOutstandingAmount - pos.MGSTAmount);
                        }
                        else
                        {
                            mnettTotal = pos.MNettAmount;
                        }

                        dRewardPoint = ((double)mnettTotal) * dRewardPercent / 100;
                    }
                    else
                    {
                        if (pos.NCategoryID == 0)
                        {
                            dRewardPoint = dRewardValue;
                        }
                    }
                    if (pos.NThisMonthBirthday == 1)
                    {
                        DialogResult result1 = MessageBox.Show("Member is having birthday this months. Do you want to give double point?", "Warning",
                        MessageBoxButtons.YesNo);

                        if (result1 == DialogResult.Yes)
                            dRewardPoint *= 2;
                    }

                    TblRewardsTransaction rewardTran = new TblRewardsTransaction();
                    rewardTran.MainConnectionProvider = connProvider;
                    if (pos.NCategoryID == 20)
                    {
                        rewardTran.StrMembershipID = pos.StrNewMembershipID;
                    }
                    else
                    {
                        rewardTran.StrMembershipID = pos.StrMembershipID;
                    }
                    rewardTran.DtDate = pos.DtDate;
                    rewardTran.NTypeID = 1;
                    rewardTran.NEmployeeID = pos.NCashierID;
                    rewardTran.DRewardsPoints = dRewardPoint;
                    rewardTran.StrReferenceNo = pos.StrReceiptNo;
                    if (dRewardPoint > 0) // rewards point > 0 then insert records //3004
                    {
                        rewardTran.Insert();
                    }
                }

                if (pos.StrRewardsCode.ToString() == "Null") pos.StrRewardsCode = "";

                DataTable QtyTable = receiptEntries.Get_StrCodeReceiptNo(pos.StrReceiptNo);
                //check is the receipt fully paid
                string Nett = pos.MNettAmount.ToString();
                string Outstanding = pos.MOutstandingAmount.ToString();

                //if (pos.MOutstandingAmount == 0 && (pos.NCategoryID == 11 || pos.NCategoryID == 12))
                //    PostToStock(connProvider, QtyTable, pos);

                receiptTable = pos.ReceiptMasterTable.Copy();
                int PosCategory = ACMS.Convert.ToInt32(receiptTable.Rows[0]["nCategoryID"]);
                if (PosCategory == 24)
                {
                    receiptTable.Rows[0]["fDeposit"] = true;
                    receipt.SaveData(receiptTable);
                }

                if (pos.StrBillReferenceNo != "")
                {
                    receiptTable.Rows[0]["strBillReferenceNo"] = pos.StrBillReferenceNo;
                    receipt.SaveData(receiptTable);
                }

                if (pos.NCategoryID == 0 || pos.NCategoryID == 10)
                {
                    receipt.StrReceiptNo = pos.StrReceiptNo;
                    receipt.SelectOne();
                    receipt.MOutstandingAmount = Convert.ToDecimal(pos.MOutstandingAmount);
                    receipt.NCategoryID = ParentCategoryID;
                    receipt.Update();
                    //TblReceipt receipt3 = new TblReceipt();
                    //receipt3.StrReceiptNo = pos.StrReceiptNo;
                    //receipt3.SelectOne();
                    //receipt3.MOutstandingAmount = Convert.ToDecimal(pos.MOutstandingAmount);
                    //receipt3.NCategoryID = ParentCategoryID;
                    //receipt3.Update();
                }

                if (pos.StrDeposit != "")
                {
                    receipt.StrReceiptNo = pos.StrDeposit;
                    DataTable tblDeposit = receipt.SelectOne();
                    if (tblDeposit.Rows.Count > 0)
                    {
                        receipt.FDeposit = false;
                        receipt.Update();

                    }
                    else
                    {
                        TblMemberPackage ConvertedPackage = new TblMemberPackage();
                        ConvertedPackage.NPackageID = ACMS.Convert.ToSqlInt32(pos.StrDeposit);
                        ConvertedPackage.NStatusID = 1;
                        ConvertedPackage.UpdateConvertedPackageStatus();
                    }
                }

                if (pos.ReceiptItemsTable.Select("", "", DataViewRowState.ModifiedCurrent).Length > 0)
                {
                    receiptEntriesTable = pos.ReceiptItemsTable.Copy();
                    receipt.SaveData(receiptEntriesTable);
                }
                //1503
                branchReceiptNoTable.Rows[0]["nReceiptNo"] = latestReceiptNo;

                SaveUpToDateReceiptNo(connProvider, branchReceiptNoTable);
                connProvider.CommitTransaction();

                if (pos.StrDeposit != "")
                {
                    TblReceipt receipt2 = new TblReceipt();
                    receipt2.StrReceiptNo = pos.StrDeposit;
                    receipt2.SelectOne();
                    receipt2.StrChildReceiptNo = receiptNo;
                    receipt2.Update();
                }
                return true;

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (connProvider.CurrentTransaction != null)
                    connProvider.CurrentTransaction.Dispose();
                if (connProvider.DBConnection != null)
                {
                    if (connProvider.DBConnection.State == ConnectionState.Open)
                        connProvider.DBConnection.Close();

                }
            }
        }
Ejemplo n.º 3
0
        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"];
                }
            }
        }
Ejemplo n.º 4
0
        public static void InitMemberCreditPackageRowInPOS(DataRow memberCreditPackageRow, string strReceiptNo,
            string strMembershipID, string strCreditPackageCode, string strPromotionCode, bool isFree)
        {
            TblCreditPackage package = new TblCreditPackage();
            package.StrCreditPackageCode = strCreditPackageCode;
            package.SelectOne();
            //int packageDuration = package.NPackageDuration.IsNull ? 0 : package.NPackageDuration.Value;

            memberCreditPackageRow["strMembershipID"] = strMembershipID;
            memberCreditPackageRow["strCreditPackageCode"] = strCreditPackageCode;
            memberCreditPackageRow["dtPurchaseDate"] = System.DateTime.Today;
            memberCreditPackageRow["fFree"] = isFree ? 1 : 0;
            memberCreditPackageRow["strReceiptNo"] = strReceiptNo;
            memberCreditPackageRow["nStatusID"] = 0; // Active
            memberCreditPackageRow["nEmployeeID"] = ACMSLogic.User.EmployeeID;
            memberCreditPackageRow["strRemarks"] = strPromotionCode;
            memberCreditPackageRow["dtLastEditDate"] = System.DateTime.Today;
            memberCreditPackageRow["mTopupAmount"] = 0;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Use Member Credit Package means use the credit to buy the package and then store in the tblMemberPackage
        /// be aware some package is not allow to purchase using credit package. Must check tblCreditPackageRestriction
        /// </summary>
        /// <returns></returns>
        public string[,] UseMemberCreditPackage(string[,] strPackageCode,
            int nCreditPackageID, string strSignID, string strSigKey, string strPdfExportPath, string remark)
        {
            //ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider();
            DataRow[] rows, row1s = new DataRow[strPackageCode.Length / 2];
            string[,] strUsage = new string[strPackageCode.Length / 2, 3];
            //DataColumn[] dc = new DataColumn["Usage",System.Type.GetType("System.Int")];

            try
            {
                TblMemberCreditPackage memberCreditPackage = new TblMemberCreditPackage();

                //connProvider.OpenConnection();
                //connProvider.BeginTransaction("UseMemberCreditPackage");

                //memberCreditPackage.MainConnectionProvider = connProvider;
                memberCreditPackage.NCreditPackageID = nCreditPackageID;
                DataTable table = memberCreditPackage.SelectOne();

                if (table == null || table.Rows.Count == 0)
                    throw new Exception("This member credit package been deleted by others");

                if (ACMS.Convert.ToInt32(table.Rows[0]["nStatusID"]) > 0)
                    throw new Exception("This member credit package has been deleted/expired/suspended.");

                string strCreditPackageCode = memberCreditPackage.StrCreditPackageCode.Value;
                string strMembershipID = memberCreditPackage.StrMembershipID.Value;
                TblCreditPackageRestriction restriction = new TblCreditPackageRestriction();
                restriction.StrCreditPackageCode = strCreditPackageCode;
                TblReceipt creditReceipt = new TblReceipt();
                if (!memberCreditPackage.StrReceiptNo.IsNull)
                {
                    creditReceipt.StrReceiptNo = memberCreditPackage.StrReceiptNo.Value;
                    creditReceipt.SelectOne();
                }

                DataTable restricttable = restriction.SelectAllWstrCreditPackageCodeLogic();
                DataColumn colQuantity = new DataColumn("colQuantity", System.Type.GetType("System.Int32"));
                restricttable.Columns.Add(colQuantity);

                bool isAllowDiscount = false;

                if (restricttable.Rows.Count == 0)
                    throw new Exception("No allow to use credit package for this package.");
                else
                {

                    for (int j = 0; j < strPackageCode.Length / 2; j++)
                    {
                        rows = restricttable.Select("strPackageCode = '" + strPackageCode[j, 0] + "'", "strCreditPackageCode");
                        rows[0]["colQuantity"] = strPackageCode[j, 1];
                        row1s[j] = rows[0];

                    }
                    if (row1s.Length == 0)
                        throw new Exception("No allow to use credit package for this package.");
                    // check later as got two package now
                    //else
                    //{
                    //    isAllowDiscount = ACMS.Convert.ToBoolean(row1s[0]["fAllowDiscount"]);
                    //}
                }

                // Must Check balance is enough to buy a Package or not
                TblCreditPackage creditPackage = new TblCreditPackage();
                creditPackage.StrCreditPackageCode = memberCreditPackage.StrCreditPackageCode.Value;
                creditPackage.SelectOne();

                decimal creditPackageValue = ACMS.Convert.ToDecimal(creditPackage.MCreditAmount);
                decimal mmbCreditPackageFreeCredit = ACMS.Convert.ToDecimal(creditPackage.MFreeCredit);
                decimal mmbCreditPackageTopupAmt = ACMS.Convert.ToDecimal(memberCreditPackage.MTopupAmount);

                decimal totalCreditUsage = GetCreditUsageFromMemberPackage(nCreditPackageID);

                decimal balance = (creditPackageValue + mmbCreditPackageTopupAmt + mmbCreditPackageFreeCredit) - totalCreditUsage;

                if (creditReceipt.MOutstandingAmount > 0 && !memberCreditPackage.StrReceiptNo.IsNull)
                {
                    DataTable creditUsageMemberPackage = null;
                    RefreshForPackageUsage(strMembershipID, ACMS.Convert.ToInt32(creditPackage.NCategoryID));
                    creditUsageMemberPackage = myDataTable;

                    double m70PercPaidAmount = 0;
                    if (creditUsageMemberPackage.Rows.Count > 0)
                        m70PercPaidAmount = ACMS.Convert.ToDouble(creditUsageMemberPackage.Select("nCreditPackageID=" + nCreditPackageID)[0]["PaidAmt"]) * 0.7;

                    if (totalCreditUsage > ACMS.Convert.ToDecimal(m70PercPaidAmount)) throw new Exception(string.Format("Total usage is more than 70% of paid amount. \n Please clear the outstanding."));
                }

                if (balance < 0) throw new Exception(string.Format("Balance for Member Credit Package : {0} is not enough.\n Please topup your credit.", nCreditPackageID.ToString()));

                // Need to know here whether it is 1st use
                TblMemberPackage mp = new TblMemberPackage();
                //mp.MainConnectionProvider = connProvider;
                mp.NCreditPackageID = nCreditPackageID;
                DataTable temptable = mp.SelectAllWnCreditPackageIDLogic();

                bool is1stUseCreditPck = false;
                if (Convert.ToInt32(temptable.Compute("COUNT(nStatusID)", "nStatusID=0 or nStatusID=1")) == 0)
                {
                    //means news insert
                    is1stUseCreditPck = true;
                }
                int i = 0;
                foreach (DataRow drPackage in row1s)
                {
                    for (int x = 0; x < ACMS.Convert.ToInt32(drPackage[3]); x++) // quantity
                    {
                        MemberPackage memberPackage = new MemberPackage();
                        DataTable memberPackageTable = memberPackage.New(false, strMembershipID);
                        DataRow memberPackageRow = memberPackageTable.Rows[0];
                        memberPackageRow["nCreditPackageID"] = nCreditPackageID;
                        memberPackageRow["strMembershipID"] = strMembershipID;
                        memberPackageRow["dtPurchaseDate"] = DateTime.Now;
                        memberPackageRow["strRemarks"] = remark;
                        memberPackageRow["strSignatureID"] = strSignID;
                        memberPackageRow["strSigKey"] = strSigKey;
                        memberPackageRow["strSigPdfPath"] = strPdfExportPath;
                        memberPackageRow["strUtilData"] = strSigKey;
                        memberPackageRow["nStatusID"] = 0;

                        memberPackageRow["strPackageCode"] = drPackage["strPackageCode"];//strPackageCode;
                        TblPackage package = new TblPackage();
                        package.StrPackageCode = drPackage["strPackageCode"].ToString(); // strPackageCode;
                        package.SelectOne();
                        decimal creditUsage = 0;
                        decimal packageListPrice = ACMS.Convert.ToDecimal(package.MListPrice);

                        TblMember sqlMember = new TblMember();
                        //Check if redeemed spa single treatment from holistic in birthday month, give 50% discount
                        if ((creditPackage.NCategoryID == 36 || creditPackage.NCategoryID == 37) && (package.NCategoryID == 4 || (package.NCategoryID == 6 && package.NMaxSession == 1)) && sqlMember.MembershipThisMonthBirtdayForUtilised(strMembershipID, nCreditPackageID))
                        {
                            DialogResult result1 = MessageBox.Show("Member is having birthday this months and having 50% discount. Do you want to utilies?", "Warning",
                            MessageBoxButtons.YesNo);

                            if (result1 == DialogResult.Yes)
                            {
                                double discountPercent = 50;
                                memberPackageRow["strPromotionCode"] = "120046SSD";
                                // calcualte usage * quantity
                                creditUsage = packageListPrice - (packageListPrice * (decimal)discountPercent / 100);
                            }
                            else
                            {
                                if (ACMS.Convert.ToBoolean(drPackage["fAllowDiscount"]))
                                {
                                    double discountPercent = creditPackage.DCreditDiscount.Value;
                                    // calcualte usage * quantity
                                    creditUsage = packageListPrice - (packageListPrice * (decimal)discountPercent / 100);
                                }
                                else
                                {
                                    creditUsage = packageListPrice;
                                }
                            }
                        }
                        else if (ACMS.Convert.ToBoolean(drPackage["fAllowDiscount"]))
                        {
                            double discountPercent = creditPackage.DCreditDiscount.Value;
                            // calcualte usage * quantity
                            creditUsage = packageListPrice - (packageListPrice * (decimal)discountPercent / 100);
                        }
                        else
                        {
                            creditUsage = packageListPrice;
                        }

                        decimal previousBal = balance;
                        balance = decimal.Parse(previousBal.ToString("N2")) - decimal.Parse(creditUsage.ToString("N2"));
                        if (balance < 0)
                            throw new Exception(string.Format("Balance for Member Credit Package : {0} is not enough. \n Please topup your credit.", nCreditPackageID.ToString()));

                        memberPackageRow["mCreditPackageUsagePrice"] = creditUsage;
                        memberPackageRow["strRemarks"] = memberPackageRow["strRemarks"] + " " + x;

                        //Initially designed for immediate kick start
                        if (memberPackageRow["dtStartDate"].ToString() == "")
                        {
                            int iduration = package.NPackageDuration.Value;
                            DateTime dtNow = DateTime.Now.Date;
                            memberPackageRow["dtStartDate"] = dtNow;
                            if (package.StrDurationUnit.ToString().Trim() == "DAY")
                                memberPackageRow["dtExpiryDate"] = dtNow.AddDays(iduration - 1).AddDays(0);
                            else if (package.StrDurationUnit.ToString().Trim() == "WEEK")
                            {
                                iduration = iduration * 7;
                                memberPackageRow["dtExpiryDate"] = dtNow.AddDays(iduration - 1).AddDays(0);
                            }
                            else
                                memberPackageRow["dtExpiryDate"] = dtNow.AddMonths(iduration).AddDays(-1);
                        }

                        mp.SaveData(memberPackageTable);
                        strUsage[i, 0] = package.StrDescription.ToString();
                        strUsage[i, 1] = creditUsage.ToString();
                    }

                    strUsage[i, 2] = drPackage[3].ToString();
                    i++;

                }

                if (is1stUseCreditPck)
                {
                    if (memberCreditPackage.DtStartDate.ToString() == "Null")
                    {
                        memberCreditPackage.NCreditPackageID = nCreditPackageID;
                        memberCreditPackage.DtStartDate = DateTime.Now.Date;
                        memberCreditPackage.DtExpiryDate = DateTime.Now.Date.AddMonths(ACMS.Convert.ToInt32(creditPackage.NValidMonths)).AddDays(-1);
                        memberCreditPackage.Update();
                    }
                }

                //connProvider.CommitTransaction();
            }
            catch (Exception)
            {
                //connProvider.RollbackTransaction("UseMemberCreditPackage");
                throw;
            }
            finally
            {
                //if (connProvider.CurrentTransaction != null)
                //    connProvider.CurrentTransaction.Dispose();
                //if (connProvider.DBConnection != null)
                //{
                //    if (connProvider.DBConnection.State == ConnectionState.Open)
                //        connProvider.DBConnection.Close();
                //}
            }
            return strUsage;
        }
Ejemplo n.º 6
0
        public void RefreshForConvert(string strMembershipID, int nCategoryID, DataTable receiptItemTable)
        {
            if (nCategoryID == 1)
                myDataTable = myCreditPkg.GetValidMemberCreditPackageForConvertToFit(strMembershipID);
            else if (nCategoryID == 4 || nCategoryID == 5 || nCategoryID == 6 || nCategoryID == 7 || nCategoryID == 9)
                myDataTable = myCreditPkg.GetValidMemberCreditPackageForConvert(strMembershipID);
            else if (nCategoryID == 36)
                myDataTable = myCreditPkg.GetValidMemberCreditPackageForConvertHolisticToHolisticFit(strMembershipID);
            else if (nCategoryID == 37)
                myDataTable = myCreditPkg.GetValidMemberCreditPackageForConvertHolistic(strMembershipID);

            if (myDataTable != null)
            {
                if (!myDataTable.Columns.Contains("Balance"))
                {
                    DataColumn colBalance = new DataColumn("Balance", System.Type.GetType("System.Decimal"));
                    myDataTable.Columns.Add(colBalance);
                }
                if (!myDataTable.Columns.Contains("mPackagePaidAmount"))
                {
                    DataColumn colBalance = new DataColumn("mPackagePaidAmount", System.Type.GetType("System.Decimal"));
                    myDataTable.Columns.Add(colBalance);
                }
                if (!myDataTable.Columns.Contains("strBalNew"))
                {
                    DataColumn colFNew = new DataColumn("strBalNew", System.Type.GetType("System.String"));
                    myDataTable.Columns.Add(colFNew);
                }
                if (!myDataTable.Columns.Contains("nFreeUtil"))
                {
                    DataColumn colNFreeUtil = new DataColumn("nFreeUtil", System.Type.GetType("System.Int32"));
                    myDataTable.Columns.Add(colNFreeUtil);
                }
                if (!myDataTable.Columns.Contains("mFreeUtil"))
                {
                    DataColumn colMFreeUtil = new DataColumn("mFreeUtil", System.Type.GetType("System.Decimal"));
                    myDataTable.Columns.Add(colMFreeUtil);
                }
                if (!myDataTable.Columns.Contains("strCalculation"))
                {
                    DataColumn colBalance = new DataColumn("strCalculation", System.Type.GetType("System.String"));
                    myDataTable.Columns.Add(colBalance);
                }
                MemberPackage memberPackage = new MemberPackage();
                double paidAmt=0;
                int nCreditPackageID = 0;
                foreach (DataRow r in myDataTable.Rows)
                {
                    string strCalculation = "Calculation:\n";
                    nCreditPackageID = ACMS.Convert.ToInt32(r["nCreditPackageID"]);
                    r["strBalNew"] = 0;
                    if (nCategoryID == 7 && nCategoryID == ACMS.Convert.ToInt32(r["nCategoryID"])) //Same spa credit category upgrade
                    {
                        r["Balance"] = ACMS.Convert.ToDecimal(r["mCreditAmount"]) + ACMS.Convert.ToDecimal(r["mTopupAmount"]) - memberPackage.GetCreditPackageUsagePrice(nCreditPackageID);
                        if (memberPackage.GetCreditPackageUsagePrice(nCreditPackageID) == 0)
                        {
                            r["strBalNew"] = "New";
                        }
                        strCalculation += "Is same category upgrade? Yes\n";
                        strCalculation += "Used Amt = " + memberPackage.GetCreditPackageUsagePrice(nCreditPackageID).ToString() + "\n";
                    }
                    else if ((nCategoryID == 36 || nCategoryID == 37) && (ACMS.Convert.ToInt32(r["nCategoryID"]) == 36 || ACMS.Convert.ToInt32(r["nCategoryID"]) == 37)) //Same Holistic category upgrade
                    {
                        strCalculation += "Is same category upgrade? Yes\n";
                        strCalculation += "Used Amt = " + memberPackage.GetCreditPackageUsagePrice(nCreditPackageID).ToString() + "\n";
                        if ((ACMS.Convert.ToDecimal(r["mCreditAmount"]) + ACMS.Convert.ToDecimal(r["mTopupAmount"]) - memberPackage.GetCreditPackageUsagePrice(nCreditPackageID)) <= (ACMS.Convert.ToDecimal(r["mCreditAmount"]) / 2) || memberPackage.GetCreditPackageUsagePrice(nCreditPackageID) == 0)
                        {
                            r["Balance"] = ACMS.Convert.ToDecimal(r["mCreditAmount"]) + ACMS.Convert.ToDecimal(r["mTopupAmount"]) - memberPackage.GetCreditPackageUsagePrice(nCreditPackageID);
                            if (memberPackage.GetCreditPackageUsagePrice(nCreditPackageID) == 0)
                            {
                                r["strBalNew"] = "New";
                            }
                        }
                        else
                        {
                            TblCreditPackage creditPackage = new TblCreditPackage();
                            creditPackage.StrCreditPackageCode = receiptItemTable.Rows[0]["strCode"].ToString();
                            creditPackage.SelectOne();

                            if (ACMS.Convert.ToDecimal(creditPackage.MCreditAmount) == ACMS.Convert.ToDecimal(r["mCreditAmount"]) && receiptItemTable.Rows.Count == 1)
                            {
                                r["Balance"] = (ACMS.Convert.ToDecimal(r["mCreditAmount"]) / 2);
                                strCalculation += "Top up of same category Utilization < 50%\nBalance to convert only 50% of credit amount";
                            }
                            else
                                r["Balance"] = ACMS.Convert.ToDecimal(r["mCreditAmount"]) + ACMS.Convert.ToDecimal(r["mTopupAmount"]) - memberPackage.GetCreditPackageUsagePrice(nCreditPackageID);
                        }
                    }
                    else if (ACMS.Convert.ToInt32(r["nCategoryID"]) == 36 || ACMS.Convert.ToInt32(r["nCategoryID"]) == 37) //Holistic different category upgrade
                    {
                        strCalculation += "Is same category upgrade? No\n";
                        strCalculation += "Used Amt = " + memberPackage.GetCreditPackageUsagePriceForDifferentCategoryConvert(nCreditPackageID).ToString() + "\n";

                        paidAmt = ACMS.Convert.ToDouble(r["mPackagePaidAmount"]);
                        r["Balance"] = ACMS.Convert.ToDecimal(paidAmt) + ACMS.Convert.ToDecimal(r["mTopupAmount"]) - memberPackage.GetCreditPackageUsagePriceForDifferentCategoryConvert(nCreditPackageID);

                        if (memberPackage.GetCreditPackageUsagePriceForDifferentCategoryConvert(nCreditPackageID) == 0)
                        {
                            r["strBalNew"] = "New";
                        }
                    }
                    else //Spa credit different category upgrade
                    {
                        paidAmt = ACMS.Convert.ToDouble(r["mPackagePaidAmount"]);

                        r["Balance"] = ACMS.Convert.ToDecimal(paidAmt) + ACMS.Convert.ToDecimal(r["mTopupAmount"]) - memberPackage.GetCreditPackageUsagePriceForDifferentCategoryConvert(nCreditPackageID);
                        if (memberPackage.GetCreditPackageUsagePrice(nCreditPackageID) == 0)
                        {
                            r["strBalNew"] = "New";
                        }
                        strCalculation += "Is same category upgrade? No\n";
                        strCalculation += "Used Amt = " + memberPackage.GetCreditPackageUsagePriceForDifferentCategoryConvert(nCreditPackageID).ToString() + "\n";
                    }

                    strCalculation += "Usage Bal Amt = " + r["Balance"].ToString();
                    r["strCalculation"] = strCalculation;
                }
            }
        }
Ejemplo n.º 7
0
        public DataTable GetPrintBalanceTable(int nCreditPackageID)
        {
            TblMemberCreditPackage memberCreditPackage = new TblMemberCreditPackage();
            memberCreditPackage.NCreditPackageID = nCreditPackageID;
            DataTable table = memberCreditPackage.SelectOne();

            TblCreditPackage creditPackage = new TblCreditPackage();
            creditPackage.StrCreditPackageCode = memberCreditPackage.StrCreditPackageCode.Value;
            creditPackage.SelectOne();

            decimal creditPackageValue = ACMS.Convert.ToDecimal(creditPackage.MCreditAmount);

            decimal mmbCreditPackageTopupAmt = ACMS.Convert.ToDecimal(memberCreditPackage.MTopupAmount);

            decimal totalCreditUsage = GetCreditUsageFromMemberPackage(nCreditPackageID);

            decimal balance =  (creditPackageValue + mmbCreditPackageTopupAmt) - totalCreditUsage;

            DataTable tableToReturn = new DataTable();

            DataColumn colCreditPackageID = new DataColumn("nCreditPackageID", System.Type.GetType("System.Int32"));
            DataColumn colBalance = new DataColumn("Balance", System.Type.GetType("System.Decimal"));
            DataColumn colExpiryDate = new DataColumn("ExpiryDate", System.Type.GetType("System.DateTime"));

            tableToReturn.Columns.Add(colBalance);
            tableToReturn.Columns.Add(colCreditPackageID);
            tableToReturn.Columns.Add(colExpiryDate);

            DataRow r = tableToReturn.NewRow();
            r["nCreditPackageID"] = nCreditPackageID;
            r["Balance"] = balance;
            r["ExpiryDate"] = memberCreditPackage.DtExpiryDate.Value;

            return tableToReturn;
        }