Пример #1
0
        public string generate(ApplicationDbContext _context, int year, int month)
        {
            string    path = "templates/vatRegisterBuy.xml";
            XDocument doc  = XDocument.Load(path);
            XElement  root = doc.Element("Template");

            Company company             = _context.Company.FirstOrDefault();
            var     vatRegisterBuyItems = _context.VATRegisterBuy.Include(i => i.Contractor).Where(p => p.Year == year && p.Month == month).ToList();

            var monthDict = Tools.getMonthsDictionary();

            string header = root.Element("Header").Value;

            header = string.Format(header, company.FullName, monthDict[month], year, company.FullAddress, company.NIP);

            string tableHeader  = root.Element("TableHeader").Value;
            string tableSummary = root.Element("TableSummary").Value;
            string tableRow     = root.Element("TableRow").Value;

            decimal totalValueBrutto          = 0;
            decimal totalValueNetto           = 0;
            decimal totalTaxDeductibleValue   = 0;
            decimal totalTaxFreeBuysValue     = 0;
            decimal totalNoTaxDeductibleValue = 0;

            foreach (VATRegisterBuy item in vatRegisterBuyItems)
            {
                decimal taxDeductibleVal   = (decimal)item.TaxDeductibleValue;
                decimal taxFreeBuysVal     = (decimal)item.TaxFreeBuysValue;
                decimal noTaxDeductibleVal = (decimal)item.NoTaxDeductibleBuysValue;

                string documentNo = Tools.handleLatexSpecialChars(item.DocumentNumber);

                string newItem = string.Format(tableRow, item.Number, item.DeliveryDate.ToShortDateString(), item.DateOfIssue.ToShortDateString(), documentNo, item.Contractor.FullName, item.ValueBrutto.ToString("0.00"), item.ValueNetto.ToString("0.00"), taxDeductibleVal.ToString("0.00"), taxFreeBuysVal.ToString("0.00"), noTaxDeductibleVal.ToString("0.00"));

                tableHeader               += newItem;
                totalValueBrutto          += item.ValueBrutto;
                totalValueNetto           += item.ValueNetto;
                totalTaxDeductibleValue   += taxDeductibleVal;
                totalTaxFreeBuysValue     += taxFreeBuysVal;
                totalNoTaxDeductibleValue += noTaxDeductibleVal;
            }

            tableSummary = string.Format(tableSummary, totalValueBrutto.ToString("0.00"), totalValueNetto.ToString("0.00"), totalTaxDeductibleValue.ToString("0.00"), totalTaxFreeBuysValue.ToString("0.00"), totalNoTaxDeductibleValue.ToString("0.00"));
            tableHeader += tableSummary;

            string footer = root.Element("Footer").Value;
            string output = header + tableHeader + footer;

            output = output.Replace("~^~^", "{{");
            output = output.Replace("^~^~", "}}");
            output = output.Replace("~^", "{");
            output = output.Replace("^~", "}");

            string time = DateTime.Now.ToFileTime().ToString();

            string outputFile = Tools.getHash(header + time);

            File.WriteAllText("tmp/" + outputFile + ".tex", output);

            Process process = new Process();

            process.StartInfo.WorkingDirectory = "tmp";
            process.StartInfo.FileName         = "pdflatex";
            process.StartInfo.Arguments        = outputFile + ".tex";
            process.Start();

            process.Dispose();
            return(outputFile + ".pdf");
        }
