Revisi tampilan dashboard admin
This commit is contained in:
parent
1e13f9d925
commit
0f45ead6bc
@ -67,7 +67,10 @@ class AdminDashboardController extends Controller
|
|||||||
$dataChartRefund[] = intval($refund);
|
$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()
|
public function getChartByMonth()
|
||||||
|
@ -23,9 +23,9 @@ class UserContactController extends Controller
|
|||||||
public function getContact()
|
public function getContact()
|
||||||
{
|
{
|
||||||
$data = DB::table('contacts')
|
$data = DB::table('contacts')
|
||||||
->select('contacts.relasi_kontak', 'users.nama_depan', 'users.nama_belakang')
|
|
||||||
->join('users', 'contacts.relasi_kontak', '=', 'users.email')
|
->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);
|
->paginate(10);
|
||||||
return response()->json($data);
|
return response()->json($data);
|
||||||
}
|
}
|
||||||
@ -89,7 +89,9 @@ class UserContactController extends Controller
|
|||||||
|
|
||||||
public function cekEmail($email)
|
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) {
|
||||||
if ($result->status == 'Finished') {
|
if ($result->status == 'Finished') {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
|
@ -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);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
@ -302,62 +302,74 @@
|
|||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h2>History Transaction</h2>
|
<div class="container">
|
||||||
|
<h2>History Transaction</h2>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-striped" id="table-1">
|
<table class="table table-striped" id="table-4">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="text-center">
|
<th class="text-center">
|
||||||
#
|
#
|
||||||
</th>
|
</th>
|
||||||
<th>Order Id</th>
|
<th>Nama Barang</th>
|
||||||
<th>Customer</th>
|
<th>Pembeli</th>
|
||||||
<th>Seller</th>
|
<th>Penjual</th>
|
||||||
<th>Total</th>
|
<th>Total</th>
|
||||||
<th>Due Date</th>
|
<th>Tanggal Transaksi</th>
|
||||||
|
<th>Tanggal Update</th>
|
||||||
<th>Status</th>
|
<th>Status</th>
|
||||||
<th>Action</th>
|
<th>Aksi</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach ($transactions as $transaction)
|
@foreach ($transactions as $transaction)
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ $transaction['no'] }}</td>
|
<td>{{ $loop->iteration }}</td>
|
||||||
<td><a href="#">{{ $transaction['orderId'] }}</a></td>
|
<td>{{ $transaction->nama_barang }}</td>
|
||||||
<td class="font-weight-600">{{ $transaction['customer'] }}</td>
|
<td>{{ $transaction->data_pembeli->nama_depan . ' ' . $transaction->data_pembeli->nama_belakang }}
|
||||||
<td class="font-weight-600">{{ $transaction['seller'] }}</td>
|
</td>
|
||||||
<td class="font-weight-600">{{ $transaction['total'] }}</td>
|
<td>{{ $transaction->data_penjual->nama_depan . ' ' . $transaction->data_penjual->nama_belakang }}
|
||||||
<td>{{ $transaction['date'] }}</td>
|
</td>
|
||||||
<td>
|
<td>Rp {{ number_format($transaction->total_bayar, 2, ',', '.') }}</td>
|
||||||
@php
|
<td>{{ $transaction->created_at }}</td>
|
||||||
$statusClass = '';
|
<td>{{ $transaction->updated_at }}</td>
|
||||||
if ($transaction['status'] === 'pending') {
|
<td><a href="#" data-toggle="modal"
|
||||||
$statusClass = 'badge-warning';
|
data-target="#modalKeteranganStatus"
|
||||||
} elseif ($transaction['status'] === 'paid') {
|
class="badge {{ in_array($transaction->status, ['pending', 'created'])
|
||||||
$statusClass = 'badge-success';
|
? 'badge-light'
|
||||||
} elseif ($transaction['status'] === 'unpaid') {
|
: (in_array($transaction->status, ['settlement', 'capture'])
|
||||||
$statusClass = 'badge-danger';
|
? 'badge-info'
|
||||||
}
|
: (in_array($transaction->status, ['process', 'sending', 'sended'])
|
||||||
@endphp
|
? 'badge-warning'
|
||||||
<div class="badge {{ $statusClass }}">{{ $transaction['status'] }}
|
: (in_array($transaction->status, ['cancel', 'expire', 'failure', 'refund'])
|
||||||
</div>
|
? 'badge-danger'
|
||||||
|
: ($transaction->status == 'finished'
|
||||||
|
? 'badge-success'
|
||||||
|
: '')))) }}">{{ ucwords($transaction->status) }}</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<button type="button" class="btn btn-primary dropdown-toggle"
|
<button type="button" class="btn btn-primary dropdown-toggle"
|
||||||
data-toggle="dropdown" aria-haspopup="true"
|
data-toggle="dropdown" aria-haspopup="true"
|
||||||
aria-expanded="false">
|
aria-expanded="false">
|
||||||
Action
|
...
|
||||||
</button>
|
</button>
|
||||||
<div class="dropdown-menu">
|
|
||||||
<a class="dropdown-item"
|
<ul class="dropdown-menu">
|
||||||
href="/detail_transaction">Details</a>
|
<li><a class="dropdown-item"
|
||||||
<a class="dropdown-item" href="#" data-toggle="modal"
|
href="{{ route('admin-transaction.show', $transaction->id) }}">Detail</a>
|
||||||
data-target="#ModalTransaction">Tracking</a>
|
</li>
|
||||||
<a class="dropdown-item" href="#">Delete</a>
|
|
||||||
</div>
|
@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>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
<th class="text-center">
|
<th class="text-center">
|
||||||
#
|
#
|
||||||
</th>
|
</th>
|
||||||
<th>ID</th>
|
|
||||||
<th>Pembeli</th>
|
<th>Pembeli</th>
|
||||||
<th>Nama Barang</th>
|
<th>Nama Barang</th>
|
||||||
<th>Penjual</th>
|
<th>Penjual</th>
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
<th class="text-center">
|
<th class="text-center">
|
||||||
#
|
#
|
||||||
</th>
|
</th>
|
||||||
<th>ID</th>
|
<th>Nama Barang</th>
|
||||||
<th>Pembeli</th>
|
<th>Pembeli</th>
|
||||||
<th>Penjual</th>
|
<th>Penjual</th>
|
||||||
<th>Total</th>
|
<th>Total</th>
|
||||||
@ -33,7 +33,7 @@
|
|||||||
@foreach ($transactions as $transaction)
|
@foreach ($transactions as $transaction)
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ $loop->iteration }}</td>
|
<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>{{ $transaction->data_pembeli->nama_depan . ' ' . $transaction->data_pembeli->nama_belakang }}
|
||||||
</td>
|
</td>
|
||||||
<td>{{ $transaction->data_penjual->nama_depan . ' ' . $transaction->data_penjual->nama_belakang }}
|
<td>{{ $transaction->data_penjual->nama_depan . ' ' . $transaction->data_penjual->nama_belakang }}
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input type="email" class="form-control" id="inputPenjual"
|
<input type="email" class="form-control" id="inputPenjual"
|
||||||
name="input_penjual" placeholder="Masukkan email penjual">
|
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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -122,6 +122,304 @@
|
|||||||
<script>
|
<script>
|
||||||
var persentaseKeuntungan = {{ $persentase_keuntungan }};
|
var persentaseKeuntungan = {{ $persentase_keuntungan }};
|
||||||
</script>
|
</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
|
@endsection
|
||||||
|
Loading…
Reference in New Issue
Block a user