Merge branch 'r700-currency' of gitlab.noalyss.eu:noalyss/noalyss into r700-currency

This commit is contained in:
Dany De Bontridder 2019-01-24 17:29:27 +01:00
commit 6c90a40068
38 changed files with 599 additions and 159 deletions

View file

@ -27,6 +27,7 @@
require_once '../include/constant.php';
require_once NOALYSS_INCLUDE.'/lib/database.class.php';
require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
/*!\brief
* Received parameters are
@ -41,11 +42,12 @@ require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
* - list of fd_id
*
*/
$http=new HttpInput();
$jrn= ( ! isset($_REQUEST['j']))?-1:$_REQUEST['j'];
$jrn= $http->request("j","number",-1);
$filter_card="";
$cn=Dossier::connect();
$d=$_REQUEST['e'];
$d=$http->request('e');
$filter_card='';
require_once('class/user.class.php');
@ -107,8 +109,8 @@ else
{
$get_cred='jrn_def_fiche_cred';
$get_deb='jrn_def_fiche_deb';
$filter_jrn=$cn->make_list("select $get_cred||','||$get_deb as fiche from jrn_def where jrn_def_type=$1",array($_REQUEST['type']));
$type=$http->request("type");
$filter_jrn=$cn->make_list("select $get_cred||','||$get_deb as fiche from jrn_def where jrn_def_type=$1",array($type));
$filter_card=($filter_jrn != "")?" and fd_id in ($filter_jrn)":' and false ';
}
@ -125,9 +127,12 @@ else
$sql_str="select distinct f_id from fiche join fiche_detail using (f_id) where ad_id in (9,1,23) and ad_value ilike '%'||$1||'%' ".$filter_card.' limit 12';
$sql=$cn->get_array($sql_str ,array($_REQUEST['FID']));
if (sizeof($sql) != 0 )
$fid=$http->request("FID");
$sql=$cn->get_array($sql_str ,array($fid));
if ($sql != false && sizeof($sql) != 0 )
{
echo "<ul>";
$sql_get=$cn->prepare('get_name',"select ad_value from fiche_detail where f_id = $1 and ad_id=$2");
@ -146,12 +151,12 @@ if (sizeof($sql) != 0 )
$sql_name=$cn->execute('get_name',array($sql[$i]['f_id'],23));
if (Database::num_row($sql_name) == 1) $quick_code=Database::fetch_result($sql_name,0,0);
$fid=htmlentities($_REQUEST['FID']);
$fid=htmlentities($fid);
/* Highlight the found pattern with bold format */
$name=str_ireplace($_REQUEST['FID'],'<em>'.$fid.'</em>',h($name));
$qcode=str_ireplace($_REQUEST['FID'],'<em>'.$fid.'</em>',h($quick_code));
$desc=str_ireplace($_REQUEST['FID'],'<em>'.$fid.'</em>',h($desc));
$name=str_ireplace($fid,'<em>'.$fid.'</em>',h($name));
$qcode=str_ireplace($fid,'<em>'.$fid.'</em>',h($quick_code));
$desc=str_ireplace($fid,'<em>'.$fid.'</em>',h($desc));
printf('<li id="%s">%s <span class="informal">%s %s</span></li>',
$quick_code,
$quick_code,

View file

@ -96,7 +96,7 @@ function CurrencyUpdateCode(p_dossier,p_code,p_update)
});
}
/**
* Update the field Update with the amount in EUR
* Update the field Update with the amount in EUR (= default currency), ledger sale or purchase
* @param DOMID p_rate where the rate is stored
* @param DOMID p_update element to update with the rate
*/
@ -115,18 +115,56 @@ function CurrencyCompute(p_rate,p_update)
console.log("rate is nan" + rate);
rate=1;
}
var tot=tvac*rate;
var tot=tvac/rate;
tot=Math.round(tot*100)/100;
$(p_update).innerHTML=tot;
}
/**
*
* @param {type} p_dossier
* @param {type} p_code
* @param {type} p_update
* @param {type} p_rate
* @param {type} p_eur_amount
* Update the field Update with the amount in EUR (= default currency) for Miscealleneous Operation
* amount for DEB (domid : default_currency_deb , totalDeb)
* amount for CRED ( domid = default_currency_cred , totalCred),
* @param DOMID p_rate where the rate is stored
* @param DOMID p_update element to update with the rate
*/
function CurrencyComputeMisc(p_rate,p_update)
{
var debAmount=$('totalDeb').innerHTML;
var credAmount=$('totalCred').innerHTML;
console.log("debAmount= "+debAmount);
console.log("credAmount= "+credAmount);
if ( isNaN(debAmount)) {
console.log("debAmount is nan" + debAmount);
debAmount=0;
}
if ( isNaN(credAmount)) {
console.log("credAmount is nan" + credAmount);
credAmount=0;
}
var rate=$(p_rate).value;
console.log("rate = "+rate);
if ( isNaN(rate) || parseFloat(rate) == 0) {
console.log("rate is nan" + rate);
rate=1;
}
var totDeb=debAmount/rate;
totDeb=Math.round(totDeb*100)/100;
$('default_currency_deb').innerHTML=totDeb;
var totCred=credAmount/rate;
totCred=Math.round(totCred*100)/100;
$('default_currency_cred').innerHTML=totCred;
}
/**
* Update the screen of input for Purchase and Sale
* @param {type} p_dossier
* @param {type} p_code name of the SELECT containing the currency code
* @param {type} p_update Domid of the element to update
* @param {type} p_rate domid of the element containing the currency rate
* @param {type} p_eur_amount domid of the amount in default currency to update
* @returns {undefined}
*/
function LedgerCurrencyUpdate(p_dossier,p_code,p_update,p_rate,p_eur_amount)
@ -142,4 +180,27 @@ function LedgerCurrencyUpdate(p_dossier,p_code,p_update,p_rate,p_eur_amount)
// Compute all the fields
compute_all_ledger ();
}
/**
* Update the screen of input for Misc. Operation
* @param {type} p_dossier
* @param {type} p_code name of the SELECT containing the currency code
* @param {type} p_update Domid of the element to update
* @param {type} p_rate domid of the element containing the currency rate
* @param {type} p_eur_amount domid of the amount in default currency to update
* @returns {undefined}
*/
function LedgerCurrencyUpdateMisc(p_dossier,p_code,p_update,p_rate,p_eur_amount)
{
// Hide or show the row of the table with the amount in EUR (= default currency)
if ($(p_code).value != -1) {
$('row_currency').show();
}else {
$('row_currency').hide();
}
CurrencyUpdateValue(p_dossier,p_code,p_rate);
CurrencyUpdateCode(p_dossier,p_code,p_update);
// Compute all the fields
checkTotalDirect();
}

View file

