Update from develop

This commit is contained in:
VESSILLER
2024-01-15 13:55:26 +01:00
3289 changed files with 104166 additions and 92979 deletions

View File

@@ -30,7 +30,7 @@
/**
* \file htdocs/reception/class/reception.class.php
* \ingroup reception
* \brief Fichier de la classe de gestion des receptions
* \brief File for class to manage receptions
*/
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
@@ -95,8 +95,9 @@ class Reception extends CommonObject
// A denormalized value
public $trueSize;
public $size_units;
public $user_author_id;
public $date_delivery; // Date delivery planed
public $date_delivery; // Date delivery planned
/**
* @var integer|string Effective delivery date
@@ -165,11 +166,11 @@ class Reception extends CommonObject
global $langs, $conf;
$langs->load("receptions");
if (!empty($conf->global->RECEPTION_ADDON_NUMBER)) {
if (getDolGlobalString('RECEPTION_ADDON_NUMBER')) {
$mybool = false;
$file = $conf->global->RECEPTION_ADDON_NUMBER.".php";
$classname = $conf->global->RECEPTION_ADDON_NUMBER;
$file = getDolGlobalString('RECEPTION_ADDON_NUMBER') . ".php";
$classname = getDolGlobalString('RECEPTION_ADDON_NUMBER');
// Include file with class
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
@@ -206,9 +207,9 @@ class Reception extends CommonObject
/**
* Create reception en base
*
* @param User $user Objet du user qui cree
* @param User $user Object du user qui cree
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @return int <0 si erreur, id reception creee si ok
* @return int Return integer <0 si erreur, id reception creee si ok
*/
public function create($user, $notrigger = 0)
{
@@ -269,12 +270,12 @@ class Reception extends CommonObject
$sql .= ", ".((int) $this->fk_project);
$sql .= ", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) : "null");
$sql .= ", '".$this->db->escape($this->tracking_number)."'";
$sql .= ", ".(is_null($this->weight) ? "NULL" : ((double) $this->weight));
$sql .= ", ".(is_null($this->trueDepth) ? "NULL" : ((double) $this->trueDepth));
$sql .= ", ".(is_null($this->trueWidth) ? "NULL" : ((double) $this->trueWidth));
$sql .= ", ".(is_null($this->trueHeight) ? "NULL" : ((double) $this->trueHeight));
$sql .= ", ".(is_null($this->weight_units) ? "NULL" : ((double) $this->weight_units));
$sql .= ", ".(is_null($this->size_units) ? "NULL" : ((double) $this->size_units));
$sql .= ", ".(is_null($this->weight) ? "NULL" : ((float) $this->weight));
$sql .= ", ".(is_null($this->trueDepth) ? "NULL" : ((float) $this->trueDepth));
$sql .= ", ".(is_null($this->trueWidth) ? "NULL" : ((float) $this->trueWidth));
$sql .= ", ".(is_null($this->trueHeight) ? "NULL" : ((float) $this->trueHeight));
$sql .= ", ".(is_null($this->weight_units) ? "NULL" : ((float) $this->weight_units));
$sql .= ", ".(is_null($this->size_units) ? "NULL" : ((float) $this->size_units));
$sql .= ", ".(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null");
$sql .= ", ".(!empty($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null");
$sql .= ", ".(!empty($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null");
@@ -413,7 +414,7 @@ class Reception extends CommonObject
$this->date_creation = $this->db->jdate($obj->date_creation);
$this->date = $this->db->jdate($obj->date_reception); // TODO deprecated
$this->date_reception = $this->db->jdate($obj->date_reception); // Date real
$this->date_delivery = $this->db->jdate($obj->date_delivery); // Date planed
$this->date_delivery = $this->db->jdate($obj->date_delivery); // Date planned
$this->model_pdf = $obj->model_pdf;
$this->shipping_method_id = $obj->fk_shipping_method;
$this->tracking_number = $obj->tracking_number;
@@ -488,7 +489,7 @@ class Reception extends CommonObject
*
* @param User $user Object user that validate
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @return int <0 if OK, >0 if KO
* @return int Return integer <0 if OK, >0 if KO
*/
public function valid($user, $notrigger = 0)
{
@@ -504,8 +505,8 @@ class Reception extends CommonObject
return 0;
}
if (!((!getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->reception->creer))
|| (getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->reception->reception_advance->validate)))) {
if (!((!getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'creer'))
|| (getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'reception_advance', 'validate')))) {
$this->error = 'Permission denied';
dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
return -1;
@@ -545,7 +546,7 @@ class Reception extends CommonObject
$error++;
}
// If stock increment is done on reception (recommanded choice)
// If stock increment is done on reception (recommended choice)
if (!$error && isModEnabled('stock') && getDolGlobalInt('STOCK_CALCULATE_ON_RECEPTION')) {
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
@@ -617,22 +618,24 @@ class Reception extends CommonObject
}
}
// Change status of order to "reception in process" or "totally received"
$status = $this->getStatusDispatch();
if ($status < 0) {
$error++;
} else {
$trigger_key = '';
if ($status == CommandeFournisseur::STATUS_RECEIVED_COMPLETELY) {
$ret = $this->commandeFournisseur->Livraison($user, dol_now(), 'tot', '');
if ($ret < 0) {
$error++;
$this->errors = array_merge($this->errors, $this->commandeFournisseur->errors);
}
if (!$error) {
// Change status of order to "reception in process" or "totally received"
$status = $this->getStatusDispatch();
if ($status < 0) {
$error++;
} else {
$ret = $this->setStatut($status, $this->origin_id, 'commande_fournisseur', $trigger_key);
if ($ret < 0) {
$error++;
$trigger_key = '';
if ($status == CommandeFournisseur::STATUS_RECEIVED_COMPLETELY) {
$ret = $this->commandeFournisseur->Livraison($user, dol_now(), 'tot', '');
if ($ret < 0) {
$error++;
$this->errors = array_merge($this->errors, $this->commandeFournisseur->errors);
}
} else {
$ret = $this->setStatut($status, $this->origin_id, 'commande_fournisseur', $trigger_key);
if ($ret < 0) {
$error++;
}
}
}
}
@@ -656,13 +659,15 @@ class Reception extends CommonObject
$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'reception/".$this->db->escape($this->ref)."' AND entity = ".((int) $conf->entity);
$resql = $this->db->query($sql);
if (!$resql) {
$error++; $this->error = $this->db->lasterror();
$error++;
$this->error = $this->db->lasterror();
}
$sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'reception/".$this->db->escape($this->newref)."'";
$sql .= " WHERE filepath = 'reception/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
$resql = $this->db->query($sql);
if (!$resql) {
$error++; $this->error = $this->db->lasterror();
$error++;
$this->error = $this->db->lasterror();
}
// We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
@@ -712,23 +717,24 @@ class Reception extends CommonObject
/**
* Get status from all dispatched lines
*
* @return int <0 if KO, Status of reception if OK
* @return int Return integer <0 if KO, Status of reception if OK
*/
public function getStatusDispatch()
{
global $conf;
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
$status = CommandeFournisseur::STATUS_RECEIVED_PARTIALLY;
if (!empty($this->origin) && $this->origin_id > 0 && ($this->origin == 'order_supplier' || $this->origin == 'commandeFournisseur')) {
if (empty($this->commandeFournisseur)) {
if (empty($this->origin_object)) {
$this->fetch_origin();
if (empty($this->commandeFournisseur->lines)) {
$res = $this->commandeFournisseur->fetch_lines();
if ($res < 0) return $res;
if (empty($this->origin_object->lines)) {
$res = $this->origin_object->fetch_lines();
$this->commandeFournisseur = $this->origin_object; // deprecated
if ($res < 0) {
return $res;
}
}
}
@@ -808,14 +814,14 @@ class Reception extends CommonObject
* @param int $id Id of source line (supplier order line)
* @param int $qty Quantity
* @param array $array_options extrafields array
* @param string $comment Comment for stock movement
* @param integer $eatby eat-by date
* @param integer $sellby sell-by date
* @param string $batch Lot number
* @param string $comment Comment for stock movement
* @param int $eatby eat-by date
* @param int $sellby sell-by date
* @param string $batch Lot number
* @param double $cost_price Line cost
* @return int <0 if KO, index of line if OK
* @return int Return integer <0 if KO, index of line if OK
*/
public function addline($entrepot_id, $id, $qty, $array_options = 0, $comment = '', $eatby = '', $sellby = '', $batch = '', $cost_price = 0)
public function addline($entrepot_id, $id, $qty, $array_options = [], $comment = '', $eatby = null, $sellby = null, $batch = '', $cost_price = 0)
{
global $conf, $langs, $user;
@@ -903,7 +909,7 @@ class Reception extends CommonObject
*
* @param User $user User that modify
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
* @return int Return integer <0 if KO, >0 if OK
*/
public function update($user = null, $notrigger = 0)
{
@@ -1003,7 +1009,8 @@ class Reception extends CommonObject
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
$error++;
$this->errors[] = "Error ".$this->db->lasterror();
}
if (!$error) {
@@ -1076,7 +1083,8 @@ class Reception extends CommonObject
$result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans("ReceptionDeletedInDolibarr", $this->ref), '', $obj->eatby, $obj->sellby, $obj->batch); // Price is set to 0, because we don't want to see WAP changed
}
} else {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
$error++;
$this->errors[] = "Error ".$this->db->lasterror();
}
}
@@ -1258,7 +1266,8 @@ class Reception extends CommonObject
*/
public function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0)
{
global $conf, $langs, $hookmanager;
global $langs, $hookmanager;
$result = '';
$label = img_picto('', $this->picto).' <u>'.$langs->trans("Reception").'</u>';
$label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
@@ -1363,6 +1372,43 @@ class Reception extends CommonObject
return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
}
/**
* Return clicable link of object (with eventually picto)
*
* @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link)
* @param array $arraydata Array of data
* @return string HTML Code for Kanban thumb.
*/
public function getKanbanView($option = '', $arraydata = null)
{
$selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
$return = '<div class="box-flex-item box-flex-grow-zero">';
$return .= '<div class="info-box info-box-sm">';
$return .= '<div class="info-box-icon bg-infobox-action">';
$return .= img_picto('', 'order');
$return .= '</div>';
$return .= '<div class="info-box-content">';
$return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
if ($selected >= 0) {
$return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
}
if (property_exists($this, 'thirdparty') && is_object($this->thirdparty)) {
$return .= '<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).'</div>';
}
/*if (property_exists($this, 'total_ht')) {
$return .= '<div class="info-box-ref amount">'.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency).' '.$langs->trans('HT').'</div>';
}*/
if (method_exists($this, 'getLibStatut')) {
$return .= '<div class="info-box-status">'.$this->getLibStatut(3).'</div>';
}
$return .= '</div>';
$return .= '</div>';
$return .= '</div>';
return $return;
}
/**
* Initialise an instance with random values.
* Used to build previews or test instances.
@@ -1383,12 +1429,11 @@ class Reception extends CommonObject
$order = new CommandeFournisseur($this->db);
$order->initAsSpecimen();
// Initialise parametres
// Initialise parameters
$this->id = 0;
$this->ref = 'SPECIMEN';
$this->specimen = 1;
$this->statut = 1;
$this->livraison_id = 0;
$this->date = $now;
$this->date_creation = $now;
$this->date_valid = $now;
@@ -1398,11 +1443,10 @@ class Reception extends CommonObject
$this->entrepot_id = 0;
$this->socid = 1;
$this->commande_id = 0;
$this->commande = $order;
$this->origin_id = 1;
$this->origin = 'commande';
$this->origin_object = $order;
$this->commandeFournisseur = $order; // deprecated
$this->note_private = 'Private note';
$this->note_public = 'Public note';
@@ -1416,7 +1460,7 @@ class Reception extends CommonObject
$line->label = $langs->trans("Description")." ".$xnbp;
$line->qty = 10;
$line->fk_product = $this->commande->lines[$xnbp]->fk_product;
$line->fk_product = $this->origin_object->lines[$xnbp]->fk_product;
$this->lines[] = $line;
$xnbp++;
@@ -1426,14 +1470,14 @@ class Reception extends CommonObject
/**
* Set the planned delivery date
*
* @param User $user Objet utilisateur qui modifie
* @param User $user Object utilisateur qui modifie
* @param integer $delivery_date Delivery date
* @return int <0 if KO, >0 if OK
* @return int Return integer <0 if KO, >0 if OK
*/
public function setDeliveryDate($user, $delivery_date)
{
// phpcs:enable
if ($user->rights->reception->creer) {
if ($user->hasRight('reception', 'creer')) {
$sql = "UPDATE ".MAIN_DB_PREFIX."reception";
$sql .= " SET date_delivery = ".($delivery_date ? "'".$this->db->idate($delivery_date)."'" : 'null');
$sql .= " WHERE rowid = ".((int) $this->id);
@@ -1485,7 +1529,7 @@ class Reception extends CommonObject
* @param int $id only this carrier, all if none
* @return void
*/
public function list_delivery_methods($id = '')
public function list_delivery_methods($id = 0)
{
// phpcs:enable
global $langs;
@@ -1495,7 +1539,7 @@ class Reception extends CommonObject
$sql = "SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
$sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
if ($id != '') {
if (!empty($id)) {
$sql .= " WHERE em.rowid = ".((int) $id);
}
@@ -1546,7 +1590,7 @@ class Reception extends CommonObject
/**
* Classify the reception as closed (this record also the stock movement)
*
* @return int <0 if KO, >0 if OK
* @return int Return integer <0 if KO, >0 if OK
*/
public function setClosed()
{
@@ -1639,7 +1683,8 @@ class Reception extends CommonObject
if ($result < 0) {
$this->error = $mouvS->error;
$this->errors = $mouvS->errors;
$error++; break;
$error++;
break;
}
} else {
// line with batch detail
@@ -1651,7 +1696,8 @@ class Reception extends CommonObject
if ($result < 0) {
$this->error = $mouvS->error;
$this->errors = $mouvS->errors;
$error++; break;
$error++;
break;
}
}
}
@@ -1677,15 +1723,17 @@ class Reception extends CommonObject
$this->db->commit();
return 1;
} else {
$this->statut = self::STATUS_VALIDATED;
$this->status = self::STATUS_VALIDATED;
$this->db->rollback();
return -1;
}
}
/**
* Classify the reception as invoiced (used for exemple by trigger when WORKFLOW_RECEPTION_CLASSIFY_BILLED_INVOICE is on)
* Classify the reception as invoiced (used for example by trigger when WORKFLOW_RECEPTION_CLASSIFY_BILLED_INVOICE is on)
*
* @return int <0 if ko, >0 if ok
* @return int Return integer <0 if ko, >0 if ok
*/
public function setBilled()
{
@@ -1729,7 +1777,7 @@ class Reception extends CommonObject
/**
* Classify the reception as validated/opened
*
* @return int <0 if ko, >0 if ok
* @return int Return integer <0 if ko, >0 if ok
*/
public function reOpen()
{
@@ -1795,7 +1843,8 @@ class Reception extends CommonObject
if ($result < 0) {
$this->error = $mouvS->error;
$this->errors = $mouvS->errors;
$error++; break;
$error++;
break;
}
} else {
// line with batch detail
@@ -1806,7 +1855,8 @@ class Reception extends CommonObject
if ($result < 0) {
$this->error = $mouvS->error;
$this->errors = $mouvS->errors;
$error++; break;
$error++;
break;
}
}
}
@@ -1848,12 +1898,12 @@ class Reception extends CommonObject
}
}
/**
* Set draft status
*
* @param User $user Object user that modify
* @return int <0 if KO, >0 if OK
*/
/**
* Set draft status
*
* @param User $user Object user that modify
* @return int Return integer <0 if KO, >0 if OK
*/
public function setDraft($user)
{
// phpcs:enable
@@ -1866,8 +1916,8 @@ class Reception extends CommonObject
return 0;
}
if (!((!getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->reception->creer))
|| (getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->reception->reception_advance->validate)))) {
if (!((!getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'creer'))
|| (getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'reception_advance', 'validate')))) {
$this->error = 'Permission denied';
return -1;
}
@@ -1938,7 +1988,8 @@ class Reception extends CommonObject
if ($result < 0) {
$this->error = $mouvS->error;
$this->errors = $mouvS->errors;
$error++; break;
$error++;
break;
}
}
}
@@ -2016,8 +2067,8 @@ class Reception extends CommonObject
if ($this->model_pdf) {
$modele = $this->model_pdf;
} elseif (!empty($conf->global->RECEPTION_ADDON_PDF)) {
$modele = $conf->global->RECEPTION_ADDON_PDF;
} elseif (getDolGlobalString('RECEPTION_ADDON_PDF')) {
$modele = getDolGlobalString('RECEPTION_ADDON_PDF');
}
}