New: Can add {tttt} in numbering modules

This commit is contained in:
Laurent Destailleur 2009-12-07 17:27:09 +00:00
parent fbce725fff
commit 0663b7cbd8
3 changed files with 27 additions and 2 deletions

View File

@ -7,6 +7,8 @@ For users:
- New: Can filter on user on stock movement list
- New: When creating a third party from a member, it is set as a new
customer.
- New: Can use {tttt} in numbering mask setup. It will be replaced
with third party type.
- Fix: bug #28055 : Unable to modify the date of a cloned command
- Fix: bug #27891

View File

@ -91,9 +91,12 @@ class mod_facture_mercure extends ModeleNumRefFactures
global $conf,$langs,$mysoc;
$old_code_client=$mysoc->code_client;
$old_code_type=$mysoc->typent_code;
$mysoc->code_client='CCCCCCCCCC';
$mysoc->typent_code='TTTTTTTTTT';
$numExample = $this->getNextValue($mysoc,'');
$mysoc->code_client=$old_code_client;
$mysoc->typent_code=$old_code_type;
if (! $numExample)
{
@ -127,7 +130,7 @@ class mod_facture_mercure extends ModeleNumRefFactures
if ($facture->type == 2) $where.= " AND type = 2";
else $where.=" AND type != 2";
$numFinal=get_next_value($db,$mask,'facture','facnumber',$where,$objsoc->code_client,$facture->date);
$numFinal=get_next_value($db,$mask,'facture','facnumber',$where,$objsoc,$facture->date);
return $numFinal;
}

View File

@ -382,17 +382,27 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='')
$maskrefclient_maskclientcode=$regClientRef[1];
$maskrefclient_maskcounter=$regClientRef[2];
$maskrefclient_maskoffset=0; //default value of maskrefclient_counter offset
$maskrefclient_clientcode=substr($valueforccc,0,strlen($maskrefclient_maskclientcode));//get n first characters of client code to form maskrefclient_clientcode
$maskrefclient_clientcode=substr($valueforccc,0,strlen($maskrefclient_maskclientcode));//get n first characters of client code where n is length in mask
$maskrefclient_clientcode=str_pad($maskrefclient_clientcode,strlen($maskrefclient_maskclientcode),"#",STR_PAD_RIGHT);//padding maskrefclient_clientcode for having exactly n characters in maskrefclient_clientcode
$maskrefclient_clientcode=dol_string_nospecial($maskrefclient_clientcode);//sanitize maskrefclient_clientcode for sql insert and sql select like
if (strlen($maskrefclient_maskcounter) > 0 && strlen($maskrefclient_maskcounter) < 3) return 'CounterMustHaveMoreThan3Digits';
}
else $maskrefclient='';
// Extract value for third party type
if (preg_match('/\{(t+)\}/i',$mask,$regType))
{
$masktype=$regType[1];
$masktype_value=substr(preg_replace('/^TE_/','',$objsoc->typent_code),0,strlen($regType[1]));//get n first characters of client code where n is length in mask
$masktype_value=str_pad($masktype_value,strlen($regType[1]),"#",STR_PAD_RIGHT);
}
else $masktype='';
$maskwithonlyymcode=$mask;
$maskwithonlyymcode=preg_replace('/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i',$maskcounter,$maskwithonlyymcode);
$maskwithonlyymcode=preg_replace('/\{dd\}/i','dd',$maskwithonlyymcode);
$maskwithonlyymcode=preg_replace('/\{(c+)(0*)\}/i',$maskrefclient,$maskwithonlyymcode);
$maskwithonlyymcode=preg_replace('/\{(t+)\}/i',$masktype_value,$maskwithonlyymcode);
$maskwithnocode=$maskwithonlyymcode;
$maskwithnocode=preg_replace('/\{yyyy\}/i','yyyy',$maskwithnocode);
$maskwithnocode=preg_replace('/\{yy\}/i','yy',$maskwithnocode);
@ -460,6 +470,8 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='')
$maskLike = str_replace(dol_string_nospecial('{dd}'),'__',$maskLike);
$maskLike = str_replace(dol_string_nospecial('{'.$masktri.'}'),str_pad("",strlen($maskcounter),"_"),$maskLike);
if ($maskrefclient) $maskLike = str_replace(dol_string_nospecial('{'.$maskrefclient.'}'),str_pad("",strlen($maskrefclient),"_"),$maskLike);
//if ($masktype) $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),str_pad("",strlen($masktype),"_"),$maskLike);
if ($masktype) $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),$masktype_value,$maskLike);
// Get counter in database
$counter=0;
@ -554,6 +566,14 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='')
$numFinal = str_replace($maskrefclient_maskbefore,$maskrefclient_maskafter,$numFinal);
}
// Now we replace the type
if ($masktype)
{
$masktype_maskbefore='{'.$masktype.'}';
$masktype_maskafter=$masktype_value;
$numFinal = str_replace($masktype_maskbefore,$masktype_maskafter,$numFinal);
}
dol_syslog("functions2::get_next_value return ".$numFinal,LOG_DEBUG);
return $numFinal;
}