From a815326a28ed4873da02e6ec08fa7de3a7b17114 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 1 Mar 2018 12:37:03 +0100 Subject: [PATCH] Fix filters on bank entry list --- htdocs/compta/bank/bankentries_list.php | 110 +++++++++++++----------- 1 file changed, 60 insertions(+), 50 deletions(-) diff --git a/htdocs/compta/bank/bankentries_list.php b/htdocs/compta/bank/bankentries_list.php index 692df2fcb22..91e496d998c 100644 --- a/htdocs/compta/bank/bankentries_list.php +++ b/htdocs/compta/bank/bankentries_list.php @@ -73,16 +73,16 @@ $description=GETPOST("description",'alpha'); $dateop = dol_mktime(12,0,0,GETPOST("opmonth",'int'),GETPOST("opday",'int'),GETPOST("opyear",'int')); $debit=GETPOST("debit",'alpha'); $credit=GETPOST("credit",'alpha'); -$type=GETPOST("type",'alpha'); -$account=GETPOST("account",'int'); -$accountancy_code=GETPOST('accountancy_code', 'alpha'); -$bid=GETPOST("bid","int"); +$search_type=GETPOST("search_type",'alpha'); +$search_account=GETPOST("search_account",'int')?GETPOST("search_account",'int'):GETPOST("account",'int'); +$search_accountancy_code=GETPOST('search_accountancy_code', 'alpha')?GETPOST('search_accountancy_code', 'alpha'):GETPOST('accountancy_code', 'alpha'); +$search_bid=GETPOST("search_bid","int")?GETPOST("search_bid","int"):GETPOST("bid","int"); $search_ref=GETPOST('search_ref','alpha'); $search_dt_start = dol_mktime(0, 0, 0, GETPOST('search_start_dtmonth', 'int'), GETPOST('search_start_dtday', 'int'), GETPOST('search_start_dtyear', 'int')); $search_dt_end = dol_mktime(0, 0, 0, GETPOST('search_end_dtmonth', 'int'), GETPOST('search_end_dtday', 'int'), GETPOST('search_end_dtyear', 'int')); $search_dv_start = dol_mktime(0, 0, 0, GETPOST('search_start_dvmonth', 'int'), GETPOST('search_start_dvday', 'int'), GETPOST('search_start_dvyear', 'int')); $search_dv_end = dol_mktime(0, 0, 0, GETPOST('search_end_dvmonth', 'int'), GETPOST('search_end_dvday', 'int'), GETPOST('search_end_dvyear', 'int')); -$search_thirdparty=GETPOST("thirdparty",'alpha'); +$search_thirdparty=GETPOST("search_thirdparty",'alpha')?GETPOST("search_thirdparty",'alpha'):GETPOST("thirdparty",'alpha'); $search_req_nb=GETPOST("req_nb",'alpha'); $search_num_releve=GETPOST("search_num_releve",'alpha'); $search_conciliated=GETPOST("search_conciliated",'int'); @@ -108,7 +108,7 @@ $mode_balance_ok=false; if (($sortfield == 'b.datev' || $sortfield == 'b.datev,b.dateo,b.rowid')) { $sortfield = 'b.datev,b.dateo,b.rowid'; - if ($id > 0 || ! empty($ref) || $account > 0) $mode_balance_ok = true; + if ($id > 0 || ! empty($ref) || $search_account > 0) $mode_balance_ok = true; } if (strtolower($sortorder) == 'desc') $mode_balance_ok = false; @@ -116,7 +116,7 @@ $object = new Account($db); if ($id > 0 || ! empty($ref)) { $result=$object->fetch($id, $ref); - $account = $object->id; // Force the search field on id of account + $search_account = $object->id; // Force the search field on id of account } @@ -179,10 +179,10 @@ if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x', $search_dv_start=''; $search_dv_end=''; $description=""; - $type=""; + $search_type=""; $debit=""; $credit=""; - $bid=""; + $search_bid=""; $search_ref=""; $search_req_nb=''; $search_thirdparty=''; @@ -190,8 +190,8 @@ if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x', $search_conciliated=''; $thirdparty=''; - $account=""; - if ($id > 0 || ! empty($ref)) $account=$object->id; + $search_account=""; + if ($id > 0 || ! empty($ref)) $search_account=$object->id; } if (empty($reshook)) @@ -297,7 +297,7 @@ if (GETPOST('save') && ! $cancel && $user->rights->banque->modifier) $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors'); } - /*if (! empty($conf->accounting->enabled) && (empty($accountancy_code) || $accountancy_code == '-1')) + /*if (! empty($conf->accounting->enabled) && (empty($search_accountancy_code) || $search_accountancy_code == '-1')) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountAccounting")), null, 'errors'); $error++; @@ -307,7 +307,7 @@ if (GETPOST('save') && ! $cancel && $user->rights->banque->modifier) { $objecttmp = new Account($db); $objecttmp->fetch($bankaccountid); - $insertid = $objecttmp->addline($dateop, $operation, $label, $amount, $num_chq, ($cat1 > 0 ? $cat1 : 0), $user, '', '', $accountancy_code); + $insertid = $objecttmp->addline($dateop, $operation, $label, $amount, $num_chq, ($cat1 > 0 ? $cat1 : 0), $user, '', '', $search_accountancy_code); if ($insertid > 0) { setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); @@ -364,26 +364,27 @@ $now = dol_now(); // Must be before button action $param=''; -if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; -if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; +if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage); +if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit); if ($id > 0) $param.='&id='.urlencode($id); if (!empty($ref)) $param.='&ref='.urlencode($ref); if (!empty($search_ref)) $param.='&search_ref='.urlencode($search_ref); if (!empty($description)) $param.='&description='.urlencode($description); -if (!empty($type)) $param.='&type='.urlencode($type); -if (!empty($debit)) $param.='&debit='.$debit; -if (!empty($credit)) $param.='&credit='.$credit; -if (!empty($account)) $param.='&account='.$account; +if (!empty($search_type)) $param.='&type='.urlencode($search_type); +if (!empty($search_thirdparty)) $param.='&search_thirdparty='.urlencode($search_thirdparty); +if (!empty($debit)) $param.='&debit='.urlencode($debit); +if (!empty($credit)) $param.='&credit='.urlencode($credit); +if (!empty($search_account)) $param.='&search_account='.urlencode($search_account); if (!empty($search_num_releve)) $param.='&search_num_releve='.urlencode($search_num_releve); if ($search_conciliated != '' && $search_conciliated != '-1') $param.='&search_conciliated='.urlencode($search_conciliated); -if (!empty($bid)) $param.='&bid='.$bid; +if ($search_bid > 0) $param.='&search_bid='.urlencode($search_bid); if (dol_strlen($search_dt_start) > 0) $param .= '&search_start_dtmonth=' . GETPOST('search_start_dtmonth', 'int') . '&search_start_dtday=' . GETPOST('search_start_dtday', 'int') . '&search_start_dtyear=' . GETPOST('search_start_dtyear', 'int'); if (dol_strlen($search_dt_end) > 0) $param .= '&search_end_dtmonth=' . GETPOST('search_end_dtmonth', 'int') . '&search_end_dtday=' . GETPOST('search_end_dtday', 'int') . '&search_end_dtyear=' . GETPOST('search_end_dtyear', 'int'); if (dol_strlen($search_dv_start) > 0) $param .= '&search_start_dvmonth=' . GETPOST('search_start_dvmonth', 'int') . '&search_start_dvday=' . GETPOST('search_start_dvday', 'int') . '&search_start_dvyear=' . GETPOST('search_start_dvyear', 'int'); if (dol_strlen($search_dv_end) > 0) $param .= '&search_end_dvmonth=' . GETPOST('search_end_dvmonth', 'int') . '&search_end_dvday=' . GETPOST('search_end_dvday', 'int') . '&search_end_dvyear=' . GETPOST('search_end_dvyear', 'int'); -if ($search_req_nb) $param.='&req_nb='.urlencode($search_req_nb); -if (GETPOST("thirdparty")) $param.='&thirdparty='.urlencode(GETPOST("thirdparty")); -if ($optioncss != '') $param.='&optioncss='.$optioncss; +if ($search_req_nb) $param.='&req_nb='.urlencode($search_req_nb); +if (GETPOST("search_thirdparty",'int')) $param.='&thirdparty='.urlencode(GETPOST("search_thirdparty",'int')); +if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss); // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; @@ -454,7 +455,7 @@ $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook $sql.=$hookmanager->resPrint; $sql.= " FROM "; -if ($bid) $sql.= MAIN_DB_PREFIX."bank_class as l,"; +if ($search_bid) $sql.= MAIN_DB_PREFIX."bank_class as l,"; $sql.= " ".MAIN_DB_PREFIX."bank_account as ba,"; $sql.= " ".MAIN_DB_PREFIX."bank as b"; if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_extrafields as ef on (b.rowid = ef.fk_object)"; @@ -462,21 +463,21 @@ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = b.rowid AND $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu.url_id = s.rowid"; $sql.= " WHERE b.fk_account = ba.rowid"; $sql.= " AND ba.entity IN (".getEntity('bank_account').")"; -if ($account > 0) $sql.=" AND b.fk_account = ".$account; +if ($search_account > 0) $sql.=" AND b.fk_account = ".$search_account; // Search period criteria if (dol_strlen($search_dt_start)>0) $sql .= " AND b.dateo >= '" . $db->idate($search_dt_start) . "'"; if (dol_strlen($search_dt_end)>0) $sql .= " AND b.dateo <= '" . $db->idate($search_dt_end) . "'"; // Search period criteria if (dol_strlen($search_dv_start)>0) $sql .= " AND b.datev >= '" . $db->idate($search_dv_start) . "'"; if (dol_strlen($search_dv_end)>0) $sql .= " AND b.datev <= '" . $db->idate($search_dv_end) . "'"; -if ($search_ref) $sql.=natural_search("b.rowid", $search_ref); +if ($search_ref) $sql.=natural_search("b.rowid", $search_ref, 1); if ($search_req_nb) $sql.= natural_search("b.num_chq", $search_req_nb); if ($search_num_releve) $sql.= natural_search("b.num_releve", $search_num_releve); if ($search_conciliated != '' && $search_conciliated != '-1') $sql.= " AND b.rappro = ".$search_conciliated; if ($search_thirdparty) $sql.= natural_search("s.nom", $search_thirdparty); if ($description) $sql.= natural_search("b.label", $description); // Warning some text are just translation keys, not translated strings -if ($bid) $sql.= " AND b.rowid=l.lineid AND l.fk_categ=".$bid; -if (! empty($type)) $sql.= " AND b.fk_type = '".$db->escape($type)."' "; +if ($search_bid > 0) $sql.= " AND b.rowid=l.lineid AND l.fk_categ=".$search_bid; +if (! empty($search_type)) $sql.= " AND b.fk_type = '".$db->escape($search_type)."' "; // Search criteria amount $debit = price2num(str_replace('-','',$debit)); $credit = price2num(str_replace('-','',$credit)); @@ -518,11 +519,11 @@ if ($page >= $nbtotalofpages) } // If not account defined $mode_balance_ok=false -if (empty($account)) $mode_balance_ok=false; +if (empty($search_account)) $mode_balance_ok=false; // If a search is done $mode_balance_ok=false if (! empty($search_ref)) $mode_balance_ok=false; if (! empty($req_nb)) $mode_balance_ok=false; -if (! empty($type)) $mode_balance_ok=false; +if (! empty($search_type)) $mode_balance_ok=false; if (! empty($debit)) $mode_balance_ok=false; if (! empty($credit)) $mode_balance_ok=false; if (! empty($thirdparty)) $mode_balance_ok=false; @@ -643,7 +644,7 @@ if ($resql) print ' '; print ''.$langs->trans("Type").''; print ''.$langs->trans("Numero").''; - //if (! $account > 0) + //if (! $search_account > 0) //{ print ''.$langs->trans("BankAccount").''; //} @@ -677,10 +678,10 @@ if ($resql) print ''; print ''; print ''; - //if (! $account > 0) + //if (! $search_account > 0) //{ print ''; - $form->select_comptes(GETPOST('add_account','int')?GETPOST('add_account','int'):$account,'add_account',0,'',1, ($id > 0 || ! empty($ref)?' disabled="disabled"':'')); + $form->select_comptes(GETPOST('add_account','int')?GETPOST('add_account','int'):$search_account,'add_account',0,'',1, ($id > 0 || ! empty($ref)?' disabled="disabled"':'')); print ''; //} print ''; @@ -688,7 +689,7 @@ if ($resql) /*if (! empty($conf->accounting->enabled)) { print ''; - print $formaccounting->select_account($accountancy_code, 'accountancy_code', 1, null, 1, 1, ''); + print $formaccounting->select_account($search_accountancy_code, 'search_accountancy_code', 1, null, 1, 1, ''); print ''; }*/ print ''; @@ -733,7 +734,7 @@ if ($resql) if (! empty($conf->global->BANK_USE_VARIOUS_PAYMENT)) // If direct entries is done using miscellaneous payments { if ($user->rights->banque->modifier) { - $addbutton = ''.$langs->trans("AddBankRecord").''; + $addbutton = ''.$langs->trans("AddBankRecord").''; } else { $addbutton = ''.$langs->trans("AddBankRecord").''; } @@ -768,15 +769,8 @@ if ($resql) $picto='title_bank'; if ($id > 0 || ! empty($ref)) $picto=''; - if (GETPOST("bid")) - { - $result=$bankcateg->fetch(GETPOST("bid")); - print_barre_liste($langs->trans("BankTransactionForCategory",$bankcateg->label).' '.($socid?' '.$soc->name:''), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $morehtml, '', $limit); - } - else - { - print_barre_liste($langs->trans("BankTransactions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $morehtml, '', $limit); - } + + print_barre_liste($langs->trans("BankTransactions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $morehtml, '', $limit); // We can add page now to param if ($page != '') $param.='&page='.urlencode($page); @@ -799,6 +793,22 @@ if ($resql) $moreforfilter .= '
'.$langs->trans('to') . ' ' . $form->select_date($search_dv_end, 'search_end_dv', 0, 0, 1, "search_form", 1, 0, 1).'
'; $moreforfilter .= ''; + if (! empty($conf->categorie->enabled)) + { + // Categories + if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) + { + $langs->load('categories'); + + // Bank line + $moreforfilter.='
'; + $moreforfilter.=$langs->trans('RubriquesTransactions').' : '; + $cate_arbo = $form->select_all_categories(Categorie::TYPE_BANK_LINE, $search_bid, 'parent', null, null, 1); + $moreforfilter.=$form->selectarray('search_bid', $cate_arbo, $search_bid, 1); + $moreforfilter.='
'; + } + } + $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; @@ -842,7 +852,7 @@ if ($resql) if (! empty($arrayfields['type']['checked'])) { print ''; - $form->select_types_paiements(empty($type)?'':$type, 'type', '', 2, 0, 1, 0, 1, 'maxwidth100'); + $form->select_types_paiements(empty($search_type)?'':$search_type, 'search_type', '', 2, 0, 1, 0, 1, 'maxwidth100'); print ''; } if (! empty($arrayfields['b.num_chq']['checked'])) @@ -852,12 +862,12 @@ if ($resql) } if (! empty($arrayfields['bu.label']['checked'])) { - print ''; + print ''; } if (! empty($arrayfields['ba.ref']['checked'])) { print ''; - $form->select_comptes($account,'account',0,'',1, ($id > 0 || ! empty($ref)?' disabled="disabled"':'')); + $form->select_comptes($search_account,'search_account',0,'',1, ($id > 0 || ! empty($ref)?' disabled="disabled"':'')); print ''; } if (! empty($arrayfields['b.debit']['checked'])) @@ -947,7 +957,7 @@ if ($resql) // If we are in a situation where we need/can show balance, we calculate the start of balance if (! $balancecalculated && (! empty($arrayfields['balancebefore']['checked']) || ! empty($arrayfields['balance']['checked'])) && $mode_balance_ok) { - if (! $account) + if (! $search_account) { dol_print_error('', 'account is not defined but $mode_balance_ok is true'); exit; @@ -962,7 +972,7 @@ if ($resql) $sqlforbalance.= " ".MAIN_DB_PREFIX."bank as b"; $sqlforbalance.= " WHERE b.fk_account = ba.rowid"; $sqlforbalance.= " AND ba.entity IN (".getEntity('bank_account').")"; - $sqlforbalance.= " AND b.fk_account = ".$account; + $sqlforbalance.= " AND b.fk_account = ".$search_account; $sqlforbalance.= " AND (b.datev < '" . $db->idate($db->jdate($objp->dv)) . "' OR (b.datev = '" . $db->idate($db->jdate($objp->dv)) . "' AND (b.dateo < '".$db->idate($db->jdate($objp->do))."' OR (b.dateo = '".$db->idate($db->jdate($objp->do))."' AND b.rowid < ".$objp->rowid."))))"; $resqlforbalance = $db->query($sqlforbalance); //print $sqlforbalance; @@ -1048,7 +1058,7 @@ if ($resql) if (! empty($arrayfields['b.rowid']['checked'])) { print ''; - print "rowid.'">'.img_object($langs->trans("ShowPayment").': '.$objp->rowid, 'account', 'class="classfortooltip"').' '.$objp->rowid."   "; + print "rowid.'&save_lastsearch_values=1">'.img_object($langs->trans("ShowPayment").': '.$objp->rowid, 'account', 'class="classfortooltip"').' '.$objp->rowid."   "; print ''; if (! $i) $totalarray['nbfield']++; }