Skip to content

Commit

Permalink
New: Can add {tttt} in numbering modules
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Dec 7, 2009
1 parent fbce725 commit 0663b7c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion htdocs/includes/modules/facture/mercure/mercure.modules.php
Expand Up @@ -91,9 +91,12 @@ function getExample()
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)
{
Expand Down Expand Up @@ -127,7 +130,7 @@ function getNextValue($objsoc,$facture)
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;
}
Expand Down
22 changes: 21 additions & 1 deletion htdocs/lib/functions2.lib.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 0663b7c

Please sign in to comment.