dolibarr/htdocs/expedition/index.php

297 lines
9.4 KiB
PHP
Raw Normal View History

<?php
2005-04-04 21:53:43 +02:00
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
2011-06-11 04:54:00 +02:00
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
2018-10-27 14:43:12 +02:00
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.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
/**
2009-08-24 15:01:29 +02:00
* \file htdocs/expedition/index.php
* \ingroup expedition
* \brief Home page of shipping area.
2009-08-24 15:01:29 +02:00
*/
require '../main.inc.php';
2016-11-24 17:03:18 +01:00
require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
2003-11-13 18:36:45 +01:00
2018-05-26 20:51:17 +02:00
// Load translation files required by the page
$langs->loadLangs(array('orders', 'sendings'));
2005-04-04 21:38:17 +02:00
2008-02-25 17:30:43 +01:00
/*
2009-08-24 15:01:29 +02:00
* View
*/
2008-02-25 17:30:43 +01:00
$orderstatic=new Commande($db);
$companystatic=new Societe($db);
$shipment=new Expedition($db);
2009-08-24 15:01:29 +02:00
$helpurl='EN:Module_Shipments|FR:Module_Exp&eacute;ditions|ES:M&oacute;dulo_Expediciones';
2013-09-25 19:07:25 +02:00
llxHeader('',$langs->trans("Shipment"),$helpurl);
2003-11-13 18:36:45 +01:00
print load_fiche_titre($langs->trans("SendingsArea"));
2003-11-13 18:36:45 +01:00
print '<div class="fichecenter"><div class="fichethirdleft">';
2003-11-26 16:59:01 +01:00
if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
{
print '<form method="post" action="list.php">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<table class="noborder nohover" width="100%">';
print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
print '<tr class="oddeven"><td>';
print $langs->trans("Shipment").':</td><td><input type="text" class="flat" name="sall" size="18"></td><td><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
print "</table></form><br>\n";
}
2003-11-13 18:36:45 +01:00
/*
2009-08-24 15:01:29 +02:00
* Shipments to validate
2003-11-13 18:36:45 +01:00
*/
$clause = " WHERE ";
2016-11-02 10:29:14 +01:00
$sql = "SELECT e.rowid, e.ref, e.ref_customer,";
$sql.= " s.nom as name, s.rowid as socid,";
$sql.= " c.ref as commande_ref, c.rowid as commande_id";
$sql.= " FROM ".MAIN_DB_PREFIX."expedition as e";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping'";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
2008-03-01 02:26:41 +01:00
if (!$user->rights->societe->client->voir && !$socid)
2003-11-13 18:36:45 +01:00
{
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
$sql.= $clause." sc.fk_user = " .$user->id;
$clause = " AND ";
2003-11-13 18:36:45 +01:00
}
$sql.= $clause." e.fk_statut = 0";
$sql.= " AND e.entity IN (".getEntity('expedition').")";
if ($socid) $sql.= " AND c.fk_soc = ".$socid;
2005-08-15 00:29:38 +02:00
$resql=$db->query($sql);
if ($resql)
2003-11-13 18:36:45 +01:00
{
2009-08-24 15:01:29 +02:00
$num = $db->num_rows($resql);
if ($num)
{
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<th colspan="3">'.$langs->trans("SendingsToValidate").'</th></tr>';
2009-08-24 15:01:29 +02:00
$i = 0;
while ($i < $num)
{
$obj = $db->fetch_object($resql);
$shipment->id=$obj->rowid;
$shipment->ref=$obj->ref;
$shipment->ref_customer=$obj->ref_customer;
2017-05-15 16:25:51 +02:00
print '<tr class="oddeven"><td class="nowrap">';
print $shipment->getNomUrl(1);
print "</td>";
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.$obj->name.'</a>';
print '</td>';
print '<td>';
if ($obj->commande_id) print '<a href="'.DOL_URL_ROOT.'/commande/card.php?id='.$obj->commande_id.'">'.$obj->commande_ref.'</a>';
print '</td></tr>';
2009-08-24 15:01:29 +02:00
$i++;
}
print "</table><br>";
}
2003-11-13 18:36:45 +01:00
}
/*
2009-08-24 15:01:29 +02:00
* Commandes a traiter
2003-11-13 18:36:45 +01:00
*/
2016-11-02 10:29:14 +01:00
$sql = "SELECT c.rowid, c.ref, c.ref_client as ref_customer, c.fk_statut, s.nom as name, s.rowid as socid";
$sql.= " FROM ".MAIN_DB_PREFIX."commande as c,";
$sql.= " ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE c.fk_soc = s.rowid";
2009-12-11 19:30:14 +01:00
$sql.= " AND c.entity = ".$conf->entity;
$sql.= " AND c.fk_statut = 1";
if ($socid) $sql.= " AND c.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
2005-04-14 22:05:16 +02:00
$sql.= " ORDER BY c.rowid ASC";
2003-11-13 18:36:45 +01:00
2010-08-09 17:52:44 +02:00
$resql=$db->query($sql);
if ($resql)
2003-11-13 18:36:45 +01:00
{
2010-08-09 17:52:44 +02:00
$num = $db->num_rows($resql);
2009-08-24 15:01:29 +02:00
if ($num)
2003-11-13 18:36:45 +01:00
{
2009-08-24 15:01:29 +02:00
$langs->load("orders");
$i = 0;
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<th colspan="3">'.$langs->trans("OrdersToProcess").'</th></tr>';
2009-08-24 15:01:29 +02:00
while ($i < $num)
{
2010-08-09 17:52:44 +02:00
$obj = $db->fetch_object($resql);
2016-11-02 10:29:14 +01:00
$orderstatic->id=$obj->rowid;
$orderstatic->ref=$obj->ref;
2016-11-02 10:29:14 +01:00
$orderstatic->ref_customer=$obj->ref_customer;
$orderstatic->statut=$obj->fk_statut;
$orderstatic->billed=0;
2016-11-02 10:29:14 +01:00
$companystatic->name=$obj->name;
$companystatic->id=$obj->socid;
print '<tr class="oddeven">';
2016-11-02 10:29:14 +01:00
print '<td class="nowrap">';
print $orderstatic->getNomUrl(1);
print '</td>';
print '<td>';
2011-06-11 04:54:00 +02:00
print $companystatic->getNomUrl(1,'customer',32);
print '</td>';
print '<td align="right">';
print $orderstatic->getLibStatut(3);
print '</td>';
print '</tr>';
$i++;
2009-08-24 15:01:29 +02:00
}
print "</table><br>";
2003-11-13 18:36:45 +01:00
}
}
2003-11-26 16:59:01 +01:00
//print '</td><td valign="top" width="70%">';
print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
2003-11-26 16:59:01 +01:00
/*
* Commandes en traitement
2003-11-13 18:36:45 +01:00
*/
2016-11-02 10:29:14 +01:00
$sql = "SELECT c.rowid, c.ref, c.ref_client as ref_customer, c.fk_statut as status, c.facture as billed, s.nom as name, s.rowid as socid";
$sql.= " FROM ".MAIN_DB_PREFIX."commande as c,";
$sql.= " ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE c.fk_soc = s.rowid";
2009-12-11 19:30:14 +01:00
$sql.= " AND c.entity = ".$conf->entity;
$sql.= " AND c.fk_statut = 2";
if ($socid) $sql.= " AND c.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
2005-04-04 21:53:43 +02:00
$resql = $db->query($sql);
2009-08-24 15:01:29 +02:00
if ( $resql )
2003-11-13 18:36:45 +01:00
{
2009-08-24 15:01:29 +02:00
$langs->load("orders");
$num = $db->num_rows($resql);
if ($num)
2003-11-13 18:36:45 +01:00
{
2009-08-24 15:01:29 +02:00
$i = 0;
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<th colspan="3">'.$langs->trans("OrdersInProcess").'</th></tr>';
2009-08-24 15:01:29 +02:00
while ($i < $num)
{
$obj = $db->fetch_object($resql);
2016-11-02 10:29:14 +01:00
$orderstatic->id=$obj->rowid;
$orderstatic->ref=$obj->ref;
2016-11-02 10:29:14 +01:00
$orderstatic->ref_customer=$obj->ref_customer;
$orderstatic->statut=$obj->status;
$orderstatic->billed=$obj->billed;
2016-11-02 10:29:14 +01:00
$companystatic->name=$obj->name;
$companystatic->id=$obj->socid;
2017-05-15 16:25:51 +02:00
print '<tr class="oddeven"><td>';
print $orderstatic->getNomUrl(1);
print '</td>';
2010-06-23 03:09:56 +02:00
print '<td>';
print $companystatic->getNomUrl(1,'customer');
2011-06-11 04:59:26 +02:00
print '</td>';
print '<td align="right">';
print $orderstatic->getLibStatut(3);
print '</td>';
print '</tr>';
$i++;
2009-08-24 15:01:29 +02:00
}
print "</table><br>";
2003-11-13 18:36:45 +01:00
}
}
2011-06-11 04:59:26 +02:00
else dol_print_error($db);
2003-11-13 18:36:45 +01:00
/*
2009-08-24 15:01:29 +02:00
* Last shipments
2003-11-13 18:36:45 +01:00
*/
2016-11-02 10:29:14 +01:00
$sql = "SELECT e.rowid, e.ref, e.ref_customer,";
$sql.= " s.nom as name, s.rowid as socid,";
$sql.= " c.ref as commande_ref, c.rowid as commande_id";
$sql.= " FROM ".MAIN_DB_PREFIX."expedition as e";
2012-07-02 16:12:55 +02:00
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping' AND el.sourcetype IN ('commande')";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid AND el.sourcetype IN ('commande') AND el.targettype = 'shipping'";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
2012-07-02 10:14:01 +02:00
if (! $user->rights->societe->client->voir && ! $socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
$sql.= " WHERE e.entity IN (".getEntity('expedition').")";
2012-07-02 10:14:01 +02:00
if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND sc.fk_user = " .$user->id;
$sql.= " AND e.fk_statut = 1";
if ($socid) $sql.= " AND c.fk_soc = ".$socid;
2010-08-26 13:48:30 +02:00
$sql.= " ORDER BY e.date_delivery DESC";
$sql.= $db->plimit(5, 0);
2005-04-04 21:53:43 +02:00
2005-04-17 15:19:06 +02:00
$resql = $db->query($sql);
2009-08-24 15:01:29 +02:00
if ($resql)
2003-11-13 18:36:45 +01:00
{
2009-08-24 15:01:29 +02:00
$num = $db->num_rows($resql);
if ($num)
{
$i = 0;
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
2017-05-15 16:25:51 +02:00
print '<th colspan="3">'.$langs->trans("LastSendings", $num).'</th></tr>';
2009-08-24 15:01:29 +02:00
while ($i < $num)
{
$obj = $db->fetch_object($resql);
2016-11-02 10:29:14 +01:00
$shipment->id=$obj->rowid;
$shipment->ref=$obj->ref;
$shipment->ref_customer=$obj->ref_customer;
print '<tr class="oddeven"><td>';
2016-11-02 10:29:14 +01:00
print $shipment->getNomUrl(1);
print '</td>';
print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a></td>';
2009-08-24 15:01:29 +02:00
print '<td>';
2016-11-02 10:29:14 +01:00
if ($obj->commande_id > 0)
2009-08-24 15:01:29 +02:00
{
$orderstatic->id=$obj->commande_id;
$orderstatic->ref=$obj->commande_ref;
print $orderstatic->getNomUrl(1);
}
else print '&nbsp;';
2009-08-24 15:01:29 +02:00
print '</td></tr>';
$i++;
}
print "</table><br>";
}
$db->free($resql);
2003-11-13 18:36:45 +01:00
}
2011-06-11 04:59:26 +02:00
else dol_print_error($db);
2003-11-13 18:36:45 +01:00
2013-03-30 19:40:52 +01:00
print '</div></div></div>';
2003-11-13 18:36:45 +01:00
2018-08-02 14:03:50 +02:00
// End of page
llxFooter();
2012-07-02 10:14:01 +02:00
$db->close();