diff --git a/system/autoload/Message.php b/system/autoload/Message.php index ece9ad4a..3f632e46 100644 --- a/system/autoload/Message.php +++ b/system/autoload/Message.php @@ -325,6 +325,42 @@ class Message $textInvoice = str_replace('[[password]]', $cust['password'], $textInvoice); $textInvoice = str_replace('[[expired_date]]', Lang::dateAndTimeFormat($trx['expiration'], $trx['time']), $textInvoice); $textInvoice = str_replace('[[footer]]', $config['note'], $textInvoice); + // Calculate bills and additional costs + list($bills, $add_cost) = User::getBills($cust['id']); + + // Initialize note and total variables + $note = ""; + $total = $trx['price']; + + // Add bills to the note if there are any additional costs + if ($add_cost != 0) { + foreach ($bills as $k => $v) { + $note .= $k . " : " . Lang::moneyFormat($v) . "\n"; + } + $total += $add_cost; + } + + // Calculate tax + $tax = 0; + $tax_enable = isset($config['enable_tax']) ? $config['enable_tax'] : 'no'; + if ($tax_enable === 'yes') { + $tax_rate_setting = isset($config['tax_rate']) ? $config['tax_rate'] : null; + $custom_tax_rate = isset($config['custom_tax_rate']) ? (float) $config['custom_tax_rate'] : null; + + $tax_rate = ($tax_rate_setting === 'custom') ? $custom_tax_rate : $tax_rate_setting; + $tax = Package::tax($trx['price'], $tax_rate); + + if ($tax != 0) { + $note .= "Tax : " . Lang::moneyFormat($tax) . "\n"; + $total += $tax; + } + } + + // Add total to the note + $note .= "Total : " . Lang::moneyFormat($total) . "\n"; + + // Replace placeholders in the message + $textInvoice = str_replace('[[bills]]', $note, $textInvoice); if ($config['user_notification_payment'] == 'sms') { Message::sendSMS($cust['phonenumber'], $textInvoice);