private void StoreDataToDatabase(DataDeduct dataDeduct, ParkingOut parkingOut) { try { // store deduct result card to server string result = dataDeduct.DeductResult; int amount = dataDeduct.Amount; string created = dataDeduct.CreatedDatetime; string bank = dataDeduct.Bank; string ipv4 = dataDeduct.IpAddress; string operatorName = dataDeduct.OperatorName; string idReader = dataDeduct.IdReader; int parkingOutId = parkingOut.ParkingOutId; string query = "INSERT INTO deduct_card_results (parking_out_id, result, amount, transaction_dt, bank, ipv4, operator, ID_reader, created) VALUES('" + parkingOutId + "', '" + result + "', '" + amount + "', '" + created + "', '" + bank + "', '" + ipv4 + "', '" + operatorName + "', '" + idReader + "', '" + created + "')"; database.Insert(query); } catch (Exception ex) { notifyIcon.ShowBalloonTip(Constant.NOTIFICATION_TRAY_TIMEOUT, "Error", ex.Message, ToolTipIcon.Error); return; } }
public CreditNoteViewModel() { try { MessageBoxCaption = "Credit Note"; TaxInvoice = false; nepDate = new DateConverter(GlobalClass.TConnectionString); PIN = new ParkingIn(); POUT = new ParkingOut(); CurDate = DateTime.Today; CurTime = DateTime.Now.ToString("hh:mm tt"); timer = new DispatcherTimer(); timer.Interval = new TimeSpan(0, 0, 1); timer.Tick += timer_Tick; timer.Start(); NewCommand = new RelayCommand(ExeucteNew); LoadData = new RelayCommand(ExecuteLoad); SaveCommand = new RelayCommand(ExecuteSave, CanExecuteSave); UndoCommand = new RelayCommand(ExecuteUndo); PrintCommand = new RelayCommand(ExecutePrint, CanExecutePrint); SetAction(ButtonAction.Init); this.PropertyChanged += CreditNoteViewModel_PropertyChanged; } catch (Exception ex) { MessageBox.Show(GlobalClass.GetRootException(ex).Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error); } }
public POutWithoutSlipVM() { try { MessageBoxCaption = "Exit Without Slip"; TaxInvoice = false; CanChangeInvoiceType = true; nepDate = new DateConverter(GlobalClass.TConnectionString); PIN = new ParkingIn(); InDate = DateTime.Today.Date; InTime = DateTime.Now; POUT = new ParkingOut(); CurDate = DateTime.Today; CurTime = DateTime.Now.ToString("hh:mm tt"); timer = new DispatcherTimer(); timer.Interval = new TimeSpan(0, 0, 1); timer.Tick += timer_Tick; timer.Start(); LoadData = new RelayCommand(ExecuteLoad); NewCommand = new RelayCommand(ExecuteNew); SaveCommand = new RelayCommand(ExecuteSave, CanExecuteSave); UndoCommand = new RelayCommand(ExecuteUndo); PrintCommand = new RelayCommand(ExecutePrint, CanExecutePrint); SetAction(ButtonAction.Init); using (SqlConnection conn = new SqlConnection(GlobalClass.TConnectionString)) { VTypeList = new ObservableCollection <VehicleType>(conn.Query <VehicleType>("SELECT VTypeID, Description FROM VehicleType")); } } catch (Exception ex) { MessageBox.Show(GlobalClass.GetRootException(ex).Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error); } }
public FunctionResponse ValidateStaffOrStamp(BarCodeTransfer barCodeTransfer) { ParkingOut POUT = barCodeTransfer.POUT; ParkingIn PIN = barCodeTransfer.PIN; try { using (SqlConnection conn = new SqlConnection(GlobalClass.DataConnectionString)) { if (POUT.STAFF_BARCODE != "STAMP") { POUT.STAFF_BARCODE = conn.ExecuteScalar <string>("SELECT BARCODE FROM tblStaff WHERE STATUS = 0 AND BCODE = '" + POUT.STAFF_BARCODE + "'"); if (string.IsNullOrEmpty(POUT.STAFF_BARCODE)) { return(new FunctionResponse() { status = "error", Message = "Invalid Barcode. Please Try Again." }); } if (GlobalClass.AllowMultiVehicleForStaff == 0) { if (conn.ExecuteScalar <int> ( string.Format ( @"SELECT COUNT(*) FROM ( SELECT INDATE + CAST(INTIME AS TIME) INTIME, OUTDATE + CAST(OUTTIME AS TIME) OUTTIME FROM ParkingInDetails PID JOIN ParkingOutDetails POD ON PID.PID =POD.PID AND PID.FYID = POD.FYID WHERE POD.STAFF_BARCODE = '{0}' ) A WHERE (INTIME < '{1}' AND OUTTIME > '{1}') OR (INTIME > '{1}' AND OUTTIME > '{1}')", POUT.STAFF_BARCODE, PIN.InDate.Add(DateTime.Parse(PIN.InTime).TimeOfDay) ) ) > 0) { return(new FunctionResponse() { status = "error", Message = "Staff already parked one vehicle during current vehile's parked period. Staff are not allowed to park multiple vehicle at a time" }); } } } } POUT.CashAmount = 0; return(ExecuteSave(barCodeTransfer)); //if (StaffBarcode != null) // StaffBarcode.Close(); } catch (Exception ex) { POUT.STAFF_BARCODE = null; return(new FunctionResponse() { status = "error", Message = ex.Message }); } }
private void btnSave_Click(object sender, EventArgs e) { string feedback = this.ValidateFields(); if (feedback == Constant.MESSAGE_OK) { // check the payment method whether it's cash or non-cash int totalFare = TKHelper.IDRToNominal(txtGrandTotal.Text.ToString()); string paymentMethod = nonCash.Checked ? "NCSH" : "CASH"; if (paymentMethod == "NCSH") { string bankCode = "BNI"; string ipv4 = TKHelper.GetLocalIPAddress(); string TIDSettlement = Properties.Settings.Default.TID; string operator_name = Properties.Settings.Default.Username; // need to disconnect SCard from WinsCard.dll beforehand in order to execute further actions to avoid 'Outstanding Connection' Exception. mifareCard.disconnect(); DataDeduct responseDeduct = bni.DeductBalance(bankCode, ipv4, TIDSettlement, operator_name); if (!responseDeduct.IsError) { string base64WebcamImage = CameraHelper.CaptureWebcamImage(camera, webcamImage); string base64LiveCameraSnapshot = CameraHelper.SnapshotLiveCamera(); if (!string.IsNullOrEmpty(base64LiveCameraSnapshot)) { ParkingOut parkingOut = SendDataToServer(totalFare, base64WebcamImage, base64LiveCameraSnapshot, paymentMethod); StoreDataToDatabase(responseDeduct, parkingOut); notifyIcon.ShowBalloonTip(Constant.NOTIFICATION_TRAY_TIMEOUT, "Success", Constant.TRANSACTION_SUCCESS, ToolTipIcon.Info); Clear(true); } } else { notifyIcon.ShowBalloonTip(Constant.NOTIFICATION_TRAY_TIMEOUT, "Error", responseDeduct.Message, ToolTipIcon.Error); } } else { string base64WebcamImage = CameraHelper.CaptureWebcamImage(camera, webcamImage); string base4LiveCameraSnapshot = CameraHelper.SnapshotLiveCamera(); if (!string.IsNullOrEmpty(base4LiveCameraSnapshot)) { ParkingOut parkingOut = SendDataToServer(totalFare, base64WebcamImage, base4LiveCameraSnapshot, paymentMethod); notifyIcon.ShowBalloonTip(Constant.NOTIFICATION_TRAY_TIMEOUT, "Success", Constant.TRANSACTION_SUCCESS, ToolTipIcon.Info); Clear(true); } } } else { notifyIcon.ShowBalloonTip(Constant.NOTIFICATION_TRAY_TIMEOUT, "Warning", feedback, ToolTipIcon.Warning); } }
void CreditNoteViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (_action == ButtonAction.New) { if (e.PropertyName == "RefBillNo" || e.PropertyName == "TaxInvoice") { PIN = new ParkingIn(); POUT = new ParkingOut(); } } }
private void ExecuteUndo(object obj) { InvoiceNo = string.Empty; RefBillNo = string.Empty; Remarks = string.Empty; TaxInvoice = false; PIN = new ParkingIn(); POUT = new ParkingOut(); SetAction(ButtonAction.Init); OnPropertyChanged("IsEntryMode"); }
public async void ExecuteFinishCommand() { try { if (PIN == null || POUT == null) { DependencyService.Get <IMessage>().ShortAlert("No Vehicle to exit"); return; } if (POUT.PID == 0 || PIN.PID == 0) { DependencyService.Get <IMessage>().ShortAlert("No vehicle entered to exit."); return; } var ans = await App.Current.MainPage.DisplayAlert("Confirm", "Are you sure to Exit Vehicle?", "Yes", "No"); if (!ans) { return; } IsLoading = true; var transferData = new BarCodeTransfer() { barcode = Barcode, Vouchers = Vouchers, mDiscount = mDiscount, PIN = PIN, POUT = POUT, Session = GlobalClass.User.Session }; var res = await ParkingDetailsConnection.SavePOUT(transferData); if (res.status == "ok") { DependencyService.Get <IMessage>().ShortAlert("Vehicle exited Successfully"); POUT = new ParkingOut(); PIN = new ParkingIn(); Vouchers = new List <Voucher>(); mDiscount = new MemberDiscount(); } else if (res.status == "error") { DependencyService.Get <IMessage>().ShortAlert(res.Message); } else { DependencyService.Get <IMessage>().ShortAlert("Error: Server Connection Problem"); } IsLoading = false; } catch (Exception ex) { IsLoading = false; DependencyService.Get <IMessage>().ShortAlert(ex.Message); } }
private void ExecuteUndo(object obj) { FocusedElement = (short)Focusable.Barcode; TaxInvoice = false; InvoiceNo = string.Empty; CanChangeInvoiceType = true; PIN = new ParkingIn(); InDate = DateTime.Today.Date; InTime = DateTime.Now; POUT = new ParkingOut(); SetAction(ButtonAction.Init); OnPropertyChanged("IsEntryMode"); PoleDisplay.WriteToDisplay(POUT.ChargedAmount, PoleDisplayType.AMOUNT); }
private void btnSave_Click(object sender, EventArgs e) { if (ValidateFields()) { string base64WebcamImage = CameraHelper.CaptureWebcamImage(camera, webcamImage); string base64LiveCameraSnapshotImage = CameraHelper.SnapshotLiveCamera(); if (!string.IsNullOrEmpty(base64LiveCameraSnapshotImage)) { ParkingOut parkingOut = SendDataToServer(base64WebcamImage, base64LiveCameraSnapshotImage); notifyIcon.ShowBalloonTip(Constant.NOTIFICATION_TRAY_TIMEOUT, "Success", Constant.TRANSACTION_SUCCESS, ToolTipIcon.Info); Clear(true); } } }
private void ExecuteSave(object obj) { try { if (!ParkingList.Any(x => x.Close)) { MessageBox.Show("No entrance is checked for closing.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (ParkingList.Any(x => x.Close && string.IsNullOrEmpty(x.Remarks))) { MessageBox.Show("Remarks must be given for closing the entrance", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } using (SqlConnection conn = new SqlConnection(GlobalClass.TConnectionString)) { conn.Open(); using (SqlTransaction tran = conn.BeginTransaction()) { foreach (var p in ParkingList.Where(x => x.Close)) { ParkingOut pout = new ParkingOut() { PID = p.PID, FYID = p.FYID, OutDate = p.InDate, OutMiti = p.InMiti, OutTime = p.InTime, SESSION_ID = GlobalClass.Session, UID = GlobalClass.User.UID, Remarks = p.Remarks, Interval = string.Empty, Rate_ID = 1 }; pout.Save(tran); } tran.Commit(); MessageBox.Show("Success", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation); ParkingList.Clear(); } } } catch (Exception ex) { MessageBox.Show(ex.GetBaseException().Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error); } }
public HomePageVM() { Test = "Test"; IsLoading = false; LoadingMessage = "Loading!! Please wait....."; Barcode = ""; LoadCommand = new Command(ExecuteLoad); FinishCommand = new Command(ExecuteFinishCommand); StampCommand = new Command(ExecuteStampCommand); StaffCommand = new Command(ExecuteStaffCommand); BackCommand = new Command(ExecuteBackCommand); ViewStaffBarcode = new Command(ExecuteViewStaffBarcode); PIN = new ParkingIn(); POUT = new ParkingOut(); ParkingDetails = new BarCodeTransfer(); Vouchers = new List <Voucher>(); mDiscount = new MemberDiscount(); StaffBarcode = ""; }
private void SaveDataLostTicket() { int totalFare = TKHelper.IDRToNominal(txtGrandTotal.Text.ToString()); string paymentMethod = cash.Checked ? "CASH" : "NCSH"; if (paymentMethod == "NCSH") { string bankCode = "BNI"; string ipv4 = TKHelper.GetLocalIPAddress(); string TIDSettlement = Properties.Settings.Default.TID; string operator_name = Properties.Settings.Default.Username; DataDeduct responseDeduct = bni.DeductBalance(bankCode, ipv4, TIDSettlement, operator_name); if (!responseDeduct.IsError) { string base64WebcamImage = CameraHelper.CaptureWebcamImage(camera, webcamImage); string base64LiveCameraSnapshotImage = CameraHelper.SnapshotLiveCamera(); if (!string.IsNullOrEmpty(base64LiveCameraSnapshotImage)) { ParkingOut parkingOut = SendDataToServer(base64WebcamImage, base64LiveCameraSnapshotImage, paymentMethod, totalFare); StoreDataToDatabase(responseDeduct, parkingOut); notifyIcon.ShowBalloonTip(Constant.NOTIFICATION_TRAY_TIMEOUT, "Success", Constant.TRANSACTION_SUCCESS, ToolTipIcon.Info); Clear(); } } else { notifyIcon.ShowBalloonTip(Constant.NOTIFICATION_TRAY_TIMEOUT, "Error", responseDeduct.Message, ToolTipIcon.Error); } } else { string base64WebcamImage = CameraHelper.CaptureWebcamImage(camera, webcamImage); string base64LiveCameraSnapshotImage = CameraHelper.SnapshotLiveCamera(); if (!string.IsNullOrEmpty(base64LiveCameraSnapshotImage)) { SendDataToServer(base64WebcamImage, base64LiveCameraSnapshotImage, paymentMethod, totalFare); notifyIcon.ShowBalloonTip(Constant.NOTIFICATION_TRAY_TIMEOUT, "Success", Constant.TRANSACTION_SUCCESS, ToolTipIcon.Info); Clear(); } } }
public async void ExecuteStaffCommand() { try { //IsStaffBarcode = false; if (string.IsNullOrEmpty(StaffBarcode)) { DependencyService.Get <IMessage>().ShortAlert("Invalid Barcode. Please Try Again"); return; } POUT.SESSION_ID = GlobalClass.User.Session; POUT.STAFF_BARCODE = StaffBarcode; var transferData = new BarCodeTransfer() { barcode = Barcode, Vouchers = Vouchers, mDiscount = mDiscount, PIN = PIN, POUT = POUT, Session = GlobalClass.User.Session }; var res = await ParkingDetailsConnection.SaveStaffOrStampPOUT(transferData); if (res.status == "ok") { IsStaffBarcode = false; DependencyService.Get <IMessage>().ShortAlert("Vehicle exited Successfully"); POUT = new ParkingOut(); PIN = new ParkingIn(); Vouchers = new List <Voucher>(); mDiscount = new MemberDiscount(); } else if (res.status == "error") { DependencyService.Get <IMessage>().ShortAlert(res.Message); } } catch (Exception ex) { DependencyService.Get <IMessage>().ShortAlert(ex.Message); } }
public FunctionResponse CheckParkingSlip(BarCodeTransfer transferData) { try { string barcode = transferData.barcode; ParkingOut POUT = new ParkingOut(); decimal ChargedHours = 0; decimal ChargedAmount = 0; using (SqlConnection conn = new SqlConnection(ConnectionDbInfo.ConnectionString)) { try { if (transferData.POUT != null && (transferData.POUT.PID) != 0) { transferData.POUT.SaveLog(conn); } } catch { } var PINS = conn.Query <ParkingIn>(@"SELECT PID, VehicleType, InDate, InMiti, InTime, PlateNo, Barcode, UID FROM ParkingInDetails WHERE((BARCODE <> '' AND BARCODE = @barcode) OR(ISNULL(PLATENO, '') <> '' AND ISNULL(PlateNo, '') = @barcode)) AND FYID = @fyid", new { barcode, fyid = GlobalClass.FYID }); if (PINS.Count() <= 0) { return(new FunctionResponse() { status = "error", Message = "Invalid barcode readings." }); } ParkingIn PIN = PINS.First(); PIN.VType = conn.Query <VehicleType>(string.Format("SELECT VTypeId, Description FROM VehicleType WHERE VTypeId = {0}", PIN.VehicleType)).First(); var POUTS = conn.Query <ParkingOut>(string.Format("SELECT * FROM ParkingOutDetails WHERE PID = {0} AND FYID = {1}", PIN.PID, GlobalClass.FYID)); if (POUTS.Count() > 0) { return(new FunctionResponse() { status = "error", Message = "Entity already exited" }); } POUT.Rate_ID = (int)conn.ExecuteScalar("SELECT RATE_ID FROM RATEMASTER WHERE IsDefault = 1"); DateTime ServerTime = conn.ExecuteScalar <DateTime>("SELECT GETDATE()"); POUT.OutDate = ServerTime.Date; POUT.OutTime = ServerTime.ToString("hh:mm:ss tt"); POUT.OutMiti = conn.ExecuteScalar <String>("SELECT MITI FROM DATEMITI WHERE AD = @AD", new { AD = ServerTime.Date }); POUT.Interval = GetInterval(PIN.InDate, POUT.OutDate, PIN.InTime, POUT.OutTime); POUT.PID = PIN.PID; CalculateParkingCharge(conn, PIN.InDate.Add(DateTime.Parse(PIN.InTime).TimeOfDay), POUT.OutDate.Add(DateTime.Parse(POUT.OutTime).TimeOfDay), POUT.Rate_ID, PIN.VehicleType, ref ChargedAmount, ref ChargedHours); POUT.ChargedHours = ChargedHours; POUT.ChargedAmount = ChargedAmount; POUT.CashAmount = POUT.ChargedAmount; PIN.Barcode = string.Empty; bool IsHoliday = conn.ExecuteScalar <int>("SELECT COUNT(*) FROM Holiday WHERE HolidayDate = @HolidayDate", new { HolidayDate = POUT.OutDate }) > 0; return(new FunctionResponse() { status = "ok", result = new BarCodeTransfer() { barcode = barcode, Vouchers = new List <Voucher>(), mDiscount = new MemberDiscount(), POUT = POUT, PIN = PIN, IsHoliday = IsHoliday } }); } } catch (Exception ex) { return(new FunctionResponse() { status = "error", Message = ex.Message }); } }
public FunctionResponse ValidateMember(BarCodeTransfer obj) { try { string barcode = obj.barcode; List <Voucher> Vouchers = obj.Vouchers; MemberDiscount mDiscount = obj.mDiscount; ParkingIn PIN = obj.PIN; ParkingOut POUT = obj.POUT; if (mDiscount != null && !string.IsNullOrEmpty(mDiscount.MemberId)) { return new FunctionResponse() { status = "error", Message = "Member already accepted." } } ; TimeSpan InTime = DateTime.Parse(PIN.InTime).TimeOfDay; TimeSpan OutTime = DateTime.Parse(POUT.OutTime).TimeOfDay; decimal DiscountAmount = 0; decimal DiscountHour = 0; int Interval; using (SqlConnection conn = new SqlConnection(GlobalClass.DataConnectionString)) { Member m = conn.Query <Member>("SELECT MemberId, MemberName, SchemeId, ExpiryDate, ActivationDate, Barcode, Address FROM Members WHERE Barcode = @MemberId ", new { MemberId = barcode.ToString() }).FirstOrDefault(); if (m == null) { return(new FunctionResponse() { status = "error", Message = "The member does not exists." }); } else if (m.ActivationDate > POUT.OutDate || m.ExpiryDate < POUT.OutDate) { return(new FunctionResponse() { status = "error", Message = "The membership is expired or not yet activated." }); } MembershipScheme scheme = conn.Query <MembershipScheme>("SELECT * FROM MembershipScheme WHERE SchemeId = @SchemeId", m).FirstOrDefault(); if (scheme == null) { return(new FunctionResponse() { status = "error", Message = "Membership scheme does not exists." }); } else if (!scheme.ValidOnWeekends && POUT.OutDate.DayOfWeek == DayOfWeek.Saturday) { return(new FunctionResponse() { status = "error", Message = "The Membership is not valid on Weekends" }); } else if (!scheme.ValidOnHolidays && conn.ExecuteScalar <int>("SELECT COUNT(*) FROM Holiday WHERE HolidayDate = @HolidayDate", new { HolidayDate = POUT.OutDate }) > 0) { return(new FunctionResponse() { status = "error", Message = "The Membership is not valid on Public Holidays" }); } List <dynamic> TimeSpentInEachSession = GetTimeSpentInEachSession(InTime, OutTime, scheme, PIN); Interval = conn.ExecuteScalar <int>("SELECT ISNULL(SUM(MDD.Interval - MDD.SkipInterval),0) Interval FROM MemberDiscountDetail MDD JOIN ParkingOutDetails POD ON MDD.PID = POD.PID WHERE MemberId = @MemberId AND POD.OutDate = @OutDate", new { MemberId = m.MemberId, OutDate = POUT.OutDate }); if (Interval >= scheme.Limit && !TimeSpentInEachSession.Any(x => x.SkipValidityPeriod && x.TimeSpent > 0)) { return(new FunctionResponse() { status = "error", Message = "Free Entrance for the Member has exceeded for day." }); } mDiscount = new MemberDiscount { MemberId = m.MemberId, SchemeId = m.SchemeId, FYID = POUT.FYID, PID = PIN.PID, }; POUT.BILLTO = m.MemberName; POUT.BILLTOADD = m.Address; if (TimeSpentInEachSession.Any(x => x.SkipValidityPeriod)) { mDiscount.SkipInterval = TimeSpentInEachSession.Where(x => x.SkipValidityPeriod).Sum(x => x.TimeSpent); } int DiscountInterval = scheme.Limit - Interval + mDiscount.SkipInterval; foreach (dynamic session in TimeSpentInEachSession.Where(x => x.TimeSpent > 0)) { if (session.IgnoreLimit) { CalculateParkingCharge(conn, session.Start, session.End, POUT.Rate_ID, PIN.VehicleType, ref DiscountAmount, ref DiscountHour); DiscountInterval -= session.TimeSpent; } else { CalculateParkingCharge(conn, session.Start, (DiscountInterval < session.TimeSpent) ? session.Start.AddMinutes(DiscountInterval) : session.End, POUT.Rate_ID, PIN.VehicleType, ref DiscountAmount, ref DiscountHour); DiscountInterval -= (DiscountInterval < session.TimeSpent) ? DiscountInterval : session.TimeSpent; } mDiscount.Interval += DiscountHour * 60; mDiscount.DiscountAmount += DiscountAmount * scheme.Discount / 100; DiscountHour = 0; DiscountAmount = 0; } POUT.CashAmount = POUT.ChargedAmount = POUT.ChargedAmount - mDiscount.DiscountAmount; obj.mDiscount = mDiscount; return(new FunctionResponse() { status = "ok", result = obj }); } //if (POUT.CashAmount == 0) // ExecuteSave(null); //PoleDisplay.WriteToDisplay(POUT.CashAmount, PoleDisplayType.AMOUNT); }catch (Exception ex) { return(new FunctionResponse() { status = "error", Message = ex.Message }); } }
public FunctionResponse ValidateVoucher(BarCodeTransfer obj) { try { string barcode = obj.barcode; List <Voucher> Vouchers = obj.Vouchers; MemberDiscount mDiscount = obj.mDiscount; ParkingIn PIN = obj.PIN; ParkingOut POUT = obj.POUT; if (Vouchers.Any(x => x.Barcode.ToUpper() == barcode.ToUpper().ToString())) { return new FunctionResponse() { status = "error", Message = "Voucher already accepted." } } ; using (SqlConnection conn = new SqlConnection(GlobalClass.DataConnectionString)) { Voucher v = conn.Query <Voucher>("SELECT VoucherNo, Barcode, VoucherId, Value, ExpDate, ValidStart, ValidEnd, ScannedTime FROM ParkingVouchers WHERE Barcode = @Barcode", new { Barcode = barcode.ToString() }).FirstOrDefault(); if (v == null) { return(new FunctionResponse() { status = "error", Message = "InValid Voucher" }); } else if (v.ScannedTime == null) { return(new FunctionResponse() { status = "error", Message = "Voucher already redeemed." }); } else if (!VoucherTypes.Any(x => x.VoucherId == v.VoucherId && x.VehicleType == PIN.VehicleType)) { return(new FunctionResponse() { status = "error", Message = "The Voucher is not valid for current Entrance Type." }); } else if (v.ExpDate < CurDate) { return(new FunctionResponse() { status = "error", Message = "Voucher has expired." }); } else { TimeSpan outTime = Convert.ToDateTime(POUT.OutTime).TimeOfDay; if (v.ValidStart < v.ValidEnd) { if (outTime < v.ValidStart || outTime > v.ValidEnd) { return(new FunctionResponse() { status = "error", Message = "Voucher is not valid for current Shift." }); } } else { if (outTime < v.ValidStart && outTime > v.ValidEnd) { return(new FunctionResponse() { status = "error", Message = "Voucher is not valid for current Shift." }); } } v.Value = (POUT.ChargedAmount > v.Value) ? v.Value : POUT.ChargedAmount; POUT.CashAmount = POUT.CashAmount - v.Value; //PIN.Barcode = string.Empty; Vouchers.Add(v); return(new FunctionResponse() { status = "ok", result = obj }); //if (POUT.CashAmount == 0) // ExecuteSave(null); //PoleDisplay.WriteToDisplay(POUT.CashAmount, PoleDisplayType.AMOUNT); } } }catch (Exception ex) { return(new FunctionResponse() { status = "error", Message = ex.Message }); } }
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 }); } }
public async void ExecuteLoad() { try { if (string.IsNullOrEmpty(Barcode)) { DependencyService.Get <IMessage>().ShortAlert("Enter Correct barcode "); return; } IsLoading = true; var res = new FunctionResponse(); if (Barcode.ToString().StartsWith("#")) { if (POUT.PID == 0) { DependencyService.Get <IMessage>().ShortAlert("Voucher cannot be accepted. No Vehicle barcode scanned."); IsLoading = false; return; } if (Vouchers.Any(x => x.Barcode.ToUpper() == Barcode.ToUpper().ToString())) { DependencyService.Get <IMessage>().ShortAlert("Voucher already Accepted."); IsLoading = false; return; } var transferData = new BarCodeTransfer() { barcode = Barcode.ToUpper(), Vouchers = Vouchers, mDiscount = mDiscount, PIN = PIN, POUT = POUT }; res = await ParkingDetailsConnection.UploadVoucherCode(transferData); if (res.status == "ok") { DependencyService.Get <IMessage>().ShortAlert("Voucher Discount applied Successfully"); } } else if (Barcode.ToUpper().ToString().StartsWith(GlobalClass.MemberBarcodePrefix)) { if (POUT.PID == 0) { DependencyService.Get <IMessage>().LongAlert("MemberCard cannot be accepted. No Vehicle barcode scanned."); IsLoading = false; return; } if (mDiscount != null && !string.IsNullOrEmpty(mDiscount.MemberId)) { DependencyService.Get <IMessage>().ShortAlert("Member already Accepted."); IsLoading = false; return; } var transferData = new BarCodeTransfer() { barcode = Barcode.ToUpper(), Vouchers = Vouchers, mDiscount = mDiscount, PIN = PIN, POUT = POUT }; res = await ParkingDetailsConnection.UploadMemberCode(transferData); if (res.status == "ok") { DependencyService.Get <IMessage>().ShortAlert("Member Discount applied successfully"); } } else { var transferData = new BarCodeTransfer() { barcode = Barcode.ToUpper(), PIN = PIN, POUT = POUT }; res = await ParkingDetailsConnection.LoadParkingOutAsync(transferData); if (res.status == "error") { PIN = new ParkingIn(); POUT = new ParkingOut(); Vouchers = new List <Voucher>(); mDiscount = new MemberDiscount(); } if (res.status == "ok") { DependencyService.Get <IMessage>().ShortAlert("Details Loaded Successfully"); } } if (res.status == "ok") { ParkingDetails = JsonConvert.DeserializeObject <BarCodeTransfer>(res.result.ToString()); if (ParkingDetails != null) { PIN = ParkingDetails.PIN; POUT = ParkingDetails.POUT; POUT.UID = GlobalClass.User.UID; POUT.SESSION_ID = GlobalClass.User.Session; Vouchers = ParkingDetails.Vouchers; mDiscount = ParkingDetails.mDiscount; Barcode = ""; } } else { DependencyService.Get <IMessage>().ShortAlert(res.Message); } IsLoading = false; }catch (Exception ex) { IsLoading = false; DependencyService.Get <IMessage>().ShortAlert(ex.Message); } }