function editAction()
 {
 	$id = $this->getRequest()->getParam("id");
 	$db = new Loan_Model_DbTable_DbLoanILPayment();
 	if($this->getRequest()->isPost()){
 		$data = $this->getRequest()->getPost();
 		//print_r($data);exit();
 		$db->editQuickPayment($id,$data);
 		if(isset($data["save_new"])){
 			Application_Form_FrmMessage::Sucessfull("INSERT_SUCCESS!","/loan/il-quick-payment/add");
 		}elseif(isset($data["save_close"])){
 			Application_Form_FrmMessage::Sucessfull("INSERT_SUCCESS!","/loan/IlQuickPayment");
 		}
 	}
 	
 	$quickPayment = $db->getIlQuickPaymentById($id);
 	$this->view->quickPayment = $quickPayment;
 	
 	$quickPaymentDetail = $db->getIlQuickPaymentDetailById($id);
 	$this->view->quickPaymentDetail = $quickPaymentDetail;
 	
 	$frm = new Loan_Form_FrmIlPayment();
 	$frm_loan=$frm->quickPayment();
 	Application_Model_Decorator::removeAllDecorator($frm_loan);
 	$db_keycode = new Application_Model_DbTable_DbKeycode();
 	$this->view->keycode = $db_keycode->getKeyCodeMiniInv();
 	 
 	$this->view->graiceperiod = $db_keycode->getSystemSetting(9);
 	$this->view->frm_ilpayment = $frm_loan;
 	 
 	$this->view->co = $db->getAllCo();
 }
Example #2
0
    function updateGroupPayment($data,$id){
    	$db = $this->getAdapter();
    	$db->beginTransaction();
    	$session_user=new Zend_Session_Namespace('auth');
    	$user_id = $session_user->user_id;
    	$query = new Application_Model_DbTable_DbGlobal();
    	//$id= $data["id"];
    	try{
    		$arr_client_pay = array(
    				'co_id'							=>		$data['co_id'],
    				'group_id'						=>		$data["client_code"],
    				'receiver_id'					=>		$data['reciever'],
    				'branch_id'						=>		$data['branch_id'],
    				'date_input'					=>		$data["date_input"],
    				'principal_amount'				=>		$data["priciple_amount"],
    				'total_principal_permonth'		=>		$data["os_amount"],
    				'total_payment'					=>		$data["total_payment"],
    				'total_interest'				=>		$data["total_interest"],
    				'recieve_amount'				=>		$data["amount_receive"],
    				'penalize_amount'				=>		$data['penalize_amount'],
    				'return_amount'					=>		$data["amount_return"],
    				'service_charge'				=>		$data["service_charge"],
    				'note'							=>		$data['note'],
    				'user_id'						=>		$user_id,
    				'is_group'						=>		1,
    				'payment_option'				=>		1,
    				'currency_type'					=>		$data["currency_type"],
    				'status'						=>		1,
    				'amount_payment'				=>		$data["amount_receive"]-$data["amount_return"],
    				'is_completed'					=>		1
    		);
    		$this->_name = "ln_client_receipt_money";
    		$where = $db->quoteInto("id=?", $id);
    		
    		$client_pay = $this->update($arr_client_pay, $where);
    		
    		$loan_fun = $this->getGroupPaymentDetail($id);
    			
    		$sql_delete = "DELETE FROM ln_client_receipt_money_detail WHERE crm_id =$id";
    		
    		$db->query($sql_delete);
    		
    		if(!empty($loan_fun)){
    			foreach ($loan_fun as $rs){
    				$principle = $rs["principal_permonth"];
    				$interest = $rs["total_interest"];
    				$recieve_amount = $rs["total_recieve"];
    				$total_pay = $rs["total_payment"];
    				$penelize = $rs["penelize_amount"];
    				$service_charge = $rs["service_charge"];
    		
    				$db_fun = new Loan_Model_DbTable_DbLoanILPayment();
    				$fun = $db_fun->getFunDetail($rs["lfd_id"]);
    				foreach ($fun as $row_fun){
    						
    					if($row_fun["is_completed"]==1){
    						$arr_fun = array(
    								'is_completed'	=>	0,
    						);
    						$this->_name= "ln_loanmember_funddetail";
    						$where = $db->quoteInto("id=?", $rs["lfd_id"]);
    		
    						$this->update($arr_fun, $where);
    						
    					}else{
    						$arr_fun = array(
    								'principle_after'	=>	$principle,
    								'total_interest_after'	=> $interest,
    								'total_payment_after'	=>	$total_pay,
    								'penelize'				=>	$penelize,
    								'service_charge'		=>	$service_charge,
    						);
    						$this->_name= "ln_loanmember_funddetail";
    						$where = $db->quoteInto("id=?", $rs["lfd_id"]);
    						
    						$this->update($arr_fun, $where);
    						
    					}
    				}
    			}
    		}
    	
    		$identify = explode(',',$data['identity']);
    		foreach($identify as $i){
    			$client_detail = $data["mfdid_".$i];
    			$sub_recieve_amount = $data["sub_recive_amount_".$i];
    			$sub_service_charge = $data["sub_service_charge_".$i];
    			$sub_peneline_amount = $data["sub_penelize_".$i];
    			$sub_interest_amount = $data["sub_interest_".$i];
    			$sub_principle= $data["sub_principal_permonth_".$i];
    			$sub_total_payment = $data["sub_payment_".$i];
    			if($client_detail!=""){
    				//$reciept_no=$this->getIlPaymentNumber();
    				if($sub_recieve_amount>=$sub_total_payment){
    					$arr_money_detail = array(
    							'crm_id'				=>		$id,
    							'loan_number'			=>		$data["loan_number_".$i],
    							'lfd_id'				=>		$data["mfdid_".$i],
    							'client_id'				=>		$data["client_id_".$i],
    							'date_payment'			=>		$data["date_payment_".$i],
    							'capital'				=>		$data["sub_total_priciple_".$i],
    							'remain_capital'		=>		$data["sub_total_priciple_".$i] - $data["sub_principal_permonth_".$i],
    							'principal_permonth'	=>		$data["sub_principal_permonth_".$i],
    							'total_interest'		=>		$data["sub_interest_".$i],
    							'total_payment'			=>		$data["sub_payment_".$i],
    							'total_recieve'			=>		$data["sub_recive_amount_".$i],
    							'currency_id'			=>		$data["cu_id_".$i],
    							'pay_after'				=>		$data['multiplier_'.$i],
    							'is_completed'			=>		0,
    							'is_verify'				=>		0,
    							'verify_by'				=>		0,
    							'is_closingentry'		=>		0,
    							'status'				=>		1
    					);
    					
    					
    					$db->insert("ln_client_receipt_money_detail", $arr_money_detail);
    					
    					
    					$arr_update_fun_detail = array(
    							'is_completed'		=> 	1,
    							'payment_option'	=>	1
    					);
    					$this->_name="ln_loanmember_funddetail";
    					$where = $db->quoteInto("id=?", $data["mfdid_".$i]);
    					
    					
    					$this->update($arr_update_fun_detail, $where);
    					
    				}else{
    					$new_sub_interest_amount = $data["sub_interest_".$i];
    					$new_sub_penelize = $data["sub_penelize_".$i];
    					$new_sub_service_charge = $data["sub_service_charge_".$i];
    					$new_sub_principle = $data["sub_principal_permonth_".$i];
    					if($sub_recieve_amount>0){
    						$new_amount_after_service = $sub_recieve_amount-$sub_service_charge;
    						if($new_amount_after_service>=0){
    							$new_sub_service_charge = 0;
    							$new_amount_after_penelize = $new_amount_after_service - $sub_peneline_amount;
    							if($new_amount_after_penelize>=0){
    								$new_sub_penelize = 0;
    								$new_amount_after_interest = $new_amount_after_penelize - $sub_interest_amount;
    								if($new_amount_after_interest>=0){
    									$new_sub_interest_amount = 0;
    									$new_sub_principle = $sub_principle - $new_amount_after_interest;
    								}else{
    									$new_sub_interest_amount = abs($new_amount_after_interest);
    								}
    							}else{
    								$new_sub_penelize = abs($new_amount_after_penelize);
    							}
    						}else{
    							$new_sub_service_charge = abs($new_amount_after_service);
    						}
    					}
    					 
    					$arr_money_detail = array(
    							'crm_id'				=>		$id,
    							'loan_number'			=>		$data["loan_number_".$i],
    							'lfd_id'				=>		$data["mfdid_".$i],
    							'client_id'				=>		$data["client_id_".$i],
    							'date_payment'			=>		$data["date_payment_".$i],
    							'capital'				=>		$data["sub_total_priciple_".$i],
    							'remain_capital'		=>		$data["sub_total_priciple_".$i] - $data["sub_principal_permonth_".$i],
    							'principal_permonth'	=>		$sub_principle,
    							'total_interest'		=>		$sub_interest_amount,
    							'total_payment'			=>		$sub_total_payment,
    							'total_recieve'			=>		$data["sub_recive_amount_".$i],
    							'currency_id'			=>		$data["cu_id_".$i],
    							'pay_after'				=>		$data['multiplier_'.$i],
    							'is_completed'			=>		0,
    							'is_verify'				=>		0,
    							'verify_by'				=>		0,
    							'is_closingentry'		=>		0,
    							'status'				=>		1
    					);
    					
    					
    					$db->insert("ln_client_receipt_money_detail", $arr_money_detail);
    					
    					 
    					$arr_update_fun_detail = array(
    							'is_completed'			=> 	0,
    							'total_interest_after'	=>  $new_sub_interest_amount,
    							'total_payment_after'	=>	$new_sub_principle,
    							'penelize'				=>	$new_sub_penelize,
    							'principle_after'		=>	$new_sub_principle,
    							'service_charge'		=>	$new_sub_service_charge,
    							'payment_option'		=>	1
    					);
    					$this->_name="ln_loanmember_funddetail";
    					$where = $db->quoteInto("id=?", $data["mfdid_".$i]);
    					
    					
    					$this->update($arr_update_fun_detail, $where);
    					
    				}
    				
    				$loan_number = $data["loan_number_".$i];
    				$sql_payment ="SELECT
				    					l.*
				    				FROM
				    					`ln_loanmember_funddetail` AS l,
				    					`ln_loan_member` AS m
				    				WHERE l.`member_id` = m.`member_id`
				    					AND m.`loan_number` = '$loan_number'
				    					AND l.`is_completed` = 0 ";
    				$rs_payment = $db->fetchRow($sql_payment);
    				
    				$group_id = $data["client_code"];
    				if(empty($rs_payment)){
    				$sql ="UPDATE
    							`ln_loan_group` AS l
    						SET l.`status` = 2
    						WHERE l.`g_id`= (SELECT m.`group_id` FROM `ln_loan_member` AS m WHERE m.`loan_number`='$loan_number' LIMIT 1)
    							AND l.`group_id`= $group_id AND l.`loan_type`=1";
    				
    					$db->query($sql);
    					
    					 
    					$sql_loan_memeber ="UPDATE `ln_loan_member` AS m SET m.`is_completed`=1 WHERE m.`loan_number`= '$loan_number'";
    					
    					
    					$db->query($sql_loan_memeber);
    					
    			}
    		}
    		}
    		$db->commit();
    	}catch (Exception $e){
    		$db->rollBack();
    		echo $e->getMessage();
    		Application_Model_DbTable_DbUserLog::writeMessageError($e->getMessage());
    	}
    }
