fix ui on multi line subtotal & fix text contrast (#35449)

* fix ui on multi line subtotal & fix text contrast

* extract subtotal pdf logic

* phpcs

* lint

* lint

* refactor

* phpcs

* phpcs

* phpcs

* Update pdf.lib.php

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
Dylan Bourdere 2025-09-23 23:24:37 +02:00 committed by GitHub
parent 35f6a98665
commit 59ec1a2811
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 76 additions and 69 deletions

View file

@ -2511,7 +2511,7 @@ function pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails = 0)
*
* @param Commande|Facture|Propal|FactureFournisseur|CommandeFournisseur|SupplierProposal $object Object
* @param int $i Current line number
* @param Translate $outputlangs Object langs for output
* @param Translate $outputlangs Object langs for output
* @param int<0,2> $hidedetails Hide value (0 = no, 1 = yes, 2 = just special lines)
* @return string Return total of line incl tax
*/
@ -2838,3 +2838,74 @@ function pdfExtractMetadata($file, $field = 'Keywords')
return "ERROR: FAILED TO READ PDF";
}
}
/**
* Render subtotals line with a colored background and adapted text color .
*
* @param TCPDF $pdf PDF instance
* @param CommonDocGenerator $generator Generator object
* @param float $curY Current Y position
* @param CommonObject $object Object containing lines
* @param int $i Current line number
* @param Translate $outputlangs Output language object
* @param int $hideref Hide reference
* @param int $hidedesc Hide description
* @param array<int, int> $bgColor RGB color array [R,G,B]
* @param bool $isSubtotal Whether this is a subtotal line
* @param bool $applySubtotalLogic Whether to apply subtotal specific logic
*
* @return void
*/
function pdf_render_subtotals(
TCPDF $pdf,
CommonDocGenerator $generator,
float $curY,
CommonObject $object,
int $i,
Translate $outputlangs,
int $hideref,
int $hidedesc,
array $bgColor,
bool $isSubtotal = false,
bool $applySubtotalLogic = true
) {
$savePage = $pdf->getPage();
$saveX = $pdf->GetX();
$prevAlign = $generator->cols['desc']['content']['align'];
if ($isSubtotal && $applySubtotalLogic && $object->lines[$i]->qty < 0) {
$outputlangs->load("subtotals");
$object->lines[$i]->desc = $outputlangs->trans("SubtotalOf", $object->lines[$i]->desc);
$generator->cols['desc']['content']['align'] = ($prevAlign === 'L') ? 'R' : 'L';
}
$pdf->startTransaction();
$pdf->SetXY($saveX, $curY);
$generator->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
$pageAfter = $pdf->getPage();
$yAfter = $pdf->GetY();
$pdf->rollbackTransaction(true);
$pdf->SetFillColor($bgColor[0], $bgColor[1], $bgColor[2]);
$width = $generator->page_largeur - $generator->marge_droite - $generator->marge_gauche;
$pdf->SetXY($generator->marge_gauche, $curY);
if ($pageAfter === $savePage) {
$pdf->MultiCell($width, max(0, $yAfter - $curY), '', 0, '', true);
} else {
$pdf->MultiCell($width, $pdf->getPageHeight() - $pdf->getBreakMargin() - $curY, '', 0, '', true);
$pdf->setPage($pageAfter);
$pdf->SetXY($generator->marge_gauche, $pdf->getMargins()['top']);
$pdf->MultiCell($width, max(0, $yAfter - $pdf->getMargins()['top']), '', 0, '', true);
$pdf->setPage($savePage);
}
$pdf->SetTextColor(colorIsLight(implode(',', $bgColor)));
$pdf->SetXY($saveX, $curY);
$generator->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
$generator->setAfterColsLinePositionsData('desc', $pdf->GetY(), $pdf->getPage());
$generator->cols['desc']['content']['align'] = $prevAlign;
}

View file

@ -662,23 +662,7 @@ class pdf_eratosthene extends ModelePDFCommandes
$this->setAfterColsLinePositionsData('desc', $pdf->GetY(), $pdf->getPage());
} else {
$bg_color = colorStringToArray(getDolGlobalString("SUBTOTAL_BACK_COLOR_LEVEL_".abs($object->lines[$i]->qty)));
$pdf->SetFillColor($bg_color[0], $bg_color[1], $bg_color[2]);
$pdf->SetXY($pdf->GetX(), $curY);
$pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->marge_gauche, 6, '', 0, '', true);
$previous_align = array();
$previous_align['align'] = $this->cols['desc']['content']['align'];
if ($object->lines[$i]->qty < 0) {
$langs->load("subtotals");
$object->lines[$i]->desc = $langs->trans("SubtotalOf", $object->lines[$i]->desc);
if ($previous_align['align'] == 'L') {
$this->cols['desc']['content']['align'] = 'R';
} elseif ($previous_align['align'] == 'R') {
$this->cols['desc']['content']['align'] = 'L';
}
}
$this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
$this->setAfterColsLinePositionsData('desc', $pdf->GetY(), $pdf->getPage());
$this->cols['desc']['content']['align'] = $previous_align['align']; // Re align if we printed a subtotal ligne
pdf_render_subtotals($pdf, $this, $curY, $object, $i, $outputlangs, $hideref, $hidedesc, $bg_color, true, true);
}
}

