60 global $user, $langs, $conf;
64 include_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
68 $this->info_box_head = array(
'text' => $langs->trans(
"BoxLastExpiredServices", $max));
70 if ($user->hasRight(
'contrat',
'lire')) {
73 $sql .=
" c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.ref_customer, c.ref_supplier,";
74 $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,";
75 $sql .=
" MIN(cd.date_fin_validite) as date_line, COUNT(cd.rowid) as nb_services";
76 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c, ".MAIN_DB_PREFIX.
"societe s, ".MAIN_DB_PREFIX.
"contratdet as cd";
77 if (!$user->hasRight(
'societe',
'client',
'voir')) {
78 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
80 $sql .=
" WHERE cd.statut = 4 AND cd.date_fin_validite <= '".$this->db->idate($now).
"'";
81 $sql .=
" AND c.entity = ".$conf->entity;
82 $sql .=
" AND c.fk_soc=s.rowid AND cd.fk_contrat=c.rowid AND c.statut > 0";
84 $sql .=
' AND c.fk_soc = '.((int) $user->socid);
86 if (!$user->hasRight(
'societe',
'client',
'voir')) {
87 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
89 $sql .=
" GROUP BY c.rowid, c.ref, c.statut, c.date_contrat, c.ref_customer, c.ref_supplier, s.nom, s.rowid";
90 $sql .=
", s.email, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
91 $sql .=
" ORDER BY date_line ASC";
92 $sql .= $this->db->plimit($max, 0);
94 $resql = $this->db->query($sql);
96 $num = $this->db->num_rows($resql);
100 $thirdpartytmp =
new Societe($this->db);
101 $contract =
new Contrat($this->db);
106 $objp = $this->db->fetch_object($resql);
108 $thirdpartytmp->name = $objp->name;
109 $thirdpartytmp->id = $objp->socid;
110 $thirdpartytmp->email = $objp->email;
111 $thirdpartytmp->client = $objp->client;
112 $thirdpartytmp->fournisseur = $objp->fournisseur;
113 $thirdpartytmp->code_client = $objp->code_client;
114 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
115 $thirdpartytmp->code_compta = $objp->code_compta;
116 $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
118 $contract->id = $objp->rowid;
119 $contract->ref = $objp->ref;
120 $contract->statut = $objp->fk_statut;
121 $contract->ref_customer = $objp->ref_customer;
122 $contract->ref_supplier = $objp->ref_supplier;
124 $dateline = $this->db->jdate($objp->date_line);
125 if (($dateline + $conf->contrat->services->expires->warning_delay) < $now) {
129 $this->info_box_contents[$i][] = array(
130 'td' =>
'class="nowraponall"',
131 'text' => $contract->getNomUrl(1),
135 $this->info_box_contents[$i][] = array(
136 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone left"',
137 'text' => $thirdpartytmp->getNomUrl(1,
'customer'),
141 $this->info_box_contents[$i][] = array(
142 'td' =>
'class="center nowraponall" title="'.
dol_escape_htmltag($langs->trans(
"DateEndPlanned").
': '.
dol_print_date($dateline,
'dayhour',
'tzuserrel')).
'"',
147 $this->info_box_contents[$i][] = array(
148 'td' =>
'class="right"',
149 'text' => $objp->nb_services,
157 $langs->load(
"contracts");
158 $this->info_box_contents[$i][] = array(
159 'td' =>
'class="nohover center"',
160 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"NoExpiredServices").
'</span>'
164 $this->db->free($resql);
166 $this->info_box_contents[0][] = array(
169 'text' => ($this->db->error().
' sql='.$sql),
173 $this->info_box_contents[0][0] = array(
174 'td' =>
'class="nohover left"',
175 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'