Merge branch 'development' into production
This commit is contained in:
commit
92d30617e3
@ -42,9 +42,20 @@ class ItemController extends Controller
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(int $id)
|
||||
public function show(string $kode_item)
|
||||
{
|
||||
$item = Item::with('produk.foto','nampan')->findOrFail($id);
|
||||
$query = Item::with(['produk.foto', 'nampan']);
|
||||
|
||||
if (is_numeric($kode_item)) {
|
||||
$item = $query->where('id', (int)$kode_item)->first();
|
||||
} else {
|
||||
$item = $query->where('kode_item', $kode_item)->first();
|
||||
}
|
||||
|
||||
if (!$item) {
|
||||
return response()->json(['message' => 'Item tidak ditemukan'], 404);
|
||||
}
|
||||
|
||||
return response()->json($item);
|
||||
}
|
||||
|
||||
|
||||
@ -27,14 +27,13 @@ class NampanController extends Controller
|
||||
'nama' => 'required|string|max:10|unique:nampans,nama',
|
||||
],
|
||||
[
|
||||
'nama.required' => 'Nama nampan harus diisi.',
|
||||
'nama.max' => 'Nama nampan maksimal 10 karakter.',
|
||||
'nama.unique' => 'Nampan dengan nama yang sama sudah ada.',
|
||||
'nama.max' => 'Nama nampan maksimal 10 karakter.'
|
||||
'nama.required' => 'Nama nampan harus diisi.'
|
||||
]);
|
||||
|
||||
Nampan::create($validated);
|
||||
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Nampan berhasil dibuat'
|
||||
],201);
|
||||
@ -59,7 +58,9 @@ class NampanController extends Controller
|
||||
'nama' => 'required|string|max:10|unique:nampans,nama,'.$id,
|
||||
],
|
||||
[
|
||||
'nama' => 'Nama nampan harus diisi.'
|
||||
'nama.max' => 'Nama nampan maksimal 10 karakter.',
|
||||
'nama.unique' => 'Nampan dengan nama yang sama sudah ada.',
|
||||
'nama.required' => 'Nama nampan harus diisi.'
|
||||
]);
|
||||
|
||||
$nampan = Nampan::findOrFail($id);
|
||||
|
||||
@ -125,13 +125,20 @@ class TransaksiController extends Controller
|
||||
]);
|
||||
|
||||
foreach ($request->items as $it) {
|
||||
// TODO: ubah saat transaksi pake kode_item
|
||||
// $item = Item::where('kode_item', $it['kode_item'])->first();
|
||||
// if (!$item) {
|
||||
// throw new \Exception("Item dengan kode_item {$it['kode_item']} tidak ditemukan.");
|
||||
// }
|
||||
$item = Item::where('id',$it['kode_item'])->with('produk')->first();
|
||||
$query = Item::with(['produk.foto', 'nampan']);
|
||||
|
||||
if (is_numeric($it['kode_item'])) {
|
||||
$item = $query->where('id', (int)$it['kode_item'])->first();
|
||||
} else {
|
||||
$item = $query->where('kode_item', $it['kode_item'])->first();
|
||||
}
|
||||
|
||||
if (!$item) {
|
||||
return response()->json(['message' => 'Item tidak ditemukan'], 404);
|
||||
}
|
||||
if (!$item) {
|
||||
throw new \Exception("Item dengan kode_item {$it['kode_item']} tidak ditemukan.");
|
||||
}
|
||||
ItemTransaksi::create([
|
||||
'id_transaksi' => $transaksi->id,
|
||||
'id_produk' => $item->produk->id,
|
||||
|
||||
@ -13,7 +13,7 @@ return new class extends Migration
|
||||
{
|
||||
Schema::create('nampans', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('nama', 100)->unique();
|
||||
$table->string('nama', 10)->unique();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
62
database/seeders/DataSeeder.php
Normal file
62
database/seeders/DataSeeder.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Kategori;
|
||||
use App\Models\Nampan;
|
||||
use App\Models\Produk;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DataSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// Nampan
|
||||
for ($i=0; $i < 30; $i++) {
|
||||
if ($i != 12) {
|
||||
Nampan::factory()->create([
|
||||
'nama' => 'A' . ($i + 1)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Kategori
|
||||
$kategoriList = ['Cincin', 'Gelang Rantai', 'Gelang Bulat', 'Kalung', 'Liontin', 'Anting', 'Giwang'];
|
||||
foreach ($kategoriList as $kategori) {
|
||||
Kategori::factory()->create([
|
||||
'nama' => $kategori
|
||||
]);
|
||||
}
|
||||
|
||||
// Produk
|
||||
$produk1 = Produk::factory()->create([
|
||||
'nama'=>'Gelang serut daun shimmer mp (mas putih)',
|
||||
'id_kategori'=>Kategori::find(2),
|
||||
'berat'=>1.4,
|
||||
'kadar'=>8,
|
||||
'harga_per_gram'=>900000,
|
||||
'harga_jual'=>1260000,
|
||||
]);
|
||||
$produk1->foto()->create([
|
||||
'id_produk'=>$produk1->id,
|
||||
'url'=>'https://i.imgur.com/eGYHzvw.jpeg'
|
||||
]);
|
||||
|
||||
$produk2 = Produk::factory()->create([
|
||||
'nama'=>'Gelang rantai 5 buah clover merah',
|
||||
'id_kategori'=>Kategori::find(2),
|
||||
'berat'=>3.6,
|
||||
'kadar'=>8,
|
||||
'harga_per_gram'=>850000,
|
||||
'harga_jual'=>3060000,
|
||||
]);
|
||||
$produk2->foto()->create([
|
||||
'id_produk'=>$produk2->id,
|
||||
'url'=>'https://i.imgur.com/UjQzYoE.jpeg'
|
||||
]);
|
||||
}
|
||||
}
|
||||
@ -20,109 +20,23 @@ class DatabaseSeeder extends Seeder
|
||||
public function run(): void
|
||||
{
|
||||
User::factory()->create([
|
||||
'nama' => 'andre',
|
||||
'nama' => 'admin',
|
||||
'role' => 'owner',
|
||||
'password' => bcrypt('123123'),
|
||||
]);
|
||||
User::factory()->create([
|
||||
'nama' => 'luis',
|
||||
'nama' => 'kasir',
|
||||
'role' => 'kasir',
|
||||
'password' => bcrypt('123123'),
|
||||
]);
|
||||
|
||||
User::factory(2)->create();
|
||||
Sales::factory(5)->create();
|
||||
|
||||
for ($i=0; $i < 30; $i++) {
|
||||
if ($i != 12) {
|
||||
Nampan::factory()->create([
|
||||
'nama' => 'A' . ($i + 1)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$kategoriList = ['Cincin', 'Gelang Rantai', 'Gelang Bulat', 'Kalung', 'Liontin', 'Anting', 'Giwang'];
|
||||
foreach ($kategoriList as $kategori) {
|
||||
Kategori::factory()->create([
|
||||
'nama' => $kategori
|
||||
]);
|
||||
}
|
||||
|
||||
// Produk::factory(10)->create()->each(function ($produk) {
|
||||
// // setiap produk punya 1-3 foto
|
||||
// $jumlah_foto = rand(1, 3);
|
||||
// $fotoData = [];
|
||||
// for ($i = 0; $i < $jumlah_foto; $i++) {
|
||||
// $fotoData[] = [
|
||||
// // 'url' => 'https://random-image-pepebigotes.vercel.app/api/random-image'
|
||||
// 'url' => 'https://static.promediateknologi.id/crop/0x0:0x0/0x0/webp/photo/p2/255/2024/12/10/Screenshot_2024-12-10-11-50-18-88_1c337646f29875672b5a61192b9010f9-1-1282380831.jpg'
|
||||
// ];
|
||||
// }
|
||||
// $produk->foto()->createMany($fotoData);
|
||||
|
||||
// $jumlah_item = rand(1, 20);
|
||||
// Item::factory($jumlah_item)->create([
|
||||
// 'id_produk' => $produk->id,
|
||||
// ]);
|
||||
// });
|
||||
|
||||
$produk1 = Produk::factory()->create([
|
||||
'nama'=>'Gelang serut daun shimmer mp (mas putih)',
|
||||
'id_kategori'=>Kategori::find(2),
|
||||
'berat'=>1.4,
|
||||
'kadar'=>8,
|
||||
'harga_per_gram'=>900000,
|
||||
'harga_jual'=>1260000,
|
||||
]);
|
||||
$produk1->foto()->create([
|
||||
'id_produk'=>$produk1->id,
|
||||
'url'=>'https://i.imgur.com/eGYHzvw.jpeg'
|
||||
Sales::factory()->create([
|
||||
'nama' => 'Umum',
|
||||
'no_hp' => '-',
|
||||
'alamat' => '-',
|
||||
]);
|
||||
|
||||
$produk2 = Produk::factory()->create([
|
||||
'nama'=>'Gelang rantai 5 buah clover merah',
|
||||
'id_kategori'=>Kategori::find(2),
|
||||
'berat'=>3.6,
|
||||
'kadar'=>8,
|
||||
'harga_per_gram'=>850000,
|
||||
'harga_jual'=>3060000,
|
||||
]);
|
||||
$produk2->foto()->create([
|
||||
'id_produk'=>$produk2->id,
|
||||
'url'=>'https://i.imgur.com/UjQzYoE.jpeg'
|
||||
]);
|
||||
|
||||
Item::factory(500)->create();
|
||||
|
||||
// 75% peluang item masuk nampan, sisanya di brankas
|
||||
$nampans = Nampan::all()->pluck('id')->toArray();
|
||||
$jumlahNampan = count($nampans);
|
||||
$counter = 0;
|
||||
|
||||
foreach (Item::all() as $item) {
|
||||
if (rand(1, 100) <= 75) {
|
||||
$item->update([
|
||||
'id_nampan' => $nampans[$counter % $jumlahNampan],
|
||||
]);
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
|
||||
Transaksi::factory(250)->create()->each(function ($transaksi) {
|
||||
$jumlah_item = rand(1, 2);
|
||||
$items = Item::with('produk')->inRandomOrder()->limit($jumlah_item)->get();
|
||||
if ($items->isEmpty()) return;
|
||||
$total_harga = $transaksi->total_harga;
|
||||
foreach ($items as $item) {
|
||||
$transaksi->itemTransaksi()->create([
|
||||
'id_produk' => $item->produk->id,
|
||||
'harga_deal' => $item->produk->harga_jual,
|
||||
'posisi_asal' => $item->id_nampan ? $item->nampan->nama : 'Brankas',
|
||||
]);
|
||||
$item->delete();
|
||||
$total_harga += $item->produk->harga_jual;
|
||||
}
|
||||
$transaksi->update(['total_harga' => $total_harga]);
|
||||
});
|
||||
$this->call(DataSeeder::class);
|
||||
$this->call(DummySeeder::class);
|
||||
}
|
||||
}
|
||||
|
||||
56
database/seeders/DummySeeder.php
Normal file
56
database/seeders/DummySeeder.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Item;
|
||||
use App\Models\Nampan;
|
||||
use App\Models\Sales;
|
||||
use App\Models\Transaksi;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DummySeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
User::factory(2)->create();
|
||||
Sales::factory(5)->create();
|
||||
|
||||
Item::factory(500)->create();
|
||||
|
||||
// 75% peluang item masuk nampan, sisanya di brankas
|
||||
$nampans = Nampan::all()->pluck('id')->toArray();
|
||||
$jumlahNampan = count($nampans);
|
||||
$counter = 0;
|
||||
|
||||
foreach (Item::all() as $item) {
|
||||
if (rand(1, 100) <= 75) {
|
||||
$item->update([
|
||||
'id_nampan' => $nampans[$counter % $jumlahNampan],
|
||||
]);
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
|
||||
Transaksi::factory(250)->create()->each(function ($transaksi) {
|
||||
$jumlah_item = rand(1, 2);
|
||||
$items = Item::with('produk')->inRandomOrder()->limit($jumlah_item)->get();
|
||||
if ($items->isEmpty()) return;
|
||||
$total_harga = $transaksi->total_harga;
|
||||
foreach ($items as $item) {
|
||||
$transaksi->itemTransaksi()->create([
|
||||
'id_produk' => $item->produk->id,
|
||||
'harga_deal' => $item->produk->harga_jual,
|
||||
'posisi_asal' => $item->id_nampan ? $item->nampan->nama : 'Brankas',
|
||||
]);
|
||||
$item->delete();
|
||||
$total_harga += $item->produk->harga_jual;
|
||||
}
|
||||
$transaksi->update(['total_harga' => $total_harga]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -66,10 +66,10 @@
|
||||
<!-- Modal Pindah Nampan -->
|
||||
<div v-if="isPopupVisible" class="fixed inset-0 bg-black/75 flex items-center justify-center p-4 z-50 backdrop-blur-sm">
|
||||
<div class="bg-white rounded-xl shadow-lg max-w-sm w-full p-6 relative transform transition-all duration-300 scale-95 opacity-0 animate-fadeIn">
|
||||
<!-- QR Code -->
|
||||
<!-- Barcode -->
|
||||
<div class="flex justify-center mb-4">
|
||||
<div class="p-2 border border-C rounded-lg">
|
||||
<img :src="qrCodeUrl" alt="QR Code" class="size-36" />
|
||||
<img :src="barcodeUrl" alt="Barcode" class="w-64 h-24" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -201,11 +201,11 @@ const confirmModalMessage = ref("");
|
||||
const confirmText = ref("Ya, Konfirmasi");
|
||||
const cancelText = ref("Batal");
|
||||
|
||||
// QR Code generator
|
||||
const qrCodeUrl = computed(() => {
|
||||
// Barcode generator (Code128)
|
||||
const barcodeUrl = computed(() => {
|
||||
if (selectedItem.value) {
|
||||
const data = selectedItem.value.kode_item;
|
||||
return `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${encodeURIComponent(data)}`;
|
||||
return `https://barcode.tec-it.com/barcode.ashx?data=${encodeURIComponent(data)}&code=Code128&dpi=96`;
|
||||
}
|
||||
return "";
|
||||
});
|
||||
@ -333,15 +333,15 @@ const handleConfirmAction = async () => {
|
||||
|
||||
// Fungsi utilitas
|
||||
const printQR = () => {
|
||||
if (qrCodeUrl.value) {
|
||||
if (barcodeUrl.value) {
|
||||
const printWindow = window.open('', '_blank');
|
||||
printWindow.document.write(`
|
||||
<html>
|
||||
<head>
|
||||
<title>Print QR Code - ${selectedItem.value.kode_item}</title>
|
||||
<title>Print Barcode - ${selectedItem.value.kode_item}</title>
|
||||
<style>
|
||||
@page {
|
||||
size: 60mm 50mm;
|
||||
size: 80mm 40mm;
|
||||
margin: 1mm;
|
||||
}
|
||||
body {
|
||||
@ -354,12 +354,12 @@ const printQR = () => {
|
||||
justify-content: center;
|
||||
height: 100vh;
|
||||
}
|
||||
.qr-container {
|
||||
.barcode-container {
|
||||
text-align: center;
|
||||
}
|
||||
.qr-img {
|
||||
width: 40mm;
|
||||
height: 40mm;
|
||||
.barcode-img {
|
||||
width: 70mm;
|
||||
height: 25mm;
|
||||
margin-bottom: 2mm;
|
||||
}
|
||||
.item-info {
|
||||
@ -369,8 +369,8 @@ const printQR = () => {
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="qr-container">
|
||||
<img class="qr-img" src="${qrCodeUrl.value}" alt="QR Code"
|
||||
<div class="barcode-container">
|
||||
<img class="barcode-img" src="${barcodeUrl.value}" alt="Barcode"
|
||||
onload="window.print()" />
|
||||
<div class="item-info">
|
||||
${selectedItem.value.kode_item}
|
||||
|
||||
@ -102,14 +102,16 @@ const createdItem = ref(null);
|
||||
// QR Code generator - berdasarkan logika dari brankas list
|
||||
const qrCodeUrl = computed(() => {
|
||||
if (createdItem.value && props.product) {
|
||||
const itemId = createdItem.value.id || createdItem.value.kode_item;
|
||||
const productName = props.product.nama.replace(/\s/g, "");
|
||||
const data = `ITM-${itemId}-${productName}`;
|
||||
return `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${encodeURIComponent(data)}`;
|
||||
const itemId = createdItem.value.kode_item || createdItem.value.id;
|
||||
const data = `${itemId}`;
|
||||
|
||||
// Barcode Code128
|
||||
return `https://barcode.tec-it.com/barcode.ashx?data=${encodeURIComponent(data)}&code=Code128&dpi=96`;
|
||||
}
|
||||
return "";
|
||||
});
|
||||
|
||||
|
||||
// Methods
|
||||
const loadNampanList = async () => {
|
||||
try {
|
||||
@ -204,7 +206,7 @@ const printItem = () => {
|
||||
</head>
|
||||
<body>
|
||||
<div class="qr-container">
|
||||
<img src="${qrCodeUrl.value}" alt="QR Code" style="width: 200px; height: 200px;" />
|
||||
<img src="${qrCodeUrl.value}" alt="Barcode" style="width: 300px; height: 100px;" />
|
||||
<div class="item-info">
|
||||
<div style="font-weight: bold; margin-bottom: 5px;">${itemCode}</div>
|
||||
<div>${props.product.nama}</div>
|
||||
|
||||
@ -284,7 +284,7 @@ const konfirmasiPenjualan = () => {
|
||||
}, 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(pesanan.value)
|
||||
// Tampilkan struk overlay
|
||||
showStruk.value = true;
|
||||
};
|
||||
|
||||
20
resources/js/components/ModalConfirm.vue
Normal file
20
resources/js/components/ModalConfirm.vue
Normal file
@ -0,0 +1,20 @@
|
||||
<template>
|
||||
<div class="fixed inset-0 bg-black/50 flex items-center justify-center z-50">
|
||||
<div class="bg-white rounded-lg p-6 max-w-sm w-full shadow-xl">
|
||||
<h3 class="text-lg font-semibold mb-4">{{ title }}</h3>
|
||||
<p class="mb-6">{{ message }}</p>
|
||||
<div class="flex justify-end gap-2">
|
||||
<button @click="$emit('cancel')" class="px-4 py-2 bg-gray-300 rounded">Batal</button>
|
||||
<button @click="$emit('confirm')" class="px-4 py-2 bg-blue-600 text-white rounded">Ya</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
defineProps({
|
||||
title: String,
|
||||
message: String
|
||||
});
|
||||
defineEmits(["confirm", "cancel"]);
|
||||
</script>
|
||||
@ -88,7 +88,7 @@
|
||||
<div class="bg-white rounded-xl shadow-lg max-w-sm w-full p-6 relative">
|
||||
<div class="flex justify-center mb-2">
|
||||
<div class="p-2 border rounded-lg">
|
||||
<img :src="qrCodeUrl" alt="QR Code" class="size-36" />
|
||||
<img :src="barcodeUrl" alt="Barcode" class="w-64 h-24" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -167,25 +167,25 @@ const selectedItem = ref(null);
|
||||
const selectedTrayId = ref("");
|
||||
const showDeleteConfirm = ref(false);
|
||||
|
||||
// QR Code generator
|
||||
const qrCodeUrl = computed(() => {
|
||||
// Barcode generator (Code128)
|
||||
const barcodeUrl = computed(() => {
|
||||
if (selectedItem.value) {
|
||||
const data = selectedItem.value.kode_item;
|
||||
return `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${encodeURIComponent(data)}`;
|
||||
return `https://barcode.tec-it.com/barcode.ashx?data=${encodeURIComponent(data)}&code=Code128&dpi=96`;
|
||||
}
|
||||
return "";
|
||||
});
|
||||
|
||||
const printQR = () => {
|
||||
if (qrCodeUrl.value) {
|
||||
if (barcodeUrl.value) {
|
||||
const printWindow = window.open('', '_blank');
|
||||
printWindow.document.write(`
|
||||
<html>
|
||||
<head>
|
||||
<title>Print QR Code - ${selectedItem.value.kode_item}</title>
|
||||
<title>Print Barcode - ${selectedItem.value.kode_item}</title>
|
||||
<style>
|
||||
@page {
|
||||
size: 60mm 50mm;
|
||||
size: 80mm 40mm;
|
||||
margin: 1mm;
|
||||
}
|
||||
* {
|
||||
@ -200,13 +200,13 @@ const printQR = () => {
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
}
|
||||
.qr-container {
|
||||
.barcode-container {
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
}
|
||||
.qr-img {
|
||||
width: 40mm;
|
||||
height: 40mm;
|
||||
.barcode-img {
|
||||
width: 70mm;
|
||||
height: 25mm;
|
||||
margin-bottom: 2mm;
|
||||
}
|
||||
.kode-item {
|
||||
@ -216,8 +216,8 @@ const printQR = () => {
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="qr-container">
|
||||
<img id="qr-img" class="qr-img" src="${qrCodeUrl.value}" alt="QR Code" />
|
||||
<div class="barcode-container">
|
||||
<img id="barcode-img" class="barcode-img" src="${barcodeUrl.value}" alt="Barcode" />
|
||||
<div class="kode-item">${selectedItem.value.kode_item}</div>
|
||||
</div>
|
||||
</body>
|
||||
@ -226,7 +226,7 @@ const printQR = () => {
|
||||
|
||||
printWindow.document.close();
|
||||
|
||||
const img = printWindow.document.getElementById("qr-img");
|
||||
const img = printWindow.document.getElementById("barcode-img");
|
||||
img.onload = () => {
|
||||
printWindow.focus();
|
||||
printWindow.print();
|
||||
|
||||
@ -33,16 +33,26 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ✅ POPUP KONFIRMASI -->
|
||||
<ModalConfirm
|
||||
v-if="showConfirm"
|
||||
title="Konfirmasi"
|
||||
:message="confirmMessage"
|
||||
@confirm="handleConfirm"
|
||||
@cancel="showConfirm = false"
|
||||
/>
|
||||
</mainLayout>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from "vue";
|
||||
import { ref, onMounted, onUnmounted } from "vue";
|
||||
import axios from "axios";
|
||||
|
||||
import mainLayout from "../layouts/mainLayout.vue";
|
||||
import KasirForm from "../components/KasirForm.vue";
|
||||
import KasirTransaksiList from "../components/KasirTransaksiList.vue";
|
||||
import ModalConfirm from "../components/ModalConfirm.vue"; // ✅ Tambah ini
|
||||
|
||||
const transaksi = ref({
|
||||
data: [],
|
||||
@ -52,13 +62,22 @@ const loading = ref(true);
|
||||
const currentPage = ref(1);
|
||||
const limit = 10;
|
||||
|
||||
const showConfirm = ref(false); // ✅
|
||||
const confirmMessage = ref("Apakah kamu yakin?"); // ✅
|
||||
let lastTransaksi = null; // untuk tau data transaksi terakhir
|
||||
|
||||
// ✅ Placeholder jika user tekan "Ya"
|
||||
const handleConfirm = () => {
|
||||
showConfirm.value = false;
|
||||
console.log("User konfirmasi, cetak struk di sini...", lastTransaksi);
|
||||
// TODO: jalankan fungsi cetakStruk(lastTransaksi)
|
||||
};
|
||||
|
||||
// Fetch hanya transaksi hari ini
|
||||
const fetchTransaksiHariIni = async (page = 1) => {
|
||||
try {
|
||||
loading.value = true;
|
||||
currentPage.value = page;
|
||||
|
||||
// Hanya fetch transaksi hari ini
|
||||
const today = new Date().toISOString().split('T')[0];
|
||||
const params = new URLSearchParams({
|
||||
limit: limit,
|
||||
@ -67,8 +86,6 @@ const fetchTransaksiHariIni = async (page = 1) => {
|
||||
end_date: today
|
||||
}).toString();
|
||||
|
||||
// console.log('Fetching transaksi hari ini:', params);
|
||||
|
||||
const res = await axios.get(`/api/transaksi?${params}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
||||
@ -80,22 +97,10 @@ const fetchTransaksiHariIni = async (page = 1) => {
|
||||
pagination: res.data.pagination || null
|
||||
};
|
||||
|
||||
// console.log("Transaksi hari ini:", transaksi.value);
|
||||
|
||||
} catch (err) {
|
||||
console.error("Gagal fetch transaksi hari ini:", err);
|
||||
transaksi.value = { data: [], pagination: null };
|
||||
|
||||
let errorMessage = 'Gagal memuat transaksi hari ini';
|
||||
if (err.response) {
|
||||
errorMessage += `: ${err.response.status} - ${err.response.data?.message || err.response.statusText}`;
|
||||
} else if (err.request) {
|
||||
errorMessage += ': Tidak ada respon dari server';
|
||||
} else {
|
||||
errorMessage += `: ${err.message}`;
|
||||
}
|
||||
|
||||
alert(errorMessage);
|
||||
alert("Gagal memuat transaksi hari ini");
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
@ -103,18 +108,13 @@ const fetchTransaksiHariIni = async (page = 1) => {
|
||||
|
||||
// Handle pagination
|
||||
const handlePageChange = (page) => {
|
||||
// console.log('Page changed to:', page);
|
||||
|
||||
if (page >= 1 && page <= (transaksi.value.pagination?.last_page || 1)) {
|
||||
fetchTransaksiHariIni(page);
|
||||
}
|
||||
};
|
||||
|
||||
// Handle transaksi baru dari KasirForm
|
||||
// ✅ Popup setelah transaksi tersimpan
|
||||
const handleTransaksiSaved = async (newTransaksi) => {
|
||||
// console.log("Transaksi baru disimpan:", newTransaksi);
|
||||
|
||||
// Karena ini transaksi hari ini, selalu tambahkan ke list
|
||||
const formattedNewTransaksi = {
|
||||
id: newTransaksi.id,
|
||||
kode_transaksi: newTransaksi.kode_transaksi,
|
||||
@ -126,30 +126,27 @@ const handleTransaksiSaved = async (newTransaksi) => {
|
||||
tanggal: new Date(newTransaksi.created_at).toLocaleDateString('id-ID')
|
||||
};
|
||||
|
||||
// Tambahkan ke awal array
|
||||
transaksi.value.data.unshift(formattedNewTransaksi);
|
||||
lastTransaksi = formattedNewTransaksi; // ✅ Simpan untuk cetak
|
||||
|
||||
// Update pagination
|
||||
if (transaksi.value.pagination) {
|
||||
transaksi.value.pagination.total += 1;
|
||||
|
||||
// Jika sudah penuh, hapus item terakhir
|
||||
if (transaksi.value.data.length > limit) {
|
||||
transaksi.value.data.pop();
|
||||
}
|
||||
}
|
||||
|
||||
// console.log("Transaksi baru ditambahkan ke list hari ini");
|
||||
confirmMessage.value = "Transaksi berhasil disimpan. Cetak struk sekarang?";
|
||||
showConfirm.value = true; // ✅ Munculkan popup
|
||||
};
|
||||
|
||||
// Auto-refresh setiap 10 detik untuk update real-time
|
||||
let refreshInterval = null;
|
||||
|
||||
const startAutoRefresh = () => {
|
||||
if (refreshInterval) clearInterval(refreshInterval);
|
||||
refreshInterval = setInterval(() => {
|
||||
fetchTransaksiHariIni(currentPage.value);
|
||||
}, 10000); // 10 detik
|
||||
}, 10000);
|
||||
};
|
||||
|
||||
const stopAutoRefresh = () => {
|
||||
@ -159,14 +156,11 @@ const stopAutoRefresh = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// Initialize
|
||||
onMounted(async () => {
|
||||
await fetchTransaksiHariIni();
|
||||
startAutoRefresh();
|
||||
});
|
||||
|
||||
// Cleanup
|
||||
import { onUnmounted } from 'vue';
|
||||
onUnmounted(() => {
|
||||
stopAutoRefresh();
|
||||
});
|
||||
|
||||
@ -77,7 +77,11 @@ const handleLogin = async () => {
|
||||
window.location.href = data.redirect;
|
||||
} catch (error) {
|
||||
if (error.response?.data?.message) {
|
||||
errorMessage.value = error.response.data.message;
|
||||
if (error.response.data.message.includes("Nama atau password salah")) {
|
||||
errorMessage.value = "Login gagal. Periksa username atau password.";
|
||||
} else {
|
||||
errorMessage.value = "Terjadi kesalahan pada server";
|
||||
}
|
||||
} else {
|
||||
errorMessage.value = "Login gagal. Periksa username atau password.";
|
||||
}
|
||||
|
||||
@ -1,13 +1,7 @@
|
||||
<template>
|
||||
<mainLayout>
|
||||
<!-- Modal Buat Item -->
|
||||
<CreateItemModal
|
||||
:isOpen="creatingItem"
|
||||
:product="detail"
|
||||
@close="closeItemModal"
|
||||
@itemAdded="handleItemAdded"
|
||||
/>
|
||||
|
||||
<CreateItemModal :isOpen="creatingItem" :product="detail" @close="closeItemModal" @itemAdded="handleItemAdded" />
|
||||
|
||||
<!-- Modal Konfirmasi Hapus Produk -->
|
||||
<ConfirmDeleteModal :isOpen="deleting" @cancel="deleting = false" @confirm="deleteProduk" title="Hapus Produk"
|
||||
@ -53,19 +47,13 @@
|
||||
|
||||
<!-- 🔹 Alert Message -->
|
||||
<div class="my-5" v-if="alert">
|
||||
<div
|
||||
v-if="alert.error"
|
||||
class="text-[#721c24] bg-[#f8d7da] border-l-4 border-[#dc3545] p-3 mb-5 rounded"
|
||||
role="alert"
|
||||
>
|
||||
<div v-if="alert.error" class="text-[#721c24] bg-[#f8d7da] border-l-4 border-[#dc3545] p-3 mb-5 rounded"
|
||||
role="alert">
|
||||
<strong class="font-bold">Error! </strong>
|
||||
<span class="block sm:inline">{{ alert.error }}</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="alert.success"
|
||||
class="text-[#155724] bg-[#d4edda] border-l-4 border-[#28a745] p-3 mb-5 rounded"
|
||||
role="alert"
|
||||
>
|
||||
<div v-if="alert.success" class="text-[#155724] bg-[#d4edda] border-l-4 border-[#28a745] p-3 mb-5 rounded"
|
||||
role="alert">
|
||||
<strong class="font-bold">Success! </strong>
|
||||
<span class="block sm:inline">{{ alert.success }}</span>
|
||||
</div>
|
||||
@ -319,11 +307,8 @@ function handleItemAdded() {
|
||||
if (detail.value) {
|
||||
detail.value.items_count++;
|
||||
}
|
||||
creatingItem.value = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Hapus produk
|
||||
async function deleteProduk() {
|
||||
try {
|
||||
|
||||
@ -99,7 +99,10 @@ const saveTray = async () => {
|
||||
}
|
||||
try {
|
||||
const token = localStorage.getItem("token");
|
||||
const headers = { Authorization: `Bearer ${token}` };
|
||||
const headers = {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${token}`
|
||||
};
|
||||
if (editingTrayId.value) {
|
||||
await axios.put(`/api/nampan/${editingTrayId.value}`, { nama: trayName.value }, { headers });
|
||||
alert.value = { success: "Nampan berhasil diperbarui" };
|
||||
@ -110,11 +113,13 @@ const saveTray = async () => {
|
||||
timer.value = setTimeout(() => { alert.value = null; }, 5000);
|
||||
closeModal();
|
||||
if (trayList.value) {
|
||||
await trayList.value.refreshData(); // Call refreshData on TrayList
|
||||
await trayList.value.refreshData();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
errorCreate.value = error.response?.data?.message || "Gagal menyimpan nampan.";
|
||||
const errors = error.response?.data?.errors?.nama || [];
|
||||
console.log(errors);
|
||||
errorCreate.value = errors[0] || 'Gagal menyimpan nampan.';
|
||||
|
||||
clearTimeout(timer.value);
|
||||
timer.value = setTimeout(() => { errorCreate.value = ""; }, 3000);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user