2004-10-19 22:43:23 +02:00
< ? php
2005-04-15 12:34:44 +02:00
/* Copyright ( C ) 2003 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2006-05-06 23:09:26 +02:00
* Copyright ( C ) 2005 - 2006 Laurent Destailleur < eldy @ users . sourceforge . net >
2007-05-16 00:47:58 +02:00
* Copyright ( C ) 2005 Simon TOSSER < simon @ kornog - computing . com >
* Copyright ( C ) 2005 - 2007 R<EFBFBD> gis Houssin < regis . houssin @ cap - networks . 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 2 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 , write to the Free Software
* Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*
* $Id $
* $Source $
*/
2004-08-14 15:05:12 +02:00
2005-09-11 18:51:41 +02:00
// Code identique a /expedition/commande.php
2005-07-09 03:16:31 +02:00
/**
\file htdocs / expedition / fiche . php
\ingroup expedition
\brief Fiche descriptive d ' une expedition
\version $Revision $
2004-08-14 15:05:12 +02:00
*/
2003-11-13 18:36:45 +01:00
require ( " ./pre.inc.php " );
2006-05-06 23:09:26 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /expedition/mods/pdf/ModelePdfExpedition.class.php " );
2005-09-11 18:51:41 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /product.class.php " );
require_once ( DOL_DOCUMENT_ROOT . " /propal.class.php " );
require_once ( DOL_DOCUMENT_ROOT . " /product/stock/entrepot.class.php " );
2003-11-13 18:36:45 +01:00
2006-06-24 19:10:32 +02:00
$langs -> load ( " companies " );
2005-08-23 21:31:25 +02:00
$langs -> load ( " bills " );
2006-06-01 12:30:47 +02:00
$langs -> load ( 'deliveries' );
2006-06-24 19:10:32 +02:00
$langs -> load ( 'orders' );
2006-07-14 13:31:57 +02:00
$langs -> load ( 'stocks' );
2007-05-16 01:03:08 +02:00
$langs -> load ( 'other' );
2005-04-15 12:34:44 +02:00
2006-01-14 14:45:04 +01:00
$user -> getrights ( 'expedition' );
2003-11-13 18:36:45 +01:00
if ( ! $user -> rights -> expedition -> lire )
accessforbidden ();
2005-07-09 03:16:31 +02:00
// S<> curit<69> acc<63> s client
2006-11-11 01:46:15 +01:00
if ( $user -> societe_id > 0 )
2003-11-13 18:36:45 +01:00
{
$action = '' ;
2006-09-13 20:56:30 +02:00
$socid = $user -> societe_id ;
2003-11-13 18:36:45 +01:00
}
2005-07-09 03:16:31 +02:00
2003-11-13 18:36:45 +01:00
/*
2005-07-09 03:16:31 +02:00
* Actions
2005-04-16 16:00:07 +02:00
*/
2006-11-11 01:46:15 +01:00
if ( $_POST [ " action " ] == 'add' )
2003-11-13 18:36:45 +01:00
{
2006-07-14 13:31:57 +02:00
// \todo Mettre id entrepot sur ligne detail expedition et non sur fiche expedition
2006-11-11 01:46:15 +01:00
2005-09-22 01:43:07 +02:00
$db -> begin ();
2006-11-11 01:46:15 +01:00
2005-09-22 01:43:07 +02:00
// Creation de l'objet expedition
2005-07-09 03:16:31 +02:00
$expedition = new Expedition ( $db );
2006-11-11 01:46:15 +01:00
2005-07-09 03:16:31 +02:00
$expedition -> date_expedition = time ();
$expedition -> note = $_POST [ " note " ];
$expedition -> commande_id = $_POST [ " commande_id " ];
$expedition -> entrepot_id = $_POST [ " entrepot_id " ];
2006-11-11 01:46:15 +01:00
2005-09-22 01:43:07 +02:00
// On boucle sur chaque ligne de commande pour compl<70> ter objet expedition
// avec qt<71> <20> livrer
2005-07-09 03:16:31 +02:00
$commande = new Commande ( $db );
$commande -> fetch ( $expedition -> commande_id );
2007-05-15 17:53:46 +02:00
$commande -> fetch_lines ();
2005-07-09 03:16:31 +02:00
for ( $i = 0 ; $i < sizeof ( $commande -> lignes ) ; $i ++ )
2003-11-13 18:36:45 +01:00
{
2005-07-09 03:16:31 +02:00
$qty = " qtyl " . $i ;
$idl = " idl " . $i ;
if ( $_POST [ $qty ] > 0 )
{
$expedition -> addline ( $_POST [ $idl ], $_POST [ $qty ]);
}
}
2006-11-11 01:46:15 +01:00
2005-07-09 03:16:31 +02:00
$ret = $expedition -> create ( $user );
if ( $ret > 0 )
{
$db -> commit ();
Header ( " Location: fiche.php?id= " . $expedition -> id );
exit ;
}
else
{
$db -> rollback ();
$mesg = '<div class="error">' . $expedition -> error . '</div>' ;
$_GET [ " commande_id " ] = $_POST [ " commande_id " ];
$_GET [ " action " ] = 'create' ;
2003-11-13 18:36:45 +01:00
}
}
2006-05-30 15:49:03 +02:00
/*
* G<EFBFBD> n<EFBFBD> re un bon de livraison
*/
2006-05-30 17:22:01 +02:00
if ( $_GET [ " action " ] == 'create_delivery' && $conf -> livraison -> enabled && $user -> rights -> expedition -> livraison -> creer )
2006-05-30 15:49:03 +02:00
{
$expedition = new Expedition ( $db );
$expedition -> fetch ( $_GET [ " id " ]);
2006-05-30 17:02:32 +02:00
$result = $expedition -> create_delivery ( $user );
2006-05-30 17:22:01 +02:00
Header ( " Location: " . DOL_URL_ROOT . '/livraison/fiche.php?id=' . $result );
2006-05-30 15:49:03 +02:00
}
2005-04-12 20:21:30 +02:00
if ( $_POST [ " action " ] == 'confirm_valid' && $_POST [ " confirm " ] == 'yes' && $user -> rights -> expedition -> valider )
2003-11-13 18:36:45 +01:00
{
$expedition = new Expedition ( $db );
$expedition -> fetch ( $_GET [ " id " ]);
$result = $expedition -> valid ( $user );
2006-05-29 15:53:20 +02:00
//$expedition->PdfWrite();
2003-11-13 18:36:45 +01:00
}
2005-04-12 20:21:30 +02:00
if ( $_POST [ " action " ] == 'confirm_delete' && $_POST [ " confirm " ] == 'yes' )
2003-11-13 18:36:45 +01:00
{
2006-11-11 01:46:15 +01:00
if ( $user -> rights -> expedition -> supprimer )
2003-11-13 18:36:45 +01:00
{
$expedition = new Expedition ( $db );
2006-07-14 13:31:57 +02:00
$expedition -> fetch ( $_GET [ " id " ]);
2003-11-13 18:36:45 +01:00
$expedition -> delete ();
Header ( " Location: liste.php " );
}
}
2005-07-09 16:58:25 +02:00
/*
* G<EFBFBD> n<EFBFBD> rer ou reg<EFBFBD> n<EFBFBD> rer le PDF
*/
2006-05-06 23:09:26 +02:00
if ( $_REQUEST [ 'action' ] == 'builddoc' ) // En get ou en post
2005-04-16 16:00:07 +02:00
{
2006-07-14 15:26:19 +02:00
// Sauvegarde le dernier mod<6F> le choisi pour g<> n<EFBFBD> rer un document
$expedition = new Expedition ( $db , 0 , $_REQUEST [ 'id' ]);
$expedition -> fetch ( $_REQUEST [ 'id' ]);
2006-08-26 16:13:37 +02:00
2006-07-14 15:26:19 +02:00
if ( $_REQUEST [ 'model' ])
{
$expedition -> set_pdf_model ( $user , $_REQUEST [ 'model' ]);
}
2006-06-18 17:48:28 +02:00
if ( $_REQUEST [ 'lang_id' ])
{
2007-05-25 22:02:23 +02:00
$outputlangs = new Translate ( DOL_DOCUMENT_ROOT . " /langs " , $conf );
2006-06-18 17:48:28 +02:00
$outputlangs -> setDefaultLang ( $_REQUEST [ 'lang_id' ]);
}
2006-08-26 15:47:10 +02:00
$result = expedition_pdf_create ( $db , $expedition -> id , $expedition -> modelpdf , $outputlangs );
2006-05-06 23:09:26 +02:00
if ( $result <= 0 )
{
dolibarr_print_error ( $db , $result );
exit ;
2006-11-11 01:46:15 +01:00
}
2005-04-16 16:00:07 +02:00
}
2005-07-09 03:16:31 +02:00
2003-11-13 18:36:45 +01:00
/*
*
*/
2006-06-04 01:53:10 +02:00
llxHeader ( '' , 'Fiche expedition' , 'ch-expedition.html' , $form_search );
2003-11-13 18:36:45 +01:00
$html = new Form ( $db );
/*********************************************************************
*
* Mode creation
*
2005-07-09 03:16:31 +02:00
*********************************************************************/
2006-11-11 01:46:15 +01:00
if ( $_GET [ " action " ] == 'create' )
2003-11-13 18:36:45 +01:00
{
2004-02-13 18:13:39 +01:00
2006-07-14 13:31:57 +02:00
print_titre ( $langs -> trans ( " CreateASending " ));
if ( $mesg )
{
print $mesg . '<br>' ;
}
$commande = new Commande ( $db );
2006-09-03 14:12:56 +02:00
$commande -> loadExpeditions ();
2006-07-14 13:31:57 +02:00
if ( $commande -> fetch ( $_GET [ " commande_id " ]))
{
$soc = new Societe ( $db );
2006-09-13 20:56:30 +02:00
$soc -> fetch ( $commande -> socid );
2006-08-20 01:00:53 +02:00
2006-07-14 13:31:57 +02:00
$author = new User ( $db );
$author -> id = $commande -> user_author_id ;
$author -> fetch ();
$entrepot = new Entrepot ( $db );
/*
* Commande
*/
print '<form action="fiche.php" method="post">' ;
print '<input type="hidden" name="action" value="add">' ;
print '<input type="hidden" name="commande_id" value="' . $commande -> id . '">' ;
if ( $_GET [ " entrepot_id " ])
{
print '<input type="hidden" name="entrepot_id" value="' . $_GET [ " entrepot_id " ] . '">' ;
}
print '<table class="border" width="100%">' ;
// Ref commande
print '<tr><td>' . $langs -> trans ( " RefOrder " ) . '</td><td colspan="3"><a href="' . DOL_URL_ROOT . '/commande/fiche.php?id=' . $commande -> id . '">' . img_object ( $langs -> trans ( " ShowOrder " ), 'order' ) . ' ' . $commande -> ref . '</a></td>' ;
print " </tr> \n " ;
2006-06-24 19:10:32 +02:00
// Ref commande client
print '<tr><td>' ;
2006-07-14 13:31:57 +02:00
print '<table class="nobordernopadding" width="100%"><tr><td nowrap>' ;
2006-06-24 19:10:32 +02:00
print $langs -> trans ( 'RefCustomerOrderShort' ) . '</td><td align="left">' ;
2006-07-14 13:31:57 +02:00
print '</td>' ;
2006-08-03 13:53:09 +02:00
if ( $_GET [ 'action' ] != 'RefCustomerOrder' && $commande -> brouillon ) print '<td align="right"><a href="' . $_SERVER [ 'PHP_SELF' ] . '?action=RefCustomerOrder&id=' . $commande -> id . '">' . img_edit ( $langs -> trans ( 'Edit' )) . '</a></td>' ;
2006-07-14 13:31:57 +02:00
print '</tr></table>' ;
print '</td><td colspan="3">' ;
2006-08-03 13:53:09 +02:00
if ( $user -> rights -> commande -> creer && $_GET [ 'action' ] == 'RefCustomerOrder' )
2006-06-24 19:10:32 +02:00
{
print '<form action="fiche.php?id=' . $id . '" method="post">' ;
print '<input type="hidden" name="action" value="set_ref_client">' ;
print '<input type="text" class="flat" size="20" name="ref_client" value="' . $commande -> ref_client . '">' ;
print ' <input type="submit" class="button" value="' . $langs -> trans ( 'Modify' ) . '">' ;
print '</form>' ;
}
else
{
print $commande -> ref_client ;
}
print '</td>' ;
print '</tr>' ;
2006-07-14 13:31:57 +02:00
// Soci<63> t
2006-06-24 19:10:32 +02:00
print '<tr><td>' . $langs -> trans ( 'Company' ) . '</td>' ;
print '<td colspan="3">' . $soc -> getNomUrl ( 1 ) . '</td>' ;
print '</tr>' ;
2006-07-14 13:31:57 +02:00
2006-06-24 19:10:32 +02:00
// Date
print " <tr><td> " . $langs -> trans ( " Date " ) . " </td> " ;
2007-06-16 15:56:05 +02:00
print '<td colspan="3">' . dolibarr_print_date ( $commande -> date , " dayhour " ) . " </td></tr> \n " ;
2006-07-14 13:31:57 +02:00
// Entrepot (si forc<72> )
if ( $conf -> stock -> enabled && $_GET [ " entrepot_id " ])
{
2006-06-24 19:10:32 +02:00
print '<tr><td>' . $langs -> trans ( " Warehouse " ) . '</td>' ;
print '<td colspan="3">' ;
$ents = $entrepot -> list_array ();
print '<a href="' . DOL_URL_ROOT . '/product/stock/fiche.php?id=' . $_GET [ " entrepot_id " ] . '">' . img_object ( $langs -> trans ( " ShowWarehouse " ), 'stock' ) . ' ' . $ents [ $_GET [ " entrepot_id " ]] . '</a>' ;
print '</td></tr>' ;
}
2006-07-14 13:31:57 +02:00
2006-08-19 00:03:47 +02:00
if ( $commande -> note && ! $user -> societe_id )
2006-06-24 19:10:32 +02:00
{
2006-07-14 13:31:57 +02:00
print '<tr><td colspan="3">' . $langs -> trans ( " NotePrivate " ) . ': ' . nl2br ( $commande -> note ) . " </td></tr> " ;
2006-06-24 19:10:32 +02:00
}
print " </table> " ;
2006-07-14 13:31:57 +02:00
/*
* Lignes de commandes
*
*/
echo '<br><table class="noborder" width="100%">' ;
2007-05-15 17:53:46 +02:00
$lignes = $commande -> fetch_lines ( 1 );
2006-07-14 13:31:57 +02:00
/* Lecture des expeditions d<> j<EFBFBD> effectu<74> es */
2006-09-03 14:12:56 +02:00
$commande -> loadExpeditions ();
2006-07-14 13:31:57 +02:00
$num = sizeof ( $commande -> lignes );
$i = 0 ;
if ( $num )
{
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " Description " ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " QtyOrdered " ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " QtyShipped " ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " QtyToShip " ) . '</td>' ;
if ( $conf -> stock -> enabled )
{
if ( $_GET [ " entrepot_id " ])
{
print '<td align="right">' . $langs -> trans ( " Stock " ) . '</td>' ;
}
else
{
print '<td align="left">' . $langs -> trans ( " Warehouse " ) . '</td>' ;
}
}
print " </tr> \n " ;
}
$var = true ;
while ( $i < $num )
{
$ligne = $commande -> lignes [ $i ];
$var =! $var ;
print " <tr $bc[$var] > \n " ;
if ( $ligne -> fk_product > 0 )
{
$product = new Product ( $db );
$product -> fetch ( $ligne -> fk_product );
print '<td>' ;
print '<a href="' . DOL_URL_ROOT . '/product/fiche.php?id=' . $ligne -> fk_product . '">' . img_object ( $langs -> trans ( " ShowProduct " ), " product " ) . ' ' . $product -> ref . '</a> - ' . $product -> libelle ;
if ( $ligne -> description ) print nl2br ( $ligne -> description );
print '</td>' ;
}
else
{
print " <td> " . nl2br ( $ligne -> description ) . " </td> \n " ;
}
print '<td align="center">' . $ligne -> qty . '</td>' ;
print '<td align="center">' ;
$quantite_livree = $commande -> expeditions [ $ligne -> fk_product ];
print $quantite_livree ;;
print '</td>' ;
$quantite_commandee = $ligne -> qty ;
$quantite_a_livrer = $quantite_commandee - $quantite_livree ;
if ( $conf -> stock -> enabled )
{
$defaultqty = 0 ;
if ( $_GET [ " entrepot_id " ])
{
$stock = $product -> stock_entrepot [ $_GET [ " entrepot_id " ]];
$stock += 0 ; // Convertit en num<75> rique
$defaultqty = min ( $quantite_a_livrer , $stock );
}
// Quantit<69> <20> livrer
print '<td align="center">' ;
print '<input name="idl' . $i . '" type="hidden" value="' . $ligne -> id . '">' ;
print '<input name="qtyl' . $i . '" type="text" size="4" value="' . $defaultqty . '">' ;
print '</td>' ;
// Stock
if ( $_GET [ " entrepot_id " ])
{
print '<td align="right">' . $stock ;
if ( $stock < $quantite_a_livrer )
{
print ' ' . img_warning ( $langs -> trans ( " StockTooLow " ));
}
print '</td>' ;
}
else
{
$array = array ();
$sql = " SELECT e.rowid, e.label, ps.reel " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " product_stock as ps, " . MAIN_DB_PREFIX . " entrepot as e " ;
$sql .= " WHERE ps.fk_entrepot = e.rowid AND fk_product = ' " . $product -> id . " ' " ;
$result = $db -> query ( $sql ) ;
if ( $result )
{
$num = $db -> num_rows ( $result );
$i = 0 ;
if ( $num > 0 )
{
while ( $i < $num )
{
$obj = $db -> fetch_object ( $result );
$array [ $obj -> rowid ] = $obj -> label . ' (' . $obj -> reel . ')' ;
$i ++ ;
}
}
$db -> free ( $result );
}
else
{
$this -> error = $db -> error ();
2006-11-11 01:46:15 +01:00
return - 1 ;
2006-07-14 13:31:57 +02:00
}
print '<td align="left">' ;
2006-11-11 01:46:15 +01:00
$html -> select_array ( 'warehouse' . $i , $array , '' , 1 , 0 , 0 );
2006-07-14 13:31:57 +02:00
print '</td>' ;
}
}
else
{
// Quantit<69> <20> livrer
print '<td align="center">' ;
print '<input name="idl' . $i . '" type="hidden" value="' . $ligne -> id . '">' ;
print '<input name="qtyl' . $i . '" type="text" size="6" value="' . $quantite_a_livrer . '">' ;
print '</td>' ;
}
print " </tr> \n " ;
$i ++ ;
$var =! $var ;
}
/*
*
*/
print '<tr><td align="center" colspan="5"><br><input type="submit" class="button" value="' . $langs -> trans ( " Create " ) . '"></td></tr>' ;
print " </table> " ;
print '</form>' ;
2003-11-13 18:36:45 +01:00
}
2006-07-14 13:31:57 +02:00
else
2003-11-13 18:36:45 +01:00
{
2006-07-14 13:31:57 +02:00
dolibarr_print_error ( $db );
}
}
2006-11-11 01:46:15 +01:00
else
2003-11-13 18:36:45 +01:00
/* *************************************************************************** */
/* */
/* Mode vue et edition */
/* */
/* *************************************************************************** */
2006-11-11 01:46:15 +01:00
{
2006-01-14 14:45:04 +01:00
if ( $_GET [ " id " ] > 0 )
2003-11-13 18:36:45 +01:00
{
2006-01-14 14:45:04 +01:00
$expedition = New Expedition ( $db );
$result = $expedition -> fetch ( $_GET [ " id " ]);
2007-05-16 00:47:58 +02:00
$lignes = $expedition -> lignes ;
$num_prod = sizeof ( $lignes );
2006-11-11 01:46:15 +01:00
2006-06-04 01:53:10 +02:00
if ( $expedition -> id > 0 )
2005-09-22 01:43:07 +02:00
{
2006-01-14 14:45:04 +01:00
$author = new User ( $db );
$author -> id = $expedition -> user_author_id ;
$author -> fetch ();
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
$commande = New Commande ( $db );
$commande -> fetch ( $expedition -> commande_id );
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
$soc = new Societe ( $db );
2006-09-13 20:56:30 +02:00
$soc -> fetch ( $commande -> socid );
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
$h = 0 ;
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /expedition/fiche.php?id= " . $expedition -> id ;
$head [ $h ][ 1 ] = $langs -> trans ( " SendingCard " );
$hselected = $h ;
$h ++ ;
2006-11-11 01:46:15 +01:00
2006-05-30 17:40:05 +02:00
if ( $conf -> livraison -> enabled && $expedition -> livraison_id )
2006-05-29 15:53:20 +02:00
{
2006-05-30 17:40:05 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /livraison/fiche.php?id= " . $expedition -> livraison_id ;
2006-05-29 15:53:20 +02:00
$head [ $h ][ 1 ] = $langs -> trans ( " DeliveryCard " );
$h ++ ;
}
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
dolibarr_fiche_head ( $head , $hselected , $langs -> trans ( " Sending " ));
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
/*
* Confirmation de la suppression
*
*/
if ( $_GET [ " action " ] == 'delete' )
{
2006-11-11 01:46:15 +01:00
$html -> form_confirm ( " fiche.php?id= $expedition->id " , $langs -> trans ( " DeleteSending " ), " Etes-vous s<> r de vouloir supprimer cette expedition ? " , " confirm_delete " );
2006-01-14 14:45:04 +01:00
print '<br>' ;
}
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
/*
* Confirmation de la validation
*
*/
if ( $_GET [ " action " ] == 'valid' )
{
2006-11-11 01:46:15 +01:00
$html -> form_confirm ( " fiche.php?id= $expedition->id " , $langs -> trans ( " ValidateSending " ), " Etes-vous s<> r de vouloir valider cette exp<78> dition ? " , " confirm_valid " );
2006-01-14 14:45:04 +01:00
print '<br>' ;
}
/*
* Confirmation de l ' annulation
*
*/
if ( $_GET [ " action " ] == 'annuler' )
2005-09-22 01:43:07 +02:00
{
2006-11-11 01:46:15 +01:00
$html -> form_confirm ( " fiche.php?id= $expedition->id " , $langs -> trans ( " CancelSending " ), " Etes-vous s<> r de vouloir annuler cette commande ? " , " confirm_cancel " );
2005-09-22 01:43:07 +02:00
print '<br>' ;
2006-01-14 14:45:04 +01:00
}
2007-05-16 00:47:58 +02:00
// calcul du poids total et du volume total des produits
//TODO: ajouter conversion pour le poids et le volume et selection de l'unit<69> de mesure la plus utilis<69> e
$totalWeight = '' ;
$totalVolume = '' ;
for ( $i = 0 ; $i < $num_prod ; $i ++ )
2006-01-14 14:45:04 +01:00
{
2007-05-16 00:47:58 +02:00
$totalWeight += $lignes [ $i ] -> weight * $lignes [ $i ] -> qty_expedie ;
$weightUnit = $lignes [ $i ] -> weight_units ;
$totalVolume += $lignes [ $i ] -> volume * $lignes [ $i ] -> qty_expedie ;
$volumeUnit = $lignes [ $i ] -> volume_units ;
2006-01-14 14:45:04 +01:00
}
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
print '<table class="border" width="100%">' ;
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
// Ref
print '<tr><td width="20%">' . $langs -> trans ( " Ref " ) . '</td>' ;
print '<td colspan="3">' . $expedition -> ref . '</td></tr>' ;
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
// Client
print '<tr><td width="20%">' . $langs -> trans ( " Customer " ) . '</td>' ;
2006-06-24 19:10:32 +02:00
print '<td colspan="3">' . $soc -> getNomUrl ( 1 ) . '</td>' ;
2006-01-14 14:45:04 +01:00
print " </tr> " ;
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
// Commande li<6C> e
2006-06-24 19:10:32 +02:00
print '<tr><td>' . $langs -> trans ( " RefOrder " ) . '</td>' ;
print '<td colspan="3"><a href="' . DOL_URL_ROOT . '/expedition/commande.php?id=' . $commande -> id . '">' . img_object ( $langs -> trans ( " ShowOrder " ), 'order' ) . ' ' . $commande -> ref . " </a></td> \n " ;
print '</tr>' ;
2006-11-11 01:46:15 +01:00
2006-06-24 19:10:32 +02:00
// Commande li<6C> e
print '<tr><td>' . $langs -> trans ( " RefCustomerOrderShort " ) . '</td>' ;
print '<td colspan="3"><a href="' . DOL_URL_ROOT . '/expedition/commande.php?id=' . $commande -> id . '">' . $commande -> ref_client . " </a></td> \n " ;
print '</tr>' ;
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
// Date
print '<tr><td>' . $langs -> trans ( " Date " ) . '</td>' ;
2007-06-16 15:56:05 +02:00
print '<td colspan="3">' . dolibarr_print_date ( $expedition -> date , " dayhour " ) . " </td> \n " ;
2007-05-16 00:47:58 +02:00
print '</tr>' ;
// Poids Total
print '<tr><td>' . $langs -> trans ( " TotalWeight " ) . '</td>' ;
print '<td colspan="3">' . $totalWeight . ' ' . measuring_units_string ( $weightUnit , " weight " ) . " </td> \n " ;
print '</tr>' ;
// Volume Total
print '<tr><td>' . $langs -> trans ( " TotalVolume " ) . '</td>' ;
2007-05-16 01:04:48 +02:00
print '<td colspan="3">' . $totalVolume . ' ' . measuring_units_string ( $volumeUnit , " volume " ) . " </td> \n " ;
2007-05-16 00:47:58 +02:00
print '</tr>' ;
2006-07-14 13:31:57 +02:00
// Statut
print '<tr><td>' . $langs -> trans ( " Status " ) . '</td>' ;
2006-07-14 15:26:19 +02:00
print '<td colspan="3">' . $expedition -> getLibStatut ( 4 ) . " </td> \n " ;
2007-05-16 00:47:58 +02:00
print '</tr>' ;
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
print " </table> \n " ;
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
/*
* Lignes produits
*/
2007-05-16 00:47:58 +02:00
print '<br><table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " Products " ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " QtyOrdered " ) . '</td>' ;
if ( $expedition -> fk_statut <= 1 )
2006-01-14 14:45:04 +01:00
{
2007-05-16 00:47:58 +02:00
print '<td align="center">' . $langs -> trans ( " QtyToShip " ) . '</td>' ;
}
else
{
print '<td align="center">' . $langs -> trans ( " QtyShipped " ) . '</td>' ;
}
print '<td align="center">' . $langs -> trans ( " Weight " ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " Volume " ) . '</td>' ;
if ( $conf -> stock -> enabled )
{
print '<td align="left">' . $langs -> trans ( " WarehouseSource " ) . '</td>' ;
}
print " </tr> \n " ;
2006-11-11 01:46:15 +01:00
2007-05-16 00:47:58 +02:00
$var = true ;
for ( $i = 0 ; $i < $num_prod ; $i ++ )
{
$var =! $var ;
print " <tr $bc[$var] > " ;
if ( $lignes [ $i ] -> fk_product > 0 )
{
print '<td>' ;
print '<a href="' . DOL_URL_ROOT . '/product/fiche.php?id=' . $lignes [ $i ] -> fk_product . '">' . img_object ( $langs -> trans ( " ShowProduct " ), " product " ) . ' ' . $lignes [ $i ] -> ref . '</a> - ' . $lignes [ $i ] -> libelle ;
if ( $lignes [ $i ] -> description ) print '<br>' . nl2br ( $lignes [ $i ] -> description );
print '</td>' ;
}
else
{
print " <td> " . nl2br ( $lignes [ $i ] -> description ) . " </td> \n " ;
}
// Qte command<6E>
print '<td align="center">' . $lignes [ $i ] -> qty_commande . '</td>' ;
// Qte a expedier ou expedier
print '<td align="center">' . $lignes [ $i ] -> qty_expedie . '</td>' ;
// Poids
print '<td align="center">' . $lignes [ $i ] -> weight * $lignes [ $i ] -> qty_expedie . ' ' . measuring_units_string ( $lignes [ $i ] -> weight_units , " weight " ) . '</td>' ;
// Volume
print '<td align="center">' . $lignes [ $i ] -> volume * $lignes [ $i ] -> qty_expedie . ' ' . measuring_units_string ( $lignes [ $i ] -> volume_units , " volume " ) . '</td>' ;
// Entrepot source
if ( $conf -> stock -> enabled )
{
$entrepot = new Entrepot ( $db );
$entrepot -> fetch ( $expedition -> entrepot_id );
print '<td align="left">' . $entrepot -> getNomUrl ( 1 ) . '</td>' ;
}
2006-11-11 01:46:15 +01:00
2007-05-16 00:47:58 +02:00
print " </tr> " ;
2007-05-16 00:50:08 +02:00
2007-05-16 00:47:58 +02:00
$var =! $var ;
}
2006-01-14 14:45:04 +01:00
}
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
print " </table> \n " ;
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
print " \n </div> \n " ;
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
/*
* Boutons actions
*/
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
if ( $user -> societe_id == 0 )
{
print '<div class="tabsAction">' ;
2006-11-11 01:46:15 +01:00
if ( ! eregi ( '^(valid|delete)' , $_REQUEST [ " action " ]))
2006-01-14 14:45:04 +01:00
{
2006-11-11 01:46:15 +01:00
if ( $expedition -> statut == 0 && $user -> rights -> expedition -> valider && $num_prod > 0 )
{
print '<a class="butAction" href="fiche.php?id=' . $expedition -> id . '&action=valid">' . $langs -> trans ( " Validate " ) . '</a>' ;
}
if ( $conf -> livraison -> enabled && $expedition -> statut == 1 && $user -> rights -> expedition -> livraison -> creer && ! $expedition -> livraison_id )
{
print '<a class="butAction" href="fiche.php?id=' . $expedition -> id . '&action=create_delivery">' . $langs -> trans ( " DeliveryOrder " ) . '</a>' ;
}
if ( $user -> rights -> expedition -> lire && ( $expedition -> statut > 0 ))
{
print '<a class="butAction" href="fiche.php?id=' . $expedition -> id . '&action=builddoc">' . $langs -> trans ( 'BuildPDF' ) . '</a>' ;
}
if ( $expedition -> brouillon && $user -> rights -> expedition -> supprimer )
{
print '<a class="butActionDelete" href="fiche.php?id=' . $expedition -> id . '&action=delete">' . $langs -> trans ( " Delete " ) . '</a>' ;
}
}
2006-01-14 14:45:04 +01:00
print '</div>' ;
}
2006-11-11 01:46:15 +01:00
print " \n " ;
2006-05-06 23:09:26 +02:00
print " <table width= \" 100% \" cellspacing=2><tr><td width= \" 50% \" valign= \" top \" > " ;
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
/*
* Documents g<EFBFBD> n<EFBFBD> r<EFBFBD> s
*/
2006-11-11 01:46:15 +01:00
2006-05-31 13:34:05 +02:00
$expeditionref = sanitize_string ( $expedition -> ref );
$filedir = $conf -> expedition -> dir_output . " / " . $expeditionref ;
2006-11-11 01:46:15 +01:00
2006-05-31 13:34:05 +02:00
$urlsource = $_SERVER [ " PHP_SELF " ] . " ?id= " . $expedition -> id ;
2006-11-11 01:46:15 +01:00
2006-07-14 15:26:19 +02:00
$genallowed = $user -> rights -> expedition -> lire && ( $expedition -> statut > 0 );
2006-05-31 13:34:05 +02:00
$delallowed = $user -> rights -> expedition -> supprimer ;
//$genallowed=1;
//$delallowed=0;
2006-11-11 01:46:15 +01:00
2006-07-02 15:45:06 +02:00
$somethingshown = $html -> show_documents ( 'expedition' , $expeditionref , $filedir , $urlsource , $genallowed , $delallowed , $expedition -> modelpdf );
2006-07-14 13:31:57 +02:00
if ( $genallowed && ! $somethingshown ) $somethingshown = 1 ;
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
/*
2006-07-14 15:26:19 +02:00
* Autres expeditions
2006-01-14 14:45:04 +01:00
*/
$sql = " SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande " ;
$sql .= " , ed.qty as qty_livre, e.ref, ed.fk_expedition as expedition_id " ;
$sql .= " , " . $db -> pdate ( " e.date_expedition " ) . " as date_expedition " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " commandedet as cd " ;
$sql .= " , " . MAIN_DB_PREFIX . " expeditiondet as ed, " . MAIN_DB_PREFIX . " expedition as e " ;
$sql .= " WHERE cd.fk_commande = " . $expedition -> commande_id ;
$sql .= " AND e.rowid <> " . $expedition -> id ;
$sql .= " AND cd.rowid = ed.fk_commande_ligne " ;
$sql .= " AND ed.fk_expedition = e.rowid " ;
$sql .= " ORDER BY cd.fk_product " ;
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
if ( $num )
{
2006-07-14 13:31:57 +02:00
if ( $somethingshown ) print '<br>' ;
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
print_titre ( $langs -> trans ( " OtherSendingsForSameOrder " ));
print '<table class="liste" width="100%">' ;
print '<tr class="liste_titre">' ;
2006-06-24 19:10:32 +02:00
print '<td align="left">' . $langs -> trans ( " Ref " ) . '</td>' ;
2006-05-06 23:09:26 +02:00
print '<td>' . $langs -> trans ( " Description " ) . '</td>' ;
2006-07-14 13:31:57 +02:00
print '<td align="center">' . $langs -> trans ( " Qty " ) . '</td>' ;
2006-01-14 14:45:04 +01:00
print '<td align="center">' . $langs -> trans ( " Date " ) . '</td>' ;
print " </tr> \n " ;
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
$var = True ;
while ( $i < $num )
{
$var =! $var ;
$objp = $db -> fetch_object ( $resql );
print " <tr $bc[$var] > " ;
2006-06-24 19:10:32 +02:00
print '<td align="left" nowrap="nowrap"><a href="' . DOL_URL_ROOT . '/expedition/fiche.php?id=' . $objp -> expedition_id . '">' . img_object ( $langs -> trans ( " ShowSending " ), 'sending' ) . ' ' . $objp -> ref . '<a></td>' ;
2006-01-14 14:45:04 +01:00
if ( $objp -> fk_product > 0 )
{
$product = new Product ( $db );
$product -> fetch ( $objp -> fk_product );
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
print '<td>' ;
2006-07-14 13:31:57 +02:00
print '<a href="' . DOL_URL_ROOT . '/product/fiche.php?id=' . $objp -> fk_product . '">' . img_object ( $langs -> trans ( " ShowProduct " ), " product " ) . ' ' . $product -> ref . '</a> - ' . dolibarr_trunc ( $product -> libelle , 20 );
if ( $objp -> description ) print nl2br ( dolibarr_trunc ( $objp -> description , 24 ));
2006-01-14 14:45:04 +01:00
print '</td>' ;
}
else
{
2006-07-14 13:31:57 +02:00
print " <td> " . nl2br ( dolibarr_trunc ( $objp -> description , 24 )) . " </td> \n " ;
2006-01-14 14:45:04 +01:00
}
print '<td align="center">' . $objp -> qty_livre . '</td>' ;
2006-06-24 19:10:32 +02:00
print '<td align="center" nowrap="nowrap">' . dolibarr_print_date ( $objp -> date_expedition ) . '</td>' ;
2006-05-06 23:09:26 +02:00
print '</tr>' ;
2006-01-14 14:45:04 +01:00
$i ++ ;
}
2006-11-11 01:46:15 +01:00
2006-01-14 14:45:04 +01:00
print '</table>' ;
}
$db -> free ( $resql );
}
2007-05-16 00:47:58 +02:00
else
{
dolibarr_print_error ( $db );
2006-01-14 14:45:04 +01:00
}
2006-11-11 01:46:15 +01:00
2006-05-06 23:09:26 +02:00
print '</td><td valign="top" width="50%">' ;
2006-07-14 15:26:19 +02:00
// Rien a droite
2006-11-11 01:46:15 +01:00
2006-05-06 23:09:26 +02:00
print '</td></tr></table>' ;
2006-11-11 01:46:15 +01:00
2005-04-15 12:34:44 +02:00
}
2006-01-14 14:45:04 +01:00
else
2005-04-15 12:34:44 +02:00
{
2006-01-14 14:45:04 +01:00
print " Expedition inexistante ou acc<63> s refus<75> " ;
2003-11-13 18:36:45 +01:00
}
}
$db -> close ();
2005-07-09 03:16:31 +02:00
llxFooter ( '$Date$ - $Revision$' );
2003-11-13 18:36:45 +01:00
?>