function _get(&$db, $case)
{
    global $conf;
    switch ($case) {
        case 'tasks':
            $onlyUseGrid = isset($_REQUEST['gridMode']) && $_REQUEST['gridMode'] == 1 ? true : false;
            $var = explode('|', GETPOST('status'));
            $Tab = array();
            foreach ($var as $statut) {
                $Tab = array_merge($Tab, _tasks($db, (int) GETPOST('id_project'), $statut, $onlyUseGrid));
            }
            print json_encode($Tab);
            break;
        case 'task-ordo-simulation':
            if ($conf->workstation->enabled) {
                define('INC_FROM_DOLIBARR', true);
                dol_include_once('/workstation/config.php');
                $ATMdb = new TPDOdb();
                $TWorkstation = TWorkstation::getWorstations($ATMdb, true);
            } else {
                print 'module non configuré';
                exit;
            }
            $Tab = ordonnanceur(array_merge(_tasks_ordo($db, $TWorkstation, 'inprogress|todo', 0), _task_commande($db, GETPOST('fk_commande'))), $TWorkstation, 0, false);
            $time_max = 0;
            foreach ($Tab['tasks'] as &$task) {
                if ($task['time_estimated_end'] > $time_max) {
                    $time_max = (int) $task['time_estimated_end'];
                }
            }
            print dol_print_date($time_max + $conf->global->SCRUM_TIME_MORE_PREVISION * 86400, 'day');
            break;
        case 'tasks-ordo':
            $TWorkstation = array(0 => array('nb_ressource' => 1, 'velocity' => 1, 'background' => 'linear-gradient(to right,white, #ccc)', 'name' => 'Non ordonnancé'));
            if ($conf->workstation->enabled) {
                define('INC_FROM_DOLIBARR', true);
                dol_include_once('/workstation/config.php');
                $ATMdb = new TPDOdb();
                $TWorkstation = TWorkstation::getWorstations($ATMdb, true, false, $TWorkstation);
            }
            //     var_dump($TWorkstation);
            $Tab = ordonnanceur(_tasks_ordo($db, $TWorkstation, GETPOST('status'), GETPOST('fk_workstation')), $TWorkstation, (int) GETPOST('fk_workstation'));
            if (!empty($conf->global->SCRUM_LINK_EVENT_TO_TASK)) {
                ordonnanceur_link_event($Tab);
            }
            print json_encode($Tab);
            break;
        case 'task':
            print json_encode(_task($db, (int) GETPOST('id')));
            break;
        case 'velocity':
            print json_encode(_velocity($db, (int) GETPOST('id_project')));
            break;
    }
}
예제 #2
0
 *	\brief      Project card
 */
require 'config.php';
/*$TWorkstation = array(
	
		0=>array('nb_ressource'=>1, 'velocity'=>1, 'background'=>'linear-gradient(to right,white, #ccc)', 'name'=>'Non ordonnancé') // base de 7h par jour
		,1=>array('nb_ressource'=>2, 'velocity'=>(5/7), 'background'=>'linear-gradient(to right,white, #660000)', 'name'=>'Stagiaire') // base de 7h par jour
		,2=>array('nb_ressource'=>2, 'velocity'=>(5.5/7), 'background'=>'linear-gradient(to right,white, #cccc00)', 'name'=>'devconfirme')
		,3=>array('nb_ressource'=>1, 'velocity'=>1, 'background'=>'linear-gradient(to right,white,#00cc00)', 'name'=>'DSI')
	);*/
