2004-10-19 22:43:23 +02:00
< ? php
2012-08-25 15:21:34 +02:00
/* Copyright ( C ) 2003 - 2008 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2016-09-19 13:57:50 +02:00
* Copyright ( C ) 2005 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-08-25 15:21:34 +02:00
* Copyright ( C ) 2005 Simon TOSSER < simon @ kornog - computing . com >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2017-03-17 16:10:40 +01:00
* Copyright ( C ) 2011 - 2017 Juanjo Menent < jmenent @ 2 byte . es >
2013-04-14 12:19:21 +02:00
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
2013-04-21 14:14:30 +02:00
* Copyright ( C ) 2013 Marcos García < marcosgdf @ gmail . com >
2014-03-07 11:35:16 +01:00
* Copyright ( C ) 2014 Cedric GROSS < c . gross @ kreiz - it . fr >
2017-10-24 11:45:11 +02:00
* Copyright ( C ) 2014 - 2017 Francis Appels < francis . appels @ yahoo . com >
2015-12-16 16:18:29 +01:00
* Copyright ( C ) 2015 Claudio Aschieri < c . aschieri @ 19. coop >
2018-09-05 10:00:33 +02:00
* Copyright ( C ) 2016 - 2018 Ferran Marcet < fmarcet @ 2 byte . es >
2016-10-28 19:33:21 +02:00
* Copyright ( C ) 2016 Yasser Carreón < yacasia @ gmail . com >
2018-09-09 09:36:12 +02:00
* Copyright ( C ) 2018 Frédéric France < frederic . france @ netlogic . fr >
2020-04-23 07:38:08 +02:00
* Copyright ( C ) 2020 Lenin Rivas < lenin @ leninrivas . com >
2012-03-16 00:34:41 +01:00
*
2012-03-14 16:26:22 +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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2012-03-14 16:26:22 +01:00
* ( at your option ) any later version .
2012-03-16 00:34:41 +01:00
*
2012-03-14 16:26:22 +01:00
* 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 .
2012-03-16 00:34:41 +01:00
*
2012-03-14 16:26:22 +01:00
* 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 />.
2012-03-14 16:26:22 +01:00
*/
2004-08-14 15:05:12 +02:00
2005-07-09 03:16:31 +02:00
/**
2014-09-18 21:18:25 +02:00
* \file htdocs / expedition / card . php
2012-03-14 16:26:22 +01:00
* \ingroup expedition
2018-02-15 15:27:06 +01:00
* \brief Card of a shipment
2012-03-14 16:26:22 +01:00
*/
2004-08-14 15:05:12 +02:00
2012-08-22 23:24:21 +02:00
require '../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/sendings.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/modules/expedition/modules_expedition.php' ;
2013-04-09 17:18:07 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2016-09-19 13:57:50 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php' ;
2016-10-29 14:52:13 +02:00
require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php' ;
2016-11-14 13:40:41 +01:00
require_once DOL_DOCUMENT_ROOT . '/product/stock/class/productlot.class.php' ;
2019-11-14 12:15:16 +01:00
require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php' ;
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled )) {
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
}
if ( ! empty ( $conf -> propal -> enabled )) {
require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php' ;
}
if ( ! empty ( $conf -> productbatch -> enabled )) {
require_once DOL_DOCUMENT_ROOT . '/product/class/productbatch.class.php' ;
}
2019-11-13 19:35:39 +01:00
if ( ! empty ( $conf -> projet -> enabled )) {
2020-09-07 10:18:17 +02:00
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php' ;
2016-09-19 13:57:50 +02:00
}
2003-11-13 18:36:45 +01:00
2018-05-26 20:51:17 +02:00
// Load translation files required by the page
2019-03-15 02:32:21 +01:00
$langs -> loadLangs ( array ( " sendings " , " companies " , " bills " , 'deliveries' , 'orders' , 'stocks' , 'other' , 'propal' ));
2017-12-02 10:43:01 +01:00
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> incoterm -> enabled )) {
$langs -> load ( 'incoterm' );
}
if ( ! empty ( $conf -> productbatch -> enabled )) {
$langs -> load ( 'productbatch' );
}
2005-04-15 12:34:44 +02:00
2020-04-10 10:59:32 +02:00
$origin = GETPOST ( 'origin' , 'alpha' ) ? GETPOST ( 'origin' , 'alpha' ) : 'expedition' ; // Example: commande, propal
$origin_id = GETPOST ( 'id' , 'int' ) ? GETPOST ( 'id' , 'int' ) : '' ;
2013-10-14 17:56:23 +02:00
$id = $origin_id ;
2021-02-25 22:38:35 +01:00
if ( empty ( $origin_id )) {
$origin_id = GETPOST ( 'origin_id' , 'int' ); // Id of order or propal
}
if ( empty ( $origin_id )) {
$origin_id = GETPOST ( 'object_id' , 'int' ); // Id of order or propal
}
2020-04-10 10:59:32 +02:00
$ref = GETPOST ( 'ref' , 'alpha' );
$line_id = GETPOST ( 'lineid' , 'int' ) ? GETPOST ( 'lineid' , 'int' ) : '' ;
2009-04-05 21:30:37 +02:00
2019-01-27 11:55:16 +01:00
$action = GETPOST ( 'action' , 'alpha' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
2020-04-10 10:59:32 +02:00
$cancel = GETPOST ( 'cancel' , 'alpha' );
2011-06-02 19:20:24 +02:00
2012-07-02 19:30:37 +02:00
//PDF
2020-04-10 10:59:32 +02:00
$hidedetails = ( GETPOST ( 'hidedetails' , 'int' ) ? GETPOST ( 'hidedetails' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS ) ? 1 : 0 ));
$hidedesc = ( GETPOST ( 'hidedesc' , 'int' ) ? GETPOST ( 'hidedesc' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_DESC ) ? 1 : 0 ));
$hideref = ( GETPOST ( 'hideref' , 'int' ) ? GETPOST ( 'hideref' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_REF ) ? 1 : 0 ));
2012-05-21 17:12:57 +02:00
2011-05-26 17:33:33 +02:00
$object = new Expedition ( $db );
2019-11-14 12:15:16 +01:00
$objectorder = new Commande ( $db );
2015-12-16 16:18:29 +01:00
$extrafields = new ExtraFields ( $db );
// fetch optionals attributes and labels
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
$extrafields -> fetch_name_optionals_label ( $object -> table_element_line );
2019-11-14 12:15:16 +01:00
$extrafields -> fetch_name_optionals_label ( $objectorder -> table_element_line );
2015-12-16 16:18:29 +01:00
2015-08-14 23:53:59 +02:00
// Load object. Make an object->fetch
2019-11-13 19:35:39 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php' ; // Must be include, not include_once
2013-07-11 15:55:33 +02:00
2017-06-10 12:56:28 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2019-03-15 02:32:21 +01:00
$hookmanager -> initHooks ( array ( 'expeditioncard' , 'globalcard' ));
2013-09-27 11:00:25 +02:00
2020-11-16 12:20:18 +01:00
$date_delivery = dol_mktime ( GETPOST ( 'date_deliveryhour' , 'int' ), GETPOST ( 'date_deliverymin' , 'int' ), 0 , GETPOST ( 'date_deliverymonth' , 'int' ), GETPOST ( 'date_deliveryday' , 'int' ), GETPOST ( 'date_deliveryyear' , 'int' ));
2021-05-10 19:20:17 +02:00
if ( $id > 0 || ! empty ( $ref )) {
$object -> fetch ( $id , $ref );
$object -> fetch_thirdparty ();
}
2021-03-21 18:01:43 +01:00
// Security check
2021-05-10 19:20:17 +02:00
$socid = '' ;
2021-03-21 18:01:43 +01:00
if ( $user -> socid ) {
$socid = $user -> socid ;
}
2021-04-09 13:15:27 +02:00
2021-03-21 18:01:43 +01:00
$result = restrictedArea ( $user , 'expedition' , $object -> id , '' );
2021-05-10 19:20:17 +02:00
$permissiondellink = $user -> rights -> expedition -> delivery -> creer ; // Used by the include of actions_dellink.inc.php
//var_dump($object->lines[0]->detail_batch);
2015-07-28 14:13:16 +02:00
2003-11-13 18:36:45 +01:00
/*
2005-07-09 03:16:31 +02:00
* Actions
2013-08-07 15:08:30 +02:00
*/
2014-12-05 16:01:01 +01:00
2019-11-13 19:35:39 +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 22:38:35 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2005-04-16 16:00:07 +02:00
2021-02-25 22:38:35 +01:00
if ( empty ( $reshook )) {
if ( $cancel ) {
2017-06-07 16:44:04 +02:00
$action = '' ;
2017-03-25 16:17:43 +01:00
$object -> fetch ( $id ); // show shipment also after canceling modification
2020-09-07 10:18:17 +02:00
}
2017-06-07 16:44:04 +02:00
2019-11-13 19:35:39 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php' ; // Must be include, not include_once
2015-07-28 14:13:16 +02:00
2018-05-10 14:15:52 +02:00
// Actions to build doc
$upload_dir = $conf -> expedition -> dir_output . '/sending' ;
2019-11-05 19:41:30 +01:00
$permissiontoadd = $user -> rights -> expedition -> creer ;
2018-05-10 14:15:52 +02:00
include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php' ;
2017-12-20 12:45:38 +01:00
// Reopen
2021-02-25 22:38:35 +01:00
if ( $action == 'reopen' && $user -> rights -> expedition -> creer ) {
2020-09-07 10:18:17 +02:00
$object -> fetch ( $id );
$result = $object -> reOpen ();
2016-02-24 13:19:25 +01:00
}
2017-06-07 16:44:04 +02:00
2016-02-24 13:19:25 +01:00
// Set incoterm
2021-02-25 22:38:35 +01:00
if ( $action == 'set_incoterms' && ! empty ( $conf -> incoterm -> enabled )) {
2020-09-07 10:18:17 +02:00
$result = $object -> setIncoterms ( GETPOST ( 'incoterm_id' , 'int' ), GETPOST ( 'location_incoterms' , 'alpha' ));
2016-02-24 13:19:25 +01:00
}
2017-06-07 16:44:04 +02:00
2021-02-25 22:38:35 +01:00
if ( $action == 'setref_customer' ) {
2020-09-07 10:18:17 +02:00
$result = $object -> fetch ( $id );
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
$result = $object -> setValueFrom ( 'ref_customer' , GETPOST ( 'ref_customer' , 'alpha' ), '' , null , 'text' , '' , $user , 'SHIPMENT_MODIFY' );
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$action = 'editref_customer' ;
} else {
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
}
2016-10-29 14:52:13 +02:00
}
2017-06-07 16:44:04 +02:00
2021-02-25 22:38:35 +01:00
if ( $action == 'update_extras' ) {
2018-02-23 16:11:00 +01:00
$object -> oldcopy = dol_clone ( $object );
// Fill array 'array_options' with data from update form
2020-09-18 01:29:17 +02:00
$ret = $extrafields -> setOptionalsFromPost ( null , $object , GETPOST ( 'attribute' , 'restricthtml' ));
2021-02-25 22:38:35 +01:00
if ( $ret < 0 ) {
$error ++ ;
}
2017-06-07 16:44:04 +02:00
2021-02-25 22:38:35 +01:00
if ( ! $error ) {
2020-09-07 10:18:17 +02:00
// Actions on extra fields
$result = $object -> insertExtraFields ( 'SHIPMENT_MODIFY' );
2021-02-25 22:38:35 +01:00
if ( $result < 0 ) {
2018-04-10 12:03:01 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
2020-09-07 10:18:17 +02:00
}
2017-06-07 16:44:04 +02:00
2021-02-25 22:38:35 +01:00
if ( $error ) {
2020-09-07 10:18:17 +02:00
$action = 'edit_extras' ;
2021-02-25 22:38:35 +01:00
}
2016-02-24 13:19:25 +01:00
}
2017-06-07 16:44:04 +02:00
2016-04-01 10:57:18 +02:00
// Create shipment
2021-02-25 22:38:35 +01:00
if ( $action == 'add' && $user -> rights -> expedition -> creer ) {
2020-09-07 10:18:17 +02:00
$error = 0 ;
$db -> begin ();
$object -> note = GETPOST ( 'note' , 'alpha' );
$object -> origin = $origin ;
$object -> origin_id = $origin_id ;
$object -> fk_project = GETPOST ( 'projectid' , 'int' );
$object -> weight = GETPOST ( 'weight' , 'int' ) == '' ? " NULL " : GETPOST ( 'weight' , 'int' );
$object -> sizeH = GETPOST ( 'sizeH' , 'int' ) == '' ? " NULL " : GETPOST ( 'sizeH' , 'int' );
$object -> sizeW = GETPOST ( 'sizeW' , 'int' ) == '' ? " NULL " : GETPOST ( 'sizeW' , 'int' );
$object -> sizeS = GETPOST ( 'sizeS' , 'int' ) == '' ? " NULL " : GETPOST ( 'sizeS' , 'int' );
$object -> size_units = GETPOST ( 'size_units' , 'int' );
$object -> weight_units = GETPOST ( 'weight_units' , 'int' );
// We will loop on each line of the original document to complete the shipping object with various info and quantity to deliver
$classname = ucfirst ( $object -> origin );
$objectsrc = new $classname ( $db );
$objectsrc -> fetch ( $object -> origin_id );
$object -> socid = $objectsrc -> socid ;
$object -> ref_customer = GETPOST ( 'ref_customer' , 'alpha' );
$object -> model_pdf = GETPOST ( 'model' );
$object -> date_delivery = $date_delivery ; // Date delivery planed
$object -> fk_delivery_address = $objectsrc -> fk_delivery_address ;
$object -> shipping_method_id = GETPOST ( 'shipping_method_id' , 'int' );
$object -> tracking_number = GETPOST ( 'tracking_number' , 'alpha' );
2020-09-18 01:29:17 +02:00
$object -> note_private = GETPOST ( 'note_private' , 'restricthtml' );
$object -> note_public = GETPOST ( 'note_public' , 'restricthtml' );
2019-11-13 19:35:39 +01:00
$object -> fk_incoterms = GETPOST ( 'incoterm_id' , 'int' );
$object -> location_incoterms = GETPOST ( 'location_incoterms' , 'alpha' );
2015-01-18 17:13:42 +01:00
2020-09-07 10:18:17 +02:00
$batch_line = array ();
2015-12-18 18:00:31 +01:00
$stockLine = array ();
2019-11-13 19:35:39 +01:00
$array_options = array ();
2015-02-16 20:14:16 +01:00
2020-09-07 10:18:17 +02:00
$num = count ( $objectsrc -> lines );
$totalqty = 0 ;
2015-08-14 23:53:59 +02:00
2021-02-25 22:38:35 +01:00
for ( $i = 0 ; $i < $num ; $i ++ ) {
2019-11-13 19:35:39 +01:00
$idl = " idl " . $i ;
2015-02-16 20:14:16 +01:00
2019-11-13 19:35:39 +01:00
$sub_qty = array ();
$subtotalqty = 0 ;
2015-02-16 20:14:16 +01:00
2019-11-13 19:35:39 +01:00
$j = 0 ;
$batch = " batchl " . $i . " _0 " ;
$stockLocation = " ent1 " . $i . " _0 " ;
2020-09-07 10:18:17 +02:00
$qty = " qtyl " . $i ;
2015-02-16 20:14:16 +01:00
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> productbatch -> enabled ) && $objectsrc -> lines [ $i ] -> product_tobatch ) { // If product need a batch number
if ( GETPOSTISSET ( $batch )) {
2020-09-07 10:18:17 +02:00
//shipment line with batch-enable product
$qty .= '_' . $j ;
2021-02-25 22:38:35 +01:00
while ( GETPOSTISSET ( $batch )) {
2020-09-07 10:18:17 +02:00
// save line of detail into sub_qty
$sub_qty [ $j ][ 'q' ] = GETPOST ( $qty , 'int' ); // the qty we want to move for this stock record
$sub_qty [ $j ][ 'id_batch' ] = GETPOST ( $batch , 'int' ); // the id into llx_product_batch of stock record to move
$subtotalqty += $sub_qty [ $j ][ 'q' ];
//var_dump($qty);var_dump($batch);var_dump($sub_qty[$j]['q']);var_dump($sub_qty[$j]['id_batch']);
$j ++ ;
$batch = " batchl " . $i . " _ " . $j ;
$qty = " qtyl " . $i . '_' . $j ;
}
$batch_line [ $i ][ 'detail' ] = $sub_qty ; // array of details
$batch_line [ $i ][ 'qty' ] = $subtotalqty ;
$batch_line [ $i ][ 'ix_l' ] = GETPOST ( $idl , 'int' );
$totalqty += $subtotalqty ;
} else {
2021-03-24 19:06:44 +01:00
// No detail were provided for lots, so if a qty was provided, we can show an error.
if ( GETPOST ( $qty )) {
2020-09-07 10:18:17 +02:00
// We try to set an amount
// Case we dont use the list of available qty for each warehouse/lot
// GUI does not allow this yet
setEventMessages ( $langs -> trans ( " StockIsRequiredToChooseWhichLotToUse " ), null , 'errors' );
}
}
2020-12-08 17:53:12 +01:00
} elseif ( GETPOSTISSET ( $stockLocation )) {
2020-09-07 10:18:17 +02:00
//shipment line from multiple stock locations
$qty .= '_' . $j ;
2021-02-25 22:38:35 +01:00
while ( GETPOSTISSET ( $stockLocation )) {
2020-09-07 10:18:17 +02:00
// save sub line of warehouse
2020-12-08 17:53:12 +01:00
$stockLine [ $i ][ $j ][ 'qty' ] = price2num ( GETPOST ( $qty , 'alpha' ), 'MS' );
2020-09-07 10:18:17 +02:00
$stockLine [ $i ][ $j ][ 'warehouse_id' ] = GETPOST ( $stockLocation , 'int' );
$stockLine [ $i ][ $j ][ 'ix_l' ] = GETPOST ( $idl , 'int' );
2020-12-08 17:53:12 +01:00
$totalqty += price2num ( GETPOST ( $qty , 'alpha' ), 'MS' );
2020-09-07 10:18:17 +02:00
$j ++ ;
$stockLocation = " ent1 " . $i . " _ " . $j ;
$qty = " qtyl " . $i . '_' . $j ;
}
2020-05-21 15:05:19 +02:00
} else {
2020-12-08 17:53:12 +01:00
//var_dump(GETPOST($qty,'alpha')); var_dump($_POST); var_dump($batch);exit;
2016-02-10 23:37:34 +01:00
//shipment line for product with no batch management and no multiple stock location
2021-02-25 22:38:35 +01:00
if ( GETPOST ( $qty , 'int' ) > 0 ) {
$totalqty += price2num ( GETPOST ( $qty , 'alpha' ), 'MS' );
}
2015-01-18 17:13:42 +01:00
}
2017-06-07 16:44:04 +02:00
2015-12-16 16:18:29 +01:00
// Extrafields
2019-10-06 14:41:52 +02:00
$array_options [ $i ] = $extrafields -> getOptionalsFromPost ( $object -> table_element_line , $i );
2015-12-16 16:18:29 +01:00
// Unset extrafield
2019-11-01 21:06:06 +01:00
if ( is_array ( $extrafields -> attributes [ $object -> table_element_line ][ 'label' ])) {
2015-12-16 16:18:29 +01:00
// Get extra fields
2019-11-01 21:06:06 +01:00
foreach ( $extrafields -> attributes [ $object -> table_element_line ][ 'label' ] as $key => $value ) {
2020-04-10 10:59:32 +02:00
unset ( $_POST [ " options_ " . $key ]);
2015-12-16 16:18:29 +01:00
}
}
2020-09-07 10:18:17 +02:00
}
2017-06-07 16:44:04 +02:00
2020-09-07 10:18:17 +02:00
//var_dump($batch_line[2]);
2015-01-18 17:13:42 +01:00
2021-02-25 22:38:35 +01:00
if ( $totalqty > 0 ) { // There is at least one thing to ship
2020-09-07 10:18:17 +02:00
//var_dump($_POST);exit;
2021-02-25 22:38:35 +01:00
for ( $i = 0 ; $i < $num ; $i ++ ) {
2020-09-07 10:18:17 +02:00
$qty = " qtyl " . $i ;
2021-02-25 22:38:35 +01:00
if ( ! isset ( $batch_line [ $i ])) {
2015-08-14 23:53:59 +02:00
// not batch mode
2021-02-25 22:38:35 +01:00
if ( isset ( $stockLine [ $i ])) {
2020-09-07 10:18:17 +02:00
//shipment from multiple stock locations
$nbstockline = count ( $stockLine [ $i ]);
2021-02-25 22:38:35 +01:00
for ( $j = 0 ; $j < $nbstockline ; $j ++ ) {
if ( $stockLine [ $i ][ $j ][ 'qty' ] > 0 ) {
2020-09-07 10:18:17 +02:00
$ret = $object -> addline ( $stockLine [ $i ][ $j ][ 'warehouse_id' ], $stockLine [ $i ][ $j ][ 'ix_l' ], $stockLine [ $i ][ $j ][ 'qty' ], $array_options [ $i ]);
2021-02-25 22:38:35 +01:00
if ( $ret < 0 ) {
2020-09-07 10:18:17 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
}
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-25 22:38:35 +01:00
if ( GETPOST ( $qty , 'int' ) > 0 || ( GETPOST ( $qty , 'int' ) == 0 && $conf -> global -> SHIPMENT_GETS_ALL_ORDER_PRODUCTS )) {
2016-02-15 02:01:58 +01:00
$ent = " entl " . $i ;
$idl = " idl " . $i ;
2019-11-13 19:35:39 +01:00
$entrepot_id = is_numeric ( GETPOST ( $ent , 'int' )) ? GETPOST ( $ent , 'int' ) : GETPOST ( 'entrepot_id' , 'int' );
2021-02-25 22:38:35 +01:00
if ( $entrepot_id < 0 ) {
$entrepot_id = '' ;
}
if ( ! ( $objectsrc -> lines [ $i ] -> fk_product > 0 )) {
$entrepot_id = 0 ;
}
2017-06-07 16:44:04 +02:00
2019-11-13 19:35:39 +01:00
$ret = $object -> addline ( $entrepot_id , GETPOST ( $idl , 'int' ), GETPOST ( $qty , 'int' ), $array_options [ $i ]);
2021-02-25 22:38:35 +01:00
if ( $ret < 0 ) {
2016-02-15 02:01:58 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
2015-01-18 17:13:42 +01:00
}
}
2020-05-21 15:05:19 +02:00
} else {
2015-08-14 23:53:59 +02:00
// batch mode
2021-02-25 22:38:35 +01:00
if ( $batch_line [ $i ][ 'qty' ] > 0 ) {
2019-11-13 19:35:39 +01:00
$ret = $object -> addline_batch ( $batch_line [ $i ], $array_options [ $i ]);
2021-02-25 22:38:35 +01:00
if ( $ret < 0 ) {
2015-12-14 21:38:26 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-01-18 17:13:42 +01:00
$error ++ ;
}
2014-03-07 11:35:16 +01:00
}
}
2020-09-07 10:18:17 +02:00
}
// Fill array 'array_options' with data from add form
$ret = $extrafields -> setOptionalsFromPost ( null , $object );
2021-02-25 22:38:35 +01:00
if ( $ret < 0 ) {
$error ++ ;
}
2015-01-18 17:13:42 +01:00
2021-02-25 22:38:35 +01:00
if ( ! $error ) {
2020-09-07 10:18:17 +02:00
$ret = $object -> create ( $user ); // This create shipment (like Odoo picking) and lines of shipments. Stock movement will be done when validating shipment.
2021-02-25 22:38:35 +01:00
if ( $ret <= 0 ) {
2020-09-07 10:18:17 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
}
} else {
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " QtyToShip " ) . '/' . $langs -> transnoentitiesnoconv ( " Warehouse " )), null , 'errors' );
$error ++ ;
}
2021-02-25 22:38:35 +01:00
if ( ! $error ) {
2020-09-07 10:18:17 +02:00
$db -> commit ();
header ( " Location: card.php?id= " . $object -> id );
exit ;
} else {
$db -> rollback ();
$_GET [ " commande_id " ] = GETPOST ( 'commande_id' , 'int' );
$action = 'create' ;
}
2021-02-25 22:38:35 +01:00
} elseif ( $action == 'create_delivery' && $conf -> delivery_note -> enabled && $user -> rights -> expedition -> delivery -> creer ) {
// Build a receiving receipt
2020-09-07 10:18:17 +02:00
$result = $object -> create_delivery ( $user );
2021-02-25 22:38:35 +01:00
if ( $result > 0 ) {
2020-10-05 15:32:29 +02:00
header ( " Location: " . DOL_URL_ROOT . '/delivery/card.php?action=create_delivery&id=' . $result );
2020-09-07 10:18:17 +02:00
exit ;
} else {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2020-05-21 15:05:19 +02:00
} elseif ( $action == 'confirm_valid' && $confirm == 'yes' &&
2020-09-07 10:18:17 +02:00
(( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> expedition -> creer ))
2021-02-25 22:38:35 +01:00
|| ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> expedition -> shipping_advance -> validate )))
) {
2020-09-07 10:18:17 +02:00
$object -> fetch_thirdparty ();
2017-06-07 16:44:04 +02:00
2020-09-07 10:18:17 +02:00
$result = $object -> valid ( $user );
2017-06-07 16:44:04 +02:00
2020-11-27 16:21:32 +01:00
if ( $result < 0 ) {
2020-11-27 16:13:27 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2020-09-07 10:18:17 +02:00
} else {
// Define output language
2021-02-25 22:38:35 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
2020-09-07 10:18:17 +02:00
$outputlangs = $langs ;
$newlang = '' ;
2021-02-25 22:38:35 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
$newlang = $object -> thirdparty -> default_lang ;
}
2020-09-07 10:18:17 +02:00
if ( ! empty ( $newlang )) {
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
2020-09-10 01:49:09 +02:00
$model = $object -> model_pdf ;
2020-09-07 10:18:17 +02:00
$ret = $object -> fetch ( $id ); // Reload to get new records
$result = $object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
2021-02-25 22:38:35 +01:00
if ( $result < 0 ) {
dol_print_error ( $db , $result );
}
2020-09-07 10:18:17 +02:00
}
}
2021-02-25 22:38:35 +01:00
} elseif ( $action == 'confirm_cancel' && $confirm == 'yes' && $user -> rights -> expedition -> supprimer ) {
2020-04-23 07:38:08 +02:00
$also_update_stock = ( GETPOST ( 'alsoUpdateStock' , 'alpha' ) ? 1 : 0 );
2020-09-07 10:18:17 +02:00
$result = $object -> cancel ( 0 , $also_update_stock );
2021-02-25 22:38:35 +01:00
if ( $result > 0 ) {
2020-09-07 10:18:17 +02:00
$result = $object -> setStatut ( - 1 );
} else {
2020-04-23 07:38:08 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2020-09-07 10:18:17 +02:00
}
2021-02-25 22:38:35 +01:00
} elseif ( $action == 'confirm_delete' && $confirm == 'yes' && $user -> rights -> expedition -> supprimer ) {
2020-09-07 10:18:17 +02:00
$also_update_stock = ( GETPOST ( 'alsoUpdateStock' , 'alpha' ) ? 1 : 0 );
$result = $object -> delete ( 0 , $also_update_stock );
2021-02-25 22:38:35 +01:00
if ( $result > 0 ) {
2020-09-07 10:18:17 +02:00
header ( " Location: " . DOL_URL_ROOT . '/expedition/index.php' );
exit ;
} else {
2015-12-14 21:38:26 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2020-09-07 10:18:17 +02:00
}
2021-02-25 22:38:35 +01:00
// TODO add alternative status
//} elseif ($action == 'reopen' && (! empty($user->rights->expedition->creer) || ! empty($user->rights->expedition->shipping_advance->validate)))
//{
// $result = $object->setStatut(0);
// if ($result < 0)
// {
// setEventMessages($object->error, $object->errors, 'errors');
// }
//}
} elseif ( $action == 'setdate_livraison' && $user -> rights -> expedition -> creer ) {
2020-09-07 10:18:17 +02:00
//print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
$datedelivery = dol_mktime ( GETPOST ( 'liv_hour' , 'int' ), GETPOST ( 'liv_min' , 'int' ), 0 , GETPOST ( 'liv_month' , 'int' ), GETPOST ( 'liv_day' , 'int' ), GETPOST ( 'liv_year' , 'int' ));
2015-01-18 17:13:42 +01:00
2020-09-07 10:18:17 +02:00
$object -> fetch ( $id );
2020-10-26 16:50:52 +01:00
$result = $object -> setDeliveryDate ( $user , $datedelivery );
2021-02-25 22:38:35 +01:00
if ( $result < 0 ) {
2020-09-07 10:18:17 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2021-02-25 22:38:35 +01:00
} elseif (( $action == 'settracking_number'
2018-06-22 12:25:14 +02:00
|| $action == 'settracking_url'
|| $action == 'settrueWeight'
|| $action == 'settrueWidth'
|| $action == 'settrueHeight'
|| $action == 'settrueDepth'
|| $action == 'setshipping_method_id' )
&& $user -> rights -> expedition -> creer
2021-02-25 22:38:35 +01:00
) {
// Action update
2020-09-07 10:18:17 +02:00
$error = 0 ;
2015-01-18 17:13:42 +01:00
2021-02-25 22:38:35 +01:00
if ( $action == 'settracking_number' ) {
$object -> tracking_number = trim ( GETPOST ( 'tracking_number' , 'alpha' ));
}
if ( $action == 'settracking_url' ) {
$object -> tracking_url = trim ( GETPOST ( 'tracking_url' , 'int' ));
}
2020-09-07 10:18:17 +02:00
if ( $action == 'settrueWeight' ) {
$object -> trueWeight = trim ( GETPOST ( 'trueWeight' , 'int' ));
2019-01-27 11:55:16 +01:00
$object -> weight_units = GETPOST ( 'weight_units' , 'int' );
2020-09-07 10:18:17 +02:00
}
2021-02-25 22:38:35 +01:00
if ( $action == 'settrueWidth' ) {
$object -> trueWidth = trim ( GETPOST ( 'trueWidth' , 'int' ));
}
2020-09-07 10:18:17 +02:00
if ( $action == 'settrueHeight' ) {
$object -> trueHeight = trim ( GETPOST ( 'trueHeight' , 'int' ));
2019-01-27 11:55:16 +01:00
$object -> size_units = GETPOST ( 'size_units' , 'int' );
2015-01-18 17:13:42 +01:00
}
2021-02-25 22:38:35 +01:00
if ( $action == 'settrueDepth' ) {
$object -> trueDepth = trim ( GETPOST ( 'trueDepth' , 'int' ));
}
if ( $action == 'setshipping_method_id' ) {
$object -> shipping_method_id = trim ( GETPOST ( 'shipping_method_id' , 'int' ));
}
2015-01-18 17:13:42 +01:00
2021-02-25 22:38:35 +01:00
if ( ! $error ) {
if ( $object -> update ( $user ) >= 0 ) {
2020-09-07 10:18:17 +02:00
header ( " Location: card.php?id= " . $object -> id );
exit ;
}
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2015-01-18 17:13:42 +01:00
2020-09-07 10:18:17 +02:00
$action = " " ;
2021-02-25 22:38:35 +01:00
} elseif ( $action == 'classifybilled' ) {
2020-09-07 10:18:17 +02:00
$object -> fetch ( $id );
2021-02-09 13:10:11 +01:00
$result = $object -> setBilled ();
2020-09-07 10:18:17 +02:00
if ( $result >= 0 ) {
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ();
}
2019-09-27 11:00:17 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2021-02-25 22:38:35 +01:00
} elseif ( $action == 'classifyclosed' ) {
2020-09-07 10:18:17 +02:00
$object -> fetch ( $id );
$result = $object -> setClosed ();
if ( $result >= 0 ) {
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ();
}
2019-09-27 11:00:17 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2021-02-25 22:38:35 +01:00
} elseif ( $action == 'deleteline' && ! empty ( $line_id )) {
// delete a line
2017-10-18 18:18:17 +02:00
$object -> fetch ( $id );
2017-10-23 22:18:15 +02:00
$lines = $object -> lines ;
2017-10-18 18:18:17 +02:00
$line = new ExpeditionLigne ( $db );
2017-11-02 12:38:36 +01:00
2017-10-23 22:18:15 +02:00
$num_prod = count ( $lines );
2021-02-25 22:38:35 +01:00
for ( $i = 0 ; $i < $num_prod ; $i ++ ) {
if ( $lines [ $i ] -> id == $line_id ) {
if ( count ( $lines [ $i ] -> details_entrepot ) > 1 ) {
2017-10-24 11:37:17 +02:00
// delete multi warehouse lines
foreach ( $lines [ $i ] -> details_entrepot as $details_entrepot ) {
$line -> id = $details_entrepot -> line_id ;
2021-02-25 22:38:35 +01:00
if ( ! $error && $line -> delete ( $user ) < 0 ) {
2017-10-24 11:37:17 +02:00
$error ++ ;
}
2017-10-23 22:18:15 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-24 11:37:17 +02:00
// delete single warehouse line
$line -> id = $line_id ;
2021-02-25 22:38:35 +01:00
if ( ! $error && $line -> delete ( $user ) < 0 ) {
2017-10-24 11:37:17 +02:00
$error ++ ;
}
2017-10-23 22:18:15 +02:00
}
}
2017-10-24 11:37:17 +02:00
unset ( $_POST [ " lineid " ]);
2017-10-23 22:18:15 +02:00
}
2017-11-02 12:38:36 +01:00
2019-11-13 19:35:39 +01:00
if ( ! $error ) {
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
2017-10-18 18:18:17 +02:00
exit ();
2020-05-21 15:05:19 +02:00
} else {
2017-10-23 22:18:15 +02:00
setEventMessages ( $line -> error , $line -> errors , 'errors' );
}
2021-02-25 22:38:35 +01:00
} elseif ( $action == 'updateline' && $user -> rights -> expedition -> creer && GETPOST ( 'save' )) {
// Update a line
2017-10-23 22:18:15 +02:00
// Clean parameters
2019-11-13 19:35:39 +01:00
$qty = 0 ;
2017-10-23 22:18:15 +02:00
$entrepot_id = 0 ;
$batch_id = 0 ;
2017-11-02 12:38:36 +01:00
2017-10-23 22:18:15 +02:00
$lines = $object -> lines ;
$num_prod = count ( $lines );
2021-02-25 22:38:35 +01:00
for ( $i = 0 ; $i < $num_prod ; $i ++ ) {
if ( $lines [ $i ] -> id == $line_id ) { // we have found line to update
2017-10-23 22:18:15 +02:00
$line = new ExpeditionLigne ( $db );
2019-10-06 14:41:52 +02:00
2017-10-24 10:53:11 +02:00
// Extrafields Lines
2019-10-06 14:41:52 +02:00
$line -> array_options = $extrafields -> getOptionalsFromPost ( $object -> table_element_line );
2017-10-24 10:53:11 +02:00
// Unset extrafield POST Data
2019-11-01 21:06:06 +01:00
if ( is_array ( $extrafields -> attributes [ $object -> table_element_line ][ 'label' ])) {
foreach ( $extrafields -> attributes [ $object -> table_element_line ][ 'label' ] as $key => $value ) {
2020-04-10 10:59:32 +02:00
unset ( $_POST [ " options_ " . $key ]);
2017-10-24 10:53:11 +02:00
}
}
2017-10-23 22:18:15 +02:00
$line -> fk_product = $lines [ $i ] -> fk_product ;
2021-02-25 22:38:35 +01:00
if ( is_array ( $lines [ $i ] -> detail_batch ) && count ( $lines [ $i ] -> detail_batch ) > 0 ) {
2017-10-23 22:18:15 +02:00
// line with lot
2021-02-25 22:38:35 +01:00
foreach ( $lines [ $i ] -> detail_batch as $detail_batch ) {
2017-10-23 22:18:15 +02:00
$lotStock = new Productbatch ( $db );
2019-11-13 19:35:39 +01:00
$batch = " batchl " . $detail_batch -> fk_expeditiondet . " _ " . $detail_batch -> fk_origin_stock ;
2017-10-23 22:18:15 +02:00
$qty = " qtyl " . $detail_batch -> fk_expeditiondet . '_' . $detail_batch -> id ;
2019-01-27 11:55:16 +01:00
$batch_id = GETPOST ( $batch , 'int' );
2017-10-30 12:39:06 +01:00
$batch_qty = GETPOST ( $qty , 'int' );
2021-02-25 22:38:35 +01:00
if ( ! empty ( $batch_id ) && ( $batch_id != $detail_batch -> fk_origin_stock || $batch_qty != $detail_batch -> qty )) {
if ( $lotStock -> fetch ( $batch_id ) > 0 && $line -> fetch ( $detail_batch -> fk_expeditiondet ) > 0 ) { // $line is ExpeditionLine
if ( $lines [ $i ] -> entrepot_id != 0 ) {
2017-10-30 12:39:06 +01:00
// allow update line entrepot_id if not multi warehouse shipping
$line -> entrepot_id = $lotStock -> warehouseid ;
}
2017-11-02 12:38:36 +01:00
// detail_batch can be an object with keys, or an array of ExpeditionLineBatch
2021-02-25 22:38:35 +01:00
if ( empty ( $line -> detail_batch )) {
$line -> detail_batch = new stdClass ();
}
2017-11-02 12:38:36 +01:00
2017-10-23 22:18:15 +02:00
$line -> detail_batch -> fk_origin_stock = $batch_id ;
$line -> detail_batch -> batch = $lotStock -> batch ;
$line -> detail_batch -> id = $detail_batch -> id ;
2017-10-30 12:39:06 +01:00
$line -> detail_batch -> entrepot_id = $lotStock -> warehouseid ;
2018-10-11 11:56:52 +02:00
$line -> detail_batch -> qty = $batch_qty ;
2017-10-23 22:18:15 +02:00
if ( $line -> update ( $user ) < 0 ) {
setEventMessages ( $line -> error , $line -> errors , 'errors' );
$error ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-23 22:18:15 +02:00
setEventMessages ( $lotStock -> error , $lotStock -> errors , 'errors' );
$error ++ ;
}
}
2017-10-24 10:53:11 +02:00
unset ( $_POST [ $batch ]);
unset ( $_POST [ $qty ]);
2017-10-23 22:18:15 +02:00
}
2017-11-02 11:44:36 +01:00
// add new batch
$lotStock = new Productbatch ( $db );
2019-11-13 19:35:39 +01:00
$batch = " batchl " . $line_id . " _0 " ;
2017-11-02 11:44:36 +01:00
$qty = " qtyl " . $line_id . " _0 " ;
2019-01-27 11:55:16 +01:00
$batch_id = GETPOST ( $batch , 'int' );
2017-11-02 11:44:36 +01:00
$batch_qty = GETPOST ( $qty , 'int' );
$lineIdToAddLot = 0 ;
2021-02-25 22:38:35 +01:00
if ( $batch_qty > 0 && ! empty ( $batch_id )) {
if ( $lotStock -> fetch ( $batch_id ) > 0 ) {
2017-11-02 11:44:36 +01:00
// check if lotStock warehouse id is same as line warehouse id
2021-02-25 22:38:35 +01:00
if ( $lines [ $i ] -> entrepot_id > 0 ) {
2017-11-02 11:44:36 +01:00
// single warehouse shipment line
2021-02-25 22:38:35 +01:00
if ( $lines [ $i ] -> entrepot_id == $lotStock -> warehouseid ) {
2017-11-02 11:44:36 +01:00
$lineIdToAddLot = $line_id ;
}
2021-02-25 22:38:35 +01:00
} elseif ( count ( $lines [ $i ] -> details_entrepot ) > 1 ) {
2017-11-02 11:44:36 +01:00
// multi warehouse shipment lines
2021-02-25 22:38:35 +01:00
foreach ( $lines [ $i ] -> details_entrepot as $detail_entrepot ) {
if ( $detail_entrepot -> entrepot_id == $lotStock -> warehouseid ) {
2017-11-02 11:44:36 +01:00
$lineIdToAddLot = $detail_entrepot -> line_id ;
}
}
}
2021-02-25 22:38:35 +01:00
if ( $lineIdToAddLot ) {
2017-11-02 11:44:36 +01:00
// add lot to existing line
2021-02-25 22:38:35 +01:00
if ( $line -> fetch ( $lineIdToAddLot ) > 0 ) {
2017-11-02 11:44:36 +01:00
$line -> detail_batch -> fk_origin_stock = $batch_id ;
$line -> detail_batch -> batch = $lotStock -> batch ;
$line -> detail_batch -> entrepot_id = $lotStock -> warehouseid ;
2018-10-11 11:56:52 +02:00
$line -> detail_batch -> qty = $batch_qty ;
2017-11-02 11:44:36 +01:00
if ( $line -> update ( $user ) < 0 ) {
setEventMessages ( $line -> error , $line -> errors , 'errors' );
$error ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-11-02 11:44:36 +01:00
setEventMessages ( $line -> error , $line -> errors , 'errors' );
$error ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-11-02 11:44:36 +01:00
// create new line with new lot
$line -> origin_line_id = $lines [ $i ] -> origin_line_id ;
$line -> entrepot_id = $lotStock -> warehouseid ;
$line -> detail_batch [ 0 ] = new ExpeditionLineBatch ( $db );
$line -> detail_batch [ 0 ] -> fk_origin_stock = $batch_id ;
$line -> detail_batch [ 0 ] -> batch = $lotStock -> batch ;
$line -> detail_batch [ 0 ] -> entrepot_id = $lotStock -> warehouseid ;
2018-10-11 11:56:52 +02:00
$line -> detail_batch [ 0 ] -> qty = $batch_qty ;
2021-02-25 22:38:35 +01:00
if ( $object -> create_line_batch ( $line , $line -> array_options ) < 0 ) {
2017-11-02 11:44:36 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
}
2020-05-21 15:05:19 +02:00
} else {
2017-11-02 11:44:36 +01:00
setEventMessages ( $lotStock -> error , $lotStock -> errors , 'errors' );
$error ++ ;
}
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-25 22:38:35 +01:00
if ( $lines [ $i ] -> fk_product > 0 ) {
2017-12-01 14:33:06 +01:00
// line without lot
2021-02-25 22:38:35 +01:00
if ( $lines [ $i ] -> entrepot_id > 0 ) {
2017-12-01 14:33:06 +01:00
// single warehouse shipment line
2019-11-13 19:35:39 +01:00
$stockLocation = " entl " . $line_id ;
2017-12-01 14:33:06 +01:00
$qty = " qtyl " . $line_id ;
$line -> id = $line_id ;
2019-01-27 11:55:16 +01:00
$line -> entrepot_id = GETPOST ( $stockLocation , 'int' );
2017-12-01 14:33:06 +01:00
$line -> qty = GETPOST ( $qty , 'int' );
if ( $line -> update ( $user ) < 0 ) {
setEventMessages ( $line -> error , $line -> errors , 'errors' );
$error ++ ;
}
unset ( $_POST [ $stockLocation ]);
unset ( $_POST [ $qty ]);
2021-02-25 22:38:35 +01:00
} elseif ( count ( $lines [ $i ] -> details_entrepot ) > 1 ) {
2017-12-01 14:33:06 +01:00
// multi warehouse shipment lines
2021-02-25 22:38:35 +01:00
foreach ( $lines [ $i ] -> details_entrepot as $detail_entrepot ) {
2019-11-13 19:35:39 +01:00
if ( ! $error ) {
$stockLocation = " entl " . $detail_entrepot -> line_id ;
2017-12-01 14:33:06 +01:00
$qty = " qtyl " . $detail_entrepot -> line_id ;
2019-01-27 11:55:16 +01:00
$warehouse = GETPOST ( $stockLocation , 'int' );
2021-02-25 22:38:35 +01:00
if ( ! empty ( $warehouse )) {
2017-12-01 14:33:06 +01:00
$line -> id = $detail_entrepot -> line_id ;
$line -> entrepot_id = $warehouse ;
$line -> qty = GETPOST ( $qty , 'int' );
if ( $line -> update ( $user ) < 0 ) {
setEventMessages ( $line -> error , $line -> errors , 'errors' );
$error ++ ;
}
}
unset ( $_POST [ $stockLocation ]);
unset ( $_POST [ $qty ]);
}
}
}
2020-05-21 15:05:19 +02:00
} else {
2020-09-07 10:18:17 +02:00
// Product no predefined
2017-10-23 22:18:15 +02:00
$qty = " qtyl " . $line_id ;
$line -> id = $line_id ;
$line -> qty = GETPOST ( $qty , 'int' );
2017-12-01 14:33:06 +01:00
$line -> entrepot_id = 0 ;
2017-10-23 22:18:15 +02:00
if ( $line -> update ( $user ) < 0 ) {
setEventMessages ( $line -> error , $line -> errors , 'errors' );
$error ++ ;
}
2017-10-24 10:53:11 +02:00
unset ( $_POST [ $qty ]);
2017-10-23 22:18:15 +02:00
}
}
}
}
2017-10-24 10:53:11 +02:00
unset ( $_POST [ " lineid " ]);
2017-10-23 22:18:15 +02:00
2019-11-13 19:35:39 +01:00
if ( ! $error ) {
2017-10-23 22:18:15 +02:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
2021-02-25 22:38:35 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
2019-01-27 11:55:16 +01:00
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
2021-02-25 22:38:35 +01:00
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
2017-10-23 22:18:15 +02:00
$newlang = $object -> thirdparty -> default_lang ;
2021-02-25 22:38:35 +01:00
}
2019-11-13 19:35:39 +01:00
if ( ! empty ( $newlang )) {
2017-10-23 22:18:15 +02:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$ret = $object -> fetch ( $object -> id ); // Reload to get new records
2020-09-10 01:49:09 +02:00
$object -> generateDocument ( $object -> model_pdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
2017-10-23 22:18:15 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
header ( 'Location: ' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id ); // To redisplay the form being edited
2017-10-23 22:18:15 +02:00
exit ();
}
2020-11-23 15:12:52 +01:00
} elseif ( $action == 'updateline' && $user -> rights -> expedition -> creer && GETPOST ( 'cancel' , 'alpha' ) == $langs -> trans ( " Cancel " )) {
2019-11-13 19:35:39 +01:00
header ( 'Location: ' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id ); // To redisplay the form being edited
2017-10-23 22:18:15 +02:00
exit ();
2017-10-18 18:18:17 +02:00
}
2015-01-18 18:44:22 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php' ;
2014-12-08 20:33:26 +01:00
2015-01-18 18:44:22 +01:00
// Actions to send emails
2021-02-25 22:38:35 +01:00
if ( empty ( $id )) {
$id = $facid ;
}
2019-12-02 09:38:16 +01:00
$triggersendname = 'SHIPPING_SENTBYMAIL' ;
2019-11-13 19:35:39 +01:00
$paramname = 'id' ;
$mode = 'emailfromshipment' ;
$trackid = 'shi' . $object -> id ;
2015-01-18 18:44:22 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php' ;
2012-03-13 17:28:55 +01:00
}
2011-08-21 14:41:29 +02:00
2012-03-14 11:11:46 +01:00
2003-11-13 18:36:45 +01:00
/*
2008-08-21 09:39:38 +02:00
* View
2012-11-18 16:21:38 +01:00
*/
2003-11-13 18:36:45 +01:00
2021-03-16 13:38:46 +01:00
$help_url = 'EN:Module_Shipments|FR:Module_Expéditions|ES:Módulo_Expediciones|DE:Modul_Lieferungen' ;
llxHeader ( '' , $langs -> trans ( 'Shipment' ), 'Expedition' , $help_url );
2006-06-04 01:53:10 +02:00
2011-11-08 10:18:45 +01:00
$form = new Form ( $db );
2008-01-20 14:53:02 +01:00
$formfile = new FormFile ( $db );
2008-10-28 22:59:53 +01:00
$formproduct = new FormProduct ( $db );
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> projet -> enabled )) {
$formproject = new FormProjets ( $db );
}
2003-11-13 18:36:45 +01:00
2016-10-29 14:52:13 +02:00
$product_static = new Product ( $db );
$shipment_static = new Expedition ( $db );
$warehousestatic = new Entrepot ( $db );
2021-02-25 22:38:35 +01:00
if ( $action == 'create2' ) {
2020-09-07 10:18:17 +02:00
print load_fiche_titre ( $langs -> trans ( " CreateShipment " ), '' , 'dolly' );
2020-04-20 15:57:15 +02:00
2020-09-07 10:18:17 +02:00
print '<br>' . $langs -> trans ( " ShipmentCreationIsDoneFromOrder " );
$action = '' ; $id = '' ; $ref = '' ;
2011-08-21 13:00:43 +02:00
}
2017-06-07 16:44:04 +02:00
// Mode creation.
2021-02-25 22:38:35 +01:00
if ( $action == 'create' ) {
2020-09-07 10:18:17 +02:00
$expe = new Expedition ( $db );
2012-03-14 14:48:27 +01:00
2020-09-07 10:18:17 +02:00
print load_fiche_titre ( $langs -> trans ( " CreateShipment " ), '' , 'dolly' );
2020-04-20 15:57:15 +02:00
2021-02-25 22:38:35 +01:00
if ( ! $origin ) {
2020-09-07 10:18:17 +02:00
setEventMessages ( $langs -> trans ( " ErrorBadParameters " ), null , 'errors' );
}
2012-03-14 14:48:27 +01:00
2021-02-25 22:38:35 +01:00
if ( $origin ) {
2020-09-07 10:18:17 +02:00
$classname = ucfirst ( $origin );
2012-03-14 14:48:27 +01:00
2020-09-07 10:18:17 +02:00
$object = new $classname ( $db );
2021-02-25 22:38:35 +01:00
if ( $object -> fetch ( $origin_id )) { // This include the fetch_lines
2020-09-07 10:18:17 +02:00
$soc = new Societe ( $db );
$soc -> fetch ( $object -> socid );
2012-03-14 14:48:27 +01:00
2020-09-07 10:18:17 +02:00
$author = new User ( $db );
$author -> fetch ( $object -> user_author_id );
2012-03-14 14:48:27 +01:00
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> stock -> enabled )) {
$entrepot = new Entrepot ( $db );
}
2012-03-14 14:48:27 +01:00
2020-09-07 10:18:17 +02:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="action" value="add">' ;
print '<input type="hidden" name="origin" value="' . $origin . '">' ;
print '<input type="hidden" name="origin_id" value="' . $object -> id . '">' ;
print '<input type="hidden" name="ref_int" value="' . $object -> ref_int . '">' ;
2021-02-25 22:38:35 +01:00
if ( GETPOST ( 'entrepot_id' , 'int' )) {
2020-09-07 10:18:17 +02:00
print '<input type="hidden" name="entrepot_id" value="' . GETPOST ( 'entrepot_id' , 'int' ) . '">' ;
}
2012-03-14 14:48:27 +01:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( '' );
2015-07-13 11:22:18 +02:00
2020-09-07 10:18:17 +02:00
print '<table class="border centpercent">' ;
2012-03-14 14:48:27 +01:00
2020-09-07 10:18:17 +02:00
// Ref
print '<tr><td class="titlefieldcreate fieldrequired">' ;
2021-02-25 22:38:35 +01:00
if ( $origin == 'commande' && ! empty ( $conf -> commande -> enabled )) {
2020-10-25 17:02:25 +01:00
print $langs -> trans ( " RefOrder " );
2020-09-07 10:18:17 +02:00
}
2021-02-25 22:38:35 +01:00
if ( $origin == 'propal' && ! empty ( $conf -> propal -> enabled )) {
2020-10-25 17:02:25 +01:00
print $langs -> trans ( " RefProposal " );
2020-09-07 10:18:17 +02:00
}
2020-10-25 17:02:25 +01:00
print '</td><td colspan="3">' ;
print $object -> getNomUrl ( 1 );
print '</td>' ;
2020-09-07 10:18:17 +02:00
print " </tr> \n " ;
2017-05-19 08:50:10 +02:00
2020-09-07 10:18:17 +02:00
// Ref client
print '<tr><td>' ;
2021-02-25 22:38:35 +01:00
if ( $origin == 'commande' ) {
print $langs -> trans ( 'RefCustomerOrder' );
} elseif ( $origin == 'propal' ) {
print $langs -> trans ( 'RefCustomerOrder' );
} else {
print $langs -> trans ( 'RefCustomer' );
}
2020-09-07 10:18:17 +02:00
print '</td><td colspan="3">' ;
print '<input type="text" name="ref_customer" value="' . $object -> ref_client . '" />' ;
print '</td>' ;
print '</tr>' ;
2012-03-14 14:48:27 +01:00
2020-09-07 10:18:17 +02:00
// Tiers
print '<tr><td class="titlefieldcreate fieldrequired">' . $langs -> trans ( 'Company' ) . '</td>' ;
print '<td colspan="3">' . $soc -> getNomUrl ( 1 ) . '</td>' ;
print '</tr>' ;
// Project
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> projet -> enabled )) {
2020-09-07 10:18:17 +02:00
$projectid = GETPOST ( 'projectid' , 'int' ) ? GETPOST ( 'projectid' , 'int' ) : 0 ;
2021-02-25 22:38:35 +01:00
if ( empty ( $projectid ) && ! empty ( $object -> fk_project )) {
$projectid = $object -> fk_project ;
}
if ( $origin == 'project' ) {
$projectid = ( $originid ? $originid : 0 );
}
2020-09-07 10:18:17 +02:00
$langs -> load ( " projects " );
print '<tr>' ;
print '<td>' . $langs -> trans ( " Project " ) . '</td><td colspan="2">' ;
print img_picto ( '' , 'project' );
$numprojet = $formproject -> select_projects ( $soc -> id , $projectid , 'projectid' , 0 );
print ' <a class="paddingleft" href="' . DOL_URL_ROOT . '/projet/card.php?socid=' . $soc -> id . '&action=create&status=1&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ] . '?action=create&socid=' . $soc -> id ) . '"><span class="fa fa-plus-circle valignmiddle"></span></a>' ;
print '</td>' ;
print '</tr>' ;
}
// Date delivery planned
print '<tr><td>' . $langs -> trans ( " DateDeliveryPlanned " ) . '</td>' ;
print '<td colspan="3">' ;
2020-11-16 12:20:18 +01:00
$date_delivery = ( $date_delivery ? $date_delivery : $object -> delivery_date ); // $date_delivery comes from GETPOST
2020-09-07 10:18:17 +02:00
print $form -> selectDate ( $date_delivery ? $date_delivery : - 1 , 'date_delivery' , 1 , 1 , 1 );
print " </td> \n " ;
print '</tr>' ;
// Note Public
print '<tr><td>' . $langs -> trans ( " NotePublic " ) . '</td>' ;
print '<td colspan="3">' ;
2020-11-30 14:54:44 +01:00
$doleditor = new DolEditor ( 'note_public' , $object -> note_public , '' , 60 , 'dolibarr_notes' , 'In' , 0 , false , empty ( $conf -> global -> FCKEDITOR_ENABLE_NOTE_PUBLIC ) ? 0 : 1 , ROWS_3 , '90%' );
2020-09-07 10:18:17 +02:00
print $doleditor -> Create ( 1 );
print " </td></tr> " ;
// Note Private
2021-02-25 22:38:35 +01:00
if ( $object -> note_private && ! $user -> socid ) {
2020-09-07 10:18:17 +02:00
print '<tr><td>' . $langs -> trans ( " NotePrivate " ) . '</td>' ;
print '<td colspan="3">' ;
2020-11-30 14:54:44 +01:00
$doleditor = new DolEditor ( 'note_private' , $object -> note_private , '' , 60 , 'dolibarr_notes' , 'In' , 0 , false , empty ( $conf -> global -> FCKEDITOR_ENABLE_NOTE_PRIVATE ) ? 0 : 1 , ROWS_3 , '90%' );
2020-09-07 10:18:17 +02:00
print $doleditor -> Create ( 1 );
print " </td></tr> " ;
}
// Weight
print '<tr><td>' ;
print $langs -> trans ( " Weight " );
print '</td><td colspan="3"><input name="weight" size="4" value="' . GETPOST ( 'weight' , 'int' ) . '"> ' ;
$text = $formproduct -> selectMeasuringUnits ( " weight_units " , " weight " , GETPOST ( 'weight_units' , 'int' ), 0 , 2 );
$htmltext = $langs -> trans ( " KeepEmptyForAutoCalculation " );
print $form -> textwithpicto ( $text , $htmltext );
print '</td></tr>' ;
// Dim
print '<tr><td>' ;
print $langs -> trans ( " Width " ) . ' x ' . $langs -> trans ( " Height " ) . ' x ' . $langs -> trans ( " Depth " );
print ' </td><td colspan="3"><input name="sizeW" size="4" value="' . GETPOST ( 'sizeW' , 'int' ) . '">' ;
print ' x <input name="sizeH" size="4" value="' . GETPOST ( 'sizeH' , 'int' ) . '">' ;
print ' x <input name="sizeS" size="4" value="' . GETPOST ( 'sizeS' , 'int' ) . '">' ;
print ' ' ;
$text = $formproduct -> selectMeasuringUnits ( " size_units " , " size " , GETPOST ( 'size_units' , 'int' ), 0 , 2 );
$htmltext = $langs -> trans ( " KeepEmptyForAutoCalculation " );
print $form -> textwithpicto ( $text , $htmltext );
print '</td></tr>' ;
// Delivery method
print " <tr><td> " . $langs -> trans ( " DeliveryMethod " ) . " </td> " ;
print '<td colspan="3">' ;
$expe -> fetch_delivery_methods ();
print $form -> selectarray ( " shipping_method_id " , $expe -> meths , GETPOST ( 'shipping_method_id' , 'int' ), 1 , 0 , 0 , " " , 1 );
2021-02-25 22:38:35 +01:00
if ( $user -> admin ) {
print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
}
2020-09-07 10:18:17 +02:00
print " </td></tr> \n " ;
// Tracking number
print " <tr><td> " . $langs -> trans ( " TrackingNumber " ) . " </td> " ;
print '<td colspan="3">' ;
print '<input name="tracking_number" size="20" value="' . GETPOST ( 'tracking_number' , 'alpha' ) . '">' ;
print " </td></tr> \n " ;
// Other attributes
$parameters = array ( 'objectsrc' => $objectsrc , 'colspan' => ' colspan="3"' , 'cols' => '3' , 'socid' => $socid );
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $expe , $action ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
2017-06-07 16:44:04 +02:00
2018-04-13 13:28:48 +02:00
if ( empty ( $reshook )) {
2017-09-19 18:43:00 +02:00
// copy from order
2018-02-21 14:48:25 +01:00
if ( $object -> fetch_optionals () > 0 ) {
2017-09-19 18:43:00 +02:00
$expe -> array_options = array_merge ( $expe -> array_options , $object -> array_options );
}
2019-11-16 14:38:05 +01:00
print $expe -> showOptionals ( $extrafields , 'edit' , $parameters );
2017-09-19 18:43:00 +02:00
}
2017-06-07 16:44:04 +02:00
2012-03-14 14:48:27 +01:00
2020-09-08 21:27:28 +02:00
// Incoterms
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> incoterm -> enabled )) {
2015-02-23 09:16:14 +01:00
print '<tr>' ;
2019-06-25 13:00:02 +02:00
print '<td><label for="incoterm_id">' . $form -> textwithpicto ( $langs -> trans ( " IncotermLabel " ), $object -> label_incoterms , 1 ) . '</label></td>' ;
2020-09-08 21:27:28 +02:00
print '<td colspan="3" class="maxwidthonsmartphone">' ;
print $form -> select_incoterms (( ! empty ( $object -> fk_incoterms ) ? $object -> fk_incoterms : '' ), ( ! empty ( $object -> location_incoterms ) ? $object -> location_incoterms : '' ));
2015-02-23 09:16:14 +01:00
print '</td></tr>' ;
}
2015-03-18 21:44:57 +01:00
2020-09-08 21:27:28 +02:00
// Document model
2019-11-13 19:35:39 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/expedition/modules_expedition.php' ;
2021-02-09 14:21:39 +01:00
$list = ModelePdfExpedition :: liste_modeles ( $db );
2021-02-25 22:38:35 +01:00
if ( count ( $list ) > 1 ) {
2020-09-08 21:27:28 +02:00
print " <tr><td> " . $langs -> trans ( " DefaultModel " ) . " </td> " ;
print '<td colspan="3">' ;
2021-02-09 14:21:39 +01:00
print $form -> selectarray ( 'model' , $list , $conf -> global -> EXPEDITION_ADDON_PDF );
2020-09-08 21:27:28 +02:00
print " </td></tr> \n " ;
2016-04-01 11:12:49 +02:00
}
2017-06-07 16:44:04 +02:00
2020-09-08 21:27:28 +02:00
print " </table> " ;
2012-03-14 14:48:27 +01:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2015-07-13 11:22:18 +02:00
2017-06-07 16:44:04 +02:00
2020-09-08 21:27:28 +02:00
// Shipment lines
2013-08-07 15:08:30 +02:00
2020-09-08 21:27:28 +02:00
$numAsked = count ( $object -> lines );
2013-08-07 15:08:30 +02:00
2020-09-08 21:27:28 +02:00
print ' < script type = " text/javascript " language = " javascript " >
2013-04-21 14:14:30 +02:00
jQuery ( document ) . ready ( function () {
jQuery ( " #autofill " ) . click ( function () { ' ;
2020-09-08 21:27:28 +02:00
$i = 0 ;
2021-02-25 22:38:35 +01:00
while ( $i < $numAsked ) {
2020-09-08 21:27:28 +02:00
print 'jQuery("#qtyl' . $i . '").val(jQuery("#qtyasked' . $i . '").val() - jQuery("#qtydelivered' . $i . '").val());' . " \n " ;
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> productbatch -> enabled )) {
print 'jQuery("#qtyl' . $i . '_' . $i . '").val(jQuery("#qtyasked' . $i . '").val() - jQuery("#qtydelivered' . $i . '").val());' . " \n " ;
}
2020-09-08 21:27:28 +02:00
$i ++ ;
}
print ' });
2021-03-04 08:52:55 +01:00
jQuery ( " #autoreset " ) . click ( function () { console . log ( " Reset values to 0 " ); jQuery ( " .qtyl " ) . val ( 0 ); });
2013-04-21 14:14:30 +02:00
});
</ script > ' ;
2013-08-07 15:08:30 +02:00
2020-09-08 21:27:28 +02:00
print '<br>' ;
2017-06-07 16:44:04 +02:00
2020-09-08 21:27:28 +02:00
print '<table class="noborder centpercent">' ;
2013-04-14 12:19:21 +02:00
2020-09-08 21:27:28 +02:00
// Load shipments already done for same order
$object -> loadExpeditions ();
2017-06-07 16:44:04 +02:00
2021-02-25 22:38:35 +01:00
if ( $numAsked ) {
2020-09-08 21:27:28 +02:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " Description " ) . '</td>' ;
print '<td class="center">' . $langs -> trans ( " QtyOrdered " ) . '</td>' ;
print '<td class="center">' . $langs -> trans ( " QtyShipped " ) . '</td>' ;
print '<td class="center">' . $langs -> trans ( " QtyToShip " );
2021-02-25 22:38:35 +01:00
if ( empty ( $conf -> productbatch -> enabled )) {
2021-04-09 13:15:27 +02:00
print '<br><a href="#" id="autofill" class="opacitymedium link cursor cursorpointer">' . img_picto ( $langs -> trans ( " Autofill " ), 'autofill' , 'class="paddingrightonly"' ) . $langs -> trans ( " Fill " ) . '</a>' ;
2020-09-08 21:27:28 +02:00
print ' / ' ;
2020-08-23 19:51:13 +02:00
} else {
print '<br>' ;
}
2020-11-16 16:31:05 +01:00
print '<span id="autoreset" class="opacitymedium link cursor cursorpointer">' . img_picto ( $langs -> trans ( " Reset " ), 'eraser' ) . '</span>' ;
2020-09-08 21:27:28 +02:00
print '</td>' ;
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> stock -> enabled )) {
if ( empty ( $conf -> productbatch -> enabled )) {
2020-09-08 21:27:28 +02:00
print '<td class="left">' . $langs -> trans ( " Warehouse " ) . ' (' . $langs -> trans ( " Stock " ) . ')</td>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-01-19 12:40:17 +01:00
print '<td class="left">' . $langs -> trans ( " Warehouse " ) . ' / ' . $langs -> trans ( " Batch " ) . ' (' . $langs -> trans ( " Stock " ) . ')</td>' ;
2014-03-07 11:35:16 +01:00
}
2020-09-08 21:27:28 +02:00
}
print " </tr> \n " ;
}
$indiceAsked = 0 ;
2021-02-25 22:38:35 +01:00
while ( $indiceAsked < $numAsked ) {
2020-09-08 21:27:28 +02:00
$product = new Product ( $db );
$line = $object -> lines [ $indiceAsked ];
$parameters = array ( 'i' => $indiceAsked , 'line' => $line , 'num' => $numAsked );
$reshook = $hookmanager -> executeHooks ( 'printObjectLine' , $parameters , $object , $action );
2021-02-25 22:38:35 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2020-09-08 21:27:28 +02:00
2021-02-25 22:38:35 +01:00
if ( empty ( $reshook )) {
2020-09-08 21:27:28 +02:00
// Show product and description
$type = $line -> product_type ? $line -> product_type : $line -> fk_product_type ;
// Try to enhance type detection using date_start and date_end for free lines where type
// was not saved.
2021-02-25 22:38:35 +01:00
if ( ! empty ( $line -> date_start )) {
$type = 1 ;
}
if ( ! empty ( $line -> date_end )) {
$type = 1 ;
}
2020-09-08 21:27:28 +02:00
2020-11-16 16:31:05 +01:00
print '<!-- line ' . $line -> id . ' for product -->' . " \n " ;
2020-09-08 21:27:28 +02:00
print '<tr class="oddeven">' . " \n " ;
// Product label
2021-02-25 22:38:35 +01:00
if ( $line -> fk_product > 0 ) { // If predefined product
2020-09-08 21:27:28 +02:00
$product -> fetch ( $line -> fk_product );
$product -> load_stock ( 'warehouseopen' ); // Load all $product->stock_warehouse[idwarehouse]->detail_batch
//var_dump($product->stock_warehouse[1]);
print '<td>' ;
2020-11-16 16:31:05 +01:00
print '<a name="' . $line -> id . '"></a>' ; // ancre pour retourner sur la ligne
2020-09-08 21:27:28 +02:00
// Show product and description
$product_static -> type = $line -> fk_product_type ;
$product_static -> id = $line -> fk_product ;
$product_static -> ref = $line -> ref ;
2020-11-16 16:31:05 +01:00
$product_static -> status = $line -> product_tosell ;
$product_static -> status_buy = $line -> product_tobuy ;
2020-09-08 21:27:28 +02:00
$product_static -> status_batch = $line -> product_tobatch ;
2020-11-16 16:31:05 +01:00
2020-09-08 21:27:28 +02:00
$text = $product_static -> getNomUrl ( 1 );
$text .= ' - ' . ( ! empty ( $line -> label ) ? $line -> label : $line -> product_label );
$description = ( $conf -> global -> PRODUIT_DESC_IN_FORM ? '' : dol_htmlentitiesbr ( $line -> desc ));
print $form -> textwithtooltip ( $text , $description , 3 , '' , '' , $i );
// Show range
print_date_range ( $db -> jdate ( $line -> date_start ), $db -> jdate ( $line -> date_end ));
// Add description in form
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_DESC_IN_FORM )) {
2020-09-08 21:27:28 +02:00
print ( $line -> desc && $line -> desc != $line -> product_label ) ? '<br>' . dol_htmlentitiesbr ( $line -> desc ) : '' ;
}
print '</td>' ;
} else {
print " <td> " ;
2021-02-25 22:38:35 +01:00
if ( $type == 1 ) {
$text = img_object ( $langs -> trans ( 'Service' ), 'service' );
} else {
$text = img_object ( $langs -> trans ( 'Product' ), 'product' );
}
2020-09-08 21:27:28 +02:00
if ( ! empty ( $line -> label )) {
$text .= ' <strong>' . $line -> label . '</strong>' ;
print $form -> textwithtooltip ( $text , $line -> desc , 3 , '' , '' , $i );
} else {
print $text . ' ' . nl2br ( $line -> desc );
}
// Show range
print_date_range ( $db -> jdate ( $line -> date_start ), $db -> jdate ( $line -> date_end ));
print " </td> \n " ;
}
// Qty
print '<td class="center">' . $line -> qty ;
print '<input name="qtyasked' . $indiceAsked . '" id="qtyasked' . $indiceAsked . '" type="hidden" value="' . $line -> qty . '">' ;
print '</td>' ;
$qtyProdCom = $line -> qty ;
// Qty already shipped
print '<td class="center">' ;
$quantityDelivered = $object -> expeditions [ $line -> id ];
print $quantityDelivered ;
print '<input name="qtydelivered' . $indiceAsked . '" id="qtydelivered' . $indiceAsked . '" type="hidden" value="' . $quantityDelivered . '">' ;
print '</td>' ;
// Qty to ship
$quantityAsked = $line -> qty ;
2021-02-25 22:38:35 +01:00
if ( $line -> product_type == 1 && empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES )) {
2019-03-12 11:28:36 +01:00
$quantityToBeDelivered = 0 ;
2020-05-21 15:05:19 +02:00
} else {
2019-03-12 11:28:36 +01:00
$quantityToBeDelivered = $quantityAsked - $quantityDelivered ;
}
2020-09-08 21:27:28 +02:00
$warehouse_id = GETPOST ( 'entrepot_id' , 'int' );
2017-06-07 16:44:04 +02:00
2019-03-12 11:28:36 +01:00
$warehouseObject = null ;
2021-02-25 22:38:35 +01:00
if ( $warehouse_id > 0 || ! ( $line -> fk_product > 0 ) || empty ( $conf -> stock -> enabled )) { // If warehouse was already selected or if product is not a predefined, we go into this part with no multiwarehouse selection
2020-09-08 21:27:28 +02:00
print '<!-- Case warehouse already known or product not a predefined product -->' ;
2019-03-12 11:28:36 +01:00
//ship from preselected location
$stock = + $product -> stock_warehouse [ $warehouse_id ] -> real ; // Convert to number
2019-11-13 19:35:39 +01:00
$deliverableQty = min ( $quantityToBeDelivered , $stock );
2021-02-25 22:38:35 +01:00
if ( $deliverableQty < 0 ) {
$deliverableQty = 0 ;
}
if ( empty ( $conf -> productbatch -> enabled ) || ! $product -> hasbatch ()) {
2019-03-12 11:28:36 +01:00
// Quantity to send
2019-03-14 19:23:59 +01:00
print '<td class="center">' ;
2021-02-25 22:38:35 +01:00
if ( $line -> product_type == Product :: TYPE_PRODUCT || ! empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES )) {
if ( GETPOST ( 'qtyl' . $indiceAsked , 'int' )) {
$deliverableQty = GETPOST ( 'qtyl' . $indiceAsked , 'int' );
}
2020-09-07 10:18:17 +02:00
print '<input name="idl' . $indiceAsked . '" type="hidden" value="' . $line -> id . '">' ;
2019-03-12 11:28:36 +01:00
print '<input name="qtyl' . $indiceAsked . '" id="qtyl' . $indiceAsked . '" type="text" size="4" value="' . $deliverableQty . '">' ;
2021-02-25 22:38:35 +01:00
} else {
print $langs -> trans ( " NA " );
}
2019-03-12 11:28:36 +01:00
print '</td>' ;
2015-12-18 18:00:31 +01:00
2019-03-12 11:28:36 +01:00
// Stock
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> stock -> enabled )) {
2019-03-14 19:23:59 +01:00
print '<td class="left">' ;
2021-02-25 22:38:35 +01:00
if ( $line -> product_type == Product :: TYPE_PRODUCT || ! empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES )) { // Type of product need stock change ?
2019-03-12 11:28:36 +01:00
// Show warehouse combo list
$ent = " entl " . $indiceAsked ;
$idl = " idl " . $indiceAsked ;
2019-11-13 19:35:39 +01:00
$tmpentrepot_id = is_numeric ( GETPOST ( $ent , 'int' )) ? GETPOST ( $ent , 'int' ) : $warehouse_id ;
2021-02-25 22:38:35 +01:00
if ( $line -> fk_product > 0 ) {
2020-09-07 10:18:17 +02:00
print '<!-- Show warehouse selection -->' ;
2019-09-09 16:58:20 +02:00
2020-09-07 10:18:17 +02:00
$stockMin = false ;
if ( empty ( $conf -> global -> STOCK_ALLOW_NEGATIVE_TRANSFER )) {
$stockMin = 0 ;
}
print $formproduct -> selectWarehouses ( $tmpentrepot_id , 'entl' . $indiceAsked , '' , 1 , 0 , $line -> fk_product , '' , 1 , 0 , array (), 'minwidth200' , '' , 1 , $stockMin , 'stock DESC, e.ref' );
2019-09-09 16:58:20 +02:00
2021-02-25 22:38:35 +01:00
if ( $tmpentrepot_id > 0 && $tmpentrepot_id == $warehouse_id ) {
2019-03-12 11:28:36 +01:00
//print $stock.' '.$quantityToBeDelivered;
2021-02-25 22:38:35 +01:00
if ( $stock < $quantityToBeDelivered ) {
2019-11-13 19:35:39 +01:00
print ' ' . img_warning ( $langs -> trans ( " StockTooLow " )); // Stock too low for this $warehouse_id but you can change warehouse
2019-03-12 11:28:36 +01:00
}
2016-01-12 13:56:00 +01:00
}
2015-12-18 18:00:31 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2019-03-12 11:28:36 +01:00
print $langs -> trans ( " Service " );
}
print '</td>' ;
2014-03-26 17:18:02 +01:00
}
2015-08-14 20:37:20 +02:00
2019-03-12 11:28:36 +01:00
print " </tr> \n " ;
2015-12-18 18:00:31 +01:00
2019-03-12 11:28:36 +01:00
// Show subproducts of product
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_SOUSPRODUITS ) && $line -> fk_product > 0 ) {
2019-03-12 11:28:36 +01:00
$product -> get_sousproduits_arbo ();
$prods_arbo = $product -> get_arbo_each_prod ( $qtyProdCom );
2021-02-25 22:38:35 +01:00
if ( count ( $prods_arbo ) > 0 ) {
foreach ( $prods_arbo as $key => $value ) {
2019-03-12 11:28:36 +01:00
//print $value[0];
2019-11-13 19:35:39 +01:00
$img = '' ;
2021-02-25 22:38:35 +01:00
if ( $value [ 'stock' ] < $value [ 'stock_alert' ]) {
2019-11-13 19:35:39 +01:00
$img = img_warning ( $langs -> trans ( " StockTooLow " ));
2019-03-12 11:28:36 +01:00
}
print " <tr class= \" oddeven \" ><td> ->
< a href = \ " " . DOL_URL_ROOT . " /product/card.php?id= " . $value [ 'id' ] . " \" > " . $value [ 'fullpath' ] . "
2021-02-07 18:49:46 +01:00
</ a > ( " . $value['nb'] . " ) </ td >< td class = \ " center \" > " . $value [ 'nb_total' ] . " </td><td> </td><td> </td>
2019-03-14 19:23:59 +01:00
< td class = \ " center \" > " . $value [ 'stock' ] . " " . $img . " </td></tr> " ;
2015-12-18 18:00:31 +01:00
}
}
}
2020-05-21 15:05:19 +02:00
} else {
2020-09-07 10:18:17 +02:00
// Product need lot
2019-11-13 19:35:39 +01:00
print '<td></td><td></td></tr>' ; // end line and start a new one for lot/serial
2019-03-12 11:28:36 +01:00
print '<!-- Case product need lot -->' ;
2017-06-07 16:44:04 +02:00
2019-11-13 19:35:39 +01:00
$staticwarehouse = new Entrepot ( $db );
2021-02-25 22:38:35 +01:00
if ( $warehouse_id > 0 ) {
$staticwarehouse -> fetch ( $warehouse_id );
}
2017-06-07 16:44:04 +02:00
2019-11-13 19:35:39 +01:00
$subj = 0 ;
2019-03-12 11:28:36 +01:00
// Define nb of lines suggested for this order line
2019-11-13 19:35:39 +01:00
$nbofsuggested = 0 ;
2021-02-25 22:38:35 +01:00
if ( is_object ( $product -> stock_warehouse [ $warehouse_id ]) && count ( $product -> stock_warehouse [ $warehouse_id ] -> detail_batch )) {
foreach ( $product -> stock_warehouse [ $warehouse_id ] -> detail_batch as $dbatch ) {
2020-09-07 10:18:17 +02:00
$nbofsuggested ++ ;
}
}
2019-03-12 11:28:36 +01:00
print '<input name="idl' . $indiceAsked . '" type="hidden" value="' . $line -> id . '">' ;
2021-02-25 22:38:35 +01:00
if ( is_object ( $product -> stock_warehouse [ $warehouse_id ]) && count ( $product -> stock_warehouse [ $warehouse_id ] -> detail_batch )) {
foreach ( $product -> stock_warehouse [ $warehouse_id ] -> detail_batch as $dbatch ) { // $dbatch is instance of Productbatch
2019-03-12 11:28:36 +01:00
//var_dump($dbatch);
2019-11-13 19:35:39 +01:00
$batchStock = + $dbatch -> qty ; // To get a numeric
2019-03-15 02:48:13 +01:00
$deliverableQty = min ( $quantityToBeDelivered , $batchStock );
2019-11-13 19:35:39 +01:00
print '<!-- subj=' . $subj . '/' . $nbofsuggested . ' --><tr ' . ((( $subj + 1 ) == $nbofsuggested ) ? $bc [ $var ] : '' ) . '>' ;
2019-03-14 19:23:59 +01:00
print '<td colspan="3" ></td><td class="center">' ;
2021-03-04 08:52:55 +01:00
print '<input class="qtyl" name="qtyl' . $indiceAsked . '_' . $subj . '" id="qtyl' . $indiceAsked . '_' . $subj . '" type="text" size="4" value="' . $deliverableQty . '">' ;
2019-03-12 11:28:36 +01:00
print '</td>' ;
2017-06-07 16:44:04 +02:00
2019-03-12 11:28:36 +01:00
print '<!-- Show details of lot -->' ;
2019-03-14 19:23:59 +01:00
print '<td class="left">' ;
2017-06-07 16:44:04 +02:00
2019-03-12 11:28:36 +01:00
print $staticwarehouse -> getNomUrl ( 0 ) . ' / ' ;
2017-06-07 16:44:04 +02:00
2019-03-12 11:28:36 +01:00
print '<input name="batchl' . $indiceAsked . '_' . $subj . '" type="hidden" value="' . $dbatch -> id . '">' ;
2017-12-02 10:43:01 +01:00
2019-11-13 19:35:39 +01:00
$detail = '' ;
$detail .= $langs -> trans ( " Batch " ) . ': ' . $dbatch -> batch ;
2020-08-20 12:13:27 +02:00
if ( empty ( $conf -> global -> PRODUCT_DISABLE_SELLBY )) {
$detail .= ' - ' . $langs -> trans ( " SellByDate " ) . ': ' . dol_print_date ( $dbatch -> sellby , " day " );
}
if ( empty ( $conf -> global -> PRODUCT_DISABLE_EATBY )) {
$detail .= ' - ' . $langs -> trans ( " EatByDate " ) . ': ' . dol_print_date ( $dbatch -> eatby , " day " );
}
2019-11-13 19:35:39 +01:00
$detail .= ' - ' . $langs -> trans ( " Qty " ) . ': ' . $dbatch -> qty ;
$detail .= '<br>' ;
2019-03-12 11:28:36 +01:00
print $detail ;
2017-12-02 10:43:01 +01:00
2019-03-12 11:28:36 +01:00
$quantityToBeDelivered -= $deliverableQty ;
2021-02-25 22:38:35 +01:00
if ( $quantityToBeDelivered < 0 ) {
2019-03-12 11:28:36 +01:00
$quantityToBeDelivered = 0 ;
}
$subj ++ ;
print '</td></tr>' ;
2015-12-18 18:00:31 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-09-07 10:18:17 +02:00
print '<!-- Case there is no details of lot at all -->' ;
print '<tr class="oddeven"><td colspan="3"></td><td class="center">' ;
2021-03-04 08:52:55 +01:00
print '<input class="qtyl" name="qtyl' . $indiceAsked . '_' . $subj . '" id="qtyl' . $indiceAsked . '_' . $subj . '" type="text" size="4" value="0" disabled="disabled"> ' ;
2020-09-07 10:18:17 +02:00
print '</td>' ;
print '<td class="left">' ;
print img_warning () . ' ' . $langs -> trans ( " NoProductToShipFoundIntoStock " , $staticwarehouse -> label );
print '</td></tr>' ;
2019-03-12 11:28:36 +01:00
}
2015-12-18 18:00:31 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2019-03-12 11:28:36 +01:00
// ship from multiple locations
2021-02-25 22:38:35 +01:00
if ( empty ( $conf -> productbatch -> enabled ) || ! $product -> hasbatch ()) {
2020-09-07 10:18:17 +02:00
print '<!-- Case warehouse not already known and product does not need lot -->' ;
print '<td></td><td></td></tr>' . " \n " ; // end line and start a new one for each warehouse
2019-03-12 11:28:36 +01:00
print '<input name="idl' . $indiceAsked . '" type="hidden" value="' . $line -> id . '">' ;
2019-11-13 19:35:39 +01:00
$subj = 0 ;
2020-09-07 10:18:17 +02:00
// Define nb of lines suggested for this order line
2019-11-13 19:35:39 +01:00
$nbofsuggested = 0 ;
2021-02-25 22:38:35 +01:00
foreach ( $product -> stock_warehouse as $warehouse_id => $stock_warehouse ) {
if ( $stock_warehouse -> real > 0 ) {
2020-09-07 10:18:17 +02:00
$nbofsuggested ++ ;
}
2019-03-12 11:28:36 +01:00
}
2019-11-13 19:35:39 +01:00
$tmpwarehouseObject = new Entrepot ( $db );
2021-02-25 22:38:35 +01:00
foreach ( $product -> stock_warehouse as $warehouse_id => $stock_warehouse ) { // $stock_warehouse is product_stock
2019-03-12 11:28:36 +01:00
$tmpwarehouseObject -> fetch ( $warehouse_id );
2021-02-25 22:38:35 +01:00
if ( $stock_warehouse -> real > 0 ) {
2019-03-12 11:28:36 +01:00
$stock = + $stock_warehouse -> real ; // Convert it to number
2019-03-15 02:48:13 +01:00
$deliverableQty = min ( $quantityToBeDelivered , $stock );
2019-03-12 11:28:36 +01:00
$deliverableQty = max ( 0 , $deliverableQty );
// Quantity to send
2019-11-13 19:35:39 +01:00
print '<!-- subj=' . $subj . '/' . $nbofsuggested . ' --><tr ' . ((( $subj + 1 ) == $nbofsuggested ) ? $bc [ $var ] : '' ) . '>' ;
2019-03-14 19:23:59 +01:00
print '<td colspan="3" ></td><td class="center"><!-- qty to ship (no lot management for product line indiceAsked=' . $indiceAsked . ') -->' ;
2021-02-25 22:38:35 +01:00
if ( $line -> product_type == Product :: TYPE_PRODUCT || ! empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES )) {
2019-03-12 11:28:36 +01:00
print '<input name="qtyl' . $indiceAsked . '_' . $subj . '" id="qtyl' . $indiceAsked . '" type="text" size="4" value="' . $deliverableQty . '">' ;
print '<input name="ent1' . $indiceAsked . '_' . $subj . '" type="hidden" value="' . $warehouse_id . '">' ;
2021-02-25 22:38:35 +01:00
} else {
print $langs -> trans ( " NA " );
}
2019-03-12 11:28:36 +01:00
print '</td>' ;
// Stock
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> stock -> enabled )) {
2019-03-14 19:23:59 +01:00
print '<td class="left">' ;
2021-02-25 22:38:35 +01:00
if ( $line -> product_type == Product :: TYPE_PRODUCT || ! empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES )) {
2019-03-12 11:28:36 +01:00
print $tmpwarehouseObject -> getNomUrl ( 0 ) . ' ' ;
2017-06-07 16:44:04 +02:00
2019-03-12 11:28:36 +01:00
print '<!-- Show details of stock -->' ;
print '(' . $stock . ')' ;
2020-05-21 15:05:19 +02:00
} else {
2019-03-12 11:28:36 +01:00
print $langs -> trans ( " Service " );
}
print '</td>' ;
2015-12-18 18:00:31 +01:00
}
2019-03-12 11:28:36 +01:00
$quantityToBeDelivered -= $deliverableQty ;
2021-02-25 22:38:35 +01:00
if ( $quantityToBeDelivered < 0 ) {
2019-03-12 11:28:36 +01:00
$quantityToBeDelivered = 0 ;
2015-12-18 18:00:31 +01:00
}
2019-03-12 11:28:36 +01:00
$subj ++ ;
print " </tr> \n " ;
2015-12-18 18:00:31 +01:00
}
}
2019-03-12 11:28:36 +01:00
// Show subproducts of product (not recommanded)
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_SOUSPRODUITS ) && $line -> fk_product > 0 ) {
2019-03-12 11:28:36 +01:00
$product -> get_sousproduits_arbo ();
$prods_arbo = $product -> get_arbo_each_prod ( $qtyProdCom );
2021-02-25 22:38:35 +01:00
if ( count ( $prods_arbo ) > 0 ) {
foreach ( $prods_arbo as $key => $value ) {
2019-03-12 11:28:36 +01:00
//print $value[0];
2019-11-13 19:35:39 +01:00
$img = '' ;
2021-02-25 22:38:35 +01:00
if ( $value [ 'stock' ] < $value [ 'stock_alert' ]) {
2019-11-13 19:35:39 +01:00
$img = img_warning ( $langs -> trans ( " StockTooLow " ));
2019-03-12 11:28:36 +01:00
}
print '<tr class"oddeven"><td>' ;
print " ->
< a href = \ " " . DOL_URL_ROOT . " /product/card.php?id= " . $value [ 'id' ] . " \" > " . $value [ 'fullpath' ] . "
2021-02-07 18:49:46 +01:00
</ a > ( " . $value['nb'] . " ) </ td >< td class = \ " center \" > " . $value [ 'nb_total' ] . " </td><td> </td><td> </td>
2019-03-14 19:23:59 +01:00
< td class = \ " center \" > " . $value [ 'stock' ] . " " . $img . " </td> " ;
2019-03-12 11:28:36 +01:00
print " </tr> " ;
2015-12-18 18:00:31 +01:00
}
}
2015-08-14 20:37:20 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-09-07 10:18:17 +02:00
print '<!-- Case warehouse not already known and product need lot -->' ;
print '<td></td><td></td></tr>' ; // end line and start a new one for lot/serial
2017-06-07 16:44:04 +02:00
2019-11-13 19:35:39 +01:00
$subj = 0 ;
2019-03-12 11:28:36 +01:00
print '<input name="idl' . $indiceAsked . '" type="hidden" value="' . $line -> id . '">' ;
2017-06-07 16:44:04 +02:00
2019-11-13 19:35:39 +01:00
$tmpwarehouseObject = new Entrepot ( $db );
$productlotObject = new Productlot ( $db );
2019-03-12 11:28:36 +01:00
// Define nb of lines suggested for this order line
2019-11-13 19:35:39 +01:00
$nbofsuggested = 0 ;
2021-02-25 22:38:35 +01:00
foreach ( $product -> stock_warehouse as $warehouse_id => $stock_warehouse ) {
2020-09-07 10:18:17 +02:00
if (( $stock_warehouse -> real > 0 ) && ( count ( $stock_warehouse -> detail_batch ))) {
2021-02-25 22:38:35 +01:00
foreach ( $stock_warehouse -> detail_batch as $dbatch ) {
2020-09-07 10:18:17 +02:00
$nbofsuggested ++ ;
2019-03-12 11:28:36 +01:00
}
2020-09-07 10:18:17 +02:00
}
2019-03-12 11:28:36 +01:00
}
2021-02-25 22:38:35 +01:00
foreach ( $product -> stock_warehouse as $warehouse_id => $stock_warehouse ) {
2019-03-12 11:28:36 +01:00
$tmpwarehouseObject -> fetch ( $warehouse_id );
if (( $stock_warehouse -> real > 0 ) && ( count ( $stock_warehouse -> detail_batch ))) {
2021-02-25 22:38:35 +01:00
foreach ( $stock_warehouse -> detail_batch as $dbatch ) {
2019-03-12 11:28:36 +01:00
//var_dump($dbatch);
2019-11-13 19:35:39 +01:00
$batchStock = + $dbatch -> qty ; // To get a numeric
2019-03-15 02:48:13 +01:00
$deliverableQty = min ( $quantityToBeDelivered , $batchStock );
2021-02-25 22:38:35 +01:00
if ( $deliverableQty < 0 ) {
$deliverableQty = 0 ;
}
2019-11-13 19:35:39 +01:00
print '<!-- subj=' . $subj . '/' . $nbofsuggested . ' --><tr ' . ((( $subj + 1 ) == $nbofsuggested ) ? $bc [ $var ] : '' ) . '><td colspan="3"></td><td class="center">' ;
2021-03-04 08:52:55 +01:00
print '<input class="qtyl" name="qtyl' . $indiceAsked . '_' . $subj . '" id="qtyl' . $indiceAsked . '_' . $subj . '" type="text" size="4" value="' . $deliverableQty . '">' ;
2019-03-12 11:28:36 +01:00
print '</td>' ;
2019-03-14 19:23:59 +01:00
print '<td class="left">' ;
2019-03-12 11:28:36 +01:00
print $tmpwarehouseObject -> getNomUrl ( 0 ) . ' / ' ;
print '<!-- Show details of lot -->' ;
print '<input name="batchl' . $indiceAsked . '_' . $subj . '" type="hidden" value="' . $dbatch -> id . '">' ;
//print '|'.$line->fk_product.'|'.$dbatch->batch.'|<br>';
print $langs -> trans ( " Batch " ) . ': ' ;
$result = $productlotObject -> fetch ( 0 , $line -> fk_product , $dbatch -> batch );
2021-02-25 22:38:35 +01:00
if ( $result > 0 ) {
print $productlotObject -> getNomUrl ( 1 );
} else {
print 'TableLotIncompleteRunRepairWithParamStandardEqualConfirmed' ;
}
2019-03-12 11:28:36 +01:00
print ' (' . $dbatch -> qty . ')' ;
$quantityToBeDelivered -= $deliverableQty ;
2021-02-25 22:38:35 +01:00
if ( $quantityToBeDelivered < 0 ) {
2019-03-12 11:28:36 +01:00
$quantityToBeDelivered = 0 ;
}
//dol_syslog('deliverableQty = '.$deliverableQty.' batchStock = '.$batchStock);
$subj ++ ;
print '</td></tr>' ;
2015-12-18 18:00:31 +01:00
}
}
}
}
2021-02-25 22:38:35 +01:00
if ( $subj == 0 ) { // Line not shown yet, we show it
2020-07-24 01:30:34 +02:00
$warehouse_selected_id = GETPOST ( 'entrepot_id' , 'int' );
print '<!-- line not shown yet, we show it -->' ;
print '<tr class="oddeven"><td colspan="3"></td><td class="center">' ;
2021-02-25 22:38:35 +01:00
if ( $line -> product_type == Product :: TYPE_PRODUCT || ! empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES )) {
2020-09-07 10:18:17 +02:00
$disabled = '' ;
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> productbatch -> enabled ) && $product -> hasbatch ()) {
2020-09-07 10:18:17 +02:00
$disabled = 'disabled="disabled"' ;
}
if ( $warehouse_selected_id <= 0 ) { // We did not force a given warehouse, so we won't have no warehouse to change qty.
$disabled = 'disabled="disabled"' ;
}
2021-03-04 08:52:55 +01:00
print '<input class="qtyl" name="qtyl' . $indiceAsked . '_' . $subj . '" id="qtyl' . $indiceAsked . '_' . $subj . '" type="text" size="4" value="0"' . ( $disabled ? ' ' . $disabled : '' ) . '> ' ;
2020-05-21 15:05:19 +02:00
} else {
2020-09-07 10:18:17 +02:00
print $langs -> trans ( " NA " );
2019-03-12 11:28:36 +01:00
}
print '</td>' ;
2017-06-07 16:44:04 +02:00
2019-03-14 19:23:59 +01:00
print '<td class="left">' ;
2021-02-25 22:38:35 +01:00
if ( $line -> product_type == Product :: TYPE_PRODUCT || ! empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES )) {
if ( $warehouse_selected_id > 0 ) {
2020-09-07 10:18:17 +02:00
$warehouseObject = new Entrepot ( $db );
$warehouseObject -> fetch ( $warehouse_selected_id );
print img_warning () . ' ' . $langs -> trans ( " NoProductToShipFoundIntoStock " , $warehouseObject -> label );
} else {
2021-02-25 22:38:35 +01:00
if ( $line -> fk_product ) {
print img_warning () . ' ' . $langs -> trans ( " StockTooLow " );
} else {
print '' ;
}
2020-09-07 10:18:17 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-09-07 10:18:17 +02:00
print $langs -> trans ( " Service " );
2019-03-12 11:28:36 +01:00
}
print '</td>' ;
print '</tr>' ;
2015-12-18 18:00:31 +01:00
}
2014-03-07 11:35:16 +01:00
}
2017-06-07 16:44:04 +02:00
2019-10-06 14:41:52 +02:00
// Line extrafield
2021-02-25 22:38:35 +01:00
if ( ! empty ( $extrafields )) {
2019-10-06 16:11:57 +02:00
//var_dump($line);
2020-04-10 10:59:32 +02:00
$colspan = 5 ;
2019-10-06 16:50:04 +02:00
$expLine = new ExpeditionLigne ( $db );
2019-03-12 11:28:36 +01:00
$srcLine = new OrderLine ( $db );
2020-03-27 16:02:58 +01:00
$srcLine -> id = $line -> id ;
$srcLine -> fetch_optionals (); // fetch extrafields also available in orderline
2020-11-25 15:06:07 +01:00
$expLine -> array_options = array_merge ( $expLine -> array_options , $srcLine -> array_options );
2019-10-06 14:41:52 +02:00
2020-02-21 14:32:23 +01:00
print $expLine -> showOptionals ( $extrafields , 'edit' , array ( 'style' => 'class="drag drop oddeven"' , 'colspan' => $colspan ), $indiceAsked , '' , 1 );
2019-03-12 11:28:36 +01:00
}
2020-09-07 10:18:17 +02:00
}
2019-07-29 13:54:48 +02:00
2020-09-07 10:18:17 +02:00
$indiceAsked ++ ;
}
2012-03-14 14:48:27 +01:00
2020-09-07 10:18:17 +02:00
print " </table> " ;
2013-08-07 15:08:30 +02:00
2020-09-07 10:18:17 +02:00
print '<br>' ;
2017-11-02 12:38:36 +01:00
2020-09-07 10:18:17 +02:00
print '<div class="center">' ;
print '<input type="submit" class="button" name="add" value="' . dol_escape_htmltag ( $langs -> trans ( " Create " )) . '">' ;
print ' ' ;
2020-11-23 15:12:52 +01:00
print '<input type="' . ( $backtopage ? " submit " : " button " ) . '" class="button button-cancel" name="cancel" value="' . dol_escape_htmltag ( $langs -> trans ( " Cancel " )) . '"' . ( $backtopage ? '' : ' onclick="javascript:history.go(-1)"' ) . '>' ; // Cancel for create does not post form if we don't know the backtopage
2020-09-07 10:18:17 +02:00
print '</div>' ;
2013-08-07 15:08:30 +02:00
2020-09-07 10:18:17 +02:00
print '</form>' ;
2013-08-07 15:08:30 +02:00
2020-09-07 10:18:17 +02:00
print '<br>' ;
} else {
dol_print_error ( $db );
}
}
2021-02-25 22:38:35 +01:00
} elseif ( $id || $ref ) {
/* *************************************************************************** */
/* */
/* Edit and view mode */
/* */
/* *************************************************************************** */
2013-08-07 15:08:30 +02:00
$lines = $object -> lines ;
2016-11-14 13:40:41 +01:00
2013-08-07 15:08:30 +02:00
$num_prod = count ( $lines );
2012-03-14 14:48:27 +01:00
2021-02-25 22:38:35 +01:00
if ( $object -> id > 0 ) {
if ( ! empty ( $object -> origin ) && $object -> origin_id > 0 ) {
2013-08-07 15:08:30 +02:00
$typeobject = $object -> origin ;
$origin = $object -> origin ;
2016-10-29 14:52:13 +02:00
$origin_id = $object -> origin_id ;
2019-11-13 19:35:39 +01:00
$object -> fetch_origin (); // Load property $object->commande, $object->propal, ...
2013-08-07 15:08:30 +02:00
}
$soc = new Societe ( $db );
$soc -> fetch ( $object -> socid );
2017-06-07 16:44:04 +02:00
2018-02-21 14:48:25 +01:00
$res = $object -> fetch_optionals ();
2013-08-07 15:08:30 +02:00
2019-11-13 19:35:39 +01:00
$head = shipping_prepare_head ( $object );
2021-05-10 19:33:45 +02:00
print dol_get_fiche_head ( $head , 'shipping' , $langs -> trans ( " Shipment " ), - 1 , $object -> picto );
2013-08-07 15:08:30 +02:00
2019-11-13 19:35:39 +01:00
$formconfirm = '' ;
2017-06-07 16:44:04 +02:00
2016-10-29 14:52:13 +02:00
// Confirm deleteion
2021-02-25 22:38:35 +01:00
if ( $action == 'delete' ) {
2020-09-07 10:18:17 +02:00
$formquestion = array ();
if ( $object -> statut == Expedition :: STATUS_CLOSED && ! empty ( $conf -> global -> STOCK_CALCULATE_ON_SHIPMENT_CLOSE )) {
$formquestion = array (
array (
'label' => $langs -> trans ( 'ShipmentIncrementStockOnDelete' ),
'name' => 'alsoUpdateStock' ,
'type' => 'checkbox' ,
'value' => 0
),
);
}
$formconfirm = $form -> formconfirm (
$_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id ,
$langs -> trans ( 'DeleteSending' ),
$langs -> trans ( " ConfirmDeleteSending " , $object -> ref ),
'confirm_delete' ,
$formquestion ,
0 ,
1
);
2013-08-07 15:08:30 +02:00
}
2016-10-29 14:52:13 +02:00
// Confirmation validation
2021-02-25 22:38:35 +01:00
if ( $action == 'valid' ) {
2013-08-07 15:08:30 +02:00
$objectref = substr ( $object -> ref , 1 , 4 );
2021-02-25 22:38:35 +01:00
if ( $objectref == 'PROV' ) {
2013-08-07 15:08:30 +02:00
$numref = $object -> getNextNumRef ( $soc );
2020-05-21 15:05:19 +02:00
} else {
2013-08-07 15:08:30 +02:00
$numref = $object -> ref ;
}
2012-03-14 14:48:27 +01:00
2019-01-27 11:55:16 +01:00
$text = $langs -> trans ( " ConfirmValidateSending " , $numref );
2012-03-14 14:48:27 +01:00
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> notification -> enabled )) {
2019-11-13 19:35:39 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php' ;
$notify = new Notify ( $db );
$text .= '<br>' ;
$text .= $notify -> confirmMessage ( 'SHIPPING_VALIDATE' , $object -> socid , $object );
2013-08-07 15:08:30 +02:00
}
2019-11-13 19:35:39 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $langs -> trans ( 'ValidateSending' ), $text , 'confirm_valid' , '' , 0 , 1 );
2013-08-07 15:08:30 +02:00
}
2016-10-29 14:52:13 +02:00
// Confirm cancelation
2021-02-25 22:38:35 +01:00
if ( $action == 'cancel' ) {
2019-11-13 19:35:39 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $langs -> trans ( 'CancelSending' ), $langs -> trans ( " ConfirmCancelSending " , $object -> ref ), 'confirm_cancel' , '' , 0 , 1 );
2013-08-07 15:08:30 +02:00
}
2018-08-30 11:27:48 +02:00
// Call Hook formConfirm
2020-01-28 12:00:27 +01:00
$parameters = array ( 'formConfirm' => $formconfirm );
2018-08-30 11:27:48 +02:00
$reshook = $hookmanager -> executeHooks ( 'formConfirm' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2021-02-25 22:38:35 +01:00
if ( empty ( $reshook )) {
$formconfirm .= $hookmanager -> resPrint ;
} elseif ( $reshook > 0 ) {
$formconfirm = $hookmanager -> resPrint ;
}
2017-06-07 16:44:04 +02:00
2016-09-19 13:57:50 +02:00
// Print form confirm
print $formconfirm ;
2017-06-07 16:44:04 +02:00
2016-02-25 13:46:38 +01:00
// Calculate totalWeight and totalVolume for all products
2013-08-07 15:08:30 +02:00
// by adding weight and volume of each product line.
2019-11-13 19:35:39 +01:00
$tmparray = $object -> getTotalWeightVolume ();
$totalWeight = $tmparray [ 'weight' ];
$totalVolume = $tmparray [ 'volume' ];
2017-06-07 16:44:04 +02:00
2021-02-25 22:38:35 +01:00
if ( $typeobject == 'commande' && $object -> $typeobject -> id && ! empty ( $conf -> commande -> enabled )) {
2020-09-07 10:18:17 +02:00
$objectsrc = new Commande ( $db );
$objectsrc -> fetch ( $object -> $typeobject -> id );
2016-10-29 14:52:13 +02:00
}
2021-02-25 22:38:35 +01:00
if ( $typeobject == 'propal' && $object -> $typeobject -> id && ! empty ( $conf -> propal -> enabled )) {
2020-09-07 10:18:17 +02:00
$objectsrc = new Propal ( $db );
$objectsrc -> fetch ( $object -> $typeobject -> id );
2016-10-29 14:52:13 +02:00
}
2016-10-30 16:34:46 +01:00
2016-10-24 20:52:21 +02:00
// Shipment card
2019-11-13 19:35:39 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/expedition/list.php?restore_lastsearch_values=1' . ( ! empty ( $socid ) ? '&socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
$morehtmlref = '<div class="refidno">' ;
2016-09-19 13:57:50 +02:00
// Ref customer shipment
2019-11-13 19:35:39 +01:00
$morehtmlref .= $form -> editfieldkey ( " RefCustomer " , 'ref_customer' , $object -> ref_customer , $object , $user -> rights -> expedition -> creer , 'string' , '' , 0 , 1 );
$morehtmlref .= $form -> editfieldval ( " RefCustomer " , 'ref_customer' , $object -> ref_customer , $object , $user -> rights -> expedition -> creer , 'string' , '' , null , null , '' , 1 );
2016-09-19 13:57:50 +02:00
// Thirdparty
2020-09-07 10:18:17 +02:00
$morehtmlref .= '<br>' . $langs -> trans ( 'ThirdParty' ) . ' : ' . $object -> thirdparty -> getNomUrl ( 1 );
// Project
if ( ! empty ( $conf -> projet -> enabled )) {
$langs -> load ( " projects " );
$morehtmlref .= '<br>' . $langs -> trans ( 'Project' ) . ' ' ;
if ( 0 ) { // Do not change on shipment
if ( $action != 'classify' ) {
$morehtmlref .= '<a class="editfielda" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=classify&id=' . $object -> id . '">' . img_edit ( $langs -> transnoentitiesnoconv ( 'SetProject' )) . '</a> : ' ;
}
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" 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 {
// We don't have project on shipment, so we will use the project or source object instead
// TODO Add project on shipment
$morehtmlref .= ' : ' ;
if ( ! empty ( $objectsrc -> fk_project )) {
$proj = new Project ( $db );
$proj -> fetch ( $objectsrc -> fk_project );
$morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $objectsrc -> fk_project . '" title="' . $langs -> trans ( 'ShowProject' ) . '">' ;
$morehtmlref .= $proj -> ref ;
$morehtmlref .= '</a>' ;
} else {
$morehtmlref .= '' ;
}
}
}
2019-11-13 19:35:39 +01:00
$morehtmlref .= '</div>' ;
2017-06-07 16:44:04 +02:00
2016-10-29 14:52:13 +02:00
2020-09-07 10:18:17 +02:00
dol_banner_tab ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' , $morehtmlref );
2017-06-07 16:44:04 +02:00
2020-09-07 10:18:17 +02:00
print '<div class="fichecenter">' ;
print '<div class="fichehalfleft">' ;
print '<div class="underbanner clearboth"></div>' ;
2017-06-07 16:44:04 +02:00
2020-09-07 10:18:17 +02:00
print '<table class="border tableforfield" width="100%">' ;
2013-08-07 15:08:30 +02:00
// Linked documents
2021-02-25 22:38:35 +01:00
if ( $typeobject == 'commande' && $object -> $typeobject -> id && ! empty ( $conf -> commande -> enabled )) {
2013-08-07 15:08:30 +02:00
print '<tr><td>' ;
print $langs -> trans ( " RefOrder " ) . '</td>' ;
print '<td colspan="3">' ;
2019-01-27 11:55:16 +01:00
print $objectsrc -> getNomUrl ( 1 , 'commande' );
2013-08-07 15:08:30 +02:00
print " </td> \n " ;
print '</tr>' ;
}
2021-02-25 22:38:35 +01:00
if ( $typeobject == 'propal' && $object -> $typeobject -> id && ! empty ( $conf -> propal -> enabled )) {
2013-08-07 15:08:30 +02:00
print '<tr><td>' ;
print $langs -> trans ( " RefProposal " ) . '</td>' ;
print '<td colspan="3">' ;
2019-01-27 11:55:16 +01:00
print $objectsrc -> getNomUrl ( 1 , 'expedition' );
2013-08-07 15:08:30 +02:00
print " </td> \n " ;
print '</tr>' ;
}
// Date creation
2016-09-19 13:57:50 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " DateCreation " ) . '</td>' ;
2019-01-27 11:55:16 +01:00
print '<td colspan="3">' . dol_print_date ( $object -> date_creation , " dayhour " ) . " </td> \n " ;
2013-08-07 15:08:30 +02:00
print '</tr>' ;
// Delivery date planned
print '<tr><td height="10">' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( 'DateDeliveryPlanned' );
print '</td>' ;
2021-02-25 22:38:35 +01:00
if ( $action != 'editdate_livraison' ) {
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editdate_livraison&id=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetDeliveryDate' ), 1 ) . '</a></td>' ;
}
2013-08-07 15:08:30 +02:00
print '</tr></table>' ;
print '</td><td colspan="2">' ;
2021-02-25 22:38:35 +01:00
if ( $action == 'editdate_livraison' ) {
2013-08-07 15:08:30 +02:00
print '<form name="setdate_livraison" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="post">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2013-08-07 15:08:30 +02:00
print '<input type="hidden" name="action" value="setdate_livraison">' ;
2019-11-13 19:35:39 +01:00
print $form -> selectDate ( $object -> date_delivery ? $object -> date_delivery : - 1 , 'liv_' , 1 , 1 , '' , " setdate_livraison " , 1 , 0 );
2013-08-07 15:08:30 +02:00
print '<input type="submit" class="button" value="' . $langs -> trans ( 'Modify' ) . '">' ;
print '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-01-27 11:55:16 +01:00
print $object -> date_delivery ? dol_print_date ( $object -> date_delivery , 'dayhour' ) : ' ' ;
2013-08-07 15:08:30 +02:00
}
print '</td>' ;
print '</tr>' ;
// Weight
2016-02-24 13:19:25 +01:00
print '<tr><td>' ;
2019-01-27 11:55:16 +01:00
print $form -> editfieldkey ( " Weight " , 'trueWeight' , $object -> trueWeight , $object , $user -> rights -> expedition -> creer );
2016-02-24 13:19:25 +01:00
print '</td><td colspan="3">' ;
2014-06-20 12:03:41 +02:00
2021-02-25 22:38:35 +01:00
if ( $action == 'edittrueWeight' ) {
2014-05-14 17:20:11 +02:00
print '<form name="settrueweight" action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
print '<input name="action" value="settrueWeight" type="hidden">' ;
print '<input name="id" value="' . $object -> id . '" type="hidden">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-10-06 16:11:57 +02:00
print '<input id="trueWeight" name="trueWeight" value="' . $object -> trueWeight . '" type="text" class="width50">' ;
print $formproduct -> selectMeasuringUnits ( " weight_units " , " weight " , $object -> weight_units , 0 , 2 );
2014-05-14 17:20:11 +02:00
print ' <input class="button" name="modify" value="' . $langs -> trans ( " Modify " ) . '" type="submit">' ;
2020-11-23 15:12:52 +01:00
print ' <input class="button button-cancel" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '" type="submit">' ;
2014-05-14 17:20:11 +02:00
print '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2014-05-14 17:20:11 +02:00
print $object -> trueWeight ;
2020-04-10 10:59:32 +02:00
print ( $object -> trueWeight && $object -> weight_units != '' ) ? ' ' . measuringUnitString ( 0 , " weight " , $object -> weight_units ) : '' ;
2014-06-20 12:03:41 +02:00
}
2014-05-14 17:20:11 +02:00
2020-09-07 10:18:17 +02:00
// Calculated
2021-02-25 22:38:35 +01:00
if ( $totalWeight > 0 ) {
if ( ! empty ( $object -> trueWeight )) {
print ' (' . $langs -> trans ( " SumOfProductWeights " ) . ': ' ;
}
2020-04-10 10:59:32 +02:00
print showDimensionInBestUnit ( $totalWeight , 0 , " weight " , $langs , isset ( $conf -> global -> MAIN_WEIGHT_DEFAULT_ROUND ) ? $conf -> global -> MAIN_WEIGHT_DEFAULT_ROUND : - 1 , isset ( $conf -> global -> MAIN_WEIGHT_DEFAULT_UNIT ) ? $conf -> global -> MAIN_WEIGHT_DEFAULT_UNIT : 'no' );
2021-02-25 22:38:35 +01:00
if ( ! empty ( $object -> trueWeight )) {
print ')' ;
}
2013-08-07 15:08:30 +02:00
}
print '</td></tr>' ;
// Width
2019-01-27 11:55:16 +01:00
print '<tr><td>' . $form -> editfieldkey ( " Width " , 'trueWidth' , $object -> trueWidth , $object , $user -> rights -> expedition -> creer ) . '</td><td colspan="3">' ;
print $form -> editfieldval ( " Width " , 'trueWidth' , $object -> trueWidth , $object , $user -> rights -> expedition -> creer );
2020-04-10 10:59:32 +02:00
print ( $object -> trueWidth && $object -> width_units != '' ) ? ' ' . measuringUnitString ( 0 , " size " , $object -> width_units ) : '' ;
2013-08-07 15:08:30 +02:00
print '</td></tr>' ;
// Height
2019-01-27 11:55:16 +01:00
print '<tr><td>' . $form -> editfieldkey ( " Height " , 'trueHeight' , $object -> trueHeight , $object , $user -> rights -> expedition -> creer ) . '</td><td colspan="3">' ;
2021-02-25 22:38:35 +01:00
if ( $action == 'edittrueHeight' ) {
2014-05-14 17:20:11 +02:00
print '<form name="settrueHeight" action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
print '<input name="action" value="settrueHeight" type="hidden">' ;
print '<input name="id" value="' . $object -> id . '" type="hidden">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-10-06 16:11:57 +02:00
print '<input id="trueHeight" name="trueHeight" value="' . $object -> trueHeight . '" type="text" class="width50">' ;
print $formproduct -> selectMeasuringUnits ( " size_units " , " size " , $object -> size_units , 0 , 2 );
2014-05-14 17:20:11 +02:00
print ' <input class="button" name="modify" value="' . $langs -> trans ( " Modify " ) . '" type="submit">' ;
2020-11-23 15:12:52 +01:00
print ' <input class="button button-cancel" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '" type="submit">' ;
2014-05-14 17:20:11 +02:00
print '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2014-05-14 17:20:11 +02:00
print $object -> trueHeight ;
2020-04-10 10:59:32 +02:00
print ( $object -> trueHeight && $object -> height_units != '' ) ? ' ' . measuringUnitString ( 0 , " size " , $object -> height_units ) : '' ;
2014-05-14 17:20:11 +02:00
}
2014-06-20 12:03:41 +02:00
2013-08-07 15:08:30 +02:00
print '</td></tr>' ;
// Depth
2019-01-27 11:55:16 +01:00
print '<tr><td>' . $form -> editfieldkey ( " Depth " , 'trueDepth' , $object -> trueDepth , $object , $user -> rights -> expedition -> creer ) . '</td><td colspan="3">' ;
print $form -> editfieldval ( " Depth " , 'trueDepth' , $object -> trueDepth , $object , $user -> rights -> expedition -> creer );
2020-04-10 10:59:32 +02:00
print ( $object -> trueDepth && $object -> depth_units != '' ) ? ' ' . measuringUnitString ( 0 , " size " , $object -> depth_units ) : '' ;
2013-08-07 15:08:30 +02:00
print '</td></tr>' ;
// Volume
print '<tr><td>' ;
print $langs -> trans ( " Volume " );
print '</td>' ;
print '<td colspan="3">' ;
2019-11-13 19:35:39 +01:00
$calculatedVolume = 0 ;
$volumeUnit = 0 ;
2021-02-25 22:38:35 +01:00
if ( $object -> trueWidth && $object -> trueHeight && $object -> trueDepth ) {
2020-09-07 10:18:17 +02:00
$calculatedVolume = ( $object -> trueWidth * $object -> trueHeight * $object -> trueDepth );
$volumeUnit = $object -> size_units * 3 ;
2016-02-25 13:46:38 +01:00
}
2013-08-07 15:08:30 +02:00
// If sending volume not defined we use sum of products
2021-02-25 22:38:35 +01:00
if ( $calculatedVolume > 0 ) {
if ( $volumeUnit < 50 ) {
2020-09-07 10:18:17 +02:00
print showDimensionInBestUnit ( $calculatedVolume , $volumeUnit , " volume " , $langs , isset ( $conf -> global -> MAIN_VOLUME_DEFAULT_ROUND ) ? $conf -> global -> MAIN_VOLUME_DEFAULT_ROUND : - 1 , isset ( $conf -> global -> MAIN_VOLUME_DEFAULT_UNIT ) ? $conf -> global -> MAIN_VOLUME_DEFAULT_UNIT : 'no' );
2021-02-25 22:38:35 +01:00
} else {
print $calculatedVolume . ' ' . measuringUnitString ( 0 , " volume " , $volumeUnit );
}
2013-08-07 15:08:30 +02:00
}
2021-02-25 22:38:35 +01:00
if ( $totalVolume > 0 ) {
if ( $calculatedVolume ) {
print ' (' . $langs -> trans ( " SumOfProductVolumes " ) . ': ' ;
}
2020-04-10 10:59:32 +02:00
print showDimensionInBestUnit ( $totalVolume , 0 , " volume " , $langs , isset ( $conf -> global -> MAIN_VOLUME_DEFAULT_ROUND ) ? $conf -> global -> MAIN_VOLUME_DEFAULT_ROUND : - 1 , isset ( $conf -> global -> MAIN_VOLUME_DEFAULT_UNIT ) ? $conf -> global -> MAIN_VOLUME_DEFAULT_UNIT : 'no' );
2016-02-24 13:19:25 +01:00
//if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')';
2021-02-25 22:38:35 +01:00
if ( $calculatedVolume ) {
print ')' ;
}
2013-08-07 15:08:30 +02:00
}
print " </td> \n " ;
print '</tr>' ;
2016-09-19 13:57:50 +02:00
// Other attributes
$cols = 2 ;
2019-11-13 19:35:39 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php' ;
2017-06-07 16:44:04 +02:00
2016-09-19 13:57:50 +02:00
print '</table>' ;
2017-06-07 16:44:04 +02:00
2016-09-19 13:57:50 +02:00
print '</div>' ;
print '<div class="fichehalfright">' ;
print '<div class="ficheaddleft">' ;
print '<div class="underbanner clearboth"></div>' ;
2017-06-07 16:44:04 +02:00
2020-07-26 19:27:29 +02:00
print '<table class="border centpercent tableforfield">' ;
2013-08-07 15:08:30 +02:00
// Sending method
print '<tr><td height="10">' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( 'SendingMethod' );
print '</td>' ;
2021-02-25 22:38:35 +01:00
if ( $action != 'editshipping_method_id' ) {
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editshipping_method_id&id=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetSendingMethod' ), 1 ) . '</a></td>' ;
}
2013-08-07 15:08:30 +02:00
print '</tr></table>' ;
print '</td><td colspan="2">' ;
2021-02-25 22:38:35 +01:00
if ( $action == 'editshipping_method_id' ) {
2013-08-07 15:08:30 +02:00
print '<form name="setshipping_method_id" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="post">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2013-08-07 15:08:30 +02:00
print '<input type="hidden" name="action" value="setshipping_method_id">' ;
$object -> fetch_delivery_methods ();
2019-01-27 11:55:16 +01:00
print $form -> selectarray ( " shipping_method_id " , $object -> meths , $object -> shipping_method_id , 1 , 0 , 0 , " " , 1 );
2021-02-25 22:38:35 +01:00
if ( $user -> admin ) {
print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
}
2013-08-07 15:08:30 +02:00
print '<input type="submit" class="button" value="' . $langs -> trans ( 'Modify' ) . '">' ;
print '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-25 22:38:35 +01:00
if ( $object -> shipping_method_id > 0 ) {
2013-08-07 15:08:30 +02:00
// Get code using getLabelFromKey
2019-11-13 19:35:39 +01:00
$code = $langs -> getLabelFromKey ( $db , $object -> shipping_method_id , 'c_shipment_mode' , 'rowid' , 'code' );
2013-08-07 15:08:30 +02:00
print $langs -> trans ( " SendingMethod " . strtoupper ( $code ));
}
}
print '</td>' ;
print '</tr>' ;
2017-06-07 16:44:04 +02:00
2013-08-07 15:08:30 +02:00
// Tracking Number
2019-01-27 11:55:16 +01:00
print '<tr><td class="titlefield">' . $form -> editfieldkey ( " TrackingNumber " , 'tracking_number' , $object -> tracking_number , $object , $user -> rights -> expedition -> creer ) . '</td><td colspan="3">' ;
2020-03-06 17:22:41 +01:00
print $form -> editfieldval ( " TrackingNumber " , 'tracking_number' , $object -> tracking_url , $object , $user -> rights -> expedition -> creer , 'safehtmlstring' , $object -> tracking_number );
2013-08-07 15:08:30 +02:00
print '</td></tr>' ;
2015-02-23 09:16:14 +01:00
// Incoterms
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> incoterm -> enabled )) {
2015-02-23 09:16:14 +01:00
print '<tr><td>' ;
2020-09-07 10:18:17 +02:00
print '<table width="100%" class="nobordernopadding"><tr><td>' ;
print $langs -> trans ( 'IncotermLabel' );
print '<td><td class="right">' ;
2021-02-25 22:38:35 +01:00
if ( $user -> rights -> expedition -> creer ) {
print '<a class="editfielda" href="' . DOL_URL_ROOT . '/expedition/card.php?id=' . $object -> id . '&action=editincoterm">' . img_edit () . '</a>' ;
} else {
print ' ' ;
}
2020-09-07 10:18:17 +02:00
print '</td></tr></table>' ;
print '</td>' ;
print '<td colspan="3">' ;
2021-02-25 22:38:35 +01:00
if ( $action != 'editincoterm' ) {
2019-06-25 13:00:02 +02:00
print $form -> textwithpicto ( $object -> display_incoterms (), $object -> label_incoterms , 1 );
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
print $form -> select_incoterms (( ! empty ( $object -> fk_incoterms ) ? $object -> fk_incoterms : '' ), ( ! empty ( $object -> location_incoterms ) ? $object -> location_incoterms : '' ), $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id );
2015-02-23 09:16:14 +01:00
}
2020-09-07 10:18:17 +02:00
print '</td></tr>' ;
2015-02-23 09:16:14 +01:00
}
2019-03-12 11:28:36 +01:00
// Other attributes
2019-11-16 14:38:05 +01:00
$parameters = array ( 'colspan' => ' colspan="3"' , 'cols' => '3' );
2019-11-13 19:35:39 +01:00
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2019-03-12 11:28:36 +01:00
print $hookmanager -> resPrint ;
2016-09-19 13:57:50 +02:00
print " </table> " ;
2017-06-07 16:44:04 +02:00
2016-09-19 13:57:50 +02:00
print '</div>' ;
print '</div>' ;
print '</div>' ;
2017-06-07 16:44:04 +02:00
2016-09-19 13:57:50 +02:00
print '<div class="clearboth"></div>' ;
2017-06-07 16:44:04 +02:00
2013-08-07 15:08:30 +02:00
2017-12-01 14:33:06 +01:00
// Lines of products
2021-02-25 22:38:35 +01:00
if ( $action == 'editline' ) {
2019-11-13 19:35:39 +01:00
print ' <form name="updateline" id="updateline" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&lineid=' . $line_id . ' " method= " POST " >
2020-03-24 13:10:35 +01:00
< input type = " hidden " name = " token " value = " ' . newToken().' " >
2017-10-23 22:18:15 +02:00
< input type = " hidden " name = " action " value = " updateline " >
< input type = " hidden " name = " mode " value = " " >
2019-11-13 19:35:39 +01:00
< input type = " hidden " name = " id " value = " ' . $object->id .' " >
2017-10-23 22:18:15 +02:00
' ;
}
2017-03-02 01:26:15 +01:00
print '<br>' ;
2017-06-07 16:44:04 +02:00
2020-09-07 10:18:17 +02:00
print '<div class="div-table-responsive-no-min">' ;
2019-09-16 16:49:08 +02:00
print '<table class="noborder" width="100%" id="tablelines" >' ;
print '<thead>' ;
2013-08-07 15:08:30 +02:00
print '<tr class="liste_titre">' ;
2018-09-25 17:26:57 +02:00
// Adds a line numbering column
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> global -> MAIN_VIEW_LINE_NUMBER )) {
2019-09-16 16:49:08 +02:00
print '<td width="5" class="center linecolnum"> </td>' ;
2013-08-07 15:08:30 +02:00
}
2017-12-01 14:33:06 +01:00
// Product/Service
2019-09-16 16:49:08 +02:00
print '<td class="linecoldescription" >' . $langs -> trans ( " Products " ) . '</td>' ;
2017-12-01 14:33:06 +01:00
// Qty
2019-09-16 16:49:08 +02:00
print '<td class="center linecolqty">' . $langs -> trans ( " QtyOrdered " ) . '</td>' ;
2021-02-25 22:38:35 +01:00
if ( $origin && $origin_id > 0 ) {
2019-09-16 16:49:08 +02:00
print '<td class="center linecolqtyinothershipments">' . $langs -> trans ( " QtyInOtherShipments " ) . '</td>' ;
2013-08-07 15:08:30 +02:00
}
2021-02-25 22:38:35 +01:00
if ( $action == 'editline' ) {
2017-10-23 22:18:15 +02:00
$editColspan = 3 ;
2021-02-25 22:38:35 +01:00
if ( empty ( $conf -> stock -> enabled )) {
$editColspan -- ;
}
if ( empty ( $conf -> productbatch -> enabled )) {
$editColspan -- ;
}
2019-11-13 19:35:39 +01:00
print '<td class="center linecoleditlineotherinfo" colspan="' . $editColspan . '">' ;
2021-02-25 22:38:35 +01:00
if ( $object -> statut <= 1 ) {
2017-10-23 22:18:15 +02:00
print $langs -> trans ( " QtyToShip " ) . ' - ' ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-23 22:18:15 +02:00
print $langs -> trans ( " QtyShipped " ) . ' - ' ;
}
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> stock -> enabled )) {
2017-10-23 22:18:15 +02:00
print $langs -> trans ( " WarehouseSource " ) . ' - ' ;
}
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> productbatch -> enabled )) {
2017-10-23 22:18:15 +02:00
print $langs -> trans ( " Batch " );
}
print '</td>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-25 22:38:35 +01:00
if ( $object -> statut <= 1 ) {
2019-09-16 16:49:08 +02:00
print '<td class="center linecolqtytoship">' . $langs -> trans ( " QtyToShip " ) . '</td>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-09-16 16:49:08 +02:00
print '<td class="center linecolqtyshipped">' . $langs -> trans ( " QtyShipped " ) . '</td>' ;
2017-10-23 22:18:15 +02:00
}
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> stock -> enabled )) {
2019-09-16 16:49:08 +02:00
print '<td class="left linecolwarehousesource">' . $langs -> trans ( " WarehouseSource " ) . '</td>' ;
2017-10-23 22:18:15 +02:00
}
2017-11-02 12:38:36 +01:00
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> productbatch -> enabled )) {
2019-09-16 16:49:08 +02:00
print '<td class="left linecolbatch">' . $langs -> trans ( " Batch " ) . '</td>' ;
2017-10-23 22:18:15 +02:00
}
2016-10-29 14:52:13 +02:00
}
2019-09-16 16:49:08 +02:00
print '<td class="center linecolweight">' . $langs -> trans ( " CalculatedWeight " ) . '</td>' ;
print '<td class="center linecolvolume">' . $langs -> trans ( " CalculatedVolume " ) . '</td>' ;
2019-03-10 09:13:13 +01:00
//print '<td class="center">'.$langs->trans("Size").'</td>';
2021-02-25 22:38:35 +01:00
if ( $object -> statut == 0 ) {
2017-10-23 22:18:15 +02:00
print '<td class="linecoledit"></td>' ;
print '<td class="linecoldelete" width="10"></td>' ;
2013-08-07 15:08:30 +02:00
}
print " </tr> \n " ;
2019-09-16 16:49:08 +02:00
print '</thead>' ;
2013-08-07 15:08:30 +02:00
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && ! empty ( $conf -> global -> PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE )) {
2013-08-07 15:08:30 +02:00
$object -> fetch_thirdparty ();
$outputlangs = $langs ;
2019-11-13 19:35:39 +01:00
$newlang = '' ;
2021-02-25 22:38:35 +01:00
if ( empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( empty ( $newlang )) {
$newlang = $object -> thirdparty -> default_lang ;
}
if ( ! empty ( $newlang )) {
2019-01-27 11:55:16 +01:00
$outputlangs = new Translate ( " " , $conf );
2013-08-07 15:08:30 +02:00
$outputlangs -> setDefaultLang ( $newlang );
}
}
2012-03-14 14:48:27 +01:00
2017-12-01 14:33:06 +01:00
// Get list of products already sent for same source object into $alreadysent
2016-10-29 14:52:13 +02:00
$alreadysent = array ();
2021-02-25 22:38:35 +01:00
if ( $origin && $origin_id > 0 ) {
2020-09-07 10:18:17 +02:00
$sql = " SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.date_start, obj.date_end " ;
$sql .= " , ed.rowid as shipmentline_id, ed.qty as qty_shipped, ed.fk_expedition as expedition_id, ed.fk_origin_line, ed.fk_entrepot " ;
$sql .= " , e.rowid as shipment_id, e.ref as shipment_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_expedition " ;
2020-10-06 15:57:50 +02:00
//if ($conf->delivery_note->enabled) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received";
2020-11-16 16:31:05 +01:00
$sql .= ', p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tosell as product_tosell, p.tobuy as product_tobuy, p.tobatch as product_tobatch' ;
2020-09-07 10:18:17 +02:00
$sql .= ', p.description as product_desc' ;
$sql .= " FROM " . MAIN_DB_PREFIX . " expeditiondet as ed " ;
$sql .= " , " . MAIN_DB_PREFIX . " expedition as e " ;
$sql .= " , " . MAIN_DB_PREFIX . $origin . " det as obj " ;
2020-10-06 15:57:50 +02:00
//if ($conf->delivery_note->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.fk_expedition = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."deliverydet as ld ON ld.fk_delivery = l.rowid AND obj.rowid = ld.fk_origin_line";
2020-09-07 10:18:17 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product as p ON obj.fk_product = p.rowid " ;
$sql .= " WHERE e.entity IN ( " . getEntity ( 'expedition' ) . " ) " ;
$sql .= " AND obj.fk_ " . $origin . " = " . $origin_id ;
$sql .= " AND obj.rowid = ed.fk_origin_line " ;
$sql .= " AND ed.fk_expedition = e.rowid " ;
//if ($filter) $sql.= $filter;
$sql .= " ORDER BY obj.fk_product " ;
dol_syslog ( " get list of shipment lines " , LOG_DEBUG );
$resql = $db -> query ( $sql );
2021-02-25 22:38:35 +01:00
if ( $resql ) {
2020-09-07 10:18:17 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2021-02-25 22:38:35 +01:00
while ( $i < $num ) {
2020-09-07 10:18:17 +02:00
$obj = $db -> fetch_object ( $resql );
2021-02-25 22:38:35 +01:00
if ( $obj ) {
2020-09-07 10:18:17 +02:00
// $obj->rowid is rowid in $origin."det" table
2020-11-16 16:31:05 +01:00
$alreadysent [ $obj -> rowid ][ $obj -> shipmentline_id ] = array (
'shipment_ref' => $obj -> shipment_ref , 'shipment_id' => $obj -> shipment_id , 'warehouse' => $obj -> fk_entrepot , 'qty_shipped' => $obj -> qty_shipped ,
'product_tosell' => $obj -> product_tosell , 'product_tobuy' => $obj -> product_tobuy , 'product_tobatch' => $obj -> product_tobatch ,
'date_valid' => $db -> jdate ( $obj -> date_valid ), 'date_delivery' => $db -> jdate ( $obj -> date_delivery ));
2020-09-07 10:18:17 +02:00
}
$i ++ ;
}
}
//var_dump($alreadysent);
2016-10-29 14:52:13 +02:00
}
2019-09-16 16:49:08 +02:00
print '<tbody>' ;
2020-11-16 16:31:05 +01:00
2016-10-29 14:52:13 +02:00
// Loop on each product to send/sent
2021-02-25 22:38:35 +01:00
for ( $i = 0 ; $i < $num_prod ; $i ++ ) {
2019-03-12 11:28:36 +01:00
$parameters = array ( 'i' => $i , 'line' => $lines [ $i ], 'line_id' => $line_id , 'num' => $num_prod , 'alreadysent' => $alreadysent , 'editColspan' => $editColspan , 'outputlangs' => $outputlangs );
$reshook = $hookmanager -> executeHooks ( 'printObjectLine' , $parameters , $object , $action );
2021-02-25 22:38:35 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2012-03-14 14:48:27 +01:00
2021-02-25 22:38:35 +01:00
if ( empty ( $reshook )) {
2020-09-07 10:18:17 +02:00
print '<!-- origin line id = ' . $lines [ $i ] -> origin_line_id . ' -->' ; // id of order line
2019-09-16 16:49:08 +02:00
print '<tr class="oddeven" id="row-' . $lines [ $i ] -> id . '" data-id="' . $lines [ $i ] -> id . '" data-element="' . $lines [ $i ] -> element . '" >' ;
2012-03-14 14:48:27 +01:00
2019-03-12 11:28:36 +01:00
// #
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> global -> MAIN_VIEW_LINE_NUMBER )) {
2020-04-10 10:59:32 +02:00
print '<td class="center linecolnum">' . ( $i + 1 ) . '</td>' ;
2013-08-07 15:08:30 +02:00
}
2019-03-12 11:28:36 +01:00
// Predefined product or service
2021-02-25 22:38:35 +01:00
if ( $lines [ $i ] -> fk_product > 0 ) {
2019-03-12 11:28:36 +01:00
// Define output language
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && ! empty ( $conf -> global -> PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE )) {
2019-03-12 11:28:36 +01:00
$prod = new Product ( $db );
$prod -> fetch ( $lines [ $i ] -> fk_product );
2020-04-10 10:59:32 +02:00
$label = ( ! empty ( $prod -> multilangs [ $outputlangs -> defaultlang ][ " label " ])) ? $prod -> multilangs [ $outputlangs -> defaultlang ][ " label " ] : $lines [ $i ] -> product_label ;
2021-02-25 22:38:35 +01:00
} else {
$label = ( ! empty ( $lines [ $i ] -> label ) ? $lines [ $i ] -> label : $lines [ $i ] -> product_label );
}
2019-03-12 11:28:36 +01:00
2019-09-16 16:49:08 +02:00
print '<td class="linecoldescription">' ;
2019-03-12 11:28:36 +01:00
// Show product and description
2020-04-10 10:59:32 +02:00
$product_static -> type = $lines [ $i ] -> fk_product_type ;
$product_static -> id = $lines [ $i ] -> fk_product ;
$product_static -> ref = $lines [ $i ] -> ref ;
2020-11-16 16:31:05 +01:00
$product_static -> status = $lines [ $i ] -> product_tosell ;
$product_static -> status_buy = $lines [ $i ] -> product_tobuy ;
2020-04-10 10:59:32 +02:00
$product_static -> status_batch = $lines [ $i ] -> product_tobatch ;
$product_static -> weight = $lines [ $i ] -> weight ;
$product_static -> weight_units = $lines [ $i ] -> weight_units ;
$product_static -> length = $lines [ $i ] -> length ;
$product_static -> length_units = $lines [ $i ] -> length_units ;
$product_static -> width = $lines [ $i ] -> width ;
$product_static -> width_units = $lines [ $i ] -> width_units ;
$product_static -> height = $lines [ $i ] -> height ;
$product_static -> height_units = $lines [ $i ] -> height_units ;
$product_static -> surface = $lines [ $i ] -> surface ;
$product_static -> surface_units = $lines [ $i ] -> surface_units ;
$product_static -> volume = $lines [ $i ] -> volume ;
$product_static -> volume_units = $lines [ $i ] -> volume_units ;
$text = $product_static -> getNomUrl ( 1 );
$text .= ' - ' . $label ;
$description = ( ! empty ( $conf -> global -> PRODUIT_DESC_IN_FORM ) ? '' : dol_htmlentitiesbr ( $lines [ $i ] -> description ));
2019-03-15 02:32:21 +01:00
print $form -> textwithtooltip ( $text , $description , 3 , '' , '' , $i );
print_date_range ( $lines [ $i ] -> date_start , $lines [ $i ] -> date_end );
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_DESC_IN_FORM )) {
2020-04-10 10:59:32 +02:00
print ( ! empty ( $lines [ $i ] -> description ) && $lines [ $i ] -> description != $lines [ $i ] -> product ) ? '<br>' . dol_htmlentitiesbr ( $lines [ $i ] -> description ) : '' ;
2019-03-12 11:28:36 +01:00
}
print " </td> \n " ;
2020-05-21 15:05:19 +02:00
} else {
2019-09-16 16:49:08 +02:00
print '<td class="linecoldescription" >' ;
2021-02-25 22:38:35 +01:00
if ( $lines [ $i ] -> product_type == Product :: TYPE_SERVICE ) {
$text = img_object ( $langs -> trans ( 'Service' ), 'service' );
} else {
$text = img_object ( $langs -> trans ( 'Product' ), 'product' );
}
2013-08-07 15:08:30 +02:00
2019-11-13 19:35:39 +01:00
if ( ! empty ( $lines [ $i ] -> label )) {
$text .= ' <strong>' . $lines [ $i ] -> label . '</strong>' ;
2019-03-15 02:32:21 +01:00
print $form -> textwithtooltip ( $text , $lines [ $i ] -> description , 3 , '' , '' , $i );
2019-03-12 11:28:36 +01:00
} else {
print $text . ' ' . nl2br ( $lines [ $i ] -> description );
}
2013-08-07 15:08:30 +02:00
2019-03-15 02:32:21 +01:00
print_date_range ( $lines [ $i ] -> date_start , $lines [ $i ] -> date_end );
2019-03-12 11:28:36 +01:00
print " </td> \n " ;
}
2013-08-07 15:08:30 +02:00
2019-03-12 11:28:36 +01:00
// Qty ordered
2019-09-16 16:49:08 +02:00
print '<td class="center linecolqty">' . $lines [ $i ] -> qty_asked . '</td>' ;
2019-03-12 11:28:36 +01:00
// Qty in other shipments (with shipment and warehouse used)
2021-02-25 22:38:35 +01:00
if ( $origin && $origin_id > 0 ) {
2020-09-07 10:18:17 +02:00
print '<td class="linecolqtyinothershipments center nowrap">' ;
2021-02-25 22:38:35 +01:00
foreach ( $alreadysent as $key => $val ) {
if ( $lines [ $i ] -> fk_origin_line == $key ) {
2020-09-07 10:18:17 +02:00
$j = 0 ;
2021-02-25 22:38:35 +01:00
foreach ( $val as $shipmentline_id => $shipmentline_var ) {
if ( $shipmentline_var [ 'shipment_id' ] == $lines [ $i ] -> fk_expedition ) {
continue ; // We want to show only "other shipments"
}
2020-09-07 10:18:17 +02:00
$j ++ ;
2021-02-25 22:38:35 +01:00
if ( $j > 1 ) {
print '<br>' ;
}
2020-09-07 10:18:17 +02:00
$shipment_static -> fetch ( $shipmentline_var [ 'shipment_id' ]);
print $shipment_static -> getNomUrl ( 1 );
print ' - ' . $shipmentline_var [ 'qty_shipped' ];
$htmltext = $langs -> trans ( " DateValidation " ) . ' : ' . ( empty ( $shipmentline_var [ 'date_valid' ]) ? $langs -> trans ( " Draft " ) : dol_print_date ( $shipmentline_var [ 'date_valid' ], 'dayhour' ));
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> stock -> enabled ) && $shipmentline_var [ 'warehouse' ] > 0 ) {
2020-09-07 10:18:17 +02:00
$warehousestatic -> fetch ( $shipmentline_var [ 'warehouse' ]);
$htmltext .= '<br>' . $langs -> trans ( " FromLocation " ) . ' : ' . $warehousestatic -> getNomUrl ( 1 , '' , 0 , 1 );
}
print ' ' . $form -> textwithpicto ( '' , $htmltext , 1 );
}
}
}
print '</td>' ;
}
2016-10-29 14:52:13 +02:00
2021-02-25 22:38:35 +01:00
if ( $action == 'editline' && $lines [ $i ] -> id == $line_id ) {
2019-03-12 11:28:36 +01:00
// edit mode
2019-03-14 19:23:59 +01:00
print '<td colspan="' . $editColspan . '" class="center"><table class="nobordernopadding">' ;
2021-02-25 22:38:35 +01:00
if ( is_array ( $lines [ $i ] -> detail_batch ) && count ( $lines [ $i ] -> detail_batch ) > 0 ) {
2019-03-12 11:28:36 +01:00
print '<!-- case edit 1 -->' ;
$line = new ExpeditionLigne ( $db );
2021-02-25 22:38:35 +01:00
foreach ( $lines [ $i ] -> detail_batch as $detail_batch ) {
2017-10-23 22:18:15 +02:00
print '<tr>' ;
// Qty to ship or shipped
2021-03-04 08:52:55 +01:00
print '<td><input class="qtyl" name="qtyl' . $detail_batch -> fk_expeditiondet . '_' . $detail_batch -> id . '" id="qtyl' . $line_id . '_' . $detail_batch -> id . '" type="text" size="4" value="' . $detail_batch -> qty . '"></td>' ;
2017-10-23 22:18:15 +02:00
// Batch number managment
2021-02-25 22:38:35 +01:00
if ( $lines [ $i ] -> entrepot_id == 0 ) {
2019-03-12 11:28:36 +01:00
// only show lot numbers from src warehouse when shipping from multiple warehouses
$line -> fetch ( $detail_batch -> fk_expeditiondet );
}
2019-11-13 19:35:39 +01:00
print '<td>' . $formproduct -> selectLotStock ( $detail_batch -> fk_origin_stock , 'batchl' . $detail_batch -> fk_expeditiondet . '_' . $detail_batch -> fk_origin_stock , '' , 1 , 0 , $lines [ $i ] -> fk_product , $line -> entrepot_id ) . '</td>' ;
2017-10-23 22:18:15 +02:00
print '</tr>' ;
2014-10-03 12:20:02 +02:00
}
2019-03-12 11:28:36 +01:00
// add a 0 qty lot row to be able to add a lot
print '<tr>' ;
// Qty to ship or shipped
2021-03-04 08:52:55 +01:00
print '<td><input class="qtyl" name="qtyl' . $line_id . '_0" id="qtyl' . $line_id . '_0" type="text" size="4" value="0"></td>' ;
2019-03-12 11:28:36 +01:00
// Batch number managment
2019-11-13 19:35:39 +01:00
print '<td>' . $formproduct -> selectLotStock ( '' , 'batchl' . $line_id . '_0' , '' , 1 , 0 , $lines [ $i ] -> fk_product ) . '</td>' ;
2019-03-12 11:28:36 +01:00
print '</tr>' ;
2021-02-25 22:38:35 +01:00
} elseif ( ! empty ( $conf -> stock -> enabled )) {
if ( $lines [ $i ] -> fk_product > 0 ) {
if ( $lines [ $i ] -> entrepot_id > 0 ) {
2019-03-12 11:28:36 +01:00
print '<!-- case edit 2 -->' ;
2017-12-01 14:33:06 +01:00
print '<tr>' ;
// Qty to ship or shipped
2021-03-04 08:52:55 +01:00
print '<td><input class="qtyl" name="qtyl' . $line_id . '" id="qtyl' . $line_id . '" type="text" size="4" value="' . $lines [ $i ] -> qty_shipped . '"></td>' ;
2017-12-01 14:33:06 +01:00
// Warehouse source
2019-11-13 19:35:39 +01:00
print '<td>' . $formproduct -> selectWarehouses ( $lines [ $i ] -> entrepot_id , 'entl' . $line_id , '' , 1 , 0 , $lines [ $i ] -> fk_product , '' , 1 ) . '</td>' ;
2017-12-01 14:33:06 +01:00
// Batch number managment
2019-11-13 19:35:39 +01:00
print '<td> - ' . $langs -> trans ( " NA " ) . '</td>' ;
2017-12-01 14:33:06 +01:00
print '</tr>' ;
2021-02-25 22:38:35 +01:00
} elseif ( count ( $lines [ $i ] -> details_entrepot ) > 1 ) {
2019-03-12 11:28:36 +01:00
print '<!-- case edit 3 -->' ;
2021-02-25 22:38:35 +01:00
foreach ( $lines [ $i ] -> details_entrepot as $detail_entrepot ) {
2019-03-12 11:28:36 +01:00
print '<tr>' ;
// Qty to ship or shipped
2021-03-04 08:52:55 +01:00
print '<td><input class="qtyl" name="qtyl' . $detail_entrepot -> line_id . '" id="qtyl' . $detail_entrepot -> line_id . '" type="text" size="4" value="' . $detail_entrepot -> qty_shipped . '"></td>' ;
2019-03-12 11:28:36 +01:00
// Warehouse source
2019-11-13 19:35:39 +01:00
print '<td>' . $formproduct -> selectWarehouses ( $detail_entrepot -> entrepot_id , 'entl' . $detail_entrepot -> line_id , '' , 1 , 0 , $lines [ $i ] -> fk_product , '' , 1 ) . '</td>' ;
2019-03-12 11:28:36 +01:00
// Batch number managment
2019-11-13 19:35:39 +01:00
print '<td> - ' . $langs -> trans ( " NA " ) . '</td>' ;
2019-03-12 11:28:36 +01:00
print '</tr>' ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-03-12 11:28:36 +01:00
print '<!-- case edit 4 -->' ;
print '<tr><td colspan="3">' . $langs -> trans ( " NotEnoughStock " ) . '</td></tr>' ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-03-12 11:28:36 +01:00
print '<!-- case edit 5 -->' ;
print '<tr>' ;
// Qty to ship or shipped
2021-03-04 08:52:55 +01:00
print '<td><input class="qtyl" name="qtyl' . $line_id . '" id="qtyl' . $line_id . '" type="text" size="4" value="' . $lines [ $i ] -> qty_shipped . '"></td>' ;
2019-03-12 11:28:36 +01:00
// Warehouse source
2020-04-27 00:02:31 +02:00
print '<td></td>' ;
2019-03-12 11:28:36 +01:00
// Batch number managment
2020-04-27 00:02:31 +02:00
print '<td></td>' ;
2019-03-12 11:28:36 +01:00
print '</tr>' ;
2017-12-01 14:33:06 +01:00
}
}
2017-10-23 22:18:15 +02:00
2019-03-12 11:28:36 +01:00
print '</table></td>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-03-12 11:28:36 +01:00
// Qty to ship or shipped
2019-09-16 16:49:08 +02:00
print '<td class="linecolqtytoship center">' . $lines [ $i ] -> qty_shipped . '</td>' ;
2019-03-12 11:28:36 +01:00
// Warehouse source
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> stock -> enabled )) {
2019-09-16 16:49:08 +02:00
print '<td class="linecolwarehousesource left">' ;
2021-02-25 22:38:35 +01:00
if ( $lines [ $i ] -> entrepot_id > 0 ) {
2019-03-12 11:28:36 +01:00
$entrepot = new Entrepot ( $db );
$entrepot -> fetch ( $lines [ $i ] -> entrepot_id );
print $entrepot -> getNomUrl ( 1 );
2021-02-25 22:38:35 +01:00
} elseif ( count ( $lines [ $i ] -> details_entrepot ) > 1 ) {
2019-03-12 11:28:36 +01:00
$detail = '' ;
2021-02-25 22:38:35 +01:00
foreach ( $lines [ $i ] -> details_entrepot as $detail_entrepot ) {
if ( $detail_entrepot -> entrepot_id > 0 ) {
2019-03-12 11:28:36 +01:00
$entrepot = new Entrepot ( $db );
$entrepot -> fetch ( $detail_entrepot -> entrepot_id );
2021-04-19 21:30:25 +02:00
$detail .= $langs -> trans ( " DetailWarehouseFormat " , $entrepot -> libelle , $detail_entrepot -> qty_shipped ) . '<br>' ;
2019-03-12 11:28:36 +01:00
}
2017-10-23 22:18:15 +02:00
}
2019-03-15 02:32:21 +01:00
print $form -> textwithtooltip ( img_picto ( '' , 'object_stock' ) . ' ' . $langs -> trans ( " DetailWarehouseNumber " ), $detail );
2015-08-14 23:53:59 +02:00
}
2019-03-12 11:28:36 +01:00
print '</td>' ;
2015-08-14 23:53:59 +02:00
}
2017-10-23 22:18:15 +02:00
2019-03-12 11:28:36 +01:00
// Batch number managment
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> productbatch -> enabled )) {
if ( isset ( $lines [ $i ] -> detail_batch )) {
2019-03-12 11:28:36 +01:00
print '<!-- Detail of lot -->' ;
2019-09-16 16:49:08 +02:00
print '<td class="linecolbatch">' ;
2021-02-25 22:38:35 +01:00
if ( $lines [ $i ] -> product_tobatch ) {
2019-03-12 11:28:36 +01:00
$detail = '' ;
2021-02-25 22:38:35 +01:00
foreach ( $lines [ $i ] -> detail_batch as $dbatch ) { // $dbatch is instance of ExpeditionLineBatch
2019-11-13 19:35:39 +01:00
$detail .= $langs -> trans ( " Batch " ) . ': ' . $dbatch -> batch ;
2020-08-20 15:27:34 +02:00
if ( empty ( $conf -> global -> PRODUCT_DISABLE_SELLBY )) {
$detail .= ' - ' . $langs -> trans ( " SellByDate " ) . ': ' . dol_print_date ( $dbatch -> sellby , " day " );
}
if ( empty ( $conf -> global -> PRODUCT_DISABLE_EATBY )) {
$detail .= ' - ' . $langs -> trans ( " EatByDate " ) . ': ' . dol_print_date ( $dbatch -> eatby , " day " );
}
2019-11-13 19:35:39 +01:00
$detail .= ' - ' . $langs -> trans ( " Qty " ) . ': ' . $dbatch -> qty ;
$detail .= '<br>' ;
2019-03-12 11:28:36 +01:00
}
2019-03-15 02:32:21 +01:00
print $form -> textwithtooltip ( img_picto ( '' , 'object_barcode' ) . ' ' . $langs -> trans ( " DetailBatchNumber " ), $detail );
2020-05-21 15:05:19 +02:00
} else {
2019-03-12 11:28:36 +01:00
print $langs -> trans ( " NA " );
}
print '</td>' ;
} else {
2019-09-16 16:49:08 +02:00
print '<td class="linecolbatch" ></td>' ;
2017-10-23 22:18:15 +02:00
}
2014-03-07 11:35:16 +01:00
}
}
2017-10-18 18:18:17 +02:00
2019-03-12 11:28:36 +01:00
// Weight
2019-09-16 16:49:08 +02:00
print '<td class="center linecolweight">' ;
2021-02-25 22:38:35 +01:00
if ( $lines [ $i ] -> fk_product_type == Product :: TYPE_PRODUCT ) {
print $lines [ $i ] -> weight * $lines [ $i ] -> qty_shipped . ' ' . measuringUnitString ( 0 , " weight " , $lines [ $i ] -> weight_units );
} else {
print ' ' ;
}
2017-10-23 22:18:15 +02:00
print '</td>' ;
2019-03-12 11:28:36 +01:00
// Volume
2019-09-16 16:49:08 +02:00
print '<td class="center linecolvolume">' ;
2021-02-25 22:38:35 +01:00
if ( $lines [ $i ] -> fk_product_type == Product :: TYPE_PRODUCT ) {
print $lines [ $i ] -> volume * $lines [ $i ] -> qty_shipped . ' ' . measuringUnitString ( 0 , " volume " , $lines [ $i ] -> volume_units );
} else {
print ' ' ;
}
2017-10-23 22:18:15 +02:00
print '</td>' ;
2019-03-12 11:28:36 +01:00
// Size
2019-10-22 18:36:36 +02:00
//print '<td class="center">'.$lines[$i]->volume*$lines[$i]->qty_shipped.' '.measuringUnitString(0, "volume", $lines[$i]->volume_units).'</td>';
2017-06-07 16:44:04 +02:00
2021-02-25 22:38:35 +01:00
if ( $action == 'editline' && $lines [ $i ] -> id == $line_id ) {
2019-03-14 19:23:59 +01:00
print '<td class="center" colspan="2" valign="middle">' ;
2020-11-19 20:23:38 +01:00
print '<input type="submit" class="button button-save" id="savelinebutton marginbottomonly" name="save" value="' . $langs -> trans ( " Save " ) . '"><br>' ;
2020-11-23 15:12:52 +01:00
print '<input type="submit" class="button button-cancel" id="cancellinebutton" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '"><br>' ;
2019-10-06 16:50:04 +02:00
print '</td>' ;
2021-02-25 22:38:35 +01:00
} elseif ( $object -> statut == Expedition :: STATUS_DRAFT ) {
2019-03-12 11:28:36 +01:00
// edit-delete buttons
2019-03-14 19:23:59 +01:00
print '<td class="linecoledit center">' ;
2020-04-10 10:59:32 +02:00
print '<a class="editfielda reposition" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=editline&lineid=' . $lines [ $i ] -> id . '">' . img_edit () . '</a>' ;
2019-03-12 11:28:36 +01:00
print '</td>' ;
print '<td class="linecoldelete" width="10">' ;
2020-10-01 10:50:54 +02:00
print '<a class="reposition" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=deleteline&token=' . newToken () . '&lineid=' . $lines [ $i ] -> id . '">' . img_delete () . '</a>' ;
2019-03-12 11:28:36 +01:00
print '</td>' ;
// Display lines extrafields
2021-02-25 22:38:35 +01:00
if ( ! empty ( $rowExtrafieldsStart )) {
2019-03-12 11:28:36 +01:00
print $rowExtrafieldsStart ;
print $rowExtrafieldsView ;
print $rowEnd ;
}
}
print " </tr> " ;
// Display lines extrafields
2019-11-13 19:35:39 +01:00
if ( ! empty ( $extrafields )) {
$colspan = 6 ;
2021-02-25 22:38:35 +01:00
if ( $origin && $origin_id > 0 ) {
$colspan ++ ;
}
if ( ! empty ( $conf -> productbatch -> enabled )) {
$colspan ++ ;
}
if ( ! empty ( $conf -> stock -> enabled )) {
$colspan ++ ;
}
2019-10-06 14:41:52 +02:00
2019-11-19 16:35:31 +01:00
$line = $lines [ $i ];
2020-03-27 16:02:58 +01:00
$line -> fetch_optionals ();
2019-10-06 14:41:52 +02:00
2021-02-25 22:38:35 +01:00
if ( $action == 'editline' && $line -> id == $line_id ) {
2019-10-06 14:41:52 +02:00
print $lines [ $i ] -> showOptionals ( $extrafields , 'edit' , array ( 'colspan' => $colspan ), $indiceAsked );
2020-05-21 15:05:19 +02:00
} else {
2019-10-06 14:41:52 +02:00
print $lines [ $i ] -> showOptionals ( $extrafields , 'view' , array ( 'colspan' => $colspan ), $indiceAsked );
2019-03-12 11:28:36 +01:00
}
2017-10-23 22:18:15 +02:00
}
2015-12-16 16:18:29 +01:00
}
2013-08-07 15:08:30 +02:00
}
2017-06-07 16:44:04 +02:00
2016-10-29 14:52:13 +02:00
// TODO Show also lines ordered but not delivered
2017-06-07 16:44:04 +02:00
2016-09-19 13:57:50 +02:00
print " </table> \n " ;
2019-09-16 16:49:08 +02:00
print '</tbody>' ;
2017-03-02 01:26:15 +01:00
print '</div>' ;
2013-08-07 15:08:30 +02:00
}
2012-03-14 14:48:27 +01:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2012-03-14 14:48:27 +01:00
2019-01-27 11:55:16 +01:00
$object -> fetchObjectLinked ( $object -> id , $object -> element );
2012-03-14 14:48:27 +01:00
2017-06-07 16:44:04 +02:00
2013-08-07 15:08:30 +02:00
/*
* Boutons actions
2015-07-13 11:22:18 +02:00
*/
2012-03-14 14:48:27 +01:00
2021-02-25 22:38:35 +01:00
if (( $user -> socid == 0 ) && ( $action != 'presend' )) {
2013-08-07 15:08:30 +02:00
print '<div class="tabsAction">' ;
2012-03-14 14:48:27 +01:00
2016-05-03 14:20:42 +02:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'addMoreActionsButtons' , $parameters , $object , $action ); // Note that $action and $object may have been
2020-09-07 10:18:17 +02:00
// modified by hook
2021-02-25 22:38:35 +01:00
if ( empty ( $reshook )) {
if ( $object -> statut == Expedition :: STATUS_DRAFT && $num_prod > 0 ) {
2019-11-13 19:35:39 +01:00
if (( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> expedition -> creer ))
2021-02-25 22:38:35 +01:00
|| ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> expedition -> shipping_advance -> validate ))) {
2016-05-03 14:20:42 +02:00
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=valid">' . $langs -> trans ( " Validate " ) . '</a>' ;
2020-05-21 15:05:19 +02:00
} else {
2018-11-13 21:40:17 +01:00
print '<a class="butActionRefused classfortooltip" href="#" title="' . $langs -> trans ( " NotAllowed " ) . '">' . $langs -> trans ( " Validate " ) . '</a>' ;
2016-05-03 14:20:42 +02:00
}
2013-08-07 15:08:30 +02:00
}
2017-06-07 16:44:04 +02:00
2016-05-03 14:20:42 +02:00
// TODO add alternative status
// 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order)
2021-02-25 22:38:35 +01:00
if ( $object -> statut == Expedition :: STATUS_CLOSED && $user -> rights -> expedition -> creer ) {
if ( ! empty ( $conf -> facture -> enabled ) && ! empty ( $conf -> global -> WORKFLOW_BILL_ON_SHIPMENT )) { // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
2018-02-15 15:27:06 +01:00
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=reopen">' . $langs -> trans ( " ClassifyUnbilled " ) . '</a>' ;
2020-05-21 15:05:19 +02:00
} else {
2020-09-07 10:18:17 +02:00
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=reopen">' . $langs -> trans ( " ReOpen " ) . '</a>' ;
2018-02-15 15:27:06 +01:00
}
2013-08-07 15:08:30 +02:00
}
2017-06-07 16:44:04 +02:00
2016-05-03 14:20:42 +02:00
// Send
2020-04-10 01:37:04 +02:00
if ( empty ( $user -> socid )) {
2021-02-25 22:38:35 +01:00
if ( $object -> statut > 0 ) {
if ( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) || $user -> rights -> expedition -> shipping_advance -> send ) {
2020-04-10 01:37:04 +02:00
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=presend&mode=init#formmailbeforetitle">' . $langs -> trans ( 'SendMail' ) . '</a>' ;
2021-02-25 22:38:35 +01:00
} else {
print '<a class="butActionRefused classfortooltip" href="#">' . $langs -> trans ( 'SendMail' ) . '</a>' ;
}
2016-05-03 14:20:42 +02:00
}
2013-08-07 15:08:30 +02:00
}
2017-06-07 16:44:04 +02:00
2017-08-02 17:45:35 +02:00
// Create bill
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> facture -> enabled ) && ( $object -> statut == Expedition :: STATUS_VALIDATED || $object -> statut == Expedition :: STATUS_CLOSED )) {
if ( $user -> rights -> facture -> creer ) {
2017-08-02 17:45:35 +02:00
// TODO show button only if (! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))
// If we do that, we must also make this option official.
2017-03-20 20:58:43 +01:00
print '<a class="butAction" href="' . DOL_URL_ROOT . '/compta/facture/card.php?action=create&origin=' . $object -> element . '&originid=' . $object -> id . '&socid=' . $object -> socid . '">' . $langs -> trans ( " CreateBill " ) . '</a>' ;
2016-05-03 14:20:42 +02:00
}
2013-08-07 15:08:30 +02:00
}
2017-06-07 16:44:04 +02:00
2016-05-03 14:20:42 +02:00
// This is just to generate a delivery receipt
//var_dump($object->linkedObjectsIds['delivery']);
2021-02-25 22:38:35 +01:00
if ( $conf -> delivery_note -> enabled && ( $object -> statut == Expedition :: STATUS_VALIDATED || $object -> statut == Expedition :: STATUS_CLOSED ) && $user -> rights -> expedition -> delivery -> creer && empty ( $object -> linkedObjectsIds [ 'delivery' ])) {
2016-05-03 14:20:42 +02:00
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=create_delivery">' . $langs -> trans ( " CreateDeliveryOrder " ) . '</a>' ;
}
// Close
2021-02-25 22:38:35 +01:00
if ( $object -> statut == Expedition :: STATUS_VALIDATED ) {
if ( $user -> rights -> expedition -> creer && $object -> statut > 0 && ! $object -> billed ) {
2019-11-13 19:35:39 +01:00
$label = " Close " ; $paramaction = 'classifyclosed' ; // = Transferred/Received
2016-05-03 14:20:42 +02:00
// Label here should be "Close" or "ClassifyBilled" if we decided to make bill on shipments instead of orders
2021-02-25 22:38:35 +01:00
if ( ! empty ( $conf -> facture -> enabled ) && ! empty ( $conf -> global -> WORKFLOW_BILL_ON_SHIPMENT )) { // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
2020-09-07 10:18:17 +02:00
$label = " ClassifyBilled " ;
$paramaction = 'classifybilled' ;
2016-05-03 14:20:42 +02:00
}
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=' . $paramaction . '">' . $langs -> trans ( $label ) . '</a>' ;
2016-04-26 13:27:32 +02:00
}
2013-08-07 15:08:30 +02:00
}
2017-06-07 16:44:04 +02:00
2020-04-23 07:54:13 +02:00
// Cancel
2021-02-25 22:38:35 +01:00
if ( $object -> statut == Expedition :: STATUS_VALIDATED ) {
if ( $user -> rights -> expedition -> supprimer ) {
2020-09-07 10:18:17 +02:00
print '<a class="butActionDelete" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=cancel">' . $langs -> trans ( " Cancel " ) . '</a>' ;
}
2020-04-23 07:38:08 +02:00
}
2020-04-23 07:54:13 +02:00
2020-04-23 07:38:08 +02:00
// Delete
2021-02-25 22:38:35 +01:00
if ( $user -> rights -> expedition -> supprimer ) {
2020-10-01 10:50:54 +02:00
print '<a class="butActionDelete" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=delete&token=' . newToken () . '">' . $langs -> trans ( " Delete " ) . '</a>' ;
2016-05-03 14:20:42 +02:00
}
2013-08-07 15:08:30 +02:00
}
2017-06-07 16:44:04 +02:00
2013-08-07 15:08:30 +02:00
print '</div>' ;
}
2012-03-14 14:48:27 +01:00
2012-03-16 00:34:41 +01:00
2013-08-07 15:08:30 +02:00
/*
* Documents generated
2015-07-13 11:22:18 +02:00
*/
2017-06-07 16:44:04 +02:00
2021-02-25 22:38:35 +01:00
if ( $action != 'presend' && $action != 'editline' ) {
2020-09-07 10:18:17 +02:00
print '<div class="fichecenter"><div class="fichehalfleft">' ;
2017-06-07 16:44:04 +02:00
2020-09-07 10:18:17 +02:00
$objectref = dol_sanitizeFileName ( $object -> ref );
2019-11-13 19:35:39 +01:00
$filedir = $conf -> expedition -> dir_output . " /sending/ " . $objectref ;
2012-03-14 14:48:27 +01:00
2013-08-07 15:08:30 +02:00
$urlsource = $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id ;
2013-03-23 14:39:23 +01:00
2019-11-13 19:35:39 +01:00
$genallowed = $user -> rights -> expedition -> lire ;
$delallowed = $user -> rights -> expedition -> creer ;
2013-03-30 13:54:46 +01:00
2020-09-10 01:49:09 +02:00
print $formfile -> showdocuments ( 'expedition' , $objectref , $filedir , $urlsource , $genallowed , $delallowed , $object -> model_pdf , 1 , 0 , 0 , 28 , 0 , '' , '' , '' , $soc -> default_lang );
2013-03-30 13:54:46 +01:00
2017-06-07 16:44:04 +02:00
2015-06-06 15:57:59 +02:00
// Show links to link elements
2016-08-05 15:30:28 +02:00
//$linktoelem = $form->showLinkToObjectBlock($object, null, array('order'));
$somethingshown = $form -> showLinkedObjectBlock ( $object , '' );
2017-06-07 16:44:04 +02:00
2015-10-22 19:13:16 +02:00
print '</div><div class="fichehalfright"><div class="ficheaddleft">' ;
2013-03-30 13:54:46 +01:00
2013-08-07 15:08:30 +02:00
// List of actions on element
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php' ;
2019-11-13 19:35:39 +01:00
$formactions = new FormActions ( $db );
2019-01-27 11:55:16 +01:00
$somethingshown = $formactions -> showactions ( $object , 'shipping' , $socid , 1 );
2012-03-14 14:48:27 +01:00
2015-10-22 19:13:16 +02:00
print '</div></div></div>' ;
2013-08-07 15:08:30 +02:00
}
2012-03-14 14:48:27 +01:00
2017-06-07 16:44:04 +02:00
2013-08-07 15:08:30 +02:00
/*
* Action presend
2015-07-13 11:22:18 +02:00
*/
2017-06-07 16:44:04 +02:00
2015-04-18 17:15:36 +02:00
//Select mail models is same action as presend
2015-04-18 22:59:20 +02:00
if ( GETPOST ( 'modelselected' )) {
2015-04-18 17:15:36 +02:00
$action = 'presend' ;
}
2017-10-08 16:34:42 +02:00
// Presend form
2019-11-13 19:35:39 +01:00
$modelmail = 'shipping_send' ;
$defaulttopic = 'SendShippingRef' ;
$diroutput = $conf -> expedition -> dir_output . '/sending' ;
2017-10-08 16:34:42 +02:00
$trackid = 'shi' . $object -> id ;
include DOL_DOCUMENT_ROOT . '/core/tpl/card_presend.tpl.php' ;
2003-11-13 18:36:45 +01:00
}
2018-08-02 14:03:50 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-08-25 15:21:34 +02:00
$db -> close ();