--- /tmp/dsg/dolibarr/htdocs/reception/class/github_reception.class.php +++ /tmp/dsg/dolibarr/htdocs/reception/class/client_reception.class.php @@ -7,7 +7,7 @@ * Copyright (C) 2013 Florian Henry * Copyright (C) 2014 Cedric GROSS * Copyright (C) 2014-2015 Marcos GarcĂ­a - * Copyright (C) 2014-2020 Francis Appels + * Copyright (C) 2014-2015 Francis Appels * Copyright (C) 2015 Claudio Aschieri * Copyright (C) 2016 Ferran Marcet * Copyright (C) 2018 Quentin Vial-Gouteyron @@ -34,7 +34,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; require_once DOL_DOCUMENT_ROOT."/core/class/commonobjectline.class.php"; -require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php'; if (!empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; if (!empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; @@ -44,16 +43,7 @@ */ class Reception extends CommonObject { - use CommonIncoterm; - - /** - * @var string element name - */ public $element = "reception"; - - /** - * @var string Fieldname with ID of parent key if this field has a parent - */ public $fk_element = "fk_reception"; public $table_element = "reception"; public $table_element_line = "commande_fournisseur_dispatch"; @@ -64,34 +54,35 @@ */ public $picto = 'dollyrevert'; - public $socid; - public $ref_supplier; - - /** - * @var int Ref int - * @deprecated - */ - public $ref_int; - - public $brouillon; - public $entrepot_id; - public $tracking_number; - public $tracking_url; - public $billed; - public $model_pdf; - - public $trueWeight; - public $weight_units; - public $trueWidth; - public $width_units; - public $trueHeight; - public $height_units; - public $trueDepth; - public $depth_units; + public $socid; + public $ref_supplier; + + /** + * @var int Ref int + * @deprecated + */ + public $ref_int; + + public $brouillon; + public $entrepot_id; + public $lines = array(); + public $tracking_number; + public $tracking_url; + public $billed; + public $model_pdf; + + public $trueWeight; + public $weight_units; + public $trueWidth; + public $width_units; + public $trueHeight; + public $height_units; + public $trueDepth; + public $depth_units; // A denormalized value - public $trueSize; - - public $date_delivery; // Date delivery planed + public $trueSize; + + public $date_delivery; // Date delivery planed /** @@ -109,10 +100,8 @@ */ public $date_valid; - public $meths; - public $listmeths; // List of carriers - - public $lines = array(); + public $meths; + public $listmeths; // List of carriers const STATUS_DRAFT = 0; @@ -126,9 +115,11 @@ * * @param DoliDB $db Database handler */ - public function __construct($db) + public function __construct($db) { $this->db = $db; + $this->lines = array(); + $this->products = array(); // List of long language codes for status $this->statuts = array(); @@ -151,33 +142,33 @@ * @param Societe $soc Thirdparty object * @return string Free reference for contract */ - public function getNextNumRef($soc) + public function getNextNumRef($soc) { global $langs, $conf; $langs->load("receptions"); - if (!empty($conf->global->RECEPTION_ADDON_NUMBER)) - { + if (!empty($conf->global->RECEPTION_ADDON_NUMBER)) + { $mybool = false; $file = $conf->global->RECEPTION_ADDON_NUMBER.".php"; $classname = $conf->global->RECEPTION_ADDON_NUMBER; - // Include file with class - $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); - - foreach ($dirmodels as $reldir) { - $dir = dol_buildpath($reldir."core/modules/reception/"); - - // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; - } - - if (!$mybool) - { - dol_print_error('', "Failed to include file ".$file); - return ''; - } + // Include file with class + $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); + + foreach ($dirmodels as $reldir) { + $dir = dol_buildpath($reldir."core/modules/reception/"); + + // Load file with numbering class (if found) + $mybool |= @include_once $dir.$file; + } + + if (!$mybool) + { + dol_print_error('', "Failed to include file ".$file); + return ''; + } $obj = new $classname(); @@ -187,14 +178,18 @@ if ($numref != "") { return $numref; - } else { + } + else + { dol_print_error($this->db, get_class($this)."::getNextNumRef ".$obj->error); return ""; } - } else { - print $langs->trans("Error")." ".$langs->trans("Error_RECEPTION_ADDON_NUMBER_NotDefined"); - return ""; - } + } + else + { + print $langs->trans("Error")." ".$langs->trans("Error_RECEPTION_ADDON_NUMBER_NotDefined"); + return ""; + } } /** @@ -204,7 +199,7 @@ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 si erreur, id reception creee si ok */ - public function create($user, $notrigger = 0) + public function create($user, $notrigger = 0) { global $conf, $hookmanager; @@ -229,6 +224,7 @@ $sql .= "ref"; $sql .= ", entity"; $sql .= ", ref_supplier"; + $sql .= ", ref_int"; $sql .= ", date_creation"; $sql .= ", fk_user_author"; $sql .= ", date_reception"; @@ -251,6 +247,7 @@ $sql .= "'(PROV)'"; $sql .= ", ".$conf->entity; $sql .= ", ".($this->ref_supplier ? "'".$this->db->escape($this->ref_supplier)."'" : "null"); + $sql .= ", ".($this->ref_int ? "'".$this->db->escape($this->ref_int)."'" : "null"); $sql .= ", '".$this->db->idate($now)."'"; $sql .= ", ".$user->id; $sql .= ", ".($this->date_reception > 0 ? "'".$this->db->idate($this->date_reception)."'" : "null"); @@ -268,8 +265,8 @@ $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"); - $sql .= ", ".(int) $this->fk_incoterms; - $sql .= ", '".$this->db->escape($this->location_incoterms)."'"; + $sql .= ", ".(int) $this->fk_incoterms; + $sql .= ", '".$this->db->escape($this->location_incoterms)."'"; $sql .= ")"; dol_syslog(get_class($this)."::create", LOG_DEBUG); @@ -317,17 +314,19 @@ if (!$error && !$notrigger) { - // Call trigger - $result = $this->call_trigger('RECEPTION_CREATE', $user); - if ($result < 0) { $error++; } - // End call triggers + // Call trigger + $result = $this->call_trigger('RECEPTION_CREATE', $user); + if ($result < 0) { $error++; } + // End call triggers } if (!$error) { $this->db->commit(); return $this->id; - } else { + } + else + { foreach ($this->errors as $errmsg) { dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); @@ -336,13 +335,17 @@ $this->db->rollback(); return -1 * $error; } - } else { + } + else + { $error++; $this->error = $this->db->lasterror()." - sql=$sql"; $this->db->rollback(); return -2; } - } else { + } + else + { $error++; $this->error = $this->db->error()." - sql=$sql"; $this->db->rollback(); @@ -358,32 +361,32 @@ * @param int $id Id of object to load * @param string $ref Ref of object * @param string $ref_ext External reference of object - * @param string $notused Internal reference of other object + * @param string $notused Internal reference of other object * @return int >0 if OK, 0 if not found, <0 if KO */ - public function fetch($id, $ref = '', $ref_ext = '', $notused = '') + public function fetch($id, $ref = '', $ref_ext = '', $notused = '') { global $conf; // Check parameters if (empty($id) && empty($ref) && empty($ref_ext)) return -1; - $sql = "SELECT e.rowid, e.ref, e.fk_soc as socid, e.date_creation, e.ref_supplier, e.ref_ext, e.fk_user_author, e.fk_statut"; + $sql = "SELECT e.rowid, e.ref, e.fk_soc as socid, e.date_creation, e.ref_supplier, e.ref_ext, e.ref_int, e.fk_user_author, e.fk_statut"; $sql .= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height"; $sql .= ", e.date_reception as date_reception, e.model_pdf, e.date_delivery"; $sql .= ", e.fk_shipping_method, e.tracking_number"; $sql .= ", el.fk_source as origin_id, el.sourcetype as origin"; $sql .= ", e.note_private, e.note_public"; - $sql .= ', e.fk_incoterms, e.location_incoterms'; - $sql .= ', i.libelle as label_incoterms'; + $sql .= ', e.fk_incoterms, e.location_incoterms'; + $sql .= ', i.libelle as label_incoterms'; $sql .= " FROM ".MAIN_DB_PREFIX."reception as e"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element)."'"; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON e.fk_incoterms = i.rowid'; $sql .= " WHERE e.entity IN (".getEntity('reception').")"; if ($id) $sql .= " AND e.rowid=".$id; - if ($ref) $sql .= " AND e.ref='".$this->db->escape($ref)."'"; - if ($ref_ext) $sql .= " AND e.ref_ext='".$this->db->escape($ref_ext)."'"; - if ($notused) $sql .= " AND e.ref_int='".$this->db->escape($notused)."'"; + if ($ref) $sql .= " AND e.ref='".$this->db->escape($ref)."'"; + if ($ref_ext) $sql .= " AND e.ref_ext='".$this->db->escape($ref_ext)."'"; + if ($notused) $sql .= " AND e.ref_int='".$this->db->escape($notused)."'"; dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $result = $this->db->query($sql); @@ -397,7 +400,8 @@ $this->ref = $obj->ref; $this->socid = $obj->socid; $this->ref_supplier = $obj->ref_supplier; - $this->ref_ext = $obj->ref_ext; + $this->ref_ext = $obj->ref_ext; + $this->ref_int = $obj->ref_int; $this->statut = $obj->fk_statut; $this->user_author_id = $obj->fk_user_author; $this->date_creation = $this->db->jdate($obj->date_creation); @@ -405,8 +409,8 @@ $this->date_reception = $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->model_pdf = $obj->model_pdf; - $this->modelpdf = $obj->model_pdf; // deprecated + $this->fk_delivery_address = $obj->fk_address; + $this->modelpdf = $obj->model_pdf; $this->shipping_method_id = $obj->fk_shipping_method; $this->tracking_number = $obj->tracking_number; $this->origin = ($obj->origin ? $obj->origin : 'commande'); // For compatibility @@ -468,12 +472,16 @@ } return 1; - } else { + } + else + { dol_syslog(get_class($this).'::Fetch no reception found', LOG_ERR); $this->error = 'Delivery with id '.$id.' not found'; return 0; } - } else { + } + else + { $this->error = $this->db->error(); return -1; } @@ -483,14 +491,14 @@ * Validate object and update stock if option enabled * * @param User $user Object user that validate - * @param int $notrigger 1=Does not execute triggers, 0= execute triggers + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if OK, >0 if KO */ - public function valid($user, $notrigger = 0) + public function valid($user, $notrigger = 0) { global $conf, $langs; - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; dol_syslog(get_class($this)."::valid"); @@ -501,8 +509,8 @@ return 0; } - if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer)) - || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) + if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer)) + || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) { $this->error = 'Permission denied'; dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR); @@ -522,11 +530,12 @@ if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life { $numref = $this->getNextNumRef($soc); - } else { + } + else { $numref = $this->ref; } - $this->newref = dol_sanitizeFileName($numref); + $this->newref = dol_sanitizeFileName($numref); $now = dol_now(); @@ -592,11 +601,13 @@ $this->errors = array_merge($this->errors, $mouvS->errors); break; } - } else { + } + else + { // line with batch detail // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record. - // Note: ->fk_origin_stock = id into table llx_product_batch (may be rename into llx_product_stock_batch in another version) + // Note: ->fk_origin_stock = id into table llx_product_batch (may be rename into llx_product_stock_batch in another version) $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionValidatedInDolibarr", $numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch); if ($result < 0) { $error++; @@ -606,7 +617,9 @@ } } } - } else { + } + else + { $this->db->rollback(); $this->error = $this->db->error(); return -2; @@ -616,22 +629,22 @@ // Change status of order to "reception in process" $ret = $this->setStatut(4, $this->origin_id, 'commande_fournisseur'); - if (!$ret) - { - $error++; + if (!$ret) + { + $error++; } if (!$error && !$notrigger) { - // Call trigger - $result = $this->call_trigger('RECEPTION_VALIDATE', $user); - if ($result < 0) { $error++; } - // End call triggers + // Call trigger + $result = $this->call_trigger('RECEPTION_VALIDATE', $user); + if ($result < 0) { $error++; } + // End call triggers } if (!$error) { - $this->oldref = $this->ref; + $this->oldref = $this->ref; // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) @@ -653,17 +666,17 @@ if (@rename($dirsource, $dirdest)) { - dol_syslog("Rename ok"); - // Rename docs starting with $oldref with $newref - $listoffiles = dol_dir_list($conf->reception->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); - foreach ($listoffiles as $fileentry) - { - $dirsource = $fileentry['name']; - $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); - $dirsource = $fileentry['path'].'/'.$dirsource; - $dirdest = $fileentry['path'].'/'.$dirdest; - @rename($dirsource, $dirdest); - } + dol_syslog("Rename ok"); + // Rename docs starting with $oldref with $newref + $listoffiles = dol_dir_list($conf->reception->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); + foreach ($listoffiles as $fileentry) + { + $dirsource = $fileentry['name']; + $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); + $dirsource = $fileentry['path'].'/'.$dirsource; + $dirdest = $fileentry['path'].'/'.$dirdest; + @rename($dirsource, $dirdest); + } } } } @@ -680,11 +693,13 @@ { $this->db->commit(); return 1; - } else { + } + else + { foreach ($this->errors as $errmsg) { - dol_syslog(get_class($this)."::valid ".$errmsg, LOG_ERR); - $this->error .= ($this->error ? ', '.$errmsg : $errmsg); + dol_syslog(get_class($this)."::valid ".$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } $this->db->rollback(); return -1 * $error; @@ -706,9 +721,9 @@ * @param integer $eatby eat-by date * @param integer $sellby sell-by date * @param string $batch Lot number - * @return int <0 if KO, index of line if OK - */ - public function addline($entrepot_id, $id, $qty, $array_options = 0, $comment = '', $eatby = '', $sellby = '', $batch = '') + * @return int <0 if KO, >0 if OK + */ + public function addline($entrepot_id, $id, $qty, $array_options = 0, $comment = '', $eatby = '', $sellby = '', $batch = '') { global $conf, $langs, $user; @@ -728,7 +743,7 @@ if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS)) { - $langs->load("errors"); + $langs->load("errors"); $this->error = $langs->trans("ErrorWarehouseRequiredIntoReceptionLine"); return -1; } @@ -754,21 +769,19 @@ $line->fk_reception = $this->id; $this->lines[$num] = $line; - - return $num; } - /** - * Update database - * - * @param User $user User that modify - * @param int $notrigger 0=launch triggers after, 1=disable triggers - * @return int <0 if KO, >0 if OK - */ - public function update($user = null, $notrigger = 0) - { - global $conf; + /** + * Update database + * + * @param User $user User that modify + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK + */ + public function update($user = null, $notrigger = 0) + { + global $conf; $error = 0; // Clean parameters @@ -779,6 +792,7 @@ if (isset($this->socid)) $this->socid = trim($this->socid); if (isset($this->fk_user_author)) $this->fk_user_author = trim($this->fk_user_author); if (isset($this->fk_user_valid)) $this->fk_user_valid = trim($this->fk_user_valid); + if (isset($this->fk_delivery_address)) $this->fk_delivery_address = trim($this->fk_delivery_address); if (isset($this->shipping_method_id)) $this->shipping_method_id = trim($this->shipping_method_id); if (isset($this->tracking_number)) $this->tracking_number = trim($this->tracking_number); if (isset($this->statut)) $this->statut = (int) $this->statut; @@ -788,17 +802,18 @@ if (isset($this->size_units)) $this->size_units = trim($this->size_units); if (isset($this->weight_units)) $this->weight_units = trim($this->weight_units); if (isset($this->trueWeight)) $this->weight = trim($this->trueWeight); - if (isset($this->note_private)) $this->note_private = trim($this->note_private); - if (isset($this->note_public)) $this->note_public = trim($this->note_public); - if (isset($this->model_pdf)) $this->model_pdf = trim($this->model_pdf); + if (isset($this->note_private)) $this->note = trim($this->note_private); + if (isset($this->note_public)) $this->note = trim($this->note_public); + if (isset($this->modelpdf)) $this->modelpdf = trim($this->modelpdf); // Check parameters // Put here code to add control on parameters values - // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."reception SET"; - + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX."reception SET"; + + $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; $sql .= " ref=".(isset($this->ref) ? "'".$this->db->escape($this->ref)."'" : "null").","; $sql .= " ref_supplier=".(isset($this->ref_supplier) ? "'".$this->db->escape($this->ref_supplier)."'" : "null").","; $sql .= " fk_soc=".(isset($this->socid) ? $this->socid : "null").","; @@ -822,36 +837,38 @@ $sql .= " model_pdf=".(isset($this->modelpdf) ? "'".$this->db->escape($this->modelpdf)."'" : "null").","; $sql .= " entity=".$conf->entity; - $sql .= " WHERE rowid=".$this->id; + $sql .= " WHERE rowid=".$this->id; $this->db->begin(); dol_syslog(get_class($this)."::update", LOG_DEBUG); - $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + $resql = $this->db->query($sql); + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } if (!$error) { if (!$notrigger) { - // Call trigger - $result = $this->call_trigger('RECEPTION_MODIFY', $user); - if ($result < 0) { $error++; } - // End call triggers - } - } - - // Commit or rollback + // Call trigger + $result = $this->call_trigger('RECEPTION_MODIFY', $user); + if ($result < 0) { $error++; } + // End call triggers + } + } + + // Commit or rollback if ($error) { foreach ($this->errors as $errmsg) { - dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); - $this->error .= ($this->error ? ', '.$errmsg : $errmsg); + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } $this->db->rollback(); return -1 * $error; - } else { + } + else + { $this->db->commit(); return 1; } @@ -863,7 +880,7 @@ * @param User $user Object user * @return int >0 if OK, 0 if deletion done but failed to delete files, <0 if KO */ - public function delete(User $user) + public function delete(User $user) { global $conf, $langs, $user; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -904,16 +921,18 @@ $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 { + } + else + { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } } if (!$error) { - $main = MAIN_DB_PREFIX.'commande_fournisseur_dispatch'; - $ef = $main."_extrafields"; - $sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_reception = ".$this->id.")"; + $main = MAIN_DB_PREFIX.'commande_fournisseur_dispatch'; + $ef = $main."_extrafields"; + $sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_reception = ".$this->id.")"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch"; $sql .= " WHERE fk_reception = ".$this->id; @@ -938,18 +957,18 @@ if (!empty($this->origin) && $this->origin_id > 0) { - $this->fetch_origin(); - $origin = $this->origin; - if ($this->$origin->statut == 4) // If order source of reception is "partially received" - { - // Check if there is no more reception. If not, we can move back status of order to "validated" instead of "reception in progress" - $this->$origin->loadReceptions(); - //var_dump($this->$origin->receptions);exit; - if (count($this->$origin->receptions) <= 0) - { - $this->$origin->setStatut(3); // ordered - } - } + $this->fetch_origin(); + $origin = $this->origin; + if ($this->$origin->statut == 4) // If order source of reception is "partially received" + { + // Check if there is no more reception. If not, we can move back status of order to "validated" instead of "reception in progress" + $this->$origin->loadReceptions(); + //var_dump($this->$origin->receptions);exit; + if (count($this->$origin->receptions) <= 0) + { + $this->$origin->setStatut(3); // ordered + } + } } if (!$error) @@ -980,54 +999,65 @@ } return 1; - } else { + } + else + { $this->db->rollback(); return -1; } - } else { + } + else + { $this->error = $this->db->lasterror()." - sql=$sql"; $this->db->rollback(); return -3; } - } else { + } + else + { $this->error = $this->db->lasterror()." - sql=$sql"; $this->db->rollback(); return -2; } - } else { + } + else + { $this->error = $this->db->lasterror()." - sql=$sql"; $this->db->rollback(); return -1; } - } else { + } + else + { $this->db->rollback(); return -1; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Load lines * * @return int >0 if OK, Otherwise if KO */ - public function fetch_lines() + public function fetch_lines() { // phpcs:enable + global $db; dol_include_once('/fourn/class/fournisseur.commande.dispatch.class.php'); $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'commande_fournisseur_dispatch WHERE fk_reception='.$this->id; - $resql = $this->db->query($sql); + $resql = $db->query($sql); if (!empty($resql)) { $this->lines = array(); - while ($obj = $this->db->fetch_object($resql)) { - $line = new CommandeFournisseurDispatch($this->db); + while ($obj = $resql->fetch_object()) { + $line = new CommandeFournisseurDispatch($db); $line->fetch($obj->rowid); $line->fetch_product(); $sql_commfourndet = 'SELECT qty, ref, label, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent FROM llx_commande_fournisseurdet WHERE rowid='.$line->fk_commandefourndet; - $resql_commfourndet = $this->db->query($sql_commfourndet); + $resql_commfourndet = $db->query($sql_commfourndet); if (!empty($resql_commfourndet)) { - $obj = $this->db->fetch_object($resql_commfourndet); + $obj = $db->fetch_object($resql_commfourndet); $line->qty_asked = $obj->qty; $line->description = $line->comment; $line->desc = $line->comment; @@ -1056,28 +1086,29 @@ } return 1; - } else { + } + else { return -1; } } /** - * Return clicable link of object (with eventually picto) - * - * @param int $withpicto Add picto into link - * @param int $option Where point the link - * @param int $max Max length to show - * @param int $short Use short labels - * @param int $notooltip 1=No tooltip - * @return string String with URL - */ - public function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0) + * Return clicable link of object (with eventually picto) + * + * @param int $withpicto Add picto into link + * @param int $option Where point the link + * @param int $max Max length to show + * @param int $short Use short labels + * @param int $notooltip 1=No tooltip + * @return string String with URL + */ + public function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0) { global $conf, $langs; $result = ''; - $label = img_picto('', $this->picto).' '.$langs->trans("Reception").''; - $label .= '
'.$langs->trans('Ref').': '.$this->ref; - $label .= '
'.$langs->trans('RefSupplier').': '.($this->ref_supplier ? $this->ref_supplier : $this->ref_client); + $label = ''.$langs->trans("Reception").''; + $label .= '
'.$langs->trans('Ref').': '.$this->ref; + $label .= '
'.$langs->trans('RefSupplier').': '.($this->ref_supplier ? $this->ref_supplier : $this->ref_client); $url = DOL_URL_ROOT.'/reception/card.php?id='.$this->id; @@ -1086,17 +1117,17 @@ $linkclose = ''; if (empty($notooltip)) { - if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { - $label = $langs->trans("Reception"); - $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; - } - $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose .= ' class="classfortooltip"'; - } - - $linkstart = ''; + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { + $label = $langs->trans("Reception"); + $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; + } + $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose .= ' class="classfortooltip"'; + } + + $linkstart = ''; $linkend = ''; if ($withpicto) $result .= ($linkstart.img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? '' : 'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).$linkend); @@ -1106,15 +1137,15 @@ } /** - * Return status label - * - * @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 Libelle - */ - public function getLibStatut($mode = 0) - { - return $this->LibStatut($this->statut, $mode); - } + * Return status label + * + * @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 Libelle + */ + public function getLibStatut($mode = 0) + { + return $this->LibStatut($this->statut, $mode); + } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** @@ -1124,30 +1155,30 @@ * @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) - { - // phpcs:enable - global $langs; - - $labelStatus = $langs->trans($this->statuts[$status]); - $labelStatusShort = $langs->trans($this->statutshorts[$status]); - - $statusType = 'status'.$status; - if ($status == self::STATUS_VALIDATED) $statusType = 'status4'; - if ($status == self::STATUS_CLOSED) $statusType = 'status6'; - - return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode); + public function LibStatut($status, $mode) + { + // phpcs:enable + global $langs; + + $labelStatus = $langs->trans($this->statuts[$status]); + $labelStatusShort = $langs->trans($this->statutshorts[$status]); + + $statusType = 'status'.$status; + if ($status == self::STATUS_VALIDATED) $statusType = 'status4'; + if ($status == self::STATUS_CLOSED) $statusType = 'status6'; + + return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode); } /** - * Initialise an instance with random values. - * Used to build previews or test instances. - * id must be 0 if object instance is a specimen. - * - * @return void - */ - public function initAsSpecimen() - { + * Initialise an instance with random values. + * Used to build previews or test instances. + * id must be 0 if object instance is a specimen. + * + * @return void + */ + public function initAsSpecimen() + { global $langs; include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; @@ -1156,14 +1187,12 @@ dol_syslog(get_class($this)."::initAsSpecimen"); - // Load array of products prodids + // Load array of products prodids $num_prods = 0; $prodids = array(); $sql = "SELECT rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."product"; $sql .= " WHERE entity IN (".getEntity('product').")"; - $sql .= $this->db->plimit(100); - $resql = $this->db->query($sql); if ($resql) { @@ -1193,16 +1222,17 @@ $this->date_reception = $now + 24 * 3600; $this->entrepot_id = 0; + $this->fk_delivery_address = 0; $this->socid = 1; $this->commande_id = 0; $this->commande = $order; - $this->origin_id = 1; - $this->origin = 'commande'; - - $this->note_private = 'Private note'; - $this->note_public = 'Public note'; + $this->origin_id = 1; + $this->origin = 'commande'; + + $this->note_private = 'Private note'; + $this->note_public = 'Public note'; $nbp = 5; $xnbp = 0; @@ -1220,44 +1250,49 @@ } } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set the planned delivery date * * @param User $user Objet utilisateur qui modifie - * @param integer $delivery_date Delivery date + * @param integer $date_livraison Date de livraison * @return int <0 if KO, >0 if OK */ - public function setDeliveryDate($user, $delivery_date) + public function set_date_livraison($user, $date_livraison) { // phpcs:enable if ($user->rights->reception->creer) { $sql = "UPDATE ".MAIN_DB_PREFIX."reception"; - $sql .= " SET date_delivery = ".($delivery_date ? "'".$this->db->idate($delivery_date)."'" : 'null'); + $sql .= " SET date_delivery = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null'); $sql .= " WHERE rowid = ".$this->id; - dol_syslog(get_class($this)."::setDeliveryDate", LOG_DEBUG); + dol_syslog(get_class($this)."::set_date_livraison", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - $this->date_delivery = $delivery_date; + $this->date_delivery = $date_livraison; return 1; - } else { + } + else + { $this->error = $this->db->error(); return -1; } - } else { + } + else + { return -2; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Fetch deliveries method and return an array. Load array this->meths(rowid=>label). * * @return void */ - public function fetch_delivery_methods() + public function fetch_delivery_methods() { // phpcs:enable global $langs; @@ -1279,101 +1314,103 @@ } } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Fetch all deliveries method and return an array. Load array this->listmeths. + * + * @param int $id only this carrier, all if none + * @return void + */ + public function list_delivery_methods($id = '') + { + // phpcs:enable + global $langs; + + $this->listmeths = array(); + $i = 0; + + $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 != '') $sql .= " WHERE em.rowid=".$id; + + $resql = $this->db->query($sql); + if ($resql) { + while ($obj = $this->db->fetch_object($resql)) { + $this->listmeths[$i]['rowid'] = $obj->rowid; + $this->listmeths[$i]['code'] = $obj->code; + $label = $langs->trans('ReceptionMethod'.$obj->code); + $this->listmeths[$i]['libelle'] = ($label != 'ReceptionMethod'.$obj->code ? $label : $obj->libelle); + $this->listmeths[$i]['description'] = $obj->description; + $this->listmeths[$i]['tracking'] = $obj->tracking; + $this->listmeths[$i]['active'] = $obj->active; + $i++; + } + } + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Update/create delivery method. + * + * @param string $id id method to activate + * + * @return void + */ + public function update_delivery_method($id = '') + { + // phpcs:enable + if ($id == '') + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_shipment_mode (code, libelle, description, tracking)"; + $sql .= " VALUES ('".$this->db->escape($this->update['code'])."','".$this->db->escape($this->update['libelle'])."','".$this->db->escape($this->update['description'])."','".$this->db->escape($this->update['tracking'])."')"; + $resql = $this->db->query($sql); + } + else + { + $sql = "UPDATE ".MAIN_DB_PREFIX."c_shipment_mode SET"; + $sql .= " code='".$this->db->escape($this->update['code'])."'"; + $sql .= ",libelle='".$this->db->escape($this->update['libelle'])."'"; + $sql .= ",description='".$this->db->escape($this->update['description'])."'"; + $sql .= ",tracking='".$this->db->escape($this->update['tracking'])."'"; + $sql .= " WHERE rowid=".$id; + $resql = $this->db->query($sql); + } + if ($resql < 0) dol_print_error($this->db, ''); + } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Fetch all deliveries method and return an array. Load array this->listmeths. - * - * @param int $id only this carrier, all if none - * @return void - */ - public function list_delivery_methods($id = '') - { + /** + * Activate delivery method. + * + * @param int $id id method to activate + * + * @return void + */ + public function activ_delivery_method($id) + { // phpcs:enable - global $langs; - - $this->listmeths = array(); - $i = 0; - - $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 != '') $sql .= " WHERE em.rowid=".$id; - - $resql = $this->db->query($sql); - if ($resql) { - while ($obj = $this->db->fetch_object($resql)) { - $this->listmeths[$i]['rowid'] = $obj->rowid; - $this->listmeths[$i]['code'] = $obj->code; - $label = $langs->trans('ReceptionMethod'.$obj->code); - $this->listmeths[$i]['libelle'] = ($label != 'ReceptionMethod'.$obj->code ? $label : $obj->libelle); - $this->listmeths[$i]['description'] = $obj->description; - $this->listmeths[$i]['tracking'] = $obj->tracking; - $this->listmeths[$i]['active'] = $obj->active; - $i++; - } - } - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Update/create delivery method. - * - * @param string $id id method to activate - * - * @return void - */ - public function update_delivery_method($id = '') - { + $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=1'; + $sql .= ' WHERE rowid='.$id; + + $resql = $this->db->query($sql); + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * DesActivate delivery method. + * + * @param int $id id method to desactivate + * + * @return void + */ + public function disable_delivery_method($id) + { // phpcs:enable - if ($id == '') - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_shipment_mode (code, libelle, description, tracking)"; - $sql .= " VALUES ('".$this->db->escape($this->update['code'])."','".$this->db->escape($this->update['libelle'])."','".$this->db->escape($this->update['description'])."','".$this->db->escape($this->update['tracking'])."')"; - $resql = $this->db->query($sql); - } else { - $sql = "UPDATE ".MAIN_DB_PREFIX."c_shipment_mode SET"; - $sql .= " code='".$this->db->escape($this->update['code'])."'"; - $sql .= ",libelle='".$this->db->escape($this->update['libelle'])."'"; - $sql .= ",description='".$this->db->escape($this->update['description'])."'"; - $sql .= ",tracking='".$this->db->escape($this->update['tracking'])."'"; - $sql .= " WHERE rowid=".$id; - $resql = $this->db->query($sql); - } - if ($resql < 0) dol_print_error($this->db, ''); - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Activate delivery method. - * - * @param int $id id method to activate - * - * @return void - */ - public function activ_delivery_method($id) - { - // phpcs:enable - $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=1'; - $sql .= ' WHERE rowid='.$id; - - $resql = $this->db->query($sql); - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * DesActivate delivery method. - * - * @param int $id id method to desactivate - * - * @return void - */ - public function disable_delivery_method($id) - { - // phpcs:enable - $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=0'; - $sql .= ' WHERE rowid='.$id; - - $resql = $this->db->query($sql); - } + $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=0'; + $sql .= ' WHERE rowid='.$id; + + $resql = $this->db->query($sql); + } /** @@ -1382,7 +1419,7 @@ * @param string $value Value * @return void */ - public function getUrlTrackingStatus($value = '') + public function getUrlTrackingStatus($value = '') { if (!empty($this->shipping_method_id)) { @@ -1404,7 +1441,9 @@ { $url = str_replace('{TRACKID}', $value, $tracking); $this->tracking_url = sprintf(''.($value ? $value : 'url').'', $url, $url); - } else { + } + else + { $this->tracking_url = $value; } } @@ -1414,7 +1453,7 @@ * * @return int <0 if KO, >0 if OK */ - public function setClosed() + public function setClosed() { global $conf, $langs, $user; @@ -1501,24 +1540,28 @@ // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionClassifyClosedInDolibarr", $numref)); if ($result < 0) { - $this->error = $mouvS->error; - $this->errors = $mouvS->errors; - $error++; break; - } - } else { - // line with batch detail - - // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record - $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionClassifyClosedInDolibarr", $numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch); - - if ($result < 0) { - $this->error = $mouvS->error; - $this->errors = $mouvS->errors; + $this->error = $mouvS->error; + $this->errors = $mouvS->errors; $error++; break; } } + else + { + // line with batch detail + + // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record + $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionClassifyClosedInDolibarr", $numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch); + + if ($result < 0) { + $this->error = $mouvS->error; + $this->errors = $mouvS->errors; + $error++; break; + } + } } - } else { + } + else + { $this->error = $this->db->lasterror(); $error++; } @@ -1527,36 +1570,40 @@ // Call trigger if (!$error) { - $result = $this->call_trigger('RECEPTION_CLOSED', $user); - if ($result < 0) { - $error++; - } - } - } else { + $result = $this->call_trigger('RECEPTION_CLOSED', $user); + if ($result < 0) { + $error++; + } + } + } + else + { dol_print_error($this->db); - $error++; + $error++; } if (!$error) { - $this->db->commit(); - return 1; - } else { - $this->db->rollback(); - return -1; + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Classify the reception as invoiced (used when WORKFLOW_BILL_ON_RECEPTION is on) * * @return int <0 if ko, >0 if ok */ - public function set_billed() + public function set_billed() { // phpcs:enable - global $user; + global $user; $error = 0; $this->db->begin(); @@ -1585,7 +1632,9 @@ if (empty($error)) { $this->db->commit(); return 1; - } else { + } + else + { $this->db->rollback(); return -1; } @@ -1596,7 +1645,7 @@ * * @return int <0 if ko, >0 if ok */ - public function reOpen() + public function reOpen() { global $conf, $langs, $user; @@ -1656,23 +1705,27 @@ // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionUnClassifyCloseddInDolibarr", $numref)); if ($result < 0) { - $this->error = $mouvS->error; - $this->errors = $mouvS->errors; + $this->error = $mouvS->error; + $this->errors = $mouvS->errors; $error++; break; } - } else { + } + else + { // line with batch detail // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionUnClassifyCloseddInDolibarr", $numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock); if ($result < 0) { - $this->error = $mouvS->error; - $this->errors = $mouvS->errors; - $error++; break; + $this->error = $mouvS->error; + $this->errors = $mouvS->errors; + $error++; break; } } } - } else { + } + else + { $this->error = $this->db->lasterror(); $error++; } @@ -1680,11 +1733,11 @@ if (!$error) { - // Call trigger - $result = $this->call_trigger('RECEPTION_REOPEN', $user); - if ($result < 0) { - $error++; - } + // Call trigger + $result = $this->call_trigger('RECEPTION_REOPEN', $user); + if ($result < 0) { + $error++; + } } if ($this->origin == 'order_supplier') { @@ -1701,48 +1754,50 @@ { $this->db->commit(); return 1; - } else { + } + else + { $this->db->rollback(); return -1; } } /** - * Set draft status - * - * @param User $user Object user that modify - * @return int <0 if KO, >0 if OK - */ - public function setDraft($user) - { + * Set draft status + * + * @param User $user Object user that modify + * @return int <0 if KO, >0 if OK + */ + public function setDraft($user) + { // phpcs:enable - global $conf, $langs; - - $error = 0; - - // Protection - if ($this->statut <= self::STATUS_DRAFT) - { - return 0; - } - - if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer)) - || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) - { - $this->error = 'Permission denied'; - return -1; - } - - $this->db->begin(); - - $sql = "UPDATE ".MAIN_DB_PREFIX."reception"; - $sql .= " SET fk_statut = ".self::STATUS_DRAFT; - $sql .= " WHERE rowid = ".$this->id; - - dol_syslog(__METHOD__, LOG_DEBUG); - if ($this->db->query($sql)) - { - // If stock increment is done on closing + global $conf, $langs; + + $error = 0; + + // Protection + if ($this->statut <= self::STATUS_DRAFT) + { + return 0; + } + + if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer)) + || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) + { + $this->error = 'Permission denied'; + return -1; + } + + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."reception"; + $sql .= " SET fk_statut = ".self::STATUS_DRAFT; + $sql .= " WHERE rowid = ".$this->id; + + dol_syslog(__METHOD__, LOG_DEBUG); + if ($this->db->query($sql)) + { + // If stock increment is done on closing if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)) { require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; @@ -1785,34 +1840,38 @@ // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionBackToDraftInDolibarr", $this->ref)); if ($result < 0) { - $this->error = $mouvS->error; - $this->errors = $mouvS->errors; + $this->error = $mouvS->error; + $this->errors = $mouvS->errors; $error++; break; } - } else { + } + else + { // line with batch detail // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionBackToDraftInDolibarr", $this->ref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch); if ($result < 0) { - $this->error = $mouvS->error; - $this->errors = $mouvS->errors; - $error++; break; + $this->error = $mouvS->error; + $this->errors = $mouvS->errors; + $error++; break; } } } - } else { + } + else + { $this->error = $this->db->lasterror(); $error++; } } - if (!$error) { - // Call trigger - $result = $this->call_trigger('RECEPTION_UNVALIDATE', $user); - if ($result < 0) $error++; - } + if (!$error) { + // Call trigger + $result = $this->call_trigger('RECEPTION_UNVALIDATE', $user); + if ($result < 0) $error++; + } if ($this->origin == 'order_supplier') { if (!empty($this->origin) && $this->origin_id > 0) @@ -1844,20 +1903,22 @@ } } - if (!$error) { - $this->statut = self::STATUS_DRAFT; - $this->db->commit(); - return 1; - } else { - $this->db->rollback(); - return -1; - } - } else { - $this->error = $this->db->error(); - $this->db->rollback(); - return -1; - } - } + if (!$error) { + $this->statut = self::STATUS_DRAFT; + $this->db->commit(); + return 1; + } else { + $this->db->rollback(); + return -1; + } + } + else + { + $this->error = $this->db->error(); + $this->db->rollback(); + return -1; + } + } /** * Create a document onto disk according to template module. @@ -1879,8 +1940,8 @@ { $modele = 'squille'; - if ($this->model_pdf) { - $modele = $this->model_pdf; + if ($this->modelpdf) { + $modele = $this->modelpdf; } elseif (!empty($conf->global->RECEPTION_ADDON_PDF)) { $modele = $conf->global->RECEPTION_ADDON_PDF; } --- /tmp/dsg/dolibarr/htdocs/reception/class/github_receptionstats.class.php +++ /tmp/dsg/dolibarr/htdocs/reception/class/client_receptionstats.class.php @@ -34,35 +34,35 @@ */ class ReceptionStats extends Stats { - public $table_element; + public $table_element; - public $socid; - public $userid; + public $socid; + public $userid; - public $from; - public $field; - public $where; + public $from; + public $field; + public $where; - /** - * Constructor - * - * @param DoliDB $db Database handler + /** + * Constructor + * + * @param DoliDB $db Database handler * @param int $socid Id third party for filter * @param string $mode Option (not used) * @param int $userid Id user for filter (creation user) - */ - public function __construct($db, $socid, $mode, $userid = 0) - { + */ + public function __construct($db, $socid, $mode, $userid = 0) + { global $user, $conf; $this->db = $db; $this->socid = ($socid > 0 ? $socid : 0); - $this->userid = $userid; + $this->userid = $userid; $this->cachefilesuffix = $mode; - $object = new Reception($this->db); + $object = new Reception($this->db); $this->from = MAIN_DB_PREFIX.$object->table_element." as c"; //$this->from.= ", ".MAIN_DB_PREFIX."societe as s"; $this->field = 'weight'; // Warning, unit of weight is NOT USED AND MUST BE @@ -75,32 +75,32 @@ { $this->where .= " AND c.fk_soc = ".$this->socid; } - if ($this->userid > 0) $this->where .= ' AND c.fk_user_author = '.$this->userid; - } + if ($this->userid > 0) $this->where .= ' AND c.fk_user_author = '.$this->userid; + } - /** - * Return reception number by month for a year - * + /** + * Return reception number by month for a year + * * @param int $year Year to scan * @return array Array with number by month - */ - public function getNbByMonth($year) - { - global $user; + */ + public function getNbByMonth($year) + { + global $user; - $sql = "SELECT date_format(c.date_valid,'%m') as dm, COUNT(*) as nb"; + $sql = "SELECT date_format(c.date_valid,'%m') as dm, COUNT(*) as nb"; $sql .= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$this->socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - } + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } $sql .= " WHERE c.date_valid BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; - $sql .= $this->db->order('dm', 'DESC'); + $sql .= $this->db->order('dm', 'DESC'); $res = $this->_getNbByMonth($year, $sql); return $res; - } + } /** * Return receptions number per year @@ -108,7 +108,7 @@ * @return array Array with number by year * */ - public function getNbByYear() + public function getNbByYear() { global $user; @@ -117,7 +117,7 @@ if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql .= " WHERE ".$this->where; $sql .= " GROUP BY dm"; - $sql .= $this->db->order('dm', 'DESC'); + $sql .= $this->db->order('dm', 'DESC'); return $this->_getNbByYear($sql); } @@ -127,7 +127,7 @@ * * @return array Array of values */ - public function getAllByYear() + public function getAllByYear() { global $user;