public function editgroupAction() { // check group head , and members are correct if ($this->_request->getParam('error')) { // display error message for wrong head selection $error = $this->_request->getParam('error'); if ($error == 1) { $this->view->error = "Improper Group head selection ! "; } if ($error == 2) { $this->view->error = "Chose single member in a family ! "; } if ($error == 3) { $this->view->error = "Improper Group representatives selection ! "; } if ($error == 4) { $this->view->error = "Maximum 3 members can be a representative in a single group ! "; } if ($error == 5) { $this->view->error = "Chose Bank branch name"; } } $app = $this->view->baseUrl(); $group_id = $this->_getParam('id'); $this->view->groupid = $group_id; $this->view->title = "Edit Group Details"; // create instance for form page with baseurl $addForm = new Groupmdefault_Form_groupdefault($app); $days = $this->view->adm->viewRecord("ourbank_master_weekdays", "id", "ASC"); foreach ($days as $day) { $addForm->day->addMultiOption($day['id'], $day['name']); } $bank = $this->view->adm->viewRecord("ourbank_master_bank", "id", "ASC"); /* foreach($bank as $banks) { $addForm->bank->addMultiOption($banks['id'],$banks['name']); }*/ $branch = $this->view->adm->viewRecord("ourbank_master_branch", "id", "ASC"); foreach ($branch as $branch) { $addForm->branch->addMultiOption($branch['id'], $branch['name']); } $addForm->Submit->setLabel('Update'); $this->view->form = $addForm; $dbobject = new Groupmdefault_Model_Groupdefault(); $hierarchy = $dbobject->getofficehierarchy(); foreach ($hierarchy as $hiearchyids) { $hiearchyid = $hiearchyids['hierarchyid']; } // load office id $officedetails = $this->view->adm->getRecord('ourbank_office', 'officetype_id', $hiearchyid); foreach ($officedetails as $officeiddetails) { $addForm->office->addMultiOption($officeiddetails['id'], $officeiddetails['name']); } $dbobj = new Groupcommonview_Model_groupcommon(); $result = $dbobj->getgroup($group_id); $convertdate = new App_Model_dateConvertor(); // assign values with respective form fields foreach ($result as $group) { $this->view->grouptype = $grouptype = substr($group['groupcode'], 4, 1); $this->view->officeid = $group['officeid']; $addForm->offedit->setValue($group['officename']); $addForm->offeditv->setValue($group['officeid']); $addForm->groupname->setValue($group['groupname']); $addForm->bank->setValue($group['bank_id']); $addForm->branch->setValue($group['branch_id']); $addForm->savingamt->setValue($group['saving_perweek']); $addForm->penaltylate->setValue($group['penalty_latecoming']); $addForm->penaltyabsence->setValue($group['penalty_notcoming']); $addForm->interest->setValue($group['rateinterest']); $addForm->place->setValue($group['place']); $addForm->times->setValue($group['time']); $addForm->day->setValue($group['days']); $addForm->Created_Date->setValue($convertdate->phpnormalformat($group['group_created_date'])); } $dbobj = new Groupmdefault_Model_Groupdefault(); $officeid = $group['officeid']; $banks = $dbobj->Getbank($officeid); // load applicable to values foreach ($banks as $banks) { $addForm->bank->addMultiOption($banks['id'], $banks['name']); } // enable javascript function to load groupmembers echo "<script>getMember('" . $group['officeid'] . "','" . $app . "','" . $group['groupid'] . "','" . $grouptype . "');</script>"; $gacc = array(); $gmembersacc = array(); if ($this->_request->isPost() && $this->_request->getPost('Submit')) { $mem = $this->_request->getPost('member_id'); // get selected members $groupmembersid = $this->view->adm->getRecord('ourbank_groupmembers', 'group_id', $this->view->groupid); // Fetch group members foreach ($groupmembersid as $groupmembers) { $macc = $dbobject->Getaccdetails($groupmembers['member_id']); // Get account id from accounts table foreach ($macc as $memberaccount) { $acc = $memberaccount['id']; // get account id $gacc[] = $acc; $savingdetails = $dbobject->getsavings($acc); // get savings details foreach ($savingdetails as $saving) { if ($saving['Amount'] > 0) { $gmembersacc[] = $groupmembers['member_id']; } } } } if ($gmembersacc) { foreach ($gmembersacc as $gmacc) { $meminfor = $this->view->adm->getRecord('ourbank_familymember', 'id', $gmacc); foreach ($meminfor as $membersinfo) { echo "<font color = 'green' ><b>" . $membersinfo['name'] . "</b> <br> </font>"; } } echo "<font color ='red'> <b>These group members are having valid accounts. you cannot edit the group members.. </b></font>"; } else { $group_head = $_POST['memberhead']; // get group head $representative_id = $_POST['representatives']; $countreps = count($representative_id); $result = ""; $memberids = array(); $famid = array(); $memid = array(); $countvalues = array(); foreach ($mem as $memberid) { $memberids[] = explode('_', $memberid); } foreach ($memberids as $Memberids) { $famid[] = $Memberids[0]; $memid[] = $Memberids[1]; } $result = array_diff($representative_id, $memid); $error = 0; if (in_array($group_head, $memid)) { $results = "ok"; if ($result) { $results = "not ok"; $error = "3"; } if ($countreps > 3) { $results = "not ok"; $error = "4"; } if (!$branch) { $error = "5"; $results = "not ok"; } else { $countvalues[] = array_count_values($famid); foreach ($countvalues[0] as $key => $value) { if ($value > 1) { $results = "not ok"; $error = "2"; } } } } else { $error = "1"; } if ($results == "ok" && $error == 0) { // if ok then get all input values $office_id = $this->_request->getParam('offeditv'); $groupname = $this->_request->getParam('groupname'); $bank = $this->_request->getParam('bank'); $branch = $this->_request->getParam('branch'); $createddate = $this->_request->getParam('Created_Date'); // $latitude = $this->_request->getParam('latitude'); // $longitude = $this->_request->getParam('longitude'); $savingamt = $this->_request->getParam('savingamt'); $penaltyabsence = $this->_request->getParam('penaltyabsence'); $penaltylate = $this->_request->getParam('penaltylate'); $interest = $this->_request->getParam('interest'); $place = $this->_request->getParam('place'); $times = $this->_request->getParam('times'); $day = $this->_request->getParam('day'); $convertdate = new App_Model_dateConvertor(); $createddate = $convertdate->phpmysqlformat($createddate); $date = date("y/m/d H:i:s"); // updation and insertion in Accounts table foreach ($gacc as $gaccountid) { } //get the account id $tagacc = $this->view->adm->getsingleRecord('ourbank_accounts', 'tag_account', 'id', $gaccountid); $data = array('tag_account' => 0, 'status_id' => 0); foreach ($gacc as $gaccountid) { //get the account id $where = array('id = ' . $gaccountid, 'membertype_id = 1'); $dbobject->updateaccount('ourbank_accounts', $data, $where); // make tag account and status id as zero } $individualtypeid = $this->view->adm->getsingleRecord('ourbank_master_membertypes', 'id', 'type', 'Individual'); // get individual type id $productid = $dbobject->getProductid(); $productcode = $productid . 'S'; // // insert accounts value for group members foreach ($memid as $Memid) { $account_ids = $this->view->adm->addRecord("ourbank_accounts", array('id' => '', 'membertype_id' => $individualtypeid, 'begin_date' => $date, 'tag_account' => $tagacc, 'accountcreated_date' => $date, 'created_date' => $createddate, 'created_by' => $this->view->createdby, 'status_id' => 1)); // insert some value to accounts table // // create account number <!--(3)office id--(2)individualtype--(3)productoffer with saving code(6)accountid!> $accountNumber = str_pad($office_id, 3, "0", STR_PAD_LEFT) . str_pad($individualtypeid, 2, "0", STR_PAD_LEFT) . str_pad($productcode, 3, "0", STR_PAD_LEFT) . str_pad($account_ids, 6, "0", STR_PAD_LEFT); $this->view->adm->updateRecord("ourbank_accounts", $account_ids, array('account_number' => $accountNumber, 'member_id' => $Memid, 'product_id' => $productid)); } $groupdetails = $dbobject->getgroupdetails($group_id); // get group details for particular id $this->view->adm->addRecord("ourbank_group_log", $groupdetails[0]); // add group details to log table $glidforabsense = $this->view->adm->getsingleRecord('ourbank_glsubcode', 'id', 'header', 'Absense'); $glidforlate = $this->view->adm->getsingleRecord('ourbank_glsubcode', 'id', 'header', 'Late'); $this->view->adm->updateRecord("ourbank_group", $group_id, array('village_id' => $office_id, 'bank_id' => $bank, 'branch_id' => $branch, 'name' => $groupname, 'saving_perweek' => $savingamt, 'penalty_notcoming' => $penaltyabsence, 'penalty_latecoming' => $penaltylate, 'late_subglcode' => $glidforlate, 'absent_subglcode' => $glidforabsense, 'rateinterest' => $interest, 'place' => $place, 'time' => $times, 'days' => $day, 'head' => $group_head, 'group_created_date' => $date, 'created_by' => $this->view->createdby, 'created_date' => $createddate)); // update group details $groupmemberdetails = $this->view->adm->getRecord('ourbank_groupmembers', 'group_id', $group_id); // get groupmembers details for particular id foreach ($groupmemberdetails as $groupmemberDetails) { $this->view->adm->addRecord("ourbank_groupmembers_log", array('record_id' => '', 'id' => $groupmemberDetails['id'], 'group_id' => $groupmemberDetails['group_id'], 'member_id' => $groupmemberDetails['member_id'], 'groupmember_status' => $groupmemberDetails['groupmember_status'])); } // add group members details to log table $dbobject->UpdateGroupdetails($group_id); // insert group members foreach ($memid as $memberid) { $this->view->adm->addRecord("ourbank_groupmembers", array('id' => '', 'group_id' => $group_id, 'member_id' => $memberid, 'groupmember_status' => 3)); } $grouprepdetails = $this->view->adm->getRecord('ourbank_group_representatives', 'group_id', $group_id); // get groupmembers details for particular id foreach ($grouprepdetails as $grouprepmemDetails) { $this->view->adm->addRecord("ourbank_group_representatives_log", array('record_id' => '', 'id' => $grouprepmemDetails['id'], 'group_id' => $grouprepmemDetails['group_id'], 'representative_id' => $grouprepmemDetails['representative_id'])); } // add group Representative members details to log table $dbobject->UpdateGroupreps($group_id); foreach ($representative_id as $representatives) { $this->view->adm->addRecord("ourbank_group_representatives", array('id' => '', 'group_id' => $group_id, 'representative_id' => $representatives)); ////add representatives with its group id ->($groupid) } $this->_redirect('groupcommonview/index/commonview/id/' . $group_id); } else { // display error message for wrong group head selection $this->_redirect('groupmdefault/index/editgroup/id/' . $group_id . '/error/' . $error); } } } }