From 9e078b32d261bdfe91ed11e177b93973623b61a5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 20 Feb 2015 18:35:52 +0100 Subject: [PATCH] Fixes the way the RUM number is generated. Start phpunit test. --- .../class/bonprelevement.class.php | 33 ++-- test/phpunit/AllTests.php | 5 +- test/phpunit/BankAccountTest.php | 2 +- test/phpunit/BonPrelevementTest.php | 182 ++++++++++++++++++ 4 files changed, 202 insertions(+), 20 deletions(-) create mode 100644 test/phpunit/BonPrelevementTest.php diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php index 3738abac4c7..a43423c0d78 100644 --- a/htdocs/compta/prelevement/class/bonprelevement.class.php +++ b/htdocs/compta/prelevement/class/bonprelevement.class.php @@ -894,13 +894,13 @@ class BonPrelevement extends CommonObject if (!$error) { $ref = substr($year,-2).$month; - + $sql = "SELECT substring(ref from char_length(ref) - 1)"; $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons"; $sql.= " WHERE ref LIKE '%".$ref."%'"; $sql.= " AND entity = ".$conf->entity; $sql.= " ORDER BY ref DESC LIMIT 1"; - + dol_syslog(get_class($this)."::Create sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); @@ -917,7 +917,7 @@ class BonPrelevement extends CommonObject $ref = "T".$ref.str_pad(dol_substr("00".intval($row[0])+1),2,"0",STR_PAD_LEFT); $filebonprev = $ref; - + // Create withdraw receipt in database $sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_bons ("; $sql.= " ref, entity, datec"; @@ -978,10 +978,7 @@ class BonPrelevement extends CommonObject $error++; } - /* - * Update orders - * - */ + // Update invoice requests as done $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_facture_demande"; $sql.= " SET traite = 1"; $sql.= ", date_traite = '".$this->db->idate($now)."'"; @@ -1029,7 +1026,7 @@ class BonPrelevement extends CommonObject $bonprev->factures = $factures_prev_id; - //Build file + // Generation of SEPA file $bonprev->generate(); } dol_syslog($filebonprev); @@ -1039,7 +1036,6 @@ class BonPrelevement extends CommonObject /* * Update total */ - $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_bons"; $sql.= " SET amount = ".price2num($bonprev->total); $sql.= " WHERE rowid = ".$prev_id; @@ -1053,9 +1049,6 @@ class BonPrelevement extends CommonObject dol_syslog("Erreur mise a jour du total - $sql"); } - /* - * Rollback or Commit - */ if (!$error) { $this->db->commit(); @@ -1267,9 +1260,9 @@ class BonPrelevement extends CommonObject /* * section Debiteur (sepa Debiteurs bloc lines) */ - $sql = "SELECT soc.code_client as code, soc.address, soc.zip, soc.town, soc.datec, c.code as country_code,"; + $sql = "SELECT soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,"; $sql.= " pl.client_nom as name, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,"; - $sql.= " f.facnumber as fac, pf.fk_facture as idfac, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum"; + $sql.= " f.facnumber as fac, pf.fk_facture as idfac, rib.iban_prefix as iban, rib.bic as bic, rib.datec, rib.rowid as drum"; $sql.= " FROM"; $sql.= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; $sql.= " ".MAIN_DB_PREFIX."facture as f,"; @@ -1510,17 +1503,21 @@ class BonPrelevement extends CommonObject * @param string $row_idfac pf.fk_facture AS idfac, * @param string $row_iban rib.iban_prefix AS iban, * @param string $row_bic rib.bic AS bic, - * @param string $row_datec soc.datec, - * @param string $row_drum soc.rowid AS drum + * @param string $row_datec rib.datec, + * @param string $row_drum rib.rowid AS drum * @return string Return string with SEPA part DrctDbtTxInf */ function EnregDestinataireSEPA($row_code_client, $row_nom, $row_address, $row_zip, $row_town, $row_country_code, $row_cb, $row_cg, $row_cc, $row_somme, $row_facnumber, $row_idfac, $row_iban, $row_bic, $row_datec, $row_drum) { $CrLf = "\n"; $Rowing = sprintf("%06d", $row_idfac); + + // Define value for RUM + // Example: RUMCustomerCode-CustomerBankAccountId-01424448606 (note: Date is date of creation of CustomerBankAccountId) $Date_Rum = strtotime($row_datec); - $pre = ($date_Rum > 1359673200) ? 'Rum' : '++R'; - $Rum = $pre.$row_code_client.$row_drum.'-0'.date('U', $Date_Rum); + $pre = ($date_Rum > 1359673200) ? 'RUM' : '++R'; + $Rum = dol_trunc($pre.$row_code_client.'-'.$row_drum.'-0'.date('U', $Date_Rum), 35, 'right', 'UTF-8', 1); + $XML_DEBITOR =''; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; diff --git a/test/phpunit/AllTests.php b/test/phpunit/AllTests.php index a8a554ca25d..739104f72fd 100644 --- a/test/phpunit/AllTests.php +++ b/test/phpunit/AllTests.php @@ -153,8 +153,11 @@ class AllTests $suite->addTestSuite('UserGroupTest'); require_once dirname(__FILE__).'/BankAccountTest.php'; $suite->addTestSuite('BankAccountTest'); - require_once dirname(__FILE__).'/CompanyBankAccountTest.php'; + require_once dirname(__FILE__).'/CompanyBankAccountTest.php'; $suite->addTestSuite('CompanyBankAccountTest'); + require_once dirname(__FILE__).'/BonPrelevementTest.php'; + $suite->addTestSuite('BonPrelevementTest'); + require_once dirname(__FILE__).'/ChargeSocialesTest.php'; $suite->addTestSuite('ChargeSocialesTest'); require_once dirname(__FILE__).'/HolidayTest.php'; diff --git a/test/phpunit/BankAccountTest.php b/test/phpunit/BankAccountTest.php index 4983f1e2173..0556b21fb85 100644 --- a/test/phpunit/BankAccountTest.php +++ b/test/phpunit/BankAccountTest.php @@ -17,7 +17,7 @@ */ /** - * \file test/phpunit/ContratTest.php + * \file test/phpunit/BankAccounrTest.php * \ingroup test * \brief PHPUnit test * \remarks To run this script as CLI: phpunit filename.php diff --git a/test/phpunit/BonPrelevementTest.php b/test/phpunit/BonPrelevementTest.php new file mode 100644 index 00000000000..0124b25e6c6 --- /dev/null +++ b/test/phpunit/BonPrelevementTest.php @@ -0,0 +1,182 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * or see http://www.gnu.org/ + */ + +/** + * \file test/phpunit/BonPrelevementTest.php + * \ingroup test + * \brief PHPUnit test + * \remarks To run this script as CLI: phpunit filename.php + */ + +global $conf,$user,$langs,$db; +//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver +//require_once 'PHPUnit/Autoload.php'; +require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; +require_once dirname(__FILE__).'/../../htdocs/compta/prelevement/class/bonprelevement.class.php'; + +if (empty($user->id)) +{ + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); +} +$conf->global->MAIN_DISABLE_ALL_MAILS=1; + +$langs->load("main"); + + +/** + * Class for PHPUnit tests + * + * @backupGlobals disabled + * @backupStaticAttributes enabled + * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased. + */ +class BonPrelevementTest extends PHPUnit_Framework_TestCase +{ + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; + + /** + * Constructor + * We save global variables into local variables + * + * @return BankAccountTest + */ + function __construct() + { + //$this->sharedFixture + global $conf,$user,$langs,$db; + $this->savconf=$conf; + $this->savuser=$user; + $this->savlangs=$langs; + $this->savdb=$db; + + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } + + // Static methods + public static function setUpBeforeClass() + { + global $conf,$user,$langs,$db; + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. + + print __METHOD__."\n"; + } + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); + + print __METHOD__."\n"; + } + + /** + * Init phpunit tests + * + * @return void + */ + protected function setUp() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + print __METHOD__."\n"; + } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } + + /** + * testBonPrevelementCreate + * + * @return int + */ + public function testBonPrelevementCreate() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + // TODO + // Create invoice + + + // Create payment with mode withdraw + + + // Ask withdraw request + + + // Create withdraw record and generate SEPA file + $localobject=new BonPrelevement($this->savdb); + //$localobject->date_solde=dol_now(); + $result=$localobject->Create(0,0,'simu'); + + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, 0); + + // Test SEPA file + + + return $result; + } + + /** + * testBonPrelevementDelete + * + * @param int $id Id of contract + * @return int + * + * @depends testBonPrelevementOther + * The depends says test is run only if previous is ok + */ +/* public function testBonPrelevementDelete($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject=new BonPrelevement($this->savdb); + $result=$localobject->fetch($id); + $result=$localobject->delete($id); + + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $result; + } +*/ + +}