72 global $user, $langs, $conf;
76 include_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
80 $this->info_box_head = array(
'text' => $langs->trans(
"BoxLastExpiredServices", $max));
82 if ($user->rights->contrat->lire) {
85 $sql .=
" c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.ref_customer, c.ref_supplier,";
86 $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,";
87 $sql .=
" MIN(cd.date_fin_validite) as date_line, COUNT(cd.rowid) as nb_services";
88 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c, ".MAIN_DB_PREFIX.
"societe s, ".MAIN_DB_PREFIX.
"contratdet as cd";
89 if (empty($user->rights->societe->client->voir) && !$user->socid) {
90 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
92 $sql .=
" WHERE cd.statut = 4 AND cd.date_fin_validite <= '".$this->db->idate($now).
"'";
93 $sql .=
" AND c.entity = ".$conf->entity;
94 $sql .=
" AND c.fk_soc=s.rowid AND cd.fk_contrat=c.rowid AND c.statut > 0";
96 $sql .=
' AND c.fk_soc = '.((int) $user->socid);
98 if (empty($user->rights->societe->client->voir) && !$user->socid) {
99 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
101 $sql .=
" GROUP BY c.rowid, c.ref, c.statut, c.date_contrat, c.ref_customer, c.ref_supplier, s.nom, s.rowid";
102 $sql .=
", s.email, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
103 $sql .=
" ORDER BY date_line ASC";
104 $sql .= $this->db->plimit($max, 0);
106 $resql = $this->db->query($sql);
108 $num = $this->db->num_rows($resql);
112 $thirdpartytmp =
new Societe($this->db);
113 $contract =
new Contrat($this->db);
118 $objp = $this->db->fetch_object($resql);
120 $thirdpartytmp->name = $objp->name;
121 $thirdpartytmp->id = $objp->socid;
122 $thirdpartytmp->email = $objp->email;
123 $thirdpartytmp->client = $objp->client;
124 $thirdpartytmp->fournisseur = $objp->fournisseur;
125 $thirdpartytmp->code_client = $objp->code_client;
126 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
127 $thirdpartytmp->code_compta = $objp->code_compta;
128 $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
130 $contract->id = $objp->rowid;
131 $contract->ref = $objp->ref;
132 $contract->statut = $objp->fk_statut;
133 $contract->ref_customer = $objp->ref_customer;
134 $contract->ref_supplier = $objp->ref_supplier;
136 $dateline = $this->db->jdate($objp->date_line);
137 if (($dateline + $conf->contrat->services->expires->warning_delay) < $now) {
141 $this->info_box_contents[$i][] = array(
142 'td' =>
'class="nowraponall"',
143 'text' => $contract->getNomUrl(1),
147 $this->info_box_contents[$i][] = array(
148 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone left"',
149 'text' => $thirdpartytmp->getNomUrl(1,
'customer'),
153 $this->info_box_contents[$i][] = array(
154 'td' =>
'class="center nowraponall" title="'.
dol_escape_htmltag($langs->trans(
"DateEndPlanned").
': '.
dol_print_date($dateline,
'dayhour',
'tzuserrel')).
'"',
159 $this->info_box_contents[$i][] = array(
160 'td' =>
'class="right"',
161 'text' => $objp->nb_services,
169 $langs->load(
"contracts");
170 $this->info_box_contents[$i][] = array(
171 'td' =>
'class="nohover opacitymedium center"',
172 'text' => $langs->trans(
"NoExpiredServices"),
176 $this->db->free($resql);
178 $this->info_box_contents[0][] = array(
181 'text' => ($this->db->error().
' sql='.$sql),
185 $this->info_box_contents[0][0] = array(
186 'td' =>
'class="nohover opacitymedium left"',
187 'text' => $langs->trans(
"ReadPermissionNotAllowed")