From 3111b56b206ac14650cc4a49a2f966e20272e4f2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 21 Oct 2016 12:45:19 +0200 Subject: [PATCH] Fix navigation for list of product to bound. --- htdocs/accountancy/admin/productaccount.php | 157 ++++++++++---------- htdocs/product/list.php | 32 ++-- 2 files changed, 98 insertions(+), 91 deletions(-) diff --git a/htdocs/accountancy/admin/productaccount.php b/htdocs/accountancy/admin/productaccount.php index 7d640968eb1..598320bfd63 100644 --- a/htdocs/accountancy/admin/productaccount.php +++ b/htdocs/accountancy/admin/productaccount.php @@ -49,7 +49,7 @@ if (! $user->rights->accounting->bind->write) accessforbidden(); // search & action GETPOST -$action = GETPOST('action'); +$action = GETPOST('action', 'alpha'); $codeventil_buy = GETPOST('codeventil_buy', 'array'); $codeventil_sell = GETPOST('codeventil_sell', 'array'); $chk_prod = GETPOST('chk_prod', 'array'); @@ -65,28 +65,34 @@ $accounting_product_mode = GETPOST('accounting_product_mode', 'alpha'); $btn_changeaccount = GETPOST('changeaccount'); $btn_changetype = GETPOST('changetype'); -$sortfield = GETPOST('sortfield', 'alpha'); -$sortorder = GETPOST('sortorder', 'alpha'); -$page = GETPOST('page', 'int'); -if ($page < 0) - $page = 0; +$limit = GETPOST("limit")?GETPOST("limit","int"):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); +$sortfield = GETPOST("sortfield",'alpha'); +$sortorder = GETPOST("sortorder",'alpha'); +$page = GETPOST("page",'int'); +if ($page == -1) { $page = 0; } +$offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -// bug in page limit if ACCOUNTING_LIMIT_LIST_VENTILATION < $conf->liste_limit there is no pagination displayed ! -if (! empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) && $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION >= $conf->liste_limit) { - $limit = $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION; -} else { - $limit = GETPOST('limit') ? GETPOST('limit', 'int') : $conf->liste_limit; -} -$offset = $limit * $page; +if (! $sortfield) $sortfield="p.ref"; +if (! $sortorder) $sortorder="ASC"; -if (! $sortfield) { - $sortfield = "p.ref"; +if (empty($action)) $action='list'; + +$arrayfields=array(); + + +/* + * Actions + */ + +// Purge search criteria +if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All test are required to be compatible with all browsers +{ + $search_ref = ''; + $search_label = ''; + $search_desc = ''; } -if (! $sortorder) { - $sortorder = "ASC"; -} - + // Sales or Purchase mode ? if ($action == 'update') { if (! empty($btn_changetype)) { @@ -158,6 +164,12 @@ if ($action == 'update') { } } + + +/* + * View + */ + $form = new FormVentilation($db); // Defaut AccountingAccount RowId Product / Service @@ -175,44 +187,13 @@ $aacompta_prodbuy = (! empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $c $aacompta_servsell = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef")); $aacompta_prodsell = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef")); -// Purge search criteria -if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All test are required to be compatible with all browsers -{ - $search_ref = ''; - $search_label = ''; - $search_desc = ''; -} - - -/* - * View - */ - llxHeader('', $langs->trans("ProductsBinding")); -print ''; +$pcgver = $conf->global->CHARTOFACCOUNTS; $sql = "SELECT p.rowid, p.ref, p.label, p.description , p.accountancy_code_sell, p.accountancy_code_buy, p.tms, p.fk_product_type as product_type"; $sql .= " FROM " . MAIN_DB_PREFIX . "product as p"; $sql .= " WHERE ("; - -$pcgver = $conf->global->CHARTOFACCOUNTS; - if ($accounting_product_mode == 'ACCOUNTANCY_BUY' ? ' checked' : '') { $sql .= " p.accountancy_code_buy ='' OR p.accountancy_code_buy IS NULL"; $sql .= " OR (p.accountancy_code_buy IS NOT NULL AND p.accountancy_code_buy != '' AND p.accountancy_code_buy NOT IN @@ -222,39 +203,58 @@ if ($accounting_product_mode == 'ACCOUNTANCY_BUY' ? ' checked' : '') { $sql .= " OR (p.accountancy_code_sell IS NOT NULL AND p.accountancy_code_sell != '' AND p.accountancy_code_sell NOT IN (SELECT aa.account_number FROM " . MAIN_DB_PREFIX . "accounting_account as aa , " . MAIN_DB_PREFIX . "accounting_system as asy WHERE fk_pcg_version = asy.pcg_version AND asy.rowid = " . $pcgver . "))"; } - $sql .= ")"; - +if (! empty($conf->multicompany->enabled)) { + $sql.= ' AND p.entity IN ('.getEntity('product', 1).')'; +} // Add search filter like if (strlen(trim($search_ref))) { - $sql .= " AND (p.ref like '" . $search_ref . "%')"; + $sql .= natural_search("p.ref",$search_ref); } if (strlen(trim($search_label))) { - $sql .= " AND (p.label like '" . $search_label . "%')"; + $sql .= natural_search("p.label",$search_label); } if (strlen(trim($search_desc))) { - $sql .= " AND (p.description like '%" . $search_desc . "%')"; + $sql .= natural_search("p.description",$search_desc); } $sql .= $db->order($sortfield, $sortorder); - +$nbtotalofrecords = 0; +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) +{ + $result = $db->query($sql); + $nbtotalofrecords = $db->num_rows($result); +} $sql .= $db->plimit($limit + 1, $offset); dol_syslog("/accountancy/admin/productaccount.php:: sql=" . $sql, LOG_DEBUG); $result = $db->query($sql); -if ($result) { - $num_lines = $db->num_rows($result); +if ($result) +{ + $num = $db->num_rows($result); $i = 0; - print load_fiche_titre($langs->trans("ProductsBinding"), '', 'title_accountancy'); + $param=''; + if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; + if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; + if ($search_ref > 0) $param.="&search_desc=".urlencode($search_ref); + if ($search_label > 0) $param.="&search_desc=".urlencode($search_label); + if ($search_desc > 0) $param.="&search_desc=".urlencode($search_desc); + + print '
'; + if ($optioncss != '') print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print load_fiche_titre($langs->trans("ProductsBinding"), '', 'title_accountancy'); print '
'; print $langs->trans("InitAccountancyDesc") . '
'; print '
'; - print ''; - print ''; - print ''; - + // Select mode print ''; print ''; print ''; @@ -270,11 +270,17 @@ if ($result) { print '
'; print "
\n"; + + // Filter on categories + $moreforfilter=''; + $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; + $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields - print_barre_liste($langs->trans("ListOfProductsWithoutAccountingAccount"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num_lines, '', ''); + $texte=$langs->trans("ListOfProductsWithoutAccountingAccount"); + print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit); - print '
' . $langs->trans('Options') . '' . $langs->trans('Description') . '
'; + print '
'; print ''; print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder); print_liste_field_titre($langs->trans("Label"), $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder); @@ -292,12 +298,11 @@ if ($result) { print ''; print ''; - print ''; - print ''; - print ''; - + print ''; + print ''; + print ''; print ''; - print ''; @@ -305,7 +310,8 @@ if ($result) { $var = true; - while ( $i < min($num_lines, 250) ) { + while ($i < min($num,$limit)) + { $obj = $db->fetch_object($result); $var = ! $var; @@ -374,14 +380,15 @@ if ($result) { } // Checkbox select - print ''; - print ""; $i ++; } print '
 '; + print ''; $searchpitco=$form->showFilterAndCheckAddButtons(1, 'checkforselect', 1); print $searchpitco; print ''; + print ''; print '