Пример #2
0
        public string generate()
        {
            XDocument xml  = new XDocument();
            XElement  root = new XElement(tns + "JPK");

            root.Add(new XAttribute(XNamespace.Xmlns + "etd", etd));
            root.Add(new XAttribute(XNamespace.Xmlns + "tns", tns));
            root.Add(new XAttribute(XNamespace.Xmlns + "xsi", xsi));

            XElement naglowek = new XElement(tns + "Naglowek");

            XElement   kodFormularza = new XElement(tns + "KodFormularza", Naglowek.KodFormularza.Wartosc);
            XAttribute kodSystemowy  = new XAttribute("kodSystemowy", Naglowek.KodFormularza.KodSystemowy);
            XAttribute wersjaSchemy  = new XAttribute("wersjaSchemy", Naglowek.KodFormularza.WersjaSchemy);

            kodFormularza.Add(kodSystemowy);
            kodFormularza.Add(wersjaSchemy);
            naglowek.Add(kodFormularza);

            XElement wariantFormularza  = new XElement(tns + "WariantFormularza", Naglowek.WariantFormularza);
            XElement celZlozenia        = new XElement(tns + "CelZlozenia", Naglowek.CelZlozenia);
            XElement dataWytworzeniaJPK = new XElement(tns + "DataWytworzeniaJPK", Naglowek.DataWytworzeniaJPK.ToString("yyyy-MM-ddTHH:mm:ss"));
            XElement dataOd             = new XElement(tns + "DataOd", formatDate(Naglowek.DataOd));
            XElement dataDo             = new XElement(tns + "DataDo", formatDate(Naglowek.DataDo));
            XElement nazwaSystemu       = new XElement(tns + "NazwaSystemu", Naglowek.NazwaSystemu);

            naglowek.Add(wariantFormularza);
            naglowek.Add(celZlozenia);
            naglowek.Add(dataWytworzeniaJPK);
            naglowek.Add(dataOd);
            naglowek.Add(dataDo);
            naglowek.Add(nazwaSystemu);
            root.Add(naglowek);

            XElement podmiot    = new XElement(tns + "Podmiot1");
            XElement nip        = new XElement(tns + "NIP", Podmiot.NIP);
            XElement pelnaNazwa = new XElement(tns + "PelnaNazwa", Podmiot.PelnaNazwa);
            XElement email      = new XElement(tns + "Email", Podmiot.Email);

            podmiot.Add(nip);
            podmiot.Add(pelnaNazwa);
            podmiot.Add(email);
            root.Add(podmiot);

            foreach (SprzedazWiersz s in SprzedazWierszList)
            {
                XElement sprzedazWiersz   = new XElement(tns + "SprzedazWiersz");
                XElement lpSprzedazy      = new XElement(tns + "LpSprzedazy", s.LpSprzedazy);
                XElement nrKontrahenta    = new XElement(tns + "NrKontrahenta", s.NrKontrahenta);
                XElement nazwaKontrahenta = new XElement(tns + "NazwaKontrahenta", s.NazwaKontrahenta);
                XElement adresKontrahenta = new XElement(tns + "AdresKontrahenta", s.AdresKontrahenta);
                XElement dowodSprzedazy   = new XElement(tns + "DowodSprzedazy", s.DowodSprzedazy);
                XElement dataWystawienia  = new XElement(tns + "DataWystawienia", formatDate(s.DataWystawienia));
                XElement dataSprzedazy    = new XElement(tns + "DataSprzedazy", formatDate(s.DataSprzedazy));
                XElement k_19             = new XElement(tns + "K_19", Tools.decimalRound(s.K_19));
                XElement k_20             = new XElement(tns + "K_20", Tools.decimalRound(s.K_20));

                sprzedazWiersz.Add(lpSprzedazy);
                sprzedazWiersz.Add(nrKontrahenta);
                sprzedazWiersz.Add(nazwaKontrahenta);
                sprzedazWiersz.Add(adresKontrahenta);
                sprzedazWiersz.Add(dowodSprzedazy);
                sprzedazWiersz.Add(dataWystawienia);
                sprzedazWiersz.Add(dataSprzedazy);
                sprzedazWiersz.Add(k_19);
                sprzedazWiersz.Add(k_20);
                root.Add(sprzedazWiersz);
            }
            XElement sprzedazCtrl           = new XElement(tns + "SprzedazCtrl");
            XElement liczbaWierszySprzedazy = new XElement(tns + "LiczbaWierszySprzedazy", SprzedazCtrl.LiczbaWierszySprzedazy);
            XElement podatekNalezny         = new XElement(tns + "PodatekNalezny", SprzedazCtrl.PodatekNalezny);

            sprzedazCtrl.Add(liczbaWierszySprzedazy);
            sprzedazCtrl.Add(podatekNalezny);
            root.Add(sprzedazCtrl);

            foreach (ZakupWiersz z in ZakupWierszList)
            {
                XElement zakupWiersz   = new XElement(tns + "ZakupWiersz");
                XElement lpZakupu      = new XElement(tns + "LpZakupu", z.LpZakupu);
                XElement nrDostawcy    = new XElement(tns + "NrDostawcy", z.NrDostawcy);
                XElement nazwaDostawcy = new XElement(tns + "NazwaDostawcy", z.NazwaDostawcy);
                XElement adresDostawcy = new XElement(tns + "AdresDostawcy", z.AdresDostawcy);
                XElement dowodZakupu   = new XElement(tns + "DowodZakupu", z.DowodZakupu);
                XElement dataZakupu    = new XElement(tns + "DataZakupu", formatDate(z.DataZakupu));
                XElement dataWplywu    = new XElement(tns + "DataWplywu", formatDate(z.DataWplywu));
                XElement k_45          = new XElement(tns + "K_45", z.K_45);
                XElement k_46          = new XElement(tns + "K_46", z.K_46);

                zakupWiersz.Add(lpZakupu);
                zakupWiersz.Add(nrDostawcy);
                zakupWiersz.Add(nazwaDostawcy);
                zakupWiersz.Add(adresDostawcy);
                zakupWiersz.Add(dowodZakupu);
                zakupWiersz.Add(dataZakupu);
                zakupWiersz.Add(dataWplywu);
                zakupWiersz.Add(k_45);
                zakupWiersz.Add(k_46);
                root.Add(zakupWiersz);
            }
            XElement zakupCtrl           = new XElement(tns + "ZakupCtrl");
            XElement liczbaWierszyZakupu = new XElement(tns + "LiczbaWierszyZakupow", ZakupCtrl.LiczbaWierszyZakupow);
            XElement podatekNaliczony    = new XElement(tns + "PodatekNaliczony", ZakupCtrl.PodatekNaliczony);

            zakupCtrl.Add(liczbaWierszyZakupu);
            zakupCtrl.Add(podatekNaliczony);
            root.Add(zakupCtrl);

            xml.Add(root);

            string time     = DateTime.Now.ToFileTime().ToString();
            string filename = Tools.getHash(xml.ToString() + time) + ".xml";

            xml.Save("tmp/" + filename);

            return(filename);
        }
