Merge pull request #20298 from atm-lena/develop_NEW_InventoryProduct_AddPage

Add paging to inventory card
This commit is contained in:
Laurent Destailleur 2022-09-10 09:49:44 +02:00 committed by GitHub
commit 99e0b5e945
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 72 additions and 33 deletions

View File

@ -386,7 +386,7 @@ if ($action == 'confirm_deleteline' && $confirm == 'yes' && !empty($permissionto
setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs');
if (empty($noback)) {
header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
header('Location: '.((empty($backtopage)) ? $_SERVER["PHP_SELF"].'?id='.$object->id : $backtopage));
exit;
}
} else {

View File

@ -42,6 +42,15 @@ $confirm = GETPOST('confirm', 'alpha');
$cancel = GETPOST('cancel', 'aZ09');
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'inventorycard'; // To manage different context of search
$backtopage = GETPOST('backtopage', 'alpha');
$listoffset = GETPOST('listoffset', 'alpha');
$limit = GETPOST('limit', 'int') > 0 ?GETPOST('limit', 'int') : $conf->liste_limit;
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) {
$page = 0;
}
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
$fk_warehouse = GETPOST('fk_warehouse', 'int');
$fk_product = GETPOST('fk_product', 'int');
@ -87,6 +96,14 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be includ
//if ($user->socid > 0) $socid = $user->socid;
//$result = restrictedArea($user, 'mymodule', $id);
//Parameters Page
$param = '&id='.$object->id;
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
$paramwithsearch = $param;
if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
$permissiontoadd = $user->rights->stock->creer;
$permissiontodelete = $user->rights->stock->supprimer;
@ -98,6 +115,7 @@ if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
$now = dol_now();
/*
* Actions
*/
@ -247,6 +265,7 @@ if (empty($reshook)) {
$sql .= ' id.fk_product, id.batch, id.qty_stock, id.qty_view, id.qty_regulated';
$sql .= ' FROM '.MAIN_DB_PREFIX.'inventorydet as id';
$sql .= ' WHERE id.fk_inventory = '.((int) $object->id);
$sql .= $db->plimit($limit, $offset);
$db->begin();
@ -297,7 +316,7 @@ if (empty($reshook)) {
}
}
// Update user that update quantities
// Update line with id of stock movement (and the start quantity if it has changed this last recording)
if (! $error) {
$sqlupdate = "UPDATE ".MAIN_DB_PREFIX."inventory";
$sqlupdate .= " SET fk_user_modif = ".((int) $user->id);
@ -316,9 +335,8 @@ if (empty($reshook)) {
}
}
$backurlforlist = DOL_URL_ROOT.'/product/inventory/list.php';
$backtopage = DOL_URL_ROOT.'/product/inventory/inventory.php?id='.$object->id;
$backtopage = DOL_URL_ROOT.'/product/inventory/inventory.php?id='.$object->id.'&page='.$page.$paramwithsearch;
// Actions cancel, add, update, delete or clone
include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
@ -409,30 +427,6 @@ $help_url = '';
llxHeader('', $langs->trans('Inventory'), $help_url);
// Disable button Generate movement if data were modified and not saved
print '<script type="text/javascript">
function disablebuttonmakemovementandclose() {
console.log("Disable button idbuttonmakemovementandclose until we save");
jQuery("#idbuttonmakemovementandclose").attr(\'disabled\',\'disabled\');
jQuery("#idbuttonmakemovementandclose").attr(\'onclick\', \'return false;\');
jQuery("#idbuttonmakemovementandclose").attr(\'title\',\''.dol_escape_js($langs->trans("SaveQtyFirst")).'\');
jQuery("#idbuttonmakemovementandclose").attr(\'class\',\'butActionRefused classfortooltip\');
};
jQuery(document).ready(function() {
jQuery(".realqty").keyup(function() {
console.log("keyup on realqty");
disablebuttonmakemovementandclose();
});
jQuery(".realqty").change(function() {
console.log("change on realqty");
disablebuttonmakemovementandclose();
});
});
</script>';
// Part to show record
if ($object->id > 0) {
$res = $object->fetch_optionals();
@ -448,7 +442,7 @@ if ($object->id > 0) {
}
// Confirmation to delete line
if ($action == 'deleteline') {
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
$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
@ -554,8 +548,7 @@ if ($object->id > 0) {
print dol_get_fiche_end();
print '<form id="formrecord" name="formrecord" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<form id="formrecord" name="formrecord" method="POST" action="'.$_SERVER["PHP_SELF"].'?page='.$page.'&id='.$object->id.'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="updateinventorylines">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
@ -980,6 +973,7 @@ if ($object->id > 0) {
$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->plimit($limit, $offset);
$cacheOfProducts = array();
$cacheOfWarehouses = array();
@ -989,6 +983,10 @@ if ($object->id > 0) {
if ($resql) {
$num = $db->num_rows($resql);
if (!empty($limit != 0) || $num > $limit || $page) {
print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num >= $limit), '<li class="pagination"><span>' . $langs->trans("Page") . ' ' . ($page + 1) . '</span></li>', '', $limit);
}
$i = 0;
$hasinput = false;
$totalarray = array();
@ -1109,7 +1107,7 @@ if ($object->id > 0) {
// Picto delete line
print '<td class="right">';
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>';
print '<a class="reposition" href="'.DOL_URL_ROOT.'/product/inventory/inventory.php?id='.$object->id.'&lineid='.$obj->rowid.'&action=deleteline&page='.$page.$paramwithsearch.'&token='.newToken().'">'.img_delete().'</a>';
$qty_tmp = price2num(GETPOST("id_".$obj->rowid."_input_tmp", 'MS')) >= 0 ? GETPOST("id_".$obj->rowid."_input_tmp") : $qty_view;
print '<input type="hidden" class="maxwidth50 right realqty" name="id_'.$obj->rowid.'_input_tmp" id="id_'.$obj->rowid.'_input_tmp" value="'.$qty_tmp.'">';
print '</td>';
@ -1194,6 +1192,48 @@ if ($object->id > 0) {
}
print '</form>';
print '<script type="text/javascript">
$(document).ready(function() {
$(".paginationnext:last").click(function(e){
var form = $("#formrecord");
var actionURL = "'.$_SERVER['PHP_SELF']."?page=".($page).$paramwithsearch.'";
$.ajax({
url: actionURL,
data: form.serialize(),
cache: false,
success: function(result){
window.location.href = "'.$_SERVER['PHP_SELF']."?page=".($page + 1).$paramwithsearch.'";
}});
});
$(".paginationprevious:last").click(function(e){
var form = $("#formrecord");
var actionURL = "'.$_SERVER['PHP_SELF']."?page=".($page).$paramwithsearch.'";
$.ajax({
url: actionURL,
data: form.serialize(),
cache: false,
success: function(result){
window.location.href = "'.$_SERVER['PHP_SELF']."?page=".($page - 1).$paramwithsearch.'";
}});
});
$("#idbuttonmakemovementandclose").click(function(e){
var form = $("#formrecord");
var actionURL = "'.$_SERVER['PHP_SELF']."?page=".($page).$paramwithsearch.'";
$.ajax({
url: actionURL,
data: form.serialize(),
cache: false,
success: function(result){
window.location.href = "'.$_SERVER['PHP_SELF']."?page=".($page - 1).$paramwithsearch.'&action=record";
}});
});
});
</script>';
if (!empty($conf->global->INVENTORY_MANAGE_REAL_PMP)) {
?>

View File

@ -685,7 +685,6 @@ if ($search_dateclose_end) {
$param .= '&search_date_endmonth='.urlencode($tmparray['mon']);
$param .= '&search_date_endyear='.urlencode($tmparray['year']);
}
// List of mass actions available
$arrayofmassactions = array(
//'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),