Use constant for contract line status

This commit is contained in:
Laurent Destailleur 2018-03-30 15:46:08 +02:00
parent b3a454033e
commit 34c26dffc7

View File

@ -264,6 +264,7 @@ class Contrat extends CommonObject
* @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
* @param string $comment Comment
* @return int <0 if KO, >0 if OK
* @see closeAll
*/
function activateAll($user, $date_start='', $notrigger=0, $comment='')
{
@ -279,7 +280,7 @@ class Contrat extends CommonObject
foreach($this->lines as $contratline)
{
// Open lines not already open
if ($contratline->statut != 4)
if ($contratline->statut != ContratLigne::STATUS_OPEN)
{
$contratline->context = $this->context;
@ -319,6 +320,7 @@ class Contrat extends CommonObject
* @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
* @param string $comment Comment
* @return int <0 if KO, >0 if OK
* @see activateAll
*/
function closeAll(User $user, $notrigger=0, $comment='')
{
@ -334,11 +336,11 @@ class Contrat extends CommonObject
foreach($this->lines as $contratline)
{
// Close lines not already closed
if ($contratline->statut != 5)
if ($contratline->statut != ContratLigne::STATUS_CLOSED)
{
$contratline->date_cloture=$now;
$contratline->fk_user_cloture=$user->id;
$contratline->statut='5';
$contratline->statut=ContratLigne::STATUS_CLOSED;
$result=$contratline->close_line($user, $now, $comment, $notrigger);
if ($result < 0)
{
@ -806,10 +808,10 @@ class Contrat extends CommonObject
//dol_syslog("1 ".$line->desc);
//dol_syslog("2 ".$line->product_desc);
if ($line->statut == 0) $this->nbofserviceswait++;
if ($line->statut == 4 && (empty($line->date_fin_prevue) || $line->date_fin_prevue >= $now)) $this->nbofservicesopened++;
if ($line->statut == 4 && (! empty($line->date_fin_prevue) && $line->date_fin_prevue < $now)) $this->nbofservicesexpired++;
if ($line->statut == 5) $this->nbofservicesclosed++;
if ($line->statut == ContratLigne::STATUS_INITIAL) $this->nbofserviceswait++;
if ($line->statut == ContratLigne::STATUS_OPEN && (empty($line->date_fin_prevue) || $line->date_fin_prevue >= $now)) $this->nbofservicesopened++;
if ($line->statut == ContratLigne::STATUS_OPEN && (! empty($line->date_fin_prevue) && $line->date_fin_prevue < $now)) $this->nbofservicesexpired++;
if ($line->statut == ContratLigne::STATUS_CLOSED) $this->nbofservicesclosed++;
$total_ttc+=$objp->total_ttc; // TODO Not saved into database
$total_vat+=$objp->total_tva;
@ -2518,6 +2520,11 @@ class ContratLigne extends CommonObjectLine
var $fk_user_cloture;
var $commentaire;
const STATUS_INITIAL = 0;
const STATUS_OPEN = 4;
const STATUS_CLOSED = 5;
/**
* Constructor
@ -2556,51 +2563,51 @@ class ContratLigne extends CommonObjectLine
$langs->load("contracts");
if ($mode == 0)
{
if ($statut == 0) { return $langs->trans("ServiceStatusInitial"); }
if ($statut == 4 && $expired == -1) { return $langs->trans("ServiceStatusRunning"); }
if ($statut == 4 && $expired == 0) { return $langs->trans("ServiceStatusNotLate"); }
if ($statut == 4 && $expired == 1) { return $langs->trans("ServiceStatusLate"); }
if ($statut == 5) { return $langs->trans("ServiceStatusClosed"); }
if ($statut == self::STATUS_INITIAL) { return $langs->trans("ServiceStatusInitial"); }
if ($statut == self::STATUS_OPEN && $expired == -1) { return $langs->trans("ServiceStatusRunning"); }
if ($statut == self::STATUS_OPEN && $expired == 0) { return $langs->trans("ServiceStatusNotLate"); }
if ($statut == self::STATUS_OPEN && $expired == 1) { return $langs->trans("ServiceStatusLate"); }
if ($statut == self::STATUS_CLOSED) { return $langs->trans("ServiceStatusClosed"); }
}
if ($mode == 1)
{
if ($statut == 0) { return $langs->trans("ServiceStatusInitial"); }
if ($statut == 4 && $expired == -1) { return $langs->trans("ServiceStatusRunning"); }
if ($statut == 4 && $expired == 0) { return $langs->trans("ServiceStatusNotLateShort"); }
if ($statut == 4 && $expired == 1) { return $langs->trans("ServiceStatusLateShort"); }
if ($statut == 5) { return $langs->trans("ServiceStatusClosed"); }
if ($statut == self::STATUS_INITIAL) { return $langs->trans("ServiceStatusInitial"); }
if ($statut == self::STATUS_OPEN && $expired == -1) { return $langs->trans("ServiceStatusRunning"); }
if ($statut == self::STATUS_OPEN && $expired == 0) { return $langs->trans("ServiceStatusNotLateShort"); }
if ($statut == self::STATUS_OPEN && $expired == 1) { return $langs->trans("ServiceStatusLateShort"); }
if ($statut == self::STATUS_CLOSED) { return $langs->trans("ServiceStatusClosed"); }
}
if ($mode == 2)
{
if ($statut == 0) { return img_picto($langs->trans('ServiceStatusInitial'),'statut0').' '.$langs->trans("ServiceStatusInitial"); }
if ($statut == 4 && $expired == -1) { return img_picto($langs->trans('ServiceStatusRunning'),'statut4').' '.$langs->trans("ServiceStatusRunning"); }
if ($statut == 4 && $expired == 0) { return img_picto($langs->trans('ServiceStatusNotLate'),'statut4').' '.$langs->trans("ServiceStatusNotLateShort"); }
if ($statut == 4 && $expired == 1) { return img_picto($langs->trans('ServiceStatusLate'),'statut3').' '.$langs->trans("ServiceStatusLateShort"); }
if ($statut == 5) { return img_picto($langs->trans('ServiceStatusClosed'),'statut6') .' '.$langs->trans("ServiceStatusClosed"); }
if ($statut == self::STATUS_INITIAL) { return img_picto($langs->trans('ServiceStatusInitial'),'statut0').' '.$langs->trans("ServiceStatusInitial"); }
if ($statut == self::STATUS_OPEN && $expired == -1) { return img_picto($langs->trans('ServiceStatusRunning'),'statut4').' '.$langs->trans("ServiceStatusRunning"); }
if ($statut == self::STATUS_OPEN && $expired == 0) { return img_picto($langs->trans('ServiceStatusNotLate'),'statut4').' '.$langs->trans("ServiceStatusNotLateShort"); }
if ($statut == self::STATUS_OPEN && $expired == 1) { return img_picto($langs->trans('ServiceStatusLate'),'statut3').' '.$langs->trans("ServiceStatusLateShort"); }
if ($statut == self::STATUS_CLOSED) { return img_picto($langs->trans('ServiceStatusClosed'),'statut6') .' '.$langs->trans("ServiceStatusClosed"); }
}
if ($mode == 3)
{
if ($statut == 0) { return img_picto($langs->trans('ServiceStatusInitial'),'statut0',$moreatt); }
if ($statut == 4 && $expired == -1) { return img_picto($langs->trans('ServiceStatusRunning'),'statut4',$moreatt); }
if ($statut == 4 && $expired == 0) { return img_picto($langs->trans('ServiceStatusNotLate'),'statut4',$moreatt); }
if ($statut == 4 && $expired == 1) { return img_picto($langs->trans('ServiceStatusLate'),'statut3',$moreatt); }
if ($statut == 5) { return img_picto($langs->trans('ServiceStatusClosed'),'statut6',$moreatt); }
if ($statut == self::STATUS_INITIAL) { return img_picto($langs->trans('ServiceStatusInitial'),'statut0',$moreatt); }
if ($statut == self::STATUS_OPEN && $expired == -1) { return img_picto($langs->trans('ServiceStatusRunning'),'statut4',$moreatt); }
if ($statut == self::STATUS_OPEN && $expired == 0) { return img_picto($langs->trans('ServiceStatusNotLate'),'statut4',$moreatt); }
if ($statut == self::STATUS_OPEN && $expired == 1) { return img_picto($langs->trans('ServiceStatusLate'),'statut3',$moreatt); }
if ($statut == self::STATUS_CLOSED) { return img_picto($langs->trans('ServiceStatusClosed'),'statut6',$moreatt); }
}
if ($mode == 4)
{
if ($statut == 0) { return img_picto($langs->trans('ServiceStatusInitial'),'statut0').' '.$langs->trans("ServiceStatusInitial"); }
if ($statut == 4 && $expired == -1) { return img_picto($langs->trans('ServiceStatusRunning'),'statut4').' '.$langs->trans("ServiceStatusRunning"); }
if ($statut == 4 && $expired == 0) { return img_picto($langs->trans('ServiceStatusNotLate'),'statut4').' '.$langs->trans("ServiceStatusNotLate"); }
if ($statut == 4 && $expired == 1) { return img_picto($langs->trans('ServiceStatusLate'),'statut3').' '.$langs->trans("ServiceStatusLate"); }
if ($statut == 5) { return img_picto($langs->trans('ServiceStatusClosed'),'statut6') .' '.$langs->trans("ServiceStatusClosed"); }
if ($statut == self::STATUS_INITIAL) { return img_picto($langs->trans('ServiceStatusInitial'),'statut0').' '.$langs->trans("ServiceStatusInitial"); }
if ($statut == self::STATUS_OPEN && $expired == -1) { return img_picto($langs->trans('ServiceStatusRunning'),'statut4').' '.$langs->trans("ServiceStatusRunning"); }
if ($statut == self::STATUS_OPEN && $expired == 0) { return img_picto($langs->trans('ServiceStatusNotLate'),'statut4').' '.$langs->trans("ServiceStatusNotLate"); }
if ($statut == self::STATUS_OPEN && $expired == 1) { return img_picto($langs->trans('ServiceStatusLate'),'statut3').' '.$langs->trans("ServiceStatusLate"); }
if ($statut == self::STATUS_CLOSED) { return img_picto($langs->trans('ServiceStatusClosed'),'statut6') .' '.$langs->trans("ServiceStatusClosed"); }
}
if ($mode == 5)
{
if ($statut == 0) { return $langs->trans("ServiceStatusInitial").' '.img_picto($langs->trans('ServiceStatusInitial'),'statut0'); }
if ($statut == 4 && $expired == -1) { return $langs->trans("ServiceStatusRunning").' '.img_picto($langs->trans('ServiceStatusRunning'),'statut4'); }
if ($statut == 4 && $expired == 0) { return $langs->trans("ServiceStatusNotLateShort").' '.img_picto($langs->trans('ServiceStatusNotLateShort'),'statut4'); }
if ($statut == 4 && $expired == 1) { return $langs->trans("ServiceStatusLateShort").' '.img_picto($langs->trans('ServiceStatusLate'),'statut3'); }
if ($statut == 5) { return $langs->trans("ServiceStatusClosed").' '.img_picto($langs->trans('ServiceStatusClosed'),'statut6'); }
if ($statut == self::STATUS_INITIAL) { return $langs->trans("ServiceStatusInitial").' '.img_picto($langs->trans('ServiceStatusInitial'),'statut0'); }
if ($statut == self::STATUS_OPEN && $expired == -1) { return $langs->trans("ServiceStatusRunning").' '.img_picto($langs->trans('ServiceStatusRunning'),'statut4'); }
if ($statut == self::STATUS_OPEN && $expired == 0) { return $langs->trans("ServiceStatusNotLateShort").' '.img_picto($langs->trans('ServiceStatusNotLateShort'),'statut4'); }
if ($statut == self::STATUS_OPEN && $expired == 1) { return $langs->trans("ServiceStatusLateShort").' '.img_picto($langs->trans('ServiceStatusLate'),'statut3'); }
if ($statut == self::STATUS_CLOSED) { return $langs->trans("ServiceStatusClosed").' '.img_picto($langs->trans('ServiceStatusClosed'),'statut6'); }
}
}
@ -3096,13 +3103,13 @@ class ContratLigne extends CommonObjectLine
$this->db->begin();
$sql = "UPDATE " . MAIN_DB_PREFIX . "contratdet SET statut = 4,";
$sql = "UPDATE " . MAIN_DB_PREFIX . "contratdet SET statut = ".ContratLigne::STATUS_OPEN.",";
$sql .= " date_ouverture = " . (dol_strlen($date) != 0 ? "'" . $this->db->idate($date) . "'" : "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) . "'";
$sql .= " WHERE rowid = " . $this->id . " AND (statut = 0 OR statut = 3 OR statut = 5)";
$sql .= " WHERE rowid = " . $this->id . " AND (statut = ".ContratLigne::STATUS_INITIAL." OR statut = ".ContratLigne::STATUS_CLOSED.")";
dol_syslog(get_class($this) . "::active_line", LOG_DEBUG);
$resql = $this->db->query($sql);
@ -3114,7 +3121,7 @@ class ContratLigne extends CommonObjectLine
if (! $error)
{
$this->statut = 4;
$this->statut = ContratLigne::STATUS_OPEN;
$this->date_ouverture = $date;
$this->date_fin_validite = $date_end;
$this->fk_user_ouverture = $user->id;
@ -3160,11 +3167,11 @@ class ContratLigne extends CommonObjectLine
$this->db->begin();
$sql = "UPDATE " . MAIN_DB_PREFIX . "contratdet SET statut = 5,";
$sql = "UPDATE " . MAIN_DB_PREFIX . "contratdet SET statut = ".ContratLigne::STATUS_CLOSED.",";
$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";
$sql .= " WHERE rowid = " . $this->id . " AND statut = ".ContratLigne::STATUS_OPEN;
$resql = $this->db->query($sql);
if ($resql)