From df2e548a2ae5a184e582c7e9cb35a3d0b530dc95 Mon Sep 17 00:00:00 2001
From: Ibnu Maksum <ibnumaksum@gmail.com>
Date: Wed, 24 Jul 2024 09:04:17 +0700
Subject: [PATCH] delete used Voucher more than 3 months

---
 system/controllers/plan.php | 5 ++++-
 system/lan/english.json     | 3 ++-
 system/updates.json         | 3 ++-
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/system/controllers/plan.php b/system/controllers/plan.php
index 3cc1e206..adffeba9 100644
--- a/system/controllers/plan.php
+++ b/system/controllers/plan.php
@@ -480,7 +480,10 @@ switch ($action) {
         if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
             _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
         }
-        $d = ORM::for_table('tbl_voucher')->where_equal('status', '1')->findMany();
+        $time3months = strtotime('-3 months');
+        $d = ORM::for_table('tbl_voucher')->where_equal('status', '1')
+        ->where_raw("UNIX_TIMESTAMP(used_date) < $time3months")
+        ->findMany();
         if ($d) {
             $jml = 0;
             foreach ($d as $v) {
diff --git a/system/lan/english.json b/system/lan/english.json
index 77eebd2e..61af7a3d 100644
--- a/system/lan/english.json
+++ b/system/lan/english.json
@@ -661,5 +661,6 @@
     "Internet_Voucher_Expired": "Internet Voucher Expired",
     "": "",
     "Additional_Billing": "Additional Billing",
-    "_": "-"
+    "_": "-",
+    "Used_Date": "Used Date"
 }
\ No newline at end of file
diff --git a/system/updates.json b/system/updates.json
index d4aa9765..3d10cad5 100644
--- a/system/updates.json
+++ b/system/updates.json
@@ -127,6 +127,7 @@
         "ALTER TABLE `rad_acct` MODIFY `id` bigint NOT NULL AUTO_INCREMENT;"
     ],
     "2024.7.24" : [
-        "ALTER TABLE `tbl_voucher` ADD `used_date` DATETIME NULL DEFAULT NULL AFTER `status`;"
+        "ALTER TABLE `tbl_voucher` ADD `used_date` DATETIME NULL DEFAULT NULL AFTER `status`;",
+        "UPDATE `tbl_voucher` SET `used_date`=now() WHERE `status`=1;"
     ]
 }
\ No newline at end of file