* Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005-2011 Regis Houssin * Copyright (C) 2012 Juanjo Menent * Copyright (C) 2018 charlene Benke * Copyright (C) 2024 Frédéric France * * 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/deplacement/list.php * \brief Page to list trips and expenses */ // Load Dolibarr environment require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; /** * @var Conf $conf * @var DoliDB $db * @var Form $form * @var HookManager $hookmanager * @var Translate $langs * @var User $user */ // Load translation files required by the page $langs->loadLangs(array('companies', 'users', 'trips')); // Security check $socid = GETPOSTINT('socid'); if ($user->socid) { $socid = $user->socid; } $result = restrictedArea($user, 'deplacement', '', ''); $search_ref = GETPOST('search_ref', 'alpha'); $search_name = GETPOST('search_name', 'alpha'); $search_company = GETPOST('search_company', 'alpha'); // $search_amount=GETPOST('search_amount','alpha'); $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (!$sortorder) { $sortorder = "DESC"; } if (!$sortfield) { $sortfield = "d.dated"; } $year = GETPOST("year"); $month = GETPOST("month"); $day = GETPOST("day"); if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers $search_ref = ""; $search_name = ""; $search_company = ""; // $search_amount=""; $year = ""; $month = ""; $day = ""; } /* * View */ $formother = new FormOther($db); $tripandexpense_static = new Deplacement($db); $userstatic = new User($db); $childids = $user->getAllChildIds(); $childids[] = $user->id; llxHeader(); $sql = "SELECT s.nom, d.fk_user, s.rowid as socid,"; // Ou $sql .= " d.rowid, d.type, d.dated as dd, d.km,"; // Comment $sql .= " d.fk_statut,"; $sql .= " u.lastname, u.firstname"; // Qui $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; $sql .= ", ".MAIN_DB_PREFIX."deplacement as d"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON d.fk_soc = s.rowid"; $sql .= " WHERE d.fk_user = u.rowid"; $sql .= " AND d.entity = ".$conf->entity; if (!$user->hasRight('deplacement', 'readall') && !$user->hasRight('deplacement', 'lire_tous')) { $sql .= ' AND d.fk_user IN ('.$db->sanitize(implode(',', $childids)).')'; } // If the internal user must only see his customers, force searching by him $search_sale = 0; if (!$user->hasRight('societe', 'client', 'voir')) { $search_sale = $user->id; } // Search on sale representative if ($search_sale && $search_sale != '-1') { if ($search_sale == -2) { $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = d.fk_soc)"; } elseif ($search_sale > 0) { $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = d.fk_soc AND sc.fk_user = ".((int) $search_sale).")"; } } // Search on socid if ($socid) { $sql .= " AND d.fk_soc = ".((int) $socid); } if ($search_ref) { $sql .= " AND d.rowid = ".((int) $search_ref); } if ($search_name) { $sql .= natural_search('u.lastname', $search_name); } if ($search_company) { $sql .= natural_search('s.nom', $search_company); } $sql .= dolSqlDateFilter("d.dated", $day, $month, $year); $sql .= $db->order($sortfield, $sortorder); $sql .= $db->plimit($limit + 1, $offset); //print $sql; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); print_barre_liste($langs->trans("TripsAndExpenses"), $page, $_SERVER["PHP_SELF"], "&socid=$socid", $sortfield, $sortorder, '', $num); $i = 0; print '
'."\n"; print ''; print ""; print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", "", "&socid=$socid", '', $sortfield, $sortorder); print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "d.type", "", "&socid=$socid", '', $sortfield, $sortorder); print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "d.dated", "", "&socid=$socid", 'align="center"', $sortfield, $sortorder); print_liste_field_titre("Person", $_SERVER["PHP_SELF"], "u.lastname", "", "&socid=$socid", '', $sortfield, $sortorder); print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "&socid=$socid", '', $sortfield, $sortorder); print_liste_field_titre("FeesKilometersOrAmout", $_SERVER["PHP_SELF"], "d.km", "", "&socid=$socid", 'class="right"', $sortfield, $sortorder); print_liste_field_titre(''); print "\n"; // Filters lines print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; while ($i < min($num, $limit)) { $obj = $db->fetch_object($resql); $soc = new Societe($db); if ($obj->socid) { $soc->fetch($obj->socid); } print ''; // Id print ''; // Type print ''; // Date print ''; // User print ''; if ($obj->socid) { print ''; } else { print ''; } print ''; $tripandexpense_static->statut = $obj->fk_statut; print ''; print "\n"; $i++; } print "
'; print ''; print ''; print ' '; print ''; if (getDolGlobalString('MAIN_LIST_FILTER_ON_DAY')) { print ''; } print ''; print $formother->selectyear($year ? $year : -1, 'year', 1, 20, 5); print ''; print ''; print ''; print ''; print ''; // print ''; print ''; $searchpicto = $form->showFilterAndCheckAddButtons(0); print $searchpicto; print '
'.img_object($langs->trans("ShowTrip"), "trip").' '.$obj->rowid.''.$langs->trans($obj->type).''.dol_print_date($db->jdate($obj->dd), 'day').''; $userstatic->id = $obj->fk_user; $userstatic->lastname = $obj->lastname; $userstatic->firstname = $obj->firstname; print $userstatic->getNomUrl(1); print ''.$soc->getNomUrl(1).' '.$obj->km.''.$tripandexpense_static->getLibStatut(5).'
"; print "
\n"; $db->free($resql); } else { dol_print_error($db); } // End of page llxFooter(); $db->close();