From 15b9744b189c2882b3247e0468d3286e5773c859 Mon Sep 17 00:00:00 2001
From: Ibnu Maksum
Date: Thu, 24 Aug 2023 11:35:23 +0700
Subject: [PATCH] balance notification
---
system/autoload/Lang.php | 9 ++++++++
system/autoload/Message.php | 16 ++++++++++++++
system/autoload/Package.php | 8 +++----
system/boot.php | 3 +--
system/controllers/home.php | 7 ++++--
system/controllers/settings.php | 1 +
system/cron.php | 11 +++++-----
system/cron_reminder.php | 23 ++++++++++----------
system/lan/english/common.lan.php | 2 ++
system/uploads/notifications.default.json | 2 ++
ui/ui/app-notifications.tpl | 26 +++++++++++++++++++++++
11 files changed, 82 insertions(+), 26 deletions(-)
diff --git a/system/autoload/Lang.php b/system/autoload/Lang.php
index e8f34793..52abdd0f 100644
--- a/system/autoload/Lang.php
+++ b/system/autoload/Lang.php
@@ -49,4 +49,13 @@ class Lang
public static function arrayCount($arr){
return count($arr);
}
+
+ public static function getNotifText($key){
+ global $_notifmsg, $_notifmsg_default;
+ if(isset($_notifmsg[$key])){
+ return $_notifmsg[$key];
+ }else{
+ return $_notifmsg_default[$key];
+ }
+ }
}
diff --git a/system/autoload/Message.php b/system/autoload/Message.php
index 0373d682..15981d06 100644
--- a/system/autoload/Message.php
+++ b/system/autoload/Message.php
@@ -56,4 +56,20 @@ class Message
return "$via: $msg";
}
+ public static function sendBalanceNotification($phone, $name, $balance, $message, $via)
+ {
+ $msg = str_replace('[[name]]', "*$name*", $message);
+ $msg = str_replace('[[balance]]', "*" . Lang::moneyFormat($balance) . "*", $msg);
+ if (
+ !empty($phone) && strlen($phone) > 5
+ && !empty($message) && in_array($via, ['sms', 'wa'])
+ ) {
+ if ($via == 'sms') {
+ Message::sendSMS($phone, $msg);
+ } else if ($via == 'wa') {
+ Message::sendWhatsapp($phone, $msg);
+ }
+ }
+ return "$via: $msg";
+ }
}
diff --git a/system/autoload/Package.php b/system/autoload/Package.php
index 29de2f0f..97fbda01 100644
--- a/system/autoload/Package.php
+++ b/system/autoload/Package.php
@@ -49,7 +49,7 @@ class Package
Balance::plus($id_customer, $p['price']);
- $textInvoice = $_notifmsg['invoice_balance'];
+ $textInvoice = Lang::getNotifText('invoice_balance');
$textInvoice = str_replace('[[company_name]]', $_c['CompanyName'], $textInvoice);
$textInvoice = str_replace('[[address]]', $_c['address'], $textInvoice);
$textInvoice = str_replace('[[phone]]', $_c['phone'], $textInvoice);
@@ -165,7 +165,7 @@ class Package
"\nRouter: " . $router_name .
"\nGateway: " . $gateway .
"\nChannel: " . $channel .
- "\nPrice: " . $p['price']);
+ "\nPrice: " . Lang::moneyFormat($p['price']));
} else {
if ($b) {
@@ -241,12 +241,12 @@ class Package
"\nRouter: " . $router_name .
"\nGateway: " . $gateway .
"\nChannel: " . $channel .
- "\nPrice: " . $p['price']);
+ "\nPrice: " . Lang::moneyFormat($p['price']));
}
$in = ORM::for_table('tbl_transactions')->where('username', $c['username'])->order_by_desc('id')->find_one();
- $textInvoice = $_notifmsg['invoice_paid'];
+ $textInvoice = Lang::getNotifText('invoice_paid');
$textInvoice = str_replace('[[company_name]]', $_c['CompanyName'], $textInvoice);
$textInvoice = str_replace('[[address]]', $_c['address'], $textInvoice);
$textInvoice = str_replace('[[phone]]', $_c['phone'], $textInvoice);
diff --git a/system/boot.php b/system/boot.php
index b88699b3..dcfe4f11 100644
--- a/system/boot.php
+++ b/system/boot.php
@@ -131,9 +131,8 @@ include "autoload/Hookers.php";
// notification message
if(file_exists("system/uploads/notifications.json")){
$_notifmsg =json_decode(file_get_contents('system/uploads/notifications.json'), true);
-}else{
- $_notifmsg = json_decode(file_get_contents('system/uploads/notifications.default.json'), true);
}
+$_notifmsg_default = json_decode(file_get_contents('system/uploads/notifications.default.json'), true);
//register all plugin
foreach (glob("system/plugin/*.php") as $filename) {
diff --git a/system/controllers/home.php b/system/controllers/home.php
index a669ca7a..37147063 100644
--- a/system/controllers/home.php
+++ b/system/controllers/home.php
@@ -28,7 +28,7 @@ if (_post('send') == 'balance') {
if ($user['username'] == $target['username']) {
r2(U . 'home', 'd', Lang::T('Cannot send to yourself'));
}
- if(Balance::transfer($user['id'], $username, $balance)){
+ if (Balance::transfer($user['id'], $username, $balance)) {
//sender
$d = ORM::for_table('tbl_payment_gateway')->create();
$d->username = $user['username'];
@@ -46,6 +46,7 @@ if (_post('send') == 'balance') {
$d->pg_url_payment = 'balance';
$d->status = 2;
$d->save();
+ Message::sendBalanceNotification($user['phonenumber'], $target['fullname'] . ' (' . $target['username'] . ')', $balance, Lang::getNotifText('balance_send'), $config['user_notification_reminder']);
//receiver
$d = ORM::for_table('tbl_payment_gateway')->create();
$d->username = $target['username'];
@@ -63,9 +64,11 @@ if (_post('send') == 'balance') {
$d->pg_url_payment = 'balance';
$d->status = 2;
$d->save();
+ Message::sendBalanceNotification($target['phonenumber'], $user['fullname'] . ' (' . $user['username'] . ')', $balance, Lang::getNotifText('balance_received'), $config['user_notification_reminder']);
+ Message::sendTelegram("#u$user[username] send balance to #u$target[username] \n" . Lang::moneyFormat($balance));
r2(U . 'home', 's', Lang::T('Sending balance success'));
}
- }else{
+ } else {
r2(U . 'home', 'd', 'Failed, balance is not available');
}
}
diff --git a/system/controllers/settings.php b/system/controllers/settings.php
index 0de22c16..5b0d94e4 100644
--- a/system/controllers/settings.php
+++ b/system/controllers/settings.php
@@ -502,6 +502,7 @@ switch ($action) {
}else{
$ui->assign('_json', json_decode(file_get_contents('system/uploads/notifications.default.json'), true));
}
+ $ui->assign('_default', json_decode(file_get_contents('system/uploads/notifications.default.json'), true));
$ui->display('app-notifications.tpl');
break;
case 'notifications-post':
diff --git a/system/cron.php b/system/cron.php
index 2106ef9a..75465898 100644
--- a/system/cron.php
+++ b/system/cron.php
@@ -19,11 +19,10 @@ ORM::configure('logging', true);
include "autoload/Hookers.php";
// notification message
-if (file_exists("uploads/notifications.json")) {
- $_notifmsg = json_decode(file_get_contents('uploads/notifications.json'), true);
-} else {
- $_notifmsg = json_decode(file_get_contents('uploads/notifications.default.json'), true);
+if(file_exists("system/uploads/notifications.json")){
+ $_notifmsg =json_decode(file_get_contents('system/uploads/notifications.json'), true);
}
+$_notifmsg_default = json_decode(file_get_contents('system/uploads/notifications.default.json'), true);
//register all plugin
foreach (glob("plugin/*.php") as $filename) {
@@ -64,10 +63,10 @@ $_c = $config;
date_default_timezone_set($config['timezone']);
-$textExpired = $_notifmsg['expired'];
+$textExpired = Lang::getNotifText('expired');
$d = ORM::for_table('tbl_user_recharges')->where('status', 'on')->where('expiration', date("Y-m-d"))->find_many();
-
+echo "Found ".count($d)." user(s)\n";
run_hook('cronjob'); #HOOK
foreach ($d as $ds) {
diff --git a/system/cron_reminder.php b/system/cron_reminder.php
index 8fd04c12..2985a4af 100644
--- a/system/cron_reminder.php
+++ b/system/cron_reminder.php
@@ -22,11 +22,10 @@ ORM::configure('logging', true);
include "autoload/Hookers.php";
// notification message
-if(file_exists("uploads/notifications.json")){
- $_notifmsg =json_decode(file_get_contents('uploads/notifications.json'), true);
-}else{
- $_notifmsg = json_decode(file_get_contents('uploads/notifications.default.json'), true);
+if(file_exists("system/uploads/notifications.json")){
+ $_notifmsg =json_decode(file_get_contents('system/uploads/notifications.json'), true);
}
+$_notifmsg_default = json_decode(file_get_contents('system/uploads/notifications.default.json'), true);
//register all plugin
foreach (glob("plugin/*.php") as $filename) {
@@ -74,17 +73,17 @@ run_hook('cronjob_reminder'); #HOOK
$day7 = date('Y-m-d', strtotime("+7 day"));
$day3 = date('Y-m-d', strtotime("+3 day"));
$day1 = date('Y-m-d', strtotime("+1 day"));
-print_r([$day1,$day3,$day7]);
+print_r([$day1, $day3, $day7]);
foreach ($d as $ds) {
- if(in_array($ds['expiration'],[$day1,$day3,$day7])){
+ if (in_array($ds['expiration'], [$day1, $day3, $day7])) {
$u = ORM::for_table('tbl_user_recharges')->where('id', $ds['id'])->find_one();
$c = ORM::for_table('tbl_customers')->where('id', $ds['customer_id'])->find_one();
- if($ds['expiration']==$day7){
- echo Message::sendPackageNotification($c['phonenumber'], $c['fullname'], $u['namebp'], $_notifmsg['reminder_7_day'], $config['user_notification_reminder'])."\n";
- }else if($ds['expiration']==$day3){
- echo Message::sendPackageNotification($c['phonenumber'], $c['fullname'], $u['namebp'], $_notifmsg['reminder_3_day'], $config['user_notification_reminder'])."\n";
- }else if($ds['expiration']==$day1){
- echo Message::sendPackageNotification($c['phonenumber'], $c['fullname'], $u['namebp'], $_notifmsg['reminder_1_day'], $config['user_notification_reminder'])."\n";
+ if ($ds['expiration'] == $day7) {
+ echo Message::sendPackageNotification($c['phonenumber'], $c['fullname'], $u['namebp'], Lang::getNotifText('reminder_7_day'), $config['user_notification_reminder']) . "\n";
+ } else if ($ds['expiration'] == $day3) {
+ echo Message::sendPackageNotification($c['phonenumber'], $c['fullname'], $u['namebp'], Lang::getNotifText('reminder_3_day'), $config['user_notification_reminder']) . "\n";
+ } else if ($ds['expiration'] == $day1) {
+ echo Message::sendPackageNotification($c['phonenumber'], $c['fullname'], $u['namebp'], Lang::getNotifText('reminder_1_day'), $config['user_notification_reminder']) . "\n";
}
}
}
diff --git a/system/lan/english/common.lan.php b/system/lan/english/common.lan.php
index c57f8e4d..b8340e4a 100644
--- a/system/lan/english/common.lan.php
+++ b/system/lan/english/common.lan.php
@@ -380,3 +380,5 @@ $_L['Sending_balance_success'] = 'Sending balance success';
$_L['From'] = 'From';
$_L['To'] = 'To';
$_L['insufficient_balance'] = 'insufficient balance';
+$_L['Send_Balance'] = 'Send Balance';
+$_L['Received_Balance'] = 'Received Balance';
diff --git a/system/uploads/notifications.default.json b/system/uploads/notifications.default.json
index 21e9c1cc..a1485439 100644
--- a/system/uploads/notifications.default.json
+++ b/system/uploads/notifications.default.json
@@ -1,5 +1,7 @@
{
"expired": "Hello [[name]], your internet package [[package]] has been expired.",
+ "balance_send": "You sent [[balance]] to [[name]].",
+ "balance_received": "You have received [[balance]] from [[name]].",
"reminder_7_day": "Hello *[[name]]*, \r\nyour internet package *[[package]]* will be expired in 7 days.",
"reminder_3_day": "Hello *[[name]]*, \r\nyour internet package *[[package]]* will be expired in 3 days.",
"reminder_1_day": "Hello *[[name]]*,\r\n your internet package *[[package]]* will be expired tomorrow.",
diff --git a/ui/ui/app-notifications.tpl b/ui/ui/app-notifications.tpl
index 6446adf1..a453f864 100644
--- a/ui/ui/app-notifications.tpl
+++ b/ui/ui/app-notifications.tpl
@@ -113,6 +113,32 @@
+
+