@accounter/shaam6111-generator
Version:
Fully typed application that generates, parses, and validates SHAAM 6111 tax reports.
37 lines (36 loc) • 1.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateReport = generateReport;
const index_js_1 = require("../types/index.js");
const index_js_2 = require("../validation/index.js");
const generate_header_js_1 = require("./generate-header.js");
const generate_report_entries_js_1 = require("./generate-report-entries.js");
/**
* Generates a full report string for the SHAAM 6111 specification.
* @param reportData The ReportData object containing all sections of the report.
* @returns A string formatted according to the SHAAM 6111 specification, 8612 characters long.
*/
function generateReport(reportData, validate = true) {
// Validate the report data using the schema
if (validate) {
const validationResult = (0, index_js_2.validateData)(reportData);
if (!validationResult.isValid) {
throw new index_js_1.ValidationError('Validation failed', validationResult.errors);
}
}
// Generate the header section
const headerSection = (0, generate_header_js_1.generateHeaderRecord)(reportData.header);
// Add the 370-long fixture
const fixture = '0'.repeat(370);
// Generate the profit and loss section
const profitAndLossSection = (0, generate_report_entries_js_1.generateReportEntriesSection)(reportData.profitAndLoss);
// Generate the tax adjustment section
const taxAdjustmentSection = (0, generate_report_entries_js_1.generateReportEntriesSection)(reportData.taxAdjustment);
// Generate the balance sheet section (if exists)
const balanceSheetSection = reportData.balanceSheet
? (0, generate_report_entries_js_1.generateReportEntriesSection)(reportData.balanceSheet)
: ''.padEnd(2700, '0');
// Combine all sections into a single string
const report = headerSection + fixture + profitAndLossSection + taxAdjustmentSection + balanceSheetSection;
return report;
}