From cdfbab7119daab3f32563906a429e096dfd5d94b Mon Sep 17 00:00:00 2001 From: Focuslinkstech <45756999+Focuslinkstech@users.noreply.github.com> Date: Tue, 18 Mar 2025 16:51:37 +0100 Subject: [PATCH] Refactor invoice handling to use 'invoice' key and improve payment link generation Still in development --- system/autoload/Invoice.php | 34 ++++++++++++++--------- system/uploads/notifications.default.json | 21 +++++++------- ui/ui/admin/settings/notifications.tpl | 3 +- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/system/autoload/Invoice.php b/system/autoload/Invoice.php index 423a626e..96f558e6 100644 --- a/system/autoload/Invoice.php +++ b/system/autoload/Invoice.php @@ -7,7 +7,7 @@ class Invoice public static function generateInvoice($invoiceData) { try { - if (empty($invoiceData['id'])) { + if (empty($invoiceData['invoice'])) { throw new Exception("Invoice ID is required"); } @@ -45,7 +45,7 @@ class Invoice $mpdf->WriteHTML($processedHtml); // Save PDF - $filename = "invoice_{$invoiceData['id']}.pdf"; + $filename = "invoice_{$invoiceData['invoice']}.pdf"; $outputPath = "system/uploads/invoices/{$filename}"; $mpdf->Output($outputPath, 'F'); @@ -88,9 +88,9 @@ class Invoice }, $template); } - public static function sendInvoice($userId, $package, $status = "Unpaid") + public static function sendInvoice($userId, $status = "Unpaid") { - global $config; + global $config, $root_path, $UPLOAD_PATH; if (empty($config['currency_code'])) { $config['currency_code'] = '$'; @@ -142,19 +142,28 @@ class Invoice $tax = $config['enable_tax'] ? Package::tax($subtotal) : 0; $total = ($tax > 0) ? $subtotal + $tax : $subtotal + $tax; - $token = User::generateToken($account['id'], 1); + $token = User::generateToken($account->id, 1); if (!empty($token['token'])) { $tur = ORM::for_table('tbl_user_recharges') - ->where('customer_id', $account['id']) - ->where('namebp', $package) - ->find_one(); - if ($tur) { - $payLink = '?_route=home&recharge=' . $tur['id'] . '&uid=' . urlencode($token['token']); + ->where('customer_id', $account->id) + ->where('namebp', $invoice->plan_name); + + switch ($status) { + case 'Paid': + $tur->where('status', 'on'); + break; + default: + $tur->where('status', 'off'); + break; } + $turResult = $tur->find_one(); + $payLink = $turResult ? '?_route=home&recharge=' . $turResult['id'] . '&uid=' . urlencode($token['token']) : '?_route=home'; } else { $payLink = '?_route=home'; } + $UPLOAD_URL_PATH = str_replace($root_path, '', $UPLOAD_PATH); + $logo = (file_exists($UPLOAD_PATH . DIRECTORY_SEPARATOR . 'logo.png')) ? $UPLOAD_URL_PATH . DIRECTORY_SEPARATOR . 'logo.png?' . time() : $UPLOAD_URL_PATH . DIRECTORY_SEPARATOR . 'logo.default.png'; $invoiceData = [ 'invoice' => "INV-" . Package::_raid(), 'fullname' => $account->fullname, @@ -169,9 +178,8 @@ class Invoice 'company_address' => $config['address'], 'company_name' => $config['CompanyName'], 'company_phone' => $config['phone'], - 'logo' => $config['logo'], - 'company_url' => APP_URL, - 'payment_link' => $payLink, + 'logo' => $logo, + 'payment_link' => $payLink ]; if (!isset($invoiceData['bill_rows']) || empty($invoiceData['bill_rows'])) { diff --git a/system/uploads/notifications.default.json b/system/uploads/notifications.default.json index 45fd9acb..b22efb78 100644 --- a/system/uploads/notifications.default.json +++ b/system/uploads/notifications.default.json @@ -1,13 +1,12 @@ { - "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.", - "invoice_paid": "*[[company_name]]*\r\n[[address]]\r\n[[phone]]\r\n\r\n\r\nINVOICE: *[[invoice]]*\r\nDate : [[date]]\r\n[[payment_gateway]] [[payment_channel]]\r\n\r\n\r\nType : *[[type]]*\r\nPackage : *[[plan_name]]*\r\nPrice : *[[plan_price]]*\r\n\r\nUsername : *[[user_name]]*\r\nPassword : ***********\r\n\r\nExpired : *[[expired_date]]*\r\n\r\n====================\r\n[[footer]]", - "email_invoice": "\r\n\r\n\r\n\r\n \r\n Invoice No: [[id]]\r\n\r\n \r\n\r\n\r\n\r\n
\r\n \r\n \r\n \r\n \r\n\r\n \r\n \r\n \r\n\r\n [[bill_rows]]\r\n
\r\n \r\n \r\n \r\n\r\n \r\n \r\n
\r\n \r\n \r\n Invoice #: [[invoice]]
\r\n Created: [[created_at]]
\r\n Due: [[due_date]]\r\n
\r\n
\r\n \r\n \r\n \r\n\r\n \r\n \r\n
\r\n [[company_name]]
\r\n [[company_address]]
\r\n [[company_phone]]
\r\n
\r\n [[fullname]]
\r\n [[address]]
\r\n [[email]]
\r\n [[phone]]
\r\n
\r\n
\r\n\r\n
\r\n

Payment Options:

\r\n

Online Portal: pay.phpnuxbill.com
\r\n Bank Transfer: Account # 1234-567890
\r\n Auto Pay: Enabled (Next payment: 2023-11-12)

\r\n
\r\n\r\n \r\n

Thank you for choosing [[company_name]]!
\r\n Late payments may result in service interruption
\r\n Need help? Contact support@[[company_name]].com or call [[company_phone]]

\r\n \r\n
\r\n\r\n\r\n", - "invoice_balance": "*[[company_name]]*\r\n[[address]]\r\n[[phone]]\r\n\r\n\r\nINVOICE: *[[invoice]]*\r\nDate : [[date]]\r\n[[payment_gateway]] [[payment_channel]]\r\n\r\n\r\nType : *[[type]]*\r\nPackage : *[[plan_name]]*\r\nPrice : *[[plan_price]]*\r\n\r\n====================\r\n[[footer]]", - "welcome_message": "Welcome aboard, [[name]]! \r\nWe're excited to have you as a new [[company]] customer. \r\nYour account is all set up and ready to go.\r\n\r\nHere's a quick overview:\r\n\r\nPortal: [[url]]\r\nYour login is [[Username]]\r\nYour temporary password is [[Password]] (please change this on your first login)\r\n\r\nNeed help? Reach out to our support team at anytime.\r\n\r\nWe're here to ensure you have an amazing experience with our services. Let us know how we can best support you.\r\n\r\nWelcome to the [[company]] family!" - + "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.", + "invoice_paid": "*[[company_name]]*\r\n[[address]]\r\n[[phone]]\r\n\r\n\r\nINVOICE: *[[invoice]]*\r\nDate : [[date]]\r\n[[payment_gateway]] [[payment_channel]]\r\n\r\n\r\nType : *[[type]]*\r\nPackage : *[[plan_name]]*\r\nPrice : *[[plan_price]]*\r\n\r\nUsername : *[[user_name]]*\r\nPassword : ***********\r\n\r\nExpired : *[[expired_date]]*\r\n\r\n====================\r\n[[footer]]", + "email_invoice": "\r\n\r\n\r\n\r\n \r\n Invoice No: [[invoice]]\r\n\r\n \r\n\r\n\r\n\r\n
\r\n \r\n \r\n \r\n \r\n\r\n \r\n \r\n \r\n\r\n [[bill_rows]]\r\n
\r\n \r\n \r\n \r\n\r\n \r\n \r\n
\r\n \r\n \r\n Invoice #: [[invoice]]
\r\n Created: [[created_at]]
\r\n Due: [[due_date]]\r\n
\r\n
\r\n \r\n \r\n \r\n\r\n \r\n \r\n
\r\n [[company_name]]
\r\n [[company_address]]
\r\n [[company_phone]]
\r\n
\r\n [[fullname]]
\r\n [[address]]
\r\n [[email]]
\r\n [[phone]]
\r\n
\r\n
\r\n\r\n
\r\n

Payment Options:

\r\n

Online Portal: https://yoursite-domain.com/[[payment_link]]
\r\n Bank Transfer: Account # 1234-567890
\r\n Auto Pay: Enabled (Next payment: 2023-11-12)

\r\n
\r\n\r\n \r\n

Thank you for choosing [[company_name]]!
\r\n Late payments may result in service interruption
\r\n Need help? Contact support@[[company_name]].com or call [[company_phone]]

\r\n \r\n
\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n ", + "invoice_balance": "*[[company_name]]*\r\n[[address]]\r\n[[phone]]\r\n\r\n\r\nINVOICE: *[[invoice]]*\r\nDate : [[date]]\r\n[[payment_gateway]] [[payment_channel]]\r\n\r\n\r\nType : *[[type]]*\r\nPackage : *[[plan_name]]*\r\nPrice : *[[plan_price]]*\r\n\r\n====================\r\n[[footer]]", + "welcome_message": "Welcome aboard, [[name]]! \r\nWe're excited to have you as a new [[company]] customer. \r\nYour account is all set up and ready to go.\r\n\r\nHere's a quick overview:\r\n\r\nPortal: [[url]]\r\nYour login is [[Username]]\r\nYour temporary password is [[Password]] (please change this on your first login)\r\n\r\nNeed help? Reach out to our support team at anytime.\r\n\r\nWe're here to ensure you have an amazing experience with our services. Let us know how we can best support you.\r\n\r\nWelcome to the [[company]] family!" } diff --git a/ui/ui/admin/settings/notifications.tpl b/ui/ui/admin/settings/notifications.tpl index a1c9ce2e..10cc609f 100644 --- a/ui/ui/admin/settings/notifications.tpl +++ b/ui/ui/admin/settings/notifications.tpl @@ -210,7 +210,6 @@ [[company_name]] {Lang::T('Your Company Name at Settings')}.
[[company_address]] {Lang::T('Your Company Address at Settings')}.
[[company_phone]] - {Lang::T('Your Company Phone at Settings')}.
- [[company_url]] - {Lang::T('Your APP_URL at Settings')}.
[[invoice]] - {Lang::T('Invoice number')}.
[[created_at]] - {Lang::T('Date invoice created')}.
[[payment_gateway]] - {Lang::T('Payment gateway user paid from')}.
@@ -230,7 +229,7 @@ target="_blank">{Lang::T("read documentation")}.

- *} + *}