<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_STOCK_COUNT_INQ';
$path_to_root = "../..";

include($path_to_root . "/includes/db_pager.inc");
include($path_to_root . "/includes/session.inc");
include($path_to_root . "/includes/ui/ui_input.inc");
include($path_to_root . "/includes/ui/ui_view_custom.inc"); 
include_once($path_to_root . "/assets/includes/db/asset_verification_count_db.inc");
include_once($path_to_root . "/assets/includes/db/asset_verification_count_inquiry_db.inc"); 
include_once($path_to_root . "/includes/ui/ui_lists_custom.inc");  

$js = "";
$js .= get_js_open_window(900, 500);
$js .= get_js_date_picker();

page(_($help_context = "Search Asset Verification List"), false, false, "", $js);

function view_link($row) {
    return get_trans_view_str(ST_ASSET_VERIFICATION, $row["asset_verification_count_no"]);
}

function count_link($row) {  
    if ($row['status_id'] == SC_COUNTING) {  
        return pager_link( _("Count"), "/assets/manage/enter_asset_verification_counted_data.php?asset_verification_count_no=".$row['asset_verification_count_no']); 
    } else {
        return null;
    }
}

function complete_link($row) {
    if ($row['status_id'] == SC_COUNTED || $row['status_id'] == SC_COMPLETING) {
        return pager_link( _("Complete"), "/assets/manage/complete_asset_verification_count.php?CompleteStockCountNo=".$row["asset_verification_count_no"]);
    } else {
        return "&nbsp&nbsp";
    }
}

function edit_link($row) {
    if ($row['status_id'] == SC_NEW) {
        return pager_link( _("Edit"), "/assets/manage/asset_verification_count.php?ModifyAssetVerificationCountNo=" . $row["asset_verification_count_no"]);
    } else {
        return null;
    }
}

function process_link($row) {    
    if ($row['status_id'] == SC_COMPLETED || $row['status_id'] == SC_PROCESSING) {
        return pager_link( _("Process"), "/assets/manage/process_asset_verification_count.php?AssetVerificationCountNo=" . $row["asset_verification_count_no"]);
    } else {
        return "&nbsp&nbsp";
    }
}

function show_status_name($row) {
    global $stock_counting_statuses;
    return array_selector(null, $row['status_id'], $stock_counting_statuses, array( 'select_submit'=> false, 
                                                                                    'disabled' => true));
}

function show_location($row) {
    return $row['loc_code'] . ' - '. $row['location_name'];
}


start_form();

    start_table(TABLESTYLE_NOBORDER);
        start_row();
        asset_locations_list_cells(_("Location:"), 'location', null, '', true);
        date_cells(_("From Date:"), 'from_date', '', null, -30);
        date_cells(_("To Date:"), 'to_date');
        submit_cells('Search', _("Search"),'',_('Select documents'), 'default');
        end_row();
    end_table(1);

    $sql = get_sql_for_asset_verification_count_search($_POST['location'], $_POST['from_date'], $_POST['to_date']);

    $result = db_query($sql, "No orders were returned");

    $cols = array(
                _("Asset Verification Count No") => array('align' => 'center', 'ord' => '', 'fun' => 'view_link'),
                _("Reference"), 
                _("Location") => array('fun' => 'show_location', 'align' => 'left'), 
                _("Created On") => array('type' =>  'date', 'ord' => '' ),
                _("Status") => array('fun' => 'show_status_name'),
                _("Edit") => array('insert' => true, 'fun' => 'edit_link'),
                _("Count") => array('insert' => true, 'fun' => 'count_link'),
                _("Process") => array('insert' => true, 'fun' => 'process_link'));


    if (get_post('AssetLocation') != $all_items) {
        $cols[_("Location")] = 'skip';
    }

    $table =& new_db_pager('orders_tbl', $sql, $cols);

    $table->width = "60%";

    display_db_pager($table);

end_form();

end_page();

?>