dolibarr 22.0.5
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
5 * Copyright (C) 2005-2015 Regis Houssin <regis.houssin@capnetworks.com>
6 * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
7 * Copyright (C) 2006 Auguria SARL <info@auguria.org>
8 * Copyright (C) 2010-2015 Juanjo Menent <jmenent@2byte.es>
9 * Copyright (C) 2013-2016 Marcos García <marcosgdf@gmail.com>
10 * Copyright (C) 2012-2013 Cédric Salvador <csalvador@gpcsolutions.fr>
11 * Copyright (C) 2011-2023 Alexandre Spangaro <alexandre@inovea-conseil.com>
12 * Copyright (C) 2014 Cédric Gross <c.gross@kreiz-it.fr>
13 * Copyright (C) 2014-2015 Ferran Marcet <fmarcet@2byte.es>
14 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
15 * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
16 * Copyright (C) 2016-2022 Charlene Benke <charlene@patas-monkey.com>
17 * Copyright (C) 2016 Meziane Sof <virtualsof@yahoo.fr>
18 * Copyright (C) 2017 Josep Lluís Amador <joseplluis@lliuretic.cat>
19 * Copyright (C) 2019-2024 Frédéric France <frederic.france@free.fr>
20 * Copyright (C) 2019-2020 Thibault FOUCART <support@ptibogxiv.net>
21 * Copyright (C) 2020 Pierre Ardoin <mapiolca@me.com>
22 * Copyright (C) 2022 Vincent de Grandpré <vincent@de-grandpre.quebec>
23 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
24 *
25 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation; either version 3 of the License, or
28 * (at your option) any later version.
29 *
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
34 *
35 * You should have received a copy of the GNU General Public License
36 * along with this program. If not, see <https://www.gnu.org/licenses/>.
37 */
38
46// Load Dolibarr environment
47require '../main.inc.php';
48require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
49require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
50require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
51require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
52require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
53require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
54require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
55require_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.class.php';
56require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
57require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
58require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
67if (isModEnabled('propal')) {
68 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
69}
70if (isModEnabled('invoice')) {
71 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
72}
73if (isModEnabled('order')) {
74 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
75}
76if (isModEnabled('accounting')) {
77 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
78 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
79 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
80}
81if (isModEnabled('bom')) {
82 require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
83 $langs->load("mrp");
84}
85if (isModEnabled('workstation')) {
86 require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php';
87}
88
89// Load translation files required by the page
90$langs->loadLangs(array('products', 'other'));
91if (isModEnabled('stock')) {
92 $langs->load("stocks");
93}
94if (isModEnabled('invoice')) {
95 $langs->load("bills");
96}
97if (isModEnabled('productbatch')) {
98 $langs->load("productbatch");
99}
100
101$backtopageforcancel = GETPOST('backtopageforcancel');
102
103$mesg = '';
104$error = 0;
105$errors = array();
106
107$refalreadyexists = 0;
108$formbarcode = null;
109
110// Get parameters
111$id = GETPOSTINT('id');
112if (getDolGlobalString('MAIN_SECURITY_ALLOW_UNSECURED_REF_LABELS')) {
113 $ref = (GETPOSTISSET('ref') ? GETPOST('ref', 'nohtml') : null);
114} else {
115 $ref = (GETPOSTISSET('ref') ? GETPOST('ref', 'alpha') : null);
116}
117$type = (GETPOSTISSET('type') ? GETPOSTINT('type') : Product::TYPE_PRODUCT);
118$action = (GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view');
119$cancel = GETPOST('cancel', 'alpha');
120$backtopage = GETPOST('backtopage', 'alpha');
121$confirm = GETPOST('confirm', 'alpha');
122$socid = GETPOSTINT('socid');
123$duration_value = GETPOST('duration_value'); // duration value can be an empty string
124$duration_unit = GETPOST('duration_unit', 'alpha');
125
126$accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
127$accountancy_code_sell_intra = GETPOST('accountancy_code_sell_intra', 'alpha');
128$accountancy_code_sell_export = GETPOST('accountancy_code_sell_export', 'alpha');
129$accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
130$accountancy_code_buy_intra = GETPOST('accountancy_code_buy_intra', 'alpha');
131$accountancy_code_buy_export = GETPOST('accountancy_code_buy_export', 'alpha');
132
133$checkmandatory = GETPOST('accountancy_code_buy_export', 'alpha');
134
135// by default 'alphanohtml' (better security); hidden conf MAIN_SECURITY_ALLOW_UNSECURED_LABELS_WITH_HTML allows basic html
136if (getDolGlobalString('MAIN_SECURITY_ALLOW_UNSECURED_REF_LABELS')) {
137 $label_security_check = 'nohtml';
138} else {
139 $label_security_check = !getDolGlobalString('MAIN_SECURITY_ALLOW_UNSECURED_LABELS_WITH_HTML') ? 'alphanohtml' : 'restricthtml';
140}
141
142if (!empty($user->socid)) {
143 $socid = $user->socid;
144}
145
146// Load object modCodeProduct
147$module = getDolGlobalString('PRODUCT_CODEPRODUCT_ADDON', 'mod_codeproduct_leopard');
148if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php') {
149 $module = substr($module, 0, dol_strlen($module) - 4);
150}
151$result = dol_include_once('/core/modules/product/'.$module.'.php');
152if ($result > 0) {
153 $modCodeProduct = new $module();
154}
155
156$object = new Product($db);
157$object->type = $type; // so test later to fill $usercancxxx is correct
158$extrafields = new ExtraFields($db);
159
160// fetch optionals attributes and labels
161$extrafields->fetch_name_optionals_label($object->table_element);
162
163if ($id > 0 || !empty($ref)) {
164 $result = $object->fetch($id, (string) $ref);
165 if ($result < 0) {
166 dol_print_error($db, $object->error, $object->errors);
167 }
168 $entity = (empty($object->entity) ? $conf->entity : $object->entity);
169 if (isModEnabled("product")) {
170 $upload_dir = $conf->product->multidir_output[$entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref);
171 } elseif (isModEnabled("service")) {
172 $upload_dir = $conf->service->multidir_output[$entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref);
173 }
174
175 if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { // For backward compatibility, we scan also old dirs
176 if (isModEnabled("product")) {
177 $upload_dirold = $conf->product->multidir_output[$entity].'/'.substr(substr("000".$object->id, -2), 1, 1).'/'.substr(substr("000".$object->id, -2), 0, 1).'/'.$object->id."/photos";
178 } else {
179 $upload_dirold = $conf->service->multidir_output[$entity].'/'.substr(substr("000".$object->id, -2), 1, 1).'/'.substr(substr("000".$object->id, -2), 0, 1).'/'.$object->id."/photos";
180 }
181 }
182}
183
184$modulepart = 'product';
185
186// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
187$canvas = !empty($object->canvas) ? $object->canvas : GETPOST("canvas");
188$objcanvas = null;
189if (!empty($canvas)) {
190 require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
191 $objcanvas = new Canvas($db, $action);
192 $objcanvas->getCanvas('product', 'card', $canvas);
193}
194
195// Security check
196$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
197$fieldtype = (!empty($id) ? 'rowid' : 'ref');
198
199// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
200$hookmanager->initHooks(array('productcard', 'globalcard'));
201
202if ($object->id > 0) {
203 if ($object->type == $object::TYPE_PRODUCT) {
204 restrictedArea($user, 'produit', $object->id, 'product&product', '', '');
205 }
206 if ($object->type == $object::TYPE_SERVICE) {
207 restrictedArea($user, 'service', $object->id, 'product&product', '', '');
208 }
209} else {
210 restrictedArea($user, 'produit|service', 0, 'product&product', '', '', $fieldtype);
211}
212
213// Permissions
214$usercanread = (($object->type == Product::TYPE_PRODUCT && $user->hasRight('produit', 'lire')) || ($object->type == Product::TYPE_SERVICE && $user->hasRight('service', 'lire')));
215$usercancreate = (($object->type == Product::TYPE_PRODUCT && $user->hasRight('produit', 'creer')) || ($object->type == Product::TYPE_SERVICE && $user->hasRight('service', 'creer')));
216$usercandelete = (($object->type == Product::TYPE_PRODUCT && $user->hasRight('produit', 'supprimer')) || ($object->type == Product::TYPE_SERVICE && $user->hasRight('service', 'supprimer')));
217$permissiontoeditextra = $usercancreate;
218if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
219 // For action 'update_extras', is there a specific permission set for the attribute to update
220 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
221}
222
223
224/*
225 * Actions
226 */
227
228if ($cancel) {
229 $action = '';
230}
231
232$createbarcode = isModEnabled('barcode');
233if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('barcode', 'creer_advance')) {
234 $createbarcode = 0;
235}
236
237$parameters = array('id' => $id, 'ref' => $ref, 'objcanvas' => $objcanvas);
238$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
239if ($reshook < 0) {
240 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
241}
242
243if (empty($reshook)) {
244 $backurlforlist = DOL_URL_ROOT.'/product/list.php?type='.$type;
245
246 if (empty($backtopage) || ($cancel && empty($id))) {
247 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
248 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
249 $backtopage = $backurlforlist;
250 } else {
251 $backtopage = DOL_URL_ROOT.'/product/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
252 }
253 }
254 }
255
256 if ($cancel) {
257 if (!empty($backtopageforcancel)) {
258 header("Location: ".$backtopageforcancel);
259 exit;
260 } elseif (!empty($backtopage)) {
261 header("Location: ".$backtopage);
262 exit;
263 }
264 $action = '';
265 }
266 // merge products
267 if ($action == 'confirm_merge' && $confirm == 'yes' && $user->hasRight('societe', 'creer')) {
268 $error = 0;
269 $productOriginId = GETPOSTINT('product_origin');
270 $productOrigin = new Product($db);
271
272 if ($productOriginId <= 0) {
273 $langs->load('errors');
274 setEventMessages($langs->trans('ErrorProductIdIsMandatory', $langs->transnoentitiesnoconv('MergeOriginProduct')), null, 'errors');
275 } else {
276 if (!$error && $productOrigin->fetch($productOriginId) < 1) {
277 setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
278 $error++;
279 }
280
281 if (!$error) {
282 // TODO Move the merge function into class of object.
283 $db->begin();
284
285 // Recopy some data
286 $listofproperties = array(
287 'ref',
288 'ref_ext',
289 'label',
290 'description',
291 'url',
292 'barcode',
293 'fk_barcode_type',
294 'import_key',
295 'mandatory_period',
296 'accountancy_code_buy',
297 'accountancy_code_buy_intra',
298 'accountancy_code_buy_export',
299 'accountancy_code_sell',
300 'accountancy_code_sell_intra',
301 'accountancy_code_sell_export'
302 );
303 foreach ($listofproperties as $property) {
304 if (empty($object->$property)) {
305 $object->$property = $productOrigin->$property;
306 }
307 }
308 // Concat some data
309 $listofproperties = array(
310 'note_public', 'note_private'
311 );
312 foreach ($listofproperties as $property) {
313 $object->$property = dol_concatdesc($object->$property, $productOrigin->$property);
314 }
315
316 // Merge extrafields
317 if (is_array($productOrigin->array_options)) {
318 foreach ($productOrigin->array_options as $key => $val) {
319 if (empty($object->array_options[$key])) {
320 $object->array_options[$key] = $val;
321 }
322 }
323 }
324
325 // Merge categories
326 $static_cat = new Categorie($db);
327 $custcats_ori = $static_cat->containing($productOrigin->id, 'product', 'id');
328 $custcats = $static_cat->containing($object->id, 'product', 'id');
329 $custcats = array_merge($custcats, $custcats_ori);
330 $object->setCategories($custcats);
331
332 // If product has a new code that is same than origin, we clean origin code to avoid duplicate key from database unique keys.
333 if ($productOrigin->barcode == $object->barcode) {
334 dol_syslog("We clean customer and supplier code so we will be able to make the update of target");
335 $productOrigin->barcode = '';
336 //$productOrigin->update($productOrigin->id, $user, 0, 'merge');
337 }
338
339 // Update
340 $result = $object->update($object->id, $user, 0, 'merge');
341 if ($result <= 0) {
342 setEventMessages($object->error, $object->errors, 'errors');
343 $error++;
344 }
345
346 // Move links
347 if (!$error) {
348 // TODO add this functionality into the api_products.class.php
349 // TODO Mutualise the list into object product.class.php
350 $objects = array(
351 'ActionComm' => '/comm/action/class/actioncomm.class.php',
352 'Bom' => '/bom/class/bom.class.php',
353 // do not use Categorie, it cause foreign key error, merge is done before
354 //'Categorie' => '/categories/class/categorie.class.php',
355 'Commande' => '/commande/class/commande.class.php',
356 'CommandeFournisseur' => '/fourn/class/fournisseur.commande.class.php',
357 'Contrat' => '/contrat/class/contrat.class.php',
358 'Delivery' => '/delivery/class/delivery.class.php',
359 'Facture' => '/compta/facture/class/facture.class.php',
360 'FactureFournisseur' => '/fourn/class/fournisseur.facture.class.php',
361 'FactureRec' => '/compta/facture/class/facture-rec.class.php',
362 'FichinterRec' => '/fichinter/class/fichinterrec.class.php',
363 'ProductFournisseur' => '/fourn/class/fournisseur.product.class.php',
364 'Propal' => '/comm/propal/class/propal.class.php',
365 'Reception' => '/reception/class/reception.class.php',
366 'SupplierProposal' => '/supplier_proposal/class/supplier_proposal.class.php',
367 );
368
369 // First, all core objects must update their tables
370 foreach ($objects as $object_name => $object_file) {
371 require_once DOL_DOCUMENT_ROOT.$object_file;
372
373 if (!$error && !$object_name::replaceProduct($db, $productOrigin->id, $object->id)) {
374 $error++;
375 setEventMessages($db->lasterror(), null, 'errors');
376 break;
377 }
378 }
379 }
380
381 // External modules should update their ones too
382 if (!$error) {
383 $parameters = array('soc_origin' => $productOrigin->id, 'soc_dest' => $object->id);
384 $reshook = $hookmanager->executeHooks(
385 'replaceProduct',
386 $parameters,
387 $object,
388 $action
389 );
390
391 if ($reshook < 0) {
392 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
393 $error++;
394 }
395 }
396
397
398 if (!$error) {
399 $object->context = array(
400 'merge' => 1,
401 'mergefromid' => $productOrigin->id,
402 );
403
404 // Call trigger
405 $result = $object->call_trigger('PRODUCT_MODIFY', $user);
406 if ($result < 0) {
407 setEventMessages($object->error, $object->errors, 'errors');
408 $error++;
409 }
410 // End call triggers
411 }
412
413 if (!$error) {
414 // Move files from the dir of the product being deleted into the dir of the product kept.
415 // This must happen on success only, and before the deletion: the filesystem is not part
416 // of the transaction, so moving the files on the failing path stripped the origin product
417 // of its documents while the database was rolled back, and Product::delete() removes the
418 // directory of the product, so a move placed after it finds nothing left to move.
419 if (!empty($conf->product->multidir_output[$productOrigin->entity])) {
420 $srcdir = $conf->product->multidir_output[$productOrigin->entity]."/".$productOrigin->ref;
421 $destdir = $conf->product->multidir_output[$object->entity]."/".$object->ref;
422
423 if (dol_is_dir($srcdir)) {
424 $dirlist = dol_dir_list($srcdir, 'files', 1);
425 foreach ($dirlist as $filetomove) {
426 $destfile = $destdir.'/'.$filetomove['relativename'];
427 //var_dump('Move file '.$filetomove['relativename'].' into '.$destfile);
428 dol_move($filetomove['fullname'], $destfile, '0', 0, 0, 1);
429 }
430 //exit;
431 }
432 }
433
434 // Delete the product
435 if ($productOrigin->delete($user) < 1) {
436 $error++;
437 }
438 }
439
440 if (!$error) {
441 setEventMessages($langs->trans('ProductsMergeSuccess'), null, 'mesgs');
442 $db->commit();
443 } else {
444 $langs->load("errors");
445 setEventMessages($langs->trans('ErrorsProductsMerge'), null, 'errors');
446 $db->rollback();
447 }
448 }
449 }
450 }
451
452 // Type
453 if ($action == 'setfk_product_type' && $usercancreate) {
454 $result = $object->setValueFrom('fk_product_type', GETPOST('fk_product_type'), '', null, 'text', '', $user, 'PRODUCT_MODIFY');
455 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
456 exit;
457 }
458
459 // Actions to build doc
460 $upload_dir = $conf->product->dir_output;
461 $permissiontoadd = $usercancreate;
462 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
463
464 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
465
466 // Barcode type
467 if ($action == 'setfk_barcode_type' && $usercancreate) {
468 $result = $object->setValueFrom('fk_barcode_type', GETPOST('fk_barcode_type'), '', null, 'text', '', $user, 'PRODUCT_MODIFY');
469 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
470 exit;
471 }
472
473 // Barcode value
474 if ($action == 'setbarcode' && $usercancreate) {
475 $result = $object->check_barcode(GETPOST('barcode'), GETPOST('barcode_type_code'));
476
477 if ($result >= 0) {
478 $result = $object->setValueFrom('barcode', GETPOST('barcode'), '', null, 'text', '', $user, 'PRODUCT_MODIFY');
479 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
480 exit;
481 } else {
482 $langs->load("errors");
483 if ($result == -1) {
484 $errors[] = 'ErrorBadBarCodeSyntax';
485 } elseif ($result == -2) {
486 $errors[] = 'ErrorBarCodeRequired';
487 } elseif ($result == -3) {
488 $errors[] = 'ErrorBarCodeAlreadyUsed';
489 } else {
490 $errors[] = 'FailedToValidateBarCode';
491 }
492
493 $error++;
494 setEventMessages('', $errors, 'errors');
495 }
496 }
497
498 // Quick edit for extrafields
499 if ($action == 'update_extras' && $permissiontoeditextra) {
500 // we may use oldcopy->hasBatch( in triggers so keep 1
501 $object->oldcopy = dol_clone($object, 1); // @phan-suppress-current-line PhanTypeMismatchProperty
502
503 $attribute_name = GETPOST('attribute', 'aZ09');
504
505 // Fill array 'array_options' with data from update form
506 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
507 if ($ret < 0) {
508 $error++;
509 }
510
511 if (!$error) {
512 $result = $object->updateExtraField($attribute_name, 'PRODUCT_MODIFY');
513 if ($result < 0) {
514 setEventMessages($object->error, $object->errors, 'errors');
515 $error++;
516 }
517 }
518
519 if ($error) {
520 $action = 'edit_extras';
521 }
522 }
523
524 // Add a product or service
525 if ($action == 'add' && $usercancreate) {
526 $error = 0;
527
528 if (!GETPOST('label', $label_security_check)) {
529 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Label')), null, 'errors');
530 $action = "create";
531 $error++;
532 }
533 if (empty($ref)) {
534 if (!getDolGlobalString('PRODUCT_GENERATE_REF_AFTER_FORM')) {
535 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('ProductRef')), null, 'errors');
536 $action = "create";
537 $error++;
538 }
539 }
540 if (!empty($duration_value) && empty($duration_unit)) {
541 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Unit')), null, 'errors');
542 $action = "create";
543 $error++;
544 }
545 $stockable_product = (int) ($type == 0 || ($type == 1 && getDolGlobalInt('STOCK_SUPPORTS_SERVICES')));
546 if (GETPOST('status_batch') && $stockable_product == 0 && isModEnabled('stock') && isModEnabled('productbatch')) {
547 setEventMessages($langs->trans('ErrorBatchesNeedStockManagement'), null, 'errors');
548 $action = "create";
549 $error++;
550 }
551
552 if (!$error) {
553 $units = GETPOSTINT('units');
554
555 $object->entity = $conf->entity;
556 $object->ref = (string) $ref;
557 $object->label = GETPOST('label', $label_security_check);
558 $object->price_base_type = GETPOST('price_base_type', 'aZ09');
559 $object->mandatory_period = empty(GETPOST("mandatoryperiod", 'alpha')) ? 0 : 1;
560 if ($object->price_base_type == 'TTC') {
561 $object->price_ttc = GETPOSTFLOAT('price');
562 } else {
563 $object->price = GETPOSTFLOAT('price');
564 }
565 if ($object->price_base_type == 'TTC') {
566 $object->price_min_ttc = GETPOSTFLOAT('price_min');
567 } else {
568 $object->price_min = GETPOSTFLOAT('price_min');
569 }
570
571 $tva_tx_txt = GETPOST('tva_tx', 'alpha'); // tva_tx can be '8.5' or '8.5*' or '8.5 (XXX)' or '8.5* (XXX)'
572
573 // We must define tva_tx, npr and local taxes
574 $vatratecode = '';
575 $tva_tx = preg_replace('/[^0-9\.].*$/', '', $tva_tx_txt); // keep remove all after the numbers and dot
576 $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0;
577 $localtax1 = 0;
578 $localtax2 = 0;
579 $localtax1_type = '0';
580 $localtax2_type = '0';
581 // If value contains the unique code of vat line (new recommended method), we use it to find npr and local taxes
582 $reg = array();
583 if (preg_match('/\‍((.*)\‍)/', $tva_tx_txt, $reg)) {
584 // We look into database using code (we can't use get_localtax() because it depends on buyer that is not known). Same in update price.
585 $vatratecode = $reg[1];
586 // Get record from code
587 $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
588 $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
589 $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
590 $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
591 $sql .= " AND t.code = '".$db->escape($vatratecode)."'";
592 $sql .= " AND t.entity IN (".getEntity('c_tva').")";
593 $resql = $db->query($sql);
594 if ($resql) {
595 $obj = $db->fetch_object($resql);
596 $npr = $obj->recuperableonly;
597 $localtax1 = $obj->localtax1;
598 $localtax2 = $obj->localtax2;
599 $localtax1_type = $obj->localtax1_type;
600 $localtax2_type = $obj->localtax2_type;
601 }
602 }
603
604 $object->default_vat_code = $vatratecode;
605 $object->tva_tx = $tva_tx;
606 $object->tva_npr = $npr;
607 $object->localtax1_tx = $localtax1;
608 $object->localtax2_tx = $localtax2;
609 $object->localtax1_type = $localtax1_type;
610 $object->localtax2_type = $localtax2_type;
611
612 $object->type = $type;
613 $object->status = GETPOSTINT('statut');
614 $object->status_buy = GETPOSTINT('statut_buy');
615 $object->status_batch = GETPOSTINT('status_batch');
616 $object->sell_or_eat_by_mandatory = GETPOSTINT('sell_or_eat_by_mandatory');
617 $object->batch_mask = GETPOST('batch_mask');
618
619 $object->barcode_type = GETPOSTINT('fk_barcode_type');
620 $object->barcode = GETPOST('barcode');
621 // Set barcode_type_xxx from barcode_type id
622 $stdobject = new GenericObject($db);
623 $stdobject->element = 'product';
624 $stdobject->barcode_type = GETPOSTINT('fk_barcode_type');
625 $result = $stdobject->fetchBarCode();
626 if ($result < 0) {
627 $error++;
628 $mesg = 'Failed to get bar code type information ';
629 setEventMessages($mesg.$stdobject->error, $stdobject->errors, 'errors');
630 }
631 $object->barcode_type_code = $stdobject->barcode_type_code;
632 $object->barcode_type_coder = $stdobject->barcode_type_coder;
633 $object->barcode_type_label = $stdobject->barcode_type_label;
634
635 $object->description = dol_htmlcleanlastbr(GETPOST('desc', 'restricthtml'));
636 $object->url = GETPOST('url');
637 $object->note_private = dol_htmlcleanlastbr(GETPOST('note_private', 'restricthtml'));
638 $object->note = $object->note_private; // deprecated
639 $object->customcode = GETPOST('customcode', 'alphanohtml');
640 $object->country_id = GETPOSTINT('country_id');
641 $object->state_id = GETPOSTINT('state_id');
642 $object->lifetime = GETPOSTINT('lifetime');
643 $object->qc_frequency = GETPOSTINT('qc_frequency');
644 $object->duration_value = $duration_value;
645 $object->duration_unit = $duration_unit;
646 $object->fk_default_warehouse = GETPOSTINT('fk_default_warehouse');
647 $object->fk_default_workstation = GETPOSTINT('fk_default_workstation');
648 $object->seuil_stock_alerte = GETPOST('seuil_stock_alerte') ? GETPOST('seuil_stock_alerte') : 0;
649 $object->desiredstock = GETPOST('desiredstock') ? GETPOST('desiredstock') : 0;
650 $object->canvas = GETPOST('canvas');
651 $object->net_measure = GETPOST('net_measure');
652 $object->net_measure_units = GETPOST('net_measure_units') === '' ? null : GETPOSTINT('net_measure_units'); // This is not the fk_unit but the power of unit
653 $object->weight = GETPOST('weight');
654 $object->weight_units = GETPOST('weight_units'); // This is not the fk_unit but the power of unit
655 $object->length = GETPOST('size');
656 $object->length_units = GETPOST('size_units'); // This is not the fk_unit but the power of unit
657 $object->width = GETPOST('sizewidth');
658 $object->height = GETPOST('sizeheight');
659 $object->surface = GETPOST('surface');
660 $object->surface_units = GETPOST('surface_units'); // This is not the fk_unit but the power of unit
661 $object->volume = GETPOST('volume');
662 $object->volume_units = GETPOST('volume_units'); // This is not the fk_unit but the power of unit
663 $finished = GETPOSTINT('finished');
664 if ($finished >= 0) {
665 $object->finished = $finished;
666 } else {
667 $object->finished = null;
668 }
669
670 $units = GETPOSTINT('units');
671 if ($units > 0) {
672 $object->fk_unit = $units;
673 } else {
674 $object->fk_unit = null;
675 }
676
677 $object->stockable_product = $stockable_product;
678
679 $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
680 $accountancy_code_sell_intra = GETPOST('accountancy_code_sell_intra', 'alpha');
681 $accountancy_code_sell_export = GETPOST('accountancy_code_sell_export', 'alpha');
682 $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
683 $accountancy_code_buy_intra = GETPOST('accountancy_code_buy_intra', 'alpha');
684 $accountancy_code_buy_export = GETPOST('accountancy_code_buy_export', 'alpha');
685
686 if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
687 $object->accountancy_code_sell = '';
688 } else {
689 $object->accountancy_code_sell = $accountancy_code_sell;
690 }
691 if (empty($accountancy_code_sell_intra) || $accountancy_code_sell_intra == '-1') {
692 $object->accountancy_code_sell_intra = '';
693 } else {
694 $object->accountancy_code_sell_intra = $accountancy_code_sell_intra;
695 }
696 if (empty($accountancy_code_sell_export) || $accountancy_code_sell_export == '-1') {
697 $object->accountancy_code_sell_export = '';
698 } else {
699 $object->accountancy_code_sell_export = $accountancy_code_sell_export;
700 }
701 if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') {
702 $object->accountancy_code_buy = '';
703 } else {
704 $object->accountancy_code_buy = $accountancy_code_buy;
705 }
706 if (empty($accountancy_code_buy_intra) || $accountancy_code_buy_intra == '-1') {
707 $object->accountancy_code_buy_intra = '';
708 } else {
709 $object->accountancy_code_buy_intra = $accountancy_code_buy_intra;
710 }
711 if (empty($accountancy_code_buy_export) || $accountancy_code_buy_export == '-1') {
712 $object->accountancy_code_buy_export = '';
713 } else {
714 $object->accountancy_code_buy_export = $accountancy_code_buy_export;
715 }
716
717 // MultiPrix
718 if (getDolGlobalString('PRODUIT_MULTIPRICES')) {
719 $produit_multiprices_limit = getDolGlobalString('PRODUIT_MULTIPRICES_LIMIT');
720 for ($i = 2; $i <= $produit_multiprices_limit; $i++) {
721 if (GETPOSTISSET("price_".$i)) {
722 $object->multiprices["$i"] = price2num(GETPOST("price_".$i), 'MU');
723 $object->multiprices_base_type["$i"] = GETPOST("multiprices_base_type_".$i);
724 } else {
725 $object->multiprices["$i"] = "";
726 }
727 }
728 }
729
730 // Fill array 'array_options' with data from add form
731 $ret = $extrafields->setOptionalsFromPost(null, $object);
732 if ($ret < 0) {
733 $error++;
734 }
735
736 if (!$ref && getDolGlobalString('PRODUCT_GENERATE_REF_AFTER_FORM')) {
737 // Generate ref...
738 '@phan-var ModeleProductCode $modCodeProduct';
739 $ref = $modCodeProduct->getNextValue($object, $type);
740 }
741
742 if (!$error) {
743 $id = $object->create($user);
744 }
745
746 if ($id > 0) {
747 // Category association
748 $categories = GETPOST('categories', 'array');
749 $object->setCategories($categories);
750
751 if (!empty($backtopage)) {
752 $backtopage = preg_replace('/__ID__/', (string) $object->id, $backtopage); // New method to autoselect parent project after a New on another form object creation
753 $backtopage = preg_replace('/--IDFORBACKTOPAGE--/', (string) $object->id, $backtopage); // New method to autoselect parent after a New on another form object creation
754 if (preg_match('/\?/', $backtopage)) {
755 $backtopage .= '&productid='.$object->id; // Old method
756 }
757
758 header("Location: ".$backtopage);
759 exit;
760 } else {
761 header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
762 exit;
763 }
764 } else {
765 if (count($object->errors)) {
766 setEventMessages($object->error, $object->errors, 'errors');
767 } else {
768 if ($object->error == 'ErrorProductAlreadyExists') {
769 // allow to hook on ErrorProductAlreadyExists in any module
770 $reshook = $hookmanager->executeHooks('onProductAlreadyExists', $parameters, $object, $action);
771 if ($reshook < 0) {
772 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
773 }
774 if ($object->error) {
775 // check again to prevent translation issue,
776 // as error may have been cleared in hook function
777 setEventMessages($langs->trans($object->error), null, 'errors');
778 }
779 } else {
780 setEventMessages($langs->trans($object->error), null, 'errors');
781 }
782 }
783 $action = "create";
784 }
785 }
786 }
787
788 // Update a product or service
789 if ($action == 'update' && $usercancreate) {
790 if (GETPOST('cancel', 'alpha')) {
791 $action = '';
792 } else {
793 if ($object->id > 0) {
794 // Need dol_clone methode 1 (same object class) because update product use hasbatch() method on oldcopy
795 $object->oldcopy = dol_clone($object, 1); // @phan-suppress-current-line PhanTypeMismatchProperty
796
797 if (!getDolGlobalString('PRODUCT_GENERATE_REF_AFTER_FORM')) {
798 $object->ref = (string) $ref;
799 }
800 $object->label = GETPOST('label', $label_security_check);
801
802 $desc = dol_htmlcleanlastbr(preg_replace('/&nbsp;$/', '', GETPOST('desc', 'restricthtml')));
803 $object->description = $desc;
804
805 $object->url = GETPOST('url');
806 if (getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
807 $object->note_private = dol_htmlcleanlastbr(GETPOST('note_private', 'restricthtml'));
808 $object->note = $object->note_private;
809 }
810 $object->customcode = GETPOST('customcode', 'alpha');
811 $object->country_id = GETPOSTINT('country_id');
812 $object->state_id = GETPOSTINT('state_id');
813 $object->lifetime = GETPOSTINT('lifetime');
814 $object->qc_frequency = GETPOSTINT('qc_frequency');
815 $object->status = GETPOSTINT('statut');
816 $object->status_buy = GETPOSTINT('statut_buy');
817 $object->status_batch = GETPOSTINT('status_batch');
818 $object->sell_or_eat_by_mandatory = GETPOSTINT('sell_or_eat_by_mandatory');
819 $object->batch_mask = GETPOST('batch_mask', 'alpha');
820 $object->fk_default_warehouse = GETPOSTINT('fk_default_warehouse');
821 $object->fk_default_workstation = GETPOSTINT('fk_default_workstation');
822 // removed from update view so GETPOST always empty
823 /*
824 $object->seuil_stock_alerte = GETPOST('seuil_stock_alerte');
825 $object->desiredstock = GETPOST('desiredstock');
826 */
827 $object->duration_value = GETPOST('duration_value');
828 $object->duration_unit = GETPOST('duration_unit', 'alpha');
829
830 $object->canvas = GETPOST('canvas');
831 $object->net_measure = GETPOST('net_measure');
832 $object->net_measure_units = GETPOST('net_measure_units') === '' ? null : GETPOSTINT('net_measure_units'); // This is not the fk_unit but the power of unit
833 $object->weight = GETPOST('weight');
834 $object->weight_units = GETPOST('weight_units'); // This is not the fk_unit but the power of unit
835 $object->length = GETPOST('size');
836 $object->length_units = GETPOST('size_units'); // This is not the fk_unit but the power of unit
837 $object->width = GETPOST('sizewidth');
838 $object->height = GETPOST('sizeheight');
839
840 $object->surface = GETPOST('surface');
841 $object->surface_units = GETPOST('surface_units'); // This is not the fk_unit but the power of unit
842 $object->volume = GETPOST('volume');
843 $object->volume_units = GETPOST('volume_units'); // This is not the fk_unit but the power of unit
844
845 $finished = GETPOSTINT('finished');
846 if ($finished >= 0) {
847 $object->finished = $finished;
848 } else {
849 $object->finished = null;
850 }
851
852 $fk_default_bom = GETPOSTINT('fk_default_bom');
853 if ($fk_default_bom >= 0) {
854 $object->fk_default_bom = $fk_default_bom;
855 } else {
856 $object->fk_default_bom = 0;
857 }
858
859 // managed_in_stock
860 $object->stockable_product = (int) GETPOSTISSET('stockable_product');
861 if ($object->status_batch > 0 && $object->stockable_product == 0 && isModEnabled('stock') && isModEnabled('productbatch')) {
862 $object->stockable_product = 1;
863 setEventMessages($langs->trans('ForceBatchesNeedStockManagement'), null, 'warnings');
864 }
865
866 $units = GETPOSTINT('units');
867 if ($units > 0) {
868 $object->fk_unit = $units;
869 } else {
870 $object->fk_unit = null;
871 }
872
873 $object->barcode_type = GETPOSTINT('fk_barcode_type');
874 $object->barcode = GETPOST('barcode');
875 // Set barcode_type_xxx from barcode_type id
876 $stdobject = new GenericObject($db);
877 $stdobject->element = 'product';
878 $stdobject->barcode_type = GETPOSTINT('fk_barcode_type');
879 $result = $stdobject->fetchBarCode();
880 if ($result < 0) {
881 $error++;
882 $mesg = 'Failed to get bar code type information ';
883 setEventMessages($mesg.$stdobject->error, $stdobject->errors, 'errors');
884 }
885 $object->barcode_type_code = $stdobject->barcode_type_code;
886 $object->barcode_type_coder = $stdobject->barcode_type_coder;
887 $object->barcode_type_label = $stdobject->barcode_type_label;
888
889 $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
890 $accountancy_code_sell_intra = GETPOST('accountancy_code_sell_intra', 'alpha');
891 $accountancy_code_sell_export = GETPOST('accountancy_code_sell_export', 'alpha');
892 $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
893 $accountancy_code_buy_intra = GETPOST('accountancy_code_buy_intra', 'alpha');
894 $accountancy_code_buy_export = GETPOST('accountancy_code_buy_export', 'alpha');
895 $checkmandatory = GETPOST('mandatoryperiod', 'alpha');
896 if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
897 $object->accountancy_code_sell = '';
898 } else {
899 $object->accountancy_code_sell = $accountancy_code_sell;
900 }
901 if (empty($accountancy_code_sell_intra) || $accountancy_code_sell_intra == '-1') {
902 $object->accountancy_code_sell_intra = '';
903 } else {
904 $object->accountancy_code_sell_intra = $accountancy_code_sell_intra;
905 }
906 if (empty($accountancy_code_sell_export) || $accountancy_code_sell_export == '-1') {
907 $object->accountancy_code_sell_export = '';
908 } else {
909 $object->accountancy_code_sell_export = $accountancy_code_sell_export;
910 }
911 if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') {
912 $object->accountancy_code_buy = '';
913 } else {
914 $object->accountancy_code_buy = $accountancy_code_buy;
915 }
916 if (empty($accountancy_code_buy_intra) || $accountancy_code_buy_intra == '-1') {
917 $object->accountancy_code_buy_intra = '';
918 } else {
919 $object->accountancy_code_buy_intra = $accountancy_code_buy_intra;
920 }
921 if (empty($accountancy_code_buy_export) || $accountancy_code_buy_export == '-1') {
922 $object->accountancy_code_buy_export = '';
923 } else {
924 $object->accountancy_code_buy_export = $accountancy_code_buy_export;
925 }
926 if ($object->isService()) {
927 $object->mandatory_period = (!empty($checkmandatory)) ? 1 : 0 ;
928 }
929
930
931 // Fill array 'array_options' with data from add form
932 $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
933 if ($ret < 0) {
934 $error++;
935 }
936
937 // The lot/serial fields are not in the form when module productbatch is disabled: keep their values,
938 // an empty status_batch would switch the product to "no lot" and move all its stock out of its lots.
939 if (!GETPOSTISSET('status_batch')) {
940 $object->status_batch = $object->oldcopy->status_batch;
941 }
942 if (!GETPOSTISSET('sell_or_eat_by_mandatory')) {
943 $object->sell_or_eat_by_mandatory = $object->oldcopy->sell_or_eat_by_mandatory;
944 }
945 if (!GETPOSTISSET('batch_mask')) {
946 $object->batch_mask = $object->oldcopy->batch_mask;
947 }
948
949 if (!$error && $object->check()) {
950 if ($object->update($object->id, $user) > 0) {
951 // Category association
952 $categories = GETPOST('categories', 'array');
953 $object->setCategories($categories);
954
955 $action = 'view';
956 } else {
957 if (count($object->errors)) {
958 setEventMessages($object->error, $object->errors, 'errors');
959 } else {
960 setEventMessages($langs->trans($object->error), null, 'errors');
961 }
962 $action = 'edit';
963 }
964 } else {
965 if (count($object->errors)) {
966 setEventMessages($object->error, $object->errors, 'errors');
967 } else {
968 setEventMessages($langs->trans("ErrorProductBadRefOrLabel"), null, 'errors');
969 }
970 $action = 'edit';
971 }
972 }
973 }
974 }
975
976 // Action clone object
977 if ($action == 'confirm_clone' && $confirm != 'yes') { // Test on permission not required
978 $action = '';
979 }
980 if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate) {
981 if (!GETPOST('clone_content') && !GETPOST('clone_prices')) {
982 setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
983 } else {
984 if ($object->id > 0) {
985 $error = 0;
986 // We clone object to avoid to denaturate loaded object when setting some properties for clone or if createFromClone modifies the object.
987 // We use native clone to keep this->db valid and allow to use later all the methods of object.
988 $clone = dol_clone($object, 1);
989
990 $clone->id = 0;
991 $clone->ref = GETPOST('clone_ref', 'alphanohtml');
992 $clone->status = 0;
993 $clone->status_buy = 0;
994 $clone->barcode = -1;
995
996 if ($clone->check()) {
997 $db->begin();
998
999 $clone->context['createfromclone'] = 'createfromclone';
1000 $id = $clone->create($user);
1001 if ($id > 0) {
1002 if (GETPOST('clone_composition')) {
1003 $result = $clone->clone_associations($object->id, $id);
1004 if ($result < 1) {
1005 setEventMessages($langs->trans('ErrorProductClone'), null, 'errors');
1006 setEventMessages($clone->error, $clone->errors, 'errors');
1007 $error++;
1008 }
1009 }
1010
1011 if (!$error && GETPOST('clone_categories')) {
1012 $result = $clone->cloneCategories($object->id, $id);
1013 if ($result < 1) {
1014 setEventMessages($langs->trans('ErrorProductClone'), null, 'errors');
1015 setEventMessages($clone->error, $clone->errors, 'errors');
1016 $error++;
1017 }
1018 }
1019
1020 if (!$error && GETPOST('clone_prices')) {
1021 $result = $clone->clone_price($object->id, $id);
1022 if ($result < 1) {
1023 setEventMessages($langs->trans('ErrorProductClone'), null, 'errors');
1024 setEventMessages($clone->error, $clone->errors, 'errors');
1025 $error++;
1026 }
1027 }
1028
1029 if (!$error && isModEnabled('bom') && $user->hasRight('bom', 'write')) {
1030 $defbomidac = 0; // to avoid cloning same BOM twice
1031 if (GETPOST('clone_defbom') && $object->fk_default_bom > 0) {
1032 $bomstatic = new BOM($db);
1033 $bomclone = $bomstatic->createFromClone($user, $object->fk_default_bom);
1034 if ((int) $bomclone < 0) {
1035 setEventMessages($langs->trans('ErrorProductClone').' : '.$langs->trans('ErrorProductCloneBom'), null, 'warnings');
1036 } else {
1037 $defbomidac = $object->fk_default_bom;
1038 $clone->fk_default_bom = $bomclone->id;
1039 $clone->update($id, $user);
1040 $bomclone->fk_product = $id;
1041 $bomclone->label = $langs->trans('BOMofRef', $clone->ref);
1042 $bomclone->update($user);
1043 $bomclone->validate($user);
1044 }
1045 }
1046 if (GETPOST('clone_otherboms')) {
1047 $bomstatic = new BOM($db);
1048 $bomlist = $bomstatic->fetchAll("", "", 0, 0, 'fk_product:=:'.(int) $object->id);
1049 if (is_array($bomlist)) {
1050 foreach ($bomlist as $bom2clone) {
1051 if ($bom2clone->id != $defbomidac) { // to avoid cloning same BOM twice
1052 $bomclone = $bomstatic->createFromClone($user, $bom2clone->id);
1053 if ((int) $bomclone < 0) {
1054 setEventMessages($langs->trans('ErrorProductClone').' : '.$langs->trans('ErrorProductCloneBom'), null, 'warnings');
1055 } else {
1056 $bomclone->fk_product = $id;
1057 $bomclone->label = $langs->trans('BOMofRef', $clone->ref);
1058 $bomclone->update($user);
1059 $bomclone->validate($user);
1060 }
1061 }
1062 }
1063 }
1064 }
1065 }
1066 // $clone->clone_fournisseurs($object->id, $id);
1067 } else {
1068 if ($clone->error == 'ErrorProductAlreadyExists') {
1069 $refalreadyexists++;
1070 $action = "";
1071
1072 $mesg = $langs->trans("ErrorProductAlreadyExists", $clone->ref);
1073 $mesg .= ' <a href="' . $_SERVER["PHP_SELF"] . '?ref=' . $clone->ref . '">' . $langs->trans("ShowCardHere") . '</a>.';
1074 setEventMessages($mesg, null, 'errors');
1075 } else {
1076 setEventMessages(empty($clone->error) ? '' : $langs->trans($clone->error), $clone->errors, 'errors');
1077 }
1078 $error++;
1079 }
1080
1081 unset($clone->context['createfromclone']);
1082
1083 if ($error) {
1084 $db->rollback();
1085 } else {
1086 $db->commit();
1087 $db->close();
1088 header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
1089 exit;
1090 }
1091 } else {
1092 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NewRefForClone")), null, 'errors');
1093 }
1094 } else {
1095 dol_print_error($db, $object->error, $object->errors);
1096 }
1097 }
1098 $action = 'clone';
1099 }
1100
1101 // Delete a product
1102 if ($action == 'confirm_delete' && $confirm != 'yes') { // Test on permission not required
1103 $action = '';
1104 }
1105 if ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete) {
1106 $result = $object->delete($user);
1107
1108 if ($result > 0) {
1109 header('Location: '.DOL_URL_ROOT.'/product/list.php?type='.$object->type.'&delprod='.urlencode($object->ref));
1110 exit;
1111 } else {
1112 setEventMessages($langs->trans($object->error), null, 'errors');
1113 $reload = 0;
1114 $action = '';
1115 }
1116 }
1117
1118
1119 // Add product into object (when PRODUCT_ADD_FORM_ADD_TO is set)
1120 if ($object->id > 0 && $action == 'addin') { // Test on permission not required here. it is done later according to object.
1121 $thirdpartyid = 0;
1122 $permissiontoaddline = false;
1123 $propal = null;
1124 $facture = null;
1125 $commande = null;
1126
1127 // Get object and test permission
1128 if (GETPOSTINT('propalid') > 0) {
1129 $propal = new Propal($db);
1130 $result = $propal->fetch(GETPOSTINT('propalid'));
1131 if ($result <= 0) {
1132 dol_print_error($db, $propal->error);
1133 exit;
1134 }
1135 $thirdpartyid = $propal->socid;
1136 $permissiontoaddline = $user->hasRight('propal', 'creer');
1137 } elseif (GETPOSTINT('commandeid') > 0) {
1138 $commande = new Commande($db);
1139 $result = $commande->fetch(GETPOSTINT('commandeid'));
1140 if ($result <= 0) {
1141 dol_print_error($db, $commande->error);
1142 exit;
1143 }
1144 $thirdpartyid = $commande->socid;
1145 $permissiontoaddline = $user->hasRight('commande', 'creer');
1146 } elseif (GETPOSTINT('factureid') > 0) {
1147 $facture = new Facture($db);
1148 $result = $facture->fetch(GETPOSTINT('factureid'));
1149 if ($result <= 0) {
1150 dol_print_error($db, $facture->error);
1151 exit;
1152 }
1153 $thirdpartyid = $facture->socid;
1154 $permissiontoaddline = $user->hasRight('facture', 'creer');
1155 }
1156
1157 if ($thirdpartyid > 0) {
1158 $soc = new Societe($db);
1159 $result = $soc->fetch($thirdpartyid);
1160 if ($result <= 0) {
1161 dol_print_error($db, $soc->error);
1162 exit;
1163 }
1164
1165 $desc = $object->description;
1166
1167 $tva_tx = get_default_tva($mysoc, $soc, $object->id);
1168 $tva_npr = get_default_npr($mysoc, $soc, $object->id);
1169 if (empty($tva_tx)) {
1170 $tva_npr = 0;
1171 }
1172 $localtax1_tx = get_localtax($tva_tx, 1, $soc, $mysoc, $tva_npr);
1173 $localtax2_tx = get_localtax($tva_tx, 2, $soc, $mysoc, $tva_npr);
1174
1175 $pu_ht = $object->price;
1176 $pu_ttc = $object->price_ttc;
1177 $price_base_type = $object->price_base_type;
1178
1179 // If multiprice
1180 if (getDolGlobalString('PRODUIT_MULTIPRICES') && $soc->price_level) {
1181 $pu_ht = $object->multiprices[$soc->price_level];
1182 $pu_ttc = $object->multiprices_ttc[$soc->price_level];
1183 $price_base_type = $object->multiprices_base_type[$soc->price_level];
1184 } elseif (getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) {
1185 require_once DOL_DOCUMENT_ROOT.'/product/class/productcustomerprice.class.php';
1186
1187 $prodcustprice = new ProductCustomerPrice($db);
1188
1189 $filter = array('t.fk_product' => (string) $object->id, 't.fk_soc' => (string) $soc->id);
1190
1191 $result = $prodcustprice->fetchAll('', '', 0, 0, $filter);
1192 if ($result) {
1193 if (count($prodcustprice->lines) > 0) {
1194 $date_now = (int) floor(dol_now() / 86400) * 86400; // date without hours
1195 foreach ($prodcustprice->lines as $k => $custprice_line) {
1196 if ($custprice_line->date_begin <= $date_now && (empty($custprice_line->date_end) || $date_now <= $custprice_line->date_end)) {
1197 $pu_ht = price($custprice_line->price);
1198 $pu_ttc = price($custprice_line->price_ttc);
1199 $price_base_type = $custprice_line->price_base_type;
1200 $tva_tx = $custprice_line->tva_tx;
1201 break;
1202 }
1203 }
1204 }
1205 }
1206 }
1207
1208 $tmpvat = price2num(preg_replace('/\s*\‍(.*\‍)/', '', $tva_tx));
1209 $tmpprodvat = price2num(preg_replace('/\s*\‍(.*\‍)/', '', $object->tva_tx));
1210
1211 // On reevalue prix selon taux tva car taux tva transaction peut etre different
1212 // de ceux du produit par default (par example si pays different entre vendeur et acheteur).
1213 if ($tmpvat != $tmpprodvat) {
1214 if ($price_base_type != 'HT') {
1215 $pu_ht = price2num($pu_ttc / (1 + ((float) $tmpvat / 100)), 'MU');
1216 } else {
1217 $pu_ttc = price2num($pu_ht * (1 + ((float) $tmpvat / 100)), 'MU');
1218 }
1219 }
1220
1221 if (GETPOSTINT('propalid') > 0 && $permissiontoaddline && is_object($propal)) {
1222 // Define cost price for margin calculation
1223 $buyprice = 0;
1224 if (($result = $propal->defineBuyPrice($pu_ht, (float) price2num(GETPOST('remise_percent'), '', 2), $object->id)) < 0) {
1225 dol_syslog($langs->trans('FailedToGetCostPrice'));
1226 setEventMessages($langs->trans('FailedToGetCostPrice'), null, 'errors');
1227 } else {
1228 $buyprice = $result;
1229 }
1230
1231 $result = $propal->addline(
1232 $desc,
1233 $pu_ht,
1234 (float) price2num(GETPOST('qty'), 'MS'),
1235 $tva_tx,
1236 $localtax1_tx, // localtax1
1237 $localtax2_tx, // localtax2
1238 $object->id,
1239 (float) price2num(GETPOST('remise_percent'), '', 2),
1240 $price_base_type,
1241 $pu_ttc,
1242 0,
1243 0,
1244 -1,
1245 0,
1246 0,
1247 0,
1248 $buyprice,
1249 '',
1250 '',
1251 '',
1252 array(),
1253 $object->fk_unit
1254 );
1255 if ($result > 0) {
1256 header("Location: ".DOL_URL_ROOT."/comm/propal/card.php?id=".$propal->id);
1257 return;
1258 }
1259
1260 setEventMessages($langs->trans("ErrorUnknown").": $result", null, 'errors');
1261 } elseif (GETPOST('commandeid') > 0 && $permissiontoaddline && is_object($commande)) {
1262 // Define cost price for margin calculation
1263 $buyprice = 0;
1264 if (($result = $commande->defineBuyPrice($pu_ht, (float) price2num(GETPOST('remise_percent'), '', 2), $object->id)) < 0) {
1265 dol_syslog($langs->trans('FailedToGetCostPrice'));
1266 setEventMessages($langs->trans('FailedToGetCostPrice'), null, 'errors');
1267 } else {
1268 $buyprice = $result;
1269 }
1270
1271 $result = $commande->addline(
1272 $desc,
1273 (float) $pu_ht,
1274 (float) price2num(GETPOST('qty'), 'MS'),
1275 $tva_tx,
1276 $localtax1_tx, // localtax1
1277 $localtax2_tx, // localtax2
1278 $object->id,
1279 (float) price2num(GETPOST('remise_percent'), '', 2),
1280 0,
1281 0,
1282 $price_base_type,
1283 $pu_ttc,
1284 '',
1285 '',
1286 0,
1287 -1,
1288 0,
1289 0,
1290 0,
1291 $buyprice,
1292 '',
1293 array(),
1294 $object->fk_unit
1295 );
1296
1297 if ($result > 0) {
1298 header("Location: ".DOL_URL_ROOT."/commande/card.php?id=".urlencode((string) ($commande->id)));
1299 exit;
1300 }
1301
1302 setEventMessages($langs->trans("ErrorUnknown").": $result", null, 'errors');
1303 } elseif (GETPOST('factureid') > 0 && $permissiontoaddline && is_object($facture)) {
1304 // Define cost price for margin calculation
1305 $buyprice = 0;
1306 if (($result = $facture->defineBuyPrice($pu_ht, (float) price2num(GETPOST('remise_percent'), '', 2), $object->id)) < 0) {
1307 dol_syslog($langs->trans('FailedToGetCostPrice'));
1308 setEventMessages($langs->trans('FailedToGetCostPrice'), null, 'errors');
1309 } else {
1310 $buyprice = $result;
1311 }
1312
1313 $result = $facture->addline(
1314 $desc,
1315 (float) $pu_ht,
1316 (float) price2num(GETPOST('qty'), 'MS'),
1317 $tva_tx,
1318 $localtax1_tx,
1319 $localtax2_tx,
1320 $object->id,
1321 (float) price2num(GETPOST('remise_percent'), '', 2),
1322 '',
1323 '',
1324 0,
1325 0,
1326 0,
1327 $price_base_type,
1328 $pu_ttc,
1330 -1,
1331 0,
1332 '',
1333 0,
1334 0,
1335 0,
1336 $buyprice,
1337 '',
1338 array(),
1339 100,
1340 0,
1341 $object->fk_unit
1342 );
1343
1344 if ($result > 0) {
1345 header("Location: ".DOL_URL_ROOT."/compta/facture/card.php?facid=".$facture->id);
1346 exit;
1347 }
1348
1349 setEventMessages($langs->trans("ErrorUnknown").": $result", null, 'errors');
1350 }
1351 } else {
1352 $action = "";
1353 setEventMessages($langs->trans("WarningSelectOneDocument"), null, 'warnings');
1354 }
1355 }
1356
1357 // Actions to send emails
1358 $triggersendname = 'PRODUCT_SENTBYMAIL';
1359 $paramname = 'id';
1360 $autocopy = 'MAIN_MAIL_AUTOCOPY_PRODUCT_TO';
1361 $trackid = 'prod'.$object->id;
1362 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
1363}
1364
1365
1366
1367/*
1368 * View
1369 */
1370
1371$form = new Form($db);
1372$formfile = new FormFile($db);
1373$formproduct = new FormProduct($db);
1374$formcompany = new FormCompany($db);
1375if (isModEnabled('accounting')) {
1376 $formaccounting = new FormAccounting($db);
1377}
1378$sellOrEatByMandatoryList = null;
1379if (isModEnabled('productbatch')) {
1380 $sellOrEatByMandatoryList = Product::getSellOrEatByMandatoryList();
1381
1382 $disableSellBy = getDolGlobalString('PRODUCT_DISABLE_SELLBY');
1383 $disableEatBy = getDolGlobalString('PRODUCT_DISABLE_EATBY');
1384
1385 if ($disableSellBy) {
1386 unset($sellOrEatByMandatoryList[Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY]);
1387 unset($sellOrEatByMandatoryList[Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT]);
1388 }
1389 if ($disableEatBy) {
1390 unset($sellOrEatByMandatoryList[Product::SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY]);
1391 unset($sellOrEatByMandatoryList[Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT]);
1392 }
1393}
1394
1395$title = $langs->trans('ProductServiceCard');
1396
1397$help_url = '';
1398$shortlabel = dol_trunc($object->label, 16);
1399if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) {
1400 if ($action == 'create') {
1401 $title = $langs->trans("NewProduct");
1402 } else {
1403 $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Card');
1404 $help_url = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos|DE:Modul_Produkte';
1405 }
1406}
1407if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) {
1408 if ($action == 'create') {
1409 $title = $langs->trans("NewService");
1410 } else {
1411 $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Card');
1412 $help_url = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios|DE:Modul_Leistungen';
1413 }
1414}
1415
1416llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-product page-card');
1417
1418// Load object modBarCodeProduct
1419$res = 0;
1420$modBarCodeProduct = null;
1421if (isModEnabled('barcode') && getDolGlobalString('BARCODE_PRODUCT_ADDON_NUM')) {
1422 $module = strtolower(getDolGlobalString('BARCODE_PRODUCT_ADDON_NUM'));
1423 $dirbarcode = array_merge(array('/core/modules/barcode/'), $conf->modules_parts['barcode']);
1424 foreach ($dirbarcode as $dirroot) {
1425 $res = dol_include_once($dirroot.$module.'.php');
1426 if ($res) {
1427 break;
1428 }
1429 }
1430 if ($res > 0) {
1431 $modBarCodeProduct = new $module();
1432 '@phan-var-force ModeleNumRefBarCode $modBarCodeProduct';
1433 }
1434}
1435
1436$canvasdisplayaction = $action;
1437if (in_array($canvasdisplayaction, array('merge', 'confirm_merge'))) {
1438 $canvasdisplayaction = 'view';
1439}
1440
1441if (is_object($objcanvas) && $objcanvas->displayCanvasExists($canvasdisplayaction)) {
1442 // -----------------------------------------
1443 // When used with CANVAS
1444 // -----------------------------------------
1445 $objcanvas->assign_values($canvasdisplayaction, $object->id, $object->ref); // Set value for templates
1446 $objcanvas->display_canvas($canvasdisplayaction); // Show template
1447} else {
1448 // -----------------------------------------
1449 // When used in standard mode
1450 // -----------------------------------------
1451 if ($action == 'create' && $usercancreate) {
1452 //WYSIWYG Editor
1453 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1454
1455 if (!empty($conf->use_javascript_ajax)) {
1456 print '<script type="text/javascript">';
1457 print '$(document).ready(function () {
1458 $("#selectcountry_id").change(function() {
1459 console.log("selectcountry_id change");
1460 document.formprod.action.value="create";
1461 document.formprod.submit();
1462 });
1463 });';
1464 print '</script>'."\n";
1465 }
1466
1467 // Load object modCodeProduct
1468 $module = getDolGlobalString('PRODUCT_CODEPRODUCT_ADDON', 'mod_codeproduct_leopard');
1469 if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php') {
1470 $module = substr($module, 0, dol_strlen($module) - 4);
1471 }
1472 $result = dol_include_once('/core/modules/product/'.$module.'.php');
1473 if ($result > 0) {
1474 $modCodeProduct = new $module();
1475 }
1476
1477 dol_set_focus('input[name="ref"]');
1478
1479 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formprod">';
1480 print '<input type="hidden" name="token" value="'.newToken().'">';
1481 print '<input type="hidden" name="action" value="add">';
1482 print '<input type="hidden" name="type" value="'.$type.'">'."\n";
1483 if (!empty($modCodeProduct->code_auto)) {
1484 print '<input type="hidden" name="code_auto" value="1">';
1485 }
1486 if (!empty($modBarCodeProduct->code_auto)) {
1487 print '<input type="hidden" name="barcode_auto" value="1">';
1488 }
1489 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1490
1491 if ($type == 1) {
1492 $picto = 'service';
1493 $title = $langs->trans("NewService");
1494 } else {
1495 $picto = 'product';
1496 $title = $langs->trans("NewProduct");
1497 }
1498 $linkback = "";
1499 print load_fiche_titre($title, $linkback, $picto);
1500
1501 // We set country_id, country_code and country for the selected country
1502 $object->country_id = GETPOSTISSET('country_id') ? GETPOSTINT('country_id') : null;
1503 if ($object->country_id > 0) {
1504 $tmparray = getCountry($object->country_id, 'all');
1505 $object->country_code = $tmparray['code'];
1506 $object->country = $tmparray['label'];
1507 }
1508
1509 print dol_get_fiche_head();
1510
1511 // Call Hook tabContentCreateProduct
1512 $parameters = array();
1513 // Note that $action and $object may be modified by hook
1514 $reshook = $hookmanager->executeHooks('tabContentCreateProduct', $parameters, $object, $action);
1515 if (empty($reshook)) {
1516 print '<table class="border centpercent">';
1517
1518 if (!getDolGlobalString('PRODUCT_GENERATE_REF_AFTER_FORM')) {
1519 print '<tr>';
1520 $tmpcode = '';
1521 if (!empty($modCodeProduct->code_auto)) {
1522 $tmpcode = $modCodeProduct->getNextValue($object, $type);
1523 }
1524 print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("ProductRef").'</td><td><input id="ref" name="ref" class="maxwidth200" maxlength="128" value="'.dol_escape_htmltag(GETPOSTISSET('ref') ? GETPOST('ref', 'alphanohtml') : $tmpcode).'">';
1525 if ($refalreadyexists) {
1526 print $langs->trans("RefAlreadyExists");
1527 }
1528 print '</td></tr>';
1529 }
1530
1531 // Label
1532 print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input id="label" name="label" class="minwidth300 maxwidth400onsmartphone" maxlength="255" value="'.dol_escape_htmltag(GETPOST('label', $label_security_check)).'"></td></tr>';
1533
1534 // On sell
1535 print '<tr><td class="fieldrequired">'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td>';
1536 $statutarray = array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell"));
1537 print $form->selectarray('statut', $statutarray, GETPOST('statut'));
1538 print '</td></tr>';
1539
1540 // To buy
1541 print '<tr><td class="fieldrequired">'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td>';
1542 $statutarray = array('1' => $langs->trans("ProductStatusOnBuy"), '0' => $langs->trans("ProductStatusNotOnBuy"));
1543 print $form->selectarray('statut_buy', $statutarray, GETPOST('statut_buy'));
1544 print '</td></tr>';
1545
1546 // Batch number management
1547 if (isModEnabled('productbatch')) {
1548 print '<tr><td>'.$langs->trans("ManageLotSerial").'</td><td>';
1549 $statutarray = array('0' => $langs->trans("ProductStatusNotOnBatch"), '1' => $langs->trans("ProductStatusOnBatch"), '2' => $langs->trans("ProductStatusOnSerial"));
1550 print $form->selectarray('status_batch', $statutarray, GETPOSTINT('status_batch'));
1551 print '</td></tr>';
1552 // Product specific batch number management
1553 $status_batch = GETPOSTINT('status_batch');
1554 if ($status_batch !== '0') {
1555 $langs->load("admin");
1556 $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Batch"), $langs->transnoentities("Batch"));
1557 $tooltip .= $langs->trans("GenericMaskCodes1");
1558 $tooltip .= '<br>'.$langs->trans("GenericMaskCodes2");
1559 $tooltip .= '<br>'.$langs->trans("GenericMaskCodes3");
1560 $tooltip .= '<br>'.$langs->trans("GenericMaskCodes4a", $langs->transnoentities("Batch"), $langs->transnoentities("Batch"));
1561 $tooltip .= '<br>'.$langs->trans("GenericMaskCodes5");
1562 //$tooltip .= '<br>'.$langs->trans("GenericMaskCodes5b");
1563
1564 if ((getDolGlobalString('PRODUCTBATCH_LOT_ADDON') == 'mod_lot_advanced')
1565 || (getDolGlobalString('PRODUCTBATCH_SN_ADDON') == 'mod_sn_advanced')) {
1566 print '<tr><td id="mask_option">'.$langs->trans("ManageLotMask").'</td>';
1567 $inherited_mask_lot = getDolGlobalString('LOT_ADVANCED_MASK');
1568 $inherited_mask_sn = getDolGlobalString('SN_ADVANCED_MASK');
1569 print '<td id="field_mask">';
1570 print $form->textwithpicto('<input type="text" class="flat minwidth175" name="batch_mask" id="batch_mask_input">', $tooltip, 1, 'help');
1571 print '<script type="text/javascript">
1572 $(document).ready(function() {
1573 $("#field_mask, #mask_option").addClass("hideobject");
1574 $("#status_batch").on("change", function () {
1575 console.log("We change batch status");
1576 var optionSelected = $("option:selected", this);
1577 var valueSelected = this.value;
1578 $("#field_mask, #mask_option").addClass("hideobject");
1579 ';
1580 if (getDolGlobalString('PRODUCTBATCH_LOT_USE_PRODUCT_MASKS') && getDolGlobalString('PRODUCTBATCH_LOT_ADDON') == 'mod_lot_advanced') {
1581 print '
1582 if (this.value == 1) {
1583 $("#field_mask, #mask_option").toggleClass("hideobject");
1584 $("#batch_mask_input").val("'.$inherited_mask_lot.'");
1585 }
1586 ';
1587 }
1588 if (getDolGlobalString('PRODUCTBATCH_SN_USE_PRODUCT_MASKS') && getDolGlobalString('PRODUCTBATCH_SN_ADDON') == 'mod_sn_advanced') {
1589 print '
1590 if (this.value == 2) {
1591 $("#field_mask, #mask_option").toggleClass("hideobject");
1592 $("#batch_mask_input").val("'.$inherited_mask_sn.'");
1593 }
1594 ';
1595 }
1596 print '
1597 })
1598 })
1599 </script>';
1600 print '</td></tr>';
1601 }
1602 }
1603
1604 // SellBy / EatBy mandatory list
1605 if (!empty($sellOrEatByMandatoryList)) {
1606 print '<tr><td>'.$langs->trans('BatchSellOrEatByMandatoryList', $langs->transnoentities('SellByDate'), $langs->transnoentities('EatByDate')).'</td><td>';
1607 print $form->selectarray('sell_or_eat_by_mandatory', $sellOrEatByMandatoryList, GETPOSTINT('sell_or_eat_by_mandatory'));
1608 print '</td></tr>';
1609 }
1610 }
1611
1612 $showbarcode = isModEnabled('barcode');
1613 if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('barcode', 'lire_advance')) {
1614 $showbarcode = 0;
1615 }
1616
1617 if ($showbarcode && is_object($modBarCodeProduct)) {
1618 //var_dump($modBarCodeProduct); exit;
1619
1620 print '<tr><td>'.$langs->trans('BarcodeType').'</td><td>';
1621 if (GETPOSTISSET('fk_barcode_type')) {
1622 $fk_barcode_type = GETPOST('fk_barcode_type') ? GETPOST('fk_barcode_type') : 0;
1623 } else {
1624 if (empty($fk_barcode_type) && getDolGlobalString('PRODUIT_DEFAULT_BARCODE_TYPE')) {
1625 $fk_barcode_type = getDolGlobalInt("PRODUIT_DEFAULT_BARCODE_TYPE");
1626 } else {
1627 $fk_barcode_type = 0;
1628 }
1629 }
1630 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
1631 $formbarcode = new FormBarCode($db);
1632 print $formbarcode->selectBarcodeType($fk_barcode_type, 'fk_barcode_type', 1);
1633 print '</td>';
1634 print '</tr>';
1635
1636 print '<tr>';
1637 print '<td'.($modBarCodeProduct->code_null ? '' : ' class="fieldrequired"').'>'.$langs->trans("BarcodeValue").'</td><td>';
1638 $tmpcode = GETPOSTISSET('barcode') ? GETPOST('barcode') : $object->barcode;
1639 if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) {
1640 $tmpcode = $modBarCodeProduct->getNextValue($object, $fk_barcode_type);
1641 }
1642 print img_picto('', 'barcode', 'class="pictofixedwidth"');
1643 print '<input class="maxwidth150" type="text" name="barcode" value="'.dol_escape_htmltag($tmpcode).'">';
1644 print '</td></tr>';
1645 }
1646
1647 // Description (used in invoice, propal...)
1648 print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
1649 $doleditor = new DolEditor('desc', GETPOST('desc', 'restricthtml'), '', 160, 'dolibarr_details', '', false, true, getDolGlobalString('FCKEDITOR_ENABLE_DETAILS'), ROWS_4, '90%');
1650 $doleditor->Create();
1651 print "</td></tr>";
1652
1653 if (!getDolGlobalString('PRODUCT_DISABLE_PUBLIC_URL')) {
1654 // Public URL
1655 print '<tr><td>'.$langs->trans("PublicUrl").'</td><td>';
1656 print img_picto('', 'globe', 'class="pictofixedwidth"');
1657 print '<input type="text" name="url" class="quatrevingtpercent" value="'.GETPOST('url').'">';
1658 print '</td></tr>';
1659 }
1660
1661 if (($type != 1 || getDolGlobalInt('STOCK_SUPPORTS_SERVICES')) && isModEnabled('stock')) {
1662 // Default warehouse
1663 print '<tr><td>'.$langs->trans("DefaultWarehouse").'</td><td>';
1664 print img_picto($langs->trans("DefaultWarehouse"), 'stock', 'class="pictofixedwidth"');
1665 print $formproduct->selectWarehouses(GETPOSTINT('fk_default_warehouse'), 'fk_default_warehouse', 'warehouseopen', 1, 0, 0, '', 0, 0, array(), 'minwidth300 widthcentpercentminusxx maxwidth500');
1666 print ' <a href="'.DOL_URL_ROOT.'/product/stock/card.php?action=create&token='.newToken().'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?&action=create&type='.GETPOSTINT('type')).'">';
1667 print '<span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddWarehouse").'"></span>';
1668 print '</a>';
1669
1670 print '</td>';
1671 print '</tr>';
1672
1673 if (!getDolGlobalString('PRODUCT_DISABLE_STOCK_LEVELS')) {
1674 // Stock min level
1675 print '<tr><td>'.$form->textwithpicto($langs->trans("StockLimit"), $langs->trans("StockLimitDesc"), 1).'</td><td>';
1676 print '<input name="seuil_stock_alerte" class="maxwidth50" value="'.GETPOST('seuil_stock_alerte').'">';
1677 print '</td>';
1678 print '</tr>';
1679
1680 // Stock desired level
1681 print '<tr><td>'.$form->textwithpicto($langs->trans("DesiredStock"), $langs->trans("DesiredStockDesc"), 1).'</td><td>';
1682 print '<input name="desiredstock" class="maxwidth50" value="'.GETPOST('desiredstock').'">';
1683 print '</td></tr>';
1684 }
1685 } else {
1686 if (!getDolGlobalString('PRODUCT_DISABLE_STOCK_LEVELS')) {
1687 print '<input name="seuil_stock_alerte" type="hidden" value="0">';
1688 print '<input name="desiredstock" type="hidden" value="0">';
1689 }
1690 }
1691
1692 if ($type == $object::TYPE_SERVICE && isModEnabled("workstation")) {
1693 // Default workstation
1694 print '<tr><td>'.$langs->trans("DefaultWorkstation").'</td><td>';
1695 print img_picto($langs->trans("DefaultWorkstation"), 'workstation', 'class="pictofixedwidth"');
1696 print $formproduct->selectWorkstations((GETPOSTISSET('fk_default_workstation') ? GETPOSTINT('fk_default_workstation') : ''), 'fk_default_workstation', 1);
1697 print '</td></tr>';
1698 }
1699
1700 // Duration
1701 if ($type == 1) {
1702 print '<tr><td>'.$langs->trans("Duration").'</td><td>';
1703 print img_picto('', 'clock', 'class="pictofixedwidth"');
1704 print '<input name="duration_value" class="width50" value="'.(GETPOSTISSET('duration_value') ? GETPOST('duration_value') : '').'">';
1705 print $formproduct->selectMeasuringUnits("duration_unit", "time", (GETPOSTISSET('duration_unit') ? GETPOST('duration_unit', 'alpha') : 'h'), 0, 1);
1706
1707 // Mandatory period
1708 if ($object->duration_value > 0) {
1709 print ' &nbsp; &nbsp; ';
1710 }
1711 print '<input type="checkbox" class="marginleftonly valignmiddle" id="mandatoryperiod" name="mandatoryperiod"'.(GETPOSTISSET('mandatoryperiod') ? ' checked="checked"' : '').'>';
1712 print '<label for="mandatoryperiod">';
1713 $htmltooltip = $langs->trans("mandatoryHelper");
1714 if (!getDolGlobalString('SERVICE_STRICT_MANDATORY_PERIOD')) {
1715 $htmltooltip .= '<br>'.$langs->trans("mandatoryHelper2");
1716 }
1717 print $form->textwithpicto($langs->trans("mandatoryperiod"), $htmltooltip, 1, 'info');
1718 print '</label>';
1719
1720 print '</td></tr>';
1721 }
1722
1723 if ($type != 1) { // Nature, Weight and volume only applies to products and not to services
1724 if (!getDolGlobalString('PRODUCT_DISABLE_NATURE')) {
1725 // Nature
1726 print '<tr><td>'.$form->textwithpicto($langs->trans("NatureOfProductShort"), $langs->trans("NatureOfProductDesc")).'</td><td>';
1727 print $formproduct->selectProductNature('finished', (GETPOST('finished') ? GETPOST('finished') : (string) $object->finished));
1728 print '</td></tr>';
1729 }
1730 }
1731
1732 if ($type != 1) {
1733 if (!getDolGlobalString('PRODUCT_DISABLE_WEIGHT')) {
1734 // Brut Weight
1735 print '<tr><td>'.$langs->trans("Weight").'</td><td>';
1736 print img_picto('', 'fa-balance-scale', 'class="pictofixedwidth"');
1737 print '<input name="weight" size="4" value="'.GETPOST('weight').'">';
1738 print $formproduct->selectMeasuringUnits("weight_units", "weight", GETPOSTISSET('weight_units') ? GETPOST('weight_units', 'alpha') : (GETPOST('weight_units', 'alpha') ?: getDolGlobalString('MAIN_WEIGHT_DEFAULT_UNIT', 0)), 0, 2);
1739 print '</td></tr>';
1740 }
1741
1742 // Brut Length
1743 if (!getDolGlobalString('PRODUCT_DISABLE_SIZE')) {
1744 print '<tr><td>'.$langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").'</td><td>';
1745 print img_picto('', 'fa-ruler', 'class="pictofixedwidth"');
1746 print '<input name="size" class="width50" value="'.GETPOST('size').'"> x ';
1747 print '<input name="sizewidth" class="width50" value="'.GETPOST('sizewidth').'"> x ';
1748 print '<input name="sizeheight" class="width50" value="'.GETPOST('sizeheight').'">';
1749 print $formproduct->selectMeasuringUnits("size_units", "size", GETPOSTISSET('size_units') ? GETPOST('size_units', 'alpha') : (GETPOST('size_units', 'alpha') ?: '0'), 0, 2);
1750 print '</td></tr>';
1751 }
1752 if (!getDolGlobalString('PRODUCT_DISABLE_SURFACE')) {
1753 // Brut Surface
1754 print '<tr><td>'.$langs->trans("Surface").'</td><td>';
1755 print '<input name="surface" size="4" value="'.GETPOST('surface').'">';
1756 print $formproduct->selectMeasuringUnits("surface_units", "surface", GETPOSTISSET('surface_units') ? GETPOST('surface_units', 'alpha') : (GETPOST('surface_units', 'alpha') ?: '0'), 0, 2);
1757 print '</td></tr>';
1758 }
1759 if (!getDolGlobalString('PRODUCT_DISABLE_VOLUME')) {
1760 // Brut Volume
1761 print '<tr><td>'.$langs->trans("Volume").'</td><td>';
1762 print '<input name="volume" size="4" value="'.GETPOST('volume').'">';
1763 print $formproduct->selectMeasuringUnits("volume_units", "volume", GETPOSTISSET('volume_units') ? GETPOST('volume_units', 'alpha') : (GETPOST('volume_units', 'alpha') ?: '0'), 0, 2);
1764 print '</td></tr>';
1765 }
1766
1767 if (getDolGlobalString('PRODUCT_ADD_NET_MEASURE')) {
1768 // Net Measure
1769 print '<tr><td>'.$langs->trans("NetMeasure").'</td><td>';
1770 print '<input name="net_measure" size="4" value="'.GETPOST('net_measure').'">';
1771 print $formproduct->selectMeasuringUnits("net_measure_units", '', GETPOSTISSET('net_measure_units') ? GETPOST('net_measure_units', 'alpha') : (GETPOST('net_measure_units', 'alpha') ?: getDolGlobalString('MAIN_WEIGHT_DEFAULT_UNIT', 0)), 0, 0);
1772 print '</td></tr>';
1773 }
1774 }
1775
1776 // Units
1777 if (getDolGlobalString('PRODUCT_USE_UNITS')) {
1778 print '<tr><td>'.$langs->trans('DefaultUnitToShow').'</td>';
1779 print '<td>';
1780 print $form->selectUnits(GETPOSTISSET('units') ? GETPOST('units', 'alpha') : (GETPOST('units', 'alpha') ?: '0'), 'units');
1781 print '</td></tr>';
1782 }
1783
1784 // Custom code
1785 if (!getDolGlobalString('PRODUCT_DISABLE_CUSTOMS_INFO') && empty($type)) {
1786 print '<tr><td class="wordbreak">'.$form->textwithpicto($langs->trans("CustomsCode"), $langs->trans("CustomsCodeHelp")).'</td><td><input name="customcode" class="maxwidth100onsmartphone" value="'.GETPOST('customcode').'"></td></tr>';
1787
1788 // Origin country
1789 print '<tr><td>'.$langs->trans("CountryOrigin").'</td>';
1790 print '<td>';
1791 print img_picto('', 'globe-americas', 'class="pictofixedwidth"');
1792 print $form->select_country((GETPOSTISSET('country_id') ? GETPOST('country_id') : $object->country_id), 'country_id', '', 0, 'minwidth300 widthcentpercentminusx maxwidth500');
1793 if ($user->admin) {
1794 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1795 }
1796 print '</td></tr>';
1797
1798 // State
1799 if (!getDolGlobalString('PRODUCT_DISABLE_STATE')) {
1800 print '<tr>';
1801 if (getDolGlobalString('MAIN_SHOW_REGION_IN_STATE_SELECT') && (getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) {
1802 print '<td>'.$form->editfieldkey('RegionStateOrigin', 'state_id', '', $object, 0).'</td><td>';
1803 } else {
1804 print '<td>'.$form->editfieldkey('StateOrigin', 'state_id', '', $object, 0).'</td><td>';
1805 }
1806
1807 print img_picto('', 'state', 'class="pictofixedwidth"');
1808 print $formcompany->select_state($object->state_id, $object->country_code);
1809 print '</tr>';
1810 }
1811 }
1812
1813 // Quality control
1814 if (getDolGlobalString('PRODUCT_LOT_ENABLE_QUALITY_CONTROL')) {
1815 print '<tr><td>'.$langs->trans("LifeTime").'</td><td><input name="lifetime" class="maxwidth50" value="'.GETPOST('lifetime').'"></td></tr>';
1816 print '<tr><td>'.$langs->trans("QCFrequency").'</td><td><input name="qc_frequency" class="maxwidth50" value="'.GETPOST('qc_frequency').'"></td></tr>';
1817 }
1818
1819 // Other attributes
1820 $parameters = array('colspan' => ' colspan="2"', 'cols' => 2);
1821 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1822 print $hookmanager->resPrint;
1823 if (empty($reshook)) {
1824 print $object->showOptionals($extrafields, 'create', $parameters);
1825 }
1826
1827 // Note (private, no output on invoices, propales...)
1828 print '<tr><td class="tdtop">'.$langs->trans("NoteNotVisibleOnBill").'</td><td>';
1829
1830 // We use dolibarr_details as type of DolEditor here, because we must not accept images as description is included into PDF and not accepted by TCPDF.
1831 $doleditor = new DolEditor('note_private', GETPOST('note_private', 'restricthtml'), '', 140, 'dolibarr_details', '', false, true, getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE'), ROWS_8, '90%');
1832 $doleditor->Create();
1833
1834 print "</td></tr>";
1835
1836 if (isModEnabled('category')) {
1837 // Categories
1838 print '<tr><td>'.$langs->trans("Categories").'</td><td>';
1839 print $form->selectCategories(Categorie::TYPE_PRODUCT, 'categories', $object);
1840 print "</td></tr>";
1841 }
1842
1843 print '</table>';
1844
1845 print '<hr>';
1846
1847 if (!getDolGlobalString('PRODUCT_DISABLE_PRICES')) {
1848 if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) {
1849 // We do no show price array on create when multiprices enabled.
1850 // We must set them on prices tab.
1851 print '<table class="border centpercent">';
1852 // VAT
1853 print '<tr><td class="titlefieldcreate">'.$langs->trans("VATRate").'</td><td>';
1854 $defaultva = get_default_tva($mysoc, $mysoc);
1855 print $form->load_tva("tva_tx", $defaultva, $mysoc, $mysoc, 0, 0, '', false, 1);
1856 print ajax_combobox("tva_tx");
1857 print '</td></tr>';
1858
1859 print '</table>';
1860
1861 print '<br>';
1862 } else {
1863 print '<table class="border centpercent">';
1864
1865 // Price
1866 print '<tr><td class="titlefieldcreate">'.$langs->trans("SellingPrice").'</td>';
1867 print '<td><input name="price" class="maxwidth50" value="'.$object->price.'">';
1868 print $form->selectPriceBaseType(getDolGlobalString('PRODUCT_PRICE_BASE_TYPE'), "price_base_type");
1869 print ajax_combobox("select_price_base_type");
1870 print '</td></tr>';
1871
1872 // Min price
1873 print '<tr><td>'.$langs->trans("MinPrice").'</td>';
1874 print '<td><input name="price_min" class="maxwidth50" value="'.$object->price_min.'">';
1875 print '</td></tr>';
1876
1877 // VAT
1878 print '<tr><td>'.$langs->trans("VATRate").'</td><td>';
1879 $defaultva = get_default_tva($mysoc, $mysoc);
1880 print $form->load_tva("tva_tx", $defaultva, $mysoc, $mysoc, 0, 0, '', false, 1);
1881 print ajax_combobox("tva_tx");
1882 print '</td></tr>';
1883
1884 print '</table>';
1885
1886 print '<br>';
1887 }
1888 }
1889
1890 // Accountancy codes
1891 print '<!-- accountancy codes -->'."\n";
1892 print '<table class="border centpercent">';
1893
1894 if (!getDolGlobalString('PRODUCT_DISABLE_ACCOUNTING')) {
1895 if (isModEnabled('accounting')) {
1897 // Accountancy_code_sell
1898 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
1899 print '<td>';
1900 if ($type == 0) {
1901 $accountancy_code_sell = (GETPOSTISSET('accountancy_code_sell') ? GETPOST('accountancy_code_sell', 'alpha') : getDolGlobalString("ACCOUNTING_PRODUCT_SOLD_ACCOUNT"));
1902 } else {
1903 $accountancy_code_sell = (GETPOSTISSET('accountancy_code_sell') ? GETPOST('accountancy_code_sell', 'alpha') : getDolGlobalString("ACCOUNTING_SERVICE_SOLD_ACCOUNT"));
1904 }
1905 print $formaccounting->select_account($accountancy_code_sell, 'accountancy_code_sell', 1, array(), 1, 1, 'minwidth150 maxwidth300', '1');
1906 print '</td></tr>';
1907
1908 // Accountancy_code_sell_intra
1909 if ($mysoc->isInEEC()) {
1910 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellIntraCode").'</td>';
1911 print '<td>';
1912 if ($type == 0) {
1913 $accountancy_code_sell_intra = (GETPOSTISSET('accountancy_code_sell_intra') ? GETPOST('accountancy_code_sell_intra', 'alpha') : getDolGlobalString("ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT"));
1914 } else {
1915 $accountancy_code_sell_intra = (GETPOSTISSET('accountancy_code_sell_intra') ? GETPOST('accountancy_code_sell_intra', 'alpha') : getDolGlobalString("ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT"));
1916 }
1917 print $formaccounting->select_account($accountancy_code_sell_intra, 'accountancy_code_sell_intra', 1, array(), 1, 1, 'minwidth150 maxwidth300', '1');
1918 print '</td></tr>';
1919 }
1920
1921 // Accountancy_code_sell_export
1922 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellExportCode").'</td>';
1923 print '<td>';
1924 if ($type == 0) {
1925 $accountancy_code_sell_export = (GETPOST('accountancy_code_sell_export') ? GETPOST('accountancy_code_sell_export', 'alpha') : getDolGlobalString("ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT"));
1926 } else {
1927 $accountancy_code_sell_export = (GETPOST('accountancy_code_sell_export') ? GETPOST('accountancy_code_sell_export', 'alpha') : getDolGlobalString("ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT"));
1928 }
1929 print $formaccounting->select_account($accountancy_code_sell_export, 'accountancy_code_sell_export', 1, array(), 1, 1, 'minwidth150 maxwidth300', '1');
1930 print '</td></tr>';
1931
1932 // Accountancy_code_buy
1933 print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
1934 print '<td>';
1935 if ($type == 0) {
1936 $accountancy_code_buy = (GETPOST('accountancy_code_buy', 'alpha') ? (GETPOST('accountancy_code_buy', 'alpha')) : getDolGlobalString("ACCOUNTING_PRODUCT_BUY_ACCOUNT"));
1937 } else {
1938 $accountancy_code_buy = (GETPOST('accountancy_code_buy', 'alpha') ? (GETPOST('accountancy_code_buy', 'alpha')) : getDolGlobalString("ACCOUNTING_SERVICE_BUY_ACCOUNT"));
1939 }
1940 print $formaccounting->select_account($accountancy_code_buy, 'accountancy_code_buy', 1, array(), 1, 1, 'minwidth150 maxwidth300', '1');
1941 print '</td></tr>';
1942
1943 // Accountancy_code_buy_intra
1944 if ($mysoc->isInEEC()) {
1945 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyIntraCode").'</td>';
1946 print '<td>';
1947 if ($type == 0) {
1948 $accountancy_code_buy_intra = (GETPOSTISSET('accountancy_code_buy_intra') ? GETPOST('accountancy_code_buy_intra', 'alpha') : getDolGlobalString("ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT"));
1949 } else {
1950 $accountancy_code_buy_intra = (GETPOSTISSET('accountancy_code_buy_intra') ? GETPOST('accountancy_code_buy_intra', 'alpha') : getDolGlobalString("ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT"));
1951 }
1952 print $formaccounting->select_account($accountancy_code_buy_intra, 'accountancy_code_buy_intra', 1, array(), 1, 1, 'minwidth150 maxwidth300', '1');
1953 print '</td></tr>';
1954 }
1955
1956 // Accountancy_code_buy_export
1957 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyExportCode").'</td>';
1958 print '<td>';
1959 if ($type == 0) {
1960 $accountancy_code_buy_export = (GETPOST('accountancy_code_buy_export') ? GETPOST('accountancy_code_buy_export', 'alpha') : getDolGlobalString("ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT"));
1961 } else {
1962 $accountancy_code_buy_export = (GETPOST('accountancy_code_buy_export') ? GETPOST('accountancy_code_buy_export', 'alpha') : getDolGlobalString("ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT"));
1963 }
1964 print $formaccounting->select_account($accountancy_code_buy_export, 'accountancy_code_buy_export', 1, array(), 1, 1, 'minwidth150 maxwidth300', '1');
1965 print '</td></tr>';
1966 } else {// For external software
1967 if (!empty($accountancy_code_sell)) {
1968 $object->accountancy_code_sell = $accountancy_code_sell;
1969 }
1970 if (!empty($accountancy_code_sell_intra)) {
1971 $object->accountancy_code_sell_intra = $accountancy_code_sell_intra;
1972 }
1973 if (!empty($accountancy_code_sell_export)) {
1974 $object->accountancy_code_sell_export = $accountancy_code_sell_export;
1975 }
1976 if (!empty($accountancy_code_buy)) {
1977 $object->accountancy_code_buy = $accountancy_code_buy;
1978 }
1979 if (!empty($accountancy_code_buy_intra)) {
1980 $object->accountancy_code_buy_intra = $accountancy_code_buy_intra;
1981 }
1982 if (!empty($accountancy_code_buy_export)) {
1983 $object->accountancy_code_buy_export = $accountancy_code_buy_export;
1984 }
1985
1986 // Accountancy_code_sell
1987 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
1988 print '<td class="maxwidthonsmartphone"><input class="minwidth150" name="accountancy_code_sell" value="'.$object->accountancy_code_sell.'">';
1989 print '</td></tr>';
1990
1991 // Accountancy_code_sell_intra
1992 if ($mysoc->isInEEC()) {
1993 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellIntraCode").'</td>';
1994 print '<td class="maxwidthonsmartphone"><input class="minwidth150" name="accountancy_code_sell_intra" value="'.$object->accountancy_code_sell_intra.'">';
1995 print '</td></tr>';
1996 }
1997
1998 // Accountancy_code_sell_export
1999 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellExportCode").'</td>';
2000 print '<td class="maxwidthonsmartphone"><input class="minwidth150" name="accountancy_code_sell_export" value="'.$object->accountancy_code_sell_export.'">';
2001 print '</td></tr>';
2002
2003 // Accountancy_code_buy
2004 print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
2005 print '<td class="maxwidthonsmartphone"><input class="minwidth150" name="accountancy_code_buy" value="'.$object->accountancy_code_buy.'">';
2006 print '</td></tr>';
2007
2008 // Accountancy_code_buy_intra
2009 if ($mysoc->isInEEC()) {
2010 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyIntraCode").'</td>';
2011 print '<td class="maxwidthonsmartphone"><input class="minwidth150" name="accountancy_code_buy_intra" value="'.$object->accountancy_code_buy_intra.'">';
2012 print '</td></tr>';
2013 }
2014
2015 // Accountancy_code_buy_export
2016 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyExportCode").'</td>';
2017 print '<td class="maxwidthonsmartphone"><input class="minwidth150" name="accountancy_code_buy_export" value="'.$object->accountancy_code_buy_export.'">';
2018 print '</td></tr>';
2019 }
2020 }
2021 print '</table>';
2022 }
2023
2024 print dol_get_fiche_end();
2025
2026 print $form->buttonsSaveCancel("Create");
2027
2028 print '</form>';
2029 } elseif ($object->id > 0) {
2030 /*
2031 * Product card
2032 */
2033
2034 // Card in edit mode
2035 if ($action == 'edit' && $usercancreate) {
2036 //WYSIWYG Editor
2037 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
2038
2039 if (!empty($conf->use_javascript_ajax)) {
2040 print '<script type="text/javascript">';
2041 print '$(document).ready(function () {
2042 $("#selectcountry_id").change(function () {
2043 document.formprod.action.value="edit";
2044 document.formprod.submit();
2045 });
2046 });';
2047 print '</script>'."\n";
2048 }
2049
2050 // We set country_id, country_code and country for the selected country
2051 $object->country_id = GETPOST('country_id') ? GETPOST('country_id') : $object->country_id;
2052 if ($object->country_id) {
2053 $tmparray = getCountry($object->country_id, 'all');
2054 $object->country_code = $tmparray['code'];
2055 $object->country = $tmparray['label'];
2056 }
2057
2058 $type = $langs->trans('Product');
2059 if ($object->isService()) {
2060 $type = $langs->trans('Service');
2061 }
2062 // print load_fiche_titre($langs->trans('Modify').' '.$type.' : '.(is_object($object->oldcopy)?$object->oldcopy->ref:$object->ref), "");
2063
2064 // Main official, simple, and not duplicated code
2065 print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="POST" name="formprod">'."\n";
2066 print '<input type="hidden" name="token" value="'.newToken().'">';
2067 print '<input type="hidden" name="action" value="update">';
2068 print '<input type="hidden" name="id" value="'.$object->id.'">';
2069 print '<input type="hidden" name="canvas" value="'.$object->canvas.'">';
2070
2072 $titre = $langs->trans("CardProduct".$object->type);
2073 $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
2074 print dol_get_fiche_head($head, 'card', $titre, 0, $picto, 0, '', '', 0, '', 1);
2075
2076 // Call Hook tabContentEditProduct
2077 $parameters = array();
2078 // Note that $action and $object may be modified by hook
2079 $reshook = $hookmanager->executeHooks('tabContentEditProduct', $parameters, $object, $action);
2080
2081 if (empty($reshook)) {
2082 print '<table class="border allwidth">';
2083
2084 // Ref
2085 if (!getDolGlobalString('MAIN_PRODUCT_REF_NOT_EDITABLE')) {
2086 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td colspan="3"><input name="ref" class="maxwidth200" maxlength="128" value="'.dol_escape_htmltag(GETPOSTISSET('ref') ? GETPOST('ref') : $object->ref).'"></td></tr>';
2087 } else {
2088 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td colspan="3"><input name="ref" class="maxwidth200" maxlength="128" value="'.dol_escape_htmltag($object->ref).'" readonly="true"></td></tr>';
2089 }
2090
2091 // Label
2092 print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td colspan="3"><input name="label" class="minwidth300 maxwidth400onsmartphone" maxlength="255" value="'.dol_escape_htmltag(GETPOSTISSET('label') ? GETPOST('label') : $object->label).'"></td></tr>';
2093
2094 // Status To sell
2095 print '<tr><td class="fieldrequired">'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td colspan="3">';
2096 print '<select class="flat" name="statut">';
2097 if ((GETPOSTISSET('statut') && GETPOST('statut')) || (!GETPOSTISSET('statut') && $object->status)) {
2098 print '<option value="1" selected>'.$langs->trans("OnSell").'</option>';
2099 print '<option value="0">'.$langs->trans("NotOnSell").'</option>';
2100 } else {
2101 print '<option value="1">'.$langs->trans("OnSell").'</option>';
2102 print '<option value="0" selected>'.$langs->trans("NotOnSell").'</option>';
2103 }
2104 print '</select>';
2105 print '</td></tr>';
2106
2107 // Status To Buy
2108 print '<tr><td class="fieldrequired">'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="3">';
2109 print '<select class="flat" name="statut_buy">';
2110 if ((GETPOSTISSET('statut_buy') && GETPOST('statut_buy')) || (!GETPOSTISSET('statut_buy') && $object->status_buy)) {
2111 print '<option value="1" selected>'.$langs->trans("ProductStatusOnBuy").'</option>';
2112 print '<option value="0">'.$langs->trans("ProductStatusNotOnBuy").'</option>';
2113 } else {
2114 print '<option value="1">'.$langs->trans("ProductStatusOnBuy").'</option>';
2115 print '<option value="0" selected>'.$langs->trans("ProductStatusNotOnBuy").'</option>';
2116 }
2117 print '</select>';
2118 print '</td></tr>';
2119
2120 // Batch number management
2121 if (isModEnabled('productbatch')) {
2122 if ($object->isProduct() || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
2123 print '<tr><td>'.$langs->trans("ManageLotSerial").'</td><td>';
2124 $statutarray = array('0' => $langs->trans("ProductStatusNotOnBatch"), '1' => $langs->trans("ProductStatusOnBatch"), '2' => $langs->trans("ProductStatusOnSerial"));
2125
2126 print $form->selectarray('status_batch', $statutarray, GETPOSTISSET('status_batch') ? GETPOSTINT('status_batch') : $object->status_batch);
2127
2128 print '<span id="statusBatchWarning" class="warning" style="display: none;">';
2129 print img_warning().'&nbsp;'.$langs->trans("WarningConvertFromBatchToSerial").'</span>';
2130
2131 print '<span id="statusBatchMouvToGlobal" class="warning" style="display: none;">';
2132 print img_warning().'&nbsp;'.$langs->trans("WarningTransferBatchStockMouvToGlobal").'</span>';
2133
2134 if ($object->status_batch) {
2135 // Display message to make user know that all batch will be move into global stock
2136 print '<script type="text/javascript">
2137 $(document).ready(function() {
2138 console.log($("#statusBatchWarning"))
2139 $("#status_batch").on("change", function() {
2140 if ($("#status_batch")[0].value == 0) {
2141 $("#statusBatchMouvToGlobal").show()
2142 } else {
2143 $("#statusBatchMouvToGlobal").hide()
2144 }
2145 })
2146 })</script>';
2147
2148 // Display message to explain that if the product currently have a quantity higher or equal to 2, switching to this choice means we will still have a product with different objects of the same batch (while we want a unique serial number)
2149 if ($object->status_batch == 1) {
2150 print '<script type="text/javascript">
2151 $(document).ready(function() {
2152 console.log($("#statusBatchWarning"))
2153 $("#status_batch").on("change", function() {
2154 if ($("#status_batch")[0].value == 2) {
2155 $("#statusBatchWarning").show()
2156 } else {
2157 $("#statusBatchWarning").hide()
2158 }
2159 })
2160 })</script>';
2161 }
2162 }
2163
2164 print '</td></tr>';
2165 if (!empty($object->status_batch) || !empty($conf->use_javascript_ajax)) {
2166 $langs->load("admin");
2167 $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Batch"), $langs->transnoentities("Batch"));
2168 $tooltip .= '<br>'.$langs->trans("GenericMaskCodes2");
2169 $tooltip .= '<br>'.$langs->trans("GenericMaskCodes3");
2170 $tooltip .= '<br>'.$langs->trans("GenericMaskCodes4a", $langs->transnoentities("Batch"), $langs->transnoentities("Batch"));
2171 $tooltip .= '<br>'.$langs->trans("GenericMaskCodes5");
2172 //$tooltip .= '<br>'.$langs->trans("GenericMaskCodes5b");
2173
2174 print '<tr><td id="mask_option">'.$langs->trans("ManageLotMask").'</td>';
2175 $mask = '';
2176 if ($object->status_batch == '1' && getDolGlobalString('PRODUCTBATCH_LOT_USE_PRODUCT_MASKS') && getDolGlobalString('PRODUCTBATCH_LOT_ADDON') == 'mod_lot_advanced') {
2177 $mask = !empty($object->batch_mask) ? $object->batch_mask : getDolGlobalString('LOT_ADVANCED_MASK');
2178 }
2179 if ($object->status_batch == '2' && getDolGlobalString('PRODUCTBATCH_SN_USE_PRODUCT_MASKS') && getDolGlobalString('PRODUCTBATCH_SN_ADDON') == 'mod_sn_advanced') {
2180 $mask = !empty($object->batch_mask) ? $object->batch_mask : getDolGlobalString('SN_ADVANCED_MASK');
2181 }
2182 $inherited_mask_lot = getDolGlobalString('LOT_ADVANCED_MASK');
2183 $inherited_mask_sn = getDolGlobalString('SN_ADVANCED_MASK');
2184 print '<td id="field_mask">';
2185 print $form->textwithpicto('<input type="text" class="flat minwidth175" name="batch_mask" id="batch_mask_input" value="'.$mask.'">', $tooltip, 1, 'help');
2186 // Add javascript to sho/hide field for custom mask
2187 if (!empty($conf->use_javascript_ajax)) {
2188 print '<script type="text/javascript">
2189 $(document).ready(function() {
2190 $("#field_mask").parent().addClass("hideobject");
2191 var preselect = document.getElementById("status_batch");';
2192 if (getDolGlobalString('PRODUCTBATCH_SN_USE_PRODUCT_MASKS')) {
2193 print 'if (preselect.value == "2") {
2194 $("#field_mask").parent().removeClass("hideobject");
2195 }';
2196 }
2197 if (getDolGlobalString('PRODUCTBATCH_LOT_USE_PRODUCT_MASKS')) {
2198 print 'if (preselect.value == "1") {
2199 $("#field_mask").parent().removeClass("hideobject");
2200 }';
2201 }
2202 print '$("#status_batch").on("change", function () {
2203 var optionSelected = $("option:selected", this);
2204 var valueSelected = this.value;
2205 $("#field_mask").parent().addClass("hideobject");
2206 ';
2207 if (getDolGlobalString('PRODUCTBATCH_LOT_USE_PRODUCT_MASKS') && getDolGlobalString('PRODUCTBATCH_LOT_ADDON') == 'mod_lot_advanced') {
2208 print '
2209 if (this.value == 1) {
2210 $("#field_mask").parent().removeClass("hideobject");
2211 $("#batch_mask_input").val("'.$inherited_mask_lot.'");
2212 }
2213 ';
2214 }
2215 if (getDolGlobalString('PRODUCTBATCH_SN_USE_PRODUCT_MASKS') && getDolGlobalString('PRODUCTBATCH_SN_ADDON') == 'mod_sn_advanced') {
2216 print '
2217 if (this.value == 2) {
2218 $("#field_mask").parent().removeClass("hideobject");
2219 $("#batch_mask_input").val("'.$inherited_mask_sn.'");
2220 }
2221 ';
2222 }
2223 print '
2224 })
2225 })
2226 </script>';
2227 }
2228 print '</td></tr>';
2229 }
2230 }
2231
2232 // SellBy / EatBy mandatory list
2233 if (!empty($sellOrEatByMandatoryList)) {
2234 if (GETPOSTISSET('sell_or_eat_by_mandatory')) {
2235 $sellOrEatByMandatorySelectedId = GETPOSTINT('sell_or_eat_by_mandatory');
2236 } else {
2237 $sellOrEatByMandatorySelectedId = $object->sell_or_eat_by_mandatory;
2238 }
2239 print '<tr><td>'.$langs->trans('BatchSellOrEatByMandatoryList', $langs->transnoentities('SellByDate'), $langs->transnoentities('EatByDate')).'</td><td>';
2240 print $form->selectarray('sell_or_eat_by_mandatory', $sellOrEatByMandatoryList, $sellOrEatByMandatorySelectedId);
2241 print '</td></tr>';
2242 }
2243 }
2244
2245 // Barcode
2246 $showbarcode = isModEnabled('barcode');
2247 if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('barcode', 'lire_advance')) {
2248 $showbarcode = 0;
2249 }
2250
2251 if ($showbarcode) {
2252 print '<tr><td>'.$langs->trans('BarcodeType').'</td><td>';
2253 if (GETPOSTISSET('fk_barcode_type')) {
2254 $fk_barcode_type = GETPOST('fk_barcode_type');
2255 } else {
2256 $fk_barcode_type = $object->barcode_type;
2257 if (empty($fk_barcode_type) && getDolGlobalString('PRODUIT_DEFAULT_BARCODE_TYPE')) {
2258 $fk_barcode_type = getDolGlobalString('PRODUIT_DEFAULT_BARCODE_TYPE');
2259 }
2260 }
2261 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
2262 $formbarcode = new FormBarCode($db);
2263 print $formbarcode->selectBarcodeType($fk_barcode_type, 'fk_barcode_type', 1);
2264 print '</td></tr>';
2265 print '<tr><td>'.$langs->trans("BarcodeValue").'</td><td>';
2266 $tmpcode = GETPOSTISSET('barcode') ? GETPOST('barcode') : $object->barcode;
2267 if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) {
2268 $tmpcode = $modBarCodeProduct->getNextValue($object, $fk_barcode_type);
2269 }
2270 print '<input class="maxwidth150 maxwidthonsmartphone" type="text" name="barcode" value="'.dol_escape_htmltag($tmpcode).'">';
2271 print '</td></tr>';
2272 }
2273
2274 // Description (used in invoice, propal...)
2275 print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
2276
2277 // We use dolibarr_details as type of DolEditor here, because we must not accept images, as description is included into PDF and external links are not accepted by TCPDF.
2278 $doleditor = new DolEditor('desc', GETPOSTISSET('desc') ? GETPOST('desc', 'restricthtml') : $object->description, '', 160, 'dolibarr_details', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_4, '90%');
2279 $doleditor->Create();
2280
2281 print "</td></tr>";
2282 print "\n";
2283
2284 // Public Url
2285 if (!getDolGlobalString('PRODUCT_DISABLE_PUBLIC_URL')) {
2286 print '<tr><td>'.$langs->trans("PublicUrl").'</td><td>';
2287 print img_picto('', 'globe', 'class="pictofixedwidth"');
2288 print '<input type="text" name="url" class="maxwidth500 widthcentpercentminusx" value="'.(GETPOSTISSET('url') ? GETPOST('url') : $object->url).'">';
2289 print '</td></tr>';
2290 }
2291
2292 // Stock
2293 if (($object->isProduct() || getDolGlobalInt('STOCK_SUPPORTS_SERVICES')) && isModEnabled('stock')) {
2294 if (isModEnabled('productbatch') && $object->hasbatch()) {
2295 print '<tr><td><input type="hidden" id="stockable_product" name="stockable_product" value="on" /></td><td></td></tr>';
2296 } else {
2297 print '<tr><td><label for="stockable_product">' . $langs->trans("StockableProduct") . '</label></td>';
2298 $checked = empty($object->stockable_product) ? "" : "checked";
2299 print '<td><input type="checkbox" id="stockable_product" name="stockable_product" '. $checked . ' /></td></tr>';
2300 }
2301
2302 // Default warehouse
2303 print '<tr class="showifstockable'.(empty($object->stockable_product) ? ' hidden' : '').'"><td>'.$langs->trans("DefaultWarehouse").'</td><td>';
2304 print img_picto($langs->trans("DefaultWarehouse"), 'stock', 'class="pictofixedwidth"');
2305 print $formproduct->selectWarehouses((GETPOSTISSET('fk_default_warehouse') ? GETPOST('fk_default_warehouse') : $object->fk_default_warehouse), 'fk_default_warehouse', 'warehouseopen', 1, 0, 0, '', 0, 0, array(), 'minwidth200 maxwidth500 widthcentpercentminusxx');
2306 print ' <a href="'.DOL_URL_ROOT.'/product/stock/card.php?action=create&amp;backtopage='.urlencode($_SERVER['PHP_SELF'].'?action=edit&id='.((int) $object->id)).'">';
2307 print '<span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddWarehouse").'"></span></a>';
2308 print '</td></tr>';
2309
2310 /*
2311 print "<tr>".'<td>'.$langs->trans("StockLimit").'</td><td>';
2312 print '<input name="seuil_stock_alerte" size="4" value="'.$object->seuil_stock_alerte.'">';
2313 print '</td>';
2314
2315 print '<td>'.$langs->trans("DesiredStock").'</td><td>';
2316 print '<input name="desiredstock" size="4" value="'.$object->desiredstock.'">';
2317 print '</td></tr>';
2318 */
2319 }
2320
2321 if ($object->isService() && isModEnabled('workstation')) {
2322 // Default workstation
2323 print '<tr><td>'.$langs->trans("DefaultWorkstation").'</td><td>';
2324 print img_picto($langs->trans("DefaultWorkstation"), 'workstation', 'class="pictofixedwidth"');
2325 print $formproduct->selectWorkstations($object->fk_default_workstation, 'fk_default_workstation', 1);
2326 print '</td></tr>';
2327 }
2328
2329 /*
2330 else
2331 {
2332 print '<input name="seuil_stock_alerte" type="hidden" value="'.$object->seuil_stock_alerte.'">';
2333 print '<input name="desiredstock" type="hidden" value="'.$object->desiredstock.'">';
2334 }*/
2335
2336 if ($object->isService()) {
2337 // Duration
2338 print '<tr><td>'.$langs->trans("Duration").'</td><td>';
2339 print '<input name="duration_value" class="width50" value="'.($object->duration_value ? $object->duration_value : '').'"> ';
2340
2341 print $formproduct->selectMeasuringUnits("duration_unit", "time", ($object->duration_unit ? $object->duration_unit : 'h'), 0, 1);
2342
2343 // Mandatory period
2344 //if ($object->duration_value > 0) {
2345 print ' &nbsp; &nbsp; ';
2346 //}
2347 print '<input type="checkbox" class="valignmiddle" id="mandatoryperiod" name="mandatoryperiod"'.($object->mandatory_period == 1 ? ' checked="checked"' : '').'>';
2348 print '<label for="mandatoryperiod">';
2349 $htmltooltip = $langs->trans("mandatoryHelper");
2350 if (!getDolGlobalString('SERVICE_STRICT_MANDATORY_PERIOD')) {
2351 $htmltooltip .= '<br>'.$langs->trans("mandatoryHelper2");
2352 }
2353 print $form->textwithpicto($langs->trans("mandatoryperiod"), $htmltooltip, 1, 'info');
2354 print '</label>';
2355
2356 print '</td></tr>';
2357 } else {
2358 if (!getDolGlobalString('PRODUCT_DISABLE_NATURE')) {
2359 // Nature
2360 print '<tr><td>'.$form->textwithpicto($langs->trans("NatureOfProductShort"), $langs->trans("NatureOfProductDesc")).'</td><td>';
2361 print $formproduct->selectProductNature('finished', (GETPOSTISSET('finished') ? GETPOST('finished') : $object->finished));
2362 print '</td></tr>';
2363 }
2364 }
2365
2366 if (!$object->isService() && isModEnabled('bom')) {
2367 print '<tr><td>'.$form->textwithpicto($langs->trans("DefaultBOM"), $langs->trans("DefaultBOMDesc", $langs->transnoentitiesnoconv("Finished"))).'</td><td>';
2368 $bomkey = "Bom:bom/class/bom.class.php:0:(t.status:=:1) AND (t.fk_product:=:".((int) $object->id).')';
2369 print img_picto($langs->trans("DefaultBOM"), 'bom', 'class="pictofixedwidth"');
2370 print $form->selectForForms($bomkey, 'fk_default_bom', (GETPOSTISSET('fk_default_bom') ? GETPOST('fk_default_bom') : $object->fk_default_bom), 1);
2371 print '</td></tr>';
2372 }
2373
2374 if (!$object->isService()) {
2375 if (!getDolGlobalString('PRODUCT_DISABLE_WEIGHT')) {
2376 // Brut Weight
2377 print '<tr><td>'.$langs->trans("Weight").'</td><td>';
2378 print '<input name="weight" size="5" value="'.(GETPOSTISSET('weight') ? GETPOST('weight') : $object->weight).'"> ';
2379 print $formproduct->selectMeasuringUnits("weight_units", "weight", GETPOSTISSET('weight_units') ? GETPOST('weight_units') : (int) $object->weight_units, 0, 2);
2380 print '</td></tr>';
2381 }
2382
2383 if (!getDolGlobalString('PRODUCT_DISABLE_SIZE')) {
2384 // Brut Length
2385 print '<tr><td>'.$langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").'</td><td>';
2386 print '<input name="size" size="5" value="'.(GETPOSTISSET('size') ? GETPOST('size') : $object->length).'">x';
2387 print '<input name="sizewidth" size="5" value="'.(GETPOSTISSET('sizewidth') ? GETPOST('sizewidth') : $object->width).'">x';
2388 print '<input name="sizeheight" size="5" value="'.(GETPOSTISSET('sizeheight') ? GETPOST('sizeheight') : $object->height).'"> ';
2389 print $formproduct->selectMeasuringUnits("size_units", "size", GETPOSTISSET('size_units') ? GETPOST('size_units') : (int) $object->length_units, 0, 2);
2390 print '</td></tr>';
2391 }
2392 if (!getDolGlobalString('PRODUCT_DISABLE_SURFACE')) {
2393 // Brut Surface
2394 print '<tr><td>'.$langs->trans("Surface").'</td><td>';
2395 print '<input name="surface" size="5" value="'.(GETPOSTISSET('surface') ? GETPOST('surface') : $object->surface).'"> ';
2396 print $formproduct->selectMeasuringUnits("surface_units", "surface", GETPOSTISSET('surface_units') ? GETPOST('surface_units') : (int) $object->surface_units, 0, 2);
2397 print '</td></tr>';
2398 }
2399 if (!getDolGlobalString('PRODUCT_DISABLE_VOLUME')) {
2400 // Brut Volume
2401 print '<tr><td>'.$langs->trans("Volume").'</td><td>';
2402 print '<input name="volume" size="5" value="'.(GETPOSTISSET('volume') ? GETPOST('volume') : $object->volume).'"> ';
2403 print $formproduct->selectMeasuringUnits("volume_units", "volume", GETPOSTISSET('volume_units') ? GETPOST('volume_units') : (int) $object->volume_units, 0, 2);
2404 print '</td></tr>';
2405 }
2406
2407 if (getDolGlobalString('PRODUCT_ADD_NET_MEASURE')) {
2408 // Net Measure
2409 print '<tr><td>'.$langs->trans("NetMeasure").'</td><td>';
2410 print '<input name="net_measure" size="5" value="'.(GETPOSTISSET('net_measure') ? GETPOST('net_measure') : $object->net_measure).'"> ';
2411 print $formproduct->selectMeasuringUnits("net_measure_units", "", GETPOSTISSET('net_measure_units') ? GETPOST('net_measure_units') : (int) $object->net_measure_units, 0, 0);
2412 print '</td></tr>';
2413 }
2414 }
2415 // Units
2416 if (getDolGlobalString('PRODUCT_USE_UNITS')) {
2417 print '<tr><td>'.$langs->trans('DefaultUnitToShow').'</td>';
2418 print '<td>';
2419 print $form->selectUnits($object->fk_unit, 'units');
2420 print '</td></tr>';
2421 }
2422
2423 // Customs code
2424 if (!$object->isService() && !getDolGlobalString('PRODUCT_DISABLE_CUSTOMS_INFO')) {
2425 print '<tr><td class="wordbreak">'.$form->textwithpicto($langs->trans("CustomsCode"), $langs->trans("CustomsCodeHelp")).'</td><td><input name="customcode" class="maxwidth100onsmartphone" value="'.(GETPOSTISSET('customcode') ? GETPOST('customcode') : $object->customcode).'"></td></tr>';
2426 // Origin country
2427 print '<tr><td>'.$langs->trans("CountryOrigin").'</td>';
2428 print '<td>';
2429 print img_picto('', 'globe-americas', 'class="paddingrightonly"');
2430 print $form->select_country((string) (GETPOSTISSET('country_id') ? GETPOSTINT('country_id') : $object->country_id), 'country_id', '', 0, 'minwidth100 maxwidthonsmartphone');
2431 if ($user->admin) {
2432 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
2433 }
2434 print '</td></tr>';
2435
2436 // State
2437 if (!getDolGlobalString('PRODUCT_DISABLE_STATE')) {
2438 print '<tr>';
2439 if (getDolGlobalString('MAIN_SHOW_REGION_IN_STATE_SELECT') && (getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) {
2440 print '<td>'.$form->editfieldkey('RegionStateOrigin', 'state_id', '', $object, 0).'</td><td>';
2441 } else {
2442 print '<td>'.$form->editfieldkey('StateOrigin', 'state_id', '', $object, 0).'</td><td>';
2443 }
2444
2445 print img_picto('', 'state', 'class="pictofixedwidth"');
2446 print $formcompany->select_state(GETPOSTISSET('state_id') ? GETPOSTINT('state_id') : $object->state_id, $object->country_code);
2447 print '</td>';
2448 print '</tr>';
2449 }
2450 }
2451
2452 // Quality control
2453 if (getDolGlobalString('PRODUCT_LOT_ENABLE_QUALITY_CONTROL')) {
2454 print '<tr><td>'.$langs->trans("LifeTime").'</td><td><input name="lifetime" class="maxwidth100onsmartphone" value="'.$object->lifetime.'"></td></tr>';
2455 print '<tr><td>'.$langs->trans("QCFrequency").'</td><td><input name="qc_frequency" class="maxwidth100onsmartphone" value="'.$object->qc_frequency.'"></td></tr>';
2456 }
2457
2458 // Other attributes
2459 $parameters = array('colspan' => ' colspan="2"', 'cols' => 2);
2460 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2461 print $hookmanager->resPrint;
2462 if (empty($reshook)) {
2463 print $object->showOptionals($extrafields, 'edit', $parameters);
2464 }
2465
2466 // Tags-Categories
2467 if (isModEnabled('category')) {
2468 print '<tr><td>'.$langs->trans("Categories").'</td><td>';
2469 print $form->selectCategories(Categorie::TYPE_PRODUCT, 'categories', $object);
2470 print "</td></tr>";
2471 }
2472
2473 // Note private
2474 if (getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
2475 print '<tr><td class="tdtop">'.$langs->trans("NoteNotVisibleOnBill").'</td><td>';
2476
2477 $doleditor = new DolEditor('note_private', $object->note_private, '', 140, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_NOTE_PRIVATE'), ROWS_4, '90%');
2478 $doleditor->Create();
2479
2480 print "</td></tr>";
2481 }
2482
2483 print '</table>';
2484
2485 if (!getDolGlobalString('PRODUCT_DISABLE_ACCOUNTING')) {
2486 print '<hr>';
2487
2488 print '<table class="border centpercent">';
2489
2490 if (isModEnabled('accounting')) {
2492 // Accountancy_code_sell
2493 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
2494 print '<td>';
2495 print $formaccounting->select_account((GETPOSTISSET('accountancy_code_sell') ? GETPOST('accountancy_code_sell') : $object->accountancy_code_sell), 'accountancy_code_sell', 1, array(), 1, 1, 'minwidth150 maxwidth300');
2496 print '</td></tr>';
2497
2498 // Accountancy_code_sell_intra
2499 if ($mysoc->isInEEC()) {
2500 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellIntraCode").'</td>';
2501 print '<td>';
2502 print $formaccounting->select_account((GETPOSTISSET('accountancy_code_sell_intra') ? GETPOST('accountancy_code_sell_intra') : $object->accountancy_code_sell_intra), 'accountancy_code_sell_intra', 1, array(), 1, 1, 'minwidth150 maxwidth300');
2503 print '</td></tr>';
2504 }
2505
2506 // Accountancy_code_sell_export
2507 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellExportCode").'</td>';
2508 print '<td>';
2509 print $formaccounting->select_account((GETPOSTISSET('accountancy_code_sell_export') ? GETPOST('accountancy_code_sell_export') : $object->accountancy_code_sell_export), 'accountancy_code_sell_export', 1, array(), 1, 1, 'minwidth150 maxwidth300');
2510 print '</td></tr>';
2511
2512 // Accountancy_code_buy
2513 print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
2514 print '<td>';
2515 print $formaccounting->select_account((GETPOSTISSET('accountancy_code_buy') ? GETPOST('accountancy_code_buy') : $object->accountancy_code_buy), 'accountancy_code_buy', 1, array(), 1, 1, 'minwidth150 maxwidth300');
2516 print '</td></tr>';
2517
2518 // Accountancy_code_buy_intra
2519 if ($mysoc->isInEEC()) {
2520 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyIntraCode").'</td>';
2521 print '<td>';
2522 print $formaccounting->select_account((GETPOSTISSET('accountancy_code_buy_intra') ? GETPOST('accountancy_code_buy_intra') : $object->accountancy_code_buy_intra), 'accountancy_code_buy_intra', 1, array(), 1, 1, 'minwidth150 maxwidth300');
2523 print '</td></tr>';
2524 }
2525
2526 // Accountancy_code_buy_export
2527 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyExportCode").'</td>';
2528 print '<td>';
2529 print $formaccounting->select_account((GETPOSTISSET('accountancy_code_buy_export') ? GETPOST('accountancy_code_buy_export') : $object->accountancy_code_buy_export), 'accountancy_code_buy_export', 1, array(), 1, 1, 'minwidth150 maxwidth300');
2530 print '</td></tr>';
2531 } else {
2532 // For external software
2533 // Accountancy_code_sell
2534 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
2535 print '<td><input name="accountancy_code_sell" class="maxwidth200" value="'.(GETPOSTISSET('accountancy_code_sell') ? GETPOST('accountancy_code_sell') : $object->accountancy_code_sell).'">';
2536 print '</td></tr>';
2537
2538 // Accountancy_code_sell_intra
2539 if ($mysoc->isInEEC()) {
2540 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellIntraCode").'</td>';
2541 print '<td><input name="accountancy_code_sell_intra" class="maxwidth200" value="'.(GETPOSTISSET('accountancy_code_sell_intra') ? GETPOST('accountancy_code_sell_intra') : $object->accountancy_code_sell_intra).'">';
2542 print '</td></tr>';
2543 }
2544
2545 // Accountancy_code_sell_export
2546 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellExportCode").'</td>';
2547 print '<td><input name="accountancy_code_sell_export" class="maxwidth200" value="'.(GETPOSTISSET('accountancy_code_sell_export') ? GETPOST('accountancy_code_sell_export') : $object->accountancy_code_sell_export).'">';
2548 print '</td></tr>';
2549
2550 // Accountancy_code_buy
2551 print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
2552 print '<td><input name="accountancy_code_buy" class="maxwidth200" value="'.(GETPOSTISSET('accountancy_code_buy') ? GETPOST('accountancy_code_buy') : $object->accountancy_code_buy).'">';
2553 print '</td></tr>';
2554
2555 // Accountancy_code_buy_intra
2556 if ($mysoc->isInEEC()) {
2557 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyIntraCode").'</td>';
2558 print '<td><input name="accountancy_code_buy_intra" class="maxwidth200" value="'.(GETPOSTISSET('accountancy_code_buy_intra') ? GETPOST('accountancy_code_buy_intra') : $object->accountancy_code_buy_intra).'">';
2559 print '</td></tr>';
2560 }
2561
2562 // Accountancy_code_buy_export
2563 print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyExportCode").'</td>';
2564 print '<td><input name="accountancy_code_buy_export" class="maxwidth200" value="'.(GETPOSTISSET('accountancy_code_buy_export') ? GETPOST('accountancy_code_buy_export') : $object->accountancy_code_buy_export).'">';
2565 print '</td></tr>';
2566 }
2567
2568 print '</table>';
2569 }
2570 }
2571
2572 print '<script>';
2573 print '$(document).ready(function() {
2574 $("#stockable_product").change(function() {
2575 $(".showifstockable").toggle(this.checked);
2576 });
2577 });';
2578
2579 print '</script>';
2580
2581
2582 print dol_get_fiche_end();
2583
2584 print $form->buttonsSaveCancel();
2585
2586 print '</form>';
2587 } else {
2588 // Card in view mode
2589
2590 $showbarcode = isModEnabled('barcode');
2591 if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('barcode', 'lire_advance')) {
2592 $showbarcode = 0;
2593 }
2594
2596 $titre = $langs->trans("CardProduct".$object->type);
2597 $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
2598
2599 print dol_get_fiche_head($head, 'card', $titre, -1, $picto, 0, '', '', 0, '', 1);
2600
2601 $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1&type='.$object->type.'">'.$langs->trans("BackToList").'</a>';
2602 $object->next_prev_filter = "(te.fk_product_type:=:".((int) $object->type).")";
2603
2604 $shownav = 1;
2605 if ($user->socid && !in_array('product', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
2606 $shownav = 0;
2607 }
2608
2609 dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
2610
2611 // Call Hook tabContentViewProduct
2612 $parameters = array();
2613 // Note that $action and $object may be modified by hook
2614 $reshook = $hookmanager->executeHooks('tabContentViewProduct', $parameters, $object, $action);
2615 if (empty($reshook)) {
2616 print '<div class="fichecenter">';
2617 print '<div class="fichehalfleft">';
2618
2619 print '<div class="underbanner clearboth"></div>';
2620 print '<table class="border tableforfield centpercent">';
2621
2622 // Type
2623 if (isModEnabled("product") && isModEnabled("service")) {
2624 $typeformat = 'select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service");
2625 print '<tr><td class="titlefield">';
2626 print (!getDolGlobalString('PRODUCT_DENY_CHANGE_PRODUCT_TYPE')) ? $form->editfieldkey("Type", 'fk_product_type', (string) $object->type, $object, (int) $usercancreate, $typeformat) : $langs->trans('Type');
2627 print '</td><td>';
2628 print $form->editfieldval("Type", 'fk_product_type', $object->type, $object, $usercancreate, $typeformat);
2629 print '</td></tr>';
2630 }
2631
2632 if ($showbarcode) {
2633 // Barcode type
2634 print '<tr><td class="nowrap">';
2635 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
2636 print $langs->trans("BarcodeType");
2637 print '</td>';
2638 if (($action != 'editbarcodetype') && $usercancreate && $createbarcode) {
2639 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbarcodetype&id='.$object->id.'&token='.newToken().'">'.img_edit($langs->trans('Edit'), 1).'</a></td>';
2640 }
2641 print '</tr></table>';
2642 print '</td><td>';
2643 if ($action == 'editbarcodetype' || $action == 'editbarcode') {
2644 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
2645 $formbarcode = new FormBarCode($db);
2646 }
2647
2648 $fk_barcode_type = '';
2649 if ($action == 'editbarcodetype' && is_object($formbarcode)) {
2650 print $formbarcode->formBarcodeType($_SERVER['PHP_SELF'].'?id='.$object->id, $object->barcode_type, 'fk_barcode_type');
2651 $fk_barcode_type = $object->barcode_type;
2652 } else {
2653 $object->fetchBarCode();
2654 $fk_barcode_type = $object->barcode_type;
2655 print $object->barcode_type_label ? $object->barcode_type_label : ($object->barcode ? '<div class="warning">'.$langs->trans("SetDefaultBarcodeType").'<div>' : '');
2656 }
2657 print '</td></tr>'."\n";
2658
2659 // Barcode value
2660 print '<tr><td class="nowrap">';
2661 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
2662 print $langs->trans("BarcodeValue");
2663 print '</td>';
2664 if (($action != 'editbarcode') && $usercancreate && $createbarcode) {
2665 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbarcode&id='.$object->id.'&token='.newToken().'">'.img_edit($langs->trans('Edit'), 1).'</a></td>';
2666 }
2667 print '</tr></table>';
2668 print '</td><td class="wordbreak">';
2669 if ($action == 'editbarcode') {
2670 $tmpcode = GETPOSTISSET('barcode') ? GETPOST('barcode') : $object->barcode;
2671 if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) {
2672 $tmpcode = $modBarCodeProduct->getNextValue($object, (string) $fk_barcode_type);
2673 }
2674
2675 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
2676 print '<input type="hidden" name="token" value="'.newToken().'">';
2677 print '<input type="hidden" name="action" value="setbarcode">';
2678 print '<input type="hidden" name="barcode_type_code" value="'.$object->barcode_type_code.'">';
2679 print '<input class="width300" class="maxwidthonsmartphone" type="text" name="barcode" value="'.$tmpcode.'">';
2680 print '&nbsp;<input type="submit" class="button smallpaddingimp" value="'.$langs->trans("Modify").'">';
2681 print '</form>';
2682 } else {
2684 }
2685 print '</td></tr>'."\n";
2686 }
2687
2688 // Batch number management (to batch)
2689 if (isModEnabled('productbatch')) {
2690 if ($object->isProduct() || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
2691 print '<tr><td>'.$langs->trans("ManageLotSerial").'</td><td>';
2692 print $object->getLibStatut(0, 2);
2693 print '</td></tr>';
2694 if ((($object->status_batch == '1' && getDolGlobalString('PRODUCTBATCH_LOT_USE_PRODUCT_MASKS') && getDolGlobalString('PRODUCTBATCH_LOT_ADDON') == 'mod_lot_advanced')
2695 || ($object->status_batch == '2' && getDolGlobalString('PRODUCTBATCH_SN_ADDON') == 'mod_sn_advanced' && getDolGlobalString('PRODUCTBATCH_SN_USE_PRODUCT_MASKS')))) {
2696 print '<tr><td>'.$langs->trans("ManageLotMask").'</td><td>';
2697 print $object->batch_mask;
2698 print '</td></tr>';
2699 }
2700 }
2701
2702 print '<tr><td>'.$langs->trans('BatchSellOrEatByMandatoryList', $langs->transnoentities('SellByDate'), $langs->transnoentities('EatByDate')).'</td><td>';
2703 print $object->getSellOrEatByMandatoryLabel();
2704 print '</td></tr>';
2705 }
2706
2707 if (!getDolGlobalString('PRODUCT_DISABLE_ACCOUNTING')) {
2708 // Accountancy sell code
2709 print '<tr><td class="nowrap">';
2710 print $langs->trans("ProductAccountancySellCode");
2711 print '</td><td>';
2712 if (isModEnabled('accounting')) {
2713 if (!empty($object->accountancy_code_sell)) {
2714 $accountingaccount = new AccountingAccount($db);
2715 $accountingaccount->fetch(0, $object->accountancy_code_sell, 1);
2716
2717 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
2718 }
2719 } else {
2720 print $object->accountancy_code_sell;
2721 }
2722 print '</td></tr>';
2723
2724 // Accountancy sell code intra-community
2725 if ($mysoc->isInEEC()) {
2726 print '<tr><td class="nowrap">';
2727 print $langs->trans("ProductAccountancySellIntraCode");
2728 print '</td><td>';
2729 if (isModEnabled('accounting')) {
2730 if (!empty($object->accountancy_code_sell_intra)) {
2731 $accountingaccount2 = new AccountingAccount($db);
2732 $accountingaccount2->fetch(0, $object->accountancy_code_sell_intra, 1);
2733
2734 print $accountingaccount2->getNomUrl(0, 1, 1, '', 1);
2735 }
2736 } else {
2737 print $object->accountancy_code_sell_intra;
2738 }
2739 print '</td></tr>';
2740 }
2741
2742 // Accountancy sell code export
2743 print '<tr><td class="nowrap">';
2744 print $langs->trans("ProductAccountancySellExportCode");
2745 print '</td><td>';
2746 if (isModEnabled('accounting')) {
2747 if (!empty($object->accountancy_code_sell_export)) {
2748 $accountingaccount3 = new AccountingAccount($db);
2749 $accountingaccount3->fetch(0, $object->accountancy_code_sell_export, 1);
2750
2751 print $accountingaccount3->getNomUrl(0, 1, 1, '', 1);
2752 }
2753 } else {
2754 print $object->accountancy_code_sell_export;
2755 }
2756 print '</td></tr>';
2757
2758 // Accountancy buy code
2759 print '<tr><td class="nowrap">';
2760 print $langs->trans("ProductAccountancyBuyCode");
2761 print '</td><td>';
2762 if (isModEnabled('accounting')) {
2763 if (!empty($object->accountancy_code_buy)) {
2764 $accountingaccount4 = new AccountingAccount($db);
2765 $accountingaccount4->fetch(0, $object->accountancy_code_buy, 1);
2766
2767 print $accountingaccount4->getNomUrl(0, 1, 1, '', 1);
2768 }
2769 } else {
2770 print $object->accountancy_code_buy;
2771 }
2772 print '</td></tr>';
2773
2774 // Accountancy buy code intra-community
2775 if ($mysoc->isInEEC()) {
2776 print '<tr><td class="nowrap">';
2777 print $langs->trans("ProductAccountancyBuyIntraCode");
2778 print '</td><td>';
2779 if (isModEnabled('accounting')) {
2780 if (!empty($object->accountancy_code_buy_intra)) {
2781 $accountingaccount5 = new AccountingAccount($db);
2782 $accountingaccount5->fetch(0, $object->accountancy_code_buy_intra, 1);
2783
2784 print $accountingaccount5->getNomUrl(0, 1, 1, '', 1);
2785 }
2786 } else {
2787 print $object->accountancy_code_buy_intra;
2788 }
2789 print '</td></tr>';
2790 }
2791
2792 // Accountancy buy code export
2793 print '<tr><td class="nowrap">';
2794 print $langs->trans("ProductAccountancyBuyExportCode");
2795 print '</td><td>';
2796 if (isModEnabled('accounting')) {
2797 if (!empty($object->accountancy_code_buy_export)) {
2798 $accountingaccount6 = new AccountingAccount($db);
2799 $accountingaccount6->fetch(0, $object->accountancy_code_buy_export, 1);
2800
2801 print $accountingaccount6->getNomUrl(0, 1, 1, '', 1);
2802 }
2803 } else {
2804 print $object->accountancy_code_buy_export;
2805 }
2806 print '</td></tr>';
2807 }
2808
2809 // Description
2810 print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
2811 print '<td class="wordbreakimp wrapimp"><div class="longmessagecut">'.(dol_textishtml($object->description) ? $object->description : dol_nl2br($object->description, 1, true)).'</div></td></tr>';
2812
2813 // Public URL
2814 if (!getDolGlobalString('PRODUCT_DISABLE_PUBLIC_URL')) {
2815 print '<tr><td>'.$langs->trans("PublicUrl").'</td><td>';
2816 print dol_print_url($object->url, '_blank', 128);
2817 print '</td></tr>';
2818 }
2819
2820 // Stockable product / default warehouse
2821 if (($object->isProduct() || getDolGlobalInt('STOCK_SUPPORTS_SERVICES')) && isModEnabled('stock')) {
2822 print '<tr><td>' . $form->textwithpicto($langs->trans("StockableProduct"), $langs->trans('StockableProductDescription')) . '</td>';
2823 print '<td><input type="checkbox" readonly disabled '.($object->stockable_product == 1 ? 'checked' : '').'></td></tr>';
2824
2825 if ($object->isStockManaged()) {
2826 $warehouse = new Entrepot($db);
2827 $warehouse->fetch($object->fk_default_warehouse);
2828
2829 print '<tr><td>'.$langs->trans("DefaultWarehouse").'</td><td>';
2830 print(!empty($warehouse->id) ? $warehouse->getNomUrl(1) : '');
2831 print '</td>';
2832 }
2833 }
2834
2835 if ($object->isService() && isModEnabled('workstation')) {
2836 $workstation = new Workstation($db);
2837 $res = $workstation->fetch($object->fk_default_workstation);
2838
2839 print '<tr><td>'.$langs->trans("DefaultWorkstation").'</td><td>';
2840 print(!empty($workstation->id) ? $workstation->getNomUrl(1) : '');
2841 print '</td>';
2842 }
2843
2844 // Parent product.
2845 if (isModEnabled('variants') && ($object->isProduct() || $object->isService())) {
2846 $combination = new ProductCombination($db);
2847
2848 if ($combination->fetchByFkProductChild($object->id) > 0) {
2849 $prodstatic = new Product($db);
2850 $prodstatic->fetch($combination->fk_product_parent);
2851
2852 // Parent product
2853 print '<tr><td>'.$langs->trans("ParentProduct").'</td><td>';
2854 print $prodstatic->getNomUrl(1);
2855 print '</td></tr>';
2856 }
2857 }
2858
2859 print '</table>';
2860
2861 print '</div>';
2862 print '<div class="fichehalfright">';
2863 print '<div class="underbanner clearboth"></div>';
2864
2865 print '<table class="border tableforfield centpercent">';
2866
2867 if ($object->isService()) {
2868 // Duration
2869 require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
2870 $measuringUnits = new CUnits($db);
2871 $durations = [];
2872 $plural = '';
2873 if ($object->duration_value > 1) {
2874 $plural = 's';
2875 }
2876 $result = $measuringUnits->fetchAll('', 'scale', 0, 0, ['t.active' => 1, 't.unit_type' => 'time']);
2877 if ($result !== -1) {
2878 foreach ($measuringUnits->records as $record) {
2879 $durations[$record->short_label] = dol_ucfirst($record->label) . $plural;
2880 }
2881 }
2882 print '<tr><td class="titlefieldmiddle">'.$langs->trans("Duration").'</td><td>';
2883 if ($object->duration_value) {
2884 print $object->duration_value;
2885 print(!empty($object->duration_unit) && isset($durations[$object->duration_unit]) ? "&nbsp; ".$langs->trans($durations[$object->duration_unit])."&nbsp;" : '');
2886 }
2887
2888 // Mandatory period
2889 $htmltooltip = $langs->trans("mandatoryHelper");
2890 if (!getDolGlobalString('SERVICE_STRICT_MANDATORY_PERIOD')) {
2891 $htmltooltip .= '<br>'.$langs->trans("mandatoryHelper2");
2892 }
2893 if ($object->duration_value > 0) {
2894 print ' &nbsp; &nbsp; ';
2895 }
2896 print '<input type="checkbox" class="valignmiddle" name="mandatoryperiod"'.($object->mandatory_period == 1 ? ' checked="checked"' : '').' disabled>';
2897 print $form->textwithpicto($langs->trans("mandatoryperiod"), $htmltooltip, 1, 'info');
2898
2899 print '</td></tr>';
2900 } else {
2901 if (!getDolGlobalString('PRODUCT_DISABLE_NATURE')) {
2902 // Nature
2903 print '<tr><td class="titlefieldmiddle">'.$form->textwithpicto($langs->trans("NatureOfProductShort"), $langs->trans("NatureOfProductDesc")).'</td><td>';
2904 print $object->getLibFinished();
2905 print '</td></tr>';
2906 }
2907 }
2908
2909 if (!$object->isService() && isModEnabled('bom') && $object->finished) {
2910 print '<tr><td class="titlefieldmiddle">'.$form->textwithpicto($langs->trans("DefaultBOM"), $langs->trans("DefaultBOMDesc", $langs->transnoentitiesnoconv("Finished"))).'</td><td>';
2911 if ($object->fk_default_bom) {
2912 $bom_static = new BOM($db);
2913 $bom_static->fetch($object->fk_default_bom);
2914 print $bom_static->getNomUrl(1);
2915 }
2916 print '</td></tr>';
2917 }
2918
2919 if (!$object->isService()) {
2920 // Brut Weight
2921 if (!getDolGlobalString('PRODUCT_DISABLE_WEIGHT')) {
2922 print '<tr><td class="titlefieldmiddle">'.$langs->trans("Weight").'</td><td>';
2923 if ($object->weight != '') {
2924 print $object->weight." ".measuringUnitString(0, "weight", $object->weight_units);
2925 } else {
2926 print '&nbsp;';
2927 }
2928 print "</td></tr>\n";
2929 }
2930
2931 if (!getDolGlobalString('PRODUCT_DISABLE_SIZE')) {
2932 // Brut Length
2933 print '<tr><td>'.$langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").'</td><td>';
2934 if ($object->length != '' || $object->width != '' || $object->height != '') {
2935 print $object->length;
2936 if ($object->width) {
2937 print " x ".$object->width;
2938 }
2939 if ($object->height) {
2940 print " x ".$object->height;
2941 }
2942 print ' '.measuringUnitString(0, "size", $object->length_units);
2943 } else {
2944 print '&nbsp;';
2945 }
2946 print "</td></tr>\n";
2947 }
2948 if (!getDolGlobalString('PRODUCT_DISABLE_SURFACE') || !getDolGlobalString('PRODUCT_DISABLE_VOLUME')) {
2949 // Brut Surface / Volume
2950 print '<tr><td>';
2951 print (getDolGlobalString('PRODUCT_DISABLE_SURFACE') ? '' : $langs->trans("Surface"));
2952 print (!getDolGlobalString('PRODUCT_DISABLE_SURFACE') && !getDolGlobalString('PRODUCT_DISABLE_VOLUME')) ? ' / ' : '';
2953 print (getDolGlobalString('PRODUCT_DISABLE_VOLUME') ? '' : $langs->trans("Volume")).'</td><td>';
2954 if (!getDolGlobalString('PRODUCT_DISABLE_SURFACE') && $object->surface != '') {
2955 print $object->surface." ".measuringUnitString(0, "surface", $object->surface_units);
2956 }
2957 print (!getDolGlobalString('PRODUCT_DISABLE_SURFACE') && !getDolGlobalString('PRODUCT_DISABLE_VOLUME') && $object->surface && $object->volume) ? ' / ' : '';
2958 if (!getDolGlobalString('PRODUCT_DISABLE_VOLUME') && $object->volume != '') {
2959 print $object->volume." ".measuringUnitString(0, "volume", $object->volume_units);
2960 }
2961 print "</td></tr>\n";
2962 }
2963
2964 if (getDolGlobalString('PRODUCT_ADD_NET_MEASURE')) {
2965 // Net Measure
2966 print '<tr><td class="titlefieldmiddle">'.$langs->trans("NetMeasure").'</td><td>';
2967 if ($object->net_measure != '') {
2968 print $object->net_measure." ".measuringUnitString((int) $object->net_measure_units);
2969 } else {
2970 print '&nbsp;';
2971 }
2972 print '</td></tr>';
2973 }
2974 }
2975
2976 // Unit
2977 if (getDolGlobalString('PRODUCT_USE_UNITS')) {
2978 $unit = $object->getLabelOfUnit('long', $langs);
2979
2980 print '<tr><td>'.$langs->trans('DefaultUnitToShow').'</td><td>';
2981 print $unit;
2982 print '</td></tr>';
2983 }
2984
2985 // Custom code
2986 if (!$object->isService() && !getDolGlobalString('PRODUCT_DISABLE_CUSTOMS_INFO')) {
2987 print '<tr><td>'.$form->textwithpicto($langs->trans("CustomsCode"), $langs->trans("CustomsCodeHelp")).'</td><td>'.dolPrintHTML($object->customcode).'</td></tr>';
2988
2989 // Origin country code
2990 print '<tr><td>'.$langs->trans("Origin").'</td><td>'.getCountry($object->country_id, '', $db);
2991 if (!empty($object->state_id)) {
2992 print ' - '.getState($object->state_id, '0', $db);
2993 }
2994 print '</td></tr>';
2995 }
2996
2997 // Quality Control
2998 if (getDolGlobalString('PRODUCT_LOT_ENABLE_QUALITY_CONTROL')) {
2999 print '<tr><td>'.$langs->trans("LifeTime").'</td><td>'.$object->lifetime.'</td></tr>';
3000 print '<tr><td>'.$langs->trans("QCFrequency").'</td><td>'.$object->qc_frequency.'</td></tr>';
3001 }
3002
3003 // Other attributes
3004 $parameters = array();
3005 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
3006
3007 // Categories
3008 if (isModEnabled('category')) {
3009 print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
3010 print $form->showCategories($object->id, Categorie::TYPE_PRODUCT, 1);
3011 print "</td></tr>";
3012 }
3013
3014 // Note private
3015 if (getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
3016 print '<!-- show Note --> '."\n";
3017 print '<tr><td class="tdtop">'.$langs->trans("NotePrivate").'</td><td>'.(dol_textishtml($object->note_private) ? $object->note_private : dol_nl2br($object->note_private, 1, true)).'</td></tr>'."\n";
3018 print '<!-- End show Note --> '."\n";
3019 }
3020
3021 print "</table>\n";
3022 print '</div>';
3023
3024 print '</div>';
3025 print '<div class="clearboth"></div>';
3026 }
3027
3028 print dol_get_fiche_end();
3029 }
3030 } elseif ($action != 'create') {
3031 exit;
3032 }
3033}
3034
3035$tmpcode = '';
3036if (!empty($modCodeProduct->code_auto)) {
3037 $tmpcode = $modCodeProduct->getNextValue($object, $object->type);
3038}
3039
3040$formconfirm = '';
3041
3042// Confirm delete product
3043if (($action == 'delete' && (empty($conf->use_javascript_ajax) || !empty($conf->dol_use_jmobile))) // Output when action = clone if jmobile or no js
3044 || (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) { // Always output when not jmobile nor js
3045 $formconfirm = $form->formconfirm("card.php?id=".$object->id, $langs->trans("DeleteProduct"), $langs->trans("ConfirmDeleteProduct"), "confirm_delete", '', 0, "action-delete");
3046}
3047if ($action == 'merge') {
3048 $formquestion = array(
3049 array(
3050 'name' => 'product_origin',
3051 'label' => $langs->trans('MergeOriginProduct'),
3052 'type' => 'other',
3053 'value' => $form->select_produits(0, 'product_origin', '', 0, 0, 1, 2, '', 1, array(), 0, 1, 0, 'minwidth200', 0, '', null, 1),
3054 )
3055 );
3056 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("MergeProducts"), $langs->trans("ConfirmMergeProducts"), "confirm_merge", $formquestion, 'no', 1, 250);
3057}
3058
3059// Clone confirmation
3060if (($action == 'clone' && (empty($conf->use_javascript_ajax) || !empty($conf->dol_use_jmobile))) // Output when action = clone if jmobile or no js
3061 || (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) { // Always output when not jmobile nor js
3062 // Define confirmation messages
3063 $formquestionclone = array(
3064 'text' => $langs->trans("ConfirmClone"),
3065 0 => array('type' => 'text', 'name' => 'clone_ref', 'label' => $langs->trans("NewRefForClone"), 'value' => empty($tmpcode) ? $langs->trans("CopyOf").' '.$object->ref : $tmpcode, 'morecss' => 'width150'),
3066 1 => array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneContentProduct"), 'value' => 1),
3067 2 => array('type' => 'checkbox', 'name' => 'clone_categories', 'label' => $langs->trans("CloneCategoriesProduct"), 'value' => 1),
3068 );
3069 if (getDolGlobalString('PRODUIT_MULTIPRICES')) {
3070 $formquestionclone[] = array('type' => 'checkbox', 'name' => 'clone_prices', 'label' => $langs->trans("ClonePricesProduct").' ('.$langs->trans("CustomerPrices").')', 'value' => 0);
3071 }
3072 if (getDolGlobalString('PRODUIT_SOUSPRODUITS')) {
3073 $formquestionclone[] = array('type' => 'checkbox', 'name' => 'clone_composition', 'label' => $langs->trans('CloneCompositionProduct'), 'value' => 1);
3074 }
3075 if (isModEnabled('bom') && $user->hasRight('bom', 'write')) {
3076 if ($object->fk_default_bom > 0) {
3077 $formquestionclone[] = array('type' => 'checkbox', 'name' => 'clone_defbom', 'label' => $langs->trans("CloneDefBomProduct"), 'value' => getDolGlobalInt('BOM_CLONE_DEFBOM'));
3078 }
3079 $bomstatic = new BOM($db);
3080 $bomlist = $bomstatic->fetchAll("", "", 0, 0, 'fk_product:=:'.(int) $object->id);
3081 if (is_array($bomlist) && count($bomlist) > 0) {
3082 $formquestionclone[] = array('type' => 'checkbox', 'name' => 'clone_otherboms', 'label' => $langs->trans("CloneOtherBomsProduct"), 'value' => 0);
3083 }
3084 }
3085 $formconfirm .= $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneProduct', $object->ref), 'confirm_clone', $formquestionclone, 'yes', 'action-clone', 350, 600);
3086}
3087
3088// Call Hook formConfirm
3089$parameters = array('formConfirm' => $formconfirm, 'object' => $object);
3090$reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3091if (empty($reshook)) {
3092 $formconfirm .= $hookmanager->resPrint;
3093} elseif ($reshook > 0) {
3094 $formconfirm = $hookmanager->resPrint;
3095}
3096
3097// Print form confirm
3098print $formconfirm;
3099
3100/*
3101 * Action bar
3102 */
3103if ($action != 'create' && $action != 'edit') {
3104 $cloneProductUrl = $_SERVER["PHP_SELF"].'?action=clone&token='.newToken();
3105 $cloneButtonId = 'action-clone-no-ajax';
3106
3107 print "\n".'<div class="tabsAction">'."\n";
3108
3109 $parameters = array();
3110 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3111 if (empty($reshook)) {
3112 if ($usercancreate) {
3113 if (!isset($hookmanager->resArray['no_button_edit']) || $hookmanager->resArray['no_button_edit'] != 1) {
3114 print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$object->id, '', $usercancreate);
3115 }
3116
3117 //Send
3118 print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=presend&mode=init&token=' . newToken() . '#formmailbeforetitle');
3119
3120 if (!isset($hookmanager->resArray['no_button_copy']) || $hookmanager->resArray['no_button_copy'] != 1) {
3121 if (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile)) {
3122 $cloneProductUrl = '';
3123 $cloneButtonId = 'action-clone';
3124 }
3125 print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $cloneProductUrl, $cloneButtonId, $usercancreate);
3126 }
3127 }
3128 $object_is_used = $object->isObjectUsed($object->id);
3129
3130 if ($usercandelete) {
3131 if (empty($object_is_used)) {
3132 if (!isset($hookmanager->resArray['no_button_delete']) || $hookmanager->resArray['no_button_delete'] != 1) {
3133 if (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile)) {
3134 print dolGetButtonAction($langs->trans('Delete'), '', 'delete', '#', 'action-delete', true);
3135 } else {
3136 print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, '');
3137 }
3138 }
3139 } else {
3140 print dolGetButtonAction($langs->trans("ProductIsUsed"), $langs->trans('Delete'), 'delete', '#', '', false);
3141 }
3142 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') > 1) {
3143 print '<a class="butActionDelete" href="card.php?action=merge&id='.$object->id.'" title="'.dol_escape_htmltag($langs->trans("MergeProducts")).'">'.$langs->trans('Merge').'</a>'."\n";
3144 }
3145 } else {
3146 print dolGetButtonAction($langs->trans("NotEnoughPermissions"), $langs->trans('Delete'), 'delete', '#', '', false);
3147 }
3148 }
3149
3150 print "\n</div>\n";
3151}
3152
3153
3154/*
3155 * All the "Add to" areas if PRODUCT_ADD_FORM_ADD_TO is set
3156 */
3157
3158if (getDolGlobalString('PRODUCT_ADD_FORM_ADD_TO') && $object->id && ($action == '' || $action == 'view') && $object->status) {
3159 //Variable used to check if any text is going to be printed
3160 $html = '';
3161 //print '<div class="fichecenter"><div class="fichehalfleft">';
3162
3163 // Propals
3164 if (isModEnabled("propal") && $user->hasRight('propal', 'creer')) {
3165 $propal = new Propal($db);
3166
3167 $langs->load("propal");
3168
3169 $otherprop = $propal->liste_array(2, 1, 0);
3170
3171 if (is_array($otherprop) && count($otherprop)) {
3172 $html .= '<tr><td style="width: 200px;">';
3173 $html .= $langs->trans("AddToDraftProposals").'</td><td>';
3174 $html .= $form->selectarray("propalid", $otherprop, 0, 1);
3175 $html .= '</td></tr>';
3176 } else {
3177 $html .= '<tr><td style="width: 200px;">';
3178 $html .= $langs->trans("AddToDraftProposals").'</td><td>';
3179 $html .= $langs->trans("NoDraftProposals");
3180 $html .= '</td></tr>';
3181 }
3182 }
3183
3184 // Commande
3185 if (isModEnabled('order') && $user->hasRight('commande', 'creer')) {
3186 $commande = new Commande($db);
3187
3188 $langs->load("orders");
3189
3190 $othercom = $commande->liste_array(2, 1, null);
3191 if (is_array($othercom) && count($othercom)) {
3192 $html .= '<tr><td style="width: 200px;">';
3193 $html .= $langs->trans("AddToDraftOrders").'</td><td>';
3194 $html .= $form->selectarray("commandeid", $othercom, 0, 1);
3195 $html .= '</td></tr>';
3196 } else {
3197 $html .= '<tr><td style="width: 200px;">';
3198 $html .= $langs->trans("AddToDraftOrders").'</td><td>';
3199 $html .= $langs->trans("NoDraftOrders");
3200 $html .= '</td></tr>';
3201 }
3202 }
3203
3204 // Factures
3205 if (isModEnabled('invoice') && $user->hasRight('facture', 'creer')) {
3206 $invoice = new Facture($db);
3207
3208 $langs->load("bills");
3209
3210 $otherinvoice = $invoice->liste_array(2, 1, null);
3211 if (is_array($otherinvoice) && count($otherinvoice)) {
3212 $html .= '<tr><td style="width: 200px;">';
3213 $html .= $langs->trans("AddToDraftInvoices").'</td><td>';
3214 $html .= $form->selectarray("factureid", $otherinvoice, 0, 1);
3215 $html .= '</td></tr>';
3216 } else {
3217 $html .= '<tr><td style="width: 200px;">';
3218 $html .= $langs->trans("AddToDraftInvoices").'</td><td>';
3219 $html .= $langs->trans("NoDraftInvoices");
3220 $html .= '</td></tr>';
3221 }
3222 }
3223
3224 // If any text is going to be printed, then we show the table
3225 if (!empty($html)) {
3226 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
3227 print '<input type="hidden" name="token" value="'.newToken().'">';
3228 print '<input type="hidden" name="action" value="addin">';
3229
3230 print load_fiche_titre($langs->trans("AddToDraft"), '', '');
3231
3232 print dol_get_fiche_head();
3233
3234 $html .= '<tr><td class="nowrap">'.$langs->trans("Quantity").' ';
3235 $html .= '<input type="text" class="flat" name="qty" size="1" value="1"></td>';
3236 $html .= '<td class="nowrap">'.$langs->trans("ReductionShort").'(%) ';
3237 $html .= '<input type="text" class="flat" name="remise_percent" size="1" value="0">';
3238 $html .= '</td></tr>';
3239
3240 print '<table class="centpercent border">';
3241 print $html;
3242 print '</table>';
3243
3244 print '<div class="center">';
3245 print '<input type="submit" class="button button-add" value="'.$langs->trans("Add").'">';
3246 print '</div>';
3247
3248 print dol_get_fiche_end();
3249
3250 print '</form>';
3251 }
3252}
3253
3254
3255/*
3256 * Generated documents
3257 */
3258
3259if (GETPOST('modelselected')) {
3260 $action = 'presend';
3261}
3262
3263if ($action != 'create' && $action != 'edit' && $action != 'delete') {
3264 print '<div class="fichecenter"><div class="fichehalfleft">';
3265 print '<a name="builddoc"></a>'; // ancre
3266
3267 // Documents
3268 $objectref = dol_sanitizeFileName($object->ref);
3269 if (!empty($conf->product->multidir_output[$object->entity])) {
3270 $filedir = $conf->product->multidir_output[$object->entity].'/'.$objectref; //Check repertories of current entities
3271 } else {
3272 $filedir = $conf->product->dir_output.'/'.$objectref;
3273 }
3274 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
3275 $genallowed = $usercanread;
3276 $delallowed = $usercancreate;
3277
3278 print $formfile->showdocuments($modulepart, $object->ref, $filedir, $urlsource, (int) $genallowed, (int) $delallowed, '', 0, 0, 0, 28, 0, '', '', '', $langs->getDefaultLang(), '', $object);
3279 $somethingshown = $formfile->numoffiles;
3280
3281 print '</div><div class="fichehalfright">';
3282
3283 $MAXEVENT = 10;
3284 $morehtmlcenter = '<div class="nowraponall">';
3285 $morehtmlcenter .= dolGetButtonTitle($langs->trans('FullConversation'), '', 'fa fa-comments imgforviewmode', DOL_URL_ROOT.'/product/messaging.php?id='.$object->id);
3286 $morehtmlcenter .= dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/product/agenda.php?id='.$object->id);
3287 $morehtmlcenter .= '</div>';
3288
3289 // List of actions on element
3290 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
3291 $formactions = new FormActions($db);
3292 $somethingshown = $formactions->showactions($object, 'product', 0, 1, '', $MAXEVENT, '', $morehtmlcenter); // Show all action for product
3293
3294 print '</div></div>';
3295
3296 // Presend form
3297 $modelmail = 'product_send';
3298 $defaulttopic = $object->label;
3299 $diroutput = $conf->product->multidir_output[$object->entity];
3300 $trackid = 'prod' . $object->id;
3301
3302 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
3303}
3304
3305// End of page
3306llxFooter();
3307$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:475
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
$object ref
Definition info.php:90
Class to manage accounting accounts.
Class for BOM.
Definition bom.class.php:42
Class of dictionary type of thirdparty (used by imports)
Class to manage canvas.
Class to manage categories.
Class to manage customers orders.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage standard extra fields.
Class to manage invoices.
const TYPE_STANDARD
Standard invoice.
Class to manage generation of HTML components for accounting management.
Class to manage building of HTML components.
Class to manage barcode HTML.
Class to build HTML component for third parties management Only common components are here.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class with static methods for building HTML components related to products Only components common to ...
Class of a generic business object.
Class ProductCombination Used to represent the relation between a product and one of its variants.
File of class to manage predefined price products or services by customer.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
static getSellOrEatByMandatoryList()
Get the array of labels of Sell by or Eat by all mandatory flags for each status.
const TYPE_SERVICE
Service.
Class to manage proposals.
Class to manage third parties objects (customers, suppliers, prospects...)
Class for Workstation.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
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_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array(), $entity=0)
Move a file into another name.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
dol_is_dir($folder)
Test if filename is a directory.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_ucfirst($string, $encoding="UTF-8")
Convert first character of the first word of a string to upper.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dolPrintHTML($s, $allowiframe=0)
Return a string (that can be on several lines) ready to be output on a HTML page.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='')
Show Url link.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dol_textishtml($msg, $option=0)
Return if a text is a html content.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='')
Return the value of a $_GET or $_POST supervariable, converted into float.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
measuringUnitString($unitid, $measuring_style='', $unitscale=null, $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
product_prepare_head($object)
Prepare array with list of tabs.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.