74 global $user, $langs, $conf;
78 include_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
80 $form =
new Form($this->db);
82 $this->info_box_head = array(
'text' => $langs->trans(
"BoxLastProductsInContract", $max));
84 if ($user->hasRight(
'service',
'lire') && $user->hasRight(
'contrat',
'lire')) {
85 $contractstatic =
new Contrat($this->db);
87 $thirdpartytmp =
new Societe($this->db);
88 $productstatic =
new Product($this->db);
90 $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,";
91 $sql .=
" c.rowid, c.ref, c.statut as contract_status, c.ref_customer, c.ref_supplier,";
92 $sql .=
" cd.rowid as cdid, cd.label, cd.description, cd.tms as datem, cd.statut as contractline_status, cd.product_type as type, cd.date_fin_validite as date_line,";
93 $sql .=
" p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as product_type, p.entity as product_entity, p.tobuy, p.tosell";
94 $sql .=
" FROM (".MAIN_DB_PREFIX.
"societe as s";
95 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"contrat as c ON s.rowid = c.fk_soc";
96 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"contratdet as cd ON c.rowid = cd.fk_contrat";
97 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON cd.fk_product = p.rowid";
98 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
99 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
102 $sql .=
" WHERE c.entity = ".$conf->entity;
104 $sql .=
" AND s.rowid = ".((int) $user->socid);
106 $sql .= $this->db->order(
"c.tms",
"DESC");
107 $sql .= $this->db->plimit($max, 0);
109 $result = $this->db->query($sql);
111 $num = $this->db->num_rows($result);
119 $objp = $this->db->fetch_object($result);
120 $datem = $this->db->jdate($objp->datem);
122 $contractlinestatic->id = $objp->cdid;
123 $contractlinestatic->fk_contrat = $objp->rowid;
124 $contractlinestatic->label = $objp->label;
125 $contractlinestatic->description = $objp->description;
126 $contractlinestatic->type = $objp->type;
127 $contractlinestatic->fk_product = $objp->product_id;
128 $contractlinestatic->product_ref = $objp->product_ref;
129 $contractlinestatic->product_type = $objp->product_type;
130 $contractlinestatic->statut = $objp->contractline_status;
132 $contractstatic->id = $objp->rowid;
133 $contractstatic->ref = $objp->ref;
134 $contractstatic->ref_customer = $objp->ref_customer;
135 $contractstatic->ref_supplier = $objp->ref_supplier;
136 $contractstatic->statut = $objp->contract_status;
138 $thirdpartytmp->name = $objp->name;
139 $thirdpartytmp->id = $objp->socid;
140 $thirdpartytmp->email = $objp->email;
141 $thirdpartytmp->client = $objp->client;
142 $thirdpartytmp->fournisseur = $objp->fournisseur;
143 $thirdpartytmp->code_client = $objp->code_client;
144 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
145 $thirdpartytmp->code_compta = $objp->code_compta;
146 $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
148 $dateline = $this->db->jdate($objp->date_line);
149 if ($contractstatic->statut == Contrat::STATUS_VALIDATED && $objp->contractline_status == ContratLigne::STATUS_OPEN && !empty($dateline) && ($dateline + $conf->contrat->services->expires->warning_delay) < $now) {
154 if ($objp->product_id > 0) {
155 $productstatic->id = $objp->product_id;
156 $productstatic->type = $objp->product_type;
157 $productstatic->ref = $objp->product_ref;
158 $productstatic->entity = $objp->product_entity;
159 $productstatic->label = $objp->product_label;
160 $productstatic->status = $objp->tosell;
161 $productstatic->status_buy = $objp->tobuy;
163 $text = $productstatic->getNomUrl(1,
'', 20);
164 if ($objp->product_label) {
168 $text .= $objp->product_label;
170 $description = $objp->description;
172 $s = $form->textwithtooltip($text, $description, 3,
'',
'',
'', 0,
'');
174 $s =
img_object($langs->trans(
"ShowProductOrService"), ($objp->product_type ?
'service' :
'product')).
' '.
dol_htmlentitiesbr($objp->description);
178 $this->info_box_contents[$i][] = array(
179 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
184 $this->info_box_contents[$i][] = array(
185 'td' =>
'class="nowraponall"',
186 'text' => $contractstatic->getNomUrl(1),
190 $this->info_box_contents[$i][] = array(
191 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
192 'text' => $thirdpartytmp->getNomUrl(1),
196 $this->info_box_contents[$i][] = array(
202 $this->info_box_contents[$i][] = array(
203 'td' =>
'class="right" width="18"',
204 'text' => $contractlinestatic->getLibStatut(3)
210 $this->info_box_contents[$i][0] = array(
211 'td' =>
'class="center"',
212 'text'=>
'<span class="opacitymedium">'.$langs->trans(
"NoContractedProducts").
'</span>'
216 $this->db->free($result);
218 $this->info_box_contents[0][0] = array(
221 'text' => ($this->db->error().
' sql='.$sql),
225 $this->info_box_contents[0][0] = array(
226 'td' =>
'class="nohover left"',
227 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'