Improve Exception for accountancy ACH, VEN, ODS, FIN

This commit is contained in:
sparkyx 2024-12-28 11:16:31 +01:00
parent d15e85649d
commit 5f33bc1bd3
11 changed files with 94 additions and 46 deletions

View file

@ -1644,11 +1644,9 @@ class Acc_Ledger extends jrn_def_sql
} }
catch (Exception $e) catch (Exception $e)
{ {
record_log($e); record_log($e);
$this->db->rollback(); $this->db->rollback();
echo _('OPERATION ANNULEE '); echo_warning(_('OPERATION ANNULEE voir log'));
echo '<hr>';
echo __FILE__.__LINE__.$e->getMessage();
exit(); exit();
} }
$this->db->commit(); $this->db->commit();

View file

@ -979,6 +979,9 @@ class Acc_Ledger_Fin extends Acc_Ledger
$acc_operation->pj=$e_pj; $acc_operation->pj=$e_pj;
$jr_id=$acc_operation->insert_jrn(); $jr_id=$acc_operation->insert_jrn();
if ( $jr_id == false )
throw new Exception (_("Erreur de balance"),EXC_BALANCE);
// $acc_operation->update_receipt(); // $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)); $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); $internal=$this->compute_internal_code($seq);
@ -1096,13 +1099,10 @@ class Acc_Ledger_Fin extends Acc_Ledger
} }
catch (Exception $e) catch (Exception $e)
{ {
$r='<span class="error">'.
'Erreur dans l\'enregistrement '.
__FILE__.':'.__LINE__.' '.
$e->getMessage();
$this->db->rollback(); $this->db->rollback();
record_log($e); record_log($e);
throw new Exception($r); throw $e;
} }
$this->db->commit(); $this->db->commit();
if ($acc_currency->get_id()==0) if ($acc_currency->get_id()==0)

View file

@ -946,10 +946,6 @@ class Acc_Ledger_Purchase extends Acc_Ledger
// Total DEB // Total DEB
$acc_operation->amount=$this->db->get_value("select sum(j_montant) from jrnx where j_grpt = $1 and j_debit='t'", $acc_operation->amount=$this->db->get_value("select sum(j_montant) from jrnx where j_grpt = $1 and j_debit='t'",
array($seq)); array($seq));
if ( DEBUGNOALYSS > 1 ) {
echo __LINE__." amount ".$acc_operation->amount."<br>";
}
$acc_operation->desc=$e_comm; $acc_operation->desc=$e_comm;
$acc_operation->grpt=$seq; $acc_operation->grpt=$seq;
$acc_operation->jrn=$p_jrn; $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(); $acc_operation->currency_rate_ref=$currency_rate_ref->get_rate();
if ( ! $this->jr_id=$acc_operation->insert_jrn() ) { 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(); $this->pj=$acc_operation->update_receipt();
@ -1145,14 +1141,9 @@ class Acc_Ledger_Purchase extends Acc_Ledger
}//end try }//end try
catch (Exception $e) catch (Exception $e)
{ {
record_log($e); record_log($e);
echo '<span class="error">'.
'Erreur dans l\'enregistrement '.
__FILE__.':'.__LINE__.' '.
$e->getMessage().$e->getMessage();
record_log($e->getMessage());
$this->db->rollback(); $this->db->rollback();
throw new Exception($e); throw $e;
} }
$this->db->commit(); $this->db->commit();
return $internal; return $internal;
@ -1272,7 +1263,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
$add_js=""; $add_js="";
if ( $g_parameter->MY_PJ_SUGGEST !='N') if ( $g_parameter->MY_PJ_SUGGEST !='N')
{ {
$add_js="update_pj();"; $add_js="update_receipt();";
} }
if ($g_parameter->MY_DATE_SUGGEST == 'Y') 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 we suggest the pj n# the run the script */
if ( $g_parameter->MY_PJ_SUGGEST !='N') if ( $g_parameter->MY_PJ_SUGGEST !='N')
{ {
$r.='<script> update_pj();</script>'; $r.='<script> update_receipt();</script>';
} }
// set focus on date // set focus on date
$r.= create_script("$('".$Date->id."').focus()"); $r.= create_script("$('".$Date->id."').focus()");

View file

