Esempio n. 1
0
        public static void CreateUnLinkPackage()
        {
            TblPackage sqlPackage = new TblPackage();
            sqlPackage.StrPackageCode = "Unlinked";
            DataTable packageTable = sqlPackage.SelectOne();

            if (packageTable == null || packageTable.Rows.Count == 0)
            {
                sqlPackage.StrPackageCode = "Unlinked";
                sqlPackage.NCategoryID = 1;
                sqlPackage.NStatus = 2;
                sqlPackage.DtValidEnd = DateTime.Now;
                sqlPackage.DtValidStart = DateTime.Now;
                sqlPackage.NMaxSession = 10000;
                sqlPackage.Insert();
            }
        }
Esempio n. 2
0
        public void AddRegFees()
        {
            TblMember member = new TblMember();
            member.StrMembershipID = myMembershipID;
            DataTable table = member.SelectOne();
            DataRow memberRow = table.Rows[0];
            bool isRegistered = ACMS.Convert.ToBoolean(memberRow["fRegistrationFee"]);

            if (!isRegistered)
            {
                DialogResult result = MessageBox.Show("You are no yet paid the registration fees. Do you want to pay it now?", "Warning",
                    MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    TblPackage pckg = new TblPackage();
                    pckg.StrPackageCode = "JOINFEE";
                    pckg.SelectOne();

                    NewReceiptEntry("JOINFEE", myStaffPurchaseCategoryID, pckg.StrDescription.IsNull ? "" : pckg.StrDescription.Value,
                        1, ACMS.Convert.ToDecimal(pckg.MListPrice), "");

                    pckg.StrPackageCode = "FA";
                    pckg.SelectOne();

                    NewReceiptEntry("FA", myStaffPurchaseCategoryID, pckg.StrDescription.IsNull ? "" : pckg.StrDescription.Value,
                        1, ACMS.Convert.ToDecimal(pckg.MListPrice), "");
                }

                        }
        }
Esempio n. 3
0
        private int UpgradePackage(ACMSDAL.ConnectionProvider connProvider, ACMSLogic.POS pos)
        {
            int OriginalCategoryID = 10 ;

            if (pos.NCategoryID == 10 && pos.WantToUpgradeMemberPackageTable.Rows.Count == 1)
            {
                int wantToUpgrade_nPackageID = ACMS.Convert.ToInt32(pos.WantToUpgradeMemberPackageRow["nPackageID"]);
                string oldStrPackageCode = pos.WantToUpgradeMemberPackageRow["strPackageCode"].ToString();

                foreach (DataRow r in pos.ReceiptItemsTable.Rows)
                {
                    pos.CheckPackageWhenSave(r["strCode"].ToString(), wantToUpgrade_nPackageID);
                }

                // from here, we can get a list of strClassCode that already been used by member
                //DataTable attendedClassCodetable = GetAttendedClassCode(ACMS.Convert.ToInt32(myWantToUpgradeMemberPackageTable.Rows[0]["nPackageID"]));

                // from here, we can get a list of strClassCode that already been used by member
                //DataTable attendedServiceCodetable = GetAttendedServiceCode(ACMS.Convert.ToInt32(myWantToUpgradeMemberPackageTable.Rows[0]["nPackageID"]));

                TblMemberPackage memberPackage = new TblMemberPackage();
                TblClassAttendance classAttendance = new TblClassAttendance();
                TblServiceSession serviceSession = new TblServiceSession();
                TblPackage freeSpaPackage = new TblPackage();

                memberPackage.MainConnectionProvider = connProvider;
                classAttendance.MainConnectionProvider = connProvider;
                serviceSession.MainConnectionProvider = connProvider;
                freeSpaPackage.MainConnectionProvider = connProvider;

                DataTable memberPackagetable = memberPackage.FillSchema("Select * from tblMemberPackage");

                //get old free spa package Code
                freeSpaPackage.StrPackageCode = oldStrPackageCode;
                DataTable OldFreePackageCode = freeSpaPackage.SelectSpaPackageFreebie();
                string strOldFreePackage = OldFreePackageCode.Rows[0]["strFreePkgCode"].ToString();

                foreach (DataRow r in pos.ReceiptItemsTable.Rows)
                {
                    int nQuantity = ACMS.Convert.ToInt32(r["nQuantity"]);

                    for (int i = 0; i < nQuantity; i++)
                    {
                        DataRow rowToAdd = memberPackagetable.NewRow();
                        MemberPackage.InitMemberPackageRowInPOS(rowToAdd, pos.StrReceiptNo, pos.StrMembershipID, r["strCode"].ToString(), "", false);
                        memberPackagetable.Rows.Add(rowToAdd);
                    }
                }
            //insert a new upgrade package to member package
                if (memberPackagetable.Rows.Count > 0)
                    memberPackage.SaveData(memberPackagetable);

                DataTable newAddMemberPackageTable = memberPackage.SelectAllWstrReceiptNo(pos.StrReceiptNo);
                DataRow[] rowNewAddMemberPackage = newAddMemberPackageTable.Select("fFree = 0");
                DataTable attendedClassTable = classAttendance.GetAllClassAttendancesBasePackageID(wantToUpgrade_nPackageID, pos.StrMembershipID, pos.StrBranchCode);

                DataTable serviceUsedTable = serviceSession.GetMemberServiceSessionBasePackageID(wantToUpgrade_nPackageID, pos.StrMembershipID, pos.StrBranchCode);

            //insert a new freebie package based on new added upgrade pacakge

                string newStrPackageCode = "";
                for( int i = 0; i<newAddMemberPackageTable.Rows.Count; i++)
                {
                    if (newAddMemberPackageTable.Rows[i]["fFree"].ToString() == "False")
                    {
                        if (newAddMemberPackageTable.Rows.Count > 1)
                            newStrPackageCode = newAddMemberPackageTable.Rows[newAddMemberPackageTable.Rows.Count - 1]["strPackageCode"].ToString();
                            else
                             newStrPackageCode = newAddMemberPackageTable.Rows[0]["strPackageCode"].ToString();

                    }
                }
                //get new free spa package Code

                    freeSpaPackage.StrPackageCode = newStrPackageCode;
                    DataTable NewFreePackageCode = freeSpaPackage.SelectSpaPackageFreebie();
                    string strNewFreePackage = NewFreePackageCode.Rows[0]["strFreePkgCode"].ToString();

                if (strNewFreePackage != "")
                {
                    DataTable FreememberPackagetable = memberPackage.FillSchema("Select * from tblMemberPackage");
                    DataRow rowToAdd2 = FreememberPackagetable.NewRow();
                    MemberPackage.InitMemberPackageRowInPOS(rowToAdd2, pos.StrReceiptNo, pos.StrMembershipID, strNewFreePackage, "", true);
                    FreememberPackagetable.Rows.Add(rowToAdd2);
                    if (FreememberPackagetable.Rows.Count > 0)
                        memberPackage.SaveData(FreememberPackagetable);

                    //move session from old freebie to new freebie
                    //find old free package ID,via wantToUpgrade_nPackageID
                    freeSpaPackage.NPackageID = wantToUpgrade_nPackageID;
                    freeSpaPackage.StrPackageCode = oldStrPackageCode;
                    DataTable OldFreePackageID = freeSpaPackage.SelectSpaPackageFreebieID();
                    int nOldFreePackageID;
                    if (OldFreePackageID.Rows.Count > 0)
                        nOldFreePackageID = ACMS.Convert.ToInt32(OldFreePackageID.Rows[OldFreePackageID.Rows.Count - 1]["nPackageID"]);
                    else
                        nOldFreePackageID = 0;

                    DataTable newFreeMemberPackageTable = memberPackage.SelectAllWstrReceiptNo(pos.StrReceiptNo);
                    DataRow[] rowNewFreeMemberPackage = newFreeMemberPackageTable.Select("fFree = 1");
                    DataTable freeserviceUsedTable = serviceSession.GetMemberServiceSessionBasePackageID(nOldFreePackageID, pos.StrMembershipID, pos.StrBranchCode);

                    //foreach (DataRow FmemberPackageRow in rowNewFreeMemberPackage)
                    //{
                    string strFreePackageCode ="";
                    if (rowNewFreeMemberPackage.Length > 0)
                        strFreePackageCode = rowNewFreeMemberPackage[rowNewFreeMemberPackage.Length - 1]["strPackageCode"].ToString();

                        DataRow[] tempRowList3 = freeserviceUsedTable.Select("nPackageID = '"+nOldFreePackageID+"'", "dtDate");

                        if (tempRowList3.Length > 0)
                        {
                            foreach (DataRow freeserviceUsedRow in tempRowList3)
                            {
                                freeserviceUsedRow["nPackageID"] = rowNewFreeMemberPackage[rowNewFreeMemberPackage.Length - 1]["nPackageID"];
                            }

                        }

                        if (tempRowList3.Length > 0)
                        {
                            //update the expiryDate

                            TblPackage package = new TblPackage();
                            package.MainConnectionProvider = connProvider;

                            package.StrPackageCode = strFreePackageCode;
                            DataTable tablePackage = package.SelectOne();

                            if (tablePackage == null && tablePackage.Rows.Count == 0)
                                throw new Exception("Package no found.");

                            if (tempRowList3.Length > 0)
                            {
                                rowNewFreeMemberPackage[rowNewFreeMemberPackage.Length - 1]["DtStartDate"] = ACMS.Convert.ToDateTime(tempRowList3[0]["dtDate"]);

                                rowNewFreeMemberPackage[rowNewFreeMemberPackage.Length - 1]["DtExpiryDate"] = ACMS.Convert.ToDateTime(
                                    rowNewFreeMemberPackage[rowNewFreeMemberPackage.Length - 1]["DtStartDate"]).AddMonths(ACMS.Convert.ToInt32(package.NPackageDuration.Value)).AddDays(-1);
                            }
                        }

                    //}

                    DataTable oldFreeMemberPackageTable = memberPackage.SelectPackageID(nOldFreePackageID);
                    oldFreeMemberPackageTable.Rows[0]["nStatusID"] = 2;
                    serviceSession.UpgradePackage(ACMS.Convert.ToInt32(rowNewFreeMemberPackage[rowNewFreeMemberPackage.Length - 1]["nPackageID"]), nOldFreePackageID, pos.StrMembershipID);
                    memberPackage.SaveData(oldFreeMemberPackageTable);
                    memberPackage.SaveData(newFreeMemberPackageTable);

                }

            //move session from old package to new package
                foreach (DataRow memberPackageRow in rowNewAddMemberPackage)
                {
                    string strPackageCode = memberPackageRow["strPackageCode"].ToString();

                    DataRow[] tempRowList = attendedClassTable.Select("nPackageID = '" + wantToUpgrade_nPackageID + "'", "dtDate");

                    if (tempRowList.Length > 0)
                    {
                        foreach (DataRow attendedClassRow in tempRowList)
                        {   // new packageID
                            attendedClassRow["nPackageID"] = memberPackageRow["nPackageID"];
                        }
                    }

                    DataRow[] tempRowList2 = serviceUsedTable.Select("nPackageID = '" + wantToUpgrade_nPackageID + "'", "dtDate");

                    if (tempRowList2.Length > 0)
                    {
                        foreach (DataRow serviceUsedRow in tempRowList2)
                        {
                        serviceUsedRow["nPackageID"] = memberPackageRow["nPackageID"];
                        }

                    }

                    if (tempRowList.Length > 0 ||
                        tempRowList2.Length > 0)
                    {
                        //update the expiryDate

                        TblPackage package = new TblPackage();
                        package.MainConnectionProvider = connProvider;

                        package.StrPackageCode = strPackageCode;
                        DataTable tablePackage = package.SelectOne();

                        TblPackageExtension PackExtension = new TblPackageExtension();
                        PackExtension.MainConnectionProvider = connProvider;

                        PackExtension.NPackageID = ACMS.Convert.ToInt32(rowNewAddMemberPackage[0]["nPackageID"]);
                        PackExtension.NPackageIDOld = wantToUpgrade_nPackageID;
                        int days = 0;
                        DataTable tblPkgExt = PackExtension.SelectExtensionDays();
                        if (PackExtension.NDaysExtended.IsNull == false)
                        days = System.Convert.ToInt32(PackExtension.NDaysExtended.Value);

                        if (tablePackage == null && tablePackage.Rows.Count == 0)
                            throw new Exception("Package no found.");

                        if (tempRowList.Length > 0 && tempRowList2.Length == 0)
                        {

                            ///07/11/2012 Jackie

                            DataTable  myDataTable1;
                            DateTime dtDate;
                            ACMSDAL.TblClassAttendance ClassAttendance = new ACMSDAL.TblClassAttendance();
                            myDataTable1 = ClassAttendance.LoadData("Select top 1 dtDate From tblClassAttendance where  nstatusid=1 and nPackageID= " + wantToUpgrade_nPackageID + " and  " +
                             " strMemberShipID = @strMembershipID order by dtDate",
                                new string[] { "@strMembershipID" },
                                new object[] { pos.StrMembershipID });
                            dtDate = DateTime.Now;
                            if (myDataTable1.Rows.Count > 0)
                                dtDate = System.Convert.ToDateTime(myDataTable1.Rows[0][0]);

                            memberPackageRow["DtStartDate"] = dtDate;
                           // Stop

                            memberPackageRow["DtExpiryDate"] =  ACMS.Convert.ToDateTime(
                                memberPackageRow["DtStartDate"]).AddMonths(ACMS.Convert.ToInt32(package.NPackageDuration.Value)).AddDays(days - 1);
                        }
                        else if (tempRowList2.Length > 0 &&
                            tempRowList.Length == 0)
                        {
                            memberPackageRow["DtStartDate"] = ACMS.Convert.ToDateTime(tempRowList2[0]["dtDate"]);

                            memberPackageRow["DtExpiryDate"] =  ACMS.Convert.ToDateTime(
                                memberPackageRow["DtStartDate"]).AddMonths(ACMS.Convert.ToInt32(package.NValidMonths.Value)).AddDays(days - 1);
                        }
                    }
                }
                OriginalCategoryID=  ACMS.Convert.ToDBInt32(pos.WantToUpgradeMemberPackageRow["nCategoryID"]) ;
                pos.WantToUpgradeMemberPackageRow["nStatusID"] = 2;

                serviceSession.UpgradePackage(ACMS.Convert.ToInt32(rowNewAddMemberPackage[0]["nPackageID"]), wantToUpgrade_nPackageID, pos.StrMembershipID);
                memberPackage.SaveData(pos.WantToUpgradeMemberPackageTable);
                memberPackage.SaveData(newAddMemberPackageTable);

                classAttendance.SaveData(wantToUpgrade_nPackageID,pos.StrMembershipID);

            }
            return OriginalCategoryID;
        }
