Fix Balance sent/received

This commit is contained in:
Ibnu Maksum 2024-09-09 10:23:51 +07:00
parent f736868819
commit 0d2b140bcf
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
2 changed files with 17 additions and 4 deletions

View File

@ -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();
}
}

View File

@ -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'));
}