diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php
index cbc6141ac1b..6978de14e40 100644
--- a/htdocs/commande/card.php
+++ b/htdocs/commande/card.php
@@ -1232,14 +1232,16 @@ $formorder = new FormOrder($db);
*
* *******************************************************************
*/
-if ($action == 'create' && $user->rights->commande->creer) {
+if ($action == 'create' && $user->rights->commande->creer)
+{
print_fiche_titre($langs->trans('CreateOrder'));
$soc = new Societe($db);
if ($socid > 0)
$res = $soc->fetch($socid);
- if (! empty($origin) && ! empty($originid)) {
+ if (! empty($origin) && ! empty($originid))
+ {
// Parse element/subelement (ex: project_task)
$element = $subelement = $origin;
if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
@@ -1353,7 +1355,7 @@ if ($action == 'create' && $user->rights->commande->creer) {
/*
* Contact de la commande
- */
+ */
if ($socid > 0) {
print "
| " . $langs->trans("DefaultContact") . ' | ';
$form->select_contacts($soc->id, $setcontact, 'contactid', 1, $srccontactslist);
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index b4aff6002d0..aed2aa3b224 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -2480,12 +2480,13 @@ abstract class CommonObject
$tplpath = 'comm/'.$element;
if (empty($conf->propal->enabled)) continue; // Do not show if module disabled
}
- else if ($objecttype == 'shipping') {
+ else if ($objecttype == 'shipping' || $objecttype == 'shipment') {
$tplpath = 'expedition';
if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled
}
else if ($objecttype == 'delivery') {
$tplpath = 'livraison';
+ if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled
}
else if ($objecttype == 'invoice_supplier') {
$tplpath = 'fourn/facture';
diff --git a/htdocs/core/lib/order.lib.php b/htdocs/core/lib/order.lib.php
index abdf1b648a5..1e0f2f50139 100644
--- a/htdocs/core/lib/order.lib.php
+++ b/htdocs/core/lib/order.lib.php
@@ -52,7 +52,7 @@ function commande_prepare_head($object)
|| ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->lire))
{
$head[$h][0] = DOL_URL_ROOT.'/expedition/shipment.php?id='.$object->id;
- if ($conf->expedition_bon->enabled) $text=$langs->trans("Shipment");
+ if ($conf->expedition_bon->enabled) $text=$langs->trans("Shipments");
if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled) $text.='/';
if ($conf->livraison_bon->enabled) $text.=$langs->trans("Receivings");
$head[$h][1] = $text;
diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php
index 8ecae0ff2dc..846323ba6b6 100644
--- a/htdocs/expedition/card.php
+++ b/htdocs/expedition/card.php
@@ -144,45 +144,59 @@ if (empty($reshook))
$object->note_private = GETPOST('note_private');
$object->note_public = GETPOST('note_public');
+ $batch_line = array();
+
$num=count($objectsrc->lines);
$totalqty=0;
for ($i = 0; $i < $num; $i++)
{
- $qty = "qtyl".$i;
- $j=0;
+ $idl="idl".$i;
+
$sub_qty=array();
$subtotalqty=0;
- $idl="idl".$i;
+
+ $j=0;
$batch="batchl".$i."_0";
- if (isset($_POST[$batch])) {
+ $qty = "qtyl".$i;
+
+ if (isset($_POST[$batch]))
+ {
//shipment line with batch-enable product
$qty .= '_'.$j;
- while (isset($_POST[$batch])) {
+ while (isset($_POST[$batch]))
+ {
+ // save line of detail into sub_qty
$sub_qty[$j]['q']=GETPOST($qty,'int');
$sub_qty[$j]['id_batch']=GETPOST($batch,'int');
+
$subtotalqty+=$sub_qty[$j]['q'];
+
$j++;
$batch="batchl".$i."_".$j;
$qty = "qtyl".$i.'_'.$j;
-
}
- $batch_line[$i]['detail']=$sub_qty;
+
+ $batch_line[$i]['detail']=$sub_qty; // array of details
$batch_line[$i]['qty']=$subtotalqty;
$batch_line[$i]['ix_l']=GETPOST($idl,'int');
+
$totalqty+=$subtotalqty;
- } else {
- //Standard product
+ }
+ else
+ {
+ //shipment line for product with no batch management
if (GETPOST($qty,'int') > 0) $totalqty+=GETPOST($qty,'int');
}
}
- if ($totalqty > 0)
+ if ($totalqty > 0) // There is at least one thing to ship
{
//var_dump($_POST);exit;
for ($i = 0; $i < $num; $i++)
{
$qty = "qtyl".$i;
- if (! isset($batch_line[$i])) {
+ if (! isset($batch_line[$i]))
+ { // not batch mode
if (GETPOST($qty,'int') > 0 || (GETPOST($qty,'int') == 0 && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS))
{
$ent = "entl".$i;
@@ -197,8 +211,11 @@ if (empty($reshook))
$error++;
}
}
- } else {
- if ($batch_line[$i]['qty']>0) {
+ }
+ else
+ { // batch mode
+ if ($batch_line[$i]['qty']>0)
+ {
$ret=$object->addline_batch($batch_line[$i]);
if ($ret < 0)
{
@@ -211,7 +228,7 @@ if (empty($reshook))
if (! $error)
{
- $ret=$object->create($user);
+ $ret=$object->create($user); // This create shipment (like Odoo picking) and line of shipments. Stock movement will when validating shipment.
if ($ret <= 0)
{
$mesg=' '.$object->error.' ';
diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php
index 228845d162e..379d9849b8f 100644
--- a/htdocs/expedition/class/expedition.class.php
+++ b/htdocs/expedition/class/expedition.class.php
@@ -255,13 +255,16 @@ class Expedition extends CommonObject
$num=count($this->lines);
for ($i = 0; $i < $num; $i++)
{
- if (! isset($this->lines[$i]->detail_batch)) {
- if (! $this->create_line($this->lines[$i]->entrepot_id, $this->lines[$i]->origin_line_id, $this->lines[$i]->qty) > 0)
- {
- $error++;
+ if (! isset($this->lines[$i]->detail_batch))
+ { // no batch management
+ if (! $this->create_line($this->lines[$i]->entrepot_id, $this->lines[$i]->origin_line_id, $this->lines[$i]->qty) > 0)
+ {
+ $error++;
+ }
}
- } else {
- if (! $this->create_line_ext($this->lines[$i]) > 0)
+ else
+ { // with batch management
+ if (! $this->create_line_batch($this->lines[$i]) > 0)
{
$error++;
}
@@ -366,28 +369,37 @@ class Expedition extends CommonObject
if (! $error) return 1;
else return -1;
}
+
+
/**
* Create a expedition line with eat-by date
*
* @param object $line_ext full line informations
* @return int <0 if KO, >0 if OK
*/
- function create_line_ext($line_ext)
+ function create_line_batch($line_ext)
{
$error = 0;
- if ( $this->create_line(($line_ext->entrepot_id?$line_ext->entrepot_id:'null'),$line_ext->origin_line_id,$line_ext->qty)<0)
+ if ($this->create_line(($line_ext->entrepot_id?$line_ext->entrepot_id:'null'),$line_ext->origin_line_id,$line_ext->qty) < 0)
{
$error++;
- } else {
+ }
+
+ if (! $error)
+ {
$line_id= $this->db->last_insert_id(MAIN_DB_PREFIX."expeditiondet");
$tab=$line_ext->detail_batch;
- foreach ($tab as $detbatch) {
- if (! ($detbatch->create($line_id) >0)) {
+ foreach ($tab as $detbatch)
+ {
+ if (! ($detbatch->create($line_id) >0)) // Create an expeditionlinebatch
+ {
$error++;
}
}
}
+
+
if (! $error) return 1;
else return -1;
}
@@ -612,10 +624,13 @@ class Expedition extends CommonObject
$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, $obj->subprice, $langs->trans("ShipmentValidatedInDolibarr",$numref));
if ($result < 0) { $error++; break; }
- if (! empty($conf->productbatch->enabled)) {
- $details=ExpeditionLigneBatch::fetchAll($this->db,$obj->rowid);
- if (! empty($details)) {
- foreach ($details as $dbatch) {
+ if (! empty($conf->productbatch->enabled))
+ {
+ $details=ExpeditionLineBatch::fetchAll($this->db,$obj->rowid);
+ if (! empty($details))
+ {
+ foreach ($details as $dbatch)
+ {
$result=$mouvS->livraison_batch($dbatch->fk_origin_stock,$dbatch->dluo_qty);
if ($result < 0) { $error++; $this->errors[]=$mouvS->$error; break 2; }
}
@@ -751,7 +766,8 @@ class Expedition extends CommonObject
$line->origin_line_id = $id;
$line->qty = $qty;
- if($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT) {
+ if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT)
+ {
$orderline = new OrderLine($this->db);
$orderline->fetch($id);
$fk_product = $orderline->fk_product;
@@ -762,7 +778,8 @@ class Expedition extends CommonObject
$result=$product->fetch($fk_product);
$product_type=$product->type;
- if($product_type == 0 && $product->stock_reel < $qty) {
+ if($product_type == 0 && $product->stock_reel < $qty)
+ {
$this->error=$langs->trans('ErrorStockIsNotEnough');
$this->db->rollback();
return -3;
@@ -777,19 +794,23 @@ class Expedition extends CommonObject
* Add a shipment line with batch record
*
* @param array $dbatch Array of value (key 'detail' -> Array, key 'qty' total quantity for line, key ix_l : original line index)
- * @return int <0 if KO, >0 if OK
+ * @return int <0 if KO, >0 if OK
*/
function addline_batch($dbatch)
{
$num = count($this->lines);
- if ($dbatch['qty']>0) {
+ if ($dbatch['qty']>0)
+ {
$line = new ExpeditionLigne($this->db);
$tab=array();
- foreach ($dbatch['detail'] as $key=>$value) {
- if ($value['q']>0) {
- $linebatch = new ExpeditionLigneBatch($this->db);
- $ret=$linebatch->fetchFromStock($value['id_batch']);
- if ($ret<0) {
+ foreach ($dbatch['detail'] as $key=>$value)
+ {
+ if ($value['q']>0)
+ {
+ $linebatch = new ExpeditionLineBatch($this->db);
+ $ret=$linebatch->fetchFromStock($value['id_batch']); // load serial, sellby, eatby
+ if ($ret<0)
+ {
$this->error=$linebatch->error;
return -1;
}
@@ -932,10 +953,13 @@ class Expedition extends CommonObject
$this->db->begin();
- if ($conf->productbatch->enabled) {
+ if ($conf->productbatch->enabled)
+ {
require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php';
- if ( ExpeditionLigneBatch::deletefromexp($this->db,$this->id)<0)
- {$error++;$this->errors[]="Error ".$this->db->lasterror();}
+ if (ExpeditionLineBatch::deletefromexp($this->db,$this->id) < 0)
+ {
+ $error++;$this->errors[]="Error ".$this->db->lasterror();
+ }
}
// Stock control
if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > 0)
@@ -1174,10 +1198,11 @@ class Expedition extends CommonObject
* May be conf is not well initialized for dark reason
*/
require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php';
- if ($originline != $obj->fk_origin_line) {
- $line->detail_batch = ExpeditionLigneBatch::fetchAll($this->db,$obj->line_id);
+ if ($originline != $obj->fk_origin_line)
+ {
+ $line->detail_batch = ExpeditionLineBatch::fetchAll($this->db,$obj->line_id);
} else {
- $line->detail_batch = array_merge($line->detail_batch,ExpeditionLigneBatch::fetchAll($this->db,$obj->line_id));
+ $line->detail_batch = array_merge($line->detail_batch,ExpeditionLineBatch::fetchAll($this->db,$obj->line_id));
}
}
if ($originline != $obj->fk_origin_line) {
diff --git a/htdocs/expedition/class/expeditionbatch.class.php b/htdocs/expedition/class/expeditionbatch.class.php
index ea179710271..cc5726ed0c8 100644
--- a/htdocs/expedition/class/expeditionbatch.class.php
+++ b/htdocs/expedition/class/expeditionbatch.class.php
@@ -17,16 +17,16 @@
*/
/**
- * \file expedition/class/productbatch.class.php
+ * \file expedition/class/expeditionbatch.class.php
* \ingroup productbatch
- * \brief This file implements CRUD method for managing product's shipment
+ * \brief This file implements CRUD method for managing shipment batch lines
* with batch record
*/
/**
* CRUD class for batch number management within shipment
*/
-class ExpeditionLigneBatch extends CommonObject
+class ExpeditionLineBatch extends CommonObject
{
var $element='expeditionlignebatch'; //!< Id that identify managed objects
private static $_table_element='expeditiondet_batch'; //!< Name of table without prefix where object is stored
@@ -115,9 +115,9 @@ class ExpeditionLigneBatch extends CommonObject
$sql.= ", fk_origin_stock";
$sql.= ") VALUES (";
$sql.= $id_line_expdet.",";
- $sql.= " ".(! isset($this->sellby) || dol_strlen($this->sellby)==0?'NULL':"'".$this->db->idate($this->sellby))."',";
- $sql.= " ".(! isset($this->eatby) || dol_strlen($this->eatby)==0?'NULL':"'".$this->db->idate($this->eatby))."',";
- $sql.= " ".(! isset($this->batch)?'NULL':"'".$this->db->escape($this->batch)."'").",";
+ $sql.= " ".(! isset($this->sellby) || dol_strlen($this->sellby)==0?'NULL':("'".$this->db->idate($this->sellby))."'").",";
+ $sql.= " ".(! isset($this->eatby) || dol_strlen($this->eatby)==0?'NULL':("'".$this->db->idate($this->eatby))."'").",";
+ $sql.= " ".(! isset($this->batch)?'NULL':("'".$this->db->escape($this->batch)."'")).",";
$sql.= " ".(! isset($this->dluo_qty)?'NULL':$this->dluo_qty).",";
$sql.= " ".(! isset($this->fk_origin_stock)?'NULL':$this->fk_origin_stock);
$sql.= ")";
@@ -174,7 +174,7 @@ class ExpeditionLigneBatch extends CommonObject
*
* @param object $db Database object
* @param int $id_line_expdet id of shipment line
- * @return variant -1 if KO, array of ExpeditionLigneBatch if OK
+ * @return variant -1 if KO, array of ExpeditionLineBatch if OK
*/
static function fetchAll($db,$id_line_expdet)
{
diff --git a/htdocs/install/mysql/migration/repair.sql b/htdocs/install/mysql/migration/repair.sql
index 9e1ca7bb6f9..fe0f8fb2a13 100755
--- a/htdocs/install/mysql/migration/repair.sql
+++ b/htdocs/install/mysql/migration/repair.sql
@@ -73,6 +73,18 @@ delete from llx_livraisondet where fk_livraison not in (select fk_target from ll
delete from llx_livraison where rowid not in (select fk_target from llx_element_element where targettype = 'delivery') AND rowid not in (select fk_source from llx_element_element where sourcetype = 'delivery');
+-- Fix delete element_element orphelins (right side)
+delete from llx_element_element where targettype='shipping' and fk_target not in (select rowid from llx_expedition);
+delete from llx_element_element where targettype='propal' and fk_target not in (select rowid from llx_propal);
+delete from llx_element_element where targettype='facture' and fk_target not in (select rowid from llx_facture);
+delete from llx_element_element where targettype='commande' and fk_target not in (select rowid from llx_commande);
+-- Fix delete element_element orphelins (left side)
+delete from llx_element_element where sourcetype='shipping' and fk_source not in (select rowid from llx_expedition);
+delete from llx_element_element where sourcetype='propal' and fk_source not in (select rowid from llx_propal);
+delete from llx_element_element where sourcetype='facture' and fk_source not in (select rowid from llx_facture);
+delete from llx_element_element where sourcetype='commande' and fk_source not in (select rowid from llx_commande);
+
+
UPDATE llx_product SET canvas = NULL where canvas = 'default@product';
UPDATE llx_product SET canvas = NULL where canvas = 'service@product';
|