Esempio n. 4
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"];
                }
            }
        }
Esempio n. 5
0
        public static void InitMemberPackageRowInPOS(DataRow memberPackageRow, string strReceiptNo,
			string strMembershipID, string strPackageCode, string strPromotionCode, bool isFree, int nGiroRefID,
			DateTime dtPackageStart, int ProDays)
        {
            TblPackage package = new TblPackage();
            package.StrPackageCode = strPackageCode;
            package.SelectOne();
            int packageDuration = package.NPackageDuration.IsNull ? 0 : package.NPackageDuration.Value;

            memberPackageRow["strMembershipID"] = strMembershipID;
            memberPackageRow["strReceiptNo"] = strReceiptNo;
            memberPackageRow["nEmployeeID"] = ACMSLogic.User.EmployeeID;
            memberPackageRow["nStatusID"] = 0; // Active
            memberPackageRow["dtLastEdit"] = System.DateTime.Today;
            memberPackageRow["fFree"] = isFree? 1 : 0;
            memberPackageRow["strPackageCode"] = strPackageCode;
            memberPackageRow["dtPurchaseDate"] = System.DateTime.Today;
            memberPackageRow["dtStartDate"] = dtPackageStart;

            if(dtPackageStart.Day > 1 && dtPackageStart.Day <=16)
            memberPackageRow["dtExpiryDate"] = new DateTime(dtPackageStart.Year,dtPackageStart.Month,15).AddMonths(packageDuration);
            else if(dtPackageStart.Day > 16 && dtPackageStart.Day <=31)
            memberPackageRow["dtExpiryDate"] = new DateTime(dtPackageStart.Year,dtPackageStart.Month,1).AddMonths(packageDuration+1).AddDays(-1);
            else if (dtPackageStart.Day == 1)
            memberPackageRow["dtExpiryDate"] = new DateTime(dtPackageStart.Year,dtPackageStart.Month,1).AddMonths(packageDuration).AddDays(-1);

            memberPackageRow["strRemarks"] = strPromotionCode;
            memberPackageRow["nBalance"]=1;
            memberPackageRow["nAdjust"]=0;

            if (nGiroRefID >= 0)
                memberPackageRow["nGIRORefID"] = nGiroRefID;

            if (ACMS.Convert.ToInt32(package.NCategoryID) == 6)
            {
                int nWarrantyMonths = ACMS.Convert.ToInt32(package.NWarrantyMonths);
                memberPackageRow["dtWarrantyDate"] = System.DateTime.Today.Date.AddMonths(nWarrantyMonths - 1);
            }
        }
