Example #1
0
        public void QrPaymentComplete()
        {
            PaymentCommand payment = new PaymentCommand()
            {
                TotalDiscount = TotalDiscount,
                ItemList      = CurrentTicket.ToList(),
                ShiftId       = App.OpenShiftId,
                StoreEmail    = App.Email,
                Total         = TotalPrice
            };

            payment.PaymentType = Api.ViewModels.Enixer_Enumerations.EP_PaymentTypeEnum.Qr;
            ReceiptViewModel resultW = _service.AddPayment(payment);

            if (resultW != null)
            {
                PopupNavigation.PushAsync(new Error(new ErrorViewModel("Payment Completed", 3)));
                Application.Current.MainPage.Navigation.PushAsync(new ReceiptPage(this));
            }
            else
            {
                Application.Current.MainPage.DisplayAlert("Payment Error", "Payment not completed please try again.", "Ok");
            }
            PopupNavigation.PopAllAsync();
        }
        private void ChangeSeating()
        {
            if (!LockCheckPass(true, false, Types.Strings.ThisTicketIsOpenSomewhereElseItCanNotBeModified))
            {
                return;
            }

            // Create the seating selection control
            PosDialogWindow         window  = SeatingSelectionControl.CreateInDefaultWindow();
            SeatingSelectionControl control = window.DockedControl as SeatingSelectionControl;

            control.InitializeFromTicket(CurrentTicket);

            // Show the dialog
            ParentWindow.ShowShadingOverlay = true;
            window.ShowDialog(ParentWindow);

            if (!window.ClosedByUser)
            {
                // Process Results
                if (CurrentTicket != null)
                {
                    if (control.SelectedCustomer != null)
                    {
                        CurrentTicket.SetCustomerId(control.SelectedCustomer.Id);
                    }
                    CurrentTicket.SetType(control.TicketType);
                    CurrentTicket.SetSeatingId(control.SelectedSeatingId);
                    CurrentTicket.Update();
                }
            }
            ParentWindow.ShowShadingOverlay = false;
        }
