function _autocomplete_lot_number(&$PDOdb, $productid)
{
    global $db, $conf, $langs;
    $langs->load('other');
    dol_include_once('/core/lib/product.lib.php');
    $sql = "SELECT DISTINCT(lot_number),rowid, SUM(contenancereel_value) as qty, contenancereel_units as unit\n\t\t\tFROM " . MAIN_DB_PREFIX . "asset\n\t\t\tWHERE fk_product = " . $productid . " GROUP BY lot_number,contenancereel_units,rowid";
    $PDOdb->Execute($sql);
    $TLotNumber = array('');
    $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]['lot_number'] = $res->lot_number;
        $TLotNumber[$res->lot_number]['label'] = $res->lot_number . " / " . $res->qty . " " . ($asset->assetType->measuring_units == 'unit' ? 'unité(s)' : measuring_units_string($res->unit, $asset->assetType->measuring_units));
    }
    return $TLotNumber;
}
 /** Overloading the doActions function : replacing the parent's function with the one below 
  *  @param      parameters  meta datas of the hook (context, etc...) 
  *  @param      object             the object you want to process (an invoice if you are in invoice module, a propale in propale's module, etc...) 
  *  @param      action             current action (if set). Generally create or edit or null 
  *  @return       void 
  */
 function beforePDFCreation($parameters, &$object, &$action, $hookmanager)
 {
     // pour implementation dans Dolibarr 3.7
     if (in_array('pdfgeneration', explode(':', $parameters['context']))) {
         define('INC_FROM_DOLIBARR', true);
         dol_include_once('/dispatch/config.php');
         dol_include_once('/asset/class/asset.class.php');
         dol_include_once('/dispatch/class/dispatchdetail.class.php');
         global $conf;
         if (isset($parameters['object']) && get_class($object) == 'Expedition') {
             $PDOdb = new TPDOdb();
             foreach ($object->lines as &$line) {
                 $sql = 'SELECT DISTINCT(lot_number),rowid FROM ' . MAIN_DB_PREFIX . 'expeditiondet_asset WHERE fk_expeditiondet = ' . $line->line_id;
                 $PDOdb->Execute($sql);
                 $TRes = $PDOdb->Get_All();
                 if (count($TRes) > 0) {
                     $line->desc .= "<br>Lot(s) expédié(s) : ";
                     foreach ($TRes as $res) {
                         $dispatchDetail = new TDispatchDetail();
                         $dispatchDetail->load($PDOdb, $res->rowid);
                         $asset = new TAsset();
                         $asset->load($PDOdb, $dispatchDetail->fk_asset);
                         $asset->load_asset_type($PDOdb);
                         $unite = $asset->assetType->measuring_units == 'unit' ? 'unité(s)' : measuring_units_string($dispatchDetail->weight_reel_unit, $asset->assetType->measuring_units);
                         $desc = "<br>- " . $res->lot_number . " x " . $dispatchDetail->weight_reel . " " . $unite;
                         if (empty($conf->global->DISPATCH_HIDE_DLUO_PDF)) {
                             $desc .= ' (DLUO : ' . $asset->get_date('dluo') . ')';
                         }
                         $line->desc .= $desc;
                     }
                 }
             }
         }
         //pre($object,true);exit;
     }
 }
