dolibarr 19.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
23include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
24
25
30{
34 public $db;
35
36 public $dirmodule;
37 public $targetmodule;
38 public $canvas;
39 public $card;
40
41 public $name;
42 public $definition;
43 public $description;
44 public $price_base_type;
45 public $accountancy_code_sell;
46 public $accountancy_code_buy;
47 public $fieldListName;
48 public $next_prev_filter;
49
51 public $object;
52
54 public $tpl = array();
55
56 // List of fiels for action=list
57 public $field_list = array();
58
62 public $error = '';
63
67 public $errors = array();
68
69
79 public function __construct($db, $dirmodule, $targetmodule, $canvas, $card)
80 {
81 $this->db = $db;
82 $this->dirmodule = $dirmodule;
83 $this->targetmodule = $targetmodule;
84 $this->canvas = $canvas;
85 $this->card = $card;
86
87 $this->name = "product";
88 $this->definition = "Product canvas (default)";
89 $this->fieldListName = "product_default";
90 $this->next_prev_filter = "canvas='product'";
91 }
92
93
94 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
103 public function assign_values(&$action, $id = 0, $ref = '')
104 {
105 // phpcs:enable
106 global $conf, $langs, $user, $mysoc, $canvas;
107 global $form, $formproduct;
108
109 $tmpobject = new Product($this->db);
110 if (!empty($id) || !empty($ref)) {
111 $tmpobject->fetch($id, $ref);
112 }
113 $this->object = $tmpobject;
114
115 foreach ($this->object as $key => $value) {
116 $this->tpl[$key] = $value;
117 }
118
119 $this->tpl['error'] = get_htmloutput_errors($this->object->error, $this->object->errors);
120
121 // canvas
122 $this->tpl['canvas'] = $this->canvas;
123
124 // id
125 $this->tpl['id'] = $this->object->id;
126
127 // Ref
128 $this->tpl['ref'] = $this->object->ref;
129
130 // Label
131 $this->tpl['label'] = $this->object->label;
132
133 // Description
134 $this->tpl['description'] = nl2br($this->description);
135
136 // Statut
137 $this->tpl['status'] = $this->object->getLibStatut(2);
138
139 // Note
140 $this->tpl['note'] = $this->object->note_private;
141
142 if ($action == 'create') {
143 // Price
144 $this->tpl['price'] = $this->object->price;
145 $this->tpl['price_min'] = $this->object->price_min;
146 $this->tpl['price_base_type'] = $form->selectPriceBaseType($this->price_base_type, "price_base_type");
147
148 // VAT
149 $this->tpl['tva_tx'] = $form->load_tva("tva_tx", -1, $mysoc, '');
150 }
151
152 if ($action == 'view') {
153 $head = product_prepare_head($this->object);
154
155 $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'ref', '', 1, 'ref');
156
157 $titre = $langs->trans("CardProduct".$this->object->type);
158 $picto = ($this->object->type == Product::TYPE_SERVICE ? 'service' : 'product');
159 $this->tpl['showhead'] = dol_get_fiche_head($head, 'card', $titre, 0, $picto);
160 $this->tpl['showend'] = dol_get_fiche_end();
161
162 // Accountancy buy code
163 $this->tpl['accountancyBuyCodeKey'] = $form->editfieldkey("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
164 $this->tpl['accountancyBuyCodeVal'] = $form->editfieldval("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
165
166 // Accountancy sell code
167 $this->tpl['accountancySellCodeKey'] = $form->editfieldkey("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
168 $this->tpl['accountancySellCodeVal'] = $form->editfieldval("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
169 }
170
171 $this->tpl['finished'] = $this->object->finished;
172 $this->tpl['ref'] = $this->object->ref;
173 $this->tpl['label'] = $this->object->label;
174 $this->tpl['id'] = $this->object->id;
175 $this->tpl['type'] = $this->object->type;
176 $this->tpl['note'] = $this->object->note_private;
177 $this->tpl['seuil_stock_alerte'] = $this->object->seuil_stock_alerte;
178
179 if ($action == 'create') {
180 // Title
181 $this->tpl['title'] = $langs->trans("NewProduct");
182 }
183
184 if ($action == 'edit') {
185 $this->tpl['title'] = $langs->trans('Modify').' '.$langs->trans('Product').' : '.$this->object->ref;
186 }
187
188 if ($action == 'create' || $action == 'edit') {
189 // Status
190 $statutarray = array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell"));
191 $this->tpl['status'] = $form->selectarray('statut', $statutarray, $this->object->status);
192
193 $statutarray = array('1' => $langs->trans("ProductStatusOnBuy"), '0' => $langs->trans("ProductStatusNotOnBuy"));
194 $this->tpl['status_buy'] = $form->selectarray('statut_buy', $statutarray, $this->object->status_buy);
195
196 $this->tpl['description'] = $this->object->description;
197 $this->tpl['note'] = $this->object->note_private;
198
199 // Finished
200 $statutarray = array('1' => $langs->trans("Finished"), '0' => $langs->trans("RowMaterial"));
201 $this->tpl['finished'] = $form->selectarray('finished', $statutarray, $this->object->finished);
202
203 // Weight
204 $this->tpl['weight'] = $this->object->weight;
205 $this->tpl['weight_units'] = $formproduct->selectMeasuringUnits("weight_units", "weight", $this->object->weight_units, 0, 2);
206
207 // Length
208 $this->tpl['length'] = $this->object->length;
209 $this->tpl['length_units'] = $formproduct->selectMeasuringUnits("length_units", "size", $this->object->length_units, 0, 2);
210
211 // Surface
212 $this->tpl['surface'] = $this->object->surface;
213 $this->tpl['surface_units'] = $formproduct->selectMeasuringUnits("surface_units", "surface", $this->object->surface_units, 0, 2);
214
215 // Volume
216 $this->tpl['volume'] = $this->object->volume;
217 $this->tpl['volume_units'] = $formproduct->selectMeasuringUnits("volume_units", "volume", $this->object->volume_units, 0, 2);
218 }
219
220 if ($action == 'view') {
221 // Photo
222 $this->tpl['nblines'] = 4;
223 if ($this->object->is_photo_available($conf->product->multidir_output[$this->object->entity])) {
224 $this->tpl['photos'] = $this->object->show_photos('product', $conf->product->multidir_output[$this->object->entity], 1, 1, 0, 0, 0, 80);
225 }
226
227 // Nature
228 $this->tpl['finished'] = $this->object->getLibFinished();
229
230 // Weight
231 if ($this->object->weight != '') {
232 $this->tpl['weight'] = $this->object->weight." ".measuringUnitString(0, "weight", $this->object->weight_units);
233 }
234
235 // Length
236 if ($this->object->length != '') {
237 $this->tpl['length'] = $this->object->length." ".measuringUnitString(0, "size", $this->object->length_units);
238 }
239
240 // Surface
241 if ($this->object->surface != '') {
242 $this->tpl['surface'] = $this->object->surface." ".measuringUnitString(0, "surface", $this->object->surface_units);
243 }
244
245 // Volume
246 if ($this->object->volume != '') {
247 $this->tpl['volume'] = $this->object->volume." ".measuringUnitString(0, "volume", $this->object->volume_units);
248 }
249
250 $this->tpl['fiche_end'] = dol_get_fiche_end();
251 }
252 }
253
254
260 private function getFieldListCanvas()
261 {
262 global $conf, $langs;
263
264 $this->field_list = array();
265
266 $sql = "SELECT rowid, name, alias, title, align, sort, search, visible, enabled, rang";
267 $sql .= " FROM ".MAIN_DB_PREFIX."c_field_list";
268 $sql .= " WHERE element = '".$this->db->escape($this->fieldListName)."'";
269 $sql .= " AND entity = ".$conf->entity;
270 $sql .= " ORDER BY rang ASC";
271
272 $resql = $this->db->query($sql);
273 if ($resql) {
274 $num = $this->db->num_rows($resql);
275
276 $i = 0;
277 while ($i < $num) {
278 $fieldlist = array();
279
280 $obj = $this->db->fetch_object($resql);
281
282 $fieldlist["id"] = $obj->rowid;
283 $fieldlist["name"] = $obj->name;
284 $fieldlist["alias"] = $obj->alias;
285 $fieldlist["title"] = $langs->trans($obj->title);
286 $fieldlist["align"] = $obj->align;
287 $fieldlist["sort"] = $obj->sort;
288 $fieldlist["search"] = $obj->search;
289 $fieldlist["visible"] = $obj->visible;
290 $fieldlist["enabled"] = verifCond($obj->enabled);
291 $fieldlist["order"] = $obj->rang;
292
293 array_push($this->field_list, $fieldlist);
294
295 $i++;
296 }
297 $this->db->free($resql);
298 } else {
299 dol_print_error($this->db, $sql);
300 }
301 }
302}
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.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after 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.
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:124