Fix: Validation of contract lose the new ref into trigger.
Fix: Validation of contract was not using transaction Fix: Validation of contract did not renamed uploaded directory.
This commit is contained in:
parent
a8f784083c
commit
e5bc7d29d0
@ -1788,8 +1788,8 @@ class Facture extends CommonInvoice
|
|||||||
// Rename directory if dir was a temporary ref
|
// Rename directory if dir was a temporary ref
|
||||||
if (preg_match('/^[\(]?PROV/i', $this->ref))
|
if (preg_match('/^[\(]?PROV/i', $this->ref))
|
||||||
{
|
{
|
||||||
// On renomme repertoire facture ($this->ref = ancienne ref, $num = nouvelle ref)
|
// Rename of object directory ($this->ref = old ref, $num = new ref)
|
||||||
// afin de ne pas perdre les fichiers attaches
|
// to not lose the linked files
|
||||||
$facref = dol_sanitizeFileName($this->ref);
|
$facref = dol_sanitizeFileName($this->ref);
|
||||||
$snumfa = dol_sanitizeFileName($num);
|
$snumfa = dol_sanitizeFileName($num);
|
||||||
$dirsource = $conf->facture->dir_output.'/'.$facref;
|
$dirsource = $conf->facture->dir_output.'/'.$facref;
|
||||||
@ -1977,7 +1977,7 @@ class Facture extends CommonInvoice
|
|||||||
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits=0, $fk_remise_except='', $price_base_type='HT', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $origin='', $origin_id=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='',$array_option=0)
|
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits=0, $fk_remise_except='', $price_base_type='HT', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $origin='', $origin_id=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='',$array_option=0)
|
||||||
{
|
{
|
||||||
global $mysoc;
|
global $mysoc;
|
||||||
|
|
||||||
$facid=$this->id;
|
$facid=$this->id;
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::Addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, fk_product=$fk_product,remise_percent=$remise_percent,date_start=$date_start,date_end=$date_end,ventil=$ventil,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type", LOG_DEBUG);
|
dol_syslog(get_class($this)."::Addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, fk_product=$fk_product,remise_percent=$remise_percent,date_start=$date_start,date_end=$date_end,ventil=$ventil,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type", LOG_DEBUG);
|
||||||
@ -2023,9 +2023,9 @@ class Facture extends CommonInvoice
|
|||||||
// qty, pu, remise_percent et txtva
|
// qty, pu, remise_percent et txtva
|
||||||
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
|
// 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.
|
// 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,$mysoc);
|
||||||
|
|
||||||
$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type,'',$localtaxes_type);
|
$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type,'',$localtaxes_type);
|
||||||
$total_ht = $tabprice[0];
|
$total_ht = $tabprice[0];
|
||||||
$total_tva = $tabprice[1];
|
$total_tva = $tabprice[1];
|
||||||
@ -2148,7 +2148,7 @@ class Facture extends CommonInvoice
|
|||||||
function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type=0, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_option=0)
|
function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type=0, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_option=0)
|
||||||
{
|
{
|
||||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
|
||||||
|
|
||||||
global $mysoc;
|
global $mysoc;
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::updateline $rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1, $txlocaltax2, $price_base_type, $info_bits, $type, $fk_parent_line", LOG_DEBUG);
|
dol_syslog(get_class($this)."::updateline $rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1, $txlocaltax2, $price_base_type, $info_bits, $type, $fk_parent_line", LOG_DEBUG);
|
||||||
@ -2176,9 +2176,9 @@ class Facture extends CommonInvoice
|
|||||||
// Calculate total with, without tax and tax from qty, pu, remise_percent and txtva
|
// Calculate total with, without tax and tax from qty, pu, remise_percent and txtva
|
||||||
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
|
// 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.
|
// 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,$mysoc);
|
||||||
|
|
||||||
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type,'',$localtaxes_type);
|
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type,'',$localtaxes_type);
|
||||||
$total_ht = $tabprice[0];
|
$total_ht = $tabprice[0];
|
||||||
$total_tva = $tabprice[1];
|
$total_tva = $tabprice[1];
|
||||||
|
|||||||
@ -274,54 +274,63 @@ class Contrat extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate a contract
|
* Validate a contract
|
||||||
*
|
*
|
||||||
* @param User $user Objet User
|
* @param User $user Objet User
|
||||||
* @return int <0 if KO, >0 if OK
|
* @param string $force_number Reference to force on contract (not implemented yet)
|
||||||
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function validate($user)
|
function validate($user, $force_number='')
|
||||||
{
|
{
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||||
global $langs, $conf;
|
global $langs, $conf;
|
||||||
|
|
||||||
|
$now=dol_now();
|
||||||
|
|
||||||
$error=0;
|
$error=0;
|
||||||
|
dol_syslog(get_class($this).'::validate user='.$user->id.', force_number='.$force_number);
|
||||||
|
|
||||||
// Definition du nom de module de numerotation de commande
|
|
||||||
$soc = new Societe($this->db);
|
|
||||||
$soc->fetch($this->socid);
|
|
||||||
|
|
||||||
// Class of company linked to order
|
$this->db->begin();
|
||||||
$result=$soc->set_as_client();
|
|
||||||
|
$this->fetch_thirdparty();
|
||||||
|
|
||||||
|
// A contract is validated so we can move thirdparty to status customer
|
||||||
|
$result=$this->thirdparty->set_as_client();
|
||||||
|
|
||||||
// Define new ref
|
// Define new ref
|
||||||
if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref)))
|
if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref)))
|
||||||
{
|
{
|
||||||
$num = $this->getNextNumRef($soc);
|
$num = $this->getNextNumRef($this->thirdparty);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$num = $this->ref;
|
$num = $this->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET ref = '".$num."', statut = 1";
|
if ($num)
|
||||||
$sql .= " WHERE rowid = ".$this->id . " AND statut = 0";
|
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
|
||||||
if ($resql)
|
|
||||||
{
|
{
|
||||||
// Appel des triggers
|
$sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET ref = '".$num."', statut = 1";
|
||||||
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
//$sql.= ", fk_user_valid = ".$user->id.", date_valid = '".$this->db->idate($now)."'";
|
||||||
$interface=new Interfaces($this->db);
|
$sql .= " WHERE rowid = ".$this->id . " AND statut = 0";
|
||||||
$result=$interface->run_triggers('CONTRACT_VALIDATE',$this,$user,$langs,$conf);
|
|
||||||
if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
dol_syslog(get_class($this)."::validate sql=".$sql);
|
||||||
// Fin appel triggers
|
$resql = $this->db->query($sql);
|
||||||
|
if (! $resql)
|
||||||
|
{
|
||||||
|
dol_syslog(get_class($this)."::validate Echec update - 10 - sql=".$sql, LOG_ERR);
|
||||||
|
dol_print_error($this->db);
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
|
$this->oldref = '';
|
||||||
|
|
||||||
// Rename directory if dir was a temporary ref
|
// Rename directory if dir was a temporary ref
|
||||||
if (preg_match('/^[\(]?PROV/i', $this->ref))
|
if (preg_match('/^[\(]?PROV/i', $this->ref))
|
||||||
{
|
{
|
||||||
// Rename of propal directory ($this->ref = old ref, $num = new ref)
|
// Rename of object directory ($this->ref = old ref, $num = new ref)
|
||||||
// to not lose the linked files
|
// to not lose the linked files
|
||||||
$facref = dol_sanitizeFileName($this->ref);
|
$facref = dol_sanitizeFileName($this->ref);
|
||||||
$snumfa = dol_sanitizeFileName($num);
|
$snumfa = dol_sanitizeFileName($num);
|
||||||
@ -330,28 +339,56 @@ class Contrat extends CommonObject
|
|||||||
if (file_exists($dirsource))
|
if (file_exists($dirsource))
|
||||||
{
|
{
|
||||||
dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest);
|
dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest);
|
||||||
|
|
||||||
if (@rename($dirsource, $dirdest))
|
if (@rename($dirsource, $dirdest))
|
||||||
{
|
{
|
||||||
|
$this->oldref = $facref;
|
||||||
|
|
||||||
dol_syslog("Rename ok");
|
dol_syslog("Rename ok");
|
||||||
// Deleting old PDF in new rep
|
// Deleting old PDF in new rep
|
||||||
dol_delete_file($conf->contract->dir_output.'/'.$snumfa.'/'.$facref.'*.*');
|
dol_delete_file($conf->contract->dir_output.'/'.$snumfa.'/'.$facref.'*.*');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
// Set new ref and define current statut
|
||||||
|
if (! $error)
|
||||||
{
|
{
|
||||||
return -1;
|
$this->ref = $num;
|
||||||
|
$this->statut=1;
|
||||||
|
$this->brouillon=0;
|
||||||
|
$this->date_validation=$now;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trigger calls
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
// Appel des triggers
|
||||||
|
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
||||||
|
$interface=new Interfaces($this->db);
|
||||||
|
$result=$interface->run_triggers('CONTRACT_VALIDATE',$this,$user,$langs,$conf);
|
||||||
|
if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
||||||
|
// Fin appel triggers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->db->rollback();
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -966,19 +1003,19 @@ class Contrat extends CommonObject
|
|||||||
// qty, pu, remise_percent et txtva
|
// qty, pu, remise_percent et txtva
|
||||||
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
|
// 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.
|
// 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,$mysoc);
|
||||||
|
|
||||||
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, 1,'', $localtaxes_type);
|
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, 1,'', $localtaxes_type);
|
||||||
$total_ht = $tabprice[0];
|
$total_ht = $tabprice[0];
|
||||||
$total_tva = $tabprice[1];
|
$total_tva = $tabprice[1];
|
||||||
$total_ttc = $tabprice[2];
|
$total_ttc = $tabprice[2];
|
||||||
$total_localtax1= $tabprice[9];
|
$total_localtax1= $tabprice[9];
|
||||||
$total_localtax2= $tabprice[10];
|
$total_localtax2= $tabprice[10];
|
||||||
|
|
||||||
$localtax1_type=$localtaxes_type[0];
|
$localtax1_type=$localtaxes_type[0];
|
||||||
$localtax2_type=$localtaxes_type[2];
|
$localtax2_type=$localtaxes_type[2];
|
||||||
|
|
||||||
// TODO A virer
|
// TODO A virer
|
||||||
// Anciens indicateurs: $price, $remise (a ne plus utiliser)
|
// Anciens indicateurs: $price, $remise (a ne plus utiliser)
|
||||||
$remise = 0;
|
$remise = 0;
|
||||||
@ -1114,19 +1151,19 @@ class Contrat extends CommonObject
|
|||||||
// qty, pu, remise_percent et txtva
|
// qty, pu, remise_percent et txtva
|
||||||
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
|
// 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.
|
// 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,$mysoc);
|
||||||
|
|
||||||
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $tvatx, $localtaxtx1, $txlocaltaxtx2, 0, $price_base_type, $info_bits, 1, '', $localtaxes_type);
|
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $tvatx, $localtaxtx1, $txlocaltaxtx2, 0, $price_base_type, $info_bits, 1, '', $localtaxes_type);
|
||||||
$total_ht = $tabprice[0];
|
$total_ht = $tabprice[0];
|
||||||
$total_tva = $tabprice[1];
|
$total_tva = $tabprice[1];
|
||||||
$total_ttc = $tabprice[2];
|
$total_ttc = $tabprice[2];
|
||||||
$total_localtax1= $tabprice[9];
|
$total_localtax1= $tabprice[9];
|
||||||
$total_localtax2= $tabprice[10];
|
$total_localtax2= $tabprice[10];
|
||||||
|
|
||||||
$localtax1_type=$localtaxes_type[0];
|
$localtax1_type=$localtaxes_type[0];
|
||||||
$localtax2_type=$localtaxes_type[2];
|
$localtax2_type=$localtaxes_type[2];
|
||||||
|
|
||||||
// TODO A virer
|
// TODO A virer
|
||||||
// Anciens indicateurs: $price, $remise (a ne plus utiliser)
|
// Anciens indicateurs: $price, $remise (a ne plus utiliser)
|
||||||
$remise = 0;
|
$remise = 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user