diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 64fd8fdef7c..8dd2b47fd48 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -71,6 +71,7 @@ $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); $cancel = GETPOST('cancel', 'alpha'); $backtopage = GETPOST('backtopage', 'alpha'); +$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); $socid = GETPOSTINT('socid'); $id = GETPOSTINT('id'); @@ -129,6 +130,7 @@ $permissiontodelete = ($user->hasRight('contrat', 'creer') && $object->status == $permissiontoadd = $user->hasRight('contrat', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php $permissiontoedit = $permissiontoadd; $permissiontoactivate = $user->hasRight('contrat', 'activer'); +$permissiontodisable = $user->hasRight('contrat', 'desactiver'); // TODO use same than $permissiontoactivate $permissiontoeditextra = $permissiontoadd; if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) { // For action 'update_extras', is there a specific permission set for the attribute to update @@ -218,7 +220,7 @@ if (empty($reshook)) { } else { $mesg = $object->error; } - } elseif ($action == 'confirm_closeline' && $confirm == 'yes' && $permissiontoactivate) { + } elseif ($action == 'confirm_closeline' && $confirm == 'yes' && $permissiontodisable) { $date_end = ''; if (GETPOST('endmonth') && GETPOST('endday') && GETPOST('endyear')) { $date_end = dol_mktime(GETPOSTINT('endhour'), GETPOSTINT('endmin'), 0, GETPOSTINT('endmonth'), GETPOSTINT('endday'), GETPOSTINT('endyear')); @@ -910,13 +912,13 @@ if (empty($reshook)) { if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } - } elseif ($action == 'confirm_close' && $confirm == 'yes' && $user->hasRight('contrat', 'creer')) { + } elseif ($action == 'confirm_close' && $confirm == 'yes' && $permissiontodisable) { // Close all lines $result = $object->closeAll($user); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } - } elseif ($action == 'confirm_activate' && $confirm == 'yes' && $user->hasRight('contrat', 'creer')) { + } elseif ($action == 'confirm_activate' && $confirm == 'yes' && $permissiontoactivate) { $date_start = dol_mktime(12, 0, 0, GETPOSTINT('d_startmonth'), GETPOSTINT('d_startday'), GETPOSTINT('d_startyear')); $date_end = dol_mktime(12, 0, 0, GETPOSTINT('d_endmonth'), GETPOSTINT('d_endday'), GETPOSTINT('d_endyear')); $comment = GETPOST('comment', 'alpha'); @@ -924,7 +926,7 @@ if (empty($reshook)) { if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } - } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('contrat', 'supprimer')) { + } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) { $result = $object->delete($user); if ($result >= 0) { header("Location: list.php?restore_lastsearch_values=1"); @@ -932,7 +934,7 @@ if (empty($reshook)) { } else { setEventMessages($object->error, $object->errors, 'errors'); } - } elseif ($action == 'confirm_move' && $confirm == 'yes' && $user->hasRight('contrat', 'creer')) { + } elseif ($action == 'confirm_move' && $confirm == 'yes' && $permissiontoedit) { if (GETPOST('newcid') > 0) { $contractline = new ContratLigne($db); $result = $contractline->fetch(GETPOSTINT('lineid')); @@ -1996,14 +1998,14 @@ if ($action == 'create') { } // Area with status and activation info of line - if ($object->statut > 0) { + if ($object->status > 0) { print ''; print ''; print ''; print '
'.$langs->trans("ServiceStatus").': '.$object->lines[$cursorline - 1]->getLibStatut(4).''; if ($user->socid == 0) { - if ($object->statut > 0 && $action != 'activateline' && $action != 'unactivateline' && is_object($objp)) { + if ($object->status > 0 && $action != 'activateline' && $action != 'unactivateline' && is_object($objp)) { $tmpaction = 'activateline'; $tmpactionpicto = 'play'; $tmpactiontext = $langs->trans("Activate"); @@ -2059,7 +2061,7 @@ if ($action == 'create') { } // Form to activate line - if ($user->hasRight('contrat', 'activer') && $action == 'activateline' && $object->lines[$cursorline - 1]->id == GETPOSTINT('ligne') && is_object($objp)) { + if ($permissiontoactivate && $action == 'activateline' && $object->lines[$cursorline - 1]->id == GETPOSTINT('ligne') && is_object($objp)) { print '
'; print ''; print ''; @@ -2116,10 +2118,8 @@ if ($action == 'create') { print '
'; } - if ($user->hasRight('contrat', 'activer') && $action == 'unactivateline' && $object->lines[$cursorline - 1]->id == GETPOSTINT('ligne') && is_object($objp)) { - /** - * Disable a contract line - */ + // Form to disable a contract line + if ($permissiontodisable && $action == 'unactivateline' && $object->lines[$cursorline - 1]->id == GETPOSTINT('ligne') && is_object($objp)) { print ''."\n"; print '
'; print ''; @@ -2182,7 +2182,7 @@ if ($action == 'create') { } // Form to add new line - if ($user->hasRight('contrat', 'creer') && ($object->statut == 0)) { + if ($user->hasRight('contrat', 'creer') && ($object->status == 0)) { $dateSelector = 1; print "\n"; @@ -2317,7 +2317,7 @@ if ($action == 'create') { 'url' => '/contrat/card.php?id='.$object->id.'&action=activate&token='.newToken(), 'label' => $langs->trans('ActivateAllContracts'), 'lang' => 'bills', - 'perm' => $user->hasRight('contrat', 'activer'), + 'perm' => $permissiontoactivate, 'enabled' => true, ); } @@ -2326,7 +2326,7 @@ if ($action == 'create') { 'url' => '/contrat/card.php?id='.$object->id.'&action=close&token='.newToken(), 'label' => $langs->trans('CloseAllContracts'), 'lang' => 'bills', - 'perm' => $user->hasRight('contrat', 'desactiver') ? true : false, + 'perm' => $permissiontodisable, 'enabled' => true, ); } diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index c4bdbd72e4f..56e08c43a7b 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -470,9 +470,12 @@ class Contrat extends CommonObject */ public function closeAll(User $user, $notrigger = 0, $comment = '') { + dol_syslog("closeAll begin", LOG_DEBUG, 1); + $this->db->begin(); // Load lines + // TODO Should be useless if object was fetched without the noline param. $this->fetch_lines(); $now = dol_now(); @@ -498,7 +501,7 @@ class Contrat extends CommonObject } } - if (!$error && $this->statut == 0) { + if (!$error && $this->status == 0) { $result = $this->validate($user, '', $notrigger); if ($result < 0) { $error++; @@ -507,9 +510,15 @@ class Contrat extends CommonObject if (!$error) { $this->db->commit(); + + dol_syslog("closeAll end", LOG_DEBUG, -1); + return 1; } else { $this->db->rollback(); + + dol_syslog("closeAll end", LOG_DEBUG, -1); + return -1; } } @@ -739,6 +748,7 @@ class Contrat extends CommonObject } dol_syslog(get_class($this)."::fetch", LOG_DEBUG); + $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql);