Jump to content

Modify Invoice number


Wilfredcy

Recommended Posts

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 by SimoneS93 (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 1 month later...

 

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

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


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 by SimoneS93 (see edit history)
Link to comment
Share on other sites

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

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

Hello

Thanks 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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...