<?php

function loan_interests_graph_display(&$pg1, $from_month_id, $to_month_id)
{
    loan_interests_graph_set_values($pg1, $from_month_id, $to_month_id);

    $random_id = 'lig_'.$from_month_id."_".$to_month_id."_".time();
    
    $pg1->axis_value_names_angle = -30;
    
    $data = array();
    $data['title'] = "Loan Reayments Summary";
    $data['x_axis_name'] = "Month";
    $data['y_axis_name'] = "Value";
    $data['graph1_name'] = "Capital";
    $data['graph2_name'] = "Interest";
    $data['graph3_name'] = "Late Interest";
    
    
    //echo "<a href='".$path_to_root."/admin/dashboard_uda_level_1.php?month_id=".$month_id."&division_code=UDA_0001&level=".$level."'>";
    display_graph($pg1, $data, 1, $random_id);//line graph = 4
//    source_graphic($today, $title, , $pg1, "Target", _("Achievement"), 1, $random_id, "Trend");
    //echo "</a>";
}

function loan_interests_graph_set_values(&$pg1, $from_month_id, $to_month_id) 
{
    $title = "";

        $result = get_months_range($from_month_id, $to_month_id);
        $i = 0;
        $early_loans_value = 0;
        while ($myrow = db_fetch($result)) {

            $name = $myrow["description"];
            if ($pg1 != null) {
                $pg1->x[$i] = $name;

//                $loans = get_loans_total($myrow['id'], $myrow['month_begin_date'], $myrow['month_end_date']);
//                    if($loans == 0){
//                        $loans = $early_loans_value;
//                    }else{
//                        $early_loans_value = $loans;
//                    }
 
                $month_loan_payment_summary = get_month_loan_repayments_summary($myrow['display_order'], $myrow['display_order']);
                $capital_payments = $month_loan_payment_summary['capital_paid'];
                $late_interest = $month_loan_payment_summary['interest_paid'];       
                $interest = $month_loan_payment_summary['late_interest_paid'];       

                $pg1->y[$i] = $capital_payments;
                $pg1->z[$i] = $interest;
                $pg1->z1[$i] = $late_interest;

//                $pg1->y[$i] = $myrow['target'];
//                $pg1->z1[$i] = $pg1->z[$i]; // for trend calculation
                $pg1->colour_type[$i] = set_bar_colour_type($interest);
                
                
//                $pg1->y[$i] = $myrow['achievement'];
//                $pg1->z[$i] = $myrow['target'];
//                $pg1->z1[$i] = $myrow['target'];
//                $pg1->colour_type[$i] = set_bar_colour_type($myrow['achievement']);
            }
            
            
            $i++;
            
//            if($i == 1 && $myrow['achievement'] == null){
//                $title = "No data for ".$myrow['division_name'];
//            }
//            else{
//                $title = $myrow['division_name'];
//            }
        }

        return $title;

}




?>












































































































































































































































































