33require
'../../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
38$langs->loadLangs(array(
'banks',
'categories',
'multicurrency'));
40$action =
GETPOST(
'action',
'aZ09');
42$hookmanager->initHooks(array(
'banktransfer'));
45if ($user->socid > 0) {
46 $socid = $user->socid;
48if (!$user->hasRight(
'banque',
'transfer')) {
61$parameters = array(
'socid' => $socid);
62$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
66if ($action ==
'add' && $user->hasRight(
'banque',
'transfer')) {
67 $langs->load(
'errors');
74 $accountfrom = array();
80 while ($i < $MAXLINES) {
82 $label[$i] =
GETPOST($i.
'_label',
'alpha');
85 $accountfrom[$i] =
GETPOST($i.
'_account_from',
'int');
86 $accountto[$i] =
GETPOST($i.
'_account_to',
'int');
87 $type[$i] =
GETPOST($i.
'_type',
'int');
90 if (!empty($label[$i]) || !($amount[$i] <= 0) || !($accountfrom[$i] < 0) || !($accountto[$i] < 0)) {
100 while ($n < $MAXLINES) {
101 if ($tabnum[$n] === 1) {
102 if ($accountfrom[$n] < 0) {
104 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' ' .$langs->transnoentities(
"TransferFrom")),
null,
'errors');
106 if ($accountto[$n] < 0) {
108 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' ' .$langs->transnoentities(
"TransferTo")),
null,
'errors');
112 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' ' .$langs->transnoentities(
"Type")),
null,
'errors');
116 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' ' .$langs->transnoentities(
"Date")),
null,
'errors');
121 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' ' . $langs->transnoentities(
"Description")),
null,
'errors');
123 if (!($amount[$n])) {
125 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' ' .$langs->transnoentities(
"Amount")),
null,
'errors');
128 $tmpaccountfrom =
new Account($db);
129 $tmpaccountfrom->fetch(
GETPOST($n.
'_account_from',
'int'));
131 $tmpaccountto =
new Account($db);
132 $tmpaccountto->fetch(
GETPOST($n.
'_account_to',
'int'));
134 if ($tmpaccountto->currency_code == $tmpaccountfrom->currency_code) {
135 $amountto[$n] = $amount[$n];
137 if (!$amountto[$n]) {
139 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' '.$langs->transnoentities(
"AmountToOthercurrency")),
null,
'errors');
142 if ($amountto[$n] < 0) {
144 setEventMessages($langs->trans(
"AmountMustBePositive").
' #'.$n,
null,
'errors');
147 if ($tmpaccountto->id == $tmpaccountfrom->id) {
149 setEventMessages($langs->trans(
"ErrorFromToAccountsMustDiffers").
' #'.$n,
null,
'errors');
153 $bank_line_id_from = 0;
154 $bank_line_id_to = 0;
158 $typefrom = $type[$n];
167 $bank_line_id_from = $tmpaccountfrom->addline($dateo[$n], $typefrom, $label[$n],
price2num(-1 * $amount[$n]),
'',
'', $user);
169 if (!($bank_line_id_from > 0)) {
173 $bank_line_id_to = $tmpaccountto->addline($dateo[$n], $typeto, $label[$n], $amountto[$n],
'',
'', $user);
175 if (!($bank_line_id_to > 0)) {
180 $result = $tmpaccountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT.
'/compta/bank/line.php?rowid=',
'(banktransfert)',
'banktransfert');
182 if (!($result > 0)) {
186 $result = $tmpaccountto->add_url_line($bank_line_id_to, $bank_line_id_from, DOL_URL_ROOT.
'/compta/bank/line.php?rowid=',
'(banktransfert)',
'banktransfert');
188 if (!($result > 0)) {
192 $mesg = $langs->trans(
"TransferFromToDone",
'{s1}',
'{s2}', $amount[$n], $langs->transnoentitiesnoconv(
"Currency".$conf->currency));
193 $mesg = str_replace(
'{s1}',
'<a href="bankentries_list.php?id='.$tmpaccountfrom->id.
'&sortfield=b.datev,b.dateo,b.rowid&sortorder=desc">'.$tmpaccountfrom->label.
'</a>', $mesgs);
194 $mesg = str_replace(
'{s2}',
'<a href="bankentries_list.php?id='.$tmpaccountto->id.
'">'.$tmpaccountto->label.
'</a>', $mesgs);
198 setEventMessages($tmpaccountfrom->error.
' '.$tmpaccountto->error,
null,
'errors');
208 header(
"Location: ".DOL_URL_ROOT.
'/compta/bank/transfer.php');
220$form =
new Form($db);
222$help_url =
'EN:Module_Banks_and_Cash|FR:Module_Banques_et_Caisses|ES:Módulo_Bancos_y_Cajas';
223$title = $langs->trans(
'MenuBankInternalTransfer');
228print
'<script type="text/javascript">
229 $(document).ready(function () {
230 $(".selectbankaccount").change(function() {
231 console.log("We change bank account. We check if currency differs. If yes, we show multicurrency field");
232 i = $(this).attr("name").replace("_account_to", "").replace("_account_from", "");
237 function init_page(i) {
238 var atleast2differentcurrency = false;
240 $(".selectbankaccount").each(function( index ) {
241 // Scan all line i and set atleast2differentcurrency if there is 2 different values among all lines
242 var account1 = $("#select"+index+"_account_from").val();
243 var account2 = $("#select"+index+"_account_to").val();
244 var currencycode1 = $("#select"+index+"_account_from option:selected").attr("data-currency-code");
245 var currencycode2 = $("#select"+index+"_account_to option:selected").attr("data-currency-code");
246 console.log("Set atleast2differentcurrency according to currencycode found for index="+index+" currencycode1="+currencycode1+" currencycode2="+currencycode2);
248 atleast2differentcurrency = (currencycode2!==currencycode1 && currencycode1 !== undefined && currencycode2 !== undefined && currencycode2!=="" && currencycode1!=="");
249 if (atleast2differentcurrency) {
255 if (atleast2differentcurrency) {
256 console.log("We show multicurrency field");
257 $(".multicurrency").show();
259 console.log("We hide multicurrency field");
260 $(".multicurrency").hide();
263 // Show all linew with view=view
264 $("select").each(function() {
265 if( $(this).attr("view")){
266 $(this).closest("tr").removeClass("hidejs").removeClass("hideobject");
277print
load_fiche_titre($langs->trans(
"MenuBankInternalTransfer"),
'',
'bank_account');
279print
'<span class="opacitymedium">'.$langs->trans(
"TransferDesc").
'</span>';
282print
'<form name="add" method="post" action="'.$_SERVER[
"PHP_SELF"].
'">';
283print
'<input type="hidden" name="token" value="'.newToken().
'">';
284print
'<input type="hidden" name="action" value="add">';
288print
'<div class="div-table-responsive-no-min">';
289print
'<table id="tablemouvbank" class="noborder centpercent">';
291print
'<tr class="liste_titre">';
292print
'<th>'.$langs->trans(
"TransferFrom").
'</th>';
293print
'<th>'.$langs->trans(
"TransferTo").
'</th>';
294print
'<th>'.$langs->trans(
"Type").
'</th>';
295print
'<th>'.$langs->trans(
"Date").
'</th>';
296print
'<th>'.$langs->trans(
"Description").
'</th>';
297print
'<th class="right">'.$langs->trans(
"Amount").
'</th>';
298print
'<td class="hideobject multicurrency right">'.$langs->trans(
"AmountToOthercurrency").
'</td>';
301for ($i = 1 ; $i < $MAXLINES; $i++) {
307 $label =
GETPOST($i.
'_label',
'alpha');
308 $amount =
GETPOST($i.
'_amount',
'alpha');
309 $amountto =
GETPOST($i.
'_amountto',
'alpha');
313 $classi =
'numvir number'.$i;
314 $classi .=
' active';
316 $classi =
'numvir number'.$i;
317 $classi .=
' hidejs hideobject';
320 print
'<tr class="oddeven nowraponall '.$classi.
'"><td>';
321 print
img_picto(
'',
'bank_account',
'class="paddingright"');
322 $form->select_comptes(($error ?
GETPOST($i.
'_account_from',
'int') :
''), $i.
'_account_from', 0,
'', 1,
'', isModEnabled(
'multicurrency') ? 1 : 0,
'minwidth100');
325 print
'<td class="nowraponall">';
326 print
img_picto(
'',
'bank_account',
'class="paddingright"');
327 $form->select_comptes(($error ?
GETPOST($i.
'_account_to',
'int') :
''), $i.
'_account_to', 0,
'', 1,
'', isModEnabled(
'multicurrency') ? 1 : 0,
'minwidth100');
331 print
'<td class="nowraponall">';
333 $form->select_types_paiements(($error ?
GETPOST($i.
'_type',
'aZ09') : $idpaymentmodetransfer), $i.
'_type',
'', 0, 1, 0, 0, 1,
'minwidth100');
337 print
'<td class="nowraponall">';
338 print $form->selectDate((!empty($dateo[$i]) ? $dateo[$i] :
''), $i.
'_',
'',
'',
'',
'add');
342 print
'<td><input name="'.$i.
'_label" class="flat quatrevingtpercent selectjs" type="text" value="'.
dol_escape_htmltag($label).
'"></td>';
345 print
'<td class="right"><input name="'.$i.
'_amount" class="flat right selectjs" type="text" size="6" value="'.
dol_escape_htmltag($amount).
'"></td>';
348 print
'<td class="hideobject multicurrency right"><input name="'.$i.
'_amountto" class="flat right" type="text" size="6" value="'.
dol_escape_htmltag($amountto).
'"></td>';
356print
'<div id="btncont" style="display: flex; align-items: center">';
357print
'<a id="btnincrement" style="margin-left:35%" class="btnTitle btnTitlePlus" onclick="increment()" title="'.dol_escape_htmltag($langs->trans(
"Add")).
'">
358 <span class="fa fa-plus-circle valignmiddle btnTitle-icon">
361print
'<br><div class=""><input type="submit" class="button" value="'.$langs->trans(
"Save").
'"></div>';
366print
'<script type="text/javascript">
367 function increment() {
368 console.log("We click to show next line");
369 $(".numvir").nextAll(".hidejs:first").removeClass("hidejs").removeClass("hideobject").addClass("active").show();
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 informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.