function fiche_preview(&$object, &$TData)
{
    global $langs, $user, $db, $conf;
    //var_dump($_REQUEST);exit;
    $origin = GETPOST('origin');
    $head = null;
    if ($object->element == 'propal') {
        $head = propal_prepare_head($object);
    } else {
        $head = commande_prepare_head($object);
    }
    if (empty($user->rights->importdevis->myactions)) {
        accessforbidden();
        exit;
    }
    $form = new Form($db);
    llxHeader();
    $title = $langs->trans('Import');
    if ($origin == 'propal') {
        dol_fiche_head($head, 'importdevis', $title, 0, 'propal');
    } else {
        dol_fiche_head($head, 'importdevis', $title, 0, 'commande');
    }
    ?>
		<style type="text/css">
			#table_before_import tr.title_line td.for_line > * {
				display:none;
			}
			
			#table_before_import tr.line_line td.for_title > * {
				display:none;
			}
			
			.for_line select{
				white-space:normal;
				width:300px;
			}
			.ui-dialog {
			    overflow: visible !important;  /* or 'visible' whatever */
			}
		</style>
		
		<script type="text/javascript">
			$(function() {
				var old_type;
				
				$('#to_parse .type select').unbind().click(function() { old_type = $(this).val(); }).change(function() {
					switchClass($(this));
				});
				
				$( "#pop-edit-product-link" ).dialog({
			      modal: true,
			      autoOpen: false,
			      title:"Lier un produit à cette ligne",
			      buttons: {
			        "Lier ce produit": function() {
			        	
			          var fk_product = $('#fk_product_to_link').val() ;
			          var k = $(this).attr('k');	
			          $input = $('tr[k='+k+'] input[rel=fk_product]');
			         //console.log($input);
			         
			          $.ajax({
			          	url:"<?php 
    echo dol_buildpath('/product/ajax/products.php', 1);
    ?>
?action=fetch&id="+fk_product
			          	,dataType:'json'
			          }).done(function(product) {
			          	
			          	$('span[rel="ref-product"][k='+k+']').html(product.ref);
			          	$input.val(fk_product);
			          	console.log(product);
			          	
			          });
			        		
			          $( this ).dialog( "close" );
			        }
			      }
			    });
				
				function switchClass(element)
				{
					var type_value = $(element).val();
	
					if (type_value == 'title') 
					{
						$(element).parent().parent().addClass('liste_titre title_line');
						$(element).parent().parent().removeClass('line_line');
					}
					else 
					{
						$(element).parent().parent().addClass('line_line');
						$(element).parent().parent().removeClass('liste_titre title_line');
						
						if (old_type == 'title' && type_value == 'line')
						{
							while (element.length > 0)
							{
								element = $(element).parent().parent().next().find('td.type').children('select');
								
								if (element.val() == 'title') break;
								
								element.children('option[value=nomenclature]').attr('selected', true);
							}
							
						}
					}
				}
			});
			
			var imp_is_all_check = true;
			function checkAndUncheckAllImport()
			{
				if (imp_is_all_check)
				{
					imp_is_all_check = false;
					$("#to_parse tr .check_imp").attr('checked', false).prop('checked', false);
				}
				else
				{
					imp_is_all_check = true;
					$("#to_parse tr .check_imp").attr('checked', true).prop('checked', true);
				}
			}
			
			function edit_product_link(k) {
				$div = $('#pop-edit-product-link');
				$div.attr('k', k);
				
				$div.dialog('open');
			}
			
		</script>
		<div id="pop-edit-product-link" class="ui-dialog"  >
			<?php 
    $form->select_produits('', 'fk_product_to_link');
    ?>
		</div>
		<table id="table_before_import" width="100%" class="border">
			<tr>
				<td width="25%"><?php 
    echo $langs->trans('Ref');
    ?>
</td>
				<td colspan="3"><div style="vertical-align: middle"><div class="inline-block floatleft refid"><?php 
    echo $object->ref;
    ?>
