Exemplo n.º 1
0
 public function doExport()
 {
     $filename = 'firefly-export-' . date('Y-m-d') . '.json';
     $data = array();
     // accounts
     $accounts = Auth::user()->accounts()->get();
     foreach ($accounts as $account) {
         $account->name = Crypt::decrypt($account->name);
         $account->balance = floatval($account->balance);
         $data['accounts'][] = $account->toArray();
     }
     // icons
     $icons = Icon::all();
     foreach ($icons as $i) {
         $data['icons'][] = $i->toArray();
     }
     // beneficiaries
     $bene = Auth::user()->beneficiaries()->get();
     foreach ($bene as $b) {
         $b->name = Crypt::decrypt($b->name);
         $data['beneficiaries'][] = $b->toArray();
     }
     // budgets
     $budgets = Auth::user()->budgets()->get();
     foreach ($budgets as $budget) {
         $budget->name = Crypt::decrypt($budget->name);
         $budget->amount = floatval($budget->amount);
         $data['budgets'][] = $budget->toArray();
     }
     // categories
     $categories = Auth::user()->categories()->get();
     foreach ($categories as $cat) {
         $cat->name = Crypt::decrypt($cat->name);
         $data['categories'][] = $cat->toArray();
     }
     // targets
     $targets = Auth::user()->targets()->get();
     foreach ($targets as $target) {
         $target->description = Crypt::decrypt($target->description);
         $target->amount = floatval($target->amount);
         $data['targets'][] = $target->toArray();
     }
     // transactions
     $transactions = Auth::user()->transactions()->get();
     foreach ($transactions as $transaction) {
         $transaction->description = Crypt::decrypt($transaction->description);
         $transaction->amount = floatval($transaction->amount);
         $data['transactions'][] = $transaction->toArray();
     }
     // transfers
     $transfers = Auth::user()->transfers()->get();
     foreach ($transfers as $transfer) {
         $transfer->description = Crypt::decrypt($transfer->description);
         $transfer->amount = floatval($transfer->amount);
         $data['transfers'][] = $transfer->toArray();
     }
     // settings:
     $settings = Auth::user()->settings()->get();
     foreach ($settings as $setting) {
         $setting->value = Crypt::decrypt($setting->value);
         $data['settings'][] = $setting->toArray();
     }
     $payload = json_encode($data, JSON_PRETTY_PRINT);
     // We'll be outputting a PDF
     header('Content-Description: File Transfer');
     header('Content-Type: application/octet-stream');
     header('Content-Disposition: attachment; filename=' . $filename);
     header('Content-Transfer-Encoding: binary');
     header('Expires: 0');
     header('Cache-Control: must-revalidate');
     header('Pragma: public');
     header('Content-Length: ' . strlen($payload));
     echo $payload;
     exit;
 }