Merge branch 'production' of https://git.abbauf.com/Magang-2025/Kasir into production
This commit is contained in:
commit
3313ae13c8
@ -14,7 +14,7 @@ class TransaksiController extends Controller
|
|||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$limit = request()->query('limit', null);
|
$limit = request()->query('limit', null);
|
||||||
$query = Transaksi::with(['kasir', 'sales', 'items.item.produk'])->latest();
|
$query = Transaksi::with(['kasir', 'sales', 'itemTransaksi.item.produk'])->latest();
|
||||||
if ($limit) {
|
if ($limit) {
|
||||||
$query->limit((int)$limit);
|
$query->limit((int)$limit);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
use App\Models\itemTransaksi;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
|
||||||
class Item extends Model
|
class Item extends Model
|
||||||
@ -14,10 +13,37 @@ class Item extends Model
|
|||||||
'id_produk',
|
'id_produk',
|
||||||
'id_nampan',
|
'id_nampan',
|
||||||
'is_sold',
|
'is_sold',
|
||||||
|
'kode_item', // ✅ ditambahkan agar bisa diisi otomatis
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $hidden = ['created_at', 'updated_at', 'deleted_at'];
|
protected $hidden = ['created_at', 'updated_at', 'deleted_at'];
|
||||||
|
|
||||||
|
// ✅ Auto-generate kode_item setiap kali create
|
||||||
|
protected static function boot()
|
||||||
|
{
|
||||||
|
parent::boot();
|
||||||
|
|
||||||
|
static::creating(function ($item) {
|
||||||
|
$prefix = 'ITM';
|
||||||
|
$date = now()->format('Ymd');
|
||||||
|
|
||||||
|
// Cari item terakhir yg dibuat hari ini
|
||||||
|
$lastItem = self::whereDate('created_at', now()->toDateString())
|
||||||
|
->orderBy('id', 'desc')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$number = 1;
|
||||||
|
if ($lastItem && $lastItem->kode_item) {
|
||||||
|
// Ambil 4 digit terakhir dari kode_item
|
||||||
|
$lastNumber = intval(substr($lastItem->kode_item, -4));
|
||||||
|
$number = $lastNumber + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format: ITM202509090001
|
||||||
|
$item->kode_item = $prefix . $date . str_pad($number, 4, '0', STR_PAD_LEFT);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function produk()
|
public function produk()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Produk::class, 'id_produk');
|
return $this->belongsTo(Produk::class, 'id_produk');
|
||||||
|
@ -9,7 +9,9 @@ class Transaksi extends Model
|
|||||||
{
|
{
|
||||||
/** @use HasFactory<\Database\Factories\TransaksiFactory> */
|
/** @use HasFactory<\Database\Factories\TransaksiFactory> */
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
|
'kode_transaksi', // ✅ Tambahin kolom kode transaksi
|
||||||
'id_kasir',
|
'id_kasir',
|
||||||
'id_sales',
|
'id_sales',
|
||||||
'nama_sales',
|
'nama_sales',
|
||||||
@ -23,6 +25,24 @@ class Transaksi extends Model
|
|||||||
|
|
||||||
protected $hidden = ['updated_at', 'deleted_at'];
|
protected $hidden = ['updated_at', 'deleted_at'];
|
||||||
|
|
||||||
|
// ✅ Auto-generate kode_transaksi saat create
|
||||||
|
protected static function boot()
|
||||||
|
{
|
||||||
|
parent::boot();
|
||||||
|
|
||||||
|
// Setelah transaksi berhasil dibuat (sudah punya ID)
|
||||||
|
static::created(function ($transaksi) {
|
||||||
|
if (!$transaksi->kode_transaksi) {
|
||||||
|
$prefix = "TRS";
|
||||||
|
$date = $transaksi->created_at->format('Ymd');
|
||||||
|
$number = str_pad($transaksi->id, 4, '0', STR_PAD_LEFT);
|
||||||
|
|
||||||
|
$transaksi->kode_transaksi = $prefix . $date . $number;
|
||||||
|
$transaksi->save();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function kasir()
|
public function kasir()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class, 'id_kasir');
|
return $this->belongsTo(User::class, 'id_kasir');
|
||||||
|
@ -4,37 +4,46 @@ namespace Database\Factories;
|
|||||||
|
|
||||||
use App\Models\Sales;
|
use App\Models\Sales;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Models\Transaksi;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
/**
|
|
||||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Transaksi>
|
|
||||||
*/
|
|
||||||
class TransaksiFactory extends Factory
|
class TransaksiFactory extends Factory
|
||||||
{
|
{
|
||||||
/**
|
protected $model = Transaksi::class;
|
||||||
* Define the model's default state.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function definition(): array
|
public function definition(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$sales = Sales::inRandomOrder()->first();
|
$sales = Sales::inRandomOrder()->first();
|
||||||
$kasir = User::inRandomOrder()->first();
|
$kasir = User::inRandomOrder()->first();
|
||||||
|
|
||||||
$date = $this->faker->dateTimeBetween('-3 months');
|
$date = $this->faker->dateTimeBetween('-3 months');
|
||||||
$ongkos_bikin = $this->faker->numberBetween(8, 12) * 10000;
|
$ongkos_bikin = $this->faker->numberBetween(8, 12) * 10000;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id_kasir' => $kasir?->id,
|
'id_kasir' => $kasir?->id,
|
||||||
'id_sales' => $sales?->id,
|
'id_sales' => $sales?->id,
|
||||||
'nama_sales' => $sales?->nama,
|
'nama_sales' => $sales?->nama,
|
||||||
|
'kode_transaksi' => 'bwabwa' . $this->faker->unique()->numberBetween(1, 9999), // temporary, will be updated in configure()
|
||||||
'nama_pembeli' => $this->faker->name(),
|
'nama_pembeli' => $this->faker->name(),
|
||||||
'no_hp' => $this->faker->phoneNumber(),
|
'no_hp' => $this->faker->phoneNumber(),
|
||||||
'alamat' => $this->faker->address(),
|
'alamat' => $this->faker->address(),
|
||||||
'ongkos_bikin' => $ongkos_bikin,
|
'ongkos_bikin' => $ongkos_bikin,
|
||||||
'total_harga' => $ongkos_bikin,
|
'total_harga' => $ongkos_bikin,
|
||||||
'created_at' => $date,
|
'created_at' => $date,
|
||||||
'updated_at' => $date,
|
'updated_at' => $date,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function configure()
|
||||||
|
{
|
||||||
|
return $this->afterCreating(function (Transaksi $transaksi) {
|
||||||
|
// generate kode transaksi TRS202509090001
|
||||||
|
$prefix = "TRS";
|
||||||
|
$date = $transaksi->created_at->format('Ymd');
|
||||||
|
$number = str_pad($transaksi->id, 4, '0', STR_PAD_LEFT);
|
||||||
|
|
||||||
|
$transaksi->kode_transaksi = $prefix . $date . $number;
|
||||||
|
$transaksi->save();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*/
|
|
||||||
public function up(): void
|
|
||||||
{
|
|
||||||
Schema::create('personal_access_tokens', function (Blueprint $table) {
|
|
||||||
$table->id();
|
|
||||||
$table->morphs('tokenable');
|
|
||||||
$table->text('name');
|
|
||||||
$table->string('token', 64)->unique();
|
|
||||||
$table->text('abilities')->nullable();
|
|
||||||
$table->timestamp('last_used_at')->nullable();
|
|
||||||
$table->timestamp('expires_at')->nullable()->index();
|
|
||||||
$table->timestamps();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::dropIfExists('personal_access_tokens');
|
|
||||||
}
|
|
||||||
};
|
|
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('items', function (Blueprint $table) {
|
||||||
|
$table->string('kode_item')->unique()->after('id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('items', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('kode_item');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('transaksis', function (Blueprint $table) {
|
||||||
|
$table->string('kode_transaksi')->unique()->after('id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('transaksis', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('kode_transaksi');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
@ -20,7 +20,7 @@ class DatabaseSeeder extends Seeder
|
|||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
User::factory()->create([
|
User::factory()->create([
|
||||||
'nama' => 'iwan',
|
'nama' => 'andre',
|
||||||
'role' => 'owner',
|
'role' => 'owner',
|
||||||
'password' => bcrypt('123123'),
|
'password' => bcrypt('123123'),
|
||||||
]);
|
]);
|
||||||
|
@ -17,19 +17,16 @@ const {
|
|||||||
<template>
|
<template>
|
||||||
<div class="md:hidden">
|
<div class="md:hidden">
|
||||||
<div class="bg-D h-5 shadow-lg"></div>
|
<div class="bg-D h-5 shadow-lg"></div>
|
||||||
<div class="px-4 fixed flex items-center mt-2">
|
|
||||||
<button @click="toggleMobileMenu"
|
<button @click="toggleMobileMenu"
|
||||||
class="text-D bg-C hover:bg-B transition-colors duration-200 p-0.5 rounded-sm z-50">
|
:class="{ 'hidden': isMobileMenuOpen, 'block': !isMobileMenuOpen }"
|
||||||
<svg :class="{ 'hidden': isMobileMenuOpen, 'block': !isMobileMenuOpen }" class="w-7 h-7" fill="none"
|
class="fixed top-4 left-4 text-D bg-C hover:bg-B transition-colors duration-200 p-0.5 rounded-sm z-[9999]">
|
||||||
|
<svg class="w-7 h-7" fill="none"
|
||||||
stroke="currentColor" viewBox="0 0 24 24">
|
stroke="currentColor" viewBox="0 0 24 24">
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
|
||||||
</svg>
|
</svg>
|
||||||
<svg :class="{ 'block': isMobileMenuOpen, 'hidden': !isMobileMenuOpen }" class="w-6 h-6" fill="none"
|
|
||||||
stroke="currentColor" viewBox="0 0 24 24">
|
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
</button>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div :class="{ 'translate-x-0': isMobileMenuOpen, '-translate-x-full': !isMobileMenuOpen }"
|
<div :class="{ 'translate-x-0': isMobileMenuOpen, '-translate-x-full': !isMobileMenuOpen }"
|
||||||
class="fixed inset-y-0 left-0 w-64 bg-A transform transition-transform duration-300 ease-in-out z-50 shadow-xl">
|
class="fixed inset-y-0 left-0 w-64 bg-A transform transition-transform duration-300 ease-in-out z-50 shadow-xl">
|
||||||
@ -53,7 +50,7 @@ const {
|
|||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<transition
|
<transition
|
||||||
enter-active-class="transition-all ease-in-out duration-300"
|
enter-active-class="transition-all ease-in-out duration-300"
|
||||||
enter-from-class="transform opacity-0 max-h-0"
|
enter-from-class="transform opacity-0 max-h-0"
|
||||||
@ -91,4 +88,4 @@ const {
|
|||||||
|
|
||||||
<div v-if="isMobileMenuOpen" @click="closeMobileMenu" class="fixed inset-0 bg-black/75 z-40"></div>
|
<div v-if="isMobileMenuOpen" @click="closeMobileMenu" class="fixed inset-0 bg-black/75 z-40"></div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
class="relative border border-C rounded-md aspect-square flex items-center justify-center hover:shadow-md transition cursor-pointer overflow-hidden"
|
class="relative z-0 border border-C rounded-md aspect-square flex items-center justify-center hover:shadow-md transition cursor-pointer overflow-hidden"
|
||||||
@click="$emit('click', product.id)"
|
@click="$emit('click', product.id)"
|
||||||
>
|
>
|
||||||
<!-- Foto Produk -->
|
<!-- Foto Produk -->
|
||||||
|
@ -8,11 +8,11 @@
|
|||||||
Nampan tidak ditemukan.
|
Nampan tidak ditemukan.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-else class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
|
<div v-else class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 ">
|
||||||
<div
|
<div
|
||||||
v-for="tray in filteredTrays"
|
v-for="tray in filteredTrays"
|
||||||
:key="tray.id"
|
:key="tray.id"
|
||||||
class="border rounded-xl p-4 shadow-sm hover:shadow-md transition"
|
class="border border-C rounded-xl p-4 shadow-sm hover:shadow-md transition"
|
||||||
>
|
>
|
||||||
<div class="flex justify-between items-center mb-3">
|
<div class="flex justify-between items-center mb-3">
|
||||||
<h2 class="font-bold text-lg text-[#102C57]">{{ tray.nama }}</h2>
|
<h2 class="font-bold text-lg text-[#102C57]">{{ tray.nama }}</h2>
|
||||||
@ -26,7 +26,7 @@
|
|||||||
<div
|
<div
|
||||||
v-for="item in tray.items"
|
v-for="item in tray.items"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
class="flex justify-between items-center border rounded-lg p-2 cursor-pointer hover:bg-gray-50"
|
class="flex justify-between items-center border border-C rounded-lg p-2 cursor-pointer hover:bg-gray-50"
|
||||||
@click="openMovePopup(item)"
|
@click="openMovePopup(item)"
|
||||||
>
|
>
|
||||||
<div class="flex items-center gap-3">
|
<div class="flex items-center gap-3">
|
||||||
@ -53,7 +53,7 @@
|
|||||||
Masuk ke menu <b>Brankas</b> untuk memindahkan item ke nampan.
|
Masuk ke menu <b>Brankas</b> untuk memindahkan item ke nampan.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="border-t mt-3 pt-2 text-right font-semibold">
|
<div class="border-t border-C mt-3 pt-2 text-right font-semibold">
|
||||||
Berat Total: {{ totalWeight(tray) }}g
|
Berat Total: {{ totalWeight(tray) }}g
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="min-h-screen max-w-screen">
|
<div class="min-h-screen flex flex-col">
|
||||||
|
<!-- Navbar -->
|
||||||
<NavigationComponent />
|
<NavigationComponent />
|
||||||
<div class="mx-2 md:mx-4 lg:mx-6 xl:mx-7 my-6">
|
|
||||||
|
<!-- Konten utama -->
|
||||||
|
<div class="flex-1 mx-2 md:mx-4 lg:mx-6 xl:mx-7 my-6">
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
<Footer class="bottom-0 w-full" />
|
|
||||||
|
<!-- Footer selalu di bawah -->
|
||||||
|
<Footer class="w-full" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import Footer from '../components/Footer.vue'
|
import Footer from '../components/Footer.vue'
|
||||||
import NavigationComponent from '../components/NavigationComponent.vue';
|
import NavigationComponent from '../components/NavigationComponent.vue'
|
||||||
</script>
|
</script>
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
message="Apakah Anda yakin ingin menghapus produk ini?"
|
message="Apakah Anda yakin ingin menghapus produk ini?"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="p-6">
|
<div class="p-6 min-h-[75vh]">
|
||||||
<!-- Judul -->
|
<!-- Judul -->
|
||||||
<p class="font-serif italic text-[25px] text-D">PRODUK</p>
|
<p class="font-serif italic text-[25px] text-D">PRODUK</p>
|
||||||
|
|
||||||
@ -81,9 +81,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Grid Produk -->
|
<!-- 🔵 Loading State (sama persis dengan kategori) -->
|
||||||
|
<div v-if="loading" class="flex justify-center items-center h-screen">
|
||||||
|
<div class="animate-spin rounded-full h-8 w-8 border-b-2 border-C"></div>
|
||||||
|
<span class="ml-2 text-gray-600">Memuat data...</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 🔵 Grid Produk -->
|
||||||
<div
|
<div
|
||||||
class="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-4 mt-4"
|
v-else
|
||||||
|
class="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-4 mt-4 relative z-0"
|
||||||
>
|
>
|
||||||
<ProductCard
|
<ProductCard
|
||||||
v-for="item in filteredProducts"
|
v-for="item in filteredProducts"
|
||||||
@ -91,6 +98,27 @@
|
|||||||
:product="item"
|
:product="item"
|
||||||
@click="openOverlay(item.id)"
|
@click="openOverlay(item.id)"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<!-- 🔵 Empty State (sama kayak kategori) -->
|
||||||
|
<div
|
||||||
|
v-if="filteredProducts.length === 0"
|
||||||
|
class="col-span-full flex flex-col items-center py-10 text-gray-500"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
class="w-12 h-12 text-gray-400 mb-2"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
stroke-width="2"
|
||||||
|
d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2 2v-5m16 0h-2M4 13h2"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
<p>Tidak ada data produk</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -214,7 +242,9 @@ const showOverlay = ref(false);
|
|||||||
const currentFotoIndex = ref(0);
|
const currentFotoIndex = ref(0);
|
||||||
|
|
||||||
const kategori = ref([]);
|
const kategori = ref([]);
|
||||||
|
const loading = ref(false); // 🔥 Loading persis kategori
|
||||||
|
|
||||||
|
// Load kategori
|
||||||
const loadKategori = async () => {
|
const loadKategori = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get("/api/kategori", {
|
const response = await axios.get("/api/kategori", {
|
||||||
@ -236,23 +266,27 @@ const loadKategori = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Load produk
|
||||||
const loadProduk = async () => {
|
const loadProduk = async () => {
|
||||||
|
loading.value = true; // 🔵 start loading
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`/api/produk`, {
|
const response = await axios.get(`/api/produk`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.data && Array.isArray(response.data)) {
|
if (response.data && Array.isArray(response.data)) {
|
||||||
products.value = response.data;
|
products.value = response.data;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error loading products:", error);
|
console.error("Error loading products:", error);
|
||||||
|
} finally {
|
||||||
|
loading.value = false; // 🔵 stop loading
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Buka modal item
|
// Modal item
|
||||||
const openItemModal = () => {
|
const openItemModal = () => {
|
||||||
creatingItem.value = true;
|
creatingItem.value = true;
|
||||||
};
|
};
|
||||||
@ -260,13 +294,13 @@ const closeItemModal = () => {
|
|||||||
creatingItem.value = false;
|
creatingItem.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fetch data awal
|
// Fetch awal
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
loadKategori();
|
await loadKategori();
|
||||||
loadProduk();
|
await loadProduk();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Filter produk (kategori + search)
|
// Filter produk
|
||||||
const filteredProducts = computed(() => {
|
const filteredProducts = computed(() => {
|
||||||
let hasil = products.value;
|
let hasil = products.value;
|
||||||
|
|
||||||
@ -283,7 +317,7 @@ const filteredProducts = computed(() => {
|
|||||||
return hasil;
|
return hasil;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Buka overlay detail
|
// Overlay detail
|
||||||
function openOverlay(id) {
|
function openOverlay(id) {
|
||||||
const produk = products.value.find((p) => p.id === id);
|
const produk = products.value.find((p) => p.id === id);
|
||||||
if (produk) {
|
if (produk) {
|
||||||
@ -292,8 +326,6 @@ function openOverlay(id) {
|
|||||||
showOverlay.value = true;
|
showOverlay.value = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tutup overlay detail
|
|
||||||
function closeOverlay() {
|
function closeOverlay() {
|
||||||
showOverlay.value = false;
|
showOverlay.value = false;
|
||||||
currentFotoIndex.value = 0;
|
currentFotoIndex.value = 0;
|
||||||
@ -322,7 +354,11 @@ function formatNumber(num) {
|
|||||||
// Hapus produk
|
// Hapus produk
|
||||||
async function deleteProduk() {
|
async function deleteProduk() {
|
||||||
try {
|
try {
|
||||||
await axios.delete(`/api/produk/${detail.value.id}`);
|
await axios.delete(`/api/produk/${detail.value.id}`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
products.value = products.value.filter((p) => p.id !== detail.value.id);
|
products.value = products.value.filter((p) => p.id !== detail.value.id);
|
||||||
deleting.value = false;
|
deleting.value = false;
|
||||||
showOverlay.value = false;
|
showOverlay.value = false;
|
||||||
@ -340,7 +376,6 @@ async function deleteProduk() {
|
|||||||
width: 100% !important;
|
width: 100% !important;
|
||||||
justify-content: flex-start !important;
|
justify-content: flex-start !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.searchbar-mobile:deep(input) {
|
.searchbar-mobile:deep(input) {
|
||||||
width: 100% !important;
|
width: 100% !important;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user