27 require
'../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/productlot.class.php';
37 $langs->loadLangs(array(
'stocks',
'other',
'productbatch'));
41 $action =
GETPOST(
'action',
'aZ09');
42 $confirm =
GETPOST(
'confirm',
'alpha');
43 $cancel =
GETPOST(
'cancel',
'aZ09');
44 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'myobjectcard';
45 $backtopage =
GETPOST(
'backtopage',
'alpha');
48 $object =
new ProductLot($db);
50 $hookmanager->initHooks(array(
'productlotcard',
'globalcard'));
53 $extrafields->fetch_name_optionals_label($object->table_element);
55 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element,
'',
'search_');
58 $search_all =
GETPOST(
"search_all",
'alpha');
60 foreach ($object->fields as $key => $val) {
61 if (
GETPOST(
'search_'.$key,
'alpha')) {
62 $search[$key] =
GETPOST(
'search_'.$key,
'alpha');
66 if (empty($action) && empty($id) && empty($ref)) {
70 $batch =
GETPOST(
'batch',
'alpha');
71 $productid =
GETPOST(
'productid',
'int');
74 $search_entity =
GETPOST(
'search_entity',
'int');
75 $search_fk_product =
GETPOST(
'search_fk_product',
'int');
76 $search_batch =
GETPOST(
'search_batch',
'alpha');
77 $search_fk_user_creat =
GETPOST(
'search_fk_user_creat',
'int');
78 $search_fk_user_modif =
GETPOST(
'search_fk_user_modif',
'int');
79 $search_import_key =
GETPOST(
'search_import_key',
'int');
81 if (empty($action) && empty($id) && empty($ref)) {
89 $tmp = explode(
'_', $ref);
93 $object->fetch($id, $productid, $batch);
94 $object->ref = $object->batch;
95 $upload_dir = $conf->productbatch->multidir_output[$object->entity].
'/'.
get_exdir(0, 0, 0, 1, $object, $modulepart);
97 if (empty($filearray)) {
99 $object->fetch($id, $productid, $batch);
104 $hookmanager->initHooks(array(
'productlotcard',
'globalcard'));
107 $permissionnote = $user->rights->stock->creer;
108 $permissiondellink = $user->rights->stock->creer;
109 $permissiontoadd = $user->rights->stock->creer;
111 $usercanread = $user->rights->produit->lire;
112 $usercancreate = $user->rights->produit->creer;
113 $usercandelete = $user->rights->produit->supprimer;
115 $upload_dir = $conf->productbatch->multidir_output[$conf->entity];
117 $permissiontoread = $usercanread;
118 $permissiontoadd = $usercancreate;
122 if (empty($conf->productbatch->enabled)) {
126 if ($user->socid > 0) {
138 $parameters = array();
139 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
144 if (empty($reshook)) {
147 $backurlforlist =
dol_buildpath(
'/product/stock/productlot_list.php', 1);
149 if ($action ==
'seteatby' && $user->rights->stock->creer && !
GETPOST(
'cancel',
'alpha')) {
151 $result = $object->setValueFrom(
'eatby', $newvalue,
'',
null,
'date',
'', $user,
'PRODUCTLOT_MODIFY');
154 $action ==
'editeatby';
160 if ($action ==
'setsellby' && $user->rights->stock->creer && !
GETPOST(
'cancel',
'alpha')) {
162 $result = $object->setValueFrom(
'sellby', $newvalue,
'',
null,
'date',
'', $user,
'PRODUCTLOT_MODIFY');
165 $action ==
'editsellby';
171 if ($action ==
'seteol_date' && $user->rights->stock->creer && !
GETPOST(
'cancel',
'alpha')) {
173 $result = $object->setValueFrom(
'eol_date', $newvalue,
'',
null,
'date',
'', $user,
'PRODUCTLOT_MODIFY');
176 $action ==
'editeol_date';
182 if ($action ==
'setmanufacturing_date' && $user->rights->stock->creer && !
GETPOST(
'cancel',
'alpha')) {
183 $newvalue =
dol_mktime(12, 0, 0,
GETPOST(
'manufacturing_datemonth',
'int'),
GETPOST(
'manufacturing_dateday',
'int'),
GETPOST(
'manufacturing_dateyear',
'int'));
184 $result = $object->setValueFrom(
'manufacturing_date', $newvalue,
'',
null,
'date',
'', $user,
'PRODUCTLOT_MODIFY');
187 $action ==
'editmanufacturing_date';
193 if ($action ==
'setscrapping_date' && $user->rights->stock->creer && !
GETPOST(
'cancel',
'alpha')) {
195 $result = $object->setValueFrom(
'scrapping_date', $newvalue,
'',
null,
'date',
'', $user,
'PRODUCTLOT_MODIFY');
198 $action ==
'editscrapping_date';
215 if ($action ==
'setqc_frequency' && $user->rights->stock->creer && !
GETPOST(
'cancel',
'alpha')) {
216 $result = $object->setValueFrom(
'qc_frequency',
GETPOST(
'qc_frequency'),
'',
null,
'int',
'', $user,
'PRODUCT_MODIFY');
219 $action ==
'editqc_frequency';
225 $triggermodname =
'PRODUCT_LOT_MODIFY';
228 include DOL_DOCUMENT_ROOT.
'/core/actions_addupdatedelete.inc.php';
355 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
358 $triggersendname =
'PRODUCT_LOT_SENTBYMAIL';
359 $autocopy =
'MAIN_MAIL_AUTOCOPY_PRODUCT_LOT_TO';
360 $trackid =
'productlot'.$object->id;
361 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
374 $title = $langs->trans(
"ProductLot");
381 if ($action ==
'create') {
382 print
load_fiche_titre($langs->trans(
"Batch"),
'',
'object_'.$object->picto);
384 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
385 print
'<input type="hidden" name="token" value="'.newToken().
'">';
386 print
'<input type="hidden" name="action" value="add">';
388 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
390 if ($backtopageforcancel) {
391 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
396 print
'<table class="border centpercent tableforfieldcreate">'.
"\n";
399 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_add.tpl.php';
402 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
404 print
'</table>'.
"\n";
408 print
$form->buttonsSaveCancel(
"Create");
417 if ($object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
418 $res = $object->fetch_optionals();
426 if ($action ==
'delete') {
427 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteBatch'), $langs->trans(
'ConfirmDeleteBatch'),
'confirm_delete',
'', 0, 1);
431 $parameters = array(
'formConfirm' =>
$formconfirm,
'lineid' => $lineid);
432 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
433 if (empty($reshook)) {
435 } elseif ($reshook > 0) {
444 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/stock/productlot_list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
447 if ($user->socid && !in_array(
'batch', explode(
',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
453 dol_banner_tab($object,
'id', $linkback, $shownav,
'rowid',
'batch', $morehtmlref);
455 print
'<div class="fichecenter">';
456 print
'<div class="underbanner clearboth"></div>';
457 print
'<table class="border centpercent tableforfield">'.
"\n";
460 print
'<tr><td class="titlefield">'.$langs->trans(
"Product").
'</td><td>';
461 $producttmp =
new Product($db);
462 $producttmp->fetch($object->fk_product);
463 print $producttmp->getNomUrl(1,
'stock').
" - ".$producttmp->label;
467 if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
469 print
$form->editfieldkey($langs->trans(
'SellByDate'),
'sellby', $object->sellby, $object, $user->rights->stock->creer,
'datepicker');
471 print
$form->editfieldval($langs->trans(
'SellByDate'),
'sellby', $object->sellby, $object, $user->rights->stock->creer,
'datepicker');
477 if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
479 print
$form->editfieldkey($langs->trans(
'EatByDate'),
'eatby', $object->eatby, $object, $user->rights->stock->creer,
'datepicker');
481 print
$form->editfieldval($langs->trans(
'EatByDate'),
'eatby', $object->eatby, $object, $user->rights->stock->creer,
'datepicker');
486 if (!empty($conf->global->PRODUCT_LOT_ENABLE_TRACEABOLITY)) {
487 print
'<tr><td>'.$form->editfieldkey($langs->trans(
'ManufacturingDate'),
'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer).
'</td>';
488 print
'<td>'.$form->editfieldval($langs->trans(
'ManufacturingDate'),
'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer,
'datepicker').
'</td>';
493 print
'<tr><td>'.$form->editfieldkey($langs->trans(
'DestructionDate'),
'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer).
'</td>';
494 print
'<td>'.$form->editfieldval($langs->trans(
'DestructionDate'),
'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer,
'datepicker').
'</td>';
499 if (!empty($conf->global->PRODUCT_LOT_ENABLE_QUALITY_CONTROL)) {
500 print
'<tr><td>'.$form->editfieldkey($langs->trans(
'EndOfLife'),
'eol_date', $object->eol_date, $object, $user->rights->stock->creer).
'</td>';
501 print
'<td>'.$form->editfieldval($langs->trans(
'EndOfLife'),
'eol_date', $object->eol_date, $object, $user->rights->stock->creer,
'datepicker').
'</td>';
503 print
'<tr><td>'.$form->editfieldkey($langs->trans(
'QCFrequency'),
'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer).
'</td>';
504 print
'<td>'.$form->editfieldval($langs->trans(
'QCFrequency'),
'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer,
'numeric').
'</td>';
509 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
515 print
'<div class="clearboth"></div>';
520 print
'<a href="'.DOL_URL_ROOT.
'/product/reassortlot.php?sref='.urlencode($producttmp->ref).
'&search_batch='.urlencode($object->batch).
'">'.$langs->trans(
"ShowCurrentStockOfLot").
'</a><br>';
522 print
'<a href="'.DOL_URL_ROOT.
'/product/stock/movement_list.php?search_product_ref='.urlencode($producttmp->ref).
'&search_batch='.urlencode($object->batch).
'">'.$langs->trans(
"ShowLogOfMovementIfLot").
'</a><br>';
528 if ($action !=
'presend' && $action !=
'editline') {
529 print
'<div class="tabsAction">'.
"\n";
530 $parameters = array();
531 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
536 if (empty($reshook)) {
559 if ($action !=
'presend') {
560 print
'<div class="fichecenter"><div class="fichehalfleft">';
561 print
'<a name="builddoc"></a>';
563 $includedocgeneration = 1;
566 if ($includedocgeneration) {
568 $relativepath = $objref.
'/'.$objref.
'.pdf';
569 $filedir = $conf->productbatch->multidir_output[$object->entity].
'/'.
get_exdir(0, 0, 0, 1, $object,
'product_batch');
570 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
571 $genallowed = $usercanread;
572 $delallowed = $usercancreate;
573 print $formfile->showdocuments(
'product_batch', $objref, $filedir, $urlsource, $genallowed, $delallowed,
'', 0, 0, 0, 28, 0,
'', 0,
'', $langs->default_lang,
'', $object);
576 print
'</div><div class="fichehalfright">';
580 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
582 $somethingshown =
$formactions->showactions($object,
'productlot', 0, 1,
'', $MAXEVENT);
584 print
'</div></div>';