示例#1
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);
        }
示例#2
0
        private void simpleButtonOK_Click(object sender, System.EventArgs e)
        {
            DataRow r = gridView1.GetDataRow(gridView1.FocusedRowHandle);

            if (r != null)
            {
                ACMSDAL.TblMemberPackage sqlCalcAnyOS1 = new ACMSDAL.TblMemberPackage();
                decimal dOutAmount = sqlCalcAnyOS1.OutstandingAmount(myPOS.StrMembershipID);

                if (myPOS.ReceiptMasterTable.Rows[0]["nCategoryID"].ToString() == "9")
                {
                    if (myPOS.ReceiptItemsTable.Select("strCode='" + r["strPackageGroupCode"].ToString() + "'").Length > 0)
                    {
                        MessageBox.Show(this, r["strPackageGroupCode"].ToString() + " already selected!", "Warning");
                        return;
                    }
                }

                if (dOutAmount > 0)
                {
                    DialogResult result1 = MessageBox.Show(this, myPOS.ReceiptMasterTable.Rows[0]["strMemberName"] + " has Outstanding amount of " + (string.Format("{0:C}", dOutAmount)) + "\nDo you want to continue?", "Warning",
                                                           MessageBoxButtons.YesNo);

                    if (result1 == DialogResult.No)
                    {
                        return;
                    }
                }

                if (myCategoryID == 4)
                {
                    //2106
                    TblMember sqlMember = new TblMember();
                    if (sqlMember.MembershipThisMonthBirtdayForUtilised(myPOS.StrMembershipID))
                    {
                        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)
                        {
                            myPOS.NewBillDiscount("120046SSD");
                            myPOS.NewReceiptEntry(r["strPackageCode"].ToString(),
                                                  -1, r["strDescription"].ToString(),
                                                  1, (ACMS.Convert.ToDecimal(r["mListPrice"])), "");
                        }
                        else
                        {
                            myPOS.NewReceiptEntry(r["strPackageCode"].ToString(),
                                                  -1, r["strDescription"].ToString(),
                                                  1, ACMS.Convert.ToDecimal(r["mListPrice"]), "");
                        }
                    }
                    else
                    {
                        myPOS.NewReceiptEntry(r["strPackageCode"].ToString(),
                                              -1, r["strDescription"].ToString(),
                                              1, ACMS.Convert.ToDecimal(r["mListPrice"]), "");
                    }
                }
                // END TEST

                if (myCategoryID == 1 || myCategoryID == 3 ||                // myCategoryID == 4 ||
                    myCategoryID == 6 || myCategoryID == 14 ||
                    myCategoryID == 23)
                {
                    myPOS.NewReceiptEntry(r["strPackageCode"].ToString(),
                                          -1, r["strDescription"].ToString(),
                                          1, ACMS.Convert.ToDecimal(r["mListPrice"]), "");
                }
                else if (myCategoryID == 5)
                {
                    myPOS.NewReceiptEntry(r["strPackageCode"].ToString(), -1, r["strDescription"].ToString(), 1, ACMS.Convert.ToDecimal(r["mListPrice"]), "");
                    DataTable myTblspapacakge = myPOSHelper.SearchOnePackageCode(r["strPackageCode"].ToString());

                    if (myTblspapacakge.Rows[0]["strFreePkgCode"].ToString() != string.Empty)
                    {
                        // ACMSLogic.POSEntries myEntry = new ACMSLogic.POSEntries(r);
                        myPOS.EditItemFreebieAndDiscount(myTblspapacakge.Rows[0]["strFreePkgCode"].ToString());
                    }
                }
                else if (myCategoryID == 2)
                {
                    decimal  mBasePrice      = 0M;
                    decimal  mProRateTotal   = 0M;
                    string   strTypeCard     = string.Empty;
                    string   strCode         = string.Empty;
                    string   strDesc         = string.Empty;
                    string   strCardHolder   = txtCardHolder.Text.Trim();
                    string   strCreditCardNo = txtCreditCardNo.Text.Trim();
                    string   strRefNo        = string.Empty;
                    DateTime dtFrom          = dtProrateFrom.Value;

                    mBasePrice           = ACMS.Convert.ToDecimal(r["mListPrice"]);
                    mProRateTotal        = (2 * mBasePrice);
                    strCode              = r["strPackageCode"].ToString();
                    strDesc              = r["strDescription"].ToString();
                    lblAmount.Text       = "$" + mProRateTotal.ToString();
                    myPOS.dtPackageStart = dtFrom;
                    if (dtProrateFrom.Value.Day != 1 && dtProrateFrom.Value.Day != 16)
                    {
                        MessageBox.Show(" Please select the date either 1st or 16th of the month ");
                        this.DialogResult = DialogResult.None;
                        return;
                    }

                    {
                        myPOS.NewReceiptEntry(strCode, -1, strDesc, 1, mProRateTotal, strRefNo, strCardHolder, strTypeCard, strCreditCardNo);
                    }
                }
                else if (myCategoryID == 7 || myCategoryID == 36 || myCategoryID == 37)
                {
                    myPOS.NewReceiptEntry(r["strCreditPackageCode"].ToString(),
                                          -1, r["strDescription"].ToString(),
                                          1, ACMS.Convert.ToDecimal(r["mListPrice"]), "");
                }
                else if (myCategoryID == 38)
                {
                    myPOS.NewReceiptEntry(r["strSN"].ToString(),
                                          -1, r["strDescription"].ToString(),
                                          1, ACMS.Convert.ToDecimal(r["mValue"]), "");
                }
                else if (myCategoryID == 8 || myCategoryID == 9)
                {
                    myPOS.NewReceiptEntry(r["strPackageGroupCode"].ToString(),
                                          -1, r["strDescription"].ToString(),
                                          1, ACMS.Convert.ToDecimal(r["mListPrice"]), "");
                }
                else if (myCategoryID == 11 || myCategoryID == 12)
                {
                    myPOS.NewReceiptEntry(r["strProductCode"].ToString(),
                                          -1, r["strDescription"].ToString(),
                                          1, ACMS.Convert.ToDecimal(r["mBaseUnitPrice"]), "");
                }
            }
        }