MSIN-4469 — Enhance fxBibProductionXmlSetFormula function to support cached values for Excel output, preventing empty totals in Excel/LibreOffice until recalculation occurs. Update fxBibProductionBuildOrderXml to utilize this new functionality for improved total calculations. Increment version code.

This commit is contained in:
2026-07-23 12:55:42 -04:00
parent f93f6d14ff
commit 685a1fd4f3

View File

@ -342,7 +342,8 @@ function fxBibProductionXmlSetFormula(
$strColumn, $strColumn,
$intRow, $intRow,
$strFormula, $strFormula,
$strStyle = '' $strStyle = '',
$mixCachedValue = null
) { ) {
$strNs = 'http://schemas.openxmlformats.org/spreadsheetml/2006/main'; $strNs = 'http://schemas.openxmlformats.org/spreadsheetml/2006/main';
$objCell = fxBibProductionXmlEnsureCell($objDom, $objRow, $strColumn, $intRow, $strStyle); $objCell = fxBibProductionXmlEnsureCell($objDom, $objRow, $strColumn, $intRow, $strStyle);
@ -350,6 +351,13 @@ function fxBibProductionXmlSetFormula(
$objFormula = $objDom->createElementNS($strNs, 'f'); $objFormula = $objDom->createElementNS($strNs, 'f');
$objFormula->appendChild($objDom->createTextNode($strFormula)); $objFormula->appendChild($objDom->createTextNode($strFormula));
$objCell->appendChild($objFormula); $objCell->appendChild($objFormula);
// MSIN-4469 — Valeur calculée en cache : sinon Excel/LibreOffice peut
// afficher le TOTAL vide tant que le recalcul n'a pas tourné.
if ($mixCachedValue !== null && $mixCachedValue !== '') {
$objValue = $objDom->createElementNS($strNs, 'v');
$objValue->appendChild($objDom->createTextNode((string)$mixCachedValue));
$objCell->appendChild($objValue);
}
} }
function fxBibProductionXmlCloneRow(DOMElement $objTemplateRow, $intTargetRow) { function fxBibProductionXmlCloneRow(DOMElement $objTemplateRow, $intTargetRow) {
@ -574,23 +582,68 @@ function fxBibProductionBuildOrderXml($strXml, array $tabSnapshot, array $tabLab
$objHeaderRow, $objHeaderRow,
'K', 'K',
3, 3,
$tabLabels['printer_lines'], isset($tabLabels['printer_lines']) ? $tabLabels['printer_lines'] : 'Lignes Imprimeur',
$strHeaderStyleK $strHeaderStyleK
); );
} }
$intBibTotal = 0;
foreach ($tabOrderRows as $tabRow) {
$intBibTotal += (int)$tabRow['quantity'];
}
// Reprendre la ligne TOTAL après les insertions (référence DOM à jour).
$objTotal = fxBibProductionXmlFindRow($objXpath, $intTotalRow);
if (!$objTotal) {
throw new Exception('MSIN-4469 total row missing');
}
fxBibProductionXmlSetInlineString($objDom, $objTotal, 'A', $intTotalRow, $tabLabels['total']); fxBibProductionXmlSetInlineString($objDom, $objTotal, 'A', $intTotalRow, $tabLabels['total']);
fxBibProductionXmlSetFormula($objDom, $objTotal, 'F', $intTotalRow, 'SUM(F4:F' . ($intTotalRow - 1) . ')'); fxBibProductionXmlSetFormula(
fxBibProductionXmlSetFormula($objDom, $objTotal, 'I', $intTotalRow, 'SUM(I4:I' . ($intTotalRow - 1) . ')'); $objDom,
fxBibProductionXmlSetFormula($objDom, $objTotal, 'L', $intTotalRow, 'SUM(L4:L' . ($intTotalRow - 1) . ')'); $objTotal,
// COUNT ne compte que les numéros (ignore en-tête texte et lignes blanches entre épreuves). 'F',
fxBibProductionXmlSetFormula($objDom, $objTotal, 'K', $intTotalRow, 'COUNT(Imprimeur!A:A)'); $intTotalRow,
'SUM(F4:F' . ($intTotalRow - 1) . ')',
'',
$intBibTotal
);
fxBibProductionXmlSetFormula(
$objDom,
$objTotal,
'I',
$intTotalRow,
'SUM(I4:I' . ($intTotalRow - 1) . ')',
'',
$intBibTotal
);
fxBibProductionXmlSetFormula(
$objDom,
$objTotal,
'L',
$intTotalRow,
'SUM(L4:L' . ($intTotalRow - 1) . ')',
'',
$intBibTotal
);
// COUNT ignore l'en-tête texte et les lignes blanches entre épreuves.
fxBibProductionXmlSetFormula(
$objDom,
$objTotal,
'K',
$intTotalRow,
'COUNT(Imprimeur!A:A)',
'',
$intBibTotal
);
fxBibProductionXmlSetFormula( fxBibProductionXmlSetFormula(
$objDom, $objDom,
$objTotal, $objTotal,
'J', 'J',
$intTotalRow, $intTotalRow,
'F' . $intTotalRow . '=K' . $intTotalRow 'F' . $intTotalRow . '=K' . $intTotalRow,
'',
'1'
); );
$objDimension = $objXpath->query('//m:dimension')->item(0); $objDimension = $objXpath->query('//m:dimension')->item(0);