Skip to main content
Topic: Invoice number format (Read 2023 times) previous topic - next topic

Invoice number format

Hi,
i'am developping an app with a part of invoice and invoice items. So i have a code developed 3 yers ago with another php framework to handle invoice number generation like this format : 00001-2020-04 (00001 the number supposed to be incremented and reseted every year - 2020: the year - 04: the month).
Where in PhpRAD i should paste the code so the invoice_number field to prefill when the form is opened ?

Thank you


Re: Invoice number format

Reply #2
Hi @willvin , here is the code
Code: [Select]
<?php 
   $ref = null;
 
if(date('Y') == date('Y',strtotime($inv_ref->date_facture)))
{
$temp = substr($inv_ref->id_facture,0,6);
$temp_ref = $temp + 1;
$ref = str_pad((int)$temp_ref,6,"0",STR_PAD_LEFT);
}else{
$init = 0;
$ref = str_pad((int)$init,6,"0",STR_PAD_LEFT);
$ref = date('Y',strtotime($inv_ref->date_facture)) + 1;
}
  ?>

Thanks

Re: Invoice number format

Reply #3
@babacar‍ add the following code to helpers/functions.php 
Code: [Select]
function refnum(){
$ref = null;
if(date('Y') == date('Y',strtotime($inv_ref->date_facture))){
$temp = substr($inv_ref->id_facture,0,6);
$temp_ref = $temp + 1;
$ref = str_pad((int)$temp_ref,6,"0",STR_PAD_LEFT);
}else{
$init = 0;
$ref = str_pad((int)$init,6,"0",STR_PAD_LEFT);
$ref = date('Y',strtotime($inv_ref->date_facture)) + 1;
}

Then you can call refnum() from page events.
 From the code I see, you can not add it to default value for the input as it requires data to process the new ref number. 
You would be able to add it to the DefaultValue of an input if it does not require extra data to process the ref num.

Re: Invoice number format

Reply #4
Hi @willvin - bThanks for your reply.
My worry about this is when PhpRAD gets a new updates, shall the code i added in the helpers won't be deleted ?

 

Re: Invoice number format

Reply #5
@babacar‍ when you publish to a new folder and if phprad gets an update that changes something on the file then the code will not be available to the project anymore, you have to keep the code where you can get it easily.