diff --git a/html/fid_card.php b/html/fid_card.php
index 1ee5d07ac..57577bb18 100644
--- a/html/fid_card.php
+++ b/html/fid_card.php
@@ -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 "
";
$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'],''.$fid.'',h($name));
- $qcode=str_ireplace($_REQUEST['FID'],''.$fid.'',h($quick_code));
- $desc=str_ireplace($_REQUEST['FID'],''.$fid.'',h($desc));
+ $name=str_ireplace($fid,''.$fid.'',h($name));
+ $qcode=str_ireplace($fid,''.$fid.'',h($quick_code));
+ $desc=str_ireplace($fid,''.$fid.'',h($desc));
printf('
%s %s %s
',
$quick_code,
$quick_code,
diff --git a/html/js/acc_currency.js b/html/js/acc_currency.js
index 51ff8ecc0..fdf49ab2a 100644
--- a/html/js/acc_currency.js
+++ b/html/js/acc_currency.js
@@ -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();
+
}
\ No newline at end of file
diff --git a/html/js/acc_ledger.js b/html/js/acc_ledger.js
index e488708d4..e51e7cce6 100644
--- a/html/js/acc_ledger.js
+++ b/html/js/acc_ledger.js
@@ -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');
+
}
/**
diff --git a/html/js/anc_script.js b/html/js/anc_script.js
index 50d255705..97e524de2 100644
--- a/html/js/anc_script.js
+++ b/html/js/anc_script.js
@@ -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)
{
diff --git a/html/js/compute_direct.js b/html/js/compute_direct.js
index 8773ace98..f145cc789 100644
--- a/html/js/compute_direct.js
+++ b/html/js/compute_direct.js
@@ -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 )
{
diff --git a/html/js/scripts.js b/html/js/scripts.js
index 4257023c8..ee099d888 100644
--- a/html/js/scripts.js
+++ b/html/js/scripts.js
@@ -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)
{
diff --git a/include/class/acc_account_ledger.class.php b/include/class/acc_account_ledger.class.php
index 640a4b1d8..b381a9f0e 100644
--- a/include/class/acc_account_ledger.class.php
+++ b/include/class/acc_account_ledger.class.php
@@ -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
"
';
+
}
// 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'});
}
diff --git a/include/class/acc_ledger_purchase.class.php b/include/class/acc_ledger_purchase.class.php
index af6f33e3b..f93bbae98 100644
--- a/include/class/acc_ledger_purchase.class.php
+++ b/include/class/acc_ledger_purchase.class.php
@@ -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')?'
':'
';
$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);
diff --git a/include/class/acc_ledger_sold.class.php b/include/class/acc_ledger_sold.class.php
index 0640e1009..cf76ce982 100644
--- a/include/class/acc_ledger_sold.class.php
+++ b/include/class/acc_ledger_sold.class.php
@@ -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')?'
':'
';
$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
diff --git a/include/class/anc_operation.class.php b/include/class/anc_operation.class.php
index 13445271f..aa3b19d3b 100644
--- a/include/class/anc_operation.class.php
+++ b/include/class/anc_operation.class.php
@@ -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;
diff --git a/include/class/currency_mtable.class.php b/include/class/currency_mtable.class.php
index 89ddf5afc..fa6203e1f 100644
--- a/include/class/currency_mtable.class.php
+++ b/include/class/currency_mtable.class.php
@@ -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();
+ }
}
diff --git a/include/class/fiche.class.php b/include/class/fiche.class.php
index fc02a9e31..91aaae84c 100644
--- a/include/class/fiche.class.php
+++ b/include/class/fiche.class.php
@@ -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 ".
diff --git a/include/class/follow_up.class.php b/include/class/follow_up.class.php
index 471b7ebd0..39d9a004f 100644
--- a/include/class/follow_up.class.php
+++ b/include/class/follow_up.class.php
@@ -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='
';
$r.='Aucun enregistrement trouvé';
diff --git a/include/class/noalyss_parameter_folder.class.php b/include/class/noalyss_parameter_folder.class.php
index 31b79b893..4d32dd558 100644
--- a/include/class/noalyss_parameter_folder.class.php
+++ b/include/class/noalyss_parameter_folder.class.php
@@ -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');
}
diff --git a/include/class/print_ledger_fin.class.php b/include/class/print_ledger_fin.class.php
index 1f3b82b0d..931da51a2 100644
--- a/include/class/print_ledger_fin.class.php
+++ b/include/class/print_ledger_fin.class.php
@@ -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);
diff --git a/include/class/print_ledger_misc.class.php b/include/class/print_ledger_misc.class.php
index ece4cc653..6773b7417 100644
--- a/include/class/print_ledger_misc.class.php
+++ b/include/class/print_ledger_misc.class.php
@@ -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);
diff --git a/include/company.inc.php b/include/company.inc.php
index 1dfaf3ecb..f433c3108 100644
--- a/include/company.inc.php
+++ b/include/company.inc.php
@@ -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 "
" . td(_("Suggérer la date"), 'style="text-align:right"') . $date_sug
echo '
' . td(_('Afficher la période comptable pour éviter les erreurs de date'), 'style="text-align:right"') . $check_periode->input('p_check_periode', $strict_array) . '