function tabImport(&$TImport, &$expedition)
{
    global $langs, $db;
    $form = new TFormCore();
    $formDoli = new Form($db);
    $formproduct = new FormProduct($db);
    $PDOdb = new TPDOdb();
    print count($TImport) . ' équipement(s) dans votre expédition';
    ?>
	<table width="100%" class="border">
		<tr class="liste_titre">
			<td>Produit</td>
			<td>Numéro de série</td>
			<td>Numéro de Lot</td>
			<td>Quantité</td>
			<td>&nbsp;</td>
		</tr>
		
	<?php 
    $prod = new Product($db);
    $form->Set_typeaff('view');
    if (is_array($TImport)) {
        foreach ($TImport as $k => $line) {
            if ($prod->id == 0 || $line['ref'] != $prod->ref) {
                if (!empty($line['fk_product'])) {
                    $prod->fetch($line['fk_product']);
                } else {
                    $prod->fetch('', $line['ref']);
                }
            }
            $asset = new TAsset();
            $asset->loadBy($PDOdb, $line['numserie'], 'serial_number');
            $asset->load_asset_type($PDOdb);
            $assetLot = new TAssetLot();
            $assetLot->loadBy($PDOdb, $line['lot_number'], 'lot_number');
            $Trowid = TRequeteCore::get_id_from_what_you_want($PDOdb, MAIN_DB_PREFIX . "expeditiondet_asset", array('fk_asset' => $asset->rowid, 'fk_expeditiondet' => $line['fk_expeditiondet']));
            ?>
<tr>
					<td><?php 
            echo $prod->getNomUrl(1) . $form->hidden('TLine[' . $k . '][fk_product]', $prod->id) . $form->hidden('TLine[' . $k . '][ref]', $prod->ref);
            ?>
</td>
					<td><a href="<?php 
            echo dol_buildpath('/asset/fiche.php?id=' . $asset->rowid, 1);
            ?>
"><?php 
            echo $form->texte('', 'TLine[' . $k . '][numserie]', $line['numserie'], 30);
            ?>
</a></td>
					<td><a href="<?php 
            echo dol_buildpath('/asset/fiche_lot.php?id=' . $assetLot->rowid, 1);
            ?>
"><?php 
            echo $form->texte('', 'TLine[' . $k . '][lot_number]', $line['lot_number'], 30);
            ?>
</a></td>
					<td><?php 
            echo $line['quantity'] . " " . ($asset->assetType->measuring_units == 'unit' ? 'unité(s)' : measuring_units_string($line['quantity_unit'], $asset->assetType->measuring_units));
            ?>
</td>
					<td>
						<?php 
            if ($expedition->statut != 1) {
                echo '<a href="?action=DELETE_LINE&k=' . $k . '&id=' . $expedition->id . '&rowid=' . $Trowid[0] . '">' . img_delete() . '</a>';
            }
            ?>
					</td>
				</tr>
				
				<?php 
        }
    }
    ?>
			
		
	</table>
	<br>
	<?php 
}
 private function create_flacon_stock_mouvement(&$PDOdb, &$linedetail, $numref, $fk_soc = 0)
 {
     global $user, $langs, $conf;
     dol_include_once('/asset/class/asset.class.php');
     dol_include_once('/product/class/product.class.php');
     dol_include_once('/expedition/class/expedition.class.php');
     $asset = new TAsset();
     $asset->load($PDOdb, $linedetail->fk_asset);
     if ($conf->global->clilatoxan) {
         $poids_destocke = $this->calcule_poids_destocke($PDOdb, $linedetail);
         $poids_destocke = $poids_destocke * pow(10, $asset->contenancereel_units);
     } else {
         $poids_destocke = $linedetail->weight_reel;
     }
     /*pre($linedetail,true);
     		echo $poids_destocke;exit;*/
     //$asset->contenancereel_value = $asset->contenancereel_value - $poids_destocke;
     $asset->fk_societe_localisation = $fk_soc;
     //Vas destocker l'équipement mais pas dolibarr
     $asset->save($PDOdb, $user, $langs->trans("ShipmentValidatedInDolibarr", $numref), -$poids_destocke, false, 0, true);
     /*$stock = new TAssetStock;
     		$stock->mouvement_stock($PDOdb, $user, $asset->getId(), -$poids_destocke, $langs->trans("ShipmentValidatedInDolibarr",$numref), $linedetail->fk_expeditiondet);
     */
     return $poids_destocke;
 }
