<?php
/**********************************************************************
***********************************************************************/
//---------------------------------------------------------------------------------------------------
include_once($path_to_root . "/includes/db/approval_functions_db.inc");
function display_grn_summary(&$po)
{
	global $Refs;
    start_table(TABLESTYLE2, "width=90%");

    start_row();
	label_cells(_("Supplier"), $po->supplier_name, "class='tableheader2'");

    if (!is_company_currency($po->curr_code))
    	label_cells(_("Order Currency"), $po->curr_code, "class='tableheader2'");

    label_cells(_("For Purchase Order"), get_trans_view_str(ST_PURCHORDER, $po->order_no),
    	"class='tableheader2'");

	label_cells(_("Ordered On"), $po->orig_order_date, "class='tableheader2'");
	end_row();

   	start_row();
   	label_cells(_("Reference"), $po->reference, "class='tableheader2'");
   	label_cells(_("Deliver Into Location"), get_location_name($po->Location), "class='tableheader2'");
	label_cells(_("Supplier's Reference"), $po->supp_ref, "class='tableheader2'");

    end_row();

   	label_row(_("Delivery Address"), $po->delivery_address, "class='tableheader2'", "colspan=9");

    if ($po->Comments != "")
    	label_row(_("Order Comments"), $po->Comments, "class='tableheader2'", "colspan=9");
    end_table(1);
}

function edit_grn_summary(&$po)
{
	global $Refs;

    $project_id = $po->project_id;
    $user_id = $_SESSION['wa_current_user']->user;
    $cap = can_access_project($project_id, $user_id);
    if($cap['success'] !== true) 
    {
        display_error($cap["message"]);
        set_focus('project_id');
        display_footer_exit();
        exit;
    } 
    
    if(!(isset($po->receiving_pr_no) && $po->receiving_pr_no > 0)){// No PR selected
        if(!$_SESSION["wa_current_user"]->can_access('SA_GRNS_WITHOUT_PRS'))// No access to receive item without a PR        
        {
            $msg = "You are not alllowed to receive items without a purchase requisition.";
            display_error($msg);
            set_focus('project_id');
            display_footer_exit();
            exit;
        }
    }  
    
	start_outer_table(TABLESTYLE2, "width=80%");

	table_section(1);
	label_row(_("Supplier"), $po->supplier_name);

    	if (!is_company_currency($po->curr_code)){
    		label_row(_("Order Currency"), $po->curr_code);
        }

	label_row(_("For Purchase Order"), get_trans_view_str(ST_PURCHORDER, $po->order_no));

	label_row(_("Ordered On"), $po->orig_order_date);

	table_section(2);
    	if (!isset($_POST['ref'])){
    	    $_POST['ref'] = $Refs->get_next(ST_SUPPRECEIVE);
        }
    	ref_row(_("Reference"), 'ref', '', null);

        if (!isset($_POST['Location'])){
            $_POST['Location'] = $po->Location;
        }

        locations_list_row(_("Deliver Into Location"), "Location", $_POST['Location'], "Select a Location");

    	if (!isset($_POST['DefaultReceivedDate'])){
            $_POST['DefaultReceivedDate'] = new_doc_date();
        }

    	date_row(_("Date Items Received"), 'DefaultReceivedDate', '', true, 0, 0, 0, '', true);
        
        if(isset($_POST['project_id'])){
            $po->project_id  = $_POST["project_id"];
        }
            
        $po->task_id;
        $po->approval_path_id = 0;
        $po->approval_path_description = '';

//        project_list_row(_("Select a project:"), 'project_id', $po->project_id, "Select a Project",TRUE);
        
        $project = get_project_record($project_id);
        label_row("Project", $project['description']);
        hidden('project_id',$po->project_id);
        //tasks_list_row(_("Select a task:"), 'task_id', $po->project_id, $po->task_id,false, TRUE);

        if(isset($_POST['project_id'])){
            //$po->task_id  = $_POST["task_id"];
            $approval_path = get_approval_path($po->project_id, "PO");
            if($approval_path){
                $po->approval_path_id = $approval_path['approval_path_id'];
                $po->approval_path_description = $approval_path['approval_path_name'];
            }
        }

//        label_row("Approval Path:", $po->approval_path_description);

	table_section(3);
		// currently this is related order supp reference
//		ref_row(_("Supplier's Reference"), 'supp_ref', _("Supplier's Reference"));
        label_row(_("Supplier's Reference"), $po->supp_ref);

        label_row(_("Delivery Address"), $po->delivery_address);

    	if ($po->Comments != ""){
            label_row(_("Order Comments"), $po->Comments);
        }

	if (!is_company_currency($po->curr_code)){
            exchange_rate_display(get_company_currency(), $po->curr_code, get_post('DefaultReceivedDate'));
        }
	end_outer_table(1);
}

?>