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