</div></div></td>
			</tr>
			<tr>
				<td><?php 
    echo $langs->trans('Company');
    ?>
</td>MO-1
				<td colspan="3"><?php 
    echo $object->thirdparty->getNomUrl(1);
    ?>
</td>
			</tr>
			<tr>
				<td colspan="4">
					
						<?php 
    $PDOdb = new TPDOdb();
    $formCore = new TFormCore('auto', 'to_parse', 'post');
    echo $formCore->hidden('action', 'import_data');
    echo $formCore->hidden('id', $object->id);
    echo $formCore->hidden('origin', $origin);
    echo $formCore->hidden('token', $_SESSION['newtoken']);
    echo $formCore->hidden('data', base64_encode(serialize($TData)));
    ?>
							<table class="border" width="100%">
								<tr class="liste_titre">
									<th onclick="javascript:checkAndUncheckAllImport();" style="cursor:pointer;" title="sélectionner/désélectionner tous">Imp.</th>
									<th>Type</th>
									<?php 
    if ($conf->subtotal->enabled) {
        ?>
<th>Niveau</th><?php 
    }
    ?>
									<th>Produit</th>
									<th>Label</th>
									<th>Qté</th>
									<?php 
    if (!empty($conf->global->PRODUCT_USE_UNITS)) {
        ?>
<th>Unité</th><?php 
    }
    ?>
									<th>Prix Achat</th>
									<th>Prix</th>
									<?php 
    if (!empty($conf->global->IMPORTPROPAL_USE_MAJ_ON_NOMENCLATURE)) {
        ?>
									<th>Ligne d'origine</th>
									<?php 
    }
    ?>
								</tr>
							<?php 
    if (!empty($conf->global->IMPORTPROPAL_USE_MAJ_ON_NOMENCLATURE)) {
        $TPropalDet = array();
        foreach ($object->lines as $line) {
            $label = !empty($line->label) ? $line->label : $line->desc;
            $label .= ' (qté : ' . $line->qty . ', total HT : ' . $line->total_ht . ')';
            $TPropalDet[$line->id] = $label;
        }
    }
    $class = '';
    //var_dump($TData);
    $TWorkstation = TWorkstation::getWorstations($PDOdb);
    foreach ($TData as $k => &$row) {
        //var_dump($row);MO-1
        $workstation = new TWorkstation();
        //var_dump($workstation->loadBy($PDOdb, $row['workstation'], 'code'));
        //var_dump($workstation);exit;
        if (!empty($row['ref'])) {
            $res = $workstation->loadBy($PDOdb, $row['ref'], 'code');
            if ($res > 0) {
                $row['type'] = 'workstation';
                $id_workstation = $workstation->getId();
                //var_dump($workstation);
            }
        }
        $type = $row['type'];
        if ($type == 'title') {
            $class = '';
            print '<tr class="' . $class . ' liste_titre title_line">';
            print '<td>' . $formCore->checkbox1('', 'TData[' . $k . '][to_import]', 1, true, '', 'check_imp') . '</td>';
            print '<td class="type">' . $form->selectarray('TData[' . $k . '][type]', getTypeLine(), $row['type']) . '</td>';
            print '<td class="for_title">' . $form->selectarray('TData[' . $k . '][level]', getLevelTitle(), $row['level']) . '</td>';
            print '<td class="for_line">';
            //$form->select_produits(0, 'TData['.$k.'][fk_product]');
            print '</td>';
            print '<td>' . $formCore->texte('', 'TData[' . $k . '][label]', $row['label'], 50, 255) . '</td>';
            print '<td class="for_line">' . $formCore->texte('', 'TData[' . $k . '][qty]', $row['qty'], 3, 20) . '</td>';
            if (!empty($conf->global->PRODUCT_USE_UNITS)) {
                print '<td class="for_line"></td>';
            }
            print '<td class="for_line">' . $formCore->texte('', 'TData[' . $k . '][price]', $row['price'], 10, 20) . '</td>';
            print '<td class="for_line">' . $formCore->texte('', 'TData[' . $k . '][price]', $row['price'], 10, 20) . '</td>';
        } elseif ($type == 'workstation') {
            //var_dump($type);
            $class = '';
            print '<tr class="' . $class . ' workstation_line">';
            print '<td>' . $formCore->checkbox1('', 'TData[' . $k . '][to_import]', 1, true, '', 'check_imp') . '</td>';
            print '<td class="type">' . $form->selectarray('TData[' . $k . '][type]', getTypeLine(), $row['type']) . '</td>';
            print '<td></td>';
            print '<td class="for_line">';
            echo $formCore->combo('', 'TData[' . $k . '][fk_workstation]', $TWorkstation, $id_workstation);
            print '</td>';
            print '<td>' . $row['workstation'] . '</td>';
            print '<td class="for_line">' . $formCore->texte('', 'TData[' . $k . '][qty]', $row['qty'], 3, 20) . '</td>';
            if (!empty($conf->global->PRODUCT_USE_UNITS)) {
                print '<td class="for_line"></td>';
            }
            print '<td></td>';
            print '<td></td>';
        } else {
            $class = $class == 'impair' ? 'pair' : 'impair';
            print '<tr class="line_line ' . $class . '" k="' . $k . '">';
            print '<td>' . $formCore->checkbox1('', 'TData[' . $k . '][to_import]', 1, true, '', 'check_imp') . '</td>';
            print '<td class="type">' . $form->selectarray('TData[' . $k . '][type]', getTypeLine(), $row['type']) . '</td>';
            if ($conf->subtotal->enabled) {
                print '<td class="for_title">' . $form->selectarray('TData[' . $k . '][level]', getLevelTitle(), $row['level']) . '</td>';
            }
            print '<td class="for_line">';
            if (!empty($row['product_ref'])) {
                $p = new Product($db);
                $p->fetch(null, $row['product_ref']);
                $fk_product = $p->id;
            } else {
                $fk_product = 0;
            }
            print '<span rel="ref-product" k="' . $k . '">' . ($fk_product > 0 ? $p->getNomUrl(1) : 'N/A') . '</span> <a href="javascript:edit_product_link(' . $k . ')">' . img_edit('Changer le produit de destination') . '</a>';
            //$form->select_produits($fk_product, 'TData['.$k.'][fk_product]');
            echo $formCore->hidden('TData[' . $k . '][fk_product]', $fk_product, ' rel="fk_product" ');
            echo $formCore->hidden('TData[' . $k . '][product_ref]', $row['product_ref'], ' rel="product_ref" ');
            print '</td>';
            print '<td>' . $formCore->texte('', 'TData[' . $k . '][label]', $row['label'], 80, 255);
            print '<table>';
            print '<tr>';
            print '<td>Longueur : ' . $formCore->texte('', 'TData[' . $k . '][length]', $row['length'], 15, 255) . '</td>';
            print '<td>Largeur : ' . $formCore->texte('', 'TData[' . $k . '][width]', $row['width'], 15, 255) . '</td>';
            print '<td>Hauteur : ' . $formCore->texte('', 'TData[' . $k . '][height]', $row['height'], 15, 255) . '</td>';
            print '<td>Poids : ' . $formCore->texte('', 'TData[' . $k . '][weight]', $row['weight'], 15, 255) . '</td>';
            print '</tr>';
            print '</table>';
            print '</td>';
            print '<td class="for_line">' . $formCore->texte('', 'TData[' . $k . '][qty]', $row['qty'], 3, 20) . '</td>';
            if (!empty($conf->global->PRODUCT_USE_UNITS)) {
                print '<td class="for_line">' . $form->selectUnits($row['fk_unit'], 'TData[' . $k . '][fk_unit]', 1) . '</td>';
            }
            print '<td class="for_line">' . $formCore->texte('', 'TData[' . $k . '][buy_price]', $row['buy_price'], 10, 20) . '</td>';
            print '<td class="for_line">' . $formCore->texte('', 'TData[' . $k . '][price]', $row['price'], 10, 20) . '</td>';
        }
        if (!empty($conf->global->IMPORTPROPAL_USE_MAJ_ON_NOMENCLATURE)) {
            print '<td class="for_line">' . $form->selectarray('TData[' . $k . '][fk_propaldet]', $TPropalDet, '', 1) . '</td>';
        }
        print '</tr>';
    }
    //exit;
    ?>
							</table>
							<div class="tabsAction">
								<?php 
    echo $langs->trans('DeleteLinesBeforeImport');
    ?>
 <input id="delete_lines_before_import" name="delete_lines_before_import" type="checkbox" value="1" />
								<input class="button" type="submit" value="<?php 
    echo $langs->trans('Import');
    ?>
