UNPKG

@accounter/shaam6111-generator

Version:

Fully typed application that generates, parses, and validates SHAAM 6111 tax reports.

29 lines (28 loc) 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateReportEntriesSection = generateReportEntriesSection; const generation_utils_js_1 = require("../utils/generation-utils.js"); /** * Generates a fixed-width formatted string for the report entries section. * @param entries An array of ReportEntry objects. * @remarks If more than 150 entries are provided, only the first 150 will be included in the output. * @returns A string formatted according to the specification, 2700 characters long. */ function generateReportEntriesSection(entries) { const formattedEntries = entries.map(entry => { const code = (0, generation_utils_js_1.padOrTrim)(entry.code.toFixed(0), 5); const isNegative = entry.amount < 0; const absAmount = (0, generation_utils_js_1.padOrTrim)(Math.abs(entry.amount).toFixed(0), isNegative ? 12 : 13); const amount = ((isNegative ? '-' : '') + absAmount).slice(0, 13); return code + amount; }); // Add phantom records if less than 150 entries const phantomRecord = '000000000000000000'; while (formattedEntries.length < 150) { formattedEntries.push(phantomRecord); } // Join all entries into a single string const result = formattedEntries.join(''); // Ensure the result is exactly 2700 characters long return result.slice(0, 2700); }