function fiche(&$PDOdb, &$expedition, &$TImport)
{
    global $langs, $db;
    llxHeader();
    $head = shipping_prepare_head($expedition);
    $title = $langs->trans("Shipment");
    dol_fiche_head($head, 'dispatch', $title, 0, 'dispatch');
    enteteexpedition($expedition);
    echo '<br>';
    if ($expedition->statut == 0) {
        //Form pour import de fichier
        if ($conf->global->DISPATCH_USE_IMPORT_FILE) {
            $form = new TFormCore('auto', 'formimport', 'post', true);
            echo $form->hidden('action', 'SAVE');
            echo $form->hidden('id', $expedition->id);
            echo $form->fichier('Fichier à importer', 'file1', '', 80);
            echo $form->btsubmit('Envoyer', 'btsend');
            $form->end();
        }
        ?>
		<script>
			$(document).ready(function() {

				$('#lot_number').change(function() {
					var lot_number = $(this).val();

					$.ajax({
						url: 'script/interface.php',
						method: 'GET',
						data: {
							lot_number: lot_number,
							productid: $('#lineexpeditionid').find(':selected').attr('fk-product'),
							type:'get',
							get:'autocomplete_asset'
						}
					}).done(function(results) {
						var json_results = $.parseJSON(results);

						$('#numserie option').remove();
						cpt = 0;
						$.each(json_results, function(index) {
							var obj = json_results[index];
							cpt ++;
							$('#numserie').append($('<option>', {
								value: obj.serial_number,
								text: obj.serial_number + ' - ' + obj.qty + ' ' +obj.unite_string
							}));

							$('#quantity').val(obj.qty);
							if(obj.unite != 'unité(s)'){
								$('#quantity_unit').show();
								$('#units_lable').remove();
								$('#quantity_unit option[value='+obj.unite+']').attr("selected","selected");
							}
							else{
								$('#quantity_unit').hide();
								$('#quantity_unit option[value=0]').attr("selected","selected");
								$('#quantity').after('<span id="units_lable"> unité(s)</span>');
							}
						});
					});
				});
				
				$('#lineexpeditionid').change(function() {
					var productid = $(this).find(':selected').attr('fk-product');

					$.ajax({
						url: 'script/interface.php',
						method: 'GET',
						data: {
							productid: productid,
							type:'get',
							get:'autocomplete_lot_number'
						}
					}).done(function(results) {
						var json_results = $.parseJSON(results);

						$('#lot_number option').remove();
						
						$.each(json_results, function(index) {
							var obj = json_results[index];
							
							$('#lot_number').append($('<option>', {
								value: obj.lot_number,
								text: obj.label
							}));
						});
					});
				});
			});
		</script>
		<?php 
        //Form pour ajouter un équipement directement
        $DoliForm = new FormProduct($db);
        $form = new TFormCore('auto', 'formaddasset', 'post', true);
        echo $form->hidden('action', 'edit');
        echo $form->hidden('mode', 'addasset');
        echo $form->hidden('id', $expedition->id);
        $TLotNumber = array(' -- aucun produit sélectionné -- ');
        /*$sql = "SELECT DISTINCT(lot_number),rowid, SUM(contenancereel_value) as qty, contenancereel_units as unit FROM ".MAIN_DB_PREFIX."asset GROUP BY lot_number ORDER BY lot_number ASC";
        
        		$PDOdb->Execute($sql);
        		$Tres = $PDOdb->Get_All();
        		foreach($Tres as $res){
        			
        			$asset = new TAsset;
        			$asset->load($PDOdb, $res->rowid);
        			$asset->load_asset_type($PDOdb);
        			//pre($asset,true);exit;
        			$TLotNumber[$res->lot_number] = $res->lot_number." / ".$res->qty." ".(($asset->assetType->measuring_units == 'unit') ? 'unité(s)' : measuring_units_string($res->unit,$asset->assetType->measuring_units));
        		}
        		*/
        $TSerialNumber = array(' -- aucun lot sélectionné -- ');
        /*$sql = "SELECT DISTINCT(serial_number),contenancereel_value, contenancereel_units FROM ".MAIN_DB_PREFIX."asset ORDER BY serial_number ASC";
        		$PDOdb->Execute($sql);
        		while ($PDOdb->Get_line()) {
        			$TSerialNumber[$PDOdb->Get_field('serial_number')] = $PDOdb->Get_field('serial_number').' / '.$PDOdb->Get_field('contenancereel_value')." ".measuring_units_string($PDOdb->Get_field('contenancereel_units'),'weight');
        		}
        		*/
        echo 'Produit expédié<select id="lineexpeditionid" name="lineexpeditionid"><option value=""></option>';
        $TProduct = array('');
        $sql = "SELECT DISTINCT(ed.rowid),p.rowid as fk_product,p.ref,p.label ,ed.qty\n\t\t\t\tFROM " . MAIN_DB_PREFIX . "product as p\n\t\t\t\t\tLEFT JOIN " . MAIN_DB_PREFIX . "commandedet as cd ON (cd.fk_product = p.rowid)\n\t\t\t\t\tLEFT JOIN " . MAIN_DB_PREFIX . "expeditiondet as ed ON (ed.fk_origin_line = cd.rowid)\n\t\t\t\tWHERE ed.fk_expedition = " . $expedition->id . "";
        $PDOdb->Execute($sql);
        while ($obj = $PDOdb->Get_line()) {
            //$TProduct[$PDOdb->Get_field('rowid')] = $PDOdb->Get_field('ref').' - '.$PDOdb->Get_field('label');
            echo '<option value="' . $obj->rowid . '" fk-product="' . $obj->fk_product . '">' . $obj->ref . ' - ' . $obj->label . ' x ' . $obj->qty . '</option>';
        }
        echo '</select><br />';
        //echo $form->combo('Produit expédié', 'lineexpeditionid', $TProduct, '').'<br>';
        echo $form->combo('Numéro de Lot', 'lot_number', $TLotNumber, '') . '<br>';
        echo $form->combo('Numéro de série à ajouter', 'numserie', $TSerialNumber, '') . '<br>';
        echo $form->texte('Quantité', 'quantity', '', 10) . " " . $DoliForm->load_measuring_units('quantity_unit" id="quantity_unit', 'weight');
        echo $form->btsubmit('Ajouter', 'btaddasset');
        $form->end();
        echo '<br>';
    }
    tabImport($TImport, $expedition);
    llxFooter();
}
function fiche(&$commande, &$TImport)
{
    global $langs, $db, $conf;
    llxHeader();
    $head = ordersupplier_prepare_head($commande);
    $title = $langs->trans("SupplierOrder");
    dol_fiche_head($head, 'recepasset', $title, 0, 'order');
    entetecmd($commande);
    $form = new TFormCore('auto', 'formrecept', 'post', true);
    echo $form->hidden('action', 'SAVE');
    echo $form->hidden('id', $commande->id);
    if ($commande->statut < 5 && $conf->global->DISPATCH_USE_IMPORT_FILE) {
        echo $form->fichier('Fichier à importer', 'file1', '', 80);
        echo $form->btsubmit('Envoyer', 'btsend');
    }
    tabImport($TImport, $commande);
    $form->end();
    _list_already_dispatched($commande);
    llxFooter();
}
function liste()
{
    global $langs, $conf, $user;
    $PDOdb = new TPDOdb();
    llxHeader('', 'Query', '', '', 0, 0, array(), array('/query/css/query.css'));
    dol_fiche_head();
    $sql = "SELECT rowid as 'Id', type,nb_result_max, title,expert,0 as 'delete' \n\tFROM " . MAIN_DB_PREFIX . "query\n\tWHERE 1\n\t ";
    $formCore = new TFormCore('auto', 'formQ', 'get');
    $r = new TListviewTBS('lQuery');
    echo $r->render($PDOdb, $sql, array('link' => array('Id' => '<a href="?action=view&id=@val@">' . img_picto('Edit', 'edit.png') . ' @val@</a>', 'title' => '<a href="?action=run&id=@Id@">' . img_picto('Run', 'object_cron.png') . ' @val@</a>', 'delete' => '<a href="?action=delete&id=@Id@" onclick="return(confirm(\'' . $langs->trans('ConfirmDeleteMessage') . '\'));">' . img_picto('Delete', 'delete.png') . '</a>'), 'orderBy' => array('title' => 'ASC'), 'hide' => array('type', 'nb_result_max'), 'title' => array('title' => $langs->trans('Title'), 'expert' => $langs->trans('Expert'), 'delete' => $langs->trans('Delete')), 'translate' => array('expert' => array(0 => $langs->trans('No'), 1 => $langs->trans('Yes'), 2 => $langs->trans('Free'))), 'search' => array('title' => true)));
    $formCore->end();
    $formCore = new TFormCore('auto', 'formUPQ', 'post', true);
    echo $formCore->hidden('action', 'up_query');
    echo $formCore->fichier($langs->trans('QueryToUpload'), 'query_to_upload', '', 10) . ' ' . $formCore->btsubmit($langs->trans('UploadQuery'), 'bt_upquery');
    $formCore->end();
    dol_fiche_end();
    llxFooter();
}
            }
        }
    }
}
$page_name = "RemiseImport";
llxHeader('', $langs->trans($page_name));
// Subheader
$linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">' . $langs->trans("BackToModuleList") . '</a>';
print_fiche_titre($langs->trans($page_name), $linkback);
// Configuration header
$head = remiseAdminPrepareHead();
dol_fiche_head($head, 'import', $langs->trans("Module104921Name"), 0, "remise@remise");
$form = new TFormCore('auto', 'formImport', 'post', true);
echo $form->hidden('action', 'import');
print_titre('Etape 1');
echo $form->fichier('Fichier à importer', 'f1', '', 50);
echo $form->btsubmit('Prévisualiser', 'bt_preview');
?>
<br /><small>(Colonnes : n° département,poids,palier,montant - séparateur : ';')</small>
<?php 
if ($etape > 1) {
    print_titre('Etape 2');
    echo $form->zonetexte('', 'data', serialize($TData), 80, 5, ' style="display:none;" ');
    ?>
	<table class="liste">
		<tr class="liste_titre">
			<td>Département</td>
			<td>Poids</td>
			<td>ou Palier</td>
			<td>Montant</td>
		</tr>