Clean code
This commit is contained in:
parent
8e63baeeab
commit
0d8d2528b0
@ -76,7 +76,7 @@ if ($action == 'add') {
|
|||||||
$errori[$i] = 0;
|
$errori[$i] = 0;
|
||||||
|
|
||||||
$tabnum[$i] = 0;
|
$tabnum[$i] = 0;
|
||||||
if (!empty($label[$i]) || !empty($type[$i]) || !($amount[$i] <= 0) || !($accountfrom[$i] < 0) || !($accountto[$i] < 0)) {
|
if (!empty($label[$i]) || !($amount[$i] <= 0) || !($accountfrom[$i] < 0) || !($accountto[$i] < 0)) {
|
||||||
$tabnum[$i] = 1;
|
$tabnum[$i] = 1;
|
||||||
}
|
}
|
||||||
$i++;
|
$i++;
|
||||||
@ -124,7 +124,7 @@ if ($action == 'add') {
|
|||||||
$amountto[$n] = $amount[$n];
|
$amountto[$n] = $amount[$n];
|
||||||
} else {
|
} else {
|
||||||
if (!$amountto[$n]) {
|
if (!$amountto[$n]) {
|
||||||
$error[$n]++;
|
$errori[$n]++;
|
||||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AmountTo")).' #'.$n, null, 'errors');
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AmountTo")).' #'.$n, null, 'errors');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,7 +172,7 @@ if ($action == 'add') {
|
|||||||
$result = $tmpaccountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT.'/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert');
|
$result = $tmpaccountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT.'/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert');
|
||||||
}
|
}
|
||||||
if (!($result > 0)) {
|
if (!($result > 0)) {
|
||||||
$errori++;
|
$errori[$n]++;
|
||||||
}
|
}
|
||||||
if (!$errori[$n]) {
|
if (!$errori[$n]) {
|
||||||
$result = $tmpaccountto->add_url_line($bank_line_id_to, $bank_line_id_from, DOL_URL_ROOT.'/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert');
|
$result = $tmpaccountto->add_url_line($bank_line_id_to, $bank_line_id_from, DOL_URL_ROOT.'/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert');
|
||||||
@ -211,68 +211,38 @@ llxHeader('', $title, $help_url);
|
|||||||
print ' <script type="text/javascript">
|
print ' <script type="text/javascript">
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$(".selectbankaccount").change(function() {
|
$(".selectbankaccount").change(function() {
|
||||||
console.log("We change bank account");
|
console.log("We change bank account. We check if currency differs. If yes, we show multicurrency field");
|
||||||
init_page();
|
i = $(this).attr("name").replace("_account_to", "").replace("_account_from", "");
|
||||||
|
console.log(i);
|
||||||
|
init_page(i);
|
||||||
});
|
});
|
||||||
|
|
||||||
function init_page() {
|
function init_page(i) {
|
||||||
console.log("Set fields according to currency");
|
// TODO Scan all line i and set atleast2differentcurrency if there is 2 different values among all lines
|
||||||
var account1 = $("#selectaccount_from").val();
|
var account1 = $("#select"+i+"_account_from").val();
|
||||||
var account2 = $("#selectaccount_to").val();
|
var account2 = $("#select"+i+"_account_to").val();
|
||||||
var currencycode1="";
|
var currencycode1 = $("#select"+i+"_account_from option:selected").attr("data-currency-code");
|
||||||
var currencycode2="";
|
var currencycode2 = $("#select"+i+"_account_to option:selected").attr("data-currency-code");
|
||||||
|
console.log("Set fields according to currencycode found currencycode1="+currencycode1+" currencycode2="+currencycode2);
|
||||||
|
|
||||||
|
var atleast2differentcurrency = (currencycode2!==currencycode1 && currencycode1 !== undefined && currencycode2 !== undefined && currencycode2!=="" && currencycode1!=="");
|
||||||
|
|
||||||
|
if (atleast2differentcurrency) {
|
||||||
|
console.log("We show multucurrency field");
|
||||||
|
$(".multicurrency").show();
|
||||||
|
} else {
|
||||||
|
console.log("We hide multucurrency field");
|
||||||
|
$(".multicurrency").hide();
|
||||||
|
}
|
||||||
|
|
||||||
$("select").each(function() {
|
$("select").each(function() {
|
||||||
if( $(this).attr("view")){
|
if( $(this).attr("view")){
|
||||||
$(this).closest("tr").removeClass("hidejs").removeClass("hideobject");
|
$(this).closest("tr").removeClass("hidejs").removeClass("hideobject");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$.get("'.DOL_URL_ROOT.'/core/ajax/getaccountcurrency.php", {id: account1})
|
|
||||||
.done(function( data ) {
|
|
||||||
if (data != null)
|
|
||||||
{
|
|
||||||
var item= $.parseJSON(data);
|
|
||||||
if (item.num==-1) {
|
|
||||||
console.error("Error: "+item.error);
|
|
||||||
} else if (item.num!==0) {
|
|
||||||
currencycode1 = item.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
$.get("'.DOL_URL_ROOT.'/core/ajax/getaccountcurrency.php", {id: account2})
|
|
||||||
.done(function( data ) {
|
|
||||||
if (data != null)
|
|
||||||
{
|
|
||||||
var item=$.parseJSON(data);
|
|
||||||
if (item.num==-1) {
|
|
||||||
console.error("Error: "+item.error);
|
|
||||||
} else if (item.num!==0) {
|
|
||||||
currencycode2 = item.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currencycode2!==currencycode1 && currencycode2!=="" && currencycode1!=="") {
|
|
||||||
$(".multicurrency").show();
|
|
||||||
} else {
|
|
||||||
$(".multicurrency").hide();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.error("Error: Ajax url has returned an empty page. Should be an empty json array.");
|
|
||||||
}
|
|
||||||
}).fail(function( data ) {
|
|
||||||
console.error("Error: has returned an empty page. Should be an empty json array.");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.error("Error: has returned an empty page. Should be an empty json array.");
|
|
||||||
}
|
|
||||||
}).fail(function( data ) {
|
|
||||||
console.error("Error: has returned an empty page. Should be an empty json array.");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init_page();
|
init_page(1);
|
||||||
});
|
});
|
||||||
</script>';
|
</script>';
|
||||||
|
|
||||||
@ -298,16 +268,18 @@ print '<th>'.$langs->trans("Type").'</th>';
|
|||||||
print '<th>'.$langs->trans("Date").'</th>';
|
print '<th>'.$langs->trans("Date").'</th>';
|
||||||
print '<th>'.$langs->trans("Description").'</th>';
|
print '<th>'.$langs->trans("Description").'</th>';
|
||||||
print '<th class="right">'.$langs->trans("Amount").'</th>';
|
print '<th class="right">'.$langs->trans("Amount").'</th>';
|
||||||
//print '<td class="hideobject" class="multicurrency">'.$langs->trans("AmountToOthercurrency").'</td>';
|
print '<td class="hideobject multicurrency right">'.$langs->trans("AmountToOthercurrency").'</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
for ($i = 1 ; $i < $MAXLINES; $i++) {
|
for ($i = 1 ; $i < $MAXLINES; $i++) {
|
||||||
$label = '';
|
$label = '';
|
||||||
$amount = '';
|
$amount = '';
|
||||||
|
$amounto = '';
|
||||||
|
|
||||||
if ($errori[$i]) {
|
if ($errori[$i]) {
|
||||||
$label = GETPOST($i.'_label', 'alpha');
|
$label = GETPOST($i.'_label', 'alpha');
|
||||||
$amount = GETPOST($i.'_amount', 'alpha');
|
$amount = GETPOST($i.'_amount', 'alpha');
|
||||||
|
$amountto = GETPOST($i.'_amountto', 'alpha');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($i == 1) {
|
if ($i == 1) {
|
||||||
@ -339,11 +311,14 @@ for ($i = 1 ; $i < $MAXLINES; $i++) {
|
|||||||
print $form->selectDate((!empty($dateo[$i]) ? $dateo[$i] : ''), $i.'_', '', '', '', 'add');
|
print $form->selectDate((!empty($dateo[$i]) ? $dateo[$i] : ''), $i.'_', '', '', '', 'add');
|
||||||
print "</td>\n";
|
print "</td>\n";
|
||||||
|
|
||||||
|
// Description
|
||||||
print '<td><input name="'.$i.'_label" class="flat quatrevingtpercent selectjs" type="text" value="'.dol_escape_htmltag($label).'"></td>';
|
print '<td><input name="'.$i.'_label" class="flat quatrevingtpercent selectjs" type="text" value="'.dol_escape_htmltag($label).'"></td>';
|
||||||
|
|
||||||
|
// Amount
|
||||||
print '<td class="right"><input name="'.$i.'_amount" class="flat right selectjs" type="text" size="6" value="'.dol_escape_htmltag($amount).'"></td>';
|
print '<td class="right"><input name="'.$i.'_amount" class="flat right selectjs" type="text" size="6" value="'.dol_escape_htmltag($amount).'"></td>';
|
||||||
|
|
||||||
print '<td class="hideobject" class="multicurrency"><input name="'.$i.'_amountto" class="flat" type="text" size="6" value="'.dol_escape_htmltag($amountto).'"></td>';
|
// AmountToOthercurrency
|
||||||
|
print '<td class="hideobject multicurrency right"><input name="'.$i.'_amountto" class="flat" type="text" size="6" value="'.dol_escape_htmltag($amountto).'"></td>';
|
||||||
|
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
}
|
}
|
||||||
@ -352,7 +327,7 @@ print '</table>';
|
|||||||
print '</div>';
|
print '</div>';
|
||||||
print '</div>';
|
print '</div>';
|
||||||
print '<div id="btncont" style="display: flex; align-items: center">';
|
print '<div id="btncont" style="display: flex; align-items: center">';
|
||||||
print '<a id="btnincrement" style="margin-left:35%" class="btnTitle btnTitlePlus" onclick="increment()" title="Ajouter écriture">
|
print '<a id="btnincrement" style="margin-left:35%" class="btnTitle btnTitlePlus" onclick="increment()" title="'.dol_escape_htmltag($langs->trans("Add")).'">
|
||||||
<span class="fa fa-plus-circle valignmiddle btnTitle-icon">
|
<span class="fa fa-plus-circle valignmiddle btnTitle-icon">
|
||||||
</span>
|
</span>
|
||||||
</a>';
|
</a>';
|
||||||
|
|||||||
@ -1,66 +0,0 @@
|
|||||||
<?php
|
|
||||||
/* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \file htdocs/core/ajax/getaccountcurrency.php
|
|
||||||
* \brief File to load currency rates
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!defined('NOTOKENRENEWAL')) {
|
|
||||||
define('NOTOKENRENEWAL', '1'); // Disables token renewal
|
|
||||||
}
|
|
||||||
if (!defined('NOREQUIREMENU')) {
|
|
||||||
define('NOREQUIREMENU', '1');
|
|
||||||
}
|
|
||||||
if (!defined('NOREQUIREAJAX')) {
|
|
||||||
define('NOREQUIREAJAX', '1');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load Dolibarr environment
|
|
||||||
require '../../main.inc.php';
|
|
||||||
|
|
||||||
$id = GETPOST('id', 'int');
|
|
||||||
|
|
||||||
// Security check
|
|
||||||
$result = restrictedArea($user, 'banque', $id, 'bank_account&bank_account');
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* View
|
|
||||||
*/
|
|
||||||
|
|
||||||
top_httphead();
|
|
||||||
|
|
||||||
//print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
|
|
||||||
|
|
||||||
// Load original field value
|
|
||||||
if (!empty($id)) {
|
|
||||||
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
|
||||||
$account = new Account($db);
|
|
||||||
$result = $account->fetch($id);
|
|
||||||
if ($result < 0) {
|
|
||||||
$return['value'] = '';
|
|
||||||
$return['num'] = $result;
|
|
||||||
$return['error'] = $account->errors[0];
|
|
||||||
} else {
|
|
||||||
$return['value'] = $account->currency_code;
|
|
||||||
$return['num'] = $result;
|
|
||||||
$return['error'] = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
echo json_encode($return);
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user