31require
'../main.inc.php';
40require_once DOL_DOCUMENT_ROOT.
'/bom/class/bom.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/mrp/class/mo.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/mrp/lib/mrp_mo.lib.php';
46require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/productlot.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/workstation/class/workstation.class.php';
55$langs->loadLangs(array(
"mrp",
"stocks",
"other",
"products",
"productbatch"));
60$action =
GETPOST(
'action',
'aZ09');
61$confirm =
GETPOST(
'confirm',
'alpha');
63$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'mocard';
64$backtopage =
GETPOST(
'backtopage',
'alpha');
67$fk_default_warehouse =
GETPOSTINT(
'fk_default_warehouse');
69$collapse =
GETPOST(
'collapse',
'aZ09comma');
73$diroutputmassaction =
$conf->mrp->dir_output.
'/temp/massgeneration/'.$user->id;
74$objectline =
new MoLine($db);
76$hookmanager->initHooks(array(
'moproduction',
'globalcard'));
79$extrafields->fetch_name_optionals_label(
$object->table_element);
81$search_array_options = $extrafields->getOptionalsFromPost(
$object->table_element,
'',
'search_');
84$search_all =
GETPOST(
"search_all",
'alpha');
86foreach (
$object->fields as $key => $val) {
87 if (
GETPOST(
'search_'.$key,
'alpha')) {
88 $search[$key] =
GETPOST(
'search_'.$key,
'alpha');
92if (empty($action) && empty($id) && empty($ref)) {
97include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
102$isdraft = ((
$object->status == $object::STATUS_DRAFT) ? 1 : 0);
106$permissionnote = $user->hasRight(
'mrp',
'write');
107$permissiondellink = $user->hasRight(
'mrp',
'write');
108$permissiontoadd = $user->hasRight(
'mrp',
'write');
109$permissiontodelete = $user->hasRight(
'mrp',
'delete') || ($permissiontoadd && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT);
111$permissiontoproduce = $permissiontoadd;
112$permissiontoupdatecost = $user->hasRight(
'bom',
'read');
121$parameters = array();
122$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
124 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
127if (empty($reshook)) {
130 $backurlforlist = DOL_URL_ROOT.
'/mrp/mo_list.php';
132 if (empty($backtopage) || ($cancel && empty($id))) {
134 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
135 $backtopage = $backurlforlist;
137 $backtopage = DOL_URL_ROOT.
'/mrp/mo_production.php?id='.(
$id > 0 ?
$id :
'__ID__');
140 $triggermodname =
'MO_MODIFY';
142 if ($action ==
'confirm_cancel' && $confirm ==
'yes' && !empty($permissiontoadd)) {
143 $also_cancel_consumed_and_produced_lines = (
GETPOST(
'alsoCancelConsumedAndProducedLines',
'alpha') ? 1 : 0);
144 $result =
$object->cancel($user, 0, (
bool) $also_cancel_consumed_and_produced_lines);
146 header(
"Location: " . DOL_URL_ROOT.
'/mrp/mo_card.php?id=' .
$object->id);
152 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && !empty($permissiontodelete)) {
153 $also_cancel_consumed_and_produced_lines = (
GETPOST(
'alsoCancelConsumedAndProducedLines',
'alpha') ? 1 : 0);
155 $result =
$object->delete($user, 0, (
bool) $also_cancel_consumed_and_produced_lines);
157 header(
"Location: " . $backurlforlist);
171 if ($action ==
'setqty' && $permissiontoadd &&
$object->status == Mo::STATUS_DRAFT) {
185 foreach (
$object->lines as $line) {
186 if ($line->role ===
'toproduce'
187 && (
int) $line->fk_product === (
int)
$object->fk_product
188 && empty($line->qty_frozen)
189 && (
float) $line->qty != (
float)
$object->qty) {
190 $line->qty = (float)
$object->qty;
191 $line->update($user);
194 setEventMessages($langs->trans(
"RecordSaved"),
null,
'mesgs');
199 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->trans(
"Qty")),
null,
'errors');
201 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
206 include DOL_DOCUMENT_ROOT.
'/core/actions_addupdatedelete.inc.php';
209 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
212 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
215 $triggersendname =
'MO_SENTBYMAIL';
216 $autocopy =
'MAIN_MAIL_AUTOCOPY_MO_TO';
217 $trackid =
'mo'.$object->id;
218 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
223 if ($action ==
'set_thirdparty' && $permissiontoadd) {
224 $object->setValueFrom(
'fk_soc',
GETPOSTINT(
'fk_soc'),
'',
null,
'date',
'', $user, $triggermodname);
226 if ($action ==
'classin' && $permissiontoadd) {
230 if ($action ==
'confirm_reopen' && $permissiontoadd &&
$object->status == $object::STATUS_PRODUCED) {
231 $result =
$object->setStatut($object::STATUS_INPROGRESS, 0,
'',
'MRP_REOPEN');
234 if (($action ==
'confirm_addconsumeline' &&
GETPOST(
'addconsumelinebutton') && $permissiontoadd)
235 || ($action ==
'confirm_addproduceline' &&
GETPOST(
'addproducelinebutton') && $permissiontoadd)) {
236 $moline =
new MoLine($db);
241 $moline->fk_product =
GETPOSTINT(
'productidtoadd');
242 if (
GETPOST(
'addconsumelinebutton')) {
243 $moline->role =
'toconsume';
245 $moline->role =
'toproduce';
247 $moline->origin_type =
'free';
248 $moline->position = 0;
251 if (!empty($moline->fk_product)) {
252 $tmpproduct =
new Product($db);
253 $tmpproduct->fetch($moline->fk_product);
255 $moline->fk_default_workstation = $tmpproduct->fk_default_workstation;
256 $moline->disable_stock_change = 1;
257 if ($tmpproduct->duration_unit) {
258 $moline->qty = $tmpproduct->duration_value;
259 include_once DOL_DOCUMENT_ROOT.
'/core/class/cunits.class.php';
260 $cunits =
new CUnits($db);
261 $res = $cunits->fetch(0,
'', $tmpproduct->duration_unit,
'time');
263 $moline->fk_unit = $cunits->id;
267 $moline->disable_stock_change = 0;
269 $moline->fk_unit = $tmpproduct->fk_unit;
274 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
275 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
277 if (is_array($extralabelsline)) {
279 foreach ($extralabelsline as $key => $value) {
280 unset($_POST[
"options_".$key]);
283 if (is_array($array_options) && count($array_options) > 0) {
284 $moline->array_options = $array_options;
287 $resultline = $moline->create($user, 0);
288 if ($resultline <= 0) {
290 setEventMessages($moline->error, $moline->errors,
'errors');
295 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
300 if (in_array($action, array(
'confirm_consumeorproduce',
'confirm_consumeandproduceall')) &&
$object->status != $object::STATUS_VALIDATED &&
$object->status != $object::STATUS_INPROGRESS) {
301 $langs->load(
"errors");
302 setEventMessages($langs->trans(
"ErrorObjectHasWrongStatus",
$object->ref),
null,
'errors');
306 if (in_array($action, array(
'confirm_consumeorproduce',
'confirm_consumeandproduceall')) && $permissiontoproduce) {
309 $labelmovement =
GETPOST(
'inventorylabel',
'alphanohtml');
310 $codemovement =
GETPOST(
'inventorycode',
'alphanohtml');
315 foreach (
$object->lines as $line) {
316 if ($line->role ==
'toconsume') {
317 $tmpproduct =
new Product($db);
318 $tmpproduct->fetch($line->fk_product);
324 if ($qtytoprocess != 0) {
327 if (!(
GETPOST(
'idwarehouse-'.$line->id.
'-'.$i) > 0)) {
328 $langs->load(
"errors");
329 setEventMessages($langs->trans(
"ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv(
"Warehouse"), (
string) $tmpproduct->ref),
null,
'errors');
332 if (
isModEnabled(
'productbatch') && $tmpproduct->status_batch && (!
GETPOST(
'batch-'.$line->id.
'-'.$i))) {
333 $langs->load(
"errors");
334 setEventMessages($langs->trans(
"ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv(
"Batch"), (
string) $tmpproduct->ref),
null,
'errors');
340 if (!$error &&
GETPOST(
'idwarehouse-'.$line->id.
'-'.$i) > 0) {
342 $id_product_batch = 0;
344 $stockmove->context[
'mrp_role'] =
'toconsume';
346 if ($qtytoprocess >= 0) {
347 $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);
349 $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);
351 if ($idstockmove < 0) {
353 setEventMessages($stockmove->error, $stockmove->errors,
'errors');
359 $moline =
new MoLine($db);
361 $moline->position = $pos;
362 $moline->fk_product = $line->fk_product;
363 $moline->fk_warehouse =
GETPOSTINT(
'idwarehouse-'.$line->id.
'-'.$i);
364 $moline->qty = $qtytoprocess;
365 $moline->batch =
GETPOST(
'batch-'.$line->id.
'-'.$i);
366 $moline->role =
'consumed';
367 $moline->fk_mrp_production = $line->id;
368 $moline->fk_stock_movement = $idstockmove == 0 ? null : $idstockmove;
369 $moline->fk_user_creat = $user->id;
371 $resultmoline = $moline->create($user);
372 if ($resultmoline <= 0) {
374 setEventMessages($moline->error, $moline->errors,
'errors');
389 foreach (
$object->lines as $line) {
390 if ($line->role ==
'toproduce') {
391 $tmpproduct =
new Product($db);
392 $tmpproduct->fetch($line->fk_product);
395 while (
GETPOSTISSET(
'qtytoproduce-'.$line->id.
'-'.$i)) {
396 $qtytoprocess = (float)
price2num(
GETPOST(
'qtytoproduce-'.$line->id.
'-'.$i));
397 $pricetoprocess =
GETPOST(
'pricetoproduce-'.$line->id.
'-'.$i) ?
price2num(
GETPOST(
'pricetoproduce-'.$line->id.
'-'.$i)) : 0;
399 if ($qtytoprocess != 0) {
401 if (
GETPOSTISSET(
'idwarehousetoproduce-'.$line->id.
'-'.$i)) {
402 if (!(
GETPOST(
'idwarehousetoproduce-'.$line->id.
'-'.$i) > 0)) {
403 $langs->load(
"errors");
404 setEventMessages($langs->trans(
"ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv(
"Warehouse"), $tmpproduct->ref),
null,
'errors');
407 if (
isModEnabled(
'productbatch') && $tmpproduct->status_batch && (!
GETPOST(
'batchtoproduce-'.$line->id.
'-'.$i))) {
408 $langs->load(
"errors");
409 setEventMessages($langs->trans(
"ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv(
"Batch"), $tmpproduct->ref),
null,
'errors');
415 if (!$error &&
GETPOST(
'idwarehousetoproduce-'.$line->id.
'-'.$i) > 0) {
417 $id_product_batch = 0;
418 $stockmove->origin_type =
$object->element;
419 $stockmove->origin_id =
$object->id;
420 $stockmove->context[
'mrp_role'] =
'toproduce';
422 $idstockmove = $stockmove->reception($user, $line->fk_product,
GETPOSTINT(
'idwarehousetoproduce-'.$line->id.
'-'.$i), $qtytoprocess, $pricetoprocess, $labelmovement,
GETPOSTDATE(
'eatby-'.$line->id.
'-'.$i),
GETPOSTDATE(
'sellby-'.$line->id.
'-'.$i),
GETPOST(
'batchtoproduce-'.$line->id.
'-'.$i),
dol_now(), $id_product_batch, $codemovement);
423 if ($idstockmove < 0) {
425 setEventMessages($stockmove->error, $stockmove->errors,
'errors');
431 $moline =
new MoLine($db);
433 $moline->position = $pos;
434 $moline->fk_product = $line->fk_product;
435 $moline->fk_warehouse =
GETPOSTINT(
'idwarehousetoproduce-'.$line->id.
'-'.$i);
436 $moline->qty = $qtytoprocess;
437 $moline->batch =
GETPOST(
'batchtoproduce-'.$line->id.
'-'.$i);
438 $moline->role =
'produced';
439 $moline->fk_mrp_production = $line->id;
440 $moline->fk_stock_movement = (($idstockmove == 0) ?
null : $idstockmove);
441 $moline->fk_user_creat = $user->id;
443 $resultmoline = $moline->create($user);
444 if ($resultmoline <= 0) {
446 setEventMessages($moline->error, $moline->errors,
'errors');
459 $consumptioncomplete =
true;
460 $productioncomplete =
true;
463 foreach (
$object->lines as $line) {
464 $tmpproduct =
new Product($db);
465 $tmpproduct->fetch($line->fk_product);
466 if ((
int) $tmpproduct->stockable_product > 0) {
467 if ($line->role ==
'toconsume') {
468 $arrayoflines =
$object->fetchLinesLinked(
'consumed', $line->id);
469 $alreadyconsumed = 0;
470 foreach ($arrayoflines as $line2) {
471 $alreadyconsumed += $line2[
'qty'];
474 if ($alreadyconsumed < $line->qty) {
475 $consumptioncomplete =
false;
478 if ($line->role ==
'toproduce') {
479 $arrayoflines =
$object->fetchLinesLinked(
'produced', $line->id);
480 $alreadyproduced = 0;
481 foreach ($arrayoflines as $line2) {
482 $alreadyproduced += $line2[
'qty'];
485 if ($alreadyproduced < $line->qty) {
486 $productioncomplete =
false;
492 $consumptioncomplete =
false;
493 $productioncomplete =
false;
497 dol_syslog(
"consumptioncomplete = ".json_encode($consumptioncomplete).
" productioncomplete = ".json_encode($productioncomplete));
498 if ($consumptioncomplete && $productioncomplete) {
499 $result =
$object->setStatut($object::STATUS_PRODUCED, 0,
'',
'MRP_MO_PRODUCED');
501 $result =
$object->setStatut($object::STATUS_INPROGRESS, 0,
'',
'MRP_MO_PRODUCED');
510 $action = str_replace(
'confirm_',
'', $action);
516 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
522 if ($action ==
'confirm_produced' && $confirm ==
'yes' && $permissiontoadd) {
523 $result =
$object->setStatut($object::STATUS_PRODUCED, 0,
'',
'MRP_MO_PRODUCED');
527 $outputlangs = $langs;
530 $newlang =
GETPOST(
'lang_id',
'aZ09');
533 $newlang =
$object->thirdparty->default_lang;
535 if (!empty($newlang)) {
537 $outputlangs->setDefaultLang($newlang);
542 $object->generateDocument($model, $outputlangs, 0, 0, 0);
549 if ($action ==
'confirm_editline' && $permissiontoadd && !in_array(
$object->status, array($object::STATUS_PRODUCED, $object::STATUS_CANCELED))) {
550 $moline =
new MoLine($db);
551 $result = $moline->fetch(
GETPOSTINT(
'lineid'));
552 if ($result > 0 && $moline->fk_mo !=
$object->id) {
555 if ($result > 0 && in_array($moline->role, array(
'consumed',
'produced'))) {
559 $extrafields->fetch_name_optionals_label($moline->table_element);
560 if (!empty($extrafields->attributes[$moline->table_element][
'label'])) {
561 foreach ($extrafields->attributes[$moline->table_element][
'label'] as $key => $label) {
562 $value =
GETPOST(
'options_'.$key,
'alphanohtml');
563 $moline->array_options[
"options_".$key] = $value;
568 $moline->fk_warehouse = (
GETPOSTINT(
'warehouse_lineProduce') > 0 ?
GETPOSTINT(
'warehouse_lineProduce') : 0);
571 $moline->fk_default_workstation = (
GETPOSTINT(
'workstation_lineProduce') > 0 ?
GETPOSTINT(
'workstation_lineProduce') : 0);
574 $res = $moline->update($user);
577 setEventMessages($moline->error, $moline->errors,
'errors');
578 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
581 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
593$form =
new Form($db);
600$title = $langs->trans(
'Mo');
601$help_url =
'EN:Module_Manufacturing_Orders|FR:Module_Ordres_de_Fabrication|DE:Modul_Fertigungsauftrag';
602$morejs = array(
'/mrp/js/lib_dispatch.js.php');
603llxHeader(
'', $title, $help_url,
'', 0, 0, $morejs,
'',
'',
'mod-mrp page-card_production');
608if (
$object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create' && $action !=
'reload'))) {
609 $res =
$object->fetch_thirdparty();
610 $res =
$object->fetch_optionals();
613 $tmpwarehouse->fetch((
int)
$object->fk_warehouse);
614 $fk_default_warehouse = (int)
$object->fk_warehouse;
624 if ($action ==
'delete') {
625 $formquestion = array(
627 'label' => $langs->trans(
'MoCancelConsumedAndProducedLines'),
628 'name' =>
'alsoCancelConsumedAndProducedLines',
629 'type' =>
'checkbox',
633 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'DeleteMo'), $langs->trans(
'ConfirmDeleteMo'),
'confirm_delete', $formquestion, 0, 1);
636 if ($action ==
'deleteline') {
637 $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);
640 if ($action ==
'clone') {
642 $formquestion = array();
643 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneMo',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
647 if ($action ==
'validate') {
649 $ref = substr(
$object->ref, 1, 4);
650 if ($ref ==
'PROV') {
654 $numref = (string)
$object->ref;
657 $text = $langs->trans(
'ConfirmValidateMo', $numref);
666 $formquestion = array();
669 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
672 if (
$conf->browser->name ==
'ie') {
675 $formquestion = array(
682 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'Validate'), $text,
'confirm_validate', $formquestion, 0, 1, 220);
686 if ($action ==
'cancel') {
687 $formquestion = array(
689 'label' => $langs->trans(
'MoCancelConsumedAndProducedLines'),
690 'name' =>
'alsoCancelConsumedAndProducedLines',
691 'type' =>
'checkbox',
692 'value' => !
getDolGlobalString(
'MO_ALSO_CANCEL_CONSUMED_AND_PRODUCED_LINES_BY_DEFAULT') ? 0 : 1
695 $formconfirm = $form->formconfirm(
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' =>
$object->id]), $langs->trans(
'CancelMo'), $langs->trans(
'ConfirmCancelMo'),
'confirm_cancel', $formquestion, 0, 1);
699 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
700 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
701 if (empty($reshook)) {
702 $formconfirm .= $hookmanager->resPrint;
703 } elseif ($reshook > 0) {
704 $formconfirm = $hookmanager->resPrint;
713 $linkback =
'<a href="'.DOL_URL_ROOT.
'/mrp/mo_list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
715 $morehtmlref =
'<div class="refidno">';
724 if (is_object(
$object->thirdparty)) {
725 $morehtmlref .=
$object->thirdparty->getNomUrl(1,
'customer');
727 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/commande/list.php?socid='.
$object->thirdparty->id.
'">'.$langs->trans(
"OtherOrders").
'</a>)';
733 $langs->load(
"projects");
734 if (is_object(
$object->thirdparty)) {
735 $morehtmlref .=
'<br>';
737 if ($permissiontoadd) {
738 $morehtmlref .= img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
739 if ($action !=
'classify') {
740 $morehtmlref .=
'<a class="editfielda" href="'.dolBuildUrl($_SERVER[
'PHP_SELF'], [
'action' =>
'classify',
'id' =>
$object->id],
true).
'">'.img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
742 $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');
744 if (!empty(
$object->fk_project)) {
746 $proj->fetch(
$object->fk_project);
747 $morehtmlref .= $proj->getNomUrl(1);
749 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
754 $morehtmlref .=
'</div>';
757 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
760 print
'<div class="fichecenter">';
761 print
'<div class="fichehalfleft">';
762 print
'<div class="underbanner clearboth"></div>';
763 print
'<table class="border centpercent tableforfield">'.
"\n";
766 $keyforbreak =
'fk_warehouse';
767 unset(
$object->fields[
'fk_project']);
768 unset(
$object->fields[
'fk_soc']);
774 if (
$object->status == Mo::STATUS_DRAFT && $permissiontoadd && isset(
$object->fields[
'qty'])) {
775 $object->fields[
'qty'][
'alwayseditable'] = 1;
776 if ($action ==
'editqty') {
777 $object->fields[
'qty'][
'type'] =
'numeric';
781 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_view.tpl.php';
784 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
790 print
'<div class="clearboth"></div>';
795 if (!in_array($action, array(
'consumeorproduce',
'consumeandproduceall',
'editline'))) {
796 print
'<div class="tabsAction">';
798 $parameters = array();
800 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
801 if (empty($reshook)) {
803 if (
$object->status == $object::STATUS_DRAFT) {
804 if ($permissiontoadd) {
806 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=validate&token='.$newToken.
'">'.$langs->trans(
"Validate").
'</a>';
808 $langs->load(
"errors");
809 print
'<a class="butActionRefused" href="" title="'.$langs->trans(
"ErrorAddAtLeastOneLineFirst").
'">'.$langs->trans(
"Validate").
'</a>';
815 if (
$object->status == Mo::STATUS_VALIDATED ||
$object->status == Mo::STATUS_INPROGRESS) {
816 if ($permissiontoproduce) {
817 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=consumeorproduce&token='.$newToken.
'">'.$langs->trans(
'ConsumeOrProduce').
'</a>';
819 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
'ConsumeOrProduce').
'</a>';
821 } elseif (
$object->status == Mo::STATUS_DRAFT) {
822 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"ValidateBefore").
'">'.$langs->trans(
'ConsumeOrProduce').
'</a>';
826 if (
$object->status == Mo::STATUS_VALIDATED ||
$object->status == Mo::STATUS_INPROGRESS) {
827 if ($permissiontoproduce) {
828 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=consumeandproduceall&token='.$newToken.
'">'.$langs->trans(
'ConsumeAndProduceAll').
'</a>';
830 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
'ConsumeAndProduceAll').
'</a>';
832 } elseif (
$object->status == Mo::STATUS_DRAFT) {
833 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"ValidateBefore").
'">'.$langs->trans(
'ConsumeAndProduceAll').
'</a>';
837 if ($permissiontoadd) {
838 if (
$object->status == $object::STATUS_VALIDATED ||
$object->status == $object::STATUS_INPROGRESS) {
839 $arrayproduced =
$object->fetchLinesLinked(
'produced', 0);
841 foreach ($arrayproduced as $lineproduced) {
842 $nbProduced += $lineproduced[
'qty'];
844 if ($nbProduced > 0) {
845 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=confirm_produced&confirm=yes&token='.$newToken.
'">'.$langs->trans(
"Close").
'</a>'.
"\n";
847 print
'<a class="butActionRefused" href="#" title="'.$langs->trans(
"GoOnTabProductionToProduceFirst", $langs->transnoentitiesnoconv(
"Production")).
'">'.$langs->trans(
"Close").
'</a>'.
"\n";
850 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=cancel&token='.$newToken.
'">'.$langs->trans(
"Cancel").
'</a>'.
"\n";
853 if (
$object->status == $object::STATUS_CANCELED) {
854 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=confirm_reopen&confirm=yes&token='.$newToken.
'">'.$langs->trans(
"ReOpen").
'</a>'.
"\n";
857 if (
$object->status == $object::STATUS_PRODUCED) {
858 if ($permissiontoproduce) {
859 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=confirm_reopen&token='.$newToken.
'">'.$langs->trans(
'ReOpen').
'</a>';
861 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
'ReOpen').
'</a>';
870 if (in_array($action, array(
'consumeorproduce',
'consumeandproduceall',
'addconsumeline',
'addproduceline',
'editline'))) {
871 print
'<!-- Form to enter value for consumption/production -->';
872 print
'<form method="POST" action="'.dolBuildUrl($_SERVER[
"PHP_SELF"]).
'">';
873 print
'<input type="hidden" name="token" value="'.newToken().
'">';
874 print
'<input type="hidden" name="action" value="confirm_'.$action.
'">';
875 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
876 print
'<input type="hidden" name="id" value="'.$id.
'">';
879 if (in_array($action, array(
'consumeorproduce',
'consumeandproduceall'))) {
880 $defaultstockmovementlabel =
GETPOST(
'inventorylabel',
'alphanohtml') ?
GETPOST(
'inventorylabel',
'alphanohtml') : $langs->trans(
"ProductionForRef",
$object->
ref);
883 print
'<div class="center'.(in_array($action, array(
'consumeorproduce',
'consumeandproduceall')) ?
' formconsumeproduce' :
'').
'">';
884 print
'<div class="opacitymedium hideonsmartphone paddingbottom marginbottomonly">'.$langs->trans(
"ConfirmProductionDesc", $langs->transnoentitiesnoconv(
"Confirm")).
'<br></div>';
885 print
'<span class="paddingright">'.$langs->trans(
"InventoryCode").
':</span>';
886 print
'<span class="clearbothonsmartphone"></span>';
887 print
'<input type="text" class="minwidth125 maxwidth150" name="inventorycode" value="'.$defaultstockmovementcode.
'">';
888 print
'<span class="hideonsmartphone"> </span>';
889 print
'<span class="clearbothonsmartphone"></span>';
890 print
'<span class="paddingright">'.$langs->trans(
"MovementLabel").
':</span>';
891 print
'<span class="clearbothonsmartphone"></span>';
892 print
'<input type="text" class="minwidth300" name="inventorylabel" value="'.$defaultstockmovementlabel.
'"><br><br>';
893 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>';
894 print
'<input type="submit" class="button margintoponly" value="'.$langs->trans(
"Confirm").
'" name="confirm">';
896 print
'<input class="button margintoponly button-cancel" type="submit" value="'.$langs->trans(
"Cancel").
'" name="cancel">';
910 if (!empty(
$object->table_element_line)) {
917 $res = $bom->fetch(
$object->fk_bom);
919 $bom->calculateCosts();
920 $bomcost = $bom->unit_cost;
926 print
'<!-- Lines to consume -->'.
"\n";
927 print
'<div class="fichecenter">';
928 print
'<div class="fichehalfleft">';
929 print
'<div class="clearboth"></div>';
931 $url = $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=addconsumeline&token='.
newToken();
932 $permissiontoaddaconsumeline = (
$object->status != $object::STATUS_PRODUCED &&
$object->status != $object::STATUS_CANCELED) ? 1 : -2;
933 $parameters = array(
'morecss' =>
'reposition');
935 if ($permissiontoaddaconsumeline == -2) {
936 $helpText = $langs->trans(
'MOIsClosed');
940 if ($action !=
'consumeorproduce' && $action !=
'consumeandproduceall') {
941 $newcardbutton =
dolGetButtonTitle($langs->trans(
'AddNewConsumeLines'), $helpText,
'fa fa-plus-circle size15x', $url,
'', $permissiontoaddaconsumeline, $parameters);
944 print
load_fiche_titre($langs->trans(
'Consumption'), $newcardbutton,
'', 0,
'',
'',
'');
946 print
'<div class="div-table-responsive-no-min">';
947 print
'<table class="noborder noshadow centpercent nobottom">';
949 print
'<!-- Line of title for products to consume -->'.
"\n";
950 print
'<tr class="liste_titre trheight5em">';
952 print
'<td>'.$langs->trans(
"Product").
'</td>';
954 print
'<td class="right">'.$langs->trans(
"Qty").
'</td>';
959 print
'<td class="right">'.$langs->trans(
"UnitCost").
'</td>';
962 print
'<td class="right classfortooltip" title="'.$langs->trans(
"QtyAlreadyConsumed").
'">';
963 print $langs->trans(
"QtyAlreadyConsumedShort");
967 if ($collapse || in_array($action, array(
'consumeorproduce',
'consumeandproduceall'))) {
968 print $langs->trans(
"Warehouse");
970 print
' '.$langs->trans(
"or").
' '.$langs->trans(
"Workstation");
973 if (in_array($action, array(
'consumeorproduce',
'consumeandproduceall'))) {
974 $listwarehouses = $tmpwarehouse->list_array(1);
975 if (count($listwarehouses) > 1) {
976 print
'<br>'.$form->selectarray(
'fk_default_warehouse', $listwarehouses, $fk_default_warehouse, $langs->trans(
"ForceTo"), 0, 0,
'', 0, 0, 0,
'',
'minwidth100 maxwidth200', 1);
977 } elseif (count($listwarehouses) == 1) {
978 print
'<br>'.$form->selectarray(
'fk_default_warehouse', $listwarehouses, $fk_default_warehouse, 0, 0, 0,
'', 0, 0, 0,
'',
'minwidth100 maxwidth200', 1);
986 print
'<td align="right">';
987 if ($collapse || in_array($action, array(
'consumeorproduce',
'consumeandproduceall'))) {
988 print $langs->trans(
"Stock");
995 if ($collapse || in_array($action, array(
'consumeorproduce',
'consumeandproduceall'))) {
996 print $langs->trans(
"Batch");
1008 if (
$object->status == Mo::STATUS_DRAFT) {
1013 if ($permissiontodelete) {
1019 if ($action ==
'addconsumeline') {
1020 print
'<!-- Add line to consume -->'.
"\n";
1021 print
'<tr class="liste_titre">';
1024 print $form->select_produits(0,
'productidtoadd',
'', 0, 0, -1, 2,
'', 1, array(), 0,
'1', 0,
'maxwidth150');
1027 print
'<td class="right"><input type="text" name="qtytoadd" value="1" class="width40 right"></td>';
1035 if ($permissiontoupdatecost &&
getDolGlobalString(
'MRP_SHOW_COST_FOR_CONSUMPTION')) {
1047 print
'<td colspan="'.$colspan.
'">';
1048 print
'<input type="submit" class="button buttongen button-add" name="addconsumelinebutton" value="'.$langs->trans(
"Add").
'">';
1049 print
'<input type="submit" class="button buttongen button-cancel" name="canceladdconsumelinebutton" value="'.$langs->trans(
"Cancel").
'">';
1054 if (
$object->status == Mo::STATUS_DRAFT) {
1058 if ($permissiontodelete) {
1064 if (is_object($objectline)) {
1065 $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1066 $temps = $objectline->showOptionals($extrafields,
'edit', array(),
'',
'',
'1',
'line');
1067 if (!empty($temps)) {
1068 print
'<tr class="liste_titre"><td style="padding-top: 20px" colspan="9" id="extrafield_lines_area_edit" name="extrafield_lines_area_edit">';
1077 $bomcostupdated = 0;
1080 $nblinetoconsume = 0;
1081 foreach (
$object->lines as $line) {
1082 if ($line->role ==
'toconsume') {
1087 $nblinetoconsumecursor = 0;
1088 foreach (
$object->lines as $line) {
1089 if ($line->role ==
'toconsume') {
1090 $nblinetoconsumecursor++;
1092 $tmpproduct =
new Product($db);
1093 $tmpproduct->fetch($line->fk_product);
1094 $linecost =
price2num($tmpproduct->pmp,
'MT');
1098 $costprice =
price2num((!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp);
1099 if (empty($costprice)) {
1100 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
1102 if ($productFournisseur->find_min_price_product_fournisseur($line->fk_product, $line->qty) > 0) {
1103 $costprice = $productFournisseur->fourn_unitprice;
1111 if ($useunit && $line->fk_unit > 0) {
1113 $qtyhourservice = 0;
1114 if (preg_match(
'/^(\d+)([a-z]+)$/', $tmpproduct->duration, $reg)) {
1117 $qtyhourforline = 0;
1118 if ($line->fk_unit) {
1124 if (
isModEnabled(
'workstation') && $line->fk_default_workstation > 0) {
1126 $workstation->fetch($line->fk_default_workstation);
1127 $linecost =
price2num($qtyhourforline * ($workstation->thm_operator_estimated + $workstation->thm_machine_estimated) /
$object->qty,
'MT');
1128 $bomcostupdated +=
price2num($qtyhourforline * ($workstation->thm_operator_estimated + $workstation->thm_machine_estimated) /
$object->qty,
'MU');
1129 } elseif ($qtyhourservice && $qtyhourforline) {
1130 $linecost =
price2num(($qtyhourforline / $qtyhourservice * $costprice) /
$object->qty,
'MT');
1131 $bomcostupdated +=
price2num(($qtyhourforline / $qtyhourservice * $costprice) /
$object->qty,
'MU');
1134 $bomcostupdated +=
price2num(($line->qty * $costprice) /
$object->qty,
'MU');
1138 $bomcostupdated +=
price2num(($line->qty * $costprice) /
$object->qty,
'MU');
1142 $bomcostupdated =
price2num($bomcostupdated,
'MU');
1143 $arrayoflines =
$object->fetchLinesLinked(
'consumed', $line->id);
1144 $alreadyconsumed = 0;
1145 foreach ($arrayoflines as $line2) {
1146 $alreadyconsumed += $line2[
'qty'];
1149 if ($action ==
'editline' && $lineid == $line->id) {
1150 $linecost =
price2num($tmpproduct->pmp,
'MT');
1152 $arrayoflines =
$object->fetchLinesLinked(
'consumed', $line->id);
1153 $alreadyconsumed = 0;
1154 if (is_array($arrayoflines) && !empty($arrayoflines)) {
1155 foreach ($arrayoflines as $line2) {
1156 $alreadyconsumed += $line2[
'qty'];
1159 $suffix =
'_' . $line->id;
1160 print
'<!-- Line to dispatch ' . $suffix .
' (line edited) -->' .
"\n";
1162 print
'<input id="qty_ordered' . $suffix .
'" type="hidden" value="' . $line->qty .
'">';
1164 print
'<input id="qty_dispatched' . $suffix .
'" type="hidden" value="' . $alreadyconsumed .
'">';
1166 print
'<input name="lineid" type="hidden" value="' . $line->id .
'">';
1169 print
'<td>' . $tmpproduct->getNomUrl(1);
1170 print
'<br><div class="opacitymedium small tdoverflowmax150" title="' .
dol_escape_htmltag($tmpproduct->label) .
'">' . $tmpproduct->label .
'</span>';
1174 print
'<td class="right nowraponall">';
1175 print
'<input class="width40 right" name="qty_lineProduce" value="'. $line->qty.
'">';
1179 print
'<td class="right nowraponall">';
1187 if ($permissiontoupdatecost &&
getDolGlobalString(
'MRP_SHOW_COST_FOR_CONSUMPTION')) {
1192 print
'<td class="right">';
1193 print
' ' .
price2num($alreadyconsumed,
'MS');
1199 print $formproduct->selectWarehouses($line->fk_warehouse,
'warehouse_lineProduce',
'warehouseopen', 1);
1201 print $formproduct->selectWorkstations($line->fk_default_workstation,
'workstation_lineProduce', 1);
1207 print
'<td class="nowraponall right">';
1208 if ($tmpproduct->isStockManaged()) {
1209 if ($tmpproduct->stock_reel < ($line->qty - $alreadyconsumed)) {
1210 print img_warning($langs->trans(
'StockTooLow')).
' ';
1212 print
'<span class="left">'. $tmpproduct->stock_reel .
' </span>';
1222 print
'<td colspan="'.(3 + (
$object->status == Mo::STATUS_DRAFT ? 1 : 0) + ($permissiontodelete ? 1 : 0)).
'">';
1223 print
'<input type="submit" class="button buttongen button-add small nominwidth" name="save" value="' . $langs->trans(
"Save") .
'">';
1224 print
'<input type="submit" class="button buttongen button-cancel small nominwidth" name="cancel" value="' . $langs->trans(
"Cancel") .
'">';
1230 if (!empty($extrafields)) {
1231 $line->fetch_optionals();
1232 $temps = $line->showOptionals($extrafields,
'edit', array(),
'',
'',
'1',
'line');
1233 if (!empty($temps)) {
1235 print
'<tr><td colspan="'.$colspan.
'"><div style="padding-top: 20px" id="extrafield_lines_area_edit" name="extrafield_lines_area_edit">';
1237 print
'</div></td></tr>';
1241 $suffix =
'_' . $line->id;
1242 print
'<!-- Line to dispatch ' . $suffix .
' -->' .
"\n";
1244 print
'<input id="qty_ordered' . $suffix .
'" type="hidden" value="' . $line->qty .
'">';
1245 print
'<input id="qty_dispatched' . $suffix .
'" type="hidden" value="' . $alreadyconsumed .
'">';
1247 print
'<tr data-line-id="' . $line->id .
'">';
1250 print
'<td>' . $tmpproduct->getNomUrl(1);
1251 print
'<br><div class="opacitymedium small tdoverflowmax150" title="' .
dol_escape_htmltag($tmpproduct->label) .
'">' . $tmpproduct->label .
'</div>';
1255 print
'<td class="right nowraponall">';
1257 if ($line->qty_frozen) {
1258 $help = ($help ?
'<br>' :
'') .
'<strong>' . $langs->trans(
"QuantityFrozen") .
'</strong>: ' . yn(1) .
' (' . $langs->trans(
"QuantityConsumedInvariable") .
')';
1259 print $form->textwithpicto(
'', $help, -1,
'lock') .
' ';
1261 if ($line->disable_stock_change) {
1262 $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")) .
')';
1263 print $form->textwithpicto(
'', $help, -1,
'help') .
' ';
1269 print
'<td class="right nowraponall">';
1277 if ($permissiontoupdatecost &&
getDolGlobalString(
'MRP_SHOW_COST_FOR_CONSUMPTION')) {
1278 print
'<td class="right nowraponall">';
1279 print
price($linecost);
1284 print
'<td class="right">';
1285 if ($alreadyconsumed) {
1287 print
'jQuery(document).ready(function() {
1288 jQuery("#expandtoproduce' . $line->id .
'").click(function() {
1289 console.log("Expand mrp_production line ' . $line->id .
'");
1290 jQuery(".expanddetail' . $line->id .
'").toggle();';
1291 if ($nblinetoconsume == $nblinetoconsumecursor) {
1292 print
'if (jQuery("#tablelines").hasClass("nobottom")) { jQuery("#tablelines").removeClass("nobottom"); } else { jQuery("#tablelines").addClass("nobottom"); }';
1298 if (empty(
$conf->use_javascript_ajax)) {
1299 print
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?collapse=' . $collapse .
',' . $line->id .
'">';
1301 print img_picto($langs->trans(
"ShowDetails"),
"chevron-down",
'id="expandtoproduce' . $line->id .
'"');
1302 if (empty(
$conf->use_javascript_ajax)) {
1306 if ($nblinetoconsume == $nblinetoconsumecursor) {
1307 print
'<script>jQuery("#tablelines").removeClass("nobottom");</script>';
1310 print
' ' .
price2num($alreadyconsumed,
'MS');
1314 print
'<td class="tdoverflowmax100">';
1315 if ($tmpproduct->isStockManaged()) {
1317 if (
getDolGlobalString(
'STOCK_CONSUMPTION_FROM_MANUFACTURING_WAREHOUSE') && $tmpwarehouse->id > 0) {
1318 print img_picto(
'', $tmpwarehouse->picto) .
" " . $tmpwarehouse->label;
1320 if ($line->fk_warehouse > 0) {
1321 $warehouseline =
new Entrepot($db);
1322 $warehouseline->fetch($line->fk_warehouse);
1323 print $warehouseline->getNomUrl(1);
1327 if (
isModEnabled(
'workstation') && $line->fk_default_workstation > 0) {
1329 $tmpworkstation->fetch($line->fk_default_workstation);
1330 print $tmpworkstation->getNomUrl(1);
1336 print
'<td class="nowraponall right">';
1338 if (!$line->disable_stock_change && $tmpproduct->stock_reel < ($line->qty - $alreadyconsumed)) {
1339 print img_warning($langs->trans(
'StockTooLow')) .
' ';
1341 if (!
getDolGlobalString(
'STOCK_CONSUMPTION_FROM_MANUFACTURING_WAREHOUSE') || empty($tmpwarehouse->id)) {
1342 print
price2num($tmpproduct->stock_reel,
'MS');
1345 $tmpproduct->load_stock();
1346 $wh_stock = $tmpproduct->stock_warehouse[$tmpwarehouse->id];
1347 if (!empty($wh_stock)) {
1369 if (
$object->status == Mo::STATUS_DRAFT) {
1370 $href = $_SERVER[
"PHP_SELF"] .
'?id=' . ((int)
$object->id) .
'&action=editline&token=' .
newToken() .
'&lineid=' . ((int) $line->id);
1371 print
'<td class="center">';
1372 print
'<a class="reposition editfielda" href="' . $href .
'">';
1373 print img_picto($langs->trans(
'TooltipEditAndRevertStockMovement'),
'edit');
1379 if ($permissiontodelete && empty($arrayoflines)) {
1380 $href = $_SERVER[
"PHP_SELF"] .
'?id=' . ((int)
$object->id) .
'&action=deleteline&token=' .
newToken() .
'&lineid=' . ((int) $line->id);
1381 print
'<td class="center">';
1382 print
'<a class="reposition" href="' . $href .
'">';
1383 print img_picto($langs->trans(
'TooltipDeleteAndRevertStockMovement'),
'delete');
1391 if (!empty($extrafields)) {
1392 $line->fetch_optionals();
1393 $temps = $line->showOptionals($extrafields,
'view', array(),
'',
'',
'1',
'line');
1394 if (!empty($temps)) {
1396 print
'<tr><td colspan="'.$colspan.
'"><div id="extrafield_lines_area_'.$line->id.
'" name="extrafield_lines_area_'.$line->id.
'">';
1398 print
'</div></td></tr>';
1404 foreach ($arrayoflines as $line2) {
1405 print
'<tr class="expanddetail'.$line->id.
' hideobject opacitylow">';
1409 $tmpstockmovement->id = $line2[
'fk_stock_movement'];
1410 print
'<a href="'.DOL_URL_ROOT.
'/product/stock/movement_list.php?search_ref='.$tmpstockmovement->id.
'">'.img_picto($langs->trans(
"StockMovement"),
'movement',
'class="paddingright"').
'</a>';
1421 if ($permissiontoupdatecost &&
getDolGlobalString(
'MRP_SHOW_COST_FOR_CONSUMPTION')) {
1426 print
'<td class="right">'.$line2[
'qty'].
'</td>';
1429 print
'<td class="tdoverflowmax150">';
1430 if ($line2[
'fk_warehouse'] > 0) {
1431 $result = $tmpwarehouse->fetch($line2[
'fk_warehouse']);
1433 print $tmpwarehouse->getNomUrl(1);
1446 if ($line2[
'batch'] !=
'') {
1447 $tmpbatch->fetch(0, $line2[
'fk_product'], $line2[
'batch']);
1448 print $tmpbatch->getNomUrl(1);
1460 if (
$object->status == Mo::STATUS_DRAFT) {
1461 $href = $_SERVER[
"PHP_SELF"] .
'?id=' . ((int)
$object->id) .
'&action=editline&token=' .
newToken() .
'&lineid=' . ((int) $line2[
'rowid']);
1462 print
'<td class="center">';
1463 print
'<a class="reposition" href="' . $href .
'">';
1464 print img_picto($langs->trans(
'TooltipEditAndRevertStockMovement'),
'edit');
1470 if ($permissiontodelete) {
1471 $href = $_SERVER[
"PHP_SELF"].
'?id='.((int)
$object->id).
'&action=deleteline&token='.
newToken().
'&lineid='.((int) $line2[
'rowid']).
'&fk_movement='.((int) $line2[
'fk_stock_movement']);
1472 print
'<td class="center">';
1473 print
'<a class="reposition" href="'.$href.
'">';
1474 print img_picto($langs->trans(
'TooltipDeleteAndRevertStockMovement'),
'delete');
1482 if (in_array($action, array(
'consumeorproduce',
'consumeandproduceall'))) {
1484 print
'<!-- Enter line to consume -->'.
"\n";
1486 print
'<tr data-max-qty="'.$maxQty.
'" name="batch_'.$line->id.
'_'.$i.
'">';
1488 print
'<td><span class="opacitymedium">'.$langs->trans(
"ToConsume").
'</span></td>';
1489 $preselected = (
GETPOSTISSET(
'qty-'.$line->id.
'-'.$i) ?
GETPOST(
'qty-'.$line->id.
'-'.$i) : max(0, $line->qty - $alreadyconsumed));
1490 if ($action ==
'consumeorproduce' && !
getDolGlobalString(
'MRP_AUTO_SET_REMAINING_QUANTITIES_TO_BE_CONSUMED') && !
GETPOSTISSET(
'qty-'.$line->id.
'-'.$i)) {
1495 if (
getDolGlobalString(
'MRP_NEVER_CONSUME_MORE_THAN_EXPECTED') && ($line->qty - $alreadyconsumed) <= 0) {
1496 $disable =
'disabled';
1500 print
'<input type="hidden" name="product-'.$line->id.
'-'.$i.
'" value="'.$line->fk_product.
'">';
1503 print
'<td class="right">';
1504 if ((
int) $tmpproduct->stockable_product > 0) {
1505 print
'<input type="text" class="width50 right" id="qtytoconsume-' . $line->id .
'-' . $i .
'" name="qty-' . $line->id .
'-' . $i .
'" value="' . $preselected .
'" ' . $disable .
'>';
1507 print
'<input type="hidden" id="qtytoconsume-' . $line->id .
'-' . $i .
'" name="qty-' . $line->id .
'-' . $i .
'" value="0">';
1508 print
'<span class="opacitymedium">' . $langs->trans(
"StockDisabled") .
'</span>';
1516 if ($permissiontoupdatecost &&
getDolGlobalString(
'MRP_SHOW_COST_FOR_CONSUMPTION')) {
1526 && ((
int) $tmpproduct->stockable_product > 0)) {
1527 if (empty($line->disable_stock_change)) {
1528 $preselected = (
GETPOSTISSET(
'idwarehouse-'.$line->id.
'-'.$i) ?
GETPOST(
'idwarehouse-'.$line->id.
'-'.$i) : ($tmpproduct->fk_default_warehouse > 0 ? $tmpproduct->fk_default_warehouse :
'ifone'));
1529 print $formproduct->selectWarehouses($preselected,
'idwarehouse-'.$line->id.
'-'.$i,
'', 1, 0, $line->fk_product,
'', 1, 0, array(),
'maxwidth200 csswarehouse_'.$line->id.
'_'.$i);
1531 print
'<span class="opacitymedium">'.$langs->trans(
"DisableStockChange").
'</span>';
1534 if ((
int) $tmpproduct->stockable_product > 0) {
1535 print
'<span class="opacitymedium">' . $langs->trans(
"StockDisabled") .
'</span>';
1537 print
'<span class="opacitymedium">' . $langs->trans(
"NoStockChangeOnServices") .
'</span>';
1549 print
'<td class="nowraponall">';
1550 if ($tmpproduct->status_batch) {
1551 $preselected = (
GETPOSTISSET(
'batch-'.$line->id.
'-'.$i) ?
GETPOST(
'batch-'.$line->id.
'-'.$i) :
'');
1552 print
'<input type="text" class="width75" name="batch-'.$line->id.
'-'.$i.
'" value="'.$preselected.
'" list="batch-'.$line->id.
'-'.$i.
'">';
1553 print $formproduct->selectLotDataList(
'batch-'.$line->id.
'-'.$i, 0, $line->fk_product, 0, array());
1560 print
'<td align="right" class="split">';
1561 print
' '.img_picto($langs->trans(
'AddStockLocationLine'),
'split',
'class="splitbutton" onClick="addDispatchLine('.((int) $line->id).
', \''.
dol_escape_js($type).
'\', \
'qtymissingconsume\', 1)"');
1565 print
'<td align="right" class="splitall">';
1566 if (($action ==
'consumeorproduce' || $action ==
'consumeandproduceall') && $tmpproduct->status_batch == 2) {
1567 print img_picto($langs->trans(
'SplitAllQuantity'),
'split',
'class="splitbutton splitallbutton field-error-icon" data-max-qty="1" onClick="addDispatchLine('.$line->id.
', \'batch\', \'allmissingconsume\', 1)"');
1572 if (
$object->status == Mo::STATUS_DRAFT) {
1577 if ($permissiontodelete) {
1591 print
'<script type="text/javascript">
1592 $(document).ready(function () {
1593 $("select[name=fk_default_warehouse]").change(function() {
1594 var fk_default_warehouse = $("option:selected", this).val();
1595 $("select[name^=idwarehouse-]").val(fk_default_warehouse).change();
1600 if (in_array($action, array(
'consumeorproduce',
'consumeandproduceall')) &&
1602 print
'<script>$(document).ready(function () {
1603 $("#fk_default_warehouse").change();
1611 print
'<div class="fichehalfright">';
1612 print
'<div class="clearboth"></div>';
1614 $nblinetoproduce = 0;
1615 $atLeastOneEatBy =
false;
1616 $atLeastOneSellBy =
false;
1617 foreach (
$object->lines as $line) {
1618 if ($line->role ==
'toproduce') {
1619 $tmpproduct =
new Product($db);
1620 $tmpproduct->fetch($line->fk_product);
1622 $tmpproduct->sell_or_eat_by_mandatory == $tmpproduct::SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY
1623 || $tmpproduct->sell_or_eat_by_mandatory == $tmpproduct::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT
1625 $atLeastOneEatBy =
true;
1628 $tmpproduct->sell_or_eat_by_mandatory == $tmpproduct::SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY
1629 || $tmpproduct->sell_or_eat_by_mandatory == $tmpproduct::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT
1631 $atLeastOneSellBy =
true;
1637 $newcardbutton =
'';
1638 $url = $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=addproduceline&token='.
newToken();
1639 $permissiontoaddaproductline =
$object->status != $object::STATUS_PRODUCED &&
$object->status != $object::STATUS_CANCELED;
1640 $parameters = array(
'morecss' =>
'reposition');
1641 if ($action !=
'consumeorproduce' && $action !=
'consumeandproduceall') {
1642 if ($nblinetoproduce == 0 ||
$object->mrptype == 1) {
1643 $newcardbutton =
dolGetButtonTitle($langs->trans(
'AddNewProduceLines'),
'',
'fa fa-plus-circle size15x', $url,
'', (
int) $permissiontoaddaproductline, $parameters);
1647 print
load_fiche_titre($langs->trans(
'Production'), $newcardbutton,
'', 0,
'',
'');
1649 print
'<div class="div-table-responsive-no-min">';
1650 print
'<table id="tablelinestoproduce" class="noborder noshadow nobottom centpercent">';
1652 print
'<tr class="liste_titre trheight5em">';
1654 print
'<td>'.$langs->trans(
"Product").
'</td>';
1656 print
'<td class="right">'.$langs->trans(
"Qty").
'</td>';
1659 print
'<td class="right">'.$langs->trans(
"Unit").
'</td>';
1662 if ($permissiontoupdatecost) {
1663 if (empty($bomcostupdated)) {
1664 print
'<td class="right classfortooltip" title="'.$langs->trans(
"AmountUsedToUpdateWAP").
'">';
1665 print $langs->trans(
"UnitCost");
1668 print
'<td class="right classfortooltip" title="'.$langs->trans(
"AmountUsedToUpdateWAP").
'">';
1669 print $langs->trans(
"ManufacturingPrice");
1674 print
'<td class="right classfortooltip" title="'.$langs->trans(
"QtyAlreadyProduced").
'">';
1675 print $langs->trans(
"QtyAlreadyProducedShort");
1679 if ($collapse || in_array($action, array(
'consumeorproduce',
'consumeandproduceall'))) {
1680 print $langs->trans(
"Warehouse");
1687 if ($collapse || in_array($action, array(
'consumeorproduce',
'consumeandproduceall'))) {
1688 print $langs->trans(
"Batch");
1699 if ($atLeastOneEatBy) {
1700 print
'<td>'.$langs->trans(
"EatByDate").
'</td>';
1704 if ($atLeastOneSellBy) {
1705 print
'<td>'.$langs->trans(
"SellByDate").
'</td>';
1710 if ($permissiontodelete) {
1716 if ($action ==
'addproduceline') {
1717 print
'<!-- Add line to produce -->'.
"\n";
1718 print
'<tr class="liste_titre">';
1722 print $form->select_produits(0,
'productidtoadd',
'', 0, 0, -1, 2,
'', 1, array(), 0,
'1', 0,
'maxwidth300');
1725 print
'<td class="right"><input type="text" name="qtytoadd" value="1" class="width50 right"></td>';
1731 if ($permissiontoupdatecost) {
1735 print
'<td colspan="2">';
1736 print
'<input type="submit" class="button buttongen button-add" name="addproducelinebutton" value="'.$langs->trans(
"Add").
'">';
1737 print
'<input type="submit" class="button buttongen button-cancel" name="canceladdproducelinebutton" value="'.$langs->trans(
"Cancel").
'">';
1750 if ($permissiontodelete) {
1757 $nblinetoproduce = 0;
1758 foreach (
$object->lines as $line) {
1759 if ($line->role ==
'toproduce') {
1764 $nblinetoproducecursor = 0;
1765 foreach (
$object->lines as $line) {
1766 if ($line->role ==
'toproduce') {
1769 $nblinetoproducecursor++;
1771 $tmpproduct =
new Product($db);
1772 $tmpproduct->fetch($line->fk_product);
1774 $arrayoflines =
$object->fetchLinesLinked(
'produced', $line->id);
1775 $alreadyproduced = 0;
1776 foreach ($arrayoflines as $line2) {
1777 $alreadyproduced += $line2[
'qty'];
1780 $suffix =
'_'.$line->id;
1781 print
'<!-- Line to dispatch '.$suffix.
' (toproduce) -->'.
"\n";
1783 print
'<input id="qty_ordered'.$suffix.
'" type="hidden" value="'.$line->qty.
'">';
1784 print
'<input id="qty_dispatched'.$suffix.
'" type="hidden" value="'.$alreadyproduced.
'">';
1788 print
'<td>'.$tmpproduct->getNomUrl(1);
1789 print
'<br><span class="opacitymedium small">'.$tmpproduct->label.
'</span>';
1792 print
'<td class="right">'.$line->qty.
'</td>';
1795 print
'<td class="right">'.measuringUnitString($line->fk_unit,
'',
null, 1).
'</td>';
1798 if ($permissiontoupdatecost) {
1800 $manufacturingcost = 0;
1801 $manufacturingcostsrc =
'';
1803 $manufacturingcost = $bomcostupdated;
1804 $manufacturingcostsrc = $langs->trans(
"CalculatedFromProductsToConsume");
1805 if (empty($manufacturingcost)) {
1806 $manufacturingcost = $bomcost;
1807 $manufacturingcostsrc = $langs->trans(
"ValueFromBom");
1809 if (empty($manufacturingcost)) {
1810 $manufacturingcost =
price2num($tmpproduct->cost_price,
'MU');
1811 $manufacturingcostsrc = $langs->trans(
"CostPrice");
1813 if (empty($manufacturingcost)) {
1814 $manufacturingcost =
price2num($tmpproduct->pmp,
'MU');
1815 $manufacturingcostsrc = $langs->trans(
"PMPValue");
1819 print
'<td class="right nowraponall" title="'.dol_escape_htmltag($manufacturingcostsrc).
'">';
1820 if ($manufacturingcost) {
1821 print
price($manufacturingcost);
1826 print
'<td class="right nowraponall">';
1827 if ($alreadyproduced) {
1829 print
'jQuery(document).ready(function() {
1830 jQuery("#expandtoproduce'.$line->id.
'").click(function() {
1831 console.log("Expand mrp_production line '.$line->id.
'");
1832 jQuery(".expanddetailtoproduce'.$line->id.
'").toggle();';
1833 if ($nblinetoproduce == $nblinetoproducecursor) {
1834 print
'if (jQuery("#tablelinestoproduce").hasClass("nobottom")) { jQuery("#tablelinestoproduce").removeClass("nobottom"); } else { jQuery("#tablelinestoproduce").addClass("nobottom"); }';
1840 if (empty(
$conf->use_javascript_ajax)) {
1841 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?collapse='.$collapse.
','.$line->id.
'">';
1843 print img_picto($langs->trans(
"ShowDetails"),
"chevron-down",
'id="expandtoproduce'.$line->id.
'"');
1844 if (empty(
$conf->use_javascript_ajax)) {
1848 print
' '.$alreadyproduced;
1864 if ($permissiontodelete) {
1865 if ($line->origin_type ==
'free' && empty($arrayoflines)) {
1866 $href = $_SERVER[
"PHP_SELF"];
1867 $href .=
'?id='.$object->id;
1868 $href .=
'&action=deleteline';
1869 $href .=
'&token='.newToken();
1870 $href .=
'&lineid='.$line->id;
1871 print
'<td class="center">';
1872 print
'<a class="reposition" href="'.$href.
'">';
1873 print img_picto($langs->trans(
'TooltipDeleteAndRevertStockMovement'),
"delete");
1883 foreach ($arrayoflines as $line2) {
1884 print
'<tr class="expanddetailtoproduce'.$line->id.
' hideobject opacitylow">';
1887 $tmpstockmovement->id = $line2[
'fk_stock_movement'];
1888 print
'<a href="'.DOL_URL_ROOT.
'/product/stock/movement_list.php?search_ref='.$tmpstockmovement->id.
'">'.img_picto($langs->trans(
"StockMovement"),
'movement',
'class="paddingright"').
'</a>';
1898 if ($permissiontoupdatecost) {
1902 print
'<td class="right">'.$line2[
'qty'].
'</td>';
1904 print
'<td class="tdoverflowmax150">';
1905 if ($line2[
'fk_warehouse'] > 0) {
1906 $result = $tmpwarehouse->fetch($line2[
'fk_warehouse']);
1908 print $tmpwarehouse->getNomUrl(1);
1915 if ($line2[
'batch'] !=
'') {
1916 $tmpbatch->fetch(0, $line2[
'fk_product'], $line2[
'batch']);
1917 print $tmpbatch->getNomUrl(1);
1928 if ($permissiontodelete) {
1934 if (in_array($action, array(
'consumeorproduce',
'consumeandproduceall'))) {
1935 print
'<!-- Enter line to produce -->'.
"\n";
1937 print
'<tr data-max-qty="'.$maxQty.
'" name="batch_'.$line->id.
'_'.$i.
'">';
1939 print
'<td><span class="opacitymedium">'.$langs->trans(
"ToProduce").
'</span></td>';
1940 $preselected = (
GETPOSTISSET(
'qtytoproduce-'.$line->id.
'-'.$i) ?
GETPOST(
'qtytoproduce-'.$line->id.
'-'.$i) : max(0, $line->qty - $alreadyproduced));
1941 if ($action ==
'consumeorproduce' && !
GETPOSTISSET(
'qtytoproduce-'.$line->id.
'-'.$i)) {
1945 print
'<td class="right"><input type="text" class="width50 right" id="qtytoproduce-'.$line->id.
'-'.$i.
'" name="qtytoproduce-'.$line->id.
'-'.$i.
'" value="'.$preselected.
'"></td>';
1948 print
'<td class="right"></td>';
1951 if ($permissiontoupdatecost) {
1953 $manufacturingcost = 0;
1954 $manufacturingcostsrc =
'';
1956 $manufacturingcost = $bomcostupdated;
1957 $manufacturingcostsrc = $langs->trans(
"CalculatedFromProductsToConsume");
1958 if (empty($manufacturingcost)) {
1959 $manufacturingcost = $bomcost;
1960 $manufacturingcostsrc = $langs->trans(
"ValueFromBom");
1962 if (empty($manufacturingcost)) {
1963 $manufacturingcost =
price2num($tmpproduct->cost_price,
'MU');
1964 $manufacturingcostsrc = $langs->trans(
"CostPrice");
1966 if (empty($manufacturingcost)) {
1967 $manufacturingcost =
price2num($tmpproduct->pmp,
'MU');
1968 $manufacturingcostsrc = $langs->trans(
"PMPValue");
1973 $preselected = (
GETPOSTISSET(
'pricetoproduce-'.$line->id.
'-'.$i) ?
GETPOST(
'pricetoproduce-'.$line->id.
'-'.$i) : ($manufacturingcost ?
price($manufacturingcost) :
''));
1974 print
'<td class="right"><input type="text" class="width75 right" name="pricetoproduce-'.$line->id.
'-'.$i.
'" value="'.$preselected.
'"></td>';
1976 print
'<td><input type="hidden" class="width50 right" name="pricetoproduce-'.$line->id.
'-'.$i.
'" value="'.($manufacturingcost ? $manufacturingcost :
'').
'"></td>';
1984 $preselected = (
GETPOSTISSET(
'idwarehousetoproduce-'.$line->id.
'-'.$i) ?
GETPOST(
'idwarehousetoproduce-'.$line->id.
'-'.$i) : (
$object->fk_warehouse > 0 ?
$object->fk_warehouse :
'ifone'));
1985 print $formproduct->selectWarehouses($preselected,
'idwarehousetoproduce-'.$line->id.
'-'.$i,
'', 1, 0, $line->fk_product,
'', 1, 0, array(),
'maxwidth200 csswarehouse_'.$line->id.
'_'.$i);
1987 print
'<span class="opacitymedium">'.$langs->trans(
"NoStockChangeOnServices").
'</span>';
1993 if ($tmpproduct->status_batch) {
1994 $preselected = (
GETPOSTISSET(
'batchtoproduce-'.$line->id.
'-'.$i) ?
GETPOST(
'batchtoproduce-'.$line->id.
'-'.$i) :
'');
1995 print
'<input type="text" class="width75" name="batchtoproduce-'.$line->id.
'-'.$i.
'" value="'.$preselected.
'">';
1999 if ($tmpproduct->status_batch) {
2001 print
'<td align="right" class="split">';
2002 print img_picto($langs->trans(
'AddStockLocationLine'),
'split',
'class="splitbutton" onClick="addDispatchLine('.$line->id.
', \''.$type.
'\', \
'qtymissing\')"');
2005 print
'<td align="right" class="splitall">';
2006 if (($action ==
'consumeorproduce' || $action ==
'consumeandproduceall') && $tmpproduct->status_batch == 2) {
2007 print img_picto($langs->trans(
'SplitAllQuantity'),
'split',
'class="splitbutton splitallbutton field-error-icon" onClick="addDispatchLine('.$line->id.
', \'batch\', \'alltoproduce\')"');
2018 if ($tmpproduct->sell_or_eat_by_mandatory == $tmpproduct::SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY || $tmpproduct->sell_or_eat_by_mandatory == $tmpproduct::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT) {
2019 print
'<td align="right">';
2020 $preselectedSellBy = (
GETPOSTISSET(
'sellby-' . $line->id .
'-' . $i) ?
GETPOSTDATE(
'sellby-' . $line->id .
'-' . $i) :
'');
2021 print $form->selectDate($preselectedSellBy,
'sellby-' . $line->id .
'-' . $i, 0, 0, 1,
'', 1, 0);
2024 if ($atLeastOneSellBy) {
2030 if ($tmpproduct->sell_or_eat_by_mandatory == $tmpproduct::SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY || $tmpproduct->sell_or_eat_by_mandatory == $tmpproduct::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT) {
2031 print
'<td align="right">';
2032 $preselectedEatBy = (
GETPOSTISSET(
'eatby-' . $line->id .
'-' . $i) ?
GETPOSTDATE(
'eatby-' . $line->id .
'-' . $i) :
'');
2033 print $form->selectDate($preselectedEatBy,
'eatby-' . $line->id .
'-' . $i, 0, 0, 1,
'', 1, 0);
2036 if ($atLeastOneEatBy) {
2057 if (in_array($action, array(
'consumeorproduce',
'consumeandproduceall',
'addconsumeline'))) {
2061 <script
type=
"text/javascript">
2063 $(document).ready(
function() {
2065 updateselectbatchbywarehouse();
2067 updateselectwarehousebybatch();
2070 function updateselectbatchbywarehouse() {
2071 $(document).on(
'change',
"select[name*='idwarehouse']",
function () {
2072 console.log(
"We change warehouse so we update the list of possible batch number");
2074 var selectwarehouse = $(
this);
2076 var selectbatch_name = selectwarehouse.attr(
'name').replace(
'idwarehouse',
'batch');
2077 var selectbatch = $(
"datalist[id*='" + selectbatch_name +
"']");
2078 var selectedbatch = selectbatch.val();
2080 var product_element_name = selectwarehouse.attr(
'name').replace(
'idwarehouse',
'product');
2084 url:
"<?php echo DOL_URL_ROOT . '/mrp/ajax/interface.php'; ?>",
2086 action:
"updateselectbatchbywarehouse",
2087 permissiontoproduce: <?php echo $permissiontoproduce ?>,
2088 warehouse_id: $(
this).val(),
2089 token:
'<?php echo currentToken(); ?>',
2090 product_id: $(
"input[name='" + product_element_name +
"']").val()
2092 }).done(
function (data) {
2094 selectbatch.empty();
2096 if (typeof data ==
"object") {
2097 console.log(
"data is already type object, no need to parse it");
2099 console.log(
"data is type "+(typeof data));
2100 data = JSON.parse(data);
2103 selectbatch.append($(
'<option>', {
2107 $.each(data,
function (key, value) {
2109 if(selectwarehouse.val() == -1) {
2110 var label = key +
" (<?php echo $langs->trans('TotalStock') ?> : " + value +
")";
2112 var label = key +
" (<?php echo $langs->trans('Stock') ?> : " + value +
")";
2115 if(key === selectedbatch) {
2116 var option =
'<option value="'+key+
'" selected>'+ label +
'</option>';
2118 var option =
'<option value="'+key+
'">'+ label +
'</option>';
2121 selectbatch.append(option);
2127 function updateselectwarehousebybatch() {
2128 $(document).on(
'change',
'input[name*=batch]',
function(){
2129 console.log(
"We change batch so we update the list of possible warehouses");
2131 var selectbatch = $(
this);
2133 var selectwarehouse_name = selectbatch.attr(
'name').replace(
'batch',
'idwarehouse');
2134 var selectwarehouse = $(
"select[name*='" + selectwarehouse_name +
"']");
2135 var selectedwarehouse = selectwarehouse.val();
2137 if(selectedwarehouse != -1){
2141 var product_element_name = selectbatch.attr(
'name').replace(
'batch',
'product');
2145 url:
"<?php echo DOL_URL_ROOT . '/mrp/ajax/interface.php'; ?>",
2147 action:
"updateselectwarehousebybatch",
2148 permissiontoproduce: <?php echo $permissiontoproduce ?>,
2149 batch: $(
this).val(),
2150 token:
'<?php echo currentToken(); ?>',
2151 product_id: $(
"input[name='" + product_element_name +
"']").val()
2153 }).done(
function (data) {
2155 if (typeof data ==
"object") {
2156 console.log(
"data is already type object, no need to parse it");
2158 console.log(
"data is type "+(typeof data));
2159 data = JSON.parse(data);
2163 selectwarehouse.val(data).change();
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class of dictionary type of thirdparty (used by imports)
Class to manage warehouses.
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.
convertDurationtoHour($duration_value, $duration_unit)
Convert duration to hour.
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 '.
GETPOSTDATE($prefix, $hourTime='', $gm='auto', $saverestore='')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
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.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
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.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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.
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
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.
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.