dol_include_once('/contrat/class/contrat.class.php');
dol_include_once('/product/class/html.formproduct.class.php');
dol_include_once('/fichinter/class/fichinter.class.php');
dol_include_once('/asset/class/asset.class.php');
dol_include_once('/core/lib/product.lib.php');
$PDOdb = new TPDOdb();
$type_object = GETPOST('type_object');
$id = (int) GETPOST('id');
$dispatch = new TDispatch();
$dispatch->loadByObject($PDOdb, $id, $type_object);
$action = GETPOST('action');
switch ($action) {
    case 'save':
        $TLine = GETPOST('TLine');
        if (!empty($TLine[-1]['serial_number']) && (!empty($TLine[-1]['fk_object']) || GETPOST('type_object') === 'ticketsup')) {
            $asset = new TAsset();
            $asset->loadReference($PDOdb, $TLine[-1]['serial_number']);
            if ($asset->getId() > 0) {
                $k = $dispatch->addChild($PDOdb, 'TDispatchAsset');
                $dispatch->TDispatchAsset[$k]->fk_asset = $asset->getId();
                $dispatch->TDispatchAsset[$k]->fk_object = $TLine[-1]['fk_object'];
                $dispatch->TDispatchAsset[$k]->object_type = $type_object;
                $dispatch->TDispatchAsset[$k]->asset = $asset;
                $dispatch->save($PDOdb);
            }
        }
        break;
    case 'delete-line':
        $k = (int) GETPOST('k');
        $dispatch->TDispatchAsset[$k]->to_delete = true;
        $dispatch->save($PDOdb);
function _action()
{
    global $user, $db, $conf, $langs;
    $PDOdb = new TPDOdb();
    //$PDOdb->debug=true;
    /*******************************************************************
     * ACTIONS
     *
     * Put here all code to do according to value of "action" parameter
     ********************************************************************/
    $action = __get('action', 'view');
    switch ($action) {
        case 'new':
        case 'add':
            $assetOf = new TAssetOF();
            $assetOf->set_values($_REQUEST);
            $fk_product = __get('fk_product', 0, 'int');
            $fk_nomenclature = __get('fk_nomenclature', 0, 'int');
            _fiche($PDOdb, $assetOf, 'edit', $fk_product, $fk_nomenclature);
            break;
        case 'edit':
            $assetOf = new TAssetOF();
            $assetOf->load($PDOdb, $_REQUEST['id']);
            _fiche($PDOdb, $assetOf, 'edit');
            break;
        case 'create':
        case 'save':
            $assetOf = new TAssetOF();
            if (!empty($_REQUEST['id'])) {
                $assetOf->load($PDOdb, $_REQUEST['id'], false);
                $mode = 'view';
            } else {
                $mode = $action == 'create' ? 'view' : 'edit';
            }
            $assetOf->set_values($_REQUEST);
            $fk_product = __get('fk_product_to_add', 0);
            $quantity_to_create = __get('quantity_to_create', 1);
            $fk_nomenclature = __get('fk_nomenclature', 0);
            if ($fk_product > 0) {
                $assetOf->addLine($PDOdb, $fk_product, 'TO_MAKE', $quantity_to_create, 0, '', $fk_nomenclature);
            }
            if (!empty($_REQUEST['TAssetOFLine'])) {
                foreach ($_REQUEST['TAssetOFLine'] as $k => $row) {
                    if (!isset($assetOf->TAssetOFLine[$k])) {
                        $assetOf->TAssetOFLine[$k] = new TAssetOFLine();
                    }
                    if (!empty($conf->global->ASSET_DEFINED_WORKSTATION_BY_NEEDED)) {
                        $assetOf->TAssetOFLine[$k]->set_workstations($PDOdb, $row['fk_workstation']);
                        unset($row['fk_workstation']);
                    }
                    $assetOf->TAssetOFLine[$k]->set_values($row);
                }
                foreach ($assetOf->TAssetOFLine as &$line) {
                    $line->TAssetOFLine = array();
                }
            }
            if (!empty($_REQUEST['TAssetWorkstationOF'])) {
                foreach ($_REQUEST['TAssetWorkstationOF'] as $k => $row) {
                    //Association des utilisateurs à un poste de travail
                    if (!empty($conf->global->ASSET_DEFINED_USER_BY_WORKSTATION)) {
                        $assetOf->TAssetWorkstationOF[$k]->set_users($PDOdb, $row['fk_user']);
                        unset($row['fk_user']);
                    }
                    //Association des opérations à une poste de travail (mode opératoire)
                    if (!empty($conf->global->ASSET_DEFINED_OPERATION_BY_WORKSTATION)) {
                        $assetOf->TAssetWorkstationOF[$k]->set_tasks($PDOdb, $row['fk_task']);
                        unset($row['fk_task']);
                    }
                    $assetOf->TAssetWorkstationOF[$k]->set_values($row);
                }
            }
            $assetOf->entity = $conf->entity;
            //Permet de mettre à jour le lot de l'OF parent
            if (!empty($assetOf->fk_assetOf_parent)) {
                $assetOf->update_parent = true;
            }
            $assetOf->save($PDOdb);
            _fiche($PDOdb, $assetOf, $mode);
            break;
        case 'valider':
            $error = 0;
            $assetOf = new TAssetOF();
            $id = GETPOST('id');
            if (empty($id)) {
                exit('Where is Waldo ?');
            }
            $assetOf->load($PDOdb, $id);
            //Si use_lot alors check de la saisie du lot pour chaque ligne avant validation
            if (!empty($conf->global->USE_LOT_IN_OF) && !empty($conf->global->OF_LOT_MANDATORY)) {
                if (!$assetOf->checkLotIsFill()) {
                    _fiche($PDOdb, $assetOf, 'view');
                    break;
                }
            }
            $res = $assetOf->validate($PDOdb);
            if ($res > 0) {
                //Relaod de l'objet OF parce que createOfAndCommandesFourn() fait tellement de truc que c'est le bordel
                $assetOf = new TAssetOF();
                if (!empty($_REQUEST['id'])) {
                    $assetOf->load($PDOdb, $_REQUEST['id'], false);
                }
            }
            _fiche($PDOdb, $assetOf, 'view');
            break;
        case 'lancer':
            $assetOf = new TAssetOF();
            $id = GETPOST('id');
            if (empty($id)) {
                exit('Where is Waldo ?');
            }
            $assetOf->load($PDOdb, $id);
            $assetOf->openOF($PDOdb);
            $assetOf->load($PDOdb, $id);
            _fiche($PDOdb, $assetOf, 'view');
            break;
        case 'terminer':
            $assetOf = new TAssetOF();
            $assetOf->load($PDOdb, $_REQUEST['id']);
            $assetOf->closeOF($PDOdb);
            $assetOf->load($PDOdb, $_REQUEST['id']);
            _fiche($PDOdb, $assetOf, 'view');
            break;
        case 'delete':
            $assetOf = new TAssetOF();
            $assetOf->load($PDOdb, $_REQUEST['id']);
            //$PDOdb->db->debug=true;
            $assetOf->delete($PDOdb);
            header('Location: ' . dol_buildpath('/of/liste_of.php?delete_ok=1', 1));
            exit;
            break;
        case 'view':
            $assetOf = new TAssetOF();
            $assetOf->load($PDOdb, $_REQUEST['id']);
            _fiche($PDOdb, $assetOf, 'view');
            break;
        case 'createDocOF':
            $id_of = $_REQUEST['id'];
            $assetOf = new TAssetOF();
            $assetOf->load($PDOdb, $id_of, false);
            $TOFToGenerate = array($assetOf->rowid);
            if ($conf->global->ASSET_CONCAT_PDF) {
                $assetOf->getListeOFEnfants($PDOdb, $TOFToGenerate, $assetOf->rowid);
            }
            //			var_dump($TOFToGenerate);exit;
            foreach ($TOFToGenerate as $id_of) {
                $assetOf = new TAssetOF();
                $assetOf->load($PDOdb, $id_of, false);
                //echo $id_of;
                $TRes[] = generateODTOF($PDOdb, $assetOf);
                //echo '...ok<br />';
            }
            $TFilePath = get_tab_file_path($TRes);
            //	var_dump($TFilePath);exit;
            if ($conf->global->ASSET_CONCAT_PDF) {
                ob_start();
                $pdf = pdf_getInstance();
                if (class_exists('TCPDF')) {
                    $pdf->setPrintHeader(false);
                    $pdf->setPrintFooter(false);
                }
                $pdf->SetFont(pdf_getPDFFont($langs));
                if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) {
                    $pdf->SetCompression(false);
                }
                //$pdf->SetCompression(false);
                $pagecount = concatPDFOF($pdf, $TFilePath);
                if ($pagecount) {
                    $pdf->Output($TFilePath[0], 'F');
                    if (!empty($conf->global->MAIN_UMASK)) {
                        @chmod($file, octdec($conf->global->MAIN_UMASK));
                    }
                }
                ob_clean();
            }
            header("Location: " . DOL_URL_ROOT . "/document.php?modulepart=of&entity=1&file=" . $TRes[0]['dir_name'] . "/" . $TRes[0]['num_of'] . ".pdf");
            break;
        case 'control':
            $assetOf = new TAssetOF();
            $assetOf->load($PDOdb, $_REQUEST['id']);
            $subAction = __get('subAction', false);
            if ($subAction) {
                $assetOf->updateControl($PDOdb, $subAction);
            }
            _fiche_control($PDOdb, $assetOf);
            break;
        case 'addAssetLink':
            $assetOf = new TAssetOF();
            $assetOf->load($PDOdb, __get('id', 0, 'int'));
            $idLine = __get('idLine', 0, 'int');
            $idAsset = __get('idAsset', 0, 'int');
            if ($idLine && $idAsset) {
                $find = false;
                foreach ($assetOf->TAssetOFLine as $TAssetOFLine) {
                    if ($TAssetOFLine->getId() == $idLine) {
                        $find = true;
                        $asset = new TAsset();
                        $asset->load($PDOdb, $idAsset);
                        $TAssetOFLine->addAssetLink($asset);
                        break;
                    }
                }
                if (!$find) {
                    setEventMessage('Erreur sur l\'identifiant de l\'équipement', 'errors');
                }
            } else {
                setEventMessage('Erreur sur la saisie de l\'équipement.', 'errors');
            }
            _fiche($PDOdb, $assetOf, 'edit');
            break;
        case 'deleteAssetLink':
            $assetOf = new TAssetOF();
            $assetOf->load($PDOdb, __get('id', 0, 'int'));
            $idLine = __get('idLine', 0, 'int');
            $idAsset = __get('idAsset', 0, 'int');
            if ($idLine && $idAsset) {
                TAsset::del_element_element($PDOdb, $idLine, $idAsset, 'TAsset');
            } else {
                setEventMessage('Erreur sur un des identifiants', 'errors');
            }
            _fiche($PDOdb, $assetOf, 'edit');
            break;
        default:
            $assetOf = new TAssetOF();
            $assetOf->load($PDOdb, $_REQUEST['id'], false);
            _fiche($PDOdb, $assetOf, 'view');
            break;
    }
}
function tabImport(&$TImport, &$commande)
{
    global $langs, $db, $conf;
    $PDOdb = new TPDOdb();
    $form = new TFormCore();
    $formDoli = new Form($db);
    $formproduct = new FormProduct($db);
    if ($commande->statut >= 5 || $commande->statut <= 2) {
        $form->type_aff = "view";
    }
    if ($commande->statut <= 2 || $commande->statut >= 6) {
        print $langs->trans("OrderStatusNotReadyToDispatch");
    }
    _show_product_ventil($TImport, $commande, $form);
    print count($TImport) . ' équipement(s) dans votre réception';
    ?>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#dispatchAsset").change(function() {
				$("#actionVentilation").addClass("error").html("<?php 
    echo $langs->trans('SaveBeforeVentil');
    ?>
");
			});
		});
	</script>
	<table width="100%" class="border" id="dispatchAsset">
		<tr class="liste_titre">
			<td>Produit</td>
			<td>Numéro de Série</td>
			<td>Numéro de Lot</td>
			<td><?php 
    echo $langs->trans('Warehouse');
    ?>