Example #3
0
        async void Payment()
        {
            if (Cash < TotalPrice)
            {
                Application.Current.MainPage.DisplayAlert("Invalid Cash Amount", "Invalid cash amount, Please try again", "Ok");
                return;
            }
            Change = Cash - TotalPrice;
            PaymentCommand payment = new PaymentCommand()
            {
                TotalDiscount = TotalDiscount,
                ItemList      = CurrentTicket.ToList(),
                PaymentType   = Api.ViewModels.Enixer_Enumerations.EP_PaymentTypeEnum.Cash,
                ShiftId       = App.OpenShiftId,
                StoreEmail    = App.Email,
                Total         = TotalPrice
            };

            payment.PaymentType = Api.ViewModels.Enixer_Enumerations.EP_PaymentTypeEnum.Cash;
            ReceiptViewModel resultW = _service.AddPayment(payment);

            if (resultW != null)
            {
                await PopupNavigation.Instance.PushAsync(new ShowChange(this));

                await Application.Current.MainPage.Navigation.PushAsync(new ReceiptPage(this));
            }
            else
            {
                Application.Current.MainPage.DisplayAlert("Payment Error", "Payment not completed please try again.", "Ok");
            }
        }
        public void EnvoyerCuisine()
        {
            if (CurrentTicket != null && CurrentTicket.CarteLines.Any())
            {
                CurrentTicket.EnvoyerCuisine();
                NotifyOfPropertyChange("CmdStatus");
                NotifyOfPropertyChange("CmdColor");

                //CurrentTicket?.Refresh();
                //Tickets?.Refresh();

                NotifyOfPropertyChange("CurrentTicket");
                NotifyOfPropertyChange("Tickets");

                if (ShowTicketsVisible)
                {
                    ShowTickets();
                }
            }
        }
        public void DeleteTicket()
        {
            if (CurrentTicket != null)
            {
                CurrentTicket.Delete(false);
                Tickets.Remove(CurrentTicket);
                NotifyOfPropertyChange("Tickets");

                NotifyOfPropertyChange("CmdStatus");
                NotifyOfPropertyChange("CmdColor");
                CreateCartLines();

                MessageQueue.Enqueue("Ticket supprimer");
                NextTicket();

                if (ShowTicketsVisible)
                {
                    ShowTickets();
                }
            }
        }
        void SetTotalDiscount()
        {
            DiscountModel currentDiscount = new DiscountModel();

            if (TotalDiscount1)
            {
                currentDiscount = new DiscountModel {
                    DiscountName = Discounts[0].DiscountName, Amount = Discounts[0].Amount, IsPercentage = Discounts[0].IsPercentage
                }
            }
            ;
            else if (TotalDiscount2)
            {
                currentDiscount = new DiscountModel {
                    DiscountName = Discounts[1].DiscountName, Amount = Discounts[1].Amount, IsPercentage = Discounts[1].IsPercentage
                }
            }
            ;
            else if (TotalDiscount3)
            {
                currentDiscount = new DiscountModel {
                    DiscountName = Discounts[2].DiscountName, Amount = Discounts[2].Amount, IsPercentage = Discounts[2].IsPercentage
                }
            }
            ;
            else if (TotalDiscount4)
            {
                currentDiscount = new DiscountModel {
                    DiscountName = Discounts[3].DiscountName, Amount = Discounts[3].Amount, IsPercentage = Discounts[3].IsPercentage
                }
            }
            ;
            CurrentTotalDiscount = currentDiscount;
        }

        void OpenOption(ItemModel item)
        {
            CurrentItem   = item;
            CurrentOption = new List <string>();
            OptionList    = new List <ItemOptionModel>();

            if (!string.IsNullOrEmpty(item.Option1))
            {
                OptionList.Add(new ItemOptionModel()
                {
                    OptionName = item.Option1, Price = item.Option1Price
                });
            }

            if (!string.IsNullOrEmpty(item.Option2))
            {
                OptionList.Add(new ItemOptionModel()
                {
                    OptionName = item.Option2, Price = item.Option2Price
                });
            }

            if (!string.IsNullOrEmpty(item.Option3))
            {
                OptionList.Add(new ItemOptionModel()
                {
                    OptionName = item.Option3, Price = item.Option3Price
                });
            }

            if (!string.IsNullOrEmpty(item.Option4))
            {
                OptionList.Add(new ItemOptionModel()
                {
                    OptionName = item.Option4, Price = item.Option4Price
                });
            }

            foreach (var option in OptionList)
            {
                CurrentOption.Add(option.OptionName + "  ( +" + option.Price.ToString("#,0.00") + " )");
            }

            CurrentItemPrice = item.Price;

            if (item.Option2 == null && item.Option3 == null && item.Option4 == null)
            {
                if (!string.IsNullOrEmpty(item.Option1))
                {
                    OptionList.Add(new ItemOptionModel()
                    {
                        OptionName = item.Option1, Price = item.Option1Price
                    });
                }
                CurrentSelectedOptionIndex = 0;
                CurrentItemPrice           = item.Price;
                SaveItemToTicket();
            }
            else
            {
                PopupNavigation.PushAsync(new ItemPopup(this));
            }
        }

        void SetItemMenu()
        {
            if (App.ListCategoryModels == null)
            {
                var getCate = _service.GetAllCategories();

                if (!getCate.Result.IsError)
                {
                    CategoriesList         = getCate.Result.Categories;
                    App.ListCategoryModels = CategoriesList;
                }
            }
            else
            {
                CategoriesList = App.ListCategoryModels;
            }
            if (CategoriesList == null)
            {
                CategoriesList = new List <CategoryModel>();

                foreach (var category in CategoriesList)
                {
                    AllMenu.Add(new MenuModel()
                    {
                        CategoryName = category.Name,
                        Items        = new ObservableCollection <ItemModel>()
                    });
                }
            }
            ItemsViewModel items;

            if (App.ItemsManuViewModel == null || App.ItemsManuViewModel.Items.Count == 0)
            {
                items = _service.GetItems();
                App.ItemsManuViewModel = items;
            }
            else
            {
                items = App.ItemsManuViewModel;
            }
            if (items.Items == null || items.Items.Count == 0)
            {
                //Application.Current.MainPage.DisplayAlert("", "ไม่พบรายการอาหารในระบบ", "OK");
                //PopupNavigation.PushAsync(new Error(new ErrorViewModel("ไม่พบรายการอาหารในระบบ")));
                return;
            }

            foreach (var item in items.Items)
            {
                var isCatExist = AllMenu.Where(a => a.CategoryName == item.CategoryName).FirstOrDefault();
                if (isCatExist == null)
                {
                    AllMenu.Add(new MenuModel()
                    {
                        CategoryName = item.CategoryName,
                        Items        = new ObservableCollection <ItemModel>()
                    });;
                }
                if (item.Color == null)
                {
                    item.Color = "DDDDDD";
                }
                AllMenu.Where(a => a.CategoryName == item.CategoryName).FirstOrDefault().Items.Add(item);
            }
        }

        void SaveTicket()
        {
            var maxNumber = 0;

            try
            {
                maxNumber = App.TicketList.Max(t => t.TicketNumber);
            }
            catch (Exception e)
            {
            }
            ReceiptViewModel receipt = new ReceiptViewModel()
            {
                ItemList       = CurrentTicket.ToList(),
                Total          = TotalPrice,
                TicketNumber   = maxNumber + 1,
                CreateDateTime = DateTime.Now,
            };

            App.TicketList.Add(receipt);
            ClearTicket();
        }

        void OpenTicketList()
        {
            ClearTicket();
            PopupNavigation.PushAsync(new OpenTicketsPopup(this));
            TicketList = App.TicketList;
        }

        void ClearTicket()
        {
            CurrentTicket         = new ObservableCollection <OrderItemModel>();
            Quantity              = 1;
            QuantityChangeCommand = new Command <string>((change) => QuantityChange(change));
            SaveItemCommand       = new Command(SaveItemToTicket);
            CurrentTicket         = new ObservableCollection <OrderItemModel>();
            CurrentTotalDiscount  = new DiscountModel();
            CurrentDiscountAmount = 0;
            TotalPrice            = 0;
            ShowOpenButton        = true;
        }

        void OpenTicket(int ticketNumber)
        {
            var ticket = App.TicketList.Where(t => t.TicketNumber == ticketNumber).FirstOrDefault();

            if (ticket.ItemList == null || ticket.ItemList.Count == 0)
            {
                return;
            }
            foreach (var item in ticket.ItemList)
            {
                CurrentTicket.Add(item);
                TotalPrice += item.DiscountedPrice;
            }
            App.TicketList.Remove(ticket);
            PopupNavigation.PopAllAsync();
        }

        void Charge()
        {
            if (CurrentTicket == null || CurrentTicket.Count == 0)
            {
                PopupNavigation.PushAsync(new Error(new ErrorViewModel("Please add item to ticket before proceeding")));
                return;
            }
            decimal totalDiscount = 0;

            foreach (var item in CurrentTicket)
            {
                totalDiscount += item.ItemDiscount;
            }
            ReceiptViewModel receipt = new ReceiptViewModel()
            {
                ItemList       = CurrentTicket.ToList(),
                Total          = TotalPrice,
                CreateDateTime = DateTime.Now,
                TotalDiscount  = totalDiscount + CurrentDiscountAmount,
                Discount       = CurrentDiscountAmount,
            };

            Application.Current.MainPage.Navigation.PushAsync(new ChargePage(receipt));
        }

        void GetDiscount()
        {
            var discountVM = _service.GetDiscounts();

            Discounts = discountVM.Discounts;
            if (Discounts.Count > 0)
            {
                DiscountName1 = Discounts[0].DiscountName;
                HasDiscount1  = true;
                Discount1     = false;
            }

            if (Discounts.Count > 1)
            {
                DiscountName2 = Discounts[1].DiscountName;
                HasDiscount2  = true;
                Discount2     = false;
            }

            if (Discounts.Count > 2)
            {
                DiscountName3 = Discounts[2].DiscountName;
                HasDiscount3  = true;
                Discount3     = false;
            }

            if (Discounts.Count > 3)
            {
                DiscountName4 = Discounts[3].DiscountName;
                HasDiscount4  = true;
                Discount4     = false;
            }
        }

        void DeleteItem(OrderItemModel model)
        {
            CurrentTicket.Remove(model);
            CalculateTotalAmount();
        }

        void CloudsyncClick()
        {
            IsLoadding = true;
            var getCate = _service.GetAllCategories();

            if (!getCate.Result.IsError)
            {
                CategoriesList         = getCate.Result.Categories;
                App.ListCategoryModels = CategoriesList;
            }


            var items = _service.GetItems();


            if (items.Items == null || items.Items.Count == 0)
            {
                //Application.Current.MainPage.DisplayAlert("", "ไม่พบรายการอาหารในระบบ", "OK");
                //PopupNavigation.PushAsync(new Error(new ErrorViewModel("ไม่พบรายการอาหารในระบบ")));
                return;
            }
            App.ItemsManuViewModel       = items;
            Application.Current.MainPage = new NavigationPage(new Views.SaleView());
        }
        public void SaveItemToTicket()
        {
            ShowOpenButton = false;
            try
            {
                decimal       optionPrice     = OptionList[CurrentSelectedOptionIndex].Price;
                bool          isDiscount      = true;
                DiscountModel currentDiscount = new DiscountModel();
                if (Discount1)
                {
                    currentDiscount = new DiscountModel {
                        DiscountName = Discounts[0].DiscountName, Amount = Discounts[0].Amount, IsPercentage = Discounts[0].IsPercentage
                    }
                }
                ;
                else if (Discount2)
                {
                    currentDiscount = new DiscountModel {
                        DiscountName = Discounts[1].DiscountName, Amount = Discounts[1].Amount, IsPercentage = Discounts[1].IsPercentage
                    }
                }
                ;
                else if (Discount3)
                {
                    currentDiscount = new DiscountModel {
                        DiscountName = Discounts[2].DiscountName, Amount = Discounts[2].Amount, IsPercentage = Discounts[2].IsPercentage
                    }
                }
                ;
                else if (Discount4)
                {
                    currentDiscount = new DiscountModel {
                        DiscountName = Discounts[3].DiscountName, Amount = Discounts[3].Amount, IsPercentage = Discounts[3].IsPercentage
                    }
                }
                ;
                else
                {
                    isDiscount = false;
                }
                decimal discountedAmount = (currentDiscount.IsPercentage) ?
                                           (currentDiscount.Amount / 100 * (CurrentItem.Price + optionPrice) * Quantity)
                    : ((currentDiscount.Amount < (CurrentItem.Price + optionPrice) * Quantity) ? currentDiscount.Amount : (CurrentItem.Price + optionPrice) * Quantity);

                CurrentTicket.Add(new OrderItemModel
                {
                    ItemName             = CurrentItem.Name,
                    IsDiscounted         = isDiscount,
                    ItemPrice            = (CurrentItem.Price + optionPrice) * Quantity,
                    Quantity             = Quantity,
                    OptionName           = OptionList[CurrentSelectedOptionIndex].OptionName,
                    OptionPrice          = OptionList[CurrentSelectedOptionIndex].Price,
                    DiscountName         = CurrentTotalDiscount.DiscountName,
                    DiscountedPrice      = (CurrentItem.Price + optionPrice) * Quantity - discountedAmount,
                    IsDiscountPercentage = currentDiscount.IsPercentage,
                    ItemDiscount         = currentDiscount.Amount
                });

                CalculateTotalAmount();

                Discount1 = false;
                Discount2 = false;
                Discount3 = false;
                Discount4 = false;
            }
            catch (Exception e)
            {
                Application.Current.MainPage.DisplayAlert("Error", "Cannot add item to ticket", "Ok");
            }

            CurrentTicket = CurrentTicket;
            if (PopupNavigation.Instance.PopupStack.Any())
            {
                PopupNavigation.PopAllAsync();
            }
            CurrentItem   = new ItemModel();
            CurrentOption = new List <string>();
            CurrentSelectedOptionIndex = 0;
            Quantity = 1;
        }
        public void OpenPaiementDialog()
        {
            try
            {
                var Client = PosSettings.getInstance().DefaultClient.GetObject("Client");
                var paye   = new PayeTicketViewModel(CurrentTicket, Client);
                //var view = DataHelpers.container.Get<ViewManager>().CreateAndBindViewForModelIfNecessary(paye);
                var doDelete = DataHelpers.windowManager.ShowDialog(paye);



                if (doDelete == true)
                {
                    CurrentTicket.isHandled = 1;
                    CurrentTicket.Save();
                    var index = Tickets.IndexOf(CurrentTicket); // * * * *
                    Tickets.Remove(CurrentTicket);              //  * * |*| *

                    if (Tickets.Count > index)                  // 3
                    {
                        CurrentTicket = Tickets[index];
                    }
                    else if (Tickets.Count > 0)
                    {
                        CurrentTicket = Tickets[--index];
                    }
                    else
                    {
                        CurrentTicket = null;
                    }



                    // Automatic create new ticket
                    if (!Tickets.Any())
                    {
                        var ticket = new PosTicket()
                        {
                            Date       = DateTime.Now,
                            ticketType = TicketType.PREPAYE,
                            Numero     = SesssionIndex++
                        };
                        Tickets.Add(ticket);
                        CurrentTicket = ticket;
                    }

                    NotifyOfPropertyChange("Tickets");
                    NotifyOfPropertyChange("CurrentTicket");
                    //CurrentTicket?.Refresh();
                    //Tickets?.Refresh();
                    CreateCartLines();
                    MessageQueue.Enqueue("Vente terminé");
                }
                //else if (paye.MontantRecu < CurrentTicket.Total)
                //{
                //    CurrentTicket.MontantPaye += paye.MontantRecu;
                //    MessageQueue.Enqueue("PAIEMENT PARTIEL ENREGISTRÉ");

                //}

                CreateCartLines();
                if (ShowTicketsVisible)
                {
                    ShowTickets();
                }
            }
            catch (Exception s)
            {
                MessageBox.Show(s.Message);
            }
        }
