<?php
    session_start();
    if(!$_SESSION['id']){
        header('location:index.php');
    }
    
  require_once '../system/conn.php';
    $date1=date('Y-m-d');
    $date=date('Y-m-d', strtotime(date('Y-m')." -1 month"));

    $insert = " INSERT IGNORE INTO `prv_rev_payment` select * from `rev_payment_tbl`  where (`return_date` NOT BETWEEN '$date' AND '$date1') ";
    $statement = $conn->prepare($insert)->execute($data);
    
    if($statement){
       $delete = $conn->query(" DELETE FROM `rev_payment_tbl` WHERE (`return_date` NOT BETWEEN '$date' AND '$date1') ");
       if($delete) {
         echo "<script>alert('Archive payment entry successfully generate..')</script>";
         echo "<script>window.location.href = 'archive.php'</script>";   
       }
    }
?>