Beispiel #1
0
 public void UpdateTicketNumber(Ticket ticket, Numerator numerator)
 {
     if (numerator == null)
     {
         numerator = SelectedDepartment.TicketNumerator;
     }
     if (string.IsNullOrEmpty(ticket.TicketNumber))
     {
         ticket.TicketNumber = NumberGenerator.GetNextString(numerator.Id);
     }
 }
Beispiel #2
0
        public TicketCommitResult CloseTicket()
        {
            var result = new TicketCommitResult();

            Debug.Assert(SelectedTicket != null);
            var changed = false;

            if (SelectedTicket.Id > 0)
            {
                var lup = Dao.Single <Ticket, DateTime>(SelectedTicket.Id, x => x.LastUpdateTime);
                if (SelectedTicket.LastUpdateTime.CompareTo(lup) != 0)
                {
                    var currentTicket = Dao.Single <Ticket>(x => x.Id == SelectedTicket.Id, x => x.TicketItems, x => x.Payments);
                    if (currentTicket.LocationName != SelectedTicket.LocationName)
                    {
                        result.ErrorMessage = string.Format(Resources.TicketMovedRetryLastOperation_f, currentTicket.LocationName);
                        changed             = true;
                    }

                    if (currentTicket.IsPaid != SelectedTicket.IsPaid)
                    {
                        if (currentTicket.IsPaid)
                        {
                            result.ErrorMessage = Resources.TicketPaidChangesNotSaved;
                        }
                        if (SelectedTicket.IsPaid)
                        {
                            result.ErrorMessage = Resources.TicketChangedRetryLastOperation;
                        }
                        changed = true;
                    }
                    else if (SelectedTicket.RemainingAmount == 0 && currentTicket.TotalAmount != SelectedTicket.TotalAmount)
                    {
                        result.ErrorMessage = Resources.TicketChangedRetryLastOperation;
                        changed             = true;
                    }
                    else if (currentTicket.LastPaymentDate != SelectedTicket.LastPaymentDate)
                    {
                        var currentPaymentIds = SelectedTicket.Payments.Select(x => x.Id).Distinct();
                        var unknownPayments   = currentTicket.Payments.Where(x => !currentPaymentIds.Contains(x.Id)).FirstOrDefault();
                        if (unknownPayments != null)
                        {
                            result.ErrorMessage = Resources.TicketPaidLastChangesNotSaved;
                            changed             = true;
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(SelectedTicket.LocationName) && SelectedTicket.Id == 0)
            {
                var ticketId = Dao.Select <Table, int>(x => x.TicketId, x => x.Name == SelectedTicket.LocationName).FirstOrDefault();
                {
                    if (ticketId > 0)
                    {
                        result.ErrorMessage = string.Format(Resources.TableChangedRetryLastOperation_f, SelectedTicket.LocationName);
                        changed             = true;
                    }
                }
            }

            var canSumbitTicket = !changed && SelectedTicket.CanSubmit; // Fişi kaydedebilmek için gün sonu yapılmamış ve fişin ödenmemiş olması gerekir.

            if (canSumbitTicket)
            {
                _ticketWorkspace.RemoveTicketItems(SelectedTicket.PopRemovedTicketItems());
                _ticketWorkspace.RemoveTaxServices(SelectedTicket.PopRemovedTaxServices());
                Recalculate(SelectedTicket);

                if (!SelectedTicket.IsPaid && SelectedTicket.RemainingAmount == 0 && AppServices.CurrentTerminal.DepartmentId > 0)
                {
                    SelectedTicket.DepartmentId = AppServices.CurrentTerminal.DepartmentId;
                }

                SelectedTicket.IsPaid = SelectedTicket.RemainingAmount == 0;


                if (SelectedTicket.TicketItems.Count > 0)
                {
                    if (SelectedTicket.TicketItems.Where(x => !x.Locked).FirstOrDefault() != null)
                    {
                        SelectedTicket.MergeLinesAndUpdateOrderNumbers(NumberGenerator.GetNextNumber(SelectedDepartment.OrderNumerator.Id));
                    }

                    if (SelectedTicket.Id == 0)
                    {
                        UpdateTicketNumber(SelectedTicket);
                        SelectedTicket.LastOrderDate = DateTime.Now;
                        _ticketWorkspace.CommitChanges();
                    }

                    Debug.Assert(!string.IsNullOrEmpty(SelectedTicket.TicketNumber));
                    Debug.Assert(SelectedTicket.Id > 0);

                    //Otomatik yazdırma
                    AppServices.PrintService.AutoPrintTicket(SelectedTicket);
                    SelectedTicket.LockTicket();
                }

                UpdateTicketTable(SelectedTicket);

                if (SelectedTicket.Id > 0)  // eğer adisyonda satır yoksa ID burada 0 olmalı.
                {
                    _ticketWorkspace.CommitChanges();
                }

                Debug.Assert(SelectedTicket.TicketItems.Count(x => x.OrderNumber == 0) == 0);
            }
            result.TicketId = SelectedTicket.Id;
            _ticketWorkspace.Reset();

            return(result);
        }