<?php

function dashboard_display_purchase_requisitions($from_month_display_requisition, $to_month_display_requisition) {
    
   $month_ranges_array = dashboard_get_month_ranges_array($from_month_display_requisition, $to_month_display_requisition);
   $table_width = dashboard_calculate_table_width($month_ranges_array);
   
   start_table(TABLESTYLE, "width$table_width%");
        
        $th = array("Category");
            foreach ($month_ranges_array as $month) {
                $th[] = $month['month_name'];
            }

            table_header($th);
        
                dashboard_purchase_requisitions_details($month_ranges_array, DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_CREATED, 0);

                dashboard_purchase_requisitions_details($month_ranges_array, DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_UNAPPROVED, 1);

                dashboard_purchase_requisitions_types_details($month_ranges_array, DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_NOT_ORDERED, true, 0);

                dashboard_purchase_requisitions_types_details($month_ranges_array, DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_PARTIALLY_ORDERED, 1);

                dashboard_purchase_requisitions_types_details($month_ranges_array, DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_FULLY_ORDERED, 0);

                dashboard_purchase_requisitions_types_details($month_ranges_array, DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_NOT_ISSUED, 1);

                dashboard_purchase_requisitions_types_details($month_ranges_array, DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_PARTIALLY_ISSUED, 0);

                dashboard_purchase_requisitions_types_details($month_ranges_array, DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_FULLY_ISSUED, 1);
                
                dashboard_purchase_requisitions_types_details($month_ranges_array, DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_PARTIALLY_ISSUED_AND_CLOSED, 0);
                
                dashboard_purchase_requisitions_types_details($month_ranges_array, DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_CLOSED_WITHOUT_ISSUING, 1);
            
    end_table(2);
}

function dashboard_purchase_requisitions_details($month_ranges_array, $type, $not_ordered=null, $k=0) {
    global $dashboard_view_types_array;
    $ap_st_array = null;
    
        alt_table_row_color($k);

            label_cell($dashboard_view_types_array[$type]);
            
            if ($type === DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_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_purchase_requisitions_count($from_date, $to_date, $ap_st_array, $not_ordered);
                
                if($count>0){
                    $str_count = get_dashboard_view_str(DASH_SC_PURCHASE_PURCHASE_REQUISITIONS, $parameters, $count);
                }else{
                    $str_count = "";
                }

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

        end_row();
}

function dashboard_purchase_requisitions_types_details($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_PURCHASE_PURCHASE_REQUISITIONS_NOT_ORDERED :
                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_purchase_requisitions_not_ordered_count($from_date, $to_date);
                    
                    if($count>0){
                        $str_count = get_dashboard_view_str(DASH_SC_PURCHASE_PURCHASE_REQUISITIONS, $parameters, $count);
                    }else{
                        $str_count = "";
                    }
                        
                    label_cell($str_count, 'align=center');
                }

                break;
            case DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_PARTIALLY_ORDERED :
                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_purchase_requisitions_partially_ordered_count($from_date, $to_date);
                    
                    if($count>0){
                        $str_count = get_dashboard_view_str(DASH_SC_PURCHASE_PURCHASE_REQUISITIONS, $parameters, $count);
                    }else{
                        $str_count = "";
                    }
                        
                    label_cell($str_count, 'align=center');
                }

                break;
            case DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_FULLY_ORDERED :
                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_purchase_requisitions_fully_ordered_count($from_date, $to_date);
                    
                    if($count>0){
                        $str_count = get_dashboard_view_str(DASH_SC_PURCHASE_PURCHASE_REQUISITIONS, $parameters, $count);
                    }else{
                        $str_count = "";
                    }
                        
                    label_cell($str_count, 'align=center');
                }

                break;
            case DASH_VW_PURCHASE_PURCHASE_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_purchase_requisitions_not_issued_count($from_date, $to_date);
                    
                    if($count>0){
                        $str_count = get_dashboard_view_str(DASH_SC_PURCHASE_PURCHASE_REQUISITIONS, $parameters, $count);
                    }else{
                        $str_count = "";
                    }
                        
                    label_cell($str_count, 'align=center');
                }

                break;
            case DASH_VW_PURCHASE_PURCHASE_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_purchase_requisitions_partially_issued_count($from_date, $to_date);
                    
                    if($count>0){
                        $str_count = get_dashboard_view_str(DASH_SC_PURCHASE_PURCHASE_REQUISITIONS, $parameters, $count);
                    }else{
                        $str_count = "";
                    }
                        
                    label_cell($str_count, 'align=center');
                }

                break;
            case DASH_VW_PURCHASE_PURCHASE_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_purchase_requisitions_fully_issued_count($from_date, $to_date);
                    
                    if($count>0){
                        $str_count = get_dashboard_view_str(DASH_SC_PURCHASE_PURCHASE_REQUISITIONS, $parameters, $count);
                    }else{
                        $str_count = "";
                    }
                        
                    label_cell($str_count, 'align=center');
                }

                break;
            case DASH_VW_PURCHASE_PURCHASE_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_purchase_requisitions_partially_issued_and_closed_count($from_date, $to_date);
                    
                    if($count>0){
                        $str_count = get_dashboard_view_str(DASH_SC_PURCHASE_PURCHASE_REQUISITIONS, $parameters, $count);
                    }else{
                        $str_count = "";
                    }
                        
                    label_cell($str_count, 'align=center');
                }

                break;
            case DASH_VW_PURCHASE_PURCHASE_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_purchase_requisitions_partially_issued_and_closed_count($from_date, $to_date);
                    
                    if($count>0){
                        $str_count = get_dashboard_view_str(DASH_SC_PURCHASE_PURCHASE_REQUISITIONS, $parameters, $count);
                    }else{
                        $str_count = "";
                    }
                        
                    label_cell($str_count, 'align=center');
                }

                break;
            case DASH_VW_PURCHASE_PURCHASE_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_purchase_requisitions_closed_without_issuing_count($from_date, $to_date);
                    
                    if($count>0){
                        $str_count = get_dashboard_view_str(DASH_SC_PURCHASE_PURCHASE_REQUISITIONS, $parameters, $count);
                    }else{
                        $str_count = "";
                    }
                        
                    label_cell($str_count, 'align=center');
                }

                break;

            default:
                break;
        }

    end_row();
}

?>