예제 #1
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function home()
 {
     if (\Auth::check()) {
         return PresenterFactory::getInstance('Reports')->dashboard();
     } else {
         return redirect('/');
     }
 }
예제 #2
0
 public function profile()
 {
     $this->view->assignmentOptions = $this->getAssignmentOptions();
     $this->view->roles = $this->getRoles();
     $this->view->gender = $this->getGender();
     $admin = $this->isAdmin();
     $this->view->areas = PresenterFactory::getInstance('Reports')->getArea();
     $this->view->readOnly = $admin ? '' : 'readonly';
     return $this->view('myProfile');
 }
예제 #3
0
 /**
  * This is a helper method which will handle necessary data
  * needed for the view. This is created to centralize this functionality
  * for all presenters
  * @param string $template
  * @param array $data
  * @param string $parent
  */
 protected function view($template, $data = [], $parent = '')
 {
     if ($parent) {
         $name = $parent;
     } else {
         $namespace = get_class($this);
         $chunks = explode('\\', $namespace);
         $name = array_pop($chunks);
         $name = str_replace(PresenterFactory::getSuffix(), '', $name);
     }
     //$menu = LibraryFactory::getInstance('Menu')->getMyMenus();
     //$this->view->menu = $menu;
     $templateName = $name . '.' . $template;
     return view($templateName, $data, (array) $this->view);
 }
예제 #4
0
 /**
  * This is a helper method which will handle necessary data
  * needed for the view. This is created to centralize this functionality
  * for all presenters
  * @param string $template
  * @param array $data
  * @param string $parent
  */
 protected function view($template, $data = [], $parent = '')
 {
     if ($parent) {
         $name = $parent;
     } else {
         $namespace = get_class($this);
         $chunks = explode('\\', $namespace);
         $name = array_pop($chunks);
         $name = str_replace(PresenterFactory::getSuffix(), '', $name);
     }
     $menuLib = LibraryFactory::getInstance('Menu');
     if (!$menuLib->isActionAllowed($template)) {
         return view('errors.403');
     }
     $this->view->menu = $menuLib->getMyMenus();
     $templateName = $name . '.' . $template;
     $this->view->isAdmin = $this->isAdmin();
     $this->view->isAuditor = $this->isAuditor();
     $this->view->isAccounting = $this->isAcounting();
     $this->view->isGuest1 = $this->isGuest1();
     $this->view->isGuest2 = $this->isGuest2();
     return view($templateName, $data, (array) $this->view);
 }
예제 #5
0
 /**
  * Get records
  * @return \Illuminate\Http\JsonResponse
  */
 public function getRecords($type)
 {
     switch ($type) {
         case 'salescollectionreport':
             return $this->getSalesCollectionReport();
         case 'salescollectionposting':
             return $this->getSalesCollectionPosting();
         case 'salescollectionsummary':
             return $this->getSalesCollectionSummary();
         case 'vaninventoryfrozen':
         case 'vaninventorycanned':
             return $this->getVanInventory();
         case 'unpaidinvoice':
             return $this->getUnpaidInvoice();
         case 'bir':
             return $this->getBir();
         case 'salesreportpermaterial':
             return $this->getSalesReportMaterial();
         case 'salesreportperpeso':
             return $this->getSalesReportPeso();
         case 'returnpermaterial':
             return $this->getReturnMaterial();
         case 'returnperpeso':
             return $this->getReturnPeso();
         case 'customerlist':
             return $this->getCustomerList();
         case 'salesmanlist':
             return $this->getSalesmanList();
         case 'materialpricelist':
             return $this->getMaterialPriceList();
         case 'conditioncodes':
             return $this->getConditionCodes();
         case 'userlist':
             return PresenterFactory::getInstance('User')->getUsers();
         case 'usergrouplist':
             return PresenterFactory::getInstance('User')->getUserGroup();
     }
 }
