<?php

/* * ********************************************************************
 * ********************************************************************* */
$page_security = 'SA_ASSET_TRANSVIEW';
$path_to_root = "../..";
include_once($path_to_root . "/includes/db_pager.inc");
include($path_to_root . "/includes/session.inc");
$js = "";
if ($SysPrefs->use_popup_windows)
    $js .= get_js_open_window(900, 500);
if (user_use_date_picker())
    $js .= get_js_date_picker();

page(_($help_context = "Asset List"), @$_REQUEST['popup'], false, "", $js);

include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/data_checks.inc");

//include_once($path_to_root . "/inventory/includes/inventory_db.inc");
//include_once($path_to_root . "/inventory/includes/db/item_list_db.inc");


include_once($path_to_root . "/assets/includes/db/assets_db.inc");
include_once($path_to_root . "/assets/includes/db/asset_list_db.inc");


function edit_link($row){
    return '<a href="#" onclick="pass_to_parent(\''.$row['asset_id'].'\')">Select</a>';
}

function type_encrypt($row){

    if($row['mb_flag']=='B'){
        return 'Purchased';
    }else if($row['mb_flag']=='M'){
        return 'Manufactured';
    }else{
        return 'Service';
    }
}

start_form();

start_table(TABLESTYLE_NOBORDER,"width=90%");
start_row();
echo '<td align="center" colspan=5>&nbsp;</td>';
end_row();

start_row();
text_cells_ex(_('Asset Id').' :', 'id', 10);
text_cells_ex(_('Code').' :', 'code', 35, 50);
end_row();

start_row();
text_cells_ex(_('Description').' :', 'description', 35, 200);
//yesno_list_cells("Hired :", 'hired');
asset_types_list_cells("Type", 'type', null, '', true);
end_row();

start_row();
asset_groups_list_cells(_('Group').' :', 'group_id', null, '', true);
asset_subgroups_list_cells("Subgroup :", 'subgroup_id', get_post('group_id'), null, '');
end_row();


start_row();
asset_categories_list_cells("Category :", 'category', null, '');
tool_rate_category_list_cells("Rate Category", 'rate_category', null, '');
end_row();

start_row();
text_cells_ex(_('Serial No').' :', 'serial_no', 20);
three_value_list_cells("Hired / Own :", 'hired', null, "All", 2, "Own", 0, "Hired", 1);
end_row();

start_row();
text_cells_ex(_('Make').' :', 'make', 20);
text_cells_ex(_('Model').' :', 'model', 20);
end_row();





$_POST['country_of_origin'] = $_POST['country_of_manufacture'] = $_POST['supplier_id'] = $_POST['local_agent'] =-1;
        
start_row();
submit_cells('SearchItem', _("Search"), '', _('Select documents'), 'default');
end_row();

start_row();

end_row();
end_table(1);

$sql = get_asset_advance_search_sql($_POST['id'], $_POST['code'],$_POST['description'], $_POST['hired'], 
                                    $_POST['group_id'],$_POST['subgroup_id'],$_POST['category'], $_POST['rate_category'], 
                                    $_POST['make'], $_POST['model'], $_POST['serial_no'], $_POST['type']);

//$sql = get_item_advance_search_sql();

$cols = array(
    _('Id'),
    _('Code')=>array('ord'=>''),
    _('Description'),
    _('Group'),
    _('Subgroup'),
    _('Category'),
	array('insert' => true, 'fun' => 'edit_link')
);

//if(isset($_GET['popup'])){
//    array_append($cols, array(
//        array('insert' => true, 'fun' => 'edit_link'),
//    ));
//}
 
$table = & new_db_pager('item_tbl', $sql, $cols);
$table->width = "90%";
display_db_pager($table);

end_form();

if(isset($_GET['popup'])){
    echo get_js_parent_passing_item($_GET['parent']);
}
end_page();