function generateODTOF(&$PDOdb, &$assetOf)
{
    global $db, $conf, $TProductCachegenerateODTOF;
    $TBS = new TTemplateTBS();
    dol_include_once("/product/class/product.class.php");
    $TToMake = array();
    // Tableau envoyé à la fonction render contenant les informations concernant les produit à fabriquer
    $TNeeded = array();
    // Tableau envoyé à la fonction render contenant les informations concernant les produit nécessaires
    $TWorkstations = array();
    // Tableau envoyé à la fonction render contenant les informations concernant les stations de travail
    $TWorkstationUser = array();
    // Tableau de liaison entre les postes et les utilisateurs
    $TWorkstationTask = array();
    // Tableau de liaison entre les postes et les tâches 'mode opératoire'
    $TAssetWorkstation = array();
    // Tableau de liaison entre les composants et les postes de travails
    $TControl = array();
    // Tableau de liaison entre l'OF et les controles associés
    $societe = new Societe($db);
    $societe->fetch($assetOf->fk_soc);
    //pre($societe,true); exit;
    if (!empty($conf->global->ASSET_USE_CONTROL)) {
        $TControl = $assetOf->getControlPDF($PDOdb);
    }
    if (empty($TProductCachegenerateODTOF)) {
        $TProductCachegenerateODTOF = array();
    }
    // On charge les tableaux de produits à fabriquer, et celui des produits nécessaires
    foreach ($assetOf->TAssetOFLine as $k => &$v) {
        if (!isset($TProductCachegenerateODTOF[$v->fk_product])) {
            $prod_cache = new Product($db);
            if ($prod_cache->fetch($v->fk_product) > 0) {
                $prod_cache->fetch_optionals($prod_cache->id);
                $TProductCachegenerateODTOF[$v->fk_product] = $prod_cache;
            }
        } else {
            //echo 'cache '.$v->fk_product.':'.$TProductCachegenerateODTOF[$v->fk_product]->ref.' / '.$TProductCachegenerateODTOF[$v->fk_product]->id.'<br />';
        }
        $prod =& $TProductCachegenerateODTOF[$v->fk_product];
        if ($conf->nomenclature->enabled) {
            $n = new TNomenclature();
            if (!empty($v->fk_nomenclature)) {
                $n->load($PDOdb, $v->fk_nomenclature);
                $TTypesProductsNomenclature = $n->getArrayTypesProducts();
            }
        }
        $qty = !empty($v->qty_needed) ? $v->qty_needed : $v->qty;
        if (!empty($conf->asset->enabled)) {
            $TAssetType = new TAsset_type();
            $TAssetType->load($PDOdb, $prod->array_options['options_type_asset']);
            $unitLabel = $TAssetType->measuring_units == 'unit' || $TAssetType->gestion_stock == 'UNIT' ? 'unité(s)' : measuring_units_string($prod->weight_units, 'weight');
        } else {
            $unitLabel = 'unité(s)';
        }
        if ($v->type == "TO_MAKE") {
            $TToMake[] = array('type' => $v->type, 'qte' => $qty . " " . utf8_decode($unitLabel), 'nomProd' => $prod->ref, 'designation' => utf8_decode($prod->label), 'dateBesoin' => date("d/m/Y", $assetOf->date_besoin), 'lot_number' => $v->lot_number ? "\n(Lot numero " . $v->lot_number . ")" : "", 'code_suivi_ponderal' => $prod->array_options['options_suivi_ponderal'] ? "\n" . $prod->array_options['options_suivi_ponderal'] : "\n(Aucun)");
        } else {
            if ($v->type == "NEEDED") {
                $TNeeded[] = array('type' => $conf->nomenclature->enabled ? $TTypesProductsNomenclature[$v->fk_product] : $v->type, 'qte' => $qty, 'nomProd' => $prod->ref, 'designation' => utf8_decode($prod->label), 'dateBesoin' => date("d/m/Y", $assetOf->date_besoin), 'poids' => $prod->weight ? $prod->weight : 1, 'unitPoids' => utf8_decode($unitLabel), 'finished' => $prod->finished ? "PM" : "MP", 'lot_number' => $v->lot_number ? "\n(Lot numero " . $v->lot_number . ")" : "", 'code_suivi_ponderal' => $prod->array_options['options_suivi_ponderal'] ? "\n(Code suivi ponderal : " . $prod->array_options['options_suivi_ponderal'] . ")" : "");
                if (!empty($conf->global->ASSET_DEFINED_WORKSTATION_BY_NEEDED)) {
                    $TAssetWorkstation[] = array('nomProd' => utf8_decode($prod->label), 'workstations' => utf8_decode($v->getWorkstationsPDF($db)));
                }
            }
        }
    }
    //exit;
    // On charge le tableau d'infos sur les stations de travail de l'OF courant
    foreach ($assetOf->TAssetWorkstationOF as $k => $v) {
        $TWorkstations[] = array('libelle' => utf8_decode($v->ws->libelle), 'nb_hour_max' => utf8_decode($v->ws->nb_hour_capacity), 'nb_hour_real' => utf8_decode($v->nb_hour_real), 'nb_hour_preparation' => utf8_decode($v->nb_hour_prepare), 'nb_heures_prevues' => utf8_decode($v->nb_hour));
        if (!empty($conf->global->ASSET_DEFINED_USER_BY_WORKSTATION)) {
            $TWorkstationUser[] = array('workstation' => utf8_decode($v->ws->libelle), 'users' => utf8_decode($v->getUsersPDF($PDOdb)));
        }
        if (!empty($conf->global->ASSET_DEFINED_OPERATION_BY_WORKSTATION)) {
            $TWorkstationTask[] = array('workstation' => utf8_decode($v->ws->libelle), 'tasks' => utf8_decode($v->getTasksPDF($PDOdb)));
        }
    }
    $dirName = 'OF' . $assetOf->rowid . '(' . date("d_m_Y") . ')';
    $dir = DOL_DATA_ROOT . ($conf->entity > 1 ? '/' . $conf->entity : '') . '/of/' . $dirName . '/';
    @mkdir($dir, 0777, true);
    if (defined('TEMPLATE_OF')) {
        $template = TEMPLATE_OF;
    } else {
        $template = "templateOF.odt";
        //$template = "templateOF.doc";
    }
    $refcmd = '';
    if (!empty($assetOf->fk_commande)) {
        $cmd = new Commande($db);
        $cmd->fetch($assetOf->fk_commande);
        $refcmd = $cmd->ref;
    }
    $barcode_pic = getBarCodePicture($assetOf);
    //var_dump($TToMake);
    $file_path = $TBS->render(dol_buildpath('/of/exempleTemplate/' . $template), array('lignesToMake' => $TToMake, 'lignesNeeded' => $TNeeded, 'lignesWorkstation' => $TWorkstations, 'lignesAssetWorkstations' => $TAssetWorkstation, 'lignesUser' => $TWorkstationUser, 'lignesTask' => $TWorkstationTask, 'lignesControl' => $TControl), array('date' => date("d/m/Y"), 'numeroOF' => $assetOf->numero, 'statutOF' => utf8_decode(TAssetOF::$TStatus[$assetOf->status]), 'prioriteOF' => utf8_decode(TAssetOF::$TOrdre[$assetOf->ordre]), 'date' => date("d/m/Y"), 'refcmd' => $refcmd, 'societe' => $societe->name, 'logo' => DOL_DATA_ROOT . "/mycompany/logos/" . MAIN_INFO_SOCIETE_LOGO, 'barcode' => $barcode_pic, 'use_lot' => (int) $conf->global->ASSET_DEFINED_WORKSTATION_BY_NEEDED, 'defined_user' => (int) $conf->global->ASSET_DEFINED_USER_BY_WORKSTATION, 'defined_task' => (int) $conf->global->ASSET_DEFINED_OPERATION_BY_WORKSTATION, 'use_control' => (int) $conf->global->ASSET_USE_CONTROL), array(), array('outFile' => $dir . $assetOf->numero . ".odt", "convertToPDF" => true));
    return array('file_path' => $file_path, 'dir_name' => $dirName, 'num_of' => $assetOf->numero);
    header("Location: " . DOL_URL_ROOT . "/document.php?modulepart=of&entity=1&file=" . $dirName . "/" . $assetOf->numero . ".pdf");
    //header("Location: ".DOL_URL_ROOT."/document.php?modulepart=asset&entity=1&file=".$dirName."/".$assetOf->numero.".doc");
}