$TWorkstation = array(0 => array('nb_ressource' => 1, 'velocity' => 1, 'background' => 'linear-gradient(to right,white, #ccc)', 'name' => 'Non ordonnancé', 'id' => 0));
if ($conf->workstation->enabled) {
    define('INC_FROM_DOLIBARR', true);
    dol_include_once('/workstation/config.php');
    $ATMdb = new TPDOdb();
    $TWorkstation = TWorkstation::getWorstations($ATMdb, true, false, $TWorkstation);
} else {
    setEventMessage($langs->trans("moduleWorkstationNeeded") . ' : <a href="https://github.com/ATM-Consulting/dolibarr_module_workstation" target="_blank">' . $langs->trans('DownloadModule') . '</a>', 'errors');
}
$number_of_columns = 0;
foreach ($TWorkstation as $w_param) {
    $number_of_columns += $w_param['nb_ressource'];
}
$hh = GETPOST('hour_height');
if (!empty($hh)) {
    $_SESSION['hour_height'] = (int) $hh;
}
$cw = GETPOST('column_width');
if (!empty($cw)) {
    $_SESSION['column_width'] = (int) $cw;
}
function _ordo_init_dayOff(&$smallGeoffrey, $fk_workstation, $time_init, $time_day, $nb_second_in_hour, $velocity)
{
    global $conf;
    $TOff = array();
    $PDOdb = new TPDOdb();
    $ws = new TWorkstation();
    //var_dump($fk_workstation);
    $ws->load($PDOdb, $fk_workstation);
    // TODO function asshole
    $t_start_ordo = strtotime(date('Y-m-d') . ' ' . $conf->global->SCRUM_TIME_ORDO_START, $time_day);
    $t_end_ordo = strtotime(date('Y-m-d') . ' ' . $conf->global->SCRUM_TIME_ORDO_END, $time_day);
    $t_diff = $t_end_ordo - $t_start_ordo;
    // task for past of day
    if (empty($conf->global->SCRUM_TIME_ORDO_START) || empty($conf->global->SCRUM_TIME_ORDO_END)) {
        $height_of_past_day = ($time_init - $time_day) / $nb_second_in_hour;
    } else {
        if ($time_init < $t_start_ordo) {
            $height_of_past_day = 0;
        } else {
            if ($time_init > $t_end_ordo) {
                $height_of_past_day = 86400 / $nb_second_in_hour;
            } else {
                $height_of_past_day = ($time_init - $t_start_ordo) / $t_diff * 86400 / $nb_second_in_hour;
            }
        }
    }
    //var_dump($height_of_past_day, $nb_second_in_hour);exit;
    if ($height_of_past_day > 0) {
        $smallGeoffrey->addBox(0, 0, $height_of_past_day, $ws->nb_ressource);
        $TOff[] = array('top' => 0, 'left' => 0, 'height' => $height_of_past_day, 'nb_ressource' => $ws->nb_ressource, 'class' => 'past', 'title' => $fk_workstation . '. Passé');
    }
    //  var_dump($height_of_past_day,$smallGeoffrey );
    $TDayWeekOff = array();
    foreach ($ws->TWorkstationSchedule as &$sc) {
        if ($sc->nb_ressource == 0) {
            $sc->nb_ressource = $ws->nb_ressource;
        }
        if ($sc->date_off > 0) {
            $TRow = _ordo_ido_get($sc->date_off, $sc->day_moment, $sc->nb_ressource, $time_init, $nb_second_in_hour);
            $TOff[] = $TRow;
            $smallGeoffrey->addBox($TRow['top'], $TRow['left'], $TRow['height'], $TRow['nb_ressource']);
        } else {
            if (!isset($TDayWeekOff[$sc->week_day])) {
                $TDayWeekOff[$sc->week_day] = array('AM' => 0, 'PM' => 0, 'nb_ressource' => 0);
            }
            if ($sc->day_moment == 'AM') {
                $TDayWeekOff[$sc->week_day]['AM'] = 1;
            } else {
                if ($sc->day_moment == 'PM') {
                    $TDayWeekOff[$sc->week_day]['PM'] = 1;
                } else {
                    $TDayWeekOff[$sc->week_day]['AM'] = $TDayWeekOff[$sc->week_day]['PM'] = 1;
                }
            }
            if ($TDayWeekOff[$sc->week_day]['nb_ressource'] < $sc->nb_ressource) {
                $TDayWeekOff[$sc->week_day]['nb_ressource'] = $sc->nb_ressource;
            }
        }
    }
    $t_end_3month = strtotime('+3month', $time_day);
    $t_current = $time_init;
    while ($t_current < $t_end_3month) {
        $dw = (int) date('w', $t_current);
        $TRow = array();
        if (!empty($TDayWeekOff[$dw]['AM']) && !empty($TDayWeekOff[$dw]['PM'])) {
            $TRow = _ordo_ido_get($t_current, 'ALL', $TDayWeekOff[$dw]['nb_ressource'], $time_init, $nb_second_in_hour);
        } else {
            if (!empty($TDayWeekOff[$dw]['AM'])) {
                $TRow = _ordo_ido_get($t_current, 'AM', $TDayWeekOff[$dw]['nb_ressource'], $time_init, $nb_second_in_hour);
            } else {
                if (!empty($TDayWeekOff[$dw]['PM'])) {
                    $TRow = _ordo_ido_get($t_current, 'PM', $TDayWeekOff[$dw]['nb_ressource'], $time_init, $nb_second_in_hour);
                }
            }
        }
        if (!empty($TRow)) {
            $TOff[] = $TRow;
            $smallGeoffrey->addBox($TRow['top'], $TRow['left'], $TRow['height'], $TRow['nb_ressource']);
        }
        $t_current = strtotime('+1day', $t_current);
    }
    //if(!empty($TPlanned)) $TFree = _ordo_gnc_get_free_place($TPlanned, $ws->nb_ressource,true);
    $PDOdb->close();
    return $TOff;
}
function _stat_wd(&$PDOdb, $id_ws, $tDeb, $tFin)
{
    $ws = new TWorkstation();
    $ws->load($PDOdb, $id_ws);
    $TData = _get_data_ws($PDOdb, $id_ws, $tDeb, $tFin, $ws->nb_ressource);
    ?>
    <table class="border" style="margin-top:20px;width:100%;">
        <tr>
            <td><?php 
    echo $ws->getNomUrl(1) . ' du ' . date('d/m/Y', $tDeb) . ' au ' . date('d/m/Y', $tFin);
    ?>
</td>
        </tr>
        <tr>
            <td>
                <div id="stat-ws-<?php 
    echo $id_ws;
    ?>
"></div>
                <?php 
    $d = new TReport_dashboard();
    $d->format = 'area';
    $d->getChart('stat-ws-' . $id_ws, false, '', $TData);
    ?>
</td>
        </tr>
        
    </table>
   
    <?php 
}
function _stat_wd(&$PDOdb, $id_ws, $tDeb, $tFin)
{
    $ws = new TWorkstation();
    $ws->load($PDOdb, $id_ws);
    $TData = _get_data_ws($PDOdb, $id_ws, $tDeb, $tFin, $ws->nb_ressource);
    // var_dump($TData);
    ?>
    <table class="border" style="margin-top:20px;width:100%;">
        <tr>
            <td><?php 
    echo $ws->getNomUrl(1) . ' du ' . date('d/m/Y', $tDeb) . ' au ' . date('d/m/Y', $tFin);
    ?>
</td>
        </tr>
        <tr>
            <td>
                <?php 
    $l = new TListviewTBS('stat_ws_' . $id_ws);
    echo $l->renderArray($PDOdb, $TData, array('type' => 'chart', 'chartType' => 'AreaChart'));
    ?>
</td>
        </tr>
        
    </table>
   
    <?php 
}
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 _get(&$db, $case)
{
    global $conf;
    switch ($case) {
        case 'logged-status':
            echo 'ok';
            break;
        case 'tasks':
            $onlyUseGrid = isset($_REQUEST['gridMode']) && $_REQUEST['gridMode'] == 1 && empty($conf->global->SCRUM_ALLOW_ALL_TASK_IN_GRID) ? true : false;
            $var = explode('|', GETPOST('status'));
            $Tab = array();
            foreach ($var as $statut) {
                $Tab = array_merge($Tab, _tasks($db, (int) GETPOST('id_project'), $statut, $onlyUseGrid));
            }
            print json_encode($Tab);
            break;
        case 'task-ordo-simulation':
            if ($conf->workstation->enabled) {
                define('INC_FROM_DOLIBARR', true);
                dol_include_once('/workstation/config.php');
                $PDOdb = new TPDOdb();
                $TWorkstation = TWorkstation::getWorstations($PDOdb, true);
            } else {
                print 'module non configuré';
                exit;
            }
            $type_object = GETPOST('type_object');
            $TTaskObject = $type_object == 'propal' ? _task_propal($db, GETPOST('fk_object')) : _task_commande($db, GETPOST('fk_object'));
            $Tab = ordonnanceur(array_merge(_tasks_ordo($db, $TWorkstation, 'inprogress|todo', 0), $TTaskObject), $TWorkstation, 0, false);
            $time_max = 0;
            foreach ($Tab['tasks'] as &$task) {
                if ($task['time_estimated_end'] > $time_max) {
                    $time_max = (int) $task['time_estimated_end'];
                }
            }
            if ($type_object == 'propal') {
                print dol_print_date($time_max + $conf->global->SCRUM_TIME_MORE_PREVISION_PROPAL * 86400, 'day');
            } else {
                print dol_print_date($time_max + $conf->global->SCRUM_TIME_MORE_PREVISION * 86400, 'day');
            }
            break;
        case 'tasks-ordo':
            $TWorkstation = array(0 => array('nb_ressource' => 1, 'velocity' => 1, 'background' => 'linear-gradient(to right,white, #ccc)', 'name' => 'Non ordonnancé'));
            if ($conf->workstation->enabled) {
                define('INC_FROM_DOLIBARR', true);
                dol_include_once('/workstation/config.php');
                $PDOdb = new TPDOdb();
                $TWorkstation = TWorkstation::getWorstations($PDOdb, true, false, $TWorkstation);
            }
            //     var_dump($TWorkstation);
            $Tab = ordonnanceur(_tasks_ordo($db, $TWorkstation, GETPOST('status'), GETPOST('fk_workstation')), $TWorkstation, (int) GETPOST('fk_workstation'));
            if (!empty($conf->global->SCRUM_LINK_EVENT_TO_TASK)) {
                ordonnanceur_link_event($Tab);
            }
            print json_encode($Tab);
            break;
        case 'task':
            print json_encode(_task($db, (int) GETPOST('id')));
            break;
        case 'velocity':
            print json_encode(_velocity($db, (int) GETPOST('id_project')));
            break;
        case 'select-task':
            dol_include_once('/core/class/html.formother.class.php');
            $formother = new FormOther($db);
            //selectProjectTasks($selectedtask='', $projectid=0, $htmlname='task_parent', $modeproject=0, $modetask=0, $mode=0, $useempty=0, $disablechildoftaskid=0)
            echo $formother->selectProjectTasks(GETPOST('fk_task'), GETPOST('fk_project'), 'fk_project_task', 0, 1, 0, 1);
            break;
    }
}
function _fiche(&$PDOdb, &$assetOf, $mode = 'edit', $fk_product_to_add = 0, $fk_nomenclature = 0)
{
    global $langs, $db, $conf, $user, $hookmanager;
    /***************************************************
     * PAGE
     *
     * Put here all code to build page
     ****************************************************/
    $parameters = array('id' => $assetOf->getId());
    $reshook = $hookmanager->executeHooks('doActions', $parameters, $assetOf, $mode);
    // Note that $action and $object may have been modified by hook
    //pre($assetOf,true);
    llxHeader('', $langs->trans('OFAsset'), '', '');
    print dol_get_fiche_head(ofPrepareHead($assetOf, 'assetOF'), 'fiche', $langs->trans('OFAsset'));
    ?>
<style type="text/css">
		#assetChildContener .OFMaster {
			
			background:#fff;
			-webkit-box-shadow: 4px 4px 5px 0px rgba(50, 50, 50, 0.52);
			-moz-box-shadow:    4px 4px 5px 0px rgba(50, 50, 50, 0.52);
			box-shadow:         4px 4px 5px 0px rgba(50, 50, 50, 0.52);
			
			margin-bottom:20px;
		}
		
	</style>
		<div class="OFContent" rel="<?php 
    echo $assetOf->getId();
    ?>
