From 840a98d8acc5015d4537aabd6c3782abc2d293a3 Mon Sep 17 00:00:00 2001 From: Francis Appels <francis.appels@yahoo.com> Date: Fri, 3 Oct 2014 12:20:02 +0200 Subject: [PATCH] Expedition lines from same orderline merged. When there are more expedition lines from same orderline key, merge them and get source warehouses. Usefull future possibility for creating shippinglines with same products from multiple warehouses. @KreizIT also changed some batch related items. --- htdocs/expedition/card.php | 25 ++++++++++- htdocs/expedition/class/expedition.class.php | 46 ++++++++++++++++---- htdocs/langs/en_US/sendings.lang | 4 ++ 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index ade0014708d..e9083b77e21 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -7,6 +7,7 @@ * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2013 Marcos García <marcosgdf@gmail.com> * Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr> + * Copyright (C) 2014 Francis Appels <francis.appels@yahoo.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1433,6 +1434,18 @@ else if ($id || $ref) $entrepot = new Entrepot($db); $entrepot->fetch($lines[$i]->entrepot_id); print $entrepot->getNomUrl(1); + } + else if (count($lines[$i]->details_entrepot) > 1) + { + $detail = ''; + foreach ($lines[$i]->details_entrepot as $detail_entrepot) { + if ($detail_entrepot->entrepot_id > 0) { + $entrepot = new Entrepot($db); + $entrepot->fetch($detail_entrepot->entrepot_id); + $detail.= $langs->trans("DetailWarehouseFormat",$entrepot->libelle,$detail_entrepot->qty_shipped).'<br/>'; + } + } + print $form->textwithtooltip($langs->trans("DetailWarehouseNumber"),$detail); } print '</td>'; } @@ -1440,6 +1453,7 @@ else if ($id || $ref) // Batch number managment if (! empty($conf->productbatch->enabled)) { if (isset($lines[$i]->detail_batch) ) { + $flagBatch = true; print '<td align="center">'; $detail = ''; foreach ($lines[$i]->detail_batch as $dbatch) { @@ -1526,10 +1540,17 @@ else if ($id || $ref) print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=classifybilled">'.$langs->trans($label).'</a>'; } } - + if ($user->rights->expedition->supprimer) { - print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete">'.$langs->trans("Delete").'</a>'; + if (empty($conf->productbatch->enabled) || (!empty($conf->productbatch->enabled) && !$conf->global->STOCK_CALCULATE_ON_SHIPMENT) || !isset($flagBatch)) + { + print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete">'.$langs->trans("Delete").'</a>'; + } + else + { + print '<a class="butActionRefused" href="#">'.$langs->trans('Delete').'</a>'; + } } print '</div>'; diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index d929dd067ef..019ef22f769 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -7,6 +7,7 @@ * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr> * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com> + * Copyright (C) 2014 Francis Appels <francis.appels@yahoo.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1068,7 +1069,7 @@ class Expedition extends CommonObject $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = cd.fk_product"; $sql.= " WHERE ed.fk_expedition = ".$this->id; $sql.= " AND ed.fk_origin_line = cd.rowid"; - $sql.= " ORDER BY cd.rang"; + $sql.= " ORDER BY cd.rang, ed.fk_origin_line"; dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG); $resql = $this->db->query($sql); @@ -1078,6 +1079,8 @@ class Expedition extends CommonObject $num = $this->db->num_rows($resql); $i = 0; + $lineindex = 0; + $originline = 0; $this->total_ht = 0; $this->total_tva = 0; @@ -1087,13 +1090,25 @@ class Expedition extends CommonObject while ($i < $num) { - $line = new ExpeditionLigne($this->db); - $obj = $this->db->fetch_object($resql); - + $obj = $this->db->fetch_object($resql); + + if ($originline == $obj->fk_origin_line) { + $line->entrepot_id = 0; // entrepod_id in details_entrepot + $line->qty_shipped += $obj->qty_shipped; + } else { + $line = new ExpeditionLigne($this->db); + $line->entrepot_id = $obj->fk_entrepot; + $line->qty_shipped = $obj->qty_shipped; + } + + $detail_entrepot = new stdClass; + $detail_entrepot->entrepot_id = $obj->fk_entrepot; + $detail_entrepot->qty_shipped = $obj->qty_shipped; + $line->details_entrepot[] = $detail_entrepot; + $line->line_id = $obj->line_id; $line->fk_origin_line = $obj->fk_origin_line; $line->origin_line_id = $obj->fk_origin_line; // TODO deprecated - $line->entrepot_id = $obj->fk_entrepot; $line->fk_product = $obj->fk_product; $line->fk_product_type = $obj->fk_product_type; $line->ref = $obj->product_ref; // TODO deprecated @@ -1103,7 +1118,6 @@ class Expedition extends CommonObject $line->label = $obj->custom_label; $line->description = $obj->description; $line->qty_asked = $obj->qty_asked; - $line->qty_shipped = $obj->qty_shipped; $line->weight = $obj->weight; $line->weight_units = $obj->weight_units; $line->length = $obj->length; @@ -1116,7 +1130,7 @@ class Expedition extends CommonObject // For invoicing $tabprice = calcul_price_total($obj->qty_shipped, $obj->subprice, $obj->remise_percent, $obj->tva_tx, $obj->localtax1_tx, $obj->localtax2_tx, 0, 'HT', $obj->info_bits, $obj->fk_product_type); // We force type to 0 $line->desc = $obj->description; // We need ->desc because some code into CommonObject use desc (property defined for other elements) - $line->qty = $obj->qty_shipped; + $line->qty = $line->qty_shipped; $line->total_ht = $tabprice[0]; $line->total_localtax1 = $tabprice[9]; $line->total_localtax2 = $tabprice[10]; @@ -1141,11 +1155,25 @@ class Expedition extends CommonObject * May be conf is not well initialized for dark reason */ require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php'; - $line->detail_batch=ExpeditionLigneBatch::FetchAll($this->db,$obj->line_id); + if ($originline != $obj->fk_origin_line) { + $line->detail_batch = ExpeditionLigneBatch::FetchAll($this->db,$obj->line_id); + } else { + $line->detail_batch = array_merge($line->detail_batch,ExpeditionLigneBatch::FetchAll($this->db,$obj->line_id)); + } + } + if ($originline != $obj->fk_origin_line) { + $this->lines[$lineindex] = $line; + $lineindex++; + } else { + $line->total_ht += $tabprice[0]; + $line->total_localtax1 += $tabprice[9]; + $line->total_localtax2 += $tabprice[10]; + $line->total_ttc += $tabprice[2]; + $line->total_tva += $tabprice[1]; } - $this->lines[$i] = $line; $i++; + $originline = $obj->fk_origin_line; } $this->db->free($resql); return 1; diff --git a/htdocs/langs/en_US/sendings.lang b/htdocs/langs/en_US/sendings.lang index 170f5984c4d..2ae43f39766 100644 --- a/htdocs/langs/en_US/sendings.lang +++ b/htdocs/langs/en_US/sendings.lang @@ -72,3 +72,7 @@ DocumentModelTyphon=More complete document model for delivery receipts (logo...) Error_EXPEDITION_ADDON_NUMBER_NotDefined=Constant EXPEDITION_ADDON_NUMBER not defined SumOfProductVolumes=Sum of product volumes SumOfProductWeights=Sum of product weights + +# warehouse details +DetailWarehouseNumber= Warehouse details +DetailWarehouseFormat= W:%s (Qty : %d) -- GitLab