* Copyright (C) 2004-2019 Laurent Destailleur * Copyright (C) 2005-2015 Regis Houssin * Copyright (C) 2012 Juanjo Menent * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2015 Marcos García * Copyright (C) 2018-2021 Frédéric France * Copyright (C) 2023 Maxime Nicolas * Copyright (C) 2023 Benjamin GREMBI * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/compta/bank/transfer.php * \ingroup bank * \brief Page for entering a bank transfer */ // Load Dolibarr environment require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // Load translation files required by the page $langs->loadLangs(array('banks', 'categories', 'multicurrency')); $socid = 0; if ($user->socid > 0) { $socid = $user->socid; } if (!$user->rights->banque->transfer) { accessforbidden(); } $action = GETPOST('action', 'aZ09'); $hookmanager->initHooks(array('banktransfer')); $MAXLINES = 10; /* * Actions */ $parameters = array('socid' => $socid); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } if ($action == 'add') { $langs->load('errors'); $i = 1; while ($i < $MAXLINES) { $dateo[$i] = dol_mktime(12, 0, 0, GETPOST($i.'_month', 'int'), GETPOST($i.'_day', 'int'), GETPOST($i.'_year', 'int')); $label[$i] = GETPOST($i.'_label', 'alpha'); $amount[$i] = intval(price2num(GETPOST($i.'_amount', 'alpha'), 'MT', 2)); $amountto[$i] = price2num(GETPOST($i.'_amountto', 'alpha'), 'MT', 2); $accountfrom[$i] = intval(GETPOST($i.'_account_from', 'int')); $accountto[$i] = intval(GETPOST($i.'_account_to', 'int')); $type[$i] = GETPOST($i.'_type', 'int'); $errori[$i] = 0; $tabnum[$i] = 0; if (!empty($label[$i]) || !empty($type[$i]) || !($amount[$i] <= 0) || !($accountfrom[$i] < 0) || !($accountto[$i] < 0)) { $tabnum[$i] = 1; } $i++; } $n = 1; while ($n < $MAXLINES) { if ($tabnum[$n] === 1) { if ($accountfrom[$n] < 0) { $errori[$n]++; setEventMessages($langs->trans("ErrorFieldRequired", '#'.$n. ' ' .$langs->transnoentities("TransferFrom")), null, 'errors'); } if ($accountto[$n] < 0) { $errori[$n]++; setEventMessages($langs->trans("ErrorFieldRequired", '#'.$n. ' ' .$langs->transnoentities("TransferTo")), null, 'errors'); } if (!$type[$n]) { $errori[$n]++; setEventMessages($langs->trans("ErrorFieldRequired", '#'.$n. ' ' .$langs->transnoentities("Type")), null, 'errors'); } if (!$dateo[$n]) { $errori[$n]++; setEventMessages($langs->trans("ErrorFieldRequired", '#'.$n. ' ' .$langs->transnoentities("Date")), null, 'errors'); } if (!($label[$n])) { $errori[$n]++; setEventMessages($langs->trans("ErrorFieldRequired", '#'.$n. ' ' . $langs->transnoentities("Description")), null, 'errors'); } if (!($amount[$n])) { $errori[$n]++; setEventMessages($langs->trans("ErrorFieldRequired", '#'.$n. ' ' .$langs->transnoentities("Amount")), null, 'errors'); } if (!$errori[$n]) { require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; $accountfrom = new Account($db); $accountfrom->fetch(GETPOST($n.'_account_from', 'int')); $accountto = new Account($db); $accountto->fetch(GETPOST($n.'_account_to', 'int')); if ($accountto->currency_code == $accountfrom->currency_code) { $amountto[$n] = $amount[$n]; } else { if (!$amountto[$n]) { $error[$n]++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AmountTo")).' #'.$n, null, 'errors'); } } if ($amountto[$n] < 0) { $errori[$n]++; setEventMessages($langs->trans("AmountMustBePositive").' #'.$n, null, 'errors'); } if ($accountto->id == $accountfrom->id) { $errori[$n]++; setEventMessages($langs->trans("ErrorFromToAccountsMustDiffers").' #'.$n, null, 'errors'); } } if ($errori[$n] == 0) { $db->begin(); $bank_line_id_from = 0; $bank_line_id_to = 0; $result = 0; // By default, electronic transfert from bank to bank $typefrom = $type[$n]; $typeto = $type[$n]; if ($accountto->courant == Account::TYPE_CASH || $accountfrom->courant == Account::TYPE_CASH) { // This is transfer of change $typefrom = 'LIQ'; $typeto = 'LIQ'; } if (!$errori[$n]) { $bank_line_id_from = $accountfrom->addline($dateo[$n], $typefrom, $label[$n], price2num(-1 * $amount[$n]), '', '', $user); } if (!($bank_line_id_from > 0)) { $errori[$n]++; } if (!$errori[$n]) { $bank_line_id_to = $accountto->addline($dateo[$n], $typeto, $label[$n], $amountto[$n], '', '', $user); } if (!($bank_line_id_to > 0)) { $errori[$n]++; } if (!$errori[$n]) { $result = $accountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT.'/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert'); } if (!($result > 0)) { $errori++; } if (!$errori[$n]) { $result = $accountto->add_url_line($bank_line_id_to, $bank_line_id_from, DOL_URL_ROOT.'/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert'); } if (!($result > 0)) { $errori[$n]++; } if (!$errori[$n]) { $mesgs = $langs->trans("TransferFromToDone", '{s1}', '{s2}', $amount[$n], $langs->transnoentitiesnoconv("Currency".$conf->currency)); $mesgs = str_replace('{s1}', ''.$accountfrom->label.'', $mesgs); $mesgs = str_replace('{s2}', ''.$accountto->label.'', $mesgs); setEventMessages($mesgs, null, 'mesgs'); $db->commit(); } else { setEventMessages($accountfrom->error.' '.$accountto->error, null, 'errors'); $db->rollback(); } } } $n++; } } /* * View */ $form = new Form($db); $help_url = 'EN:Module_Banks_and_Cash|FR:Module_Banques_et_Caisses|ES:Módulo_Bancos_y_Cajas'; $title = $langs->trans('MenuBankInternalTransfer'); llxHeader('', $title, $help_url); print ' '; print load_fiche_titre($langs->trans("MenuBankInternalTransfer"), '', 'bank_account'); print ''.$langs->trans("TransferDesc").''; print '

