Currency : financial ledger can be set to a specific currency
This commit is contained in:
parent
765a62b2f3
commit
7eb4644cf0
4 changed files with 91 additions and 18 deletions
|
|
@ -82,6 +82,7 @@ class Acc_Ledger extends jrn_def_sql
|
|||
$this->db=$p_cn;
|
||||
$this->row=null;
|
||||
$this->nb=MAX_ARTICLE;
|
||||
$this->currency_id=0;
|
||||
}
|
||||
|
||||
function get_last_pj()
|
||||
|
|
@ -2277,9 +2278,27 @@ class Acc_Ledger extends jrn_def_sql
|
|||
["label"=>_("Désactivé"),"value"=>0]
|
||||
];
|
||||
$actif->selected=$this->jrn_enable;
|
||||
// -- default currency used : only for financial ledgers
|
||||
$default_currency=$this->select_default_currency();
|
||||
require_once NOALYSS_TEMPLATE.'/param_jrn.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief create a select button to set the default currency for a ledger
|
||||
* used only for empty financial ledger
|
||||
* @return ISelect object
|
||||
*/
|
||||
function select_default_currency()
|
||||
{
|
||||
$default_currency=new ISelect("defaultCurrency");
|
||||
$default_currency->value=$this->db->make_array("select id,cr_code_iso from public.currency order by 1 ");
|
||||
$default_currency->selected=$this->currency_id;
|
||||
$nb_operation=$this->db->get_value("select count(*) from jrn where jr_def_id=$1",[$this->id]);
|
||||
if ( $nb_operation > 0) {
|
||||
$default_currency->setReadOnly(TRUE);
|
||||
}
|
||||
return $default_currency;
|
||||
}
|
||||
/**
|
||||
* Verify before update
|
||||
*
|
||||
|
|
@ -2357,6 +2376,7 @@ class Acc_Ledger extends jrn_def_sql
|
|||
$this->jrn_deb_max_line=($min_row<1)?1:$min_row;
|
||||
$this->jrn_def_description=$p_description;
|
||||
$this->jrn_enable=$jrn_enable;
|
||||
$this->currency_id=0;
|
||||
switch ($this->jrn_def_type)
|
||||
{
|
||||
case 'ACH':
|
||||
|
|
@ -2389,6 +2409,18 @@ class Acc_Ledger extends jrn_def_sql
|
|||
if ($result==-1)
|
||||
throw new Exception(_("Aucun compte en banque n'est donné"));
|
||||
$this->jrn_def_num_op=(isset($numb_operation))?1:0;
|
||||
// if nb operation == 0 then update currency_id
|
||||
$nb_operation = $this->db->get_value("select count(*) from jrn where jr_def_id=$1",
|
||||
[$this->jrn_def_id]);
|
||||
/*
|
||||
* Set the default currency except if there are already operation
|
||||
*/
|
||||
if ( $nb_operation == 0 ){
|
||||
$this->currency_id=$defaultCurrency;
|
||||
} else {
|
||||
$this->currency_id=$this->db->get_value("select currency_id from jrn_def where jrn_def_id=$1",
|
||||
[$this->jrn_def_id]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -2513,6 +2545,8 @@ class Acc_Ledger extends jrn_def_sql
|
|||
$cn=$this->db;
|
||||
$min_row=new INum("min_row", MAX_ARTICLE);
|
||||
$min_row->prec=0;
|
||||
// -- default currency used : only for financial ledgers
|
||||
$default_currency=$this->select_default_currency();
|
||||
require_once NOALYSS_TEMPLATE.'/param_jrn.php';
|
||||
}
|
||||
|
||||
|
|
@ -2536,6 +2570,8 @@ class Acc_Ledger extends jrn_def_sql
|
|||
trim(substr($this->jrn_def_type, 0, 1)),
|
||||
Acc_Ledger::next_number($this->db, $this->jrn_def_type));
|
||||
$this->jrn_def_description=$p_description;
|
||||
$this->currency_id=0;
|
||||
|
||||
switch ($this->jrn_def_type)
|
||||
{
|
||||
case 'ACH':
|
||||
|
|
@ -2567,6 +2603,7 @@ class Acc_Ledger extends jrn_def_sql
|
|||
if ($result==-1)
|
||||
throw new Exception(_("Aucun compte en banque n'est donné"));
|
||||
$this->jrn_def_num_op=(isset($numb_operation))?1:0;
|
||||
$this->currency_id=$defaultCurrency;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ class Jrn_Def_sql
|
|||
, "jrn_def_bank" => "jrn_def_bank"
|
||||
, "jrn_def_num_op" => "jrn_def_num_op"
|
||||
, "jrn_def_description" => "jrn_def_description"
|
||||
, "currency_id"=>"currency_id"
|
||||
);
|
||||
|
||||
function __construct(& $p_cn, $p_id=-1)
|
||||
|
|
@ -213,6 +214,7 @@ class Jrn_Def_sql
|
|||
,jrn_def_bank
|
||||
,jrn_def_num_op
|
||||
,jrn_def_description
|
||||
,currency_id
|
||||
) values ($1
|
||||
,$2
|
||||
,$3
|
||||
|
|
@ -228,6 +230,7 @@ class Jrn_Def_sql
|
|||
,$13
|
||||
,$14
|
||||
,$15
|
||||
,$16
|
||||
) returning jrn_def_id";
|
||||
|
||||
$this->jrn_def_id = $this->db->get_value(
|
||||
|
|
@ -246,6 +249,7 @@ class Jrn_Def_sql
|
|||
, $this->jrn_def_bank
|
||||
, $this->jrn_def_num_op
|
||||
, strip_tags($this->jrn_def_description)
|
||||
, $this->currency_id
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
@ -284,25 +288,29 @@ jrn_enable) values ($1
|
|||
,$15
|
||||
,$16
|
||||
,1
|
||||
,$17
|
||||
) returning jrn_def_id";
|
||||
|
||||
$this->jrn_def_id = $this->db->get_value(
|
||||
$sql, array($this->jrn_def_name
|
||||
, $this->jrn_def_class_deb
|
||||
, $this->jrn_def_class_cred
|
||||
, $this->jrn_def_fiche_deb
|
||||
, $this->jrn_def_fiche_cred
|
||||
, $this->jrn_deb_max_line
|
||||
, $this->jrn_cred_max_line
|
||||
, $this->jrn_def_ech
|
||||
, $this->jrn_def_ech_lib
|
||||
, $this->jrn_def_type
|
||||
, $this->jrn_def_code
|
||||
, $this->jrn_def_pj_pref
|
||||
, $this->jrn_def_bank
|
||||
, $this->jrn_def_num_op
|
||||
, $this->jrn_def_id
|
||||
, strip_tags($this->jrn_def_description))
|
||||
$sql, array(
|
||||
$this->jrn_def_name // 1
|
||||
, $this->jrn_def_class_deb // 2
|
||||
, $this->jrn_def_class_cred // 3
|
||||
, $this->jrn_def_fiche_deb // 4
|
||||
, $this->jrn_def_fiche_cred // 5
|
||||
, $this->jrn_deb_max_line // 6
|
||||
, $this->jrn_cred_max_line // 7
|
||||
, $this->jrn_def_ech // 8
|
||||
, $this->jrn_def_ech_lib // 9
|
||||
, $this->jrn_def_type // 10
|
||||
, $this->jrn_def_code // 11
|
||||
, $this->jrn_def_pj_pref // 12
|
||||
, $this->jrn_def_bank // 13
|
||||
, $this->jrn_def_num_op // 14
|
||||
, $this->jrn_def_id // 15
|
||||
, strip_tags($this->jrn_def_description)) // 16
|
||||
, $this->currency_id // 17
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -328,6 +336,7 @@ jrn_enable) values ($1
|
|||
,jrn_def_num_op = $14
|
||||
,jrn_def_description = $15
|
||||
,jrn_enable=$17
|
||||
, currency_id = $18
|
||||
where jrn_def_id= $16";
|
||||
$res = $this->db->exec_sql(
|
||||
$sql, array($this->jrn_def_name
|
||||
|
|
@ -347,6 +356,7 @@ jrn_enable) values ($1
|
|||
, strip_tags($this->jrn_def_description)
|
||||
, $this->jrn_def_id
|
||||
, $this->jrn_enable
|
||||
, $this->currency_id
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
@ -374,6 +384,7 @@ jrn_enable) values ($1
|
|||
,jrn_def_num_op
|
||||
,jrn_def_description
|
||||
,jrn_enable
|
||||
,currency_id
|
||||
from public.jrn_def where jrn_def_id=$1";
|
||||
/* please adapt */
|
||||
$res = $this->db->get_array(
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
//This file is part of NOALYSS and is under GPL
|
||||
//see licence.txt
|
||||
?><TABLE style="width: auto">
|
||||
?><TABLE style="width: auto" class="nowrap">
|
||||
<TR>
|
||||
|
||||
<TD><?php echo _('Nom journal')?> </TD>
|
||||
|
|
@ -128,7 +128,22 @@ echo $str_add_button;
|
|||
<?=$actif->input()?>
|
||||
</td>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
|
||||
// if the ledger is financial and has no operation let choose the currency
|
||||
if ( $new == 1 || $type == 'FIN'):
|
||||
?>
|
||||
<tr id="type_fin3">
|
||||
<td>
|
||||
<?php echo _("Devise")?>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo $default_currency->input();?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
</TABLE>
|
||||
<hr>
|
||||
<?php
|
||||
|
|
@ -363,6 +378,7 @@ echo $str_add_button;
|
|||
$('type_ods').style.display='none';
|
||||
$('type_fin').style.display='none';
|
||||
$('type_fin2').style.display='none';
|
||||
$('type_fin3').style.display='none';
|
||||
}
|
||||
function show_ledger_div()
|
||||
{
|
||||
|
|
@ -374,6 +390,7 @@ echo $str_add_button;
|
|||
hide_row();
|
||||
$('type_fin').style.display='table-row';
|
||||
$('type_fin2').style.display='table-row';
|
||||
$('type_fin3').style.display='table-row';
|
||||
break;
|
||||
case 'ODS':
|
||||
hide_row();
|
||||
|
|
|
|||
|
|
@ -19,4 +19,12 @@ EXCEPTION WHEN others THEN
|
|||
RETURN FALSE;
|
||||
END;
|
||||
$$
|
||||
LANGUAGE plpgsql;
|
||||
LANGUAGE plpgsql;
|
||||
|
||||
ALTER TABLE public.jrn_def ADD currency_id int NULL;
|
||||
ALTER TABLE public.jrn_def ALTER COLUMN currency_id SET DEFAULT 0;
|
||||
update public.jrn_def set currency_id = 0 ;
|
||||
ALTER TABLE public.jrn_def ALTER COLUMN currency_id SET NOT NULL;
|
||||
ALTER TABLE public.jrn_def ADD CONSTRAINT jrn_def_currency_fk FOREIGN KEY (currency_id) REFERENCES public.currency(id);
|
||||
|
||||
COMMENT ON COLUMN public.jrn_def.currency_id IS 'Default currency for financial ledger';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue