<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_DOCUMENT_LINKS_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/purchase_requisitions_db.inc");
include_once($path_to_root . "/purchasing/includes/db/purchase_indents_db.inc");
include_once($path_to_root . "/manufacturing/includes/db/work_order_entry_db.inc");

include_once($path_to_root . "/purchasing/includes/db/grn_db.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 = "Document Links Inquiry"), @$_GET['popup'], false, "", $js);
}	
//------------------------------------------------------------------------------------------------

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

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

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

global $systypes_array;

$values_array[ST_PURCHORDER] = $systypes_array[ST_PURCHORDER];
$values_array[ST_PR_DETAIL_ALLOCATIONS] = 'Purchase Requisition Allocation';
$values_array[ST_PURCH_INDENTS] = 'Purchase Indents';
$values_array[ST_PURCH_REQ] = $systypes_array[ST_PURCH_REQ];
$values_array[ST_WORKORDER] = $systypes_array[ST_WORKORDER];
$values_array[ST_SALESORDER] = $systypes_array[ST_SALESORDER];
$values_array[ST_SUPPRECEIVE] = $systypes_array[ST_SUPPRECEIVE];

start_table(TABLESTYLE_NOBORDER);
start_row();


custom_values_list_row("Select Document Type:", "doc_type", $values_array, null, "Select a type");

text_cells('Document No.', 'doc_no',null,'10','20', null, null, null, null);

submit_cells('Search',_("Search"),'',_('Refresh Inquiry'), 'default');
end_row();
end_table();
if (!@$_GET['popup'])
    
    

end_form();

$doc_type = -1;
$doc_no = -1;

if (isset($_POST['doc_type']))
{
	$doc_type = get_post('doc_type');
}

if (isset($_POST['doc_no']))
{
	$doc_no = get_post('doc_no');
}

if(isset($_POST['Search'])){
    if(!($doc_type > 0)){
        display_error("Please select a document type");
    }
    if(!($doc_no > 0)){
        display_error("Please enter a document number");
    }
}

if($doc_type == ST_SUPPRECEIVE)
{
    $result = get_sql_from_grn_document_search($doc_no);
}

if($doc_type == ST_PURCHORDER)
{
    $result = get_sql_from_po_document_search($doc_no);
}
if($doc_type == ST_PR_DETAIL_ALLOCATIONS)
{
    $result = get_sql_from_pr_allocation_document_search($doc_no);
}

if($doc_type == ST_PURCH_INDENTS)
{
    $result = get_sql_from_pr_indent_document_search($doc_no);
}

if($doc_type == ST_PURCH_REQ)
{
    $result = get_sql_from_pr_req_indent_document_search($doc_no);
}

if($doc_type == ST_WORKORDER)
{
    $result = get_sql_from_wo_document_search($doc_no);
}

div_start('doc_tbl');
start_table(TABLESTYLE);
$th = array(_("Work Order "),_("Purchase Requisition"),_("Purchase Indent"),_("Purchase Requisition Allocation"),_("Purchase Order "),_("Goods Receive Note "));


table_header($th);

$j = 1;
$k = 0; //row colour counter

$total_in = 0;
$total_out = 0;

if(isset($result)){
    while ($myrow = db_fetch($result))
    {

        alt_table_row_color($k);

            label_cell(get_manufacturing_trans_view_str(ST_WORKORDER, $myrow["work_order_id"]),"align=left");
            label_cell(get_supplier_trans_view_str(ST_PURCH_REQ, $myrow['requisition_id']),"align=left");
            label_cell(get_supplier_trans_view_str(ST_PURCH_INDENTS, $myrow["indent_id"]),"align=left");
            label_cell(get_supplier_trans_view_str(ST_PR_DETAIL_ALLOCATIONS, $myrow["pr_allo_id"]),"align=left");
            label_cell(get_supplier_trans_view_str(ST_PURCHORDER, $myrow["order_no"]),"align=left");
            label_cell(get_supplier_trans_view_str(ST_SUPPRECEIVE, $myrow["grn_batch_id"]),"align=left");

    }
}

end_table(1);
div_end();
if (!@$_GET['popup'])
	end_page(@$_GET['popup'], false, false);

?>
