Eugene Posted February 26 Share Posted February 26 Hello, Can I somehow segregate invoice prefixes and/or Pay-to-text based on the payment method selected by the client? For example All PayPal paid invoices should come up like PP/123 PP/124 PP/125.. and so on, with Pay To text "Paid to Company 1" All other invoices paid using another payment method should come up like "INV/123 iNV/124 INV/125 and so on, with "Pay To" text "Paid to Company 2" 0 Quote Link to comment Share on other sites More sharing options...
Saroha Posted February 27 Share Posted February 27 Eugene, for this, you need to modify the Invoice number generation code. But you can't do this in WHMCS because WHMCS code is encoded and no hooks for this. You can do this by creating a custom hook before this disable auto sequence invoice number from Setup -> General Settings and in Setup->Tax Configuration. Then in the custom hook use the WHMCS InvoicePaid hook. this hook is called when an invoice is marked paid. in this hook, you have the invoice ID which is just marked paid. Here follow these step First, fetch the invoice information by using GetInvoice WHMCS API. From this API you receive all information about this invoice including payment method. Now you have a payment method. Save it in a variable as $paymethod. Now get the last paid invoice with the same method as the code below $stmtx = Capsule::table('tblinvoices')->where('paymentmethod',$paymethod)->where('id','!=',$invoiceid)->orderBy('datepaid', 'desc')->first(); here you got the last paid invoice with the same payment method. generate the next invoice number by adding 1 to your last paid invoice number. for example as per your format INV/125 Note: maybe you not receive any invoice details only in case you do not have any paid invoice with this payment method. So we cover both scenarios in the below code if($stmtx){ $last_inv_num = $stmtx->invoicenum; $inv_parts = explode('/',$last_inv_num); $increase_one = $inv_parts[1] + 1; $next_invoice_number = $inv_parts[0]."/".$increase_one; }else{ $inv_format_array = array("paypal"=>"Pay","Debit_Card"=>"INV"); $next_invoice_number = $inv_format_array[$paymethod].'/1'; //it gernerate invoice number as per paymentmethod like INV/1 } Now Update invoice number to invoice ID like Capsule::table('tblinvoices')->where('id',$invoiceid)->update(array('invoicenum'=>$next_invoice_number)); save your hook file in your WHMCS install directory->includes->hooks that it. all set Note: we do not recommend that you generate two different invoice number sequences. 0 Quote Link to comment Share on other sites More sharing options...
Eugene Posted February 28 Author Share Posted February 28 (edited) On 2/27/2024 at 8:19 AM, Saroha said: Note: we do not recommend that you generate two different invoice number sequences. Any specific reason why? WHMCS itself has the option to format the invoice numbers but not two different ones. Is it going to create problems in the database somewhere? Is it because of a compatibility issue? Edited February 28 by Eugene typo correction 0 Quote Link to comment Share on other sites More sharing options...
Saroha Posted February 29 Share Posted February 29 WHMCS has the option to format the invoice number because every user wants a different format option. but it does not give two different sequence options because it's a different requirement. I think you are the first who demands this. if you do this with your custom hooks I did not create any problem in the database because WHMCS works on InvoiceID and has no compatibility issue we just recommend it only in case of server slowness or case two invoices are raised at the same time with the same payment method then maybe you have a duplicate invoice number. But the chance of this is only 0.001%. but make sure auto sequencing should be disabled. Out of this topic but important for you : I checked your website I found that you using our SEO SMO Manager modules but you have not updated it with its latest version 4.1 autopilot. You have a valid support addon means you can free update it. Please download the latest version and enjoy its autopilot SEO for WHMCS product pages and Knowledgebase bases with schema markup. 0 Quote Link to comment Share on other sites More sharing options...
twhiting9275 Posted March 1 Share Posted March 1 Before you consider doing this, please make sure you understand the legalities in your area. As you're trying to modify an existing (paid) invoice, this may not exactly be legal in your area. 0 Quote Link to comment Share on other sites More sharing options...
Eugene Posted March 1 Author Share Posted March 1 1 hour ago, twhiting9275 said: Before you consider doing this, please make sure you understand the legalities in your area. As you're trying to modify an existing (paid) invoice, this may not exactly be legal in your area. I'm not modifying existing invoices. The new ones going forward 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.