dolibarr/htdocs/expedition/list.php

234 lines
8.2 KiB
PHP
Raw Normal View History

<?php
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
2010-02-27 18:30:17 +01:00
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
2012-12-30 15:13:49 +01:00
* Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com>
2003-11-13 18:36:45 +01:00
*
* 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
2003-11-13 18:36:45 +01:00
* (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
2011-08-01 01:45:11 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2003-11-13 18:36:45 +01:00
*/
2005-04-04 21:38:17 +02:00
/**
* \file htdocs/expedition/list.php
2009-08-24 15:01:29 +02:00
* \ingroup expedition
2010-04-21 10:53:55 +02:00
* \brief Page to list all shipments
2009-08-24 15:01:29 +02:00
*/
2003-11-13 18:36:45 +01:00
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
2003-11-13 18:36:45 +01:00
$langs->load("sendings");
$langs->load('companies');
2008-02-25 17:30:43 +01:00
// Security check
2012-03-08 15:28:32 +01:00
$expeditionid = GETPOST('id','int');
2008-02-25 21:03:21 +01:00
if ($user->societe_id) $socid=$user->societe_id;
2008-03-01 02:26:41 +01:00
$result = restrictedArea($user, 'expedition',$expeditionid,'');
2008-02-25 17:30:43 +01:00
$search_ref_exp = GETPOST("search_ref_exp");
$search_ref_liv = GETPOST('search_ref_liv');
$search_company = GETPOST("search_company");
2012-03-08 15:28:32 +01:00
$sortfield = GETPOST('sortfield','alpha');
$sortorder = GETPOST('sortorder','alpha');
$page = GETPOST('page','int');
2003-11-13 18:36:45 +01:00
2010-11-20 14:08:44 +01:00
if ($page == -1) { $page = 0; }
$offset = $conf->liste_limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
$limit = $conf->liste_limit;
2010-04-21 10:53:55 +02:00
if (! $sortfield) $sortfield="e.ref";
2005-04-04 21:38:17 +02:00
if (! $sortorder) $sortorder="DESC";
2003-11-13 18:36:45 +01:00
$limit = $conf->liste_limit;
2015-04-18 01:21:22 +02:00
$viewstatut=GETPOST('viewstatut');
// Purge search criteria
2014-11-23 09:33:32 +01:00
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='';
}
2005-08-15 00:29:38 +02:00
2009-08-24 15:01:29 +02:00
/*
* View
*/
2005-08-15 00:29:38 +02:00
2010-04-21 10:53:55 +02:00
$companystatic=new Societe($db);
$shipment=new Expedition($db);
2010-04-21 10:53:55 +02:00
2009-08-24 15:01:29 +02:00
$helpurl='EN:Module_Shipments|FR:Module_Exp&eacute;ditions|ES:M&oacute;dulo_Expediciones';
llxHeader('',$langs->trans('ListOfSendings'),$helpurl);
2015-01-25 01:20:58 +01:00
$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";
2010-02-27 18:30:17 +01:00
$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";
}
2010-04-21 10:53:55 +02:00
$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";
2009-12-11 19:30:14 +01:00
$sql.= " WHERE e.entity = ".$conf->entity;
2010-02-27 18:30:17 +01:00
if (!$user->rights->societe->client->voir && !$socid) // Internal user with no permission to see all
{
2010-02-27 18:30:17 +01:00
$sql.= " AND e.fk_soc = sc.fk_soc";
$sql.= " AND sc.fk_user = " .$user->id;
}
if ($socid)
2009-08-24 15:01:29 +02:00
{
2010-04-21 10:53:55 +02:00
$sql.= " AND e.fk_soc = ".$socid;
2003-11-13 18:36:45 +01:00
}
2015-04-18 01:21:22 +02:00
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);
2003-11-13 18:36:45 +01:00
2010-04-21 10:53:55 +02:00
$sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($limit + 1,$offset);
2003-11-13 18:36:45 +01:00
2005-04-04 21:38:17 +02:00
$resql=$db->query($sql);
if ($resql)
2003-11-13 18:36:45 +01:00
{
2010-04-21 10:53:55 +02:00
$num = $db->num_rows($resql);
$expedition = new Expedition($db);
$param="";
if ($search_ref_exp) $param.= "&amp;search_ref_exp=".$search_ref_exp;
if ($search_ref_liv) $param.= "&amp;search_ref_liv=".$search_ref_liv;
if ($search_company) $param.= "&amp;search_company=".$search_company;
2010-04-21 10:53:55 +02:00
2014-09-18 20:13:38 +02:00
print_barre_liste($langs->trans('ListOfSendings'), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num);
2010-04-21 10:53:55 +02:00
$i = 0;
print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">'."\n";
2010-04-21 10:53:55 +02:00
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
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 '<td class="liste_titre">&nbsp;</td>';
print "</tr>\n";
// Lignes des champs de filtre
print '<tr class="liste_titre">';
print '<td class="liste_titre">';
print '<input class="flat" size="10" type="text" name="search_ref_exp" value="'.$search_ref_exp.'">';
print '</td>';
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" size="10" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
print '</td>';
// Date
print '<td class="liste_titre">&nbsp;</td>';
if ($conf->livraison_bon->enabled)
{
print '<td class="liste_titre">';
print '<input class="flat" size="10" type="text" name="search_ref_liv" value="'.$search_ref_liv.'"';
print '</td>';
print '<td class="liste_titre">&nbsp;</td>';
}
print '<td class="liste_titre" align="right"><input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"),'search.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
print '<input type="image" class="liste_titre" name="button_removefilter" src="'.img_picto($langs->trans("Search"),'searchclear.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
print '</td>';
print '<td class="liste_titre" align="center">';
print '<a href="#" id="checkall">'.$langs->trans("All").'</a> / <a href="#" id="checknone">'.$langs->trans("None").'</a>';
print '</td>';
2010-04-21 10:53:55 +02:00
print "</tr>\n";
2010-04-21 10:53:55 +02:00
$var=True;
while ($i < min($num,$limit))
{
$objp = $db->fetch_object($resql);
$var=!$var;
// Ref
2013-06-20 09:18:12 +02:00
print "<tr ".$bc[$var].">";
print "<td>";
$shipment->id=$objp->rowid;
$shipment->ref=$objp->ref;
print $shipment->getNomUrl(1);
print "</td>\n";
2010-04-21 10:53:55 +02:00
// Third party
print '<td>';
2010-05-23 03:30:04 +02:00
$companystatic->id=$objp->socid;
$companystatic->ref=$objp->socname;
$companystatic->name=$objp->socname;
2010-04-21 10:53:55 +02:00
print $companystatic->getNomUrl(1);
print '</td>';
// Date delivery planed
2010-04-21 10:53:55 +02:00
print "<td align=\"center\">";
2015-01-25 01:20:58 +01:00
print dol_print_date($db->jdate($objp->date_livraison),"day");
2010-04-21 10:53:55 +02:00
/*$now = time();
if ( ($now - $db->jdate($objp->date_expedition)) > $conf->warnings->lim && $objp->statutid == 1 )
{
}*/
print "</td>\n";
// Date real
print '<td align="center">';
print dol_print_date($db->jdate($objp->date_expedition),"day");
print '</td>'."\n";
if ($conf->livraison_bon->enabled)
{
$shipment->fetchObjectLinked($shipment->id,$shipment->element);
$receiving=(! empty($shipment->linkedObjects['delivery'][0])?$shipment->linkedObjects['delivery'][0]:'');
// Ref
print '<td>';
print !empty($receiving) ? $receiving->getNomUrl($db) : '';
print '</td>';
print '<td align="center">';
2015-01-25 01:20:58 +01:00
print dol_print_date($db->jdate($objp->date_reception),"day");
print '</td>'."\n";
}
2010-04-21 10:53:55 +02:00
print '<td align="right">'.$expedition->LibStatut($objp->fk_statut,5).'</td>';
print "</tr>\n";
$i++;
}
print "</table>";
$db->free($resql);
2003-11-26 17:04:22 +01:00
}
else
{
2010-04-21 10:53:55 +02:00
dol_print_error($db);
2003-11-26 17:04:22 +01:00
}
2003-11-13 18:36:45 +01:00
$db->close();
2005-04-04 21:38:17 +02:00
llxFooter();