i try to generate file and update a field directly from a controllerfile for getting a automated invoicenumbering.
The file is perfect generated but the increment and updating is not correct.
//Invoice Number generation and save
$invoiceNrFile = 'content/validation-registration/invoice-number/invoicenr.en.txt';
$invoiceNrContent = array('title' => 'Aktuelle Rechnungsnummer', 'invoicenumber' => '0000');
$invoiceNr = $invoiceNrContent['invoicenumber'];
$newInvoicePage = page('validation-registration')->children()->create('invoice-number', 'invoicenr', $invoiceNrContent);
$invoiceNr = page('validation-registration/invoice-number')->increment('invoicenumber', 1);
$newInvoiceNr = page('validation-registration/invoice-number')->update(array('invoicenumber' => $invoiceNr), 'en');
With this I get a value
validation-registration/invoice-numberas new invoicenumber. What do I 'm wrong?
I’ve never used
increment() by myself, but I think you don’t need to update the page afterwards. Have you tried to simply use
If you need the new
invoicennumber afterwards, you should get it as usual …
$newInvoiceNr = page('validation-registration/invoice-number')->invoicenumber();
What is your default language? If English is the non-default language, your
increment() function will only work in the default language, see this post for a solution: $page->increment($field) in multilang environment
english is my default language. But your method works fine but not with left-hand zeros.
0000will increment to
1and not to
Exist for this also a method solution?
No, but why do you need this? You can add leading zeros in your template. This is just a formatting thing, I don’t think it is required to actually save those numbers in the file.
I use this number for invoices. But yes I can add the zeros later.