34require
'../../main.inc.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
36require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
39$langs->loadLangs(array(
'banks',
'categories',
'multicurrency'));
41$action =
GETPOST(
'action',
'aZ09');
43$hookmanager->initHooks(array(
'banktransfer'));
46if ($user->socid > 0) {
47 $socid = $user->socid;
49if (!$user->hasRight(
'banque',
'transfer')) {
53$MAXLINESFORTRANSFERT = 20;
62$parameters = array(
'socid' => $socid);
63$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
67if ($action ==
'add' && $user->hasRight(
'banque',
'transfer')) {
68 $langs->load(
'errors');
75 $accountfrom = array();
81 while ($i < $MAXLINESFORTRANSFERT) {
83 $label[$i] =
GETPOST($i.
'_label',
'alpha');
86 $accountfrom[$i] =
GETPOSTINT($i.
'_account_from');
91 if (!empty($label[$i]) || !($amount[$i] <= 0) || !($accountfrom[$i] < 0) || !($accountto[$i] < 0)) {
101 while ($n < $MAXLINESFORTRANSFERT) {
102 if ($tabnum[$n] === 1) {
103 if ($accountfrom[$n] < 0) {
105 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' ' .$langs->transnoentities(
"TransferFrom")),
null,
'errors');
107 if ($accountto[$n] < 0) {
109 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' ' .$langs->transnoentities(
"TransferTo")),
null,
'errors');
113 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' ' .$langs->transnoentities(
"Type")),
null,
'errors');
117 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' ' .$langs->transnoentities(
"Date")),
null,
'errors');
122 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' ' . $langs->transnoentities(
"Description")),
null,
'errors');
124 if (!($amount[$n])) {
126 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' ' .$langs->transnoentities(
"Amount")),
null,
'errors');
129 $tmpaccountfrom =
new Account($db);
130 $tmpaccountfrom->fetch(
GETPOSTINT($n.
'_account_from'));
132 $tmpaccountto =
new Account($db);
133 $tmpaccountto->fetch(
GETPOSTINT($n.
'_account_to'));
135 if ($tmpaccountto->currency_code == $tmpaccountfrom->currency_code) {
136 $amountto[$n] = $amount[$n];
138 if (!$amountto[$n]) {
140 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' '.$langs->transnoentities(
"AmountToOthercurrency")),
null,
'errors');
143 if ($amountto[$n] < 0) {
145 setEventMessages($langs->trans(
"AmountMustBePositive").
' #'.$n,
null,
'errors');
148 if ($tmpaccountto->id == $tmpaccountfrom->id) {
150 setEventMessages($langs->trans(
"ErrorFromToAccountsMustDiffers").
' #'.$n,
null,
'errors');
154 $bank_line_id_from = 0;
155 $bank_line_id_to = 0;
159 $typefrom = $type[$n];
168 $bank_line_id_from = $tmpaccountfrom->addline($dateo[$n], $typefrom, $label[$n],
price2num(-1 * (
float) $amount[$n]),
'',
'', $user);
170 if (!($bank_line_id_from > 0)) {
174 $bank_line_id_to = $tmpaccountto->addline($dateo[$n], $typeto, $label[$n], $amountto[$n],
'',
'', $user);
176 if (!($bank_line_id_to > 0)) {
181 $result = $tmpaccountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT.
'/compta/bank/line.php?rowid=',
'(banktransfert)',
'banktransfert');
183 if (!($result > 0)) {
187 $result = $tmpaccountto->add_url_line($bank_line_id_to, $bank_line_id_from, DOL_URL_ROOT.
'/compta/bank/line.php?rowid=',
'(banktransfert)',
'banktransfert');
189 if (!($result > 0)) {
194 $mesg = $langs->trans(
"TransferFromToDone",
'{s1}',
'{s2}', $amount[$n], $langs->transnoentitiesnoconv(
"Currency".$conf->currency));
195 $mesg = str_replace(
'{s1}',
'<a href="bankentries_list.php?id='.$tmpaccountfrom->id.
'&sortfield=b.datev,b.dateo,b.rowid&sortorder=desc">'.$tmpaccountfrom->label.
'</a>', $mesg);
196 $mesg = str_replace(
'{s2}',
'<a href="bankentries_list.php?id='.$tmpaccountto->id.
'">'.$tmpaccountto->label.
'</a>', $mesg);
200 setEventMessages($tmpaccountfrom->error.
' '.$tmpaccountto->error,
null,
'errors');
210 header(
"Location: ".DOL_URL_ROOT.
'/compta/bank/transfer.php');
222$form =
new Form($db);
224$help_url =
'EN:Module_Banks_and_Cash|FR:Module_Banques_et_Caisses|ES:Módulo_Bancos_y_Cajas';
225$title = $langs->trans(
'MenuBankInternalTransfer');
230print
'<script type="text/javascript">
231 $(document).ready(function () {
232 $(".selectbankaccount").change(function() {
233 console.log("We change bank account. We check if currency differs. If yes, we show multicurrency field");
234 i = $(this).attr("name").replace("_account_to", "").replace("_account_from", "");
239 function init_page(i) {
240 var atleast2differentcurrency = false;
242 $(".selectbankaccount").each(function( index ) {
243 // Scan all line i and set atleast2differentcurrency if there is 2 different values among all lines
244 var account1 = $("#select"+index+"_account_from").val();
245 var account2 = $("#select"+index+"_account_to").val();
246 var currencycode1 = $("#select"+index+"_account_from option:selected").attr("data-currency-code");
247 var currencycode2 = $("#select"+index+"_account_to option:selected").attr("data-currency-code");
248 console.log("Set atleast2differentcurrency according to currencycode found for index="+index+" currencycode1="+currencycode1+" currencycode2="+currencycode2);
250 atleast2differentcurrency = (currencycode2!==currencycode1 && currencycode1 !== undefined && currencycode2 !== undefined && currencycode2!=="" && currencycode1!=="");
251 if (atleast2differentcurrency) {
257 if (atleast2differentcurrency) {
258 console.log("We show multicurrency field");
259 $(".multicurrency").show();
261 console.log("We hide multicurrency field");
262 $(".multicurrency").hide();
265 // Show all linew with view=view
266 $("select").each(function() {
267 if( $(this).attr("view")){
268 $(this).closest("tr").removeClass("hidejs").removeClass("hideobject");
279print
load_fiche_titre($langs->trans(
"MenuBankInternalTransfer"),
'',
'bank_account');
281print
'<span class="opacitymedium">'.$langs->trans(
"TransferDesc").
'</span>';
284print
'<form name="add" method="post" action="'.$_SERVER[
"PHP_SELF"].
'">';
285print
'<input type="hidden" name="token" value="'.newToken().
'">';
286print
'<input type="hidden" name="action" value="add">';
290print
'<div class="div-table-responsive-no-min">';
291print
'<table id="tablemouvbank" class="noborder centpercent">';
293print
'<tr class="liste_titre">';
294print
'<th>'.$langs->trans(
"TransferFrom").
'</th>';
295print
'<th>'.$langs->trans(
"TransferTo").
'</th>';
296print
'<th>'.$langs->trans(
"Type").
'</th>';
297print
'<th>'.$langs->trans(
"Date").
'</th>';
298print
'<th>'.$langs->trans(
"Description").
'</th>';
299print
'<th class="right">'.$langs->trans(
"Amount").
'</th>';
300print
'<td class="hideobject multicurrency right">'.$langs->trans(
"AmountToOthercurrency").
'</td>';
303for ($i = 1 ; $i < $MAXLINESFORTRANSFERT; $i++) {
309 $label =
GETPOST($i.
'_label',
'alpha');
310 $amount =
GETPOST($i.
'_amount',
'alpha');
311 $amountto =
GETPOST($i.
'_amountto',
'alpha');
315 $classi =
'numvir number'.$i;
316 $classi .=
' active';
318 $classi =
'numvir number'.$i;
319 $classi .=
' hidejs hideobject';
322 print
'<tr class="oddeven nowraponall '.$classi.
'"><td>';
323 print
img_picto(
'',
'bank_account',
'class="paddingright"');
324 $form->select_comptes(($error ?
GETPOSTINT($i.
'_account_from') :
''), $i.
'_account_from', 0,
'', 1,
'', isModEnabled(
'multicurrency') ? 1 : 0,
'minwidth100');
327 print
'<td class="nowraponall">';
328 print
img_picto(
'',
'bank_account',
'class="paddingright"');
329 $form->select_comptes(($error ?
GETPOSTINT($i.
'_account_to') :
''), $i.
'_account_to', 0,
'', 1,
'', isModEnabled(
'multicurrency') ? 1 : 0,
'minwidth100');
333 print
'<td class="nowraponall">';
335 $form->select_types_paiements(($error ?
GETPOST($i.
'_type',
'aZ09') : $idpaymentmodetransfer), $i.
'_type',
'', 0, 1, 0, 0, 1,
'minwidth100');
339 print
'<td class="nowraponall">';
340 print $form->selectDate((!empty($dateo[$i]) ? $dateo[$i] :
''), $i.
'_', 0, 0, 0,
'add');
344 print
'<td><input name="'.$i.
'_label" class="flat quatrevingtpercent selectjs" type="text" value="'.
dol_escape_htmltag($label).
'"></td>';
347 print
'<td class="right"><input name="'.$i.
'_amount" class="flat right selectjs" type="text" size="6" value="'.
dol_escape_htmltag($amount).
'"></td>';
350 print
'<td class="hideobject multicurrency right"><input name="'.$i.
'_amountto" class="flat right" type="text" size="6" value="'.
dol_escape_htmltag($amountto).
'"></td>';
358print
'<div id="btncont" style="display: flex; align-items: center">';
359print
'<a id="btnincrement" style="margin-left:35%" class="btnTitle btnTitlePlus" onclick="increment()" title="'.dol_escape_htmltag($langs->trans(
"Add")).
'">
360 <span class="fa fa-plus-circle valignmiddle btnTitle-icon">
363print
'<br><div class=""><input type="submit" class="button" value="'.$langs->trans(
"Save").
'"></div>';
368print
'<script type="text/javascript">
369 function increment() {
370 console.log("We click to show next line");
371 $(".numvir").nextAll(".hidejs:first").removeClass("hidejs").removeClass("hideobject").addClass("active").show();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage bank accounts.
const TYPE_CASH
Cash account.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.