<?php

function job_order_materials(&$jo_id) {
    global $path_to_root, $Ajax;
    
    $Ajax->activate('job_order_materials');
    div_start('job_order_materials');
        display_job_order_materials($jo_id);

        start_table();
            hyperlink_params_separate($path_to_root . "/inventory/job_material_requisitions.php", 'Create a New Job Material Request', "jo_id=$jo_id");
        end_table();
    div_end();
}

function display_job_order_materials($jo_id) {
    global $approval_statuses, $path_to_root, $systypes_array;
    
    display_heading("Job Material Requision Headers");    
    
	start_table(TABLESTYLE, "width=80%");
        
            $th = array(_("Id"), _("Trans #"), _("Location"), _("Date"), _("Approval Status"), _("Created Via"), _(""), _(""), _("")); 
            table_header($th);
            
            $k = 0;  
            
            $result = get_job_material_requisition_headers($jo_id);
                while ($row = db_fetch($result)) {
                    alt_table_row_color($k);

                        $id = $row['id'];
			label_cell($id, 'align=center');
			label_cell(get_inventory_trans_view_str($row['type'], $row['trans_no']), 'align=center');
			label_cell($row['location_name']);
			label_cell(sql2date($row['tran_date']), 'align=center');
			label_cell($approval_statuses[$row['approval_status']], 'align=center');
                        if ($row['source_trans_no'] > 0) {
                            label_cell($systypes_array[$row['source_type']]);
                        } else {
                            label_cell('Directly');
                        }
                        
                        if (in_array($row['approval_status'], array(AS_NEW, AS_WITH_THE_APPROVER, AS_AWAITING_APPROVAL, AS_BACK_TO_ORIGINATOR))) {
                            label_cell(''); label_cell('');
                            $link = "<a target='_blank' href='$path_to_root/inventory/job_material_requisitions.php?ModifyJMR_No=$id' >Edit</a>";
                            label_cell($link, 'align=center');
                        } elseif (in_array($row['approval_status'], array(AS_APPROVED))) {
                            $link = "<a target='_blank' href='$path_to_root/inventory/job_material_issue_requisitions.php?jmr_no=$id'>Issue Req.</a>";
                            label_cell($link, 'align=center');
                            
                            $link_2 = "<a target='_blank' href='$path_to_root/inventory/job_material_returns.php?jmr_no=$id'>Return</a>";
                            label_cell($link_2, 'align=center');
                            
                            $param = "jmr_no=$id&type=".ST_DIRECT_PURCHASE_REQ;
                            $link_3 = "<a target='_blank' href='$path_to_root/inventory/job_material_requisition_dpr.php?$param'>DP Req.</a>";
                            label_cell($link_3, 'align=center');
                        } elseif (in_array($row['approval_status'], array(AS_COMPLETED))) {
                            label_cell('');
                            
                            $link_2 = "<a target='_blank' href='$path_to_root/inventory/job_material_returns.php?jmr_no=$id'>Return</a>";
                            label_cell($link_2, 'align=center');
                            
                            $param = "jmr_no=$id&type=".ST_DIRECT_PURCHASE_REQ;
                            $link_3 = "<a target='_blank' href='$path_to_root/inventory/job_material_requisition_dpr.php?$param'>DP Req.</a>";
                            label_cell($link_3, 'align=center');
                        } else {
                            label_cell(''); label_cell(''); label_cell('');
                        }
                        
                    end_row();
            }

    end_table(2);
}

?>