mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-07 16:41:48 +01:00
Merge branch 'develop' into oldline
This commit is contained in:
@@ -161,7 +161,7 @@ class Commande extends CommonOrder
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @see date
|
||||
* @see $date
|
||||
*/
|
||||
public $date_commande;
|
||||
|
||||
@@ -321,6 +321,7 @@ class Commande extends CommonOrder
|
||||
public function valid($user, $idwarehouse = 0, $notrigger = 0)
|
||||
{
|
||||
global $conf,$langs;
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
|
||||
$error=0;
|
||||
@@ -364,7 +365,7 @@ class Commande extends CommonOrder
|
||||
|
||||
// Validate
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande";
|
||||
$sql.= " SET ref = '".$num."',";
|
||||
$sql.= " SET ref = '".$this->db->escape($num)."',";
|
||||
$sql.= " fk_statut = ".self::STATUS_VALIDATED.",";
|
||||
$sql.= " date_valid='".$this->db->idate($now)."',";
|
||||
$sql.= " fk_user_valid = ".$user->id;
|
||||
@@ -423,13 +424,18 @@ class Commande extends CommonOrder
|
||||
// Rename directory if dir was a temporary ref
|
||||
if (preg_match('/^[\(]?PROV/i', $this->ref))
|
||||
{
|
||||
// On renomme repertoire ($this->ref = ancienne ref, $num = nouvelle ref)
|
||||
// in order not to lose the attachments
|
||||
// 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 = 'commande/".$this->db->escape($this->newref)."'";
|
||||
$sql.= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'commande/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
|
||||
$resql = $this->db->query($sql);
|
||||
if (! $resql) { $error++; $this->error = $this->db->lasterror(); }
|
||||
|
||||
// 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($num);
|
||||
$dirsource = $conf->commande->dir_output.'/'.$oldref;
|
||||
$dirdest = $conf->commande->dir_output.'/'.$newref;
|
||||
if (file_exists($dirsource))
|
||||
$dirsource = $conf->commande->multidir_output[$this->entity].'/'.$oldref;
|
||||
$dirdest = $conf->commande->multidir_output[$this->entity].'/'.$newref;
|
||||
if (! $error && file_exists($dirsource))
|
||||
{
|
||||
dol_syslog(get_class($this)."::valid() rename dir ".$dirsource." into ".$dirdest);
|
||||
|
||||
@@ -437,7 +443,7 @@ class Commande extends CommonOrder
|
||||
{
|
||||
dol_syslog("Rename ok");
|
||||
// Rename docs starting with $oldref with $newref
|
||||
$listoffiles=dol_dir_list($conf->commande->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
|
||||
$listoffiles=dol_dir_list($conf->commande->multidir_output[$this->entity].'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
|
||||
foreach($listoffiles as $fileentry)
|
||||
{
|
||||
$dirsource=$fileentry['name'];
|
||||
@@ -499,7 +505,7 @@ class Commande extends CommonOrder
|
||||
return -1;
|
||||
}
|
||||
|
||||
dol_syslog(get_class($this)."::set_draft", LOG_DEBUG);
|
||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
@@ -815,7 +821,7 @@ class Commande extends CommonOrder
|
||||
}
|
||||
if (! empty($conf->global->COMMANDE_REQUIRE_SOURCE) && $this->source < 0)
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFieldRequired", $langs->trans("Source"));
|
||||
$this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Source"));
|
||||
dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
@@ -859,7 +865,7 @@ class Commande extends CommonOrder
|
||||
$sql.= ", ".($this->remise_percent>0?$this->db->escape($this->remise_percent):0);
|
||||
$sql.= ", ".(int) $this->fk_incoterms;
|
||||
$sql.= ", '".$this->db->escape($this->location_incoterms)."'";
|
||||
$sql.= ", ".$conf->entity;
|
||||
$sql.= ", ".setEntity($this);
|
||||
$sql.= ", ".($this->module_source ? "'".$this->db->escape($this->module_source)."'" : "null");
|
||||
$sql.= ", ".($this->pos_source != '' ? "'".$this->db->escape($this->pos_source)."'" : "null");
|
||||
$sql.= ", ".(int) $this->fk_multicurrency;
|
||||
@@ -1070,12 +1076,13 @@ class Commande extends CommonOrder
|
||||
/**
|
||||
* Load an object from its id and create a new one in database
|
||||
*
|
||||
* @param int $socid Id of thirdparty
|
||||
* @return int New id of clone
|
||||
* @param User $user User making the clone
|
||||
* @param int $socid Id of thirdparty
|
||||
* @return int New id of clone
|
||||
*/
|
||||
public function createFromClone($socid = 0)
|
||||
public function createFromClone(User $user, $socid = 0)
|
||||
{
|
||||
global $user,$hookmanager;
|
||||
global $conf, $user,$hookmanager;
|
||||
|
||||
$error=0;
|
||||
|
||||
@@ -1085,69 +1092,88 @@ class Commande extends CommonOrder
|
||||
foreach($this->lines as $line)
|
||||
$line->fetch_optionals();
|
||||
|
||||
// Load source object
|
||||
$objFrom = clone $this;
|
||||
// Load source object
|
||||
$objFrom = clone $this;
|
||||
|
||||
// Change socid if needed
|
||||
if (! empty($socid) && $socid != $this->socid)
|
||||
// Change socid if needed
|
||||
if (! empty($socid) && $socid != $this->socid)
|
||||
{
|
||||
$objsoc = new Societe($this->db);
|
||||
|
||||
if ($objsoc->fetch($socid)>0)
|
||||
{
|
||||
$objsoc = new Societe($this->db);
|
||||
|
||||
if ($objsoc->fetch($socid)>0)
|
||||
{
|
||||
$this->socid = $objsoc->id;
|
||||
$this->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
|
||||
$this->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
|
||||
$this->fk_project = 0;
|
||||
$this->fk_delivery_address = 0;
|
||||
}
|
||||
|
||||
// TODO Change product price if multi-prices
|
||||
$this->socid = $objsoc->id;
|
||||
$this->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
|
||||
$this->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
|
||||
$this->fk_project = 0;
|
||||
$this->fk_delivery_address = 0;
|
||||
}
|
||||
|
||||
$this->id=0;
|
||||
$this->ref = '';
|
||||
$this->statut=self::STATUS_DRAFT;
|
||||
// TODO Change product price if multi-prices
|
||||
}
|
||||
|
||||
// Clear fields
|
||||
$this->user_author_id = $user->id;
|
||||
$this->user_valid = '';
|
||||
$this->date = dol_now();
|
||||
$this->date_commande = dol_now();
|
||||
$this->date_creation = '';
|
||||
$this->date_validation = '';
|
||||
$this->ref_client = '';
|
||||
$this->id=0;
|
||||
$this->ref = '';
|
||||
$this->statut=self::STATUS_DRAFT;
|
||||
|
||||
// Create clone
|
||||
$this->context['createfromclone'] = 'createfromclone';
|
||||
$result=$this->create($user);
|
||||
if ($result < 0) $error++;
|
||||
// Clear fields
|
||||
$this->user_author_id = $user->id;
|
||||
$this->user_valid = '';
|
||||
$this->date = dol_now();
|
||||
$this->date_commande = dol_now();
|
||||
$this->date_creation = '';
|
||||
$this->date_validation = '';
|
||||
if (empty($conf->global->MAIN_KEEP_REF_CUSTOMER_ON_CLONING)) $this->ref_client = '';
|
||||
|
||||
if (! $error)
|
||||
// Create clone
|
||||
$this->context['createfromclone'] = 'createfromclone';
|
||||
$result=$this->create($user);
|
||||
if ($result < 0) $error++;
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
// copy internal contacts
|
||||
if ($this->copy_linked_contact($objFrom, 'internal') < 0)
|
||||
{
|
||||
// Hook of thirdparty module
|
||||
if (is_object($hookmanager))
|
||||
{
|
||||
$parameters=array('objFrom'=>$objFrom);
|
||||
$action='';
|
||||
$reshook=$hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
||||
if ($reshook < 0) $error++;
|
||||
}
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
unset($this->context['createfromclone']);
|
||||
if (! $error)
|
||||
{
|
||||
// copy external contacts if same company
|
||||
if ($this->socid == $objFrom->socid)
|
||||
{
|
||||
if ($this->copy_linked_contact($objFrom, 'external') < 0)
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
// End
|
||||
if (! $error)
|
||||
if (! $error)
|
||||
{
|
||||
// Hook of thirdparty module
|
||||
if (is_object($hookmanager))
|
||||
{
|
||||
$this->db->commit();
|
||||
return $this->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
$parameters=array('objFrom'=>$objFrom);
|
||||
$action='';
|
||||
$reshook=$hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
||||
if ($reshook < 0) $error++;
|
||||
}
|
||||
}
|
||||
|
||||
unset($this->context['createfromclone']);
|
||||
|
||||
// End
|
||||
if (! $error)
|
||||
{
|
||||
$this->db->commit();
|
||||
return $this->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1212,6 +1238,7 @@ class Commande extends CommonOrder
|
||||
$this->lines[$i] = $line;
|
||||
}
|
||||
|
||||
$this->entity = $object->entity;
|
||||
$this->socid = $object->socid;
|
||||
$this->fk_project = $object->fk_project;
|
||||
$this->cond_reglement_id = $object->cond_reglement_id;
|
||||
@@ -1292,7 +1319,7 @@ class Commande extends CommonOrder
|
||||
* @param float $txlocaltax2 Local tax 2 rate (deprecated, use instead txtva with code inside)
|
||||
* @param int $fk_product Id of product
|
||||
* @param float $remise_percent Percentage discount of the line
|
||||
* @param int $info_bits Bits de type de lignes
|
||||
* @param int $info_bits Bits of type of lines
|
||||
* @param int $fk_remise_except Id remise
|
||||
* @param string $price_base_type HT or TTC
|
||||
* @param float $pu_ttc Prix unitaire TTC
|
||||
@@ -1312,7 +1339,7 @@ class Commande extends CommonOrder
|
||||
* @param double $pu_ht_devise Unit price in currency
|
||||
* @return int >0 if OK, <0 if KO
|
||||
*
|
||||
* @see add_product
|
||||
* @see add_product()
|
||||
*
|
||||
* Les parametres sont deja cense etre juste et avec valeurs finales a l'appel
|
||||
* de cette methode. Aussi, pour le taux tva, il doit deja avoir ete defini
|
||||
@@ -1431,11 +1458,11 @@ class Commande extends CommonOrder
|
||||
$pu_ht_devise = $tabprice[19];
|
||||
|
||||
// Rang to use
|
||||
$rangtouse = $rang;
|
||||
if ($rangtouse == -1)
|
||||
$ranktouse = $rang;
|
||||
if ($ranktouse == -1)
|
||||
{
|
||||
$rangmax = $this->line_max($fk_parent_line);
|
||||
$rangtouse = $rangmax + 1;
|
||||
$ranktouse = $rangmax + 1;
|
||||
}
|
||||
|
||||
// TODO A virer
|
||||
@@ -1469,7 +1496,7 @@ class Commande extends CommonOrder
|
||||
$this->line->fk_remise_except=$fk_remise_except;
|
||||
$this->line->remise_percent=$remise_percent;
|
||||
$this->line->subprice=$pu_ht;
|
||||
$this->line->rang=$rangtouse;
|
||||
$this->line->rang=$ranktouse;
|
||||
$this->line->info_bits=$info_bits;
|
||||
$this->line->total_ht=$total_ht;
|
||||
$this->line->total_tva=$total_tva;
|
||||
@@ -1656,7 +1683,7 @@ class Commande extends CommonOrder
|
||||
$sql.= ', c.fk_incoterms, c.location_incoterms';
|
||||
$sql.= ", c.fk_multicurrency, c.multicurrency_code, c.multicurrency_tx, c.multicurrency_total_ht, c.multicurrency_total_tva, c.multicurrency_total_ttc";
|
||||
$sql.= ", c.module_source, c.pos_source";
|
||||
$sql.= ", i.libelle as libelle_incoterms";
|
||||
$sql.= ", i.libelle as label_incoterms";
|
||||
$sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
|
||||
$sql.= ', cr.code as cond_reglement_code, cr.libelle as cond_reglement_libelle, cr.libelle_facture as cond_reglement_libelle_doc';
|
||||
$sql.= ', ca.code as availability_code, ca.label as availability_label';
|
||||
@@ -1665,7 +1692,7 @@ class Commande extends CommonOrder
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON c.fk_cond_reglement = cr.rowid';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON c.fk_mode_reglement = p.id';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_availability as ca ON c.fk_availability = ca.rowid';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as dr ON c.fk_input_reason = ca.rowid';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as dr ON c.fk_input_reason = dr.rowid';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON c.fk_incoterms = i.rowid';
|
||||
|
||||
if ($id) $sql.= " WHERE c.rowid=".$id;
|
||||
@@ -1738,7 +1765,7 @@ class Commande extends CommonOrder
|
||||
//Incoterms
|
||||
$this->fk_incoterms = $obj->fk_incoterms;
|
||||
$this->location_incoterms = $obj->location_incoterms;
|
||||
$this->libelle_incoterms = $obj->libelle_incoterms;
|
||||
$this->label_incoterms = $obj->label_incoterms;
|
||||
|
||||
// Multicurrency
|
||||
$this->fk_multicurrency = $obj->fk_multicurrency;
|
||||
@@ -1868,10 +1895,12 @@ class Commande extends CommonOrder
|
||||
* Load array lines
|
||||
*
|
||||
* @param int $only_product Return only physical products
|
||||
* @param int $loadalsotranslation Return translation for products
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
public function fetch_lines($only_product = 0)
|
||||
public function fetch_lines($only_product = 0, $loadalsotranslation = 0)
|
||||
{
|
||||
global $langs, $conf;
|
||||
// phpcs:enable
|
||||
$this->lines=array();
|
||||
|
||||
@@ -1964,6 +1993,13 @@ class Commande extends CommonOrder
|
||||
|
||||
$line->fetch_optionals();
|
||||
|
||||
// multilangs
|
||||
if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($objp->fk_product) && ! empty($loadalsotranslation)) {
|
||||
$line = new Product($this->db);
|
||||
$line->fetch($objp->fk_product);
|
||||
$line->getMultiLangs();
|
||||
}
|
||||
|
||||
$this->lines[$i] = $line;
|
||||
|
||||
$i++;
|
||||
@@ -2940,7 +2976,7 @@ class Commande extends CommonOrder
|
||||
dol_syslog(get_class($this)."::updateline id=$rowid, desc=$desc, pu=$pu, qty=$qty, remise_percent=$remise_percent, txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, price_base_type=$price_base_type, info_bits=$info_bits, date_start=$date_start, date_end=$date_end, type=$type, fk_parent_line=$fk_parent_line, pa_ht=$pa_ht, special_code=$special_code");
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
|
||||
|
||||
if ($this->statut == Propal::STATUS_DRAFT)
|
||||
if ($this->statut == Commande::STATUS_DRAFT)
|
||||
{
|
||||
|
||||
// Clean parameters
|
||||
@@ -3304,10 +3340,10 @@ class Commande extends CommonOrder
|
||||
{
|
||||
// Remove directory with files
|
||||
$comref = dol_sanitizeFileName($this->ref);
|
||||
if ($conf->commande->dir_output && !empty($this->ref))
|
||||
if ($conf->commande->multidir_output[$this->entity] && !empty($this->ref))
|
||||
{
|
||||
$dir = $conf->commande->dir_output . "/" . $comref ;
|
||||
$file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf";
|
||||
$dir = $conf->commande->multidir_output[$this->entity] . "/" . $comref ;
|
||||
$file = $conf->commande->multidir_output[$this->entity] . "/" . $comref . "/" . $comref . ".pdf";
|
||||
if (file_exists($file)) // We must delete all files before deleting directory
|
||||
{
|
||||
dol_delete_preview($this);
|
||||
@@ -3380,6 +3416,7 @@ class Commande extends CommonOrder
|
||||
$response = new WorkboardResponse();
|
||||
$response->warning_delay=$conf->commande->client->warning_delay/60/60/24;
|
||||
$response->label=$langs->trans("OrdersToProcess");
|
||||
$response->labelShort = $langs->trans("Opened");
|
||||
$response->url=DOL_URL_ROOT.'/commande/list.php?viewstatut=-3&mainmenu=commercial&leftmenu=orders';
|
||||
$response->img=img_object('', "order");
|
||||
|
||||
@@ -3890,7 +3927,7 @@ class OrderLine extends CommonOrderLine
|
||||
* Id of parent order
|
||||
* @var int
|
||||
* @deprecated Use fk_commande
|
||||
* @see fk_commande
|
||||
* @see $fk_commande
|
||||
*/
|
||||
public $commande_id;
|
||||
|
||||
@@ -3917,7 +3954,7 @@ class OrderLine extends CommonOrderLine
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @see remise_percent, fk_remise_except
|
||||
* @see $remise_percent, $fk_remise_except
|
||||
*/
|
||||
public $remise;
|
||||
|
||||
@@ -4035,6 +4072,33 @@ class OrderLine extends CommonOrderLine
|
||||
|
||||
$error=0;
|
||||
|
||||
// check if order line is not in a shipment line before deleting
|
||||
$sqlCheckShipmentLine = "SELECT";
|
||||
$sqlCheckShipmentLine .= " ed.rowid";
|
||||
$sqlCheckShipmentLine .= " FROM " . MAIN_DB_PREFIX . "expeditiondet ed";
|
||||
$sqlCheckShipmentLine .= " WHERE ed.fk_origin_line = " . $this->rowid;
|
||||
|
||||
$resqlCheckShipmentLine = $this->db->query($sqlCheckShipmentLine);
|
||||
if (!$resqlCheckShipmentLine) {
|
||||
$error++;
|
||||
$this->error = $this->db->lasterror();
|
||||
$this->errors[] = $this->error;
|
||||
} else {
|
||||
$langs->load('errors');
|
||||
$num = $this->db->num_rows($resqlCheckShipmentLine);
|
||||
if ($num > 0) {
|
||||
$error++;
|
||||
$objCheckShipmentLine = $this->db->fetch_object($resqlCheckShipmentLine);
|
||||
$this->error = $langs->trans('ErrorRecordAlreadyExists') . ' : ' . $langs->trans('ShipmentLine') . ' ' . $objCheckShipmentLine->rowid;
|
||||
$this->errors[] = $this->error;
|
||||
}
|
||||
$this->db->free($resqlCheckShipmentLine);
|
||||
}
|
||||
if ($error) {
|
||||
dol_syslog(__METHOD__ . 'Error ; ' . $this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE rowid=".$this->rowid;
|
||||
|
||||
Reference in New Issue
Block a user