<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_PURCHASE_REQUISITION_ISSUES';
if (!@$_GET['popup'])
	$path_to_root = "..";
else	
	$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/ui.inc");
include_once($path_to_root . "/includes/data_checks.inc");
//include_once($path_to_root . "/gl/includes/db/i_owe_you_db.inc");
//include_once($path_to_root . "/gl/includes/db/i_owe_you_expenses_db.inc");
//include_once($path_to_root . "/gl/includes/db/petty_cash_floats_db.inc");

include_once($path_to_root . "/purchasing/includes/db/purchase_requisitions_db.inc");

simple_page_mode(true);

page(_($help_context = "Select POs for PR Issues"));

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

$pr_no = 0;

if (isset($_GET['pr_no']) && $_GET['pr_no'] > 0) 
{
    $pr_no = $_GET['pr_no'];
}

function build_po_array(&$ious, $pr_no)
{
//    $result = get_i_owe_you_expence_batches_for_approval();
    $result = get_pos_for_pr_issues($pr_no);
    while ($myrow = db_fetch($result))
    {
        $a = array(
                "id" => $myrow["id"],
                "project_id" => $myrow["project_id"],
                "project_description" => $myrow["project_description"],
                "float_id" => $myrow["float_id"],
                "float_name" => $myrow["float_name"],
                "employee" => $myrow["employee"],
                "type_name" => $myrow["type_name"],
                "tran_date" => $myrow["tran_date"],
                "amount" => $myrow["amount"],
                "comments" => $myrow["comments"],
                "batch_no" => $myrow["batch_no"]);

        $ious[] = $a;
    }
//    $result = get_i_owe_yous_for_expenses_entry(true);
//    while ($myrow = db_fetch($result))
//    {
//        $a = array(
//                "id" => $myrow["id"],
//                "project_id" => $myrow["project_id"],
//                "project_description" => $myrow["project_description"],
//                "float_id" => $myrow["float_id"],
//                "float_name" => $myrow["float_name"],
//                "employee" => $myrow["employee"],
//                "type_name" => $myrow["type_name"],
//                "tran_date" => $myrow["tran_date"],
//                "amount" => $myrow["amount"],
//                "comments" => $myrow["comments"],
//                "batch_no" => $myrow["batch_no"]);
//
//        $ious[] = $a;
//    }

}

//if (isset($_POST['UpdateData'])){
//    mark_selected_i_owe_yous($path_to_root);
//}

start_form();


br();


$Ajax->activate('leaves');

div_start('leaves');

$result = get_pos_for_pr_issues($pr_no);

if(db_num_rows($result) == 0){
    br(3);
    $note = "No Purchase Orders created for the selected Purchase Requisition";
    display_note($note);
    br(3);
}
else{
    start_table(TABLESTYLE, "width=90%");

    $th = array(_("Order No"),"Reference", _("Supplier"), "Project", _("Order Date"),
                _("Location"),_("Total"), "Delivery Address", "Issue");
    table_header($th);

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



    $approval_statuses_in = AS_NEW;

    //$ious = array();
    //build_po_array($ious, $pr_no);


    while ($myrow = db_fetch($result))
    {
            alt_table_row_color($k);

            //label_cells('',$myrow["id"]);
            label_cells('',$myrow["order_no"]);
            label_cells('',$myrow["reference"]);
            label_cells('',$myrow["supp_name"]);
            label_cells('',$myrow["project_description"]);
            label_cells('',sql2date($myrow["ord_date"]));
            label_cells('',$myrow["into_stock_location"]);

            qty_cell($myrow["total"], false, 2);

            label_cells('',$myrow["delivery_address"]);
    //        label_cells('',$myrow["total"],'', "align=center");

    //        check_cells('', 'selected_'.$iou_line["id"],0);
            $url = "<a href='$path_to_root/purchasing/pr_issues.php?pr_no=".$pr_no."&po_no=".$myrow['order_no']."'>" . "Issue" . "</a>";

                    label_cell($url);
            end_row();
            $j++;
            If ($j == 12)
            {
                    $j = 1;
                    table_header($th);
            }
    }
    end_table(1);
}




if ($_SESSION["wa_current_user"]->can_access('SA_PR_ISSUES_WITHOUT_POS')){
    $header_text = "Issue Items without a Purchase Order";
    display_heading($header_text);
    start_table(TABLESTYLE_NOBORDER, "width=40%");
    start_row();
        $s = ("If you issue items without a Purchase Order, cost will be charge to the Project as per the Purchase Requisition creator's estimated cost and NOT on Purchase Order price.");
        label_cell($s, "style=color:red");
    end_row();
    end_table(1);

    hyperlink_params("$path_to_root/purchasing/pr_issues.php", _("Issue without Purchase Order"), "pr_no=".$pr_no."&po_no=-1");

    br();
}

div_end();
//submit_center('UpdateData', _("Select"), true, false, 'default');

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