예제 #1
0
	function getAllLoanHasPayedAction(){
		if($this->getRequest()->isPost()){
			$data = $this->getRequest()->getPost();
			$db = new Loan_Model_DbTable_DbGroupPayment();
			$row = $db->getAllLoanHasPayed($data);
			print_r(Zend_Json::encode($row));
			exit();
		}
	}
예제 #2
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();
		
	}
}   
예제 #3
0
	function cancelIlPayment(){
// 		$db = new Loan_Model_DbTable_DbLoanILPayment();
		$db = new Loan_Model_DbTable_DbGroupPayment();
		if($this->getRequest()->isPost()){
			$_data = $this->getRequest()->getPost();
			$identity = $_data["identity"];
			try {
				$row = $db->cancelIlPayment($_data);
				print_r(Zend_Json::encode($row));
				exit();
			}catch (Exception $e) {
				$err =$e->getMessage();
				Application_Model_DbTable_DbUserLog::writeMessageError($err);
			}
		}
	}
예제 #4
0
	public function AdvanceSearch ($data=null){
		$request=Zend_Controller_Front::getInstance()->getRequest();
		$db = new Loan_Model_DbTable_DbGroupPayment();
		
		$payment_type = new Zend_Dojo_Form_Element_FilteringSelect("paymnet_type");
		$payment_type->setAttribs(array('class'=>'fullside','dojoType'=>'dijit.form.FilteringSelect'));
		$options= array(''=>'ប្រភេទបង់ប្រាក់',1=>'បង់ធម្មតា',2=>'បង់មុន',3=>'បង់រំលោះប្រាក់ដើម');
		$payment_type->setMultiOptions($options);
		$payment_type->setValue($request->getParam("paymnet_type"));
		
		$branch = new Zend_Dojo_Form_Element_FilteringSelect("branch_id");
		$branch->setAttribs(array('class'=>'fullside','dojoType'=>'dijit.form.FilteringSelect'));
		$opt_branch = array(-1=>'ជ្រើសរើស សាខា');
		$dbs = new Application_Model_DbTable_DbGlobal();
		$rows = $dbs->getAllBranchName();
			if(!empty($rows))foreach($rows AS $row){
				$opt_branch[$row['br_id']]=$row['branch_namekh'];
			}
		$branch->setMultiOptions($opt_branch);
		$branch->setValue($request->getParam("branch_id"));
		
		
		$advnceSearch = new Zend_Dojo_Form_Element_TextBox("advance_search");
		$advnceSearch->setAttribs(array('class'=>'fullside'
				,'dojoType'=>'dijit.form.TextBox'
				,'placeholder'=>$this->tr->translate("ADVANCE_SEARCH")));
		
		$client_name = new Zend_Dojo_Form_Element_FilteringSelect("client_name");
		$opt_client = array(''=>'ជ្រើសរើស ឈ្មោះអតិថិជន');
		$rows = $db->getIndividuleClient();
		if(!empty($rows))foreach($rows AS $row){
			$opt_client[$row['id']]=$row['name'];
		}
		$client_name->setMultiOptions($opt_client);
		$client_name->setAttribs(array('class'=>'fullside','dojoType'=>'dijit.form.FilteringSelect'));
		
		$g_client_name = new Zend_Dojo_Form_Element_FilteringSelect("g_client_name");
		$opt_client = array(''=>'ជ្រើសរើស ឈ្មោះអតិថិជន');
		$rows = $db->getAllClient();
		if(!empty($rows))foreach($rows AS $row){
			$opt_client[$row['id']]=$row['name'];
		}
		$g_client_name->setMultiOptions($opt_client);
		$g_client_name->setAttribs(array('class'=>'fullside','dojoType'=>'dijit.form.FilteringSelect'));
		
		$_coid = new Zend_Dojo_Form_Element_FilteringSelect('co_id');
		$_coid->setAttribs(array(
				'dojoType'=>'dijit.form.FilteringSelect',
				'onchange'=>'popupCheckCO();',
				'class'=>'fullside'
		));
		$options = $dbs->getAllCOName(1);
		$_coid->setMultiOptions($options);
		$_coid->setValue($request->getParam("co_id"));
		
		
		$start_date = new Zend_Dojo_Form_Element_DateTextBox("start_date");
		$start_date->setAttribs(array('class'=>'fullside','dojoType'=>'dijit.form.DateTextBox','placeholder'=>$this->tr->translate("ចាប់ពីថ្ងៃ")));
		//$start_date->setValue($date);
		$_date = $request->getParam("start_date");
		if(empty($_date)){
			$_date = date('Y-m-d');
		}
		$start_date->setValue($_date);
		
		$date = date("y-m-d");
		$end_date = new Zend_Dojo_Form_Element_DateTextBox("end_date");
		$end_date->setAttribs(array('class'=>'fullside','dojoType'=>'dijit.form.DateTextBox','placeholder'=>$this->tr->translate("រហូតដល់ថ្ងៃ")));
		//$end_date->setValue($date);
		
		$_date = $request->getParam("end_date");
		if(empty($_date)){
			$_date = date('Y-m-d');
		}
		$end_date->setValue($_date);
		
		$status = new Zend_Dojo_Form_Element_FilteringSelect("status");
		$status->setAttribs(array('class'=>'fullside','dojoType'=>'dijit.form.FilteringSelect','placeholder'=>$this->tr->translate("ស្ថានការ")));
		$opt_status = array(''=>'ជ្រើសរើស ស្ថានការ','1'=>'ដំណើការ','2'=>'មិនដំណើការ');
		$status->setMultiOptions($opt_status);
		
		$submit = new Zend_Dojo_Form_Element_SubmitButton("btn_submit");
		$submit->setAttribs(array('dojoType'=>'dijit.form.Button',
				'iconclass'=>'dijitIconSearch',
				'label'=>'Search'));
		$advnceSearch->setValue($request->getParam("advance_search"));
		$client_name->setValue($request->getParam("client_name"));
		//$start_date->setValue($request->getParam("start_date"));
		//$end_date->setValue($request->getParam("end_date"));
		$status->setValue($request->getParam("status"));
		
		$_currency_type = new Zend_Dojo_Form_Element_FilteringSelect('currency_type');
		$_currency_type->setAttribs(array(
				'dojoType'=>'dijit.form.FilteringSelect',
		));
		$opt = array(-1=>"--Select Currency Type--",2=>"Dollar",1=>'Khmer',3=>"Bath");
		$_currency_type->setMultiOptions($opt);
		$_currency_type->setValue($request->getParam("currency_type"));
		if($data!=null){
			$advnceSearch->setValue($request->getParam("advance_search"));
			$client_name->setValue($request->getParam("client_name"));
			$start_date->setValue($request->getParam("start_date"));
			$end_date->setValue($request->getParam("end_date"));
			$status->setValue($request->getParam("status"));
			
		}
		$this->addElements(array($g_client_name,$_currency_type,$payment_type,$_coid,$branch,$submit,$advnceSearch,$client_name,$start_date,$end_date,$status));
		return $this;
		
	}	
