public async Task <IViewComponentResult> InvokeAsync() { string MyView = "Default"; ViewData["Month"] = new SelectList(Tools.getMonthsDictionary(), "Key", "Value"); ViewData["Year"] = new SelectList(Tools.getYearsList()); return(View(MyView, new IncomeTax(DateTime.Now.Year, DateTime.Now.Month - 1))); }
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"); }
// 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"); }