Razva Posted September 8, 2017 Share Posted September 8, 2017 Is there any module that allows me to set a different invoice number for each payment method? For example BankTransfer should generate BT-1, PayPal should generate PP-1 etc. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 9, 2017 Share Posted September 9, 2017 Is there any module that allows me to set a different invoice number for each payment method? For example BankTransfer should generate BT-1, PayPal should generate PP-1 etc. none that springs to mind - I know that you can add some more tags with the Billing Extension addon, but payment method wouldn't be one of them. but you have to remember that effectively these tags are just values added to the invoicenum value in the database table... therefore, if you write a hook to update that value after the invoice has been created, but before it's been sent to the client, you will have achieved what you want. the hook below should get you closer to what you want... <?php /** * Generate Custom Invoice Number Format Based On Payment Method * @author brian! */ use Illuminate\Database\Capsule\Manager as Capsule; function generate_custom_invoice_number_hook($vars) { $invoiceid = $vars['invoiceid']; $paymentmethod = Capsule::table('tblinvoices') ->where('id',$invoiceid) ->value('paymentmethod'); if ($paymentmethod == 'paypal') { $customnumber = "PP-".$invoiceid; } elseif ($paymentmethod == 'banktransfer') { $customnumber = "BT-".$invoiceid; } if (isset($customnumber)) { try { $updatedInvoiceNumber = Capsule::table('tblinvoices') ->where('id', $invoiceid) ->update(['invoicenum' => $customnumber,]); } catch (\Exception $e) { // Deal with error } } } add_hook("InvoiceCreationPreEmail",1,"generate_custom_invoice_number_hook"); ?> so if invoice uses PayPal, it adds 'PP-{invoice number}' as the invoice number, 'BT' if Bank Transfer is used; if neither, it does nothing and it will just use the invoiceid value instead... obviously, just expand the if statement to add more payment methods. I did toy with querying the db to get a list of active payment methods, but unless you were using a LOT of gateways and had a simple way to abbreviate them all in the invoice numbers, I didn't think it would be worth it - it's quicker to just expand the if statement. btw - i'm assuming that you're going to use the invoiceID values and you don't want different invoices to use the same number, e.g the first Paypal invoice is PP-1 and the first BankTransfer invoice is BT-1 (and not BT-2 or whatever) ? if not, then you're going to need additional coding to ensure the save invoicenum isn't reused. 0 Quote Link to comment Share on other sites More sharing options...
Darius Posted July 24, 2018 Share Posted July 24, 2018 On 9/9/2017 at 6:43 PM, brian! said: none that springs to mind - I know that you can add some more tags with the Billing Extension addon, but payment method wouldn't be one of them. but you have to remember that effectively these tags are just values added to the invoicenum value in the database table... therefore, if you write a hook to update that value after the invoice has been created, but before it's been sent to the client, you will have achieved what you want. the hook below should get you closer to what you want... <?php /** * Generate Custom Invoice Number Format Based On Payment Method * @author brian! */ use Illuminate\Database\Capsule\Manager as Capsule; function generate_custom_invoice_number_hook($vars) { $invoiceid = $vars['invoiceid']; $paymentmethod = Capsule::table('tblinvoices') ->where('id',$invoiceid) ->value('paymentmethod'); if ($paymentmethod == 'paypal') { $customnumber = "PP-".$invoiceid; } elseif ($paymentmethod == 'banktransfer') { $customnumber = "BT-".$invoiceid; } if (isset($customnumber)) { try { $updatedInvoiceNumber = Capsule::table('tblinvoices') ->where('id', $invoiceid) ->update(['invoicenum' => $customnumber,]); } catch (\Exception $e) { // Deal with error } } } add_hook("InvoiceCreationPreEmail",1,"generate_custom_invoice_number_hook"); ?> Hello, Brian can you help me? I use 7,5 version whcms but invoice generate only with number. I am need normal invoice for clients example 201807241. This no working for me Available auto-insert tags are: {YEAR} {MONTH} {DAY} {NUMBER} only invoice have number. Please help with hooks? so if invoice uses PayPal, it adds 'PP-{invoice number}' as the invoice number, 'BT' if Bank Transfer is used; if neither, it does nothing and it will just use the invoiceid value instead... obviously, just expand the if statement to add more payment methods. I did toy with querying the db to get a list of active payment methods, but unless you were using a LOT of gateways and had a simple way to abbreviate them all in the invoice numbers, I didn't think it would be worth it - it's quicker to just expand the if statement. btw - i'm assuming that you're going to use the invoiceID values and you don't want different invoices to use the same number, e.g the first Paypal invoice is PP-1 and the first BankTransfer invoice is BT-1 (and not BT-2 or whatever) ? if not, then you're going to need additional coding to ensure the save invoicenum isn't reused. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 25, 2018 Share Posted July 25, 2018 19 hours ago, Darius said: Hello, Brian can you help me? I use 7,5 version whcms but invoice generate only with number. I am need normal invoice for clients example 201807241. This no working for me Available auto-insert tags are: {YEAR} {MONTH} {DAY} {NUMBER} only invoice have number. Please help with hooks? {YEAR} {MONTH} {DAY} {NUMBER} would only work if you enabled Sequential Invoicing. probably a better hook to modify for your needs would be the one I posted in the thread below... <?php /** * Generate Custom Invoice Number Format * @author brian! */ use Illuminate\Database\Capsule\Manager as Capsule; function generate_custom_invoice_number_hook($vars) { $invoiceid = $vars['invoiceid']; $customnumber = date("Y").date("m").date("d").$invoiceid; if (isset($customnumber)) { try { $updatedInvoiceNumber = Capsule::table('tblinvoices')->where('id', $invoiceid)->update(['invoicenum' => $customnumber,]); } catch (\Exception $e) { // Deal with error } } } add_hook("InvoiceCreationPreEmail",1,"generate_custom_invoice_number_hook"); ?> so for new invoices, it will use a format of (YEAR)(MONTH)(DATE)(INVOICE NUM) hardcoded by the hook. 0 Quote Link to comment Share on other sites More sharing options...
John Kennedy Posted January 17, 2019 Share Posted January 17, 2019 (edited) This doesn't seem to work in 7.6.1. /includes/hooks]# cat customInvoicePrefix.php <?php /** * Generate Custom Invoice Number Format * @author brian! */ use Illuminate\Database\Capsule\Manager as Capsule; function generate_custom_invoice_number_hook($vars) { $invoiceid = $vars['invoiceid']; $customnumber = "SI-".$invoiceid; if (isset($customnumber)) { try { $updatedInvoiceNumber = Capsule::table('tblinvoices') ->where('id', $invoiceid) ->update(['invoicenum' => $customnumber,]); } catch (\Exception $e) { // Deal with error } } } add_hook("InvoiceCreationPreEmail",1,"generate_custom_invoice_number_hook"); Tried several different variants. Edited January 17, 2019 by John Kennedy 0 Quote Link to comment Share on other sites More sharing options...
John Kennedy Posted January 17, 2019 Share Posted January 17, 2019 (edited) Works fine when done directly in the database: Edited January 17, 2019 by John Kennedy 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 17, 2019 Share Posted January 17, 2019 Hi John, there's something weird about how you've typed in $customnumber... if I re-encode the file to utf-8, that fixes the issue... <?php /** * Generate Custom Invoice Number Format * @author brian! */ use Illuminate\Database\Capsule\Manager as Capsule; function generate_custom_invoice_number_hook($vars) { $invoiceid = $vars['invoiceid']; $customnumber = "SI-".$invoiceid; if (isset($customnumber)) { try { $updatedInvoiceNumber = Capsule::table('tblinvoices') ->where('id', $invoiceid) ->update(['invoicenum' => $customnumber,]); } catch (\Exception $e) { // Deal with error } } } add_hook("InvoiceCreationPreEmail",1,"generate_custom_invoice_number_hook"); ?> the hook is working for me locally in v7.6.1... 0 Quote Link to comment Share on other sites More sharing options...
John Kennedy Posted January 17, 2019 Share Posted January 17, 2019 OK, this is bizarre - copied and pasted again, saved as UTF-8, uploaded into hooks. Still doesn't work. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 17, 2019 Share Posted January 17, 2019 Just now, John Kennedy said: OK, this is bizarre - copied and pasted again, saved as UTF-8, uploaded into hooks. Still doesn't work. manually type in the three $customnumber again - as long as all three are the same, it should work... 0 Quote Link to comment Share on other sites More sharing options...
John Kennedy Posted January 17, 2019 Share Posted January 17, 2019 (edited) Tried that before reuploading - didn't work. I'll try changing the var altogether to something else. Edit: nope. Edited January 17, 2019 by John Kennedy 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 17, 2019 Share Posted January 17, 2019 custom_invoice.php 0 Quote Link to comment Share on other sites More sharing options...
John Kennedy Posted January 17, 2019 Share Posted January 17, 2019 (edited) 4 minutes ago, brian! said: custom_invoice.php Lol no 😄 This is fucked up. All other hooks in that folder work fine Edited January 17, 2019 by John Kennedy 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 17, 2019 Share Posted January 17, 2019 this is what I see in my hook... and what I saw in yours... so it's checking that a variable is set - but it's seeing it as different from the one you're defining.... so the db update is never triggered. I suppose you could check if $invoiceid is empty instead... and I assume there are no other hooks that could be interfering with this ?? 0 Quote Link to comment Share on other sites More sharing options...
John Kennedy Posted January 17, 2019 Share Posted January 17, 2019 (edited) Guessing it's safe to assume something funky is going on with the encoding here. I've tried uploading/creating the file numerous times - either pasting or typing it out. The only thing I haven't tried yet is using the hosting platform editor to create the hook. Edited January 17, 2019 by John Kennedy 0 Quote Link to comment Share on other sites More sharing options...
John Kennedy Posted January 17, 2019 Share Posted January 17, 2019 This is also what I'm seeing after rewriting everything: Still doesn't work 😞 0 Quote Link to comment Share on other sites More sharing options...
John Kennedy Posted January 17, 2019 Share Posted January 17, 2019 OK, got it working, but now I got a new problem - I need the same to work for manual invoices after having them published. Sometimes we need to backdate invoices and the only way to do it is to create an invoice, publish it without sending, change the dates and only them email it. This hook doesn't work it you publish without sending it right away. Can it be changed to something like "InvoiceCreationPostCreate"? What will it break if it can? 0 Quote Link to comment Share on other sites More sharing options...
John Kennedy Posted January 18, 2019 Share Posted January 18, 2019 (edited) 14 hours ago, John Kennedy said: Can it be changed to something like "InvoiceCreationPostCreate"? What will it break if it can? Anyone looking to do the same: update the last call to "InvoiceCreation" add_hook("InvoiceCreation",1,"generate_custom_invoice_number_hook"); @brian! Thanks for all the help! You're a legend. Edited January 18, 2019 by John Kennedy To say thank you 0 Quote Link to comment Share on other sites More sharing options...
Sonu2007 Posted December 23, 2020 Share Posted December 23, 2020 On 9/9/2017 at 9:13 PM, brian! said: none that springs to mind - I know that you can add some more tags with the Billing Extension addon, but payment method wouldn't be one of them. but you have to remember that effectively these tags are just values added to the invoicenum value in the database table... therefore, if you write a hook to update that value after the invoice has been created, but before it's been sent to the client, you will have achieved what you want. the hook below should get you closer to what you want... <?php /** * Generate Custom Invoice Number Format Based On Payment Method * @author brian! */ use Illuminate\Database\Capsule\Manager as Capsule; function generate_custom_invoice_number_hook($vars) { $invoiceid = $vars['invoiceid']; $paymentmethod = Capsule::table('tblinvoices') ->where('id',$invoiceid) ->value('paymentmethod'); if ($paymentmethod == 'paypal') { $customnumber = "PP-".$invoiceid; } elseif ($paymentmethod == 'banktransfer') { $customnumber = "BT-".$invoiceid; } if (isset($customnumber)) { try { $updatedInvoiceNumber = Capsule::table('tblinvoices') ->where('id', $invoiceid) ->update(['invoicenum' => $customnumber,]); } catch (\Exception $e) { // Deal with error } } } add_hook("InvoiceCreationPreEmail",1,"generate_custom_invoice_number_hook"); ?> so if invoice uses PayPal, it adds 'PP-{invoice number}' as the invoice number, 'BT' if Bank Transfer is used; if neither, it does nothing and it will just use the invoiceid value instead... obviously, just expand the if statement to add more payment methods. I did toy with querying the db to get a list of active payment methods, but unless you were using a LOT of gateways and had a simple way to abbreviate them all in the invoice numbers, I didn't think it would be worth it - it's quicker to just expand the if statement. btw - i'm assuming that you're going to use the invoiceID values and you don't want different invoices to use the same number, e.g the first Paypal invoice is PP-1 and the first BankTransfer invoice is BT-1 (and not BT-2 or whatever) ? if not, then you're going to need additional coding to ensure the save invoicenum isn't reused. How to achieve this if i want different invoices to use the same number EX: PP-1 and BT-1. I just want to display such format on invoice not in DB update 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted December 23, 2020 Share Posted December 23, 2020 1 hour ago, Prahost said: How to achieve this if i want different invoices to use the same number EX: PP-1 and BT-1. you would have to check the last number used for that gateway option and add 1 to it. 1 hour ago, Prahost said: I just want to display such format on invoice not in DB update it's the db update that saves you having to modify the template outputs... if you're not updating the db, then you're going to have to do more work to display this change. 0 Quote Link to comment Share on other sites More sharing options...
Sonu2007 Posted December 23, 2020 Share Posted December 23, 2020 23 minutes ago, brian! said: you would have to check the last number used for that gateway option and add 1 to it. Where I have to change in code for this? 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.