NEW : Uniformize code and correct deal with triggers
This commit is contained in:
parent
80d3c68c07
commit
195d6187a3
@ -1610,11 +1610,12 @@ class Propal extends CommonObject
|
|||||||
/**
|
/**
|
||||||
* Define proposal date
|
* Define proposal date
|
||||||
*
|
*
|
||||||
* @param User $user Object user that modify
|
* @param User $user Object user that modify
|
||||||
* @param int $date Date
|
* @param int $date Date
|
||||||
* @return int <0 if KO, >0 if OK
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_date($user, $date)
|
function set_date($user, $date, $notrigger=0)
|
||||||
{
|
{
|
||||||
if (empty($date))
|
if (empty($date))
|
||||||
{
|
{
|
||||||
@ -1625,20 +1626,46 @@ class Propal extends CommonObject
|
|||||||
|
|
||||||
if (! empty($user->rights->propal->creer))
|
if (! empty($user->rights->propal->creer))
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET datep = '".$this->db->idate($date)."'";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET datep = '".$this->db->idate($date)."'";
|
||||||
$sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT;
|
$sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT;
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::set_date", LOG_DEBUG);
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
if ($this->db->query($sql) )
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->date = $date;
|
$this->errors[]=$this->db->error();
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('PROPAL_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->date = $date;
|
||||||
$this->datep = $date; // deprecated
|
$this->datep = $date; // deprecated
|
||||||
return 1;
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->lasterror();
|
foreach($this->errors as $errmsg)
|
||||||
return -1;
|
{
|
||||||
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1646,25 +1673,54 @@ class Propal extends CommonObject
|
|||||||
/**
|
/**
|
||||||
* Define end validity date
|
* Define end validity date
|
||||||
*
|
*
|
||||||
* @param User $user Object user that modify
|
* @param User $user Object user that modify
|
||||||
* @param int $date_fin_validite End of validity date
|
* @param int $date_fin_validite End of validity date
|
||||||
* @return int <0 if KO, >0 if OK
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_echeance($user, $date_fin_validite)
|
function set_echeance($user, $date_fin_validite, $notrigger=0)
|
||||||
{
|
{
|
||||||
if (! empty($user->rights->propal->creer))
|
if (! empty($user->rights->propal->creer))
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fin_validite = ".($date_fin_validite!=''?"'".$this->db->idate($date_fin_validite)."'":'null');
|
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fin_validite = ".($date_fin_validite!=''?"'".$this->db->idate($date_fin_validite)."'":'null');
|
||||||
$sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT;
|
$sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT;
|
||||||
if ($this->db->query($sql) )
|
|
||||||
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->fin_validite = $date_fin_validite;
|
$this->errors[]=$this->db->error();
|
||||||
return 1;
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('PROPAL_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->fin_validite = $date_fin_validite;
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
foreach($this->errors as $errmsg)
|
||||||
return -1;
|
{
|
||||||
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1672,28 +1728,55 @@ class Propal extends CommonObject
|
|||||||
/**
|
/**
|
||||||
* Set delivery date
|
* Set delivery date
|
||||||
*
|
*
|
||||||
* @param User $user Object user that modify
|
* @param User $user Object user that modify
|
||||||
* @param int $date_livraison Delivery date
|
* @param int $date_livraison Delivery date
|
||||||
* @return int <0 if ko, >0 if ok
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
|
* @return int <0 if ko, >0 if ok
|
||||||
*/
|
*/
|
||||||
function set_date_livraison($user, $date_livraison)
|
function set_date_livraison($user, $date_livraison, $notrigger=0)
|
||||||
{
|
{
|
||||||
if (! empty($user->rights->propal->creer))
|
if (! empty($user->rights->propal->creer))
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."propal ";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."propal ";
|
||||||
$sql.= " SET date_livraison = ".($date_livraison!=''?"'".$this->db->idate($date_livraison)."'":'null');
|
$sql.= " SET date_livraison = ".($date_livraison!=''?"'".$this->db->idate($date_livraison)."'":'null');
|
||||||
$sql.= " WHERE rowid = ".$this->id;
|
$sql.= " WHERE rowid = ".$this->id;
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->date_livraison = $date_livraison;
|
$this->errors[]=$this->db->error();
|
||||||
return 1;
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('PROPAL_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->date_livraison = $date_livraison;
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
foreach($this->errors as $errmsg)
|
||||||
dol_syslog(get_class($this)."::set_date_livraison Erreur SQL");
|
{
|
||||||
return -1;
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1703,26 +1786,53 @@ class Propal extends CommonObject
|
|||||||
*
|
*
|
||||||
* @param User $user Object user that modify
|
* @param User $user Object user that modify
|
||||||
* @param int $id Availability id
|
* @param int $id Availability id
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_availability($user, $id)
|
function set_availability($user, $id, $notrigger=0)
|
||||||
{
|
{
|
||||||
if (! empty($user->rights->propal->creer))
|
if (! empty($user->rights->propal->creer))
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."propal ";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."propal ";
|
||||||
$sql.= " SET fk_availability = '".$id."'";
|
$sql.= " SET fk_availability = '".$id."'";
|
||||||
$sql.= " WHERE rowid = ".$this->id;
|
$sql.= " WHERE rowid = ".$this->id;
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->fk_availability = $id;
|
$this->errors[]=$this->db->error();
|
||||||
return 1;
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('PROPAL_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->fk_availability = $id;
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
foreach($this->errors as $errmsg)
|
||||||
dol_syslog(get_class($this)."::set_availability Erreur SQL");
|
{
|
||||||
return -1;
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1732,26 +1842,53 @@ class Propal extends CommonObject
|
|||||||
*
|
*
|
||||||
* @param User $user Object user that modify
|
* @param User $user Object user that modify
|
||||||
* @param int $id Input reason id
|
* @param int $id Input reason id
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_demand_reason($user, $id)
|
function set_demand_reason($user, $id, $notrigger=0)
|
||||||
{
|
{
|
||||||
if (! empty($user->rights->propal->creer))
|
if (! empty($user->rights->propal->creer))
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."propal ";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."propal ";
|
||||||
$sql.= " SET fk_input_reason = '".$id."'";
|
$sql.= " SET fk_input_reason = '".$id."'";
|
||||||
$sql.= " WHERE rowid = ".$this->id;
|
$sql.= " WHERE rowid = ".$this->id;
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->fk_input_reason = $id;
|
$this->errors[]=$this->db->error();
|
||||||
return 1;
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('PROPAL_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->fk_input_reason = $id;
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
foreach($this->errors as $errmsg)
|
||||||
dol_syslog(get_class($this)."::set_demand_reason Erreur SQL");
|
{
|
||||||
return -1;
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1761,26 +1898,52 @@ class Propal extends CommonObject
|
|||||||
*
|
*
|
||||||
* @param User $user Object user that modify
|
* @param User $user Object user that modify
|
||||||
* @param string $ref_client Customer reference
|
* @param string $ref_client Customer reference
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int <0 if ko, >0 if ok
|
* @return int <0 if ko, >0 if ok
|
||||||
*/
|
*/
|
||||||
function set_ref_client($user, $ref_client)
|
function set_ref_client($user, $ref_client, $notrigger=0)
|
||||||
{
|
{
|
||||||
if (! empty($user->rights->propal->creer))
|
if (! empty($user->rights->propal->creer))
|
||||||
{
|
{
|
||||||
dol_syslog('Propale::set_ref_client this->id='.$this->id.', ref_client='.$ref_client);
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET ref_client = '.(empty($ref_client) ? 'NULL' : '\''.$this->db->escape($ref_client).'\'');
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET ref_client = '.(empty($ref_client) ? 'NULL' : '\''.$this->db->escape($ref_client).'\'');
|
||||||
$sql.= ' WHERE rowid = '.$this->id;
|
$sql.= ' WHERE rowid = '.$this->id;
|
||||||
if ($this->db->query($sql) )
|
|
||||||
|
dol_syslog(__METHOD__.' $this->id='.$this->id.', ref_client='.$ref_client, LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->ref_client = $ref_client;
|
$this->errors[]=$this->db->error();
|
||||||
return 1;
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('PROPAL_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->ref_client = $ref_client;
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
foreach($this->errors as $errmsg)
|
||||||
dol_syslog('Propale::set_ref_client Erreur '.$this->error.' - '.$sql);
|
{
|
||||||
return -2;
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1793,10 +1956,11 @@ class Propal extends CommonObject
|
|||||||
* Set an overall discount on the proposal
|
* Set an overall discount on the proposal
|
||||||
*
|
*
|
||||||
* @param User $user Object user that modify
|
* @param User $user Object user that modify
|
||||||
* @param double $remise Amount discount
|
* @param double $remise Amount discount
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int <0 if ko, >0 if ok
|
* @return int <0 if ko, >0 if ok
|
||||||
*/
|
*/
|
||||||
function set_remise_percent($user, $remise)
|
function set_remise_percent($user, $remise, $notrigger=0)
|
||||||
{
|
{
|
||||||
$remise=trim($remise)?trim($remise):0;
|
$remise=trim($remise)?trim($remise):0;
|
||||||
|
|
||||||
@ -1804,19 +1968,46 @@ class Propal extends CommonObject
|
|||||||
{
|
{
|
||||||
$remise = price2num($remise);
|
$remise = price2num($remise);
|
||||||
|
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET remise_percent = ".$remise;
|
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET remise_percent = ".$remise;
|
||||||
$sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT;
|
$sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT;
|
||||||
|
|
||||||
if ($this->db->query($sql) )
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->remise_percent = $remise;
|
$this->errors[]=$this->db->error();
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('PROPAL_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->remise_percent = $remise;
|
||||||
$this->update_price(1);
|
$this->update_price(1);
|
||||||
return 1;
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
foreach($this->errors as $errmsg)
|
||||||
return -1;
|
{
|
||||||
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1825,11 +2016,12 @@ class Propal extends CommonObject
|
|||||||
/**
|
/**
|
||||||
* Set an absolute overall discount on the proposal
|
* Set an absolute overall discount on the proposal
|
||||||
*
|
*
|
||||||
* @param User $user Object user that modify
|
* @param User $user Object user that modify
|
||||||
* @param double $remise Amount discount
|
* @param double $remise Amount discount
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int <0 if ko, >0 if ok
|
* @return int <0 if ko, >0 if ok
|
||||||
*/
|
*/
|
||||||
function set_remise_absolue($user, $remise)
|
function set_remise_absolue($user, $remise, $notrigger=0)
|
||||||
{
|
{
|
||||||
$remise=trim($remise)?trim($remise):0;
|
$remise=trim($remise)?trim($remise):0;
|
||||||
|
|
||||||
@ -1837,20 +2029,47 @@ class Propal extends CommonObject
|
|||||||
{
|
{
|
||||||
$remise = price2num($remise);
|
$remise = price2num($remise);
|
||||||
|
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."propal ";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."propal ";
|
||||||
$sql.= " SET remise_absolue = ".$remise;
|
$sql.= " SET remise_absolue = ".$remise;
|
||||||
$sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT;
|
$sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT;
|
||||||
|
|
||||||
if ($this->db->query($sql) )
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->remise_absolue = $remise;
|
$this->errors[]=$this->db->error();
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('PROPAL_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->remise_absolue = $remise;
|
||||||
$this->update_price(1);
|
$this->update_price(1);
|
||||||
return 1;
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
foreach($this->errors as $errmsg)
|
||||||
return -1;
|
{
|
||||||
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1924,9 +2143,10 @@ class Propal extends CommonObject
|
|||||||
* @param User $user Object user that close
|
* @param User $user Object user that close
|
||||||
* @param int $statut Statut
|
* @param int $statut Statut
|
||||||
* @param string $note Comment
|
* @param string $note Comment
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function cloture($user, $statut, $note)
|
function cloture($user, $statut, $note, $notrigger=0)
|
||||||
{
|
{
|
||||||
global $langs,$conf;
|
global $langs,$conf;
|
||||||
|
|
||||||
@ -1981,10 +2201,13 @@ class Propal extends CommonObject
|
|||||||
$this->generateDocument($modelpdf, $outputlangs);
|
$this->generateDocument($modelpdf, $outputlangs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call trigger
|
if (! $notrigger && empty($error))
|
||||||
$result=$this->call_trigger($trigger_name,$user);
|
{
|
||||||
if ($result < 0) { $error++; }
|
// Call trigger
|
||||||
// End call triggers
|
$result=$this->call_trigger($trigger_name,$user);
|
||||||
|
if ($result < 0) { $error++; }
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! $error )
|
if ( ! $error )
|
||||||
{
|
{
|
||||||
@ -2010,20 +2233,51 @@ class Propal extends CommonObject
|
|||||||
/**
|
/**
|
||||||
* Class invoiced the Propal
|
* Class invoiced the Propal
|
||||||
*
|
*
|
||||||
* @return int <0 si ko, >0 si ok
|
* @param User $user Object user
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
|
* @return int <0 si ko, >0 si ok
|
||||||
*/
|
*/
|
||||||
function classifyBilled()
|
function classifyBilled(User $user, $notrigger=0)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET fk_statut = '.self::STATUS_BILLED;
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET fk_statut = '.self::STATUS_BILLED;
|
||||||
$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > '.self::STATUS_DRAFT.' ;';
|
$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > '.self::STATUS_DRAFT.' ;';
|
||||||
if ($this->db->query($sql) )
|
|
||||||
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
|
{
|
||||||
|
$this->errors[]=$this->db->error();
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('PROPAL_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
{
|
{
|
||||||
$this->statut=self::STATUS_BILLED;
|
$this->statut=self::STATUS_BILLED;
|
||||||
return 1;
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dol_print_error($this->db);
|
foreach($this->errors as $errmsg)
|
||||||
|
{
|
||||||
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2032,7 +2286,7 @@ class Propal extends CommonObject
|
|||||||
*
|
*
|
||||||
* @return int <0 si ko, >0 si ok
|
* @return int <0 si ko, >0 si ok
|
||||||
* @deprecated
|
* @deprecated
|
||||||
* @see classifyBilled()
|
* @see classifyBilled()
|
||||||
*/
|
*/
|
||||||
function classer_facturee()
|
function classer_facturee()
|
||||||
{
|
{
|
||||||
@ -2046,22 +2300,51 @@ class Propal extends CommonObject
|
|||||||
* Set draft status
|
* Set draft status
|
||||||
*
|
*
|
||||||
* @param User $user Object user that modify
|
* @param User $user Object user that modify
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_draft($user)
|
function set_draft($user, $notrigger=0)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = ".self::STATUS_DRAFT;
|
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = ".self::STATUS_DRAFT;
|
||||||
$sql.= " WHERE rowid = ".$this->id;
|
$sql.= " WHERE rowid = ".$this->id;
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->statut = self::STATUS_DRAFT;
|
$this->errors[]=$this->db->error();
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('PROPAL_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->statut = self::STATUS_DRAFT;
|
||||||
$this->brouillon = 1;
|
$this->brouillon = 1;
|
||||||
return 1;
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return -1;
|
foreach($this->errors as $errmsg)
|
||||||
|
{
|
||||||
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2364,32 +2647,61 @@ class Propal extends CommonObject
|
|||||||
* Change the delivery time
|
* Change the delivery time
|
||||||
*
|
*
|
||||||
* @param int $availability_id Id of new delivery time
|
* @param int $availability_id Id of new delivery time
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int >0 if OK, <0 if KO
|
* @return int >0 if OK, <0 if KO
|
||||||
*/
|
*/
|
||||||
function availability($availability_id)
|
function availability($availability_id, $notrigger=0)
|
||||||
{
|
{
|
||||||
dol_syslog('Propale::availability('.$availability_id.')');
|
|
||||||
if ($this->statut >= self::STATUS_DRAFT)
|
if ($this->statut >= self::STATUS_DRAFT)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'propal';
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'propal';
|
||||||
$sql .= ' SET fk_availability = '.$availability_id;
|
$sql .= ' SET fk_availability = '.$availability_id;
|
||||||
$sql .= ' WHERE rowid='.$this->id;
|
$sql .= ' WHERE rowid='.$this->id;
|
||||||
if ( $this->db->query($sql) )
|
|
||||||
|
dol_syslog(__METHOD__.' availability('.$availability_id.')', LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->availability_id = $availability_id;
|
$this->errors[]=$this->db->error();
|
||||||
return 1;
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('PROPAL_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->availability_id = $availability_id;
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dol_syslog('Propale::availability Erreur '.$sql.' - '.$this->db->error());
|
foreach($this->errors as $errmsg)
|
||||||
$this->error=$this->db->error();
|
{
|
||||||
return -1;
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dol_syslog('Propale::availability, etat propale incompatible');
|
$error_str='Propal status do not meet requirement '.$this->statut;
|
||||||
$this->error='Etat propale incompatible '.$this->statut;
|
dol_syslog(__METHOD__.$error_str, LOG_ERR);
|
||||||
|
$this->error=$error_str;
|
||||||
|
$this->errors[]= $this->error;
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2398,32 +2710,61 @@ class Propal extends CommonObject
|
|||||||
* Change source demand
|
* Change source demand
|
||||||
*
|
*
|
||||||
* @param int $demand_reason_id Id of new source demand
|
* @param int $demand_reason_id Id of new source demand
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int >0 si ok, <0 si ko
|
* @return int >0 si ok, <0 si ko
|
||||||
*/
|
*/
|
||||||
function demand_reason($demand_reason_id)
|
function demand_reason($demand_reason_id, $notrigger=0)
|
||||||
{
|
{
|
||||||
dol_syslog('Propale::demand_reason('.$demand_reason_id.')');
|
|
||||||
if ($this->statut >= self::STATUS_DRAFT)
|
if ($this->statut >= self::STATUS_DRAFT)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'propal';
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'propal';
|
||||||
$sql .= ' SET fk_input_reason = '.$demand_reason_id;
|
$sql .= ' SET fk_input_reason = '.$demand_reason_id;
|
||||||
$sql .= ' WHERE rowid='.$this->id;
|
$sql .= ' WHERE rowid='.$this->id;
|
||||||
if ( $this->db->query($sql) )
|
|
||||||
|
dol_syslog(__METHOD__.' demand_reason('.$demand_reason_id.')', LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->demand_reason_id = $demand_reason_id;
|
$this->errors[]=$this->db->error();
|
||||||
return 1;
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('PROPAL_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->demand_reason_id = $demand_reason_id;
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dol_syslog('Propale::demand_reason Erreur '.$sql.' - '.$this->db->error());
|
foreach($this->errors as $errmsg)
|
||||||
$this->error=$this->db->error();
|
{
|
||||||
return -1;
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dol_syslog('Propale::demand_reason, etat propale incompatible');
|
$error_str='Propal status do not meet requirement '.$this->statut;
|
||||||
$this->error='Etat propale incompatible '.$this->statut;
|
dol_syslog(__METHOD__.$error_str, LOG_ERR);
|
||||||
|
$this->error=$error_str;
|
||||||
|
$this->errors[]= $this->error;
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2507,21 +2848,21 @@ class Propal extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function LibStatut($statut,$mode=1)
|
function LibStatut($statut,$mode=1)
|
||||||
{
|
{
|
||||||
global $langs;
|
global $langs;
|
||||||
$langs->load("propal");
|
$langs->load("propal");
|
||||||
|
|
||||||
if ($statut==self::STATUS_DRAFT) $statuttrans='statut0';
|
if ($statut==self::STATUS_DRAFT) $statuttrans='statut0';
|
||||||
if ($statut==self::STATUS_VALIDATED) $statuttrans='statut1';
|
if ($statut==self::STATUS_VALIDATED) $statuttrans='statut1';
|
||||||
if ($statut==self::STATUS_SIGNED) $statuttrans='statut3';
|
if ($statut==self::STATUS_SIGNED) $statuttrans='statut3';
|
||||||
if ($statut==self::STATUS_NOTSIGNED) $statuttrans='statut5';
|
if ($statut==self::STATUS_NOTSIGNED) $statuttrans='statut5';
|
||||||
if ($statut==self::STATUS_BILLED) $statuttrans='statut6';
|
if ($statut==self::STATUS_BILLED) $statuttrans='statut6';
|
||||||
|
|
||||||
if ($mode == 0) return $this->labelstatut[$statut];
|
if ($mode == 0) return $this->labelstatut[$statut];
|
||||||
if ($mode == 1) return $this->labelstatut_short[$statut];
|
if ($mode == 1) return $this->labelstatut_short[$statut];
|
||||||
if ($mode == 2) return img_picto($this->labelstatut_short[$statut], $statuttrans).' '.$this->labelstatut_short[$statut];
|
if ($mode == 2) return img_picto($this->labelstatut_short[$statut], $statuttrans).' '.$this->labelstatut_short[$statut];
|
||||||
if ($mode == 3) return img_picto($this->labelstatut[$statut], $statuttrans);
|
if ($mode == 3) return img_picto($this->labelstatut[$statut], $statuttrans);
|
||||||
if ($mode == 4) return img_picto($this->labelstatut[$statut],$statuttrans).' '.$this->labelstatut[$statut];
|
if ($mode == 4) return img_picto($this->labelstatut[$statut],$statuttrans).' '.$this->labelstatut[$statut];
|
||||||
if ($mode == 5) return '<span class="hideonsmartphone">'.$this->labelstatut_short[$statut].' </span>'.img_picto($this->labelstatut_short[$statut],$statuttrans);
|
if ($mode == 5) return '<span class="hideonsmartphone">'.$this->labelstatut_short[$statut].' </span>'.img_picto($this->labelstatut_short[$statut],$statuttrans);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -469,7 +469,7 @@ class Commande extends CommonOrder
|
|||||||
|
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
// Call trigger
|
// Call trigger
|
||||||
$result=$this->call_trigger('ORDER_SETDRAFT',$user);
|
$result=$this->call_trigger('ORDER_UNVALIDATE',$user);
|
||||||
if ($result < 0) $error++;
|
if ($result < 0) $error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2044,7 +2044,7 @@ class Commande extends CommonOrder
|
|||||||
*
|
*
|
||||||
* @param User $user User qui positionne la remise
|
* @param User $user User qui positionne la remise
|
||||||
* @param float $remise Discount (percent)
|
* @param float $remise Discount (percent)
|
||||||
* @param int $notrigger Not Trigger
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_remise($user, $remise, $notrigger=0)
|
function set_remise($user, $remise, $notrigger=0)
|
||||||
@ -2063,6 +2063,7 @@ class Commande extends CommonOrder
|
|||||||
$sql.= ' SET remise_percent = '.$remise;
|
$sql.= ' SET remise_percent = '.$remise;
|
||||||
$sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = '.self::STATUS_DRAFT.' ;';
|
$sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = '.self::STATUS_DRAFT.' ;';
|
||||||
|
|
||||||
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if (!$resql)
|
if (!$resql)
|
||||||
{
|
{
|
||||||
@ -2105,7 +2106,7 @@ class Commande extends CommonOrder
|
|||||||
*
|
*
|
||||||
* @param User $user User qui positionne la remise
|
* @param User $user User qui positionne la remise
|
||||||
* @param float $remise Discount
|
* @param float $remise Discount
|
||||||
* @param int $notrigger Not Trigger
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_remise_absolue($user, $remise, $notrigger=0)
|
function set_remise_absolue($user, $remise, $notrigger=0)
|
||||||
@ -2125,7 +2126,6 @@ class Commande extends CommonOrder
|
|||||||
$sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = '.self::STATUS_DRAFT.' ;';
|
$sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = '.self::STATUS_DRAFT.' ;';
|
||||||
|
|
||||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if (!$resql)
|
if (!$resql)
|
||||||
{
|
{
|
||||||
@ -2168,14 +2168,13 @@ class Commande extends CommonOrder
|
|||||||
*
|
*
|
||||||
* @param User $user Object user making change
|
* @param User $user Object user making change
|
||||||
* @param int $date Date
|
* @param int $date Date
|
||||||
* @param int $notrigger Not Trigger
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_date($user, $date, $notrigger=0)
|
function set_date($user, $date, $notrigger=0)
|
||||||
{
|
{
|
||||||
if ($user->rights->commande->creer)
|
if ($user->rights->commande->creer)
|
||||||
{
|
{
|
||||||
|
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
@ -2229,13 +2228,17 @@ class Commande extends CommonOrder
|
|||||||
*
|
*
|
||||||
* @param User $user Objet utilisateur qui modifie
|
* @param User $user Objet utilisateur qui modifie
|
||||||
* @param int $date_livraison Date de livraison
|
* @param int $date_livraison Date de livraison
|
||||||
* @param int $notrigger Not Trigger
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int <0 si ko, >0 si ok
|
* @return int <0 si ko, >0 si ok
|
||||||
*/
|
*/
|
||||||
function set_date_livraison($user, $date_livraison, $notrigger=0)
|
function set_date_livraison($user, $date_livraison, $notrigger=0)
|
||||||
{
|
{
|
||||||
if ($user->rights->commande->creer)
|
if ($user->rights->commande->creer)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."commande";
|
||||||
$sql.= " SET date_livraison = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null');
|
$sql.= " SET date_livraison = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null');
|
||||||
$sql.= " WHERE rowid = ".$this->id;
|
$sql.= " WHERE rowid = ".$this->id;
|
||||||
@ -2285,13 +2288,17 @@ class Commande extends CommonOrder
|
|||||||
*
|
*
|
||||||
* @param User $user Object user making change
|
* @param User $user Object user making change
|
||||||
* @param int $id If of availability delay
|
* @param int $id If of availability delay
|
||||||
* @param int $notrigger Not Trigger
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_availability($user, $id, $notrigger=0)
|
function set_availability($user, $id, $notrigger=0)
|
||||||
{
|
{
|
||||||
if ($user->rights->commande->creer)
|
if ($user->rights->commande->creer)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande ";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."commande ";
|
||||||
$sql.= " SET fk_availability = '".$id."'";
|
$sql.= " SET fk_availability = '".$id."'";
|
||||||
$sql.= " WHERE rowid = ".$this->id;
|
$sql.= " WHERE rowid = ".$this->id;
|
||||||
@ -2337,13 +2344,18 @@ class Commande extends CommonOrder
|
|||||||
*
|
*
|
||||||
* @param User $user Object user making change
|
* @param User $user Object user making change
|
||||||
* @param int $id Id of source
|
* @param int $id Id of source
|
||||||
* @param int $notrigger Not Trigger
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_demand_reason($user, $id, $notrigger=0)
|
function set_demand_reason($user, $id, $notrigger=0)
|
||||||
{
|
{
|
||||||
if ($user->rights->commande->creer)
|
if ($user->rights->commande->creer)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande ";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."commande ";
|
||||||
$sql.= " SET fk_input_reason = '".$id."'";
|
$sql.= " SET fk_input_reason = '".$id."'";
|
||||||
$sql.= " WHERE rowid = ".$this->id;
|
$sql.= " WHERE rowid = ".$this->id;
|
||||||
@ -2461,7 +2473,7 @@ class Commande extends CommonOrder
|
|||||||
* Update delivery delay
|
* Update delivery delay
|
||||||
*
|
*
|
||||||
* @param int $availability_id Id du nouveau mode
|
* @param int $availability_id Id du nouveau mode
|
||||||
* @param int $notrigger Not Trigger
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int >0 if OK, <0 if KO
|
* @return int >0 if OK, <0 if KO
|
||||||
*/
|
*/
|
||||||
function availability($availability_id, $notrigger=0)
|
function availability($availability_id, $notrigger=0)
|
||||||
@ -2469,6 +2481,10 @@ class Commande extends CommonOrder
|
|||||||
dol_syslog('Commande::availability('.$availability_id.')');
|
dol_syslog('Commande::availability('.$availability_id.')');
|
||||||
if ($this->statut >= self::STATUS_DRAFT)
|
if ($this->statut >= self::STATUS_DRAFT)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande';
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande';
|
||||||
$sql .= ' SET fk_availability = '.$availability_id;
|
$sql .= ' SET fk_availability = '.$availability_id;
|
||||||
$sql .= ' WHERE rowid='.$this->id;
|
$sql .= ' WHERE rowid='.$this->id;
|
||||||
@ -2521,7 +2537,7 @@ class Commande extends CommonOrder
|
|||||||
* Update order demand_reason
|
* Update order demand_reason
|
||||||
*
|
*
|
||||||
* @param int $demand_reason_id Id of new demand
|
* @param int $demand_reason_id Id of new demand
|
||||||
* @param int $notrigger Not Trigger
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int >0 if ok, <0 if ko
|
* @return int >0 if ok, <0 if ko
|
||||||
*/
|
*/
|
||||||
function demand_reason($demand_reason_id, $notrigger=0)
|
function demand_reason($demand_reason_id, $notrigger=0)
|
||||||
@ -2529,6 +2545,10 @@ class Commande extends CommonOrder
|
|||||||
dol_syslog('Commande::demand_reason('.$demand_reason_id.')');
|
dol_syslog('Commande::demand_reason('.$demand_reason_id.')');
|
||||||
if ($this->statut >= self::STATUS_DRAFT)
|
if ($this->statut >= self::STATUS_DRAFT)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande';
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande';
|
||||||
$sql .= ' SET fk_input_reason = '.$demand_reason_id;
|
$sql .= ' SET fk_input_reason = '.$demand_reason_id;
|
||||||
$sql .= ' WHERE rowid='.$this->id;
|
$sql .= ' WHERE rowid='.$this->id;
|
||||||
@ -2582,12 +2602,17 @@ class Commande extends CommonOrder
|
|||||||
*
|
*
|
||||||
* @param User $user User that make change
|
* @param User $user User that make change
|
||||||
* @param string $ref_client Customer ref
|
* @param string $ref_client Customer ref
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_ref_client($user, $ref_client)
|
function set_ref_client($user, $ref_client, $notrigger=0)
|
||||||
{
|
{
|
||||||
if ($user->rights->commande->creer)
|
if ($user->rights->commande->creer)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET';
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET';
|
||||||
$sql.= ' ref_client = '.(empty($ref_client) ? 'NULL' : '\''.$this->db->escape($ref_client).'\'');
|
$sql.= ' ref_client = '.(empty($ref_client) ? 'NULL' : '\''.$this->db->escape($ref_client).'\'');
|
||||||
$sql.= ' WHERE rowid = '.$this->id;
|
$sql.= ' WHERE rowid = '.$this->id;
|
||||||
|
|||||||
@ -1486,25 +1486,54 @@ class Facture extends CommonInvoice
|
|||||||
* Set customer ref
|
* Set customer ref
|
||||||
*
|
*
|
||||||
* @param string $ref_client Customer ref
|
* @param string $ref_client Customer ref
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_ref_client($ref_client)
|
function set_ref_client($ref_client, $notrigger=0)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
|
||||||
if (empty($ref_client))
|
if (empty($ref_client))
|
||||||
$sql .= ' SET ref_client = NULL';
|
$sql .= ' SET ref_client = NULL';
|
||||||
else
|
else
|
||||||
$sql .= ' SET ref_client = \''.$this->db->escape($ref_client).'\'';
|
$sql .= ' SET ref_client = \''.$this->db->escape($ref_client).'\'';
|
||||||
$sql .= ' WHERE rowid = '.$this->id;
|
$sql .= ' WHERE rowid = '.$this->id;
|
||||||
if ($this->db->query($sql))
|
|
||||||
|
dol_syslog(__METHOD__.' this->id='.$this->id.', ref_client='.$ref_client, LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
|
{
|
||||||
|
$this->errors[]=$this->db->error();
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('BILL_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
{
|
{
|
||||||
$this->ref_client = $ref_client;
|
$this->ref_client = $ref_client;
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dol_print_error($this->db);
|
foreach($this->errors as $errmsg)
|
||||||
return -1;
|
{
|
||||||
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2070,7 +2099,7 @@ class Facture extends CommonInvoice
|
|||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
if ($final) {
|
if ($final) {
|
||||||
$this->setFinal();
|
$this->setFinal($user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2760,9 +2789,10 @@ class Facture extends CommonInvoice
|
|||||||
*
|
*
|
||||||
* @param User $user User that set discount
|
* @param User $user User that set discount
|
||||||
* @param double $remise Discount
|
* @param double $remise Discount
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int <0 if ko, >0 if ok
|
* @return int <0 if ko, >0 if ok
|
||||||
*/
|
*/
|
||||||
function set_remise($user, $remise)
|
function set_remise($user, $remise, $notrigger=0)
|
||||||
{
|
{
|
||||||
// Clean parameters
|
// Clean parameters
|
||||||
if (empty($remise)) $remise=0;
|
if (empty($remise)) $remise=0;
|
||||||
@ -2771,21 +2801,48 @@ class Facture extends CommonInvoice
|
|||||||
{
|
{
|
||||||
$remise=price2num($remise);
|
$remise=price2num($remise);
|
||||||
|
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
|
||||||
$sql.= ' SET remise_percent = '.$remise;
|
$sql.= ' SET remise_percent = '.$remise;
|
||||||
$sql.= ' WHERE rowid = '.$this->id;
|
$sql.= ' WHERE rowid = '.$this->id;
|
||||||
$sql.= ' AND fk_statut = '.self::STATUS_DRAFT;
|
$sql.= ' AND fk_statut = '.self::STATUS_DRAFT;
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
|
{
|
||||||
|
$this->errors[]=$this->db->error();
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('BILL_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
{
|
{
|
||||||
$this->remise_percent = $remise;
|
$this->remise_percent = $remise;
|
||||||
$this->update_price(1);
|
$this->update_price(1);
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
foreach($this->errors as $errmsg)
|
||||||
return -1;
|
{
|
||||||
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2796,14 +2853,19 @@ class Facture extends CommonInvoice
|
|||||||
*
|
*
|
||||||
* @param User $user User that set discount
|
* @param User $user User that set discount
|
||||||
* @param double $remise Discount
|
* @param double $remise Discount
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_remise_absolue($user, $remise)
|
function set_remise_absolue($user, $remise, $notrigger=0)
|
||||||
{
|
{
|
||||||
if (empty($remise)) $remise=0;
|
if (empty($remise)) $remise=0;
|
||||||
|
|
||||||
if ($user->rights->facture->creer)
|
if ($user->rights->facture->creer)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$remise=price2num($remise);
|
$remise=price2num($remise);
|
||||||
|
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
|
||||||
@ -2811,18 +2873,39 @@ class Facture extends CommonInvoice
|
|||||||
$sql.= ' WHERE rowid = '.$this->id;
|
$sql.= ' WHERE rowid = '.$this->id;
|
||||||
$sql.= ' AND fk_statut = '.self::STATUS_DRAFT;
|
$sql.= ' AND fk_statut = '.self::STATUS_DRAFT;
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::set_remise_absolue", LOG_DEBUG);
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
|
{
|
||||||
|
$this->errors[]=$this->db->error();
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('BILL_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
{
|
{
|
||||||
$this->remise_absolue = $remise;
|
$this->remise_absolue = $remise;
|
||||||
$this->update_price(1);
|
$this->update_price(1);
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
foreach($this->errors as $errmsg)
|
||||||
return -1;
|
{
|
||||||
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3818,25 +3901,49 @@ class Facture extends CommonInvoice
|
|||||||
/**
|
/**
|
||||||
* Sets the invoice as a final situation
|
* Sets the invoice as a final situation
|
||||||
*
|
*
|
||||||
* @return int 1 if ok, -1 if error
|
* @param User $user Object user
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function setFinal()
|
function setFinal(User $user, $notrigger=0)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$this->situation_final = 1;
|
$this->situation_final = 1;
|
||||||
$sql = 'update ' . MAIN_DB_PREFIX . 'facture set situation_final = ' . $this->situation_final . ' where rowid = ' . $this->id;
|
$sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facture SET situation_final = ' . $this->situation_final . ' where rowid = ' . $this->id;
|
||||||
$resql = $this->db->query($sql);
|
|
||||||
if ($resql) {
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
// FIXME: call triggers MODIFY because we modify invoice
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
|
{
|
||||||
|
$this->errors[]=$this->db->error();
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('BILL_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
}
|
||||||
$this->error = $this->db->lasterror();
|
else
|
||||||
dol_syslog(get_class($this) . "::update Error setFinal " . $sql, LOG_ERR);
|
{
|
||||||
|
foreach($this->errors as $errmsg)
|
||||||
|
{
|
||||||
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1;
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user