Allowed multiply bank accounts on same gl account, removed bank trans type.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 9 Nov 2008 18:14:36 +0000 (18:14 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 9 Nov 2008 18:14:36 +0000 (18:14 +0000)
26 files changed:
applications/generalledger.php
gl/bank_transfer.php
gl/gl_bank.php
gl/includes/db/gl_db_bank_accounts.inc
gl/includes/db/gl_db_bank_trans.inc
gl/includes/db/gl_db_banking.inc
gl/includes/db/gl_db_trans.inc
gl/includes/ui/gl_bank_ui.inc
gl/inquiry/bank_inquiry.php
gl/manage/bank_accounts.php
gl/view/bank_transfer_view.php
gl/view/gl_deposit_view.php
gl/view/gl_payment_view.php
includes/banking.inc
includes/data_checks.inc
includes/types.inc
includes/ui/ui_lists.inc
purchasing/includes/db/supp_payment_db.inc
purchasing/includes/db/supp_trans_db.inc
purchasing/supplier_payment.php
purchasing/view/view_supp_payment.php
sales/customer_payments.php
sales/includes/db/payment_db.inc
sales/includes/db/sales_invoice_db.inc
sales/view/view_receipt.php
sql/alter2.1.sql

index ecbc6b9128f8ea204a197af09e028190b39a99ba..9b02b2a5bbb57fe84323a519c08f0e74a6ba0e42 100644 (file)
@@ -26,7 +26,6 @@
 
                        $this->add_module(_("Maintenance"));
                        $this->add_lapp_function(2, _("Bank &Accounts"),"gl/manage/bank_accounts.php?");
-                       $this->add_lapp_function(2, _("Payment, Deposit and Transfer &Types"),"gl/manage/bank_trans_types.php?");
                        $this->add_lapp_function(2, _("Quick Entries"),"gl/manage/gl_quick_entries.php?");
                        $this->add_lapp_function(2, "","");
                        $this->add_lapp_function(2, _("&Currencies"),"gl/manage/currencies.php?");
index 6699a1a5cbfac3da12cb10dd7a88903f57456686..87e82c71daed0f1e7f6686fabe59091db54794e8 100644 (file)
@@ -19,7 +19,6 @@ if ($use_date_picker)
 page(_("Transfer between Bank Accounts"), false, false, "", $js);
 
 check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
-check_db_has_bank_trans_types(_("There are no bank transfer types defined in the system."));
 
 //----------------------------------------------------------------------------------------
 
@@ -77,8 +76,6 @@ function gl_payment_controls()
        echo "</td><td valign=top class='tableseparator'>"; // outer table
        echo "<table>";
 
-       bank_trans_types_list_row(_("Transfer Type:"), 'TransferType', null);
-
     ref_row(_("Reference:"), 'ref', '', references::get_next(systypes::bank_transfer()));
 
     textarea_row(_("Memo:"), 'memo_', null, 40,4);
@@ -148,8 +145,7 @@ function handle_add_deposit()
        global $path_to_root;
 
        $trans_no = add_bank_transfer($_POST['FromBankAccount'], $_POST['ToBankAccount'],
-               $_POST['DatePaid'], input_num('amount'),
-               $_POST['TransferType'], $_POST['ref'], $_POST['memo_']);
+               $_POST['DatePaid'], input_num('amount'), $_POST['ref'], $_POST['memo_']);
 
        meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no");
 }
index ae5b1daf2b23d5563bc72c8d20cdb9bfcdbbc18e..b3f1c1b7766f0f5871371ecf47d4f817346734a7 100644 (file)
@@ -31,8 +31,6 @@ page($_SESSION['page_title'], false, false, '', $js);
 //-----------------------------------------------------------------------------------------------
 check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
 
-check_db_has_bank_trans_types(_("There are no bank payment types defined in the system."));
-
 //----------------------------------------------------------------------------------------
 if ($ret = context_restore()) {
        if(isset($ret['supplier_id']))
@@ -55,7 +53,7 @@ if (isset($_POST['_person_id_editor'])) {
 //
 context_call($path_to_root.$editor.$_POST['person_id'], 
        array('bank_account', 'date_', 'PayType', 'person_id',
-               'PersonDetailID', 'type', 'ref', 'memo_') );
+               'PersonDetailID', 'ref', 'memo_') );
 }
 //--------------------------------------------------------------------------------------------------
 function line_start_focus() {
@@ -170,7 +168,7 @@ if (isset($_POST['Process']))
                $_SESSION['pay_items']->trans_type, $_POST['bank_account'],
                $_SESSION['pay_items'], $_POST['date_'],
                $_POST['PayType'], $_POST['person_id'], get_post('PersonDetailID'),
-               $_POST['type'], $_POST['ref'], $_POST['memo_']);
+               $_POST['ref'], $_POST['memo_']);
 
        $trans_type = $trans[0];
        $trans_no = $trans[1];
