Fix error phpunit
This commit is contained in:
parent
678e23b13a
commit
02f8ac4cbc
@ -166,11 +166,11 @@ class Delivery extends CommonObject
|
|||||||
$sql .= ", fk_incoterms, location_incoterms";
|
$sql .= ", fk_incoterms, location_incoterms";
|
||||||
$sql .= ") VALUES (";
|
$sql .= ") VALUES (";
|
||||||
$sql .= "'(PROV)'";
|
$sql .= "'(PROV)'";
|
||||||
$sql .= ", ".$conf->entity;
|
$sql .= ", ".((int) $conf->entity);
|
||||||
$sql .= ", ".$this->socid;
|
$sql .= ", ".((int) $this->socid);
|
||||||
$sql .= ", '".$this->db->escape($this->ref_customer)."'";
|
$sql .= ", '".$this->db->escape($this->ref_customer)."'";
|
||||||
$sql .= ", '".$this->db->idate($now)."'";
|
$sql .= ", '".$this->db->idate($now)."'";
|
||||||
$sql .= ", ".$user->id;
|
$sql .= ", ".((int) $user->id);
|
||||||
$sql .= ", ".($this->date_delivery ? "'".$this->db->idate($this->date_delivery)."'" : "null");
|
$sql .= ", ".($this->date_delivery ? "'".$this->db->idate($this->date_delivery)."'" : "null");
|
||||||
$sql .= ", ".($this->fk_delivery_address > 0 ? $this->fk_delivery_address : "null");
|
$sql .= ", ".($this->fk_delivery_address > 0 ? $this->fk_delivery_address : "null");
|
||||||
$sql .= ", ".(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null");
|
$sql .= ", ".(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null");
|
||||||
@ -189,7 +189,7 @@ class Delivery extends CommonObject
|
|||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."delivery ";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."delivery ";
|
||||||
$sql .= "SET ref = '".$this->db->escape($numref)."'";
|
$sql .= "SET ref = '".$this->db->escape($numref)."'";
|
||||||
$sql .= " WHERE rowid = ".$this->id;
|
$sql .= " WHERE rowid = ".((int) $this->id);
|
||||||
|
|
||||||
dol_syslog("Delivery::create", LOG_DEBUG);
|
dol_syslog("Delivery::create", LOG_DEBUG);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
@ -262,9 +262,10 @@ class Delivery extends CommonObject
|
|||||||
* @param string $qty Quantity
|
* @param string $qty Quantity
|
||||||
* @param string $fk_product Id of predefined product
|
* @param string $fk_product Id of predefined product
|
||||||
* @param string $description Description
|
* @param string $description Description
|
||||||
|
* @param array $array_options Array options
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
public function create_line($origin_id, $qty, $fk_product, $description, $array_options = 0)
|
public function create_line($origin_id, $qty, $fk_product, $description, $array_options = null)
|
||||||
{
|
{
|
||||||
// phpcs:enable
|
// phpcs:enable
|
||||||
$error = 0;
|
$error = 0;
|
||||||
@ -394,126 +395,126 @@ class Delivery extends CommonObject
|
|||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery->creer))
|
if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery->creer))
|
||||||
|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery_advance->validate))) {
|
|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery_advance->validate))) {
|
||||||
if (!empty($conf->global->DELIVERY_ADDON_NUMBER)) {
|
if (!empty($conf->global->DELIVERY_ADDON_NUMBER)) {
|
||||||
// Setting the command numbering module name
|
// Setting the command numbering module name
|
||||||
$modName = $conf->global->DELIVERY_ADDON_NUMBER;
|
$modName = $conf->global->DELIVERY_ADDON_NUMBER;
|
||||||
|
|
||||||
if (is_readable(DOL_DOCUMENT_ROOT.'/core/modules/delivery/'.$modName.'.php')) {
|
if (is_readable(DOL_DOCUMENT_ROOT.'/core/modules/delivery/'.$modName.'.php')) {
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/modules/delivery/'.$modName.'.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/modules/delivery/'.$modName.'.php';
|
||||||
|
|
||||||
$now = dol_now();
|
$now = dol_now();
|
||||||
|
|
||||||
// Retrieving the new reference
|
// Retrieving the new reference
|
||||||
$objMod = new $modName($this->db);
|
$objMod = new $modName($this->db);
|
||||||
$soc = new Societe($this->db);
|
$soc = new Societe($this->db);
|
||||||
$soc->fetch($this->socid);
|
$soc->fetch($this->socid);
|
||||||
|
|
||||||
if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life
|
if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life
|
||||||
$numref = $objMod->delivery_get_num($soc, $this);
|
$numref = $objMod->delivery_get_num($soc, $this);
|
||||||
} else {
|
} else {
|
||||||
$numref = $this->ref;
|
$numref = $this->ref;
|
||||||
}
|
|
||||||
$this->newref = dol_sanitizeFileName($numref);
|
|
||||||
|
|
||||||
// Test if is not already in valid status. If so, we stop to avoid decrementing the stock twice.
|
|
||||||
$sql = "SELECT ref";
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."delivery";
|
|
||||||
$sql .= " WHERE ref = '".$this->db->escape($numref)."'";
|
|
||||||
$sql .= " AND fk_statut <> 0";
|
|
||||||
$sql .= " AND entity = ".((int) $conf->entity);
|
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
|
||||||
if ($resql) {
|
|
||||||
$num = $this->db->num_rows($resql);
|
|
||||||
if ($num > 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
$this->newref = dol_sanitizeFileName($numref);
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."delivery SET";
|
// Test if is not already in valid status. If so, we stop to avoid decrementing the stock twice.
|
||||||
$sql .= " ref='".$this->db->escape($numref)."'";
|
$sql = "SELECT ref";
|
||||||
$sql .= ", fk_statut = 1";
|
$sql .= " FROM ".MAIN_DB_PREFIX."delivery";
|
||||||
$sql .= ", date_valid = '".$this->db->idate($now)."'";
|
$sql .= " WHERE ref = '".$this->db->escape($numref)."'";
|
||||||
$sql .= ", fk_user_valid = ".$user->id;
|
$sql .= " AND fk_statut <> 0";
|
||||||
$sql .= " WHERE rowid = ".$this->id;
|
$sql .= " AND entity = ".((int) $conf->entity);
|
||||||
$sql .= " AND fk_statut = 0";
|
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if (!$resql) {
|
if ($resql) {
|
||||||
dol_print_error($this->db);
|
$num = $this->db->num_rows($resql);
|
||||||
$this->error = $this->db->lasterror();
|
if ($num > 0) {
|
||||||
$error++;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!$error && !$notrigger) {
|
$sql = "UPDATE ".MAIN_DB_PREFIX."delivery SET";
|
||||||
// Call trigger
|
$sql .= " ref='".$this->db->escape($numref)."'";
|
||||||
$result = $this->call_trigger('DELIVERY_VALIDATE', $user);
|
$sql .= ", fk_statut = 1";
|
||||||
if ($result < 0) {
|
$sql .= ", date_valid = '".$this->db->idate($now)."'";
|
||||||
|
$sql .= ", fk_user_valid = ".$user->id;
|
||||||
|
$sql .= " WHERE rowid = ".((int) $this->id);
|
||||||
|
$sql .= " AND fk_statut = 0";
|
||||||
|
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if (!$resql) {
|
||||||
|
dol_print_error($this->db);
|
||||||
|
$this->error = $this->db->lasterror();
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
// End call triggers
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$error) {
|
if (!$error && !$notrigger) {
|
||||||
$this->oldref = $this->ref;
|
// Call trigger
|
||||||
|
$result = $this->call_trigger('DELIVERY_VALIDATE', $user);
|
||||||
// Rename directory if dir was a temporary ref
|
if ($result < 0) {
|
||||||
if (preg_match('/^[\(]?PROV/i', $this->ref)) {
|
$error++;
|
||||||
// Now we rename also files into index
|
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'expedition/receipt/".$this->db->escape($this->newref)."'";
|
|
||||||
$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'expedition/receipt/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
|
|
||||||
$resql = $this->db->query($sql);
|
|
||||||
if (!$resql) {
|
|
||||||
$error++; $this->error = $this->db->lasterror();
|
|
||||||
}
|
}
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
// We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
|
if (!$error) {
|
||||||
$oldref = dol_sanitizeFileName($this->ref);
|
$this->oldref = $this->ref;
|
||||||
$newref = dol_sanitizeFileName($numref);
|
|
||||||
$dirsource = $conf->expedition->dir_output.'/receipt/'.$oldref;
|
|
||||||
$dirdest = $conf->expedition->dir_output.'/receipt/'.$newref;
|
|
||||||
if (!$error && file_exists($dirsource)) {
|
|
||||||
dol_syslog(get_class($this)."::valid rename dir ".$dirsource." into ".$dirdest);
|
|
||||||
|
|
||||||
if (@rename($dirsource, $dirdest)) {
|
// Rename directory if dir was a temporary ref
|
||||||
dol_syslog("Rename ok");
|
if (preg_match('/^[\(]?PROV/i', $this->ref)) {
|
||||||
// Rename docs starting with $oldref with $newref
|
// Now we rename also files into index
|
||||||
$listoffiles = dol_dir_list($conf->expedition->dir_output.'/receipt/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
|
$sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'expedition/receipt/".$this->db->escape($this->newref)."'";
|
||||||
foreach ($listoffiles as $fileentry) {
|
$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'expedition/receipt/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
|
||||||
$dirsource = $fileentry['name'];
|
$resql = $this->db->query($sql);
|
||||||
$dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
|
if (!$resql) {
|
||||||
$dirsource = $fileentry['path'].'/'.$dirsource;
|
$error++; $this->error = $this->db->lasterror();
|
||||||
$dirdest = $fileentry['path'].'/'.$dirdest;
|
}
|
||||||
@rename($dirsource, $dirdest);
|
|
||||||
|
// We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
|
||||||
|
$oldref = dol_sanitizeFileName($this->ref);
|
||||||
|
$newref = dol_sanitizeFileName($numref);
|
||||||
|
$dirsource = $conf->expedition->dir_output.'/receipt/'.$oldref;
|
||||||
|
$dirdest = $conf->expedition->dir_output.'/receipt/'.$newref;
|
||||||
|
if (!$error && file_exists($dirsource)) {
|
||||||
|
dol_syslog(get_class($this)."::valid rename dir ".$dirsource." into ".$dirdest);
|
||||||
|
|
||||||
|
if (@rename($dirsource, $dirdest)) {
|
||||||
|
dol_syslog("Rename ok");
|
||||||
|
// Rename docs starting with $oldref with $newref
|
||||||
|
$listoffiles = dol_dir_list($conf->expedition->dir_output.'/receipt/'.$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set new ref and current status
|
||||||
|
if (!$error) {
|
||||||
|
$this->ref = $numref;
|
||||||
|
$this->statut = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dol_syslog(get_class($this)."::valid ok");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set new ref and current status
|
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
$this->ref = $numref;
|
$this->db->commit();
|
||||||
$this->statut = 1;
|
return 1;
|
||||||
|
} else {
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::valid ok");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$error) {
|
|
||||||
$this->db->commit();
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
$this->db->rollback();
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$this->error = "Non autorise";
|
||||||
|
dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$this->error = "Non autorise";
|
|
||||||
dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||||
@ -600,15 +601,16 @@ class Delivery extends CommonObject
|
|||||||
/**
|
/**
|
||||||
* Add line
|
* Add line
|
||||||
*
|
*
|
||||||
* @param int $origin_id Origin id
|
* @param int $origin_id Origin id
|
||||||
* @param int $qty Qty
|
* @param int $qty Qty
|
||||||
|
* @param array $array_options Array options
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function addline($origin_id, $qty, $array_options = 0)
|
public function addline($origin_id, $qty, $array_options = null)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$num = count($this->lines);
|
$num = count($this->lines);
|
||||||
$line = new DeliveryLine($this->db);
|
$line = new DeliveryLine($this->db);
|
||||||
|
|
||||||
$line->origin_id = $origin_id;
|
$line->origin_id = $origin_id;
|
||||||
@ -666,7 +668,7 @@ class Delivery extends CommonObject
|
|||||||
|
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."delivery";
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."delivery";
|
||||||
$sql .= " WHERE rowid = ".$this->id;
|
$sql .= " WHERE rowid = ".((int) $this->id);
|
||||||
if ($this->db->query($sql)) {
|
if ($this->db->query($sql)) {
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
|
|
||||||
@ -734,8 +736,8 @@ class Delivery extends CommonObject
|
|||||||
|
|
||||||
//if ($option !== 'nolink')
|
//if ($option !== 'nolink')
|
||||||
//{
|
//{
|
||||||
// Add param to save lastsearch_values or not
|
// Add param to save lastsearch_values or not
|
||||||
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
|
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
|
||||||
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
|
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
|
||||||
$add_save_lastsearch_values = 1;
|
$add_save_lastsearch_values = 1;
|
||||||
}
|
}
|
||||||
@ -861,12 +863,12 @@ class Delivery extends CommonObject
|
|||||||
if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
|
if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
|
||||||
global $langs;
|
global $langs;
|
||||||
//$langs->load("mymodule");
|
//$langs->load("mymodule");
|
||||||
$this->labelStatus[-1] = $langs->trans('StatusDeliveryCanceled');
|
$this->labelStatus[-1] = $langs->transnoentitiesnoconv('StatusDeliveryCanceled');
|
||||||
$this->labelStatus[0] = $langs->trans('StatusDeliveryDraft');
|
$this->labelStatus[0] = $langs->transnoentitiesnoconv('StatusDeliveryDraft');
|
||||||
$this->labelStatus[1] = $langs->trans('StatusDeliveryValidated');
|
$this->labelStatus[1] = $langs->transnoentitiesnoconv('StatusDeliveryValidated');
|
||||||
$this->labelStatusShort[-1] = $langs->trans('StatusDeliveryCanceled');
|
$this->labelStatusShort[-1] = $langs->transnoentitiesnoconv('StatusDeliveryCanceled');
|
||||||
$this->labelStatusShort[0] = $langs->trans('StatusDeliveryDraft');
|
$this->labelStatusShort[0] = $langs->transnoentitiesnoconv('StatusDeliveryDraft');
|
||||||
$this->labelStatusShort[1] = $langs->trans('StatusDeliveryValidated');
|
$this->labelStatusShort[1] = $langs->transnoentitiesnoconv('StatusDeliveryValidated');
|
||||||
}
|
}
|
||||||
|
|
||||||
$statusType = 'status0';
|
$statusType = 'status0';
|
||||||
@ -995,7 +997,7 @@ class Delivery extends CommonObject
|
|||||||
$array[$i]['label'] = $objSourceLine->label ? $objSourceLine->label : $objSourceLine->description;
|
$array[$i]['label'] = $objSourceLine->label ? $objSourceLine->label : $objSourceLine->description;
|
||||||
}
|
}
|
||||||
|
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
return $array;
|
return $array;
|
||||||
} else {
|
} else {
|
||||||
@ -1016,7 +1018,7 @@ class Delivery extends CommonObject
|
|||||||
if ($user->rights->expedition->creer) {
|
if ($user->rights->expedition->creer) {
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."delivery";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."delivery";
|
||||||
$sql .= " SET date_delivery = ".($delivery_date ? "'".$this->db->idate($delivery_date)."'" : 'null');
|
$sql .= " SET date_delivery = ".($delivery_date ? "'".$this->db->idate($delivery_date)."'" : 'null');
|
||||||
$sql .= " WHERE rowid = ".$this->id;
|
$sql .= " WHERE rowid = ".((int) $this->id);
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::setDeliveryDate", LOG_DEBUG);
|
dol_syslog(get_class($this)."::setDeliveryDate", LOG_DEBUG);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user