Example #3
0
   public function editQuickPayment($id,$data){
   	$db = $this->getAdapter();
   	$db->beginTransaction();
   	$session_user=new Zend_Session_Namespace('auth');
   	$user_id = $session_user->user_id;
   	$reciept_no=$this->getIlPaymentNumber();
   	$db_loanFun = new Loan_Model_DbTable_DbLoanILPayment();
   	
   	try {
   		$is_set=0;
   		$quick_fun = $this->getIlQuickPaymentDetailById($id);
   		$identify = explode(',',$data['identity']);
   		if(!empty($identify)){
   			$arr_reciept_money = array(
   					'co_id'							=>		$data['co_id'],
   					'receiver_id'					=>		$data['reciever'],
   					'branch_id'						=>		$data['branch_id'],
   					'date_input'					=>		$data["collect_date"],
   					'principal_amount'				=>		$data["priciple_amount"],
   					'total_principal_permonth'		=>		$data["os_amount"],
   					'total_payment'					=>		$data["total_payment"],
   					'total_interest'				=>		$data["total_interest"],
   					'recieve_amount'				=>		$data["amount_receive"],
   					'penalize_amount'				=>		$data['penalize_amount'],
   					'return_amount'					=>		$data["amount_return"],
   					'service_charge'				=>		$data["service_charge"],
   					'note'							=>		$data['note'],
   					'user_id'						=>		$user_id,
   					'is_group'						=>		2,
   					'payment_option'				=>		1,
   					'currency_type'					=>		$data["currency_type"],
   					'status'						=>		1,
   					'amount_payment'				=>		$data["amount_receive"]-$data["amount_return"],
   					'is_completed'					=>		1
   			);
   				
   			$this->_name="ln_client_receipt_money";
   			$where = $db->quoteInto("id=?", $id);
   			$this->update($arr_reciept_money, $where);
   			
   			$sql_delete = "DELETE FROM `ln_client_receipt_money_detail` WHERE crm_id = $id";
   			$db->query($sql_delete);
   			
   			if(!empty($quick_fun)){
   				foreach ($quick_fun as $rs){
   					$principle = $rs["principal_permonth"];
   					$interest = $rs["total_interest"];
   					$recieve_amount = $rs["total_recieve"];
   					$total_pay = $rs["total_payment"];
   					$penelize = $rs["penelize_amount"];
   					$service_charge = $rs["service_charge"];
   					
   					$old_group_id = $rs["group_id"];
   					$old_datepayment = $rs["date_payment"];
   					
   					$fun = $db_loanFun->getLoanFunByGroupId($old_group_id, $old_datepayment);
   					foreach ($fun as $row_fun){
   						
   						if($row_fun["is_completed"]==1){
   							$arr_fun = array(
   								'is_completed'	=>	0,
   							);
   							$this->_name= "ln_loanmember_funddetail";
   							$where = $db->quoteInto("id=?", $row_fun["id"]);
   							
   							$db->getProfiler()->setEnabled(true);
   							$this->update($arr_fun, $where);
   							Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
   							Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
   							$db->getProfiler()->setEnabled(false);
   						}else{
	   						$arr_fun = array(
	   							'principle_after'	=>	$principle,
	   							'total_interest_after'	=> $interest,
	   							'total_payment_after'	=>	$total_pay,
	   							'penelize'				=>	$penelize,
	   							'service_charge'		=>	$service_charge,
	   						);
	   						$this->_name= "ln_loanmember_funddetail";
	   						$where = $db->quoteInto("id=?", $row_fun["id"]);
	   						
	   						$db->getProfiler()->setEnabled(true);
	   						$this->update($arr_fun, $where);
	   						Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
	   						Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
	   						$db->getProfiler()->setEnabled(false);
   						}
   					}
   				}
   			}
   			
   			foreach ($identify as $i){
   				$client_detail = $data["mfdid_".$i];
   				$sub_recieve_amount = $data["sub_recive_amount_".$i];
   				$sub_service_charge = $data["sub_service_charge_".$i];
   				$sub_peneline_amount = $data["sub_penelize_".$i];
   				$sub_interest_amount = $data["sub_interest_".$i];
   				$sub_principle= $data["sub_principal_permonth_".$i];
   				$sub_total_payment = $data["sub_payment_".$i];
   				if($client_detail!=""){
   					$loan_type = $data["loan_type_".$i];
   					$group_id = $data["group_id_".$i];
   					$pay_date = $data["date_payment_".$i];
   						
   					$loanFun = $db_loanFun->getLoanFunByGroupId($group_id,$pay_date);
   					if($loan_type==2){
   						if(!empty($loanFun) or $loanFun!="" or $loanFun!=null){
   							foreach ($loanFun as $rowFun){
   								if($is_set!=1){
   									$total_pene = $data["sub_penelize_".$i];
   									$total_pay = $rowFun["total_payment_after"]+$data["sub_penelize_".$i];
   									$is_set=1;
   								}else{
   									$total_pene = $rowFun["penelize"];
   									$total_pay = $rowFun["total_payment_after"];
   								}
   			
   								$arr_money_detail = array(
   										'crm_id'				=>		$id,
   										'loan_number'			=>		$rowFun["loan_number"],
   										'lfd_id'				=>		$rowFun["id"],
   										'client_id'				=>		$rowFun["client_id"],
   										'date_payment'			=>		$rowFun["date_payment"],
   										'capital'				=>		$rowFun["total_capital"],
   										'remain_capital'		=>		$rowFun["total_capital"] - $rowFun["principle_after"],
   										'principal_permonth'	=>		$rowFun["principle_after"],
   										'total_interest'		=>		$rowFun["total_interest_after"],
   										'total_payment'			=>		$total_pay,
   										'total_recieve'			=>		$total_pay,
   										'currency_id'			=>		$data["cu_id_".$i],
   										'pay_after'				=>		$data['multiplier_'.$i],
   										'penelize_amount'		=>		$total_pene,
   										'service_charge'		=>		$data["sub_service_charge_".$i],
   										'is_completed'			=>		1,
   										'is_verify'				=>		0,
   										'verify_by'				=>		0,
   										'is_closingentry'		=>		0,
   										'status'				=>		1
   								);
   								$db->getProfiler()->setEnabled(true);
   								$db->insert("ln_client_receipt_money_detail", $arr_money_detail);
   								Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
   								Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
   								$db->getProfiler()->setEnabled(false);
   			
   								$arr_fu = array(
   										'is_completed'	=> 1,
   								);
   								$this->_name="ln_loanmember_funddetail";
   								$where = $db->quoteInto("id=?", $rowFun["id"]);
   								$db->getProfiler()->setEnabled(true);
   								$this->update($arr_fu, $where);
   								Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
   								Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
   								$db->getProfiler()->setEnabled(false);
   							}
   						}
   							
   					}else{
   						if($sub_recieve_amount>=$sub_total_payment){
   							$arr_money_detail = array(
   									'crm_id'				=>		$id,
   									'loan_number'			=>		$data["loan_number_".$i],
   									'lfd_id'				=>		$data["mfdid_".$i],
   									'client_id'				=>		$data["client_id_".$i],
   									'date_payment'			=>		$data["date_payment_".$i],
   									'capital'				=>		$data["sub_total_priciple_".$i],
   									'remain_capital'		=>		$data["sub_total_priciple_".$i] - $data["sub_principal_permonth_".$i],
   									'principal_permonth'	=>		$data["sub_principal_permonth_".$i],
   									'total_interest'		=>		$data["sub_interest_".$i],
   									'total_payment'			=>		$data["sub_payment_".$i],
   									'total_recieve'			=>		$data["sub_recive_amount_".$i],
   									'currency_id'			=>		$data["cu_id_".$i],
   									'pay_after'				=>		$data['multiplier_'.$i],
   									'penelize_amount'		=>		$data["sub_penelize_".$i],
   									'service_charge'		=>		$data["sub_service_charge_".$i],
   									'is_completed'			=>		0,
   									'is_verify'				=>		0,
   									'verify_by'				=>		0,
   									'is_closingentry'		=>		0,
   									'status'				=>		1
   							);
   							$db->insert("ln_client_receipt_money_detail", $arr_money_detail);
   			
   							$arr_update_fun_detail = array(
   									'is_completed'		=> 	1,
   									'payment_option'	=>	1
   							);
   							$this->_name="ln_loanmember_funddetail";
   							$where = $db->quoteInto("id=?", $data["mfdid_".$i]);
   							 
   							$this->update($arr_update_fun_detail, $where);
   							 
   						}else{
   							$new_sub_interest_amount = $data["sub_interest_".$i];
   							$new_sub_penelize = $data["sub_penelize_".$i];
   							$new_sub_service_charge = $data["sub_service_charge_".$i];
   							$new_sub_principle = $data["sub_principal_permonth_".$i];
   							if($sub_recieve_amount>0){
   								$new_amount_after_service = $sub_recieve_amount-$sub_service_charge;
   								if($new_amount_after_service>=0){
   									$new_sub_service_charge = 0;
   									$new_amount_after_penelize = $new_amount_after_service - $sub_peneline_amount;
   									if($new_amount_after_penelize>=0){
   										$new_sub_penelize = 0;
   										$new_amount_after_interest = $new_amount_after_penelize - $sub_interest_amount;
   										if($new_amount_after_interest>=0){
   											$new_sub_interest_amount = 0;
   											$new_sub_principle = $sub_principle - $new_amount_after_interest;
   										}else{
   											$new_sub_interest_amount = abs($new_amount_after_interest);
   										}
   									}else{
   										$new_sub_penelize = abs($new_amount_after_penelize);
   									}
   								}else{
   									$new_sub_service_charge = abs($new_amount_after_service);
   								}
   							}
   							$arr_money_detail = array(
   									'crm_id'				=>		$id,
   									'loan_number'			=>		$data["loan_number_".$i],
   									'lfd_id'				=>		$data["mfdid_".$i],
   									'client_id'				=>		$data["client_id_".$i],
   									'date_payment'			=>		$data["date_payment_".$i],
   									'capital'				=>		$data["sub_total_priciple_".$i],
   									'remain_capital'		=>		$data["sub_total_priciple_".$i] - $data["sub_principal_permonth_".$i],
   									'principal_permonth'	=>		$sub_principle,
   									'total_interest'		=>		$sub_interest_amount,
   									'total_payment'			=>		$sub_total_payment,
   									'total_recieve'			=>		$data["sub_recive_amount_".$i],
   									'currency_id'			=>		$data["cu_id_".$i],
   									'pay_after'				=>		$data['multiplier_'.$i],
   									'penelize_amount'		=>		$data["sub_penelize_".$i],
   									'service_charge'		=>		$data["sub_service_charge_".$i],
   									'is_completed'			=>		0,
   									'is_verify'				=>		0,
   									'verify_by'				=>		0,
   									'is_closingentry'		=>		0,
   									'status'				=>		1
   							);
   							$db->insert("ln_client_receipt_money_detail", $arr_money_detail);
   							 
   							$arr_update_fun_detail = array(
   									'is_completed'			=> 	0,
   									'total_interest_after'	=>  $new_sub_interest_amount,
   									'total_payment_after'	=>	$new_sub_principle,
   									'penelize'				=>	$new_sub_penelize,
   									'principle_after'		=>	$new_sub_principle,
   									'service_charge'		=>	$new_sub_service_charge,
   									'payment_option'		=>	1
   							);
   							$this->_name="ln_loanmember_funddetail";
   							$where = $db->quoteInto("id=?", $data["mfdid_".$i]);
   							$this->update($arr_update_fun_detail, $where);
   						}
   					}
   					$loan_fun = $db_loanFun->getFunByGroupId($group_id);
   					if(empty($loan_fun) or $loan_fun="" or $loan_fun=null){
   						$sql_mem = "SELECT lm.`member_id` FROM `ln_loan_member` AS lm WHERE lm.`group_id`=$group_id";
   						$row_mem = $db->fetchAll($sql_mem);
   						foreach ($row_mem as $rs_mem){
   							$arr_member = array(
   									'is_completed'	=> 1,
   							);
   							$this->_name ="ln_loan_member";
   							$where = $db->quoteInto("member_id=?", $rs_mem["member_id"]);
   							$this->update($arr_member, $where);
   								
   							$arr_group = array(
   									'status'	=> 2,
   							);
   							$this->_name ="ln_loan_group";
   							$where = $db->quoteInto("g_id=?", $group_id);
   							$this->update($arr_group, $where);
   						}
   					}
   				}
   			}
   		}
//    		exit();
   		$db->commit();
   	}catch (Exception $e){
   		$db->rollBack();
   		Application_Model_DbTable_DbUserLog::writeMessageError($e->getMessage());
   	}
   }
