24 require
'../../main.inc.php';
25 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
26 include_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
27 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
28 include_once DOL_DOCUMENT_ROOT.
'/product/inventory/class/inventory.class.php';
29 include_once DOL_DOCUMENT_ROOT.
'/product/inventory/lib/inventory.lib.php';
32 $langs->loadLangs(array(
"stocks",
"other",
"productbatch"));
37 $action =
GETPOST(
'action',
'aZ09');
38 $confirm =
GETPOST(
'confirm',
'alpha');
39 $cancel =
GETPOST(
'cancel',
'aZ09');
40 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'inventorycard';
41 $backtopage =
GETPOST(
'backtopage',
'alpha');
43 $fk_warehouse =
GETPOST(
'fk_warehouse',
'int');
44 $fk_product =
GETPOST(
'fk_product',
'int');
45 $lineid =
GETPOST(
'lineid',
'int');
46 $batch =
GETPOST(
'batch',
'alphanohtml');
48 if (empty($conf->global->MAIN_USE_ADVANCED_PERMS))
52 $result =
restrictedArea($user,
'stock', $id,
'',
'inventory_advance');
58 $diroutputmassaction = $conf->stock->dir_output.
'/temp/massgeneration/'.$user->id;
59 $hookmanager->initHooks(array(
'inventorycard'));
62 $extrafields->fetch_name_optionals_label($object->table_element);
64 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element,
'',
'search_');
67 $search_all =
GETPOST(
"search_all",
'alpha');
69 foreach ($object->fields as $key => $val)
71 if (
GETPOST(
'search_'.$key,
'alpha')) $search[$key] =
GETPOST(
'search_'.$key,
'alpha');
74 if (empty($action) && empty($id) && empty($ref)) $action =
'view';
77 include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
84 if (empty($conf->global->MAIN_USE_ADVANCED_PERMS))
86 $permissiontoadd = $user->rights->stock->creer;
87 $permissiontodelete = $user->rights->stock->supprimer;
89 $permissiontoadd = $user->rights->stock->inventory_advance->write;
90 $permissiontodelete = $user->rights->stock->inventory_advance->write;
100 $parameters = array();
101 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
102 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
108 $backurlforlist = DOL_URL_ROOT.
'/product/inventory/list.php';
109 $backtopage = DOL_URL_ROOT.
'/product/inventory/inventory.php?id='.$object->id;
112 include DOL_DOCUMENT_ROOT.
'/core/actions_addupdatedelete.inc.php';
115 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
118 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
126 if (
GETPOST(
'addline',
'alpha')) {
127 if ($fk_warehouse <= 0) {
129 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Warehouse")), null,
'errors');
131 if ($fk_product <= 0) {
133 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Product")), null,
'errors');
136 if (!$error && !empty($conf->productbatch->enabled)) {
137 $tmpproduct =
new Product($db);
138 $result = $tmpproduct->fetch($fk_product);
140 if (!$error && $tmpproduct->status_batch && !$batch) {
142 $langs->load(
"errors");
143 setEventMessages($langs->trans(
"ErrorProductNeedBatchNumber", $tmpproduct->ref), null,
'errors');
145 if (!$error && !$tmpproduct->status_batch && $batch) {
147 $langs->load(
"errors");
148 setEventMessages($langs->trans(
"ErrorProductDoesNotNeedBatchNumber", $tmpproduct->ref), null,
'errors');
153 $tmp->fk_inventory = $object->id;
154 $tmp->fk_warehouse = $fk_warehouse;
155 $tmp->fk_product = $fk_product;
156 $tmp->batch = $batch;
159 $result = $tmp->create($user);
161 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
178 $form =
new Form($db);
181 llxHeader(
'', $langs->trans(
'Inventory'),
'');
184 print '<script type="text/javascript" language="javascript">
185 jQuery(document).ready(function() {
186 function init_myfunc()
188 jQuery("#myid").removeAttr(\'disabled\');
189 jQuery("#myid").attr(\'disabled\',\'disabled\');
192 jQuery("#mybutton").click(function() {
202 $res = $object->fetch_optionals();
205 print
dol_get_fiche_head($head,
'inventory', $langs->trans(
"Inventory"), -1,
'stock');
210 if ($action ==
'delete') {
211 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteInventory'), $langs->trans(
'ConfirmDeleteOrder'),
'confirm_delete',
'', 0, 1);
214 if ($action ==
'deleteline')
216 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteLine'), $langs->trans(
'ConfirmDeleteLine'),
'confirm_deleteline',
'', 0, 1);
220 if ($action ==
'clone') {
222 $formquestion = array();
223 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneMyObject', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
227 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
228 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
229 if (empty($reshook)) $formconfirm .= $hookmanager->resPrint;
230 elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint;
238 $linkback = '<a href="'.DOL_URL_ROOT.'/product/inventory/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
240 $morehtmlref = '<div class="refidno">';
280 $morehtmlref .= '</div>';
283 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
286 print '<div class="fichecenter">';
287 print '<div class="fichehalfleft">';
288 print '<div class="underbanner clearboth"></div>';
289 print '<table class="border centpercent tableforfield">'."\
n";
292 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
295 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
301 print '<div class="clearboth"></div>';
307 if ($action == 'record') {
308 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
309 print
'<input type="hidden" name="token" value="'.newToken().
'">';
310 print
'<input type="hidden" name="action" value="update">';
311 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
312 if ($backtopage) print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
314 print
'<div class="center">';
315 print
'<span class="opacitymedium">'.$langs->trans(
"InventoryDesc").
'</span><br>';
316 print
'<input type="submit" class="button button-save" name="save" value="'.$langs->trans(
"Save").
'">';
318 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
323 print
'<div class="tabsAction">'.
"\n";
324 $parameters = array();
325 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
326 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
330 if ($object->status == Inventory::STATUS_DRAFT)
332 if ($permissiontoadd)
334 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=confirm_validate&confirm=yes">'.$langs->trans(
"Validate").
' ('.$langs->trans(
"Start").
')</a>'.
"\n";
336 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">'.$langs->trans(
'Validate').
' ('.$langs->trans(
"Start").
')</a>'.
"\n";
340 if ($object->status == Inventory::STATUS_VALIDATED)
342 if ($permissiontoadd)
351 if (!empty($conf->barcode->enabled) || !empty($conf->productbatch->enabled)) {
352 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=updatebyscaning" class="butAction">'.$langs->trans(
"UpdateByScaning").
'</a>';
355 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">'.$langs->trans(
"Save").
'</a>'.
"\n";
359 if ($object->status == Inventory::STATUS_VALIDATED)
361 if ($permissiontoadd)
363 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=record">'.$langs->trans(
"Finish").
'</a>'.
"\n";
365 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">'.$langs->trans(
'Finish').
'</a>'.
"\n";
384 if ($action ==
'updatebyscaning') {
385 print
'<div class="div-for-modal">';
393 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
394 print
'<input type="hidden" name="token" value="'.newToken().
'">';
395 print
'<input type="hidden" name="action" value="updateinventorylines">';
396 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
397 if ($backtopage) print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
399 print
'<div class="fichecenter">';
401 print
'<div class="clearboth"></div>';
405 print
'<div class="div-table-responsive-no-min">';
406 print
'<table id="tablelines" class="noborder noshadow centpercent">';
408 print
'<tr class="liste_titre">';
409 print
'<td>'.$langs->trans(
"Warehouse").
'</td>';
410 print
'<td>'.$langs->trans(
"Product").
'</td>';
411 if ($conf->productbatch->enabled) {
413 print $langs->trans(
"Batch");
416 print
'<td class="right">'.$langs->trans(
"ExpectedQty").
'</td>';
417 print
'<td class="center">';
418 print $form->textwithpicto($langs->trans(
"RealQty"), $langs->trans(
"InventoryRealQtyHelp"));
421 print
'<td class="center">';
426 if ($object->status == $object::STATUS_VALIDATED) {
429 print $formproduct->selectWarehouses((
GETPOSTISSET(
'fk_warehouse') ?
GETPOST(
'fk_warehouse',
'int') : $object->fk_warehouse),
'fk_warehouse',
'warehouseopen', 1, 0, 0,
'', 0, 0, array(),
'maxwidth300');
432 print $form->select_produits((
GETPOSTISSET(
'fk_product') ?
GETPOST(
'fk_product',
'int') : $object->fk_product),
'fk_product',
'', 0, 0, 1, 2,
'', 0, null, 0,
'1', 0,
'maxwidth300');
434 if ($conf->productbatch->enabled) {
436 print
'<input type="text" name="batch" class="maxwidth100" value="'.(GETPOSTISSET(
'batch') ?
GETPOST(
'batch') :
'').
'">';
439 print
'<td class="right"></td>';
440 print
'<td class="center">';
441 print
'<input type="submit" class="button paddingrightonly" name="addline" value="'.$langs->trans(
"Add").
'">';
445 print
'<td class="center">';
451 $sql =
'SELECT id.rowid, id.datec as date_creation, id.tms as date_modification, id.fk_inventory, id.fk_warehouse,';
452 $sql .=
' id.fk_product, id.batch, id.qty_stock, id.qty_view, id.qty_regulated';
453 $sql .=
' FROM '.MAIN_DB_PREFIX.
'inventorydet as id';
454 $sql .=
' WHERE id.fk_inventory = '.$object->id;
456 $cacheOfProducts = array();
457 $cacheOfWarehouses = array();
460 $resql = $db->query($sql);
463 $num = $db->num_rows(
$resql);
466 $totalarray = array();
469 $obj = $db->fetch_object(
$resql);
471 if (is_object($cacheOfWarehouses[$obj->fk_warehouse])) {
472 $warehouse_static = $cacheOfWarehouses[$obj->fk_warehouse];
474 $warehouse_static =
new Entrepot($db);
475 $warehouse_static->fetch($obj->fk_warehouse);
477 $cacheOfWarehouses[$warehouse_static->id] = $warehouse_static;
480 if (is_object($cacheOfProducts[$obj->fk_product])) {
481 $product_static = $cacheOfProducts[$obj->fk_product];
483 $product_static =
new Product($db);
484 $product_static->fetch($obj->fk_product);
487 $option .=
',novirtual';
488 $product_static->load_stock($option);
490 $cacheOfProducts[$product_static->id] = $product_static;
493 print
'<tr class="oddeven">';
495 print $warehouse_static->getNomUrl(1);
498 print $product_static->getNomUrl(1);
501 if ($conf->productbatch->enabled) {
507 print
'<td class="right">';
510 print
'<td class="center">';
511 print
'<input type="text" class="maxwidth75" name="id_'.$obj->rowid.
' value="'.
GETPOST(
"id_".$obj->rowid).
'">';
513 print
'<td class="right">';
514 print
'<a class="reposition" href="'.DOL_URL_ROOT.
'/product/inventory/inventory.php?id='.$object->id.
'&lineid='.$obj->rowid.
'&action=deleteline&token='.
newToken().
'">'.
img_delete().
'</a>';
528 if ($object->status == $object::STATUS_VALIDATED) {
529 print
'<div class="center">';
530 print
'<input type="submit" class="button button-save" name="save" value="'.$langs->trans(
"Save").
'">';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
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.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
inventoryPrepareHead(&$inventory, $title= 'Inventory', $get= '')
Define head array for tabs of inventory tools setup pages.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
print $_SERVER["PHP_SELF"] n
Edit parameters.
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.
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
Class to manage warehouses.