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';
47$langs->loadLangs(array(
'banks',
'categories',
'multicurrency'));
49$action =
GETPOST(
'action',
'aZ09');
51$hookmanager->initHooks(array(
'banktransfer'));
54if ($user->socid > 0) {
55 $socid = $user->socid;
57if (!$user->hasRight(
'banque',
'transfer')) {
61$MAXLINESFORTRANSFERT = 20;
70$parameters = array(
'socid' => $socid);
71$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
75if ($action ==
'add' && $user->hasRight(
'banque',
'transfer')) {
76 $langs->load(
'errors');
83 $accountfrom = array();
89 while ($i < $MAXLINESFORTRANSFERT) {
91 $label[$i] =
GETPOST($i.
'_label',
'alpha');
94 $accountfrom[$i] =
GETPOSTINT($i.
'_account_from');
99 if (!empty($label[$i]) || !($amount[$i] <= 0) || !($accountfrom[$i] < 0) || !($accountto[$i] < 0)) {
109 while ($n < $MAXLINESFORTRANSFERT) {
110 if ($tabnum[$n] === 1) {
111 if ($accountfrom[$n] < 0) {
113 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' ' .$langs->transnoentities(
"TransferFrom")),
null,
'errors');
115 if ($accountto[$n] < 0) {
117 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' ' .$langs->transnoentities(
"TransferTo")),
null,
'errors');
121 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' ' .$langs->transnoentities(
"Type")),
null,
'errors');
125 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' ' .$langs->transnoentities(
"Date")),
null,
'errors');
130 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' ' . $langs->transnoentities(
"Description")),
null,
'errors');
132 if (!($amount[$n])) {
134 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' ' .$langs->transnoentities(
"Amount")),
null,
'errors');
137 $tmpaccountfrom =
new Account($db);
138 $tmpaccountfrom->fetch(
GETPOSTINT($n.
'_account_from'));
140 $tmpaccountto =
new Account($db);
141 $tmpaccountto->fetch(
GETPOSTINT($n.
'_account_to'));
143 if ($tmpaccountto->currency_code == $tmpaccountfrom->currency_code) {
144 $amountto[$n] = $amount[$n];
146 if (!$amountto[$n]) {
148 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' '.$langs->transnoentities(
"AmountToOthercurrency")),
null,
'errors');
151 if ($amountto[$n] < 0) {
153 setEventMessages($langs->trans(
"AmountMustBePositive").
' #'.$n,
null,
'errors');
156 if ($tmpaccountto->id == $tmpaccountfrom->id) {
158 setEventMessages($langs->trans(
"ErrorFromToAccountsMustDiffers").
' #'.$n,
null,
'errors');
162 $bank_line_id_from = 0;
163 $bank_line_id_to = 0;
167 $typefrom = $type[$n];
176 $bank_line_id_from = $tmpaccountfrom->addline($dateo[$n], $typefrom, $label[$n],
price2num(-1 * (
float) $amount[$n]),
'', 0, $user);
178 if (!($bank_line_id_from > 0)) {
182 $bank_line_id_to = $tmpaccountto->addline($dateo[$n], $typeto, $label[$n], $amountto[$n],
'', 0, $user);
184 if (!($bank_line_id_to > 0)) {
189 $result = $tmpaccountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT.
'/compta/bank/line.php?rowid=',
'(banktransfert)',
'banktransfert');
191 if (!($result > 0)) {
195 $result = $tmpaccountto->add_url_line($bank_line_id_to, $bank_line_id_from, DOL_URL_ROOT.
'/compta/bank/line.php?rowid=',
'(banktransfert)',
'banktransfert');
197 if (!($result > 0)) {
202 $mesg = $langs->trans(
"TransferFromToDone",
'{s1}',
'{s2}', $amount[$n], $langs->transnoentitiesnoconv(
"Currency".$conf->currency));
203 $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);
204 $mesg = str_replace(
'{s2}',
'<a href="bankentries_list.php?id='.$tmpaccountto->id.
'">'.$tmpaccountto->label.
'</a>', $mesg);
208 setEventMessages($tmpaccountfrom->error.
' '.$tmpaccountto->error,
null,
'errors');
218 header(
"Location: ".DOL_URL_ROOT.
'/compta/bank/transfer.php');
230$form =
new Form($db);
232$help_url =
'EN:Module_Banks_and_Cash|FR:Module_Banques_et_Caisses|ES:Módulo_Bancos_y_Cajas';
233$title = $langs->trans(
'MenuBankInternalTransfer');
238print
'<script type="text/javascript">
239 $(document).ready(function () {
240 $(".selectbankaccount").change(function() {
241 console.log("We change bank account. We check if currency differs. If yes, we show multicurrency field");
242 i = $(this).attr("name").replace("_account_to", "").replace("_account_from", "");
247 function init_page(i) {
248 var atleast2differentcurrency = false;
250 $(".selectbankaccount").each(function( index ) {
251 // Scan all line i and set atleast2differentcurrency if there is 2 different values among all lines
252 var account1 = $("#select"+index+"_account_from").val();
253 var account2 = $("#select"+index+"_account_to").val();
254 var currencycode1 = $("#select"+index+"_account_from option:selected").attr("data-currency-code");
255 var currencycode2 = $("#select"+index+"_account_to option:selected").attr("data-currency-code");
256 console.log("Set atleast2differentcurrency according to currencycode found for index="+index+" currencycode1="+currencycode1+" currencycode2="+currencycode2);
258 atleast2differentcurrency = (currencycode2!==currencycode1 && currencycode1 !== undefined && currencycode2 !== undefined && currencycode2!=="" && currencycode1!=="");
259 if (atleast2differentcurrency) {
265 if (atleast2differentcurrency) {
266 console.log("We show multicurrency field");
267 $(".multicurrency").show();
269 console.log("We hide multicurrency field");
270 $(".multicurrency").hide();
273 // Show all linew with view=view
274 $("select").each(function() {
275 if( $(this).attr("view")){
276 $(this).closest("tr").removeClass("hidejs").removeClass("hideobject");
287print
load_fiche_titre($langs->trans(
"MenuBankInternalTransfer"),
'',
'bank_account');
289print
'<span class="opacitymedium">'.$langs->trans(
"TransferDesc").
'</span>';
292print
'<form name="add" method="post" action="'.$_SERVER[
"PHP_SELF"].
'">';
293print
'<input type="hidden" name="token" value="'.newToken().
'">';
294print
'<input type="hidden" name="action" value="add">';
298print
'<div class="div-table-responsive-no-min">';
299print
'<table id="tablemouvbank" class="noborder centpercent">';
301print
'<tr class="liste_titre">';
302print
'<th>'.$langs->trans(
"TransferFrom").
'</th>';
303print
'<th>'.$langs->trans(
"TransferTo").
'</th>';
304print
'<th>'.$langs->trans(
"Type").
'</th>';
305print
'<th>'.$langs->trans(
"Date").
'</th>';
306print
'<th>'.$langs->trans(
"Description").
'</th>';
307print
'<th class="right">'.$langs->trans(
"Amount").
'</th>';
308print
'<td class="hideobject multicurrency right">'.$langs->trans(
"AmountToOthercurrency").
'</td>';
311for ($i = 1 ; $i < $MAXLINESFORTRANSFERT; $i++) {
317 $label =
GETPOST($i.
'_label',
'alpha');
318 $amount =
GETPOST($i.
'_amount',
'alpha');
319 $amountto =
GETPOST($i.
'_amountto',
'alpha');
323 $classi =
'numvir number'.$i;
324 $classi .=
' active';
326 $classi =
'numvir number'.$i;
327 $classi .=
' hidejs hideobject';
330 print
'<tr class="oddeven nowraponall '.$classi.
'"><td>';
331 print
img_picto(
'',
'bank_account',
'class="paddingright"');
332 $form->select_comptes(($error ?
GETPOSTINT($i.
'_account_from') :
''), $i.
'_account_from', 0,
'', 1,
'', isModEnabled(
'multicurrency') ? 1 : 0,
'minwidth100');
335 print
'<td class="nowraponall">';
336 print
img_picto(
'',
'bank_account',
'class="paddingright"');
337 $form->select_comptes(($error ?
GETPOSTINT($i.
'_account_to') :
''), $i.
'_account_to', 0,
'', 1,
'', isModEnabled(
'multicurrency') ? 1 : 0,
'minwidth100');
341 print
'<td class="nowraponall">';
343 $form->select_types_paiements(($error ?
GETPOST($i.
'_type',
'aZ09') : $idpaymentmodetransfer), $i.
'_type',
'', 0, 1, 0, 0, 1,
'minwidth100');
347 print
'<td class="nowraponall">';
348 print $form->selectDate((!empty($dateo[$i]) ? $dateo[$i] :
''), $i.
'_', 0, 0, 0,
'add');
352 print
'<td><input name="'.$i.
'_label" class="flat quatrevingtpercent selectjs" type="text" value="'.
dol_escape_htmltag($label).
'"></td>';
355 print
'<td class="right"><input name="'.$i.
'_amount" class="flat right selectjs" type="text" size="6" value="'.
dol_escape_htmltag($amount).
'"></td>';
358 print
'<td class="hideobject multicurrency right"><input name="'.$i.
'_amountto" class="flat right" type="text" size="6" value="'.
dol_escape_htmltag($amountto).
'"></td>';
366print
'<div id="btncont" style="display: flex; align-items: center">';
367print
'<a id="btnincrement" style="margin-left:35%" class="btnTitle btnTitlePlus" onclick="increment()" title="'.dol_escape_htmltag($langs->trans(
"Add")).
'">
368 <span class="fa fa-plus-circle valignmiddle btnTitle-icon">
371print
'<br><div class=""><input type="submit" class="button" value="'.$langs->trans(
"Save").
'"></div>';
376print
'<script type="text/javascript">
377 function increment() {
378 console.log("We click to show next line");
379 $(".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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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.