27require
'../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/productlot.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
43$langs->loadLangs(array(
"mrp",
"stocks",
"other",
"product",
"productbatch"));
48$action =
GETPOST(
'action',
'aZ09');
49$confirm =
GETPOST(
'confirm',
'alpha');
50$cancel =
GETPOST(
'cancel',
'aZ09');
51$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'mocard';
52$backtopage =
GETPOST(
'backtopage',
'alpha');
53$lineid =
GETPOST(
'lineid',
'int');
54$fk_movement =
GETPOST(
'fk_movement',
'int');
55$fk_default_warehouse =
GETPOST(
'fk_default_warehouse',
'int');
57$collapse =
GETPOST(
'collapse',
'aZ09comma');
62$diroutputmassaction = $conf->mrp->dir_output.
'/temp/massgeneration/'.$user->id;
63$hookmanager->initHooks(array(
'moproduction',
'globalcard'));
66$extrafields->fetch_name_optionals_label($object->table_element);
68$search_array_options = $extrafields->getOptionalsFromPost($object->table_element,
'',
'search_');
71$search_all =
GETPOST(
"search_all",
'alpha');
73foreach ($object->fields as $key => $val) {
74 if (
GETPOST(
'search_'.$key,
'alpha')) {
75 $search[$key] =
GETPOST(
'search_'.$key,
'alpha');
79if (empty($action) && empty($id) && empty($ref)) {
84include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
89$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
90$result =
restrictedArea($user,
'mrp', $object->id,
'mrp_mo',
'',
'fk_soc',
'rowid', $isdraft);
92$permissionnote = $user->rights->mrp->write;
93$permissiondellink = $user->rights->mrp->write;
94$permissiontoadd = $user->rights->mrp->write;
95$permissiontodelete = $user->rights->mrp->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
96$upload_dir = $conf->mrp->multidir_output[isset($object->entity) ? $object->entity : 1];
98$permissiontoproduce = $permissiontoadd;
99$permissiontoupdatecost = $user->hasRight(
'bom',
'read');
106$parameters = array();
107$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
112if (empty($reshook)) {
117 if (empty($backtopage) || ($cancel && empty($id))) {
119 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
120 $backtopage = $backurlforlist;
122 $backtopage = DOL_URL_ROOT.
'/mrp/mo_production.php?id='.($id > 0 ? $id :
'__ID__');
125 $triggermodname =
'MO_MODIFY';
128 include DOL_DOCUMENT_ROOT.
'/core/actions_addupdatedelete.inc.php';
131 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
134 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
137 $triggersendname =
'MO_SENTBYMAIL';
138 $autocopy =
'MAIN_MAIL_AUTOCOPY_MO_TO';
139 $trackid =
'mo'.$object->id;
140 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
145 if ($action ==
'set_thirdparty' && $permissiontoadd) {
146 $object->setValueFrom(
'fk_soc',
GETPOST(
'fk_soc',
'int'),
'',
'',
'date',
'', $user, $triggermodname);
148 if ($action ==
'classin' && $permissiontoadd) {
149 $object->setProject(
GETPOST(
'projectid',
'int'));
152 if ($action ==
'confirm_reopen' && $permissiontoadd) {
153 $result = $object->setStatut($object::STATUS_INPROGRESS, 0,
'',
'MRP_REOPEN');
156 if (($action ==
'confirm_addconsumeline' &&
GETPOST(
'addconsumelinebutton') && $permissiontoadd)
157 || ($action ==
'confirm_addproduceline' &&
GETPOST(
'addproducelinebutton') && $permissiontoadd)) {
158 $moline =
new MoLine($db);
161 $moline->fk_mo = $object->id;
162 $moline->qty =
GETPOST(
'qtytoadd',
'int');
163 $moline->fk_product =
GETPOST(
'productidtoadd',
'int');
164 if (
GETPOST(
'addconsumelinebutton')) {
165 $moline->role =
'toconsume';
167 $moline->role =
'toproduce';
169 $moline->origin_type =
'free';
170 $moline->position = 0;
173 if (!empty($moline->fk_product)) {
174 $tmpproduct =
new Product($db);
175 $tmpproduct->fetch($moline->fk_product);
177 $moline->fk_default_workstation = $tmpproduct->fk_default_workstation;
182 $resultline = $moline->create($user,
false);
183 if ($resultline <= 0) {
190 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
194 if (in_array($action, array(
'confirm_consumeorproduce',
'confirm_consumeandproduceall')) && $permissiontoproduce) {
197 $labelmovement =
GETPOST(
'inventorylabel',
'alphanohtml');
198 $codemovement =
GETPOST(
'inventorycode',
'alphanohtml');
203 foreach ($object->lines as $line) {
204 if ($line->role ==
'toconsume') {
205 $tmpproduct =
new Product($db);
206 $tmpproduct->fetch($line->fk_product);
209 while (GETPOSTISSET(
'qty-'.$line->id.
'-'.$i)) {
212 if ($qtytoprocess != 0) {
214 if (GETPOSTISSET(
'idwarehouse-'.$line->id.
'-'.$i)) {
215 if (!(
GETPOST(
'idwarehouse-'.$line->id.
'-'.$i) > 0)) {
216 $langs->load(
"errors");
217 setEventMessages($langs->trans(
"ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv(
"Warehouse"), $tmpproduct->ref),
null,
'errors');
220 if ($tmpproduct->status_batch && (!
GETPOST(
'batch-'.$line->id.
'-'.$i))) {
221 $langs->load(
"errors");
222 setEventMessages($langs->trans(
"ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv(
"Batch"), $tmpproduct->ref),
null,
'errors');
228 if (!$error &&
GETPOST(
'idwarehouse-'.$line->id.
'-'.$i) > 0) {
230 $id_product_batch = 0;
231 $stockmove->setOrigin($object->element, $object->id);
233 if ($qtytoprocess >= 0) {
234 $idstockmove = $stockmove->livraison($user, $line->fk_product,
GETPOST(
'idwarehouse-'.$line->id.
'-'.$i), $qtytoprocess, 0, $labelmovement,
dol_now(),
'',
'',
GETPOST(
'batch-'.$line->id.
'-'.$i), $id_product_batch, $codemovement);
236 $idstockmove = $stockmove->reception($user, $line->fk_product,
GETPOST(
'idwarehouse-'.$line->id.
'-'.$i), $qtytoprocess * -1, 0, $labelmovement,
dol_now(),
'',
'',
GETPOST(
'batch-'.$line->id.
'-'.$i), $id_product_batch, $codemovement);
238 if ($idstockmove < 0) {
246 $moline =
new MoLine($db);
247 $moline->fk_mo = $object->id;
248 $moline->position = $pos;
249 $moline->fk_product = $line->fk_product;
250 $moline->fk_warehouse =
GETPOST(
'idwarehouse-'.$line->id.
'-'.$i);
251 $moline->qty = $qtytoprocess;
252 $moline->batch =
GETPOST(
'batch-'.$line->id.
'-'.$i);
253 $moline->role =
'consumed';
254 $moline->fk_mrp_production = $line->id;
255 $moline->fk_stock_movement = $idstockmove == 0 ? null : $idstockmove;
256 $moline->fk_user_creat = $user->id;
258 $resultmoline = $moline->create($user);
259 if ($resultmoline <= 0) {
276 foreach ($object->lines as $line) {
277 if ($line->role ==
'toproduce') {
278 $tmpproduct =
new Product($db);
279 $tmpproduct->fetch($line->fk_product);
282 while (GETPOSTISSET(
'qtytoproduce-'.$line->id.
'-'.$i)) {
284 $pricetoprocess =
GETPOST(
'pricetoproduce-'.$line->id.
'-'.$i) ?
price2num(
GETPOST(
'pricetoproduce-'.$line->id.
'-'.$i)) : 0;
286 if ($qtytoprocess != 0) {
288 if (GETPOSTISSET(
'idwarehousetoproduce-'.$line->id.
'-'.$i)) {
289 if (!(
GETPOST(
'idwarehousetoproduce-'.$line->id.
'-'.$i) > 0)) {
290 $langs->load(
"errors");
291 setEventMessages($langs->trans(
"ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv(
"Warehouse"), $tmpproduct->ref),
null,
'errors');
294 if (isModEnabled(
'productbatch') && $tmpproduct->status_batch && (!
GETPOST(
'batchtoproduce-'.$line->id.
'-'.$i))) {
295 $langs->load(
"errors");
296 setEventMessages($langs->trans(
"ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv(
"Batch"), $tmpproduct->ref),
null,
'errors');
302 if (!$error &&
GETPOST(
'idwarehousetoproduce-'.$line->id.
'-'.$i) > 0) {
304 $id_product_batch = 0;
305 $stockmove->origin_type = $object->element;
306 $stockmove->origin_id = $object->id;
308 $idstockmove = $stockmove->reception($user, $line->fk_product,
GETPOST(
'idwarehousetoproduce-'.$line->id.
'-'.$i), $qtytoprocess, $pricetoprocess, $labelmovement,
'',
'',
GETPOST(
'batchtoproduce-'.$line->id.
'-'.$i),
dol_now(), $id_product_batch, $codemovement);
309 if ($idstockmove < 0) {
317 $moline =
new MoLine($db);
318 $moline->fk_mo = $object->id;
319 $moline->position = $pos;
320 $moline->fk_product = $line->fk_product;
321 $moline->fk_warehouse =
GETPOST(
'idwarehousetoproduce-'.$line->id.
'-'.$i);
322 $moline->qty = $qtytoprocess;
323 $moline->batch =
GETPOST(
'batchtoproduce-'.$line->id.
'-'.$i);
324 $moline->role =
'produced';
325 $moline->fk_mrp_production = $line->id;
326 $moline->fk_stock_movement = $idstockmove;
327 $moline->fk_user_creat = $user->id;
329 $resultmoline = $moline->create($user);
330 if ($resultmoline <= 0) {
345 $consumptioncomplete =
true;
346 $productioncomplete =
true;
348 if (
GETPOST(
'autoclose',
'int')) {
349 foreach ($object->lines as $line) {
350 if ($line->role ==
'toconsume') {
351 $arrayoflines = $object->fetchLinesLinked(
'consumed', $line->id);
352 $alreadyconsumed = 0;
353 foreach ($arrayoflines as $line2) {
354 $alreadyconsumed += $line2[
'qty'];
357 if ($alreadyconsumed < $line->qty) {
358 $consumptioncomplete =
false;
361 if ($line->role ==
'toproduce') {
362 $arrayoflines = $object->fetchLinesLinked(
'produced', $line->id);
363 $alreadyproduced = 0;
364 foreach ($arrayoflines as $line2) {
365 $alreadyproduced += $line2[
'qty'];
368 if ($alreadyproduced < $line->qty) {
369 $productioncomplete =
false;
374 $consumptioncomplete =
false;
375 $productioncomplete =
false;
379 dol_syslog(
"consumptioncomplete = ".$consumptioncomplete.
" productioncomplete = ".$productioncomplete);
381 if ($consumptioncomplete && $productioncomplete) {
382 $result = $object->setStatut($object::STATUS_PRODUCED, 0,
'',
'MRP_MO_PRODUCED');
384 $result = $object->setStatut($object::STATUS_INPROGRESS, 0,
'',
'MRP_MO_PRODUCED');
393 $action = str_replace(
'confirm_',
'', $action);
399 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
405 if ($action ==
'confirm_produced' && $confirm ==
'yes' && $permissiontoadd) {
406 $result = $object->setStatut($object::STATUS_PRODUCED, 0,
'',
'MRP_MO_PRODUCED');
409 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
410 $outputlangs = $langs;
413 $newlang =
GETPOST(
'lang_id',
'aZ09');
416 $newlang = $object->thirdparty->default_lang;
418 if (!empty($newlang)) {
420 $outputlangs->setDefaultLang($newlang);
422 $model = $object->model_pdf;
423 $ret = $object->fetch($id);
425 $object->generateDocument($model, $outputlangs, 0, 0, 0);
439$form =
new Form($db);
446$help_url =
'EN:Module_Manufacturing_Orders|FR:Module_Ordres_de_Fabrication|DE:Modul_Fertigungsauftrag';
447$morejs = array(
'/mrp/js/lib_dispatch.js.php');
448llxHeader(
'', $langs->trans(
'Mo'), $help_url,
'', 0, 0, $morejs);
450$newToken = newToken();
453if ($object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
454 $res = $object->fetch_thirdparty();
455 $res = $object->fetch_optionals();
457 if (!empty($conf->global->STOCK_CONSUMPTION_FROM_MANUFACTURING_WAREHOUSE) && $object->fk_warehouse > 0) {
458 $tmpwarehouse->fetch($object->fk_warehouse);
459 $fk_default_warehouse = $object->fk_warehouse;
464 print
dol_get_fiche_head($head,
'production', $langs->trans(
"ManufacturingOrder"), -1, $object->picto);
469 if ($action ==
'delete') {
470 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteMo'), $langs->trans(
'ConfirmDeleteMo'),
'confirm_delete',
'', 0, 1);
473 if ($action ==
'deleteline') {
474 $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);
477 if ($action ==
'clone') {
479 $formquestion = array();
480 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneMo', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
484 if ($action ==
'validate') {
486 $ref = substr($object->ref, 1, 4);
487 if ($ref ==
'PROV') {
488 $object->fetch_product();
489 $numref = $object->getNextNumRef($object->product);
491 $numref = $object->ref;
494 $text = $langs->trans(
'ConfirmValidateMo', $numref);
503 $formquestion = array();
504 if (isModEnabled(
'mrp')) {
506 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
509 if ($conf->browser->name ==
'ie') {
512 $formquestion = array(
519 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'Validate'), $text,
'confirm_validate', $formquestion, 0, 1, 220);
523 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
524 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
525 if (empty($reshook)) {
526 $formconfirm .= $hookmanager->resPrint;
527 } elseif ($reshook > 0) {
528 $formconfirm = $hookmanager->resPrint;
537 $linkback =
'<a href="'.DOL_URL_ROOT.
'/mrp/mo_list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
539 $morehtmlref =
'<div class="refidno">';
545 if (is_object($object->thirdparty)) {
546 $morehtmlref .= $object->thirdparty->getNomUrl(1,
'customer');
547 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
548 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/commande/list.php?socid='.$object->thirdparty->id.
'&search_societe='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherOrders").
'</a>)';
552 if (isModEnabled(
'project')) {
553 $langs->load(
"projects");
554 if (is_object($object->thirdparty)) {
555 $morehtmlref .=
'<br>';
557 if ($permissiontoadd) {
558 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
559 if ($action !=
'classify') {
560 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
562 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
564 if (!empty($object->fk_project)) {
566 $proj->fetch($object->fk_project);
567 $morehtmlref .= $proj->getNomUrl(1);
569 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
574 $morehtmlref .=
'</div>';
577 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
580 print
'<div class="fichecenter">';
581 print
'<div class="fichehalfleft">';
582 print
'<div class="underbanner clearboth"></div>';
583 print
'<table class="border centpercent tableforfield">'.
"\n";
586 $keyforbreak =
'fk_warehouse';
587 unset($object->fields[
'fk_project']);
588 unset($object->fields[
'fk_soc']);
589 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_view.tpl.php';
592 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
598 print
'<div class="clearboth"></div>';
603 if (!in_array($action, array(
'consumeorproduce',
'consumeandproduceall'))) {
604 print
'<div class="tabsAction">';
606 $parameters = array();
608 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
609 if (empty($reshook)) {
611 if ($object->status == $object::STATUS_DRAFT) {
612 if ($permissiontoadd) {
613 if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
614 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=validate&token='.$newToken.
'">'.$langs->trans(
"Validate").
'</a>';
616 $langs->load(
"errors");
617 print
'<a class="butActionRefused" href="" title="'.$langs->trans(
"ErrorAddAtLeastOneLineFirst").
'">'.$langs->trans(
"Validate").
'</a>';
623 if ($object->status == Mo::STATUS_VALIDATED || $object->status == Mo::STATUS_INPROGRESS) {
624 if ($permissiontoproduce) {
625 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=consumeorproduce&token='.$newToken.
'">'.$langs->trans(
'ConsumeOrProduce').
'</a>';
627 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
'ConsumeOrProduce').
'</a>';
629 } elseif ($object->status == Mo::STATUS_DRAFT) {
630 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"ValidateBefore").
'">'.$langs->trans(
'ConsumeOrProduce').
'</a>';
634 if ($object->status == Mo::STATUS_VALIDATED || $object->status == Mo::STATUS_INPROGRESS) {
635 if ($permissiontoproduce) {
636 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=consumeandproduceall&token='.$newToken.
'">'.$langs->trans(
'ConsumeAndProduceAll').
'</a>';
638 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
'ConsumeAndProduceAll').
'</a>';
640 } elseif ($object->status == Mo::STATUS_DRAFT) {
641 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"ValidateBefore").
'">'.$langs->trans(
'ConsumeAndProduceAll').
'</a>';
645 if ($permissiontoadd) {
646 if ($object->status == $object::STATUS_VALIDATED || $object->status == $object::STATUS_INPROGRESS) {
647 $arrayproduced = $object->fetchLinesLinked(
'produced', 0);
649 foreach ($arrayproduced as $lineproduced) {
650 $nbProduced += $lineproduced[
'qty'];
652 if ($nbProduced > 0) {
653 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=confirm_produced&confirm=yes&token='.$newToken.
'">'.$langs->trans(
"Close").
'</a>'.
"\n";
655 print
'<a class="butActionRefused" href="#" title="'.$langs->trans(
"GoOnTabProductionToProduceFirst", $langs->transnoentitiesnoconv(
"Production")).
'">'.$langs->trans(
"Close").
'</a>'.
"\n";
658 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=confirm_close&confirm=yes&token='.$newToken.
'">'.$langs->trans(
"Cancel").
'</a>'.
"\n";
661 if ($object->status == $object::STATUS_CANCELED) {
662 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=confirm_reopen&confirm=yes&token='.$newToken.
'">'.$langs->trans(
"Re-Open").
'</a>'.
"\n";
665 if ($object->status == $object::STATUS_PRODUCED) {
666 if ($permissiontoproduce) {
667 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=confirm_reopen&token='.$newToken.
'">'.$langs->trans(
'ReOpen').
'</a>';
669 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
'ReOpen').
'</a>';
678 if (in_array($action, array(
'consumeorproduce',
'consumeandproduceall',
'addconsumeline',
'addproduceline'))) {
679 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
680 print
'<input type="hidden" name="token" value="'.newToken().
'">';
681 print
'<input type="hidden" name="action" value="confirm_'.$action.
'">';
682 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
683 print
'<input type="hidden" name="id" value="'.$id.
'">';
686 if (in_array($action, array(
'consumeorproduce',
'consumeandproduceall'))) {
687 $defaultstockmovementlabel =
GETPOST(
'inventorylabel',
'alphanohtml') ?
GETPOST(
'inventorylabel',
'alphanohtml') : $langs->trans(
"ProductionForRef", $object->
ref);
690 print
'<div class="center'.(in_array($action, array(
'consumeorproduce',
'consumeandproduceall')) ?
' formconsumeproduce' :
'').
'">';
691 print
'<div class="opacitymedium hideonsmartphone paddingbottom">'.$langs->trans(
"ConfirmProductionDesc", $langs->transnoentitiesnoconv(
"Confirm")).
'<br></div>';
692 print
'<span class="fieldrequired">'.$langs->trans(
"InventoryCode").
':</span> <input type="text" class="minwidth150 maxwidth200" name="inventorycode" value="'.$defaultstockmovementcode.
'"> ';
693 print
'<span class="clearbothonsmartphone"></span>';
694 print $langs->trans(
"MovementLabel").
': <input type="text" class="minwidth300" name="inventorylabel" value="'.$defaultstockmovementlabel.
'"><br><br>';
695 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>';
696 print
'<input type="submit" class="button" value="'.$langs->trans(
"Confirm").
'" name="confirm">';
698 print
'<input class="button button-cancel" type="submit" value="'.$langs->trans(
"Cancel").
'" name="cancel">';
712 if (!empty($object->table_element_line)) {
714 $object->fetchLines();
717 if ($object->fk_bom > 0) {
719 $res = $bom->fetch($object->fk_bom);
721 $bom->calculateCosts();
722 $bomcost = $bom->unit_cost;
728 print
'<div class="fichecenter">';
729 print
'<div class="fichehalfleft">';
730 print
'<div class="clearboth"></div>';
732 $url = $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=addconsumeline&token='.newToken();
733 $permissiontoaddaconsumeline = $object->status != $object::STATUS_PRODUCED && $object->status != $object::STATUS_CANCELED;
734 $parameters = array(
'morecss'=>
'reposition');
737 if ($action !=
'consumeorproduce' && $action !=
'consumeandproduceall') {
738 $newcardbutton =
dolGetButtonTitle($langs->trans(
'AddNewConsumeLines'),
'',
'fa fa-plus-circle size15x', $url,
'', $permissiontoaddaconsumeline, $parameters);
741 print
load_fiche_titre($langs->trans(
'Consumption'), $newcardbutton,
'', 0,
'',
'',
'');
743 print
'<div class="div-table-responsive-no-min">';
744 print
'<table class="noborder noshadow centpercent nobottom">';
746 print
'<tr class="liste_titre">';
748 print
'<td>'.$langs->trans(
"Product").
'</td>';
750 print
'<td class="right">'.$langs->trans(
"Qty").
'</td>';
752 if ($permissiontoupdatecost && !empty($conf->global->MRP_SHOW_COST_FOR_CONSUMPTION)) {
753 print
'<td class="right">'.$langs->trans(
"UnitCost").
'</td>';
756 print
'<td class="right">'.$langs->trans(
"QtyAlreadyConsumed").
'</td>';
759 if ($collapse || in_array($action, array(
'consumeorproduce',
'consumeandproduceall'))) {
760 print $langs->trans(
"Warehouse");
763 if (in_array($action, array(
'consumeorproduce',
'consumeandproduceall'))) {
764 $listwarehouses = $tmpwarehouse->list_array(1);
765 if (count($listwarehouses) > 1) {
766 print
'<br>'.$form->selectarray(
'fk_default_warehouse', $listwarehouses, $fk_default_warehouse, $langs->trans(
"ForceTo"), 0, 0,
'', 0, 0, 0,
'',
'minwidth100 maxwidth200', 1);
767 } elseif (count($listwarehouses) == 1) {
768 print
'<br>'.$form->selectarray(
'fk_default_warehouse', $listwarehouses, $fk_default_warehouse, 0, 0, 0,
'', 0, 0, 0,
'',
'minwidth100 maxwidth200', 1);
774 if (isModEnabled(
'stock')) {
776 print
'<td align="right">';
777 if ($collapse || in_array($action, array(
'consumeorproduce',
'consumeandproduceall'))) {
778 print $langs->trans(
"Stock");
783 if (isModEnabled(
'productbatch')) {
785 if ($collapse || in_array($action, array(
'consumeorproduce',
'consumeandproduceall'))) {
786 print $langs->trans(
"Batch");
791 if ($permissiontodelete) {
803 if ($action ==
'addconsumeline') {
804 print
'<!-- Add line to consume -->'.
"\n";
805 print
'<tr class="liste_titre">';
807 print $form->select_produits(
'',
'productidtoadd',
'', 0, 0, -1, 2,
'', 1, array(), 0,
'1', 0,
'maxwidth300');
810 print
'<td class="right"><input type="text" name="qtytoadd" value="1" class="width50 right"></td>';
812 if ($permissiontoupdatecost && !empty($conf->global->MRP_SHOW_COST_FOR_CONSUMPTION)) {
816 print
'<td colspan="2">';
818 print
'<input type="submit" class="button buttongen button-add" name="addconsumelinebutton" value="'.$langs->trans(
"Add").
'">';
819 print
'<input type="submit" class="button buttongen button-cancel" name="canceladdconsumelinebutton" value="'.$langs->trans(
"Cancel").
'">';
821 if (isModEnabled(
'stock')) {
825 if (isModEnabled(
'productbatch')) {
829 if ($permissiontodelete) {
843 if (!empty($object->lines)) {
844 $nblinetoconsume = 0;
845 foreach ($object->lines as $line) {
846 if ($line->role ==
'toconsume') {
851 $nblinetoconsumecursor = 0;
852 foreach ($object->lines as $line) {
853 if ($line->role ==
'toconsume') {
854 $nblinetoconsumecursor++;
856 $tmpproduct =
new Product($db);
857 $tmpproduct->fetch($line->fk_product);
858 $linecost =
price2num($tmpproduct->pmp,
'MT');
860 if ($object->qty > 0) {
862 $costprice =
price2num((!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp);
863 if (empty($costprice)) {
864 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
866 if ($productFournisseur->find_min_price_product_fournisseur($line->fk_product) > 0) {
867 $costprice = $productFournisseur->fourn_unitprice;
872 $linecost =
price2num(($line->qty * $costprice) / $object->qty,
'MT');
873 $bomcostupdated +=
price2num(($line->qty * $costprice) / $object->qty,
'MU');
876 $bomcostupdated =
price2num($bomcostupdated,
'MU');
877 $arrayoflines = $object->fetchLinesLinked(
'consumed', $line->id);
878 $alreadyconsumed = 0;
879 foreach ($arrayoflines as $line2) {
880 $alreadyconsumed += $line2[
'qty'];
883 $suffix =
'_'.$line->id;
884 print
'<!-- Line to dispatch '.$suffix.
' -->'.
"\n";
886 print
'<input id="qty_ordered'.$suffix.
'" type="hidden" value="'.$line->qty.
'">';
887 print
'<input id="qty_dispatched'.$suffix.
'" type="hidden" value="'.$alreadyconsumed.
'">';
889 print
'<tr data-line-id="'.$line->id.
'">';
891 print
'<td>'.$tmpproduct->getNomUrl(1);
892 print
'<br><div class="opacitymedium small tdoverflowmax150" title="'.dol_escape_htmltag($tmpproduct->label).
'">'.$tmpproduct->label.
'</div>';
895 print
'<td class="right nowraponall">';
896 $help =
''; $picto =
'help';
897 if ($line->qty_frozen) {
898 $help = ($help ?
'<br>' :
'').
'<strong>'.$langs->trans(
"QuantityFrozen").
'</strong>: '.
yn(1).
' ('.$langs->trans(
"QuantityConsumedInvariable").
')';
899 print $form->textwithpicto(
'', $help, -1,
'lock').
' ';
901 if ($line->disable_stock_change) {
902 $help = ($help ?
'<br>' :
'').
'<strong>'.$langs->trans(
"DisableStockChange").
'</strong>: '.
yn(1).
' ('.(($tmpproduct->type ==
Product::TYPE_SERVICE && empty($conf->global->STOCK_SUPPORTS_SERVICES)) ? $langs->trans(
"NoStockChangeOnServices") : $langs->trans(
"DisableStockChangeHelp")).
')';
903 print $form->textwithpicto(
'', $help, -1,
'help').
' ';
908 if ($permissiontoupdatecost && !empty($conf->global->MRP_SHOW_COST_FOR_CONSUMPTION)) {
909 print
'<td class="right nowraponall">';
910 print
price($linecost);
914 print
'<td class="right">';
915 if ($alreadyconsumed) {
917 print
'jQuery(document).ready(function() {
918 jQuery("#expandtoproduce'.$line->id.
'").click(function() {
919 console.log("Expand mrp_production line '.$line->id.
'");
920 jQuery(".expanddetail'.$line->id.
'").toggle();';
921 if ($nblinetoconsume == $nblinetoconsumecursor) {
922 print
'if (jQuery("#tablelines").hasClass("nobottom")) { jQuery("#tablelines").removeClass("nobottom"); } else { jQuery("#tablelines").addClass("nobottom"); }';
928 if (empty($conf->use_javascript_ajax)) {
929 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?collapse='.$collapse.
','.$line->id.
'">';
931 print
img_picto($langs->trans(
"ShowDetails"),
"chevron-down",
'id="expandtoproduce'.$line->id.
'"');
932 if (empty($conf->use_javascript_ajax)) {
936 if ($nblinetoconsume == $nblinetoconsumecursor) {
937 print
'<script>jQuery("#tablelines").removeClass("nobottom");</script>';
940 print
' '.price2num($alreadyconsumed,
'MS');
944 if (!empty($conf->global->STOCK_CONSUMPTION_FROM_MANUFACTURING_WAREHOUSE) && $tmpwarehouse->id > 0) {
945 print
img_picto(
'', $tmpwarehouse->picto).
" ".$tmpwarehouse->label;
949 if (isModEnabled(
'stock')) {
950 print
'<td class="nowraponall right">';
952 if (!$line->disable_stock_change && $tmpproduct->stock_reel < ($line->qty - $alreadyconsumed)) {
953 print
img_warning($langs->trans(
'StockTooLow')) .
' ';
955 if (empty($conf->global->STOCK_CONSUMPTION_FROM_MANUFACTURING_WAREHOUSE) || empty($tmpwarehouse->id)) {
956 print
price2num($tmpproduct->stock_reel,
'MS');
959 $tmpproduct->load_stock();
960 $wh_stock = $tmpproduct->stock_warehouse[$tmpwarehouse->id];
961 if (!empty($wh_stock)) {
971 if (isModEnabled(
'productbatch')) {
982 if ($permissiontodelete) {
983 $href = $_SERVER[
"PHP_SELF"].
'?id='.((int) $object->id).
'&action=deleteline&token='.newToken().
'&lineid='.((int) $line->id);
984 print
'<td class="center">';
985 print
'<a class="reposition" href="'.$href.
'">';
986 print
img_picto($langs->trans(
'TooltipDeleteAndRevertStockMovement'),
'delete');
994 foreach ($arrayoflines as $line2) {
995 print
'<tr class="expanddetail'.$line->id.
' hideobject opacitylow">';
999 $tmpstockmovement->id = $line2[
'fk_stock_movement'];
1000 print
'<a href="'.DOL_URL_ROOT.
'/product/stock/movement_list.php?search_ref='.$tmpstockmovement->id.
'">'.
img_picto($langs->trans(
"StockMovement"),
'movement',
'class="paddingright"').
'</a>';
1008 print
'<td class="right">'.$line2[
'qty'].
'</td>';
1011 if ($permissiontoupdatecost && !empty($conf->global->MRP_SHOW_COST_FOR_CONSUMPTION)) {
1016 print
'<td class="tdoverflowmax150">';
1017 if ($line2[
'fk_warehouse'] > 0) {
1018 $result = $tmpwarehouse->fetch($line2[
'fk_warehouse']);
1020 print $tmpwarehouse->getNomUrl(1);
1026 if (isModEnabled(
'stock')) {
1031 if (isModEnabled(
'productbatch')) {
1033 if ($line2[
'batch'] !=
'') {
1034 $tmpbatch->fetch(0, $line2[
'fk_product'], $line2[
'batch']);
1035 print $tmpbatch->getNomUrl(1);
1047 if ($permissiontodelete) {
1048 $href = $_SERVER[
"PHP_SELF"].
'?id='.((int) $object->id).
'&action=deleteline&token='.newToken().
'&lineid='.((int) $line->id).
'&fk_movement='.((int) $line2[
'fk_stock_movement']);
1049 print
'<td class="center">';
1050 print
'<a class="reposition" href="'.$href.
'">';
1051 print
img_picto($langs->trans(
'TooltipDeleteAndRevertStockMovement'),
'delete');
1059 if (in_array($action, array(
'consumeorproduce',
'consumeandproduceall'))) {
1061 print
'<!-- Enter line to consume -->'.
"\n";
1063 print
'<tr data-max-qty="'.$maxQty.
'" name="batch_'.$line->id.
'_'.$i.
'">';
1065 print
'<td><span class="opacitymedium">'.$langs->trans(
"ToConsume").
'</span></td>';
1066 $preselected = (GETPOSTISSET(
'qty-'.$line->id.
'-'.$i) ?
GETPOST(
'qty-'.$line->id.
'-'.$i) : max(0, $line->qty - $alreadyconsumed));
1067 if ($action ==
'consumeorproduce' && !GETPOSTISSET(
'qty-'.$line->id.
'-'.$i)) {
1072 if (!empty($conf->global->MRP_NEVER_CONSUME_MORE_THAN_EXPECTED) && ($line->qty - $alreadyconsumed) <= 0) {
1073 $disable =
'disabled';
1077 print
'<input type="hidden" name="product-'.$line->id.
'-'.$i.
'" value="'.$line->fk_product.
'">';
1080 print
'<td class="right"><input type="text" class="width50 right" id="qtytoconsume-'.$line->id.
'-'.$i.
'" name="qty-'.$line->id.
'-'.$i.
'" value="'.$preselected.
'" '.$disable.
'></td>';
1083 if ($permissiontoupdatecost && !empty($conf->global->MRP_SHOW_COST_FOR_CONSUMPTION)) {
1093 if (empty($line->disable_stock_change)) {
1094 $preselected = (GETPOSTISSET(
'idwarehouse-'.$line->id.
'-'.$i) ?
GETPOST(
'idwarehouse-'.$line->id.
'-'.$i) : ($tmpproduct->fk_default_warehouse > 0 ? $tmpproduct->fk_default_warehouse :
'ifone'));
1095 print $formproduct->selectWarehouses($preselected,
'idwarehouse-'.$line->id.
'-'.$i,
'', 1, 0, $line->fk_product,
'', 1, 0,
null,
'maxwidth200 csswarehouse_'.$line->id.
'_'.$i);
1097 print
'<span class="opacitymedium">'.$langs->trans(
"DisableStockChange").
'</span>';
1100 print
'<span class="opacitymedium">'.$langs->trans(
"NoStockChangeOnServices").
'</span>';
1105 if (isModEnabled(
'stock')) {
1110 if (isModEnabled(
'productbatch')) {
1111 print
'<td class="nowraponall">';
1112 if ($tmpproduct->status_batch) {
1113 $preselected = (GETPOSTISSET(
'batch-'.$line->id.
'-'.$i) ?
GETPOST(
'batch-'.$line->id.
'-'.$i) :
'');
1114 print
'<input type="text" class="width75" name="batch-'.$line->id.
'-'.$i.
'" value="'.$preselected.
'" list="batch-'.$line->id.
'-'.$i.
'">';
1115 print $formproduct->selectLotDataList(
'batch-'.$line->id.
'-'.$i, 0, $line->fk_product,
'',
'');
1122 print
'<td align="right" class="split">';
1123 print
' '.img_picto($langs->trans(
'AddStockLocationLine'),
'split.png',
'class="splitbutton" onClick="addDispatchLine('.((int) $line->id).
', \''.
dol_escape_js($type).
'\', \
'qtymissingconsume\')"');
1127 print
'<td align="right" class="splitall">';
1128 if (($action ==
'consumeorproduce' || $action ==
'consumeandproduceall') && $tmpproduct->status_batch == 2) {
1129 print
img_picto($langs->trans(
'SplitAllQuantity'),
'split.png',
'class="splitbutton splitallbutton field-error-icon" data-max-qty="1" onClick="addDispatchLine('.$line->id.
', \'batch\', \'allmissingconsume\')"');
1134 if ($permissiontodelete) {
1148 print
'<script type="text/javascript">
1149 $(document).ready(function () {
1150 $("select[name=fk_default_warehouse]").change(function() {
1151 var fk_default_warehouse = $("option:selected", this).val();
1152 $("select[name^=idwarehouse-]").val(fk_default_warehouse).change();
1157 if (in_array($action, array(
'consumeorproduce',
'consumeandproduceall')) &&
1158 !empty($conf->global->STOCK_CONSUMPTION_FROM_MANUFACTURING_WAREHOUSE)) {
1159 print
'<script>$(document).ready(function () {
1160 $("#fk_default_warehouse").change();
1167 print
'<div class="fichehalfright">';
1168 print
'<div class="clearboth"></div>';
1170 $nblinetoproduce = 0;
1171 foreach ($object->lines as $line) {
1172 if ($line->role ==
'toproduce') {
1177 $newcardbutton =
'';
1178 $url = $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=addproduceline&token='.newToken();
1179 $permissiontoaddaproductline = $object->status != $object::STATUS_PRODUCED && $object->status != $object::STATUS_CANCELED;
1180 $parameters = array(
'morecss'=>
'reposition');
1181 if ($action !=
'consumeorproduce' && $action !=
'consumeandproduceall') {
1182 if ($nblinetoproduce == 0 || $object->mrptype == 1) {
1183 $newcardbutton =
dolGetButtonTitle($langs->trans(
'AddNewProduceLines'),
'',
'fa fa-plus-circle size15x', $url,
'', $permissiontoaddaproductline, $parameters);
1187 print
load_fiche_titre($langs->trans(
'Production'), $newcardbutton,
'', 0,
'',
'');
1189 print
'<div class="div-table-responsive-no-min">';
1190 print
'<table id="tablelinestoproduce" class="noborder noshadow nobottom centpercent">';
1192 print
'<tr class="liste_titre">';
1194 print
'<td>'.$langs->trans(
"Product").
'</td>';
1196 print
'<td class="right">'.$langs->trans(
"Qty").
'</td>';
1198 if ($permissiontoupdatecost) {
1199 if (empty($bomcostupdated)) {
1200 print
'<td class="right">'.$form->textwithpicto($langs->trans(
"UnitCost"), $langs->trans(
"AmountUsedToUpdateWAP")).
'</td>';
1202 print
'<td class="right">'.$form->textwithpicto($langs->trans(
"ManufacturingPrice"), $langs->trans(
"AmountUsedToUpdateWAP")).
'</td>';
1206 print
'<td class="right">'.$langs->trans(
"QtyAlreadyProduced").
'</td>';
1209 if ($collapse || in_array($action, array(
'consumeorproduce',
'consumeandproduceall'))) {
1210 print $langs->trans(
"Warehouse");
1215 if (isModEnabled(
'productbatch')) {
1217 if ($collapse || in_array($action, array(
'consumeorproduce',
'consumeandproduceall'))) {
1218 print $langs->trans(
"Batch");
1230 if ($permissiontodelete) {
1236 if ($action ==
'addproduceline') {
1237 print
'<!-- Add line to produce -->'.
"\n";
1238 print
'<tr class="liste_titre">';
1242 print $form->select_produits(
'',
'productidtoadd',
'', 0, 0, -1, 2,
'', 1, array(), 0,
'1', 0,
'maxwidth300');
1245 print
'<td class="right"><input type="text" name="qtytoadd" value="1" class="width50 right"></td>';
1247 if ($permissiontoupdatecost) {
1251 print
'<td colspan="2">';
1252 print
'<input type="submit" class="button buttongen button-add" name="addproducelinebutton" value="'.$langs->trans(
"Add").
'">';
1253 print
'<input type="submit" class="button buttongen button-cancel" name="canceladdproducelinebutton" value="'.$langs->trans(
"Cancel").
'">';
1256 if (isModEnabled(
'productbatch')) {
1266 if ($permissiontodelete) {
1272 if (!empty($object->lines)) {
1273 $nblinetoproduce = 0;
1274 foreach ($object->lines as $line) {
1275 if ($line->role ==
'toproduce') {
1280 $nblinetoproducecursor = 0;
1281 foreach ($object->lines as $line) {
1282 if ($line->role ==
'toproduce') {
1285 $nblinetoproducecursor++;
1287 $tmpproduct =
new Product($db);
1288 $tmpproduct->fetch($line->fk_product);
1290 $arrayoflines = $object->fetchLinesLinked(
'produced', $line->id);
1291 $alreadyproduced = 0;
1292 foreach ($arrayoflines as $line2) {
1293 $alreadyproduced += $line2[
'qty'];
1296 $suffix =
'_'.$line->id;
1297 print
'<!-- Line to dispatch '.$suffix.
' -->'.
"\n";
1299 print
'<input id="qty_ordered'.$suffix.
'" type="hidden" value="'.$line->qty.
'">';
1300 print
'<input id="qty_dispatched'.$suffix.
'" type="hidden" value="'.$alreadyproduced.
'">';
1304 print
'<td>'.$tmpproduct->getNomUrl(1);
1305 print
'<br><span class="opacitymedium small">'.$tmpproduct->label.
'</span>';
1308 print
'<td class="right">'.$line->qty.
'</td>';
1310 if ($permissiontoupdatecost) {
1312 $manufacturingcost = 0;
1313 $manufacturingcostsrc =
'';
1314 if ($object->mrptype == 0) {
1315 $manufacturingcost = $bomcostupdated;
1316 $manufacturingcostsrc = $langs->trans(
"CalculatedFromProductsToConsume");
1317 if (empty($manufacturingcost)) {
1318 $manufacturingcost = $bomcost;
1319 $manufacturingcostsrc = $langs->trans(
"ValueFromBom");
1321 if (empty($manufacturingcost)) {
1322 $manufacturingcost =
price2num($tmpproduct->cost_price,
'MU');
1323 $manufacturingcostsrc = $langs->trans(
"CostPrice");
1325 if (empty($manufacturingcost)) {
1326 $manufacturingcost =
price2num($tmpproduct->pmp,
'MU');
1327 $manufacturingcostsrc = $langs->trans(
"PMPValue");
1331 print
'<td class="right nowraponall" title="'.dol_escape_htmltag($manufacturingcostsrc).
'">';
1332 if ($manufacturingcost) {
1333 print
price($manufacturingcost);
1338 print
'<td class="right nowraponall">';
1339 if ($alreadyproduced) {
1341 print
'jQuery(document).ready(function() {
1342 jQuery("#expandtoproduce'.$line->id.
'").click(function() {
1343 console.log("Expand mrp_production line '.$line->id.
'");
1344 jQuery(".expanddetailtoproduce'.$line->id.
'").toggle();';
1345 if ($nblinetoproduce == $nblinetoproducecursor) {
1346 print
'if (jQuery("#tablelinestoproduce").hasClass("nobottom")) { jQuery("#tablelinestoproduce").removeClass("nobottom"); } else { jQuery("#tablelinestoproduce").addClass("nobottom"); }';
1352 if (empty($conf->use_javascript_ajax)) {
1353 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?collapse='.$collapse.
','.$line->id.
'">';
1355 print
img_picto($langs->trans(
"ShowDetails"),
"chevron-down",
'id="expandtoproduce'.$line->id.
'"');
1356 if (empty($conf->use_javascript_ajax)) {
1360 print
' '.$alreadyproduced;
1366 if (isModEnabled(
'productbatch')) {
1376 if ($permissiontodelete) {
1377 if ($line->origin_type ==
'free') {
1378 $href = $_SERVER[
"PHP_SELF"];
1379 $href .=
'?id='.$object->id;
1380 $href .=
'&action=deleteline';
1381 $href .=
'&lineid='.$line->id;
1382 print
'<td class="center">';
1383 print
'<a class="reposition" href="'.$href.
'">';
1384 print
img_picto($langs->trans(
'TooltipDeleteAndRevertStockMovement'),
"delete");
1394 foreach ($arrayoflines as $line2) {
1395 print
'<tr class="expanddetailtoproduce'.$line->id.
' hideobject opacitylow">';
1398 $tmpstockmovement->id = $line2[
'fk_stock_movement'];
1399 print
'<a href="'.DOL_URL_ROOT.
'/product/stock/movement_list.php?search_ref='.$tmpstockmovement->id.
'">'.
img_picto($langs->trans(
"StockMovement"),
'movement',
'class="paddingright"').
'</a>';
1405 if ($permissiontoupdatecost) {
1409 print
'<td class="right">'.$line2[
'qty'].
'</td>';
1411 print
'<td class="tdoverflowmax150">';
1412 if ($line2[
'fk_warehouse'] > 0) {
1413 $result = $tmpwarehouse->fetch($line2[
'fk_warehouse']);
1415 print $tmpwarehouse->getNomUrl(1);
1420 if (isModEnabled(
'productbatch')) {
1422 if ($line2[
'batch'] !=
'') {
1423 $tmpbatch->fetch(0, $line2[
'fk_product'], $line2[
'batch']);
1424 print $tmpbatch->getNomUrl(1);
1435 if ($permissiontodelete) {
1441 if (in_array($action, array(
'consumeorproduce',
'consumeandproduceall'))) {
1442 print
'<!-- Enter line to produce -->'.
"\n";
1444 print
'<tr data-max-qty="'.$maxQty.
'" name="batch_'.$line->id.
'_'.$i.
'">';
1446 print
'<td><span class="opacitymedium">'.$langs->trans(
"ToProduce").
'</span></td>';
1447 $preselected = (GETPOSTISSET(
'qtytoproduce-'.$line->id.
'-'.$i) ?
GETPOST(
'qtytoproduce-'.$line->id.
'-'.$i) : max(0, $line->qty - $alreadyproduced));
1448 if ($action ==
'consumeorproduce' && !GETPOSTISSET(
'qtytoproduce-'.$line->id.
'-'.$i)) {
1452 print
'<td class="right"><input type="text" class="width50 right" id="qtytoproduce-'.$line->id.
'-'.$i.
'" name="qtytoproduce-'.$line->id.
'-'.$i.
'" value="'.$preselected.
'"></td>';
1454 if ($permissiontoupdatecost) {
1456 $manufacturingcost = 0;
1457 $manufacturingcostsrc =
'';
1458 if ($object->mrptype == 0) {
1459 $manufacturingcost = $bomcostupdated;
1460 $manufacturingcostsrc = $langs->trans(
"CalculatedFromProductsToConsume");
1461 if (empty($manufacturingcost)) {
1462 $manufacturingcost = $bomcost;
1463 $manufacturingcostsrc = $langs->trans(
"ValueFromBom");
1465 if (empty($manufacturingcost)) {
1466 $manufacturingcost =
price2num($tmpproduct->cost_price,
'MU');
1467 $manufacturingcostsrc = $langs->trans(
"CostPrice");
1469 if (empty($manufacturingcost)) {
1470 $manufacturingcost =
price2num($tmpproduct->pmp,
'MU');
1471 $manufacturingcostsrc = $langs->trans(
"PMPValue");
1476 $preselected = (GETPOSTISSET(
'pricetoproduce-'.$line->id.
'-'.$i) ?
GETPOST(
'pricetoproduce-'.$line->id.
'-'.$i) : ($manufacturingcost ?
price($manufacturingcost) :
''));
1477 print
'<td class="right"><input type="text" class="width75 right" name="pricetoproduce-'.$line->id.
'-'.$i.
'" value="'.$preselected.
'"></td>';
1479 print
'<td><input type="hidden" class="width50 right" name="pricetoproduce-'.$line->id.
'-'.$i.
'" value="'.($manufacturingcost ? $manufacturingcost :
'').
'"></td>';
1487 $preselected = (GETPOSTISSET(
'idwarehousetoproduce-'.$line->id.
'-'.$i) ?
GETPOST(
'idwarehousetoproduce-'.$line->id.
'-'.$i) : ($object->fk_warehouse > 0 ? $object->fk_warehouse :
'ifone'));
1488 print $formproduct->selectWarehouses($preselected,
'idwarehousetoproduce-'.$line->id.
'-'.$i,
'', 1, 0, $line->fk_product,
'', 1, 0,
null,
'maxwidth200 csswarehouse_'.$line->id.
'_'.$i);
1490 print
'<span class="opacitymedium">'.$langs->trans(
"NoStockChangeOnServices").
'</span>';
1494 if (isModEnabled(
'productbatch')) {
1496 if ($tmpproduct->status_batch) {
1497 $preselected = (GETPOSTISSET(
'batchtoproduce-'.$line->id.
'-'.$i) ?
GETPOST(
'batchtoproduce-'.$line->id.
'-'.$i) :
'');
1498 print
'<input type="text" class="width75" name="batchtoproduce-'.$line->id.
'-'.$i.
'" value="'.$preselected.
'">';
1502 if ($tmpproduct->status_batch) {
1504 print
'<td align="right" class="split">';
1505 print
img_picto($langs->trans(
'AddStockLocationLine'),
'split.png',
'class="splitbutton" onClick="addDispatchLine('.$line->id.
', \''.$type.
'\', \
'qtymissing\')"');
1508 print
'<td align="right" class="splitall">';
1509 if (($action ==
'consumeorproduce' || $action ==
'consumeandproduceall') && $tmpproduct->status_batch == 2) print
img_picto($langs->trans(
'SplitAllQuantity'),
'split.png',
'class="splitbutton splitallbutton field-error-icon" onClick="addDispatchLine('.$line->id.
', \'batch\', \'alltoproduce\')"');
1534 if (in_array($action, array(
'consumeorproduce',
'consumeandproduceall',
'addconsumeline'))) {
1540 <script
type=
"text/javascript" language=
"javascript">
1542 $(document).ready(
function() {
1544 updateselectbatchbywarehouse();
1546 updateselectwarehousebybatch();
1549 function updateselectbatchbywarehouse() {
1550 $(document).on(
'change',
"select[name*='idwarehouse']",
function () {
1551 console.log(
"We change warehouse so we update the list of possible batch number");
1553 var selectwarehouse = $(
this);
1555 var selectbatch_name = selectwarehouse.attr(
'name').replace(
'idwarehouse',
'batch');
1556 var selectbatch = $(
"datalist[id*='" + selectbatch_name +
"']");
1557 var selectedbatch = selectbatch.val();
1559 var product_element_name = selectwarehouse.attr(
'name').replace(
'idwarehouse',
'product');
1563 url:
"<?php echo DOL_URL_ROOT . '/mrp/ajax/interface.php'; ?>",
1565 action:
"updateselectbatchbywarehouse",
1566 permissiontoproduce: <?php echo $permissiontoproduce ?>,
1567 warehouse_id: $(
this).val(),
1568 token:
'<?php echo currentToken(); ?>',
1569 product_id: $(
"input[name='" + product_element_name +
"']").val()
1571 }).done(
function (data) {
1573 selectbatch.empty();
1575 if (typeof data ==
"object") {
1576 console.log(
"data is already type object, no need to parse it");
1578 console.log(
"data is type "+(typeof data));
1579 data = JSON.parse(data);
1582 selectbatch.append($(
'<option>', {
1586 $.each(data,
function (key, value) {
1588 if(selectwarehouse.val() == -1) {
1589 var label =
" (<?php echo $langs->trans('Stock total') ?> : " + value +
")";
1591 var label =
" (<?php echo $langs->trans('Stock') ?> : " + value +
")";
1594 if(key === selectedbatch) {
1595 var option =
'<option value="'+key+
'" selected>'+ label +
'</option>';
1597 var option =
'<option value="'+key+
'">'+ label +
'</option>';
1600 selectbatch.append(option);
1606 function updateselectwarehousebybatch() {
1607 $(document).on(
'change',
'input[name*=batch]',
function(){
1608 console.log(
"We change batch so we update the list of possible warehouses");
1610 var selectbatch = $(
this);
1612 var selectwarehouse_name = selectbatch.attr(
'name').replace(
'batch',
'idwarehouse');
1613 var selectwarehouse = $(
"select[name*='" + selectwarehouse_name +
"']");
1614 var selectedwarehouse = selectwarehouse.val();
1616 if(selectedwarehouse != -1){
1620 var product_element_name = selectbatch.attr(
'name').replace(
'batch',
'product');
1624 url:
"<?php echo DOL_URL_ROOT . '/mrp/ajax/interface.php'; ?>",
1626 action:
"updateselectwarehousebybatch",
1627 permissiontoproduce: <?php echo $permissiontoproduce ?>,
1628 batch: $(
this).val(),
1629 token:
'<?php echo currentToken(); ?>',
1630 product_id: $(
"input[name='" + product_element_name +
"']").val()
1632 }).done(
function (data) {
1634 if (typeof data ==
"object") {
1635 console.log(
"data is already type object, no need to parse it");
1637 console.log(
"data is type "+(typeof data));
1638 data = JSON.parse(data);
1642 selectwarehouse.val(data).change();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
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.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
moPrepareHead($object)
Prepare array of tabs for Mo.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
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.