'; - print '
'; + + print '
'; + print '
'; $db->free($result); diff --git a/htdocs/product/list.php b/htdocs/product/list.php index ec55ad4f74c..fa0f18f538c 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -335,23 +335,23 @@ else } $param=''; - if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; - if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; - if ($search_categ > 0) $param.="&search_categ=".$search_categ; - if ($sref) $param="&sref=".$sref; - if ($search_ref_supplier) $param="&search_ref_supplier=".$search_ref_supplier; - if ($sbarcode) $param.=($sbarcode?"&sbarcode=".$sbarcode:""); - if ($snom) $param.="&snom=".$snom; - if ($sall) $param.="&sall=".$sall; - if ($tosell != '') $param.="&tosell=".$tosell; - if ($tobuy != '') $param.="&tobuy=".$tobuy; - if ($fourn_id) $param.=($fourn_id?"&fourn_id=".$fourn_id:""); - if ($seach_categ) $param.=($search_categ?"&search_categ=".$search_categ:""); + if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage); + if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit); + if ($search_categ > 0) $param.="&search_categ=".urlencode($search_categ); + if ($sref) $param="&sref=".urlencode($sref); + if ($search_ref_supplier) $param="&search_ref_supplier=".urlencode($search_ref_supplier); + if ($sbarcode) $param.=($sbarcode?"&sbarcode=".urlencode($sbarcode):""); + if ($snom) $param.="&snom=".urlencode($snom); + if ($sall) $param.="&sall=".urlencode($sall); + if ($tosell != '') $param.="&tosell=".urlencode($tosell); + if ($tobuy != '') $param.="&tobuy=".urlencode($tobuy); + if ($fourn_id > 0) $param.=($fourn_id?"&fourn_id=".$fourn_id:""); + if ($seach_categ) $param.=($search_categ?"&search_categ=".urlencode($search_categ):""); if ($type != '') $param.='&type='.urlencode($type); - if ($optioncss != '') $param.='&optioncss='.$optioncss; - if ($search_tobatch) $param="&search_ref_supplier=".$search_ref_supplier; - if ($search_accountancy_code_sell) $param="&search_accountancy_code_sell=".$search_accountancy_code_sell; - if ($search_accountancy_code_buy) $param="&search_accountancy_code_buy=".$search_accountancy_code_buy; + if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss); + if ($search_tobatch) $param="&search_ref_supplier=".urlencode($search_ref_supplier); + if ($search_accountancy_code_sell) $param="&search_accountancy_code_sell=".urlencode($search_accountancy_code_sell); + if ($search_accountancy_code_buy) $param="&search_accountancy_code_buy=".urlencode($search_accountancy_code_buy); // Add $param from extra fields foreach ($search_array_options as $key => $val) {