62 global $user, $langs, $conf;
66 include_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
68 $this->info_box_head = array(
69 'text' =>
'<span class="valignmiddle">'.$langs->trans(
"BoxTitleLastContracts", $max).
'</span><a class="paddingleft valignmiddle" href="'.DOL_URL_ROOT.
'/contrat/list.php?sortfield=c.tms&sortorder=DESC"><span class="badge">...</span></a>'
72 if ($user->hasRight(
'contrat',
'lire')) {
73 $contractstatic =
new Contrat($this->db);
74 $thirdpartytmp =
new Societe($this->db);
76 $sql =
"SELECT 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,";
77 $sql .=
" c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.datec, c.tms as date_modification, c.fin_validite, c.date_cloture,";
78 $sql .=
" c.ref_customer, c.ref_supplier";
79 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"contrat as c";
80 if (!$user->hasRight(
'societe',
'client',
'voir')) {
81 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
83 $sql .=
" WHERE c.fk_soc = s.rowid";
84 $sql .=
" AND c.entity = ".$conf->entity;
85 if (!$user->hasRight(
'societe',
'client',
'voir')) {
86 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
89 $sql .=
" AND s.rowid = ".((int) $user->socid);
92 $sql .=
" ORDER BY c.date_contrat DESC, c.ref DESC ";
94 $sql .=
" ORDER BY c.tms DESC, c.ref DESC ";
96 $sql .= $this->db->plimit($max, 0);
98 $resql = $this->db->query($sql);
100 $num = $this->db->num_rows($resql);
105 $langs->load(
"contracts");
107 while ($line < $num) {
108 $objp = $this->db->fetch_object($resql);
110 $datec = $this->db->jdate($objp->datec);
111 $datem = $this->db->jdate($objp->date_modification);
112 $dateterm = $this->db->jdate($objp->fin_validite);
113 $dateclose = $this->db->jdate($objp->date_cloture);
116 $contractstatic->statut = $objp->fk_statut;
117 $contractstatic->id = $objp->rowid;
118 $contractstatic->ref = $objp->ref;
119 $contractstatic->ref_customer = $objp->ref_customer;
120 $contractstatic->ref_supplier = $objp->ref_supplier;
121 $result = $contractstatic->fetch_lines();
123 $thirdpartytmp->name = $objp->name;
124 $thirdpartytmp->id = $objp->socid;
125 $thirdpartytmp->email = $objp->email;
126 $thirdpartytmp->client = $objp->client;
127 $thirdpartytmp->fournisseur = $objp->fournisseur;
128 $thirdpartytmp->code_client = $objp->code_client;
129 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
130 $thirdpartytmp->code_compta = $objp->code_compta;
131 $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
136 $this->info_box_contents[$line][] = array(
137 'td' =>
'class="nowraponall"',
138 'text' => $contractstatic->getNomUrl(1),
143 $this->info_box_contents[$line][] = array(
144 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
145 'text' => $thirdpartytmp->getNomUrl(1),
149 $this->info_box_contents[$line][] = array(
154 $this->info_box_contents[$line][] = array(
155 'td' =>
'class="nowraponall right"',
156 'text' => $contractstatic->getLibStatut(7),
164 $this->info_box_contents[$line][0] = array(
165 'td' =>
'class="center"',
166 'text'=>
'<span class="opacitymedium">'.$langs->trans(
"NoRecordedContracts").
'</span>'
170 $this->db->free($resql);
172 $this->info_box_contents[0][0] = array(
175 'text' => ($this->db->error().
' sql='.$sql),
179 $this->info_box_contents[0][0] = array(
180 'td' =>
'class="nohover left"',
181 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'