diff --git a/htdocs/core/modules/modReception.class.php b/htdocs/core/modules/modReception.class.php
index 71dc0b9623f..860181935e1 100644
--- a/htdocs/core/modules/modReception.class.php
+++ b/htdocs/core/modules/modReception.class.php
@@ -241,7 +241,7 @@ class modReception 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_reception AND ed.fk_commandefourndet = cd.rowid';
+ $this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = ed.fk_reception AND ed.fk_elementdet = cd.rowid';
$this->export_sql_end[$r] .= ' AND c.entity IN ('.getEntity('reception').')';
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/dispatch.php b/htdocs/expedition/dispatch.php
index 7e3edde6355..ac376353e85 100644
--- a/htdocs/expedition/dispatch.php
+++ b/htdocs/expedition/dispatch.php
@@ -773,10 +773,6 @@ if ($object->id > 0 || !empty($object->ref)) {
print ''; // Dispatch column
print '
| '; // Warehouse column
- /*$sql = "SELECT cfd.rowid, cfd.qty, cfd.fk_entrepot, cfd.batch, cfd.eatby, cfd.sellby, cfd.fk_product";
- $sql .= " FROM ".MAIN_DB_PREFIX."receptiondet_batch as cfd";
- $sql .= " WHERE cfd.fk_commandefourndet = ".(int) $objp->rowid;*/
-
$sql = "SELECT ed.rowid, ed.qty, ed.fk_entrepot,";
$sql .= " eb.batch, eb.eatby, eb.sellby, cd.fk_product";
$sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed";
diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php
index 3f30bf444de..b018cda619d 100644
--- a/htdocs/fourn/class/fournisseur.commande.class.php
+++ b/htdocs/fourn/class/fournisseur.commande.class.php
@@ -2252,7 +2252,7 @@ class CommandeFournisseur extends CommonOrder
$this->db->begin();
$sql = "INSERT INTO ".$this->db->prefix()."receptiondet_batch";
- $sql .= " (fk_commande, fk_product, qty, fk_entrepot, fk_user, datec, fk_commandefourndet, status, comment, eatby, sellby, batch, fk_reception) VALUES";
+ $sql .= " (fk_element, fk_product, qty, fk_entrepot, fk_user, datec, fk_elementdet, status, comment, eatby, sellby, batch, fk_reception) VALUES";
$sql .= " ('".$this->id."','".$product."','".$qty."',".($entrepot > 0 ? "'".$entrepot."'" : "null").",'".$user->id."','".$this->db->idate($now)."','".$fk_commandefourndet."', ".$dispatchstatus.", '".$this->db->escape($comment)."', ";
$sql .= ($eatby ? "'".$this->db->idate($eatby)."'" : "null").", ".($sellby ? "'".$this->db->idate($sellby)."'" : "null").", ".($batch ? "'".$this->db->escape($batch)."'" : "null").", ".($fk_reception > 0 ? "'".$this->db->escape($fk_reception)."'" : "null");
$sql .= ")";
@@ -2497,11 +2497,11 @@ class CommandeFournisseur extends CommonOrder
// List of already dispatched lines
$sql = "SELECT p.ref, p.label,";
$sql .= " e.rowid as warehouse_id, e.ref as entrepot,";
- $sql .= " cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.fk_commandefourndet";
+ $sql .= " cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.fk_elementdet";
$sql .= " FROM ".$this->db->prefix()."product as p,";
$sql .= " ".$this->db->prefix()."receptiondet_batch as cfd";
$sql .= " LEFT JOIN ".$this->db->prefix()."entrepot as e ON cfd.fk_entrepot = e.rowid";
- $sql .= " WHERE cfd.fk_commande = ".((int) $this->id);
+ $sql .= " WHERE cfd.fk_element = ".((int) $this->id);
$sql .= " AND cfd.fk_product = p.rowid";
if ($status >= 0) {
$sql .= " AND cfd.status = ".((int) $status);
@@ -2521,7 +2521,7 @@ class CommandeFournisseur extends CommonOrder
'productid' => $objp->fk_product,
'warehouseid' => $objp->warehouse_id,
'qty' => $objp->qty,
- 'orderlineid' => $objp->fk_commandefourndet
+ 'orderlineid' => $objp->fk_elementdet
);
}
@@ -3534,7 +3534,7 @@ class CommandeFournisseur extends CommonOrder
$supplierorderdispatch = new CommandeFournisseurDispatch($this->db);
- $filter = array('t.fk_commande' => $this->id);
+ $filter = array('t.fk_element' => $this->id);
if (getDolGlobalString('SUPPLIER_ORDER_USE_DISPATCH_STATUS')) {
$filter['t.status'] = 1; // Restrict to lines with status validated
}
@@ -3670,7 +3670,7 @@ class CommandeFournisseur extends CommonOrder
if ($filtre_statut >= 0) {
$sql .= ' cfd.fk_reception = e.rowid AND';
}
- $sql .= ' cfd.fk_commandefourndet = cd.rowid';
+ $sql .= ' cfd.fk_elementdet = cd.rowid';
$sql .= ' AND cd.fk_commande ='.((int) $this->id);
if (isset($this->fk_product) && !empty($this->fk_product) > 0) {
$sql .= ' AND cd.fk_product = '.((int) $this->fk_product);
diff --git a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php
index 84d76aadd93..06408ce0fa5 100644
--- a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php
+++ b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php
@@ -3,6 +3,7 @@
* Copyright (C) 2014 Juanjo Menent
* Copyright (C) 2024 Frédéric France
* Copyright (C) 2024 MDW
+ * Copyright (C) 2024 Christophe Battarel
*
* 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
@@ -26,118 +27,28 @@
*/
// Put here all includes required by your class file
-require_once DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php";
-require_once DOL_DOCUMENT_ROOT."/reception/class/reception.class.php";
+require_once DOL_DOCUMENT_ROOT."/reception/class/receptionlinebatch.class.php";
/**
- * Class to manage table commandefournisseurdispatch
+ * Class to manage table ReceptionLineBatch.
+ * Old name was CommandeFournisseurDispatch. This is a transition class.
*/
-class CommandeFournisseurDispatch extends CommonObjectLine
+class CommandeFournisseurDispatch extends ReceptionLineBatch
{
- /**
- * @var DoliDB Database handler.
- */
- public $db;
-
- /**
- * @var string Error code (or message)
- */
- public $error;
-
- /**
- * @var string[] Error codes (or messages)
- */
- public $errors = array();
-
/**
* @var string ID to identify managed object
*/
public $element = 'commandefournisseurdispatch';
-
- /**
- * @var string Name of table without prefix where object is stored
- */
- public $table_element = 'receptiondet_batch'; //!< Name of table without prefix where object is stored
- public $lines = array();
-
- /**
- * @var int ID
- */
- public $id;
-
/**
* @var int ID
*/
public $fk_commande;
-
/**
* @var int ID
*/
- public $fk_product;
-
- /**
- * @var int ID. Should be named fk_origin_line ?
- */
public $fk_commandefourndet;
- public $fk_reception;
-
-
- public $qty;
- public $qty_asked;
-
- public $libelle;
- public $label;
- public $desc;
- public $tva_tx;
- public $vat_src_code;
- public $ref_supplier;
-
- /**
- * @var int ID
- */
- public $fk_entrepot;
-
- /**
- * @var int User ID
- */
- public $fk_user;
-
- public $datec = '';
- public $comment;
-
- /**
- * @var int Status
- */
- public $status;
-
- public $batch;
- public $eatby = '';
- public $sellby = '';
- public $cost_price = 0;
-
-
-
-
- /**
- * Constructor
- *
- * @param DoliDB $db Database handler
- */
- public function __construct($db)
- {
- $this->db = $db;
-
- // List of language codes for status
- $this->labelStatus[0] = 'Received';
- $this->labelStatus[1] = 'Verified';
- $this->labelStatus[2] = 'Denied';
- $this->labelStatusShort[0] = 'Received';
- $this->labelStatusShort[1] = 'Verified';
- $this->labelStatusShort[2] = 'Denied';
- }
-
/**
* Create object into database
@@ -148,126 +59,12 @@ class CommandeFournisseurDispatch extends CommonObjectLine
*/
public function create($user, $notrigger = 0)
{
- global $conf, $langs, $hookmanager;
- $error = 0;
+ $this->fk_element = $this->fk_commande;
+ $this->fk_elementdet = $this->fk_commandefourndet;
- // Clean parameters
-
- if (isset($this->fk_commande)) {
- $this->fk_commande = (int) $this->fk_commande;
- }
- if (isset($this->fk_product)) {
- $this->fk_product = (int) $this->fk_product;
- }
- if (isset($this->fk_commandefourndet)) {
- $this->fk_commandefourndet = (int) $this->fk_commandefourndet;
- }
- if (isset($this->qty)) {
- $this->qty = trim((string) $this->qty);
- }
- if (isset($this->fk_entrepot)) {
- $this->fk_entrepot = (int) $this->fk_entrepot;
- }
- if (isset($this->fk_user)) {
- $this->fk_user = (int) $this->fk_user;
- }
- if (isset($this->comment)) {
- $this->comment = trim($this->comment);
- }
- if (isset($this->status)) {
- $this->status = (int) $this->status;
- }
- if (isset($this->batch)) {
- $this->batch = trim($this->batch);
- }
- if (empty($this->datec)) {
- $this->datec = dol_now();
- }
-
-
- // Check parameters
- // Put here code to add control on parameters values
-
- // Insert request
- $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."(";
- $sql .= "fk_commande,";
- $sql .= "fk_product,";
- $sql .= "fk_commandefourndet,";
- $sql .= "qty,";
- $sql .= "fk_entrepot,";
- $sql .= "fk_user,";
- $sql .= "datec,";
- $sql .= "comment,";
- $sql .= "status,";
- $sql .= "batch,";
- $sql .= "eatby,";
- $sql .= "sellby,";
- $sql .= "fk_reception,";
- $sql .= "cost_price";
-
-
- $sql .= ") VALUES (";
- $sql .= " ".(!isset($this->fk_commande) ? 'NULL' : "'".$this->db->escape($this->fk_commande)."'").",";
- $sql .= " ".(!isset($this->fk_product) ? 'NULL' : "'".$this->db->escape($this->fk_product)."'").",";
- $sql .= " ".(!isset($this->fk_commandefourndet) ? 'NULL' : "'".$this->db->escape($this->fk_commandefourndet)."'").",";
- $sql .= " ".(!isset($this->qty) ? 'NULL' : "'".$this->db->escape($this->qty)."'").",";
- $sql .= " ".(!isset($this->fk_entrepot) ? 'NULL' : "'".$this->db->escape($this->fk_entrepot)."'").",";
- $sql .= " ".(!isset($this->fk_user) ? 'NULL' : "'".$this->db->escape($this->fk_user)."'").",";
- $sql .= " ".(!isset($this->datec) || dol_strlen($this->datec) == 0 ? 'NULL' : "'".$this->db->idate($this->datec)."'").",";
- $sql .= " ".(!isset($this->comment) ? 'NULL' : "'".$this->db->escape($this->comment)."'").",";
- $sql .= " ".(!isset($this->status) ? 'NULL' : "'".$this->db->escape($this->status)."'").",";
- $sql .= " ".(!isset($this->batch) ? 'NULL' : "'".$this->db->escape($this->batch)."'").",";
- $sql .= " ".(!isset($this->eatby) || dol_strlen($this->eatby) == 0 ? 'NULL' : "'".$this->db->idate($this->eatby)."'").",";
- $sql .= " ".(!isset($this->sellby) || dol_strlen($this->sellby) == 0 ? 'NULL' : "'".$this->db->idate($this->sellby)."'").",";
- $sql .= " ".(!isset($this->fk_reception) ? 'NULL' : "'".$this->db->escape($this->fk_reception)."'").",";
- $sql .= " ".(!isset($this->cost_price) ? '0' : "'".$this->db->escape($this->cost_price)."'");
- $sql .= ")";
-
- $this->db->begin();
-
- dol_syslog(__METHOD__, LOG_DEBUG);
- $resql = $this->db->query($sql);
- if (!$resql) {
- $error++;
- $this->errors[] = "Error ".$this->db->lasterror();
- }
-
- if (!$error) {
- $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
-
- if (!$notrigger) {
- // Call triggers
- $result = $this->call_trigger('LINERECEPTION_CREATE', $user);
- if ($result < 0) {
- $error++;
- }
- // End call triggers
- }
- }
-
- // Create extrafields
- if (!$error) {
- $result = $this->insertExtraFields();
- if ($result < 0) {
- $error++;
- }
- }
-
- // Commit or rollback
- if ($error) {
- foreach ($this->errors as $errmsg) {
- dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
- $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
- }
- $this->db->rollback();
- return -1 * $error;
- } else {
- $this->db->commit();
- return $this->id;
- }
+ return parent::create($user, $notrigger);
}
-
/**
* Load object in memory from the database
*
@@ -277,68 +74,14 @@ class CommandeFournisseurDispatch extends CommonObjectLine
*/
public function fetch($id, $ref = '')
{
- global $langs;
- $sql = "SELECT";
- $sql .= " t.rowid,";
-
- $sql .= " t.fk_commande,";
- $sql .= " t.fk_product,";
- $sql .= " t.fk_commandefourndet,";
- $sql .= " t.qty,";
- $sql .= " t.fk_entrepot,";
- $sql .= " t.fk_user,";
- $sql .= " t.datec,";
- $sql .= " t.comment,";
- $sql .= " t.status,";
- $sql .= " t.tms,";
- $sql .= " t.batch,";
- $sql .= " t.eatby,";
- $sql .= " t.sellby,";
- $sql .= " t.fk_reception";
-
-
- $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
- if ($ref) {
- $sql .= " WHERE t.ref = '".$this->db->escape($ref)."'";
- } else {
- $sql .= " WHERE t.rowid = ".((int) $id);
- }
-
- dol_syslog(get_class($this)."::fetch");
- $resql = $this->db->query($sql);
- if ($resql) {
- if ($this->db->num_rows($resql)) {
- $obj = $this->db->fetch_object($resql);
-
- $this->id = $obj->rowid;
-
- $this->fk_commande = $obj->fk_commande;
- $this->fk_product = $obj->fk_product;
- $this->fk_commandefourndet = $obj->fk_commandefourndet;
- $this->qty = $obj->qty;
- $this->fk_entrepot = $obj->fk_entrepot;
- $this->fk_user = $obj->fk_user;
- $this->datec = $this->db->jdate($obj->datec);
- $this->comment = $obj->comment;
- $this->status = $obj->status;
- $this->tms = $this->db->jdate($obj->tms);
- $this->batch = $obj->batch;
- $this->eatby = $this->db->jdate($obj->eatby);
- $this->sellby = $this->db->jdate($obj->sellby);
- $this->fk_reception = $obj->fk_reception;
-
- $this->fetch_optionals();
- }
- $this->db->free($resql);
-
- return 1;
- } else {
- $this->error = "Error ".$this->db->lasterror();
- return -1;
+ $ret = parent::fetch($id, $ref);
+ if ($ret > 0) {
+ $this->fk_commande = $this->fk_element;
+ $this->fk_commandefourndet = $this->fk_elementdet;
}
+ return $ret;
}
-
/**
* Update object into database
*
@@ -348,408 +91,9 @@ class CommandeFournisseurDispatch extends CommonObjectLine
*/
public function update($user, $notrigger = 0)
{
- $error = 0;
+ $this->fk_element = $this->fk_commande;
+ $this->fk_elementdet = $this->fk_commandefourndet;
- // Clean parameters
-
- if (isset($this->fk_commande)) {
- $this->fk_commande = (int) $this->fk_commande;
- }
- if (isset($this->fk_product)) {
- $this->fk_product = (int) $this->fk_product;
- }
- if (isset($this->fk_commandefourndet)) {
- $this->fk_commandefourndet = (int) $this->fk_commandefourndet;
- }
- if (isset($this->qty)) {
- $this->qty = trim($this->qty);
- }
- if (isset($this->fk_entrepot)) {
- $this->fk_entrepot = (int) $this->fk_entrepot;
- }
- if (isset($this->fk_user)) {
- $this->fk_user = (int) $this->fk_user;
- }
- if (isset($this->comment)) {
- $this->comment = trim($this->comment);
- }
- if (isset($this->status)) {
- $this->status = (int) $this->status;
- }
- if (isset($this->batch)) {
- $this->batch = trim($this->batch);
- }
-
-
-
- // Check parameters
- // Put here code to add a control on parameters values
-
- // Update request
- $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
- $sql .= " fk_commande=".(isset($this->fk_commande) ? $this->fk_commande : "null").",";
- $sql .= " fk_product=".(isset($this->fk_product) ? $this->fk_product : "null").",";
- $sql .= " fk_commandefourndet=".(isset($this->fk_commandefourndet) ? $this->fk_commandefourndet : "null").",";
- $sql .= " qty=".(isset($this->qty) ? $this->qty : "null").",";
- $sql .= " fk_entrepot=".(isset($this->fk_entrepot) ? $this->fk_entrepot : "null").",";
- $sql .= " fk_user=".(isset($this->fk_user) ? $this->fk_user : "null").",";
- $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
- $sql .= " comment=".(isset($this->comment) ? "'".$this->db->escape($this->comment)."'" : "null").",";
- $sql .= " status=".(isset($this->status) ? $this->status : "null").",";
- $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
- $sql .= " batch=".(isset($this->batch) ? "'".$this->db->escape($this->batch)."'" : "null").",";
- $sql .= " eatby=".(dol_strlen($this->eatby) != 0 ? "'".$this->db->idate($this->eatby)."'" : 'null').",";
- $sql .= " sellby=".(dol_strlen($this->sellby) != 0 ? "'".$this->db->idate($this->sellby)."'" : 'null');
- $sql .= " WHERE rowid=".((int) $this->id);
-
- $this->db->begin();
-
- dol_syslog(__METHOD__);
- $resql = $this->db->query($sql);
- if (!$resql) {
- $error++;
- $this->errors[] = "Error ".$this->db->lasterror();
- }
-
- if (!$error) {
- if (!$error) {
- if (empty($this->id) && !empty($this->rowid)) {
- $this->id = $this->rowid;
- }
- $result = $this->insertExtraFields();
- if ($result < 0) {
- $error++;
- }
- }
-
- if (!$notrigger) {
- // Call triggers
- $result = $this->call_trigger('LINERECEPTION_MODIFY', $user);
- if ($result < 0) {
- $error++;
- }
- // End call triggers
- }
- }
-
- // Commit or rollback
- if ($error) {
- foreach ($this->errors as $errmsg) {
- dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
- $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
- }
- $this->db->rollback();
- return -1 * $error;
- } else {
- $this->db->commit();
- return 1;
- }
- }
-
-
- /**
- * Delete object in database
- *
- * @param User $user User that deletes
- * @param int $notrigger 0=launch triggers after, 1=disable triggers
- * @return int Return integer <0 if KO, >0 if OK
- */
- public function delete($user, $notrigger = 0)
- {
- $error = 0;
-
- $this->db->begin();
-
- if (!$error) {
- if (!$notrigger) {
- // Call triggers
- $result = $this->call_trigger('LINERECEPTION_DELETE', $user);
- if ($result < 0) {
- $error++;
- }
- // End call triggers
- }
- }
-
- // Remove extrafields
- if (!$error) {
- $result = $this->deleteExtraFields();
- if ($result < 0) {
- $error++;
- dol_syslog(get_class($this)."::delete error deleteExtraFields ".$this->error, LOG_ERR);
- }
- }
-
- if (!$error) {
- $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
- $sql .= " WHERE rowid=".((int) $this->id);
-
- dol_syslog(__METHOD__);
- $resql = $this->db->query($sql);
- if (!$resql) {
- $error++;
- $this->errors[] = "Error ".$this->db->lasterror();
- }
- }
-
- // Commit or rollback
- if ($error) {
- foreach ($this->errors as $errmsg) {
- dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
- $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
- }
- $this->db->rollback();
- return -1 * $error;
- } else {
- $this->db->commit();
- return 1;
- }
- }
-
-
- /**
- * Load an object from its id and create a new one in database
- *
- * @param User $user User making the clone
- * @param int $fromid Id of object to clone
- * @return int New id of clone
- */
- public function createFromClone(User $user, $fromid)
- {
- $error = 0;
-
- $object = new CommandeFournisseurDispatch($this->db);
-
- $this->db->begin();
-
- // Load source object
- $object->fetch($fromid);
- $object->id = 0;
- $object->statut = 0;
-
- // Clear fields
- // ...
-
- // Create clone
- $object->context['createfromclone'] = 'createfromclone';
- $result = $object->create($user);
-
- // Other options
- if ($result < 0) {
- $this->error = $object->error;
- $error++;
- }
-
- if (!$error) {
- }
-
- unset($object->context['createfromclone']);
-
- // End
- if (!$error) {
- $this->db->commit();
- return $object->id;
- } else {
- $this->db->rollback();
- return -1;
- }
- }
-
-
-
- /**
- * Return label of the status of object
- *
- * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto
- * @return string Label
- */
- public function getLibStatut($mode = 0)
- {
- return $this->LibStatut($this->status, $mode);
- }
-
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
- /**
- * Return label of a status
- *
- * @param int $status Id status
- * @param int $mode 0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto
- * @return string Label of status
- */
- public function LibStatut($status, $mode = 0)
- {
- // phpcs:enable
- global $langs;
- $langs->load('orders');
-
- if ($mode == 0) {
- return $langs->trans($this->labelStatus[$status]);
- } elseif ($mode == 1) {
- return $langs->trans($this->labelStatusShort[$status]);
- } elseif ($mode == 2) {
- return $langs->trans($this->labelStatus[$status]);
- } elseif ($mode == 3) {
- if ($status == 0) {
- return img_picto($langs->trans($this->labelStatus[$status]), 'statut0');
- } elseif ($status == 1) {
- return img_picto($langs->trans($this->labelStatus[$status]), 'statut4');
- } elseif ($status == 2) {
- return img_picto($langs->trans($this->labelStatus[$status]), 'statut8');
- }
- } elseif ($mode == 4) {
- if ($status == 0) {
- return img_picto($langs->trans($this->labelStatus[$status]), 'statut0').' '.$langs->trans($this->labelStatus[$status]);
- } elseif ($status == 1) {
- return img_picto($langs->trans($this->labelStatus[$status]), 'statut4').' '.$langs->trans($this->labelStatus[$status]);
- } elseif ($status == 2) {
- return img_picto($langs->trans($this->labelStatus[$status]), 'statut8').' '.$langs->trans($this->labelStatus[$status]);
- }
- } elseif ($mode == 5) {
- if ($status == 0) {
- return ''.$langs->trans($this->labelStatusShort[$status]).' '.img_picto($langs->trans($this->labelStatus[$status]), 'statut0');
- } elseif ($status == 1) {
- return ''.$langs->trans($this->labelStatusShort[$status]).' '.img_picto($langs->trans($this->labelStatus[$status]), 'statut4');
- } elseif ($status == 2) {
- return ''.$langs->trans($this->labelStatusShort[$status]).' '.img_picto($langs->trans($this->labelStatus[$status]), 'statut8');
- }
- }
- return "";
- }
-
-
- /**
- * Initialise object with example values
- * Id must be 0 if object instance is a specimen
- *
- * @return int
- */
- public function initAsSpecimen()
- {
- $this->id = 0;
-
- $this->fk_commande = 0;
- $this->fk_product = 0;
- $this->fk_commandefourndet = 0;
- $this->qty = '';
- $this->fk_entrepot = 0;
- $this->fk_user = 0;
- $this->datec = '';
- $this->comment = '';
- $this->status = 0;
- $this->tms = dol_now();
- $this->batch = '';
- $this->eatby = '';
- $this->sellby = '';
-
- return 1;
- }
-
- /**
- * Load object in memory from the database
- *
- * @param string $sortorder Sort Order
- * @param string $sortfield Sort field
- * @param int $limit limit
- * @param int $offset offset limit
- * @param string|array $filter filter array
- * @param string $filtermode filter mode (AND or OR)
- * @return int Return integer <0 if KO, >0 if OK
- */
- public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
- {
- dol_syslog(__METHOD__, LOG_DEBUG);
-
- $sql = "SELECT";
- $sql .= " t.rowid,";
- $sql .= " t.fk_commande,";
- $sql .= " t.fk_product,";
- $sql .= " t.fk_commandefourndet,";
- $sql .= " t.qty,";
- $sql .= " t.fk_entrepot,";
- $sql .= " t.fk_user,";
- $sql .= " t.datec,";
- $sql .= " t.comment,";
- $sql .= " t.status,";
- $sql .= " t.tms,";
- $sql .= " t.batch,";
- $sql .= " t.eatby,";
- $sql .= " t.sellby";
- $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
-
- // Manage filter
- if (is_array($filter)) {
- $sqlwhere = array();
- if (count($filter) > 0) {
- foreach ($filter as $key => $value) {
- if ($key == 't.comment') {
- $sqlwhere [] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
- } elseif ($key == 't.datec' || $key == 't.tms' || $key == 't.eatby' || $key == 't.sellby' || $key == 't.batch') {
- $sqlwhere [] = $this->db->sanitize($key)." = '".$this->db->escape($value)."'";
- } elseif ($key == 'qty') {
- $sqlwhere [] = $this->db->sanitize($key)." = ".((float) $value);
- } else {
- $sqlwhere [] = $this->db->sanitize($key)." = ".((int) $value);
- }
- }
- }
- if (count($sqlwhere) > 0) {
- $sql .= ' WHERE '.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere);
- }
-
- $filter = '';
- }
-
- // Manage filter
- $errormessage = '';
- $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
- if ($errormessage) {
- $this->errors[] = $errormessage;
- dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
- return -1;
- }
-
- if (!empty($sortfield)) {
- $sql .= $this->db->order($sortfield, $sortorder);
- }
- if (!empty($limit)) {
- $sql .= $this->db->plimit($limit, $offset);
- }
- $this->lines = array();
-
- $resql = $this->db->query($sql);
- if ($resql) {
- $num = $this->db->num_rows($resql);
-
- while ($obj = $this->db->fetch_object($resql)) {
- $line = new self($this->db);
-
- $line->id = $obj->rowid;
-
- $line->fk_commande = $obj->fk_commande;
- $line->fk_product = $obj->fk_product;
- $line->fk_commandefourndet = $obj->fk_commandefourndet;
- $line->qty = $obj->qty;
- $line->fk_entrepot = $obj->fk_entrepot;
- $line->fk_user = $obj->fk_user;
- $line->datec = $this->db->jdate($obj->datec);
- $line->comment = $obj->comment;
- $line->status = $obj->status;
- $line->tms = $this->db->jdate($obj->tms);
- $line->batch = $obj->batch;
- $line->eatby = $this->db->jdate($obj->eatby);
- $line->sellby = $this->db->jdate($obj->sellby);
- $line->fetch_optionals();
-
- $this->lines[$line->id] = $line;
- }
- $this->db->free($resql);
-
- return $num;
- } else {
- $this->errors[] = 'Error '.$this->db->lasterror();
- dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
-
- return -1;
- }
+ return parent::update($user, $notrigger);
}
}
diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php
index 90da456e660..f9ec2a67379 100644
--- a/htdocs/fourn/commande/dispatch.php
+++ b/htdocs/fourn/commande/dispatch.php
@@ -669,8 +669,8 @@ if ($id > 0 || !empty($ref)) {
$products_dispatched = array();
$sql = "SELECT l.rowid, cfd.fk_product, sum(cfd.qty) as qty";
$sql .= " FROM ".MAIN_DB_PREFIX."receptiondet_batch as cfd";
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as l on l.rowid = cfd.fk_commandefourndet";
- $sql .= " WHERE cfd.fk_commande = ".((int) $object->id);
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as l on l.rowid = cfd.fk_elementdet";
+ $sql .= " WHERE cfd.fk_element = ".((int) $object->id);
$sql .= " GROUP BY l.rowid, cfd.fk_product";
$resql = $db->query($sql);
@@ -1172,12 +1172,12 @@ if ($id > 0 || !empty($ref)) {
}
$sql .= " FROM ".MAIN_DB_PREFIX."product as p,";
$sql .= " ".MAIN_DB_PREFIX."receptiondet_batch as cfd";
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as cd ON cd.rowid = cfd.fk_commandefourndet";
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as cd ON cd.rowid = cfd.fk_elementdet";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e ON cfd.fk_entrepot = e.rowid";
if ($conf->reception->enabled) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."reception as r ON cfd.fk_reception = r.rowid";
}
- $sql .= " WHERE cfd.fk_commande = ".((int) $object->id);
+ $sql .= " WHERE cfd.fk_element = ".((int) $object->id);
$sql .= " AND cfd.fk_product = p.rowid";
$sql .= " ORDER BY cfd.rowid ASC";
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 9b8183b49c4..f0e6b72901c 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
@@ -283,3 +283,6 @@ ALTER TABLE llx_societe 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_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/migration/repair.sql b/htdocs/install/mysql/migration/repair.sql
index 6b48ef5ac16..2c0e43dc3fe 100644
--- a/htdocs/install/mysql/migration/repair.sql
+++ b/htdocs/install/mysql/migration/repair.sql
@@ -1,10 +1,10 @@
--
-- Script to repair some fatal errors due to database corruption
--- when current version is 2.6.0 or higher.
+-- when current version is 2.6.0 or higher.
--
--- Replace xxx with your IP Address
+-- Replace xxx with your IP Address
-- bind-address = xxx.xxx.xxx.xxx
-- CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypass';
-- CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypass';
@@ -65,10 +65,10 @@
-- VMYSQL4.1 INSERT IGNORE INTO llx_product_lot (entity, fk_product, batch, eatby, sellby, datec, fk_user_creat, fk_user_modif) SELECT DISTINCT e.entity, ps.fk_product, pb.batch, pb.eatby, pb.sellby, pb.tms, e.fk_user_author, e.fk_user_author from llx_product_batch as pb, llx_product_stock as ps, llx_entrepot as e WHERE pb.fk_product_stock = ps.rowid AND ps.fk_entrepot = e.rowid;
-- -- a tester VPGSQL9.5 INSERT IGNORE INTO llx_product_lot (entity, fk_product, batch, eatby, sellby, datec, fk_user_creat, fk_user_modif) SELECT DISTINCT e.entity, ps.fk_product, pb.batch, pb.eatby, pb.sellby, pb.tms, e.fk_user_author, e.fk_user_author from llx_product_batch as pb, llx_product_stock as ps, llx_entrepot as e WHERE pb.fk_product_stock = ps.rowid AND ps.fk_entrepot = e.rowid ON CONFLICT DO NOTHING;
-- -- avant 9.5 faire en variant x pour qu'au 2eme passage, le premier doublon soit dans la tabel cible
--- -- INSERT INTO llx_product_lot (entity, fk_product, batch, eatby, sellby, datec, fk_user_creat, fk_user_modif)
--- -- SELECT DISTINCT e.entity, ps.fk_product, pb.batch, pb.eatby, pb.sellby, pb.tms, e.fk_user_author, e.fk_user_author
+-- -- INSERT INTO llx_product_lot (entity, fk_product, batch, eatby, sellby, datec, fk_user_creat, fk_user_modif)
+-- -- SELECT DISTINCT e.entity, ps.fk_product, pb.batch, pb.eatby, pb.sellby, pb.tms, e.fk_user_author, e.fk_user_author
-- -- from llx_product_batch as pb, llx_product_stock as ps, llx_entrepot as e
--- -- WHERE pb.fk_product_stock = ps.rowid AND ps.fk_entrepot = e.rowid
+-- -- WHERE pb.fk_product_stock = ps.rowid AND ps.fk_entrepot = e.rowid
-- -- AND NOT EXISTS (SELECT 1 FROM llx_product_lot as b WHERE b.fk_product=ps.fk_product and pb.batch=b.batch) LIMIT x
@@ -145,13 +145,13 @@ update llx_product_batch set batch = '' where batch = 'Non défini';
update llx_stock_mouvement set batch = null where batch = 'Non défini';
update llx_stock_mouvement set batch = null where batch = 'Non défini';
-DELETE FROM llx_product_lot WHERE fk_product NOT IN (select rowid from llx_product);
-DELETE FROM llx_product_stock WHERE fk_product NOT IN (select rowid from llx_product);
+DELETE FROM llx_product_lot WHERE fk_product NOT IN (select rowid from llx_product);
+DELETE FROM llx_product_stock WHERE fk_product NOT IN (select rowid from llx_product);
DELETE FROM llx_product_stock WHERE reel = 0 AND rowid NOT IN (SELECT fk_product_stock FROM llx_product_batch as pb);
--- Merge splitted lines into one in table llx_product_batch
+-- Merge splitted lines into one in table llx_product_batch
DROP TABLE tmp_llx_product_batch;
DROP TABLE tmp_llx_product_batch2;
CREATE TABLE tmp_llx_product_batch AS select fk_product_stock, eatby, sellby, batch, SUM(qty) as qty, COUNT(rowid) as nb FROM llx_product_batch GROUP BY fk_product_stock, eatby, sellby, batch HAVING COUNT(rowid) > 1;
@@ -175,7 +175,7 @@ delete from llx_product_association where fk_product_fils NOT IN (select rowid f
-- Fix: delete category child with no category parent.
drop table tmp_categorie;
-create table tmp_categorie as select * from llx_categorie;
+create table tmp_categorie as select * from llx_categorie;
-- select * from llx_categorie where fk_parent not in (select rowid from tmp_categorie) and fk_parent is not null and fk_parent <> 0;
delete from llx_categorie where fk_parent not in (select rowid from tmp_categorie) and fk_parent is not null and fk_parent <> 0;
drop table tmp_categorie;
@@ -397,7 +397,7 @@ update llx_facturedet set product_type = 1 where product_type = 2;
update llx_propal set fk_statut = 1 where fk_statut = -1;
-delete from llx_commande_fournisseur_dispatch where fk_commandefourndet = 0 or fk_commandefourndet IS NULL;
+delete from llx_receptiondet_batch where fk_elementdet = 0 or fk_elementdet IS NULL;
delete from llx_menu where menu_handler = 'smartphone';
@@ -408,7 +408,7 @@ update llx_expedition set date_valid = NOW() where fk_statut = 1 and date_valid
-- Detect bad consistency between duraction_effective of a task and sum of time of tasks
-- select pt.rowid, pt.duration_effective, SUM(ptt.element_duration) as y from llx_projet_task as pt, llx_element_time as ptt where ptt.fk_element = pt.rowid and ptt.elementtype = 'task' group by pt.rowid, pt.duration_effective having pt.duration_effective <> y;
update llx_projet_task as pt set pt.duration_effective = (select SUM(ptt.element_duration) as y from llx_element_time as ptt where ptt.fk_element = pt.rowid and ptt.elementtype = 'task') where pt.duration_effective <> (select SUM(ptt.element_duration) as y from llx_element_time as ptt where ptt.fk_element = pt.rowid and ptt.elementtype = 'task');
-
+
-- Remove duplicate of shipment mode (keep the one with tracking defined)
drop table tmp_c_shipment_mode;
@@ -443,9 +443,9 @@ UPDATE llx_expensereport_det SET fk_code_ventilation = 0 WHERE fk_code_ventilati
-- Clean product prices
---delete from llx_product_price where date_price between '2017-04-20 06:51:00' and '2017-04-20 06:51:05';
+--delete from llx_product_price where date_price between '2017-04-20 06:51:00' and '2017-04-20 06:51:05';
-- Set product prices into llx_product with last price into llx_product_prices
---update llx_product as p set
+--update llx_product as p set
-- p.price = (select pp.price from llx_product_price as pp where pp.price_level = 1 and pp.fk_product = p.rowid order by pp.tms desc limit 1),
-- p.price_ttc = (select pp.price_ttc from llx_product_price as pp where pp.price_level = 1 and pp.fk_product = p.rowid order by pp.tms desc limit 1),
-- p.price_min = (select pp.price_min from llx_product_price as pp where pp.price_level = 1 and pp.fk_product = p.rowid order by pp.tms desc limit 1),
@@ -503,7 +503,7 @@ UPDATE llx_chargesociales SET date_creation = tms WHERE date_creation IS NULL;
--ALTER TABLE llx_table modify column columnname datetime DEFAULT CURRENT_TIMESTAMP;
--- Backport a change of value into the hourly rate.
+-- Backport a change of value into the hourly rate.
-- update llx_element_time as ptt set ptt.thm = (SELECT thm from llx_user as u where ptt.fk_user = u.rowid) where (ptt.thm is null)
@@ -513,14 +513,14 @@ update llx_facturedet set product_type = 1 where product_type = 0 AND fk_product
update llx_facture_fourn_det set product_type = 0 where product_type = 1 AND fk_product > 0 AND fk_product IN (SELECT rowid FROM llx_product WHERE fk_product_type = 0);
update llx_facture_fourn_det set product_type = 1 where product_type = 0 AND fk_product > 0 AND fk_product IN (SELECT rowid FROM llx_product WHERE fk_product_type = 1);
-
+
DELETE FROM llx_mrp_production where qty = 0;
UPDATE llx_accounting_bookkeeping set date_creation = tms where date_creation IS NULL;
-
+
-- UPDATE llx_contratdet set label = NULL WHERE label IS NOT NULL;
-- UPDATE llx_facturedet_rec set label = NULL WHERE label IS NOT NULL;
@@ -528,21 +528,21 @@ UPDATE llx_accounting_bookkeeping set date_creation = tms where date_creation IS
--Fix bad sign on multicompany column for customer invoice lines
UPDATE llx_facturedet SET multicurrency_subprice = -multicurrency_subprice WHERE ((multicurrency_subprice < 0 and subprice > 0) OR (multicurrency_subprice > 0 and subprice < 0));
UPDATE llx_facturedet SET multicurrency_total_ht = -multicurrency_total_ht WHERE ((multicurrency_total_ht < 0 and total_ht > 0) OR (multicurrency_total_ht > 0 and total_ht < 0));
-UPDATE llx_facturedet SET multicurrency_total_tva = -multicurrency_total_tva WHERE ((multicurrency_total_tva < 0 and total_tva > 0) OR (multicurrency_total_tva > 0 and total_tva < 0));
-UPDATE llx_facturedet SET multicurrency_total_ttc = -multicurrency_total_ttc WHERE ((multicurrency_total_ttc < 0 and total_ttc > 0) OR (multicurrency_total_ttc > 0 and total_ttc < 0));
+UPDATE llx_facturedet SET multicurrency_total_tva = -multicurrency_total_tva WHERE ((multicurrency_total_tva < 0 and total_tva > 0) OR (multicurrency_total_tva > 0 and total_tva < 0));
+UPDATE llx_facturedet SET multicurrency_total_ttc = -multicurrency_total_ttc WHERE ((multicurrency_total_ttc < 0 and total_ttc > 0) OR (multicurrency_total_ttc > 0 and total_ttc < 0));
--Fix bad sign on multicompany column for customer invoices
-UPDATE llx_facture SET multicurrency_total_ht = -multicurrency_total_ht WHERE ((multicurrency_total_ht < 0 and total_ht > 0) OR (multicurrency_total_ht > 0 and total_ht < 0));
-UPDATE llx_facture SET multicurrency_total_tva = -multicurrency_total_tva WHERE ((multicurrency_total_tva < 0 and total_tva > 0) OR (multicurrency_total_tva > 0 and total_tva < 0));
-UPDATE llx_facture SET multicurrency_total_ttc = -multicurrency_total_ttc WHERE ((multicurrency_total_ttc < 0 and total_ttc > 0) OR (multicurrency_total_ttc > 0 and total_ttc < 0));
+UPDATE llx_facture SET multicurrency_total_ht = -multicurrency_total_ht WHERE ((multicurrency_total_ht < 0 and total_ht > 0) OR (multicurrency_total_ht > 0 and total_ht < 0));
+UPDATE llx_facture SET multicurrency_total_tva = -multicurrency_total_tva WHERE ((multicurrency_total_tva < 0 and total_tva > 0) OR (multicurrency_total_tva > 0 and total_tva < 0));
+UPDATE llx_facture SET multicurrency_total_ttc = -multicurrency_total_ttc WHERE ((multicurrency_total_ttc < 0 and total_ttc > 0) OR (multicurrency_total_ttc > 0 and total_ttc < 0));
--Fix bad sign on multicurrency column for supplier invoice lines
UPDATE llx_facture_fourn_det SET multicurrency_subprice = -multicurrency_subprice WHERE ((multicurrency_subprice < 0 and pu_ht > 0) OR (multicurrency_subprice > 0 and pu_ht < 0));
UPDATE llx_facture_fourn_det SET multicurrency_total_ht = -multicurrency_total_ht WHERE ((multicurrency_total_ht < 0 and total_ht > 0) OR (multicurrency_total_ht > 0 and total_ht < 0));
-UPDATE llx_facture_fourn_det SET multicurrency_total_tva = -multicurrency_total_tva WHERE ((multicurrency_total_tva < 0 and tva > 0) OR (multicurrency_total_tva > 0 and tva < 0));
-UPDATE llx_facture_fourn_det SET multicurrency_total_ttc = -multicurrency_total_ttc WHERE ((multicurrency_total_ttc < 0 and total_ttc > 0) OR (multicurrency_total_ttc > 0 and total_ttc < 0));
+UPDATE llx_facture_fourn_det SET multicurrency_total_tva = -multicurrency_total_tva WHERE ((multicurrency_total_tva < 0 and tva > 0) OR (multicurrency_total_tva > 0 and tva < 0));
+UPDATE llx_facture_fourn_det SET multicurrency_total_ttc = -multicurrency_total_ttc WHERE ((multicurrency_total_ttc < 0 and total_ttc > 0) OR (multicurrency_total_ttc > 0 and total_ttc < 0));
--Fix bad sign on multicompany column for customer invoices
-UPDATE llx_facture_fourn SET multicurrency_total_ht = -multicurrency_total_ht WHERE ((multicurrency_total_ht < 0 and total_ht > 0) OR (multicurrency_total_ht > 0 and total_ht < 0));
-UPDATE llx_facture_fourn SET multicurrency_total_tva = -multicurrency_total_tva WHERE ((multicurrency_total_tva < 0 and total_tva > 0) OR (multicurrency_total_tva > 0 and total_tva < 0));
-UPDATE llx_facture_fourn SET multicurrency_total_ttc = -multicurrency_total_ttc WHERE ((multicurrency_total_ttc < 0 and total_ttc > 0) OR (multicurrency_total_ttc > 0 and total_ttc < 0));
+UPDATE llx_facture_fourn SET multicurrency_total_ht = -multicurrency_total_ht WHERE ((multicurrency_total_ht < 0 and total_ht > 0) OR (multicurrency_total_ht > 0 and total_ht < 0));
+UPDATE llx_facture_fourn SET multicurrency_total_tva = -multicurrency_total_tva WHERE ((multicurrency_total_tva < 0 and total_tva > 0) OR (multicurrency_total_tva > 0 and total_tva < 0));
+UPDATE llx_facture_fourn SET multicurrency_total_ttc = -multicurrency_total_ttc WHERE ((multicurrency_total_ttc < 0 and total_ttc > 0) OR (multicurrency_total_ttc > 0 and total_ttc < 0));
UPDATE llx_facturedet SET situation_percent = 100 WHERE situation_percent IS NULL AND fk_prev_id IS NULL;
@@ -558,7 +558,7 @@ UPDATE llx_facturedet SET situation_percent = 100 WHERE situation_percent IS NUL
--update llx_facture set paye = 1, fk_statut = 2 where rowid in (select rowid from tmp_invoice_deposit_mark_as_available);
--- TODO We should fix multicurrency_amount that are empty into llx_societe_remise_except, but we can't because we don't know what is the rate
+-- TODO We should fix multicurrency_amount that are empty into llx_societe_remise_except, but we can't because we don't know what is the rate
-- We may retreive info fro minvoice line by using fk_facture_line or fk_facture_supplier_line
-- select * from llx_societe_remise_except where multicurrency_amount_ht = 0 and amount_ht <> 0;
@@ -586,7 +586,7 @@ DELETE FROM llx_rights_def WHERE module = 'hrm' AND perms = 'employee';
-- Sequence to fix the content of llx_bank.amount_main_currency (value was empty and should not for payment on bank account with a different currency so when amount_main_currency is different than amount)
-- Note: amount is amount in the currency of the bank account
-- Note: pamount is always amount into the main currency
--- Note: pmulticurrencyamount is in the currency of invoice
+-- Note: pmulticurrencyamount is in the currency of invoice
-- Note: amount_main_currency must be NULL or amount in main currency of company (we set it when the currency of the bank account differs from main currency)
-- DROP TABLE tmp_bank;
-- CREATE TABLE tmp_bank SELECT b.rowid, b.amount, p.rowid as pid, p.amount as pamount, p.multicurrency_amount as pmulticurrencyamount, b.datec FROM llx_bank as b INNER JOIN llx_bank_url as bu ON bu.fk_bank=b.rowid AND bu.type = 'payment' INNER JOIN llx_paiement as p ON bu.url_id = p.rowid WHERE p.multicurrency_amount <> 0 AND p.multicurrency_amount <> p.amount;
diff --git a/htdocs/install/mysql/tables/llx_receptiondet_batch.key.sql b/htdocs/install/mysql/tables/llx_receptiondet_batch.key.sql
index 0c92a0d8302..4470247061b 100644
--- a/htdocs/install/mysql/tables/llx_receptiondet_batch.key.sql
+++ b/htdocs/install/mysql/tables/llx_receptiondet_batch.key.sql
@@ -20,4 +20,4 @@ ALTER TABLE llx_receptiondet_batch ADD INDEX idx_receptiondet_batch_fk_commande
ALTER TABLE llx_receptiondet_batch ADD INDEX idx_receptiondet_batch_fk_reception (fk_reception);
ALTER TABLE llx_receptiondet_batch ADD CONSTRAINT fk_receptiondet_batch_fk_reception FOREIGN KEY (fk_reception) REFERENCES llx_reception (rowid);
ALTER TABLE llx_receptiondet_batch ADD INDEX idx_receptiondet_batch_fk_product (fk_product);
-ALTER TABLE llx_receptiondet_batch ADD INDEX idx_receptiondet_batch_fk_commandefourndet (fk_commandefourndet);
+ALTER TABLE llx_receptiondet_batch ADD INDEX idx_receptiondet_batch_fk_elementdet (fk_elementdet);
diff --git a/htdocs/install/mysql/tables/llx_receptiondet_batch.sql b/htdocs/install/mysql/tables/llx_receptiondet_batch.sql
index f5f7f7deb39..e8b414510d1 100644
--- a/htdocs/install/mysql/tables/llx_receptiondet_batch.sql
+++ b/htdocs/install/mysql/tables/llx_receptiondet_batch.sql
@@ -28,8 +28,8 @@ create table llx_receptiondet_batch
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_reception integer DEFAULT NULL, -- ID of parent object
- fk_commande integer, -- ID of main source object. TODO should be renamed into fk_element
- fk_commandefourndet integer, -- ID of line of main source object. TODO should be renamed into fk_elementdet
+ fk_element integer, -- ID of main source object. TODO should be renamed into fk_element
+ fk_elementdet integer, -- ID of line of main source object. TODO should be renamed into fk_elementdet
element_type varchar(50) DEFAULT 'supplier_order' NOT NULL, -- Type of source object ('supplier_order', ...)
fk_product integer,
qty float, -- qty to move
diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php
index 51d0164541a..bf0b8cd6534 100644
--- a/htdocs/install/repair.php
+++ b/htdocs/install/repair.php
@@ -1488,7 +1488,7 @@ if ($ok && GETPOST('repair_link_dispatch_lines_supplier_order_lines')) {
echo '| Repair llx_receptiondet_batch.fk_commandefourndet |
';
echo '| Repair in progress. This may take a while. |
';
- $sql_dispatch = 'SELECT * FROM '.MAIN_DB_PREFIX.'receptiondet_batch WHERE COALESCE(fk_commandefourndet, 0) = 0';
+ $sql_dispatch = 'SELECT * FROM '.MAIN_DB_PREFIX.'receptiondet_batch WHERE COALESCE(fk_elementdet, 0) = 0';
$db->begin();
$resql_dispatch = $db->query($sql_dispatch);
$n_processed_rows = 0;
@@ -1529,17 +1529,17 @@ if ($ok && GETPOST('repair_link_dispatch_lines_supplier_order_lines')) {
$qty_for_line = min($remaining_qty, $obj_line->qty);
if ($first_iteration) {
$sql_attach = 'UPDATE '.MAIN_DB_PREFIX.'receptiondet_batch';
- $sql_attach .= ' SET fk_commandefourndet = '.((int) $obj_line->rowid).', qty = '.((float) $qty_for_line);
+ $sql_attach .= ' SET fk_elementdet = '.((int) $obj_line->rowid).', qty = '.((float) $qty_for_line);
$sql_attach .= ' WHERE rowid = '.((int) $obj_dispatch->rowid);
$first_iteration = false;
} else {
$sql_attach_values = array(
- (string) ((int) $obj_dispatch->fk_commande),
- (string) ((int) $obj_dispatch->fk_product),
- (string) ((int) $obj_line->rowid),
- (string) ((float) $qty_for_line),
- (string) ((int) $obj_dispatch->fk_entrepot),
- (string) ((int) $obj_dispatch->fk_user),
+ ((int) $obj_dispatch->fk_element),
+ ((int) $obj_dispatch->fk_product),
+ ((int) $obj_line->rowid),
+ ((float) $qty_for_line),
+ ((int) $obj_dispatch->fk_entrepot),
+ ((int) $obj_dispatch->fk_user),
$obj_dispatch->datec ? "'".$db->idate($db->jdate($obj_dispatch->datec))."'" : 'NULL',
$obj_dispatch->comment ? "'".$db->escape($obj_dispatch->comment)."'" : 'NULL',
$obj_dispatch->status ? (string) ((int) $obj_dispatch->status) : 'NULL',
@@ -1551,7 +1551,7 @@ if ($ok && GETPOST('repair_link_dispatch_lines_supplier_order_lines')) {
$sql_attach_values = implode(', ', $sql_attach_values);
$sql_attach = 'INSERT INTO '.MAIN_DB_PREFIX.'receptiondet_batch';
- $sql_attach .= ' (fk_commande, fk_product, fk_commandefourndet, qty, fk_entrepot, fk_user, datec, comment, status, tms, batch, eatby, sellby)';
+ $sql_attach .= ' (fk_element, fk_product, fk_elementdet, qty, fk_entrepot, fk_user, datec, comment, status, tms, batch, eatby, sellby)';
$sql_attach .= " VALUES (".$sql_attach_values.")";
}
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index ab072b4cda1..040f4d77183 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -3501,7 +3501,7 @@ class Product extends CommonObject
if (!$user->hasRight('societe', 'client', 'voir') && !$forVirtualStock) {
$sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
}
- $sql .= " WHERE cf.rowid = fd.fk_commande";
+ $sql .= " WHERE cf.rowid = fd.fk_element";
$sql .= " AND cf.fk_soc = s.rowid";
$sql .= " AND cf.entity IN (".getEntity($forVirtualStock && getDolGlobalString('STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE') ? 'stock' : 'supplier_order').")";
$sql .= " AND fd.fk_product = ".((int) $this->id);
diff --git a/htdocs/product/stock/class/productlot.class.php b/htdocs/product/stock/class/productlot.class.php
index 3d46b4ff41e..edbf9be17b8 100644
--- a/htdocs/product/stock/class/productlot.class.php
+++ b/htdocs/product/stock/class/productlot.class.php
@@ -855,7 +855,7 @@ class Productlot extends CommonObject
$sql = "SELECT COUNT(DISTINCT cf.fk_soc) as nb_customers, COUNT(DISTINCT cf.rowid) as nb,";
$sql .= " COUNT(cfd.rowid) as nb_rows, SUM(cfdi.qty) as qty";
$sql .= " FROM ".$this->db->prefix()."receptiondet_batch as cfdi";
- $sql .= " INNER JOIN ".$this->db->prefix()."commande_fournisseurdet as cfd ON (cfd.rowid = cfdi.fk_commandefourndet)";
+ $sql .= " INNER JOIN ".$this->db->prefix()."commande_fournisseurdet as cfd ON (cfd.rowid = cfdi.fk_elementdet)";
$sql .= " INNER JOIN ".$this->db->prefix()."commande_fournisseur as cf ON (cf.rowid = cfd.fk_commande)";
// $sql .= ", ".$this->db->prefix()."societe as s";
if (!$user->hasRight('societe', 'client', 'voir')) {
diff --git a/htdocs/product/stock/stats/commande_fournisseur.php b/htdocs/product/stock/stats/commande_fournisseur.php
index e179a65e1e1..a2e40c1db92 100644
--- a/htdocs/product/stock/stats/commande_fournisseur.php
+++ b/htdocs/product/stock/stats/commande_fournisseur.php
@@ -224,7 +224,7 @@ if ($id > 0 || !empty($ref)) {
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."commande_fournisseur as cf ON (cf.fk_soc = s.rowid)";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as cfd ON (cfd.fk_commande = cf.rowid)";
- $sql .= " INNER JOIN ".MAIN_DB_PREFIX."receptiondet_batch as cfdi ON (cfdi.fk_commandefourndet = cfd.rowid)";
+ $sql .= " INNER JOIN ".MAIN_DB_PREFIX."receptiondet_batch as cfdi ON (cfdi.fk_elementdet = cfd.rowid)";
if (!$user->hasRight('societe', 'client', 'voir')) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
diff --git a/htdocs/reception/card.php b/htdocs/reception/card.php
index b3362854db6..28e7c1933f4 100644
--- a/htdocs/reception/card.php
+++ b/htdocs/reception/card.php
@@ -1825,7 +1825,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('reception').")";
$sql .= " AND obj.fk_commande = ".((int) $origin_id);
- $sql .= " AND obj.rowid = ed.fk_commandefourndet";
+ $sql .= " AND obj.rowid = ed.fk_elementdet";
$sql .= " AND ed.fk_reception = e.rowid";
$sql .= " AND ed.fk_reception !=".((int) $object->id);
//if ($filter) $sql.= $filter;
diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php
index 92a59e101e5..b91c791bb9d 100644
--- a/htdocs/reception/class/reception.class.php
+++ b/htdocs/reception/class/reception.class.php
@@ -562,7 +562,7 @@ class Reception extends CommonObject
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
$sql .= " ".MAIN_DB_PREFIX."receptiondet_batch as ed";
$sql .= " WHERE ed.fk_reception = ".((int) $this->id);
- $sql .= " AND cd.rowid = ed.fk_commandefourndet";
+ $sql .= " AND cd.rowid = ed.fk_elementdet";
dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
$resql = $this->db->query($sql);
@@ -747,7 +747,7 @@ class Reception extends CommonObject
$qty_wished = array();
$supplierorderdispatch = new CommandeFournisseurDispatch($this->db);
- $filter = array('t.fk_commande' => $this->origin_id);
+ $filter = array('t.fk_element' => $this->origin_id);
if (getDolGlobalInt('SUPPLIER_ORDER_USE_DISPATCH_STATUS')) {
$filter['t.status'] = 1; // Restrict to lines with status validated
}
@@ -1071,7 +1071,7 @@ class Reception extends CommonObject
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
$sql .= " ".MAIN_DB_PREFIX."receptiondet_batch as ed";
$sql .= " WHERE ed.fk_reception = ".((int) $this->id);
- $sql .= " AND cd.rowid = ed.fk_commandefourndet";
+ $sql .= " AND cd.rowid = ed.fk_elementdet";
dol_syslog(get_class($this)."::delete select details", LOG_DEBUG);
$resql = $this->db->query($sql);
@@ -1660,7 +1660,7 @@ class Reception extends CommonObject
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
$sql .= " ".MAIN_DB_PREFIX."receptiondet_batch as ed";
$sql .= " WHERE ed.fk_reception = ".((int) $this->id);
- $sql .= " AND cd.rowid = ed.fk_commandefourndet";
+ $sql .= " AND cd.rowid = ed.fk_elementdet";
dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
$resql = $this->db->query($sql);
@@ -1818,7 +1818,7 @@ class Reception extends CommonObject
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
$sql .= " ".MAIN_DB_PREFIX."receptiondet_batch as ed";
$sql .= " WHERE ed.fk_reception = ".((int) $this->id);
- $sql .= " AND cd.rowid = ed.fk_commandefourndet";
+ $sql .= " AND cd.rowid = ed.fk_elementdet";
dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
$resql = $this->db->query($sql);
@@ -1952,7 +1952,7 @@ class Reception extends CommonObject
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
$sql .= " ".MAIN_DB_PREFIX."receptiondet_batch as ed";
$sql .= " WHERE ed.fk_reception = ".((int) $this->id);
- $sql .= " AND cd.rowid = ed.fk_commandefourndet";
+ $sql .= " AND cd.rowid = ed.fk_elementdet";
dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
$resql = $this->db->query($sql);
diff --git a/htdocs/reception/class/receptionlinebatch.class.php b/htdocs/reception/class/receptionlinebatch.class.php
new file mode 100644
index 00000000000..81f93a32f37
--- /dev/null
+++ b/htdocs/reception/class/receptionlinebatch.class.php
@@ -0,0 +1,754 @@
+
+ * Copyright (C) 2014 Juanjo Menent
+ * Copyright (C) 2024 Frédéric France
+ * Copyright (C) 2024 Christophe Battarel
+ * 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
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+/**
+ * \file htdocs/fourn/class/fournisseur.commande.dispatch.class.php
+ * \ingroup fournisseur stock
+ * \brief This file is an example for a CRUD class file (Create/Read/Update/Delete)
+ * Initially built by build_class_from_table on 2015-02-24 10:38
+ */
+
+// Put here all includes required by your class file
+require_once DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php";
+require_once DOL_DOCUMENT_ROOT."/reception/class/reception.class.php";
+
+
+/**
+ * Class to manage table commandefournisseurdispatch
+ */
+class ReceptionLineBatch extends CommonObjectLine
+{
+ /**
+ * @var DoliDB Database handler.
+ */
+ public $db;
+
+ /**
+ * @var string Error code (or message)
+ */
+ public $error;
+
+ /**
+ * @var string[] Error codes (or messages)
+ */
+ public $errors = array();
+
+ /**
+ * @var string ID to identify managed object
+ */
+ public $element = 'receptionlinebatch';
+
+ /**
+ * @var string Name of table without prefix where object is stored
+ */
+ public $table_element = 'receptiondet_batch'; //!< Name of table without prefix where object is stored
+ public $lines = array();
+
+ /**
+ * @var int ID
+ */
+ public $id;
+
+ /**
+ * @var int ID
+ */
+ public $fk_element;
+
+ /**
+ * @var int ID
+ */
+ public $fk_product;
+
+ /**
+ * @var int ID
+ */
+ public $fk_elementdet;
+
+ public $fk_reception;
+
+
+ public $qty;
+ public $qty_asked;
+
+ public $libelle;
+ public $label;
+ public $desc;
+ public $tva_tx;
+ public $vat_src_code;
+ public $ref_supplier;
+
+ /**
+ * @var int ID
+ */
+ public $fk_entrepot;
+
+ /**
+ * @var int User ID
+ */
+ public $fk_user;
+
+ public $datec = '';
+ public $comment;
+
+ /**
+ * @var int Status
+ */
+ public $status;
+
+ public $batch;
+ public $eatby = '';
+ public $sellby = '';
+ public $cost_price = 0;
+
+
+
+
+ /**
+ * Constructor
+ *
+ * @param DoliDB $db Database handler
+ */
+ public function __construct($db)
+ {
+ $this->db = $db;
+
+ // List of language codes for status
+ $this->labelStatus[0] = 'Received';
+ $this->labelStatus[1] = 'Verified';
+ $this->labelStatus[2] = 'Denied';
+ $this->labelStatusShort[0] = 'Received';
+ $this->labelStatusShort[1] = 'Verified';
+ $this->labelStatusShort[2] = 'Denied';
+ }
+
+
+ /**
+ * Create object into database
+ *
+ * @param User $user User that creates
+ * @param int $notrigger 0=launch triggers after, 1=disable triggers
+ * @return int Return integer <0 if KO, Id of created object if OK
+ */
+ public function create($user, $notrigger = 0)
+ {
+ global $conf, $langs, $hookmanager;
+ $error = 0;
+
+ // Clean parameters
+
+ if (isset($this->fk_element)) {
+ $this->fk_element = (int) $this->fk_element;
+ }
+ if (isset($this->fk_product)) {
+ $this->fk_product = (int) $this->fk_product;
+ }
+ if (isset($this->fk_elementdet)) {
+ $this->fk_elementdet = (int) $this->fk_elementdet;
+ }
+ if (isset($this->qty)) {
+ $this->qty = trim($this->qty);
+ }
+ if (isset($this->fk_entrepot)) {
+ $this->fk_entrepot = (int) $this->fk_entrepot;
+ }
+ if (isset($this->fk_user)) {
+ $this->fk_user = (int) $this->fk_user;
+ }
+ if (isset($this->comment)) {
+ $this->comment = trim($this->comment);
+ }
+ if (isset($this->status)) {
+ $this->status = (int) $this->status;
+ }
+ if (isset($this->batch)) {
+ $this->batch = trim($this->batch);
+ }
+ if (empty($this->datec)) {
+ $this->datec = dol_now();
+ }
+
+
+ // Check parameters
+ // Put here code to add control on parameters values
+
+ // Insert request
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."(";
+ $sql .= "fk_element,";
+ $sql .= "fk_product,";
+ $sql .= "fk_elementdet,";
+ $sql .= "qty,";
+ $sql .= "fk_entrepot,";
+ $sql .= "fk_user,";
+ $sql .= "datec,";
+ $sql .= "comment,";
+ $sql .= "status,";
+ $sql .= "batch,";
+ $sql .= "eatby,";
+ $sql .= "sellby,";
+ $sql .= "fk_reception,";
+ $sql .= "cost_price";
+
+
+ $sql .= ") VALUES (";
+ $sql .= " ".(!isset($this->fk_element) ? 'NULL' : "'".$this->db->escape($this->fk_element)."'").",";
+ $sql .= " ".(!isset($this->fk_product) ? 'NULL' : "'".$this->db->escape($this->fk_product)."'").",";
+ $sql .= " ".(!isset($this->fk_elementdet) ? 'NULL' : "'".$this->db->escape($this->fk_elementdet)."'").",";
+ $sql .= " ".(!isset($this->qty) ? 'NULL' : "'".$this->db->escape($this->qty)."'").",";
+ $sql .= " ".(!isset($this->fk_entrepot) ? 'NULL' : "'".$this->db->escape($this->fk_entrepot)."'").",";
+ $sql .= " ".(!isset($this->fk_user) ? 'NULL' : "'".$this->db->escape($this->fk_user)."'").",";
+ $sql .= " ".(!isset($this->datec) || dol_strlen($this->datec) == 0 ? 'NULL' : "'".$this->db->idate($this->datec)."'").",";
+ $sql .= " ".(!isset($this->comment) ? 'NULL' : "'".$this->db->escape($this->comment)."'").",";
+ $sql .= " ".(!isset($this->status) ? 'NULL' : "'".$this->db->escape($this->status)."'").",";
+ $sql .= " ".(!isset($this->batch) ? 'NULL' : "'".$this->db->escape($this->batch)."'").",";
+ $sql .= " ".(!isset($this->eatby) || dol_strlen($this->eatby) == 0 ? 'NULL' : "'".$this->db->idate($this->eatby)."'").",";
+ $sql .= " ".(!isset($this->sellby) || dol_strlen($this->sellby) == 0 ? 'NULL' : "'".$this->db->idate($this->sellby)."'").",";
+ $sql .= " ".(!isset($this->fk_reception) ? 'NULL' : "'".$this->db->escape($this->fk_reception)."'").",";
+ $sql .= " ".(!isset($this->cost_price) ? '0' : "'".$this->db->escape($this->cost_price)."'");
+ $sql .= ")";
+
+ $this->db->begin();
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if (!$resql) {
+ $error++;
+ $this->errors[] = "Error ".$this->db->lasterror();
+ }
+
+ if (!$error) {
+ $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
+
+ if (!$notrigger) {
+ // Call triggers
+ $result = $this->call_trigger('LINERECEPTION_CREATE', $user);
+ if ($result < 0) {
+ $error++;
+ }
+ // End call triggers
+ }
+ }
+
+ // Create extrafields
+ if (!$error) {
+ $result = $this->insertExtraFields();
+ if ($result < 0) {
+ $error++;
+ }
+ }
+
+ // Commit or rollback
+ if ($error) {
+ foreach ($this->errors as $errmsg) {
+ dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
+ $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
+ }
+ $this->db->rollback();
+ return -1 * $error;
+ } else {
+ $this->db->commit();
+ return $this->id;
+ }
+ }
+
+
+ /**
+ * Load object in memory from the database
+ *
+ * @param int $id Id object
+ * @param string $ref Ref
+ * @return int Return integer <0 if KO, >0 if OK
+ */
+ public function fetch($id, $ref = '')
+ {
+ global $langs;
+ $sql = "SELECT";
+ $sql .= " t.rowid,";
+
+ $sql .= " t.fk_element,";
+ $sql .= " t.fk_product,";
+ $sql .= " t.fk_elementdet,";
+ $sql .= " t.qty,";
+ $sql .= " t.fk_entrepot,";
+ $sql .= " t.fk_user,";
+ $sql .= " t.datec,";
+ $sql .= " t.comment,";
+ $sql .= " t.status,";
+ $sql .= " t.tms,";
+ $sql .= " t.batch,";
+ $sql .= " t.eatby,";
+ $sql .= " t.sellby,";
+ $sql .= " t.fk_reception";
+
+
+ $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
+ if ($ref) {
+ $sql .= " WHERE t.ref = '".$this->db->escape($ref)."'";
+ } else {
+ $sql .= " WHERE t.rowid = ".((int) $id);
+ }
+
+ dol_syslog(get_class($this)."::fetch");
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ if ($this->db->num_rows($resql)) {
+ $obj = $this->db->fetch_object($resql);
+
+ $this->id = $obj->rowid;
+
+ $this->fk_element = $obj->fk_element;
+ $this->fk_product = $obj->fk_product;
+ $this->fk_elementdet = $obj->fk_elementdet;
+ $this->qty = $obj->qty;
+ $this->fk_entrepot = $obj->fk_entrepot;
+ $this->fk_user = $obj->fk_user;
+ $this->datec = $this->db->jdate($obj->datec);
+ $this->comment = $obj->comment;
+ $this->status = $obj->status;
+ $this->tms = $this->db->jdate($obj->tms);
+ $this->batch = $obj->batch;
+ $this->eatby = $this->db->jdate($obj->eatby);
+ $this->sellby = $this->db->jdate($obj->sellby);
+ $this->fk_reception = $obj->fk_reception;
+
+ $this->fetch_optionals();
+ }
+ $this->db->free($resql);
+
+ return 1;
+ } else {
+ $this->error = "Error ".$this->db->lasterror();
+ return -1;
+ }
+ }
+
+
+ /**
+ * Update object into database
+ *
+ * @param User $user User that modifies
+ * @param int $notrigger 0=launch triggers after, 1=disable triggers
+ * @return int Return integer <0 if KO, >0 if OK
+ */
+ public function update($user, $notrigger = 0)
+ {
+ $error = 0;
+
+ // Clean parameters
+
+ if (isset($this->fk_element)) {
+ $this->fk_element = (int) $this->fk_element;
+ }
+ if (isset($this->fk_product)) {
+ $this->fk_product = (int) $this->fk_product;
+ }
+ if (isset($this->fk_elementdet)) {
+ $this->fk_elementdet = (int) $this->fk_elementdet;
+ }
+ if (isset($this->qty)) {
+ $this->qty = trim($this->qty);
+ }
+ if (isset($this->fk_entrepot)) {
+ $this->fk_entrepot = (int) $this->fk_entrepot;
+ }
+ if (isset($this->fk_user)) {
+ $this->fk_user = (int) $this->fk_user;
+ }
+ if (isset($this->comment)) {
+ $this->comment = trim($this->comment);
+ }
+ if (isset($this->status)) {
+ $this->status = (int) $this->status;
+ }
+ if (isset($this->batch)) {
+ $this->batch = trim($this->batch);
+ }
+
+
+
+ // Check parameters
+ // Put here code to add a control on parameters values
+
+ // Update request
+ $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
+ $sql .= " fk_element=".(isset($this->fk_element) ? $this->fk_element : "null").",";
+ $sql .= " fk_product=".(isset($this->fk_product) ? $this->fk_product : "null").",";
+ $sql .= " fk_elementdet=".(isset($this->fk_elementdet) ? $this->fk_elementdet : "null").",";
+ $sql .= " qty=".(isset($this->qty) ? $this->qty : "null").",";
+ $sql .= " fk_entrepot=".(isset($this->fk_entrepot) ? $this->fk_entrepot : "null").",";
+ $sql .= " fk_user=".(isset($this->fk_user) ? $this->fk_user : "null").",";
+ $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
+ $sql .= " comment=".(isset($this->comment) ? "'".$this->db->escape($this->comment)."'" : "null").",";
+ $sql .= " status=".(isset($this->status) ? $this->status : "null").",";
+ $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
+ $sql .= " batch=".(isset($this->batch) ? "'".$this->db->escape($this->batch)."'" : "null").",";
+ $sql .= " eatby=".(dol_strlen($this->eatby) != 0 ? "'".$this->db->idate($this->eatby)."'" : 'null').",";
+ $sql .= " sellby=".(dol_strlen($this->sellby) != 0 ? "'".$this->db->idate($this->sellby)."'" : 'null');
+ $sql .= " WHERE rowid=".((int) $this->id);
+
+ $this->db->begin();
+
+ dol_syslog(__METHOD__);
+ $resql = $this->db->query($sql);
+ if (!$resql) {
+ $error++;
+ $this->errors[] = "Error ".$this->db->lasterror();
+ }
+
+ if (!$error) {
+ if (!$error) {
+ if (empty($this->id) && !empty($this->rowid)) {
+ $this->id = $this->rowid;
+ }
+ $result = $this->insertExtraFields();
+ if ($result < 0) {
+ $error++;
+ }
+ }
+
+ if (!$notrigger) {
+ // Call triggers
+ $result = $this->call_trigger('LINERECEPTION_MODIFY', $user);
+ if ($result < 0) {
+ $error++;
+ }
+ // End call triggers
+ }
+ }
+
+ // Commit or rollback
+ if ($error) {
+ foreach ($this->errors as $errmsg) {
+ dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
+ $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
+ }
+ $this->db->rollback();
+ return -1 * $error;
+ } else {
+ $this->db->commit();
+ return 1;
+ }
+ }
+
+
+ /**
+ * Delete object in database
+ *
+ * @param User $user User that deletes
+ * @param int $notrigger 0=launch triggers after, 1=disable triggers
+ * @return int Return integer <0 if KO, >0 if OK
+ */
+ public function delete($user, $notrigger = 0)
+ {
+ $error = 0;
+
+ $this->db->begin();
+
+ if (!$error) {
+ if (!$notrigger) {
+ // Call triggers
+ $result = $this->call_trigger('LINERECEPTION_DELETE', $user);
+ if ($result < 0) {
+ $error++;
+ }
+ // End call triggers
+ }
+ }
+
+ // Remove extrafields
+ if (!$error) {
+ $result = $this->deleteExtraFields();
+ if ($result < 0) {
+ $error++;
+ dol_syslog(get_class($this)."::delete error deleteExtraFields ".$this->error, LOG_ERR);
+ }
+ }
+
+ if (!$error) {
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
+ $sql .= " WHERE rowid=".((int) $this->id);
+
+ dol_syslog(__METHOD__);
+ $resql = $this->db->query($sql);
+ if (!$resql) {
+ $error++;
+ $this->errors[] = "Error ".$this->db->lasterror();
+ }
+ }
+
+ // Commit or rollback
+ if ($error) {
+ foreach ($this->errors as $errmsg) {
+ dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
+ $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
+ }
+ $this->db->rollback();
+ return -1 * $error;
+ } else {
+ $this->db->commit();
+ return 1;
+ }
+ }
+
+
+ /**
+ * Load an object from its id and create a new one in database
+ *
+ * @param User $user User making the clone
+ * @param int $fromid Id of object to clone
+ * @return int New id of clone
+ */
+ public function createFromClone(User $user, $fromid)
+ {
+ $error = 0;
+
+ $object = new ReceptionLineBatch($this->db);
+
+ $this->db->begin();
+
+ // Load source object
+ $object->fetch($fromid);
+ $object->id = 0;
+ $object->statut = 0;
+
+ // Clear fields
+ // ...
+
+ // Create clone
+ $object->context['createfromclone'] = 'createfromclone';
+ $result = $object->create($user);
+
+ // Other options
+ if ($result < 0) {
+ $this->error = $object->error;
+ $error++;
+ }
+
+ if (!$error) {
+ }
+
+ unset($object->context['createfromclone']);
+
+ // End
+ if (!$error) {
+ $this->db->commit();
+ return $object->id;
+ } else {
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
+
+
+ /**
+ * Return label of the status of object
+ *
+ * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto
+ * @return string Label
+ */
+ public function getLibStatut($mode = 0)
+ {
+ return $this->LibStatut($this->status, $mode);
+ }
+
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * Return label of a status
+ *
+ * @param int $status Id status
+ * @param int $mode 0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto
+ * @return string Label of status
+ */
+ public function LibStatut($status, $mode = 0)
+ {
+ // phpcs:enable
+ global $langs;
+ $langs->load('orders');
+
+ if ($mode == 0) {
+ return $langs->trans($this->labelStatus[$status]);
+ } elseif ($mode == 1) {
+ return $langs->trans($this->labelStatusShort[$status]);
+ } elseif ($mode == 2) {
+ return $langs->trans($this->labelStatus[$status]);
+ } elseif ($mode == 3) {
+ if ($status == 0) {
+ return img_picto($langs->trans($this->labelStatus[$status]), 'statut0');
+ } elseif ($status == 1) {
+ return img_picto($langs->trans($this->labelStatus[$status]), 'statut4');
+ } elseif ($status == 2) {
+ return img_picto($langs->trans($this->labelStatus[$status]), 'statut8');
+ }
+ } elseif ($mode == 4) {
+ if ($status == 0) {
+ return img_picto($langs->trans($this->labelStatus[$status]), 'statut0').' '.$langs->trans($this->labelStatus[$status]);
+ } elseif ($status == 1) {
+ return img_picto($langs->trans($this->labelStatus[$status]), 'statut4').' '.$langs->trans($this->labelStatus[$status]);
+ } elseif ($status == 2) {
+ return img_picto($langs->trans($this->labelStatus[$status]), 'statut8').' '.$langs->trans($this->labelStatus[$status]);
+ }
+ } elseif ($mode == 5) {
+ if ($status == 0) {
+ return ''.$langs->trans($this->labelStatusShort[$status]).' '.img_picto($langs->trans($this->labelStatus[$status]), 'statut0');
+ } elseif ($status == 1) {
+ return ''.$langs->trans($this->labelStatusShort[$status]).' '.img_picto($langs->trans($this->labelStatus[$status]), 'statut4');
+ } elseif ($status == 2) {
+ return ''.$langs->trans($this->labelStatusShort[$status]).' '.img_picto($langs->trans($this->labelStatus[$status]), 'statut8');
+ }
+ }
+ return "";
+ }
+
+
+ /**
+ * Initialise object with example values
+ * Id must be 0 if object instance is a specimen
+ *
+ * @return int
+ */
+ public function initAsSpecimen()
+ {
+ $this->id = 0;
+
+ $this->fk_element = 0;
+ $this->fk_product = 0;
+ $this->fk_elementdet = 0;
+ $this->qty = '';
+ $this->fk_entrepot = 0;
+ $this->fk_user = 0;
+ $this->datec = '';
+ $this->comment = '';
+ $this->status = 0;
+ $this->tms = dol_now();
+ $this->batch = '';
+ $this->eatby = '';
+ $this->sellby = '';
+
+ return 1;
+ }
+
+ /**
+ * Load object in memory from the database
+ *
+ * @param string $sortorder Sort Order
+ * @param string $sortfield Sort field
+ * @param int $limit limit
+ * @param int $offset offset limit
+ * @param string|array $filter filter array
+ * @param string $filtermode filter mode (AND or OR)
+ * @return int Return integer <0 if KO, >0 if OK
+ */
+ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
+ {
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $sql = "SELECT";
+ $sql .= " t.rowid,";
+ $sql .= " t.fk_element,";
+ $sql .= " t.fk_product,";
+ $sql .= " t.fk_elementdet,";
+ $sql .= " t.qty,";
+ $sql .= " t.fk_entrepot,";
+ $sql .= " t.fk_user,";
+ $sql .= " t.datec,";
+ $sql .= " t.comment,";
+ $sql .= " t.status,";
+ $sql .= " t.tms,";
+ $sql .= " t.batch,";
+ $sql .= " t.eatby,";
+ $sql .= " t.sellby";
+ $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
+
+ // Manage filter
+ if (is_array($filter)) {
+ $sqlwhere = array();
+ if (count($filter) > 0) {
+ foreach ($filter as $key => $value) {
+ if ($key == 't.comment') {
+ $sqlwhere [] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
+ } elseif ($key == 't.datec' || $key == 't.tms' || $key == 't.eatby' || $key == 't.sellby' || $key == 't.batch') {
+ $sqlwhere [] = $this->db->sanitize($key)." = '".$this->db->escape($value)."'";
+ } elseif ($key == 'qty') {
+ $sqlwhere [] = $this->db->sanitize($key)." = ".((float) $value);
+ } else {
+ $sqlwhere [] = $this->db->sanitize($key)." = ".((int) $value);
+ }
+ }
+ }
+ if (count($sqlwhere) > 0) {
+ $sql .= ' WHERE '.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere);
+ }
+
+ $filter = '';
+ }
+
+ // Manage filter
+ $errormessage = '';
+ $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
+ if ($errormessage) {
+ $this->errors[] = $errormessage;
+ dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
+ return -1;
+ }
+
+ if (!empty($sortfield)) {
+ $sql .= $this->db->order($sortfield, $sortorder);
+ }
+ if (!empty($limit)) {
+ $sql .= $this->db->plimit($limit, $offset);
+ }
+ $this->lines = array();
+
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $num = $this->db->num_rows($resql);
+
+ while ($obj = $this->db->fetch_object($resql)) {
+ $line = new self($this->db);
+
+ $line->id = $obj->rowid;
+
+ $line->fk_element = $obj->fk_element;
+ $line->fk_product = $obj->fk_product;
+ $line->fk_elementdet = $obj->fk_elementdet;
+ $line->qty = $obj->qty;
+ $line->fk_entrepot = $obj->fk_entrepot;
+ $line->fk_user = $obj->fk_user;
+ $line->datec = $this->db->jdate($obj->datec);
+ $line->comment = $obj->comment;
+ $line->status = $obj->status;
+ $line->tms = $this->db->jdate($obj->tms);
+ $line->batch = $obj->batch;
+ $line->eatby = $this->db->jdate($obj->eatby);
+ $line->sellby = $this->db->jdate($obj->sellby);
+ $line->fetch_optionals();
+
+ $this->lines[$line->id] = $line;
+ }
+ $this->db->free($resql);
+
+ return $num;
+ } else {
+ $this->errors[] = 'Error '.$this->db->lasterror();
+ dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
+
+ return -1;
+ }
+ }
+}
diff --git a/htdocs/reception/dispatch.php b/htdocs/reception/dispatch.php
index b48ea7b4164..3d2ed4bd36c 100644
--- a/htdocs/reception/dispatch.php
+++ b/htdocs/reception/dispatch.php
@@ -462,7 +462,7 @@ if ($id > 0 || !empty($ref)) {
$products_dispatched = array();
$sql = "SELECT l.rowid, cfd.fk_product, sum(cfd.qty) as qty";
$sql .= " FROM ".MAIN_DB_PREFIX."receptiondet_batch as cfd";
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as l on l.rowid = cfd.fk_commandefourndet";
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."receptiondet_batch as l on l.rowid = cfd.fk_elementdet";
$sql .= " WHERE cfd.fk_reception = ".((int) $object->id);
$sql .= " GROUP BY l.rowid, cfd.fk_product";
@@ -690,8 +690,8 @@ if ($id > 0 || !empty($ref)) {
$sql = "SELECT cfd.rowid, cfd.qty, cfd.fk_entrepot, cfd.batch, cfd.eatby, cfd.sellby, cfd.fk_product";
$sql .= " FROM ".MAIN_DB_PREFIX."receptiondet_batch as cfd"; // commande_fournisseur_dispatch should be named receptiondet_batch
$sql .= " WHERE cfd.fk_reception = ".((int) $object->id);
- $sql .= " AND cfd.fk_commande = ".((int) $objectsrc->id);
- $sql .= " AND cfd.fk_commandefourndet = ".(int) $objp->rowid;
+ $sql .= " AND cfd.fk_element = ".((int) $objectsrc->id);
+ $sql .= " AND cfd.fk_elementdet = ".(int) $objp->rowid;
//print $sql;
$resultsql = $db->query($sql);