35require
'../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
37require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
48$langs->loadLangs(array(
'banks',
'categories',
'multicurrency'));
50$action =
GETPOST(
'action',
'aZ09');
52$hookmanager->initHooks(array(
'banktransfer'));
55if ($user->socid > 0) {
56 $socid = $user->socid;
58if (!$user->hasRight(
'banque',
'transfer')) {
62$MAXLINESFORTRANSFERT = 20;
71$parameters = array(
'socid' => $socid);
76$accountfrom = array();
81$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
85if ($action ==
'add' && $user->hasRight(
'banque',
'transfer')) {
86 $langs->load(
'errors');
89 while ($i < $MAXLINESFORTRANSFERT) {
91 $label[$i] =
GETPOST($i.
'_label',
'alpha');
94 $accountfrom[$i] =
GETPOSTINT($i.
'_account_from');
97 $number[$i] =
GETPOST($i.
'_num_chq',
'alpha');
100 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');
138 $tmpaccountfrom->fetch(
GETPOSTINT($n.
'_account_from'));
141 $tmpaccountto->fetch(
GETPOSTINT($n.
'_account_to'));
143 $amount_main_currency_from =
null;
144 $amount_main_currency_to =
null;
146 if ($tmpaccountto->currency_code == $tmpaccountfrom->currency_code) {
147 $amountto[$n] = $amount[$n];
149 if (!$amountto[$n]) {
151 setEventMessages($langs->trans(
"ErrorFieldRequired",
'#'.$n.
' '.$langs->transnoentities(
"AmountToOthercurrency")),
null,
'errors');
155 if ($tmpaccountfrom->currency_code !=
$conf->currency && $tmpaccountto->currency_code ==
$conf->currency) {
156 $amount_main_currency_from = (float)
price2num(-1 * (
float) $amountto[$n]);
159 if ($tmpaccountto->currency_code !=
$conf->currency && $tmpaccountfrom->currency_code ==
$conf->currency) {
160 $amount_main_currency_to = (float)
price2num((
float) $amount[$n]);
163 if ($amountto[$n] < 0) {
165 setEventMessages($langs->trans(
"AmountMustBePositive").
' #'.$n,
null,
'errors');
168 if ($tmpaccountto->id == $tmpaccountfrom->id) {
170 setEventMessages($langs->trans(
"ErrorFromToAccountsMustDiffers").
' #'.$n,
null,
'errors');
174 $bank_line_id_from = 0;
175 $bank_line_id_to = 0;
179 $typefrom = $type[$n];
188 $bank_line_id_from = $tmpaccountfrom->addline($dateo[$n], $typefrom, $label[$n], (
float)
price2num(-1 * (
float) $amount[$n]),
'', 0, $user,
'',
'',
'',
null,
'', $amount_main_currency_from);
190 if (!($bank_line_id_from > 0)) {
194 $bank_line_id_to = $tmpaccountto->addline($dateo[$n], $typeto, $label[$n], (
float)
price2num((
float) $amountto[$n]),
'', 0, $user,
'',
'',
'',
null,
'', $amount_main_currency_to);
196 if (!($bank_line_id_to > 0)) {
201 $result = $tmpaccountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT.
'/compta/bank/line.php?rowid=',
'(banktransfert)',
'banktransfert');
203 if (!($result > 0)) {
207 $result = $tmpaccountto->add_url_line($bank_line_id_to, $bank_line_id_from, DOL_URL_ROOT.
'/compta/bank/line.php?rowid=',
'(banktransfert)',
'banktransfert');
209 if (!($result > 0)) {
214 $mesg = $langs->trans(
"TransferFromToDone",
'{s1}',
'{s2}', $amount[$n], $langs->transnoentitiesnoconv(
"Currency".$conf->currency));
215 $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);
216 $mesg = str_replace(
'{s2}',
'<a href="bankentries_list.php?id='.$tmpaccountto->id.
'">'.$tmpaccountto->label.
'</a>', $mesg);
220 setEventMessages($tmpaccountfrom->error.
' '.$tmpaccountto->error,
null,
'errors');
230 header(
"Location: ".DOL_URL_ROOT.
'/compta/bank/transfer.php');
244$help_url =
'EN:Module_Banks_and_Cash|FR:Module_Banques_et_Caisses|ES:Módulo_Bancos_y_Cajas';
245$title = $langs->trans(
'MenuBankInternalTransfer');
250print
'<script type="text/javascript">
251 $(document).ready(function () {
252 $(".selectbankaccount").change(function() {
253 console.log("We change bank account. We check if currency differs. If yes, we show multicurrency field");
254 i = $(this).attr("name").replace("_account_to", "").replace("_account_from", "");
259 function init_page(i) {
260 var atleast2differentcurrency = false;
262 $(".selectbankaccount").each(function( index ) {
263 // Scan all line i and set atleast2differentcurrency if there is 2 different values among all lines
264 var account1 = $("#select"+index+"_account_from").val();
265 var account2 = $("#select"+index+"_account_to").val();
266 var currencycode1 = $("#select"+index+"_account_from option:selected").attr("data-currency-code");
267 var currencycode2 = $("#select"+index+"_account_to option:selected").attr("data-currency-code");
268 console.log("Set atleast2differentcurrency according to currencycode found for index="+index+" currencycode1="+currencycode1+" currencycode2="+currencycode2);
270 atleast2differentcurrency = (currencycode2!==currencycode1 && currencycode1 !== undefined && currencycode2 !== undefined && currencycode2!=="" && currencycode1!=="");
271 if (atleast2differentcurrency) {
277 if (atleast2differentcurrency) {
278 console.log("We show multicurrency field");
279 $(".multicurrency").show();
281 console.log("We hide multicurrency field");
282 $(".multicurrency").hide();
285 // Show all linew with view=view
286 $("select").each(function() {
287 if( $(this).attr("view")){
288 $(this).closest("tr").removeClass("hidejs").removeClass("hideobject");
299print
load_fiche_titre($langs->trans(
"MenuBankInternalTransfer"),
'',
'bank_account');
301print
'<span class="opacitymedium">'.$langs->trans(
"TransferDesc").
'</span>';
304print
'<form name="add" method="post" action="'.dolBuildUrl($_SERVER[
"PHP_SELF"]).
'">';
305print
'<input type="hidden" name="token" value="'.newToken().
'">';
306print
'<input type="hidden" name="action" value="add">';
310print
'<div class="div-table-responsive-no-min">';
311print
'<table id="tablemouvbank" class="noborder centpercent">';
313print
'<tr class="liste_titre">';
314print
'<th>'.$langs->trans(
"TransferFrom").
'</th>';
315print
'<th>'.$langs->trans(
"TransferTo").
'</th>';
316print
'<th>'.$langs->trans(
"Type").
'</th>';
317print
'<th>'.$langs->trans(
"Date").
'</th>';
319 print
'<th>'.$langs->trans(
"ChequeNumber").
'</th>';
321print
'<th>'.$langs->trans(
"Description").
'</th>';
322print
'<th class="right">'.$langs->trans(
"Amount").
'</th>';
323print
'<td class="hideobject multicurrency right">'.$langs->trans(
"AmountToOthercurrency").
'</td>';
326for ($i = 1 ; $i < $MAXLINESFORTRANSFERT; $i++) {
333 $label =
GETPOST($i.
'_label',
'alpha');
334 $amount =
GETPOST($i.
'_amount',
'alpha');
335 $amountto =
GETPOST($i.
'_amountto',
'alpha');
336 $number =
GETPOST($i.
'_num_chq',
'alpha');
340 $classi =
'numvir number'.$i;
341 $classi .=
' active';
343 $classi =
'numvir number'.$i;
344 $classi .=
' hidejs hideobject';
347 print
'<tr class="oddeven nowraponall '.$classi.
'"><td>';
348 print
img_picto(
'',
'bank_account',
'class="paddingright"');
349 $form->select_comptes(($error ?
GETPOSTINT($i.
'_account_from') :
''), $i.
'_account_from', 0,
'', 1,
'',
isModEnabled(
'multicurrency') ? 1 : 0,
'minwidth100');
352 print
'<td class="nowraponall">';
353 print
img_picto(
'',
'bank_account',
'class="paddingright"');
354 $form->select_comptes(($error ?
GETPOSTINT($i.
'_account_to') :
''), $i.
'_account_to', 0,
'', 1,
'',
isModEnabled(
'multicurrency') ? 1 : 0,
'minwidth100');
358 print
'<td class="nowraponall">';
360 $form->select_types_paiements(($error ?
GETPOST($i.
'_type',
'aZ09') : $idpaymentmodetransfer), $i.
'_type',
'', 0, 1, 0, 0, 1,
'minwidth100');
364 print
'<td class="nowraponall">';
365 print $form->selectDate((!empty($dateo[$i] ??
null) ? $dateo[$i] :
''), $i.
'_', 0, 0, 0,
'add');
370 print
'<td><input name="'.$i.
'_num_chq" class="flat quatrevingtpercent selectjs" type="text" value="'.
dol_escape_htmltag($number).
'"></td>';
374 print
'<td><input name="'.$i.
'_label" class="flat quatrevingtpercent selectjs" type="text" value="'.
dol_escape_htmltag($label).
'"></td>';
377 print
'<td class="right"><input name="'.$i.
'_amount" class="flat right selectjs" type="text" size="6" value="'.
dol_escape_htmltag($amount).
'"></td>';
380 print
'<td class="hideobject multicurrency right"><input name="'.$i.
'_amountto" class="flat right" type="text" size="6" value="'.
dol_escape_htmltag($amountto).
'"></td>';
388print
'<div id="btncont" style="display: flex; align-items: center">';
389print
'<a id="btnincrement" style="margin-left:35%" class="btnTitle btnTitlePlus" onclick="increment()" title="'.dol_escape_htmltag($langs->trans(
"Add")).
'">
390 <span class="fa fa-plus-circle valignmiddle btnTitle-icon">
393print
'<br><div class=""><input type="submit" class="button" value="'.$langs->trans(
"Save").
'"></div>';
398print
'<script type="text/javascript">
399 function increment() {
400 console.log("We click to show next line");
401 $(".numvir").nextAll(".hidejs:first").removeClass("hidejs").removeClass("hideobject").addClass("active").show();
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
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, $allowothertags=array())
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 '.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.