23 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
39 public $field_list = array();
40 public $list_datas = array();
58 public function __construct($db, $targetmodule, $canvas, $card)
61 $this->targetmodule = $targetmodule;
62 $this->canvas = $canvas;
65 $this->module =
"service";
66 $this->
name =
"service";
67 $this->definition =
"Services canvas";
68 $this->fieldListName =
"product_service";
69 $this->next_prev_filter =
"canvas='service'";
85 global $limit, $offset, $sortfield, $sortorder;
86 global $conf, $langs, $user, $mysoc, $canvas;
87 global
$form, $formproduct;
90 if (!empty($id) || !empty($ref)) {
91 $tmpobject->fetch($id, $ref);
93 $this->
object = $tmpobject;
97 foreach ($this->
object as $key => $value) {
98 $this->tpl[$key] = $value;
104 $this->tpl[
'canvas'] = $this->canvas;
107 $this->tpl[
'id'] = $this->id;
110 $this->tpl[
'ref'] = $this->ref;
113 $this->tpl[
'label'] = $this->label;
116 $this->tpl[
'description'] = nl2br($this->
description);
119 $this->tpl[
'status'] = $this->
object->getLibStatut(2);
122 $this->tpl[
'note'] = nl2br($this->note);
124 if ($action ==
'create') {
126 $this->tpl[
'price'] = $this->price;
127 $this->tpl[
'price_min'] = $this->price_min;
128 $this->tpl[
'price_base_type'] =
$form->selectPriceBaseType($this->price_base_type,
"price_base_type");
131 $this->tpl[
'tva_tx'] =
$form->load_tva(
"tva_tx", -1, $mysoc,
'');
134 if ($action ==
'view') {
137 $this->tpl[
'showrefnav'] =
$form->showrefnav($this->
object,
'ref',
'', 1,
'ref');
139 $titre = $langs->trans(
"CardProduct".$this->object->type);
145 $this->tpl[
'accountancyBuyCodeKey'] =
$form->editfieldkey(
"ProductAccountancyBuyCode",
'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
146 $this->tpl[
'accountancyBuyCodeVal'] =
$form->editfieldval(
"ProductAccountancyBuyCode",
'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
149 $this->tpl[
'accountancySellCodeKey'] =
$form->editfieldkey(
"ProductAccountancySellCode",
'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
150 $this->tpl[
'accountancySellCodeVal'] =
$form->editfieldval(
"ProductAccountancySellCode",
'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
153 $this->tpl[
'finished'] = $this->
object->finished;
154 $this->tpl[
'ref'] = $this->
object->ref;
155 $this->tpl[
'label'] = $this->
object->label;
156 $this->tpl[
'id'] = $this->
object->id;
157 $this->tpl[
'type'] = $this->
object->type;
158 $this->tpl[
'note'] = $this->
object->note;
159 $this->tpl[
'seuil_stock_alerte'] = $this->
object->seuil_stock_alerte;
162 $this->tpl[
'duration_value'] = $this->
object->duration_value;
164 if ($action ==
'create') {
166 $this->tpl[
'title'] = $langs->trans(
"NewService");
169 if ($action ==
'edit') {
170 $this->tpl[
'title'] = $langs->trans(
'Modify').
' '.$langs->trans(
'Service').
' : '.$this->
object->ref;
173 if ($action ==
'create' || $action ==
'edit') {
175 $statutarray = array(
'1' => $langs->trans(
"OnSell"),
'0' => $langs->trans(
"NotOnSell"));
176 $this->tpl[
'status'] =
$form->selectarray(
'statut', $statutarray, $this->object->status);
178 $statutarray = array(
'1' => $langs->trans(
"ProductStatusOnBuy"),
'0' => $langs->trans(
"ProductStatusNotOnBuy"));
179 $this->tpl[
'status_buy'] =
$form->selectarray(
'statut_buy', $statutarray, $this->object->status_buy);
181 $this->tpl[
'description'] = $this->description;
182 $this->tpl[
'note'] = $this->note;
186 $duration_unit =
'<input name="duration_unit" type="radio" value="h"'.($this->object->duration_unit ==
'h' ?
' checked' :
'').
'>'.$langs->trans(
"Hour");
187 $duration_unit .=
' ';
188 $duration_unit .=
'<input name="duration_unit" type="radio" value="d"'.($this->object->duration_unit ==
'd' ?
' checked' :
'').
'>'.$langs->trans(
"Day");
189 $duration_unit .=
' ';
190 $duration_unit .=
'<input name="duration_unit" type="radio" value="w"'.($this->object->duration_unit ==
'w' ?
' checked' :
'').
'>'.$langs->trans(
"Week");
191 $duration_unit .=
' ';
192 $duration_unit .=
'<input name="duration_unit" type="radio" value="m"'.($this->object->duration_unit ==
'm' ?
' checked' :
'').
'>'.$langs->trans(
"Month");
193 $duration_unit .=
' ';
194 $duration_unit .=
'<input name="duration_unit" type="radio" value="y"'.($this->object->duration_unit ==
'y' ?
' checked' :
'').
'>'.$langs->trans(
"Year");
195 $this->tpl[
'duration_unit'] = $duration_unit;
198 if ($action ==
'view') {
200 $this->tpl[
'nblines'] = 4;
201 if ($this->object->is_photo_available($conf->service->multidir_output[$this->object->entity])) {
202 $this->tpl[
'photos'] = $this->
object->show_photos(
'product', $conf->service->multidir_output[$this->object->entity], 1, 1, 0, 0, 0, 80);
207 if ($this->object->duration_value > 1) {
208 $dur = array(
"h"=>$langs->trans(
"Hours"),
"d"=>$langs->trans(
"Days"),
"w"=>$langs->trans(
"Weeks"),
"m"=>$langs->trans(
"Months"),
"y"=>$langs->trans(
"Years"));
209 } elseif ($this->object->duration_value > 0) {
210 $dur = array(
"h"=>$langs->trans(
"Hour"),
"d"=>$langs->trans(
"Day"),
"w"=>$langs->trans(
"Week"),
"m"=>$langs->trans(
"Month"),
"y"=>$langs->trans(
"Year"));
212 $this->tpl[
'duration_unit'] = $langs->trans($dur[$this->object->duration_unit]);
217 if ($action ==
'list') {
218 $this->
LoadListDatas($limit, $offset, $sortfield, $sortorder);
230 global $conf, $langs;
232 $this->field_list = array();
234 $sql =
"SELECT rowid, name, alias, title, align, sort, search, visible, enabled, rang";
235 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_field_list";
236 $sql .=
" WHERE element = '".$this->db->escape($this->fieldListName).
"'";
237 $sql .=
" AND entity = ".$conf->entity;
238 $sql .=
" ORDER BY rang ASC";
246 $fieldlist = array();
248 $obj = $this->
db->fetch_object(
$resql);
250 $fieldlist[
"id"] = $obj->rowid;
251 $fieldlist[
"name"] = $obj->name;
252 $fieldlist[
"alias"] = $obj->alias;
253 $fieldlist[
"title"] = $langs->trans($obj->title);
254 $fieldlist[
"align"] = $obj->align;
255 $fieldlist[
"sort"] = $obj->sort;
256 $fieldlist[
"search"] = $obj->search;
257 $fieldlist[
"visible"] = $obj->visible;
258 $fieldlist[
"enabled"] =
verifCond($obj->enabled);
259 $fieldlist[
"order"] = $obj->rang;
261 array_push($this->field_list, $fieldlist);
285 global $search_categ, $sall, $sref, $search_barcode, $snom, $catid;
289 $sql =
'SELECT DISTINCT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,';
290 $sql .=
' p.fk_product_type, p.tms as datem,';
291 $sql .=
' p.duration, p.tosell as statut, p.seuil_stock_alerte';
292 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product as p';
295 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_product as cp";
298 if (
GETPOST(
"fourn_id",
'int') > 0) {
299 $fourn_id =
GETPOST(
"fourn_id",
'int');
300 $sql .=
", ".MAIN_DB_PREFIX.
"product_fournisseur_price as pfp";
302 $sql .=
" WHERE p.entity IN (".getEntity(
'product').
")";
304 $sql .=
" AND p.rowid = cp.fk_product";
307 $sql .=
" AND (p.ref LIKE '%".$this->db->escape($sall).
"%' OR p.label LIKE '%".$this->
db->escape($sall).
"%' OR p.description LIKE '%".$this->
db->escape($sall).
"%' OR p.note LIKE '%".$this->
db->escape($sall).
"%')";
310 $sql .=
" AND p.ref LIKE '%".$this->db->escape($sref).
"%'";
312 if ($search_barcode) {
313 $sql .=
" AND p.barcode LIKE '%".$this->db->escape($search_barcode).
"%'";
316 $sql .=
" AND p.label LIKE '%".$this->db->escape($snom).
"%'";
319 $sql .=
" AND p.tosell = ".((int)
GETPOST(
"tosell",
'int'));
322 $sql .=
" AND p.canvas = '".$this->db->escape(
GETPOST(
"canvas")).
"'";
325 $sql .=
" AND cp.fk_categorie = ".((int) $catid);
328 $sql .=
" AND p.rowid = pfp.fk_product AND pfp.fk_soc = ".((int) $fourn_id);
332 $sql .=
" AND cp.fk_categorie = ".((int) $search_categ);
334 $sql .= $this->
db->order($sortfield, $sortorder);
335 $sql .= $this->
db->plimit($limit + 1, $offset);
337 $this->list_datas = array();
344 while ($i < min($num, $limit)) {
346 $obj = $this->
db->fetch_object(
$resql);
348 $datas[
"id"] = $obj->rowid;
349 $datas[
"ref"] = $obj->ref;
350 $datas[
"label"] = $obj->label;
351 $datas[
"barcode"] = $obj->barcode;
352 $datas[
"statut"] = $obj->statut;
354 array_push($this->list_datas, $datas);