Beispiel #1
0
        public void UpdateTicketPayment(PaymentType paymentType, ChangePaymentType changeTemplate, decimal paymentDueAmount, decimal paidAmount, decimal tenderedAmount)
        {
            var paymentAccount = paymentType.Account ?? _ticketService.GetAccountForPayment(SelectedTicket, paymentType);

            if (paymentDueAmount > SelectedTicket.GetRemainingAmount() && paidAmount > SelectedTicket.GetRemainingAmount())
            {
                var account = _accountBalances.GetActiveAccount();
                if (account != null)
                {
                    var ticketAmount = SelectedTicket.GetRemainingAmount();
                    var accountAmount = paidAmount - ticketAmount;
                    var accountBalance = _accountBalances.GetAccountBalance(account.Id);
                    if (accountAmount > accountBalance) accountAmount = accountBalance;
                    if (ticketAmount > 0)
                        _ticketService.AddPayment(SelectedTicket, paymentType, paymentAccount, ticketAmount, tenderedAmount - accountAmount);
                    if (accountAmount > 0)
                        _ticketService.AddAccountTransaction(SelectedTicket, account, paymentAccount, accountAmount, ExchangeRate);
                }
                _accountBalances.Refresh();
            }
            else
            {
                _ticketService.AddPayment(SelectedTicket, paymentType, paymentAccount, paidAmount, tenderedAmount);
                if (paidAmount > paymentDueAmount && changeTemplate != null)
                {
                    _ticketService.AddChangePayment(SelectedTicket, changeTemplate, changeTemplate.Account,
                                                    paidAmount - paymentDueAmount);
                }
            }
        }
 private bool CanMakePayment(PaymentType arg)
 {
     if (arg == null) return false;
     if (_paymentEditor.AccountMode && _tenderedValueViewModel.GetTenderedValue() > _tenderedValueViewModel.GetPaymentDueValue()) return false;
     if (_paymentEditor.AccountMode && arg.Account == null) return false;
     return _paymentEditor.SelectedTicket != null
         && !_paymentEditor.SelectedTicket.IsClosed
         && _tenderedValueViewModel.GetTenderedValue() != 0
         && _paymentEditor.GetRemainingAmount() != 0
         && (arg.Account != null || _paymentEditor.SelectedTicket.TicketEntities.Any(x =>
             _ticketService.CanMakeAccountTransaction(x, arg.AccountTransactionType, _accountBalances.GetAccountBalance(x.AccountId) + _tenderedValueViewModel.GetTenderedValue())));
 }
        public void Display(IList<ChangePaymentType> changeTemplates, decimal tenderedAmount, decimal paymentDueAmount, PaymentType paymentType, ICaptionCommand selectChangePaymentTypeCommand)
        {
            ChangeTemplates.Clear();
            ChangeTemplates.AddRange(changeTemplates.Select(x => new CommandButtonViewModel<PaymentData>
            {
                Caption = GetChangeAmountCaption(paymentDueAmount, tenderedAmount, x),
                Parameter = new PaymentData
                {
                    ChangePaymentType = x,
                    PaymentDueAmount = paymentDueAmount,
                    TenderedAmount = tenderedAmount,
                    PaymentType = paymentType
                },
                Command = selectChangePaymentTypeCommand
            }));

            this.PublishEvent(EventTopicNames.Activate);
        }
