From 6c589955a679506792676256fe992dff30c0054a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 1 Apr 2023 15:00:54 +0200 Subject: [PATCH] FIX Autofill / clear qty in inventory page --- htdocs/product/inventory/inventory.php | 1516 ++++++++++++------------ 1 file changed, 761 insertions(+), 755 deletions(-) diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php index 506b6e0c198..5f72928ed13 100644 --- a/htdocs/product/inventory/inventory.php +++ b/htdocs/product/inventory/inventory.php @@ -428,772 +428,779 @@ $help_url = ''; llxHeader('', $langs->trans('Inventory'), $help_url); // Part to show record -if ($object->id > 0) { - $res = $object->fetch_optionals(); - - $head = inventoryPrepareHead($object); - print dol_get_fiche_head($head, 'inventory', $langs->trans("Inventory"), -1, 'stock'); - - $formconfirm = ''; - - // Confirmation to delete - if ($action == 'delete') { - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteInventory'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1); - } - // Confirmation to delete line - if ($action == 'deleteline') { - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid.'&page='.$page.$paramwithsearch, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1); - } - - // Clone confirmation - if ($action == 'clone') { - // Create an array for form - $formquestion = array(); - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneMyObject', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); - } - - // Confirmation to close - if ($action == 'record') { - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Close'), $langs->trans('ConfirmFinish'), 'update', '', 0, 1); - $action = 'view'; - } - - // Confirmation to close - if ($action == 'confirm_cancel') { - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Cancel'), $langs->trans('ConfirmCancel'), 'cancel_record', '', 0, 1); - $action = 'view'; - } - - // Call Hook formConfirm - $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid); - $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) { - $formconfirm .= $hookmanager->resPrint; - } elseif ($reshook > 0) { - $formconfirm = $hookmanager->resPrint; - } - - // Print form confirm - print $formconfirm; +if ($object->id <= 0) { + dol_print_error('', 'Bad value for object id'); + exit; +} - // Object card - // ------------------------------------------------------------ - $linkback = ''.$langs->trans("BackToList").''; +$res = $object->fetch_optionals(); - $morehtmlref = '
'; - /* - // Ref bis - $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->inventory->creer, 'string', '', 0, 1); - $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->inventory->creer, 'string', '', null, null, '', 1); - // Thirdparty - $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1); - // Project - if (!empty($conf->project->enabled)) +$head = inventoryPrepareHead($object); +print dol_get_fiche_head($head, 'inventory', $langs->trans("Inventory"), -1, 'stock'); + +$formconfirm = ''; + +// Confirmation to delete +if ($action == 'delete') { + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteInventory'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1); +} +// Confirmation to delete line +if ($action == 'deleteline') { + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid.'&page='.$page.$paramwithsearch, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1); +} + +// Clone confirmation +if ($action == 'clone') { + // Create an array for form + $formquestion = array(); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneMyObject', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); +} + +// Confirmation to close +if ($action == 'record') { + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Close'), $langs->trans('ConfirmFinish'), 'update', '', 0, 1); + $action = 'view'; +} + +// Confirmation to close +if ($action == 'confirm_cancel') { + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Cancel'), $langs->trans('ConfirmCancel'), 'cancel_record', '', 0, 1); + $action = 'view'; +} + +// Call Hook formConfirm +$parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid); +$reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook +if (empty($reshook)) { + $formconfirm .= $hookmanager->resPrint; +} elseif ($reshook > 0) { + $formconfirm = $hookmanager->resPrint; +} + +// Print form confirm +print $formconfirm; + + +// Object card +// ------------------------------------------------------------ +$linkback = ''.$langs->trans("BackToList").''; + +$morehtmlref = '
'; +/* +// Ref bis +$morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->inventory->creer, 'string', '', 0, 1); +$morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->inventory->creer, 'string', '', null, null, '', 1); +// Thirdparty +$morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1); +// Project +if (!empty($conf->project->enabled)) +{ + $langs->load("projects"); + $morehtmlref.='
'.$langs->trans('Project') . ' '; + if ($user->rights->inventory->creer) { - $langs->load("projects"); - $morehtmlref.='
'.$langs->trans('Project') . ' '; - if ($user->rights->inventory->creer) + if ($action != 'classify') { - if ($action != 'classify') - { - $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; - if ($action == 'classify') { - //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); - $morehtmlref.='
'; - $morehtmlref.=''; - $morehtmlref.=''; - $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); - $morehtmlref.=''; - $morehtmlref.='
'; - } else { - $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); - } + $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; + if ($action == 'classify') { + //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); + $morehtmlref.='
'; + $morehtmlref.=''; + $morehtmlref.=''; + $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref.=''; + $morehtmlref.='
'; + } else { + $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); } + } + } else { + if (!empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref.=$proj->getNomUrl(); } else { - if (!empty($object->fk_project)) { - $proj = new Project($db); - $proj->fetch($object->fk_project); - $morehtmlref.=$proj->getNomUrl(); - } else { - $morehtmlref.=''; - } + $morehtmlref.=''; } } - */ - $morehtmlref .= '
'; +} +*/ +$morehtmlref .= '
'; - dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); +dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); - print '
'; - print '
'; - print '
'; - print ''."\n"; +print '
'; +print '
'; +print '
'; +print '
'."\n"; - // Common attributes - include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php'; +// Common attributes +include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php'; - // Other attributes. Fields from hook formObjectOptions and Extrafields. - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; +// Other attributes. Fields from hook formObjectOptions and Extrafields. +include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; - //print ''; +//print ''; - print '
'.$langs->trans("InventoryCode").'INV'.$object->id.'
'.$langs->trans("InventoryCode").'INV'.$object->id.'
'; - print '
'; - print '
'; +print ''; +print ''; +print ''; - print '
'; +print '
'; - print dol_get_fiche_end(); +print dol_get_fiche_end(); - print '
'; - print ''; - print ''; - print ''; - if ($backtopage) { - print ''; +print ''; +print ''; +print ''; +print ''; +if ($backtopage) { + print ''; +} + + +// Buttons for actions +if ($action != 'record') { + print '
'."\n"; + $parameters = array(); + $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } - - // Buttons for actions - if ($action != 'record') { - print '
'."\n"; - $parameters = array(); - $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if ($reshook < 0) { - setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - } - - if (empty($reshook)) { - if ($object->status == Inventory::STATUS_DRAFT) { - if ($permissiontoadd) { - print ''.$langs->trans("Validate").' ('.$langs->trans("Start").')'."\n"; - } else { - print ''.$langs->trans('Validate').' ('.$langs->trans("Start").')'."\n"; - } - } - - // Save - if ($object->status == $object::STATUS_VALIDATED) { - if ($permissiontoadd) { - print ''.$langs->trans("MakeMovementsAndClose").''."\n"; - } else { - print ''.$langs->trans('MakeMovementsAndClose').''."\n"; - } - - if ($permissiontoadd) { - print ''.$langs->trans("Cancel").''."\n"; - } - } - } - print '
'."\n"; - - if ($object->status != Inventory::STATUS_DRAFT && $object->status != Inventory::STATUS_VALIDATED) { - print '

