From 86913a7681d43565c7789135bcaaaf12b500e845 Mon Sep 17 00:00:00 2001 From: tnegre Date: Mon, 6 Jan 2025 17:01:47 +0100 Subject: [PATCH 1/2] Add 4 substitutions for ODTs. Reuse logic from PDF generator, but reformat to make it clearer. --- .../core/class/commondocgenerator.class.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index 625d3584382..063da141889 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -1081,6 +1081,42 @@ abstract class CommonDocGenerator $array_shipment['order_ref_customer'] = $object->commande->ref_customer; } + // Load dim data + $tmparray = $object->getTotalWeightVolume(); + $totalWeight = $tmparray['weight']; + $totalVolume = $tmparray['volume']; + $totalOrdered = $tmparray['ordered']; + $totalToShip = $tmparray['toship']; + + // Set trueVolume and volume_units not currently stored into database + if ($object->trueWidth && $object->trueHeight && $object->trueDepth) { + $object->trueVolume = $object->trueWidth * $object->trueHeight * $object->trueDepth; + $object->volume_units = $object->size_units * 3; + } + + $array_shipment[$array_key.'_total_ordered'] = (string) $totalOrdered; + $array_shipment[$array_key.'_total_toship'] = (string) $totalToShip; + + if ($object->trueWeight) { + $array_shipment[$array_key.'_total_weight'] = (empty($totalWeight)) ? '' : showDimensionInBestUnit($object->trueWeight, $object->weight_units, "weight", $outputlangs); + } elseif (!empty($totalWeight)) { + $array_shipment[$array_key.'_total_weight'] = (empty($totalWeight)) ? '' : showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs, -1, 'no', 1); + } else { + $array_shipment[$array_key.'_total_weight'] = ""; + } + + if (!empty($object->trueVolume)) { + if ($object->volume_units < 50) { + $array_shipment[$array_key.'_total_volume'] = (empty($totalVolume)) ? '' : showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs); + } else { + $array_shipment[$array_key.'_total_volume'] = (empty($totalVolume)) ? '' : price($object->trueVolume, 0, $outputlangs, 0, 0).' '.measuringUnitString(0, "volume", $object->volume_units); + } + } elseif (!empty($totalVolume)) { + $array_shipment[$array_key.'_total_volume'] = (empty($totalVolume)) ? '' : showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs, -1, 'no', 1); + } else { + $array_shipment[$array_key.'_total_volume'] = ""; + } + return $array_shipment; } From 81298d6787e0905b8d8b4ff2cac88ef0f16bb11a Mon Sep 17 00:00:00 2001 From: tnegre Date: Mon, 6 Jan 2025 17:09:45 +0100 Subject: [PATCH 2/2] fix Phpstan --- htdocs/core/class/commondocgenerator.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index 063da141889..f37bfc34085 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -1100,7 +1100,7 @@ abstract class CommonDocGenerator if ($object->trueWeight) { $array_shipment[$array_key.'_total_weight'] = (empty($totalWeight)) ? '' : showDimensionInBestUnit($object->trueWeight, $object->weight_units, "weight", $outputlangs); } elseif (!empty($totalWeight)) { - $array_shipment[$array_key.'_total_weight'] = (empty($totalWeight)) ? '' : showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs, -1, 'no', 1); + $array_shipment[$array_key.'_total_weight'] = showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs, -1, 'no', 1); } else { $array_shipment[$array_key.'_total_weight'] = ""; } @@ -1112,7 +1112,7 @@ abstract class CommonDocGenerator $array_shipment[$array_key.'_total_volume'] = (empty($totalVolume)) ? '' : price($object->trueVolume, 0, $outputlangs, 0, 0).' '.measuringUnitString(0, "volume", $object->volume_units); } } elseif (!empty($totalVolume)) { - $array_shipment[$array_key.'_total_volume'] = (empty($totalVolume)) ? '' : showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs, -1, 'no', 1); + $array_shipment[$array_key.'_total_volume'] = showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs, -1, 'no', 1); } else { $array_shipment[$array_key.'_total_volume'] = ""; }