private void btnPrint_Click(object sender, System.EventArgs e) { #region dyiwei if (myPOS.MOutstandingAmount == myPOS.MTotalAmount) { if (myPOS.MOutstandingAmount == 0) { DialogResult zeroTender = MessageBox.Show(this, string.Format("Proceed to Tender with zero amount value"), "Warning", MessageBoxButtons.YesNo); if (zeroTender == DialogResult.No) { this.DialogResult = DialogResult.None; return; } } } # endregion //2903 bool HasCashMode = false; decimal remainder; decimal receiptAmt_temp; decimal paymentAmount = 0; decimal receiptTotalAmt = 0; decimal outstandingAmt = 0; decimal DepositAmount = 0; string ONOFF_State = ""; TblPaymentPlan myPaymentPlan = new TblPaymentPlan(); ONOFF_State = myPaymentPlan.GetInhouseIPP_ONOFF_State().ToString(); if (gridView1.RowCount == 0) { MessageBox.Show(this, "Please Key In at least 1 payment code."); this.DialogResult = DialogResult.None; return; } if (myPOS.NCategoryID == 1 || myPOS.NCategoryID == 3 || myPOS.NCategoryID == 4 || myPOS.NCategoryID == 5 || myPOS.NCategoryID == 6 || myPOS.NCategoryID == 7 || myPOS.NCategoryID == 8 || myPOS.NCategoryID == 9 || myPOS.NCategoryID == 14 || myPOS.NCategoryID == 36 || myPOS.NCategoryID == 37) { //decimal paymentAmount = 0; //decimal receiptTotalAmt = 0; //decimal outstandingAmt = 0; decimal mininum1stPayment = 0; decimal percentageControl = Convert.ToDecimal(0.3); if (ONOFF_State == "1") { percentageControl = Convert.ToDecimal(0.4); } //Get ReceiptMasterTable's Total Amount receiptTotalAmt = ACMS.Convert.ToDecimal(myPOS.ReceiptMasterTable.Rows[0]["mTotalAmount"]); //Get Outstanding Amount outstandingAmt = ACMS.Convert.ToDecimal(myPOS.ReceiptMasterTable.Rows[0]["mOutstandingAmount"]); //Get Payment Amount if (myPOS.ReceiptPaymentTable != null && myPOS.ReceiptPaymentTable.Rows.Count > 0) { foreach (DataRow r in myPOS.ReceiptPaymentTable.Rows) { paymentAmount += ACMS.Convert.ToDecimal(r["mAmount"]); if (r["strPaymentCode"].ToString() == "CASH") { HasCashMode = true; } } } //Fixing Deposit if (myPOS.StrDeposit != null || myPOS.StrDeposit != "") { try { TblReceipt DepositReceipt = new TblReceipt(); DepositReceipt.StrReceiptNo = myPOS.StrDeposit; DataTable tblDeposit = DepositReceipt.SelectOne(); DepositAmount = (decimal)(DepositReceipt.MTotalAmount.IsNull ? 0 : DepositReceipt.MTotalAmount.Value); //paymentAmount += DepositAmount; } catch { } } if (HasCashMode) { remainder = myPOS.MTotalAmount % ACMS.Convert.ToDecimal(0.05); receiptAmt_temp = myPOS.MTotalAmount - remainder; if (receiptAmt_temp == paymentAmount) { receiptTotalAmt = receiptAmt_temp; outstandingAmt = 0; } } //if (myPOS.StrParentReceiptNo != DBNull.Value || myPOS.StrParentReceiptNo != "") //{ //Deposit //} //else //{ try { //Derek Instalment Plan //If ReceiptMaster Total < 300 - full payment is required - include Joining Fees and GST if ((receiptTotalAmt + DepositAmount) < 300 && ONOFF_State == "1") { if (receiptTotalAmt > paymentAmount) { MessageBox.Show("Full payment is required for bill total less than SGD 300."); this.DialogResult = DialogResult.None; return; } } //1st instalment must be 40% of the total mininum1stPayment = (decimal.Ceiling(percentageControl * (receiptTotalAmt + DepositAmount) * 10) / 10); //percentageControl * receiptTotalAmt; if ((paymentAmount + DepositAmount) < mininum1stPayment) { MessageBox.Show("Need to pay at least $" + string.Format("{0:0,0.00}", mininum1stPayment) + " (" + (Convert.ToInt32(percentageControl * 100)).ToString() + "%) of bill total (before deposit offset).\n\n" + "Please pay another $" + string.Format("{0:0,0.00}", mininum1stPayment - (paymentAmount + DepositAmount))); this.DialogResult = DialogResult.None; return; } //Derek Instalment Plan if (outstandingAmt > 0) { //Check If Total Payment Amount is round figures //Else Reject /*if (paymentAmount != (Convert.ToInt32(paymentAmount * 100) / 100)) { if (decimal.Ceiling(paymentAmount) <= receiptTotalAmt) { MessageBox.Show("Please pay well rounded amount of $ " + decimal.Ceiling(paymentAmount).ToString() + ", as you still have outstanding."); this.DialogResult = DialogResult.None; return; } else { MessageBox.Show("Please full amount of $ " + receiptTotalAmt.ToString()); this.DialogResult = DialogResult.None; return; } }*/ if (ONOFF_State == "1") { string strPackageCodeList = ""; int mytotalInstalment = 0; foreach (DataRow r in myPOS.ReceiptItemsTable.Rows) { strPackageCodeList += r["strCode"].ToString() + ","; } //Work Out the instalment plan //Params: paymentAmount, receiptTotalAmt, outstandingAmt //Update myPOS.PaymentPlanTable //TblPaymentPlan myPaymentPlan = new TblPaymentPlan(); //GetInhouseIPP_ONOFF_State //frmMasterReceiptNo = strMasterReceiptNo; //frmMasterReceiptTotal = mMasterReceiptTotal; //frmPaymentAmount = mPaymentAmount; //frmOutstandingAmount = mOutstandingAmount; //frmPackageList = strPackageList; DataTable dtIPPTotalNOptions = myPaymentPlan.GetInhouseIPPTotalNOptions("", (receiptTotalAmt + DepositAmount), paymentAmount, outstandingAmt, strPackageCodeList); if (dtIPPTotalNOptions.Rows.Count > 1) { FormPaymentPlan frm = new FormPaymentPlan(myPOS, "", (receiptTotalAmt + DepositAmount), paymentAmount, outstandingAmt, strPackageCodeList); DialogResult result = frm.ShowDialog(); if (result == DialogResult.OK) { mytotalInstalment = Convert.ToInt32(frm.NTotalInstalment.ToString()); } else { this.DialogResult = DialogResult.None; return; } } else if (dtIPPTotalNOptions.Rows.Count == 1) { mytotalInstalment = Convert.ToInt32(dtIPPTotalNOptions.Rows[0]["nInstalmentNo"]); } myPaymentPlan.StrMasterReceiptNo = ""; myPaymentPlan.MMasterReceiptTotal = (receiptTotalAmt + DepositAmount); myPaymentPlan.MOutstandingAmount = outstandingAmt; myPaymentPlan.MPaymentAmount = paymentAmount; myPaymentPlan.StrPackageList = strPackageCodeList; myPaymentPlan.NEnforceTotalInstalment = mytotalInstalment; myPOS.myPaymentPlanTable = myPaymentPlan.GetInhouseInstalmentPaymentPlan(); } } //Payment Tab to highlight receipt that have instalment plan - light blue //Temporary suspension of the usage of the purchased package under the receipt if the due date of the "last instalment" is missed //Packages under the receipt will be fully nullified (expired) if the final due dates (any instalments) myPOS.MTotalAmount = receiptTotalAmt; myPOS.MOutstandingAmount = outstandingAmt; } catch (Exception ex) { MessageBox.Show("Error Occur: Outstanding Payment - New Inhouse Instalment Payment Plan. " + ex.Message); this.DialogResult = DialogResult.None; return; } } else if (myPOS.NCategoryID == 0) { //Derek Instalment Plan //#Get Total Payment Here //#Check If Pay Outstanding Category = Yes; Cat = 0 //#Get strCode Receipt No as 1st Reference ReceiptNo //#Get Master receipt and match it from tblPaymentPlan //#If Receipt Found In Payment Plan Table //#Get the Next Instalment Amount //#If Next Instalment Amount = 0 then abort and return error //#Check If the Payment Amount >= the next instalment amount //#If Yes => Update the tblPaymentPlan DataTable and save later //#Else Return; //#Else (Master Receipt Not Found In Payment Plan Table) //#Proceed to normal flow try { decimal subsequentInstalmentAmt = 0; string strParentReceiptNo = myPOS.ReceiptItemsTable.Rows[0]["strCode"].ToString(); string strMasterReceiptNo = ""; //Get ReceiptMasterTable's Total Amount receiptTotalAmt = ACMS.Convert.ToDecimal(myPOS.ReceiptMasterTable.Rows[0]["mTotalAmount"]); //Get Outstanding Amount outstandingAmt = ACMS.Convert.ToDecimal(myPOS.ReceiptMasterTable.Rows[0]["mOutstandingAmount"]); //Get Payment Amount if (myPOS.ReceiptPaymentTable != null && myPOS.ReceiptPaymentTable.Rows.Count > 0) { foreach (DataRow r in myPOS.ReceiptPaymentTable.Rows) { paymentAmount += ACMS.Convert.ToDecimal(r["mAmount"]); if (r["strPaymentCode"].ToString() == "CASH") { HasCashMode = true; } } } if (HasCashMode) { remainder = myPOS.MTotalAmount % ACMS.Convert.ToDecimal(0.05); receiptAmt_temp = myPOS.MTotalAmount - remainder; if (receiptAmt_temp == paymentAmount) { receiptTotalAmt = receiptAmt_temp; outstandingAmt = 0; } } if (myPOS.StrParentReceiptNo != DBNull.Value || myPOS.StrParentReceiptNo != "") { } else { if (outstandingAmt > 0) { } //1st instalment must be 100% of the total //TblPaymentPlan myPaymentPlan = new TblPaymentPlan(); if (ONOFF_State == "1") { //Get Master Receipt No strMasterReceiptNo = myPaymentPlan.GetInhouseIPPMasterOSReceipt(strParentReceiptNo); //Get Next Instalment Amount subsequentInstalmentAmt = myPaymentPlan.GetInhouseIPPNextInstalmentAmount(strMasterReceiptNo); if (subsequentInstalmentAmt > 0) { if (paymentAmount < subsequentInstalmentAmt) { if (paymentAmount == receiptTotalAmt) { myPOS.myPaymentPlanTable = myPaymentPlan.GetInhouseAdjustedIPP_PayOS(strMasterReceiptNo, "", paymentAmount); } else { MessageBox.Show("Need to pay at least 100% of the subsequent instalment amount of SGD " + subsequentInstalmentAmt); this.DialogResult = DialogResult.None; return; } } else { //Work Out the New instalment plan //Params: paymentAmount, receiptTotalAmt, outstandingAmt //Update myPOS.PaymentPlanTable myPOS.myPaymentPlanTable = myPaymentPlan.GetInhouseAdjustedIPP_PayOS(strMasterReceiptNo, "", paymentAmount); } } else { //Proceed to normal flow //No Inhouse Instalment Payment Plan } } } myPOS.MTotalAmount = receiptTotalAmt; myPOS.MOutstandingAmount = outstandingAmt; } catch { MessageBox.Show("Error Occur: Outstanding Payment - Subsequent Inhouse IPP Payment"); this.DialogResult = DialogResult.None; return; } } else { try { //Get ReceiptMasterTable's Total Amount receiptTotalAmt = ACMS.Convert.ToDecimal(myPOS.ReceiptMasterTable.Rows[0]["mTotalAmount"]); //Get Outstanding Amount outstandingAmt = ACMS.Convert.ToDecimal(myPOS.ReceiptMasterTable.Rows[0]["mOutstandingAmount"]); //Get Payment Amount if (myPOS.ReceiptPaymentTable != null && myPOS.ReceiptPaymentTable.Rows.Count > 0) { foreach (DataRow r in myPOS.ReceiptPaymentTable.Rows) { paymentAmount += ACMS.Convert.ToDecimal(r["mAmount"]); if (r["strPaymentCode"].ToString() == "CASH") { HasCashMode = true; } } } if (HasCashMode) { remainder = myPOS.MTotalAmount % ACMS.Convert.ToDecimal(0.05); receiptAmt_temp = myPOS.MTotalAmount - remainder; if (receiptAmt_temp == paymentAmount) { receiptTotalAmt = receiptAmt_temp; outstandingAmt = 0; } } myPOS.MTotalAmount = receiptTotalAmt; myPOS.MOutstandingAmount = outstandingAmt; } catch { MessageBox.Show("Error Occur: Other Categories, No IHP"); this.DialogResult = DialogResult.None; return; } } if (myPOS.MOutstandingAmount > 0) //if (outstandingAmt > 0) { DialogResult yes = MessageBox.Show(this, string.Format("This receipt still have outstanding amount : ${0}, do you really want to tender?", myPOS.MOutstandingAmount.ToString()), "Warning", MessageBoxButtons.YesNo); if (yes == DialogResult.No) { this.DialogResult = DialogResult.None; return; } if (myPOS.NCategoryID == 11 || myPOS.NCategoryID == 12) { MessageBox.Show(this, "Products are not allow outstanding payment anymore. Please use Deposit Function"); this.DialogResult = DialogResult.None; return; } else if (myPOS.NCategoryID == 18 || myPOS.NCategoryID == 19) { MessageBox.Show(this, "Top Ups are not allow outstanding payment."); this.DialogResult = DialogResult.None; return; } else if (myPOS.NCategoryID == 2 || myPOS.NCategoryID == 34 || myPOS.NCategoryID == 35) { MessageBox.Show(this, "Giros are not allow outstanding payment."); this.DialogResult = DialogResult.None; return; } else if (myPOS.NCategoryID == 38) { MessageBox.Show(this, "Cash Voucher are not allow outstanding payment."); this.DialogResult = DialogResult.None; return; } else if (myPOS.NCategoryID == 15) { MessageBox.Show(this, "Locker Rental are not allow outstanding payment."); this.DialogResult = DialogResult.None; return; } else if (myPOS.NCategoryID == 17) { MessageBox.Show(this, "Forget Card are not allow outstanding payment."); this.DialogResult = DialogResult.None; return; } else if (myPOS.NCategoryID == 20) { MessageBox.Show(this, "Lost Card are not allow outstanding payment."); this.DialogResult = DialogResult.None; return; } else if (myPOS.NCategoryID == 21) { MessageBox.Show(this, "Mineral Water are not allow outstanding payment."); this.DialogResult = DialogResult.None; return; } else if (myPOS.NCategoryID == 23) { MessageBox.Show(this, "Others are not allow outstanding payment."); this.DialogResult = DialogResult.None; return; } else if (myPOS.NCategoryID == 24) { MessageBox.Show(this, "Deposit are not allow outstanding payment."); this.DialogResult = DialogResult.None; return; } } else if (myPOS.MOutstandingAmount < 0) //else if (outstandingAmt < 0) // { if (myPOS.NCategoryID != 15 && myPOS.NCategoryID != 17) { MessageBox.Show(this, "Invalid Outstanding amount. This may be caused by amount been paid is more than outstand amount"); this.DialogResult = DialogResult.None; return; } } else if (myPOS.ReceiptItemsTable.Rows.Count == 0) { MessageBox.Show(this, "No items in Receipt."); this.DialogResult = DialogResult.None; return; } #region jackie // if (myPOS.MOutstandingAmount == 0)|| (!myPOS.StrFreebieCode.HasValue) //2704 if (myPOS.MOutstandingAmount == 0) //if (outstandingAmt == 0) { if (myPOS.NCategoryID == 38) { foreach (DataRow r in myPOS.ReceiptItemsTable.Rows) { string strSQL = "Select * from tblCashVoucher where fsell=1 and nstatusid<>0 and strSN='"+r["strCode"]+"' "; DataSet _ds = new DataSet(); SqlHelper.FillDataset(connection, CommandType.StoredProcedure, "UP_GETDATA", _ds, new string[] { "table" }, new SqlParameter("@strSQL", strSQL)); if (_ds.Tables["table"].Rows.Count > 0) { MessageBox.Show(this, "Cash Voucher selected ( " +r["strCode"]+ " ) already sold."); this.DialogResult = DialogResult.None; return; } } } if (myPOS.NCategoryID != 35)//23 others Extent GIRO no freebiz { if (!myPOS.StrFreebieCode.HasValue) { string strSQL = "Select distinct A.* from tblPromotion A, tblMember B, tblLoyaltyStatus C, tblPromotionBranch D, tblPromotionReceiptSalesCategory E, tblSalesCategory sc where A.FItemDiscount = 0 AND A.mMinimumAmount <= " + (myPOS.MTotalAmount.ToString() == "" ? "0" : myPOS.MTotalAmount.ToString()) + " And A.nApprovedStatusID = 1 AND ( A.nPromotionTypeID = 1 or A.nPromotionTypeID = 2) AND A.dtValidStart <= convert(varchar(10),getdate(),120) AND A.dtValidEnd >= convert(varchar(10),getdate(),120) AND ((A.nDiscountCategoryID = C.nDiscountCategoryID AND B.nLoyaltyStatusID = C.nLoyaltyStatusID) or A.nDiscountCategoryID =0) AND D.strPromotionCode = A.strPromotionCode and D.strBranchCode = '" + myPOS.StrBranchCode + "' AND E.strPromotionCode = A.strPromotionCode AND B.StrMembershipID = '" + myPOS.StrMembershipID + "' AND E.nSalesCategoryID = sc.nSalesCategoryID AND sc.nSalesCategoryID = " + myPOS.NCategoryID; DataSet _ds = new DataSet(); SqlHelper.FillDataset(connection, CommandType.StoredProcedure, "UP_GETDATA", _ds, new string[] { "table" }, new SqlParameter("@strSQL", strSQL)); if (_ds.Tables["table"].Rows.Count > 0) { DialogResult result1 = MessageBox.Show(this, "Freebie is empty. Do you want to add it now? ", "Warning",MessageBoxButtons.YesNo); if (result1 == DialogResult.Yes) { ACMSPOS2.FormAddBillFreebie frm = new ACMS.ACMSPOS2.FormAddBillFreebie(myPOS,true); frm.ShowDialog(this); } } _ds.Dispose(); } } } # endregion //myPOS.MTotalAmount = receiptTotalAmt; //myPOS.MOutstandingAmount = outstandingAmt; }
private void AddBillFreebies() { ACMSPOS2.FormAddBillFreebie frm = new ACMS.ACMSPOS2.FormAddBillFreebie(myPOS, myIsFinishLoadStockRecon); frm.ShowDialog(this); }