'; - } - } - - - - if ($object->status == Inventory::STATUS_VALIDATED) { - print '
'; - if (!empty($conf->use_javascript_ajax)) { + if (empty($reshook)) { + if ($object->status == Inventory::STATUS_DRAFT) { if ($permissiontoadd) { - // Link to launch scan tool - if (isModEnabled('barcode') || isModEnabled('productbatch')) { - print ''.img_picto('', 'barcode', 'class="paddingrightonly"').$langs->trans("UpdateByScaning").''; - } - - // Link to autofill - print ''.img_picto('', 'autofill', 'class="paddingrightonly"').$langs->trans('AutofillWithExpected').''; - print ''; - - // Link to reset qty - print ''.img_picto('', 'eraser', 'class="paddingrightonly"').$langs->trans("ClearQtys").''; + print ''.$langs->trans("Validate").' ('.$langs->trans("Start").')'."\n"; } else { - print ''.$langs->trans("Save").''."\n"; + print ''.$langs->trans('Validate').' ('.$langs->trans("Start").')'."\n"; } } - print '
'; - print '
'; - print '
'; - } - - - // Popup for mass barcode scanning - if ($action == 'updatebyscaning') { - if ($permissiontoadd) { - // Output the javascript to manage the scanner tool. - print ''; + + // Link to reset qty + print ''.img_picto('', 'eraser', 'class="paddingrightonly"').$langs->trans("ClearQtys").''; + } else { + print ''.$langs->trans("Save").''."\n"; + } + } + print '
'; + print '
'; + print ''; +} + + +// Popup for mass barcode scanning +if ($action == 'updatebyscaning') { + if ($permissiontoadd) { + // Output the javascript to manage the scanner tool. + print ''; + if(BarcodeIsInProduct > 0){ + result = true; + } + return result; } - include DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; - $formother = new FormOther($db); - print $formother->getHTMLScannerForm("barcodescannerjs", 'all'); + '; + print ''; } + include DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; + $formother = new FormOther($db); + print $formother->getHTMLScannerForm("barcodescannerjs", 'all'); +} - //Call method to undo changes in real qty - print ''; +//Call method to undo changes in real qty +print ''; - print '
'; - //print '
'; - print '
'; +print '
'; +//print '
'; +print '
'; - //print load_fiche_titre($langs->trans('Consumption'), '', ''); +//print load_fiche_titre($langs->trans('Consumption'), '', ''); - print '
'; - print ''; +print '
'; +print '
'; - print ''; - print ''; - print ''; +print ''; +print ''; +print ''; +if (isModEnabled('productbatch')) { + print ''; +} +print ''; +if (!empty($conf->global->INVENTORY_MANAGE_REAL_PMP)) { + print ''; + print ''; + print ''; + print ''; + print ''; +} else { + print ''; +} +if ($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_VALIDATED) { + // Actions or link to stock movement + print ''; +} else { + // Actions or link to stock movement + print ''; +} +print ''; + +// Line to add a new line in inventory +if ($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_VALIDATED) { + print ''; + print ''; + print ''; if (isModEnabled('productbatch')) { print ''; } - print ''; + print ''; if (!empty($conf->global->INVENTORY_MANAGE_REAL_PMP)) { - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; } else { print ''; - } - if ($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_VALIDATED) { - // Actions or link to stock movement - print ''; - } else { - // Actions or link to stock movement - print ''; } + // Actions + print ''; print ''; +} - // Line to add a new line in inventory - if ($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_VALIDATED) { - print ''; - print ''; + print ''; - print ''; + if (isModEnabled('productbatch')) { - print ''; } - print ''; - if (!empty($conf->global->INVENTORY_MANAGE_REAL_PMP)) { - print ''; - print ''; - print ''; - print ''; + + // Expected quantity = Quantity in stock when we start inventory + print ''; + + // Real quantity + if ($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_VALIDATED) { + $qty_view = GETPOST("id_".$obj->rowid) && price2num(GETPOST("id_".$obj->rowid), 'MS') >= 0 ? GETPOST("id_".$obj->rowid) : $obj->qty_view; + + //if (!$hasinput && $qty_view !== null && $obj->qty_stock != $qty_view) { + if ($qty_view != '') { + $hasinput = true; + } + + if (!empty($conf->global->INVENTORY_MANAGE_REAL_PMP)) { + //PMP Expected + if (!empty($obj->pmp_expected)) $pmp_expected = $obj->pmp_expected; + else $pmp_expected = $product_static->pmp; + $pmp_valuation = $pmp_expected * $valuetoshow; + print ''; + print ''; + + print ''; + + //PMP Real + print ''; + print ''; + + $totalExpectedValuation += $pmp_valuation; + $totalRealValuation += $pmp_valuation_real; + } else { + print ''; + } + + // Picto delete line print ''; } else { - print ''; - } - // Actions - print ''; - print ''; - } - - // Request to show lines of inventory (prefilled after start/validate step) - $sql = 'SELECT id.rowid, id.datec as date_creation, id.tms as date_modification, id.fk_inventory, id.fk_warehouse,'; - $sql .= ' id.fk_product, id.batch, id.qty_stock, id.qty_view, id.qty_regulated, id.fk_movement, id.pmp_real, id.pmp_expected'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'inventorydet as id'; - $sql .= ' WHERE id.fk_inventory = '.((int) $object->id); - $sql .= $db->order('id.rowid', 'ASC'); - $sql .= $db->plimit($limit, $offset); - - $cacheOfProducts = array(); - $cacheOfWarehouses = array(); - - //$sql = ''; - $resql = $db->query($sql); - if ($resql) { - $num = $db->num_rows($resql); - - if (!empty($limit != 0) || $num > $limit || $page) { - print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num >= $limit), '', '', $limit); - } - - $i = 0; - $hasinput = false; - $totalarray = array(); - while ($i < $num) { - $obj = $db->fetch_object($resql); - - if (isset($cacheOfWarehouses[$obj->fk_warehouse])) { - $warehouse_static = $cacheOfWarehouses[$obj->fk_warehouse]; - } else { - $warehouse_static = new Entrepot($db); - $warehouse_static->fetch($obj->fk_warehouse); - - $cacheOfWarehouses[$warehouse_static->id] = $warehouse_static; - } - - // Load real stock we have now - $option = ''; - if (isset($cacheOfProducts[$obj->fk_product])) { - $product_static = $cacheOfProducts[$obj->fk_product]; - } else { - $product_static = new Product($db); - $result = $product_static->fetch($obj->fk_product, '', '', '', 1, 1, 1); - - //$option = 'nobatch'; - $option .= ',novirtual'; - $product_static->load_stock($option); // Load stock_reel + stock_warehouse. - - $cacheOfProducts[$product_static->id] = $product_static; - } - - print ''; - print ''; - print ''; - - if (isModEnabled('productbatch')) { - print ''; - } - - // Expected quantity = Quantity in stock when we start inventory - print ''; - - // Real quantity - if ($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_VALIDATED) { - $qty_view = GETPOST("id_".$obj->rowid) && price2num(GETPOST("id_".$obj->rowid), 'MS') >= 0 ? GETPOST("id_".$obj->rowid) : $obj->qty_view; - - //if (!$hasinput && $qty_view !== null && $obj->qty_stock != $qty_view) { - if ($qty_view != '') { - $hasinput = true; - } - - if (!empty($conf->global->INVENTORY_MANAGE_REAL_PMP)) { - //PMP Expected - if (!empty($obj->pmp_expected)) $pmp_expected = $obj->pmp_expected; - else $pmp_expected = $product_static->pmp; - $pmp_valuation = $pmp_expected * $valuetoshow; - print ''; - print ''; - - print ''; - - //PMP Real - print ''; - print ''; - - $totalExpectedValuation += $pmp_valuation; - $totalRealValuation += $pmp_valuation_real; - } else { - print ''; - } - - // Picto delete line + if (!empty($conf->global->INVENTORY_MANAGE_REAL_PMP)) { + //PMP Expected + if (!empty($obj->pmp_expected)) $pmp_expected = $obj->pmp_expected; + else $pmp_expected = $product_static->pmp; + $pmp_valuation = $pmp_expected * $valuetoshow; print ''; + print ''; + + print ''; + + //PMP Real + print ''; + print ''; + print ''; - print ''; - - print ''; - - //PMP Real - print ''; - print ''; - print ''; - } - if ($obj->fk_movement > 0) { - $stockmovment = new MouvementStock($db); - $stockmovment->fetch($obj->fk_movement); - print $stockmovment->getNomUrl(1, 'movements'); - } + print ''; } - print ''; - - $i++; + if ($obj->fk_movement > 0) { + $stockmovment = new MouvementStock($db); + $stockmovment->fetch($obj->fk_movement); + print $stockmovment->getNomUrl(1, 'movements'); + } + print ''; } - } else { - dol_print_error($db); - } - if (!empty($conf->global->INVENTORY_MANAGE_REAL_PMP)) { - print ''; - print ''; - print ''; - print ''; - print ''; print ''; + + $i++; } - print '
'.$langs->trans("Warehouse").''.$langs->trans("Product").'
'.$langs->trans("Warehouse").''.$langs->trans("Product").''; + print $langs->trans("Batch"); + print ''.$langs->trans("ExpectedQty").''.$langs->trans('PMPExpected').''.$langs->trans('ExpectedValuation').''.$form->textwithpicto($langs->trans("RealQty"), $langs->trans("InventoryRealQtyHelp")).''.$langs->trans('PMPReal').''.$langs->trans('RealValuation').''; + print $form->textwithpicto($langs->trans("RealQty"), $langs->trans("InventoryRealQtyHelp")); + print ''; + print ''; + //print $langs->trans("StockMovement"); + print '
'; + print $formproduct->selectWarehouses((GETPOSTISSET('fk_warehouse') ? GETPOST('fk_warehouse', 'int') : $object->fk_warehouse), 'fk_warehouse', 'warehouseopen', 1, 0, 0, '', 0, 0, array(), 'maxwidth300'); + print ''; + 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'); + print ''; - print $langs->trans("Batch"); + print ''; print ''.$langs->trans("ExpectedQty").''.$langs->trans('PMPExpected').''.$langs->trans('ExpectedValuation').''.$form->textwithpicto($langs->trans("RealQty"), $langs->trans("InventoryRealQtyHelp")).''.$langs->trans('PMPReal').''.$langs->trans('RealValuation').''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; - print $form->textwithpicto($langs->trans("RealQty"), $langs->trans("InventoryRealQtyHelp")); - print ''; - print ''; - //print $langs->trans("StockMovement"); + print ''; print ''; + print ''; + print '
'; - print $formproduct->selectWarehouses((GETPOSTISSET('fk_warehouse') ? GETPOST('fk_warehouse', 'int') : $object->fk_warehouse), 'fk_warehouse', 'warehouseopen', 1, 0, 0, '', 0, 0, array(), 'maxwidth300'); +// Request to show lines of inventory (prefilled after start/validate step) +$sql = 'SELECT id.rowid, id.datec as date_creation, id.tms as date_modification, id.fk_inventory, id.fk_warehouse,'; +$sql .= ' id.fk_product, id.batch, id.qty_stock, id.qty_view, id.qty_regulated, id.fk_movement, id.pmp_real, id.pmp_expected'; +$sql .= ' FROM '.MAIN_DB_PREFIX.'inventorydet as id'; +$sql .= ' WHERE id.fk_inventory = '.((int) $object->id); +$sql .= $db->order('id.rowid', 'ASC'); +$sql .= $db->plimit($limit, $offset); + +$cacheOfProducts = array(); +$cacheOfWarehouses = array(); + +//$sql = ''; +$resql = $db->query($sql); +if ($resql) { + $num = $db->num_rows($resql); + + if (!empty($limit != 0) || $num > $limit || $page) { + print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num >= $limit), '', '', $limit); + } + + $i = 0; + $hasinput = false; + $totalarray = array(); + while ($i < $num) { + $obj = $db->fetch_object($resql); + + if (isset($cacheOfWarehouses[$obj->fk_warehouse])) { + $warehouse_static = $cacheOfWarehouses[$obj->fk_warehouse]; + } else { + $warehouse_static = new Entrepot($db); + $warehouse_static->fetch($obj->fk_warehouse); + + $cacheOfWarehouses[$warehouse_static->id] = $warehouse_static; + } + + // Load real stock we have now + $option = ''; + if (isset($cacheOfProducts[$obj->fk_product])) { + $product_static = $cacheOfProducts[$obj->fk_product]; + } else { + $product_static = new Product($db); + $result = $product_static->fetch($obj->fk_product, '', '', '', 1, 1, 1); + + //$option = 'nobatch'; + $option .= ',novirtual'; + $product_static->load_stock($option); // Load stock_reel + stock_warehouse. + + $cacheOfProducts[$product_static->id] = $product_static; + } + + print '
'; + print $warehouse_static->getNomUrl(1); print ''; - 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'); + print ''; + print $product_static->getNomUrl(1).' - '.$product_static->label; print ''; - print ''; + print ''; + $batch_static = new Productlot($db); + $res = $batch_static->fetch(0, $product_static->id, $obj->batch); + if ($res) { + print $batch_static->getNomUrl(1); + } else { + print dol_escape_htmltag($obj->batch); + } print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + $valuetoshow = $obj->qty_stock; + // For inventory not yet close, we overwrite with the real value in stock now + if ($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_VALIDATED) { + if (isModEnabled('productbatch') && $product_static->hasbatch()) { + $valuetoshow = $product_static->stock_warehouse[$obj->fk_warehouse]->detail_batch[$obj->batch]->qty; + } else { + $valuetoshow = $product_static->stock_warehouse[$obj->fk_warehouse]->real; + } + } + print price2num($valuetoshow, 'MS'); + print ''; + print ''; + print price($pmp_expected); + print ''; + print ''; + print price($pmp_valuation); + print ''; + print ''; + print img_picto('', 'eraser', 'class="opacitymedium"'); + print ''; + print ''; + print ''; + + + if (!empty($obj->pmp_real)) $pmp_real = $obj->pmp_real; + else $pmp_real = $product_static->pmp; + $pmp_valuation_real = $pmp_real * $qty_view; + print ''; + print ''; + print ''; + print ''; + print ''; + print img_picto('', 'eraser', 'class="opacitymedium"'); + print ''; + print ''; + print ''; + print ''.img_delete().''; + $qty_tmp = price2num(GETPOST("id_".$obj->rowid."_input_tmp", 'MS')) >= 0 ? GETPOST("id_".$obj->rowid."_input_tmp") : $qty_view; + print ''; print ''; - print ''; - print ''; - print ''; - print '
'; - print $warehouse_static->getNomUrl(1); - print ''; - print $product_static->getNomUrl(1).' - '.$product_static->label; - print ''; - $batch_static = new Productlot($db); - $res = $batch_static->fetch(0, $product_static->id, $obj->batch); - if ($res) { - print $batch_static->getNomUrl(1); - } else { - print dol_escape_htmltag($obj->batch); - } - print ''; - $valuetoshow = $obj->qty_stock; - // For inventory not yet close, we overwrite with the real value in stock now - if ($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_VALIDATED) { - if (isModEnabled('productbatch') && $product_static->hasbatch()) { - $valuetoshow = $product_static->stock_warehouse[$obj->fk_warehouse]->detail_batch[$obj->batch]->qty; - } else { - $valuetoshow = $product_static->stock_warehouse[$obj->fk_warehouse]->real; - } - } - print price2num($valuetoshow, 'MS'); - print ''; - print ''; - print price($pmp_expected); - print ''; - print ''; - print price($pmp_valuation); - print ''; - print ''; - print img_picto('', 'eraser', 'class="opacitymedium"'); - print ''; - print ''; - print ''; - - - if (!empty($obj->pmp_real)) $pmp_real = $obj->pmp_real; - else $pmp_real = $product_static->pmp; - $pmp_valuation_real = $pmp_real * $qty_view; - print ''; - print ''; - print ''; - print ''; - print ''; - print img_picto('', 'eraser', 'class="opacitymedium"'); - print ''; - print ''; - print ''; - print ''.img_delete().''; - $qty_tmp = price2num(GETPOST("id_".$obj->rowid."_input_tmp", 'MS')) >= 0 ? GETPOST("id_".$obj->rowid."_input_tmp") : $qty_view; - print ''; + print price($pmp_expected); print ''; + print price($pmp_valuation); + print ''; + print $obj->qty_view; // qty found + print ''; + if (!empty($obj->pmp_real)) $pmp_real = $obj->pmp_real; + else $pmp_real = $product_static->pmp; + $pmp_valuation_real = $pmp_real * $obj->qty_view; + print price($pmp_real); + print ''; + print price($pmp_valuation_real); + print ''; + + $totalExpectedValuation += $pmp_valuation; + $totalRealValuation += $pmp_valuation_real; } else { - if (!empty($conf->global->INVENTORY_MANAGE_REAL_PMP)) { - //PMP Expected - if (!empty($obj->pmp_expected)) $pmp_expected = $obj->pmp_expected; - else $pmp_expected = $product_static->pmp; - $pmp_valuation = $pmp_expected * $valuetoshow; - print ''; - print price($pmp_expected); - print ''; - print price($pmp_valuation); - print ''; - print $obj->qty_view; // qty found - print ''; - if (!empty($obj->pmp_real)) $pmp_real = $obj->pmp_real; - else $pmp_real = $product_static->pmp; - $pmp_valuation_real = $pmp_real * $obj->qty_view; - print price($pmp_real); - print ''; - print price($pmp_valuation_real); - print ''; - - $totalExpectedValuation += $pmp_valuation; - $totalRealValuation += $pmp_valuation_real; - } else { - print ''; - print $obj->qty_view; // qty found - print ''; + print $obj->qty_view; // qty found print '
'.$langs->trans("Total").''.price($totalExpectedValuation).''.price($totalRealValuation).'
'; +} else { + dol_print_error($db); +} +if (!empty($conf->global->INVENTORY_MANAGE_REAL_PMP)) { + print ''; + print ''.$langs->trans("Total").''; + print ''.price($totalExpectedValuation).''; + print ''.price($totalRealValuation).''; + print ''; + print ''; +} +print ''; - print '
'; +print '
'; - if ($object->status == $object::STATUS_VALIDATED) { - print '
'; - } +if ($object->status == $object::STATUS_VALIDATED) { + print '
'; +} - print '
'; +print '
'; - // Call method to disable the button if no qty entered yet for inventory - - if ($object->status != $object::STATUS_VALIDATED || !$hasinput) { - print ''; - } - print ''; - +// Call method to disable the button if no qty entered yet for inventory +/* +if ($object->status != $object::STATUS_VALIDATED || !$hasinput) { print ''; +} +*/ + +print ''; + +print ''; +'; - if (!empty($conf->global->INVENTORY_MANAGE_REAL_PMP)) { - ?> - - global->INVENTORY_MANAGE_REAL_PMP)) { + ?> + +