">	<?php 
    $TPrixFournisseurs = array();
    //$form=new TFormCore($_SERVER['PHP_SELF'],'formeq'.$assetOf->getId(),'POST');
    //Affichage des erreurs
    if (!empty($assetOf->errors)) {
        ?>
		<br><div class="error">
		<?php 
        foreach ($assetOf->errors as $error) {
            echo $error . "<br>";
            setEventMessage($error, 'errors');
        }
        $assetOf->errors = array();
        ?>
		</div><br>
		<?php 
    }
    $form = new TFormCore();
    $form->Set_typeaff($mode);
    $doliform = new Form($db);
    if (!empty($_REQUEST['fk_product'])) {
        echo $form->hidden('fk_product', $_REQUEST['fk_product']);
    }
    $TBS = new TTemplateTBS();
    $liste = new TListviewTBS('asset');
    $TBS->TBS->protect = false;
    $TBS->TBS->noerr = true;
    $PDOdb = new TPDOdb();
    $TNeeded = array();
    $TToMake = array();
    $TNeeded = _fiche_ligne($form, $assetOf, "NEEDED");
    $TToMake = _fiche_ligne($form, $assetOf, "TO_MAKE");
    $TIdCommandeFourn = $assetOf->getElementElement($PDOdb);
    $HtmlCmdFourn = '';
    if (count($TIdCommandeFourn)) {
        foreach ($TIdCommandeFourn as $idcommandeFourn) {
            $cmd = new CommandeFournisseur($db);
            $cmd->fetch($idcommandeFourn);
            $HtmlCmdFourn .= $cmd->getNomUrl(1) . " - " . $cmd->getLibStatut(0);
        }
    }
    ob_start();
    $doliform->select_produits('', 'fk_product', '', $conf->product->limit_size, 0, -1, 2, '', 3, array());
    $select_product = ob_get_clean();
    $Tid = array();
    //$Tid[] = $assetOf->rowid;
    if ($assetOf->getId() > 0) {
        $assetOf->getListeOFEnfants($PDOdb, $Tid);
    }
    $TWorkstation = array();
    foreach ($assetOf->TAssetWorkstationOF as $k => &$TAssetWorkstationOF) {
        $ws =& $TAssetWorkstationOF->ws;
        $TWorkstation[] = array('libelle' => '<a href="' . dol_buildpath('workstation/workstation.php?id=' . $ws->rowid . '&action=view', 2) . '">' . $ws->name . '</a>', 'fk_user' => visu_checkbox_user($PDOdb, $form, $ws->fk_usergroup, $TAssetWorkstationOF->users, 'TAssetWorkstationOF[' . $k . '][fk_user][]', $assetOf->status), 'fk_project_task' => visu_project_task($db, $TAssetWorkstationOF->fk_project_task, $form->type_aff, 'TAssetWorkstationOF[' . $k . '][progress]'), 'fk_task' => visu_checkbox_task($PDOdb, $form, $TAssetWorkstationOF->fk_asset_workstation, $TAssetWorkstationOF->tasks, 'TAssetWorkstationOF[' . $k . '][fk_task][]', $assetOf->status), 'nb_hour' => $assetOf->status == 'DRAFT' && $mode == "edit" ? $form->texte('', 'TAssetWorkstationOF[' . $k . '][nb_hour]', $TAssetWorkstationOF->nb_hour, 3, 10) : ($conf->global->ASSET_USE_CONVERT_TO_TIME ? convertSecondToTime($TAssetWorkstationOF->nb_hour * 3600) : price($TAssetWorkstationOF->nb_hour)), 'nb_hour_real' => $assetOf->status == 'OPEN' && $mode == "edit" ? $form->texte('', 'TAssetWorkstationOF[' . $k . '][nb_hour_real]', $TAssetWorkstationOF->nb_hour_real, 3, 10) : ($conf->global->ASSET_USE_CONVERT_TO_TIME ? convertSecondToTime($TAssetWorkstationOF->nb_hour_real * 3600) : price($TAssetWorkstationOF->nb_hour_real)), 'nb_days_before_beginning' => $assetOf->status == 'DRAFT' && $mode == "edit" ? $form->texte('', 'TAssetWorkstationOF[' . $k . '][nb_days_before_beginning]', $TAssetWorkstationOF->nb_days_before_beginning, 3, 10) : $TAssetWorkstationOF->nb_days_before_beginning, 'delete' => $mode == 'edit' && $assetOf->status == 'DRAFT' ? '<a href="javascript:deleteWS(' . $assetOf->getId() . ',' . $TAssetWorkstationOF->getId() . ');">' . img_picto('Supprimer', 'delete.png') . '</a>' : '', 'note_private' => $assetOf->status == 'DRAFT' && $mode == 'edit' ? $form->zonetexte('', 'TAssetWorkstationOF[' . $k . '][note_private]', $TAssetWorkstationOF->note_private, 50, 1) : $TAssetWorkstationOF->note_private, 'rang' => $assetOf->status == 'DRAFT' && $mode == "edit" ? $form->texte('', 'TAssetWorkstationOF[' . $k . '][rang]', $TAssetWorkstationOF->rang, 3, 10) : $TAssetWorkstationOF->rang, 'id' => $ws->getId());
    }
    $client = new Societe($db);
    if ($assetOf->fk_soc > 0) {
        $client->fetch($assetOf->fk_soc);
    }
    $commande = new Commande($db);
    if ($assetOf->fk_commande > 0) {
        $commande->fetch($assetOf->fk_commande);
    }
    $TOFParent = array_merge(array(0 => ''), $assetOf->getCanBeParent($PDOdb));
    $hasParent = false;
    if (!empty($assetOf->fk_assetOf_parent)) {
        $TAssetOFParent = new TAssetOF();
        $TAssetOFParent->load($PDOdb, $assetOf->fk_assetOf_parent);
        $hasParent = true;
    }
    $parameters = array('id' => $assetOf->getId());
    $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $assetOf, $mode);
    // Note that $action and $object may have been modified by hook
    if ($fk_product_to_add > 0) {
        $product_to_add = new Product($db);
        $product_to_add->fetch($fk_product_to_add);
        $link_product_to_add = $product_to_add->getNomUrl(1) . ' ' . $product_to_add->label;
        $quantity_to_create = $form->texte('', 'quantity_to_create', 1, 3, 255);
    } else {
        $link_product_to_add = '';
        $quantity_to_create = '';
    }
    print $TBS->render('tpl/fiche_of.tpl.php', array('TNeeded' => $TNeeded, 'TTomake' => $TToMake, 'workstation' => $TWorkstation), array('assetOf' => array('id' => $assetOf->getId(), 'numero' => $assetOf->getId() > 0 ? '<a href="fiche_of.php?id=' . $assetOf->getId() . '">' . $assetOf->getNumero($PDOdb) . '</a>' : $assetOf->getNumero($PDOdb), 'ordre' => $form->combo('', 'ordre', TAssetOf::$TOrdre, $assetOf->ordre), 'fk_commande' => $assetOf->fk_commande == 0 ? '' : $commande->getNomUrl(1), 'commande_fournisseur' => $HtmlCmdFourn, 'date_besoin' => $form->calendrier('', 'date_besoin', $assetOf->date_besoin, 12, 12), 'date_lancement' => $form->calendrier('', 'date_lancement', $assetOf->date_lancement, 12, 12), 'temps_estime_fabrication' => price($assetOf->temps_estime_fabrication, 0, '', 1, -1, 2), 'temps_reel_fabrication' => price($assetOf->temps_reel_fabrication, 0, '', 1, -1, 2), 'fk_soc' => $mode == 'edit' ? $doliform->select_company($assetOf->fk_soc, 'fk_soc', 'client=1', 1) : ($client->id ? $client->getNomUrl(1) : ''), 'fk_project' => custom_select_projects(-1, $assetOf->fk_project, 'fk_project', $mode), 'note' => $form->zonetexte('', 'note', $assetOf->note, 80, 5), 'quantity_to_create' => $quantity_to_create, 'product_to_create' => $link_product_to_add, 'status' => $form->combo('', 'status', TAssetOf::$TStatus, $assetOf->status), 'statustxt' => TAssetOf::$TStatus[$assetOf->status], 'idChild' => !empty($Tid) ? '"' . implode('","', $Tid) . '"' : '', 'url' => dol_buildpath('/of/fiche_of.php', 2), 'url_liste' => $assetOf->getId() ? dol_buildpath('/of/fiche_of.php?id=' . $assetOf->getId(), 2) : dol_buildpath('/of/liste_of.php', 2), 'fk_product_to_add' => $fk_product_to_add, 'fk_nomenclature' => $fk_nomenclature, 'fk_assetOf_parent' => $assetOf->fk_assetOf_parent ? $assetOf->fk_assetOf_parent : '', 'link_assetOf_parent' => $hasParent ? '<a href="' . dol_buildpath('/of/fiche_of.php?id=' . $TAssetOFParent->rowid, 2) . '">' . $TAssetOFParent->numero . '</a>' : '', 'total_cost' => price($assetOf->total_cost, 0, '', 1, -1, 2), 'total_estimated_cost' => price($assetOf->total_estimated_cost, 0, '', 1, -1, 2), 'mo_cost' => price($assetOf->mo_cost, 0, '', 1, -1, 2), 'mo_estimated_cost' => price($assetOf->mo_estimated_cost, 0, '', 1, -1, 2), 'compo_cost' => price($assetOf->compo_cost, 0, '', 1, -1, 2), 'compo_estimated_cost' => price($assetOf->compo_estimated_cost, 0, '', 1, -1, 2), 'current_cost_for_to_make' => price($assetOf->current_cost_for_to_make, 0, '', 1, -1, 2)), 'view' => array('mode' => $mode, 'status' => $assetOf->status, 'allow_delete_of_finish' => $user->rights->of->of->allow_delete_of_finish, 'ASSET_USE_MOD_NOMENCLATURE' => (int) $conf->nomenclature->enabled, 'OF_MINIMAL_VIEW_CHILD_OF' => (int) $conf->global->OF_MINIMAL_VIEW_CHILD_OF, 'select_product' => $select_product, 'select_workstation' => $form->combo('', 'fk_asset_workstation', TWorkstation::getWorstations($PDOdb), -1), 'actionChild' => $mode == 'edit' ? __get('actionChild', 'edit') : __get('actionChild', 'view'), 'use_lot_in_of' => (int) (!empty($conf->asset->enabled) && !empty($conf->global->USE_LOT_IN_OF)), 'use_project_task' => (int) $conf->global->ASSET_USE_PROJECT_TASK, 'defined_user_by_workstation' => (int) $conf->global->ASSET_DEFINED_USER_BY_WORKSTATION, 'defined_task_by_workstation' => (int) $conf->global->ASSET_DEFINED_OPERATION_BY_WORKSTATION, 'defined_workstation_by_needed' => (int) $conf->global->ASSET_DEFINED_WORKSTATION_BY_NEEDED, 'defined_manual_wharehouse' => (int) $conf->global->ASSET_MANUAL_WAREHOUSE, 'hasChildren' => (int) (!empty($Tid)), 'user_id' => $user->id, 'workstation_module_activate' => (int) $conf->workstation->enabled, 'show_cost' => (int) $user->rights->of->of->price), 'rights' => array('show_ws_time' => $user->rights->of->of->show_ws_time)));
    echo $form->end_form();
    llxFooter('$Date: 2011/07/31 22:21:57 $ - $Revision: 1.19 $');
}
 function save(&$PDOdb)
 {
     global $conf;
     $this->name = $this->libelle;
     $this->entity = $conf->entity;
     parent::save($PDOdb);
 }