31 require
'../../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
36 $langs->loadLangs(array(
'banks',
'categories',
'multicurrency'));
40 if ($user->socid > 0) {
41 $socid = $user->socid;
43 if (!$user->rights->banque->transfer) {
47 $action =
GETPOST(
'action',
'aZ09');
50 $hookmanager->initHooks(array(
'banktransfer'));
57 $parameters = array(
'socid' => $socid);
58 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
62 if ($action ==
'add') {
63 $langs->load(
"errors");
66 $label =
GETPOST(
'label',
'alpha');
72 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Description")),
null,
'errors');
76 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount")),
null,
'errors');
78 if (!
GETPOST(
'account_from',
'int')) {
80 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"TransferFrom")),
null,
'errors');
82 if (!
GETPOST(
'account_to',
'int')) {
84 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"TransferTo")),
null,
'errors');
87 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
89 $accountfrom =
new Account($db);
90 $accountfrom->fetch(
GETPOST(
'account_from',
'int'));
93 $accountto->fetch(
GETPOST(
'account_to',
'int'));
95 if ($accountto->currency_code == $accountfrom->currency_code) {
100 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"AmountTo")),
null,
'errors');
108 if ($accountto->id == $accountfrom->id) {
110 setEventMessages($langs->trans(
"ErrorFromToAccountsMustDiffers"),
null,
'errors');
116 $bank_line_id_from = 0;
117 $bank_line_id_to = 0;
130 $bank_line_id_from = $accountfrom->addline($dateo, $typefrom, $label,
price2num(-1 * $amount),
'',
'', $user);
132 if (!($bank_line_id_from > 0)) {
136 $bank_line_id_to = $accountto->addline($dateo, $typeto, $label, $amountto,
'',
'', $user);
138 if (!($bank_line_id_to > 0)) {
143 $result = $accountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT.
'/compta/bank/line.php?rowid=',
'(banktransfert)',
'banktransfert');
145 if (!($result > 0)) {
149 $result = $accountto->add_url_line($bank_line_id_to, $bank_line_id_from, DOL_URL_ROOT.
'/compta/bank/line.php?rowid=',
'(banktransfert)',
'banktransfert');
151 if (!($result > 0)) {
156 $mesgs = $langs->trans(
"TransferFromToDone",
'{s1}',
'{s2}', $amount, $langs->transnoentitiesnoconv(
"Currency".$conf->currency));
157 $mesgs = str_replace(
'{s1}',
'<a href="bankentries_list.php?id='.$accountfrom->id.
'&sortfield=b.datev,b.dateo,b.rowid&sortorder=desc">'.$accountfrom->label.
'</a>', $mesgs);
158 $mesgs = str_replace(
'{s2}',
'<a href="bankentries_list.php?id='.$accountto->id.
'">'.$accountto->label.
'</a>', $mesgs);
162 setEventMessages($accountfrom->error.
' '.$accountto->error,
null,
'errors');
175 $help_url =
'EN:Module_Banks_and_Cash|FR:Module_Banques_et_Caisses|ES:Módulo_Bancos_y_Cajas';
176 $title = $langs->trans(
'MenuBankInternalTransfer');
180 print
' <script type="text/javascript">
181 $(document).ready(function () {
182 $(".selectbankaccount").change(function() {
183 console.log("We change bank account");
187 function init_page() {
188 console.log("Set fields according to currency");
189 var account1 = $("#selectaccount_from").val();
190 var account2 = $("#selectaccount_to").val();
191 var currencycode1="";
192 var currencycode2="";
194 $.get("'.DOL_URL_ROOT.
'/core/ajax/getaccountcurrency.php", {id: account1})
195 .done(function( data ) {
198 var item= $.parseJSON(data);
200 console.error("Error: "+item.error);
201 } else if (item.num!==0) {
202 currencycode1 = item.value;
205 $.get("'.DOL_URL_ROOT.
'/core/ajax/getaccountcurrency.php", {id: account2})
206 .done(function( data ) {
209 var item=$.parseJSON(data);
211 console.error("Error: "+item.error);
212 } else if (item.num!==0) {
213 currencycode2 = item.value;
216 if (currencycode2!==currencycode1 && currencycode2!=="" && currencycode1!=="") {
217 $(".multicurrency").show();
219 $(".multicurrency").hide();
223 console.error("Error: Ajax url has returned an empty page. Should be an empty json array.");
225 }).fail(function( data ) {
226 console.error("Error: has returned an empty page. Should be an empty json array.");
230 console.error("Error: has returned an empty page. Should be an empty json array.");
232 }).fail(function( data ) {
233 console.error("Error: has returned an empty page. Should be an empty json array.");
250 $account_from =
GETPOST(
'account_from',
'int');
251 $account_to =
GETPOST(
'account_to',
'int');
252 $label =
GETPOST(
'label',
'alpha');
253 $amount =
GETPOST(
'amount',
'alpha');
256 print
load_fiche_titre($langs->trans(
"MenuBankInternalTransfer"),
'',
'bank_account');
258 print
'<span class="opacitymedium">'.$langs->trans(
"TransferDesc").
'</span>';
261 print
'<form name="add" method="post" action="'.$_SERVER[
"PHP_SELF"].
'">';
262 print
'<input type="hidden" name="token" value="'.newToken().
'">';
264 print
'<input type="hidden" name="action" value="add">';
266 print
'<div class="div-table-responsive-no-min">';
267 print
'<table class="noborder centpercent">';
268 print
'<tr class="liste_titre">';
269 print
'<td>'.$langs->trans(
"TransferFrom").
'</td><td>'.$langs->trans(
"TransferTo").
'</td><td>'.$langs->trans(
"Date").
'</td><td>'.$langs->trans(
"Description").
'</td>';
270 print
'<td class="right">'.$langs->trans(
"Amount").
'</td>';
271 print
'<td style="display:none" class="multicurrency">'.$langs->trans(
"AmountToOthercurrency").
'</td>';
274 print
'<tr class="oddeven"><td>';
275 print
img_picto(
'',
'bank_account',
'class="paddingright"');
276 $form->select_comptes($account_from,
'account_from', 0,
'', 1,
'', !
isModEnabled(
'multicurrency') ? 0 : 1);
280 print
img_picto(
'',
'bank_account',
'class="paddingright"');
281 $form->select_comptes($account_to,
'account_to', 0,
'', 1,
'', !
isModEnabled(
'multicurrency') ? 0 : 1);
285 print
$form->selectDate((!empty($dateo) ? $dateo :
''),
'',
'',
'',
'',
'add');
287 print
'<td><input name="label" class="flat quatrevingtpercent" type="text" value="'.dol_escape_htmltag($label).
'"></td>';
288 print
'<td class="right"><input name="amount" class="flat right" type="text" size="6" value="'.dol_escape_htmltag($amount).
'"></td>';
289 print
'<td style="display:none" class="multicurrency"><input name="amountto" class="flat" type="text" size="6" value="'.dol_escape_htmltag($amountto).
'"></td>';
294 print
'<br><div class="center"><input type="submit" class="button" value="'.$langs->trans(
"Create").
'"></div>';
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
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.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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 '.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
isModEnabled($module)
Is Dolibarr module enabled.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.