diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php
index 05827451553..15ded6dd8d9 100644
--- a/htdocs/comm/propal/class/propal.class.php
+++ b/htdocs/comm/propal/class/propal.class.php
@@ -1574,6 +1574,9 @@ class Propal extends CommonObject
$sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = ".$this->id;
if ( $this->db->query($sql) )
{
+ // Delete all rang of files
+ $this->delAllRangOfLines();
+
$sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = ".$this->id;
if ( $this->db->query($sql) )
{
diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index d2aafc8fb7e..94be8f6312c 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -1992,6 +1992,9 @@ class Commande extends CommonObject
dol_syslog("CustomerOrder::delete error", LOG_ERR);
$err++;
}
+
+ // Delete all rang of lines
+ $this->delAllRangOfLines();
// Delete order
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = ".$this->id;
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index 9ec7698fe56..07fe2959003 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -1801,7 +1801,7 @@ else
}
else
{*/
- print ''.$langs->trans('ShipProduct').'';
+ print ''.$langs->trans('ShipProduct').'';
//}
}
else
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 110e043f2ae..2b6ff791acc 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -1030,6 +1030,8 @@ class Facture extends CommonObject
$resql=$this->db->query($sql);
if ($resql)
{
+ $this->delAllRangOfLines();
+
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db);
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 6f3a89fc2fb..9e941b159e9 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -754,7 +754,7 @@ class CommonObject
/**
* Add position of line (rang)
*/
- function addRangOfLine($childid,$childtype,$rang)
+ function addRangOfLine($childid,$childtype,$rang=0)
{
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'element_rang (';
$sql.= 'fk_parent, parenttype, fk_child, childtype, rang';
@@ -784,6 +784,21 @@ class CommonObject
dol_print_error($this->db);
}
}
+
+ /**
+ * Delete all position of lines (rang)
+ */
+ function delAllRangOfLines()
+ {
+ $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'element_rang';
+ $sql.= ' WHERE fk_parent = '.$this->id;
+ $sql.= ' AND parenttype = "'.$this->element.'"';
+
+ if (! $this->db->query($sql) )
+ {
+ dol_print_error($this->db);
+ }
+ }
/**
* Update position of line (rang)
diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php
index 4fbf5aef231..c8bd7bb64f7 100644
--- a/htdocs/expedition/class/expedition.class.php
+++ b/htdocs/expedition/class/expedition.class.php
@@ -231,13 +231,19 @@ class Expedition extends CommonObject
$sql.= ", ".$qty;
$sql.= ")";
- if (! $this->db->query($sql))
+ if ($this->db->query($sql))
{
- $error++;
- }
+ $this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'expeditiondet');
- if (! $error) return 1;
- else return -1;
+ $this->rang = 0; // TODO en attendant une gestion de la disposition
+ $this->addRangOfLine($this->rowid,$this->element,$this->rang);
+
+ return 1;
+ }
+ else
+ {
+ return -1;
+ }
}
/**
@@ -544,16 +550,18 @@ class Expedition extends CommonObject
*
*
*/
- function delete_line($id)
+ function delete_line($lineid)
{
if ($this->statut == 0)
{
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet";
- $sql.= " WHERE rowid = ".$id;
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet";
+ $sql.= " WHERE rowid = ".$lineid;
if ($this->db->query($sql) )
{
$this->update_price();
+
+ $this->delRangOfLine($lineid, $this->element);
return 1;
}
@@ -679,6 +687,9 @@ class Expedition extends CommonObject
if ( $this->db->query($sql) )
{
+ // Delete all rang of files
+ $this->delAllRangOfLines();
+
$sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element";
$sql.= " WHERE fk_target = ".$this->id;
$sql.= " AND targettype = '".$this->element."'";
@@ -752,10 +763,14 @@ class Expedition extends CommonObject
$sql.= ", ed.qty as qty_shipped, ed.fk_origin_line, ed.fk_entrepot";
$sql.= ", p.ref, p.fk_product_type, p.label, p.weight, p.weight_units, p.volume, p.volume_units";
$sql.= " FROM (".MAIN_DB_PREFIX."expeditiondet as ed,";
- $sql.= " ".MAIN_DB_PREFIX."commandedet as cd)";
+ $sql.= " ".MAIN_DB_PREFIX."commandedet as cd)"; // FIXME utiliser llx_element_element
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_rang as r ON r.fk_parent = ed.fk_expedition AND r.parenttype = '".$this->element."'";
$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.= " AND r.fk_child = ed.rowid";
+ $sql.= " AND r.childtype = '".$this->element."'";
+ $sql.= " AND ed.fk_origin_line = cd.rowid"; // FIXME utiliser llx_element_element
+ $sql.= " ORDER by r.rang";
dol_syslog("Expedition::fetch_lines sql=".$sql);
$resql = $this->db->query($sql);
diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php
index 4841f955b2d..b7177af0881 100644
--- a/htdocs/expedition/fiche.php
+++ b/htdocs/expedition/fiche.php
@@ -49,6 +49,7 @@ $langs->load('other');
$langs->load('propal');
$origin = $_GET["origin"]?$_GET["origin"]:$_POST["origin"]; // Example: commande, propal
+if (empty($origin)) $origin = 'expedition';
$origin_id = isset($_REQUEST["id"])?$_REQUEST["id"]:'';
if (empty($origin_id)) $origin_id = $_GET["origin_id"]?$_GET["origin_id"]:$_POST["origin_id"]; // Id of order or propal
if (empty($origin_id)) $origin_id = $_GET["object_id"]?$_GET["object_id"]:$_POST["object_id"]; // Id of order or propal
@@ -57,7 +58,7 @@ $id = $origin_id;
// Security check
if ($user->societe_id) $socid=$user->societe_id;
-$result=restrictedArea($user,$origin,$origin_id,'');
+$result=restrictedArea($user,$origin,$origin_id);
/*
diff --git a/htdocs/expedition/shipment.php b/htdocs/expedition/shipment.php
index 00baf722bd7..d37a8c8f20b 100644
--- a/htdocs/expedition/shipment.php
+++ b/htdocs/expedition/shipment.php
@@ -394,11 +394,12 @@ if ($id > 0 || ! empty($ref))
$sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid,';
$sql.= ' p.description as product_desc, p.fk_product_type as product_type';
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_rang as r ON r.fk_parent = cd.fk_commande AND r.parenttype = '".$commande->element."'";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
$sql.= " WHERE cd.fk_commande = ".$commande->id;
- // $sql.= " AND p.fk_product_type <> 1"; Why this line ?
- //$sql.= " GROUP by cd.rowid, cd.fk_product";
- $sql.= " ORDER BY cd.rang, cd.rowid";
+ $sql.= " AND r.fk_child = cd.rowid";
+ $sql.= " AND r.childtype = '".$commande->element."'";
+ $sql.= " ORDER BY r.rang, cd.rowid";
//print $sql;
dol_syslog("commande.php sql=".$sql, LOG_DEBUG);
diff --git a/htdocs/install/mysql/tables/llx_expeditiondet.sql b/htdocs/install/mysql/tables/llx_expeditiondet.sql
index 6bd6e54a437..63a490a0ae5 100644
--- a/htdocs/install/mysql/tables/llx_expeditiondet.sql
+++ b/htdocs/install/mysql/tables/llx_expeditiondet.sql
@@ -25,6 +25,5 @@ create table llx_expeditiondet
fk_expedition integer NOT NULL,
fk_origin_line integer, -- Correspondance de la ligne avec le document d'origine (propal, commande)
fk_entrepot integer, -- Entrepot de depart du produit
- qty real, -- Quantity
- rang integer DEFAULT 0
+ qty real -- Quantity
)type=innodb;
diff --git a/htdocs/install/mysql/tables/llx_livraisondet.sql b/htdocs/install/mysql/tables/llx_livraisondet.sql
index e720eb12bb6..2cc5a6d73a6 100644
--- a/htdocs/install/mysql/tables/llx_livraisondet.sql
+++ b/htdocs/install/mysql/tables/llx_livraisondet.sql
@@ -28,6 +28,5 @@ create table llx_livraisondet
description text,
qty real, -- quantity
subprice double(24,8) DEFAULT 0, -- prix unitaire
- total_ht double(24,8) DEFAULT 0, -- Total HT de la ligne toute quantite
- rang integer DEFAULT 0
+ total_ht double(24,8) DEFAULT 0 -- Total HT de la ligne toute quantite
)type=innodb;
diff --git a/htdocs/install/mysql/tables/llx_projet_task.sql b/htdocs/install/mysql/tables/llx_projet_task.sql
index ca28fcb5a6d..3cdf2c6edf7 100644
--- a/htdocs/install/mysql/tables/llx_projet_task.sql
+++ b/htdocs/install/mysql/tables/llx_projet_task.sql
@@ -38,6 +38,5 @@ create table llx_projet_task
fk_user_valid integer, -- user who validated the task
fk_statut smallint DEFAULT 0 NOT NULL,
note_private text,
- note_public text,
- rang integer DEFAULT 0
+ note_public text
)type=innodb;
diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php
index 40a7104a5e1..43c24fe7c05 100644
--- a/htdocs/install/upgrade2.php
+++ b/htdocs/install/upgrade2.php
@@ -3074,6 +3074,12 @@ function migrate_element_rang($db,$langs,$conf)
$tables[] = array('name'=>'commandedet','element'=>'commande','fk_element'=>'fk_commande');
//llx_facturedet
$tables[] = array('name'=>'facturedet','element'=>'facture','fk_element'=>'fk_facture');
+ //llx_expeditiondet
+ $tables[] = array('name'=>'expeditiondet','element'=>'shipping','fk_element'=>'fk_expedition');
+ //llx_livraisondet
+ $tables[] = array('name'=>'livraisondet','element'=>'delivery','fk_element'=>'fk_livraison');
+ //llx_projet_task
+ //$tables[] = array('name'=>'projet_task','element'=>'project','fk_element'=>'fk_projet');
foreach($tables as $table)
{
diff --git a/htdocs/livraison/class/livraison.class.php b/htdocs/livraison/class/livraison.class.php
index 3020f2cc3e5..b4ebce6acf7 100644
--- a/htdocs/livraison/class/livraison.class.php
+++ b/htdocs/livraison/class/livraison.class.php
@@ -224,15 +224,19 @@ class Livraison extends CommonObject
$sql.= $qty.")";
dol_syslog("Livraison::create_line sql=".$sql, LOG_DEBUG);
- if (! $this->db->query($sql) )
+ if ($this->db->query($sql))
{
- $error++;
- }
+ $this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'livraisondet');
- if ($error == 0 )
- {
+ $this->rang = 0; // TODO en attendant une gestion de la disposition
+ $this->addRangOfLine($this->rowid,$this->element,$this->rang);
+
return 1;
}
+ else
+ {
+ return -1;
+ }
}
/**
@@ -536,16 +540,18 @@ class Livraison extends CommonObject
*
*
*/
- function delete_line($idligne)
+ function delete_line($lineid)
{
if ($this->statut == 0)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet";
- $sql.= " WHERE rowid = ".$idligne;
+ $sql.= " WHERE rowid = ".$lineid;
if ($this->db->query($sql) )
{
$this->update_price();
+
+ $this->delRangOfLine($lineid, $this->element);
return 1;
}
@@ -568,6 +574,9 @@ class Livraison extends CommonObject
$sql.= " WHERE fk_livraison = ".$this->id;
if ( $this->db->query($sql) )
{
+ // Delete all rang of files
+ $this->delAllRangOfLines();
+
$sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element";
$sql.= " WHERE fk_target = ".$this->id;
$sql.= " AND targettype = '".$this->element."'";
@@ -576,7 +585,7 @@ class Livraison extends CommonObject
$sql = "DELETE FROM ".MAIN_DB_PREFIX."livraison";
$sql.= " WHERE rowid = ".$this->id;
if ( $this->db->query($sql) )
- {
+ {
$this->db->commit();
// On efface le repertoire de pdf provisoire
@@ -663,10 +672,15 @@ class Livraison extends CommonObject
$sql = "SELECT ld.rowid, ld.fk_product, ld.description, ld.subprice, ld.total_ht, ld.qty as qty_shipped,";
$sql.= " cd.qty as qty_asked,";
$sql.= " p.ref, p.fk_product_type as fk_product_type, p.label as label, p.description as product_desc";
- $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."livraisondet as ld";
+ $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; // TODO utiliser llx_element_element
+ $sql.= ", ".MAIN_DB_PREFIX."livraisondet as ld";
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_rang as r ON r.fk_parent = ld.fk_livraison AND r.parenttype = '".$this->element."'";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on p.rowid = ld.fk_product";
$sql.= " WHERE ld.fk_origin_line = cd.rowid";
$sql.= " AND ld.fk_livraison = ".$this->id;
+ $sql.= " AND r.fk_child = ld.rowid";
+ $sql.= " AND r.childtype = '".$this->element."'";
+ $sql.= " ORDER by r.rang";
dol_syslog("Livraison::fetch_lignes sql=".$sql);
$resql = $this->db->query($sql);