<?php
/**********************************************************************
***********************************************************************/

$page_security = 'SA_STOCK_ASSET_TRANSFER_INQ';
$path_to_root = "../..";

include_once($path_to_root . "/includes/db_pager.inc");
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/sales/includes/sales_ui.inc");
include_once($path_to_root . "/reporting/includes/reporting.inc");
include_once($path_to_root . "/includes/ui/ui_lists_group_companies.inc");
include_once($path_to_root . "/includes/db/group_companies_db.inc");
include_once($path_to_root . "/assets/includes/db/stock_asset_transfers_inquiry_db.inc");


$js = "";
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(800, 500);
if (user_use_date_picker())
	$js .= get_js_date_picker();
page(_($help_context = "Stock Asset Transfers Inquiry"), false, false, "", $js);

if (isset($_GET['Approves']))
{
    $_SESSION['current_user_for_mr'] = $_SESSION['wa_current_user']->user;
}



function id($row)
{
    return $row['id'];
}

function _trans_no($row)
{
    return get_asset_trans_view_str(ST_STOCK_ASSET_TRANSFER, $row['trans_no']);
}

function reference($row)
{
    return $row['reference'];
}

function tran_date($row)
{
    return sql2date($row['tran_date']);
}

function type($row)
{
    if($row['is_return'] == 1){
        $return = "Return to Stock"; 
    }else{
        $return = "Move to Asset";
    }
    return $return;
}

function project_description($row)
{
    return $row['project_description'];
}


function asset_quantity($row)
{
    return number_format($row['asset_quantity'],0);
}

function asset_name($row)
{
    return $row['asset_code']." - ".$row['asset_description']." - "."(".$row['asset_id'].")";
}

function tran_unit_name($row)
{
    return $row['tran_unit'];
}

function comment($row)
{
    return $row['comment'];
}

function stock_description($row)
{  
    return $row['stock_description'];  
}


function task_description($row)
{  
    return $row['task_description'];  
}


function value($row)
{  
    return number_format($row['value'], 2);  
}


function po_number($row)
{  
    if($row["po_number"] > 0){
        return  get_supplier_trans_view_str(ST_PURCHORDER, $row["po_number"]);  
    }
    else{
        return null;
    }
}



if (get_post('SearchOrders')) 
{
    $Ajax->activate('orders_tbl');
}


if (!@$_GET['popup'])
	start_form();

start_table();
start_row();
    ref_cells("Id:", "asset_material_issue_id");
    date_cells(_("From Date:"), 'from_date', '', null, -15, null, null, null, true);
    date_cells(_("To Date:"), 'to_date', '', null, +15, null, null, null, true);

end_row();
end_table();


start_table();
start_row();
    project_list_cells("Project:", 'project_id', null, _('Select a project'), true); 
    asset_list_cells("Asset:", 'asset_id', null, 'Select an asset', true, null);
    
    submit_cells('SearchOrders', _("Search"),'',_('Select documents'), 'default');

end_row();

end_table(1);

//---------------------------------------------------------------------------------------------

$ami_id = "";
if(isset($_POST['asset_material_issue_id'])){
    $ami_id = $_POST['asset_material_issue_id'];
}

$project_id = "";
if(isset($_POST['project_id'])){
    $project_id = $_POST['project_id'];
}


$from_date = "";
if(isset($_POST['from_date'])){
    $from_date = $_POST['from_date'];
}

$to_date = "";
if(isset($_POST['to_date'])){
    $to_date = $_POST['to_date'];
}

$asset_id = "";
if(isset($_POST['asset_id'])){
    $asset_id = $_POST['asset_id'];
}

  $sql = get_sql_for_stock_asset_transfers_inquiry($ami_id, $project_id, $from_date, $to_date, $asset_id);    
    
    $cols = array(
                _("ID")=> array('fun'=>'id', 'align'=>'center'),
                _("Trans #")=> array('fun'=>'_trans_no', 'align'=>'center'),
                _("Reference")=> array('fun'=>'reference'),
                _("Date")=> array('fun'=>'tran_date', 'align'=>'center'),
                _("Type")=> array('fun'=>'type', 'align'=>'center'),
                _("Asset")=> array('fun'=>'asset_name'),
                _("Asset Qty")=> array('fun'=>'asset_quantity', 'align'=>'right'),
                _("Asset Value")=> array('fun'=>'value', 'align'=>'right'),  
                _("Stock Item")=> array('fun'=>'stock_description'),
//                _("Unit")=> array('fun'=>'tran_unit_name', 'align'=>'right'),
                _("Project")=> array('fun'=>'project_description'),
//                _("Task")=>array('fun'=>'task_description'),        
                             
                _("PO#")=> array('fun'=>'po_number', 'align'=>'center'),
                _("Comment")=> array('fun'=>'comment')

            );
    


$table =& new_db_pager('orders_tbl', $sql, $cols);
//$table->set_marker('check_overdue', _("Marked items are overdue."));

$table->width = "98%";

display_db_pager($table);
submit_center('Update', _("Update"), true, '', null);

if (!@$_GET['popup'])
{
    end_form();
    end_page();
}



?>
