2018-10-03 12:22:41 +02:00
< ? php
/* Copyright ( C ) 2003 - 2008 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2005 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2005 Simon TOSSER < simon @ kornog - computing . com >
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
* Copyright ( C ) 2011 - 2017 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
* Copyright ( C ) 2013 Marcos García < marcosgdf @ gmail . com >
* Copyright ( C ) 2014 Cedric GROSS < c . gross @ kreiz - it . fr >
* Copyright ( C ) 2014 - 2017 Francis Appels < francis . appels @ yahoo . com >
* Copyright ( C ) 2015 Claudio Aschieri < c . aschieri @ 19. coop >
* Copyright ( C ) 2016 Ferran Marcet < fmarcet @ 2 byte . es >
* Copyright ( C ) 2016 Yasser Carreón < yacasia @ gmail . com >
2018-10-09 17:05:45 +02:00
* Copyright ( C ) 2018 Quentin Vial - Gouteyron < quentin . vial - gouteyron @ atm - consulting . fr >
2018-10-03 12:22:41 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
/**
2018-10-04 12:27:10 +02:00
* \file htdocs / reception / card . php
* \ingroup reception
* \brief Card of a reception
2018-10-03 12:22:41 +02:00
*/
require '../main.inc.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
2018-10-04 12:27:10 +02:00
require_once DOL_DOCUMENT_ROOT . '/reception/class/reception.class.php' ;
2018-10-03 12:22:41 +02:00
require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php' ;
2018-10-04 12:27:10 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/reception.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/modules/reception/modules_reception.php' ;
2018-10-03 12:22:41 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/stock/class/productlot.class.php' ;
if ( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled )) require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
if ( ! empty ( $conf -> propal -> enabled )) require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php' ;
2018-12-15 13:58:39 +01:00
if ( ! empty ( $conf -> fournisseur -> enabled )){
2018-10-04 17:32:50 +02:00
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.dispatch.class.php' ;
}
2018-10-03 12:22:41 +02:00
if ( ! empty ( $conf -> productbatch -> enabled )) require_once DOL_DOCUMENT_ROOT . '/product/class/productbatch.class.php' ;
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' ;
}
2018-10-04 12:27:10 +02:00
$langs -> loadLangs ( array ( " receptions " , " companies " , " bills " , 'deliveries' , 'orders' , 'stocks' , 'other' , 'propal' ));
2018-10-03 12:22:41 +02:00
if ( ! empty ( $conf -> incoterm -> enabled )) $langs -> load ( 'incoterm' );
if ( ! empty ( $conf -> productbatch -> enabled )) $langs -> load ( 'productbatch' );
2018-10-04 12:27:10 +02:00
$origin = GETPOST ( 'origin' , 'alpha' ) ? GETPOST ( 'origin' , 'alpha' ) : 'reception' ; // Example: commande, propal
2018-10-03 12:22:41 +02:00
$origin_id = GETPOST ( 'id' , 'int' ) ? GETPOST ( 'id' , 'int' ) : '' ;
$id = $origin_id ;
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
2018-10-04 12:27:10 +02:00
if ( empty ( $origin_id )) $origin_id = GETPOST ( 'originid' , 'int' ); // Id of order or propal
2018-10-03 12:22:41 +02:00
$ref = GETPOST ( 'ref' , 'alpha' );
$line_id = GETPOST ( 'lineid' , 'int' ) ? GETPOST ( 'lineid' , 'int' ) : '' ;
// Security check
$socid = '' ;
if ( $user -> societe_id ) $socid = $user -> societe_id ;
2018-10-04 12:27:10 +02:00
if ( $origin == 'reception' ) $result = restrictedArea ( $user , $origin , $id );
2018-10-03 12:22:41 +02:00
else {
2018-10-04 12:27:10 +02:00
$result = restrictedArea ( $user , 'reception' );
if ( $origin == 'supplierorder' ){
if ( empty ( $user -> rights -> fournisseur -> commande -> lire ) && empty ( $user -> rights -> fournisseur -> commande -> read )) accessforbidden ();
} else if ( empty ( $user -> rights -> { $origin } -> lire ) && empty ( $user -> rights -> { $origin } -> read )) accessforbidden ();
2018-10-03 12:22:41 +02:00
}
$action = GETPOST ( 'action' , 'alpha' );
2018-10-18 17:02:20 +02:00
//Select mail models is same action as presend
if ( GETPOST ( 'modelselected' )) {
$action = 'presend' ;
}
2018-10-03 12:22:41 +02:00
$confirm = GETPOST ( 'confirm' , 'alpha' );
$cancel = GETPOST ( 'cancel' , 'alpha' );
//PDF
$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 ));
2018-10-04 12:27:10 +02:00
$object = new Reception ( $db );
2018-10-03 12:22:41 +02: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 );
// Load object. Make an object->fetch
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php' ; // Must be include, not include_once
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2018-10-04 12:27:10 +02:00
$hookmanager -> initHooks ( array ( 'receptioncard' , 'globalcard' ));
2018-10-03 12:22:41 +02:00
2018-10-10 12:19:57 +02:00
$permissiondellink = $user -> rights -> reception -> creer ; // Used by the include of actions_dellink.inc.php
2018-10-03 12:22:41 +02:00
//var_dump($object->lines[0]->detail_batch);
/*
* Actions
*/
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
if ( empty ( $reshook ))
{
if ( $cancel )
{
$action = '' ;
2018-10-04 12:27:10 +02:00
$object -> fetch ( $id ); // show reception also after canceling modification
2018-10-03 12:22:41 +02:00
}
include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php' ; // Must be include, not include_once
// Reopen
2018-10-04 12:27:10 +02:00
if ( $action == 'reopen' && $user -> rights -> reception -> creer )
2018-10-03 12:22:41 +02:00
{
$object -> fetch ( $id );
$result = $object -> reOpen ();
}
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
// Confirm back to draft status
2018-10-04 12:27:10 +02:00
if ( $action == 'modif' && $user -> rights -> reception -> creer )
2018-10-03 12:22:41 +02:00
{
$result = $object -> set_draft ( $user );
if ( $result >= 0 )
{
// Define output language
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$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 );
}
$model = $object -> modelpdf ;
$ret = $object -> fetch ( $id ); // Reload to get new records
$object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
}
}
}
// Set incoterm
if ( $action == 'set_incoterms' && ! empty ( $conf -> incoterm -> enabled ))
{
$result = $object -> setIncoterms ( GETPOST ( 'incoterm_id' , 'int' ), GETPOST ( 'location_incoterms' , 'alpha' ));
}
2018-10-08 16:54:33 +02:00
if ( $action == 'setref_supplier' )
2018-10-03 12:22:41 +02:00
{
$result = $object -> fetch ( $id );
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2018-10-08 16:54:33 +02:00
$result = $object -> setValueFrom ( 'ref_supplier' , GETPOST ( 'ref_supplier' , 'alpha' ), '' , null , 'text' , '' , $user , 'RECEPTION_MODIFY' );
2018-10-03 12:22:41 +02:00
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2018-10-08 16:54:33 +02:00
$action = 'editref_supplier' ;
2018-10-03 12:22:41 +02:00
} else {
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
}
}
if ( $action == 'update_extras' )
{
// Fill array 'array_options' with data from update form
$extralabels = $extrafields -> fetch_name_optionals_label ( $object -> table_element );
$ret = $extrafields -> setOptionalsFromPost ( $extralabels , $object , GETPOST ( 'attribute' ));
if ( $ret < 0 ) $error ++ ;
if ( ! $error )
{
// Actions on extra fields (by external module or standard code)
// TODO le hook fait double emploi avec le trigger !!
2018-10-04 12:27:10 +02:00
$hookmanager -> initHooks ( array ( 'receptiondao' ));
2018-10-03 12:22:41 +02:00
$parameters = array ( 'id' => $object -> id );
$reshook = $hookmanager -> executeHooks ( 'insertExtraFields' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
if ( empty ( $reshook )) {
$result = $object -> insertExtraFields ();
if ( $result < 0 )
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
} else if ( $reshook < 0 )
$error ++ ;
}
if ( $error )
$action = 'edit_extras' ;
}
2018-10-04 12:27:10 +02:00
// Create reception
if ( $action == 'add' && $user -> rights -> reception -> creer )
2018-10-03 12:22:41 +02:00
{
2018-12-15 13:58:39 +01:00
2018-10-04 17:32:50 +02:00
$error = 0 ;
$predef = '' ;
2018-10-03 12:22:41 +02:00
2018-10-04 17:32:50 +02:00
$db -> begin ();
2018-10-03 12:22:41 +02:00
2018-10-04 17:32:50 +02:00
$object -> note = GETPOST ( 'note' , 'alpha' );
$object -> origin = $origin ;
$object -> origin_id = $origin_id ;
$object -> fk_project = GETPOST ( 'projectid' , 'int' );
$object -> weight = GETPOST ( 'weight' , 'int' ) == '' ? " NULL " : GETPOST ( 'weight' , 'int' );
$object -> sizeH = GETPOST ( 'sizeH' , 'int' ) == '' ? " NULL " : GETPOST ( 'sizeH' , 'int' );
$object -> sizeW = GETPOST ( 'sizeW' , 'int' ) == '' ? " NULL " : GETPOST ( 'sizeW' , 'int' );
$object -> sizeS = GETPOST ( 'sizeS' , 'int' ) == '' ? " NULL " : GETPOST ( 'sizeS' , 'int' );
$object -> size_units = GETPOST ( 'size_units' , 'int' );
$object -> weight_units = GETPOST ( 'weight_units' , 'int' );
2018-10-03 12:22:41 +02:00
2018-10-04 17:32:50 +02:00
$date_delivery = dol_mktime ( GETPOST ( 'date_deliveryhour' , 'int' ), GETPOST ( 'date_deliverymin' , 'int' ), 0 , GETPOST ( 'date_deliverymonth' , 'int' ), GETPOST ( 'date_deliveryday' , 'int' ), GETPOST ( 'date_deliveryyear' , 'int' ));
2018-10-03 12:22:41 +02:00
2018-10-04 17:32:50 +02:00
// On va boucler sur chaque ligne du document d'origine pour completer objet reception
// avec info diverses + qte a livrer
2018-10-03 12:22:41 +02:00
2018-10-04 17:32:50 +02:00
if ( $object -> origin == " supplierorder " )
$classname = 'CommandeFournisseur' ;
else
$classname = ucfirst ( $object -> origin );
$objectsrc = new $classname ( $db );
$objectsrc -> fetch ( $object -> origin_id );
2018-12-15 13:58:39 +01:00
2018-10-04 17:32:50 +02:00
$object -> socid = $objectsrc -> socid ;
$object -> ref_supplier = GETPOST ( 'ref_supplier' , 'alpha' );
$object -> model_pdf = GETPOST ( 'model' );
$object -> date_delivery = $date_delivery ; // Date delivery planed
$object -> fk_delivery_address = $objectsrc -> fk_delivery_address ;
2018-10-05 16:21:50 +02:00
$object -> shipping_method_id = GETPOST ( 'shipping_method_id' , 'int' );
2018-10-04 17:32:50 +02:00
$object -> tracking_number = GETPOST ( 'tracking_number' , 'alpha' );
$object -> ref_int = GETPOST ( 'ref_int' , 'alpha' );
$object -> note_private = GETPOST ( 'note_private' , 'none' );
$object -> note_public = GETPOST ( 'note_public' , 'none' );
$object -> fk_incoterms = GETPOST ( 'incoterm_id' , 'int' );
$object -> location_incoterms = GETPOST ( 'location_incoterms' , 'alpha' );
$batch_line = array ();
$stockLine = array ();
$array_options = array ();
$totalqty = 0 ;
$num = 0 ;
foreach ( $_POST as $key => $value )
{
// without batch module enabled
if ( strpos ( $key , 'qtyasked' ) !== false )
2018-10-03 12:22:41 +02:00
{
2018-10-04 17:32:50 +02:00
$num ++ ;
2018-10-03 12:22:41 +02:00
}
2018-10-04 17:32:50 +02:00
}
for ( $i = 1 ; $i <= $num ; $i ++ )
{
$idl = " idl " . $i ;
$sub_qty = array ();
$subtotalqty = 0 ;
$j = 0 ;
$batch = " batchl " . $i . " _0 " ;
$stockLocation = " ent1 " . $i . " _0 " ;
$qty = " qtyl " . $i ;
2018-12-15 13:58:39 +01:00
2018-10-04 17:32:50 +02:00
//var_dump(GETPOST($qty,'int')); var_dump($_POST); var_dump($batch);exit;
2018-10-04 12:27:10 +02:00
//reception line for product with no batch management and no multiple stock location
2018-10-04 17:32:50 +02:00
if ( GETPOST ( $qty , 'int' ) > 0 )
$totalqty += GETPOST ( $qty , 'int' );
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
// Extrafields
$extralabelsline = $extrafieldsline -> fetch_name_optionals_label ( $object -> table_element_line );
2018-10-04 17:32:50 +02:00
$array_options [ $i ] = $extrafieldsline -> getOptionalsFromPost ( $extralabelsline , $i );
}
2018-10-03 12:22:41 +02:00
2018-10-04 17:32:50 +02:00
if ( $totalqty > 0 ) // There is at least one thing to ship
{
//var_dump($_POST);exit;
for ( $i = 1 ; $i <= $num ; $i ++ )
{
$lineToTest = '' ;
foreach ( $objectsrc -> lines as $linesrc ){
if ( $linesrc -> id == GETPOST ( $idl , 'int' )) $lineToTest = $linesrc ;
2018-10-03 12:22:41 +02:00
}
2018-10-04 17:32:50 +02:00
$qty = " qtyl " . $i ;
$comment = " comment " . $i ;
$eatby = " dlc " . $i ;
$sellby = " dluo " . $i ;
$batch = " batch " . $i ;
2018-12-15 13:58:39 +01:00
2018-10-04 17:32:50 +02:00
$timeFormat = '%d/%m/%Y' ;
if ( GETPOST ( $qty , 'int' ) > 0 || ( GETPOST ( $qty , 'int' ) == 0 && $conf -> global -> RECEPTION_GETS_ALL_ORDER_PRODUCTS ))
2018-10-03 12:22:41 +02:00
{
2018-10-04 17:32:50 +02:00
$ent = " entl " . $i ;
2018-12-15 13:58:39 +01:00
2018-10-04 17:32:50 +02:00
$idl = " idl " . $i ;
2018-12-15 13:58:39 +01:00
2018-10-04 17:32:50 +02:00
$entrepot_id = is_numeric ( GETPOST ( $ent , 'int' )) ? GETPOST ( $ent , 'int' ) : GETPOST ( 'entrepot_id' , 'int' );
2018-12-15 13:58:39 +01:00
2018-10-04 17:32:50 +02:00
if ( $entrepot_id < 0 )
$entrepot_id = '' ;
2018-10-10 12:19:57 +02:00
if ( ! ( $linesrc -> fk_product > 0 ) && empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES ))
2018-10-04 17:32:50 +02:00
$entrepot_id = 0 ;
$eatby = GETPOST ( $eatby , 'alpha' );
$sellby = GETPOST ( $sellby , 'alpha' );
$eatbydate = str_replace ( '/' , '-' , $eatby );
$sellbydate = str_replace ( '/' , '-' , $sellby );
2018-12-15 13:58:39 +01:00
$ret = $object -> addline ( $entrepot_id , GETPOST ( $idl , 'int' ), GETPOST ( $qty , 'int' ), $array_options [ $i ], GETPOST ( $comment , 'alpha' ), strtotime ( $eatbydate ), strtotime ( $sellbydate ), GETPOST ( $batch , 'alpha' ));
2018-10-04 17:32:50 +02:00
if ( $ret < 0 )
2018-10-03 12:22:41 +02:00
{
2018-10-04 17:32:50 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
2018-10-03 12:22:41 +02:00
}
}
2018-10-04 17:32:50 +02:00
}
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
// Fill array 'array_options' with data from add form
$ret = $extrafields -> setOptionalsFromPost ( $extralabels , $object );
if ( $ret < 0 ) $error ++ ;
if ( ! $error )
{
2018-10-04 12:27:10 +02:00
$ret = $object -> create ( $user ); // This create reception (like Odoo picking) and line of receptions. Stock movement will when validating reception.
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
if ( $ret <= 0 )
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
}
}
else
{
2018-10-04 12:27:10 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " QtyToReceive " ) . '/' . $langs -> transnoentitiesnoconv ( " Warehouse " )), null , 'errors' );
2018-10-03 12:22:41 +02: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' ;
}
}
else if ( $action == 'confirm_valid' && $confirm == 'yes' &&
2018-10-04 12:27:10 +02:00
(( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> reception -> creer ))
|| ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> reception -> reception_advance -> validate )))
2018-10-03 12:22:41 +02:00
)
{
$object -> fetch_thirdparty ();
$result = $object -> valid ( $user );
if ( $result < 0 )
{
$langs -> load ( " errors " );
setEventMessages ( $langs -> trans ( $object -> error ), null , 'errors' );
}
else
{
// Define output language
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$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 );
}
$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 );
}
}
}
2018-10-04 12:27:10 +02:00
else if ( $action == 'confirm_delete' && $confirm == 'yes' && $user -> rights -> reception -> supprimer )
2018-10-03 12:22:41 +02:00
{
2018-12-15 16:37:00 +01:00
$result = $object -> delete ( $user );
2018-10-03 12:22:41 +02:00
if ( $result > 0 )
{
2018-10-04 12:27:10 +02:00
header ( " Location: " . DOL_URL_ROOT . '/reception/index.php' );
2018-10-03 12:22:41 +02:00
exit ;
}
else
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
// TODO add alternative status
2018-10-04 12:27:10 +02:00
/* else if ( $action == 'reopen' && ( ! empty ( $user -> rights -> reception -> creer ) || ! empty ( $user -> rights -> reception -> reception_advance -> validate )))
2018-10-03 12:22:41 +02:00
{
$result = $object -> setStatut ( 0 );
if ( $result < 0 )
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
} */
2018-10-04 12:27:10 +02:00
else if ( $action == 'setdate_livraison' && $user -> rights -> reception -> creer )
2018-10-03 12:22:41 +02:00
{
//print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
$datedelivery = dol_mktime ( GETPOST ( 'liv_hour' , 'int' ), GETPOST ( 'liv_min' , 'int' ), 0 , GETPOST ( 'liv_month' , 'int' ), GETPOST ( 'liv_day' , 'int' ), GETPOST ( 'liv_year' , 'int' ));
$object -> fetch ( $id );
$result = $object -> set_date_livraison ( $user , $datedelivery );
if ( $result < 0 )
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
// Action update
else if ( $action == 'settracking_number' || $action == 'settracking_url'
|| $action == 'settrueWeight'
|| $action == 'settrueWidth'
|| $action == 'settrueHeight'
|| $action == 'settrueDepth'
2018-10-05 16:21:50 +02:00
|| $action == 'setshipping_method_id' )
2018-10-03 12:22:41 +02:00
{
$error = 0 ;
if ( $action == 'settracking_number' ) $object -> tracking_number = trim ( GETPOST ( 'tracking_number' , 'alpha' ));
if ( $action == 'settracking_url' ) $object -> tracking_url = trim ( GETPOST ( 'tracking_url' , 'int' ));
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' ));
2018-10-05 16:21:50 +02:00
if ( $action == 'setshipping_method_id' ) $object -> shipping_method_id = trim ( GETPOST ( 'shipping_method_id' , 'int' ));
2018-10-03 12:22:41 +02:00
if ( ! $error )
{
if ( $object -> update ( $user ) >= 0 )
{
header ( " Location: card.php?id= " . $object -> id );
exit ;
}
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
$action = " " ;
}
// Build document
else if ( $action == 'builddoc' ) // En get ou en post
{
// Save last template used to generate document
if ( GETPOST ( 'model' )) $object -> setDocModel ( $user , GETPOST ( 'model' , 'alpha' ));
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) $newlang = GETPOST ( 'lang_id' , 'aZ09' );
2018-10-04 12:27:10 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $reception -> thirdparty -> default_lang ;
2018-10-03 12:22:41 +02:00
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$result = $object -> generateDocument ( $object -> modelpdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
if ( $result <= 0 )
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$action = '' ;
}
}
// Delete file in doc form
elseif ( $action == 'remove_file' )
{
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2018-10-10 12:19:57 +02:00
$upload_dir = $conf -> reception -> dir_output ;
2018-10-03 12:22:41 +02:00
$file = $upload_dir . '/' . GETPOST ( 'file' );
$ret = dol_delete_file ( $file , 0 , 0 , 0 , $object );
if ( $ret ) setEventMessages ( $langs -> trans ( " FileWasRemoved " , GETPOST ( 'urlfile' )), null , 'mesgs' );
else setEventMessages ( $langs -> trans ( " ErrorFailToDeleteFile " , GETPOST ( 'urlfile' )), null , 'errors' );
}
elseif ( $action == 'classifybilled' )
{
$object -> fetch ( $id );
$result = $object -> set_billed ();
if ( $result >= 0 ) {
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ();
}
}
elseif ( $action == 'classifyclosed' )
{
$object -> fetch ( $id );
$result = $object -> setClosed ();
if ( $result >= 0 ) {
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ();
}
}
/*
* delete a line
*/
elseif ( $action == 'deleteline' && ! empty ( $line_id ))
{
$object -> fetch ( $id );
$lines = $object -> lines ;
2018-10-05 16:21:50 +02:00
$line = new CommandeFournisseurDispatch ( $db );
2018-10-03 12:22:41 +02:00
$num_prod = count ( $lines );
for ( $i = 0 ; $i < $num_prod ; $i ++ )
{
if ( $lines [ $i ] -> id == $line_id )
{
// delete single warehouse line
$line -> id = $line_id ;
if ( ! $error && $line -> delete ( $user ) < 0 )
{
$error ++ ;
}
}
unset ( $_POST [ " lineid " ]);
}
if ( ! $error ) {
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ();
}
else
{
setEventMessages ( $line -> error , $line -> errors , 'errors' );
}
}
/*
* Update a line
*/
2018-10-04 12:27:10 +02:00
else if ( $action == 'updateline' && $user -> rights -> reception -> creer && GETPOST ( 'save' ))
2018-10-03 12:22:41 +02:00
{
// Clean parameters
2018-10-08 16:54:33 +02:00
$qty = 0 ;
2018-10-03 12:22:41 +02:00
$entrepot_id = 0 ;
$batch_id = 0 ;
$lines = $object -> lines ;
$num_prod = count ( $lines );
2018-10-08 16:54:33 +02:00
for ( $i = 0 ; $i < $num_prod ; $i ++ )
2018-10-03 12:22:41 +02:00
{
2018-10-08 16:54:33 +02:00
if ( $lines [ $i ] -> id == $line_id ) // we have found line to update
2018-10-03 12:22:41 +02:00
{
2018-10-05 16:21:50 +02:00
$line = new CommandeFournisseurDispatch ( $db );
2018-10-08 16:54:33 +02:00
$line -> fetch ( $line_id );
2018-10-03 12:22:41 +02:00
// Extrafields Lines
$extrafieldsline = new ExtraFields ( $db );
$extralabelsline = $extrafieldsline -> fetch_name_optionals_label ( $object -> table_element_line );
$line -> array_options = $extrafieldsline -> getOptionalsFromPost ( $extralabelsline );
2018-10-08 16:54:33 +02:00
2018-10-03 12:22:41 +02:00
$line -> fk_product = $lines [ $i ] -> fk_product ;
2018-12-15 13:58:39 +01:00
2018-10-08 16:54:33 +02:00
if ( $lines [ $i ] -> fk_product > 0 )
{
// single warehouse reception line
$stockLocation = " entl " . $line_id ;
$qty = " qtyl " . $line_id ;
2018-10-15 17:08:28 +02:00
$comment = " comment " . $line_id ;
2018-12-15 13:58:39 +01:00
2018-10-08 16:54:33 +02:00
$line -> id = $line_id ;
$line -> fk_entrepot = GETPOST ( $stockLocation , 'int' );
$line -> qty = GETPOST ( $qty , 'int' );
2018-10-15 17:08:28 +02:00
$line -> comment = GETPOST ( $comment , 'alpha' );
2018-12-15 13:58:39 +01:00
2018-10-08 16:54:33 +02:00
if ( ! empty ( $conf -> productbatch -> enabled )){
$batch = " batch " . $line_id ;
$dlc = " dlc " . $line_id ;
$dluo = " dluo " . $line_id ;
$eatby = GETPOST ( $dlc , 'alpha' );
$eatbydate = str_replace ( '/' , '-' , $eatby );
$sellby = GETPOST ( $dluo , 'alpha' );
$sellbydate = str_replace ( '/' , '-' , $sellby );
$line -> batch = GETPOST ( $batch , 'alpha' );
$line -> eatby = strtotime ( $eatbydate );
$line -> sellby = strtotime ( $sellbydate );
2018-10-03 12:22:41 +02:00
}
2018-12-15 13:58:39 +01:00
2018-10-08 16:54:33 +02:00
if ( $line -> update ( $user ) < 0 )
2018-10-03 12:22:41 +02:00
{
2018-10-08 16:54:33 +02:00
setEventMessages ( $line -> error , $line -> errors , 'errors' );
$error ++ ;
2018-10-03 12:22:41 +02:00
}
}
2018-10-08 16:54:33 +02:00
else // Product no predefined
2018-10-03 12:22:41 +02:00
{
2018-10-08 16:54:33 +02:00
$qty = " qtyl " . $line_id ;
$line -> id = $line_id ;
$line -> qty = GETPOST ( $qty , 'int' );
$line -> fk_entrepot = 0 ;
if ( $line -> update ( $user ) < 0 )
2018-10-03 12:22:41 +02:00
{
2018-10-08 16:54:33 +02:00
setEventMessages ( $line -> error , $line -> errors , 'errors' );
$error ++ ;
2018-10-03 12:22:41 +02:00
}
2018-10-08 16:54:33 +02:00
unset ( $_POST [ $qty ]);
2018-10-03 12:22:41 +02:00
}
}
}
unset ( $_POST [ " lineid " ]);
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 );
}
}
else
{
header ( 'Location: ' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id ); // Pour reaffichage de la fiche en cours d'edition
exit ();
}
}
2018-10-04 12:27:10 +02:00
else if ( $action == 'updateline' && $user -> rights -> reception -> creer && GETPOST ( 'cancel' , 'alpha' ) == $langs -> trans ( 'Cancel' )) {
2018-10-03 12:22:41 +02:00
header ( 'Location: ' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id ); // Pour reaffichage de la fiche en cours d'edition
exit ();
}
include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php' ;
// Actions to send emails
if ( empty ( $id )) $id = $facid ;
2018-10-04 12:27:10 +02:00
$trigger_name = 'RECEPTION_SENTBYMAIL' ;
2018-10-03 12:22:41 +02:00
$paramname = 'id' ;
2018-10-04 12:27:10 +02:00
$mode = 'emailfromreception' ;
2018-10-03 12:22:41 +02:00
$trackid = 'shi' . $object -> id ;
include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php' ;
}
/*
* View
*/
2018-10-04 12:27:10 +02:00
llxHeader ( '' , $langs -> trans ( 'Reception' ), 'Reception' );
2018-10-03 12:22:41 +02:00
$form = new Form ( $db );
$formfile = new FormFile ( $db );
$formproduct = new FormProduct ( $db );
if ( ! empty ( $conf -> projet -> enabled )) { $formproject = new FormProjets ( $db ); }
$product_static = new Product ( $db );
2018-10-04 12:27:10 +02:00
$reception_static = new Reception ( $db );
2018-10-03 12:22:41 +02:00
$warehousestatic = new Entrepot ( $db );
if ( $action == 'create2' )
{
2018-10-04 12:27:10 +02:00
print load_fiche_titre ( $langs -> trans ( " CreateReception " )) . '<br>' ;
print $langs -> trans ( " ReceptionCreationIsDoneFromOrder " );
2018-10-03 12:22:41 +02:00
$action = '' ; $id = '' ; $ref = '' ;
}
// Mode creation.
if ( $action == 'create' )
{
2018-10-04 12:27:10 +02:00
$recept = new Reception ( $db );
2018-10-03 12:22:41 +02:00
2018-10-04 12:27:10 +02:00
print load_fiche_titre ( $langs -> trans ( " CreateReception " ));
2018-10-03 12:22:41 +02:00
if ( ! $origin )
{
setEventMessages ( $langs -> trans ( " ErrorBadParameters " ), null , 'errors' );
}
if ( $origin )
{
2018-10-04 12:27:10 +02:00
if ( $origin == 'supplierorder' ) $classname = 'CommandeFournisseur' ;
else $classname = ucfirst ( $origin );
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
$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 );
if ( ! empty ( $conf -> stock -> enabled )) $entrepot = new Entrepot ( $db );
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' ) . '">' ;
}
dol_fiche_head ( '' );
print '<table class="border centpercent">' ;
// Ref
print '<tr><td class="titlefieldcreate fieldrequired">' ;
2018-10-04 12:27:10 +02:00
if ( $origin == 'supplierorder' && ! empty ( $conf -> fournisseur -> enabled ))
2018-10-03 12:22:41 +02:00
{
2018-10-04 12:27:10 +02:00
print $langs -> trans ( " RefOrder " ) . '</td><td colspan="3"><a href="' . DOL_URL_ROOT . '/fourn/commande/card.php?id=' . $object -> id . '">' . img_object ( $langs -> trans ( " ShowOrder " ), 'order' ) . ' ' . $object -> ref ;
2018-10-03 12:22:41 +02:00
}
if ( $origin == 'propal' && ! empty ( $conf -> propal -> enabled ))
{
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 ;
}
print '</a></td>' ;
print " </tr> \n " ;
// Ref client
print '<tr><td>' ;
2018-10-04 12:27:10 +02:00
if ( $origin == 'supplier_order' ) print $langs -> trans ( 'RefSupplierOrder' );
else print $langs -> trans ( 'RefSupplier' );
2018-10-03 12:22:41 +02:00
print '</td><td colspan="3">' ;
2018-10-05 16:21:50 +02:00
print '<input type="text" name="ref_supplier" value="' . $object -> ref_supplier . '" />' ;
2018-10-03 12:22:41 +02:00
print '</td>' ;
print '</tr>' ;
// Tiers
print '<tr><td class="titlefieldcreate fieldrequired">' . $langs -> trans ( 'Company' ) . '</td>' ;
print '<td colspan="3">' . $soc -> getNomUrl ( 1 ) . '</td>' ;
print '</tr>' ;
// Project
if ( ! empty ( $conf -> projet -> enabled ))
{
$projectid = GETPOST ( 'projectid' , 'int' ) ? GETPOST ( 'projectid' , 'int' ) : 0 ;
if ( empty ( $projectid ) && ! empty ( $object -> fk_project )) $projectid = $object -> fk_project ;
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>' ;
}
// 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.
$date_delivery = ( $date_delivery ? $date_delivery : $object -> date_livraison ); // $date_delivery comes from GETPOST
print $form -> select_date ( $date_delivery ? $date_delivery :- 1 , 'date_delivery' , 1 , 1 , 1 );
print " </td> \n " ;
print '</tr>' ;
// Note Public
print '<tr><td>' . $langs -> trans ( " NotePublic " ) . '</td>' ;
print '<td colspan="3">' ;
$doleditor = new DolEditor ( 'note_public' , $object -> note_public , '' , 60 , 'dolibarr_notes' , 'In' , 0 , false , true , ROWS_3 , '90%' );
print $doleditor -> Create ( 1 );
print " </td></tr> " ;
// Note Private
if ( $object -> note_private && ! $user -> societe_id )
{
print '<tr><td>' . $langs -> trans ( " NotePrivate " ) . '</td>' ;
print '<td colspan="3">' ;
$doleditor = new DolEditor ( 'note_private' , $object -> note_private , '' , 60 , 'dolibarr_notes' , 'In' , 0 , false , true , ROWS_3 , '90%' );
print $doleditor -> Create ( 1 );
print " </td></tr> " ;
}
// Weight
print '<tr><td>' ;
print $langs -> trans ( " Weight " );
print '</td><td colspan="3"><input name="weight" size="4" value="' . GETPOST ( 'weight' , 'int' ) . '"> ' ;
$text = $formproduct -> select_measuring_units ( " weight_units " , " weight " , GETPOST ( 'weight_units' , 'int' ));
$htmltext = $langs -> trans ( " KeepEmptyForAutoCalculation " );
print $form -> textwithpicto ( $text , $htmltext );
print '</td></tr>' ;
// Dim
print '<tr><td>' ;
print $langs -> trans ( " Width " ) . ' x ' . $langs -> trans ( " Height " ) . ' x ' . $langs -> trans ( " Depth " );
print ' </td><td colspan="3"><input name="sizeW" size="4" value="' . GETPOST ( 'sizeW' , 'int' ) . '">' ;
print ' x <input name="sizeH" size="4" value="' . GETPOST ( 'sizeH' , 'int' ) . '">' ;
print ' x <input name="sizeS" size="4" value="' . GETPOST ( 'sizeS' , 'int' ) . '">' ;
print ' ' ;
$text = $formproduct -> select_measuring_units ( " size_units " , " size " );
$htmltext = $langs -> trans ( " KeepEmptyForAutoCalculation " );
print $form -> textwithpicto ( $text , $htmltext );
print '</td></tr>' ;
// Delivery method
2018-10-15 17:08:28 +02:00
print " <tr><td> " . $langs -> trans ( " ReceptionMethod " ) . " </td> " ;
2018-10-03 12:22:41 +02:00
print '<td colspan="3">' ;
2018-10-04 12:27:10 +02:00
$recept -> fetch_delivery_methods ();
2018-10-05 16:21:50 +02:00
print $form -> selectarray ( " shipping_method_id " , $recept -> meths , GETPOST ( 'shipping_method_id' , 'int' ), 1 , 0 , 0 , " " , 1 );
2018-10-03 12:22:41 +02:00
if ( $user -> admin ) print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
print " </td></tr> \n " ;
// Tracking number
print " <tr><td> " . $langs -> trans ( " TrackingNumber " ) . " </td> " ;
print '<td colspan="3">' ;
print '<input name="tracking_number" size="20" value="' . GETPOST ( 'tracking_number' , 'alpha' ) . '">' ;
print " </td></tr> \n " ;
// Other attributes
$parameters = array ( 'objectsrc' => $objectsrc , 'colspan' => ' colspan="3"' , 'socid' => $socid );
2018-10-04 12:27:10 +02:00
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $recept , $action ); // Note that $action and $object may have been modified by hook
2018-10-03 12:22:41 +02:00
print $hookmanager -> resPrint ;
if ( empty ( $reshook ) && ! empty ( $extrafields -> attribute_label )) {
// copy from order
$orderExtrafields = new Extrafields ( $db );
$orderExtrafieldLabels = $orderExtrafields -> fetch_name_optionals_label ( $object -> table_element );
if ( $object -> fetch_optionals ( $object -> id , $orderExtrafieldLabels ) > 0 ) {
2018-10-04 12:27:10 +02:00
$recept -> array_options = array_merge ( $recept -> array_options , $object -> array_options );
2018-10-03 12:22:41 +02:00
}
print $object -> showOptionals ( $extrafields , 'edit' );
}
// Incoterms
if ( ! empty ( $conf -> incoterm -> enabled ))
{
print '<tr>' ;
print '<td><label for="incoterm_id">' . $form -> textwithpicto ( $langs -> trans ( " IncotermLabel " ), $object -> libelle_incoterms , 1 ) . '</label></td>' ;
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>' ;
}
// Document model
2018-10-04 12:27:10 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/reception/modules_reception.php' ;
$liste = ModelePdfReception :: liste_modeles ( $db );
2018-10-04 17:32:50 +02:00
2018-10-03 12:22:41 +02:00
if ( count ( $liste ) > 1 )
{
print " <tr><td> " . $langs -> trans ( " DefaultModel " ) . " </td> " ;
print '<td colspan="3">' ;
2018-10-04 12:27:10 +02:00
print $form -> selectarray ( 'model' , $liste , $conf -> global -> RECEPTION_ADDON_PDF );
2018-10-03 12:22:41 +02:00
print " </td></tr> \n " ;
}
print " </table> " ;
dol_fiche_end ();
2018-10-04 12:27:10 +02:00
// Reception lines
$numAsked = 0 ;
$dispatchLines = array ();
foreach ( $_POST as $key => $value )
{
// without batch module enabled
if ( preg_match ( '/^product_([0-9]+)_([0-9]+)$/i' , $key , $reg ))
{
2018-10-04 17:32:50 +02:00
$numAsked ++ ;
2018-10-04 12:27:10 +02:00
// $numline=$reg[2] + 1; // line of product
$numline = $numAsked ;
$prod = " product_ " . $reg [ 1 ] . '_' . $reg [ 2 ];
$qty = " qty_ " . $reg [ 1 ] . '_' . $reg [ 2 ];
$ent = " entrepot_ " . $reg [ 1 ] . '_' . $reg [ 2 ];
$pu = " pu_ " . $reg [ 1 ] . '_' . $reg [ 2 ]; // This is unit price including discount
$fk_commandefourndet = " fk_commandefourndet_ " . $reg [ 1 ] . '_' . $reg [ 2 ];
$dispatchLines [ $numAsked ] = array ( 'prod' => GETPOST ( $prod , 'int' ), 'qty' => GETPOST ( $qty ), 'ent' => GETPOST ( $ent , 'int' ), 'pu' => GETPOST ( $pu ), 'comment' => GETPOST ( 'comment' ), 'fk_commandefourndet' => GETPOST ( $fk_commandefourndet , 'int' ));
}
2018-12-15 14:12:39 +01:00
2018-10-04 12:27:10 +02:00
// with batch module enabled
if ( preg_match ( '/^product_batch_([0-9]+)_([0-9]+)$/i' , $key , $reg ))
{
2018-12-15 14:12:39 +01:00
$numAsked ++ ;
2018-12-15 13:58:39 +01:00
2018-10-04 12:27:10 +02:00
// eat-by date dispatch
// $numline=$reg[2] + 1; // line of product
$numline = $numAsked ;
$prod = 'product_batch_' . $reg [ 1 ] . '_' . $reg [ 2 ];
$qty = 'qty_' . $reg [ 1 ] . '_' . $reg [ 2 ];
$ent = 'entrepot_' . $reg [ 1 ] . '_' . $reg [ 2 ];
$pu = 'pu_' . $reg [ 1 ] . '_' . $reg [ 2 ];
$lot = 'lot_number_' . $reg [ 1 ] . '_' . $reg [ 2 ];
$dDLUO = dol_mktime ( 12 , 0 , 0 , $_POST [ 'dluo_' . $reg [ 1 ] . '_' . $reg [ 2 ] . 'month' ], $_POST [ 'dluo_' . $reg [ 1 ] . '_' . $reg [ 2 ] . 'day' ], $_POST [ 'dluo_' . $reg [ 1 ] . '_' . $reg [ 2 ] . 'year' ]);
$dDLC = dol_mktime ( 12 , 0 , 0 , $_POST [ 'dlc_' . $reg [ 1 ] . '_' . $reg [ 2 ] . 'month' ], $_POST [ 'dlc_' . $reg [ 1 ] . '_' . $reg [ 2 ] . 'day' ], $_POST [ 'dlc_' . $reg [ 1 ] . '_' . $reg [ 2 ] . 'year' ]);
$fk_commandefourndet = 'fk_commandefourndet_' . $reg [ 1 ] . '_' . $reg [ 2 ];
$dispatchLines [ $numAsked ] = array ( 'prod' => GETPOST ( $prod , 'int' ), 'qty' => GETPOST ( $qty ), 'ent' => GETPOST ( $ent , 'int' ), 'pu' => GETPOST ( $pu ), 'comment' => GETPOST ( 'comment' ), 'fk_commandefourndet' => GETPOST ( $fk_commandefourndet , 'int' ), 'DLC' => $dDLC , 'DLUO' => $dDLUO , 'lot' => GETPOST ( $lot , 'alpha' ));
}
}
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
print ' < script type = " text/javascript " language = " javascript " >
jQuery ( document ) . ready ( function () {
jQuery ( " #autofill " ) . click ( function () { ' ;
2018-10-11 12:18:14 +02:00
$i = 1 ;
while ( $i <= $numAsked )
2018-10-03 12:22:41 +02:00
{
print 'jQuery("#qtyl' . $i . '").val(jQuery("#qtyasked' . $i . '").val() - jQuery("#qtydelivered' . $i . '").val());' . " \n " ;
$i ++ ;
}
print ' });
jQuery ( " #autoreset " ) . click ( function () { ' ;
2018-10-11 12:18:14 +02:00
$i = 1 ;
while ( $i <= $numAsked )
2018-10-03 12:22:41 +02:00
{
print 'jQuery("#qtyl' . $i . '").val(0);' . " \n " ;
$i ++ ;
}
print ' });
});
</ script > ' ;
print '<br>' ;
print '<table class="noborder" width="100%">' ;
2018-10-04 12:27:10 +02:00
// Load receptions already done for same order
$object -> loadReceptions ();
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
if ( $numAsked )
{
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " Description " ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " QtyOrdered " ) . '</td>' ;
2018-10-04 12:27:10 +02:00
print '<td align="center">' . $langs -> trans ( " QtyReceived " ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " QtyToReceive " );
2018-10-03 12:22:41 +02:00
if ( empty ( $conf -> productbatch -> enabled ))
{
print ' <br>(<a href="#" id="autofill">' . $langs -> trans ( " Fill " ) . '</a>' ;
print ' / <a href="#" id="autoreset">' . $langs -> trans ( " Reset " ) . '</a>)' ;
}
print '</td>' ;
if ( ! empty ( $conf -> stock -> enabled ))
{
2018-10-04 17:32:50 +02:00
print '<td align="left">' . $langs -> trans ( " Warehouse " ) . ' (' . $langs -> trans ( " Stock " ) . ')</td>' ;
2018-10-03 12:22:41 +02:00
}
2018-10-04 17:32:50 +02:00
if ( ! empty ( $conf -> productbatch -> enabled ))
{
print '<td align="left">' . $langs -> trans ( " batch_number " ) . '</td>' ;
print '<td align="left">' . $langs -> trans ( " EatByDate " ) . '</td>' ;
print '<td align="left">' . $langs -> trans ( " SellByDate " ) . '</td>' ;
}
2018-10-03 12:22:41 +02:00
print " </tr> \n " ;
}
$var = true ;
2018-10-04 17:32:50 +02:00
$indiceAsked = 1 ;
while ( $indiceAsked <= $numAsked )
2018-10-03 12:22:41 +02:00
{
$product = new Product ( $db );
2018-10-04 12:27:10 +02:00
foreach ( $object -> lines as $supplierLine ){
2018-10-04 17:32:50 +02:00
if ( $dispatchLines [ $indiceAsked ][ 'fk_commandefourndet' ] == $supplierLine -> id ){
2018-10-04 12:27:10 +02:00
$line = $supplierLine ;
break ;
}
}
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
// Show product and description
$type = $line -> product_type ? $line -> product_type : $line -> fk_product_type ;
// Try to enhance type detection using date_start and date_end for free lines where type
// was not saved.
if ( ! empty ( $line -> date_start )) $type = 1 ;
if ( ! empty ( $line -> date_end )) $type = 1 ;
print '<!-- line ' . $line -> rowid . ' for product -->' . " \n " ;
print '<tr class="oddeven">' . " \n " ;
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
// Product label
if ( $line -> fk_product > 0 ) // If predefined product
{
$product -> fetch ( $line -> fk_product );
$product -> load_stock ( 'warehouseopen' ); // Load all $product->stock_warehouse[idwarehouse]->detail_batch
//var_dump($product->stock_warehouse[1]);
print '<td>' ;
print '<a name="' . $line -> rowid . '"></a>' ; // ancre pour retourner sur la ligne
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
// Show product and description
$product_static -> type = $line -> fk_product_type ;
$product_static -> id = $line -> fk_product ;
$product_static -> ref = $line -> ref ;
$product_static -> status_batch = $line -> product_tobatch ;
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
$text = $product_static -> getNomUrl ( 1 );
$text .= ' - ' . ( ! empty ( $line -> label ) ? $line -> label : $line -> product_label );
$description = ( $conf -> global -> PRODUIT_DESC_IN_FORM ? '' : dol_htmlentitiesbr ( $line -> desc ));
print $form -> textwithtooltip ( $text , $description , 3 , '' , '' , $i );
// Show range
print_date_range ( $db -> jdate ( $line -> date_start ), $db -> jdate ( $line -> date_end ));
// Add description in form
if ( ! empty ( $conf -> global -> PRODUIT_DESC_IN_FORM ))
{
print ( $line -> desc && $line -> desc != $line -> product_label ) ? '<br>' . dol_htmlentitiesbr ( $line -> desc ) : '' ;
}
print '</td>' ;
}
else
{
print " <td> " ;
if ( $type == 1 ) $text = img_object ( $langs -> trans ( 'Service' ), 'service' );
else $text = img_object ( $langs -> trans ( 'Product' ), 'product' );
if ( ! empty ( $line -> label )) {
$text .= ' <strong>' . $line -> label . '</strong>' ;
print $form -> textwithtooltip ( $text , $line -> desc , 3 , '' , '' , $i );
} else {
print $text . ' ' . nl2br ( $line -> desc );
}
// Show range
print_date_range ( $db -> jdate ( $line -> date_start ), $db -> jdate ( $line -> date_end ));
print " </td> \n " ;
}
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
// Qty
2018-10-04 17:32:50 +02:00
print '<td align="center">' . $line -> qty ;
2018-10-11 12:18:14 +02:00
print '<input type="hidden" name="fk_commandefournisseurdet' . $indiceAsked . '" value=\'' . $line -> id . '\' />' ;
2018-10-16 12:05:28 +02:00
print '<textarea style="display:none;" name="comment' . $indiceAsked . '" >' . $line -> desc . '</textarea>' ;
print '<input name="qtyasked' . $indiceAsked . '" id="qtyasked' . $indiceAsked . '" type="hidden" value="' . $line -> qty . '">' ;
2018-10-03 12:22:41 +02:00
print '</td>' ;
$qtyProdCom = $line -> qty ;
2018-10-04 12:27:10 +02:00
// Qty already received
2018-10-03 12:22:41 +02:00
print '<td align="center">' ;
2018-12-15 13:58:39 +01:00
2018-10-04 17:32:50 +02:00
2018-10-04 12:27:10 +02:00
$quantityDelivered = $object -> receptions [ $line -> id ];
2018-10-03 12:22:41 +02:00
print $quantityDelivered ;
print '<input name="qtydelivered' . $indiceAsked . '" id="qtydelivered' . $indiceAsked . '" type="hidden" value="' . $quantityDelivered . '">' ;
print '</td>' ;
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
if ( $line -> product_type == 1 && empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES ))
{
$quantityToBeDelivered = 0 ;
}
else
{
2018-10-04 12:27:10 +02:00
$quantityToBeDelivered = $dispatchLines [ $indiceAsked ][ 'qty' ];
2018-10-03 12:22:41 +02:00
}
2018-10-04 17:32:50 +02:00
$warehouse_id = $dispatchLines [ $indiceAsked ][ 'ent' ];
2018-12-15 13:58:39 +01:00
2018-10-04 17:32:50 +02:00
2018-10-03 12:22:41 +02:00
$warehouseObject = null ;
2018-10-15 17:08:28 +02:00
if ( ! 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
2018-10-03 12:22:41 +02:00
{
print '<!-- Case warehouse already known or product not a predefined product -->' ;
2018-12-15 13:58:39 +01:00
2018-10-04 17:32:50 +02:00
$stock = + $product -> stock_warehouse [ $dispatchLines [ $indiceAsked ][ 'ent' ]] -> real ; // Convert to number
$deliverableQty = $dispatchLines [ $indiceAsked ][ 'qty' ];
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
// Quantity to send
print '<td align="center">' ;
if ( $line -> product_type == Product :: TYPE_PRODUCT || ! empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES ))
{
if ( GETPOST ( 'qtyl' . $indiceAsked , 'int' )) $defaultqty = GETPOST ( 'qtyl' . $indiceAsked , 'int' );
print '<input name="idl' . $indiceAsked . '" type="hidden" value="' . $line -> id . '">' ;
print '<input name="qtyl' . $indiceAsked . '" id="qtyl' . $indiceAsked . '" type="text" size="4" value="' . $deliverableQty . '">' ;
}
else print $langs -> trans ( " NA " );
print '</td>' ;
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
// Stock
if ( ! empty ( $conf -> stock -> enabled ))
{
print '<td align="left">' ;
if ( $line -> product_type == Product :: TYPE_PRODUCT || ! empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES )) // Type of product need stock change ?
{
// Show warehouse combo list
$ent = " entl " . $indiceAsked ;
$idl = " idl " . $indiceAsked ;
$tmpentrepot_id = is_numeric ( GETPOST ( $ent , 'int' )) ? GETPOST ( $ent , 'int' ) : $warehouse_id ;
if ( $line -> fk_product > 0 )
{
2018-12-15 15:43:30 +01:00
print '<!-- Show warehouse selection -->' ;
2018-12-15 18:30:35 +01:00
print $formproduct -> selectWarehouses ( $tmpentrepot_id , 'entl' . $indiceAsked , '' , 0 , 0 , $line -> fk_product , '' , 1 );
2018-10-03 12:22:41 +02:00
}
}
else
{
print $langs -> trans ( " Service " );
}
print '</td>' ;
}
2018-12-15 13:58:39 +01:00
2018-12-15 15:43:30 +01:00
if ( ! empty ( $conf -> productbatch -> enabled ))
{
2018-12-15 16:37:00 +01:00
if ( ! empty ( $product -> status_batch ))
{
2018-10-04 17:32:50 +02:00
print '<td><input name="batch' . $indiceAsked . '" value="' . $dispatchLines [ $indiceAsked ][ 'lot' ] . '"></td>' ;
print '<td>' ;
print $form -> select_date ( $dispatchLines [ $indiceAsked ][ 'DLC' ], 'dlc' . $indiceAsked , '' , '' , 1 , " " );
print '</td>' ;
print '<td>' ;
print $form -> select_date ( $dispatchLines [ $indiceAsked ][ 'DLUO' ], 'dluo' . $indiceAsked , '' , '' , 1 , " " );
print '</td>' ;
2018-12-15 16:37:00 +01:00
}
else {
2018-10-04 17:32:50 +02:00
print '<td colspan="3"></td>' ;
}
}
2018-10-03 12:22:41 +02:00
print " </tr> \n " ;
}
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
//Display lines extrafields
if ( is_array ( $extralabelslines ) && count ( $extralabelslines ) > 0 )
{
$colspan = 5 ;
2018-10-04 17:32:50 +02:00
if ( $conf -> productbatch -> enabled ) $colspan += 3 ;
2018-10-03 12:22:41 +02:00
$orderLineExtrafields = new Extrafields ( $db );
$orderLineExtrafieldLabels = $orderLineExtrafields -> fetch_name_optionals_label ( $object -> table_element_line );
2018-10-04 17:32:50 +02:00
$srcLine = new CommandeFournisseurLigne ( $db );
2018-10-03 12:22:41 +02:00
$srcLine -> fetch_optionals ( $line -> id , $orderLineExtrafieldLabels ); // fetch extrafields also available in orderline
2018-10-04 17:32:50 +02:00
$line = new CommandeFournisseurDispatch ( $db );
2018-10-03 12:22:41 +02:00
$line -> fetch_optionals ( $object -> id , $extralabelslines );
$line -> array_options = array_merge ( $line -> array_options , $srcLine -> array_options );
print '<tr class="oddeven">' ;
print $line -> showOptionals ( $extrafieldsline , 'edit' , array ( 'style' => $bc [ $var ], 'colspan' => $colspan ), $indiceAsked );
print '</tr>' ;
}
$indiceAsked ++ ;
}
print " </table> " ;
print '<br>' ;
print '<div class="center">' ;
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
print '</div>' ;
print '</form>' ;
print '<br>' ;
}
else
{
dol_print_error ( $db );
}
}
}
else if ( $id || $ref )
/* *************************************************************************** */
/* */
/* Edit and view mode */
/* */
/* *************************************************************************** */
{
$lines = $object -> lines ;
$num_prod = count ( $lines );
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
if ( $object -> id > 0 )
{
if ( ! empty ( $object -> origin ) && $object -> origin_id > 0 )
{
2018-10-05 16:21:50 +02:00
$object -> origin = 'CommandeFournisseur' ;
2018-10-03 12:22:41 +02:00
$typeobject = $object -> origin ;
$origin = $object -> origin ;
$origin_id = $object -> origin_id ;
$object -> fetch_origin (); // Load property $object->commande, $object->propal, ...
}
$soc = new Societe ( $db );
$soc -> fetch ( $object -> socid );
$res = $object -> fetch_optionals ( $object -> id , $extralabels );
2018-12-15 13:58:39 +01:00
2018-10-04 12:27:10 +02:00
$head = reception_prepare_head ( $object );
dol_fiche_head ( $head , 'reception' , $langs -> trans ( " Reception " ), - 1 , 'reception' );
2018-10-03 12:22:41 +02:00
$formconfirm = '' ;
// Confirm deleteion
if ( $action == 'delete' )
{
2018-10-04 12:27:10 +02:00
$formconfirm = $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $langs -> trans ( 'DeleteReception' ), $langs -> trans ( " ConfirmDeleteReception " , $object -> ref ), 'confirm_delete' , '' , 0 , 1 );
2018-10-03 12:22:41 +02:00
}
// Confirmation validation
if ( $action == 'valid' )
{
$objectref = substr ( $object -> ref , 1 , 4 );
if ( $objectref == 'PROV' )
{
$numref = $object -> getNextNumRef ( $soc );
}
else
{
$numref = $object -> ref ;
}
2018-10-04 12:27:10 +02:00
$text = $langs -> trans ( " ConfirmValidateReception " , $numref );
2018-10-03 12:22:41 +02:00
if ( ! empty ( $conf -> notification -> enabled ))
{
require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php' ;
$notify = new Notify ( $db );
$text .= '<br>' ;
2018-10-04 12:27:10 +02:00
$text .= $notify -> confirmMessage ( 'RECEPTION_VALIDATE' , $object -> socid , $object );
2018-10-03 12:22:41 +02:00
}
2018-10-04 12:27:10 +02:00
$formconfirm = $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $langs -> trans ( 'ValidateReception' ), $text , 'confirm_valid' , '' , 0 , 1 );
2018-10-03 12:22:41 +02:00
}
2018-12-15 15:43:30 +01:00
2018-10-03 12:22:41 +02:00
// Confirm cancelation
if ( $action == 'annuler' )
{
2018-10-04 12:27:10 +02:00
$formconfirm = $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $langs -> trans ( 'CancelReception' ), $langs -> trans ( " ConfirmCancelReception " , $object -> ref ), 'confirm_cancel' , '' , 0 , 1 );
2018-10-03 12:22:41 +02:00
}
if ( ! $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 ;
}
// Print form confirm
print $formconfirm ;
// Calculate totalWeight and totalVolume for all products
// by adding weight and volume of each product line.
$tmparray = $object -> getTotalWeightVolume ();
$totalWeight = $tmparray [ 'weight' ];
$totalVolume = $tmparray [ 'volume' ];
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 );
}
2018-10-05 16:21:50 +02:00
if ( $typeobject == 'CommandeFournisseur' && $object -> $typeobject -> id && ! empty ( $conf -> fournisseur -> enabled ))
{
$objectsrc = new CommandeFournisseur ( $db );
$objectsrc -> fetch ( $object -> $typeobject -> id );
}
2018-10-04 12:27:10 +02:00
// Reception card
$linkback = '<a href="' . DOL_URL_ROOT . '/reception/list.php?restore_lastsearch_values=1' . ( ! empty ( $socid ) ? '&socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2018-10-03 12:22:41 +02:00
$morehtmlref = '<div class="refidno">' ;
2018-10-04 12:27:10 +02:00
// Ref customer reception
2018-12-15 13:58:39 +01:00
2018-10-05 16:21:50 +02:00
$morehtmlref .= $form -> editfieldkey ( " RefSupplier " , 'ref_supplier' , $object -> ref_supplier , $object , $user -> rights -> reception -> creer , 'string' , '' , 0 , 1 );
$morehtmlref .= $form -> editfieldval ( " RefSupplier " , 'ref_supplier' , $object -> ref_supplier , $object , $user -> rights -> reception -> creer , 'string' , '' , null , null , '' , 1 );
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
// Thirdparty
$morehtmlref .= '<br>' . $langs -> trans ( 'ThirdParty' ) . ' : ' . $object -> thirdparty -> getNomUrl ( 1 );
// Project
2018-12-15 15:43:30 +01:00
if ( ! empty ( $conf -> projet -> enabled ))
{
2018-10-03 12:22:41 +02:00
$langs -> load ( " projects " );
$morehtmlref .= '<br>' . $langs -> trans ( 'Project' ) . ' ' ;
2018-10-04 12:27:10 +02:00
if ( 0 ) { // Do not change on reception
2018-10-03 12:22:41 +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 {
2018-10-04 12:27:10 +02:00
// We don't have project on reception, so we will use the project or source object instead
// TODO Add project on reception
2018-10-03 12:22:41 +02:00
$morehtmlref .= ' : ' ;
if ( ! empty ( $objectsrc -> fk_project )) {
$proj = new Project ( $db );
$proj -> fetch ( $objectsrc -> fk_project );
$morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $objectsrc -> fk_project . '" title="' . $langs -> trans ( 'ShowProject' ) . '">' ;
$morehtmlref .= $proj -> ref ;
$morehtmlref .= '</a>' ;
} else {
$morehtmlref .= '' ;
}
}
}
$morehtmlref .= '</div>' ;
2018-10-05 16:21:50 +02:00
$object -> picto = 'sending' ;
2018-10-03 12:22:41 +02:00
dol_banner_tab ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' , $morehtmlref );
print '<div class="fichecenter">' ;
print '<div class="fichehalfleft">' ;
print '<div class="underbanner clearboth"></div>' ;
print '<table class="border" width="100%">' ;
// 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">' ;
2018-10-04 12:27:10 +02:00
print $objectsrc -> getNomUrl ( 1 , 'reception' );
2018-10-03 12:22:41 +02:00
print " </td> \n " ;
print '</tr>' ;
}
2018-10-05 16:21:50 +02:00
if ( $typeobject == 'CommandeFournisseur' && $object -> $typeobject -> id && ! empty ( $conf -> propal -> enabled ))
{
print '<tr><td>' ;
print $langs -> trans ( " RefSupplierOrder " ) . '</td>' ;
print '<td colspan="3">' ;
print $objectsrc -> getNomUrl ( 1 , 'reception' );
print " </td> \n " ;
print '</tr>' ;
}
2018-10-03 12:22:41 +02:00
// Date creation
print '<tr><td class="titlefield">' . $langs -> trans ( " DateCreation " ) . '</td>' ;
print '<td colspan="3">' . dol_print_date ( $object -> date_creation , " dayhour " ) . " </td> \n " ;
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">' ;
print $form -> select_date ( $object -> date_delivery ? $object -> date_delivery :- 1 , 'liv_' , 1 , 1 , '' , " setdate_livraison " , 1 , 0 , 1 );
print '<input type="submit" class="button" value="' . $langs -> trans ( 'Modify' ) . '">' ;
print '</form>' ;
}
else
{
print $object -> date_delivery ? dol_print_date ( $object -> date_delivery , 'dayhour' ) : ' ' ;
}
print '</td>' ;
print '</tr>' ;
// Weight
print '<tr><td>' ;
2018-10-04 12:27:10 +02:00
print $form -> editfieldkey ( " Weight " , 'trueWeight' , $object -> trueWeight , $object , $user -> rights -> reception -> creer );
2018-10-03 12:22:41 +02:00
print '</td><td colspan="3">' ;
if ( $action == 'edittrueWeight' )
{
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>' ;
}
else
{
print $object -> trueWeight ;
print ( $object -> trueWeight && $object -> weight_units != '' ) ? ' ' . measuring_units_string ( $object -> weight_units , " weight " ) : '' ;
}
// Calculated
if ( $totalWeight > 0 )
{
if ( ! empty ( $object -> trueWeight )) print ' (' . $langs -> trans ( " SumOfProductWeights " ) . ': ' ;
//print $totalWeight.' '.measuring_units_string(0,"weight");
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' );
//if (empty($object->trueWeight)) print ' ('.$langs->trans("Calculated").')';
if ( ! empty ( $object -> trueWeight )) print ')' ;
}
print '</td></tr>' ;
// Width
2018-10-04 12:27:10 +02:00
print '<tr><td>' . $form -> editfieldkey ( " Width " , 'trueWidth' , $object -> trueWidth , $object , $user -> rights -> reception -> creer ) . '</td><td colspan="3">' ;
print $form -> editfieldval ( " Width " , 'trueWidth' , $object -> trueWidth , $object , $user -> rights -> reception -> creer );
2018-10-03 12:22:41 +02:00
print ( $object -> trueWidth && $object -> width_units != '' ) ? ' ' . measuring_units_string ( $object -> width_units , " size " ) : '' ;
print '</td></tr>' ;
// Height
2018-10-04 12:27:10 +02:00
print '<tr><td>' . $form -> editfieldkey ( " Height " , 'trueHeight' , $object -> trueHeight , $object , $user -> rights -> reception -> creer ) . '</td><td colspan="3">' ;
2018-10-03 12:22:41 +02:00
if ( $action == 'edittrueHeight' )
{
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>' ;
}
else
{
print $object -> trueHeight ;
print ( $object -> trueHeight && $object -> height_units != '' ) ? ' ' . measuring_units_string ( $object -> height_units , " size " ) : '' ;
}
print '</td></tr>' ;
// Depth
2018-10-04 12:27:10 +02:00
print '<tr><td>' . $form -> editfieldkey ( " Depth " , 'trueDepth' , $object -> trueDepth , $object , $user -> rights -> reception -> creer ) . '</td><td colspan="3">' ;
print $form -> editfieldval ( " Depth " , 'trueDepth' , $object -> trueDepth , $object , $user -> rights -> reception -> creer );
2018-10-03 12:22:41 +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 ;
$volumeUnit = 0 ;
if ( $object -> trueWidth && $object -> trueHeight && $object -> trueDepth )
{
$calculatedVolume = ( $object -> trueWidth * $object -> trueHeight * $object -> trueDepth );
$volumeUnit = $object -> size_units * 3 ;
}
2018-10-04 12:27:10 +02:00
// If reception volume not defined we use sum of products
2018-10-03 12:22:41 +02:00
if ( $calculatedVolume > 0 )
{
if ( $volumeUnit < 50 )
{
//print $calculatedVolume.' '.measuring_units_string($volumeUnit,"volume");
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' );
}
else print $calculatedVolume . ' ' . measuring_units_string ( $volumeUnit , " volume " );
}
if ( $totalVolume > 0 )
{
if ( $calculatedVolume ) print ' (' . $langs -> trans ( " SumOfProductVolumes " ) . ': ' ;
//print $totalVolume.' '.measuring_units_string(0,"volume");
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' );
//if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')';
if ( $calculatedVolume ) print ')' ;
}
print " </td> \n " ;
print '</tr>' ;
// Other attributes
$cols = 2 ;
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php' ;
print '</table>' ;
print '</div>' ;
print '<div class="fichehalfright">' ;
print '<div class="ficheaddleft">' ;
print '<div class="underbanner clearboth"></div>' ;
print '<table class="border centpercent">' ;
2018-10-04 12:27:10 +02:00
// Reception method
2018-10-03 12:22:41 +02:00
print '<tr><td height="10">' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
2018-10-15 17:08:28 +02:00
print $langs -> trans ( 'ReceptionMethod' );
2018-10-03 12:22:41 +02:00
print '</td>' ;
2018-10-05 16:21:50 +02:00
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 ( 'SetReceptionMethod' ), 1 ) . '</a></td>' ;
2018-10-03 12:22:41 +02:00
print '</tr></table>' ;
print '</td><td colspan="2">' ;
2018-10-05 16:21:50 +02:00
if ( $action == 'editshipping_method_id' )
2018-10-03 12:22:41 +02:00
{
2018-10-05 16:21:50 +02:00
print '<form name="setshipping_method_id" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="post">' ;
2018-10-03 12:22:41 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2018-10-05 16:21:50 +02:00
print '<input type="hidden" name="action" value="setshipping_method_id">' ;
2018-10-03 12:22:41 +02:00
$object -> fetch_delivery_methods ();
2018-10-05 16:21:50 +02:00
print $form -> selectarray ( " shipping_method_id " , $object -> meths , $object -> shipping_method_id , 1 , 0 , 0 , " " , 1 );
2018-10-03 12:22:41 +02:00
if ( $user -> admin ) print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
print '<input type="submit" class="button" value="' . $langs -> trans ( 'Modify' ) . '">' ;
print '</form>' ;
}
else
{
2018-10-05 16:21:50 +02:00
if ( $object -> shipping_method_id > 0 )
2018-10-03 12:22:41 +02:00
{
// Get code using getLabelFromKey
2018-10-05 16:21:50 +02:00
$code = $langs -> getLabelFromKey ( $db , $object -> shipping_method_id , 'c_shipment_mode' , 'rowid' , 'code' );
print $langs -> trans ( " SendingMethod " . strtoupper ( $code ));
2018-10-03 12:22:41 +02:00
}
}
print '</td>' ;
print '</tr>' ;
// Tracking Number
2018-12-15 13:58:39 +01:00
2018-10-04 12:27:10 +02:00
print '<tr><td class="titlefield">' . $form -> editfieldkey ( " TrackingNumber " , 'tracking_number' , $object -> tracking_number , $object , $user -> rights -> reception -> creer ) . '</td><td colspan="3">' ;
print $form -> editfieldval ( " TrackingNumber " , 'tracking_number' , $object -> tracking_url , $object , $user -> rights -> reception -> creer , 'string' , $object -> tracking_number );
2018-10-03 12:22:41 +02:00
print '</td></tr>' ;
// Incoterms
if ( ! empty ( $conf -> incoterm -> enabled ))
{
print '<tr><td>' ;
print '<table width="100%" class="nobordernopadding"><tr><td>' ;
print $langs -> trans ( 'IncotermLabel' );
print '<td><td align="right">' ;
2018-10-04 12:27:10 +02:00
if ( $user -> rights -> reception -> creer ) print '<a href="' . DOL_URL_ROOT . '/reception/card.php?id=' . $object -> id . '&action=editincoterm">' . img_edit () . '</a>' ;
2018-10-03 12:22:41 +02:00
else print ' ' ;
print '</td></tr></table>' ;
print '</td>' ;
print '<td colspan="3">' ;
if ( $action != 'editincoterm' )
{
print $form -> textwithpicto ( $object -> display_incoterms (), $object -> libelle_incoterms , 1 );
}
else
{
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>' ;
}
print " </table> " ;
print '</div>' ;
print '</div>' ;
print '</div>' ;
print '<div class="clearboth"></div>' ;
// Lines of products
if ( $action == 'editline' )
{
2018-12-15 16:37:00 +01:00
print '<form name="updateline" id="updateline" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&lineid=' . $line_id . ' " method= " POST " >
2018-10-03 12:22:41 +02:00
< input type = " hidden " name = " token " value = " ' . $_SESSION ['newtoken'] . ' " >
< input type = " hidden " name = " action " value = " updateline " >
< input type = " hidden " name = " mode " value = " " >
2018-12-15 16:37:00 +01:00
< input type = " hidden " name = " id " value = " ' . $object->id . ' " > ' ;
2018-10-03 12:22:41 +02:00
}
print '<br>' ;
2018-12-15 16:37:00 +01:00
print '<div class="div-table-responsive-no-min">' ;
2018-10-03 12:22:41 +02:00
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
// #
if ( ! empty ( $conf -> global -> MAIN_VIEW_LINE_NUMBER ))
{
print '<td width="5" align="center"> </td>' ;
}
// Product/Service
print '<td>' . $langs -> trans ( " Products " ) . '</td>' ;
2018-10-15 17:08:28 +02:00
// Comment
2018-10-16 12:05:28 +02:00
print '<td>' . $langs -> trans ( " Description " ) . '</td>' ;
2018-10-03 12:22:41 +02:00
// Qty
print '<td align="center">' . $langs -> trans ( " QtyOrdered " ) . '</td>' ;
if ( $origin && $origin_id > 0 )
{
2018-10-04 12:27:10 +02:00
print '<td align="center">' . $langs -> trans ( " QtyInOtherReceptions " ) . '</td>' ;
2018-10-03 12:22:41 +02:00
}
if ( $action == 'editline' )
{
$editColspan = 3 ;
if ( empty ( $conf -> stock -> enabled )) $editColspan -- ;
if ( empty ( $conf -> productbatch -> enabled )) $editColspan -- ;
print '<td align="center" colspan="' . $editColspan . '">' ;
if ( $object -> statut <= 1 )
{
2018-10-04 12:27:10 +02:00
print $langs -> trans ( " QtyToReceive " ) . ' - ' ;
2018-10-03 12:22:41 +02:00
}
else
{
2018-10-04 12:27:10 +02:00
print $langs -> trans ( " QtyReceived " ) . ' - ' ;
2018-10-03 12:22:41 +02:00
}
if ( ! empty ( $conf -> stock -> enabled ))
{
print $langs -> trans ( " WarehouseSource " ) . ' - ' ;
}
if ( ! empty ( $conf -> productbatch -> enabled ))
{
print $langs -> trans ( " Batch " );
}
print '</td>' ;
}
else
{
if ( $object -> statut <= 1 )
{
2018-10-04 12:27:10 +02:00
print '<td align="center">' . $langs -> trans ( " QtyToReceive " ) . '</td>' ;
2018-10-03 12:22:41 +02:00
}
else
{
2018-10-04 12:27:10 +02:00
print '<td align="center">' . $langs -> trans ( " QtyReceived " ) . '</td>' ;
2018-10-03 12:22:41 +02:00
}
if ( ! empty ( $conf -> stock -> enabled ))
{
print '<td align="left">' . $langs -> trans ( " WarehouseSource " ) . '</td>' ;
}
if ( ! empty ( $conf -> productbatch -> enabled ))
{
print '<td align="left">' . $langs -> trans ( " Batch " ) . '</td>' ;
}
}
print '<td align="center">' . $langs -> trans ( " CalculatedWeight " ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " CalculatedVolume " ) . '</td>' ;
//print '<td align="center">'.$langs->trans("Size").'</td>';
if ( $object -> statut == 0 )
{
print '<td class="linecoledit"></td>' ;
print '<td class="linecoldelete" width="10"></td>' ;
}
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 = '' ;
if ( empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) $newlang = GETPOST ( 'lang_id' , 'aZ09' );
if ( empty ( $newlang )) $newlang = $object -> thirdparty -> default_lang ;
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
}
// Get list of products already sent for same source object into $alreadysent
$alreadysent = array ();
2018-12-15 13:58:39 +01:00
2018-10-05 16:40:43 +02:00
$origin = 'commande_fournisseur' ;
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
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 " ;
2018-10-05 16:40:43 +02:00
$sql .= " , ed.rowid as receptionline_id, ed.qty, ed.fk_reception as reception_id, ed.fk_entrepot " ;
2018-10-04 12:27:10 +02:00
$sql .= " , e.rowid as reception_id, e.ref as reception_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_reception " ;
2018-10-03 12:22:41 +02:00
//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' ;
2018-10-05 16:40:43 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " commande_fournisseur_dispatch as ed " ;
2018-10-04 12:27:10 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " reception as e " ;
2018-10-03 12:22:41 +02:00
$sql .= " , " . MAIN_DB_PREFIX . $origin . " det as obj " ;
2018-10-04 12:27:10 +02:00
//if ($conf->livraison_bon->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_reception = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."livraisondet as ld ON ld.fk_livraison = l.rowid AND obj.rowid = ld.fk_origin_line";
2018-10-03 12:22:41 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product as p ON obj.fk_product = p.rowid " ;
2018-10-04 12:27:10 +02:00
$sql .= " WHERE e.entity IN ( " . getEntity ( 'reception' ) . " ) " ;
2018-10-05 16:40:43 +02:00
$sql .= " AND obj.fk_commande = " . $origin_id ;
$sql .= " AND obj.rowid = ed.fk_commandefourndet " ;
2018-10-04 12:27:10 +02:00
$sql .= " AND ed.fk_reception = e.rowid " ;
2018-10-10 12:19:57 +02:00
$sql .= " AND ed.fk_reception != " . $object -> id ;
2018-10-03 12:22:41 +02:00
//if ($filter) $sql.= $filter;
$sql .= " ORDER BY obj.fk_product " ;
2018-12-15 13:58:39 +01:00
2018-10-04 12:27:10 +02:00
dol_syslog ( " get list of reception lines " , LOG_DEBUG );
2018-10-03 12:22:41 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
if ( $obj )
{
// $obj->rowid is rowid in $origin."det" table
2018-10-08 16:54:33 +02:00
$alreadysent [ $obj -> rowid ][ $obj -> receptionline_id ] = array ( 'reception_ref' => $obj -> reception_ref , 'reception_id' => $obj -> reception_id , 'warehouse' => $obj -> fk_entrepot , 'qty' => $obj -> qty , 'date_valid' => $obj -> date_valid , 'date_delivery' => $obj -> date_delivery );
2018-10-03 12:22:41 +02:00
}
$i ++ ;
}
}
//var_dump($alreadysent);
}
// Loop on each product to send/sent
for ( $i = 0 ; $i < $num_prod ; $i ++ )
{
print '<!-- origin line id = ' . $lines [ $i ] -> origin_line_id . ' -->' ; // id of order line
print '<tr class="oddeven">' ;
// #
if ( ! empty ( $conf -> global -> MAIN_VIEW_LINE_NUMBER ))
{
print '<td align="center">' . ( $i + 1 ) . '</td>' ;
}
// 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 );
2018-10-08 16:54:33 +02:00
$label = ( ! empty ( $prod -> multilangs [ $outputlangs -> defaultlang ][ " label " ])) ? $prod -> multilangs [ $outputlangs -> defaultlang ][ " label " ] : $lines [ $i ] -> product -> label ;
2018-10-03 12:22:41 +02:00
}
else
2018-10-08 12:15:17 +02:00
$label = ( ! empty ( $lines [ $i ] -> product -> label ) ? $lines [ $i ] -> product -> label : $lines [ $i ] -> product -> product_label );
2018-10-03 12:22:41 +02:00
print '<td>' ;
2018-12-15 13:58:39 +01:00
2018-10-08 16:54:33 +02:00
$text = $lines [ $i ] -> product -> getNomUrl ( 1 );
2018-10-03 12:22:41 +02:00
$text .= ' - ' . $label ;
2018-10-08 12:15:17 +02:00
$description = ( ! empty ( $conf -> global -> PRODUIT_DESC_IN_FORM ) ? '' : dol_htmlentitiesbr ( $lines [ $i ] -> product -> description ));
2018-10-03 12:22:41 +02:00
print $form -> textwithtooltip ( $text , $description , 3 , '' , '' , $i );
print_date_range ( $lines [ $i ] -> date_start , $lines [ $i ] -> date_end );
if ( ! empty ( $conf -> global -> PRODUIT_DESC_IN_FORM ))
{
2018-10-08 12:15:17 +02:00
print ( ! empty ( $lines [ $i ] -> product -> description ) && $lines [ $i ] -> description != $lines [ $i ] -> product -> description ) ? '<br>' . dol_htmlentitiesbr ( $lines [ $i ] -> description ) : '' ;
2018-10-03 12:22:41 +02:00
}
print " </td> \n " ;
}
else
{
print " <td> " ;
if ( $lines [ $i ] -> product_type == Product :: TYPE_SERVICE ) $text = img_object ( $langs -> trans ( 'Service' ), 'service' );
else $text = img_object ( $langs -> trans ( 'Product' ), 'product' );
if ( ! empty ( $lines [ $i ] -> label )) {
$text .= ' <strong>' . $lines [ $i ] -> label . '</strong>' ;
print $form -> textwithtooltip ( $text , $lines [ $i ] -> description , 3 , '' , '' , $i );
} else {
print $text . ' ' . nl2br ( $lines [ $i ] -> description );
}
print_date_range ( $lines [ $i ] -> date_start , $lines [ $i ] -> date_end );
print " </td> \n " ;
}
2018-12-15 13:58:39 +01:00
2018-10-15 17:08:28 +02:00
if ( $action == 'editline' && $lines [ $i ] -> id == $line_id )
{
print '<td ><textarea name="comment' . $line_id . '" id="comment' . $line_id . '" /> ' . $lines [ $i ] -> comment . '</textarea></td>' ;
}
else
{
2018-10-17 15:36:47 +02:00
print '<td style="white-space: pre-wrap;max-width: 200px;" >' . $lines [ $i ] -> comment . '</td>' ;
2018-10-15 17:08:28 +02:00
}
2018-10-03 12:22:41 +02:00
// Qty ordered
print '<td align="center">' . $lines [ $i ] -> qty_asked . '</td>' ;
2018-10-04 12:27:10 +02:00
// Qty in other receptions (with reception and warehouse used)
2018-10-03 12:22:41 +02:00
if ( $origin && $origin_id > 0 )
{
print '<td align="center" class="nowrap">' ;
foreach ( $alreadysent as $key => $val )
{
2018-10-08 12:15:17 +02:00
if ( $lines [ $i ] -> fk_commandefourndet == $key )
2018-10-03 12:22:41 +02:00
{
$j = 0 ;
2018-10-04 12:27:10 +02:00
foreach ( $val as $receptionline_id => $receptionline_var )
2018-10-03 12:22:41 +02:00
{
2018-10-04 12:27:10 +02:00
if ( $receptionline_var [ 'reception_id' ] == $lines [ $i ] -> fk_reception ) continue ; // We want to show only "other receptions"
2018-10-03 12:22:41 +02:00
$j ++ ;
if ( $j > 1 ) print '<br>' ;
2018-10-04 12:27:10 +02:00
$reception_static -> fetch ( $receptionline_var [ 'reception_id' ]);
print $reception_static -> getNomUrl ( 1 );
2018-10-08 16:54:33 +02:00
print ' - ' . $receptionline_var [ 'qty' ];
2018-12-15 13:58:39 +01:00
2018-10-04 12:27:10 +02:00
$htmltext = $langs -> trans ( " DateValidation " ) . ' : ' . ( empty ( $receptionline_var [ 'date_valid' ]) ? $langs -> trans ( " Draft " ) : dol_print_date ( $receptionline_var [ 'date_valid' ], 'dayhour' ));
if ( ! empty ( $conf -> stock -> enabled ) && $receptionline_var [ 'warehouse' ] > 0 )
2018-10-03 12:22:41 +02:00
{
2018-10-04 12:27:10 +02:00
$warehousestatic -> fetch ( $receptionline_var [ 'warehouse' ]);
2018-10-03 12:22:41 +02:00
$htmltext .= '<br>' . $langs -> trans ( " From " ) . ' : ' . $warehousestatic -> getNomUrl ( 1 );
}
print ' ' . $form -> textwithpicto ( '' , $htmltext , 1 );
}
}
}
}
print '</td>' ;
if ( $action == 'editline' && $lines [ $i ] -> id == $line_id )
{
// edit mode
print '<td colspan="' . $editColspan . '" align="center"><table class="nobordernopadding">' ;
2018-12-15 15:43:30 +01:00
if ( ! empty ( $conf -> stock -> enabled ))
2018-10-03 12:22:41 +02:00
{
if ( $lines [ $i ] -> fk_product > 0 )
{
2018-12-15 15:01:49 +01:00
print '<!-- case edit 1 -->' ;
print '<tr>' ;
// Qty to receive or received
print '<td>' . '<input name="qtyl' . $line_id . '" id="qtyl' . $line_id . '" type="text" size="4" value="' . $lines [ $i ] -> qty . '">' . '</td>' ;
// Warehouse source
print '<td>' . $formproduct -> selectWarehouses ( $lines [ $i ] -> fk_entrepot , 'entl' . $line_id , '' , 1 , 0 , $lines [ $i ] -> fk_product , '' , 1 ) . '</td>' ;
// Batch number managment
2018-12-15 15:43:30 +01:00
if ( $conf -> productbatch -> enabled && ! empty ( $lines [ $i ] -> product -> status_batch ))
{
2018-12-15 15:01:49 +01:00
print '<td> <input name="batch' . $line_id . '" id="batch' . $line_id . '" type="text" value="' . $lines [ $i ] -> batch . '"> </br>' ;
print $langs -> trans ( 'EatByDate' ) . ' : ' ;
2018-12-15 18:30:35 +01:00
print $form -> select_date ( $lines [ $i ] -> eatby , 'dlc' . $line_id , '' , '' , 1 , " " ) . '</br>' ;
2018-12-15 15:01:49 +01:00
print $langs -> trans ( 'SellByDate' ) . ' : ' ;
2018-12-15 18:30:35 +01:00
print $form -> select_date ( $lines [ $i ] -> sellby , 'dluo' . $line_id , '' , '' , 1 , " " );
2018-12-15 15:01:49 +01:00
print '</td>' ;
}
print '</tr>' ;
2018-10-03 12:22:41 +02:00
}
else
{
2018-10-08 12:15:17 +02:00
print '<!-- case edit 2 -->' ;
2018-10-03 12:22:41 +02:00
print '<tr>' ;
2018-10-18 15:11:43 +02:00
// Qty to receive or received
2018-10-08 16:54:33 +02:00
print '<td>' . '<input name="qtyl' . $line_id . '" id="qtyl' . $line_id . '" type="text" size="4" value="' . $lines [ $i ] -> qty . '">' . '</td>' ;
2018-10-03 12:22:41 +02:00
// Warehouse source
print '<td>' . '</td>' ;
// Batch number managment
print '<td>' . '</td>' ;
print '</tr>' ;
}
}
print '</table></td>' ;
}
else
{
2018-10-18 15:11:43 +02:00
// Qty to receive or received
2018-10-08 12:15:17 +02:00
print '<td align="center">' . $lines [ $i ] -> qty . '</td>' ;
2018-10-03 12:22:41 +02:00
// Warehouse source
if ( ! empty ( $conf -> stock -> enabled ))
{
print '<td align="left">' ;
2018-12-15 13:58:39 +01:00
2018-10-08 12:15:17 +02:00
if ( $lines [ $i ] -> fk_entrepot > 0 )
2018-10-03 12:22:41 +02:00
{
$entrepot = new Entrepot ( $db );
2018-10-08 12:15:17 +02:00
$entrepot -> fetch ( $lines [ $i ] -> fk_entrepot );
2018-10-03 12:22:41 +02:00
print $entrepot -> getNomUrl ( 1 );
}
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
print '</td>' ;
}
// Batch number managment
if ( ! empty ( $conf -> productbatch -> enabled ))
{
2018-10-08 12:15:17 +02:00
if ( isset ( $lines [ $i ] -> batch ))
2018-10-03 12:22:41 +02:00
{
print '<!-- Detail of lot -->' ;
print '<td>' ;
2018-10-08 12:15:17 +02:00
$detail = '' ;
if ( $lines [ $i ] -> product -> status_batch )
2018-10-03 12:22:41 +02:00
{
2018-10-08 12:15:17 +02:00
$detail .= $langs -> trans ( " Batch " ) . ': ' . $lines [ $i ] -> batch ;
$detail .= ' - ' . $langs -> trans ( " SellByDate " ) . ': ' . dol_print_date ( $lines [ $i ] -> sellby , " day " );
$detail .= ' - ' . $langs -> trans ( " EatByDate " ) . ': ' . dol_print_date ( $lines [ $i ] -> eatby , " day " );
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
$detail .= '<br>' ;
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
print $form -> textwithtooltip ( img_picto ( '' , 'object_barcode' ) . ' ' . $langs -> trans ( " DetailBatchNumber " ), $detail );
}
else
{
print $langs -> trans ( " NA " );
}
print '</td>' ;
} else {
print '<td></td>' ;
}
}
}
// Weight
print '<td align="center">' ;
2018-10-08 12:15:17 +02:00
if ( $lines [ $i ] -> fk_product_type == Product :: TYPE_PRODUCT ) print $lines [ $i ] -> product -> weight * $lines [ $i ] -> qty . ' ' . measuring_units_string ( $lines [ $i ] -> product -> weight_units , " weight " );
2018-10-03 12:22:41 +02:00
else print ' ' ;
print '</td>' ;
// Volume
print '<td align="center">' ;
2018-10-08 12:15:17 +02:00
if ( $lines [ $i ] -> fk_product_type == Product :: TYPE_PRODUCT ) print $lines [ $i ] -> product -> volume * $lines [ $i ] -> qty . ' ' . measuring_units_string ( $lines [ $i ] -> product -> volume_units , " volume " );
2018-10-03 12:22:41 +02:00
else print ' ' ;
print '</td>' ;
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
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 ;
}
}
print " </tr> " ;
// Display lines extrafields
if ( is_array ( $extralabelslines ) && count ( $extralabelslines ) > 0 ) {
2018-10-08 16:54:33 +02:00
$colspan = empty ( $conf -> productbatch -> enabled ) ? 8 : 9 ;
2018-10-05 16:21:50 +02:00
$line = new CommandeFournisseurDispatch ( $db );
2018-10-03 12:22:41 +02:00
$line -> fetch_optionals ( $lines [ $i ] -> id , $extralabelslines );
print '<tr class="oddeven">' ;
if ( $action == 'editline' && $lines [ $i ] -> id == $line_id )
{
print $line -> showOptionals ( $extrafieldsline , 'edit' , array ( 'style' => $bc [ $var ], 'colspan' => $colspan ), $indiceAsked );
}
else
{
print $line -> showOptionals ( $extrafieldsline , 'view' , array ( 'style' => $bc [ $var ], 'colspan' => $colspan ), $indiceAsked );
}
print '</tr>' ;
}
}
// TODO Show also lines ordered but not delivered
print " </table> \n " ;
print '</div>' ;
}
dol_fiche_end ();
$object -> fetchObjectLinked ( $object -> id , $object -> element );
/*
* Boutons actions
*/
if (( $user -> societe_id == 0 ) && ( $action != 'presend' ))
{
print '<div class="tabsAction">' ;
$parameters = array ();
2018-12-15 15:01:49 +01:00
$reshook = $hookmanager -> executeHooks ( 'addMoreActionsButtons' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2018-10-03 12:22:41 +02:00
if ( empty ( $reshook ))
{
2018-10-04 12:27:10 +02:00
if ( $object -> statut == Reception :: STATUS_DRAFT && $num_prod > 0 )
2018-10-03 12:22:41 +02:00
{
2018-10-04 12:27:10 +02:00
if (( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> reception -> creer ))
|| ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> reception -> reception_advance -> validate )))
2018-10-03 12:22:41 +02:00
{
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=valid">' . $langs -> trans ( " Validate " ) . '</a>' ;
}
else
{
print '<a class="butActionRefused" href="#" title="' . $langs -> trans ( " NotAllowed " ) . '">' . $langs -> trans ( " Validate " ) . '</a>' ;
}
}
// Edit
2018-10-04 12:27:10 +02:00
if ( $object -> statut == Reception :: STATUS_VALIDATED && $user -> rights -> reception -> creer ) {
2018-10-03 12:22:41 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id=' . $object -> id . '&action=modif">' . $langs -> trans ( 'Modify' ) . '</a></div>' ;
}
// TODO add alternative status
// 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order)
2018-10-04 12:27:10 +02:00
if ( $object -> statut == Reception :: STATUS_CLOSED && $user -> rights -> reception -> creer )
2018-10-03 12:22:41 +02:00
{
2018-10-04 12:27:10 +02:00
if ( ! empty ( $conf -> facture -> enabled ) && ! empty ( $conf -> global -> WORKFLOW_BILL_ON_RECEPTION )) // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
2018-10-03 12:22:41 +02:00
{
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>' ;
}
}
// Send
if ( $object -> statut > 0 )
{
2018-10-04 12:27:10 +02:00
if ( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) || $user -> rights -> reception -> reception_advance -> send )
2018-10-03 12:22:41 +02:00
{
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=presend&mode=init#formmailbeforetitle">' . $langs -> trans ( 'SendByMail' ) . '</a>' ;
}
else print '<a class="butActionRefused" href="#">' . $langs -> trans ( 'SendByMail' ) . '</a>' ;
}
// Create bill
2018-10-09 16:26:40 +02:00
if ( ! empty ( $conf -> fournisseur -> enabled ) && ( $object -> statut == Reception :: STATUS_VALIDATED || $object -> statut == Reception :: STATUS_CLOSED ))
2018-10-03 12:22:41 +02:00
{
2018-10-09 16:26:40 +02:00
if ( $user -> rights -> fournisseur -> facture -> creer )
2018-10-03 12:22:41 +02:00
{
2018-10-04 12:27:10 +02:00
// TODO show button only if (! empty($conf->global->WORKFLOW_BILL_ON_RECEPTION))
2018-10-03 12:22:41 +02:00
// If we do that, we must also make this option official.
2018-10-09 16:26:40 +02:00
print '<a class="butAction" href="' . DOL_URL_ROOT . '/fourn/facture/card.php?action=create&origin=' . $object -> element . '&originid=' . $object -> id . '&socid=' . $object -> socid . '">' . $langs -> trans ( " CreateBill " ) . '</a>' ;
2018-10-03 12:22:41 +02:00
}
}
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
// Close
2018-10-04 12:27:10 +02:00
if ( $object -> statut == Reception :: STATUS_VALIDATED )
2018-10-03 12:22:41 +02:00
{
2018-10-04 12:27:10 +02:00
if ( $user -> rights -> reception -> creer && $object -> statut > 0 && ! $object -> billed )
2018-10-03 12:22:41 +02:00
{
$label = " Close " ; $paramaction = 'classifyclosed' ; // = Transferred/Received
2018-10-04 12:27:10 +02:00
// Label here should be "Close" or "ClassifyBilled" if we decided to make bill on receptions instead of orders
2018-10-10 12:19:57 +02:00
if ( ! empty ( $conf -> fournisseur -> enabled ) && ! empty ( $conf -> global -> WORKFLOW_BILL_ON_RECEPTION )) // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
2018-10-03 12:22:41 +02:00
{
$label = " ClassifyBilled " ;
$paramaction = 'classifybilled' ;
}
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=' . $paramaction . '">' . $langs -> trans ( $label ) . '</a>' ;
}
}
2018-10-04 12:27:10 +02:00
if ( $user -> rights -> reception -> supprimer )
2018-10-03 12:22:41 +02:00
{
print '<a class="butActionDelete" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=delete">' . $langs -> trans ( " Delete " ) . '</a>' ;
}
}
print '</div>' ;
}
/*
* Documents generated
*/
if ( $action != 'presend' && $action != 'editline' )
{
print '<div class="fichecenter"><div class="fichehalfleft">' ;
$objectref = dol_sanitizeFileName ( $object -> ref );
2018-10-09 11:33:41 +02:00
$filedir = $conf -> reception -> dir_output . " / " . $objectref ;
2018-10-03 12:22:41 +02:00
$urlsource = $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id ;
2018-10-04 12:27:10 +02:00
$genallowed = $user -> rights -> reception -> lire ;
$delallowed = $user -> rights -> reception -> creer ;
2018-12-15 13:58:39 +01:00
2018-10-04 12:27:10 +02:00
print $formfile -> showdocuments ( 'reception' , $objectref , $filedir , $urlsource , $genallowed , $delallowed , $object -> modelpdf , 1 , 0 , 0 , 28 , 0 , '' , '' , '' , $soc -> default_lang );
2018-10-03 12:22:41 +02:00
// Show links to link elements
//$linktoelem = $form->showLinkToObjectBlock($object, null, array('order'));
$somethingshown = $form -> showLinkedObjectBlock ( $object , '' );
print '</div><div class="fichehalfright"><div class="ficheaddleft">' ;
}
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
if ( $action == 'presend' )
{
$ref = dol_sanitizeFileName ( $object -> ref );
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2018-10-08 16:54:33 +02:00
$fileparams = dol_most_recent_file ( $conf -> reception -> dir_output . '/' . $ref , preg_quote ( $ref , '/' ) . '[^\-]+' );
2018-10-03 12:22:41 +02:00
$file = $fileparams [ 'fullname' ];
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && ! empty ( $_REQUEST [ 'lang_id' ]))
$newlang = $_REQUEST [ 'lang_id' ];
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ))
$newlang = $object -> thirdparty -> default_lang ;
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( '' , $conf );
$outputlangs -> setDefaultLang ( $newlang );
2018-10-04 12:27:10 +02:00
$outputlangs -> load ( 'receptions' );
2018-10-03 12:22:41 +02:00
}
// Build document if it not exists
if ( ! $file || ! is_readable ( $file ))
{
$result = $object -> generateDocument ( GETPOST ( 'model' ) ? GETPOST ( 'model' ) : $object -> modelpdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
if ( $result <= 0 )
{
dol_print_error ( $db , $object -> error , $object -> errors );
exit ;
}
2018-10-04 12:27:10 +02:00
$fileparams = dol_most_recent_file ( $conf -> reception -> dir_output . '/reception/' . $ref , preg_quote ( $ref , '/' ) . '[^\-]+' );
2018-10-03 12:22:41 +02:00
$file = $fileparams [ 'fullname' ];
}
print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>' ;
print '<div class="clearboth"></div>' ;
print '<br>' ;
2018-10-04 12:27:10 +02:00
print load_fiche_titre ( $langs -> trans ( 'SendReceptionByEMail' ));
2018-10-03 12:22:41 +02:00
dol_fiche_head ( '' );
// Cree l'objet formulaire mail
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' ;
$formmail = new FormMail ( $db );
$formmail -> param [ 'langsmodels' ] = ( empty ( $newlang ) ? $langs -> defaultlang : $newlang );
$formmail -> fromtype = ( GETPOST ( 'fromtype' ) ? GETPOST ( 'fromtype' ) : ( ! empty ( $conf -> global -> MAIN_MAIL_DEFAULT_FROMTYPE ) ? $conf -> global -> MAIN_MAIL_DEFAULT_FROMTYPE : 'user' ));
if ( $formmail -> fromtype === 'user' ){
$formmail -> fromid = $user -> id ;
}
$formmail -> trackid = 'shi' . $object -> id ;
if ( ! empty ( $conf -> global -> MAIN_EMAIL_ADD_TRACK_ID ) && ( $conf -> global -> MAIN_EMAIL_ADD_TRACK_ID & 2 )) // If bit 2 is set
{
include DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
$formmail -> frommail = dolAddEmailTrackId ( $formmail -> frommail , 'shi' . $object -> id );
}
$formmail -> withfrom = 1 ;
$liste = array ();
foreach ( $object -> thirdparty -> thirdparty_and_contact_email_array ( 1 ) as $key => $value ) $liste [ $key ] = $value ;
$formmail -> withto = GETPOST ( " sendto " ) ? GETPOST ( " sendto " ) : $liste ;
$formmail -> withtocc = $liste ;
$formmail -> withtoccc = $conf -> global -> MAIN_EMAIL_USECCC ;
2018-10-04 12:27:10 +02:00
$formmail -> withtopic = $outputlangs -> trans ( 'SendReceptionRef' , '__RECEPTIONREF__' );
2018-10-03 12:22:41 +02:00
$formmail -> withfile = 2 ;
$formmail -> withbody = 1 ;
$formmail -> withdeliveryreceipt = 1 ;
$formmail -> withcancel = 1 ;
// Tableau des substitutions
2018-10-23 14:31:58 +02:00
$formmail -> setSubstitFromObject ( $object , $langs );
2018-10-04 12:27:10 +02:00
$formmail -> substit [ '__RECEPTIONREF__' ] = $object -> ref ;
$formmail -> substit [ '__RECEPTIONTRACKNUM__' ] = $object -> tracking_number ;
$formmail -> substit [ '__RECEPTIONTRACKNUMURL__' ] = $object -> tracking_url ;
2018-10-03 12:22:41 +02:00
//Find the good contact adress
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 );
}
$custcontact = '' ;
$contactarr = array ();
2018-10-04 12:27:10 +02:00
if ( is_object ( $objectsrc )) // For the case the reception was created without orders
2018-10-03 12:22:41 +02:00
{
$contactarr = $objectsrc -> liste_contact ( - 1 , 'external' );
}
if ( is_array ( $contactarr ) && count ( $contactarr ) > 0 ) {
foreach ( $contactarr as $contact ) {
if ( $contact [ 'libelle' ] == $langs -> trans ( 'TypeContact_commande_external_CUSTOMER' )) {
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php' ;
$contactstatic = new Contact ( $db );
$contactstatic -> fetch ( $contact [ 'id' ]);
$custcontact = $contactstatic -> getFullName ( $langs , 1 );
}
}
if ( ! empty ( $custcontact )) {
$formmail -> substit [ '__CONTACTCIVNAME__' ] = $custcontact ;
}
}
// Tableau des parametres complementaires
$formmail -> param [ 'action' ] = 'send' ;
2018-10-04 12:27:10 +02:00
$formmail -> param [ 'models' ] = 'reception_send' ;
2018-10-03 12:22:41 +02:00
$formmail -> param [ 'models_id' ] = GETPOST ( 'modelmailselected' , 'int' );
2018-10-04 12:27:10 +02:00
$formmail -> param [ 'receptionid' ] = $object -> id ;
2018-10-03 12:22:41 +02:00
$formmail -> param [ 'returnurl' ] = $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id ;
// Init list of files
if ( GETPOST ( " mode " ) == 'init' )
{
$formmail -> clear_attached_files ();
$formmail -> add_attached_files ( $file , basename ( $file ), dol_mimetype ( $file ));
}
// Show form
print $formmail -> get_form ();
dol_fiche_end ();
}
}
llxFooter ();
$db -> close ();