27 include_once DOL_DOCUMENT_ROOT.
'/core/boxes/modules_boxes.php';
35 public $boxcode =
"lastproductsincontract";
36 public $boximg =
"object_product";
37 public $boxlabel =
"BoxLastProductsInContract";
38 public $depends = array(
"service",
"contrat");
47 public $info_box_head = array();
48 public $info_box_contents = array();
63 $this->hidden = !($user->rights->service->lire && $user->rights->contrat->lire);
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->rights->service->lire && $user->rights->contrat->lire)
91 $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,";
92 $sql .=
" c.rowid, c.ref, c.statut as contract_status, c.ref_customer, c.ref_supplier,";
93 $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,";
94 $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, p.tobuy, p.tosell";
95 $sql .=
" FROM (".MAIN_DB_PREFIX.
"societe as s";
96 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"contrat as c ON s.rowid = c.fk_soc";
97 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"contratdet as cd ON c.rowid = cd.fk_contrat";
98 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON cd.fk_product = p.rowid";
99 if (!$user->rights->societe->client->voir && !$user->socid) $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
101 $sql .=
" WHERE c.entity = ".$conf->entity;
102 if ($user->socid) $sql .=
" AND s.rowid = ".$user->socid;
103 $sql .= $this->
db->order(
"c.tms",
"DESC");
104 $sql .= $this->
db->plimit($max, 0);
106 $result = $this->
db->query($sql);
109 $num = $this->
db->num_rows($result);
118 $objp = $this->
db->fetch_object($result);
119 $datem = $this->
db->jdate($objp->datem);
121 $contractlinestatic->id = $objp->cdid;
122 $contractlinestatic->fk_contrat = $objp->rowid;
123 $contractlinestatic->label = $objp->label;
124 $contractlinestatic->description = $objp->description;
125 $contractlinestatic->type = $objp->type;
126 $contractlinestatic->product_id = $objp->product_id;
127 $contractlinestatic->product_ref = $objp->product_ref;
128 $contractlinestatic->product_type = $objp->product_type;
129 $contractlinestatic->statut = $objp->contractline_status;
131 $contractstatic->id = $objp->rowid;
132 $contractstatic->ref = $objp->ref;
133 $contractstatic->ref_customer = $objp->ref_customer;
134 $contractstatic->ref_supplier = $objp->ref_supplier;
135 $contractstatic->statut = $objp->contract_status;
137 $thirdpartytmp->name = $objp->name;
138 $thirdpartytmp->id = $objp->socid;
139 $thirdpartytmp->email = $objp->email;
140 $thirdpartytmp->client = $objp->client;
141 $thirdpartytmp->fournisseur = $objp->fournisseur;
142 $thirdpartytmp->code_client = $objp->code_client;
143 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
144 $thirdpartytmp->code_compta = $objp->code_compta;
145 $thirdpartytmp->code_compta_fournisseur = $objp->code_compta_fournisseur;
147 $dateline = $this->
db->jdate($objp->date_line);
148 if ($contractstatic->statut == Contrat::STATUS_VALIDATED && $objp->contractline_status == ContratLigne::STATUS_OPEN && !empty($dateline) && ($dateline + $conf->contrat->services->expires->warning_delay) < $now) $late =
img_warning($langs->trans(
"Late"));
151 if ($objp->product_id > 0)
153 $productstatic->id = $objp->product_id;
154 $productstatic->type = $objp->product_type;
155 $productstatic->ref = $objp->product_ref;
156 $productstatic->entity = $objp->pentity;
157 $productstatic->label = $objp->product_label;
158 $productstatic->status = $objp->tosell;
159 $productstatic->status_buy = $objp->tobuy;
161 $text = $productstatic->getNomUrl(1,
'', 20);
162 if ($objp->product_label)
167 $text .= $objp->product_label;
169 $description = $objp->description;
172 if (!empty($conf->global->PRODUIT_DESC_IN_FORM))
178 $s = $form->textwithtooltip($text, $description, 3,
'',
'',
'', 0, (!empty($objp->fk_parent_line) ?
img_picto(
'',
'rightarrow') :
''));
180 $s =
img_object($langs->trans(
"ShowProductOrService"), ($objp->product_type ?
'service' :
'product')).
' '.
dol_htmlentitiesbr($objp->description);
184 $this->info_box_contents[$i][] = array(
185 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
190 $this->info_box_contents[$i][] = array(
191 'td' =>
'class="nowraponall"',
192 'text' => $contractstatic->getNomUrl(1),
196 $this->info_box_contents[$i][] = array(
197 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
198 'text' => $thirdpartytmp->getNomUrl(1),
202 $this->info_box_contents[$i][] = array(
208 $this->info_box_contents[$i][] = array(
209 'td' =>
'class="right" width="18"',
210 'text' => $contractlinestatic->getLibStatut(3)
215 if ($num == 0) $this->info_box_contents[$i][0] = array(
216 'td' =>
'class="center opacitymedium"',
217 'text'=>$langs->trans(
"NoContractedProducts")
220 $this->
db->free($result);
222 $this->info_box_contents[0][0] = array(
225 'text' => ($this->
db->error().
' sql='.$sql),
229 $this->info_box_contents[0][0] = array(
230 'td' =>
'class="nohover opacitymedium left"',
231 'text' => $langs->trans(
"ReadPermissionNotAllowed")
244 public function showBox($head = null, $contents = null, $nooutput = 0)
246 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
__construct($db, $param)
Constructor.
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
Class to manage contracts.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom= 'UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
Class to manage lines of contracts.
$conf db
API class for accounts.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
Class to manage third parties objects (customers, suppliers, prospects...)
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Class to manage the box to show last contracted products/services lines.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
loadBox($max=5)
Load data into info_box_contents array to show array later.