From 0d2b140bcfc9761e9d813ed403cdd4991f24556b Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Mon, 9 Sep 2024 10:23:51 +0700 Subject: [PATCH] Fix Balance sent/received --- system/autoload/Message.php | 16 ++++++++++++++-- system/controllers/home.php | 5 +++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/system/autoload/Message.php b/system/autoload/Message.php index a7fbae9b..988c98e0 100644 --- a/system/autoload/Message.php +++ b/system/autoload/Message.php @@ -201,10 +201,10 @@ class Message return "$via: $msg"; } - public static function sendBalanceNotification($cust, $balance, $balance_now, $message, $via) + public static function sendBalanceNotification($cust, $target, $balance, $balance_now, $message, $via) { global $config; - $msg = str_replace('[[name]]', $cust['fullname'] . ' (' . $cust['username'] . ')', $message); + $msg = str_replace('[[name]]', $target['fullname'] . ' (' . $target['username'] . ')', $message); $msg = str_replace('[[current_balance]]', Lang::moneyFormat($balance_now), $msg); $msg = str_replace('[[balance]]', Lang::moneyFormat($balance), $msg); $phone = $cust['phonenumber']; @@ -219,6 +219,7 @@ class Message } else if ($via == 'wa') { Message::sendWhatsapp($phone, $msg); } + self::addToInbox($cust['id'], Lang::T('Balance Notification'), $msg); } return "$via: $msg"; } @@ -258,4 +259,15 @@ class Message Message::sendWhatsapp($cust['phonenumber'], $textInvoice); } } + + + public static function addToInbox($to_customer_id, $subject, $body, $from = 'System'){ + $v = ORM::for_table('tbl_customers_inbox')->create(); + $v->from = $from; + $v->customer_id = $to_customer_id; + $v->subject = $subject; + $v->date_created = date('Y-m-d H:i:s'); + $v->body = nl2br($body); + $v->save(); + } } diff --git a/system/controllers/home.php b/system/controllers/home.php index 147476b5..a71d340e 100644 --- a/system/controllers/home.php +++ b/system/controllers/home.php @@ -71,8 +71,9 @@ if (_post('send') == 'balance') { $d->pg_url_payment = 'balance'; $d->status = 2; $d->save(); - Message::sendBalanceNotification($user, $balance, ($user['balance'] - $balance), Lang::getNotifText('balance_send'), $config['user_notification_payment']); - Message::sendBalanceNotification($target, $balance, ($target['balance'] + $balance), Lang::getNotifText('balance_received'), $config['user_notification_payment']); + // + Message::sendBalanceNotification($user, $target, $balance, ($user['balance'] - $balance), Lang::getNotifText('balance_send'), $config['user_notification_payment']); + Message::sendBalanceNotification($target, $user, $balance, ($target['balance'] + $balance), Lang::getNotifText('balance_received'), $config['user_notification_payment']); Message::sendTelegram("#u$user[username] send balance to #u$target[username] \n" . Lang::moneyFormat($balance)); r2(U . 'home', 's', Lang::T('Sending balance success')); }