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 >
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
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
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' ;
2012-09-15 11:21:22 +02:00
if ( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled )) require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> propal -> enabled )) require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php' ;
if ( ! empty ( $conf -> commande -> enabled )) require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php' ;
2017-10-24 11:45:11 +02:00
if ( ! empty ( $conf -> productbatch -> enabled )) require_once DOL_DOCUMENT_ROOT . '/product/class/productbatch.class.php' ;
2016-09-19 13:57:50 +02:00
if ( ! empty ( $conf -> projet -> enabled )) {
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php' ;
}
2003-11-13 18:36:45 +01:00
2018-05-26 20:51:17 +02:00
// Load translation files required by the page
2017-12-02 10:43:01 +01:00
$langs -> loadLangs ( array ( " sendings " , " companies " , " bills " , 'deliveries' , 'orders' , 'stocks' , 'other' , 'propal' ));
2015-02-23 09:16:14 +01:00
if ( ! empty ( $conf -> incoterm -> enabled )) $langs -> load ( 'incoterm' );
2014-03-07 11:35:16 +01:00
if ( ! empty ( $conf -> productbatch -> enabled )) $langs -> load ( 'productbatch' );
2005-04-15 12:34:44 +02:00
2012-03-08 15:28:32 +01:00
$origin = GETPOST ( 'origin' , 'alpha' ) ? GETPOST ( 'origin' , 'alpha' ) : 'expedition' ; // Example: commande, propal
2012-02-27 22:26:22 +01:00
$origin_id = GETPOST ( 'id' , 'int' ) ? GETPOST ( 'id' , 'int' ) : '' ;
2013-10-14 17:56:23 +02:00
$id = $origin_id ;
2012-03-08 15:28:32 +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
$ref = GETPOST ( 'ref' , 'alpha' );
2017-10-18 18:18:17 +02:00
$line_id = GETPOST ( 'lineid' , 'int' ) ? GETPOST ( 'lineid' , 'int' ) : '' ;
2009-04-05 21:30:37 +02:00
2009-04-30 13:29:32 +02:00
// Security check
2012-10-31 09:50:20 +01:00
$socid = '' ;
2009-04-30 13:29:32 +02:00
if ( $user -> societe_id ) $socid = $user -> societe_id ;
2017-06-11 12:59:54 +02:00
if ( $origin == 'expedition' ) $result = restrictedArea ( $user , $origin , $id );
else {
$result = restrictedArea ( $user , 'expedition' );
if ( empty ( $user -> rights -> { $origin } -> lire ) && empty ( $user -> rights -> { $origin } -> read )) accessforbidden ();
}
2009-04-30 13:29:32 +02:00
2012-03-08 15:28:32 +01:00
$action = GETPOST ( 'action' , 'alpha' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
2016-10-29 14:52:13 +02:00
$cancel = GETPOST ( 'cancel' , 'alpha' );
2011-06-02 19:20:24 +02:00
2012-07-02 19:30:37 +02:00
//PDF
2012-05-21 18:44:09 +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 );
2015-12-16 16:18:29 +01:00
$extrafields = new ExtraFields ( $db );
$extrafieldsline = new ExtraFields ( $db );
// fetch optionals attributes and labels
$extralabels = $extrafields -> fetch_name_optionals_label ( $object -> table_element );
// fetch optionals attributes lines and labels
$extralabelslines = $extrafieldsline -> fetch_name_optionals_label ( $object -> table_element_line );
2009-04-30 13:29:32 +02:00
2015-08-14 23:53:59 +02:00
// Load object. Make an object->fetch
2015-10-01 16:50:18 +02: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
2014-10-06 07:20:58 +02:00
$hookmanager -> initHooks ( array ( 'expeditioncard' , 'globalcard' ));
2013-09-27 11:00:25 +02:00
2015-07-28 14:13:16 +02:00
$permissiondellink = $user -> rights -> expedition -> livraison -> creer ; // Used by the include of actions_dellink.inc.php
2017-12-02 10:43:01 +01:00
//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
2013-09-27 11:00:25 +02:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2014-09-28 03:41:32 +02:00
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
2005-04-16 16:00:07 +02:00
2015-01-18 17:13:42 +01:00
if ( empty ( $reshook ))
2003-11-13 18:36:45 +01:00
{
2017-06-07 16:44:04 +02:00
if ( $cancel )
{
$action = '' ;
2017-03-25 16:17:43 +01:00
$object -> fetch ( $id ); // show shipment also after canceling modification
}
2017-06-07 16:44:04 +02:00
2015-07-28 14:13:16 +02:00
include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php' ; // Must be include, not include_once
2018-05-10 14:15:52 +02:00
// Actions to build doc
$upload_dir = $conf -> expedition -> dir_output . '/sending' ;
$permissioncreate = $user -> rights -> expedition -> creer ;
include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php' ;
2017-12-20 12:45:38 +01:00
// Reopen
2016-02-24 13:19:25 +01:00
if ( $action == 'reopen' && $user -> rights -> expedition -> creer )
{
$object -> fetch ( $id );
$result = $object -> reOpen ();
}
2017-06-07 16:44:04 +02:00
2016-02-24 13:19:25 +01:00
// Set incoterm
if ( $action == 'set_incoterms' && ! empty ( $conf -> incoterm -> enabled ))
{
$result = $object -> setIncoterms ( GETPOST ( 'incoterm_id' , 'int' ), GETPOST ( 'location_incoterms' , 'alpha' ));
}
2017-06-07 16:44:04 +02:00
2016-10-29 14:52:13 +02:00
if ( $action == 'setref_customer' )
{
$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 ;
}
}
2017-06-07 16:44:04 +02:00
2016-02-24 13:19:25 +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
2016-02-24 13:19:25 +01:00
$extralabels = $extrafields -> fetch_name_optionals_label ( $object -> table_element );
2018-02-23 16:11:00 +01:00
$ret = $extrafields -> setOptionalsFromPost ( $extralabels , $object , GETPOST ( 'attribute' , 'none' ));
2016-02-24 13:19:25 +01:00
if ( $ret < 0 ) $error ++ ;
2017-06-07 16:44:04 +02:00
2016-02-24 13:19:25 +01:00
if ( ! $error )
{
2018-04-10 12:03:01 +02:00
// Actions on extra fields
$result = $object -> insertExtraFields ( 'SHIPMENT_MODIFY' );
if ( $result < 0 )
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
2016-02-24 13:19:25 +01:00
}
2017-06-07 16:44:04 +02:00
2016-02-24 13:19:25 +01:00
if ( $error )
$action = 'edit_extras' ;
}
2017-06-07 16:44:04 +02:00
2016-04-01 10:57:18 +02:00
// Create shipment
2015-12-16 16:18:29 +01:00
if ( $action == 'add' && $user -> rights -> expedition -> creer )
2015-01-18 17:13:42 +01:00
{
$error = 0 ;
2015-12-16 16:18:29 +01:00
$predef = '' ;
2015-01-18 17:13:42 +01:00
$db -> begin ();
$object -> note = GETPOST ( 'note' , 'alpha' );
$object -> origin = $origin ;
2017-06-27 16:41:57 +02:00
$object -> origin_id = $origin_id ;
$object -> fk_project = GETPOST ( 'projectid' , 'int' );
2015-01-18 17:13:42 +01:00
$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' );
$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' ));
// On va boucler sur chaque ligne du document d'origine pour completer objet expedition
// avec info diverses + qte a livrer
$classname = ucfirst ( $object -> origin );
$objectsrc = new $classname ( $db );
$objectsrc -> fetch ( $object -> origin_id );
$object -> socid = $objectsrc -> socid ;
2017-10-26 17:02:40 +02:00
$object -> ref_customer = GETPOST ( 'ref_customer' , 'alpha' );
2015-04-19 00:23:46 +02:00
$object -> model_pdf = GETPOST ( 'model' );
2016-10-30 16:34:46 +01:00
$object -> date_delivery = $date_delivery ; // Date delivery planed
2015-01-18 17:13:42 +01:00
$object -> fk_delivery_address = $objectsrc -> fk_delivery_address ;
$object -> shipping_method_id = GETPOST ( 'shipping_method_id' , 'int' );
$object -> tracking_number = GETPOST ( 'tracking_number' , 'alpha' );
$object -> ref_int = GETPOST ( 'ref_int' , 'alpha' );
2017-09-25 00:16:52 +02:00
$object -> note_private = GETPOST ( 'note_private' , 'none' );
$object -> note_public = GETPOST ( 'note_public' , 'none' );
2015-02-23 09:16:14 +01:00
$object -> fk_incoterms = GETPOST ( 'incoterm_id' , 'int' );
$object -> location_incoterms = GETPOST ( 'location_incoterms' , 'alpha' );
2015-01-18 17:13:42 +01:00
2015-02-16 20:14:16 +01:00
$batch_line = array ();
2015-12-18 18:00:31 +01:00
$stockLine = array ();
2015-12-18 19:31:02 +01:00
$array_options = array ();
2015-02-16 20:14:16 +01:00
2015-01-18 17:13:42 +01:00
$num = count ( $objectsrc -> lines );
$totalqty = 0 ;
2015-08-14 23:53:59 +02:00
2015-01-18 17:13:42 +01:00
for ( $i = 0 ; $i < $num ; $i ++ )
{
2015-02-16 20:14:16 +01:00
$idl = " idl " . $i ;
2015-01-18 17:13:42 +01:00
$sub_qty = array ();
$subtotalqty = 0 ;
2015-02-16 20:14:16 +01:00
$j = 0 ;
2015-01-18 17:13:42 +01:00
$batch = " batchl " . $i . " _0 " ;
2015-12-18 18:00:31 +01:00
$stockLocation = " ent1 " . $i . " _0 " ;
2015-02-16 20:14:16 +01:00
$qty = " qtyl " . $i ;
2016-11-14 13:40:41 +01:00
if ( $objectsrc -> lines [ $i ] -> product_tobatch ) // If product need a batch number
{
if ( isset ( $_POST [ $batch ]))
{
//shipment line with batch-enable product
$qty .= '_' . $j ;
while ( isset ( $_POST [ $batch ]))
{
// save line of detail into sub_qty
2017-02-16 01:39:16 +01:00
$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
2016-11-14 13:40:41 +01:00
$subtotalqty += $sub_qty [ $j ][ 'q' ];
2017-06-07 16:44:04 +02:00
2016-11-14 13:40:41 +01:00
//var_dump($qty);var_dump($batch);var_dump($sub_qty[$j]['q']);var_dump($sub_qty[$j]['id_batch']);
2017-06-07 16:44:04 +02:00
2016-11-14 13:40:41 +01:00
$j ++ ;
$batch = " batchl " . $i . " _ " . $j ;
$qty = " qtyl " . $i . '_' . $j ;
}
2017-06-07 16:44:04 +02:00
2016-11-14 13:40:41 +01:00
$batch_line [ $i ][ 'detail' ] = $sub_qty ; // array of details
$batch_line [ $i ][ 'qty' ] = $subtotalqty ;
$batch_line [ $i ][ 'ix_l' ] = GETPOST ( $idl , 'int' );
2017-06-07 16:44:04 +02:00
2016-11-14 13:40:41 +01:00
$totalqty += $subtotalqty ;
}
else
{
2017-02-16 01:39:16 +01:00
// No detail were provided for lots
if ( ! empty ( $_POST [ $qty ]))
{
// 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
2018-07-25 15:25:23 +02:00
setEventMessages ( $langs -> trans ( " StockIsRequiredToChooseWhichLotToUse " ), null , 'errors' );
2017-02-16 01:39:16 +01:00
}
2016-11-14 13:40:41 +01:00
}
2015-02-16 20:14:16 +01:00
}
2015-12-18 18:00:31 +01:00
else if ( isset ( $_POST [ $stockLocation ]))
{
//shipment line from multiple stock locations
$qty .= '_' . $j ;
while ( isset ( $_POST [ $stockLocation ]))
{
// save sub line of warehouse
$stockLine [ $i ][ $j ][ 'qty' ] = GETPOST ( $qty , 'int' );
$stockLine [ $i ][ $j ][ 'warehouse_id' ] = GETPOST ( $stockLocation , 'int' );
$stockLine [ $i ][ $j ][ 'ix_l' ] = GETPOST ( $idl , 'int' );
2016-02-20 04:25:39 +01:00
$totalqty += GETPOST ( $qty , 'int' );
2017-06-07 16:44:04 +02:00
2015-12-18 18:00:31 +01:00
$j ++ ;
$stockLocation = " ent1 " . $i . " _ " . $j ;
$qty = " qtyl " . $i . '_' . $j ;
2017-06-07 16:44:04 +02:00
}
2015-12-18 18:00:31 +01:00
}
2015-02-16 20:14:16 +01:00
else
{
2016-04-01 10:57:18 +02:00
//var_dump(GETPOST($qty,'int')); 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
2015-01-18 17:13:42 +01:00
if ( GETPOST ( $qty , 'int' ) > 0 ) $totalqty += GETPOST ( $qty , 'int' );
}
2017-06-07 16:44:04 +02:00
2015-12-16 16:18:29 +01:00
// Extrafields
$extralabelsline = $extrafieldsline -> fetch_name_optionals_label ( $object -> table_element_line );
2016-01-08 18:15:53 +01:00
$array_options [ $i ] = $extrafieldsline -> getOptionalsFromPost ( $extralabelsline , $i );
2015-12-16 16:18:29 +01:00
// Unset extrafield
if ( is_array ( $extralabelsline )) {
// Get extra fields
foreach ( $extralabelsline as $key => $value ) {
unset ( $_POST [ " options_ " . $key ]);
}
}
2015-01-18 17:13:42 +01:00
}
2017-06-07 16:44:04 +02:00
2015-08-14 23:53:59 +02:00
//var_dump($batch_line[2]);
2015-01-18 17:13:42 +01:00
2015-02-16 20:14:16 +01:00
if ( $totalqty > 0 ) // There is at least one thing to ship
2015-01-18 17:13:42 +01:00
{
//var_dump($_POST);exit;
for ( $i = 0 ; $i < $num ; $i ++ )
{
$qty = " qtyl " . $i ;
2015-02-16 20:14:16 +01:00
if ( ! isset ( $batch_line [ $i ]))
2017-06-07 16:44:04 +02:00
{
2015-08-14 23:53:59 +02:00
// not batch mode
2015-12-18 18:00:31 +01:00
if ( isset ( $stockLine [ $i ]))
{
//shipment from multiple stock locations
2016-04-01 10:57:18 +02:00
$nbstockline = count ( $stockLine [ $i ]);
for ( $j = 0 ; $j < $nbstockline ; $j ++ )
2015-12-18 18:00:31 +01:00
{
if ( $stockLine [ $i ][ $j ][ 'qty' ] > 0 )
{
2016-02-15 02:01:58 +01:00
$ret = $object -> addline ( $stockLine [ $i ][ $j ][ 'warehouse_id' ], $stockLine [ $i ][ $j ][ 'ix_l' ], $stockLine [ $i ][ $j ][ 'qty' ], $array_options [ $i ]);
2015-12-18 18:00:31 +01:00
if ( $ret < 0 )
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
}
}
}
2016-02-15 02:01:58 +01:00
else
2014-03-07 11:35:16 +01:00
{
2016-02-15 02:01:58 +01:00
if ( GETPOST ( $qty , 'int' ) > 0 || ( GETPOST ( $qty , 'int' ) == 0 && $conf -> global -> SHIPMENT_GETS_ALL_ORDER_PRODUCTS ))
2015-01-18 17:13:42 +01:00
{
2016-02-15 02:01:58 +01:00
$ent = " entl " . $i ;
$idl = " idl " . $i ;
$entrepot_id = is_numeric ( GETPOST ( $ent , 'int' )) ? GETPOST ( $ent , 'int' ) : GETPOST ( 'entrepot_id' , 'int' );
if ( $entrepot_id < 0 ) $entrepot_id = '' ;
if ( ! ( $objectsrc -> lines [ $i ] -> fk_product > 0 )) $entrepot_id = 0 ;
2017-06-07 16:44:04 +02:00
2016-02-15 02:01:58 +01:00
$ret = $object -> addline ( $entrepot_id , GETPOST ( $idl , 'int' ), GETPOST ( $qty , 'int' ), $array_options [ $i ]);
if ( $ret < 0 )
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
2015-01-18 17:13:42 +01:00
}
}
2015-02-16 20:14:16 +01:00
}
else
2017-06-07 16:44:04 +02:00
{
2015-08-14 23:53:59 +02:00
// batch mode
2015-02-16 20:14:16 +01:00
if ( $batch_line [ $i ][ 'qty' ] > 0 )
{
2015-12-16 16:18:29 +01:00
$ret = $object -> addline_batch ( $batch_line [ $i ], $array_options [ $i ]);
2015-01-18 17:13:42 +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
}
}
2017-06-07 16:44:04 +02:00
}
2015-12-16 16:18:29 +01:00
// Fill array 'array_options' with data from add form
$ret = $extrafields -> setOptionalsFromPost ( $extralabels , $object );
if ( $ret < 0 ) $error ++ ;
2017-06-07 16:44:04 +02:00
2015-01-18 17:13:42 +01:00
if ( ! $error )
{
2015-02-16 20:14:16 +01:00
$ret = $object -> create ( $user ); // This create shipment (like Odoo picking) and line of shipments. Stock movement will when validating shipment.
2015-01-18 17:13:42 +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 ++ ;
}
}
}
else
{
2016-02-24 13:19:25 +01:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " QtyToShip " ) . '/' . $langs -> transnoentitiesnoconv ( " Warehouse " )), null , 'errors' );
2015-01-18 17:13:42 +01:00
$error ++ ;
}
if ( ! $error )
{
$db -> commit ();
header ( " Location: card.php?id= " . $object -> id );
exit ;
}
else
{
$db -> rollback ();
$_GET [ " commande_id " ] = GETPOST ( 'commande_id' , 'int' );
$action = 'create' ;
}
}
2003-11-13 18:36:45 +01:00
2015-01-18 17:13:42 +01:00
/*
* Build a receiving receipt
*/
else if ( $action == 'create_delivery' && $conf -> livraison_bon -> enabled && $user -> rights -> expedition -> livraison -> creer )
2014-04-26 17:27:59 +02:00
{
2015-01-18 17:13:42 +01:00
$result = $object -> create_delivery ( $user );
if ( $result > 0 )
{
2016-01-13 20:41:32 +01:00
header ( " Location: " . DOL_URL_ROOT . '/livraison/card.php?action=create_delivery&id=' . $result );
2015-01-18 17:13:42 +01:00
exit ;
}
else
{
2015-12-14 21:38:26 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-01-18 17:13:42 +01:00
}
}
2003-11-13 18:36:45 +01:00
2015-01-25 21:32:40 +01:00
else if ( $action == 'confirm_valid' && $confirm == 'yes' &&
(( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> expedition -> creer ))
|| ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> expedition -> shipping_advance -> validate )))
)
2015-01-18 17:13:42 +01:00
{
$object -> fetch_thirdparty ();
2017-06-07 16:44:04 +02:00
2015-01-18 17:13:42 +01:00
$result = $object -> valid ( $user );
2017-06-07 16:44:04 +02:00
2015-01-18 17:13:42 +01:00
if ( $result < 0 )
{
$langs -> load ( " errors " );
2015-12-04 19:45:39 +01:00
setEventMessages ( $langs -> trans ( $object -> error ), null , 'errors' );
2015-01-18 17:13:42 +01:00
}
else
{
// Define output language
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$outputlangs = $langs ;
$newlang = '' ;
2017-06-27 17:27:01 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) $newlang = GETPOST ( 'lang_id' , 'aZ09' );
2015-01-18 17:13:42 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> thirdparty -> default_lang ;
if ( ! empty ( $newlang )) {
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$model = $object -> modelpdf ;
$ret = $object -> fetch ( $id ); // Reload to get new records
$result = $object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
if ( $result < 0 ) dol_print_error ( $db , $result );
}
}
2014-05-14 17:20:11 +02:00
}
2013-09-06 13:25:45 +02:00
2015-01-18 17:13:42 +01:00
else if ( $action == 'confirm_delete' && $confirm == 'yes' && $user -> rights -> expedition -> supprimer )
2014-04-26 17:27:59 +02:00
{
2015-01-18 17:13:42 +01:00
$result = $object -> delete ();
if ( $result > 0 )
{
header ( " Location: " . DOL_URL_ROOT . '/expedition/index.php' );
exit ;
}
else
{
2015-12-14 21:38:26 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-01-18 17:13:42 +01:00
}
}
2015-12-14 21:38:26 +01:00
// TODO add alternative status
/* else if ( $action == 'reopen' && ( ! empty ( $user -> rights -> expedition -> creer ) || ! empty ( $user -> rights -> expedition -> shipping_advance -> validate )))
2015-01-18 17:13:42 +01:00
{
$result = $object -> setStatut ( 0 );
if ( $result < 0 )
{
2015-12-14 21:38:26 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-01-18 17:13:42 +01:00
}
2015-12-14 21:38:26 +01:00
} */
2012-08-05 20:34:51 +02:00
2015-01-18 17:13:42 +01:00
else if ( $action == 'setdate_livraison' && $user -> rights -> expedition -> creer )
{
//print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
$datedelivery = dol_mktime ( GETPOST ( 'liv_hour' , 'int' ), GETPOST ( 'liv_min' , 'int' ), 0 , GETPOST ( 'liv_month' , 'int' ), GETPOST ( 'liv_day' , 'int' ), GETPOST ( 'liv_year' , 'int' ));
$object -> fetch ( $id );
$result = $object -> set_date_livraison ( $user , $datedelivery );
if ( $result < 0 )
{
2015-12-14 21:38:26 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-01-18 17:13:42 +01:00
}
}
2011-06-02 19:20:24 +02:00
2017-12-20 12:45:38 +01:00
// Action update
2018-06-22 12:25:14 +02:00
else if (
2018-07-26 11:57:25 +02:00
( $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
)
2015-01-18 17:13:42 +01:00
{
$error = 0 ;
2017-12-20 12:45:38 +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' ));
2015-01-18 17:13:42 +01:00
if ( $action == 'settrueWeight' ) {
$object -> trueWeight = trim ( GETPOST ( 'trueWeight' , 'int' ));
$object -> weight_units = GETPOST ( 'weight_units' , 'int' );
}
if ( $action == 'settrueWidth' ) $object -> trueWidth = trim ( GETPOST ( 'trueWidth' , 'int' ));
if ( $action == 'settrueHeight' ){
$object -> trueHeight = trim ( GETPOST ( 'trueHeight' , 'int' ));
$object -> size_units = GETPOST ( 'size_units' , 'int' );
}
if ( $action == 'settrueDepth' ) $object -> trueDepth = trim ( GETPOST ( 'trueDepth' , 'int' ));
if ( $action == 'setshipping_method_id' ) $object -> shipping_method_id = trim ( GETPOST ( 'shipping_method_id' , 'int' ));
if ( ! $error )
{
if ( $object -> update ( $user ) >= 0 )
{
header ( " Location: card.php?id= " . $object -> id );
exit ;
}
2015-12-04 19:45:39 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-01-18 17:13:42 +01:00
}
$action = " " ;
2014-05-14 17:20:11 +02:00
}
2011-06-02 19:20:24 +02:00
2015-01-18 18:44:22 +01:00
elseif ( $action == 'classifybilled' )
2015-01-18 17:13:42 +01:00
{
2015-01-18 18:44:22 +01:00
$object -> fetch ( $id );
2016-10-28 19:33:21 +02:00
$result = $object -> set_billed ();
if ( $result >= 0 ) {
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ();
}
2015-01-18 17:13:42 +01:00
}
2011-06-02 19:20:24 +02:00
2016-04-26 13:27:32 +02:00
elseif ( $action == 'classifyclosed' )
{
$object -> fetch ( $id );
2016-10-28 19:33:21 +02:00
$result = $object -> setClosed ();
if ( $result >= 0 ) {
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ();
}
2016-04-26 13:27:32 +02:00
}
2017-10-23 22:18:15 +02:00
/*
* delete a line
*/
2017-10-18 18:18:17 +02:00
elseif ( $action == 'deleteline' && ! empty ( $line_id ))
{
$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 );
for ( $i = 0 ; $i < $num_prod ; $i ++ )
{
2017-11-02 12:38:36 +01:00
if ( $lines [ $i ] -> id == $line_id )
2017-10-23 22:18:15 +02:00
{
2017-11-02 12:38:36 +01:00
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 ;
if ( ! $error && $line -> delete ( $user ) < 0 )
{
$error ++ ;
}
2017-10-23 22:18:15 +02:00
}
}
2017-11-02 12:38:36 +01:00
else
2017-10-23 22:18:15 +02:00
{
2017-10-24 11:37:17 +02:00
// delete single warehouse line
$line -> id = $line_id ;
if ( ! $error && $line -> delete ( $user ) < 0 )
{
$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
2017-10-23 22:18:15 +02:00
if ( ! $error ) {
2017-10-18 18:18:17 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ();
}
2017-11-02 12:38:36 +01:00
else
2017-10-23 22:18:15 +02:00
{
setEventMessages ( $line -> error , $line -> errors , 'errors' );
}
}
/*
* Update a line
*/
else if ( $action == 'updateline' && $user -> rights -> expedition -> creer && GETPOST ( 'save' ))
{
// Clean parameters
$qty = 0 ;
$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 );
for ( $i = 0 ; $i < $num_prod ; $i ++ )
{
2017-12-01 14:33:06 +01:00
if ( $lines [ $i ] -> id == $line_id ) // we have found line to update
2017-10-23 22:18:15 +02:00
{
$line = new ExpeditionLigne ( $db );
2017-10-24 10:53:11 +02:00
// Extrafields Lines
$extrafieldsline = new ExtraFields ( $db );
$extralabelsline = $extrafieldsline -> fetch_name_optionals_label ( $object -> table_element_line );
$line -> array_options = $extrafieldsline -> getOptionalsFromPost ( $extralabelsline );
// Unset extrafield POST Data
if ( is_array ( $extralabelsline )) {
foreach ( $extralabelsline as $key => $value ) {
unset ( $_POST [ " options_ " . $key ]);
}
}
2017-10-23 22:18:15 +02:00
$line -> fk_product = $lines [ $i ] -> fk_product ;
if ( is_array ( $lines [ $i ] -> detail_batch ) && count ( $lines [ $i ] -> detail_batch ) > 0 )
{
// line with lot
2017-11-02 12:38:36 +01:00
foreach ( $lines [ $i ] -> detail_batch as $detail_batch )
2017-10-23 22:18:15 +02:00
{
$lotStock = new Productbatch ( $db );
$batch = " batchl " . $detail_batch -> fk_expeditiondet . " _ " . $detail_batch -> fk_origin_stock ;
$qty = " qtyl " . $detail_batch -> fk_expeditiondet . '_' . $detail_batch -> id ;
$batch_id = GETPOST ( $batch , 'int' );
2017-10-30 12:39:06 +01:00
$batch_qty = GETPOST ( $qty , 'int' );
2018-10-11 11:56:52 +02:00
if ( ! empty ( $batch_id ) && ( $batch_id != $detail_batch -> fk_origin_stock || $batch_qty != $detail_batch -> qty ))
2017-10-23 22:18:15 +02:00
{
2017-11-02 12:38:36 +01:00
if ( $lotStock -> fetch ( $batch_id ) > 0 && $line -> fetch ( $detail_batch -> fk_expeditiondet ) > 0 ) // $line is ExpeditionLine
2017-10-23 22:18:15 +02:00
{
2017-10-30 12:39:06 +01:00
if ( $lines [ $i ] -> entrepot_id != 0 )
{
// 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
if ( empty ( $line -> detail_batch )) $line -> detail_batch = new stdClass ();
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 ++ ;
}
}
2017-11-02 12:38:36 +01: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 );
$batch = " batchl " . $line_id . " _0 " ;
$qty = " qtyl " . $line_id . " _0 " ;
$batch_id = GETPOST ( $batch , 'int' );
$batch_qty = GETPOST ( $qty , 'int' );
$lineIdToAddLot = 0 ;
if ( $batch_qty > 0 && ! empty ( $batch_id ))
{
if ( $lotStock -> fetch ( $batch_id ) > 0 )
{
// check if lotStock warehouse id is same as line warehouse id
if ( $lines [ $i ] -> entrepot_id > 0 )
{
// single warehouse shipment line
if ( $lines [ i ] -> entrepot_id == $lotStock -> warehouseid )
{
$lineIdToAddLot = $line_id ;
}
}
else if ( count ( $lines [ $i ] -> details_entrepot ) > 1 )
{
// multi warehouse shipment lines
foreach ( $lines [ $i ] -> details_entrepot as $detail_entrepot )
{
if ( $detail_entrepot -> entrepot_id == $lotStock -> warehouseid )
{
$lineIdToAddLot = $detail_entrepot -> line_id ;
}
}
}
2017-11-24 15:27:00 +01:00
if ( $lineIdToAddLot )
2017-11-02 11:44:36 +01:00
{
// add lot to existing line
if ( $line -> fetch ( $lineIdToAddLot ) > 0 )
{
$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 ++ ;
}
}
else
{
setEventMessages ( $line -> error , $line -> errors , 'errors' );
$error ++ ;
}
}
else
{
// 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 ;
2017-11-02 11:44:36 +01:00
if ( $object -> create_line_batch ( $line , $line -> array_options ) < 0 )
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
}
}
2017-11-24 15:27:00 +01:00
else
2017-11-02 11:44:36 +01:00
{
setEventMessages ( $lotStock -> error , $lotStock -> errors , 'errors' );
$error ++ ;
}
}
2017-10-23 22:18:15 +02:00
}
2017-11-02 12:38:36 +01:00
else
2017-10-23 22:18:15 +02:00
{
2017-12-01 14:33:06 +01:00
if ( $lines [ $i ] -> fk_product > 0 )
{
// line without lot
if ( $lines [ $i ] -> entrepot_id > 0 )
{
// single warehouse shipment line
$stockLocation = " entl " . $line_id ;
$qty = " qtyl " . $line_id ;
$line -> id = $line_id ;
$line -> entrepot_id = GETPOST ( $stockLocation , 'int' );
$line -> qty = GETPOST ( $qty , 'int' );
if ( $line -> update ( $user ) < 0 ) {
setEventMessages ( $line -> error , $line -> errors , 'errors' );
$error ++ ;
}
unset ( $_POST [ $stockLocation ]);
unset ( $_POST [ $qty ]);
}
else if ( count ( $lines [ $i ] -> details_entrepot ) > 1 )
{
// multi warehouse shipment lines
foreach ( $lines [ $i ] -> details_entrepot as $detail_entrepot )
{
if ( ! $error ) {
$stockLocation = " entl " . $detail_entrepot -> line_id ;
$qty = " qtyl " . $detail_entrepot -> line_id ;
$warehouse = GETPOST ( $stockLocation , 'int' );
if ( ! empty ( $warehouse ))
{
$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 ]);
}
}
}
}
else // 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
if ( ! $error ) {
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
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 ;
if ( ! empty ( $newlang )) {
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$ret = $object -> fetch ( $object -> id ); // Reload to get new records
$object -> generateDocument ( $object -> modelpdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
}
}
2017-11-02 12:38:36 +01:00
else
2017-10-23 22:18:15 +02:00
{
header ( 'Location: ' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id ); // Pour reaffichage de la fiche en cours d'edition
exit ();
}
}
else if ( $action == 'updateline' && $user -> rights -> expedition -> creer && GETPOST ( 'cancel' , 'alpha' ) == $langs -> trans ( 'Cancel' )) {
header ( 'Location: ' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id ); // Pour reaffichage de la fiche en cours d'edition
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
if ( empty ( $id )) $id = $facid ;
$trigger_name = 'SHIPPING_SENTBYMAIL' ;
$paramname = 'id' ;
$mode = 'emailfromshipment' ;
2016-10-03 00:38:28 +02:00
$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
2013-09-25 19:07:25 +02:00
llxHeader ( '' , $langs -> trans ( 'Shipment' ), 'Expedition' );
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 );
2016-09-19 13:57:50 +02: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 );
2011-08-21 13:00:43 +02:00
if ( $action == 'create2' )
{
2016-11-14 14:34:15 +01:00
print load_fiche_titre ( $langs -> trans ( " CreateShipment " )) . '<br>' ;
2011-08-21 13:00:43 +02:00
print $langs -> trans ( " ShipmentCreationIsDoneFromOrder " );
$action = '' ; $id = '' ; $ref = '' ;
}
2017-06-07 16:44:04 +02:00
// Mode creation.
2011-05-30 20:49:31 +02:00
if ( $action == 'create' )
2003-11-13 18:36:45 +01:00
{
2012-03-14 14:48:27 +01:00
$expe = new Expedition ( $db );
2016-11-14 14:34:15 +01:00
print load_fiche_titre ( $langs -> trans ( " CreateShipment " ));
2012-03-14 14:48:27 +01:00
if ( ! $origin )
{
2015-12-04 19:45:39 +01:00
setEventMessages ( $langs -> trans ( " ErrorBadParameters " ), null , 'errors' );
2012-03-14 14:48:27 +01:00
}
if ( $origin )
{
$classname = ucfirst ( $origin );
$object = new $classname ( $db );
if ( $object -> fetch ( $origin_id )) // This include the fetch_lines
{
$soc = new Societe ( $db );
$soc -> fetch ( $object -> socid );
$author = new User ( $db );
$author -> fetch ( $object -> user_author_id );
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> stock -> enabled )) $entrepot = new Entrepot ( $db );
2012-03-14 14:48:27 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ '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 . '">' ;
if ( GETPOST ( 'entrepot_id' , 'int' ))
{
print '<input type="hidden" name="entrepot_id" value="' . GETPOST ( 'entrepot_id' , 'int' ) . '">' ;
}
2015-07-13 11:22:18 +02:00
dol_fiche_head ( '' );
2015-10-22 19:13:16 +02:00
print '<table class="border centpercent">' ;
2012-03-14 14:48:27 +01:00
// Ref
2016-11-14 13:40:41 +01:00
print '<tr><td class="titlefieldcreate fieldrequired">' ;
2012-09-15 11:21:22 +02:00
if ( $origin == 'commande' && ! empty ( $conf -> commande -> enabled ))
2012-03-14 14:48:27 +01:00
{
2014-09-18 21:18:25 +02:00
print $langs -> trans ( " RefOrder " ) . '</td><td colspan="3"><a href="' . DOL_URL_ROOT . '/commande/card.php?id=' . $object -> id . '">' . img_object ( $langs -> trans ( " ShowOrder " ), 'order' ) . ' ' . $object -> ref ;
2012-03-14 14:48:27 +01:00
}
2012-09-15 11:21:22 +02:00
if ( $origin == 'propal' && ! empty ( $conf -> propal -> enabled ))
2012-03-14 14:48:27 +01:00
{
2014-09-18 21:18:25 +02:00
print $langs -> trans ( " RefProposal " ) . '</td><td colspan="3"><a href="' . DOL_URL_ROOT . '/comm/card.php?id=' . $object -> id . '">' . img_object ( $langs -> trans ( " ShowProposal " ), 'propal' ) . ' ' . $object -> ref ;
2012-03-14 14:48:27 +01:00
}
print '</a></td>' ;
print " </tr> \n " ;
// Ref client
print '<tr><td>' ;
2013-04-14 12:19:21 +02:00
if ( $origin == 'commande' ) print $langs -> trans ( 'RefCustomerOrder' );
else if ( $origin == 'propal' ) print $langs -> trans ( 'RefCustomerOrder' );
else print $langs -> trans ( 'RefCustomer' );
print '</td><td colspan="3">' ;
2017-10-20 12:28:33 +02:00
print '<input type="text" name="ref_customer" value="' . $object -> ref_client . '" />' ;
2012-03-14 14:48:27 +01:00
print '</td>' ;
print '</tr>' ;
// Tiers
2016-11-14 13:40:41 +01:00
print '<tr><td class="titlefieldcreate fieldrequired">' . $langs -> trans ( 'Company' ) . '</td>' ;
2012-03-14 14:48:27 +01:00
print '<td colspan="3">' . $soc -> getNomUrl ( 1 ) . '</td>' ;
print '</tr>' ;
2017-05-19 08:50:10 +02:00
// Project
if ( ! empty ( $conf -> projet -> enabled ))
{
2017-06-27 16:41:57 +02:00
$projectid = GETPOST ( 'projectid' , 'int' ) ? GETPOST ( 'projectid' , 'int' ) : 0 ;
2018-07-30 15:16:53 +02:00
if ( empty ( $projectid ) && ! empty ( $object -> fk_project )) $projectid = $object -> fk_project ;
2017-05-19 08:50:10 +02:00
if ( $origin == 'project' ) $projectid = ( $originid ? $originid : 0 );
$langs -> load ( " projects " );
print '<tr>' ;
print '<td>' . $langs -> trans ( " Project " ) . '</td><td colspan="2">' ;
$numprojet = $formproject -> select_projects ( $soc -> id , $projectid , 'projectid' , 0 );
print ' <a href="' . DOL_URL_ROOT . '/projet/card.php?socid=' . $soc -> id . '&action=create&status=1&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ] . '?action=create&socid=' . $soc -> id ) . '">' . $langs -> trans ( " AddProject " ) . '</a>' ;
print '</td>' ;
print '</tr>' ;
}
2012-03-14 14:48:27 +01:00
// Date delivery planned
print '<tr><td>' . $langs -> trans ( " DateDeliveryPlanned " ) . '</td>' ;
print '<td colspan="3">' ;
//print dol_print_date($object->date_livraison,"day"); // date_livraison come from order and will be stored into date_delivery planed.
2014-11-11 11:21:31 +01:00
$date_delivery = ( $date_delivery ? $date_delivery : $object -> date_livraison ); // $date_delivery comes from GETPOST
2018-09-09 09:36:12 +02:00
print $form -> selectDate ( $date_delivery ? $date_delivery :- 1 , 'date_delivery' , 1 , 1 , 1 );
2012-03-14 14:48:27 +01:00
print " </td> \n " ;
print '</tr>' ;
2013-08-07 15:08:30 +02:00
// Note Public
2013-04-09 17:18:07 +02:00
print '<tr><td>' . $langs -> trans ( " NotePublic " ) . '</td>' ;
print '<td colspan="3">' ;
2016-11-25 17:47:47 +01:00
$doleditor = new DolEditor ( 'note_public' , $object -> note_public , '' , 60 , 'dolibarr_notes' , 'In' , 0 , false , true , ROWS_3 , '90%' );
2013-04-09 17:18:07 +02:00
print $doleditor -> Create ( 1 );
print " </td></tr> " ;
2012-03-14 14:48:27 +01:00
2013-04-09 17:18:07 +02:00
// Note Private
if ( $object -> note_private && ! $user -> societe_id )
2012-03-14 14:48:27 +01:00
{
print '<tr><td>' . $langs -> trans ( " NotePrivate " ) . '</td>' ;
2013-04-09 17:18:07 +02:00
print '<td colspan="3">' ;
2016-11-25 17:47:47 +01:00
$doleditor = new DolEditor ( 'note_private' , $object -> note_private , '' , 60 , 'dolibarr_notes' , 'In' , 0 , false , true , ROWS_3 , '90%' );
2013-08-07 15:08:30 +02:00
print $doleditor -> Create ( 1 );
2013-04-09 17:18:07 +02:00
print " </td></tr> " ;
2012-03-14 14:48:27 +01:00
}
// Weight
print '<tr><td>' ;
print $langs -> trans ( " Weight " );
2017-06-07 16:44:04 +02:00
print '</td><td colspan="3"><input name="weight" size="4" value="' . GETPOST ( 'weight' , 'int' ) . '"> ' ;
2017-04-18 17:04:56 +02:00
$text = $formproduct -> select_measuring_units ( " weight_units " , " weight " , GETPOST ( 'weight_units' , 'int' ));
$htmltext = $langs -> trans ( " KeepEmptyForAutoCalculation " );
print $form -> textwithpicto ( $text , $htmltext );
2016-11-14 13:40:41 +01:00
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 ' ' ;
2017-04-18 17:04:56 +02:00
$text = $formproduct -> select_measuring_units ( " size_units " , " size " );
$htmltext = $langs -> trans ( " KeepEmptyForAutoCalculation " );
print $form -> textwithpicto ( $text , $htmltext );
2016-11-14 13:40:41 +01:00
print '</td></tr>' ;
2012-03-14 14:48:27 +01:00
// Delivery method
print " <tr><td> " . $langs -> trans ( " DeliveryMethod " ) . " </td> " ;
print '<td colspan="3">' ;
$expe -> fetch_delivery_methods ();
2017-08-19 13:26:50 +02:00
print $form -> selectarray ( " shipping_method_id " , $expe -> meths , GETPOST ( 'shipping_method_id' , 'int' ), 1 , 0 , 0 , " " , 1 );
2014-09-04 18:41:28 +02:00
if ( $user -> admin ) print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
2012-03-14 14:48:27 +01: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 " ;
2017-06-07 16:44:04 +02:00
2015-12-16 16:18:29 +01:00
// Other attributes
$parameters = array ( 'objectsrc' => $objectsrc , 'colspan' => ' colspan="3"' , 'socid' => $socid );
2017-10-26 11:32:26 +02:00
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $expe , $action ); // Note that $action and $object may have been modified by hook
2017-06-11 10:37:58 +02:00
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
$orderExtrafields = new Extrafields ( $db );
$orderExtrafieldLabels = $orderExtrafields -> fetch_name_optionals_label ( $object -> table_element );
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 );
}
2018-09-05 10:00:33 +02:00
print $expe -> showOptionals ( $extrafields , 'edit' );
2017-09-19 18:43:00 +02:00
}
2017-06-07 16:44:04 +02:00
2012-03-14 14:48:27 +01:00
2015-02-23 09:16:14 +01:00
// Incoterms
if ( ! empty ( $conf -> incoterm -> enabled ))
{
print '<tr>' ;
2016-03-25 15:24:57 +01:00
print '<td><label for="incoterm_id">' . $form -> textwithpicto ( $langs -> trans ( " IncotermLabel " ), $object -> libelle_incoterms , 1 ) . '</label></td>' ;
2015-02-23 09:16:14 +01: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 : '' ));
print '</td></tr>' ;
}
2015-03-18 21:44:57 +01:00
2015-04-18 11:24:55 +02:00
// Document model
include_once DOL_DOCUMENT_ROOT . '/core/modules/expedition/modules_expedition.php' ;
$liste = ModelePdfExpedition :: liste_modeles ( $db );
2016-04-01 11:12:49 +02:00
if ( count ( $liste ) > 1 )
{
2016-12-06 15:03:39 +01:00
print " <tr><td> " . $langs -> trans ( " DefaultModel " ) . " </td> " ;
2016-04-01 11:12:49 +02:00
print '<td colspan="3">' ;
print $form -> selectarray ( 'model' , $liste , $conf -> global -> EXPEDITION_ADDON_PDF );
print " </td></tr> \n " ;
}
2017-06-07 16:44:04 +02:00
2012-03-14 14:48:27 +01:00
print " </table> " ;
2015-07-13 11:22:18 +02:00
dol_fiche_end ();
2017-06-07 16:44:04 +02:00
2016-02-10 23:37:34 +01:00
// Shipment lines
2013-08-07 15:08:30 +02:00
2012-03-14 14:48:27 +01:00
$numAsked = count ( $object -> lines );
2013-08-07 15:08:30 +02:00
2013-04-21 14:14:30 +02:00
print ' < script type = " text/javascript " language = " javascript " >
jQuery ( document ) . ready ( function () {
jQuery ( " #autofill " ) . click ( function () { ' ;
2013-04-14 12:19:21 +02:00
$i = 0 ;
while ( $i < $numAsked )
{
print 'jQuery("#qtyl' . $i . '").val(jQuery("#qtyasked' . $i . '").val() - jQuery("#qtydelivered' . $i . '").val());' . " \n " ;
$i ++ ;
2013-04-21 14:14:30 +02:00
}
print ' });
2013-04-14 12:19:21 +02:00
jQuery ( " #autoreset " ) . click ( function () { ' ;
$i = 0 ;
while ( $i < $numAsked )
{
print 'jQuery("#qtyl' . $i . '").val(0);' . " \n " ;
$i ++ ;
}
print ' });
2013-04-21 14:14:30 +02:00
});
</ script > ' ;
2013-08-07 15:08:30 +02:00
2013-04-14 12:19:21 +02:00
print '<br>' ;
2017-06-07 16:44:04 +02:00
2013-04-14 12:19:21 +02:00
print '<table class="noborder" width="100%">' ;
2012-03-14 14:48:27 +01:00
2017-02-16 01:39:16 +01:00
// Load shipments already done for same order
2012-03-14 14:48:27 +01:00
$object -> loadExpeditions ();
2017-06-07 16:44:04 +02:00
2012-03-14 14:48:27 +01:00
if ( $numAsked )
{
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " Description " ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " QtyOrdered " ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " QtyShipped " ) . '</td>' ;
2013-04-14 12:19:21 +02:00
print '<td align="center">' . $langs -> trans ( " QtyToShip " );
2017-06-07 16:44:04 +02:00
if ( empty ( $conf -> productbatch -> enabled ))
2015-08-14 20:37:20 +02:00
{
print ' <br>(<a href="#" id="autofill">' . $langs -> trans ( " Fill " ) . '</a>' ;
print ' / <a href="#" id="autoreset">' . $langs -> trans ( " Reset " ) . '</a>)' ;
2014-03-07 11:35:16 +01:00
}
2013-04-14 12:19:21 +02:00
print '</td>' ;
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> stock -> enabled ))
2012-03-14 14:48:27 +01:00
{
2014-12-05 16:01:01 +01:00
if ( empty ( $conf -> productbatch -> enabled ))
{
print '<td align="left">' . $langs -> trans ( " Warehouse " ) . ' (' . $langs -> trans ( " Stock " ) . ')</td>' ;
}
else
{
print '<td align="left">' . $langs -> trans ( " Warehouse " ) . ' / ' . $langs -> trans ( " Batch " ) . ' (' . $langs -> trans ( " Stock " ) . ')</td>' ;
2014-03-07 11:35:16 +01:00
}
2012-03-14 14:48:27 +01:00
}
print " </tr> \n " ;
}
$indiceAsked = 0 ;
while ( $indiceAsked < $numAsked )
{
$product = new Product ( $db );
$line = $object -> lines [ $indiceAsked ];
2017-06-07 16:44:04 +02:00
2012-03-14 14:48:27 +01: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.
if ( ! empty ( $line -> date_start )) $type = 1 ;
if ( ! empty ( $line -> date_end )) $type = 1 ;
2017-06-27 16:41:57 +02:00
print '<!-- line ' . $line -> rowid . ' for product -->' . " \n " ;
2017-04-18 17:04:56 +02:00
print '<tr class="oddeven">' . " \n " ;
2017-06-07 16:44:04 +02:00
2012-03-14 14:48:27 +01:00
// Product label
2016-02-15 02:01:58 +01:00
if ( $line -> fk_product > 0 ) // If predefined product
2012-03-14 14:48:27 +01:00
{
$product -> fetch ( $line -> fk_product );
2017-12-02 10:43:01 +01:00
$product -> load_stock ( 'warehouseopen' ); // Load all $product->stock_warehouse[idwarehouse]->detail_batch
//var_dump($product->stock_warehouse[1]);
2012-03-14 14:48:27 +01:00
print '<td>' ;
print '<a name="' . $line -> rowid . '"></a>' ; // ancre pour retourner sur la ligne
// Show product and description
$product_static -> type = $line -> fk_product_type ;
$product_static -> id = $line -> fk_product ;
$product_static -> ref = $line -> ref ;
2016-11-14 13:40:41 +01:00
$product_static -> status_batch = $line -> product_tobatch ;
2012-03-14 14:48:27 +01:00
$text = $product_static -> getNomUrl ( 1 );
2012-08-25 15:21:34 +02:00
$text .= ' - ' . ( ! empty ( $line -> label ) ? $line -> label : $line -> product_label );
2012-03-14 14:48:27 +01:00
$description = ( $conf -> global -> PRODUIT_DESC_IN_FORM ? '' : dol_htmlentitiesbr ( $line -> desc ));
2016-03-25 15:24:57 +01:00
print $form -> textwithtooltip ( $text , $description , 3 , '' , '' , $i );
2012-03-14 14:48:27 +01:00
// Show range
print_date_range ( $db -> jdate ( $line -> date_start ), $db -> jdate ( $line -> date_end ));
// Add description in form
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> global -> PRODUIT_DESC_IN_FORM ))
2012-03-14 14:48:27 +01:00
{
print ( $line -> desc && $line -> desc != $line -> product_label ) ? '<br>' . dol_htmlentitiesbr ( $line -> desc ) : '' ;
}
2017-06-07 16:44:04 +02:00
2012-03-14 14:48:27 +01:00
print '</td>' ;
}
else
2014-12-05 16:01:01 +01:00
{
2016-02-10 23:37:34 +01:00
print " <td> " ;
2012-03-14 14:48:27 +01:00
if ( $type == 1 ) $text = img_object ( $langs -> trans ( 'Service' ), 'service' );
else $text = img_object ( $langs -> trans ( 'Product' ), 'product' );
2012-08-25 15:21:34 +02:00
if ( ! empty ( $line -> label )) {
$text .= ' <strong>' . $line -> label . '</strong>' ;
2016-03-25 15:24:57 +01:00
print $form -> textwithtooltip ( $text , $line -> desc , 3 , '' , '' , $i );
2012-08-25 15:21:34 +02:00
} else {
print $text . ' ' . nl2br ( $line -> desc );
}
2012-03-14 14:48:27 +01:00
// Show range
print_date_range ( $db -> jdate ( $line -> date_start ), $db -> jdate ( $line -> date_end ));
print " </td> \n " ;
}
// Qty
2013-04-14 12:19:21 +02:00
print '<td align="center">' . $line -> qty ;
print '<input name="qtyasked' . $indiceAsked . '" id="qtyasked' . $indiceAsked . '" type="hidden" value="' . $line -> qty . '">' ;
print '</td>' ;
2012-03-14 14:48:27 +01:00
$qtyProdCom = $line -> qty ;
2016-02-10 23:37:34 +01:00
// Qty already shipped
2012-03-14 14:48:27 +01:00
print '<td align="center">' ;
$quantityDelivered = $object -> expeditions [ $line -> id ];
print $quantityDelivered ;
2013-04-14 12:19:21 +02:00
print '<input name="qtydelivered' . $indiceAsked . '" id="qtydelivered' . $indiceAsked . '" type="hidden" value="' . $quantityDelivered . '">' ;
2012-03-14 14:48:27 +01:00
print '</td>' ;
2017-02-16 01:39:16 +01:00
// Qty to ship
2012-03-14 14:48:27 +01:00
$quantityAsked = $line -> qty ;
2015-12-18 18:00:31 +01:00
if ( $line -> product_type == 1 && empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES ))
{
$quantityToBeDelivered = 0 ;
}
else
{
$quantityToBeDelivered = $quantityAsked - $quantityDelivered ;
}
2014-12-05 16:01:01 +01:00
$warehouse_id = GETPOST ( 'entrepot_id' , 'int' );
2017-06-07 16:44:04 +02:00
2015-12-18 18:00:31 +01:00
$warehouseObject = null ;
2016-04-01 10:57:18 +02: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
2014-03-31 02:41:15 +02:00
{
2016-04-01 10:57:18 +02:00
print '<!-- Case warehouse already known or product not a predefined product -->' ;
2015-12-18 18:00:31 +01:00
//ship from preselected location
$stock = + $product -> stock_warehouse [ $warehouse_id ] -> real ; // Convert to number
$deliverableQty = min ( $quantityToBeDelivered , $stock );
2016-04-26 13:13:18 +02:00
if ( $deliverableQty < 0 ) $deliverableQty = 0 ;
2017-02-16 01:39:16 +01:00
if ( empty ( $conf -> productbatch -> enabled ) || ! $product -> hasbatch ())
2014-03-26 17:18:02 +01:00
{
2015-12-18 18:00:31 +01:00
// Quantity to send
print '<td align="center">' ;
2017-12-01 13:40:24 +01:00
if ( $line -> product_type == Product :: TYPE_PRODUCT || ! empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES ))
2014-03-26 17:18:02 +01:00
{
2018-02-28 11:24:00 +01:00
if ( GETPOST ( 'qtyl' . $indiceAsked , 'int' )) $deliverableQty = GETPOST ( 'qtyl' . $indiceAsked , 'int' );
2016-02-20 04:25:39 +01:00
print '<input name="idl' . $indiceAsked . '" type="hidden" value="' . $line -> id . '">' ;
2015-12-18 18:00:31 +01:00
print '<input name="qtyl' . $indiceAsked . '" id="qtyl' . $indiceAsked . '" type="text" size="4" value="' . $deliverableQty . '">' ;
}
else print $langs -> trans ( " NA " );
print '</td>' ;
// Stock
if ( ! empty ( $conf -> stock -> enabled ))
2014-03-26 17:18:02 +01:00
{
2015-12-18 18:00:31 +01:00
print '<td align="left">' ;
2017-12-01 13:40:24 +01:00
if ( $line -> product_type == Product :: TYPE_PRODUCT || ! empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES )) // Type of product need stock change ?
2014-03-26 17:18:02 +01:00
{
2015-12-18 18:00:31 +01:00
// Show warehouse combo list
$ent = " entl " . $indiceAsked ;
$idl = " idl " . $indiceAsked ;
$tmpentrepot_id = is_numeric ( GETPOST ( $ent , 'int' )) ? GETPOST ( $ent , 'int' ) : $warehouse_id ;
2016-01-12 13:56:00 +01:00
if ( $line -> fk_product > 0 )
2014-03-26 17:18:02 +01:00
{
2016-04-01 11:05:15 +02:00
print '<!-- Show warehouse selection -->' ;
print $formproduct -> selectWarehouses ( $tmpentrepot_id , 'entl' . $indiceAsked , '' , 1 , 0 , $line -> fk_product , '' , 1 );
2016-01-12 13:56:00 +01:00
if ( $tmpentrepot_id > 0 && $tmpentrepot_id == $warehouse_id )
2015-12-18 18:00:31 +01:00
{
2016-01-12 13:56:00 +01:00
//print $stock.' '.$quantityToBeDelivered;
if ( $stock < $quantityToBeDelivered )
{
print ' ' . img_warning ( $langs -> trans ( " StockTooLow " )); // Stock too low for this $warehouse_id but you can change warehouse
}
2015-12-18 18:00:31 +01:00
}
2014-03-26 17:18:02 +01:00
}
}
2015-12-18 18:00:31 +01:00
else
{
print $langs -> trans ( " Service " );
}
print '</td>' ;
2014-03-26 17:18:02 +01:00
}
2015-08-14 20:37:20 +02:00
2015-12-18 18:00:31 +01:00
print " </tr> \n " ;
// Show subproducts of product
if ( ! empty ( $conf -> global -> PRODUIT_SOUSPRODUITS ) && $line -> fk_product > 0 )
{
$product -> get_sousproduits_arbo ();
$prods_arbo = $product -> get_arbo_each_prod ( $qtyProdCom );
if ( count ( $prods_arbo ) > 0 )
{
foreach ( $prods_arbo as $key => $value )
{
//print $value[0];
$img = '' ;
if ( $value [ 'stock' ] < $value [ 'stock_alert' ])
{
$img = img_warning ( $langs -> trans ( " StockTooLow " ));
}
2017-05-15 16:25:51 +02:00
print " <tr class= \" oddeven \" ><td> ->
2015-12-18 18:00:31 +01:00
< a href = \ " " . DOL_URL_ROOT . " /product/card.php?id= " . $value [ 'id' ] . " \" > " . $value [ 'fullpath' ] . "
</ a > ( " . $value['nb'] . " ) </ td >< td align = \ " center \" > " . $value [ 'nb_total' ] . " </td><td> </td><td> </td>
< td align = \ " center \" > " . $value [ 'stock' ] . " " . $img . " </td></tr> " ;
}
}
}
}
else
2014-12-05 16:01:01 +01:00
{
2017-02-16 01:39:16 +01:00
// Product need lot
2015-12-18 18:00:31 +01:00
print '<td></td><td></td></tr>' ; // end line and start a new one for lot/serial
2018-10-11 11:56:52 +02:00
print '<!-- Case product need lot -->' ;
2017-06-07 16:44:04 +02:00
2015-12-18 18:00:31 +01:00
$staticwarehouse = new Entrepot ( $db );
2016-02-10 23:37:34 +01:00
if ( $warehouse_id > 0 ) $staticwarehouse -> fetch ( $warehouse_id );
2017-06-07 16:44:04 +02:00
2015-12-18 18:00:31 +01:00
$subj = 0 ;
2017-02-16 01:39:16 +01:00
// Define nb of lines suggested for this order line
$nbofsuggested = 0 ;
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 )
{
$nbofsuggested ++ ;
}
}
2015-12-18 18:00:31 +01:00
print '<input name="idl' . $indiceAsked . '" type="hidden" value="' . $line -> id . '">' ;
2017-02-16 01:39:16 +01:00
if ( is_object ( $product -> stock_warehouse [ $warehouse_id ]) && count ( $product -> stock_warehouse [ $warehouse_id ] -> detail_batch ))
2015-12-18 18:00:31 +01:00
{
2018-10-11 11:56:52 +02:00
foreach ( $product -> stock_warehouse [ $warehouse_id ] -> detail_batch as $dbatch ) // $dbatch is instance of Productbatch
2015-12-18 18:00:31 +01:00
{
//var_dump($dbatch);
$batchStock = + $dbatch -> qty ; // To get a numeric
$deliverableQty = min ( $quantityToBeDelivered , $batchStock );
2017-02-16 01:39:16 +01:00
print '<!-- subj=' . $subj . '/' . $nbofsuggested . ' --><tr ' . ((( $subj + 1 ) == $nbofsuggested ) ? $bc [ $var ] : '' ) . '>' ;
print '<td colspan="3" ></td><td align="center">' ;
2015-12-18 18:00:31 +01:00
print '<input name="qtyl' . $indiceAsked . '_' . $subj . '" id="qtyl' . $indiceAsked . '_' . $subj . '" type="text" size="4" value="' . $deliverableQty . '">' ;
print '</td>' ;
2017-06-07 16:44:04 +02:00
2017-12-02 10:43:01 +01:00
print '<!-- Show details of lot -->' ;
2015-12-18 18:00:31 +01:00
print '<td align="left">' ;
2017-06-07 16:44:04 +02:00
2015-12-18 18:00:31 +01:00
print $staticwarehouse -> getNomUrl ( 0 ) . ' / ' ;
2017-06-07 16:44:04 +02:00
2015-12-18 18:00:31 +01:00
print '<input name="batchl' . $indiceAsked . '_' . $subj . '" type="hidden" value="' . $dbatch -> id . '">' ;
2017-12-02 10:43:01 +01:00
$detail = '' ;
$detail .= $langs -> trans ( " Batch " ) . ': ' . $dbatch -> batch ;
$detail .= ' - ' . $langs -> trans ( " SellByDate " ) . ': ' . dol_print_date ( $dbatch -> sellby , " day " );
2017-12-02 11:34:56 +01:00
$detail .= ' - ' . $langs -> trans ( " EatByDate " ) . ': ' . dol_print_date ( $dbatch -> eatby , " day " );
2018-10-11 11:56:52 +02:00
$detail .= ' - ' . $langs -> trans ( " Qty " ) . ': ' . $dbatch -> qty ;
2017-12-02 10:43:01 +01:00
$detail .= '<br>' ;
print $detail ;
2015-12-18 18:00:31 +01:00
$quantityToBeDelivered -= $deliverableQty ;
if ( $quantityToBeDelivered < 0 )
{
$quantityToBeDelivered = 0 ;
}
$subj ++ ;
2016-02-10 23:37:34 +01:00
print '</td></tr>' ;
2015-12-18 18:00:31 +01:00
}
}
else
2015-08-14 20:37:20 +02:00
{
2017-02-16 01:39:16 +01:00
print '<!-- Case there is no details of lot at all -->' ;
2017-04-14 13:02:29 +02:00
print '<tr class="oddeven"><td colspan="3"></td><td align="center">' ;
2015-12-18 18:00:31 +01:00
print '<input name="qtyl' . $indiceAsked . '_' . $subj . '" id="qtyl' . $indiceAsked . '_' . $subj . '" type="text" size="4" value="0" disabled="disabled"> ' ;
2015-08-14 20:37:20 +02:00
print '</td>' ;
2017-06-07 16:44:04 +02:00
2015-08-14 20:37:20 +02:00
print '<td align="left">' ;
2015-12-18 18:00:31 +01:00
print img_warning () . ' ' . $langs -> trans ( " NoProductToShipFoundIntoStock " , $staticwarehouse -> libelle );
2016-02-10 23:37:34 +01:00
print '</td></tr>' ;
2015-12-18 18:00:31 +01:00
}
}
}
2017-06-07 16:44:04 +02:00
else
2015-12-18 18:00:31 +01:00
{
// ship from multiple locations
if ( empty ( $conf -> productbatch -> enabled ) || ! $product -> hasbatch ())
{
2016-04-01 10:57:18 +02:00
print '<!-- Case warehouse not already known and product does not need lot -->' ;
2017-06-27 16:41:57 +02:00
print '<td></td><td></td></tr>' . " \n " ; // end line and start a new one for each warehouse
2017-06-07 16:44:04 +02:00
2015-12-18 18:00:31 +01:00
print '<input name="idl' . $indiceAsked . '" type="hidden" value="' . $line -> id . '">' ;
$subj = 0 ;
2017-02-16 01:39:16 +01:00
// Define nb of lines suggested for this order line
$nbofsuggested = 0 ;
foreach ( $product -> stock_warehouse as $warehouse_id => $stock_warehouse )
{
2017-06-07 16:44:04 +02:00
if ( $stock_warehouse -> real > 0 )
2017-02-16 01:39:16 +01:00
{
$nbofsuggested ++ ;
}
}
2017-04-18 17:04:56 +02:00
$tmpwarehouseObject = new Entrepot ( $db );
2016-04-01 10:57:18 +02:00
foreach ( $product -> stock_warehouse as $warehouse_id => $stock_warehouse ) // $stock_warehouse is product_stock
2016-02-10 23:37:34 +01:00
{
2017-04-18 17:04:56 +02:00
$tmpwarehouseObject -> fetch ( $warehouse_id );
2017-06-07 16:44:04 +02:00
if ( $stock_warehouse -> real > 0 )
2016-02-10 23:37:34 +01:00
{
2015-12-18 18:00:31 +01:00
$stock = + $stock_warehouse -> real ; // Convert it to number
$deliverableQty = min ( $quantityToBeDelivered , $stock );
2016-02-20 04:25:39 +01:00
$deliverableQty = max ( 0 , $deliverableQty );
2015-12-18 18:00:31 +01:00
// Quantity to send
2017-02-16 01:39:16 +01:00
print '<!-- subj=' . $subj . '/' . $nbofsuggested . ' --><tr ' . ((( $subj + 1 ) == $nbofsuggested ) ? $bc [ $var ] : '' ) . '>' ;
print '<td colspan="3" ></td><td align="center"><!-- qty to ship (no lot management for product line indiceAsked=' . $indiceAsked . ') -->' ;
2017-12-01 13:40:24 +01:00
if ( $line -> product_type == Product :: TYPE_PRODUCT || ! empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES ))
2015-12-18 18:00:31 +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 . '">' ;
}
else print $langs -> trans ( " NA " );
print '</td>' ;
2017-06-07 16:44:04 +02:00
2015-12-18 18:00:31 +01:00
// Stock
if ( ! empty ( $conf -> stock -> enabled ))
{
print '<td align="left">' ;
2017-12-01 13:40:24 +01:00
if ( $line -> product_type == Product :: TYPE_PRODUCT || ! empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES ))
2015-12-18 18:00:31 +01:00
{
2017-04-18 17:04:56 +02:00
print $tmpwarehouseObject -> getNomUrl ( 0 ) . ' ' ;
2017-06-07 16:44:04 +02:00
2015-12-18 18:00:31 +01:00
print '<!-- Show details of stock -->' ;
2016-02-20 04:25:39 +01:00
print '(' . $stock . ')' ;
2015-12-18 18:00:31 +01:00
}
else
{
print $langs -> trans ( " Service " );
}
print '</td>' ;
}
$quantityToBeDelivered -= $deliverableQty ;
if ( $quantityToBeDelivered < 0 )
{
$quantityToBeDelivered = 0 ;
}
$subj ++ ;
print " </tr> \n " ;
}
}
2016-04-01 10:57:18 +02:00
// Show subproducts of product (not recommanded)
2015-12-18 18:00:31 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_SOUSPRODUITS ) && $line -> fk_product > 0 )
{
$product -> get_sousproduits_arbo ();
$prods_arbo = $product -> get_arbo_each_prod ( $qtyProdCom );
2016-02-10 23:37:34 +01:00
if ( count ( $prods_arbo ) > 0 )
2015-12-18 18:00:31 +01:00
{
foreach ( $prods_arbo as $key => $value )
{
//print $value[0];
$img = '' ;
if ( $value [ 'stock' ] < $value [ 'stock_alert' ])
{
$img = img_warning ( $langs -> trans ( " StockTooLow " ));
}
2017-04-18 17:04:56 +02:00
print '<tr class"oddeven"><td>' ;
2016-02-10 23:37:34 +01:00
print " ->
2015-12-18 18:00:31 +01:00
< a href = \ " " . DOL_URL_ROOT . " /product/card.php?id= " . $value [ 'id' ] . " \" > " . $value [ 'fullpath' ] . "
</ a > ( " . $value['nb'] . " ) </ td >< td align = \ " center \" > " . $value [ 'nb_total' ] . " </td><td> </td><td> </td>
2016-02-10 23:37:34 +01:00
< td align = \ " center \" > " . $value [ 'stock' ] . " " . $img . " </td> " ;
print " </tr> " ;
2015-12-18 18:00:31 +01:00
}
2015-08-14 20:37:20 +02:00
}
2014-03-07 11:35:16 +01:00
}
2015-08-14 20:37:20 +02:00
}
else
2015-12-18 18:00:31 +01:00
{
2017-06-27 16:41:57 +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
2016-02-10 23:37:34 +01:00
2015-12-18 18:00:31 +01:00
$subj = 0 ;
print '<input name="idl' . $indiceAsked . '" type="hidden" value="' . $line -> id . '">' ;
2017-06-07 16:44:04 +02:00
2017-04-18 17:04:56 +02:00
$tmpwarehouseObject = new Entrepot ( $db );
2016-11-14 13:40:41 +01:00
$productlotObject = new Productlot ( $db );
2017-02-16 01:39:16 +01:00
// Define nb of lines suggested for this order line
$nbofsuggested = 0 ;
foreach ( $product -> stock_warehouse as $warehouse_id => $stock_warehouse )
{
if (( $stock_warehouse -> real > 0 ) && ( count ( $stock_warehouse -> detail_batch ))) {
foreach ( $stock_warehouse -> detail_batch as $dbatch )
{
$nbofsuggested ++ ;
}
}
}
2017-06-07 16:44:04 +02:00
foreach ( $product -> stock_warehouse as $warehouse_id => $stock_warehouse )
2016-02-10 23:37:34 +01:00
{
2017-04-18 17:04:56 +02:00
$tmpwarehouseObject -> fetch ( $warehouse_id );
2015-12-18 18:00:31 +01:00
if (( $stock_warehouse -> real > 0 ) && ( count ( $stock_warehouse -> detail_batch ))) {
2017-02-16 01:39:16 +01:00
foreach ( $stock_warehouse -> detail_batch as $dbatch )
2015-12-18 18:00:31 +01:00
{
//var_dump($dbatch);
$batchStock = + $dbatch -> qty ; // To get a numeric
$deliverableQty = min ( $quantityToBeDelivered , $batchStock );
2017-06-27 16:41:57 +02:00
if ( $deliverableQty < 0 ) $deliverableQty = 0 ;
2017-02-16 01:39:16 +01:00
print '<!-- subj=' . $subj . '/' . $nbofsuggested . ' --><tr ' . ((( $subj + 1 ) == $nbofsuggested ) ? $bc [ $var ] : '' ) . '><td colspan="3"></td><td align="center">' ;
2015-12-18 18:00:31 +01:00
print '<input name="qtyl' . $indiceAsked . '_' . $subj . '" id="qtyl' . $indiceAsked . '_' . $subj . '" type="text" size="4" value="' . $deliverableQty . '">' ;
print '</td>' ;
2017-06-07 16:44:04 +02:00
2015-12-18 18:00:31 +01:00
print '<td align="left">' ;
2017-06-07 16:44:04 +02:00
2017-04-18 17:04:56 +02:00
print $tmpwarehouseObject -> getNomUrl ( 0 ) . ' / ' ;
2017-06-07 16:44:04 +02:00
2015-12-18 18:00:31 +01:00
print '<!-- Show details of lot -->' ;
print '<input name="batchl' . $indiceAsked . '_' . $subj . '" type="hidden" value="' . $dbatch -> id . '">' ;
2017-10-28 22:08:16 +02:00
2018-10-09 21:21:10 +02:00
//print '|'.$line->fk_product.'|'.$dbatch->batch.'|<br>';
2017-06-27 16:41:57 +02:00
print $langs -> trans ( " Batch " ) . ': ' ;
$result = $productlotObject -> fetch ( 0 , $line -> fk_product , $dbatch -> batch );
if ( $result > 0 ) print $productlotObject -> getNomUrl ( 1 );
2018-10-09 21:21:10 +02:00
else print 'TableLotIncompleteRunRepairWithParamStandardEqualConfirmed' ;
2016-11-14 13:40:41 +01:00
print ' (' . $dbatch -> qty . ')' ;
2015-12-18 18:00:31 +01:00
$quantityToBeDelivered -= $deliverableQty ;
if ( $quantityToBeDelivered < 0 )
{
$quantityToBeDelivered = 0 ;
}
//dol_syslog('deliverableQty = '.$deliverableQty.' batchStock = '.$batchStock);
$subj ++ ;
2016-02-10 23:37:34 +01:00
print '</td></tr>' ;
2015-12-18 18:00:31 +01:00
}
}
}
}
2016-02-24 13:19:25 +01:00
if ( $subj == 0 ) // Line not shown yet, we show it
2015-08-14 20:37:20 +02:00
{
2016-04-01 10:57:18 +02:00
print '<!-- line not shown yet, we show it -->' ;
2017-04-14 13:02:29 +02:00
print '<tr class="oddeven"><td colspan="3" ></td><td align="center">' ;
2017-12-01 13:40:24 +01:00
if ( $line -> product_type == Product :: TYPE_PRODUCT || ! empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES ))
2016-02-10 23:37:34 +01:00
{
2017-02-16 01:39:16 +01:00
$disabled = '' ;
if ( ! empty ( $conf -> productbatch -> enabled ) && $product -> hasbatch ())
{
$disabled = 'disabled="disabled"' ;
}
2016-02-10 23:37:34 +01:00
print '<input name="qtyl' . $indiceAsked . '_' . $subj . '" id="qtyl' . $indiceAsked . '_' . $subj . '" type="text" size="4" value="0"' . ( $disabled ? ' ' . $disabled : '' ) . '> ' ;
}
else
{
print $langs -> trans ( " NA " );
}
2015-08-15 11:21:50 +02:00
print '</td>' ;
2017-06-07 16:44:04 +02:00
2015-08-15 11:21:50 +02:00
print '<td align="left">' ;
2017-12-01 13:40:24 +01:00
if ( $line -> product_type == Product :: TYPE_PRODUCT || ! empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES ))
2015-12-18 18:00:31 +01:00
{
2017-06-07 16:44:04 +02:00
$warehouse_selected_id = GETPOST ( 'entrepot_id' , 'int' );
if ( $warehouse_selected_id > 0 )
2016-02-10 23:37:34 +01:00
{
2017-04-18 17:04:56 +02:00
$warehouseObject = new Entrepot ( $db );
$warehouseObject -> fetch ( $warehouse_selected_id );
2016-02-10 23:37:34 +01:00
print img_warning () . ' ' . $langs -> trans ( " NoProductToShipFoundIntoStock " , $warehouseObject -> libelle );
}
else
{
if ( $line -> fk_product ) print img_warning () . ' ' . $langs -> trans ( " StockTooLow " );
else print '' ;
}
2015-12-18 18:00:31 +01:00
}
else
{
2016-02-10 23:37:34 +01:00
print $langs -> trans ( " Service " );
2015-12-18 18:00:31 +01:00
}
2016-02-10 23:37:34 +01:00
print '</td>' ;
print '</tr>' ;
2014-03-07 11:35:16 +01:00
}
}
2017-06-07 16:44:04 +02:00
2015-12-16 16:18:29 +01:00
//Display lines extrafields
2017-06-07 16:44:04 +02:00
if ( is_array ( $extralabelslines ) && count ( $extralabelslines ) > 0 )
2016-04-01 10:57:18 +02:00
{
2015-12-16 16:18:29 +01:00
$colspan = 5 ;
2017-09-19 18:43:00 +02:00
$orderLineExtrafields = new Extrafields ( $db );
$orderLineExtrafieldLabels = $orderLineExtrafields -> fetch_name_optionals_label ( $object -> table_element_line );
$srcLine = new OrderLine ( $db );
2018-02-21 14:48:25 +01:00
$srcLine -> fetch_optionals ( $line -> id ); // fetch extrafields also available in orderline
2015-12-16 16:18:29 +01:00
$line = new ExpeditionLigne ( $db );
2018-10-02 09:37:44 +02:00
//$line->fetch_optionals($line->id);
2017-09-19 18:43:00 +02:00
$line -> array_options = array_merge ( $line -> array_options , $srcLine -> array_options );
2017-09-19 18:52:27 +02:00
print '<tr class="oddeven">' ;
2015-12-16 16:18:29 +01:00
print $line -> showOptionals ( $extrafieldsline , 'edit' , array ( 'style' => $bc [ $var ], 'colspan' => $colspan ), $indiceAsked );
print '</tr>' ;
}
2012-03-14 14:48:27 +01:00
$indiceAsked ++ ;
}
print " </table> " ;
2013-08-07 15:08:30 +02:00
2017-11-02 12:38:36 +01:00
print '<br>' ;
print '<div class="center">' ;
2017-11-02 12:48:40 +01:00
print '<input type="submit" class="button" name="add" value="' . dol_escape_htmltag ( $langs -> trans ( " Create " )) . '">' ;
print ' ' ;
print '<input type="' . ( $backtopage ? " submit " : " button " ) . '" class="button" 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
2017-11-02 12:38:36 +01:00
print '</div>' ;
2013-08-07 15:08:30 +02:00
2013-04-21 14:14:30 +02:00
print '</form>' ;
2013-08-07 15:08:30 +02:00
2013-04-14 12:19:21 +02:00
print '<br>' ;
2012-03-14 14:48:27 +01:00
}
else
2015-02-16 19:14:34 +01:00
{
2012-03-14 14:48:27 +01:00
dol_print_error ( $db );
}
}
2006-07-14 13:31:57 +02:00
}
2013-10-10 15:49:41 +02:00
else if ( $id || $ref )
2003-11-13 18:36:45 +01:00
/* *************************************************************************** */
/* */
2008-09-01 15:22:36 +02:00
/* Edit and view mode */
2003-11-13 18:36:45 +01:00
/* */
/* *************************************************************************** */
2006-11-11 01:46:15 +01:00
{
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
2013-08-07 15:08:30 +02:00
if ( $object -> id > 0 )
{
2016-10-29 14:52:13 +02:00
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 ;
$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
$head = shipping_prepare_head ( $object );
2017-06-27 16:41:57 +02:00
dol_fiche_head ( $head , 'shipping' , $langs -> trans ( " Shipment " ), - 1 , 'sending' );
2013-08-07 15:08:30 +02:00
2016-09-19 13:57:50 +02:00
$formconfirm = '' ;
2017-06-07 16:44:04 +02:00
2016-10-29 14:52:13 +02:00
// Confirm deleteion
2013-08-07 15:08:30 +02:00
if ( $action == 'delete' )
{
2016-09-19 13:57:50 +02:00
$formconfirm = $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $langs -> trans ( 'DeleteSending' ), $langs -> trans ( " ConfirmDeleteSending " , $object -> ref ), 'confirm_delete' , '' , 0 , 1 );
2013-08-07 15:08:30 +02:00
}
2016-10-29 14:52:13 +02:00
// Confirmation validation
2013-08-07 15:08:30 +02:00
if ( $action == 'valid' )
{
$objectref = substr ( $object -> ref , 1 , 4 );
if ( $objectref == 'PROV' )
2012-11-18 16:21:38 +01:00
{
2013-08-07 15:08:30 +02:00
$numref = $object -> getNextNumRef ( $soc );
}
else
{
$numref = $object -> ref ;
}
2012-03-14 14:48:27 +01:00
2013-08-07 15:08:30 +02:00
$text = $langs -> trans ( " ConfirmValidateSending " , $numref );
2012-03-14 14:48:27 +01:00
2013-08-07 15:08:30 +02:00
if ( ! empty ( $conf -> notification -> enabled ))
{
require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php' ;
$notify = new Notify ( $db );
$text .= '<br>' ;
2015-03-18 21:44:57 +01:00
$text .= $notify -> confirmMessage ( 'SHIPPING_VALIDATE' , $object -> socid , $object );
2013-08-07 15:08:30 +02:00
}
2016-09-19 13:57:50 +02: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
2013-08-07 15:08:30 +02:00
if ( $action == 'annuler' )
{
2016-09-19 13:57:50 +02: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
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'formConfirm' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
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.
2016-02-25 13:46:38 +01:00
$tmparray = $object -> getTotalWeightVolume ();
$totalWeight = $tmparray [ 'weight' ];
$totalVolume = $tmparray [ 'volume' ];
2017-06-07 16:44:04 +02:00
2016-10-29 14:52:13 +02:00
if ( $typeobject == 'commande' && $object -> $typeobject -> id && ! empty ( $conf -> commande -> enabled ))
{
$objectsrc = new Commande ( $db );
$objectsrc -> fetch ( $object -> $typeobject -> id );
}
if ( $typeobject == 'propal' && $object -> $typeobject -> id && ! empty ( $conf -> propal -> enabled ))
{
$objectsrc = new Propal ( $db );
$objectsrc -> fetch ( $object -> $typeobject -> id );
}
2016-10-30 16:34:46 +01:00
2016-10-24 20:52:21 +02:00
// Shipment card
2017-10-03 16:00:52 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/expedition/list.php?restore_lastsearch_values=1' . ( ! empty ( $socid ) ? '&socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2016-09-19 13:57:50 +02:00
$morehtmlref = '<div class="refidno">' ;
// Ref customer shipment
2016-10-29 14:52:13 +02: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
$morehtmlref .= '<br>' . $langs -> trans ( 'ThirdParty' ) . ' : ' . $object -> thirdparty -> getNomUrl ( 1 );
// Project
if ( ! empty ( $conf -> projet -> enabled )) {
$langs -> load ( " projects " );
$morehtmlref .= '<br>' . $langs -> trans ( 'Project' ) . ' ' ;
2016-10-29 14:52:13 +02:00
if ( 0 ) { // Do not change on shipment
2016-09-19 13:57:50 +02:00
if ( $action != 'classify' ) {
$morehtmlref .= '<a 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="' . $_SESSION [ '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 {
2016-10-29 16:18:39 +02:00
// We don't have project on shipment, so we will use the project or source object instead
// TODO Add project on shipment
2016-10-29 14:52:13 +02:00
$morehtmlref .= ' : ' ;
if ( ! empty ( $objectsrc -> fk_project )) {
2016-09-19 13:57:50 +02:00
$proj = new Project ( $db );
2016-10-29 14:52:13 +02:00
$proj -> fetch ( $objectsrc -> fk_project );
$morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $objectsrc -> fk_project . '" title="' . $langs -> trans ( 'ShowProject' ) . '">' ;
2016-09-19 13:57:50 +02:00
$morehtmlref .= $proj -> ref ;
$morehtmlref .= '</a>' ;
} else {
$morehtmlref .= '' ;
}
}
2016-10-29 14:52:13 +02:00
}
2016-09-19 13:57:50 +02:00
$morehtmlref .= '</div>' ;
2017-06-07 16:44:04 +02:00
2016-10-29 14:52:13 +02:00
2016-09-19 13:57:50 +02:00
dol_banner_tab ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' , $morehtmlref );
2017-06-07 16:44:04 +02:00
2016-09-19 13:57:50 +02:00
print '<div class="fichecenter">' ;
print '<div class="fichehalfleft">' ;
print '<div class="underbanner clearboth"></div>' ;
2017-06-07 16:44:04 +02:00
2017-03-02 01:26:15 +01:00
print '<table class="border" width="100%">' ;
2013-08-07 15:08:30 +02:00
// Linked documents
if ( $typeobject == 'commande' && $object -> $typeobject -> id && ! empty ( $conf -> commande -> enabled ))
{
print '<tr><td>' ;
print $langs -> trans ( " RefOrder " ) . '</td>' ;
print '<td colspan="3">' ;
print $objectsrc -> getNomUrl ( 1 , 'commande' );
print " </td> \n " ;
print '</tr>' ;
}
if ( $typeobject == 'propal' && $object -> $typeobject -> id && ! empty ( $conf -> propal -> enabled ))
{
print '<tr><td>' ;
print $langs -> trans ( " RefProposal " ) . '</td>' ;
print '<td colspan="3">' ;
print $objectsrc -> getNomUrl ( 1 , 'expedition' );
print " </td> \n " ;
print '</tr>' ;
}
// Date creation
2016-09-19 13:57:50 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " DateCreation " ) . '</td>' ;
2016-10-29 16:18:39 +02: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>' ;
if ( $action != 'editdate_livraison' ) print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=editdate_livraison&id=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetDeliveryDate' ), 1 ) . '</a></td>' ;
print '</tr></table>' ;
print '</td><td colspan="2">' ;
if ( $action == 'editdate_livraison' )
{
print '<form name="setdate_livraison" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="post">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="setdate_livraison">' ;
2018-09-09 09:36:12 +02: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>' ;
}
else
{
2014-06-20 12:03:41 +02: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>' ;
2016-03-25 15:53:44 +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
2015-07-13 11:22:18 +02: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">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input id="trueWeight" name="trueWeight" value="' . $object -> trueWeight . '" type="text">' ;
print $formproduct -> select_measuring_units ( " weight_units " , " weight " , $object -> weight_units );
print ' <input class="button" name="modify" value="' . $langs -> trans ( " Modify " ) . '" type="submit">' ;
print ' <input class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '" type="submit">' ;
print '</form>' ;
}
2015-07-13 11:22:18 +02:00
else
{
2014-05-14 17:20:11 +02:00
print $object -> trueWeight ;
print ( $object -> trueWeight && $object -> weight_units != '' ) ? ' ' . measuring_units_string ( $object -> weight_units , " weight " ) : '' ;
2014-06-20 12:03:41 +02:00
}
2014-05-14 17:20:11 +02:00
2016-02-24 13:19:25 +01:00
// Calculated
2013-08-07 15:08:30 +02:00
if ( $totalWeight > 0 )
{
if ( ! empty ( $object -> trueWeight )) print ' (' . $langs -> trans ( " SumOfProductWeights " ) . ': ' ;
2016-02-25 13:46:38 +01:00
//print $totalWeight.' '.measuring_units_string(0,"weight");
2016-04-01 18:44:23 +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' );
2017-06-07 16:44:04 +02:00
//if (empty($object->trueWeight)) print ' ('.$langs->trans("Calculated").')';
2013-08-07 15:08:30 +02:00
if ( ! empty ( $object -> trueWeight )) print ')' ;
}
print '</td></tr>' ;
// Width
2016-03-25 15:53:44 +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 );
2013-08-07 15:08:30 +02:00
print ( $object -> trueWidth && $object -> width_units != '' ) ? ' ' . measuring_units_string ( $object -> width_units , " size " ) : '' ;
print '</td></tr>' ;
// Height
2016-03-25 15:53:44 +01:00
print '<tr><td>' . $form -> editfieldkey ( " Height " , 'trueHeight' , $object -> trueHeight , $object , $user -> rights -> expedition -> creer ) . '</td><td colspan="3">' ;
2015-07-13 11:22:18 +02: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">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input id="trueHeight" name="trueHeight" value="' . $object -> trueHeight . '" type="text">' ;
print $formproduct -> select_measuring_units ( " size_units " , " size " , $object -> size_units );
print ' <input class="button" name="modify" value="' . $langs -> trans ( " Modify " ) . '" type="submit">' ;
print ' <input class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '" type="submit">' ;
print '</form>' ;
}
2015-07-13 11:22:18 +02:00
else
{
2014-05-14 17:20:11 +02:00
print $object -> trueHeight ;
print ( $object -> trueHeight && $object -> height_units != '' ) ? ' ' . measuring_units_string ( $object -> height_units , " size " ) : '' ;
}
2014-06-20 12:03:41 +02:00
2013-08-07 15:08:30 +02:00
print '</td></tr>' ;
// Depth
2016-03-25 15:53:44 +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 );
2013-08-07 15:08:30 +02:00
print ( $object -> trueDepth && $object -> depth_units != '' ) ? ' ' . measuring_units_string ( $object -> depth_units , " size " ) : '' ;
print '</td></tr>' ;
// Volume
print '<tr><td>' ;
print $langs -> trans ( " Volume " );
print '</td>' ;
print '<td colspan="3">' ;
$calculatedVolume = 0 ;
2016-02-25 13:46:38 +01:00
$volumeUnit = 0 ;
2017-06-07 16:44:04 +02:00
if ( $object -> trueWidth && $object -> trueHeight && $object -> trueDepth )
2016-02-25 13:46:38 +01:00
{
$calculatedVolume = ( $object -> trueWidth * $object -> trueHeight * $object -> trueDepth );
$volumeUnit = $object -> size_units * 3 ;
}
2013-08-07 15:08:30 +02:00
// If sending volume not defined we use sum of products
if ( $calculatedVolume > 0 )
{
2017-06-07 16:44:04 +02:00
if ( $volumeUnit < 50 )
2016-02-25 13:46:38 +01:00
{
//print $calculatedVolume.' '.measuring_units_string($volumeUnit,"volume");
2016-04-01 18:44:23 +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' );
2016-02-25 13:46:38 +01:00
}
else print $calculatedVolume . ' ' . measuring_units_string ( $volumeUnit , " volume " );
2013-08-07 15:08:30 +02:00
}
if ( $totalVolume > 0 )
{
if ( $calculatedVolume ) print ' (' . $langs -> trans ( " SumOfProductVolumes " ) . ': ' ;
2016-02-25 13:46:38 +01:00
//print $totalVolume.' '.measuring_units_string(0,"volume");
2016-04-01 18:44:23 +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").')';
2013-08-07 15:08:30 +02:00
if ( $calculatedVolume ) print ')' ;
}
print " </td> \n " ;
print '</tr>' ;
2016-09-19 13:57:50 +02:00
// Other attributes
$cols = 2 ;
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
2016-09-19 13:57:50 +02:00
print '<table class="border centpercent">' ;
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>' ;
if ( $action != 'editshipping_method_id' ) print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=editshipping_method_id&id=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetSendingMethod' ), 1 ) . '</a></td>' ;
print '</tr></table>' ;
print '</td><td colspan="2">' ;
if ( $action == 'editshipping_method_id' )
{
print '<form name="setshipping_method_id" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="post">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="setshipping_method_id">' ;
$object -> fetch_delivery_methods ();
2016-03-25 15:34:37 +01:00
print $form -> selectarray ( " shipping_method_id " , $object -> meths , $object -> shipping_method_id , 1 , 0 , 0 , " " , 1 );
2014-09-04 18:41:28 +02: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>' ;
}
else
{
if ( $object -> shipping_method_id > 0 )
{
// Get code using getLabelFromKey
$code = $langs -> getLabelFromKey ( $db , $object -> shipping_method_id , 'c_shipment_mode' , 'rowid' , 'code' );
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
2017-12-20 12:45:38 +01:00
print '<tr><td class="titlefield">' . $form -> editfieldkey ( " TrackingNumber " , 'tracking_number' , $object -> tracking_number , $object , $user -> rights -> expedition -> creer ) . '</td><td colspan="3">' ;
print $form -> editfieldval ( " TrackingNumber " , 'tracking_number' , $object -> tracking_url , $object , $user -> rights -> expedition -> creer , 'string' , $object -> tracking_number );
2013-08-07 15:08:30 +02:00
print '</td></tr>' ;
2015-02-23 09:16:14 +01:00
// Incoterms
if ( ! empty ( $conf -> incoterm -> enabled ))
2015-03-18 21:44:57 +01:00
{
2015-02-23 09:16:14 +01:00
print '<tr><td>' ;
print '<table width="100%" class="nobordernopadding"><tr><td>' ;
print $langs -> trans ( 'IncotermLabel' );
print '<td><td align="right">' ;
if ( $user -> rights -> expedition -> creer ) print '<a href="' . DOL_URL_ROOT . '/expedition/card.php?id=' . $object -> id . '&action=editincoterm">' . img_edit () . '</a>' ;
else print ' ' ;
print '</td></tr></table>' ;
print '</td>' ;
print '<td colspan="3">' ;
if ( $action != 'editincoterm' )
{
2016-03-25 15:24:57 +01:00
print $form -> textwithpicto ( $object -> display_incoterms (), $object -> libelle_incoterms , 1 );
2015-02-23 09:16:14 +01:00
}
2015-03-18 21:44:57 +01:00
else
2015-02-23 09:16:14 +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 );
}
print '</td></tr>' ;
}
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
2017-10-23 22:18:15 +02:00
if ( $action == 'editline' )
{
print ' <form name="updateline" id="updateline" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&lineid=' . $line_id . ' " method= " POST " >
< input type = " hidden " name = " token " value = " ' . $_SESSION ['newtoken'] . ' " >
< input type = " hidden " name = " action " value = " updateline " >
< input type = " hidden " name = " mode " value = " " >
< input type = " hidden " name = " id " value = " ' . $object->id . ' " >
' ;
}
2017-03-02 01:26:15 +01:00
print '<br>' ;
2017-06-07 16:44:04 +02:00
2017-03-02 01:26:15 +01:00
print '<div class="div-table-responsive-no-min">' ;
print '<table class="noborder" width="100%">' ;
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
2013-08-07 15:08:30 +02:00
if ( ! empty ( $conf -> global -> MAIN_VIEW_LINE_NUMBER ))
{
print '<td width="5" align="center"> </td>' ;
}
2017-12-01 14:33:06 +01:00
// Product/Service
2013-08-07 15:08:30 +02:00
print '<td>' . $langs -> trans ( " Products " ) . '</td>' ;
2017-12-01 14:33:06 +01:00
// Qty
2013-08-07 15:08:30 +02:00
print '<td align="center">' . $langs -> trans ( " QtyOrdered " ) . '</td>' ;
2017-10-23 22:18:15 +02:00
if ( $origin && $origin_id > 0 )
2013-08-07 15:08:30 +02:00
{
2017-10-23 22:18:15 +02:00
print '<td align="center">' . $langs -> trans ( " QtyInOtherShipments " ) . '</td>' ;
2013-08-07 15:08:30 +02:00
}
2017-10-23 22:18:15 +02:00
if ( $action == 'editline' )
2013-08-07 15:08:30 +02:00
{
2017-10-23 22:18:15 +02:00
$editColspan = 3 ;
if ( empty ( $conf -> stock -> enabled )) $editColspan -- ;
if ( empty ( $conf -> productbatch -> enabled )) $editColspan -- ;
print '<td align="center" colspan="' . $editColspan . '">' ;
if ( $object -> statut <= 1 )
{
print $langs -> trans ( " QtyToShip " ) . ' - ' ;
}
else
{
print $langs -> trans ( " QtyShipped " ) . ' - ' ;
}
if ( ! empty ( $conf -> stock -> enabled ))
{
print $langs -> trans ( " WarehouseSource " ) . ' - ' ;
}
if ( ! empty ( $conf -> productbatch -> enabled ))
{
print $langs -> trans ( " Batch " );
}
print '</td>' ;
2013-08-07 15:08:30 +02:00
}
2017-11-02 12:38:36 +01:00
else
2016-10-29 14:52:13 +02:00
{
2017-10-23 22:18:15 +02:00
if ( $object -> statut <= 1 )
{
print '<td align="center">' . $langs -> trans ( " QtyToShip " ) . '</td>' ;
}
else
{
print '<td align="center">' . $langs -> trans ( " QtyShipped " ) . '</td>' ;
}
if ( ! empty ( $conf -> stock -> enabled ))
{
print '<td align="left">' . $langs -> trans ( " WarehouseSource " ) . '</td>' ;
}
2017-11-02 12:38:36 +01:00
2017-10-23 22:18:15 +02:00
if ( ! empty ( $conf -> productbatch -> enabled ))
{
print '<td align="left">' . $langs -> trans ( " Batch " ) . '</td>' ;
}
2016-10-29 14:52:13 +02:00
}
2013-08-07 15:08:30 +02:00
print '<td align="center">' . $langs -> trans ( " CalculatedWeight " ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " CalculatedVolume " ) . '</td>' ;
//print '<td align="center">'.$langs->trans("Size").'</td>';
2017-10-23 22:18:15 +02:00
if ( $object -> statut == 0 )
2013-08-07 15:08:30 +02:00
{
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 " ;
$var = false ;
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && ! empty ( $conf -> global -> PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE ))
{
$object -> fetch_thirdparty ();
$outputlangs = $langs ;
$newlang = '' ;
2017-06-27 17:27:01 +02:00
if ( empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) $newlang = GETPOST ( 'lang_id' , 'aZ09' );
2016-04-17 15:24:22 +02:00
if ( empty ( $newlang )) $newlang = $object -> thirdparty -> default_lang ;
2013-08-07 15:08:30 +02:00
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( " " , $conf );
$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 ();
if ( $origin && $origin_id > 0 )
{
$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 " ;
2017-03-17 16:10:40 +01:00
$sql .= " , e.rowid as shipment_id, e.ref as shipment_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_expedition " ;
//if ($conf->livraison_bon->enabled) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received";
$sql .= ', p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch' ;
$sql .= ', p.description as product_desc' ;
2016-10-29 14:52:13 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " expeditiondet as ed " ;
$sql .= " , " . MAIN_DB_PREFIX . " expedition as e " ;
$sql .= " , " . MAIN_DB_PREFIX . $origin . " det as obj " ;
//if ($conf->livraison_bon->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_expedition = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."livraisondet as ld ON ld.fk_livraison = l.rowid AND obj.rowid = ld.fk_origin_line";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product as p ON obj.fk_product = p.rowid " ;
2017-05-30 18:50:54 +02:00
$sql .= " WHERE e.entity IN ( " . getEntity ( 'expedition' ) . " ) " ;
2016-10-29 14:52:13 +02:00
$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 " ;
2016-11-14 14:34:15 +01:00
dol_syslog ( " get list of shipment lines " , LOG_DEBUG );
2016-10-29 14:52:13 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
2017-06-07 16:44:04 +02:00
2016-10-29 14:52:13 +02:00
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
if ( $obj )
{
// $obj->rowid is rowid in $origin."det" table
$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 , 'date_valid' => $obj -> date_valid , 'date_delivery' => $obj -> date_delivery );
}
$i ++ ;
}
}
//var_dump($alreadysent);
}
// Loop on each product to send/sent
2013-08-07 15:08:30 +02:00
for ( $i = 0 ; $i < $num_prod ; $i ++ )
{
2017-06-27 16:41:57 +02:00
print '<!-- origin line id = ' . $lines [ $i ] -> origin_line_id . ' -->' ; // id of order line
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2012-03-14 14:48:27 +01:00
2018-09-25 17:26:57 +02:00
// Adds a line numbering column
2013-08-07 15:08:30 +02:00
if ( ! empty ( $conf -> global -> MAIN_VIEW_LINE_NUMBER ))
{
print '<td align="center">' . ( $i + 1 ) . '</td>' ;
}
2012-03-14 14:48:27 +01:00
2013-08-07 15:08:30 +02:00
// Predefined product or service
if ( $lines [ $i ] -> fk_product > 0 )
{
// Define output language
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && ! empty ( $conf -> global -> PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE ))
{
$prod = new Product ( $db );
$prod -> fetch ( $lines [ $i ] -> fk_product );
$label = ( ! empty ( $prod -> multilangs [ $outputlangs -> defaultlang ][ " label " ])) ? $prod -> multilangs [ $outputlangs -> defaultlang ][ " label " ] : $lines [ $i ] -> product_label ;
}
else
$label = ( ! empty ( $lines [ $i ] -> label ) ? $lines [ $i ] -> label : $lines [ $i ] -> product_label );
print '<td>' ;
// Show product and description
$product_static -> type = $lines [ $i ] -> fk_product_type ;
$product_static -> id = $lines [ $i ] -> fk_product ;
$product_static -> ref = $lines [ $i ] -> ref ;
2016-11-14 13:40:41 +01:00
$product_static -> status_batch = $lines [ $i ] -> product_tobatch ;
2013-08-07 15:08:30 +02:00
$text = $product_static -> getNomUrl ( 1 );
$text .= ' - ' . $label ;
$description = ( ! empty ( $conf -> global -> PRODUIT_DESC_IN_FORM ) ? '' : dol_htmlentitiesbr ( $lines [ $i ] -> description ));
2016-03-25 15:24:57 +01:00
print $form -> textwithtooltip ( $text , $description , 3 , '' , '' , $i );
2013-08-07 15:08:30 +02:00
print_date_range ( $lines [ $i ] -> date_start , $lines [ $i ] -> date_end );
if ( ! empty ( $conf -> global -> PRODUIT_DESC_IN_FORM ))
{
print ( ! empty ( $lines [ $i ] -> description ) && $lines [ $i ] -> description != $lines [ $i ] -> product ) ? '<br>' . dol_htmlentitiesbr ( $lines [ $i ] -> description ) : '' ;
}
2016-02-10 23:37:34 +01:00
print " </td> \n " ;
2013-08-07 15:08:30 +02:00
}
else
{
print " <td> " ;
2017-12-01 14:33:06 +01:00
if ( $lines [ $i ] -> product_type == Product :: TYPE_SERVICE ) $text = img_object ( $langs -> trans ( 'Service' ), 'service' );
2013-08-07 15:08:30 +02:00
else $text = img_object ( $langs -> trans ( 'Product' ), 'product' );
if ( ! empty ( $lines [ $i ] -> label )) {
$text .= ' <strong>' . $lines [ $i ] -> label . '</strong>' ;
2016-03-25 15:24:57 +01:00
print $form -> textwithtooltip ( $text , $lines [ $i ] -> description , 3 , '' , '' , $i );
2013-08-07 15:08:30 +02:00
} else {
print $text . ' ' . nl2br ( $lines [ $i ] -> description );
}
print_date_range ( $lines [ $i ] -> date_start , $lines [ $i ] -> date_end );
print " </td> \n " ;
}
2016-10-29 14:52:13 +02:00
// Qty ordered
2013-08-07 15:08:30 +02:00
print '<td align="center">' . $lines [ $i ] -> qty_asked . '</td>' ;
2016-10-29 14:52:13 +02:00
// Qty in other shipments (with shipment and warehouse used)
if ( $origin && $origin_id > 0 )
{
print '<td align="center" class="nowrap">' ;
foreach ( $alreadysent as $key => $val )
{
if ( $lines [ $i ] -> fk_origin_line == $key )
{
$j = 0 ;
foreach ( $val as $shipmentline_id => $shipmentline_var )
{
2017-06-27 16:41:57 +02:00
if ( $shipmentline_var [ 'shipment_id' ] == $lines [ $i ] -> fk_expedition ) continue ; // We want to show only "other shipments"
2016-10-29 14:52:13 +02:00
$j ++ ;
if ( $j > 1 ) print '<br>' ;
$shipment_static -> fetch ( $shipmentline_var [ 'shipment_id' ]);
print $shipment_static -> getNomUrl ( 1 );
print ' - ' . $shipmentline_var [ 'qty_shipped' ];
2017-06-27 16:41:57 +02:00
$htmltext = $langs -> trans ( " DateValidation " ) . ' : ' . ( empty ( $shipmentline_var [ 'date_valid' ]) ? $langs -> trans ( " Draft " ) : dol_print_date ( $shipmentline_var [ 'date_valid' ], 'dayhour' ));
2016-10-29 14:52:13 +02:00
if ( ! empty ( $conf -> stock -> enabled ) && $shipmentline_var [ 'warehouse' ] > 0 )
{
$warehousestatic -> fetch ( $shipmentline_var [ 'warehouse' ]);
$htmltext .= '<br>' . $langs -> trans ( " From " ) . ' : ' . $warehousestatic -> getNomUrl ( 1 );
}
print ' ' . $form -> textwithpicto ( '' , $htmltext , 1 );
}
}
}
2017-06-07 16:44:04 +02:00
}
2016-10-29 14:52:13 +02:00
print '</td>' ;
2017-10-23 22:18:15 +02:00
if ( $action == 'editline' && $lines [ $i ] -> id == $line_id )
2013-08-07 15:08:30 +02:00
{
2017-10-23 22:18:15 +02:00
// edit mode
2017-12-01 14:33:06 +01:00
print '<td colspan="' . $editColspan . '" align="center"><table class="nobordernopadding">' ;
2017-10-23 22:18:15 +02:00
if ( is_array ( $lines [ $i ] -> detail_batch ) && count ( $lines [ $i ] -> detail_batch ) > 0 )
2013-08-07 15:08:30 +02:00
{
2017-12-01 14:33:06 +01:00
print '<!-- case edit 1 -->' ;
2017-10-30 12:39:06 +01:00
$line = new ExpeditionLigne ( $db );
2017-11-02 12:38:36 +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
2018-10-11 11:56:52 +02:00
print '<td>' . '<input 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
2017-10-30 12:39:06 +01:00
if ( $lines [ $i ] -> entrepot_id == 0 )
{
// only show lot numbers from src warehouse when shipping from multiple warehouses
$line -> fetch ( $detail_batch -> fk_expeditiondet );
}
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>' ;
}
2017-11-02 11:44:36 +01:00
// add a 0 qty lot row to be able to add a lot
print '<tr>' ;
// Qty to ship or shipped
print '<td>' . '<input name="qtyl' . $line_id . '_0" id="qtyl' . $line_id . '_0" type="text" size="4" value="0">' . '</td>' ;
// Batch number managment
print '<td>' . $formproduct -> selectLotStock ( '' , 'batchl' . $line_id . '_0' , '' , 1 , 0 , $lines [ $i ] -> fk_product ) . '</td>' ;
print '</tr>' ;
2017-10-29 19:01:42 +01:00
}
2017-10-23 22:18:15 +02:00
else if ( ! empty ( $conf -> stock -> enabled ))
2014-10-03 12:20:02 +02:00
{
2017-12-01 14:33:06 +01:00
if ( $lines [ $i ] -> fk_product > 0 )
2017-10-23 22:18:15 +02:00
{
2017-12-01 14:33:06 +01:00
if ( $lines [ $i ] -> entrepot_id > 0 )
2015-07-13 11:22:18 +02:00
{
2017-12-01 14:33:06 +01:00
print '<!-- case edit 2 -->' ;
2017-10-23 22:18:15 +02:00
print '<tr>' ;
// Qty to ship or shipped
2017-12-01 14:33:06 +01:00
print '<td>' . '<input name="qtyl' . $line_id . '" id="qtyl' . $line_id . '" type="text" size="4" value="' . $lines [ $i ] -> qty_shipped . '">' . '</td>' ;
2017-10-23 22:18:15 +02:00
// Warehouse source
2017-12-01 14:33:06 +01:00
print '<td>' . $formproduct -> selectWarehouses ( $lines [ $i ] -> entrepot_id , 'entl' . $line_id , '' , 1 , 0 , $lines [ $i ] -> fk_product , '' , 1 ) . '</td>' ;
2017-10-23 22:18:15 +02:00
// Batch number managment
print '<td> - ' . $langs -> trans ( " NA " ) . '</td>' ;
print '</tr>' ;
2014-10-03 12:20:02 +02:00
}
2017-12-01 14:33:06 +01:00
else if ( count ( $lines [ $i ] -> details_entrepot ) > 1 )
{
print '<!-- case edit 3 -->' ;
foreach ( $lines [ $i ] -> details_entrepot as $detail_entrepot )
{
print '<tr>' ;
// Qty to ship or shipped
print '<td>' . '<input name="qtyl' . $detail_entrepot -> line_id . '" id="qtyl' . $detail_entrepot -> line_id . '" type="text" size="4" value="' . $detail_entrepot -> qty_shipped . '">' . '</td>' ;
// Warehouse source
print '<td>' . $formproduct -> selectWarehouses ( $detail_entrepot -> entrepot_id , 'entl' . $detail_entrepot -> line_id , '' , 1 , 0 , $lines [ $i ] -> fk_product , '' , 1 ) . '</td>' ;
// Batch number managment
print '<td> - ' . $langs -> trans ( " NA " ) . '</td>' ;
print '</tr>' ;
}
}
else
{
print '<!-- case edit 4 -->' ;
print '<tr><td colspan="3">' . $langs -> trans ( " NotEnoughStock " ) . '</td></tr>' ;
}
}
else
{
print '<!-- case edit 5 -->' ;
print '<tr>' ;
// Qty to ship or shipped
print '<td>' . '<input name="qtyl' . $line_id . '" id="qtyl' . $line_id . '" type="text" size="4" value="' . $lines [ $i ] -> qty_shipped . '">' . '</td>' ;
// Warehouse source
print '<td>' . '</td>' ;
// Batch number managment
print '<td>' . '</td>' ;
print '</tr>' ;
2014-10-03 12:20:02 +02:00
}
2013-08-07 15:08:30 +02:00
}
2017-10-23 22:18:15 +02:00
print '</table></td>' ;
2013-08-07 15:08:30 +02:00
}
2017-10-23 22:18:15 +02:00
else
2014-12-05 16:01:01 +01:00
{
2017-10-23 22:18:15 +02:00
// Qty to ship or shipped
print '<td align="center">' . $lines [ $i ] -> qty_shipped . '</td>' ;
// Warehouse source
if ( ! empty ( $conf -> stock -> enabled ))
2014-12-05 16:01:01 +01:00
{
2017-10-23 22:18:15 +02:00
print '<td align="left">' ;
if ( $lines [ $i ] -> entrepot_id > 0 )
{
$entrepot = new Entrepot ( $db );
$entrepot -> fetch ( $lines [ $i ] -> entrepot_id );
print $entrepot -> getNomUrl ( 1 );
}
else if ( count ( $lines [ $i ] -> details_entrepot ) > 1 )
2015-08-14 23:53:59 +02:00
{
$detail = '' ;
2017-10-23 22:18:15 +02:00
foreach ( $lines [ $i ] -> details_entrepot as $detail_entrepot )
2015-08-14 23:53:59 +02:00
{
2017-10-23 22:18:15 +02:00
if ( $detail_entrepot -> entrepot_id > 0 )
{
$entrepot = new Entrepot ( $db );
$entrepot -> fetch ( $detail_entrepot -> entrepot_id );
$detail .= $langs -> trans ( " DetailWarehouseFormat " , $entrepot -> libelle , $detail_entrepot -> qty_shipped ) . '<br/>' ;
}
2015-08-14 23:53:59 +02:00
}
2017-10-23 22:18:15 +02:00
print $form -> textwithtooltip ( img_picto ( '' , 'object_stock' ) . ' ' . $langs -> trans ( " DetailWarehouseNumber " ), $detail );
2015-08-14 23:53:59 +02:00
}
2017-10-23 22:18:15 +02:00
print '</td>' ;
}
// Batch number managment
if ( ! empty ( $conf -> productbatch -> enabled ))
{
if ( isset ( $lines [ $i ] -> detail_batch ))
2015-07-13 11:22:18 +02:00
{
2017-12-02 10:43:01 +01:00
print '<!-- Detail of lot -->' ;
2017-10-23 22:18:15 +02:00
print '<td>' ;
if ( $lines [ $i ] -> product_tobatch )
{
$detail = '' ;
2018-10-11 11:56:52 +02:00
foreach ( $lines [ $i ] -> detail_batch as $dbatch ) // $dbatch is instance of ExpeditionLineBatch
2017-10-23 22:18:15 +02:00
{
2017-12-02 10:43:01 +01:00
$detail .= $langs -> trans ( " Batch " ) . ': ' . $dbatch -> batch ;
$detail .= ' - ' . $langs -> trans ( " SellByDate " ) . ': ' . dol_print_date ( $dbatch -> sellby , " day " );
2017-12-02 11:34:56 +01:00
$detail .= ' - ' . $langs -> trans ( " EatByDate " ) . ': ' . dol_print_date ( $dbatch -> eatby , " day " );
2018-10-11 11:56:52 +02:00
$detail .= ' - ' . $langs -> trans ( " Qty " ) . ': ' . $dbatch -> qty ;
2017-12-02 10:43:01 +01:00
$detail .= '<br>' ;
2017-10-23 22:18:15 +02:00
}
print $form -> textwithtooltip ( img_picto ( '' , 'object_barcode' ) . ' ' . $langs -> trans ( " DetailBatchNumber " ), $detail );
}
else
{
print $langs -> trans ( " NA " );
}
print '</td>' ;
} else {
print '<td></td>' ;
2014-03-07 11:35:16 +01:00
}
}
}
2017-10-18 18:18:17 +02:00
2017-10-23 22:18:15 +02:00
// Weight
print '<td align="center">' ;
2017-12-01 13:40:24 +01:00
if ( $lines [ $i ] -> fk_product_type == Product :: TYPE_PRODUCT ) print $lines [ $i ] -> weight * $lines [ $i ] -> qty_shipped . ' ' . measuring_units_string ( $lines [ $i ] -> weight_units , " weight " );
2017-10-23 22:18:15 +02:00
else print ' ' ;
2017-10-18 18:18:17 +02:00
print '</td>' ;
2017-10-23 22:18:15 +02:00
// Volume
print '<td align="center">' ;
2017-12-01 13:40:24 +01:00
if ( $lines [ $i ] -> fk_product_type == Product :: TYPE_PRODUCT ) print $lines [ $i ] -> volume * $lines [ $i ] -> qty_shipped . ' ' . measuring_units_string ( $lines [ $i ] -> volume_units , " volume " );
2017-10-23 22:18:15 +02:00
else print ' ' ;
2017-10-18 18:18:17 +02:00
print '</td>' ;
2017-10-23 22:18:15 +02:00
// Size
//print '<td align="center">'.$lines[$i]->volume*$lines[$i]->qty_shipped.' '.measuring_units_string($lines[$i]->volume_units,"volume").'</td>';
if ( $action == 'editline' && $lines [ $i ] -> id == $line_id )
{
print '<td align="center" colspan="2" valign="middle">' ;
print '<input type="submit" class="button" id="savelinebutton" name="save" value="' . $langs -> trans ( " Save " ) . '"><br>' ;
print '<input type="submit" class="button" id="cancellinebutton" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '"><br>' ;
}
else if ( $object -> statut == 0 )
{
// edit-delete buttons
print '<td class="linecoledit" align="center">' ;
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=editline&lineid=' . $lines [ $i ] -> id . '">' . img_edit () . '</a>' ;
print '</td>' ;
print '<td class="linecoldelete" width="10">' ;
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=deleteline&lineid=' . $lines [ $i ] -> id . '">' . img_delete () . '</a>' ;
print '</td>' ;
// Display lines extrafields
if ( ! empty ( $rowExtrafieldsStart ))
{
print $rowExtrafieldsStart ;
print $rowExtrafieldsView ;
print $rowEnd ;
}
}
2013-08-07 15:08:30 +02:00
print " </tr> " ;
2017-06-07 16:44:04 +02:00
2016-10-29 14:52:13 +02:00
// Display lines extrafields
2015-12-16 16:18:29 +01:00
if ( is_array ( $extralabelslines ) && count ( $extralabelslines ) > 0 ) {
$colspan = empty ( $conf -> productbatch -> enabled ) ? 5 : 6 ;
$line = new ExpeditionLigne ( $db );
2018-02-21 14:48:25 +01:00
$line -> fetch_optionals ( $lines [ $i ] -> id );
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2017-10-24 10:53:11 +02:00
if ( $action == 'editline' && $lines [ $i ] -> id == $line_id )
2017-10-23 22:18:15 +02:00
{
print $line -> showOptionals ( $extrafieldsline , 'edit' , array ( 'style' => $bc [ $var ], 'colspan' => $colspan ), $indiceAsked );
}
2017-11-02 12:38:36 +01:00
else
2017-10-23 22:18:15 +02:00
{
print $line -> showOptionals ( $extrafieldsline , 'view' , array ( 'style' => $bc [ $var ], 'colspan' => $colspan ), $indiceAsked );
}
2015-12-16 16:18:29 +01:00
print '</tr>' ;
}
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 " ;
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
2016-09-19 13:57:50 +02:00
dol_fiche_end ();
2012-03-14 14:48:27 +01:00
2013-08-07 15:08:30 +02: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
2013-08-07 15:08:30 +02:00
if (( $user -> societe_id == 0 ) && ( $action != 'presend' ))
{
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
// modified by hook
if ( empty ( $reshook ))
2013-08-07 15:08:30 +02:00
{
2016-05-03 14:20:42 +02:00
2018-02-15 15:27:06 +01:00
if ( $object -> statut == Expedition :: STATUS_DRAFT && $num_prod > 0 )
2013-08-07 15:08:30 +02:00
{
2016-05-03 14:20:42 +02:00
if (( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> expedition -> creer ))
|| ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> expedition -> shipping_advance -> validate )))
{
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=valid">' . $langs -> trans ( " Validate " ) . '</a>' ;
}
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)
2018-02-15 15:27:06 +01:00
if ( $object -> statut == Expedition :: STATUS_CLOSED && $user -> rights -> expedition -> creer )
2013-08-07 15:08:30 +02:00
{
2018-02-15 15:27:06 +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 ?
{
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=reopen">' . $langs -> trans ( " ClassifyUnbilled " ) . '</a>' ;
}
else
{
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=reopen">' . $langs -> trans ( " ReOpen " ) . '</a>' ;
}
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
if ( $object -> statut > 0 )
2013-08-07 15:08:30 +02:00
{
2016-05-03 14:20:42 +02:00
if ( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) || $user -> rights -> expedition -> shipping_advance -> send )
{
2018-03-11 21:34:38 +01:00
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=presend&mode=init#formmailbeforetitle">' . $langs -> trans ( 'SendMail' ) . '</a>' ;
2016-05-03 14:20:42 +02:00
}
2018-11-13 21:40:17 +01:00
else print '<a class="butActionRefused classfortooltip" href="#">' . $langs -> trans ( 'SendMail' ) . '</a>' ;
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
2017-11-24 15:27:00 +01:00
if ( ! empty ( $conf -> facture -> enabled ) && ( $object -> statut == Expedition :: STATUS_VALIDATED || $object -> statut == Expedition :: STATUS_CLOSED ))
2013-08-07 15:08:30 +02:00
{
2016-05-03 14:20:42 +02:00
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']);
2017-11-24 15:27:00 +01:00
if ( $conf -> livraison_bon -> enabled && ( $object -> statut == Expedition :: STATUS_VALIDATED || $object -> statut == Expedition :: STATUS_CLOSED ) && $user -> rights -> expedition -> livraison -> creer && count ( $object -> linkedObjectsIds [ 'delivery' ]) == 0 )
2013-08-07 15:08:30 +02:00
{
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
2017-11-24 15:27:00 +01:00
if ( $object -> statut == Expedition :: STATUS_VALIDATED )
2016-05-03 14:20:42 +02:00
{
if ( $user -> rights -> expedition -> creer && $object -> statut > 0 && ! $object -> billed )
2016-04-26 13:27:32 +02:00
{
2016-05-03 14:20:42 +02:00
$label = " Close " ; $paramaction = 'classifyclosed' ; // = Transferred/Received
// Label here should be "Close" or "ClassifyBilled" if we decided to make bill on shipments instead of orders
2017-11-24 15:27:00 +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 ?
2016-05-03 14:20:42 +02:00
{
$label = " ClassifyBilled " ;
$paramaction = 'classifybilled' ;
}
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
2016-05-03 14:20:42 +02:00
if ( $user -> rights -> expedition -> supprimer )
{
print '<a class="butActionDelete" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=delete">' . $langs -> trans ( " Delete " ) . '</a>' ;
}
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
2017-10-23 22:18:15 +02:00
if ( $action != 'presend' && $action != 'editline' )
2013-08-07 15:08:30 +02:00
{
2015-10-22 19:13:16 +02:00
print '<div class="fichecenter"><div class="fichehalfleft">' ;
2017-06-07 16:44:04 +02:00
2015-10-22 19:13:16 +02:00
$objectref = dol_sanitizeFileName ( $object -> ref );
2013-08-07 15:08:30 +02: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
2013-08-07 15:08:30 +02:00
$genallowed = $user -> rights -> expedition -> lire ;
2017-10-18 17:21:30 +02:00
$delallowed = $user -> rights -> expedition -> creer ;
2013-03-30 13:54:46 +01:00
2016-10-24 11:27:39 +02:00
print $formfile -> showdocuments ( 'expedition' , $objectref , $filedir , $urlsource , $genallowed , $delallowed , $object -> modelpdf , 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' ;
$formactions = new FormActions ( $db );
2017-09-13 14:18:36 +02: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
$modelmail = 'shipping_send' ;
$defaulttopic = 'SendShippingRef' ;
$diroutput = $conf -> expedition -> dir_output . '/sending' ;
$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 ();