';
if($object->listmeths[$i]['active'] == 0)
{
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 272e2d313b5..f36ddc88a1d 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -1611,7 +1611,7 @@ class Facture extends CommonInvoice
$now=dol_now();
$error=0;
- dol_syslog(get_class($this).'::validate user='.$user->id.', force_number='.$force_number.', idwarehouse='.$idwarehouse, LOG_WARNING);
+ dol_syslog(get_class($this).'::validate user='.$user->id.', force_number='.$force_number.', idwarehouse='.$idwarehouse);
// Check parameters
if (! $this->brouillon)
@@ -2611,11 +2611,10 @@ class Facture extends CommonInvoice
{
$maxfacnumber = $this->getNextNumRef($this->client,'last');
$ventilExportCompta = $this->getVentilExportCompta();
- // Si derniere facture et si non ventilee, on peut supprimer
- if ($maxfacnumber == $this->ref && $ventilExportCompta == 0)
- {
- return 1;
- }
+ // If there is no invoice into the reset range and not already dispatched, we can delete
+ if ($maxfacnumber == '' && $ventilExportCompta == 0) return 1;
+ // If invoice to delete is last one and not already dispatched, we can delete
+ if ($maxfacnumber == $this->ref && $ventilExportCompta == 0) return 1;
}
else if ($this->statut == 0 && $facref == 'PROV') // Si facture brouillon et provisoire
{
diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php
index fb51b62809e..059400d7399 100644
--- a/htdocs/core/lib/functions2.lib.php
+++ b/htdocs/core/lib/functions2.lib.php
@@ -506,7 +506,7 @@ function array2table($data,$tableMarkup=1,$tableoptions='',$troptions='',$tdopti
}
/**
- * Return next value for a mask
+ * Return last or next value for a mask (according to area we should not reset)
*
* @param DoliDB $db Database handler
* @param string $mask Mask to use
@@ -688,7 +688,6 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
$posnumstart=strpos($maskwithnocode,$maskcounter); // Pos of counter in final string (from 0 to ...)
if ($posnumstart < 0) return 'ErrorBadMaskFailedToLocatePosOfSequence';
$sqlstring='SUBSTRING('.$field.', '.($posnumstart+1).', '.dol_strlen($maskcounter).')';
- //print "x".$sqlstring;
// Define $maskLike
$maskLike = dol_string_nospecial($mask);
@@ -701,7 +700,6 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
$maskLike = preg_replace('/\{dd\}/i','__',$maskLike);
$maskLike = str_replace(dol_string_nospecial('{'.$masktri.'}'),str_pad("",dol_strlen($maskcounter),"_"),$maskLike);
if ($maskrefclient) $maskLike = str_replace(dol_string_nospecial('{'.$maskrefclient.'}'),str_pad("",dol_strlen($maskrefclient),"_"),$maskLike);
- //if ($masktype) $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),str_pad("",dol_strlen($masktype),"_"),$maskLike);
if ($masktype) $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),$masktype_value,$maskLike);
// Get counter in database
@@ -715,7 +713,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
if ($sqlwhere) $sql.=' AND '.$sqlwhere;
//print $sql.' ';
- dol_syslog("functions2::get_next_value sql=".$sql, LOG_DEBUG);
+ dol_syslog("functions2::get_next_value mode=".$mode." sql=".$sql, LOG_DEBUG);
$resql=$db->query($sql);
if ($resql)
{
@@ -725,30 +723,32 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
else dol_print_error($db);
if (empty($counter) || preg_match('/[^0-9]/i',$counter)) $counter=$maskoffset;
- if ($mode == 'last')
+ if ($mode == 'last') // We found value for counter = last counter value. Now need to get corresponding ref of invoice.
{
$counterpadded=str_pad($counter,dol_strlen($maskcounter),"0",STR_PAD_LEFT);
- // Define $maskLike
- $maskLike = dol_string_nospecial($mask);
- $maskLike = str_replace("%","_",$maskLike);
- // Replace protected special codes with matching number of _ as wild card caracter
- $maskLike = preg_replace('/\{yyyy\}/i','____',$maskLike);
- $maskLike = preg_replace('/\{yy\}/i','__',$maskLike);
- $maskLike = preg_replace('/\{y\}/i','_',$maskLike);
- $maskLike = preg_replace('/\{mm\}/i','__',$maskLike);
- $maskLike = preg_replace('/\{dd\}/i','__',$maskLike);
- $maskLike = str_replace(dol_string_nospecial('{'.$masktri.'}'),$counterpadded,$maskLike);
- if ($maskrefclient) $maskLike = str_replace(dol_string_nospecial('{'.$maskrefclient.'}'),str_pad("",dol_strlen($maskrefclient),"_"),$maskLike);
- //if ($masktype) $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),str_pad("",dol_strlen($masktype),"_"),$maskLike);
- if ($masktype) $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),$masktype_value,$maskLike);
-
+ // Define $maskLike
+ $maskLike = dol_string_nospecial($mask);
+ $maskLike = str_replace("%","_",$maskLike);
+ // Replace protected special codes with matching number of _ as wild card caracter
+ $maskLike = preg_replace('/\{yyyy\}/i','____',$maskLike);
+ $maskLike = preg_replace('/\{yy\}/i','__',$maskLike);
+ $maskLike = preg_replace('/\{y\}/i','_',$maskLike);
+ $maskLike = preg_replace('/\{mm\}/i','__',$maskLike);
+ $maskLike = preg_replace('/\{dd\}/i','__',$maskLike);
+ $maskLike = str_replace(dol_string_nospecial('{'.$masktri.'}'),$counterpadded,$maskLike);
+ if ($maskrefclient) $maskLike = str_replace(dol_string_nospecial('{'.$maskrefclient.'}'),str_pad("",dol_strlen($maskrefclient),"_"),$maskLike);
+ if ($masktype) $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),$masktype_value,$maskLike);
+
$ref='';
- $sql = "SELECT facnumber as ref";
- $sql.= " FROM ".MAIN_DB_PREFIX."facture";
- $sql.= " WHERE facnumber LIKE '".$maskLike."'";
+ $sql = "SELECT ".$field." as ref";
+ $sql.= " FROM ".MAIN_DB_PREFIX.$table;
+ $sql.= " WHERE ".$field." LIKE '".$maskLike."'";
+ $sql.= " AND ".$field." NOT LIKE '%PROV%'";
$sql.= " AND entity IN (".getEntity($table, 1).")";
-
+ if ($where) $sql.=$where;
+ if ($sqlwhere) $sql.=' AND '.$sqlwhere;
+
dol_syslog("functions2::get_next_value sql=".$sql);
$resql=$db->query($sql);
if ($resql)
diff --git a/htdocs/install/mysql/migration/3.3.0-3.4.0.sql b/htdocs/install/mysql/migration/3.3.0-3.4.0.sql
index 479874a441f..e8c1da2aa4f 100755
--- a/htdocs/install/mysql/migration/3.3.0-3.4.0.sql
+++ b/htdocs/install/mysql/migration/3.3.0-3.4.0.sql
@@ -110,6 +110,14 @@ ALTER TABLE llx_c_shipment_mode ADD COLUMN tracking VARCHAR(256) NOT NULL DEFAUL
-- VMYSQL4.3 ALTER TABLE llx_c_shipment_mode CHANGE COLUMN rowid rowid INTEGER NOT NULL AUTO_INCREMENT;
-- VPGSQL8.2 DROP table llx_c_shipment_mode;
-- VPGSQL8.2 CREATE TABLE llx_c_shipment_mode (rowid SERIAL PRIMARY KEY, tms timestamp, code varchar(30) NOT NULL, libelle varchar(50) NOT NULL, description text, tracking varchar(256) NOT NULL, active integer DEFAULT 0, module varchar(32) NULL);
+-- VPGSQL8.2 INSERT INTO llx_c_shipment_mode (rowid,code,libelle,description,tracking,active) VALUES (1,'CATCH','Catch','Catch by client','',1);
+-- VPGSQL8.2 INSERT INTO llx_c_shipment_mode (rowid,code,libelle,description,tracking,active) VALUES (2,'TRANS','Transporter','Generic transporter','',1);
+-- VPGSQL8.2 INSERT INTO llx_c_shipment_mode (rowid,code,libelle,description,tracking,active) VALUES (3,'COLSUI','Colissimo Suivi','Colissimo Suivi','',0);
+-- VPGSQL8.2 INSERT INTO llx_c_shipment_mode (rowid,code,libelle,description,tracking,active) VALUES (4,'LETTREMAX','Lettre Max','Courrier Suivi et Lettre Max','',0);
+-- VPGSQL8.2 INSERT INTO llx_c_shipment_mode (rowid,code,libelle,description,tracking,active) VALUES (5,'UPS','UPS','United Parcel Service','http://wwwapps.ups.com/etracking/tracking.cgi?InquiryNumber2=&InquiryNumber3=&tracknums_displayed=3&loc=fr_FR&TypeOfInquiryNumber=T&HTMLVersion=4.0&InquiryNumber22=&InquiryNumber32=&track=Track&Suivi.x=64&Suivi.y=7&Suivi=Valider&InquiryNumber1={TRACKID}',0);
+-- VPGSQL8.2 INSERT INTO llx_c_shipment_mode (rowid,code,libelle,description,tracking,active) VALUES (6,'KIALA','KIALA','Relais Kiala','http://www.kiala.fr/tnt/delivery/{TRACKID}',0);
+-- VPGSQL8.2 INSERT INTO llx_c_shipment_mode (rowid,code,libelle,description,tracking,active) VALUES (7,'GLS','GLS','General Logistics Systems','http://www.gls-group.eu/276-I-PORTAL-WEB/content/GLS/FR01/FR/5004.htm?txtAction=71000&txtRefNo={TRACKID}',0);
+-- VPGSQL8.2 INSERT INTO llx_c_shipment_mode (rowid,code,libelle,description,tracking,active) VALUES (8,'CHRONO','Chronopost','Chronopost','http://www.chronopost.fr/expedier/inputLTNumbersNoJahia.do?listeNumeros={TRACKID}',0);
-- and create the new index and constraint
ALTER TABLE llx_expedition ADD INDEX idx_expedition_fk_shipping_method (fk_shipping_method);
diff --git a/test/phpunit/Functions2Test.php b/test/phpunit/Functions2Test.php
index 46f662576f5..3c44e004fc9 100755
--- a/test/phpunit/Functions2Test.php
+++ b/test/phpunit/Functions2Test.php
@@ -127,8 +127,32 @@ class Functions2Test extends PHPUnit_Framework_TestCase
$result=jsUnEscape('%u03BD%u03B5%u03BF');
print __METHOD__." result=".$result."\n";
$this->assertEquals('νεο',$result);
-
- return;
}
+
+ /**
+ * isValidMailDomain
+ *
+ * @return void
+ */
+ public function testIsValidMailDomain()
+ {
+
+ }
+
+ /**
+ * isValidURL
+ *
+ * @return void
+ */
+ public function testIsValidUrl()
+ {
+ $result=isValidUrl('http://www.google.com',1);
+ print __METHOD__." result=".$result."\n";
+ $this->assertEquals(1,$result);
+ $result=isValidUrl('www.google.com',2);
+ print __METHOD__." result=".$result."\n";
+ $this->assertEquals(0,$result);
+ }
+
}
?>
\ No newline at end of file
diff --git a/test/phpunit/NumberingModulesTest.php b/test/phpunit/NumberingModulesTest.php
index 946826449ed..008ffe6ce94 100644
--- a/test/phpunit/NumberingModulesTest.php
+++ b/test/phpunit/NumberingModulesTest.php
@@ -131,6 +131,7 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase
// First we try with a simple mask, with no reset
// and we test counter is still increase second year.
+ $conf->global->FACTURE_ADDON='mercure';
$conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}-{0000}';
$conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}-{0000}';
@@ -140,18 +141,32 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase
$numbering=new mod_facture_mercure();
$result=$numbering->getNextValue($mysoc, $localobject);
$result2=$localobject->create($user,1);
- $result3=$localobject->validate($user, $result);
+ $result3=$localobject->validate($user, $result); // create invoice by forcing ref
print __METHOD__." result=".$result."\n";
- $this->assertEquals('1915-0001', $result); // counter must start to 1
-
- $localobject=new Facture($this->savdb);
- $localobject->initAsSpecimen();
- $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1916); // we use following year for second invoice
+ $this->assertEquals('1915-0001', $result); // counter must start to 1
+ $result=$localobject->is_erasable();
+ print __METHOD__." is_erasable=".$result."\n";
+ $this->assertEquals(1, $result); // Can be deleted
+
+ $localobject2=new Facture($this->savdb);
+ $localobject2->initAsSpecimen();
+ $localobject2->date=dol_mktime(12, 0, 0, 1, 1, 1916); // we use following year for second invoice (there is no reset into mask)
$numbering=new mod_facture_mercure();
- $result=$numbering->getNextValue($mysoc, $localobject);
+ $result=$numbering->getNextValue($mysoc, $localobject2, 'last');
print __METHOD__." result=".$result."\n";
- $this->assertEquals('1916-0002', $result); // counter must not be reset
-
+ $this->assertEquals('1915-0001', $result);
+ $result=$numbering->getNextValue($mysoc, $localobject2);
+ $result2=$localobject2->create($user,1);
+ $result3=$localobject2->validate($user, $result); // create invoice by forcing ref
+ print __METHOD__." result=".$result."\n";
+ $this->assertEquals('1916-0002', $result); // counter must not be reseted so be 2
+ $result=$localobject2->is_erasable();
+ print __METHOD__." is_erasable=".$result."\n";
+ $this->assertEquals(1, $result); // Can be deleted
+ $result=$localobject->is_erasable();
+ print __METHOD__." is_erasable=".$result."\n";
+ $this->assertEquals(0, $result); // Case 1 can not be deleted (case 2 is more recent)
+
// Now we try with a reset
$conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}-{0000@1}';
$conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}-{0000@1}';
@@ -162,7 +177,7 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase
$numbering=new mod_facture_mercure();
$result=$numbering->getNextValue($mysoc, $localobject);
print __METHOD__." result=".$result."\n";
- $this->assertEquals('1910-0001', $result); // counter must start to 1
+ $this->assertEquals('1910-0001', $result); // counter must start to 1
// Same mask but we add month
$conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@1}';
@@ -175,16 +190,27 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase
$result2=$localobject->create($user,1);
$result3=$localobject->validate($user, $result);
print __METHOD__." result=".$result."\n";
- $this->assertEquals('192001-0001', $result); // counter must start to 1
-
- $localobject=new Facture($this->savdb);
- $localobject->initAsSpecimen();
- $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1921); // we use following year for second invoice
+ $this->assertEquals('192001-0001', $result); // counter must start to 1
+ $result=$localobject->is_erasable();
+ print __METHOD__." is_erasable=".$result."\n";
+ $this->assertEquals(1, $result); // Can be deleted
+
+ $localobject2=new Facture($this->savdb);
+ $localobject2->initAsSpecimen();
+ $localobject2->date=dol_mktime(12, 0, 0, 1, 1, 1921); // we use following year for second invoice (and there is a reset required)
$numbering=new mod_facture_mercure();
- $result=$numbering->getNextValue($mysoc, $localobject);
- print __METHOD__." result=".$result."\n";
- $this->assertEquals('192101-0001', $result); // counter must be resete to 1
-
+ $result=$numbering->getNextValue($mysoc, $localobject2);
+ $result2=$localobject2->create($user,1);
+ $result3=$localobject2->validate($user, $result);
+ print __METHOD__." result=".$result."\n";
+ $this->assertEquals('192101-0001', $result); // counter must be reseted to 1
+ $result=$localobject2->is_erasable();
+ print __METHOD__." is_erasable=".$result."\n";
+ $this->assertEquals(1, $result); // Can be deleted
+ $result=$localobject->is_erasable();
+ print __METHOD__." is_erasable=".$result."\n";
+ $this->assertEquals(1, $result); // Case 1 can be deleted (because there was a reset for case 2)
+
// Now we try with a different fiscal month (forced by mask)
$conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@6}';
@@ -194,16 +220,25 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase
$localobject->initAsSpecimen();
$localobject->date=dol_mktime(12, 0, 0, 1, 1, 1930); // we use year 1930 to be sure to not have existing invoice for this year
$numbering=new mod_facture_mercure();
+ $result=$numbering->getNextValue($mysoc, $localobject, 'last');
+ print __METHOD__." result for last=".$result."\n";
+ $this->assertEquals('', $result); // no existing ref into reset range
$result=$numbering->getNextValue($mysoc, $localobject);
$result2=$localobject->create($user,1);
$result3=$localobject->validate($user, $result);
print __METHOD__." result=".$result."\n";
- $this->assertEquals('193001-0001', $result); // counter must start to 1
+ $this->assertEquals('193001-0001', $result); // counter must start to 1
+ $result=$numbering->getNextValue($mysoc, $localobject, 'last');
+ print __METHOD__." result for last=".$result."\n";
+ $this->assertEquals('193001-0001', $result); // last ref into reset range should be same than last created
$localobject=new Facture($this->savdb);
$localobject->initAsSpecimen();
$localobject->date=dol_mktime(12, 0, 0, 12, 1, 1930); // we use same year but fiscal month after
$numbering=new mod_facture_mercure();
+ $result=$numbering->getNextValue($mysoc, $localobject, 'last');
+ print __METHOD__." result for last=".$result."\n";
+ $this->assertEquals('', $result); // last ref into reset range should be ''
$result=$numbering->getNextValue($mysoc, $localobject);
$result2=$localobject->create($user,1);
$result3=$localobject->validate($user, $result);
@@ -222,7 +257,7 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase
$localobject=new Facture($this->savdb);
$localobject->initAsSpecimen();
- $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1931); // we use different discal year but same year
+ $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1931); // we use different fiscal year but same year
$numbering=new mod_facture_mercure();
$result=$numbering->getNextValue($mysoc, $localobject);
print __METHOD__." result=".$result."\n";