MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/lifemaze_in/bend/planner_callback.php
<?php
require_once('../lp_lib/lpObject.php');
require_once('../lp_lib/lp_calculation.php');
$lp_session  =  lpObject::newObject('lp_session');
$lp_session->startSession();

$libObject   = $lp_session->is_session_exist();
if(!$libObject){
	echo json_encode(array('sts' => false, 'info' =>"Required Login"));
	exit(0);
}

$is_customer = $libObject->is_customer();
if(!$is_customer){
	echo json_encode(array('sts' => false, 'info' =>"Required Login"));
	exit(0);
}
$dbObject = $libObject->getDBObject();
$real_db  = $libObject->get_db();
$frm = "";
if(isset($_POST['frm'])){
	$frm = $_POST['frm'];
}

/**** SAVE FAMILY ****/
if($frm === "save_family"){
	$cust_id   = $libObject->cust_id;	
	$fdata = "";
	if(isset($_POST['fdata'])){
		$fdata = $_POST['fdata'];
		$fdata = json_decode($fdata);
	}
	
	$qry_key     = "cust_id,";
	$qry_value   = "'$cust_id',";
	$exist_query = "";
	$upd_query   = "";
	$family_mode = "";
	$family_name = "";
	foreach($fdata as $form_data){
		$name  = $real_db->real_escape_string($form_data->name);
		$value = $real_db->real_escape_string($form_data->value);
		if($name === "family_dob"){
			//$value = date('Y-m-d',strtotime($value));
			$value    = new DateTime($value);
			$value    = $value->format("Y-m-d");
		}
		if($name === "family_id"){
			$family_id = $value;
		}
		if($name === "family_mode"){
			$family_mode = $value;
		}
		if($name === "family_name"){
			$family_name = $value;
		}
		if(($name !== "family_id") && ($name !== "family_mode")){
			if($value){
				$exist_query .= " $name = '$value' and";
				$qry_key     .= "$name,";
				$qry_value   .= "'$value',";
				$upd_query   .= "$name = '$value',";
			}
		}
	}
	$created_on = date("Y-m-d h:i:s");
	$qry_key   .= "created_on,";
	$qry_value .= "'$created_on',";	
	$upd_query .= "updated_on = '$created_on',";	
	$qry_key    = rtrim($qry_key,',');
	$qry_value  = rtrim($qry_value,',');
	$upd_query  = rtrim($upd_query,',');
	
	if($family_mode === "Self"){
		$dbObject->runQuery("UPDATE lp_customers SET cust_name = '$family_name' WHERE cust_id = '$cust_id'");
	}
	if((int)$family_id !== 0){
		$update_query = "UPDATE lp_cust_family SET $upd_query WHERE family_id = '$family_id' and cust_id = '$cust_id'";
		$dbObject->runQuery($update_query);
		
		$msg = "Family information updated successfully";
	}else{		
		$isExist_qry   = $dbObject->runQuery("SELECT * FROM lp_cust_family WHERE $exist_query cust_id = '$cust_id' and status= '1'");
		$expense_count = $dbObject->num_rows($isExist_qry);	
		if((int)$expense_count  === 0){
			$query = "insert into lp_cust_family ($qry_key) values ($qry_value)";
			if($dbObject->runQuery($query)){
				$msg = "Family information added successfully";
			}
		}else{
			$msg = "Family already in list";
		}
	}	
	echo $libObject->get_fam_list_content($msg);
}else
/**** EDIT FAMILY ****/
if($frm === "edit_family"){
	$cust_id   = $libObject->cust_id;	
	$family_id = "";
	if(isset($_POST['send_id'])){
		$family_id = $_POST['send_id'];
	}

	$family_qry  = $dbObject->runQuery("SELECT * FROM lp_cust_family WHERE family_id = '$family_id' and cust_id = '$cust_id' ");
	$family_info = $dbObject->result($family_qry);
	foreach($family_info as $family){
		$family_id       = $family->family_id;
		$family_name     = $family->family_name;
		//$family_dob      = date('d-M-Y',strtotime($family->family_dob));
		$family_age      = $family->family_age;
		$family_gender   = $family->family_gender;
		$family_earning  = $family->family_earning;
		$family_relation = $family->family_relation;
		if($family_relation === "0"){
			$family_mode = "Self";
		}else{
			$family_mode = "Family";
		}
		$family_dob    = new DateTime($family->family_dob);
		$family_dob    = $family_dob->format("d-M-Y");
	}
	echo json_encode(array("family_id" =>$family_id ,"family_name" =>$family_name, "family_dob" =>$family_dob, "family_age" =>$family_age, "family_gender" =>$family_gender,"family_earning" =>$family_earning,"family_relation" =>$family_relation,"family_mode" =>$family_mode,));
}else
/**** REMOVE FAMILY ****/
if($frm === "remove_family"){
	$cust_id   = $libObject->cust_id;	
	$family_id = "";
	if(isset($_POST['send_id'])){
		$family_id = $_POST['send_id'];
	}
	$dbObject->runQuery("UPDATE lp_cust_family SET status = '0' WHERE family_id = '$family_id' and cust_id = '$cust_id'");
	$msg = "Family information removed successfully";
	echo $libObject->get_fam_list_content($msg);
}else
/**** IT CHECK TAB CAN PROCEED TO expense AND LOAN ****/
if($frm === "profile_btn"){ 
	$cust_family_info  = $libObject->get_cust_family();
	$cust_family_rows  = $dbObject->num_rows($cust_family_info);
	if((int)$cust_family_rows > 0){
		echo json_encode(array('sts' => true, 'info' =>"Let's Goto Expense and Loan"));
	}else{
		echo json_encode(array('sts' => FALSE, 'info' =>"Please add your family members"));
	}
}else
/**** SAVE EXPENSE ****/
if($frm === "save_expense"){ 
	$cust_id   = $libObject->cust_id;	
	$fdata = "";
	if(isset($_POST['fdata'])){
		$fdata = $_POST['fdata'];
		$fdata = json_decode($fdata);
	}
	
	$qry_key     = "cust_id,";
	$qry_value   = "'$cust_id',";
	$exist_query = "";
	$upd_query   = "";
	foreach($fdata as $form_data){
		$name  = $real_db->real_escape_string($form_data->name);
		$value = $real_db->real_escape_string($form_data->value);
		if($name === "expense_id"){
			$expense_id = $value;
		}else{
			$exist_query .= " $name = '$value' and";
		}		
		if($name === "exp_amt"){
			$exp_amt = $value;
		}		
		if($name === "exp_frq"){
			$exp_frq_array  = array(1=>1,2=>12,3=>4,4=>2,5=>1);
			$multi_value    = $exp_frq_array[$value];
		}
		
		if($value){
			$qry_key     .= "$name,";
			$qry_value   .= "'$value',";
			$upd_query   .= "$name = '$value',";
		}
	}	
	$exp_yearly     = $exp_amt * $multi_value;
	$qry_key       .= "exp_yearly,";
	$qry_value     .= "$exp_yearly,";
	$upd_query     .= "exp_yearly = '$exp_yearly',";
	
	$created_on = date("Y-m-d h:i:s");
	$qry_key   .= "created_on,";
	$qry_value .= "'$created_on',";	
	$upd_query .= "updated_on = '$created_on',";	
	$qry_key    = rtrim($qry_key,',');
	$qry_value  = rtrim($qry_value,',');
	$upd_query  = rtrim($upd_query,',');
	
	if((int)$expense_id !== 0){
		$update_query = "UPDATE lp_cust_expense SET $upd_query WHERE expense_id = '$expense_id' and cust_id = '$cust_id'";
		$dbObject->runQuery($update_query);
		$msg = "Expense information updated successfully";
	}else{
		$isExist_qry   = $dbObject->runQuery("SELECT * FROM lp_cust_expense WHERE $exist_query cust_id = '$cust_id' and status= '1'");
		$expense_count = $dbObject->num_rows($isExist_qry);	
		if((int)$expense_count  === 0){
			$query = "insert into lp_cust_expense ($qry_key) values ($qry_value)";
			if($dbObject->runQuery($query)){
				$msg = "Expense information added successfully";
			}
		}else{
			$msg = "Expense already in list";
		}
	}
	
	echo $libObject->get_expense_content($msg);
}else
/**** EDIT EXPENSE ****/
if($frm === "edit_expense"){
	$cust_id   = $libObject->cust_id;	
	$expense_id = "";
	if(isset($_POST['send_id'])){
		$expense_id = $_POST['send_id'];
	}
	$expense_qry  = $dbObject->runQuery("SELECT * FROM lp_cust_expense WHERE expense_id = '$expense_id' and cust_id = '$cust_id' ");
	$expense_info = $dbObject->result($expense_qry);
	foreach($expense_info as $expense){
		$expense_id     = $expense->expense_id;		
		$cust_id        = $expense->cust_id;
		$exp_cat        = $expense->exp_cat;
		$exp_sub_cat    = $expense->exp_sub_cat;
		$exp_frq        = $expense->exp_frq;
		$exp_amt        = $expense->exp_amt;
		$exp_family     = $expense->exp_family;
		
		$exp_info        = $libObject->get_expense($exp_cat);
		$expense_related = $exp_info[0]->expense_related;
	}
	echo json_encode(array("expense_id" =>$expense_id ,"exp_cat" =>$exp_cat, "exp_family" =>$exp_family, "exp_sub_cat" =>$exp_sub_cat, "exp_frq" =>$exp_frq, "exp_amt" =>$exp_amt,"expense_related" =>$expense_related,));
}else
/**** REMOVE EXPENSE ****/
if($frm === "remove_expense"){ 
	$cust_id   = $libObject->cust_id;	
	$expense_id = "";
	if(isset($_POST['send_id'])){
		$expense_id = $_POST['send_id'];
	}
	$dbObject->runQuery("UPDATE lp_cust_expense SET status = '0' WHERE expense_id = '$expense_id' and cust_id = '$cust_id'");
	$msg = "Expense information removed successfully";
	echo $libObject->get_expense_content($msg);
}else
/**** SAVE LOAN ****/
if($frm === "save_loan"){
	$cust_id   = $libObject->cust_id;	
	$fdata = "";
	if(isset($_POST['fdata'])){
		$fdata = $_POST['fdata'];
		$fdata = json_decode($fdata);
	}
	
	$qry_key     = "cust_id,";
	$qry_value   = "'$cust_id',";
	$exist_query = "";
	$upd_query   = "";
	foreach($fdata as $form_data){
		$name  = $real_db->real_escape_string($form_data->name);
		$value = $real_db->real_escape_string($form_data->value);
		if($name === "loan_start"){
			//$value = date('Y-m-d',strtotime($value));
			$value    = new DateTime($value);
			$value    = $value->format("Y-m-d");
		}
		if($name === "loan_id"){
			$loan_id = $value;
		}else{
			$exist_query .= " $name = '$value' and";
		}
		
		if($name === "loan_emi"){
			$loan_emi = $value;
		}		
		if($name === "loan_frq"){
			$loan_frq_array  = array(1=>1,2=>12,3=>4,4=>2,5=>1);
			$multi_value    = $loan_frq_array[$value];
		}
		
		if($value){
			$qry_key     .= "$name,";
			$qry_value   .= "'$value',";
			$upd_query   .= "$name = '$value',";
		}
	}
	$emi_yearly  = $loan_emi * $multi_value;
	$qry_key    .= "emi_yearly,";
	$qry_value  .= "$emi_yearly,";
	$upd_query  .= "emi_yearly = '$emi_yearly',";
	
	$created_on = date("Y-m-d h:i:s");
	$qry_key   .= "created_on,";
	$qry_value .= "'$created_on',";	
	$upd_query .= "updated_on = '$created_on',";	
	$qry_key    = rtrim($qry_key,',');
	$qry_value  = rtrim($qry_value,',');
	$upd_query  = rtrim($upd_query,',');
	
	if((int)$loan_id !== 0){		
		$update_query = "UPDATE lp_cust_loan SET $upd_query WHERE loan_id = '$loan_id' and cust_id = '$cust_id'";
		$dbObject->runQuery($update_query);
		$msg = "Loan information updated successfully";
	}else{
		$isExist_qry   = $dbObject->runQuery("SELECT * FROM lp_cust_loan WHERE $exist_query cust_id = '$cust_id' and status= '1'");
		$loan_count = $dbObject->num_rows($isExist_qry);	
		if((int)$loan_count  === 0){
			$query = "insert into lp_cust_loan ($qry_key) values ($qry_value)";
			if($dbObject->runQuery($query)){
				$msg = "Loan information added successfully";
			}
		}else{
			$msg = "Loan already in list";
		}
	}
	echo $libObject->get_loan_content($msg);
}else
/**** EDIT LOAN ****/
if($frm === "edit_loan"){
	$cust_id   = $libObject->cust_id;	
	$loan_id = "";
	if(isset($_POST['send_id'])){
		$loan_id = $_POST['send_id'];
	}					
	$loan_qry  = $dbObject->runQuery("SELECT * FROM lp_cust_loan WHERE loan_id = '$loan_id' and cust_id = '$cust_id' ");
	$loan_info = $dbObject->result($loan_qry);
	foreach($loan_info as $loan){
		$loan_id            = $loan->loan_id;
		$loan_type          = $loan->loan_type;
		$loan_name          = $loan->loan_name;
		$loan_outstanding   = $loan->loan_outstanding;
		$loan_frq           = $loan->loan_frq;
		$loan_remaining     = $loan->loan_remaining;
		$loan_emi           = $loan->loan_emi;
		$loan_interest      = $loan->loan_interest;
		//$loan_start         = date('d-M-Y',strtotime($loan->loan_start));
		$loan_start    = new DateTime($loan->loan_start);
		$loan_start    = $loan_start->format("d-M-Y");
		$loan_interest_type = $loan->loan_interest_type;
	}
	echo json_encode(array("loan_id" =>$loan_id ,"loan_type" =>$loan_type, "loan_name" =>$loan_name, "loan_outstanding" =>$loan_outstanding, "loan_frq" =>$loan_frq,"loan_remaining" =>$loan_remaining, "loan_emi" =>$loan_emi, "loan_interest" =>$loan_interest, "loan_start" =>$loan_start, "loan_interest_type" =>$loan_interest_type));
}else
/**** REMOVE LOAN ****/
if($frm === "remove_loan"){
	$cust_id   = $libObject->cust_id;	
	$loan_id = "";
	if(isset($_POST['send_id'])){
		$loan_id = $_POST['send_id'];
	}
	$dbObject->runQuery("UPDATE lp_cust_loan SET status = '0' WHERE loan_id = '$loan_id' and cust_id = '$cust_id'");
	$msg = "Loan information removed successfully";
	echo $libObject->get_loan_content($msg);
}else
/**** IT CHECK TAB CAN PROCEED TO INCOME AND ASSET ****/
if($frm === "expense_btn"){
	$expense_list_info  = $libObject->get_expense_list();
	$expense_list_rows  = $dbObject->num_rows($expense_list_info);
	$loan_list_info     = $libObject->get_loan_list();
	$loan_list_rows     = $dbObject->num_rows($loan_list_info);
	if(((int)$expense_list_rows === 0) && ((int)$loan_list_rows === 0)){
		echo json_encode(array('sts' => FALSE, 'info' =>"Please add your Expense and Loan"));
	}else{
		echo json_encode(array('sts' => true, 'info' =>"Let's Goto Income and Asset"));
	}
}else
/**** SAVE INCOME ****/
if($frm === "save_income"){
	$cust_id   = $libObject->cust_id;	
	$fdata = "";
	if(isset($_POST['fdata'])){
		$fdata = $_POST['fdata'];
		$fdata = json_decode($fdata);
	}
	
	$qry_key     = "cust_id,";
	$qry_value   = "'$cust_id',";
	$exist_query = "";
	$upd_query   = "";
	foreach($fdata as $form_data){
		$name  = $real_db->real_escape_string($form_data->name);
		$value = $real_db->real_escape_string($form_data->value);
		if($name === "income_id"){
			$income_id = $value;
		}else{
			$exist_query .= " $name = '$value' and";
		}
		
		if($name === "income_amt"){
			$income_amt = $value;
		}		
		if($name === "income_pay_type"){
			$income_frq_array  = array(1=>1,2=>12,3=>4,4=>2,5=>1);
			$multi_value    = $income_frq_array[$value];
		}
		
		if($value){
			$qry_key     .= "$name,";
			$qry_value   .= "'$value',";
			$upd_query   .= "$name = '$value',";
		}
	}
	$income_yearly  = $income_amt * $multi_value;
	$qry_key       .= "income_yearly,";
	$qry_value     .= "$income_yearly,";
	$upd_query     .= "income_yearly = '$income_yearly',";
	
	$created_on = date("Y-m-d h:i:s");
	$qry_key   .= "created_on,";
	$qry_value .= "'$created_on',";	
	$upd_query .= "updated_on = '$created_on',";	
	$qry_key    = rtrim($qry_key,',');
	$qry_value  = rtrim($qry_value,',');
	$upd_query  = rtrim($upd_query,',');
	
	if((int)$income_id !== 0){		
		$update_query = "UPDATE lp_cust_income SET $upd_query WHERE income_id = '$income_id' and cust_id = '$cust_id'";
		$dbObject->runQuery($update_query);
		$msg = "Income information updated successfully";
	}else{
		$isExist_qry   = $dbObject->runQuery("SELECT * FROM lp_cust_income WHERE $exist_query cust_id = '$cust_id' and status= '1'");
		$loan_count = $dbObject->num_rows($isExist_qry);	
		if((int)$loan_count  === 0){
			$query = "insert into lp_cust_income ($qry_key) values ($qry_value)";
			if($dbObject->runQuery($query)){
				$msg = "Income Information added successfully";
			}
		}else{
			$msg = "Income already in list";
		}
	}
	echo $libObject->get_income_content($msg);
}else
/**** EDIT INCOME ****/
if($frm === "edit_income"){
	$cust_id   = $libObject->cust_id;	
	$income_id = "";
	if(isset($_POST['send_id'])){
		$income_id = $_POST['send_id'];
	}					
	$income_qry  = $dbObject->runQuery("SELECT * FROM lp_cust_income WHERE income_id = '$income_id' and cust_id = '$cust_id' ");
	$income_info = $dbObject->result($income_qry);
	foreach($income_info as $income){
		$income_id        = $income->income_id;
		$cust_id          = $income->cust_id;
		$income_type      = $income->income_type;
		$income_family    = $income->income_family;
		$income_amt       = $income->income_amt;
		$income_pay_type  = $income->income_pay_type;;
	}
	echo json_encode(array("income_id" =>$income_id ,"income_type" =>$income_type, "income_family" =>$income_family, "income_amt" =>$income_amt, "income_pay_type" =>$income_pay_type));
}else
/**** REMOVE INCOME ****/
if($frm === "remove_income"){
	$cust_id   = $libObject->cust_id;	
	$income_id = "";
	if(isset($_POST['send_id'])){
		$income_id = $_POST['send_id'];
	}
	$dbObject->runQuery("UPDATE lp_cust_income SET status = '0' WHERE income_id = '$income_id' and cust_id = '$cust_id'");
	$msg = "Income information removed successfully";
	echo $libObject->get_income_content($msg);
}else
/**** SAVE ASSET ****/
if($frm === "save_asset"){
	$cust_id   = $libObject->cust_id;	
	$fdata = "";
	if(isset($_POST['fdata'])){
		$fdata = $_POST['fdata'];
		$fdata = json_decode($fdata);
	}
	
	$qry_key     = "cust_id,";
	$qry_value   = "'$cust_id',";
	$exist_query = "";
	$upd_query   = "";
	foreach($fdata as $form_data){
		$name  = $real_db->real_escape_string($form_data->name);
		$value = $real_db->real_escape_string($form_data->value);
		if($name === "asset_id"){
			$asset_id = $value;
		}else{
			$exist_query .= " $name = '$value' and";
		}
		if($value){
			$qry_key     .= "$name,";
			$qry_value   .= "'$value',";
			$upd_query   .= "$name = '$value',";
		}
	}
	$created_on = date("Y-m-d h:i:s");
	$qry_key   .= "created_on,";
	$qry_value .= "'$created_on',";	
	$upd_query .= "updated_on = '$created_on',";	
	$qry_key    = rtrim($qry_key,',');
	$qry_value  = rtrim($qry_value,',');
	$upd_query  = rtrim($upd_query,',');
	
	if((int)$asset_id !== 0){		
		$update_query = "UPDATE lp_cust_asset SET $upd_query WHERE asset_id = '$asset_id' and cust_id = '$cust_id'";
		$dbObject->runQuery($update_query);
		$msg = "Asset information updated successfully";
	}else{
		$isExist_qry   = $dbObject->runQuery("SELECT * FROM lp_cust_asset WHERE $exist_query cust_id = '$cust_id' and status= '1'");
		$loan_count = $dbObject->num_rows($isExist_qry);	
		if((int)$loan_count  === 0){
			$query = "insert into lp_cust_asset ($qry_key) values ($qry_value)";
			if($dbObject->runQuery($query)){
				$msg = "Asset information added successfully";
			}
		}else{
			$msg = "Asset already in list";
		}
	}
	echo $libObject->get_asset_content($msg);
}else
/**** EDIT ASSET ****/
if($frm === "edit_asset"){
	$cust_id   = $libObject->cust_id;	
	$asset_id = "";
	if(isset($_POST['send_id'])){
		$asset_id = $_POST['send_id'];
	}					
	$asset_qry  = $dbObject->runQuery("SELECT * FROM lp_cust_asset WHERE asset_id = '$asset_id' and cust_id = '$cust_id' ");
	$asset_info = $dbObject->result($asset_qry);
	foreach($asset_info as $asset){		
		$asset_id             = $asset->asset_id;
		$cust_id              = $asset->cust_id;
		$asset_family         = $asset->asset_family;
		$asset_name           = $asset->asset_name;
		$asset_current_value  = $asset->asset_current_value;
	}
	echo json_encode(array("asset_id" =>$asset_id ,"asset_family" =>$asset_family, "asset_name" =>$asset_name, "asset_current_value" =>$asset_current_value));
}else
/**** REMOVE INCOME ****/
if($frm === "remove_asset"){
	$cust_id   = $libObject->cust_id;	
	$asset_id = "";
	if(isset($_POST['send_id'])){
		$asset_id = $_POST['send_id'];
	}
	$dbObject->runQuery("UPDATE lp_cust_asset SET status = '0' WHERE asset_id = '$asset_id' and cust_id = '$cust_id'");
	$msg = "Asset information removed successfully";
	echo $libObject->get_asset_content($msg);
}else
/**** IT CHECK TAB CAN PROCEED TO INVESTMENTS ****/
if($frm === "income_btn"){	
	$income_list_info  = $libObject->get_income_list();
	$income_list_rows  = $dbObject->num_rows($income_list_info);
	$asset_list_info  = $libObject->get_asset_list();
	$asset_list_rows  = $dbObject->num_rows($asset_list_info);	
	if(((int)$income_list_rows === 0) && ((int)$asset_list_rows === 0)){
		echo json_encode(array('sts' => FALSE, 'info' =>"Please add your Income and Asset"));
	}else{
		echo json_encode(array('sts' => true, 'info' =>"Let's Goto Investments"));
	}
}else
/**** SAVE BANK ****/
if($frm === "save_bank"){
	$cust_id   = $libObject->cust_id;	
	$fdata = "";
	if(isset($_POST['fdata'])){
		$fdata = $_POST['fdata'];
		$fdata = json_decode($fdata);
	}
	
	$qry_key     = "cust_id,";
	$qry_value   = "'$cust_id',";
	$exist_query = "";
	$upd_query   = "";
	foreach($fdata as $form_data){
		$name  = $real_db->real_escape_string($form_data->name);
		$value = $real_db->real_escape_string($form_data->value);		
		
		if($name === "bank_startdate"){
			//$value = date('Y-m-d',strtotime($value));
			$value    = new DateTime($value);
			$value    = $value->format("Y-m-d");
		}
		if($name === "bank_maturity"){
			//$value = date('Y-m-d',strtotime($value));
			$value    = new DateTime($value);
			$value    = $value->format("Y-m-d");
		}		
		if($name === "bank_scheme"){
			$bank_scheme = $value;
		}		
		if($name === "bank_amt"){
			$bank_amt = $value;
		}
		
		if($name === "bank_id"){
			$bank_id = $value;
		}else{
			$exist_query .= " $name = '$value' and";
		}
		if($value){
			$qry_key     .= "$name,";
			$qry_value   .= "'$value',";
			$upd_query   .= "$name = '$value',";
		}
	}
	if((int)$bank_scheme === 3){
		$multi_value = 12;
	}else{
		$multi_value = 1;
	}
	
	$bank_yearly  = $bank_amt * $multi_value;
	$qry_key       .= "bank_yearly,";
	$qry_value     .= "$bank_yearly,";
	$upd_query     .= "bank_yearly = '$bank_yearly',";
	
	$created_on = date("Y-m-d h:i:s");
	$qry_key   .= "created_on,";
	$qry_value .= "'$created_on',";	
	$upd_query .= "updated_on = '$created_on',";	
	$qry_key    = rtrim($qry_key,',');
	$qry_value  = rtrim($qry_value,',');
	$upd_query  = rtrim($upd_query,',');
	
	if((int)$bank_id !== 0){		
		$update_query = "UPDATE lp_cust_bank SET $upd_query WHERE bank_id = '$bank_id' and cust_id = '$cust_id'";
		$dbObject->runQuery($update_query);
		$msg = "Bank information updated successfully";
	}else{
		$isExist_qry   = $dbObject->runQuery("SELECT * FROM lp_cust_bank WHERE $exist_query cust_id = '$cust_id' and status= '1'");
		$loan_count = $dbObject->num_rows($isExist_qry);	
		if((int)$loan_count  === 0){
			$query = "insert into lp_cust_bank ($qry_key) values ($qry_value)";
			if($dbObject->runQuery($query)){
				$msg = "Bank information added successfully";
			}
		}else{
			$msg = "Bank already in list";
		}
	}
	echo $libObject->get_bank_content($msg);
}else
/**** EDIT BANK ****/
if($frm === "edit_bank"){
	$cust_id   = $libObject->cust_id;	
	$bank_id = "";
	if(isset($_POST['send_id'])){
		$bank_id = $_POST['send_id'];
	}					
	$bank_qry  = $dbObject->runQuery("SELECT * FROM lp_cust_bank WHERE bank_id = '$bank_id' and cust_id = '$cust_id' ");
	$bank_info = $dbObject->result($bank_qry);
	foreach($bank_info as $bank){					
		$bank_id  			= $bank->bank_id;
		$cust_id  			= $bank->cust_id;
		$bank_family  		= $bank->bank_family;
		$bank_scheme 		= $bank->bank_scheme;
		$bank_descript  	= $bank->bank_descript;
		$bank_amt    		= $bank->bank_amt;
		$bank_type          = $bank->bank_type;
		//$bank_startdate     = date('d-M-Y',strtotime($bank->bank_startdate));
		$bank_startdate     = new DateTime($bank->bank_startdate);
		$bank_startdate     = $bank_startdate->format("d-M-Y");
		$bank_tenure        = $bank->bank_tenure;
		$bank_tenure_type   = $bank->bank_tenure_type;
		$bank_ror           = $bank->bank_ror;
		//$bank_maturity      = date('d-M-Y',strtotime($bank->bank_maturity));
		$bank_maturity      = new DateTime($bank->bank_maturity);
		$bank_maturity      = $bank_maturity->format("d-M-Y");
		$bank_maturity_amt  = $bank->bank_maturity_amt;
	}
	echo json_encode(array("bank_id" =>$bank_id ,"bank_family" =>$bank_family, "bank_scheme" =>$bank_scheme, "bank_descript" =>$bank_descript, "bank_amt" =>$bank_amt, "bank_type" =>$bank_type, "bank_startdate" =>$bank_startdate, "bank_tenure" =>$bank_tenure, "bank_tenure_type" =>$bank_tenure_type, "bank_ror" =>$bank_ror, "bank_maturity" =>$bank_maturity, "bank_maturity_amt" =>$bank_maturity_amt));
}else
/**** REMOVE INCOME ****/
if($frm === "remove_bank"){
	$cust_id   = $libObject->cust_id;	
	$bank_id = "";
	if(isset($_POST['send_id'])){
		$bank_id = $_POST['send_id'];
	}
	$dbObject->runQuery("UPDATE lp_cust_bank SET status = '0' WHERE bank_id = '$bank_id' and cust_id = '$cust_id'");
	$msg = "Bank information removed successfully";
	echo $libObject->get_bank_content($msg);
}else
/**** SAVE INSURANCE ****/
if($frm === "save_insurance"){
	$cust_id   = $libObject->cust_id;	
	$fdata = "";
	if(isset($_POST['fdata'])){
		$fdata = $_POST['fdata'];
		$fdata = json_decode($fdata);
	}
	$newfdata = array();
	foreach ($fdata as $option) {
		$name  = $option->name;
		$value = $option->value;
		if (array_key_exists($name,$newfdata)){			
			$prv_val = $newfdata[$name];
			$newfdata[$name] = "$prv_val,$value";
		}else{
			$newfdata[$name] = $value;
		}
	}

	$qry_key     = "cust_id,";
	$qry_value   = "'$cust_id',";
	$exist_query = "";
	$upd_query   = "";
	$ins_insured = "";
	foreach ($newfdata as $key => $value){
		$name  = $real_db->real_escape_string($key);
		$value = $real_db->real_escape_string($value);
		if($name === "ins_start_date"){
			$value    = new DateTime($value);
			$value    = $value->format("Y-m-d");
		}
		if($name === "ins_issued_date"){
			$value    = new DateTime($value);
			$value    = $value->format("Y-m-d");
		}
		if($name === "ins_due_date"){
			$value    = new DateTime($value);
			$value    = $value->format("Y-m-d");
		}
		if($name === "vesting_date"){
			$value    = new DateTime($value);
			$value    = $value->format("Y-m-d");
		}
		if($name === "ins_type"){
			$ins_type = $value;
		}
		if($name === "ins_premium"){
			$ins_premium = $value;
		}
		if($name === "pen_amt"){
			$pen_amt = $value;
		}
		if($name === "ins_frq"){
			$ins_frq = $value;
		}
		if($name === "pen_frq"){
			$pen_frq = $value;
		}
		
		if($name === "insurance_id"){
			$insurance_id = $value;
		}else{
			$exist_query .= " $name = '$value' and";
		}
		if($value){
			$qry_key     .= "$name,";
			$qry_value   .= "'$value',";
			$upd_query   .= "$name = '$value',";
		}
	}
	$in_frq_array  = array(1=>1,2=>12,3=>4,4=>2,5=>1);
	if((int)$ins_type === 2){	
		$multi_value    = $in_frq_array[$ins_frq];
		$premium_yearly  = $ins_premium * $multi_value;
	}else
	if((int)$ins_type === 6){	
		$multi_value    = $in_frq_array[$pen_frq];
		$premium_yearly  = $pen_amt * $multi_value;
	}else{
		$multi_value = 1;
		$premium_yearly  = $ins_premium * $multi_value;
	}	
	
	$qry_key       .= "premium_yearly,";
	$qry_value     .= "$premium_yearly,";
	$upd_query     .= "premium_yearly = '$premium_yearly',";
	
	$created_on = date("Y-m-d h:i:s");
	$qry_key   .= "created_on,";
	$qry_value .= "'$created_on',";	
	$upd_query .= "updated_on = '$created_on',";	
	$qry_key    = rtrim($qry_key,',');
	$qry_value  = rtrim($qry_value,',');
	$upd_query  = rtrim($upd_query,',');
	
	if((int)$insurance_id !== 0){		
		$update_query = "UPDATE lp_cust_insurance SET $upd_query WHERE insurance_id = '$insurance_id' and cust_id = '$cust_id'";
		$dbObject->runQuery($update_query);
		$msg = "Insurance information updated successfully";
	}else{
		$isExist_qry   = $dbObject->runQuery("SELECT * FROM lp_cust_insurance WHERE $exist_query cust_id = '$cust_id' and status= '1'");
		$loan_count = $dbObject->num_rows($isExist_qry);	
		if((int)$loan_count  === 0){
			$query = "insert into lp_cust_insurance ($qry_key) values ($qry_value)";
			if($dbObject->runQuery($query)){
				$msg = "Insurance information added successfully";
			}
		}else{
			$msg = "Insurance already in list";
		}
	}
	echo $libObject->get_insurance_content($msg);
}else
/**** EDIT INSURANCE ****/
if($frm === "edit_insurance"){
	$cust_id   = $libObject->cust_id;	
	$insurance_id = "";
	if(isset($_POST['send_id'])){
		$insurance_id = $_POST['send_id'];
	}					
	$insurance_qry  = $dbObject->runQuery("SELECT * FROM lp_cust_insurance WHERE insurance_id = '$insurance_id' and cust_id = '$cust_id' ");
	$insurance_info = $dbObject->result($insurance_qry);
	foreach($insurance_info as $insurance){					
		$insurance_id       = $insurance->insurance_id;
		$cust_id      		= $insurance->cust_id;
		$ins_type      		= $insurance->ins_type;
		$ins_general_type   = $insurance->ins_general_type;
		$ins_proposer      	= $insurance->ins_proposer;
		$ins_insured      	= $insurance->ins_insured;
		$ins_life_assured   = $insurance->ins_life_assured;
		$ins_company      	= $insurance->ins_company;
		$ins_plan      		= $insurance->ins_plan;
		$ins_sum_assured    = $insurance->ins_sum_assured;
		//$ins_start_date   = date('d-M-Y',strtotime($insurance->ins_start_date));
		$ins_start_date    	= new DateTime($insurance->ins_start_date);
		$ins_start_date     = $ins_start_date->format("d-M-Y");
		//$ins_issued_date  = date('d-M-Y',strtotime($insurance->ins_issued_date));
		$ins_issued_date    = new DateTime($insurance->ins_issued_date);
		$ins_issued_date    = $ins_issued_date->format("d-M-Y");
		$ins_term      		= $insurance->ins_term;
		$ins_ppt      		= $insurance->ins_ppt;
		$ins_premium      	= $insurance->ins_premium;
		$ins_frq      		= $insurance->ins_frq;
		$ins_rider      	= $insurance->ins_rider;
		$ins_rider_amt      = $insurance->ins_rider_amt;		
		//$ins_due_date     = date('d-M-Y',strtotime($insurance->ins_due_date));
		$ins_due_date       = new DateTime($insurance->ins_due_date);
		$ins_due_date       = $ins_due_date->format("d-M-Y");
		$pensioner          = $insurance->pensioner;		
		$vesting_date       = new DateTime($insurance->vesting_date);
		$vesting_date       = $vesting_date->format("d-M-Y");
		$pen_frq            = $insurance->pen_frq;
		$pen_amt            = $insurance->pen_amt;
		$pen_ror            = $insurance->pen_ror;
		$vesting_corpus     = $insurance->vesting_corpus;
		$one3rd_corpus      = $insurance->one3rd_corpus;
		$pen_payout         = $insurance->pen_payout;
		$pen_ropen          = $insurance->pen_ropen;
		$pension_amount     = $insurance->pension_amount;
	}
	echo json_encode(array("insurance_id" =>$insurance_id ,"ins_type" =>$ins_type, "ins_general_type" =>$ins_general_type, "ins_proposer" =>$ins_proposer, "ins_insured" =>$ins_insured, "ins_life_assured" =>$ins_life_assured, "ins_company" =>$ins_company, "ins_plan" =>$ins_plan, "ins_sum_assured" =>$ins_sum_assured, "ins_start_date" =>$ins_start_date, "ins_issued_date" =>$ins_issued_date, "ins_term" =>$ins_term, "ins_ppt" =>$ins_ppt, "ins_premium" =>$ins_premium, "ins_frq" =>$ins_frq, "ins_rider" =>$ins_rider, "ins_rider_amt" =>$ins_rider_amt, "ins_due_date" =>$ins_due_date, "pensioner" =>$pensioner, "vesting_date" =>$vesting_date, "pen_frq" =>$pen_frq, "pen_amt" =>$pen_amt, "pen_ror" =>$pen_ror, "vesting_corpus" =>$vesting_corpus, "one3rd_corpus" =>$one3rd_corpus, "pen_payout" =>$pen_payout, "pen_ropen" =>$pen_ropen, "pension_amount" =>$pension_amount));
}else
/**** REMOVE INSURANCE ****/
if($frm === "remove_insurance"){
	$cust_id   = $libObject->cust_id;	
	$insurance_id = "";
	if(isset($_POST['send_id'])){
		$insurance_id = $_POST['send_id'];
	}
	$dbObject->runQuery("UPDATE lp_cust_insurance SET status = '0' WHERE insurance_id = '$insurance_id' and cust_id = '$cust_id'");
	$msg = "Insurance information removed successfully";
	echo $libObject->get_insurance_content($msg);
}else
/**** SAVE MUTUAL FUND ****/
if($frm === "save_mf"){
	$cust_id   = $libObject->cust_id;	
	$fdata = "";
	if(isset($_POST['fdata'])){
		$fdata = $_POST['fdata'];
		$fdata = json_decode($fdata);
	}
	
	$qry_key     = "cust_id,";
	$qry_value   = "'$cust_id',";
	$exist_query = "";
	$upd_query   = "";
	foreach($fdata as $form_data){
		$name  = $real_db->real_escape_string($form_data->name);
		$value = $real_db->real_escape_string($form_data->value);		
		if($name === "mf_live_sip"){
			$mf_live_sip = $value;
		}
		
		if($name === "mf_end_date"){
			//$value = date('Y-m-d',strtotime($value));
			$value    = new DateTime($value);
			$value    = $value->format("Y-m-d");
		}
		
		if($value){
			$qry_key     .= "$name,";
			$qry_value   .= "'$value',";
			$upd_query   .= "$name = '$value',";
		}
		if($name === "mf_id"){
			$mf_id = $value;
		}else{
			$exist_query .= " $name = '$value' and";
		}
	}
	$mf_yearly  = $mf_live_sip * 12;
	$qry_key   .= "mf_yearly,";
	$qry_value .= "$mf_yearly,";
	$upd_query .= "mf_yearly = '$mf_yearly',";
	
	$created_on = date("Y-m-d h:i:s");
	$qry_key   .= "created_on,";
	$qry_value .= "'$created_on',";	
	$upd_query .= "updated_on = '$created_on',";	
	$qry_key    = rtrim($qry_key,',');
	$qry_value  = rtrim($qry_value,',');
	$upd_query  = rtrim($upd_query,',');
	
	if((int)$mf_id !== 0){		
		$update_query = "UPDATE lp_cust_mf SET $upd_query WHERE mf_id = '$mf_id' and cust_id = '$cust_id'";
		$dbObject->runQuery($update_query);
		$msg = "Mutual fund information updated successfully";
	}else{
		$isExist_qry   = $dbObject->runQuery("SELECT * FROM lp_cust_mf WHERE $exist_query cust_id = '$cust_id' and status= '1'");
		$loan_count = $dbObject->num_rows($isExist_qry);	
		if((int)$loan_count  === 0){
			$query = "insert into lp_cust_mf ($qry_key) values ($qry_value)";
			if($dbObject->runQuery($query)){
				$msg = "Mutual fund information added successfully";
			}
		}else{
			$msg = "Mutual Fund already in list";
		}
	}
	echo $libObject->get_mf_content($msg);
}else
/**** EDIT MUTUAL FUND ****/
if($frm === "edit_mf"){
	$cust_id   = $libObject->cust_id;	
	$mf_id = "";
	if(isset($_POST['send_id'])){
		$mf_id = $_POST['send_id'];
	}					
	$mf_qry  = $dbObject->runQuery("SELECT * FROM lp_cust_mf WHERE mf_id = '$mf_id' and cust_id = '$cust_id' ");
	$mf_info = $dbObject->result($mf_qry);
	foreach($mf_info as $mf){					
		$mf_id             = $mf->mf_id;
		$cust_id      	   = $mf->cust_id;
		$mf_investor       = $mf->mf_investor;
		$mf_amc      	   = $mf->mf_amc;
		$mf_scheme         = $mf->mf_scheme;
		$mf_fund_class     = $mf->mf_fund_class;
		$mf_fund_type      = $mf->mf_fund_type;
		$mf_inv_type       = $mf->mf_inv_type;
		$mf_present_val    = $mf->mf_present_val;
		$mf_live_sip       = $mf->mf_live_sip;
		//$mf_end_date       = date('d-M-Y',strtotime($mf->mf_end_date));
		$mf_end_date       = new DateTime($mf->mf_end_date);
		$mf_end_date       = $mf_end_date->format("d-M-Y");
	}
	echo json_encode(array("mf_id" =>$mf_id ,"mf_investor" =>$mf_investor, "mf_amc" =>$mf_amc, "mf_scheme" =>$mf_scheme, "mf_fund_class" =>$mf_fund_class, "mf_fund_type" =>$mf_fund_type, "mf_inv_type" =>$mf_inv_type, "mf_present_val" =>$mf_present_val, "mf_live_sip" =>$mf_live_sip, "mf_end_date" =>$mf_end_date));
}else
/**** REMOVE MUTUAL FUND ****/
if($frm === "remove_mf"){
	$cust_id   = $libObject->cust_id;	
	$mf_id = "";
	if(isset($_POST['send_id'])){
		$mf_id = $_POST['send_id'];
	}
	$dbObject->runQuery("UPDATE lp_cust_mf SET status = '0' WHERE mf_id = '$mf_id' and cust_id = '$cust_id'");
	$msg = "Mutual Fund information removed successfully";
	echo $libObject->get_mf_content($msg);
}else
/**** SAVE GOVERNMENT SCHEME ****/
if($frm === "save_gov"){
	$cust_id   = $libObject->cust_id;	
	$fdata = "";
	if(isset($_POST['fdata'])){
		$fdata = $_POST['fdata'];
		$fdata = json_decode($fdata);
	}
	
	$qry_key     = "cust_id,";
	$qry_value   = "'$cust_id',";
	$exist_query = "";
	$upd_query   = "";
	foreach($fdata as $form_data){
		$name  = $real_db->real_escape_string($form_data->name);
		$value = $real_db->real_escape_string($form_data->value);		
		
		if($name === "gov_start_date"){
			//$value = date('Y-m-d',strtotime($value));
			$value    = new DateTime($value);
			$value    = $value->format("Y-m-d");
		}
		if($name === "gov_maturity_date"){
			//$value = date('Y-m-d',strtotime($value));
			$value    = new DateTime($value);
			$value    = $value->format("Y-m-d");
		}
		if($name === "gov_amount"){
			$gov_amount = $value;
		}		
		if($name === "gov_type"){
			$gov_frq_array  = array(1=>1,2=>12,3=>4,4=>2,5=>1);
			$multi_value    = $gov_frq_array[$value];
		}
		
		if($name === "gov_id"){
			$gov_id = $value;
		}else{
			$exist_query .= " $name = '$value' and";
		}
		if($value){
			$qry_key     .= "$name,";
			$qry_value   .= "'$value',";
			$upd_query   .= "$name = '$value',";
		}
	}
	$gov_yearly  = $gov_amount * $multi_value;
	$qry_key    .= "gov_yearly,";
	$qry_value  .= "$gov_yearly,";
	$upd_query  .= "gov_yearly = '$gov_yearly',";
	
	$created_on = date("Y-m-d h:i:s");
	$qry_key   .= "created_on,";
	$qry_value .= "'$created_on',";	
	$upd_query .= "updated_on = '$created_on',";	
	$qry_key    = rtrim($qry_key,',');
	$qry_value  = rtrim($qry_value,',');
	$upd_query  = rtrim($upd_query,',');
	
	if((int)$gov_id !== 0){		
		$update_query = "UPDATE lp_cust_gov SET $upd_query WHERE gov_id = '$gov_id' and cust_id = '$cust_id'";
		$dbObject->runQuery($update_query);
		$msg = "Government scheme information updated successfully";
	}else{
		$isExist_qry   = $dbObject->runQuery("SELECT * FROM lp_cust_gov WHERE $exist_query cust_id = '$cust_id' and status= '1'");
		$loan_count = $dbObject->num_rows($isExist_qry);	
		if((int)$loan_count  === 0){
			$query = "insert into lp_cust_gov ($qry_key) values ($qry_value)";
			if($dbObject->runQuery($query)){
				$msg = "Government scheme information added successfully";
			}
		}else{
			$msg = "Government Scheme already in list";
		}
	}
	echo $libObject->get_gov_content($msg);
}else
/**** EDIT GOVERNMENT SCHEME ****/
if($frm === "edit_gov"){
	$cust_id   = $libObject->cust_id;	
	$gov_id = "";
	if(isset($_POST['send_id'])){
		$gov_id = $_POST['send_id'];
	}					
	$gov_qry  = $dbObject->runQuery("SELECT * FROM lp_cust_gov WHERE gov_id = '$gov_id' and cust_id = '$cust_id' ");
	$gov_info = $dbObject->result($gov_qry);
	foreach($gov_info as $gov){					
		$gov_id             = $gov->gov_id;
		$cust_id      	    = $gov->cust_id;
		$gov_holder         = $gov->gov_holder;
		$gov_scheme         = $gov->gov_scheme;
		$gov_type           = $gov->gov_type;
		$gov_amount         = $gov->gov_amount;
		//$gov_start_date     = date('d-M-Y',strtotime($gov->gov_start_date));
		$gov_start_date     = new DateTime($gov->gov_start_date);
		$gov_start_date     = $gov_start_date->format("d-M-Y");
		//$gov_maturity_date  = date('d-M-Y',strtotime($gov->gov_maturity_date));
		$gov_maturity_date  = new DateTime($gov->gov_maturity_date);
		$gov_maturity_date  = $gov_maturity_date->format("d-M-Y");
		$gov_ror            = $gov->gov_ror;
		$gov_maturity_value = $gov->gov_maturity_value;
	}
	echo json_encode(array("gov_id" =>$gov_id ,"gov_holder" =>$gov_holder, "gov_scheme" =>$gov_scheme, "gov_type" =>$gov_type, "gov_amount" =>$gov_amount, "gov_start_date" =>$gov_start_date, "gov_maturity_date" =>$gov_maturity_date, "gov_ror" =>$gov_ror, "gov_maturity_value" =>$gov_maturity_value));
}else
/**** REMOVE GOVERNMENT SCHEME ****/
if($frm === "remove_gov"){
	$cust_id   = $libObject->cust_id;
	$gov_id = "";
	if(isset($_POST['send_id'])){
		$gov_id = $_POST['send_id'];
	}
	$dbObject->runQuery("UPDATE lp_cust_gov SET status = '0' WHERE gov_id = '$gov_id' and cust_id = '$cust_id'");
	$msg = "Government Scheme information removed successfully";
	echo $libObject->get_gov_content($msg);
}else
/**** SAVE STOCK & BULLION ****/
if($frm === "save_stock"){
	$cust_id   = $libObject->cust_id;	
	$fdata = "";
	if(isset($_POST['fdata'])){
		$fdata = $_POST['fdata'];
		$fdata = json_decode($fdata);
	}
	
	$qry_key     = "cust_id,";
	$qry_value   = "'$cust_id',";
	$exist_query = "";
	$upd_query   = "";
	foreach($fdata as $form_data){
		$name  = $real_db->real_escape_string($form_data->name);
		$value = $real_db->real_escape_string($form_data->value);
		
		if($name === "gov_start_date"){
			//$value = date('Y-m-d',strtotime($value));
			$value    = new DateTime($value);
			$value    = $value->format("Y-m-d");
		}
		if($name === "gov_maturity_date"){
			//$value = date('Y-m-d',strtotime($value));
			$value    = new DateTime($value);
			$value    = $value->format("Y-m-d");
		}
		if($name === "stock_type"){
			$stock_type = $value;
		}
		if($name === "stock_current_value"){
			$stock_current_value = $value;
		}		
		if($name === "stock_paytype"){
			$stock_frq_array  = array(1=>1,2=>12,3=>4,4=>2,5=>1);
			$multi_value    = $stock_frq_array[$value];
		}
		
		if($name === "stock_id"){
			$stock_id = $value;
		}else{
			$exist_query .= " $name = '$value' and";
		}
		if($value){
			$qry_key     .= "$name,";
			$qry_value   .= "'$value',";
			$upd_query   .= "$name = '$value',";
		}
	}
	if((int)$stock_type === 2){
		$multi_value = 1;
	}
	
	$stock_yearly  = $stock_current_value * $multi_value;
	$qry_key      .= "stock_yearly,";
	$qry_value    .= "$stock_yearly,";
	$upd_query    .= "stock_yearly = '$stock_yearly',";
	
	$created_on = date("Y-m-d h:i:s");
	$qry_key   .= "created_on,";
	$qry_value .= "'$created_on',";	
	$upd_query .= "updated_on = '$created_on',";	
	$qry_key    = rtrim($qry_key,',');
	$qry_value  = rtrim($qry_value,',');
	$upd_query  = rtrim($upd_query,',');
	
	if((int)$stock_id !== 0){		
		$update_query = "UPDATE lp_cust_stock SET $upd_query WHERE stock_id = '$stock_id' and cust_id = '$cust_id'";
		$dbObject->runQuery($update_query);
		$msg = "Stock & Bullion  information updated successfully";
	}else{
		$isExist_qry   = $dbObject->runQuery("SELECT * FROM lp_cust_stock WHERE $exist_query cust_id = '$cust_id' and status= '1'");
		$loan_count = $dbObject->num_rows($isExist_qry);	
		if((int)$loan_count  === 0){
			$query = "insert into lp_cust_stock ($qry_key) values ($qry_value)";
			if($dbObject->runQuery($query)){
				$msg = "Stock & Bullion information added successfully";
			}
		}else{
			$msg = "Stock & Bullion already in list";
		}
	}
	echo $libObject->get_stock_content($msg);
}else
/**** EDIT STOCK & BULLION ****/
if($frm === "edit_stock"){
	$cust_id   = $libObject->cust_id;	
	$stock_id = "";
	if(isset($_POST['send_id'])){
		$stock_id = $_POST['send_id'];
	}					
	$stock_qry  = $dbObject->runQuery("SELECT * FROM lp_cust_stock WHERE stock_id = '$stock_id' and cust_id = '$cust_id' ");
	$stock_info = $dbObject->result($stock_qry);
	foreach($stock_info as $stock){					
		$stock_id             = $stock->stock_id;
		$cust_id      	      = $stock->cust_id;
		$stock_type           = $stock->stock_type;
		$stock_investor       = $stock->stock_investor;
		$bullion_type         = $stock->bullion_type;
		$stock_inflow_value   = $stock->stock_inflow_value;
		$stock_current_value  = $stock->stock_current_value;
		$stock_expected_value = $stock->stock_expected_value;
		$stock_paytype        = $stock->stock_paytype;
	}
	echo json_encode(array("stock_id" =>$stock_id ,"stock_type" =>$stock_type, "stock_investor" =>$stock_investor, "bullion_type" =>$bullion_type, "stock_inflow_value" =>$stock_inflow_value, "stock_current_value" =>$stock_current_value, "stock_expected_value" =>$stock_expected_value, "stock_paytype" =>$stock_paytype));
}else
/**** REMOVE STOCK & BULLION ****/
if($frm === "remove_stock"){
	$cust_id   = $libObject->cust_id;
	$stock_id = "";
	if(isset($_POST['send_id'])){
		$stock_id = $_POST['send_id'];
	}
	$dbObject->runQuery("UPDATE lp_cust_stock SET status = '0' WHERE stock_id = '$stock_id' and cust_id = '$cust_id'");
	$msg = "Stock & Bullion information removed successfully";
	echo $libObject->get_stock_content($msg);
}else
/**** SAVE OTHERS ****/
if($frm === "save_others"){
	$cust_id   = $libObject->cust_id;	
	$fdata = "";
	if(isset($_POST['fdata'])){
		$fdata = $_POST['fdata'];
		$fdata = json_decode($fdata);
	}
	
	$qry_key     = "cust_id,";
	$qry_value   = "'$cust_id',";
	$exist_query = "";
	$upd_query   = "";
	foreach($fdata as $form_data){
		$name  = $real_db->real_escape_string($form_data->name);
		$value = $real_db->real_escape_string($form_data->value);
		
		if($name === "others_startdate"){
			//$value = date('Y-m-d',strtotime($value));
			$value    = new DateTime($value);
			$value    = $value->format("Y-m-d");
		}
		if($name === "others_maturity_date"){
			//$value = date('Y-m-d',strtotime($value));
			$value    = new DateTime($value);
			$value    = $value->format("Y-m-d");
		}
		
		if($name === "others_amt"){
			$others_amt = $value;
		}		
		if($name === "others_type"){
			$other_frq_array  = array(1=>1,2=>12,3=>4,4=>2,5=>1);
			$multi_value    = $other_frq_array[$value];
		}
		
		if($name === "others_id"){
			$others_id = $value;
		}else{
			$exist_query .= " $name = '$value' and";
		}
		if($value){
			$qry_key     .= "$name,";
			$qry_value   .= "'$value',";
			$upd_query   .= "$name = '$value',";
		}
	}
	$other_yearly  = $others_amt * $multi_value;
	$qry_key    .= "other_yearly,";
	$qry_value  .= "$other_yearly,";
	$upd_query  .= "other_yearly = '$other_yearly',";
	
	$created_on = date("Y-m-d h:i:s");
	$qry_key   .= "created_on,";
	$qry_value .= "'$created_on',";	
	$upd_query .= "updated_on = '$created_on',";	
	$qry_key    = rtrim($qry_key,',');
	$qry_value  = rtrim($qry_value,',');
	$upd_query  = rtrim($upd_query,',');
	
	if((int)$others_id !== 0){		
		$update_query = "UPDATE lp_cust_others SET $upd_query WHERE others_id = '$others_id' and cust_id = '$cust_id'";
		$dbObject->runQuery($update_query);
		$msg = "Others  information updated successfully";
	}else{
		$isExist_qry   = $dbObject->runQuery("SELECT * FROM lp_cust_others WHERE $exist_query cust_id = '$cust_id' and status= '1'");
		$loan_count = $dbObject->num_rows($isExist_qry);	
		if((int)$loan_count  === 0){
			$query = "insert into lp_cust_others ($qry_key) values ($qry_value)";
			if($dbObject->runQuery($query)){
				$msg = "Others information added successfully";
			}
		}else{
			$msg = "Others already in list";
		}
	}
	echo $libObject->get_others_content($msg);
}else
/**** EDIT OTHERS ****/
if($frm === "edit_others"){
	$cust_id   = $libObject->cust_id;	
	$others_id = "";
	if(isset($_POST['send_id'])){
		$others_id = $_POST['send_id'];
	}					
	$others_qry  = $dbObject->runQuery("SELECT * FROM lp_cust_others WHERE others_id = '$others_id' and cust_id = '$cust_id' ");
	$others_info = $dbObject->result($others_qry);
	foreach($others_info as $others){					
		$others_id             = $others->others_id;
		$cust_id      	       = $others->cust_id;
		$others_investor       = $others->others_investor;
		$others_descript       = $others->others_descript;
		$others_amt      	   = $others->others_amt;
		$others_type      	   = $others->others_type;
		//$others_startdate      = date('d-M-Y',strtotime($others->others_startdate));
		$others_startdate      = new DateTime($others->others_startdate);
		$others_startdate      = $others_startdate->format("d-M-Y");
		$others_tenure         = $others->others_tenure;
		$others_tenure_type    = $others->others_tenure_type;
		$others_expected_val   = $others->others_expected_val;
		$others_maturity_date  = $others->others_maturity_date;
		$others_maturity_val   = $others->others_maturity_val;
	}
	echo json_encode(array("others_id" =>$others_id ,"others_investor" =>$others_investor, "others_descript" =>$others_descript, "others_amt" =>$others_amt, "others_type" =>$others_type, "others_startdate" =>$others_startdate, "others_tenure" =>$others_tenure, "others_tenure_type" =>$others_tenure_type, "others_expected_val" =>$others_expected_val, "others_maturity_date" =>$others_maturity_date, "others_maturity_val" =>$others_maturity_val));
}else
/**** REMOVE OTHERS ****/
if($frm === "remove_others"){
	$cust_id   = $libObject->cust_id;
	$others_id = "";
	if(isset($_POST['send_id'])){
		$others_id = $_POST['send_id'];
	}
	$dbObject->runQuery("UPDATE lp_cust_others SET status = '0' WHERE others_id = '$others_id' and cust_id = '$cust_id'");
	$msg = "Others information removed successfully";
	echo $libObject->get_others_content($msg);
}else
/**** INVESTMENTS LIST OTHERS ****/
if($frm === "investments_list"){
	$cust_id   = $libObject->cust_id;
	$bank_scheme_info     = array('1'=>"Bank Fixed Deposit",'2'=>"Company Deposit",'3'=>"Bank Recurring Deposit",'4'=>"Bonds",'5'=>"Other Deposits");
	$bank_list_info       = $libObject->get_bank_list();
	$bank_info            = $dbObject->result($bank_list_info);
	
	$insurance_list_info  = $libObject->get_insurance_list();
	$insurance_info       = $dbObject->result($insurance_list_info);
	
	$mf_list_info         = $libObject->get_mf_list();
	$mf_info              = $dbObject->result($mf_list_info);
	
	$gov_list_info        = $libObject->get_gov_list();
	$gov_info             = $dbObject->result($gov_list_info);
	
	$others_list_info     = $libObject->get_others_list();
	$others_info          = $dbObject->result($others_list_info);
	
	$goal_map_list = "<option value='' disabled>-- Map Investments --</option>";
	foreach($bank_info as $bank){
		$bank_id          = $bank->bank_id;
		$bank_scheme      = $bank->bank_scheme;
		$bank_descript    = $bank->bank_descript;
		$bank_amt         = $bank->bank_amt;
		$bank_scheme_name = $bank_scheme_info[$bank_scheme];
		$list_id = "BK_$bank_id";
		$goal_map_list .=  "<option value='$list_id'>$bank_scheme_name - $bank_amt</option>";
	}
	
	foreach($insurance_info as $insurance){				
		$insurance_id          = $insurance->insurance_id;
		$ins_type              = $insurance->ins_type;
		$insurance_type_name   = $insurance->insurance_type_name;
		$ins_sum_assured       = $insurance->ins_sum_assured;
		$list_id = "INS_$insurance_id";
		if(($ins_type === "2") || ($ins_type === "3")){
			$goal_map_list .=  "<option value='$list_id'>$insurance_type_name - $ins_sum_assured</option>";
		}
	}

	foreach($mf_info as $mf){				
		$mf_id       = $mf->mf_id;
		$amc_name    = $mf->amc_name;
		$mf_live_sip = $mf->mf_live_sip;
		$list_id = "MF_$mf_id";
		$goal_map_list .=  "<option value='$list_id'>$amc_name - $mf_live_sip</option>";
	}
	
	foreach($gov_info as $gov){
		$gov_id          = $gov->gov_id;
		$gov_scheme_name = $gov->gov_scheme_name;
		$gov_amount      = $gov->gov_amount;
		$list_id = "GOV_$gov_id";
		$goal_map_list .=  "<option value='$list_id'>$gov_scheme_name - $gov_amount</option>";
	}
	foreach($others_info as $others){
		$others_id        = $others->others_id;
		$others_descript  = $others->others_descript;
		$others_amt       = $others->others_amt;
		$list_id = "OTH_$others_id";
		$goal_map_list .=  "<option value='$list_id'>$others_descript - $others_amt</option>";
	}
	echo json_encode(array('goal_map' =>"$goal_map_list"));
}else
/**** IT CHECK TAB CAN PROCEED TO GOAL ****/
if($frm === "investments_btn"){	
	$bank_list_info       = $libObject->get_bank_list();
	$bank_list_rows       = $dbObject->num_rows($bank_list_info);
	$insurance_list_info  = $libObject->get_insurance_list();
	$insurance_list_rows  = $dbObject->num_rows($insurance_list_info);
	$mf_list_info         = $libObject->get_mf_list();
	$mf_list_rows         = $dbObject->num_rows($mf_list_info);
	$gov_list_info        = $libObject->get_gov_list();
	$gov_list_rows        = $dbObject->num_rows($gov_list_info);
	$stock_list_info      = $libObject->get_stock_list();
	$stock_list_rows      = $dbObject->num_rows($stock_list_info);
	$others_list_info     = $libObject->get_others_list();
	$others_list_rows     = $dbObject->num_rows($others_list_info);
	
	if(((int)$bank_list_rows === 0) && ((int)$insurance_list_rows === 0) && ((int)$mf_list_rows === 0) && ((int)$gov_list_rows === 0) && ((int)$stock_list_rows === 0) && ((int)$others_list_rows === 0)){
		//echo json_encode(array('sts' => FALSE, 'info' =>"Please add your Investments"));
		echo json_encode(array('sts' => true, 'info' =>"Let's Goto Long Term Goals"));
	}else{
		echo json_encode(array('sts' => true, 'info' =>"Let's Goto Long Term Goals"));
	}
}else
/**** SAVE GOAL ****/
if($frm === "save_goal"){
	$cust_id   = $libObject->cust_id;
	$fdata = "";
	if(isset($_POST['fdata'])){
		$fdata = $_POST['fdata'];
		$fdata = json_decode($fdata);
	}
	$newfdata = array();
	foreach ($fdata as $option) {
		$name  = $option->name;
		$value = $option->value;
		if (array_key_exists($name,$newfdata)){			
			$prv_val = $newfdata[$name];
			$newfdata[$name] = "$prv_val,$value";
		}else{
			$newfdata[$name] = $value;
		}
	}
	
	$qry_key     = "cust_id,";
	$qry_value   = "'$cust_id',";
	$exist_query = "";
	$upd_query   = "";
	$goal_amount = 0;
	$goal_date   = "";
	foreach ($newfdata as $key => $value){
		$name  = $real_db->real_escape_string($key);
		$value = $real_db->real_escape_string($value);
		
		if($name === "goal_date"){			
			//$value = date('Y-m-d',strtotime($value));
			$value    = new DateTime($value);
			$value    = $value->format("Y-m-d");
			$goal_date = $value;
		}		
		if($name === "goal_amount"){
			$goal_amount = $value;
		}
		if($name === "goal_id"){
			$goal_id = $value;
		}else{
			$exist_query .= " $name = '$value' and";
		}
		if($value){
			$qry_key     .= "$name,";
			$qry_value   .= "'$value',";
			$upd_query   .= "$name = '$value',";
		}
	}
	
	//INFLATION CALCULATION - START
	$inflation       = 8;
	$year            = lp_calculation::total_year($goal_date, date("Y-m-d"));	
	$inflation_info  = lp_calculation::compound_interest($goal_amount,$inflation,$year);
	$inflation_info  = json_decode($inflation_info); 
	$inflation_amt   = $inflation_info->future_value;
	//INFLATION CALCULATION - END
	
	$created_on = date("Y-m-d h:i:s");
	$qry_key   .= "created_on,";
	$qry_value .= "'$created_on',";	
	$upd_query .= "inflation = '$inflation',inflation_amt= '$inflation_amt',updated_on = '$created_on'";	
	$qry_key    = rtrim($qry_key,',');
	$qry_value  = rtrim($qry_value,',');
	$upd_query  = rtrim($upd_query,',');
	
	
	
	if((int)$goal_id !== 0){
		$update_query = "UPDATE lp_cust_goal SET $upd_query WHERE goal_id = '$goal_id' and cust_id = '$cust_id'";
		$dbObject->runQuery($update_query);
		$msg = "Goal information updated successfully";
	}else{
		$isExist_qry   = $dbObject->runQuery("SELECT * FROM lp_cust_goal WHERE $exist_query cust_id = '$cust_id' and status= '1'");
		$goal_count = $dbObject->num_rows($isExist_qry);	
		if((int)$goal_count  === 0){
			$query = "insert into lp_cust_goal ($qry_key,inflation,inflation_amt) values ($qry_value,'$inflation','$inflation_amt')";
			if($dbObject->runQuery($query)){
				$msg = "Goal information added successfully";
			}
		}else{
			$msg = "Goal already in list";
		}
	}
	echo $libObject->get_goal_inner_content($msg);
}else
/**** EDIT GOAL ****/
if($frm === "edit_goal"){
	$cust_id   = $libObject->cust_id;	
	$goal_id = "";
	if(isset($_POST['send_id'])){
		$goal_id = $_POST['send_id'];
	}					
	$goal_qry  = $dbObject->runQuery("SELECT * FROM lp_cust_goal WHERE goal_id = '$goal_id' and cust_id = '$cust_id' ");
	$goal_info = $dbObject->result($goal_qry);
	foreach($goal_info as $goal){		
		$goal_id        = $goal->goal_id;
		$cust_id        = $goal->cust_id;
		$goal_family      = $goal->goal_family;
		$goal_name      = $goal->goal_name;
		//$goal_date      = date('d-M-Y',strtotime($goal->goal_date));
		$goal_date      = new DateTime($goal->goal_date);
		$goal_date      = $goal_date->format("d-M-Y");
		$goal_amount    = $goal->goal_amount;
		$goal_amount    = $goal->goal_amount;
		$goal_map       = $goal->goal_map;
		$goal_for       = $goal->goal_for;
	}
	echo json_encode(array("goal_id" =>$goal_id,"goal_family" =>$goal_family,"goal_name" =>$goal_name,"goal_date" =>$goal_date,"goal_amount" =>$goal_amount,"goal_map" =>$goal_map,"goal_for" =>$goal_for));
}else
/**** REMOVE GOAL ****/
if($frm === "remove_goal"){
	$cust_id   = $libObject->cust_id;
	$goal_id = "";
	if(isset($_POST['send_id'])){
		$goal_id = $_POST['send_id'];
	}	
	$dbObject->runQuery("UPDATE lp_cust_goal SET status = '0' WHERE goal_id = '$goal_id' and cust_id = '$cust_id'");
	$msg = "Goal information removed successfully";
	echo $libObject->get_goal_inner_content($msg);
}else
/**** CHECK GOAL MAPPED ****/
if($frm === "check_goal_map"){
	$cust_id   = $libObject->cust_id;
	$goal_id = "";
	if(isset($_POST['goal_id'])){
		$goal_id = $_POST['goal_id'];
	}
	$goal_map = "";
	if(isset($_POST['goal_map'])){
		$goal_map = $_POST['goal_map'];
	}	
	$goal_date = "";
	if(isset($_POST['goal_date'])){
		$goal_date = $_POST['goal_date'];
	}
	$goal_qry  = $dbObject->runQuery("SELECT * FROM lp_cust_goal where find_in_set ('$goal_map',goal_map) and cust_id = '13' and status = '1' and goal_id != '$goal_id'");
	$goal_count = $dbObject->num_rows($goal_qry);
	if((int)$goal_count === 0){
		echo json_encode(array('sts' => true,'info' =>"Not Mapped with any goal"));
	}else{
		echo json_encode(array('sts' => false,'info' =>"Already mapped with another goal"));
	}
}else
/**** PROVIDE CONTENT FOR ALL FAMILY RELATED DROP DOWN ****/
if($frm === "family_list"){	
	$salaried_info = $libObject->get_salaried_list();
	$salaried_list = "<option value='' disabled selected>-- Salaried --</option>"; //income_family
	foreach($salaried_info as $salaried){
		$family_id      = $salaried->family_id;
		$family_name    = $salaried->family_name;
		$salaried_list .=  "<option value='$family_id'>$family_name</option>";
	}
	
	$family_info       = $libObject->get_family_list();
	$asset_family_list = "<option value='' disabled selected>-- Owner --</option>"; //asset_family	
	$bank_family_list  = "<option value='' disabled selected>-- Depositor --</option>"; //bank_family	
	$proposer_list     = "<option value='' disabled selected>-- Proposer --</option>";//ins_proposer
	$insured_list      = "<option value='' disabled selected>-- Insured --</option>"; //ins_insured
	$life_assured_list = "<option value='' disabled selected>-- Life Assured --</option>";//ins_life_assured	
	$investor_list     = "<option value='' disabled selected>-- Investor --</option>"; //mf_investor,stock_investor,others_investor	
	$holder_list       = "<option value='' disabled selected>-- Holder --</option>"; //gov_holder
	$goal_list         = "<option value='' disabled selected>-- Family --</option>"; //goal_family
	$exp_family        = "<option value='' disabled selected>-- Family --</option>"; //exp_family
	$exp_family       .= "<option value='' disabled selected>All</option>"; //exp_family
	foreach($family_info as $family){
		$family_id          = $family->family_id;
		$family_name        = $family->family_name;
		$asset_family_list .=  "<option value='$family_id'>$family_name</option>";		
		$bank_family_list  .=  "<option value='$family_id'>$family_name</option>";		
		$proposer_list     .=  "<option value='$family_id'>$family_name</option>";
		$insured_list      .=  "<option value='$family_id'>$family_name</option>";		
		$life_assured_list .=  "<option value='$family_id'>$family_name</option>";		
		$investor_list     .=  "<option value='$family_id'>$family_name</option>";
		$holder_list       .=  "<option value='$family_id'>$family_name</option>";
		$goal_list         .=  "<option value='$family_id'>$family_name</option>";
		$exp_family        .=  "<option value='$family_id'>$family_name</option>";
	}
	echo json_encode(array('income_family' =>$salaried_list,'asset_family' =>$asset_family_list,'bank_family' =>$bank_family_list,'ins_proposer' =>$proposer_list,'ins_insured' =>$insured_list,'ins_life_assured' =>$life_assured_list,'mf_investor' =>$investor_list,'stock_investor' =>$investor_list,'others_investor' =>$investor_list,'gov_holder' =>$holder_list,'goal_family' =>$goal_list,'exp_family' =>$exp_family));
}else
/**** PROVIDE CONTENT FOR EXPENSE SUB CATEGORY DROP DOWN ****/
if($frm === "expense_subcat"){
	$exp_cat = "";
	if(isset($_POST['exp_cat'])){
		$exp_cat = $_POST['exp_cat'];
	}
	$exp_info = $libObject->get_expense($exp_cat);
	$expense_related = $exp_info[0]->expense_related;
	$related_to = "";
	if((int)$expense_related === 1){
		$related_to = "Sub Category";
		$subcat_info = $libObject->get_expense_sub($exp_cat);
		$sub_list = "<option value='' disabled selected>-- Sub Category --</option>";
		foreach($subcat_info as $sub){
			$sub_id    = $sub->expense_sub_id;
			$sub_name  = $sub->expense_sub_name;
			$sub_list .=  "<option value='$sub_id'>$sub_name</option>";
		}
		echo json_encode(array('exp_sub_cat' =>$sub_list,'expense_related' =>$expense_related));
	}
	if((int)$expense_related === 2){
		$related_to = "Family";
		$family_info  = $libObject->get_family_list();
		$sub_list     = "<option value='' disabled selected>-- Family --</option>";
		$sub_list    .= "<option value='0'>All</option>";
		foreach($family_info as $family){
			$family_id    = $family->family_id;
			$family_name  = $family->family_name;
			$sub_list    .=  "<option value='$family_id'>$family_name</option>";
		}
		echo json_encode(array('exp_family' =>$sub_list,'expense_related' =>$expense_related));
	}	
}else
/**** PROVIDE CONTENT FOR INCOME OTHER FAMILY LIST DROP DOWN ****/
if($frm === "income_others"){	
	$income_type = "";
	if(isset($_POST['income_type'])){
		$income_type = $_POST['income_type'];
	}
	if($income_type === "1"){
		$salaried_info = $libObject->get_salaried_list();
		$sub_list = "<option value='' disabled selected>-- Salaried --</option>"; //income_family
		foreach($salaried_info as $salaried){
			$family_id      = $salaried->family_id;
			$family_name    = $salaried->family_name;
			$sub_list .=  "<option value='$family_id'>$family_name</option>";
		}
	}
	if($income_type === "2"){
		$family_info  = $libObject->get_family_list();
		$sub_list     = "<option value='' disabled selected>-- Family --</option>";
		foreach($family_info as $family){
			$family_id    = $family->family_id;
			$family_name  = $family->family_name;
			$sub_list    .=  "<option value='$family_id'>$family_name</option>";
		}
	}	
	echo json_encode(array('income_family' =>$sub_list));	
}else
/**** PROVIDE CONTENT FOR INVESTMENTS CHART INFORMATION ****/
if($frm === "investments_chart_info"){
	echo $libObject->investments_chart_info();
	//echo json_encode(array('chart_info' =>$chart_info));
}else
/**** PROVIDE CONTENT FOR INVESTMENTS PLAN DROP DOWN ****/
if($frm === "update_plan"){
	$ins_company = "";
	if(isset($_POST['ins_company'])){
		$ins_company = $_POST['ins_company'];
	}
	
	$plan_info           = $libObject->get_insurance_plan($ins_company);
	$insurance_plan_list = "<option value='' disabled selected>-- Plan --</option>";
	foreach($plan_info as $insurance_plan){
		$insurance_plan_id    = $insurance_plan->insurance_plan_id;
		$insurance_plan_name  = $insurance_plan->insurance_plan_name;
		$insurance_plan_list .=  "<option value='$insurance_plan_id'>$insurance_plan_name</option>";
	}
	echo json_encode(array('ins_plan' =>$insurance_plan_list));
}else
/**** PROVIDE CONTENT FOR MUTUAL FUND DROP DOWN ****/
if($frm === "update_fund_name"){
	$mf_amc = "";
	if(isset($_POST['mf_amc'])){
		$mf_amc = $_POST['mf_amc'];
	}
	
	$fund_name_info = $libObject->get_fund_name($mf_amc);
	$fund_name_list = "<option value='' disabled selected>-- Fund Name --</option>";
	foreach($fund_name_info as $fund_name){
		$fund_name_id    = $fund_name->fund_name_id;
		$fund_name       = $fund_name->fund_name;
		$fund_name_list .=  "<option value='$fund_name_id'>$fund_name</option>";
	}
	echo json_encode(array('mf_scheme' =>$fund_name_list));
}else
/**** RETIREMENT INFO ****/
if($frm === "retirement_info"){
	$goal_family = "";
	if(isset($_POST['goal_family'])){
		$goal_family = $_POST['goal_family'];
	}
	$family_info     = $libObject->get_family_id($goal_family);
	$family_relation = $family_info[0]->family_relation;
	$family_age      = $family_info[0]->family_age;
	$family_dob      = $family_info[0]->family_dob;
	if((int)$family_relation === 0){
		$now = new DateTime();
		$end = new DateTime($family_dob);
		$interval = $now->diff($end);
		$age =  $interval->format('%y years %m months and %d days');
	}else{
		$age = $family_age;
	}
	$goal_expence = $libObject->goal_get_expense();
	$exp_amt      = $goal_expence[0]->exp_amt;
	$retirement_info = " <table class='centered'>
								  <tr>
									<td style='border: 1px solid #CCCCCC;background-color:#f2f2f2;'>Age</td>
									<td style='border: 1px solid #CCCCCC;'>$age</td>
									<td style='border: 1px solid #CCCCCC;background-color:#f2f2f2;'>Monthly Expense</td>
									<td style='border: 1px solid #CCCCCC;'>$exp_amt</td>
								  </tr>
						  </table>";
	echo json_encode(array('retirement_info' =>$retirement_info));
}else
/**** CALCULATION LOAN INTEREST RATE ****/
if($frm === "cal_interest_rate"){
	$outstanding = "";
	if(isset($_POST['outstanding'])){
		$outstanding = $_POST['outstanding'];
	}
	$frq = "";
	if(isset($_POST['frq'])){
		$frq = $_POST['frq'];
	}
	$remaining = "";
	if(isset($_POST['remaining'])){
		$remaining = $_POST['remaining'];
	}
	$emi = "";
	if(isset($_POST['emi'])){
		$emi = $_POST['emi'];
	}
	$total_month = 0;
	$frq_array   = array("1"=>1,"2"=>1,"3"=>3,"4"=>6,"5"=>12);
	$total_month = $frq_array[$frq];	 
	$total_month = $total_month * $remaining;
	$rslt = lp_calculation::loan_interest($total_month,$emi,$outstanding);
	echo $rslt;
}else
/**** CALCULATION BANK MATURITY AMOUNT ****/
if($frm === "cal_bank_maturity"){
	$bank_amt = "";
	if(isset($_POST['bank_amt'])){
		$bank_amt = $_POST['bank_amt'];
	}
	$bank_startdate = "";
	if(isset($_POST['bank_startdate'])){
		$bank_startdate = $_POST['bank_startdate'];
	}
	$bank_tenure = "";
	if(isset($_POST['bank_tenure'])){
		$bank_tenure = $_POST['bank_tenure'];
	}
	$bank_tenure_type = "";
	if(isset($_POST['bank_tenure_type'])){
		$bank_tenure_type = $_POST['bank_tenure_type'];
	}
	$bank_ror = "";
	if(isset($_POST['bank_ror'])){
		$bank_ror = $_POST['bank_ror'];
	}
	$bank_maturity = "";
	if(isset($_POST['bank_maturity'])){
		$bank_maturity = $_POST['bank_maturity'];
	}
	$bank_scheme = "";
	if(isset($_POST['bank_scheme'])){
		$bank_scheme = $_POST['bank_scheme'];
	}
	$bank_type = "";
	if(isset($_POST['bank_type'])){
		$bank_type = $_POST['bank_type'];
	}
	$year_array  = array(1=>0,2=>12,3=>4,4=>2,5=>1);
	$compounding = $year_array[$bank_type];
	if((int)$bank_scheme === 1){
		$maturity_info = lp_calculation::maturity_date($bank_startdate,$bank_tenure,$bank_tenure_type);
		$maturity_info = json_decode($maturity_info); 
		$maturity_date = $maturity_info->maturity_date;	
		
		$years         = lp_calculation::days_difference($maturity_date, $bank_startdate);
		//echo "years :: $years\n";
		//$years = 1825;
		$amount_info   = lp_calculation::fd_maturity($bank_ror,$compounding,$years,$bank_amt);
		$amount_info   = json_decode($amount_info); 
		$maturity_amt  = $amount_info->fd_maturity_amount;
		echo json_encode(array('sts' => true,'maturity_amt' =>$maturity_amt,'maturity_date' =>$maturity_date));
	}else
	if((int)$bank_scheme === 3){
		$maturity_info = lp_calculation::maturity_date($bank_startdate,$bank_tenure,$bank_tenure_type);
		$maturity_info = json_decode($maturity_info); 
		$maturity_date = $maturity_info->maturity_date;	
		$months        = lp_calculation::total_month($bank_startdate,$maturity_date);		
		$amount_info   = lp_calculation::rd_maturity($bank_ror,$compounding,$months,$bank_amt);
		$amount_info   = json_decode($amount_info); 
		$maturity_amt  = $amount_info->maturity_amount;
		echo json_encode(array('sts' => true,'maturity_amt' =>$maturity_amt,'maturity_date' =>$maturity_date));
	}else{
		$rslt = lp_calculation::simple_interest($bank_startdate,$bank_maturity,$bank_tenure,$bank_tenure_type,$bank_ror,$bank_amt);
		echo $rslt;
	}
}else
/**** CALCULATION GOVERNMENT AMOUNT ****/
if($frm === "cal_gov_maturity"){
	$gov_amount = "";
	if(isset($_POST['gov_amount'])){
		$gov_amount = $_POST['gov_amount'];
	}
	$gov_start_date = "";
	if(isset($_POST['gov_start_date'])){
		$gov_start_date = $_POST['gov_start_date'];
	}
	$gov_maturity_date = "";
	if(isset($_POST['gov_maturity_date'])){
		$gov_maturity_date = $_POST['gov_maturity_date'];
	}
	$gov_type = "";
	if(isset($_POST['gov_type'])){
		$gov_type = $_POST['gov_type'];
	}
	$gov_ror = "";
	if(isset($_POST['gov_ror'])){
		$gov_ror = $_POST['gov_ror'];
	}
	
	$year           = lp_calculation::total_year($gov_maturity_date, $gov_start_date);	
	$amount_info    = lp_calculation::compound_interest($gov_amount,$gov_ror,$year);
	$amount_info    = json_decode($amount_info); 
	$maturity_amt   = $amount_info->future_value;
	echo json_encode(array('sts' => true,'maturity_amt' =>$maturity_amt));
}else
/**** CALCULATION AUNNITY AMOUNT ****/
if($frm === "cal_annuity"){
	$ins_start_date = "";
	if(isset($_POST['ins_start_date'])){
		$ins_start_date = $_POST['ins_start_date'];
	}
	$vesting_date = "";
	if(isset($_POST['vesting_date'])){
		$vesting_date = $_POST['vesting_date'];
	}
	$pen_ror = "";
	if(isset($_POST['pen_ror'])){
		$pen_ror = $_POST['pen_ror'];
	}
	$pen_amt = "";
	if(isset($_POST['pen_amt'])){
		$pen_amt = $_POST['pen_amt'];
	}
	$pen_frq = "";
	if(isset($_POST['pen_frq'])){
		$pen_frq = $_POST['pen_frq'];
	}
	$pen_ropen = "";
	if(isset($_POST['pen_ropen'])){
		$pen_ropen = $_POST['pen_ropen'];
	}
	$year_array  = array(1=>0,2=>12,3=>4,4=>2,5=>1);
	$compounding = $year_array[(int)$pen_frq];	
	
	$months         = lp_calculation::total_month($ins_start_date,$vesting_date);
	$amount_info    = lp_calculation::rd_maturity($pen_ror,$compounding,$months,$pen_amt);
	$amount_info    = json_decode($amount_info); 
	$vesting_corpus = $amount_info->maturity_amount;
	$one3rd_corpus  = $vesting_corpus / 3;
	$pension_amount = ($vesting_corpus - $one3rd_corpus) / 100 * $pen_ropen;
	
	echo json_encode(array('sts' => true,'vesting_corpus' =>$vesting_corpus,'one3rd_corpus' =>round($one3rd_corpus),'pension_amount' =>round($pension_amount)));
}else
/**** CALCULATION OTHERS INVESTMENTS MATURITY AMOUNT ****/
if($frm === "cal_other_maturity"){
	$others_amt = "";
	if(isset($_POST['others_amt'])){
		$others_amt = $_POST['others_amt'];
	}
	$others_startdate = "";
	if(isset($_POST['others_startdate'])){
		$others_startdate = $_POST['others_startdate'];
	}
	$others_tenure = "";
	if(isset($_POST['others_tenure'])){
		$others_tenure = $_POST['others_tenure'];
	}
	$others_tenure_type = "";
	if(isset($_POST['others_tenure_type'])){
		$others_tenure_type = $_POST['others_tenure_type'];
	}
	$others_expected_val = "";
	if(isset($_POST['others_expected_val'])){
		$others_expected_val = $_POST['others_expected_val'];
	}
	$others_maturity_date = "";
	if(isset($_POST['others_maturity_date'])){
		$others_maturity_date = $_POST['others_maturity_date'];
	}
	
	//$start_date     = date('Y-m-d',strtotime($others_startdate));
	$start_date      = new DateTime($others_startdate);
	$start_date      = $start_date->format("Y-m-d");
		
	$maturity_info  = lp_calculation::maturity_date($start_date,$others_tenure,$others_tenure_type);
	$maturity_info  = json_decode($maturity_info); 
	$maturity_date  = $maturity_info->maturity_date;
	
	$year           = lp_calculation::total_year($maturity_date, $start_date);	
	$amount_info    = lp_calculation::compound_interest($others_amt,$others_expected_val,$year);
	$amount_info    = json_decode($amount_info); 
	$maturity_amt   = $amount_info->future_value;
	echo json_encode(array('sts' => true, 'maturity_amt' =>$maturity_amt,'maturity_date' =>$maturity_date));
}else
/**** PROFILE SAVE ****/
if($frm === "profile_save"){ 
	$cust_id   = $libObject->cust_id;	
	$fdata = "";
	if(isset($_POST['fdata'])){
		$fdata = $_POST['fdata'];
		$fdata = json_decode($fdata);
	}
	
	$qry_key     = "cust_id,";
	$qry_value   = "'$cust_id',";
	$exist_query = "";
	$upd_query   = "";
	foreach($fdata as $form_data){
		$name  = $real_db->real_escape_string($form_data->name);
		$value = $real_db->real_escape_string($form_data->value);
		if($name === "mobile_no"){
			$name 		 = "cust_mobile";
			$cust_mobile = $value;
		}		
		if($value){
			$qry_key     .= "$name,";
			$qry_value   .= "'$value',";
			$upd_query   .= "$name = '$value',";
		}
	}	
		
	$created_on = date("Y-m-d h:i:s");
	$upd_query .= "updated_date = '$created_on',";	
	$upd_query  = rtrim($upd_query,',');
	//echo "UPDATE lp_customers SET $upd_query WHERE cust_id = '$cust_id'";
	$update_query = "UPDATE lp_customers SET $upd_query WHERE cust_id = '$cust_id'";
	$profile_info = $dbObject->runQuery($update_query);
			$cust_id   = $cust_id;			
			$libObject->get_cust_info($cust_id);
			$obj_id = urlencode(base64_encode(serialize($libObject)));
			
			$lp_session = lpObject::newObject('lp_session');
			if($lp_session->clear_session($cust_id)){				
				$lp_session->save_session($cust_id, $obj_id);
			}	

	if($profile_info){
		echo json_encode(array('sts' => TRUE,'info'=>'Profile Updated Successfully'));
	}else{
		echo json_encode(array('sts' => FALSE,'info'=>'Please Try After Sometime'));
	}
}else{
	echo json_encode(array('sts' => FALSE, 'info' =>"No Record found"));
}
?>