@babacar add the following code to helpers/functions.php
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.