<commit_before><?php

class page_Accounts_FixedAndMis extends Page {
	function init(){
		parent::init();
		$this->add('Controller_Acl');

		$crud=$this->add('xCRUD',array('grid_class'=>'Grid_Account','add_form_beautifier'=>false));
		$account_fixedandmis_model = $this->add('Model_Account_FixedAndMis');
		$account_fixedandmis_model->add('Controller_Acl');
		$account_fixedandmis_model->setOrder('id','desc');
		$self=$this;
		$crud->addHook('myupdate',function($crud,$form)use($self){
			if($crud->isEditing('edit')) return false;
			
			$fixedAndMis_account_model = $crud->add('Model_Account_FixedAndMis');
			$sm_model=$self->add('Model_Account_SM');
				$sm_model->addCondition('member_id',$form['member_id']);
				$sm_model->tryLoadAny();
				if(!$sm_model->loaded()){
					$form->displayError('member',"Member Does not have SM Account");
				}
			try {
				$crud->api->db->beginTransaction();

					if($form['account_type']=='MIS' and !$form['intrest_to_account_id']){
						$form->displayError('intrest_to_account_id','Field is must for MIS type accounts');
					}

					if(!$form['debit_account']) $form->displayError('debit_account','Please specify account');

					$account = $crud->add('Model_Account');
					$account->loadBy('AccountNumber',$form['debit_account']);

					$member_ids_array=[];
					$member_ids_array[] = $form['member_id'];
					
					if($form['member_ID_2']) $member_ids_array[] =$form['member_ID_2'];
					if($form['member_ID_3']) $member_ids_array[] =$form['member_ID_3'];
					if($form['member_ID_4']) $member_ids_array[] =$form['member_ID_4'];

					if($account['SchemeType']==ACCOUNT_TYPE_SAVING and !in_array($account['member_id'], $member_ids_array)){
						$form->displayError('debit_account','Account must be of same member');
					}

					$intrest_to_account_model = $crud->add('Model_Account');
					$intrest_to_account_model->addCondition('id',$form['intrest_to_account_id']);
					$intrest_to_account_model->tryLoadAny();
					if($form['intrest_to_account_id'] AND $intrest_to_account_model['member_id'] != $form['member_id']){
						$form->displayError('intrest_to_account_id','Not for same member ');
					}
					if($form['NomineeAge'] And  $form['NomineeAge']<18 And $form['MinorNomineeParentName']==""){
						$form->displayError('MinorNomineeParentName','mandatory field');
					}
					if($form['MaturityToAccount_id']){
						$maturity_to_account_model = $crud->add('Model_Account');
						$maturity_to_account_model->addCondition('id',$form['MaturityToAccount_id']);
						$maturity_to_account_model->tryLoadAny();
						if($maturity_to_account_model['member_id'] != $form['member_id']){<commit_msg>Allow all members that are even joint member in saving account<commit_after><?php

class page_Accounts_FixedAndMis extends Page {
	function init(){
		parent::init();
		$this->add('Controller_Acl');

		$crud=$this->add('xCRUD',array('grid_class'=>'Grid_Account','add_form_beautifier'=>false));
		$account_fixedandmis_model = $this->add('Model_Account_FixedAndMis');
		$account_fixedandmis_model->add('Controller_Acl');
		$account_fixedandmis_model->setOrder('id','desc');
		$self=$this;
		$crud->addHook('myupdate',function($crud,$form)use($self){
			if($crud->isEditing('edit')) return false;
			
			$fixedAndMis_account_model = $crud->add('Model_Account_FixedAndMis');
			$sm_model=$self->add('Model_Account_SM');
				$sm_model->addCondition('member_id',$form['member_id']);
				$sm_model->tryLoadAny();
				if(!$sm_model->loaded()){
					$form->displayError('member',"Member Does not have SM Account");
				}
			try {
				$crud->api->db->beginTransaction();

					if($form['account_type']=='MIS' and !$form['intrest_to_account_id']){
						$form->displayError('intrest_to_account_id','Field is must for MIS type accounts');
					}

					if(!$form['debit_account']) $form->displayError('debit_account','Please specify account');

					$account = $crud->add('Model_Account');
					$account->loadBy('AccountNumber',$form['debit_account']);

					$member_ids_filled=[];
					$member_ids_filled[] = $form['member_id'];
					
					if($form['member_ID_2']) $member_ids_filled[] =$form['member_ID_2'];
					if($form['member_ID_3']) $member_ids_filled[] =$form['member_ID_3'];
					if($form['member_ID_4']) $member_ids_filled[] =$form['member_ID_4'];

					$member_ids_of_saving_account = [$account['member_id']];

					foreach ($account->ref('JointMember') as $jm) {
						$member_ids_of_saving_account[] =$jm['member_id'];
					}

					if($account['SchemeType']==ACCOUNT_TYPE_SAVING and !count(array_intersect($member_ids_of_saving_account, $member_ids_filled))){
						$form->displayError('debit_account','Account must be of same member');
					}

					$intrest_to_account_model = $crud->add('Model_Account');
					$intrest_to_account_model->addCondition('id',$form['intrest_to_account_id']);
					$intrest_to_account_model->tryLoadAny();
					if($form['intrest_to_account_id'] AND $intrest_to_account_model['member_id'] != $form['member_id']){
						$form->displayError('intrest_to_account_id','Not for same member ');
					}
					if($form['NomineeAge'] And  $form['NomineeAge']<18 And $form['MinorNomineeParentName']==""){
						$form->displayError('MinorNomineeParentName','mandatory field');
					}
					if($form['MaturityToAccount_id']){
						$maturity_to_account_model = $crud->add('Model_Account');
						$maturity_to_account_model->addCondition('id',$form['MaturityToAccount_id']);
						$maturity_to_account_model->tryLoadAny();
						if($maturity_to_account_model['member_id'] != $form['member_id']){
{'fraction_non_alphanumeric': 0.18466522678185746, 'fraction_numerical': 0.0028797696184305254, 'mean_word_length': 6.198186528497409, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4985412', 'n_tokens_mistral': 2288, 'n_tokens_neox': 1893, 'n_words': 213}