dolibarr  17.0.4
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 $limit, $offset, $sortfield, $sortorder;
81  global $conf, $langs, $user, $mysoc, $canvas;
82  global $form, $formproduct;
83 
84  $tmpobject = new Product($this->db);
85  if (!empty($id) || !empty($ref)) {
86  $tmpobject->fetch($id, $ref);
87  }
88  $this->object = $tmpobject;
89 
90  foreach ($this->object as $key => $value) {
91  $this->tpl[$key] = $value;
92  }
93 
94  $this->tpl['error'] = get_htmloutput_errors($this->object->error, $this->object->errors);
95 
96  // canvas
97  $this->tpl['canvas'] = $this->canvas;
98 
99  // id
100  $this->tpl['id'] = $this->object->id;
101 
102  // Ref
103  $this->tpl['ref'] = $this->object->ref;
104 
105  // Label
106  $this->tpl['label'] = $this->object->label;
107 
108  // Description
109  $this->tpl['description'] = nl2br($this->description);
110 
111  // Statut
112  $this->tpl['status'] = $this->object->getLibStatut(2);
113 
114  // Note
115  $this->tpl['note'] = nl2br($this->object->note_private);
116 
117  if ($action == 'create') {
118  // Price
119  $this->tpl['price'] = $this->object->price;
120  $this->tpl['price_min'] = $this->object->price_min;
121  $this->tpl['price_base_type'] = $form->selectPriceBaseType($this->price_base_type, "price_base_type");
122 
123  // VAT
124  $this->tpl['tva_tx'] = $form->load_tva("tva_tx", -1, $mysoc, '');
125  }
126 
127  if ($action == 'view') {
128  $head = product_prepare_head($this->object);
129 
130  $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'ref', '', 1, 'ref');
131 
132  $titre = $langs->trans("CardProduct".$this->object->type);
133  $picto = ($this->object->type == Product::TYPE_SERVICE ? 'service' : 'product');
134  $this->tpl['showhead'] = dol_get_fiche_head($head, 'card', $titre, 0, $picto);
135  $this->tpl['showend'] = dol_get_fiche_end();
136 
137  // Accountancy buy code
138  $this->tpl['accountancyBuyCodeKey'] = $form->editfieldkey("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
139  $this->tpl['accountancyBuyCodeVal'] = $form->editfieldval("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
140 
141  // Accountancy sell code
142  $this->tpl['accountancySellCodeKey'] = $form->editfieldkey("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
143  $this->tpl['accountancySellCodeVal'] = $form->editfieldval("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
144  }
145 
146  $this->tpl['finished'] = $this->object->finished;
147  $this->tpl['ref'] = $this->object->ref;
148  $this->tpl['label'] = $this->object->label;
149  $this->tpl['id'] = $this->object->id;
150  $this->tpl['type'] = $this->object->type;
151  $this->tpl['note'] = $this->object->note_private;
152  $this->tpl['seuil_stock_alerte'] = $this->object->seuil_stock_alerte;
153 
154  if ($action == 'create') {
155  // Title
156  $this->tpl['title'] = $langs->trans("NewProduct");
157  }
158 
159  if ($action == 'edit') {
160  $this->tpl['title'] = $langs->trans('Modify').' '.$langs->trans('Product').' : '.$this->object->ref;
161  }
162 
163  if ($action == 'create' || $action == 'edit') {
164  // Status
165  $statutarray = array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell"));
166  $this->tpl['status'] = $form->selectarray('statut', $statutarray, $this->object->status);
167 
168  $statutarray = array('1' => $langs->trans("ProductStatusOnBuy"), '0' => $langs->trans("ProductStatusNotOnBuy"));
169  $this->tpl['status_buy'] = $form->selectarray('statut_buy', $statutarray, $this->object->status_buy);
170 
171  $this->tpl['description'] = $this->object->description;
172  $this->tpl['note'] = $this->object->note;
173 
174  // Finished
175  $statutarray = array('1' => $langs->trans("Finished"), '0' => $langs->trans("RowMaterial"));
176  $this->tpl['finished'] = $form->selectarray('finished', $statutarray, $this->object->finished);
177 
178  // Weight
179  $this->tpl['weight'] = $this->object->weight;
180  $this->tpl['weight_units'] = $formproduct->selectMeasuringUnits("weight_units", "weight", $this->object->weight_units, 0, 2);
181 
182  // Length
183  $this->tpl['length'] = $this->object->length;
184  $this->tpl['length_units'] = $formproduct->selectMeasuringUnits("length_units", "size", $this->object->length_units, 0, 2);
185 
186  // Surface
187  $this->tpl['surface'] = $this->object->surface;
188  $this->tpl['surface_units'] = $formproduct->selectMeasuringUnits("surface_units", "surface", $this->object->surface_units, 0, 2);
189 
190  // Volume
191  $this->tpl['volume'] = $this->object->volume;
192  $this->tpl['volume_units'] = $formproduct->selectMeasuringUnits("volume_units", "volume", $this->object->volume_units, 0, 2);
193  }
194 
195  if ($action == 'view') {
196  // Photo
197  $this->tpl['nblines'] = 4;
198  if ($this->object->is_photo_available($conf->product->multidir_output[$this->object->entity])) {
199  $this->tpl['photos'] = $this->object->show_photos('product', $conf->product->multidir_output[$this->object->entity], 1, 1, 0, 0, 0, 80);
200  }
201 
202  // Nature
203  $this->tpl['finished'] = $this->object->getLibFinished();
204 
205  // Weight
206  if ($this->object->weight != '') {
207  $this->tpl['weight'] = $this->object->weight." ".measuringUnitString(0, "weight", $this->object->weight_units);
208  }
209 
210  // Length
211  if ($this->object->length != '') {
212  $this->tpl['length'] = $this->object->length." ".measuringUnitString(0, "size", $this->object->length_units);
213  }
214 
215  // Surface
216  if ($this->object->surface != '') {
217  $this->tpl['surface'] = $this->object->surface." ".measuringUnitString(0, "surface", $this->object->surface_units);
218  }
219 
220  // Volume
221  if ($this->object->volume != '') {
222  $this->tpl['volume'] = $this->object->volume." ".measuringUnitString(0, "volume", $this->object->volume_units);
223  }
224 
225  $this->tpl['fiche_end'] = dol_get_fiche_end();
226  }
227  }
228 
229 
235  private function getFieldListCanvas()
236  {
237  global $conf, $langs;
238 
239  $this->field_list = array();
240 
241  $sql = "SELECT rowid, name, alias, title, align, sort, search, visible, enabled, rang";
242  $sql .= " FROM ".MAIN_DB_PREFIX."c_field_list";
243  $sql .= " WHERE element = '".$this->db->escape($this->fieldListName)."'";
244  $sql .= " AND entity = ".$conf->entity;
245  $sql .= " ORDER BY rang ASC";
246 
247  $resql = $this->db->query($sql);
248  if ($resql) {
249  $num = $this->db->num_rows($resql);
250 
251  $i = 0;
252  while ($i < $num) {
253  $fieldlist = array();
254 
255  $obj = $this->db->fetch_object($resql);
256 
257  $fieldlist["id"] = $obj->rowid;
258  $fieldlist["name"] = $obj->name;
259  $fieldlist["alias"] = $obj->alias;
260  $fieldlist["title"] = $langs->trans($obj->title);
261  $fieldlist["align"] = $obj->align;
262  $fieldlist["sort"] = $obj->sort;
263  $fieldlist["search"] = $obj->search;
264  $fieldlist["visible"] = $obj->visible;
265  $fieldlist["enabled"] = verifCond($obj->enabled);
266  $fieldlist["order"] = $obj->rang;
267 
268  array_push($this->field_list, $fieldlist);
269 
270  $i++;
271  }
272  $this->db->free($resql);
273  } else {
274  dol_print_error($this->db, $sql);
275  }
276  }
277 }
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') &&!empty($user->rights->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') &&!empty($user->rights->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)) $resql
Social contributions to pay.
Definition: index.php:745
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='')
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:35
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:122
$conf db
API class for accounts.
Definition: inc.php:41