Compare commits
14 Commits
a3e68b8cd0
...
70c1a7a0bf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70c1a7a0bf | ||
|
|
b43b098936 | ||
|
|
1d7b9e2d32 | ||
|
|
f2d77a07c3 | ||
|
|
92d30617e3 | ||
|
|
3ba9b200b5 | ||
|
|
39879b247f | ||
|
|
aa1cf0787d | ||
|
|
9692e01400 | ||
|
|
a1cb3e3f21 | ||
|
|
94d146557f | ||
|
|
2b743f9ce6 | ||
|
|
37d48c8b15 | ||
|
|
a6be703b10 |
@ -1,10 +1,82 @@
|
||||
node_modules
|
||||
vendor
|
||||
.env
|
||||
Dockerfile
|
||||
docker-compose.yml
|
||||
# ========================================
|
||||
# Docker Ignore File
|
||||
# ========================================
|
||||
|
||||
# Git
|
||||
.git
|
||||
.gitignore
|
||||
tests
|
||||
.gitattributes
|
||||
|
||||
# Documentation
|
||||
README.md
|
||||
CHANGELOG.md
|
||||
Documentation/
|
||||
*.md
|
||||
|
||||
# Tests
|
||||
tests/
|
||||
phpunit.xml
|
||||
.phpunit.cache
|
||||
.phpunit.result.cache
|
||||
|
||||
# IDE & Editors
|
||||
.vscode/
|
||||
.idea/
|
||||
.fleet/
|
||||
.nova/
|
||||
.zed/
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
.phpactor.json
|
||||
|
||||
# Docker files (tidak perlu di-copy ke image)
|
||||
Dockerfile
|
||||
docker-compose*.yml
|
||||
.dockerignore
|
||||
|
||||
# Environment files (akan di-set via environment variables)
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
|
||||
# Dependencies (akan di-install via composer & npm)
|
||||
/vendor/
|
||||
/node_modules/
|
||||
|
||||
# Build artifacts (akan di-build di stage terpisah)
|
||||
/public/hot
|
||||
/public/build
|
||||
|
||||
# Storage & Cache (akan di-mount sebagai volume)
|
||||
/storage/*.key
|
||||
/storage/logs/*
|
||||
/storage/framework/cache/*
|
||||
/storage/framework/sessions/*
|
||||
/storage/framework/views/*
|
||||
/storage/pail
|
||||
|
||||
# Generated files
|
||||
/public/storage
|
||||
/bootstrap/cache/*
|
||||
|
||||
# Local development files
|
||||
Homestead.json
|
||||
Homestead.yaml
|
||||
auth.json
|
||||
.vagrant
|
||||
.phpstorm.meta.php
|
||||
_ide_helper.php
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
storage/logs/*
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# OS Files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
desktop.ini
|
||||
86
.env.docker
Normal file
86
.env.docker
Normal file
@ -0,0 +1,86 @@
|
||||
# ========================================
|
||||
# Abbauf Kasir - Docker Environment Configuration
|
||||
# ========================================
|
||||
# Copy file ini ke .env sebelum deployment
|
||||
# Ganti semua placeholder dengan nilai yang sesuai
|
||||
|
||||
# Application
|
||||
APP_NAME=Abbauf-Kasir
|
||||
APP_ENV=production
|
||||
APP_KEY= # Generate dengan: php artisan key:generate
|
||||
APP_DEBUG=false
|
||||
APP_URL=http://localhost # Ganti dengan domain production
|
||||
|
||||
APP_LOCALE=id
|
||||
APP_FALLBACK_LOCALE=en
|
||||
APP_FAKER_LOCALE=id_ID
|
||||
|
||||
APP_MAINTENANCE_DRIVER=file
|
||||
PHP_CLI_SERVER_WORKERS=4
|
||||
|
||||
BCRYPT_ROUNDS=12
|
||||
|
||||
# Logging
|
||||
LOG_CHANNEL=stack
|
||||
LOG_STACK=daily
|
||||
LOG_DEPRECATIONS_CHANNEL=null
|
||||
LOG_LEVEL=error
|
||||
|
||||
# Database Configuration
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=mysql # Nama service di docker-compose
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=kasir_db # Nama database
|
||||
DB_USERNAME=kasir_user # Username database
|
||||
DB_PASSWORD=strong_password_here # GANTI dengan password kuat!
|
||||
|
||||
# MySQL Root Password (untuk docker-compose)
|
||||
MYSQL_ROOT_PASSWORD=root_strong_password # GANTI dengan password root yang kuat!
|
||||
|
||||
# Cache & Session
|
||||
CACHE_STORE=redis
|
||||
SESSION_DRIVER=redis
|
||||
SESSION_LIFETIME=120
|
||||
SESSION_ENCRYPT=false
|
||||
SESSION_PATH=/
|
||||
SESSION_DOMAIN=null
|
||||
|
||||
# Redis Configuration
|
||||
REDIS_CLIENT=phpredis
|
||||
REDIS_HOST=redis
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
# Queue
|
||||
QUEUE_CONNECTION=redis
|
||||
|
||||
# Broadcasting
|
||||
BROADCAST_CONNECTION=log
|
||||
|
||||
# Filesystem
|
||||
FILESYSTEM_DISK=local
|
||||
|
||||
# Mail Configuration (opsional)
|
||||
MAIL_MAILER=log
|
||||
MAIL_SCHEME=null
|
||||
MAIL_HOST=127.0.0.1
|
||||
MAIL_PORT=2525
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_FROM_ADDRESS="noreply@abbauf-kasir.local"
|
||||
MAIL_FROM_NAME="${APP_NAME}"
|
||||
|
||||
# AWS (jika menggunakan S3 untuk storage)
|
||||
AWS_ACCESS_KEY_ID=
|
||||
AWS_SECRET_ACCESS_KEY=
|
||||
AWS_DEFAULT_REGION=us-east-1
|
||||
AWS_BUCKET=
|
||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||
|
||||
# Ports (untuk docker-compose)
|
||||
APP_PORT=80 # Port untuk akses aplikasi
|
||||
# DB_PORT=3306 # Uncomment jika ingin expose DB port
|
||||
# REDIS_PORT=6379 # Uncomment jika ingin expose Redis port
|
||||
|
||||
# Vite
|
||||
VITE_APP_NAME="${APP_NAME}"
|
||||
@ -1,8 +1,8 @@
|
||||
APP_NAME=Abbauf-Kasir
|
||||
APP_ENV=local
|
||||
APP_ENV=production
|
||||
APP_KEY=
|
||||
APP_DEBUG=true
|
||||
APP_URL=http://localhost:8000
|
||||
APP_DEBUG=false
|
||||
APP_URL=http://localhost
|
||||
|
||||
APP_LOCALE=en
|
||||
APP_FALLBACK_LOCALE=en
|
||||
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@ -22,3 +22,8 @@
|
||||
Homestead.json
|
||||
Homestead.yaml
|
||||
Thumbs.db
|
||||
|
||||
# Docker - Database Backups (exclude backups from git)
|
||||
/docker/mysql/backups/*.sql
|
||||
/docker/mysql/backups/*.sql.gz
|
||||
!/docker/mysql/backups/README.md
|
||||
|
||||
87
Dockerfile
87
Dockerfile
@ -1,34 +1,91 @@
|
||||
# Stage 1: Build Vue (tetap sama)
|
||||
FROM node:20 as node_builder
|
||||
# ========================================
|
||||
# Stage 1: Build Frontend Assets (Vue.js)
|
||||
# ========================================
|
||||
FROM node:20-alpine as node_builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files untuk caching layer
|
||||
COPY package*.json ./
|
||||
RUN npm install
|
||||
|
||||
# Install dependencies
|
||||
RUN npm ci --legacy-peer-deps
|
||||
|
||||
# Copy seluruh source code
|
||||
COPY . .
|
||||
|
||||
# Build production assets
|
||||
RUN npm run build
|
||||
|
||||
# Stage 2: Laravel
|
||||
FROM php:8.3-fpm
|
||||
# ========================================
|
||||
# Stage 2: Laravel Application
|
||||
# ========================================
|
||||
FROM php:8.3-fpm-alpine
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
git unzip libzip-dev libpng-dev libonig-dev libxml2-dev curl \
|
||||
&& docker-php-ext-install pdo_mysql zip gd mbstring exif pcntl bcmath \
|
||||
&& apt-get clean && rm -rf /var/lib/apt/lists/* # Cleanup untuk ukuran kecil
|
||||
# Install system dependencies dan PHP extensions
|
||||
RUN apk update && apk add --no-cache \
|
||||
git \
|
||||
unzip \
|
||||
libzip-dev \
|
||||
libpng-dev \
|
||||
oniguruma-dev \
|
||||
libxml2-dev \
|
||||
curl \
|
||||
mysql-client \
|
||||
autoconf \
|
||||
g++ \
|
||||
make \
|
||||
&& docker-php-ext-install \
|
||||
pdo_mysql \
|
||||
zip \
|
||||
gd \
|
||||
mbstring \
|
||||
exif \
|
||||
pcntl \
|
||||
bcmath \
|
||||
&& pecl install redis \
|
||||
&& docker-php-ext-enable redis \
|
||||
&& apk del autoconf g++ make \
|
||||
&& rm -rf /var/cache/apk/* /tmp/*
|
||||
|
||||
# Install Composer
|
||||
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /var/www/html
|
||||
|
||||
# Copy source code
|
||||
# Copy composer files untuk caching layer
|
||||
COPY composer.json composer.lock ./
|
||||
|
||||
# Install PHP dependencies
|
||||
RUN composer install --no-dev --no-scripts --no-autoloader --prefer-dist
|
||||
|
||||
# Copy application source code
|
||||
COPY . .
|
||||
# Copy hasil build Vue
|
||||
|
||||
# Copy hasil build Vue dari stage 1
|
||||
COPY --from=node_builder /app/public/build /var/www/html/public/build
|
||||
|
||||
RUN composer install --no-dev --optimize-autoloader
|
||||
RUN php artisan config:cache && php artisan route:cache && php artisan view:cache # Optimasi cache untuk performa laporan/transaksi
|
||||
# Generate autoload files dengan optimasi
|
||||
RUN composer dump-autoload --optimize --classmap-authoritative
|
||||
|
||||
# Set permission dan user non-root
|
||||
RUN chown -R www-data:www-data /var/www/html
|
||||
# Create required directories dan set permissions
|
||||
RUN mkdir -p \
|
||||
storage/framework/cache \
|
||||
storage/framework/sessions \
|
||||
storage/framework/views \
|
||||
storage/logs \
|
||||
bootstrap/cache \
|
||||
&& chown -R www-data:www-data \
|
||||
/var/www/html/storage \
|
||||
/var/www/html/bootstrap/cache \
|
||||
&& chmod -R 775 \
|
||||
/var/www/html/storage \
|
||||
/var/www/html/bootstrap/cache
|
||||
|
||||
# Switch ke user non-root untuk keamanan
|
||||
USER www-data
|
||||
|
||||
EXPOSE 9000
|
||||
|
||||
CMD ["php-fpm"]
|
||||
|
||||
186
README.md
186
README.md
@ -1,6 +1,6 @@
|
||||
# 💎 Aplikasi Kasir Toko Perhiasan
|
||||
|
||||
Aplikasi kasir modern berbasis web untuk toko perhiasan dengan sistem manajemen yang lengkap dan antarmuka yang user-friendly.
|
||||
Aplikasi kasir modern berbasis web untuk toko perhiasan dengan sistem manajemen yang lengkap dan antarmuka yang user-friendly. Dibuat khusus sesuai kebutuhan Toko Emas Jakarta Citayam.
|
||||
|
||||
## 👥 Tim Development
|
||||
|
||||
@ -15,7 +15,7 @@ Aplikasi kasir modern berbasis web untuk toko perhiasan dengan sistem manajemen
|
||||
|
||||
## 🚀 Tentang Aplikasi
|
||||
|
||||
Aplikasi Kasir Toko Perhiasan adalah sistem Point of Sale (POS) yang dirancang khusus untuk kebutuhan toko perhiasan dengan fitur manajemen yang komprehensif dan sistem role-based access control.
|
||||
Semuah sistem Point of Sale (POS) yang dirancang khusus untuk kebutuhan toko perhiasan dengan fitur manajemen yang komprehensif dan sistem role-based access control.
|
||||
|
||||
### ✨ Fitur Utama
|
||||
|
||||
@ -38,7 +38,7 @@ Aplikasi Kasir Toko Perhiasan adalah sistem Point of Sale (POS) yang dirancang k
|
||||
|
||||
- **Backend**: Laravel 11.x
|
||||
- **Frontend**: Vue.js 3 + Vue Router
|
||||
- **Database**: MySQL/PostgreSQL
|
||||
- **Database**: MySQL
|
||||
- **Styling**: Tailwind CSS
|
||||
- **Build Tool**: Vite
|
||||
- **Authentication**: Laravel Sanctum
|
||||
@ -48,18 +48,68 @@ Aplikasi Kasir Toko Perhiasan adalah sistem Point of Sale (POS) yang dirancang k
|
||||
|
||||
## 📋 Prerequisites
|
||||
|
||||
Pastikan sistem Anda sudah memiliki:
|
||||
### Opsi 1: Docker (Recommended) 🐳
|
||||
|
||||
- **PHP** >= 8.1
|
||||
- **Composer** >= 2.0
|
||||
- **Node.js** >= 16.x
|
||||
- **NPM** atau **Yarn**
|
||||
- **MySQL** >= 8.0 atau **PostgreSQL** >= 13
|
||||
- **Docker Desktop** (Windows/Mac) atau **Docker Engine** (Linux)
|
||||
- **Docker Compose** v2.0+
|
||||
- **Git**
|
||||
|
||||
### Opsi 2: Manual Installation
|
||||
|
||||
- **PHP** 8.2+
|
||||
- **Composer**
|
||||
- **Node.js** 18+
|
||||
- **NPM**
|
||||
- **MySQL** 8.0+
|
||||
- **Redis** (optional)
|
||||
- **Git**
|
||||
|
||||
---
|
||||
|
||||
## 🔧 Instalasi
|
||||
## <20> Docker Installation (Recommended)
|
||||
|
||||
### Quick Start dengan Docker
|
||||
|
||||
```bash
|
||||
# 1. Clone repository
|
||||
git clone https://git.abbauf.com/Magang-2025/Kasir.git
|
||||
cd Kasir
|
||||
|
||||
# 2. Setup environment
|
||||
copy .env.docker .env # Windows
|
||||
# atau
|
||||
cp .env.docker .env # Linux/Mac
|
||||
|
||||
# 3. Edit .env (PENTING: ganti password!)
|
||||
notepad .env # Windows
|
||||
nano .env # Linux/Mac
|
||||
|
||||
# 4. Deploy dengan satu command
|
||||
docker-deploy.bat # Windows
|
||||
# atau
|
||||
./docker-deploy.sh # Linux/Mac
|
||||
|
||||
# 5. Akses aplikasi
|
||||
# http://localhost
|
||||
```
|
||||
|
||||
**Dokumentasi Docker Lengkap:**
|
||||
- 📖 Quick Start: [README-DOCKER.md](README-DOCKER.md)
|
||||
- 📚 Full Guide: [DOCKER-DEPLOYMENT.md](DOCKER-DEPLOYMENT.md)
|
||||
- 📋 Checklist: [DEPLOYMENT-CHECKLIST.md](DEPLOYMENT-CHECKLIST.md)
|
||||
- 🎯 Quick Reference: [QUICK-REFERENCE.txt](QUICK-REFERENCE.txt)
|
||||
|
||||
**Management Commands:**
|
||||
```bash
|
||||
docker-helper.bat status # Cek status containers
|
||||
docker-helper.bat logs # Lihat logs
|
||||
docker-helper.bat backup # Backup database
|
||||
docker-helper.bat restart # Restart containers
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## <20>🔧 Manual Installation
|
||||
|
||||
### 1. Clone Repository
|
||||
|
||||
@ -90,15 +140,15 @@ npm install
|
||||
|
||||
### 4. Konfigurasi Database
|
||||
|
||||
Edit file `.env` sesuai dengan konfigurasi database Anda:
|
||||
Edit file `.env` sesuai dengan konfigurasi database:
|
||||
|
||||
```env
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=kasir_perhiasan
|
||||
DB_USERNAME=your_username
|
||||
DB_PASSWORD=your_password
|
||||
DB_DATABASE=toko_emas
|
||||
DB_USERNAME=root
|
||||
DB_PASSWORD=
|
||||
```
|
||||
|
||||
---
|
||||
@ -106,17 +156,16 @@ DB_PASSWORD=your_password
|
||||
### 5. Setup Database
|
||||
|
||||
```bash
|
||||
# Jalankan migrasi
|
||||
php artisan migrate
|
||||
```
|
||||
|
||||
# Jalankan seeder (data dummy)
|
||||
```bash
|
||||
php artisan db:seed
|
||||
```
|
||||
|
||||
### 6. Storage Link
|
||||
|
||||
```bash
|
||||
# Buat symbolic link untuk storage
|
||||
php artisan storage:link
|
||||
```
|
||||
|
||||
@ -125,24 +174,9 @@ php artisan storage:link
|
||||
#### Development Mode
|
||||
|
||||
```bash
|
||||
# Terminal 1 - Laravel Server
|
||||
php artisan serve
|
||||
|
||||
# Terminal 2 - Vite Dev Server
|
||||
npm run dev
|
||||
```
|
||||
|
||||
#### Production Mode
|
||||
|
||||
```bash
|
||||
# Build untuk production
|
||||
npm run build
|
||||
|
||||
# Jalankan dengan web server (Apache/Nginx)
|
||||
# atau gunakan PHP built-in server
|
||||
php artisan serve --host=0.0.0.0 --port=8000
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🌐 Akses Aplikasi
|
||||
@ -243,24 +277,10 @@ ItemTransaksi -> belongsTo -> Item
|
||||
|
||||
## 🛠️ Development
|
||||
|
||||
### Menjalankan Tests
|
||||
|
||||
```bash
|
||||
# PHP Unit Tests
|
||||
php artisan test
|
||||
|
||||
# atau dengan coverage
|
||||
php artisan test --coverage
|
||||
```
|
||||
|
||||
### Code Quality
|
||||
|
||||
```bash
|
||||
# PHP CS Fixer
|
||||
vendor/bin/php-cs-fixer fix
|
||||
|
||||
# Laravel Pint
|
||||
vendor/bin/pint
|
||||
npm run dev
|
||||
```
|
||||
|
||||
### Database Management
|
||||
@ -276,13 +296,77 @@ php artisan backup:run
|
||||
php artisan make:model ProductCategory -m
|
||||
```
|
||||
|
||||
### Production
|
||||
|
||||
> Pastikan `.env.production` sudah ada.
|
||||
### Production Deployment
|
||||
|
||||
**Dengan Docker (Recommended):**
|
||||
```bash
|
||||
docker compose --env-file .env.production up --build -d
|
||||
# 1. Setup .env untuk production
|
||||
copy .env.docker .env
|
||||
# Edit: APP_ENV=production, APP_DEBUG=false, set password kuat
|
||||
|
||||
# 2. Deploy
|
||||
docker-deploy.bat
|
||||
|
||||
# 3. Monitor
|
||||
docker-helper.bat status
|
||||
docker-helper.bat logs
|
||||
```
|
||||
|
||||
**Manual Deployment:**
|
||||
```bash
|
||||
# Build assets
|
||||
npm run build
|
||||
|
||||
# Optimize Laravel
|
||||
php artisan config:cache
|
||||
php artisan route:cache
|
||||
php artisan view:cache
|
||||
|
||||
# Set permissions
|
||||
chmod -R 775 storage bootstrap/cache
|
||||
```
|
||||
|
||||
**Dokumentasi lengkap:** [DOCKER-DEPLOYMENT.md](DOCKER-DEPLOYMENT.md)
|
||||
|
||||
---
|
||||
|
||||
## 🔄 Update Aplikasi
|
||||
|
||||
**Dengan Docker:**
|
||||
```bash
|
||||
docker-helper.bat update # Otomatis: pull, rebuild, migrate, cache
|
||||
```
|
||||
|
||||
**Manual:**
|
||||
```bash
|
||||
git pull origin main
|
||||
composer install --no-dev
|
||||
npm install && npm run build
|
||||
php artisan migrate --force
|
||||
php artisan config:cache
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 💾 Backup & Restore
|
||||
|
||||
**Backup Database (Docker):**
|
||||
```bash
|
||||
docker-helper.bat backup
|
||||
# File tersimpan di: docker/mysql/backups/
|
||||
```
|
||||
|
||||
**Restore Database (Docker):**
|
||||
```bash
|
||||
docker-helper.bat restore
|
||||
# Pilih file backup yang tersedia
|
||||
```
|
||||
|
||||
**Manual Backup:**
|
||||
```bash
|
||||
mysqldump -u root -p toko_emas > backup.sql
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📄 License
|
||||
|
||||
@ -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]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -1,56 +1,176 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
# ========================================
|
||||
# Laravel PHP-FPM Application
|
||||
# ========================================
|
||||
laravel:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: laravel_app_prod
|
||||
container_name: abbauf_kasir_app
|
||||
restart: unless-stopped
|
||||
working_dir: /var/www/html
|
||||
volumes:
|
||||
# Mount storage untuk uploads dan logs (persistent)
|
||||
- ./storage:/var/www/html/storage
|
||||
# Mount public build assets (read-only)
|
||||
- ./public/build:/var/www/html/public/build:ro
|
||||
environment:
|
||||
# Application
|
||||
APP_NAME: ${APP_NAME:-Abbauf-Kasir}
|
||||
APP_ENV: ${APP_ENV:-production}
|
||||
APP_KEY: ${APP_KEY}
|
||||
APP_DEBUG: ${APP_DEBUG:-false}
|
||||
APP_URL: ${APP_URL:-http://localhost}
|
||||
|
||||
# Database
|
||||
DB_CONNECTION: mysql
|
||||
DB_HOST: mysql
|
||||
DB_PORT: 3306
|
||||
DB_DATABASE: ${DB_DATABASE:-kasir_db}
|
||||
DB_USERNAME: ${DB_USERNAME:-kasir_user}
|
||||
DB_PASSWORD: ${DB_PASSWORD}
|
||||
|
||||
# Cache & Session
|
||||
CACHE_STORE: redis
|
||||
SESSION_DRIVER: redis
|
||||
REDIS_HOST: redis
|
||||
REDIS_PORT: 6379
|
||||
|
||||
# Queue
|
||||
QUEUE_CONNECTION: redis
|
||||
depends_on:
|
||||
mysql:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_started
|
||||
networks:
|
||||
- kasir_network
|
||||
healthcheck:
|
||||
test: ["CMD", "php-fpm", "-t"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
|
||||
# ========================================
|
||||
# Nginx Web Server
|
||||
# ========================================
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
container_name: abbauf_kasir_nginx
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "${APP_PORT:-80}:80"
|
||||
volumes:
|
||||
# Nginx configuration
|
||||
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
||||
# Laravel public directory (untuk static assets)
|
||||
- ./public:/var/www/html/public:ro
|
||||
# Storage symlink untuk file uploads
|
||||
- ./storage/app/public:/var/www/html/public/storage:ro
|
||||
depends_on:
|
||||
- laravel
|
||||
networks:
|
||||
- kasir_network
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost/"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
|
||||
# ========================================
|
||||
# MySQL Database
|
||||
# ========================================
|
||||
mysql:
|
||||
image: mysql:8.4
|
||||
container_name: abbauf_kasir_db
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root_secret_password}
|
||||
MYSQL_DATABASE: ${DB_DATABASE:-kasir_db}
|
||||
MYSQL_USER: ${DB_USERNAME:-kasir_user}
|
||||
MYSQL_PASSWORD: ${DB_PASSWORD}
|
||||
MYSQL_CHARACTER_SET_SERVER: utf8mb4
|
||||
MYSQL_COLLATION_SERVER: utf8mb4_unicode_ci
|
||||
ports:
|
||||
- "${DB_PORT:-3306}:3306"
|
||||
volumes:
|
||||
- mysql_data:/var/lib/mysql
|
||||
# Optional: backup folder
|
||||
- ./docker/mysql/backups:/backups
|
||||
networks:
|
||||
- kasir_network
|
||||
healthcheck:
|
||||
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD:-root_secret_password}"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
command: --default-authentication-plugin=mysql_native_password
|
||||
|
||||
# ========================================
|
||||
# Redis Cache & Session Store
|
||||
# ========================================
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
container_name: abbauf_kasir_redis
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "${REDIS_PORT:-6379}:6379"
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
networks:
|
||||
- kasir_network
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
command: redis-server --appendonly yes
|
||||
|
||||
# ========================================
|
||||
# Queue Worker (Optional - untuk background jobs)
|
||||
# ========================================
|
||||
queue:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: abbauf_kasir_queue
|
||||
restart: unless-stopped
|
||||
working_dir: /var/www/html
|
||||
volumes:
|
||||
- ./storage:/var/www/html/storage
|
||||
ports:
|
||||
- "9000"
|
||||
depends_on:
|
||||
- mysql
|
||||
environment:
|
||||
APP_ENV: production
|
||||
APP_DEBUG: false
|
||||
APP_ENV: ${APP_ENV:-production}
|
||||
APP_KEY: ${APP_KEY}
|
||||
DB_CONNECTION: mysql
|
||||
DB_HOST: mysql
|
||||
DB_PORT: 3306
|
||||
DB_DATABASE: ${DB_DATABASE}
|
||||
DB_USERNAME: ${DB_USERNAME}
|
||||
DB_DATABASE: ${DB_DATABASE:-kasir_db}
|
||||
DB_USERNAME: ${DB_USERNAME:-kasir_user}
|
||||
DB_PASSWORD: ${DB_PASSWORD}
|
||||
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
container_name: nginx_prod
|
||||
ports:
|
||||
- "80:80"
|
||||
volumes:
|
||||
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
||||
- ./storage:/var/www/html/storage:ro
|
||||
REDIS_HOST: redis
|
||||
QUEUE_CONNECTION: redis
|
||||
depends_on:
|
||||
- laravel
|
||||
- redis
|
||||
- mysql
|
||||
networks:
|
||||
- kasir_network
|
||||
command: php artisan queue:work --tries=3 --timeout=90
|
||||
|
||||
mysql:
|
||||
image: mysql:8
|
||||
container_name: mysql_db_prod
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
|
||||
MYSQL_DATABASE: ${DB_DATABASE}
|
||||
MYSQL_USER: ${DB_USERNAME}
|
||||
MYSQL_PASSWORD: ${DB_PASSWORD}
|
||||
ports:
|
||||
- "3306:3306"
|
||||
volumes:
|
||||
- mysql_data:/var/lib/mysql
|
||||
|
||||
redis:
|
||||
image: redis:alpine
|
||||
container_name: redis_prod
|
||||
ports:
|
||||
- "6379:6379"
|
||||
# ========================================
|
||||
# Networks
|
||||
# ========================================
|
||||
networks:
|
||||
kasir_network:
|
||||
driver: bridge
|
||||
|
||||
# ========================================
|
||||
# Persistent Volumes
|
||||
# ========================================
|
||||
volumes:
|
||||
mysql_data:
|
||||
driver: local
|
||||
redis_data:
|
||||
driver: local
|
||||
|
||||
75
nginx.conf
75
nginx.conf
@ -1,14 +1,43 @@
|
||||
# ========================================
|
||||
# Abbauf Kasir - Nginx Configuration
|
||||
# ========================================
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
index index.php index.html;
|
||||
error_log /var/log/nginx/error.log;
|
||||
access_log /var/log/nginx/access.log;
|
||||
root /var/www/html/public;
|
||||
listen [::]:80;
|
||||
server_name localhost;
|
||||
|
||||
root /var/www/html/public;
|
||||
index index.php index.html index.htm;
|
||||
|
||||
# Logging
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
|
||||
# Security Headers
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
|
||||
# Client body size limit (untuk upload file)
|
||||
client_max_body_size 20M;
|
||||
|
||||
# Gzip compression
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_proxied any;
|
||||
gzip_comp_level 6;
|
||||
gzip_types text/plain text/css text/xml text/javascript
|
||||
application/json application/javascript application/xml+rss
|
||||
application/rss+xml font/truetype font/opentype
|
||||
application/vnd.ms-fontobject image/svg+xml;
|
||||
|
||||
# Main location block
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php?$query_string;
|
||||
}
|
||||
|
||||
# PHP-FPM configuration
|
||||
location ~ \.php$ {
|
||||
try_files $uri =404;
|
||||
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||
@ -17,5 +46,43 @@ server {
|
||||
include fastcgi_params;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||
|
||||
# Buffer settings untuk performa
|
||||
fastcgi_buffer_size 128k;
|
||||
fastcgi_buffers 256 16k;
|
||||
fastcgi_busy_buffers_size 256k;
|
||||
fastcgi_temp_file_write_size 256k;
|
||||
|
||||
# Timeout settings
|
||||
fastcgi_read_timeout 300;
|
||||
fastcgi_connect_timeout 300;
|
||||
}
|
||||
|
||||
# Cache static assets
|
||||
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
access_log off;
|
||||
}
|
||||
|
||||
# Deny access to hidden files
|
||||
location ~ /\. {
|
||||
deny all;
|
||||
access_log off;
|
||||
log_not_found off;
|
||||
}
|
||||
|
||||
# Deny access to sensitive files
|
||||
location ~ /(?:\.env|\.git|composer\.json|composer\.lock|package\.json|package-lock\.json|README\.md|\.gitignore) {
|
||||
deny all;
|
||||
access_log off;
|
||||
log_not_found off;
|
||||
}
|
||||
|
||||
# Health check endpoint
|
||||
location /health {
|
||||
access_log off;
|
||||
return 200 "healthy\n";
|
||||
add_header Content-Type text/plain;
|
||||
}
|
||||
}
|
||||
@ -69,7 +69,7 @@
|
||||
<!-- QR Code -->
|
||||
<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="qrCodeUrl" alt="QR Code" class="w-36 h-36" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -333,53 +333,56 @@ const handleConfirmAction = async () => {
|
||||
|
||||
// Fungsi utilitas
|
||||
const printQR = () => {
|
||||
if (qrCodeUrl.value) {
|
||||
if (qrCodeUrl.value && selectedItem.value) {
|
||||
const printWindow = window.open('', '_blank');
|
||||
const itemCode = selectedItem.value.kode_item;
|
||||
|
||||
printWindow.document.write(`
|
||||
<html>
|
||||
<head>
|
||||
<title>Print QR Code - ${selectedItem.value.kode_item}</title>
|
||||
<title>Print QR Code - ${itemCode}</title>
|
||||
<style>
|
||||
@page {
|
||||
size: 60mm 50mm;
|
||||
margin: 1mm;
|
||||
}
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
text-align: center;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100vh;
|
||||
padding: 20px;
|
||||
}
|
||||
.qr-container {
|
||||
text-align: center;
|
||||
border: 2px solid #ccc;
|
||||
padding: 20px;
|
||||
display: inline-block;
|
||||
margin: 20px;
|
||||
}
|
||||
.qr-img {
|
||||
width: 40mm;
|
||||
height: 40mm;
|
||||
margin-bottom: 2mm;
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
}
|
||||
.item-info {
|
||||
font-size: 14pt;
|
||||
font-weight: bold;
|
||||
margin-top: 10px;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="qr-container">
|
||||
<img class="qr-img" src="${qrCodeUrl.value}" alt="QR Code"
|
||||
onload="window.print()" />
|
||||
<img id="qr-img" class="qr-img" src="${qrCodeUrl.value}" alt="QR Code" />
|
||||
<div class="item-info">
|
||||
${selectedItem.value.kode_item}
|
||||
<div style="font-weight: bold; margin-bottom: 5px;">${itemCode}</div>
|
||||
<div>${selectedItem.value.produk?.nama || ''}</div>
|
||||
<div style="color: #666; margin-top: 5px;">${selectedItem.value.produk?.berat || ''}g</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`);
|
||||
|
||||
printWindow.document.close();
|
||||
|
||||
const img = printWindow.document.getElementById("qr-img");
|
||||
img.onload = () => {
|
||||
printWindow.focus();
|
||||
printWindow.print();
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -102,14 +102,14 @@ 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}`;
|
||||
const kode_item = createdItem.value.kode_item;
|
||||
const data = kode_item;
|
||||
return `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${encodeURIComponent(data)}`;
|
||||
}
|
||||
return "";
|
||||
});
|
||||
|
||||
|
||||
// Methods
|
||||
const loadNampanList = async () => {
|
||||
try {
|
||||
@ -196,6 +196,10 @@ const printItem = () => {
|
||||
display: inline-block;
|
||||
margin: 20px;
|
||||
}
|
||||
.qr-img {
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
}
|
||||
.item-info {
|
||||
margin-top: 10px;
|
||||
font-size: 14px;
|
||||
@ -204,7 +208,7 @@ const printItem = () => {
|
||||
</head>
|
||||
<body>
|
||||
<div class="qr-container">
|
||||
<img src="${qrCodeUrl.value}" alt="QR Code" style="width: 200px; height: 200px;" />
|
||||
<img id="qr-img" class="qr-img" src="${qrCodeUrl.value}" alt="QR Code" />
|
||||
<div class="item-info">
|
||||
<div style="font-weight: bold; margin-bottom: 5px;">${itemCode}</div>
|
||||
<div>${props.product.nama}</div>
|
||||
@ -214,8 +218,14 @@ const printItem = () => {
|
||||
</body>
|
||||
</html>
|
||||
`);
|
||||
|
||||
printWindow.document.close();
|
||||
|
||||
const img = printWindow.document.getElementById("qr-img");
|
||||
img.onload = () => {
|
||||
printWindow.focus();
|
||||
printWindow.print();
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -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>
|
||||
@ -281,7 +281,7 @@ const getCurrentDate = () => {
|
||||
const month = months[now.getMonth()]
|
||||
const year = now.getFullYear()
|
||||
|
||||
return `${dayName}/${day}-${month}-${year}`
|
||||
return `${dayName}, ${day}-${month}-${year}`
|
||||
}
|
||||
|
||||
const generateTransactionCode = () => {
|
||||
|
||||
@ -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="qrCodeUrl" alt="QR Code" class="w-36 h-36" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -177,48 +177,44 @@ const qrCodeUrl = computed(() => {
|
||||
});
|
||||
|
||||
const printQR = () => {
|
||||
if (qrCodeUrl.value) {
|
||||
if (qrCodeUrl.value && selectedItem.value) {
|
||||
const printWindow = window.open('', '_blank');
|
||||
const itemCode = selectedItem.value.kode_item;
|
||||
|
||||
printWindow.document.write(`
|
||||
<html>
|
||||
<head>
|
||||
<title>Print QR Code - ${selectedItem.value.kode_item}</title>
|
||||
<title>Print QR Code - ${itemCode}</title>
|
||||
<style>
|
||||
@page {
|
||||
size: 60mm 50mm;
|
||||
margin: 1mm;
|
||||
}
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
}
|
||||
.qr-container {
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
border: 2px solid #ccc;
|
||||
padding: 20px;
|
||||
display: inline-block;
|
||||
margin: 20px;
|
||||
}
|
||||
.qr-img {
|
||||
width: 40mm;
|
||||
height: 40mm;
|
||||
margin-bottom: 2mm;
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
}
|
||||
.kode-item {
|
||||
font-weight: bold;
|
||||
font-size: 14pt;
|
||||
.item-info {
|
||||
margin-top: 10px;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="qr-container">
|
||||
<img id="qr-img" class="qr-img" src="${qrCodeUrl.value}" alt="QR Code" />
|
||||
<div class="kode-item">${selectedItem.value.kode_item}</div>
|
||||
<div class="item-info">
|
||||
<div style="font-weight: bold; margin-bottom: 5px;">${itemCode}</div>
|
||||
<div>${selectedItem.value.produk?.nama || ''}</div>
|
||||
<div style="color: #666; margin-top: 5px;">${selectedItem.value.produk?.berat || ''}g</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import mainLayout from '../layouts/mainLayout.vue'
|
||||
import searchbar from '../components/Searchbar.vue';
|
||||
import searchbar from '../components/searchbar.vue';
|
||||
import BrankasList from '../components/BrankasList.vue';
|
||||
const searchQuery = ref("");
|
||||
</script>
|
||||
|
||||
@ -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>
|
||||
@ -168,7 +156,7 @@ import { ref, onMounted, computed } from "vue";
|
||||
import axios from "axios";
|
||||
import mainLayout from "../layouts/mainLayout.vue";
|
||||
import ProductCard from "../components/ProductCard.vue";
|
||||
import searchbar from "../components/Searchbar.vue";
|
||||
import searchbar from "../components/searchbar.vue";
|
||||
import CreateItemModal from "../components/CreateItemModal.vue";
|
||||
import ConfirmDeleteModal from "../components/ConfirmDeleteModal.vue";
|
||||
import InputSelect from "../components/InputSelect.vue";
|
||||
@ -319,11 +307,8 @@ function handleItemAdded() {
|
||||
if (detail.value) {
|
||||
detail.value.items_count++;
|
||||
}
|
||||
creatingItem.value = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Hapus produk
|
||||
async function deleteProduk() {
|
||||
try {
|
||||
|
||||
@ -60,7 +60,7 @@
|
||||
import { ref } from "vue";
|
||||
import axios from "axios";
|
||||
import mainLayout from "../layouts/mainLayout.vue";
|
||||
import Searchbar from "../components/Searchbar.vue";
|
||||
import Searchbar from "../components/searchbar.vue";
|
||||
import TrayList from "../components/TrayList.vue";
|
||||
import InputField from "../components/InputField.vue";
|
||||
import ConfirmDeleteModal from "../components/ConfirmDeleteModal.vue";
|
||||
@ -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