예제 #1
0
    public function __construct($record, $opts)
    {
        $componentName = $record->getTable()->getComponentName();

        $q = $record->getTable()->createQuery();

        $params = array($record->get('lft'), $record->get('rgt'));
        if (isset($opts['include_record']) && $opts['include_record']) {
            $query = $q->where("$componentName.lft >= ? AND $componentName.rgt <= ?", $params)->orderBy("$componentName.lft asc");
        } else {
            $query = $q->where("$componentName.lft > ? AND $componentName.rgt < ?", $params)->orderBy("$componentName.lft asc");
        }

        $query = $record->getTable()->getTree()->returnQueryWithRootId($query, $record->getNode()->getRootValue());

        $this->maxLevel   = isset($opts['depth']) ? ($opts['depth'] + $record->getNode()->getLevel()) : 0;
        $this->options    = $opts;
        $this->collection = isset($opts['collection']) ? $opts['collection'] : $query->execute();
        $this->keys       = $this->collection->getKeys();
        $this->count      = $this->collection->count();
        $this->index      = -1;
        $this->level      = $record->getNode()->getLevel();
        $this->prevLeft   = $record->getNode()->getLeftValue();

        // clear the table identity cache
        $record->getTable()->clear();
    }
예제 #2
0
 /**
  * @param Doctrine_Collection $collection
  * @param int $position position into collection
  * @param int $level
  * @return array
  */
 public static function collectionToTree(Doctrine_Collection $collection, &$position = 0, $level = 0)
 {
     $result = array();
     for ($i = $position; $i < $collection->count(); $i++) {
         if ($level < $collection[$i]->level) {
             $perv_index = $i - 1;
             $result[$collection[$perv_index]->id]['children'] = self::collectionToTree($collection, $i, $collection[$i]->level);
         } else {
             if ($level > $collection[$i]->level) {
                 // Shift loop global index
                 $position = $i - 1;
                 return $result;
             } else {
                 $result[$collection[$i]->id]['data'] = $collection[$i];
             }
         }
     }
     // Shift loop global index
     $position = $i - 1;
     return $result;
 }
예제 #3
0
 /**
  * constructor
  * @var Doctrine_Collection $collection
  */
 public function __construct($collection)
 {
     $this->collection = $collection;
     $this->keys = $this->collection->getKeys();
     $this->count = $this->collection->count();
 }
예제 #4
0
 public function testCount()
 {
     $coll = new Doctrine_Collection($this->connection->getTable('User'));
     $this->assertEqual($coll->count(), 0);
     $coll[0];
     $this->assertEqual($coll->count(), 1);
 }
예제 #5
0
 /**
  * Return how many items are in the collection
  *
  * @return void
  */
 public function count()
 {
     return $this->_dbData->count();
 }
예제 #6
0
 /**
  * Tries to return the next record in table
  */
 public function getNextRecord(Doctrine_Collection $nearRecords)
 {
     foreach ($nearRecords as $key => $record) {
         if ($this->getOid() === $record->getOid()) {
             $myOffset = $key;
             break;
         }
     }
     if (!isset($myOffset) || $myOffset === $nearRecords->count() - 1) {
         return null;
     }
     return $nearRecords[$myOffset + 1];
 }
예제 #7
0
 function reactivateAllAccounts()
 {
     $user_collection = new Doctrine_Collection(Doctrine_Core::getTable("UserAccount"));
     $users = $this->getUsers();
     //debugMessage($users->toArray());
     if ($users->count() > 0) {
         foreach ($users as $user) {
             if ($user->isUserInActive() && $user->getActivationKey() == md5($this->getCompanyID())) {
                 $user->setStatus(1);
                 $user->setActivationKey('');
                 $user_collection->add($user);
             }
         }
         // debugMessage($user_collection->toArray());
     }
     if ($user_collection->count() > 0) {
         try {
             $user_collection->save();
         } catch (Exception $e) {
             debugMessage("An error occured in updating status. " . $e->getMessage());
         }
     }
     return true;
 }
