<?php

function sc_calculate_loan_summary($calculation_id, $calculation_type, $group_code, $month_id, $month_begin_date, $month_end_date, $recalculate)
{
    delete_monthly_loan_payment_summary($month_id);
//    $m_row = get_month($month_id);
//    $month_end_date = $m_row['month_end_date'];
    
    
    $result = get_monthly_company_loans($month_end_date);
    while($company_loan = db_fetch($result))
    {
        $summary = get_monthly_loan_summary($company_loan['id'], $month_end_date);
//        AND (cl.completed_date = '0000-00-00' OR cl.completed_date >= ".db_escape($month_begin_date).")  
        $loan_balance = $company_loan['loan_amount'] + $company_loan['interest'] - ($summary['total_capital_paid'] + $summary['total_interest_paid']);
                
        add_to_monthly_summary_loans($month_id, $company_loan['id'], $calculation_type, $summary['total_capital_paid'], 
                                     $summary['total_interest_paid'], $summary['total_late_interest_paid'], $loan_balance, $calculation_id);
    }

}