Пример #3
0
        // public int getOrderNumber (ApplicationDbContext _context)
        // {
        //     try
        //     {
        //         return _context.TaxBookItem.Where (p => p.Date.Month == DateTime.Now.Month && p.Date.Year == DateTime.Now.Year).Last ().Number + 1;
        //     }
        //     catch (Exception)
        //     {
        //         return 1;
        //     }
        // }

        public string generate(ApplicationDbContext _context, int year, int month)
        {
            string    path = "templates/taxBook.xml";
            XDocument doc  = XDocument.Load(path);
            XElement  root = doc.Element("Template");

            string dateTimeFormat = "yyyy-MM-dd";

            var taxBookItems = _context.TaxBookItem.Include(p => p.Contractor).Where(p => p.Date.Year == year && p.Date.Month == month).OrderBy(p => p.Date).ToList();

            var monthDict = Tools.getMonthsDictionary();

            string header = root.Element("Header").Value;

            header = string.Format(header, monthDict[month], year);

            string tableHeader  = root.Element("TableHeader").Value;
            string tableSummary = root.Element("TableSummary").Value;
            string tableRow     = root.Element("TableRow").Value;

            decimal totalSellVall    = 0;
            decimal totalOtherInc    = 0;
            decimal totalTotalInc    = 0;
            decimal totalGoodsBuy    = 0;
            decimal totalBuysSideEff = 0;
            decimal totalSalary      = 0;
            decimal totalOtherCos    = 0;
            decimal totalTotalCos    = 0;
            decimal totalCol15       = 0;
            decimal totalResearchCos = 0;

            int i = 1;

            foreach (TaxBook item in taxBookItems)
            {
                string documentNo = Tools.handleLatexSpecialChars(item.InvoiceNumber);

                decimal sellVal     = (decimal)item.SellValue;
                decimal otherInc    = (decimal)item.OtherIncome;
                decimal totalInc    = (decimal)item.TotalIncome;
                decimal goodsBuy    = (decimal)item.GoodsBuys;
                decimal buysSideEff = (decimal)item.BuysSideEffects;
                decimal salary      = (decimal)item.Salary;
                decimal otherCos    = (decimal)item.OtherCosts;
                decimal totalCos    = (decimal)item.TotalCosts;
                decimal col15       = (decimal)item.Column15;
                decimal researchCos = (decimal)item.ResearchCostValue;

                string newItem = string.Format(tableRow, i, item.Date.ToString(dateTimeFormat), documentNo, Tools.handleLatexSpecialChars(item.Contractor.FullName), item.Contractor.FullAddress, item.Description, sellVal.ToString("0.00"), otherInc.ToString("0.00"), totalInc.ToString("0.00"), goodsBuy.ToString("0.00"), buysSideEff.ToString("0.00"), salary.ToString("0.00"), otherCos.ToString("0.00"), totalCos.ToString("0.00"), col15.ToString("0.00"), item.CostDescription, researchCos.ToString("0.00"), item.Comments);

                tableHeader += newItem;

                totalSellVall    += sellVal;
                totalOtherInc    += otherInc;
                totalTotalInc    += totalInc;
                totalGoodsBuy    += goodsBuy;
                totalBuysSideEff += buysSideEff;
                totalSalary      += salary;
                totalOtherCos    += otherCos;
                totalTotalCos    += totalCos;
                totalCol15       += col15;
                totalResearchCos += researchCos;

                i++;
            }

            tableSummary = string.Format(tableSummary, totalSellVall.ToString("0.00"), totalOtherInc.ToString("0.00"), totalTotalInc.ToString("0.00"), totalGoodsBuy.ToString("0.00"), totalBuysSideEff.ToString("0.00"), totalSalary.ToString("0.00"), totalOtherCos.ToString("0.00"), totalTotalCos.ToString("0.00"), totalCol15.ToString("0.00"), totalResearchCos.ToString("0.00"));
            tableHeader += tableSummary;

            string output = header + tableHeader;

            output = output.Replace("~^~^~^", "{{{");
            output = output.Replace("^~^~^~", "}}}");
            output = output.Replace("~^~^", "{{");
            output = output.Replace("^~^~", "}}");
            output = output.Replace("~^", "{");
            output = output.Replace("^~", "}");

            string time = DateTime.Now.ToFileTime().ToString();

            string outputFile = Tools.getHash(header + time);

            File.WriteAllText("tmp/" + outputFile + ".tex", output);

            Process process = new Process();

            process.StartInfo.WorkingDirectory = "tmp";
            process.StartInfo.FileName         = "pdflatex";
            process.StartInfo.Arguments        = "-synctex=1 -interaction=nonstopmode " + outputFile + ".tex";
            process.Start();
            process.Dispose();

            return(outputFile + ".pdf");
        }
