From 281b06a2d327f51de0b37bccd1c980b78b212f75 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 1 Apr 2016 18:44:23 +0200 Subject: [PATCH] NEW Introduce option MAIN_WEIGHT_DEFAULT_UNIT and MAIN_VOLUME_DEFAULT_UNIT to force output unit for weight and volume. --- htdocs/commande/card.php | 39 ++++++++---- htdocs/commande/class/commande.class.php | 8 ++- htdocs/core/class/commonobject.class.php | 62 ++++++++++++++++++++ htdocs/core/class/commonorder.class.php | 6 +- htdocs/core/lib/functions.lib.php | 11 ++-- htdocs/expedition/card.php | 6 +- htdocs/expedition/class/expedition.class.php | 50 ---------------- 7 files changed, 106 insertions(+), 76 deletions(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index d9258d921cd..f2d2e24d269 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -1997,6 +1997,19 @@ if ($action == 'create' && $user->rights->commande->creer) } print ''; + if ($soc->outstanding_limit) + { + // Outstanding Bill + print ''; + print $langs->trans('OutstandingBill'); + print ''; + print price($soc->get_OutstandingBill()) . ' / '; + print price($soc->outstanding_limit, 0, '', 1, - 1, - 1, $conf->currency); + print ''; + print ''; + } + + // Relative and absolute discounts if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final // invoice @@ -2006,7 +2019,6 @@ if ($action == 'create' && $user->rights->commande->creer) $filtercreditnote = "fk_facture_source IS NOT NULL AND description <> '(DEPOSIT)'"; } - // Relative and absolute discounts $addrelativediscount = '' . $langs->trans("EditRelativeDiscounts") . ''; $addabsolutediscount = '' . $langs->trans("EditGlobalDiscounts") . ''; $addcreditnote = '' . $langs->trans("AddCreditNote") . ''; @@ -2236,6 +2248,19 @@ if ($action == 'create' && $user->rights->commande->creer) // print ''.$langs->trans("DictionarySource").''; print ''; + $tmparray=$object->getTotalWeightVolume(); + $totalWeight=$tmparray['weight']; + $totalVolume=$tmparray['volume']; + if ($totalWeight || $totalVolume) + { + print ''.$langs->trans("CalculatedWeight").' / '.$langs->trans("CalculatedVolume").''; + print ''; + print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND)?$conf->global->MAIN_WEIGHT_DEFAULT_ROUND:-1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT)?$conf->global->MAIN_WEIGHT_DEFAULT_UNIT:'no'); + print ' / '; + print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND)?$conf->global->MAIN_VOLUME_DEFAULT_ROUND:-1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT)?$conf->global->MAIN_VOLUME_DEFAULT_UNIT:'no'); + print ''; + } + // TODO How record was recorded OrderMode (llx_c_input_method) // Project @@ -2259,18 +2284,6 @@ if ($action == 'create' && $user->rights->commande->creer) print ''; } - if ($soc->outstanding_limit) - { - // Outstanding Bill - print ''; - print $langs->trans('OutstandingBill'); - print ''; - print price($soc->get_OutstandingBill()) . ' / '; - print price($soc->outstanding_limit, 0, '', 1, - 1, - 1, $conf->currency); - print ''; - print ''; - } - // Incoterms if (!empty($conf->incoterm->enabled)) { diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 275f42452a6..6e9e988daa0 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1718,7 +1718,8 @@ class Commande extends CommonOrder $sql.= ' l.total_ht, l.total_ttc, l.total_tva, l.total_localtax1, l.total_localtax2, l.date_start, l.date_end,'; $sql.= ' l.fk_unit,'; $sql.= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,'; - $sql.= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label'; + $sql.= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label,'; + $sql.= ' p.weight, p.weight_units, p.volume, p.volume_units'; $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON (p.rowid = l.fk_product)'; $sql.= ' WHERE l.fk_commande = '.$this->id; @@ -1777,6 +1778,11 @@ class Commande extends CommonOrder $line->product_desc = $objp->product_desc; $line->fk_product_type = $objp->fk_product_type; // Produit ou service $line->fk_unit = $objp->fk_unit; + + $line->weight = $objp->weight; + $line->weight_units = $objp->weight_units; + $line->volume = $objp->volume; + $line->volume_units = $objp->volume_units; $line->date_start = $this->db->jdate($objp->date_start); $line->date_end = $this->db->jdate($objp->date_end); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index a65573a7947..059ce7e5e25 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2939,6 +2939,68 @@ abstract class CommonObject return price2num($total_discount); } + + /** + * Return into unit=0, the calculated total of weight and volume of all lines * qty + * Calculate by adding weight and volume of each product line, so properties ->volume/volume_units/weight/weight_units must be loaded on line. + * + * @return array array('weight'=>...,'volume'=>...) + */ + function getTotalWeightVolume() + { + $weightUnit=0; + $volumeUnit=0; + $totalWeight = ''; + $totalVolume = ''; + $totalOrdered = ''; // defined for shipment only + $totalToShip = ''; // defined for shipment only + + foreach ($this->lines as $line) + { + + $totalOrdered+=$line->qty_asked; // defined for shipment only + $totalToShip+=$line->qty_shipped; // defined for shipment only + + // Define qty, weight, volume, weight_units, volume_units + if ($this->element == 'shipping') $qty=$line->qty_shipped; // for shipments + else $qty=$line->qty; + $weight=$line->weight; + $volume=$line->volume; + $weight_units=$line->weight_units; + $volume_units=$line->volume_units; + + $weightUnit=0; + $volumeUnit=0; + if (! empty($weight_units)) $weightUnit = $weight_units; + if (! empty($volume_units)) $volumeUnit = $volume_units; + + //var_dump($line->volume_units); + if ($weight_units < 50) // >50 means a standard unit (power of 10 of official unit) > 50 means an exotic unit (like inch) + { + $trueWeightUnit=pow(10, $weightUnit); + $totalWeight += $weight * $qty * $trueWeightUnit; + } + else + { + $totalWeight += $weight * $qty; // This may be wrong if we mix different units + } + if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit) > 50 means an exotic unit (like inch) + { + //print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit; + $trueVolumeUnit=pow(10, $volumeUnit); + //print $line->volume; + $totalVolume += $volume * $qty * $trueVolumeUnit; + } + else + { + $totalVolume += $volume * $qty; // This may be wrong if we mix different units + } + } + + return array('weight'=>$totalWeight, 'volume'=>$totalVolume, 'ordered'=>$totalOrdered, 'toship'=>$totalToShip); + } + + /** * Set extra parameters * diff --git a/htdocs/core/class/commonorder.class.php b/htdocs/core/class/commonorder.class.php index 74d14af0819..8cacf7065b1 100644 --- a/htdocs/core/class/commonorder.class.php +++ b/htdocs/core/class/commonorder.class.php @@ -25,8 +25,7 @@ require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; require_once DOL_DOCUMENT_ROOT .'/core/class/commonobjectline.class.php'; /** - * \class CommonOrder - * \brief Superclass for orders classes + * Superclass for orders classes */ abstract class CommonOrder extends CommonObject { @@ -34,8 +33,7 @@ abstract class CommonOrder extends CommonObject } /** - * \class CommonOrderLine - * \brief Superclass for orders classes + * Superclass for orders classes */ abstract class CommonOrderLine extends CommonObjectLine { diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 00c805b98ba..bedb2a78bae 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3420,28 +3420,29 @@ function price2num($amount,$rounding='',$alreadysqlnb=0) * @param string $type 'weight', 'volume', ... * @param Translate $outputlangs Translate language object * @param int $round -1 = non rounding, x = number of decimal + * @param string $forceunitoutput 'no' or numeric (-3, -6, ...) compared to $unit * @return string String to show dimensions */ -function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1) +function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitouput='no') { require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; - if ($dimension < 1/10000) + if (($forceunitouput == 'no' && $dimension < 1/10000) || (is_numeric($forceunitouput) && $forceunitouput == -6)) { $dimension = $dimension * 1000000; $unit = $unit - 6; } - elseif ($dimension < 1/10) + elseif (($forceunitouput == 'no' && $dimension < 1/10) || (is_numeric($forceunitouput) && $forceunitouput == -3)) { $dimension = $dimension * 1000; $unit = $unit - 3; } - elseif ($dimension > 100000000) + elseif (($forceunitouput == 'no' && $dimension > 100000000) || (is_numeric($forceunitouput) && $forceunitouput == 6)) { $dimension = $dimension / 1000000; $unit = $unit + 6; } - elseif ($dimension > 100000) + elseif (($forceunitouput == 'no' && $dimension > 100000) || (is_numeric($forceunitouput) && $forceunitouput == 3)) { $dimension = $dimension / 1000; $unit = $unit + 3; diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 6915594dd92..af973886071 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -1373,7 +1373,7 @@ else if ($id || $ref) { if (!empty($object->trueWeight)) print ' ('.$langs->trans("SumOfProductWeights").': '; //print $totalWeight.' '.measuring_units_string(0,"weight"); - print showDimensionInBestUnit($totalWeight, 0, "weight", $langs); + print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND)?$conf->global->MAIN_WEIGHT_DEFAULT_ROUND:-1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT)?$conf->global->MAIN_WEIGHT_DEFAULT_UNIT:'no'); //if (empty($object->trueWeight)) print ' ('.$langs->trans("Calculated").')'; if (!empty($object->trueWeight)) print ')'; } @@ -1432,7 +1432,7 @@ else if ($id || $ref) if ($volumeUnit < 50) { //print $calculatedVolume.' '.measuring_units_string($volumeUnit,"volume"); - print showDimensionInBestUnit($calculatedVolume, $volumeUnit, "volume", $langs); + print showDimensionInBestUnit($calculatedVolume, $volumeUnit, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND)?$conf->global->MAIN_VOLUME_DEFAULT_ROUND:-1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT)?$conf->global->MAIN_VOLUME_DEFAULT_UNIT:'no'); } else print $calculatedVolume.' '.measuring_units_string($volumeUnit,"volume"); } @@ -1440,7 +1440,7 @@ else if ($id || $ref) { if ($calculatedVolume) print ' ('.$langs->trans("SumOfProductVolumes").': '; //print $totalVolume.' '.measuring_units_string(0,"volume"); - print showDimensionInBestUnit($totalVolume, 0, "volume", $langs); + print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND)?$conf->global->MAIN_VOLUME_DEFAULT_ROUND:-1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT)?$conf->global->MAIN_VOLUME_DEFAULT_UNIT:'no'); //if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')'; if ($calculatedVolume) print ')'; } diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 317b71bde99..a0ba1567c24 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1758,56 +1758,6 @@ class Expedition extends CommonObject } - /** - * Return into unit=0, the calculated total of weight and volume of all lines * qty - * Calculate by adding weight and volume of each product line. - * - * @return array array('weight'=>...,'volume'=>...) - */ - function getTotalWeightVolume() - { - $weightUnit=0; - $volumeUnit=0; - $totalWeight = ''; - $totalVolume = ''; - $totalOrdered = ''; - $totalToShip = ''; - foreach ($this->lines as $line) - { - $totalOrdered+=$line->qty_asked; - $totalToShip+=$line->qty_shipped; - - $weightUnit=0; - $volumeUnit=0; - if (! empty($line->weight_units)) $weightUnit = $line->weight_units; - if (! empty($line->volume_units)) $volumeUnit = $line->volume_units; - - //var_dump($line->volume_units); - if ($line->weight_units < 50) // >50 means a standard unit (power of 10 of official unit) > 50 means an exotic unit (like inch) - { - $trueWeightUnit=pow(10,$weightUnit); - $totalWeight += $line->weight*$line->qty_shipped*$trueWeightUnit; - } - else - { - $totalWeight += $line->weight*$line->qty_shipped; // This may be wrong if we mix different units - } - if ($line->volume_units < 50) // >50 means a standard unit (power of 10 of official unit) > 50 means an exotic unit (like inch) - { - //print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit; - $trueVolumeUnit=pow(10,$volumeUnit); - //print $line->volume; - $totalVolume += $line->volume*$line->qty_shipped*$trueVolumeUnit; - } - else - { - $totalVolume += $line->volume*$line->qty_shipped; // This may be wrong if we mix different units - } - } - - return array('weight'=>$totalWeight, 'volume'=>$totalVolume, 'ordered'=>$totalOrdered, 'toship'=>$totalToShip); - } - /** * Forge an set tracking url