From 415b7c6307ac8e1cbe506cff5186237528fb6781 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Thu, 26 Dec 2024 11:19:43 +0100 Subject: [PATCH 1/7] Fix : wrong file shown in description --- include/template/follow_up-display.php | 41 ++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/include/template/follow_up-display.php b/include/template/follow_up-display.php index 7a2f54693..1c66b7443 100644 --- a/include/template/follow_up-display.php +++ b/include/template/follow_up-display.php @@ -4,6 +4,39 @@ //see licence.txt $uniq=uniqid("tab",TRUE); $dossier_id=Dossier::id(); +/** + * @var $str_ag_ref string reference of Action inherited Follow_Up::display + * @var $str_doc_type string type of document (DOCUMENT_TYPE) inherited Follow_Up::display + * @var $w ICard concerned tiers inherited Follow_Up::display + * @var $sp ISpan concerned tiers' name inherited Follow_Up::display + * @var $g_user Noalyss_User connected user : global variable + * @var $ag_contact ICard card of contacts inherited Follow_Up::display + * @var $spcontact ISpan contact's name inherited Follow_Up::display + * @var $ag_id Number Follow_Up::ag_id inherited Follow_Up::display + * @var $p_view string mode : READ NEW UPD inherited Follow_Up::display + * @var $str_add_button string for adding event inherited Follow_Up::display + * @var $date IDate inherited Follow_Up::display + * @var $str_ag_hour string Hour inherited Follow_Up::display + * @var $remind_date IDate inherited Follow_Up::display + * @var $str_state string status event inherited Follow_Up::display + * @var $str_ag_priority string priority event inherited Follow_Up::display + * @var $str_ag_dest string group event inherited Follow_Up::display + * @var $this Follow_Up inherited Follow_Up::display + * @var $operation array table ACTION_GESTION_OPERATION inherited Follow_Up::display + * @var $iaction array IRelated_Action inherited Follow_Up::display + * @var $p_base string ac parameter inherited Follow_Up::display + * @var $acomment array comment of event inherited Follow_Up::display + * @var $iconcerned IConcerned concerned operation inherited Follow_Up::display + * @var $title string title action inherited Follow_Up::display + * @var $desc string description of action inherited Follow_Up::display + * @var $upload IFiles file to upkiad + * @var $str_select_doc + * @var $aAttachedFile + * @var $str_submit_generate + * + * + * + */ ?>
0) { $has_description = true; $editable_description = Document_Option::is_enable_editable_description($this->dt_id); @@ -352,8 +387,8 @@ function small(p_id_textarea){ // link to files to download $aFile=$this->db->get_array('select d_id,d_filename,d_description,d_mimetype from action_comment_document - join document on (d_id=document_id) where action_gestion_comment_id=$1' - , array($this->ag_id)); + join document on (d_id=document_id) where ag_id=$1' + , array($acomment[0]['agc_id'])); if ( ! empty ($aFile)) { echo '
'; echo _("Fichiers :"); @@ -362,7 +397,7 @@ function small(p_id_textarea){ $url="export.php?".http_build_query(array("act"=>'RAW:document' ,"gDossier"=>$dossier_id ,"d_id"=>$file["d_id"])); - printf('%s', + printf('%s', $url,h($file['d_filename'])); } From 3fe64ba9e19dbf75ba186fc9910aef20441e6444 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Thu, 26 Dec 2024 12:34:57 +0100 Subject: [PATCH 2/7] Cosmetic : hightlight element in follow-up and plugin --- html/css/style-classic7.css | 10 ++++++++++ include/cfgplugin.inc.php | 4 ++-- include/template/follow_up-display.php | 6 ++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/html/css/style-classic7.css b/html/css/style-classic7.css index c7beae097..c7e3804dd 100644 --- a/html/css/style-classic7.css +++ b/html/css/style-classic7.css @@ -517,6 +517,16 @@ tr.highlight { font-weight: bold; } +/* highlight a small element (span) + */ + .cell.highlight { + color: darkred !important; + background-color: lightgoldenrodyellow; + color: antiquewhite !important; + background-color: lightskyblue; + padding: 2px 10px 2px 10px; + } + td.odd{ background-color:#DDE6FF; } diff --git a/include/cfgplugin.inc.php b/include/cfgplugin.inc.php index 578f73736..8445d9575 100644 --- a/include/cfgplugin.inc.php +++ b/include/cfgplugin.inc.php @@ -103,9 +103,9 @@ $nb_profile=count($a_profile); me_description);?> - + depend); + printf(_("Installé par défaut dans le menu AD: %s "),$a_plugin[$e]->depend); ?> diff --git a/include/template/follow_up-display.php b/include/template/follow_up-display.php index 1c66b7443..e651f8918 100644 --- a/include/template/follow_up-display.php +++ b/include/template/follow_up-display.php @@ -585,8 +585,10 @@ catch(exception) { alert('

0)?"cell highlight":""; + printf('%s (%s)',$a,$class,count($aAttachedFile)); ?>

From d25e56c1c4ab6126a2535366466bd0d406d917c2 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Thu, 26 Dec 2024 13:33:07 +0100 Subject: [PATCH 3/7] improve : HtmlInput::filter_table filtre instead of Recherche --- include/lib/html_input.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/lib/html_input.class.php b/include/lib/html_input.class.php index 1cea9dd0d..bfdb2b10b 100755 --- a/include/lib/html_input.class.php +++ b/include/lib/html_input.class.php @@ -1021,7 +1021,7 @@ class HtmlInput $r=" - + "; @@ -1041,7 +1041,7 @@ class HtmlInput - + "; From 4ff5243aef9eecf5092405c8bfbc522f58b88d00 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Fri, 27 Dec 2024 17:23:06 +0100 Subject: [PATCH 4/7] =?UTF-8?q?Bug=20#2400:=20TVA=20Non=20d=C3=A9ductible?= =?UTF-8?q?=20et=20TVA=20autoliquidation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/class/acc_compute.class.php | 6 +- include/class/acc_ledger_purchase.class.php | 71 ++++++--------- unit-test/include/class/acc_compute.Test.php | 2 +- .../include/class/acc_ledger_purchaseTest.php | 88 +++++++++++++++---- unit-test/include/class/followupTest.php | 2 +- 5 files changed, 106 insertions(+), 63 deletions(-) diff --git a/include/class/acc_compute.class.php b/include/class/acc_compute.class.php index e6a390548..2a8f2ec22 100644 --- a/include/class/acc_compute.class.php +++ b/include/class/acc_compute.class.php @@ -48,6 +48,7 @@ 'nd_vat_rate'=>'nd_vat_rate', 'amount_perso'=>'amount_perso', 'amount_perso_rate'=>'amount_perso_rate' ); + * 'autoreverse'=>'autoreverse' */ @@ -68,7 +69,8 @@ class Acc_Compute 'amount_perso_rate'=>'amount_perso_rate', 'amount_currency'=>'amount_currency', 'amount_vat_currency'=>'amount_vat_currency', - 'currency_rate'=>'currency_rate' + 'currency_rate'=>'currency_rate', + 'autoreverse'=>'autoreverse' ); private $order; // check that the compute @@ -196,7 +198,7 @@ class Acc_Compute } - /**! + /*! * \brief verify that all the amount are positive or null * otherwise throw a exception and the sum of amount + vat must * equal to the sum of all the amount of the current object diff --git a/include/class/acc_ledger_purchase.class.php b/include/class/acc_ledger_purchase.class.php index 6c1c6031c..cae6349fa 100644 --- a/include/class/acc_ledger_purchase.class.php +++ b/include/class/acc_ledger_purchase.class.php @@ -556,22 +556,18 @@ class Acc_Ledger_Purchase extends Acc_Ledger bcscale(4); // variable : $tot_amount float : total amount of the purchase (debit) $tot_amount=0; + // variable : $tot_tva float : total amount of the VAT $tot_tva=0; + // variable: $tot_debit float : amount on debit side $tot_debit=0; + $this->db->start(); - // variable : $tot_nd float total not Deductible - $tot_nd=0; - // variable : $tot_perso float total private amount - $tot_perso=0; - // variable : $tot_tva_nd float total vat not deductible - $tot_tva_nd=0; - // variable : $tot_tva_ndded float total vat not deductible - deductible via another tax - $tot_tva_ndded=0; - $tot_tva_reversed=0; //@todo to remove + // variable: $tot_tva_reversed float total VAT autoreverse, to deduce from supplier's amount + $tot_tva_reversed=0; // variable : $tva array that will contain all the VAT Amount $tva=array(); @@ -579,6 +575,9 @@ class Acc_Ledger_Purchase extends Acc_Ledger // variable : $tva_reverse array that contain all the VAT autoreverse AND negative $tva_reverse = array(); + // variable : $tva_reverse_credit array that contain all the VAT autoreverse for credit + $tva_reverse_credit = array(); + // variable : $tot_amount_cur : total amount in currency $tot_amount_cur=0; @@ -600,7 +599,6 @@ class Acc_Ledger_Purchase extends Acc_Ledger if ($g_parameter->MY_TVA_USE=='Y') { $idx_tva=trim(${'e_march'.$i.'_tva_id'}); - \Noalyss\Dbg::echo_var(1," idx_tva [$idx_tva]",); $oTva=Acc_Tva::build($this->db,$idx_tva); $oTva->load(); @@ -650,13 +648,16 @@ class Acc_Ledger_Purchase extends Acc_Ledger /* compute ND */ + // variable: $save_amount_vat total float amount of VAT before changing due to NOT DEDUCTIBLE $save_amount_vat=$acc_amount->amount_vat; $this->compute_no_deductible($acc_amount, $fiche); $acc_amount->correct(); - // TVA which avoid - $acc_amount->amount_unpaid=($tva_both == 1 ) ? $save_amount_vat :0 ; - $tot_tva_reversed=bcadd($tot_tva_reversed,$acc_amount->amount_unpaid); - + // TVA which avoid + if ( $tva_both == 1 ) { + $acc_amount->autoreverse=$save_amount_vat; + $tot_tva_reversed=bcadd($tot_tva_reversed,$save_amount_vat); + } + $tot_amount=round(bcadd($tot_amount,$acc_amount->amount),2); @@ -700,13 +701,16 @@ class Acc_Ledger_Purchase extends Acc_Ledger if ( $g_parameter->MY_TVA_USE=='Y') { $tva_item=$acc_amount->amount_vat; - $tva[$idx_tva]=(isset( $tva[$idx_tva]))? $tva[$idx_tva]:0; - if ($tva_both == 0 || $tva_item >= 0){ + + if ($tva_both == 0 ){ + $tva[$idx_tva]=(isset( $tva[$idx_tva]))? $tva[$idx_tva]:0; $tva[$idx_tva]=bcadd($tva[$idx_tva], $tva_item); }else { // $tva_item < 0 && $tva_both == 1 $tva_reverse[$idx_tva]=(isset($tva_reverse[$idx_tva]))?$tva_reverse[$idx_tva]:0; $tva_reverse[$idx_tva]=bcadd($tva_item,$tva_reverse[$idx_tva]); + $tva_reverse_credit[$idx_tva]=(isset($tva_reverse_credit[$idx_tva]))?$tva_reverse_credit[$idx_tva]:0; + $tva_reverse_credit[$idx_tva]=bcadd($save_amount_vat,$tva_reverse_credit[$idx_tva]); } } /* Save the stock */ @@ -760,7 +764,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger ,$acc_amount->nd_ded_vat /* 10 */ ,$acc_amount->amount_perso /* 11 */ ,$e_client /* 12 */ - , $acc_amount->amount_unpaid /*13*/ + , $acc_amount->autoreverse /*13*/ ,$price_euro /* 14 */ )); @@ -783,7 +787,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger ,$acc_amount->nd_ded_vat /* 10 */ ,$acc_amount->amount_perso /* 11 */ ,$e_client /* 12 */ - , $acc_amount->amount_unpaid /*13*/ + , $acc_amount->autoreverse /*13*/ ,$price_euro /* 14 */ )); } @@ -890,30 +894,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger $acc_operation->type='d'; $acc_operation->periode=$tperiode; if ( $value > 0 ) $tot_debit=bcadd($tot_debit,abs($value)); - if ( $oTva->get_parameter("both_side") == 1 && $value ==0 ) continue; $acc_operation->insert_jrnx(); - // if TVA is on both side, we deduce it immediately - - if ( $oTva->get_parameter("both_side")==1 ) - { - // $x temp variable is the tva_reverse_account and will be used to check $poste_vat - $x=$oTva->get_parameter("tva_reverse_account"); - $poste_vat =(trim($x??"")=="")? $oTva->get_side('c'):$x; - if ( $poste_vat == '#') - { - $poste_vat=$oTva->get_side('d'); - } - $acc_operation=new Acc_Operation($this->db); - $acc_operation->date=$e_date; - $acc_operation->poste=$poste_vat; - $acc_operation->amount=$value; - $acc_operation->grpt=$seq; - $acc_operation->jrn=$p_jrn; - $acc_operation->type='c'; - $acc_operation->periode=$tperiode; - $acc_operation->insert_jrnx(); - //if ( $value < 0 ) $tot_debit=bcadd($tot_debit,abs($value)); - } } // LOOP : foreach $tva foreach ($tva_reverse as $i => $value) { @@ -936,7 +917,10 @@ class Acc_Ledger_Purchase extends Acc_Ledger $acc_operation->insert_jrnx(); // if TVA is on both side, we deduce it immediately - $poste_vat = $oTva->get_side('c'); + // $x temp variable is the tva_reverse_account and will be used to check $poste_vat + $x=$oTva->get_parameter("tva_reverse_account"); + $poste_vat =(trim($x??"")=="")? $oTva->get_side('c'):$x; + if ( $poste_vat == '#') { $poste_vat=$oTva->get_side('d'); @@ -944,7 +928,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger $acc_operation = new Acc_Operation($this->db); $acc_operation->date = $e_date; $acc_operation->poste = $poste_vat; - $acc_operation->amount = $value; + $acc_operation->amount = $tva_reverse_credit[$i]; $acc_operation->grpt = $seq; $acc_operation->jrn = $p_jrn; $acc_operation->type = 'c'; @@ -952,7 +936,6 @@ class Acc_Ledger_Purchase extends Acc_Ledger $acc_operation->insert_jrnx(); $tot_debit = bcadd($tot_debit, $value); $tot_debit = round($tot_debit, 2); - $n_both = $value; } //LOOP: foreach $tva_reverse } diff --git a/unit-test/include/class/acc_compute.Test.php b/unit-test/include/class/acc_compute.Test.php index 87b90e152..5065de633 100644 --- a/unit-test/include/class/acc_compute.Test.php +++ b/unit-test/include/class/acc_compute.Test.php @@ -189,7 +189,7 @@ class Acc_ComputeTest extends TestCase $result=ob_get_contents(); ob_end_clean(); $this->assertStringStartsWith("key amount Description amount value is 0
key amount_vat Description amount_vat value is 0
",$result); - $this->assertStringEndsWith("
key amount_vat_currency Description amount_vat_currency value is 0
key currency_rate Description currency_rate value is 0
",$result); + $this->assertStringEndsWith("
key amount_vat_currency Description amount_vat_currency value is 0
key currency_rate Description currency_rate value is 0
key autoreverse Description autoreverse value is 0
",$result); } public function testCompute() diff --git a/unit-test/include/class/acc_ledger_purchaseTest.php b/unit-test/include/class/acc_ledger_purchaseTest.php index 8d9e292c1..d3a7ab25c 100644 --- a/unit-test/include/class/acc_ledger_purchaseTest.php +++ b/unit-test/include/class/acc_ledger_purchaseTest.php @@ -448,10 +448,11 @@ class Acc_Ledger_PurchaseTest extends TestCase /** * @testdox Purchase not deductible : VAT , TAX , PRIVATE fee * @dataProvider data_no_deductible - * Parameters : $p_attribut if the no deductible attribute, the $p_value is the % not deductible, $p_amount - * is the corresponding column in quant_purchase and $p_accounting is the counterpart - * for this not deductible fee($p_counterpart) - */ + * @parameter $p_attribut int ATTR_DEF.AD_ID $p_attribut if the no deductible attribute, + * @parameter $p_value int is the % not deductible, + * @parameter $p_amount float the corresponding column in quant_purchase + * @parameter $p_accounting string is the accounting counterpart for this not deductible fee($p_counterpart) + */ public function testInsertPurchase_No_Ded($p_attribut , $p_value,$p_column,$p_amount,$p_counterpart,$p_accounting) { global $g_connection; @@ -497,7 +498,63 @@ class Acc_Ledger_PurchaseTest extends TestCase } + /** + * @testdox Purchase not deductible + autoreverse: VAT , TAX , PRIVATE fee with VAT autoreverse + * @dataProvider data_no_deductible + * @parameter $p_attribut int ATTR_DEF.AD_ID $p_attribut if the no deductible attribute, + * @parameter $p_value int is the % not deductible, + * @parameter $p_amount float the corresponding column in quant_purchase + * @parameter $p_accounting string is the accounting counterpart for this not deductible fee($p_counterpart) + */ + public function testInsertPurchase_No_Ded_reverse($p_attribut , $p_value,$p_column,$p_amount,$p_counterpart,$p_accounting) + { + global $g_connection; + static $scenario=0; + $scenario++; + + //-- modify card 29 : ELECTR + $fiche=new Fiche($g_connection,29); + $fiche->set_f_enable("1"); + $fiche->setAttribut($p_attribut,$p_value); + $fiche->setAttribut($p_counterpart,$p_accounting); + $a_attribut=$fiche->to_array(); + $this->assertEquals($a_attribut['av_text'.$p_attribut],$p_value,"Attribut $p_attribut not set to $p_value%"); + + $fiche->update($a_attribut); + + $this->assertEquals($p_value, + $g_connection->get_value("select ad_value + from fiche_detail + where f_id=$1 and ad_id=$2",[29,$p_attribut]), + "Attribut ad_id $p_attribut not inserted"); + + $array=$this->array; + $array['e_comm']="scenario [$scenario]"; + $array['e_march0']='ELECTR'; + $array['e_march0_tva_id']='5'; + $array['tva_march0']=bcmul($array['e_march0_tva_amount'],0.21,2); + $array['tvac_march0']=bcmul ($array['htva_march0'],1.21,2); + $array['mt']='no-ded-33'.$scenario; + $this->clean_operation($array['mt']); + + $this->object->insert($array); + + $row_quant=$g_connection->get_row("select * from quant_purchase where qp_internal in + ( select jr_internal from jrn where jr_mt=$1)",[$array["mt"]]); + $this->assertFalse(empty($row_quant)," row not inserted in quant_purchase"); + + // unit price not rounded + $this->assertEquals(603.8990,$row_quant['qp_unit']); + + // rounded to 2 decimal + $this->assertEquals(603.9000,$row_quant['qp_price']); + $this->assertEquals($p_amount,$row_quant[$p_column]); + + $this->clean_operation($array['mt']); + + + } /** * @covers Acc_Ledger_Purchase::input */ @@ -706,22 +763,22 @@ class Acc_Ledger_PurchaseTest extends TestCase select count(*) from jrnx j1 join jrn j2 on (j1.j_grpt=j2.jr_grpt_id) where - j2.jr_mt ='1572704002.1732' + j2.jr_mt = $1 and j1.j_poste ='4119999' and j1.j_debit ='f' "; - $this->assertEquals(1, $g_connection->get_value($sql),'fails : reversed account credit is wrong'); + $this->assertEquals(1, $g_connection->get_value($sql,[$array["mt"]]),'fails : reversed account credit is wrong'); // check that the accounting for reverse VAT is only 45142 $sql=" select count(*) from jrnx j1 join jrn j2 on (j1.j_grpt=j2.jr_grpt_id) where - j2.jr_mt ='1572704002.1732' + j2.jr_mt = $1 and j1.j_poste ='41142' and j1.j_debit ='t' "; - $this->assertEquals(1, $g_connection->get_value($sql),'fails : reversed account credit is wrong'); + $this->assertEquals(1, $g_connection->get_value($sql,[$array["mt"]]),'fails : reversed account credit is wrong'); $this->clean_operation(); @@ -735,12 +792,13 @@ class Acc_Ledger_PurchaseTest extends TestCase function testInsertReverseVAT4() { global $g_connection; $array=$this->array1; + $array['mt']='testInsertReverseVAT4'; $old_autoreverse=$g_connection->get_value("select tva_both_side from tva_rate where tva_id=3 "); // set autoreverse to 1 $g_connection->get_value("update tva_rate set tva_both_side = 1 where tva_id=3 "); // clean - $g_connection->exec_sql("delete from jrn where jr_mt=$1",[1734717784.385]); + $g_connection->exec_sql("delete from jrn where jr_mt=$1",[ $array['mt'] ]); $this->object->insert($array); $accounting=new \Acc_Operation($g_connection); @@ -768,7 +826,7 @@ class Acc_Ledger_PurchaseTest extends TestCase // cancel change $g_connection->get_value("update tva_rate set tva_both_side = $1 where tva_id=3 ",[$old_autoreverse]); - $g_connection->exec_sql("delete from jrn where jr_mt=$1",[1734717784.385]); + $g_connection->exec_sql("delete from jrn where jr_mt=$1",[$array['mt']]); } @@ -782,22 +840,23 @@ class Acc_Ledger_PurchaseTest extends TestCase $array=$this->array1; $array['e_march1_tva_id']=5; + $array['mt']='testInsertReverseVAT5'; // clean - $g_connection->exec_sql("delete from jrn where jr_mt=$1",[1734717784.385]); + $g_connection->exec_sql("delete from jrn where jr_mt=$1",[ $array['mt'] ]); $this->object->insert($array); $accounting=new \Acc_Operation($g_connection); $accounting->jr_id=$this->object->jr_id; $aResult=$accounting->get_jrnx_detail(); - $this->assertTrue(count($aResult)==7, 'Number of rows is '.count($aResult)."instead of 7"); + $this->assertTrue(count($aResult)==5, 'Number of rows is '.count($aResult)."instead of 5"); foreach($aResult as $result) { switch ($result['j_poste']) { case '41142': if ( $result['debit']=='D') - $this->assertEquals(25.20, $result['j_montant'],"erreur account {$result['j_poste']}"); + $this->assertEquals(23.10, $result['j_montant'],"erreur account {$result['j_poste']}"); else $this->assertEquals(2.1, $result['j_montant'],"erreur account {$result['j_poste']}"); break; @@ -814,8 +873,7 @@ class Acc_Ledger_PurchaseTest extends TestCase } // cancel change - - $g_connection->exec_sql("delete from jrn where jr_mt=$1",[1734717784.385]); + $g_connection->exec_sql("delete from jrn where jr_mt=$1",[ $array['mt'] ]); } diff --git a/unit-test/include/class/followupTest.php b/unit-test/include/class/followupTest.php index 06cf94116..98a99981e 100644 --- a/unit-test/include/class/followupTest.php +++ b/unit-test/include/class/followupTest.php @@ -137,7 +137,7 @@ class FollowupTest extends TestCase $content=ob_get_contents(); ob_end_clean(); $this->assertStringContainsString("BONDEC3-1", $content); - $this->assertTrue(mb_strlen($content)==1613,"error result not valid $content size = ".mb_strlen($content)); + $this->assertTrue(mb_strlen($content)==1620,"error result not valid $content size = ".mb_strlen($content)); } From 7731305ab805e4ddd50482fd6d585073d97d8c1a Mon Sep 17 00:00:00 2001 From: sparkyx Date: Sat, 28 Dec 2024 11:16:31 +0100 Subject: [PATCH 5/7] Improve Exception for accountancy ACH, VEN, ODS, FIN --- include/class/acc_ledger.class.php | 6 +-- include/class/acc_ledger_fin.class.php | 10 ++--- include/class/acc_ledger_purchase.class.php | 15 ++----- include/class/acc_ledger_sale.class.php | 12 ++---- include/compta_ach.inc.php | 11 ++++- include/compta_fin.inc.php | 11 ++++- include/compta_ven.inc.php | 13 +++++- include/constant.php | 6 +-- include/lib/ac_common.php | 48 +++++++++++++++++---- log/.htaccess | 3 ++ log/index.html | 1 + 11 files changed, 92 insertions(+), 44 deletions(-) create mode 100644 log/.htaccess create mode 100644 log/index.html diff --git a/include/class/acc_ledger.class.php b/include/class/acc_ledger.class.php index ca9223c9f..fcb28f12d 100644 --- a/include/class/acc_ledger.class.php +++ b/include/class/acc_ledger.class.php @@ -1644,11 +1644,9 @@ class Acc_Ledger extends jrn_def_sql } catch (Exception $e) { - record_log($e); + record_log($e); $this->db->rollback(); - echo _('OPERATION ANNULEE '); - echo '
'; - echo __FILE__.__LINE__.$e->getMessage(); + echo_warning(_('OPERATION ANNULEE voir log')); exit(); } $this->db->commit(); diff --git a/include/class/acc_ledger_fin.class.php b/include/class/acc_ledger_fin.class.php index 153000c69..3e5206221 100644 --- a/include/class/acc_ledger_fin.class.php +++ b/include/class/acc_ledger_fin.class.php @@ -979,6 +979,9 @@ class Acc_Ledger_Fin extends Acc_Ledger $acc_operation->pj=$e_pj; $jr_id=$acc_operation->insert_jrn(); + if ( $jr_id == false ) + throw new Exception (_("Erreur de balance"),EXC_BALANCE); + // $acc_operation->update_receipt(); $this->db->exec_sql('update jrn set jr_pj_number=$1 where jr_id=$2', array($acc_operation->pj, $jr_id)); $internal=$this->compute_internal_code($seq); @@ -1096,13 +1099,10 @@ class Acc_Ledger_Fin extends Acc_Ledger } catch (Exception $e) { - $r=''. - 'Erreur dans l\'enregistrement '. - __FILE__.':'.__LINE__.' '. - $e->getMessage(); + $this->db->rollback(); record_log($e); - throw new Exception($r); + throw $e; } $this->db->commit(); if ($acc_currency->get_id()==0) diff --git a/include/class/acc_ledger_purchase.class.php b/include/class/acc_ledger_purchase.class.php index cae6349fa..afbe7e8ab 100644 --- a/include/class/acc_ledger_purchase.class.php +++ b/include/class/acc_ledger_purchase.class.php @@ -946,10 +946,6 @@ class Acc_Ledger_Purchase extends Acc_Ledger // Total DEB $acc_operation->amount=$this->db->get_value("select sum(j_montant) from jrnx where j_grpt = $1 and j_debit='t'", array($seq)); - if ( DEBUGNOALYSS > 1 ) { - echo __LINE__." amount ".$acc_operation->amount."
"; - - } $acc_operation->desc=$e_comm; $acc_operation->grpt=$seq; $acc_operation->jrn=$p_jrn; @@ -961,7 +957,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger $acc_operation->currency_rate_ref=$currency_rate_ref->get_rate(); if ( ! $this->jr_id=$acc_operation->insert_jrn() ) { - throw new Exception (_("Erreur de balance")); + throw new Exception (_("Erreur de balance"),EXC_BALANCE); } $this->pj=$acc_operation->update_receipt(); @@ -1145,14 +1141,9 @@ class Acc_Ledger_Purchase extends Acc_Ledger }//end try catch (Exception $e) { - record_log($e); - echo ''. - 'Erreur dans l\'enregistrement '. - __FILE__.':'.__LINE__.' '. - $e->getMessage().$e->getMessage(); - record_log($e->getMessage()); + record_log($e); $this->db->rollback(); - throw new Exception($e); + throw $e; } $this->db->commit(); return $internal; diff --git a/include/class/acc_ledger_sale.class.php b/include/class/acc_ledger_sale.class.php index 1888669fc..8dca652e3 100644 --- a/include/class/acc_ledger_sale.class.php +++ b/include/class/acc_ledger_sale.class.php @@ -678,7 +678,7 @@ class Acc_Ledger_Sale extends Acc_Ledger { $acc_operation->currency_rate_ref=$currency_rate_ref->get_rate(); if ( ! $this->jr_id=$acc_operation->insert_jrn() ) { - throw new Exception (_("Erreur de balance")); + throw new Exception (_("Erreur de balance"),EXC_BALANCE); } $this->pj = $acc_operation->update_receipt(); @@ -856,15 +856,9 @@ class Acc_Ledger_Sale extends Acc_Ledger { $acc_operation_note->save(); } } catch (Exception $e) { - record_log($e); - echo '' . - 'Erreur dans l\'enregistrement ' . - __FILE__ . ':' . __LINE__ . ' ' . - $e->getMessage(); - echo $e->getTraceAsString(); - + record_log($e); $this->db->rollback(); - throw new Exception ($e); + throw $e; } $this->db->commit(); diff --git a/include/compta_ach.inc.php b/include/compta_ach.inc.php index 7b60dc67b..b1389ccb8 100644 --- a/include/compta_ach.inc.php +++ b/include/compta_ach.inc.php @@ -105,7 +105,16 @@ if (isset($_POST['record'])) echo '
'; $Ledger = new Acc_Ledger_Purchase($cn, $post_jrn); - $internal = $Ledger->insert($_POST); + + try { + $internal = $Ledger->insert($_POST); + } catch (\Exception $e) { + if ( $e->getCode()==EXC_BALANCE) + echo_warning(_("enregistrement annulé: balance , voyer le fichier log")); + else + echo_warning($e->getMessage()); + return; + } /* Save the predefined operation */ diff --git a/include/compta_fin.inc.php b/include/compta_fin.inc.php index 7ef5b2944..e9d853ee9 100644 --- a/include/compta_fin.inc.php +++ b/include/compta_fin.inc.php @@ -116,7 +116,16 @@ if ( isset($_POST['confirm'])) echo '
'; echo '
'; - $a= $Ledger->insert($_POST); + try { + $a= $Ledger->insert($_POST); + + } catch (\Exception $e) { + if ( $e->getCode()==EXC_BALANCE) + echo_warning(_("enregistrement annulé: balance , voyer le fichier log")); + else + echo_warning($e->getMessage()); + return; + } echo '

