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 >
2019-09-06 01:52:51 +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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2018-10-03 12:22:41 +02:00
*/
/**
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' ;
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled )) {
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
}
if ( ! empty ( $conf -> propal -> enabled )) {
require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php' ;
}
2021-04-12 06:04:08 +02:00
if (( ! empty ( $conf -> fournisseur -> enabled ) && empty ( $conf -> global -> MAIN_USE_NEW_SUPPLIERMOD )) || ! empty ( $conf -> supplier_order -> 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' ;
}
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> productbatch -> enabled )) {
require_once DOL_DOCUMENT_ROOT . '/product/class/productbatch.class.php' ;
}
2022-06-14 17:53:17 +02:00
if ( ! empty ( $conf -> project -> enabled )) {
2020-10-28 17:49:52 +01:00
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php' ;
2018-10-03 12:22:41 +02:00
}
2019-11-12 00:15:34 +01:00
$langs -> loadLangs ( array ( " receptions " , " companies " , " bills " , 'deliveries' , 'orders' , 'stocks' , 'other' , 'propal' , 'sendings' ));
2018-10-03 12:22:41 +02:00
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> incoterm -> enabled )) {
$langs -> load ( 'incoterm' );
}
if ( ! empty ( $conf -> productbatch -> enabled )) {
$langs -> load ( 'productbatch' );
}
2018-10-03 12:22:41 +02:00
2019-11-12 00:15:34 +01:00
$origin = GETPOST ( 'origin' , 'alpha' ) ? GETPOST ( 'origin' , 'alpha' ) : 'reception' ; // Example: commande, propal
2021-06-02 04:15:21 +02:00
$origin_id = GETPOST ( 'id' , 'int' ) ? GETPOST ( 'id' , 'int' ) : '' ;
2018-10-03 12:22:41 +02:00
$id = $origin_id ;
2021-02-26 20:53:03 +01:00
if ( empty ( $origin_id )) {
$origin_id = GETPOST ( 'origin_id' , 'int' ); // Id of order or propal
}
if ( empty ( $origin_id )) {
$origin_id = GETPOST ( 'object_id' , 'int' ); // Id of order or propal
}
if ( empty ( $origin_id )) {
$origin_id = GETPOST ( 'originid' , 'int' ); // Id of order or propal
}
2019-11-12 00:15:34 +01:00
$ref = GETPOST ( 'ref' , 'alpha' );
$line_id = GETPOST ( 'lineid' , 'int' ) ? GETPOST ( 'lineid' , 'int' ) : '' ;
2021-12-01 15:40:53 +01:00
$facid = GETPOST ( 'facid' , 'int' );
2018-10-03 12:22:41 +02:00
2021-06-02 04:15:21 +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' ;
}
2021-06-02 04:15:21 +02:00
$confirm = GETPOST ( 'confirm' , 'alpha' );
2019-11-12 00:15:34 +01:00
$cancel = GETPOST ( 'cancel' , 'alpha' );
2018-10-03 12:22:41 +02:00
//PDF
2019-11-12 00:15:34 +01:00
$hidedetails = ( GETPOST ( 'hidedetails' , 'int' ) ? GETPOST ( 'hidedetails' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS ) ? 1 : 0 ));
$hidedesc = ( GETPOST ( 'hidedesc' , 'int' ) ? GETPOST ( 'hidedesc' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_DESC ) ? 1 : 0 ));
$hideref = ( GETPOST ( 'hideref' , 'int' ) ? GETPOST ( 'hideref' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_REF ) ? 1 : 0 ));
2018-10-03 12:22:41 +02:00
2018-10-04 12:27:10 +02:00
$object = new Reception ( $db );
2022-06-14 17:36:42 +02:00
$objectorder = new CommandeFournisseur ( $db );
2018-10-03 12:22:41 +02:00
$extrafields = new ExtraFields ( $db );
// fetch optionals attributes and labels
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
$extrafields -> fetch_name_optionals_label ( $object -> table_element_line );
2022-06-14 17:36:42 +02:00
$extrafields -> fetch_name_optionals_label ( $objectorder -> table_element_line );
2018-10-03 12:22:41 +02:00
// Load object. Make an object->fetch
2019-11-12 00:15:34 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php' ; // Must be include, not include_once
2018-10-03 12:22:41 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2019-11-12 00:15:34 +01:00
$hookmanager -> initHooks ( array ( 'receptioncard' , 'globalcard' ));
2018-10-03 12:22:41 +02:00
2020-11-16 12:20:18 +01:00
$date_delivery = dol_mktime ( GETPOST ( 'date_deliveryhour' , 'int' ), GETPOST ( 'date_deliverymin' , 'int' ), 0 , GETPOST ( 'date_deliverymonth' , 'int' ), GETPOST ( 'date_deliveryday' , 'int' ), GETPOST ( 'date_deliveryyear' , 'int' ));
2021-05-10 19:12:03 +02:00
if ( $id > 0 || ! empty ( $ref )) {
$object -> fetch ( $id , $ref );
$object -> fetch_thirdparty ();
if ( ! empty ( $object -> origin )) {
$origin = $object -> origin ;
$object -> fetch_origin ();
$typeobject = $object -> origin ;
}
// Linked documents
if ( $origin == 'order_supplier' && $object -> $typeobject -> id && ( ! empty ( $conf -> fournisseur -> enabled ) && empty ( $conf -> global -> MAIN_USE_NEW_SUPPLIERMOD ) || ! empty ( $conf -> supplier_order -> enabled ))) {
$origin_id = $object -> $typeobject -> id ;
$objectsrc = new CommandeFournisseur ( $db );
$objectsrc -> fetch ( $object -> $typeobject -> id );
}
}
2021-03-27 15:49:18 +01:00
// Security check
$socid = '' ;
if ( $user -> socid ) {
$socid = $user -> socid ;
}
2021-11-20 15:41:31 +01:00
if ( ! empty ( $conf -> reception -> enabled ) || $origin == 'reception' || empty ( $origin )) {
2021-05-10 19:12:03 +02:00
$result = restrictedArea ( $user , 'reception' , $id );
2021-03-27 15:49:18 +01:00
} else {
2021-11-20 15:41:31 +01:00
// We do not use the reception module, so we test permission on the supplier orders
2021-05-10 19:12:03 +02:00
if ( $origin == 'supplierorder' || $origin == 'order_supplier' ) {
$result = restrictedArea ( $user , 'fournisseur' , $origin_id , 'commande_fournisseur' , 'commande' );
2021-03-27 15:49:18 +01:00
} elseif ( empty ( $user -> rights -> { $origin } -> lire ) && empty ( $user -> rights -> { $origin } -> read )) {
accessforbidden ();
}
}
2021-11-20 15:41:31 +01:00
if ( ! empty ( $conf -> reception -> enabled )) {
$permissiontoread = $user -> rights -> reception -> lire ;
$permissiontoadd = $user -> rights -> reception -> creer ;
$permissiondellink = $user -> rights -> reception -> creer ; // Used by the include of actions_dellink.inc.php
$permissiontovalidate = (( 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 )));
$permissiontodelete = $user -> rights -> reception -> supprimer ;
} else {
$permissiontoread = $user -> rights -> fournisseur -> commande -> receptionner ;
$permissiontoadd = $user -> rights -> fournisseur -> commande -> receptionner ;
$permissiondellink = $user -> rights -> fournisseur -> commande -> receptionner ; // Used by the include of actions_dellink.inc.php
$permissiontovalidate = (( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> fournisseur -> commande -> receptionner )) || ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> fournisseur -> commande_advance -> check )));
$permissiontodelete = $user -> rights -> fournisseur -> commande -> receptionner ;
}
2018-10-03 12:22:41 +02:00
/*
* Actions
*/
2019-11-12 00:15:34 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-26 20:53:03 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2018-10-03 12:22:41 +02:00
2021-02-26 20:53:03 +01:00
if ( empty ( $reshook )) {
if ( $cancel ) {
2018-10-03 12:22:41 +02:00
$action = '' ;
}
2019-11-12 00:15:34 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php' ; // Must be include, not include_once
2018-10-03 12:22:41 +02:00
// Reopen
2021-11-20 15:41:31 +01:00
if ( $action == 'reopen' && $permissiontoadd ) {
2020-10-28 17:49:52 +01:00
$result = $object -> reOpen ();
2018-10-03 12:22:41 +02:00
}
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
// Confirm back to draft status
2021-11-20 15:41:31 +01:00
if ( $action == 'modif' && $permissiontoadd ) {
2019-03-15 19:01:40 +01:00
$result = $object -> setDraft ( $user );
2021-02-26 20:53:03 +01:00
if ( $result >= 0 ) {
2018-10-03 12:22:41 +02:00
// Define output language
2021-02-26 20:53:03 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
2018-10-03 12:22:41 +02:00
$outputlangs = $langs ;
$newlang = '' ;
2021-02-26 20:53:03 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
$newlang = $object -> thirdparty -> default_lang ;
}
2019-11-12 00:15:34 +01:00
if ( ! empty ( $newlang )) {
2018-10-03 12:22:41 +02:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
2020-09-10 01:49:09 +02:00
$model = $object -> model_pdf ;
2018-10-03 12:22:41 +02:00
$ret = $object -> fetch ( $id ); // Reload to get new records
$object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
}
2022-05-05 11:04:27 +02:00
} else {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2018-10-03 12:22:41 +02:00
}
}
// Set incoterm
2021-11-20 15:41:31 +01:00
if ( $action == 'set_incoterms' && ! empty ( $conf -> incoterm -> enabled ) && $permissiontoadd ) {
2020-10-28 17:49:52 +01:00
$result = $object -> setIncoterms ( GETPOST ( 'incoterm_id' , 'int' ), GETPOST ( 'location_incoterms' , 'alpha' ));
2018-10-03 12:22:41 +02:00
}
2021-11-20 15:41:31 +01:00
if ( $action == 'setref_supplier' && $permissiontoadd ) {
2020-10-28 17:49:52 +01:00
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
$result = $object -> setValueFrom ( 'ref_supplier' , GETPOST ( 'ref_supplier' , 'alpha' ), '' , null , 'text' , '' , $user , 'RECEPTION_MODIFY' );
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$action = 'editref_supplier' ;
} else {
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
}
2018-10-03 12:22:41 +02:00
}
2021-11-20 15:41:31 +01:00
if ( $action == 'update_extras' && $permissiontoadd ) {
2020-04-23 12:54:28 +02:00
$object -> oldcopy = dol_clone ( $object );
// Fill array 'array_options' with data from update form
2020-09-18 01:29:17 +02:00
$ret = $extrafields -> setOptionalsFromPost ( null , $object , GETPOST ( 'attribute' , 'restricthtml' ));
2021-02-26 20:53:03 +01:00
if ( $ret < 0 ) {
$error ++ ;
}
2020-04-23 12:54:28 +02:00
2021-02-26 20:53:03 +01:00
if ( ! $error ) {
2020-04-23 12:54:28 +02:00
// Actions on extra fields
$result = $object -> insertExtraFields ( 'RECEPTION_MODIFY' );
2021-02-26 20:53:03 +01:00
if ( $result < 0 ) {
2020-04-23 12:54:28 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
}
2018-10-03 12:22:41 +02:00
2021-02-26 20:53:03 +01:00
if ( $error ) {
2020-04-23 12:54:28 +02:00
$action = 'edit_extras' ;
2021-02-26 20:53:03 +01:00
}
2018-10-03 12:22:41 +02:00
}
2018-10-04 12:27:10 +02:00
// Create reception
2021-11-20 15:41:31 +01:00
if ( $action == 'add' && $permissiontoadd ) {
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' );
2022-03-17 18:53:50 +01:00
$object -> weight = GETPOST ( 'weight' , 'int' ) == '' ? null : GETPOST ( 'weight' , 'int' );
2022-05-22 01:19:00 +02:00
$object -> trueHeight = GETPOST ( 'trueHeight' , 'int' ) == '' ? null : GETPOST ( 'trueHeight' , 'int' );
$object -> trueWidth = GETPOST ( 'trueWidth' , 'int' ) == '' ? null : GETPOST ( 'trueWidth' , 'int' );
$object -> trueDepth = GETPOST ( 'trueDepth' , 'int' ) == '' ? null : GETPOST ( 'trueDepth' , 'int' );
2018-10-04 17:32:50 +02:00
$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
// 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
2021-02-26 20:53:03 +01:00
if ( $object -> origin == " supplierorder " ) {
2018-10-04 17:32:50 +02:00
$classname = 'CommandeFournisseur' ;
2021-02-26 20:53:03 +01:00
} else {
$classname = ucfirst ( $object -> origin );
}
2018-10-04 17:32:50 +02:00
$objectsrc = new $classname ( $db );
$objectsrc -> fetch ( $object -> origin_id );
$object -> socid = $objectsrc -> socid ;
$object -> ref_supplier = GETPOST ( 'ref_supplier' , 'alpha' );
$object -> model_pdf = GETPOST ( 'model' );
2019-11-12 00:15:34 +01:00
$object -> date_delivery = $date_delivery ; // Date delivery planed
2018-10-04 17:32:50 +02:00
$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' );
2020-09-18 01:29:17 +02:00
$object -> note_private = GETPOST ( 'note_private' , 'restricthtml' );
$object -> note_public = GETPOST ( 'note_public' , 'restricthtml' );
2018-10-04 17:32:50 +02:00
$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 ;
2021-02-26 20:53:03 +01:00
foreach ( $_POST as $key => $value ) {
2018-10-04 17:32:50 +02:00
// without batch module enabled
2021-02-26 20:53:03 +01:00
if ( strpos ( $key , 'qtyasked' ) !== false ) {
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
}
2021-02-26 20:53:03 +01:00
for ( $i = 1 ; $i <= $num ; $i ++ ) {
2018-10-04 17:32:50 +02:00
$idl = " idl " . $i ;
$sub_qty = array ();
$subtotalqty = 0 ;
$j = 0 ;
$batch = " batchl " . $i . " _0 " ;
$stockLocation = " ent1 " . $i . " _0 " ;
$qty = " qtyl " . $i ;
2021-03-30 23:04:29 +02:00
//reception line for product with no batch management and no multiple stock location
2021-03-31 13:59:21 +02:00
if ( GETPOST ( $qty , 'alpha' ) > 0 ) {
$totalqty += price2num ( GETPOST ( $qty , 'alpha' ), 'MS' );
2021-02-26 20:53:03 +01:00
}
2018-12-15 13:58:39 +01:00
2018-10-03 12:22:41 +02:00
// Extrafields
2019-10-06 14:41:52 +02:00
$array_options [ $i ] = $extrafields -> getOptionalsFromPost ( $object -> table_element_line , $i );
2018-10-04 17:32:50 +02:00
}
2018-10-03 12:22:41 +02:00
2021-02-26 20:53:03 +01:00
if ( $totalqty > 0 ) { // There is at least one thing to ship
for ( $i = 1 ; $i <= $num ; $i ++ ) {
2018-10-04 17:32:50 +02:00
$lineToTest = '' ;
2021-03-24 09:55:55 +01:00
$lineId = GETPOST ( $idl , 'int' );
2019-11-12 00:15:34 +01:00
foreach ( $objectsrc -> lines as $linesrc ) {
2021-03-24 09:55:55 +01:00
if ( $linesrc -> id == $lineId ) {
2021-02-26 20:53:03 +01:00
$lineToTest = $linesrc ;
2021-03-24 09:55:55 +01:00
break ;
2021-02-26 20:53:03 +01:00
}
2018-10-03 12:22:41 +02:00
}
2021-03-24 09:55:55 +01:00
if ( empty ( $lineToTest )) {
continue ;
}
2018-10-04 17:32:50 +02:00
$qty = " qtyl " . $i ;
$comment = " comment " . $i ;
2022-05-16 11:06:21 +02:00
// EATBY <-> DLUO see productbatch.class.php
// SELLBY <-> DLC
$eatby = " dluo " . $i ;
$sellby = " dlc " . $i ;
2018-10-04 17:32:50 +02:00
$batch = " batch " . $i ;
2021-09-22 14:56:44 +02:00
$cost_price = " cost_price " . $i ;
2018-10-04 17:32:50 +02:00
2022-11-05 15:39:31 +01:00
//if (GETPOST($qty, 'int') > 0 || (GETPOST($qty, 'int') == 0 && getDolGlobalString('RECEPTION_GETS_ALL_ORDER_PRODUCTS')) || (GETPOST($qty, 'int') < 0 && getDolGlobalString('RECEPTION_ALLOW_NEGATIVE_QTY'))) {
2021-02-26 20:53:03 +01:00
if ( GETPOST ( $qty , 'int' ) > 0 || ( GETPOST ( $qty , 'int' ) == 0 && $conf -> global -> RECEPTION_GETS_ALL_ORDER_PRODUCTS )) {
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
2021-03-30 23:02:53 +02:00
if ( ! empty ( $lineToTest )) {
$fk_product = $lineToTest -> fk_product ;
} else {
$fk_product = $linesrc -> fk_product ;
}
2021-02-26 20:53:03 +01:00
if ( $entrepot_id < 0 ) {
2018-10-04 17:32:50 +02:00
$entrepot_id = '' ;
2021-02-26 20:53:03 +01:00
}
2021-03-31 13:59:21 +02:00
if ( ! ( $fk_product > 0 ) && empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES )) {
2018-10-04 17:32:50 +02:00
$entrepot_id = 0 ;
2021-02-26 20:53:03 +01:00
}
2018-10-04 17:32:50 +02:00
$eatby = GETPOST ( $eatby , 'alpha' );
$sellby = GETPOST ( $sellby , 'alpha' );
2019-01-27 11:55:16 +01:00
$eatbydate = str_replace ( '/' , '-' , $eatby );
$sellbydate = str_replace ( '/' , '-' , $sellby );
2018-12-15 13:58:39 +01:00
2021-09-22 14:56:44 +02:00
if ( ! empty ( $conf -> global -> STOCK_CALCULATE_ON_RECEPTION ) || ! empty ( $conf -> global -> STOCK_CALCULATE_ON_RECEPTION_CLOSE )) {
2021-09-24 14:46:52 +02: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' ), price2num ( GETPOST ( $cost_price , 'double' ), 'MU' ));
2021-09-22 14:56:44 +02:00
} else {
$ret = $object -> addline ( $entrepot_id , GETPOST ( $idl , 'int' ), GETPOST ( $qty , 'int' ), $array_options [ $i ], GETPOST ( $comment , 'alpha' ), strtotime ( $eatbydate ), strtotime ( $sellbydate ), GETPOST ( $batch , 'alpha' ));
}
2021-02-26 20:53:03 +01:00
if ( $ret < 0 ) {
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
2020-10-28 17:49:52 +01:00
// Fill array 'array_options' with data from add form
$ret = $extrafields -> setOptionalsFromPost ( null , $object );
2021-02-26 20:53:03 +01:00
if ( $ret < 0 ) {
$error ++ ;
}
if ( ! $error ) {
2020-10-28 17:49:52 +01:00
$ret = $object -> create ( $user ); // This create reception (like Odoo picking) and line of receptions. Stock movement will when validating reception.
2018-10-03 12:22:41 +02:00
2021-02-26 20:53:03 +01:00
if ( $ret <= 0 ) {
2020-10-28 17:49:52 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
}
} else {
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " QtyToReceive " ) . '/' . $langs -> transnoentitiesnoconv ( " Warehouse " )), null , 'errors' );
$error ++ ;
}
2021-02-26 20:53:03 +01:00
if ( ! $error ) {
2020-10-28 17:49:52 +01:00
$db -> commit ();
header ( " Location: card.php?id= " . $object -> id );
exit ;
} else {
$db -> rollback ();
$_GET [ " commande_id " ] = GETPOST ( 'commande_id' , 'int' );
$action = 'create' ;
}
2021-11-20 15:41:31 +01:00
} elseif ( $action == 'confirm_valid' && $confirm == 'yes' && $permissiontovalidate ) {
2020-10-28 17:49:52 +01:00
$object -> fetch_thirdparty ();
2018-10-03 12:22:41 +02:00
2020-10-28 17:49:52 +01:00
$result = $object -> valid ( $user );
2018-10-03 12:22:41 +02:00
2021-02-26 20:53:03 +01:00
if ( $result < 0 ) {
2018-10-03 12:22:41 +02:00
$langs -> load ( " errors " );
2020-10-28 17:49:52 +01:00
setEventMessages ( $langs -> trans ( $object -> error ), null , 'errors' );
} else {
// Define output language
2021-02-26 20:53:03 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
2020-10-28 17:49:52 +01:00
$outputlangs = $langs ;
$newlang = '' ;
2021-02-26 20:53:03 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
$newlang = $object -> thirdparty -> default_lang ;
}
2020-10-28 17:49:52 +01:00
if ( ! empty ( $newlang )) {
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$model = $object -> model_pdf ;
$ret = $object -> fetch ( $id ); // Reload to get new records
$result = $object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
2021-02-26 20:53:03 +01:00
if ( $result < 0 ) {
dol_print_error ( $db , $result );
}
2020-10-28 17:49:52 +01:00
}
}
2021-11-20 15:41:31 +01:00
} elseif ( $action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete ) {
2020-10-28 17:49:52 +01:00
$result = $object -> delete ( $user );
2021-02-26 20:53:03 +01:00
if ( $result > 0 ) {
2020-10-28 17:49:52 +01:00
header ( " Location: " . DOL_URL_ROOT . '/reception/index.php' );
exit ;
} else {
2018-10-03 12:22:41 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2020-10-28 17:49:52 +01:00
}
2021-02-26 20:53:03 +01:00
// TODO add alternative status
/* } elseif ( $action == 'reopen' && ( ! empty ( $user -> rights -> reception -> creer ) || ! empty ( $user -> rights -> reception -> reception_advance -> validate ))) {
$result = $object -> setStatut ( 0 );
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
} */
2021-11-20 15:41:31 +01:00
} elseif ( $action == 'setdate_livraison' && $permissiontoadd ) {
2020-10-31 14:32:18 +01:00
$datedelivery = dol_mktime ( GETPOST ( 'liv_hour' , 'int' ), GETPOST ( 'liv_min' , 'int' ), 0 , GETPOST ( 'liv_month' , 'int' ), GETPOST ( 'liv_day' , 'int' ), GETPOST ( 'liv_year' , 'int' ));
2018-10-03 12:22:41 +02:00
2020-10-31 14:32:18 +01:00
$object -> fetch ( $id );
$result = $object -> setDeliveryDate ( $user , $datedelivery );
2021-02-26 20:53:03 +01:00
if ( $result < 0 ) {
2020-10-31 14:32:18 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2021-02-26 20:53:03 +01:00
} elseif ( $action == 'settracking_number' || $action == 'settracking_url'
2018-10-03 12:22:41 +02:00
|| $action == 'settrueWeight'
|| $action == 'settrueWidth'
|| $action == 'settrueHeight'
|| $action == 'settrueDepth'
2021-02-26 20:53:03 +01:00
|| $action == 'setshipping_method_id' ) {
// Action update
2020-10-28 17:49:52 +01:00
$error = 0 ;
2018-10-03 12:22:41 +02:00
2021-02-26 20:53:03 +01:00
if ( $action == 'settracking_number' ) {
$object -> tracking_number = trim ( GETPOST ( 'tracking_number' , 'alpha' ));
}
if ( $action == 'settracking_url' ) {
$object -> tracking_url = trim ( GETPOST ( 'tracking_url' , 'int' ));
}
2020-10-28 17:49:52 +01:00
if ( $action == 'settrueWeight' ) {
$object -> trueWeight = trim ( GETPOST ( 'trueWeight' , 'int' ));
2019-01-27 11:55:16 +01:00
$object -> weight_units = GETPOST ( 'weight_units' , 'int' );
2020-10-28 17:49:52 +01:00
}
2021-02-26 20:53:03 +01:00
if ( $action == 'settrueWidth' ) {
$object -> trueWidth = trim ( GETPOST ( 'trueWidth' , 'int' ));
}
2020-10-28 17:49:52 +01:00
if ( $action == 'settrueHeight' ) {
$object -> trueHeight = trim ( GETPOST ( 'trueHeight' , 'int' ));
2019-01-27 11:55:16 +01:00
$object -> size_units = GETPOST ( 'size_units' , 'int' );
2018-10-03 12:22:41 +02:00
}
2021-02-26 20:53:03 +01:00
if ( $action == 'settrueDepth' ) {
$object -> trueDepth = trim ( GETPOST ( 'trueDepth' , 'int' ));
}
if ( $action == 'setshipping_method_id' ) {
$object -> shipping_method_id = trim ( GETPOST ( 'shipping_method_id' , 'int' ));
}
2018-10-03 12:22:41 +02:00
2021-02-26 20:53:03 +01:00
if ( ! $error ) {
if ( $object -> update ( $user ) >= 0 ) {
2020-10-28 17:49:52 +01:00
header ( " Location: card.php?id= " . $object -> id );
exit ;
}
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2018-10-03 12:22:41 +02:00
2020-10-28 17:49:52 +01:00
$action = " " ;
2021-11-20 15:41:31 +01:00
} elseif ( $action == 'builddoc' && $permissiontoread ) {
2021-02-26 20:53:03 +01:00
// Build document
// En get ou en post
2018-10-03 12:22:41 +02:00
// Save last template used to generate document
2021-02-26 20:53:03 +01:00
if ( GETPOST ( 'model' )) {
$object -> setDocModel ( $user , GETPOST ( 'model' , 'alpha' ));
}
2018-10-03 12:22:41 +02:00
2020-10-28 17:49:52 +01:00
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
2021-02-26 20:53:03 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
$newlang = $reception -> thirdparty -> default_lang ;
}
if ( ! empty ( $newlang )) {
2020-10-28 17:49:52 +01:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
2020-09-10 01:49:09 +02:00
$result = $object -> generateDocument ( $object -> model_pdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
2021-02-26 20:53:03 +01:00
if ( $result <= 0 ) {
2018-10-03 12:22:41 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2020-10-28 17:49:52 +01:00
$action = '' ;
}
2021-11-20 15:41:31 +01:00
} elseif ( $action == 'remove_file' && $permissiontoadd ) {
2021-02-26 20:53:03 +01:00
// Delete file in doc form
2018-10-03 12:22:41 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2019-11-12 00:15:34 +01:00
$upload_dir = $conf -> reception -> dir_output ;
$file = $upload_dir . '/' . GETPOST ( 'file' );
$ret = dol_delete_file ( $file , 0 , 0 , 0 , $object );
2021-02-26 20:53:03 +01:00
if ( $ret ) {
setEventMessages ( $langs -> trans ( " FileWasRemoved " , GETPOST ( 'urlfile' )), null , 'mesgs' );
} else {
setEventMessages ( $langs -> trans ( " ErrorFailToDeleteFile " , GETPOST ( 'urlfile' )), null , 'errors' );
}
} elseif ( $action == 'classifybilled' ) {
2021-02-09 13:10:11 +01:00
$result = $object -> setBilled ();
2020-10-28 17:49:52 +01:00
if ( $result >= 0 ) {
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ();
}
2021-11-20 15:41:31 +01:00
} elseif ( $action == 'classifyclosed' && $permissiontoread ) {
2020-10-28 17:49:52 +01:00
$result = $object -> setClosed ();
if ( $result >= 0 ) {
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ();
}
2021-11-20 15:41:31 +01:00
} elseif ( $action == 'deleteline' && ! empty ( $line_id ) && $permissiontoread ) {
2021-02-26 20:53:03 +01:00
// delete a line
2018-10-03 12:22:41 +02:00
$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 );
2021-02-26 20:53:03 +01:00
for ( $i = 0 ; $i < $num_prod ; $i ++ ) {
if ( $lines [ $i ] -> id == $line_id ) {
2019-10-27 11:18:36 +01:00
// delete single warehouse line
$line -> id = $line_id ;
2021-02-26 20:53:03 +01:00
if ( ! $error && $line -> delete ( $user ) < 0 ) {
2019-10-27 11:18:36 +01:00
$error ++ ;
}
2018-10-03 12:22:41 +02:00
}
unset ( $_POST [ " lineid " ]);
}
2019-11-12 00:15:34 +01:00
if ( ! $error ) {
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
2018-10-03 12:22:41 +02:00
exit ();
2020-05-21 15:05:19 +02:00
} else {
2018-10-03 12:22:41 +02:00
setEventMessages ( $line -> error , $line -> errors , 'errors' );
}
2021-11-20 15:41:31 +01:00
} elseif ( $action == 'updateline' && GETPOST ( 'save' ) && $permissiontoadd ) {
2021-02-26 20:53:03 +01:00
// Update a line
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 );
2021-02-26 20:53:03 +01:00
for ( $i = 0 ; $i < $num_prod ; $i ++ ) {
if ( $lines [ $i ] -> id == $line_id ) { // we have found line to update
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
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element_line );
$line -> array_options = $extrafields -> getOptionalsFromPost ( $object -> table_element_line );
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
2021-02-26 20:53:03 +01:00
if ( $lines [ $i ] -> fk_product > 0 ) {
2018-10-08 16:54:33 +02:00
// 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
2019-11-12 00:15:34 +01:00
if ( ! empty ( $conf -> productbatch -> enabled )) {
2018-10-08 16:54:33 +02:00
$batch = " batch " . $line_id ;
$dlc = " dlc " . $line_id ;
$dluo = " dluo " . $line_id ;
2022-05-16 11:06:21 +02:00
// EATBY <-> DLUO
$eatby = GETPOST ( $dluo , 'alpha' );
2019-01-27 11:55:16 +01:00
$eatbydate = str_replace ( '/' , '-' , $eatby );
2022-05-16 11:06:21 +02:00
// SELLBY <-> DLC
$sellby = GETPOST ( $dlc , 'alpha' );
2019-01-27 11:55:16 +01:00
$sellbydate = str_replace ( '/' , '-' , $sellby );
2018-10-08 16:54:33 +02:00
$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
2021-02-26 20:53:03 +01:00
if ( $line -> update ( $user ) < 0 ) {
2018-10-08 16:54:33 +02:00
setEventMessages ( $line -> error , $line -> errors , 'errors' );
$error ++ ;
2018-10-03 12:22:41 +02:00
}
2022-05-16 11:06:21 +02:00
} else { // Product no predefined
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 ;
2021-02-26 20:53:03 +01:00
if ( $line -> update ( $user ) < 0 ) {
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 " ]);
2019-11-12 00:15:34 +01:00
if ( ! $error ) {
2018-10-03 12:22:41 +02:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
2021-02-26 20:53:03 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
2019-01-27 11:55:16 +01:00
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
2021-02-26 20:53:03 +01:00
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
2018-10-03 12:22:41 +02:00
$newlang = $object -> thirdparty -> default_lang ;
2021-02-26 20:53:03 +01:00
}
2019-11-12 00:15:34 +01:00
if ( ! empty ( $newlang )) {
2018-10-03 12:22:41 +02:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$ret = $object -> fetch ( $object -> id ); // Reload to get new records
2020-09-10 01:49:09 +02:00
$object -> generateDocument ( $object -> model_pdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
2018-10-03 12:22:41 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2021-11-20 15:41:31 +01:00
header ( 'Location: ' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id ); // To reshow the record we edit
2018-10-03 12:22:41 +02:00
exit ();
}
2021-11-20 15:41:31 +01:00
} elseif ( $action == 'updateline' && $permissiontoadd && GETPOST ( 'cancel' , 'alpha' ) == $langs -> trans ( " Cancel " )) {
header ( 'Location: ' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id ); // To reshow the record we edit
2018-10-03 12:22:41 +02:00
exit ();
}
include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php' ;
// Actions to send emails
2021-02-26 20:53:03 +01:00
if ( empty ( $id )) {
$id = $facid ;
}
2019-12-02 09:38:16 +01:00
$triggersendname = 'RECEPTION_SENTBYMAIL' ;
2019-11-12 00:15:34 +01:00
$paramname = 'id' ;
$mode = 'emailfromreception' ;
2022-03-16 08:58:01 +01:00
$trackid = 'rec' . $object -> id ;
2018-10-03 12:22:41 +02:00
include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php' ;
}
/*
* View
*/
2019-01-27 11:55:16 +01: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 );
2022-06-14 17:53:17 +02:00
if ( ! empty ( $conf -> project -> enabled )) {
2021-02-26 20:53:03 +01:00
$formproject = new FormProjets ( $db );
}
2018-10-03 12:22:41 +02:00
$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 );
2021-02-26 20:53:03 +01:00
if ( $action == 'create2' ) {
2020-10-28 17:49:52 +01:00
print load_fiche_titre ( $langs -> trans ( " CreateReception " ), '' , 'dollyrevert' );
2020-04-20 15:57:15 +02:00
2020-10-28 17:49:52 +01:00
print '<br>' . $langs -> trans ( " ReceptionCreationIsDoneFromOrder " );
$action = '' ; $id = '' ; $ref = '' ;
2018-10-03 12:22:41 +02:00
}
// Mode creation.
2022-07-11 00:05:50 +02:00
if ( $action == 'create' ) {
2020-10-28 17:49:52 +01:00
$recept = new Reception ( $db );
2018-10-03 12:22:41 +02:00
2020-10-28 17:49:52 +01:00
print load_fiche_titre ( $langs -> trans ( " CreateReception " ));
2021-02-26 20:53:03 +01:00
if ( ! $origin ) {
2020-10-28 17:49:52 +01:00
setEventMessages ( $langs -> trans ( " ErrorBadParameters " ), null , 'errors' );
}
2018-10-03 12:22:41 +02:00
2021-02-26 20:53:03 +01:00
if ( $origin ) {
if ( $origin == 'supplierorder' ) {
$classname = 'CommandeFournisseur' ;
} else {
$classname = ucfirst ( $origin );
}
2020-10-28 17:49:52 +01:00
2021-06-02 04:15:21 +02:00
$objectsrc = new $classname ( $db );
if ( $objectsrc -> fetch ( $origin_id )) { // This include the fetch_lines
2020-10-28 17:49:52 +01:00
$soc = new Societe ( $db );
2021-06-02 04:15:21 +02:00
$soc -> fetch ( $objectsrc -> socid );
2020-10-28 17:49:52 +01:00
$author = new User ( $db );
2021-06-02 04:15:21 +02:00
$author -> fetch ( $objectsrc -> user_author_id );
2020-10-28 17:49:52 +01:00
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> stock -> enabled )) {
$entrepot = new Entrepot ( $db );
}
2020-10-28 17:49:52 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="action" value="add">' ;
print '<input type="hidden" name="origin" value="' . $origin . '">' ;
2021-06-02 04:15:21 +02:00
print '<input type="hidden" name="origin_id" value="' . $objectsrc -> id . '">' ;
2021-02-26 20:53:03 +01:00
if ( GETPOST ( 'entrepot_id' , 'int' )) {
2020-10-28 17:49:52 +01:00
print '<input type="hidden" name="entrepot_id" value="' . GETPOST ( 'entrepot_id' , 'int' ) . '">' ;
}
print dol_get_fiche_head ( '' );
print '<table class="border centpercent">' ;
// Ref
print '<tr><td class="titlefieldcreate fieldrequired">' ;
2021-04-12 06:04:08 +02:00
if ( $origin == 'supplierorder' && (( ! empty ( $conf -> fournisseur -> enabled ) && empty ( $conf -> global -> MAIN_USE_NEW_SUPPLIERMOD )) || ! empty ( $conf -> supplier_order -> enabled ))) {
2021-06-02 04:15:21 +02:00
print $langs -> trans ( " RefOrder " ) . '</td><td colspan="3"><a href="' . DOL_URL_ROOT . '/fourn/commande/card.php?id=' . $objectsrc -> id . '">' . img_object ( $langs -> trans ( " ShowOrder " ), 'order' ) . ' ' . $objectsrc -> ref ;
2020-10-28 17:49:52 +01:00
}
2021-02-26 20:53:03 +01:00
if ( $origin == 'propal' && ! empty ( $conf -> propal -> enabled )) {
2021-06-02 04:15:21 +02:00
print $langs -> trans ( " RefProposal " ) . '</td><td colspan="3"><a href="' . DOL_URL_ROOT . '/comm/card.php?id=' . $objectsrc -> id . '">' . img_object ( $langs -> trans ( " ShowProposal " ), 'propal' ) . ' ' . $objectsrc -> ref ;
2020-10-28 17:49:52 +01:00
}
print '</a></td>' ;
print " </tr> \n " ;
// Ref client
print '<tr><td>' ;
2021-02-26 20:53:03 +01:00
if ( $origin == 'supplier_order' ) {
print $langs -> trans ( 'SupplierOrder' );
} else {
print $langs -> trans ( 'RefSupplier' );
}
2020-10-28 17:49:52 +01:00
print '</td><td colspan="3">' ;
2021-06-02 04:15:21 +02:00
print '<input type="text" name="ref_supplier" value="' . $objectsrc -> ref_supplier . '" />' ;
2020-10-28 17:49:52 +01: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
2022-06-14 17:53:17 +02:00
if ( ! empty ( $conf -> project -> enabled )) {
2020-10-28 17:49:52 +01:00
$projectid = GETPOST ( 'projectid' , 'int' ) ? GETPOST ( 'projectid' , 'int' ) : 0 ;
2021-06-02 04:15:21 +02:00
if ( empty ( $projectid ) && ! empty ( $objectsrc -> fk_project )) {
$projectid = $objectsrc -> fk_project ;
2021-02-26 20:53:03 +01:00
}
if ( $origin == 'project' ) {
$projectid = ( $originid ? $originid : 0 );
}
2020-10-28 17:49:52 +01:00
$langs -> load ( " projects " );
print '<tr>' ;
print '<td>' . $langs -> trans ( " Project " ) . '</td><td colspan="2">' ;
2021-04-27 17:28:28 +02:00
print img_picto ( '' , 'project' , 'class="paddingright"' );
2021-04-27 23:29:53 +02:00
print $formproject -> select_projects (( empty ( $conf -> global -> PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS ) ? $soc -> id : - 1 ), $projectid , 'projectid' , 0 , 0 , 1 , 0 , 1 , 0 , 0 , '' , 1 , 0 , 'maxwidth500' );
2021-03-27 15:49:18 +01:00
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 ) . '"><span class="fa fa-plus-circle valignmiddle" title="' . $langs -> trans ( " AddProject " ) . '"></span></a>' ;
2020-10-28 17:49:52 +01:00
print '</td>' ;
print '</tr>' ;
}
// Date delivery planned
print '<tr><td>' . $langs -> trans ( " DateDeliveryPlanned " ) . '</td>' ;
print '<td colspan="3">' ;
2021-06-02 04:15:21 +02:00
$date_delivery = ( $date_delivery ? $date_delivery : $objectsrc -> delivery_date ); // $date_delivery comes from GETPOST
2020-10-28 17:49:52 +01:00
print $form -> selectDate ( $date_delivery ? $date_delivery : - 1 , 'date_delivery' , 1 , 1 , 1 );
print " </td> \n " ;
print '</tr>' ;
// Note Public
print '<tr><td>' . $langs -> trans ( " NotePublic " ) . '</td>' ;
print '<td colspan="3">' ;
2021-06-02 04:15:21 +02:00
$doleditor = new DolEditor ( 'note_public' , $objectsrc -> note_public , '' , 60 , 'dolibarr_notes' , 'In' , 0 , false , empty ( $conf -> global -> FCKEDITOR_ENABLE_NOTE_PUBLIC ) ? 0 : 1 , ROWS_3 , '90%' );
2020-10-28 17:49:52 +01:00
print $doleditor -> Create ( 1 );
print " </td></tr> " ;
// Note Private
2021-06-02 04:15:21 +02:00
if ( $objectsrc -> note_private && ! $user -> socid ) {
2020-10-28 17:49:52 +01:00
print '<tr><td>' . $langs -> trans ( " NotePrivate " ) . '</td>' ;
print '<td colspan="3">' ;
2021-06-02 04:15:21 +02:00
$doleditor = new DolEditor ( 'note_private' , $objectsrc -> note_private , '' , 60 , 'dolibarr_notes' , 'In' , 0 , false , empty ( $conf -> global -> FCKEDITOR_ENABLE_NOTE_PRIVATE ) ? 0 : 1 , ROWS_3 , '90%' );
2020-10-28 17:49:52 +01:00
print $doleditor -> Create ( 1 );
print " </td></tr> " ;
}
// Weight
print '<tr><td>' ;
print $langs -> trans ( " Weight " );
print '</td><td colspan="3"><input name="weight" size="4" value="' . GETPOST ( 'weight' , 'int' ) . '"> ' ;
$text = $formproduct -> selectMeasuringUnits ( " weight_units " , " weight " , GETPOST ( 'weight_units' , 'int' ), 0 , 2 );
$htmltext = $langs -> trans ( " KeepEmptyForAutoCalculation " );
print $form -> textwithpicto ( $text , $htmltext );
print '</td></tr>' ;
// Dim
print '<tr><td>' ;
print $langs -> trans ( " Width " ) . ' x ' . $langs -> trans ( " Height " ) . ' x ' . $langs -> trans ( " Depth " );
2022-05-22 01:19:00 +02:00
print ' </td><td colspan="3"><input name="trueWidth" size="4" value="' . GETPOST ( 'trueWidth' , 'int' ) . '">' ;
print ' x <input name="trueHeight" size="4" value="' . GETPOST ( 'trueHeight' , 'int' ) . '">' ;
print ' x <input name="trueDepth" size="4" value="' . GETPOST ( 'trueDepth' , 'int' ) . '">' ;
2020-10-28 17:49:52 +01:00
print ' ' ;
$text = $formproduct -> selectMeasuringUnits ( " size_units " , " size " , GETPOST ( 'size_units' , 'int' ), 0 , 2 );
$htmltext = $langs -> trans ( " KeepEmptyForAutoCalculation " );
print $form -> textwithpicto ( $text , $htmltext );
print '</td></tr>' ;
// Delivery method
print " <tr><td> " . $langs -> trans ( " ReceptionMethod " ) . " </td> " ;
print '<td colspan="3">' ;
$recept -> fetch_delivery_methods ();
print $form -> selectarray ( " shipping_method_id " , $recept -> meths , GETPOST ( 'shipping_method_id' , 'int' ), 1 , 0 , 0 , " " , 1 );
2021-02-26 20:53:03 +01:00
if ( $user -> admin ) {
print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
}
2020-10-28 17:49:52 +01:00
print " </td></tr> \n " ;
// Tracking number
print " <tr><td> " . $langs -> trans ( " TrackingNumber " ) . " </td> " ;
print '<td colspan="3">' ;
print '<input name="tracking_number" size="20" value="' . GETPOST ( 'tracking_number' , 'alpha' ) . '">' ;
print " </td></tr> \n " ;
// Other attributes
$parameters = array ( 'objectsrc' => $objectsrc , 'colspan' => ' colspan="3"' , 'cols' => '3' , 'socid' => $socid );
2021-06-02 04:15:21 +02:00
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $recept , $action ); // Note that $action and $objectsrc may have been modified by hook
2020-10-28 17:49:52 +01:00
print $hookmanager -> resPrint ;
2021-06-02 04:15:21 +02:00
// Here $object can be of an object Reception
2020-10-28 17:49:52 +01:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
if ( empty ( $reshook ) && ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'label' ])) {
2018-10-03 12:22:41 +02:00
// copy from order
2021-06-02 04:15:21 +02:00
if ( $objectsrc -> fetch_optionals () > 0 ) {
$recept -> array_options = array_merge ( $recept -> array_options , $objectsrc -> array_options );
2018-10-03 12:22:41 +02:00
}
2023-04-03 15:49:38 +02:00
print $recept -> showOptionals ( $extrafields , 'create' , $parameters );
2018-10-03 12:22:41 +02:00
}
2020-10-31 14:32:18 +01:00
// Incoterms
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> incoterm -> enabled )) {
2018-10-03 12:22:41 +02:00
print '<tr>' ;
2021-06-02 04:15:21 +02:00
print '<td><label for="incoterm_id">' . $form -> textwithpicto ( $langs -> trans ( " IncotermLabel " ), $objectsrc -> label_incoterms , 1 ) . '</label></td>' ;
2020-10-31 14:32:18 +01:00
print '<td colspan="3" class="maxwidthonsmartphone">' ;
2021-06-02 04:15:21 +02:00
print $form -> select_incoterms (( ! empty ( $objectsrc -> fk_incoterms ) ? $objectsrc -> fk_incoterms : '' ), ( ! empty ( $objectsrc -> location_incoterms ) ? $objectsrc -> location_incoterms : '' ));
2018-10-03 12:22:41 +02:00
print '</td></tr>' ;
}
2020-10-31 14:32:18 +01:00
// Document model
2019-11-12 00:15:34 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/reception/modules_reception.php' ;
2021-02-09 14:26:46 +01:00
$list = ModelePdfReception :: liste_modeles ( $db );
2018-10-04 17:32:50 +02:00
2021-02-26 20:53:03 +01:00
if ( count ( $list ) > 1 ) {
2020-10-31 14:32:18 +01:00
print " <tr><td> " . $langs -> trans ( " DefaultModel " ) . " </td> " ;
print '<td colspan="3">' ;
2021-02-09 14:26:46 +01:00
print $form -> selectarray ( 'model' , $list , $conf -> global -> RECEPTION_ADDON_PDF );
2020-10-31 14:32:18 +01:00
print " </td></tr> \n " ;
2018-10-03 12:22:41 +02:00
}
2020-10-31 14:32:18 +01:00
print " </table> " ;
2018-10-03 12:22:41 +02:00
2020-10-31 14:32:18 +01:00
print dol_get_fiche_end ();
2018-10-03 12:22:41 +02:00
2020-10-31 14:32:18 +01:00
// Reception lines
2019-11-12 00:15:34 +01:00
$numAsked = 0 ;
2021-07-16 19:24:34 +02:00
/**
* @ var array $suffix2numAsked map HTTP query parameter suffixes ( like '1_0' ) to line indices so that
* extrafields from HTTP query can be assigned to the correct dispatch line
*/
$suffix2numAsked = array ();
2018-10-04 12:27:10 +02:00
$dispatchLines = array ();
2021-07-16 19:24:34 +02:00
2021-02-26 20:53:03 +01:00
foreach ( $_POST as $key => $value ) {
2021-06-02 04:15:21 +02:00
// If create form is coming from the button "Create Reception" of previous page
2018-10-04 12:27:10 +02:00
// without batch module enabled
2021-06-02 04:15:21 +02:00
$reg = array ();
2021-02-26 20:53:03 +01:00
if ( preg_match ( '/^product_([0-9]+)_([0-9]+)$/i' , $key , $reg )) {
2019-11-12 00:15:34 +01:00
$numAsked ++ ;
2021-07-16 19:24:34 +02:00
$paramSuffix = $reg [ 1 ] . '_' . $reg [ 2 ];
$suffix2numAsked [ $paramSuffix ] = $numAsked ;
2018-10-04 12:27:10 +02:00
// $numline=$reg[2] + 1; // line of product
$numline = $numAsked ;
2021-12-19 00:17:37 +01:00
2021-07-16 19:24:34 +02:00
$prod = " product_ " . $paramSuffix ;
$qty = " qty_ " . $paramSuffix ;
$ent = " entrepot_ " . $paramSuffix ;
$pu = " pu_ " . $paramSuffix ; // This is unit price including discount
$fk_commandefourndet = " fk_commandefourndet_ " . $paramSuffix ;
2021-09-24 13:29:03 +02:00
$dispatchLines [ $numAsked ] = array ( 'prod' => GETPOST ( $prod , 'int' ), 'qty' => price2num ( GETPOST ( $qty ), 'MS' ), 'ent' => GETPOST ( $ent , 'int' ), 'pu' => price2num ( GETPOST ( $pu ), 'MU' ), 'comment' => GETPOST ( 'comment' ), 'fk_commandefourndet' => GETPOST ( $fk_commandefourndet , 'int' ));
2018-10-04 12:27:10 +02:00
}
2018-12-15 14:12:39 +01:00
2018-10-04 12:27:10 +02:00
// with batch module enabled
2021-02-26 20:53:03 +01:00
if ( preg_match ( '/^product_batch_([0-9]+)_([0-9]+)$/i' , $key , $reg )) {
2018-12-15 14:12:39 +01:00
$numAsked ++ ;
2021-07-16 19:24:34 +02:00
$paramSuffix = $reg [ 1 ] . '_' . $reg [ 2 ];
$suffix2numAsked [ $paramSuffix ] = $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 ;
2021-12-19 00:17:37 +01:00
2021-07-16 19:24:34 +02:00
$prod = 'product_batch_' . $paramSuffix ;
$qty = 'qty_' . $paramSuffix ;
$ent = 'entrepot_' . $paramSuffix ;
$pu = 'pu_' . $paramSuffix ;
$lot = 'lot_number_' . $paramSuffix ;
2022-02-22 23:44:56 +01:00
$dDLUO = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'dluo_' . $paramSuffix . 'month' , 'int' ), GETPOST ( 'dluo_' . $paramSuffix . 'day' , 'int' ), GETPOST ( 'dluo_' . $paramSuffix . 'year' , 'int' ));
$dDLC = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'dlc_' . $paramSuffix . 'month' , 'int' ), GETPOST ( 'dlc_' . $paramSuffix . 'day' , 'int' ), GETPOST ( 'dlc_' . $paramSuffix . 'year' , 'int' ));
2021-07-16 19:24:34 +02:00
$fk_commandefourndet = 'fk_commandefourndet_' . $paramSuffix ;
2022-02-22 23:44:56 +01:00
$dispatchLines [ $numAsked ] = array ( 'prod' => GETPOST ( $prod , 'int' ), 'qty' => price2num ( GETPOST ( $qty ), 'MS' ), 'ent' => GETPOST ( $ent , 'int' ), 'pu' => price2num ( GETPOST ( $pu ), 'MU' ), 'comment' => GETPOST ( 'comment' ), 'fk_commandefourndet' => GETPOST ( $fk_commandefourndet , 'int' ), 'DLC' => $dDLC , 'DLUO' => $dDLUO , 'lot' => GETPOST ( $lot , 'alpha' ));
2018-10-04 12:27:10 +02:00
}
2021-06-02 04:15:21 +02:00
2021-09-24 13:29:03 +02:00
// If create form is coming from same page, it means that post was sent but an error occured
2021-06-02 04:15:21 +02:00
if ( preg_match ( '/^productid([0-9]+)$/i' , $key , $reg )) {
$numAsked ++ ;
2021-07-16 19:24:34 +02:00
$paramSuffix = $reg [ 1 ];
$suffix2numAsked [ $paramSuffix ] = $numAsked ;
2021-06-02 04:15:21 +02:00
// eat-by date dispatch
// $numline=$reg[2] + 1; // line of product
$numline = $numAsked ;
2021-12-19 00:17:37 +01:00
2021-07-16 19:24:34 +02:00
$prod = 'productid' . $paramSuffix ;
$comment = 'comment' . $paramSuffix ;
$qty = 'qtyl' . $paramSuffix ;
$ent = 'entl' . $paramSuffix ;
$pu = 'pul' . $paramSuffix ;
$lot = 'batch' . $paramSuffix ;
$dDLUO = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'dluo' . $paramSuffix . 'month' , 'int' ), GETPOST ( 'dluo' . $paramSuffix . 'day' , 'int' ), GETPOST ( 'dluo' . $paramSuffix . 'year' , 'int' ));
$dDLC = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'dlc' . $paramSuffix . 'month' , 'int' ), GETPOST ( 'dlc' . $paramSuffix . 'day' , 'int' ), GETPOST ( 'dlc' . $paramSuffix . 'year' , 'int' ));
$fk_commandefourndet = 'fk_commandefournisseurdet' . $paramSuffix ;
2021-09-24 13:29:03 +02:00
$dispatchLines [ $numAsked ] = array ( 'prod' => GETPOST ( $prod , 'int' ), 'qty' => price2num ( GETPOST ( $qty ), 'MS' ), 'ent' => GETPOST ( $ent , 'int' ), 'pu' => price2num ( GETPOST ( $pu ), 'MU' ), 'comment' => GETPOST ( $comment ), 'fk_commandefourndet' => GETPOST ( $fk_commandefourndet , 'int' ), 'DLC' => $dDLC , 'DLUO' => $dDLUO , 'lot' => GETPOST ( $lot , 'alpha' ));
2021-06-02 04:15:21 +02:00
}
2018-10-04 12:27:10 +02:00
}
2018-12-15 13:58:39 +01:00
2021-07-16 19:24:34 +02:00
// If extrafield values are passed in the HTTP query, assign them to the correct dispatch line
// Note that if an extrafield with the same name exists in the origin supplier order line, the value
// from the HTTP query will be ignored
foreach ( $suffix2numAsked as $suffix => $n ) {
$dispatchLines [ $n ][ 'array_options' ] = $extrafields -> getOptionalsFromPost ( 'commande_fournisseur_dispatch' , '_' . $suffix , '' );
}
2018-10-03 12:22:41 +02:00
2021-11-29 15:09:18 +01:00
print ' < script type = " text/javascript " >
2018-10-03 12:22:41 +02:00
jQuery ( document ) . ready ( function () {
jQuery ( " #autofill " ) . click ( function () { ' ;
2020-10-28 17:49:52 +01:00
$i = 1 ;
2021-02-26 20:53:03 +01:00
while ( $i <= $numAsked ) {
2020-10-28 17:49:52 +01:00
print 'jQuery("#qtyl' . $i . '").val(jQuery("#qtyasked' . $i . '").val() - jQuery("#qtydelivered' . $i . '").val());' . " \n " ;
$i ++ ;
}
print ' });
2018-10-03 12:22:41 +02:00
jQuery ( " #autoreset " ) . click ( function () { ' ;
2020-10-28 17:49:52 +01:00
$i = 1 ;
2021-02-26 20:53:03 +01:00
while ( $i <= $numAsked ) {
2020-10-28 17:49:52 +01:00
print 'jQuery("#qtyl' . $i . '").val(0);' . " \n " ;
$i ++ ;
}
print ' });
2018-10-03 12:22:41 +02:00
});
</ script > ' ;
2020-10-28 17:49:52 +01:00
print '<br>' ;
2018-10-03 12:22:41 +02:00
2020-10-28 17:49:52 +01:00
print '<table class="noborder centpercent">' ;
2018-10-03 12:22:41 +02:00
2020-10-28 17:49:52 +01:00
// Load receptions already done for same order
2021-06-02 04:15:21 +02:00
$objectsrc -> loadReceptions ();
2018-12-15 13:58:39 +01:00
2021-02-26 20:53:03 +01:00
if ( $numAsked ) {
2020-10-28 17:49:52 +01:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " Description " ) . '</td>' ;
2021-05-10 11:30:37 +02:00
print '<td>' . $langs -> trans ( " Comment " ) . '</td>' ;
2020-10-28 17:49:52 +01:00
print '<td class="center">' . $langs -> trans ( " QtyOrdered " ) . '</td>' ;
print '<td class="center">' . $langs -> trans ( " QtyReceived " ) . '</td>' ;
print '<td class="center">' . $langs -> trans ( " QtyToReceive " );
2021-09-22 14:56:44 +02:00
if ( ! empty ( $conf -> global -> STOCK_CALCULATE_ON_RECEPTION || $conf -> global -> STOCK_CALCULATE_ON_RECEPTION_CLOSE )) {
2022-06-09 02:48:32 +02:00
print '<td>' . $langs -> trans ( " BuyingPrice " ) . '</td>' ;
2021-09-22 14:56:44 +02:00
}
2021-02-26 20:53:03 +01:00
if ( empty ( $conf -> productbatch -> enabled )) {
2020-10-28 17:49:52 +01:00
print ' <br>(<a href="#" id="autofill">' . $langs -> trans ( " Fill " ) . '</a>' ;
print ' / <a href="#" id="autoreset">' . $langs -> trans ( " Reset " ) . '</a>)' ;
2018-10-03 12:22:41 +02:00
}
2020-10-28 17:49:52 +01:00
print '</td>' ;
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> stock -> enabled )) {
2019-01-21 10:06:44 +01:00
print '<td class="left">' . $langs -> trans ( " Warehouse " ) . ' (' . $langs -> trans ( " Stock " ) . ')</td>' ;
2020-10-28 17:49:52 +01:00
}
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> productbatch -> enabled )) {
2019-01-21 10:06:44 +01:00
print '<td class="left">' . $langs -> trans ( " batch_number " ) . '</td>' ;
2020-08-20 12:48:23 +02:00
if ( empty ( $conf -> global -> PRODUCT_DISABLE_SELLBY )) {
print '<td class="left">' . $langs -> trans ( " SellByDate " ) . '</td>' ;
}
2021-08-17 17:55:00 +02:00
if ( empty ( $conf -> global -> PRODUCT_DISABLE_EATBY )) {
print '<td class="left">' . $langs -> trans ( " EatByDate " ) . '</td>' ;
}
2018-10-04 17:32:50 +02:00
}
2020-10-28 17:49:52 +01:00
print " </tr> \n " ;
}
2018-10-03 12:22:41 +02:00
2022-01-28 15:51:18 +01:00
// $objectsrc->lines contains the line of the purchase order
// $dispatchLines is list of lines with dispatching detail (with product, qty and warehouse). One purchase order line may have n of this dispatch lines.
$arrayofpurchaselinealreadyoutput = array ();
// $_POST contains fk_commandefourndet_X_Y where Y is num of product line and X is number of splitted line
2020-10-28 17:49:52 +01:00
$indiceAsked = 1 ;
2022-01-28 15:51:18 +01:00
while ( $indiceAsked <= $numAsked ) { // Loop on $dispatchLines. Warning: $dispatchLines must be sorted by fk_commandefourndet (it is a regroupment key on output)
2020-10-28 17:49:52 +01:00
$product = new Product ( $db );
2022-01-28 15:51:18 +01:00
// We search the purchase order line that is linked to the dispatchLines
2021-06-02 04:15:21 +02:00
foreach ( $objectsrc -> lines as $supplierLine ) {
2019-11-12 00:15:34 +01: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
2020-10-28 17:49:52 +01:00
// Show product and description
$type = $line -> product_type ? $line -> product_type : $line -> fk_product_type ;
// Try to enhance type detection using date_start and date_end for free lines where type
// was not saved.
2021-02-26 20:53:03 +01:00
if ( ! empty ( $line -> date_start )) {
$type = 1 ;
}
if ( ! empty ( $line -> date_end )) {
$type = 1 ;
}
2020-10-28 17:49:52 +01:00
2021-06-02 04:15:21 +02:00
print '<!-- line fk_commandefourndet=' . $line -> id . ' for product=' . $line -> fk_product . ' -->' . " \n " ;
2020-10-28 17:49:52 +01:00
print '<tr class="oddeven">' . " \n " ;
// Product label
2021-02-26 20:53:03 +01:00
if ( $line -> fk_product > 0 ) { // If predefined product
2020-10-28 17:49:52 +01:00
$product -> fetch ( $line -> fk_product );
$product -> load_stock ( 'warehouseopen' ); // Load all $product->stock_warehouse[idwarehouse]->detail_batch
//var_dump($product->stock_warehouse[1]);
print '<td>' ;
print '<a name="' . $line -> id . '"></a>' ; // ancre pour retourner sur la ligne
2022-01-28 15:51:18 +01:00
if ( ! array_key_exists ( $line -> id , $arrayofpurchaselinealreadyoutput )) { // Add test to avoid to show qty twice
print '<input type="hidden" name="productid' . $indiceAsked . '" value="' . $line -> fk_product . '">' ;
2020-10-28 17:49:52 +01:00
2022-01-28 15:51:18 +01:00
// Show product and description
$product_static = $product ;
2020-10-28 17:49:52 +01:00
2022-01-28 15:51:18 +01: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 );
2020-10-28 17:49:52 +01:00
2022-01-28 15:51:18 +01:00
// Show range
print_date_range ( $db -> jdate ( $line -> date_start ), $db -> jdate ( $line -> date_end ));
2020-10-28 17:49:52 +01:00
2022-01-28 15:51:18 +01:00
// 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 ) : '' ;
}
2020-10-28 17:49:52 +01:00
}
print '</td>' ;
} else {
print " <td> " ;
2022-01-28 15:51:18 +01:00
if ( ! array_key_exists ( $line -> id , $arrayofpurchaselinealreadyoutput )) { // Add test to avoid to show qty twice
if ( $type == 1 ) {
$text = img_object ( $langs -> trans ( 'Service' ), 'service' );
} else {
$text = img_object ( $langs -> trans ( 'Product' ), 'product' );
}
2020-10-28 17:49:52 +01:00
2022-01-28 15:51:18 +01:00
if ( ! empty ( $line -> label )) {
$text .= ' <strong>' . $line -> label . '</strong>' ;
print $form -> textwithtooltip ( $text , $line -> desc , 3 , '' , '' , $i );
} else {
print $text . ' ' . nl2br ( $line -> desc );
}
2020-10-28 17:49:52 +01:00
2022-01-28 15:51:18 +01:00
// Show range
print_date_range ( $db -> jdate ( $line -> date_start ), $db -> jdate ( $line -> date_end ));
}
2020-10-28 17:49:52 +01:00
print " </td> \n " ;
}
2021-05-10 11:30:37 +02:00
// Comment
//$defaultcomment = 'Line create from order line id '.$line->id;
2021-06-02 04:15:21 +02:00
$defaultcomment = $dispatchLines [ $indiceAsked ][ 'comment' ];
2021-05-10 11:30:37 +02:00
print '<td>' ;
print '<input type="text" class="maxwidth100" name="comment' . $indiceAsked . '" value="' . $defaultcomment . '">' ;
print '</td>' ;
2022-01-28 15:51:18 +01:00
// Qty in source purchase order line
print '<td class="center">' ;
if ( ! array_key_exists ( $line -> id , $arrayofpurchaselinealreadyoutput )) { // Add test to avoid to show qty twice
print $line -> qty ;
}
2021-05-10 11:30:37 +02:00
print '<input type="hidden" name="fk_commandefournisseurdet' . $indiceAsked . '" value="' . $line -> id . '">' ;
2021-06-02 04:15:21 +02:00
print '<input type="hidden" name="pul' . $indiceAsked . '" value="' . $line -> pu_ht . '">' ;
2020-10-28 17:49:52 +01:00
print '<input name="qtyasked' . $indiceAsked . '" id="qtyasked' . $indiceAsked . '" type="hidden" value="' . $line -> qty . '">' ;
print '</td>' ;
$qtyProdCom = $line -> qty ;
2018-10-03 12:22:41 +02:00
2020-10-28 17:49:52 +01:00
// Qty already received
print '<td class="center">' ;
2021-06-02 04:15:21 +02:00
$quantityDelivered = $objectsrc -> receptions [ $line -> id ];
2022-01-28 15:51:18 +01:00
if ( ! array_key_exists ( $line -> id , $arrayofpurchaselinealreadyoutput )) { // Add test to avoid to show qty twice
print $quantityDelivered ;
}
2020-10-28 17:49:52 +01:00
print '<input name="qtydelivered' . $indiceAsked . '" id="qtydelivered' . $indiceAsked . '" type="hidden" value="' . $quantityDelivered . '">' ;
print '</td>' ;
2018-10-03 12:22:41 +02:00
2018-12-15 13:58:39 +01:00
2021-02-26 20:53:03 +01:00
if ( $line -> product_type == 1 && empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES )) {
2018-10-03 12:22:41 +02:00
$quantityToBeDelivered = 0 ;
2020-05-21 15:05:19 +02:00
} else {
2018-10-04 12:27:10 +02:00
$quantityToBeDelivered = $dispatchLines [ $indiceAsked ][ 'qty' ];
2018-10-03 12:22:41 +02:00
}
2020-10-28 17:49:52 +01: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 ;
2021-02-26 20:53:03 +01: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
2020-10-28 17:49:52 +01: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
2019-11-12 00:15:34 +01:00
$deliverableQty = $dispatchLines [ $indiceAsked ][ 'qty' ];
2021-09-22 14:56:44 +02:00
$cost_price = $dispatchLines [ $indiceAsked ][ 'pu' ];
2018-12-15 13:58:39 +01:00
2019-10-27 11:18:36 +01:00
// Quantity to send
print '<td class="center">' ;
2021-02-26 20:53:03 +01:00
if ( $line -> product_type == Product :: TYPE_PRODUCT || ! empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES )) {
if ( GETPOST ( 'qtyl' . $indiceAsked , 'int' )) {
$defaultqty = GETPOST ( 'qtyl' . $indiceAsked , 'int' );
}
2020-10-28 17:49:52 +01:00
print '<input name="idl' . $indiceAsked . '" type="hidden" value="' . $line -> id . '">' ;
2022-06-09 02:48:32 +02:00
print '<input class="right" name="qtyl' . $indiceAsked . '" id="qtyl' . $indiceAsked . '" type="text" size="4" value="' . $deliverableQty . '">' ;
2021-02-26 20:53:03 +01:00
} else {
print $langs -> trans ( " NA " );
}
2019-10-27 11:18:36 +01:00
print '</td>' ;
2018-12-15 13:58:39 +01:00
2021-09-22 14:56:44 +02:00
if ( ! empty ( $conf -> global -> STOCK_CALCULATE_ON_RECEPTION ) || ! empty ( $conf -> global -> STOCK_CALCULATE_ON_RECEPTION_CLOSE )) {
print '<td>' ;
2022-06-09 02:48:32 +02:00
print '<input class="width75 right" name="cost_price' . $indiceAsked . '" id="cost_price' . $indiceAsked . '" value="' . $cost_price . '">' ;
2021-09-22 14:56:44 +02:00
print '</td>' ;
}
2019-10-27 11:18:36 +01:00
// Stock
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> stock -> enabled )) {
2019-10-27 11:18:36 +01:00
print '<td class="left">' ;
2021-02-26 20:53:03 +01:00
if ( $line -> product_type == Product :: TYPE_PRODUCT || ! empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES )) { // Type of product need stock change ?
2019-10-27 11:18:36 +01:00
// Show warehouse combo list
$ent = " entl " . $indiceAsked ;
$idl = " idl " . $indiceAsked ;
2019-11-12 00:15:34 +01:00
$tmpentrepot_id = is_numeric ( GETPOST ( $ent , 'int' )) ? GETPOST ( $ent , 'int' ) : $warehouse_id ;
2021-02-26 20:53:03 +01:00
if ( $line -> fk_product > 0 ) {
2019-10-27 11:18:36 +01:00
print '<!-- Show warehouse selection -->' ;
print $formproduct -> selectWarehouses ( $tmpentrepot_id , 'entl' . $indiceAsked , '' , 0 , 0 , $line -> fk_product , '' , 1 );
}
2020-05-21 15:05:19 +02:00
} else {
2019-10-27 11:18:36 +01:00
print $langs -> trans ( " Service " );
2018-10-03 12:22:41 +02:00
}
print '</td>' ;
2019-10-27 11:18:36 +01:00
}
2018-12-15 13:58:39 +01:00
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> productbatch -> enabled )) {
if ( ! empty ( $product -> status_batch )) {
2019-10-27 11:18:36 +01:00
print '<td><input name="batch' . $indiceAsked . '" value="' . $dispatchLines [ $indiceAsked ][ 'lot' ] . '"></td>' ;
2021-08-17 17:55:00 +02:00
if ( empty ( $conf -> global -> PRODUCT_DISABLE_SELLBY )) {
2021-03-27 15:49:18 +01:00
print '<td class="nowraponall">' ;
2020-08-20 12:48:23 +02:00
print $form -> selectDate ( $dispatchLines [ $indiceAsked ][ 'DLC' ], 'dlc' . $indiceAsked , '' , '' , 1 , " " );
print '</td>' ;
}
2021-08-17 17:55:00 +02:00
if ( empty ( $conf -> global -> PRODUCT_DISABLE_EATBY )) {
2021-03-27 15:49:18 +01:00
print '<td class="nowraponall">' ;
2020-08-20 12:48:23 +02:00
print $form -> selectDate ( $dispatchLines [ $indiceAsked ][ 'DLUO' ], 'dluo' . $indiceAsked , '' , '' , 1 , " " );
print '</td>' ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-10-27 11:18:36 +01:00
print '<td colspan="3"></td>' ;
2018-10-04 17:32:50 +02:00
}
2019-10-27 11:18:36 +01:00
}
2018-10-03 12:22:41 +02:00
}
2022-01-28 15:51:18 +01:00
$arrayofpurchaselinealreadyoutput [ $line -> id ] = $line -> id ;
2021-05-10 11:30:37 +02:00
print " </tr> \n " ;
2018-12-15 13:58:39 +01:00
2022-06-14 17:36:42 +02:00
// Display lines for extrafields of the Reception line
// $line is a 'CommandeFournisseurLigne', $dispatchLines contains values of Reception lines so properties of CommandeFournisseurDispatch
if ( ! empty ( $extrafields )) {
//var_dump($line);
2019-11-12 00:15:34 +01:00
$colspan = 5 ;
2022-06-21 20:54:28 +02:00
if ( isModEnabled ( 'productbatch' )) {
2021-02-26 20:53:03 +01:00
$colspan += 3 ;
}
2022-06-14 17:36:42 +02:00
$recLine = new CommandeFournisseurDispatch ( $db );
2019-10-06 14:41:52 +02:00
2018-10-04 17:32:50 +02:00
$srcLine = new CommandeFournisseurLigne ( $db );
2020-03-27 16:02:58 +01:00
$srcLine -> id = $line -> id ;
$srcLine -> fetch_optionals (); // fetch extrafields also available in orderline
2019-10-06 14:41:52 +02:00
2022-06-14 17:36:42 +02:00
if ( empty ( $recLine -> array_options ) && ! empty ( $dispatchLines [ $indiceAsked ][ 'array_options' ])) {
$recLine -> array_options = $dispatchLines [ $indiceAsked ][ 'array_options' ];
2021-07-16 19:24:34 +02:00
}
2022-06-14 17:36:42 +02:00
$recLine -> array_options = array_merge ( $recLine -> array_options , $srcLine -> array_options );
2019-10-06 14:41:52 +02:00
2022-06-14 17:36:42 +02:00
print $recLine -> showOptionals ( $extrafields , 'edit' , array ( 'style' => 'class="oddeven"' , 'colspan' => $colspan ), $indiceAsked , '' , 1 );
2018-10-03 12:22:41 +02:00
}
2020-10-28 17:49:52 +01:00
$indiceAsked ++ ;
}
2018-10-03 12:22:41 +02:00
2020-10-28 17:49:52 +01:00
print " </table> " ;
2018-10-03 12:22:41 +02:00
2020-10-28 17:49:52 +01:00
print '<br>' ;
2018-10-03 12:22:41 +02:00
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ( " Create " );
2018-10-03 12:22:41 +02:00
2020-10-28 17:49:52 +01:00
print '</form>' ;
2018-10-03 12:22:41 +02:00
2020-10-28 17:49:52 +01:00
print '<br>' ;
} else {
dol_print_error ( $db );
}
}
2021-02-26 20:53:03 +01:00
} elseif ( $id || $ref ) {
/* *************************************************************************** */
/* */
/* Edit and view mode */
/* */
/* *************************************************************************** */
2018-10-03 12:22:41 +02:00
$lines = $object -> lines ;
$num_prod = count ( $lines );
2018-12-15 13:58:39 +01:00
2021-02-26 20:53:03 +01: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 ;
2019-11-12 00:15:34 +01:00
$object -> fetch_origin (); // Load property $object->commande, $object->propal, ...
2018-10-03 12:22:41 +02:00
}
$soc = new Societe ( $db );
$soc -> fetch ( $object -> socid );
2020-03-27 16:02:58 +01:00
$res = $object -> fetch_optionals ();
2018-12-15 13:58:39 +01:00
2019-11-12 00:15:34 +01:00
$head = reception_prepare_head ( $object );
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'reception' , $langs -> trans ( " Reception " ), - 1 , 'dollyrevert' );
2018-10-03 12:22:41 +02:00
2019-11-12 00:15:34 +01:00
$formconfirm = '' ;
2018-10-03 12:22:41 +02:00
// Confirm deleteion
2021-02-26 20:53:03 +01:00
if ( $action == 'delete' ) {
2019-11-12 00:15:34 +01: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
2021-02-26 20:53:03 +01:00
if ( $action == 'valid' ) {
2018-10-03 12:22:41 +02:00
$objectref = substr ( $object -> ref , 1 , 4 );
2021-02-26 20:53:03 +01:00
if ( $objectref == 'PROV' ) {
2018-10-03 12:22:41 +02:00
$numref = $object -> getNextNumRef ( $soc );
2020-05-21 15:05:19 +02:00
} else {
2018-10-03 12:22:41 +02:00
$numref = $object -> ref ;
}
2019-01-27 11:55:16 +01:00
$text = $langs -> trans ( " ConfirmValidateReception " , $numref );
2018-10-03 12:22:41 +02:00
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> notification -> enabled )) {
2019-11-12 00:15:34 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php' ;
$notify = new Notify ( $db );
$text .= '<br>' ;
$text .= $notify -> confirmMessage ( 'RECEPTION_VALIDATE' , $object -> socid , $object );
2018-10-03 12:22:41 +02:00
}
2019-11-12 00:15:34 +01: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
2021-02-26 20:53:03 +01:00
if ( $action == 'annuler' ) {
2019-11-12 00:15:34 +01: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
}
2019-11-12 00:15:34 +01:00
if ( ! $formconfirm ) {
2020-01-28 12:00:27 +01:00
$parameters = array ( 'formConfirm' => $formconfirm );
2020-10-28 17:49:52 +01:00
$reshook = $hookmanager -> executeHooks ( 'formConfirm' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2021-02-26 20:53:03 +01:00
if ( empty ( $reshook )) {
$formconfirm .= $hookmanager -> resPrint ;
} elseif ( $reshook > 0 ) {
$formconfirm = $hookmanager -> resPrint ;
}
2018-10-03 12:22:41 +02:00
}
// Print form confirm
print $formconfirm ;
// Calculate totalWeight and totalVolume for all products
// by adding weight and volume of each product line.
2019-11-12 00:15:34 +01:00
$tmparray = $object -> getTotalWeightVolume ();
$totalWeight = $tmparray [ 'weight' ];
$totalVolume = $tmparray [ 'volume' ];
2018-10-03 12:22:41 +02:00
2021-02-26 20:53:03 +01:00
if ( $typeobject == 'commande' && $object -> $typeobject -> id && ! empty ( $conf -> commande -> enabled )) {
2020-10-28 17:49:52 +01:00
$objectsrc = new Commande ( $db );
$objectsrc -> fetch ( $object -> $typeobject -> id );
2018-10-03 12:22:41 +02:00
}
2021-02-26 20:53:03 +01:00
if ( $typeobject == 'propal' && $object -> $typeobject -> id && ! empty ( $conf -> propal -> enabled )) {
2020-10-28 17:49:52 +01:00
$objectsrc = new Propal ( $db );
$objectsrc -> fetch ( $object -> $typeobject -> id );
2018-10-03 12:22:41 +02:00
}
2021-04-12 06:04:08 +02:00
if ( $typeobject == 'CommandeFournisseur' && $object -> $typeobject -> id && (( ! empty ( $conf -> fournisseur -> enabled ) && empty ( $conf -> global -> MAIN_USE_NEW_SUPPLIERMOD )) || ! empty ( $conf -> supplier_order -> enabled ))) {
2020-10-28 17:49:52 +01:00
$objectsrc = new CommandeFournisseur ( $db );
$objectsrc -> fetch ( $object -> $typeobject -> id );
2018-10-05 16:21:50 +02:00
}
2018-10-04 12:27:10 +02:00
// Reception card
2019-11-12 00:15:34 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/reception/list.php?restore_lastsearch_values=1' . ( ! empty ( $socid ) ? '&socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
$morehtmlref = '<div class="refidno">' ;
2018-10-04 12:27:10 +02:00
// Ref customer reception
2018-12-15 13:58:39 +01:00
2019-11-12 00:15:34 +01: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
2020-10-28 17:49:52 +01:00
$morehtmlref .= '<br>' . $langs -> trans ( 'ThirdParty' ) . ' : ' . $object -> thirdparty -> getNomUrl ( 1 );
// Project
2022-06-14 17:53:17 +02:00
if ( ! empty ( $conf -> project -> enabled )) {
2020-10-28 17:49:52 +01:00
$langs -> load ( " projects " );
$morehtmlref .= '<br>' . $langs -> trans ( 'Project' ) . ' ' ;
if ( 0 ) { // Do not change on reception
if ( $action != 'classify' ) {
2021-09-18 22:09:55 +02:00
$morehtmlref .= '<a class="editfielda" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=classify&token=' . newToken () . '&id=' . $object -> id . '">' . img_edit ( $langs -> transnoentitiesnoconv ( 'SetProject' )) . '</a> : ' ;
2020-10-28 17:49:52 +01:00
}
if ( $action == 'classify' ) {
// $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
$morehtmlref .= '<form method="post" action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '">' ;
$morehtmlref .= '<input type="hidden" name="action" value="classin">' ;
$morehtmlref .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
$morehtmlref .= $formproject -> select_projects ( $object -> socid , $object -> fk_project , 'projectid' , $maxlength , 0 , 1 , 0 , 1 , 0 , 0 , '' , 1 );
2021-08-24 17:04:17 +02:00
$morehtmlref .= '<input type="submit" class="button button-edit" value="' . $langs -> trans ( " Modify " ) . '">' ;
2020-10-28 17:49:52 +01:00
$morehtmlref .= '</form>' ;
} else {
$morehtmlref .= $form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> socid , $object -> fk_project , 'none' , 0 , 0 , 0 , 1 );
}
} else {
// We don't have project on reception, so we will use the project or source object instead
// TODO Add project on reception
$morehtmlref .= ' : ' ;
if ( ! empty ( $objectsrc -> fk_project )) {
$proj = new Project ( $db );
$proj -> fetch ( $objectsrc -> fk_project );
2021-10-29 09:40:38 +02:00
$morehtmlref .= ' : ' . $proj -> getNomUrl ( 1 );
if ( $proj -> title ) {
$morehtmlref .= ' - ' . $proj -> title ;
}
2020-10-28 17:49:52 +01:00
} else {
$morehtmlref .= '' ;
}
}
}
2019-11-12 00:15:34 +01:00
$morehtmlref .= '</div>' ;
2018-10-03 12:22:41 +02:00
2020-10-28 17:49:52 +01:00
dol_banner_tab ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' , $morehtmlref );
2018-10-03 12:22:41 +02:00
2020-10-28 17:49:52 +01:00
print '<div class="fichecenter">' ;
print '<div class="fichehalfleft">' ;
print '<div class="underbanner clearboth"></div>' ;
2018-10-03 12:22:41 +02:00
2021-05-10 19:12:03 +02:00
print '<table class="border centpercent tableforfield">' ;
2018-10-03 12:22:41 +02:00
// Linked documents
2021-02-26 20:53:03 +01:00
if ( $typeobject == 'commande' && $object -> $typeobject -> id && ! empty ( $conf -> commande -> enabled )) {
2018-10-03 12:22:41 +02:00
print '<tr><td>' ;
print $langs -> trans ( " RefOrder " ) . '</td>' ;
print '<td colspan="3">' ;
2019-01-27 11:55:16 +01:00
print $objectsrc -> getNomUrl ( 1 , 'commande' );
2018-10-03 12:22:41 +02:00
print " </td> \n " ;
print '</tr>' ;
}
2021-02-26 20:53:03 +01:00
if ( $typeobject == 'propal' && $object -> $typeobject -> id && ! empty ( $conf -> propal -> enabled )) {
2018-10-03 12:22:41 +02:00
print '<tr><td>' ;
print $langs -> trans ( " RefProposal " ) . '</td>' ;
print '<td colspan="3">' ;
2019-01-27 11:55:16 +01:00
print $objectsrc -> getNomUrl ( 1 , 'reception' );
2018-10-03 12:22:41 +02:00
print " </td> \n " ;
print '</tr>' ;
}
2021-02-26 20:53:03 +01:00
if ( $typeobject == 'CommandeFournisseur' && $object -> $typeobject -> id && ! empty ( $conf -> propal -> enabled )) {
2018-10-05 16:21:50 +02:00
print '<tr><td>' ;
2019-09-06 02:09:37 +02:00
print $langs -> trans ( " SupplierOrder " ) . '</td>' ;
2018-10-05 16:21:50 +02:00
print '<td colspan="3">' ;
2019-01-27 11:55:16 +01:00
print $objectsrc -> getNomUrl ( 1 , 'reception' );
2018-10-05 16:21:50 +02:00
print " </td> \n " ;
print '</tr>' ;
}
2018-10-03 12:22:41 +02:00
// Date creation
print '<tr><td class="titlefield">' . $langs -> trans ( " DateCreation " ) . '</td>' ;
2022-08-29 16:52:27 +02:00
print '<td colspan="3">' . dol_print_date ( $object -> date_creation , " dayhour " , " tzuserrel " ) . " </td> \n " ;
2018-10-03 12:22:41 +02:00
print '</tr>' ;
// Delivery date planned
print '<tr><td height="10">' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( 'DateDeliveryPlanned' );
print '</td>' ;
2021-02-26 20:53:03 +01:00
if ( $action != 'editdate_livraison' ) {
2021-09-27 12:24:01 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editdate_livraison&token=' . newToken () . '&id=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetDeliveryDate' ), 1 ) . '</a></td>' ;
2021-02-26 20:53:03 +01:00
}
2018-10-03 12:22:41 +02:00
print '</tr></table>' ;
print '</td><td colspan="2">' ;
2021-02-26 20:53:03 +01:00
if ( $action == 'editdate_livraison' ) {
2018-10-03 12:22:41 +02:00
print '<form name="setdate_livraison" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="post">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2018-10-03 12:22:41 +02:00
print '<input type="hidden" name="action" value="setdate_livraison">' ;
2019-11-12 00:15:34 +01:00
print $form -> selectDate ( $object -> date_delivery ? $object -> date_delivery : - 1 , 'liv_' , 1 , 1 , '' , " setdate_livraison " , 1 , 0 );
2021-08-24 17:04:17 +02:00
print '<input type="submit" class="button button-edit" value="' . $langs -> trans ( 'Modify' ) . '">' ;
2018-10-03 12:22:41 +02:00
print '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-01-27 11:55:16 +01:00
print $object -> date_delivery ? dol_print_date ( $object -> date_delivery , 'dayhour' ) : ' ' ;
2018-10-03 12:22:41 +02:00
}
print '</td>' ;
print '</tr>' ;
// Weight
print '<tr><td>' ;
2019-01-27 11:55:16 +01: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">' ;
2021-02-26 20:53:03 +01:00
if ( $action == 'edittrueWeight' ) {
2018-10-03 12:22:41 +02:00
print '<form name="settrueweight" action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
print '<input name="action" value="settrueWeight" type="hidden">' ;
print '<input name="id" value="' . $object -> id . '" type="hidden">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2018-10-03 12:22:41 +02:00
print '<input id="trueWeight" name="trueWeight" value="' . $object -> trueWeight . '" type="text">' ;
2019-10-23 02:58:39 +02:00
print $formproduct -> selectMeasuringUnits ( " weight_units " , " weight " , $object -> weight_units , 0 , 2 );
2018-10-03 12:22:41 +02:00
print ' <input class="button" name="modify" value="' . $langs -> trans ( " Modify " ) . '" type="submit">' ;
2020-11-23 15:12:52 +01:00
print ' <input class="button button-cancel" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '" type="submit">' ;
2018-10-03 12:22:41 +02:00
print '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2018-10-03 12:22:41 +02:00
print $object -> trueWeight ;
2019-11-12 00:15:34 +01:00
print ( $object -> trueWeight && $object -> weight_units != '' ) ? ' ' . measuringUnitString ( 0 , " weight " , $object -> weight_units ) : '' ;
2018-10-03 12:22:41 +02:00
}
2020-10-28 17:49:52 +01:00
// Calculated
2021-02-26 20:53:03 +01:00
if ( $totalWeight > 0 ) {
if ( ! empty ( $object -> trueWeight )) {
print ' (' . $langs -> trans ( " SumOfProductWeights " ) . ': ' ;
}
2019-11-12 00:15:34 +01:00
print showDimensionInBestUnit ( $totalWeight , 0 , " weight " , $langs , isset ( $conf -> global -> MAIN_WEIGHT_DEFAULT_ROUND ) ? $conf -> global -> MAIN_WEIGHT_DEFAULT_ROUND : - 1 , isset ( $conf -> global -> MAIN_WEIGHT_DEFAULT_UNIT ) ? $conf -> global -> MAIN_WEIGHT_DEFAULT_UNIT : 'no' );
2021-02-26 20:53:03 +01:00
if ( ! empty ( $object -> trueWeight )) {
print ')' ;
}
2018-10-03 12:22:41 +02:00
}
print '</td></tr>' ;
// Width
2019-01-27 11:55:16 +01:00
print '<tr><td>' . $form -> editfieldkey ( " Width " , 'trueWidth' , $object -> trueWidth , $object , $user -> rights -> reception -> creer ) . '</td><td colspan="3">' ;
print $form -> editfieldval ( " Width " , 'trueWidth' , $object -> trueWidth , $object , $user -> rights -> reception -> creer );
2019-11-12 00:15:34 +01:00
print ( $object -> trueWidth && $object -> width_units != '' ) ? ' ' . measuringUnitString ( 0 , " size " , $object -> width_units ) : '' ;
2018-10-03 12:22:41 +02:00
print '</td></tr>' ;
// Height
2019-01-27 11:55:16 +01:00
print '<tr><td>' . $form -> editfieldkey ( " Height " , 'trueHeight' , $object -> trueHeight , $object , $user -> rights -> reception -> creer ) . '</td><td colspan="3">' ;
2021-02-26 20:53:03 +01:00
if ( $action == 'edittrueHeight' ) {
2018-10-03 12:22:41 +02:00
print '<form name="settrueHeight" action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
print '<input name="action" value="settrueHeight" type="hidden">' ;
print '<input name="id" value="' . $object -> id . '" type="hidden">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2018-10-03 12:22:41 +02:00
print '<input id="trueHeight" name="trueHeight" value="' . $object -> trueHeight . '" type="text">' ;
2019-10-23 02:58:39 +02:00
print $formproduct -> selectMeasuringUnits ( " size_units " , " size " , $object -> size_units , 0 , 2 );
2018-10-03 12:22:41 +02:00
print ' <input class="button" name="modify" value="' . $langs -> trans ( " Modify " ) . '" type="submit">' ;
2020-11-23 15:12:52 +01:00
print ' <input class="button button-cancel" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '" type="submit">' ;
2018-10-03 12:22:41 +02:00
print '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2018-10-03 12:22:41 +02:00
print $object -> trueHeight ;
2019-11-12 00:15:34 +01:00
print ( $object -> trueHeight && $object -> height_units != '' ) ? ' ' . measuringUnitString ( 0 , " size " , $object -> height_units ) : '' ;
2018-10-03 12:22:41 +02:00
}
print '</td></tr>' ;
// Depth
2019-01-27 11:55:16 +01:00
print '<tr><td>' . $form -> editfieldkey ( " Depth " , 'trueDepth' , $object -> trueDepth , $object , $user -> rights -> reception -> creer ) . '</td><td colspan="3">' ;
print $form -> editfieldval ( " Depth " , 'trueDepth' , $object -> trueDepth , $object , $user -> rights -> reception -> creer );
2019-11-12 00:15:34 +01:00
print ( $object -> trueDepth && $object -> depth_units != '' ) ? ' ' . measuringUnitString ( 0 , " size " , $object -> depth_units ) : '' ;
2018-10-03 12:22:41 +02:00
print '</td></tr>' ;
// Volume
print '<tr><td>' ;
print $langs -> trans ( " Volume " );
print '</td>' ;
print '<td colspan="3">' ;
2019-11-12 00:15:34 +01:00
$calculatedVolume = 0 ;
$volumeUnit = 0 ;
2021-02-26 20:53:03 +01:00
if ( $object -> trueWidth && $object -> trueHeight && $object -> trueDepth ) {
2020-10-28 17:49:52 +01:00
$calculatedVolume = ( $object -> trueWidth * $object -> trueHeight * $object -> trueDepth );
$volumeUnit = $object -> size_units * 3 ;
2018-10-03 12:22:41 +02:00
}
2018-10-04 12:27:10 +02:00
// If reception volume not defined we use sum of products
2021-02-26 20:53:03 +01:00
if ( $calculatedVolume > 0 ) {
if ( $volumeUnit < 50 ) {
2020-10-28 17:49:52 +01:00
print showDimensionInBestUnit ( $calculatedVolume , $volumeUnit , " volume " , $langs , isset ( $conf -> global -> MAIN_VOLUME_DEFAULT_ROUND ) ? $conf -> global -> MAIN_VOLUME_DEFAULT_ROUND : - 1 , isset ( $conf -> global -> MAIN_VOLUME_DEFAULT_UNIT ) ? $conf -> global -> MAIN_VOLUME_DEFAULT_UNIT : 'no' );
2021-02-26 20:53:03 +01:00
} else {
print $calculatedVolume . ' ' . measuringUnitString ( 0 , " volume " , $volumeUnit );
}
2018-10-03 12:22:41 +02:00
}
2021-02-26 20:53:03 +01:00
if ( $totalVolume > 0 ) {
if ( $calculatedVolume ) {
print ' (' . $langs -> trans ( " SumOfProductVolumes " ) . ': ' ;
}
2019-11-12 00:15:34 +01:00
print showDimensionInBestUnit ( $totalVolume , 0 , " volume " , $langs , isset ( $conf -> global -> MAIN_VOLUME_DEFAULT_ROUND ) ? $conf -> global -> MAIN_VOLUME_DEFAULT_ROUND : - 1 , isset ( $conf -> global -> MAIN_VOLUME_DEFAULT_UNIT ) ? $conf -> global -> MAIN_VOLUME_DEFAULT_UNIT : 'no' );
2018-10-03 12:22:41 +02:00
//if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')';
2021-02-26 20:53:03 +01:00
if ( $calculatedVolume ) {
print ')' ;
}
2018-10-03 12:22:41 +02:00
}
print " </td> \n " ;
print '</tr>' ;
// Other attributes
$cols = 2 ;
2018-12-15 13:58:39 +01:00
2019-11-12 00:15:34 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php' ;
2018-10-03 12:22:41 +02:00
print '</table>' ;
print '</div>' ;
print '<div class="fichehalfright">' ;
print '<div class="underbanner clearboth"></div>' ;
2021-05-10 19:12:03 +02:00
print '<table class="border centpercent tableforfield">' ;
2018-10-03 12:22:41 +02:00
2018-10-04 12:27:10 +02:00
// Reception method
2018-10-03 12:22:41 +02:00
print '<tr><td height="10">' ;
2021-05-10 19:12:03 +02:00
print '<table class="nobordernopadding centpercent"><tr><td>' ;
2018-10-15 17:08:28 +02:00
print $langs -> trans ( 'ReceptionMethod' );
2018-10-03 12:22:41 +02:00
print '</td>' ;
2021-02-26 20:53:03 +01:00
if ( $action != 'editshipping_method_id' ) {
2021-09-27 12:24:01 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editshipping_method_id&token=' . newToken () . '&id=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetReceptionMethod' ), 1 ) . '</a></td>' ;
2021-02-26 20:53:03 +01:00
}
2018-10-03 12:22:41 +02:00
print '</tr></table>' ;
print '</td><td colspan="2">' ;
2021-02-26 20:53:03 +01:00
if ( $action == 'editshipping_method_id' ) {
2018-10-05 16:21:50 +02:00
print '<form name="setshipping_method_id" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="post">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
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 ();
2019-01-27 11:55:16 +01:00
print $form -> selectarray ( " shipping_method_id " , $object -> meths , $object -> shipping_method_id , 1 , 0 , 0 , " " , 1 );
2021-02-26 20:53:03 +01:00
if ( $user -> admin ) {
print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
}
2021-08-24 17:04:17 +02:00
print '<input type="submit" class="button button-edit" value="' . $langs -> trans ( 'Modify' ) . '">' ;
2018-10-03 12:22:41 +02:00
print '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-26 20:53:03 +01:00
if ( $object -> shipping_method_id > 0 ) {
2018-10-03 12:22:41 +02:00
// Get code using getLabelFromKey
2019-11-12 00:15:34 +01:00
$code = $langs -> getLabelFromKey ( $db , $object -> shipping_method_id , 'c_shipment_mode' , 'rowid' , 'code' );
2018-10-05 16:21:50 +02:00
print $langs -> trans ( " SendingMethod " . strtoupper ( $code ));
2018-10-03 12:22:41 +02:00
}
}
print '</td>' ;
print '</tr>' ;
// Tracking Number
2019-01-27 11:55:16 +01:00
print '<tr><td class="titlefield">' . $form -> editfieldkey ( " TrackingNumber " , 'tracking_number' , $object -> tracking_number , $object , $user -> rights -> reception -> creer ) . '</td><td colspan="3">' ;
2021-11-13 20:04:03 +01:00
print $form -> editfieldval ( " TrackingNumber " , 'tracking_number' , $object -> tracking_url , $object , $user -> rights -> reception -> creer , 'safehtmlstring' , $object -> tracking_number );
2018-10-03 12:22:41 +02:00
print '</td></tr>' ;
// Incoterms
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> incoterm -> enabled )) {
2018-10-03 12:22:41 +02:00
print '<tr><td>' ;
2020-10-28 17:49:52 +01:00
print '<table width="100%" class="nobordernopadding"><tr><td>' ;
print $langs -> trans ( 'IncotermLabel' );
print '<td><td class="right">' ;
2021-02-26 20:53:03 +01:00
if ( $user -> rights -> reception -> creer ) {
2021-09-27 12:24:01 +02:00
print '<a class="editfielda" href="' . DOL_URL_ROOT . '/reception/card.php?id=' . $object -> id . '&action=editincoterm&token=' . newToken () . '">' . img_edit () . '</a>' ;
2021-02-26 20:53:03 +01:00
} else {
print ' ' ;
}
2020-10-28 17:49:52 +01:00
print '</td></tr></table>' ;
print '</td>' ;
print '<td colspan="3">' ;
2021-02-26 20:53:03 +01:00
if ( $action != 'editincoterm' ) {
2019-06-25 13:00:02 +02:00
print $form -> textwithpicto ( $object -> display_incoterms (), $object -> label_incoterms , 1 );
2020-05-21 15:05:19 +02:00
} else {
2019-11-12 00:15:34 +01:00
print $form -> select_incoterms (( ! empty ( $object -> fk_incoterms ) ? $object -> fk_incoterms : '' ), ( ! empty ( $object -> location_incoterms ) ? $object -> location_incoterms : '' ), $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id );
2018-10-03 12:22:41 +02:00
}
2020-10-28 17:49:52 +01:00
print '</td></tr>' ;
2018-10-03 12:22:41 +02:00
}
print " </table> " ;
print '</div>' ;
print '</div>' ;
print '<div class="clearboth"></div>' ;
// Lines of products
2021-02-26 20:53:03 +01:00
if ( $action == 'editline' ) {
2019-11-12 00:15:34 +01:00
print '<form name="updateline" id="updateline" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&lineid=' . $line_id . ' " method= " POST " >
2020-03-24 13:10:35 +01:00
< input type = " hidden " name = " token " value = " ' . newToken().' " >
2018-10-03 12:22:41 +02:00
< input type = " hidden " name = " action " value = " updateline " >
< input type = " hidden " name = " mode " value = " " >
2019-11-12 00:15:34 +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">' ;
2022-05-23 11:50:06 +02:00
print '<table id="tablelines" class="noborder centpercent">' ;
2022-05-23 12:24:51 +02:00
print '<thead>' ;
2018-10-03 12:22:41 +02:00
print '<tr class="liste_titre">' ;
// #
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> global -> MAIN_VIEW_LINE_NUMBER )) {
2019-02-23 21:47:04 +01:00
print '<td width="5" class="center"> </td>' ;
2018-10-03 12:22:41 +02:00
}
// Product/Service
print '<td>' . $langs -> trans ( " Products " ) . '</td>' ;
2018-10-15 17:08:28 +02:00
// Comment
2021-05-10 11:30:37 +02:00
print '<td>' . $langs -> trans ( " Comment " ) . '</td>' ;
2018-10-03 12:22:41 +02:00
// Qty
2019-02-23 21:47:04 +01:00
print '<td class="center">' . $langs -> trans ( " QtyOrdered " ) . '</td>' ;
2021-02-26 20:53:03 +01:00
if ( $origin && $origin_id > 0 ) {
2019-02-23 21:47:04 +01:00
print '<td class="center">' . $langs -> trans ( " QtyInOtherReceptions " ) . '</td>' ;
2018-10-03 12:22:41 +02:00
}
2021-02-26 20:53:03 +01:00
if ( $action == 'editline' ) {
2018-10-03 12:22:41 +02:00
$editColspan = 3 ;
2021-02-26 20:53:03 +01:00
if ( empty ( $conf -> stock -> enabled )) {
$editColspan -- ;
}
if ( empty ( $conf -> productbatch -> enabled )) {
$editColspan -- ;
}
2019-11-12 00:15:34 +01:00
print '<td class="center" colspan="' . $editColspan . '">' ;
2021-02-26 20:53:03 +01:00
if ( $object -> statut <= 1 ) {
2018-10-04 12:27:10 +02:00
print $langs -> trans ( " QtyToReceive " ) . ' - ' ;
2020-05-21 15:05:19 +02:00
} else {
2018-10-04 12:27:10 +02:00
print $langs -> trans ( " QtyReceived " ) . ' - ' ;
2018-10-03 12:22:41 +02:00
}
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> stock -> enabled )) {
2018-10-03 12:22:41 +02:00
print $langs -> trans ( " WarehouseSource " ) . ' - ' ;
}
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> productbatch -> enabled )) {
2018-10-03 12:22:41 +02:00
print $langs -> trans ( " Batch " );
}
print '</td>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-11-19 13:46:30 +01:00
$statusreceived = $object :: STATUS_CLOSED ;
if ( getDolGlobalInt ( " STOCK_CALCULATE_ON_RECEPTION " )) {
$statusreceived = $object :: STATUS_VALIDATED ;
}
if ( getDolGlobalInt ( " STOCK_CALCULATE_ON_RECEPTION_CLOSE " )) {
$statusreceived = $object :: STATUS_CLOSED ;
}
if ( $object -> statut < $statusreceived ) {
2019-02-23 21:47:04 +01:00
print '<td class="center">' . $langs -> trans ( " QtyToReceive " ) . '</td>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-02-23 21:47:04 +01:00
print '<td class="center">' . $langs -> trans ( " QtyReceived " ) . '</td>' ;
2018-10-03 12:22:41 +02:00
}
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> stock -> enabled )) {
2019-01-21 10:06:44 +01:00
print '<td class="left">' . $langs -> trans ( " WarehouseSource " ) . '</td>' ;
2018-10-03 12:22:41 +02:00
}
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> productbatch -> enabled )) {
2019-01-21 10:06:44 +01:00
print '<td class="left">' . $langs -> trans ( " Batch " ) . '</td>' ;
2018-10-03 12:22:41 +02:00
}
}
2019-02-23 21:47:04 +01:00
print '<td class="center">' . $langs -> trans ( " CalculatedWeight " ) . '</td>' ;
print '<td class="center">' . $langs -> trans ( " CalculatedVolume " ) . '</td>' ;
//print '<td class="center">'.$langs->trans("Size").'</td>';
2021-02-26 20:53:03 +01:00
if ( $object -> statut == 0 ) {
2018-10-03 12:22:41 +02:00
print '<td class="linecoledit"></td>' ;
print '<td class="linecoldelete" width="10"></td>' ;
}
print " </tr> \n " ;
2022-05-23 12:24:51 +02:00
print '</thead>' ;
2018-10-03 12:22:41 +02:00
2019-11-12 00:15:34 +01:00
$var = false ;
2018-10-03 12:22:41 +02:00
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && ! empty ( $conf -> global -> PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE )) {
2018-10-03 12:22:41 +02:00
$object -> fetch_thirdparty ();
$outputlangs = $langs ;
2019-11-12 00:15:34 +01:00
$newlang = '' ;
2021-02-26 20:53:03 +01:00
if ( empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( empty ( $newlang )) {
$newlang = $object -> thirdparty -> default_lang ;
}
if ( ! empty ( $newlang )) {
2019-01-27 11:55:16 +01:00
$outputlangs = new Translate ( " " , $conf );
2018-10-03 12:22:41 +02:00
$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
2021-02-26 20:53:03 +01:00
if ( $origin && $origin_id > 0 ) {
2020-10-28 17:49:52 +01:00
$sql = " SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.date_start, obj.date_end " ;
$sql .= " , ed.rowid as receptionline_id, ed.qty, ed.fk_reception as reception_id, ed.fk_entrepot " ;
$sql .= " , e.rowid as reception_id, e.ref as reception_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_reception " ;
//if ($conf->delivery_note->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' ;
$sql .= " FROM " . MAIN_DB_PREFIX . " commande_fournisseur_dispatch as ed " ;
$sql .= " , " . MAIN_DB_PREFIX . " reception as e " ;
$sql .= " , " . MAIN_DB_PREFIX . $origin . " det as obj " ;
//if ($conf->delivery_note->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.fk_reception = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."deliverydet as ld ON ld.fk_delivery = l.rowid AND obj.rowid = ld.fk_origin_line";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product as p ON obj.fk_product = p.rowid " ;
$sql .= " WHERE e.entity IN ( " . getEntity ( 'reception' ) . " ) " ;
2021-06-09 15:36:47 +02:00
$sql .= " AND obj.fk_commande = " . (( int ) $origin_id );
2020-10-28 17:49:52 +01:00
$sql .= " AND obj.rowid = ed.fk_commandefourndet " ;
$sql .= " AND ed.fk_reception = e.rowid " ;
2021-06-09 17:50:21 +02:00
$sql .= " AND ed.fk_reception != " . (( int ) $object -> id );
2020-10-28 17:49:52 +01:00
//if ($filter) $sql.= $filter;
$sql .= " ORDER BY obj.fk_product " ;
dol_syslog ( " get list of reception lines " , LOG_DEBUG );
$resql = $db -> query ( $sql );
2021-02-26 20:53:03 +01:00
if ( $resql ) {
2020-10-28 17:49:52 +01:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2021-02-26 20:53:03 +01:00
while ( $i < $num ) {
2020-10-28 17:49:52 +01:00
$obj = $db -> fetch_object ( $resql );
2021-02-26 20:53:03 +01:00
if ( $obj ) {
2020-10-28 17:49:52 +01:00
// $obj->rowid is rowid in $origin."det" table
$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 );
}
$i ++ ;
}
}
//var_dump($alreadysent);
2018-10-03 12:22:41 +02:00
}
2022-01-28 15:51:18 +01:00
$arrayofpurchaselinealreadyoutput = array ();
// Loop on each product to send/sent. Warning: $lines must be sorted by ->fk_commandefourndet (it is a regroupment key on output)
2022-05-23 12:24:51 +02:00
print '<tbody>' ;
2021-02-26 20:53:03 +01:00
for ( $i = 0 ; $i < $num_prod ; $i ++ ) {
2021-12-01 16:24:57 +01:00
print '<!-- origin line id = ' . ( ! empty ( $lines [ $i ] -> origin_line_id ) ? $lines [ $i ] -> origin_line_id : 0 ) . ' -->' ; // id of order line
2022-05-23 12:24:51 +02:00
print '<tr class="oddeven" id="row-' . $lines [ $i ] -> id . '" data-id="' . $lines [ $i ] -> id . '" data-element="' . $lines [ $i ] -> element . '">' ;
2018-10-03 12:22:41 +02:00
// #
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> global -> MAIN_VIEW_LINE_NUMBER )) {
2019-11-12 00:15:34 +01:00
print '<td class="center">' . ( $i + 1 ) . '</td>' ;
2018-10-03 12:22:41 +02:00
}
// Predefined product or service
2021-02-26 20:53:03 +01:00
if ( $lines [ $i ] -> fk_product > 0 ) {
2018-10-03 12:22:41 +02:00
// Define output language
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && ! empty ( $conf -> global -> PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE )) {
2018-10-03 12:22:41 +02:00
$prod = new Product ( $db );
$prod -> fetch ( $lines [ $i ] -> fk_product );
2019-11-12 00:15:34 +01:00
$label = ( ! empty ( $prod -> multilangs [ $outputlangs -> defaultlang ][ " label " ])) ? $prod -> multilangs [ $outputlangs -> defaultlang ][ " label " ] : $lines [ $i ] -> product -> label ;
2021-02-26 20:53:03 +01:00
} else {
$label = ( ! empty ( $lines [ $i ] -> product -> label ) ? $lines [ $i ] -> product -> label : $lines [ $i ] -> product -> product_label );
}
2018-10-03 12:22:41 +02:00
2022-05-23 12:24:51 +02:00
print '<td class="linecoldescription">' ;
2022-01-28 15:51:18 +01:00
if ( ! array_key_exists ( $lines [ $i ] -> fk_commandefourndet , $arrayofpurchaselinealreadyoutput )) {
$text = $lines [ $i ] -> product -> getNomUrl ( 1 );
$text .= ' - ' . $label ;
$description = ( ! empty ( $conf -> global -> PRODUIT_DESC_IN_FORM ) ? '' : dol_htmlentitiesbr ( $lines [ $i ] -> product -> description ));
print $form -> textwithtooltip ( $text , $description , 3 , '' , '' , $i );
2022-01-28 15:57:09 +01:00
print_date_range ( ! empty ( $lines [ $i ] -> date_start ) ? $lines [ $i ] -> date_start : 0 , ! empty ( $lines [ $i ] -> date_end ) ? $lines [ $i ] -> date_end : 0 );
2022-01-28 15:51:18 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_DESC_IN_FORM )) {
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 " ;
2020-05-21 15:05:19 +02:00
} else {
2022-05-23 12:24:51 +02:00
print '<td class="linecoldescription">' ;
2022-01-28 15:51:18 +01:00
if ( ! array_key_exists ( $lines [ $i ] -> fk_commandefourndet , $arrayofpurchaselinealreadyoutput )) {
if ( $lines [ $i ] -> product_type == Product :: TYPE_SERVICE ) {
$text = img_object ( $langs -> trans ( 'Service' ), 'service' );
} else {
$text = img_object ( $langs -> trans ( 'Product' ), 'product' );
}
2018-10-03 12:22:41 +02:00
2022-01-28 15:51:18 +01:00
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 );
}
2018-10-03 12:22:41 +02:00
2022-01-28 15:51:18 +01:00
print_date_range ( $lines [ $i ] -> date_start , $lines [ $i ] -> date_end );
}
2018-10-03 12:22:41 +02:00
print " </td> \n " ;
}
2018-12-15 13:58:39 +01:00
2021-02-26 20:53:03 +01:00
if ( $action == 'editline' && $lines [ $i ] -> id == $line_id ) {
2021-05-10 11:30:37 +02:00
print '<td><input name="comment' . $line_id . '" id="comment' . $line_id . '" value="' . dol_escape_htmltag ( $lines [ $i ] -> comment ) . '"></td>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-05-10 11:30:37 +02:00
print '<td style="white-space: pre-wrap; max-width: 200px;">' . dol_escape_htmltag ( $lines [ $i ] -> comment ) . '</td>' ;
2018-10-15 17:08:28 +02:00
}
2018-10-03 12:22:41 +02:00
// Qty ordered
2022-05-23 12:24:51 +02:00
print '<td class="center linecolqty">' ;
2022-01-28 15:51:18 +01:00
if ( ! array_key_exists ( $lines [ $i ] -> fk_commandefourndet , $arrayofpurchaselinealreadyoutput )) {
print $lines [ $i ] -> qty_asked ;
}
print '</td>' ;
2018-10-03 12:22:41 +02:00
2018-10-04 12:27:10 +02:00
// Qty in other receptions (with reception and warehouse used)
2021-02-26 20:53:03 +01:00
if ( $origin && $origin_id > 0 ) {
2022-05-23 12:24:51 +02:00
print '<td class="center nowrap linecolqtyinotherreceptions">' ;
2022-01-28 15:51:18 +01:00
if ( ! array_key_exists ( $lines [ $i ] -> fk_commandefourndet , $arrayofpurchaselinealreadyoutput )) {
foreach ( $alreadysent as $key => $val ) {
if ( $lines [ $i ] -> fk_commandefourndet == $key ) {
$j = 0 ;
foreach ( $val as $receptionline_id => $receptionline_var ) {
if ( $receptionline_var [ 'reception_id' ] == $lines [ $i ] -> fk_reception ) {
continue ; // We want to show only "other receptions"
}
$j ++ ;
if ( $j > 1 ) {
print '<br>' ;
}
$reception_static -> fetch ( $receptionline_var [ 'reception_id' ]);
print $reception_static -> getNomUrl ( 1 );
print ' - ' . $receptionline_var [ 'qty' ];
$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 ) {
$warehousestatic -> fetch ( $receptionline_var [ 'warehouse' ]);
$htmltext .= '<br>' . $langs -> trans ( " From " ) . ' : ' . $warehousestatic -> getNomUrl ( 1 , '' , 0 , 1 );
}
print ' ' . $form -> textwithpicto ( '' , $htmltext , 1 );
2021-02-26 20:53:03 +01:00
}
2020-10-28 17:49:52 +01:00
}
}
}
}
2018-10-03 12:22:41 +02:00
print '</td>' ;
2021-02-26 20:53:03 +01:00
if ( $action == 'editline' && $lines [ $i ] -> id == $line_id ) {
2018-10-03 12:22:41 +02:00
// edit mode
2019-02-23 21:47:04 +01:00
print '<td colspan="' . $editColspan . '" class="center"><table class="nobordernopadding">' ;
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> stock -> enabled )) {
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
2020-04-26 23:06:52 +02:00
print '<td><input name="qtyl' . $line_id . '" id="qtyl' . $line_id . '" type="text" size="4" value="' . $lines [ $i ] -> qty . '"></td>' ;
2018-12-15 15:01:49 +01:00
// Warehouse source
2019-11-12 00:15:34 +01:00
print '<td>' . $formproduct -> selectWarehouses ( $lines [ $i ] -> fk_entrepot , 'entl' . $line_id , '' , 1 , 0 , $lines [ $i ] -> fk_product , '' , 1 ) . '</td>' ;
2018-12-15 15:01:49 +01:00
// Batch number managment
2021-02-26 20:53:03 +01:00
if ( $conf -> productbatch -> enabled && ! empty ( $lines [ $i ] -> product -> status_batch )) {
2021-08-17 18:07:10 +02:00
print '<td class="nowraponall"><input name="batch' . $line_id . '" id="batch' . $line_id . '" type="text" value="' . $lines [ $i ] -> batch . '"><br>' ;
2020-08-20 12:48:23 +02:00
if ( empty ( $conf -> global -> PRODUCT_DISABLE_SELLBY )) {
print $langs -> trans ( 'SellByDate' ) . ' : ' ;
2021-08-17 18:07:10 +02:00
print $form -> selectDate ( $lines [ $i ] -> sellby , 'dlc' . $line_id , '' , '' , 1 , " " ) . '</br>' ;
2020-08-20 12:48:23 +02:00
}
2021-08-17 17:55:00 +02:00
if ( empty ( $conf -> global -> PRODUCT_DISABLE_EATBY )) {
2021-08-17 18:07:10 +02:00
print $langs -> trans ( 'EatByDate' ) . ' : ' ;
print $form -> selectDate ( $lines [ $i ] -> eatby , 'dluo' . $line_id , '' , '' , 1 , " " );
2020-08-20 12:48:23 +02:00
}
2018-12-15 15:01:49 +01:00
print '</td>' ;
}
print '</tr>' ;
2020-05-21 15:05:19 +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
2020-04-26 23:06:52 +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
2020-04-26 23:06:52 +02:00
print '<td></td>' ;
2018-10-03 12:22:41 +02:00
// Batch number managment
2020-04-26 23:06:52 +02:00
print '<td></td>' ;
2018-10-03 12:22:41 +02:00
print '</tr>' ;
}
}
print '</table></td>' ;
2020-05-21 15:05:19 +02:00
} else {
2018-10-18 15:11:43 +02:00
// Qty to receive or received
2022-05-23 12:24:51 +02:00
print '<td class="center linecolqtytoreceive">' . $lines [ $i ] -> qty . '</td>' ;
2018-10-03 12:22:41 +02:00
// Warehouse source
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> stock -> enabled )) {
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 );
2022-03-17 18:53:50 +01:00
print '<td class="left tdoverflowmax150" title="' . dol_escape_htmltag ( $entrepot -> label ) . '">' ;
2018-10-03 12:22:41 +02:00
print $entrepot -> getNomUrl ( 1 );
2022-03-17 18:53:50 +01:00
print '</td>' ;
} else {
print '<td></td>' ;
2018-10-03 12:22:41 +02:00
}
}
// Batch number managment
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> productbatch -> enabled )) {
if ( isset ( $lines [ $i ] -> batch )) {
2018-10-03 12:22:41 +02:00
print '<!-- Detail of lot -->' ;
2022-05-23 12:24:51 +02:00
print '<td class="linecolbatch">' ;
2019-11-12 00:15:34 +01:00
$detail = '' ;
2021-02-26 20:53:03 +01:00
if ( $lines [ $i ] -> product -> status_batch ) {
2020-08-20 12:48:23 +02:00
$detail .= $langs -> trans ( " Batch " ) . ': ' . $lines [ $i ] -> batch ;
if ( empty ( $conf -> global -> PRODUCT_DISABLE_SELLBY )) {
2019-11-12 00:15:34 +01:00
$detail .= ' - ' . $langs -> trans ( " SellByDate " ) . ': ' . dol_print_date ( $lines [ $i ] -> sellby , " day " );
2020-08-20 12:48:23 +02:00
}
if ( empty ( $conf -> global -> PRODUCT_DISABLE_EATBY )) {
2019-11-12 00:15:34 +01:00
$detail .= ' - ' . $langs -> trans ( " EatByDate " ) . ': ' . dol_print_date ( $lines [ $i ] -> eatby , " day " );
2020-08-20 12:48:23 +02:00
}
$detail .= '<br>' ;
2018-12-15 13:58:39 +01:00
2019-01-27 11:55:16 +01:00
print $form -> textwithtooltip ( img_picto ( '' , 'object_barcode' ) . ' ' . $langs -> trans ( " DetailBatchNumber " ), $detail );
2020-05-21 15:05:19 +02:00
} else {
2018-10-03 12:22:41 +02:00
print $langs -> trans ( " NA " );
}
print '</td>' ;
} else {
print '<td></td>' ;
}
}
}
// Weight
2022-05-23 12:24:51 +02:00
print '<td class="center linecolweight">' ;
2021-12-01 16:24:57 +01:00
if ( ! empty ( $lines [ $i ] -> fk_product_type ) && $lines [ $i ] -> fk_product_type == Product :: TYPE_PRODUCT ) {
2021-02-26 20:53:03 +01:00
print $lines [ $i ] -> product -> weight * $lines [ $i ] -> qty . ' ' . measuringUnitString ( 0 , " weight " , $lines [ $i ] -> product -> weight_units );
} else {
print ' ' ;
}
2018-10-03 12:22:41 +02:00
print '</td>' ;
// Volume
2022-05-23 12:24:51 +02:00
print '<td class="center linecolvolume">' ;
2021-12-01 16:24:57 +01:00
if ( ! empty ( $lines [ $i ] -> fk_product_type ) && $lines [ $i ] -> fk_product_type == Product :: TYPE_PRODUCT ) {
2021-02-26 20:53:03 +01:00
print $lines [ $i ] -> product -> volume * $lines [ $i ] -> qty . ' ' . measuringUnitString ( 0 , " volume " , $lines [ $i ] -> product -> volume_units );
} else {
print ' ' ;
}
2018-10-03 12:22:41 +02:00
print '</td>' ;
2018-12-15 13:58:39 +01:00
2021-02-26 20:53:03 +01:00
if ( $action == 'editline' && $lines [ $i ] -> id == $line_id ) {
2019-02-23 21:47:04 +01:00
print '<td class="center" colspan="2" valign="middle">' ;
2020-11-19 20:23:38 +01:00
print '<input type="submit" class="button button-save" id="savelinebutton marginbottomonly" name="save" value="' . $langs -> trans ( " Save " ) . '"><br>' ;
2020-11-23 15:12:52 +01:00
print '<input type="submit" class="button button-cancel" id="cancellinebutton" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '"><br>' ;
2021-02-26 20:53:03 +01:00
} elseif ( $object -> statut == Reception :: STATUS_DRAFT ) {
2018-10-03 12:22:41 +02:00
// edit-delete buttons
2019-02-23 21:47:04 +01:00
print '<td class="linecoledit center">' ;
2021-09-18 22:04:41 +02:00
print '<a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=editline&token=' . newToken () . '&lineid=' . $lines [ $i ] -> id . '">' . img_edit () . '</a>' ;
2018-10-03 12:22:41 +02:00
print '</td>' ;
print '<td class="linecoldelete" width="10">' ;
2021-09-18 22:04:41 +02:00
print '<a class="reposition" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=deleteline&token=' . newToken () . '&lineid=' . $lines [ $i ] -> id . '">' . img_delete () . '</a>' ;
2018-10-03 12:22:41 +02:00
print '</td>' ;
// Display lines extrafields
2021-02-26 20:53:03 +01:00
if ( ! empty ( $rowExtrafieldsStart )) {
2018-10-03 12:22:41 +02:00
print $rowExtrafieldsStart ;
print $rowExtrafieldsView ;
print $rowEnd ;
}
}
print " </tr> " ;
2022-01-28 15:51:18 +01:00
$arrayofpurchaselinealreadyoutput [ $lines [ $i ] -> fk_commandefourndet ] = $lines [ $i ] -> fk_commandefourndet ;
2018-10-03 12:22:41 +02:00
// Display lines extrafields
2021-07-16 19:24:34 +02:00
$extralabelslines = $extrafields -> attributes [ $lines [ $i ] -> table_element ];
2021-12-01 16:24:57 +01:00
if ( ! empty ( $extralabelslines ) && is_array ( $extralabelslines ) && count ( $extralabelslines ) > 0 ) {
2019-11-12 00:15:34 +01:00
$colspan = empty ( $conf -> productbatch -> enabled ) ? 8 : 9 ;
2018-10-05 16:21:50 +02:00
$line = new CommandeFournisseurDispatch ( $db );
2020-03-27 16:02:58 +01:00
$line -> id = $lines [ $i ] -> id ;
$line -> fetch_optionals ();
2019-11-22 14:22:35 +01:00
2021-02-26 20:53:03 +01:00
if ( $action == 'editline' && $lines [ $i ] -> id == $line_id ) {
2019-10-06 14:41:52 +02:00
print $line -> showOptionals ( $extrafields , 'edit' , array ( 'colspan' => $colspan ), $indiceAsked );
2020-05-21 15:05:19 +02:00
} else {
2019-10-06 14:41:52 +02:00
print $line -> showOptionals ( $extrafields , 'view' , array ( 'colspan' => $colspan ), $indiceAsked );
2018-10-03 12:22:41 +02:00
}
}
}
2022-05-23 12:24:51 +02:00
print '</tbody>' ;
2018-10-03 12:22:41 +02:00
// TODO Show also lines ordered but not delivered
print " </table> \n " ;
print '</div>' ;
}
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2018-10-03 12:22:41 +02:00
2019-01-27 11:55:16 +01:00
$object -> fetchObjectLinked ( $object -> id , $object -> element );
2018-10-03 12:22:41 +02:00
/*
* Boutons actions
*/
2021-02-26 20:53:03 +01:00
if (( $user -> socid == 0 ) && ( $action != 'presend' )) {
2018-10-03 12:22:41 +02:00
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
2021-02-26 20:53:03 +01:00
if ( empty ( $reshook )) {
if ( $object -> statut == Reception :: STATUS_DRAFT && $num_prod > 0 ) {
2019-11-12 00:15:34 +01:00
if (( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> reception -> creer ))
2021-02-26 20:53:03 +01:00
|| ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> reception -> reception_advance -> validate ))) {
2021-11-19 13:46:30 +01:00
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=valid&token=' . newToken () . '">' . $langs -> trans ( " Validate " ) . '</a>' ;
2020-05-21 15:05:19 +02:00
} else {
2018-10-03 12:22:41 +02:00
print '<a class="butActionRefused" href="#" title="' . $langs -> trans ( " NotAllowed " ) . '">' . $langs -> trans ( " Validate " ) . '</a>' ;
}
}
2021-11-19 13:46:30 +01:00
// Back to draft
2018-10-04 12:27:10 +02:00
if ( $object -> statut == Reception :: STATUS_VALIDATED && $user -> rights -> reception -> creer ) {
2021-11-19 13:46:30 +01:00
print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id=' . $object -> id . '&action=modif&token=' . newToken () . '">' . $langs -> trans ( 'SetToDraft' ) . '</a></div>' ;
2018-10-03 12:22:41 +02:00
}
// TODO add alternative status
// 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order)
2021-02-26 20:53:03 +01:00
if ( $object -> statut == Reception :: STATUS_CLOSED && $user -> rights -> reception -> creer ) {
2022-06-11 09:46:28 +02:00
if ( isModEnabled ( 'facture' ) && ! 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 ?
2021-09-18 19:34:46 +02:00
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=reopen&token=' . newToken () . '">' . $langs -> trans ( " ClassifyUnbilled " ) . '</a>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-09-18 19:34:46 +02:00
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=reopen&token=' . newToken () . '">' . $langs -> trans ( " ReOpen " ) . '</a>' ;
2018-10-03 12:22:41 +02:00
}
}
// Send
2020-04-10 01:37:04 +02:00
if ( empty ( $user -> socid )) {
2021-02-26 20:53:03 +01:00
if ( $object -> statut > 0 ) {
if ( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) || $user -> rights -> reception -> reception_advance -> send ) {
2020-04-10 01:37:04 +02:00
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=presend&mode=init#formmailbeforetitle">' . $langs -> trans ( 'SendByMail' ) . '</a>' ;
2021-02-26 20:53:03 +01:00
} else {
print '<a class="butActionRefused" href="#">' . $langs -> trans ( 'SendByMail' ) . '</a>' ;
}
2018-10-03 12:22:41 +02:00
}
}
// Create bill
2021-04-12 06:04:08 +02:00
if ((( ! empty ( $conf -> fournisseur -> enabled ) && empty ( $conf -> global -> MAIN_USE_NEW_SUPPLIERMOD )) || ! empty ( $conf -> supplier_invoice -> enabled )) && ( $object -> statut == Reception :: STATUS_VALIDATED || $object -> statut == Reception :: STATUS_CLOSED )) {
2021-04-12 07:37:34 +02:00
if ( $user -> rights -> fournisseur -> facture -> creer || $user -> rights -> supplier_invoice -> creer ) {
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
2021-02-26 20:53:03 +01:00
if ( $object -> statut == Reception :: STATUS_VALIDATED ) {
if ( $user -> rights -> reception -> creer && $object -> statut > 0 && ! $object -> billed ) {
2019-11-12 00:15:34 +01: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
2021-04-12 06:04:08 +02:00
if ((( ! empty ( $conf -> fournisseur -> enabled ) && empty ( $conf -> global -> MAIN_USE_NEW_SUPPLIERMOD )) || ! empty ( $conf -> supplier_order -> 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 ?
2020-10-28 17:49:52 +01:00
$label = " ClassifyBilled " ;
$paramaction = 'classifybilled' ;
2018-10-03 12:22:41 +02:00
}
2021-09-27 15:41:58 +02:00
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=' . $paramaction . '&token=' . newToken () . '">' . $langs -> trans ( $label ) . '</a>' ;
2018-10-03 12:22:41 +02:00
}
}
2021-02-26 20:53:03 +01:00
if ( $user -> rights -> reception -> supprimer ) {
2021-09-18 22:04:41 +02:00
print '<a class="butActionDelete" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=delete&token=' . newToken () . '">' . $langs -> trans ( " Delete " ) . '</a>' ;
2018-10-03 12:22:41 +02:00
}
}
print '</div>' ;
}
/*
* Documents generated
*/
2021-02-26 20:53:03 +01:00
if ( $action != 'presend' && $action != 'editline' ) {
2020-10-28 17:49:52 +01:00
print '<div class="fichecenter"><div class="fichehalfleft">' ;
2018-10-03 12:22:41 +02:00
2020-10-28 17:49:52 +01:00
$objectref = dol_sanitizeFileName ( $object -> ref );
2019-11-12 00:15:34 +01:00
$filedir = $conf -> reception -> dir_output . " / " . $objectref ;
2018-10-03 12:22:41 +02:00
$urlsource = $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id ;
2019-11-12 00:15:34 +01:00
$genallowed = $user -> rights -> reception -> lire ;
$delallowed = $user -> rights -> reception -> creer ;
2018-12-15 13:58:39 +01:00
2020-09-10 01:49:09 +02:00
print $formfile -> showdocuments ( 'reception' , $objectref , $filedir , $urlsource , $genallowed , $delallowed , $object -> model_pdf , 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 , '' );
2021-10-23 17:18:35 +02:00
print '</div><div class="fichehalfright">' ;
print '</div></div>' ;
2018-10-03 12:22:41 +02:00
}
2018-12-15 13:58:39 +01:00
2020-11-08 14:39:20 +01:00
// Presend form
$modelmail = 'shipping_send' ;
$defaulttopic = 'SendReceptionRef' ;
$diroutput = $conf -> reception -> dir_output ;
$trackid = 'rec' . $object -> id ;
include DOL_DOCUMENT_ROOT . '/core/tpl/card_presend.tpl.php' ;
2018-10-03 12:22:41 +02:00
}
llxFooter ();
$db -> close ();