diff --git a/app/Http/Controllers/API/Contact/ContactApiController.php b/app/Http/Controllers/API/Contact/ContactApiController.php index 0d35cce..75e63ee 100644 --- a/app/Http/Controllers/API/Contact/ContactApiController.php +++ b/app/Http/Controllers/API/Contact/ContactApiController.php @@ -17,8 +17,6 @@ class ContactApiController extends Controller { public function getListContact(Request $request) { - // $token = JWTAuth::getToken(); - // $user = JWTAuth::user($token); $data = DB::table('contacts') ->join('users', 'contacts.relasi_kontak', '=', 'users.email') diff --git a/app/Http/Controllers/API/Notification/NotificationApiController.php b/app/Http/Controllers/API/Notification/NotificationApiController.php new file mode 100644 index 0000000..62fda62 --- /dev/null +++ b/app/Http/Controllers/API/Notification/NotificationApiController.php @@ -0,0 +1,44 @@ +input('id'))->get(); + + return response()->json([ + 'data' => $notification + ]); + } + + public function markAllAsRead(){ + $result = NotificationReceiver::where('receiver', auth()->user()->email)->update([ + 'status' => 'read' + ]); + + if($result){ + return response()->json([ + 'status' => true, + 'message' => 'Berhasil' + ]); + }else{ + return response()->json([ + 'status' => false, + 'message' => 'Gagal' + ]); + + Log::error($result); + } + } +} diff --git a/app/Http/Controllers/Admin/Dashboard/AdminDashboardController.php b/app/Http/Controllers/Admin/Dashboard/AdminDashboardController.php index d8cd92a..5631210 100644 --- a/app/Http/Controllers/Admin/Dashboard/AdminDashboardController.php +++ b/app/Http/Controllers/Admin/Dashboard/AdminDashboardController.php @@ -8,76 +8,369 @@ use Carbon\Carbon; use App\Models\Transaction; use App\Models\Refund; use App\Models\User; +use DateInterval; +use DateTime; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\DB; class AdminDashboardController extends Controller { public function index() { - $currentMonth = Carbon::now()->month; - $currentYear = Carbon::now()->year; + $today = new DateTime(); + $todayDate = $today->format('Y-m-d'); + $pickDate = new DateTime(); + $interval = new DateInterval('P29D'); + $start = $pickDate->sub($interval); + $startDate = $start->format('Y-m-d'); - $countSuccess = Transaction::where('status_pembayaran', 'settlement') - ->whereMonth('updated_at', $currentMonth) - ->whereYear('updated_at', $currentYear) + $intervalBefore = new DateInterval('P1D'); + $intervalBeforeStart = new DateInterval('P29D'); + $endBefore = $pickDate->sub($intervalBefore); + $endBeforeDate = $endBefore->format('Y-m-d'); + $startBefore = $pickDate->sub($intervalBeforeStart); + $startBeforeDate = $startBefore->format('Y-m-d'); + + $countSuccess = Transaction::whereIn('status_transaksi', ['done']) + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->count(); // selesai + + $countProcessed = Transaction::whereIn('status_transaksi', ['process', 'sending', 'sent', 'success', 'finished']) + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->count(); // diproses + + $countCancelled = Transaction::where('status_transaksi', 'failure') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->count(); //gagal + + $countIndicated = Transaction::where('status_transaksi', 'challenge') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->count(); // terindikasi + + $countWaiting = Transaction::where('status_transaksi', 'created_at') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->count(); // terindikasi + + $totalTransaction = Transaction::whereNotIn('status_transaksi', ['refund']) + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->count(); // transaksi + + $totalTransactionSebelum = Transaction::whereNotIn('status_transaksi', ['refund', 'created']) + ->whereDate('created_at', '>=', $startBeforeDate) + ->whereDate('created_at', '<=', $endBeforeDate) + ->count(); // transaksi sebelum + + $rateTransaction = floatval((floatval($totalTransaction)-floatval($totalTransactionSebelum))*100)/ ($totalTransactionSebelum == 0 ? 1 : floatval($totalTransactionSebelum)); + + $countPending = Refund::where('status', 'pending') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->count(); //ajuan + + $countApprove = Refund::where('status', 'refund') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->count(); // disetujui + + $countDeny = Refund::where('status', 'deny') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->count(); // ditolak + + $totalRefund = Refund::whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->count(); // refund + + $totalRefundSebelum = Refund::whereDate('created_at', '>=', $startBeforeDate) + ->whereDate('created_at', '<=', $endBeforeDate) + ->count(); // refund sebelum + + $rateRefund = floatval((floatval($totalRefund)-floatval($totalRefundSebelum))*100)/ ($totalRefundSebelum == 0 ? 1 : floatval($totalRefundSebelum)); + + $totalUser = User::where('role', 'User') + ->where('status', 'Finished') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) ->count(); - $countPending = Transaction::where('status_pembayaran', 'pending') - ->whereMonth('updated_at', $currentMonth) - ->whereYear('updated_at', $currentYear) - ->count(); + $totalUserSebelum = User::where('role', 'User') + ->where('status', 'Finished') + ->whereDate('created_at', '>=', $startBeforeDate) + ->whereDate('created_at', '<=', $endBeforeDate) + ->count(); - $countCancelled = Transaction::where('status_pembayaran', 'cancel') - ->whereMonth('updated_at', $currentMonth) - ->whereYear('updated_at', $currentYear) - ->count(); + $rateUser = floatval((floatval($totalUser)-floatval($totalUserSebelum))*100)/ ($totalUserSebelum == 0 ? 1 : floatval($totalUserSebelum)); - $countRefund = Transaction::where('status_pembayaran', 'refund') - ->whereMonth('updated_at', $currentMonth) - ->whereYear('updated_at', $currentYear) - ->count(); + $totalProfit = Transaction::whereIn('status_transaksi', ['done', 'finished']) + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->sum('total_keuntungan'); - $totalTransaction = Transaction::whereMonth('updated_at', $currentMonth) - ->whereYear('updated_at', $currentYear) - ->count(); + $totalProfitSebelum = Transaction::whereIn('status_transaksi', ['done', 'finished']) + ->whereDate('created_at', '>=', $startBeforeDate) + ->whereDate('created_at', '<=', $endBeforeDate) + ->sum('total_keuntungan'); + + $rateProfit = floatval((floatval($totalProfit)-floatval($totalProfitSebelum))*100)/ ($totalProfitSebelum == 0 ? 1 : floatval($totalProfitSebelum)); $dataChartTransaction = []; $dataChartRefund = []; + $dataChartUser = []; + $dataLabel = []; - $totalRefund = Transaction::where('status_pembayaran', 'refund')->count(); - $dataChartTotalRefund = []; + $startDate = $start; + $intervalDate = new DateInterval('P1D'); + $todayDate = $today; + $endDate = $todayDate->add($intervalDate); - $totalUser = User::where('status', 'Finished')->count(); - $dataChartTotalUser = []; + for ($date = clone $startDate; $date <= $endDate; $date->modify('+1 day')) { + $transaction = Transaction::whereIn('status_transaksi', ['done', 'finished']) + ->whereDate('created_at', $date->format('Y-m-d')) + ->sum('total_keuntungan'); - for ($bulan = 1; $bulan <= 12; $bulan++) { - $transaction = Transaction::whereMonth('updated_at', $bulan) - ->whereYear('updated_at', $currentYear) - ->where('status_pembayaran', 'settlement') - ->sum('total_bayar')/100; + $refund = Transaction::where('status_transaksi', 'refund') + ->whereDate('created_at', $date->format('Y-m-d')) + ->sum('total_keuntungan'); - $refund = Transaction::whereMonth('updated_at', $bulan) - ->whereYear('updated_at', $currentYear) - ->where('status_pembayaran', 'refund') - ->sum('total_harga')/100; + $user = User::where('role', 'User') + ->where('status', 'Finished') + ->whereDate('created_at', $date->format('Y-m-d')) + ->count(); - $dataChartTransaction[] = intval($transaction); - $dataChartRefund[] = intval($refund); + $dataChartTransaction[] = floatval($transaction) / 1000; + $dataChartRefund[] = floatval($refund) / 1000; + $dataChartUser[] = intval($user); + $dataLabel[] = $date->format('d/m/Y'); } - $transactions = Transaction::latest() - ->get(); + $dataTopUsers = Transaction::selectRaw( + " + CONCAT(users.nama_depan,' ',users.nama_belakang) AS nama_lengkap, + COUNT(CASE WHEN transactions.status_transaksi = 'done' OR refunds.status = 'refund' THEN 1 ELSE NULL END) AS jumlah_transaksi, + COUNT(CASE WHEN transactions.status_transaksi = 'done' THEN 1 ELSE NULL END) AS jumlah_transaksi_berhasil, + COUNT(CASE WHEN refunds.status = 'refund' THEN 1 ELSE NULL END) AS jumlah_refund_berhasil, + SUM(CASE WHEN refunds.status = 'refund' THEN refunds.total ELSE 0 END) AS total_refund_berhasil, + SUM(CASE WHEN transactions.status_transaksi = 'done' THEN transactions.total_harga ELSE 0 END) AS total_transaksi_berhasil, + users.foto_profile + ", + ) + ->leftJoin('refunds', 'refunds.transaction_id', '=', 'transactions.id') + ->leftJoin('users', 'users.email', '=', 'transactions.pembeli') + ->groupBy('nama_lengkap', 'users.foto_profile') + ->orderBy('total_transaksi_berhasil', 'DESC') + ->orderBy('total_refund_berhasil', 'ASC') + ->whereDate('transactions.created_at', '>=', $startDate) + ->whereDate('transactions.created_at', '<=', $todayDate) + ->limit(5) + ->get(); - return view('admin.index', compact('transactions', 'countSuccess', 'countPending', 'countCancelled', 'countRefund', 'totalRefund', 'totalUser', 'totalTransaction', 'dataChartTransaction', 'dataChartRefund', 'dataChartTotalUser', 'dataChartTotalRefund', 'transactions')); + return view('admin.index', compact( + 'countSuccess', + 'countProcessed', + 'countCancelled', + 'countIndicated', + 'countWaiting', + 'totalTransaction', + 'rateTransaction', + 'countPending', + 'countApprove', + 'countDeny', + 'totalRefund', + 'rateRefund', + 'totalUser', + 'rateUser', + 'rateProfit', + 'dataChartTransaction', + 'dataChartRefund', + 'dataChartUser', + 'dataLabel', + 'dataTopUsers' + )); } - public function getSelectedChart() + public function getDataBySearch(Request $request) { - $dataChartLaporan = []; - $tahun = Carbon::now()->year; - } + $startDate = $request->startDate; // 0 + $endDate = $request->endDate; // 29 + $pickDate = new DateTime($request->startDate); + $startDateTime = new DateTime($request->startDate); + $endDateTime = new DateTime($request->endDate); + $interval = $startDateTime->diff($endDateTime); - public function getCharByYear() - { + $intervalBefore = new DateInterval('P1D'); + $intervalBeforeStart = new DateInterval('P'.$interval->format('%a').'D'); + $endBefore = $pickDate->sub($intervalBefore); + $endBeforeDate = $endBefore->format('Y-m-d'); // -1 + $startBefore = $pickDate->sub($intervalBeforeStart); + $startBeforeDate = $startBefore->format('Y-m-d'); // -29 + + $countSuccess = Transaction::whereIn('status_transaksi', ['done']) + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $endDate) + ->count(); // selesai + + $countProcessed = Transaction::whereIn('status_transaksi', ['process', 'sending', 'sent', 'success', 'finished']) + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $endDate) + ->count(); // diproses + + $countCancelled = Transaction::where('status_transaksi', 'failure') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $endDate) + ->count(); //gagal + + $countIndicated = Transaction::where('status_transaksi', 'challenge') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $endDate) + ->count(); // terindikasi + + $countWaiting = Transaction::where('status_transaksi', 'created') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $endDate) + ->count(); // terindikasi + + $totalTransaction = Transaction::whereNotIn('status_transaksi', ['refund']) + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $endDate) + ->count(); // transaksi + + $totalTransactionSebelum = Transaction::whereNotIn('status_transaksi', ['refund']) + ->whereDate('created_at', '>=', $startBeforeDate) + ->whereDate('created_at', '<=', $endBeforeDate) + ->count(); // transaksi + + $rateTransaction = floatval((floatval($totalTransaction)-floatval($totalTransactionSebelum))*100)/ ($totalTransactionSebelum == 0 ? 1 : floatval($totalTransactionSebelum)); + + $countPending = Refund::where('status', 'pending') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $endDate) + ->count(); //ajuan + + $countApprove = Refund::where('status', 'refund') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $endDate) + ->count(); // disetujui + + $countDeny = Refund::where('status', 'deny') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $endDate) + ->count(); // ditolak + + $totalRefund = Refund::whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $endDate) + ->count(); // refund + + $totalRefundSebelum = Refund::whereDate('created_at', '>=', $startBeforeDate) + ->whereDate('created_at', '<=', $endBeforeDate) + ->count(); + + $rateRefund = floatval((floatval($totalRefund)-floatval($totalRefundSebelum))*100)/ ($totalRefundSebelum == 0 ? 1 : floatval($totalRefundSebelum)); + + $totalUser = User::where('role', 'User') + ->where('status', 'Finished') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $endDate) + ->count(); + + $totalUserSebelum = User::where('role', 'User') + ->where('status', 'Finished') + ->whereDate('created_at', '>=', $startBeforeDate) + ->whereDate('created_at', '<=', $endBeforeDate) + ->count(); + + $rateUser = floatval((floatval($totalUser)-floatval($totalUserSebelum))*100)/ ($totalUserSebelum == 0 ? 1 : floatval($totalUserSebelum)); + + $totalProfit = Transaction::where('status_transaksi', 'done') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $endDate) + ->sum('total_keuntungan'); + + $totalProfitSebelum = Transaction::where('status_transaksi', 'done') + ->whereDate('created_at', '>=', $startBeforeDate) + ->whereDate('created_at', '<=', $endBeforeDate) + ->sum('total_keuntungan'); + + $rateProfit = floatval((floatval($totalProfit)-floatval($totalProfitSebelum))*100)/ ($totalProfitSebelum == 0 ? 1 : floatval($totalProfitSebelum)); + + $dataChartTransaction = []; + $dataChartRefund = []; + $dataChartUser = []; + $dataLabel = []; + + $first = $startDateTime; + $intervalDate = new DateInterval('P1D'); + $endPlus1 = $endDateTime; + $last = $endPlus1->add($intervalDate); + + for ($date = clone $first; $date <= $last; $date->modify('+1 day')) { + $transaction = Transaction::where('status_transaksi', 'done') + ->whereDate('created_at', $date->format('Y-m-d')) + ->sum('total_keuntungan'); + + $refund = Transaction::where('status_transaksi', 'refund') + ->whereDate('created_at', $date->format('Y-m-d')) + ->sum('total_keuntungan'); + + $user = User::where('role', 'User') + ->where('status', 'Finished') + ->whereDate('created_at', $date->format('Y-m-d')) + ->count(); + + $dataChartTransaction[] = floatval($transaction); + $dataChartRefund[] = floatval($refund); + $dataChartUser[] = intval($user); + $dataLabel[] = $date->format('d/m/Y'); + } + + $dataTopUsers = Transaction::selectRaw( + " + CONCAT(users.nama_depan,' ',users.nama_belakang) AS nama_lengkap, + COUNT(CASE WHEN transactions.status_transaksi = 'done' OR refunds.status = 'refund' THEN 1 ELSE NULL END) AS jumlah_transaksi, + COUNT(CASE WHEN transactions.status_transaksi = 'done' THEN 1 ELSE NULL END) AS jumlah_transaksi_berhasil, + COUNT(CASE WHEN refunds.status = 'refund' THEN 1 ELSE NULL END) AS jumlah_refund_berhasil, + SUM(CASE WHEN refunds.status = 'refund' THEN refunds.total ELSE 0 END) AS total_refund_berhasil, + SUM(CASE WHEN transactions.status_transaksi = 'done' THEN transactions.total_harga ELSE 0 END) AS total_transaksi_berhasil, + users.foto_profile + ", + ) + ->leftJoin('refunds', 'refunds.transaction_id', '=', 'transactions.id') + ->leftJoin('users', 'users.email', 'transactions.pembeli') + ->groupBy('nama_lengkap', 'users.foto_profile') + ->orderBy('total_transaksi_berhasil', 'DESC') + ->orderBy('total_refund_berhasil', 'ASC') + ->whereDate('transactions.created_at', '>=', $startDate) + ->whereDate('transactions.created_at', '<=', $endDate) + ->limit(5) + ->get(); + + return response()->json([ + 'countSuccess' => $countSuccess, + 'countProcessed' => $countProcessed, + 'countCancelled' => $countCancelled, + 'countIndicated' => $countIndicated, + 'countWaiting' => $countWaiting, + 'totalTransaction' => $totalTransaction, + 'rateTransaction' => $rateTransaction, + 'countPending' => $countPending, + 'countApprove' => $countApprove, + 'countDeny' => $countDeny, + 'totalRefund' => $totalRefund, + 'rateRefund' => $rateRefund, + 'totalUser' => $totalUser, + 'rateUser' => $rateUser, + 'rateProfit' => $rateProfit, + 'dataChartTransaction' => $dataChartTransaction, + 'dataChartRefund' => $dataChartRefund, + 'dataChartUser' => $dataChartUser, + 'dataLabel' => $dataLabel, + 'dataTopUser' => $dataTopUsers, + 'endDate' => $request->endDate, + ]); } } diff --git a/app/Http/Controllers/Admin/Notification/AdminNotification.php b/app/Http/Controllers/Admin/Notification/AdminNotification.php index c5a8983..3bf6ad6 100644 --- a/app/Http/Controllers/Admin/Notification/AdminNotification.php +++ b/app/Http/Controllers/Admin/Notification/AdminNotification.php @@ -46,7 +46,7 @@ class AdminNotification extends Controller public function listNotification(Request $request) { try { - $subQuery = Notification::latest()->select('notifications.id', 'notifications.title', 'notifications.teaser', 'notifications.created_at'); + $subQuery = Notification::latest('notifications.updated_at')->select('notifications.id', 'notifications.title', 'notifications.teaser', 'notifications.created_at'); if ($request->has('search') && !empty($request->search['value'])) { $searchNotif = $request->search['value']; @@ -266,6 +266,7 @@ class AdminNotification extends Controller $email = NotificationReceiver::where('notification_id', $request->id) ->pluck('receiver') ->toArray(); + return view('admin.notification.edit', compact('notification', 'email')); } diff --git a/app/Http/Controllers/Admin/Refund/AdminRefundController.php b/app/Http/Controllers/Admin/Refund/AdminRefundController.php index 16e669d..17cb517 100644 --- a/app/Http/Controllers/Admin/Refund/AdminRefundController.php +++ b/app/Http/Controllers/Admin/Refund/AdminRefundController.php @@ -11,6 +11,8 @@ use App\Models\RefundDescription; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use App\Http\Controllers\Controller; +use App\Models\Notification; +use App\Models\NotificationReceiver; use App\Models\TransactionDescription; use Carbon\Carbon; use Illuminate\Support\Facades\Http; @@ -44,6 +46,7 @@ class AdminRefundController extends Controller public function approveRefund(Request $request) { $refund = Refund::where('id', $request->id)->first(); + $transactionDetail = Transaction::where('id', $refund->transaction_id)->first(); $params = [ 'refund_key' => $request->id . '-ref1', @@ -60,7 +63,7 @@ class AdminRefundController extends Controller 'Content-Type' => 'application/json', 'Authorization' => "Basic $auth", ]) - ->post('https://api.sandbox.midtrans.com/v2/'.$request->id.'/refund', $params); + ->post('https://api.sandbox.midtrans.com/v2/'.$refund->transaction_id.'/refund', $params); $result = json_decode($response->body(), true); $code = $result['status_code']; @@ -85,11 +88,31 @@ class AdminRefundController extends Controller 'deskripsi' => 'Admin telah menyetujui refund.', ]); + $url = route('user-transaction.show', ['id' => $transactionDetail->id]); + + $notif = Notification::create([ + 'title' => 'Refund Diterima', + 'content' => 'Refund telah diterima dan uang akan dikembalikan ke pembeli. Klik disini untuk langsung ke detail transaksi.', + 'teaser' => 'Refund telah diterima...', + ]); + + NotificationReceiver::create([ + 'receiver' => [ + $transactionDetail->pembeli, + $transactionDetail->penjual + ], + 'notification_id' => $notif->id + ]); + DB::commit(); return response()->json([ 'status' => true, 'message' => 'Refund berhasil dilakukan. Uang akan dikembalikan ke pembeli.', + 'receivers' => [ + $transactionDetail->pembeli, + $transactionDetail->penjual + ] ]); } catch (Throwable $e) { DB::rollBack(); @@ -98,7 +121,7 @@ class AdminRefundController extends Controller return response()->json([ 'status' => false, - 'message' => 'Refund gagal dilakukan', + 'message' => 'Refund gagal dilakukan' ]); } }else{ @@ -116,6 +139,7 @@ class AdminRefundController extends Controller public function denyRefund(Request $request) { $refund = Refund::where('id', $request->id)->first(); + $transactionDetail = Transaction::where('id', $refund->transaction_id)->first(); try { Transaction::where('id', $refund->transaction_id)->update([ @@ -136,11 +160,31 @@ class AdminRefundController extends Controller 'deskripsi' => 'Admin telah menolak refund. Transaksi akan diteruskan ke penjual. Alasan: '.$request->complaint, ]); + $url = route('user-transaction.show', ['id' => $transactionDetail->id]); + + $notif = Notification::create([ + 'title' => 'Refund Diterima', + 'content' => 'Refund ditolak dan transaksi akan diteruskan ke penjual. Klik disini untuk langsung ke detail transaksi.', + 'teaser' => 'Refund ditolak...', + ]); + + NotificationReceiver::create([ + 'receiver' => [ + $transactionDetail->pembeli, + $transactionDetail->penjual + ], + 'notification_id' => $notif->id + ]); + DB::commit(); return response()->json([ 'status' => true, 'message' => 'Refund berhasil ditolak. Transaksi diselesaikan dan uang disampaikan ke penjual.', + 'receivers' => [ + $transactionDetail->pembeli, + $transactionDetail->penjual + ] ]); } catch (Throwable $e) { DB::rollBack(); @@ -160,7 +204,7 @@ class AdminRefundController extends Controller $subQuery = Refund::join('transactions', 'refunds.transaction_id', '=', 'transactions.id') ->join('users as b', 'transactions.pembeli', '=', 'b.email') ->join('users as s', 'transactions.penjual', '=', 's.email') - ->latest() + ->latest('refunds.updated_at') ->select('refunds.id as id', DB::raw("CONCAT(b.nama_depan,' ', b.nama_belakang) as pembeli"), DB::raw("CONCAT(s.nama_depan,' ', s.nama_belakang) as penjual"), 'transactions.nama_barang as nama_barang', 'refunds.total as total', 'refunds.created_at', 'refunds.due_date', 'refunds.status'); if ($request->has('search') && !empty($request->search['value'])) { diff --git a/app/Http/Controllers/Admin/Setting/AdminSettingController.php b/app/Http/Controllers/Admin/Setting/AdminSettingController.php index d182fdc..74050b3 100644 --- a/app/Http/Controllers/Admin/Setting/AdminSettingController.php +++ b/app/Http/Controllers/Admin/Setting/AdminSettingController.php @@ -86,7 +86,7 @@ class AdminSettingController extends Controller public function listSetting(Request $request){ try{ - $subQuery = Setting::latest()->select('id','bulan','tahun','persentase','status'); + $subQuery = Setting::select('id','bulan','tahun','persentase','status')->orderBy('tahun', 'DESC')->orderBy('bulan', 'DESC'); if($request->has('search') && !empty($request->search['value'])){ $searchSetting = $request->search['value']; diff --git a/app/Http/Controllers/Admin/Transaction/AdminTransactionController.php b/app/Http/Controllers/Admin/Transaction/AdminTransactionController.php index ddbb842..29d6904 100644 --- a/app/Http/Controllers/Admin/Transaction/AdminTransactionController.php +++ b/app/Http/Controllers/Admin/Transaction/AdminTransactionController.php @@ -4,6 +4,8 @@ namespace App\Http\Controllers\Admin\Transaction; use App\Models\Transaction; use App\Http\Controllers\Controller; +use App\Models\Notification; +use App\Models\NotificationReceiver; use App\Models\TransactionDescription; use App\Models\TransactionUser; use Illuminate\Http\Request; @@ -52,6 +54,8 @@ class AdminTransactionController extends Controller $result = json_decode($response->body(), true); $code = $result['status_code']; + $transactionDetail = Transaction::where('id', $request->id)->first(); + if($code == '200'){ try { DB::beginTransaction(); @@ -71,11 +75,33 @@ class AdminTransactionController extends Controller 'deskripsi' => 'Admin telah menerima pembayaran transaksi dan dilanjutkan ke penjual.', ]); + $url = route('user-transaction.show', ['id' => $transactionDetail->id]); + + $notif = Notification::create([ + 'title' => 'Transaksi Diterima', + 'content' => 'Transaksi telah diterima dan akan dilanjutkan. Klik disini untuk langsung ke detail transaksi.', + 'teaser' => 'Transaksi telah diterima...', + ]); + + NotificationReceiver::create([ + 'receiver' => $transactionDetail->penjual, + 'notification_id' => $notif->id + ]); + + NotificationReceiver::create([ + 'receiver' => $transactionDetail->pembeli, + 'notification_id' => $notif->id + ]); + DB::commit(); return response()->json([ 'status' => true, - 'message' => 'Transaksi telah diterima.' + 'message' => 'Transaksi telah diterima.', + 'receivers' => [ + $transactionDetail->penjual, + $transactionDetail->pembeli + ] ]); } catch (Throwable $e) { DB::rollBack(); @@ -111,6 +137,8 @@ class AdminTransactionController extends Controller $result = json_decode($response->body(), true); $code = $result['status_code']; + $transactionDetail = Transaction::where('id', $request->id)->first(); + if($code == '200'){ try { DB::beginTransaction(); @@ -130,11 +158,26 @@ class AdminTransactionController extends Controller 'deskripsi' => 'Admin telah menolak pembayaran. Alasan: '.$request->compaint, ]); + $url = route('user-transaction.show', ['id' => $transactionDetail->id]); + + + $notif = Notification::create([ + 'title' => 'Transaksi Ditolak', + 'content' => 'Transaksi anda ditolak oleh Admin. Klik disini untuk langsung ke detail transaksi.', + 'teaser' => 'Transaksi anda ditolak...', + ]); + + NotificationReceiver::create([ + 'receiver' => $transactionDetail->pembeli, + 'notification_id' => $notif->id + ]); + DB::commit(); return response()->json([ 'status' => true, - 'message' => 'Transaksi telah ditolak.' + 'message' => 'Transaksi telah ditolak.', + 'receivers' => $transactionDetail->pembeli ]); } catch (Throwable $e) { DB::rollBack(); @@ -159,7 +202,7 @@ class AdminTransactionController extends Controller try { $subQuery = Transaction::join('users as b', 'transactions.pembeli', '=', 'b.email') ->join('users as s', 'transactions.penjual', '=', 's.email') - ->latest() + ->latest('transactions.updated_at') ->select('transactions.id', 'transactions.nama_barang', DB::raw("CONCAT(b.nama_depan,' ',b.nama_belakang) as nama_pembeli"), DB::raw("CONCAT(s.nama_depan,' ',s.nama_belakang) as nama_penjual"), 'transactions.total_harga', 'transactions.created_at', 'transactions.status_transaksi'); if ($request->has('search') && !empty($request->search['value'])) { diff --git a/app/Http/Controllers/Admin/User/AdminUserController.php b/app/Http/Controllers/Admin/User/AdminUserController.php index bf4974e..d76cbb4 100644 --- a/app/Http/Controllers/Admin/User/AdminUserController.php +++ b/app/Http/Controllers/Admin/User/AdminUserController.php @@ -4,9 +4,12 @@ namespace App\Http\Controllers\Admin\User; use App\Models\User; use App\Http\Controllers\Controller; +use App\Mail\approveUser; +use App\Mail\denyUser; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Mail; use Yajra\DataTables\DataTables; use Throwable; @@ -59,6 +62,13 @@ class AdminUserController extends Controller public function approveUser(Request $request) { + $user = User::where('id', $request->id)->first(); + $email = $user->email; + + $content = [ + 'email' => $email, + ]; + try { DB::beginTransaction(); @@ -66,6 +76,8 @@ class AdminUserController extends Controller 'status' => 'Finished', ]); + Mail::to($email)->send(new approveUser($content)); + DB::commit(); return response()->json([ @@ -81,6 +93,15 @@ class AdminUserController extends Controller public function denyUser(Request $request) { + $user = User::where('id', $request->id)->first(); + $email = $user->email; + $keterangan = $request->keterangan; + + $content = [ + 'keterangan' => $keterangan, + 'email' => $email, + ]; + try { DB::beginTransaction(); @@ -89,6 +110,8 @@ class AdminUserController extends Controller 'keterangan' => $request->keterangan, ]); + Mail::to($email)->send(new denyUser($content)); + DB::commit(); return response()->json([ @@ -107,7 +130,7 @@ class AdminUserController extends Controller try { $subQuery = User::where('role', 'User') ->orderByRaw("CASE WHEN status = 'Progress' THEN 1 WHEN status = 'Finished' THEN 2 WHEN status = 'Rejected' THEN 3 ELSE 4 END ASC") - ->latest() + ->latest('transactions.updated_at') ->select('users.id', DB::raw("CONCAT(users.nama_depan, ' ', users.nama_belakang) as nama_lengkap"), 'users.email', 'users.foto_profile', 'users.status', 'users.created_at as tanggal_daftar'); if ($request->has('search') && !empty($request->search['value'])) { @@ -146,6 +169,17 @@ class AdminUserController extends Controller $url . '">Detail + '; + if($row->status == 'Rejected'){ + $html_code .= ' +
  • Hapus +
  • + '; + } + $html_code .= ' '; return $html_code; diff --git a/app/Http/Controllers/Login/LoginController.php b/app/Http/Controllers/Login/LoginController.php index c4f2fdf..651e0a0 100644 --- a/app/Http/Controllers/Login/LoginController.php +++ b/app/Http/Controllers/Login/LoginController.php @@ -23,6 +23,7 @@ use Laravolt\Indonesia\Models\City; use Laravolt\Indonesia\Models\District; use Laravolt\Indonesia\Models\Province; use Laravolt\Indonesia\Models\Village; +use Pusher\Pusher; use Ramsey\Uuid\Uuid; class LoginController extends Controller @@ -263,6 +264,19 @@ class LoginController extends Controller DB::commit(); + $options = [ + 'cluster' => 'ap1', + 'useTLS' => true, + ]; + + $pusher = new Pusher('3e5bdc20dddd7fbc655e', 'f2274c37c616d29ff590', '1659859', $options); + + $payload = [ + 'service' => 'User' + ]; + + $pusher->trigger('chanel-update-notifikasi-untuk-admin', 'event-update-notifikasi-untuk-admin', $payload); + return response()->json([ 'status' => true, 'message' => 'Akun anda sudah terdaftar dan butuh verifikasi hingga maksimal 1 hari kerja', diff --git a/app/Http/Controllers/User/Contact/UserContactController.php b/app/Http/Controllers/User/Contact/UserContactController.php index 1311a97..f6c3fba 100644 --- a/app/Http/Controllers/User/Contact/UserContactController.php +++ b/app/Http/Controllers/User/Contact/UserContactController.php @@ -26,15 +26,15 @@ class UserContactController extends Controller { if($request->input == '' || $request->input == null){ $data = DB::table('contacts') - ->join('users', 'contacts.relasi_kontak', '=', 'users.email') ->select('contacts.relasi_kontak', 'users.nama_depan', 'users.nama_belakang') - ->where('contacts.pemilik_kontak', '=', Auth::user()->email) + ->join('users', 'contacts.relasi_kontak', '=', 'users.email') + ->where('contacts.pemilik_kontak', '=', auth()->user()->email) ->paginate(10); }else{ $data = DB::table('contacts') ->join('users', 'contacts.relasi_kontak', '=', 'users.email') ->select('contacts.relasi_kontak', 'users.nama_depan', 'users.nama_belakang') - ->where('contacts.pemilik_kontak', '=', Auth::user()->email) + ->where('contacts.pemilik_kontak', '=', auth()->user()->email) ->whereRaw(DB::raw("LOWER(CONCAT(users.nama_depan,' ',users.nama_belakang)) LIKE ?",['%'.strtolower($request->input).'%'])) ->paginate(10); } @@ -143,7 +143,8 @@ class UserContactController extends Controller ->select( 'contacts.id', DB::raw("CONCAT(users.nama_depan, ' ', users.nama_belakang) as nama_lengkap"), - ); + ) + ->orderBy('nama_lengkap'); if($request->has('search') && !empty($request->search['value'])){ $searchContact = $request->search['value']; diff --git a/app/Http/Controllers/User/Dashboard/UserDashboardController.php b/app/Http/Controllers/User/Dashboard/UserDashboardController.php index 28b5067..27bf535 100644 --- a/app/Http/Controllers/User/Dashboard/UserDashboardController.php +++ b/app/Http/Controllers/User/Dashboard/UserDashboardController.php @@ -4,56 +4,646 @@ namespace App\Http\Controllers\User\Dashboard; use App\Http\Controllers\Controller; use Illuminate\Http\Request; -use App\Models\RefundUser; use App\Models\Transaction; use Carbon\Carbon; -use Illuminate\Support\Facades\Auth; -use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Log; -use Throwable; +use DateInterval; +use DateTime; class UserDashboardController extends Controller { public function index() { - $currentMonth = Carbon::now()->month; - $currentYear = Carbon::now()->year; - $currentRole = 'Pembeli'; + $today = new DateTime(); + $todayDate = $today->format('Y-m-d'); + $pickDate = new DateTime(); + $interval = new DateInterval('P29D'); + $start = $pickDate->sub($interval); + $startDate = $start->format('Y-m-d'); - $countCreated = Transaction::where('status_transaksi', 'created') - ->whereMonth('updated_at', $currentMonth) - ->whereYear('updated_at', $currentYear) - ->where('pembeli', auth()->user()->email) - ->count(); + $intervalBefore = new DateInterval('P1D'); + $intervalBeforeStart = new DateInterval('P29D'); + $endBefore = $pickDate->sub($intervalBefore); + $endBeforeDate = $endBefore->format('Y-m-d'); + $startBefore = $pickDate->sub($intervalBeforeStart); + $startBeforeDate = $startBefore->format('Y-m-d'); - $countPending = Transaction::where('status_pembayaran', 'pending') - ->whereMonth('updated_at', $currentMonth) - ->whereYear('updated_at', $currentYear) - ->where('pembeli', auth()->user()->email) - ->count(); + // Semua + $countAllFinished = Transaction::whereIn('status_transaksi', ['finished', 'done']) + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->count(); - $countFailure = Transaction::whereIn('status_pembayaran', ['cancel', 'expire', 'failure']) - ->whereMonth('updated_at', $currentMonth) - ->whereYear('updated_at', $currentYear) - ->where('pembeli', auth()->user()->email) - ->count(); + $countAllPending = Transaction::where('status_transaksi', 'created') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->count(); - $sumRefund = ''; + $countAllProcessed = Transaction::whereIn('status_transaksi', ['process', 'sending', 'sent']) + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->count(); - $sumTransaksi = ''; + $countAllCanceled = Transaction::where('status_transaksi', 'failure') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->count(); - return view('user.index'); + $countAllRefund = Transaction::where('status_transaksi', 'refund') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->count(); + + $countAllIndicated = Transaction::where('status_transaksi', 'challenge') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->count(); + + // Pembeli + $countBuyerFinished = Transaction::whereIn('status_transaksi', ['finished', 'done']) + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('pembeli', auth()->user()->email) + ->count(); + + $countBuyerPaid = Transaction::where('status_transaksi', 'success') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('pembeli', auth()->user()->email) + ->count(); + + $countBuyerPending = Transaction::where('status_transaksi', 'created') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('pembeli', auth()->user()->email) + ->count(); + + $countBuyerProcessed = Transaction::whereIn('status_transaksi', ['process', 'sending', 'sent']) + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('pembeli', auth()->user()->email) + ->count(); + + $countBuyerCancelled = Transaction::where('status_transaksi', 'failure') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('pembeli', auth()->user()->email) + ->count(); + + $countBuyerRefundPending = Transaction::join('refunds', 'refunds.transaction_id', '=', 'transactions.id') + ->where('refunds.status', 'pending') + ->whereDate('transactions.created_at', '>=', $startDate) + ->whereDate('transactions.created_at', '<=', $todayDate) + ->where('pembeli', auth()->user()->email) + ->count(); + + $countBuyerRefundApproved = Transaction::join('refunds', 'refunds.transaction_id', '=', 'transactions.id') + ->where('refunds.status', 'refund') + ->whereDate('transactions.created_at', '>=', $startDate) + ->whereDate('transactions.created_at', '<=', $todayDate) + ->where('pembeli', auth()->user()->email) + ->count(); + + $countBuyerRefundDenied = Transaction::join('refunds', 'refunds.transaction_id', '=', 'transactions.id') + ->where('refunds.status', 'deny') + ->whereDate('transactions.created_at', '>=', $startDate) + ->whereDate('transactions.created_at', '<=', $todayDate) + ->where('pembeli', auth()->user()->email) + ->count(); + + $countBuyerIndicated = Transaction::where('status_transaksi', 'challenge') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('pembeli', auth()->user()->email) + ->count(); + + // Penjual + $countSellerPending = Transaction::where('status_transaksi', 'success') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('penjual', auth()->user()->email) + ->count(); + + $countSellerFinished = Transaction::whereIn('status_transaksi', ['done', 'finished']) + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('penjual', auth()->user()->email) + ->count(); + + $countSellerProcessed = Transaction::where('status_transaksi', 'process') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('penjual', auth()->user()->email) + ->count(); + + $countSellerSending = Transaction::where('status_transaksi', 'sending') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('penjual', auth()->user()->email) + ->count(); + + $countSellerSent = Transaction::where('status_transaksi', 'sent') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('penjual', auth()->user()->email) + ->count(); + + $countSellerCancelled = Transaction::where('status_transaksi', 'failure') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('penjual', auth()->user()->email) + ->count(); + + $countSellerRefund = Transaction::where('status_transaksi', 'refund') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('penjual', auth()->user()->email) + ->count(); + + $countSellerIndicated = Transaction::where('status_transaksi', 'challenge') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('penjual', auth()->user()->email) + ->count(); + + $totalTransaction = Transaction::whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->count(); + + $totalTransactionSebelum = Transaction::whereDate('created_at', '>=', $startBeforeDate) + ->whereDate('created_at', '<=', $endBeforeDate) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->count(); + + $rateTransaction = floatval((floatval($totalTransaction) - floatval($totalTransactionSebelum)) * 100) / ($totalTransactionSebelum == 0 ? 1 : floatval($totalTransactionSebelum)); + + $totalPemasukan = Transaction::where('status_transaksi', 'done') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('penjual', auth()->user()->email) + ->sum('total_harga'); + + $totalPemasukanSebelum = Transaction::where('status_transaksi', 'done') + ->whereDate('created_at', '>=', $startBeforeDate) + ->whereDate('created_at', '<=', $endBeforeDate) + ->where('penjual', auth()->user()->email) + ->sum('total_harga'); + + $ratePemasukan = floatval((floatval($totalPemasukan) - floatval($totalPemasukanSebelum)) * 100) / ($totalPemasukanSebelum == 0 ? 1 : floatval($totalPemasukanSebelum)); + + $totalPengeluaran = Transaction::whereIn('status_transaksi', ['finished','done']) + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('pembeli', auth()->user()->email) + ->sum('total_harga'); + + $totalPengeluaranSebelum = Transaction::whereIn('status_transaksi', ['finished','done']) + ->whereDate('created_at', '>=', $startBeforeDate) + ->whereDate('created_at', '<=', $endBeforeDate) + ->where('pembeli', auth()->user()->email) + ->sum('total_harga'); + + $ratePengeluaran = floatval(((floatval($totalPengeluaran) - floatval($totalPengeluaranSebelum)) * 100) / ($totalPengeluaranSebelum == 0 ? 1 : floatval($totalPengeluaranSebelum))); + + $totalProfit = Transaction::whereIn('status_transaksi', ['done', 'finished']) + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->sum('total_harga'); + + $totalProfitSebelum = Transaction::whereIn('status_transaksi', ['done', 'finished']) + ->whereDate('created_at', '>=', $startBeforeDate) + ->whereDate('created_at', '<=', $endBeforeDate) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->sum('total_harga'); + + $rateProfit = floatval(((floatval($totalProfit) - floatval($totalProfitSebelum))*100)/($totalProfitSebelum == 0 ? 1 : floatval($totalProfitSebelum))); + + $dataLabel = []; + $dataChartTransaction = []; + $dataChartRefund = []; + $dataChartPemasukan = []; + $dataChartPengeluaran = []; + + $startDate = $start; + $intervalDate = new DateInterval('P1D'); + $todayDate = $today; + $endDate = $todayDate->add($intervalDate); + + for ($date = clone $startDate; $date <= $endDate; $date->modify('+1 day')) { + $transaction = Transaction::whereIn('status_transaksi', ['done', 'finished']) + ->whereDate('created_at', $date->format('Y-m-d')) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->sum('total_keuntungan'); + + $refund = Transaction::join('refunds','refunds.transaction_id','=','transactions.id') + ->where('status_transaksi', 'refund') + ->where('status','refund') + ->whereDate('transactions.created_at', $date->format('Y-m-d')) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->sum('total_keuntungan'); + + $pemasukan = Transaction::whereIn('status_transaksi', ['done', 'finished']) + ->where('penjual', auth()->user()->email) + ->whereDate('created_at', $date->format('Y-m-d')) + ->sum('total_harga'); + + $pengeluaran = Transaction::whereIn('status_transaksi', ['done', 'finished']) + ->where('pembeli', auth()->user()->email) + ->whereDate('created_at', $date->format('Y-m-d')) + ->sum('total_harga'); + + $dataChartTransaction[] = floatval($transaction); + $dataChartRefund[] = floatval($refund); + $dataChartPemasukan[] = floatval($pemasukan); + $dataChartPengeluaran[] = floatval($pengeluaran); + $dataLabel[] = $date->format('d/m/Y'); + } + + return view('user.index', compact( + 'countAllFinished', + 'countAllPending', + 'countAllProcessed', + 'countAllCanceled', + 'countAllRefund', + 'countAllIndicated', + 'countBuyerFinished', + 'countBuyerPaid', + 'countBuyerPending', + 'countBuyerProcessed', + 'countBuyerCancelled', + 'countBuyerRefundPending', + 'countBuyerRefundApproved', + 'countBuyerRefundDenied', + 'countBuyerIndicated', + 'countSellerPending', + 'countSellerFinished', + 'countSellerProcessed', + 'countSellerSending', + 'countSellerSent', + 'countSellerCancelled', + 'countSellerRefund', + 'countSellerIndicated', + 'totalTransaction', + 'rateTransaction', + 'totalPemasukan', + 'ratePemasukan', + 'totalPengeluaran', + 'ratePengeluaran', + 'rateProfit', + 'dataLabel', + 'dataChartTransaction', + 'dataChartRefund', + 'dataChartPemasukan', + 'dataChartPengeluaran' + )); } - public function getSelectedChart(){ - $currentMonth = Carbon::now()->month; - $currentYear = Carbon::now()->year; - $currentRole = 'Pembeli'; + public function getDataBySearch(Request $request) + { + $startDate = $request->startDate; + $todayDate = $request->endDate; + $pickDate = new DateTime($startDate); + $start = new DateTime($startDate); + $today = new DateTime($todayDate); + $interval = $start->diff($today); - if($currentRole == 'Pembeli'){ + $intervalBefore = new DateInterval('P1D'); + $intervalBeforeStart = new DateInterval('P'.$interval->format('%a').'D'); + $endBefore = $pickDate->sub($intervalBefore); + $endBeforeDate = $endBefore->format('Y-m-d'); + $startBefore = $pickDate->sub($intervalBeforeStart); + $startBeforeDate = $startBefore->format('Y-m-d'); - }else{ + // Semua + $countAllFinished = Transaction::where('status_transaksi', 'Finished') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->count(); + $countAllPending = Transaction::where('status_transaksi', 'created') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->count(); + + $countAllProcessed = Transaction::whereIn('status_transaksi', ['process', 'sending', 'sent']) + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->count(); + + $countAllCanceled = Transaction::where('status_transaksi', 'failure') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->count(); + + $countAllRefund = Transaction::where('status_transaksi', 'refund') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->count(); + + $countAllIndicated = Transaction::where('status_transaksi', 'challenge') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->count(); + + // Pembeli + $countBuyerFinished = Transaction::where('status_transaksi', 'finished') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('pembeli', auth()->user()->email) + ->count(); + + $countBuyerPaid = Transaction::where('status_transaksi', 'success') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('pembeli', auth()->user()->email) + ->count(); + + $countBuyerPending = Transaction::where('status_transaksi', 'created') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('pembeli', auth()->user()->email) + ->count(); + + $countBuyerProcessed = Transaction::whereIn('status_transaksi', ['process', 'sending', 'sent']) + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('pembeli', auth()->user()->email) + ->count(); + + $countBuyerCancelled = Transaction::where('status_transaksi', 'failure') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('pembeli', auth()->user()->email) + ->count(); + + $countBuyerRefundPending = Transaction::join('refunds', 'refunds.transaction_id', '=', 'transactions.id') + ->where('refunds.status', 'pending') + ->whereDate('transactions.created_at', '>=', $startDate) + ->whereDate('transactions.created_at', '<=', $todayDate) + ->where('pembeli', auth()->user()->email) + ->count(); + + $countBuyerRefundApproved = Transaction::join('refunds', 'refunds.transaction_id', '=', 'transactions.id') + ->where('refunds.status', 'refund') + ->whereDate('transactions.created_at', '>=', $startDate) + ->whereDate('transactions.created_at', '<=', $todayDate) + ->where('pembeli', auth()->user()->email) + ->count(); + + $countBuyerRefundDenied = Transaction::join('refunds', 'refunds.transaction_id', '=', 'transactions.id') + ->where('refunds.status', 'deny') + ->whereDate('transactions.created_at', '>=', $startDate) + ->whereDate('transactions.created_at', '<=', $todayDate) + ->where('pembeli', auth()->user()->email) + ->count(); + + $countBuyerIndicated = Transaction::where('status_transaksi', 'challenge') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('pembeli', auth()->user()->email) + ->count(); + + // Penjual + $countSellerPending = Transaction::where('status_transaksi', 'success') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('penjual', auth()->user()->email) + ->count(); + + $countSellerFinished = Transaction::where('status_transaksi', 'done') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('penjual', auth()->user()->email) + ->count(); + + $countSellerProcessed = Transaction::where('status_transaksi', 'process') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('penjual', auth()->user()->email) + ->count(); + + $countSellerSending = Transaction::where('status_transaksi', 'sending') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('penjual', auth()->user()->email) + ->count(); + + $countSellerSent = Transaction::where('status_transaksi', 'sent') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('penjual', auth()->user()->email) + ->count(); + + $countSellerCancelled = Transaction::where('status_transaksi', 'failure') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('penjual', auth()->user()->email) + ->count(); + + $countSellerRefund = Transaction::where('status_transaksi', 'refund') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('penjual', auth()->user()->email) + ->count(); + + $countSellerIndicated = Transaction::where('status_transaksi', 'challenge') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('penjual', auth()->user()->email) + ->count(); + + $totalTransaction = Transaction::whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->count(); + + $totalTransactionSebelum = Transaction::whereDate('created_at', '>=', $startBeforeDate) + ->whereDate('created_at', '<=', $endBeforeDate) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->count(); + + $rateTransaction = floatval((floatval($totalTransaction) - floatval($totalTransactionSebelum)) * 100) / ($totalTransactionSebelum == 0 ? 1 : floatval($totalTransactionSebelum)); + + $totalPemasukan = Transaction::where('status_transaksi', 'done') + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('penjual', auth()->user()->email) + ->sum('total_harga'); + + $totalPemasukanSebelum = Transaction::where('status_transaksi', 'done') + ->whereDate('created_at', '>=', $startBeforeDate) + ->whereDate('created_at', '<=', $endBeforeDate) + ->where('penjual', auth()->user()->email) + ->sum('total_harga'); + + $ratePemasukan = floatval((floatval($totalPemasukan) - floatval($totalPemasukanSebelum)) * 100) / ($totalPemasukanSebelum == 0 ? 1 : floatval($totalPemasukanSebelum)); + + $totalPengeluaran = Transaction::whereIn('status_transaksi', ['finished','done']) + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where('pembeli', auth()->user()->email) + ->sum('total_harga'); + + $totalPengeluaranSebelum = Transaction::whereIn('status_transaksi', ['finished','done']) + ->whereDate('created_at', '>=', $startBeforeDate) + ->whereDate('created_at', '<=', $endBeforeDate) + ->where('pembeli', auth()->user()->email) + ->sum('total_harga'); + + $ratePengeluaran = floatval(((floatval($totalPengeluaran) - floatval($totalPengeluaranSebelum)) * 100) / ($totalPengeluaranSebelum == 0 ? 1 : floatval($totalPengeluaranSebelum))); + + $totalProfit = Transaction::whereIn('status_transaksi', ['done', 'finished']) + ->whereDate('created_at', '>=', $startDate) + ->whereDate('created_at', '<=', $todayDate) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->sum('total_harga'); + + $totalProfitSebelum = Transaction::whereIn('status_transaksi', ['done', 'finished']) + ->whereDate('created_at', '>=', $startBeforeDate) + ->whereDate('created_at', '<=', $endBeforeDate) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->sum('total_harga'); + + $rateProfit = floatval(((floatval($totalProfit) - floatval($totalProfitSebelum))*100)/($totalProfitSebelum == 0 ? 1 : floatval($totalProfitSebelum))); + + $dataLabel = []; + $dataChartTransaction = []; + $dataChartRefund = []; + $dataChartPemasukan = []; + $dataChartPengeluaran = []; + + $first = $start; + $intervalDate = new DateInterval('P1D'); + $lastDate = $today; + $last = $lastDate->add($intervalDate); + + for ($date = clone $first; $date <= $last; $date->modify('+1 day')) { + $transaction = Transaction::whereIn('status_transaksi', ['done', 'finished']) + ->whereDate('created_at', $date->format('Y-m-d')) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->sum('total_keuntungan'); + + $refund = Transaction::join('refunds','refunds.transaction_id','=','transactions.id') + ->where('status_transaksi', 'refund') + ->where('status','refund') + ->whereDate('transactions.created_at', $date->format('Y-m-d')) + ->where(function ($a) { + $a->where('pembeli', auth()->user()->email)->orWhere('penjual', auth()->user()->email); + }) + ->sum('total_keuntungan'); + + $pemasukan = Transaction::whereIn('status_transaksi', ['done', 'finished']) + ->where('penjual', auth()->user()->email) + ->whereDate('created_at', $date->format('Y-m-d')) + ->sum('total_harga'); + + $pengeluaran = Transaction::whereIn('status_transaksi', ['done', 'finished']) + ->where('pembeli', auth()->user()->email) + ->whereDate('created_at', $date->format('Y-m-d')) + ->sum('total_harga'); + + $dataChartTransaction[] = floatval($transaction); + $dataChartRefund[] = floatval($refund); + $dataChartPemasukan[] = floatval($pemasukan); + $dataChartPengeluaran[] = floatval($pengeluaran); + $dataLabel[] = $date->format('d/m/Y'); } + + return response()->json([ + 'countAllFinished' => $countAllFinished, + 'countAllPending' => $countAllPending, + 'countAllProcessed' => $countAllProcessed, + 'countAllCanceled' => $countAllCanceled, + 'countAllRefund' => $countAllRefund, + 'countAllIndicated' => $countAllIndicated, + 'countBuyerFinished' => $countBuyerFinished, + 'countBuyerPaid' => $countBuyerPaid, + 'countBuyerPending' => $countBuyerPending, + 'countBuyerProcessed' => $countBuyerProcessed, + 'countBuyerCancelled' => $countBuyerCancelled, + 'countBuyerRefundPending' => $countBuyerRefundPending, + 'countBuyerRefundApproved' => $countBuyerRefundApproved, + 'countBuyerRefundDenied' => $countBuyerRefundDenied, + 'countBuyerIndicated' => $countBuyerIndicated, + 'countSellerPending' => $countSellerPending, + 'countSellerFinished' => $countSellerFinished, + 'countSellerProcessed' => $countSellerProcessed, + 'countSellerSending' => $countSellerSending, + 'countSellerSent' => $countSellerSent, + 'countSellerCancelled' => $countSellerCancelled, + 'countSellerRefund' => $countSellerRefund, + 'countSellerIndicated' => $countSellerIndicated, + 'totalTransaction' => $totalTransaction, + 'rateTransaction' => $rateTransaction, + 'totalPemasukan' => $totalPemasukan, + 'ratePemasukan' => $ratePemasukan, + 'totalPengeluaran' => $totalPengeluaran, + 'ratePengeluaran' => $ratePengeluaran, + 'rateProfit' => $rateProfit, + 'dataLabel' => $dataLabel, + 'dataChartTransaction' => $dataChartTransaction, + 'dataChartRefund' => $dataChartRefund, + 'dataChartPemasukan' => $dataChartPemasukan, + 'dataChartPengeluaran' => $dataChartPengeluaran + ]); } } diff --git a/app/Http/Controllers/User/Notification/UserNotification.php b/app/Http/Controllers/User/Notification/UserNotification.php index 5d9688b..5bf1eb1 100644 --- a/app/Http/Controllers/User/Notification/UserNotification.php +++ b/app/Http/Controllers/User/Notification/UserNotification.php @@ -8,6 +8,7 @@ use App\Models\NotificationReceiver; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; +use Pusher\Pusher; use Throwable; use Yajra\DataTables\Facades\DataTables; @@ -23,7 +24,7 @@ class UserNotification extends Controller try { $subQuery = Notification::join('notification_receivers','notifications.id','=','notification_receivers.notification_id') ->where('notification_receivers.receiver','=',auth()->user()->email) - ->latest() + ->latest('notification_receivers.updated_at') ->select('notifications.id', 'notifications.title', 'notifications.teaser', 'notification_receivers.created_at', 'notification_receivers.status'); if ($request->has('search') && !empty($request->search['value'])) { @@ -114,13 +115,53 @@ class UserNotification extends Controller public function markAllAsRead() { - NotificationReceiver::where('receiver', auth()->user()->email)->update([ + $result = NotificationReceiver::where('receiver', auth()->user()->email)->update([ 'status' => 'read', ]); - return response()->json([ - 'status' => true, - 'message' => 'Berhasil', - ]); + if($result){ + return response()->json([ + 'status' => true, + 'message' => 'Berhasil', + ]); + }else{ + return response()->json([ + 'status' => false, + 'message' => 'Gagal', + ]); + Log::error($result); + } + } + + public function updateNewNotification(Request $request) + { + $options = [ + 'cluster' => 'ap1', + 'useTLS' => true, + ]; + + $pusher = new Pusher('3e5bdc20dddd7fbc655e', 'f2274c37c616d29ff590', '1659859', $options); + + $payload = [ + 'receivers' => $request->receiver, + ]; + + $pusher->trigger('chanel-update-notifikasi', 'event-update-notifikasi', $payload); + } + + public function updateNotificationToAdmin(Request $request) + { + $options = [ + 'cluster' => 'ap1', + 'useTLS' => true, + ]; + + $pusher = new Pusher('3e5bdc20dddd7fbc655e', 'f2274c37c616d29ff590', '1659859', $options); + + $payload = [ + 'service' => $request->service + ]; + + $pusher->trigger('chanel-update-notifikasi-untuk-admin', 'event-update-notifikasi-untuk-admin', $payload); } } diff --git a/app/Http/Controllers/User/Pembeli/PembeliController.php b/app/Http/Controllers/User/Pembeli/PembeliController.php index d65ec84..0429467 100644 --- a/app/Http/Controllers/User/Pembeli/PembeliController.php +++ b/app/Http/Controllers/User/Pembeli/PembeliController.php @@ -4,6 +4,8 @@ namespace App\Http\Controllers\User\Pembeli; use App\Http\Controllers\Controller; use App\Models\Contact; +use App\Models\Notification; +use App\Models\NotificationReceiver; use App\Models\Refund; use App\Models\Setting; use App\Models\Transaction; @@ -15,6 +17,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; +use Pusher\Pusher; use Throwable; use Yajra\DataTables\DataTables; @@ -84,7 +87,6 @@ class PembeliController extends Controller $batas_pembayaran = $now->addDays(1)->toTimeString(); $batas_konfirmasi_transaksi = $now->addDays(2)->toDateTimeString(); - $batas_pengiriman_barang_awal = $now->addDays(3)->toDateTimeString(); $batas_pengiriman_barang_akhir = $now->addDays(4)->toDateTimeString(); $status = 'created'; @@ -109,7 +111,6 @@ class PembeliController extends Controller 'status_transaksi' => $status, 'batas_pembayaran' => $batas_pembayaran, 'batas_konfirmasi_transaksi' => $batas_konfirmasi_transaksi, - 'batas_pengiriman_barang_awal' => $batas_pengiriman_barang_awal, 'batas_pengiriman_barang_akhir' => $batas_pengiriman_barang_akhir, ]); @@ -214,6 +215,8 @@ class PembeliController extends Controller public function finishTransaction(Request $request) { + $transactionDetail = Transaction::where('id', $request->id)->first(); + try { DB::beginTransaction(); @@ -231,11 +234,23 @@ class PembeliController extends Controller 'deskripsi' => 'Pesanan telah diselesaikan oleh ' . auth()->user()->nama_depan . '. Uang akan dikirim ke penjual.', ]); + $notif = Notification::create([ + 'title' => 'Transaksi Selesai', + 'content' => auth()->user()->nama_depan.' telah menyelesaikan transaksi. Silahkan terima uang anda.', + 'teaser' => auth()->user()->nama_depan.' telah...' + ]); + + NotificationReceiver::create([ + 'receiver' => $transactionDetail->penjual, + 'notification_id' => $notif->id + ]); + DB::commit(); return response()->json([ 'status' => true, 'message' => 'Pesanan anda selesai dan uang akan dikirim ke penjual. Terima kasih telah menggunakan Rekber.', + 'receiver' => $transactionDetail->penjual ]); } catch (Throwable $e) { DB::rollBack(); @@ -253,6 +268,8 @@ class PembeliController extends Controller { $auth = base64_encode(env('MIDTRANS_SERVER_KEY')); + $transactionDetail = Transaction::where('id', $request->id)->first(); + $response = Http::withOptions([ 'verify' => false, ]) @@ -307,11 +324,25 @@ class PembeliController extends Controller 'user' => auth()->user()->email, ]); + $url = route('user-transaction.show', ['id' => $transactionDetail->id]); + + $notif = Notification::create([ + 'title' => 'Pembayaran Sukses', + 'content' => auth()->user()->nama_depan.' telah membayar transaksi. Silahkan proses transaksi ini jika memang dituju kepada anda. Klik disini untuk langsung ke detail transaksi.', + 'teaser' => auth()->user()->nama_depan.' telah...' + ]); + + NotificationReceiver::create([ + 'receiver' => $transactionDetail->penjual, + 'notification_id' => $notif->id + ]); + DB::commit(); return response()->json([ 'status' => true, 'message' => 'Pembayaran sukses', + 'receiver' => $transactionDetail->penjual ]); } elseif ($transaction == 'challenge') { TransactionDescription::create([ @@ -324,6 +355,19 @@ class PembeliController extends Controller 'keterangan' => $result['status_message'], ]); + $options = [ + 'cluster' => 'ap1', + 'useTLS' => true, + ]; + + $pusher = new Pusher('3e5bdc20dddd7fbc655e', 'f2274c37c616d29ff590', '1659859', $options); + + $payload = [ + 'service' => 'Transaksi' + ]; + + $pusher->trigger('chanel-update-notifikasi-untuk-admin', 'event-update-notifikasi-untuk-admin', $payload); + DB::commit(); return response()->json([ @@ -471,11 +515,25 @@ class PembeliController extends Controller 'deskripsi' => 'Transaksi dibatalkan oleh ' . auth()->user()->nama_depan . '. Alasan : ' . $request->complaint, ]); + $url = route('user-transaction.show', ['id' => $transaction->id]); + + $notif = Notification::create([ + 'title' => 'Transaksi Dibatalkan', + 'content' => auth()->user()->nama_depan.' telah membatalkan transaksi. Klik disini untuk langsung ke detail transaksi.', + 'teaser' => auth()->user()->nama_depan.' telah...' + ]); + + NotificationReceiver::create([ + 'receiver' => $transaction->penjual, + 'notification_id' => $notif->id + ]); + DB::commit(); return response()->json([ 'status' => true, 'message' => 'Transaksi telah dibatalkan.', + 'receiver' => $transaction->penjual ]); } catch (Throwable $e) { DB::rollBack(); @@ -740,7 +798,8 @@ class PembeliController extends Controller 'transactions.created_at', 'transactions.status_transaksi', 'transactions.token' - ); + ) + ->latest('transactions.updated_at'); if($request->has('search') && !empty($request->search['value'])){ $searchPembeli = $request->search['value']; diff --git a/app/Http/Controllers/User/Penjual/PenjualController.php b/app/Http/Controllers/User/Penjual/PenjualController.php index ade1002..4fffa99 100644 --- a/app/Http/Controllers/User/Penjual/PenjualController.php +++ b/app/Http/Controllers/User/Penjual/PenjualController.php @@ -3,6 +3,8 @@ namespace App\Http\Controllers\User\Penjual; use App\Http\Controllers\Controller; +use App\Models\Notification; +use App\Models\NotificationReceiver; use App\Models\Refund; use App\Models\Transaction; use App\Models\TransactionDescription; @@ -26,7 +28,8 @@ class PenjualController extends Controller try { $subQuery = Transaction::join('users', 'transactions.pembeli', '=', 'users.email') ->where('transactions.penjual', auth()->user()->email) - ->select('transactions.id', DB::raw("CONCAT(users.nama_depan,' ',users.nama_belakang) as nama_pembeli"), 'transactions.nama_barang', 'transactions.total_harga', 'transactions.created_at', 'transactions.status_transaksi'); + ->select('transactions.id', DB::raw("CONCAT(users.nama_depan,' ',users.nama_belakang) as nama_pembeli"), 'transactions.nama_barang', 'transactions.total_harga', 'transactions.created_at', 'transactions.status_transaksi') + ->latest('transactions.updated_at'); if ($request->has('search') && !empty($request->search['value'])) { $searchPenjual = $request->search['value']; @@ -103,7 +106,7 @@ class PenjualController extends Controller '; } - if ($row->status_transaksi == 'progress') { + if ($row->status_transaksi == 'process') { $html_code .= '
  • id)->first(); + try { DB::beginTransaction(); @@ -172,11 +177,25 @@ class PenjualController extends Controller 'deskripsi' => 'Transaksi telah diterima oleh ' . auth()->user()->nama_depan, ]); + $url = route('user-transaction.show', ['id' => $transactionDetail->id]); + + $notif = Notification::create([ + 'title' => 'Transaksi Diproses', + 'content' => auth()->user()->nama_depan.' telah menerima dan memproses transaksi. Klik disini untuk langsung ke detail transaksi.', + 'teaser' => auth()->user()->nama_depan.' telah...' + ]); + + NotificationReceiver::create([ + 'receiver' => $transactionDetail->pembeli, + 'notification_id' => $notif->id + ]); + DB::commit(); return response()->json([ 'status' => true, 'message' => 'Transaksi telah diterima. Siapkan pesanan untuk dikirim ke penjual.', + 'receiver' => $transactionDetail->pembeli ]); } catch (Throwable $e) { DB::rollBack(); @@ -241,11 +260,25 @@ class PenjualController extends Controller 'deskripsi' => 'Transaksi ditolak ' . auth()->user()->nama_depan . ', uang akan dikembalikan ke pembeli. Alasan : ' . $request->complaint, ]); + $url = route('user-transaction.show', ['id' => $transaction->id]); + + $notif = Notification::create([ + 'title' => 'Transaksi Diproses', + 'content' => auth()->user()->nama_depan.' telah menolak transaksi.Klik disini untuk langsung ke detail transaksi.', + 'teaser' => auth()->user()->nama_depan.' telah...' + ]); + + NotificationReceiver::create([ + 'receiver' => $transaction->pembeli, + 'notification_id' => $notif->id + ]); + DB::commit(); return response()->json([ 'status' => true, 'message' => 'Transaksi telah ditolak. Uang akan dikirimkan ke pembeli.', + 'receiver' => $transaction->pembeli ]); } catch (Throwable $e) { DB::rollBack(); @@ -305,6 +338,8 @@ class PenjualController extends Controller public function sentOrder(Request $request) { + $transactionDetail = Transaction::where('id', $request->transaction_id)->first(); + try { DB::beginTransaction(); @@ -332,11 +367,25 @@ class PenjualController extends Controller 'bukti_foto' => $bukti_foto, ]); + $url = route('user-transaction.show', ['id' => $transactionDetail->id]); + + $notif = Notification::create([ + 'title' => 'Transaksi Sudah Tiba', + 'content' => 'Transaksi sudah tiba dan silahkan periksa terlebih dahulu sebelum menyelesaikan transaksi atau mengajukan refund. Klik disini untuk langsung ke detail transaksi.', + 'teaser' => 'Transaksi sudah tiba dan silahkan per...', + ]); + + NotificationReceiver::create([ + 'receiver' => $transactionDetail->pembeli, + 'notification_id' => $notif->id + ]); + DB::commit(); return response()->json([ 'status' => true, 'message' => 'Pesanan telah sampai di tempat pembeli.', + 'receiver' => $transactionDetail->pembeli ]); } catch (Throwable $e) { DB::rollBack(); diff --git a/app/Http/Controllers/User/Refund/UserRefundController.php b/app/Http/Controllers/User/Refund/UserRefundController.php index 317e4c4..a94b207 100644 --- a/app/Http/Controllers/User/Refund/UserRefundController.php +++ b/app/Http/Controllers/User/Refund/UserRefundController.php @@ -83,6 +83,7 @@ class UserRefundController extends Controller return response()->json([ 'status' => true, 'message' => 'Permintaan refund anda telah dikirim ke admin untuk direview. Mohon tunggu maksimal 2 hari.', + 'service' => 'Refund' ]); }catch(Throwable $e){ DB::rollback(); @@ -115,7 +116,8 @@ class UserRefundController extends Controller 'refunds.status', 'transactions.nama_barang', DB::raw("CONCAT(s.nama_depan,' ',s.nama_belakang) as nama_penjual"), - ); + ) + ->latest('refunds.updated_at'); if($request->has('search') && !empty($request->search['value'])){ $searchRefund = $request->search['value']; diff --git a/app/Mail/approveUser.php b/app/Mail/approveUser.php new file mode 100644 index 0000000..4fe6325 --- /dev/null +++ b/app/Mail/approveUser.php @@ -0,0 +1,59 @@ +content = $content; + } + + /** + * Get the message envelope. + */ + // public function envelope(): Envelope + // { + // return new Envelope( + // subject: 'Approve User', + // ); + // } + + /** + * Get the message content definition. + */ + // public function content(): Content + // { + // return new Content( + // view: 'view.name', + // ); + // } + + /** + * Get the attachments for the message. + * + * @return array + */ + // public function attachments(): array + // { + // return []; + // } + + public function build(){ + return $this->subject('Pendaftaran Akun Sukses')->view('email.approve-user-email'); + } +} diff --git a/app/Mail/denyUser.php b/app/Mail/denyUser.php new file mode 100644 index 0000000..1c8ec4a --- /dev/null +++ b/app/Mail/denyUser.php @@ -0,0 +1,59 @@ +content = $content; + } + + /** + * Get the message envelope. + */ + // public function envelope(): Envelope + // { + // return new Envelope( + // subject: 'Deny User', + // ); + // } + + /** + * Get the message content definition. + */ + // public function content(): Content + // { + // return new Content( + // view: 'view.name', + // ); + // } + + /** + * Get the attachments for the message. + * + * @return array + */ + // public function attachments(): array + // { + // return []; + // } + + public function build(){ + return $this->subject('Pendaftaran Akun Gagal')->view('email.deny-user-email'); + } +} diff --git a/app/Models/transaction.php b/app/Models/transaction.php index 2472671..ff02bb3 100644 --- a/app/Models/transaction.php +++ b/app/Models/transaction.php @@ -30,7 +30,6 @@ class Transaction extends Model 'status_transaksi', 'status_pembayaran', 'batas_pembayaran', - 'batas_pengiriman_barang_awal', 'batas_pengiriman_barang_akhir', 'nama_bank_penjual', 'no_rek_penjual' diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index a324d5b..a915de8 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -34,7 +34,8 @@ class UserFactory extends Factory 'status'=> $this->faker->randomElement(['Progress', 'Finished', 'Rejected']), 'gender' => $this->faker->randomElement(['Laki-laki', 'Perempuan']), 'kode_kelurahan' => '1101012002', - 'keterangan' => $this->faker->sentence + 'keterangan' => $this->faker->sentence, + 'foto_profile' => 'face'.random_int(1,10).'.jpg' ]; } diff --git a/database/migrations/2023_08_01_073859_create_transactions_table.php b/database/migrations/2023_08_01_073859_create_transactions_table.php index e1c9da9..6df18e4 100644 --- a/database/migrations/2023_08_01_073859_create_transactions_table.php +++ b/database/migrations/2023_08_01_073859_create_transactions_table.php @@ -33,7 +33,6 @@ return new class extends Migration $table->enum('status_pembayaran',['settlement','capture','pending','expire','failure','cancel','refund'])->nullable(); // status transaksi dari midtrans $table->timestamp('batas_pembayaran')->nullable(); $table->timestamp('batas_konfirmasi_transaksi')->nullable(); - $table->timestamp('batas_pengiriman_barang_awal'); $table->timestamp('batas_pengiriman_barang_akhir'); $table->timestamp('tanggal_transaksi')->nullable(); $table->string('nama_bank_penjual'); diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index be654e3..62f7879 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -50,6 +50,7 @@ class DatabaseSeeder extends Seeder 'persentase_kemiripan' => 100, 'gender' => $faker->randomElement(['Laki-laki', 'Perempuan']), 'kode_kelurahan' => '1101012002', + 'foto_profile' => 'face1.jpg' ]); $user1 = User::factory()->create([ @@ -71,7 +72,8 @@ class DatabaseSeeder extends Seeder 'kode_kelurahan' => '1101012002', 'nama_bank' => 'mandiri', 'no_rek' => '019809210873', - 'keterangan' => $faker->sentence() + 'keterangan' => $faker->sentence(), + 'foto_profile' => 'face2.jpg' ]); $user2 = User::factory()->create([ @@ -93,7 +95,8 @@ class DatabaseSeeder extends Seeder 'kode_kelurahan' => '1101012002', 'nama_bank' => 'bca', 'no_rek' => '01980921', - 'keterangan' => $faker->sentence() + 'keterangan' => $faker->sentence(), + 'foto_profile' => 'face3.jpg' ]); User::factory(100)->create(); @@ -125,7 +128,6 @@ class DatabaseSeeder extends Seeder 'token' => 'asda', 'status_transaksi' => 'created', 'batas_pembayaran' => now(), - 'batas_pengiriman_barang_awal' => now(), 'batas_pengiriman_barang_akhir' => now(), 'nama_bank_penjual' => $user2->nama_bank, 'no_rek_penjual' => $user2->no_rek, @@ -140,6 +142,36 @@ class DatabaseSeeder extends Seeder 'deskripsi' => $user1->nama_depan . ' telah membuat transaksi baru dengan ' . $user2->nama_depan, ]); + $transaction = Transaction::create([ + 'id' => Str::uuid(), + 'pembeli' => $user2->email, + 'penjual' => $user1->email, + 'nama_barang' => 'hah', + 'deskripsi_transaksi' => null, + 'satuan_barang' => 'barang', + 'harga_barang' => 2000, + 'jumlah_barang' => 2, + 'persentase_keuntungan' => 2, + 'total_keuntungan' => 2, + 'total_harga' => 2, + 'total_bayar' => 2, + 'token' => 'asda', + 'status_transaksi' => 'created', + 'batas_pembayaran' => now(), + 'batas_pengiriman_barang_akhir' => now(), + 'nama_bank_penjual' => $user1->nama_bank, + 'no_rek_penjual' => $user1->no_rek, + ]); + + TransactionDescription::create([ + 'transaction_id' => $transaction->id, + 'status' => 'pending', + 'user' => $user2->email, + 'judul' => 'fa fa-plus', + 'background' => 'bg-buyer', + 'deskripsi' => $user2->nama_depan . ' telah membuat transaksi baru dengan ' . $user1->nama_depan, + ]); + $transactionRefund = Transaction::create([ 'id' => Str::uuid(), 'pembeli' => $user1->email, @@ -157,7 +189,6 @@ class DatabaseSeeder extends Seeder 'status_transaksi' => 'success', 'status_pembayaran' => 'refund', 'batas_pembayaran' => now(), - 'batas_pengiriman_barang_awal' => now(), 'batas_pengiriman_barang_akhir' => now(), 'nama_bank_penjual' => $user2->nama_bank, 'no_rek_penjual' => $user2->no_rek, diff --git a/public/assets/css/style.css b/public/assets/css/style.css index daad49a..37ab2c8 100644 --- a/public/assets/css/style.css +++ b/public/assets/css/style.css @@ -1271,9 +1271,9 @@ select.form-control:not([size]):not([multiple]) { margin-bottom: -15px; } -.card.card-statistic-2 .card-chart canvas { +/* .card.card-statistic-2 .card-chart canvas { height: 90px !important; -} +} */ .card .card-stats { width: 100%; diff --git a/resources/views/Admin/index.blade.php b/resources/views/Admin/index.blade.php index a33e1b2..4ae5cdd 100644 --- a/resources/views/Admin/index.blade.php +++ b/resources/views/Admin/index.blade.php @@ -4,109 +4,123 @@
    -
    +
    -
    List Transaction - - -
    -
    -

    Total Transaction

    +

    Total Transaksi

    -
    - {{ $totalTransaction }} +
    + +
    +
    + {{ $totalTransaction }} Transaksi
    -

    - - 1.08% - Since last week +

    + + {{ abs($rateTransaction) }}% + Dibandingkan sebelumnya

    -
    +
    -
    - -
    -
    - +
    +
    +

    Refund

    +
    +
    +
    +
    {{ $countPending }}
    +
    Menunggu
    +
    +
    +
    {{ $countApprove }}
    +
    Disetujui
    +
    +
    +
    {{ $countDeny }}
    +
    Ditolak
    +
    +

    Total Refund

    -
    - {{ $totalRefund }} +
    + +
    +
    + {{ $totalRefund }} Pengajuan
    -

    - - 5.27% - Since last month +

    + + {{ abs($rateRefund) }}% + Dibandingkan sebelumnya

    -
    +
    -
    - +
    +
    +

    Pengguna

    +
    -
    - +
    +
    -

    Total user

    +

    Total Pengguna

    +
    +
    + +
    +
    + {{ $totalUser }} Pengguna
    -
    - {{ $totalUser }}
    -

    - - 1.08% - Since previous week +

    + + {{ abs($rateUser) }}% + Dibandingkan sebelumnya

    @@ -115,18 +129,17 @@
    -
    @include('admin.transaction.modal-tracking') +@endsection +@section('tambahan-js') + @endsection diff --git a/resources/views/Admin/notification/create.blade.php b/resources/views/Admin/notification/create.blade.php index aae1c32..7286fb8 100644 --- a/resources/views/Admin/notification/create.blade.php +++ b/resources/views/Admin/notification/create.blade.php @@ -1,5 +1,5 @@ @extends('layouts.main') -@section('content') +@section('tambahan-js') +@endsection +@section('content')
    diff --git a/resources/views/Admin/notification/edit.blade.php b/resources/views/Admin/notification/edit.blade.php index 4332cc5..1999faa 100644 --- a/resources/views/Admin/notification/edit.blade.php +++ b/resources/views/Admin/notification/edit.blade.php @@ -1,5 +1,5 @@ @extends('layouts.main') -@section('content') +@section('tambahan-js') +@endsection +@section('content')
    diff --git a/resources/views/Admin/notification/index.blade.php b/resources/views/Admin/notification/index.blade.php index bc6d090..f9e114c 100644 --- a/resources/views/Admin/notification/index.blade.php +++ b/resources/views/Admin/notification/index.blade.php @@ -1,5 +1,5 @@ @extends('layouts.main') -@section('content') +@section('tambahan-js') +@endsection +@section('content')
    diff --git a/resources/views/Admin/notification/show.blade.php b/resources/views/Admin/notification/show.blade.php index 49b264e..4137738 100644 --- a/resources/views/Admin/notification/show.blade.php +++ b/resources/views/Admin/notification/show.blade.php @@ -1,5 +1,5 @@ @extends('layouts.main') -@section('content') +@section('tambahan-js') +@endsection +@section('content')
    @@ -83,7 +85,7 @@
    - {{ $notification->content }} + {!! $notification->content !!}
    diff --git a/resources/views/Admin/refund/detail-refund.blade.php b/resources/views/Admin/refund/detail-refund.blade.php index 2cc5813..39aa432 100644 --- a/resources/views/Admin/refund/detail-refund.blade.php +++ b/resources/views/Admin/refund/detail-refund.blade.php @@ -99,6 +99,8 @@
    +@endsection +@section('tambahan-js') - @extends('admin.transaction.modal-keterangan-status') @endsection diff --git a/resources/views/Admin/transaction/detail-transaction.blade.php b/resources/views/Admin/transaction/detail-transaction.blade.php index 3341e79..0848923 100644 --- a/resources/views/Admin/transaction/detail-transaction.blade.php +++ b/resources/views/Admin/transaction/detail-transaction.blade.php @@ -97,6 +97,14 @@
    +
    +
    +
    + Deskripsi:
    + {!! $transaction->deskripsi_transaksi !!}
    +
    +
    +
    {{-- batas pembayaran dan pengiriman --}}
    @@ -107,20 +115,8 @@
    - Estimasi Pengiriman:
    - {{ date('Y', strtotime($transaction->batas_pengiriman_barang_awal)) == - date('Y', strtotime($transaction->batas_pengiriman_barang_akhir)) - ? (date('F', strtotime($transaction->batas_pengiriman_barang_awal)) == - date('F', strtotime($transaction->batas_pengiriman_barang_akhir)) - ? date('d', strtotime($transaction->batas_pengiriman_barang_awal)) . - '-' . - date('d F Y', strtotime($transaction->batas_pengiriman_barang_akhir)) - : date('F', strtotime($transaction->batas_pengiriman_barang_awal)) . - '-' . - date('d F Y', strtotime($transaction->batas_pengiriman_barang_akhir))) - : date('d F', strtotime($transaction->batas_pengiriman_barang_awal)) . - '-' . - date('d F Y', strtotime($transaction->batas_pengiriman_barang_akhir)) }}
    + Batas Pengiriman:
    + {{ date('d F Y', strtotime($transaction->batas_pengiriman_barang_akhir)) }}
    @@ -139,13 +135,12 @@
    - {{-- Keterangan --}}
    Status Indikasi Penipuan:
    - {{ $transaction->fraud_status == null ? 'Tidak ada' : 'Ada' }} + {{ $transaction->fraud_status == null ? 'Tidak ada' : ucwords($transaction->fraud_status) }}
    @@ -245,6 +240,8 @@
    +@endsection +@section('tambahan-js') @endsection diff --git a/resources/views/User/contact/index.blade.php b/resources/views/User/contact/index.blade.php index 7f930de..8232a39 100644 --- a/resources/views/User/contact/index.blade.php +++ b/resources/views/User/contact/index.blade.php @@ -44,6 +44,8 @@ @include('user.contact.modal-detail-contact') @include('user.contact.modal-add-contact') +@endsection +@section('tambahan-js') + @endsection diff --git a/resources/views/User/notification/detail-notification.blade.php b/resources/views/User/notification/detail-notification.blade.php index 3425642..cc08592 100644 --- a/resources/views/User/notification/detail-notification.blade.php +++ b/resources/views/User/notification/detail-notification.blade.php @@ -18,7 +18,7 @@
    - {{ $notification->content }} + {!! $notification->content !!}
    diff --git a/resources/views/User/notification/index.blade.php b/resources/views/User/notification/index.blade.php index b80f5ed..4dbe768 100644 --- a/resources/views/User/notification/index.blade.php +++ b/resources/views/User/notification/index.blade.php @@ -1,12 +1,5 @@ @extends('layouts.main') -@section('content') - +@section('tambahan-js') +@endsection +@section('content') +
    diff --git a/resources/views/User/refund/index.blade.php b/resources/views/User/refund/index.blade.php index f632039..a62b9eb 100644 --- a/resources/views/User/refund/index.blade.php +++ b/resources/views/User/refund/index.blade.php @@ -42,6 +42,8 @@
    @include('user.refund.modal-keterangan-status') +@endsection +@section('tambahan-js') + @if (Session::has('message')) + +@endsection diff --git a/resources/views/layouts/main.blade.php b/resources/views/layouts/main.blade.php index 8477d7f..b62dec6 100644 --- a/resources/views/layouts/main.blade.php +++ b/resources/views/layouts/main.blade.php @@ -9,6 +9,8 @@ @include('layouts.css') + @yield('css-tambahan') + @include('layouts.js') @@ -29,8 +31,16 @@ @include('layouts.footer') + @yield('js-khusus') + @include('layouts.js-bawah') + @yield('js-header') + + @yield('js-sidebar') + + @yield('tambahan-js') + diff --git a/resources/views/layouts/sidebar.blade.php b/resources/views/layouts/sidebar.blade.php index 448aed9..389b0ee 100644 --- a/resources/views/layouts/sidebar.blade.php +++ b/resources/views/layouts/sidebar.blade.php @@ -17,14 +17,14 @@ @if (Auth::user()->role == 'Admin')
  • - User
  • + href="{{ route('admin-user.index') }}" id="clickUser"> + User
  • Transaction
  • + href="{{ route('admin-transaction.index') }}" id="clickTransaction">Transaction
  • - Refund + href="{{ route('admin-refund.index') }}" id="clickRefund"> + Refund
  • @@ -73,4 +73,52 @@ - +@section('js-khusus') + +@endsection +@section('js-sidebar') + +@endsection diff --git a/resources/views/profile/index.blade.php b/resources/views/profile/index.blade.php index 9c8e1b1..9f8a7fd 100644 --- a/resources/views/profile/index.blade.php +++ b/resources/views/profile/index.blade.php @@ -351,8 +351,8 @@ - - {{-- profile --}} +@endsection +@section('tambahan-js') - {{-- profile --}} @endsection diff --git a/routes/api.php b/routes/api.php index abdd2bf..aa04370 100644 --- a/routes/api.php +++ b/routes/api.php @@ -9,6 +9,7 @@ use App\Http\Controllers\API\Penjual\PenjualApiController; use App\Http\Controllers\API\Profile\ProfileApiController; use App\Http\Controllers\API\Transaction\TransactionApiController; use App\Http\Controllers\API\Invoice\InvoiceApiController; +use App\Http\Controllers\API\Notification\NotificationApiController; use Illuminate\Support\Facades\Auth; /* @@ -103,6 +104,12 @@ Route::middleware(['auth:api'])->group(function () { Route::get('get-invoice', 'getInvoice')->name('invoice.get-invoice'); // Bisa Route::get('export-invoice', 'exportInvoice')->name('invoice.export-invoice'); // Bisa }); // sudah + + Route::controller(NotificationApiController::class)->group(function(){ + Route::get('list-notification','listNotification')->name('notification.list-notification'); + Route::get('get-detail-notification','getDetailNotification')->name('notification.get-detail-notification'); + Route::get('mark-all-as-read','markAllAsRead')->name('notification.mark-all-as-read'); + }); }); }); }); diff --git a/routes/web.php b/routes/web.php index 27b034d..cc36c37 100644 --- a/routes/web.php +++ b/routes/web.php @@ -89,6 +89,7 @@ Route::middleware(['auth'])->group(function(){ // Tampilan dashboard admin beserta perhitungan Route::controller(AdminDashboardController::class)->group(function(){ Route::get('/','index')->name('admin.index'); + Route::get('admin-dashboard/get-data-dashboard','getDataBySearch')->name('admin.get-data-dashboard'); }); // Tampilan, aprove atau deny dan hapus user @@ -96,7 +97,7 @@ Route::middleware(['auth'])->group(function(){ Route::get('admin-user','index')->name('admin-user.index'); Route::get('admin-user/list-user','listUser')->name('admin-user.list-user'); Route::get('admin-user/{id}','show')->name('admin-user.show'); - Route::delete('admin-user/hapus-user','delete')->name('admin-user.destroy'); + Route::delete('admin-user/hapus-user','destroy')->name('admin-user.destroy'); Route::put('admin-user/approve-user', 'approveUser')->name('admin-user.approve'); Route::put('admin-user/deny-user', 'denyUser')->name('admin-user.deny'); }); @@ -137,7 +138,7 @@ Route::middleware(['auth'])->group(function(){ Route::get('admin-notification/list-user-for-create-edit','listUserForCreateEdit')->name('admin-notification.list-user-for-create-edit'); Route::get('admin-notification/select-all-user','selectAllUser')->name('admin-notification.select-all-user'); Route::get('admin-notification/edit','edit')->name('admin-notification.edit'); - Route::post('admin-notification/update-new-notification','updateNewNotification')->name('admin-notification.update-new-notification'); + Route::get('admin-notification/update-new-notification','updateNewNotification')->name('admin-notification.update-new-notification'); Route::post('admin-notification/store','store')->name('admin-notification.store'); Route::post('admin-notification/update','update')->name('admin-notification.update'); Route::delete('admin-notification/delete','delete')->name('admin-notification.delete'); @@ -152,6 +153,7 @@ Route::middleware(['auth'])->group(function(){ // Tampilan dashboard user beserta perhitungan Route::controller(UserDashboardController::class)->group(function(){ Route::get('/','index')->name('user.index'); + Route::get('user-dashboard/get-data-dashboard','getDataBySearch')->name('user.get-data-dashboard'); }); // Tampilan, tambah dan hapus kontak @@ -201,7 +203,7 @@ Route::middleware(['auth'])->group(function(){ Route::controller(UserRefundController::class)->group(function(){ Route::get('user-refund','index')->name('user-refund.index'); Route::get('user-refund/list-refund','listRefund')->name('user-refund.list-refund'); - Route::get('user-refund/ajukan-komplain','create')->name('user-refund.create'); + Route::get('user-refund/ajukan-komplain/{id}','create')->name('user-refund.create'); Route::get('user-refund/detail-refund/{id}','show')->name('user-refund.show'); Route::post('user-refund','store')->name('user-refund.store'); }); @@ -212,6 +214,8 @@ Route::middleware(['auth'])->group(function(){ Route::get('user-notification/detail-notification/{id}','show')->name('user-notifiaction.detail-notification'); Route::get('user-notification/latest-notification','latestNotification')->name('user-notification.latest-notification'); Route::get('user-notification/mark-all-as-read','markAllAsRead')->name('user.notification.mark-all-as-read'); + Route::get('user-notification/update-new-notification','updateNewNotification')->name('user-notification.update-new-notification'); + Route::get('user-notification/update-notification-to-admin','updateNotificationToAdmin')->name('user-notification.update-notification-to-admin'); }); }); });