Refactor invoice handling to use 'invoice' key and improve payment link generation

Still in development
This commit is contained in:
Focuslinkstech 2025-03-18 16:51:37 +01:00
parent 1a2b85ae4f
commit cdfbab7119
3 changed files with 32 additions and 26 deletions

View File

@ -7,7 +7,7 @@ class Invoice
public static function generateInvoice($invoiceData) public static function generateInvoice($invoiceData)
{ {
try { try {
if (empty($invoiceData['id'])) { if (empty($invoiceData['invoice'])) {
throw new Exception("Invoice ID is required"); throw new Exception("Invoice ID is required");
} }
@ -45,7 +45,7 @@ class Invoice
$mpdf->WriteHTML($processedHtml); $mpdf->WriteHTML($processedHtml);
// Save PDF // Save PDF
$filename = "invoice_{$invoiceData['id']}.pdf"; $filename = "invoice_{$invoiceData['invoice']}.pdf";
$outputPath = "system/uploads/invoices/{$filename}"; $outputPath = "system/uploads/invoices/{$filename}";
$mpdf->Output($outputPath, 'F'); $mpdf->Output($outputPath, 'F');
@ -88,9 +88,9 @@ class Invoice
}, $template); }, $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'])) { if (empty($config['currency_code'])) {
$config['currency_code'] = '$'; $config['currency_code'] = '$';
@ -142,19 +142,28 @@ class Invoice
$tax = $config['enable_tax'] ? Package::tax($subtotal) : 0; $tax = $config['enable_tax'] ? Package::tax($subtotal) : 0;
$total = ($tax > 0) ? $subtotal + $tax : $subtotal + $tax; $total = ($tax > 0) ? $subtotal + $tax : $subtotal + $tax;
$token = User::generateToken($account['id'], 1); $token = User::generateToken($account->id, 1);
if (!empty($token['token'])) { if (!empty($token['token'])) {
$tur = ORM::for_table('tbl_user_recharges') $tur = ORM::for_table('tbl_user_recharges')
->where('customer_id', $account['id']) ->where('customer_id', $account->id)
->where('namebp', $package) ->where('namebp', $invoice->plan_name);
->find_one();
if ($tur) { switch ($status) {
$payLink = '?_route=home&recharge=' . $tur['id'] . '&uid=' . urlencode($token['token']); 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 { } else {
$payLink = '?_route=home'; $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 = [ $invoiceData = [
'invoice' => "INV-" . Package::_raid(), 'invoice' => "INV-" . Package::_raid(),
'fullname' => $account->fullname, 'fullname' => $account->fullname,
@ -169,9 +178,8 @@ class Invoice
'company_address' => $config['address'], 'company_address' => $config['address'],
'company_name' => $config['CompanyName'], 'company_name' => $config['CompanyName'],
'company_phone' => $config['phone'], 'company_phone' => $config['phone'],
'logo' => $config['logo'], 'logo' => $logo,
'company_url' => APP_URL, 'payment_link' => $payLink
'payment_link' => $payLink,
]; ];
if (!isset($invoiceData['bill_rows']) || empty($invoiceData['bill_rows'])) { if (!isset($invoiceData['bill_rows']) || empty($invoiceData['bill_rows'])) {

File diff suppressed because one or more lines are too long

View File

@ -210,7 +210,6 @@
<b>[[company_name]]</b> {Lang::T('Your Company Name at Settings')}.<br> <b>[[company_name]]</b> {Lang::T('Your Company Name at Settings')}.<br>
<b>[[company_address]]</b> {Lang::T('Your Company Address at Settings')}.<br> <b>[[company_address]]</b> {Lang::T('Your Company Address at Settings')}.<br>
<b>[[company_phone]]</b> - {Lang::T('Your Company Phone at Settings')}.<br> <b>[[company_phone]]</b> - {Lang::T('Your Company Phone at Settings')}.<br>
<b>[[company_url]]</b> - {Lang::T('Your APP_URL at Settings')}.<br>
<b>[[invoice]]</b> - {Lang::T('Invoice number')}.<br> <b>[[invoice]]</b> - {Lang::T('Invoice number')}.<br>
<b>[[created_at]]</b> - {Lang::T('Date invoice created')}.<br> <b>[[created_at]]</b> - {Lang::T('Date invoice created')}.<br>
<b>[[payment_gateway]]</b> - {Lang::T('Payment gateway user paid from')}.<br> <b>[[payment_gateway]]</b> - {Lang::T('Payment gateway user paid from')}.<br>
@ -230,7 +229,7 @@
target="_blank">{Lang::T("read documentation")}</a>. target="_blank">{Lang::T("read documentation")}</a>.
</p> </p>
</div> </div>
</div>*} </div> *}
<div class="panel-body"> <div class="panel-body">
<div class="form-group"> <div class="form-group">