mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-08 00:52:01 +01:00
Merge pull request #6017 from GPCsolutions/develop-5325
FIX #5325 contract service triggers
This commit is contained in:
@@ -141,6 +141,12 @@ class Contrat extends CommonObject
|
||||
*/
|
||||
var $lines=array();
|
||||
|
||||
/**
|
||||
* Maps ContratLigne IDs to $this->lines indexes
|
||||
* @var int[]
|
||||
*/
|
||||
protected $lines_id_index_mapper=array();
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -221,38 +227,7 @@ class Contrat extends CommonObject
|
||||
*/
|
||||
function active_line($user, $line_id, $date, $date_end='', $comment='')
|
||||
{
|
||||
global $langs,$conf;
|
||||
|
||||
$error=0;
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET statut = 4,";
|
||||
$sql.= " date_ouverture = ".(dol_strlen($date)!=0?"'".$this->db->idate($date)."'":"null").",";
|
||||
$sql.= " date_fin_validite = ".(dol_strlen($date_end)!=0?"'".$this->db->idate($date_end)."'":"null").",";
|
||||
$sql.= " fk_user_ouverture = ".$user->id.",";
|
||||
$sql.= " date_cloture = null,";
|
||||
$sql.= " commentaire = '".$this->db->escape($comment)."'";
|
||||
$sql.= " WHERE rowid = ".$line_id . " AND (statut = 0 OR statut = 3 OR statut = 5)";
|
||||
|
||||
dol_syslog(get_class($this)."::active_line", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
// Call trigger
|
||||
$result=$this->call_trigger('CONTRACT_SERVICE_ACTIVATE',$user);
|
||||
if ($result < 0) { $error++; $this->db->rollback(); return -1; }
|
||||
// End call triggers
|
||||
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
$this->lines[$this->lines_id_index_mapper[$line_id]]->active_line($user, $date, $date_end, $comment);
|
||||
}
|
||||
|
||||
|
||||
@@ -267,37 +242,7 @@ class Contrat extends CommonObject
|
||||
*/
|
||||
function close_line($user, $line_id, $date_end, $comment='')
|
||||
{
|
||||
global $langs,$conf;
|
||||
|
||||
$error=0;
|
||||
|
||||
// statut actif : 4
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET statut = 5,";
|
||||
$sql.= " date_cloture = '".$this->db->idate($date_end)."',";
|
||||
$sql.= " fk_user_cloture = ".$user->id.",";
|
||||
$sql.= " commentaire = '".$this->db->escape($comment)."'";
|
||||
$sql.= " WHERE rowid = ".$line_id . " AND statut = 4";
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
// Call trigger
|
||||
$result=$this->call_trigger('CONTRACT_SERVICE_CLOSE',$user);
|
||||
if ($result < 0) { $error++; $this->db->rollback(); return -1; }
|
||||
// End call triggers
|
||||
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
$this->lines[$this->lines_id_index_mapper[$line_id]]->close_line($user, $date_end, $comment);
|
||||
}
|
||||
|
||||
|
||||
@@ -748,6 +693,7 @@ class Contrat extends CommonObject
|
||||
$line->fetch_optionals($line->id,$extralabelsline);
|
||||
|
||||
$this->lines[] = $line;
|
||||
$this->lines_id_index_mapper[$line->id] = key($this->lines);
|
||||
|
||||
//dol_syslog("1 ".$line->desc);
|
||||
//dol_syslog("2 ".$line->product_desc);
|
||||
@@ -852,6 +798,7 @@ class Contrat extends CommonObject
|
||||
|
||||
|
||||
$this->lines[] = $line;
|
||||
$this->lines_id_index_mapper[$line->id] = key($this->lines);
|
||||
|
||||
$total_ttc+=$objp->total_ttc;
|
||||
$total_vat+=$objp->total_tva;
|
||||
@@ -2947,4 +2894,106 @@ class ContratLigne extends CommonObjectLine
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate a contract line
|
||||
*
|
||||
* @param User $user Objet User who activate contract
|
||||
* @param int $date Date d'ouverture
|
||||
* @param int|string $date_end Date fin prevue
|
||||
* @param string $comment A comment typed by user
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function active_line($user, $date, $date_end = '', $comment = '')
|
||||
{
|
||||
global $langs, $conf;
|
||||
|
||||
// Update object
|
||||
$this->date_ouverture = $date;
|
||||
$this->date_fin_validite = $date_end;
|
||||
$this->fk_user_ouverture = $user->id;
|
||||
$this->date_cloture = null;
|
||||
$this->commentaire = $comment;
|
||||
|
||||
$error = 0;
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "UPDATE " . MAIN_DB_PREFIX . "contratdet SET statut = 4,";
|
||||
$sql .= " date_ouverture = " . (dol_strlen($date) != 0 ? "'" . $this->db->idate($date) . "'" : "null") . ",";
|
||||
$sql .= " date_fin_validite = " . (dol_strlen($date_end) != 0 ? "'" . $this->db->idate($date_end) . "'" : "null") . ",";
|
||||
$sql .= " fk_user_ouverture = " . $user->id . ",";
|
||||
$sql .= " date_cloture = null,";
|
||||
$sql .= " commentaire = '" . $this->db->escape($comment) . "'";
|
||||
$sql .= " WHERE rowid = " . $this->id . " AND (statut = 0 OR statut = 3 OR statut = 5)";
|
||||
|
||||
dol_syslog(get_class($this) . "::active_line", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
// Call trigger
|
||||
$result = $this->call_trigger('CONTRACT_SERVICE_ACTIVATE', $user);
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
// End call triggers
|
||||
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
} else {
|
||||
$this->error = $this->db->lasterror();
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a contract line
|
||||
*
|
||||
* @param User $user Objet User who close contract
|
||||
* @param int $date_end Date end
|
||||
* @param string $comment A comment typed by user
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function close_line($user, $date_end, $comment = '')
|
||||
{
|
||||
global $langs, $conf;
|
||||
|
||||
// Update object
|
||||
$this->date_cloture = $date_end;
|
||||
$this->fk_user_cloture = $user->id;
|
||||
$this->commentaire = $comment;
|
||||
|
||||
$error = 0;
|
||||
|
||||
// statut actif : 4
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "UPDATE " . MAIN_DB_PREFIX . "contratdet SET statut = 5,";
|
||||
$sql .= " date_cloture = '" . $this->db->idate($date_end) . "',";
|
||||
$sql .= " fk_user_cloture = " . $user->id . ",";
|
||||
$sql .= " commentaire = '" . $this->db->escape($comment) . "'";
|
||||
$sql .= " WHERE rowid = " . $this->id . " AND statut = 4";
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
// Call trigger
|
||||
$result = $this->call_trigger('CONTRACT_SERVICE_CLOSE', $user);
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
// End call triggers
|
||||
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
} else {
|
||||
$this->error = $this->db->lasterror();
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user