Currency : because of Misc Operation, the tiers must also be saved into

operation_currency.
Fix also PRINTJRN for currency
This commit is contained in:
Dany De Bontridder 2019-01-09 09:26:14 +01:00
parent e2a707e8e6
commit 6a6322bd43
7 changed files with 40 additions and 21 deletions

View file

@ -1927,8 +1927,10 @@ class Acc_Ledger extends jrn_def_sql
"jr_pj_number as pj,jr_grpt_id,".
" to_char(jr_date,'DDMMYY') as date_fmt, ".
" jr_comment as comment, jr_montant as montant ,".
" jr_grpt_id,jr_def_id".
" from jrn join jrn_def on (jr_def_id=jrn_def_id) where ".
" jr_grpt_id,jr_def_id,jrn.currency_id,currency_rate,currency_rate_ref,cr_code_iso ".
" from jrn join jrn_def on (jr_def_id=jrn_def_id) ".
" left join currency on (currency.id=jrn.currency_id) ".
" where ".
" jr_date >= (select p_start from parm_periode where p_id = $1)
and jr_date <= (select p_end from parm_periode where p_id = $2)".
' '.$jrn.' order by jr_date,substring(jr_pj_number,\'[0-9]+$\')::numeric asc';

View file

@ -852,7 +852,7 @@ class Acc_Ledger_Fin extends Acc_Ledger
$operation_currency = new Operation_currency_SQL($this->db);
$operation_currency->oc_amount=$amount_input;
$operation_currency->oc_vat_amount=0;
$operation_currency->oc_price_unit=$amount_input;
$operation_currency->oc_price_unit=0;
$operation_currency->j_id=$j_id_currency;
$operation_currency->insert();
@ -883,18 +883,26 @@ class Acc_Ledger_Fin extends Acc_Ledger
$acc_operation->qcode = $e_bank_account;
$j_id=$acc_operation->insert_jrnx();
// -- Insert into Operation Currency
$operation_currency = new Operation_currency_SQL($this->db);
$operation_currency->oc_amount=$amount_input;
$operation_currency->oc_vat_amount=0;
$operation_currency->oc_price_unit=0;
$operation_currency->j_id=$j_id;
$operation_currency->insert();
if (sql_string(${"e_other$i" . "_comment"}) == null)
{
// if comment is blank set a default one
$comment = " compte : " . $fBank->strAttribut(ATTR_DEF_NAME) . ' a ' .
$fPoste->strAttribut(ATTR_DEF_NAME);
$comment = sprintf(_(" compte : %s a %s "),
$fBank->strAttribut(ATTR_DEF_NAME),
$fPoste->strAttribut(ATTR_DEF_NAME)
);
}
else
{
$comment = ${'e_other' . $i . '_comment'};
$comment =strip_tags(${'e_other' . $i . '_comment'});
}

View file

@ -478,8 +478,16 @@ class Acc_Ledger_Sold extends Acc_Ledger {
$tot_debit=round($tot_debit, 2);
}
$let_tiers = $acc_operation->insert_jrnx();
// --- insert also the currency amount for the customer
$operation_currency=new Operation_currency_SQL($this->db);
$operation_currency->oc_amount=$tot_amount_cur;
$operation_currency->oc_vat_amount=0;
$operation_currency->oc_price_unit=0;
$operation_currency->j_id=$let_tiers ;
$operation_currency->insert();
/** save all vat
* $i contains the tva_id and value contains the vat amount
* if if ($g_parameter->MY_TVA_USE == 'Y' )

View file

@ -100,12 +100,10 @@ class Print_Ledger_Financial extends PDF
if ( $a_jrn == null ) return;
bcscale(2);
$this->ledger->load();
$currency=$this->ledger->get_currency()->get_code();
$currency_id=$this->ledger->get_currency()->get_id();
$this->cn->prepare("amount_cur",
"select jrn2.jr_id ,
sum(coalesce(oc_amount,0)) as sum_ocamount,
sum(coalesce(oc_vat_amount,0)) as sum_ocvat_amount
sum(coalesce(oc_amount,0)) as sum_ocamount
from operation_currency
join jrnx using (j_id)
join jrn as jrn2 on (j_grpt=jrn2.jr_grpt_Id)
@ -126,13 +124,15 @@ class Print_Ledger_Financial extends PDF
$this->LongLine(60,5,$row['comment'],0,'L');
$amount=$this->cn->get_value('select qf_amount from quant_fin where jr_id=$1',array( $row['id']));
if ( $currency_id != 0) {
$ret_amount_cur=$this->cn->execute("amount_cur",array($row['id']));
$ret_amount_cur=$this->cn->execute("amount_cur",array($row['id']));
if ( $this->cn->count($ret_amount_cur) == 1) {
if ( $this->cn->count($ret_amount_cur) == 1) {
$amount_cur=Database::fetch_result($ret_amount_cur, 0,1);
$this->write_cell(20,5,sprintf('%s %s',nbm($amount_cur),$currency),0,0,'R');
}
$amount_cur=Database::fetch_result($ret_amount_cur, 0,1);
$this->write_cell(20,5,sprintf('%s %s',nbm($amount_cur),$row['cr_code_iso']),0,0,'R');
} else {
$this->write_cell(20,5,"",0,0,'R');
}
$this->write_cell(20,5,sprintf('%s',nbm($amount)),0,0,'R');
$this->line_new(5);

View file

@ -93,7 +93,7 @@ class Print_Ledger_Misc extends PDF
$positive = $this->cn->get_value("select qf_amount from quant_fin ".
" where jr_id=".$row['jr_id']);
}
$this->write_cell(20,5,nbm(bcadd($row['sum_ocvat_amount'],$row['sum_ocamount']),4).$row['cr_code_iso'],0,0,'R');
$this->write_cell(20,5,nbm(bcadd($row['sum_ocvat_amount'],$row['sum_ocamount']),2).$row['cr_code_iso'],0,0,'R');
$this->write_cell(15,5,nbm($positive),0,0,'R');
$this->line_new(5);

View file

@ -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"
, "jrn_enable"=>"jrn_enable"
, "currency_id"=>"currency_id"
);

View file

@ -103,7 +103,7 @@ if ($obj->det->currency_id!=0)
[$obj->det->array[0]['j_id']]);
$currency_rate=$obj->db->get_value("select currency_rate from jrn where jr_id=$1",[$obj->jr_id]);
$currency_code=$obj->db->get_value("select cr_code_iso from currency where id=$1",[$obj->det->currency_id]);
printf ("%s Taux utilisé %s Montant en devise %s",$currency_code,$currency_rate,$currency_amount);
printf (_("%s Taux utilisé %s Montant en devise %s"),$currency_code,$currency_rate,$currency_amount);
}
?>
<div class="myfieldset">