<?php include "top.php"; 



$paks=mysqli_query($con,"SELECT * FROM `cbill` WHERE bl_payamt<>0");
while($aap=mysqli_fetch_array($paks)){
    $gstamt=floatval($aap['bl_payamt'])*(18/118);
               
            if($aap['bl_remarks']==''){

                $rmrk="Amount received from $aap[bl_cname]";
            }else{

                $rmrk=$aap['bl_remarks'];
            }
    $inspay=mysqli_query($con,"INSERT INTO tbl_billpay SET pay_date='$aap[bl_paydt]',pay_amt='$aap[bl_payamt]',pay_bill='$aap[blid]',pay_by='$aap[bl_paymd]',pay_user='$aap[bl_user]',pay_rmrk='$rmrk'");
    if($inspay){
        $srch=f(q("SELECT * FROM tbl_trans WHERE trn_type='MONTHLY BILL' AND trn_billid='$aap[blid]'"));
        if($srch['trn_ac']==''){
            
            
            
           
            $insdata=mysqli_query($con,"INSERT INTO tbl_trans SET trn_ac='$aap[bl_cid]',trn_name='$aap[bl_cname]',trn_amt='$aap[bl_payamt]',trn_date='$aap[bl_paydt]',trn_type='MONTHLY BILL',trn_memo='$rmrk',trn_gst='1',trn_grate='18',trn_gamt='$gstamt',trn_igst=0,trn_billid='$aap[blid]'");

            }



        }





}



?>