@ -678,7 +678,7 @@ class Acc_Ledger_Sale extends Acc_Ledger {
$acc_operation->currency_rate_ref=$currency_rate_ref->get_rate(); $acc_operation->currency_rate_ref=$currency_rate_ref->get_rate();
if ( ! $this->jr_id=$acc_operation->insert_jrn() ) { 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(); $this->pj = $acc_operation->update_receipt();
@ -856,15 +856,9 @@ class Acc_Ledger_Sale extends Acc_Ledger {
$acc_operation_note->save(); $acc_operation_note->save();
} }
} catch (Exception $e) { } catch (Exception $e) {
record_log($e); record_log($e);
echo '<span class="error">' .
'Erreur dans l\'enregistrement ' .
__FILE__ . ':' . __LINE__ . ' ' .
$e->getMessage();
echo $e->getTraceAsString();
$this->db->rollback(); $this->db->rollback();
throw new Exception ($e); throw $e;
} }
$this->db->commit(); $this->db->commit();

View file

@ -105,7 +105,16 @@ if (isset($_POST['record']))
echo '<div class="content">'; echo '<div class="content">';
$Ledger = new Acc_Ledger_Purchase($cn, $post_jrn); $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 */ /* Save the predefined operation */

View file

@ -116,7 +116,16 @@ if ( isset($_POST['confirm']))
echo '</div>'; echo '</div>';
echo '<div class="content">'; echo '<div class="content">';
$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 '<h1>'._('Enregistrement').' </h1>'; echo '<h1>'._('Enregistrement').' </h1>';
echo '<div class="content">'; echo '<div class="content">';
echo $a; echo $a;

View file

@ -122,7 +122,18 @@ if ( isset($_POST['record']) )
echo '<div class="content">'; echo '<div class="content">';
$Ledger=new Acc_Ledger_Sale($cn,$_POST['p_jrn']); $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 */ /* Save the predefined operation */
if ( isset($_POST['opd_name']) && trim($_POST['opd_name']) != "" ) if ( isset($_POST['opd_name']) && trim($_POST['opd_name']) != "" )

View file

@ -113,9 +113,6 @@ if (!defined('LOGINPUT')) {
define("LOGINPUT", false); define("LOGINPUT", false);
} }
if (!defined('DEBUGNOALYSS')) {
define('DEBUGNOALYSS', 0);
}
$version_noalyss = NOALYSS_VERSION; $version_noalyss = NOALYSS_VERSION;
// If you don't want to be notified of the update // 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("html_errors", 0);
ini_set('log_errors', 1); ini_set('log_errors', 1);
ini_set('log_errors_max_len', 0); ini_set('log_errors_max_len', 0);
if(function_exists('xdebug_disable')) { xdebug_disable(); }
} elseif (DEBUGNOALYSS == 1) { } elseif (DEBUGNOALYSS == 1) {
/* DEVELOPPEMENT : display all errors warning notice deprecated ...*/ /* DEVELOPPEMENT : display all errors warning notice deprecated ...*/
error_reporting(2147483647); error_reporting(2147483647);
@ -347,6 +345,8 @@ define('EXC_PARAM_TYPE', 1006);
define('EXC_DUPLICATE', 1200); define('EXC_DUPLICATE', 1200);
define('EXC_INVALID', 1400); define('EXC_INVALID', 1400);
define('EXC_FORBIDDEN', 1500); define('EXC_FORBIDDEN', 1500);
// exception when balance is incorrect when saving an operation
define('EXC_BALANCE', 1501);
define("UNPINDG", "&#xf047;"); define("UNPINDG", "&#xf047;");
define("PINDG", "&#xe809;"); define("PINDG", "&#xe809;");

View file

@ -1335,22 +1335,54 @@ function is_msie()
return $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 * Record also the GET and POST data
* @param string $p_message * @param $p_message string message to display
*/ */
function record_log($p_message) 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); if ($handle_log == false )
error_log("noalyss exception".$p_message->getTraceAsString(),0); {
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 { } 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')) { if(!function_exists('tracedebug')) {
function tracedebug($file,$var, $label = NULL) { function tracedebug($file,$var, $label = NULL) {

3
log/.htaccess Normal file
View file

@ -0,0 +1,3 @@
order deny,allow
deny from all

1
log/index.html Normal file
View file

@ -0,0 +1 @@
<h1>LOGFILE</h1>