Revisi tampilan dashboard admin

This commit is contained in:
Muhammad Raihan Surya 2023-11-01 15:27:42 +07:00
parent 1e13f9d925
commit 0f45ead6bc
7 changed files with 358 additions and 331 deletions

View File

@ -67,7 +67,10 @@ class AdminDashboardController extends Controller
$dataChartRefund[] = intval($refund);
}
return view('admin.index', compact('transactions', 'countSuccess', 'countPending', 'countCancelled', 'countRefund', 'totalRefund', 'totalUser', 'totalTransaction', 'dataChartTransaction', 'dataChartRefund', 'dataChartTotalUser', 'dataChartTotalRefund'));
$transactions = Transaction::latest()
->get();
return view('admin.index', compact('transactions', 'countSuccess', 'countPending', 'countCancelled', 'countRefund', 'totalRefund', 'totalUser', 'totalTransaction', 'dataChartTransaction', 'dataChartRefund', 'dataChartTotalUser', 'dataChartTotalRefund', 'transactions'));
}
public function getChartByMonth()

View File

@ -23,9 +23,9 @@ class UserContactController extends Controller
public function getContact()
{
$data = DB::table('contacts')
->select('contacts.relasi_kontak', 'users.nama_depan', 'users.nama_belakang')
->join('users', 'contacts.relasi_kontak', '=', 'users.email')
->where('contacts.pemilik_kontak','=',Auth::user()->email)
->select('contacts.relasi_kontak', 'users.nama_depan', 'users.nama_belakang')
->where('contacts.pemilik_kontak', '=', Auth::user()->email)
->paginate(10);
return response()->json($data);
}
@ -89,7 +89,9 @@ class UserContactController extends Controller
public function cekEmail($email)
{
$result = User::where('email', $email)->where('role','User')->first();
$result = User::where('email', $email)
->where('role', 'User')
->first();
if ($result) {
if ($result->status == 'Finished') {
return response()->json([

View File

@ -1,287 +0,0 @@
$(document).ready(function () {
let totalHarga = 0;
let biayaAdmin = persentaseKeuntungan;
let totalBiayaAdmin = 0;
let totalBayar = 0;
function tampilTotalHarga(harga) {
let tampilTotalNominal = document.getElementById("totalBiaya");
let tampilTotalBiaya = document.getElementById("totalBayar");
let tampilTotalBiayaAdmin = document.getElementById("totalBiayaAdmin");
totalBiayaAdmin = (harga * biayaAdmin) / 100;
totalBayar = totalBiayaAdmin + harga;
tampilTotalNominal.innerHTML = harga.toLocaleString("id-ID", {
style: "currency",
currency: "IDR",
});
tampilTotalBiaya.innerHTML = totalBayar.toLocaleString("id-ID", {
style: "currency",
currency: "IDR",
});
tampilTotalBiayaAdmin.innerHTML = totalBiayaAdmin.toLocaleString(
"id-ID",
{
style: "currency",
currency: "IDR",
}
);
}
$("#selectContact").select2({
placeholder: "Pilih Kontak",
ajax: {
url: "{{ route('user-contact.get') }}",
processResults: function ({ data }) {
return {
results: $.map(data, function (item) {
return {
id: item.relasi_kontak,
text: item.nama_depan + " " + item.nama_belakang,
};
}),
};
},
},
});
$("#hargaBarang").change(function () {
let harga = $(this).val();
let jumlah = $("#jumlahBarang").val();
let biaya = document.getElementById("totalBiaya");
if (harga.trim() != "") {
if (jumlah.trim() != "") {
totalHarga = harga * jumlah;
} else {
totalHarga = harga * 0;
}
tampilTotalHarga(totalHarga);
}
});
$("#jumlahBarang").change(function () {
let jumlah = $(this).val();
let harga = $("#hargaBarang").val();
let nominal = document.getElementById("jumlah");
if (jumlah.trim() != "") {
if (jumlah == 0) {
nominal.innerHTML = "Nominal";
} else {
nominal.innerHTML = "Nominal (x" + jumlah + ")";
}
if (harga.trim() != "") {
totalHarga = harga * jumlah;
} else {
totalHarga = 0 * jumlah;
}
tampilTotalHarga(totalHarga);
}
});
$("#selectContact").change(function () {
let email = $("#selectContact").val();
if (email === null) {
$("#inputPenjual").prop("disabled", false);
$("#checkButton").prop("disabled", false);
$("#deleteOption").prop("disabled", false);
} else {
$("#inputPenjual").prop("disabled", true);
$("#deleteOption").prop("disabled", false);
$("#checkButton").prop("disabled", true);
}
});
$("#deleteOption").click(function () {
$("#selectContact").val(null).trigger("change");
});
$("#inputPenjual").on("input", function () {
let emailInput = $("#inputPenjual").val();
if (emailInput.trim() == "") {
$("#selectContact").prop("disabled", false);
$("#deleteOption").prop("disabled", false);
} else {
$("#selectContact").prop("disabled", true);
$("#deleteOption").prop("disabled", true);
}
});
$("#checkButton").click(function () {
let email = document.querySelector('[name="input_penjual"]').value;
const csrfToken = $('meta[name="csrf-token"]').attr("content");
if (email.trim() == "") {
Swal.fire({
title: "Gagal",
text: "Email tidak boleh kosong",
icon: "error",
});
} else {
if (email != "{{ Auth::user()->email }}") {
$.ajaxSetup({
headers: {
"X-CSRF-TOKEN": csrfToken,
},
});
$.ajax({
url: "{{ route('user-contact.email', ':email') }}".replace(
":email",
email
),
type: "GET",
success: function (response) {
if (
response.status &&
(response.message.nama_bank == null ||
response.message.nama_bank == "") &&
(response.message.no_rek == null ||
response.message.no_rek == "")
) {
Swal.fire({
title: "Berhasil",
text: "Akun tersedia",
icon: "success",
});
} else {
Swal.fire({
title: "Gagal",
text: response.message,
icon: "error",
});
}
},
error: function (error) {
Swal.fire({
title: "Gagal",
text: "Terjadi error karena, " + error,
icon: "error",
});
},
});
} else {
Swal.fire({
title: "Gagal",
text: "Email penjual tidak boleh sama denggan email pembeli",
icon: "error",
});
}
}
});
$("#save").on("click", function () {
let opsiKontak = document.querySelector(
'[name="select_penjual"]'
).value;
let inputKontak = document.querySelector(
'[name="input_penjual"]'
).value;
let namaBarang = document.querySelector('[name="nama_barang"]').value;
let hargaBarang = document.querySelector('[name="harga_barang"]').value;
let satuanBarang = document.querySelector(
'[name="satuan_barang"]'
).value;
let jumlahBarang = document.querySelector(
'[name="jumlah_barang"]'
).value;
let deskripsi = document.querySelector(
'textarea[name="deskripsi"]'
).value;
let emptyInput = [];
let penjual = "";
if (opsiKontak != "" && inputKontak != "") {
penjual = opsiKontak;
} else if (opsiKontak == "" && inputKontak != "") {
penjual = inputKontak;
} else if (inputKontak == "" && opsiKontak != "") {
penjual = opsiKontak;
} else {
emptyInput.push("Kolom penjual tidak boleh kosong");
}
if (penjual == "{{ Auth::user()->email }}") {
emptyInput.push(
"Email penjual tidak boleh sama dengan email pembeli"
);
}
if (namaBarang == "") {
emptyInput.push("Nama barang tidak boleh kosong");
}
if (hargaBarang == "") {
emptyInput.push("Harga barang tidak boleh kosong");
}
if (satuanBarang == "") {
emptyInput.push("Satuan barang tidak boleh kosong");
}
if (jumlahBarang == "") {
emptyInput.push("Jumlah barang tidak boleh kosong");
}
if (emptyInput.length > 0) {
const emptyInputError = emptyInput.join(", ");
Swal.fire({
title: "Gagal",
text: emptyInputError,
icon: "error",
confirmButtonText: "OK",
});
} else {
const csrfToken = $('meta[name="csrf-token"]').attr("content");
const formData = new FormData();
formData.append("email_penjual", penjual);
formData.append("nama_barang", namaBarang);
formData.append("satuan_barang", satuanBarang);
formData.append("harga_barang", hargaBarang);
formData.append("jumlah_barang", jumlahBarang);
// formData.append('batas_pengiriman', batasPengiriman);
formData.append("deskripsi", deskripsi);
formData.append("persentase_keuntungan", biayaAdmin);
formData.append("total_keuntungan", totalBiayaAdmin);
formData.append("total_harga", totalHarga);
formData.append("total_bayar", totalBayar);
$(modal).modal("show");
$.ajaxSetup({
headers: {
"X-CSRF-TOKEN": csrfToken,
},
});
$.ajax({
url: "{{ route('store-transaction.pembeli') }}",
type: "POST",
data: formData,
processData: false,
contentType: false,
success: function (response) {
$(modal).modal("hide");
Swal.fire({
title: response.status ? "Berhasil" : "Gagal",
text: response.message,
icon: response.status ? "success" : "error",
confirmButtonText: "OK",
}).then(function () {
location.href =
"{{ route('user-transaction.index.pembeli') }}";
});
console.log(response);
},
error: function (error) {
$(modal).modal("hide");
Swal.fire({
title: "Gagal",
text: "Gagal mengirimkan data karena " + error,
icon: "error",
});
console.log(error);
},
});
}
});
});

View File

@ -302,62 +302,74 @@
<div class="col-12">
<div class="card">
<div class="card-header">
<h2>History Transaction</h2>
<div class="container">
<h2>History Transaction</h2>
</div>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped" id="table-1">
<table class="table table-striped" id="table-4">
<thead>
<tr>
<th class="text-center">
#
</th>
<th>Order Id</th>
<th>Customer</th>
<th>Seller</th>
<th>Nama Barang</th>
<th>Pembeli</th>
<th>Penjual</th>
<th>Total</th>
<th>Due Date</th>
<th>Tanggal Transaksi</th>
<th>Tanggal Update</th>
<th>Status</th>
<th>Action</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
@foreach ($transactions as $transaction)
<tr>
<td>{{ $transaction['no'] }}</td>
<td><a href="#">{{ $transaction['orderId'] }}</a></td>
<td class="font-weight-600">{{ $transaction['customer'] }}</td>
<td class="font-weight-600">{{ $transaction['seller'] }}</td>
<td class="font-weight-600">{{ $transaction['total'] }}</td>
<td>{{ $transaction['date'] }}</td>
<td>
@php
$statusClass = '';
if ($transaction['status'] === 'pending') {
$statusClass = 'badge-warning';
} elseif ($transaction['status'] === 'paid') {
$statusClass = 'badge-success';
} elseif ($transaction['status'] === 'unpaid') {
$statusClass = 'badge-danger';
}
@endphp
<div class="badge {{ $statusClass }}">{{ $transaction['status'] }}
</div>
<td>{{ $loop->iteration }}</td>
<td>{{ $transaction->nama_barang }}</td>
<td>{{ $transaction->data_pembeli->nama_depan . ' ' . $transaction->data_pembeli->nama_belakang }}
</td>
<td>{{ $transaction->data_penjual->nama_depan . ' ' . $transaction->data_penjual->nama_belakang }}
</td>
<td>Rp {{ number_format($transaction->total_bayar, 2, ',', '.') }}</td>
<td>{{ $transaction->created_at }}</td>
<td>{{ $transaction->updated_at }}</td>
<td><a href="#" data-toggle="modal"
data-target="#modalKeteranganStatus"
class="badge {{ in_array($transaction->status, ['pending', 'created'])
? 'badge-light'
: (in_array($transaction->status, ['settlement', 'capture'])
? 'badge-info'
: (in_array($transaction->status, ['process', 'sending', 'sended'])
? 'badge-warning'
: (in_array($transaction->status, ['cancel', 'expire', 'failure', 'refund'])
? 'badge-danger'
: ($transaction->status == 'finished'
? 'badge-success'
: '')))) }}">{{ ucwords($transaction->status) }}</a>
</td>
<td>
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle"
data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false">
Action
...
</button>
<div class="dropdown-menu">
<a class="dropdown-item"
href="/detail_transaction">Details</a>
<a class="dropdown-item" href="#" data-toggle="modal"
data-target="#ModalTransaction">Tracking</a>
<a class="dropdown-item" href="#">Delete</a>
</div>
<ul class="dropdown-menu">
<li><a class="dropdown-item"
href="{{ route('admin-transaction.show', $transaction->id) }}">Detail</a>
</li>
@if (!$transaction->transactionDescription->isEmpty())
<li><a class="dropdown-item" data-toggle="modal"
data-target="#modalTracking"
data-transaction="{{ $transaction->transactionDescription }}">Tracking</a>
</li>
@endif
</ul>
</div>
</td>
</tr>

View File

@ -19,7 +19,6 @@
<th class="text-center">
#
</th>
<th>ID</th>
<th>Pembeli</th>
<th>Nama Barang</th>
<th>Penjual</th>

View File

@ -19,7 +19,7 @@
<th class="text-center">
#
</th>
<th>ID</th>
<th>Nama Barang</th>
<th>Pembeli</th>
<th>Penjual</th>
<th>Total</th>
@ -33,7 +33,7 @@
@foreach ($transactions as $transaction)
<tr>
<td>{{ $loop->iteration }}</td>
<td>{{ $transaction->id }}</td>
<td>{{ $transaction->nama_barang }}</td>
<td>{{ $transaction->data_pembeli->nama_depan . ' ' . $transaction->data_pembeli->nama_belakang }}
</td>
<td>{{ $transaction->data_penjual->nama_depan . ' ' . $transaction->data_penjual->nama_belakang }}

View File

@ -44,7 +44,7 @@
<div class="input-group">
<input type="email" class="form-control" id="inputPenjual"
name="input_penjual" placeholder="Masukkan email penjual">
<button class="btn btn-danger" type="button" id="checkButton">Check</button>
<button class="btn btn-danger" type="button" id="checkButton">Cek</button>
</div>
</div>
@ -122,6 +122,304 @@
<script>
var persentaseKeuntungan = {{ $persentase_keuntungan }};
</script>
<script src="{{ asset('assets/js/progress_bar/progress_bar.js') }}"></script>
<script src="{{ asset('assets/js/user/new-transaction.js') }}"></script>
{{-- <script src="{{ asset('assets/js/user/new-transaction.js') }}"></script> --}}
<script>
$(document).ready(function() {
let totalHarga = 0;
let biayaAdmin = persentaseKeuntungan;
let totalBiayaAdmin = 0;
let totalBayar = 0;
function tampilTotalHarga(harga) {
let tampilTotalNominal = document.getElementById("totalBiaya");
let tampilTotalBiaya = document.getElementById("totalBayar");
let tampilTotalBiayaAdmin = document.getElementById("totalBiayaAdmin");
totalBiayaAdmin = (harga * biayaAdmin) / 100;
totalBayar = totalBiayaAdmin + harga;
tampilTotalNominal.innerHTML = harga.toLocaleString("id-ID", {
style: "currency",
currency: "IDR",
});
tampilTotalBiaya.innerHTML = totalBayar.toLocaleString("id-ID", {
style: "currency",
currency: "IDR",
});
tampilTotalBiayaAdmin.innerHTML = totalBiayaAdmin.toLocaleString(
"id-ID", {
style: "currency",
currency: "IDR",
}
);
}
$("#selectContact").select2({
placeholder: "Pilih Kontak",
ajax: {
url: "{{ route('user-contact.get') }}",
processResults: function({
data
}) {
return {
results: $.map(data, function(item) {
return {
id: item.relasi_kontak,
text: item.nama_depan + " " + item.nama_belakang,
};
}),
};
},
},
});
$("#hargaBarang").change(function() {
let harga = $(this).val();
let jumlah = $("#jumlahBarang").val();
let biaya = document.getElementById("totalBiaya");
if (harga.trim() != "") {
if (jumlah.trim() != "") {
totalHarga = harga * jumlah;
} else {
totalHarga = harga * 0;
}
tampilTotalHarga(totalHarga);
}
});
$("#jumlahBarang").change(function() {
let jumlah = $(this).val();
let harga = $("#hargaBarang").val();
let nominal = document.getElementById("jumlah");
if (jumlah.trim() != "") {
if (jumlah == 0) {
nominal.innerHTML = "Nominal";
} else {
nominal.innerHTML = "Nominal (x" + jumlah + ")";
}
if (harga.trim() != "") {
totalHarga = harga * jumlah;
} else {
totalHarga = 0 * jumlah;
}
tampilTotalHarga(totalHarga);
}
});
$("#selectContact").change(function() {
let email = $("#selectContact").val();
if (email === null) {
$("#inputPenjual").prop("disabled", false);
$("#checkButton").prop("disabled", false);
$("#deleteOption").prop("disabled", false);
} else {
$("#inputPenjual").prop("disabled", true);
$("#deleteOption").prop("disabled", false);
$("#checkButton").prop("disabled", true);
}
});
$("#deleteOption").click(function() {
$("#selectContact").val(null).trigger("change");
});
$("#inputPenjual").on("input", function() {
let emailInput = $("#inputPenjual").val();
if (emailInput.trim() == "") {
$("#selectContact").prop("disabled", false);
$("#deleteOption").prop("disabled", false);
} else {
$("#selectContact").prop("disabled", true);
$("#deleteOption").prop("disabled", true);
}
});
$("#checkButton").click(function() {
let email = document.querySelector('[name="input_penjual"]').value;
const csrfToken = $('meta[name="csrf-token"]').attr("content");
if (email.trim() == "") {
Swal.fire({
title: "Gagal",
text: "Email tidak boleh kosong",
icon: "error",
});
} else {
Swal.fire({
html: '<div class="mt-3"><lord-icon src="https://cdn.lordicon.com/etwtznjn.json" trigger="loop" colors="primary:#0ab39c,secondary:#405189" style="width:120px;height:120px"></lord-icon><div class="mt-4 pt-2 fs-15"><h4>Form Anda sedang diproses!</h4><p class="text-muted mx-4 mb-0">Mohon tunggu...</p></div></div>',
allowEscapeKey: false,
allowOutsideClick: false,
didOpen: () => {
Swal.showLoading();
}
});
if (email != "{{ Auth::user()->email }}") {
$.ajaxSetup({
headers: {
"X-CSRF-TOKEN": csrfToken,
},
});
$.ajax({
url: "{{ route('user-contact.email', ':email') }}".replace(
":email",
email
),
type: "GET",
success: function(response) {
if (
response.status &&
(response.message.nama_bank == null ||
response.message.nama_bank == "") &&
(response.message.no_rek == null ||
response.message.no_rek == "")
) {
Swal.fire({
title: "Berhasil",
text: "Akun tersedia",
icon: "success",
});
} else {
Swal.fire({
title: "Gagal",
text: response.message,
icon: "error",
});
}
},
error: function(error) {
Swal.fire({
title: "Gagal",
text: "Terjadi error karena, " + error,
icon: "error",
});
},
});
} else {
Swal.fire({
title: "Gagal",
text: "Email penjual tidak boleh sama denggan email pembeli",
icon: "error",
});
}
}
});
$("#save").on("click", function() {
let opsiKontak = document.querySelector(
'[name="select_penjual"]'
).value;
let inputKontak = document.querySelector(
'[name="input_penjual"]'
).value;
let namaBarang = document.querySelector('[name="nama_barang"]').value;
let hargaBarang = document.querySelector('[name="harga_barang"]').value;
let satuanBarang = document.querySelector(
'[name="satuan_barang"]'
).value;
let jumlahBarang = document.querySelector(
'[name="jumlah_barang"]'
).value;
let deskripsi = document.querySelector(
'textarea[name="deskripsi"]'
).value;
let emptyInput = [];
let penjual = "";
if (opsiKontak != "" && inputKontak != "") {
penjual = opsiKontak;
} else if (opsiKontak == "" && inputKontak != "") {
penjual = inputKontak;
} else if (inputKontak == "" && opsiKontak != "") {
penjual = opsiKontak;
} else {
emptyInput.push("Kolom penjual tidak boleh kosong");
}
if (penjual == "{{ Auth::user()->email }}") {
emptyInput.push(
"Email penjual tidak boleh sama dengan email pembeli"
);
}
if (namaBarang == "") {
emptyInput.push("Nama barang tidak boleh kosong");
}
if (hargaBarang == "") {
emptyInput.push("Harga barang tidak boleh kosong");
}
if (satuanBarang == "") {
emptyInput.push("Satuan barang tidak boleh kosong");
}
if (jumlahBarang == "") {
emptyInput.push("Jumlah barang tidak boleh kosong");
}
if (emptyInput.length > 0) {
const emptyInputError = emptyInput.join(", ");
Swal.fire({
title: "Gagal",
text: emptyInputError,
icon: "error",
confirmButtonText: "OK",
});
} else {
const csrfToken = $('meta[name="csrf-token"]').attr("content");
const formData = new FormData();
formData.append("email_penjual", penjual);
formData.append("nama_barang", namaBarang);
formData.append("satuan_barang", satuanBarang);
formData.append("harga_barang", hargaBarang);
formData.append("jumlah_barang", jumlahBarang);
// formData.append('batas_pengiriman', batasPengiriman);
formData.append("deskripsi", deskripsi);
formData.append("persentase_keuntungan", biayaAdmin);
formData.append("total_keuntungan", totalBiayaAdmin);
formData.append("total_harga", totalHarga);
formData.append("total_bayar", totalBayar);
$(modal).modal("show");
$.ajaxSetup({
headers: {
"X-CSRF-TOKEN": csrfToken,
},
});
$.ajax({
url: "{{ route('user-pembeli.store') }}",
type: "POST",
data: formData,
processData: false,
contentType: false,
success: function(response) {
$(modal).modal("hide");
Swal.fire({
title: response.status ? "Berhasil" : "Gagal",
text: response.message,
icon: response.status ? "success" : "error",
confirmButtonText: "OK",
}).then(function() {
location.href =
"{{ route('user-pembeli.index') }}";
});
console.log(response);
},
error: function(error) {
$(modal).modal("hide");
Swal.fire({
title: "Gagal",
text: "Gagal mengirimkan data karena " + error,
icon: "error",
});
console.log(error);
},
});
}
});
});
</script>
@endsection