<?php


function cs_get_all_loan_repayments(){
    $sql = "SELECT * FROM  ".TB_PREF."company_loan_payments ";
    return db_query($sql,"cs_get_all_loan_repayments");
}

function  cs_update_company_loan_payment_loan_id($payment_id, $installment_id, $loan_id)
{
    $sql = "UPDATE ".TB_PREF."company_loan_payments   
            SET loan_id =".db_escape($loan_id)." 
            WHERE id = ".db_escape($payment_id)." AND installment_id = ".db_escape($installment_id);
    
    db_query($sql,"cs_update_company_loan_payment_loan_id");
}


function cs_update_loan_payment_loan_id()
{
    $d = cs_get_all_loan_repayments();
    while ($row = db_fetch($d)) {
        $installment = get_company_loan_installment($row['installment_id']);             
        cs_update_company_loan_payment_loan_id($row['id'], $row['installment_id'], $installment['loan_id']);   
    }
}

?>