2 * Copyright (C) 2018 Dany De Bontridder <dany@alchimerys.be>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * @brief All the currency related ajax calls
24 * Delete a old currency rate via ajax, but all currency must have at least one rate, delete the rate and hide the
25 * row in the table "currency_rate_table"
26 * @param {int} p_dossier
28 * @see currency_mtable_input.php
30 * - row = currency_rate_{p_id}
31 * - table = currency_rate_table
33function CurrencyRateDelete(p_dossier, p_id)
35 smoke.confirm("Confirm ?", function (e) {
38 var a = new Ajax.Request("ajax_misc.php", {
40 parameters:{gDossier:p_dossier,op:"CurrencyRateDelete",currency_rate_id:p_id},
41 onSuccess: function (req)
44 var answer=req.responseText.evalJSON();
45 if ( answer['status'] == 'NOK') {
46 smoke.alert(answer['content']);
48 $('currency_rate_'+p_id).hide();
49 alternate_row_color("currency_rate_table");
58 * Update the field p_update with the rate from the currency
59 * @param DOMID p_code where the cr_code_iso will be selected
60 * @param DOMID p_update element to update
62function CurrencyUpdateValue(p_dossier,p_code,p_update)
64 new Ajax.Request("ajax_misc.php",{
67 parameters:{p_code:$(p_code).value,gDossier:p_dossier,op:'CurrencyRate'},
68 onSuccess:function (req) {
69 var answer=req.responseText.evalJSON();
70 if ( answer.status == "OK") {
71 $(p_update).value=answer.content;
73 smoke.alert(answer.content);
79 * Update the field p_update with the code ISO from the currency
80 * @param DOMID p_code where the cr_code_iso will be selected
81 * @param DOMID p_update element to update
83function CurrencyUpdateCode(p_dossier,p_code,p_update)
85 new Ajax.Request("ajax_misc.php",{
87 parameters:{p_code:$(p_code).value,gDossier:p_dossier,op:'CurrencyCode'},
88 onSuccess:function (req) {
89 var answer=req.responseText.evalJSON();
90 if ( answer.status == "OK") {
91 $(p_update).innerHTML=answer.content;
93 smoke.alert(answer.content);
99 * Update the field Update with the amount in EUR (= default currency), ledger sale or purchase
100 * @param DOMID p_rate where the rate is stored
101 * @param DOMID p_update element to update with the rate
103function CurrencyCompute(p_rate,p_update)
108 tvac=$('tvac').innerHTML;
109 } else if ($("htva")) {
110 tvac=$('htva').innerHTML;
116 var rate=$(p_rate).value;
121 tot=Math.round(tot*100)/100;
122 $(p_update).innerHTML=tot;
126 * Update the field Update with the amount in EUR (= default currency) for Miscealleneous Operation
127 * amount for DEB (domid : default_currency_deb , totalDeb)
128 * amount for CRED ( domid = default_currency_cred , totalCred),
129 * @param DOMID p_rate where the rate is stored
130 * @param DOMID p_update element to update with the rate
132function CurrencyComputeMisc(p_rate,p_update)
134 var debAmount=$('totalDeb').innerHTML;
135 var credAmount=$('totalCred').innerHTML;
137 if ( isNaN(debAmount)) {
140 if ( isNaN(credAmount)) {
143 var rate=$(p_rate).value;
144 if ( isNaN(rate) || parseFloat(rate) == 0) {
147 var totDeb=debAmount/rate;
148 totDeb=Math.round(totDeb*100)/100;
149 $('default_currency_deb').innerHTML=totDeb;
151 var totCred=credAmount/rate;
152 totCred=Math.round(totCred*100)/100;
153 $('default_currency_cred').innerHTML=totCred;
158 * Update the screen of input for Purchase and Sale
159 * @param {type} p_dossier
160 * @param {type} p_code name of the SELECT containing the currency code
161 * @param {type} p_update Domid of the element to update
162 * @param {type} p_rate domid of the element containing the currency rate
163 * @param {type} p_eur_amount domid of the amount in default currency to update
164 * @returns {undefined}
166function LedgerCurrencyUpdate(p_dossier,p_code,p_update,p_rate,p_eur_amount)
168 // Hide or show the row of the table with the amount in EUR
169 if ($(p_code).value != 0) {
170 $('row_currency').show();
172 $('row_currency').hide();
174 CurrencyUpdateValue(p_dossier,p_code,p_rate);
175 CurrencyUpdateCode(p_dossier,p_code,p_update);
176 // Compute all the fields
177 compute_all_ledger ();
181 * Update the screen of input for Misc. Operation
182 * @param {type} p_dossier
183 * @param {type} p_code name of the SELECT containing the currency code
184 * @param {type} p_update Domid of the element to update
185 * @param {type} p_rate domid of the element containing the currency rate
186 * @param {type} p_eur_amount domid of the amount in default currency to update
187 * @returns {undefined}
189function LedgerCurrencyUpdateMisc(p_dossier,p_code,p_update,p_rate,p_eur_amount)
191 // Hide or show the row of the table with the amount in EUR (= default currency)
192 if ($(p_code).value != -1) {
193 $('row_currency').show();
195 $('row_currency').hide();
197 CurrencyUpdateValue(p_dossier,p_code,p_rate);
198 CurrencyUpdateCode(p_dossier,p_code,p_update);
199 // Compute all the fields