Esempio n. 1
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();

                }
            }
        }
Esempio n. 2
0
        private void btnPrint_Click(object sender, System.EventArgs e)
        {
            #region dyiwei
            if (myPOS.MOutstandingAmount == myPOS.MTotalAmount)
            {
                if (myPOS.MOutstandingAmount == 0)
                {
                    DialogResult zeroTender = MessageBox.Show(this, string.Format("Proceed to Tender with zero amount value"), "Warning", MessageBoxButtons.YesNo);

                    if (zeroTender == DialogResult.No)
                    {
                        this.DialogResult = DialogResult.None;
                        return;
                    }
                }
            }
            # endregion
            //2903

            bool HasCashMode = false;
            decimal remainder;
            decimal receiptAmt_temp;
            decimal paymentAmount = 0;
            decimal receiptTotalAmt = 0;
            decimal outstandingAmt = 0;
            decimal DepositAmount = 0;
            string ONOFF_State = "";

            TblPaymentPlan myPaymentPlan = new TblPaymentPlan();
            ONOFF_State = myPaymentPlan.GetInhouseIPP_ONOFF_State().ToString();

            if (gridView1.RowCount == 0)
            {
                MessageBox.Show(this, "Please Key In at least 1 payment code.");
                this.DialogResult = DialogResult.None;
                return;
            }

            if (myPOS.NCategoryID == 1 || myPOS.NCategoryID == 3 || myPOS.NCategoryID == 4 || myPOS.NCategoryID == 5 ||
                myPOS.NCategoryID == 6 || myPOS.NCategoryID == 7 || myPOS.NCategoryID == 8 || myPOS.NCategoryID == 9 ||
                myPOS.NCategoryID == 14 || myPOS.NCategoryID == 36 || myPOS.NCategoryID == 37)
            {
                //decimal paymentAmount = 0;
                //decimal receiptTotalAmt = 0;
                //decimal outstandingAmt = 0;
                decimal mininum1stPayment = 0;
                decimal percentageControl = Convert.ToDecimal(0.3);

                if (ONOFF_State == "1")
                {
                    percentageControl = Convert.ToDecimal(0.4);
                }

                //Get ReceiptMasterTable's Total Amount
                receiptTotalAmt = ACMS.Convert.ToDecimal(myPOS.ReceiptMasterTable.Rows[0]["mTotalAmount"]);

                //Get Outstanding Amount
                outstandingAmt = ACMS.Convert.ToDecimal(myPOS.ReceiptMasterTable.Rows[0]["mOutstandingAmount"]);

                //Get Payment Amount
                if (myPOS.ReceiptPaymentTable != null &&
                    myPOS.ReceiptPaymentTable.Rows.Count > 0)
                {
                    foreach (DataRow r in myPOS.ReceiptPaymentTable.Rows)
                    {
                        paymentAmount += ACMS.Convert.ToDecimal(r["mAmount"]);

                        if (r["strPaymentCode"].ToString() == "CASH")
                        {
                            HasCashMode = true;
                        }
                    }
                }

                //Fixing Deposit
                if (myPOS.StrDeposit != null || myPOS.StrDeposit != "")
                {
                    try
                    {
                        TblReceipt DepositReceipt = new TblReceipt();
                        DepositReceipt.StrReceiptNo = myPOS.StrDeposit;
                        DataTable tblDeposit = DepositReceipt.SelectOne();
                        DepositAmount = (decimal)(DepositReceipt.MTotalAmount.IsNull ? 0 : DepositReceipt.MTotalAmount.Value);

                        //paymentAmount += DepositAmount;
                    }
                    catch { }
                }

                if (HasCashMode)
                {
                    remainder = myPOS.MTotalAmount % ACMS.Convert.ToDecimal(0.05);

                    receiptAmt_temp = myPOS.MTotalAmount - remainder;

                    if (receiptAmt_temp == paymentAmount)
                    {
                        receiptTotalAmt = receiptAmt_temp;

                        outstandingAmt = 0;
                    }
                }

                //if (myPOS.StrParentReceiptNo != DBNull.Value || myPOS.StrParentReceiptNo != "")
                //{
                    //Deposit

                //}
                //else
                //{
                    try
                    {
                        //Derek Instalment Plan
                        //If ReceiptMaster Total < 300 - full payment is required - include Joining Fees and GST
                        if ((receiptTotalAmt + DepositAmount) < 300 && ONOFF_State == "1")
                        {
                            if (receiptTotalAmt > paymentAmount)
                            {
                                MessageBox.Show("Full payment is required for bill total less than SGD 300.");
                                this.DialogResult = DialogResult.None;
                                return;
                            }
                        }

                        //1st instalment must be 40% of the total
                        mininum1stPayment = (decimal.Ceiling(percentageControl * (receiptTotalAmt + DepositAmount) * 10) / 10); //percentageControl * receiptTotalAmt;

                        if ((paymentAmount + DepositAmount) < mininum1stPayment)
                        {
                            MessageBox.Show("Need to pay at least $" + string.Format("{0:0,0.00}", mininum1stPayment) +
                                                " (" + (Convert.ToInt32(percentageControl * 100)).ToString() + "%) of bill total (before deposit offset).\n\n" +
                                                "Please pay another $" + string.Format("{0:0,0.00}", mininum1stPayment - (paymentAmount + DepositAmount)));
                            this.DialogResult = DialogResult.None;
                            return;
                        }

                        //Derek Instalment Plan
                        if (outstandingAmt > 0)
                        {
                            //Check If Total Payment Amount is round figures
                            //Else Reject
                            /*if (paymentAmount != (Convert.ToInt32(paymentAmount * 100) / 100))
                            {
                                if (decimal.Ceiling(paymentAmount) <= receiptTotalAmt)
                                {
                                    MessageBox.Show("Please pay well rounded amount of $ " + decimal.Ceiling(paymentAmount).ToString() + ", as you still have outstanding.");
                                    this.DialogResult = DialogResult.None;
                                    return;
                                }
                                else
                                {
                                    MessageBox.Show("Please full amount of $ " + receiptTotalAmt.ToString());
                                    this.DialogResult = DialogResult.None;
                                    return;
                                }

                            }*/

                            if (ONOFF_State == "1")
                            {
                                string strPackageCodeList = "";
                                int mytotalInstalment = 0;

                                foreach (DataRow r in myPOS.ReceiptItemsTable.Rows)
                                {
                                    strPackageCodeList += r["strCode"].ToString() + ",";
                                }

                                //Work Out the instalment plan
                                //Params: paymentAmount, receiptTotalAmt, outstandingAmt
                                //Update myPOS.PaymentPlanTable
                                //TblPaymentPlan myPaymentPlan = new TblPaymentPlan();  //GetInhouseIPP_ONOFF_State

                                //frmMasterReceiptNo = strMasterReceiptNo;
                                //frmMasterReceiptTotal = mMasterReceiptTotal;
                                //frmPaymentAmount = mPaymentAmount;
                                //frmOutstandingAmount = mOutstandingAmount;
                                //frmPackageList = strPackageList;

                                DataTable dtIPPTotalNOptions = myPaymentPlan.GetInhouseIPPTotalNOptions("", (receiptTotalAmt + DepositAmount), paymentAmount,
                                                                                                        outstandingAmt, strPackageCodeList);

                                if (dtIPPTotalNOptions.Rows.Count > 1)
                                {

                                    FormPaymentPlan frm = new FormPaymentPlan(myPOS, "", (receiptTotalAmt + DepositAmount), paymentAmount,
                                                                                outstandingAmt, strPackageCodeList);
                                    DialogResult result = frm.ShowDialog();

                                    if (result == DialogResult.OK)
                                    {
                                        mytotalInstalment = Convert.ToInt32(frm.NTotalInstalment.ToString());
                                    }
                                    else
                                    {
                                        this.DialogResult = DialogResult.None;
                                        return;
                                    }
                                }
                                else if (dtIPPTotalNOptions.Rows.Count == 1)
                                {
                                    mytotalInstalment = Convert.ToInt32(dtIPPTotalNOptions.Rows[0]["nInstalmentNo"]);
                                }

                                myPaymentPlan.StrMasterReceiptNo = "";
                                myPaymentPlan.MMasterReceiptTotal = (receiptTotalAmt + DepositAmount);
                                myPaymentPlan.MOutstandingAmount = outstandingAmt;
                                myPaymentPlan.MPaymentAmount = paymentAmount;
                                myPaymentPlan.StrPackageList = strPackageCodeList;
                                myPaymentPlan.NEnforceTotalInstalment = mytotalInstalment;

                                myPOS.myPaymentPlanTable = myPaymentPlan.GetInhouseInstalmentPaymentPlan();
                            }
                        }

                        //Payment Tab to highlight receipt that have instalment plan - light blue
                        //Temporary suspension of the usage of the purchased package under the receipt if the due date of the "last instalment" is missed
                        //Packages under the receipt will be fully nullified (expired) if the final due dates (any instalments)

                        myPOS.MTotalAmount = receiptTotalAmt;
                        myPOS.MOutstandingAmount = outstandingAmt;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error Occur: Outstanding Payment - New Inhouse Instalment Payment Plan. " + ex.Message);
                        this.DialogResult = DialogResult.None;
                        return;
                    }

            }
            else if (myPOS.NCategoryID == 0)
            {
                //Derek Instalment Plan
                //#Get Total Payment Here
                //#Check If Pay Outstanding Category = Yes; Cat = 0
                //#Get strCode Receipt No as 1st Reference ReceiptNo
                //#Get Master receipt and match it from tblPaymentPlan
                //#If Receipt Found In Payment Plan Table
                //#Get the Next Instalment Amount
                //#If Next Instalment Amount = 0 then abort and return error
                //#Check If the Payment Amount >= the next instalment amount
                //#If Yes => Update the tblPaymentPlan DataTable and save later
                //#Else Return;
                //#Else (Master Receipt Not Found In Payment Plan Table)
                //#Proceed to normal flow
                try
                {
                    decimal subsequentInstalmentAmt = 0;

                    string strParentReceiptNo = myPOS.ReceiptItemsTable.Rows[0]["strCode"].ToString();
                    string strMasterReceiptNo = "";

                    //Get ReceiptMasterTable's Total Amount
                    receiptTotalAmt = ACMS.Convert.ToDecimal(myPOS.ReceiptMasterTable.Rows[0]["mTotalAmount"]);

                    //Get Outstanding Amount
                    outstandingAmt = ACMS.Convert.ToDecimal(myPOS.ReceiptMasterTable.Rows[0]["mOutstandingAmount"]);

                    //Get Payment Amount
                    if (myPOS.ReceiptPaymentTable != null &&
                        myPOS.ReceiptPaymentTable.Rows.Count > 0)
                    {
                        foreach (DataRow r in myPOS.ReceiptPaymentTable.Rows)
                        {
                            paymentAmount += ACMS.Convert.ToDecimal(r["mAmount"]);

                            if (r["strPaymentCode"].ToString() == "CASH")
                            {
                                HasCashMode = true;
                            }
                        }
                    }

                    if (HasCashMode)
                    {
                        remainder = myPOS.MTotalAmount % ACMS.Convert.ToDecimal(0.05);

                        receiptAmt_temp = myPOS.MTotalAmount - remainder;

                        if (receiptAmt_temp == paymentAmount)
                        {
                            receiptTotalAmt = receiptAmt_temp;

                            outstandingAmt = 0;
                        }
                    }

                    if (myPOS.StrParentReceiptNo != DBNull.Value || myPOS.StrParentReceiptNo != "") { }
                    else
                    {
                        if (outstandingAmt > 0)
                        {

                        }

                        //1st instalment must be 100% of the total
                        //TblPaymentPlan myPaymentPlan = new TblPaymentPlan();

                        if (ONOFF_State == "1")
                        {
                            //Get Master Receipt No
                            strMasterReceiptNo = myPaymentPlan.GetInhouseIPPMasterOSReceipt(strParentReceiptNo);
                            //Get Next Instalment Amount
                            subsequentInstalmentAmt = myPaymentPlan.GetInhouseIPPNextInstalmentAmount(strMasterReceiptNo);

                            if (subsequentInstalmentAmt > 0)
                            {
                                if (paymentAmount < subsequentInstalmentAmt)
                                {
                                    if (paymentAmount == receiptTotalAmt)
                                    {
                                        myPOS.myPaymentPlanTable = myPaymentPlan.GetInhouseAdjustedIPP_PayOS(strMasterReceiptNo, "", paymentAmount);
                                    }
                                    else
                                    {
                                        MessageBox.Show("Need to pay at least 100% of the subsequent instalment amount of SGD " + subsequentInstalmentAmt);
                                        this.DialogResult = DialogResult.None;
                                        return;
                                    }
                                }
                                else
                                {
                                    //Work Out the New instalment plan
                                    //Params: paymentAmount, receiptTotalAmt, outstandingAmt
                                    //Update myPOS.PaymentPlanTable
                                    myPOS.myPaymentPlanTable = myPaymentPlan.GetInhouseAdjustedIPP_PayOS(strMasterReceiptNo, "", paymentAmount);

                                }
                            }
                            else
                            {
                                //Proceed to normal flow
                                //No Inhouse Instalment Payment Plan
                            }
                        }
                    }

                    myPOS.MTotalAmount = receiptTotalAmt;
                    myPOS.MOutstandingAmount = outstandingAmt;
                }
                catch
                {
                    MessageBox.Show("Error Occur: Outstanding Payment - Subsequent Inhouse IPP Payment");
                    this.DialogResult = DialogResult.None;
                    return;
                }
            }
            else
            {
                try
                {
                    //Get ReceiptMasterTable's Total Amount
                    receiptTotalAmt = ACMS.Convert.ToDecimal(myPOS.ReceiptMasterTable.Rows[0]["mTotalAmount"]);

                    //Get Outstanding Amount
                    outstandingAmt = ACMS.Convert.ToDecimal(myPOS.ReceiptMasterTable.Rows[0]["mOutstandingAmount"]);

                    //Get Payment Amount
                    if (myPOS.ReceiptPaymentTable != null &&
                        myPOS.ReceiptPaymentTable.Rows.Count > 0)
                    {
                        foreach (DataRow r in myPOS.ReceiptPaymentTable.Rows)
                        {
                            paymentAmount += ACMS.Convert.ToDecimal(r["mAmount"]);

                            if (r["strPaymentCode"].ToString() == "CASH")
                            {
                                HasCashMode = true;
                            }
                        }
                    }

                    if (HasCashMode)
                    {
                        remainder = myPOS.MTotalAmount % ACMS.Convert.ToDecimal(0.05);

                        receiptAmt_temp = myPOS.MTotalAmount - remainder;

                        if (receiptAmt_temp == paymentAmount)
                        {
                            receiptTotalAmt = receiptAmt_temp;

                            outstandingAmt = 0;
                        }
                    }
                    myPOS.MTotalAmount = receiptTotalAmt;
                    myPOS.MOutstandingAmount = outstandingAmt;
                }
                catch
                {
                    MessageBox.Show("Error Occur: Other Categories, No IHP");
                    this.DialogResult = DialogResult.None;
                    return;
                }

            }

            if (myPOS.MOutstandingAmount > 0) //if (outstandingAmt > 0)
            {

                DialogResult yes = MessageBox.Show(this, string.Format("This receipt still have outstanding amount : ${0}, do you really want to tender?", myPOS.MOutstandingAmount.ToString()),
                    "Warning", MessageBoxButtons.YesNo);

                if (yes == DialogResult.No)
                {
                    this.DialogResult = DialogResult.None;
                    return;
                }

                if (myPOS.NCategoryID == 11 || myPOS.NCategoryID == 12)
                {
                    MessageBox.Show(this, "Products are not allow outstanding payment anymore. Please use Deposit Function");
                    this.DialogResult = DialogResult.None;
                    return;
                }
                else if (myPOS.NCategoryID == 18 || myPOS.NCategoryID == 19)
                {
                    MessageBox.Show(this, "Top Ups are not allow outstanding payment.");
                    this.DialogResult = DialogResult.None;
                    return;
                }
                else if (myPOS.NCategoryID == 2 || myPOS.NCategoryID == 34 || myPOS.NCategoryID == 35)
                {
                    MessageBox.Show(this, "Giros are not allow outstanding payment.");
                    this.DialogResult = DialogResult.None;
                    return;
                }
                else if (myPOS.NCategoryID == 38)
                {
                    MessageBox.Show(this, "Cash Voucher are not allow outstanding payment.");
                    this.DialogResult = DialogResult.None;
                    return;
                }
                else if (myPOS.NCategoryID == 15)
                {
                    MessageBox.Show(this, "Locker Rental are not allow outstanding payment.");
                    this.DialogResult = DialogResult.None;
                    return;
                }
                else if (myPOS.NCategoryID == 17)
                {
                    MessageBox.Show(this, "Forget Card are not allow outstanding payment.");
                    this.DialogResult = DialogResult.None;
                    return;
                }
                else if (myPOS.NCategoryID == 20)
                {
                    MessageBox.Show(this, "Lost Card are not allow outstanding payment.");
                    this.DialogResult = DialogResult.None;
                    return;
                }
                else if (myPOS.NCategoryID == 21)
                {
                    MessageBox.Show(this, "Mineral Water are not allow outstanding payment.");
                    this.DialogResult = DialogResult.None;
                    return;
                }
                else if (myPOS.NCategoryID == 23)
                {
                    MessageBox.Show(this, "Others are not allow outstanding payment.");
                    this.DialogResult = DialogResult.None;
                    return;
                }
                else if (myPOS.NCategoryID == 24)
                {
                    MessageBox.Show(this, "Deposit are not allow outstanding payment.");
                    this.DialogResult = DialogResult.None;
                    return;
                }
            }
            else if (myPOS.MOutstandingAmount < 0) //else if (outstandingAmt < 0) //
            {
                if (myPOS.NCategoryID != 15 &&
                    myPOS.NCategoryID != 17)
                {
                    MessageBox.Show(this, "Invalid Outstanding amount. This may be caused by amount been paid is more than outstand amount");
                    this.DialogResult = DialogResult.None;
                    return;
                }
            }
            else if (myPOS.ReceiptItemsTable.Rows.Count == 0)
            {
                MessageBox.Show(this, "No items in Receipt.");
                this.DialogResult = DialogResult.None;
                return;
            }

            #region jackie
            //  if (myPOS.MOutstandingAmount == 0)|| (!myPOS.StrFreebieCode.HasValue)

            //2704
            if (myPOS.MOutstandingAmount == 0) //if (outstandingAmt == 0)
            {
                if (myPOS.NCategoryID == 38)
                {
                    foreach (DataRow r in myPOS.ReceiptItemsTable.Rows)
                    {
                        string strSQL = "Select * from tblCashVoucher where fsell=1 and nstatusid<>0 and strSN='"+r["strCode"]+"' ";
                        DataSet _ds = new DataSet();
                        SqlHelper.FillDataset(connection, CommandType.StoredProcedure, "UP_GETDATA", _ds, new string[] { "table" }, new SqlParameter("@strSQL", strSQL));
                        if (_ds.Tables["table"].Rows.Count > 0)
                        {
                            MessageBox.Show(this, "Cash Voucher selected ( " +r["strCode"]+ " ) already sold.");
                            this.DialogResult = DialogResult.None;
                            return;
                        }
                    }
                }
                if (myPOS.NCategoryID != 35)//23 others Extent GIRO no freebiz
                {
                    if (!myPOS.StrFreebieCode.HasValue)
                    {
                        string strSQL = "Select distinct A.* from tblPromotion A, tblMember B, tblLoyaltyStatus C, tblPromotionBranch D, tblPromotionReceiptSalesCategory E, tblSalesCategory sc where A.FItemDiscount = 0 AND  A.mMinimumAmount <= " + (myPOS.MTotalAmount.ToString() == "" ? "0" : myPOS.MTotalAmount.ToString()) + " And A.nApprovedStatusID = 1 AND  ( A.nPromotionTypeID = 1 or A.nPromotionTypeID = 2) AND  A.dtValidStart <= convert(varchar(10),getdate(),120) AND A.dtValidEnd >= convert(varchar(10),getdate(),120) AND  ((A.nDiscountCategoryID = C.nDiscountCategoryID AND B.nLoyaltyStatusID = C.nLoyaltyStatusID) or A.nDiscountCategoryID =0) AND D.strPromotionCode = A.strPromotionCode and D.strBranchCode = '" + myPOS.StrBranchCode + "' AND E.strPromotionCode = A.strPromotionCode AND  B.StrMembershipID = '" + myPOS.StrMembershipID + "' AND E.nSalesCategoryID = sc.nSalesCategoryID AND sc.nSalesCategoryID = " + myPOS.NCategoryID;
                        DataSet _ds = new DataSet();
                        SqlHelper.FillDataset(connection, CommandType.StoredProcedure, "UP_GETDATA", _ds, new string[] { "table" }, new SqlParameter("@strSQL", strSQL));
                        if (_ds.Tables["table"].Rows.Count > 0)
                        {
                            DialogResult result1 = MessageBox.Show(this, "Freebie is empty. Do you want to add it now? ", "Warning",MessageBoxButtons.YesNo);

                            if (result1 == DialogResult.Yes)
                            {
                                ACMSPOS2.FormAddBillFreebie frm = new ACMS.ACMSPOS2.FormAddBillFreebie(myPOS,true);
                                frm.ShowDialog(this);
                            }
                        }
                        _ds.Dispose();
                    }
                }
            }
            # endregion

            //myPOS.MTotalAmount = receiptTotalAmt;
            //myPOS.MOutstandingAmount = outstandingAmt;
        }
Esempio n. 3
0
        //DEREK Instalment Plan Need to Update Receipt Here
        public void PrintReceipt(string receiptNo)
        {
            DataColumn colItemDiscountAmt = new DataColumn("DiscountAmt", typeof(decimal));
            DataColumn colBillDiscountAmt = new DataColumn("DiscountAmt", typeof(decimal));
            DataColumn colMemberName = new DataColumn("strMemberName", typeof(string));
            DataColumn colRewardPoint = new DataColumn("RewardPoint", typeof(decimal));
            DataColumn colGSTPaid = new DataColumn("GSTPaid", typeof(decimal));
            //DataColumn colOSAmt = new DataColumn("mOutstandingAmount", typeof(decimal));

            TblReceipt receipt = new TblReceipt();
            receipt.StrReceiptNo = receiptNo;
            DataTable tableReceipt = receipt.SelectOne();
            tableReceipt.TableName = "TblReceipt";
            tableReceipt.Columns.Add(colBillDiscountAmt);
            tableReceipt.Columns.Add(colMemberName);
            tableReceipt.Columns.Add(colRewardPoint);
            tableReceipt.Columns.Add(colGSTPaid);
               // tableReceipt.Columns.Add(colOSAmt);

            TblMember sqlMember = new TblMember();
            sqlMember.StrMembershipID = receipt.StrMembershipID;
            sqlMember.SelectOne();

            tableReceipt.Rows[0]["strMemberName"] = sqlMember.StrMemberName.IsNull ? "" : sqlMember.StrMemberName.Value.ToUpper();

            TblBranch sqlBranch = new TblBranch();
            sqlBranch.StrBranchCode = receipt.StrBranchCode == SqlString.Null ? "" : receipt.StrBranchCode.Value;
            DataTable branchTable = sqlBranch.SelectOne();

            TblRewardsTransaction sqlRewTrans = new TblRewardsTransaction();
            decimal rewardpoint = sqlRewTrans.GetMemberLoyaltyPoint(receipt.StrMembershipID.Value);
            tableReceipt.Rows[0]["RewardPoint"] = System.Math.Round(rewardpoint);

            TblReceiptEntries receiptEntries = new TblReceiptEntries();
            receiptEntries.StrReceiptNo = receiptNo;
            DataTable tableReceiptEntries = receiptEntries.SelectAllWstrReceiptNoLogic();
            tableReceiptEntries.TableName = "TblReceiptEntries";
            tableReceiptEntries.Columns.Add(colItemDiscountAmt);

            TblReceiptFreebie freebie = new TblReceiptFreebie();
            freebie.StrReceiptNo = receiptNo;
            DataTable tableReceiptFreebie = freebie.SelectReceiptFreebie();
            tableReceiptFreebie.TableName = "TblReceiptFreebie";

            TblMemberPackage FreePackage = new TblMemberPackage();
            FreePackage.StrReceiptNo = receiptNo;
            DataTable tableFreePackage = FreePackage.GetFreePackage(receiptNo);
            tableFreePackage.TableName = "TblFreePackage";

            TblMemberPackage ConvertedPackage = new TblMemberPackage();
            ConvertedPackage.StrReceiptNo = receiptNo;
            DataTable tableConvertedPackage = ConvertedPackage.GetConvertedPackage(receiptNo);
            tableConvertedPackage.TableName = "TblConvertedPackage";

            TblPaymentPlan myPaymentPlan = new TblPaymentPlan();
            DataTable tablePaymentPlan = myPaymentPlan.GetInhouseIPPOSByReceiptNo(receiptNo);
            tablePaymentPlan.TableName = "TblPaymentPlan";

            DataTable tableDeposit = myPaymentPlan.GetInhouseIPPReceiptDeposit(receiptNo);
            tableDeposit.TableName = "TblReceiptDeposit";

            //			TblProduct Product = new TblProduct();
            //		//	Product.StrProductCode = tableReceiptFreebie.Rows[0]["strItemCode"].ToString();
            //			DataTable tableProduct = Product.SelectAll();
            //			tableProduct.TableName = "TblProductName";

            decimal nettAmountB4Discount = 0;
            decimal discoutnAmt =0;
            decimal depositAmt = 0;

            if (tableDeposit.Rows.Count > 0)
            {
                depositAmt = Convert.ToDecimal(tableDeposit.Rows[0]["TotalDeposit"]);
            }

            foreach (DataRow r in tableReceiptEntries.Rows)
            {
                int qty = ACMS.Convert.ToInt32(r["nQuantity"]);
                decimal unitPrice = ACMS.Convert.ToDecimal(r["mUnitPrice"]);
                decimal currSubtotal = ACMS.Convert.ToDecimal(r["mSubTotal"]);
                discoutnAmt = (unitPrice * qty) - currSubtotal;
                r["DiscountAmt"] = decimal.Round(discoutnAmt, 2);

                nettAmountB4Discount += currSubtotal;
            }

            //Sub Total
            DataColumn colSubTotal = new DataColumn("mSubTotal", typeof(decimal));
            tableReceipt.Columns.Add(colSubTotal);
            tableReceipt.Rows[0]["mSubTotal"] = nettAmountB4Discount;

             decimal nettAmountAfterDiscount = ACMS.Convert.ToDecimal(tableReceipt.Rows[0]["mNettAmount"]);

            if (tableReceipt.Rows[0]["strDiscountCode"].ToString().Length > 0 &&
                tableReceipt.Rows[0]["strDiscountCode"] != DBNull.Value)
            {
                tableReceipt.Rows[0]["DiscountAmt"] = nettAmountB4Discount - (nettAmountAfterDiscount + depositAmt);
            }

            TblReceiptPayment receiptPayment = new TblReceiptPayment();
            receiptPayment.StrReceiptNo = receiptNo;
            DataTable tableReceiptPayment = receiptPayment.SelectAllWstrReceiptNoLogic();
            tableReceiptPayment.TableName = "TblReceiptPayment";

            TblCompany comp = new TblCompany();

            DataTable compTable = comp.SelectAll();

            int myTaxID = ACMS.Convert.ToInt32(compTable.Rows[0]["NTaxID"]);
            TblTax tax = new TblTax();
            tax.NTaxID = myTaxID;
            tax.SelectOne();
            decimal myGSTRate = tax.DTaxRate.IsNull ? 0 : (decimal)tax.DTaxRate.Value;

            decimal GSTAmtPaid=0;
            decimal GSTRate1=myGSTRate;//0.05M;
            decimal GSTRate2=myGSTRate+1;// 1.05M;

            foreach (DataRow p in tableReceiptPayment.Rows)
            {
                GSTAmtPaid=GSTAmtPaid+ACMS.Convert.ToDecimal(p[3])* GSTRate1 /GSTRate2;
            }
            if (receipt.NCategoryID.ToString() != "38")
            {
                tableReceipt.Rows[0]["GSTPaid"] = decimal.Round(GSTAmtPaid, 2);
            }
            else
            {
                tableReceipt.Rows[0]["GSTPaid"] = decimal.Round(0, 2);
            }

            DataSet newDS = new DataSet("Receipt");
            newDS.Tables.Add(tableReceipt);

            newDS.Tables.Add(tableReceiptEntries);
            newDS.Tables.Add(tableReceiptPayment);
            newDS.Tables.Add(branchTable);
            //			newDS.Tables.Add(tableProduct);
            newDS.Tables.Add(tableReceiptFreebie);
            newDS.Tables.Add(tableFreePackage);
            newDS.Tables.Add(tableConvertedPackage);
            newDS.Tables.Add(tablePaymentPlan);
            newDS.Tables.Add(tableDeposit);

            DataRelation relation1 = new DataRelation("Receipt_ReceiptEntries_Relation", newDS.Tables["TblReceipt"].Columns["strReceiptNo"],
                newDS.Tables["TblReceiptEntries"].Columns["strReceiptNo"], false);

            DataRelation relation2 = new DataRelation("Receipt_ReceiptPayment_Relation", newDS.Tables["TblReceipt"].Columns["strReceiptNo"],
                newDS.Tables["TblReceiptPayment"].Columns["strReceiptNo"], false);

            DataRelation relation3 = new DataRelation("Receipt_ReceiptFreebie_Relation", newDS.Tables["TblReceipt"].Columns["strReceiptNo"],
                newDS.Tables["TblReceiptFreebie"].Columns["strReceiptNo"], false);

            DataRelation relation4 = new DataRelation("Receipt_FreePackage_Relation", newDS.Tables["TblReceipt"].Columns["strReceiptNo"],
                newDS.Tables["TblFreePackage"].Columns["strReceiptNo"], false);

            DataRelation relation5 = new DataRelation("Receipt_ConvertedPackage_Relation", newDS.Tables["TblReceipt"].Columns["strReceiptNo"],
                newDS.Tables["TblConvertedPackage"].Columns["strReceiptNo"], false);

            DataRelation relation6 = new DataRelation("Receipt_PaymentPlan_Relation", newDS.Tables["TblReceipt"].Columns["strReceiptNo"],
                newDS.Tables["TblPaymentPlan"].Columns["strReceiptNo"], false);

            DataRelation relation7 = new DataRelation("Receipt_Deposit_Relation", newDS.Tables["TblReceipt"].Columns["strReceiptNo"],
                newDS.Tables["TblReceiptDeposit"].Columns["strReceiptNo"], false);

            newDS.Relations.Add(relation1);
            newDS.Relations.Add(relation2);
            newDS.Relations.Add(relation3);
            newDS.Relations.Add(relation4);
            newDS.Relations.Add(relation5);
            newDS.Relations.Add(relation6);
            newDS.Relations.Add(relation7);

            //display GST %
            DataColumn colGstTax = new DataColumn("GstTax", typeof(int));
            tableReceipt.Columns.Add(colGstTax);
            tableReceipt.Rows[0]["GstTax"] = myGSTRate * 100;

            ACMSLogic.Report.Receipt receiptReport = new ACMSLogic.Report.Receipt();

            receiptReport.DataSource = newDS;

            //			if (ACMS.Convert.ToDecimal(tableReceipt.Rows[0]["DiscountAmt"])==0)
            //			{
            //				receiptReport.HideFields(false);
            //            }
            //			else
            //			{
            //				receiptReport.HideFields(true);
            //			}

               // receiptReport.ShowDesignerDialog();
            receiptReport.Print();
        }
Esempio n. 4
0
        //Derek Instalment Plan - Void Pay OS - Update Payment Plan
        public void VoidReceipt(string strReceiptNo, bool VoidPre)
        {
            ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider();

            try
            {
                // Check Access Right here
                TblReceipt receipt = new TblReceipt();
                TblReceiptFreebie sqlReceiptFreebie = new TblReceiptFreebie();
                TblRewardsTransaction mRewardTransaction = new TblRewardsTransaction();
                TblReceiptPayment sqlReceiptPayment = new TblReceiptPayment();
                TblPaymentPlan myPaymentPlan = new TblPaymentPlan();

                myPaymentPlan.MainConnectionProvider = connProvider;
                mRewardTransaction.MainConnectionProvider = connProvider;
                receipt.MainConnectionProvider = connProvider;
                sqlReceiptFreebie.MainConnectionProvider = connProvider;
                sqlReceiptPayment.MainConnectionProvider = connProvider;

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

                receipt.StrReceiptNo = strReceiptNo;
                receipt.SelectOne();

                int nCategoryID = receipt.NCategoryID.Value;
                string strBranchCode = receipt.StrBranchCode.Value;

                if (receipt.DtDate.Value != System.DateTime.Today && VoidPre == false)
                    throw new Exception("Not allow to void previous data receipt. ");

                if (strBranchCode != User.BranchCode)
                    throw new Exception("Not allow to void other's branches' receipt. ");

                receipt.FVoid = System.Data.SqlTypes.SqlBoolean.True;
                receipt.Update();

                string strSQL;
                if (receipt.NCategoryID == 7 || receipt.NCategoryID == 36 || receipt.NCategoryID == 37)
                    strSQL = "select top 1 * from tblMemberCreditPackage where strReceiptNo ='" + receipt.StrReceiptNo.ToString() + "' AND fFree=0";
                else
                    strSQL = "select top 1 * from tblMemberPackage where strReceiptNo ='" + receipt.StrReceiptNo.ToString() + "' AND fFree=0";
                DataSet _ds1 = new DataSet();
                SqlHelper.FillDataset(connection, CommandType.StoredProcedure, "UP_GETDATA", _ds1, new string[] { "table" }, new SqlParameter("@strSQL", strSQL));

                //Roll back when package conversion
                if (_ds1.Tables["table"].Rows.Count > 0)
                {
                    string strPkgRemark = _ds1.Tables["table"].Rows[0]["strUpgradeFrom"].ToString();
                    string[] rollbackPackages = strPkgRemark.ToString().Split(',');

                    foreach (string rollbackPackage in rollbackPackages)
                    {
                        if (rollbackPackage.Trim() != "" && rollbackPackage.Trim() != "Null")
                        {
                            if (rollbackPackage.Contains("(C)"))
                            {
                                int nPackageID = Convert.ToInt32(rollbackPackage.Trim().Replace("(C)", ""));
                                TblMemberCreditPackage mp2 = new TblMemberCreditPackage();
                                mp2.NCreditPackageID = nPackageID;
                                mp2.SelectOne();
                                mp2.StrUpgradeTo = "";
                                mp2.StrRemarks = "";
                                mp2.NStatusID = 0;
                                mp2.Update();
                            }
                            else if (rollbackPackage.Contains("(B)"))
                            {
                                string strSQL2 = "select * from tblMemberPackage where strUpgradeTo='" + receipt.StrReceiptNo.ToString() + "' ";
                                DataSet _ds2 = new DataSet();
                                SqlHelper.FillDataset(connection, CommandType.StoredProcedure, "UP_GETDATA", _ds2, new string[] { "table" }, new SqlParameter("@strSQL", strSQL2));
                                foreach (DataRow drComboPkg in _ds2.Tables["table"].Rows)
                                {
                                    TblMemberPackage mp = new TblMemberPackage();
                                    DataTable convertedPkgTable = mp.LoadData("select * from tblMemberPackage where nPackageID=" + drComboPkg["nPackageID"].ToString());
                                    if (convertedPkgTable.Rows.Count > 0)
                                    {
                                        convertedPkgTable.Rows[0]["nStatusID"] = 0;
                                        convertedPkgTable.Rows[0]["strUpgradeTo"] = "";
                                        convertedPkgTable.Rows[0]["strRemarks"] = "";
                                        mp.SaveData(convertedPkgTable);
                                    }
                                }
                            }
                            else
                            {
                                int nPackageID = Convert.ToInt32(rollbackPackage.Trim());
                                TblMemberPackage mp2 = new TblMemberPackage();
                                mp2.NPackageID = nPackageID;
                                mp2.SelectOne();
                                mp2.StrUpgradeTo = "";
                                mp2.StrRemarks = "";
                                mp2.NStatusID = 0;
                                mp2.Update();

                                //rollback free package if have any
                                TblMemberPackage mp3 = new TblMemberPackage();
                                string strFreePackageCode = "";
                                string strSQL3 = "select strFreePkgCode from tblPackage where strPackageCode='" + Convert.ToString(mp2.StrPackageCode) + "' ";
                                DataSet _ds = new DataSet();
                                SqlHelper.FillDataset(connection, CommandType.StoredProcedure, "UP_GETDATA", _ds, new string[] { "table" }, new SqlParameter("@strSQL", strSQL3));
                                if (_ds.Tables["table"].Rows.Count > 0)
                                {
                                    strFreePackageCode = _ds.Tables["table"].Rows[0]["strFreePkgCode"].ToString();
                                }
                                DataTable freePkgTable = mp3.LoadData("select * from tblMemberPackage where strReceiptNo=@strReceiptNo and strPackageCode =@strFreePackageCode ",
                                    new string[] { "@strReceiptNo", "@strFreePackageCode" }, new object[] { mp2.StrReceiptNo.ToString(), strFreePackageCode });

                                if (freePkgTable.Rows.Count > 0)
                                {
                                    freePkgTable.Rows[0]["nStatusID"] = 0;
                                    freePkgTable.Rows[0]["strUpgradeTo"] = "";
                                    freePkgTable.Rows[0]["strRemarks"] = "";
                                    mp3.SaveData(freePkgTable);
                                }
                            }
                        }
                    }
                }

                receipt.MUpgradeAmount = System.Data.SqlTypes.SqlMoney.Null;
                receipt.StrRemarks = "";
                receipt.Update();

                #region ====== Added By Albert ======
                /*
                 * To remove reward transaction.
                 */
                mRewardTransaction.StrReferenceNo = strReceiptNo;
                mRewardTransaction.SelectAllWReferenceNo();
                mRewardTransaction.NTypeID = 3;
                mRewardTransaction.Update();
                #endregion

                //rollback used cash voucher
                TblReceiptPayment tblReceiptPayment = new ACMSDAL.TblReceiptPayment();
                tblReceiptPayment.StrReceiptNo = strReceiptNo;
                DataTable tblPayment = tblReceiptPayment.SelectAllWstrReceiptNoLogic();

                foreach (DataRow dr in tblPayment.Rows)
                {
                    if (dr["strPaymentCode"].ToString() == "CASHVOUCHER")
                    {
                        TblCashVoucher sqlCV = new TblCashVoucher();
                        sqlCV.MainConnectionProvider = connProvider;
                        sqlCV.StrSN = dr["strReferenceNo"].ToString();
                        DataTable table = sqlCV.SelectOne();
                        sqlCV.NStatusID = 1;
                        sqlCV.StrRedeemedByID = System.Data.SqlTypes.SqlString.Null;
                        sqlCV.DtRedeemedDate = System.Data.SqlTypes.SqlDateTime.Null;
                        sqlCV.StrRedeemedBranch = System.Data.SqlTypes.SqlString.Null;
                        sqlCV.Update();
                        sqlCV.SaveData(table);
                    }
                }

                if (!receipt.StrChildReceiptNo.IsNull)
                {
                    int IsVoid = 0;

                    IsVoid = receipt.CheckIfChildReceiptVoid(receipt.StrChildReceiptNo.Value);

                    if (IsVoid == 0)
                    {
                        throw new Exception("The receipt given has child receipt, please void child receipt first before void this receipt");
                    }
                }

                string strDepositReceiptNo = "";

                if (!receipt.StrParentReceiptNo.IsNull)
                {
                    TblReceiptEntries pReceipt = new TblReceiptEntries();
                    pReceipt.StrReceiptNo = receipt.StrParentReceiptNo.Value;
                    pReceipt.SelectAllWstrReceiptNoLogic();
                    if (pReceipt.StrCode.Value != "Deposit")
                    {
                        nCategoryID = 0; //Check if pay outstanding receipt, reset category to 0
                    }
                    else if (pReceipt.StrCode.Value == "Deposit")
                    {
                        strDepositReceiptNo = receipt.StrParentReceiptNo.Value;
                    }
                    pReceipt.Dispose();
                }

                if (strDepositReceiptNo != "")
                {
                    try
                    {
                        receipt.ReviveDepositForVoidMasterReceipt(strReceiptNo, strDepositReceiptNo);
                    }
                    catch { }
                }

                if (nCategoryID == 1 || nCategoryID == 3 || nCategoryID == 4 || nCategoryID == 5 ||
                    nCategoryID == 6 || nCategoryID == 8 || nCategoryID == 9 || nCategoryID == 14 || nCategoryID == 23)
                {
                    ActionTakeWhenVoidReceiptForCategory_1_3_4_5_6_8_9_14_23(strReceiptNo, connProvider);
                }
                else if (nCategoryID == 2)
                {
                    //Fitness GIRO
                    ActionTakeWhenVoidReceiptForCategory_2(strReceiptNo, connProvider);
                }
                else if (nCategoryID == 7)
                {
                    // Spa Credit Account
                    ActionTakeWhenVoidReceiptForCategory_7(strReceiptNo, connProvider);
                }
                else if (nCategoryID == 36 || nCategoryID == 37)
                {
                    // Holistic Credit Account
                    ActionTakeWhenVoidReceiptForCategory_7(strReceiptNo, connProvider);
                }
                else if (nCategoryID == 38)
                {
                    // Cash Voucher
                    ActionTakeWhenVoidReceiptForCategory_38(strReceiptNo, connProvider);
                }
                else
                {
                    DeleteFreeMemberPackage(strReceiptNo, connProvider);

                    if (nCategoryID == 11 || nCategoryID == 12)
                    {
                        //ActionTakeWhenVoidReceiptForCategory_11_12(strReceiptNo, connProvider);
                    }
                    else if (nCategoryID == 21)
                    {
                        // mineral water
                    }
                    else if (nCategoryID == 15)
                    {
                        //Locker Rental
                    }
                    else if (nCategoryID == 0)
                    {
                        // Pay Outstanding
                        ActionTakeWhenVoidReceiptForCategory_0(receipt, connProvider);

                        //Get New Payment Plan
                        //If Table Row Count > 0 Then Update Payment Plan

                        //Derek Instalment Plan - Update tblPaymentPlan (if any)
                        //Reset Payment Plan's Receipt by payment receipt No - Bool 1 Updated 0 Not Found
                        //Get Bool If 1
                        //Find the Master Receipt No if 1

                        string strMasterReceiptNo = "";

                        strMasterReceiptNo = myPaymentPlan.GetInhouseIPPMasterOSReceiptSimple(strReceiptNo);

                        if (strMasterReceiptNo != "")
                        {
                            if (myPaymentPlan.GetInhouseResetIPP_VoidPayOS(strReceiptNo) == 1)
                            {
                                DataTable paymentPlanTable = myPaymentPlan.GetInhouseAdjustedIPP_VoidPayOS(strMasterReceiptNo);

                                if (paymentPlanTable != null && paymentPlanTable.Rows.Count > 0)
                                {
                                    foreach (DataRow r in paymentPlanTable.Rows)
                                    {
                                        if (r["lastestUpdate"].ToString() == "1")
                                        {
                                            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();
                                }
                            }
                        }
                    }
                    else if (nCategoryID == 18)
                    {
                        ActionTakeWhenVoidReceiptForCategory_18(strReceiptNo, connProvider);
                    }
                    else if (nCategoryID == 19)
                    {
                        ActionTakeWhenVoidReceiptForCategory_19(strReceiptNo, connProvider);
                    }
                    #region Un-support voiding
                    /*
                    else if (nCategoryID == 17)
                    {
                        //throw new Exception("Forget card's receipt is not allow to void.");
                        //do notthing. Just void the receipt
                    }
                    else if (nCategoryID == 10)
                    {
                        //throw new Exception("Upgrade Package's receipt is not allow to void.");
                        // do notthing. Just void the receipt.
                    }
                    else if (nCategoryID == 20)
                    {
                        //Replace Membership Card
                        //throw new Exception("Replace member card's receipt is not allow to void.");
                        //do notthing, just void the receipt
                    }
                    */
                    #endregion

                }

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

                }
            }
        }