71 global $user, $langs, $conf;
75 include_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
79 $this->info_box_head = array(
'text' => $langs->trans(
"BoxLastExpiredServices", $max));
81 if ($user->hasRight(
'contrat',
'lire')) {
84 $sql .=
" c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.ref_customer, c.ref_supplier,";
85 $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,";
86 $sql .=
" MIN(cd.date_fin_validite) as date_line, COUNT(cd.rowid) as nb_services";
87 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c, ".MAIN_DB_PREFIX.
"societe s, ".MAIN_DB_PREFIX.
"contratdet as cd";
88 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
89 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
91 $sql .=
" WHERE cd.statut = 4 AND cd.date_fin_validite <= '".$this->db->idate($now).
"'";
92 $sql .=
" AND c.entity = ".$conf->entity;
93 $sql .=
" AND c.fk_soc=s.rowid AND cd.fk_contrat=c.rowid AND c.statut > 0";
95 $sql .=
' AND c.fk_soc = '.((int) $user->socid);
97 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
98 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
100 $sql .=
" GROUP BY c.rowid, c.ref, c.statut, c.date_contrat, c.ref_customer, c.ref_supplier, s.nom, s.rowid";
101 $sql .=
", s.email, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
102 $sql .=
" ORDER BY date_line ASC";
103 $sql .= $this->db->plimit($max, 0);
105 $resql = $this->db->query($sql);
107 $num = $this->db->num_rows($resql);
111 $thirdpartytmp =
new Societe($this->db);
112 $contract =
new Contrat($this->db);
117 $objp = $this->db->fetch_object($resql);
119 $thirdpartytmp->name = $objp->name;
120 $thirdpartytmp->id = $objp->socid;
121 $thirdpartytmp->email = $objp->email;
122 $thirdpartytmp->client = $objp->client;
123 $thirdpartytmp->fournisseur = $objp->fournisseur;
124 $thirdpartytmp->code_client = $objp->code_client;
125 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
126 $thirdpartytmp->code_compta = $objp->code_compta;
127 $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
129 $contract->id = $objp->rowid;
130 $contract->ref = $objp->ref;
131 $contract->statut = $objp->fk_statut;
132 $contract->ref_customer = $objp->ref_customer;
133 $contract->ref_supplier = $objp->ref_supplier;
135 $dateline = $this->db->jdate($objp->date_line);
136 if (($dateline + $conf->contrat->services->expires->warning_delay) < $now) {
140 $this->info_box_contents[$i][] = array(
141 'td' =>
'class="nowraponall"',
142 'text' => $contract->getNomUrl(1),
146 $this->info_box_contents[$i][] = array(
147 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone left"',
148 'text' => $thirdpartytmp->getNomUrl(1,
'customer'),
152 $this->info_box_contents[$i][] = array(
153 'td' =>
'class="center nowraponall" title="'.
dol_escape_htmltag($langs->trans(
"DateEndPlanned").
': '.
dol_print_date($dateline,
'dayhour',
'tzuserrel')).
'"',
158 $this->info_box_contents[$i][] = array(
159 'td' =>
'class="right"',
160 'text' => $objp->nb_services,
168 $langs->load(
"contracts");
169 $this->info_box_contents[$i][] = array(
170 'td' =>
'class="nohover center"',
171 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"NoExpiredServices").
'</span>'
175 $this->db->free($resql);
177 $this->info_box_contents[0][] = array(
180 'text' => ($this->db->error().
' sql='.$sql),
184 $this->info_box_contents[0][0] = array(
185 'td' =>
'class="nohover left"',
186 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'