26 require
'../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/productlot.class.php';
35 $langs->loadLangs(array(
'stocks',
'other',
'productbatch'));
39 $action =
GETPOST(
'action',
'alpha');
40 $backtopage =
GETPOST(
'backtopage',
'alpha');
41 $batch =
GETPOST(
'batch',
'alpha');
42 $productid =
GETPOST(
'productid',
'int');
45 $search_entity =
GETPOST(
'search_entity',
'int');
46 $search_fk_product =
GETPOST(
'search_fk_product',
'int');
47 $search_batch =
GETPOST(
'search_batch',
'alpha');
48 $search_fk_user_creat =
GETPOST(
'search_fk_user_creat',
'int');
49 $search_fk_user_modif =
GETPOST(
'search_fk_user_modif',
'int');
50 $search_import_key =
GETPOST(
'search_import_key',
'int');
52 if (empty($action) && empty($id) && empty($ref)) $action =
'list';
63 $object =
new ProductLot($db);
68 $extrafields->fetch_name_optionals_label($object->table_element);
76 $tmp = explode(
'_', $ref);
80 $object->fetch($id, $productid, $batch);
81 $object->ref = $object->batch;
85 $hookmanager->initHooks(array(
'productlotcard',
'globalcard'));
88 $permissionnote = $user->rights->stock->creer;
89 $permissiondellink = $user->rights->stock->creer;
90 $permissiontoadd = $user->rights->stock->creer;
92 $usercanread = $user->rights->produit->lire;
93 $usercancreate = $user->rights->produit->creer;
94 $usercandelete = $user->rights->produit->supprimer;
100 $parameters = array();
101 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
102 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
106 if ($action ==
'seteatby' && $user->rights->stock->creer) {
108 $result = $object->setValueFrom(
'eatby', $newvalue,
'', null,
'date',
'', $user,
'PRODUCTLOT_MODIFY');
111 $action ==
'editeatby';
117 if ($action ==
'setsellby' && $user->rights->stock->creer) {
119 $result = $object->setValueFrom(
'sellby', $newvalue,
'', null,
'date',
'', $user,
'PRODUCTLOT_MODIFY');
122 $action ==
'editsellby';
128 if ($action ==
'update_extras')
133 $ret = $extrafields->setOptionalsFromPost(null, $object,
GETPOST(
'attribute',
'restricthtml'));
134 if ($ret < 0) $error++;
139 $result = $object->insertExtraFields(
'PRODUCT_LOT_MODIFY');
148 $action =
'edit_extras';
153 if ($action ==
'add')
155 if (
GETPOST(
'cancel',
'alpha'))
157 $urltogo = $backtopage ? $backtopage :
dol_buildpath(
'/stock/list.php', 1);
158 header(
"Location: ".$urltogo);
166 $object->entity =
GETPOST(
'entity',
'int');
167 $object->fk_product =
GETPOST(
'fk_product',
'int');
168 $object->batch =
GETPOST(
'batch',
'alpha');
169 $object->fk_user_creat =
GETPOST(
'fk_user_creat',
'int');
170 $object->fk_user_modif =
GETPOST(
'fk_user_modif',
'int');
171 $object->import_key =
GETPOST(
'import_key',
'int');
173 if (empty($object->ref))
176 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref")), null,
'errors');
181 $result = $object->create($user);
185 $urltogo = $backtopage ? $backtopage :
dol_buildpath(
'/stock/list.php', 1);
186 header(
"Location: ".$urltogo);
191 if (!empty($object->errors))
setEventMessages(null, $object->errors,
'errors');
201 if ($action ==
'update' &&
GETPOST(
'cancel',
'alpha')) $action =
'view';
204 if ($action ==
'update' && !
GETPOST(
'cancel',
'alpha'))
208 $object->entity =
GETPOST(
'entity',
'int');
209 $object->fk_product =
GETPOST(
'fk_product',
'int');
210 $object->batch =
GETPOST(
'batch',
'alpha');
211 $object->fk_user_creat =
GETPOST(
'fk_user_creat',
'int');
212 $object->fk_user_modif =
GETPOST(
'fk_user_modif',
'int');
213 $object->import_key =
GETPOST(
'import_key',
'int');
215 if (empty($object->ref))
218 setEventMessages($langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref")), null,
'errors');
223 $result = $object->update($user);
229 if (!empty($object->errors))
setEventMessages(null, $object->errors,
'errors');
239 if ($action ==
'confirm_delete')
241 $result = $object->delete($user);
249 if (!empty($object->errors))
setEventMessages(null, $object->errors,
'errors');
255 $upload_dir = $conf->productbatch->multidir_output[$conf->entity];
256 $permissiontoadd = $usercancreate;
257 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
269 $form =
new Form($db);
273 if ($action ==
'create')
277 print '<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
278 print '<input type="hidden" name="action" value="add">';
279 print '<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
283 print '<table class="border centpercent">'.
"\n";
286 print '<tr><td class="fieldrequired">'.$langs->trans(
"Fieldfk_product").
'</td><td><input class="flat" type="text" name="fk_product" value="'.
GETPOST(
'fk_product').
'"></td></tr>';
287 print '<tr><td class="fieldrequired">'.$langs->trans(
"Fieldbatch").
'</td><td><input class="flat" type="text" name="batch" value="'.
GETPOST(
'batch').
'"></td></tr>';
288 print '<tr><td class="fieldrequired">'.$langs->trans(
"Fieldfk_user_creat").
'</td><td><input class="flat" type="text" name="fk_user_creat" value="'.
GETPOST(
'fk_user_creat').
'"></td></tr>';
289 print '<tr><td class="fieldrequired">'.$langs->trans(
"Fieldfk_user_modif").
'</td><td><input class="flat" type="text" name="fk_user_modif" value="'.
GETPOST(
'fk_user_modif').
'"></td></tr>';
290 print '<tr><td class="fieldrequired">'.$langs->trans(
"Fieldimport_key").
'</td><td><input class="flat" type="text" name="import_key" value="'.
GETPOST(
'import_key').
'"></td></tr>';
292 print '</table>'.
"\n";
296 print '<div class="center"><input type="submit" class="button" name="add" value="'.$langs->trans(
"Create").
'"> <input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'"></div>';
303 if ($object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create')))
305 $res = $object->fetch_optionals();
313 if ($action ==
'delete') {
314 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteBatch'), $langs->trans(
'ConfirmDeleteBatch'),
'confirm_delete',
'', 0, 1);
319 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/stock/productlot_list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
322 if ($user->socid && !in_array(
'batch', explode(
',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0;
324 dol_banner_tab($object,
'id', $linkback, $shownav,
'rowid',
'batch');
326 print '<div class="fichecenter">';
327 print '<div class="underbanner clearboth"></div>';
329 print '<table class="border centpercent">'.
"\n";
332 print '<tr><td class="titlefield">'.$langs->trans(
"Product").
'</td><td>';
333 $producttmp =
new Product($db);
334 $producttmp->fetch($object->fk_product);
335 print $producttmp->getNomUrl(1,
'stock').
" - ".$producttmp->label;
339 if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
341 print $form->editfieldkey($langs->trans(
'EatByDate'),
'eatby', $object->eatby, $object, $user->rights->stock->creer,
'datepicker');
343 print $form->editfieldval($langs->trans(
'EatByDate'),
'eatby', $object->eatby, $object, $user->rights->stock->creer,
'datepicker');
349 if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
351 print $form->editfieldkey($langs->trans(
'SellByDate'),
'sellby', $object->sellby, $object, $user->rights->stock->creer,
'datepicker');
353 print $form->editfieldval($langs->trans(
'SellByDate'),
'sellby', $object->sellby, $object, $user->rights->stock->creer,
'datepicker');
358 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
368 print '<div class="tabsAction">'.
"\n";
369 $parameters = array();
370 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
371 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
389 print '<a href="'.DOL_URL_ROOT.
'/product/reassortlot.php?sref='.urlencode($producttmp->ref).
'&search_batch='.urlencode($object->batch).
'">'.$langs->trans(
"ShowCurrentStockOfLot").
'</a><br>';
391 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>';
402 if (empty($action) || $action ==
'view')
404 print '<div class="fichecenter"><div class="fichehalfleft">';
405 print '<a name="builddoc"></a>';
408 $filedir = $conf->productbatch->multidir_output[$object->entity].
'/'.
get_exdir(0, 0, 0, 0, $object,
'product_batch');
409 $urlsource =
$_SERVER[
"PHP_SELF"].
"?id=".$object->id;
410 $genallowed = $usercanread;
411 $delallowed = $usercancreate;
413 print $formfile->showdocuments(
'product_batch',
dol_sanitizeFileName($object->ref), $filedir, $urlsource, $genallowed, $delallowed,
'', 0, 0, 0, 28, 0,
'', 0,
'', $object->default_lang,
'', $object);
414 $somethingshown = $formfile->numoffiles;
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
productlot_prepare_head($object)
Prepare array with list of tabs.
Class to manage products or services.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart= '')
Return a path to have a the directory according to object where files are stored. ...
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.