<?php

function dashboard_view_top_items($item_code, $from_date, $to_date) {

        $item_name = get_stock_item_formatted_name($item_code);
        display_heading("Item : ".$item_name);    br();
        
        start_table(TABLESTYLE, "width=70%");

            $th = array("GRN Date", "GRN #", "Unit", "Quantity", "Unit Cost", "Line Cost", "Supplier", "PO#");
                table_header($th);
                
                    $k = $total_amount = $count = 0;
                    $result = dashboard_view_top_purchased_items_details($item_code, $from_date, $to_date);
                        while($row = db_fetch($result)) {
                            alt_table_row_color($k);
                                label_cell(sql2date($row['delivery_date']),"align=center");
                                $grn_link = get_supplier_trans_view_str(ST_SUPPRECEIVE, $row['grn_no']);
                                label_cell($grn_link, "align=center");
                                
                                label_cell($row['tran_unit'], "align=center");
                                $convertion_factor = $row['convertion_factor'];
                                amount_cell($row['tran_qty']);
                                
                                $tran_unit_cost = $row['unit_cost'] * $convertion_factor;
                                amount_cell($tran_unit_cost);
                                
                                $line_cost = $row['tran_qty'] * $tran_unit_cost;
                                amount_cell($line_cost);
                                
                                $supplier_name = get_supplier_formatted_name($row['supplier_id']);
                                label_cell($supplier_name);
                                
                                $link = get_supplier_trans_view_str(ST_PURCHORDER, $row['purch_order_no']);
                                label_cell($link, "align=center");
\
                            end_row();

                            $total_amount += $line_cost;
                            $count++;
                        }
                        
                        start_row();
                            label_cell(text_bold("Total (Without Taxes)"),"align=right colspan=5");
                            label_cell(text_bold(number_format($total_amount, 2)),"align=right");
                            label_cell("", "colspan=2");
                        end_row();
                
        end_table(2);
}


?>