From 70bae8b1b75dfe2beda7ae979cd98898af91d469 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Sun, 18 May 2025 15:31:02 +0200 Subject: [PATCH] FIX bug due changes Data_SQL --- include/class/acc_ledger.class.php | 31 ++++++++-- include/class/acc_ledger_fin.class.php | 2 +- include/class/acc_ledger_purchase.class.php | 14 ++--- include/class/acc_ledger_sale.class.php | 8 +-- include/class/anc_print.class.php | 2 +- include/class/fiche.class.php | 8 +-- include/database/tva_rate_sql.class.php | 2 +- include/lib/data_sql.class.php | 2 +- include/lib/table_data_sql.class.php | 2 +- .../include/class/acc_account_ledgerTest.php | 58 +++++++++++++++++++ ...c_compute.Test.php => acc_computeTest.php} | 0 unit-test/include/class/acc_ledgerTest.php | 2 +- ...er_fin.Test.php => acc_ledger_finTest.php} | 0 ...p => acc_ledger_history_financialTest.php} | 0 ...atabaseTest.class.php => databaseTest.php} | 0 unit-test/include/class/upgrade176.sql | 0 unit-test/include/lib/data_sqlTest.php | 24 ++++---- 17 files changed, 116 insertions(+), 39 deletions(-) rename unit-test/include/class/{acc_compute.Test.php => acc_computeTest.php} (100%) rename unit-test/include/class/{acc_ledger_fin.Test.php => acc_ledger_finTest.php} (100%) rename unit-test/include/class/{acc_ledger_history_financial.Test.php => acc_ledger_history_financialTest.php} (100%) rename unit-test/include/class/{databaseTest.class.php => databaseTest.php} (100%) delete mode 100644 unit-test/include/class/upgrade176.sql diff --git a/include/class/acc_ledger.class.php b/include/class/acc_ledger.class.php index 182ce4173..f9b0bc7f5 100644 --- a/include/class/acc_ledger.class.php +++ b/include/class/acc_ledger.class.php @@ -40,11 +40,30 @@ class Acc_Ledger extends jrn_def_sql var $row; /**!< row of the ledger */ var $ledger_type; /**!< type of the ledger ACH ODS FIN VEN or GL */ var $nb; /**!< default number of rows by default 10 */ - var $currency_id; + var $currency_id;/**!< $currency_id (int) SQL:CURRENCY.ID default 0 */ /**!< is_loaded true the ledger definition is loaded or false, it is not */ protected $is_loaded ; var $ledger_name; - + var $jr_internal ; /**!< $jr_internal (string) internal number for an operation */ + var $jr_id; /**!< $jr_id (int) SQL : PK JRN.JR_ID */ + var $jrn_def_max_line_deb ; /**!< $jr_id (int) PK.JRN */ + var $jrn_def_id; /**!< $jrn_def_id(INT) jrn_def.jrn_def_id */ + var $jrn_def_name; /**!< $jrn_def_name(string) ledger name */ + var $jrn_def_ech_lib; /**!< $jrn_def_ech_lib (string) text for limit date */ + var $jrn_def_type; /**!< $jrn_def_type(string) type of the ledger ACH,VEN,ODS,FIN */ + var $jrn_def_pj_pref; /**!< $jrn_def_pj_pref(string) prefix for receipt */ + var $jrn_deb_max_line;/**!< $jrn_deb_max_line(int) max rows to display*/ + var $jrn_def_description; /**!< $jrn_def_description(string) ledger description */ + var $jrn_enable; /**!< $jrn_enable (0 or 1)0:ledger not available, 1:ledger available */ + var $jrn_def_negative_amount; /**!< $jrn_def_negative_amount (0-1) 0: ledger use positive or negative amount, 1: ledger should use negative amount */ + var $jrn_def_negative_warning; /**!<$jrn_def_negative_warning (string) string to display if the amount is not positive (see $jrn_def_negative_amount) */ + var $jrn_def_quantity; /**!< $jrn_def_quantity (0-1) 0 no quantity for operations + * 1 has quantity */ + var $with_concerned; /**!< $with_concerned(bool) : true is operation comes with + another one, */ + var $jr_grpt_id ; /**! $jr_grpt_id (int) SQL JRN.JR_GRP_ID group rows + of an operations */ + var $pj; /**!< $pj (string) nb receipt of the operation */ /** * @brief construct * @param $p_cn database connexion @@ -1607,7 +1626,7 @@ class Acc_Ledger extends jrn_def_sql $this->db->exec_sql("update jrn set jr_internal=$1 where jr_grpt_id = $2",array($internal,$seq)); - $this->internal=$internal; + $this->jr_internal=$internal; // Save now the predef op //------------------------ if (isset($opd_name)&&trim($opd_name)!="") @@ -1712,10 +1731,10 @@ class Acc_Ledger extends jrn_def_sql function update_internal_code($p_internal) { - if (!isset($this->grpt_id)) - throw new Exception(('ERREUR '.__FILE__.":".__LINE__)); + if (!isset($this->jr_grpt_id)) + throw new Exception(('ERREUR jr_grpt_id not set '.__FILE__.":".__LINE__)); $Res=$this->db->exec_sql("update jrn set jr_internal=$1 where - jr_grpt_id = $2 ",array($p_internal,$this->grpt_id)); + jr_grpt_id = $2 ",array($p_internal,$this->jr_grpt_id)); } /** diff --git a/include/class/acc_ledger_fin.class.php b/include/class/acc_ledger_fin.class.php index f02b00543..88a5e3d2c 100644 --- a/include/class/acc_ledger_fin.class.php +++ b/include/class/acc_ledger_fin.class.php @@ -1040,7 +1040,7 @@ class Acc_Ledger_Fin extends Acc_Ledger } // Set Internal code - $this->grpt_id=$seq; + $this->jr_grpt_id=$seq; /** * save also into quant_fin */ diff --git a/include/class/acc_ledger_purchase.class.php b/include/class/acc_ledger_purchase.class.php index afbe7e8ab..2c3951b66 100644 --- a/include/class/acc_ledger_purchase.class.php +++ b/include/class/acc_ledger_purchase.class.php @@ -526,7 +526,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger $this->id=$p_jrn; $internal=$this->compute_internal_code($seq); - $this->internal=$internal; + $this->jr_internal=$internal; $cust=new Fiche($this->db); $cust->get_by_qcode($e_client); @@ -678,11 +678,11 @@ class Acc_Ledger_Purchase extends Acc_Ledger } if ($g_parameter->MY_UPDLAB=='Y') { - $acc_operation->desc=strip_tags(${"e_march".$i."_label"}); + $acc_operation->desc=strip_tags(${"e_march".$i."_label"}??""); } else { - $acc_operation->desc=null; + $acc_operation->desc=""; } $acc_operation->poste=$poste_val; $acc_operation->amount=$acc_amount->amount; @@ -962,7 +962,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger $this->pj=$acc_operation->update_receipt(); // Set Internal code - $this->grpt_id=$seq; + $this->jr_grpt_id=$seq; $this->update_internal_code($internal); /* update quant_purchase */ $this->db->exec_sql('update quant_purchase set qp_internal = $1 where j_id in (select j_id from jrnx where j_grpt=$2)', @@ -1090,7 +1090,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger // insert into the table JRN $mp_jr_id=$acc_pay->insert_jrn(); $this->payment_operation=$mp_jr_id; - $acjrn->grpt_id=$acseq; + $acjrn->jr_grpt_id=$acseq; $acjrn->update_internal_code($acinternal); // add an automatic PJ if ODS if ($acjrn->get_type()=="ODS") { @@ -1606,14 +1606,14 @@ class Acc_Ledger_Purchase extends Acc_Ledger $r .= '
'; $r.=''; if ( $p_summary ) { - $jr_id=$this->db->get_value('select jr_id from jrn where jr_internal=$1',array($this->internal)); + $jr_id=$this->db->get_value('select jr_id from jrn where jr_internal=$1',array($this->jr_internal)); $r.=""; $r.=''; $r.=''; $r.=""; } diff --git a/include/class/acc_ledger_sale.class.php b/include/class/acc_ledger_sale.class.php index 8dca652e3..ff21e3444 100644 --- a/include/class/acc_ledger_sale.class.php +++ b/include/class/acc_ledger_sale.class.php @@ -275,7 +275,7 @@ class Acc_Ledger_Sale extends Acc_Ledger { $seq = $this->db->get_next_seq('s_grpt'); $this->id = $p_jrn; $internal = $this->compute_internal_code($seq); - $this->internal = $internal; + $this->jr_internal = $internal; $oPeriode = new Periode($this->db); $check_periode = $this->check_periode(); @@ -805,7 +805,7 @@ class Acc_Ledger_Sale extends Acc_Ledger { /* insert into jrn */ $acc_pay->mt = $mt; - $acjrn->grpt_id = $acseq; + $acjrn->jr_grpt_id = $acseq; $acc_pay->desc = (!isset($e_comm_paiement) || noalyss_strlentrim($e_comm_paiement) == 0) ? $e_comm : $e_comm_paiement; $mp_jr_id = $acc_pay->insert_jrn(); $acjrn->update_internal_code($acinternal); @@ -906,14 +906,14 @@ class Acc_Ledger_Sale extends Acc_Ledger { $r .= '
'; $r.='
'; $r.=_('Détail opération '); $r.=''; $r.=sprintf ('%s', - $jr_id,dossier::id(),$this->internal); + $jr_id,dossier::id(),$this->jr_internal); $r.='
'; if ( $p_summary ) { - $jr_id=$this->db->get_value('select jr_id from jrn where jr_internal=$1',array($this->internal)); + $jr_id=$this->db->get_value('select jr_id from jrn where jr_internal=$1',array($this->jr_internal)); $r.=""; $r.=''; $r.=''; $r.=""; } diff --git a/include/class/anc_print.class.php b/include/class/anc_print.class.php index 24f8e216d..748511c61 100644 --- a/include/class/anc_print.class.php +++ b/include/class/anc_print.class.php @@ -38,7 +38,7 @@ class Anc_Print var $from_poste; /*!< $from_poste from poste */ var $to_poste; /*!< $to_poste to the poste */ var $has_data; /*!< array of data */ - protected $pa_id; /*!< axis for analytic : plan */ + var $pa_id; /*!< axis for analytic : plan */ function __construct($p_cn) { diff --git a/include/class/fiche.class.php b/include/class/fiche.class.php index b8c7a657e..bdf72501c 100644 --- a/include/class/fiche.class.php +++ b/include/class/fiche.class.php @@ -49,7 +49,7 @@ class Fiche var $tot_deb; var $ledger_name; ///!< this variable is a mistake, it shouldn't exist, need code rewrite var $ledger_description; ///!< this variable is a mistake, it shouldn't exist, need code rewrite - + function __construct($p_cn,$p_id=0) { $this->cn=$p_cn; @@ -1461,10 +1461,10 @@ class Fiche $sql='select fd_id from fiche where f_id=$1'; $R=$this->cn->get_value($sql, array($this->id)); if ( $R == "" ) - $this->fd_id=0; + $this->fiche_def=0; else - $this->fd_id=$R; - return $this->fd_id; + $this->fiche_def=$R; + return $this->fiche_def; } /*! *************************************************** diff --git a/include/database/tva_rate_sql.class.php b/include/database/tva_rate_sql.class.php index 78bb589b4..9043d0605 100644 --- a/include/database/tva_rate_sql.class.php +++ b/include/database/tva_rate_sql.class.php @@ -73,7 +73,7 @@ class Tva_Rate_SQL extends Table_Data_SQL $this->default=array( "tva_id"=>"auto" ); - + $this->date_format="DD.MM.YYYY"; parent::__construct($p_cn, $p_id); } diff --git a/include/lib/data_sql.class.php b/include/lib/data_sql.class.php index aa4299ae2..7b5e86d86 100644 --- a/include/lib/data_sql.class.php +++ b/include/lib/data_sql.class.php @@ -103,7 +103,7 @@ abstract class Data_SQL var $type; //! Type of the data var $date_format; //! defaullt date format var $default; - var $table; + var $table; public function __toString(): string { diff --git a/include/lib/table_data_sql.class.php b/include/lib/table_data_sql.class.php index 7b5428adc..0c4737860 100644 --- a/include/lib/table_data_sql.class.php +++ b/include/lib/table_data_sql.class.php @@ -195,7 +195,7 @@ abstract class Table_Data_SQL extends Data_SQL $pk=$this->primary_key; // primary cannot be null or empty if (trim($this->$pk??"")==="" || $this->$pk===null) { - $this->pk=-1; + $this->$pk=-1; return false; } diff --git a/unit-test/include/class/acc_account_ledgerTest.php b/unit-test/include/class/acc_account_ledgerTest.php index 5021476cd..4997d51e3 100644 --- a/unit-test/include/class/acc_account_ledgerTest.php +++ b/unit-test/include/class/acc_account_ledgerTest.php @@ -48,6 +48,36 @@ class Acc_Account_LedgerTest extends TestCase $this->assertEquals(count($array), 3); } + /** + * @return array : idx [ $accounting,$from_date,$to_date,$nb_row,$tot_deb,$tot_cred] + */ + public function dataGet_row_date() + { + $array=array( + ['55000004','01.01.2019','31.12.2019',4,0,806.90] + ,['55000005','01.01.2019','31.12.2019',3,3750.78,250.25] + ,['4400005','01.01.2019','31.12.2019',17,806.90,1761.00] + ,['4400005','01.03.2019','02.05.2019',9,602.19,848.80] + ); + return $array; + } + /** + * @brief test function Acc_Account_Ledger::get_row_date + * @covers Acc_Account_Ledger::get_row_date + * @dataProvider dataGet_row_date + */ + public function testGetRowData($accounting,$from_date,$to_date,$nb_row,$tot_deb,$tot_cred) + { + global $g_connection; + $g_connection->clear_all_prepare(); + $acc_account_ledger=new Acc_Account_Ledger( $g_connection, $accounting); + $acc_account_ledger->get_row_date($from_date,$to_date); + $nb_actual_row=count($acc_account_ledger->row); + $this->assertEquals($nb_row,$nb_actual_row,"error received $nb_row rows"); + $this->assertEquals($tot_deb,$acc_account_ledger->tot_deb,"error amount incorrect received ".$acc_account_ledger->tot_deb); + $this->assertEquals($tot_cred,$acc_account_ledger->tot_cred,"error amount incorrect received ".$acc_account_ledger->tot_cred); + + } /** * @covers Acc_Account_Ledger::get_row_date */ @@ -480,5 +510,33 @@ class Acc_Account_LedgerTest extends TestCase $this->assertEquals($nb_accounting,count($a_result) ,"number of accounting incorrect for (\$from_date,\$to_date,\$from_accounting,\$to_accounting,\$nb_accounting : ($from_date,$to_date,$from_accounting,$to_accounting,$nb_accounting"); + } + /** + * @return array : idx [ $accounting,$from_date,$to_date,$nb_row,$tot_deb,$tot_cred] + */ + public function dataRowNotLettered() + { + $array=array( + ['4400005','01.01.2019','31.12.2019',9,0,954.10] + ,['4400005','01.03.2019','02.05.2019',3,0,246.61] + ); + return $array; + } + /** + * @brief test function Acc_Account_Ledger::get_row_date only unlettered + * @covers Acc_Account_Ledger::get_row_date + * @dataProvider dataRowNotLettered + */ + public function testGetRowDataNotLetted($accounting,$from_date,$to_date,$nb_row,$tot_deb,$tot_cred) + { + global $g_connection; + $g_connection->clear_all_prepare(); + $acc_account_ledger=new Acc_Account_Ledger( $g_connection, $accounting); + $acc_account_ledger->get_row_date(p_from:$from_date,p_to:$to_date,let:2); + $nb_actual_row=count($acc_account_ledger->row); + $this->assertEquals($nb_row,$nb_actual_row,"error received $nb_row rows"); + $this->assertEquals($tot_deb,$acc_account_ledger->tot_deb,"error amount incorrect received ".$acc_account_ledger->tot_deb); + $this->assertEquals($tot_cred,$acc_account_ledger->tot_cred,"error amount incorrect received ".$acc_account_ledger->tot_cred); + } } diff --git a/unit-test/include/class/acc_compute.Test.php b/unit-test/include/class/acc_computeTest.php similarity index 100% rename from unit-test/include/class/acc_compute.Test.php rename to unit-test/include/class/acc_computeTest.php diff --git a/unit-test/include/class/acc_ledgerTest.php b/unit-test/include/class/acc_ledgerTest.php index b6c809913..1f8e3f981 100644 --- a/unit-test/include/class/acc_ledgerTest.php +++ b/unit-test/include/class/acc_ledgerTest.php @@ -901,7 +901,7 @@ class Acc_LedgerTest extends TestCase 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->assertTrue($size == 16044 ," output input_new is not what it is expected"); + $this->assertTrue($size == 16063 ," output input_new is $size not what it is expected"); } diff --git a/unit-test/include/class/acc_ledger_fin.Test.php b/unit-test/include/class/acc_ledger_finTest.php similarity index 100% rename from unit-test/include/class/acc_ledger_fin.Test.php rename to unit-test/include/class/acc_ledger_finTest.php diff --git a/unit-test/include/class/acc_ledger_history_financial.Test.php b/unit-test/include/class/acc_ledger_history_financialTest.php similarity index 100% rename from unit-test/include/class/acc_ledger_history_financial.Test.php rename to unit-test/include/class/acc_ledger_history_financialTest.php diff --git a/unit-test/include/class/databaseTest.class.php b/unit-test/include/class/databaseTest.php similarity index 100% rename from unit-test/include/class/databaseTest.class.php rename to unit-test/include/class/databaseTest.php diff --git a/unit-test/include/class/upgrade176.sql b/unit-test/include/class/upgrade176.sql deleted file mode 100644 index e69de29bb..000000000 diff --git a/unit-test/include/lib/data_sqlTest.php b/unit-test/include/lib/data_sqlTest.php index 72bec5e9d..434c07f20 100644 --- a/unit-test/include/lib/data_sqlTest.php +++ b/unit-test/include/lib/data_sqlTest.php @@ -26,7 +26,7 @@ use PHPUnit\Framework\TestCase; */ require DIRTEST.'/global.php'; -class Currency_SQL extends \Table_Data_SQL +class data_Currency_SQL extends \Table_Data_SQL { function __construct(Database $p_cn, $p_id=-1) @@ -69,7 +69,7 @@ class Data_SQLTest extends TestCase function testBuildObject() { $cn=new \Database(DOSSIER); - $currency_sql = new Currency_SQL($cn,0); + $currency_sql = new data_Currency_SQL($cn,0); $this->assertEquals($currency_sql->cr_code_iso,'EUR','invalid ISO Code'); } /** @@ -79,17 +79,17 @@ class Data_SQLTest extends TestCase { /* insert */ $cn=new \Database(DOSSIER); - $currency_sql = new Currency_SQL($cn); + $currency_sql = new data_Currency_SQL($cn); $currency_sql->cr_code_iso = 'XIU'; $currency_sql->cr_name = 'Currency for UNIT TEST'; $currency_sql->insert(); $this->assertTrue($currency_sql->id > 0,' row not created'); /* update */ - $update_sql = new Currency_SQL($cn,$currency_sql->id); + $update_sql = new data_Currency_SQL($cn,$currency_sql->id); $this->assertTrue($update_sql->cr_code_iso=='XIU'," update can not find row"); $update_sql->cr_name='xxxx'; $update_sql->save(); - $check_sql=new Currency_SQL($cn,$currency_sql->id); + $check_sql=new data_Currency_SQL($cn,$currency_sql->id); $this->assertEquals($check_sql->get('cr_name'),'xxxx','get row not updated'); $this->assertEquals($check_sql->cr_name,'xxxx',' __get row not updated'); $this->assertEquals($check_sql->getp('cr_name'),'xxxx',' getp row not updated'); @@ -107,7 +107,7 @@ class Data_SQLTest extends TestCase { try { $cn=new \Database(DOSSIER); - $currency_sql = new Currency_SQL($cn,0); + $currency_sql = new data_Currency_SQL($cn,0); $a=$currency_sql->dummy; $currency_sql->save(); @@ -122,7 +122,7 @@ class Data_SQLTest extends TestCase { try { $cn=new \Database(DOSSIER); - $currency_sql = new Currency_SQL($cn,0); + $currency_sql = new data_Currency_SQL($cn,0); $currency_sql->get("dummy"); $currency_sql->save(); @@ -137,7 +137,7 @@ class Data_SQLTest extends TestCase { try { $cn=new \Database(DOSSIER); - $currency_sql = new Currency_SQL($cn,0); + $currency_sql = new data_Currency_SQL($cn,0); $currency_sql->getp("dummy"); $currency_sql->save(); @@ -152,7 +152,7 @@ class Data_SQLTest extends TestCase { try { $cn=new \Database(DOSSIER); - $currency_sql = new Currency_SQL($cn,0); + $currency_sql = new data_Currency_SQL($cn,0); $currency_sql->dummy=1; $currency_sql->save(); @@ -167,7 +167,7 @@ class Data_SQLTest extends TestCase { try { $cn=new \Database(DOSSIER); - $currency_sql = new Currency_SQL($cn,0); + $currency_sql = new data_Currency_SQL($cn,0); $currency_sql->set("dummy",1); $currency_sql->save(); @@ -182,7 +182,7 @@ class Data_SQLTest extends TestCase { try { $cn=new \Database(DOSSIER); - $currency_sql = new Currency_SQL($cn,0); + $currency_sql = new data_Currency_SQL($cn,0); $currency_sql->setp("dummy",1); $currency_sql->save(); @@ -190,4 +190,4 @@ class Data_SQLTest extends TestCase $this->assertEquals($ex->getCode(), EXC_DATA_SQL,' get unknow column fails'); } } -} \ No newline at end of file +}
'; $r.=_('Détail opération '); $r.=''; $r.=sprintf ('%s', - $jr_id,dossier::id(),$this->internal); + $jr_id,dossier::id(),$this->jr_internal); $r.='