Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 59 additions & 62 deletions Core/Lib/PDF/PDFDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ abstract class PDFDocument extends PDFCore

const INVOICE_TOTALS_Y = 200;

private const COLOR_ACCENT = [0.15, 0.15, 0.15];
private const COLOR_HEADER = [0.95, 0.95, 0.95];
private const COLOR_ROW = [0.98, 0.98, 0.98];
private const COLOR_TEXT = [0.10, 0.10, 0.10];
private const COLOR_LINE = [0.75, 0.75, 0.75];
private const COLOR_TOTAL = [0.88, 0.88, 0.88];

/** @var FormatoDocumento */
protected $format;

Expand Down Expand Up @@ -178,6 +185,23 @@ protected function getLineHeaders(): array
];
}

protected function businessTableOptions(array $cols = [], bool $showHeadings = true): array
{
return [
'cols' => $cols,
'shaded' => $showHeadings ? 1 : 0,
'showHeadings' => $showHeadings ? 1 : 0,
'shadeCol' => self::COLOR_ROW,
'shadeHeadingCol' => self::COLOR_HEADER,
'textCol' => self::COLOR_TEXT,
'lineCol' => self::COLOR_LINE,
'innerLineThickness' => 0.35,
'outerLineThickness' => 0.7,
'rowGap' => 3,
'width' => $this->tableWidth
];
}

/**
* @param BusinessDocument $model
*
Expand Down Expand Up @@ -278,12 +302,7 @@ protected function insertBusinessDocBody($model)
$qrSubtitle = $this->pipe('qrSubtitleAfterLines', $model);

$headers = [];
$tableOptions = [
'cols' => [],
'shadeCol' => [0.95, 0.95, 0.95],
'shadeHeadingCol' => [0.95, 0.95, 0.95],
'width' => $this->tableWidth
];
$tableOptions = $this->businessTableOptions();

// fill headers and options with the line headers information
foreach ($this->getLineHeaders() as $key => $value) {
Expand Down Expand Up @@ -384,19 +403,14 @@ protected function insertBusinessDocFooter($model)
'taxsurcharge' => $this->i18n->trans('amount')
];
$taxRows = $this->getTaxesRows($model);
$taxTableOptions = [
'cols' => [
$taxTableOptions = $this->businessTableOptions([
'tax' => ['justification' => 'right'],
'taxbase' => ['justification' => 'right'],
'taxp' => ['justification' => 'right'],
'taxamount' => ['justification' => 'right'],
'taxsurchargep' => ['justification' => 'right'],
'taxsurcharge' => ['justification' => 'right']
],
'shadeCol' => [0.95, 0.95, 0.95],
'shadeHeadingCol' => [0.95, 0.95, 0.95],
'width' => $this->tableWidth
];
]);
if (count($taxRows) > 1) {
$this->removeEmptyCols($taxRows, $taxHeaders, Tools::number(0));
$this->pdf->ezTable($taxRows, $taxHeaders, '', $taxTableOptions);
Expand Down Expand Up @@ -433,8 +447,10 @@ protected function insertBusinessDocFooter($model)
]
];
$this->removeEmptyCols($rows, $headers, Tools::number(0));
$tableOptions = [
'cols' => [
if (isset($headers['total'])) {
$rows[0]['total'] = '<b>' . $rows[0]['total'] . '</b>';
}
$tableOptions = $this->businessTableOptions([
'subtotal' => ['justification' => 'right'],
'dto' => ['justification' => 'right'],
'dto-2' => ['justification' => 'right'],
Expand All @@ -443,12 +459,9 @@ protected function insertBusinessDocFooter($model)
'totalSurcharge' => ['justification' => 'right'],
'totalIrpf' => ['justification' => 'right'],
'totalSupplied' => ['justification' => 'right'],
'total' => ['justification' => 'right']
],
'shadeCol' => [0.95, 0.95, 0.95],
'shadeHeadingCol' => [0.95, 0.95, 0.95],
'width' => $this->tableWidth
];
'total' => ['justification' => 'right', 'bgcolor' => self::COLOR_TOTAL]
]);
$rows[0]['totalColor'] = [0, 0, 0];
$this->pdf->ezTable($rows, $headers, '', $tableOptions);

// receipts
Expand Down Expand Up @@ -510,17 +523,15 @@ protected function insertBusinessDocHeader($model)
}

// Título alineado a la izquierda y dentro del bloque
$this->pdf->ezText("\n" . $headerData['title'] . ': ' . $model->codigo, self::FONT_SIZE + 6, [
'justification' => 'left',
'left' => $startX - $this->pdf->ez['leftMargin'], // compensar margen
'width' => $leftBlockWidth
]);

// Línea divisoria solo del 80%
$lineY = $this->pdf->y;
$this->pdf->setStrokeColor(0, 0, 0);
$this->pdf->line($startX, $lineY - 8, $startX + $leftBlockWidth, $lineY - 8);
$this->pdf->y -= 10;
$title = $headerData['title'] . ': ' . Tools::fixHtml($model->codigo);
$barHeight = 28;
$barY = $startY - $barHeight;
$this->pdf->setColor(...self::COLOR_ACCENT);
$this->pdf->filledRectangle($startX, $barY, $leftBlockWidth, $barHeight);
$this->pdf->setColor(1, 1, 1);
$this->pdf->addText($startX + 10, $startY - 19, self::FONT_SIZE + 6, $title, $leftBlockWidth - 20, 'left');
$this->pdf->setColor(...self::COLOR_TEXT);
$this->pdf->y = $barY - 14;
$subject = $model->getSubject();
$tipoIdFiscal = empty($subject->tipoidfiscal) ? $this->i18n->trans('cifnif') : $subject->tipoidfiscal;
$serie = $model->getSerie();
Expand Down Expand Up @@ -551,15 +562,10 @@ protected function insertBusinessDocHeader($model)
}

// Opciones de la tabla
$tableWidth = $leftBlockWidth + 5;
$tableOptions = [
'width' => $tableWidth,
'showHeadings' => 0,
'shaded' => 0,
'lineCol' => [1, 1, 1],
'cols' => [],
'xPos' => $startX + ($tableWidth / 2) - 5, // Posicionar el centro de la tabla para que empiece en el margen izquierdo
];
$tableWidth = $leftBlockWidth;
$tableOptions = $this->businessTableOptions([], false);
$tableOptions['xPos'] = $startX + ($tableWidth / 2);
$tableOptions['width'] = $tableWidth;
$this->insertParallelTable($tableData, '', $tableOptions);
$this->pdf->ezText('');
$this->pdf->restoreState();
Expand All @@ -580,7 +586,9 @@ protected function insertBusinessDocHeader($model)
*/
protected function insertBusinessDocShipping($model)
{
$this->pdf->setColor(...self::COLOR_ACCENT);
$this->pdf->ezText("\n" . $this->i18n->trans('shipping-address') . "\n", self::FONT_SIZE + 6);
$this->pdf->setColor(...self::COLOR_TEXT);
$this->newLine();

$contacto = new Contacto();
Expand All @@ -595,13 +603,7 @@ protected function insertBusinessDocShipping($model)
['key' => $this->i18n->trans('tracking-code'), 'value' => $model->codigoenv]
];