Beispiel #4
0
 public static void PaySelectedTicket(PaymentType paymentType)
 {
     AddPaymentToSelectedTicket(AppServices.MainDataContext.SelectedTicket.GetRemainingAmount(), paymentType);
 }
        private void ProcessPayment(PaymentType paymentType)
        {
            var tenderedAmount = GetTenderedValue();
            var originalTenderedAmount = tenderedAmount;
            var remainingTicketAmount = GetPaymentValue();
            var returningAmount = 0m;
            if (tenderedAmount == 0) tenderedAmount = remainingTicketAmount;

            if (tenderedAmount > remainingTicketAmount)
            {
                returningAmount = tenderedAmount - remainingTicketAmount;
                tenderedAmount = remainingTicketAmount;
            }

            if (tenderedAmount > 0)
            {
                if (tenderedAmount > AppServices.MainDataContext.SelectedTicket.GetRemainingAmount())
                    tenderedAmount = AppServices.MainDataContext.SelectedTicket.GetRemainingAmount();

                TicketViewModel.AddPaymentToSelectedTicket(tenderedAmount, paymentType);

                PaymentAmount = (GetPaymentValue() - tenderedAmount).ToString("#,#0.00");

                LastTenderedAmount = tenderedAmount <= AppServices.MainDataContext.SelectedTicket.GetRemainingAmount()
                    ? tenderedAmount.ToString("#,#0.00")
                    : AppServices.MainDataContext.SelectedTicket.GetRemainingAmount().ToString("#,#0.00");
            }

            ReturningAmount = string.Format(Resources.ChangeAmount_f, returningAmount.ToString(LocalSettings.DefaultCurrencyFormat));
            ReturningAmountVisibility = returningAmount > 0 ? Visibility.Visible : Visibility.Collapsed;

            if (returningAmount > 0)
            {
                RuleExecutor.NotifyEvent(RuleEventNames.ChangeAmountChanged,
                    new { Ticket = SelectedTicket.Model, TicketAmount = SelectedTicket.Model.TotalAmount, ChangeAmount = returningAmount, TenderedAmount = originalTenderedAmount });
            }

            if (returningAmount == 0 && AppServices.MainDataContext.SelectedTicket.GetRemainingAmount() == 0)
            {
                ClosePaymentScreen();
            }
            else PersistMergedItems();
        }
 private bool CanMakeAccountTransaction(TicketResource ticketResource, PaymentType paymentType)
 {
     if (ticketResource.AccountId == 0) return false;
     var resourceType = _cacheService.GetResourceTypeById(ticketResource.ResourceTypeId);
     if (resourceType.AccountTypeId != paymentType.AccountTransactionType.TargetAccountTypeId) return false;
     return true;
 }
Beispiel #7
0
        public static void AddPaymentToSelectedTicket(decimal amount, PaymentType paymentType)
        {
            var ticket = AppServices.MainDataContext.SelectedTicket;

            var departmentId = AppServices.CurrentTerminal.DepartmentId > 0
               ? AppServices.MainDataContext.SelectedDepartment.Id
               : ticket.DepartmentId;
            ticket.AddPayment(DateTime.Now, amount, paymentType, AppServices.CurrentLoggedInUser.Id, departmentId);
            string paymentName = Resources.Cash;
            if (paymentType == PaymentType.CreditCard) paymentName = Resources.CreditCard;
            if (paymentType == PaymentType.Ticket) paymentName = Resources.Voucher;

            RuleExecutor.NotifyEvent(RuleEventNames.PaymentReceived,
                new { Ticket = ticket, PaymentType = paymentName, Amount = amount, TicketTag = ticket.Tag, ticket.CustomerId, ticket.CustomerName, ticket.CustomerGroupCode, SelectedLinesCount = ticket.GetPaidItems().Count() });
        }
        private void SubmitPaymentAmount(PaymentType paymentType, ChangePaymentType changeTemplate, decimal paymentDueAmount, decimal tenderedAmount)
        {
            var returningAmount = _returningAmountViewModel.GetReturningAmount(tenderedAmount, paymentDueAmount, changeTemplate);

            if (changeTemplate == null) tenderedAmount -= returningAmount;
            _orderSelectorViewModel.UpdateSelectedTicketPaidItems();
            _paymentEditor.UpdateTicketPayment(paymentType, changeTemplate, paymentDueAmount, tenderedAmount);
            _numberPadViewModel.LastTenderedAmount = (tenderedAmount / _paymentEditor.ExchangeRate).ToString(LocalSettings.DefaultCurrencyFormat);
            _tenderedValueViewModel.UpdatePaymentAmount(_paymentEditor.GetRemainingAmount());

            if (returningAmount == 0 && _paymentEditor.GetRemainingAmount() == 0)
            {
                OnClosePaymentScreen("");
            }
            else
            {
                if (returningAmount > 0)
                {
                    _returningAmountViewModel.PublishEvent(EventTopicNames.Activate);
                }
                _orderSelectorViewModel.PersistSelectedItems();
                _numberPadViewModel.ResetValues();
                RaisePropertyChanged(() => SelectedTicketTitle);
            }
        }
        private void SubmitPaymentAmount(PaymentType paymentType, ChangePaymentType changeTemplate, decimal paymentDueAmount, decimal tenderedAmount)
        {
            _applicationStateSetter.SetLastPaidItems(OrderSelector.GetSelectedItems());

            var returningAmount = DisplayReturningAmount(tenderedAmount, paymentDueAmount, changeTemplate);
            if (changeTemplate == null) tenderedAmount -= returningAmount;

            var paymentAccount = paymentType.Account ?? GetAccountForTransaction(paymentType, SelectedTicket.TicketResources);

            _ticketService.AddPayment(SelectedTicket, paymentType, paymentAccount, tenderedAmount);

            if (tenderedAmount > paymentDueAmount && changeTemplate != null)
            {
                _ticketService.AddChangePayment(SelectedTicket, changeTemplate, changeTemplate.Account, tenderedAmount - paymentDueAmount);
            }

            NumberPadViewModel.LastTenderedAmount = (tenderedAmount / ExchangeRate).ToString("#,#0.00");

            UpdatePaymentAmount(GetRemainingAmount());

            if (returningAmount == 0 && GetRemainingAmount() == 0)
            {
                ClosePaymentScreen();
            }
            else
            {
                OrderSelector.PersistSelectedItems();
                RefreshValues();
            }
        }