예제 #6
0
 /**
  * Check if a specific user has access to this page
  * @param unknown $page The nav Id or url
  * @param number $userId The userId
  */
 public function hasPageAccess($page, $userId = 0)
 {
     $hasAccess = false;
     if (!$userId) {
         $userId = auth()->user() ? auth()->user()->id : 0;
     }
     $navModel = ModelFactory::getInstance('Navigation');
     if (is_numeric($page)) {
         $nav = $navModel->find($id);
     } else {
         $nav = $navModel->where('url', '=', $page)->first();
     }
     if ($nav) {
         // Check user permission first
         // 			$userToNav = ModelFactory::getInstance('UserToNav')
         // 							->where('user_id','=',$userId)
         // 							->where('nav_id','=',$nav->id)
         // 							->first();
         // 			if($userToNav)
         // 			{
         // 				return $userToNav->enable;
         // 			}
         // Check role permission
         $userRoles = ModelFactory::getInstance('User')->with('roles')->find($userId);
         $roleIds = [];
         foreach ($userRoles->roles as $role) {
             $roleIds[] = $role->id;
         }
         //@TODO: optimize this
         $menuLib = LibraryFactory::getInstance('Menu');
         foreach ($roleIds as $roleId) {
             if ($menuLib->roleHasMenu($roleId, $nav->id)) {
                 return true;
             }
         }
         return $hasAccess;
     }
     // Finally check feature
     if (!$hasAccess) {
         $route = request()->route();
         $action = $route->getAction();
         $controller = $action['controller'];
         $namespace = $action['namespace'];
         if ($controller && $namespace) {
             $controller = str_replace($namespace . '\\', '', $controller);
             $chunks = explode('@', $controller);
             $presenter = $chunks[0];
             $method = $chunks[1];
             if (false !== strpos(PresenterFactory::getNamespace(), $namespace)) {
                 $name = str_replace(PresenterFactory::getSuffix(), '', $presenter);
                 $permissions = PresenterFactory::getInstance($name)->getPermissions();
             } elseif (false !== strpos(ControllerFactory::getNamespace(), $namespace)) {
                 $name = str_replace(ControllerFactory::getSuffix(), '', $presenter);
                 $permissions = ControllerFactory::getInstance($name)->getPermissions();
             } elseif (false !== strpos(WebServiceFactory::getNamespace(), $namespace)) {
                 $name = str_replace(WebServiceFactory::getSuffix(), '', $presenter);
                 $permissions = WebServiceFactory::getInstance($name)->getPermissions();
             }
             if (isset($permissions[$method])) {
                 $features = $permissions[$method];
                 if (!$features || feature_enabled($features)) {
                     return true;
                 }
             } else {
                 foreach ($permissions as $method => $features) {
                     if (!$features || feature_enabled($features)) {
                         return true;
                     }
                 }
             }
         }
     }
     return $hasAccess;
 }
예제 #7
0
 /**
  * Sync sfa database to my database
  * @param string $display
  * @return boolean
  */
 public function sync($display = false)
 {
     $this->log('Synchronization started ' . date('Y-m-d H:m:s') . "\n");
     \DB::table('settings')->where('name', 'synching_sfi')->update(['value' => 1]);
     try {
         $dbh = new PDO("dblib:host={$this->host}:{$this->port};dbname={$this->database}", $this->dbuser, $this->dbpass);
         $configTables = config('sync.sync_tables');
         $tables = array_keys($configTables);
         $limit = 1000;
         foreach ($tables as $table) {
             //Delete records from local database
             \DB::table($table)->whereNull('updated_at')->delete();
             $ids = [];
             if ($keys = $configTables[$table]) {
                 $records = \DB::table($table)->get($keys);
                 $pKey = array_shift($keys);
                 foreach ($records as $record) {
                     $ids[] = $record->{$pKey};
                 }
             }
             $query = 'SELECT * FROM ' . $table;
             if ($ids) {
                 //exclude records
                 $query .= ' WHERE ' . $pKey . ' NOT IN(' . implode(',', $ids) . ')';
             }
             $stmt = $dbh->prepare($query);
             $stmt->execute();
             $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
             $data = $this->formatData($data);
             $count = count($data);
             if ($count > $limit) {
                 foreach (array_chunk($data, $limit, true) as $row) {
                     // Import data to local database
                     \DB::table($table)->insert($row);
                 }
                 $msg = "{$table} : inserted " . count($data) . " records.\n";
                 $this->log($msg);
                 if ($display) {
                     echo $msg;
                 }
             } else {
                 // Import data to local database
                 \DB::table($table)->insert($data);
                 $msg = "{$table} : inserted " . count($data) . " records.\n";
                 $this->log($msg);
                 if ($display) {
                     echo $msg;
                 }
             }
             unset($data);
         }
     } catch (PDOException $e) {
         $this->log('Error :' . $e->getMessage());
         //$email = config('system.error_email');
         if ($email) {
             $email = explode(',', $email);
             $data['email'] = $email;
             $data['errors'] = $e->getMessage();
             \Mail::send('emails.error', $data, function ($m) use($email) {
                 $m->from(config('system.from_email'), config('system.from'));
                 $m->to($email)->subject('Application Error');
             });
         }
         return false;
     }
     \DB::table('settings')->where('name', 'synching_sfi')->update(['value' => 0]);
     $this->log('Synchronization ended ' . date('Y-m-d H:m:s') . "\n");
     // update report summary columns
     PresenterFactory::getInstance('Reports')->updateReportSummary();
     return true;
 }