2006-05-29 15:53:20 +02:00
< ? php
2012-08-25 15:21:34 +02:00
/* Copyright ( C ) 2003 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2005 - 2010 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2005 Simon TOSSER < simon @ kornog - computing . com >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2012-08-25 15:21:34 +02:00
* Copyright ( C ) 2007 Franky Van Liedekerke < franky . van . liedekerke @ telenet . be >
2013-04-09 17:18:07 +02:00
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
2006-05-29 15:53:20 +02: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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2006-05-29 15:53:20 +02: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:24:38 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2006-05-29 15:53:20 +02:00
*/
/**
2008-10-17 16:43:33 +02:00
* \file htdocs / livraison / fiche . php
* \ingroup livraison
2009-07-15 22:10:28 +02:00
* \brief Fiche descriptive d ' un bon de livraison = reception
2008-08-05 10:41:54 +02:00
*/
2006-05-29 15:53:20 +02:00
2012-08-22 23:24:21 +02:00
require '../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/livraison/class/livraison.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/modules/livraison/modules_livraison.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/sendings.lib.php' ;
2012-08-25 15:21:34 +02:00
if ( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled ))
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
if ( ! empty ( $conf -> expedition_bon -> enabled ))
require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php' ;
if ( ! empty ( $conf -> stock -> enabled ))
require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php' ;
2006-05-29 15:53:20 +02:00
2009-04-27 22:37:50 +02:00
2006-06-24 19:10:32 +02:00
$langs -> load ( " sendings " );
2006-05-29 15:53:20 +02:00
$langs -> load ( " bills " );
2006-06-01 12:30:47 +02:00
$langs -> load ( 'deliveries' );
2013-08-07 15:08:30 +02:00
$langs -> load ( 'orders' );
2006-05-29 15:53:20 +02:00
2012-08-05 20:34:51 +02:00
$action = GETPOST ( 'action' , 'alpha' );
2012-08-25 15:21:34 +02:00
$confirm = GETPOST ( 'confirm' , 'alpha' );
2014-05-06 13:15:37 +02:00
$backtourl = GETPOST ( 'backtourl' );
2012-08-05 20:34:51 +02:00
2008-10-17 16:43:33 +02:00
// Security check
2012-08-25 15:21:34 +02:00
$id = GETPOST ( 'id' , 'int' );
2009-04-27 22:37:50 +02:00
if ( $user -> societe_id ) $socid = $user -> societe_id ;
2009-04-30 13:29:32 +02:00
$result = restrictedArea ( $user , 'expedition' , $id , 'livraison' , 'livraison' );
2006-05-29 15:53:20 +02:00
2010-07-23 02:17:46 +02:00
2006-05-29 15:53:20 +02:00
/*
* Actions
*/
2012-08-25 15:21:34 +02:00
if ( $action == 'add' )
2006-05-29 15:53:20 +02:00
{
2008-08-05 10:41:54 +02:00
$db -> begin ();
// Creation de l'objet livraison
2010-02-27 14:37:13 +01:00
$delivery = new Livraison ( $db );
2008-08-05 10:41:54 +02:00
2010-02-27 14:37:13 +01:00
$delivery -> date_livraison = time ();
$delivery -> note = $_POST [ " note " ];
$delivery -> commande_id = $_POST [ " commande_id " ];
2008-08-05 10:41:54 +02:00
2012-09-15 11:21:22 +02:00
if ( ! $conf -> expedition_bon -> enabled && ! empty ( $conf -> stock -> enabled ))
2008-08-05 10:41:54 +02:00
{
$expedition -> entrepot_id = $_POST [ " entrepot_id " ];
}
2009-04-30 13:29:32 +02:00
// On boucle sur chaque ligne de commande pour completer objet livraison
// avec qte a livrer
2008-08-05 10:41:54 +02:00
$commande = new Commande ( $db );
2010-02-27 14:37:13 +01:00
$commande -> fetch ( $delivery -> commande_id );
2008-08-05 10:41:54 +02:00
$commande -> fetch_lines ();
2011-09-17 21:49:50 +02:00
$num = count ( $commande -> lines );
for ( $i = 0 ; $i < $num ; $i ++ )
2008-08-05 10:41:54 +02:00
{
$qty = " qtyl " . $i ;
$idl = " idl " . $i ;
if ( $_POST [ $qty ] > 0 )
{
2010-02-27 14:37:13 +01:00
$delivery -> addline ( $_POST [ $idl ], $_POST [ $qty ]);
2008-08-05 10:41:54 +02:00
}
}
2010-02-27 14:37:13 +01:00
$ret = $delivery -> create ( $user );
2008-08-05 10:41:54 +02:00
if ( $ret > 0 )
{
$db -> commit ();
2012-08-31 05:58:38 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $delivery -> id );
2008-08-05 10:41:54 +02:00
exit ;
}
else
{
2012-08-25 15:21:34 +02:00
setEventMessage ( $delivery -> error , 'errors' );
2008-08-05 10:41:54 +02:00
$db -> rollback ();
2012-08-25 15:21:34 +02:00
2008-08-05 10:41:54 +02:00
$_GET [ " commande_id " ] = $_POST [ " commande_id " ];
2012-08-25 15:21:34 +02:00
$action = 'create' ;
2008-08-05 10:41:54 +02:00
}
2006-05-29 15:53:20 +02:00
}
2012-08-25 15:21:34 +02:00
else if ( $action == 'confirm_valid' && $confirm == 'yes' && $user -> rights -> expedition -> livraison -> valider )
2006-05-29 15:53:20 +02:00
{
2011-12-02 19:57:20 +01:00
$object = new Livraison ( $db );
2012-08-25 15:21:34 +02:00
$object -> fetch ( $id );
2011-12-02 19:57:20 +01:00
$object -> fetch_thirdparty ();
2010-02-27 14:37:13 +01:00
2011-12-02 19:57:20 +01:00
$result = $object -> valid ( $user );
2010-02-27 14:37:13 +01:00
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && ! empty ( $_REQUEST [ 'lang_id' ])) $newlang = $_REQUEST [ 'lang_id' ];
2011-12-02 19:57:20 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
2010-02-27 14:37:13 +01:00
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
2011-12-02 19:57:20 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$ret = $object -> fetch ( $id ); // Reload to get new records
$result = delivery_order_pdf_create ( $db , $object , $_REQUEST [ 'model' ], $outputlangs );
}
2011-10-14 16:44:22 +02:00
if ( $result < 0 )
{
dol_print_error ( $db , $result );
exit ;
2010-02-27 14:37:13 +01:00
}
2006-05-29 15:53:20 +02:00
}
2012-08-25 15:21:34 +02:00
if ( $action == 'confirm_delete' && $confirm == 'yes' && $user -> rights -> expedition -> livraison -> supprimer )
2006-05-29 15:53:20 +02:00
{
2011-12-02 19:57:20 +01:00
$object = new Livraison ( $db );
2012-08-25 15:21:34 +02:00
$object -> fetch ( $id );
2012-08-05 20:34:51 +02:00
$object -> fetch_thirdparty ();
2009-07-15 22:10:28 +02:00
$db -> begin ();
2011-12-02 19:57:20 +01:00
$result = $object -> delete ();
2009-07-15 22:10:28 +02:00
if ( $result > 0 )
2008-08-05 10:41:54 +02:00
{
2009-07-15 22:10:28 +02:00
$db -> commit ();
2014-05-06 13:15:37 +02:00
if ( ! empty ( $backtourl )) header ( " Location: " . $backtourl );
else header ( " Location: " . DOL_URL_ROOT . '/expedition/index.php' );
2010-08-29 00:54:23 +02:00
exit ;
2008-08-05 10:41:54 +02:00
}
2009-07-15 22:10:28 +02:00
else
{
$db -> rollback ();
}
2006-05-29 15:53:20 +02:00
}
2013-08-07 15:08:30 +02:00
if ( $action == 'setdate_livraison' && $user -> rights -> expedition -> livraison -> creer )
{
$object = new Livraison ( $db );
$object -> fetch ( $id );
$object -> fetch_thirdparty ();
//print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
$datedelivery = dol_mktime ( GETPOST ( 'liv_hour' , 'int' ), GETPOST ( 'liv_min' , 'int' ), 0 , GETPOST ( 'liv_month' , 'int' ), GETPOST ( 'liv_day' , 'int' ), GETPOST ( 'liv_year' , 'int' ));
$object -> fetch ( $id );
$result = $object -> set_date_livraison ( $user , $datedelivery );
if ( $result < 0 )
{
$mesg = '<div class="error">' . $object -> error . '</div>' ;
}
}
2006-05-29 15:53:20 +02:00
/*
2008-08-05 10:41:54 +02:00
* Build document
2006-05-29 15:53:20 +02:00
*/
2012-08-25 15:21:34 +02:00
if ( $action == 'builddoc' ) // En get ou en post
2006-05-29 15:53:20 +02:00
{
2011-12-02 19:57:20 +01:00
$object = new Livraison ( $db );
2012-08-25 15:21:34 +02:00
$object -> fetch ( $id );
2012-08-05 20:34:51 +02:00
$object -> fetch_thirdparty ();
2014-05-06 13:43:41 +02:00
2013-09-06 13:25:45 +02:00
// Save last template used to generate document
if ( GETPOST ( 'model' )) $object -> setDocModel ( $user , GETPOST ( 'model' , 'alpha' ));
2007-01-05 14:20:46 +01:00
2010-02-27 14:37:13 +01:00
// Define output language
2008-10-29 00:36:36 +01:00
$outputlangs = $langs ;
2010-02-27 14:37:13 +01:00
$newlang = '' ;
2013-09-06 13:25:45 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' )) $newlang = GETPOST ( 'lang_id' );
2011-12-02 19:57:20 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
2010-02-27 14:37:13 +01:00
if ( ! empty ( $newlang ))
2006-06-18 17:48:28 +02:00
{
2008-03-31 17:17:39 +02:00
$outputlangs = new Translate ( " " , $conf );
2010-02-27 14:37:13 +01:00
$outputlangs -> setDefaultLang ( $newlang );
2006-06-18 17:48:28 +02:00
}
2011-12-02 19:57:20 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$ret = $object -> fetch ( $id ); // Reload to get new records
$result = delivery_order_pdf_create ( $db , $object , $object -> modelpdf , $outputlangs );
}
if ( $result < 0 )
2008-08-05 10:41:54 +02:00
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db , $result );
2008-08-05 10:41:54 +02:00
exit ;
}
2006-05-29 15:53:20 +02:00
}
2012-08-22 23:11:24 +02:00
// Delete file in doc form
elseif ( $action == 'remove_file' )
{
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
$object = new Livraison ( $db );
if ( $object -> fetch ( $id ))
{
$object -> fetch_thirdparty ();
$upload_dir = $conf -> expedition -> dir_output . " /receipt " ;
$file = $upload_dir . '/' . GETPOST ( 'file' );
$ret = dol_delete_file ( $file , 0 , 0 , 0 , $object );
if ( $ret ) setEventMessage ( $langs -> trans ( " FileWasRemoved " , GETPOST ( 'urlfile' )));
else setEventMessage ( $langs -> trans ( " ErrorFailToDeleteFile " , GETPOST ( 'urlfile' )), 'errors' );
}
2012-08-05 20:34:51 +02:00
}
2006-05-29 15:53:20 +02:00
/*
2008-08-05 10:41:54 +02:00
* View
2006-05-29 15:53:20 +02:00
*/
2007-11-16 23:01:14 +01:00
llxHeader ( '' , $langs -> trans ( 'Delivery' ), 'Livraison' );
2011-11-08 10:18:45 +01:00
$form = new Form ( $db );
2008-01-20 14:53:02 +01:00
$formfile = new FormFile ( $db );
2006-05-29 15:53:20 +02:00
/*********************************************************************
*
* Mode creation
*
*********************************************************************/
2012-08-25 15:21:34 +02:00
if ( $action == 'create' )
2006-05-29 15:53:20 +02:00
{
2008-08-05 10:41:54 +02:00
2009-03-02 20:07:12 +01:00
print_fiche_titre ( $langs -> trans ( " CreateADeliveryOrder " ));
2008-08-05 10:41:54 +02:00
if ( $mesg )
2006-05-29 15:53:20 +02:00
{
2008-08-05 10:41:54 +02:00
print $mesg . '<br>' ;
2006-05-29 15:53:20 +02:00
}
2008-08-05 10:41:54 +02:00
$commande = new Commande ( $db );
$commande -> livraison_array ();
2012-08-25 15:21:34 +02:00
if ( $commande -> fetch ( $_GET [ " commande_id " ]))
2006-05-29 15:53:20 +02:00
{
2008-08-05 10:41:54 +02:00
$soc = new Societe ( $db );
$soc -> fetch ( $commande -> socid );
$author = new User ( $db );
2010-05-05 19:36:20 +02:00
$author -> fetch ( $commande -> user_author_id );
2008-08-05 10:41:54 +02:00
2012-09-15 11:21:22 +02:00
if ( ! $conf -> expedition_bon -> enabled && ! empty ( $conf -> stock -> enabled ))
2008-08-05 10:41:54 +02:00
{
$entrepot = new Entrepot ( $db );
}
/*
* Commande
*/
print '<form action="fiche.php" method="post">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2008-08-05 10:41:54 +02:00
print '<input type="hidden" name="action" value="add">' ;
print '<input type="hidden" name="commande_id" value="' . $commande -> id . '">' ;
2012-09-15 11:21:22 +02:00
if ( ! $conf -> expedition_bon -> enabled && ! empty ( $conf -> stock -> enabled ))
2008-08-05 10:41:54 +02:00
{
print '<input type="hidden" name="entrepot_id" value="' . $_GET [ " entrepot_id " ] . '">' ;
}
print '<table class="border" width="100%">' ;
print '<tr><td width="20%">' . $langs -> trans ( " Customer " ) . '</td>' ;
print '<td width="30%"><b><a href="' . DOL_URL_ROOT . '/comm/fiche.php?socid=' . $soc -> id . '">' . $soc -> nom . '</a></b></td>' ;
print '<td width="50%" colspan="2">' ;
print " </td></tr> " ;
print " <tr><td> " . $langs -> trans ( " Date " ) . " </td> " ;
2009-02-20 23:53:15 +01:00
print " <td> " . dol_print_date ( $commande -> date , 'dayhourtext' ) . " </td> \n " ;
2008-08-05 10:41:54 +02:00
print '<td>' . $langs -> trans ( " Order " ) . '</td><td><a href="' . DOL_URL_ROOT . '/commande/fiche.php?id=' . $commande -> id . '">' . img_object ( $langs -> trans ( " ShowOrder " ), 'order' ) . ' ' . $commande -> ref . '</a>' ;
print " </td></tr> \n " ;
print '<tr>' ;
2012-09-15 11:21:22 +02:00
if ( ! $conf -> expedition_bon -> enabled && ! empty ( $conf -> stock -> enabled ))
2008-08-05 10:41:54 +02:00
{
print '<td>' . $langs -> trans ( " Warehouse " ) . '</td>' ;
print '<td>' ;
$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>' ;
}
2010-07-18 12:39:07 +02:00
print " <td> " . $langs -> trans ( " Author " ) . " </td><td> " . $author -> getFullName ( $langs ) . " </td> \n " ;
2008-08-05 10:41:54 +02:00
if ( $commande -> note )
{
2008-10-17 16:43:33 +02:00
print '<tr><td colspan="3">Note : ' . nl2br ( $commande -> note ) . " </td></tr> " ;
2008-08-05 10:41:54 +02:00
}
print " </table> " ;
/*
* Lignes de commandes
*/
2010-03-13 17:23:43 +01:00
print '<br><table class="noborder" width="100%">' ;
2008-08-05 10:41:54 +02:00
2010-12-15 08:49:05 +01:00
$lines = $commande -> fetch_lines ( 1 );
2008-08-05 10:41:54 +02:00
2010-03-13 17:23:43 +01:00
// Lecture des livraisons deja effectuees
2008-08-05 10:41:54 +02:00
$commande -> livraison_array ();
2011-09-17 21:49:50 +02:00
$num = count ( $commande -> lines );
2008-08-05 10:41:54 +02:00
$i = 0 ;
if ( $num )
{
2008-10-17 16:43:33 +02:00
print '<tr class="liste_titre">' ;
print '<td width="54%">' . $langs -> trans ( " Description " ) . '</td>' ;
2012-11-03 21:14:23 +01:00
print '<td align="center">' . $langs -> trans ( " QtyOrdered " ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " QtyReceived " ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " QtyToShip " ) . '</td>' ;
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> stock -> enabled ))
2008-10-17 16:43:33 +02:00
{
print '<td width="12%" align="center">' . $langs -> trans ( " Stock " ) . '</td>' ;
}
print " </tr> \n " ;
2008-08-05 10:41:54 +02:00
}
$var = true ;
while ( $i < $num )
{
2010-06-17 22:24:11 +02:00
$product = new Product ( $db );
2010-12-15 08:49:05 +01:00
$line = $commande -> lines [ $i ];
2008-10-17 16:43:33 +02:00
$var =! $var ;
2013-06-20 09:18:12 +02:00
print " <tr " . $bc [ $var ] . " > \n " ;
2010-12-15 08:49:05 +01:00
if ( $line -> fk_product > 0 )
2008-10-17 16:43:33 +02:00
{
2010-12-15 08:49:05 +01:00
$product -> fetch ( $line -> fk_product );
2010-06-17 22:24:11 +02:00
$product -> load_stock ();
2008-10-17 16:43:33 +02:00
2012-08-25 15:21:34 +02:00
// Define output language
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && ! empty ( $conf -> global -> PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE ))
{
$commande -> fetch_thirdparty ();
$outputlangs = $langs ;
$newlang = '' ;
if ( empty ( $newlang ) && ! empty ( $_REQUEST [ 'lang_id' ])) $newlang = $_REQUEST [ 'lang_id' ];
if ( empty ( $newlang )) $newlang = $commande -> client -> default_lang ;
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$label = ( ! empty ( $product -> multilangs [ $outputlangs -> defaultlang ][ " label " ])) ? $product -> multilangs [ $outputlangs -> defaultlang ][ " label " ] : $product -> label ;
}
else
$label = ( ! empty ( $line -> label ) ? $line -> label : $product -> label );
2012-01-17 12:03:05 +01:00
2008-10-17 16:43:33 +02:00
print '<td>' ;
2012-01-17 12:03:05 +01:00
print '<a href="' . DOL_URL_ROOT . '/product/fiche.php?id=' . $line -> fk_product . '">' . img_object ( $langs -> trans ( " ShowProduct " ), " product " ) . ' ' . $product -> ref . '</a> - ' . $label ;
2010-12-15 08:49:05 +01:00
if ( $line -> description ) print nl2br ( $line -> description );
2008-10-17 16:43:33 +02:00
print '</td>' ;
}
else
{
2012-08-25 15:21:34 +02:00
print " <td> " ;
if ( $line -> fk_product_type == 1 ) $text = img_object ( $langs -> trans ( 'Service' ), 'service' );
else $text = img_object ( $langs -> trans ( 'Product' ), 'product' );
if ( ! empty ( $line -> label )) {
$text .= ' <strong>' . $line -> label . '</strong>' ;
print $form -> textwithtooltip ( $text , $line -> description , 3 , '' , '' , $i );
} else {
print $text . ' ' . nl2br ( $line -> description );
}
print_date_range ( $lines [ $i ] -> date_start , $lines [ $i ] -> date_end );
print " </td> \n " ;
2008-10-17 16:43:33 +02:00
}
2010-12-15 08:49:05 +01:00
print '<td align="center">' . $line -> qty . '</td>' ;
2008-10-17 16:43:33 +02:00
/*
*
*/
print '<td align="center">' ;
2010-12-15 08:49:05 +01:00
$quantite_livree = $commande -> livraisons [ $line -> id ];
2008-10-17 16:43:33 +02:00
print $quantite_livree ;;
print '</td>' ;
2010-12-15 08:49:05 +01:00
$quantite_commandee = $line -> qty ;
2008-10-17 16:43:33 +02:00
$quantite_a_livrer = $quantite_commandee - $quantite_livree ;
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> stock -> enabled ))
2008-10-17 16:43:33 +02:00
{
2010-07-14 17:41:39 +02:00
$stock = $product -> stock_warehouse [ $_GET [ " entrepot_id " ]] -> real ;
2009-04-30 14:52:04 +02:00
$stock += 0 ; // Convertit en numerique
2008-10-17 16:43:33 +02:00
2009-04-30 14:52:04 +02:00
// Quantite a livrer
2008-10-17 16:43:33 +02:00
print '<td align="center">' ;
2010-12-15 08:49:05 +01:00
print '<input name="idl' . $i . '" type="hidden" value="' . $line -> id . '">' ;
2008-10-17 16:43:33 +02:00
print '<input name="qtyl' . $i . '" type="text" size="6" value="' . min ( $quantite_a_livrer , $stock ) . '">' ;
print '</td>' ;
// Stock
if ( $stock < $quantite_a_livrer )
{
2008-11-16 02:09:04 +01:00
print '<td align="center">' . $stock . ' ' . img_warning () . '</td>' ;
2008-10-17 16:43:33 +02:00
}
else
{
print '<td align="center">' . $stock . '</td>' ;
}
}
else
{
2008-11-16 02:09:04 +01:00
// Quantite a livrer
2008-10-17 16:43:33 +02:00
print '<td align="center">' ;
2010-12-15 08:49:05 +01:00
print '<input name="idl' . $i . '" type="hidden" value="' . $line -> id . '">' ;
2008-10-17 16:43:33 +02:00
print '<input name="qtyl' . $i . '" type="text" size="6" value="' . $quantite_a_livrer . '">' ;
print '</td>' ;
}
print " </tr> \n " ;
$i ++ ;
$var =! $var ;
2008-08-05 10:41:54 +02:00
}
/*
*
*/
print '<tr><td align="center" colspan="4"><br><input type="submit" class="button" value="' . $langs -> trans ( " Create " ) . '"></td></tr>' ;
print " </table> " ;
print '</form>' ;
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2008-08-05 10:41:54 +02:00
}
}
else
2006-05-29 15:53:20 +02:00
/* *************************************************************************** */
/* */
/* Mode vue et edition */
/* */
/* *************************************************************************** */
2008-01-31 15:23:57 +01:00
{
2012-08-25 15:21:34 +02:00
if ( $id > 0 )
2008-08-05 10:41:54 +02:00
{
2010-02-27 14:37:13 +01:00
$delivery = new Livraison ( $db );
2012-08-25 15:21:34 +02:00
$result = $delivery -> fetch ( $id );
2010-08-06 15:56:25 +02:00
$delivery -> fetch_thirdparty ();
2013-08-07 15:08:30 +02:00
2014-05-06 13:15:37 +02:00
// Origin of a 'livraison' (delivery) is ALWAYS 'expedition' (shipment).
// However, origin of shipment in future may differs (commande, proposal, ...)
2008-10-17 16:43:33 +02:00
$expedition = new Expedition ( $db );
2010-12-21 00:58:34 +01:00
$result = $expedition -> fetch ( $delivery -> origin_id );
2014-05-06 13:15:37 +02:00
$typeobject = $expedition -> origin ; // example: commande
if ( $delivery -> origin_id > 0 )
2008-08-05 10:41:54 +02:00
{
2010-09-09 16:06:15 +02:00
$delivery -> fetch_origin ();
2008-08-05 10:41:54 +02:00
}
2012-08-25 15:21:34 +02:00
if ( $delivery -> id > 0 )
2008-08-05 10:41:54 +02:00
{
$soc = new Societe ( $db );
2010-02-27 14:37:13 +01:00
$soc -> fetch ( $delivery -> socid );
2008-10-17 16:43:33 +02:00
2010-03-13 16:52:30 +01:00
$head = delivery_prepare_head ( $delivery );
2013-09-25 19:07:25 +02:00
dol_fiche_head ( $head , 'delivery' , $langs -> trans ( " Shipment " ), 0 , 'sending' );
2008-08-05 10:41:54 +02:00
/*
* Confirmation de la suppression
*
*/
2012-08-25 15:21:34 +02:00
if ( $action == 'delete' )
2008-08-05 10:41:54 +02:00
{
2014-05-06 13:15:37 +02:00
$expedition_id = GETPOST ( " expid " );
print $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $delivery -> id . '&expid=' . $expedition_id . '&backtourl=' . urlencode ( $backtourl ), $langs -> trans ( " DeleteDeliveryReceipt " ), $langs -> trans ( " DeleteDeliveryReceiptConfirm " , $delivery -> ref ), 'confirm_delete' , '' , '' , 1 );
2013-09-25 19:07:25 +02:00
2008-08-05 10:41:54 +02:00
}
/*
* Confirmation de la validation
*/
2012-08-25 15:21:34 +02:00
if ( $action == 'valid' )
2008-08-05 10:41:54 +02:00
{
2013-09-06 12:10:09 +02:00
print $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $delivery -> id , $langs -> trans ( " ValidateDeliveryReceipt " ), $langs -> trans ( " ValidateDeliveryReceiptConfirm " , $delivery -> ref ), 'confirm_valid' , '' , '' , 1 );
2013-09-25 19:07:25 +02:00
2008-08-05 10:41:54 +02:00
}
/*
* Livraison
*/
print '<table class="border" width="100%">' ;
2014-05-06 13:15:37 +02:00
// Shipment
if (( $delivery -> origin == 'shipment' || $delivery -> origin == 'expedition' ) && $delivery -> origin_id > 0 )
{
2014-05-07 10:42:13 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/expedition/liste.php">' . $langs -> trans ( " BackToList " ) . '</a>' ;
// Ref
print '<tr><td width="20%">' . $langs -> trans ( " RefSending " ) . '</td>' ;
print '<td colspan="3">' ;
2014-05-06 13:15:37 +02:00
// Nav is hidden because on a delivery receipt of a shipment, if we go on next shipment, we may find no tab (a shipment may not have delivery receipt yet)
2014-05-07 10:42:13 +02:00
//print $form->showrefnav($expedition, 'refshipment', $linkback, 1, 'ref', 'ref');
2014-05-06 13:15:37 +02:00
print $form -> showrefnav ( $expedition , 'refshipment' , $linkback , 0 , 'ref' , 'ref' );
2014-05-07 10:42:13 +02:00
print '</td></tr>' ;
}
2014-05-06 13:15:37 +02:00
2008-08-05 10:41:54 +02:00
// Ref
print '<tr><td width="20%">' . $langs -> trans ( " Ref " ) . '</td>' ;
2010-02-27 14:37:13 +01:00
print '<td colspan="3">' . $delivery -> ref . '</td></tr>' ;
2008-08-05 10:41:54 +02:00
// Client
print '<tr><td width="20%">' . $langs -> trans ( " Customer " ) . '</td>' ;
print '<td align="3">' . $soc -> getNomUrl ( 1 ) . '</td>' ;
print " </tr> " ;
// Document origine
2012-09-15 11:21:22 +02:00
if ( $typeobject == 'commande' && $expedition -> origin_id && ! empty ( $conf -> commande -> enabled ))
2008-08-05 10:41:54 +02:00
{
print '<tr><td>' . $langs -> trans ( " RefOrder " ) . '</td>' ;
$order = new Commande ( $db );
2008-10-17 16:43:33 +02:00
$order -> fetch ( $expedition -> origin_id );
2008-08-05 10:41:54 +02:00
print '<td colspan="3">' ;
2008-10-25 17:33:21 +02:00
print $order -> getNomUrl ( 1 , 'commande' );
2008-08-05 10:41:54 +02:00
print " </td> \n " ;
print '</tr>' ;
}
2012-09-15 11:21:22 +02:00
if ( $typeobject == 'propal' && $expedition -> origin_id && ! empty ( $conf -> propal -> enabled ))
2008-08-05 10:41:54 +02:00
{
$propal = new Propal ( $db );
2009-07-30 09:24:18 +02:00
$propal -> fetch ( $expedition -> origin_id );
2008-08-05 10:41:54 +02:00
print '<tr><td>' . $langs -> trans ( " RefProposal " ) . '</td>' ;
print '<td colspan="3">' ;
print $propal -> getNomUrl ( 1 , 'expedition' );
print " </td> \n " ;
print '</tr>' ;
}
// Ref client
print '<tr><td>' . $langs -> trans ( " RefCustomer " ) . '</td>' ;
2010-03-13 16:52:30 +01:00
print '<td colspan="3">' . $delivery -> ref_customer . " </a></td> \n " ;
2008-08-05 10:41:54 +02:00
print '</tr>' ;
// Date
2010-05-13 01:03:33 +02:00
print '<tr><td>' . $langs -> trans ( " DateCreation " ) . '</td>' ;
2010-03-13 17:23:43 +01:00
print '<td colspan="3">' . dol_print_date ( $delivery -> date_creation , 'daytext' ) . " </td> \n " ;
print '</tr>' ;
2010-03-27 01:33:28 +01:00
2010-05-13 01:03:33 +02:00
// Date delivery real / Received
2013-08-07 15:08:30 +02:00
print '<tr><td height="10">' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( 'DateReceived' );
print '</td>' ;
if ( $action != 'editdate_livraison' ) print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=editdate_livraison&id=' . $delivery -> id . '">' . img_edit ( $langs -> trans ( 'SetDeliveryDate' ), 1 ) . '</a></td>' ;
print '</tr></table>' ;
print '</td><td colspan="2">' ;
if ( $action == 'editdate_livraison' )
{
print '<form name="setdate_livraison" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $delivery -> id . '" method="post">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="setdate_livraison">' ;
$form -> select_date ( $delivery -> date_delivery ? $delivery -> date_delivery :- 1 , 'liv_' , 1 , 1 , '' , " setdate_livraison " );
print '<input type="submit" class="button" value="' . $langs -> trans ( 'Modify' ) . '">' ;
print '</form>' ;
}
else
{
print $delivery -> date_delivery ? dol_print_date ( $delivery -> date_delivery , 'dayhourtext' ) : ' ' ;
}
print '</td>' ;
2008-08-05 10:41:54 +02:00
print '</tr>' ;
2013-08-07 15:08:30 +02:00
// Note Public
2013-04-09 17:18:07 +02:00
print '<tr><td>' . $langs -> trans ( " NotePublic " ) . '</td>' ;
print '<td colspan="3">' ;
print nl2br ( $delivery -> note_public );
/* $doleditor = new DolEditor ( 'note_public' , $object -> note_public , '' , 80 , 'dolibarr_notes' , 'In' , 0 , false , true , ROWS_3 , 70 );
print $doleditor -> Create ( 1 ); */
print " </td></tr> " ;
2013-08-07 15:08:30 +02:00
2013-04-09 17:18:07 +02:00
// Note Private
print '<tr><td>' . $langs -> trans ( " NotePrivate " ) . '</td>' ;
print '<td colspan="3">' ;
print nl2br ( $delivery -> note_private );
/* $doleditor = new DolEditor ( 'note_pprivate' , $object -> note_private , '' , 80 , 'dolibarr_notes' , 'In' , 0 , false , true , ROWS_3 , 70 );
print $doleditor -> Create ( 1 ); */
print " </td></tr> " ;
2013-08-07 15:08:30 +02:00
2008-08-05 10:41:54 +02:00
// Statut
print '<tr><td>' . $langs -> trans ( " Status " ) . '</td>' ;
2010-02-27 14:37:13 +01:00
print '<td colspan="3">' . $delivery -> getLibStatut ( 4 ) . " </td> \n " ;
2008-08-05 10:41:54 +02:00
print '</tr>' ;
2012-09-15 11:21:22 +02:00
if ( ! $conf -> expedition_bon -> enabled && ! empty ( $conf -> stock -> enabled ))
2008-08-05 10:41:54 +02:00
{
// Entrepot
$entrepot = new Entrepot ( $db );
2010-02-27 14:37:13 +01:00
$entrepot -> fetch ( $delivery -> entrepot_id );
2008-08-05 10:41:54 +02:00
print '<tr><td width="20%">' . $langs -> trans ( " Warehouse " ) . '</td>' ;
print '<td colspan="3"><a href="' . DOL_URL_ROOT . '/product/stock/fiche.php?id=' . $entrepot -> id . '">' . $entrepot -> libelle . '</a></td>' ;
print '</tr>' ;
}
2009-02-04 23:12:23 +01:00
print " </table><br> \n " ;
2008-08-05 10:41:54 +02:00
/*
* Lignes produits
*/
2011-09-17 21:49:50 +02:00
$num_prod = count ( $delivery -> lines );
2009-02-04 23:12:23 +01:00
$i = 0 ; $total = 0 ;
print '<table class="noborder" width="100%">' ;
2008-08-05 10:41:54 +02:00
if ( $num_prod )
{
$i = 0 ;
2009-02-04 23:12:23 +01:00
2008-08-05 10:41:54 +02:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " Products " ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " QtyOrdered " ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " QtyReceived " ) . '</td>' ;
print " </tr> \n " ;
2009-02-04 23:12:23 +01:00
}
$var = true ;
while ( $i < $num_prod )
{
$var =! $var ;
2013-06-20 09:18:12 +02:00
print " <tr " . $bc [ $var ] . " > " ;
2010-12-15 08:49:05 +01:00
if ( $delivery -> lines [ $i ] -> fk_product > 0 )
2008-08-05 10:41:54 +02:00
{
2009-02-04 23:12:23 +01:00
$product = new Product ( $db );
2010-12-15 08:49:05 +01:00
$product -> fetch ( $delivery -> lines [ $i ] -> fk_product );
2009-02-04 23:12:23 +01:00
2012-08-25 15:21:34 +02:00
// Define output language
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && ! empty ( $conf -> global -> PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE ))
{
$delivery -> fetch_thirdparty ();
$outputlangs = $langs ;
$newlang = '' ;
if ( empty ( $newlang ) && ! empty ( $_REQUEST [ 'lang_id' ])) $newlang = $_REQUEST [ 'lang_id' ];
if ( empty ( $newlang )) $newlang = $delivery -> client -> default_lang ;
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$label = ( ! empty ( $product -> multilangs [ $outputlangs -> defaultlang ][ " label " ])) ? $product -> multilangs [ $outputlangs -> defaultlang ][ " label " ] : $delivery -> lines [ $i ] -> product_label ;
}
else
$label = ( ! empty ( $delivery -> lines [ $i ] -> label ) ? $delivery -> lines [ $i ] -> label : $delivery -> lines [ $i ] -> product_label );
2012-01-17 12:03:05 +01:00
2009-02-04 23:12:23 +01:00
print '<td>' ;
// Affiche ligne produit
2010-12-15 08:49:05 +01:00
$text = '<a href="' . DOL_URL_ROOT . '/product/fiche.php?id=' . $delivery -> lines [ $i ] -> fk_product . '">' ;
if ( $delivery -> lines [ $i ] -> fk_product_type == 1 ) $text .= img_object ( $langs -> trans ( 'ShowService' ), 'service' );
2009-02-04 23:12:23 +01:00
else $text .= img_object ( $langs -> trans ( 'ShowProduct' ), 'product' );
2012-08-25 15:21:34 +02:00
$text .= ' ' . $delivery -> lines [ $i ] -> product_ref . '</a>' ;
2012-01-17 12:03:05 +01:00
$text .= ' - ' . $label ;
2012-08-25 15:21:34 +02:00
$description = ( ! empty ( $conf -> global -> PRODUIT_DESC_IN_FORM ) ? '' : dol_htmlentitiesbr ( $delivery -> lines [ $i ] -> description ));
2009-02-04 23:12:23 +01:00
//print $description;
2011-11-08 10:18:45 +01:00
print $form -> textwithtooltip ( $text , $description , 3 , '' , '' , $i );
2010-12-15 08:49:05 +01:00
print_date_range ( $delivery -> lines [ $i ] -> date_start , $delivery -> lines [ $i ] -> date_end );
2012-08-25 15:21:34 +02:00
if ( ! empty ( $conf -> global -> PRODUIT_DESC_IN_FORM ))
2008-08-05 10:41:54 +02:00
{
2012-08-25 15:21:34 +02:00
print ( ! empty ( $delivery -> lines [ $i ] -> description ) && $delivery -> lines [ $i ] -> description != $delivery -> lines [ $i ] -> product_label ) ? '<br>' . dol_htmlentitiesbr ( $delivery -> lines [ $i ] -> description ) : '' ;
2008-08-05 10:41:54 +02:00
}
2009-02-04 23:12:23 +01:00
}
else
{
print " <td> " ;
2010-12-15 08:49:05 +01:00
if ( $delivery -> lines [ $i ] -> fk_product_type == 1 ) $text = img_object ( $langs -> trans ( 'Service' ), 'service' );
2009-02-04 23:12:23 +01:00
else $text = img_object ( $langs -> trans ( 'Product' ), 'product' );
2012-08-25 15:21:34 +02:00
if ( ! empty ( $delivery -> lines [ $i ] -> label )) {
$text .= ' <strong>' . $delivery -> lines [ $i ] -> label . '</strong>' ;
print $form -> textwithtooltip ( $text , $delivery -> lines [ $i ] -> description , 3 , '' , '' , $i );
} else {
print $text . ' ' . nl2br ( $delivery -> lines [ $i ] -> description );
}
2009-02-04 23:12:23 +01:00
print_date_range ( $objp -> date_start , $objp -> date_end );
print " </td> \n " ;
}
2008-08-05 10:41:54 +02:00
2010-12-15 08:49:05 +01:00
print '<td align="center">' . $delivery -> lines [ $i ] -> qty_asked . '</td>' ;
print '<td align="center">' . $delivery -> lines [ $i ] -> qty_shipped . '</td>' ;
2008-08-05 10:41:54 +02:00
2009-02-04 23:12:23 +01:00
print " </tr> " ;
2008-08-05 10:41:54 +02:00
2009-02-04 23:12:23 +01:00
$i ++ ;
2008-08-05 10:41:54 +02:00
}
print " </table> \n " ;
print " \n </div> \n " ;
/*
* Boutons actions
*/
if ( $user -> societe_id == 0 )
{
print '<div class="tabsAction">' ;
2010-03-27 01:33:28 +01:00
2010-03-01 18:38:35 +01:00
if ( $delivery -> statut == 0 && $user -> rights -> expedition -> livraison -> valider && $num_prod > 0 )
{
print '<a class="butAction" href="fiche.php?id=' . $delivery -> id . '&action=valid">' . $langs -> trans ( " Validate " ) . '</a>' ;
}
2009-02-04 23:12:23 +01:00
2010-03-01 18:38:35 +01:00
if ( $user -> rights -> expedition -> livraison -> supprimer )
{
if ( $conf -> expedition_bon -> enabled )
2008-08-05 10:41:54 +02:00
{
2014-05-06 13:15:37 +02:00
print '<a class="butActionDelete" href="fiche.php?id=' . $delivery -> id . '&expid=' . $delivery -> origin_id . '&action=delete&backtourl=' . urlencode ( DOL_URL_ROOT . '/expedition/fiche.php?id=' . $delivery -> origin_id ) . '">' . $langs -> trans ( " Delete " ) . '</a>' ;
2008-08-05 10:41:54 +02:00
}
2010-03-01 18:38:35 +01:00
else
2008-08-05 10:41:54 +02:00
{
2010-03-01 18:38:35 +01:00
print '<a class="butActionDelete" href="fiche.php?id=' . $delivery -> id . '&action=delete">' . $langs -> trans ( " Delete " ) . '</a>' ;
2008-08-05 10:41:54 +02:00
}
2010-03-01 18:38:35 +01:00
}
2009-02-04 23:12:23 +01:00
2008-08-05 10:41:54 +02:00
print '</div>' ;
}
print " \n " ;
2008-10-17 16:43:33 +02:00
2010-03-01 18:38:35 +01:00
print '<table width="100%" cellspacing="2"><tr><td width="50%" valign="top">' ;
2008-10-17 16:43:33 +02:00
2008-08-05 10:41:54 +02:00
/*
2008-10-17 16:43:33 +02:00
* Documents generated
2008-08-05 10:41:54 +02:00
*/
2010-02-27 14:37:13 +01:00
$deliveryref = dol_sanitizeFileName ( $delivery -> ref );
$filedir = $conf -> expedition -> dir_output . " /receipt/ " . $deliveryref ;
$urlsource = $_SERVER [ " PHP_SELF " ] . " ?id= " . $delivery -> id ;
2008-08-05 10:41:54 +02:00
$genallowed = $user -> rights -> expedition -> livraison -> creer ;
$delallowed = $user -> rights -> expedition -> livraison -> supprimer ;
2010-03-27 01:33:28 +01:00
$somethingshown = $formfile -> show_documents ( 'livraison' , $deliveryref , $filedir , $urlsource , $genallowed , $delallowed , $delivery -> modelpdf , 1 , 0 , 0 , 28 , 0 , '' , '' , '' , $soc -> default_lang );
2013-08-07 15:08:30 +02:00
/*
* Linked object block ( of linked shipment )
*/
if ( $delivery -> origin == 'expedition' )
{
$shipment = new Expedition ( $db );
$shipment -> fetch ( $delivery -> origin_id );
$somethingshown = $shipment -> showLinkedObjectBlock ();
}
2008-10-17 16:43:33 +02:00
if ( $genallowed && ! $somethingshown ) $somethingshown = 1 ;
2008-08-05 10:41:54 +02:00
print '</td><td valign="top" width="50%">' ;
2006-05-29 15:53:20 +02:00
2008-10-17 16:43:33 +02:00
// Rien a droite
2009-02-04 23:12:23 +01:00
2008-01-31 15:23:57 +01:00
print '</td></tr></table>' ;
2008-10-17 16:43:33 +02:00
2009-07-30 09:24:18 +02:00
if ( $expedition -> origin_id )
{
print '<br>' ;
//show_list_sending_receive($expedition->origin,$expedition->origin_id," AND e.rowid <> ".$expedition->id);
show_list_sending_receive ( $expedition -> origin , $expedition -> origin_id );
}
2008-01-31 15:23:57 +01:00
}
else
{
2009-07-15 22:10:28 +02:00
/* Expedition non trouvee */
print " Expedition inexistante ou acces refuse " ;
2008-01-31 15:23:57 +01:00
}
}
else
2008-08-05 10:41:54 +02:00
{
2009-07-15 22:10:28 +02:00
/* Expedition non trouvee */
print " Expedition inexistante ou acces refuse " ;
2008-08-05 10:41:54 +02:00
}
2006-05-29 15:53:20 +02:00
}
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-08-25 15:21:34 +02:00
$db -> close ();
2013-08-07 15:29:13 +02:00
?>