Beispiel #10
0
 public Account GetAccountForPayment(Ticket ticket, PaymentType paymentType)
 {
     var rt = _cacheService.GetEntityTypes().Where(
         x => x.AccountTypeId == paymentType.AccountTransactionType.TargetAccountTypeId).Select(x => x.Id);
     var tr = ticket.TicketEntities.FirstOrDefault(x => rt.Contains(x.EntityTypeId));
     return tr != null ? _accountService.GetAccountById(tr.AccountId) : null;
 }
 private void OnMakePayment(PaymentType obj)
 {
     SubmitPayment(obj);
 }
Beispiel #12
0
 public void AddExpense(int customerId, decimal amount, string description, PaymentType paymentType)
 {
     AddTransaction(customerId, amount, description, paymentType, TransactionType.Expense);
 }
Beispiel #13
0
 public void PayTicket(Ticket ticket, PaymentType template)
 {
     var amount = ticket.GetRemainingAmount();
     AddPayment(ticket, template, template.Account ?? GetAccountForPayment(ticket, template), amount, amount);
 }
 private void OnMakeFastPaymentExecute(PaymentType obj)
 {
     if (!CanCloseTicket()) return;
     _ticketService.PayTicket(SelectedTicket, obj);
     CloseTicket();
 }
 private bool CanMakeFastPayment(PaymentType arg)
 {
     return SelectedTicket != Ticket.Empty && SelectedTicket.GetRemainingAmount() > 0;
 }
 private bool CanMakePayment(PaymentType arg)
 {
     return SelectedTicket != null
         && !SelectedTicket.IsClosed
         && GetTenderedValue() != 0
         && GetRemainingAmount() != 0
         && (arg.Account != null || SelectedTicket.TicketResources.Any(x => CanMakeAccountTransaction(x, arg)));
 }
Beispiel #17
0
 private void SubmitPayment(PaymentType paymentType)
 {
     if (paymentType == PaymentType.CreditCard && CreditCardProcessingService.CanProcessCreditCards)
     {
         if (SelectedTicket.Id == 0)
         {
             var result = AppServices.MainDataContext.CloseTicket();
             AppServices.MainDataContext.OpenTicket(result.TicketId);
         }
         var ccpd = new CreditCardProcessingData
                        {
                            TenderedAmount = GetTenderedValue(),
                            Ticket = AppServices.MainDataContext.SelectedTicket
                        };
         CreditCardProcessingService.Process(ccpd);
         return;
     }
     ProcessPayment(paymentType);
 }
