123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
- <?php
- /* Copyright (C) 2014-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
- * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
- * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
- * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
- *
- * 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 <https://www.gnu.org/licenses/>.
- */
- /**
- * \file htdocs/loan/list.php
- * \ingroup loan
- * \brief Page to list all loans
- */
- // Load Dolibarr environment
- require '../main.inc.php';
- require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
- // Load translation files required by the page
- $langs->loadLangs(array("loan", "compta", "banks", "bills"));
- // Security check
- $socid = GETPOST('socid', 'int');
- if ($user->socid) {
- $socid = $user->socid;
- }
- $result = restrictedArea($user, 'loan', '', '', '');
- $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');
- $massaction = GETPOST('massaction', 'alpha');
- if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
- $page = 0;
- } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
- $offset = $limit * $page;
- $pageprev = $page - 1;
- $pagenext = $page + 1;
- // Initialize technical objects
- $loan_static = new Loan($db);
- $extrafields = new ExtraFields($db);
- if (!$sortfield) {
- $sortfield = "l.rowid";
- }
- if (!$sortorder) {
- $sortorder = "DESC";
- }
- $search_ref = GETPOST('search_ref', 'int');
- $search_label = GETPOST('search_label', 'alpha');
- $search_amount = GETPOST('search_amount', 'alpha');
- $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'loanlist'; // To manage different context of search
- $optioncss = GETPOST('optioncss', 'alpha');
- $mode = GETPOST('mode', 'alpha'); // mode view result
- /*
- * Actions
- */
- if (GETPOST('cancel', 'alpha')) {
- $action = 'list'; $massaction = '';
- }
- if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
- $massaction = '';
- }
- $parameters = array();
- $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
- if ($reshook < 0) {
- setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
- }
- if (empty($reshook)) {
- // Purge search criteria
- 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_ref = "";
- $search_label = "";
- $search_amount = "";
- }
- }
- /*
- * View
- */
- $now = dol_now();
- //$help_url="EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
- $help_url = '';
- $title = $langs->trans('Loans');
- $sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.paid,";
- $sql .= " SUM(pl.amount_capital) as alreadypaid";
- $sqlfields = $sql; // $sql fields to remove for count total
- $sql .= " FROM ".MAIN_DB_PREFIX."loan as l";
- $linktopl = " LEFT JOIN ".MAIN_DB_PREFIX."payment_loan AS pl ON l.rowid = pl.fk_loan";
- $sql .= $linktopl;
- $sql .= " WHERE l.entity = ".$conf->entity;
- if ($search_amount) {
- $sql .= natural_search("l.capital", $search_amount, 1);
- }
- if ($search_ref) {
- $sql .= " AND l.rowid = ".((int) $search_ref);
- }
- if ($search_label) {
- $sql .= natural_search("l.label", $search_label);
- }
- $sql .= " GROUP BY l.rowid, l.label, l.capital, l.paid, l.datestart, l.dateend";
- // 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('/'.preg_quote($linktopl, '/').'/', '', $sqlforcount);
- $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 then paging size (filtering), goto and load page 0
- $page = 0;
- $offset = 0;
- }
- $db->free($resql);
- }
- $arrayfields = array();
- // 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);
- if ($resql) {
- $i = 0;
- $param = '';
- 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 ($search_ref) {
- $param .= "&search_ref=".urlencode($search_ref);
- }
- if ($search_label) {
- $param .= "&search_label=".urlencode($search_label);
- }
- if ($search_amount) {
- $param .= "&search_amount=".urlencode($search_amount);
- }
- if ($optioncss != '') {
- $param .= '&optioncss='.urlencode($optioncss);
- }
- $url = DOL_URL_ROOT.'/loan/card.php?action=create';
- if (!empty($socid)) {
- $url .= '&socid='.$socid;
- }
- $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'));
- $newcardbutton .= dolGetButtonTitle($langs->trans('NewLoan'), '', 'fa fa-plus-circle', $url, '', $user->rights->loan->write);
- print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
- if ($optioncss != '') {
- print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
- }
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
- print '<input type="hidden" name="action" value="list">';
- print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
- print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
- print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
- print '<input type="hidden" name="mode" value="'.$mode.'">';
- print_barre_liste($langs->trans("Loans"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'money-bill-alt', 0, $newcardbutton, '', $limit, 0, 0, 1);
- $moreforfilter = '';
- print '<div class="div-table-responsive">';
- print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
- // Filters lines
- print '<tr class="liste_titre_filter">';
- if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
- print '<td class="liste_titre maxwidthsearch">';
- $searchpicto = $form->showFilterAndCheckAddButtons();
- print $searchpicto;
- print '</td>';
- }
- print '<td class="liste_titre"><input class="flat" size="4" type="text" name="search_ref" value="'.$search_ref.'"></td>';
- print '<td class="liste_titre"><input class="flat" size="12" type="text" name="search_label" value="'.$search_label.'"></td>';
- print '<td class="liste_titre right" ><input class="flat" size="8" type="text" name="search_amount" value="'.$search_amount.'"></td>';
- print '<td class="liste_titre"> </td>';
- print '<td class="liste_titre"> </td>';
- print '<td class="liste_titre"></td>';
- if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
- print '<td class="liste_titre maxwidthsearch">';
- $searchpicto = $form->showFilterAndCheckAddButtons();
- print $searchpicto;
- print '</td>';
- }
- print '</tr>';
- // Fields title label
- // --------------------------------------------------------------------
- print '<tr class="liste_titre">';
- if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
- print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch ');
- }
- print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "l.rowid", "", $param, "", $sortfield, $sortorder);
- print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "l.label", "", $param, '', $sortfield, $sortorder, 'left ');
- print_liste_field_titre("LoanCapital", $_SERVER["PHP_SELF"], "l.capital", "", $param, '', $sortfield, $sortorder, 'right ');
- print_liste_field_titre("DateStart", $_SERVER["PHP_SELF"], "l.datestart", "", $param, '', $sortfield, $sortorder, 'center ');
- print_liste_field_titre("DateEnd", $_SERVER["PHP_SELF"], "l.dateend", "", $param, '', $sortfield, $sortorder, 'center ');
- print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "l.paid", "", $param, '', $sortfield, $sortorder, 'right ');
- if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
- print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch ');
- }
- print "</tr>\n";
- print "</tr>\n";
- // Loop on record
- // --------------------------------------------------------------------
- $i = 0;
- $totalarray = array();
- $imaxinloop = ($limit ? min($num, $limit) : $num);
- while ($i < $imaxinloop) {
- $obj = $db->fetch_object($resql);
- if (empty($obj)) {
- break; // Should not happen
- }
- $loan_static->id = $obj->rowid;
- $loan_static->ref = $obj->rowid;
- $loan_static->label = $obj->label;
- $loan_static->paid = $obj->paid;
- if ($mode == 'kanban') {
- if ($i == 0) {
- print '<tr><td colspan="12">';
- print '<div class="box-flex-container kanban">';
- }
- // Output Kanban
- $loan_static->datestart= $obj->datestart;
- $loan_static->dateend = $obj->dateend;
- $loan_static->capital = $obj->capital;
- $loan_static->totalpaid = $obj->paid;
- print $loan_static->getKanbanView('', array('selected' => in_array($loan_static->id, $arrayofselected)));
- if ($i == ($imaxinloop - 1)) {
- print '</div>';
- print '</td></tr>';
- }
- } else {
- print '<tr class="oddeven">';
- // Action column
- if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
- print '<td></td>';
- }
- // Ref
- print '<td>'.$loan_static->getNomUrl(1).'</td>';
- // Label
- print '<td>'.dol_trunc($obj->label, 42).'</td>';
- // Capital
- print '<td class="right maxwidth100"><span class="amount">'.price($obj->capital).'</span></td>';
- // Date start
- print '<td class="center width100">'.dol_print_date($db->jdate($obj->datestart), 'day').'</td>';
- // Date end
- print '<td class="center width100">'.dol_print_date($db->jdate($obj->dateend), 'day').'</td>';
- print '<td class="right nowrap">';
- print $loan_static->LibStatut($obj->paid, 5, $obj->alreadypaid);
- print '</td>';
- // Action column
- if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
- print '<td></td>';
- }
- print "</tr>\n";
- }
- $i++;
- }
- // If no record found
- if ($num == 0) {
- $colspan = 7;
- //foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
- print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
- }
- $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
- $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
- print $hookmanager->resPrint;
- print '</table>'."\n";
- print '</div>'."\n";
- print '</form>'."\n";
- $db->free($resql);
- } else {
- dol_print_error($db);
- }
- // End of page
- llxFooter();
- $db->close();
|