<?php

function dashboard_view_transport_item_consumption($item_code, $from_date, $to_date, $project_id, $linked_field_type_id, $linked_field_id) {
    
    global $systypes_array, $inventory_movement_type_linked_fields;
    
        display_heading('Transport Item Consumption');   
        
        if($project_id > 0){
            $project_name = get_project_formatted_name($project_id);
            display_heading("Project : ".$project_name);    
        }
        
        if(strlen($item_code) > 2){
            $item = get_stock_item_edit_info($item_code);
            $unit_name = $item['unit_name'];
            $item_name = get_stock_item_formatted_name($item_code);
            display_heading("Item : ".$item_name);    
        }else{
            $unit_name = "";
            $item_name = "";
        }
    
        if($linked_field_type_id > 0){
            $lf_name = get_movement_type_linked_field_values($linked_field_type_id, $linked_field_id, '');
            $linked_field_name  = $inventory_movement_type_linked_fields[$linked_field_type_id]." : ".$lf_name["value"]; 
            display_heading($linked_field_name);    br();
        }
                            
        
        start_table(TABLESTYLE, "width=80%");

            $th = array("Date", "Type", "Trans. No.", "Movement Type", "Item", "Unit", "Quantity", "Unit Cost", "Amount"); 
            
                table_header($th);
                
                    $k = $total_amount = $count = 0;
                    $result = view_dashboard_transport_item_consumption($project_id, $item_code, $from_date, $to_date, $linked_field_type_id, $linked_field_id);
                        while($row = db_fetch($result)) {
                            alt_table_row_color($k);
                                label_cell(sql2date($row['tran_date']),"align=center");
                                label_cell($systypes_array[$row["trans_type"]]);
                                $link = get_trans_view_str($row['trans_type'], $row['trans_no']);
                                label_cell($link, "align=center");
                                label_cell($row["movement_type_name"]);
                                
                                if(strlen($item_code) > 0){
//                                    $item_code = $item_code;
                                }else{
                                    $item_code = $row["item_code"];
                                }
                                
                                if(strlen($row["item_trans_description"]) > 0){
                                    $display_item_name  = $item_code." - ".$row["item_trans_description"];
                                }else{
                                    $display_item_name = $item_name;
                                }
                                label_cell($display_item_name);
                                label_cell($row['tran_unit_name']);
                                qty_cell($row['tran_qty']);
                                $tran_unit_cost = $row['unit_cost'] * $row['conversion_factor'];
                                $tran_unit_cost = round($tran_unit_cost,2);
                                amount_cell($row['unit_cost']);
                                
                                $total = $row['qty'] * $row['unit_cost'];
                                amount_cell($total);
                                
                            end_row();

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


?>