Exemple #1
0
 /**
  * @param array|string $profiles
  */
 protected function setReceivers($profiles)
 {
     if (!empty($profiles)) {
         if (is_string($profiles)) {
             $profiles = [$profiles];
         }
         $users = $this->userRepository->getUsersByProfile($this->user, $profiles);
         foreach ($users as $user) {
             array_push($this->receivers, ['email' => $user->email, 'name' => $user->full_name]);
         }
     }
 }
Exemple #2
0
 protected function getDataForReport()
 {
     $this->cities = $this->cityRepository->getCitiesByRetailer($this->retailer->id);
     $this->agencies = $this->agencyRepository->getAgenciesByRetailer($this->retailer->id);
     $this->users = $this->userRepository->getUsersByRetailer($this->retailer->id);
     $permission = $this->getPermissionForReport($this->user);
     /*
      * Cities
      */
     $this->cities = $this->cities->filter(function ($item) use($permission) {
         $item->id = $item->slug;
         if ($permission === 'RU' || $permission === 'RA' || $permission === 'RR') {
             if ($item->slug === $this->user->city->slug) {
                 return true;
             }
         } elseif ($permission === 'RN') {
             return true;
         }
     })->toArray();
     /*
      * Agencies
      */
     $this->agencies = $this->agencies->filter(function ($item) use($permission) {
         $item->id = $item->slug;
         if (!$this->user->agency instanceof Agency && $this->profile->slug === 'COP') {
             return true;
         } else {
             if ($permission === 'RU' || $permission === 'RA') {
                 if ($item->slug === $this->user->agency->slug) {
                     return true;
                 }
             } elseif ($permission === 'RR') {
                 foreach ($item->retailerCityAgencies as $retailerCityAgency) {
                     if ($retailerCityAgency->retailerCity->ad_city_id === $this->user->city->id) {
                         return true;
                     }
                 }
             } elseif ($permission === 'RN') {
                 return true;
             }
         }
     })->toArray();
     /*
      * Users
      */
     $this->users = $this->users->filter(function ($item) use($permission) {
         $item->id = $item->username;
         $item->name = $item->full_name;
         if ($permission === 'RU') {
             if ($item->username === $this->user->username) {
                 return true;
             }
         } elseif ($permission === 'RA') {
             if ($item->agency instanceof Agency && $item->agency->id === $this->user->agency->id) {
                 return true;
             }
         } elseif ($permission === 'RR') {
             if ($item->city instanceof City && $item->city->id === $this->user->city->id) {
                 return true;
             }
         } elseif ($permission === 'RN') {
             if ($item->agency instanceof Agency && $item->city instanceof City) {
                 return true;
             }
         }
     })->toArray();
     if ($permission !== 'RU') {
         $users = $this->getSelectOption();
         $this->users = $users->merge($this->users)->toArray();
         if ($permission === 'RN' || $permission === 'RR') {
             $agencies = $this->getSelectOption();
             $this->agencies = $agencies->merge($this->agencies)->toArray();
             if ($permission === 'RN') {
                 $cities = $this->getSelectOption();
                 $this->cities = $cities->merge($this->cities)->toArray();
             }
         }
     }
 }