64 global $user, $langs, $conf;
68 include_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
72 $this->info_box_head = array(
'text' => $langs->trans(
"BoxLastExpiredServices", $max));
74 if ($user->hasRight(
'contrat',
'lire')) {
77 $sql .=
" c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.ref_customer, c.ref_supplier,";
78 $sql .=
" s.nom as name, s.rowid as socid, s.email, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,";
79 $sql .=
" MIN(cd.date_fin_validite) as date_line, COUNT(cd.rowid) as nb_services";
80 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c, ".MAIN_DB_PREFIX.
"societe s, ".MAIN_DB_PREFIX.
"contratdet as cd";
81 if (!$user->hasRight(
'societe',
'client',
'voir')) {
82 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
84 $sql .=
" WHERE cd.statut = 4 AND cd.date_fin_validite <= '".$this->db->idate($now).
"'";
85 $sql .=
" AND c.entity = ".$conf->entity;
86 $sql .=
" AND c.fk_soc=s.rowid AND cd.fk_contrat=c.rowid AND c.statut > 0";
88 $sql .=
' AND c.fk_soc = '.((int) $user->socid);
90 if (!$user->hasRight(
'societe',
'client',
'voir')) {
91 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
93 $sql .=
" GROUP BY c.rowid, c.ref, c.statut, c.date_contrat, c.ref_customer, c.ref_supplier, s.nom, s.rowid";
94 $sql .=
", s.email, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
95 $sql .=
" ORDER BY date_line ASC";
96 $sql .= $this->db->plimit($max, 0);
98 $resql = $this->db->query($sql);
100 $num = $this->db->num_rows($resql);
104 $thirdpartytmp =
new Societe($this->db);
105 $contract =
new Contrat($this->db);
110 $objp = $this->db->fetch_object($resql);
112 $thirdpartytmp->name = $objp->name;
113 $thirdpartytmp->id = $objp->socid;
114 $thirdpartytmp->email = $objp->email;
115 $thirdpartytmp->client = $objp->client;
116 $thirdpartytmp->fournisseur = $objp->fournisseur;
117 $thirdpartytmp->code_client = $objp->code_client;
118 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
119 $thirdpartytmp->code_compta = $objp->code_compta;
120 $thirdpartytmp->code_compta_client = $objp->code_compta;
121 $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
123 $contract->id = $objp->rowid;
124 $contract->ref = $objp->ref;
125 $contract->statut = $objp->fk_statut;
126 $contract->ref_customer = $objp->ref_customer;
127 $contract->ref_supplier = $objp->ref_supplier;
129 $dateline = $this->db->jdate($objp->date_line);
130 if (($dateline + $conf->contrat->services->expires->warning_delay) < $now) {
134 $this->info_box_contents[$i][] = array(
135 'td' =>
'class="nowraponall"',
136 'text' => $contract->getNomUrl(1),
140 $this->info_box_contents[$i][] = array(
141 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone left"',
142 'text' => $thirdpartytmp->getNomUrl(1,
'customer'),
146 $this->info_box_contents[$i][] = array(
147 'td' =>
'class="center nowraponall" title="'.
dol_escape_htmltag($langs->trans(
"DateEndPlanned").
': '.
dol_print_date($dateline,
'dayhour',
'tzuserrel')).
'"',
152 $this->info_box_contents[$i][] = array(
153 'td' =>
'class="right"',
154 'text' => $objp->nb_services,
162 $this->db->free($resql);
164 $this->info_box_contents[0][] = array(
167 'text' => ($this->db->error().
' sql='.$sql),
171 $this->info_box_contents[0][0] = array(
172 'td' =>
'class="nohover left"',
173 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'