23 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
41 public $field_list = array();
42 public $list_datas = array();
54 public function __construct($db, $dirmodule, $targetmodule, $canvas, $card)
57 $this->dirmodule = $dirmodule;
58 $this->targetmodule = $targetmodule;
59 $this->canvas = $canvas;
62 $this->
name =
"product";
63 $this->definition =
"Product canvas (défaut)";
64 $this->fieldListName =
"product_default";
65 $this->next_prev_filter =
"canvas='product'";
81 global $limit, $offset, $sortfield, $sortorder;
82 global $conf, $langs, $user, $mysoc, $canvas;
83 global
$form, $formproduct;
86 if (!empty($id) || !empty($ref)) {
87 $tmpobject->fetch($id, $ref);
89 $this->
object = $tmpobject;
93 foreach ($this->
object as $key => $value) {
94 $this->tpl[$key] = $value;
100 $this->tpl[
'canvas'] = $this->canvas;
103 $this->tpl[
'id'] = $this->
object->id;
106 $this->tpl[
'ref'] = $this->
object->ref;
109 $this->tpl[
'label'] = $this->
object->label;
112 $this->tpl[
'description'] = nl2br($this->
description);
115 $this->tpl[
'status'] = $this->
object->getLibStatut(2);
118 $this->tpl[
'note'] = nl2br($this->object->note_private);
120 if ($action ==
'create') {
122 $this->tpl[
'price'] = $this->
object->price;
123 $this->tpl[
'price_min'] = $this->
object->price_min;
124 $this->tpl[
'price_base_type'] =
$form->selectPriceBaseType($this->price_base_type,
"price_base_type");
127 $this->tpl[
'tva_tx'] =
$form->load_tva(
"tva_tx", -1, $mysoc,
'');
130 if ($action ==
'view') {
133 $this->tpl[
'showrefnav'] =
$form->showrefnav($this->
object,
'ref',
'', 1,
'ref');
135 $titre = $langs->trans(
"CardProduct".$this->object->type);
141 $this->tpl[
'accountancyBuyCodeKey'] =
$form->editfieldkey(
"ProductAccountancyBuyCode",
'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
142 $this->tpl[
'accountancyBuyCodeVal'] =
$form->editfieldval(
"ProductAccountancyBuyCode",
'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
145 $this->tpl[
'accountancySellCodeKey'] =
$form->editfieldkey(
"ProductAccountancySellCode",
'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
146 $this->tpl[
'accountancySellCodeVal'] =
$form->editfieldval(
"ProductAccountancySellCode",
'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
149 $this->tpl[
'finished'] = $this->
object->finished;
150 $this->tpl[
'ref'] = $this->
object->ref;
151 $this->tpl[
'label'] = $this->
object->label;
152 $this->tpl[
'id'] = $this->
object->id;
153 $this->tpl[
'type'] = $this->
object->type;
154 $this->tpl[
'note'] = $this->
object->note_private;
155 $this->tpl[
'seuil_stock_alerte'] = $this->
object->seuil_stock_alerte;
157 if ($action ==
'create') {
159 $this->tpl[
'title'] = $langs->trans(
"NewProduct");
162 if ($action ==
'edit') {
163 $this->tpl[
'title'] = $langs->trans(
'Modify').
' '.$langs->trans(
'Product').
' : '.$this->
object->ref;
166 if ($action ==
'create' || $action ==
'edit') {
168 $statutarray = array(
'1' => $langs->trans(
"OnSell"),
'0' => $langs->trans(
"NotOnSell"));
169 $this->tpl[
'status'] =
$form->selectarray(
'statut', $statutarray, $this->object->status);
171 $statutarray = array(
'1' => $langs->trans(
"ProductStatusOnBuy"),
'0' => $langs->trans(
"ProductStatusNotOnBuy"));
172 $this->tpl[
'status_buy'] =
$form->selectarray(
'statut_buy', $statutarray, $this->object->status_buy);
174 $this->tpl[
'description'] = $this->
object->description;
175 $this->tpl[
'note'] = $this->
object->note;
178 $statutarray = array(
'1' => $langs->trans(
"Finished"),
'0' => $langs->trans(
"RowMaterial"));
179 $this->tpl[
'finished'] =
$form->selectarray(
'finished', $statutarray, $this->object->finished);
182 $this->tpl[
'weight'] = $this->
object->weight;
183 $this->tpl[
'weight_units'] = $formproduct->selectMeasuringUnits(
"weight_units",
"weight", $this->object->weight_units, 0, 2);
186 $this->tpl[
'length'] = $this->
object->length;
187 $this->tpl[
'length_units'] = $formproduct->selectMeasuringUnits(
"length_units",
"size", $this->object->length_units, 0, 2);
190 $this->tpl[
'surface'] = $this->
object->surface;
191 $this->tpl[
'surface_units'] = $formproduct->selectMeasuringUnits(
"surface_units",
"surface", $this->object->surface_units, 0, 2);
194 $this->tpl[
'volume'] = $this->
object->volume;
195 $this->tpl[
'volume_units'] = $formproduct->selectMeasuringUnits(
"volume_units",
"volume", $this->object->volume_units, 0, 2);
198 if ($action ==
'view') {
200 $this->tpl[
'nblines'] = 4;
201 if ($this->object->is_photo_available($conf->product->multidir_output[$this->object->entity])) {
202 $this->tpl[
'photos'] = $this->
object->show_photos(
'product', $conf->product->multidir_output[$this->object->entity], 1, 1, 0, 0, 0, 80);
206 $this->tpl[
'finished'] = $this->
object->getLibFinished();
209 if ($this->object->weight !=
'') {
210 $this->tpl[
'weight'] = $this->
object->weight.
" ".
measuringUnitString(0,
"weight", $this->object->weight_units);
214 if ($this->object->length !=
'') {
215 $this->tpl[
'length'] = $this->
object->length.
" ".
measuringUnitString(0,
"size", $this->object->length_units);
219 if ($this->object->surface !=
'') {
220 $this->tpl[
'surface'] = $this->
object->surface.
" ".
measuringUnitString(0,
"surface", $this->object->surface_units);
224 if ($this->object->volume !=
'') {
225 $this->tpl[
'volume'] = $this->
object->volume.
" ".
measuringUnitString(0,
"volume", $this->object->volume_units);
231 if ($action ==
'list') {
232 $this->
LoadListDatas($limit, $offset, $sortfield, $sortorder);
244 global $conf, $langs;
246 $this->field_list = array();
248 $sql =
"SELECT rowid, name, alias, title, align, sort, search, visible, enabled, rang";
249 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_field_list";
250 $sql .=
" WHERE element = '".$this->db->escape($this->fieldListName).
"'";
251 $sql .=
" AND entity = ".$conf->entity;
252 $sql .=
" ORDER BY rang ASC";
260 $fieldlist = array();
262 $obj = $this->
db->fetch_object(
$resql);
264 $fieldlist[
"id"] = $obj->rowid;
265 $fieldlist[
"name"] = $obj->name;
266 $fieldlist[
"alias"] = $obj->alias;
267 $fieldlist[
"title"] = $langs->trans($obj->title);
268 $fieldlist[
"align"] = $obj->align;
269 $fieldlist[
"sort"] = $obj->sort;
270 $fieldlist[
"search"] = $obj->search;
271 $fieldlist[
"visible"] = $obj->visible;
272 $fieldlist[
"enabled"] =
verifCond($obj->enabled);
273 $fieldlist[
"order"] = $obj->rang;
275 array_push($this->field_list, $fieldlist);
299 global $conf, $langs;
303 $this->list_datas = array();
306 $sall = trim((
GETPOST(
'search_all',
'alphanohtml') !=
'') ?
GETPOST(
'search_all',
'alphanohtml') :
GETPOST(
'sall',
'alphanohtml'));
308 foreach ($this->field_list as $field) {
309 if ($field[
'enabled']) {
310 $fieldname =
"s".$field[
'alias'];
311 $$fieldname =
GETPOST($fieldname);
315 $sql =
'SELECT DISTINCT ';
318 $sql .=
'p.rowid, p.price_base_type, p.fk_product_type, p.seuil_stock_alerte, p.entity';
321 foreach ($this->field_list as $field) {
322 if ($field[
'enabled']) {
323 $sql .=
", ".$field[
'name'].
" as ".$field[
'alias'];
327 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product as p';
328 $sql .=
" WHERE p.entity IN (".getEntity(
'product').
")";
333 foreach ($this->field_list as $field) {
334 if ($field[
'enabled']) {
335 $sql .= $clause.
" ".$field[
'name'].
" LIKE '%".$this->
db->escape($sall).
"%'";
345 foreach ($this->field_list as $field) {
346 if ($field[
'enabled']) {
347 $fieldname =
"s".$field[
'alias'];
349 $sql .=
" AND ".$field[
'name'].
" LIKE '%".$this->
db->escape(${$fieldname}).
"%'";
355 $sql .=
" AND p.tosell = ".((int)
GETPOST(
"tosell",
"int"));
358 $sql .=
" AND p.canvas = '".$this->db->escape(
GETPOST(
"canvas")).
"'";
360 $sql .= $this->
db->order($sortfield, $sortorder);
361 $sql .= $this->
db->plimit($limit + 1, $offset);
369 while ($i < min($num, $limit)) {
372 $obj = $this->
db->fetch_object(
$resql);
374 $datas[
"id"] = $obj->rowid;
376 foreach ($this->field_list as $field) {
377 if ($field[
'enabled']) {
378 $alias = $field[
'alias'];
380 if ($alias ==
'ref') {
381 $this->
id = $obj->rowid;
382 $this->
ref = $obj->$alias;
383 $this->
type = $obj->fk_product_type;
384 $this->entity = $obj->entity;
385 $datas[$alias] = $this->getNomUrl(1,
'', 24);
386 } elseif ($alias ==
'stock') {
388 if ($this->stock_reel < $obj->seuil_stock_alerte) {
389 $datas[$alias] = $this->stock_reel.
' '.
img_warning($langs->trans(
"StockTooLow"));
391 $datas[$alias] = $this->stock_reel;
393 } elseif ($alias ==
'label') {
394 $datas[$alias] =
dol_trunc($obj->$alias, 40);
395 } elseif (preg_match(
'/price/i', $alias)) {
396 $datas[$alias] =
price($obj->$alias);
397 } elseif ($alias ==
'datem') {
399 } elseif ($alias ==
'status') {
400 $datas[$alias] = $this->LibStatut($obj->$alias, 5);
402 $datas[$alias] = $obj->$alias;
407 array_push($this->list_datas, $datas);