2
0
forked from Wavyzz/dolibarr

Merge remote-tracking branch 'origin/3.6' into 3.7

Conflicts:
	ChangeLog
	htdocs/commande/class/commande.class.php
	htdocs/filefunc.inc.php
This commit is contained in:
Laurent Destailleur
2015-01-09 22:40:45 +01:00
6747 changed files with 160288 additions and 413741 deletions

View File

@@ -3,10 +3,11 @@
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2014 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2011 Jean Heimburger <jean@tiaris.info>
* Copyright (C) 2012-2014 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -43,6 +44,11 @@ class Commande extends CommonOrder
public $fk_element = 'fk_commande';
protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
/**
* {@inheritdoc}
*/
protected $table_ref_field = 'ref';
var $id;
var $socid; // Id client
@@ -60,6 +66,7 @@ class Commande extends CommonOrder
var $brouillon;
var $cond_reglement_id;
var $cond_reglement_code;
var $fk_account;
var $mode_reglement_id;
var $mode_reglement_code;
var $availability_id;
@@ -71,6 +78,7 @@ class Commande extends CommonOrder
var $date; // Date commande
var $date_commande; // Date commande (deprecated)
var $date_livraison; // Date livraison souhaitee
var $shipping_method_id;
var $fk_remise_except;
var $remise_percent;
var $total_ht; // Total net of tax
@@ -131,18 +139,21 @@ class Commande extends CommonOrder
if (! empty($conf->global->COMMANDE_ADDON))
{
$mybool=false;
$mybool=false;
$dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
foreach ($dirmodels as $reldir)
{
$file = $conf->global->COMMANDE_ADDON.".php";
$classname = $conf->global->COMMANDE_ADDON;
$file = $conf->global->COMMANDE_ADDON.".php";
$classname = $conf->global->COMMANDE_ADDON;
// Include file with class
foreach ($conf->file->dol_document_root as $dirroot)
{
$dir = $dirroot."/core/modules/commande/";
// Load file with numbering class (if found)
$mybool|=@include_once $dir.$file;
}
// Include file with class
foreach ($conf->file->dol_document_root as $dirroot)
{
$dir = $dirroot.$reldir."/core/modules/commande/";
// Load file with numbering class (if found)
$mybool|=@include_once $dir.$file;
}
}
if (! $mybool)
{
@@ -177,9 +188,10 @@ class Commande extends CommonOrder
*
* @param User $user User making status change
* @param int $idwarehouse Id of warehouse to use for stock decrease
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
* @return int <=0 if OK, >0 if KO
*/
function valid($user, $idwarehouse=0)
function valid($user, $idwarehouse=0, $notrigger=0)
{
global $conf,$langs;
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@@ -217,9 +229,10 @@ class Commande extends CommonOrder
$num = $this->getNextNumRef($soc);
}
else
{
{
$num = $this->ref;
}
$this->newref = $num;
// Validate
$sql = "UPDATE ".MAIN_DB_PREFIX."commande";
@@ -229,12 +242,12 @@ class Commande extends CommonOrder
$sql.= " fk_user_valid = ".$user->id;
$sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::valid() sql=".$sql);
dol_syslog(get_class($this)."::valid()", LOG_DEBUG);
$resql=$this->db->query($sql);
if (! $resql)
{
dol_syslog(get_class($this)."::valid Echec update - 10 - sql=".$sql, LOG_ERR);
dol_print_error($this->db);
$this->error=$this->db->lasterror();
$error++;
}
@@ -256,36 +269,55 @@ class Commande extends CommonOrder
$mouvP->origin = &$this;
// We decrement stock of product (and sub-products)
$result=$mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("OrderValidatedInDolibarr",$num));
if ($result < 0) { $error++; }
if ($result < 0)
{
$error++;
$this->error=$mouvP->error;
}
}
if ($error) break;
}
}
}
if (! $error && ! $notrigger)
{
// Call trigger
$result=$this->call_trigger('ORDER_VALIDATE',$user);
if ($result < 0) $error++;
// End call triggers
}
if (! $error)
{
$this->oldref='';
$this->oldref = $this->ref;
// Rename directory if dir was a temporary ref
if (preg_match('/^[\(]?PROV/i', $this->ref))
{
// On renomme repertoire ($this->ref = ancienne ref, $numfa = nouvelle ref)
// On renomme repertoire ($this->ref = ancienne ref, $numfa = nouvelle ref)
// in order not to lose the attachments
$comref = dol_sanitizeFileName($this->ref);
$snum = dol_sanitizeFileName($num);
$dirsource = $conf->commande->dir_output.'/'.$comref;
$dirdest = $conf->commande->dir_output.'/'.$snum;
$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))
{
dol_syslog(get_class($this)."::valid() rename dir ".$dirsource." into ".$dirdest);
if (@rename($dirsource, $dirdest))
{
$this->oldref = $comref;
dol_syslog("Rename ok");
// Suppression ancien fichier PDF dans nouveau rep
dol_delete_file($conf->commande->dir_output.'/'.$snum.'/'.$comref.'*.*');
// Rename docs starting with $oldref with $newref
$listoffiles=dol_dir_list($conf->commande->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);
}
}
}
}
@@ -294,18 +326,8 @@ class Commande extends CommonOrder
// Set new ref and current status
if (! $error)
{
$this->ref = $num;
$this->statut = 1;
}
if (! $error)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('ORDER_VALIDATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
$this->ref = $num;
$this->statut = 1;
}
if (! $error)
@@ -314,9 +336,8 @@ class Commande extends CommonOrder
return 1;
}
else
{
{
$this->db->rollback();
$this->error=$this->db->lasterror();
return -1;
}
}
@@ -352,7 +373,7 @@ class Commande extends CommonOrder
$sql.= " SET fk_statut = 0";
$sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::set_draft sql=".$sql, LOG_DEBUG);
dol_syslog(get_class($this)."::set_draft", LOG_DEBUG);
if ($this->db->query($sql))
{
// If stock is decremented on validate order, we must reincrement it
@@ -395,7 +416,6 @@ class Commande extends CommonOrder
{
$this->error=$this->db->error();
$this->db->rollback();
dol_syslog($this->error, LOG_ERR);
return -1;
}
}
@@ -424,16 +444,14 @@ class Commande extends CommonOrder
$sql.= ' SET fk_statut=1, facture=0';
$sql.= ' WHERE rowid = '.$this->id;
dol_syslog(get_class($this)."::set_reopen sql=".$sql);
dol_syslog(get_class($this)."::set_reopen", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('ORDER_REOPEN',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
// Call trigger
$result=$this->call_trigger('ORDER_REOPEN',$user);
if ($result < 0) $error++;
// End call triggers
}
else
{
@@ -489,12 +507,10 @@ class Commande extends CommonOrder
if ($this->db->query($sql))
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('ORDER_CLOSE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
// Call trigger
$result=$this->call_trigger('ORDER_CLOSE',$user);
if ($result < 0) $error++;
// End call triggers
if (! $error)
{
@@ -512,7 +528,6 @@ class Commande extends CommonOrder
else
{
$this->error=$this->db->lasterror();
dol_syslog($this->error, LOG_ERR);
$this->db->rollback();
return -1;
@@ -540,7 +555,7 @@ class Commande extends CommonOrder
$sql.= " WHERE rowid = ".$this->id;
$sql.= " AND fk_statut = 1";
dol_syslog(get_class($this)."::cancel sql=".$sql, LOG_DEBUG);
dol_syslog(get_class($this)."::cancel", LOG_DEBUG);
if ($this->db->query($sql))
{
// If stock is decremented on validate order, we must reincrement it
@@ -557,8 +572,11 @@ class Commande extends CommonOrder
$mouvP = new MouvementStock($this->db);
// We increment stock of product (and sub-products)
$result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("OrderCanceledInDolibarr",$this->ref));
if ($result < 0) {
if ($result < 0)
{
$error++;
$this->error=$mouvP->error;
break;
}
}
}
@@ -566,14 +584,10 @@ class Commande extends CommonOrder
if (! $error)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('ORDER_CANCEL',$this,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
// Call trigger
$result=$this->call_trigger('ORDER_CANCEL',$user);
if ($result < 0) $error++;
// End call triggers
}
if (! $error)
@@ -584,8 +598,6 @@ class Commande extends CommonOrder
}
else
{
$this->error=$mouvP->error;
foreach($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::cancel ".$errmsg, LOG_ERR);
@@ -599,7 +611,6 @@ class Commande extends CommonOrder
{
$this->error=$this->db->error();
$this->db->rollback();
dol_syslog($this->error, LOG_ERR);
return -1;
}
}
@@ -658,8 +669,9 @@ class Commande extends CommonOrder
$this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commande (";
$sql.= " ref, fk_soc, date_creation, fk_user_author, fk_projet, date_commande, source, note_private, note_public, ref_ext, ref_client, ref_int";
$sql.= ", model_pdf, fk_cond_reglement, fk_mode_reglement, fk_availability, fk_input_reason, date_livraison, fk_delivery_address";
$sql.= " ref, fk_soc, date_creation, fk_user_author, fk_projet, date_commande, source, note_private, note_public, ref_client, ref_int";
$sql.= ", model_pdf, fk_cond_reglement, fk_mode_reglement, fk_account, fk_availability, fk_input_reason, date_livraison, fk_delivery_address";
$sql.= ", fk_shipping_method";
$sql.= ", remise_absolue, remise_percent";
$sql.= ", entity";
$sql.= ")";
@@ -675,16 +687,18 @@ class Commande extends CommonOrder
$sql.= ", '".$this->modelpdf."'";
$sql.= ", ".($this->cond_reglement_id>0?"'".$this->cond_reglement_id."'":"null");
$sql.= ", ".($this->mode_reglement_id>0?"'".$this->mode_reglement_id."'":"null");
$sql.= ", ".($this->fk_account>0?$this->fk_account:'NULL');
$sql.= ", ".($this->availability_id>0?"'".$this->availability_id."'":"null");
$sql.= ", ".($this->demand_reason_id>0?"'".$this->demand_reason_id."'":"null");
$sql.= ", ".($this->date_livraison?"'".$this->db->idate($this->date_livraison)."'":"null");
$sql.= ", ".($this->fk_delivery_address>0?$this->fk_delivery_address:'NULL');
$sql.= ", ".($this->shipping_method_id>0?$this->shipping_method_id:'NULL');
$sql.= ", ".($this->remise_absolue>0?$this->remise_absolue:'NULL');
$sql.= ", ".($this->remise_percent>0?$this->remise_percent:0);
$sql.= ", ".$conf->entity;
$sql.= ")";
dol_syslog(get_class($this)."::create sql=".$sql);
dol_syslog(get_class($this)."::create", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
@@ -766,9 +780,10 @@ class Commande extends CommonOrder
if ($origin == 'propal' && $origin_id)
{
// On recupere les differents contact interne et externe
$prop = new Propal($this->db, $this->socid, $origin_id);
$prop = new Propal($this->db);
$prop->fetch($origin_id);
// On recupere le commercial suivi propale
// We get ids of sales representatives of proposal
$this->userid = $prop->getIdcontact('internal', 'SALESREPFOLL');
if ($this->userid)
@@ -777,7 +792,7 @@ class Commande extends CommonOrder
$this->add_contact($this->userid[0], 'SALESREPFOLL', 'internal');
}
// On recupere le contact client suivi propale
// We get ids of customer follower of proposal
$this->contactid = $prop->getIdcontact('external', 'CUSTOMER');
if ($this->contactid)
@@ -792,6 +807,8 @@ class Commande extends CommonOrder
if (! $error)
{
$action='create';
// Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !!
$hookmanager->initHooks(array('orderdao'));
@@ -813,12 +830,10 @@ class Commande extends CommonOrder
if (! $notrigger)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('ORDER_CREATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
// Call trigger
$result=$this->call_trigger('ORDER_CREATE',$user);
if ($result < 0) $error++;
// End call triggers
}
if (!$error) {
@@ -921,12 +936,10 @@ class Commande extends CommonOrder
if ($reshook < 0) $error++;
}
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('ORDER_CLONE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
// Call trigger
$result=$this->call_trigger('ORDER_CLONE',$user);
if ($result < 0) $error++;
// End call triggers
}
// End
@@ -1005,9 +1018,11 @@ class Commande extends CommonOrder
$this->fk_project = $object->fk_project;
$this->cond_reglement_id = $object->cond_reglement_id;
$this->mode_reglement_id = $object->mode_reglement_id;
$this->fk_account = $object->fk_account;
$this->availability_id = $object->availability_id;
$this->demand_reason_id = $object->demand_reason_id;
$this->date_livraison = $object->date_livraison;
$this->shipping_method_id = $object->shipping_method_id;
$this->fk_delivery_address = $object->fk_delivery_address;
$this->contact_id = $object->contactid;
$this->ref_client = $object->ref_client;
@@ -1142,7 +1157,7 @@ class Commande extends CommonOrder
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
$localtaxes_type=getLocalTaxesFromRate($txtva,0,$mysoc);
$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc);
$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type,'', $localtaxes_type);
$total_ht = $tabprice[0];
@@ -1361,8 +1376,10 @@ class Commande extends CommonOrder
$sql = 'SELECT c.rowid, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_statut';
$sql.= ', c.amount_ht, c.total_ht, c.total_ttc, c.tva as total_tva, c.localtax1 as total_localtax1, c.localtax2 as total_localtax2, c.fk_cond_reglement, c.fk_mode_reglement, c.fk_availability, c.fk_input_reason';
$sql.= ', c.fk_account';
$sql.= ', c.date_commande';
$sql.= ', c.date_livraison';
$sql.= ', c.fk_shipping_method';
$sql.= ', c.fk_projet, c.remise_percent, c.remise, c.remise_absolue, c.source, c.facture as billed';
$sql.= ', c.note_private, c.note_public, c.ref_client, c.ref_ext, c.ref_int, c.model_pdf, c.fk_delivery_address, c.extraparams';
$sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
@@ -1380,7 +1397,7 @@ class Commande extends CommonOrder
if ($ref_ext) $sql.= " AND c.ref_ext='".$this->db->escape($ref_ext)."'";
if ($ref_int) $sql.= " AND c.ref_int='".$this->db->escape($ref_int)."'";
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
@@ -1420,11 +1437,13 @@ class Commande extends CommonOrder
$this->cond_reglement_code = $obj->cond_reglement_code;
$this->cond_reglement = $obj->cond_reglement_libelle;
$this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
$this->fk_account = $obj->fk_account;
$this->availability_id = $obj->fk_availability;
$this->availability_code = $obj->availability_code;
$this->demand_reason_id = $obj->fk_input_reason;
$this->demand_reason_code = $obj->demand_reason_code;
$this->date_livraison = $this->db->jdate($obj->date_livraison);
$this->shipping_method_id = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null;
$this->fk_delivery_address = $obj->fk_delivery_address;
$this->extraparams = (array) json_decode($obj->extraparams, true);
@@ -1455,13 +1474,11 @@ class Commande extends CommonOrder
else
{
$this->error='Order with id '.$id.' not found sql='.$sql;
dol_syslog(get_class($this).'::fetch '.$this->error);
return 0;
}
}
else
{
dol_syslog(get_class($this).'::fetch Error rowid='.$id, LOG_ERR);
$this->error=$this->db->error();
return -1;
}
@@ -1564,7 +1581,7 @@ class Commande extends CommonOrder
if ($only_product) $sql .= ' AND p.fk_product_type = 0';
$sql .= ' ORDER BY l.rang';
dol_syslog(get_class($this)."::fetch_lines sql=".$sql,LOG_DEBUG);
dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
@@ -1629,7 +1646,6 @@ class Commande extends CommonOrder
else
{
$this->error=$this->db->error();
dol_syslog('Commande::fetch_lines: Error '.$this->error, LOG_ERR);
return -3;
}
}
@@ -1691,7 +1707,7 @@ class Commande extends CommonOrder
$sql.= ' GROUP BY cd.rowid, cd.fk_product';
//print $sql;
dol_syslog(get_class($this)."::loadExpeditions sql=".$sql,LOG_DEBUG);
dol_syslog(get_class($this)."::loadExpeditions", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
@@ -1709,7 +1725,6 @@ class Commande extends CommonOrder
else
{
$this->error=$this->db->lasterror();
dol_syslog(get_class($this)."::loadExpeditions ".$this->error,LOG_ERR);
return -1;
}
@@ -1924,7 +1939,7 @@ class Commande extends CommonOrder
$sql.= ' SET remise_absolue = '.$remise;
$sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;';
dol_syslog(get_class($this)."::set_remise_absolue sql=$sql");
dol_syslog(get_class($this)."::set_remise_absolue", LOG_DEBUG);
if ($this->db->query($sql))
{
@@ -1956,7 +1971,7 @@ class Commande extends CommonOrder
$sql.= " SET date_commande = ".($date ? $this->db->idate($date) : 'null');
$sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
dol_syslog(get_class($this)."::set_date sql=$sql",LOG_DEBUG);
dol_syslog(get_class($this)."::set_date",LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
@@ -1966,7 +1981,6 @@ class Commande extends CommonOrder
else
{
$this->error=$this->db->error();
dol_syslog(get_class($this)."::set_date ".$this->error,LOG_ERR);
return -1;
}
}
@@ -1991,7 +2005,7 @@ class Commande extends CommonOrder
$sql.= " SET date_livraison = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null');
$sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::set_date_livraison sql=".$sql,LOG_DEBUG);
dol_syslog(get_class($this)."::set_date_livraison", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
@@ -2001,7 +2015,6 @@ class Commande extends CommonOrder
else
{
$this->error=$this->db->error();
dol_syslog(get_class($this)."::set_date_livraison ".$this->error,LOG_ERR);
return -1;
}
}
@@ -2235,7 +2248,6 @@ class Commande extends CommonOrder
else
{
$this->error=$this->db->lasterror();
dol_syslog(get_class($this).'::set_ref_client Erreur '.$this->error.' - '.$sql, LOG_ERR);
return -2;
}
}
@@ -2259,17 +2271,13 @@ class Commande extends CommonOrder
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET facture = 1';
$sql.= ' WHERE rowid = '.$this->id.' AND fk_statut > 0';
dol_syslog(get_class($this)."::classifyBilled sql=".$sql, LOG_DEBUG);
dol_syslog(get_class($this)."::classifyBilled", LOG_DEBUG);
if ($this->db->query($sql))
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('ORDER_CLASSIFY_BILLED',$this,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
// Call trigger
$result=$this->call_trigger('ORDER_CLASSIFY_BILLED',$user);
if ($result < 0) $error++;
// End call triggers
if (! $error)
{
@@ -2281,8 +2289,6 @@ class Commande extends CommonOrder
}
else
{
$this->error=$this->db->error();
foreach($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::classifyBilled ".$errmsg, LOG_ERR);
@@ -2295,7 +2301,6 @@ class Commande extends CommonOrder
else
{
$this->error=$this->db->error();
dol_syslog(get_class($this)."::classifyBilled Error ".$this->error, LOG_ERR);
$this->db->rollback();
return -1;
}
@@ -2371,7 +2376,7 @@ class Commande extends CommonOrder
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
$localtaxes_type=getLocalTaxesFromRate($txtva,0,$mysoc);
$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty, $mysoc);
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, '', $localtaxes_type);
$total_ht = $tabprice[0];
@@ -2496,34 +2501,31 @@ class Commande extends CommonOrder
if (! $error && ! $notrigger)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('ORDER_DELETE',$this,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
// Call trigger
$result=$this->call_trigger('ORDER_DELETE',$user);
if ($result < 0) $error++;
// End call triggers
}
//TODO: Check for error after each action. If one failed we rollback, don't waste time to do action if previous fail
if (! $error)
{
// Delete order details
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE fk_commande = ".$this->id;
dol_syslog(get_class($this)."::delete sql=".$sql);
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
if (! $this->db->query($sql) )
{
dol_syslog(get_class($this)."::delete error", LOG_ERR);
$error++;
$this->errors[]=$this->db->lasterror();
}
// Delete order
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG);
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
if (! $this->db->query($sql) )
{
dol_syslog(get_class($this)."::delete error", LOG_ERR);
$error++;
$this->errors[]=$this->db->lasterror();
}
// Delete linked object
@@ -2583,7 +2585,6 @@ class Commande extends CommonOrder
}
else
{
$this->error=$this->db->lasterror();
foreach($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
@@ -2753,7 +2754,7 @@ class Commande extends CommonOrder
$result='';
if (! empty($conf->expedition->enabled) && ($option == 1 || $option == 2)) $url = DOL_URL_ROOT.'/expedition/shipment.php?id='.$this->id;
else $url = DOL_URL_ROOT.'/commande/fiche.php?id='.$this->id;
else $url = DOL_URL_ROOT.'/commande/card.php?id='.$this->id;
if ($short) return $url;
@@ -2961,6 +2962,8 @@ class Commande extends CommonOrder
*/
function update_extrafields($user)
{
$action='create';
// Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !!
$hookmanager->initHooks(array('orderdao'));
@@ -3061,11 +3064,44 @@ class Commande extends CommonOrder
else
{
$this->error=$this->db->error();
dol_syslog("Error sql=$sql, error=".$this->error,LOG_ERR);
return -1;
}
}
/**
* Create a document onto disk accordign to template module.
*
* @param string $modele Force le mnodele a utiliser ('' to not force)
* @param Translate $outputlangs objet lang a utiliser pour traduction
* @param int $hidedetails Hide details of lines
* @param int $hidedesc Hide description
* @param int $hideref Hide ref
* @return int 0 if KO, 1 if OK
*/
public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
{
global $conf,$user,$langs,$hookmanager;
$langs->load("orders");
// Positionne le modele sur le nom du modele a utiliser
if (! dol_strlen($modele))
{
if (! empty($conf->global->COMMANDE_ADDON_PDF))
{
$modele = $conf->global->COMMANDE_ADDON_PDF;
}
else
{
$modele = 'einstein';
}
}
$modelpath = "core/modules/commande/doc/";
return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
}
@@ -3227,7 +3263,7 @@ class OrderLine extends CommonOrderLine
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE rowid='".$this->rowid."';";
dol_syslog("OrderLine::delete sql=".$sql);
dol_syslog("OrderLine::delete", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
@@ -3243,12 +3279,10 @@ class OrderLine extends CommonOrderLine
}
}
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('LINEORDER_DELETE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
// Call trigger
$result=$this->call_trigger('LINEORDER_DELETE',$user);
if ($result < 0) $error++;
// End call triggers
if (!$error) {
$this->db->commit();
@@ -3266,7 +3300,6 @@ class OrderLine extends CommonOrderLine
else
{
$this->error=$this->db->lasterror();
dol_syslog("OrderLine::delete ".$this->error, LOG_ERR);
return -1;
}
}
@@ -3283,7 +3316,7 @@ class OrderLine extends CommonOrderLine
$error=0;
dol_syslog("OrderLine::insert rang=".$this->rang);
dol_syslog(get_class($this)."::insert rang=".$this->rang);
// Clean parameters
if (empty($this->tva_tx)) $this->tva_tx=0;
@@ -3351,7 +3384,7 @@ class OrderLine extends CommonOrderLine
$sql.= " ".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null");
$sql.= ')';
dol_syslog(get_class($this)."::insert sql=".$sql, LOG_DEBUG);
dol_syslog(get_class($this)."::insert", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
@@ -3369,12 +3402,10 @@ class OrderLine extends CommonOrderLine
if (! $notrigger)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('LINEORDER_INSERT',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
// Call trigger
$result=$this->call_trigger('LINEORDER_INSERT',$user);
if ($result < 0) $error++;
// End call triggers
}
if (!$error) {
@@ -3393,7 +3424,6 @@ class OrderLine extends CommonOrderLine
else
{
$this->error=$this->db->error();
dol_syslog(get_class($this)."::insert Error ".$this->error, LOG_ERR);
$this->db->rollback();
return -2;
}
@@ -3471,7 +3501,7 @@ class OrderLine extends CommonOrderLine
if (! empty($this->rang)) $sql.= ", rang=".$this->rang;
$sql.= " WHERE rowid = ".$this->rowid;
dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
@@ -3487,12 +3517,10 @@ class OrderLine extends CommonOrderLine
if (! $notrigger)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result = $interface->run_triggers('LINEORDER_UPDATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
// Call trigger
$result=$this->call_trigger('LINEORDER_UPDATE',$user);
if ($result < 0) $error++;
// End call triggers
}
if (!$error) {
@@ -3511,7 +3539,6 @@ class OrderLine extends CommonOrderLine
else
{
$this->error=$this->db->error();
dol_syslog(get_class($this)."::update Error ".$this->error, LOG_ERR);
$this->db->rollback();
return -2;
}
@@ -3539,7 +3566,7 @@ class OrderLine extends CommonOrderLine
$sql.= ",total_ttc='".price2num($this->total_ttc)."'";
$sql.= " WHERE rowid = ".$this->rowid;
dol_syslog("OrderLine::update_total sql=$sql");
dol_syslog("OrderLine::update_total", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
@@ -3550,7 +3577,6 @@ class OrderLine extends CommonOrderLine
else
{
$this->error=$this->db->error();
dol_syslog("OrderLine::update_total Error ".$this->error, LOG_ERR);
$this->db->rollback();
return -2;
}

View File