<?php

function dashboard_view_supplier_delivery_lead_time($supplier_id, $from_date, $to_date) {

        display_heading('Delivery Lead Time');    br();
        
        $supplier_name = get_supplier_formatted_name($supplier_id);
        display_heading("Supplier : ".$supplier_name);    br();
        
        start_table(TABLESTYLE, "width=60%");

            $th = array("PO #","PO Date", "GRN #","GRN Date", "Lead Time<br>(Days)", "Item", "Unit", "Quantity");
                table_header($th);
                
                    $k = $total_amount = $count = 0;
                    $result = view_supplier_delivery_lead_time_details($supplier_id, $from_date, $to_date);
                        while($row = db_fetch($result)) {
                            alt_table_row_color($k);
                                $po_link = get_supplier_trans_view_str(ST_PURCHORDER, $row['order_no']);
                                label_cell($po_link, "align=center");
                                label_cell(sql2date($row['pod_delivery_date']),"align=center");
                                
                                $grn_link = get_supplier_trans_view_str(ST_SUPPRECEIVE, $row['grn_batch_id']);
                                label_cell($grn_link, "align=center");
                                label_cell(sql2date($row['grn_delivery_date']),"align=center");
                                
                                $lead_time = $row['lead_time'];
                                percent_cell($lead_time);                                
                                
                                $item_name = get_stock_item_formatted_name($row['item_code']);
                                label_cell($item_name);
                                
                                label_cell($row['unit_name'],"align=center");
                                amount_cell($row['tran_qty']);          
                                

                            end_row();

                            $total_amount += $lead_time;
                            $count++;
                        }
                        
                        start_row();
                            label_cell(text_bold("Average Delivery Lead Time"),"align=right colspan=4");
                            label_cell(text_bold(number_format($total_amount/$count, 2)),"align=right");
                            label_cell("");
                        end_row();
                
        end_table(2);
}


?>