Esempio n. 6
0
        public static void InitMemberPackageRowInPOS(DataRow memberPackageRow, string strReceiptNo,
			string strMembershipID, string strPackageCode, string strPromotionCode, bool isFree)
        {
            TblPackage package = new TblPackage();
            package.StrPackageCode = strPackageCode;
            package.SelectOne();
            //int packageDuration = package.NPackageDuration.IsNull ? 0 : package.NPackageDuration.Value;

            memberPackageRow["strMembershipID"] = strMembershipID;
            memberPackageRow["strReceiptNo"] = strReceiptNo;
            memberPackageRow["nEmployeeID"] = ACMSLogic.User.EmployeeID;
            memberPackageRow["nStatusID"] = 0; // Active
            memberPackageRow["dtLastEdit"] = System.DateTime.Today;
            memberPackageRow["fFree"] = isFree? 1 : 0;
            memberPackageRow["strPackageCode"] = strPackageCode;
            memberPackageRow["dtPurchaseDate"] = System.DateTime.Today;
            //memberPackageRow["dtExpiryDate"] = System.DateTime.Today.AddMonths(packageDuration - 1);
            memberPackageRow["strRemarks"] = strPromotionCode;
            memberPackageRow["nBalance"]=1;
            memberPackageRow["nAdjust"]=0;

            if (ACMS.Convert.ToInt32(package.NCategoryID) == 6)
            {
                int nWarrantyMonths = ACMS.Convert.ToInt32(package.NWarrantyMonths);
                memberPackageRow["dtWarrantyDate"] = System.DateTime.Today.Date.AddMonths(nWarrantyMonths - 1);
            }
        }
