<?php


function read_mr($mr_no, &$mr_cart)
{
    read_mr_header($mr_no, $mr_cart);
    read_mr_details($mr_cart);
    
}
    
function read_mr_header($mr_id, &$mr_cart)
{
    $myrow = get_material_requisition($mr_id);
        
        //$mr_cart = $_SESSION['mr_items'];

        $mr_cart->order_id = $myrow["mr_no"];
        $mr_cart->reference = $myrow["reference"];
        if(isset($_POST['issuing_location'])){
            $mr_cart->issuing_location  = $_POST["issuing_location"];
        }
        else {
            $mr_cart->issuing_location  = $myrow["issuing_location"];
        }

        $mr_cart->required_date  = ($myrow["mr_required_date"]);
        $mr_cart->memo_  = $myrow["comments"];
        $mr_cart->requestor_name  = $myrow["requestor_name"];
        $mr_cart->created_on  = $myrow["created_on"];
        //$mr_cart->approval_path_id  = $myrow["approval_path_id"];
        $mr_cart->next_approval_group_id  = $myrow["next_approval_group_id"];
        $mr_cart->mr_complete  = $myrow["mr_complete"];
        $mr_cart->project_id  = $myrow["project_id"];
        //$mr_cart->task_id  = $myrow["task_id"];
        $mr_cart->job_reference  = $myrow["project_description"];
        $mr_cart->project_description  = $myrow["project_description"];
        //$mr_cart->task_description  = $myrow["task_description"];
        $mr_cart->approval_status  = $myrow["approval_status"];
        $mr_cart->created_by  = $myrow["created_by"];
        //$mr_cart->use_future_budget  = $myrow["use_future_budget"];

        if(isset($_POST['movement_type'])){
            $mr_cart->movement_type  = $_POST["movement_type"];
        }
        else{
            $mr_cart->movement_type  = $myrow["movement_type"];
            $_POST["movement_type"] = $myrow["movement_type"];
        }
        
        $mr_cart->sample_items = $myrow["sample_items"];
        
        if(isset($_POST['linked_field_id'])){
            $mr_cart->linked_field_id  = $_POST["linked_field_id"];
        }
        else{
            $mr_cart->linked_field_id  = $myrow["linked_field_id"];
            $_POST["linked_field_id"] = $myrow["linked_field_id"];
        }
        
        $mr_cart->row_state = $myrow["row_state"];
}
        
function read_mr_details(&$mr_cart)
{

    $mr_details = get_mr_details($mr_cart->order_id); 

    $element_no = 0;
    while ($mrd_row = db_fetch($mr_details)) 
    {
        $mr_line = new line_item($mrd_row["stock_id"], 0, $mrd_row["standard_cost"], 
                $mrd_row["description"],sql2date($mrd_row["required_date"]), $mrd_row["line_comment"],
                $comment=null, 
                $mrd_row["id"], $mrd_row["issued_qty"], $mrd_row["requested_qty"], 0, 0, null, 0, 
                null, null, null, null, null, $mrd_row["requested_unit"], $mrd_row["requested_unit_qty"], 
                $mrd_row["req_unit_conv_factor"]);

        $mr_line->row_id = $mrd_row["id"];
        $mr_line->line_complete = $mrd_row["line_complete"];
        $mr_line->created_by = $mrd_row["created_by"];
        $mr_line->created_on = $mrd_row["created_on"];
        $mr_line->high_value_item = $mrd_row["high_value_item"];
        $mr_line->sample_item = $mrd_row["sample_item"];
        $mr_line->reference_cost = $mrd_row["reference_cost"];
        $mr_line->pr_line_id = $mrd_row["pr_line_id"];
        $mr_line->task_id = $mrd_row["task_id"];
        $mr_line->task_description = $mrd_row["task_description"];
        $mr_line->project_site_id = $mrd_row["project_site_id"];
        $mr_line->project_site_description = $mrd_row["project_site_description"];

        $mr_cart->line_items[$element_no] = $mr_line;
        $element_no++;
    }

}


