ViewManageController.php
unknown
php_laravel_blade
2 years ago
3.9 kB
2
Indexable
Never
public function viewDashboard() { $id_account = Auth::id(); $role = User::where('id', $id_account)->first(); if ($role->role != 'kasir') { $kd_transaction = Transaction::select(['kode_transaksi', 'total', 'created_at']) ->where('status', 'lunas') ->latest() ->distinct() ->take(3) ->get(); $kd_transaction_nonppn = TransactionNonPPN::select(['kode_transaksi', 'total', 'created_at']) ->where('status', 'lunas') ->latest() ->distinct() ->take(3) ->get(); $kd_transaction = $kd_transaction->concat($kd_transaction_nonppn); $kd_transaction = $kd_transaction->sortByDesc('created_at'); $kd_transaction_uniques = array(); foreach ($kd_transaction as $c) { $kd_transaction_uniques[$c->kode_transaksi] = $c; } $transactions = Transaction::where('status', 'lunas')->get(); $transactions_nonppn = TransactionNonPPN::where('status', 'lunas')->get(); $transactions = $transactions->concat($transactions_nonppn); $array = array(); foreach ($transactions as $no => $transaction) { array_push($array, $transactions[$no]->created_at->toDateString()); } $dates = array_unique($array); rsort($dates); $arr_ammount = count($dates); $incomes_data = array(); if ($arr_ammount > 7) { for ($i = 0; $i < 7; $i++) { array_push($incomes_data, $dates[$i]); } } elseif ($arr_ammount > 0) { for ($i = 0; $i < $arr_ammount; $i++) { array_push($incomes_data, $dates[$i]); } } $incomes = array_reverse($incomes_data); $kode_transaksi_dis_daily = Transaction::whereDate('created_at', Carbon::now()) ->where('status', 'lunas') ->select(['kode_transaksi', 'id_customer', 'subtotal']) ->distinct() ->get(); $kode_transaksi_npp_dis_daily = TransactionNonPPN::whereDate('created_at', Carbon::now()) ->where('status', 'lunas') ->select(['kode_transaksi', 'id_customer', 'subtotal']) ->distinct() ->get(); $kode_transaksi_dis_daily = $kode_transaksi_dis_daily->concat($kode_transaksi_npp_dis_daily); $kode_transaksi_daily_uniques = array(); $costumer_daily_uniques = array(); // $income_total_daily_uniques = array(); $incomes_daily = 0; foreach ($kode_transaksi_dis_daily as $c) { $kode_transaksi_daily_uniques[$c->kode_transaksi] = $c; $costumer_daily_uniques[$c->id_customer] = $c; // $income_total_daily_uniques[$c->stotal] = $c; $incomes_daily += $c->subtotal; } $retur = 0; $retur = Transaction::where('status', 'retur')->whereDate('created_at', Carbon::now())->sum('total_barang'); $retur_nppn = TransactionNonPPN::where('status', 'retur')->whereDate('created_at', Carbon::now())->sum('total_barang'); $retur = $retur + $retur_nppn; $incomes_daily = $incomes_daily - $retur; $customers_daily = count($costumer_daily_uniques); $market = Market::first(); return view('dashboard', compact('kd_transaction_uniques', 'incomes', 'incomes_daily', 'customers_daily', 'market')); } else { return view('blank_dashboard'); } }