* Copyright (C) 2005-2016 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2010-2018 Juanjo Menent * Copyright (C) 2022 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/compta/prelevement/list.php * \ingroup prelevement * \brief Page to list direct debit orders or credit transfers orders */ // Load Dolibarr environment require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // Load translation files required by the page $langs->loadLangs(array('banks', 'withdrawals', 'companies', 'categories')); $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ... $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ? $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'directdebitcredittransferlinelist'; // To manage different context of search $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') $mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...) $type = GETPOST('type', 'aZ09'); // Load variable for pagination $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // If $page is not defined, or '' or -1 or if we click on clear filters $page = 0; } $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (!$sortorder) { $sortorder = "DESC"; } if (!$sortfield) { $sortfield = "p.datec"; } $search_line = GETPOST('search_line', 'alpha'); $search_bon = GETPOST('search_bon', 'alpha'); $search_code = GETPOST('search_code', 'alpha'); $search_company = GETPOST('search_company', 'alpha'); $statut = GETPOST('statut', 'int'); $bon = new BonPrelevement($db); $line = new LignePrelevement($db); $company = new Societe($db); $hookmanager->initHooks(array('withdrawalsreceiptslineslist')); // Security check $socid = GETPOST('socid', 'int'); if ($user->socid) { $socid = $user->socid; } if ($type == 'bank-transfer') { $result = restrictedArea($user, 'paymentbybanktransfer', '', '', ''); } else { $result = restrictedArea($user, 'prelevement', '', '', 'bons'); } /* * Actions */ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers $search_line = ""; $search_bon = ""; $search_code = ""; $search_company = ""; $statut = ""; } /* * View */ $form = new Form($db); $title = $langs->trans("WithdrawalsLines"); if ($type == 'bank-transfer') { $title = $langs->trans("CreditTransferLines"); } $help_url = ''; $sql = "SELECT p.rowid, p.ref, p.statut as status, p.datec"; $sql .= " , f.rowid as facid, f.ref as invoiceref, f.total_ttc"; $sql .= " , s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur, s.email"; $sql .= " , pl.amount, pl.statut as statut_ligne, pl.rowid as rowid_ligne"; $sqlfields = $sql; // $sql fields to remove for count total $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p"; $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl"; $sql .= " , ".MAIN_DB_PREFIX."prelevement as pf"; if ($type == 'bank-transfer') { $sql .= " , ".MAIN_DB_PREFIX."facture_fourn as f"; } else { $sql .= " , ".MAIN_DB_PREFIX."facture as f"; } $sql .= " , ".MAIN_DB_PREFIX."societe as s"; $sql .= " WHERE pl.fk_prelevement_bons = p.rowid"; $sql .= " AND pf.fk_prelevement_lignes = pl.rowid"; if ($type == 'bank-transfer') { $sql .= " AND pf.fk_facture_fourn = f.rowid"; } else { $sql .= " AND pf.fk_facture = f.rowid"; } $sql .= " AND f.fk_soc = s.rowid"; $sql .= " AND f.entity IN (".getEntity('invoice').")"; if ($socid) { $sql .= " AND s.rowid = ".((int) $socid); } if ($search_line) { $sql .= " AND pl.rowid = '".$db->escape($search_line)."'"; } if ($search_bon) { $sql .= natural_search("p.ref", $search_bon); } if ($type == 'bank-transfer') { if ($search_code) { $sql .= natural_search("s.code_fournisseur", $search_code); } } else { if ($search_code) { $sql .= natural_search("s.code_client", $search_code); } } if ($search_company) { $sql .= natural_search("s.nom", $search_company); } // Count total nb of records $nbtotalofrecords = ''; if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) { /* The fast and low memory method to get and count full list converts the sql into a sql count */ $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql); $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); $resql = $db->query($sqlforcount); if ($resql) { $objforcount = $db->fetch_object($resql); $nbtotalofrecords = $objforcount->nbtotalofrecords; } else { dol_print_error($db); } if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0 $page = 0; $offset = 0; } $db->free($resql); } // Complete request and execute it with limit $sql .= $db->order($sortfield, $sortorder); if ($limit) { $sql .= $db->plimit($limit + 1, $offset); } $resql = $db->query($sql); if (!$resql) { dol_print_error($db); exit; } $num = $db->num_rows($resql); // Output page // -------------------------------------------------------------------- llxHeader('', $title, $help_url); $arrayofselected = is_array($toselect) ? $toselect : array(); $param = ''; $param .= "&statut=".urlencode($statut); $param .= "&search_bon=".urlencode($search_bon); if ($type == 'bank-transfer') { $param .= '&type=bank-transfer'; } if (!empty($mode)) { $param .= '&mode='.urlencode($mode); } if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { $param .= '&contextpage='.urlencode($contextpage); } if ($limit > 0 && $limit != $conf->liste_limit) { $param .= '&limit='.((int) $limit); } if ($optioncss != '') { $param .= '&optioncss='.urlencode($optioncss); } $arrayofmassactions = array( //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"), //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"), ); $massactionbutton = $form->selectMassAction('', $arrayofmassactions); print '
'."\n"; print ''; if ($optioncss != '') { print ''; } print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if ($type != '') { print ''; } $newcardbutton = ''; $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition')); $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition')); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, $newcardbutton, '', $limit, 0, 0, 1); $moreforfilter = ''; /*$moreforfilter.='
'; $moreforfilter.= $langs->trans('MyFilter') . ': '; $moreforfilter.= '
';*/ $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook if (empty($reshook)) { $moreforfilter .= $hookmanager->resPrint; } else { $moreforfilter = $hookmanager->resPrint; } if (!empty($moreforfilter)) { print '
'; print $moreforfilter; $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; print '
'; } $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : ''); print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table print ''."\n"; // Fields title search // -------------------------------------------------------------------- print ''; // Action column if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print ''; } print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Action column if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print ''; } print ''."\n"; $totalarray = array(); $totalarray['nbfield'] = 0; $columntitle = "WithdrawalsReceipts"; $columntitlethirdparty = "CustomerCode"; $columncodethirdparty = "s.code_client"; if ($type == 'bank-transfer') { $columntitle = "BankTransferReceipts"; $columntitlethirdparty = "SupplierCode"; $columncodethirdparty = "s.code_fournisseur"; } // Fields title label // -------------------------------------------------------------------- print ''; // Action column if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n"; $totalarray['nbfield']++; } print_liste_field_titre($columntitle, $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder); $totalarray['nbfield']++; print_liste_field_titre("Line", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder); $totalarray['nbfield']++; print_liste_field_titre("Bill", $_SERVER["PHP_SELF"], "f.ref", '', $param, '', $sortfield, $sortorder); $totalarray['nbfield']++; print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder); $totalarray['nbfield']++; print_liste_field_titre($columntitlethirdparty, $_SERVER["PHP_SELF"], $columncodethirdparty, '', $param, '', $sortfield, $sortorder, 'center '); $totalarray['nbfield']++; print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center '); $totalarray['nbfield']++; print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "pl.amount", "", $param, '', $sortfield, $sortorder, 'right '); $totalarray['nbfield']++; // Action column if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n"; $totalarray['nbfield']++; } print ''."\n"; // Loop on record // -------------------------------------------------------------------- $i = 0; $savnbfield = $totalarray['nbfield']; $totalarray = array(); $totalarray['nbfield'] = 0; $imaxinloop = ($limit ? min($num, $limit) : $num); while ($i < $imaxinloop) { $obj = $db->fetch_object($resql); $bon->id = $obj->rowid; $bon->ref = $obj->ref; $bon->statut = $obj->status; $bon->date_echeance = $obj->datec; $bon->total = $obj->amount; $object = $bon; $company->id = $obj->socid; $company->name = $obj->name; $company->email = $obj->email; $company->code_client = $obj->code_client; if ($mode == 'kanban') { if ($i == 0) { print ''; } } else { // Show line of result $j = 0; print ''; // Action column if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print ''; if (!$i) { $totalarray['nbfield']++; } } print '\n"; print ''; print '\n"; print ''; print ''; print '\n"; print '\n"; print '\n"; print '\n"; // Action column if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print ''; if (!$i) { $totalarray['nbfield']++; } } print ''."\n"; } $i++; } if ($num == 0) { print ''; } $db->free($result); $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql); $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; print '
'; $searchpicto = $form->showFilterButtons('left'); print $searchpicto; print '   '; $searchpicto = $form->showFilterButtons(); print $searchpicto; print '
'; print '
'; } // Output Kanban if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined $selected = 0; if (in_array($object->id, $arrayofselected)) { $selected = 1; } } print $object->getKanbanView('', array('selected' => in_array($bon->id, $arrayofselected))); if ($i == ($imaxinloop - 1)) { print '
'; print '
'; if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined $selected = 0; if (in_array($object->id, $arrayofselected)) { $selected = 1; } print ''; } print ''; print $bon->getNomUrl(1); print "'; print $line->LibStatut($obj->statut_ligne, 2); print " "; print ''; print substr('000000'.$obj->rowid_ligne, -6); print ''; $link_to_bill = '/compta/facture/card.php?facid='; $link_title = 'Invoice'; $link_picto = 'bill'; if ($type == 'bank-transfer') { $link_to_bill = '/fourn/facture/card.php?facid='; $link_title = 'SupplierInvoice'; $link_picto = 'supplier_invoice'; } print ''; print img_object($langs->trans($link_title), $link_picto); print ' '.$obj->invoiceref."'; print $company->getNomUrl(1); print "'; $link_to_tab = '/comm/card.php?socid='; $link_code = $obj->code_client; if ($type == 'bank-transfer') { $link_to_tab = '/fourn/card.php?socid='; $link_code = $obj->code_fournisseur; } print ''.$link_code."'.dol_print_date($db->jdate($obj->datec), 'day')."'.price($obj->amount)."'; if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined $selected = 0; if (in_array($object->id, $arrayofselected)) { $selected = 1; } print ''; } print '
'.$langs->trans("None").'
'."\n"; print '
'."\n"; print '
'."\n"; // End of page llxFooter(); $db->close();