public IActionResult PostCalcRates([FromBody] InvoiceSellDTO inv)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            return(Ok(inv));
        }
        public async Task <IActionResult> GenInvoicePdf([FromBody] InvoiceSellDTO invoiceSell)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            invoiceSell.CompanySeller = await this._companyService.OwnerDTO();

            if (invoiceSell.CompanyBuyer.AddressList.Count == 0 || invoiceSell.CompanyBuyer.BankAccountList.Count == 0)
            {
                invoiceSell.CompanyBuyer = this._companyService.GetCompanyDTOById((int)invoiceSell.CompanyBuyer.CompanyId.Value);
            }
            MemoryStream ms = new MemoryStream(_pdf.InvoicePdf(invoiceSell).ToArray());

            return(File(ms, "application/pdf", "invoice.pdf"));
        }
        public async Task <IActionResult> Put(int id, [FromBody] InvoiceSellDTO dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var dbInvoice = new InvoiceSell();

            if (id > 0)
            {
                dbInvoice = await this._invoiceService.QueryableInvoiceSell()
                            .FirstOrDefaultAsync(f => f.InvoiceSellId == id);

                if (dbInvoice == null)
                {
                    return(BadRequest(bp.sharedLocal.ModelStateHelpful.ModelStateHelpful.ModelError("Error", $"Nie znaleziono faktury o Id: {id}")));
                }
            }
            else
            {
                this._db.Entry(dbInvoice).State = EntityState.Added;
            }

            //correction - create NEW
            if (dto.IsCorrection && dto.InvoiceNo == null)
            {
                //setting inActive
                var newInvCorr = new InvoiceSell();
                this._invoiceService.InvoiceSellCorrectionSetInactive(dbInvoice);

                newInvCorr.BaseInvoiceId = dbInvoice.InvoiceSellId;

                await this._invoiceService.MapperInvoiceSell(newInvCorr, dto, User);

                this._db.Entry(newInvCorr).State = EntityState.Added;
                try
                {
                    await this._db.SaveChangesAsync();

                    //setting new correctionID
                    dbInvoice.CorrectiondId = newInvCorr.InvoiceSellId;
                    await this._db.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    throw e;
                }

                var correctedDTO = this._invoiceService.EtoDTOInvoiceSellForInvoiceCorrection(this._invoiceService.EtoDTOInvoiceSell(newInvCorr), this._invoiceService.EtoDTOInvoiceSell(dbInvoice));
                return(Ok(correctedDTO));
            }

            if (dto.IsCorrection && dto.InvoiceNo != null)
            {
                if (dbInvoice.IsInactive == false)
                {
                    await this._invoiceService.MapperInvoiceSell(dbInvoice, dto, User);

                    await this._db.SaveChangesAsync();
                }

                var baseInvoice = await this._invoiceService.QueryableInvoiceSell()
                                  .FirstOrDefaultAsync(f => f.InvoiceSellId == dbInvoice.BaseInvoiceId.Value);

                return(Ok(this._invoiceService.EtoDTOInvoiceSellForInvoiceCorrection(this._invoiceService.EtoDTOInvoiceSell(dbInvoice), this._invoiceService.EtoDTOInvoiceSell(baseInvoice))));
            }

            if (dbInvoice.IsInactive == false)
            {
                await this._invoiceService.MapperInvoiceSell(dbInvoice, dto, User);
            }

            try
            {
                await this._db.SaveChangesAsync();
            }
            catch (Exception e)
            {
                throw e;
            }


            return(Ok(this._invoiceService.EtoDTOInvoiceSell(dbInvoice)));
        }
Beispiel #4
0
 public InvoiceCorrectionPaymentInfo(InvoiceSellDTO inv)
 {
     this._inv = inv;
 }
