diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index 6c206bd51d9..fdf2d48735c 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -1007,7 +1007,7 @@ class Orders extends DolibarrApi $sql .= " JOIN ".MAIN_DB_PREFIX."expeditiondet as edet"; $sql .= " ON e.rowid = edet.fk_expedition"; $sql .= " JOIN ".MAIN_DB_PREFIX."commandedet as cdet"; - $sql .= " ON edet.fk_origin_line = cdet.rowid"; + $sql .= " ON edet.fk_elementdet = cdet.rowid"; $sql .= " JOIN ".MAIN_DB_PREFIX."commande as c"; $sql .= " ON cdet.fk_commande = c.rowid"; $sql .= " WHERE c.rowid = ".((int) $id); diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 51c49c5e121..e2b051a9595 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2231,7 +2231,7 @@ class Commande extends CommonOrder $sql .= ' FROM '.MAIN_DB_PREFIX.'expeditiondet as ed,'; $sql .= ' '.MAIN_DB_PREFIX.'commandedet as cd'; $sql .= ' WHERE'; - $sql .= ' ed.fk_origin_line = cd.rowid'; + $sql .= ' ed.fk_elementdet = cd.rowid'; $sql .= ' AND cd.fk_commande = '.((int) $this->id); //print $sql; @@ -2274,7 +2274,7 @@ class Commande extends CommonOrder if ($filtre_statut >= 0) { $sql .= ' ed.fk_expedition = e.rowid AND'; } - $sql .= ' ed.fk_origin_line = cd.rowid'; + $sql .= ' ed.fk_elementdet = cd.rowid'; $sql .= ' AND cd.fk_commande = '.((int) $this->id); if ($fk_product > 0) { $sql .= ' AND cd.fk_product = '.((int) $fk_product); @@ -4389,7 +4389,7 @@ class OrderLine extends CommonOrderLine $sqlCheckShipmentLine = "SELECT"; $sqlCheckShipmentLine .= " ed.rowid"; $sqlCheckShipmentLine .= " FROM " . MAIN_DB_PREFIX . "expeditiondet ed"; - $sqlCheckShipmentLine .= " WHERE ed.fk_origin_line = " . ((int) $this->id); + $sqlCheckShipmentLine .= " WHERE ed.fk_elementdet = " . ((int) $this->id); $resqlCheckShipmentLine = $this->db->query($sqlCheckShipmentLine); if (!$resqlCheckShipmentLine) { diff --git a/htdocs/core/lib/sendings.lib.php b/htdocs/core/lib/sendings.lib.php index 7c108f74eca..40fa6e220ba 100644 --- a/htdocs/core/lib/sendings.lib.php +++ b/htdocs/core/lib/sendings.lib.php @@ -241,7 +241,7 @@ function show_list_sending_receive($origin, $origin_id, $filter = '') $warehousestatic = new Entrepot($db); $sql = "SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.date_start, obj.date_end,"; - $sql .= " ed.rowid as edrowid, ed.qty as qty_shipped, ed.fk_expedition as expedition_id, ed.fk_origin_line, ed.fk_entrepot as warehouse_id,"; + $sql .= " ed.rowid as edrowid, ed.qty as qty_shipped, ed.fk_expedition as expedition_id, ed.fk_elementdet, ed.fk_entrepot as warehouse_id,"; $sql .= " e.rowid as sendingid, e.ref as exp_ref, e.date_creation, e.date_delivery, e.date_expedition, e.billed, e.fk_statut as status,"; $sql .= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch,'; $sql .= ' p.description as product_desc'; @@ -252,7 +252,7 @@ function show_list_sending_receive($origin, $origin_id, $filter = '') //TODO Add link to expeditiondet_batch $sql .= " WHERE e.entity IN (".getEntity('expedition').")"; $sql .= " AND obj.fk_".$origin." = ".((int) $origin_id); - $sql .= " AND obj.rowid = ed.fk_origin_line"; + $sql .= " AND obj.rowid = ed.fk_elementdet"; $sql .= " AND ed.fk_expedition = e.rowid"; if ($filter) { $sql .= $filter; @@ -450,7 +450,7 @@ function show_list_sending_receive($origin, $origin_id, $filter = '') } if (!empty($receiving)) { - // $expedition->fk_origin_line = id of det line of order + // $expedition->fk_elementdet = id of det line of order // $receiving->fk_origin_line = id of det line of order // $receiving->origin may be 'shipping' // $receiving->origin_id may be id of shipping diff --git a/htdocs/core/modules/modExpedition.class.php b/htdocs/core/modules/modExpedition.class.php index ede84c3f927..e1e4e41353a 100644 --- a/htdocs/core/modules/modExpedition.class.php +++ b/htdocs/core/modules/modExpedition.class.php @@ -318,7 +318,7 @@ class modExpedition extends DolibarrModules $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople as sp ON sp.rowid = ee.fk_socpeople'; $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra3 ON sp.rowid = extra3.fk_object'; } - $this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = ed.fk_expedition AND ed.fk_origin_line = cd.rowid'; + $this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = ed.fk_expedition AND ed.fk_elementdet = cd.rowid'; $this->export_sql_end[$r] .= ' AND c.entity IN ('.getEntity('expedition').')'; if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) { $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : $user->id); diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 16a71da87da..7f748bf3e03 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -2241,7 +2241,7 @@ if ($action == 'create') { $alreadysent = array(); if ($origin && $origin_id > 0) { $sql = "SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.fk_unit, obj.date_start, obj.date_end"; - $sql .= ", ed.rowid as shipmentline_id, ed.qty as qty_shipped, ed.fk_expedition as expedition_id, ed.fk_origin_line, ed.fk_entrepot"; + $sql .= ", ed.rowid as shipmentline_id, ed.qty as qty_shipped, ed.fk_expedition as expedition_id, ed.fk_elementdet, ed.fk_entrepot"; $sql .= ", e.rowid as shipment_id, e.ref as shipment_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_expedition"; //if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received"; $sql .= ', p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tosell as product_tosell, p.tobuy as product_tobuy, p.tobatch as product_tobatch'; @@ -2253,7 +2253,7 @@ if ($action == 'create') { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid"; $sql .= " WHERE e.entity IN (".getEntity('expedition').")"; $sql .= " AND obj.fk_".$origin." = ".((int) $origin_id); - $sql .= " AND obj.rowid = ed.fk_origin_line"; + $sql .= " AND obj.rowid = ed.fk_elementdet"; $sql .= " AND ed.fk_expedition = e.rowid"; //if ($filter) $sql.= $filter; $sql .= " ORDER BY obj.fk_product"; @@ -2374,7 +2374,7 @@ if ($action == 'create') { $htmltooltip = ''; $qtyalreadysent = 0; foreach ($alreadysent as $key => $val) { - if ($lines[$i]->fk_origin_line == $key) { + if ($lines[$i]->fk_elementdet == $key) { $j = 0; foreach ($val as $shipmentline_id => $shipmentline_var) { if ($shipmentline_var['shipment_id'] == $lines[$i]->fk_expedition) { diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 1d805421a6e..d8b533ca413 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -506,7 +506,8 @@ class Expedition extends CommonObject $expeditionline = new ExpeditionLigne($this->db); $expeditionline->fk_expedition = $this->id; $expeditionline->entrepot_id = $entrepot_id; - $expeditionline->fk_origin_line = $origin_line_id; + $expeditionline->fk_elementdet = $origin_line_id; + $expeditionline->element_type = $this->origin; $expeditionline->qty = $qty; $expeditionline->rang = $rang; $expeditionline->array_options = $array_options; @@ -910,7 +911,8 @@ class Expedition extends CommonObject $line->entrepot_id = $entrepot_id; $line->origin_line_id = $id; - $line->fk_origin_line = $id; + $line->fk_elementdet = $id; + $line->element_type = 'order'; $line->qty = $qty; $orderline = new OrderLine($this->db); @@ -1030,7 +1032,7 @@ class Expedition extends CommonObject } $line->entrepot_id = $linebatch->entrepot_id; $line->origin_line_id = $dbatch['ix_l']; // deprecated - $line->fk_origin_line = $dbatch['ix_l']; + $line->fk_elementdet = $dbatch['ix_l']; $line->qty = $dbatch['qty']; $line->detail_batch = $tab; @@ -1230,7 +1232,7 @@ class Expedition extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd,"; $sql .= " ".MAIN_DB_PREFIX."expeditiondet as ed"; $sql .= " WHERE ed.fk_expedition = ".((int) $this->id); - $sql .= " AND cd.rowid = ed.fk_origin_line"; + $sql .= " AND cd.rowid = ed.fk_elementdet"; dol_syslog(get_class($this)."::delete select details", LOG_DEBUG); $resql = $this->db->query($sql); @@ -1430,7 +1432,7 @@ class Expedition extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd,"; $sql .= " ".MAIN_DB_PREFIX."expeditiondet as ed"; $sql .= " WHERE ed.fk_expedition = ".((int) $this->id); - $sql .= " AND cd.rowid = ed.fk_origin_line"; + $sql .= " AND cd.rowid = ed.fk_elementdet"; dol_syslog(get_class($this)."::delete select details", LOG_DEBUG); $resql = $this->db->query($sql); @@ -1599,14 +1601,14 @@ class Expedition extends CommonObject $sql .= ", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva"; $sql .= ", cd.vat_src_code, cd.tva_tx, cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.info_bits, cd.price, cd.subprice, cd.remise_percent,cd.buy_price_ht as pa_ht"; $sql .= ", cd.fk_multicurrency, cd.multicurrency_code, cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc, cd.rang"; - $sql .= ", ed.rowid as line_id, ed.qty as qty_shipped, ed.fk_origin_line, ed.fk_entrepot"; + $sql .= ", ed.rowid as line_id, ed.qty as qty_shipped, ed.fk_elementdet, ed.element_type, ed.fk_entrepot"; $sql .= ", p.ref as product_ref, p.label as product_label, p.fk_product_type, p.barcode as product_barcode"; $sql .= ", p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units, p.tosell as product_tosell, p.tobuy as product_tobuy, p.tobatch as product_tobatch"; $sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd"; $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"; // We need after a break on fk_origin_line but when there is no break on fk_origin_line, cd.rang is same so we can add it as first order criteria. + $sql .= " AND ed.fk_elementdet = cd.rowid"; + $sql .= " ORDER BY cd.rang, ed.fk_elementdet"; // We need after a break on fk_elementdet but when there is no break on fk_elementdet, cd.rang is same so we can add it as first order criteria. dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG); $resql = $this->db->query($sql); @@ -1634,7 +1636,7 @@ class Expedition extends CommonObject $obj = $this->db->fetch_object($resql); - if ($originline > 0 && $originline == $obj->fk_origin_line) { + if ($originline > 0 && $originline == $obj->fk_elementdet) { '@phan-var-force ExpeditionLigne $line'; // $line from previous loop $line->entrepot_id = 0; // entrepod_id in details_entrepot $line->qty_shipped += $obj->qty_shipped; @@ -1655,8 +1657,9 @@ class Expedition extends CommonObject $line->id = $obj->line_id; $line->fk_origin = 'orderline'; - $line->fk_origin_line = $obj->fk_origin_line; - $line->origin_line_id = $obj->fk_origin_line; // TODO deprecated + $line->fk_elementdet = $obj->fk_elementdet; + $line->origin_line_id = $obj->fk_elementdet; // TODO deprecated + $line->element_type = $obj->element_type; $line->fk_expedition = $this->id; // id of parent @@ -1732,7 +1735,7 @@ class Expedition extends CommonObject $this->multicurrency_total_tva += $obj->multicurrency_total_tva; $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc; - if ($originline != $obj->fk_origin_line) { + if ($originline != $obj->fk_elementdet) { $line->detail_batch = array(); } @@ -1741,7 +1744,7 @@ class Expedition extends CommonObject $newdetailbatch = $shipmentlinebatch->fetchAll($obj->line_id, $obj->fk_product); if (is_array($newdetailbatch)) { - if ($originline != $obj->fk_origin_line) { + if ($originline != $obj->fk_elementdet) { $line->detail_batch = $newdetailbatch; } else { $line->detail_batch = array_merge($line->detail_batch, $newdetailbatch); @@ -1751,7 +1754,7 @@ class Expedition extends CommonObject $line->fetch_optionals(); - if ($originline != $obj->fk_origin_line) { + if ($originline != $obj->fk_elementdet) { $this->lines[$lineindex] = $line; $lineindex++; } else { @@ -1763,7 +1766,7 @@ class Expedition extends CommonObject } $i++; - $originline = $obj->fk_origin_line; + $originline = $obj->fk_elementdet; } $this->db->free($resql); return 1; @@ -2312,7 +2315,7 @@ class Expedition extends CommonObject $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "expedition as e ON ed.fk_expedition = e.rowid"; $sql .= " WHERE ed.fk_expedition = " . ((int) $this->id); - $sql .= " AND cd.rowid = ed.fk_origin_line"; + $sql .= " AND cd.rowid = ed.fk_elementdet"; dol_syslog(get_class($this) . "::valid select details", LOG_DEBUG); $resql = $this->db->query($sql); @@ -2473,7 +2476,7 @@ class Expedition extends CommonObject $sql .= " ".MAIN_DB_PREFIX."expeditiondet as ed"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid"; $sql .= " WHERE ed.fk_expedition = ".((int) $this->id); - $sql .= " AND cd.rowid = ed.fk_origin_line"; + $sql .= " AND cd.rowid = ed.fk_elementdet"; dol_syslog(get_class($this)."::valid select details", LOG_DEBUG); $resql = $this->db->query($sql); @@ -2629,7 +2632,7 @@ class ExpeditionLigne extends CommonObjectLine /** * @deprecated - * @see $fk_origin_line + * @see $fk_elementdet */ public $origin_line_id; @@ -2640,10 +2643,17 @@ class ExpeditionLigne extends CommonObjectLine */ public $fk_origin; // Example: 'orderline' + /** + * Type of source object + * + * @var string + */ + public $element_type; // Example: 'order' + /** * @var int ID */ - public $fk_origin_line; + public $fk_elementdet; /** * @var int Id of shipment @@ -2819,7 +2829,7 @@ class ExpeditionLigne extends CommonObjectLine */ public function fetch($rowid) { - $sql = 'SELECT ed.rowid, ed.fk_expedition, ed.fk_entrepot, ed.fk_origin_line, ed.qty, ed.rang'; + $sql = 'SELECT ed.rowid, ed.fk_expedition, ed.fk_entrepot, ed.fk_elementdet, ed.element_type, ed.qty, ed.rang'; $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as ed'; $sql .= ' WHERE ed.rowid = '.((int) $rowid); $result = $this->db->query($sql); @@ -2828,7 +2838,8 @@ class ExpeditionLigne extends CommonObjectLine $this->id = $objp->rowid; $this->fk_expedition = $objp->fk_expedition; $this->entrepot_id = $objp->fk_entrepot; - $this->fk_origin_line = $objp->fk_origin_line; + $this->fk_elementdet = $objp->fk_elementdet; + $this->element_type = $objp->element_type; $this->qty = $objp->qty; $this->rang = $objp->rang; @@ -2854,7 +2865,7 @@ class ExpeditionLigne extends CommonObjectLine $error = 0; // Check parameters - if (empty($this->fk_expedition) || empty($this->fk_origin_line) || !is_numeric($this->qty)) { + if (empty($this->fk_expedition) || empty($this->fk_elementdet) || !is_numeric($this->qty)) { $this->error = 'ErrorMandatoryParametersNotProvided'; return -1; } @@ -2875,13 +2886,15 @@ class ExpeditionLigne extends CommonObjectLine $sql = "INSERT INTO ".MAIN_DB_PREFIX."expeditiondet ("; $sql .= "fk_expedition"; $sql .= ", fk_entrepot"; - $sql .= ", fk_origin_line"; + $sql .= ", fk_elementdet"; + $sql .= ", element_type"; $sql .= ", qty"; $sql .= ", rang"; $sql .= ") VALUES ("; $sql .= $this->fk_expedition; $sql .= ", ".(empty($this->entrepot_id) ? 'NULL' : $this->entrepot_id); - $sql .= ", ".((int) $this->fk_origin_line); + $sql .= ", ".((int) $this->fk_elementdet); + $sql .= ", ".(empty($this->element_type) ? 'order' : $this->element_type); $sql .= ", ".price2num($this->qty, 'MS'); $sql .= ", ".((int) $ranktouse); $sql .= ")"; diff --git a/htdocs/expedition/dispatch.php b/htdocs/expedition/dispatch.php index 615785de08b..cd5c703835a 100644 --- a/htdocs/expedition/dispatch.php +++ b/htdocs/expedition/dispatch.php @@ -272,7 +272,7 @@ if ($action == 'updatelines' && $usercancreate) { } else { $expeditiondispatch->fk_expedition = $object->id; $expeditiondispatch->entrepot_id = GETPOSTINT($ent); - $expeditiondispatch->fk_origin_line = GETPOSTINT($fk_commandedet); + $expeditiondispatch->fk_elementdet = GETPOSTINT($fk_commandedet); $expeditiondispatch->qty = $newqty; if ($newqty > 0) { @@ -380,8 +380,8 @@ $morejs = array('/expedition/js/lib_dispatch.js.php'); llxHeader('', $title, $help_url, '', 0, 0, $morejs); if ($object->id > 0 || !empty($object->ref)) { - $lines = $object->lines; // This is an array of detail of line, on line per source order line found intolines[]->fk_origin_line, then each line may have sub data - //var_dump($lines[0]->fk_origin_line); exit; + $lines = $object->lines; // This is an array of detail of line, on line per source order line found intolines[]->fk_elementdet, then each line may have sub data + //var_dump($lines[0]->fk_elementdet); exit; $num_prod = count($lines); @@ -550,10 +550,10 @@ if ($object->id > 0 || !empty($object->ref)) { // Get list of lines of the shipment $products_dispatched, with qty dispatched for each product id $products_dispatched = array(); - $sql = "SELECT ed.fk_origin_line as rowid, sum(ed.qty) as qty"; + $sql = "SELECT ed.fk_elementdet as rowid, sum(ed.qty) as qty"; $sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed"; $sql .= " WHERE ed.fk_expedition = ".((int) $object->id); - $sql .= " GROUP BY ed.fk_origin_line"; + $sql .= " GROUP BY ed.fk_elementdet"; $resql = $db->query($sql); if ($resql) { @@ -777,10 +777,10 @@ if ($object->id > 0 || !empty($object->ref)) { $sql .= " eb.batch, eb.eatby, eb.sellby, cd.fk_product"; $sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as eb on ed.rowid = eb.fk_expeditiondet"; - $sql .= " JOIN ".MAIN_DB_PREFIX."commandedet as cd on ed.fk_origin_line = cd.rowid"; - $sql .= " WHERE ed.fk_origin_line =".(int) $objp->rowid; + $sql .= " JOIN ".MAIN_DB_PREFIX."commandedet as cd on ed.fk_elementdet = cd.rowid"; + $sql .= " WHERE ed.fk_elementdet =".(int) $objp->rowid; $sql .= " AND ed.fk_expedition =".(int) $object->id; - $sql .= " ORDER BY ed.rowid, ed.fk_origin_line"; + $sql .= " ORDER BY ed.rowid, ed.fk_elementdet"; $resultsql = $db->query($sql); $j = 0; diff --git a/htdocs/expedition/list.php b/htdocs/expedition/list.php index 0c30741910b..17c4e818481 100644 --- a/htdocs/expedition/list.php +++ b/htdocs/expedition/list.php @@ -294,7 +294,7 @@ if (!empty($extrafields->attributes[$object->table_element]['label']) && is_arra } if ($search_all) { $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'expeditiondet as ed ON e.rowid=ed.fk_expedition'; - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commandedet as pd ON pd.rowid=ed.fk_origin_line'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commandedet as pd ON pd.rowid=ed.fk_elementdet'; } $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)"; @@ -433,17 +433,17 @@ if (!empty($searchCategoryProductList)) { $listofcategoryid = ''; foreach ($searchCategoryProductList as $searchCategoryProduct) { if (intval($searchCategoryProduct) == -2) { - $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd WHERE ed.fk_expedition = e.rowid AND ed.fk_origin_line = cd.rowid AND cd.fk_product = ck.fk_product)"; + $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd WHERE ed.fk_expedition = e.rowid AND ed.fk_elementdet = cd.rowid AND cd.fk_product = ck.fk_product)"; } elseif (intval($searchCategoryProduct) > 0) { if ($searchCategoryProductOperator == 0) { - $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd WHERE ed.fk_expedition = e.rowid AND ed.fk_origin_line = cd.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")"; + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd WHERE ed.fk_expedition = e.rowid AND ed.fk_elementdet = cd.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")"; } else { $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct); } } } if ($listofcategoryid) { - $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd WHERE ed.fk_expedition = e.rowid AND ed.fk_origin_line = cd.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd WHERE ed.fk_expedition = e.rowid AND ed.fk_elementdet = cd.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; } if ($searchCategoryProductOperator == 1) { if (!empty($searchCategoryProductSqlList)) { diff --git a/htdocs/install/mysql/migration/19.0.0-20.0.0.sql b/htdocs/install/mysql/migration/19.0.0-20.0.0.sql index ff25b08f3da..65cd026efb5 100644 --- a/htdocs/install/mysql/migration/19.0.0-20.0.0.sql +++ b/htdocs/install/mysql/migration/19.0.0-20.0.0.sql @@ -285,6 +285,9 @@ ALTER TABLE llx_socpeople ADD COLUMN fk_parent integer NULL; ALTER TABLE llx_expeditiondet ADD COLUMN fk_element integer; ALTER TABLE llx_expeditiondet ADD COLUMN element_type varchar(50) DEFAULT 'order' NOT NULL; +ALTER TABLE llx_expeditiondet CHANGE COLUMN fk_origin_line fk_elementdet integer; +ALTER TABLE llx_expeditiondet DROP INDEX idx_expeditiondet_fk_origin_line; +ALTER TABLE llx_expeditiondet ADD INDEX idx_expeditiondet_fk_elementdet (fk_elementdet); ALTER TABLE llx_receptiondet_batch CHANGE COLUMN fk_commande fk_element integer; ALTER TABLE llx_receptiondet_batch CHANGE COLUMN fk_commandefourndet fk_elementdet integer; diff --git a/htdocs/install/mysql/tables/llx_expeditiondet.key.sql b/htdocs/install/mysql/tables/llx_expeditiondet.key.sql index b37ae457fe3..5417074f917 100644 --- a/htdocs/install/mysql/tables/llx_expeditiondet.key.sql +++ b/htdocs/install/mysql/tables/llx_expeditiondet.key.sql @@ -19,5 +19,5 @@ ALTER TABLE llx_expeditiondet ADD INDEX idx_expeditiondet_fk_expedition (fk_expedition); -ALTER TABLE llx_expeditiondet ADD INDEX idx_expeditiondet_fk_origin_line (fk_origin_line); +ALTER TABLE llx_expeditiondet ADD INDEX idx_expeditiondet_fk_elementdet (fk_elementdet); ALTER TABLE llx_expeditiondet ADD CONSTRAINT fk_expeditiondet_fk_expedition FOREIGN KEY (fk_expedition) REFERENCES llx_expedition (rowid); diff --git a/htdocs/install/mysql/tables/llx_expeditiondet.sql b/htdocs/install/mysql/tables/llx_expeditiondet.sql index ca52ae7a912..65a9244f7dc 100644 --- a/htdocs/install/mysql/tables/llx_expeditiondet.sql +++ b/htdocs/install/mysql/tables/llx_expeditiondet.sql @@ -24,7 +24,7 @@ create table llx_expeditiondet rowid integer AUTO_INCREMENT PRIMARY KEY, fk_expedition integer NOT NULL, -- ID of parent object fk_element integer, -- ID of main source object - fk_origin_line integer, -- ID of line of source object (proposal, sale order). TODO should be renamed into fk_elementdet in SQL files and code in same PR + fk_elementdet integer, -- ID of line of source object (proposal, sale order) element_type varchar(50) DEFAULT 'order' NOT NULL, -- Type of source object ('order', ...) qty real, -- Quantity fk_entrepot integer, -- Warehouse for departure of product diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 27d8c136275..479d6b9e6b2 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3422,7 +3422,7 @@ class Product extends CommonObject $sql .= " AND c.rowid = cd.fk_commande"; $sql .= " AND e.fk_soc = s.rowid"; $sql .= " AND e.entity IN (".getEntity($forVirtualStock && getDolGlobalString('STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE') ? 'stock' : 'expedition').")"; - $sql .= " AND ed.fk_origin_line = cd.rowid"; + $sql .= " AND ed.fk_elementdet = cd.rowid"; $sql .= " AND cd.fk_product = ".((int) $this->id); if (!$user->hasRight('societe', 'client', 'voir') && !$forVirtualStock) { $sql .= " AND e.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); diff --git a/htdocs/product/reassort.php b/htdocs/product/reassort.php index 32d15a43939..c9c0fe6202c 100644 --- a/htdocs/product/reassort.php +++ b/htdocs/product/reassort.php @@ -208,7 +208,7 @@ if (!getDolGlobalString('PRODUCT_STOCK_LIST_SHOW_WITH_PRECALCULATED_DENORMALIZED SELECT SUM(ed3.qty) as qty FROM " . MAIN_DB_PREFIX . "expeditiondet as ed3 LEFT JOIN " . MAIN_DB_PREFIX . "expedition as e3 ON e3.rowid = ed3.fk_expedition - LEFT JOIN " . MAIN_DB_PREFIX . "commandedet as cd3 ON ed3.fk_origin_line = cd3.rowid + LEFT JOIN " . MAIN_DB_PREFIX . "commandedet as cd3 ON ed3.fk_elementdet = cd3.rowid LEFT JOIN " . MAIN_DB_PREFIX . "commande as c3 ON c3.rowid = cd3.fk_commande WHERE e3.entity IN (1) AND cd3.fk_product = p.rowid AND c3.fk_statut IN (1,2) AND e3.fk_statut IN (1,2) AND ed3.qty <> 0 ) IS NOT NULL diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index c56ab78c005..a6a64fb2dae 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -431,7 +431,7 @@ if ($usevirtualstock) { $sqlExpeditionsCli .= " ".MAIN_DB_PREFIX."expeditiondet as ed2,"; $sqlExpeditionsCli .= " ".MAIN_DB_PREFIX."commande as c2,"; $sqlExpeditionsCli .= " ".MAIN_DB_PREFIX."commandedet as cd2"; - $sqlExpeditionsCli .= " WHERE ed2.fk_expedition = e2.rowid AND cd2.rowid = ed2.fk_origin_line AND e2.entity IN (".getEntity(getDolGlobalString('STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE') ? 'stock' : 'expedition').")"; + $sqlExpeditionsCli .= " WHERE ed2.fk_expedition = e2.rowid AND cd2.rowid = ed2.fk_elementdet AND e2.entity IN (".getEntity(getDolGlobalString('STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE') ? 'stock' : 'expedition').")"; $sqlExpeditionsCli .= " AND cd2.fk_commande = c2.rowid"; $sqlExpeditionsCli .= " AND c2.fk_statut IN (1,2)"; $sqlExpeditionsCli .= " AND cd2.fk_product = p.rowid";