From 5f33bc1bd367fdf7ed6c078caf916998a8a1da89 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Sat, 28 Dec 2024 11:16:31 +0100 Subject: [PATCH] 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 | 19 +++----- 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, 94 insertions(+), 46 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 715ae6f76..b838dfa0e 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 394284953..041771f51 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 3ec18b01b..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; @@ -1272,7 +1263,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger $add_js=""; if ( $g_parameter->MY_PJ_SUGGEST !='N') { - $add_js="update_pj();"; + $add_js="update_receipt();"; } if ($g_parameter->MY_DATE_SUGGEST == 'Y') { @@ -1565,7 +1556,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger /* if we suggest the pj n# the run the script */ if ( $g_parameter->MY_PJ_SUGGEST !='N') { - $r.=''; + $r.=''; } // set focus on date $r.= create_script("$('".$Date->id."').focus()"); diff --git a/include/class/acc_ledger_sale.class.php b/include/class/acc_ledger_sale.class.php index 9ade61786..5a3d5c8c2 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 f0eafa255..c0aca1a2e 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 ea4f25a8b..a49393aa8 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 9b5a2a87a..83f9d36f6 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