USe common name for triggers CONTRACT_SERVICE_ACTIVATE into

LINECONTRACT_ACTIVATE and CONTRACT_SERVICE_CLOSE into LINECONTRACT_CLOSE
This commit is contained in:
Laurent Destailleur 2018-02-16 01:19:31 +01:00
parent 91c8dbcc48
commit 540e3d6dc5
3 changed files with 41 additions and 23 deletions

View File

@ -10,7 +10,9 @@ WARNING:
Following changes may create regressions for some external modules, but were necessary to make Dolibarr better: Following changes may create regressions for some external modules, but were necessary to make Dolibarr better:
* Hook 'maildao' was renamed into 'mail' into the method sendfile that send emails, and method was renamed from * Hook 'maildao' was renamed into 'mail' into the method sendfile that send emails, and method was renamed from
'doaction' into 'sendMail'. 'doaction' into 'sendMail'.
* Rename trigger CONTRACT_SERVICE_ACTIVATE into LINECONTRACT_ACTIVATE and
CONTRACT_SERVICE_CLOSE into LINECONTRACT_CLOSE
***** ChangeLog for 7.0.0 compared to 6.0.5 ***** ***** ChangeLog for 7.0.0 compared to 6.0.5 *****
For users: For users:

View File

@ -810,18 +810,30 @@ if (empty($reshook))
else if ($action == 'reopen' && $user->rights->contrat->creer) else if ($action == 'reopen' && $user->rights->contrat->creer)
{ {
$result = $object->reopen($user); $result = $object->reopen($user);
if ($result < 0)
{
setEventMessages($object->error, $object->errors, 'errors');
}
} }
// Close all lines // Close all lines
else if ($action == 'confirm_close' && $confirm == 'yes' && $user->rights->contrat->creer) else if ($action == 'confirm_close' && $confirm == 'yes' && $user->rights->contrat->creer)
{ {
$object->closeAll($user); $result = $object->closeAll($user);
if ($result < 0)
{
setEventMessages($object->error, $object->errors, 'errors');
}
} }
// Close all lines // Close all lines
else if ($action == 'confirm_activate' && $confirm == 'yes' && $user->rights->contrat->creer) else if ($action == 'confirm_activate' && $confirm == 'yes' && $user->rights->contrat->creer)
{ {
$object->activateAll($user); $result = $object->activateAll($user);
if ($result < 0)
{
setEventMessages($object->error, $object->errors, 'errors');
}
} }
else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->contrat->supprimer) else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->contrat->supprimer)

View File

@ -272,7 +272,8 @@ class Contrat extends CommonObject
// Load lines // Load lines
$this->fetch_lines(); $this->fetch_lines();
$ok=true; $error=0;
foreach($this->lines as $contratline) foreach($this->lines as $contratline)
{ {
// Open lines not already open // Open lines not already open
@ -281,26 +282,27 @@ class Contrat extends CommonObject
$result = $contratline->active_line($user, $date_start, -1); $result = $contratline->active_line($user, $date_start, -1);
if ($result < 0) if ($result < 0)
{ {
$ok=false; $error++;
$this->errors = $contratline->error;
$this->errors = $contratline->errors;
break; break;
} }
} }
} }
if ($this->statut == 0) if (! $error && $this->statut == 0)
{ {
$result=$this->validate($user); $result=$this->validate($user);
if ($result < 0) $ok=false; if ($result < 0) $error++;
} }
if ($ok) if (! $error)
{ {
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
else else
{ {
dol_print_error($this->db,'Error in activateAll function');
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
@ -310,7 +312,7 @@ class Contrat extends CommonObject
* Close all lines of a contract * Close all lines of a contract
* *
* @param User $user Object User making action * @param User $user Object User making action
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function closeAll(User $user, $notrigger=0) function closeAll(User $user, $notrigger=0)
@ -322,7 +324,8 @@ class Contrat extends CommonObject
$now = dol_now(); $now = dol_now();
$ok=true; $error = 0;
foreach($this->lines as $contratline) foreach($this->lines as $contratline)
{ {
// Close lines not already closed // Close lines not already closed
@ -331,29 +334,30 @@ class Contrat extends CommonObject
$contratline->date_cloture=$now; $contratline->date_cloture=$now;
$contratline->fk_user_cloture=$user->id; $contratline->fk_user_cloture=$user->id;
$contratline->statut='5'; $contratline->statut='5';
$result=$contratline->update($user); $result=$contratline->close_line($user, $now);
if ($result < 0) if ($result < 0)
{ {
$ok=false; $error++;
$this->errors = $contratline->error;
$this->errors = $contratline->errors;
break; break;
} }
} }
} }
if ($this->statut == 0) if (! $error && $this->statut == 0)
{ {
$result=$this->validate($user, '', $notrigger); $result=$this->validate($user, '', $notrigger);
if ($result < 0) $ok=false; if ($result < 0) $error++;
} }
if ($ok) if (! $error)
{ {
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
else else
{ {
dol_print_error($this->db,'Error in closeAll function');
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
@ -3122,7 +3126,7 @@ class ContratLigne extends CommonObjectLine
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) { if ($resql) {
// Call trigger // Call trigger
$result = $this->call_trigger('CONTRACT_SERVICE_ACTIVATE', $user); $result = $this->call_trigger('LINECONTRACT_ACTIVATE', $user);
if ($result < 0) { if ($result < 0) {
$error++; $error++;
$this->db->rollback(); $this->db->rollback();
@ -3142,10 +3146,10 @@ class ContratLigne extends CommonObjectLine
/** /**
* Close a contract line * Close a contract line
* *
* @param User $user Objet User who close contract * @param User $user Objet User who close contract
* @param int $date_end Date end * @param int $date_end Date end
* @param string $comment A comment typed by user * @param string $comment A comment typed by user
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function close_line($user, $date_end, $comment = '') function close_line($user, $date_end, $comment = '')
{ {
@ -3171,7 +3175,7 @@ class ContratLigne extends CommonObjectLine
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) { if ($resql) {
// Call trigger // Call trigger
$result = $this->call_trigger('CONTRACT_SERVICE_CLOSE', $user); $result = $this->call_trigger('LINECONTRACT_CLOSE', $user);
if ($result < 0) { if ($result < 0) {
$error++; $error++;
$this->db->rollback(); $this->db->rollback();