<?php

function display_service_complain_status_summary_filtering_parameters() {
    start_table(TABLESTYLE_NOBORDER);
        start_row();
            date_cells(_("To Date:"), 'from_date', null, null, 0, -2);
            date_cells(_("To Date:"), 'to_date', null, null, 0, 0);
            
            submit_cells('SearchOrders', _("Search"), '', _('Select documents'), false, ICON_SUBMIT);
        end_row();
    end_table(1);
}

function display_service_complain_status_summary($from_date_, $to_date_) {
    $from_date = date2sql($from_date_); $to_date = date2sql($to_date_); $comp_totals_array = array();
        
        $th = array(_("Request Department"));
        
        $header_array = create_service_complain_status_summary_header_array();
            foreach ($header_array as $key => $value) {
                array_push($th, $value);
                
                $comp_totals_array[$key] = 0;
            }
            
            start_table(TABLESTYLE, "width=40%");
                table_header($th);

                    $k = $previous_department_id = 0;   
                    
                    $section_list_codes_array = create_request_departmens_array();
                        foreach ($section_list_codes_array as $req_ped_id => $req_dep_name) {
                            alt_table_row_color($k);
                                label_cell($req_dep_name);

                                foreach ($header_array as $key => $val) {
                                    if ($key == AS_CLOSED) {
                                        $closed = 1;
                                        $has_job = 0;
                                    } else {
                                        $closed = 0;
                                        $has_job = $key;
                                    }
                                    
                                    $count = get_service_complains_count_by_filters($from_date, $to_date, $req_ped_id, 0, $closed, $has_job);
                                    $params = "&from_date=$from_date&to_date=$to_date&req_department_id=$req_ped_id&closed=$closed&has_job=$has_job";
                                    
                                    if ($count > 0) {
                                        label_cell(get_dashboard_view_str(DASH_VW_SERVICE_SERVICE_COMPLAIN, $params, $count), 'align=center');
                                        
                                        $comp_totals_array[$key] += $count;
                                    } else {
                                        label_cell('');
                                    }
                                }
                            end_row();
                        }
                        
                        display_service_complain_status_summary_company_total($header_array, $comp_totals_array, $from_date, $to_date);

            end_table(2);
}

function create_service_complain_status_summary_header_array() {
    global $approval_statuses;
    
    $values_array = array();
    
        $values_array[AS_NEW] = $approval_statuses[AS_NEW];
        $values_array[1] = 'Has Job';
        $values_array[AS_CLOSED] = $approval_statuses[AS_CLOSED];
            
            return $values_array;
}

function display_service_complain_status_summary_company_total($header_array, $comp_totals_array, $from_date, $to_date) {
    start_row("style=background-color:#f58142");
        label_cell('', 'align=right');
        
        foreach ($header_array as $key => $val) {
            if ($key == AS_CLOSED) {
                $closed = 1;
                $has_job = 0;
            } else {
                $closed = 0;
                $has_job = $key;
            }
                                    
            $params = "&from_date=$from_date&to_date=$to_date&closed=$closed&has_job=$has_job";
                                    
            $comp_total = $comp_totals_array[$key];
            
                if ($comp_total > 0) {
                    label_cell(get_dashboard_view_str(DASH_VW_SERVICE_SERVICE_COMPLAIN, $params, text_bold($comp_total)), 'align=center');
                } else {
                    label_cell('0', 'align=center style=color:silver');
                }
        }
    end_row();
}

?>