Ejemplo n.º 1
0
 public function get_report()
 {
     $account_id = Input::get('account_id');
     $periode = Input::get('periode', 'weekly');
     $date = Input::get('date');
     $end_date = Input::get('end_date');
     $today = strtotime(date('Y-m-d'));
     if (is_null($date) || empty($date)) {
         $last_week = $today - 3600 * 24 * 7;
         $date = date('Y-m-d', $last_week);
     }
     if ('daily' == $periode) {
         $range = array('start' => $date, 'end' => $date);
     } else {
         if ('weekly' == $periode) {
             $range = AppHelper::range_week($date);
         } else {
             if ('monthly' == $periode) {
                 $range = AppHelper::range_month($date);
             } else {
                 if ('custom' == $periode) {
                     $range = array('start' => $date, 'end' => $end_date);
                 }
             }
         }
     }
     $account = Account::find($account_id);
     $donations = Donation::where_between('donation_date', $range['start'], $range['end'])->where_account_id($account_id)->order_by('donation_date', 'asc')->get();
     $expenses = Expense::where_between('expense_date', $range['start'], $range['end'])->where_account_id($account_id)->order_by('expense_date', 'asc')->get();
     $transactions = Transaction::where_between('date', $range['start'], $range['end'])->where_account_id($account_id)->order_by('date', 'asc')->get();
     if (isset($donations[0]) || isset($expenses[0])) {
         $last_transaction = Transaction::earlier_than($transactions[0])->where_account_id($account_id)->first();
     } else {
         $last_transaction = Transaction::earlier_than_date($range['start'])->where_account_id($account_id)->first();
     }
     // var_dump($last_transaction); die;
     if (is_null($last_transaction)) {
         $last_transaction_balance = 0;
     } else {
         $last_transaction_balance = $last_transaction->balance->balance_amount;
     }
     $end_transaction = Transaction::where_between('date', $range['start'], $range['end'])->where_account_id($account_id)->order_by('date', 'desc')->order_by('id', 'desc')->first();
     if (is_null($end_transaction)) {
         $end_balance = 0;
     } else {
         $end_balance = $end_transaction->balance->balance_amount;
     }
     $data = array('range' => $range, 'account' => $account, 'donations' => $donations, 'expenses' => $expenses, 'last_transaction_balance' => $last_transaction_balance, 'end_balance' => $end_balance, 'periode' => $periode);
     return View::make('account.report', $data);
     // echo var_dump($end_balance);
 }