示例#1
0
        private async void GetAllInvoice()
        {
            try
            {
                var itemLogic        = new ItemLogic(_dbContext);
                var discountLogic    = new DiscountLogic(_dbContext);
                var invoiceLogic     = new InvoiceLogic(_dbContext);
                var invoiceItemLogic = new InvoiceItemLogic(_dbContext);
                var subItemLogic     = new ItemDiscountLogic(_dbContext);
                var tableLogic       = new TableLogic(_dbContext);
                var zoneLogic        = new ZoneLogic(_dbContext);

                var listTable = await tableLogic.GetAllAsync();

                var listInvoice = await invoiceLogic.GetAllAsync(InvoiceStatus.Paid);

                var listVisualInvoice = Mapper.Map <List <VisualInvoiceModel> >(listInvoice);
                var listZone          = await zoneLogic.GetAllAsync();

                var listItem = await itemLogic.GetAllAsync();

                var listVisualItem = Mapper.Map <List <VisualItemMenuModel> >(listItem);
                var listDiscount   = await discountLogic.GetAllAsync();

                var listVisualDiscount = Mapper.Map <List <VisualItemMenuModel> >(listDiscount);

                ListItem     = new List <VisualItemMenuModel>(listVisualItem);
                ListDiscount = new List <VisualItemMenuModel>(listVisualDiscount);

                foreach (var invoice in listVisualInvoice)
                {
                    var listInvoiceItem = await invoiceItemLogic.GetAsync(invoice.Id);

                    foreach (var invoiceItem in listInvoiceItem)
                    {
                        if (invoiceItem.IsDiscount == 1)
                        {
                            var item       = ListDiscount.First(h => h.Id == invoiceItem.FkItemOrDiscount);
                            var visualItem = new VisualItemMenuModel
                            {
                                Id       = item.Id,
                                Quantity = invoiceItem.Quantity,
                                Name     = item.Name,
                                Status   = Status.Normal,
                                Value    = invoiceItem.Value,
                            };
                            invoice.ListDiscount.Add(visualItem);
                        }
                        else
                        {
                            var item        = ListItem.First(h => h.Id == invoiceItem.FkItemOrDiscount);
                            var listSubItem = await subItemLogic.GetAsync(item.Id);

                            var visualItem = new VisualItemMenuModel
                            {
                                Id       = item.Id,
                                Quantity = invoiceItem.Quantity,
                                Name     = item.Name,
                                Status   = Status.Normal,
                                Value    = invoiceItem.Value,
                            };
                            visualItem.ListSubItem.Add(new VisualItemMenuModel
                            {
                                Name  = "Đơn giá",
                                Value = item.Value,
                            });

                            foreach (var subItem in listSubItem)
                            {
                                var visualSubItem = ListDiscount.FirstOrDefault(h => h.Id == subItem.FkDiscount);
                                visualItem.ListSubItem.Add(new VisualItemMenuModel
                                {
                                    Id     = visualSubItem.Id,
                                    Name   = visualSubItem.Name,
                                    Value  = subItem.Value,
                                    Status = Status.Normal,
                                });
                            }

                            invoice.ListItemInBill.Add(visualItem);
                            invoice.ItemCount     += invoiceItem.Quantity;
                            invoice.OriginalPrice += invoiceItem.Value;
                        }
                        if (invoice.IsTakeAway == 0)
                        {
                            var table = listTable.First(h => h.Id == invoice.FkTable);
                            var zone  = listZone.First(h => h.Id == table.FkZone);
                            invoice.TableName = $"{zone.ZoneName} - {table.TableName}";
                        }
                        else
                        {
                            invoice.TableName = $"MANG ĐI";
                        }
                    }
                }
                ListInvoiceBindProp = new ObservableCollection <VisualInvoiceModel>(listVisualInvoice);
            }
            catch (Exception ex)
            {
                await ShowError(ex);
            }
        }
示例#2
0
        private async void OnCompeletePayment(object obj)
        {
            if (IsBusy)
            {
                return;
            }

            if (ReceivedMoneyBindProp < BillBindProp.TotalPrice)
            {
                return;
            }

            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                if (!IsCompletedBindProp)
                {
                    IsCompletedBindProp = true;
                }
                else
                {
                    var invoiceLogic     = new InvoiceLogic(_dbContext);
                    var invoiceItemLogic = new InvoiceItemLogic(_dbContext);
                    var tableLogic       = new TableLogic(_dbContext);
                    var subItemLogic     = new ItemDiscountLogic(_dbContext);
                    var itemLogic        = new ItemLogic(_dbContext);

                    var invoice = new Invoice
                    {
                        Id            = BillBindProp.Id,
                        Status        = (int)InvoiceStatus.Paid,
                        PaidAmount    = ReceivedMoneyBindProp,
                        Tip           = TipBindProp,
                        TotalPrice    = BillBindProp.TotalPrice,
                        IsTakeAway    = BillBindProp.IsTakeAway,
                        FkTable       = BillBindProp.FkTable,
                        CloseDate     = DateTime.Now.ToString(),
                        CustomerCount = BillBindProp.CustomerCount,
                        InvoiceNumber = await GenerateInvoiceNumber()
                    };

                    if (IsEditing)
                    {
                        await invoiceLogic.UpdateAsync(invoice, false);
                    }
                    else
                    {
                        await invoiceLogic.CreateAsync(invoice, false);
                    }

                    if (BillBindProp.IsTakeAway == 0)
                    {
                        await tableLogic.ChangeStatusAsync(new Table
                        {
                            Id         = BillBindProp.FkTable,
                            IsSelected = 0
                        }, false);
                    }

                    foreach (var item in BillBindProp.ListItemInBill)
                    {
                        if (item.Status == Status.New)
                        {
                            await invoiceItemLogic.CreateAsync(new InvoiceItemOrDiscount
                            {
                                FkInvoice        = invoice.Id,
                                FkItemOrDiscount = item.Id,
                                Quantity         = item.Quantity,
                                IsDiscount       = 0,
                                Value            = item.Value
                            }, false);

                            for (int i = 1; i < item.ListSubItem.Count; i++)
                            {
                                await subItemLogic.CreateAsync(new ItemDiscount
                                {
                                    FkItem     = item.Id,
                                    FkDiscount = item.ListSubItem[i].Id,
                                    Value      = item.ListSubItem[i].Value
                                }, false);
                            }
                        }
                        await itemLogic.ModifyQuantityAsync(item.Id, -item.Quantity, false);
                    }

                    foreach (var item in BillBindProp.ListDiscount)
                    {
                        if (item.Status == Status.New)
                        {
                            await invoiceItemLogic.CreateAsync(new InvoiceItemOrDiscount
                            {
                                FkInvoice        = invoice.Id,
                                FkItemOrDiscount = item.Id,
                                Quantity         = item.Quantity,
                                IsDiscount       = 1,
                                Value            = item.Value
                            }, false);
                        }
                    }

                    await _dbContext.SaveChangesAsync();

                    var param = new NavigationParameters();
                    param.Add(Keys.BILL, BillBindProp.Id);
                    await NavigationService.GoBackAsync(param);
                }
            }
            catch (Exception e)
            {
                await ShowError(e);
            }
            finally
            {
                IsBusy = false;
            }
        }