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(
"AmountToOthercurrency")),
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');
177 $help_url =
'EN:Module_Banks_and_Cash|FR:Module_Banques_et_Caisses|ES:Módulo_Bancos_y_Cajas';
178 $title = $langs->trans(
'MenuBankInternalTransfer');
183 print
' <script type="text/javascript">
184 $(document).ready(function () {
185 $(".selectbankaccount").change(function() {
186 console.log("We change bank account. We check if currency differs. If yes, we show multicurrency field");
190 function init_page() {
191 console.log("Set fields according to currency");
192 var account1 = $("#selectaccount_from").val();
193 var account2 = $("#selectaccount_to").val();
194 var currencycode1="";
195 var currencycode2="";
197 $.get("'.DOL_URL_ROOT.
'/core/ajax/getaccountcurrency.php", {id: account1})
198 .done(function( data ) {
201 var item= $.parseJSON(data);
203 console.error("Error: "+item.error);
204 } else if (item.num!==0) {
205 currencycode1 = item.value;
207 console.log(currencycode1);
209 $.get("'.DOL_URL_ROOT.
'/core/ajax/getaccountcurrency.php", {id: account2})
210 .done(function( data ) {
213 var item=$.parseJSON(data);
215 console.error("Error: "+item.error);
216 } else if (item.num!==0) {
217 currencycode2 = item.value;
219 console.log(currencycode2);
221 if (currencycode2!==currencycode1 && currencycode2!=="" && currencycode1!=="") {
222 console.log("We show multicurrency fields");
223 $(".multicurrency").show();
225 $(".multicurrency").hide();
229 console.error("Error: Ajax url has returned an empty page. Should be an empty json array.");
231 }).fail(function( data ) {
232 console.error("Error: has returned an empty page. Should be an empty json array.");
236 console.error("Error: has returned an empty page. Should be an empty json array.");
238 }).fail(function( data ) {
239 console.error("Error: has returned an empty page. Should be an empty json array.");
255 $account_from =
GETPOST(
'account_from',
'int');
256 $account_to =
GETPOST(
'account_to',
'int');
257 $label =
GETPOST(
'label',
'alpha');
258 $amount =
GETPOST(
'amount',
'alpha');
261 print
load_fiche_titre($langs->trans(
"MenuBankInternalTransfer"),
'',
'bank_account');
263 print
'<span class="opacitymedium">'.$langs->trans(
"TransferDesc").
'</span>';
266 print
'<form name="add" method="post" action="'.$_SERVER[
"PHP_SELF"].
'">';
267 print
'<input type="hidden" name="token" value="'.newToken().
'">';
268 print
'<input type="hidden" name="action" value="add">';
270 print
'<div class="div-table-responsive-no-min">';
271 print
'<table class="noborder centpercent">';
272 print
'<tr class="liste_titre">';
273 print
'<th>'.$langs->trans(
"TransferFrom").
'</th>';
274 print
'<th>'.$langs->trans(
"TransferTo").
'</th>';
275 print
'<th>'.$langs->trans(
"Date").
'</th>';
276 print
'<th>'.$langs->trans(
"Description").
'</th>';
277 print
'<th class="right">'.$langs->trans(
"Amount").
'</th>';
278 print
'<td class="hideobject multicurrency right">'.$langs->trans(
"AmountToOthercurrency").
'</td>';
281 print
'<tr class="oddeven">';
283 print
'<td class="nowraponall">';
284 print
img_picto(
'',
'bank_account',
'class="paddingright"');
285 $form->select_comptes($account_from,
'account_from', 0,
'', 1,
'', !
isModEnabled(
'multicurrency') ? 0 : 1,
'minwidth100');
288 print
'<td class="nowraponall">';
289 print
img_picto(
'',
'bank_account',
'class="paddingright"');
290 $form->select_comptes($account_to,
'account_to', 0,
'', 1,
'', !
isModEnabled(
'multicurrency') ? 0 : 1,
'minwidth100');
293 print
'<td class="nowraponall">';
294 print
$form->selectDate((!empty($dateo) ? $dateo :
''),
'',
'',
'',
'',
'add');
297 print
'<td><input name="label" class="flat quatrevingtpercent" type="text" value="'.dol_escape_htmltag($label).
'"></td>';
299 print
'<td class="right"><input name="amount" class="flat right" type="text" size="6" value="'.dol_escape_htmltag($amount).
'"></td>';
301 print
'<td class="hideobject multicurrency right"><input name="amountto" class="flat" type="text" size="6" value="'.dol_escape_htmltag($amountto).
'"></td>';
306 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.