[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 12/30: Fix : bug cannot save an empty FIN Led
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 12/30: Fix : bug cannot save an empty FIN Ledger |
Date: |
Sat, 3 Dec 2022 08:35:08 -0500 (EST) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit 077173199b314f7e0cb71e52f17453446736d202
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Wed Nov 23 18:20:38 2022 +0100
Fix : bug cannot save an empty FIN Ledger
---
include/class/acc_ledger.class.php | 90 ++++++++++++----
unit-test/include/class/acc_ledgerTest.php | 165 ++++++++++++++++++++---------
2 files changed, 188 insertions(+), 67 deletions(-)
diff --git a/include/class/acc_ledger.class.php
b/include/class/acc_ledger.class.php
index a3fe4f913..f198149d8 100644
--- a/include/class/acc_ledger.class.php
+++ b/include/class/acc_ledger.class.php
@@ -180,6 +180,7 @@ class Acc_Ledger extends jrn_def_sql
$this->db->exec_sql('delete from jrnx where j_grpt=$1',
array($grpt_id));
$this->db->exec_sql('delete from jrn where jr_id=$1',
array($this->jr_id));
+
}
/**
@@ -2668,7 +2669,9 @@ class Acc_Ledger extends jrn_def_sql
/**
* Verify before update
*
- * @param type $array
+ * @param type
+ * @code
+ * $array
* 'p_jrn' => string '3' (length=1)
'sa' => string 'detail' (length=6)
'gDossier' => string '82' (length=2)
@@ -2678,15 +2681,10 @@ class Acc_Ledger extends jrn_def_sql
'p_jrn_name' => string 'Achat' (length=5)
'jrn_def_pj_pref' => string 'ACH' (length=3)
'jrn_def_pj_seq' => string '0' (length=1)
- 'FICHECRED' =>
- array
- 0 => string '4' (length=1)
- 'FICHEDEB' =>
- array
- 0 => string '7' (length=1)
- 1 => string '5' (length=1)
- 2 => string '13' (length=2)
- 'update' => string 'Sauve' (length=5
+ 'FICHECRED' =>array(fd_id)
+ 'FICHEDEB' =>array(fd_id)
+ 'update' => string 'Sauve' (length=5
+ * @endcode
* @exception is throw is test are not valid
*/
function verify_ledger($array)
@@ -2746,8 +2744,27 @@ class Acc_Ledger extends jrn_def_sql
}
/**
- * update a ledger
+ * @brief update a ledger
* @param type $array normally post
+ * @code
+ * // Example for a financial ledger
+ [p_jrn] => 83
+ [sa] => detail
+ [gDossier] => 25
+ [p_jrn_deb_max_line] => 10
+ [p_ech_lib] => echeance
+ [p_jrn_type] => FIN
+ [p_jrn_name] => Banque Privée
+ [bank] => BANQUE
+ [min_row] => 5
+ [p_description] => Compte fermé
+ [jrn_def_pj_pref] => BP19-
+ [jrn_def_pj_seq] => 0
+ [jrn_enable] => 0
+ [FIN_FICHEDEB] =>array(fd_id)
+ [defaultCurrency] => 0 // if there is no operation
+ [action_frm] => update
+ * @endcode
* @see verify_ledger
*/
function update($array=null)
@@ -2804,7 +2821,7 @@ class Acc_Ledger extends jrn_def_sql
case 'FIN':
$a=new Fiche($this->db);
- $result=$a->get_by_qcode(trim(strtoupper($_POST['bank'])),
false);
+
$result=$a->get_by_qcode(trim(strtoupper($http->extract('bank'))), false);
$bank=$a->id;
$this->jrn_def_bank=$bank;
$FIN_FICHEDEB=$http->extract('FIN_FICHEDEB','array',array());
@@ -2819,7 +2836,7 @@ class Acc_Ledger extends jrn_def_sql
* Set the default currency except if there are already
operation
*/
if ( $nb_operation == 0 ){
- $this->currency_id=$defaultCurrency;
+ $this->currency_id=$http->extract("defaultCurrency");
} else {
$this->currency_id=$this->db->get_value("select
currency_id from jrn_def where jrn_def_id=$1",
[$this->jrn_def_id]);
@@ -2964,6 +2981,39 @@ class Acc_Ledger extends jrn_def_sql
/**
* @brief Insert a new ledger , member variable like jrn_def_id will
changed
* @param array $array normally $_POST
+ * @code
+ Array
+ (
+ [gDossier] => 25
+ [ac] => CFG/MACC/CFGLED
+ [p_jrn] => -1
+ [p_action] => jrn
+ [sa] => add
+ [p_jrn_deb_max_line] => 10
+ [p_ech_lib] => echeance
+ [p_jrn_type] => VEN
+ [p_jrn_name] => test
+ [p_jrn_class_deb] =>
+ [bank] =>
+ [negative_amount] => 0
+ [negative_warning] => Attention, ce journal doit utiliser des montants
négatifs
+ [p_jrn_quantity] => 1
+ [min_row] => 5
+ [p_description] =>
+ [jrn_def_pj_pref] => A
+ [defaultCurrency] => 0
+ [ACH_FICHECRED] => Array(fd_id)
+ [ACH_FICHEDEB] => Array (fd_id)
+ [VEN_FICHEDEB] => Array (fd_id)
+ [VEN_FICHECRED] => Array (fd_id)
+ [ODS_FICHEDEB] => Array(fd_id)
+ [FIN_FICHEDEB] => Array(fd_id)
+ [ defaultCurrency] =>"int" only for Financial if there is no operation
+ )
+ *
+ *
+ * @endcode
+ *
* @see verify_ledger
*/
function save_new($array)
@@ -3006,9 +3056,9 @@ class Acc_Ledger extends jrn_def_sql
break;
case 'FIN':
$a=new Fiche($this->db);
- $result=$a->get_by_qcode(trim(strtoupper($_POST['bank'])),
false);
- $bank=$a->id;
- $this->jrn_def_bank=$bank;
+ $result=$a->get_by_qcode(trim(strtoupper($bank)), false);
+ $bank_id=$a->id;
+ $this->jrn_def_bank=$bank_id;
$this->jrn_def_fiche_deb=(isset($FIN_FICHEDEB))?join(',',$FIN_FICHEDEB):"";
if ($result==-1)
throw new Exception(_("Aucun compte en banque n'est
donné"));
@@ -3018,10 +3068,11 @@ class Acc_Ledger extends jrn_def_sql
}
$this->jrn_def_quantity=(!isset($this->jrn_def_quantity)||$this->jrn_def_quantity==null)?1:$this->jrn_def_quantity;
parent::insert();
+ $this->id=$this->jrn_def_id;
}
/**
- * delete a ledger IF is not already used
+ * @brief delete a ledger IF it doesn't contain anything
* @exception : cannot delete
*/
function delete_ledger()
@@ -3041,7 +3092,7 @@ class Acc_Ledger extends jrn_def_sql
}
/**
- * Get operation from the ledger type before, after or with the
+ * @brief Get operation from the ledger type before, after or with the
* given date . The array is filtered by the ledgers granted to the
* user
* @global type $g_user
@@ -3079,7 +3130,8 @@ class Acc_Ledger extends jrn_def_sql
$array=$this->db->get_array($sql, array($p_date));
return $array;
}
- /** @brief Get simplified row from ledger
+ /**
+ * @brief Get simplified row from ledger
* Call Acc_Ledger_History_Generic:get_rowSimple
* @param p_from periode
* @param p_to periode
diff --git a/unit-test/include/class/acc_ledgerTest.php
b/unit-test/include/class/acc_ledgerTest.php
index b3284196a..58dcd4ebf 100644
--- a/unit-test/include/class/acc_ledgerTest.php
+++ b/unit-test/include/class/acc_ledgerTest.php
@@ -426,6 +426,65 @@ class Acc_LedgerTest extends TestCase
$ledger->load();
$this->assertEquals(0,$ledger->has_quantity(),'jrn_def_quantity is not
saved');
+ }
+
+ /**
+ * @brief create a financial, update it
+ * @return void
+ */
+ function testManageFinancial()
+ {
+ global $g_connection;
+ // create a card financial
+ $new_fiche = new Fiche($g_connection);
+ $aProperty = array('av_text1' => 'Nom', 'av_text23' => 'BK1');
+
+ $new_fiche->insert(3, $aProperty);
+
+ //- create a new financial ledger
+ $array=["jrn_def_id"=>-1,
+ "p_jrn_name"=>"PhpUnit Fin",
+ "p_ech_lib"=>"",
+ "p_jrn_type"=>"FIN",
+ "bank"=>$new_fiche->get_quick_code(),
+ "negative_amount"=>0,
+ "negative_warning"=>"",
+ "p_jrn_quantity"=>0,
+ "min_row"=>"5",
+ "p_description"=>"",
+ "jrn_def_pj_pref"=>"PU" ,
+ "FIN_FICHE_DEF"=>[2,3,4],
+ "defaultCurrency"=>0,
+ "p_jrn_deb_max_line" => 10,
+ ];
+ // - update it
+ $acc_ledger=new Acc_Ledger($g_connection,-1);
+ $acc_ledger->save_new($array);
+ $this->assertTrue($acc_ledger->id > 0 ,'ledger not created' );
+ $update=array (
+ "p_jrn" => $acc_ledger->id,
+ "sa" => "detail",
+ "p_jrn_deb_max_line" => 10,
+ "p_ech_lib" => "echeance",
+ "p_jrn_type" => "FIN",
+ "p_jrn_name"=>"PhpUnit Fin2",
+ "bank"=>$new_fiche->get_quick_code(),
+ "min_row" => 5,
+ "p_description" => "",
+ "jrn_def_pj_pref" => "A",
+ "jrn_def_pj_seq" => 0,
+ "jrn_enable" => 0,
+ "FIN_FICHEDEB" =>array(2,3,4),
+ "defaultCurrency"=>0
+ );
+
+ $acc_ledger->update($update);
+ $this->assertTrue($acc_ledger->jrn_def_name=="PhpUnit Fin2"," cannot
change ledger name");
+ $this->assertTrue($acc_ledger->jrn_def_bank==$new_fiche->id," set bank
incorrect");
+
+ $acc_ledger->delete_ledger();
+ $new_fiche->delete();
+
}
/**
* @covers Acc_Ledger::input
@@ -481,54 +540,63 @@ class Acc_LedgerTest extends TestCase
"p_jrn_name"=>"New ledger",
"p_jrn_type"=>"ODS"
];
+ try {
//-----------------------------------------------
// Must succeed
//-----------------------------------------------
- $ledger->verify_ledger($array);
-
-
- // succeeds if negative amount 1
- $array["negative_amount"]=1;
- $ledger->verify_ledger($array);
-
- //-----------------------------------------------
- // Must fail
- //-----------------------------------------------
- ob_start();
- try {
- $array["p_jrn"]="a";
- $ledger->verify_ledger($array);
- $this->assertTrue(FALSE,"p_jrn is invalide");
- }catch (\Exception $e) {
- $this->assertTrue(TRUE);
- }
- ob_end_clean();
- // reset properly ,
- $array["p_jrn"]="15";
- $ledger->verify_ledger($array);
-
-
- // fails if negative amount neither 1 nor 0
- ob_start();
- try {
- $array["negative_amount"]=2;
- $ledger->verify_ledger($array);
- $this->assertTrue(FALSE,"negative_amount must be 1 or 0");
- }catch (\Exception $e) {
- $this->assertTrue(TRUE);
- }
- ob_end_clean();
-
- // negative amount not set , so fails
- ob_start();
- try {
- $array["negative_warning"]="Yes";
- $ledger->verify_ledger($array);
- $this->assertTrue(FALSE,"negative_warning must be a string");
- }catch (\Exception $e) {
- $this->assertTrue(TRUE);
+
+ $ledger->verify_ledger($array);
+ // succeeds if negative amount 1
+ $array["negative_amount"]=1;
+ $ledger->verify_ledger($array);
+ $this->assertTrue(true, "an unexpected exception");
+
+ } catch (\Exception $e) {
+ echo $e->getMessage();
+ $this->assertTrue(false, "an unexpected exception");
}
- ob_end_clean();
+
+
+ }
+
+ /**
+ * @testdox verify_ledger , Wrong id
+ * @return void
+ */
+ public function testVerifyWrongId()
+ {
+ global $g_connection;
+ $ledger=new Acc_Ledger($g_connection,4);
+ $this->expectException(Exception::class);
+ $array=[
+ "p_jrn"=>"15",
+ "p_jrn_deb_max_line"=>5,
+ "p_jrn_name"=>"New ledger",
+ "p_jrn_type"=>"ODS"
+ ];
+
+ $array["p_jrn"]="a";
+ $ledger->verify_ledger($array);
+ }
+
+ /**
+ * @testdox verify_ledger , Negative amount
+ * @return void
+ */
+ public function testVerifyWrongNegativeAmount()
+ {
+ global $g_connection;
+ $ledger=new Acc_Ledger($g_connection,4);
+ $this->expectException(Exception::class);
+ $array=[
+ "p_jrn"=>"15",
+ "p_jrn_deb_max_line"=>5,
+ "p_jrn_name"=>"New ledger",
+ "p_jrn_type"=>"ODS"
+ ];
+
+ $array["negative_amount"]=2;
+ $ledger->verify_ledger($array);
}
/**
@@ -842,22 +910,23 @@ class Acc_LedgerTest extends TestCase
public function testInput_new()
{
put_global([["key"=>"ac","value"=>"ODS"]]);
-
+ ob_start();
echo \Noalyss\Facility::page_start();
+
$this->object->set_ledger_id(4);
$this->object->input_new();
$result=ob_get_contents();
ob_end_clean();
\Noalyss\Facility::save_file(__DIR__."/file",
"acc_ledger-input_new.html", $result);
$size=filesize(__DIR__."/file/acc_ledger-input_new.html");
-
- $this->assertEquals(15649,$size," output input_new is not what it is
expected");
+ $this->assertEquals(16320,$size," output input_new is not what it is
expected");
+
}
/**
* @covers Acc_Ledger::save_new
*/
- public function testSave_new()
+ public function testODSSave_new()
{
global $g_connection;
$ledger=new Acc_Ledger($g_connection,-1);
- [Noalyss-commit] [noalyss] 09/30: New #0002216: Transformation d'une dépense Gestion en facture achat ou note de frais, (continued)
- [Noalyss-commit] [noalyss] 09/30: New #0002216: Transformation d'une dépense Gestion en facture achat ou note de frais, Dany De Bontridder, 2022/12/03
- [Noalyss-commit] [noalyss] 29/30: Cosmetic : color, Dany De Bontridder, 2022/12/03
- [Noalyss-commit] [noalyss] 28/30: cosmetic, Dany De Bontridder, 2022/12/03
- [Noalyss-commit] [noalyss] 30/30: Cosmetic, Dany De Bontridder, 2022/12/03
- [Noalyss-commit] [noalyss] 04/30: Show tag in operations list, Dany De Bontridder, 2022/12/03
- [Noalyss-commit] [noalyss] 08/30: To let TOOLS plugin to add tag to operation, Dany De Bontridder, 2022/12/03
- [Noalyss-commit] [noalyss] 01/30: Bug : no filter on card for ledger PURCHASE, Dany De Bontridder, 2022/12/03
- [Noalyss-commit] [noalyss] 05/30: Cosmetic : display cards on one row in account search, Dany De Bontridder, 2022/12/03
- [Noalyss-commit] [noalyss] 11/30: Improve Test and set the Patch level to 181, Dany De Bontridder, 2022/12/03
- [Noalyss-commit] [noalyss] 13/30: Better error message when cannot save a plugin, Dany De Bontridder, 2022/12/03
- [Noalyss-commit] [noalyss] 12/30: Fix : bug cannot save an empty FIN Ledger,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 14/30: Bug Fiche_Def->insertAttribut when needed to compute an attribute order, Dany De Bontridder, 2022/12/03
- [Noalyss-commit] [noalyss] 26/30: WHen creating from follow-up , keep a link to the event in the operation, Dany De Bontridder, 2022/12/03
- [Noalyss-commit] [noalyss] 24/30: Cosmetic, Dany De Bontridder, 2022/12/03
- [Noalyss-commit] [noalyss] 23/30: Comptability : Falkon doesn't understand the javascript token "??", Dany De Bontridder, 2022/12/03
- [Noalyss-commit] [noalyss] 10/30: Bug : typo change by accident function name, Dany De Bontridder, 2022/12/03
- [Noalyss-commit] [noalyss] 16/30: Fix bug : prevent identical tags on operation, Dany De Bontridder, 2022/12/03
- [Noalyss-commit] [noalyss] 21/30: Change DB version, Dany De Bontridder, 2022/12/03
- [Noalyss-commit] [noalyss] 20/30: fix bug followup cannot add first comment, Dany De Bontridder, 2022/12/03
- [Noalyss-commit] [noalyss] 22/30: cosmetic : waiting_box, Dany De Bontridder, 2022/12/03
- [Noalyss-commit] [noalyss] 15/30: Cosmetic :, Dany De Bontridder, 2022/12/03