</td>
			<?php 
    if ($conf->global->ASSET_SHOW_DLUO) {
        ?>
				<td>DLUO</td>
			<?php 
    }
    if (empty($conf->global->DISPATCH_USE_ONLY_UNIT_ASSET_RECEPTION)) {
        ?>
			<td>Quantité</td>
			<?php 
        if (!empty($conf->global->DISPATCH_SHOW_UNIT_RECEPTION)) {
            echo '<td>Unité</td>';
        }
    }
    if ($conf->global->clinomadic->enabled) {
        ?>
				<td>IMEI</td>
				<td>Firmware</td>
				<?php 
    }
    ?>
			<td>&nbsp;</td>
		</tr>

	<?php 
    $prod = new Product($db);
    $warning_asset = false;
    if (is_array($TImport)) {
        foreach ($TImport as $k => $line) {
            if ($prod->id == 0 || $line['ref'] != $prod->ref) {
                if (empty($line['fk_product']) === false) {
                    $prod->fetch($line['fk_product']);
                } else {
                    if (empty($line['ref']) === false) {
                        $prod->fetch('', $line['ref']);
                    } else {
                        continue;
                    }
                }
            }
            ?>
<tr>
					<td><?php 
            echo $prod->getNomUrl(1) . $form->hidden('TLine[' . $k . '][fk_product]', $prod->id) . $form->hidden('TLine[' . $k . '][ref]', $prod->ref) . " - " . $prod->label;
            ?>
</td>
					<td><?php 
            echo $form->texte('', 'TLine[' . $k . '][numserie]', $line['numserie'], 30);
            $asset = new TAsset();
            if (empty($line['numserie'])) {
                echo img_picto($langs->trans('SerialNumberNeeded'), 'warning.png');
                $warning_asset = true;
            } else {
                if ($asset->loadReference($PDOdb, $line['numserie'])) {
                    echo '<a href="' . dol_buildpath('/asset/fiche.php?id=' . $asset->getId(), 1) . '">' . img_picto('Equipement lié à cet import', 'info.png') . '</a>';
                } else {
                    echo img_picto('Aucun équipement créé en Base', 'warning.png');
                    $warning_asset = true;
                }
            }
            echo $form->hidden('TLine[' . $k . '][commande_fournisseurdet_asset]', $line['commande_fournisseurdet_asset'], 30);
            ?>
					</td>
					<td><?php 
            echo $form->texte('', 'TLine[' . $k . '][lot_number]', $line['lot_number'], 30);
            ?>
</td>
					<td rel="entrepotChild" fk_product="<?php 
            echo $prod->id;
            ?>
"><?php 
            $formproduct = new FormProduct($db);
            $formproduct->loadWarehouses();
            if (count($formproduct->cache_warehouses) > 1) {
                print $formproduct->selectWarehouses($line['fk_warehouse'], 'TLine[' . $k . '][entrepot]', '', 1, 0, $prod->id, '', 0, 1);
            } elseif (count($formproduct->cache_warehouses) == 1) {
                print $formproduct->selectWarehouses($line['fk_warehouse'], 'TLine[' . $k . '][entrepot]', '', 0, 0, $prod->id, '', 0, 1);
            } else {
                print $langs->trans("NoWarehouseDefined");
            }
            ?>
</td>
					<?php 
            if (!empty($conf->global->ASSET_SHOW_DLUO)) {
                ?>
					<td><?php 
                echo $form->calendrier('', 'TLine[' . $k . '][dluo]', date('d/m/Y', strtotime($line['dluo'])));
                ?>
</td>
					<?php 
            }
            if (empty($conf->global->DISPATCH_USE_ONLY_UNIT_ASSET_RECEPTION)) {
                ?>
						<td><?php 
                echo $form->texte('', 'TLine[' . $k . '][quantity]', $line['quantity'], 10);
                ?>
</td><?php 
                if (!empty($conf->global->DISPATCH_SHOW_UNIT_RECEPTION)) {
                    echo '<td>' . ($commande->statut < 5) ? $formproduct->select_measuring_units('TLine[' . $k . '][quantity_unit]', 'weight', $line['quantity_unit']) : measuring_units_string($line['quantity_unit'], 'weight') . '</td>';
                }
            } else {
                echo $form->hidden('TLine[' . $k . '][quantity]', $line['quantity']);
                echo $form->hidden('TLine[' . $k . '][quantity_unit]', $line['quantity_unit']);
            }
            if ($conf->global->clinomadic->enabled) {
                ?>
						<td><?php 
                echo $form->texte('', 'TLine[' . $k . '][imei]', $line['imei'], 30);
                ?>
</td>
						<td><?php 
                echo $form->texte('', 'TLine[' . $k . '][firmware]', $line['firmware'], 30);
                ?>
</td>
						<?php 
            }
            ?>
					<td>
						<?php 
            if ($commande->statut < 5) {
                echo '<a href="?action=DELETE_LINE&k=' . $k . '&id=' . $commande->id . '&rowid=' . $line['commande_fournisseurdet_asset'] . '">' . img_delete() . '</a>';
            }
            ?>
					</td>
				</tr>
				<?php 
        }
    }
    if ($commande->statut < 5 && $commande->statut > 2) {
        $pListe[0] = "Sélectionnez un produit";
        foreach ($commande->lines as $line) {
            if ($line->fk_product) {
                $pListe[$line->fk_product] = $line->product_ref . " - " . $line->product_label;
            }
        }
        $defaultDLUO = '';
        if ($conf->global->DISPATCH_DLUO_BY_DEFAULT) {
            $defaultDLUO = date('d/m/Y', strtotime(date('Y-m-d') . " " . $conf->global->DISPATCH_DLUO_BY_DEFAULT));
        }
        echo $defaultDLUO;
        ?>
<tr style="background-color: lightblue;">
					<td><?php 
        print $form->combo('', 'new_line_fk_product', $pListe, '');
        ?>
</td>
					<td><?php 
        echo $form->texte('', 'TLine[-1][numserie]', '', 30);
        ?>
</td>
					<td><?php 
        echo $form->texte('', 'TLine[-1][lot_number]', '', 30);
        ?>
</td>
					<td><?php 
        $formproduct = new FormProduct($db);
        $formproduct->loadWarehouses();
        if (count($formproduct->cache_warehouses) > 1) {
            print $formproduct->selectWarehouses('', 'TLine[-1][entrepot]', '', 1, 0, $prod->id, '', 0, 1);
        } elseif (count($formproduct->cache_warehouses) == 1) {
            print $formproduct->selectWarehouses('', 'TLine[-1][entrepot]', '', 0, 0, $prod->id, '', 0, 1);
        } else {
            print $langs->trans("NoWarehouseDefined");
        }
        ?>
</td>
					<?php 
        if (!empty($conf->global->ASSET_SHOW_DLUO)) {
            ?>
						<td><?php 
            echo $form->calendrier('', 'TLine[-1][dluo]', $defaultDLUO);
            ?>
</td>
					<?php 
        }
        if (empty($conf->global->DISPATCH_USE_ONLY_UNIT_ASSET_RECEPTION)) {
            ?>
					<td><?php 
            echo $form->texte('', 'TLine[-1][quantity]', '', 10);
            ?>
</td><?php 
            if (!empty($conf->global->DISPATCH_SHOW_UNIT_RECEPTION)) {
                echo '<td>' . $formproduct->select_measuring_units('TLine[-1][quantity_unit]', 'weight') . '</td>';
            }
        }
        if ($conf->global->clinomadic->enabled) {
            ?>
						<td><?php 
            echo $form->texte('', 'TLine[-1][imei]', '', 30);
            ?>
</td>
						<td><?php 
            echo $form->texte('', 'TLine[-1][firmware]', '', 30);
            ?>
</td>
						<?php 
        }
        ?>
					<td>Nouveau
					</td>
				</tr>
			<?php 
    }
    ?>


	</table>
	<?php 
    if ($commande->statut < 5 || $warning_asset) {
        if ($commande->statut < 5) {
            echo '<div class="tabsAction">' . $form->btsubmit('Enregistrer', 'bt_save') . '</div>';
        }
        $form->type_aff = 'edit';
        ?>
		<hr />
		<?php 
        echo '<div id="actionVentilation">';
        echo 'Date de réception : ' . $form->calendrier('', 'date_recep', time());
        echo ' - ' . $langs->trans("Comment") . ' : ' . $form->texte('', 'comment', $_POST["comment"] ? GETPOST("comment") : $langs->trans("DispatchSupplierOrder", $commande->ref), 60, 128);
        echo ' ' . $form->btsubmit($langs->trans('AssetVentil'), 'bt_create');
        echo '</div>';
    }
}
 function makeAsset(&$PDOdb, &$AssetOf, $fk_product, $qty_to_make, $idAsset = 0, $lot_number = '')
 {
     global $user, $conf;
     //INFO : si on utilise pas les lots on a pas besoin de créer des équipements => on gère uniquement des mvt de stock
     if (empty($conf->asset->enabled) || empty($conf->global->USE_LOT_IN_OF)) {
         return true;
     }
     if (!dol_include_once('/asset/class/asset.class.php')) {
         return true;
     }
     $assetType = new TAsset_type();
     if ($assetType->load_by_fk_product($PDOdb, $fk_product)) {
         /* On fabrique de la contenance et non pas une quantité de produit au sens strict
          * Si on fabrique un produit au sens strict, le type d'équipement de ce produit aura une contenance max à 1, donc ça marche pareil
          * En revanche, on a un sac de sable à moitier vide, s'il est réutilisable on va le remplir puis en créer si besoin
          *
          * A penser :	   [1] [2] [3]
          * Périsable :		1	0	1
          * Réutilisable :	0	1	1
          *
          * [1] => on crée de nouveaux équipements
          * [2] => on réutilise
          * [3] => si la qté de l'équipement courant = 0 alors on réutilise
          *
          * Dans le process de la validation de la production, les TO_MAKE doivent pré-séléctionner les équipements possibles à la réutilisation
          * Quand on "Termine" l'OF il faudra prendre la liste des équipements liés pour les remplir puis en créer si nécessaire
          */
         $contenance_max = $assetType->contenance_value;
         $nb_asset_to_create = ceil($qty_to_make / $contenance_max);
         //Qté restante a fabriquer
         $qty_to_make_rest = $qty_to_make;
         for ($i = 0; $i < $nb_asset_to_create; $i++) {
             $TAsset = new TAsset();
             $TAsset->fk_soc = $AssetOf->fk_soc;
             $TAsset->fk_societe_localisation = $conf->global->ASSET_DEFAULT_LOCATION;
             $TAsset->fk_product = $fk_product;
             $TAsset->entity = $conf->entity;
             if (!empty($conf->global->ASSET_DEFAULT_DLUO)) {
                 $TAsset->dluo = strtotime(date('Y-m-d') . ' +' . $conf->global->ASSET_DEFAULT_DLUO . ' days');
             } else {
                 $TAsset->dluo = strtotime(date('Y-m-d'));
             }
             //pre($assetType,true);exit;
             $TAsset->fk_asset_type = $assetType->getId();
             $TAsset->load_asset_type($PDOdb);
             if ($qty_to_make_rest > $TAsset->contenance_value) {
                 $qty_to_make_asset = $TAsset->contenance_value;
             } else {
                 $qty_to_make_asset = $qty_to_make_rest;
             }
             $qty_to_make_rest -= $qty_to_make_asset;
             $TAsset->contenancereel_value = $qty_to_make_asset;
             $TAsset->lot_number = $lot_number;
             if (!empty($conf->global->ASSET_USE_DEFAULT_WAREHOUSE)) {
                 $fk_entrepot = $conf->global->ASSET_DEFAULT_WAREHOUSE_ID_TO_MAKE;
             }
             if (!$fk_entrepot) {
                 exit('ASSET_USE_DEFAULT_WAREHOUSE non définis dans la configuration du module');
             }
             $TAsset->fk_entrepot = $fk_entrepot;
             $TAsset->save($PDOdb, '', '', 0, false, 0, true, $fk_entrepot);
             //Save une première fois pour avoir le serial_number + 2ème save pour mvt de stock
             $this->addAssetLink($TAsset);
         }
         return true;
     } else {
         return false;
     }
 }