$tableOptions = [
'width' => $this->tableWidth,
'showHeadings' => 0,
'shaded' => 0,
'lineCol' => [1, 1, 1],
'cols' => []
];
$tableOptions = $this->businessTableOptions([], false);
$this->insertParallelTable($tableData, '', $tableOptions);
$this->pdf->ezText('');
}
Expand Down Expand Up @@ -666,7 +668,9 @@ protected function insertHeader($idempresa = null)
}

$size = mb_strlen($company->nombre) > 20 ? self::FONT_SIZE + 2 : self::FONT_SIZE + 7;
$this->pdf->setColor(...self::COLOR_ACCENT);
$this->pdf->ezText(Tools::fixHtml($company->nombre), $size, ['justification' => 'right']);
$this->pdf->setColor(...self::COLOR_TEXT);
$address = $company->direccion;
$address .= empty($company->codpostal) ? "\n" : "\n" . $company->codpostal . ', ';
$address .= empty($company->ciudad) ? '' : $company->ciudad;
Expand All @@ -684,6 +688,9 @@ protected function insertHeader($idempresa = null)

$idLogo = $this->format->idlogo ?? $company->idlogo;
$this->insertCompanyLogo($idLogo);
$this->pdf->setStrokeColor(...self::COLOR_ACCENT);
$this->pdf->line(self::CONTENT_X, $this->pdf->y + 8, $this->tableWidth + self::CONTENT_X, $this->pdf->y + 8);
$this->pdf->setStrokeColor(0, 0, 0);
}

/**
Expand All @@ -701,15 +708,10 @@ protected function insertInvoicePayMethod($invoice)
['method' => $this->getBankData($invoice), 'expiration' => $expiration]
];

$tableOptions = [
'cols' => [
$tableOptions = $this->businessTableOptions([
'method' => ['justification' => 'left'],
'expiration' => ['justification' => 'right']
],
'shadeCol' => [0.95, 0.95, 0.95],
'shadeHeadingCol' => [0.95, 0.95, 0.95],
'width' => $this->tableWidth
];
]);
$this->pdf->ezText("\n");
$this->pdf->ezTable($rows, $headers, '', $tableOptions);
}
Expand Down Expand Up @@ -738,17 +740,12 @@ protected function insertInvoiceReceipts($invoice)
'vencimiento' => $receipt->pagado ? $this->i18n->trans('paid') : $receipt->vencimiento
];
}
$tableOptions = [
'cols' => [
$tableOptions = $this->businessTableOptions([
'numero' => ['justification' => 'center'],
'bank' => ['justification' => 'center'],
'importe' => ['justification' => 'right'],
'vencimiento' => ['justification' => 'right']
],
'shadeCol' => [0.95, 0.95, 0.95],
'shadeHeadingCol' => [0.95, 0.95, 0.95],
'width' => $this->tableWidth
];
]);
$this->pdf->ezText("\n");
$this->pdf->ezTable($rows, $headers, '', $tableOptions);
}
Expand Down
Loading