Topic: INVOICE NUMBER - PREVENT CHANGE BY USER

I have posted this under another post but there is no reply so I transferred the topic to here....

There is a need to implement a control of the invoice number and we have to make the invoice number non-editable by the user when they enter a Direct Invoice or Invoice against a delivery.  We used the Form Setup to assign the first number and let the Invoice number incremental run automatically.

Currently, the Invoice screen will show the Invoice Number assigned by the Form Setup and the field allows user to edit.   This is because of the lines below in sales\customer_invoice.php:

if ($_SESSION['Items']->trans_no == 0) {
    ref_cells(_("Reference"), 'ref', '', null, "class='tableheader2'"); //Invoice Number assigned but editable
} else {
    label_cells(_("Reference"), $_SESSION['Items']->reference, "class='tableheader2'");
}



To make it non-editable, I have replaced the line ref_cells to label_cells as follows:

if ($_SESSION['Items']->trans_no == 0) {
    label_cells(_("Reference"), $_SESSION['Items']->reference, "class='tableheader2'");  //Invoice Number assigned and now not editable
} else {
    label_cells(_("Reference"), $_SESSION['Items']->reference, "class='tableheader2'");
}

With this change, now the Invoice number is assigned (by Form Setups) and not editable.  However, when I process the Invoice, the error "You must enter a reference." shows.  I know I missed out something but I don't know what else to change.  The Invoice Number showed is not assigned to the variable which in turn update the reference in the database tables.  This variable is empty.

Would you please advise what other codes I have to change so that the assigned Invoice number is picked up and update the reference in the Tables?

Thank you.

Mark

Re: INVOICE NUMBER - PREVENT CHANGE BY USER

You will need to make a hidden field with assigned value.

Re: INVOICE NUMBER - PREVENT CHANGE BY USER

Thanks APmuthu.   I need some help in getting the variable of the field. 

Based on this line:

ref_cells(_("Reference"), 'ref', '', null, "class='tableheader2'"); //Invoice Number assigned but editable

I thought the value is $_SESSION['Items']->reference.  But I struggled to figure out what should be the correct variable/value to assign to the field but I failed to make it work.  (I can't put $ref = $_SESSION['Items']->reference;)

I would appreciate it if you could advise how to assign that and it will help if you could give me some examples.

Thank you.

Re: INVOICE NUMBER - PREVENT CHANGE BY USER

Try a blank (or value: auto) hidden field for it.

Re: INVOICE NUMBER - PREVENT CHANGE BY USER

Thanks very much.
It works for me!

Re: INVOICE NUMBER - PREVENT CHANGE BY USER

Would you like to provide a diff or changed fileset to the project?

Re: INVOICE NUMBER - PREVENT CHANGE BY USER

Hi AP Muthu,

Sorry for the late reply.... and sure I'm happy to provide the change I made.

Actually it is just a small change to this file:  sales/customer_invoice.php:

At around line 400,  I commented this line:

ref_cells(_("Reference"), 'ref', '', null, "class='tableheader2'");

and replaced it with these 2 lines:

label_cells(_("Inv No:"), $_SESSION['Items']->reference, "class='tableheader2'");
hidden('ref', $_SESSION['Items']->reference);

That's all I did and now the Invoice number cannot be changed by user.

I'm not sure this is the best way to do but it achieved what I need.

8 (edited by apmuthu 09/20/2015 05:29:30 am)

Re: INVOICE NUMBER - PREVENT CHANGE BY USER

The same could have been achieved easily with a flag based readonly attribute in the input tag.

I have re-factored the includes/ui/ui_input.inc 's text_cells and text_cells_ex functions to have the same argument names and bunching similar code for ease of understanding before the inclusion of the $inparams in the latter function where the readonly can be inserted. This will also server to clarify the code.

The real solution will be to have a flag in the sys_prefs table that removes the field altogether and in the processing script acquires the next reference and then populates the tables, showing the end result in the browser.

Post's attachments

ui_input_cleanup.zip 34.4 kb, 6 downloads since 2015-09-20 

You don't have the permssions to download the attachments of this post.

Re: INVOICE NUMBER - PREVENT CHANGE BY USER

The before and after depiction of the code changes suggested for pass 1 of the function synch is attached herein.

Post's attachments

B4nAfter.zip 90.4 kb, 5 downloads since 2015-09-20 

You don't have the permssions to download the attachments of this post.

10 (edited by apmuthu 09/20/2015 04:12:15 pm)

Re: INVOICE NUMBER - PREVENT CHANGE BY USER

It is possible to make all Reference fields in new element forms to be readonly. The attached screenshots are for making just one form (Direct Invoice) or all forms to have their Reference field as non-editable.

Apart from being defined in includes/ui/ui_input.inc, there are 17 files that use the function ref_row - once each. The said function is currently not used in any standard extension.

Placed on Wiki.

Post's attachments

No_Edit_Reference.zip 113.3 kb, 8 downloads since 2015-09-20 

You don't have the permssions to download the attachments of this post.