2004-10-19 22:43:23 +02:00
< ? php
2004-02-13 18:13:39 +01:00
/* Copyright ( C ) 2003 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
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
/*! \file htdocs / expedition / fiche . php
\ingroup expedition
\brief Fiche descriptive d ' une expedition
\version $Revision $
*/
2003-11-13 18:36:45 +01:00
require ( " ./pre.inc.php " );
$user -> getrights ( 'commande' );
$user -> getrights ( 'expedition' );
if ( ! $user -> rights -> expedition -> lire )
accessforbidden ();
require ( " ../propal.class.php " );
require ( " ../product/stock/entrepot.class.php " );
/*
* S<EFBFBD> curit<EFBFBD> acc<EFBFBD> s client
*/
if ( $user -> societe_id > 0 )
{
$action = '' ;
$socidp = $user -> societe_id ;
}
/*
*
*/
2004-07-27 11:25:20 +02:00
if ( $_POST [ " action " ] == 'add' )
2003-11-13 18:36:45 +01:00
{
$expedition = new Expedition ( $db );
$expedition -> date_expedition = time ();
2004-07-27 11:25:20 +02:00
$expedition -> note = $_POST [ " note " ];
$expedition -> commande_id = $_POST [ " commande_id " ];
$expedition -> entrepot_id = $_POST [ " entrepot_id " ];
2003-11-13 18:36:45 +01:00
$commande = new Commande ( $db );
$commande -> fetch ( $expedition -> commande_id );
$commande -> fetch_lignes ();
for ( $i = 0 ; $i < sizeof ( $commande -> lignes ) ; $i ++ )
{
$qty = " qtyl " . $i ;
$idl = " idl " . $i ;
2004-07-27 11:25:20 +02:00
if ( $_POST [ $qty ] > 0 )
2003-11-13 18:36:45 +01:00
{
2004-07-27 11:25:20 +02:00
$expedition -> addline ( $_POST [ $idl ], $_POST [ $qty ]);
2003-11-13 18:36:45 +01:00
}
}
$expedition -> create ( $user );
$id = $expedition -> id ;
2004-07-27 11:25:20 +02:00
Header ( " Location:fiche.php?id= $id " );
2003-11-13 18:36:45 +01:00
}
/*
*
*/
2004-07-27 11:25:20 +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 );
}
2004-07-27 11:25:20 +02:00
if ( $_POST [ " action " ] == 'confirm_delete' && $_POST [ " confirm " ] == yes )
2003-11-13 18:36:45 +01:00
{
if ( $user -> rights -> expedition -> supprimer )
{
$expedition = new Expedition ( $db );
$expedition -> id = $_GET [ " id " ];
$expedition -> delete ();
Header ( " Location: liste.php " );
}
}
/*
*
*/
$html = new Form ( $db );
/*********************************************************************
*
* Mode creation
*
*
*
************************************************************************/
2004-07-27 11:25:20 +02:00
if ( $_POST [ " action " ] == 'create' )
2003-11-13 18:36:45 +01:00
{
2004-02-13 18:13:39 +01:00
llxHeader ( '' , 'Fiche expedition' , 'ch-expedition.html' , $form_search );
2003-11-13 18:36:45 +01:00
print_titre ( " Cr<EFBFBD> er une exp<78> dition " );
$commande = new Commande ( $db );
$commande -> livraison_array ();
2004-07-27 11:25:20 +02:00
if ( $commande -> fetch ( $_POST [ " commande_id " ]))
2003-11-13 18:36:45 +01:00
{
$soc = new Societe ( $db );
$soc -> fetch ( $commande -> soc_id );
$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 . '">' ;
2004-07-27 11:25:20 +02:00
print '<input type="hidden" name="entrepot_id" value="' . $_POST [ " entrepot_id " ] . '">' ;
2003-11-13 18:36:45 +01:00
print '<table class="border" cellspacing="0" cellpadding="2" width="100%">' ;
print '<tr><td width="20%">Client</td>' ;
2003-11-19 16:16:32 +01:00
print '<td width="30%"><b><a href="' . DOL_URL_ROOT . '/comm/fiche.php?socid=' . $soc -> id . '">' . $soc -> nom . '</a></b></td>' ;
2003-11-13 18:36:45 +01:00
2003-11-19 16:16:32 +01:00
print '<td width="50%" colspan="2">' ;
2003-11-13 18:36:45 +01:00
print " </td></tr> " ;
print " <tr><td>Date</td> " ;
print " <td> " . strftime ( " %A %d %B %Y " , $commande -> date ) . " </td> \n " ;
print '<td colspan="2" width="50%">Commande : ' . $commande -> ref ;
print " </td></tr> \n " ;
print '<tr><td>Entrep<65> t</td>' ;
print '<td>' ;
$ents = $entrepot -> list_array ();
2004-07-27 11:25:20 +02:00
print $ents [ $_POST [ " entrepot_id " ]];
2003-11-13 18:36:45 +01:00
print '</td>' ;
2004-08-02 04:12:01 +02:00
print " <td> " . $langs -> trans ( " Author " ) . " </td><td> $author->fullname </td> \n " ;
2003-11-13 18:36:45 +01:00
if ( $commande -> note )
{
print '<tr><td colspan="3">Note : ' . nl2br ( $commande -> note ) . " </td></tr> " ;
}
print " </table> " ;
/*
* Lignes de commandes
*
*/
echo '<br><table border="0" width="100%" cellspacing="0" cellpadding="3">' ;
2003-11-27 12:32:08 +01:00
$lignes = $commande -> fetch_lignes ( 1 );
2003-11-13 18:36:45 +01:00
$num = sizeof ( $commande -> lignes );
$i = 0 ; $total = 0 ;
if ( $num )
{
print '<tr class="liste_titre">' ;
2004-08-29 21:03:50 +02:00
print '<td width="54%">' . $langs -> trans ( " Description " ) . '</td>' ;
2003-11-13 18:36:45 +01:00
print '<td align="center">Quan. command<6E> e</td>' ;
print '<td align="center">Quan. livr<76> e</td>' ;
print '<td align="center">Quan. <20> livrer</td>' ;
if ( defined ( " MAIN_MODULE_STOCK " ))
{
print '<td width="12%" align="center">Stock</td>' ;
}
print " </tr> \n " ;
}
$var = True ;
while ( $i < $num )
{
$ligne = $commande -> lignes [ $i ];
print " <tr $bc[$var] > \n " ;
if ( $ligne -> product_id > 0 )
{
$product = new Product ( $db );
$product -> fetch ( $ligne -> product_id );
print '<td>' ;
print '<a href="' . DOL_URL_ROOT . '/product/fiche.php?id=' . $ligne -> product_id . '">' . nl2br ( $ligne -> description ) . '</a></td>' ;
}
else
{
print " <td> " . nl2br ( $ligne -> description ) . " </TD> \n " ;
}
print '<td align="center">' . $ligne -> qty . '</td>' ;
/*
*
*/
print '<td align="center">' ;
$quantite_livree = $commande -> livraisons [ $ligne -> product_id ];
print $quantite_livree ;;
print '</td>' ;
/*
*
*/
print '<td align="center">' ;
print '<input name="idl' . $i . '" type="hidden" value="' . $ligne -> id . '">' ;
$quantite_commandee = $ligne -> qty ;
$quantite_a_livrer = $quantite_commandee - $quantite_livree ;
if ( defined ( " MAIN_MODULE_STOCK " ))
{
2004-07-27 11:25:20 +02:00
$stock = $product -> stock_entrepot [ $_POST [ " entrepot_id " ]];
2003-11-13 18:36:45 +01:00
print '<input name="qtyl' . $i . '" type="text" size="6" value="' . min ( $quantite_a_livrer , $stock ) . '">' ;
print '</td>' ;
if ( $stock < $quantite_a_livrer )
{
print '<td align="center" class="alerte">' . $stock . '</td>' ;
}
else
{
print '<td align="center">' . $stock . '</td>' ;
}
}
else
{
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="3"><input type="submit" value="Cr<43> er"></td></tr>' ;
print " </table> " ;
print '</form>' ;
}
else
{
print $db -> error () . " <br> $sql " ;;
}
}
else
/* *************************************************************************** */
/* */
/* Mode vue et edition */
/* */
/* *************************************************************************** */
{
2004-07-26 18:15:00 +02:00
if ( $_GET [ " id " ] > 0 )
2003-11-13 18:36:45 +01:00
{
$expedition = New Expedition ( $db );
2004-07-26 18:15:00 +02:00
$result = $expedition -> fetch ( $_GET [ " id " ]);
2004-02-13 18:13:39 +01:00
if ( $result > 0 )
2003-11-13 18:36:45 +01:00
{
2004-02-13 18:13:39 +01:00
2003-11-13 18:36:45 +01:00
$author = new User ( $db );
$author -> id = $expedition -> user_author_id ;
$author -> fetch ();
2004-02-13 18:13:39 +01:00
llxHeader ( '' , 'Fiche expedition' , 'ch-expedition.html' , $form_search , $author );
2003-11-13 18:36:45 +01:00
$commande = New Commande ( $db );
$commande -> fetch ( $expedition -> commande_id );
$soc = new Societe ( $db );
$soc -> fetch ( $commande -> soc_id );
print_titre ( " Expedition : " . $expedition -> ref );
/*
* Confirmation de la suppression
*
*/
2004-07-27 11:25:20 +02:00
if ( $_GET [ " action " ] == 'delete' )
2003-11-13 18:36:45 +01:00
{
2004-07-26 18:15:00 +02:00
$html -> form_confirm ( " fiche.php?id= $expedition->id " , " Supprimer l'expedition " , " Etes-vous s<> r de vouloir supprimer cette expedition ? " , " confirm_delete " );
2003-11-13 18:36:45 +01:00
}
/*
* Confirmation de la validation
*
*/
if ( $_GET [ " action " ] == 'valid' )
{
2004-07-26 18:15:00 +02:00
$html -> form_confirm ( " fiche.php?id= $expedition->id " , " Valider l'exp<78> dition " , " Etes-vous s<> r de vouloir valider cette exp<78> dition ? " , " confirm_valid " );
2003-11-13 18:36:45 +01:00
}
/*
* Confirmation de l ' annulation
*
*/
if ( $_GET [ " action " ] == 'annuler' )
{
2004-08-29 18:11:37 +02:00
$html -> form_confirm ( " fiche.php?id= $expedition->id " , $langs -> trans ( " Cancel " ), " Etes-vous s<> r de vouloir annuler cette commande ? " , " confirm_cancel " );
2003-11-13 18:36:45 +01:00
}
/*
* Commande
*/
if ( $commande -> brouillon == 1 && $user -> rights -> commande -> creer )
{
2004-07-26 18:15:00 +02:00
print '<form action="fiche.php?id=' . $expedition -> id . '" method="post">' ;
2003-11-13 18:36:45 +01:00
print '<input type="hidden" name="action" value="setremise">' ;
}
print '<table class="border" cellspacing="0" cellpadding="2" width="100%">' ;
print '<tr><td width="20%">Client</td>' ;
2003-11-19 16:16:32 +01:00
print '<td width="30%">' ;
2003-11-13 18:36:45 +01:00
print '<b><a href="' . DOL_URL_ROOT . '/comm/fiche.php?socid=' . $soc -> id . '">' . $soc -> nom . '</a></b></td>' ;
2004-08-02 04:12:01 +02:00
print '<td width="20%">' . $langs -> trans ( " Author " ) . '</td><td width="30%">' . $author -> fullname . '</td>' ;
2003-11-19 16:16:32 +01:00
2003-11-26 16:30:45 +01:00
print " </tr> " ;
2003-11-13 18:36:45 +01:00
print " <tr><td>Commande</td> " ;
2003-11-19 16:16:32 +01:00
print '<td><a href="' . DOL_URL_ROOT . '/commande/fiche.php?id=' . $commande -> id . '">' . $commande -> ref . " </a></td> \n " ;
2003-11-26 16:30:45 +01:00
print '<td> </td><td> </td></tr>' ;
2003-11-13 18:36:45 +01:00
print " <tr><td>Date</td> " ;
2003-11-19 16:16:32 +01:00
print " <td> " . strftime ( " %A %d %B %Y " , $expedition -> date ) . " </td> \n " ;
2003-11-13 18:36:45 +01:00
2003-11-26 16:30:45 +01:00
$entrepot = new Entrepot ( $db );
$entrepot -> fetch ( $expedition -> entrepot_id );
2004-07-27 11:25:20 +02:00
print '<td width="20%">Entrep<65> t</td><td><a href="' . DOL_URL_ROOT . '/product/stock/fiche.php?id=' . $entrepot -> id . '">' . $entrepot -> libelle . '</a></td></tr>' ;
2003-11-13 18:36:45 +01:00
2003-11-26 16:30:45 +01:00
print " </table> \n " ;
2003-11-13 18:36:45 +01:00
/*
* Lignes
*
*/
echo '<br><table border="0" width="100%" cellspacing="0" cellpadding="3">' ;
$sql = " SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande, ed.qty as qty_livre " ;
2004-02-01 02:19:35 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " commandedet as cd , " . MAIN_DB_PREFIX . " expeditiondet as ed " ;
2004-07-26 18:15:00 +02:00
$sql .= " WHERE ed.fk_expedition = $expedition->id AND cd.rowid = ed.fk_commande_ligne " ;
2003-11-13 18:36:45 +01:00
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ();
$i = 0 ; $total = 0 ;
if ( $num )
{
print '<tr class="liste_titre">' ;
2004-08-29 21:03:50 +02:00
print '<td width="54%">' . $langs -> trans ( " Description " ) . '</td>' ;
2003-11-13 18:36:45 +01:00
print '<td align="center">Quan. command<6E> e</td>' ;
print '<td align="center">Quan. livr<76> e</td>' ;
print " </tr> \n " ;
}
$var = True ;
while ( $i < $num )
{
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ( $result );
2003-11-13 18:36:45 +01:00
print " <TR $bc[$var] > " ;
if ( $objp -> fk_product > 0 )
{
print '<td>' ;
print '<a href="' . DOL_URL_ROOT . '/product/fiche.php?id=' . $objp -> fk_product . '">' . stripslashes ( nl2br ( $objp -> description )) . '</a></td>' ;
}
else
{
print " <td> " . stripslashes ( nl2br ( $objp -> description )) . " </TD> \n " ;
}
print '<td align="center">' . $objp -> qty_commande . '</td>' ;
print '<td align="center">' . $objp -> qty_livre . '</td>' ;
print " </tr> " ;
$i ++ ;
$var =! $var ;
}
$db -> free ();
}
else
{
print " $sql " ;
print $db -> error ();
}
print " </table> " ;
/*
*
*/
if ( $user -> societe_id == 0 )
{
2004-07-27 11:25:20 +02:00
print '<p><div class="tabsAction">' ;
2003-11-13 18:36:45 +01:00
if ( $expedition -> brouillon && $user -> rights -> expedition -> supprimer )
{
2004-07-27 11:25:20 +02:00
print '<a class="tabAction" href="fiche.php?id=' . $expedition -> id . '&action=delete">Supprimer</a>' ;
2003-11-13 18:36:45 +01:00
}
if ( $expedition -> statut == 0 )
{
if ( $user -> rights -> expedition -> valider )
{
2004-07-27 11:25:20 +02:00
print '<a class="tabAction" href="fiche.php?id=' . $expedition -> id . '&action=valid">Valider</a>' ;
2003-11-13 18:36:45 +01:00
}
2004-07-27 11:25:20 +02:00
2003-11-13 18:36:45 +01:00
}
2004-07-27 11:52:15 +02:00
print " </div> " ;
2003-11-13 18:36:45 +01:00
}
print " <p> \n " ;
/*
* D<EFBFBD> j<EFBFBD> livr<EFBFBD>
*
*
*/
$sql = " SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande, ed.qty as qty_livre, e.ref " ;
2004-02-01 02:19:35 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " commandedet as cd , " . MAIN_DB_PREFIX . " expeditiondet as ed, " . MAIN_DB_PREFIX . " expedition as e " ;
2003-11-13 18:36:45 +01:00
$sql .= " WHERE cd.fk_commande = $expedition->commande_id AND e.rowid <> $expedition->id AND cd.rowid = ed.fk_commande_ligne AND ed.fk_expedition = e.rowid " ;
$sql .= " ORDER BY cd.fk_product " ;
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ();
$i = 0 ; $total = 0 ;
if ( $num )
{
print '<br><table class="liste" cellpadding="3" width="100%"><tr>' ;
print '<tr class="liste_titre">' ;
2004-08-29 21:03:50 +02:00
print '<td width="54%">' . $langs -> trans ( " Description " ) . '</td>' ;
2003-11-13 18:36:45 +01:00
print '<td align="center">Quan. livr<76> e</td>' ;
print '<td align="center">Exp<78> dition</td>' ;
print " </tr> \n " ;
$var = True ;
while ( $i < $num )
{
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ( $result );
2003-11-13 18:36:45 +01:00
print " <TR $bc[$var] > " ;
if ( $objp -> fk_product > 0 )
{
print '<td>' ;
print '<a href="' . DOL_URL_ROOT . '/product/fiche.php?id=' . $objp -> fk_product . '">' . stripslashes ( nl2br ( $objp -> description )) . '</a></td>' ;
}
else
{
print " <td> " . stripslashes ( nl2br ( $objp -> description )) . " </TD> \n " ;
}
print '<td align="center">' . $objp -> qty_livre . '</td>' ;
print '<td align="center">' . $objp -> ref . '</td>' ;
$i ++ ;
}
print '</table>' ;
}
}
/*
* Documents g<EFBFBD> n<EFBFBD> r<EFBFBD> s
*
*/
2004-12-31 19:12:29 +01:00
$file = $conf -> commande -> dir_output . " / " . $commande -> ref . " / " . $commande -> ref . " .pdf " ;
$relativepath = $commande -> ref . " / " . $commande -> ref . " .pdf " ;
$var = true ;
2003-11-13 18:36:45 +01:00
if ( file_exists ( $file ))
{
print " <table width= \" 100% \" cellspacing=2><tr><td width= \" 50% \" valign= \" top \" > " ;
print_titre ( " Documents " );
2004-12-31 19:12:29 +01:00
print '<table width="100%" class="border">' ;
2003-11-13 18:36:45 +01:00
2004-12-31 19:12:29 +01:00
print " <tr $bc[$true] ><td> " . $langs -> trans ( " Order " ) . " PDF</td> " ;
print '<td><a href="' . DOL_URL_ROOT . '/document.php?modulepart=commande&file=' . urlencode ( $relativepath ) . '">' . $commande -> ref . '.pdf</a></td>' ;
2003-11-13 18:36:45 +01:00
print '<td align="right">' . filesize ( $file ) . ' bytes</td>' ;
print '<td align="right">' . strftime ( " %d %b %Y %H:%M:%S " , filemtime ( $file )) . '</td>' ;
print '</tr>' ;
print " </table> \n " ;
print '</td><td valign="top" width="50%">' ;
print_titre ( " Actions " );
/*
* Liste des actions
*
*/
$sql = " SELECT " . $db -> pdate ( " a.datea " ) . " as da, a.note " ;
2004-07-26 18:15:00 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " actioncomm as a WHERE a.fk_soc = $commande->socidp AND a.fk_action in (9,10) AND a.fk_commande = $expedition->id " ;
2003-11-13 18:36:45 +01:00
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ();
if ( $num )
{
$i = 0 ; $total = 0 ;
2004-12-31 19:12:29 +01:00
print '<table class="border" width="100%">' ;
print " <tr $bc[$var] ><td> " . $langs -> trans ( " Date " ) . " </td><td> " . $langs -> trans ( " Action " ) . " </td></tr> \n " ;
2003-11-13 18:36:45 +01:00
$var = True ;
while ( $i < $num )
{
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ( $result );
2003-11-13 18:36:45 +01:00
$var =! $var ;
print " <tr $bc[$var] > " ;
2004-12-31 19:12:29 +01:00
print " <td> " . strftime ( " %d %B %Y " , $objp -> da ) . " </td> \n " ;
print '<td>' . stripslashes ( $objp -> note ) . '</td>' ;
2003-11-13 18:36:45 +01:00
print " </tr> " ;
$i ++ ;
}
print " </table> " ;
}
}
else
{
2004-12-31 19:12:29 +01:00
dolibarr_print_error ( $db );
2003-11-13 18:36:45 +01:00
}
/*
*
*
*/
print " </td></tr></table> " ;
}
/*
*
*
*/
2003-11-19 16:16:32 +01:00
2003-11-13 18:36:45 +01:00
if ( $action == 'presend' )
{
$replytoname = $user -> fullname ;
$from_name = $replytoname ;
$replytomail = $user -> email ;
$from_mail = $replytomail ;
2004-07-26 18:15:00 +02:00
print " <form method= \" post \" action= \" fiche.php?id= $expedition->id &action=send \" > \n " ;
2003-11-13 18:36:45 +01:00
print '<input type="hidden" name="replytoname" value="' . $replytoname . '">' ;
print '<input type="hidden" name="replytomail" value="' . $replytomail . '">' ;
print " <p><b>Envoyer la commande par mail</b> " ;
print " <table cellspacing=0 border=1 cellpadding=3> " ;
print '<tr><td>Destinataire</td><td colspan="5">' ;
$form = new Form ( $db );
$form -> select_array ( " destinataire " , $soc -> contact_email_array ());
print " </td><td><input size= \" 30 \" name= \" sendto \" value= \" $commande->email\ " ></ td ></ tr > " ;
print " <tr><td>Exp<78> diteur</td><td colspan= \" 5 \" > $from_name </td><td> $from_mail </td></tr> " ;
print " <tr><td>Reply-to</td><td colspan= \" 5 \" > $replytoname </td> " ;
print " <td> $replytomail </td></tr></table> " ;
print " <input type= \" submit \" value= \" Envoyer \" ></form> " ;
}
}
else
{
/* Commande non trouv<75> e */
print " Commande inexistante ou acc<63> s refus<75> " ;
}
}
}
$db -> close ();
llxFooter ( " <em>Dernière modification $Date $ révision $Revision $ </em> " );
?>