Load xml
This commit is contained in:
parent
76acd42084
commit
1109c9fce6
@ -161,6 +161,11 @@
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="state-irs-submission.xml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@ -6,6 +6,8 @@ namespace FormCompareTools
|
||||
{
|
||||
public string FormName { get; set; }
|
||||
public string MainTableName { get; set; }
|
||||
public string XmlFormName { get; set; }
|
||||
public Dictionary<string, string> Columns { get; set; }
|
||||
public Dictionary<string, string> XmlColumns { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,8 +7,10 @@
|
||||
public string PrimarySsn { get; set; }
|
||||
public string FormName { get; set; }
|
||||
public string TestName { get; set; }
|
||||
public string BatchXml { get; set; }
|
||||
public string LinesColumn { get; set; } = "A";
|
||||
public string DatabaseColumn { get; set; } = "E";
|
||||
public string BatchXmColumn { get; set; } = "F";
|
||||
public int FirstRow { get; set; }
|
||||
public int LastRow { get; set; }
|
||||
public string PrimarySsnCell { get; set; } = "C1";
|
||||
|
||||
@ -5,7 +5,11 @@ using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using System.Xml.XPath;
|
||||
|
||||
namespace FormCompareTools
|
||||
{
|
||||
@ -52,7 +56,8 @@ namespace FormCompareTools
|
||||
return null;
|
||||
}
|
||||
|
||||
static void Main(string[] args){
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var inputParametersJson = GetParametersFile(args);
|
||||
var inputFormParametersJson = GetFormParametersFile(args);
|
||||
|
||||
@ -74,6 +79,8 @@ namespace FormCompareTools
|
||||
formParameters = JsonSerializer.Deserialize<FormParameters>(fs);
|
||||
}
|
||||
|
||||
var xmlFormData = LoadBatchXml(inputParameters, formParameters);
|
||||
|
||||
var sheetName = $"{inputParameters.FormName}_{inputParameters.TestName}";
|
||||
|
||||
var wb = new XLWorkbook(inputParameters.ExcelTemplate);
|
||||
@ -99,6 +106,7 @@ namespace FormCompareTools
|
||||
for (int i = inputParameters.FirstRow; i <= inputParameters.LastRow; i++)
|
||||
{
|
||||
var databaseValueCell = $"{inputParameters.DatabaseColumn}{i}";
|
||||
var batchXmlValueCell = $"{inputParameters.BatchXmColumn}{i}";
|
||||
var lineCell = $"{inputParameters.LinesColumn}{i}";
|
||||
var lineNumber = GetCellValue(worksheet, lineCell);
|
||||
|
||||
@ -118,6 +126,25 @@ namespace FormCompareTools
|
||||
worksheet.Cell(databaseValueCell).Value = rawValue.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
if (formParameters.XmlColumns.TryGetValue(lineNumber, out var xmlElementName))
|
||||
{
|
||||
if (xmlFormData.TryGetValue(xmlElementName, out var rawXmlValue))
|
||||
{
|
||||
if (int.TryParse(rawXmlValue.ToString(), out var intValue))
|
||||
{
|
||||
worksheet.Cell(batchXmlValueCell).Value = intValue;
|
||||
}
|
||||
else if (decimal.TryParse(rawXmlValue.ToString(), out var decimalValue))
|
||||
{
|
||||
worksheet.Cell(batchXmlValueCell).Value = decimalValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
worksheet.Cell(batchXmlValueCell).Value = rawXmlValue.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
worksheet.Cell(inputParameters.PrimarySsnCell).Value = inputParameters.PrimarySsn;
|
||||
@ -134,6 +161,25 @@ namespace FormCompareTools
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> LoadBatchXml(InputParameters inputParameters, FormParameters formParameters)
|
||||
{
|
||||
var xml = XDocument.Load(inputParameters.BatchXml);
|
||||
XNamespace ns = "http://www.irs.gov/efile";
|
||||
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xml.CreateReader().NameTable);
|
||||
namespaceManager.AddNamespace("ns", ns.NamespaceName);
|
||||
XElement xmlFormNode = xml.XPathSelectElement($"//ns:{formParameters.XmlFormName}", namespaceManager);
|
||||
|
||||
var xmlFormData = new Dictionary<string, string> { };
|
||||
if (xmlFormNode != null)
|
||||
{
|
||||
// Convert descendants to dictionary
|
||||
xmlFormData = xmlFormNode
|
||||
.Descendants()
|
||||
.ToDictionary(x => x.Name.LocalName, x => x.Value);
|
||||
}
|
||||
return xmlFormData;
|
||||
}
|
||||
|
||||
private static string GetCellValue(IXLWorksheet worksheet, string lineCell)
|
||||
{
|
||||
var lineNumber = string.Empty;
|
||||
|
||||
Binary file not shown.
@ -1,8 +1,13 @@
|
||||
{
|
||||
"FormName": "nm_pit_1",
|
||||
"XmlFormName": "NMPIT1",
|
||||
"MainTableName": "nm_frm_pit_1",
|
||||
"Columns": {
|
||||
"line_1": "number_of_fed_exemptions",
|
||||
"line_2": "fed_deduction_amt"
|
||||
},
|
||||
"XmlColumns": {
|
||||
"line_1": "NumberOfFedExemptions",
|
||||
"line_2": "FedDeductionAmt"
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,10 +2,12 @@
|
||||
"ExcelTemplate": "nm_forms.xlsx",
|
||||
"ExcelOutput": "C:\\temp\\nm_forms_{0}.xlsx",
|
||||
"PrimarySsn": "226966190",
|
||||
"BatchXml": "state-irs-submission.xml",
|
||||
"FormName": "nm_pit_1",
|
||||
"TestName": "test_1",
|
||||
"LinesColumn": "A",
|
||||
"DatabaseColumn": "E",
|
||||
"BatchXmColumn": "F",
|
||||
"FirstRow": 4,
|
||||
"LastRow": 8,
|
||||
"PrimarySsnCell": "C1"
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Return returnVersion="2023v5.2" xmlns="http://www.irs.gov/efile" xmlns:efile="http://www.irs.gov/efile">
|
||||
<ReturnData documentCnt="2">
|
||||
<NMPIT1 documentId="NMPIT10001" softwareId="23017922">
|
||||
<NumberOfFedExemptions>1</NumberOfFedExemptions>
|
||||
<FedDeductionAmt>300</FedDeductionAmt>
|
||||
</NMPIT1>
|
||||
</ReturnData>
|
||||
</Return>
|
||||
Loading…
x
Reference in New Issue
Block a user