Beispiel #18
0
 private Account GetAccountForTransaction(PaymentType paymentType, IEnumerable<TicketEntity> ticketResources)
 {
     var rt = _cacheService.GetEntityTypes().Where(
         x => x.AccountTypeId == paymentType.AccountTransactionType.TargetAccountTypeId).Select(x => x.Id);
     var tr = ticketResources.FirstOrDefault(x => rt.Contains(x.EntityTypeId));
     return tr != null ? _accountService.GetAccountById(tr.AccountId) : null;
 }
 private IList<ChangePaymentType> GetChangePaymentTypes(PaymentType paymentType)
 {
     return _foreignCurrencyButtonsViewModel.ForeignCurrency == null
         ? new List<ChangePaymentType>()
         : _applicationState.GetChangePaymentTypes().Where(x => x.AccountTransactionType.TargetAccountTypeId == paymentType.AccountTransactionType.SourceAccountTypeId).ToList();
 }
Beispiel #20
0
 public void AddIncome(int customerId, decimal amount, string description, PaymentType paymentType,bool isCusomter=true)
 {
     AddTransaction(customerId, amount, description, paymentType, TransactionType.Income,isCusomter);
 }
        private void SubmitPayment(PaymentType paymentType)
        {
            var paymentDueAmount = _tenderedValueViewModel.GetPaymentDueValue();
            var tenderedAmount = _tenderedValueViewModel.GetTenderedValue();

            if (Math.Abs(paymentDueAmount - _paymentEditor.GetRemainingAmount()) <= 0.01m)
                paymentDueAmount = _paymentEditor.GetRemainingAmount();

            if (tenderedAmount == 0 || Math.Abs(paymentDueAmount - tenderedAmount) <= 0.01m)
                tenderedAmount = paymentDueAmount;

            if (tenderedAmount <= paymentDueAmount)
            {
                SubmitPaymentAmount(paymentType, null, paymentDueAmount, tenderedAmount);
                return;
            }

            var changeTemplates = GetChangePaymentTypes(paymentType);
            if (changeTemplates.Count() < 2)
            {
                SubmitPaymentAmount(paymentType, changeTemplates.SingleOrDefault(), paymentDueAmount, tenderedAmount);
            }
            else
            {
                _changeTemplatesViewModel.Display(changeTemplates, tenderedAmount, paymentDueAmount, paymentType, _selectChangePaymentTypeCommand);
            }
        }
Beispiel #22
0
 public Payment AddPayment(DateTime date, decimal amount, PaymentType paymentType, int userId, int departmentId)
 {
     var result = new Payment { Amount = amount, Date = date, PaymentType = (int)paymentType, UserId = userId, DepartmentId = departmentId };
     DepartmentId = departmentId;
     Payments.Add(result);
     LastPaymentDate = DateTime.Now;
     RemainingAmount = GetRemainingAmount();
     if (RemainingAmount == 0)
     {
         PaidItems.Clear();
     }
     return result;
 }
