2
0
forked from Wavyzz/dolibarr

Fix: Support for reset everymonth (@99 into numbering mask) was ko when

changing year.
This commit is contained in:
Laurent Destailleur
2014-01-20 11:20:38 +01:00
parent 3a246bdca9
commit 5b6b8f1d5b
2 changed files with 47 additions and 2 deletions

View File

@@ -629,7 +629,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
if ($maskraz > 0) // A reset is required if ($maskraz > 0) // A reset is required
{ {
if ($maskraz == 99) { if ($maskraz == 99) {
$maskraz = date('m'); $maskraz = date('m', $date);
$resetEveryMonth = true; $resetEveryMonth = true;
} }
if ($maskraz > 12) return 'ErrorBadMaskBadRazMonth'; if ($maskraz > 12) return 'ErrorBadMaskBadRazMonth';

View File

@@ -490,12 +490,57 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase
$localobject=new Facture($this->savdb); $localobject=new Facture($this->savdb);
$localobject->initAsSpecimen(); $localobject->initAsSpecimen();
$localobject->date=dol_mktime(12, 0, 0, 12, 1, 1971); // we use different discal year but same year $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1971); // we use different fiscal year but same year
$numbering=new mod_facture_mercure(); $numbering=new mod_facture_mercure();
$result=$numbering->getNextValue($mysoc, $localobject); $result=$numbering->getNextValue($mysoc, $localobject);
print __METHOD__." result=".$result."\n"; print __METHOD__." result=".$result."\n";
$this->assertEquals('197212-0001', $result); // counter must be reset to 1 $this->assertEquals('197212-0001', $result); // counter must be reset to 1
// Now we try with a reset every month (@99)
$conf->global->SOCIETE_FISCAL_MONTH_START=6;
$conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@99}';
$conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@99}';
$localobject=new Facture($this->savdb);
$localobject->initAsSpecimen();
$localobject->date=dol_mktime(12, 0, 0, 1, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year
$numbering=new mod_facture_mercure();
$result=$numbering->getNextValue($mysoc, $localobject);
$result2=$localobject->create($user,1);
$result3=$localobject->validate($user, $result);
print __METHOD__." result=".$result."\n";
$this->assertEquals('198001-0001', $result); // counter must start to 1
$localobject=new Facture($this->savdb);
$localobject->initAsSpecimen();
$localobject->date=dol_mktime(12, 0, 0, 1, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year
$numbering=new mod_facture_mercure();
$result=$numbering->getNextValue($mysoc, $localobject);
$result2=$localobject->create($user,1);
$result3=$localobject->validate($user, $result);
print __METHOD__." result=".$result."\n";
$this->assertEquals('198001-0002', $result); // counter must start to 2
$localobject=new Facture($this->savdb);
$localobject->initAsSpecimen();
$localobject->date=dol_mktime(12, 0, 0, 2, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year
$numbering=new mod_facture_mercure();
$result=$numbering->getNextValue($mysoc, $localobject);
$result2=$localobject->create($user,1);
$result3=$localobject->validate($user, $result);
print __METHOD__." result=".$result."\n";
$this->assertEquals('198002-0001', $result); // counter must start to 1
$localobject=new Facture($this->savdb);
$localobject->initAsSpecimen();
$localobject->date=dol_mktime(12, 0, 0, 1, 1, 1981); // we use year 1981 to be sure to not have existing invoice for this year
$numbering=new mod_facture_mercure();
$result=$numbering->getNextValue($mysoc, $localobject);
$result2=$localobject->create($user,1);
$result3=$localobject->validate($user, $result);
print __METHOD__." result=".$result."\n";
$this->assertEquals('198101-0001', $result); // counter must start to 1
return $result; return $result;
} }