Esempio n. 7
0
        private void CalculateUsageBalanceForConvert(ACMSLogic.POS myPOS)
        {
            if (myDataTable != null)
            {
                if (!myDataTable.Columns.Contains("PaidAmt"))
                {
                    DataColumn colBalance = new DataColumn("PaidAmt", System.Type.GetType("System.Decimal"));
                    myDataTable.Columns.Add(colBalance);
                }
                if (!myDataTable.Columns.Contains("UsedSession"))
                {
                    DataColumn colBalance = new DataColumn("UsedSession", System.Type.GetType("System.Int32"));
                    myDataTable.Columns.Add(colBalance);
                }
                if (!myDataTable.Columns.Contains("UsedAmt"))
                {
                    DataColumn colBalance = new DataColumn("UsedAmt", System.Type.GetType("System.Decimal"));
                    myDataTable.Columns.Add(colBalance);
                }
                if (!myDataTable.Columns.Contains("UsageBalAmt"))
                {
                    DataColumn colBalance = new DataColumn("UsageBalAmt", System.Type.GetType("System.Decimal"));
                    myDataTable.Columns.Add(colBalance);
                }
                if (!myDataTable.Columns.Contains("strCalculation"))
                {
                    DataColumn colBalance = new DataColumn("strCalculation", System.Type.GetType("System.String"));
                    myDataTable.Columns.Add(colBalance);
                }

                //Added by TBBC on 9 September 2015 for SG 50 Promotion Upgrade Issue
                if (!myDataTable.Columns.Contains("PromoDis"))
                {
                    DataColumn colBalance = new DataColumn("PromoDis", System.Type.GetType("System.String"));
                    myDataTable.Columns.Add(colBalance);
                }

                DataTable dtSG50Promo;
                bool bolSG50Promo;
                bolSG50Promo = false;

                foreach (DataRow r in myDataTable.Rows)
                {
                    dtSG50Promo = myMemberPackage.GetSG50PromotionUpgrade(r["strReceiptNo"].ToString());

                    foreach (DataRow row in dtSG50Promo.Rows)
                    {
                        if ((ACMS.Convert.ToInt32(r["nPackageID"])) == (ACMS.Convert.ToInt32(row["nPackageID"])))
                        {
                            r["mSubTotal"] = row["mSubTotal"];
                            r["PromoDis"] = row["PromoDis"];
                            bolSG50Promo = true;
                        }
                    }

                    string strCalculation = "Calculation:\n";
                    int usedSession = 0;
                    if (ACMS.Convert.ToInt32(r["nMaxSession"]) != 9999)
                    {
                        usedSession = (ACMS.Convert.ToInt32(r["nMaxSession"]) - ACMS.Convert.ToInt32(r["nFreeSession"])) - (ACMS.Convert.ToInt32(r["Balance"]) - ACMS.Convert.ToInt32(r["nFreeSession"]));
                    }
                    else
                    {
                        if (r["dtStartDate"] == DBNull.Value || r["dtExpiryDate"] == DBNull.Value)
                            usedSession = 0;
                        else
                        {
                            strCalculation += "Unlimited Session Conversion:\n";
                            DateTime DtExpiryDate = Convert.ToDateTime(r["dtStartDate"]).AddMonths(Convert.ToInt16(r["nPackageDuration"])).AddDays(-1);
                            int extMonths=0;
                            if (Convert.ToDateTime(r["dtExpiryDate"]) > DtExpiryDate) //extension case
                            {
                                strCalculation += "Package Duration Extension Case: Yes\n";
                                int balMonth = getBalMonthExtend(DateTime.Now, Convert.ToDateTime(r["dtExpiryDate"]));
                                strCalculation += "Balance Months: " + balMonth.ToString() + "\n";
                                usedSession = Convert.ToInt16(r["nPackageDuration"]) - balMonth;
                            }
                            //extMonths = (Convert.ToDateTime(r["dtExpiryDate"]).Month - DtExpiryDate.Month) + 12 * (Convert.ToDateTime(r["dtExpiryDate"]).Year - DtExpiryDate.Year) - Convert.ToInt16(r["nFreeDuration"]);
                            else
                                usedSession = getUsedMonth(Convert.ToDateTime(r["dtStartDate"]), DateTime.Now);

                            strCalculation += "Used Months: " + usedSession.ToString() + "\n";
                            //usedSession = ((DateTime.Now.Month - Convert.ToDateTime(r["dtStartDate"]).Month) + 12 * (DateTime.Now.Year - Convert.ToDateTime(r["dtStartDate"]).Year)) - extMonths;
                            //r["nMaxSession"] = Convert.ToInt16(r["nPackageDuration"]);
                        }
                    }
                    bool isSameSpaCat = false;
                    if (ACMS.Convert.ToInt32(myPOS.NCategoryID) == ACMS.Convert.ToInt32(r["nCategoryID"]) && myPOS.NCategoryID == 5 && r["strFreePkgCode"] != DBNull.Value)
                    {
                        //spa package same category conversion
                        foreach (DataRow dr in myPOS.ReceiptItemsTable.Rows)
                        {
                            TblPackage package = new TblPackage();
                            package.StrPackageCode = dr["strCode"].ToString();
                            package.SelectOne();
                            if (r["fNoRestrictionUpgrade"].ToString() == package.FNoRestrictionUpgrade.ToString())
                            {
                                isSameSpaCat = true;
                                if (ACMS.Convert.ToInt32(r["nFreeUtil"]) > usedSession)
                                    usedSession = ACMS.Convert.ToInt32(r["nFreeUtil"]);
                                break;
                            }
                        }
                    }
                    if (myPOS.NCategoryID == 5)
                        strCalculation += "Is same SPA category upgrade? " + (isSameSpaCat ? "Yes" : "No")+"\n";
                    double usedAmount = usedSession * ACMS.Convert.ToDouble(r["mBaseUnitPrice"]);

                    double subTotal = ACMS.Convert.ToDouble(r["mSubTotal"]);
                    double totalSubTotal = ACMS.Convert.ToDouble(r["totalSubTotal"]);
                    double totalBillDiscount;
                    double packageBillDiscount = 0;
                    //double packageOutstanding = 0;
                    double paidAmount;
                    //if (r["strDiscountCode"] != DBNull.Value && ACMS.Convert.ToDouble(r["mNettAmount"]) + ACMS.Convert.ToDouble(r["mUpgradeAmount"]) < totalSubTotal)
                    //{
                    if (ACMS.Convert.ToDouble(r["mNettAmount"]) + ACMS.Convert.ToDouble(r["mUpgradeAmount"]) < totalSubTotal)
                    {
                        //totalBillDiscount = totalSubTotal - (ACMS.Convert.ToDouble(r["mNettAmount"]) + ACMS.Convert.ToDouble(r["mUpgradeAmount"]));
                        totalBillDiscount = totalSubTotal - (ACMS.Convert.ToDouble(r["mTotalPaid"]));
                        packageBillDiscount = totalBillDiscount * subTotal / totalSubTotal;

                        if (subTotal != totalSubTotal)
                            strCalculation += "Proportionate Bill Discount= " + totalBillDiscount.ToString() + " (Total Bill Discount) x (" + subTotal.ToString() + "/" + totalSubTotal.ToString() + ")\n";
                        else
                            strCalculation += "Bill Discount= " + totalBillDiscount.ToString() + " (Total Bill Discount) x (" + subTotal.ToString() + "/" + totalSubTotal.ToString() + ")\n";
                    }

                    //if (ACMS.Convert.ToDouble(r["mOutstandingAmount"]) > 0)
                    //{
                    //    packageOutstanding = ACMS.Convert.ToDouble(r["mOutstandingAmount"]) * subTotal / totalSubTotal / 1.07;
                    //}
                    paidAmount = (subTotal - packageBillDiscount); // ACMS.Convert.ToDouble(r["mUpgradeAmount"]); //- packageOutstanding;
                    strCalculation += "Paid Amt = " + subTotal.ToString() + " (Price after Item Discount) - " + packageBillDiscount.ToString() + " (Proportionate Bill Discount) = " + paidAmount.ToString() +"\n";
                    r["PaidAmt"] = paidAmount;
                    r["UsedSession"] = usedSession;
                    r["UsedAmt"] = usedAmount;
                    r["UsageBalAmt"] = paidAmount - usedAmount;

                    //if ((isSameSpaCat==false && ACMS.Convert.ToInt32(r["nCategoryID"]) == 5 && r["strFreePkgCode"] != DBNull.Value) || (isSameSpaCat==false && (ACMS.Convert.ToInt32(r["nCategoryID"]) == 5 || ACMS.Convert.ToInt32(r["nCategoryID"]) == 6)))
                    if (isSameSpaCat == false && ACMS.Convert.ToInt32(r["nCategoryID"]) == 5 && r["strFreePkgCode"] != DBNull.Value)
                    {
                        //spa package different category conversion
                        r["UsedAmt"] = ACMS.Convert.ToDouble(r["mFreeUtil"]);
                        r["UsageBalAmt"] = paidAmount - ACMS.Convert.ToDouble(r["mFreeUtil"]);
                    }
                    strCalculation += "Used Amt = " + r["UsedAmt"].ToString() + "\n";
                    strCalculation += "Usage Bal Amt = " + paidAmount.ToString() + " (Paid Amt) - " + r["UsedAmt"].ToString() + " (Used Amt) = " + Math.Round(ACMS.Convert.ToDouble(r["UsageBalAmt"]), 2).ToString() + "\n";
                    r["strCalculation"] = strCalculation;
                }
                if (bolSG50Promo == true)
                {
                    string message = "The member has purchased SG50 Promotion Package !";
                    string caption = "Upgrading from existing package to new package";
                    MessageBoxButtons buttons = MessageBoxButtons.OK;
                    DialogResult result;
                    // Displays the MessageBox.

                    result = MessageBox.Show(message, caption, buttons);

                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        bolSG50Promo = false;
                    }
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Use to Transfer Service Session or Update the service Session
        /// </summary>
        /// <param name="nSessionID"></param>
        /// <param name="dtDate"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="strBranchCode"></param>
        /// <param name="nPackageID"></param>
        /// <param name="strServiceCode"></param>
        /// <param name="nEmployeeInChargeID"></param>
        /// <param name="remark"></param>
        /// <param name="isTransfer"></param>
        public void UpdateServiceSession(int nSessionID, DateTime dtDate, DateTime startTime,  DateTime endTime,
			string strBranchCode, int nPackageID, string strServiceCode, 
			int nEmployeeInChargeID, string remark, int status, bool isTransfer)
        {
            TblServiceSession serviceSession = new TblServiceSession();
            serviceSession.NSessionID = nSessionID;
            DataTable table = serviceSession.SelectOne();
            if (table == null || table.Rows.Count == 0)
                throw new Exception("failed to update this package. Record not found");

            TblService service = new TblService();
            service.StrServiceCode = strServiceCode;
            DataTable serviceTable = service.SelectOne();
            if (serviceTable == null || serviceTable.Rows.Count == 0)
                throw new Exception("The service is not available.");

            int duration = ACMS.Convert.ToInt32(service.NDuration);

            bool isPT = ACMS.Convert.ToInt32(service.NServiceTypeID) == 0;

            if (!isTransfer)
            {
                if (!isPT && !ACMSLogic.SpaBooking.VerifyMemberPackageAllowCertainService(nPackageID, strServiceCode))
                    throw new Exception("this member package is not allow to use the service");

                if (endTime == DateTime.MinValue)
                    endTime = startTime.AddMinutes((Double)duration);

                if (dtDate != DateTime.MinValue)
                    serviceSession.DtDate = dtDate;
                if (startTime != DateTime.MinValue)
                    serviceSession.DtStartTime = startTime;
                if (endTime != DateTime.MinValue)
                    serviceSession.DtEndTime= endTime;
                if (strBranchCode != "")
                    serviceSession.StrBranchCode = strBranchCode;
                if (strServiceCode != "")
                    serviceSession.StrServiceCode = strServiceCode;
                if (nEmployeeInChargeID != -1)
                    serviceSession.NServiceEmployeeID = nEmployeeInChargeID;
                if (nPackageID != -1)
                    serviceSession.NPackageID = nPackageID;
                if (remark != "")
                    serviceSession.StrRemarks = remark;
                if (status != -1)
                    serviceSession.NStatusID  = status;

                if (status == 5)
                    serviceSession.NMarkedByID = User.EmployeeID;
            }
            else
            {
                serviceSession.NPackageID = nPackageID;
            }

            myMemberPackage.NPackageID = nPackageID;
            DataTable memberPackageTable = myMemberPackage.SelectOne();

            if (memberPackageTable == null || memberPackageTable.Rows.Count == 0)
                throw new Exception("Failed to create new service session. Member Package with npackageID = "+ nPackageID.ToString() + "has been deleted");

            DataRow masterRow = memberPackageTable.Rows[0];

            if (masterRow["dtStartDate"] == DBNull.Value)
            {
                // Means new class Attendance gonna insert
                TblPackage package = new TblPackage();
                package.StrPackageCode = masterRow["strPackageCode"].ToString();
                DataTable tablePackage = package.SelectOne();

                if (tablePackage == null && tablePackage.Rows.Count == 0)
                    throw new Exception("Failed to update service session. Package no found.");

                myMemberPackage.DtStartDate = serviceSession.DtDate.Value;
                myMemberPackage.DtExpiryDate = serviceSession.DtDate.Value.AddMonths(package.NPackageDuration.Value).AddDays(-1);
            }
            else
            {
                DateTime memberPackageStartDate =  ACMS.Convert.ToDateTime(masterRow["DtStartDate"]);
                DateTime memberPackageExpiryDate = ACMS.Convert.ToDateTime(masterRow["dtExpiryDate"]);

                if (memberPackageStartDate > serviceSession.DtDate.Value)
                {
                    myMemberPackage.DtExpiryDate = memberPackageExpiryDate.Subtract(memberPackageStartDate.Subtract(serviceSession.DtDate.Value));
                }
            }

            serviceSession.NEmployeeID = User.EmployeeID;
            serviceSession.DtLastEditDate = DateTime.Now;

            ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider();

            try
            {
                myMemberPackage.MainConnectionProvider = connProvider;
                serviceSession.MainConnectionProvider = connProvider;

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

                myMemberPackage.Update();
                serviceSession.Update();

                connProvider.CommitTransaction();
            }
            catch (Exception)
            {
                connProvider.RollbackTransaction("SaveServiceSession");
                throw new Exception("Failed to save Service Session");
            }
            finally
            {
                if (connProvider.CurrentTransaction != null)
                    connProvider.CurrentTransaction.Dispose();
                if (connProvider.DBConnection != null)
                {
                    if (connProvider.DBConnection.State == ConnectionState.Open)
                        connProvider.DBConnection.Close();
                }
                myMemberPackage.MainConnactionIsCreatedLocal = true;
                serviceSession.MainConnactionIsCreatedLocal = true;
            }
        }
Esempio n. 9
0
        public void UpdateClassAttendance(int nAttendanceID, int nNewPackageID)
        {
            TblClassAttendance classAttendance = new TblClassAttendance();
            System.Data.SqlTypes.SqlInt32 nOldPackageID;

            classAttendance.NAttendanceID = nAttendanceID;
            DataTable table = classAttendance.SelectOne();
            if (table != null && table.Rows.Count > 0)
            {
                nOldPackageID = classAttendance.NPackageID;
                classAttendance.NEmployeeID = User.EmployeeID;
                classAttendance.NPackageID = nNewPackageID;

                myMemberPackage.NPackageID = nNewPackageID;
                DataTable memberPackageTable = myMemberPackage.SelectOne();
                if (memberPackageTable == null || memberPackageTable.Rows.Count == 0)
                    throw new Exception("Failed to update/transfer class attendance. Member Package with Package ID = "+ nNewPackageID.ToString() + "has been deleted");

                DataRow masterRow = memberPackageTable.Rows[0];
                TblPackage package = new TblPackage();
                package.StrPackageCode = masterRow["strPackageCode"].ToString();
                package.SelectOne();

                if (masterRow["dtStartDate"] == DBNull.Value)
                {
                    if (!package.FGIRO || package.FGIRO.IsNull)
                    {
                        myMemberPackage.DtStartDate = classAttendance.DtDate;
                        int iduration = package.NPackageDuration.Value;
                        if (package.StrDurationUnit.ToString().Trim() == "DAY")
                            myMemberPackage.DtExpiryDate = classAttendance.DtDate.Value.AddDays(iduration - 1).AddDays(0);
                        else if (package.StrDurationUnit.ToString().Trim() == "WEEK")
                        {
                            iduration = iduration * 7;
                            myMemberPackage.DtExpiryDate = classAttendance.DtDate.Value.AddDays(iduration - 1).AddDays(0);
                        }
                        else
                            myMemberPackage.DtExpiryDate = classAttendance.DtDate.Value.AddMonths(package.NPackageDuration.Value).AddDays(-1);
                    }
                }
                else
                {
                    if (!package.FGIRO || package.FGIRO.IsNull)
                    {
                        if (classAttendance.DtDate < ACMS.Convert.ToDateTime(masterRow["DtStartDate"]))
                        {
                            myMemberPackage.DtStartDate = classAttendance.DtDate;
                            int iduration = package.NPackageDuration.Value;
                            if (package.StrDurationUnit.ToString().Trim() == "DAY")
                                myMemberPackage.DtExpiryDate = classAttendance.DtDate.Value.AddDays(iduration - 1).AddDays(0);
                            else if (package.StrDurationUnit.ToString().Trim() == "WEEK")
                            {
                                iduration = iduration * 7;
                                myMemberPackage.DtExpiryDate = classAttendance.DtDate.Value.AddDays(iduration - 1).AddDays(0);
                            }
                            else
                                myMemberPackage.DtExpiryDate = classAttendance.DtDate.Value.AddMonths(package.NPackageDuration.Value).AddDays(-1);
                        }
                        else
                        {
                            DateTime memberPackageStartDate = ACMS.Convert.ToDateTime(masterRow["DtStartDate"]);
                            DateTime memberPackageExpiryDate = ACMS.Convert.ToDateTime(masterRow["dtExpiryDate"]);

                            if (memberPackageStartDate > classAttendance.DtDate)
                            {
                                myMemberPackage.DtExpiryDate = memberPackageExpiryDate.Subtract(memberPackageStartDate.Subtract(classAttendance.DtDate.Value));
                                myMemberPackage.DtStartDate = classAttendance.DtDate;
                            }
                        }
                    }
                }

                ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider();

                try
                {
                    myMemberPackage.MainConnectionProvider = connProvider;
                    classAttendance.MainConnectionProvider = connProvider;

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

                    myMemberPackage.Update();
                    classAttendance.Update();
                    //UpdateStartExpiryDate(nOldPackageID);

                    connProvider.CommitTransaction();
                    connProvider.BeginTransaction("SaveClassAttendance");
                    UpdateStartExpiryDate(nOldPackageID);
                    connProvider.CommitTransaction();
                }
                catch (Exception)
                {
                    connProvider.RollbackTransaction("SaveClassAttendance");
                    throw new Exception("Failed to save Class Attendance");
                }
                finally
                {
                    if (connProvider.CurrentTransaction != null)
                        connProvider.CurrentTransaction.Dispose();
                    if (connProvider.DBConnection != null)
                    {
                        if (connProvider.DBConnection.State == ConnectionState.Open)
                            connProvider.DBConnection.Close();
                    }
                    myMemberPackage.MainConnactionIsCreatedLocal = true;
                    classAttendance.MainConnactionIsCreatedLocal = true;
                }
            }
        }
Esempio n. 10
0
        public void Save(DataTable table)
        {
            string strPackageCode = table.Rows[0]["StrPackageCode"].ToString();
            TblPackage package = new TblPackage();
            package.StrPackageCode = strPackageCode;
            package.SelectOne();
            //int packageDuration = package.NPackageDuration.IsNull ? 0 : package.NPackageDuration.Value;
            int nCategoryID = ACMS.Convert.ToInt32(package.NCategoryID);

            //table.Rows[0]["dtExpiryDate"] = System.DateTime.Today.Date.AddMonths(packageDuration - 1);

            if (nCategoryID == 6)
            {
                int nWarrantyMonths = ACMS.Convert.ToInt32(package.NWarrantyMonths);

                table.Rows[0]["dtWarrantyDate"] = System.DateTime.Today.Date.AddMonths(nWarrantyMonths - 1);
            }

            myMemberPackage.SaveData(table);
        }
Esempio n. 11
0
        public bool NewServiceSession(int nPackageID, string strServiceCode, string strMemberShipID, int nEmployeeID,
            string strBranchCode, DateTime dtDate, DateTime startTime, DateTime dtTreatment, string strSignID, int nQuatity, Boolean forfeited,
            int MemberPackageCategoryID, string strSigKey, string strPdfExportPath, ref DataTable dtSessionID, string SsRemark)
        {
            // i will know whether the service session is for PT or not by using strServiceCode and query out the record from tblService.
            // i also can calculate the endTime using the data(nduration) from tblService

            TblService service = new TblService();
            service.StrServiceCode = strServiceCode;
            DataTable table = service.SelectOne();
            if (table == null || table.Rows.Count == 0)
                throw new Exception("The service is not available.");

            int duration = ACMS.Convert.ToInt32(service.NDuration);

            bool isPT = ACMS.Convert.ToInt32(service.NServiceTypeID) == 0;

            DateTime endTime = startTime.AddMinutes((Double)duration);

            TblEmployee Employee = new TblEmployee();
            Employee.NEmployeeID = nEmployeeID;
            DataTable Emptable = Employee.SelectOne();

            if (Emptable.Rows[0]["fPartTime"].ToString() == "True" || ACMSLogic.SpaBooking.TherapistIsAvailableToBook(nEmployeeID, dtDate, startTime, endTime, strBranchCode))
            {

                TblServiceSession serviceSession = new TblServiceSession();
                serviceSession.NPackageID = nPackageID;
                serviceSession.StrMembershipID = strMemberShipID;
                serviceSession.StrServiceCode = strServiceCode;
                serviceSession.NStatusID = 5;
                serviceSession.DtDate = dtDate;
                serviceSession.DtStartTime = startTime;
                serviceSession.DtEndTime = endTime;
                serviceSession.DtLastEditDate = DateTime.Now;
                serviceSession.NEmployeeID = User.EmployeeID;
                serviceSession.NMarkedByID = User.EmployeeID;
                serviceSession.NServiceEmployeeID = nEmployeeID;
                serviceSession.DtTreatment = dtTreatment;
                serviceSession.StrSignID = strSignID;
                serviceSession.StrSigKey = strSigKey;
                serviceSession.StrSigPdfPath = strPdfExportPath;
                serviceSession.StrUtilData = strSigKey;
                serviceSession.StrRemarks = SsRemark;

                if (forfeited == true)
                {
                    serviceSession.StrRemarks = "FORFEITED";
                }

                if (isPT)
                {
                    serviceSession.StrBranchCode = strBranchCode;
                }
                else
                    serviceSession.StrBranchCode = User.BranchCode;

                TblMemberPackage memberPackage = new TblMemberPackage();
                //1309
                memberPackage.NPackageID = nPackageID;
                DataTable memberPackageTable = memberPackage.GetMemberPackage(nPackageID);
                if (memberPackageTable == null || memberPackageTable.Rows.Count == 0)
                    throw new Exception("Failed to create new service session. Member Package with npackageID = " + nPackageID.ToString() + "has been deleted");

                CalculateMemberPackageBalance(strServiceCode, strMemberShipID, memberPackageTable);
                if (ACMS.Convert.ToInt32(memberPackageTable.Rows[0]["Balance"]) == 0 || ACMS.Convert.ToInt32(memberPackageTable.Rows[0]["Balance"]) - nQuatity < 0)
                    throw new Exception("The balance of this member's package is zero.");

                // Kean Yiap
                DataRow masterRow = memberPackageTable.Rows[0];
                if (masterRow["dtStartDate"] == DBNull.Value &&
                    masterRow["dtExpiryDate"] == DBNull.Value)
                {
                    // Means new service session gonna insert
                    TblPackage package = new TblPackage();
                    package.StrPackageCode = masterRow["strPackageCode"].ToString();
                    package.SelectOne();
                    masterRow["dtStartDate"] = dtDate;
                    masterRow["dtExpiryDate"] = dtDate.AddMonths(package.NPackageDuration.Value).AddDays(-1);
                }
                else
                {
                    DateTime memberPackageStartDate = ACMS.Convert.ToDateTime(masterRow["DtStartDate"]);
                    DateTime memberPackageExpiryDate = ACMS.Convert.ToDateTime(masterRow["dtExpiryDate"]);

                    if (memberPackageStartDate > dtDate)
                    {
                        masterRow["dtExpiryDate"] = memberPackageExpiryDate.Subtract(memberPackageStartDate.Subtract(dtDate));
                    }
                }

                ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider();

                try
                {
                    memberPackage.MainConnectionProvider = connProvider;
                    serviceSession.MainConnectionProvider = connProvider;

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

                    memberPackage.SaveData(memberPackageTable);

                    for (int i = 0; i < nQuatity; i++)
                    {
                        serviceSession.Insert();  //Capture Session ID Here

                        DataRow ssRow;
                        ssRow = dtSessionID.NewRow();
                        ssRow["nSessionID"] = Convert.ToInt32(serviceSession.NSessionID.Value);
                        ssRow["strMembershipID"] = strMemberShipID;
                        dtSessionID.Rows.Add(ssRow);
                    }

                    connProvider.CommitTransaction();
                    //DEREK Wrong Here Need to Fix //Use DataTable //Same goes with Live Version
                    //mySessionID = Convert.ToInt32(serviceSession.NSessionID.Value);

                    return true;
                }
                catch (Exception ex)
                {
                    connProvider.RollbackTransaction("SaveClassAttendance");
                    throw new Exception("Failed to save Class Attendance");
                }
                finally
                {
                    if (connProvider.CurrentTransaction != null)
                        connProvider.CurrentTransaction.Dispose();
                    if (connProvider.DBConnection != null)
                    {
                        if (connProvider.DBConnection.State == ConnectionState.Open)
                            connProvider.DBConnection.Close();
                    }
                    memberPackage.MainConnactionIsCreatedLocal = true;
                    serviceSession.MainConnactionIsCreatedLocal = true;

                }

            }
            else
            {
                return false;
            }
        }
Esempio n. 12
0
        public bool NewClassAttendance(int nPackageID, string strMemberShipID, int nClassInstance,
            int nType, string strBranchCode, DateTime classDate,
            DateTime startTime, DateTime endTime, bool isRefunded)
        {
            if (!isRefunded)
            {
                ACMSDAL.TblReceipt sqlReceipt = new ACMSDAL.TblReceipt();
                DataTable receipttable = sqlReceipt.GetToDayForgetCardReceipt(strMemberShipID, 17);

                if (receipttable == null || receipttable.Rows.Count == 0)
                {
                    throw new Exception("You have yet to pay the forget card deposit today.");
                }
            }

            TblClassAttendance classAttendance = new TblClassAttendance();
            bool isPostFromOtherRecord = false;
            bool needtoAddBackOneDayExpiryDate = false;
            bool BalanceStatus = true;
            DataTable memberPackageTable = null;

            if (nType != 1)
            {

                DataRow classAttendanceRow = null;

                bool isAttendedNow = classAttendance.IsAttendedThisClass(nClassInstance, strMemberShipID, ref classAttendanceRow);

                if (isAttendedNow)
                {
                    int nStatusID = ACMS.Convert.ToInt32(classAttendanceRow["nStatusID"]);

                    if (nStatusID == 1)
                    {
                        // Process
                        throw new Exception("Member already been marked in this class.");
                    }
                    else
                    {
                        //Forfeit and need to change to process
                        if (classAttendanceRow != null)
                        {
                            int nClassAttendanceID = ACMS.Convert.ToInt32(classAttendanceRow["nAttendanceID"]);
                            classAttendance.NAttendanceID = nClassAttendanceID;
                            classAttendance.SelectOne();
                            isPostFromOtherRecord = true;
                            nPackageID = classAttendance.NPackageID.Value;
                            isRefunded = classAttendance.FRefunded.IsNull ? true : classAttendance.FRefunded.Value;

                            // this only true if the package is unlimited one
                            memberPackageTable = myMemberPackage.GetMemberPackage(nPackageID);

                            if (ACMS.Convert.ToInt32(memberPackageTable.Rows[0]["nMaxSession"]) == 9999)
                                needtoAddBackOneDayExpiryDate = true;
                        }
                    }
                }
                else if (classAttendanceRow != null && nType == 0)
                {
                    int nClassAttendanceID = ACMS.Convert.ToInt32(classAttendanceRow["nAttendanceID"]);

                    classAttendance.NAttendanceID = nClassAttendanceID;
                    classAttendance.SelectOne();
                    isPostFromOtherRecord = true;
                    nPackageID = classAttendance.NPackageID.Value;
                    isRefunded = classAttendance.FRefunded.IsNull ? true : classAttendance.FRefunded.Value;
                }
            }

            if (memberPackageTable == null)
            {
                myMemberPackage.NPackageID = nPackageID;
                memberPackageTable = myMemberPackage.GetMemberPackage(nPackageID);
            }

            if (memberPackageTable == null || memberPackageTable.Rows.Count == 0)
                throw new Exception("Failed to create new class attendance. Member Package with npackageID = " + nPackageID.ToString() + "has been deleted");

            classAttendance.NPackageID = nPackageID;
            classAttendance.StrMembershipID = strMemberShipID;
            classAttendance.NClassInstanceID = nClassInstance;
            classAttendance.NTypeID = nType;
            classAttendance.StrBranchCode = strBranchCode;
            classAttendance.DtDate = classDate;
            classAttendance.DtStartTime = startTime;
            classAttendance.DtEndTime = endTime;
            classAttendance.DtLastEditDate = DateTime.Now;
            classAttendance.NEmployeeID = ACMSLogic.User.EmployeeID;

            //indicated free class or not
            TblClassInstance classInstance = new TblClassInstance();
            DataTable Instance = classInstance.LoadData("Select fFree from tblClassInstance Where nClassInstanceID = @nClassInstanceID",
                new string[] { "@nClassInstanceID" }, new object[] { nClassInstance });

            if (Instance.Rows[0][0].ToString() == "True")
                classAttendance.NStatusID = 4;
            else
                classAttendance.NStatusID = 1;

            classAttendance.FRefunded = isRefunded;// System.Data.SqlTypes.SqlBoolean.

            //UnLinked is for temporary only
            if (memberPackageTable.Rows[0]["strPackageCode"].ToString() != "Unlinked")
            {
                CalculateMemberPackageBalance(memberPackageTable.Rows[0]["strPackageCode"].ToString(), strMemberShipID, memberPackageTable);

                DataRow masterRow = memberPackageTable.Rows[0];

                //				if (ACMS.Convert.ToDBInt32(memberPackageTable.Rows[0]["Balance"])<999 &&  ACMS.Convert.ToDBInt32(memberPackageTable.Rows[0]["nAdjust"])>=1)
                //				{
                //					memberPackageTable.Rows[0]["Balance"]=ACMS.Convert.ToDBInt32(memberPackageTable.Rows[0]["Balance"])- ACMS.Convert.ToDBInt32(memberPackageTable.Rows[0]["nAdjust"]);
                //				}

                if (ACMS.Convert.ToInt32(memberPackageTable.Rows[0]["Balance"]) <= 0)
                {
                    throw new Exception("Balance is zero");
                    masterRow["nBalance"] = false;
                    BalanceStatus = false;
                }

                if (masterRow["fGiro"].ToString() != "1")
                {
                    if ((masterRow["dtStartDate"] == DBNull.Value &&
                    masterRow["dtExpiryDate"] == DBNull.Value) || (masterRow["dtStartDate"] != DBNull.Value && Convert.ToDateTime(masterRow["dtStartDate"]) > classDate))
                    {
                        // Means new class Attendance gonna insert
                        TblPackage package = new TblPackage();
                        package.StrPackageCode = masterRow["strPackageCode"].ToString();
                        package.SelectOne();

                        //if (package.NPackageDuration.Value == 0 && package.NPackageDay.Value > 0)
                        //{
                        //    masterRow["dtStartDate"] = classDate;
                        //    masterRow["dtExpiryDate"] = classDate.AddDays(package.NPackageDay.Value - 1);
                        //}
                        //else
                        //{
                        //    masterRow["dtStartDate"] = classDate;
                        //    masterRow["dtExpiryDate"] = classDate.AddMonths(package.NPackageDuration.Value).AddDays(-1);
                        //}

                        //jackie Start 05042012
                        masterRow["dtStartDate"] = classDate;
                        if (package.NPackageDuration.Value == 0)
                        {

                            string txt = package.StrPackageCode.ToString();

                            if (txt == "FTRIAL")
                            {
                                masterRow["dtExpiryDate"] = classDate.AddDays(1).AddDays(0);
                            }
                            else
                            {
                                string strduration;

                                int cstarts = txt.IndexOf("(") + 1;
                                int len = txt.IndexOf(")") - cstarts;
                                txt = txt.Substring(cstarts, len);

                                if (string.IsNullOrEmpty(txt))
                                {
                                    strduration = string.Empty;
                                }
                                else
                                {
                                    int lens = txt.Length;
                                    strduration = txt.Substring(txt.Length - 1, 1);
                                }

                                if (strduration == "D")
                                {

                                    strduration = txt.Replace("D", "");
                                    int iduration = Int32.Parse(strduration);
                                    masterRow["dtExpiryDate"] = classDate.AddDays(iduration - 1).AddDays(0);

                                }
                                if (strduration == "W")
                                {
                                    strduration = txt.Replace("W", "");
                                    int iduration = Int32.Parse(strduration);
                                    iduration = iduration * 7;
                                    masterRow["dtExpiryDate"] = classDate.AddDays(iduration - 1).AddDays(0);

                                }
                            }

                        }
                        else
                        {
                            int iduration = package.NPackageDuration.Value;
                            if (package.StrDurationUnit.ToString().Trim() == "DAY")
                                masterRow["dtExpiryDate"] = classDate.AddDays(iduration - 1).AddDays(0);
                            else if (package.StrDurationUnit.ToString().Trim() == "WEEK")
                            {
                                iduration = iduration * 7;
                                masterRow["dtExpiryDate"] = classDate.AddDays(iduration - 1).AddDays(0);
                            }
                            else if (package.StrDurationUnit.ToString().Trim() == "MONTH")
                                masterRow["dtExpiryDate"] = classDate.AddMonths(package.NPackageDuration.Value).AddDays(-1);
                        }
                        //jackie END 2/02/2012

                    }
                    else
                    {
                        // Kean Yiap
                        string strPackageCode = masterRow["strPackageCode"].ToString();
                        CalculateMemberPackageBalance(strPackageCode, strMemberShipID, memberPackageTable);
                        DateTime memberPackageStartDate = ACMS.Convert.ToDateTime(masterRow["DtStartDate"]);
                        DateTime memberPackageExpiryDate = ACMS.Convert.ToDateTime(masterRow["dtExpiryDate"]);

                        //if (memberPackageStartDate > classDate)
                        //{
                        //jackie why must change ExpiryDate 26042012
                        //	masterRow["dtExpiryDate"] = memberPackageExpiryDate.Subtract(memberPackageStartDate.Subtract(classDate));
                        //}
                    }
                }

                if (ACMS.Convert.ToInt32(memberPackageTable.Rows[0]["Balance"]) <= 1)
                {
                    if (masterRow["strPackageCode"].ToString() == "FTRIAL")
                    {
                        memberPackageTable.Rows[0]["nBalance"] = 1;
                    }
                    else
                    {
                        memberPackageTable.Rows[0]["nBalance"] = 0;
                    }
                }

            }

            ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider();

            try
            {
                myMemberPackage.MainConnectionProvider = connProvider;
                classAttendance.MainConnectionProvider = connProvider;

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

                if (needtoAddBackOneDayExpiryDate && memberPackageTable.Rows[0]["fGIRO"].ToString() != "1")
                {
                    memberPackageTable.Rows[0]["dtExpiryDate"] = ACMS.Convert.ToDateTime(memberPackageTable.Rows[0]["dtExpiryDate"]).AddDays(1);
                }

                myMemberPackage.SaveData(memberPackageTable);

                if (BalanceStatus)
                {
                    if (!isPostFromOtherRecord)
                        classAttendance.Insert();
                    else
                        classAttendance.Update();

                    connProvider.CommitTransaction();
                }

                return true;
            }
            catch (Exception)
            {
                connProvider.RollbackTransaction("SaveClassAttendance");
                throw new Exception("Failed to save Class Attendance");
            }
            finally
            {
                if (connProvider.CurrentTransaction != null)
                    connProvider.CurrentTransaction.Dispose();
                if (connProvider.DBConnection != null)
                {
                    if (connProvider.DBConnection.State == ConnectionState.Open)
                        connProvider.DBConnection.Close();
                }
                myMemberPackage.MainConnactionIsCreatedLocal = true;
                classAttendance.MainConnactionIsCreatedLocal = true;
            }
        }
Esempio n. 13
0
        public void MarkAttendance(int nClassInstanceID, int nPackageID, string strMembershipID, 
			int nClassType, bool isRefunded, bool needToVerifyMemberPackage)
        {
            MemberPackage memberPackage = new MemberPackage();
            bool createNewClassAttendance = false;

            ACMSDAL.TblClassInstance sqlClassInstance = new TblClassInstance();
            sqlClassInstance.NClassInstanceID = nClassInstanceID;
            sqlClassInstance.SelectOne();

            if (sqlClassInstance.NActualInstructorID.IsNull)
                throw new Exception("No intructor has logined to this class. You cannot mark the attendance now.");

            //verify non peak package holder
            TblMemberPackage clsMemberPackage = new TblMemberPackage();
            clsMemberPackage.NPackageID = nPackageID;
            clsMemberPackage.SelectOne();

            TblPackage clsPackage = new TblPackage();
            clsPackage.StrPackageCode = clsMemberPackage.StrPackageCode;
            clsPackage.SelectOne();

            if (clsPackage.FPeak.IsNull == false && sqlClassInstance.FPeak.IsNull == false) {
                if (clsPackage.FPeak.Value == false && sqlClassInstance.FPeak == false) { }
                else
                {
                    throw new Exception("Member holding Leisure Package and only allow to mark the attendance for non peak classes.");
                }
            }

            if (needToVerifyMemberPackage)
            {
                if (!VerifyMemberPackageAllowCertainClass(nPackageID, sqlClassInstance.StrClassCode.Value))
                {
                    //throw new Exception("The package you wish to use is not allow to attend the class. Please use other package.");
                    DialogResult result = MessageBox.Show("The package you wish to use is not allow to attend the class. Do you still want to mark it. \n " +
                        "(An unlinked record will be create if you click yes) ", "Warning",MessageBoxButtons.YesNo);

                    if (result == DialogResult.Yes)
                    {
                        MemberPackage.CreateUnlinkedMemberPackage(strMembershipID, ref nPackageID);
                    }
                    else
                    {
                        return;
                    }
                }
            }

            createNewClassAttendance = memberPackage.NewClassAttendance(nPackageID, strMembershipID, nClassInstanceID, nClassType,
                User.BranchCode, sqlClassInstance.DtDate.Value, sqlClassInstance.DtStartTime.Value, sqlClassInstance.DtEndTime.Value, isRefunded);

            if (nPackageID >= 0)
                PrintClassAttendanceReminder(nPackageID, strMembershipID, nClassInstanceID);
        }
Esempio n. 14
0
        public bool VerifyIntructor(int nClassInstanceIDToBeVerified, int verifyUserID,string verifyUserPassword,
			int nStandingIntructorID, string remark)
        {
            TblEmployee verifyUser = new TblEmployee();

            verifyUser.NEmployeeID = verifyUserID;

            verifyUser.SelectOne();

            int [,] intArray = new int[50,2];

            int ArrayNo=1;

            if (verifyUser.StrPassword.Value != verifyUserPassword)

                return false;

            myClassInstance.NClassInstanceID = nClassInstanceIDToBeVerified;

            myClassInstance.SelectOne();

            if (myClassInstance.NActualInstructorID.IsNull)

                throw new Exception("Missing Intructor login info");

            if (myClassInstance.NActualInstructorID.Value == verifyUserID)

                throw new Exception("Instructor are not allowed to verfiy for the same class.");

            if (!myClassInstance.NVerifyID.IsNull)

                throw new Exception("This class have been verify by other staff with the employee ID : "+  myClassInstance.NVerifyID.Value.ToString());

            bool isLate =false;

            DateTime StartTime;

            DateTime LoginTime;

            myClassInstance.MInstructorDeduction=0;

            StartTime=ACMS.Convert.ToDBDateTime(myClassInstance.DtStartTime.Value.ToLongTimeString());

            LoginTime=ACMS.Convert.ToDBDateTime(myClassInstance.DtInstructorLogin.Value.ToLongTimeString());

            if (DateTime.Compare(LoginTime,StartTime)>0)

            {

                isLate=true;

            }

            bool haveStandingIntructor = nStandingIntructorID > 0;

            if (haveStandingIntructor)

                myClassInstance.NStandinInstructorID = nStandingIntructorID;

            if (isLate)

            {

                TblCompany company = new TblCompany();

                DataTable companyTable = company.SelectAll();

                decimal instructorLateDeductionFee = 0;

                if (companyTable.Rows.Count > 0)

                {

                    instructorLateDeductionFee =  ACMS.Convert.ToDecimal(companyTable.Rows[0]["mInstructorLateDeductionFee"]);

                }

                myClassInstance.MInstructorDeduction=instructorLateDeductionFee;

                if (nStandingIntructorID != 0)

                    myClassInstance.MStandinInstructorFees = instructorLateDeductionFee;

            }

            int nCommissionTypeID = myClassInstance.NCommissionTypeID.Value;

            TblEmployee actualInstructor = new TblEmployee();

            actualInstructor.NEmployeeID = myClassInstance.NActualInstructorID;

            actualInstructor.SelectOne();

            int nInstructorTypeID = ACMS.Convert.ToInt32(actualInstructor.NInstructorTypeID);

            myClassInstance.MInstructorFees = (GetCommission(nCommissionTypeID, nInstructorTypeID) - myClassInstance.MInstructorDeduction);

            TblClassAttendance classAttendance = new TblClassAttendance();

            classAttendance.NClassInstanceID = nClassInstanceIDToBeVerified;

            DataTable classAttendanceTable = classAttendance.SelectAllWnClassInstanceIDLogic();

            DataRow[] classAttendanceRowList = null;

            if (classAttendanceTable != null && classAttendanceTable.Rows.Count > 0)

            {

                classAttendanceRowList = classAttendanceTable.Select("nStatusID = 0", "nAttendanceID", DataViewRowState.CurrentRows);

                foreach (DataRow r in classAttendanceRowList)

                {

                    r["nStatusID"] = 2;
                    r["nTypeID"]=0;

                }

            }

            ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider();

            try

            {

                myClassInstance.MainConnectionProvider = connProvider;

                classAttendance.MainConnectionProvider = connProvider;

                connProvider.OpenConnection();

                connProvider.BeginTransaction("VerifyClassInstance");

                myClassInstance.NVerifyID = verifyUserID;

                myClassInstance.StrRemarks = remark;

                myClassInstance.Update();

                classAttendance.SaveData(classAttendanceTable);

                TblMemberPackage sqlMemberPackage = new TblMemberPackage();

                sqlMemberPackage.MainConnectionProvider = connProvider;

                if (classAttendanceRowList != null)

                {

                    int nPackageID = -1;

                    foreach (DataRow r in classAttendanceRowList)

                    {

                        nPackageID = ACMS.Convert.ToInt32(r["nPackageID"]);

                        int nAttendanceID=ACMS.Convert.ToInt32(r["nAttendanceID"]);

                        DataTable memberPackageTable = sqlMemberPackage.GetMemberPackage(nPackageID);

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

                        {

                            #region test

                            //MemberPackage.CalculateMemberPackageBalance(memberPackageTable, connProvider);

                            if (ACMS.Convert.ToInt32(memberPackageTable.Rows[0]["Balance"]) > 0)

                            {

                                DateTime classDate = myClassInstance.DtDate.IsNull ? DateTime.Today.Date : myClassInstance.DtDate.Value;

                                DataRow masterRow = memberPackageTable.Rows[0];// Means new class Attendance gonna insert

                                if (masterRow["dtStartDate"] == DBNull.Value &&

                                    masterRow["dtExpiryDate"] == DBNull.Value)

                                {

                                    TblPackage package = new TblPackage();

                                    package.StrPackageCode = masterRow["strPackageCode"].ToString();

                                    package.SelectOne();

                                    if (package.NPackageDuration == 0 && package.NPackageDay > 0)
                                    {
                                        masterRow["dtStartDate"] = classDate;
                                        masterRow["dtExpiryDate"] = classDate.AddDays(package.NPackageDay.Value -1);
                                    }
                                    else
                                    {
                                        masterRow["dtStartDate"] = classDate;
                                        masterRow["dtExpiryDate"] = classDate.AddMonths(package.NPackageDuration.Value).AddDays(-1);
                                    }

                                }

                                else

                                {

                                    DateTime memberPackageStartDate =  ACMS.Convert.ToDateTime(masterRow["DtStartDate"]);

                                    DateTime memberPackageExpiryDate = ACMS.Convert.ToDateTime(masterRow["dtExpiryDate"]);

                                    if (memberPackageStartDate > classDate)

                                    {

                                        masterRow["dtExpiryDate"] = memberPackageExpiryDate.Subtract(memberPackageStartDate.Subtract(classDate));

                                    }

                                }

                            }

                            else if (ACMS.Convert.ToInt32(memberPackageTable.Rows[0]["Balance"]) <=0)

                            {

                                intArray[ArrayNo,0]=nPackageID;

                                intArray[ArrayNo,1]=nAttendanceID;

                                ArrayNo=ArrayNo+1;

                                MessageBox.Show("Package Balance of " + memberPackageTable.Rows[0]["strMembershipID"].ToString().TrimEnd() + " is Zero. Attendance will be cancel");

                            }

                            #endregion

                        }

                        if (ACMS.Convert.ToInt32(memberPackageTable.Rows[0]["nMaxSession"]) == 9999 && memberPackageTable.Rows[0]["fGIRO"].ToString() != "1")
                        {

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

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

                            if (dtExpiryDate != DateTime.MinValue)

                            {

                                memberPackageTable.Rows[0]["dtExpiryDate"] = dtExpiryDate.AddDays(-1);

                            }

                        }

                        sqlMemberPackage.SaveData(memberPackageTable);

                    }

                }

                connProvider.CommitTransaction();

            }

            catch (Exception)

            {

                connProvider.RollbackTransaction("VerifyClassInstance");

                throw;

            }

            finally

            {

                if (connProvider.CurrentTransaction != null)

                    connProvider.CurrentTransaction.Dispose();

                if (connProvider.DBConnection != null)

                {

                    if (connProvider.DBConnection.State == ConnectionState.Open)

                        connProvider.DBConnection.Close();

                }

                myClassInstance.MainConnactionIsCreatedLocal = true;

                classAttendance.MainConnactionIsCreatedLocal = true;

            }

            for (int j=1;j<=50;j++)

            {

                if (intArray[j,0]>0) DeleteClassAttendance(intArray[j,0],intArray[j,1],"");

                else if (intArray[j,0]<=0)

                {return true;}

            }

            return true;
        }
Esempio n. 15
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;
        }
Esempio n. 16
0
        public void NewRedemption(string strMembershipID, string itemCode, int qtyOfItemCodeToRedempt, ref int strTransNo)
        {
            ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider();
            connProvider.OpenConnection();
            TblRewardsCatalogue catalogue = new TblRewardsCatalogue();
            catalogue.StrItemCode = itemCode;
            catalogue.SelectOne();

            TblRewardsTransaction rewardTrans = new TblRewardsTransaction();
            rewardTrans.MainConnectionProvider = connProvider;
            rewardTrans.StrMembershipID = strMembershipID;
            rewardTrans.DtDate = DateTime.Now;
            rewardTrans.NTypeID = 2;
            rewardTrans.StrReferenceNo = itemCode;
            rewardTrans.NEmployeeID = User.EmployeeID;
            rewardTrans.StrBranchCode = User.BranchCode;

            if (!catalogue.DRewardsPoints.IsNull)
                rewardTrans.DRewardsPoints = -catalogue.DRewardsPoints.Value * qtyOfItemCodeToRedempt;

            rewardTrans.Insert();
            strTransNo = rewardTrans.NTransactionID.Value;
            TblPromotionFreebie promoFreebie = new TblPromotionFreebie();
            promoFreebie.StrPromotionCode = itemCode;
            DataTable receiptFreebieTable = promoFreebie.SelectAllWstrPromotionCodeLogic();
            //Code selected is Promotion Freebie Code
            if (receiptFreebieTable.Rows.Count > 0)
            {
                //TblProductInventory proInven = new TblProductInventory();
                //proInven.MainConnectionProvider = connProvider;

                //// deduct stock
                //foreach (DataRow r in receiptFreebieTable.Rows)
                //{
                //    proInven.IncreaseQuantity(r["strItemCode"].ToString(), User.BranchCode, -qtyOfItemCodeToRedempt);
                //}
            }
            else
            {
                //Code selected is Package Code
                TblPackage pkg = new TblPackage();
                pkg.StrPackageCode = itemCode;
                DataTable pkgTable = pkg.SelectOne();
                if (pkgTable.Rows.Count > 0)
                {
                    TblMemberPackage mp = new TblMemberPackage();
                    mp.SelectAll();
                    MemberPackage memberPackage = new MemberPackage();
                    DataTable memberPackageTable = memberPackage.New(false, strMembershipID);
                    DataRow memberPackageRow = memberPackageTable.Rows[0];

                    memberPackageRow["strMembershipID"] = strMembershipID;
                    memberPackageRow["dtPurchaseDate"] = DateTime.Now;
                    memberPackageRow["strRemarks"] = "REWARDS";
                    memberPackageRow["nStatusID"] = 0;
                    memberPackageRow["strPackageCode"] = itemCode;
                    memberPackageRow["fFree"] = 1;

                    mp.SaveData(memberPackageTable);
                }
                else
                {
                    //Code selected is Product Code
                    //TblProductInventory productInvent = new TblProductInventory();
                    //productInvent.MainConnectionProvider = connProvider;
                    //productInvent.StrProductCode = itemCode;
                    //productInvent.SelectOne();

                    //productInvent.NQuantity = ACMS.Convert.ToInt32(productInvent.NQuantity) - qtyOfItemCodeToRedempt;
                    //productInvent.Update();
                }
            }

            if (connProvider.CurrentTransaction != null)
                connProvider.CurrentTransaction.Dispose();

            if (connProvider.DBConnection != null)
            {
                if (connProvider.DBConnection.State == ConnectionState.Open)
                    connProvider.DBConnection.Close();
            }
        }