@ -490,8 +490,8 @@ function success_compute_ledger(request, json)
g('htva_march' + ctl).value = rhtva;
g('tvac_march' + ctl).value = rtvac;
g('sum').show();
CurrencyCompute('p_currency_rate','p_currency_euro');
refresh_ledger();
CurrencyCompute('p_currency_rate','p_currency_euro');
return;
}
@ -500,7 +500,6 @@ function success_compute_ledger(request, json)
g('sum').show();
CurrencyCompute('p_currency_rate','p_currency_euro');
if (g('e_march' + ctl + '_tva_amount').value == "" || g('e_march' + ctl + '_tva_amount').value == 0)
{
g('tva_march' + ctl).value = rtva;
@ -514,8 +513,9 @@ function success_compute_ledger(request, json)
var tmp1 = Math.round(parseFloat(g('htva_march' + ctl).value) * 100) / 100;
var tmp2 = Math.round(parseFloat(g('tva_march' + ctl).value) * 100) / 100;
g('tvac_march' + ctl).value = Math.round((tmp1 + tmp2) * 100) / 100;
refresh_ledger();
CurrencyCompute('p_currency_rate','p_currency_euro');
}
/**

View file

@ -108,8 +108,6 @@ function anc_refresh_remain(p_table, p_seq)
var tot_table = compute_total_table(p_table, p_seq);
var remain = tot_line - tot_table;
remain = Math.round(remain * 100) / 100;
// var popup_table = p_table.toString();
// p_table = popup_table.replace("popup", "");
$('remain' + p_table).innerHTML = remain;
if (remain == 0)
{

View file

@ -18,6 +18,12 @@
/*!\file
*\brief common function for "Ecriture directe"
*/
/**
* Compute the sum of the debit and credit of the operation in the input screen for misceallenous operation
* Call CurrencyComputeMisc to update the amount in default currency for DEB (domid = default_currency_deb)
* and CRED ( domid = default_currency_cred),
* @returns {Boolean} true if ok
*/
function checkTotalDirect()
{
var ie4=false;
@ -77,6 +83,10 @@ function checkTotalDirect()
r_total_deb=Math.round(total_deb*100)/100;
document.getElementById('totalDeb').innerHTML=r_total_deb;
document.getElementById('totalCred').innerHTML=r_total_cred;
// Currency , update the amount in default currency for DEB (domid = default_currency_deb)
// and CRED ( domid = default_currency_cred),
CurrencyComputeMisc('p_currency_rate','p_currency_euro');
var diff=0;
if ( r_total_deb != r_total_cred )
{

View file

@ -3412,7 +3412,7 @@ var progressIdx = 0;
/**
* Start the progress bar
* @param {string} p_taskid id to monitor
* @param {int} p_dossier
* @param {int} p_message
*/
function progress_bar_start(p_taskid,p_message)
{

View file

@ -190,10 +190,10 @@ class Acc_Account_Ledger
,jrn.currency_id
,(select cr_code_iso from currency where id=jrn.currency_id) as cr_code_iso
,j_montant
,sum_oc_amount as oc_amount
,sum_oc_vat_amount as oc_vat_amount
,oc_amount
,oc_vat_amount
from jrnx as j1
left join v_all_account_currency as va on (j1.j_id = va.j_id and j1.j_poste=va.j_poste)
left join operation_currency as va on (j1.j_id = va.j_id )
join jrn_def on (jrn_def_id=j_jrn_def )
join jrn on (jr_grpt_id=j_grpt)
join tmp_pcmn on (j1.j_poste=pcm_val)
@ -407,7 +407,7 @@ class Acc_Account_Ledger
"<TH style=\"text-align:left\">"._('Description')."</TH>".
"<TH style=\"text-align:left\">"._('Type')."</TH>".
"<TH style=\"text-align:left\">"._('ISO')."</TH>".
"<TH style=\"text-align:left\">"._('Dev.')."</TH>".
"<TH style=\"text-align:right\">"._('Dev.')."</TH>".
"<TH style=\"text-align:right\">"._('Débit')."</TH>".
"<TH style=\"text-align:right\">"._("Crédit")."</TH>".
th('Prog.','style="text-align:right"').
@ -464,8 +464,8 @@ class Acc_Account_Ledger
$side="&nbsp;".$this->get_amount_side($progress);
$sum_cred=bcadd($sum_cred,$op['cred_montant']);
$sum_deb=bcadd($sum_deb,$op['deb_montant']);
if ($idx%2 == 0) $class='class="odd"'; else $class=' class="even"';
$idx++;
$class=($idx%2 == 0)?'class="odd"':$class=' class="even"';
$idx++;
echo "<TR $class name=\"tr_" . $let . "_" . $from_div . "\">" .
"<TD>".smaller_date(format_date($op['j_date']))."</TD>".
@ -476,10 +476,13 @@ class Acc_Account_Ledger
"<TD>".h($op['description'])."</TD>".
td($op['jr_optype']);
/// If the currency is not the default one , then show the amount
if ( $op['currency_id'] > 0 && $op['oc_amount'] != 0)
if ( $op['currency_id'] > 0 )
{
echo td($op['cr_code_iso']).
td(nbm($op['oc_amount'],4),'style="text-align:right;padding-left:10px;"');
// some amount are not directly recorded into operation_currency, like VAT
$currency_val=($op['oc_amount'] == 0)?round(bcmul ($op['j_montant'],$op['currency_rate']),2):$op['oc_amount'] ;
echo td($op['cr_code_iso']).
td(nbm($currency_val,2),'style="text-align:right;padding-left:10px;"');
} else {
echo td().td();
}

View file

@ -89,13 +89,13 @@ class Acc_Compute
function convert_euro()
{
$local_amount=$this->amount;
$this->amount=bcmul($this->amount,$this->currency_rate);
$this->amount=bcdiv($this->amount,$this->currency_rate,6);
$this->amount_currency=$local_amount;
}
function convert_euro_vat()
{
$local_amount=$this->amount_vat;
$this->amount_vat=bcmul($this->amount_vat,$this->currency_rate);
$this->amount_vat=bcdiv($this->amount_vat,$this->currency_rate,6);
$this->amount_vat_currency=$local_amount;
}
public function get_parameter($p_string)

View file

@ -586,6 +586,7 @@ class Acc_Ledger extends jrn_def_sql
function confirm($p_array, $p_readonly=false)
{
global $g_parameter;
$http=new HttpInput();
$msg=array();
if (!$p_readonly)
$msg=$this->verify($p_array);
@ -737,8 +738,26 @@ class Acc_Ledger extends jrn_def_sql
$ret.="</tr>";
}
$ret.=tr(td('').td(_('Totaux')).td($total_deb, 'class="num"').td($total_cred,
$currency_code=$http->extract($p_array,"p_currency_code","number");
$currency_rate=$http->extract($p_array,"p_currency_rate","number");
$currency=new Acc_Currency($this->db,$currency_code);
$msg_currency= ($currency_code != 0 )?sprintf(_("Totaux %s (%s)"),$currency->get_code(),$currency_rate):_("Totaux");
$ret.=tr(td('').td($msg_currency).td($total_deb, 'class="num"').td($total_cred,
'class="num"'), 'class="highlight"');
// Currency
if ( $currency_code != 0)
{
$currency_rate=$http->extract($p_array,"p_currency_rate","number");
$default_currency=new Acc_Currency($this->db,0);
$ret.=tr(td('').
td(_('Totaux')." ".$default_currency->get_code()).
td(bcdiv($total_deb,$currency_rate), 'class="num"').
td(bcdiv($total_cred,$currency_rate), 'class="num"'),
'class="highlight"');
}
$ret.="</table>";
if ($g_parameter->MY_ANALYTIC!='nu'&&$p_readonly==false)
$ret.='<input type="button" class="button" value="'._('verifie Imputation Analytique').'" onClick="verify_ca(\'\');">';
@ -762,6 +781,7 @@ class Acc_Ledger extends jrn_def_sql
function input($p_array=null, $p_readonly=0)
{
global $g_parameter, $g_user;
$http=new HttpInput();
$this->nb=$this->get_min_row();
if ($p_readonly==1)
return $this->confirm($p_array);
@ -787,7 +807,8 @@ class Acc_Ledger extends jrn_def_sql
$wLedger=$this->select_ledger('ODS', 2,FALSE);
if ($wLedger==null)
throw new Exception(_('Pas de journal disponible'));
$wLedger->javascript="onChange='update_name();update_predef(\"ods\",\"t\",\"".$_REQUEST['ac']."\");$add_js'";
$ac=$http->request("ac");
$wLedger->javascript="onChange='update_name();update_predef(\"ods\",\"t\",\"".$ac."\");$add_js'";
$label=" Journal ".Icon_Action::infobulle(2);
$ret.="<table>";
@ -803,8 +824,11 @@ class Acc_Ledger extends jrn_def_sql
$op->set('ledger', $this->id);
$op->set('ledger_type', "ODS");
$op->set('direct', 't');
$url=http_build_query(array('action'=>'use_opd', 'p_jrn_predef'=>$this->id,
'ac'=>$_REQUEST['ac'], 'gDossier'=>dossier::id()));
$url=http_build_query(
array('action'=>'use_opd',
'p_jrn_predef'=>$this->id,
'ac'=>$ac,
'gDossier'=>dossier::id()));
echo $op->form_get('do.php?'.$url);
echo '</div>';
@ -884,6 +908,20 @@ class Acc_Ledger extends jrn_def_sql
$ret.='</tr>';
$ret.='</table>';
// Currency
$currency_select = $this->CurrencyInput("currency_code", "p_currency_rate" , "p_currency_euro");
$currency_select->selected=$http->request('p_currency_code','string',0);
$currency_input=new INum("p_currency_rate");
$currency_input->prec=6;
$currency_input->id="p_currency_rate";
$currency_input->value=$http->request('p_currency_rate','string',1);
$ret.=_("Devise")." ".$currency_select->input();
$ret.=$currency_input->change('CurrencyComputeMisc(\'p_currency_rate\',\'p_currency_euro\');');
$currency=new Acc_Currency($this->db,0);
$nb_row=(isset($nb_item) )?$nb_item:$this->nb;
$ret.=HtmlInput::hidden('nb_item', $nb_row);
@ -1027,6 +1065,8 @@ class Acc_Ledger extends jrn_def_sql
*/
function verify($p_array)
{
global $g_parameter;
$http=new HttpInput();
if (is_array($p_array)==false||empty($p_array))
throw new Exception("Array empty");
/*
@ -1039,7 +1079,40 @@ class Acc_Ledger extends jrn_def_sql
$tot_cred=0;
$tot_deb=0;
$msg=array();
/* Check currency : rate cannot be equal to 0 */
$currency_rate=$http->extract($p_array,"p_currency_rate","number");
if ( $currency_rate <=0 ) {
throw new Exception(_("Taux de conversion doit être supérieur à 0"),3);
}
/* Check currency : Does the currency parameter exist */
$currency_code=$http->extract($p_array,"p_currency_code","number");
$currency=new Acc_Currency($this->db,$currency_code);
if ( $currency->get_code() == -1 )
{
throw new Exception(_('Devise inconnue'), 3);
}
/* -- check the accounting for error of exchange -*/
if ( $currency->get_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);
}
}
/* check if we can write into this ledger */
if ($g_user->check_jrn($p_jrn)!='W')
throw new Exception(_('Accès interdit'), 20);
@ -1047,12 +1120,12 @@ class Acc_Ledger extends jrn_def_sql
/* check for a double reload */
if (isset($mt)&&$this->db->count_sql('select jr_mt from jrn where jr_mt=$1',
array($mt))!=0)
throw new Exception('Double Encodage', 5);
throw new Exception(_('Double Encodage'), 5);
// Check the periode and the date
if (isDate($e_date)==null)
{
throw new Exception('Date invalide', 2);
throw new Exception(_('Date invalide'), 2);
}
$periode=new Periode($this->db);
/* find the periode if we have enabled the check_periode
@ -1076,7 +1149,7 @@ class Acc_Ledger extends jrn_def_sql
// Periode ferme
if ($this->is_closed($periode->p_id)==1)
{
throw new Exception('Periode fermee', 6);
throw new Exception(_('Periode fermee'), 6);
}
/* check if we are using the strict mode */
if ($this->check_strict()==true)
@ -1085,8 +1158,10 @@ class Acc_Ledger extends jrn_def_sql
operation */
$last_date=$this->get_last_date();
if ($last_date!=null&&cmpDate($e_date, $last_date)<0)
throw new Exception(_('Vous utilisez le mode strict la dernière operation est la date du ')
.$last_date.' '._('vous ne pouvez pas encoder à une date antérieure'),
throw new Exception(
sprintf (
_('Vous utilisez le mode strict la dernière operation est la date du %s
vous ne pouvez pas encoder à une date antérieure',$last_date)),
15);
}
@ -1111,7 +1186,7 @@ class Acc_Ledger extends jrn_def_sql
throw new Exception("La fiche quick_code = ".
$f->quick_code." n'est pas dans ce journal", 4);
if (strlen(trim(${'qc_'.$i}))!=0&&isNumber(${'amount'.$i})==0)
throw new Exception('Montant invalide', 3);
throw new Exception(_('Montant invalide'), 3);
$strPoste=$f->strAttribut(ATTR_DEF_ACCOUNT);
if ($strPoste=='')
@ -1128,9 +1203,11 @@ class Acc_Ledger extends jrn_def_sql
if (isset(${'poste'.$i})&&strlen(trim(${'poste'.$i}))!=0)
{
$p=new Acc_Account_Ledger($this->db, ${'poste'.$i});
if ($p->belong_ledger($p_jrn)<0)
throw new Exception(_("Le poste")." ".$p->id." "._("n'est pas dans ce journal"),
if ($p->belong_ledger($p_jrn)<0) {
throw new Exception(sprintf (
_("Le poste %s n'est pas dans ce journal",$p->id)),
5);
}
if (strlen(trim(${'poste'.$i}))!=0&&isNumber(${'amount'.$i})==0)
throw new Exception(_('Poste invalide ['.${'poste'.$i}.']'),
3);
@ -1140,7 +1217,7 @@ class Acc_Ledger extends jrn_def_sql
$card_id=$p->find_card();
if (!empty($card_id))
{
$str_msg=" Le poste ".$p->id." appartient à ".count($card_id)." fiche(s) dont :";
$str_msg=sprintf(_(" Le poste %s appartient à fiche(s) dont : %s"),$p->id,count($card_id));
$max=(count($card_id)>MAX_COMPTE_CARD)?MAX_COMPTE_CARD:count($card_id);
for ($x=0; $x<$max; $x++)
{
@ -1154,7 +1231,7 @@ class Acc_Ledger extends jrn_def_sql
}
$account=new Acc_Account($this->db,${"poste".$i});
if ( $account->get_parameter("pcm_direct_use") == "N") {
throw new Exception(_("Utilisation directe interdite du poste comptable ${"poste".$i}"));
throw new Exception(sprintf (_("Utilisation directe interdite du poste comptable %s"), ${"poste".$i}));
}
}
}
@ -1202,8 +1279,12 @@ class Acc_Ledger extends jrn_def_sql
function save($p_array=null)
{
if ($p_array==null)
{
throw new Exception('save cannot use a empty array');
}
global $g_parameter;
bcscale(4);
$http=new HttpInput();
extract($p_array, EXTR_SKIP);
try
{
@ -1234,6 +1315,12 @@ class Acc_Ledger extends jrn_def_sql
}
$count=0;
// currency
$currency_code=$http->extract($p_array, "p_currency_code","number");
$currency_rate=$http->extract($p_array, "p_currency_rate","number");
$currency_rate_ref=new Acc_Currency($this->db, $currency_code);
for ($i=0; $i<$nb_item; $i++)
{
if (!isset(${'qc_'.$i})&&!isset(${'poste'.$i}))
@ -1273,14 +1360,25 @@ class Acc_Ledger extends jrn_def_sql
$acc_op->desc=null;
if (strlen(trim(${'ld'.$i}))!=0)
$acc_op->desc=${'ld'.$i};
$acc_op->amount=round(${'amount'.$i}, 2);
// Amount in default currency , usually EUR
$acc_op->amount=round(bcdiv(${'amount'.$i},$p_currency_rate),2);
$acc_op->grpt=$seq;
$acc_op->poste=$poste;
$acc_op->jrn=$this->id;
$acc_op->type=(isset(${'ck'.$i}))?'d':'c';
$acc_op->qcode=$quick_code;
$j_id=$acc_op->insert_jrnx();
$tot_amount+=round($acc_op->amount, 2);
// Save in currency
$operation_currency=new Operation_currency_SQL($this->db);
$operation_currency->oc_amount=round(${'amount'.$i}, 2);
$operation_currency->oc_vat_amount=0;
$operation_currency->oc_price_unit=0;
$operation_currency->j_id=$j_id;
$operation_currency->insert();
$tot_amount=bcadd($tot_amount,round($acc_op->amount, 2));
$tot_deb+=($acc_op->type=='d')?$acc_op->amount:0;
$tot_cred+=($acc_op->type=='c')?$acc_op->amount:0;
if ($g_parameter->MY_ANALYTIC!="nu")
@ -1290,27 +1388,68 @@ class Acc_Ledger extends jrn_def_sql
// for each item, insert into operation_analytique */
$op=new Anc_Operation($this->db);
$op->set_currency_rate($currency_rate);
$op->oa_group=$group;
$op->j_id=$j_id;
$op->oa_date=$e_date;
$op->oa_debit=($acc_op->type=='d' )?'t':'f';
$op->oa_description=$desc;
$op->save_form_plan($p_array, $count, $j_id);
// send the amount in default currency to analytic
$an_array=$p_array;
$an_array['amount'.$i]=$acc_op->amount;
$op->save_form_plan($an_array, $count, $j_id);
$count++;
}
}
}// loop for each item
$acc_end=new Acc_Operation($this->db);
// Check the balance
if ( $tot_deb != $tot_cred ) {
$diff=bcsub($tot_cred, $tot_deb);
// store the difference in currency_rounded_delta
$poste_cred = $g_parameter->MY_DEFAULT_ROUND_ERROR_CRED;
$side="c";
if ( $diff > 0 )
{
$poste=$g_parameter->MY_DEFAULT_ROUND_ERROR_DEB;
$side="d";
}
// insert difference of change
$acc_change=new Acc_Operation($this->db);
$acc_change->amount=abs($diff);
$acc_change->grpt=$seq;
$acc_change->poste=$poste;
$acc_change->jrn=$this->id;
$acc_change->type=$side;
$acc_change->date=$e_date;
$acc_change->desc=_("Différence de change");
$change_j_id=$acc_change->insert_jrnx();
$tot_deb=bcadd($tot_deb,$diff);
}
$acc_end->amount=$tot_deb;
if ($check_periode==false)
{
$acc_end->periode=$oPeriode->p_id;
}
$acc_end->date=$e_date;
$acc_end->desc=$desc;
$acc_end->grpt=$seq;
$acc_end->jrn=$this->id;
$acc_end->mt=$mt;
$acc_end->jr_optype=$jr_optype;
$acc_end->currency_id=$currency_code;
$acc_end->currency_rate=$currency_rate;
$acc_end->currency_rate_ref=$currency_rate_ref->get_rate();
$jr_id=$acc_end->insert_jrn();
$this->jr_id=$jr_id;
if ($jr_id==false)
throw new Exception(_('Balance incorrecte'));
@ -1788,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';
@ -2958,19 +3099,37 @@ class Acc_Ledger extends jrn_def_sql
}
/**
* Create a select from value for currency and add javascript to update $p_currency_rate and
* $p_eur_amount
* $p_eur_amount
* @param string DOMID $p_currency_code
* @param string DOMID $p_currency_rate
* @param string DOMID $p_eur_amount
*/
function CurrencyInput($p_currency_code,$p_currency_rate,$p_eur_amount)
function CurrencyInput($p_currency_code, $p_currency_rate, $p_eur_amount)
{
$currency = new Acc_Currency($this->db);
$select=$currency->select_currency();
$select->javascript=sprintf('onchange="LedgerCurrencyUpdate(\'%s\',\'%s\',\'%s\',\'%s\',\'%s\');$(\'update_p_currency_rate\').innerHTML=$(\'p_currency_rate\').value;"',
Dossier::id(),$select->name,$p_currency_code,$p_currency_rate,$p_eur_amount);
$type=$this->get_type();
$currency=new Acc_Currency($this->db);
$select=$currency->select_currency();
if ($type =='ODS')
{
$select->javascript=sprintf('onchange="LedgerCurrencyUpdateMisc(\'%s\',\'%s\',\'%s\',\'%s\',\'%s\');'.
'$(\'update_p_currency_rate\').innerHTML=$(\'p_currency_rate\').value;"',
Dossier::id(), $select->name, $p_currency_code, $p_currency_rate, $p_eur_amount);
}
elseif ($type == 'ACH' || $type == 'VEN')
{
$select->javascript=sprintf('onchange="LedgerCurrencyUpdate(\'%s\',\'%s\',\'%s\',\'%s\',\'%s\');'.
'$(\'update_p_currency_rate\').innerHTML=$(\'p_currency_rate\').value;"',
Dossier::id(), $select->name, $p_currency_code, $p_currency_rate, $p_eur_amount);
}
else
{
throw new Exception(_("Journal type non déterminé"));
}
return $select;
}
/**
* @brief returns the code iso of the default currency for this ledger
*/

View file

@ -639,24 +639,54 @@ class Acc_Ledger_Fin extends Acc_Ledger
$cur_rate=$acc_currency->get_rate_date($e_date);
$default_currency=new Acc_Currency($this->db , 0);
// saldo
$r.='<br>'.sprintf(_("Ancien solde = %f %s"),$solde, $cur);
$r .= "<table>";
$r .= tr(
td(_("Ancien solde")) .
td(nbm($solde).$cur, 'class="num"')
);
$new_solde=bcadd($solde,$tot_amount);
$r.='<br>'.sprintf(_("Nouveau solde = %f %s"),$new_solde, $cur);
$r.='<br>'.sprintf(_("Difference = %f %s"), $tot_amount, $cur);
$r .= tr(
td(_("Nouveau solde")) .
td(nbm($new_solde).$cur, ' class="num"')
);
$r .= tr(
td(_("Difference")) .
td(nbm($tot_amount).$cur, ' class="num"')
);
$r.=tr(
td(_("Taux")).
td($cur_rate)
);
$r.=tr(
td(_("Nouveau solde")).
td(bcdiv($new_solde,$cur_rate).$default_currency->get_code(), ' class="num"')
);
$r.='</table>';
$r.='<br>'.sprintf(_("Taux = %s"),$cur_rate);
$r.='<br>'.sprintf(_("Nouveau solde = %f %s"),bcmul($new_solde,$cur_rate),$default_currency->get_code());
} else {
$cur=$acc_currency->get_code();
// saldo
$r.='<br>'.sprintf(_("Ancien solde = %f %s"),$solde, $cur);
$new_solde=bcadd($new_solde,$tot_amount);
$r.='<br>'.sprintf(_("Nouveau solde = %f %s"),$new_solde, $cur);
$r.='<br>'.sprintf(_("Difference = %f %s"), $tot_amount, $cur);
$r .= "<table>";
$r .= tr(
td(_("Ancien solde")) .
td(nbm($solde).$cur, 'class="num"')
);
$new_solde=bcadd($solde,$tot_amount);
$r .= tr(
td(_("Nouveau solde")) .
td(nbm($new_solde).$cur, ' class="num"')
);
$r .= tr(
td(_("Difference")) .
td(nbm($tot_amount).$cur, ' class="num"')
);
$r.='</table>';
}
// check for upload piece
@ -803,7 +833,7 @@ class Acc_Ledger_Fin extends Acc_Ledger
// convert to EUR if needed and round it
$amount_input=${"e_other$i" . "_amount"} = round(${"e_other$i" . "_amount"}, 2);
$amount_eur=bcmul($amount_input,$currency_rate);
$amount_eur=bcdiv($amount_input,$currency_rate);
@ -852,7 +882,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 +913,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

@ -706,7 +706,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
}
// insert into quant_purchase
//-----
$price_euro=bcmul(${'e_march'.$i.'_price'}, $p_currency_rate);
$price_euro=bcdiv(${'e_march'.$i.'_price'}, $p_currency_rate);
if ( $g_parameter->MY_TVA_USE=='Y')
{
@ -788,7 +788,14 @@ class Acc_Ledger_Purchase extends Acc_Ledger
}
$let_client=$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_client ;
$operation_currency->insert();
if ( $g_parameter->MY_TVA_USE=='Y')
{
/* save all vat
@ -933,9 +940,9 @@ class Acc_Ledger_Purchase extends Acc_Ledger
$cust_amount=bcsub($cust_amount, $tot_tva_reversed);
// Convert paid amount in EUR
$acompte=bcmul($acompte, $p_currency_rate);
$acompte_defcur=bcdiv($acompte, $p_currency_rate);
$famount=bcsub($cust_amount,$acompte);
$famount=bcsub($cust_amount,$acompte_defcur);
$acc_pay->poste=$poste_val;
$acc_pay->qcode=$fqcode;
@ -1397,11 +1404,12 @@ class Acc_Ledger_Purchase extends Acc_Ledger
$currency_select->selected=$http->request('p_currency_code','string',0);
$currency_input=new INum("p_currency_rate");
$currency_input->prec=6;
$currency_input->id="p_currency_rate";
$currency_input->value=$http->request('p_currency_rate','string',1);
$currency_input->javascript='onchange="format_number(this,4);CurrencyCompute(\'p_currency_rate\',\'p_currency_euro\');"';
$currency_input->javascript='onchange="format_number(this,6);CurrencyCompute(\'p_currency_rate\',\'p_currency_euro\');"';
$currency=new Acc_Currency($this->db,0);
//
// Button for template operation
@ -1685,10 +1693,11 @@ class Acc_Ledger_Purchase extends Acc_Ledger
$decalage=($g_parameter->MY_TVA_USE == 'Y')?'<td></td><td></td><td></td><td></td>':'<td></td>';
$tot = round(bcadd($tot_amount, $tot_tva), 2);
$str_tot=_('Totaux');
$tot_eur=round(bcmul($tot, $p_currency_rate),2);
$tot_eur=round(bcdiv($tot, $p_currency_rate),2);
// Get currency code
$str_code='EUR';
// Get currency code
$default_currency=new Acc_Currency($this->db,0);
$str_code=$default_currency->get_code();
if ( $p_currency_code != 0 ) {
$acc_currency=new Acc_Currency($this->db);
$acc_currency->set_id($p_currency_code);

View file

@ -309,7 +309,7 @@ class Acc_Ledger_Sold extends Acc_Ledger {
$amount_currency = bcmul(${'e_march' . $i . '_price'}, ${'e_quant' . $i});
// convert amount to currency
$amount=bcmul($amount_currency,$p_currency_rate);
$amount=bcdiv($amount_currency,$p_currency_rate);
$tot_amount = bcadd($tot_amount, $amount);
$tot_amount = round($tot_amount, 2);
@ -363,7 +363,7 @@ class Acc_Ledger_Sold extends Acc_Ledger {
$l->load();
$tva_item_currency = bcmul($amount, $l->get_parameter('rate'));
}
$tva_item=bcmul($tva_item_currency,$p_currency_rate);
$tva_item=bcdiv($tva_item_currency,$p_currency_rate);
$tva_item=round($tva_item,2);
if (isset($tva[$idx_tva]))
{
@ -413,7 +413,7 @@ class Acc_Ledger_Sold extends Acc_Ledger {
$op->save_form_plan($_POST, $i, $j_id);
}
$price_euro=bcmul(${'e_march'.$i.'_price'}, $p_currency_rate);
$price_euro=bcdiv(${'e_march'.$i.'_price'}, $p_currency_rate);
if ($g_parameter->MY_TVA_USE == 'Y') {
/* save into quant_sold */
$r = $this->db->exec_sql("select insert_quant_sold ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)", array(null, /* 1 */
@ -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' )
@ -619,7 +627,7 @@ class Acc_Ledger_Sold extends Acc_Ledger {
$poste_val = $sposte;
}
// Convert paid amount in EUR
$acompte_eur=bcmul($acompte, $p_currency_rate);
$acompte_eur=bcdiv($acompte, $p_currency_rate);
$famount=bcsub($cust_amount,$acompte_eur);
$acc_pay->poste = $poste_val;
@ -942,12 +950,13 @@ class Acc_Ledger_Sold extends Acc_Ledger {
// Add the sum
$decalage=($g_parameter->MY_TVA_USE == 'Y')?'<td></td><td></td><td></td><td></td>':'<td></td>';
$tot = bcadd($tot_amount, $tot_tva, 2);
$tot_eur=round(bcmul($tot, $p_currency_rate),2);
$tot_eur=round(bcdiv($tot, $p_currency_rate),2);
$tot=nbm($tot);
$str_tot=_('Totaux');
// Get currency code
$str_code='EUR';
$default_currency=new Acc_Currency($this->db,0);
$str_code=$default_currency->get_code();
if ( $p_currency_code != 0 ) {
$acc_currency=new Acc_Currency($this->db);
$acc_currency->set_id($p_currency_code);
@ -1448,7 +1457,7 @@ EOF;
$Price = new INum();
$Price->setReadOnly(false);
$Price->size = 9;
$Price->javascript = "onBlur='format_number(this,4);clean_tva($i);compute_ledger($i)'";
$Price->javascript = "onBlur=\"format_number(this,4);clean_tva($i);compute_ledger($i);\"";
$array[$i]['pu'] = $Price->input("e_march" . $i . "_price", $march_price);
$array[$i]['tva'] = '';
$array[$i]['amount_tva'] = '';
@ -1461,7 +1470,7 @@ EOF;
$Tva->set_attribute('compute', $i);
$Tva->set_filter("sale");
$Tva->js = 'onblur="format_number(this);clean_tva(' . $i . ');compute_ledger(' . $i . ')"';
$Tva->js = 'onblur="format_number(this);clean_tva(' . $i . ');compute_ledger(' . $i . ');"';
$Tva->value = $march_tva_id;
$array[$i]['tva'] = $Tva->input("e_march$i" . "_tva_id");
// vat amount
@ -1479,7 +1488,7 @@ EOF;
$Quantity = new INum();
$Quantity->setReadOnly(false);
$Quantity->size = 8;
$Quantity->javascript = "onChange='format_number(this);clean_tva($i);compute_ledger($i)'";
$Quantity->javascript = "onChange=\"format_number(this);clean_tva($i);compute_ledger($i);\"";
$array[$i]['quantity'] = $Quantity->input("e_quant" . $i, $quant);
}// foreach article
$f_type = _('Client');
@ -1490,10 +1499,11 @@ EOF;
$currency_input=new INum("p_currency_rate");
$currency_input->id="p_currency_rate";
$currency_input->prec=6;
$currency_input->value=$http->request('p_currency_rate','string',1);
$currency_input->javascript='onchange="format_number(this,4);CurrencyCompute(\'p_currency_rate\',\'p_currency_euro\');"';
$currency=new Acc_Currency($this->db,0);
//
// Button for template operation

View file

@ -799,7 +799,7 @@ class Anc_Operation
$op->oa_group=$this->oa_group;
$op->j_id=$p_j_id;
// convert oa_amount to EUR
$op->oa_amount=bcmul($val[$p_item][$row],$this->currency_rate);
$op->oa_amount=bcdiv($val[$p_item][$row],$this->currency_rate);
$op->oa_debit=$this->oa_debit;
$op->oa_date=$this->oa_date;

View file

@ -29,7 +29,7 @@ require_once NOALYSS_INCLUDE.'/database/currency_history_sql.class.php';
/**
* Manage the configuration of currency , add currency, rate, remove and update
* Concerned tables are v_currency_last_value _SQL , Currency_SQL , Currency_History_SQL
* Concerned tables are v_currency_last_value_SQL , Currency_SQL , Currency_History_SQL
* currency_id = 0 for the default currency , -1 for a new one
*/
class Currency_MTable extends Manage_Table_SQL
@ -40,12 +40,12 @@ class Currency_MTable extends Manage_Table_SQL
* @param Data $p_table
* @example test_currency_mtable.php
*/
function __construct(Data_SQL $p_table)
function __construct(V_Currency_Last_Value_SQL $p_table)
{
parent::__construct($p_table);
// If currency , cannot be deleted
if ($this->is_currency_used()==TRUE)
if ($this->is_currency_used($p_table->currency_id)==TRUE)
{
$this->set_delete_row(FALSE);
}
@ -68,11 +68,17 @@ class Currency_MTable extends Manage_Table_SQL
/**
* returns TRUE the currency is used otherwise FALSE. We cannot delete a currency which is used in a
* operation
* @param integer $p_id currency_id
* @returns boolean true if currency is used
* @todo Currency_MTable.is_currency_used to implement
*/
function is_currency_used()
function is_currency_used($p_id)
{
global $cn;
$cnt_used=$cn->get_value(" select count(*) from jrn where currency_id=$1",[$p_id]);
if ($cnt_used > 0)
{
return TRUE;
}
return FALSE;
}
/**
@ -92,7 +98,7 @@ class Currency_MTable extends Manage_Table_SQL
currency_id=$1", array($record->currency_id));
$new_rate_date=new IDate("new_rate_date");
$new_rate_value=new INum("new_rate_value");
$new_rate_value->prec=4;
$new_rate_value->prec=6;
if ($record->currency_id!=-1)
{
require NOALYSS_TEMPLATE."/currency_mtable_input.php";
@ -286,23 +292,42 @@ class Currency_MTable extends Manage_Table_SQL
function from_request()
{
$http=new HttpInput();
$this->table->cr_code_iso=mb_strtoupper(strip_tags($http->request("cr_code_iso")));
$this->table->cr_name=strip_tags($http->request("cr_name"));
$this->table->cr_code_iso=mb_strtoupper($http->request("cr_code_iso"));
$this->table->cr_name=$http->request("cr_name");
$this->table->currency_id=$http->request("p_id", "number");
$this->table->ch_value=$http->request("new_rate_value");
$this->table->str_from=$http->request("new_rate_date");
}
/**
* We don't display the default currency (id := -1)
*
* We cannot modify the default currency (id := 0)
*/
function display_row($p_row)
{
if ($p_row['currency_id']==0)
{
$this->set_update_row(FALSE);
$this->set_delete_row(FALSE);
parent::display_row($p_row);
return;
}
if ($this->is_currency_used($p_row['currency_id'])==TRUE)
{
$this->set_delete_row(FALSE);
} else {
$this->set_delete_row(TRUE);
}
$this->set_update_row(TRUE);
parent::display_row($p_row);
}
/**
* Delete after checking the currency is not used
*/
function delete()
{
$id=$this->get_table()->currency_id;
if ( $this->is_currency_used($id) == FALSE) $this->table->delete();
}
}

View file

@ -1276,7 +1276,11 @@ class Fiche
sum_oc_amount as oc_amount,
sum_oc_vat_amount as oc_vat_amount
from jrnx as j1 left join jrn_def on jrn_def_id=j_jrn_def
left join v_all_card_currency as v1 on (v1.j_id=j1.j_id )
left join (select j_id,
coalesce(oc_amount,0) as sum_oc_amount ,
coalesce(oc_vat_amount,0) as sum_oc_vat_amount
from jrnx left join operation_currency using (j_id)
) as v1 on (v1.j_id=j1.j_id )
left join jrn on jr_grpt_id=j_grpt".
" left join parm_periode on (p_id=jr_tech_per) ".
" where j_qcode=$1 and ".

View file

@ -769,7 +769,7 @@ class Follow_Up
// if there are no records return a message
if (sizeof($a_row)==0 or $a_row==false)
if ($a_row==false || sizeof($a_row)==0 )
{
$r='<div style="clear:both">';
$r.='<hr>Aucun enregistrement trouvé';

View file

@ -45,6 +45,8 @@ class Noalyss_Parameter_Folder
var $MY_ALPHANUM;
var $MY_UPDLAB;
var $MY_STOCK;
var $MY_DEFAULT_ROUND_ERROR_DEB;
var $MY_DEFAULT_ROUND_ERROR_CRED;
// constructor
function __construct($p_cn)
@ -124,7 +126,8 @@ class Noalyss_Parameter_Folder
$this->save('MY_ALPHANUM');
$this->save('MY_UPDLAB');
$this->save('MY_STOCK');
$this->save('MY_CURRENCY');
$this->save('MY_DEFAULT_ROUND_ERROR_DEB');
$this->save('MY_DEFAULT_ROUND_ERROR_CRED');
}

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

@ -49,7 +49,8 @@ if (isset($_POST['record_company']))
$m->MY_UPDLAB = $http->post("p_updlab");
$m->MY_STOCK =$http->post("p_stock");
$m->MY_CURRENCY =$http->post("p_currency");
$m->MY_DEFAULT_ROUND_ERROR_DEB=$http->post("p_round_error_deb");
$m->MY_DEFAULT_ROUND_ERROR_CRED=$http->post("p_round_error_cred");
$m->Update();
}
@ -117,6 +118,18 @@ $use_currency->table = 1;
$use_currency->value = $updlab_array;
$use_currency->selected = $my->MY_CURRENCY;
$default_error_deb=new IPoste("p_round_error_deb",$my->MY_DEFAULT_ROUND_ERROR_DEB);
$default_error_deb->name = 'p_round_error_deb';
$default_error_deb->set_attribute('gDossier',Dossier::id());
$default_error_deb->set_attribute('jrn',0);
$default_error_deb->set_attribute('account','p_round_error_deb');
$default_error_cred=new IPoste("p_round_error_deb",$my->MY_DEFAULT_ROUND_ERROR_CRED);
$default_error_cred->name = 'p_round_error_cred';
$default_error_cred->set_attribute('gDossier',Dossier::id());
$default_error_cred->set_attribute('jrn',0);
$default_error_cred->set_attribute('account','p_round_error_cred');
// other parameters
$all = new IText();
$all->table = 1;
@ -151,7 +164,18 @@ echo "<tr>" . td(_("Suggérer la date"), 'style="text-align:right"') . $date_sug
echo '<tr>' . td(_('Afficher la période comptable pour éviter les erreurs de date'), 'style="text-align:right"') . $check_periode->input('p_check_periode', $strict_array) . '</tr>';
echo '<tr>' . td(_('Utilisez des postes comptables alphanumérique'), 'style="text-align:right"') . $alpha_num->input('p_alphanum') . '</tr>';
echo '<tr>' . td(_('Changer le libellé des détails'), 'style="text-align:right"') . $updlab->input('p_updlab') . '</tr>';
echo '<tr>' .
td(_("Poste comptable de CHARGE (D) pour les différences d'arrondi pour les opérations en devise")).
'<td>'.$default_error_deb->input().
'</td>'.
'</tr>';
echo '<tr>' .
td(_("Poste comptable en PRODUIT (C) pour les différences d'arrondi pour les opérations en devise")).
'<td>'.$default_error_cred->input().
'</td>'.
'</tr>';
echo "</table>";
echo HtmlInput::submit("record_company", _("Sauve"));
echo "</form>";

View file

@ -46,7 +46,7 @@ if ( $ledger_id == 0)
$def_ledger=$Ledger->get_first('fin');
if ( empty ($def_ledger))
{
exit('Pas de journal disponible');
exit(_('Pas de journal disponible'));
}
$ledger_id=$def_ledger['jrn_def_id'];
}

View file

@ -40,13 +40,15 @@ global $g_user,$http;
$cn = Dossier::connect();
$id_predef = (isset($_REQUEST['p_jrn_predef'])) ? $_REQUEST['p_jrn_predef'] : -1;
$id_ledger = (isset($_REQUEST['p_jrn'])) ? $_REQUEST['p_jrn'] : $id_predef;
$id_predef = $http->request('p_jrn_predef','number',-1);
$id_ledger = $http->request('p_jrn','number',$id_predef);
$ledger = new Acc_Ledger($cn, $id_ledger);
$first_ledger = $ledger->get_first('ODS');
if ( empty ($first_ledger))
{
exit('Pas de journal disponible');
exit(_('Pas de journal disponible'));
}
$ledger->id = ($ledger->id == -1) ? $first_ledger['jrn_def_id'] : $id_ledger;
@ -91,7 +93,7 @@ elseif (isset($_POST['save']))
$ledger->save($array);
$jr_id = $cn->get_value('select jr_id from jrn where jr_internal=$1', array($ledger->internal));
echo '<h2> Op&eacute;ration enregistr&eacute;e Piece ' . h($ledger->pj) . '</h2>';
echo '<h2>'._("Opération enregistrée")._("Piece") . h($ledger->pj) . '</h2>';
if (strcmp($ledger->pj, $_POST['e_pj']) != 0)
{
echo '<h3 class="notice">' . _('Attention numéro pièce existante, elle a du être adaptée') . '</h3>';

View file

@ -108,7 +108,7 @@ if ( !defined ("NOALYSS_PACKAGE_REPOSITORY")) {
if ( ! defined ("SYSINFO_DISPLAY")) {
define ("SYSINFO_DISPLAY",TRUE);
}
define ("DBVERSION",132);
define ("DBVERSION",133);
define ("MONO_DATABASE",25);
define ("DBVERSIONREPO",18);
define ('NOTFOUND','--not found--');

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

@ -57,11 +57,8 @@ class Impress
else
$cond="( j_date >= to_date('$p_start','DD.MM.YYYY') and j_date <= to_date('$p_end','DD.MM.YYYY'))";
include_once("class/acc_account_ledger.class.php");
while (preg_match_all("(\[[0-9]*[A-Z]*%*c*d*s*\])",$p_formula,$e) == true)
{
// remove the [ ]
$x=$e[0];
foreach ($x as $line)

View file

@ -85,7 +85,7 @@ class ISelect extends HtmlInput
}
}
// $r='<span class="input_text_ro">'.$r.'</span>';
if ( $this->table == 1 ) $a='<td>'.$r.'</td>';
if ( $this->table == 1 ) $r='<td>'.$r.'</td>';
return $r;
}
/*!\brief print in html the readonly value of the widget*/
@ -112,11 +112,10 @@ class ISelect extends HtmlInput
* // will be turned into
* array( array("value"=>'M,"label"=>"Mister")...)
* @endcode
* @param type $p_array
* @return type
* @param array $p_array
*/
public function transform($p_array) {
if (count($p_array)==0) return array();
if (! is_array($p_array) || count($p_array)==0) return ;
$a_ret=array();
foreach ($p_array as $key=>$value) {
$a_ret['value']=$key;

View file

@ -893,7 +893,7 @@ function check()
$text->size=$min_size;
echo $text->input();
}
elseif ($this->a_type[$key]=="numeric")
elseif ($this->a_type[$key]=="numeric") // number 2 decimale
{
$text=new INum($key);
$text->value=$value;
@ -901,6 +901,24 @@ function check()
$text->size=$min_size;
echo $text->input();
}
elseif ($this->a_type[$key]=="numeric4") // number 4 decimale
{
$text=new INum($key);
$text->prec=4;
$text->value=$value;
$min_size=(strlen($value)<10)?10:strlen($value)+1;
$text->size=$min_size;
echo $text->input();
}
elseif ($this->a_type[$key]=="numeric6") // number 6 decimale
{
$text=new INum($key);
$text->prec=6;
$text->value=$value;
$min_size=(strlen($value)<10)?10:strlen($value)+1;
$text->size=$min_size;
echo $text->input();
}
elseif ($this->a_type[$key]=="date")
{
$text=new IDate($key);

View file

@ -38,7 +38,7 @@ echo h2(_("Attention, cette opération n'est pas encore sauvée : vous devez enc
echo '</div>';
echo '<FORM METHOD="POST" enctype="multipart/form-data" class="print">';
echo HtmlInput::request_to_hidden(array('ac'));
echo HtmlInput::request_to_hidden(array('ac','p_currency_code','p_currency_rate'));
echo $ledger->confirm($_POST,false);

View file

@ -31,8 +31,9 @@ require_once NOALYSS_INCLUDE.'/lib/iconcerned.class.php';
global $g_user,$g_parameter;
$cn=Dossier::connect();
$id_predef = (isset($_REQUEST['p_jrn_predef'])) ? $_REQUEST['p_jrn_predef'] : -1;
$id_ledger = (isset($_REQUEST['p_jrn'])) ? $_REQUEST['p_jrn'] : $id_predef;
$id_predef = $http->request('p_jrn_predef','number',-1);
$id_ledger = $http->request('p_jrn','number',$id_predef);
$ledger = new Acc_Ledger($cn, $id_ledger);
$first_ledger=$ledger->get_first('ODS');
$ledger->id = ($ledger->id == -1) ? $first_ledger['jrn_def_id'] : $id_ledger;
@ -73,6 +74,8 @@ echo '<form method="post" class="print" onsubmit="return controleBalance();" >'
echo dossier::hidden();
echo HtmlInput::request_to_hidden(array('ac','jr_optype'));
$default_currency=new Acc_Currency($cn,0);
echo $ledger->input($p_post);
@ -80,15 +83,29 @@ echo $ledger->input($p_post);
echo '<div style="position:absolute;width:40%;right:20px">';
echo '<table class="info_op">'.
'<tr>'.td(_('Débit')) . '<td id="totalDeb"></td>' .
td(_('Crédit')) . ' <td id="totalCred"></td>' .
td(_('Difference')) . ' <td id="totalDiff"></td>';
'<tr>'.td('').
td(_('Débit')) .
'<td id="totalDeb" class="num"></td>' .
td(_('Crédit')) .
' <td id="totalCred" class="num"></td>' .
td(_('Difference')) .
' <td id="totalDiff"></td>'.
'</tr>';
// For currency
echo '<tr id="row_currency">'.td($default_currency->get_code()).
td(_('Débit')) .
'<td id="default_currency_deb" class="num"></td>' .
td(_('Crédit')) .
' <td id="default_currency_cred" class="num"></td>' .
td().
'</tr>';
echo '</table>';
echo '</div>';
$iconcerned=new IConcerned('jrn_concerned');
$iconcerned->amount_id="totalDeb";
echo "Opération rapprochée : ".$iconcerned->input();
printf (_("Opération rapprochée : %s"),$iconcerned->input());
echo '<p>';
echo HtmlInput::button('add', _('Ajout d\'une ligne'), 'onClick="quick_writing_add_row()"');

View file

@ -79,7 +79,7 @@ echo $mtable->display_table(" where pcm_val::text like '{$g_start}%' order by pc
<div id="go_up" class="inner_box" style="padding:0px;left:auto;width:250px;height: 100px;display:none;position:fixed;bottom:5px;right:20px">
<div style="margin:3%;padding:3%">
<a class="icon" href="#up_top" >&#xe81a;</a><a href="javascript:show_calc()" class="icon">&#xf1ec;</a>
<input type="button" id="pcmn_update_add_bt3" value="<?php echo _('Ajout poste comptable'); ?>">
<input type="button" class="smallbutton" id="pcmn_update_add_bt3" value="<?php echo _('Ajout poste comptable'); ?>">
</div>
</div>
</div>

View file

@ -1,6 +1,6 @@
begin;
drop VIEW public.v_detail_sale;
drop VIEW if exists public.v_detail_sale;
CREATE OR REPLACE VIEW public.v_detail_sale as
WITH m AS (
@ -145,6 +145,8 @@ join operation_currency as oc on (oc.j_id=q1.j_id)
group by x.j_poste,x.j_id
;
drop view if exists v_all_card_currency;
create or replace view v_all_card_currency as
select sum(oc_amount) as sum_oc_amount,sum(oc_vat_amount) as sum_oc_vat_amount,x.f_id,x.j_id
from

View file

@ -0,0 +1,15 @@
begin;
insert into "parameter" (pr_id ) values ('MY_DEFAULT_ROUND_ERROR_DEB');
insert into "parameter" (pr_id ) values ('MY_DEFAULT_ROUND_ERROR_CRED');
drop view if exists v_all_card_currency;
create or replace view v_all_card_currency as
select sum(oc_amount) as sum_oc_amount,sum(oc_vat_amount) as sum_oc_vat_amount,f_id,j_id
from
operation_currency
join jrnx using (j_id)
group by f_id,j_id;
commit ;
insert into version (val,v_description) values (133,'Currency : default accounting for currency difference ');
commit ;

View file

@ -67,7 +67,7 @@
</td>
<td>
<?=$currency_select->input()?>
<?=$currency_input->change()?>EUR
<?=$currency_input->change('CurrencyCompute(\'p_currency_rate\',\'p_currency_euro\');')?>
</td>
</tr>

View file

@ -164,6 +164,7 @@ $str_anc="";
}
echo '</tr>';
$sum_charge_euro=0;
for ($e = 0; $e < count($obj->det->array); $e++)
{
$row = '';
@ -251,7 +252,8 @@ $str_anc="";
*/
if ( $obj->det->currency_id != 0 ) {
$value=$obj->db->get_value("select oc_amount+oc_vat_amount from operation_currency where j_id=$1",[$q['j_id']]);
$row.=td(nbm($value,4),' class="num"');
$row.=td(nbm($value,2),' class="num"');
$sum_charge_euro=bcadd($sum_charge_euro,$value,2);
}
echo tr($row,$class);
@ -268,7 +270,7 @@ $str_anc="";
if ( $obj->det->currency_id != "" && $obj->det->currency_id > 0)
{
$currency=new Acc_Currency($obj->db, $obj->det->currency_id);
$row.= td(nbm($currency->sum_amount($obj->jr_id),4),' class="num" style="font-style:italic;font-weight: bolder;"');
$row.= td(nbm($sum_charge_euro),' class="num" style="font-style:italic;font-weight: bolder;"');
}
echo tr($row);
@ -287,7 +289,7 @@ $str_anc="";
echo $currency->get_code(),$four_space;
echo _("Taux utilisé"),"&nbsp;", $obj->det->currency_rate,$four_space;
echo _("Taux Réf"), "&nbsp;",$obj->det->currency_rate_ref.$four_space;
echo _("Montant en devise"), "&nbsp;",$currency->sum_amount($obj->jr_id).$four_space;
echo _("Montant en devise"), "&nbsp;",nbm($sum_charge_euro).$four_space;
}
?>

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">

View file

@ -112,7 +112,7 @@ echo th(_('Crédit'), 'style="text-align:right"');
$str_anc.= Anc_Plan::hidden($a_anc);
}
echo '</tr>';
$amount_idx=0;
$amount_idx=0; $sum_prod_currency=0;
for ($e=0;$e<count($obj->det->array);$e++) {
$row=''; $q=$obj->det->array;
$view_history = HtmlInput::history_account($q[$e]['j_poste'], $q[$e]['j_poste'], "", $exercice);
@ -159,6 +159,14 @@ $amount_idx=0;
$montant=td(nbm($q[$e]['j_montant']),'class="num"');
$row.=($q[$e]['j_debit']=='t')?$montant:td('');
$row.=($q[$e]['j_debit']=='f')?$montant:td('');
/*
* Compute total in currency if not default one
*/
if ( $obj->det->currency_id != 0 && $q[$e]['j_debit']=='f' ) {
$value=$obj->db->get_value("select oc_amount+oc_vat_amount from operation_currency where j_id=$1",[$q[$e]['j_id']]);
$sum_prod_currency=bcadd($sum_prod_currency,$value,2);
}
/* Analytic accountancy */
if ( $owner->MY_ANALYTIC != "nu" /*&& $div=='popup'*/){
if ( preg_match('/^(6|7)/',$q[$e]['j_poste'])) {
@ -188,6 +196,22 @@ $amount_idx=0;
}
?>
</table>
<?php
/*
* Info about currency if not in euro
*/
// Add a row with currency and amount
if ( $obj->det->currency_id != "" && $obj->det->currency_id > 0)
{
$currency=new Acc_Currency($obj->db, $obj->det->currency_id);
$four_space="&nbsp;"."&nbsp;"."&nbsp;"."&nbsp;";
echo $currency->get_code(),$four_space;
echo _("Taux utilisé"),"&nbsp;", $obj->det->currency_rate,$four_space;
echo _("Taux Réf"), "&nbsp;",$obj->det->currency_rate_ref.$four_space;
echo _("Montant en devise"), "&nbsp;",$sum_prod_currency,$four_space;
}
?>
</div>
<?php
require_once NOALYSS_TEMPLATE.'/ledger_detail_bottom.php';

View file

@ -122,6 +122,7 @@ echo $ipaid->input();
bcscale(2);
$total_htva = 0;
$total_tvac = 0;
$sum_prod_currency=0;
echo th(_('Quick Code'));
echo th(_('Description'));
echo th(_('Prix/Un'), 'style="text-align:right"');
@ -256,7 +257,8 @@ echo $ipaid->input();
*/
if ( $obj->det->currency_id != 0 ) {
$value=$obj->db->get_value("select oc_amount+oc_vat_amount from operation_currency where j_id=$1",[$q['j_id']]);
$row.=td(nbm($value,4),' class="num"');
$sum_prod_currency=bcadd($sum_prod_currency,$value,2);
$row.=td(nbm($value,2),' class="num"');
}
echo tr($row,$class);
@ -273,8 +275,7 @@ echo $ipaid->input();
//Display total in currency
if ( $obj->det->currency_id != "" && $obj->det->currency_id > 0)
{
$currency=new Acc_Currency($obj->db, $obj->det->currency_id);
$row.= td(nbm($currency->sum_amount($obj->jr_id),4),' class="num" style="font-style:italic;font-weight: bolder;"');
$row.= td(nbm($sum_prod_currency,2),' class="num" style="font-style:italic;font-weight: bolder;"');
}
echo tr($row);
?>
@ -298,7 +299,7 @@ echo $ipaid->input();
echo $currency->get_code(),$four_space;
echo _("Taux utilisé"),"&nbsp;", $obj->det->currency_rate,$four_space;
echo _("Taux Réf"), "&nbsp;",$obj->det->currency_rate_ref.$four_space;
echo _("Montant en devise"), "&nbsp;",$currency->sum_amount($obj->jr_id).$four_space;
echo _("Montant en devise"), "&nbsp;",$sum_prod_currency,$four_space;
}
?>
<?php

View file

@ -0,0 +1,13 @@
begin;
insert into "parameter" (pr_id ) values ('MY_DEFAULT_ROUND_ERROR_DEB');
insert into "parameter" (pr_id ) values ('MY_DEFAULT_ROUND_ERROR_CRED');
drop view if exists v_all_card_currency;
create or replace view v_all_card_currency as
select sum(oc_amount) as sum_oc_amount,sum(oc_vat_amount) as sum_oc_vat_amount,f_id,j_id
from
operation_currency
join jrnx using (j_id)
group by f_id,j_id;
commit ;