Example #4
0
	public function FrmGroupPayment($data=null){
	
		$db = new Application_Model_DbTable_DbGlobal();
		
		$old_penelize = new Zend_Form_Element_Hidden("old_penelize");
		$old_penelize->setAttribs(array(
				'dojoType'=>'dijit.form.TextBox',
				'class'=>'fullside',
				//'required' =>'true'
		));
		
		$old_service_charge = new Zend_Form_Element_Hidden("old_service_charge");
		$old_service_charge->setAttribs(array(
				'dojoType'=>'dijit.form.TextBox',
				'class'=>'fullside',
				//'required' =>'true'
		));
		
		$_interest_rate = new Zend_Dojo_Form_Element_TextBox("interest_rate");
		$_interest_rate->setAttribs(array(
				'dojoType'=>'dijit.form.TextBox',
				'class'=>'fullside',
				'required' =>'true',
				'readOnly'=>'readOnly'
		));
		
		$term_opt = $db->getVewOptoinTypeByType(14,1,3);
		$_payterm = new Zend_Dojo_Form_Element_FilteringSelect('payment_term');
		$_payterm->setAttribs(array(
				'dojoType'=>'dijit.form.FilteringSelect',
				'class'=>'fullside',
				'required' =>'true',
				'readOnly'=>'readOnly'
		));
		$_payterm->setMultiOptions($term_opt);
		
		$_currency_type = new Zend_Dojo_Form_Element_FilteringSelect('currency_type');
		$_currency_type->setAttribs(array(
				'dojoType'=>'dijit.form.FilteringSelect',
				'class'=>'fullside',
				'readOnly'=>'readOnly'
		));
		$opt = array(-1=>"--Select Currency Type--",2=>"Dollar",1=>'Khmer',3=>"Bath");
		$_currency_type->setMultiOptions($opt);
		//$_currency_type->setValue($request->getParam("currency_type"));
		
// 		$_groupid = new Zend_Dojo_Form_Element_FilteringSelect('client_id');
// 		$_groupid->setAttribs(array(
// 				'dojoType'=>'dijit.form.FilteringSelect',
// 				'class'=>'fullside',
//  				//'onchange'=>'getLaonPayment(3);getAllLaonPayment(3);',
// 				'required'=>true
// 				));
		$rows = $db ->getClientByType(1);
// 		$options=array(''=>'-----Select------');
// 		if(!empty($rows))foreach($rows AS $row){
// // 			$options[$row['client_id']]=$row['name_en'].','.$row['province_en_name'].','.$row['district_name'].','.$row['commune_name'].','.$row['village_name'];
// 			$options[$row['client_id']]=$row['name_en'].','.$row['province_en_name'];
// 		}
// 		$_groupid->setMultiOptions($options);
		
		$_client_code = new Zend_Dojo_Form_Element_FilteringSelect('client_code');
		$_client_code->setAttribs(array(
				'dojoType'=>'dijit.form.FilteringSelect',
				'class'=>'fullside',
				'readOnly'=>'readOnly',
				//'onchange'=>'getLaonHasPayByLoanNumber(2);getLaonPayment(2);getAllLaonPayment(2);',
				'required'=>true
		));
		
		$option_client_number = array(''=>'-----Select------');
		if(!empty($rows))foreach($rows AS $row){
			$option_client_number[$row['client_id']]=$row['client_number']."-".$row['name_en'];
		}
		$_client_code->setMultiOptions($option_client_number);
		
// 		$_loan_number = new Zend_Dojo_Form_Element_TextBox('loan_number');
// 		$_loan_number->setAttribs(array(
// 				'dojoType'=>'dijit.form.TextBox',
// 				'class'=>'fullside',
// 				//'onKeyUp'=>'getLaonPayment(1);getAllLaonPayment(1);'
// 				'required'=>true
// 		));
		$row_loan_number = $db->getAllLoanNumber(2);
		$options=array(''=>'');
		if(!empty($row_loan_number))foreach($row_loan_number AS $row){
			$options[$row['loan_number']]=$row['loan_number'];
		}
		$_loan_number = new Zend_Dojo_Form_Element_FilteringSelect('loan_number');
		$_loan_number->setAttribs(array(
				'dojoType'=>'dijit.form.FilteringSelect',
				'class'=>'fullside',
				'onChange'=>'getLaonPayment(1);',
				'required'=>true
		));
		$_loan_number->setMultiOptions($options);
		
		
		$_amount_receive = new Zend_Dojo_Form_Element_NumberTextBox('amount_receive');
		$_amount_receive->setAttribs(array(
				'dojoType'	=>	'dijit.form.NumberTextBox',
				'class'		=>	'fullside',
				'onChange'	=>	'totalReturn();',
				'style'		=>	'color:red;',
				'required'	=>	true,
				
		));
		
		$_amount_return = new Zend_Dojo_Form_Element_NumberTextBox('amount_return');
		$_amount_return->setAttribs(array(
				'dojoType'=>'dijit.form.NumberTextBox',
				'class'=>'fullside',
				'style'=>'color:red;',
				//'required'=>true,
				'readonly'=>true
		));
		
		$_service_charge = new Zend_Dojo_Form_Element_NumberTextBox('service_charge');
		$_service_charge->setAttribs(array(
				'dojoType'	=>'dijit.form.NumberTextBox',
				'class'		=>'fullside',
				//'onkeyUp'=>'totalReturn();'
				'onBlur'	=>	'doTotalByServ();'
		));
		$_service_charge->setValue(0);
		
		$_branch_id = new Zend_Dojo_Form_Element_FilteringSelect('branch_id');
		$_branch_id->setAttribs(array(
				'dojoType'=>'dijit.form.FilteringSelect',
				'class'=>'fullside',
				'required' =>'true',
				//'OnChange'	=>	'filterClient();'
		));
		
		$rows = $db->getAllBranchName();
		$options=array(''=>'--------Select----------');
		if(!empty($rows))foreach($rows AS $row){
			$options[$row['br_id']]=$row['branch_namekh'];
		}
		$_branch_id->setMultiOptions($options);
		
		
		//$_coid = new Zend_Dojo_Form_Element_FilteringSelect('co_id');
		$_coid = new Zend_Dojo_Form_Element_FilteringSelect('co_id');
		$rows = $db ->getAllCOName();
		$options=array(''=>"------Select------",-1=>"Add New");
		if(!empty($rows))foreach($rows AS $row) $options[$row['co_id']]=$row['co_khname'];
		$_coid->setAttribs(array(
				'dojoType'=>'dijit.form.FilteringSelect',
				'class'=>'fullside',
				'readOnly'=>'readOnly'
		 						//'onchange'=>'getLoan(1);'
		));
		$_coid->setMultiOptions($options);
		
		$_cocode = new Zend_Dojo_Form_Element_FilteringSelect('co_code');
		$rows = $db ->getAllCOName();
		$options=array(''=>"------Select------",-1=>"Add New");
		if(!empty($rows))foreach($rows AS $row) $options[$row['co_id']]=$row['co_code'];
		$_cocode->setAttribs(array(
				'dojoType'=>'dijit.form.FilteringSelect',
				'class'=>'fullside',
				'readOnly'=>'readOnly'
				//'onchange'=>'getLoan(2);'
		));
		$_cocode->setMultiOptions($options);
		
		$_priciple_amount = new Zend_Dojo_Form_Element_NumberTextBox('priciple_amount');
		$_priciple_amount->setAttribs(array(
				'dojoType'=>'dijit.form.NumberTextBox',
				'class'=>'fullside',
				'readOnly'=>'readOnly'
		));
		
		$_loan_fee = new Zend_Dojo_Form_Element_NumberTextBox('loan_fee');
		$_loan_fee->setAttribs(array(
				'dojoType'=>'dijit.form.NumberTextBox',
				'class'=>'fullside',
				'readOnly'=>'readOnly'
		));
		
		$_os_amount = new Zend_Dojo_Form_Element_NumberTextBox('os_amount');
		$_os_amount->setAttribs(array(
				'dojoType'=>'dijit.form.NumberTextBox',
				'class'=>'fullside',
				'readOnly'=>'readOnly',
				'required'=>true,
		));
		
		$_rate = new Zend_Dojo_Form_Element_NumberTextBox('total_interest');
		$_rate->setAttribs(array(
				'dojoType'=>'dijit.form.NumberTextBox',
				'class'=>'fullside',
				'required' =>'true',
				'style'=>'color:red;',
				'readOnly'=>'readOnly',
				'required'=>true,
		));
// 		$value_interest = 2.5;
// 		$_rate->setValue($value_interest);
		
		$_penalize_amount = new Zend_Dojo_Form_Element_NumberTextBox('penalize_amount');
		$_penalize_amount->setAttribs(array(
				'dojoType'=>'dijit.form.NumberTextBox',
				'class'=>'fullside',
				'required'=>true,
				'onBlur'=>'doTotalBypene();'
		));
		$_penalize_amount->setValue(0);
		
		$_total_payment = new Zend_Dojo_Form_Element_NumberTextBox('total_payment');
		$_total_payment->setAttribs(array(
				'dojoType'=>'dijit.form.NumberTextBox',
				'class'=>'fullside',
				'required' =>'true',
				'style'=>'color:red;',
				'required'=>true,
				'readOnly'=>'readOnly'
		));
		
		$_hide_total_payment = new Zend_Form_Element_Text('hide_total_payment');
		$_hide_total_payment->setAttribs(array(
				'dojoType'=>'dijit.form.TextBox',
		));
		
		$_note = new Zend_Dojo_Form_Element_TextBox('note');
		$_note->setAttribs(array(
				'dojoType'=>'dijit.form.TextBox',
				'class'=>'fullside',
				//'required' =>'true'
		));
		
		$_collect_date = new Zend_Dojo_Form_Element_DateTextBox('collect_date');
		$_collect_date->setAttribs(array(
				'dojoType'=>'dijit.form.DateTextBox',
				'class'=>'fullside',
				'required' =>'true',
				'Onchange'	=>	'calculateTotal();'
		));
		$c_date = date('Y-m-d');
		$_collect_date->setValue($c_date);
		
// 		$date_input = new Zend_Dojo_Form_Element_DateTextBox('date_input');
// 		$date_input->setAttribs(array(
// 				'dojoType'=>'dijit.form.DateTextBox',
// 				'class'=>'fullside',
// 				'required' =>true
// 		));
// 		$date_input->setValue($c_date);

		$date_input = new Zend_Form_Element_Hidden("date_input");
		$date_input->setValue($c_date);
		
		$reciever = new Zend_Form_Element_Hidden("reciever");
		$reciever->setAttribs(array('dojoType'=>'dijit.form.TextBox'));
		
		$discount = new Zend_Dojo_Form_Element_TextBox("discount");
		$discount->setAttribs(array('dojoType'=>'dijit.form.TextBox','class'=>'fullside'));
		
		$reciept_no = new Zend_Dojo_Form_Element_TextBox("reciept_no");
		$reciept_no->setAttribs(array('dojoType'=>'dijit.form.TextBox','class'=>'fullside','readonly'=>true,
				'style'=>'color:red; font-weight: bold;'));
		$db_loan = new Loan_Model_DbTable_DbLoanILPayment();
		$loan_number = $db_loan->getIlPaymentNumber();
		$reciept_no->setValue($loan_number);
		$id = new Zend_Form_Element_Hidden("id");
		$id->setAttribs(array(
				'dojoType'=>'dijit.form.TextBox',
				'class'=>'fullside',
		));
		
		$option_pay = new Zend_Dojo_Form_Element_FilteringSelect('option_pay');
		$option_pay->setAttribs(array(
				'dojoType'=>'dijit.form.FilteringSelect',
				'class'=>'fullside',
				'OnChange'=>'getLaonPayment();'
		));
		$option_status = array(1=>'បង់ធម្មតា',2=>'បង់មុន',3=>'បង់រំលោះប្រាក់ដើម',4=>'បង់ផ្តាច់');
		$option_pay->setMultiOptions($option_status);
		
		$amount_payment_term = new Zend_Form_Element_Hidden("amount_payment_term");
		$amount_payment_term->setAttribs(array(
				'dojoType'=>'dijit.form.TextBox',
				'class'=>'fullside',
		));
		
// 		$id = new Zend_Form_Element_Text('id');
// 		$id->setAttrib('dojoType', 'dijit.form.TextBox');
		
		$installment_date = new Zend_Form_Element_Hidden("installment_date");
		$installment_date->setAttribs(array(
				'dojoType'=>'dijit.form.TextBox',
				'class'=>'fullside',
		));
		
		$old_tota_pay = new Zend_Form_Element_Text("oldTotalPay");
		$old_tota_pay->setAttribs(array('dojoType'=>'dijit.form.TextBox','class'=>'fullside',));
		
		$release_date = new Zend_Dojo_Form_Element_TextBox("release_date");
		$release_date->setAttribs(array('dojoType'=>'dijit.form.TextBox','class'=>'fullside','readOnly'=>'readOnly'));
		
		$old_release_date = new Zend_Form_Element_Hidden("old_release_date");
		$old_release_date->setAttribs(array('dojoType'=>'dijit.form.TextBox','class'=>'fullside','readOnly'=>'readOnly'));
		
		$loan_level= new Zend_Dojo_Form_Element_TextBox("load_level");
		$loan_level->setAttribs(array('dojoType'=>'dijit.form.TextBox','class'=>'fullside','readOnly'=>'readOnly'));
		
		$remain= new Zend_Dojo_Form_Element_NumberTextBox("remain");
		$remain->setAttribs(array('dojoType'=>'dijit.form.TextBox','class'=>'fullside','readOnly'=>'readOnly'));
		
		$total_amount_loan = new Zend_Dojo_Form_Element_TextBox("total_amount_loan");
		$total_amount_loan->setAttribs(array('dojoType'=>'dijit.form.TextBox','class'=>'fullside','readOnly'=>'readOnly'));
		
		$loan_period = new Zend_Dojo_Form_Element_TextBox("loan_period");
		$loan_period->setAttribs(array('dojoType'=>'dijit.form.TextBox','class'=>'fullside','readOnly'=>'readOnly'));
		
		$candition_payment = new Zend_Dojo_Form_Element_TextBox("pay_condition");
		$candition_payment->setAttribs(array('dojoType'=>'dijit.form.TextBox','class'=>'fullside','readOnly'=>'readOnly'));
		
		$options = $db->getAllPaymentMethod(null,1);
		$payment_method= new Zend_Dojo_Form_Element_FilteringSelect("payment_method");
		$payment_method->setAttribs(array('dojoType'=>'dijit.form.FilteringSelect','class'=>'fullside','readOnly'=>'readOnly'));
		$payment_method->setMultiOptions($options);
		
		$using_date = new Zend_Dojo_Form_Element_DateTextBox("using_date");
		$using_date->setAttribs(array(
				'dojoType'=>'dijit.form.DateTextBox',
				'class'=>'fullside',
				'required' =>true
		));
		
		$_last_payment_date = new Zend_Form_Element_Hidden("last_payment_date");
		$_last_payment_date->setAttribs(array(
				'dojoType'=>'dijit.form.TextBox',
				'class'=>'fullside',
				//'required' =>true
		));
		
		if($data!=""){
			$id->setValue($data["id"]);
// 			$_groupid->setValue($data["group_id"]);
// 			$_loan_number->setValue($data["loan_number"]);
// 			$_branch_id->setValue($data["branch_id"]);
// 			$_client_code->setValue($data["group_id"]);
// 			$reciept_no->setValue($data["receipt_no"]);
// 			$_coid->setValue($data["co_id"]);
// 			$option_pay->setValue($data["status"]);
// 			$_amount_receive->setValue($data["recieve_amount"]);
// 			$_amount_return->setValue($data["return_amount"]);
// 			$_penalize_amount->setValue($data["penalize_amount"]);
// 			$_total_payment->setValue($data["total_payment"]);
// 			$_priciple_amount->setValue($data["principal_amount"]);
// 			$_os_amount->setValue($data["total_principal_permonth"]);
// // 			$discount->setValue($data["total_discount"]);
// 			$_rate->setValue($data["total_interest"]);
// 			$_note->setValue($data["note"]);
// 			$date_input->setValue($data["date_input"]);
// 			$_collect_date->setValue(date("y-m-d"));
// 			$_service_charge->setValue($data["service_charge"]);
// 			$reciever->setValue($data["receiver_id"]);
// 			$_currency_type->setValue($data["currency_type"]);
// 			$amount_payment_term->setValue($data["amount_term"]);
// 			$_interest_rate->setValue($data["interest_rate"]);
// 			$_payterm->setValue($data["collect_typeterm"]);
// 			$_collect_date->setValue($data["date_pay"]);
// 			$old_tota_pay->setValue($data["total_payment"]-$data["service_charge"]);
		}
		$this->addElements(array($_client_code,$_loan_number,$old_release_date,$old_service_charge,$old_penelize,$_cocode,$_last_payment_date,$using_date,
				$total_amount_loan,$loan_period,$candition_payment,$payment_method,$release_date,$loan_level,$remain,$old_tota_pay,
				$installment_date,$amount_payment_term,$_interest_rate,$_payterm,$_currency_type,$id,$option_pay,$date_input,$reciept_no,
				$reciever,$discount,$id,$_coid,$_priciple_amount,$_loan_fee,$_os_amount,$_rate,
				$_penalize_amount,$_collect_date,$_total_payment,$_note,$_service_charge,$_amount_return,
				$_amount_receive,$_branch_id,$_hide_total_payment));
		return $this;
	}
