63 global $user, $langs, $conf;
67 include_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
69 $form =
new Form($this->db);
71 $this->info_box_head = array(
72 'text' => $langs->trans(
"BoxLastProductsInContract", $max).
'<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(
'service',
'lire') && $user->hasRight(
'contrat',
'lire')) {
76 $contractstatic =
new Contrat($this->db);
78 $thirdpartytmp =
new Societe($this->db);
79 $productstatic =
new Product($this->db);
81 $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,";
82 $sql .=
" c.rowid, c.ref, c.statut as contract_status, c.ref_customer, c.ref_supplier,";
83 $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,";
84 $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";
85 $sql .=
" FROM (".MAIN_DB_PREFIX.
"societe as s";
86 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"contrat as c ON s.rowid = c.fk_soc";
87 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"contratdet as cd ON c.rowid = cd.fk_contrat";
88 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON cd.fk_product = p.rowid";
89 if (!$user->hasRight(
'societe',
'client',
'voir')) {
90 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
93 $sql .=
" WHERE c.entity = ".$conf->entity;
95 $sql .=
" AND s.rowid = ".((int) $user->socid);
97 $sql .= $this->db->order(
"c.tms",
"DESC");
98 $sql .= $this->db->plimit($max, 0);
100 $result = $this->db->query($sql);
102 $num = $this->db->num_rows($result);
110 $objp = $this->db->fetch_object($result);
111 $datem = $this->db->jdate($objp->datem);
113 $contractlinestatic->id = $objp->cdid;
114 $contractlinestatic->fk_contrat = $objp->rowid;
115 $contractlinestatic->label = $objp->label;
116 $contractlinestatic->description = $objp->description;
117 $contractlinestatic->type = $objp->type;
118 $contractlinestatic->fk_product = $objp->product_id;
119 $contractlinestatic->product_ref = $objp->product_ref;
120 $contractlinestatic->product_type = $objp->product_type;
121 $contractlinestatic->statut = $objp->contractline_status;
123 $contractstatic->id = $objp->rowid;
124 $contractstatic->ref = $objp->ref;
125 $contractstatic->ref_customer = $objp->ref_customer;
126 $contractstatic->ref_supplier = $objp->ref_supplier;
127 $contractstatic->statut = $objp->contract_status;
128 $contractstatic->status = $objp->contract_status;
130 $thirdpartytmp->name = $objp->name;
131 $thirdpartytmp->id = $objp->socid;
132 $thirdpartytmp->email = $objp->email;
133 $thirdpartytmp->client = $objp->client;
134 $thirdpartytmp->fournisseur = $objp->fournisseur;
135 $thirdpartytmp->code_client = $objp->code_client;
136 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
137 $thirdpartytmp->code_compta = $objp->code_compta;
138 $thirdpartytmp->code_compta_client = $objp->code_compta;
139 $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
141 $dateline = $this->db->jdate($objp->date_line);
142 if ($contractstatic->status == Contrat::STATUS_VALIDATED && $objp->contractline_status == ContratLigne::STATUS_OPEN && !empty($dateline) && ($dateline + $conf->contrat->services->expires->warning_delay) < $now) {
147 if ($objp->product_id > 0) {
148 $productstatic->id = $objp->product_id;
149 $productstatic->type = $objp->product_type;
150 $productstatic->ref = $objp->product_ref;
151 $productstatic->entity = $objp->product_entity;
152 $productstatic->label = $objp->product_label;
153 $productstatic->status = $objp->tosell;
154 $productstatic->status_buy = $objp->tobuy;
156 $text = $productstatic->getNomUrl(1,
'', 20);
157 if ($objp->product_label) {
161 $text .= $objp->product_label;
163 $description = $objp->description;
165 $s = $form->textwithtooltip($text, $description, 3,
'',
'',
'', 0,
'');
167 $s =
img_object($langs->trans(
"ShowProductOrService"), ($objp->product_type ?
'service' :
'product')).
' '.
dol_htmlentitiesbr($objp->description);
171 $this->info_box_contents[$i][] = array(
172 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
177 $this->info_box_contents[$i][] = array(
178 'td' =>
'class="nowraponall"',
179 'text' => $contractstatic->getNomUrl(1),
183 $this->info_box_contents[$i][] = array(
184 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
185 'text' => $thirdpartytmp->getNomUrl(1),
189 $this->info_box_contents[$i][] = array(
195 $this->info_box_contents[$i][] = array(
196 'td' =>
'class="right" width="18"',
197 'text' => $contractlinestatic->getLibStatut(3)
203 $this->info_box_contents[$i][0] = array(
204 'td' =>
'class="center"',
205 'text'=>
'<span class="opacitymedium">'.$langs->trans(
"NoContractedProducts").
'</span>'
209 $this->db->free($result);
211 $this->info_box_contents[0][0] = array(
214 'text' => ($this->db->error().
' sql='.$sql),
218 $this->info_box_contents[0][0] = array(
219 'td' =>
'class="nohover left"',
220 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'