예제 #8
0
 function processglobalconfigAction()
 {
     $session = SessionWrapper::getInstance();
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $formvalues = $this->_getAllParams();
     $successurl = decode($formvalues[URL_SUCCESS]);
     // debugMessage($formvalues);
     $postarray = array();
     for ($i = 1; $i <= $formvalues['t']; $i++) {
         $postarray[$i]['id'] = $formvalues['id_' . $i];
         $postarray[$i]['displayname'] = $formvalues['displayname_' . $i];
         $postarray[$i]['optionvalue'] = $formvalues['optionvalue_' . $i];
     }
     $config_collection = new Doctrine_Collection(Doctrine_Core::getTable("AppConfig"));
     foreach ($postarray as $line) {
         $appconfig = new AppConfig();
         $appconfig->populate($line['id']);
         $appconfig->processPost($line);
         /*debugMessage('error is '.$appconfig->getErrorStackAsString());
         		debugMessage($appconfig->toArray());*/
         if ($appconfig->isValid()) {
             $config_collection->add($appconfig);
         }
     }
     // check for atleast one option and save
     if ($config_collection->count() > 0) {
         try {
             // debugMessage($config_collection->toArray());
             $config_collection->save();
             $session->setVar(SUCCESS_MESSAGE, $formvalues[SUCCESS_MESSAGE]);
             # clear cache after updating options
             $temppath = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR;
             // debugMessage($temppath);
             $files = glob($temppath . 'zend_cache---config*');
             foreach ($files as $file) {
                 debugMessage($file);
                 if (is_file($file)) {
                     unlink($file);
                 }
             }
         } catch (Exception $e) {
             $session->setVar(ERROR_MESSAGE, "An error occured in updating the parameters. " . $e->getMessage());
         }
     }
     // debugMessage($successurl);
     $this->_helper->redirector->gotoUrl($successurl);
     // exit();
 }
 function completeAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $session = SessionWrapper::getInstance();
     $formvalues = $this->_getAllParams();
     // debugMessage($formvalues); exit;
     $config = Zend_Registry::get("config");
     $payroll = new Payroll();
     $payroll->populate($this->_getParam('id'));
     $payroll->setStatus($this->_getParam('status'));
     // debugMessage($payroll->getStartDate()." - ".$payroll->getEndDate());
     $ledger_collection = new Doctrine_Collection(Doctrine_Core::getTable("Ledger"));
     $timesheet_collection = new Doctrine_Collection(Doctrine_Core::getTable("Timesheet"));
     $leave_collection = new Doctrine_Collection(Doctrine_Core::getTable("Ledger"));
     $employees = $payroll->getdetails();
     // debugMessage($employees->toArray());
     foreach ($employees as $employee) {
         $results_credits_array = array();
         // check of benefit additions
         if (decode($employee->getbenefitdetails()) != "[]" && $employee->getbenefitdetails() != "W10=") {
             $results_credits_array = objectToArray(json_decode(decode($employee->getbenefitdetails())));
             // debugMessage($results_credits_array);
             foreach ($results_credits_array as $line) {
                 if (!isArrayKeyAnEmptyString('ids', $line)) {
                     $ids_array = explode(',', $line['ids']);
                     if (count($ids_array) > 0) {
                         foreach ($ids_array as $id) {
                             $ledger = new Ledger();
                             $ledger->populate($id);
                             $ledger->setPayrollID($employee->getPayrollID());
                             $ledger_collection->add($ledger);
                             // debugMessage($ledger->toArray());
                         }
                     }
                 }
             }
         }
         // check for deductions
         if (decode($employee->getdeductiondetails()) != "[]" && $employee->getdeductiondetails() != "W10=") {
             $results_debits_array = objectToArray(json_decode(decode($employee->getdeductiondetails())));
             // debugMessage($results_credits_array);
             foreach ($results_debits_array as $line) {
                 if (!isArrayKeyAnEmptyString('ids', $line)) {
                     $ids_array = explode(',', $line['ids']);
                     if (count($ids_array) > 0) {
                         foreach ($ids_array as $id) {
                             $ledger = new Ledger();
                             $ledger->populate($id);
                             $ledger->setPayrollID($employee->getPayrollID());
                             $ledger_collection->add($ledger);
                             // debugMessage($ledger->toArray());
                         }
                     }
                 }
             }
         }
         // fetch timesheets for each employeee
         $timesheets = $employee->getUser()->getTimesheetDetails($payroll->getStartDate(), $payroll->getEndDate());
         if ($timesheets->count() > 0) {
             // debugMessage($timesheets->toArray());
             foreach ($timesheets as $timesheet) {
                 $timesheet->setPayrollID($employee->getPayrollID());
                 $timesheet_collection->add($timesheet);
             }
         }
         // generate leave accruals for period
         if ($employee->getLeaveHrs() > '0.00' && $employee->getUser()->getIsTimesheetuser() == 1) {
             // debugMessage('>'.$employee->getLeaveHrs());
             $leave = new Ledger();
             $leave_array = array("payrollid" => $payroll->getID(), "userid" => $employee->getUserID(), "ledgertype" => 2, "trxntype" => 1, "leaveid" => 1, "trxndate" => $payroll->getEndDate(), "startdate" => $payroll->getStartDate(), "enddate" => $payroll->getEndDate(), "leavelength" => $employee->getLeaveHrs() * getHoursInDay(), "lengthtype" => 1, "status" => 1, "remarks" => "Auto Accrual from Payroll (" . changeMySQLDateToPageFormat($payroll->getStartDate()) . " - " . changeMySQLDateToPageFormat($payroll->getEndDate()) . ") ", "createdby" => $session->getVar("userid"), "approvedbyid" => $session->getVar("userid"), "dateapproved" => date('Y-m-d'), "payrolltrigger" => 1);
             $leave->processPost($leave_array);
             /* debugMessage($leave->toArray());
             			debugMessage('errors are '.$leave->getErrorStackAsString()); */
             if (!$leave->hasError()) {
                 $leave_collection->add($leave);
             }
         }
         if ($employee->getSickHrs() > '0.00' && $employee->getUser()->getIsTimesheetuser() == 1) {
             // debugMessage('>'.$employee->getLeaveHrs());
             $leave = new Ledger();
             $leave_array = array("payrollid" => $payroll->getID(), "userid" => $employee->getUserID(), "ledgertype" => 2, "trxntype" => 1, "leaveid" => 2, "trxndate" => $payroll->getEndDate(), "startdate" => $payroll->getStartDate(), "enddate" => $payroll->getEndDate(), "leavelength" => $employee->getSickHrs() * getHoursInDay(), "lengthtype" => 1, "status" => 1, "remarks" => "Auto Accrued from Payroll (" . changeMySQLDateToPageFormat($payroll->getStartDate()) . " - " . changeMySQLDateToPageFormat($payroll->getEndDate()) . ") ", "createdby" => $session->getVar("userid"), "approvedbyid" => $session->getVar("userid"), "dateapproved" => date('Y-m-d'), "payrolltrigger" => 1);
             $leave->processPost($leave_array);
             /*debugMessage($leave->toArray());
             		debugMessage('errors are '.$leave->getErrorStackAsString()); */
             if (!$leave->hasError()) {
                 $leave_collection->add($leave);
             }
         }
         // generate recurring monthly benefits
         $newledgertrxns = array();
         if (decode($employee->getrecurringtrxns()) != "[]" && $employee->getrecurringtrxns() != "W10=") {
             $newledgertrxns = objectToArray(json_decode(decode($employee->getrecurringtrxns())));
             // debugMessage($newledgertrxns);
             foreach ($newledgertrxns as $line) {
                 // debugMessage($line);
                 foreach ($line as $key => $value) {
                     $ledger = new Ledger();
                     $ledger_array = array("payrollid" => $payroll->getID(), "payrolltrigger" => 1, "userid" => $employee->getUserID(), "ledgertype" => 1, "trxntype" => $value['trxntype'], "benefitid" => $value['benefitid'], "trxndate" => $payroll->getEndDate(), "startdate" => $payroll->getStartDate(), "enddate" => $payroll->getEndDate(), "amount" => $value['amount'], "status" => 1, "remarks" => "Auto Accrued from Payroll (" . changeMySQLDateToPageFormat($payroll->getStartDate()) . " - " . changeMySQLDateToPageFormat($payroll->getEndDate()) . ") ", "createdby" => $session->getVar("userid"), "approvedbyid" => $session->getVar("userid"), "dateapproved" => date('Y-m-d'), "istaxable" => isArrayKeyAnEmptyString('istaxable', $value) ? 0 : $value['istaxable']);
                     $ledger->processPost($ledger_array);
                     /* debugMessage($ledger->toArray());
                     			debugMessage('errors are '.$ledger->getErrorStackAsString()); */
                     if (!$ledger->hasError()) {
                         $ledger_collection->add($ledger);
                     }
                 }
             }
         }
         // add nssf to benefits if it exists
         if ($employee->getNssf() > 0) {
             $ledger = new Ledger();
             $ledger_array = array("payrollid" => $payroll->getID(), "payrolltrigger" => 1, "userid" => $employee->getUserID(), "ledgertype" => 1, "trxntype" => 2, "benefitid" => 19, "trxndate" => $payroll->getEndDate(), "startdate" => $payroll->getStartDate(), "enddate" => $payroll->getEndDate(), "amount" => $employee->getNssf(), "status" => 1, "remarks" => "Auto Accrued from Payroll (" . changeMySQLDateToPageFormat($payroll->getStartDate()) . " - " . changeMySQLDateToPageFormat($payroll->getEndDate()) . ") ", "createdby" => $session->getVar("userid"), "approvedbyid" => $session->getVar("userid"), "dateapproved" => date('Y-m-d'));
             $ledger->processPost($ledger_array);
             /* debugMessage($ledger->toArray());
             		 debugMessage('errors are '.$ledger->getErrorStackAsString()); */
             if (!$ledger->hasError()) {
                 $ledger_collection->add($ledger);
             }
         }
         // add paye to benefits if it exists
         if ($employee->getPaye() > 0) {
             $ledger = new Ledger();
             $ledger_array = array("payrollid" => $payroll->getID(), "payrolltrigger" => 1, "userid" => $employee->getUserID(), "ledgertype" => 1, "trxntype" => 2, "benefitid" => 20, "trxndate" => $payroll->getEndDate(), "startdate" => $payroll->getStartDate(), "enddate" => $payroll->getEndDate(), "amount" => $employee->getPaye(), "status" => 1, "remarks" => "Auto Accrued from Payroll (" . changeMySQLDateToPageFormat($payroll->getStartDate()) . " - " . changeMySQLDateToPageFormat($payroll->getEndDate()) . ") ", "createdby" => $session->getVar("userid"), "approvedbyid" => $session->getVar("userid"), "dateapproved" => date('Y-m-d'));
             $ledger->processPost($ledger_array);
             /* debugMessage($ledger->toArray());
             		 debugMessage('errors are '.$ledger->getErrorStackAsString()); */
             if (!$ledger->hasError()) {
                 $ledger_collection->add($ledger);
             }
         }
     }
     // debugMessage('exiting here');
     // exit;
     // save collection
     try {
         // update payroll status
         $payroll->save();
         // update benefits on the payroll
         if ($ledger_collection->count() > 0) {
             // debugMessage($ledger_collection->toArray());
             $ledger_collection->save();
         }
         // update timesheets on the payroll
         if ($timesheet_collection->count() > 0) {
             // debugMessage($timesheet_collection->toArray());
             $timesheet_collection->save();
         }
         // assign leave benefits
         if ($leave_collection->count() > 0) {
             // debugMessage($leave_collection->toArray());
             $leave_collection->save();
         }
         // set success message
         $msg = "Payroll Successfully Completed and Approved. Please note that this has been locked from any further updates. ";
         if (!isEmptyString($this->_getParam(SUCCESS_MESSAGE))) {
             $msg = $this->_getParam($this->_translate->translate($this->_getParam(SUCCESS_MESSAGE)));
         }
         $session->setVar(SUCCESS_MESSAGE, $msg);
         // debugMessage('success '); exit;
     } catch (Exception $e) {
         $session->setVar(ERROR_MESSAGE, "Error in saving Payroll. " . $e->getMessage());
         // debugMessage('Error in completing payroll. '.$e->getMessage()); exit;
     }
     $url = $this->view->baseUrl('payroll/list/id/' . encode($payroll->getID()) . '/issuepayslips/1');
     if (!isEmptyString($this->_getParam(URL_SUCCESS))) {
         $url = decode($this->_getParam(URL_SUCCESS));
     }
     $session->setVar("issuepayslips", '1');
     $this->_helper->redirector->gotoUrl($url);
 }