'; print '
'; print ''; print ''; print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; //print ''; print ''; for ($i = 1 ; $i < $MAXLINES; $i++) { $label = ''; $amount = ''; if ($errori[$i]) { $label = GETPOST($i.'_label', 'alpha'); $amount = GETPOST($i.'_amount', 'alpha'); } if ($i == 1) { $classi = 'numvir number'. $i; $classi .= ' active'; } else { $classi = 'numvir number'. $i; $classi .= ' hidejs hideobject'; } print ''; print '\n"; // Payment mode print '\n"; // Date print '\n"; print ''; print ''; print ''; print ''; } print '
'.$langs->trans("TransferFrom").''.$langs->trans("TransferTo").''.$langs->trans("Type").''.$langs->trans("Date").''.$langs->trans("Description").''.$langs->trans("Amount").''.$langs->trans("AmountToOthercurrency").'
'; print img_picto('', 'bank_account', 'class="paddingright"'); $form->select_comptes(($errori[$i] ? GETPOST($i.'_account_from', 'int') : ''), $i.'_account_from', 0, '', 1, ($errori[$i] ? 'view=view' : ''), isModEnabled('multicurrency') ? 1 : 0, 'minwidth100'); print ''; print img_picto('', 'bank_account', 'class="paddingright"'); $form->select_comptes(($errori[$i] ? GETPOST($i.'_account_to', 'int') : ''), $i.'_account_to', 0, '', 1, ($errori[$i] ? 'view=view' : ''), isModEnabled('multicurrency') ? 1 : 0, 'minwidth100'); print "'; $idpaymentmodetransfer = dol_getIdFromCode($db, 'VIR', 'c_paiement'); $form->select_types_paiements(($errori[$i] ? GETPOST($i.'_type', 'aZ09') : $idpaymentmodetransfer), $i.'_type', '', 0, 1, 0, 0, 1, 'minwidth100'); print "'; print $form->selectDate((!empty($dateo[$i]) ? $dateo[$i] : ''), $i.'_', '', '', '', 'add'); print "
'; print '
'; print '
'; print '
'; print ' '; print '
'; print '
'; print '
'; print ' '; // End of page llxFooter(); $db->close();