Ejemplo n.º 1
0
 public function groupaccountAction()
 {
     $dbobj = new Groupmdefault_Model_Groupdefault();
     $result = "";
     $member_id = $_POST['member_id'];
     $group_head = $_POST['memberhead'];
     $representative_id = $_POST['representatives'];
     //         $latitude = $this->_request->getParam('latitude');
     //         $longitude = $this->_request->getParam('longitude');
     $grouptypeid = $this->_request->getParam('grouptype');
     $membertypeid = $grouptypeid;
     $office_id = $this->_request->getParam('office');
     $groupname = $this->_request->getParam('groupname');
     $createddate = $this->_request->getParam('Created_Date');
     $savingamt = $this->_request->getParam('savingamt');
     $bank = $this->_request->getParam('bank');
     $branch = $this->_request->getParam('branch');
     $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');
     $sessionName = new Zend_Session_Namespace('groupsession');
     if ($grouptypeid) {
         $sessionName->__set('grouptype', $grouptypeid);
     }
     if ($office_id) {
         $sessionName->__set('office', $office_id);
     }
     if ($groupname) {
         $sessionName->__set('groupname', $groupname);
     }
     if ($bank) {
         $sessionName->__set('bank', $bank);
     }
     if ($createddate) {
         $sessionName->__set('Created_Date', $createddate);
     }
     // if($latitude){
     //                     $sessionName->__set('latitude',$latitude);
     // // }
     // if($longitude){
     //                     $sessionName->__set('longitude',$longitude);
     // }
     if ($savingamt) {
         $sessionName->__set('savingamt', $savingamt);
     }
     if ($penaltyabsence) {
         $sessionName->__set('penaltyabsence', $penaltyabsence);
     }
     if ($penaltylate) {
         $sessionName->__set('penaltylate', $penaltylate);
     }
     if ($interest) {
         $sessionName->__set('interest', $interest);
     }
     if ($place) {
         $sessionName->__set('place', $place);
     }
     if ($times) {
         $sessionName->__set('times', $times);
     }
     if ($day) {
         $sessionName->__set('day', $day);
     }
     $headers = array('Absense', 'Late');
     $description = array('Penalty for absense', 'Penalty for late');
     $countreps = count($representative_id);
     $memberids = array();
     $famid = array();
     $memid = array();
     $countvalues = array();
     foreach ($member_id as $memberid) {
         $memberids[] = explode('_', $memberid);
     }
     foreach ($memberids as $Memberids) {
         $famid[] = $Memberids[0];
         $memid[] = $Memberids[1];
     }
     $results = array_diff($representative_id, $memid);
     $error = 0;
     if (in_array($group_head, $memid)) {
         $result = "ok";
         if ($results) {
             $error = "3";
             $result = "not ok";
         }
         if ($countreps > 3) {
             $error = "4";
             $result = "not ok";
         }
         if (!$branch) {
             $error = "5";
             $result = "not ok";
         } else {
             $countvalues[] = array_count_values($famid);
             foreach ($countvalues[0] as $key => $value) {
                 if ($value > 1) {
                     $result = "not ok";
                     $error = "2";
                 }
             }
         }
     } else {
         $error = "1";
     }
     if ($result == "ok" && $error == 0) {
         $date = date("y/m/d H:i:s");
         //         // if ok get all input values
         $penalglcode = $dbobj->getpenaltyglcode(4, 'recurring deposit');
         if ($penalglcode->glcode == null) {
             $this->view->adm->addRecord('ourbank_glcode', array('id' => '', 'glcode' => 'L01000', 'ledgertype_id' => 4, 'header' => 'recurring deposit', 'description' => 'recurring deposit', 'created_date' => $date, 'created_by' => $this->view->createdby));
         }
         $penalglcode = $dbobj->getpenaltyglcode(4, 'recurring deposit');
         $bglcode = $penalglcode->glcode;
         $glcodeid = $penalglcode->glcodeid;
         $ini = substr($bglcode, 0, 1);
         $mid = substr($bglcode, 1, 2);
         $midportion = $ini . $mid;
         $last = substr($bglcode, 3, 3);
         $last += 1;
         $last1 = str_pad($last, 3, 0, STR_PAD_LEFT);
         $glsubcode[0] = $midportion . $last1;
         $last += 1;
         $last = str_pad($last, 3, 0, STR_PAD_LEFT);
         $glsubcode[1] = $midportion . $last;
         for ($l = 0; $l < 2; $l++) {
             $penalglcodes = $dbobj->checkavailid($headers[$l]);
             if (!$penalglcodes) {
                 $dbobj->insertGlsubcode(array('id' => '', 'office_id' => $office_id, 'glsubcode' => $glsubcode[$l], 'glcode_id' => $glcodeid, 'subledger_id' => 4, 'header' => $headers[$l], 'description' => $description[$l], 'created_date' => date('Y-m-d'), 'created_by' => $this->view->createdby));
             }
         }
         $glidforabsense = $this->view->adm->getsingleRecord('ourbank_glsubcode', 'id', 'header', 'Absense');
         $glidforlate = $this->view->adm->getsingleRecord('ourbank_glsubcode', 'id', 'header', 'Late');
         $convertdate = new App_Model_dateConvertor();
         $createddate = $convertdate->phpmysqlformat($createddate);
         $date = date("y/m/d H:i:s");
         //             // validate the group name if name exists or not
         $validator = new Zend_Validate_Db_RecordExists('ourbank_group', 'name');
         if ($validator->isValid($groupname)) {
             $messages = $validator->getMessages();
             $this->view->errorgroupname = $groupname . 'Already Existed';
             // if name exists display error message
         } else {
             $groupid = $this->view->adm->addRecord("ourbank_group", array('name' => $groupname, 'bank_id' => $bank, 'branch_id' => $branch, 'saving_perweek' => $savingamt, 'penalty_notcoming' => $penaltyabsence, 'penalty_latecoming' => $penaltylate, 'late_subglcode' => $glidforabsense, 'absent_subglcode' => $glidforlate, 'rateinterest' => $interest, 'place' => $place, 'time' => $times, 'days' => $day));
             // Insert group name and get pk id
             //             // generate group code
             $groupcode = str_pad($office_id, 3, "0", STR_PAD_LEFT) . "0" . $grouptypeid . str_pad($groupid, 6, "0", STR_PAD_LEFT);
             //             // update rest of group values
             $this->view->adm->updateRecord("ourbank_group", $groupid, array('village_id' => $office_id, 'head' => $group_head, 'groupcode' => $groupcode, 'group_created_date' => $date, 'created_by' => $this->view->createdby, 'created_date' => $createddate));
             /* Group created date -> Including timestamp , Created date should contain date only*/
             foreach ($memid as $Memid) {
                 $this->view->adm->addRecord("ourbank_groupmembers", array('id' => '', 'group_id' => $groupid, 'member_id' => $Memid, 'groupmember_status' => 3));
                 ////add groupmembers with its group id ->($groupid)
             }
             foreach ($representative_id as $representatives) {
                 $this->view->adm->addRecord("ourbank_group_representatives", array('id' => '', 'group_id' => $groupid, 'representative_id' => $representatives));
                 ////add representatives with its group id ->($groupid)
             }
             // //             $membertypeid = $this->view->adm->getsingleRecord('ourbank_master_membertypes','id','type','Group');
             $account_id = $this->view->adm->addRecord("ourbank_accounts", array('id' => '', 'membertype_id' => $membertypeid, 'begin_date' => $date, 'accountcreated_date' => $date, 'created_date' => $createddate, 'created_by' => $this->view->createdby, 'status_id' => 1));
             // insert some value to accounts table for group*/
             $productid = $dbobj->getProductid();
             $productcode = $productid . 'S';
             // //                 // 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($membertypeid, 2, "0", STR_PAD_LEFT) . str_pad($productcode, 3, "0", STR_PAD_LEFT) . str_pad($account_id, 6, "0", STR_PAD_LEFT);
             $this->view->adm->updateRecord("ourbank_accounts", $account_id, array('account_number' => $accountNumber, 'member_id' => $groupid, 'product_id' => $productid, 'tag_account' => $account_id));
             //  // Group created date -> Including timestamp , Created date should contain date only
             $individualtypeid = $this->view->adm->getsingleRecord('ourbank_master_membertypes', 'id', 'type', 'Individual');
             // get individual type id
             // // 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' => $account_id, '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));
             }
             // // if all the input's are satisfying all our requirements we can unset the session values
             unset($sessionName->office);
             unset($sessionName->groupname);
             unset($sessionName->bank);
             unset($sessionName->savingamt);
             unset($sessionName->penaltylate);
             unset($sessionName->penaltyabsence);
             unset($sessionName->interest);
             unset($sessionName->place);
             unset($sessionName->times);
             unset($sessionName->day);
             unset($sessionName->Created_Date);
             $this->_redirect('groupcommonview/index/commonview/id/' . $groupid);
         }
     } else {
         // // //if not ok display errormessage
         $this->_redirect('/groupmdefault/index/addgroup/error/' . $error);
     }
 }