<?php

function dashboard_purchase_requisitions_views($type, $from_date, $to_date) {
    $ap_st_array = null;
     
    switch ($type) {
        case DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_CREATED:
            $result = view_dashboard_get_purchase_requisitions_details($from_date, $to_date); 
                dashboard_print_purchase_requisitions_type_details($type, $result);
            break;
        
        case DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_UNAPPROVED:
            $ap_st_array = array(AS_NEW, AS_BACK_TO_ORIGINATOR, AS_AWAITING_APPROVAL, AS_WITH_THE_APPROVER);
            $result = view_dashboard_get_purchase_requisitions_details($from_date, $to_date, $ap_st_array); 
                dashboard_print_purchase_requisitions_type_details($type, $result);
            break;
        
        case DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_NOT_ORDERED:
            $result = view_dashboard_get_purchase_requisitions_not_ordered_details($from_date, $to_date); 
                dashboard_print_purchase_requisitions_type_details($type, $result);
            break;
        
        case DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_PARTIALLY_ORDERED:
            $result = view_dashboard_get_purchase_requisitions_partially_ordered_details($from_date, $to_date); 
                dashboard_print_purchase_requisitions_type_details($type, $result);
            break;
        
        case DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_FULLY_ORDERED:
            $result = view_dashboard_get_purchase_requisitions_fully_ordered_details($from_date, $to_date); 
                dashboard_print_purchase_requisitions_type_details($type, $result);
            break;
        
        case DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_NOT_ISSUED:
            $result = view_dashboard_get_purchase_requisitions_not_issued_details($from_date, $to_date); 
                dashboard_print_purchase_requisitions_type_details($type, $result);
            break;
        
        case DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_PARTIALLY_ISSUED:
            $result = view_dashboard_get_purchase_requisitions_partially_issued_details($from_date, $to_date); 
                dashboard_print_purchase_requisitions_type_details($type, $result);
            break;
        
        case DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_FULLY_ISSUED:
            $result = view_dashboard_get_purchase_requisitions_fully_issued_details($from_date, $to_date); 
                dashboard_print_purchase_requisitions_type_details($type, $result);
            break;
        
        case DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_PARTIALLY_ISSUED_AND_CLOSED:
            $result = view_dashboard_get_purchase_requisitions_partially_issued_and_closed_details($from_date, $to_date); 
                dashboard_print_purchase_requisitions_type_details($type, $result);
            break;
        
        case DASH_VW_PURCHASE_PURCHASE_REQUISITIONS_CLOSED_WITHOUT_ISSUING:
            $result = view_dashboard_get_purchase_requisitions_closed_without_issuing_details($from_date, $to_date); 
                dashboard_print_purchase_requisitions_type_details($type, $result);
            break;
    }
}

function dashboard_print_purchase_requisitions_type_details($type, $result) {
    global $dashboard_view_types_array, $document_approval_statuses;
    
        display_heading('Purchase Requisitions - '.$dashboard_view_types_array[$type]);    br();
        
        start_table(TABLESTYLE, "width=70%");

            $th = array("PR Date", "PR #", "Reference", "Project", "Approval Status", "Total");
                table_header($th);
                
                    $k = $total_amount = $count = 0;
                        while($row = db_fetch($result)) {
                            alt_table_row_color($k);
                                label_cell(sql2date($row['pr_date']),"align=center");
                                $link = get_trans_view_str(ST_PURCH_REQ, $row['pr_no']);
                                label_cell($link, "align=center");
                                label_cell($row['reference']);
                                label_cell($row['project_name']);
                                label_cell($document_approval_statuses[$row['approval_status']], "align=center");
                                $total = $row["total"];
                                label_cell(number_format($total, 2),"align=right");
                            end_row();

                            $total_amount += $total;
                            $count++;
                        }
                        
                        start_row();
                            label_cell(text_bold('Count'), "align=right");
                            label_cell(text_bold($count),"align=center");
                            label_cell(text_bold('Total'), "align=right colspan=3");
                            label_cell(text_bold(number_format($total_amount, 2)),"align=right");
                        end_row();
                
        end_table(2);
}

?>