2006-12-11 21:52:01 +01:00
< ? php
/* Copyright ( C ) 2004 - 2006 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2016-12-09 11:16:04 +01:00
* Copyright ( C ) 2004 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
2010-05-28 22:41:41 +02:00
* Copyright ( C ) 2005 Eric Seigne < eric . seigne @ ryxeo . com >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ inodbox . com >
2021-01-28 13:37:43 +01:00
* Copyright ( C ) 2010 - 2021 Juanjo Menent < jmenent @ 2 byte . es >
2015-02-11 22:54:06 +01:00
* Copyright ( C ) 2014 Cedric Gross < c . gross @ kreiz - it . fr >
2018-09-16 11:42:20 +02:00
* Copyright ( C ) 2016 Florian Henry < florian . henry @ atm - consulting . fr >
2020-07-17 10:50:24 +02:00
* Copyright ( C ) 2017 - 2020 Ferran Marcet < fmarcet @ 2 byte . es >
2018-09-16 11:42:20 +02:00
* Copyright ( C ) 2018 Frédéric France < frederic . france @ netlogic . fr >
2020-05-19 14:18:06 +02:00
* Copyright ( C ) 2019 - 2020 Christophe Battarel < christophe @ altairis . 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
* or see https :// www . gnu . org /
2006-12-11 21:52:01 +01:00
*/
/**
2016-08-05 10:02:36 +02:00
* \file htdocs / fourn / commande / dispatch . php
* \ingroup commande
* \brief Page to dispatch receiving
2008-11-16 02:54:33 +01:00
*/
2017-08-23 16:07:11 +02:00
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2019-11-13 19:35:02 +01: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' ;
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.dispatch.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php' ;
2020-10-31 14:32:18 +01:00
require_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php' ;
2020-05-19 15:59:03 +02:00
2021-02-25 23:21:30 +01:00
if ( ! empty ( $conf -> projet -> enabled )) {
2019-11-13 19:35:02 +01:00
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
2021-02-25 23:21:30 +01:00
}
2006-12-11 21:52:01 +01:00
2018-09-16 11:42:20 +02:00
// Load translation files required by the page
2019-11-13 19:35:02 +01:00
$langs -> loadLangs ( array ( " bills " , " orders " , " sendings " , " companies " , " deliveries " , " products " , " stocks " , " receptions " ));
2018-09-16 11:42:20 +02:00
2021-02-25 23:21:30 +01:00
if ( ! empty ( $conf -> productbatch -> enabled )) {
2016-08-05 10:02:36 +02:00
$langs -> load ( 'productbatch' );
2021-02-25 23:21:30 +01:00
}
2006-12-11 21:52:01 +01:00
2016-08-05 10:02:36 +02:00
// Security check
$id = GETPOST ( " id " , 'int' );
$ref = GETPOST ( 'ref' );
2015-03-08 02:08:26 +01:00
$lineid = GETPOST ( 'lineid' , 'int' );
2019-01-27 11:55:16 +01:00
$action = GETPOST ( 'action' , 'aZ09' );
2019-08-22 16:07:18 +02:00
$fk_default_warehouse = GETPOST ( 'fk_default_warehouse' , 'int' );
2020-05-19 14:18:06 +02:00
$cancel = GETPOST ( 'cancel' , 'alpha' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
2019-05-01 11:10:11 +02:00
2021-02-25 23:21:30 +01:00
if ( $user -> socid ) {
2019-12-19 11:35:50 +01:00
$socid = $user -> socid ;
2021-02-25 23:21:30 +01:00
}
2018-01-17 15:54:27 +01:00
$result = restrictedArea ( $user , 'fournisseur' , $id , 'commande_fournisseur' , 'commande' );
2006-12-11 21:52:01 +01:00
2016-08-05 10:02:36 +02:00
if ( empty ( $conf -> stock -> enabled )) {
2010-08-26 16:49:40 +02:00
accessforbidden ();
}
2018-04-23 15:05:37 +02:00
$hookmanager -> initHooks ( array ( 'ordersupplierdispatch' ));
2016-08-05 10:02:36 +02:00
// Recuperation de l'id de projet
$projectid = 0 ;
2021-02-25 23:21:30 +01:00
if ( $_GET [ " projectid " ]) {
2016-08-05 10:02:36 +02:00
$projectid = GETPOST ( " projectid " , 'int' );
2021-02-25 23:21:30 +01:00
}
2006-12-11 21:52:01 +01:00
2016-12-09 11:16:04 +01:00
$object = new CommandeFournisseur ( $db );
2010-08-26 16:49:40 +02:00
2019-11-13 19:35:02 +01:00
if ( $id > 0 || ! empty ( $ref )) {
2016-12-09 11:16:04 +01:00
$result = $object -> fetch ( $id , $ref );
2016-08-05 10:02:36 +02:00
if ( $result < 0 ) {
2016-12-09 11:16:04 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2016-08-05 10:02:36 +02:00
}
2016-12-09 11:16:04 +01:00
$result = $object -> fetch_thirdparty ();
2016-08-05 10:02:36 +02:00
if ( $result < 0 ) {
2016-12-09 11:16:04 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2016-08-05 10:02:36 +02:00
}
}
2016-09-12 01:05:45 +02:00
2006-12-11 21:52:01 +01:00
/*
* Actions
*/
2015-02-11 22:54:06 +01:00
2019-11-13 19:35:02 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-25 23:21:30 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2018-04-23 15:05:37 +02:00
2021-02-25 23:21:30 +01:00
if ( $action == 'checkdispatchline' && ! (( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && empty ( $user -> rights -> fournisseur -> commande -> receptionner )) || ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && empty ( $user -> rights -> fournisseur -> commande_advance -> check )))) {
2019-11-13 19:35:02 +01:00
$error = 0 ;
2015-03-08 02:08:26 +01:00
$supplierorderdispatch = new CommandeFournisseurDispatch ( $db );
2017-08-23 16:07:11 +02:00
$db -> begin ();
2016-08-05 10:02:36 +02:00
$result = $supplierorderdispatch -> fetch ( $lineid );
2021-02-25 23:21:30 +01:00
if ( ! $result ) {
2017-08-23 16:07:11 +02:00
$error ++ ;
2015-03-08 02:08:26 +01:00
setEventMessages ( $supplierorderdispatch -> error , $supplierorderdispatch -> errors , 'errors' );
2016-08-05 10:02:36 +02:00
$action = '' ;
2017-08-23 16:07:11 +02:00
}
2021-02-25 23:21:30 +01:00
if ( ! $error ) {
2017-08-23 16:07:11 +02:00
$result = $supplierorderdispatch -> setStatut ( 1 );
if ( $result < 0 ) {
setEventMessages ( $supplierorderdispatch -> error , $supplierorderdispatch -> errors , 'errors' );
$error ++ ;
$action = '' ;
}
}
2021-02-25 23:21:30 +01:00
if ( ! $error ) {
2016-12-09 11:16:04 +01:00
$result = $object -> calcAndSetStatusDispatch ( $user );
2016-08-05 10:02:36 +02:00
if ( $result < 0 ) {
2016-12-09 11:16:04 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2019-11-13 19:35:02 +01:00
$error ++ ;
2016-08-05 10:02:36 +02:00
$action = '' ;
}
2015-03-08 02:08:26 +01:00
}
2021-02-25 23:21:30 +01:00
if ( ! $error ) {
2017-08-23 16:07:11 +02:00
$db -> commit ();
2020-05-21 15:05:19 +02:00
} else {
2017-08-23 16:07:11 +02:00
$db -> rollback ();
}
2015-03-08 02:08:26 +01:00
}
2021-02-25 23:21:30 +01:00
if ( $action == 'uncheckdispatchline' && ! (( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && empty ( $user -> rights -> fournisseur -> commande -> receptionner )) || ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && empty ( $user -> rights -> fournisseur -> commande_advance -> check )))) {
2019-11-13 19:35:02 +01:00
$error = 0 ;
2015-03-08 02:08:26 +01:00
$supplierorderdispatch = new CommandeFournisseurDispatch ( $db );
2017-08-23 16:07:11 +02:00
$db -> begin ();
2016-08-05 10:02:36 +02:00
$result = $supplierorderdispatch -> fetch ( $lineid );
2021-02-25 23:21:30 +01:00
if ( ! $result ) {
2017-08-23 16:07:11 +02:00
$error ++ ;
2015-03-08 02:08:26 +01:00
setEventMessages ( $supplierorderdispatch -> error , $supplierorderdispatch -> errors , 'errors' );
2016-08-05 10:02:36 +02:00
$action = '' ;
2017-08-23 16:07:11 +02:00
}
2021-02-25 23:21:30 +01:00
if ( ! $error ) {
2017-08-23 16:07:11 +02:00
$result = $supplierorderdispatch -> setStatut ( 0 );
if ( $result < 0 ) {
setEventMessages ( $supplierorderdispatch -> error , $supplierorderdispatch -> errors , 'errors' );
2019-11-13 19:35:02 +01:00
$error ++ ;
2017-08-23 16:07:11 +02:00
$action = '' ;
}
}
2021-02-25 23:21:30 +01:00
if ( ! $error ) {
2016-12-09 11:16:04 +01:00
$result = $object -> calcAndSetStatusDispatch ( $user );
2016-08-05 10:02:36 +02:00
if ( $result < 0 ) {
2016-12-09 11:16:04 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2019-11-13 19:35:02 +01:00
$error ++ ;
2016-08-05 10:02:36 +02:00
$action = '' ;
}
2015-03-08 02:08:26 +01:00
}
2021-02-25 23:21:30 +01:00
if ( ! $error ) {
2017-08-23 16:07:11 +02:00
$db -> commit ();
2020-05-21 15:05:19 +02:00
} else {
2017-08-23 16:07:11 +02:00
$db -> rollback ();
}
2015-03-08 02:08:26 +01:00
}
2021-02-25 23:21:30 +01:00
if ( $action == 'denydispatchline' && ! (( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && empty ( $user -> rights -> fournisseur -> commande -> receptionner )) || ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && empty ( $user -> rights -> fournisseur -> commande_advance -> check )))) {
2019-11-13 19:35:02 +01:00
$error = 0 ;
2015-04-09 15:14:50 +02:00
$supplierorderdispatch = new CommandeFournisseurDispatch ( $db );
2017-08-23 16:07:11 +02:00
$db -> begin ();
2016-08-05 10:02:36 +02:00
$result = $supplierorderdispatch -> fetch ( $lineid );
2021-02-25 23:21:30 +01:00
if ( ! $result ) {
2017-08-23 16:07:11 +02:00
$error ++ ;
2015-04-09 15:14:50 +02:00
setEventMessages ( $supplierorderdispatch -> error , $supplierorderdispatch -> errors , 'errors' );
2016-08-05 10:02:36 +02:00
$action = '' ;
2017-08-23 16:07:11 +02:00
}
2021-02-25 23:21:30 +01:00
if ( ! $error ) {
2017-08-23 16:07:11 +02:00
$result = $supplierorderdispatch -> setStatut ( 2 );
if ( $result < 0 ) {
setEventMessages ( $supplierorderdispatch -> error , $supplierorderdispatch -> errors , 'errors' );
2019-11-13 19:35:02 +01:00
$error ++ ;
2017-08-23 16:07:11 +02:00
$action = '' ;
}
}
2021-02-25 23:21:30 +01:00
if ( ! $error ) {
2016-12-09 11:16:04 +01:00
$result = $object -> calcAndSetStatusDispatch ( $user );
2016-08-05 10:02:36 +02:00
if ( $result < 0 ) {
2016-12-09 11:16:04 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2019-11-13 19:35:02 +01:00
$error ++ ;
2016-08-05 10:02:36 +02:00
$action = '' ;
}
2015-04-09 15:14:50 +02:00
}
2021-02-25 23:21:30 +01:00
if ( ! $error ) {
2017-08-23 16:07:11 +02:00
$db -> commit ();
2020-05-21 15:05:19 +02:00
} else {
2017-08-23 16:07:11 +02:00
$db -> rollback ();
}
2015-04-09 15:14:50 +02:00
}
2016-08-05 10:02:36 +02:00
if ( $action == 'dispatch' && $user -> rights -> fournisseur -> commande -> receptionner ) {
$error = 0 ;
2015-02-10 21:08:02 +01:00
2014-03-01 14:49:30 +01:00
$db -> begin ();
2006-12-11 21:52:01 +01:00
2016-08-05 10:02:36 +02:00
$pos = 0 ;
2021-02-25 23:21:30 +01:00
foreach ( $_POST as $key => $value ) {
2016-08-05 10:02:36 +02:00
// without batch module enabled
2021-01-28 14:13:29 +01:00
$reg = array ();
2021-02-25 23:21:30 +01:00
if ( preg_match ( '/^product_([0-9]+)_([0-9]+)$/i' , $key , $reg )) {
2019-11-13 19:35:02 +01:00
$pos ++ ;
2016-08-05 10:02:36 +02:00
// $numline=$reg[2] + 1; // line of product
$numline = $pos ;
2019-11-13 19:35:02 +01:00
$prod = " product_ " . $reg [ 1 ] . '_' . $reg [ 2 ];
$qty = " qty_ " . $reg [ 1 ] . '_' . $reg [ 2 ];
$ent = " entrepot_ " . $reg [ 1 ] . '_' . $reg [ 2 ];
2021-02-25 23:21:30 +01:00
if ( empty ( GETPOST ( $ent ))) {
$ent = $fk_default_warehouse ;
}
2019-12-19 11:38:19 +01:00
$pu = " pu_ " . $reg [ 1 ] . '_' . $reg [ 2 ]; // This is unit price including discount
2019-11-13 19:35:02 +01:00
$fk_commandefourndet = " fk_commandefourndet_ " . $reg [ 1 ] . '_' . $reg [ 2 ];
2016-08-05 10:02:36 +02:00
2019-11-13 19:35:02 +01:00
if ( ! empty ( $conf -> global -> SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT )) {
2019-07-26 12:38:49 +02:00
if ( empty ( $conf -> multicurrency -> enabled ) && empty ( $conf -> dynamicprices -> enabled )) {
2020-07-17 10:52:52 +02:00
$dto = GETPOST ( " dto_ " . $reg [ 1 ] . '_' . $reg [ 2 ], 'int' );
2019-11-13 19:35:02 +01:00
if ( ! empty ( $dto )) {
$unit_price = price2num ( GETPOST ( " pu_ " . $reg [ 1 ]) * ( 100 - $dto ) / 100 , 'MU' );
2019-07-26 12:38:49 +02:00
}
2019-11-13 19:35:02 +01:00
$saveprice = " saveprice_ " . $reg [ 1 ] . '_' . $reg [ 2 ];
2019-07-26 12:38:49 +02:00
}
}
2016-08-05 10:02:36 +02:00
// We ask to move a qty
2018-04-27 09:14:52 +02:00
if ( GETPOST ( $qty ) != 0 ) {
2019-11-13 19:35:02 +01:00
if ( ! ( GETPOST ( $ent , 'int' ) > 0 )) {
dol_syslog ( 'No dispatch for line ' . $key . ' as no warehouse was chosen.' );
$text = $langs -> transnoentities ( 'Warehouse' ) . ', ' . $langs -> transnoentities ( 'Line' ) . ' ' . ( $numline );
2016-08-05 10:02:36 +02:00
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $text ), null , 'errors' );
2019-11-13 19:35:02 +01:00
$error ++ ;
2015-02-10 21:08:02 +01:00
}
2015-04-02 13:57:20 +02:00
2019-11-13 19:35:02 +01:00
if ( ! $error ) {
2016-12-09 11:16:04 +01:00
$result = $object -> dispatchProduct ( $user , GETPOST ( $prod , 'int' ), GETPOST ( $qty ), GETPOST ( $ent , 'int' ), GETPOST ( $pu ), GETPOST ( 'comment' ), '' , '' , '' , GETPOST ( $fk_commandefourndet , 'int' ), $notrigger );
2016-08-05 10:02:36 +02:00
if ( $result < 0 ) {
2016-12-09 11:16:04 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2019-11-13 19:35:02 +01:00
$error ++ ;
2015-03-08 02:08:26 +01:00
}
2019-07-26 12:38:49 +02:00
2019-11-13 19:35:02 +01:00
if ( ! $error && ! empty ( $conf -> global -> SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT )) {
2019-07-26 12:38:49 +02:00
if ( empty ( $conf -> multicurrency -> enabled ) && empty ( $conf -> dynamicprices -> enabled )) {
2021-01-28 14:21:48 +01:00
$dto = price2num ( GETPOST ( " dto_ " . $reg [ 1 ] . '_' . $reg [ 2 ], 'int' ), '' );
2021-01-28 13:37:43 +01:00
if ( empty ( $dto )) {
$dto = 0 ;
}
2019-07-26 12:38:49 +02:00
//update supplier price
2020-02-16 19:33:58 +01:00
if ( GETPOSTISSET ( $saveprice )) {
2019-07-26 12:38:49 +02:00
// TODO Use class
2019-11-13 19:35:02 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " product_fournisseur_price " ;
2021-01-28 14:13:29 +01:00
$sql .= " SET unitprice=' " . price2num ( GETPOST ( $pu ), 'MU' ) . " ' " ;
$sql .= " , price= " . price2num ( GETPOST ( $pu ), 'MU' ) . " *quantity " ;
2021-01-28 14:21:48 +01:00
$sql .= " , remise_percent = " . (( float ) $dto );
2021-01-28 14:13:29 +01:00
$sql .= " WHERE fk_soc= " . (( int ) $object -> socid );
$sql .= " AND fk_product= " . (( int ) GETPOST ( $prod , 'int' ));
2019-07-26 12:38:49 +02:00
$resql = $db -> query ( $sql );
}
}
}
2015-03-08 02:08:26 +01:00
}
2010-08-26 16:49:40 +02:00
}
2015-02-11 14:46:16 +01:00
}
2016-08-05 10:02:36 +02:00
// with batch module enabled
2021-02-25 23:21:30 +01:00
if ( preg_match ( '/^product_batch_([0-9]+)_([0-9]+)$/i' , $key , $reg )) {
2019-11-13 19:35:02 +01:00
$pos ++ ;
2016-08-05 10:02:36 +02:00
// eat-by date dispatch
// $numline=$reg[2] + 1; // line of product
$numline = $pos ;
2019-11-13 19:35:02 +01:00
$prod = 'product_batch_' . $reg [ 1 ] . '_' . $reg [ 2 ];
$qty = 'qty_' . $reg [ 1 ] . '_' . $reg [ 2 ];
$ent = 'entrepot_' . $reg [ 1 ] . '_' . $reg [ 2 ];
$pu = 'pu_' . $reg [ 1 ] . '_' . $reg [ 2 ];
$fk_commandefourndet = 'fk_commandefourndet_' . $reg [ 1 ] . '_' . $reg [ 2 ];
$lot = 'lot_number_' . $reg [ 1 ] . '_' . $reg [ 2 ];
$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' ]);
2016-08-05 10:02:36 +02:00
2019-11-13 19:35:02 +01:00
$fk_commandefourndet = 'fk_commandefourndet_' . $reg [ 1 ] . '_' . $reg [ 2 ];
2016-08-05 10:02:36 +02:00
2020-07-17 10:50:24 +02:00
if ( ! empty ( $conf -> global -> SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT )) {
if ( empty ( $conf -> multicurrency -> enabled ) && empty ( $conf -> dynamicprices -> enabled )) {
2020-07-17 10:52:52 +02:00
$dto = GETPOST ( " dto_ " . $reg [ 1 ] . '_' . $reg [ 2 ], 'int' );
2020-07-17 10:50:24 +02:00
if ( ! empty ( $dto )) {
$unit_price = price2num ( GETPOST ( " pu_ " . $reg [ 1 ]) * ( 100 - $dto ) / 100 , 'MU' );
}
$saveprice = " saveprice_ " . $reg [ 1 ] . '_' . $reg [ 2 ];
}
}
2016-08-05 10:02:36 +02:00
// We ask to move a qty
if ( GETPOST ( $qty ) > 0 ) {
2019-11-13 19:35:02 +01:00
if ( ! ( GETPOST ( $ent , 'int' ) > 0 )) {
dol_syslog ( 'No dispatch for line ' . $key . ' as no warehouse was chosen.' );
$text = $langs -> transnoentities ( 'Warehouse' ) . ', ' . $langs -> transnoentities ( 'Line' ) . ' ' . ( $numline ) . '-' . ( $reg [ 1 ] + 1 );
2016-08-05 10:02:36 +02:00
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $text ), null , 'errors' );
2019-11-13 19:35:02 +01:00
$error ++ ;
2015-03-08 02:08:26 +01:00
}
2015-02-11 22:54:06 +01:00
2019-11-13 19:35:02 +01:00
if ( ! ( GETPOST ( $lot , 'alpha' ) || $dDLUO || $dDLC )) {
dol_syslog ( 'No dispatch for line ' . $key . ' as serial/eat-by/sellby date are not set' );
$text = $langs -> transnoentities ( 'atleast1batchfield' ) . ', ' . $langs -> transnoentities ( 'Line' ) . ' ' . ( $numline ) . '-' . ( $reg [ 1 ] + 1 );
2016-08-05 10:02:36 +02:00
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $text ), null , 'errors' );
2019-11-13 19:35:02 +01:00
$error ++ ;
2015-02-10 21:08:02 +01:00
}
2015-04-02 13:57:20 +02:00
2019-11-13 19:35:02 +01:00
if ( ! $error ) {
2016-12-09 11:16:04 +01:00
$result = $object -> dispatchProduct ( $user , GETPOST ( $prod , 'int' ), GETPOST ( $qty ), GETPOST ( $ent , 'int' ), GETPOST ( $pu ), GETPOST ( 'comment' ), $dDLC , $dDLUO , GETPOST ( $lot , 'alpha' ), GETPOST ( $fk_commandefourndet , 'int' ), $notrigger );
2016-08-05 10:02:36 +02:00
if ( $result < 0 ) {
2016-12-09 11:16:04 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2019-11-13 19:35:02 +01:00
$error ++ ;
2015-02-11 22:54:06 +01:00
}
2020-07-17 10:50:24 +02:00
if ( ! $error && ! empty ( $conf -> global -> SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT )) {
if ( empty ( $conf -> multicurrency -> enabled ) && empty ( $conf -> dynamicprices -> enabled )) {
2020-07-17 10:52:52 +02:00
$dto = GETPOST ( " dto_ " . $reg [ 1 ] . '_' . $reg [ 2 ], 'int' );
2020-07-17 10:50:24 +02:00
//update supplier price
if ( GETPOSTISSET ( $saveprice )) {
// TODO Use class
$sql = " UPDATE " . MAIN_DB_PREFIX . " product_fournisseur_price " ;
$sql .= " SET unitprice=' " . GETPOST ( $pu ) . " ' " ;
$sql .= " , price= " . GETPOST ( $pu ) . " *quantity " ;
2020-10-31 14:32:18 +01:00
$sql .= " , remise_percent=' " . ( ! empty ( $dto ) ? $dto : 0 ) . " ' " ;
2020-07-17 10:50:24 +02:00
$sql .= " WHERE fk_soc= " . $object -> socid ;
$sql .= " AND fk_product= " . GETPOST ( $prod , 'int' );
$resql = $db -> query ( $sql );
}
}
}
2015-02-11 22:54:06 +01:00
}
2015-02-10 21:08:02 +01:00
}
2008-11-16 02:54:33 +01:00
}
2006-12-11 21:52:01 +01:00
}
2013-03-24 21:06:45 +01:00
2019-11-13 19:35:02 +01:00
if ( ! $error ) {
$result = $object -> calcAndSetStatusDispatch ( $user , GETPOST ( 'closeopenorder' ) ? 1 : 0 , GETPOST ( 'comment' ));
2016-08-05 10:02:36 +02:00
if ( $result < 0 ) {
2016-12-09 11:16:04 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2019-11-13 19:35:02 +01:00
$error ++ ;
2016-08-05 09:46:17 +02:00
}
}
2019-11-13 19:35:02 +01:00
if ( ! $notrigger && ! $error ) {
2013-02-25 16:56:37 +01:00
global $conf , $langs , $user ;
2016-08-05 10:02:36 +02:00
// Call trigger
2016-08-05 09:46:17 +02:00
2016-12-09 11:16:04 +01:00
$result = $object -> call_trigger ( 'ORDER_SUPPLIER_DISPATCH' , $user );
2016-08-05 10:02:36 +02:00
// End call triggers
2015-02-10 21:08:02 +01:00
2016-08-05 10:02:36 +02:00
if ( $result < 0 ) {
2016-12-09 11:16:04 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2019-11-13 19:35:02 +01:00
$error ++ ;
2015-02-10 21:08:02 +01:00
}
2013-02-25 16:56:37 +01:00
}
2006-12-11 21:52:01 +01:00
2019-11-13 19:35:02 +01:00
if ( $result >= 0 && ! $error ) {
2014-03-01 14:49:30 +01:00
$db -> commit ();
2019-11-13 19:35:02 +01:00
header ( " Location: dispatch.php?id= " . $id );
2016-08-05 10:02:36 +02:00
exit ();
} else {
2014-03-01 14:49:30 +01:00
$db -> rollback ();
2010-05-28 22:41:41 +02:00
}
2006-12-11 21:52:01 +01:00
}
2020-05-19 14:18:06 +02:00
// Remove a dispatched line
2021-02-25 23:21:30 +01:00
if ( $action == 'confirm_deleteline' && $confirm == 'yes' && $user -> rights -> fournisseur -> commande -> receptionner ) {
2020-05-19 15:59:03 +02:00
$db -> begin ();
2020-05-19 14:18:06 +02:00
$supplierorderdispatch = new CommandeFournisseurDispatch ( $db );
$result = $supplierorderdispatch -> fetch ( $lineid );
2021-02-25 23:21:30 +01:00
if ( $result > 0 ) {
2020-05-19 15:59:03 +02:00
$qty = $supplierorderdispatch -> qty ;
$entrepot = $supplierorderdispatch -> fk_entrepot ;
$product = $supplierorderdispatch -> fk_product ;
2021-05-10 11:30:37 +02:00
$price = price2num ( GETPOST ( 'price' , 'alpha' ), 'MU' );
2020-05-19 15:59:03 +02:00
$comment = $supplierorderdispatch -> comment ;
2021-03-15 18:10:59 +01:00
$eatby = $supplierorderdispatch -> eatby ;
2020-05-19 15:59:03 +02:00
$sellby = $supplierorderdispatch -> sellby ;
$batch = $supplierorderdispatch -> batch ;
$result = $supplierorderdispatch -> delete ( $user );
}
2021-02-25 23:21:30 +01:00
if ( $result < 0 ) {
2020-05-19 15:59:03 +02:00
$errors = $object -> errors ;
$error ++ ;
2021-02-25 23:21:30 +01:00
} else {
2020-05-19 15:59:03 +02:00
// If module stock is enabled and the stock increase is done on purchase order dispatching
2021-05-08 12:42:58 +02:00
if ( $entrepot > 0 && ! empty ( $conf -> stock -> enabled ) && ! empty ( $conf -> global -> STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER ) && empty ( $supplierorderdispatch -> fk_reception )) {
2020-05-19 15:59:03 +02:00
$mouv = new MouvementStock ( $db );
2021-02-25 23:21:30 +01:00
if ( $product > 0 ) {
2020-05-19 15:59:03 +02:00
$mouv -> origin = & $object ;
2020-10-31 14:32:18 +01:00
$result = $mouv -> livraison ( $user , $product , $entrepot , $qty , $price , $comment , '' , $eatby , $sellby , $batch );
2021-02-25 23:21:30 +01:00
if ( $result < 0 ) {
2020-10-31 14:32:18 +01:00
$errors = $mouv -> errors ;
2020-05-19 15:59:03 +02:00
$error ++ ;
}
}
}
}
2021-02-25 23:21:30 +01:00
if ( $error > 0 ) {
2020-05-19 15:59:03 +02:00
$db -> rollback ();
setEventMessages ( $error , $errors , 'errors' );
2021-02-25 23:21:30 +01:00
} else {
2020-05-19 15:59:03 +02:00
$db -> commit ();
2020-05-19 14:18:06 +02:00
}
}
// Update a dispatched line
2021-02-25 23:21:30 +01:00
if ( $action == 'updateline' && $user -> rights -> fournisseur -> commande -> receptionner ) {
2020-05-19 15:59:03 +02:00
$db -> begin ();
$error = 0 ;
2020-05-19 14:18:06 +02:00
$supplierorderdispatch = new CommandeFournisseurDispatch ( $db );
$result = $supplierorderdispatch -> fetch ( $lineid );
2021-02-25 23:21:30 +01:00
if ( $result > 0 ) {
2020-05-19 15:59:03 +02:00
$qty = $supplierorderdispatch -> qty ;
$entrepot = $supplierorderdispatch -> fk_entrepot ;
$product = $supplierorderdispatch -> fk_product ;
2021-03-02 23:09:55 +01:00
$price = price2num ( GETPOST ( 'price' ), '' , 2 );
2020-05-19 15:59:03 +02:00
$comment = $supplierorderdispatch -> comment ;
2021-05-27 16:03:17 +02:00
$eatby = $supplierorderdispatch -> eatby ;
2020-05-19 15:59:03 +02:00
$sellby = $supplierorderdispatch -> sellby ;
$batch = $supplierorderdispatch -> batch ;
2021-03-02 23:09:55 +01:00
$supplierorderdispatch -> qty = price2num ( GETPOST ( 'qty' , 'alpha' ), 'MS' , 2 );
2020-05-19 14:18:06 +02:00
$supplierorderdispatch -> fk_entrepot = GETPOST ( 'fk_entrepot' );
$result = $supplierorderdispatch -> update ( $user );
}
2021-02-25 23:21:30 +01:00
if ( $result < 0 ) {
2020-05-19 15:59:03 +02:00
$error ++ ;
2020-10-31 14:32:18 +01:00
$errors = $supplierorderdispatch -> errors ;
2021-02-25 23:21:30 +01:00
} else {
2020-05-19 15:59:03 +02:00
// If module stock is enabled and the stock increase is done on purchase order dispatching
2021-02-25 23:21:30 +01:00
if ( $entrepot > 0 && ! empty ( $conf -> stock -> enabled ) && ! empty ( $conf -> global -> STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER )) {
2020-05-19 15:59:03 +02:00
$mouv = new MouvementStock ( $db );
2021-02-25 23:21:30 +01:00
if ( $product > 0 ) {
2020-05-19 15:59:03 +02:00
$mouv -> origin = & $object ;
2020-10-31 14:32:18 +01:00
$result = $mouv -> livraison ( $user , $product , $entrepot , $qty , $price , $comment , '' , $eatby , $sellby , $batch );
2021-02-25 23:21:30 +01:00
if ( $result < 0 ) {
2020-10-31 14:32:18 +01:00
$errors = $mouv -> errors ;
2020-05-19 15:59:03 +02:00
$error ++ ;
2021-02-25 23:21:30 +01:00
} else {
2020-05-19 15:59:03 +02:00
$mouv -> origin = & $object ;
2020-10-31 14:32:18 +01:00
$result = $mouv -> reception ( $user , $product , $supplierorderdispatch -> fk_entrepot , $supplierorderdispatch -> qty , $price , $comment , $eatby , $sellby , $batch );
2021-02-25 23:21:30 +01:00
if ( $result < 0 ) {
2020-10-31 14:32:18 +01:00
$errors = $mouv -> errors ;
2020-05-19 15:59:03 +02:00
$error ++ ;
}
}
}
}
}
2021-02-25 23:21:30 +01:00
if ( $error > 0 ) {
2020-05-19 15:59:03 +02:00
$db -> rollback ();
setEventMessages ( $error , $errors , 'errors' );
2021-02-25 23:21:30 +01:00
} else {
2020-05-19 15:59:03 +02:00
$db -> commit ();
2020-05-19 14:18:06 +02:00
}
}
2017-06-27 13:57:41 +02:00
2008-06-14 12:01:31 +02:00
/*
* View
*/
2016-08-09 13:26:08 +02:00
$now = dol_now ();
2016-08-05 10:02:36 +02:00
$form = new Form ( $db );
2015-12-18 18:00:31 +01:00
$formproduct = new FormProduct ( $db );
2015-02-24 11:19:47 +01:00
$warehouse_static = new Entrepot ( $db );
$supplierorderdispatch = new CommandeFournisseurDispatch ( $db );
2019-11-13 19:35:02 +01:00
$help_url = 'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores' ;
2021-02-16 11:15:42 +01:00
$morejs = array ( '/fourn/js/lib_dispatch.js.php' );
llxHeader ( '' , $langs -> trans ( " OrderDispatch " ), $help_url , '' , 0 , 0 , $morejs );
2016-08-05 10:02:36 +02:00
2019-11-13 19:35:02 +01:00
if ( $id > 0 || ! empty ( $ref )) {
2016-08-05 10:02:36 +02:00
$soc = new Societe ( $db );
2016-12-09 11:16:04 +01:00
$soc -> fetch ( $object -> socid );
2016-08-05 10:02:36 +02:00
$author = new User ( $db );
2016-12-09 11:16:04 +01:00
$author -> fetch ( $object -> user_author_id );
2016-08-05 10:02:36 +02:00
2016-12-09 11:16:04 +01:00
$head = ordersupplier_prepare_head ( $object );
2016-08-05 10:02:36 +02:00
$title = $langs -> trans ( " SupplierOrder " );
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'dispatch' , $title , - 1 , 'order' );
2017-06-27 13:57:41 +02:00
2020-10-31 14:32:18 +01:00
$formconfirm = '' ;
2020-05-19 14:18:06 +02:00
// Confirmation to delete line
2021-02-25 23:21:30 +01:00
if ( $action == 'ask_deleteline' ) {
2020-10-31 14:32:18 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&lineid=' . $lineid , $langs -> trans ( 'DeleteLine' ), $langs -> trans ( 'ConfirmDeleteLine' ), 'confirm_deleteline' , '' , 0 , 1 );
2020-05-19 14:18:06 +02:00
}
// Call Hook formConfirm
$parameters = array ( 'lineid' => $lineid );
// Note that $action and $object may be modified by hook
$reshook = $hookmanager -> executeHooks ( 'formConfirm' , $parameters , $object , $action );
2021-02-25 23:21:30 +01:00
if ( empty ( $reshook )) {
$formconfirm .= $hookmanager -> resPrint ;
} elseif ( $reshook > 0 ) {
$formconfirm = $hookmanager -> resPrint ;
}
2020-05-19 14:18:06 +02:00
// Print form confirm
print $formconfirm ;
2016-08-05 10:02:36 +02:00
2016-12-09 11:16:04 +01:00
// Supplier order card
2019-11-13 19:35:02 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/fourn/commande/list.php' . ( ! empty ( $socid ) ? '?socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2017-06-27 13:57:41 +02:00
2019-11-13 19:35:02 +01:00
$morehtmlref = '<div class="refidno">' ;
2016-12-09 11:16:04 +01:00
// Ref supplier
2019-11-13 19:35:02 +01:00
$morehtmlref .= $form -> editfieldkey ( " RefSupplier " , 'ref_supplier' , $object -> ref_supplier , $object , 0 , 'string' , '' , 0 , 1 );
$morehtmlref .= $form -> editfieldval ( " RefSupplier " , 'ref_supplier' , $object -> ref_supplier , $object , 0 , 'string' , '' , null , null , '' , 1 );
2016-12-09 11:16:04 +01:00
// Thirdparty
2019-11-13 19:35:02 +01:00
$morehtmlref .= '<br>' . $langs -> trans ( 'ThirdParty' ) . ' : ' . $object -> thirdparty -> getNomUrl ( 1 );
2016-12-09 11:16:04 +01:00
// Project
2021-02-25 23:21:30 +01:00
if ( ! empty ( $conf -> projet -> enabled )) {
2020-09-07 10:18:17 +02:00
$langs -> load ( " projects " );
$morehtmlref .= '<br>' . $langs -> trans ( 'Project' ) . ' ' ;
2021-04-12 09:47:16 +02:00
if ( $user -> rights -> fournisseur -> commande -> creer || $user -> rights -> supplier_order -> creer ) {
2020-09-07 10:18:17 +02:00
if ( $action != 'classify' ) {
//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
2019-11-13 19:35:02 +01:00
$morehtmlref .= ' : ' ;
2020-09-07 10:18:17 +02:00
}
if ( $action == 'classify' ) {
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
$morehtmlref .= '<form method="post" action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '">' ;
$morehtmlref .= '<input type="hidden" name="action" value="classin">' ;
$morehtmlref .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
$morehtmlref .= $formproject -> select_projects ( $object -> socid , $object -> fk_project , 'projectid' , $maxlength , 0 , 1 , 0 , 1 , 0 , 0 , '' , 1 );
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
$morehtmlref .= '</form>' ;
} else {
$morehtmlref .= $form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> socid , $object -> fk_project , 'none' , 0 , 0 , 0 , 1 );
}
} else {
if ( ! empty ( $object -> fk_project )) {
$proj = new Project ( $db );
$proj -> fetch ( $object -> fk_project );
$morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $object -> fk_project . '" title="' . $langs -> trans ( 'ShowProject' ) . '">' ;
$morehtmlref .= $proj -> ref ;
$morehtmlref .= '</a>' ;
} else {
$morehtmlref .= '' ;
}
}
2016-12-09 11:16:04 +01:00
}
2019-11-13 19:35:02 +01:00
$morehtmlref .= '</div>' ;
2017-06-27 13:57:41 +02:00
dol_banner_tab ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' , $morehtmlref );
2016-12-09 11:16:04 +01:00
print '<div class="fichecenter">' ;
print '<div class="underbanner clearboth"></div>' ;
2017-06-27 13:57:41 +02:00
2019-09-05 15:30:14 +02:00
print '<table class="border tableforfield" width="100%">' ;
2016-08-05 10:02:36 +02:00
// Date
2016-12-09 11:16:04 +01:00
if ( $object -> methode_commande_id > 0 ) {
2019-11-13 19:35:02 +01:00
print '<tr><td class="titlefield">' . $langs -> trans ( " Date " ) . '</td><td>' ;
2016-12-09 11:16:04 +01:00
if ( $object -> date_commande ) {
2019-11-13 19:35:02 +01:00
print dol_print_date ( $object -> date_commande , " dayhour " ) . " \n " ;
2016-08-05 10:02:36 +02:00
}
print " </td></tr> " ;
2015-02-24 11:19:47 +01:00
2016-12-09 11:16:04 +01:00
if ( $object -> methode_commande ) {
2019-11-13 19:35:02 +01:00
print '<tr><td>' . $langs -> trans ( " Method " ) . '</td><td>' . $object -> getInputMethod () . '</td></tr>' ;
2016-08-05 10:02:36 +02:00
}
}
2006-12-11 21:52:01 +01:00
2017-11-12 19:39:02 +01:00
// Author
2019-11-13 19:35:02 +01:00
print '<tr><td class="titlefield">' . $langs -> trans ( " AuthorRequest " ) . '</td>' ;
print '<td>' . $author -> getNomUrl ( 1 , '' , 0 , 0 , 0 ) . '</td>' ;
2016-08-05 10:02:36 +02:00
print '</tr>' ;
2006-12-11 21:52:01 +01:00
2020-09-07 10:18:17 +02:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2018-04-23 15:05:37 +02:00
2016-08-05 10:02:36 +02:00
print " </table> " ;
2008-11-16 02:54:33 +01:00
2016-12-09 11:16:04 +01:00
print '</div>' ;
2017-06-27 13:57:41 +02:00
2016-08-05 10:02:36 +02:00
// if ($mesg) print $mesg;
print '<br>' ;
2009-01-31 01:06:19 +01:00
2016-08-05 10:02:36 +02:00
$disabled = 1 ;
2021-02-25 23:21:30 +01:00
if ( ! empty ( $conf -> global -> STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER )) {
2016-08-05 10:02:36 +02:00
$disabled = 0 ;
2021-02-25 23:21:30 +01:00
}
2008-11-16 02:54:33 +01:00
2016-12-09 11:16:04 +01:00
// Line of orders
2017-11-12 19:39:02 +01:00
if ( $object -> statut <= CommandeFournisseur :: STATUS_ACCEPTED || $object -> statut >= CommandeFournisseur :: STATUS_CANCELED ) {
2019-09-05 15:30:14 +02:00
print '<br><span class="opacitymedium">' . $langs -> trans ( " OrderStatusNotReadyToDispatch " ) . '</span>' ;
2016-08-05 10:02:36 +02:00
}
2008-11-16 02:54:33 +01:00
2017-11-12 19:39:02 +01:00
if ( $object -> statut == CommandeFournisseur :: STATUS_ORDERSENT
|| $object -> statut == CommandeFournisseur :: STATUS_RECEIVED_PARTIALLY
2021-02-25 23:21:30 +01:00
|| $object -> statut == CommandeFournisseur :: STATUS_RECEIVED_COMPLETELY ) {
2019-05-01 11:10:11 +02:00
require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php' ;
$formproduct = new FormProduct ( $db );
$formproduct -> loadWarehouses ();
2020-05-19 14:18:06 +02:00
$entrepot = new Entrepot ( $db );
2020-10-31 14:32:18 +01:00
$listwarehouses = $entrepot -> list_array ( 1 );
2020-05-19 14:18:06 +02:00
2009-01-31 01:06:19 +01:00
2021-02-25 23:21:30 +01:00
if ( empty ( $conf -> reception -> enabled )) {
print '<form method="POST" action="dispatch.php?id=' . $object -> id . '">' ;
} else {
print '<form method="post" action="' . dol_buildpath ( '/reception/card.php' , 1 ) . '?originid=' . $object -> id . '&origin=supplierorder">' ;
}
2019-02-03 14:29:45 +01:00
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2021-02-25 23:21:30 +01:00
if ( empty ( $conf -> reception -> enabled )) {
print '<input type="hidden" name="action" value="dispatch">' ;
} else {
print '<input type="hidden" name="action" value="create">' ;
}
2017-06-27 13:57:41 +02:00
2018-03-09 23:49:40 +01:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2009-01-31 01:06:19 +01:00
2016-08-05 10:02:36 +02:00
// Set $products_dispatched with qty dispatched for each product id
$products_dispatched = array ();
$sql = " SELECT l.rowid, cfd.fk_product, sum(cfd.qty) as qty " ;
2019-11-13 19:35:02 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " commande_fournisseur_dispatch as cfd " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " commande_fournisseurdet as l on l.rowid = cfd.fk_commandefourndet " ;
$sql .= " WHERE cfd.fk_commande = " . $object -> id ;
2016-08-05 10:02:36 +02:00
$sql .= " GROUP BY l.rowid, cfd.fk_product " ;
2008-11-16 02:54:33 +01:00
2016-08-05 10:02:36 +02:00
$resql = $db -> query ( $sql );
if ( $resql ) {
$num = $db -> num_rows ( $resql );
$i = 0 ;
2008-11-16 02:54:33 +01:00
2016-08-05 10:02:36 +02:00
if ( $num ) {
2019-11-13 19:35:02 +01:00
while ( $i < $num ) {
2016-08-05 10:02:36 +02:00
$objd = $db -> fetch_object ( $resql );
$products_dispatched [ $objd -> rowid ] = price2num ( $objd -> qty , 5 );
2016-12-09 11:16:04 +01:00
$i ++ ;
2016-08-05 10:02:36 +02:00
}
2008-11-16 02:54:33 +01:00
}
2016-08-05 10:02:36 +02:00
$db -> free ( $resql );
2006-12-11 21:52:01 +01:00
}
2008-11-16 02:54:33 +01:00
2018-06-29 19:17:44 +02:00
$sql = " SELECT l.rowid, l.fk_product, l.subprice, l.remise_percent, l.ref AS sref, SUM(l.qty) as qty, " ;
2018-03-28 11:54:21 +02:00
$sql .= " p.ref, p.label, p.tobatch, p.fk_default_warehouse " ;
2019-09-05 15:30:14 +02:00
2020-09-07 10:18:17 +02:00
// Enable hooks to alter the SQL query (SELECT)
$parameters = array ();
$reshook = $hookmanager -> executeHooks (
'printFieldListSelect' ,
$parameters ,
$object ,
$action
);
2021-02-25 23:21:30 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2020-09-07 10:18:17 +02:00
$sql .= $hookmanager -> resPrint ;
2019-09-05 15:30:14 +02:00
2019-11-13 19:35:02 +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 = " . $object -> id ;
2021-02-25 23:21:30 +01:00
if ( empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES )) {
2016-08-05 10:02:36 +02:00
$sql .= " AND l.product_type = 0 " ;
2021-02-25 23:21:30 +01:00
}
2019-09-05 15:30:14 +02:00
2020-09-07 10:18:17 +02:00
// Enable hooks to alter the SQL query (WHERE)
$parameters = array ();
$reshook = $hookmanager -> executeHooks (
'printFieldListWhere' ,
$parameters ,
$object ,
$action
);
2021-02-25 23:21:30 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2020-09-07 10:18:17 +02:00
$sql .= $hookmanager -> resPrint ;
2019-09-05 15:30:14 +02:00
2021-02-09 20:46:17 +01:00
$sql .= " GROUP BY p.ref, p.label, p.tobatch, p.fk_default_warehouse, l.rowid, l.fk_product, l.subprice, l.remise_percent, l.ref " ; // Calculation of amount dispatched is done per fk_product so we must group by fk_product
2016-08-05 10:02:36 +02:00
$sql .= " ORDER BY p.ref, p.label " ;
2008-11-16 02:54:33 +01:00
2016-08-05 10:02:36 +02:00
$resql = $db -> query ( $sql );
if ( $resql ) {
$num = $db -> num_rows ( $resql );
$i = 0 ;
2010-08-26 16:49:40 +02:00
2016-08-05 10:02:36 +02:00
if ( $num ) {
print '<tr class="liste_titre">' ;
2008-11-16 02:54:33 +01:00
2019-11-13 19:35:02 +01:00
print '<td>' . $langs -> trans ( " Description " ) . '</td>' ;
2020-05-23 21:07:47 +02:00
if ( ! empty ( $conf -> productbatch -> enabled )) {
2018-08-29 14:12:17 +02:00
print '<td class="dispatch_batch_number_title">' . $langs -> trans ( " batch_number " ) . '</td>' ;
2020-07-13 13:08:15 +02:00
if ( empty ( $conf -> global -> PRODUCT_DISABLE_EATBY )) {
print '<td class="dispatch_dluo_title">' . $langs -> trans ( " EatByDate " ) . '</td>' ;
}
if ( empty ( $conf -> global -> PRODUCT_DISABLE_SELLBY )) {
print '<td class="dispatch_dlc_title">' . $langs -> trans ( " SellByDate " ) . '</td>' ;
}
2020-05-21 15:05:19 +02:00
} else {
2018-08-30 18:57:30 +02:00
print '<td></td>' ;
print '<td></td>' ;
print '<td></td>' ;
}
2019-11-13 19:35:02 +01:00
print '<td class="right">' . $langs -> trans ( " SupplierRef " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " QtyOrdered " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " QtyDispatchedShort " ) . '</td>' ;
2020-08-03 21:31:39 +02:00
print ' <td class="right">' . $langs -> trans ( " QtyToDispatchShort " );
2020-09-07 10:18:17 +02:00
print '<br><a href="#" id="autoreset">' . $langs -> trans ( " Reset " ) . '</a></td>' ;
2017-06-27 13:57:41 +02:00
print '<td width="32"></td>' ;
2019-07-26 12:38:49 +02:00
2019-11-13 19:35:02 +01:00
if ( ! empty ( $conf -> global -> SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT )) {
2019-07-26 12:38:49 +02:00
if ( empty ( $conf -> multicurrency -> enabled ) && empty ( $conf -> dynamicprices -> enabled )) {
2019-11-13 19:35:02 +01:00
print '<td class="right">' . $langs -> trans ( " Price " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " ReductionShort " ) . ' (%)</td>' ;
print '<td class="right">' . $langs -> trans ( " UpdatePrice " ) . '</td>' ;
2019-07-26 12:38:49 +02:00
}
}
2019-12-19 12:05:34 +01:00
print '<td align="right">' . $langs -> trans ( " Warehouse " );
// Select warehouse to force it everywhere
2020-05-23 21:07:47 +02:00
if ( count ( $listwarehouses ) > 1 ) {
2020-12-03 19:13:40 +01:00
print '<br>' . $langs -> trans ( " ForceTo " ) . ' ' . $form -> selectarray ( 'fk_default_warehouse' , $listwarehouses , $fk_default_warehouse , 1 , 0 , 0 , '' , 0 , 0 , $disabled , '' , 'minwidth100 maxwidth300' , 1 );
2020-05-23 21:07:47 +02:00
} elseif ( count ( $listwarehouses ) == 1 ) {
2020-12-03 19:13:40 +01:00
print '<br>' . $langs -> trans ( " ForceTo " ) . ' ' . $form -> selectarray ( 'fk_default_warehouse' , $listwarehouses , $fk_default_warehouse , 0 , 0 , 0 , '' , 0 , 0 , $disabled , '' , 'minwidth100 maxwidth300' , 1 );
2019-12-19 12:05:34 +01:00
}
print '</td>' ;
2019-09-05 15:30:14 +02:00
2020-09-07 10:18:17 +02:00
// Enable hooks to append additional columns
$parameters = array ();
$reshook = $hookmanager -> executeHooks (
'printFieldListTitle' ,
$parameters ,
$object ,
$action
);
2021-02-25 23:21:30 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2020-09-07 10:18:17 +02:00
print $hookmanager -> resPrint ;
2019-09-05 15:30:14 +02:00
2016-08-05 10:02:36 +02:00
print " </tr> \n " ;
}
2008-11-16 02:54:33 +01:00
2019-11-13 19:35:02 +01:00
$nbfreeproduct = 0 ; // Nb of lins of free products/services
$nbproduct = 0 ; // Nb of predefined product lines to dispatch (already done or not) if SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED is off (default)
2016-12-09 11:16:04 +01:00
// or nb of line that remain to dispatch if SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED is on.
2008-11-16 02:54:33 +01:00
2019-11-13 19:35:02 +01:00
while ( $i < $num ) {
2016-08-05 10:02:36 +02:00
$objp = $db -> fetch_object ( $resql );
2010-05-28 23:52:51 +02:00
2017-06-27 13:57:41 +02:00
// On n'affiche pas les produits libres
2019-11-13 19:35:02 +01:00
if ( ! $objp -> fk_product > 0 ) {
2016-12-09 11:16:04 +01:00
$nbfreeproduct ++ ;
2016-08-05 10:02:36 +02:00
} else {
2019-11-13 19:35:02 +01:00
$remaintodispatch = price2num ( $objp -> qty - (( float ) $products_dispatched [ $objp -> rowid ]), 5 ); // Calculation of dispatched
2021-02-25 23:21:30 +01:00
if ( $remaintodispatch < 0 ) {
2016-08-05 10:02:36 +02:00
$remaintodispatch = 0 ;
2021-02-25 23:21:30 +01:00
}
2015-02-11 22:54:06 +01:00
2016-08-05 10:02:36 +02:00
if ( $remaintodispatch || empty ( $conf -> global -> SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED )) {
2016-12-09 11:16:04 +01:00
$nbproduct ++ ;
2014-03-01 14:49:30 +01:00
2016-08-05 10:02:36 +02: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);
2019-11-13 19:35:02 +01:00
$suffix = '_0_' . $i ;
2013-11-14 17:08:59 +01:00
2016-08-05 10:02:36 +02:00
print " \n " ;
2019-11-13 19:35:02 +01:00
print '<!-- Line to dispatch ' . $suffix . ' -->' . " \n " ;
2017-09-26 16:21:28 +02:00
// hidden fields for js function
2019-11-13 19:35:02 +01:00
print '<input id="qty_ordered' . $suffix . '" type="hidden" value="' . $objp -> qty . '">' ;
print '<input id="qty_dispatched' . $suffix . '" type="hidden" value="' . ( float ) $products_dispatched [ $objp -> rowid ] . '">' ;
2017-05-04 17:48:52 +02:00
print '<tr class="oddeven">' ;
2015-02-11 22:54:06 +01:00
2019-11-13 19:35:02 +01:00
$linktoprod = '<a href="' . DOL_URL_ROOT . '/product/fournisseurs.php?id=' . $objp -> fk_product . '">' . img_object ( $langs -> trans ( " ShowProduct " ), 'product' ) . ' ' . $objp -> ref . '</a>' ;
$linktoprod .= ' - ' . $objp -> label . " \n " ;
2015-02-19 00:01:26 +01:00
2019-11-13 19:35:02 +01:00
if ( ! empty ( $conf -> productbatch -> enabled )) {
2016-08-05 10:02:36 +02:00
if ( $objp -> tobatch ) {
2018-08-29 14:12:17 +02:00
print '<td>' ;
2016-08-05 10:02:36 +02:00
print $linktoprod ;
print " </td> " ;
2018-08-29 14:12:17 +02:00
print '<td class="dispatch_batch_number"></td>' ;
2020-07-13 13:08:15 +02:00
if ( empty ( $conf -> global -> PRODUCT_DISABLE_EATBY )) {
print '<td class="dispatch_dluo"></td>' ;
}
if ( empty ( $conf -> global -> PRODUCT_DISABLE_SELLBY )) {
print '<td class="dispatch_dlc"></td>' ;
}
2016-08-05 10:02:36 +02:00
} else {
2015-02-11 22:54:06 +01:00
print '<td>' ;
2016-08-05 10:02:36 +02:00
print $linktoprod ;
print " </td> " ;
2018-08-29 14:12:17 +02:00
print '<td class="dispatch_batch_number">' ;
2016-08-05 10:02:36 +02:00
print $langs -> trans ( " ProductDoesNotUseBatchSerial " );
2015-12-18 18:00:31 +01:00
print '</td>' ;
2020-07-13 13:08:15 +02:00
if ( empty ( $conf -> global -> PRODUCT_DISABLE_EATBY )) {
print '<td class="dispatch_dluo"></td>' ;
}
if ( empty ( $conf -> global -> PRODUCT_DISABLE_SELLBY )) {
print '<td class="dispatch_dlc"></td>' ;
}
2015-02-11 22:54:06 +01:00
}
2016-08-05 10:02:36 +02:00
} else {
print '<td colspan="4">' ;
print $linktoprod ;
print " </td> " ;
}
2017-05-04 17:48:52 +02:00
// Define unit price for PMP calculation
2016-08-05 10:02:36 +02:00
$up_ht_disc = $objp -> subprice ;
2021-02-25 23:21:30 +01:00
if ( ! empty ( $objp -> remise_percent ) && empty ( $conf -> global -> STOCK_EXCLUDE_DISCOUNT_FOR_PMP )) {
2016-08-05 10:02:36 +02:00
$up_ht_disc = price2num ( $up_ht_disc * ( 100 - $objp -> remise_percent ) / 100 , 'MU' );
2021-02-25 23:21:30 +01:00
}
2016-08-05 10:02:36 +02:00
2018-06-20 14:40:32 +02:00
// Supplier ref
2019-09-05 15:33:16 +02:00
print '<td class="right">' . $objp -> sref . '</td>' ;
2018-08-30 18:57:30 +02:00
2016-12-09 11:16:04 +01:00
// Qty ordered
2019-11-13 19:35:02 +01:00
print '<td class="right">' . $objp -> qty . '</td>' ;
2016-08-05 10:02:36 +02:00
// Already dispatched
2019-11-13 19:35:02 +01:00
print '<td class="right">' . $products_dispatched [ $objp -> rowid ] . '</td>' ;
2016-08-05 10:02:36 +02:00
2021-03-04 15:31:51 +01:00
if ( ! empty ( $conf -> productbatch -> enabled ) && $objp -> tobatch > 0 ) {
2016-08-05 10:02:36 +02:00
$type = 'batch' ;
2019-03-07 20:46:38 +01:00
print '<td class="right">' ;
2019-11-13 19:35:02 +01:00
print '</td>' ; // Qty to dispatch
2017-06-27 13:57:41 +02:00
print '<td>' ;
//print img_picto($langs->trans('AddDispatchBatchLine'), 'split.png', 'onClick="addDispatchLine(' . $i . ',\'' . $type . '\')"');
2019-11-13 19:35:02 +01:00
print '</td>' ; // Dispatch column
2016-08-05 10:02:36 +02:00
print '<td></td>' ; // Warehouse column
2019-09-05 15:30:14 +02:00
2020-09-07 10:18:17 +02:00
// Enable hooks to append additional columns
$parameters = array (
'is_information_row' => true , // allows hook to distinguish between the
// rows with information and the rows with
// dispatch form input
'objp' => $objp
);
$reshook = $hookmanager -> executeHooks (
'printFieldListValue' ,
$parameters ,
$object ,
$action
);
2021-02-25 23:21:30 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2020-09-07 10:18:17 +02:00
print $hookmanager -> resPrint ;
2019-09-05 15:30:14 +02:00
2016-08-05 10:02:36 +02:00
print '</tr>' ;
2019-11-13 19:35:02 +01:00
print '<tr class="oddeven" name="' . $type . $suffix . '">' ;
2016-08-05 10:02:36 +02:00
print '<td>' ;
2019-11-13 19:35:02 +01:00
print '<input name="fk_commandefourndet' . $suffix . '" type="hidden" value="' . $objp -> rowid . '">' ;
print '<input name="product_batch' . $suffix . '" type="hidden" value="' . $objp -> fk_product . '">' ;
2017-06-27 13:57:41 +02:00
2017-05-04 17:48:52 +02:00
print '<!-- This is a up (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->' ;
2021-02-25 23:21:30 +01:00
if ( ! empty ( $conf -> global -> SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT )) { // Not tested !
2020-09-07 10:18:17 +02:00
print $langs -> trans ( " BuyingPrice " ) . ': <input class="maxwidth75" name="pu' . $suffix . '" type="text" value="' . price2num ( $up_ht_disc , 'MU' ) . '">' ;
2020-05-21 15:05:19 +02:00
} else {
2020-09-07 10:18:17 +02:00
print '<input class="maxwidth75" name="pu' . $suffix . '" type="hidden" value="' . price2num ( $up_ht_disc , 'MU' ) . '">' ;
2017-05-04 17:48:52 +02:00
}
2015-02-11 22:54:06 +01:00
print '</td>' ;
2013-11-14 17:08:59 +01:00
2016-08-05 10:02:36 +02:00
print '<td>' ;
2019-11-13 19:35:02 +01:00
print '<input type="text" class="inputlotnumber quatrevingtquinzepercent" id="lot_number' . $suffix . '" name="lot_number' . $suffix . '" value="' . GETPOST ( 'lot_number' . $suffix ) . '">' ;
2016-08-05 10:02:36 +02:00
print '</td>' ;
2020-07-13 13:08:15 +02:00
if ( empty ( $conf -> global -> PRODUCT_DISABLE_EATBY )) {
print '<td class="nowraponall">' ;
2020-10-31 14:32:18 +01:00
$dlcdatesuffix = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'dlc' . $suffix . 'month' ), GETPOST ( 'dlc' . $suffix . 'day' ), GETPOST ( 'dlc' . $suffix . 'year' ));
print $form -> selectDate ( $dlcdatesuffix , 'dlc' . $suffix , '' , '' , 1 , '' );
2020-07-13 13:08:15 +02:00
print '</td>' ;
}
if ( empty ( $conf -> global -> PRODUCT_DISABLE_EATBY )) {
print '<td class="nowraponall">' ;
$dluodatesuffix = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'dluo' . $suffix . 'month' ), GETPOST ( 'dluo' . $suffix . 'day' ), GETPOST ( 'dluo' . $suffix . 'year' ));
print $form -> selectDate ( $dluodatesuffix , 'dluo' . $suffix , '' , '' , 1 , '' );
print '</td>' ;
}
2021-02-07 18:49:46 +01:00
print '<td colspan="3"> </td>' ; // Supplier ref + Qty ordered + qty already dispatched
2016-08-05 10:02:36 +02:00
} else {
$type = 'dispatch' ;
2020-09-15 14:17:55 +02:00
$colspan = 7 ;
$colspan = ( ! empty ( $conf -> global -> PRODUCT_DISABLE_EATBY )) ? -- $colspan : $colspan ;
$colspan = ( ! empty ( $conf -> global -> PRODUCT_DISABLE_SELLBY )) ? -- $colspan : $colspan ;
2019-03-07 20:46:38 +01:00
print '<td class="right">' ;
2019-11-13 19:35:02 +01:00
print '</td>' ; // Qty to dispatch
2017-06-27 13:57:41 +02:00
print '<td>' ;
//print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'onClick="addDispatchLine(' . $i . ',\'' . $type . '\')"');
2019-11-13 19:35:02 +01:00
print '</td>' ; // Dispatch column
2017-06-27 13:57:41 +02:00
print '<td></td>' ; // Warehouse column
2019-09-05 15:30:14 +02:00
2020-09-07 10:18:17 +02:00
// Enable hooks to append additional columns
$parameters = array (
'is_information_row' => true , // allows hook to distinguish between the
// rows with information and the rows with
// dispatch form input
'objp' => $objp
);
$reshook = $hookmanager -> executeHooks (
'printFieldListValue' ,
$parameters ,
$object ,
$action
);
2021-02-25 23:21:30 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2020-09-07 10:18:17 +02:00
print $hookmanager -> resPrint ;
2019-09-05 15:30:14 +02:00
2016-08-05 10:02:36 +02:00
print '</tr>' ;
2017-05-04 17:48:52 +02:00
2019-11-13 19:35:02 +01:00
print '<tr class="oddeven" name="' . $type . $suffix . '">' ;
2020-09-15 14:17:55 +02:00
print '<td colspan="' . $colspan . '">' ;
2019-11-13 19:35:02 +01:00
print '<input name="fk_commandefourndet' . $suffix . '" type="hidden" value="' . $objp -> rowid . '">' ;
print '<input name="product' . $suffix . '" type="hidden" value="' . $objp -> fk_product . '">' ;
2017-06-27 13:57:41 +02:00
2017-05-04 17:48:52 +02:00
print '<!-- This is a up (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->' ;
2021-02-25 23:21:30 +01:00
if ( ! empty ( $conf -> global -> SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT )) { // Not tested !
2020-09-07 10:18:17 +02:00
print $langs -> trans ( " BuyingPrice " ) . ': <input class="maxwidth75" name="pu' . $suffix . '" type="text" value="' . price2num ( $up_ht_disc , 'MU' ) . '">' ;
2020-05-21 15:05:19 +02:00
} else {
2020-09-07 10:18:17 +02:00
print '<input class="maxwidth75" name="pu' . $suffix . '" type="hidden" value="' . price2num ( $up_ht_disc , 'MU' ) . '">' ;
2017-05-04 17:48:52 +02:00
}
2017-06-27 13:57:41 +02:00
2016-08-05 10:02:36 +02:00
print '</td>' ;
}
2017-06-27 13:57:41 +02:00
// Qty to dispatch
2019-03-07 20:46:38 +01:00
print '<td class="right">' ;
2020-04-10 10:59:32 +02:00
print '<input id="qty' . $suffix . '" name="qty' . $suffix . '" type="text" class="width50 right" value="' . ( GETPOSTISSET ( 'qty' . $suffix ) ? GETPOST ( 'qty' . $suffix , 'int' ) : ( empty ( $conf -> global -> SUPPLIER_ORDER_DISPATCH_FORCE_QTY_INPUT_TO_ZERO ) ? $remaintodispatch : 0 )) . '">' ;
2017-09-26 16:21:28 +02:00
print '</td>' ;
2017-06-27 13:57:41 +02:00
2018-08-30 18:57:30 +02:00
print '<td>' ;
2021-03-04 15:31:51 +01:00
if ( ! empty ( $conf -> productbatch -> enabled ) && $objp -> tobatch > 0 ) {
2020-09-07 10:18:17 +02:00
$type = 'batch' ;
print img_picto ( $langs -> trans ( 'AddStockLocationLine' ), 'split.png' , 'class="splitbutton" onClick="addDispatchLine(' . $i . ', \'' . $type . '\')"' );
2020-05-21 15:05:19 +02:00
} else {
2020-09-07 10:18:17 +02:00
$type = 'dispatch' ;
print img_picto ( $langs -> trans ( 'AddStockLocationLine' ), 'split.png' , 'class="splitbutton" onClick="addDispatchLine(' . $i . ', \'' . $type . '\')"' );
2017-06-27 13:57:41 +02:00
}
2016-08-05 10:02:36 +02:00
print '</td>' ;
2015-02-11 22:54:06 +01:00
2020-04-10 10:59:32 +02:00
if ( ! empty ( $conf -> global -> SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT )) {
2019-07-26 12:38:49 +02:00
if ( empty ( $conf -> multicurrency -> enabled ) && empty ( $conf -> dynamicprices -> enabled )) {
// Price
print '<td class="right">' ;
2020-04-10 10:59:32 +02:00
print '<input id="pu' . $suffix . '" name="pu' . $suffix . '" type="text" size="8" value="' . price (( GETPOST ( 'pu' . $suffix ) != '' ? GETPOST ( 'pu' . $suffix ) : $up_ht_disc )) . '">' ;
2019-07-26 12:38:49 +02:00
print '</td>' ;
// Discount
print '<td class="right">' ;
2020-10-31 14:32:18 +01:00
print '<input id="dto' . $suffix . '" name="dto' . $suffix . '" type="text" size="8" value="' . ( GETPOST ( 'dto' . $suffix ) != '' ? GETPOST ( 'dto' . $suffix ) : '' ) . '">' ;
2019-07-26 12:38:49 +02:00
print '</td>' ;
// Save price
print '<td class="center">' ;
2020-04-10 10:59:32 +02:00
print '<input class="flat checkformerge" type="checkbox" name="saveprice' . $suffix . '" value="' . ( GETPOST ( 'saveprice' . $suffix ) != '' ? GETPOST ( 'saveprice' . $suffix ) : '' ) . '">' ;
2019-07-26 12:38:49 +02:00
print '</td>' ;
}
}
2016-08-05 10:02:36 +02:00
// Warehouse
2019-03-07 20:46:38 +01:00
print '<td class="right">' ;
2016-08-05 10:02:36 +02:00
if ( count ( $listwarehouses ) > 1 ) {
2019-11-13 19:35:02 +01:00
print $formproduct -> selectWarehouses ( GETPOST ( " entrepot " . $suffix ) ? GETPOST ( " entrepot " . $suffix ) : ( $objp -> fk_default_warehouse ? $objp -> fk_default_warehouse : '' ), " entrepot " . $suffix , '' , 1 , 0 , $objp -> fk_product , '' , 1 , 0 , null , 'csswarehouse' . $suffix );
2016-08-05 10:02:36 +02:00
} elseif ( count ( $listwarehouses ) == 1 ) {
2019-11-13 19:35:02 +01:00
print $formproduct -> selectWarehouses ( GETPOST ( " entrepot " . $suffix ) ? GETPOST ( " entrepot " . $suffix ) : ( $objp -> fk_default_warehouse ? $objp -> fk_default_warehouse : '' ), " entrepot " . $suffix , '' , 0 , 0 , $objp -> fk_product , '' , 1 , 0 , null , 'csswarehouse' . $suffix );
2016-08-05 10:02:36 +02:00
} else {
2017-03-25 03:53:11 +01:00
$langs -> load ( " errors " );
print $langs -> trans ( " ErrorNoWarehouseDefined " );
2010-08-26 16:49:40 +02:00
}
2016-08-05 10:02:36 +02:00
print " </td> \n " ;
2020-09-07 10:18:17 +02:00
// Enable hooks to append additional columns
$parameters = array (
'is_information_row' => false // this is a dispatch form row
);
$reshook = $hookmanager -> executeHooks (
'printFieldListValue' ,
$parameters ,
$object ,
$action
);
2021-02-25 23:21:30 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2020-09-07 10:18:17 +02:00
print $hookmanager -> resPrint ;
2019-09-05 15:30:14 +02:00
2016-08-05 10:02:36 +02:00
print " </tr> \n " ;
2008-11-16 02:54:33 +01:00
}
}
2016-12-09 11:16:04 +01:00
$i ++ ;
2010-05-28 23:52:51 +02:00
}
2016-08-05 10:02:36 +02:00
$db -> free ( $resql );
} else {
dol_print_error ( $db );
2006-12-11 21:52:01 +01:00
}
2014-03-01 14:49:30 +01:00
2016-08-05 10:02:36 +02:00
print " </table> \n " ;
2016-12-09 11:16:04 +01:00
print '</div>' ;
2016-08-05 10:02:36 +02:00
2021-02-25 23:21:30 +01:00
if ( $nbproduct ) {
2018-08-29 21:08:51 +02:00
$checkboxlabel = $langs -> trans ( " CloseReceivedSupplierOrdersAutomatically " , $langs -> transnoentitiesnoconv ( 'StatusOrderReceivedAll' ));
2017-06-27 13:57:41 +02:00
2019-09-05 15:30:14 +02:00
print '<div class="center">' ;
2018-08-29 14:12:17 +02:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'addMoreActionsButtons' , $parameters , $object , $action ); // Note that $action and $object may have been
// modified by hook
2021-02-25 23:21:30 +01:00
if ( empty ( $reshook )) {
2020-09-07 10:18:17 +02:00
if ( empty ( $conf -> reception -> enabled )) {
print $langs -> trans ( " Comment " ) . ' : ' ;
print '<input type="text" class="minwidth400" maxlength="128" name="comment" value="' ;
2021-03-24 19:53:31 +01:00
print GETPOSTISSET ( " comment " ) ? GETPOST ( " comment " ) : $langs -> trans ( " DispatchSupplierOrder " , $object -> ref );
2020-09-07 10:18:17 +02:00
// print ' / '.$object->ref_supplier; // Not yet available
print '" class="flat"><br>' ;
print '<input type="checkbox" checked="checked" name="closeopenorder"> ' . $checkboxlabel ;
}
2020-03-22 12:31:27 +01:00
2020-09-07 10:18:17 +02:00
$dispatchBt = empty ( $conf -> reception -> enabled ) ? $langs -> trans ( " Receive " ) : $langs -> trans ( " CreateReception " );
2019-02-03 14:29:45 +01:00
2020-09-07 10:18:17 +02:00
print '<br><input type="submit" class="button" name="dispatch" value="' . dol_escape_htmltag ( $dispatchBt ) . '"' ;
2021-02-25 23:21:30 +01:00
if ( count ( $listwarehouses ) <= 0 ) {
2018-08-29 14:12:17 +02:00
print ' disabled' ;
2021-02-25 23:21:30 +01:00
}
2018-08-29 14:12:17 +02:00
print '>' ;
}
2016-12-09 11:16:04 +01:00
print '</div>' ;
2016-08-05 10:02:36 +02:00
}
2016-12-09 11:16:04 +01:00
// Message if nothing to dispatch
2019-11-13 19:35:02 +01:00
if ( ! $nbproduct ) {
2020-09-07 10:18:17 +02:00
print " <br> \n " ;
2021-02-25 23:21:30 +01:00
if ( empty ( $conf -> global -> SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED )) {
2019-11-13 19:35:02 +01:00
print '<div class="opacitymedium">' . $langs -> trans ( " NoPredefinedProductToDispatch " ) . '</div>' ; // No predefined line at all
2021-02-25 23:21:30 +01:00
} else {
print '<div class="opacitymedium">' . $langs -> trans ( " NoMorePredefinedProductToDispatch " ) . '</div>' ; // No predefined line that remain to be dispatched.
}
2016-08-05 10:02:36 +02:00
}
2008-11-16 02:54:33 +01:00
2016-08-05 10:02:36 +02:00
print '</form>' ;
}
2008-11-16 02:54:33 +01:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2016-08-05 10:02:36 +02:00
2019-05-01 11:10:11 +02:00
// traitement entrepot par défaut
print ' < script type = " text/javascript " >
$ ( document ) . ready ( function () {
2019-05-01 13:55:27 +02:00
$ ( " select[name=fk_default_warehouse] " ) . change ( function () {
var fk_default_warehouse = $ ( " option:selected " , this ) . val ();
$ ( " select[name^=entrepot_] " ) . val ( fk_default_warehouse ) . change ();
2020-08-04 12:00:24 +02:00
});
2020-09-15 14:17:55 +02:00
2020-08-03 21:31:39 +02:00
jQuery ( " #autoreset " ) . click ( function () { ' ;
2020-09-07 10:18:17 +02:00
$i = 0 ;
while ( $i < $nbproduct ) {
print ' jQuery("#qty_0_' . $i . '").val("");' ;
$i ++ ;
}
print '
2020-08-04 12:00:24 +02:00
});
2019-05-01 11:10:11 +02:00
});
</ script > ' ;
2017-06-27 13:57:41 +02:00
2016-08-05 10:02:36 +02:00
// List of lines already dispatched
2020-06-16 21:57:49 +02:00
$sql = " SELECT p.rowid as pid, p.ref, p.label, " ;
2017-12-01 12:57:56 +01:00
$sql .= " e.rowid as warehouse_id, e.ref as entrepot, " ;
2018-03-27 15:11:42 +02:00
$sql .= " cfd.rowid as dispatchlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.datec " ;
2020-10-31 14:32:18 +01:00
$sql .= " ,cd.rowid, cd.subprice " ;
2021-02-25 23:21:30 +01:00
if ( $conf -> reception -> enabled ) {
$sql .= " ,cfd.fk_reception, r.date_delivery " ;
}
2019-11-13 19:35:02 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " product as p, " ;
$sql .= " " . MAIN_DB_PREFIX . " commande_fournisseur_dispatch as cfd " ;
2020-10-31 14:32:18 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " commande_fournisseurdet as cd ON cd.rowid = cfd.fk_commandefourndet " ;
2019-11-13 19:35:02 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " entrepot as e ON cfd.fk_entrepot = e.rowid " ;
2021-02-25 23:21:30 +01:00
if ( $conf -> reception -> enabled ) {
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " reception as r ON cfd.fk_reception = r.rowid " ;
}
2019-11-13 19:35:02 +01:00
$sql .= " WHERE cfd.fk_commande = " . $object -> id ;
2016-08-05 10:02:36 +02:00
$sql .= " AND cfd.fk_product = p.rowid " ;
$sql .= " ORDER BY cfd.rowid ASC " ;
$resql = $db -> query ( $sql );
if ( $resql ) {
$num = $db -> num_rows ( $resql );
$i = 0 ;
if ( $num > 0 ) {
2016-12-09 11:16:04 +01:00
print " <br> \n " ;
2014-03-01 14:49:30 +01:00
2016-08-05 10:02:36 +02:00
print load_fiche_titre ( $langs -> trans ( " ReceivingForSameOrder " ));
2014-03-01 14:49:30 +01:00
2016-12-09 11:16:04 +01:00
print '<div class="div-table-responsive">' ;
2019-11-05 21:24:41 +01:00
print '<table id="dispatch_received_products" class="noborder centpercent">' ;
2010-05-28 23:52:51 +02:00
2016-08-05 10:02:36 +02:00
print '<tr class="liste_titre">' ;
2021-02-25 23:21:30 +01:00
if ( $conf -> reception -> enabled ) {
print '<td>' . $langs -> trans ( " Reception " ) . '</td>' ;
}
2019-11-13 19:35:02 +01:00
print '<td>' . $langs -> trans ( " Product " ) . '</td>' ;
print '<td>' . $langs -> trans ( " DateCreation " ) . '</td>' ;
print '<td>' . $langs -> trans ( " DateDeliveryPlanned " ) . '</td>' ;
if ( ! empty ( $conf -> productbatch -> enabled )) {
print '<td class="dispatch_batch_number_title">' . $langs -> trans ( " batch_number " ) . '</td>' ;
2020-07-13 13:08:15 +02:00
if ( empty ( $conf -> global -> PRODUCT_DISABLE_EATBY )) {
2020-10-31 14:32:18 +01:00
print '<td class="dispatch_dluo_title">' . $langs -> trans ( " EatByDate " ) . '</td>' ;
2020-07-13 13:08:15 +02:00
}
if ( empty ( $conf -> global -> PRODUCT_DISABLE_SELLBY )) {
2020-10-31 14:32:18 +01:00
print '<td class="dispatch_dlc_title">' . $langs -> trans ( " SellByDate " ) . '</td>' ;
2020-07-13 13:08:15 +02:00
}
2016-08-05 10:02:36 +02:00
}
2019-11-13 19:35:02 +01:00
print '<td class="right">' . $langs -> trans ( " QtyDispatched " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Warehouse " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Comment " ) . '</td>' ;
2019-09-06 02:22:44 +02:00
// Status
2019-11-13 19:35:02 +01:00
if ( ! empty ( $conf -> global -> SUPPLIER_ORDER_USE_DISPATCH_STATUS ) && empty ( $reception -> rowid )) {
print '<td class="center" colspan="2">' . $langs -> trans ( " Status " ) . '</td>' ;
2020-05-21 15:05:19 +02:00
} elseif ( ! empty ( $conf -> reception -> enabled )) {
2019-09-06 02:22:44 +02:00
print '<td class="center"></td>' ;
}
2020-05-19 14:18:06 +02:00
print '<td class="center" colspan="2"></td>' ;
2016-08-05 10:02:36 +02:00
print " </tr> \n " ;
2019-11-13 19:35:02 +01:00
while ( $i < $num ) {
2016-08-05 10:02:36 +02:00
$objp = $db -> fetch_object ( $resql );
2021-02-25 23:21:30 +01:00
if ( $action == 'editline' && $lineid == $objp -> dispatchlineid ) {
2021-04-25 15:55:36 +02:00
print '<form name="editdispatchedlines" id="editdispatchedlines" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '#line_' . GETPOST ( 'lineid' , 'int' ) . ' " method= " POST " >
2020-10-12 19:39:54 +02:00
< input type = " hidden " name = " token " value = " '.newToken().' " >
2020-05-19 14:18:06 +02:00
< input type = " hidden " name = " action " value = " updateline " >
< input type = " hidden " name = " mode " value = " " >
2020-10-12 19:39:54 +02:00
< input type = " hidden " name = " lineid " value = " '. $objp->dispatchlineid .' " > ' ;
2020-05-19 14:18:06 +02:00
}
2020-10-12 19:39:54 +02:00
print '<tr class="oddeven" id="line_' . $objp -> dispatchlineid . '" >' ;
2019-02-03 14:29:45 +01:00
2019-11-13 19:35:02 +01:00
if ( ! empty ( $conf -> reception -> enabled )) {
2018-10-04 12:27:10 +02:00
print '<td>' ;
2019-11-13 19:35:02 +01:00
if ( ! empty ( $objp -> fk_reception )) {
2018-10-04 12:27:10 +02:00
$reception = new Reception ( $db );
$reception -> fetch ( $objp -> fk_reception );
2018-10-05 16:21:50 +02:00
print $reception -> getNomUrl ( 1 );
2018-10-04 12:27:10 +02:00
}
2019-02-03 14:29:45 +01:00
2018-10-04 12:27:10 +02:00
print " </td> " ;
2018-10-04 10:17:18 +02:00
}
2019-02-03 14:29:45 +01:00
2018-10-04 10:17:18 +02:00
print '<td>' ;
2019-11-13 19:35:02 +01:00
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 ;
2016-08-05 10:02:36 +02:00
print " </td> \n " ;
2019-01-27 11:55:16 +01:00
print '<td>' . dol_print_date ( $db -> jdate ( $objp -> datec ), 'day' ) . '</td>' ;
print '<td>' . dol_print_date ( $db -> jdate ( $objp -> date_delivery ), 'day' ) . '</td>' ;
2016-08-05 10:02:36 +02:00
2019-11-13 19:35:02 +01:00
if ( ! empty ( $conf -> productbatch -> enabled )) {
2020-06-16 21:57:49 +02:00
if ( $objp -> batch ) {
include_once DOL_DOCUMENT_ROOT . '/product/stock/class/productlot.class.php' ;
2020-10-31 14:32:18 +01:00
$lot = new Productlot ( $db );
2020-06-16 21:57:49 +02:00
$lot -> fetch ( 0 , $objp -> pid , $objp -> batch );
print '<td class="dispatch_batch_number">' . $lot -> getNomUrl ( 1 ) . '</td>' ;
2020-07-13 13:08:15 +02:00
if ( empty ( $conf -> global -> PRODUCT_DISABLE_EATBY )) {
2020-10-31 14:32:18 +01:00
print '<td class="dispatch_dluo">' . dol_print_date ( $lot -> eatby , 'day' ) . '</td>' ;
2020-07-13 13:08:15 +02:00
}
if ( empty ( $conf -> global -> PRODUCT_DISABLE_SELLBY )) {
2020-10-31 14:32:18 +01:00
print '<td class="dispatch_dlc">' . dol_print_date ( $lot -> sellby , 'day' ) . '</td>' ;
2020-07-13 13:08:15 +02:00
}
2020-06-16 21:57:49 +02:00
} else {
print '<td class="dispatch_batch_number"></td>' ;
print '<td class="dispatch_dluo"></td>' ;
print '<td class="dispatch_dlc"></td>' ;
}
2015-02-11 22:54:06 +01:00
}
2010-05-28 23:52:51 +02:00
2016-08-05 10:02:36 +02:00
// Qty
2020-05-19 15:59:03 +02:00
print '<td class="right">' ;
2021-02-25 23:21:30 +01:00
if ( $action == 'editline' && $lineid == $objp -> dispatchlineid ) {
2020-10-31 14:32:18 +01:00
print '<input style="width: 50px;" type="number" min="1" name="qty" value="' . $objp -> qty . '" />' ;
2021-02-25 23:21:30 +01:00
} else {
2020-05-19 15:59:03 +02:00
print $objp -> qty ;
2020-05-19 14:18:06 +02:00
}
2020-05-19 15:59:03 +02:00
print '<input type="hidden" name="price" value="' . $objp -> subprice . '" />' ;
print '</td>' ;
2016-08-05 10:02:36 +02:00
// Warehouse
print '<td>' ;
2021-02-25 23:21:30 +01:00
if ( $action == 'editline' && $lineid == $objp -> dispatchlineid ) {
2020-05-19 14:18:06 +02:00
if ( count ( $listwarehouses ) > 1 ) {
2020-10-31 14:32:18 +01:00
print $formproduct -> selectWarehouses ( GETPOST ( " fk_entrepot " ) ? GETPOST ( " fk_entrepot " ) : ( $objp -> warehouse_id ? $objp -> warehouse_id : '' ), " fk_entrepot " , '' , 1 , 0 , $objp -> fk_product , '' , 1 , 1 , null , 'csswarehouse' );
2020-05-19 14:18:06 +02:00
} elseif ( count ( $listwarehouses ) == 1 ) {
2020-10-31 14:32:18 +01:00
print $formproduct -> selectWarehouses ( GETPOST ( " fk_entrepot " ) ? GETPOST ( " fk_entrepot " ) : ( $objp -> warehouse_id ? $objp -> warehouse_id : '' ), " fk_entrepot " , '' , 0 , 0 , $objp -> fk_product , '' , 1 , 1 , null , 'csswarehouse' );
2020-05-19 14:18:06 +02:00
} else {
$langs -> load ( " errors " );
print $langs -> trans ( " ErrorNoWarehouseDefined " );
}
2021-02-25 23:21:30 +01:00
} else {
2020-05-19 14:18:06 +02:00
$warehouse_static -> id = $objp -> warehouse_id ;
2021-05-10 10:10:30 +02:00
$warehouse_static -> label = $objp -> entrepot ;
2020-05-19 14:18:06 +02:00
print $warehouse_static -> getNomUrl ( 1 );
}
2016-08-05 10:02:36 +02:00
print '</td>' ;
// Comment
2019-11-13 19:35:02 +01:00
print '<td class="tdoverflowmax300" style="white-space: pre;">' . $objp -> comment . '</td>' ;
2016-08-05 10:02:36 +02:00
// Status
2019-11-13 19:35:02 +01:00
if ( ! empty ( $conf -> global -> SUPPLIER_ORDER_USE_DISPATCH_STATUS ) && empty ( $reception -> rowid )) {
2019-03-07 20:46:38 +01:00
print '<td class="right">' ;
2016-08-05 10:02:36 +02:00
$supplierorderdispatch -> status = ( empty ( $objp -> status ) ? 0 : $objp -> status );
// print $supplierorderdispatch->status;
print $supplierorderdispatch -> getLibStatut ( 5 );
2010-07-11 21:29:18 +02:00
print '</td>' ;
2015-02-11 15:03:33 +01:00
2016-08-05 10:02:36 +02:00
// Add button to check/uncheck disaptching
2019-03-07 20:46:38 +01:00
print '<td class="center">' ;
2021-02-25 23:21:30 +01:00
if (( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && empty ( $user -> rights -> fournisseur -> commande -> receptionner )) || ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && empty ( $user -> rights -> fournisseur -> commande_advance -> check ))) {
2016-08-05 10:02:36 +02:00
if ( empty ( $objp -> status )) {
2019-11-13 19:35:02 +01:00
print '<a class="button buttonRefused" href="#">' . $langs -> trans ( " Approve " ) . '</a>' ;
print '<a class="button buttonRefused" href="#">' . $langs -> trans ( " Deny " ) . '</a>' ;
2016-08-05 10:02:36 +02:00
} else {
2019-11-13 19:35:02 +01:00
print '<a class="button buttonRefused" href="#">' . $langs -> trans ( " Disapprove " ) . '</a>' ;
print '<a class="button buttonRefused" href="#">' . $langs -> trans ( " Deny " ) . '</a>' ;
2015-03-08 02:08:26 +01:00
}
2016-08-05 10:02:36 +02:00
} else {
$disabled = '' ;
2021-02-25 23:21:30 +01:00
if ( $object -> statut == 5 ) {
2016-08-05 10:02:36 +02:00
$disabled = 1 ;
2021-02-25 23:21:30 +01:00
}
2016-08-05 10:02:36 +02:00
if ( empty ( $objp -> status )) {
2019-11-13 19:35:02 +01:00
print '<a class="button' . ( $disabled ? ' buttonRefused' : '' ) . '" href="' . $_SERVER [ " PHP_SELF " ] . " ?id= " . $id . " &action=checkdispatchline&lineid= " . $objp -> dispatchlineid . '">' . $langs -> trans ( " Approve " ) . '</a>' ;
print '<a class="button' . ( $disabled ? ' buttonRefused' : '' ) . '" href="' . $_SERVER [ " PHP_SELF " ] . " ?id= " . $id . " &action=denydispatchline&lineid= " . $objp -> dispatchlineid . '">' . $langs -> trans ( " Deny " ) . '</a>' ;
2016-08-05 10:02:36 +02:00
}
if ( $objp -> status == 1 ) {
2019-11-13 19:35:02 +01:00
print '<a class="button' . ( $disabled ? ' buttonRefused' : '' ) . '" href="' . $_SERVER [ " PHP_SELF " ] . " ?id= " . $id . " &action=uncheckdispatchline&lineid= " . $objp -> dispatchlineid . '">' . $langs -> trans ( " Reinit " ) . '</a>' ;
print '<a class="button' . ( $disabled ? ' buttonRefused' : '' ) . '" href="' . $_SERVER [ " PHP_SELF " ] . " ?id= " . $id . " &action=denydispatchline&lineid= " . $objp -> dispatchlineid . '">' . $langs -> trans ( " Deny " ) . '</a>' ;
2016-08-05 10:02:36 +02:00
}
if ( $objp -> status == 2 ) {
2019-11-13 19:35:02 +01:00
print '<a class="button' . ( $disabled ? ' buttonRefused' : '' ) . '" href="' . $_SERVER [ " PHP_SELF " ] . " ?id= " . $id . " &action=uncheckdispatchline&lineid= " . $objp -> dispatchlineid . '">' . $langs -> trans ( " Reinit " ) . '</a>' ;
print '<a class="button' . ( $disabled ? ' buttonRefused' : '' ) . '" href="' . $_SERVER [ " PHP_SELF " ] . " ?id= " . $id . " &action=checkdispatchline&lineid= " . $objp -> dispatchlineid . '">' . $langs -> trans ( " Approve " ) . '</a>' ;
2015-03-08 02:08:26 +01:00
}
}
2016-08-05 10:02:36 +02:00
print '</td>' ;
2019-11-13 19:35:02 +01:00
} elseif ( ! empty ( $conf -> reception -> enabled )) {
2019-03-07 20:46:38 +01:00
print '<td class="right">' ;
2019-11-13 19:35:02 +01:00
if ( ! empty ( $reception -> id )) {
2018-10-04 10:17:18 +02:00
print $reception -> getLibStatut ( 5 );
2018-10-23 14:31:58 +02:00
}
2018-10-04 10:17:18 +02:00
print '</td>' ;
2019-09-06 02:22:44 +02:00
}
2021-02-25 23:21:30 +01:00
if ( $action != 'editline' || $lineid != $objp -> dispatchlineid ) {
2021-05-08 12:42:58 +02:00
if ( empty ( $reception -> id ) || ( $reception -> statut == Reception :: STATUS_DRAFT )) { // only allow edit on draft reception
print '<td class="linecoledit center">' ;
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=editline&lineid=' . $objp -> dispatchlineid . '#line_' . $objp -> dispatchlineid . '">' ;
print img_edit ();
print '</a>' ;
print '</td>' ;
2020-05-19 14:18:06 +02:00
2021-05-08 12:42:58 +02:00
print '<td class="linecoldelete center">' ;
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=ask_deleteline&lineid=' . $objp -> dispatchlineid . '#dispatch_received_products">' ;
print img_delete ();
print '</a>' ;
print '</td>' ;
} else {
print '<td></td><td></td>' ;
}
2021-02-25 23:21:30 +01:00
} else {
2020-05-19 14:18:06 +02:00
print '<td class="center valignmiddle">' ;
2020-11-19 20:23:38 +01:00
print '<input type="submit" class="button button-save" id="savelinebutton" name="save" value="' . $langs -> trans ( " Save " ) . '" />' ;
2020-05-19 14:18:06 +02:00
print '</td>' ;
print '<td class="center valignmiddle">' ;
2020-11-23 15:12:52 +01:00
print '<input type="submit" class="button button-cancel" id="cancellinebutton" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '" />' ;
2020-05-19 14:18:06 +02:00
print '</td>' ;
}
2010-05-28 23:52:51 +02:00
2016-08-05 10:02:36 +02:00
print " </tr> \n " ;
2021-02-25 23:21:30 +01:00
if ( $action == 'editline' && $lineid == $objp -> dispatchlineid ) {
print '</form>' ;
}
2016-08-05 10:02:36 +02:00
2019-11-13 19:35:02 +01:00
$i ++ ;
2008-11-16 02:54:33 +01:00
}
2016-08-05 10:02:36 +02:00
$db -> free ( $resql );
print " </table> \n " ;
2016-12-09 11:16:04 +01:00
print '</div>' ;
2006-12-11 21:52:01 +01:00
}
2016-08-05 10:02:36 +02:00
} else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2006-12-11 21:52:01 +01:00
}
}
2018-08-12 22:40:47 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2015-02-11 15:03:33 +01:00
$db -> close ();