Пример #4
0
        // typeCode = 0 - generate invoice
        // typeCode = 1 - generate invoice duplicate eith current date
        public string generate(int typeCode)
        {
            string    path = "templates/invoice.xml";
            XDocument doc  = XDocument.Load(path);
            XElement  root = doc.Element("Template");

            string dateTimeFormat = "yyyy-MM-dd";

            string header = root.Element("Header").Value;

            header = string.Format(header, Company.Name, Company.FullAddress, Company.Phone, Company.Email, Company.Website, Company.BankName, Company.BankAccountNumber);

            string title       = root.Element("Title").Value;
            string dateOfIssue = DateOfIssue.ToString(dateTimeFormat);

            if (typeCode == 1)
            {
                string duplicateTitle = " - DUPLIKAT";
                Number      = Number + duplicateTitle;
                dateOfIssue = DateTime.Now.ToString(dateTimeFormat);
            }

            title = string.Format(title, Number);

            string cityOfIssue    = root.Element("DatePlace").Value;
            string dateOfDelivery = DateOfDelivery.ToString(dateTimeFormat);

            cityOfIssue = string.Format(cityOfIssue, dateOfIssue, Company.InvoiceIssueCity, dateOfDelivery);



            string sellerBuyer = root.Element("SellerBuyer").Value;

            sellerBuyer = string.Format(sellerBuyer, Company.FullName, Company.FullAddress, Company.NIP, Contractor.FullName, Contractor.FullAddress, Contractor.NIP);

            header += cityOfIssue += title += sellerBuyer;

            string invoiceItemsTable   = root.Element("InvoiceItemsTableHeader").Value;
            string invoiceItemsSummary = root.Element("InvoiceItemTableSummary").Value;
            string invoiceItem         = root.Element("InvoiceItem").Value;

            int i = 1;

            foreach (InvoiceItem item in InvoiceItems)
            {
                string newItem = string.Format(invoiceItem, i, item.Name, item.UnitOfMeasureShortName, item.Quantity, item.Price.ToString("0.00"), item.TotalPrice.ToString("0.00"), item.VATValue.ToString("0.00"), item.TotalVATValue.ToString("0.00"), item.TotalPriceBrutto.ToString("0.00"));
                invoiceItemsTable += newItem;
                i++;
            }
            invoiceItemsSummary = string.Format(invoiceItemsSummary, TotalValue.ToString("0.00"), TotalVATValue.ToString("0.00"), TotalValueInclVat.ToString("0.00"));
            invoiceItemsTable  += invoiceItemsSummary;

            string taxTableHeader = root.Element("TaxTableHeader").Value;
            string tax            = root.Element("Tax").Value;

            tax = string.Format(tax, "23", TotalValue.ToString("0.00"), TotalVATValue.ToString("0.00"), TotalValueInclVat.ToString("0.00"));
            string taxTableSummary = root.Element("TaxTableSummary").Value;

            taxTableSummary = string.Format(taxTableSummary, TotalValue.ToString("0.00"), TotalVATValue.ToString("0.00"), TotalValueInclVat.ToString("0.00"));
            string taxTable = taxTableHeader + tax + taxTableSummary;

            string priceSummary = root.Element("PriceSummary").Value;

            priceSummary = string.Format(priceSummary, TotalValueInclVat.ToString("0.00"), getValueInWords(TotalValueInclVat));
            string paymentMethod = root.Element("PaymentMethod").Value;

            paymentMethod = string.Format(paymentMethod, PaymentMethod.Name, DateOfIssue.AddDays(PaymentMethod.DueTerm).ToString(dateTimeFormat));
            string issuer = root.Element("Issuer").Value;

            issuer = string.Format(issuer, Company.InvoiceIssuerName);
            string footer = paymentMethod + issuer;


            //string output = header + invoiceItemsTable + priceSummary + footer;
            string output = header + invoiceItemsTable + taxTable + priceSummary + footer;

            output = output.Replace("~^~^", "{{");
            output = output.Replace("^~^~", "}}");
            output = output.Replace("~^", "{");
            output = output.Replace("^~", "}");


            string time = DateTime.Now.ToFileTime().ToString();

            string outputFile = Tools.getHash(sellerBuyer + time);

            File.WriteAllText("tmp/" + outputFile + ".tex", output);

            Process process = new Process();

            process.StartInfo.WorkingDirectory = "tmp";
            process.StartInfo.FileName         = "pdflatex";
            process.StartInfo.Arguments        = outputFile + ".tex";
            process.Start();

            // wait to avoid FileNotFoundException
            //Task.Delay(5000);
            process.Dispose();
            return(outputFile + ".pdf");
        }