index 15d524e734a83d4f45867364e6c53b76fc0d7db9..620b1bc3553cb84c7ed5ffd35337a720b7e1afa2 100644 (file)
@@ -14,38 +14,51 @@ function add_bank_account($account_code, $account_type, $bank_account_name, $ban
 
 //---------------------------------------------------------------------------------------------
 
-function update_bank_account($account_code, $account_type, $bank_account_name, $bank_name, $bank_account_number,
+function update_bank_account($id, $account_code, $account_type, $bank_account_name, $bank_name, $bank_account_number,
        $bank_address, $bank_curr_code)
 {
        $sql = "UPDATE ".TB_PREF."bank_accounts SET account_type = $account_type,
+               account_code=".db_escape($account_code).",
                bank_account_name=".db_escape($bank_account_name).", bank_name=".db_escape($bank_name).",
                bank_account_number=".db_escape($bank_account_number).", bank_curr_code='$bank_curr_code',
-               bank_address=".db_escape($bank_address)." WHERE account_code = '$account_code'";
+               bank_address=".db_escape($bank_address)." WHERE id = '$id'";
 
        db_query($sql, "could not update bank account for $account_code");
 }
 
 //---------------------------------------------------------------------------------------------
 
-function delete_bank_account($account_code)
+function delete_bank_account($id)
 {
-       $sql = "DELETE FROM ".TB_PREF."bank_accounts WHERE account_code='$account_code'";
+       $sql = "DELETE FROM ".TB_PREF."bank_accounts WHERE id='$id'";
 
-       db_query($sql,"could not delete bank account for $account_code");
+       db_query($sql,"could not delete bank account for $id");
 }
 
 
 //---------------------------------------------------------------------------------------------
 
-function get_bank_account($account_code)
+function get_bank_account($id)
 {
-       $sql = "SELECT * FROM ".TB_PREF."bank_accounts WHERE account_code='$account_code'";
+       $sql = "SELECT * FROM ".TB_PREF."bank_accounts WHERE id='$id'";
 
-       $result = db_query($sql, "could not retreive bank account for $account_code");
+       $result = db_query($sql, "could not retreive bank account for $id");
 
        return db_fetch($result);
 }
 
+//---------------------------------------------------------------------------------------------
+function get_bank_gl_account($id)
+{
+       $sql = "SELECT account_code FROM ".TB_PREF."bank_accounts WHERE id='$id'";
+
+       $result = db_query($sql, "could not retreive bank account for $id");
+
+       $bank_account = db_fetch($result);
+
+       return $bank_account['account_code'];
+}
+
 //---------------------------------------------------------------------------------------------
 
 function add_quick_entry($description, $deposit, $bank_only)
index 200277fb60b2280cb44c17a18429c7e5a6cb83db..a9c3deae1718f5f81db10e0f3c7aabd8ae7ee7f7 100644 (file)
@@ -6,7 +6,7 @@
 // $amount is in $currency
 // $date_ is display date (non-sql)
 
-function add_bank_trans($type, $trans_no, $bank_act, $ref, $date_, $bank_trans_type_id,
+function add_bank_trans($type, $trans_no, $bank_act, $ref, $date_,
        $amount, $person_type_id, $person_id, $currency="", $err_msg="")
 {
        $sqlDate = date2sql($date_);
@@ -26,9 +26,9 @@ function add_bank_trans($type, $trans_no, $bank_act, $ref, $date_, $bank_trans_t
        //$BankToHomeCurrencyRate = get_exchange_rate_to_home_currency($bank_account_currency, $date_);
 
        $sql = "INSERT INTO ".TB_PREF."bank_trans (type, trans_no, bank_act, ref,
-               trans_date, bank_trans_type_id, amount, person_type_id, person_id) ";
+               trans_date, amount, person_type_id, person_id) ";
 
-       $sql .= "VALUES ($type, $trans_no, '$bank_act', ".db_escape($ref).", '$sqlDate', '$bank_trans_type_id',
+       $sql .= "VALUES ($type, $trans_no, '$bank_act', ".db_escape($ref).", '$sqlDate',
                $amount_bank, $person_type_id, ". db_escape($person_id).")";
 
        if ($err_msg == "")
@@ -52,10 +52,9 @@ function exists_bank_trans($type, $type_no)
 
 function get_bank_trans($type, $trans_no=null, $person_type_id=null, $person_id=null)
 {
-       $sql = "SELECT *, bank_account_name, account_code, bank_curr_code, name AS BankTransType
-               FROM ".TB_PREF."bank_trans, ".TB_PREF."bank_accounts, ".TB_PREF."bank_trans_types
-               WHERE ".TB_PREF."bank_trans_types.id = ".TB_PREF."bank_trans.bank_trans_type_id
-               AND ".TB_PREF."bank_accounts.account_code=".TB_PREF."bank_trans.bank_act ";
+       $sql = "SELECT *, bank_account_name, account_code, bank_curr_code
+               FROM ".TB_PREF."bank_trans, ".TB_PREF."bank_accounts
+               WHERE ".TB_PREF."bank_accounts.id=".TB_PREF."bank_trans.bank_act ";
        if ($type != null)
                $sql .= " AND type=$type ";
        if ($trans_no != null)
index a5fe71ad2250ee84ee1d05764b9d153aa925025d..518e73c1f9c3fa9b16f49273c48fe71866053d4c 100644 (file)
@@ -1,9 +1,13 @@
 <?php
 
 //----------------------------------------------------------------------------------
-
+//     Add bank tranfer to database.
+//
+//     $from_account - source bank account id
+//     $to_account   - target bank account id
+//     
 function add_bank_transfer($from_account, $to_account, $date_,
-       $amount, $payment_type, $ref, $memo_)
+       $amount, $ref, $memo_)
 {
        begin_transaction();
 
@@ -13,24 +17,25 @@ function add_bank_transfer($from_account, $to_account, $date_,
 
        $trans_no = get_next_trans_no($trans_type);
 
+       $from_gl_account = get_bank_gl_account($from_account);
+       $to_gl_account = get_bank_gl_account($to_account);
+
        // do the source account postings
-    add_gl_trans($trans_type, $trans_no, $date_, $from_account, 0, 0, "",
+    add_gl_trans($trans_type, $trans_no, $date_, $from_gl_account, 0, 0, "",
                -$amount, $currency);
 
     add_bank_trans($trans_type, $trans_no, $from_account, $ref,
-               $date_, $payment_type, -$amount,
+               $date_, -$amount,
                payment_person_types::misc(), "", $currency,
                "Cannot insert a source bank transaction");
 
        // do the destination account postings
-       add_gl_trans($trans_type, $trans_no, $date_, $to_account, 0, 0, "",
+       add_gl_trans($trans_type, $trans_no, $date_, $to_gl_account, 0, 0, "",
                $amount, $currency);
 
        add_bank_trans($trans_type, $trans_no, $to_account, $ref,
-               $date_, $payment_type, $amount,
-               payment_person_types::misc(), "",
-               $currency,
-               "Cannot insert a destination bank transaction");
+               $date_, $amount, payment_person_types::misc(), "",
+               $currency, "Cannot insert a destination bank transaction");
 
        add_comments($trans_type, $trans_no, $date_, $memo_);
 
@@ -42,13 +47,18 @@ function add_bank_transfer($from_account, $to_account, $date_,
 }
 
 //----------------------------------------------------------------------------------
-
-// $amount is in $from_account's currency
-
+//     Add bank payment or deposit to database.
+//
+//     $from_account - bank account id
+//  $item - transaction cart (line item's amounts in bank account's currency)
+//  $person_type_id - defines type of $person_id identifiers
+//  $person_id - supplier/customer/other id
+// $person_detail_id - customer branch id or not used
+//
 // returns an array of (inserted trans type, trans no)
 
 function add_bank_transaction($trans_type, $from_account, $items, $date_,
-       $person_type_id, $person_id, $person_detail_id, $type, $ref, $memo_)
+       $person_type_id, $person_id, $person_detail_id, $ref, $memo_)
 {
        // we can only handle type 1 (payment)and type 2 (deposit)
        if ($trans_type != systypes::bank_payment() && $trans_type != systypes::bank_deposit())
@@ -57,6 +67,7 @@ function add_bank_transaction($trans_type, $from_account, $items, $date_,
        begin_transaction();
 
        $currency = get_bank_account_currency($from_account);
+       $bank_gl_account = get_bank_gl_account($from_account);
 
        // the gl items are already inversed/negated for type 2 (deposit)
        $total_amount = $items->gl_items_total();
@@ -93,14 +104,12 @@ function add_bank_transaction($trans_type, $from_account, $items, $date_,
     }
 
        // do the source account postings
-    add_gl_trans($trans_type, $trans_no, $date_, $from_account, 0, 0, "",
+    add_gl_trans($trans_type, $trans_no, $date_, $bank_gl_account, 0, 0, "",
        -$total_amount, $currency, $person_type_id, $person_id);
 
     add_bank_trans($trans_type, $trans_no, $from_account, $ref,
-       $date_, $type, -$total_amount,
-       $person_type_id, $person_id,
-       $currency,
-       "Cannot insert a source bank transaction");
+       $date_, -$total_amount, $person_type_id, $person_id,
+       $currency, "Cannot insert a source bank transaction");
 
        foreach ($items->gl_items as $gl_item)
        {
@@ -120,9 +129,8 @@ function add_bank_transaction($trans_type, $from_account, $items, $date_,
        if ($is_bank_to)
        {
                add_bank_trans($trans_type, $trans_no, $gl_item->code_id, $ref,
-                       $date_, $type, $gl_item->amount,
-                       $person_type_id, $person_id, $currency,
-                       "Cannot insert a destination bank transaction");
+                       $date_, $gl_item->amount, $person_type_id, $person_id, 
+                               $currency, "Cannot insert a destination bank transaction");
        }
        }
 
index 79b03d80651e57b3a56385564c8f660d48a54735..d44e8eac04578de6928b2d56425ea5ec5f81a4bc 100644 (file)
@@ -193,6 +193,7 @@ function add_journal_entries($items, $date_, $ref, $reverse, $memo_=null)
 
        foreach ($items as $journal_item)
        {
+               // post to first found bank account using given gl acount code.
                $is_bank_to = is_bank_account($journal_item->code_id);
 
                add_gl_trans($trans_type, $trans_id, $date_, $journal_item->code_id,
@@ -200,8 +201,8 @@ function add_journal_entries($items, $date_, $ref, $reverse, $memo_=null)
                        $journal_item->reference, $journal_item->amount);
        if ($is_bank_to)
        {
-               add_bank_trans($trans_type, $trans_id, $journal_item->code_id, $ref,
-                       $date_, 3, $journal_item->amount,
+               add_bank_trans($trans_type, $trans_id, $is_bank_to, $ref,
+                       $date_, $journal_item->amount,
                        0, "", get_company_currency(),
                        "Cannot insert a destination bank transaction");
        }
@@ -229,8 +230,8 @@ function add_journal_entries($items, $date_, $ref, $reverse, $memo_=null)
                        $journal_item->reference, -$journal_item->amount);
                if ($is_bank_to)
                {
-                       add_bank_trans($trans_type, $trans_id_reverse, $journal_item->code_id, $ref,
-                               $reversingDate, 3, $journal_item->amount,
+                       add_bank_trans($trans_type, $trans_id_reverse, $is_bank_to, $ref,
+                               $reversingDate, $journal_item->amount,
                                0, "", get_company_currency(),
                                "Cannot insert a destination bank transaction");
                }
index 8d6dd32e208a4984b14276ff41eb86ec81d8ffd7..303d557cf1f4debab35406fd941d3fb304f9ad9d 100644 (file)
@@ -87,8 +87,6 @@ function display_bank_header(&$order)
 
        echo "<table>"; // inner table
 
-       bank_trans_types_list_row(_("Type:"), 'type', null);
-
        if (isset($_GET['NewPayment']))
        ref_row(_("Reference:"), 'ref', '', references::get_next(systypes::bank_payment()));
     else
index f6ffdba757a156d37ee6bb207f94a5ac2e18ff54..d5147f5ff1ecc624ff4fa66ef9b1e1c7534c8574 100644 (file)
@@ -49,11 +49,10 @@ $date_after = date2sql($_POST['TransAfterDate']);
 $date_to = date2sql($_POST['TransToDate']);
 if (!isset($_POST['bank_account']))
        $_POST['bank_account'] = "";
-$sql = "SELECT ".TB_PREF."bank_trans.*,name AS BankTransType FROM ".TB_PREF."bank_trans, ".TB_PREF."bank_trans_types
+$sql = "SELECT ".TB_PREF."bank_trans.* FROM ".TB_PREF."bank_trans
        WHERE ".TB_PREF."bank_trans.bank_act = '" . $_POST['bank_account'] . "'
        AND trans_date >= '$date_after'
        AND trans_date <= '$date_to'
-       AND ".TB_PREF."bank_trans_types.id = ".TB_PREF."bank_trans.bank_trans_type_id
        ORDER BY trans_date,".TB_PREF."bank_trans.id";
 
 $result = db_query($sql,"The transactions for '" . $_POST['bank_account'] . "' could not be retrieved");
@@ -94,7 +93,6 @@ while ($myrow = db_fetch($result))
        label_cell(systypes::name($myrow["type"]));
        label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"]));
        label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"],$myrow['ref']));
-       label_cell($myrow["BankTransType"]);
        label_cell($trandate);
        display_debit_or_credit_cells($myrow["amount"]);
        amount_cell($running_total);
index 5081e3b5d6140acd32a0f050d7f29fb58f8abcc5..9cb5618055bf12d5c51c68f7f199ce0b544f1759 100644 (file)
@@ -30,17 +30,19 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
        if ($selected_id != -1) 
        {
                
-               update_bank_account($selected_id, $_POST['account_type'], $_POST['bank_account_name'], $_POST['bank_name'], 
-                       $_POST['bank_account_number'], 
+               update_bank_account($selected_id, $_POST['account_code'],
+                               $_POST['account_type'], $_POST['bank_account_name'], 
+                               $_POST['bank_name'], $_POST['bank_account_number'], 
                        $_POST['bank_address'], $_POST['BankAccountCurrency']);         
                        display_notification(_('Bank account has been updated'));
        } 
        else 
        {
     
-               add_bank_account($_POST['account_code'], $_POST['account_type'], $_POST['bank_account_name'], $_POST['bank_name'], 
-                       $_POST['bank_account_number'], 
-                       $_POST['bank_address'], $_POST['BankAccountCurrency']);
+               add_bank_account($_POST['account_code'], $_POST['account_type'], 
+                               $_POST['bank_account_name'], $_POST['bank_name'], 
+                       $_POST['bank_account_number'],  $_POST['bank_address'], 
+                               $_POST['BankAccountCurrency']);
                        display_notification(_('New bank account has been added'));
        }
                $Mode = 'RESET';
@@ -79,8 +81,11 @@ if ($Mode == 'RESET')
 
 /* Always show the list of accounts */
 
-$sql = "SELECT ".TB_PREF."bank_accounts.*, ".TB_PREF."chart_master.account_name FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master 
-       WHERE ".TB_PREF."bank_accounts.account_code = ".TB_PREF."chart_master.account_code";
+$sql = "SELECT account.*, gl_account.account_name 
+       FROM ".TB_PREF."bank_accounts account, ".TB_PREF."chart_master gl_account 
+       WHERE account.account_code = gl_account.account_code"
+       ." ORDER BY account_code, bank_curr_code";
+
 $result = db_query($sql,"could not get bank accounts");
 
 check_db_error("The bank accounts set up could not be retreived", $sql);
@@ -88,8 +93,8 @@ check_db_error("The bank accounts set up could not be retreived", $sql);
 start_form();
 start_table("$table_style width='80%'");
 
-$th = array(_("GL Account"), _("Bank"), _("Account Name"),
-       _("Type"), _("Number"), _("Currency"), _("Bank Address"),'','');
+$th = array(_("Account Name"), _("Type"), _("Currency"), _("GL Account"), 
+       _("Bank"), _("Number"), _("Bank Address"),'','');
 table_header($th);     
 
 $k = 0; 
@@ -98,15 +103,15 @@ while ($myrow = db_fetch($result))
        
        alt_table_row_color($k);
 
-    label_cell($myrow["account_code"] . " " . $myrow["account_name"], "nowrap");
-    label_cell($myrow["bank_name"], "nowrap");
     label_cell($myrow["bank_account_name"], "nowrap");
        label_cell(bank_account_types::name($myrow["account_type"]), "nowrap");
-    label_cell($myrow["bank_account_number"], "nowrap");
     label_cell($myrow["bank_curr_code"], "nowrap");
+    label_cell($myrow["account_code"] . " " . $myrow["account_name"], "nowrap");
+    label_cell($myrow["bank_name"], "nowrap");
+    label_cell($myrow["bank_account_number"], "nowrap");
     label_cell($myrow["bank_address"]);
-       edit_button_cell("Edit".$myrow["account_code"], _("Edit"));
-       edit_button_cell("Delete".$myrow["account_code"], _("Delete"));
+       edit_button_cell("Edit".$myrow["id"], _("Edit"));
+       edit_button_cell("Delete".$myrow["id"], _("Delete"));
     end_row(); 
 }
 
@@ -135,20 +140,12 @@ if ($is_editing)
        hidden('selected_id', $selected_id);
        hidden('account_code');
        hidden('BankAccountCurrency', $_POST['BankAccountCurrency']);   
-       label_row(_("Bank Account GL Code:"), $_POST['account_code']);
-       set_focus('account_type');
+       set_focus('bank_account_name');
 } 
-else 
-{
-       gl_all_accounts_list_row(_("Bank Account GL Code:"), 'account_code', null, true);       
-       set_focus('account_code');
-}
 
-bank_account_types_list_row(_("Account Type:"), 'account_type', null); 
-
-text_row(_("Bank Name:"), 'bank_name', null, 50, 60);
 text_row(_("Bank Account Name:"), 'bank_account_name', null, 50, 100);
-text_row(_("Bank Account Number:"), 'bank_account_number', null, 30, 60);
+
+bank_account_types_list_row(_("Account Type:"), 'account_type', null); 
 
 if ($is_editing) 
 {
@@ -159,6 +156,13 @@ else
        currencies_list_row(_("Bank Account Currency:"), 'BankAccountCurrency', null);
 }      
 
+if($is_editing)
+       label_row(_("Bank Account GL Code:"), $_POST['account_code']);
+else 
+       gl_all_accounts_list_row(_("Bank Account GL Code:"), 'account_code', null, false);
+
+text_row(_("Bank Name:"), 'bank_name', null, 50, 60);
+text_row(_("Bank Account Number:"), 'bank_account_number', null, 30, 60);
 textarea_row(_("Bank Address:"), 'bank_address', null, 40, 5);
 
 end_table(1);
index c0a25e2786df5205cec1923d44cb1447139bbccb..3e447a4db238444c7c3e2547cc343ae7510c66e7 100644 (file)
@@ -72,7 +72,7 @@ if ($show_both_amounts)
 end_row();
 start_row();
 label_cells(_("Date"), sql2date($from_trans['trans_date']), "class='tableheader2'");
-label_cells(_("Transfer Type"), $from_trans['BankTransType'], "class='tableheader2'");
+label_cells(_("Transfer Type"), bank_account_types::transfer_type($from_trans['account_type']), "class='tableheader2'");
 label_cells(_("Reference"), $from_trans['ref'], "class='tableheader2'");
 end_row();
 comments_display_row(systypes::bank_transfer(), $trans_no);
index 02a3f7e00b733beb2d30608dd2b07f81211bd105..eafa9469cef5bbf251f5880b0772f8f616ab7e10 100644 (file)
@@ -60,7 +60,7 @@ label_cells(_("Date"), sql2date($to_trans['trans_date']), "class='tableheader2'"
 end_row();
 start_row();
 label_cells(_("From"), payment_person_types::person_name($to_trans['person_type_id'], $to_trans['person_id']), "class='tableheader2'", "colspan=$colspan1");
-label_cells(_("Deposit Type"), $to_trans['BankTransType'], "class='tableheader2'");
+label_cells(_("Deposit Type"), bank_account_types::transfer_type($to_trans['account_type']), "class='tableheader2'");
 end_row();
 start_row();
 label_cells(_("Reference"), $to_trans['ref'], "class='tableheader2'", "colspan=$colspan2");
index f52dc67221420c954d9908a9644d7efa4a05a023..520de94d252d2aa6c743a5bda2ce501a3a823ff5 100644 (file)
@@ -58,7 +58,7 @@ label_cells(_("Date"), sql2date($from_trans['trans_date']), "class='tableheader2
 end_row();
 start_row();
 label_cells(_("Pay To"), payment_person_types::person_name($from_trans['person_type_id'], $from_trans['person_id']), "class='tableheader2'", "colspan=$colspan1");
-label_cells(_("Payment Type"), $from_trans['BankTransType'], "class='tableheader2'");
+label_cells(_("Payment Type"),bank_account_types::transfer_type($from_trans['account_type']), "class='tableheader2'");
 end_row();
 start_row();
 label_cells(_("Reference"), $from_trans['ref'], "class='tableheader2'", "colspan=$colspan2");
index 93fcb294333f7ed728924f6cc4727eeaf559feb9..54345259c889ffb9c573a96e2dbfd3ecb69431f1 100644 (file)
@@ -3,13 +3,22 @@
 include_once($path_to_root . "/gl/includes/gl_db.inc");
 
 //----------------------------------------------------------------------------------
-
+//     Check if given account is used by any bank_account. 
+//     Returns id of first bank_account using account_code, null otherwise.
+//
+//     Keep in mind that direct posting to bank account is depreciated
+//     because we have no way to select right bank account if 
+//     there is more than one using given gl account.
+//
 function is_bank_account($account_code)
 {
-       $sql= "SELECT account_code FROM ".TB_PREF."bank_accounts WHERE account_code='$account_code'";
-       $result = db_query($sql, "retreive bank account currency");
-
-       return (db_num_rows($result) > 0);
+       $sql= "SELECT id FROM ".TB_PREF."bank_accounts WHERE account_code='$account_code'";
+       $result = db_query($sql, "checking account is bank account");
+       if (db_num_rows($result) > 0) {
+               $acct = db_fetch($result);
+               return $acct['id'];
+       } else
+               return false;
 }
 
 //----------------------------------------------------------------------------------
@@ -35,9 +44,9 @@ function get_company_currency()
 
 //----------------------------------------------------------------------------------
 
-function get_bank_account_currency($bankAccount)
+function get_bank_account_currency($id)
 {
-       $sql= "SELECT bank_curr_code FROM ".TB_PREF."bank_accounts WHERE account_code='$bankAccount'";
+       $sql= "SELECT bank_curr_code FROM ".TB_PREF."bank_accounts WHERE id='$id'";
        $result = db_query($sql, "retreive bank account currency");
 
        $myrow = db_fetch_row($result);
index 2f33cb531c272485e24e09fc4d728507dbfade61..0b94f9328723b49f80317879c8cfa5c2b919285d 100644 (file)
@@ -111,22 +111,6 @@ function check_db_has_movement_types($msg)
     }  
 }
 
-function db_has_bank_trans_types()
-{
-       return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."bank_trans_types");
-}
-
-function check_db_has_bank_trans_types($msg)
-{
-       global $path_to_root;
-    if (!db_has_bank_trans_types()) 
-    {
-       display_error($msg, true);
-       end_page();
-       exit;   
-    }  
-}
-
 function db_customer_has_branches($customer_id)
 {
        return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."cust_branch WHERE debtor_no='$customer_id'");
index 73efbfe1107bfefd8665c95f6985c34cedce5aad..9003ecebbdaf0e49fa008ee6cf0ff1588a52cc12 100644 (file)
@@ -110,11 +110,11 @@ class systypes
 //----------------------------------------------------------------------------------
 
 $bank_account_types_array = array (
-                                               0=> array ('id' => 0, 'name' => _("Savings Account")),
-                                               1=> array ('id' => 1, 'name' => _("Chequing Account")),
-                                               2=> array ('id' => 2, 'name' => _("Credit Account")),
-                                               3=> array ('id' => 3, 'name' => _("Cash Account"))
-                                               );
+       0=> array ('id' => 0, 'name' => _("Savings Account"), 'ptype' => _("Transfer")),
+       1=> array ('id' => 1, 'name' => _("Chequing Account"),'ptype' => _("Cheque")),
+       2=> array ('id' => 2, 'name' => _("Credit Account"), 'ptype' => _("Credit")),
+       3=> array ('id' => 3, 'name' => _("Cash Account"), 'ptype' => _("Cash"))
+       );
 
 class bank_account_types 
 {
@@ -130,8 +130,13 @@ class bank_account_types
                global $bank_account_types_array;
                return $bank_account_types_array[$index]['name'];
        }
+       
+       function transfer_type($index) 
+       {
+               global $bank_account_types_array;
+               return $bank_account_types_array[$index]['ptype'];
+       }
 }
-
 //----------------------------------------------------------------------------------
 
 include_once($path_to_root . "/manufacturing/includes/manufacturing_db.inc");
index 17c61441db0d32fa4ff24873daf4487f42c95fe7..0d38d72203d202131b40c275f4f6afffaa4d0b8d 100644 (file)
@@ -1137,7 +1137,7 @@ function movement_types_list_row($label, $name, $selected_id=null)
 }
 
 //-----------------------------------------------------------------------------------------------
-
+/*
 function bank_trans_types_list($name, $selected_id=null)
 {
        $sql = "SELECT id, name FROM ".TB_PREF."bank_trans_types";
@@ -1159,7 +1159,7 @@ function bank_trans_types_list_row($label, $name, $selected_id=null)
        bank_trans_types_list_cells($label, $name, $selected_id);
        echo "</tr>\n";
 }
-
+*/
 //-----------------------------------------------------------------------------------------------
 
 function workcenter_list($name, $selected_id=null, $all_option=false)
@@ -1196,11 +1196,11 @@ function workcenter_list_row($label, $name, $selected_id=null, $all_option=false
 
 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
 {
-       $sql = "SELECT ".TB_PREF."bank_accounts.account_code, bank_account_name, bank_curr_code
+       $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code
                FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
                WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
 
-       return combo_input($name, $selected_id, $sql, 'account_code', 'bank_account_name',
+       return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
        array(
                'format' => '_format_add_curr',
                'select_submit'=> $submit_on_change,
index 38b1d440f4c4dcf1279df993aa06a73ce243ee4b..b82ab8889b818689efd006f2e7c4f6308d391b56 100644 (file)
@@ -1,12 +1,13 @@
 <?php
 
-function add_supp_payment($supplier_id, $date_, $payment_type, $bank_account,
+function add_supp_payment($supplier_id, $date_, $bank_account,
        $amount, $discount, $ref, $memo_)
 {
        begin_transaction();
 
        $supplier_currency = get_supplier_currency($supplier_id);
     $bank_account_currency = get_bank_account_currency($bank_account);
+       $bank_gl_account = get_bank_gl_account($bank_account);
 
        $supp_amount = exchange_from_to($amount, $bank_account_currency, $supplier_currency, $date_);
        $supp_discount = exchange_from_to($discount, $bank_account_currency, $supplier_currency, $date_);
@@ -34,13 +35,13 @@ function add_supp_payment($supplier_id, $date_, $payment_type, $bank_account,
 
        if ($supp_amount != 0)
        {
-               add_gl_trans_supplier($trans_type, $payment_id, $date_, $bank_account, 0, 0,
+               add_gl_trans_supplier($trans_type, $payment_id, $date_, $bank_gl_account, 0, 0,
                        -$supp_amount, $supplier_id);
        }
 
    /*now enter the bank_trans entry */
        add_bank_trans($trans_type, $payment_id, $bank_account, $ref,
-               $date_, $payment_type, -($amount), payment_person_types::supplier(),
+               $date_, -($amount), payment_person_types::supplier(),
                $supplier_id, $bank_account_currency,
                "Could not add the supplier payment bank transaction");
 
index 0ddabcec3d27f4cb36cb8dc431ac437a17b4969a..bf5e539f747f8c66c92e86e8d0a66196c0f71516 100644 (file)
@@ -41,7 +41,7 @@ function get_supp_trans($trans_no, $trans_type=-1)
        {
                // it's a payment so also get the bank account
                $sql .= ", ".TB_PREF."bank_accounts.bank_name, ".TB_PREF."bank_accounts.bank_account_name, ".TB_PREF."bank_accounts.bank_curr_code,
-                       ".TB_PREF."bank_trans_types.name AS BankTransType, ".TB_PREF."bank_trans.amount AS BankAmount,
+                       ".TB_PREF."bank_accounts.account_type AS BankTransType, ".TB_PREF."bank_trans.amount AS BankAmount,
                        ".TB_PREF."bank_trans.ref ";
        }
 
@@ -50,7 +50,7 @@ function get_supp_trans($trans_no, $trans_type=-1)
        if ($trans_type == 22)
        {
                // it's a payment so also get the bank account
-               $sql .= ", ".TB_PREF."bank_trans, ".TB_PREF."bank_accounts, ".TB_PREF."bank_trans_types ";
+               $sql .= ", ".TB_PREF."bank_trans, ".TB_PREF."bank_accounts";
        }
 
        $sql .= " WHERE ".TB_PREF."supp_trans.trans_no=$trans_no
@@ -64,8 +64,7 @@ function get_supp_trans($trans_no, $trans_type=-1)
                // it's a payment so also get the bank account
                $sql .= " AND ".TB_PREF."bank_trans.trans_no =$trans_no
                        AND ".TB_PREF."bank_trans.type=$trans_type
-                       AND ".TB_PREF."bank_trans_types.id = ".TB_PREF."bank_trans.bank_trans_type_id
-                       AND ".TB_PREF."bank_accounts.account_code=".TB_PREF."bank_trans.bank_act ";
+                       AND ".TB_PREF."bank_accounts.id=".TB_PREF."bank_trans.bank_act ";
        }
 
        $result = db_query($sql, "Cannot retreive a supplier transaction");
index bb94fbdb866e138784ef8edcc0877608ad828f1b..a530ecb4d8863134066d557f8b266af0c47c72ca 100644 (file)
@@ -29,8 +29,6 @@ check_db_has_suppliers(_("There are no suppliers defined in the system."));
 
 check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
 
-check_db_has_bank_trans_types(_("There are no bank payment types defined in the system."));
-
 //----------------------------------------------------------------------------------------
 if ($ret = context_restore()) {
        if(isset($ret['supplier_id']))
@@ -38,8 +36,8 @@ if ($ret = context_restore()) {
 }
 if (isset($_POST['_supplier_id_editor'])) {
        context_call($path_to_root.'/purchasing/manage/suppliers.php?supplier_id='.$_POST['supplier_id'], 
-               array( 'supplier_id', 'bank_account', 'DatePaid', 
-                       'PaymentType', 'ref', 'amount', 'discount', 'memo_') );
+               array( 'supplier_id', 'bank_account', 'DatePaid', 'ref', 'amount', 
+                       'discount', 'memo_') );
 }
 if (isset($_POST['_DatePaid_changed'])) {
   $Ajax->activate('_ex_rate');
@@ -103,8 +101,6 @@ function display_controls()
                exchange_rate_display($bank_currency, $supplier_currency, $_POST['DatePaid']);
        }
 
-       bank_trans_types_list_row(_("Payment Type:"), 'PaymentType', null);
-
     ref_row(_("Reference:"), 'ref', '', references::get_next(22));
 
     text_row(_("Memo:"), 'memo_', null, 52,50);
@@ -193,13 +189,12 @@ function check_inputs()
 function handle_add_payment()
 {
        $payment_id = add_supp_payment($_POST['supplier_id'], $_POST['DatePaid'],
-               $_POST['PaymentType'], $_POST['bank_account'],
-               input_num('amount'), input_num('discount'), $_POST['ref'], $_POST['memo_']);
+               $_POST['bank_account'], input_num('amount'), input_num('discount'), 
+               $_POST['ref'], $_POST['memo_']);
 
        //unset($_POST['supplier_id']);
        unset($_POST['bank_account']);
        unset($_POST['DatePaid']);
-       unset($_POST['PaymentType']);
        unset($_POST['currency']);
        unset($_POST['memo_']);
        unset($_POST['amount']);
index 82d190a3a89547c4ff68c312a8b9632634e82547..756f686cf7d48576f309b0fd28cde6e18984a245 100644 (file)
@@ -49,7 +49,7 @@ start_row();
 if ($show_currencies)
        label_cells(_("Payment Currency"), $receipt['bank_curr_code'], "class='tableheader2'");
 label_cells(_("Amount"), number_format2(-$receipt['BankAmount'], user_price_dec()), "class='tableheader2'");
-label_cells(_("Payment Type"), $receipt['BankTransType'], "class='tableheader2'");
+label_cells(_("Payment Type"), bank_account_types::transfer_type($receipt['BankTransType']), "class='tableheader2'");
 end_row();
 start_row();
 if ($show_currencies) 
index ec98198dab9ff8de15d3e8f2d7a3e8fe2ac9ad6e..03639e75482a03983bf9c3c89b23af3a34b7a138 100644 (file)
@@ -24,8 +24,6 @@ check_db_has_customers(_("There are no customers defined in the system."));
 
 check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
 
-check_db_has_bank_trans_types(_("There are no bank payment types defined in the system."));
-
 //----------------------------------------------------------------------------------------
 if ($ret = context_restore()) {
        if(isset($ret['customer_id']))
@@ -36,7 +34,7 @@ if ($ret = context_restore()) {
 if (isset($_POST['_customer_id_editor'])) {
        context_call($path_to_root.'/sales/manage/customers.php?debtor_no='.$_POST['customer_id'], 
                array( 'customer_id', 'BranchID', 'bank_account', 'DateBanked', 
-                       'ReceiptType', 'ref', 'amount', 'discount', 'memo_') );
+                       'ref', 'amount', 'discount', 'memo_') );
 }
 
 if (isset($_GET['AddedID'])) {
@@ -121,9 +119,8 @@ if (isset($_POST['_DateBanked_changed'])) {
 
 if (isset($_POST['AddPaymentItem'])) {
        $payment_no = write_customer_payment(0, $_POST['customer_id'], $_POST['BranchID'],
-               $_POST['bank_account'], $_POST['DateBanked'], $_POST['ReceiptType'], $_POST['ref'],
+               $_POST['bank_account'], $_POST['DateBanked'], $_POST['ref'],
                input_num('amount'), input_num('discount'), $_POST['memo_']);
-
        meta_forward($_SERVER['PHP_SELF'], "AddedID=$payment_no");
 }
 
@@ -201,8 +198,6 @@ function display_item_form()
                        exchange_rate_display($cust_currency, $bank_currency, $_POST['DateBanked']);
                }
 
-               bank_trans_types_list_row(_("Type:"), 'ReceiptType', null);
-
                text_row(_("Reference:"), 'ref', null, 20, 40);
 
                textarea_row(_("Memo:"), 'memo_', null, 22, 4);
index 74054b06965669e886c5e6389b6fa44a6286a4cd..e1147b1c856465ed1643e32f475a12bb6ed56596 100644 (file)
@@ -3,7 +3,7 @@
   Write/update customer payment.
 */
 function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_account,
-       $date_, $receipt_type, $ref, $amount, $discount, $memo_)
+       $date_, $ref, $amount, $discount, $memo_)
 {
        begin_transaction();
 
@@ -12,6 +12,8 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
        $payment_no = write_customer_trans(12, $trans_no,
            $customer_id, $branch_id, $date_, $ref, $amount, $discount);
 
+       $bank_gl_account = get_bank_gl_account($bank_account);
+
        if ($trans_no != 0) {
          delete_comments(12, $trans_no);
          void_bank_trans(12, $trans_no, true);
@@ -21,7 +23,7 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
 
        /* Bank account entry first */
        add_gl_trans_customer(12, $payment_no, $date_,
-               $bank_account, 0, 0, $amount,  $customer_id,
+               $bank_gl_account, 0, 0, $amount,  $customer_id,
                "Cannot insert a GL transaction for the bank account debit");
 
        if ($branch_id != reserved_words::get_any_numeric()) {
@@ -52,7 +54,7 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
 
        /*now enter the bank_trans entry */
        add_bank_trans(12, $payment_no, $bank_account, $ref,
-               $date_, $receipt_type, $amount, payment_person_types::customer(), $customer_id,
+               $date_, $amount, payment_person_types::customer(), $customer_id,
                get_customer_currency($customer_id));
 
        add_comments(12, $payment_no, $date_, $memo_);
index e63ce8427423217f85e9d6b5fcd08f7dafb1c7ae..d11786356d4d2820942ec0e985515b461da0ae52 100644 (file)
@@ -157,7 +157,7 @@ function write_sales_invoice(&$invoice)
                        // and change line below.
                        $discount = 0; // $invoice->cash_discount*$amount;
                        $pmtno = write_customer_payment(0, $invoice->customer_id, 
-                               $invoice->Branch, $invoice->cash_account, $date_, 1,
+                               $invoice->Branch, $invoice->cash_account, $date_,
                                references::get_next(12), $amount-$discount, $discount,
                                _('Cash invoice').' '.$invoice->trans_no);
                        add_cust_allocation($amount, 12, $pmtno, 10, $invoice_no);
index 1f1fbd50c04677c2b3d6b174a8741b65f82f6329..cf0ae3f865a4b2fa596c1a544c3810b01a83268f 100644 (file)
@@ -32,7 +32,8 @@ label_cells(_("Amount"), price_format($receipt['ov_amount']), "class='tableheade
 label_cells(_("Discount"), price_format($receipt['ov_discount']), "class='tableheader2'");
 end_row();
 start_row();
-label_cells(_("Payment Type"), $receipt['BankTransType'], "class='tableheader2'");
+label_cells(_("Payment Type"), 
+       bank_account_types::transfer_type($receipt['BankTransType']), "class='tableheader2'");
 label_cells(_("Reference"), $receipt['reference'], "class='tableheader2'", "colspan=4");
 end_row();
 comments_display_row(systypes::cust_payment(), $trans_id);
index 529f2d10bbb69620c446734b2f5afa481aa0df3d..cdcdd73e14149c68def30770fea62eb05ed3847c 100644 (file)
@@ -1,3 +1,14 @@
+ALTER TABLE `0_bank_accounts` DROP PRIMARY KEY;
+ALTER TABLE `0_bank_accounts` ADD `id` SMALLINT(6) AUTO_INCREMENT PRIMARY KEY;
+ALTER TABLE `0_bank_accounts` ADD KEY (`account_code`);
+
+# Version for any MySQL but usable with digital only gl account codes:
+# UPDATE 0_bank_accounts SET id = account_code;
+# For any Applicable only to  MySQL >=4.0.4 :
+UPDATE `0_bank_trans`, `0_bank_accounts` SET 0_bank_trans.bank_act=0_bank_accounts.id 
+       WHERE 0_bank_trans.bank_act=0_bank_accounts.account_code; */
+
+
 ALTER TABLE `0_users` ADD `query_size` TINYINT(1) DEFAULT '10';
 
 DROP TABLE IF EXISTS `0_sales_pos`;