Fix Balance sent/received

This commit is contained in:
Ibnu Maksum
2024-09-09 10:23:51 +07:00
parent f736868819
commit 0d2b140bcf
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();
}
}