Beispiel #5
0
        public MemoryStream InvoicePdf(InvoiceSellDTO inv)
        {
            MemoryStream ms  = new MemoryStream();
            var          doc = this.DefaultPdfDoc(ms);


            bool   isCorr          = inv.IsCorrection;
            string invoiceTypeName = inv.IsCorrection ? "Faktura korygująca" : "Faktura VAT";
            string subTitle        = isCorr ? $"Do dokumentu: {inv.InvoiceOriginalNo}" : null;
            var    headerCompany   = this.HederCompanyGen(inv.CompanySeller, "Sprzedawca", inv.CompanyBuyer, "Nabywca", $"{invoiceTypeName} {inv.InvoiceNo}", subTitle);

            float posFontSize = 9f;

            doc.Add(FakCell(inv.DateOfSell.ToShortDateString(), "Data sprzedaży", posFontSize, TextAlignment.RIGHT, 1, 1));
            doc.Add(FakCell(inv.DateOfIssue.ToShortDateString(), "Data wystawienia", posFontSize, TextAlignment.RIGHT, 1, 1));
            doc.Add(headerCompany);

            doc.Add(EmptyCell(1, 1));
            var invListTable = this.InvoiceLinesTable(inv.InvoiceLines, posFontSize, isCorr);

            doc.Add(invListTable);
            doc.Add(EmptyCell(1, 1));

            var rates = this.InvoiceRatesTable(inv.Rates.OrderByDescending(o => o.Current.Vat_rate).ToList(), posFontSize, isCorr);

            rates.SetHorizontalAlignment(HorizontalAlignment.RIGHT);
            rates.SetKeepTogether(true);
            rates.SetMarginTop(posFontSize);

            doc.Add(rates);

            var totalTable = this.InvoiceTotalTable(inv.InvoiceTotal, isCorr, posFontSize);

            totalTable.SetMarginTop(posFontSize);
            totalTable.SetMarginBottom(posFontSize);
            totalTable.SetHorizontalAlignment(HorizontalAlignment.RIGHT);
            doc.Add(totalTable);



            if (isCorr)
            {
                //var leftToPayValue = inv.invoiceOriginalPaid?
            }

            var leftToPay = FakCell(inv.GetCorrectionPaymenntInfo, null, posFontSize * 2f, TextAlignment.RIGHT, 1, 1);

            doc.Add(leftToPay);

            doc.Add(FakCell($"{inv.Currency.Name} ({inv.Currency.Description})", "Waluta", posFontSize * 1.3f, TextAlignment.LEFT, 1, 1));
            if (isCorr)
            {
                var terms = inv.PaymentTerms;

                var dayDays = terms.PaymentDays > 1 ? "dni" : "dzień";
                var isDays  = terms.PaymentTerm.IsPaymentDate ? $", {terms.PaymentDays} {dayDays}" : null;
                doc.Add(FakCell($"{terms.PaymentTerm.Name}{isDays}", "Forma płatności", posFontSize * 1.3f, TextAlignment.LEFT, 1, 1));
            }
            else
            {
                doc.Add(FakCell(inv.PaymentTerms.PaymentTermsCombined, "Forma płatności, termin", posFontSize * 1.3f, TextAlignment.LEFT, 1, 1));
            }


            if (inv.ExtraInfo.Is_in_words)
            {
                doc.Add(FakCell(inv.ExtraInfo.Total_brutto_in_words, "Słownie brutto", posFontSize * 1.3f, TextAlignment.LEFT, 1, 1));
            }
            if (inv.ExtraInfo.Is_load_no)
            {
                if (inv.ExtraInfo.TransportOfferNo != null)
                {
                    doc.Add(FakCell(inv.ExtraInfo.TransportOfferNo, "Zlecenie nr", posFontSize * 1.3f, TextAlignment.LEFT, 1, 1));
                }
                else
                {
                    doc.Add(FakCell(inv.ExtraInfo.LoadNo, "Zlecenie nr", posFontSize * 1.3f, TextAlignment.LEFT, 1, 1));
                }
            }
            if (inv.ExtraInfo.Is_tax_nbp_exchanged)
            {
                doc.Add(FakCell(inv.ExtraInfo.Tax_exchanged_info, "Przelicznik", posFontSize * 1.3f, TextAlignment.LEFT, 1, 1));
            }
            if (!string.IsNullOrWhiteSpace(inv.Info))
            {
                doc.Add(FakCell(inv.Info, "Uwagi", posFontSize * 1.3f, TextAlignment.LEFT, 1, 1));
            }

            if (inv.ExtraInfo.IsSigningPlace)
            {
                var signingTable = new Table(UnitValue.CreatePercentArray(new float[] { 3, 2, 3 })); //3 cols
                signingTable.SetWidth(UnitValue.CreatePercentValue(100));

                signingTable.AddCell(FakCell("...................................................................", null, posFontSize, TextAlignment.CENTER, 1, 1));
                signingTable.AddCell(EmptyCell());
                signingTable.AddCell(FakCell("...................................................................", null, posFontSize, TextAlignment.CENTER, 1, 1));

                signingTable.AddCell(FakCell("Podpis osoby upoważnionej do odebrania faktury", null, posFontSize * 0.8f, TextAlignment.CENTER, 1, 1));
                signingTable.AddCell(EmptyCell());
                signingTable.AddCell(FakCell("Podpis osoby upoważnionej do wystawienia faktury", null, posFontSize * 0.8f, TextAlignment.CENTER, 1, 1));

                signingTable.SetMarginTop(posFontSize * 10f);
                doc.Add(signingTable);
            }


            if (doc.GetPdfDocument().GetNumberOfPages() > 1)
            {
                doc.GetPdfDocument().AddEventHandler(PdfDocumentEvent.END_PAGE, new InvoiceFooter(doc, this.FontExoThin, inv.GetInvoiceNo));
            }
            doc.Close();
            return(ms);
        }