67 global $user, $langs, $conf;
71 include_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
73 $form =
new Form($this->db);
75 $this->info_box_head = array(
76 '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>'
79 if ($user->hasRight(
'service',
'lire') && $user->hasRight(
'contrat',
'lire')) {
80 $contractstatic =
new Contrat($this->db);
82 $thirdpartytmp =
new Societe($this->db);
83 $productstatic =
new Product($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 contract_status, c.ref_customer, c.ref_supplier,";
87 $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,";
88 $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";
89 $sql .=
" FROM (".MAIN_DB_PREFIX.
"societe as s";
90 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"contrat as c ON s.rowid = c.fk_soc";
91 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"contratdet as cd ON c.rowid = cd.fk_contrat";
92 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON cd.fk_product = p.rowid";
93 if (!$user->hasRight(
'societe',
'client',
'voir')) {
94 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
97 $sql .=
" WHERE c.entity = ".$conf->entity;
99 $sql .=
" AND s.rowid = ".((int) $user->socid);
101 $sql .= $this->db->order(
"c.tms",
"DESC");
102 $sql .= $this->db->plimit($max, 0);
104 $result = $this->db->query($sql);
106 $num = $this->db->num_rows($result);
114 $objp = $this->db->fetch_object($result);
115 $datem = $this->db->jdate($objp->datem);
117 $contractlinestatic->id = $objp->cdid;
118 $contractlinestatic->fk_contrat = $objp->rowid;
119 $contractlinestatic->label = $objp->label;
120 $contractlinestatic->description = $objp->description;
121 $contractlinestatic->type = $objp->type;
122 $contractlinestatic->fk_product = $objp->product_id;
123 $contractlinestatic->product_ref = $objp->product_ref;
124 $contractlinestatic->product_type = $objp->product_type;
125 $contractlinestatic->statut = $objp->contractline_status;
127 $contractstatic->id = $objp->rowid;
128 $contractstatic->ref = $objp->ref;
129 $contractstatic->ref_customer = $objp->ref_customer;
130 $contractstatic->ref_supplier = $objp->ref_supplier;
131 $contractstatic->statut = $objp->contract_status;
132 $contractstatic->status = $objp->contract_status;
134 $thirdpartytmp->name = $objp->name;
135 $thirdpartytmp->id = $objp->socid;
136 $thirdpartytmp->email = $objp->email;
137 $thirdpartytmp->client = $objp->client;
138 $thirdpartytmp->fournisseur = $objp->fournisseur;
139 $thirdpartytmp->code_client = $objp->code_client;
140 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
141 $thirdpartytmp->code_compta = $objp->code_compta;
142 $thirdpartytmp->code_compta_client = $objp->code_compta;
143 $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
145 $dateline = $this->db->jdate($objp->date_line);
146 if ($contractstatic->status == Contrat::STATUS_VALIDATED && $objp->contractline_status == ContratLigne::STATUS_OPEN && !empty($dateline) && ($dateline + $conf->contrat->services->expires->warning_delay) < $now) {
151 if ($objp->product_id > 0) {
152 $productstatic->id = $objp->product_id;
153 $productstatic->type = $objp->product_type;
154 $productstatic->ref = $objp->product_ref;
155 $productstatic->entity = $objp->product_entity;
156 $productstatic->label = $objp->product_label;
157 $productstatic->status = $objp->tosell;
158 $productstatic->status_buy = $objp->tobuy;
160 $text = $productstatic->getNomUrl(1,
'', 20);
161 if ($objp->product_label) {
165 $text .= $objp->product_label;
167 $description = $objp->description;
169 $s = $form->textwithtooltip($text, $description, 3,
'',
'',
'', 0,
'');
171 $s =
img_object($langs->trans(
"ShowProductOrService"), ($objp->product_type ?
'service' :
'product')).
' '.
dol_htmlentitiesbr($objp->description);
175 $this->info_box_contents[$i][] = array(
176 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
181 $this->info_box_contents[$i][] = array(
182 'td' =>
'class="nowraponall"',
183 'text' => $contractstatic->getNomUrl(1),
187 $this->info_box_contents[$i][] = array(
188 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
189 'text' => $thirdpartytmp->getNomUrl(1),
193 $this->info_box_contents[$i][] = array(
199 $this->info_box_contents[$i][] = array(
200 'td' =>
'class="right" width="18"',
201 'text' => $contractlinestatic->getLibStatut(3)
207 $this->db->free($result);
209 $this->info_box_contents[0][0] = array(
212 'text' => ($this->db->error().
' sql='.$sql),
216 $this->info_box_contents[0][0] = array(
217 'td' =>
'class="nohover left"',
218 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'