Wilfredcy Posted August 7, 2015 Share Posted August 7, 2015 (edited) Hello, how can I put date inside invoice number? for example the invoice number #IN201508030001(Invoice prefix + date + invoice number), Edited August 7, 2015 by bananaguy (see edit history) Link to comment Share on other sites More sharing options...
Simone Salerno Posted August 8, 2015 Share Posted August 8, 2015 (edited) You have to override classes/order/OrderInvoice.php with the following: public function getInvoiceNumberFormatted($id_lang, $id_shop = null) { return sprintf('%s%d%6d', Configuration::get('PS_INVOICE_PREFIX', $id_lang, null, $id_shop), date('Ymd', $this->order->invoice_date), $this->number); } Edited August 8, 2015 by SimoneS93 (see edit history) 1 Link to comment Share on other sites More sharing options...
Neekkola Posted September 21, 2015 Share Posted September 21, 2015 You have to override classes/order/OrderInvoice.php with the following: public function getInvoiceNumberFormatted($id_lang, $id_shop = null) { return sprintf('%s%d%6d', Configuration::get('PS_INVOICE_PREFIX', $id_lang, null, $id_shop), date('Ymd', $this->order->invoice_date), $this->number); } Hello I did it but I have this message error : "Trying to get property of non-object" Can you help us, please ? Link to comment Share on other sites More sharing options...
Simone Salerno Posted September 23, 2015 Share Posted September 23, 2015 public function getInvoiceNumberFormatted($id_lang, $id_shop = null) { return sprintf('%s%d%6d', Configuration::get('PS_INVOICE_PREFIX', $id_lang, null, $id_shop), date('Ymd', $this->date_add), $this->number); } Link to comment Share on other sites More sharing options...
Neekkola Posted September 27, 2015 Share Posted September 27, 2015 public function getInvoiceNumberFormatted($id_lang, $id_shop = null) { return sprintf('%s%d%6d', Configuration::get('PS_INVOICE_PREFIX', $id_lang, null, $id_shop), date('Ymd', $this->date_add), $this->number); } Hello SimoneS93 and thank you for you reply : I tried it ... but it doesn't work unfortunatelly. I have now this error message : "A non well formed numeric value encountered" so I'm always looking for a solution for having invoice number (invoice reference) like this : [prefix]+year+month+[fixed text]+invoice number. exemple : INV1509SALE00001 Link to comment Share on other sites More sharing options...
Simone Salerno Posted September 28, 2015 Share Posted September 28, 2015 (edited) public function getInvoiceNumberFormatted($id_lang, $id_shop = null) { //first %s is for prefix //second %s is for Y (year) + m(month) //then your text (you can include spaces if you need) //%d is for invoice number return sprintf('%s%sYOUR-FIXED-TEXT-HERE%6d', Configuration::get('PS_INVOICE_PREFIX', $id_lang, null, $id_shop), date('Ym', $this->date_add), $this->number); } Edited September 28, 2015 by SimoneS93 (see edit history) Link to comment Share on other sites More sharing options...
eleazar Posted September 28, 2015 Share Posted September 28, 2015 (edited) Just for the record: I don't think it makes sense to resort to an elder function from PrestaShop 1.5. With 1.6.1.2 you can easily compose the invoice number from the Back Office just by using the new options without any core changes. Edited September 28, 2015 by eleazar (see edit history) Link to comment Share on other sites More sharing options...
Simone Salerno Posted September 29, 2015 Share Posted September 29, 2015 1.6.1.2? I think you're the only one using the bleeding edge version... I'm on 1.6.0.5 and there's no such an option. Link to comment Share on other sites More sharing options...
Neekkola Posted September 29, 2015 Share Posted September 29, 2015 hello Eleazar, I'm on 1.6.1.0 and there's no such an option. 1.6.1.1 is the latest official version available. 1.6.1.2 is the latest development version. However, my accounting department requires invoice number with year ... and month, that seems not available option to compose invoice number even with 1.6.1.2 development version. SimoneS93 Thank you for you reply. I overrided classes/order/OrderInvoice.php with you last code and result invoice number like this : INV%y%m197001SALE001 Almost done... but always trouble with date Link to comment Share on other sites More sharing options...
eleazar Posted September 29, 2015 Share Posted September 29, 2015 I'm well aware that 1.6.1.2 is currently just a beta, but in some weeks this is standard. That's why I pointed out that I see no reason for overrides which are waste shortly after. However, I understand why this is urgent for you. The reason why the above solution doesn't work is simply that you cannot extract a date from a MySQL timestamp without converting it prior to that. Instead of date('Ym', $this->date_add) it should be date('Ym', strtotime($this->date_add)) That's all! Link to comment Share on other sites More sharing options...
Neekkola Posted October 1, 2015 Share Posted October 1, 2015 HelloThanks very much Eleazar ! your code is working !Thank you to SimoneS93 for your replies.I also changed the generation of pdf invoice filename in order to be the same as the invoice reference.I modified the file classes/pdf/HTMLTemplateInvoice.php. I inserted at the line 492 : date('ym', strtotime($this->order->invoice_date)) I don't know if it is the better way but now invoice reference and pdf filename are identical. Link to comment Share on other sites More sharing options...
eleazar Posted October 1, 2015 Share Posted October 1, 2015 I also changed the generation of pdf invoice filename in order to be the same as the invoice reference. I modified the file classes/pdf/HTMLTemplateInvoice.php. I inserted at the line 492 : date('ym', strtotime($this->order->invoice_date)) I don't know if it is the better way but now invoice reference and pdf filename are identical. Ah yes, I should have told you! This is required up to 1.6.1.1 for a correct display in the invoice too. From PrestaShop 1.6.1.2 on there's no need to change HTMLTemplateInvoice.php any more. You just have to modify line 859 in function getInvoiceNumberFormatted of classes/order/OrderInvoice.php: return sprintf($format, Configuration::get('PS_INVOICE_PREFIX', (int)$id_lang, null, (int)$id_shop), $this->number, date('Y', strtotime($this->date_add))); by changing $this->number, date('Y', strtotime($this->date_add) to $this->number, date('Ym', strtotime($this->date_add) Btw, you are aware that there is a difference between 'y' (2 decimals) and 'Y' (4 decimals)? Link to comment Share on other sites More sharing options...
Neekkola Posted October 5, 2015 Share Posted October 5, 2015 Thank you for you help Eleazar ... and yes I need a 2 decimals format (y)... as reclaimed by my accounting departement Link to comment Share on other sites More sharing options...
taydotech123 Posted October 5, 2015 Share Posted October 5, 2015 you should override it, do not modify core of prestashop. it is not GOOD ! Link to comment Share on other sites More sharing options...
eleazar Posted October 5, 2015 Share Posted October 5, 2015 you should override it, do not modify core of prestashop. it is not GOOD ! Just for the record: We were solely talking about overrides. So save your obtrusive advertising posts for your module. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now