Beispiel #23
0
        private static void AddTransaction(int customerId, decimal amount, string description, PaymentType paymentType, TransactionType transactionType, bool isCustomer)
        {
            int suppId = -1;
            int custId = -1;
            if (isCustomer)
            {
                custId = customerId;
            }
            else
            {
                suppId = customerId;
            }
            using (var workspace = WorkspaceFactory.Create())
            {
                if (transactionType == TransactionType.Income || transactionType == TransactionType.Expense)
                {
                    var c = new CashTransaction
                    {
                        Amount = amount,
                        Date = DateTime.Now,
                        Name = description,
                        PaymentType = (int)paymentType,
                        TransactionType = (int)transactionType,
                        UserId = AppServices.CurrentLoggedInUser.Id,
                        CustomerId = custId,
                        SupplierId = suppId
                    };
                    workspace.Add(c);
                }
                else
                {
                    var c = new AccountTransaction
                    {
                        Amount = amount,
                        Date = DateTime.Now,
                        Name = description,
                        TransactionType = (int)transactionType,
                        UserId = AppServices.CurrentLoggedInUser.Id,
                        CustomerId = custId,
                        SupplierId = suppId
                    };
                    workspace.Add(c);
                }

                workspace.CommitChanges();
            }
        }
        private void SubmitPayment(PaymentType paymentType)
        {
            var paymentDueAmount = GetPaymentDueValue();
            var tenderedAmount = GetTenderedValue();

            if (Math.Abs(paymentDueAmount - GetRemainingAmount()) <= 0.01m)
                paymentDueAmount = GetRemainingAmount();

            if (tenderedAmount == 0 || Math.Abs(paymentDueAmount - tenderedAmount) <= 0.01m)
                tenderedAmount = paymentDueAmount;

            if (tenderedAmount <= paymentDueAmount)
            {
                SubmitPaymentAmount(paymentType, null, paymentDueAmount, tenderedAmount);
                return;
            }

            var changeTemplates = GetChangePaymentTypes();
            if (changeTemplates.Count() < 2)
            {
                SubmitPaymentAmount(paymentType, changeTemplates.SingleOrDefault(), paymentDueAmount, tenderedAmount);
            }
            else
            {
                ChangeTemplates.Clear();
                ChangeTemplates.AddRange(changeTemplates.Select(x => new CommandButtonViewModel<PaymentData>
                {
                    Caption = GetChangeAmountCaption(paymentDueAmount, tenderedAmount, x),
                    Parameter = new PaymentData
                    {
                        ChangePaymentType = x,
                        PaymentDueAmount = paymentDueAmount,
                        TenderedAmount = tenderedAmount,
                        PaymentType = paymentType
                    },
                    Command = _selectChangePaymentTypeCommand
                }));
                IsChangeOptionsVisible = true;
            }
        }
Beispiel #25
0
 public void AddPayment(PaymentType paymentType, Account account, decimal amount, decimal exchangeRate, int userId)
 {
     var transaction = TransactionDocument.AddNewTransaction(paymentType.AccountTransactionType, GetTicketAccounts(account), amount, exchangeRate);
     transaction.UpdateDescription(transaction.Name + " [" + account.Name + "]");
     var payment = new Payment { AccountTransaction = transaction, Amount = amount, Name = account.Name, PaymentTypeId = paymentType.Id, UserId = userId };
     Payments.Add(payment);
     LastPaymentDate = DateTime.Now;
     RemainingAmount = GetRemainingAmount();
 }
Beispiel #26
0
 public void PayTicket(Ticket ticket, PaymentType template)
 {
     AddPayment(ticket, template, template.Account, ticket.GetRemainingAmount());
 }
Beispiel #27
0
 public void AddPayment(PaymentType paymentType, Account account, decimal amount, decimal exchangeRate, int userId)
 {
     var transaction = TransactionDocument.AddNewTransaction(paymentType.AccountTransactionType, AccountTypeId, AccountId, account, amount, exchangeRate);
     var payment = new Payment { AccountTransaction = transaction, Amount = amount, Name = account.Name, PaymentTypeId = paymentType.Id };
     Payments.Add(payment);
     LastPaymentDate = DateTime.Now;
     RemainingAmount = GetRemainingAmount();
     if (RemainingAmount == 0)
     {
         PaidItems.Clear();
     }
 }
Beispiel #28
0
 public void AddPayment(Ticket ticket, PaymentType paymentType, Account account, decimal tenderedAmount)
 {
     if (account == null) return;
     var remainingAmount = ticket.GetRemainingAmount();
     var changeAmount = tenderedAmount > remainingAmount ? tenderedAmount - remainingAmount : 0;
     ticket.AddPayment(paymentType, account, tenderedAmount, GetExchangeRate(account), _applicationState.CurrentLoggedInUser.Id);
     _applicationState.NotifyEvent(RuleEventNames.PaymentProcessed,
         new
         {
             Ticket = ticket,
             PaymentTypeName = paymentType.Name,
             TenderedAmount = tenderedAmount,
             ProcessedAmount = tenderedAmount - changeAmount,
             ChangeAmount = changeAmount,
             SelectedQuantity = ticket.PaidItems.Sum(x => x.Quantity),
             RemainingAmount = ticket.GetRemainingAmount()
         });
 }