dolibarr  18.0.6
actions_card_product.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2010-2018 Regis Houssin <regis.houssin@inodbox.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
23 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
24 
25 
30 {
31  public $targetmodule;
32  public $canvas;
33  public $card;
34 
35  public $object;
36 
38  public $tpl = array();
39 
40  // List of fiels for action=list
41  public $field_list = array();
42 
43 
53  public function __construct($db, $dirmodule, $targetmodule, $canvas, $card)
54  {
55  $this->db = $db;
56  $this->dirmodule = $dirmodule;
57  $this->targetmodule = $targetmodule;
58  $this->canvas = $canvas;
59  $this->card = $card;
60 
61  $this->name = "product";
62  $this->definition = "Product canvas (défaut)";
63  $this->fieldListName = "product_default";
64  $this->next_prev_filter = "canvas='product'";
65  }
66 
67 
68  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
77  public function assign_values(&$action, $id = 0, $ref = '')
78  {
79  // phpcs:enable
80  global $conf, $langs, $user, $mysoc, $canvas;
81  global $form, $formproduct;
82 
83  $tmpobject = new Product($this->db);
84  if (!empty($id) || !empty($ref)) {
85  $tmpobject->fetch($id, $ref);
86  }
87  $this->object = $tmpobject;
88 
89  foreach ($this->object as $key => $value) {
90  $this->tpl[$key] = $value;
91  }
92 
93  $this->tpl['error'] = get_htmloutput_errors($this->object->error, $this->object->errors);
94 
95  // canvas
96  $this->tpl['canvas'] = $this->canvas;
97 
98  // id
99  $this->tpl['id'] = $this->object->id;
100 
101  // Ref
102  $this->tpl['ref'] = $this->object->ref;
103 
104  // Label
105  $this->tpl['label'] = $this->object->label;
106 
107  // Description
108  $this->tpl['description'] = nl2br($this->description);
109 
110  // Statut
111  $this->tpl['status'] = $this->object->getLibStatut(2);
112 
113  // Note
114  $this->tpl['note'] = $this->object->note_private;
115 
116  if ($action == 'create') {
117  // Price
118  $this->tpl['price'] = $this->object->price;
119  $this->tpl['price_min'] = $this->object->price_min;
120  $this->tpl['price_base_type'] = $form->selectPriceBaseType($this->price_base_type, "price_base_type");
121 
122  // VAT
123  $this->tpl['tva_tx'] = $form->load_tva("tva_tx", -1, $mysoc, '');
124  }
125 
126  if ($action == 'view') {
127  $head = product_prepare_head($this->object);
128 
129  $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'ref', '', 1, 'ref');
130 
131  $titre = $langs->trans("CardProduct".$this->object->type);
132  $picto = ($this->object->type == Product::TYPE_SERVICE ? 'service' : 'product');
133  $this->tpl['showhead'] = dol_get_fiche_head($head, 'card', $titre, 0, $picto);
134  $this->tpl['showend'] = dol_get_fiche_end();
135 
136  // Accountancy buy code
137  $this->tpl['accountancyBuyCodeKey'] = $form->editfieldkey("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
138  $this->tpl['accountancyBuyCodeVal'] = $form->editfieldval("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
139 
140  // Accountancy sell code
141  $this->tpl['accountancySellCodeKey'] = $form->editfieldkey("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
142  $this->tpl['accountancySellCodeVal'] = $form->editfieldval("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
143  }
144 
145  $this->tpl['finished'] = $this->object->finished;
146  $this->tpl['ref'] = $this->object->ref;
147  $this->tpl['label'] = $this->object->label;
148  $this->tpl['id'] = $this->object->id;
149  $this->tpl['type'] = $this->object->type;
150  $this->tpl['note'] = $this->object->note_private;
151  $this->tpl['seuil_stock_alerte'] = $this->object->seuil_stock_alerte;
152 
153  if ($action == 'create') {
154  // Title
155  $this->tpl['title'] = $langs->trans("NewProduct");
156  }
157 
158  if ($action == 'edit') {
159  $this->tpl['title'] = $langs->trans('Modify').' '.$langs->trans('Product').' : '.$this->object->ref;
160  }
161 
162  if ($action == 'create' || $action == 'edit') {
163  // Status
164  $statutarray = array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell"));
165  $this->tpl['status'] = $form->selectarray('statut', $statutarray, $this->object->status);
166 
167  $statutarray = array('1' => $langs->trans("ProductStatusOnBuy"), '0' => $langs->trans("ProductStatusNotOnBuy"));
168  $this->tpl['status_buy'] = $form->selectarray('statut_buy', $statutarray, $this->object->status_buy);
169 
170  $this->tpl['description'] = $this->object->description;
171  $this->tpl['note'] = $this->object->note_private;
172 
173  // Finished
174  $statutarray = array('1' => $langs->trans("Finished"), '0' => $langs->trans("RowMaterial"));
175  $this->tpl['finished'] = $form->selectarray('finished', $statutarray, $this->object->finished);
176 
177  // Weight
178  $this->tpl['weight'] = $this->object->weight;
179  $this->tpl['weight_units'] = $formproduct->selectMeasuringUnits("weight_units", "weight", $this->object->weight_units, 0, 2);
180 
181  // Length
182  $this->tpl['length'] = $this->object->length;
183  $this->tpl['length_units'] = $formproduct->selectMeasuringUnits("length_units", "size", $this->object->length_units, 0, 2);
184 
185  // Surface
186  $this->tpl['surface'] = $this->object->surface;
187  $this->tpl['surface_units'] = $formproduct->selectMeasuringUnits("surface_units", "surface", $this->object->surface_units, 0, 2);
188 
189  // Volume
190  $this->tpl['volume'] = $this->object->volume;
191  $this->tpl['volume_units'] = $formproduct->selectMeasuringUnits("volume_units", "volume", $this->object->volume_units, 0, 2);
192  }
193 
194  if ($action == 'view') {
195  // Photo
196  $this->tpl['nblines'] = 4;
197  if ($this->object->is_photo_available($conf->product->multidir_output[$this->object->entity])) {
198  $this->tpl['photos'] = $this->object->show_photos('product', $conf->product->multidir_output[$this->object->entity], 1, 1, 0, 0, 0, 80);
199  }
200 
201  // Nature
202  $this->tpl['finished'] = $this->object->getLibFinished();
203 
204  // Weight
205  if ($this->object->weight != '') {
206  $this->tpl['weight'] = $this->object->weight." ".measuringUnitString(0, "weight", $this->object->weight_units);
207  }
208 
209  // Length
210  if ($this->object->length != '') {
211  $this->tpl['length'] = $this->object->length." ".measuringUnitString(0, "size", $this->object->length_units);
212  }
213 
214  // Surface
215  if ($this->object->surface != '') {
216  $this->tpl['surface'] = $this->object->surface." ".measuringUnitString(0, "surface", $this->object->surface_units);
217  }
218 
219  // Volume
220  if ($this->object->volume != '') {
221  $this->tpl['volume'] = $this->object->volume." ".measuringUnitString(0, "volume", $this->object->volume_units);
222  }
223 
224  $this->tpl['fiche_end'] = dol_get_fiche_end();
225  }
226  }
227 
228 
234  private function getFieldListCanvas()
235  {
236  global $conf, $langs;
237 
238  $this->field_list = array();
239 
240  $sql = "SELECT rowid, name, alias, title, align, sort, search, visible, enabled, rang";
241  $sql .= " FROM ".MAIN_DB_PREFIX."c_field_list";
242  $sql .= " WHERE element = '".$this->db->escape($this->fieldListName)."'";
243  $sql .= " AND entity = ".$conf->entity;
244  $sql .= " ORDER BY rang ASC";
245 
246  $resql = $this->db->query($sql);
247  if ($resql) {
248  $num = $this->db->num_rows($resql);
249 
250  $i = 0;
251  while ($i < $num) {
252  $fieldlist = array();
253 
254  $obj = $this->db->fetch_object($resql);
255 
256  $fieldlist["id"] = $obj->rowid;
257  $fieldlist["name"] = $obj->name;
258  $fieldlist["alias"] = $obj->alias;
259  $fieldlist["title"] = $langs->trans($obj->title);
260  $fieldlist["align"] = $obj->align;
261  $fieldlist["sort"] = $obj->sort;
262  $fieldlist["search"] = $obj->search;
263  $fieldlist["visible"] = $obj->visible;
264  $fieldlist["enabled"] = verifCond($obj->enabled);
265  $fieldlist["order"] = $obj->rang;
266 
267  array_push($this->field_list, $fieldlist);
268 
269  $i++;
270  }
271  $this->db->free($resql);
272  } else {
273  dol_print_error($this->db, $sql);
274  }
275  }
276 }
Class with controller methods for product canvas.
getFieldListCanvas()
Fetch field list.
__construct($db, $dirmodule, $targetmodule, $canvas, $card)
Constructor.
assign_values(&$action, $id=0, $ref='')
Assign custom values for canvas (for example into this->tpl to be used by templates)
Class to manage products or services.
const TYPE_SERVICE
Service.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
get_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Get formated error messages to output (Used to show messages on html output).
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
verifCond($strToEvaluate)
Verify if condition in string is ok or not.
product_prepare_head($object)
Prepare array with list of tabs.
Definition: product.lib.php:36
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:123