Example #5
0
public function cancelIlPayment($data){
	$db = $this->getAdapter();
	$db_loan = new Loan_Model_DbTable_DbLoanILPayment();
	$db_group = new Loan_Model_DbTable_DbGroupPayment();
	$db->beginTransaction();
	$is_set = 0;
	try{
		$id = $data["id"];
		$recipt_money = $db_loan->getReceiptMoneyById($id);
		$recipt_money_detail = $db_loan->getReceiptMoneyDetailByID($id);
			foreach ($recipt_money_detail as $row_recipt_detail){
				$fun_id = $row_recipt_detail["lfd_id"];
				if($is_set!=1){
					$loan_number = $row_recipt_detail["loan_number"];
					$rs_fun = $db_group->getFunDetailByLoanNumber($loan_number);
					$rs_group = "SELECT m.group_id FROM ln_loan_member AS m WHERE m.loan_number = '$loan_number' GROUP BY m.loan_number";
					$group_id = $db->fetchOne($rs_group);
					if(empty($rs_fun) or $rs_fun=="" or $rs_fun==null){
						$arr_member = array(
							'is_completed'	=>	0,
						);
						$this->_name = "ln_loan_member";
						$where = $db->quoteInto("loan_number=?", $loan_number);
						
						$db->getProfiler()->setEnabled(true);
						
						$this->update($arr_member, $where);
						
						Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
						Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
						$db->getProfiler()->setEnabled(false);
						
						$arr_group = array(
							'status'	=>	1,
						);
						$this->_name = "ln_loan_group";
						$where = $db->quoteInto("g_id=?", $group_id);
						
						$db->getProfiler()->setEnabled(true);
						
						$this->update($arr_group, $where);
						
						Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
						Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
						$db->getProfiler()->setEnabled(false);
					}
					$is_set=1;
				}
				if($recipt_money["payment_option"]==1){
					echo 1111;
					
					$is_completed = $db_loan->getFunDetailById($fun_id);
					if($is_completed==1){
						$arr_update = array(
							'is_completed' =>	0,
						);
						$this->_name = "ln_loanmember_funddetail";
						$where = $db->quoteInto("id=?", $fun_id);
						
						$db->getProfiler()->setEnabled(true);
						
						$this->update($arr_update, $where);
						
						Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
						Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
						$db->getProfiler()->setEnabled(false);
					}else{
						$arr_update = array(
							'principle_after'		=> 	$row_recipt_detail["principal_permonth"],
							'total_interest_after'	=>	$row_recipt_detail["total_interest"],
							'penelize'				=>	$row_recipt_detail["penelize_amount"],
							'service_charge'		=>	$row_recipt_detail["service_charge"],
							'total_payment_after'	=>	$row_recipt_detail["total_payment"],	
							'is_completed' 			=>	0,
						);
						$this->_name = "ln_loanmember_funddetail";
						$where = $db->quoteInto("id=?", $fun_id);
						
						$db->getProfiler()->setEnabled(true);
						
						$this->update($arr_update, $where);
						
						Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
						Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
						$db->getProfiler()->setEnabled(false);
					}
				}else{
					$arr_update = array(
							'is_completed' =>	0,
					);
					$this->_name = "ln_loanmember_funddetail";
					$where = $db->quoteInto("id=?", $fun_id);
					
					$db->getProfiler()->setEnabled(true);
					
					$this->update($arr_update, $where);
					
					Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
					Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
					$db->getProfiler()->setEnabled(false);
				}
			}
			
			$sql = "DELETE FROM `ln_client_receipt_money` WHERE `id`=$id";
			
			$db->getProfiler()->setEnabled(true);
			
			$db->query($sql);
			
			Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
			Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
			$db->getProfiler()->setEnabled(false);
			
			$sql_cmd = "DELETE FROM `ln_client_receipt_money_detail` WHERE `crm_id` = $id";
			
			$db->getProfiler()->setEnabled(true);
			
			$db->query($sql_cmd);
			
			Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
			Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
			$db->getProfiler()->setEnabled(false);
		exit();
// 		$db->commit();
	}catch (Exception $e){
		$db->rollBack();
		echo $e->getMessage();
		
	}
}   
Example #6
0
	function getLoanHasPayByLoanNumberAction(){
		if($this->getRequest()->isPost()){
			$data = $this->getRequest()->getPost();
			$db = new Loan_Model_DbTable_DbLoanILPayment();
			$loan_number = $data["loan_number"];
			$row = $db->getLaonHasPayByLoanNumber($loan_number);
			print_r(Zend_Json::encode($row));
			exit();
		}
	}
 function cancelPaymentAction()
 {
 	$db = new Loan_Model_DbTable_DbLoanILPayment();
 	if($this->getRequest()->isPost()){
 		$_data = $this->getRequest()->getPost();
 		$identity = $_data["identity"];
 		try {
 			$row = $db->cancelPaymnet($_data);
 			print_r(Zend_Json::encode($row));
 			exit();
 		}catch (Exception $e) {
 			$err =$e->getMessage();
 			Application_Model_DbTable_DbUserLog::writeMessageError($err);
 		}
 	}
 }
