menambahkan komentar
This commit is contained in:
parent
4001dfed71
commit
fa4796fbfe
|
|
@ -45,7 +45,7 @@ public function dashboard()
|
||||||
$labelHarga = $hargaStabil->pluck('tanggal')->map(function($date) {
|
$labelHarga = $hargaStabil->pluck('tanggal')->map(function($date) {
|
||||||
return \Carbon\Carbon::parse($date)->format('d M');
|
return \Carbon\Carbon::parse($date)->format('d M');
|
||||||
});
|
});
|
||||||
$dataHarga = $hargaStabil->pluck('rata_harga');
|
$dataHarga = $hargaStabil->pluck('rata_harga');//isi grafik
|
||||||
|
|
||||||
return view('admin.dashboard', compact(
|
return view('admin.dashboard', compact(
|
||||||
'totalPetani', 'totalProduk', 'totalTransaksi', 'transaksiTerbaru',
|
'totalPetani', 'totalProduk', 'totalTransaksi', 'transaksiTerbaru',
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ public function index(Request $request)
|
||||||
if ($request->has('kategori') && $request->kategori != '' && $request->kategori != 'Semua') {
|
if ($request->has('kategori') && $request->kategori != '' && $request->kategori != 'Semua') {
|
||||||
$slug = $request->kategori;
|
$slug = $request->kategori;
|
||||||
|
|
||||||
$query->whereHas('kategori', function ($q) use ($slug) {
|
$query->whereHas('kategori', function ($q) use ($slug) {//filter berdasarkan relasi kategori
|
||||||
$q->where('slug', $slug);
|
$q->where('slug', $slug);//ambil produk dgn slug tertentu
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,8 +45,8 @@ public function shop(Request $request)
|
||||||
|
|
||||||
// --- FILTER LOKASI ---
|
// --- FILTER LOKASI ---
|
||||||
if ($request->filled('provinsi')) {
|
if ($request->filled('provinsi')) {
|
||||||
$query->whereHas('petani', function($q) use ($request) {
|
$query->whereHas('petani', function($q) use ($request) {// filter data produk berdasarkan relasi petani
|
||||||
$q->where('provinsi_code', $request->provinsi);
|
$q->where('provinsi_code', $request->provinsi);// mengambil data produk sesuai dengan provinsi yang dipilih
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if ($request->filled('kota')) {
|
if ($request->filled('kota')) {
|
||||||
|
|
@ -71,10 +71,10 @@ public function shop(Request $request)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter Kategori
|
// Filter Kategori
|
||||||
if ($request->has('kategori') && $request->kategori != '') {
|
if ($request->has('kategori') && $request->kategori != '') {//memastikan user memilih kategori
|
||||||
$slug = $request->kategori;
|
$slug = $request->kategori;//ambil kategori berdasarkan slug yg diinptkan
|
||||||
$query->whereHas('kategori', function ($q) use ($slug) {
|
$query->whereHas('kategori', function ($q) use ($slug) {
|
||||||
$q->where('slug', $slug);
|
$q->where('slug', $slug);//ambil produk dhn slug tertentu
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,7 +110,7 @@ public function detail($id)
|
||||||
$produk_terkait = Produk::where('kategori_id', $produk->kategori_id)
|
$produk_terkait = Produk::where('kategori_id', $produk->kategori_id)
|
||||||
->where('id', '!=', $produk->id)
|
->where('id', '!=', $produk->id)
|
||||||
->where('stok', '>', 0)
|
->where('stok', '>', 0)
|
||||||
->inRandomOrder()
|
->inRandomOrder()//mengacak urutan data
|
||||||
->take(4)
|
->take(4)
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,13 @@ private function getChatList($user)
|
||||||
$q->where('pengirim_id', $user->id)->where('pengirim_type', get_class($user));
|
$q->where('pengirim_id', $user->id)->where('pengirim_type', get_class($user));
|
||||||
})->orWhere(function ($q) use ($user) {
|
})->orWhere(function ($q) use ($user) {
|
||||||
$q->where('penerima_id', $user->id)->where('penerima_type', get_class($user));
|
$q->where('penerima_id', $user->id)->where('penerima_type', get_class($user));
|
||||||
})->orderBy('created_at', 'desc')->get();
|
})->orderBy('created_at', 'desc')->get();//baru ke lama
|
||||||
|
|
||||||
$conversations = $allMessages->groupBy(function ($pesan) use ($user) {
|
$conversations = $allMessages->groupBy(function ($pesan) use ($user) {
|
||||||
if ($pesan->pengirim_id == $user->id && $pesan->pengirim_type == get_class($user)) {
|
if ($pesan->pengirim_id == $user->id && $pesan->pengirim_type == get_class($user)) {
|
||||||
return $pesan->penerima_type . '_' . $pesan->penerima_id;
|
return $pesan->penerima_type . '_' . $pesan->penerima_id;//grup bedasarkan penerima(lawan chat)
|
||||||
} else {
|
} else {
|
||||||
return $pesan->pengirim_type . '_' . $pesan->pengirim_id;
|
return $pesan->pengirim_type . '_' . $pesan->pengirim_id;//grup berdasarkan pengirim
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -54,7 +54,7 @@ private function getChatList($user)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index()
|
public function index()//detail chat
|
||||||
{
|
{
|
||||||
$user = $this->getAuthenticatedUser();
|
$user = $this->getAuthenticatedUser();
|
||||||
$isPetani = Auth::guard('petani')->check();
|
$isPetani = Auth::guard('petani')->check();
|
||||||
|
|
@ -66,29 +66,29 @@ public function index()
|
||||||
return view($view, compact('chatList'));
|
return view($view, compact('chatList'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show($id)
|
public function show($id)//isi chat
|
||||||
{
|
{
|
||||||
$user = $this->getAuthenticatedUser();
|
$user = $this->getAuthenticatedUser();
|
||||||
$isPetani = Auth::guard('petani')->check();
|
$isPetani = Auth::guard('petani')->check();
|
||||||
|
|
||||||
// Ambil List Chat juga (untuk Sidebar Kiri)
|
// Ambil daftar chat (untuk Sidebar Kiri)
|
||||||
$chatList = $this->getChatList($user);
|
$chatList = $this->getChatList($user);
|
||||||
|
|
||||||
// Logika Detail Chat (Kanan)
|
// Logika Detail Chat (Kanan)
|
||||||
$lawanType = $isPetani ? Pembeli::class : Petani::class;
|
$lawanType = $isPetani ? Pembeli::class : Petani::class;//menentukan lawan chat
|
||||||
$lawan = $lawanType::findOrFail($id);
|
$lawan = $lawanType::findOrFail($id);//ambil data lawan chat (id)
|
||||||
|
|
||||||
$chats = Pesan::where(function ($q) use ($user, $lawan, $lawanType) {
|
$chats = Pesan::where(function ($q) use ($user, $lawan, $lawanType) {
|
||||||
$q->where('pengirim_id', $user->id)->where('pengirim_type', get_class($user))
|
$q->where('pengirim_id', $user->id)->where('pengirim_type', get_class($user))//ambil pesan yg kirim user
|
||||||
->where('penerima_id', $lawan->id)->where('penerima_type', $lawanType);
|
->where('penerima_id', $lawan->id)->where('penerima_type', $lawanType);//tujuan pesan merupakan lawan chat
|
||||||
})->orWhere(function ($q) use ($user, $lawan, $lawanType) {
|
})->orWhere(function ($q) use ($user, $lawan, $lawanType) {
|
||||||
$q->where('pengirim_id', $lawan->id)->where('pengirim_type', $lawanType)
|
$q->where('pengirim_id', $lawan->id)->where('pengirim_type', $lawanType)//pesan dikirim oleh lawan
|
||||||
->where('penerima_id', $user->id)->where('penerima_type', get_class($user));
|
->where('penerima_id', $user->id)->where('penerima_type', get_class($user));
|
||||||
})->orderBy('created_at', 'asc')->get();
|
})->orderBy('created_at', 'asc')->get();
|
||||||
|
|
||||||
// Tandai dibaca
|
// Tandai dibaca
|
||||||
Pesan::where('pengirim_id', $lawan->id)->where('pengirim_type', $lawanType)
|
Pesan::where('pengirim_id', $lawan->id)->where('pengirim_type', $lawanType)//ambil pesan yg dikirim oleh lawan
|
||||||
->where('penerima_id', $user->id)->update(['sudah_dibaca' => true]);
|
->where('penerima_id', $user->id)->update(['sudah_dibaca' => true]);//dimana penerima adalah user yg sedang login
|
||||||
|
|
||||||
$view = $isPetani ? 'petani.pesan.show' : 'landing.pesan.show';
|
$view = $isPetani ? 'petani.pesan.show' : 'landing.pesan.show';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,12 +82,12 @@ public function edit($id)
|
||||||
$produk = Produk::with('images')->where('id', $id)->where('petani_id', Auth::guard('petani')->id())->firstOrFail();
|
$produk = Produk::with('images')->where('id', $id)->where('petani_id', Auth::guard('petani')->id())->firstOrFail();
|
||||||
$kategoris = Kategori::all();
|
$kategoris = Kategori::all();
|
||||||
|
|
||||||
$provinsis = Province::all();
|
// $provinsis = Province::all();
|
||||||
$kotas = City::where('province_code', $produk->provinsi_code)->get();
|
// $kotas = City::where('province_code', $produk->provinsi_code)->get();
|
||||||
$kecamatans = District::where('city_code', $produk->kota_code)->get();
|
// $kecamatans = District::where('city_code', $produk->kota_code)->get();
|
||||||
$desas = Village::where('district_code', $produk->kecamatan_code)->get();
|
// $desas = Village::where('district_code', $produk->kecamatan_code)->get();
|
||||||
|
|
||||||
return view('petani.produk.edit', compact('produk', 'kategoris', 'provinsis', 'kotas', 'kecamatans', 'desas'));
|
return view('petani.produk.edit', compact('produk', 'kategoris'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(Request $request, $id)
|
public function update(Request $request, $id)
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ public function editPetani()
|
||||||
$user = Auth::guard('petani')->user();
|
$user = Auth::guard('petani')->user();
|
||||||
|
|
||||||
$provinsis = Province::all();
|
$provinsis = Province::all();
|
||||||
$kotas = $user->provinsi_code ? City::where('province_code', $user->provinsi_code)->get() : [];
|
$kotas = $user->provinsi_code ? City::where('province_code', $user->provinsi_code)->get() : [];//memastikan user sdh memilih provinsi, lalu menampilkan semua kota sesuai provinsi
|
||||||
$kecamatans = $user->kota_code ? District::where('city_code', $user->kota_code)->get() : [];
|
$kecamatans = $user->kota_code ? District::where('city_code', $user->kota_code)->get() : [];
|
||||||
$desas = $user->kecamatan_code ? Village::where('district_code', $user->kecamatan_code)->get() : [];
|
$desas = $user->kecamatan_code ? Village::where('district_code', $user->kecamatan_code)->get() : [];
|
||||||
|
|
||||||
|
|
@ -53,7 +53,7 @@ public function updatePetani(Request $request)
|
||||||
$user->link_maps = $request->link_maps;
|
$user->link_maps = $request->link_maps;
|
||||||
|
|
||||||
if ($request->filled('password')) {
|
if ($request->filled('password')) {
|
||||||
$user->password = Hash::make($request->password);
|
$user->password = Hash::make($request->password);// hash untuk enkripsi pw
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->hasFile('foto')) {
|
if ($request->hasFile('foto')) {
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,9 @@ public function checkoutPage(Request $request)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LOGIKA CHECKOUT DARI KERANJANG (Database)
|
// LOGIKA CHECKOUT DARI KERANJANG (Database)
|
||||||
$cartIds = $request->query('cart_ids');
|
$cartIds = $request->query('cart_ids');//MENGAMBIL PARAMETER CARD_IDS DARI URL
|
||||||
|
|
||||||
if (!$cartIds) {
|
if (!$cartIds) {//mengecek apakah produk pada keranjang ada yg dipilih
|
||||||
return redirect()->route('cart')->with('error', 'Pilih minimal satu produk di keranjang untuk dicheckout.');
|
return redirect()->route('cart')->with('error', 'Pilih minimal satu produk di keranjang untuk dicheckout.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,7 +116,7 @@ public function prosesCheckout(Request $request)
|
||||||
'subtotal' => $total_harga,
|
'subtotal' => $total_harga,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$produk->decrement('stok', $request->jumlah);
|
$produk->decrement('stok', $request->jumlah);//mengurangi stok
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// --- LOGIKA KERANJANG (DATABASE) ---
|
// --- LOGIKA KERANJANG (DATABASE) ---
|
||||||
|
|
@ -124,19 +124,19 @@ public function prosesCheckout(Request $request)
|
||||||
throw new \Exception("ID keranjang tidak ditemukan.");
|
throw new \Exception("ID keranjang tidak ditemukan.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$cartIds = explode(',', $request->cart_ids);
|
$cartIds = explode(',', $request->cart_ids);//ubah teks menjadi array
|
||||||
|
|
||||||
$cartItems = Cart::with('produk')
|
$cartItems = Cart::with('produk')
|
||||||
->whereIn('id', $cartIds)
|
->whereIn('id', $cartIds)//ambil data cart dengan id
|
||||||
->where('pembeli_id', $pembeli_id)
|
->where('pembeli_id', $pembeli_id)//hanya ambil cart milik user yg sedang login
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$groupedByPetani = [];
|
$groupedByPetani = [];//membuat array kosong untuk menyimpan data
|
||||||
foreach ($cartItems as $item) {
|
foreach ($cartItems as $item) {//melakukan perulangan dengan memproses item satu persatu
|
||||||
$groupedByPetani[$item->produk->petani_id][] = $item;
|
$groupedByPetani[$item->produk->petani_id][] = $item;//mengambil id petani dari produk kemudian dikelompokkan (itek dikelompokkan)
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($groupedByPetani as $petani_id => $items) {
|
foreach ($groupedByPetani as $petani_id => $items) {//memproses data per petani satu persatu berdasarkan id petani
|
||||||
$transaksi = Transaksi::create([
|
$transaksi = Transaksi::create([
|
||||||
'pembeli_id' => $pembeli_id,
|
'pembeli_id' => $pembeli_id,
|
||||||
'petani_id' => $petani_id,
|
'petani_id' => $petani_id,
|
||||||
|
|
@ -160,7 +160,7 @@ public function prosesCheckout(Request $request)
|
||||||
'subtotal' => $total_per_item,
|
'subtotal' => $total_per_item,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$item->produk->decrement('stok', $item->quantity);
|
$item->produk->decrement('stok', $item->quantity);//mengurangi stok
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update total harga transaksi per petani
|
// Update total harga transaksi per petani
|
||||||
|
|
@ -233,7 +233,7 @@ public function updateStatus(Request $request, $id)
|
||||||
// Jika dibatalkan, kembalikan stok produk
|
// Jika dibatalkan, kembalikan stok produk
|
||||||
if ($request->status == 'batal') {
|
if ($request->status == 'batal') {
|
||||||
foreach ($transaksi->detailTransaksis as $detail) {
|
foreach ($transaksi->detailTransaksis as $detail) {
|
||||||
$detail->produk->increment('stok', $detail->jumlah);
|
$detail->produk->increment('stok', $detail->jumlah);//menambah atau mengembalikan stok
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -245,7 +245,7 @@ public function pesananDetail($id)
|
||||||
{
|
{
|
||||||
$petaniId = Auth::guard('petani')->id();
|
$petaniId = Auth::guard('petani')->id();
|
||||||
|
|
||||||
$pesanan = Transaksi::whereHas('detailTransaksis.produk', function ($q) use ($petaniId) {
|
$pesanan = Transaksi::whereHas('detailTransaksis.produk', function ($q) use ($petaniId) {//ambil data transaksi yang hanya dimiliki petani yg sedang login
|
||||||
$q->where('petani_id', $petaniId);
|
$q->where('petani_id', $petaniId);
|
||||||
})
|
})
|
||||||
->with(['pembeli', 'detailTransaksis.produk'])
|
->with(['pembeli', 'detailTransaksis.produk'])
|
||||||
|
|
|
||||||
|
|
@ -179,8 +179,8 @@
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
|
|
||||||
data: {
|
data: {
|
||||||
labels: labelMultiline,
|
labels: labelMultiline, //nama produk(x)
|
||||||
datasets: [{
|
datasets: [{//isi grafik(y)
|
||||||
label: 'Total Terjual',
|
label: 'Total Terjual',
|
||||||
data: dataTerlaris,
|
data: dataTerlaris,
|
||||||
backgroundColor: 'rgba(129, 196, 8, 0.8)',
|
backgroundColor: 'rgba(129, 196, 8, 0.8)',
|
||||||
|
|
@ -227,10 +227,10 @@
|
||||||
new Chart(ctxHarga, {
|
new Chart(ctxHarga, {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: {
|
data: {
|
||||||
labels: {!! json_encode($labelHarga) !!},
|
labels: {!! json_encode($labelHarga) !!},// sumbu x (tanggal)
|
||||||
datasets: [{
|
datasets: [{
|
||||||
label: 'Rata-rata Harga',
|
label: 'Rata-rata Harga',
|
||||||
data: {!! json_encode($dataHarga) !!},
|
data: {!! json_encode($dataHarga) !!},//sumbu y (daftar harga)
|
||||||
backgroundColor: 'rgba(54, 162, 235, 0.1)',
|
backgroundColor: 'rgba(54, 162, 235, 0.1)',
|
||||||
borderColor: '#36A2EB',
|
borderColor: '#36A2EB',
|
||||||
borderWidth: 2,
|
borderWidth: 2,
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ class="badge bg-primary bg-opacity-10 px-3 py-2 rounded-pill fw-bold border bord
|
||||||
class="btn btn-light border-danger text-danger border fw-bold mb-4 w-100 text-start shadow-sm"
|
class="btn btn-light border-danger text-danger border fw-bold mb-4 w-100 text-start shadow-sm"
|
||||||
style="border-radius: 10px;">
|
style="border-radius: 10px;">
|
||||||
<i class="fas fa-map-marker-alt me-2 fs-5 align-middle"></i>
|
<i class="fas fa-map-marker-alt me-2 fs-5 align-middle"></i>
|
||||||
Lihat Lokasi Lahan di Google Maps
|
Lihat Lokasi di Google Lahan Maps
|
||||||
<i class="fas fa-external-link-alt float-end mt-1 text-muted opacity-50"></i>
|
<i class="fas fa-external-link-alt float-end mt-1 text-muted opacity-50"></i>
|
||||||
</a>
|
</a>
|
||||||
@endif
|
@endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue