Beispiel #1
0
 public void ChangeSalesPersonID(int newSalesPersonID, string strReceiptNo)
 {
     ACMSDAL.TblReceipt sqlReceipt = new TblReceipt();
     sqlReceipt.StrReceiptNo = strReceiptNo;
     sqlReceipt.SelectOne();
     sqlReceipt.NSalespersonID = newSalesPersonID;
     sqlReceipt.Update();
 }
        public ActionResult Purchase()
        {
            TblCart userCart = null;

            foreach (TblCart cart in storeDB.TblCarts)
            {
                if (cart.UserId == (Session["user"] as TblUser).UserId)
                {
                    userCart = cart;
                    break;
                }
            }

            DateTime purchaseDate = DateTime.Now;

            List <TblReceipt> model = new List <TblReceipt>();

            foreach (TblCartItem cartItem in userCart.TblCartItems)
            {
                TblReceipt receiptItem = new TblReceipt();

                receiptItem.Amount      = cartItem.Amount;
                receiptItem.DateAndTime = purchaseDate;
                receiptItem.DeviceId    = cartItem.DeviceId;
                receiptItem.UserId      = (Session["user"] as TblUser).UserId;

                string taxValue = System.Configuration.ConfigurationManager.AppSettings["taxValue"];
                int    x;
                int.TryParse(taxValue, out x);

                receiptItem.Tax          = x;
                receiptItem.PriceWithTax = (int)(int.Parse(storeDB.TblDevices.Find(cartItem.DeviceId).Price) * cartItem.Amount * 1.20);

                storeDB.TblReceipts.Add(receiptItem);
                model.Add(receiptItem);
            }

            var items = userCart.TblCartItems;

            userCart.TblCartItems.Clear();

            foreach (TblCartItem cartItem in items)
            {
                storeDB.TblCartItems.Remove(cartItem);
            }

            storeDB.SaveChanges();

            return(View(model));
        }
Beispiel #3
0
        private int GetOriginalCatID(ACMSDAL.ConnectionProvider connProvider, ACMSLogic.POS pos, ref DataTable tableRec)
        {
            TblReceipt strCatReceiptNo = new  TblReceipt();
            strCatReceiptNo.MainConnectionProvider = connProvider;
            tableRec = strCatReceiptNo.GetOriginalCatID(pos.StrParentReceiptNo);

            int orgCatID = 0;
            if (tableRec.Rows.Count > 0)
            {
                orgCatID = ACMS.Convert.ToInt32(tableRec.Rows[0]["nCategoryID"]);
            }
            return orgCatID;
        }
Beispiel #4
0
        private void ForgetCardTransaction(ACMSDAL.ConnectionProvider connProvider, ACMSLogic.POS pos)
        {
            if (pos.NCategoryID == 17 && pos.POSForgetCardAction == ACMSLogic.POS.ForgetCardAction.Refund)
            {
                TblClassAttendance classAttendance = new TblClassAttendance();
                classAttendance.MainConnectionProvider = connProvider;
                TblReceipt sqlReceipt = new TblReceipt();
                sqlReceipt.MainConnectionProvider = connProvider;

                foreach (DataRow row in pos.ReceiptItemsTable.Rows)
                {
                    DateTime dtDate = ACMS.Convert.ToDateTime(row["strReferenceNo"]);
                    DataTable classAttendanceTable = classAttendance.GetForgetCardClassAttendance(pos.StrMembershipID, dtDate);

                    foreach (DataRow r in classAttendanceTable.Rows)
                    {
                        r["fRefunded"] = true;
                    }

                    classAttendance.SaveData(classAttendanceTable);
            /*
                    string receiptToVoid = row["strCode"].ToString();

                    sqlReceipt.StrReceiptNo = receiptToVoid;
                    sqlReceipt.SelectOne();
                    sqlReceipt.FVoid = SqlBoolean.True;
                    sqlReceipt.Update();*/
                }
            }
        }
Beispiel #5
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();

                }
            }
        }
Beispiel #6
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();
        }
Beispiel #7
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"];
                }
            }
        }
Beispiel #8
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);
        }
Beispiel #9
0
        public void Refund(string strReceiptNo, string strChequeNo, double mRefundAmount)
        {
            ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider();

            try
            {
                // Check Access Right here
                TblReceipt receipt = new TblReceipt();
                receipt.MainConnectionProvider = connProvider;

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

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

                receipt.FRefund = System.Data.SqlTypes.SqlBoolean.True;
                receipt.StrChequeNo = strChequeNo;
                receipt.MRefundAmount = ACMS.Convert.ToDecimal(mRefundAmount);
                receipt.NChequeUpdateBy = User.EmployeeID;
                receipt.UpdateChequeDetails();

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

                }
            }
        }
Beispiel #10
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;
        }
Beispiel #11
0
        private void ActionTakeWhenVoidReceiptForCategory_0(TblReceipt receipt, ConnectionProvider connProvider)
        {
            if (receipt.StrParentReceiptNo.IsNull || receipt.StrParentReceiptNo.Value.Trim().Length == 0)
            {
                throw new Exception("This is not an outstanding receipt because there is no parent receipt for the given receipt no.");
            }
            else if (!receipt.StrChildReceiptNo.IsNull)
            {
                throw new Exception("The receipt given has child receipt, please void child receipt first before void this receipt");
            }
            else
            {
                decimal mTotalAmount = receipt.MTotalAmount.Value;
                decimal myOutStandingAmt = mTotalAmount;

                TblReceipt parentReceipt = new TblReceipt();
                parentReceipt.MainConnectionProvider = connProvider;
                parentReceipt.StrReceiptNo = receipt.StrParentReceiptNo.Value;
                parentReceipt.SelectOne();

                parentReceipt.StrChildReceiptNo = System.Data.SqlTypes.SqlString.Null;

                try
                {
                    decimal prevOutstanding = Convert.ToDecimal(parentReceipt.MBalance.Value);
                    decimal remainder = prevOutstanding % ACMS.Convert.ToDecimal(0.05);

                    if (myOutStandingAmt == prevOutstanding - remainder)
                    {
                        myOutStandingAmt = prevOutstanding;
                    }
                }
                catch (Exception ex) {}

                //parentReceipt.MOutstandingAmount += ACMS.Convert.ToDecimal(receipt.MTotalAmount);
                //parentReceipt.MOutstandingAmount += ACMS.Convert.ToDecimal(parentReceipt.MBalance);

                parentReceipt.MOutstandingAmount = ACMS.Convert.ToDecimal(myOutStandingAmt);

                //parentReceipt.MainConnectionProvider = connProvider;
                parentReceipt.Update();
            }
        }
Beispiel #12
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();

                }
            }
        }
Beispiel #13
0
 public void SalesConvertion(int newCategoryID, string strReceiptNo, string remarks)
 {
     ACMSDAL.TblReceipt sqlReceipt = new TblReceipt();
     sqlReceipt.StrReceiptNo = strReceiptNo;
     sqlReceipt.SelectOne();
     sqlReceipt.NCategoryID = newCategoryID;
     sqlReceipt.Update();
 }
Beispiel #14
0
        //Derek Instalment Plan Need Update tblPaymentPlan During Pay OutStanding
        //Derek Instalment Plan TblPaymentPlan.cs
        private int PayOutstanding(ACMSDAL.ConnectionProvider connProvider, ACMSLogic.POS pos)
        {
            int OriginalCategoryID = 0 ;

            if (pos.NCategoryID == 0)
            {
                TblReceipt receipt = new TblReceipt();

                receipt.MainConnectionProvider = connProvider;

                if (pos.ReceiptItemsTable.Rows.Count == 1)
                {
                    string strReceiptNo = pos.ReceiptItemsTable.Rows[0]["strCode"].ToString();

                    decimal payAmount = ACMS.Convert.ToDecimal(pos.ReceiptItemsTable.Rows[0]["mSubtotal"]);

                    receipt.StrReceiptNo = strReceiptNo;

                    receipt.SelectOne();

                    OriginalCategoryID=receipt.NCategoryID.Value;

                    receipt.MOutstandingAmount = 0;

                    receipt.StrChildReceiptNo = pos.StrReceiptNo;

                    pos.StrRewardsCode=receipt.StrRewardsCode.ToString();

                    //receipt.StrParentReceiptNo = strReceiptNo;

                    if(receipt.NTherapistID.IsNull != true)
                    {
                        if(receipt.NTherapistID.Value.ToString().Length>0)
                            pos.NTherapistID = receipt.NTherapistID.Value;
                    }

                    receipt.Update();

                    receipt.StrReceiptNo = pos.StrReceiptNo;
                    receipt.SelectOne();
                    receipt.StrParentReceiptNo = strReceiptNo;
                    receipt.Update();

                }
            }
            return  OriginalCategoryID;
        }
Beispiel #15
0
        public void PrintClassAttendanceReminder(int nPackageID, string strMembershipID, int nClassInstanceID)
        {
            TblCompany comp = new TblCompany();
            DataTable compTable = comp.SelectAll();

            int nClassLeft = 0;
            int nDaysToExpire = 0;

            if (compTable != null && compTable.Rows.Count > 0)
            {
                nClassLeft = ACMS.Convert.ToInt32(compTable.Rows[0]["nClassLeft"]);
                nDaysToExpire = ACMS.Convert.ToInt32(compTable.Rows[0]["nDaysToExpire"]);
            }

            TblMemberPackage sqlMemberPackage = new TblMemberPackage();
            DataTable memberPackageTable = sqlMemberPackage.GetMemberPackage(nPackageID);

            ACMSLogic.MemberPackage.CalculateMemberPackageBalance(memberPackageTable.Rows[0]["strPackageCode"].ToString(),strMembershipID, memberPackageTable);

            DateTime expiryDate = ACMS.Convert.ToDateTime(memberPackageTable.Rows[0]["dtExpiryDate"]);

            TblMember member = new TblMember();
            DataTable memberTable = member.LoadData("Select dtDOB, strMemberName from tblMember Where strMembershipID = @strMembershipID",
                new string[] {"@strMembershipID"}, new object[] {strMembershipID});

            ACMSLogic.Printing myReceiptPrinting = new Printing();
            myReceiptPrinting.WriteLine(string.Format("Branch : {0} {1}", User.BranchCode,
                DateTime.Now.ToString("dd/MM/yyyy  hh:mm tt")));
            myReceiptPrinting.WriteLine(string.Format("Membership ID : {0}", strMembershipID));
            myReceiptPrinting.WriteLine(string.Format("Member Name : {0}", memberTable.Rows[0]["strMemberName"].ToString()));
            myReceiptPrinting.WriteLine("");

            if (memberPackageTable.Rows[0]["strPackageCode"].ToString() == "Unlinked")
            {

                myReceiptPrinting.WriteLine("No Valid Fitness Package.");
                //DataTable packageTable = sqlMemberPackage.LoadData("select mListPrice from tblPackage Where strDescription = 'Trial Gym'");
                //myReceiptPrinting.WriteLine("No Valid Fitness Package.");
                myReceiptPrinting.Print();
                return;
            }

            bool bClassPrint ;

            bClassPrint=false;

            if (memberPackageTable.Rows[0]["dtStartDate"] != DBNull.Value)
                myReceiptPrinting.WriteLine(string.Format("Package Start On : {0}",
                    ACMS.Convert.ToDateTime(memberPackageTable.Rows[0]["dtStartDate"]).ToString("dd/MM/yyyy")));

            if (memberPackageTable.Rows[0]["dtExpiryDate"] != DBNull.Value)
                myReceiptPrinting.WriteLine(string.Format("Package Expiry Date : {0}",
                    ACMS.Convert.ToDateTime(memberPackageTable.Rows[0]["dtExpiryDate"]).ToString("dd/MM/yyyy")));

            if (DateTime.Compare(ACMS.Convert.ToDBDateTime(memberPackageTable.Rows[0]["dtStartDate"]),DateTime.Today.Date)==0)
                //if (memberPackageTable.Rows[0]["dtExpiryDate"] == DBNull.Value)
            {
                TblClassAttendance classAttendance = new TblClassAttendance();
                classAttendance.NPackageID = nPackageID;
                int totalClassAttend = classAttendance.SelectAllWnPackageIDLogic().Rows.Count;
                if (totalClassAttend == 1)
                {
                    myReceiptPrinting.WriteLine("Package Has Been Activated.");
                    bClassPrint = true;
                }
            }

            //Print Day To Expiry
            System.TimeSpan timeSpan = expiryDate.Date.Subtract(DateTime.Today.Date);
            if (timeSpan.Days <= nDaysToExpire)
            {
                myReceiptPrinting.WriteLine(string.Format("Days To Expiry : {0}", timeSpan.Days));
                bClassPrint = true;
            }

            //Print Member Package Balance
            int balance = ACMS.Convert.ToInt32(memberPackageTable.Rows[0]["Balance"]);
            if (balance <= nClassLeft)
            {
                myReceiptPrinting.WriteLine(string.Format("Balance Visit : {0} ", balance));
                bClassPrint = true;
            }

            // Check Member Outstanding Receipt
            TblReceipt receipt = new TblReceipt();
            Decimal mTotalOutstanding = 0;
            object obj= receipt.GetOutStandingBalance(strMembershipID);

            if (obj != null)
            {
                mTotalOutstanding = (decimal)obj;
                mTotalOutstanding = decimal.Round(mTotalOutstanding, 2);
            }

            if (mTotalOutstanding > 0)
            {
                myReceiptPrinting.WriteLine("Outstanding Cash Bill Check.");
                bClassPrint = true;
            }

            if (memberPackageTable.Rows[0]["strRemarks"].ToString().Length > 0)
            {
                myReceiptPrinting.WriteLine("Refer To Member Package's Remark.");
                bClassPrint = true;
            }

            if (ACMS.Convert.ToDateTime(memberTable.Rows[0]["DtDOB"]).Date == DateTime.Today.Date)
            {
                myReceiptPrinting.WriteLine("");
                myReceiptPrinting.WriteLine(string.Format("Happy Birthday To {0}.",
                    memberTable.Rows[0]["strMemberName"].ToString()));
                bClassPrint = true;
            }

            //	myReceiptPrinting.Close;
            if (bClassPrint == true)
            {
                myReceiptPrinting.Print();
            }
            else myReceiptPrinting.DelFile();
        }
Beispiel #16
0
        private void UpdateCategoryID(ACMSDAL.ConnectionProvider connProvider, ACMSLogic.POS pos)
        {
            if (pos.NCategoryID == 0 )
            {

                TblReceipt sqlReceipt = new TblReceipt();
                sqlReceipt.MainConnectionProvider = connProvider;

                //foreach (DataRow row in pos.ReceiptItemsTable.Rows)

                    //DataTable classAttendanceTable = classAttendance.GetForgetCardClassAttendance(pos.StrMembershipID, dtDate);

                    DataTable receiptTable = new DataTable();
                    //receipt.NCategoryIDOld = GetOriginalCatID(connProvider, pos, ref branchReceiptNoTable);
                    //receipt.NCategoryID = GetOriginalCatID(connProvider, pos, ref branchReceiptNoTable);

                    sqlReceipt.StrReceiptNo = pos.StrReceiptNo;
                    sqlReceipt.SelectOne();
                    sqlReceipt.SaveData(receiptTable);// .Update();
                }
        }
Beispiel #17
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;
        }