Example #9
0
        async void Payment(string paymentType)
        {
            PaymentCommand payment = new PaymentCommand()
            {
                TotalDiscount = TotalDiscount,
                ItemList      = CurrentTicket.ToList(),
                ShiftId       = App.OpenShiftId,
                StoreEmail    = App.Email,
                Total         = TotalPrice
            };

            switch (paymentType)
            {
            case "Debit":
                payment.PaymentType = Api.ViewModels.Enixer_Enumerations.EP_PaymentTypeEnum.Debit;
                ReceiptViewModel result = _service.AddPayment(payment);
                if (result != null)
                {
                    PopupNavigation.PushAsync(new Error(new ErrorViewModel("Payment Completed", 3)));
                    Application.Current.MainPage.Navigation.PushAsync(new ReceiptPage(this));
                }
                else
                {
                    Application.Current.MainPage.DisplayAlert("Payment Error", "Payment not completed please try again.", "Ok");
                }
                return;

            case "Credit":
                payment.PaymentType = Api.ViewModels.Enixer_Enumerations.EP_PaymentTypeEnum.Credit;
                ReceiptViewModel resultC = _service.AddPayment(payment);

                if (resultC != null)
                {
                    PopupNavigation.PushAsync(new Error(new ErrorViewModel("Payment Completed", 3)));
                    Application.Current.MainPage.Navigation.PushAsync(new ReceiptPage(this));
                }
                else
                {
                    Application.Current.MainPage.DisplayAlert("Payment Error", "Payment not completed please try again.", "Ok");
                }
                break;

            case "Wallet":
                Int32 unixTimestamp        = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                GeneratePaymentModel model = new GeneratePaymentModel()
                {
                    Amount               = TotalPrice,
                    AccountNumber        = App.AccountNumber,
                    FirstName            = App.StoreName,
                    TransactionReference = unixTimestamp.ToString() + App.User,
                };
                QrValue = JsonConvert.SerializeObject(model);
                await PopupNavigation.PushAsync(new QrPage(this));

                await Task.Delay(2000);

                PollCode(unixTimestamp.ToString() + App.User);
                break;

            default:
                break;
            }
        }