" />
							</div>
							<?php 
    $formCore->end();
    ?>
				</td>
			</tr>
		</table>
	<?php 
    dol_fiche_end();
    llxFooter();
}
function _liste(&$PDOdb)
{
    global $langs, $db, $user, $conf;
    llxHeader('', $langs->trans('ListOFAsset'), '', '');
    //getStandartJS();
    if (isset($_REQUEST['delete_ok'])) {
        ?>
		<br><div class="error"><?php 
        echo $langs->trans('OFAssetDeleted');
        ?>
</div><br>
		<?php 
    }
    $fk_soc = __get('fk_soc', 0, 'integer');
    $fk_product = __get('fk_product', 0, 'integer');
    $fk_commande = __get('fk_commande', 0, 'integer');
    if ($fk_product > 0) {
        dol_include_once('/core/lib/product.lib.php');
        $product = new Product($db);
        $result = $product->fetch($fk_product);
        $head = product_prepare_head($product, $user);
        $titre = $langs->trans("CardProduct" . $product->type);
        $picto = $product->type == 1 ? 'service' : 'product';
        dol_fiche_head($head, 'tabOF2', $titre, 0, $picto);
    } elseif ($fk_commande > 0) {
        dol_include_once("/core/lib/order.lib.php");
        $commande = new Commande($db);
        $result = $commande->fetch($fk_commande);
        $head = commande_prepare_head($commande, $user);
        $titre = $langs->trans("CustomerOrder" . $product->type);
        dol_fiche_head($head, 'tabOF3', $titre, 0, "order");
    }
    $form = new TFormCore();
    $assetOf = new TAssetOF();
    $r = new TSSRenderControler($assetOf);
    $sql = "SELECT ofe.rowid, ofe.numero, ofe.fk_soc, s.nom as client, SUM(ofel.qty) as nb_product_to_make\n\t\t, GROUP_CONCAT(DISTINCT ofel.fk_product SEPARATOR ',') as fk_product, p.label as product, ofe.ordre, ofe.date_lancement , ofe.date_besoin, ofe.fk_commande,ofe.fk_project\n\t\t, ofe.status, ofe.fk_user,ofe.total_estimated_cost, ofe.total_cost, '' AS printTicket\n\t\t  FROM " . MAIN_DB_PREFIX . "assetOf as ofe \n\t\t  LEFT JOIN " . MAIN_DB_PREFIX . "assetOf_line ofel ON (ofel.fk_assetOf=ofe.rowid AND ofel.type = 'TO_MAKE')\n\t\t  LEFT JOIN " . MAIN_DB_PREFIX . "product p ON (p.rowid = ofel.fk_product)\n\t\t  LEFT JOIN " . MAIN_DB_PREFIX . "societe s ON (s.rowid = ofe.fk_soc)\n\t\t  WHERE ofe.entity=" . $conf->entity;
    if ($fk_soc > 0) {
        $sql .= " AND ofe.fk_soc=" . $fk_soc;
    }
    if ($fk_product > 0) {
        $sql .= " AND ofel.fk_product=" . $fk_product;
    }
    if ($fk_commande > 0) {
        $sql .= " AND ofe.fk_commande=" . $fk_commande;
    }
    $sql .= " GROUP BY ofe.rowid ";
    // TODO je me rappelle plus pourquoi j'ai fait cette merde mais ça fait planter le tri, donc à virer.
    /*if($conf->global->ASSET_OF_LIST_BY_ROWID_DESC) $orderBy['ofe.rowid']='DESC';
    	else $orderBy['ofe.date_cre']='DESC';*/
    $TMath = array();
    $THide = array('rowid', 'fk_user', 'fk_product', 'fk_soc');
    if ($fk_commande > 0) {
        $THide[] = 'fk_commande';
    }
    if ($conf->global->OF_NB_TICKET_PER_PAGE == -1) {
        $THide[] = 'printTicket';
    }
    if (empty($user->rights->of->of->price)) {
        $THide[] = 'total_cost';
        $THide[] = 'total_estimated_cost';
    } else {
        $TMath['total_estimated_cost'] = 'sum';
        $TMath['total_cost'] = 'sum';
    }
    if (!empty($fk_product)) {
        $TMath['nb_product_to_make'] = 'sum';
    }
    $form = new TFormCore($_SERVER['PHP_SELF'], 'form', 'GET');
    echo $form->hidden('action', '');
    if ($fk_commande > 0) {
        echo $form->hidden('fk_commande', $fk_commande);
    }
    if ($fk_product > 0) {
        echo $form->hidden('fk_product', $fk_product);
    }
    // permet de garder le filtre produit quand on est sur l'onglet OF d'une fiche produit
    $r->liste($PDOdb, $sql, array('limit' => array('nbLine' => $conf->liste_limit), 'orderBy' => $orderBy, 'subQuery' => array(), 'link' => array('Utilisateur en charge' => '<a href="' . dol_buildpath('/user/card.php?id=@fk_user@', 2) . '">' . img_picto('', 'object_user.png', '', 0) . ' @val@</a>', 'numero' => '<a href="' . dol_buildpath('/of/fiche_of.php?id=@rowid@"', 2) . '>' . img_picto('', 'object_list.png', '', 0) . ' @val@</a>', 'printTicket' => '<input style=width:40px;"" type="number" value="' . (int) $conf->global->OF_NB_TICKET_PER_PAGE . '" name="printTicket[@rowid@]" min="0" />'), 'translate' => array(), 'hide' => $THide, 'type' => array('date_lancement' => 'date', 'date_besoin' => 'date', 'total_cost' => 'money', 'total_estimated_cost' => 'money', 'nb_product_to_make' => 'number'), 'math' => $TMath, 'liste' => array('titre' => $langs->trans('ListOFAsset'), 'image' => img_picto('', 'title.png', '', 0), 'picto_precedent' => img_picto('', 'back.png', '', 0), 'picto_suivant' => img_picto('', 'next.png', '', 0), 'noheader' => (int) isset($_REQUEST['fk_soc']) | (int) isset($_REQUEST['fk_product']), 'messageNothing' => "Il n'y a aucun " . $langs->trans('OFAsset') . " à afficher", 'picto_search' => img_picto('', 'search.png', '', 0)), 'title' => array('numero' => 'Numéro', 'fk_commande' => 'Commande client', 'ordre' => 'Priorité', 'date_lancement' => 'Date du lancement', 'date_besoin' => 'Date du besoin', 'status' => 'Status', 'login' => 'Utilisateur en charge', 'product' => 'Produit', 'client' => 'Client', 'nb_product_to_make' => 'Nb produits à fabriquer', 'total_cost' => 'Coût réel', 'total_estimated_cost' => 'Coût prévu', 'printTicket' => 'impression<br />étiquette', 'fk_project' => 'Projet'), 'orderBy' => array('rowid' => 'DESC'), 'eval' => array('ordre' => 'TAssetOF::ordre(@val@)', 'status' => 'TAssetOF::status(@val@)', 'product' => 'get_format_libelle_produit("@fk_product@")', 'client' => 'get_format_libelle_societe(@fk_soc@)', 'fk_commande' => 'get_format_libelle_commande(@fk_commande@)', 'fk_project' => 'get_format_libelle_projet(@fk_project@)'), 'search' => array('numero' => array('recherche' => true, 'table' => 'ofe'), 'date_lancement' => array('recherche' => 'calendars', 'table' => 'ofe'), 'date_besoin' => array('recherche' => 'calendars', 'table' => 'ofe'), 'status' => array('recherche' => TAssetOF::$TStatus, 'table' => 'ofe'))));
    if ($conf->global->OF_NB_TICKET_PER_PAGE != -1) {
        echo '<p align="right"><input class="button" type="button" onclick="$(this).closest(\'form\').find(\'input[name=action]\').val(\'printTicket\');  $(this).closest(\'form\').submit(); " name="print" value="' . $langs->trans('ofPrintTicket') . '" /></p>';
    }
    $form->end();
    // On n'affiche pas le bouton de création d'OF si on est sur la liste OF depuis l'onglet "OF" de la fiche commande
    if ($fk_commande) {
        $commande = new Commande($db);
        $commande->fetch($fk_commande);
        $r2 = new TSSRenderControler($assetOf);
        $sql = "SELECT c.rowid as fk_commandedet, p.rowid as rowid, p.ref as refProd, p.label as nomProd, c.qty as qteCommandee, c.description, c.product_type";
        $sql .= " FROM " . MAIN_DB_PREFIX . "commandedet c LEFT JOIN " . MAIN_DB_PREFIX . "product p";
        $sql .= " ON (c.fk_product = p.rowid)";
        $sql .= " WHERE c.product_type IN (0,9) AND  c.fk_commande = " . $fk_commande;
        $resql = $db->query($sql);
        //var_dump($db);
        $num = $db->num_rows($resql);
        print_barre_liste($langs->trans('ListOrderProducts'), $page, "liste.php", $param, $sortfield, $sortorder, '', $num);
        $i = 0;
        $form = new TFormCore($_SERVER['PHP_SELF'], 'formMakeOk', 'post');
        echo $form->hidden('fk_commande', __get('fk_commande', 0, 'int'));
        echo $form->hidden('action', 'createOFCommande');
        echo $form->hidden('fk_soc', $commande->socid);
        echo $form->hidden('token', $_SESSION['newtoken']);
        print '<table class="noborder" width="100%">';
        print '<tr class="liste_titre">';
        print_liste_field_titre("#");
        print_liste_field_titre($langs->trans("Ref"), "liste_of.php", "ref", "", $param, '', $sortfield, $sortorder);
        print_liste_field_titre($langs->trans("Label"), "liste_of.php", "label", "", $param, 'align="left"', $sortfield, $sortorder);
        print_liste_field_titre($langs->trans("Quantité à produire"), "liste_of.php", "", "", $param, '', $sortfield, $sortorder);
        print_liste_field_titre($langs->trans("Produits à ajouter à un OF"), "liste_of.php", "", "", $param, '', $sortfield, $sortorder);
        print "</tr>\n";
        $var = 1;
        $bc = array(1 => 'class="pair"', -1 => 'class="impair"');
        while ($prod = $db->fetch_object($resql)) {
            $var = !$var;
            //print "<tr ".$bc[$var].">";
            if ($prod->product_type == 9) {
                print "<tr>";
                print "<td>&nbsp;</td>";
                print "<td colspan=\"4\"><strong>";
                print $prod->description;
                print '</strong></td>';
            } else {
                if (empty($prod->rowid)) {
                    // ligne libre
                    print "<tr>";
                    print "<td>&nbsp;</td>";
                    print "<td colspan=\"4\">";
                    print $prod->description;
                    print '</td>';
                } else {
                    print "<tr " . $bc[$var] . ">";
                    print "<td>" . ($i + 1) . "</td>";
                    print "<td>";
                    $p_static = new Product($db);
                    $p_static->ref = $prod->refProd;
                    $p_static->id = $prod->rowid;
                    print $p_static->getNomUrl(1);
                    print "</td>\n";
                    print '<td>';
                    print $prod->nomProd;
                    print '</td>';
                    print "<td>";
                    print $form->texte('', 'TQuantites[' . $prod->fk_commandedet . ']', $prod->qteCommandee, 3, 255);
                    print "</td>";
                    print "<td>" . $form->checkbox1('', 'TProducts[' . $prod->fk_commandedet . '][' . (int) $prod->rowid . ']', false, true, '', 'checkOF');
                    print "</td>";
                    print "</tr>\n";
                    $i++;
                }
            }
        }
        print '<tr class="liste_titre">';
        echo '<th class="liste_titre" colspan="2">&nbsp;</th><th class="liste_titre">&nbsp;</th><th class="liste_titre">&nbsp;</th>
		<th class="liste_titre"><input type="checkbox" id="checkall" checked="checked" value="1"></th>
		';
        print '</tr>';
        print "</table>";
        ?>
<script type="text/javascript">
			$('input#checkall').change(function() {
				
				$('input.checkOF').prop('checked',$(this).is(':checked'));	
				
			});
			
		</script>
		
		<?php 
        echo '<p align="right">' . $form->btsubmit('Créer OFs', 'subForm') . ' ' . $form->btsubmit('Créer un seul OF', 'subFormAlone') . '</p>';
        $form->end();
        echo '</div>';
        $db->free($resql);
    } else {
        if (!empty($fk_product)) {
            $sql = "SELECT ofe.rowid, ofe.numero, ofe.fk_soc, s.nom as client, SUM(IF(ofel.qty>0,ofel.qty,ofel.qty_needed) ) as nb_product_needed, ofel.fk_product, p.label as product, ofe.ordre, ofe.date_lancement , ofe.date_besoin\n            , ofe.status, ofe.fk_user, ofe.total_cost\n              FROM " . MAIN_DB_PREFIX . "assetOf as ofe \n              LEFT JOIN " . MAIN_DB_PREFIX . "assetOf_line ofel ON (ofel.fk_assetOf=ofe.rowid AND ofel.type = 'NEEDED')\n              LEFT JOIN " . MAIN_DB_PREFIX . "product p ON p.rowid = ofel.fk_product\n              LEFT JOIN " . MAIN_DB_PREFIX . "societe s ON s.rowid = ofe.fk_soc\n              WHERE ofe.entity=" . $conf->entity . " AND ofel.fk_product=" . $fk_product . " AND ofe.status!='CLOSE'";
            $sql .= " GROUP BY ofe.rowid ";
            if ($conf->global->ASSET_OF_LIST_BY_ROWID_DESC) {
                $orderBy['ofe.rowid'] = 'DESC';
            } else {
                $orderBy['ofe.date_cre'] = 'DESC';
            }
            $TMath = array();
            $THide = array('rowid', 'fk_user', 'fk_product', 'fk_soc');
            if (empty($user->rights->asset->of->price)) {
                $THide[] = 'total_cost';
            } else {
                $TMath['total_cost'] = 'sum';
            }
            $TMath['nb_product_needed'] = 'sum';
            $l = new TListviewTBS('listeofproductneeded');
            echo $langs->trans('ofListProductNeeded');
            echo $l->render($PDOdb, $sql, array('limit' => array('nbLine' => $conf->liste_limit), 'orderBy' => $orderBy, 'subQuery' => array(), 'link' => array('Utilisateur en charge' => '<a href="' . dol_buildpath('/user/card.php?id=@fk_user@', 2) . '">' . img_picto('', 'object_user.png', '', 0) . ' @val@</a>', 'numero' => '<a href="' . dol_buildpath('/of/fiche_of.php?id=@rowid@', 2) . '">' . img_picto('', 'object_list.png', '', 0) . ' @val@</a>', 'product' => '<a href="' . dol_buildpath('/product/card.php?id=@fk_product@', 2) . '">' . img_picto('', 'object_product.png', '', 0) . ' @val@</a>', 'client' => '<a href="' . dol_buildpath('/societe/soc.php?id=@fk_soc@', 2) . '">' . img_picto('', 'object_company.png', '', 0) . ' @val@</a>'), 'translate' => array(), 'hide' => $THide, 'type' => array('date_lancement' => 'date', 'date_besoin' => 'date', 'total_cost' => 'money', 'nb_product_needed' => 'number'), 'math' => $TMath, 'liste' => array('titre' => $langs->trans('ListOFAsset'), 'image' => img_picto('', 'title.png', '', 0), 'picto_precedent' => img_picto('', 'back.png', '', 0), 'picto_suivant' => img_picto('', 'next.png', '', 0), 'noheader' => (int) isset($_REQUEST['fk_soc']) | (int) isset($_REQUEST['fk_product']), 'messa geNothing' => "Il n'y a aucun " . $langs->trans('OFAsset') . " à afficher", 'picto_search' => img_picto('', 'search.png', '', 0)), 'title' => array('numero' => 'Numéro', 'ordre' => 'Priorité', 'date_lancement' => 'Date du lancement', 'date_besoin' => 'Date du besoin', 'status' => 'Status', 'login' => 'Utilisateur en charge', 'product' => 'Produit', 'client' => 'Client', 'nb_product_needed' => 'Nb produits nécessaire', 'total_cost' => 'Coût'), 'eval' => array('ordre' => 'TAssetOF::ordre(@val@)', 'status' => 'TAssetOF::status(@val@)', 'product' => 'get_format_libelle_produit(@fk_product@)', 'client' => 'get_format_libelle_societe(@fk_soc@)')));
        }
        echo '<div class="tabsAction">';
        echo '<a id="bt_createOf" class="butAction" href="fiche_of.php?action=new' . (!empty($fk_product) ? '&fk_product=' . $fk_product : '') . '">' . $langs->trans('CreateOFAsset') . '</a>';
        if ($conf->nomenclature->enabled && !empty($fk_product)) {
            dol_include_once('/core/class/html.form.class.php');
            dol_include_once('/asset/lib/asset.lib.php');
            dol_include_once('/nomenclature/class/nomenclature.class.php');
            $doliForm = new Form($db);
            echo $doliForm->selectarray('fk_nomenclature', TNomenclature::get($PDOdb, $fk_product, true));
            echo '<script type="text/javascript">

				    var url_create_of = $("#bt_createOf").attr("href");
	                   	    $("#bt_createOf").attr("href","#");  
                        
					$("#bt_createOf").click(function() {
						var fk_nomenclature = $("select[name=fk_nomenclature]").val();
						var href = url_create_of + "&fk_nomenclature=" + fk_nomenclature;
						$(this).attr("href", href);
					});
			</script>';
        }
        echo '</div>';
    }
    $PDOdb->close();
    llxFooter('');
}
            			<td><?php 
    echo $langs->trans('ReverseTrigger');
    ?>
</td>
            			<td><?php 
    echo $formCore->texte('', 'TRouting[' . $r->getId() . '][trigger_code_reverse]', $r->trigger_code_reverse, 25, 50, '', 'trigger_code');
    ?>
</td>
            		</tr>
            		<tr>
            			<td><?php 
    echo $langs->trans('CheckOld');
    ?>
</td>
            			<td><?php 
    echo $formCore->checkbox1('', 'TRouting[' . $r->getId() . '][check_old]', 1, $r->check_old);
    ?>
</td>
            		</tr>
            		
            	</table>
            
            </td>
            <td valign="top">
            	
            	<table width="100%">
            		<tr>
            			<td><?php 
    echo $langs->trans('Qty');
    ?>
</td>