示例#1
0
        // GET: PaymentTypes/Details/5
        public IActionResult Details(int id)
        {
            var paymentType = paymentTypeService.GetById(id);

            if (paymentType == null)
            {
                return(NotFound());
            }

            return(View(paymentType));
        }
        public async Task <DocumentView> GetDocumetnById(long id)
        {
            var document = await vatDocumentRepo.Context.VatDocuments
                           .Include(vt => vt.WriterEmployee)
                           .Include(vt => vt.RecipientEmployee)
                           .Include(vt => vt.Sales)
                           .Include(vt => vt.CompanyObject)
                           .Where(vt => vt.Id == id)
                           .FirstOrDefaultAsync();

            if (document is null)
            {
                return(null);
            }

            var documentView = new DocumentView()
            {
                Id                = document.Id,
                Type              = SetType(document.Type.ToString()),
                CreatedDate       = document.CreatedDate.ToString("dd.MM.yyyy"),
                VatReasonDate     = document.VatReasonDate.ToString("dd.MM.yyyy"),
                SubTottal         = document.SubTottal,
                Vat               = document.Vat ?? 0,
                Tottal            = document.Tottal,
                Description       = document.Description,
                FreeText          = document.FreeText,
                ObjectCity        = document.CompanyObject.City,
                ObjectName        = document.CompanyObject.Name,
                WriterEmployee    = document.WriterEmployee?.FullName,
                RecipientEmployee = document.RecipientEmployee?.FullName,
                Grif              = "ОРИГИНАЛ",
            };

            SetTottalSlovom(documentView);

            documentView.Company = await companySettingsService.GetCompanyInfoById(document.CompanyId);

            documentView.Partner = await partnerService.GetPartnerById(document.PartnerId);

            documentView.PaymentType = await paymentTypeService.GetById(document.PaymentTypeId);

            if (document.BankAccountId != null && documentView.PaymentType.RequiredBankAccount)
            {
                documentView.BankAccount = await bankAccountService.GetById(document.BankAccountId ?? 0);
            }

            var tottalByVat = new List <TottalByVat>();

            foreach (var sale in document.Sales)
            {
                if (sale.ProductId != null)
                {
                    var product = await vatDocumentRepo.Context.Products
                                  .Where(p => p.Id == sale.ProductId)
                                  .Select(p => new ProductRow()
                    {
                        IsProduct         = true,
                        Name              = p.Name,
                        ProductType       = p.QuantityType.Type,
                        VatTypeId         = p.VatTypeId,
                        VatTypeName       = p.VatType.Name,
                        VatTypePercentage = p.VatType.Percantage,
                        Quantity          = sale.Quantity,
                        Price             = sale.UnitPrice,
                        TottalPrice       = sale.Total,
                    })
                                  .FirstOrDefaultAsync();

                    documentView.Products.Add(product);

                    var vat = tottalByVat.Where(x => x.Id == product.VatTypeId).FirstOrDefault();
                    if (vat is null)
                    {
                        vat = new TottalByVat()
                        {
                            Id         = product.VatTypeId,
                            Name       = product.VatTypeName,
                            Percentage = product.VatTypePercentage,
                            Base       = sale.Total,
                            Vat        = sale.Vat ?? 0,
                            Tottal     = sale.TottalWithVat,
                        };

                        tottalByVat.Add(vat);
                    }
                    else
                    {
                        vat.Base   += sale.Total;
                        vat.Vat    += sale.Vat ?? 0;
                        vat.Tottal += sale.TottalWithVat;
                    }
                }
                else if (sale.FreeProductId != null)
                {
                    var product = await vatDocumentRepo.Context.FreeProducts
                                  .Where(p => p.Id == sale.FreeProductId)
                                  .Select(p => new ProductRow()
                    {
                        IsProduct         = false,
                        Name              = p.Name,
                        ProductType       = p.QuantityType,
                        VatTypeId         = p.VatTypeId,
                        VatTypeName       = p.VatType.Name,
                        VatTypePercentage = p.VatType.Percantage,
                        Quantity          = sale.Quantity,
                        Price             = sale.UnitPrice,
                        TottalPrice       = sale.Total,
                    })
                                  .FirstOrDefaultAsync();

                    documentView.Products.Add(product);

                    var vat = tottalByVat.Where(x => x.Id == product.VatTypeId).FirstOrDefault();
                    if (vat is null)
                    {
                        vat = new TottalByVat()
                        {
                            Id         = product.VatTypeId,
                            Name       = product.VatTypeName,
                            Percentage = product.VatTypePercentage,
                            Base       = sale.Total,
                            Vat        = sale.Vat ?? 0,
                            Tottal     = sale.TottalWithVat,
                        };
                        tottalByVat.Add(vat);
                    }
                    else
                    {
                        vat.Base   += sale.Total;
                        vat.Vat    += sale.Vat ?? 0;
                        vat.Tottal += sale.TottalWithVat;
                    }
                }
            }
            documentView.TottalByVats = tottalByVat;
            return(documentView);
        }
        public async Task <IActionResult> Edit(int id)
        {
            var model = await paymentTypeService.GetById(id);

            return(View(model));
        }