73 global $user, $langs, $conf;
77 include_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
79 $this->info_box_head = array(
'text' => $langs->trans(
"BoxTitleLastContracts", $max));
81 if ($user->hasRight(
'contrat',
'lire')) {
82 $contractstatic =
new Contrat($this->db);
83 $thirdpartytmp =
new Societe($this->db);
85 $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,";
86 $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,";
87 $sql .=
" c.ref_customer, c.ref_supplier";
88 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"contrat as c";
89 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
90 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
92 $sql .=
" WHERE c.fk_soc = s.rowid";
93 $sql .=
" AND c.entity = ".$conf->entity;
94 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
95 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
98 $sql .=
" AND s.rowid = ".((int) $user->socid);
101 $sql .=
" ORDER BY c.date_contrat DESC, c.ref DESC ";
103 $sql .=
" ORDER BY c.tms DESC, c.ref DESC ";
105 $sql .= $this->db->plimit($max, 0);
107 $resql = $this->db->query($sql);
109 $num = $this->db->num_rows($resql);
114 $langs->load(
"contracts");
116 while ($line < $num) {
117 $objp = $this->db->fetch_object($resql);
119 $datec = $this->db->jdate($objp->datec);
120 $datem = $this->db->jdate($objp->date_modification);
121 $dateterm = $this->db->jdate($objp->fin_validite);
122 $dateclose = $this->db->jdate($objp->date_cloture);
125 $contractstatic->statut = $objp->fk_statut;
126 $contractstatic->id = $objp->rowid;
127 $contractstatic->ref = $objp->ref;
128 $contractstatic->ref_customer = $objp->ref_customer;
129 $contractstatic->ref_supplier = $objp->ref_supplier;
130 $result = $contractstatic->fetch_lines();
132 $thirdpartytmp->name = $objp->name;
133 $thirdpartytmp->id = $objp->socid;
134 $thirdpartytmp->email = $objp->email;
135 $thirdpartytmp->client = $objp->client;
136 $thirdpartytmp->fournisseur = $objp->fournisseur;
137 $thirdpartytmp->code_client = $objp->code_client;
138 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
139 $thirdpartytmp->code_compta = $objp->code_compta;
140 $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
145 $this->info_box_contents[$line][] = array(
146 'td' =>
'class="nowraponall"',
147 'text' => $contractstatic->getNomUrl(1),
152 $this->info_box_contents[$line][] = array(
153 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
154 'text' => $thirdpartytmp->getNomUrl(1),
158 $this->info_box_contents[$line][] = array(
163 $this->info_box_contents[$line][] = array(
164 'td' =>
'class="nowraponall right"',
165 'text' => $contractstatic->getLibStatut(7),
173 $this->info_box_contents[$line][0] = array(
174 'td' =>
'class="center"',
175 'text'=>
'<span class="opacitymedium">'.$langs->trans(
"NoRecordedContracts").
'</span>'
179 $this->db->free($resql);
181 $this->info_box_contents[0][0] = array(
184 'text' => ($this->db->error().
' sql='.$sql),
188 $this->info_box_contents[0][0] = array(
189 'td' =>
'class="nohover left"',
190 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'