65 global $user, $langs, $conf;
69 include_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
71 $this->info_box_head = array(
72 '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>'
75 if ($user->hasRight(
'contrat',
'lire')) {
76 $contractstatic =
new Contrat($this->db);
77 $thirdpartytmp =
new Societe($this->db);
79 $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,";
80 $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,";
81 $sql .=
" c.ref_customer, c.ref_supplier";
82 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"contrat as c";
83 if (!$user->hasRight(
'societe',
'client',
'voir')) {
84 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
86 $sql .=
" WHERE c.fk_soc = s.rowid";
87 $sql .=
" AND c.entity = ".$conf->entity;
88 if (!$user->hasRight(
'societe',
'client',
'voir')) {
89 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
92 $sql .=
" AND s.rowid = ".((int) $user->socid);
95 $sql .=
" ORDER BY c.date_contrat DESC, c.ref DESC ";
97 $sql .=
" ORDER BY c.tms DESC, c.ref DESC ";
99 $sql .= $this->db->plimit($max, 0);
101 $resql = $this->db->query($sql);
103 $num = $this->db->num_rows($resql);
108 $langs->load(
"contracts");
110 while ($line < $num) {
111 $objp = $this->db->fetch_object($resql);
113 $datec = $this->db->jdate($objp->datec);
114 $datem = $this->db->jdate($objp->date_modification);
115 $dateterm = $this->db->jdate($objp->fin_validite);
116 $dateclose = $this->db->jdate($objp->date_cloture);
119 $contractstatic->statut = $objp->fk_statut;
120 $contractstatic->id = $objp->rowid;
121 $contractstatic->ref = $objp->ref;
122 $contractstatic->ref_customer = $objp->ref_customer;
123 $contractstatic->ref_supplier = $objp->ref_supplier;
124 $result = $contractstatic->fetch_lines();
126 $thirdpartytmp->name = $objp->name;
127 $thirdpartytmp->id = $objp->socid;
128 $thirdpartytmp->email = $objp->email;
129 $thirdpartytmp->client = $objp->client;
130 $thirdpartytmp->fournisseur = $objp->fournisseur;
131 $thirdpartytmp->code_client = $objp->code_client;
132 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
133 $thirdpartytmp->code_compta = $objp->code_compta;
134 $thirdpartytmp->code_compta_client = $objp->code_compta;
135 $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
140 $this->info_box_contents[$line][] = array(
141 'td' =>
'class="nowraponall"',
142 'text' => $contractstatic->getNomUrl(1),
147 $this->info_box_contents[$line][] = array(
148 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
149 'text' => $thirdpartytmp->getNomUrl(1),
153 $this->info_box_contents[$line][] = array(
158 $this->info_box_contents[$line][] = array(
159 'td' =>
'class="nowraponall right"',
160 'text' => $contractstatic->getLibStatut(7),
174 $this->db->free($resql);
176 $this->info_box_contents[0][0] = array(
179 'text' => ($this->db->error().
' sql='.$sql),
183 $this->info_box_contents[0][0] = array(
184 'td' =>
'class="nohover left"',
185 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'