* Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin * * 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/expedition/list.php * \ingroup expedition * \brief Page to list all shipments */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; $langs->load("sendings"); $langs->load("deliveries"); $langs->load('companies'); // Security check $expeditionid = GETPOST('id','int'); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'expedition',$expeditionid,''); $search_ref_exp = GETPOST("search_ref_exp"); $search_ref_liv = GETPOST('search_ref_liv'); $search_company = GETPOST("search_company"); $sortfield = GETPOST('sortfield','alpha'); $sortorder = GETPOST('sortorder','alpha'); $page = GETPOST('page','int'); if ($page == -1) { $page = 0; } $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; $limit = $conf->liste_limit; if (! $sortfield) $sortfield="e.ref"; if (! $sortorder) $sortorder="DESC"; $limit = $conf->liste_limit; $viewstatut=GETPOST('viewstatut'); // Purge search criteria if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers { $search_ref_exp=''; $search_ref_liv=''; $search_company=''; } /* * View */ $companystatic=new Societe($db); $shipment=new Expedition($db); $helpurl='EN:Module_Shipments|FR:Module_Expéditions|ES:Módulo_Expediciones'; llxHeader('',$langs->trans('ListOfSendings'),$helpurl); $sql = "SELECT e.rowid, e.ref, e.date_expedition as date_expedition, e.date_delivery as date_livraison, l.date_delivery as date_reception, e.fk_statut"; $sql.= ", s.nom as socname, s.rowid as socid"; $sql.= " FROM (".MAIN_DB_PREFIX."expedition as e"; if (!$user->rights->societe->client->voir && !$socid) // Internal user with no permission to see all { $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql.= ")"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'shipping' AND ee.targettype = 'delivery'"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.rowid = ee.fk_target"; $sql.= " WHERE e.entity IN (".getEntity('expedition', 1).")"; if (!$user->rights->societe->client->voir && !$socid) // Internal user with no permission to see all { $sql.= " AND e.fk_soc = sc.fk_soc"; $sql.= " AND sc.fk_user = " .$user->id; } if ($socid) { $sql.= " AND e.fk_soc = ".$socid; } if ($viewstatut <> '') { $sql.= " AND e.fk_statut = ".$viewstatut; } if ($search_ref_exp) $sql .= natural_search('e.ref', $search_ref_exp); if ($search_ref_liv) $sql .= natural_search('l.ref', $search_ref_liv); if ($search_company) $sql .= natural_search('s.nom', $search_company); $sql.= $db->order($sortfield,$sortorder); $sql.= $db->plimit($limit + 1,$offset); $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); $expedition = new Expedition($db); $param=""; if ($search_ref_exp) $param.= "&search_ref_exp=".$search_ref_exp; if ($search_ref_liv) $param.= "&search_ref_liv=".$search_ref_liv; if ($search_company) $param.= "&search_company=".$search_company; print_barre_liste($langs->trans('ListOfSendings'), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num); $i = 0; print '
'."\n"; print ''; print ''; print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"],"e.ref","",$param,'',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Company"), $_SERVER["PHP_SELF"],"s.nom", "", $param,'align="left"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("DateDeliveryPlanned"), $_SERVER["PHP_SELF"],"e.date_delivery","",$param, 'align="center"',$sortfield,$sortorder); if($conf->livraison_bon->enabled) { print_liste_field_titre($langs->trans("DeliveryOrder"), $_SERVER["PHP_SELF"],"l.ref","",$param, '',$sortfield,$sortorder); print_liste_field_titre($langs->trans("DateReceived"), $_SERVER["PHP_SELF"],"l.date_delivery","",$param, 'align="center"',$sortfield,$sortorder); } print_liste_field_titre($langs->trans("Status"), $_SERVER["PHP_SELF"],"e.fk_statut","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch '); print "\n"; // Lignes des champs de filtre print ''; print ''; print ''; // Date delivery planned print ''; if ($conf->livraison_bon->enabled) { // Delivery order print ''; } // Status print ''; // Search print ''; print "\n"; $var=True; while ($i < min($num,$limit)) { $objp = $db->fetch_object($resql); $var=!$var; print ""; // Ref print "\n"; // Third party print ''; // Date delivery planed print "\n"; if ($conf->livraison_bon->enabled) { $shipment->fetchObjectLinked($shipment->id,$shipment->element); $receiving=(! empty($shipment->linkedObjects['delivery'][0])?$shipment->linkedObjects['delivery'][0]:''); // Ref print ''; // Date received print ''."\n"; } print ''; print ''; print "\n"; $i++; } print "
'; print ''; print ''; print ''; print ' '; print ''; // Date received print ' '; print ''; print ''; print '
"; $shipment->id=$objp->rowid; $shipment->ref=$objp->ref; print $shipment->getNomUrl(1); print "'; $companystatic->id=$objp->socid; $companystatic->ref=$objp->socname; $companystatic->name=$objp->socname; print $companystatic->getNomUrl(1); print '"; print dol_print_date($db->jdate($objp->date_livraison),"day"); /*$now = time(); if ( ($now - $db->jdate($objp->date_expedition)) > $conf->warnings->lim && $objp->statutid == 1 ) { }*/ print "'; print !empty($receiving) ? $receiving->getNomUrl($db) : ''; print ''; print dol_print_date($db->jdate($objp->date_reception),"day"); print ''.$expedition->LibStatut($objp->fk_statut,5).'
"; $db->free($resql); } else { dol_print_error($db); } $db->close(); llxFooter();