<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_PURCH_REQ_INQ';
$path_to_root = "../..";
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/banking.inc");
include_once($path_to_root . "/sales/includes/sales_db.inc");
include_once($path_to_root . "/purchasing/includes/db/item_purchase_requisition_inquiry_db.inc");
include_once($path_to_root . "/includes/ui/ui_view.inc");
include_once($path_to_root . "/includes/ui.inc");

if (!@$_GET['popup'])
{
	$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 = "Item Purchase Requisition Inquiry"), @$_GET['popup'], false, "", $js);
}	
//------------------------------------------------------------------------------------------------

check_db_has_stock_items(_("There are no items defined in the system."));

global $Ajax, $approval_statuses;

if(get_post('ShowMoves'))
{
	$Ajax->activate('doc_tbl');
}

if (isset($_GET['stock_id']))
{
	$_POST['stock_id'] = $_GET['stock_id'];
}

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

if (!isset($_POST['stock_id']))
	$_POST['stock_id'] = get_global_stock_item();

start_form();

start_table(TABLESTYLE_NOBORDER);
start_row();
if (!@$_GET['popup'])
	stock_items_list_cells(_("Item:"), 'stock_id', $_POST['stock_id'], false, true);
end_row();
end_table();

start_table(TABLESTYLE_NOBORDER);
    start_row();
        date_cells(_("From:"), 'AfterDate', '', null, -60);
        date_cells(_("To:"), 'BeforeDate', '', null, +14);
        submit_cells('ShowMoves',_("Show Purchase Requisitions"),'',_('Refresh Inquiry'), 'default');
    end_row();
end_table();
if (!@$_GET['popup'])
//	end_form();
    

$Ajax->activate('doc_tbl');


set_global_stock_item($_POST['stock_id']);

$before_date = date2sql($_POST['BeforeDate']);
$after_date = date2sql($_POST['AfterDate']);

    div_start('doc_tbl');

    $result = get_item_purchase_requisition_inquiry($_POST['stock_id'], $_POST['BeforeDate'], $_POST['AfterDate']);
        start_table(TABLESTYLE, "width=85%");
            $th = array(_("PR#"), _("Project"), _("Location"), 
                        _("Req. Unit"), _("Req. Qty"), _("Ordered Qty."), _("Issued Qty."), _("Outstand. Qty."), 
                        _("Estd. Price"), _("Req. Date"), _("Requester"), _("PR Status"));

            table_header($th);

            $k = 0; //row colour counter

            while ($myrow = db_fetch($result))
            {
                alt_table_row_color($k);
                label_cell(get_trans_view_str(ST_PURCH_REQ, $myrow['pr_no']),"align=center");
                label_cell($myrow['project_name']);
                label_cell($myrow['location_name']);
                label_cell(($myrow['requested_unit_name']),"align=center");
//                label_cell(number_format2($myrow['quantity'],3),"align=right");
                label_cell(number_format2($myrow['requested_unit_qty'],3),"align=right");
                label_cell(number_format2($myrow['quantity_ordered']/$myrow['req_unit_conv_factor'],3),"align=right");
                
                if($myrow['pr_complete'] == 1){
                    label_cell("No PR Issue", "colspan=2 align=center");
                }
                else{
                    label_cell(number_format2($myrow['issued_qty']/$myrow['req_unit_conv_factor'],3),"align=right");

                    $outstanding_qty = $myrow['requested_unit_qty'] - $myrow['issued_qty']/$myrow['req_unit_conv_factor'];
                    if(!($outstanding_qty > 0)){
                        $outstanding_qty = 0;
                    }
                    label_cell(number_format2($outstanding_qty,3),"align=right");
                }
                
                label_cell(number_format($myrow['estimate_price'],2),"align=right");
                label_cell(sql2date($myrow['required_date']),"align=center");
                
                label_cell($myrow['real_name']);
                
                
                label_cell($approval_statuses[$myrow['approval_status']],"align=center");
            }

        end_table();
    div_end();


    
end_form();

br(1);
	
end_page(@$_GET['popup'], false, false);

?>







