/**
  * Export a Filtered Listing of the resource.
  *
  * See: ViewCreators/ExportTypeCreator for a list of the exportTypes we need to support.
  */
 public function export()
 {
     if (Entrust::hasRole('teamLead') == False) {
         return redirect()->route('home');
     }
     $associateNumber = Request::all();
     // restore fromDate & toDate
     if (isset($associateNumber['fromDate']) == false and Session::has('fromDate')) {
         $associateNumber['fromDate'] = Session::get('fromDate');
     }
     if (isset($associateNumber['toDate']) == false and Session::has('toDate')) {
         $associateNumber['toDate'] = Session::get('toDate');
     }
     //dd(__METHOD__."(".__LINE__.")",compact('associateNumber'));
     if ($associateNumber['ExportType'] == 'xls') {
         // using an implementation of the PerformanceTally Repository Interface
         $associateNumbers = $this->performanceTallyRepository->sumOn($associateNumber + ['groupBy' => 'userName'], 0);
         //dd(__METHOD__."(".__LINE__.")",compact('associateNumber','associateNumbers'));
         // TODO file name should be calculated in a separate class
         $count = sprintf('%04d', $this->countersRepository->increment('exportFile'));
         $currentDate = Carbon::now()->format('YmdHis');
         $fileName = 'AssociateNumbers-' . $currentDate . $count;
         // create Excel workbook
         Excel::create($fileName, function ($excel) use($associateNumber, $associateNumbers) {
             $excel->sheet('New sheet', function ($sheet) use($associateNumber, $associateNumbers) {
                 $sheet->loadView('pages.associateNumber.excel')->with('associateNumber', $associateNumber)->with('associateNumbers', $associateNumbers);
             });
         })->export('xls');
     }
     if ($associateNumber['ExportType'] == 'csv') {
         // using an implementation of the PerformanceTally Repository Interface
         $associateNumbers = $this->performanceTallyRepository->sumOn($associateNumber + ['groupBy' => 'userName'], 0);
         //dd(__METHOD__."(".__LINE__.")",compact('associateNumber','associateNumbers'));
         // TODO file name should be calculated in a separate class
         $count = sprintf('%04d', $this->countersRepository->increment('exportFile'));
         $currentDate = Carbon::now()->format('YmdHis');
         $fileName = 'AssociateNumbers-' . $currentDate . $count;
         // create Excel workbook
         Excel::create($fileName, function ($excel) use($associateNumber, $associateNumbers) {
             $excel->sheet('New sheet', function ($sheet) use($associateNumber, $associateNumbers) {
                 $sheet->loadView('pages.associateNumber.excel')->with('associateNumber', $associateNumber)->with('associateNumbers', $associateNumbers);
             });
         })->export('csv');
     }
     // using an implementation of the PerformanceTally Repository Interface
     $associateNumbers = $this->performanceTallyRepository->paginateSum($associateNumber + ['groupBy' => 'userName']);
     // save fromDate & toDate
     if (isset($associateNumber['fromDate'])) {
         Session::put('fromDate', $associateNumber['fromDate']);
     }
     if (isset($associateNumber['toDate'])) {
         Session::put('toDate', $associateNumber['toDate']);
     }
     // Using the view(..) helper function
     return view('pages.associateNumber.index', compact('associateNumber', 'associateNumbers'));
 }
 /**
  * Apply the updates to our resource
  */
 public function update($id, PerformanceTallyRequest $request)
 {
     // if guest or cannot performanceTally.edit, redirect -> home
     if (Entrust::can('performanceTally.edit') == false) {
         return redirect()->route('home');
     }
     // using an implementation of the PerformanceTally Repository Interface
     $performanceTally = $this->performanceTallyRepository->find($id);
     //$performanceTally->update($request->all());
     /*
      * Here we can apply any business logic required,
      * then change $request->all() to results.
      */
     $input = $request->all();
     unset($input['_method']);
     unset($input['_token']);
     //dd($input);
     $this->performanceTallyRepository->update($id, $input);
     return redirect()->route('performanceTally.index');
 }