View file

@ -635,23 +635,7 @@ class pdf_espadon extends ModelePdfExpedition
if ($this->getColumnStatus('desc')) {
if ($object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
$bg_color = colorStringToArray(getDolGlobalString("SUBTOTAL_BACK_COLOR_LEVEL_".abs($object->lines[$i]->qty)));
$pdf->SetFillColor($bg_color[0], $bg_color[1], $bg_color[2]);
$pdf->SetXY($pdf->GetX() + 1, $curY);
$pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->marge_gauche - 2, 6, '', 0, '', true);
$previous_align = array();
$previous_align['align'] = $this->cols['desc']['content']['align'];
if ($object->lines[$i]->qty < 0) {
$langs->load("subtotals");
$object->lines[$i]->desc = $langs->trans("SubtotalOf", $object->lines[$i]->desc);
if ($previous_align['align'] == 'L') {
$this->cols['desc']['content']['align'] = 'R';
} elseif ($previous_align['align'] == 'R') {
$this->cols['desc']['content']['align'] = 'L';
}
}
$this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
$this->setAfterColsLinePositionsData('desc', $pdf->GetY(), $pdf->getPage());
$this->cols['desc']['content']['align'] = $previous_align['align']; // Re align if we printed a subtotal ligne
pdf_render_subtotals($pdf, $this, $curY, $object, $i, $outputlangs, $hideref, $hidedesc, $bg_color, true, true);
} else {
$pdf->startTransaction();

View file

@ -805,23 +805,7 @@ class pdf_sponge extends ModelePDFFactures
$this->setAfterColsLinePositionsData('desc', $pdf->GetY(), $pdf->getPage());
} else {
$bg_color = colorStringToArray(getDolGlobalString("SUBTOTAL_BACK_COLOR_LEVEL_".abs($object->lines[$i]->qty)));
$pdf->SetFillColor($bg_color[0], $bg_color[1], $bg_color[2]);
$pdf->SetXY($pdf->GetX(), $curY);
$pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->marge_gauche, 6, '', 0, '', true);
$previous_align = array();
$previous_align['align'] = $this->cols['desc']['content']['align'];
if ($object->lines[$i]->qty < 0) {
$langs->load("subtotals");
$object->lines[$i]->desc = $langs->trans("SubtotalOf", $object->lines[$i]->desc);
if ($previous_align['align'] == 'L') {
$this->cols['desc']['content']['align'] = 'R';
} elseif ($previous_align['align'] == 'R') {
$this->cols['desc']['content']['align'] = 'L';
}
}
$this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
$this->setAfterColsLinePositionsData('desc', $pdf->GetY(), $pdf->getPage());
$this->cols['desc']['content']['align'] = $previous_align['align']; // Re align if we printed a subtotal ligne
pdf_render_subtotals($pdf, $this, $curY, $object, $i, $outputlangs, $hideref, $hidedesc, $bg_color, true, true);
}
}

View file

@ -666,23 +666,7 @@ class pdf_cyan extends ModelePDFPropales
$this->setAfterColsLinePositionsData('desc', $pdf->GetY(), $pdf->getPage());
} else {
$bg_color = colorStringToArray(getDolGlobalString("SUBTOTAL_BACK_COLOR_LEVEL_".abs($object->lines[$i]->qty)));
$pdf->SetFillColor($bg_color[0], $bg_color[1], $bg_color[2]);
$pdf->SetXY($pdf->GetX(), $curY);
$pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->marge_gauche, 6, '', 0, '', true);
$previous_align = array();
$previous_align['align'] = $this->cols['desc']['content']['align'];
if ($object->lines[$i]->qty < 0) {
$langs->load("subtotals");
$object->lines[$i]->desc = $langs->trans("SubtotalOf", $object->lines[$i]->desc);
if ($previous_align['align'] == 'L') {
$this->cols['desc']['content']['align'] = 'R';
} elseif ($previous_align['align'] == 'R') {
$this->cols['desc']['content']['align'] = 'L';
}
}
$this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
$this->setAfterColsLinePositionsData('desc', $pdf->GetY(), $pdf->getPage());
$this->cols['desc']['content']['align'] = $previous_align['align']; // Re align if we printed a subtotal ligne
pdf_render_subtotals($pdf, $this, $curY, $object, $i, $outputlangs, $hideref, $hidedesc, $bg_color, true, true);
}
}