dolibarr 22.0.5
mo_production.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2019-2020 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2023 Christian Humpel <christian.humpel@gmail.com>
4 * Copyright (C) 2023 Vincent de Grandpré <vincent@de-grandpre.quebec>
5 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
8 * Copyright (C) 2025 Noé Cendrier <noe.cendrier@altairis.fr>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require '../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
36require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
37require_once DOL_DOCUMENT_ROOT.'/mrp/lib/mrp_mo.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
39require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
40require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
41require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
42require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
43require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
44require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php';
45
46
55// Load translation files required by the page
56$langs->loadLangs(array("mrp", "stocks", "other", "product", "productbatch"));
57
58// Get parameters
59$id = GETPOSTINT('id');
60$ref = GETPOST('ref', 'alpha');
61$action = GETPOST('action', 'aZ09');
62$confirm = GETPOST('confirm', 'alpha');
63$cancel = GETPOST('cancel');
64$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'mocard'; // To manage different context of search
65$backtopage = GETPOST('backtopage', 'alpha');
66$lineid = GETPOSTINT('lineid');
67$fk_movement = GETPOSTINT('fk_movement');
68$fk_default_warehouse = GETPOSTINT('fk_default_warehouse');
69
70$collapse = GETPOST('collapse', 'aZ09comma');
71
72// Initialize a technical objects
73$object = new Mo($db);
74$extrafields = new ExtraFields($db);
75$diroutputmassaction = $conf->mrp->dir_output.'/temp/massgeneration/'.$user->id;
76$objectline = new MoLine($db);
77
78$hookmanager->initHooks(array('moproduction', 'globalcard')); // Note that conf->hooks_modules contains array
79
80// Fetch optionals attributes and labels
81$extrafields->fetch_name_optionals_label($object->table_element);
82
83$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
84
85// Initialize array of search criteria
86$search_all = GETPOST("search_all", 'alpha');
87$search = array();
88foreach ($object->fields as $key => $val) {
89 if (GETPOST('search_'.$key, 'alpha')) {
90 $search[$key] = GETPOST('search_'.$key, 'alpha');
91 }
92}
93
94if (empty($action) && empty($id) && empty($ref)) {
95 $action = 'view';
96}
97
98// Load object
99include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'.
100
101// Security check - Protection if external user
102//if ($user->socid > 0) accessforbidden();
103//if ($user->socid > 0) $socid = $user->socid;
104$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
105$result = restrictedArea($user, 'mrp', $object->id, 'mrp_mo', '', 'fk_soc', 'rowid', $isdraft);
106
107// Permissions
108$permissionnote = $user->hasRight('mrp', 'write'); // Used by the include of actions_setnotes.inc.php
109$permissiondellink = $user->hasRight('mrp', 'write'); // Used by the include of actions_dellink.inc.php
110$permissiontoadd = $user->hasRight('mrp', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
111$permissiontodelete = $user->hasRight('mrp', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
112
113$permissiontoproduce = $permissiontoadd;
114$permissiontoupdatecost = $user->hasRight('bom', 'read'); // User who can define cost must have knowledge of pricing
115
116$upload_dir = $conf->mrp->multidir_output[isset($object->entity) ? $object->entity : 1];
117
118
119/*
120 * Actions
121 */
122
123$parameters = array();
124$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
125if ($reshook < 0) {
126 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
127}
128
129if (empty($reshook)) {
130 $error = 0;
131
132 $backurlforlist = DOL_URL_ROOT.'/mrp/mo_list.php';
133
134 if (empty($backtopage) || ($cancel && empty($id))) {
135 //var_dump($backurlforlist);exit;
136 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
137 $backtopage = $backurlforlist;
138 } else {
139 $backtopage = DOL_URL_ROOT.'/mrp/mo_production.php?id='.($id > 0 ? $id : '__ID__');
140 }
141 }
142 $triggermodname = 'MO_MODIFY'; // Name of trigger action code to execute when we modify record
143
144 if ($action == 'confirm_cancel' && $confirm == 'yes' && !empty($permissiontoadd)) {
145 $also_cancel_consumed_and_produced_lines = (GETPOST('alsoCancelConsumedAndProducedLines', 'alpha') ? 1 : 0);
146 $result = $object->cancel($user, 0, (bool) $also_cancel_consumed_and_produced_lines);
147 if ($result > 0) {
148 header("Location: " . DOL_URL_ROOT.'/mrp/mo_card.php?id=' . $object->id);
149 exit;
150 } else {
151 $action = '';
152 setEventMessages($object->error, $object->errors, 'errors');
153 }
154 } elseif ($action == 'confirm_delete' && $confirm == 'yes' && !empty($permissiontodelete)) {
155 $also_cancel_consumed_and_produced_lines = (GETPOST('alsoCancelConsumedAndProducedLines', 'alpha') ? 1 : 0);
156 $result = $object->delete($user, 0, (bool) $also_cancel_consumed_and_produced_lines);
157 if ($result > 0) {
158 header("Location: " . $backurlforlist);
159 exit;
160 } else {
161 $action = '';
162 setEventMessages($object->error, $object->errors, 'errors');
163 }
164 }
165
166 // Actions cancel, add, update, delete or clone
167 include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
168
169 // Actions when linking object each other
170 include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
171
172 // Actions when printing a doc from card
173 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
174
175 // Actions to send emails
176 $triggersendname = 'MO_SENTBYMAIL';
177 $autocopy = 'MAIN_MAIL_AUTOCOPY_MO_TO';
178 $trackid = 'mo'.$object->id;
179 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
180
181 // Action to move up and down lines of object
182 //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be 'include', not 'include_once'
183
184 if ($action == 'set_thirdparty' && $permissiontoadd) {
185 $object->setValueFrom('fk_soc', GETPOSTINT('fk_soc'), '', null, 'date', '', $user, $triggermodname);
186 }
187 if ($action == 'classin' && $permissiontoadd) {
188 $object->setProject(GETPOSTINT('projectid'));
189 }
190
191 if ($action == 'confirm_reopen' && $permissiontoadd && $object->status == $object::STATUS_PRODUCED) { // The reopen of a canceled MO is done by $object->reopen() (with confirm=yes)
192 $result = $object->setStatut($object::STATUS_INPROGRESS, 0, '', 'MRP_REOPEN');
193 }
194
195 if (($action == 'confirm_addconsumeline' && GETPOST('addconsumelinebutton') && $permissiontoadd)
196 || ($action == 'confirm_addproduceline' && GETPOST('addproducelinebutton') && $permissiontoadd)) {
197 $moline = new MoLine($db);
198
199 // Line to produce
200 $moline->fk_mo = $object->id;
201 $moline->qty = GETPOSTFLOAT('qtytoadd');
202 $moline->fk_product = GETPOSTINT('productidtoadd');
203 if (GETPOST('addconsumelinebutton')) {
204 $moline->role = 'toconsume';
205 } else {
206 $moline->role = 'toproduce';
207 }
208 $moline->origin_type = 'free'; // free consume line
209 $moline->position = 0;
210
211 // Is it a product or a service ?
212 if (!empty($moline->fk_product)) {
213 $tmpproduct = new Product($db);
214 $tmpproduct->fetch($moline->fk_product);
215 if ($tmpproduct->type == Product::TYPE_SERVICE) {
216 $moline->fk_default_workstation = $tmpproduct->fk_default_workstation;
217 $moline->disable_stock_change = 1;
218 if ($tmpproduct->duration_unit) {
219 $moline->qty = $tmpproduct->duration_value;
220 include_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
221 $cunits = new CUnits($db);
222 $res = $cunits->fetch(0, '', $tmpproduct->duration_unit, 'time');
223 if ($res > 0) {
224 $moline->fk_unit = $cunits->id;
225 }
226 }
227 } else {
228 $moline->disable_stock_change = 0;
229 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
230 $moline->fk_unit = $tmpproduct->fk_unit;
231 }
232 }
233 }
234 // Extrafields
235 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
236 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
237 // Unset extrafield
238 if (is_array($extralabelsline)) {
239 // Get extra fields
240 foreach ($extralabelsline as $key => $value) {
241 unset($_POST["options_".$key]);
242 }
243 }
244 if (is_array($array_options) && count($array_options) > 0) {
245 $moline->array_options = $array_options;
246 }
247
248 $resultline = $moline->create($user, 0); // Never use triggers here
249 if ($resultline <= 0) {
250 $error++;
251 setEventMessages($moline->error, $moline->errors, 'errors');
252 }
253
254 $action = '';
255 // Redirect to refresh the tab information
256 header("Location: ".$_SERVER["PHP_SELF"].'?id='.$object->id);
257 exit;
258 }
259
260 // Consumption and production are possible only on a validated or in progress MO
261 if (in_array($action, array('confirm_consumeorproduce', 'confirm_consumeandproduceall')) && $object->status != $object::STATUS_VALIDATED && $object->status != $object::STATUS_INPROGRESS) {
262 $langs->load("errors");
263 setEventMessages($langs->trans("ErrorObjectHasWrongStatus", $object->ref), null, 'errors');
264 $action = '';
265 }
266
267 if (in_array($action, array('confirm_consumeorproduce', 'confirm_consumeandproduceall')) && $permissiontoproduce) {
268 $stockmove = new MouvementStock($db);
269
270 $labelmovement = GETPOST('inventorylabel', 'alphanohtml');
271 $codemovement = GETPOST('inventorycode', 'alphanohtml');
272
273 $db->begin();
274 $pos = 0;
275 // Process line to consume
276 foreach ($object->lines as $line) {
277 if ($line->role == 'toconsume') {
278 $tmpproduct = new Product($db);
279 $tmpproduct->fetch($line->fk_product);
280
281 $i = 1;
282 while (GETPOSTISSET('qty-'.$line->id.'-'.$i)) {
283 $qtytoprocess = (float) price2num(GETPOST('qty-'.$line->id.'-'.$i));
284
285 if ($qtytoprocess != 0) {
286 // Check warehouse is set if we should have to
287 if (GETPOSTISSET('idwarehouse-'.$line->id.'-'.$i)) { // If there is a warehouse to set
288 if (!(GETPOST('idwarehouse-'.$line->id.'-'.$i) > 0)) { // If there is no warehouse set.
289 $langs->load("errors");
290 setEventMessages($langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Warehouse"), $tmpproduct->ref), null, 'errors');
291 $error++;
292 }
293 if (isModEnabled('productbatch') && $tmpproduct->status_batch && (!GETPOST('batch-'.$line->id.'-'.$i))) {
294 $langs->load("errors");
295 setEventMessages($langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Batch"), $tmpproduct->ref), null, 'errors');
296 $error++;
297 }
298 }
299
300 $idstockmove = 0;
301 if (!$error && GETPOST('idwarehouse-'.$line->id.'-'.$i) > 0) {
302 // Record stock movement
303 $id_product_batch = 0;
304 $stockmove->setOrigin($object->element, $object->id);
305 $stockmove->context['mrp_role'] = 'toconsume';
306
307 if ($qtytoprocess >= 0) {
308 $idstockmove = $stockmove->livraison($user, $line->fk_product, GETPOSTINT('idwarehouse-'.$line->id.'-'.$i), $qtytoprocess, 0, $labelmovement, dol_now(), '', '', GETPOST('batch-'.$line->id.'-'.$i), $id_product_batch, $codemovement);
309 } else {
310 $idstockmove = $stockmove->reception($user, $line->fk_product, GETPOSTINT('idwarehouse-'.$line->id.'-'.$i), $qtytoprocess * -1, 0, $labelmovement, '', '', GETPOST('batch-'.$line->id.'-'.$i), dol_now(), $id_product_batch, $codemovement);
311 }
312 if ($idstockmove < 0) {
313 $error++;
314 setEventMessages($stockmove->error, $stockmove->errors, 'errors');
315 }
316 }
317
318 if (!$error) {
319 // Record consumption
320 $moline = new MoLine($db);
321 $moline->fk_mo = $object->id;
322 $moline->position = $pos;
323 $moline->fk_product = $line->fk_product;
324 $moline->fk_warehouse = GETPOSTINT('idwarehouse-'.$line->id.'-'.$i);
325 $moline->qty = $qtytoprocess;
326 $moline->batch = GETPOST('batch-'.$line->id.'-'.$i);
327 $moline->role = 'consumed';
328 $moline->fk_mrp_production = $line->id;
329 $moline->fk_stock_movement = $idstockmove == 0 ? null : $idstockmove;
330 $moline->fk_user_creat = $user->id;
331
332 $resultmoline = $moline->create($user);
333 if ($resultmoline <= 0) {
334 $error++;
335 setEventMessages($moline->error, $moline->errors, 'errors');
336 }
337
338 $pos++;
339 }
340 }
341
342 $i++;
343 }
344 }
345 }
346
347 // Process line to produce
348 $pos = 0;
349
350 foreach ($object->lines as $line) {
351 if ($line->role == 'toproduce') {
352 $tmpproduct = new Product($db);
353 $tmpproduct->fetch($line->fk_product);
354
355 $i = 1;
356 while (GETPOSTISSET('qtytoproduce-'.$line->id.'-'.$i)) {
357 $qtytoprocess = (float) price2num(GETPOST('qtytoproduce-'.$line->id.'-'.$i));
358 $pricetoprocess = GETPOST('pricetoproduce-'.$line->id.'-'.$i) ? price2num(GETPOST('pricetoproduce-'.$line->id.'-'.$i)) : 0;
359
360 if ($qtytoprocess != 0) {
361 // Check warehouse is set if we should have to
362 if (GETPOSTISSET('idwarehousetoproduce-'.$line->id.'-'.$i)) { // If there is a warehouse to set
363 if (!(GETPOST('idwarehousetoproduce-'.$line->id.'-'.$i) > 0)) { // If there is no warehouse set.
364 $langs->load("errors");
365 setEventMessages($langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Warehouse"), $tmpproduct->ref), null, 'errors');
366 $error++;
367 }
368 if (isModEnabled('productbatch') && $tmpproduct->status_batch && (!GETPOST('batchtoproduce-'.$line->id.'-'.$i))) {
369 $langs->load("errors");
370 setEventMessages($langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Batch"), $tmpproduct->ref), null, 'errors');
371 $error++;
372 }
373 }
374
375 $idstockmove = 0;
376 if (!$error && GETPOST('idwarehousetoproduce-'.$line->id.'-'.$i) > 0) {
377 // Record stock movement
378 $id_product_batch = 0;
379 $stockmove->origin_type = $object->element;
380 $stockmove->origin_id = $object->id;
381 $stockmove->context['mrp_role'] = 'toproduce';
382
383 $idstockmove = $stockmove->reception($user, $line->fk_product, GETPOSTINT('idwarehousetoproduce-'.$line->id.'-'.$i), $qtytoprocess, $pricetoprocess, $labelmovement, '', '', GETPOST('batchtoproduce-'.$line->id.'-'.$i), dol_now(), $id_product_batch, $codemovement);
384 if ($idstockmove < 0) {
385 $error++;
386 setEventMessages($stockmove->error, $stockmove->errors, 'errors');
387 }
388 }
389
390 if (!$error) {
391 // Record production
392 $moline = new MoLine($db);
393 $moline->fk_mo = $object->id;
394 $moline->position = $pos;
395 $moline->fk_product = $line->fk_product;
396 $moline->fk_warehouse = GETPOSTINT('idwarehousetoproduce-'.$line->id.'-'.$i);
397 $moline->qty = $qtytoprocess;
398 $moline->batch = GETPOST('batchtoproduce-'.$line->id.'-'.$i);
399 $moline->role = 'produced';
400 $moline->fk_mrp_production = $line->id;
401 $moline->fk_stock_movement = $idstockmove;
402 $moline->fk_user_creat = $user->id;
403
404 $resultmoline = $moline->create($user);
405 if ($resultmoline <= 0) {
406 $error++;
407 setEventMessages($moline->error, $moline->errors, 'errors');
408 }
409
410 $pos++;
411 }
412 }
413
414 $i++;
415 }
416 }
417 }
418
419 if (!$error) {
420 $consumptioncomplete = true;
421 $productioncomplete = true;
422
423 if (GETPOSTINT('autoclose')) {
424 foreach ($object->lines as $line) {
425 $tmpproduct = new Product($db);
426 $tmpproduct->fetch($line->fk_product);
427 if ((int) $tmpproduct->stockable_product > 0) {
428 if ($line->role == 'toconsume') {
429 $arrayoflines = $object->fetchLinesLinked('consumed', $line->id);
430 $alreadyconsumed = 0;
431 foreach ($arrayoflines as $line2) {
432 $alreadyconsumed += $line2['qty'];
433 }
434
435 if ($alreadyconsumed < $line->qty) {
436 $consumptioncomplete = false;
437 }
438 }
439 if ($line->role == 'toproduce') {
440 $arrayoflines = $object->fetchLinesLinked('produced', $line->id);
441 $alreadyproduced = 0;
442 foreach ($arrayoflines as $line2) {
443 $alreadyproduced += $line2['qty'];
444 }
445
446 if ($alreadyproduced < $line->qty) {
447 $productioncomplete = false;
448 }
449 }
450 }
451 }
452 } else {
453 $consumptioncomplete = false;
454 $productioncomplete = false;
455 }
456
457 // Update status of MO
458 dol_syslog("consumptioncomplete = ".json_encode($consumptioncomplete)." productioncomplete = ".json_encode($productioncomplete));
459 if ($consumptioncomplete && $productioncomplete) {
460 $result = $object->setStatut($object::STATUS_PRODUCED, 0, '', 'MRP_MO_PRODUCED');
461 } else {
462 $result = $object->setStatut($object::STATUS_INPROGRESS, 0, '', 'MRP_MO_PRODUCED');
463 }
464 if ($result <= 0) {
465 $error++;
466 setEventMessages($object->error, $object->errors, 'errors');
467 }
468 }
469
470 if ($error) {
471 $action = str_replace('confirm_', '', $action);
472 $db->rollback();
473 } else {
474 $db->commit();
475
476 // Redirect to avoid to action done a second time if we make a back from browser
477 header("Location: ".$_SERVER["PHP_SELF"].'?id='.$object->id);
478 exit;
479 }
480 }
481
482 // Action close produced
483 if ($action == 'confirm_produced' && $confirm == 'yes' && $permissiontoadd) {
484 $result = $object->setStatut($object::STATUS_PRODUCED, 0, '', 'MRP_MO_PRODUCED');
485 if ($result >= 0) {
486 // Define output language
487 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
488 $outputlangs = $langs;
489 $newlang = '';
490 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
491 $newlang = GETPOST('lang_id', 'aZ09');
492 }
493 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
494 $newlang = $object->thirdparty->default_lang;
495 }
496 if (!empty($newlang)) {
497 $outputlangs = new Translate("", $conf);
498 $outputlangs->setDefaultLang($newlang);
499 }
500 $model = $object->model_pdf;
501 $ret = $object->fetch($id); // Reload to get new records
502
503 $object->generateDocument($model, $outputlangs, 0, 0, 0);
504 }
505 } else {
506 setEventMessages($object->error, $object->errors, 'errors');
507 }
508 }
509
510 if ($action == 'confirm_editline' && $permissiontoadd && !in_array($object->status, array($object::STATUS_PRODUCED, $object::STATUS_CANCELED))) {
511 $moline = new MoLine($db);
512 $result = $moline->fetch(GETPOSTINT('lineid'));
513 if ($result > 0 && $moline->fk_mo != $object->id) {
514 $result = -1; // The line must belong to this MO
515 }
516 if ($result > 0 && in_array($moline->role, array('consumed', 'produced'))) {
517 $result = -1; // A consumed or produced quantity is changed by its stock movement, not here (only the quantities to consume or produce can be edited)
518 }
519 if ($result > 0) {
520 $extrafields->fetch_name_optionals_label($moline->element);
521 foreach ($extrafields->attributes[$moline->table_element]['label'] as $key => $label) {
522 $value = GETPOST('options_'.$key, 'alphanohtml');
523 $moline->array_options["options_".$key] = $value;
524 }
525 $moline->qty = GETPOSTFLOAT('qty_lineProduce');
526 if (GETPOSTISSET('warehouse_lineProduce')) {
527 $moline->fk_warehouse = (GETPOSTINT('warehouse_lineProduce') > 0 ? GETPOSTINT('warehouse_lineProduce') : 0);
528 }
529 if (GETPOSTISSET('workstation_lineProduce')) {
530 $moline->fk_default_workstation = (GETPOSTINT('workstation_lineProduce') > 0 ? GETPOSTINT('workstation_lineProduce') : 0);
531 }
532
533 $res = $moline->update($user);
534
535 if ($res < 0) {
536 setEventMessages($moline->error, $moline->errors, 'errors');
537 header("Location: ".$_SERVER["PHP_SELF"].'?id='.$object->id);
538 exit;
539 }
540 header("Location: ".$_SERVER["PHP_SELF"].'?id='.$object->id);
541 exit;
542 }
543 }
544}
545
546
547
548/*
549 * View
550 */
551
552$form = new Form($db);
553$formproject = new FormProjets($db);
554$formproduct = new FormProduct($db);
555$tmpwarehouse = new Entrepot($db);
556$tmpbatch = new Productlot($db);
557$tmpstockmovement = new MouvementStock($db);
558
559$title = $langs->trans('Mo');
560$help_url = 'EN:Module_Manufacturing_Orders|FR:Module_Ordres_de_Fabrication|DE:Modul_Fertigungsauftrag';
561$morejs = array('/mrp/js/lib_dispatch.js.php');
562llxHeader('', $title, $help_url, '', 0, 0, $morejs, '', '', 'mod-mrp page-card_production');
563
564$newToken = newToken();
565
566// Part to show record
567if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
568 $res = $object->fetch_thirdparty();
569 $res = $object->fetch_optionals();
570
571 if (getDolGlobalString('STOCK_CONSUMPTION_FROM_MANUFACTURING_WAREHOUSE') && $object->fk_warehouse > 0) {
572 $tmpwarehouse->fetch($object->fk_warehouse);
573 $fk_default_warehouse = $object->fk_warehouse;
574 }
575
576 $head = moPrepareHead($object);
577
578 print dol_get_fiche_head($head, 'production', $langs->trans("ManufacturingOrder"), -1, $object->picto);
579
580 $formconfirm = '';
581
582 // Confirmation to delete
583 if ($action == 'delete') {
584 $formquestion = array(
585 array(
586 'label' => $langs->trans('MoCancelConsumedAndProducedLines'),
587 'name' => 'alsoCancelConsumedAndProducedLines',
588 'type' => 'checkbox',
589 'value' => 0
590 ),
591 );
592 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteMo'), $langs->trans('ConfirmDeleteMo'), 'confirm_delete', $formquestion, 0, 1);
593 }
594 // Confirmation to delete line
595 if ($action == 'deleteline') {
596 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid.'&fk_movement='.$fk_movement, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
597 }
598 // Clone confirmation
599 if ($action == 'clone') {
600 // Create an array for form
601 $formquestion = array();
602 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneMo', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
603 }
604
605 // Confirmation of validation
606 if ($action == 'validate') {
607 // We check that object has a temporary ref
608 $ref = substr($object->ref, 1, 4);
609 if ($ref == 'PROV') {
610 $object->fetch_product();
611 $numref = $object->getNextNumRef($object->product);
612 } else {
613 $numref = $object->ref;
614 }
615
616 $text = $langs->trans('ConfirmValidateMo', $numref);
617 /*if (isModEnabled('notification'))
618 {
619 require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
620 $notify = new Notify($db);
621 $text .= '<br>';
622 $text .= $notify->confirmMessage('BOM_VALIDATE', $object->socid, $object);
623 }*/
624
625 $formquestion = array();
626 if (isModEnabled('mrp')) {
627 $langs->load("mrp");
628 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
629 $formproduct = new FormProduct($db);
630 $forcecombo = 0;
631 if ($conf->browser->name == 'ie') {
632 $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
633 }
634 $formquestion = array(
635 // 'text' => $langs->trans("ConfirmClone"),
636 // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
637 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
638 );
639 }
640
641 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Validate'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
642 }
643
644 // Confirmation to cancel
645 if ($action == 'cancel') {
646 $formquestion = array(
647 array(
648 'label' => $langs->trans('MoCancelConsumedAndProducedLines'),
649 'name' => 'alsoCancelConsumedAndProducedLines',
650 'type' => 'checkbox',
651 'value' => !getDolGlobalString('MO_ALSO_CANCEL_CONSUMED_AND_PRODUCED_LINES_BY_DEFAULT') ? 0 : 1
652 ),
653 );
654 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('CancelMo'), $langs->trans('ConfirmCancelMo'), 'confirm_cancel', $formquestion, 0, 1);
655 }
656
657 // Call Hook formConfirm
658 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
659 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
660 if (empty($reshook)) {
661 $formconfirm .= $hookmanager->resPrint;
662 } elseif ($reshook > 0) {
663 $formconfirm = $hookmanager->resPrint;
664 }
665
666 // Print form confirm
667 print $formconfirm;
668
669
670 // MO file
671 // ------------------------------------------------------------
672 $linkback = '<a href="'.DOL_URL_ROOT.'/mrp/mo_list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
673
674 $morehtmlref = '<div class="refidno">';
675
676 /*
677 // Ref bis
678 $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mrp->creer, 'string', '', 0, 1);
679 $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mrp->creer, 'string', '', null, null, '', 1);
680 */
681
682 // Thirdparty
683 if (is_object($object->thirdparty)) {
684 $morehtmlref .= $object->thirdparty->getNomUrl(1, 'customer');
685 if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
686 $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'">'.$langs->trans("OtherOrders").'</a>)';
687 }
688 }
689
690 // Project
691 if (isModEnabled('project')) {
692 $langs->load("projects");
693 if (is_object($object->thirdparty)) {
694 $morehtmlref .= '<br>';
695 }
696 if ($permissiontoadd) {
697 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
698 if ($action != 'classify') {
699 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
700 }
701 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
702 } else {
703 if (!empty($object->fk_project)) {
704 $proj = new Project($db);
705 $proj->fetch($object->fk_project);
706 $morehtmlref .= $proj->getNomUrl(1);
707 if ($proj->title) {
708 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
709 }
710 }
711 }
712 }
713 $morehtmlref .= '</div>';
714
715
716 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
717
718
719 print '<div class="fichecenter">';
720 print '<div class="fichehalfleft">';
721 print '<div class="underbanner clearboth"></div>';
722 print '<table class="border centpercent tableforfield">'."\n";
723
724 // Common attributes
725 $keyforbreak = 'fk_warehouse';
726 unset($object->fields['fk_project']);
727 unset($object->fields['fk_soc']);
728 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
729
730 // Other attributes
731 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
732
733 print '</table>';
734 print '</div>';
735 print '</div>';
736
737 print '<div class="clearboth"></div>';
738
739 print dol_get_fiche_end();
740
741
742 if (!in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
743 print '<div class="tabsAction">';
744
745 $parameters = array();
746 // Note that $action and $object may be modified by hook
747 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action);
748 if (empty($reshook)) {
749 // Validate
750 if ($object->status == $object::STATUS_DRAFT) {
751 if ($permissiontoadd) {
752 if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
753 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=validate&token='.$newToken.'">'.$langs->trans("Validate").'</a>';
754 } else {
755 $langs->load("errors");
756 print '<a class="butActionRefused" href="" title="'.$langs->trans("ErrorAddAtLeastOneLineFirst").'">'.$langs->trans("Validate").'</a>';
757 }
758 }
759 }
760
761 // Consume or produce
762 if ($object->status == Mo::STATUS_VALIDATED || $object->status == Mo::STATUS_INPROGRESS) {
763 if ($permissiontoproduce) {
764 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=consumeorproduce&token='.$newToken.'">'.$langs->trans('ConsumeOrProduce').'</a>';
765 } else {
766 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('ConsumeOrProduce').'</a>';
767 }
768 } elseif ($object->status == Mo::STATUS_DRAFT) {
769 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ValidateBefore").'">'.$langs->trans('ConsumeOrProduce').'</a>';
770 }
771
772 // ConsumeAndProduceAll
773 if ($object->status == Mo::STATUS_VALIDATED || $object->status == Mo::STATUS_INPROGRESS) {
774 if ($permissiontoproduce) {
775 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=consumeandproduceall&token='.$newToken.'">'.$langs->trans('ConsumeAndProduceAll').'</a>';
776 } else {
777 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('ConsumeAndProduceAll').'</a>';
778 }
779 } elseif ($object->status == Mo::STATUS_DRAFT) {
780 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ValidateBefore").'">'.$langs->trans('ConsumeAndProduceAll').'</a>';
781 }
782
783 // Cancel - Reopen
784 if ($permissiontoadd) {
785 if ($object->status == $object::STATUS_VALIDATED || $object->status == $object::STATUS_INPROGRESS) {
786 $arrayproduced = $object->fetchLinesLinked('produced', 0);
787 $nbProduced = 0;
788 foreach ($arrayproduced as $lineproduced) {
789 $nbProduced += $lineproduced['qty'];
790 }
791 if ($nbProduced > 0) { // If production has started, we can close it
792 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_produced&confirm=yes&token='.$newToken.'">'.$langs->trans("Close").'</a>'."\n";
793 } else {
794 print '<a class="butActionRefused" href="#" title="'.$langs->trans("GoOnTabProductionToProduceFirst", $langs->transnoentitiesnoconv("Production")).'">'.$langs->trans("Close").'</a>'."\n";
795 }
796
797 print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.$newToken.'">'.$langs->trans("Cancel").'</a>'."\n";
798 }
799
800 if ($object->status == $object::STATUS_CANCELED) {
801 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&confirm=yes&token='.$newToken.'">'.$langs->trans("ReOpen").'</a>'."\n";
802 }
803
804 if ($object->status == $object::STATUS_PRODUCED) {
805 if ($permissiontoproduce) {
806 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&token='.$newToken.'">'.$langs->trans('ReOpen').'</a>';
807 } else {
808 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('ReOpen').'</a>';
809 }
810 }
811 }
812 }
813
814 print '</div>';
815 }
816
817 if (in_array($action, array('consumeorproduce', 'consumeandproduceall', 'addconsumeline', 'addproduceline', 'editline'))) {
818 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
819 print '<input type="hidden" name="token" value="'.newToken().'">';
820 print '<input type="hidden" name="action" value="confirm_'.$action.'">';
821 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
822 print '<input type="hidden" name="id" value="'.$id.'">';
823 // Note: closing form is add end of page
824
825 if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
826 $defaultstockmovementlabel = GETPOST('inventorylabel', 'alphanohtml') ? GETPOST('inventorylabel', 'alphanohtml') : $langs->trans("ProductionForRef", $object->ref);
827 $defaultstockmovementcode = GETPOST('inventorycode', 'alphanohtml') ? GETPOST('inventorycode', 'alphanohtml') : dol_print_date(dol_now(), 'dayhourlog');
828
829 print '<div class="center'.(in_array($action, array('consumeorproduce', 'consumeandproduceall')) ? ' formconsumeproduce' : '').'">';
830 print '<div class="opacitymedium hideonsmartphone paddingbottom">'.$langs->trans("ConfirmProductionDesc", $langs->transnoentitiesnoconv("Confirm")).'<br></div>';
831 print '<span class="fieldrequired">'.$langs->trans("InventoryCode").':</span> <input type="text" class="minwidth150 maxwidth200" name="inventorycode" value="'.$defaultstockmovementcode.'"> &nbsp; ';
832 print '<span class="clearbothonsmartphone"></span>';
833 print $langs->trans("MovementLabel").': <input type="text" class="minwidth300" name="inventorylabel" value="'.$defaultstockmovementlabel.'"><br><br>';
834 print '<input type="checkbox" id="autoclose" name="autoclose" value="1"'.(GETPOSTISSET('inventorylabel') ? (GETPOST('autoclose') ? ' checked="checked"' : '') : ' checked="checked"').'> <label for="autoclose">'.$langs->trans("AutoCloseMO").'</label><br>';
835 print '<input type="submit" class="button" value="'.$langs->trans("Confirm").'" name="confirm">';
836 print ' &nbsp; ';
837 print '<input class="button button-cancel" type="submit" value="'.$langs->trans("Cancel").'" name="cancel">';
838 print '<br><br>';
839 print '</div>';
840
841 print '<br>';
842 }
843 }
844
845
846 /*
847 * Lines
848 */
849 $collapse = 1;
850
851 if (!empty($object->table_element_line)) {
852 // Show object lines
853 $object->fetchLines();
854
855 $bomcost = 0;
856 if ($object->fk_bom > 0) {
857 $bom = new BOM($db);
858 $res = $bom->fetch($object->fk_bom);
859 if ($res > 0) {
860 $bom->calculateCosts();
861 $bomcost = $bom->unit_cost;
862 }
863 }
864
865 // Lines to consume
866
867 print '<!-- Lines to consume -->'."\n";
868 print '<div class="fichecenter">';
869 print '<div class="fichehalfleft">';
870 print '<div class="clearboth"></div>';
871
872 $url = $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=addconsumeline&token='.newToken();
873 $permissiontoaddaconsumeline = ($object->status != $object::STATUS_PRODUCED && $object->status != $object::STATUS_CANCELED) ? 1 : -2;
874 $parameters = array('morecss' => 'reposition');
875 $helpText = '';
876 if ($permissiontoaddaconsumeline == -2) {
877 $helpText = $langs->trans('MOIsClosed');
878 }
879
880 $newcardbutton = '';
881 if ($action != 'consumeorproduce' && $action != 'consumeandproduceall') {
882 $newcardbutton = dolGetButtonTitle($langs->trans('AddNewConsumeLines'), $helpText, 'fa fa-plus-circle size15x', $url, '', $permissiontoaddaconsumeline, $parameters);
883 }
884
885 print load_fiche_titre($langs->trans('Consumption'), $newcardbutton, '', 0, '', '', '');
886
887 print '<div class="div-table-responsive-no-min">';
888 print '<table class="noborder noshadow centpercent nobottom">';
889
890 print '<!-- Line of title for products to consume -->'."\n";
891 print '<tr class="liste_titre trheight5em">';
892 // Product
893 print '<td>'.$langs->trans("Product").'</td>';
894 // Qty
895 print '<td class="right">'.$langs->trans("Qty").'</td>';
896 // Unit
897 print '<td></td>';
898 // Cost price
899 if ($permissiontoupdatecost && getDolGlobalString('MRP_SHOW_COST_FOR_CONSUMPTION')) {
900 print '<td class="right">'.$langs->trans("UnitCost").'</td>';
901 }
902 // Qty already consumed
903 print '<td class="right classfortooltip" title="'.$langs->trans("QtyAlreadyConsumed").'">';
904 print $langs->trans("QtyAlreadyConsumedShort");
905 print '</td>';
906 // Warehouse
907 print '<td>';
908 if ($collapse || in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
909 print $langs->trans("Warehouse");
910 if (isModEnabled('workstation')) {
911 print ' '.$langs->trans("or").' '.$langs->trans("Workstation");
912 }
913 // Select warehouse to force it everywhere
914 if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
915 $listwarehouses = $tmpwarehouse->list_array(1);
916 if (count($listwarehouses) > 1) {
917 print '<br>'.$form->selectarray('fk_default_warehouse', $listwarehouses, $fk_default_warehouse, $langs->trans("ForceTo"), 0, 0, '', 0, 0, 0, '', 'minwidth100 maxwidth200', 1);
918 } elseif (count($listwarehouses) == 1) {
919 print '<br>'.$form->selectarray('fk_default_warehouse', $listwarehouses, $fk_default_warehouse, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100 maxwidth200', 1);
920 }
921 }
922 }
923 print '</td>';
924
925 if (isModEnabled('stock')) {
926 // Available
927 print '<td align="right">';
928 if ($collapse || in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
929 print $langs->trans("Stock");
930 }
931 print '</td>';
932 }
933 // Lot - serial
934 if (isModEnabled('productbatch')) {
935 print '<td>';
936 if ($collapse || in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
937 print $langs->trans("Batch");
938 }
939 print '</td>';
940 }
941
942 // Split
943 print '<td></td>';
944
945 // SplitAll
946 print '<td></td>';
947
948 // Edit Line
949 if ($object->status == Mo::STATUS_DRAFT) {
950 print '<td></td>';
951 }
952
953 // Action
954 if ($permissiontodelete) {
955 print '<td></td>';
956 }
957
958 print '</tr>';
959
960 if ($action == 'addconsumeline') {
961 print '<!-- Add line to consume -->'."\n";
962 print '<tr class="liste_titre">';
963 // Product
964 print '<td>';
965 print $form->select_produits(0, 'productidtoadd', '', 0, 0, -1, 2, '', 1, array(), 0, '1', 0, 'maxwidth150');
966 print '</td>';
967 // Qty
968 print '<td class="right"><input type="text" name="qtytoadd" value="1" class="width40 right"></td>';
969 // Unit
970 print '<td>';
971 //if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
972 //...
973 //}
974 print '</td>';
975 // Cost price
976 if ($permissiontoupdatecost && getDolGlobalString('MRP_SHOW_COST_FOR_CONSUMPTION')) {
977 print '<td></td>';
978 }
979
980 $colspan = 3;
981 if (isModEnabled('stock')) {
982 $colspan++;
983 }
984 if (isModEnabled('productbatch')) {
985 $colspan++;
986 }
987 // Qty already consumed + Warehouse
988 print '<td colspan="'.$colspan.'">';
989 print '<input type="submit" class="button buttongen button-add" name="addconsumelinebutton" value="'.$langs->trans("Add").'">';
990 print '<input type="submit" class="button buttongen button-cancel" name="canceladdconsumelinebutton" value="'.$langs->trans("Cancel").'">';
991 print '</td>';
992 // Split All
993 print '<td></td>';
994 // Edit Line
995 if ($object->status == Mo::STATUS_DRAFT) {
996 print '<td></td>';
997 }
998 // Action
999 if ($permissiontodelete) {
1000 print '<td></td>';
1001 }
1002 print '</tr>';
1003
1004 // Extrafields Line
1005 if (is_object($objectline)) {
1006 $extrafields->fetch_name_optionals_label($object->table_element_line);
1007 $temps = $objectline->showOptionals($extrafields, 'edit', array(), '', '', '1', 'line');
1008 if (!empty($temps)) {
1009 print '<tr class="liste_titre"><td style="padding-top: 20px" colspan="9" id="extrafield_lines_area_edit" name="extrafield_lines_area_edit">';
1010 print $temps;
1011 print '</td></tr>';
1012 }
1013 }
1014 }
1015
1016 // Lines to consume
1017
1018 $bomcostupdated = 0; // We will recalculate the unitary cost to produce a product using the real "products to consume into MO"
1019
1020 if (!empty($object->lines)) {
1021 $nblinetoconsume = 0;
1022 foreach ($object->lines as $line) {
1023 if ($line->role == 'toconsume') {
1024 $nblinetoconsume++;
1025 }
1026 }
1027
1028 $nblinetoconsumecursor = 0;
1029 foreach ($object->lines as $line) {
1030 if ($line->role == 'toconsume') {
1031 $nblinetoconsumecursor++;
1032
1033 $tmpproduct = new Product($db);
1034 $tmpproduct->fetch($line->fk_product);
1035 $linecost = price2num($tmpproduct->pmp, 'MT');
1036
1037 if ($object->qty > 0) {
1038 // add free consume line cost to $bomcostupdated
1039 $costprice = price2num((!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp);
1040 if (empty($costprice)) {
1041 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
1042 $productFournisseur = new ProductFournisseur($db);
1043 if ($productFournisseur->find_min_price_product_fournisseur($line->fk_product, $line->qty) > 0) {
1044 $costprice = $productFournisseur->fourn_unitprice;
1045 } else {
1046 $costprice = 0;
1047 }
1048 }
1049
1050 $useunit = (($tmpproduct->type == Product::TYPE_PRODUCT && getDolGlobalInt('PRODUCT_USE_UNITS')) || (($tmpproduct->type == Product::TYPE_SERVICE) && ($line->fk_unit)));
1051
1052 if ($useunit && $line->fk_unit > 0) {
1053 $reg = [];
1054 $qtyhourservice = 0;
1055 if (preg_match('/^(\d+)([a-z]+)$/', $tmpproduct->duration, $reg)) {
1056 $qtyhourservice = convertDurationtoHour((float) $reg[1], (string) $reg[2]);
1057 }
1058 $qtyhourforline = 0;
1059 if ($line->fk_unit) {
1060 $unitforline = measuringUnitString($line->fk_unit, '', null, 1);
1061 $qtyhourforline = convertDurationtoHour($line->qty, $unitforline);
1062 }
1063
1064 // Add the workstation cost for the manufacturing order cost when a workstation is set
1065 if (isModEnabled('workstation') && $line->fk_default_workstation > 0) {
1066 $workstation = new Workstation($db);
1067 $workstation->fetch($line->fk_default_workstation);
1068 $linecost = price2num($qtyhourforline * ($workstation->thm_operator_estimated + $workstation->thm_machine_estimated) / $object->qty, 'MT'); //if global const MRP_SHOW_COST_FOR_CONSUMPTION is used to show price for each line
1069 $bomcostupdated += price2num($qtyhourforline * ($workstation->thm_operator_estimated + $workstation->thm_machine_estimated) / $object->qty, 'MU');
1070 } elseif ($qtyhourservice && $qtyhourforline) {
1071 $linecost = price2num(($qtyhourforline / $qtyhourservice * $costprice) / $object->qty, 'MT'); // price for line for all quantities
1072 $bomcostupdated += price2num(($qtyhourforline / $qtyhourservice * $costprice) / $object->qty, 'MU'); // same but with full accuracy
1073 } else {
1074 $linecost = price2num(($line->qty * $costprice) / $object->qty, 'MT'); // price for line for all quantities
1075 $bomcostupdated += price2num(($line->qty * $costprice) / $object->qty, 'MU'); // same but with full accuracy
1076 }
1077 } else {
1078 $linecost = price2num(($line->qty * $costprice) / $object->qty, 'MT'); // price for line for all quantities
1079 $bomcostupdated += price2num(($line->qty * $costprice) / $object->qty, 'MU'); // same but with full accuracy
1080 }
1081 }
1082
1083 $bomcostupdated = price2num($bomcostupdated, 'MU');
1084 $arrayoflines = $object->fetchLinesLinked('consumed', $line->id);
1085 $alreadyconsumed = 0;
1086 foreach ($arrayoflines as $line2) {
1087 $alreadyconsumed += $line2['qty'];
1088 }
1089
1090 if ($action == 'editline' && $lineid == $line->id) {
1091 $linecost = price2num($tmpproduct->pmp, 'MT');
1092
1093 $arrayoflines = $object->fetchLinesLinked('consumed', $line->id);
1094 $alreadyconsumed = 0;
1095 if (is_array($arrayoflines) && !empty($arrayoflines)) {
1096 foreach ($arrayoflines as $line2) {
1097 $alreadyconsumed += $line2['qty'];
1098 }
1099 }
1100 $suffix = '_' . $line->id;
1101 print '<!-- Line to dispatch ' . $suffix . ' (line edited) -->' . "\n";
1102 // hidden fields for js function
1103 print '<input id="qty_ordered' . $suffix . '" type="hidden" value="' . $line->qty . '">';
1104 // Duration - Time spent
1105 print '<input id="qty_dispatched' . $suffix . '" type="hidden" value="' . $alreadyconsumed . '">';
1106 print '<tr>';
1107 print '<input name="lineid" type="hidden" value="' . $line->id . '">';
1108
1109 // Product
1110 print '<td>' . $tmpproduct->getNomUrl(1);
1111 print '<br><div class="opacitymedium small tdoverflowmax150" title="' . dol_escape_htmltag($tmpproduct->label) . '">' . $tmpproduct->label . '</span>';
1112 print '</td>';
1113
1114 // Qty
1115 print '<td class="right nowraponall">';
1116 print '<input class="width40 right" name="qty_lineProduce" value="'. $line->qty.'">';
1117 print '</td>';
1118
1119 // Unit
1120 print '<td class="right nowraponall">';
1121 $useunit = (($tmpproduct->type == Product::TYPE_PRODUCT && getDolGlobalInt('PRODUCT_USE_UNITS')) || (($tmpproduct->type == Product::TYPE_SERVICE) && ($line->fk_unit)));
1122 if ($useunit) {
1123 print measuringUnitString($line->fk_unit, '', null, 2);
1124 }
1125 print '</td>';
1126
1127 // Cost price
1128 if ($permissiontoupdatecost && getDolGlobalString('MRP_SHOW_COST_FOR_CONSUMPTION')) {
1129 print '<td></td>';
1130 }
1131
1132 // Qty consumed
1133 print '<td class="right">';
1134 print ' ' . price2num($alreadyconsumed, 'MS');
1135 print '</td>';
1136
1137 // Warehouse / Workstation
1138 print '<td>';
1139 if ($tmpproduct->type == Product::TYPE_PRODUCT) {
1140 print $formproduct->selectWarehouses($line->fk_warehouse, 'warehouse_lineProduce', 'warehouseopen', 1);
1141 } elseif (isModEnabled('workstation')) {
1142 print $formproduct->selectWorkstations($line->fk_default_workstation, 'workstation_lineProduce', 1);
1143 }
1144 print '</td>';
1145
1146 // Stock
1147 if (isModEnabled('stock')) {
1148 print '<td class="nowraponall right">';
1149 if ($tmpproduct->isStockManaged()) {
1150 if ($tmpproduct->stock_reel < ($line->qty - $alreadyconsumed)) {
1151 print img_warning($langs->trans('StockTooLow')).' ';
1152 }
1153 print '<span class="left">'. $tmpproduct->stock_reel .' </span>';
1154 }
1155 print '</td>';
1156 }
1157
1158 // Lot - serial
1159 if (isModEnabled('productbatch')) {
1160 print '<td></td>';
1161 }
1162 // Split + SplitAll + Edit line + Delete
1163 print '<td colspan="'.(3 + ($object->status == Mo::STATUS_DRAFT ? 1 : 0) + ($permissiontodelete ? 1 : 0)).'">';
1164 print '<input type="submit" class="button buttongen button-add small nominwidth" name="save" value="' . $langs->trans("Save") . '">';
1165 print '<input type="submit" class="button buttongen button-cancel small nominwidth" name="cancel" value="' . $langs->trans("Cancel") . '">';
1166 print '</td>';
1167
1168 print '</tr>';
1169
1170 // Extrafields Line
1171 if (!empty($extrafields)) {
1172 $line->fetch_optionals();
1173 $temps = $line->showOptionals($extrafields, 'edit', array(), '', '', '1', 'line');
1174 if (!empty($temps)) {
1175 $colspan = 10;
1176 print '<tr><td colspan="'.$colspan.'"><div style="padding-top: 20px" id="extrafield_lines_area_edit" name="extrafield_lines_area_edit">';
1177 print $temps;
1178 print '</div></td></tr>';
1179 }
1180 }
1181 } else {
1182 $suffix = '_' . $line->id;
1183 print '<!-- Line to dispatch ' . $suffix . ' -->' . "\n";
1184 // hidden fields for js function
1185 print '<input id="qty_ordered' . $suffix . '" type="hidden" value="' . $line->qty . '">';
1186 print '<input id="qty_dispatched' . $suffix . '" type="hidden" value="' . $alreadyconsumed . '">';
1187
1188 print '<tr data-line-id="' . $line->id . '">';
1189
1190 // Product
1191 print '<td>' . $tmpproduct->getNomUrl(1);
1192 print '<br><div class="opacitymedium small tdoverflowmax150" title="' . dol_escape_htmltag($tmpproduct->label) . '">' . $tmpproduct->label . '</div>';
1193 print '</td>';
1194
1195 // Qty
1196 print '<td class="right nowraponall">';
1197 $help = '';
1198 if ($line->qty_frozen) {
1199 $help = ($help ? '<br>' : '') . '<strong>' . $langs->trans("QuantityFrozen") . '</strong>: ' . yn(1) . ' (' . $langs->trans("QuantityConsumedInvariable") . ')';
1200 print $form->textwithpicto('', $help, -1, 'lock') . ' ';
1201 }
1202 if ($line->disable_stock_change) {
1203 $help = ($help ? '<br>' : '') . '<strong>' . $langs->trans("DisableStockChange") . '</strong>: ' . yn(1) . ' (' . (($tmpproduct->type == Product::TYPE_SERVICE && !getDolGlobalString('STOCK_SUPPORTS_SERVICES')) ? $langs->trans("NoStockChangeOnServices") : $langs->trans("DisableStockChangeHelp")) . ')';
1204 print $form->textwithpicto('', $help, -1, 'help') . ' ';
1205 }
1206 print price2num($line->qty, 'MS');
1207 print '</td>';
1208
1209 // Unit
1210 print '<td class="right nowraponall">';
1211 $useunit = (($tmpproduct->type == Product::TYPE_PRODUCT && getDolGlobalInt('PRODUCT_USE_UNITS')) || (($tmpproduct->type == Product::TYPE_SERVICE) && ($line->fk_unit)));
1212 if ($useunit) {
1213 print measuringUnitString($line->fk_unit, '', null, 2);
1214 }
1215 print '</td>';
1216
1217 // Cost price
1218 if ($permissiontoupdatecost && getDolGlobalString('MRP_SHOW_COST_FOR_CONSUMPTION')) {
1219 print '<td class="right nowraponall">';
1220 print price($linecost);
1221 print '</td>';
1222 }
1223
1224 // Already consumed
1225 print '<td class="right">';
1226 if ($alreadyconsumed) {
1227 print '<script>';
1228 print 'jQuery(document).ready(function() {
1229 jQuery("#expandtoproduce' . $line->id . '").click(function() {
1230 console.log("Expand mrp_production line ' . $line->id . '");
1231 jQuery(".expanddetail' . $line->id . '").toggle();';
1232 if ($nblinetoconsume == $nblinetoconsumecursor) { // If it is the last line
1233 print 'if (jQuery("#tablelines").hasClass("nobottom")) { jQuery("#tablelines").removeClass("nobottom"); } else { jQuery("#tablelines").addClass("nobottom"); }';
1234 }
1235 print '
1236 });
1237 });';
1238 print '</script>';
1239 if (empty($conf->use_javascript_ajax)) {
1240 print '<a href="' . $_SERVER["PHP_SELF"] . '?collapse=' . $collapse . ',' . $line->id . '">';
1241 }
1242 print img_picto($langs->trans("ShowDetails"), "chevron-down", 'id="expandtoproduce' . $line->id . '"');
1243 if (empty($conf->use_javascript_ajax)) {
1244 print '</a>';
1245 }
1246 } else {
1247 if ($nblinetoconsume == $nblinetoconsumecursor) { // If it is the last line
1248 print '<script>jQuery("#tablelines").removeClass("nobottom");</script>';
1249 }
1250 }
1251 print ' ' . price2num($alreadyconsumed, 'MS');
1252 print '</td>';
1253
1254 // Warehouse and/or workstation
1255 print '<td class="tdoverflowmax100">';
1256 if ($tmpproduct->isStockManaged()) {
1257 // When STOCK_CONSUMPTION_FROM_MANUFACTURING_WAREHOUSE is set, we always use the warehouse of the MO, the same than production.
1258 if (getDolGlobalString('STOCK_CONSUMPTION_FROM_MANUFACTURING_WAREHOUSE') && $tmpwarehouse->id > 0) {
1259 print img_picto('', $tmpwarehouse->picto) . " " . $tmpwarehouse->label;
1260 } else {
1261 if ($line->fk_warehouse > 0) {
1262 $warehouseline = new Entrepot($db);
1263 $warehouseline->fetch($line->fk_warehouse);
1264 print $warehouseline->getNomUrl(1);
1265 }
1266 }
1267 }
1268 if (isModEnabled('workstation') && $line->fk_default_workstation > 0) {
1269 $tmpworkstation = new Workstation($db);
1270 $tmpworkstation->fetch($line->fk_default_workstation);
1271 print $tmpworkstation->getNomUrl(1);
1272 }
1273 print '</td>';
1274
1275 // Stock
1276 if (isModEnabled('stock')) {
1277 print '<td class="nowraponall right">';
1278 if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES') && $tmpproduct->type != Product::TYPE_SERVICE) {
1279 if (!$line->disable_stock_change && $tmpproduct->stock_reel < ($line->qty - $alreadyconsumed)) {
1280 print img_warning($langs->trans('StockTooLow')) . ' ';
1281 }
1282 if (!getDolGlobalString('STOCK_CONSUMPTION_FROM_MANUFACTURING_WAREHOUSE') || empty($tmpwarehouse->id)) {
1283 print price2num($tmpproduct->stock_reel, 'MS'); // Available
1284 } else {
1285 // Print only the stock in the selected warehouse
1286 $tmpproduct->load_stock();
1287 $wh_stock = $tmpproduct->stock_warehouse[$tmpwarehouse->id];
1288 if (!empty($wh_stock)) {
1289 print price2num($wh_stock->real, 'MS');
1290 } else {
1291 print "0";
1292 }
1293 }
1294 }
1295 print '</td>';
1296 }
1297
1298 // Lot
1299 if (isModEnabled('productbatch')) {
1300 print '<td></td>';
1301 }
1302
1303 // Split
1304 print '<td></td>';
1305
1306 // Split All
1307 print '<td></td>';
1308
1309 // Action Edit line
1310 if ($object->status == Mo::STATUS_DRAFT) {
1311 $href = $_SERVER["PHP_SELF"] . '?id=' . ((int) $object->id) . '&action=editline&token=' . newToken() . '&lineid=' . ((int) $line->id);
1312 print '<td class="center">';
1313 print '<a class="reposition editfielda" href="' . $href . '">';
1314 print img_picto($langs->trans('TooltipEditAndRevertStockMovement'), 'edit');
1315 print '</a>';
1316 print '</td>';
1317 }
1318
1319 // Action delete line, if no consumption has occurred for this product
1320 if ($permissiontodelete && empty($arrayoflines)) {
1321 $href = $_SERVER["PHP_SELF"] . '?id=' . ((int) $object->id) . '&action=deleteline&token=' . newToken() . '&lineid=' . ((int) $line->id);
1322 print '<td class="center">';
1323 print '<a class="reposition" href="' . $href . '">';
1324 print img_picto($langs->trans('TooltipDeleteAndRevertStockMovement'), 'delete');
1325 print '</a>';
1326 print '</td>';
1327 }
1328
1329 print '</tr>';
1330
1331 // Extrafields Line
1332 if (!empty($extrafields)) {
1333 $line->fetch_optionals();
1334 $temps = $line->showOptionals($extrafields, 'view', array(), '', '', '1', 'line');
1335 if (!empty($temps)) {
1336 $colspan = 10;
1337 print '<tr><td colspan="'.$colspan.'"><div id="extrafield_lines_area_'.$line->id.'" name="extrafield_lines_area_'.$line->id.'">';
1338 print $temps;
1339 print '</div></td></tr>';
1340 }
1341 }
1342 }
1343
1344 // Show detailed of already consumed with js code to collapse
1345 foreach ($arrayoflines as $line2) {
1346 print '<tr class="expanddetail'.$line->id.' hideobject opacitylow">';
1347
1348 // Date
1349 print '<td>';
1350 $tmpstockmovement->id = $line2['fk_stock_movement'];
1351 print '<a href="'.DOL_URL_ROOT.'/product/stock/movement_list.php?search_ref='.$tmpstockmovement->id.'">'.img_picto($langs->trans("StockMovement"), 'movement', 'class="paddingright"').'</a>';
1352 print dol_print_date($line2['date'], 'dayhour', 'tzuserrel');
1353 print '</td>';
1354
1355 // Qty
1356 print '<td></td>';
1357
1358 // Unit
1359 print '<td></td>';
1360
1361 // Cost price
1362 if ($permissiontoupdatecost && getDolGlobalString('MRP_SHOW_COST_FOR_CONSUMPTION')) {
1363 print '<td></td>';
1364 }
1365
1366 //Already consumed
1367 print '<td class="right">'.$line2['qty'].'</td>';
1368
1369 // Warehouse
1370 print '<td class="tdoverflowmax150">';
1371 if ($line2['fk_warehouse'] > 0) {
1372 $result = $tmpwarehouse->fetch($line2['fk_warehouse']);
1373 if ($result > 0) {
1374 print $tmpwarehouse->getNomUrl(1);
1375 }
1376 }
1377 print '</td>';
1378
1379 // Stock
1380 if (isModEnabled('stock')) {
1381 print '<td></td>';
1382 }
1383
1384 // Lot Batch
1385 if (isModEnabled('productbatch')) {
1386 print '<td>';
1387 if ($line2['batch'] != '') {
1388 $tmpbatch->fetch(0, $line2['fk_product'], $line2['batch']);
1389 print $tmpbatch->getNomUrl(1);
1390 }
1391 print '</td>';
1392 }
1393
1394 // Split
1395 print '<td></td>';
1396
1397 // Split All
1398 print '<td></td>';
1399
1400 // Action Edit line
1401 if ($object->status == Mo::STATUS_DRAFT) {
1402 $href = $_SERVER["PHP_SELF"] . '?id=' . ((int) $object->id) . '&action=editline&token=' . newToken() . '&lineid=' . ((int) $line2['rowid']);
1403 print '<td class="center">';
1404 print '<a class="reposition" href="' . $href . '">';
1405 print img_picto($langs->trans('TooltipEditAndRevertStockMovement'), 'edit');
1406 print '</a>';
1407 print '</td>';
1408 }
1409
1410 // Action delete line
1411 if ($permissiontodelete) {
1412 $href = $_SERVER["PHP_SELF"].'?id='.((int) $object->id).'&action=deleteline&token='.newToken().'&lineid='.((int) $line2['rowid']).'&fk_movement='.((int) $line2['fk_stock_movement']);
1413 print '<td class="center">';
1414 print '<a class="reposition" href="'.$href.'">';
1415 print img_picto($langs->trans('TooltipDeleteAndRevertStockMovement'), 'delete');
1416 print '</a>';
1417 print '</td>';
1418 }
1419
1420 print '</tr>';
1421 }
1422
1423 if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
1424 $i = 1;
1425 print '<!-- Enter line to consume -->'."\n";
1426 $maxQty = 1;
1427 print '<tr data-max-qty="'.$maxQty.'" name="batch_'.$line->id.'_'.$i.'">';
1428 // Ref
1429 print '<td><span class="opacitymedium">'.$langs->trans("ToConsume").'</span></td>';
1430 $preselected = (GETPOSTISSET('qty-'.$line->id.'-'.$i) ? GETPOST('qty-'.$line->id.'-'.$i) : max(0, $line->qty - $alreadyconsumed));
1431 if ($action == 'consumeorproduce' && !getDolGlobalString('MRP_AUTO_SET_REMAINING_QUANTITIES_TO_BE_CONSUMED') && !GETPOSTISSET('qty-'.$line->id.'-'.$i)) {
1432 $preselected = 0;
1433 }
1434
1435 $disable = '';
1436 if (getDolGlobalString('MRP_NEVER_CONSUME_MORE_THAN_EXPECTED') && ($line->qty - $alreadyconsumed) <= 0) {
1437 $disable = 'disabled';
1438 }
1439
1440 // input hidden with fk_product of line
1441 print '<input type="hidden" name="product-'.$line->id.'-'.$i.'" value="'.$line->fk_product.'">';
1442
1443 // Qty
1444 print '<td class="right">';
1445 if ((int) $tmpproduct->stockable_product > 0) {
1446 print '<input type="text" class="width50 right" id="qtytoconsume-' . $line->id . '-' . $i . '" name="qty-' . $line->id . '-' . $i . '" value="' . $preselected . '" ' . $disable . '>';
1447 } else {
1448 print '<input type="hidden" id="qtytoconsume-' . $line->id . '-' . $i . '" name="qty-' . $line->id . '-' . $i . '" value="0">';
1449 print '<span class="opacitymedium">' . $langs->trans("StockDisabled") . '</span>';
1450 }
1451 print '</td>';
1452
1453 // Unit
1454 print '<td></td>';
1455
1456 // Cost
1457 if ($permissiontoupdatecost && getDolGlobalString('MRP_SHOW_COST_FOR_CONSUMPTION')) {
1458 print '<td></td>';
1459 }
1460
1461 // Already consumed
1462 print '<td></td>';
1463
1464 // Warehouse
1465 print '<td>';
1466 if (($tmpproduct->type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES'))
1467 && ((int) $tmpproduct->stockable_product > 0)) {
1468 if (empty($line->disable_stock_change)) {
1469 $preselected = (GETPOSTISSET('idwarehouse-'.$line->id.'-'.$i) ? GETPOST('idwarehouse-'.$line->id.'-'.$i) : ($tmpproduct->fk_default_warehouse > 0 ? $tmpproduct->fk_default_warehouse : 'ifone'));
1470 print $formproduct->selectWarehouses($preselected, 'idwarehouse-'.$line->id.'-'.$i, '', 1, 0, $line->fk_product, '', 1, 0, array(), 'maxwidth200 csswarehouse_'.$line->id.'_'.$i);
1471 } else {
1472 print '<span class="opacitymedium">'.$langs->trans("DisableStockChange").'</span>';
1473 }
1474 } else {
1475 if ((int) $tmpproduct->stockable_product > 0) {
1476 print '<span class="opacitymedium">' . $langs->trans("StockDisabled") . '</span>';
1477 } else {
1478 print '<span class="opacitymedium">' . $langs->trans("NoStockChangeOnServices") . '</span>';
1479 }
1480 }
1481 print '</td>';
1482
1483 // Stock
1484 if (isModEnabled('stock')) {
1485 print '<td></td>';
1486 }
1487
1488 // Lot / Batch
1489 if (isModEnabled('productbatch')) {
1490 print '<td class="nowraponall">';
1491 if ($tmpproduct->status_batch) {
1492 $preselected = (GETPOSTISSET('batch-'.$line->id.'-'.$i) ? GETPOST('batch-'.$line->id.'-'.$i) : '');
1493 print '<input type="text" class="width75" name="batch-'.$line->id.'-'.$i.'" value="'.$preselected.'" list="batch-'.$line->id.'-'.$i.'">';
1494 print $formproduct->selectLotDataList('batch-'.$line->id.'-'.$i, 0, $line->fk_product, 0, array());
1495 }
1496 print '</td>';
1497 }
1498
1499 // Split
1500 $type = 'batch';
1501 print '<td align="right" class="split">';
1502 print ' '.img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine('.((int) $line->id).', \''.dol_escape_js($type).'\', \'qtymissingconsume\')"');
1503 print '</td>';
1504
1505 // Split All
1506 print '<td align="right" class="splitall">';
1507 if (($action == 'consumeorproduce' || $action == 'consumeandproduceall') && $tmpproduct->status_batch == 2) {
1508 print img_picto($langs->trans('SplitAllQuantity'), 'split.png', 'class="splitbutton splitallbutton field-error-icon" data-max-qty="1" onClick="addDispatchLine('.$line->id.', \'batch\', \'allmissingconsume\')"');
1509 }
1510 print '</td>';
1511
1512 // Edit Line
1513 if ($object->status == Mo::STATUS_DRAFT) {
1514 print '<td></td>';
1515 }
1516
1517 // Action delete line
1518 if ($permissiontodelete) {
1519 print '<td></td>';
1520 }
1521
1522 print '</tr>';
1523 }
1524 }
1525 }
1526 }
1527
1528 print '</table>';
1529 print '</div>';
1530
1531 // default warehouse processing
1532 print '<script type="text/javascript">
1533 $(document).ready(function () {
1534 $("select[name=fk_default_warehouse]").change(function() {
1535 var fk_default_warehouse = $("option:selected", this).val();
1536 $("select[name^=idwarehouse-]").val(fk_default_warehouse).change();
1537 });
1538 });
1539 </script>';
1540
1541 if (in_array($action, array('consumeorproduce', 'consumeandproduceall')) &&
1542 getDolGlobalString('STOCK_CONSUMPTION_FROM_MANUFACTURING_WAREHOUSE')) {
1543 print '<script>$(document).ready(function () {
1544 $("#fk_default_warehouse").change();
1545 });</script>';
1546 }
1547
1548
1549 // Lines to produce
1550
1551 print '</div>';
1552 print '<div class="fichehalfright">';
1553 print '<div class="clearboth"></div>';
1554
1555 $nblinetoproduce = 0;
1556 foreach ($object->lines as $line) {
1557 if ($line->role == 'toproduce') {
1558 $nblinetoproduce++;
1559 }
1560 }
1561
1562 $newcardbutton = '';
1563 $url = $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=addproduceline&token='.newToken();
1564 $permissiontoaddaproductline = $object->status != $object::STATUS_PRODUCED && $object->status != $object::STATUS_CANCELED;
1565 $parameters = array('morecss' => 'reposition');
1566 if ($action != 'consumeorproduce' && $action != 'consumeandproduceall') {
1567 if ($nblinetoproduce == 0 || $object->mrptype == 1) {
1568 $newcardbutton = dolGetButtonTitle($langs->trans('AddNewProduceLines'), '', 'fa fa-plus-circle size15x', $url, '', (int) $permissiontoaddaproductline, $parameters);
1569 }
1570 }
1571
1572 print load_fiche_titre($langs->trans('Production'), $newcardbutton, '', 0, '', '');
1573
1574 print '<div class="div-table-responsive-no-min">';
1575 print '<table id="tablelinestoproduce" class="noborder noshadow nobottom centpercent">';
1576
1577 print '<tr class="liste_titre trheight5em">';
1578 // Product
1579 print '<td>'.$langs->trans("Product").'</td>';
1580 // Qty
1581 print '<td class="right">'.$langs->trans("Qty").'</td>';
1583 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1584 print '<td class="right">'.$langs->trans("Unit").'</td>';
1585 }
1586 // Cost price
1587 if ($permissiontoupdatecost) {
1588 if (empty($bomcostupdated)) {
1589 print '<td class="right classfortooltip" title="'.$langs->trans("AmountUsedToUpdateWAP").'">';
1590 print $langs->trans("UnitCost");
1591 print '</td>';
1592 } else {
1593 print '<td class="right classfortooltip" title="'.$langs->trans("AmountUsedToUpdateWAP").'">';
1594 print $langs->trans("ManufacturingPrice");
1595 print '</td>';
1596 }
1597 }
1598 // Already produced
1599 print '<td class="right classfortooltip" title="'.$langs->trans("QtyAlreadyProduced").'">';
1600 print $langs->trans("QtyAlreadyProducedShort");
1601 print '</td>';
1602 // Warehouse
1603 print '<td>';
1604 if ($collapse || in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
1605 print $langs->trans("Warehouse");
1606 }
1607 print '</td>';
1608
1609 // Lot
1610 if (isModEnabled('productbatch')) {
1611 print '<td>';
1612 if ($collapse || in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
1613 print $langs->trans("Batch");
1614 }
1615 print '</td>';
1616
1617 // Split
1618 print '<td></td>';
1619
1620 // Split All
1621 print '<td></td>';
1622 }
1623
1624 // Action delete
1625 if ($permissiontodelete) {
1626 print '<td></td>';
1627 }
1628
1629 print '</tr>';
1630
1631 if ($action == 'addproduceline') {
1632 print '<!-- Add line to produce -->'."\n";
1633 print '<tr class="liste_titre">';
1634
1635 // Product
1636 print '<td>';
1637 print $form->select_produits(0, 'productidtoadd', '', 0, 0, -1, 2, '', 1, array(), 0, '1', 0, 'maxwidth300');
1638 print '</td>';
1639 // Qty
1640 print '<td class="right"><input type="text" name="qtytoadd" value="1" class="width50 right"></td>';
1641 //Unit
1642 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1643 print '<td></td>';
1644 }
1645 // Cost price
1646 if ($permissiontoupdatecost) {
1647 print '<td></td>';
1648 }
1649 // Action (cost price + already produced)
1650 print '<td colspan="2">';
1651 print '<input type="submit" class="button buttongen button-add" name="addproducelinebutton" value="'.$langs->trans("Add").'">';
1652 print '<input type="submit" class="button buttongen button-cancel" name="canceladdproducelinebutton" value="'.$langs->trans("Cancel").'">';
1653 print '</td>';
1654 // Lot - serial
1655 if (isModEnabled('productbatch')) {
1656 print '<td></td>';
1657
1658 // Split
1659 print '<td></td>';
1660
1661 // Split All
1662 print '<td></td>';
1663 }
1664 // Action delete
1665 if ($permissiontodelete) {
1666 print '<td></td>';
1667 }
1668 print '</tr>';
1669 }
1670
1671 if (!empty($object->lines)) {
1672 $nblinetoproduce = 0;
1673 foreach ($object->lines as $line) {
1674 if ($line->role == 'toproduce') {
1675 $nblinetoproduce++;
1676 }
1677 }
1678
1679 $nblinetoproducecursor = 0;
1680 foreach ($object->lines as $line) {
1681 if ($line->role == 'toproduce') {
1682 $i = 1;
1683
1684 $nblinetoproducecursor++;
1685
1686 $tmpproduct = new Product($db);
1687 $tmpproduct->fetch($line->fk_product);
1688
1689 $arrayoflines = $object->fetchLinesLinked('produced', $line->id);
1690 $alreadyproduced = 0;
1691 foreach ($arrayoflines as $line2) {
1692 $alreadyproduced += $line2['qty'];
1693 }
1694
1695 $suffix = '_'.$line->id;
1696 print '<!-- Line to dispatch '.$suffix.' (toproduce) -->'."\n";
1697 // hidden fields for js function
1698 print '<input id="qty_ordered'.$suffix.'" type="hidden" value="'.$line->qty.'">';
1699 print '<input id="qty_dispatched'.$suffix.'" type="hidden" value="'.$alreadyproduced.'">';
1700
1701 print '<tr>';
1702 // Product
1703 print '<td>'.$tmpproduct->getNomUrl(1);
1704 print '<br><span class="opacitymedium small">'.$tmpproduct->label.'</span>';
1705 print '</td>';
1706 // Qty
1707 print '<td class="right">'.$line->qty.'</td>';
1708 // Unit
1709 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1710 print '<td class="right">'.measuringUnitString($line->fk_unit, '', null, 1).'</td>';
1711 }
1712 // Cost price
1713 if ($permissiontoupdatecost) {
1714 // Defined $manufacturingcost
1715 $manufacturingcost = 0;
1716 $manufacturingcostsrc = '';
1717 if ($object->mrptype == 0) { // If MO is a "Manufacture" type (and not "Disassemble")
1718 $manufacturingcost = $bomcostupdated;
1719 $manufacturingcostsrc = $langs->trans("CalculatedFromProductsToConsume");
1720 if (empty($manufacturingcost)) {
1721 $manufacturingcost = $bomcost;
1722 $manufacturingcostsrc = $langs->trans("ValueFromBom");
1723 }
1724 if (empty($manufacturingcost)) {
1725 $manufacturingcost = price2num($tmpproduct->cost_price, 'MU');
1726 $manufacturingcostsrc = $langs->trans("CostPrice");
1727 }
1728 if (empty($manufacturingcost)) {
1729 $manufacturingcost = price2num($tmpproduct->pmp, 'MU');
1730 $manufacturingcostsrc = $langs->trans("PMPValue");
1731 }
1732 }
1733
1734 print '<td class="right nowraponall" title="'.dol_escape_htmltag($manufacturingcostsrc).'">';
1735 if ($manufacturingcost) {
1736 print price($manufacturingcost);
1737 }
1738 print '</td>';
1739 }
1740 // Already produced
1741 print '<td class="right nowraponall">';
1742 if ($alreadyproduced) {
1743 print '<script>';
1744 print 'jQuery(document).ready(function() {
1745 jQuery("#expandtoproduce'.$line->id.'").click(function() {
1746 console.log("Expand mrp_production line '.$line->id.'");
1747 jQuery(".expanddetailtoproduce'.$line->id.'").toggle();';
1748 if ($nblinetoproduce == $nblinetoproducecursor) {
1749 print 'if (jQuery("#tablelinestoproduce").hasClass("nobottom")) { jQuery("#tablelinestoproduce").removeClass("nobottom"); } else { jQuery("#tablelinestoproduce").addClass("nobottom"); }';
1750 }
1751 print '
1752 });
1753 });';
1754 print '</script>';
1755 if (empty($conf->use_javascript_ajax)) {
1756 print '<a href="'.$_SERVER["PHP_SELF"].'?collapse='.$collapse.','.$line->id.'">';
1757 }
1758 print img_picto($langs->trans("ShowDetails"), "chevron-down", 'id="expandtoproduce'.$line->id.'"');
1759 if (empty($conf->use_javascript_ajax)) {
1760 print '</a>';
1761 }
1762 }
1763 print ' '.$alreadyproduced;
1764 print '</td>';
1765 // Warehouse
1766 print '<td>';
1767 print '</td>';
1768 // Lot
1769 if (isModEnabled('productbatch')) {
1770 print '<td></td>';
1771
1772 // Split
1773 print '<td></td>';
1774
1775 // Split All
1776 print '<td></td>';
1777 }
1778 // Delete, if nothing was produced for this line
1779 if ($permissiontodelete) {
1780 if ($line->origin_type == 'free' && empty($arrayoflines)) {
1781 $href = $_SERVER["PHP_SELF"];
1782 $href .= '?id='.$object->id;
1783 $href .= '&action=deleteline';
1784 $href .= '&token='.newToken();
1785 $href .= '&lineid='.$line->id;
1786 print '<td class="center">';
1787 print '<a class="reposition" href="'.$href.'">';
1788 print img_picto($langs->trans('TooltipDeleteAndRevertStockMovement'), "delete");
1789 print '</a>';
1790 print '</td>';
1791 } else {
1792 print '<td></td>';
1793 }
1794 }
1795 print '</tr>';
1796
1797 // Show detailed of already consumed with js code to collapse
1798 foreach ($arrayoflines as $line2) {
1799 print '<tr class="expanddetailtoproduce'.$line->id.' hideobject opacitylow">';
1800 // Product
1801 print '<td>';
1802 $tmpstockmovement->id = $line2['fk_stock_movement'];
1803 print '<a href="'.DOL_URL_ROOT.'/product/stock/movement_list.php?search_ref='.$tmpstockmovement->id.'">'.img_picto($langs->trans("StockMovement"), 'movement', 'class="paddingright"').'</a>';
1804 print dol_print_date($line2['date'], 'dayhour', 'tzuserrel');
1805 print '</td>';
1806 // Qty
1807 print '<td></td>';
1808 // Unit
1809 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1810 print '<td></td>';
1811 }
1812 // Cost price
1813 if ($permissiontoupdatecost) {
1814 print '<td></td>';
1815 }
1816 // Already produced
1817 print '<td class="right">'.$line2['qty'].'</td>';
1818 // Warehouse
1819 print '<td class="tdoverflowmax150">';
1820 if ($line2['fk_warehouse'] > 0) {
1821 $result = $tmpwarehouse->fetch($line2['fk_warehouse']);
1822 if ($result > 0) {
1823 print $tmpwarehouse->getNomUrl(1);
1824 }
1825 }
1826 print '</td>';
1827 // Lot
1828 if (isModEnabled('productbatch')) {
1829 print '<td>';
1830 if ($line2['batch'] != '') {
1831 $tmpbatch->fetch(0, $line2['fk_product'], $line2['batch']);
1832 print $tmpbatch->getNomUrl(1);
1833 }
1834 print '</td>';
1835
1836 // Split
1837 print '<td></td>';
1838
1839 // Split All
1840 print '<td></td>';
1841 }
1842 // Action delete
1843 if ($permissiontodelete) {
1844 print '<td></td>';
1845 }
1846 print '</tr>';
1847 }
1848
1849 if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
1850 print '<!-- Enter line to produce -->'."\n";
1851 $maxQty = 1;
1852 print '<tr data-max-qty="'.$maxQty.'" name="batch_'.$line->id.'_'.$i.'">';
1853 // Product
1854 print '<td><span class="opacitymedium">'.$langs->trans("ToProduce").'</span></td>';
1855 $preselected = (GETPOSTISSET('qtytoproduce-'.$line->id.'-'.$i) ? GETPOST('qtytoproduce-'.$line->id.'-'.$i) : max(0, $line->qty - $alreadyproduced));
1856 if ($action == 'consumeorproduce' && !GETPOSTISSET('qtytoproduce-'.$line->id.'-'.$i)) {
1857 $preselected = 0;
1858 }
1859 // Qty
1860 print '<td class="right"><input type="text" class="width50 right" id="qtytoproduce-'.$line->id.'-'.$i.'" name="qtytoproduce-'.$line->id.'-'.$i.'" value="'.$preselected.'"></td>';
1861 //Unit
1862 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1863 print '<td class="right"></td>';
1864 }
1865 // Cost
1866 if ($permissiontoupdatecost) {
1867 // Defined $manufacturingcost
1868 $manufacturingcost = 0;
1869 $manufacturingcostsrc = '';
1870 if ($object->mrptype == 0) { // If MO is a "Manufacture" type (and not "Disassemble")
1871 $manufacturingcost = $bomcostupdated;
1872 $manufacturingcostsrc = $langs->trans("CalculatedFromProductsToConsume");
1873 if (empty($manufacturingcost)) {
1874 $manufacturingcost = $bomcost;
1875 $manufacturingcostsrc = $langs->trans("ValueFromBom");
1876 }
1877 if (empty($manufacturingcost)) {
1878 $manufacturingcost = price2num($tmpproduct->cost_price, 'MU');
1879 $manufacturingcostsrc = $langs->trans("CostPrice");
1880 }
1881 if (empty($manufacturingcost)) {
1882 $manufacturingcost = price2num($tmpproduct->pmp, 'MU');
1883 $manufacturingcostsrc = $langs->trans("PMPValue");
1884 }
1885 }
1886
1887 if ($tmpproduct->type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
1888 $preselected = (GETPOSTISSET('pricetoproduce-'.$line->id.'-'.$i) ? GETPOST('pricetoproduce-'.$line->id.'-'.$i) : ($manufacturingcost ? price($manufacturingcost) : ''));
1889 print '<td class="right"><input type="text" class="width75 right" name="pricetoproduce-'.$line->id.'-'.$i.'" value="'.$preselected.'"></td>';
1890 } else {
1891 print '<td><input type="hidden" class="width50 right" name="pricetoproduce-'.$line->id.'-'.$i.'" value="'.($manufacturingcost ? $manufacturingcost : '').'"></td>';
1892 }
1893 }
1894 // Already produced
1895 print '<td></td>';
1896 // Warehouse
1897 print '<td>';
1898 if ($tmpproduct->type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
1899 $preselected = (GETPOSTISSET('idwarehousetoproduce-'.$line->id.'-'.$i) ? GETPOST('idwarehousetoproduce-'.$line->id.'-'.$i) : ($object->fk_warehouse > 0 ? $object->fk_warehouse : 'ifone'));
1900 print $formproduct->selectWarehouses($preselected, 'idwarehousetoproduce-'.$line->id.'-'.$i, '', 1, 0, $line->fk_product, '', 1, 0, array(), 'maxwidth200 csswarehouse_'.$line->id.'_'.$i);
1901 } else {
1902 print '<span class="opacitymedium">'.$langs->trans("NoStockChangeOnServices").'</span>';
1903 }
1904 print '</td>';
1905 // Lot
1906 if (isModEnabled('productbatch')) {
1907 print '<td>';
1908 if ($tmpproduct->status_batch) {
1909 $preselected = (GETPOSTISSET('batchtoproduce-'.$line->id.'-'.$i) ? GETPOST('batchtoproduce-'.$line->id.'-'.$i) : '');
1910 print '<input type="text" class="width75" name="batchtoproduce-'.$line->id.'-'.$i.'" value="'.$preselected.'">';
1911 }
1912 print '</td>';
1913 // Batch number in same column than the stock movement picto
1914 if ($tmpproduct->status_batch) {
1915 $type = 'batch';
1916 print '<td align="right" class="split">';
1917 print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine('.$line->id.', \''.$type.'\', \'qtymissing\')"');
1918 print '</td>';
1919
1920 print '<td align="right" class="splitall">';
1921 if (($action == 'consumeorproduce' || $action == 'consumeandproduceall') && $tmpproduct->status_batch == 2) {
1922 print img_picto($langs->trans('SplitAllQuantity'), 'split.png', 'class="splitbutton splitallbutton field-error-icon" onClick="addDispatchLine('.$line->id.', \'batch\', \'alltoproduce\')"');
1923 } //
1924 print '</td>';
1925 } else {
1926 print '<td></td>';
1927
1928 print '<td></td>';
1929 }
1930 }
1931
1932 // Action delete
1933 print '<td></td>';
1934
1935 print '</tr>';
1936 }
1937 }
1938 }
1939 }
1940
1941 print '</table>';
1942 print '</div>';
1943
1944 print '</div>';
1945 print '</div>';
1946 }
1947
1948 if (in_array($action, array('consumeorproduce', 'consumeandproduceall', 'addconsumeline'))) {
1949 print "</form>\n";
1950 } ?>
1951
1952 <script type="text/javascript" language="javascript">
1953
1954 $(document).ready(function() {
1955 //Consumption : When a warehouse is selected, only the lot/serial numbers that are available in it are offered
1956 updateselectbatchbywarehouse();
1957 //Consumption : When a lot/serial number is selected and it is only available in one warehouse, the warehouse is automatically selected
1958 updateselectwarehousebybatch();
1959 });
1960
1961 function updateselectbatchbywarehouse() {
1962 $(document).on('change', "select[name*='idwarehouse']", function () {
1963 console.log("We change warehouse so we update the list of possible batch number");
1964
1965 var selectwarehouse = $(this);
1966
1967 var selectbatch_name = selectwarehouse.attr('name').replace('idwarehouse', 'batch');
1968 var selectbatch = $("datalist[id*='" + selectbatch_name + "']");
1969 var selectedbatch = selectbatch.val();
1970
1971 var product_element_name = selectwarehouse.attr('name').replace('idwarehouse', 'product');
1972
1973 $.ajax({
1974 type: "POST",
1975 url: "<?php echo DOL_URL_ROOT . '/mrp/ajax/interface.php'; ?>",
1976 data: {
1977 action: "updateselectbatchbywarehouse",
1978 permissiontoproduce: <?php echo $permissiontoproduce ?>,
1979 warehouse_id: $(this).val(),
1980 token: '<?php echo currentToken(); ?>',
1981 product_id: $("input[name='" + product_element_name + "']").val()
1982 }
1983 }).done(function (data) {
1984
1985 selectbatch.empty();
1986
1987 if (typeof data == "object") {
1988 console.log("data is already type object, no need to parse it");
1989 } else {
1990 console.log("data is type "+(typeof data));
1991 data = JSON.parse(data);
1992 }
1993
1994 selectbatch.append($('<option>', {
1995 value: '',
1996 }));
1997
1998 $.each(data, function (key, value) {
1999
2000 if(selectwarehouse.val() == -1) {
2001 var label = key + " (<?php echo $langs->trans('TotalStock') ?> : " + value + ")";
2002 } else {
2003 var label = key + " (<?php echo $langs->trans('Stock') ?> : " + value + ")";
2004 }
2005
2006 if(key === selectedbatch) {
2007 var option ='<option value="'+key+'" selected>'+ label +'</option>';
2008 } else {
2009 var option ='<option value="'+key+'">'+ label +'</option>';
2010 }
2011
2012 selectbatch.append(option);
2013 });
2014 });
2015 });
2016 }
2017
2018 function updateselectwarehousebybatch() {
2019 $(document).on('change', 'input[name*=batch]', function(){
2020 console.log("We change batch so we update the list of possible warehouses");
2021
2022 var selectbatch = $(this);
2023
2024 var selectwarehouse_name = selectbatch.attr('name').replace('batch', 'idwarehouse');
2025 var selectwarehouse = $("select[name*='" + selectwarehouse_name + "']");
2026 var selectedwarehouse = selectwarehouse.val();
2027
2028 if(selectedwarehouse != -1){
2029 return;
2030 }
2031
2032 var product_element_name = selectbatch.attr('name').replace('batch', 'product');
2033
2034 $.ajax({
2035 type: "POST",
2036 url: "<?php echo DOL_URL_ROOT . '/mrp/ajax/interface.php'; ?>",
2037 data: {
2038 action: "updateselectwarehousebybatch",
2039 permissiontoproduce: <?php echo $permissiontoproduce ?>,
2040 batch: $(this).val(),
2041 token: '<?php echo currentToken(); ?>',
2042 product_id: $("input[name='" + product_element_name + "']").val()
2043 }
2044 }).done(function (data) {
2045
2046 if (typeof data == "object") {
2047 console.log("data is already type object, no need to parse it");
2048 } else {
2049 console.log("data is type "+(typeof data));
2050 data = JSON.parse(data);
2051 }
2052
2053 if(data != 0){
2054 selectwarehouse.val(data).change();
2055 }
2056 });
2057 });
2058 }
2059
2060 </script>
2061
2062 <?php
2063}
2064
2065// End of page
2066llxFooter();
2067$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
$object ref
Definition info.php:90
Class for BOM.
Definition bom.class.php:42
Class of dictionary type of thirdparty (used by imports)
Class to manage warehouses.
Class to manage standard extra fields.
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 to manage building of HTML components.
Class for Mo.
Definition mo.class.php:35
Class MoLine.
Class to manage stock movements.
Class to manage predefined suppliers products.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class with list of lots and properties.
Class to manage projects.
Class to manage translations.
Class for Workstation.
convertDurationtoHour($duration_value, $duration_unit)
Convert duration to hour.
Definition date.lib.php:338
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='')
Return the value of a $_GET or $_POST supervariable, converted into float.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
moPrepareHead($object)
Prepare array of tabs for Mo.
measuringUnitString($unitid, $measuring_style='', $unitscale=null, $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:158
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.