Esempio n. 1
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $arrUser = User::lists('name', 'id');
     $arrExpenseList = expense::orderBy("expense.id", "ASC")->get();
     $ExpenseList = array();
     $sumData = array();
     $sumTotalPay = array();
     foreach ($arrUser as $k => $user) {
         $sumData[$k] = 0;
         foreach ($arrUser as $i => $user) {
             $sumTotalPay[$k][$i] = 0;
         }
     }
     $total_expense = 0;
     foreach ($arrExpenseList as $expense) {
         $share_count = $expense->shared_by_users->count();
         $countData = array();
         foreach ($arrUser as $k => $user) {
             $count = DB::table('mapuserexpense')->where('expense_id', $expense->id)->where('user_id', $k)->count();
             if ($count > 0) {
                 $cost = $expense->price / $share_count;
                 $countData[] = $cost;
                 $sumData[$k] = $sumData[$k] + $cost;
                 $total_expense += $cost;
                 $sumTotalPay[$expense->payed_by][$k] += $cost;
             } else {
                 $countData[] = NULL;
             }
         }
         $ExpenseList[] = array('expense_name' => $expense->expense_name, 'price' => $expense->price, 'payed_by' => user::find($expense->payed_by)->name, 'created_at' => $expense->created_at, 'countData' => $countData, 'sumData' => $sumData);
     }
     return view('user/reports', ["strCurrentPage" => "reports", "total_expense" => $total_expense, "arrUser" => $arrUser, "sumTotalPay" => $sumTotalPay, 'date_from' => "", 'date_to' => "", "arrExpenseList" => $ExpenseList]);
 }
Esempio n. 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function view()
 {
     $rsExpenseList = expense::orderBy("expense.id", "DESC")->get();
     $arrExpenseList = array();
     foreach ($rsExpenseList as $expense) {
         $users = DB::table('users')->join('mapuserexpense', 'mapuserexpense.user_id', '=', 'users.id')->select('users.name')->where('mapuserexpense.expense_id', '=', $expense->id)->get();
         $expense['shared_by'] = $users;
         $expense['payed_by'] = user::find($expense->payed_by)->name;
         $arrExpenseList[] = $expense;
     }
     return view('user/manageExpense', ['arrExpenseList' => $arrExpenseList, "strCurrentPage" => "manage_expense"]);
 }