NEW Add a button "Activate all services" on contracts
This commit is contained in:
parent
c6cbf2345d
commit
07fc0ed3ff
@ -752,7 +752,13 @@ if (empty($reshook))
|
||||
// Close all lines
|
||||
else if ($action == 'confirm_close' && $confirm == 'yes' && $user->rights->contrat->creer)
|
||||
{
|
||||
$object->cloture($user);
|
||||
$object->closeAll($user);
|
||||
}
|
||||
|
||||
// Close all lines
|
||||
else if ($action == 'confirm_activate' && $confirm == 'yes' && $user->rights->contrat->creer)
|
||||
{
|
||||
$object->activateAll($user);
|
||||
}
|
||||
|
||||
else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->contrat->supprimer)
|
||||
@ -1313,6 +1319,11 @@ else
|
||||
{
|
||||
print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("CloseAContract"),$langs->trans("ConfirmCloseContract"),"confirm_close",'',0,1);
|
||||
|
||||
}
|
||||
if ($action == 'activate')
|
||||
{
|
||||
print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("ActivateAllOnContract"),$langs->trans("ConfirmActivateAllOnContract"),"confirm_activate",'',0,1);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1617,7 +1628,7 @@ else
|
||||
print $langs->trans("DateStartPlanned").': ';
|
||||
if ($objp->date_debut)
|
||||
{
|
||||
print dol_print_date($db->jdate($objp->date_debut));
|
||||
print dol_print_date($db->jdate($objp->date_debut), 'day');
|
||||
// Warning si date prevu passee et pas en service
|
||||
if ($objp->statut == 0 && $db->jdate($objp->date_debut) < ($now - $conf->contrat->services->inactifs->warning_delay)) {
|
||||
$warning_delay=$conf->contrat->services->inactifs->warning_delay / 3600 / 24;
|
||||
@ -1630,7 +1641,7 @@ else
|
||||
print $langs->trans("DateEndPlanned").': ';
|
||||
if ($objp->date_fin)
|
||||
{
|
||||
print dol_print_date($db->jdate($objp->date_fin));
|
||||
print dol_print_date($db->jdate($objp->date_fin), 'day');
|
||||
if ($objp->statut == 4 && $db->jdate($objp->date_fin) < ($now - $conf->contrat->services->expires->warning_delay)) {
|
||||
$warning_delay=$conf->contrat->services->expires->warning_delay / 3600 / 24;
|
||||
$textlate = $langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($warning_delay) >= 0 ? '+' : '').ceil($warning_delay).' '.$langs->trans("days");
|
||||
@ -1849,21 +1860,21 @@ else
|
||||
// Si pas encore active
|
||||
if (! $objp->date_debut_reelle) {
|
||||
print $langs->trans("DateStartReal").': ';
|
||||
if ($objp->date_debut_reelle) print dol_print_date($objp->date_debut_reelle);
|
||||
if ($objp->date_debut_reelle) print dol_print_date($objp->date_debut_reelle, 'day');
|
||||
else print $langs->trans("ContractStatusNotRunning");
|
||||
}
|
||||
// Si active et en cours
|
||||
if ($objp->date_debut_reelle && ! $objp->date_fin_reelle) {
|
||||
print $langs->trans("DateStartReal").': ';
|
||||
print dol_print_date($objp->date_debut_reelle);
|
||||
print dol_print_date($objp->date_debut_reelle, 'day');
|
||||
}
|
||||
// Si desactive
|
||||
if ($objp->date_debut_reelle && $objp->date_fin_reelle) {
|
||||
print $langs->trans("DateStartReal").': ';
|
||||
print dol_print_date($objp->date_debut_reelle);
|
||||
print dol_print_date($objp->date_debut_reelle, 'day');
|
||||
print ' - ';
|
||||
print $langs->trans("DateEndReal").': ';
|
||||
print dol_print_date($objp->date_fin_reelle);
|
||||
print dol_print_date($objp->date_fin_reelle, 'day');
|
||||
}
|
||||
if (! empty($objp->comment)) print "<br>".$objp->comment;
|
||||
print '</td>';
|
||||
@ -2071,6 +2082,10 @@ else
|
||||
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&socid=' . $object->socid . '&action=clone&object=' . $object->element . '">' . $langs->trans("ToClone") . '</a></div>';
|
||||
}
|
||||
|
||||
if ($object->nbofservicesclosed > 0)
|
||||
{
|
||||
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=activate">'.$langs->trans("ActivateAllContracts").'</a></div>';
|
||||
}
|
||||
if ($object->nbofservicesclosed < $nbofservices)
|
||||
{
|
||||
//if (! $numactive)
|
||||
@ -2121,9 +2136,9 @@ else
|
||||
print $formfile->showdocuments('contract', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang);
|
||||
|
||||
|
||||
// Show links to link elements
|
||||
$linktoelem = $form->showLinkToObjectBlock($object, null, array('contrat'));
|
||||
$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
|
||||
// Show links to link elements
|
||||
$linktoelem = $form->showLinkToObjectBlock($object, null, array('contrat'));
|
||||
$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
|
||||
|
||||
|
||||
print '</div><div class="fichehalfright"><div class="ficheaddleft">';
|
||||
|
||||
@ -247,13 +247,61 @@ class Contrat extends CommonObject
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Open all lines of a contract
|
||||
*
|
||||
* @param User $user Object User making action
|
||||
* @param int|string $date_start Date start (now if empty)
|
||||
* @return void
|
||||
*/
|
||||
function activateAll($user, $date_start='')
|
||||
{
|
||||
if (empty($date_start)) $date_start = dol_now();
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
// Load lines
|
||||
$this->fetch_lines();
|
||||
|
||||
$ok=true;
|
||||
foreach($this->lines as $contratline)
|
||||
{
|
||||
// Open lines not already open
|
||||
if ($contratline->statut != 4)
|
||||
{
|
||||
$result = $contratline->active_line($user, $date_start, -1);
|
||||
if ($result < 0)
|
||||
{
|
||||
$ok=false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->statut == 0)
|
||||
{
|
||||
$result=$this->validate($user);
|
||||
if ($result < 0) $ok=false;
|
||||
}
|
||||
|
||||
if ($ok)
|
||||
{
|
||||
$this->db->commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($this->db,'Error in activateAll function');
|
||||
$this->db->rollback();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close all lines of a contract
|
||||
*
|
||||
* @param User $user Object User making action
|
||||
* @return void
|
||||
*/
|
||||
function cloture($user)
|
||||
function closeAll($user)
|
||||
{
|
||||
$this->db->begin();
|
||||
|
||||
@ -263,7 +311,7 @@ class Contrat extends CommonObject
|
||||
$ok=true;
|
||||
foreach($this->lines as $contratline)
|
||||
{
|
||||
// Close line not already closed
|
||||
// Close lines not already closed
|
||||
if ($contratline->statut != 5)
|
||||
{
|
||||
$contratline->date_cloture=dol_now();
|
||||
@ -290,7 +338,7 @@ class Contrat extends CommonObject
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($this->db,'Error in cloture function');
|
||||
dol_print_error($this->db,'Error in closeAll function');
|
||||
$this->db->rollback();
|
||||
}
|
||||
}
|
||||
@ -920,8 +968,8 @@ class Contrat extends CommonObject
|
||||
{
|
||||
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
|
||||
{
|
||||
$result=$this->insertExtraFields();
|
||||
if ($result < 0)
|
||||
$result=$this->insertExtraFields();
|
||||
if ($result < 0)
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
@ -1361,7 +1409,8 @@ class Contrat extends CommonObject
|
||||
if (empty($info_bits)) $info_bits=0;
|
||||
if (empty($pu_ht) || ! is_numeric($pu_ht)) $pu_ht=0;
|
||||
if (empty($pu_ttc)) $pu_ttc=0;
|
||||
if (empty($txlocaltax1) || ! is_numeric($txlocaltax1)) $txlocaltax1=0;
|
||||
if (empty($txtva) || ! is_numeric($txtva)) $txtva=0;
|
||||
if (empty($txlocaltax1) || ! is_numeric($txlocaltax1)) $txlocaltax1=0;
|
||||
if (empty($txlocaltax2) || ! is_numeric($txlocaltax2)) $txlocaltax2=0;
|
||||
|
||||
if ($price_base_type=='HT')
|
||||
@ -3007,11 +3056,11 @@ class ContratLigne extends CommonObjectLine
|
||||
/**
|
||||
* 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
|
||||
* @param User $user Objet User who activate contract
|
||||
* @param int $date Date activation
|
||||
* @param int|string $date_end Date planned end. Use '-1' to keep it unchanged.
|
||||
* @param string $comment A comment typed by user
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function active_line($user, $date, $date_end = '', $comment = '')
|
||||
{
|
||||
@ -3030,7 +3079,7 @@ class ContratLigne extends CommonObjectLine
|
||||
|
||||
$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") . ",";
|
||||
if ($date_end >= 0) $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) . "'";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user