<?php

function dashboard_display_material_requisitions_view($from_month_display_order, $to_month_display_order) {
    start_table(TABLESTYLE, "width=99%");
        
        $th = array("Status");
        $month_ranges_array = dashboard_get_month_ranges_array($from_month_display_order, $to_month_display_order);
            foreach ($month_ranges_array as $month) {
                $th[] = $month['month_name'];
            }

            table_header($th);
        
                dashboard_material_requisition_details_view($month_ranges_array, DASH_VW_INVENTORY_MATERIAL_REQUISITIONS_CREATED, 0);

                dashboard_material_requisition_details_view($month_ranges_array, DASH_VW_INVENTORY_MATERIAL_REQUISITIONS_UNAPPROVED, 1);

                dashboard_material_requisition_types_detals($month_ranges_array, DASH_VW_INVENTORY_MATERIAL_REQUISITIONS_NOT_ISSUED, 0);

                dashboard_material_requisition_types_detals($month_ranges_array, DASH_VW_INVENTORY_MATERIAL_REQUISITIONS_PARTIALLY_ISSUED, 1);

                dashboard_material_requisition_types_detals($month_ranges_array, DASH_VW_INVENTORY_MATERIAL_REQUISITIONS_FULLY_ISSUED, 0);

                dashboard_material_requisition_types_detals($month_ranges_array, DASH_VW_INVENTORY_MATERIAL_REQUISITIONS_PARTIALLY_ISSUED_AND_CLOSED, 1);

                dashboard_material_requisition_types_detals($month_ranges_array, DASH_VW_INVENTORY_MATERIAL_REQUISITIONS_CLOSED_WITHOUT_ISSUING, 0);
            
    end_table(2);
}

function dashboard_material_requisition_details_view($month_ranges_array, $type, $k=0) {
    $ap_st_array = null;
    
        alt_table_row_color($k);

            if ($type === DASH_VW_INVENTORY_MATERIAL_REQUISITIONS_CREATED) {
                label_cell('Created');
            } else {
                label_cell('Unapproved');
                $ap_st_array = array(AS_NEW, AS_BACK_TO_ORIGINATOR, AS_AWAITING_APPROVAL, AS_WITH_THE_APPROVER);
            }

            foreach ($month_ranges_array as $month) {
                $from_date = $month['month_begin'];
                $to_date = $month['month_end'];
                $parameters = "type=$type&from_date=$from_date&to_date=$to_date";
                $count = dashboard_get_material_requisitions_count($from_date, $to_date, $ap_st_array);
                
                if($count > 0){
                    $str_count = get_dashboard_view_str(DASH_SC_INVENTORY_MATERIAL_REQUISITIONS, $parameters, $count);
                }else{
                    $str_count = '';
                }
                label_cell($str_count, 'align=center');
            }

        end_row();
}

function dashboard_material_requisition_types_detals($month_ranges_array, $type, $k=0) {
    global $dashboard_view_types_array;
    
    alt_table_row_color($k);

        label_cell($dashboard_view_types_array[$type]);
        
        switch ($type) {
            case DASH_VW_INVENTORY_MATERIAL_REQUISITIONS_NOT_ISSUED :
                foreach ($month_ranges_array as $month) {
                    $from_date = $month['month_begin'];
                    $to_date = $month['month_end'];
                    $parameters = "type=$type&from_date=$from_date&to_date=$to_date";
                    $count = dashboard_get_material_requisitions_not_issued_count($from_date, $to_date);
                    
                    if($count > 0){
                        $str_count = get_dashboard_view_str(DASH_SC_INVENTORY_MATERIAL_REQUISITIONS, $parameters, $count);
                    }else{
                        $str_count = '';
                    }

                    label_cell($str_count, 'align=center');
                }

                break;
            case DASH_VW_INVENTORY_MATERIAL_REQUISITIONS_PARTIALLY_ISSUED :
                foreach ($month_ranges_array as $month) {
                    $from_date = $month['month_begin'];
                    $to_date = $month['month_end'];
                    $parameters = "type=$type&from_date=$from_date&to_date=$to_date";
                    $count = dashboard_get_material_requisitions_partially_issued_count($from_date, $to_date);
                    
                    if($count > 0){
                        $str_count = get_dashboard_view_str(DASH_SC_INVENTORY_MATERIAL_REQUISITIONS, $parameters, $count);
                    }else{
                        $str_count = '';
                    }

                    label_cell($str_count, 'align=center');
                }

                break;
            case DASH_VW_INVENTORY_MATERIAL_REQUISITIONS_FULLY_ISSUED :
                foreach ($month_ranges_array as $month) {
                    $from_date = $month['month_begin'];
                    $to_date = $month['month_end'];
                    $parameters = "type=$type&from_date=$from_date&to_date=$to_date";
                    $count = dashboard_get_material_requisitions_fully_issued_count($from_date, $to_date);
                    
                    if($count > 0){
                        $str_count = get_dashboard_view_str(DASH_SC_INVENTORY_MATERIAL_REQUISITIONS, $parameters, $count);
                    }else{
                        $str_count = '';
                    }

                    label_cell($str_count, 'align=center');
                }

                break;
            case DASH_VW_INVENTORY_MATERIAL_REQUISITIONS_PARTIALLY_ISSUED_AND_CLOSED :
                foreach ($month_ranges_array as $month) {
                    $from_date = $month['month_begin'];
                    $to_date = $month['month_end'];
                    $parameters = "type=$type&from_date=$from_date&to_date=$to_date";
                    $count = dashboard_get_material_requisitions_partially_issued_and_closed_count($from_date, $to_date);
                    
                    if($count > 0){
                        $str_count = get_dashboard_view_str(DASH_SC_INVENTORY_MATERIAL_REQUISITIONS, $parameters, $count);
                    }else{
                        $str_count = '';
                    }

                    label_cell($str_count, 'align=center');
                }

                break;
            case DASH_VW_INVENTORY_MATERIAL_REQUISITIONS_CLOSED_WITHOUT_ISSUING :
                foreach ($month_ranges_array as $month) {
                    $from_date = $month['month_begin'];
                    $to_date = $month['month_end'];
                    $parameters = "type=$type&from_date=$from_date&to_date=$to_date";
                    $count = dashboard_get_material_requisitions_closed_without_issuing_count($from_date, $to_date);
                    
                    if($count > 0){
                        $str_count = get_dashboard_view_str(DASH_SC_INVENTORY_MATERIAL_REQUISITIONS, $parameters, $count);
                    }else{
                        $str_count = '';
                    }

                    label_cell($str_count, 'align=center');
                }

                break;

            default:
                break;
        }

    end_row();
}

?>