From 8f71500bf1aa2b781fb0e1472e6b6e99c5a9e424 Mon Sep 17 00:00:00 2001 From: Raihan Surya Date: Wed, 1 Nov 2023 10:36:14 +0700 Subject: [PATCH] First Commit --- .../Controllers/User/UserRefundController.php | 89 ++++ .../User/UserTransactionController.php | 499 ++++++++++++++++++ app/Models/transaction.php | 26 + public/assets/js/page/modules-datatables.js | 35 ++ resources/views/Admin/refund/index.blade.php | 73 +++ resources/views/User/contact/index.blade.php | 260 +++++++++ resources/views/User/refund/index.blade.php | 68 +++ .../User/transaction/Pembeli/index.blade.php | 396 ++++++++++++++ .../User/transaction/penjual/index.blade.php | 168 ++++++ 9 files changed, 1614 insertions(+) create mode 100644 app/Http/Controllers/User/UserRefundController.php create mode 100644 app/Http/Controllers/User/UserTransactionController.php create mode 100644 resources/views/Admin/refund/index.blade.php create mode 100644 resources/views/User/contact/index.blade.php create mode 100644 resources/views/User/refund/index.blade.php create mode 100644 resources/views/User/transaction/Pembeli/index.blade.php create mode 100644 resources/views/User/transaction/penjual/index.blade.php diff --git a/app/Http/Controllers/User/UserRefundController.php b/app/Http/Controllers/User/UserRefundController.php new file mode 100644 index 0000000..dc7b920 --- /dev/null +++ b/app/Http/Controllers/User/UserRefundController.php @@ -0,0 +1,89 @@ + Refund::join('transactions', 'refunds.transaction_id', '=', 'transactions.id') + ->where('transactions.pembeli', auth()->user()->email) + ->select() + ]); + } + + public function create($id) + { + return view('user.refund.new-refund',['id' => $id]); + } + + public function store(Request $request, $id){ + try{ + DB::beginTransaction(); + + $transaction = Transaction::where('id',$id)->first(); + + $refund = Refund::create([ + 'transaction_id' => $id, + 'total' => $transaction->harga, + 'due_date' => $transaction, + 'complain' => $request->complain + ]); + + if ($request->hasFile('files')) { + $files = $request->file('files'); + foreach ($files as $file) { + $filename = $file->getClientOriginalName(); + $mime = $file->getClientMimeType(); + if (strpos($mime, 'image') !== false) { + $type = 'image'; + $file->storeAs('public/refund-image/', $filename); + } elseif (strpos($mime, 'video') !== false) { + $type = 'video'; + $file->storeAs('public/refund-video/', $filename); + } else { + $type = 'Other'; + } + + RefundDescription::create([ + 'refund_id' => $refund->id, + 'filename' => $filename, + 'type' => $type + ]); + } + } + + DB::commit(); + }catch(Throwable $e){ + DB::rollback(); + + Log::error($e->getMessage()); + + return response()->json(['success' => false, 'message' => 'Terjadi Kesalahan pada sisi server']); + } + } + + public function show($id){ + $refund = Refund::find($id); + $refundDescription = RefundDescription::where($id)->get(); + return view('admin.refund.detail-refund',[ + "refund"=> $refund, + 'descriptions' => $refundDescription + ]); + return view('user.refund.history-refund',[ + 'refund' => $refund, + 'descriptions' => $refundDescription + ]); + } +} diff --git a/app/Http/Controllers/User/UserTransactionController.php b/app/Http/Controllers/User/UserTransactionController.php new file mode 100644 index 0000000..3103e8a --- /dev/null +++ b/app/Http/Controllers/User/UserTransactionController.php @@ -0,0 +1,499 @@ + Transaction::where('pembeli', Auth::user()->email) + ->latest() + ->get(), + ]); + } + + /** + * Display a listing of the resource. + */ + public function indexPenjual() + { + return view('user.transaction.penjual.index', [ + 'transactions' => Transaction::where('penjual', Auth::user()->email) + ->latest() + ->get(), + ]); + } + + public function show($id) + { + return view('user.transaction.pembeli.detail-transaction', [ + 'transaction' => Transaction::findOrFail($id), + 'trackings' => TransactionDescription::where('transaction_id', $id) + ->latest() + ->get(), + ]); + } + + /** + * Show the form for creating a new resource. + */ + public function create() + { + $now = Carbon::now(); + $bulan = $now->format('F'); + $tahun = $now->year; + $persentase_keuntungan = Setting::where('status', 'Active') + ->where('bulan', '=', $bulan) + ->where('tahun', '=', $tahun) + ->value('persentase'); + if (is_null($persentase_keuntungan)) { + $persentase_keuntungan = Setting::where('status', 'Active') + ->latest() + ->value('persentase'); + } + return view('user.transaction.pembeli.new-transaction', [ + 'persentase_keuntungan' => $persentase_keuntungan, + ]); + } + + /** + * Store a newly created resource in storage. + */ + public function invoiceTransaction($id) + { + return view('user.transaction.pembeli.invoice-transaction', [ + 'TransactionUser' => TransactionUser::HistoryTransaction(), + ]); + } + + public function store(Request $request) + { + $pembeli = Auth::user()->email; + $penjual = $request->get('email_penjual'); + $nama_barang = $request->get('nama_barang'); + $satuan_barang = $request->get('satuan_barang'); + $deskripsi_transaksi = $request->get('deskripsi'); + $harga_barang = $request->get('harga_barang'); + $jumlah_barang = $request->get('jumlah_barang'); + + $nama_depan_pembeli = Auth::user()->nama_depan; + $nama_belakang_pembeli = Auth::user()->nama_belakang; + $nohp_pembeli = Auth::user()->nohp; + $nama_penjual = User::where('email', $penjual)->value('nama_depan'); + $alamat = ucwords(strtolower(Auth::user()->alamat)); + $id = Uuid::uuid4(); + + $now = Carbon::now(); + + $persentase_keuntungan = $request->get('persentase_keuntungan'); + + $total_harga = $request->get('total_harga'); + $total_keuntungan = $request->get('total_keuntungan'); + $total_bayar = $request->get('total_bayar'); + + $batas_pembayaran = $now->addDays(1)->toDateTimeString(); + $batas_pengiriman_barang_awal = $now->addDays(2)->toDateTimeString(); + $batas_pengiriman_barang_akhir = $now->addDays(4)->toDateTimeString(); + + $params = [ + 'transaction_details' => [ + 'order_id' => $id, + 'gross_amount' => $total_bayar, + ], + 'item_details' => [ + [ + 'id' => $nama_barang . time(), + 'price' => $harga_barang, + 'quantity' => $jumlah_barang, + 'name' => $nama_barang, + ], + [ + 'id' => 'BA01', + 'price' => $total_keuntungan, + 'quantity' => 1, + 'name' => 'Biaya Admin', + ], + ], + 'customer_details' => [ + 'firts_name' => $nama_depan_pembeli, + 'last_name' => $nama_belakang_pembeli, + 'email' => $pembeli, + 'phone' => $nohp_pembeli, + 'billing' => [ + 'first_name' => $nama_depan_pembeli, + 'last_name' => $nama_belakang_pembeli, + 'email' => $pembeli, + 'phone' => $nohp_pembeli, + 'address' => $alamat, + 'city' => Auth::user()->village->district->city->name, + 'country_code' => 'IDN', + ], + ], + 'callbacks' => [ + 'finish' => route('user-transaction.index.pembeli'), + ], + 'enabled_payments' => [ + 'credit_card', 'gopay', 'shopeepay' + ], + 'expiry' => [ + 'start_time' => $now->format('Y-m-d H:i:s P'), + 'unit' => 'days', + 'duration' => 1, + ], + ]; + + $snap_token = Snap::getSnapToken($params); + $token = $snap_token; + $status = 'created'; + + try{ + DB::beginTransaction(); + + $query = Transaction::create([ + 'pembeli' => $pembeli, + 'penjual' => $penjual, + 'nama_barang' => $nama_barang, + 'deskripsi_transaksi' => $deskripsi_transaksi, + 'satuan_barang' => $satuan_barang, + 'harga_barang' => $harga_barang, + 'jumlah_barang' => $jumlah_barang, + 'persentase_keuntungan' => $persentase_keuntungan, + 'total_keuntungan' => $total_keuntungan, + 'total_harga' => $total_harga, + 'total_bayar' => $total_bayar, + 'token' => $token, + 'status' => $status, + 'batas_pembayaran' => $batas_pembayaran, + 'batas_pengiriman_barang_awal' => $batas_pengiriman_barang_awal, + 'batas_pengiriman_barang_akhir' => $batas_pengiriman_barang_akhir, + ]); + + $contact = Contact::where('pemilik_kontak', $pembeli) + ->where('relasi_kontak', $penjual) + ->count(); + + if ($contact == 0) { + Contact::create([ + 'pemilik_kontak' => $pembeli, + 'relasi_kontak' => $penjual, + ]); + } + + TransactionDescription::create([ + 'transaction_id' => $query->id, + 'status' => $status, + 'user' => $pembeli, + 'judul' => 'fa fa-plus', + 'background' => 'bg-buyer', + 'deskripsi' => $nama_depan_pembeli . ' telah membuat transaksi baru dengan ' . $nama_penjual, + ]); + + DB::commit(); + + return response()->json([ + 'status' => true, + 'message' => 'Berhasil menambahkan transaksi. Silahkan lakukan pembayaran.', + ]); + }catch(Throwable $e){ + DB::rollBack(); + + Log::error($e->getMessage()); + + return response()->json([ + 'status' => false, + 'message' => 'Gagal menambahkan transaksi.', + ]); + } + } + + public function acceptTransaction($id) + { + $query = Transaction::where('id', $id)->update([ + 'status' => 'process', + ]); + if ($query) { + TransactionDescription::create([ + 'transaction_id' => $id, + 'status' => 'process', + 'background' => 'bg-seller', + 'user' => Auth::user()->email, + 'judul' => 'fas fa-handshake', + 'deskripsi' => 'Transaksi telah diterima oleh ' . Auth::user()->nama_depan, + ]); + + return response()->json([ + 'status' => true, + 'message' => 'Transaksi telah diterima. Siapkan pesanan untuk dikirim ke penjual.', + ]); + } else { + return response()->json([ + 'status' => false, + 'message' => 'Gagal update status karena kesalahan server.', + ]); + } + } + + public function sendingOrder($id) + { + $query = Transaction::where('id', $id)->update([ + 'status' => 'sending', + ]); + if ($query) { + TransactionDescription::create([ + 'transaction_id' => $id, + 'status' => 'sending', + 'background' => 'bg-seller', + 'user' => Auth::user()->email, + 'judul' => 'fas fa-truck-moving', + 'deskripsi' => 'Pesanan telah dikirim oleh ' . Auth::user()->nama_depan . ' dan sedang dalam perjalanan menuju pembeli.', + ]); + + return response()->json([ + 'status' => true, + 'message' => 'Pesanan sedang dikirim dan menuju pembeli.', + ]); + } else { + return response()->json([ + 'status' => false, + 'message' => 'Gagal update status karena kesalahan server.', + ]); + } + } + + public function sentOrder($id) + { + $query = Transaction::where('id', $id)->update([ + 'status' => 'sended', + ]); + if ($query) { + TransactionDescription::create([ + 'transaction_id' => $id, + 'status' => 'sended', + 'background' => 'bg-seller', + 'user' => Auth::user()->email, + 'judul' => 'fas fa-check', + 'deskripsi' => 'Pesanan telah sampai di tempat pembeli.', + ]); + + return response()->json([ + 'status' => true, + 'message' => 'Pesanan telah sampai di tempat pembeli.', + ]); + } else { + return response()->json([ + 'status' => false, + 'message' => 'Gagal update status karena kesalahan server.', + ]); + } + } + + public function finishTransaction($id) + { + $query = Transaction::where('id', $id)->update([ + 'status' => 'finished', + ]); + if ($query) { + TransactionDescription::create([ + 'transaction_id' => $id, + 'status' => 'sended', + 'background' => 'bg-buyer', + 'user' => Auth::user()->email, + 'judul' => 'fas fa-check', + 'deskripsi' => 'Pesanan telah sampai di tempat pembeli.', + ]); + + return response()->json([ + 'status' => true, + 'message' => 'Pesanan telah sampai di tempat pembeli.', + ]); + } else { + return response()->json([ + 'status' => false, + 'message' => 'Gagal update status karena kesalahan server.', + ]); + } + } + + public function payTransaction($id) + { + // Membuat objek Google Translate + $translator = new GoogleTranslate(); + + // Mengatur bahasa sumber (Inggris) dan bahasa target (Indonesia) + $translator->setSource('en'); + $translator->setTarget('id'); + + $payment = Trans::status($id); + $result = json_decode(json_encode($payment), true); + if (in_array($result['status_code'], ['200', '201', '202'])) { + $query = Transaction::where('id', $id)->update([ + 'currency' => $result['currency'], + 'merchant_id' => $result['merchant_id'], + 'metode_pembayaran' => $result['payment_type'], + 'tanggal_transaksi' => $result['transaction_time'], + 'signature_key' => $result['signature_key'], + 'status' => $result['transaction_status'], + 'fraud_status' => $result['fraud_status'], + ]); + if ($query) { + if ($result['transaction_status'] == 'pending') { + TransactionDescription::create([ + 'transaction_id' => $id, + 'status' => $result['transaction_status'], + 'user' => Auth::user()->email, + 'judul' => 'fas fa-clock', + 'status_code' => $result['status_code'], + 'background' => 'bg-buyer', + 'deskripsi' => 'Pembayaran ditunda.', + ]); + return response()->json([ + 'status' => true, + 'message' => 'Transaksi ditunda. Silahkan bayar nanti selama dalam waktu batas pembayaran.', + ]); + } else { + TransactionDescription::create([ + 'transaction_id' => $id, + 'status' => $result['transaction_status'], + 'user' => Auth::user()->email, + 'judul' => 'fas fa-plus', + 'status_code' => $result['status_code'], + 'background' => 'bg-buyer', + 'deskripsi' => Auth::user()->nama_depan . ' telah sukses melakukan pembayaran. Transaksi diteruskan ke penjual.', + ]); + return response()->json([ + 'status' => true, + 'message' => 'Pembayaran sukses.', + ]); + } + } else { + return response()->json([ + 'status' => false, + 'message' => 'Transaksi pembayaran gagal.', + ]); + } + } elseif (in_array($result['status_code'], ['400', '401', '402', '403', '404', '405', '406', '407', '408', '409', '410', '411', '412', '413'])) { + return response()->json([ + 'status' => false, + 'message' => 'Terjadi kesalahan di server.', + ]); + } else { + return response()->json([ + 'status' => false, + 'message' => 'Transaksi pembayaran gagal', + ]); + } + } + + public function cancelTransaction($id) + { + // Membuat objek Google Translate + $translator = new GoogleTranslate(); + + // Mengatur bahasa sumber (Inggris) dan bahasa target (Indonesia) + $translator->setSource('en'); + $translator->setTarget('id'); + + $transaction = Transaction::where('id', $id)->first(); + + if ($transaction->status == 'created') { + $query = Transaction::where('id', $id)->update([ + 'status' => 'cancel', + ]); + if ($query) { + TransactionDescription::create([ + 'transcation_id' => $id, + 'status' => 'cancel', + 'user' => Auth::user()->email, + 'judul' => 'fas fa-exclamation', + 'background' => 'bg-buyer', + 'deskripsi' => 'Transaksi dibatalkan', + ]); + + return response()->json([ + 'status' => true, + 'message' => 'Transaksi berhasil dibatal', + ]); + } else { + return response()->json([ + 'status' => false, + 'message' => 'Transaksi gagal dibatalkan', + ]); + } + } else { + $cancel = json_decode(json_encode(Trans::cancel($id)), true); + if ($cancel['status_code'] == '200') { + $query = Transaction::where('id', $id)->update([ + 'status' => $cancel['transaction_status'], + ]); + if ($query) { + TransactionDescription::create([ + 'transaction_id' => $id, + 'status' => $cancel['transaction_status'], + 'user' => Auth::user()->email, + 'judul' => 'fas fa-exclamation', + 'status_code' => $cancel['status_code'], + 'background' => 'bg-buyer', + 'deskripsi' => $translator->translate($cancel['status_message']), + ]); + + return response()->json([ + 'status' => true, + 'message' => $translator->translate($cancel['status_message']), + ]); + } else { + return response()->json([ + 'status' => false, + 'message' => $translator->translate($cancel['status_message']), + ]); + } + } elseif ($cancel['status_code'] == '412') { + return response()->json([ + 'status' => false, + 'message' => $translator->translate($cancel['status_message']), + ]); + } + } + } + + public function complainTransaction($id) + { + return view('user.refund.new-refund', compact('id')); + } +} diff --git a/app/Models/transaction.php b/app/Models/transaction.php index b7bb85e..e0dab44 100644 --- a/app/Models/transaction.php +++ b/app/Models/transaction.php @@ -54,7 +54,33 @@ class transaction "status"=>"paid" ] +<<<<<<< Updated upstream ]; +======= + /** + * The attributes that are mass assignable. + * + * @var array + */ + protected $fillable = [ + 'pembeli', + 'penjual', + 'nama_barang', + 'deskripsi_transaksi', + 'satuan_barang', + 'harga_barang', + 'jumlah_barang', + 'persentase_keuntungan', + 'total_keuntungan', + 'total_harga', + 'total_bayar', + 'token', + 'status', + 'batas_pembayaran', + 'batas_pengiriman_barang_awal', + 'batas_pengiriman_barang_akhir', + ]; +>>>>>>> Stashed changes private static $detail_transaction=[ [ diff --git a/public/assets/js/page/modules-datatables.js b/public/assets/js/page/modules-datatables.js index 5f91805..9899d83 100644 --- a/public/assets/js/page/modules-datatables.js +++ b/public/assets/js/page/modules-datatables.js @@ -34,7 +34,42 @@ $("#table-1").dataTable({ ] }); $("#table-2").dataTable({ +<<<<<<< Updated upstream "columnDefs": [ { "sortable": false, "targets": [0,2,3] } ] +======= + ordering: true, + searchable: true, +}); + +// Transaksi pembeli +$("#table-3").dataTable({ + columnDefs: [{ sortable: false, targets: [6] }], + searchable: true, +}); + +// Refund, Transaction Admin +$("#table-4").dataTable({ + columnDefs: [{ sortable: false, targets: [8] }], + searchable: true, +}); + +// Setting Admin +$("#table-5").dataTable({ + columnDefs: [{ sortable: false, targets: [4, 5] }], + searchable: true, +}); + +// Contact User +$("#table-6").dataTable({ + columnDefs: [{ sortable: false, targets: [4] }], + searchable: true, +>>>>>>> Stashed changes +}); + +//Refund User +$("#table-7").dataTable({ + columnDefs: [{ sortable: false, targets: [5] }], + searchable: true, }); diff --git a/resources/views/Admin/refund/index.blade.php b/resources/views/Admin/refund/index.blade.php new file mode 100644 index 0000000..bac1cff --- /dev/null +++ b/resources/views/Admin/refund/index.blade.php @@ -0,0 +1,73 @@ +@extends('layouts.main') +@section('content') +
+
+
+

Refund

+
+ + +
+
+
+
+
+
+ + + + + + + + + + + + + + + + + @foreach ($refunds as $refund) + + + + + + + + + + + + + @endforeach + +
+ # + IDPembeliNama BarangPenjualTotalTanggal PengajuanBatas KonfirmasiStatusAksi
{{ $loop->iteration }}{{ $refund->id }}{{ $refund->transaction->data_pembeli->nama_depan }} + {{ $refund->transaction->nama_barang }} + {{ $refund->transaction->data_penjual->nama_depan }} + {{ $refund->total }}{{ $refund->created_at }}{{ $refund->due_date }}{{ ucwords($refund->status) }} + +
+ + +
+
+
+
+
+
+
+
+ @extends('admin.transaction.modal-keterangan-status') +@endsection diff --git a/resources/views/User/contact/index.blade.php b/resources/views/User/contact/index.blade.php new file mode 100644 index 0000000..784c7cb --- /dev/null +++ b/resources/views/User/contact/index.blade.php @@ -0,0 +1,260 @@ +@extends('layouts.main') +@section('content') +
+
+ +
+

Kontak

+
+ + +
+
+ + {{-- tabel list kontak --}} +
+
+
+
+
+ +
+
+
+
+ + + + + + + + + + + + @foreach ($contacts as $contact) + + + + + + + + @endforeach + +
#EmailNamePhoneAction
{{ $loop->iteration }} + {{ $contact->relasiKontak->nama_depan . ' ' . $contact->relasiKontak->nama_belakang }} + {{ $contact->relasiKontak->email }} + {{ $contact->relasiKontak->nohp }} + + + +
+
+
+
+
+
+ @extends('user.contact.modal-detail-contact') + @extends('user.contact.modal-add-contact') +
+
+ +@endsection diff --git a/resources/views/User/refund/index.blade.php b/resources/views/User/refund/index.blade.php new file mode 100644 index 0000000..4d31aa9 --- /dev/null +++ b/resources/views/User/refund/index.blade.php @@ -0,0 +1,68 @@ +@extends('layouts.main') +@section('content') +
+
+
+

Refund

+
+ + +
+
+ +
+
+
+
+
+ + + + + + + + + + + + + @foreach ($refunds as $refund) + + + + + + + + + @endforeach + +
+ # + Nama BarangPenjualTotalStatusAksi
{{ $loop->iteration }}{{ $refund->transaction->nama_barang }} + {{ $refund->transaction->data_penjual->nama_depan }} + {{ $refund->total }}{{ ucwords($refund->status) }} + +
+ + +
+
+
+
+
+
+
+
+
+@endsection diff --git a/resources/views/User/transaction/Pembeli/index.blade.php b/resources/views/User/transaction/Pembeli/index.blade.php new file mode 100644 index 0000000..c3d5f74 --- /dev/null +++ b/resources/views/User/transaction/Pembeli/index.blade.php @@ -0,0 +1,396 @@ +@extends('layouts.main') +@section('content') +
+
+
+

Halaman Pembeli

+
+ + +
+
+ +
+
+
+
+

Selamat Datang! {{ Auth::user()->nama_depan }}

+

Mau belanja apa hari ini?

+
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + @forelse ($transactions as $transaction) + + + + + + + + + + @empty + @endforelse + +
+ # + PenjualTotalTanggal TransaksiTanggal UpdateStatusAksi
{{ $loop->iteration }}{{ $transaction->data_penjual->nama_depan . ' ' . $transaction->data_penjual->nama_belakang }} + Rp {{ number_format($transaction->total_bayar, 2, ',', '.') }}{{ $transaction->created_at }}{{ $transaction->updated_at }}{{ ucwords($transaction->status) }} + +
+ + + +
+
+
+
+
+
+
+
+
+ + + @extends('user.transaction.pembeli.modal-end-transaction') + @extends('user.transaction.pembeli.modal-tracking') + @extends('user.transaction.pembeli.modal-keterangan-status') + + + + + {{-- Modal --}} + +@endsection diff --git a/resources/views/User/transaction/penjual/index.blade.php b/resources/views/User/transaction/penjual/index.blade.php new file mode 100644 index 0000000..d79aab1 --- /dev/null +++ b/resources/views/User/transaction/penjual/index.blade.php @@ -0,0 +1,168 @@ +@extends('layouts.main') +@section('content') +
+
+
+

Halaman Penjual

+
+ + +
+
+ +
+
+
+
+
+

Hallo!!

+

Selamat Datang {{ Auth::user()->nama_depan }}!

+
+
+
+
+
+
+
+ + + + + + + + + + + + + + + @forelse ($transactions as $transaction) + + + + + + + + + + + @empty + @endforelse + +
+ # + Order IDPembeliTotalTanggal PembuatanTanggal UpdateStatusAksi
{{ $loop->iteration }}{{ $transaction->id }}{{ $transaction->data_pembeli->nama_depan . ' ' . $transaction->data_pembeli->nama_belakang }} + Rp {{ number_format($transaction->total_bayar, 2, ',', '.') }}{{ $transaction->created_at }}{{ $transaction->updated_at }}{{ ucwords($transaction->status) }} + +
+ + +
+
+
+
+
+
+
+
+
+
+ @extends('user.transaction.penjual.modal-tracking') + @extends('user.transaction.penjual.modal-keterangan-status') + +@endsection