private async Task GenerateContributionsJOPPD(DateTime formDate, SalaryBreakdown salaryBreakdown, DateTime formStart, DateTime formEnd) { var JOPPDNumber = JOPPDHelper.GetJOPPDNumber(formDate); var fileName = $"doprinosi-{JOPPDNumber}-{formDate:yyyy-MM-dd}.xml"; var fileFullPath = Path.Combine(OutputPath, fileName); CopyTemplate("ContributionsJOPPDTemplate.xml", fileName); XElement newJOPPD; using (var fileStream = new FileStream(fileFullPath, FileMode.Open)) { var cts = new CancellationTokenSource(); newJOPPD = await XElement.LoadAsync(fileStream, LoadOptions.None, cts.Token); } var metadata = newJOPPD.Element(MetadataNamespace + "Metapodaci"); metadata.Element(MetadataNamespace + "Datum").SetValue(formDate.ToString("yyyy-MM-ddTHH:mm:ss")); metadata.Element(MetadataNamespace + "Identifikator").SetValue(Guid.NewGuid()); var pageA = newJOPPD.Element(JOPPDNamespace + "StranaA"); pageA.SetElementValue(JOPPDNamespace + "DatumIzvjesca", formDate.ToString("yyyy-MM-dd")); pageA.SetElementValue(JOPPDNamespace + "OznakaIzvjesca", JOPPDNumber); var contributions = pageA.Element(JOPPDNamespace + "Doprinosi"); contributions.Element(JOPPDNamespace + "GeneracijskaSolidarnost").SetElementValue(JOPPDNamespace + "P1", salaryBreakdown.PensionPillar1Contribution); contributions.Element(JOPPDNamespace + "KapitaliziranaStednja").SetElementValue(JOPPDNamespace + "P1", salaryBreakdown.PensionPillar2Contribution); var healthInsurance = contributions.Element(JOPPDNamespace + "ZdravstvenoOsiguranje"); healthInsurance.SetElementValue(JOPPDNamespace + "P1", salaryBreakdown.HealthInsuranceContribution); healthInsurance.SetElementValue(JOPPDNamespace + "P2", salaryBreakdown.WorkSafetyContribution); contributions.Element(JOPPDNamespace + "Zaposljavanje").SetElementValue(JOPPDNamespace + "P1", salaryBreakdown.EmploymentContribution); var pageB = newJOPPD.Element(JOPPDNamespace + "StranaB") .Element(JOPPDNamespace + "Primatelji") .Element(JOPPDNamespace + "P"); pageB.SetElementValue(JOPPDNamespace + "P101", formStart.ToString("yyyy-MM-dd")); pageB.SetElementValue(JOPPDNamespace + "P102", formEnd.ToString("yyyy-MM-dd")); pageB.SetElementValue(JOPPDNamespace + "P12", salaryBreakdown.Gross); pageB.SetElementValue(JOPPDNamespace + "P121", salaryBreakdown.PensionPillar1Contribution); pageB.SetElementValue(JOPPDNamespace + "P122", salaryBreakdown.PensionPillar2Contribution); pageB.SetElementValue(JOPPDNamespace + "P123", salaryBreakdown.HealthInsuranceContribution); pageB.SetElementValue(JOPPDNamespace + "P124", salaryBreakdown.WorkSafetyContribution); pageB.SetElementValue(JOPPDNamespace + "P125", salaryBreakdown.EmploymentContribution); pageB.SetElementValue(JOPPDNamespace + "P17", salaryBreakdown.Gross); using (var fileStream = new FileStream(fileFullPath, FileMode.Create)) { var cts = new CancellationTokenSource(); await newJOPPD.SaveAsync(fileStream, SaveOptions.None, cts.Token); } }
private async Task GenerateTaxAndSurtaxJOPPD(DateTime formDate, SalaryBreakdown salaryBreakdown, DateTime formStart, DateTime formEnd) { var JOPPDNumber = JOPPDHelper.GetJOPPDNumber(formDate); var fileName = $"porezIPrirez-{JOPPDNumber}-{formDate:yyyy-MM-dd}.xml"; var fileFullPath = Path.Combine(OutputPath, fileName); CopyTemplate("TaxAndSurtaxJOPPDTemplate.xml", fileName); XElement newJOPPD; using (var fileStream = new FileStream(fileFullPath, FileMode.Open)) { var cts = new CancellationTokenSource(); newJOPPD = await XElement.LoadAsync(fileStream, LoadOptions.None, cts.Token); } var metadata = newJOPPD.Element(MetadataNamespace + "Metapodaci"); metadata.Element(MetadataNamespace + "Datum").SetValue(formDate.ToString("yyyy-MM-ddTHH:mm:ss")); metadata.Element(MetadataNamespace + "Identifikator").SetValue(Guid.NewGuid()); var pageA = newJOPPD.Element(JOPPDNamespace + "StranaA"); pageA.SetElementValue(JOPPDNamespace + "DatumIzvjesca", formDate.ToString("yyyy-MM-dd")); pageA.SetElementValue(JOPPDNamespace + "OznakaIzvjesca", JOPPDNumber); var tax = pageA.Element(JOPPDNamespace + "PredujamPoreza"); tax.SetElementValue(JOPPDNamespace + "P1", salaryBreakdown.TaxTotal); tax.SetElementValue(JOPPDNamespace + "P11", salaryBreakdown.TaxTotal); var pageB = newJOPPD.Element(JOPPDNamespace + "StranaB") .Element(JOPPDNamespace + "Primatelji") .Element(JOPPDNamespace + "P"); pageB.SetElementValue(JOPPDNamespace + "P101", formStart.ToString("yyyy-MM-dd")); pageB.SetElementValue(JOPPDNamespace + "P102", formEnd.ToString("yyyy-MM-dd")); pageB.SetElementValue(JOPPDNamespace + "P11", salaryBreakdown.Gross); pageB.SetElementValue(JOPPDNamespace + "P132", salaryBreakdown.ContributionsFrom); pageB.SetElementValue(JOPPDNamespace + "P133", salaryBreakdown.Income); pageB.SetElementValue(JOPPDNamespace + "P134", Math.Min(salaryBreakdown.NontaxableAmount, salaryBreakdown.Income)); pageB.SetElementValue(JOPPDNamespace + "P135", salaryBreakdown.TaxableAmount); pageB.SetElementValue(JOPPDNamespace + "P141", salaryBreakdown.Tax); pageB.SetElementValue(JOPPDNamespace + "P142", salaryBreakdown.Surtax); pageB.SetElementValue(JOPPDNamespace + "P162", salaryBreakdown.Net); using (var fileStream = new FileStream(fileFullPath, FileMode.Create)) { var cts = new CancellationTokenSource(); await newJOPPD.SaveAsync(fileStream, SaveOptions.None, cts.Token); } }
private async Task GenerateContributionsJOPPD(DateTime date, SalaryBreakdown salaryBreakdown, DateTime formStart, DateTime formEnd) { var JOPPDNumber = JOPPDHelper.GetJOPPDNumber(date); var fileName = $"doprinosi-{JOPPDNumber}-{date:yyyy-MM-dd}.xml"; var fileFullPath = Path.Combine(OutputPath, fileName); CopyTemplate("ContributionsJOPPDTemplate.xml", fileName); XElement newJOPPD; using (var fileStream = new FileStream(fileFullPath, FileMode.Open)) { var cts = new CancellationTokenSource(); newJOPPD = await XElement.LoadAsync(fileStream, LoadOptions.None, cts.Token); } newJOPPD.Element(MetadataNamespace + "Metapodaci") .Element(MetadataNamespace + "Datum") .SetValue(date.ToString("yyyy-MM-ddTHH:mm:ss")); var pageA = newJOPPD.Element(JOPPDNamespace + "StranaA"); pageA.SetElementValue(JOPPDNamespace + "DatumIzvjesca", date.ToString("yyyy-MM-dd")); pageA.SetElementValue(JOPPDNamespace + "OznakaIzvjesca", JOPPDNumber); var doprinosi = pageA.Element(JOPPDNamespace + "Doprinosi"); doprinosi.Element(JOPPDNamespace + "GeneracijskaSolidarnost").SetElementValue(JOPPDNamespace + "P1", salaryBreakdown.PensionPillar1Contribution); doprinosi.Element(JOPPDNamespace + "KapitaliziranaStednja").SetElementValue(JOPPDNamespace + "P1", salaryBreakdown.PensionPillar2Contribution); var pageB = newJOPPD.Element(JOPPDNamespace + "StranaB") .Element(JOPPDNamespace + "Primatelji") .Element(JOPPDNamespace + "P"); pageB.SetElementValue(JOPPDNamespace + "P101", formStart.ToString("yyyy-MM-dd")); pageB.SetElementValue(JOPPDNamespace + "P102", formEnd.ToString("yyyy-MM-dd")); pageB.SetElementValue(JOPPDNamespace + "P12", salaryBreakdown.GrossTotal); pageB.SetElementValue(JOPPDNamespace + "P121", salaryBreakdown.PensionPillar1Contribution); pageB.SetElementValue(JOPPDNamespace + "P122", salaryBreakdown.PensionPillar2Contribution); pageB.SetElementValue(JOPPDNamespace + "P17", salaryBreakdown.GrossTotal); using (var fileStream = new FileStream(fileFullPath, FileMode.Create)) { var cts = new CancellationTokenSource(); await newJOPPD.SaveAsync(fileStream, SaveOptions.None, cts.Token); } }
private async Task GeneratePayment(DateTime formDate, DividendBreakdown dividendBreakdown) { var JOPPDNumber = JOPPDHelper.GetJOPPDNumber(formDate); var paymentInfo = new PaymentInfo(dividendBreakdown.TaxTotal, PaymentFilePath); paymentInfo.Receiver.Reference = $"{paymentInfo.Receiver.Reference}{JOPPDNumber}"; var payment2DBarcode = await this.payment2DBarCodeGenerator.GeneratePayment2DBarcode(paymentInfo); // TODO: see if this can be made async using (var fs = new FileStream($"{OutputPath}/payments.pdf", FileMode.Create, FileAccess.Write, FileShare.None)) using (var doc = new Document()) using (var writer = PdfWriter.GetInstance(doc, fs)) { doc.Open(); doc.Add(new Paragraph($"{formDate.ToString("yyyy-MM-dd")} dividend tax and surtax payment:")); Image image = Image.GetInstance(payment2DBarcode); image.ScaleToFit(300f, 60f); doc.Add(image); doc.Close(); } }
private async Task GeneratePayments(DateTime date, DateTime salaryMonth, SalaryBreakdown salaryBreakdown) { var JOPPDNumber = JOPPDHelper.GetJOPPDNumber(date); var contributionsPillar1PaymentBarcodeTask = GenerateContributionsPillar1Barcode(JOPPDNumber, salaryMonth, salaryBreakdown); var contributionsPillar2PaymentBarcodeTask = GenerateContributionsPillar2Barcode(JOPPDNumber, salaryMonth, salaryBreakdown); var taxAndSurtaxPaymentBarcodeTask = GenerateTaxAndSurtaxBarcode(JOPPDNumber, salaryMonth, salaryBreakdown); // TODO: see if this can be made async using (var fs = new FileStream($"{OutputPath}/payments.pdf", FileMode.Create, FileAccess.Write, FileShare.None)) using (var doc = new Document()) using (var writer = PdfWriter.GetInstance(doc, fs)) { doc.Open(); doc.Add(new Paragraph($"Salary for {salaryMonth:MM/yyyy} - pension pillar 1 contribution:")); var pillar1PaymentBarcodeImage = Image.GetInstance(await contributionsPillar1PaymentBarcodeTask); pillar1PaymentBarcodeImage.ScaleToFit(300f, 60f); doc.Add(pillar1PaymentBarcodeImage); doc.Add(new Paragraph("\n\n")); doc.Add(new Paragraph($"Salary for {salaryMonth:MM/yyyy} - pension pillar 2 contribution:")); var pillar2PaymentBarcodeImage = Image.GetInstance(await contributionsPillar2PaymentBarcodeTask); pillar2PaymentBarcodeImage.ScaleToFit(300f, 60f); doc.Add(pillar2PaymentBarcodeImage); doc.Add(new Paragraph("\n\n")); doc.Add(new Paragraph($"Salary for {salaryMonth:MM/yyyy} - tax and surtax:")); var taxAndSurtaxPaymentBarcodeImage = Image.GetInstance(await taxAndSurtaxPaymentBarcodeTask); taxAndSurtaxPaymentBarcodeImage.ScaleToFit(300f, 60f); doc.Add(taxAndSurtaxPaymentBarcodeImage); doc.Close(); } }
private async Task GenerateJOPPD(DateTime date, DividendBreakdown dividendBreakdown, DateTime formStart, DateTime formEnd) { var JOPPDNumber = JOPPDHelper.GetJOPPDNumber(date); var fileName = $"dividend-{JOPPDNumber}-{date.ToString("yyyy-MM-dd")}.xml"; var fileFullPath = Path.Combine(OutputPath, fileName); CopyTemplate("DividendJOPPDTemplate.xml", fileName); var cts = new CancellationTokenSource(); var newJOPPD = await XElement.LoadAsync(new FileStream(fileFullPath, FileMode.Open), LoadOptions.None, cts.Token); newJOPPD.Element(MetadataNamespace + "Metapodaci") .Element(MetadataNamespace + "Datum") .SetValue(date.ToString("yyyy-MM-ddTHH:mm:ss")); var pageA = newJOPPD.Element(JOPPDNamespace + "StranaA"); pageA.SetElementValue(JOPPDNamespace + "DatumIzvjesca", date.ToString("yyyy-MM-dd")); pageA.SetElementValue(JOPPDNamespace + "OznakaIzvjesca", JOPPDNumber); pageA.Element(JOPPDNamespace + "PredujamPoreza").SetElementValue(JOPPDNamespace + "P2", dividendBreakdown.TaxTotal); var pageB = newJOPPD.Element(JOPPDNamespace + "StranaB") .Element(JOPPDNamespace + "Primatelji") .Element(JOPPDNamespace + "P"); pageB.SetElementValue(JOPPDNamespace + "P101", formStart.ToString("yyyy-MM-dd")); pageB.SetElementValue(JOPPDNamespace + "P102", formEnd.ToString("yyyy-MM-dd")); pageB.SetElementValue(JOPPDNamespace + "P11", dividendBreakdown.Gross); pageB.SetElementValue(JOPPDNamespace + "P133", dividendBreakdown.Gross); pageB.SetElementValue(JOPPDNamespace + "P135", dividendBreakdown.Gross); pageB.SetElementValue(JOPPDNamespace + "P141", dividendBreakdown.Tax); pageB.SetElementValue(JOPPDNamespace + "P142", dividendBreakdown.Surtax); pageB.SetElementValue(JOPPDNamespace + "P162", dividendBreakdown.Net); await newJOPPD.SaveAsync(new FileStream(fileFullPath, FileMode.Create), SaveOptions.None, cts.Token); }
private async Task GeneratePayments(DateTime formDate, DateTime salaryMonth, SalaryBreakdown salaryBreakdown) { var JOPPDNumber = JOPPDHelper.GetJOPPDNumber(formDate); // TODO: handle this better than with these ifs Task <byte[]> contributionsPillar1PaymentBarcodeTask = null; if (salaryBreakdown.PensionPillar1Contribution > 0) { contributionsPillar1PaymentBarcodeTask = GenerateContributionsPillar1Barcode(JOPPDNumber, salaryMonth, salaryBreakdown); } Task <byte[]> contributionsPillar2PaymentBarcodeTask = null; if (salaryBreakdown.PensionPillar2Contribution > 0) { contributionsPillar2PaymentBarcodeTask = GenerateContributionsPillar2Barcode(JOPPDNumber, salaryMonth, salaryBreakdown); } Task <byte[]> taxAndSurtaxPaymentBarcodeTask = null; if (salaryBreakdown.TaxTotal > 0) { taxAndSurtaxPaymentBarcodeTask = GenerateTaxAndSurtaxBarcode(JOPPDNumber, salaryMonth, salaryBreakdown); } Task <byte[]> healthInsuranceContributionPaymentBarcodeTask = null; if (salaryBreakdown.HealthInsuranceContribution > 0) { healthInsuranceContributionPaymentBarcodeTask = GenerateHealthInsuranceContributionBarcode(JOPPDNumber, salaryMonth, salaryBreakdown); } Task <byte[]> workSafetyContributionPaymentBarcodeTask = null; if (salaryBreakdown.WorkSafetyContribution > 0) { workSafetyContributionPaymentBarcodeTask = GenerateWorkSafetyContributionBarcode(JOPPDNumber, salaryMonth, salaryBreakdown); } Task <byte[]> employmentContributionPaymentBarcodeTask = null; if (salaryBreakdown.EmploymentContribution > 0) { employmentContributionPaymentBarcodeTask = GenerateEmploymentContributionBarcode(JOPPDNumber, salaryMonth, salaryBreakdown); } // TODO: see if this can be made async using (var fs = new FileStream($"{OutputPath}/payments.pdf", FileMode.Create, FileAccess.Write, FileShare.None)) using (var doc = new Document()) using (var writer = PdfWriter.GetInstance(doc, fs)) { doc.Open(); if (contributionsPillar1PaymentBarcodeTask != null) { doc.Add(new Paragraph($"Salary for {salaryMonth:MM/yyyy} - pension pillar 1 contribution:")); var pillar1PaymentBarcodeImage = Image.GetInstance(await contributionsPillar1PaymentBarcodeTask); pillar1PaymentBarcodeImage.ScaleToFit(300f, 60f); doc.Add(pillar1PaymentBarcodeImage); doc.Add(new Paragraph("\n\n")); } if (contributionsPillar2PaymentBarcodeTask != null) { doc.Add(new Paragraph($"Salary for {salaryMonth:MM/yyyy} - pension pillar 2 contribution:")); var pillar2PaymentBarcodeImage = Image.GetInstance(await contributionsPillar2PaymentBarcodeTask); pillar2PaymentBarcodeImage.ScaleToFit(300f, 60f); doc.Add(pillar2PaymentBarcodeImage); doc.Add(new Paragraph("\n\n")); } if (taxAndSurtaxPaymentBarcodeTask != null) { doc.Add(new Paragraph($"Salary for {salaryMonth:MM/yyyy} - tax and surtax:")); var taxAndSurtaxPaymentBarcodeImage = Image.GetInstance(await taxAndSurtaxPaymentBarcodeTask); taxAndSurtaxPaymentBarcodeImage.ScaleToFit(300f, 60f); doc.Add(taxAndSurtaxPaymentBarcodeImage); doc.Add(new Paragraph("\n\n")); } if (healthInsuranceContributionPaymentBarcodeTask != null) { doc.Add(new Paragraph($"Salary for {salaryMonth:MM/yyyy} - health insurance:")); var healthInsuranceContributionPaymentBarcodeImage = Image.GetInstance(await healthInsuranceContributionPaymentBarcodeTask); healthInsuranceContributionPaymentBarcodeImage.ScaleToFit(300f, 60f); doc.Add(healthInsuranceContributionPaymentBarcodeImage); doc.Add(new Paragraph("\n\n")); } if (workSafetyContributionPaymentBarcodeTask != null) { doc.Add(new Paragraph($"Salary for {salaryMonth:MM/yyyy} - work safety:")); var workSafetyContributionPaymentBarcodeImage = Image.GetInstance(await workSafetyContributionPaymentBarcodeTask); workSafetyContributionPaymentBarcodeImage.ScaleToFit(300f, 60f); doc.Add(workSafetyContributionPaymentBarcodeImage); doc.Add(new Paragraph("\n\n")); } if (employmentContributionPaymentBarcodeTask != null) { doc.Add(new Paragraph($"Salary for {salaryMonth:MM/yyyy} - employment contribution:")); var employmentContributionPaymentBarcodeImage = Image.GetInstance(await employmentContributionPaymentBarcodeTask); employmentContributionPaymentBarcodeImage.ScaleToFit(300f, 60f); doc.Add(employmentContributionPaymentBarcodeImage); doc.Add(new Paragraph("\n\n")); } doc.Close(); } }