<body background="">
<?php include("../../include/dbconnect.php"); 
$filename = 'templedger';
if($filename !='')
{
	if($cnf=='Yes')
	{
	
		$result= mysqli_query($conn,"select sum(dbamt),sum(cramt) from `$filename` ") or die(mysqli_error());
		$row = mysqli_fetch_row($result);
		$cdbamt = $row[0];
		$ccramt = $row[1];
		$ent_dt = date('Y-m-d');
		if($cdbamt == $ccramt)
		{
	
			$query= "insert into ledger(acctcode,date,narration,dbamt,cramt,type,invno,compcode,branch_code,trans_id,account_year,cheqno,entered_by,voucher_no,date_of_entry,taxtype) select acctcode,date,narration,dbamt,cramt,type,invno,compcode,branch_code,trans_id,account_year,cheqno,entered_by,voucher_no,curdate(),cheq_date from `$filename` ";
			echo($query);
			mysqli_query($conn,$query) or die(mysqli_error());
			

		}
		else
		{
			echo("Debit and Credit Balances are not tallying.. Please go back and correct it.");
			exit;
		}
	}
}
else
{
	?>
    	<script language="javascript">
		alert("You have closed the Main Program Browser before saving the data, due to that Data won't be saved. Please login again and enter ");
        </script>
    <?
	exit;
}

$mresult = mysqli_query($conn,"select acctcode,cramt,compcode,account_year,branch_code,invno,voucher_no,date from templedger where cramt > 0 and reconciled_by = 'Yes' ") or die(mysqli_error());
while($mrow = mysqli_fetch_row($mresult))
{
	$bcode = $mrow[0];
	$cramt = $mrow[1];
	$compcode = $mrow[2];
	$account_year = $mrow[3];
	$branch = $mrow[4];
	$invno = $mrow[5];
	$voucher_no = $mrow[6];
	$date = british($mrow[7]);
	
	$bresult = mysqli_query($conn,"select mobile,name from buy where bcode = '$bcode' ") or die(mysqli_error());
	$brow = mysqli_fetch_row($bresult);
	$mobile = $brow[0];
	$name = $brow[1];
	if($mobile > 0)
	{
		$balance = smsbalance($compcode,$branch,$bcode,$account_year);
		//$message = '(Name:'.$name.'),(Mobile:'.$mobile.'),( Cramt='.$cramt.'),(Balance :'.$balance.')';
		$message = 'Dear Customer, Thanks for your  payment of  Rs.'.$cramt.' The receipt no is '.$voucher_no.'  Your balance as on '.$date.' is Rs.'.$balance.' For any queries please contact 97456 47810 - CLASSIC BELTS';
		$message=addslashes($message);
		$hallo = sendsms($mobile,$message);
	}
}


			$query= "truncate table $filename";
			mysqli_query($conn,$query) or die(mysqli_error());

?>
<meta http-equiv="refresh" content="0 url=input2.php?compcode=<?=$compcode?>&branch=<?=$branch?>&myHead=vim">


