private function returnJSON($request, $fileName)
 {
     $output = fopen('php://output', 'w') or Utils::fatalError();
     header('Content-Type:application/json');
     header("Content-Disposition:attachment;filename={$fileName}.json");
     $manager = new Manager();
     $manager->setSerializer(new ArraySerializer());
     $account = Auth::user()->account;
     $account->loadAllData();
     $resource = new Item($account, new AccountTransformer());
     $data = $manager->createData($resource)->toArray();
     return response()->json($data);
 }
 /**
  * @param $request
  * @param $fileName
  *
  * @return \Illuminate\Http\JsonResponse
  */
 private function returnJSON($request, $fileName)
 {
     $output = fopen('php://output', 'w') or Utils::fatalError();
     header('Content-Type:application/json');
     header("Content-Disposition:attachment;filename={$fileName}.json");
     $manager = new Manager();
     $manager->setSerializer(new ArraySerializer());
     // eager load data, include archived but exclude deleted
     $account = Auth::user()->account;
     $account->load(['clients' => function ($query) {
         $query->withArchived()->with(['contacts', 'invoices' => function ($query) {
             $query->withArchived()->with(['invoice_items', 'payments' => function ($query) {
                 $query->withArchived();
             }]);
         }]);
     }]);
     $resource = new Item($account, new AccountTransformer());
     $data = $manager->parseIncludes('clients.invoices.payments')->createData($resource)->toArray();
     return response()->json($data);
 }