Permalink
Browse files

Subject: validation allow opening balance to take negative amount

Description:
1) in edit account allow negative opening balance except other
   symbolic charecters
2) it should not allow any symbol in between amount value
  • Loading branch information...
ashwinishinde committed Feb 19, 2014
1 parent b05c7d3 commit c405bd3826db08b24c5e5cb0e9208387ee921a0c
@@ -4,11 +4,10 @@
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@android:color/transparent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
@@ -27,12 +26,10 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Maximum 50 characters "
android:inputType="textCapWords"
android:inputType="textCapSentences"
android:maxLength="50"
style="@style/EditTextAppTheme"
android:textColor="#FFFFFF">
<requestFocus android:layout_width="wrap_content" />
</EditText>
@@ -85,7 +85,7 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="60"
android:inputType="numberDecimal"
android:inputType="phone"
style="@style/EditTextAppTheme" >
</EditText>
@@ -2,6 +2,9 @@
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.gkaakash.controller.Account;
import com.gkaakash.controller.Group;
import com.gkaakash.controller.Preferences;
@@ -429,8 +432,15 @@ public void onClick(View arg0) {
accountname = etAccName.getText().toString();
accountcode = etaccCode.getText().toString();
openingbalance= etOpBal.getText().toString();
// check for blank fields
//String pattern="([0-9]+)(\\.[0-9])";
// Pattern pattern = Pattern.compile("([0-9]+)(\\.[0-9])");
///Pattern pat = Pattern.compile(pattern);
//Matcher match = pat.matcher(etOpBal.getText().toString());
//if(match.find())
// {
//m.toastValidationMessage(context, "pattern match");
// }
// check for blank fields
if("Create New Sub-Group".equals(selSubGrpName)&&newsubgrpname.length()<1||("manually".equals(accCodeCheckFlag)&& accountcode.length()<1))
{
m.toastValidationMessage(context, "Please fill textfield");
@@ -439,19 +449,20 @@ public void onClick(View arg0) {
}else if((accountname.trim().length()<1)||(openingbalance.length()<1))
{
System.out.println("in else");
if(accountname.trim().length()<1){
etAccName.requestFocus();
etAccName.setBackgroundResource(R.drawable.btn_default_focused_holo_light);
}else {
etOpBal.requestFocus();
etOpBal.setBackgroundResource(R.drawable.btn_default_focused_holo_light);
}
m.toastValidationMessage(context, "Please fill textfield");
}else if(openingbalance.contains("-")&&!openingbalance.startsWith("-")||openingbalance.contains("#")||openingbalance.contains("*")||openingbalance.contains("+")){
etOpBal.requestFocus();
etOpBal.setBackgroundResource(R.drawable.btn_default_focused_holo_light);
m.toastValidationMessage(context, "Please insert proper balance");
}
else if("Create New Sub-Group".equals(selSubGrpName)&&newsubgrpname.length()>=1)
{
@@ -485,8 +496,7 @@ else if("Create New Sub-Group".equals(selSubGrpName)&&newsubgrpname.length()>=1)
{
SaveAccount();
}// close else
}
}
else
{
if(accountname.length()>=1)
@@ -620,7 +630,8 @@ public void onBackPressed() {
}
public void SaveAccount(){
Object[] params = new Object[]{accCodeCheckFlag,selGrpName,selSubGrpName,newsubgrpname,accountname,accountcode,openingbalance};
String Opbal = openingbalance.replaceAll("[\\-]+","-");
Object[] params = new Object[]{accCodeCheckFlag,selGrpName,selSubGrpName,newsubgrpname,accountname,accountcode,Opbal};
// call the setAccount method and pass the above parameters
account.setAccount(params,client_id);
getTotalBalances();
@@ -632,12 +643,10 @@ public void SaveAccount(){
addListenerOnItem();
module m = new module();
m.toastSuccessfulMessage(createAccount.this, "Account "+accountname+" have been saved successfully");
etSubGrp.setText("");
etAccName.setText("");
etaccCode.setText("");
etOpBal.setText("0.00");
}
}
@@ -3,6 +3,8 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.R.color;
import android.app.Activity;
@@ -345,19 +347,29 @@ public void onClick(DialogInterface dialog,int which) {
}
String newOpBal;
String Opbal = null;
newOpBal = etEditOpBal.getText().toString();
if (etEditOpBal.getVisibility() == View.VISIBLE) {
newOpBal = etEditOpBal.getText().toString();
String balance = newOpBal.substring(1, newOpBal.length());
if (newOpBal.length() < 1) {
newOpBal = "";
} else {
newOpBal = String.format("%.2f",Float.valueOf(newOpBal.trim()).floatValue());
} else if (newOpBal.startsWith("-")&&!balance.contains("-")){
String bal = newOpBal.replaceAll("[\\-]+","-");
newOpBal = String.format("%.2f",Float.valueOf(bal.trim()).floatValue());
}else if(newOpBal.startsWith("-")&&balance.contains("-")){
String bal = balance.replaceAll("[\\-]+","");
newOpBal = "-"+bal;
}
} else {
newOpBal = tvEditOpBal.getText().toString();
String bal = newOpBal.replaceAll("[\\-]+","-");
newOpBal = bal;
}
String groupname = tvEditGroupName.getText().toString();
String subgroupname = tvEditSubgroupName.getText().toString();
String accountcode = tvEditAccountCode.getText().toString();
if ((newAccountName.length() < 1)&& ("".equals(newOpBal))) {
String message = "Please fill field";
@@ -370,24 +382,33 @@ public void onClick(DialogInterface dialog,int which) {
String message = "Please fill accountname field";
m.toastValidationMessage(edit_account.this,message);
}
if ((newAccountName.length() >= 1)&& (!"".equals(newOpBal))) {
if ((newAccountName.length() >= 1)&&(!"".equals(newOpBal))) {
String accountcode_exist = account.checkAccountName(new Object[] {newAccountName,"", "" },client_id);
if (!newAccountName.equalsIgnoreCase(oldAccountName)
&& accountcode_exist.equals("exist")) {
String message = "Account '"+ newAccountName+ "' already exist";
m.toastValidationMessage(edit_account.this,message);
} else {
}else if(newOpBal.contains("-")&&!newOpBal.startsWith("-")
||newOpBal.contains("#")
||newOpBal.contains("*")
||newOpBal.contains("+")){
m.toastValidationMessage(edit_account.this, "Please insert proper balance");
}else {
Object[] params;
if ("Direct Income".equals(accountDetailList.get(1).toString())
|| "Direct Expense".equals(accountDetailList.get(1).toString())
|| "Indirect Income".equals(accountDetailList.get(1).toString())
|| "Indirect Expense".equals(accountDetailList.get(1).toString())) {
params = new Object[] {newAccountName,accountcode,groupname };
} else {
params = new Object[] {newAccountName,accountcode,groupname,newOpBal };
Opbal = newOpBal.replaceAll("[\\-]+","-");
params = new Object[] {newAccountName,accountcode,groupname,Opbal };
}
account.editAccount(params,client_id);
@@ -398,15 +419,15 @@ public void onClick(DialogInterface dialog,int which) {
String message = "Account name has been changed from '"+ oldAccountName
+ "' to '"+ newAccountName
+ "' and opening balance has been changed from '"+ oldOpBal
+ "' to '"+ newOpBal+ "'";
+ "' to '"+ Opbal+ "'";
m.toastValidationMessage(edit_account.this,message);
} else if (!newAccountName.equalsIgnoreCase(oldAccountName)) {
String message = "Account name has been changed from '"+ oldAccountName
+ "' to '"+ newAccountName+ "'";
m.toastValidationMessage(edit_account.this,message);
} else if (!newOpBal.equals(oldOpBal)) {
String message = "Opening balance has been changed from '"+ oldOpBal+ "' to '"
+ newOpBal+ "'";
+ Opbal+ "'";
m.toastValidationMessage(edit_account.this,message);
} else {
if ("edit".equals(msg)) {

0 comments on commit c405bd3

Please sign in to comment.