diff --git a/app/Http/Controllers/User/Dashboard/UserDashboardController.php b/app/Http/Controllers/User/Dashboard/UserDashboardController.php index 28b5067..7e377c0 100644 --- a/app/Http/Controllers/User/Dashboard/UserDashboardController.php +++ b/app/Http/Controllers/User/Dashboard/UserDashboardController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\User\Dashboard; use App\Http\Controllers\Controller; +use App\Models\Refund; use Illuminate\Http\Request; use App\Models\RefundUser; use App\Models\Transaction; @@ -38,11 +39,29 @@ class UserDashboardController extends Controller ->where('pembeli', auth()->user()->email) ->count(); - $sumRefund = ''; + $sumRefund = Transaction::join('refunds', 'transactions.id', '=', 'refunds.transaction_id') + ->where('transactions.status_pembayaran', 'refund') + ->whereMonth('transactions.updated_at', $currentMonth) + ->whereYear('transactions.updated_at', $currentYear) + ->where('transactions.pembeli', auth()->user()->email) + ->sum('refunds.total'); - $sumTransaksi = ''; + $sumTransaksi = Transaction::whereMonth('updated_at', $currentMonth) + ->whereYear('updated_at', $currentYear) + ->where('pembeli', auth()->user()->email) + ->sum('total_bayar'); - return view('user.index'); + $totalTransaction = Transaction::whereMonth('updated_at', $currentMonth) + ->whereYear('updated_at', $currentYear) + ->count(); + + $totalIncome = Transaction::where('status_transaksi', 'success')->sum('total_bayar'); + + $totalExpense = Transaction::where('status_transaksi', 'updated_at') + ->orWhere('status_transaksi', 'refund') + ->sum('total_bayar'); + + return view('user.index', compact('currentRole', 'countCreated', 'countPending', 'countFailure', 'sumRefund', 'sumTransaksi', 'totalTransaction', 'totalIncome', 'totalExpense')); } public function getSelectedChart(){ diff --git a/resources/views/User/index.blade.php b/resources/views/User/index.blade.php index 1b568ed..36b335c 100644 --- a/resources/views/User/index.blade.php +++ b/resources/views/User/index.blade.php @@ -56,25 +56,26 @@