Exemple #1
0
        // GET: VATRegisterSells
        public async Task <IActionResult> Index(int?year, int?month)
        {
            ViewData["Month"]         = new SelectList(Tools.getMonthsDictionary(), "Key", "Value", DateTime.Now.Month);
            ViewData["Year"]          = new SelectList(Tools.getYearsList(), DateTime.Now.Year);
            ViewData["SelectedMonth"] = DateTime.Now.Month;
            ViewData["SelectedYear"]  = DateTime.Now.Year;
            ViewData["ContractorId"]  = new SelectList(_context.Contractor, "Id", "Name");
            VATRegisterSell vATRegisterSell = new VATRegisterSell(DateTime.Now);

            ViewData["VATRegisterSell"] = vATRegisterSell;

            var applicationDbContext = _context.VATRegisterSell.Include(i => i.Contractor);

            if (month != null)
            {
                var filteredResult = applicationDbContext.Where(p => p.DateOfIssue.Month == month);
                ViewData["Month"]         = new SelectList(Tools.getMonthsDictionary(), "Key", "Value", month);
                ViewData["SelectedMonth"] = month;
                if (year != null)
                {
                    filteredResult           = applicationDbContext.Where(p => p.DateOfIssue.Month == month && p.DateOfIssue.Year == year);
                    ViewData["Year"]         = new SelectList(Tools.getYearsList(), year);
                    ViewData["SelectedYear"] = year;
                }
                return(View(await filteredResult.OrderBy(p => p.DateOfIssue).ToListAsync()));
            }
            else
            {
                return(View(await applicationDbContext.Where(p => p.Month == DateTime.Now.Month && p.Year == DateTime.Now.Year).ToListAsync()));
            }
        }
Exemple #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Number,DeliveryDate,DateOfIssue,DocumentNumber,Contractor,ValueBrutto,ValueNetto23,VATValue23,ValueNetto7_8,VATValue7_8,ValueNetto3_5,VATValue3_5,ValueNetto0,ValueTaxFree,ValueNoTax")] VATRegisterSell vATRegisterSell)
        {
            ViewData["ContractorId"] = new SelectList(_context.Contractor, "Id", "Name");
            if (id != vATRegisterSell.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(vATRegisterSell);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VATRegisterSellExists(vATRegisterSell.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vATRegisterSell));
        }
Exemple #3
0
        public async Task <IActionResult> Create([Bind("Id,DeliveryDate,DateOfIssue,DocumentNumber,Contractor,ValueBrutto,ValueNetto23,VATValue23,ValueNetto7_8,VATValue7_8,ValueNetto3_5,VATValue3_5,ValueNetto0,ValueTaxFree,ValueNoTax")] VATRegisterSell vATRegisterSell)
        {
            ViewData["ContractorId"] = new SelectList(_context.Contractor, "Id", "Name");
            if (ModelState.IsValid)
            {
                vATRegisterSell.Number = vATRegisterSell.getOrderNumber(_context);
                _context.Add(vATRegisterSell);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vATRegisterSell));
        }
Exemple #4
0
        // GET: GenerateInvoice
        public async Task <IActionResult> GenerateVATRegister(int?year, int?month)
        {
            if (year == null || month == null)
            {
                return(NotFound());
            }

            var    vATRegisterSell = new VATRegisterSell();
            string pdfFilename     = vATRegisterSell.generate(_context, (int)year, (int)month);
            string downFilename    = vATRegisterSell.getDownloadFilename((int)year, (int)month);
            await Task.Delay(1000);

            return(RedirectToAction("GetPdfFile", new { filename = pdfFilename, downloadFilename = downFilename }));
        }
        // GET: Invoice/Confirm
        public IActionResult Confirm(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Invoice invoice = _context.Invoice.Include(i => i.InvoiceItems).Include(i => i.InvoiceStatus).Single(m => m.Id == id);

            if (invoice.InvoiceStatus.Name != "zatwierdzona")
            {
                invoice.InvoiceStatusId = _context.InvoiceStatus.Single(p => p.Name == "zatwierdzona").Id;
                VATRegisterSell sell    = new VATRegisterSell();
                TaxBook         taxBook = new TaxBook();

                try
                {
                    sell                = _context.VATRegisterSell.Single(p => p.DocumentNumber == invoice.Number);
                    sell.Number         = sell.getOrderNumber(_context);
                    sell.DeliveryDate   = invoice.DateOfDelivery;
                    sell.DateOfIssue    = invoice.DateOfIssue;
                    sell.Month          = sell.DateOfIssue.Month;
                    sell.Year           = sell.DateOfIssue.Year;
                    sell.DocumentNumber = invoice.Number;
                    sell.ContractorId   = invoice.ContractorId;
                    sell.ValueBrutto    = invoice.TotalValueInclVat;

                    sell.ValueNetto23 = 0;
                    sell.VATValue23   = 0;
                    // TO DO: add other VAT rates support
                    foreach (InvoiceItem item in invoice.InvoiceItems)
                    {
                        if (item.VATValue == 23)
                        {
                            sell.ValueNetto23 += item.TotalPrice;
                            sell.VATValue23   += item.TotalVATValue;
                        }
                    }

                    _context.Update(sell);
                }
                catch (Exception)
                {
                    sell.Number         = sell.getOrderNumber(_context);
                    sell.DeliveryDate   = invoice.DateOfDelivery;
                    sell.DateOfIssue    = invoice.DateOfIssue;
                    sell.Month          = sell.DateOfIssue.Month;
                    sell.Year           = sell.DateOfIssue.Year;
                    sell.DocumentNumber = invoice.Number;
                    sell.ContractorId   = invoice.ContractorId;
                    sell.ValueBrutto    = invoice.TotalValueInclVat;

                    // TO DO: add other VAT rates support
                    foreach (InvoiceItem item in invoice.InvoiceItems)
                    {
                        if (item.VATValue == 23)
                        {
                            sell.ValueNetto23 += item.TotalPrice;
                            sell.VATValue23   += item.TotalVATValue;
                        }
                    }
                    _context.Add(sell);
                }

                try
                {
                    taxBook              = _context.TaxBookItem.Single(p => p.InvoiceNumber == invoice.Number);
                    taxBook.Date         = invoice.DateOfIssue;
                    taxBook.ContractorId = invoice.ContractorId;
                    taxBook.SellValue    = invoice.TotalValue;
                    taxBook.Description  = "sprzedaż";
                    _context.Update(taxBook);
                }
                catch (Exception)
                {
                    taxBook.Date          = invoice.DateOfIssue;
                    taxBook.InvoiceNumber = invoice.Number;
                    taxBook.ContractorId  = invoice.ContractorId;
                    taxBook.SellValue     = invoice.TotalValue;
                    taxBook.Description   = "sprzedaż";
                    _context.Add(taxBook);
                }

                _context.Update(invoice);
                _context.SaveChanges();
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                invoice.InvoiceStatusId = _context.InvoiceStatus.Single(p => p.Name == "nowa").Id;
                _context.Update(invoice);
                _context.SaveChanges();
                return(RedirectToAction(nameof(Details), new { id = id }));
            }
        }