예제 #5
0
    function cancelPaymnet($data){
    	$db = $this->getAdapter();
    	$db_recipt= new Loan_Model_DbTable_DbGroupPayment();
    	$db->beginTransaction();
    	try{
    		$id = $data["id"];
    		$loan_number = $data["old_loan_number"];
    			
    		$sql_option = "SELECT cr.`payment_option`,cr.`recieve_amount`,cr.`total_payment` FROM `ln_client_receipt_money` AS cr WHERE cr.`id`=$id";
    		$rs = $db->fetchRow($sql_option);
    		$rs_fun = $db_recipt->getFunDetailByLoanNumber($loan_number);
    		$rs_recipt = $db_recipt->getReciptDetailById($id);
    		print_r($rs_recipt);
    		if($rs_fun=="" or $rs_fun==null){
    			$loan_number = $data["old_loan_number"];
    			$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);
    			
    			$sql_group = "SELECT m.`group_id` FROM `ln_loan_member` AS m WHERE m.`loan_number`='$loan_number' LIMIT 1";
    			$rs_group = $db->fetchOne($sql);
    			
    			$arr_group = array(
    					'status'	=> 1,
    			);
    			$this->_name = "ln_loan_group";
    			$where = $db->quoteInto("g_id=?", $rs_group["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);
    			
	    		foreach ($rs_recipt as $row_recipt){
	    			$arr_fun = array(
	    				'is_completed'	=>0, 
	    			);
	    			$this->_name="`ln_loanmember_funddetail`";
	    			$where = $db->quoteInto("id=?", $row_recipt["lfd_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{
    			if($rs["payment_option"]==1){
    				foreach ($rs_recipt as $row_recipt){
    					$fun_id = $row_recipt['lfd_id'];
    					$sql = "SELECT * FROM ln_loanmember_funddetail WHERE id= $fun_id";
    					$result_fun = $db->fetchAll($sql);
//     					print_r($result_fun);
    					$fun = $db_recipt->getFunHasPayedByLoanNumber($row_recipt["lfd_id"]);
    					foreach ($result_fun as $result_row){
    						$fun_penelize = $result_row["penelize"];
    						$fun_service = $result_row["service_charge"];
	    					if($fun["is_completed"]==0){
	    							$total_pay = $row_recipt["total_payment"]; 
	    							$total_recieve = $row_recipt["total_recieve"];
	    							$principle = $row_recipt["principal_permonth"];
	    							$interest = $row_recipt["total_interest"];
	    							$penelize = $row_recipt["penelize_amount"];
	    							$service =$row_recipt["service_charge"];
	    							
	    							$new_recieve = $total_recieve-$service;
	    							if($new_recieve>0){
	    								$old_service =0;
	    								$new_recieve = $new_recieve-$penelize;
	    								if($new_recieve>0){
	    									$old_penelize =0;
// 	    									$new_recieve = $new_recieve - $interest;
// 	    									if($new_recieve>0){
// 	    										$old_interest = 0;
// 	    										$new_recieve = $new_recieve - $penelize;
// 	    										if($new_recieve>0){
// 	    											$old_principle = 0;
// 	    										}
// 	    									}else{
// 	    										$old_interest = abs($new_recieve);
// 	    									}
	    								}else{
	    									$old_penelize = abs($new_recieve);
	    								}
	    							}else{
	    								$old_service = abs($new_recieve);
	    								
	    							}
// 	    							$old_penelize = round($total_pay,2)-(round($principle,2)+round($interest,2)+round($penelize,2));
// 	    							$old_service = round($total_pay,2)-(round($principle,2)+round($interest,2)+round($penelize,2));
// 	    							echo $a= $principle+$penelize+$interest+$service;
// 	    							echo $old_penelize."=".$total_pay."-".$principle."+".$interest."+".$service;
	    							$arr_fun = array(
	    								"principle_after" 		=> $principle,
	    								'total_interest_after'	=>	$interest,
	    								'penelize'				=> $fun_penelize-$old_penelize,
	    								'service_charge'		=> $fun_service-$old_service,
	    								'total_payment_after'	=> $principle+$interest+($fun_penelize-$old_penelize)+($fun_service-$old_service),
	    							);
	    							$this->_name = "ln_loanmember_funddetail";
	    							$where = $db->quoteInto("id=?", $row_recipt["lfd_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{
	    						
	    						foreach ($rs_recipt as $row_recipt){
	    							$total_pay = $row_recipt["total_payment"];
	    							$principle = $row_recipt["principal_permonth"];
	    							$interest = $row_recipt["total_interest"];
	    							$penelize = $row_recipt["penelize_amount"];
	    							$service =$row_recipt["service_charge"];
	    								
	    							$arr_fun = array(
// 	    									"principle_after" 		=> $principle,
// 	    									'total_interest_after'	=>	$interest,
// 	    									'penelize'				=> $penelize,
// 	    									'service_charge'		=>	$service,
// 	    									'total_payment_after'	=> $total_pay,
	    									'is_completed'			=>	0,
	    							);
	    							$this->_name = "ln_loanmember_funddetail";
	    							$where = $db->quoteInto("id=?", $row_recipt["lfd_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{
    				foreach ($rs_recipt as $row_recipt){
		    			$arr_fun = array(
		    				'is_completed'	=>	0, 
		    			);
		    			$this->_name="ln_loanmember_funddetail";
		    			$where = $db->quoteInto("id=?", $row_recipt["lfd_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);
	    			}
    			}
    		}
    		$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();
    		Application_Model_DbTable_DbUserLog::writeMessageError($e->getMessage());
    	}
    }