Example #8
0
    function updateGroupPayment($data){
    	$db = $this->getAdapter();
    	$db_loan = new Loan_Model_DbTable_DbLoanILPayment();
    	$db_group= new Loan_Model_DbTable_DbGroupPayment();
    	$db->beginTransaction();
    	$session_user=new Zend_Session_Namespace('auth');
    	$user_id = $session_user->user_id;
    	$query = new Application_Model_DbTable_DbGlobal();
    	$id= $data["id"];
    	//$old_loannumber= $data["old_loan_number"];
    	$option_pay = $data["option_pay"];
    	$is_set=0;
    	try{
    		$arr_client_pay = array(
    				'co_id'							=>		$data['co_id'],
    				'group_id'						=>		$data["client_code"],
    				'receiver_id'					=>		$data['reciever'],
    				'branch_id'						=>		$data['branch_id'],
    				'date_input'					=>		$data["collect_date"],
    				'principal_amount'				=>		$data["priciple_amount"],
    				'total_principal_permonth'		=>		$data["os_amount"],
    				'total_payment'					=>		$data["total_payment"],
    				'total_interest'				=>		$data["total_interest"],
    				'recieve_amount'				=>		$data["amount_receive"],
    				'penalize_amount'				=>		$data['penalize_amount'],
    				'return_amount'					=>		$data["amount_return"],
    				'service_charge'				=>		$data["service_charge"],
    				'note'							=>		$data['note'],
    				'user_id'						=>		$user_id,
    				'is_group'						=>		1,
    				'payment_option'				=>		1,
    				'currency_type'					=>		$data["currency_type"],
    				'status'						=>		1,
    				'amount_payment'				=>		$data["amount_receive"]-$data["amount_return"],
    				'is_completed'					=>		1
    		);
    		$this->_name = "ln_client_receipt_money";
    		$where = $db->quoteInto("id=?", $id);
    		$db->getProfiler()->setEnabled(true);
    		
    		$client_pay = $this->update($arr_client_pay, $where);
    		Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
    		Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
    		$db->getProfiler()->setEnabled(false);
    		
    		$recipt_money = $db_loan->getReceiptMoneyById($id);
    		$recipt_money_detail = $db_loan->getReceiptMoneyDetailByID($id);
    		print_r($recipt_money_detail);
    		foreach ($recipt_money_detail as $row_recipt_detail){
    			$fun_id = $row_recipt_detail["lfd_id"];
    			if($is_set!=1){
    				$loan_number = $row_recipt_detail["loan_number"];
    				
    				$rs_fun = $db_group->getFunDetailByLoanNumber($loan_number);
    				$rs_group = "SELECT m.group_id FROM ln_loan_member AS m WHERE m.loan_number = '$loan_number' GROUP BY m.loan_number";
    				$group_id = $db->fetchOne($rs_group);
    				if(empty($rs_fun) or $rs_fun=="" or $rs_fun==null){
    					$arr_member = array(
    							'is_completed'	=>	0,
    					);
    					$this->_name = "ln_loan_member";
    					$where = $db->quoteInto("loan_number=?", $loan_number);
    					
    					$db->getProfiler()->setEnabled(true);
    					
    					$this->update($arr_member, $where);
    					
    					Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
    					Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
    					$db->getProfiler()->setEnabled(false);
    		
    					$arr_group = array(
    							'status'	=>	1,
    					);
    					$this->_name = "ln_loan_group";
    					$where = $db->quoteInto("g_id=?", $group_id);
    					
    					$db->getProfiler()->setEnabled(true);
    					
    					$this->update($arr_group, $where);
    					
    					Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
    					Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
    					$db->getProfiler()->setEnabled(false);
    				}
    				$is_set=1;
    			}
    			if($recipt_money["payment_option"]==1){
    				$is_completed = $db_loan->getFunDetailById($fun_id);
    				if($is_completed==1){
    					$arr_update = array(
    							'is_completed' =>	0,
    					);
    					$this->_name = "ln_loanmember_funddetail";
    					$where = $db->quoteInto("id=?", $fun_id);
    					
    					$db->getProfiler()->setEnabled(true);
    					
    					$this->update($arr_update, $where);
    					
    					Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
    					Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
    					$db->getProfiler()->setEnabled(false);
    				}else{
    					$arr_update = array(
    							'principle_after'		=> 	$row_recipt_detail["principal_permonth"],
    							'total_interest_after'	=>	$row_recipt_detail["total_interest"],
    							'penelize'				=>	$row_recipt_detail["penelize_amount"],
    							'service_charge'		=>	$row_recipt_detail["service_charge"],
    							'total_payment_after'	=>	$row_recipt_detail["total_payment"],
    							'is_completed' 			=>	0,
    					);
    					$this->_name = "ln_loanmember_funddetail";
    					$where = $db->quoteInto("id=?", $fun_id);
    					
    					$db->getProfiler()->setEnabled(true);
    					
    					$this->update($arr_update, $where);
    					
    					Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
    					Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
    					$db->getProfiler()->setEnabled(false);
    				}
    			}else{
    				$arr_update = array(
    						'is_completed' =>	0,
    				);
    				$this->_name = "ln_loanmember_funddetail";
    				$where = $db->quoteInto("id=?", $fun_id);
    				
    				$db->getProfiler()->setEnabled(true);
    				
    				$this->update($arr_update, $where);
    				
    				Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
    				Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
    				$db->getProfiler()->setEnabled(false);
    			}
    		}
    			
    		$sql_cmd = "DELETE FROM `ln_client_receipt_money_detail` WHERE `crm_id` = $id";
    		$db->query($sql_cmd);
    	
    		$identify = explode(',',$data['identity']);
    	foreach($identify as $i){
    			$client_detail = $data["mfdid_".$i];
    			$sub_recieve_amount = $data["sub_recive_amount_".$i];
    			$sub_service_charge = $data["sub_service_charge_".$i];
    			$sub_peneline_amount = $data["sub_penelize_".$i];
    			$sub_interest_amount = $data["sub_interest_".$i];
    			$sub_principle= $data["sub_principal_permonth_".$i];
    			$sub_total_payment = $data["sub_payment_".$i];
    			$loan_number = $data["loan_number_".$i];
    			$date_payment = $data["date_payment_".$i];
    			if($client_detail!=""){
    				$arr_money_detail = array(
    						'crm_id'				=>		$id,
    						'loan_number'			=>		$data["loan_number_".$i],
    						'lfd_id'				=>		$data["mfdid_".$i],
    						'client_id'				=>		$data["client_id_".$i],
    						'date_payment'			=>		$data["date_payment_".$i],
    						'capital'				=>		$data["sub_total_priciple_".$i],
    						'remain_capital'		=>		$data["sub_total_priciple_".$i] - $data["sub_principal_permonth_".$i],
    						'principal_permonth'	=>		$data["sub_principal_permonth_".$i],
    						'total_interest'		=>		$data["sub_interest_".$i],
    						'total_payment'			=>		$data["sub_payment_".$i],
    						'total_recieve'			=>		$data["sub_recive_amount_".$i],
    						'currency_id'			=>		$data["currency_type"],
    						'pay_after'				=>		$data['multiplier_'.$i],
    						'penelize_amount'		=>		$data["old_sub_penelize_".$i],
    						'service_charge'		=>		$data["sub_service_charge_".$i],
    						'is_completed'			=>		0,
    						'is_verify'				=>		0,
    						'verify_by'				=>		0,
    						'is_closingentry'		=>		0,
    						'status'				=>		1
    				);
    				 
    				$db->getProfiler()->setEnabled(true);
    				 
    				$db->insert("ln_client_receipt_money_detail", $arr_money_detail);
    				 
    				Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
    				Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
    				$db->getProfiler()->setEnabled(false);
    				if($option_pay==1){
	    				if($sub_recieve_amount>=$sub_total_payment){
		    				 
		    				$arr_update_fun_detail = array(
		    					'is_completed'		=> 	1,
		    				);
		    				$this->_name="ln_loanmember_funddetail";
		    				$where = $db->quoteInto("id=?", $data["mfdid_".$i]);
		    				
		    				$db->getProfiler()->setEnabled(true);
		    				
		    				$this->update($arr_update_fun_detail, $where);
		    				
		    				Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
		    				Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
		    				$db->getProfiler()->setEnabled(false);
	    				}else{
			   					$new_sub_interest_amount = $data["sub_interest_".$i];
			   					$new_sub_penelize = $data["sub_penelize_".$i]+$data["old_penelize_".$i];
			   					$new_sub_service_charge = $data["sub_service_charge_".$i];
			   					$new_sub_principle = $data["sub_principal_permonth_".$i];
				   				if($sub_recieve_amount>0){
				   					$new_amount_after_service = $sub_recieve_amount-$sub_service_charge;
				   					if($new_amount_after_service>=0){
				   						$new_sub_service_charge = 0;
				   						$new_amount_after_penelize = $new_amount_after_service - $sub_peneline_amount;
				   						if($new_amount_after_penelize>=0){
				   							$new_sub_penelize = 0;
				   							$new_amount_after_interest = $new_amount_after_penelize - $sub_interest_amount;
				   							if($new_amount_after_interest>=0){
				   								$new_sub_interest_amount = 0;
				   								$new_sub_principle = $sub_principle - $new_amount_after_interest;
				   							}else{
				   								$new_sub_interest_amount = abs($new_amount_after_interest);
				   							}
				   						}else{
				   							$new_sub_penelize = abs($new_amount_after_penelize);
				   						}
				   					}else{
				   						$new_sub_service_charge = abs($new_amount_after_service);
				   					}
				   				}
				   				
				   				
				   				$arr_update_fun_detail = array(
				   						'is_completed'			=> 	0,
				   						'total_interest_after'	=>  $new_sub_interest_amount,
				   						'total_payment_after'	=>	$new_sub_principle,
				   						'penelize'				=>	$new_sub_penelize,
				   						'principle_after'		=>	$new_sub_principle,
				   						'service_charge'		=>	$new_sub_service_charge,
				   						'payment_option'		=>	1
				   				);
				   				$this->_name="ln_loanmember_funddetail";
				   				$where = $db->quoteInto("id=?", $data["mfdid_".$i]);
				   				$db->getProfiler()->setEnabled(true);
				   				
				   				$this->update($arr_update_fun_detail, $where);
				   				
				   				Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
				   				Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
				   				$db->getProfiler()->setEnabled(false);
			   				}
    					}else{
    						
    						$sql_loan_fun = "SELECT 
											  lf.`id` ,
											  lf.`total_principal`,
											  lf.`principle_after`,
											  lf.`total_interest_after`,
											  lf.`service_charge`,
											  lf.`penelize`
											FROM
											  `ln_loanmember_funddetail` AS lf,
											  `ln_loan_member` AS lm 
											WHERE lf.`member_id` = lm.`member_id`      
  												AND lm.`loan_number` = '$loan_number' 
    											AND lf.`date_payment` = '$date_payment'";
    						$row_fun = $db->fetchAll($sql_loan_fun);
    						$is_set=0;
    						foreach ($row_fun as $rs_fun){
    							$arr_update_fun_detail = array(
    									'is_completed'			=> 	1,
    									'payment_option'		=>	$data["option_pay"]
    							);
    							$this->_name="ln_loanmember_funddetail";
    							$where = $db->quoteInto("id=?", $rs_fun['id']);
    							$db->getProfiler()->setEnabled(true);
    							 
    							$this->update($arr_update_fun_detail, $where);
    							 
    							Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
    							Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
    							$db->getProfiler()->setEnabled(false);
    						}
    					}
		   				
		   				$sql_payment ="SELECT
						   					l.*
						   				FROM
							   				`ln_loanmember_funddetail` AS l,
							   				`ln_loan_member` AS m
						   				WHERE l.`member_id` = m.`member_id`
							   				AND m.`loan_number` = '$loan_number'
							   				AND l.`is_completed` = 0 ";
		   				$rs_payment = $db->fetchRow($sql_payment);
		   				
		   				$group_id = $data["client_code"];
		   				if(empty($rs_payment)){
			   				$sql ="UPDATE
					   					`ln_loan_group` AS l
					   				SET l.`status` = 2
					   				WHERE l.`g_id`= (SELECT m.`group_id` FROM `ln_loan_member` AS m WHERE m.`loan_number`='$loan_number' LIMIT 1)
					   					AND l.`group_id`= $group_id AND l.`loan_type`=2";
			   				$db->getProfiler()->setEnabled(true);
			   				$db->query($sql);
			   				
			   				Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
			   				Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
			   				$db->getProfiler()->setEnabled(false);
			   				
			   				$sql_loan_memeber ="UPDATE `ln_loan_member` AS m SET m.`is_completed`=1 WHERE m.`loan_number`= '$loan_number'";
			   				
			   				$db->getProfiler()->setEnabled(true);
			   				$db->query($sql_loan_memeber);
			   				
			   				Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
			   				Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
			   				$db->getProfiler()->setEnabled(false);
		   				}
    			}
    		}
//     		exit();
    		$db->commit();
    	}catch (Exception $e){
    		$db->rollBack();
    		echo $e->getMessage();
    		Application_Model_DbTable_DbUserLog::writeMessageError($e->getMessage());
    	}
    }