   <?php
   include_once 'opendb.php';
    $CompID=$_GET["comp_id"]; 
     clear_old_records($CompID, $conn);
     function clear_old_records($CompID, $conn){
    $cutDate=date('Y-m-d',strtotime('-60 day'));
    $sql="select entry_no from sales where sync_entry_no > 0 and Entry_date < '$cutDate' and comp_id=$CompID";
    $mresult = $conn->query($sql);
    $count=0;
    while ($row = mysqli_fetch_assoc($mresult)){
         $mENo=$row['entry_no'];
         $mqry="delete from sales_sub where entry_no=$mENo";
         $conn->query($mqry);
         $mqry="delete from sales where entry_no=$mENo";
         $conn->query($mqry);
         $count=$count+1;
    }
    mysqli_free_result($mresult);
    echo "deleted sales : " . $count;
}
    
    
?>