import { Content } from 'pdfmake/interfaces'; import { createHeader, createLabelText, formatText, generateColumns, getTable, hasValue, verticalSpacing, } from '../../../shared/PDF-functions'; import FormatTyp from '../../../shared/enums/common.enum'; import { Podmiot2, Podmiot2K } from '../../types/fa3.types'; import { generateAdres } from './Adres'; import { generateDaneIdentyfikacyjneTPodmiot1Dto } from './PodmiotDaneIdentyfikacyjneTPodmiot1Dto'; import { generateDaneKontaktowe } from './PodmiotDaneKontaktowe'; export function generatePodmiot2Podmiot2K(podmiot2: Podmiot2, podmiot2K: Podmiot2K): Content[] { const result: Content[] = createHeader('Nabywca'); let firstColumn: Content[] = []; let secondColumn: Content[] = []; firstColumn.push(createHeader('Dane identyfikacyjne'), createLabelText('Numer EORI: ', podmiot2.NrEORI)); if (podmiot2.DaneIdentyfikacyjne) { firstColumn.push(...generateDaneIdentyfikacyjneTPodmiot1Dto(podmiot2.DaneIdentyfikacyjne)); } if (podmiot2.DaneKontaktowe) { firstColumn.push(generateDaneKontaktowe(getTable(podmiot2.DaneKontaktowe))); } if (podmiot2.NrKlienta) { firstColumn.push(createLabelText('Numer klienta: ', podmiot2.NrKlienta)); } if (firstColumn.length) { result.push({ columns: [firstColumn, []], columnGap: 20, }); } firstColumn = generateCorrectedContent(podmiot2K, 'Treść korygowana'); secondColumn = generateCorrectedContent(podmiot2, 'Treść korygująca'); if (podmiot2.AdresKoresp) { secondColumn.push( formatText('Adres do korespondencji', [FormatTyp.Label, FormatTyp.LabelMargin]), generateAdres(podmiot2.AdresKoresp) ); } if (firstColumn.length || secondColumn.length) { result.push(generateColumns([firstColumn, secondColumn])); } if (result.length) { result.push(verticalSpacing(1)); } return result; } export function generateCorrectedContent(podmiot: Podmiot2 | Podmiot2K, header: string): Content[] { const result: Content[] = []; result.push(createHeader(header)); if (hasValue(podmiot.IDNabywcy)) { result.push(createLabelText('Identyfikator nabywcy: ', podmiot.IDNabywcy)); } if (podmiot.DaneIdentyfikacyjne) { result.push(...generateDaneIdentyfikacyjneTPodmiot1Dto(podmiot.DaneIdentyfikacyjne)); } if (podmiot.Adres) { result.push(formatText('Adres', [FormatTyp.Label, FormatTyp.LabelMargin]), generateAdres(podmiot.Adres)); } return result; }