2006-12-11 21:52:01 +01:00
< ? php
/* Copyright ( C ) 2004 - 2006 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2011-05-24 01:46:39 +02:00
* Copyright ( C ) 2004 - 2011 Laurent Destailleur < eldy @ users . sourceforge . net >
2010-05-28 22:41:41 +02:00
* Copyright ( C ) 2005 Eric Seigne < eric . seigne @ ryxeo . com >
2012-12-30 15:11:07 +01:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ capnetworks . com >
2010-09-28 18:24:25 +02:00
* Copyright ( C ) 2010 Juanjo Menent < jmenent @ 2 byte . es >
2014-03-16 20:49:56 +01:00
* Copyright ( C ) 2014 C<EFBFBD> dric Gross < c . gross @ kreiz - it . fr >
2006-12-11 21:52:01 +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
2011-12-17 21:58:44 +01:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
* or see http :// www . gnu . org /
2006-12-11 21:52:01 +01:00
*/
/**
2010-05-28 22:41:41 +02:00
* \file htdocs / fourn / commande / dispatch . php
2009-08-06 16:44:24 +02:00
* \ingroup commande
* \brief Fiche de ventilation des commandes fournisseurs
2008-11-16 02:54:33 +01:00
*/
2006-12-11 21:52:01 +01: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 . '/core/modules/supplier_order/modules_commandefournisseur.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/fourn.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php' ;
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> projet -> enabled )) require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
2006-12-11 21:52:01 +01:00
$langs -> load ( 'orders' );
$langs -> load ( 'sendings' );
$langs -> load ( 'companies' );
$langs -> load ( 'bills' );
$langs -> load ( 'deliveries' );
$langs -> load ( 'products' );
$langs -> load ( 'stocks' );
2014-03-15 10:28:01 +01:00
if ( ! empty ( $conf -> productbatch -> enabled )) $langs -> load ( 'productbatch' );
2006-12-11 21:52:01 +01:00
2009-04-27 22:37:50 +02:00
// Security check
2014-03-01 14:49:30 +01:00
$id = GETPOST ( " id " , 'int' );
2009-04-27 22:37:50 +02:00
if ( $user -> societe_id ) $socid = $user -> societe_id ;
2013-03-24 21:06:45 +01:00
$result = restrictedArea ( $user , 'fournisseur' , $id , '' , 'commande' );
2006-12-11 21:52:01 +01:00
2010-08-26 16:49:40 +02:00
if ( empty ( $conf -> stock -> enabled ))
{
accessforbidden ();
}
2010-03-11 15:31:16 +01:00
// Recuperation de l'id de projet
$projectid = 0 ;
2014-03-15 10:28:01 +01:00
if ( $_GET [ " projectid " ]) $projectid = GETPOST ( " projectid " , 'int' );
2006-12-11 21:52:01 +01:00
$mesg = '' ;
2010-08-26 16:49:40 +02:00
2006-12-11 21:52:01 +01:00
/*
* Actions
*/
if ( $_POST [ " action " ] == 'dispatch' && $user -> rights -> fournisseur -> commande -> receptionner )
{
2008-11-16 02:54:33 +01:00
$commande = new CommandeFournisseur ( $db );
2014-03-01 14:49:30 +01:00
$commande -> fetch ( $id );
$db -> begin ();
2006-12-11 21:52:01 +01:00
2008-11-16 02:54:33 +01:00
foreach ( $_POST as $key => $value )
2006-12-11 21:52:01 +01:00
{
2009-10-22 17:09:04 +02:00
if ( preg_match ( '/^product_([0-9]+)$/i' , $key , $reg ) )
2008-11-16 02:54:33 +01:00
{
2010-05-28 22:41:41 +02:00
$prod = " product_ " . $reg [ 1 ];
$qty = " qty_ " . $reg [ 1 ];
$ent = " entrepot_ " . $reg [ 1 ];
2014-03-01 14:49:30 +01:00
$pu = " pu_ " . $reg [ 1 ]; // This is unit price including discount
2014-03-15 10:28:01 +01:00
if ( GETPOST ( $ent , 'int' ) > 0 )
2010-08-26 16:49:40 +02:00
{
2014-03-15 10:28:01 +01:00
$result = $commande -> DispatchProduct ( $user , GETPOST ( $prod , 'int' ), GETPOST ( $qty ), GETPOST ( $ent , 'int' ), GETPOST ( $pu ), GETPOST ( " comment " ));
2010-08-26 16:49:40 +02:00
}
else
{
dol_syslog ( 'No dispatch for line ' . $key . ' as no warehouse choosed' );
2013-11-14 17:08:59 +01:00
$text = $langs -> transnoentities ( 'Warehouse' ) . ', ' . $langs -> transnoentities ( 'Line' ) . '' . ( $reg [ 1 ] - 1 );
setEventMessage ( $langs -> trans ( 'ErrorFieldRequired' , $text ), 'errors' );
2010-08-26 16:49:40 +02:00
}
2014-03-15 10:28:01 +01:00
} else if ( preg_match ( '/^product_([0-9]+)_([0-9]+)$/i' , $key , $reg )) {
//eat-by date dispatch
$prod = " product_ " . $reg [ 1 ] . " _ " . $reg [ 2 ];
$qty = " qty_ " . $reg [ 1 ] . " _ " . $reg [ 2 ];
$ent = " entrepot_ " . $reg [ 1 ] . " _ " . $reg [ 2 ];
$pu = " pu_ " . $reg [ 1 ] . " _ " . $reg [ 2 ];
$lot = " lot_number_ " . $reg [ 1 ] . " _ " . $reg [ 2 ];
2014-03-16 07:00:27 +01:00
$dDLUO = dol_mktime ( 12 , 0 , 0 , $_POST [ 'dluo_' . $reg [ 1 ] . " _ " . $reg [ 2 ] . 'month' ], $_POST [ 'dluo_' . $reg [ 1 ] . " _ " . $reg [ 2 ] . 'day' ], $_POST [ 'dluo_' . $reg [ 1 ] . " _ " . $reg [ 2 ] . 'year' ]);
$dDLC = dol_mktime ( 12 , 0 , 0 , $_POST [ 'dlc_' . $reg [ 1 ] . " _ " . $reg [ 2 ] . 'month' ], $_POST [ 'dlc_' . $reg [ 1 ] . " _ " . $reg [ 2 ] . 'day' ], $_POST [ 'dlc_' . $reg [ 1 ] . " _ " . $reg [ 2 ] . 'year' ]);
2014-03-15 10:28:01 +01:00
if ( ! ( GETPOST ( $ent , 'int' ) > 0 ))
{
dol_syslog ( 'No dispatch for line ' . $key . ' as no warehouse choosed' );
$text = $langs -> transnoentities ( 'Warehouse' ) . ', ' . $langs -> transnoentities ( 'Line' ) . '' . ( $reg [ 1 ] - 1 );
setEventMessage ( $langs -> trans ( 'ErrorFieldRequired' , $text ), 'errors' );
}
if ( ! (( GETPOST ( $qty ) > 0 ) && ( $_POST [ $lot ] or $dDLUO or $dDLC ) ))
{
dol_syslog ( 'No dispatch for line ' . $key . ' as qty is not set or eat-by date are not set' );
$text = $langs -> transnoentities ( 'atleast1batchfield' ) . ', ' . $langs -> transnoentities ( 'Line' ) . '' . ( $reg [ 1 ] - 1 );
setEventMessage ( $langs -> trans ( 'ErrorFieldRequired' , $text ), 'errors' );
} else {
$result = $commande -> DispatchProduct ( $user , GETPOST ( $prod , 'int' ), GETPOST ( $qty ), GETPOST ( $ent , 'int' ), GETPOST ( $pu ), GETPOST ( " comment " ), $dDLC , $dDLUO , GETPOST ( $lot ));
}
2008-11-16 02:54:33 +01:00
}
2014-03-15 10:28:01 +01:00
2006-12-11 21:52:01 +01:00
}
2013-03-24 21:06:45 +01:00
2013-02-25 16:56:37 +01:00
if ( ! $notrigger )
{
global $conf , $langs , $user ;
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php' ;
2013-03-25 18:03:42 +01:00
$interface = new Interfaces ( $db );
$result_trigger = $interface -> run_triggers ( 'ORDER_SUPPLIER_DISPATCH' , $commande , $user , $langs , $conf );
if ( $result_trigger < 0 ) { $error ++ ; $commande -> errors = $interface -> errors ; }
2013-02-25 16:56:37 +01:00
// Fin appel triggers
}
2006-12-11 21:52:01 +01:00
2010-05-28 22:41:41 +02:00
if ( $result > 0 )
{
2014-03-01 14:49:30 +01:00
$db -> commit ();
2014-03-15 10:28:01 +01:00
header ( " Location: dispatch.php?id= " . $id );
2010-05-28 22:41:41 +02:00
exit ;
}
else
{
2014-03-01 14:49:30 +01:00
$db -> rollback ();
2010-08-26 16:49:40 +02:00
$mesg = '<div class="error">' . $langs -> trans ( $commande -> error ) . '</div>' ;
2010-05-28 22:41:41 +02:00
}
2006-12-11 21:52:01 +01:00
}
2008-06-14 12:01:31 +02:00
/*
* View
*/
2014-03-15 10:28:01 +01:00
if ( ! empty ( $conf -> productbatch -> enabled )) {
llxHeader ( '' , $langs -> trans ( " OrderCard " ), " CommandeFournisseur " , '' , 0 , 0 , array ( '/core/js/lib_batch.js' ));
} else {
llxHeader ( '' , $langs -> trans ( " OrderCard " ), " CommandeFournisseur " );
}
2006-12-11 21:52:01 +01:00
2011-11-08 10:18:45 +01:00
$form = new Form ( $db );
2010-07-11 21:29:18 +02:00
$warehouse_static = new Entrepot ( $db );
2006-12-11 21:52:01 +01:00
2010-05-28 22:41:41 +02:00
$now = dol_now ();
2006-12-11 21:52:01 +01:00
2014-03-15 10:28:01 +01:00
$id = GETPOST ( 'id' , 'int' );
$ref = GETPOST ( 'ref' );
2009-01-31 01:06:19 +01:00
if ( $id > 0 || ! empty ( $ref ))
2006-12-11 21:52:01 +01:00
{
2008-11-16 02:54:33 +01:00
//if ($mesg) print $mesg.'<br>';
$commande = new CommandeFournisseur ( $db );
2009-01-31 01:06:19 +01:00
2014-03-15 10:28:01 +01:00
$result = $commande -> fetch ( $id , $ref );
2009-01-31 01:06:19 +01:00
if ( $result >= 0 )
2006-12-11 21:52:01 +01:00
{
2008-11-16 02:54:33 +01: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-11-16 02:54:33 +01:00
2008-11-24 21:09:23 +01:00
$head = ordersupplier_prepare_head ( $commande );
2009-01-31 01:06:19 +01:00
2008-11-16 02:54:33 +01:00
$title = $langs -> trans ( " SupplierOrder " );
2009-08-06 16:44:24 +02:00
dol_fiche_head ( $head , 'dispatch' , $title , 0 , 'order' );
2009-01-31 01:06:19 +01:00
2008-11-16 02:54:33 +01:00
/*
* Commande
*/
print '<table class="border" width="100%">' ;
2009-01-31 01:06:19 +01:00
2008-11-16 02:54:33 +01:00
// Ref
print '<tr><td width="20%">' . $langs -> trans ( " Ref " ) . '</td>' ;
2009-01-31 01:06:19 +01:00
print '<td colspan="2">' ;
2011-11-08 10:18:45 +01:00
print $form -> showrefnav ( $commande , 'ref' , '' , 1 , 'ref' , 'ref' );
2009-01-31 01:06:19 +01:00
print '</td>' ;
2008-11-16 02:54:33 +01:00
print '</tr>' ;
// Fournisseur
2009-01-31 01:06:19 +01:00
print '<tr><td>' . $langs -> trans ( " Supplier " ) . " </td> " ;
print '<td colspan="2">' . $soc -> getNomUrl ( 1 , 'supplier' ) . '</td>' ;
2008-11-16 02:54:33 +01:00
print '</tr>' ;
// Statut
print '<tr>' ;
print '<td>' . $langs -> trans ( " Status " ) . '</td>' ;
2009-01-31 01:06:19 +01:00
print '<td colspan="2">' ;
2008-11-16 02:54:33 +01:00
print $commande -> getLibStatut ( 4 );
print " </td></tr> " ;
2009-01-31 01:06:19 +01:00
// Date
2008-11-16 02:54:33 +01:00
if ( $commande -> methode_commande_id > 0 )
2006-12-11 21:52:01 +01:00
{
2008-11-16 02:54:33 +01:00
print '<tr><td>' . $langs -> trans ( " Date " ) . '</td><td colspan="2">' ;
if ( $commande -> date_commande )
{
2009-02-20 23:53:15 +01:00
print dol_print_date ( $commande -> date_commande , " dayhourtext " ) . " \n " ;
2008-11-16 02:54:33 +01:00
}
2009-01-31 01:06:19 +01:00
print " </td></tr> " ;
2008-11-16 02:54:33 +01:00
if ( $commande -> methode_commande )
{
2009-01-31 01:06:19 +01:00
print '<tr><td>' . $langs -> trans ( " Method " ) . '</td><td colspan="2">' . $commande -> methode_commande . '</td></tr>' ;
2008-11-16 02:54:33 +01:00
}
2006-12-11 21:52:01 +01:00
}
2008-11-16 02:54:33 +01:00
// Auteur
print '<tr><td>' . $langs -> trans ( " AuthorRequest " ) . '</td>' ;
print '<td colspan="2">' . $author -> getNomUrl ( 1 ) . '</td>' ;
2009-01-31 01:06:19 +01:00
print '</tr>' ;
2008-11-16 02:54:33 +01:00
print " </table> " ;
2013-11-14 17:08:59 +01:00
//if ($mesg) print $mesg;
print '<br>' ;
2008-11-16 02:54:33 +01:00
2010-05-28 22:41:41 +02:00
$disabled = 1 ;
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> global -> STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER )) $disabled = 0 ;
2010-05-28 22:41:41 +02:00
2008-11-16 02:54:33 +01:00
/*
* Lignes de commandes
*/
2010-05-28 23:52:51 +02:00
if ( $commande -> statut <= 2 || $commande -> statut >= 6 )
{
print $langs -> trans ( " OrderStatusNotReadyToDispatch " );
}
2008-11-16 02:54:33 +01:00
if ( $commande -> statut == 3 || $commande -> statut == 4 || $commande -> statut == 5 )
2006-12-11 21:52:01 +01:00
{
2010-08-26 16:49:40 +02:00
$entrepot = new Entrepot ( $db );
$listwarehouses = $entrepot -> list_array ( 1 );
2008-11-16 02:54:33 +01:00
print '<form method="POST" action="dispatch.php?id=' . $commande -> id . '">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2008-11-16 02:54:33 +01:00
print '<input type="hidden" name="action" value="dispatch">' ;
print '<table class="noborder" width="100%">' ;
$sql = " SELECT cfd.fk_product, sum(cfd.qty) as qty " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " commande_fournisseur_dispatch as cfd " ;
$sql .= " WHERE cfd.fk_commande = " . $commande -> id ;
$sql .= " GROUP BY cfd.fk_product " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
2015-09-10 23:12:27 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
if ( $num )
2008-11-16 02:54:33 +01:00
{
2015-09-10 23:12:27 +02:00
while ( $i < $num )
{
$objd = $db -> fetch_object ( $resql );
$products_dispatched [ $objd -> fk_product ] = price2num ( $objd -> qty , 5 );
$i ++ ;
}
2008-11-16 02:54:33 +01:00
}
$db -> free ( $resql );
}
2014-03-01 14:49:30 +01:00
$sql = " SELECT l.fk_product, l.subprice, l.remise_percent, SUM(l.qty) as qty, " ;
2014-03-15 10:28:01 +01:00
$sql .= " p.ref, p.label, p.tobatch " ;
2008-11-16 02:54:33 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " commande_fournisseurdet as l " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product as p ON l.fk_product=p.rowid " ;
$sql .= " WHERE l.fk_commande = " . $commande -> id ;
2014-03-15 10:28:01 +01:00
$sql .= " GROUP BY p.ref, p.label, p.tobatch, l.fk_product, l.subprice, l.remise_percent " ; // Calculation of amount dispatched is done per fk_product so we must group by fk_product
2012-08-07 19:32:51 +02:00
$sql .= " ORDER BY p.ref, p.label " ;
2008-11-16 02:54:33 +01:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
if ( $num )
{
print '<tr class="liste_titre">' ;
2014-03-15 10:28:01 +01:00
print '<td colspan="4" width="40%">' . $langs -> trans ( " Description " ) . '</td>' ;
2008-11-16 02:54:33 +01:00
print '<td align="right">' . $langs -> trans ( " QtyOrdered " ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " QtyDispatched " ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " QtyDelivered " ) . '</td>' ;
2010-05-28 22:41:41 +02:00
print '<td align="right">' . $langs -> trans ( " Warehouse " ) . '</td>' ;
2008-11-16 02:54:33 +01:00
print " </tr> \n " ;
2014-03-15 10:28:01 +01:00
if ( ! empty ( $conf -> productbatch -> enabled )) {
print '<tr class="liste_titre">' ;
print '<td width="5%"> </td>' ;
print '<td>' . $langs -> trans ( " l_eatby " ) . '</td>' ;
print '<td>' . $langs -> trans ( " l_sellby " ) . '</td>' ;
print '<td>' . $langs -> trans ( " batch_number " ) . '</td>' ;
print '<td colspan="4" width="50%"> </td>' ;
print " </tr> \n " ;
}
2008-11-16 02:54:33 +01:00
}
2010-05-28 23:52:51 +02:00
$nbfreeproduct = 0 ;
$nbproduct = 0 ;
2008-11-16 02:54:33 +01:00
$var = true ;
while ( $i < $num )
{
$objp = $db -> fetch_object ( $resql );
2010-05-28 23:52:51 +02:00
2009-12-14 23:26:57 +01:00
// On n'affiche pas les produits personnalises
2010-05-28 23:52:51 +02:00
if ( ! $objp -> fk_product > 0 )
{
$nbfreeproduct ++ ;
}
else
2008-11-16 02:54:33 +01:00
{
2015-09-10 23:12:27 +02:00
$remaintodispatch = ( price2num ( $objp -> qty , 5 ) - $products_dispatched [ $objp -> fk_product ]); // Calculation of dispatched
2010-05-28 23:52:51 +02:00
if ( $remaintodispatch < 0 ) $remaintodispatch = 0 ;
2013-11-14 17:08:59 +01:00
if ( $remaintodispatch )
2010-08-26 16:49:40 +02:00
{
2013-11-14 17:08:59 +01:00
$nbproduct ++ ;
2014-03-01 14:49:30 +01:00
2013-11-14 17:08:59 +01:00
$var =! $var ;
print " <tr " . $bc [ $var ] . " > " ;
2014-03-15 10:28:01 +01:00
print '<td colspan="4">' ;
2013-11-14 17:08:59 +01:00
print '<a href="' . DOL_URL_ROOT . '/product/fournisseurs.php?id=' . $objp -> fk_product . '">' . img_object ( $langs -> trans ( " ShowProduct " ), 'product' ) . ' ' . $objp -> ref . '</a>' ;
2014-03-01 14:49:30 +01:00
print ' - ' . $objp -> label . " \n " ;
2013-11-14 17:08:59 +01:00
// To show detail cref and description value, we must make calculation by cref
//print ($objp->cref?' ('.$objp->cref.')':'');
//if ($objp->description) print '<br>'.nl2br($objp->description);
2014-03-15 10:28:01 +01:00
if (( empty ( $conf -> productbatch -> enabled )) || $objp -> tobatch == 0 ) {
$suffix = '_' . $i ;
} else {
$suffix = '_0_' . $i ;
}
2014-03-01 14:49:30 +01:00
2014-03-15 10:28:01 +01:00
$up_ht_disc = $objp -> subprice ;
if ( ! empty ( $objp -> remise_percent ) && empty ( $conf -> global -> STOCK_EXCLUDE_DISCOUNT_FOR_PMP )) $up_ht_disc = price2num ( $up_ht_disc * ( 100 - $objp -> remise_percent ) / 100 , 'MU' );
2014-03-01 14:49:30 +01:00
2013-11-14 17:08:59 +01:00
print " </td> \n " ;
print '<td align="right">' . $objp -> qty . '</td>' ;
print '<td align="right">' . $products_dispatched [ $objp -> fk_product ] . '</td>' ;
2014-03-15 10:28:01 +01:00
if ( ! ( empty ( $conf -> productbatch -> enabled )) && $objp -> tobatch == 1 ) {
2014-03-16 20:49:56 +01:00
print '<td colspan="2" align="center">' . img_picto_common ( $langs -> trans ( 'AddDispatchBatchLine' ), 'treemenu/plustop2.gif' , 'onClick="AddLineBatch(' . $i . ')"' ) . '</td>' ;
2014-03-15 10:28:01 +01:00
print '</tr>' ;
print '<tr ' . $bc [ $var ] . ' name="dluo' . $suffix . '"><td width="5%">' ;
print '<input name="product' . $suffix . '" type="hidden" value="' . $objp -> fk_product . '">' ;
print '<input name="pu' . $suffix . '" type="hidden" value="' . $up_ht_disc . '"><!-- This is a up including discount -->' ;
print '</td><td>' ;
$form -> select_date ( '' , 'dlc' . $suffix , '' , '' , 1 , " " );
print '</td><td>' ;
$form -> select_date ( '' , 'dluo' . $suffix , '' , '' , 1 , " " );
print '</td><td>' ;
print '<input type="text" name="lot_number' . $suffix . '" size="40" value="">' ;
print '</td>' ;
print '<td colspan="2"> </td>' ;
} else {
print '<input name="product' . $suffix . '" type="hidden" value="' . $objp -> fk_product . '">' ;
print '<input name="pu' . $suffix . '" type="hidden" value="' . $up_ht_disc . '"><!-- This is a up including discount -->' ;
}
2013-11-14 17:08:59 +01:00
// Dispatch
2014-03-15 10:28:01 +01:00
print '<td align="right"><input name="qty' . $suffix . '" type="text" size="8" value="' . ( $remaintodispatch ) . '"></td>' ;
2013-11-14 17:08:59 +01:00
// Warehouse
print '<td align="right">' ;
if ( count ( $listwarehouses ) > 1 )
{
2014-03-15 10:28:01 +01:00
print $form -> selectarray ( " entrepot " . $suffix , $listwarehouses , '' , 1 , 0 , 0 , '' , 0 , 0 , $disabled );
2013-11-14 17:08:59 +01:00
}
elseif ( count ( $listwarehouses ) == 1 )
{
2014-03-15 10:28:01 +01:00
print $form -> selectarray ( " entrepot " . $suffix , $listwarehouses , '' , 0 , 0 , 0 , '' , 0 , 0 , $disabled );
2013-11-14 17:08:59 +01:00
}
else
{
print $langs -> trans ( " NoWarehouseDefined " );
}
print " </td> \n " ;
print " </tr> \n " ;
2010-08-26 16:49:40 +02:00
}
2008-11-16 02:54:33 +01:00
}
$i ++ ;
}
$db -> free ( $resql );
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2008-11-16 02:54:33 +01:00
}
print " </table> \n " ;
print " <br/> \n " ;
2010-05-28 22:41:41 +02:00
2010-05-28 23:52:51 +02:00
if ( $nbproduct )
{
2010-08-26 17:46:39 +02:00
print $langs -> trans ( " Comment " ) . ' : ' ;
print '<input type="text" size="60" maxlength="128" name="comment" value="' ;
2014-03-15 10:28:01 +01:00
print $_POST [ " comment " ] ? GETPOST ( " comment " ) : $langs -> trans ( " DispatchSupplierOrder " , $commande -> ref );
2010-08-26 17:46:39 +02:00
// print ' / '.$commande->ref_supplier; // Not yet available
2011-05-24 01:46:39 +02:00
print '" class="flat"><br><br>' ;
2010-08-26 17:46:39 +02:00
2010-08-26 16:49:40 +02:00
print '<center><input type="submit" class="button" value="' . $langs -> trans ( " DispatchVerb " ) . '"' ;
2011-08-31 17:12:09 +02:00
if ( count ( $listwarehouses ) <= 0 ) print ' disabled="disabled"' ;
2010-08-26 16:49:40 +02:00
print '></center>' ;
2010-05-28 23:52:51 +02:00
}
if ( ! $nbproduct && $nbfreeproduct )
{
print $langs -> trans ( " NoPredefinedProductToDispatch " );
}
2010-05-28 22:41:41 +02:00
print '</form>' ;
2006-12-11 21:52:01 +01:00
}
2014-03-01 14:49:30 +01:00
2013-11-14 17:08:59 +01:00
dol_fiche_end ();
2008-11-16 02:54:33 +01:00
2010-05-28 22:41:41 +02:00
// List of already dispatching
2010-07-11 21:29:18 +02:00
$sql = " SELECT p.ref, p.label, " ;
$sql .= " e.rowid as warehouse_id, e.label as entrepot, " ;
2010-05-28 22:41:41 +02:00
$sql .= " cfd.fk_product, cfd.qty, cfd.rowid " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " product as p, " ;
$sql .= " " . MAIN_DB_PREFIX . " commande_fournisseur_dispatch as cfd " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " entrepot as e ON cfd.fk_entrepot = e.rowid " ;
2008-11-16 02:54:33 +01:00
$sql .= " WHERE cfd.fk_commande = " . $commande -> id ;
$sql .= " AND cfd.fk_product = p.rowid " ;
2009-12-14 23:26:57 +01:00
$sql .= " ORDER BY cfd.rowid ASC " ;
2008-11-16 02:54:33 +01:00
$resql = $db -> query ( $sql );
if ( $resql )
2006-12-11 21:52:01 +01:00
{
2008-11-16 02:54:33 +01:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2010-05-28 23:52:51 +02:00
if ( $num > 0 )
2008-11-16 02:54:33 +01:00
{
2010-05-28 23:52:51 +02:00
print " <br/> \n " ;
2014-03-01 14:49:30 +01:00
2013-11-14 17:08:59 +01:00
print_titre ( $langs -> trans ( " ReceivingForSameOrder " ));
2014-03-01 14:49:30 +01:00
2010-05-28 23:52:51 +02:00
print '<table class="noborder" width="100%">' ;
2008-11-16 02:54:33 +01:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " Description " ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " QtyDispatched " ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " Warehouse " ) . '</td>' ;
print " </tr> \n " ;
2010-05-28 23:52:51 +02:00
$var = false ;
2008-11-16 02:54:33 +01:00
2010-05-28 23:52:51 +02:00
while ( $i < $num )
{
$objp = $db -> fetch_object ( $resql );
2013-06-20 09:18:12 +02:00
print " <tr " . $bc [ $var ] . " > " ;
2010-05-28 23:52:51 +02:00
print '<td>' ;
print '<a href="' . DOL_URL_ROOT . '/product/fournisseurs.php?id=' . $objp -> fk_product . '">' . img_object ( $langs -> trans ( " ShowProduct " ), 'product' ) . ' ' . $objp -> ref . '</a>' ;
print ' - ' . $objp -> label ;
print " </td> \n " ;
print '<td align="right">' . $objp -> qty . '</td>' ;
2010-07-11 21:29:18 +02:00
print '<td align="right">' ;
$warehouse_static -> id = $objp -> warehouse_id ;
$warehouse_static -> libelle = $objp -> entrepot ;
print $warehouse_static -> getNomUrl ( 1 );
print '</td>' ;
2010-05-28 23:52:51 +02:00
print " </tr> \n " ;
$i ++ ;
$var =! $var ;
}
$db -> free ( $resql );
print " </table> \n " ;
2008-11-16 02:54:33 +01:00
}
2006-12-11 21:52:01 +01:00
}
2008-11-16 02:54:33 +01:00
else
2006-12-11 21:52:01 +01:00
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2006-12-11 21:52:01 +01:00
}
2008-11-16 02:54:33 +01:00
}
else
{
2009-12-14 23:26:57 +01:00
// Commande non trouvee
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2006-12-11 21:52:01 +01:00
}
}
$db -> close ();
2011-08-27 16:24:16 +02:00
llxFooter ();