30 require
'../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
35 $langs->loadLangs(array(
"banks",
"categories",
"multicurrency"));
37 if (!$user->rights->banque->transfer)
40 $action =
GETPOST(
'action',
'aZ09');
43 $hookmanager->initHooks(array(
'banktransfer'));
48 $parameters = array(
'socid' => $socid);
49 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
50 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
53 $langs->load(
"errors");
56 $label =
GETPOST(
'label',
'alpha');
63 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Description")), null,
'errors');
68 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount")), null,
'errors');
70 if (!
GETPOST(
'account_from',
'int'))
73 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"TransferFrom")), null,
'errors');
75 if (!
GETPOST(
'account_to',
'int'))
78 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"TransferTo")), null,
'errors');
82 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
84 $accountfrom =
new Account($db);
85 $accountfrom->fetch(
GETPOST(
'account_from',
'int'));
88 $accountto->fetch(
GETPOST(
'account_to',
'int'));
90 if ($accountto->currency_code == $accountfrom->currency_code)
97 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"AmountTo")), null,
'errors');
101 if (($accountto->id != $accountfrom->id) && empty($error))
105 $bank_line_id_from = 0;
106 $bank_line_id_to = 0;
119 if (!$error) $bank_line_id_from = $accountfrom->addline($dateo, $typefrom, $label,
price2num(-1 * $amount),
'',
'', $user);
120 if (!($bank_line_id_from > 0)) $error++;
121 if (!$error) $bank_line_id_to = $accountto->addline($dateo, $typeto, $label, $amountto,
'',
'', $user);
122 if (!($bank_line_id_to > 0)) $error++;
124 if (!$error) $result = $accountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT.
'/compta/bank/line.php?rowid=',
'(banktransfert)',
'banktransfert');
125 if (!($result > 0)) $error++;
126 if (!$error) $result = $accountto->add_url_line($bank_line_id_to, $bank_line_id_from, DOL_URL_ROOT.
'/compta/bank/line.php?rowid=',
'(banktransfert)',
'banktransfert');
127 if (!($result > 0)) $error++;
131 $mesgs = $langs->trans(
"TransferFromToDone",
'{s1}',
'{s2}', $amount, $langs->transnoentitiesnoconv(
"Currency".$conf->currency));
132 $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);
133 $mesgs = str_replace(
'{s2}',
'<a href="bankentries_list.php?id='.$accountto->id.
'">'.$accountto->label.
'</a>', $mesgs);
137 setEventMessages($accountfrom->error.
' '.$accountto->error, null,
'errors');
142 setEventMessages($langs->trans(
"ErrorFromToAccountsMustDiffers"), null,
'errors');
155 print ' <script type="text/javascript">
156 $(document).ready(function () {
157 $(".selectbankaccount").change(function() {
158 console.log("We change bank account");
162 function init_page() {
163 console.log("Set fields according to currency");
164 var account1 = $("#selectaccount_from").val();
165 var account2 = $("#selectaccount_to").val();
166 var currencycode1="";
167 var currencycode2="";
169 $.get("'.DOL_URL_ROOT.
'/core/ajax/getaccountcurrency.php", {id: account1})
170 .done(function( data ) {
173 var item= $.parseJSON(data);
175 console.error("Error: "+item.error);
176 } else if (item.num!==0) {
177 currencycode1 = item.value;
180 $.get("'.DOL_URL_ROOT.
'/core/ajax/getaccountcurrency.php", {id: account2})
181 .done(function( data ) {
184 var item=$.parseJSON(data);
186 console.error("Error: "+item.error);
187 } else if (item.num!==0) {
188 currencycode2 = item.value;
191 if (currencycode2!==currencycode1 && currencycode2!=="" && currencycode1!=="") {
192 $(".multicurrency").show();
194 $(".multicurrency").hide();
198 console.error("Error: Ajax url has returned an empty page. Should be an empty json array.");
200 }).fail(function( data ) {
201 console.error("Error: has returned an empty page. Should be an empty json array.");
205 console.error("Error: has returned an empty page. Should be an empty json array.");
207 }).fail(function( data ) {
208 console.error("Error: has returned an empty page. Should be an empty json array.");
216 $form =
new Form($db);
225 $account_from =
GETPOST(
'account_from',
'int');
226 $account_to =
GETPOST(
'account_to',
'int');
227 $label =
GETPOST(
'label',
'alpha');
228 $amount =
GETPOST(
'amount',
'alpha');
233 print '<span class="opacitymedium">'.$langs->trans(
"TransferDesc").
'</span>';
236 print '<form name="add" method="post" action="'.$_SERVER[
"PHP_SELF"].
'">';
237 print '<input type="hidden" name="token" value="'.newToken().
'">';
239 print '<input type="hidden" name="action" value="add">';
241 print '<div class="div-table-responsive-no-min">';
242 print '<table class="noborder centpercent">';
243 print '<tr class="liste_titre">';
244 print '<td>'.$langs->trans(
"TransferFrom").
'</td><td>'.$langs->trans(
"TransferTo").
'</td><td>'.$langs->trans(
"Date").
'</td><td>'.$langs->trans(
"Description").
'</td><td>'.$langs->trans(
"Amount").
'</td>';
245 print '<td style="display:none" class="multicurrency">'.$langs->trans(
"AmountToOthercurrency").
'</td>';
248 print '<tr class="oddeven"><td>';
249 $form->select_comptes($account_from,
'account_from', 0,
'', 1,
'', empty($conf->multicurrency->enabled) ? 0 : 1);
253 $form->select_comptes($account_to,
'account_to', 0,
'', 1,
'', empty($conf->multicurrency->enabled) ? 0 : 1);
257 print $form->selectDate((!empty($dateo) ? $dateo :
''),
'',
'',
'',
'',
'add');
259 print '<td><input name="label" class="flat quatrevingtpercent" type="text" value="'.dol_escape_htmltag($label).
'"></td>';
260 print '<td><input name="amount" class="flat" type="text" size="6" value="'.dol_escape_htmltag($amount).
'"></td>';
261 print '<td style="display:none" class="multicurrency"><input name="amountto" class="flat" type="text" size="6" value="'.dol_escape_htmltag($amountto).
'"></td>';
266 print '<br><div class="center"><input type="submit" class="button" value="'.$langs->trans(
"Add").
'"></div>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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...
Class to manage bank accounts.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
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 '...
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
const TYPE_CASH
Cash account.
print
Draft customers invoices.