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