Browse Source

MMIDocument Option to order shipping lines by ref

Mathieu Moulin 2 years ago
parent
commit
3d7a0440ed

+ 6 - 1
htdocs/core/modules/expedition/doc/pdf_rouget.modules.php

@@ -213,7 +213,12 @@ class pdf_rouget extends ModelePdfExpedition
 
 		// Load traductions files required by page
 		$outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies", "propal", "deliveries", "sendings", "productbatch"));
-
+		// Added by MMI Mathieu Moulin iProspective
+		// Sort by Product Ref
+		if (!empty($conf->global->MMI_EXPE_ORDER_LINES_BY_REF))
+			usort($object->lines, function($i, $j){
+				return ($i->ref > $j->ref) ?1 :(($i->ref < $j->ref) ?-1 :0);
+			});
 		$nblines = count($object->lines);
 
 		// Loop on each lines to detect if there is at least one image to show

+ 4 - 1
htdocs/expedition/class/expedition.class.php

@@ -1578,7 +1578,10 @@ class Expedition extends CommonObject
 		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = cd.fk_product";
 		$sql .= " WHERE ed.fk_expedition = ".((int) $this->id);
 		$sql .= " AND ed.fk_origin_line = cd.rowid";
-		$sql .= " ORDER BY cd.rang, ed.fk_origin_line";
+		if (!empty($conf->global->MMI_EXPE_ORDER_LINES_BY_REF))
+			$sql .= " ORDER BY p.ref, cd.rang, ed.fk_origin_line";
+		else
+			$sql .= " ORDER BY cd.rang, ed.fk_origin_line";
 
 		dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
 		$resql = $this->db->query($sql);