Skip to content

Commit

Permalink
Feature: Bank Transfer Edit
Browse files Browse the repository at this point in the history
Added bank transfer edit feature.  Implemented by voiding the existing transfer
followed by adding a new transfer with possibly modified data.
  • Loading branch information
cambell-prince committed Sep 28, 2014
1 parent edaeebe commit fad33ed
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 40 deletions.
119 changes: 81 additions & 38 deletions gl/bank_transfer.php
@@ -1,12 +1,12 @@
<?php
/**********************************************************************
Copyright (C) FrontAccounting, LLC.
Released under the terms of the GNU General Public License, GPL,
as published by the Free Software Foundation, either version 3
Released under the terms of the GNU General Public License, GPL,
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.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
$page_security = 'SA_BANKTRANSFER';
Expand All @@ -25,13 +25,20 @@
$js .= get_js_open_window(800, 500);
if ($use_date_picker)
$js .= get_js_date_picker();
page(_($help_context = "Transfer between Bank Accounts"), false, false, "", $js);

if (isset($_GET['ModifyTransfer'])) {
$_SESSION['page_title'] = _($help_context = "Modify Bank Account Transfer");
} else {
$_SESSION['page_title'] = _($help_context = "Bank Account Transfer Entry");
}

page($_SESSION['page_title'], false, false, "", $js);

check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));

//----------------------------------------------------------------------------------------

if (isset($_GET['AddedID']))
if (isset($_GET['AddedID']))
{
$trans_no = $_GET['AddedID'];
$trans_type = ST_BANKTRANSFER;
Expand All @@ -50,11 +57,37 @@
}

//----------------------------------------------------------------------------------------

function gl_payment_controls()
function gl_payment_controls($trans_no)
{
global $Refs;


if (!in_ajax()) {
if ($trans_no) {
$result = get_bank_trans(ST_BANKTRANSFER, $trans_no);

if (db_num_rows($result) != 2)
display_db_error("Bank transfer does not contain two records");

$trans1 = db_fetch($result);
$trans2 = db_fetch($result);

// var_dump($trans1);
// var_dump($trans2);

if ($trans1["amount"] < 0) {
$from_trans = $trans1; // from trans is the negative one
$to_trans = $trans2;
} else {
$from_trans = $trans2;
$to_trans = $trans1;
}
$_POST['DatePaid'] = sql2date($to_trans['trans_date']);
$_POST['ref'] = $to_trans['ref'];
$_POST['memo_'] = get_comments_string($type, $id);
} else {
$_POST['ref'] = $Refs->get_next(ST_BANKTRANSFER);
}
}
$home_currency = get_company_currency();

start_form();
Expand All @@ -63,11 +96,13 @@ function gl_payment_controls()

table_section(1);

bank_accounts_list_row(_("From Account:"), 'FromBankAccount', null, true);
bank_accounts_list_row(_("From Account:"), 'FromBankAccount', $from_trans['bank_act'], true);

bank_balance_row($_POST['FromBankAccount']);
// if (! $trans_no) {
bank_balance_row($_POST['FromBankAccount']);
//}

bank_accounts_list_row(_("To Account:"), 'ToBankAccount', null, true);
bank_accounts_list_row(_("To Account:"), 'ToBankAccount', $to_trans['bank_act'], true);

if (!isset($_POST['DatePaid'])) { // init page
$_POST['DatePaid'] = new_doc_date();
Expand All @@ -76,30 +111,32 @@ function gl_payment_controls()
}
date_row(_("Transfer Date:"), 'DatePaid', '', true, 0, 0, 0, null, true);

ref_row(_("Reference:"), 'ref', '', $Refs->get_next(ST_BANKTRANSFER));
ref_row(_("Reference:"), 'ref', '', $_POST['ref']);

table_section(2);

$from_currency = get_bank_account_currency($_POST['FromBankAccount']);
$to_currency = get_bank_account_currency($_POST['ToBankAccount']);
if ($from_currency != "" && $to_currency != "" && $from_currency != $to_currency)
{
if ($from_currency != "" && $to_currency != "" && $from_currency != $to_currency) {
amount_row(_("Amount:"), 'amount', null, null, $from_currency);
amount_row(_("Bank Charge:"), 'charge', null, null, $from_currency);

amount_row(_("Incoming Amount:"), 'target_amount', null, '', $to_currency, 2);
}
else
{
amount_row(_("Amount:"), 'amount');
} else {
amount_row(_("Amount:"), 'amount', $to_trans['amount']);
amount_row(_("Bank Charge:"), 'charge');
}

textarea_row(_("Memo:"), 'memo_', null, 40,4);

end_outer_table(1); // outer table

submit_center('AddPayment',_("Enter Transfer"), true, '', 'default');
if ($trans_no) {
hidden('_trans_no', $trans_no);
submit_center('submit', _("Modify Transfer"), true, '', 'default');
} else {
submit_center('submit', _("Enter Transfer"), true, '', 'default');
}

end_form();
}
Expand All @@ -109,8 +146,8 @@ function gl_payment_controls()
function check_valid_entries()
{
global $Refs;
if (!is_date($_POST['DatePaid']))

if (!is_date($_POST['DatePaid']))
{
display_error(_("The entered date is invalid."));
set_focus('DatePaid');
Expand All @@ -123,7 +160,7 @@ function check_valid_entries()
return false;
}

if (!check_num('amount', 0))
if (!check_num('amount', 0))
{
display_error(_("The entered amount is invalid or less than zero."));
set_focus('amount');
Expand Down Expand Up @@ -153,7 +190,7 @@ function check_valid_entries()
$input_error = 1;
}

if (isset($_POST['charge']) && !check_num('charge', 0))
if (isset($_POST['charge']) && !check_num('charge', 0))
{
display_error(_("The entered amount is invalid or less than zero."));
set_focus('charge');
Expand All @@ -164,28 +201,27 @@ function check_valid_entries()
set_focus('charge');
return false;
}
if (!$Refs->is_valid($_POST['ref']))
if (!$Refs->is_valid($_POST['ref']))
{
display_error(_("You must enter a reference."));
set_focus('ref');
return false;
}

if (!is_new_reference($_POST['ref'], ST_BANKTRANSFER))
{
if (! $_POST['_trans_no'] && ! is_new_reference($_POST['ref'], ST_BANKTRANSFER)) {
display_error(_("The entered reference is already in use."));
set_focus('ref');
return false;
}

if ($_POST['FromBankAccount'] == $_POST['ToBankAccount'])
if ($_POST['FromBankAccount'] == $_POST['ToBankAccount'])
{
display_error(_("The source and destination bank accouts cannot be the same."));
set_focus('ToBankAccount');
return false;
}

if (isset($_POST['target_amount']) && !check_num('target_amount', 0))
if (isset($_POST['target_amount']) && !check_num('target_amount', 0))
{
display_error(_("The entered amount is invalid or less than zero."));
set_focus('target_amount');
Expand All @@ -207,27 +243,34 @@ function check_valid_entries()
}

//----------------------------------------------------------------------------------------

function handle_add_deposit()
function bank_transfer_handle_submit()
{
$trans_no = $_POST['_trans_no'];
if ($trans_no) {
$trans_no = update_bank_transfer($trans_no, $_POST['FromBankAccount'], $_POST['ToBankAccount'], $_POST['DatePaid'], input_num('amount'), $_POST['ref'], $_POST['memo_'], input_num('charge'), input_num('target_amount'));
} else {
new_doc_date($_POST['DatePaid']);
$trans_no = add_bank_transfer($_POST['FromBankAccount'], $_POST['ToBankAccount'],
$_POST['DatePaid'], input_num('amount'), $_POST['ref'], $_POST['memo_'], input_num('charge'), input_num('target_amount'));
$trans_no = add_bank_transfer($_POST['FromBankAccount'], $_POST['ToBankAccount'], $_POST['DatePaid'], input_num('amount'), $_POST['ref'], $_POST['memo_'], input_num('charge'), input_num('target_amount'));
}

meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no");
}

//----------------------------------------------------------------------------------------

if (isset($_POST['AddPayment']))
{
if (check_valid_entries() == true)
{
handle_add_deposit();
if (isset($_POST['submit'])) {
if (check_valid_entries() == true) {
bank_transfer_handle_submit();
}
}

gl_payment_controls();
if (!$trans_no && isset($_POST['_trans_no'])) {
$trans_no = $_POST['_trans_no'];
}
if (!$trans_no && isset($_GET['trans_no'])) {
$trans_no = $_GET["trans_no"];
}
gl_payment_controls($trans_no);

end_page();
?>
16 changes: 16 additions & 0 deletions gl/includes/db/gl_db_banking.inc
Expand Up @@ -190,6 +190,22 @@ function add_exchange_variation_all($date=null, $ref="", $memo)
// $to_account - target bank account id
//

function update_bank_transfer(
$trans_no, $from_account, $to_account, $date_,
$amount, $ref, $memo_, $charge=0, $target_amount=0)
{
begin_transaction();
delete_comments(ST_BANKTRANSFER, $trans_no);
void_bank_trans(ST_BANKTRANSFER, $trans_no, true);
void_gl_trans(ST_BANKTRANSFER, $trans_no, true);
$new_trans_no = add_bank_transfer(
$from_account, $to_account, $date_, $amount,
$ref, $memo_, $charge, $target_amount
);
commit_transaction();
return $new_trans_no;
}

function add_bank_transfer($from_account, $to_account, $date_,
$amount, $ref, $memo_, $charge=0, $target_amount=0)
{
Expand Down
4 changes: 2 additions & 2 deletions gl/inquiry/journal_inquiry.php
Expand Up @@ -83,8 +83,8 @@ function gl_link($row)
ST_JOURNAL => "/gl/gl_journal.php?ModifyGL=Yes&trans_no=%d&trans_type=%d",
ST_BANKPAYMENT => "/gl/gl_bank.php?ModifyPayment=Yes&trans_no=%d&trans_type=%d",
ST_BANKDEPOSIT => "/gl/gl_bank.php?ModifyDeposit=Yes&trans_no=%d&trans_type=%d",
// 4=> Funds Transfer,
ST_SALESINVOICE => "/sales/customer_invoice.php?ModifyInvoice=%d",
ST_BANKTRANSFER => "/gl/bank_transfer.php?ModifyTransfer=Yes&trans_no=%d&trans_type=%d",
ST_SALESINVOICE => "/sales/customer_invoice.php?ModifyInvoice=%d",
// 11=>
// free hand (debtors_trans.order_==0)
// "/sales/credit_note_entry.php?ModifyCredit=%d"
Expand Down

0 comments on commit fad33ed

Please sign in to comment.