$leo_date=date('Y-m-d' ,time());
$leo_date_time=date('Y-m-d H:i:s' ,time());



$queryopm = "SELECT * FROM applied_loans where date_paid<='$leo_date'";
$resultsm= mysql_query($queryopm) or die ("Error $queryopm.".mysql_error());


							  
							  while ($rowsm=mysql_fetch_object($resultsm))
							  {
								  
echo $loan_id=$rowsm->applied_loan_id;
echo ' - ';
echo $date_paid=$rowsm->date_paid;

echo '</br>';

$loan_ref_no=$rowsm->loan_ref_no;	
					  
$member_id=$rowsm->member_id;						  

$queryop2r = "SELECT SUM(interest_installment) AS ttl_int_rev FROM loan_schedule 
where loan_id='$loan_id' AND schedule_date<='$leo_date'";
$results2r= mysql_query($queryop2r) or die ("Error $queryop2r.".mysql_error());
$rows2r=mysql_fetch_object($results2r);
$ttl_int_rev=$rows2r->ttl_int_rev;

$memo='Interest On loan ID '.$loan_ref_no;



$cr_transaction_code='int_rev_cr'.$loan_id.'-'.$leo_date;
$dr_transaction_code='int_rev_dr'.$loan_id.'-'.$leo_date;

$queryopm2 = "SELECT * FROM chart_transactions where transaction_code='$transaction_code'";
$resultsm2= mysql_query($queryopm2) or die ("Error $queryopm2.".mysql_error());
$num_rows2=mysql_num_rows($resultsm2);

if ($num_rows2>0)
{
	
	
	
}
else
{


if ($ttl_int_rev=='' || $ttl_int_rev==0)
{
	
	
	
}
else
{
	
	
/////////////////post to members account
//interest due to members account.
/* $memo2='Due Interest On loan ID '.$loan_ref_no;
$intr_transaction_code='intr'.$loan_id.'-'.$leo_date;
$sqltrans_st="INSERT INTO member_transactions SET 
member_id='$member_id',
group_id='$group_id',
transaction='$memo2',
amount='$ttl_int_rev',
debit='$ttl_int_rev',
credit='',
currency='$currency',
curr_rate='$curr_rate',
transaction_date='$leo_date',
date_recorded='$leo_date_time',
transaction_code='$intr_transaction_code',
transaction_type='LN-INT',
transaction_user_id='$user_id',
l_day='$day',
l_month='$month',
l_year='$year'";
$resultstrans_st=mysql_query($sqltrans_st) or die ("Error $sqltrans_st.".mysql_error());	
	
	
	
	
	
	
	
$sqltrans="INSERT INTO chart_transactions SET 
account_type_id='6',
transaction_section='INTR',
memo='$memo',
amount='$ttl_int_rev',
credit='$ttl_int_rev',
currency='7',
curr_rate='1',
transaction_date='$leo_date',
transaction_code='$cr_transaction_code',
transaction_datetime_recorded='$leo_date_time'";
$resultstrans=mysql_query($sqltrans) or die ("Error $sqltrans.".mysql_error());	

///////////////////////////post to accounts recivables
$sqltrans="INSERT INTO chart_transactions SET 
account_type_id='16',
transaction_section='INTR',
memo='$memo',
amount='$ttl_int_rev',
debit='$ttl_int_rev',
currency='7',
curr_rate='1',
transaction_code='$dr_transaction_code',
transaction_date='$leo_date',
transaction_datetime_recorded='$leo_date_time'";
$resultstrans=mysql_query($sqltrans) or die ("Error $sqltrans.".mysql_error()); */	

}
}


								  
								  
								  
								  
								  
								  
								  
							  }