Bank Reconciliation
===================
* This chapter explains how to generate Bank Reconciliation statement.
* On clicking ``Mater menu`` >> ``Bank Reconciliation``, user gets a alert dialog which asks for an account name, period and other options required to display bank reconciliation statement.
* Click on ``View`` button will take user to the next page which contains Bank Reconciliation statement with ``cleared/uncleared`` transactions in a ``tabular format``.
* Layout is included in ``res/layout/bank_recon_index.xml``.
**File res/layout/bank_recon_table.xml**
* This layout contains a ``tablelayout`` with vertical and horizontal scroll.
* ``account name`` and ``period`` at the top of the screen.
* ``Save`` button located on the ``title bar``, at the left side of the ``scroll`` up/down button which is aligned at the extreme right side of the title bar.
.. code-block:: xml
.. image:: images/bank_reconciliation.png
:name: ABT main page
:align: center
* and the associated java code is given below,
**File src/com/example/gkaakash/bankReconciliation.java**
* Get values of all the required ``static variables`` from masterMenu.java to the activity ``bankReconciliation.java``.
* Send a ``request`` to the back-end server through controller functions and get the ``response``.
* Response will be the list containing Bank Reconciliation statement with cleared/uncleared transactions.
* Transaction list is displayed in a tabular formate using TableLayout.
* Set selected account name, period, transactions, reconcilation statement and cleared transaction dates programatically.
* The activity contains the essential and required import like
.. code-block:: java
package com.example.gkaakash;
import java.math.RoundingMode;
import java.text.BreakIterator;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import com.gkaakash.controller.Report;
import com.gkaakash.controller.Startup;
import android.R.integer;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.InputFilter.LengthFilter;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
* The activity intializes all the essential parameters and variables.
* OnCreate method calls all required methods at load time.
.. code-block:: java
public class bankReconciliation extends Activity{
TableLayout bankRecontable, statementtable;
TableRow tr, tr1;
LinearLayout Ll, Ll1;
TextView label,label1,tvaccontName,tvfinancialFromDate,tvfinancialToDate;
ArrayList bankReconGrid, for_naration, statementGrid;
static Object[] bankReconResult;
static Integer client_id;
private Report report;
ArrayList bankReconResultList, with_narration;
private ArrayList accountlist, for_clearenceDate;
static boolean narration_flag;
static boolean cleared_tran_flag;
static String[] ColumnNameList;
static int day, month, year, sel_day, sel_month, sel_year;
static final int VOUCHER_DATE_DIALOG_ID = 1;
TextView tvdate;
static String date, financialFromDate, financialToDate, accountName, fromDate, toDate;
DecimalFormat mFormat;
static int rowid;
boolean nara_flag=false;
AlertDialog dialog;
LinearLayout.LayoutParams params, params1;
String clearence_date;
String retrived_date;
String Cdate;
String result;
String[] dateParts;
Boolean updown=false;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.bank_recon_table);
report = new Report();
client_id= Startup.getClient_id();
//customizing title bar
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.bank_recon_title);
//two digit date format for dd and mm
mFormat= new DecimalFormat("00");
mFormat.setRoundingMode(RoundingMode.DOWN);
try {
financialFromDate =Startup.getfinancialFromDate();
String dateParts[] = financialFromDate.split("-");
String fromday = dateParts[0];
String frommonth = dateParts[1];
String fromyear = dateParts[2];
year = Integer.parseInt(fromyear);
month = Integer.parseInt(frommonth);
day = Integer.parseInt(fromday);
financialToDate=Startup.getFinancialToDate();
accountName = menu.selectedAccount;
fromDate = menu.givenfromDateString;
toDate = menu.givenToDateString;
cleared_tran_flag = menu.cleared_tran_flag;
narration_flag = menu.narration_flag;
tvaccontName = (TextView) findViewById( R.id.tvReconAccName );
tvfinancialFromDate = (TextView) findViewById( R.id.tvfinancialFromDate );
tvfinancialToDate = (TextView) findViewById( R.id.tvfinancialToDate );
tvaccontName.setText("Account name: "+accountName);
tvfinancialToDate.setText("Period : "+fromDate+" to "+toDate);
Object[] params = new Object[]{accountName,financialFromDate,fromDate,toDate,"No Project"};
Object[] flag = new Object[]{cleared_tran_flag};
setTableAndStatement(params,flag);
setbankRecon();
final Button btnSaveRecon = (Button)findViewById(R.id.btnSaveRecon);
btnSaveRecon.setVisibility(Button.VISIBLE);
final Button btnScrollDown = (Button)findViewById(R.id.btnScrollDown);
// to scroll the table up/down...
btnScrollDown.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(updown==false){
ScrollView sv = (ScrollView)findViewById(R.id.Scroll);
sv.fullScroll(ScrollView.FOCUS_DOWN);
btnScrollDown.setBackgroundResource(R.drawable.up);
updown=true;
}else {
ScrollView sv = (ScrollView)findViewById(R.id.Scroll);
sv.fullScroll(ScrollView.FOCUS_UP);
btnScrollDown.setBackgroundResource(R.drawable.down);
updown=false;
}
}
});
} catch (Exception e) {
toastValidationMessage("Please try again");
}
}
* get all the cleared and uncleared transactions from database for the given account, from date and to date along with bank reconciliation statement.
* add header and transaction rows in the first table and bank reconciliation statement in the second table.
.. code-block:: java
private void setTableAndStatement(Object[] params, Object[] flag) {
bankReconResult = (Object[]) report.getLedgerForBankRecon(params,flag, client_id);
bankReconGrid = new ArrayList();
for_naration = new ArrayList();
for_clearenceDate = new ArrayList();
/*
* bankReconResult.length-6 is for getting only uncleared transactions with
* total debit and total credit and set in table
* because last 6 rows are bank recon statement,
* we are not adding these rows in table for now
*/
for(int k = 0; k < (bankReconResult.length-6); k++)
{
Object[] t = (Object[]) bankReconResult[k];
bankReconResultList = new ArrayList();
with_narration = new ArrayList();
for(int i=0;i<(t.length);i++)
{
if(i == 6){//narration
if(narration_flag){
//bankReconResultList.add((String) t[i].toString());
with_narration.add((String) t[i].toString());
nara_flag = true;
}
}
else{
//bankReconResultList.add((String) t[i].toString());
bankReconResultList.add((String) t[i].toString());
with_narration.add((String) t[i].toString());
}
}
bankReconGrid.add(bankReconResultList);
for_naration.add(with_narration);
}
if(cleared_tran_flag==true){
for(int i=0;i();
for(int k = (bankReconResult.length-6); k < (bankReconResult.length); k++)
{
Object[] t = (Object[]) bankReconResult[k];
bankReconResultList = new ArrayList();
for(int i=0;i<(t.length);i++)
{
bankReconResultList.add((String) t[i].toString());
}
statementGrid.add(bankReconResultList);
}
statementtable = (TableLayout)findViewById(R.id.statementtable);
statementtable.removeAllViews();
addTable(statementtable, "statement");
}
* User can ``reconcile`` transactions ie. to set a clearance date and unclear the cleared transactions.
* To save the changes in database, we have added OnClickListener for ``Save`` button.
* Below method will read table rows, transactions with clearance date will be stored in a list and transactions without clearance date will be stored in another list.
* then send these lists to the backend and update the table.
.. code-block:: java
private void setbankRecon() {
Button btnSetBankRecon = (Button)findViewById(R.id.btnSaveRecon);
btnSetBankRecon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int rowcount = bankRecontable.getChildCount();
ArrayList listOfRowsTobeClear= new ArrayList();
boolean flag = false;
for(int i=0;i rowArray = new ArrayList();
/*
* get the clear tranction rows from table
* and pass these rows to backend (set bank reconciliation)
*/
if(!tvclearanceDate.getText().toString().equals("")){
flag = true;
rowArray.clear();
LinearLayout lv = (LinearLayout)((ViewGroup) row).getChildAt(0);
TextView tvVoucherCode = (TextView) lv.getChildAt(0); //voucher code
LinearLayout l = (LinearLayout)((ViewGroup) row).getChildAt(1);
TextView tvrefdate = (TextView) l.getChildAt(0); //ref date
LinearLayout l1 = (LinearLayout)((ViewGroup) row).getChildAt(2);
TextView tvparticular = (TextView) l1.getChildAt(0); //particular
LinearLayout lr = (LinearLayout)((ViewGroup) row).getChildAt(3);
TextView tvrefno = (TextView) lr.getChildAt(0); //ref no
LinearLayout l3 = (LinearLayout)((ViewGroup) row).getChildAt(4);
TextView tvdramount = (TextView) l3.getChildAt(0); //dr amount
LinearLayout l4 = (LinearLayout)((ViewGroup) row).getChildAt(5);
TextView tvcramount = (TextView) l4.getChildAt(0); //cr amount
EditText etmemo= (EditText)((ViewGroup) row).getChildAt(7); //memo
rowArray.add(tvVoucherCode.getText().toString());
rowArray.add(tvrefdate.getText().toString());
rowArray.add(tvparticular.getText().toString());
//check for the dr and cr amount
if(tvdramount.getText().toString().length() > 0){
rowArray.add(tvdramount.getText().toString());
rowArray.add(tvcramount.getText().toString());
}
else{
rowArray.add(tvcramount.getText().toString());
rowArray.add(tvdramount.getText().toString());
}
rowArray.add(tvclearanceDate.getText().toString());
rowArray.add(etmemo.getText().toString());
/*
System.out.println("i am row "+ i+ tvrefdate.getText().toString()
+tvparticular.getText().toString()
+tvdramount.getText().toString()
+tvcramount.getText().toString()
+tvclearanceDate.getText().toString()
+etmemo.getText().toString()); */
}
/*
* unclear the cleared transaction(delete cleared rows)
*/
if(tvclearanceDate.getText().toString().equals(" ")){
flag = false;
rowArray.clear();
LinearLayout l1 = (LinearLayout)((ViewGroup) row).getChildAt(2);
TextView tvparticular = (TextView) l1.getChildAt(0); //particular
LinearLayout lv = (LinearLayout)((ViewGroup) row).getChildAt(0);
TextView tvVoucherCode = (TextView) lv.getChildAt(0);//voucher code
rowArray.add(tvparticular.getText().toString());
rowArray.add(tvVoucherCode.getText().toString());
rowArray.add(toDate);
if(rowArray.size() >0){
report.deleteClearedRecon(rowArray, client_id);
}
}
/*
* add all cleared rows to the new Array
* flag=true for set bank recon
* flag=false for unclear transaction
*/
if(rowArray.size()!=0 && flag == true){
listOfRowsTobeClear.add(rowArray);
}
}//end of if
}//end of for
/*
* pass array of rows to be cleared to the controller
*/
if(listOfRowsTobeClear.size() >0){
report.setBankReconciliation(listOfRowsTobeClear, client_id);
}
bankRecontable.removeAllViews();
/*
* update table
*/
Object[] params = new Object[]{accountName,financialFromDate,fromDate,toDate,"No Project"};
Object[] clear_flag = new Object[]{cleared_tran_flag};
setTableAndStatement(params,clear_flag);
toastValidationMessage("Changes saved successfully");
}//end of onclick
});
}//end of function setbankrecon
* add header and transaction rows in the first table and bank reconciliation statemnt in the second table.
.. code-block:: java
private void addTable(TableLayout tableID, String flag) {
//System.out.println("reco grid"+bankReconGrid);
//for adding only header and transaction rows
if(!flag.equalsIgnoreCase("statement")){
if(bankReconGrid.size() > 1){
addHeader();
}
/** Create a TableRow dynamically **/
for(int i=0;i columnValue = new ArrayList();
tr = new TableRow(this);
//for last row(total debit and total credit)
if(i==bankReconGrid.size()-1){
if(bankReconGrid.size() > 1){
columnValue.addAll(bankReconGrid.get(i));
for(int k=0;k 0){
label.setText(columnValue.get(j));
}
label.setGravity(Gravity.CENTER|Gravity.RIGHT);
}
else
{
label.setGravity(Gravity.CENTER);
}
}
else{
addRow(columnValue.get(j),i,j,1);
Ll.setVisibility(LinearLayout.GONE);//voucher code
}
}
if(!cleared_tran_flag){
if(narration_flag==false){
addRow("",i,6,1); //date
//memo
EditText e = new EditText(this);
tr.addView(e);
}
else {
addRow("",i,6,1); //date
//memo
EditText e = new EditText(this);
tr.addView(e);
addRow(for_naration.get(i).get(6).toString(),i,8,1); //naration
}
}
else{
/*
* if transaction is clear set clearance date and memo into the textview
*/
addRow(bankReconGrid.get(i).get(6).toString(),i,6,1); //date
//memo
EditText e = new EditText(this);
e.setText(bankReconGrid.get(i).get(7).toString());
tr.addView(e);
if(narration_flag==true){
addRow(for_naration.get(i).get(6).toString(),i,8,1); //naration
}
}
// Add the TableRow to the TableLayout
tableID.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.MATCH_PARENT));
}
}
}
else{ //add reconciliation statement
for(int i=0;i columnValue = new ArrayList();
columnValue.clear();
columnValue.addAll(statementGrid.get(i));
tr1 = new TableRow(this);
for(int j=0;j