	<?php
include '../includes/connection.php';

$sql = "SELECT business_id,DATE_FORMAT(recorded_on,'%Y-%m-%d') as date,(SELECT count(branch_id) from branches where branches.business_id=business.business_id) as branches FROM business where NOT EXISTS(SELECT business_id from licences where business_id=business.business_id)";

$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while ( $row = mysqli_fetch_assoc($result)) {
$b_id=$row['business_id'];
$branches=$row['branches'];
$startdate = $row['date']; 
$date = strtotime($startdate); 
$new_date = strtotime('+ 1 year', $date); 
$enddate= date('Y-m-d', $new_date);
 $yy=mysqli_query($con,"INSERT INTO licences(business_id,branches,startdate,enddate) values('$b_id','$branches','$startdate','$enddate')");
 if ($yy){
 }else{
 }
}

}
?>
