Currency : add a check , upgrade version of DB
This commit is contained in:
parent
eb9654f40a
commit
47bf11652f
5 changed files with 96 additions and 26 deletions
|
|
@ -1094,30 +1094,7 @@ class Acc_Ledger extends jrn_def_sql
|
|||
$currency_code=$http->extract($p_array,"p_currency_code","number");
|
||||
$currency=new Acc_Currency($this->db,$currency_code);
|
||||
|
||||
if ( $p_currency_code == -1 )
|
||||
{
|
||||
throw new Exception(_('Devise inconnue'), 3);
|
||||
}
|
||||
|
||||
/* -- check the accounting for error of exchange -*/
|
||||
if ($p_currency_code > 0 )
|
||||
{
|
||||
$poste=new Acc_Account($this->db,$g_parameter->MY_DEFAULT_ROUND_ERROR_DEB);
|
||||
if ($poste->get_parameter("id") == -1 )
|
||||
{
|
||||
throw new Exception(
|
||||
sprintf(_("Dans COMPANY, vous n'avez pas paramétré correctement ".
|
||||
" le compte de débit %s pour les erreurs de conversion"),$g_parameter->MY_DEFAULT_ROUND_ERROR_DEB), 3);
|
||||
}
|
||||
$poste=new Acc_Account($this->db,$g_parameter->MY_DEFAULT_ROUND_ERROR_CRED);
|
||||
if ($poste->get_parameter("id") == -1 )
|
||||
{
|
||||
throw new Exception(
|
||||
sprintf(_("Dans COMPANY, vous n'avez pas paramétré correctement ".
|
||||
" le compte de crédit %s pour les erreurs de conversion"),$g_parameter->MY_DEFAULT_ROUND_ERROR_CRED), 3);
|
||||
}
|
||||
|
||||
}
|
||||
$this->check_currency_setting($currency_code);
|
||||
|
||||
/* check if we can write into this ledger */
|
||||
if ($g_user->check_jrn($p_jrn)!='W')
|
||||
|
|
@ -1751,7 +1728,43 @@ class Acc_Ledger extends jrn_def_sql
|
|||
return false;
|
||||
throw new Exception("Valeur invalid ".__FILE__.':'.__LINE__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the currency code does exist and the setting of the folder is correct
|
||||
*
|
||||
* @param int $p_currency_code
|
||||
* @throws Exception
|
||||
*/
|
||||
function check_currency_setting ($p_currency_code)
|
||||
{
|
||||
global $g_parameter;
|
||||
if ( $p_currency_code == -1 )
|
||||
{
|
||||
throw new Exception(_('Devise inconnue'), 3);
|
||||
}
|
||||
/* -- check the accounting for error of exchange -*/
|
||||
if ($p_currency_code > 0 )
|
||||
{
|
||||
$poste=new Acc_Account($this->db,$g_parameter->MY_DEFAULT_ROUND_ERROR_DEB);
|
||||
|
||||
if ($poste->get_parameter("id") == -1 )
|
||||
{
|
||||
throw new Exception(
|
||||
sprintf(_("Dans COMPANY, vous n'avez pas paramétré correctement ".
|
||||
" le compte de débit %s pour les erreurs de conversion"),
|
||||
$g_parameter->MY_DEFAULT_ROUND_ERROR_DEB), 3);
|
||||
}
|
||||
|
||||
$poste=new Acc_Account($this->db,$g_parameter->MY_DEFAULT_ROUND_ERROR_CRED);
|
||||
if ($poste->get_parameter("id") == -1 )
|
||||
{
|
||||
throw new Exception(
|
||||
sprintf(_("Dans COMPANY, vous n'avez pas paramétré correctement ".
|
||||
" le compte de crédit %s pour les erreurs de conversion"),
|
||||
$g_parameter->MY_DEFAULT_ROUND_ERROR_CRED), 3);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
/**
|
||||
* When we write a record for the payment at the same time as a sale or a purchase, to have a
|
||||
* bank saldo reliable , all the bank operation must be in the same currency
|
||||
|
|
|
|||
|
|
@ -287,6 +287,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
|
|||
if ( isNumber($p_currency_rate) == 0 || $p_currency_rate <=0 ) {
|
||||
throw new Exception(_('Taux devise invalide'),15);
|
||||
}
|
||||
$this->check_currency_setting($p_currency_code);
|
||||
}
|
||||
/**
|
||||
* Compute the ND amount thanks the attribute of the concerned card. The object
|
||||
|
|
|
|||
|
|
@ -245,6 +245,7 @@ class Acc_Ledger_Sold extends Acc_Ledger {
|
|||
if ( isNumber($p_currency_rate) == 0 || $p_currency_rate <=0 ) {
|
||||
throw new Exception(_('Taux devise invalide'),15);
|
||||
}
|
||||
$this->check_currency_setting($p_currency_code);
|
||||
}
|
||||
|
||||
/*!\brief insert into the database, it calls first the verify function,
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ if ( !defined ("NOALYSS_PACKAGE_REPOSITORY")) {
|
|||
if ( ! defined ("SYSINFO_DISPLAY")) {
|
||||
define ("SYSINFO_DISPLAY",TRUE);
|
||||
}
|
||||
define ("DBVERSION",155);
|
||||
define ("DBVERSION",156);
|
||||
define ("MONO_DATABASE",25);
|
||||
define ("DBVERSIONREPO",19);
|
||||
define ('NOTFOUND','--not found--');
|
||||
|
|
|
|||
55
include/sql/patch/upgrade155.sql
Normal file
55
include/sql/patch/upgrade155.sql
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
begin;
|
||||
|
||||
create or replace function tmp_1 () returns void
|
||||
as
|
||||
$fct$
|
||||
declare
|
||||
sCountry text;
|
||||
nOhada int;
|
||||
begin
|
||||
|
||||
-- set my_country for OHADA
|
||||
select count(*) into nOhada from tmp_pcmn where pcm_val='886' ;
|
||||
|
||||
if nOhada = 1 then
|
||||
update parameter set pr_value='AF' where pr_id='MY_COUNTRY';
|
||||
end if;
|
||||
|
||||
select pr_value into sCountry from parameter where pr_id='MY_COUNTRY';
|
||||
|
||||
if sCountry = 'BE' then
|
||||
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type,pcm_direct_use)
|
||||
values ('755','Ecart de conversion','75','PRO','Y') on conflict do nothing;
|
||||
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type,pcm_direct_use)
|
||||
values ('655','Ecart de conversion','65','CHA','Y') on conflict do nothing;
|
||||
|
||||
update public."parameter" set pr_value = '755' where pr_id= 'MY_DEFAULT_ROUND_ERROR_CRED';
|
||||
update public."parameter" set pr_value = '655' where pr_id= 'MY_DEFAULT_ROUND_ERROR_DEB';
|
||||
|
||||
|
||||
end if;
|
||||
|
||||
if sCountry = 'FR' then
|
||||
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type,pcm_direct_use)
|
||||
values ('758','Ecart de conversion','75','PRO','Y') on conflict do nothing;
|
||||
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type,pcm_direct_use)
|
||||
values ('658','Ecart de conversion ','65','CHA','Y') on conflict do nothing;
|
||||
|
||||
update public."parameter" set pr_value = '758' where pr_id= 'MY_DEFAULT_ROUND_ERROR_CRED';
|
||||
update public."parameter" set pr_value = '658' where pr_id= 'MY_DEFAULT_ROUND_ERROR_DEB';
|
||||
|
||||
end if;
|
||||
|
||||
|
||||
|
||||
end;
|
||||
$fct$
|
||||
language plpgsql;
|
||||
|
||||
select tmp_1();
|
||||
|
||||
drop function tmp_1;
|
||||
insert into version (val,v_description) values (156,'insert default accounting');
|
||||
|
||||
|
||||
commit;
|
||||
Loading…
Add table
Add a link
Reference in a new issue