'._('Enregistrement').'

'; echo '
'; echo $a; diff --git a/include/compta_ven.inc.php b/include/compta_ven.inc.php index 9943602d8..c904f2130 100644 --- a/include/compta_ven.inc.php +++ b/include/compta_ven.inc.php @@ -122,7 +122,18 @@ if ( isset($_POST['record']) ) echo '
'; $Ledger=new Acc_Ledger_Sale($cn,$_POST['p_jrn']); - $internal=$Ledger->insert($_POST); + try { + $internal=$Ledger->insert($_POST); + + } + catch (\Exception $e) { + if ( $e->getCode()==EXC_BALANCE) + echo_warning(_("enregistrement annulé: balance , voyer le fichier log")); + else + echo_warning($e->getMessage()); + return; + } + /* Save the predefined operation */ if ( isset($_POST['opd_name']) && trim($_POST['opd_name']) != "" ) diff --git a/include/constant.php b/include/constant.php index 806867ebb..88ce881ac 100644 --- a/include/constant.php +++ b/include/constant.php @@ -113,9 +113,6 @@ if (!defined('LOGINPUT')) { define("LOGINPUT", false); } -if (!defined('DEBUGNOALYSS')) { - define('DEBUGNOALYSS', 0); -} $version_noalyss = NOALYSS_VERSION; // If you don't want to be notified of the update @@ -158,6 +155,7 @@ if (DEBUGNOALYSS == 0) { ini_set("html_errors", 0); ini_set('log_errors', 1); ini_set('log_errors_max_len', 0); + if(function_exists('xdebug_disable')) { xdebug_disable(); } } elseif (DEBUGNOALYSS == 1) { /* DEVELOPPEMENT : display all errors warning notice deprecated ...*/ error_reporting(2147483647); @@ -347,6 +345,8 @@ define('EXC_PARAM_TYPE', 1006); define('EXC_DUPLICATE', 1200); define('EXC_INVALID', 1400); define('EXC_FORBIDDEN', 1500); +// exception when balance is incorrect when saving an operation +define('EXC_BALANCE', 1501); define("UNPINDG", ""); define("PINDG", ""); diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php index 588d06292..103123d97 100644 --- a/include/lib/ac_common.php +++ b/include/lib/ac_common.php @@ -1335,22 +1335,54 @@ function is_msie() return $is_msie; } /** - *@brief Record an error message into the log file of the server. + *@brief Record an error message into the log file of the server or in the log folder of NOALYSS * Record also the GET and POST data - * @param string $p_message + * @param $p_message string message to display */ function record_log($p_message) { - if ( gettype ($p_message) == "object" && method_exists($p_message,"getTraceAsString") == 1) { + $date=date('d.m.y'); + // variable: $handle_log resource on log file , + $handle_log=fopen(NOALYSS_BASE."/log/noalyss-{$date}.log","a+"); - error_log("noalyss exception ".$p_message->getMessage(),0); - error_log("noalyss exception".$p_message->getTraceAsString(),0); + if ($handle_log == false ) + { + + if ( gettype ($p_message) == "object" && method_exists($p_message,"getTraceAsString") == 1) { + + error_log("noalyss exception ".$p_message->getMessage(),0); + error_log("noalyss exception".$p_message->getTraceAsString(),0); + } else { + error_log("noalyss".var_export($p_message,true),0); + + } + error_log("noalyss GET [".json_encode($_GET,0,10)."]"); + error_log("_POST [".json_encode($_POST,0,10)."]",0); } else { - error_log("noalyss".var_export($p_message,true),0); + $now=date('y-m-d H:i'); + fwrite ($handle_log,str_repeat("=", 80)."\n"); + fwrite ($handle_log,"ERROR: {$now}\n"); + fwrite($handle_log,"noalyss GET [".var_export($_GET,true)."]"); + fwrite ($handle_log,"\n"); + fwrite($handle_log,"_POST [".var_export($_POST,true)."]"); + fwrite ($handle_log,"\n"); + if ( gettype ($p_message) == "object" && method_exists($p_message,"getTraceAsString") == 1) { + + fwrite($handle_log,"noalyss exception ".$p_message->getMessage()); + fwrite ($handle_log,"\n"); + fwrite($handle_log,"noalyss exception".$p_message->getTraceAsString()); + fwrite ($handle_log,"\n"); + } else { + fwrite($handle_log,"noalyss".var_export($p_message,true)); + fwrite ($handle_log,"\n"); + + } + + fwrite ($handle_log,str_repeat("=", 80)."\n"); + } - error_log("noalyss GET [".json_encode($_GET,0,10)."]"); - error_log("_POST [".json_encode($_POST,0,10)."]",0); + } if(!function_exists('tracedebug')) { function tracedebug($file,$var, $label = NULL) { diff --git a/log/.htaccess b/log/.htaccess new file mode 100644 index 000000000..a83451a72 --- /dev/null +++ b/log/.htaccess @@ -0,0 +1,3 @@ +order deny,allow +deny from all + diff --git a/log/index.html b/log/index.html new file mode 100644 index 000000000..e32ba3b84 --- /dev/null +++ b/log/index.html @@ -0,0 +1 @@ +

LOGFILE

From 232aa9c4aa205abddb4fbadf21a14d58c378a09d Mon Sep 17 00:00:00 2001 From: sparkyx Date: Sat, 28 Dec 2024 12:34:56 +0100 Subject: [PATCH 6/7] improve record_log : add info in default syslog --- include/lib/ac_common.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php index 103123d97..15214a7a7 100644 --- a/include/lib/ac_common.php +++ b/include/lib/ac_common.php @@ -1359,6 +1359,15 @@ function record_log($p_message) error_log("noalyss GET [".json_encode($_GET,0,10)."]"); error_log("_POST [".json_encode($_POST,0,10)."]",0); } else { + if ( gettype ($p_message) == "object" && method_exists($p_message,"getTraceAsString") == 1) { + + error_log("noalyss exception ".$p_message->getMessage(),0); + error_log("noalyss exception".$p_message->getTraceAsString(),0); + } else { + error_log("noalyss".var_export($p_message,true),0); + + } + $now=date('y-m-d H:i'); fwrite ($handle_log,str_repeat("=", 80)."\n"); fwrite ($handle_log,"ERROR: {$now}\n"); From 622926dbddaf2e56ca18110933cbcaf6573e1f6f Mon Sep 17 00:00:00 2001 From: Dany wm DB Date: Wed, 1 Nov 2023 22:28:58 +0100 Subject: [PATCH 7/7] Code documentation --- include/company.inc.php | 2 +- include/compta_fin_saldo.inc.php | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/company.inc.php b/include/company.inc.php index 8da5be4ec..c7e0328c4 100644 --- a/include/company.inc.php +++ b/include/company.inc.php @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // Copyright Author Dany De Bontridder danydb@aevalys.eu -/* ! +/*! * \file * \brief Manage the company setting : address, vat number, Check period, VAT, * CA .... diff --git a/include/compta_fin_saldo.inc.php b/include/compta_fin_saldo.inc.php index 7e90935a8..1f5745ee7 100644 --- a/include/compta_fin_saldo.inc.php +++ b/include/compta_fin_saldo.inc.php @@ -20,9 +20,8 @@ // Copyright Author Dany De Bontridder danydb@aevalys.eu -/* * \file - * - * +/** + * \file * \brief show bank saldo * */