public FunctionResponse ExecuteSave(BarCodeTransfer obj) { int Session = obj.Session; List <Voucher> Vouchers = obj.Vouchers; string barcode = obj.barcode; MemberDiscount mDiscount = obj.mDiscount; ParkingOut POUT = obj.POUT; GlobalClass.GetUser(POUT.UID); string strSQL; decimal Taxable, VAT, Amount, Discount = 0, NonTaxable, Rate, Quantity; string BillNo = string.Empty; try { using (SqlConnection conn = new SqlConnection(ConnectionDbInfo.ConnectionString)) { conn.Open(); using (SqlTransaction tran = conn.BeginTransaction()) { POUT.SESSION_ID = Session; POUT.FYID = GlobalClass.FYID; POUT.Save(tran); if (POUT.CashAmount > 0) { BillNo = InvoicePrefix + GlobalClass.GetInvoiceNo(InvoicePrefix, tran); Quantity = POUT.ChargedHours; if (Vouchers.Count > 0) { Discount = Vouchers.Sum(x => x.Value); } else if (mDiscount != null && !string.IsNullOrEmpty(mDiscount.MemberId)) { Discount = mDiscount.DiscountAmount; } else if (POUT.CashAmount < POUT.ChargedAmount) { Discount = POUT.ChargedAmount - POUT.CashAmount; } Amount = POUT.ChargedAmount / (1 + (GlobalClass.VAT / 100)); Discount = Discount / (1 + (GlobalClass.VAT / 100)); Rate = Amount / Quantity; NonTaxable = 0; Taxable = Amount - (NonTaxable + Discount); VAT = Taxable * GlobalClass.VAT / 100; TParkingSales PSales = new TParkingSales { BillNo = BillNo, TDate = POUT.OutDate, TMiti = POUT.OutMiti, TTime = POUT.OutTime, BillTo = POUT.BILLTO, BILLTOADD = POUT.BILLTOADD, BILLTOPAN = POUT.BILLTOPAN, Amount = Amount, Discount = Discount, NonTaxable = NonTaxable, Taxable = Taxable, VAT = VAT, GrossAmount = POUT.CashAmount, PID = POUT.PID, UID = POUT.UID, SESSION_ID = POUT.SESSION_ID, FYID = GlobalClass.FYID, TaxInvoice = TaxInvoice }; PSales.Save(tran); TParkingSalesDetails PSalesDetails = new TParkingSalesDetails { BillNo = BillNo, PType = 'P', Description = "Parking Charge", FYID = GlobalClass.FYID, Quantity = Quantity, Rate = Rate, Amount = Amount, Discount = Discount, NonTaxable = NonTaxable, Taxable = Taxable, VAT = VAT, NetAmount = POUT.CashAmount, }; PSalesDetails.Save(tran); conn.Execute("UPDATE tblSequence SET CurNo = CurNo + 1 WHERE VNAME = @VNAME AND FYID = @FYID", new { VNAME = InvoicePrefix, FYID = GlobalClass.FYID }, transaction: tran); GlobalClass.SetUserActivityLog(tran, "Exit", "New", VCRHNO: BillNo, WorkDetail: "Bill No : " + BillNo); //SyncFunctions.LogSyncStatus(tran, BillNo, GlobalClass.FYNAME); } if (Vouchers.Count > 0) { strSQL = "INSERT INTO VoucherDiscountDetail (BillNo, FYID, VoucherNo, DiscountAmount, UID) VALUES (@BillNo, @FYID, @VoucherNo, @DiscountAmount, @UID)"; foreach (Voucher v in Vouchers) { conn.Execute(strSQL, new { BillNo = string.IsNullOrEmpty(BillNo) ? "CS1" : BillNo, FYID = GlobalClass.FYID, VoucherNo = v.VoucherNo, DiscountAmount = v.Value, UID = POUT.UID }, transaction: tran); conn.Execute("UPDATE ParkingVouchers SET ScannedTime = GETDATE() WHERE VoucherNo = @VoucherNo", v, tran); } } else if (mDiscount != null && !string.IsNullOrEmpty(mDiscount.MemberId)) { mDiscount.BillNo = string.IsNullOrEmpty(BillNo) ? "MS1" : BillNo; mDiscount.Save(tran); } tran.Commit(); //if (!string.IsNullOrEmpty(SyncFunctions.username) && POUT.CashAmount > 0) //{ // SyncFunctions.SyncSalesData(SyncFunctions.getBillObject(BillNo), 1); //} } //if (!string.IsNullOrEmpty(BillNo)) //{ // RawPrinterHelper.SendStringToPrinter(GlobalClass.PrinterName, ((char)27).ToString() + ((char)112).ToString() + ((char)0).ToString() + ((char)64).ToString() + ((char)240).ToString(), "Receipt"); //Open Cash Drawer // PrintBill(BillNo.ToString(), conn, (TaxInvoice) ? "TAX INVOICE" : "ABBREVIATED TAX INVOCE"); // if (TaxInvoice) // { // PrintBill(BillNo.ToString(), conn, "INVOICE"); // } //} return(new FunctionResponse() { status = "ok", Message = "Saved Successfully" }); } } catch (Exception ex) { return(new FunctionResponse() { status = "error", Message = ex.Message }); } }
private void ExecuteSave(object obj) { string strSQL; decimal Taxable, VAT, Amount, Discount, NonTaxable, Rate, Quantity; string BillNo = string.Empty; try { using (SqlConnection conn = new SqlConnection(GlobalClass.TConnectionString)) { conn.Open(); using (SqlTransaction tran = conn.BeginTransaction()) { //PIN.PID = conn.ExecuteScalar<int>("SELECT CurNo FROM tblSequence WHERE VNAME = 'PID' AND FYID = " + GlobalClass.FYID, transaction: tran); PIN.PID = Convert.ToInt32(GetInvoiceNo("PID", tran)); PIN.Barcode = string.Empty; PIN.Save(tran); POUT.PID = PIN.PID; POUT.Save(tran); if (POUT.CashAmount > 0) { BillNo = InvoicePrefix + GetInvoiceNo(InvoicePrefix, tran); Quantity = POUT.ChargedHours; Amount = POUT.CashAmount / (1 + (GlobalClass.VAT / 100)); Rate = Amount / Quantity; Discount = 0; NonTaxable = 0; Taxable = Amount - (NonTaxable + Discount); VAT = Taxable * GlobalClass.VAT / 100; TParkingSales PSales = new TParkingSales { BillNo = BillNo, TDate = POUT.OutDate, TMiti = POUT.OutMiti, TTime = POUT.OutTime, BillTo = POUT.BILLTO, BILLTOADD = POUT.BILLTOADD, BILLTOPAN = POUT.BILLTOPAN, Amount = Amount, Discount = Discount, NonTaxable = NonTaxable, Taxable = Taxable, VAT = VAT, GrossAmount = POUT.CashAmount, PID = POUT.PID, UID = POUT.UID, SESSION_ID = POUT.SESSION_ID, FYID = GlobalClass.FYID, TaxInvoice = TaxInvoice }; PSales.Save(tran); TParkingSalesDetails PSalesDetails = new TParkingSalesDetails { BillNo = BillNo, FYID = GlobalClass.FYID, Quantity = Quantity, Rate = Rate, Amount = Amount, Discount = Discount, NonTaxable = NonTaxable, Taxable = Taxable, VAT = VAT, NetAmount = POUT.CashAmount, ProdId = 0, Description = "Parking Charge", PType = 'P' }; PSalesDetails.Save(tran); conn.Execute("UPDATE tblSequence SET CurNo = CurNo + 1 WHERE VNAME = 'PID' AND FYID = " + GlobalClass.FYID, transaction: tran); conn.Execute("UPDATE tblSequence SET CurNo = CurNo + 1 WHERE VNAME = @VNAME AND FYID = @FYID", new { VNAME = InvoicePrefix, FYID = GlobalClass.FYID }, transaction: tran); GlobalClass.SetUserActivityLog("Exit", "New", VCRHNO: BillNo, WorkDetail: "PID : " + PIN.PID); SyncFunctions.LogSyncStatus(tran, BillNo, GlobalClass.FYNAME); } tran.Commit(); if (!string.IsNullOrEmpty(SyncFunctions.username)) { SyncFunctions.SyncSalesData(SyncFunctions.getBillObject(BillNo), 1); } } if (!string.IsNullOrEmpty(BillNo)) { if (!GlobalClass.NoRawPrinter) { RawPrinterHelper.SendStringToPrinter(GlobalClass.PrinterName, ((char)27).ToString() + ((char)112).ToString() + ((char)0).ToString() + ((char)64).ToString() + ((char)240).ToString(), "Receipt"); //Open Cash Drawer } POutVMTouch.PrintBill(BillNo.ToString(), conn, (TaxInvoice) ? "TAX INVOICE" : "ABBREVIATED TAX INVOCE"); if (TaxInvoice) { POutVMTouch.PrintBill(BillNo.ToString(), conn, "INVOICE"); } } ExecuteUndo(null); } } catch (Exception ex) { MessageBox.Show(ex.Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error); } }