Update Fix
This commit is contained in:
18
.editorconfig
Normal file
18
.editorconfig
Normal file
@@ -0,0 +1,18 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.{yml,yaml}]
|
||||
indent_size = 2
|
||||
|
||||
[docker-compose.yml]
|
||||
indent_size = 4
|
||||
59
.env
Normal file
59
.env
Normal file
@@ -0,0 +1,59 @@
|
||||
APP_NAME=SehatMart
|
||||
APP_ENV=local
|
||||
APP_KEY=base64:/aTzLzWVpxbMetDegAyTFjzEsZGkSKyZywrNuajGqxE=
|
||||
APP_DEBUG=true
|
||||
APP_URL=http://localhost
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
LOG_DEPRECATIONS_CHANNEL=null
|
||||
LOG_LEVEL=debug
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=localhost
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=sistem_pos
|
||||
DB_USERNAME=root
|
||||
DB_PASSWORD=
|
||||
|
||||
BROADCAST_DRIVER=log
|
||||
CACHE_DRIVER=file
|
||||
FILESYSTEM_DISK=local
|
||||
QUEUE_CONNECTION=sync
|
||||
SESSION_DRIVER=file
|
||||
SESSION_LIFETIME=120
|
||||
|
||||
MEMCACHED_HOST=127.0.0.1
|
||||
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
MAIL_MAILER=smtp
|
||||
MAIL_HOST=mailpit
|
||||
MAIL_PORT=1025
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_ENCRYPTION=null
|
||||
MAIL_FROM_ADDRESS="hello@example.com"
|
||||
MAIL_FROM_NAME="${APP_NAME}"
|
||||
|
||||
AWS_ACCESS_KEY_ID=
|
||||
AWS_SECRET_ACCESS_KEY=
|
||||
AWS_DEFAULT_REGION=us-east-1
|
||||
AWS_BUCKET=
|
||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||
|
||||
PUSHER_APP_ID=
|
||||
PUSHER_APP_KEY=
|
||||
PUSHER_APP_SECRET=
|
||||
PUSHER_HOST=
|
||||
PUSHER_PORT=443
|
||||
PUSHER_SCHEME=https
|
||||
PUSHER_APP_CLUSTER=mt1
|
||||
|
||||
VITE_APP_NAME="${APP_NAME}"
|
||||
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||
VITE_PUSHER_HOST="${PUSHER_HOST}"
|
||||
VITE_PUSHER_PORT="${PUSHER_PORT}"
|
||||
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
|
||||
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||
59
.env.example
Normal file
59
.env.example
Normal file
@@ -0,0 +1,59 @@
|
||||
APP_NAME=Laravel
|
||||
APP_ENV=local
|
||||
APP_KEY=
|
||||
APP_DEBUG=true
|
||||
APP_URL=http://localhost
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
LOG_DEPRECATIONS_CHANNEL=null
|
||||
LOG_LEVEL=debug
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=laravel
|
||||
DB_USERNAME=root
|
||||
DB_PASSWORD=
|
||||
|
||||
BROADCAST_DRIVER=log
|
||||
CACHE_DRIVER=file
|
||||
FILESYSTEM_DISK=local
|
||||
QUEUE_CONNECTION=sync
|
||||
SESSION_DRIVER=file
|
||||
SESSION_LIFETIME=120
|
||||
|
||||
MEMCACHED_HOST=127.0.0.1
|
||||
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
MAIL_MAILER=smtp
|
||||
MAIL_HOST=mailpit
|
||||
MAIL_PORT=1025
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_ENCRYPTION=null
|
||||
MAIL_FROM_ADDRESS="hello@example.com"
|
||||
MAIL_FROM_NAME="${APP_NAME}"
|
||||
|
||||
AWS_ACCESS_KEY_ID=
|
||||
AWS_SECRET_ACCESS_KEY=
|
||||
AWS_DEFAULT_REGION=us-east-1
|
||||
AWS_BUCKET=
|
||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||
|
||||
PUSHER_APP_ID=
|
||||
PUSHER_APP_KEY=
|
||||
PUSHER_APP_SECRET=
|
||||
PUSHER_HOST=
|
||||
PUSHER_PORT=443
|
||||
PUSHER_SCHEME=https
|
||||
PUSHER_APP_CLUSTER=mt1
|
||||
|
||||
VITE_APP_NAME="${APP_NAME}"
|
||||
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||
VITE_PUSHER_HOST="${PUSHER_HOST}"
|
||||
VITE_PUSHER_PORT="${PUSHER_PORT}"
|
||||
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
|
||||
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||
11
.gitattributes
vendored
Normal file
11
.gitattributes
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
* text=auto eol=lf
|
||||
|
||||
*.blade.php diff=html
|
||||
*.css diff=css
|
||||
*.html diff=html
|
||||
*.md diff=markdown
|
||||
*.php diff=php
|
||||
|
||||
/.github export-ignore
|
||||
CHANGELOG.md export-ignore
|
||||
.styleci.yml export-ignore
|
||||
14
.gitignore
vendored
Normal file
14
.gitignore
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
# ---> VisualStudioCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
!.vscode/*.code-snippets
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
# Built Visual Studio Code Extensions
|
||||
*.vsix
|
||||
|
||||
18
LICENSE
Normal file
18
LICENSE
Normal file
@@ -0,0 +1,18 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 KoalaGree
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
|
||||
following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial
|
||||
portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
||||
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
||||
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
27
app/Console/Kernel.php
Normal file
27
app/Console/Kernel.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*/
|
||||
protected function schedule(Schedule $schedule): void
|
||||
{
|
||||
// $schedule->command('inspire')->hourly();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*/
|
||||
protected function commands(): void
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
30
app/Exceptions/Handler.php
Normal file
30
app/Exceptions/Handler.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* The list of the inputs that are never flashed to the session on validation exceptions.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $dontFlash = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register the exception handling callbacks for the application.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->reportable(function (Throwable $e) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
181
app/Http/Controllers/Admin/DashboardController.php
Normal file
181
app/Http/Controllers/Admin/DashboardController.php
Normal file
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function overview(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'date' => ['nullable', 'date'],
|
||||
'lokasi_kode' => ['nullable', 'string', 'max:20'],
|
||||
'low_stock_limit' => ['nullable', 'integer', 'min:1', 'max:200'],
|
||||
'low_stock_threshold' => ['nullable', 'integer', 'min:0', 'max:1000000'],
|
||||
]);
|
||||
|
||||
$date = $data['date'] ?? now()->toDateString();
|
||||
$start = $date . ' 00:00:00';
|
||||
$end = $date . ' 23:59:59';
|
||||
|
||||
$basePenjualan = DB::table('penjualan')->whereBetween('waktu', [$start, $end]);
|
||||
$pendapatan = (int) (clone $basePenjualan)->sum('total');
|
||||
$transaksi = (int) (clone $basePenjualan)->count();
|
||||
|
||||
$itemTerjual = (int) DB::table('penjualan_barang as pb')
|
||||
->join('penjualan as p', 'p.id', '=', 'pb.penjualan_id')
|
||||
->whereBetween('p.waktu', [$start, $end])
|
||||
->sum('pb.jumlah');
|
||||
|
||||
$margin = (int) DB::table('penjualan_barang as pb')
|
||||
->join('penjualan as p', 'p.id', '=', 'pb.penjualan_id')
|
||||
->leftJoin('produk as pr', 'pr.id', '=', 'pb.produk_id')
|
||||
->whereBetween('p.waktu', [$start, $end])
|
||||
->selectRaw('COALESCE(SUM((pb.harga - COALESCE(pr.harga_beli, 0)) * pb.jumlah),0) as margin')
|
||||
->value('margin');
|
||||
|
||||
$role = $request->user()?->role ?: 'admin';
|
||||
$marginValue = $role === 'admin' ? $margin : null;
|
||||
|
||||
$summary = [
|
||||
'pendapatan' => $pendapatan,
|
||||
'transaksi' => $transaksi,
|
||||
'item_terjual' => $itemTerjual,
|
||||
'margin' => $marginValue,
|
||||
];
|
||||
|
||||
$chartStart = Carbon::parse($date)->subDays(6)->toDateString();
|
||||
$chartRows = DB::table('penjualan')
|
||||
->selectRaw('DATE(waktu) as tanggal, SUM(total) as total')
|
||||
->whereBetween('waktu', [$chartStart . ' 00:00:00', $end])
|
||||
->groupBy('tanggal')
|
||||
->orderBy('tanggal')
|
||||
->get()
|
||||
->keyBy('tanggal');
|
||||
|
||||
$chart = [];
|
||||
for ($i = 6; $i >= 0; $i--) {
|
||||
$d = Carbon::parse($date)->subDays($i)->toDateString();
|
||||
$chart[] = [
|
||||
'tanggal' => $d,
|
||||
'total' => (int) ($chartRows->get($d)?->total ?? 0),
|
||||
];
|
||||
}
|
||||
|
||||
$topProducts = DB::table('penjualan_barang as pb')
|
||||
->join('penjualan as p', 'p.id', '=', 'pb.penjualan_id')
|
||||
->join('produk as pr', 'pr.id', '=', 'pb.produk_id')
|
||||
->whereBetween('p.waktu', [$start, $end])
|
||||
->selectRaw('pr.id, pr.nama, pr.barcode, SUM(pb.jumlah) as qty, SUM(pb.total) as total')
|
||||
->groupBy('pr.id', 'pr.nama', 'pr.barcode')
|
||||
->orderByDesc('qty')
|
||||
->limit(10)
|
||||
->get()
|
||||
->map(function ($r) {
|
||||
return [
|
||||
'id' => (int) $r->id,
|
||||
'nama' => $r->nama,
|
||||
'barcode' => $r->barcode,
|
||||
'qty' => (int) $r->qty,
|
||||
'total' => (int) $r->total,
|
||||
];
|
||||
});
|
||||
|
||||
$limit = (int) ($data['low_stock_limit'] ?? 10);
|
||||
$thresholdToko = (int) ($data['low_stock_threshold'] ?? $this->getSetting('stok.low_threshold_toko', 5));
|
||||
$thresholdGudang = (int) $this->getSetting('stok.low_threshold_gudang', 5);
|
||||
|
||||
$lowStockToko = $this->lowStockByKode('TOKO', $thresholdToko, $limit);
|
||||
$lowStockGudang = $this->lowStockByKode('GUDANG', $thresholdGudang, $limit);
|
||||
|
||||
$recent = DB::table('penjualan')
|
||||
->orderByDesc('waktu')
|
||||
->limit(10)
|
||||
->get()
|
||||
->map(function ($r) {
|
||||
return [
|
||||
'id' => (int) $r->id,
|
||||
'nomor_penjualan' => $r->nomor_penjualan,
|
||||
'waktu' => $r->waktu,
|
||||
'total' => (int) $r->total,
|
||||
'metode_pembayaran' => $r->metode_pembayaran,
|
||||
];
|
||||
});
|
||||
|
||||
$dataIssues = [
|
||||
'tanpa_barcode' => (int) DB::table('produk')
|
||||
->whereNull('barcode')
|
||||
->orWhere('barcode', '')
|
||||
->count(),
|
||||
'tanpa_harga_jual' => (int) DB::table('produk')
|
||||
->whereNull('harga_jual')
|
||||
->orWhere('harga_jual', 0)
|
||||
->count(),
|
||||
];
|
||||
|
||||
return response()->json([
|
||||
'date' => $date,
|
||||
'summary' => $summary,
|
||||
'chart_7d' => $chart,
|
||||
'top_products' => $topProducts,
|
||||
'low_stock_toko' => $lowStockToko,
|
||||
'low_stock_gudang' => $lowStockGudang,
|
||||
'recent' => $recent,
|
||||
'data_issues' => $dataIssues,
|
||||
]);
|
||||
}
|
||||
|
||||
private function getSetting(string $key, $default = null)
|
||||
{
|
||||
$value = DB::table('settings')->where('key', $key)->value('value');
|
||||
return $value === null ? $default : $value;
|
||||
}
|
||||
|
||||
private function lowStockByKode(string $kode, int $threshold, int $limit): array
|
||||
{
|
||||
$lokasi = DB::table('lokasi')->where('kode', $kode)->first();
|
||||
if (!$lokasi) {
|
||||
return [
|
||||
'lokasi' => null,
|
||||
'threshold' => $threshold,
|
||||
'data' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$lokasiId = (int) $lokasi->id;
|
||||
$rows = DB::table('produk')
|
||||
->select('produk.id', 'produk.nama', 'produk.barcode', 'produk.sku')
|
||||
->selectRaw(
|
||||
'COALESCE(SUM(CASE WHEN pergerakan_stok.ke_lokasi_id = ? THEN pergerakan_stok.jumlah ELSE 0 END),0) - ' .
|
||||
'COALESCE(SUM(CASE WHEN pergerakan_stok.dari_lokasi_id = ? THEN pergerakan_stok.jumlah ELSE 0 END),0) as stok',
|
||||
[$lokasiId, $lokasiId]
|
||||
)
|
||||
->leftJoin('pergerakan_stok', 'pergerakan_stok.produk_id', '=', 'produk.id')
|
||||
->groupBy('produk.id', 'produk.nama', 'produk.barcode', 'produk.sku')
|
||||
->having('stok', '<=', $threshold)
|
||||
->orderBy('stok')
|
||||
->limit($limit)
|
||||
->get()
|
||||
->map(function ($r) {
|
||||
return [
|
||||
'id' => (int) $r->id,
|
||||
'nama' => $r->nama,
|
||||
'barcode' => $r->barcode,
|
||||
'sku' => $r->sku,
|
||||
'stok' => (int) $r->stok,
|
||||
];
|
||||
})
|
||||
->all();
|
||||
|
||||
return [
|
||||
'lokasi' => ['id' => (int) $lokasi->id, 'kode' => $lokasi->kode, 'nama' => $lokasi->nama],
|
||||
'threshold' => $threshold,
|
||||
'data' => $rows,
|
||||
];
|
||||
}
|
||||
}
|
||||
239
app/Http/Controllers/Admin/DistributorController.php
Normal file
239
app/Http/Controllers/Admin/DistributorController.php
Normal file
@@ -0,0 +1,239 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Distributor;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DistributorController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$q = trim((string) $request->query('q', ''));
|
||||
|
||||
$query = Distributor::query()->orderByDesc('id');
|
||||
if ($q !== '') {
|
||||
$query->where(function ($qq) use ($q) {
|
||||
$qq->where('nama', 'like', "%{$q}%")
|
||||
->orWhere('alamat', 'like', "%{$q}%")
|
||||
->orWhere('telepon', 'like', "%{$q}%");
|
||||
});
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'data' => $query->get([
|
||||
'id',
|
||||
'nama',
|
||||
'alamat',
|
||||
'telepon',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'nama' => ['required', 'string', 'max:150'],
|
||||
'alamat' => ['nullable', 'string', 'max:255'],
|
||||
'telepon' => ['nullable', 'string', 'max:50'],
|
||||
]);
|
||||
|
||||
$row = Distributor::create([
|
||||
'nama' => $data['nama'],
|
||||
'alamat' => $data['alamat'] ?? null,
|
||||
'telepon' => $data['telepon'] ?? null,
|
||||
]);
|
||||
|
||||
return response()->json(['data' => $row], 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, Distributor $distributor): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'nama' => ['required', 'string', 'max:150'],
|
||||
'alamat' => ['nullable', 'string', 'max:255'],
|
||||
'telepon' => ['nullable', 'string', 'max:50'],
|
||||
]);
|
||||
|
||||
$distributor->update([
|
||||
'nama' => $data['nama'],
|
||||
'alamat' => $data['alamat'] ?? null,
|
||||
'telepon' => $data['telepon'] ?? null,
|
||||
]);
|
||||
|
||||
return response()->json(['data' => $distributor->fresh()]);
|
||||
}
|
||||
|
||||
public function destroy(Distributor $distributor): JsonResponse
|
||||
{
|
||||
$distributor->delete();
|
||||
return response()->json(['message' => 'Distributor dihapus.']);
|
||||
}
|
||||
|
||||
public function import(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'file' => ['required', 'file', 'mimes:xlsx,xls,csv,txt', 'max:5120'],
|
||||
]);
|
||||
|
||||
$file = $data['file'];
|
||||
$ext = strtolower($file->getClientOriginalExtension());
|
||||
|
||||
if (in_array($ext, ['xlsx', 'xls'], true)) {
|
||||
if (!class_exists(\PhpOffice\PhpSpreadsheet\IOFactory::class)) {
|
||||
return response()->json([
|
||||
'message' => 'Import XLSX membutuhkan paket phpoffice/phpspreadsheet.',
|
||||
], 422);
|
||||
}
|
||||
$rows = $this->readXlsx($file->getRealPath());
|
||||
} else {
|
||||
$rows = $this->readCsv($file->getRealPath());
|
||||
}
|
||||
|
||||
if (count($rows) === 0) {
|
||||
return response()->json(['message' => 'File kosong atau format tidak valid.'], 422);
|
||||
}
|
||||
|
||||
$inserted = 0;
|
||||
$skipped = 0;
|
||||
|
||||
DB::transaction(function () use ($rows, &$inserted, &$skipped) {
|
||||
foreach ($rows as $row) {
|
||||
$nama = trim((string) ($row['nama'] ?? ''));
|
||||
if ($nama === '') {
|
||||
$skipped++;
|
||||
continue;
|
||||
}
|
||||
Distributor::create([
|
||||
'nama' => $nama,
|
||||
'alamat' => isset($row['alamat']) && $row['alamat'] !== '' ? $row['alamat'] : null,
|
||||
'telepon' => isset($row['telepon']) && $row['telepon'] !== '' ? $row['telepon'] : null,
|
||||
]);
|
||||
$inserted++;
|
||||
}
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'message' => "Import selesai. Berhasil: {$inserted}, Dilewati: {$skipped}.",
|
||||
'data' => [
|
||||
'inserted' => $inserted,
|
||||
'skipped' => $skipped,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function template(): \Symfony\Component\HttpFoundation\StreamedResponse
|
||||
{
|
||||
$headers = [
|
||||
'Content-Type' => 'text/csv',
|
||||
'Content-Disposition' => 'attachment; filename="template_distributor.csv"',
|
||||
];
|
||||
|
||||
$callback = function () {
|
||||
$handle = fopen('php://output', 'w');
|
||||
fputcsv($handle, ['nama', 'alamat', 'telepon']);
|
||||
fputcsv($handle, ['PT Contoh Distributor', 'Jl. Contoh No. 1', '08123456789']);
|
||||
fclose($handle);
|
||||
};
|
||||
|
||||
return response()->stream($callback, 200, $headers);
|
||||
}
|
||||
|
||||
private function readCsv(string $path): array
|
||||
{
|
||||
$rows = [];
|
||||
$handle = fopen($path, 'r');
|
||||
if (!$handle) {
|
||||
return $rows;
|
||||
}
|
||||
|
||||
$header = null;
|
||||
while (($data = fgetcsv($handle, 0, ',')) !== false) {
|
||||
if ($data === [null] || $data === false) {
|
||||
continue;
|
||||
}
|
||||
if ($header === null) {
|
||||
$header = $this->normalizeHeader($data);
|
||||
if ($this->isHeaderRow($header)) {
|
||||
continue;
|
||||
}
|
||||
$rows[] = $this->mapRowByIndex($data);
|
||||
continue;
|
||||
}
|
||||
$rows[] = $this->mapRowByHeader($data, $header);
|
||||
}
|
||||
fclose($handle);
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
private function readXlsx(string $path): array
|
||||
{
|
||||
$rows = [];
|
||||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($path);
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$data = $sheet->toArray(null, true, true, true);
|
||||
if (count($data) === 0) {
|
||||
return $rows;
|
||||
}
|
||||
|
||||
$first = array_shift($data);
|
||||
$header = $this->normalizeHeader(array_values($first ?? []));
|
||||
$hasHeader = $this->isHeaderRow($header);
|
||||
if (!$hasHeader && $first) {
|
||||
$rows[] = $this->mapRowByIndex(array_values($first));
|
||||
}
|
||||
|
||||
foreach ($data as $row) {
|
||||
$values = array_values($row);
|
||||
$rows[] = $hasHeader
|
||||
? $this->mapRowByHeader($values, $header)
|
||||
: $this->mapRowByIndex($values);
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
private function normalizeHeader(array $row): array
|
||||
{
|
||||
return array_map(function ($v) {
|
||||
$v = strtolower(trim((string) $v));
|
||||
return preg_replace('/\s+/', '_', $v);
|
||||
}, $row);
|
||||
}
|
||||
|
||||
private function isHeaderRow(array $header): bool
|
||||
{
|
||||
$fields = ['nama', 'alamat', 'telepon'];
|
||||
foreach ($fields as $f) {
|
||||
if (in_array($f, $header, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function mapRowByHeader(array $row, array $header): array
|
||||
{
|
||||
$map = array_flip($header);
|
||||
return [
|
||||
'nama' => trim((string) ($row[$map['nama']] ?? '')),
|
||||
'alamat' => trim((string) ($row[$map['alamat']] ?? '')),
|
||||
'telepon' => trim((string) ($row[$map['telepon']] ?? '')),
|
||||
];
|
||||
}
|
||||
|
||||
private function mapRowByIndex(array $row): array
|
||||
{
|
||||
return [
|
||||
'nama' => trim((string) ($row[0] ?? '')),
|
||||
'alamat' => trim((string) ($row[1] ?? '')),
|
||||
'telepon' => trim((string) ($row[2] ?? '')),
|
||||
];
|
||||
}
|
||||
}
|
||||
242
app/Http/Controllers/Admin/LaporanController.php
Normal file
242
app/Http/Controllers/Admin/LaporanController.php
Normal file
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class LaporanController extends Controller
|
||||
{
|
||||
public function harian(Request $request): JsonResponse
|
||||
{
|
||||
[$from, $to, $rows, $summary] = $this->buildHarian($request);
|
||||
|
||||
return response()->json([
|
||||
'from' => $from,
|
||||
'to' => $to,
|
||||
'summary' => $summary,
|
||||
'data' => $rows,
|
||||
]);
|
||||
}
|
||||
|
||||
public function bulanan(Request $request): JsonResponse
|
||||
{
|
||||
[$year, $rows, $summary] = $this->buildBulanan($request);
|
||||
|
||||
return response()->json([
|
||||
'year' => $year,
|
||||
'summary' => $summary,
|
||||
'data' => $rows,
|
||||
]);
|
||||
}
|
||||
|
||||
public function exportHarian(Request $request)
|
||||
{
|
||||
[$from, $to] = $this->resolveHarianRange($request);
|
||||
$rows = $this->buildDetailByRange($from, $to);
|
||||
|
||||
$filename = "laporan-harian-detail-{$from}-{$to}.xls";
|
||||
|
||||
return $this->downloadXls($filename, $rows);
|
||||
}
|
||||
|
||||
public function exportBulanan(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'year' => ['nullable', 'integer', 'min:2000', 'max:2100'],
|
||||
]);
|
||||
$year = (int) ($data['year'] ?? now()->year);
|
||||
$from = "{$year}-01-01";
|
||||
$to = "{$year}-12-31";
|
||||
$rows = $this->buildDetailByRange($from, $to);
|
||||
|
||||
$filename = "laporan-bulanan-detail-{$year}.xls";
|
||||
|
||||
return $this->downloadXls($filename, $rows);
|
||||
}
|
||||
|
||||
private function buildHarian(Request $request): array
|
||||
{
|
||||
[$from, $to] = $this->resolveHarianRange($request);
|
||||
|
||||
$penjualan = DB::table('penjualan')
|
||||
->selectRaw('DATE(waktu) as tanggal, COUNT(*) as transaksi, SUM(total) as pendapatan')
|
||||
->whereBetween('waktu', [$from . ' 00:00:00', $to . ' 23:59:59'])
|
||||
->groupBy('tanggal')
|
||||
->orderBy('tanggal', 'desc')
|
||||
->get();
|
||||
|
||||
$itemsByDay = DB::table('penjualan_barang as pb')
|
||||
->join('penjualan as p', 'p.id', '=', 'pb.penjualan_id')
|
||||
->selectRaw('DATE(p.waktu) as tanggal, SUM(pb.jumlah) as item_terjual')
|
||||
->whereBetween('p.waktu', [$from . ' 00:00:00', $to . ' 23:59:59'])
|
||||
->groupBy('tanggal')
|
||||
->get()
|
||||
->keyBy('tanggal');
|
||||
|
||||
$rows = $penjualan->map(function ($r) use ($itemsByDay) {
|
||||
$items = $itemsByDay->get($r->tanggal);
|
||||
return [
|
||||
'tanggal' => $r->tanggal,
|
||||
'transaksi' => (int) $r->transaksi,
|
||||
'pendapatan' => (int) ($r->pendapatan ?? 0),
|
||||
'item_terjual' => (int) ($items?->item_terjual ?? 0),
|
||||
];
|
||||
});
|
||||
|
||||
$summary = [
|
||||
'pendapatan' => (int) $rows->sum('pendapatan'),
|
||||
'transaksi' => (int) $rows->sum('transaksi'),
|
||||
'item_terjual' => (int) $rows->sum('item_terjual'),
|
||||
];
|
||||
|
||||
return [$from, $to, $rows, $summary];
|
||||
}
|
||||
|
||||
private function buildBulanan(Request $request): array
|
||||
{
|
||||
$data = $request->validate([
|
||||
'year' => ['nullable', 'integer', 'min:2000', 'max:2100'],
|
||||
]);
|
||||
|
||||
$year = (int) ($data['year'] ?? now()->year);
|
||||
|
||||
$penjualan = DB::table('penjualan')
|
||||
->selectRaw("DATE_FORMAT(waktu, '%Y-%m') as bulan, COUNT(*) as transaksi, SUM(total) as pendapatan")
|
||||
->whereYear('waktu', $year)
|
||||
->groupBy('bulan')
|
||||
->orderBy('bulan', 'desc')
|
||||
->get();
|
||||
|
||||
$itemsByMonth = DB::table('penjualan_barang as pb')
|
||||
->join('penjualan as p', 'p.id', '=', 'pb.penjualan_id')
|
||||
->selectRaw("DATE_FORMAT(p.waktu, '%Y-%m') as bulan, SUM(pb.jumlah) as item_terjual")
|
||||
->whereYear('p.waktu', $year)
|
||||
->groupBy('bulan')
|
||||
->get()
|
||||
->keyBy('bulan');
|
||||
|
||||
$rows = $penjualan->map(function ($r) use ($itemsByMonth) {
|
||||
$items = $itemsByMonth->get($r->bulan);
|
||||
return [
|
||||
'bulan' => $r->bulan,
|
||||
'transaksi' => (int) $r->transaksi,
|
||||
'pendapatan' => (int) ($r->pendapatan ?? 0),
|
||||
'item_terjual' => (int) ($items?->item_terjual ?? 0),
|
||||
];
|
||||
});
|
||||
|
||||
$summary = [
|
||||
'pendapatan' => (int) $rows->sum('pendapatan'),
|
||||
'transaksi' => (int) $rows->sum('transaksi'),
|
||||
'item_terjual' => (int) $rows->sum('item_terjual'),
|
||||
];
|
||||
|
||||
return [$year, $rows, $summary];
|
||||
}
|
||||
|
||||
private function resolveHarianRange(Request $request): array
|
||||
{
|
||||
$data = $request->validate([
|
||||
'from' => ['nullable', 'date'],
|
||||
'to' => ['nullable', 'date'],
|
||||
]);
|
||||
$from = $data['from'] ?? now()->subDays(14)->toDateString();
|
||||
$to = $data['to'] ?? now()->toDateString();
|
||||
return [$from, $to];
|
||||
}
|
||||
|
||||
private function buildDetailByRange(string $from, string $to): array
|
||||
{
|
||||
$rows = DB::table('penjualan as p')
|
||||
->join('penjualan_barang as pb', 'pb.penjualan_id', '=', 'p.id')
|
||||
->leftJoin('produk as pr', 'pr.id', '=', 'pb.produk_id')
|
||||
->leftJoin('users as u', 'u.id', '=', 'p.user_id')
|
||||
->selectRaw('p.waktu, p.nomor_penjualan, u.name as kasir, pr.nama as item, pr.barcode, pb.jumlah as qty, pb.harga, pb.total as total_item, p.subtotal, p.diskon, p.pajak, p.total, p.metode_pembayaran, p.jumlah_bayar, p.kembalian')
|
||||
->whereBetween('p.waktu', [$from . ' 00:00:00', $to . ' 23:59:59'])
|
||||
->orderByDesc('p.waktu')
|
||||
->get();
|
||||
|
||||
return $rows->map(function ($r) {
|
||||
$dt = new \DateTime($r->waktu);
|
||||
return [
|
||||
'tanggal' => $dt->format('Y-m-d'),
|
||||
'jam' => $dt->format('H:i:s'),
|
||||
'nomor_penjualan' => $r->nomor_penjualan,
|
||||
'kasir' => $r->kasir ?? '-',
|
||||
'item' => $r->item ?? '-',
|
||||
'barcode' => $r->barcode ?? '-',
|
||||
'qty' => (int) $r->qty,
|
||||
'harga' => (int) $r->harga,
|
||||
'total_item' => (int) $r->total_item,
|
||||
'subtotal' => (int) $r->subtotal,
|
||||
'diskon' => (int) $r->diskon,
|
||||
'pajak' => (int) $r->pajak,
|
||||
'total' => (int) $r->total,
|
||||
'metode' => $r->metode_pembayaran,
|
||||
'bayar' => (int) $r->jumlah_bayar,
|
||||
'kembalian' => (int) $r->kembalian,
|
||||
];
|
||||
})->all();
|
||||
}
|
||||
|
||||
private function downloadXls(string $filename, array $rows)
|
||||
{
|
||||
$headers = [
|
||||
'Tanggal',
|
||||
'Jam',
|
||||
'No Transaksi',
|
||||
'Kasir',
|
||||
'Item',
|
||||
'Barcode',
|
||||
'Qty',
|
||||
'Harga',
|
||||
'Total Item',
|
||||
'Subtotal',
|
||||
'Diskon',
|
||||
'Pajak',
|
||||
'Total',
|
||||
'Metode',
|
||||
'Bayar',
|
||||
'Kembalian',
|
||||
];
|
||||
|
||||
return response()->streamDownload(function () use ($headers, $rows) {
|
||||
$escape = fn ($v) => htmlspecialchars((string) $v, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||
|
||||
echo "\xEF\xBB\xBF";
|
||||
echo "<table border='1'>\n<thead><tr>";
|
||||
foreach ($headers as $h) {
|
||||
echo "<th>{$escape($h)}</th>";
|
||||
}
|
||||
echo "</tr></thead>\n<tbody>";
|
||||
|
||||
foreach ($rows as $r) {
|
||||
echo "<tr>";
|
||||
echo "<td>{$escape($r['tanggal'])}</td>";
|
||||
echo "<td>{$escape($r['jam'])}</td>";
|
||||
echo "<td>{$escape($r['nomor_penjualan'])}</td>";
|
||||
echo "<td>{$escape($r['kasir'])}</td>";
|
||||
echo "<td>{$escape($r['item'])}</td>";
|
||||
echo "<td>{$escape($r['barcode'])}</td>";
|
||||
echo "<td>{$escape($r['qty'])}</td>";
|
||||
echo "<td>{$escape($r['harga'])}</td>";
|
||||
echo "<td>{$escape($r['total_item'])}</td>";
|
||||
echo "<td>{$escape($r['subtotal'])}</td>";
|
||||
echo "<td>{$escape($r['diskon'])}</td>";
|
||||
echo "<td>{$escape($r['pajak'])}</td>";
|
||||
echo "<td>{$escape($r['total'])}</td>";
|
||||
echo "<td>{$escape($r['metode'])}</td>";
|
||||
echo "<td>{$escape($r['bayar'])}</td>";
|
||||
echo "<td>{$escape($r['kembalian'])}</td>";
|
||||
echo "</tr>\n";
|
||||
}
|
||||
|
||||
echo "</tbody></table>";
|
||||
}, $filename, [
|
||||
'Content-Type' => 'application/vnd.ms-excel; charset=UTF-8',
|
||||
]);
|
||||
}
|
||||
}
|
||||
17
app/Http/Controllers/Admin/LokasiController.php
Normal file
17
app/Http/Controllers/Admin/LokasiController.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Lokasi;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class LokasiController extends Controller
|
||||
{
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'data' => Lokasi::query()->orderBy('id')->get(['id', 'kode', 'nama']),
|
||||
]);
|
||||
}
|
||||
}
|
||||
55
app/Http/Controllers/Admin/MeController.php
Normal file
55
app/Http/Controllers/Admin/MeController.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class MeController extends Controller
|
||||
{
|
||||
public function show(Request $request): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'data' => [
|
||||
'id' => $request->user()?->id,
|
||||
'name' => $request->user()?->name,
|
||||
'email' => $request->user()?->email,
|
||||
'role' => $request->user()?->role,
|
||||
'nip' => $request->user()?->nip,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
$data = $request->validate([
|
||||
'name' => ['required', 'string', 'max:100'],
|
||||
'email' => ['required', 'string', 'email', 'max:255', Rule::unique('users', 'email')->ignore($user?->id)],
|
||||
]);
|
||||
|
||||
$user->update($data);
|
||||
|
||||
return response()->json(['message' => 'Profil berhasil diperbarui.']);
|
||||
}
|
||||
|
||||
public function updatePassword(Request $request): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
$data = $request->validate([
|
||||
'current_password' => ['required', 'current_password'],
|
||||
'password' => ['required', 'string', 'min:6', 'confirmed'],
|
||||
]);
|
||||
|
||||
$user->update([
|
||||
'password' => Hash::make($data['password']),
|
||||
]);
|
||||
|
||||
return response()->json(['message' => 'Password berhasil diperbarui.']);
|
||||
}
|
||||
}
|
||||
136
app/Http/Controllers/Admin/PegawaiController.php
Normal file
136
app/Http/Controllers/Admin/PegawaiController.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Pegawai;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class PegawaiController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$q = trim((string) $request->query('q', ''));
|
||||
|
||||
$query = Pegawai::query()->orderByDesc('id');
|
||||
if ($q !== '') {
|
||||
$query->where(function ($qq) use ($q) {
|
||||
$qq->where('nama', 'like', "%{$q}%")
|
||||
->orWhere('nip', 'like', "%{$q}%")
|
||||
->orWhere('nik', 'like', "%{$q}%")
|
||||
->orWhere('jabatan', 'like', "%{$q}%")
|
||||
->orWhere('telepon', 'like', "%{$q}%");
|
||||
});
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'data' => $query->get([
|
||||
'id',
|
||||
'nip',
|
||||
'nama',
|
||||
'jabatan',
|
||||
'telepon',
|
||||
'alamat',
|
||||
'tempat_lahir',
|
||||
'tanggal_lahir',
|
||||
'jenis_kelamin',
|
||||
'kota',
|
||||
'nik',
|
||||
'foto',
|
||||
'is_aktif',
|
||||
'created_at',
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'nip' => ['nullable', 'string', 'max:30', Rule::unique('pegawai', 'nip')],
|
||||
'nama' => ['required', 'string', 'max:100'],
|
||||
'jabatan' => ['nullable', 'string', 'max:100'],
|
||||
'telepon' => ['nullable', 'string', 'max:30'],
|
||||
'alamat' => ['nullable', 'string', 'max:255'],
|
||||
'tempat_lahir' => ['nullable', 'string', 'max:100'],
|
||||
'tanggal_lahir' => ['nullable', 'date'],
|
||||
'jenis_kelamin' => ['nullable', 'string', 'max:10'],
|
||||
'kota' => ['nullable', 'string', 'max:100'],
|
||||
'nik' => ['nullable', 'string', 'max:30', Rule::unique('pegawai', 'nik')],
|
||||
'foto' => ['nullable', 'string', 'max:255'],
|
||||
'is_aktif' => ['nullable', 'boolean'],
|
||||
]);
|
||||
|
||||
$pegawai = Pegawai::create([
|
||||
'nip' => $data['nip'] ?? null,
|
||||
'nama' => $data['nama'],
|
||||
'jabatan' => $data['jabatan'] ?? null,
|
||||
'telepon' => $data['telepon'] ?? null,
|
||||
'alamat' => $data['alamat'] ?? null,
|
||||
'tempat_lahir' => $data['tempat_lahir'] ?? null,
|
||||
'tanggal_lahir' => $data['tanggal_lahir'] ?? null,
|
||||
'jenis_kelamin' => $data['jenis_kelamin'] ?? null,
|
||||
'kota' => $data['kota'] ?? null,
|
||||
'nik' => $data['nik'] ?? null,
|
||||
'foto' => $data['foto'] ?? null,
|
||||
'is_aktif' => (bool) ($data['is_aktif'] ?? true),
|
||||
]);
|
||||
|
||||
return response()->json(['data' => $pegawai], 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, Pegawai $pegawai): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'nip' => ['nullable', 'string', 'max:30', Rule::unique('pegawai', 'nip')->ignore($pegawai->id)],
|
||||
'nama' => ['required', 'string', 'max:100'],
|
||||
'jabatan' => ['nullable', 'string', 'max:100'],
|
||||
'telepon' => ['nullable', 'string', 'max:30'],
|
||||
'alamat' => ['nullable', 'string', 'max:255'],
|
||||
'tempat_lahir' => ['nullable', 'string', 'max:100'],
|
||||
'tanggal_lahir' => ['nullable', 'date'],
|
||||
'jenis_kelamin' => ['nullable', 'string', 'max:10'],
|
||||
'kota' => ['nullable', 'string', 'max:100'],
|
||||
'nik' => ['nullable', 'string', 'max:30', Rule::unique('pegawai', 'nik')->ignore($pegawai->id)],
|
||||
'foto' => ['nullable', 'string', 'max:255'],
|
||||
'is_aktif' => ['nullable', 'boolean'],
|
||||
]);
|
||||
|
||||
$pegawai->update([
|
||||
'nip' => $data['nip'] ?? null,
|
||||
'nama' => $data['nama'],
|
||||
'jabatan' => $data['jabatan'] ?? null,
|
||||
'telepon' => $data['telepon'] ?? null,
|
||||
'alamat' => $data['alamat'] ?? null,
|
||||
'tempat_lahir' => $data['tempat_lahir'] ?? null,
|
||||
'tanggal_lahir' => $data['tanggal_lahir'] ?? null,
|
||||
'jenis_kelamin' => $data['jenis_kelamin'] ?? null,
|
||||
'kota' => $data['kota'] ?? null,
|
||||
'nik' => $data['nik'] ?? null,
|
||||
'foto' => $data['foto'] ?? null,
|
||||
'is_aktif' => (bool) ($data['is_aktif'] ?? true),
|
||||
]);
|
||||
|
||||
return response()->json(['data' => $pegawai->fresh()]);
|
||||
}
|
||||
|
||||
public function destroy(Pegawai $pegawai): JsonResponse
|
||||
{
|
||||
$pegawai->delete();
|
||||
return response()->json(['message' => 'Pegawai dihapus.']);
|
||||
}
|
||||
|
||||
public function uploadFoto(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'foto' => ['required', 'image', 'max:2048'],
|
||||
]);
|
||||
|
||||
$path = $data['foto']->store('pegawai', 'public');
|
||||
$url = Storage::url($path);
|
||||
|
||||
return response()->json(['data' => ['foto' => $url]]);
|
||||
}
|
||||
}
|
||||
296
app/Http/Controllers/Admin/PenerimaanBarangController.php
Normal file
296
app/Http/Controllers/Admin/PenerimaanBarangController.php
Normal file
@@ -0,0 +1,296 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Distributor;
|
||||
use App\Models\Lokasi;
|
||||
use App\Models\PenerimaanBarang;
|
||||
use App\Models\PenerimaanBarangItem;
|
||||
use App\Models\PergerakanStok;
|
||||
use App\Models\ProductUnit;
|
||||
use App\Models\Produk;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PenerimaanBarangController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'from' => ['nullable', 'date'],
|
||||
'to' => ['nullable', 'date'],
|
||||
'q' => ['nullable', 'string', 'max:100'],
|
||||
'limit' => ['nullable', 'integer', 'min:1', 'max:200'],
|
||||
]);
|
||||
|
||||
$limit = (int) ($data['limit'] ?? 50);
|
||||
|
||||
$query = PenerimaanBarang::query()
|
||||
->with(['distributor:id,nama', 'lokasi:id,nama,kode'])
|
||||
->withCount('items')
|
||||
->orderByDesc('id');
|
||||
|
||||
if (!empty($data['from'])) {
|
||||
$query->where('tanggal_datang', '>=', $data['from']);
|
||||
}
|
||||
if (!empty($data['to'])) {
|
||||
$query->where('tanggal_datang', '<=', $data['to']);
|
||||
}
|
||||
if (!empty($data['q'])) {
|
||||
$s = trim((string) $data['q']);
|
||||
$query->where(function ($qq) use ($s) {
|
||||
$qq->where('nomor_penerimaan', 'like', "%{$s}%")
|
||||
->orWhere('no_faktur', 'like', "%{$s}%");
|
||||
});
|
||||
}
|
||||
|
||||
$rows = $query->limit($limit)->get()->map(function (PenerimaanBarang $p) {
|
||||
return [
|
||||
'id' => $p->id,
|
||||
'nomor_penerimaan' => $p->nomor_penerimaan,
|
||||
'no_faktur' => $p->no_faktur,
|
||||
'tanggal_faktur' => $p->tanggal_faktur,
|
||||
'tanggal_datang' => $p->tanggal_datang,
|
||||
'status' => $p->status,
|
||||
'items_count' => (int) ($p->items_count ?? 0),
|
||||
'distributor' => $p->distributor?->nama,
|
||||
'lokasi' => $p->lokasi ? ($p->lokasi->nama . ' (' . $p->lokasi->kode . ')') : null,
|
||||
'created_at' => $p->created_at,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json(['data' => $rows]);
|
||||
}
|
||||
|
||||
public function show(PenerimaanBarang $penerimaan): JsonResponse
|
||||
{
|
||||
$penerimaan->load([
|
||||
'items.produk:id,nama,barcode,sku',
|
||||
'distributor:id,nama',
|
||||
'lokasi:id,nama,kode',
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'data' => [
|
||||
'id' => $penerimaan->id,
|
||||
'nomor_penerimaan' => $penerimaan->nomor_penerimaan,
|
||||
'no_faktur' => $penerimaan->no_faktur,
|
||||
'tanggal_faktur' => $penerimaan->tanggal_faktur,
|
||||
'tanggal_datang' => $penerimaan->tanggal_datang,
|
||||
'distributor_id' => $penerimaan->distributor_id,
|
||||
'lokasi_id' => $penerimaan->lokasi_id,
|
||||
'status' => $penerimaan->status,
|
||||
'catatan' => $penerimaan->catatan,
|
||||
'applied_at' => $penerimaan->applied_at,
|
||||
'items' => $penerimaan->items->map(function (PenerimaanBarangItem $i) {
|
||||
return [
|
||||
'id' => $i->id,
|
||||
'produk_id' => $i->produk_id,
|
||||
'produk_nama' => $i->produk?->nama,
|
||||
'produk_barcode' => $i->produk?->barcode,
|
||||
'produk_sku' => $i->produk?->sku,
|
||||
'unit_id' => $i->unit_id,
|
||||
'qty' => (int) $i->qty,
|
||||
'qty_input' => (int) ($i->qty_input ?? $i->qty),
|
||||
'harga' => $i->harga !== null ? (int) $i->harga : null,
|
||||
'unit' => $i->unit,
|
||||
'multiplier' => (int) ($i->multiplier ?? 1),
|
||||
];
|
||||
}),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$payload = $this->validatePayload($request);
|
||||
|
||||
$penerimaan = DB::transaction(function () use ($payload, $request) {
|
||||
$nomor = $this->generateNomor();
|
||||
$row = PenerimaanBarang::create([
|
||||
'nomor_penerimaan' => $nomor,
|
||||
'no_faktur' => $payload['no_faktur'] ?? null,
|
||||
'tanggal_faktur' => $payload['tanggal_faktur'] ?? null,
|
||||
'tanggal_datang' => $payload['tanggal_datang'] ?? null,
|
||||
'distributor_id' => (int) $payload['distributor_id'],
|
||||
'lokasi_id' => (int) $payload['lokasi_id'],
|
||||
'user_id' => $request->user()?->id,
|
||||
'status' => $payload['status'],
|
||||
'catatan' => $payload['catatan'] ?? null,
|
||||
]);
|
||||
|
||||
$this->syncItems($row, $payload['items']);
|
||||
|
||||
if (in_array($payload['status'], ['SELESAI', 'SEBAGIAN'], true)) {
|
||||
$this->applyStock($row);
|
||||
}
|
||||
|
||||
return $row->fresh();
|
||||
});
|
||||
|
||||
return response()->json(['data' => $penerimaan], 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, PenerimaanBarang $penerimaan): JsonResponse
|
||||
{
|
||||
$payload = $this->validatePayload($request);
|
||||
|
||||
if ($penerimaan->applied_at) {
|
||||
if (in_array($payload['status'], ['DRAFT', 'BATAL'], true)) {
|
||||
return response()->json([
|
||||
'message' => 'Penerimaan sudah diproses, tidak bisa dibatalkan.',
|
||||
], 422);
|
||||
}
|
||||
return response()->json([
|
||||
'message' => 'Penerimaan sudah diproses, tidak bisa diubah.',
|
||||
], 422);
|
||||
}
|
||||
|
||||
$updated = DB::transaction(function () use ($penerimaan, $payload) {
|
||||
$penerimaan->update([
|
||||
'no_faktur' => $payload['no_faktur'] ?? null,
|
||||
'tanggal_faktur' => $payload['tanggal_faktur'] ?? null,
|
||||
'tanggal_datang' => $payload['tanggal_datang'] ?? null,
|
||||
'distributor_id' => (int) $payload['distributor_id'],
|
||||
'lokasi_id' => (int) $payload['lokasi_id'],
|
||||
'status' => $payload['status'],
|
||||
'catatan' => $payload['catatan'] ?? null,
|
||||
]);
|
||||
|
||||
$this->syncItems($penerimaan, $payload['items']);
|
||||
|
||||
if (in_array($payload['status'], ['SELESAI', 'SEBAGIAN'], true)) {
|
||||
$this->applyStock($penerimaan);
|
||||
}
|
||||
|
||||
return $penerimaan->fresh();
|
||||
});
|
||||
|
||||
return response()->json(['data' => $updated]);
|
||||
}
|
||||
|
||||
private function validatePayload(Request $request): array
|
||||
{
|
||||
return $request->validate([
|
||||
'no_faktur' => ['nullable', 'string', 'max:100'],
|
||||
'tanggal_faktur' => ['nullable', 'date'],
|
||||
'tanggal_datang' => ['nullable', 'date'],
|
||||
'distributor_id' => ['required', 'integer', 'exists:distributors,id'],
|
||||
'lokasi_id' => ['required', 'integer', 'exists:lokasi,id'],
|
||||
'status' => ['required', 'string', 'max:20'],
|
||||
'catatan' => ['nullable', 'string', 'max:255'],
|
||||
'items' => ['required', 'array', 'min:1'],
|
||||
'items.*.produk_id' => ['required', 'integer', 'exists:produk,id'],
|
||||
'items.*.qty' => ['required', 'integer', 'min:1'],
|
||||
'items.*.harga' => ['nullable', 'integer', 'min:0'],
|
||||
'items.*.unit_id' => ['nullable', 'integer', 'exists:produk_unit,id'],
|
||||
]);
|
||||
}
|
||||
|
||||
private function syncItems(PenerimaanBarang $penerimaan, array $items): void
|
||||
{
|
||||
PenerimaanBarangItem::query()
|
||||
->where('penerimaan_id', $penerimaan->id)
|
||||
->delete();
|
||||
|
||||
$produkIds = collect($items)->pluck('produk_id')->unique()->values();
|
||||
$baseUnits = ProductUnit::query()
|
||||
->whereIn('produk_id', $produkIds)
|
||||
->where('is_base', true)
|
||||
->get()
|
||||
->keyBy('produk_id');
|
||||
|
||||
$unitIds = collect($items)
|
||||
->pluck('unit_id')
|
||||
->filter()
|
||||
->unique()
|
||||
->values();
|
||||
$unitMap = $unitIds->isEmpty()
|
||||
? collect()
|
||||
: ProductUnit::query()->whereIn('id', $unitIds)->get()->keyBy('id');
|
||||
|
||||
$rows = [];
|
||||
foreach ($items as $item) {
|
||||
$unit = null;
|
||||
if (!empty($item['unit_id']) && $unitMap->has((int) $item['unit_id'])) {
|
||||
$unit = $unitMap->get((int) $item['unit_id']);
|
||||
}
|
||||
if (!$unit || (int) $unit->produk_id !== (int) $item['produk_id']) {
|
||||
$unit = $baseUnits->get((int) $item['produk_id']);
|
||||
}
|
||||
$multiplier = (int) ($unit?->multiplier ?? 1);
|
||||
$qtyInput = (int) $item['qty'];
|
||||
$qtyPcs = max(1, $qtyInput * $multiplier);
|
||||
$rows[] = [
|
||||
'penerimaan_id' => $penerimaan->id,
|
||||
'produk_id' => (int) $item['produk_id'],
|
||||
'unit_id' => $unit?->id,
|
||||
'qty' => $qtyPcs,
|
||||
'harga' => isset($item['harga']) ? (int) $item['harga'] : null,
|
||||
'unit' => $unit?->nama_unit ?? 'PCS',
|
||||
'qty_input' => $qtyInput,
|
||||
'multiplier' => $multiplier,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
];
|
||||
}
|
||||
|
||||
PenerimaanBarangItem::insert($rows);
|
||||
}
|
||||
|
||||
private function applyStock(PenerimaanBarang $penerimaan): void
|
||||
{
|
||||
if ($penerimaan->applied_at) return;
|
||||
|
||||
$items = PenerimaanBarangItem::query()
|
||||
->where('penerimaan_id', $penerimaan->id)
|
||||
->get();
|
||||
|
||||
$produkIds = $items->pluck('produk_id')->unique()->values();
|
||||
$baseUnits = ProductUnit::query()
|
||||
->whereIn('produk_id', $produkIds)
|
||||
->where('is_base', true)
|
||||
->get()
|
||||
->keyBy('produk_id');
|
||||
|
||||
$rows = [];
|
||||
foreach ($items as $item) {
|
||||
$unit = $baseUnits->get($item->produk_id);
|
||||
$unitName = $unit?->nama_unit ?? 'PCS';
|
||||
$multiplier = (int) ($unit?->multiplier ?? 1);
|
||||
$rows[] = [
|
||||
'waktu' => now(),
|
||||
'produk_id' => $item->produk_id,
|
||||
'dari_lokasi_id' => null,
|
||||
'ke_lokasi_id' => $penerimaan->lokasi_id,
|
||||
'jenis' => 'PENERIMAAN',
|
||||
'jumlah' => (int) $item->qty,
|
||||
'unit' => $item->unit ?? $unitName,
|
||||
'qty_input' => (int) ($item->qty_input ?? $item->qty),
|
||||
'multiplier' => (int) ($item->multiplier ?? $multiplier),
|
||||
'catatan' => "Penerimaan {$penerimaan->nomor_penerimaan}",
|
||||
'referensi_tipe' => 'PENERIMAAN',
|
||||
'referensi_id' => $penerimaan->id,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($rows)) {
|
||||
PergerakanStok::insert($rows);
|
||||
}
|
||||
|
||||
$penerimaan->update(['applied_at' => now()]);
|
||||
}
|
||||
|
||||
private function generateNomor(): string
|
||||
{
|
||||
do {
|
||||
$nomor = 'RCV' . now()->format('ymdHis') . random_int(100, 999);
|
||||
} while (PenerimaanBarang::query()->where('nomor_penerimaan', $nomor)->exists());
|
||||
|
||||
return $nomor;
|
||||
}
|
||||
}
|
||||
116
app/Http/Controllers/Admin/PengaturanController.php
Normal file
116
app/Http/Controllers/Admin/PengaturanController.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class PengaturanController extends Controller
|
||||
{
|
||||
public function show(): JsonResponse
|
||||
{
|
||||
$settings = Setting::query()
|
||||
->whereIn('key', [
|
||||
'toko.nama',
|
||||
'toko.telepon',
|
||||
'toko.alamat',
|
||||
'toko.logo',
|
||||
'transaksi.pajak_default',
|
||||
'transaksi.diskon_default',
|
||||
'transaksi.metode_default',
|
||||
'stok.low_threshold',
|
||||
'stok.low_threshold_toko',
|
||||
'stok.low_threshold_gudang',
|
||||
'struk.footer',
|
||||
])
|
||||
->get()
|
||||
->keyBy('key')
|
||||
->map(fn ($s) => $s->value);
|
||||
|
||||
return response()->json([
|
||||
'data' => [
|
||||
'toko' => [
|
||||
'nama' => $settings['toko.nama'] ?? '',
|
||||
'telepon' => $settings['toko.telepon'] ?? '',
|
||||
'alamat' => $settings['toko.alamat'] ?? '',
|
||||
'logo' => $settings['toko.logo'] ?? '',
|
||||
],
|
||||
'transaksi' => [
|
||||
'pajak_default' => (int) ($settings['transaksi.pajak_default'] ?? 0),
|
||||
'diskon_default' => (int) ($settings['transaksi.diskon_default'] ?? 0),
|
||||
'metode_default' => $settings['transaksi.metode_default'] ?? 'CASH',
|
||||
],
|
||||
'stok' => [
|
||||
'low_threshold_toko' => (int) ($settings['stok.low_threshold_toko'] ?? $settings['stok.low_threshold'] ?? 5),
|
||||
'low_threshold_gudang' => (int) ($settings['stok.low_threshold_gudang'] ?? 5),
|
||||
],
|
||||
'struk' => [
|
||||
'footer' => $settings['struk.footer'] ?? '',
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'toko.nama' => ['nullable', 'string', 'max:100'],
|
||||
'toko.telepon' => ['nullable', 'string', 'max:30'],
|
||||
'toko.alamat' => ['nullable', 'string', 'max:255'],
|
||||
'toko.logo' => ['nullable', 'string', 'max:255'],
|
||||
'transaksi.pajak_default' => ['nullable', 'integer', 'min:0'],
|
||||
'transaksi.diskon_default' => ['nullable', 'integer', 'min:0'],
|
||||
'transaksi.metode_default' => [
|
||||
'nullable',
|
||||
'string',
|
||||
Rule::in(['CASH', 'QRIS', 'PIUTANG', 'VOUCHER', 'VOUCHER_CASH']),
|
||||
],
|
||||
'stok.low_threshold_toko' => ['nullable', 'integer', 'min:0', 'max:1000000'],
|
||||
'stok.low_threshold_gudang' => ['nullable', 'integer', 'min:0', 'max:1000000'],
|
||||
'struk.footer' => ['nullable', 'string', 'max:2000'],
|
||||
]);
|
||||
|
||||
$flat = [
|
||||
'toko.nama' => $data['toko']['nama'] ?? null,
|
||||
'toko.telepon' => $data['toko']['telepon'] ?? null,
|
||||
'toko.alamat' => $data['toko']['alamat'] ?? null,
|
||||
'toko.logo' => $data['toko']['logo'] ?? null,
|
||||
'transaksi.pajak_default' => $data['transaksi']['pajak_default'] ?? null,
|
||||
'transaksi.diskon_default' => $data['transaksi']['diskon_default'] ?? null,
|
||||
'transaksi.metode_default' => $data['transaksi']['metode_default'] ?? null,
|
||||
'stok.low_threshold_toko' => $data['stok']['low_threshold_toko'] ?? null,
|
||||
'stok.low_threshold_gudang' => $data['stok']['low_threshold_gudang'] ?? null,
|
||||
'struk.footer' => $data['struk']['footer'] ?? null,
|
||||
];
|
||||
|
||||
foreach ($flat as $key => $value) {
|
||||
if ($value === null) {
|
||||
continue;
|
||||
}
|
||||
Setting::updateOrCreate(['key' => $key], ['value' => (string) $value]);
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'Pengaturan berhasil disimpan.']);
|
||||
}
|
||||
|
||||
public function uploadLogo(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'logo' => ['required', 'image', 'max:2048'],
|
||||
]);
|
||||
|
||||
$file = $data['logo'];
|
||||
$path = $file->store('logos', 'public');
|
||||
$url = '/storage/' . $path;
|
||||
|
||||
Setting::updateOrCreate(['key' => 'toko.logo'], ['value' => $url]);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Logo berhasil diunggah.',
|
||||
'data' => ['logo' => $url],
|
||||
]);
|
||||
}
|
||||
}
|
||||
376
app/Http/Controllers/Admin/PiutangController.php
Normal file
376
app/Http/Controllers/Admin/PiutangController.php
Normal file
@@ -0,0 +1,376 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Penjualan;
|
||||
use App\Models\PiutangPayment;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PiutangController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'from' => ['nullable', 'date'],
|
||||
'to' => ['nullable', 'date'],
|
||||
'q' => ['nullable', 'string', 'max:100'],
|
||||
'limit' => ['nullable', 'integer', 'min:1', 'max:200'],
|
||||
]);
|
||||
|
||||
$limit = (int) ($data['limit'] ?? 100);
|
||||
|
||||
$query = Penjualan::query()
|
||||
->with('user:id,name')
|
||||
->where('sisa_piutang', '>', 0)
|
||||
->orderByDesc('waktu');
|
||||
|
||||
if (!empty($data['from'])) {
|
||||
$query->where('waktu', '>=', $data['from'] . ' 00:00:00');
|
||||
}
|
||||
if (!empty($data['to'])) {
|
||||
$query->where('waktu', '<=', $data['to'] . ' 23:59:59');
|
||||
}
|
||||
if (!empty($data['q'])) {
|
||||
$s = trim((string) $data['q']);
|
||||
$query->where('nomor_penjualan', 'like', "%{$s}%");
|
||||
}
|
||||
|
||||
$rows = $query->limit($limit)->get()->map(function (Penjualan $p) {
|
||||
return [
|
||||
'id' => $p->id,
|
||||
'nomor_penjualan' => $p->nomor_penjualan,
|
||||
'waktu' => $p->waktu,
|
||||
'total' => (int) $p->total,
|
||||
'jumlah_bayar' => (int) $p->jumlah_bayar,
|
||||
'sisa_piutang' => (int) ($p->sisa_piutang ?? 0),
|
||||
'status_pembayaran' => $p->status_pembayaran ?? 'PIUTANG',
|
||||
'unit_piutang' => $p->unit_piutang,
|
||||
'kasir' => $p->user?->name,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json(['data' => $rows]);
|
||||
}
|
||||
|
||||
public function pay(Request $request, Penjualan $penjualan): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'jumlah' => ['required', 'integer', 'min:1'],
|
||||
'metode' => ['nullable', 'string', 'max:50'],
|
||||
'catatan' => ['nullable', 'string', 'max:255'],
|
||||
]);
|
||||
|
||||
$metode = $data['metode'] ?? 'CASH';
|
||||
|
||||
if ((int) ($penjualan->sisa_piutang ?? 0) <= 0) {
|
||||
return response()->json([
|
||||
'message' => 'Piutang sudah lunas.',
|
||||
], 422);
|
||||
}
|
||||
|
||||
try {
|
||||
$updated = DB::transaction(function () use ($penjualan, $data, $metode, $request) {
|
||||
$p = Penjualan::query()->where('id', $penjualan->id)->lockForUpdate()->firstOrFail();
|
||||
$sisa = (int) ($p->sisa_piutang ?? 0);
|
||||
if ($sisa <= 0) {
|
||||
throw new \RuntimeException('PIUTANG_LUNAS');
|
||||
}
|
||||
$jumlah = (int) $data['jumlah'];
|
||||
if ($jumlah > $sisa) {
|
||||
throw new \RuntimeException('PIUTANG_OVER');
|
||||
}
|
||||
|
||||
$sisaAfter = $sisa - $jumlah;
|
||||
$p->jumlah_bayar = (int) $p->jumlah_bayar + $jumlah;
|
||||
$p->sisa_piutang = $sisaAfter;
|
||||
$p->status_pembayaran = $sisaAfter > 0 ? 'PIUTANG' : 'LUNAS';
|
||||
$p->save();
|
||||
|
||||
$payment = PiutangPayment::create([
|
||||
'penjualan_id' => $p->id,
|
||||
'jumlah' => $jumlah,
|
||||
'metode' => $metode,
|
||||
'catatan' => $data['catatan'] ?? null,
|
||||
'user_id' => $request->user()?->id,
|
||||
'sisa_before' => $sisa,
|
||||
'sisa_after' => $sisaAfter,
|
||||
]);
|
||||
|
||||
return [
|
||||
'penjualan' => $p->fresh(),
|
||||
'payment' => $payment,
|
||||
];
|
||||
});
|
||||
} catch (\RuntimeException $e) {
|
||||
if ($e->getMessage() === 'PIUTANG_LUNAS') {
|
||||
return response()->json(['message' => 'Piutang sudah lunas.'], 422);
|
||||
}
|
||||
if ($e->getMessage() === 'PIUTANG_OVER') {
|
||||
return response()->json(['message' => 'Jumlah bayar melebihi sisa piutang.'], 422);
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return response()->json(['data' => $updated]);
|
||||
}
|
||||
|
||||
public function history(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'from' => ['nullable', 'date'],
|
||||
'to' => ['nullable', 'date'],
|
||||
'q' => ['nullable', 'string', 'max:100'],
|
||||
'limit' => ['nullable', 'integer', 'min:1', 'max:200'],
|
||||
]);
|
||||
|
||||
$limit = (int) ($data['limit'] ?? 100);
|
||||
|
||||
$query = DB::table('piutang_payments as pp')
|
||||
->leftJoin('penjualan as p', 'p.id', '=', 'pp.penjualan_id')
|
||||
->leftJoin('users as u', 'u.id', '=', 'pp.user_id')
|
||||
->select([
|
||||
'pp.id',
|
||||
'pp.penjualan_id',
|
||||
'p.nomor_penjualan',
|
||||
'p.unit_piutang',
|
||||
'pp.jumlah',
|
||||
'pp.metode',
|
||||
'pp.catatan',
|
||||
'pp.sisa_before',
|
||||
'pp.sisa_after',
|
||||
'pp.created_at',
|
||||
'u.name as kasir',
|
||||
])
|
||||
->orderByDesc('pp.id');
|
||||
|
||||
if (!empty($data['from'])) {
|
||||
$query->where('pp.created_at', '>=', $data['from'] . ' 00:00:00');
|
||||
}
|
||||
if (!empty($data['to'])) {
|
||||
$query->where('pp.created_at', '<=', $data['to'] . ' 23:59:59');
|
||||
}
|
||||
if (!empty($data['q'])) {
|
||||
$s = trim((string) $data['q']);
|
||||
$query->where('p.nomor_penjualan', 'like', "%{$s}%");
|
||||
}
|
||||
|
||||
$rows = $query->limit($limit)->get();
|
||||
|
||||
return response()->json(['data' => $rows]);
|
||||
}
|
||||
|
||||
public function historyByPenjualan(Penjualan $penjualan): JsonResponse
|
||||
{
|
||||
$rows = PiutangPayment::query()
|
||||
->where('penjualan_id', $penjualan->id)
|
||||
->orderByDesc('id')
|
||||
->get()
|
||||
->map(function (PiutangPayment $p) {
|
||||
return [
|
||||
'id' => $p->id,
|
||||
'jumlah' => (int) $p->jumlah,
|
||||
'metode' => $p->metode,
|
||||
'catatan' => $p->catatan,
|
||||
'sisa_before' => (int) $p->sisa_before,
|
||||
'sisa_after' => (int) $p->sisa_after,
|
||||
'created_at' => $p->created_at,
|
||||
'unit_piutang' => $penjualan->unit_piutang,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json(['data' => $rows]);
|
||||
}
|
||||
|
||||
public function export(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'from' => ['nullable', 'date'],
|
||||
'to' => ['nullable', 'date'],
|
||||
'q' => ['nullable', 'string', 'max:100'],
|
||||
]);
|
||||
|
||||
$query = Penjualan::query()
|
||||
->with('user:id,name')
|
||||
->where('sisa_piutang', '>', 0)
|
||||
->orderByDesc('waktu');
|
||||
|
||||
if (!empty($data['from'])) {
|
||||
$query->where('waktu', '>=', $data['from'] . ' 00:00:00');
|
||||
}
|
||||
if (!empty($data['to'])) {
|
||||
$query->where('waktu', '<=', $data['to'] . ' 23:59:59');
|
||||
}
|
||||
if (!empty($data['q'])) {
|
||||
$s = trim((string) $data['q']);
|
||||
$query->where('nomor_penjualan', 'like', "%{$s}%");
|
||||
}
|
||||
|
||||
$rows = $query->get()->map(function (Penjualan $p) {
|
||||
$dt = new \DateTime($p->waktu);
|
||||
return [
|
||||
'tanggal' => $dt->format('Y-m-d'),
|
||||
'jam' => $dt->format('H:i:s'),
|
||||
'nomor_penjualan' => $p->nomor_penjualan,
|
||||
'kasir' => $p->user?->name ?? '-',
|
||||
'total' => (int) $p->total,
|
||||
'bayar' => (int) $p->jumlah_bayar,
|
||||
'sisa_piutang' => (int) ($p->sisa_piutang ?? 0),
|
||||
'status' => $p->status_pembayaran ?? 'PIUTANG',
|
||||
'unit_piutang' => $p->unit_piutang ?? '-',
|
||||
];
|
||||
})->all();
|
||||
|
||||
$filename = 'piutang-' . now()->format('YmdHis') . '.xls';
|
||||
|
||||
return $this->downloadXls($filename, $rows);
|
||||
}
|
||||
|
||||
public function exportHistory(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'from' => ['nullable', 'date'],
|
||||
'to' => ['nullable', 'date'],
|
||||
'q' => ['nullable', 'string', 'max:100'],
|
||||
]);
|
||||
|
||||
$query = DB::table('piutang_payments as pp')
|
||||
->leftJoin('penjualan as p', 'p.id', '=', 'pp.penjualan_id')
|
||||
->leftJoin('users as u', 'u.id', '=', 'pp.user_id')
|
||||
->select([
|
||||
'pp.created_at',
|
||||
'p.nomor_penjualan',
|
||||
'p.unit_piutang',
|
||||
'u.name as kasir',
|
||||
'pp.metode',
|
||||
'pp.jumlah',
|
||||
'pp.sisa_before',
|
||||
'pp.sisa_after',
|
||||
'pp.catatan',
|
||||
])
|
||||
->orderByDesc('pp.id');
|
||||
|
||||
if (!empty($data['from'])) {
|
||||
$query->where('pp.created_at', '>=', $data['from'] . ' 00:00:00');
|
||||
}
|
||||
if (!empty($data['to'])) {
|
||||
$query->where('pp.created_at', '<=', $data['to'] . ' 23:59:59');
|
||||
}
|
||||
if (!empty($data['q'])) {
|
||||
$s = trim((string) $data['q']);
|
||||
$query->where('p.nomor_penjualan', 'like', "%{$s}%");
|
||||
}
|
||||
|
||||
$rows = $query->get()->map(function ($r) {
|
||||
$dt = new \DateTime($r->created_at);
|
||||
return [
|
||||
'tanggal' => $dt->format('Y-m-d'),
|
||||
'jam' => $dt->format('H:i:s'),
|
||||
'nomor_penjualan' => $r->nomor_penjualan ?? '-',
|
||||
'unit_piutang' => $r->unit_piutang ?? '-',
|
||||
'kasir' => $r->kasir ?? '-',
|
||||
'metode' => $r->metode,
|
||||
'jumlah' => (int) $r->jumlah,
|
||||
'sisa_before' => (int) $r->sisa_before,
|
||||
'sisa_after' => (int) $r->sisa_after,
|
||||
'catatan' => $r->catatan ?? '-',
|
||||
];
|
||||
})->all();
|
||||
|
||||
$filename = 'piutang-riwayat-' . now()->format('YmdHis') . '.xls';
|
||||
|
||||
return $this->downloadXlsHistory($filename, $rows);
|
||||
}
|
||||
|
||||
private function downloadXls(string $filename, array $rows)
|
||||
{
|
||||
$headers = [
|
||||
'Tanggal',
|
||||
'Jam',
|
||||
'No Transaksi',
|
||||
'Kasir',
|
||||
'Total',
|
||||
'Bayar',
|
||||
'Sisa Piutang',
|
||||
'Status',
|
||||
'Unit',
|
||||
];
|
||||
|
||||
return response()->streamDownload(function () use ($headers, $rows) {
|
||||
$escape = fn ($v) => htmlspecialchars((string) $v, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||
|
||||
echo "\xEF\xBB\xBF";
|
||||
echo "<table border='1'>\n<thead><tr>";
|
||||
foreach ($headers as $h) {
|
||||
echo "<th>{$escape($h)}</th>";
|
||||
}
|
||||
echo "</tr></thead>\n<tbody>";
|
||||
|
||||
foreach ($rows as $r) {
|
||||
echo "<tr>";
|
||||
echo "<td>{$escape($r['tanggal'])}</td>";
|
||||
echo "<td>{$escape($r['jam'])}</td>";
|
||||
echo "<td>{$escape($r['nomor_penjualan'])}</td>";
|
||||
echo "<td>{$escape($r['kasir'])}</td>";
|
||||
echo "<td>{$escape($r['total'])}</td>";
|
||||
echo "<td>{$escape($r['bayar'])}</td>";
|
||||
echo "<td>{$escape($r['sisa_piutang'])}</td>";
|
||||
echo "<td>{$escape($r['status'])}</td>";
|
||||
echo "<td>{$escape($r['unit_piutang'])}</td>";
|
||||
echo "</tr>\n";
|
||||
}
|
||||
|
||||
echo "</tbody></table>";
|
||||
}, $filename, [
|
||||
'Content-Type' => 'application/vnd.ms-excel; charset=UTF-8',
|
||||
]);
|
||||
}
|
||||
|
||||
private function downloadXlsHistory(string $filename, array $rows)
|
||||
{
|
||||
$headers = [
|
||||
'Tanggal',
|
||||
'Jam',
|
||||
'No Transaksi',
|
||||
'Unit',
|
||||
'Kasir',
|
||||
'Metode',
|
||||
'Jumlah Bayar',
|
||||
'Sisa Sebelum',
|
||||
'Sisa Sesudah',
|
||||
'Catatan',
|
||||
];
|
||||
|
||||
return response()->streamDownload(function () use ($headers, $rows) {
|
||||
$escape = fn ($v) => htmlspecialchars((string) $v, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||
|
||||
echo "\xEF\xBB\xBF";
|
||||
echo "<table border='1'>\n<thead><tr>";
|
||||
foreach ($headers as $h) {
|
||||
echo "<th>{$escape($h)}</th>";
|
||||
}
|
||||
echo "</tr></thead>\n<tbody>";
|
||||
|
||||
foreach ($rows as $r) {
|
||||
echo "<tr>";
|
||||
echo "<td>{$escape($r['tanggal'])}</td>";
|
||||
echo "<td>{$escape($r['jam'])}</td>";
|
||||
echo "<td>{$escape($r['nomor_penjualan'])}</td>";
|
||||
echo "<td>{$escape($r['unit_piutang'])}</td>";
|
||||
echo "<td>{$escape($r['kasir'])}</td>";
|
||||
echo "<td>{$escape($r['metode'])}</td>";
|
||||
echo "<td>{$escape($r['jumlah'])}</td>";
|
||||
echo "<td>{$escape($r['sisa_before'])}</td>";
|
||||
echo "<td>{$escape($r['sisa_after'])}</td>";
|
||||
echo "<td>{$escape($r['catatan'])}</td>";
|
||||
echo "</tr>\n";
|
||||
}
|
||||
|
||||
echo "</tbody></table>";
|
||||
}, $filename, [
|
||||
'Content-Type' => 'application/vnd.ms-excel; charset=UTF-8',
|
||||
]);
|
||||
}
|
||||
}
|
||||
216
app/Http/Controllers/Admin/ProdukController.php
Normal file
216
app/Http/Controllers/Admin/ProdukController.php
Normal file
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ProductUnit;
|
||||
use App\Models\Produk;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class ProdukController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$withStock = $request->boolean('with_stock');
|
||||
$withUnits = $request->boolean('with_units');
|
||||
|
||||
$q = Produk::query()->select(['id', 'sku', 'nama', 'barcode', 'harga_beli', 'harga_jual', 'is_aktif']);
|
||||
|
||||
if ($withUnits) {
|
||||
$q->with(['units' => function ($q) {
|
||||
$q->select(['id', 'produk_id', 'nama_unit', 'multiplier', 'is_base'])->orderBy('multiplier');
|
||||
}]);
|
||||
}
|
||||
|
||||
if ($withStock) {
|
||||
// stok total = masuk (ke_lokasi_id tidak null) - keluar (dari_lokasi_id tidak null)
|
||||
$q->addSelect([
|
||||
'stok_total' => DB::table('pergerakan_stok')
|
||||
->selectRaw(
|
||||
'COALESCE(SUM(CASE WHEN ke_lokasi_id IS NOT NULL THEN jumlah ELSE 0 END),0) - ' .
|
||||
'COALESCE(SUM(CASE WHEN dari_lokasi_id IS NOT NULL THEN jumlah ELSE 0 END),0)'
|
||||
)
|
||||
->whereColumn('pergerakan_stok.produk_id', 'produk.id'),
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'data' => $q->orderBy('id', 'desc')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Request $request, Produk $produk): JsonResponse
|
||||
{
|
||||
$withUnits = $request->boolean('with_units');
|
||||
$withStock = $request->boolean('with_stock');
|
||||
|
||||
if ($withUnits) {
|
||||
$produk->load(['units' => function ($q) {
|
||||
$q->select(['id', 'produk_id', 'nama_unit', 'multiplier', 'is_base'])->orderBy('multiplier');
|
||||
}]);
|
||||
}
|
||||
|
||||
if ($withStock) {
|
||||
$stokTotal = DB::table('pergerakan_stok')
|
||||
->selectRaw(
|
||||
'COALESCE(SUM(CASE WHEN ke_lokasi_id IS NOT NULL THEN jumlah ELSE 0 END),0) - ' .
|
||||
'COALESCE(SUM(CASE WHEN dari_lokasi_id IS NOT NULL THEN jumlah ELSE 0 END),0) AS stok_total'
|
||||
)
|
||||
->where('produk_id', $produk->id)
|
||||
->value('stok_total');
|
||||
|
||||
$produk->setAttribute('stok_total', (int) ($stokTotal ?? 0));
|
||||
}
|
||||
|
||||
return response()->json(['data' => $produk]);
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'sku' => ['nullable', 'string', 'max:255'],
|
||||
'nama' => ['required', 'string', 'max:255'],
|
||||
'barcode' => ['required', 'string', 'max:255', 'unique:produk,barcode'],
|
||||
'harga_beli' => ['nullable', 'integer', 'min:0'],
|
||||
'harga_jual' => ['required', 'integer', 'min:0'],
|
||||
'is_aktif' => ['nullable', 'boolean'],
|
||||
|
||||
// satuan (opsional)
|
||||
'isi_pack' => ['nullable', 'integer', 'min:2'],
|
||||
'isi_dus' => ['nullable', 'integer', 'min:2'],
|
||||
'isi_box' => ['nullable', 'integer', 'min:2'],
|
||||
'units' => ['nullable', 'array'],
|
||||
]);
|
||||
|
||||
if (empty($data['sku'])) {
|
||||
$data['sku'] = null;
|
||||
}
|
||||
|
||||
// ambil unit config dari payload
|
||||
$units = $this->normalizeUnits($request, $data);
|
||||
|
||||
// remove unit-only keys before create
|
||||
unset($data['isi_pack'], $data['isi_dus'], $data['isi_box'], $data['units']);
|
||||
|
||||
$data['is_aktif'] = isset($data['is_aktif']) ? (bool) $data['is_aktif'] : true;
|
||||
|
||||
$p = Produk::create($data);
|
||||
if (!$p->sku) {
|
||||
$p->sku = $this->generateSku($p->id);
|
||||
$p->save();
|
||||
}
|
||||
$this->syncUnits($p, $units);
|
||||
|
||||
return response()->json([
|
||||
'data' => $p,
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, Produk $produk): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'sku' => ['nullable', 'string', 'max:255'],
|
||||
'nama' => ['required', 'string', 'max:255'],
|
||||
'barcode' => ['required', 'string', 'max:255', Rule::unique('produk', 'barcode')->ignore($produk->id)],
|
||||
'harga_beli' => ['nullable', 'integer', 'min:0'],
|
||||
'harga_jual' => ['required', 'integer', 'min:0'],
|
||||
'is_aktif' => ['nullable', 'boolean'],
|
||||
|
||||
'isi_pack' => ['nullable', 'integer', 'min:2'],
|
||||
'isi_dus' => ['nullable', 'integer', 'min:2'],
|
||||
'isi_box' => ['nullable', 'integer', 'min:2'],
|
||||
'units' => ['nullable', 'array'],
|
||||
]);
|
||||
|
||||
$units = $this->normalizeUnits($request, $data);
|
||||
unset($data['isi_pack'], $data['isi_dus'], $data['isi_box'], $data['units']);
|
||||
|
||||
if (array_key_exists('is_aktif', $data)) {
|
||||
$data['is_aktif'] = (bool) $data['is_aktif'];
|
||||
}
|
||||
|
||||
$produk->update($data);
|
||||
if (!$produk->sku) {
|
||||
$produk->sku = $this->generateSku($produk->id);
|
||||
$produk->save();
|
||||
}
|
||||
$this->syncUnits($produk, $units);
|
||||
|
||||
return response()->json([
|
||||
'data' => $produk->fresh(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalisasi payload unit.
|
||||
* - Selalu ada PCS (multiplier 1)
|
||||
* - pack/dus/box optional
|
||||
*/
|
||||
private function normalizeUnits(Request $request, array $validated): array
|
||||
{
|
||||
$units = [];
|
||||
|
||||
// 1) kalau user kirim units array
|
||||
if ($request->has('units') && is_array($request->input('units'))) {
|
||||
foreach ((array) $request->input('units') as $name => $mul) {
|
||||
$name = strtoupper(trim((string) $name));
|
||||
$mul = (int) $mul;
|
||||
if ($name && $mul >= 1) {
|
||||
$units[$name] = $mul;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2) fallback dari field isi_pack/isi_dus/isi_box
|
||||
foreach ([
|
||||
'PACK' => $validated['isi_pack'] ?? null,
|
||||
'DUS' => $validated['isi_dus'] ?? null,
|
||||
'BOX' => $validated['isi_box'] ?? null,
|
||||
] as $name => $mul) {
|
||||
if ($mul !== null) {
|
||||
$mul = (int) $mul;
|
||||
if ($mul >= 2) {
|
||||
$units[$name] = $mul;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// base unit
|
||||
$units['PCS'] = 1;
|
||||
|
||||
// hapus yang invalid
|
||||
$units = array_filter($units, fn ($m) => is_int($m) && $m >= 1);
|
||||
|
||||
// pastikan PCS = 1
|
||||
$units['PCS'] = 1;
|
||||
|
||||
return $units;
|
||||
}
|
||||
|
||||
private function syncUnits(Produk $produk, array $units): void
|
||||
{
|
||||
// upsert units
|
||||
foreach ($units as $name => $multiplier) {
|
||||
$isBase = ($name === 'PCS');
|
||||
ProductUnit::updateOrCreate(
|
||||
['produk_id' => $produk->id, 'nama_unit' => $name],
|
||||
['multiplier' => (int) $multiplier, 'is_base' => $isBase]
|
||||
);
|
||||
}
|
||||
|
||||
// hapus unit yang tidak ada di payload (kecuali PCS)
|
||||
$keep = array_keys($units);
|
||||
ProductUnit::query()
|
||||
->where('produk_id', $produk->id)
|
||||
->whereNotIn('nama_unit', $keep)
|
||||
->delete();
|
||||
}
|
||||
|
||||
private function generateSku(int $id): string
|
||||
{
|
||||
return 'SKU' . str_pad((string) $id, 6, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
303
app/Http/Controllers/Admin/StokController.php
Normal file
303
app/Http/Controllers/Admin/StokController.php
Normal file
@@ -0,0 +1,303 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Lokasi;
|
||||
use App\Models\PergerakanStok;
|
||||
use App\Models\ProductUnit;
|
||||
use App\Models\Produk;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class StokController extends Controller
|
||||
{
|
||||
/**
|
||||
* List stok per lokasi berdasarkan kode lokasi (contoh: GUDANG / TOKO).
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$kode = $request->string('kode')->toString();
|
||||
if (!$kode) {
|
||||
return response()->json(['message' => 'Parameter kode lokasi wajib.'], 422);
|
||||
}
|
||||
|
||||
$role = $request->user()?->role ?: 'admin';
|
||||
$kodeUpper = strtoupper($kode);
|
||||
if ($role === 'gudang' && $kodeUpper !== 'GUDANG') {
|
||||
return response()->json(['message' => 'Akses ditolak.'], 403);
|
||||
}
|
||||
if ($role === 'kasir' && $kodeUpper !== 'TOKO') {
|
||||
return response()->json(['message' => 'Akses ditolak.'], 403);
|
||||
}
|
||||
|
||||
$lokasi = Lokasi::query()->where('kode', $kode)->first();
|
||||
if (!$lokasi) {
|
||||
return response()->json(['message' => 'Lokasi tidak ditemukan.'], 404);
|
||||
}
|
||||
|
||||
$lokasiId = $lokasi->id;
|
||||
|
||||
$rows = Produk::query()
|
||||
->with(['units' => function ($q) {
|
||||
$q->selectRaw('id, produk_id, nama_unit, nama_unit as name, multiplier, is_base')
|
||||
->orderBy('multiplier');
|
||||
}])
|
||||
->select(['produk.id', 'produk.sku', 'produk.nama', 'produk.barcode', 'produk.harga_jual'])
|
||||
->addSelect([
|
||||
'stok' => DB::table('pergerakan_stok')
|
||||
->selectRaw(
|
||||
'COALESCE(SUM(CASE WHEN ke_lokasi_id = ? THEN jumlah ELSE 0 END),0) - ' .
|
||||
'COALESCE(SUM(CASE WHEN dari_lokasi_id = ? THEN jumlah ELSE 0 END),0)',
|
||||
[$lokasiId, $lokasiId]
|
||||
)
|
||||
->whereColumn('pergerakan_stok.produk_id', 'produk.id'),
|
||||
])
|
||||
->orderBy('produk.nama')
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'lokasi' => $lokasi,
|
||||
'data' => $rows,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfer stok antar lokasi.
|
||||
*/
|
||||
public function transfer(Request $request): JsonResponse
|
||||
{
|
||||
$role = $request->user()?->role ?: 'admin';
|
||||
if ($role === 'kasir') {
|
||||
return response()->json(['message' => 'Akses ditolak.'], 403);
|
||||
}
|
||||
|
||||
$data = $request->validate([
|
||||
'produk_id' => ['required', 'integer', 'exists:produk,id'],
|
||||
'dari_lokasi_id' => ['required', 'integer', 'exists:lokasi,id'],
|
||||
'ke_lokasi_id' => ['required', 'integer', 'exists:lokasi,id', 'different:dari_lokasi_id'],
|
||||
'jumlah' => ['required', 'integer', 'min:1'],
|
||||
'referensi_tipe' => ['nullable', 'string', 'max:255'],
|
||||
'catatan' => ['nullable', 'string', 'max:500'],
|
||||
]);
|
||||
|
||||
$produk = Produk::findOrFail($data['produk_id']);
|
||||
|
||||
$dari = (int) $data['dari_lokasi_id'];
|
||||
$jumlah = (int) $data['jumlah'];
|
||||
|
||||
if ($role === 'gudang') {
|
||||
$lokasiDari = Lokasi::find($dari);
|
||||
if (!$lokasiDari || strtoupper((string) $lokasiDari->kode) !== 'GUDANG') {
|
||||
return response()->json(['message' => 'Akses ditolak.'], 403);
|
||||
}
|
||||
}
|
||||
|
||||
// cek stok cukup di lokasi asal
|
||||
$stokAsal = $this->stokProdukDiLokasi($produk->id, $dari);
|
||||
if ($stokAsal < $jumlah) {
|
||||
return response()->json([
|
||||
'message' => "Stok tidak cukup di lokasi asal. Stok tersedia: {$stokAsal}",
|
||||
], 422);
|
||||
}
|
||||
|
||||
$ref = $data['referensi_tipe'] ?? null;
|
||||
if (!$ref) {
|
||||
$ref = $this->generateTransferRef();
|
||||
}
|
||||
|
||||
$movement = DB::transaction(function () use ($data, $ref) {
|
||||
return PergerakanStok::create([
|
||||
'waktu' => now(),
|
||||
'produk_id' => $data['produk_id'],
|
||||
'dari_lokasi_id' => $data['dari_lokasi_id'],
|
||||
'ke_lokasi_id' => $data['ke_lokasi_id'],
|
||||
'jenis' => 'TRANSFER',
|
||||
'jumlah' => $data['jumlah'],
|
||||
'referensi_tipe' => $ref,
|
||||
'referensi_id' => null,
|
||||
]);
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'data' => $movement,
|
||||
], 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stok masuk / keluar / penyesuaian dengan satuan (PCS/PACK/DUS/BOX).
|
||||
* qty yang disimpan di pergerakan_stok.jumlah selalu dalam PCS.
|
||||
*/
|
||||
public function adjust(Request $request): JsonResponse
|
||||
{
|
||||
$role = $request->user()?->role ?: 'admin';
|
||||
if ($role === 'kasir') {
|
||||
return response()->json(['message' => 'Akses ditolak.'], 403);
|
||||
}
|
||||
|
||||
$data = $request->validate([
|
||||
'produk_id' => ['required', 'integer', 'exists:produk,id'],
|
||||
'lokasi_id' => ['required', 'integer', 'exists:lokasi,id'],
|
||||
'tipe' => ['required', 'string', 'in:IN,OUT,ADJUST'],
|
||||
'qty' => ['required', 'integer', 'min:1'],
|
||||
'unit' => ['required', 'string', 'max:20'],
|
||||
'catatan' => ['nullable', 'string', 'max:500'],
|
||||
]);
|
||||
|
||||
$produk = Produk::query()->with('units')->findOrFail((int) $data['produk_id']);
|
||||
$lokasiId = (int) $data['lokasi_id'];
|
||||
|
||||
if ($role === 'gudang') {
|
||||
$lokasi = Lokasi::find($lokasiId);
|
||||
if (!$lokasi || strtoupper((string) $lokasi->kode) !== 'GUDANG') {
|
||||
return response()->json(['message' => 'Akses ditolak.'], 403);
|
||||
}
|
||||
}
|
||||
|
||||
$unitName = strtoupper(trim($data['unit']));
|
||||
$unit = ProductUnit::query()
|
||||
->where('produk_id', $produk->id)
|
||||
->where('nama_unit', $unitName)
|
||||
->first();
|
||||
|
||||
if (!$unit) {
|
||||
return response()->json(['message' => 'Satuan tidak valid untuk produk ini.'], 422);
|
||||
}
|
||||
|
||||
$qtyInput = (int) $data['qty'];
|
||||
$multiplier = (int) $unit->multiplier;
|
||||
$pcsQty = $qtyInput * $multiplier;
|
||||
|
||||
// hitung stok sekarang di lokasi
|
||||
$stokNow = $this->stokProdukDiLokasi($produk->id, $lokasiId);
|
||||
|
||||
$tipe = $data['tipe'];
|
||||
$deltaPcs = $pcsQty;
|
||||
if ($tipe === 'OUT') {
|
||||
$deltaPcs = -$pcsQty;
|
||||
} elseif ($tipe === 'ADJUST') {
|
||||
// ADJUST artinya set stok menjadi qty (dalam unit input)
|
||||
$target = $pcsQty;
|
||||
$deltaPcs = $target - $stokNow;
|
||||
}
|
||||
|
||||
if (($stokNow + $deltaPcs) < 0) {
|
||||
return response()->json([
|
||||
'message' => "Stok tidak cukup. Stok tersedia: {$stokNow} PCS",
|
||||
], 422);
|
||||
}
|
||||
|
||||
$movement = DB::transaction(function () use ($produk, $lokasiId, $tipe, $deltaPcs, $unitName, $qtyInput, $multiplier, $data) {
|
||||
// representasikan IN/OUT lewat dari/ke lokasi
|
||||
$dari = null;
|
||||
$ke = null;
|
||||
if ($deltaPcs >= 0) {
|
||||
$ke = $lokasiId;
|
||||
} else {
|
||||
$dari = $lokasiId;
|
||||
}
|
||||
|
||||
return PergerakanStok::create([
|
||||
'waktu' => now(),
|
||||
'produk_id' => $produk->id,
|
||||
'dari_lokasi_id' => $dari,
|
||||
'ke_lokasi_id' => $ke,
|
||||
'jenis' => $tipe,
|
||||
'jumlah' => abs($deltaPcs),
|
||||
'unit' => $unitName,
|
||||
'qty_input' => $qtyInput,
|
||||
'multiplier' => $multiplier,
|
||||
'catatan' => $data['catatan'] ?? null,
|
||||
'referensi_tipe' => null,
|
||||
'referensi_id' => null,
|
||||
]);
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'data' => $movement,
|
||||
'stok_sekarang' => $this->stokProdukDiLokasi($produk->id, $lokasiId),
|
||||
], 201);
|
||||
}
|
||||
|
||||
private function stokProdukDiLokasi(int $produkId, int $lokasiId): int
|
||||
{
|
||||
$in = (int) DB::table('pergerakan_stok')
|
||||
->where('produk_id', $produkId)
|
||||
->where('ke_lokasi_id', $lokasiId)
|
||||
->sum('jumlah');
|
||||
|
||||
$out = (int) DB::table('pergerakan_stok')
|
||||
->where('produk_id', $produkId)
|
||||
->where('dari_lokasi_id', $lokasiId)
|
||||
->sum('jumlah');
|
||||
|
||||
return $in - $out;
|
||||
}
|
||||
|
||||
private function generateTransferRef(): string
|
||||
{
|
||||
$stamp = now()->format('YmdHis');
|
||||
$rand = random_int(100, 999);
|
||||
return "TF-{$stamp}-{$rand}";
|
||||
}
|
||||
|
||||
public function transferHistory(Request $request): JsonResponse
|
||||
{
|
||||
$role = $request->user()?->role ?: 'admin';
|
||||
if ($role === 'kasir') {
|
||||
return response()->json(['message' => 'Akses ditolak.'], 403);
|
||||
}
|
||||
|
||||
$data = $request->validate([
|
||||
'from' => ['nullable', 'date'],
|
||||
'to' => ['nullable', 'date'],
|
||||
'q' => ['nullable', 'string', 'max:100'],
|
||||
'limit' => ['nullable', 'integer', 'min:1', 'max:200'],
|
||||
]);
|
||||
|
||||
$limit = (int)($data['limit'] ?? 50);
|
||||
|
||||
$query = PergerakanStok::query()
|
||||
->where('jenis', 'TRANSFER')
|
||||
->with([
|
||||
'produk:id,sku,nama,barcode',
|
||||
'dariLokasi:id,kode,nama',
|
||||
'keLokasi:id,kode,nama',
|
||||
])
|
||||
->orderByDesc('waktu');
|
||||
|
||||
if (!empty($data['from'])) {
|
||||
$query->where('waktu', '>=', $data['from'] . ' 00:00:00');
|
||||
}
|
||||
if (!empty($data['to'])) {
|
||||
$query->where('waktu', '<=', $data['to'] . ' 23:59:59');
|
||||
}
|
||||
if (!empty($data['q'])) {
|
||||
$s = trim($data['q']);
|
||||
$query->whereHas('produk', function ($q) use ($s) {
|
||||
$q->where('nama', 'like', "%{$s}%")
|
||||
->orWhere('barcode', 'like', "%{$s}%")
|
||||
->orWhere('sku', 'like', "%{$s}%");
|
||||
});
|
||||
}
|
||||
|
||||
$rows = $query->limit($limit)->get()->map(function ($m) {
|
||||
return [
|
||||
'id' => $m->id,
|
||||
'waktu' => $m->waktu,
|
||||
'produk' => $m->produk,
|
||||
'dari' => $m->dariLokasi,
|
||||
'ke' => $m->keLokasi,
|
||||
'jumlah_pcs' => (int)$m->jumlah,
|
||||
'unit' => $m->unit,
|
||||
'qty_input' => $m->qty_input,
|
||||
'multiplier' => $m->multiplier,
|
||||
'catatan' => $m->catatan,
|
||||
'referensi_tipe' => $m->referensi_tipe,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json(['data' => $rows]);
|
||||
}
|
||||
}
|
||||
439
app/Http/Controllers/Admin/TransaksiController.php
Normal file
439
app/Http/Controllers/Admin/TransaksiController.php
Normal file
@@ -0,0 +1,439 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Lokasi;
|
||||
use App\Models\Penjualan;
|
||||
use App\Models\PenjualanBarang;
|
||||
use App\Models\PergerakanStok;
|
||||
use App\Models\ProductUnit;
|
||||
use App\Models\Produk;
|
||||
use App\Models\Voucher;
|
||||
use App\Models\VoucherHistory;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TransaksiController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'from' => ['nullable', 'date'],
|
||||
'to' => ['nullable', 'date'],
|
||||
'q' => ['nullable', 'string', 'max:100'],
|
||||
'limit' => ['nullable', 'integer', 'min:1', 'max:200'],
|
||||
]);
|
||||
|
||||
$limit = (int) ($data['limit'] ?? 50);
|
||||
|
||||
$query = Penjualan::query()
|
||||
->withCount('barang')
|
||||
->orderByDesc('waktu');
|
||||
|
||||
if (!empty($data['from'])) {
|
||||
$query->where('waktu', '>=', $data['from'] . ' 00:00:00');
|
||||
}
|
||||
if (!empty($data['to'])) {
|
||||
$query->where('waktu', '<=', $data['to'] . ' 23:59:59');
|
||||
}
|
||||
if (!empty($data['q'])) {
|
||||
$s = trim($data['q']);
|
||||
$query->where('nomor_penjualan', 'like', "%{$s}%");
|
||||
}
|
||||
|
||||
$rows = $query->limit($limit)->get()->map(function (Penjualan $p) {
|
||||
return [
|
||||
'id' => $p->id,
|
||||
'nomor_penjualan' => $p->nomor_penjualan,
|
||||
'waktu' => $p->waktu,
|
||||
'subtotal' => (int) $p->subtotal,
|
||||
'diskon' => (int) $p->diskon,
|
||||
'pajak' => (int) $p->pajak,
|
||||
'total' => (int) $p->total,
|
||||
'metode_pembayaran' => $p->metode_pembayaran,
|
||||
'status_pembayaran' => $p->status_pembayaran ?? 'LUNAS',
|
||||
'voucher_kode' => $p->voucher_kode,
|
||||
'voucher_amount' => (int) ($p->voucher_amount ?? ($p->voucher_kode ? $p->total : 0)),
|
||||
'jumlah_bayar' => (int) $p->jumlah_bayar,
|
||||
'kembalian' => (int) $p->kembalian,
|
||||
'sisa_piutang' => (int) ($p->sisa_piutang ?? 0),
|
||||
'items_count' => (int) ($p->barang_count ?? 0),
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json(['data' => $rows]);
|
||||
}
|
||||
|
||||
public function simpanTransaksi(Request $request): JsonResponse
|
||||
{
|
||||
$payload = $request->validate([
|
||||
'lokasi_id' => ['required', 'integer', 'exists:lokasi,id'],
|
||||
'items' => ['required', 'array', 'min:1'],
|
||||
'items.*.produk_id' => ['required', 'integer', 'exists:produk,id'],
|
||||
'items.*.qty' => ['required', 'integer', 'min:1'],
|
||||
'items.*.harga' => ['nullable', 'integer', 'min:0'],
|
||||
'diskon' => ['nullable', 'integer', 'min:0'],
|
||||
'pajak' => ['nullable', 'integer', 'min:0'],
|
||||
'metode_pembayaran' => ['required', 'string', 'max:50'],
|
||||
'jumlah_bayar' => ['required', 'integer', 'min:0'],
|
||||
'voucher_kode' => ['nullable', 'string', 'max:255'],
|
||||
'voucher_amount' => ['nullable', 'integer', 'min:0'],
|
||||
'vouchers' => ['nullable', 'array', 'max:3'],
|
||||
'vouchers.*.kode' => ['required_with:vouchers', 'string', 'max:255'],
|
||||
'vouchers.*.amount' => ['required_with:vouchers', 'integer', 'min:1'],
|
||||
'unit_piutang' => ['nullable', 'string', 'max:100'],
|
||||
]);
|
||||
|
||||
$lokasi = Lokasi::findOrFail((int) $payload['lokasi_id']);
|
||||
|
||||
$itemRows = collect($payload['items']);
|
||||
$produkIds = $itemRows->pluck('produk_id')->unique()->values();
|
||||
$produkMap = Produk::query()->whereIn('id', $produkIds)->get()->keyBy('id');
|
||||
|
||||
if ($produkMap->count() !== $produkIds->count()) {
|
||||
return response()->json(['message' => 'Produk tidak valid.'], 422);
|
||||
}
|
||||
|
||||
$baseUnits = ProductUnit::query()
|
||||
->whereIn('produk_id', $produkIds)
|
||||
->where('is_base', true)
|
||||
->get()
|
||||
->keyBy('produk_id');
|
||||
|
||||
$qtyByProduk = [];
|
||||
$computed = [];
|
||||
$subtotal = 0;
|
||||
|
||||
foreach ($itemRows as $row) {
|
||||
$pid = (int) $row['produk_id'];
|
||||
$qty = (int) $row['qty'];
|
||||
$produk = $produkMap->get($pid);
|
||||
|
||||
$harga = isset($row['harga']) ? (int) $row['harga'] : (int) $produk->harga_jual;
|
||||
$lineTotal = $harga * $qty;
|
||||
|
||||
$qtyByProduk[$pid] = ($qtyByProduk[$pid] ?? 0) + $qty;
|
||||
$subtotal += $lineTotal;
|
||||
|
||||
$computed[] = [
|
||||
'produk' => $produk,
|
||||
'qty' => $qty,
|
||||
'harga' => $harga,
|
||||
'total' => $lineTotal,
|
||||
];
|
||||
}
|
||||
|
||||
// cek stok per produk di lokasi
|
||||
foreach ($qtyByProduk as $pid => $qty) {
|
||||
$stok = $this->stokProdukDiLokasi($pid, $lokasi->id);
|
||||
if ($stok < $qty) {
|
||||
$nama = $produkMap->get($pid)?->nama ?? 'Produk';
|
||||
return response()->json([
|
||||
'message' => "Stok tidak cukup untuk {$nama}. Stok tersedia: {$stok}",
|
||||
], 422);
|
||||
}
|
||||
}
|
||||
|
||||
$diskon = (int) ($payload['diskon'] ?? 0);
|
||||
$pajak = (int) ($payload['pajak'] ?? 0);
|
||||
$total = max(0, $subtotal - $diskon + $pajak);
|
||||
$metode = strtoupper((string) $payload['metode_pembayaran']);
|
||||
$jumlahBayar = (int) $payload['jumlah_bayar'];
|
||||
$voucherKode = null;
|
||||
$voucherAmount = 0;
|
||||
$unitPiutang = null;
|
||||
$voucherList = [];
|
||||
|
||||
if (!empty($payload['vouchers']) && is_array($payload['vouchers'])) {
|
||||
$voucherList = collect($payload['vouchers'])
|
||||
->map(function ($v) {
|
||||
return [
|
||||
'kode' => trim((string) ($v['kode'] ?? '')),
|
||||
'amount' => (int) ($v['amount'] ?? 0),
|
||||
];
|
||||
})
|
||||
->filter(fn ($v) => $v['kode'] !== '' && $v['amount'] > 0)
|
||||
->values()
|
||||
->all();
|
||||
|
||||
$uniqueCodes = collect($voucherList)->pluck('kode')->unique();
|
||||
if ($uniqueCodes->count() !== count($voucherList)) {
|
||||
return response()->json([
|
||||
'message' => 'Kode voucher tidak boleh duplikat.',
|
||||
], 422);
|
||||
}
|
||||
}
|
||||
|
||||
if ($metode === 'VOUCHER' || $metode === 'VOUCHER_CASH') {
|
||||
if (!empty($voucherList)) {
|
||||
$voucherAmount = (int) collect($voucherList)->sum('amount');
|
||||
$voucherKode = $voucherList[0]['kode'] ?? null;
|
||||
} else {
|
||||
$voucherKode = trim((string) ($payload['voucher_kode'] ?? ''));
|
||||
if ($voucherKode === '') {
|
||||
return response()->json([
|
||||
'message' => 'Kode voucher wajib diisi.',
|
||||
], 422);
|
||||
}
|
||||
if ($metode === 'VOUCHER') {
|
||||
$voucherAmount = $total;
|
||||
$jumlahBayar = 0;
|
||||
} else {
|
||||
$voucherAmount = (int) ($payload['voucher_amount'] ?? 0);
|
||||
if ($voucherAmount <= 0) {
|
||||
return response()->json([
|
||||
'message' => 'Nominal voucher wajib diisi.',
|
||||
], 422);
|
||||
}
|
||||
if ($voucherAmount > $total) {
|
||||
return response()->json([
|
||||
'message' => 'Nominal voucher tidak boleh melebihi total.',
|
||||
], 422);
|
||||
}
|
||||
}
|
||||
$voucherList = [
|
||||
['kode' => $voucherKode, 'amount' => $voucherAmount],
|
||||
];
|
||||
}
|
||||
if ($voucherAmount <= 0) {
|
||||
return response()->json([
|
||||
'message' => 'Nominal voucher wajib diisi.',
|
||||
], 422);
|
||||
}
|
||||
if ($voucherAmount > $total) {
|
||||
return response()->json([
|
||||
'message' => 'Nominal voucher tidak boleh melebihi total.',
|
||||
], 422);
|
||||
}
|
||||
if ($metode === 'VOUCHER' && $voucherAmount < $total) {
|
||||
return response()->json([
|
||||
'message' => 'Saldo voucher tidak mencukupi untuk menutup total.',
|
||||
], 422);
|
||||
}
|
||||
}
|
||||
if ($metode === 'PIUTANG') {
|
||||
$unitPiutang = trim((string) ($payload['unit_piutang'] ?? ''));
|
||||
if ($unitPiutang === '') {
|
||||
return response()->json([
|
||||
'message' => 'Unit piutang wajib diisi.',
|
||||
], 422);
|
||||
}
|
||||
}
|
||||
|
||||
$remaining = max(0, $total - $voucherAmount);
|
||||
if ($metode !== 'PIUTANG' && $jumlahBayar < $remaining) {
|
||||
return response()->json([
|
||||
'message' => 'Jumlah bayar harus sama atau lebih besar dari sisa setelah voucher.',
|
||||
], 422);
|
||||
}
|
||||
|
||||
try {
|
||||
$penjualan = DB::transaction(function () use (
|
||||
$computed,
|
||||
$baseUnits,
|
||||
$lokasi,
|
||||
$subtotal,
|
||||
$diskon,
|
||||
$pajak,
|
||||
$total,
|
||||
$jumlahBayar,
|
||||
$payload,
|
||||
$request,
|
||||
$metode,
|
||||
$voucherKode,
|
||||
$voucherAmount,
|
||||
$voucherList,
|
||||
$unitPiutang
|
||||
) {
|
||||
$nomor = $this->generateNomor();
|
||||
$remaining = max(0, $total - $voucherAmount);
|
||||
$kembalian = max(0, $jumlahBayar - $remaining);
|
||||
$sisaPiutang = $metode === 'PIUTANG' ? max(0, $remaining - $jumlahBayar) : 0;
|
||||
$statusPembayaran = $sisaPiutang > 0 ? 'PIUTANG' : 'LUNAS';
|
||||
|
||||
$voucherUsageRows = [];
|
||||
if ($voucherAmount > 0) {
|
||||
foreach ($voucherList as $v) {
|
||||
$voucher = Voucher::query()
|
||||
->where('kode', $v['kode'])
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
if (!$voucher || !$voucher->aktif) {
|
||||
throw new \RuntimeException('VOUCHER_INVALID');
|
||||
}
|
||||
if ((int) $voucher->saldo < (int) $v['amount']) {
|
||||
throw new \RuntimeException('VOUCHER_SALDO');
|
||||
}
|
||||
$saldoBefore = (int) $voucher->saldo;
|
||||
$voucher->saldo = (int) $voucher->saldo - (int) $v['amount'];
|
||||
$voucher->save();
|
||||
$voucherUsageRows[] = [
|
||||
'voucher_id' => $voucher->id,
|
||||
'kode' => $voucher->kode,
|
||||
'tipe' => 'USE',
|
||||
'jumlah' => (int) $v['amount'],
|
||||
'saldo_before' => $saldoBefore,
|
||||
'saldo_after' => (int) $voucher->saldo,
|
||||
'penjualan_id' => null,
|
||||
'user_id' => $request->user()?->id,
|
||||
'catatan' => null,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$p = Penjualan::create([
|
||||
'user_id' => $request->user()?->id,
|
||||
'nomor_penjualan' => $nomor,
|
||||
'waktu' => now(),
|
||||
'subtotal' => $subtotal,
|
||||
'diskon' => $diskon,
|
||||
'pajak' => $pajak,
|
||||
'total' => $total,
|
||||
'metode_pembayaran' => $metode,
|
||||
'status_pembayaran' => $statusPembayaran,
|
||||
'voucher_kode' => $voucherKode,
|
||||
'voucher_amount' => $voucherAmount,
|
||||
'unit_piutang' => $metode === 'PIUTANG' ? $unitPiutang : null,
|
||||
'jumlah_bayar' => $jumlahBayar,
|
||||
'kembalian' => $kembalian,
|
||||
'sisa_piutang' => $sisaPiutang,
|
||||
]);
|
||||
|
||||
$barangRows = [];
|
||||
$movementRows = [];
|
||||
|
||||
foreach ($computed as $row) {
|
||||
/** @var \App\Models\Produk $produk */
|
||||
$produk = $row['produk'];
|
||||
$qty = (int) $row['qty'];
|
||||
$harga = (int) $row['harga'];
|
||||
$lineTotal = (int) $row['total'];
|
||||
|
||||
$barangRows[] = [
|
||||
'penjualan_id' => $p->id,
|
||||
'produk_id' => $produk->id,
|
||||
'jumlah' => $qty,
|
||||
'harga' => $harga,
|
||||
'total' => $lineTotal,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
];
|
||||
|
||||
$unit = $baseUnits->get($produk->id);
|
||||
$unitName = $unit?->nama_unit ?? 'PCS';
|
||||
$multiplier = (int) ($unit?->multiplier ?? 1);
|
||||
|
||||
$movementRows[] = [
|
||||
'waktu' => now(),
|
||||
'produk_id' => $produk->id,
|
||||
'dari_lokasi_id' => $lokasi->id,
|
||||
'ke_lokasi_id' => null,
|
||||
'jenis' => 'PENJUALAN',
|
||||
'jumlah' => $qty,
|
||||
'unit' => $unitName,
|
||||
'qty_input' => $qty,
|
||||
'multiplier' => $multiplier,
|
||||
'catatan' => "Penjualan {$nomor}",
|
||||
'referensi_tipe' => 'PENJUALAN',
|
||||
'referensi_id' => $p->id,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
];
|
||||
}
|
||||
|
||||
PenjualanBarang::insert($barangRows);
|
||||
PergerakanStok::insert($movementRows);
|
||||
|
||||
if ($voucherAmount > 0) {
|
||||
foreach ($voucherUsageRows as &$row) {
|
||||
$row['penjualan_id'] = $p->id;
|
||||
}
|
||||
unset($row);
|
||||
VoucherHistory::insert($voucherUsageRows);
|
||||
}
|
||||
|
||||
return $p;
|
||||
});
|
||||
} catch (\RuntimeException $e) {
|
||||
if ($e->getMessage() === 'VOUCHER_INVALID') {
|
||||
return response()->json([
|
||||
'message' => 'Voucher tidak valid atau tidak aktif.',
|
||||
], 422);
|
||||
}
|
||||
if ($e->getMessage() === 'VOUCHER_SALDO') {
|
||||
return response()->json([
|
||||
'message' => 'Saldo voucher tidak mencukupi.',
|
||||
], 422);
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'data' => $penjualan,
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function show(Penjualan $penjualan): JsonResponse
|
||||
{
|
||||
$penjualan->load(['barang.produk:id,nama,barcode']);
|
||||
|
||||
$items = $penjualan->barang->map(function (PenjualanBarang $b) {
|
||||
return [
|
||||
'produk_id' => $b->produk_id,
|
||||
'nama' => $b->produk?->nama,
|
||||
'barcode' => $b->produk?->barcode,
|
||||
'jumlah' => (int) $b->jumlah,
|
||||
'harga' => (int) $b->harga,
|
||||
'total' => (int) $b->total,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'data' => [
|
||||
'id' => $penjualan->id,
|
||||
'nomor_penjualan' => $penjualan->nomor_penjualan,
|
||||
'waktu' => $penjualan->waktu,
|
||||
'subtotal' => (int) $penjualan->subtotal,
|
||||
'diskon' => (int) $penjualan->diskon,
|
||||
'pajak' => (int) $penjualan->pajak,
|
||||
'total' => (int) $penjualan->total,
|
||||
'metode_pembayaran' => $penjualan->metode_pembayaran,
|
||||
'status_pembayaran' => $penjualan->status_pembayaran ?? 'LUNAS',
|
||||
'voucher_kode' => $penjualan->voucher_kode,
|
||||
'voucher_amount' => (int) ($penjualan->voucher_amount ?? ($penjualan->voucher_kode ? $penjualan->total : 0)),
|
||||
'jumlah_bayar' => (int) $penjualan->jumlah_bayar,
|
||||
'kembalian' => (int) $penjualan->kembalian,
|
||||
'sisa_piutang' => (int) ($penjualan->sisa_piutang ?? 0),
|
||||
'items' => $items,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
private function stokProdukDiLokasi(int $produkId, int $lokasiId): int
|
||||
{
|
||||
$in = (int) DB::table('pergerakan_stok')
|
||||
->where('produk_id', $produkId)
|
||||
->where('ke_lokasi_id', $lokasiId)
|
||||
->sum('jumlah');
|
||||
|
||||
$out = (int) DB::table('pergerakan_stok')
|
||||
->where('produk_id', $produkId)
|
||||
->where('dari_lokasi_id', $lokasiId)
|
||||
->sum('jumlah');
|
||||
|
||||
return $in - $out;
|
||||
}
|
||||
|
||||
private function generateNomor(): string
|
||||
{
|
||||
do {
|
||||
$nomor = 'PJ' . now()->format('ymdHis') . random_int(100, 999);
|
||||
} while (Penjualan::query()->where('nomor_penjualan', $nomor)->exists());
|
||||
|
||||
return $nomor;
|
||||
}
|
||||
}
|
||||
139
app/Http/Controllers/Admin/UserController.php
Normal file
139
app/Http/Controllers/Admin/UserController.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$limit = (int) $request->query('limit', 100);
|
||||
$limit = max(1, min(200, $limit));
|
||||
|
||||
$users = User::query()
|
||||
->with('pegawai:id,nama,nip')
|
||||
->orderByDesc('id')
|
||||
->limit($limit)
|
||||
->get(['id', 'name', 'email', 'role', 'nip', 'pegawai_id', 'created_at']);
|
||||
|
||||
return response()->json([
|
||||
'data' => $users->map(function (User $u) {
|
||||
return [
|
||||
'id' => $u->id,
|
||||
'name' => $u->name,
|
||||
'email' => $u->email,
|
||||
'role' => $u->role,
|
||||
'nip' => $u->nip,
|
||||
'pegawai_id' => $u->pegawai_id,
|
||||
'pegawai_nama' => $u->pegawai?->nama,
|
||||
'created_at' => $u->created_at,
|
||||
];
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => ['nullable', 'string', 'max:100'],
|
||||
'email' => ['nullable', 'string', 'email', 'max:255', Rule::unique('users', 'email')],
|
||||
'password' => ['required', 'string', 'min:6'],
|
||||
'role' => ['nullable', 'string', Rule::in(['admin', 'kasir', 'gudang'])],
|
||||
'pegawai_id' => ['required', 'integer', 'exists:pegawai,id'],
|
||||
]);
|
||||
|
||||
$pegawai = \App\Models\Pegawai::find($data['pegawai_id']);
|
||||
if (!$pegawai) {
|
||||
return response()->json(['message' => 'Pegawai tidak ditemukan.'], 422);
|
||||
}
|
||||
|
||||
if (!$pegawai->nip) {
|
||||
return response()->json(['message' => 'Pegawai belum memiliki NIP.'], 422);
|
||||
}
|
||||
$nip = $pegawai->nip;
|
||||
if (User::query()->where('nip', $nip)->exists()) {
|
||||
return response()->json(['message' => 'NIP sudah digunakan.'], 422);
|
||||
}
|
||||
|
||||
$email = $data['email'] ?? null;
|
||||
if (!$email) {
|
||||
$email = $nip . '@pos.local';
|
||||
}
|
||||
|
||||
$user = User::create([
|
||||
'name' => $pegawai->nama ?? ($data['name'] ?? $nip),
|
||||
'email' => $email,
|
||||
'password' => Hash::make($data['password']),
|
||||
'role' => $data['role'] ?? User::ROLE_KASIR,
|
||||
'nip' => $nip,
|
||||
'pegawai_id' => $pegawai->id,
|
||||
]);
|
||||
|
||||
return response()->json(['data' => $user], 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, User $user): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => ['nullable', 'string', 'max:100'],
|
||||
'email' => ['nullable', 'string', 'email', 'max:255', Rule::unique('users', 'email')->ignore($user->id)],
|
||||
'password' => ['nullable', 'string', 'min:6'],
|
||||
'role' => ['nullable', 'string', Rule::in(['admin', 'kasir', 'gudang'])],
|
||||
'pegawai_id' => ['nullable', 'integer', 'exists:pegawai,id'],
|
||||
]);
|
||||
|
||||
$pegawai = null;
|
||||
if (!empty($data['pegawai_id'])) {
|
||||
$pegawai = \App\Models\Pegawai::find($data['pegawai_id']);
|
||||
}
|
||||
|
||||
$nip = $pegawai?->nip ?? $user->nip;
|
||||
if ($pegawai && !$pegawai->nip) {
|
||||
return response()->json(['message' => 'Pegawai belum memiliki NIP.'], 422);
|
||||
}
|
||||
if (!$nip) {
|
||||
return response()->json(['message' => 'NIP wajib diisi.'], 422);
|
||||
}
|
||||
if (User::query()->where('nip', $nip)->where('id', '!=', $user->id)->exists()) {
|
||||
return response()->json(['message' => 'NIP sudah digunakan.'], 422);
|
||||
}
|
||||
|
||||
$email = $data['email'] ?? $user->email;
|
||||
if (!$email) {
|
||||
$email = $nip . '@pos.local';
|
||||
}
|
||||
|
||||
$payload = [
|
||||
'name' => $pegawai?->nama ?? ($data['name'] ?? $user->name),
|
||||
'email' => $email,
|
||||
'role' => $data['role'] ?? $user->role ?? User::ROLE_KASIR,
|
||||
'nip' => $nip,
|
||||
'pegawai_id' => $pegawai?->id ?? null,
|
||||
];
|
||||
|
||||
if (!empty($data['password'])) {
|
||||
$payload['password'] = Hash::make($data['password']);
|
||||
}
|
||||
|
||||
$user->update($payload);
|
||||
|
||||
return response()->json(['data' => $user]);
|
||||
}
|
||||
|
||||
public function destroy(User $user): JsonResponse
|
||||
{
|
||||
if ($user->role === User::ROLE_ADMIN) {
|
||||
return response()->json(['message' => 'User admin tidak bisa dihapus.'], 422);
|
||||
}
|
||||
|
||||
$user->delete();
|
||||
|
||||
return response()->json(['message' => 'User berhasil dihapus.']);
|
||||
}
|
||||
}
|
||||
200
app/Http/Controllers/Admin/VoucherController.php
Normal file
200
app/Http/Controllers/Admin/VoucherController.php
Normal file
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Voucher;
|
||||
use App\Models\VoucherHistory;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class VoucherController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'q' => ['nullable', 'string', 'max:100'],
|
||||
'limit' => ['nullable', 'integer', 'min:1', 'max:200'],
|
||||
]);
|
||||
|
||||
$limit = (int) ($data['limit'] ?? 100);
|
||||
|
||||
$query = Voucher::query()->with('pegawai:id,nama,nip')->orderByDesc('id');
|
||||
if (!empty($data['q'])) {
|
||||
$s = trim((string) $data['q']);
|
||||
$query->where('kode', 'like', "%{$s}%")
|
||||
->orWhere('catatan', 'like', "%{$s}%");
|
||||
}
|
||||
|
||||
$rows = $query->limit($limit)->get()->map(function (Voucher $v) {
|
||||
return [
|
||||
'id' => $v->id,
|
||||
'pegawai_id' => $v->pegawai_id,
|
||||
'pegawai_nama' => $v->pegawai?->nama,
|
||||
'pegawai_nip' => $v->pegawai?->nip,
|
||||
'kode' => $v->kode,
|
||||
'saldo' => (int) $v->saldo,
|
||||
'aktif' => (bool) $v->aktif,
|
||||
'catatan' => $v->catatan,
|
||||
'created_at' => $v->created_at,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json(['data' => $rows]);
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'pegawai_id' => ['required', 'integer', 'exists:pegawai,id'],
|
||||
'kode' => ['nullable', 'string', 'max:255', 'unique:vouchers,kode'],
|
||||
'saldo' => ['nullable', 'integer', 'min:0'],
|
||||
'aktif' => ['nullable', 'boolean'],
|
||||
'catatan' => ['nullable', 'string', 'max:255'],
|
||||
]);
|
||||
|
||||
$kode = trim((string) ($data['kode'] ?? ''));
|
||||
if ($kode === '') {
|
||||
$kode = $this->generateKode();
|
||||
}
|
||||
|
||||
$voucher = Voucher::create([
|
||||
'pegawai_id' => (int) $data['pegawai_id'],
|
||||
'kode' => $kode,
|
||||
'saldo' => (int) ($data['saldo'] ?? 0),
|
||||
'aktif' => isset($data['aktif']) ? (bool) $data['aktif'] : true,
|
||||
'catatan' => $data['catatan'] ?? null,
|
||||
'created_by' => $request->user()?->id,
|
||||
]);
|
||||
|
||||
return response()->json(['data' => $voucher->load('pegawai:id,nama,nip')], 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, Voucher $voucher): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'saldo' => ['nullable', 'integer', 'min:0'],
|
||||
'add_saldo' => ['nullable', 'integer', 'min:0'],
|
||||
'aktif' => ['nullable', 'boolean'],
|
||||
'catatan' => ['nullable', 'string', 'max:255'],
|
||||
]);
|
||||
|
||||
$updated = DB::transaction(function () use ($voucher, $data, $request) {
|
||||
$voucher = Voucher::query()->where('id', $voucher->id)->lockForUpdate()->firstOrFail();
|
||||
$saldoBefore = (int) $voucher->saldo;
|
||||
if (array_key_exists('add_saldo', $data) && $data['add_saldo'] !== null) {
|
||||
$voucher->saldo = (int) $voucher->saldo + (int) $data['add_saldo'];
|
||||
} elseif (array_key_exists('saldo', $data) && $data['saldo'] !== null) {
|
||||
$voucher->saldo = (int) $data['saldo'];
|
||||
}
|
||||
if (array_key_exists('aktif', $data)) {
|
||||
$voucher->aktif = (bool) $data['aktif'];
|
||||
}
|
||||
if (array_key_exists('catatan', $data)) {
|
||||
$voucher->catatan = $data['catatan'];
|
||||
}
|
||||
$voucher->save();
|
||||
if (array_key_exists('add_saldo', $data) && $data['add_saldo'] !== null) {
|
||||
VoucherHistory::create([
|
||||
'voucher_id' => $voucher->id,
|
||||
'kode' => $voucher->kode,
|
||||
'tipe' => 'TOPUP',
|
||||
'jumlah' => (int) $data['add_saldo'],
|
||||
'saldo_before' => $saldoBefore,
|
||||
'saldo_after' => (int) $voucher->saldo,
|
||||
'penjualan_id' => null,
|
||||
'user_id' => $request->user()?->id,
|
||||
'catatan' => 'Top up',
|
||||
]);
|
||||
}
|
||||
return $voucher->fresh()->load('pegawai:id,nama,nip');
|
||||
});
|
||||
|
||||
return response()->json(['data' => $updated]);
|
||||
}
|
||||
|
||||
public function history(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'from' => ['nullable', 'date'],
|
||||
'to' => ['nullable', 'date'],
|
||||
'q' => ['nullable', 'string', 'max:100'],
|
||||
'tipe' => ['nullable', 'string', 'max:20'],
|
||||
'limit' => ['nullable', 'integer', 'min:1', 'max:200'],
|
||||
]);
|
||||
|
||||
$limit = (int) ($data['limit'] ?? 100);
|
||||
|
||||
$query = DB::table('voucher_histories as h')
|
||||
->leftJoin('penjualan as p', 'p.id', '=', 'h.penjualan_id')
|
||||
->select([
|
||||
'h.id',
|
||||
'h.voucher_id',
|
||||
'h.kode',
|
||||
'h.tipe',
|
||||
'h.jumlah',
|
||||
'h.saldo_before',
|
||||
'h.saldo_after',
|
||||
'h.penjualan_id',
|
||||
'p.nomor_penjualan',
|
||||
'h.user_id',
|
||||
'h.catatan',
|
||||
'h.created_at',
|
||||
])
|
||||
->orderByDesc('h.id');
|
||||
|
||||
if (!empty($data['from'])) {
|
||||
$query->where('h.created_at', '>=', $data['from'] . ' 00:00:00');
|
||||
}
|
||||
if (!empty($data['to'])) {
|
||||
$query->where('h.created_at', '<=', $data['to'] . ' 23:59:59');
|
||||
}
|
||||
if (!empty($data['q'])) {
|
||||
$s = trim((string) $data['q']);
|
||||
$query->where('h.kode', 'like', "%{$s}%");
|
||||
}
|
||||
if (!empty($data['tipe'])) {
|
||||
$query->where('h.tipe', $data['tipe']);
|
||||
}
|
||||
|
||||
$rows = $query->limit($limit)->get();
|
||||
|
||||
return response()->json(['data' => $rows]);
|
||||
}
|
||||
|
||||
public function lookup(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'kode' => ['required', 'string', 'max:255'],
|
||||
]);
|
||||
|
||||
$kode = trim((string) $data['kode']);
|
||||
if ($kode === '') {
|
||||
return response()->json(['message' => 'Kode voucher wajib diisi.'], 422);
|
||||
}
|
||||
|
||||
$voucher = Voucher::query()->where('kode', $kode)->first();
|
||||
if (!$voucher) {
|
||||
return response()->json(['message' => 'Voucher tidak ditemukan.'], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'data' => [
|
||||
'id' => $voucher->id,
|
||||
'kode' => $voucher->kode,
|
||||
'saldo' => (int) $voucher->saldo,
|
||||
'aktif' => (bool) $voucher->aktif,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
private function generateKode(): string
|
||||
{
|
||||
do {
|
||||
$kode = 'VCH' . now()->format('ymd') . random_int(1000, 9999);
|
||||
} while (Voucher::query()->where('kode', $kode)->exists());
|
||||
|
||||
return $kode;
|
||||
}
|
||||
}
|
||||
49
app/Http/Controllers/Auth/AuthenticatedSessionController.php
Normal file
49
app/Http/Controllers/Auth/AuthenticatedSessionController.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Auth\LoginRequest;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class AuthenticatedSessionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the login view.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming authentication request.
|
||||
*/
|
||||
public function store(LoginRequest $request): RedirectResponse
|
||||
{
|
||||
$request->authenticate();
|
||||
|
||||
$request->session()->regenerate();
|
||||
|
||||
return redirect()->intended(RouteServiceProvider::HOME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy an authenticated session.
|
||||
*/
|
||||
public function destroy(Request $request): RedirectResponse
|
||||
{
|
||||
Auth::guard('web')->logout();
|
||||
|
||||
$request->session()->invalidate();
|
||||
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
// Setelah logout balik ke login
|
||||
return redirect()->route('login');
|
||||
}
|
||||
}
|
||||
41
app/Http/Controllers/Auth/ConfirmablePasswordController.php
Normal file
41
app/Http/Controllers/Auth/ConfirmablePasswordController.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ConfirmablePasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show the confirm password view.
|
||||
*/
|
||||
public function show(): View
|
||||
{
|
||||
return view('auth.confirm-password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm the user's password.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
if (! Auth::guard('web')->validate([
|
||||
'email' => $request->user()->email,
|
||||
'password' => $request->password,
|
||||
])) {
|
||||
throw ValidationException::withMessages([
|
||||
'password' => __('auth.password'),
|
||||
]);
|
||||
}
|
||||
|
||||
$request->session()->put('auth.password_confirmed_at', time());
|
||||
|
||||
return redirect()->intended(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EmailVerificationNotificationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Send a new email verification notification.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(RouteServiceProvider::HOME);
|
||||
}
|
||||
|
||||
$request->user()->sendEmailVerificationNotification();
|
||||
|
||||
return back()->with('status', 'verification-link-sent');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class EmailVerificationPromptController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the email verification prompt.
|
||||
*/
|
||||
public function __invoke(Request $request): RedirectResponse|View
|
||||
{
|
||||
return $request->user()->hasVerifiedEmail()
|
||||
? redirect()->intended(RouteServiceProvider::HOME)
|
||||
: view('auth.verify-email');
|
||||
}
|
||||
}
|
||||
61
app/Http/Controllers/Auth/NewPasswordController.php
Normal file
61
app/Http/Controllers/Auth/NewPasswordController.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Auth\Events\PasswordReset;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class NewPasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset view.
|
||||
*/
|
||||
public function create(Request $request): View
|
||||
{
|
||||
return view('auth.reset-password', ['request' => $request]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming new password request.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'token' => ['required'],
|
||||
'email' => ['required', 'email'],
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
// Here we will attempt to reset the user's password. If it is successful we
|
||||
// will update the password on an actual user model and persist it to the
|
||||
// database. Otherwise we will parse the error and return the response.
|
||||
$status = Password::reset(
|
||||
$request->only('email', 'password', 'password_confirmation', 'token'),
|
||||
function ($user) use ($request) {
|
||||
$user->forceFill([
|
||||
'password' => Hash::make($request->password),
|
||||
'remember_token' => Str::random(60),
|
||||
])->save();
|
||||
|
||||
event(new PasswordReset($user));
|
||||
}
|
||||
);
|
||||
|
||||
// If the password was successfully reset, we will redirect the user back to
|
||||
// the application's home authenticated view. If there is an error we can
|
||||
// redirect them back to where they came from with their error message.
|
||||
return $status == Password::PASSWORD_RESET
|
||||
? redirect()->route('login')->with('status', __($status))
|
||||
: back()->withInput($request->only('email'))
|
||||
->withErrors(['email' => __($status)]);
|
||||
}
|
||||
}
|
||||
29
app/Http/Controllers/Auth/PasswordController.php
Normal file
29
app/Http/Controllers/Auth/PasswordController.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class PasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Update the user's password.
|
||||
*/
|
||||
public function update(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validateWithBag('updatePassword', [
|
||||
'current_password' => ['required', 'current_password'],
|
||||
'password' => ['required', Password::defaults(), 'confirmed'],
|
||||
]);
|
||||
|
||||
$request->user()->update([
|
||||
'password' => Hash::make($validated['password']),
|
||||
]);
|
||||
|
||||
return back()->with('status', 'password-updated');
|
||||
}
|
||||
}
|
||||
44
app/Http/Controllers/Auth/PasswordResetLinkController.php
Normal file
44
app/Http/Controllers/Auth/PasswordResetLinkController.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class PasswordResetLinkController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset link request view.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.forgot-password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming password reset link request.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'email' => ['required', 'email'],
|
||||
]);
|
||||
|
||||
// We will send the password reset link to this user. Once we have attempted
|
||||
// to send the link, we will examine the response then see the message we
|
||||
// need to show to the user. Finally, we'll send out a proper response.
|
||||
$status = Password::sendResetLink(
|
||||
$request->only('email')
|
||||
);
|
||||
|
||||
return $status == Password::RESET_LINK_SENT
|
||||
? back()->with('status', __($status))
|
||||
: back()->withInput($request->only('email'))
|
||||
->withErrors(['email' => __($status)]);
|
||||
}
|
||||
}
|
||||
51
app/Http/Controllers/Auth/RegisteredUserController.php
Normal file
51
app/Http/Controllers/Auth/RegisteredUserController.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class RegisteredUserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the registration view.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.register');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming registration request.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
$user = User::create([
|
||||
'name' => $request->name,
|
||||
'email' => $request->email,
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
|
||||
event(new Registered($user));
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
28
app/Http/Controllers/Auth/VerifyEmailController.php
Normal file
28
app/Http/Controllers/Auth/VerifyEmailController.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Auth\Events\Verified;
|
||||
use Illuminate\Foundation\Auth\EmailVerificationRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class VerifyEmailController extends Controller
|
||||
{
|
||||
/**
|
||||
* Mark the authenticated user's email address as verified.
|
||||
*/
|
||||
public function __invoke(EmailVerificationRequest $request): RedirectResponse
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(RouteServiceProvider::HOME.'?verified=1');
|
||||
}
|
||||
|
||||
if ($request->user()->markEmailAsVerified()) {
|
||||
event(new Verified($request->user()));
|
||||
}
|
||||
|
||||
return redirect()->intended(RouteServiceProvider::HOME.'?verified=1');
|
||||
}
|
||||
}
|
||||
12
app/Http/Controllers/Controller.php
Normal file
12
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, ValidatesRequests;
|
||||
}
|
||||
60
app/Http/Controllers/ProfileController.php
Normal file
60
app/Http/Controllers/ProfileController.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\ProfileUpdateRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the user's profile form.
|
||||
*/
|
||||
public function edit(Request $request): View
|
||||
{
|
||||
return view('profile.edit', [
|
||||
'user' => $request->user(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the user's profile information.
|
||||
*/
|
||||
public function update(ProfileUpdateRequest $request): RedirectResponse
|
||||
{
|
||||
$request->user()->fill($request->validated());
|
||||
|
||||
if ($request->user()->isDirty('email')) {
|
||||
$request->user()->email_verified_at = null;
|
||||
}
|
||||
|
||||
$request->user()->save();
|
||||
|
||||
return Redirect::route('profile.edit')->with('status', 'profile-updated');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the user's account.
|
||||
*/
|
||||
public function destroy(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validateWithBag('userDeletion', [
|
||||
'password' => ['required', 'current_password'],
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
|
||||
Auth::logout();
|
||||
|
||||
$user->delete();
|
||||
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return Redirect::to('/');
|
||||
}
|
||||
}
|
||||
69
app/Http/Kernel.php
Normal file
69
app/Http/Kernel.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
/**
|
||||
* The application's global HTTP middleware stack.
|
||||
*
|
||||
* These middleware are run during every request to your application.
|
||||
*
|
||||
* @var array<int, class-string|string>
|
||||
*/
|
||||
protected $middleware = [
|
||||
// \App\Http\Middleware\TrustHosts::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\Illuminate\Http\Middleware\HandleCors::class,
|
||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware groups.
|
||||
*
|
||||
* @var array<string, array<int, class-string|string>>
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
|
||||
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's middleware aliases.
|
||||
*
|
||||
* Aliases may be used instead of class names to conveniently assign middleware to routes and groups.
|
||||
*
|
||||
* @var array<string, class-string|string>
|
||||
*/
|
||||
protected $middlewareAliases = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||
'precognitive' => \Illuminate\Foundation\Http\Middleware\HandlePrecognitiveRequests::class,
|
||||
'role' => \App\Http\Middleware\RoleMiddleware::class,
|
||||
'signed' => \App\Http\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
];
|
||||
}
|
||||
17
app/Http/Middleware/Authenticate.php
Normal file
17
app/Http/Middleware/Authenticate.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*/
|
||||
protected function redirectTo(Request $request): ?string
|
||||
{
|
||||
return $request->expectsJson() ? null : '/admin/signin';
|
||||
}
|
||||
}
|
||||
17
app/Http/Middleware/EncryptCookies.php
Normal file
17
app/Http/Middleware/EncryptCookies.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
17
app/Http/Middleware/PreventRequestsDuringMaintenance.php
Normal file
17
app/Http/Middleware/PreventRequestsDuringMaintenance.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
|
||||
|
||||
class PreventRequestsDuringMaintenance extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be reachable while maintenance mode is enabled.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
30
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
30
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, string ...$guards): Response
|
||||
{
|
||||
$guards = empty($guards) ? [null] : $guards;
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
34
app/Http/Middleware/RoleMiddleware.php
Normal file
34
app/Http/Middleware/RoleMiddleware.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RoleMiddleware
|
||||
{
|
||||
/**
|
||||
* Allow access for specific roles. Admin is always allowed.
|
||||
*
|
||||
* Usage: ->middleware('role:admin,kasir')
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, ...$roles): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
$role = $user?->role ?: 'admin';
|
||||
|
||||
if ($role === 'admin') {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if (empty($roles) || !in_array($role, $roles, true)) {
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json(['message' => 'Akses ditolak.'], 403);
|
||||
}
|
||||
abort(403, 'Akses ditolak.');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
19
app/Http/Middleware/TrimStrings.php
Normal file
19
app/Http/Middleware/TrimStrings.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||
|
||||
class TrimStrings extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
||||
20
app/Http/Middleware/TrustHosts.php
Normal file
20
app/Http/Middleware/TrustHosts.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustHosts as Middleware;
|
||||
|
||||
class TrustHosts extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the host patterns that should be trusted.
|
||||
*
|
||||
* @return array<int, string|null>
|
||||
*/
|
||||
public function hosts(): array
|
||||
{
|
||||
return [
|
||||
$this->allSubdomainsOfApplicationUrl(),
|
||||
];
|
||||
}
|
||||
}
|
||||
28
app/Http/Middleware/TrustProxies.php
Normal file
28
app/Http/Middleware/TrustProxies.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The trusted proxies for this application.
|
||||
*
|
||||
* @var array<int, string>|string|null
|
||||
*/
|
||||
protected $proxies;
|
||||
|
||||
/**
|
||||
* The headers that should be used to detect proxies.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $headers =
|
||||
Request::HEADER_X_FORWARDED_FOR |
|
||||
Request::HEADER_X_FORWARDED_HOST |
|
||||
Request::HEADER_X_FORWARDED_PORT |
|
||||
Request::HEADER_X_FORWARDED_PROTO |
|
||||
Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||
}
|
||||
22
app/Http/Middleware/ValidateSignature.php
Normal file
22
app/Http/Middleware/ValidateSignature.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Routing\Middleware\ValidateSignature as Middleware;
|
||||
|
||||
class ValidateSignature extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the query string parameters that should be ignored.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
// 'fbclid',
|
||||
// 'utm_campaign',
|
||||
// 'utm_content',
|
||||
// 'utm_medium',
|
||||
// 'utm_source',
|
||||
// 'utm_term',
|
||||
];
|
||||
}
|
||||
17
app/Http/Middleware/VerifyCsrfToken.php
Normal file
17
app/Http/Middleware/VerifyCsrfToken.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
85
app/Http/Requests/Auth/LoginRequest.php
Normal file
85
app/Http/Requests/Auth/LoginRequest.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Auth;
|
||||
|
||||
use Illuminate\Auth\Events\Lockout;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class LoginRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'nip' => ['required', 'string'],
|
||||
'password' => ['required', 'string'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to authenticate the request's credentials.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function authenticate(): void
|
||||
{
|
||||
$this->ensureIsNotRateLimited();
|
||||
|
||||
if (! Auth::attempt($this->only('nip', 'password'), $this->boolean('remember'))) {
|
||||
RateLimiter::hit($this->throttleKey());
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'nip' => trans('auth.failed'),
|
||||
]);
|
||||
}
|
||||
|
||||
RateLimiter::clear($this->throttleKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the login request is not rate limited.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function ensureIsNotRateLimited(): void
|
||||
{
|
||||
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event(new Lockout($this));
|
||||
|
||||
$seconds = RateLimiter::availableIn($this->throttleKey());
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'nip' => trans('auth.throttle', [
|
||||
'seconds' => $seconds,
|
||||
'minutes' => ceil($seconds / 60),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rate limiting throttle key for the request.
|
||||
*/
|
||||
public function throttleKey(): string
|
||||
{
|
||||
return Str::transliterate(Str::lower($this->string('nip')).'|'.$this->ip());
|
||||
}
|
||||
}
|
||||
23
app/Http/Requests/ProfileUpdateRequest.php
Normal file
23
app/Http/Requests/ProfileUpdateRequest.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class ProfileUpdateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', Rule::unique(User::class)->ignore($this->user()->id)],
|
||||
];
|
||||
}
|
||||
}
|
||||
16
app/Models/Distributor.php
Normal file
16
app/Models/Distributor.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Distributor extends Model
|
||||
{
|
||||
protected $table = 'distributors';
|
||||
|
||||
protected $fillable = [
|
||||
'nama',
|
||||
'alamat',
|
||||
'telepon',
|
||||
];
|
||||
}
|
||||
15
app/Models/Lokasi.php
Normal file
15
app/Models/Lokasi.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Lokasi extends Model
|
||||
{
|
||||
protected $table = 'lokasi';
|
||||
|
||||
protected $fillable = [
|
||||
'kode',
|
||||
'nama'
|
||||
];
|
||||
}
|
||||
25
app/Models/Pegawai.php
Normal file
25
app/Models/Pegawai.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Pegawai extends Model
|
||||
{
|
||||
protected $table = 'pegawai';
|
||||
|
||||
protected $fillable = [
|
||||
'nip',
|
||||
'nama',
|
||||
'jabatan',
|
||||
'telepon',
|
||||
'alamat',
|
||||
'tempat_lahir',
|
||||
'tanggal_lahir',
|
||||
'jenis_kelamin',
|
||||
'kota',
|
||||
'nik',
|
||||
'foto',
|
||||
'is_aktif',
|
||||
];
|
||||
}
|
||||
51
app/Models/PenerimaanBarang.php
Normal file
51
app/Models/PenerimaanBarang.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class PenerimaanBarang extends Model
|
||||
{
|
||||
protected $table = 'penerimaan_barang';
|
||||
|
||||
protected $fillable = [
|
||||
'nomor_penerimaan',
|
||||
'no_faktur',
|
||||
'tanggal_faktur',
|
||||
'tanggal_datang',
|
||||
'distributor_id',
|
||||
'lokasi_id',
|
||||
'user_id',
|
||||
'status',
|
||||
'catatan',
|
||||
'applied_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'tanggal_faktur' => 'date',
|
||||
'tanggal_datang' => 'date',
|
||||
'applied_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(PenerimaanBarangItem::class, 'penerimaan_id');
|
||||
}
|
||||
|
||||
public function distributor(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Distributor::class, 'distributor_id');
|
||||
}
|
||||
|
||||
public function lokasi(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Lokasi::class, 'lokasi_id');
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
32
app/Models/PenerimaanBarangItem.php
Normal file
32
app/Models/PenerimaanBarangItem.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class PenerimaanBarangItem extends Model
|
||||
{
|
||||
protected $table = 'penerimaan_barang_items';
|
||||
|
||||
protected $fillable = [
|
||||
'penerimaan_id',
|
||||
'produk_id',
|
||||
'unit_id',
|
||||
'qty',
|
||||
'qty_input',
|
||||
'harga',
|
||||
'unit',
|
||||
'multiplier',
|
||||
];
|
||||
|
||||
public function penerimaan(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PenerimaanBarang::class, 'penerimaan_id');
|
||||
}
|
||||
|
||||
public function produk(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Produk::class, 'produk_id');
|
||||
}
|
||||
}
|
||||
39
app/Models/Penjualan.php
Normal file
39
app/Models/Penjualan.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\User;
|
||||
|
||||
class Penjualan extends Model
|
||||
{
|
||||
protected $table = 'penjualan';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'nomor_penjualan',
|
||||
'waktu',
|
||||
'subtotal',
|
||||
'diskon',
|
||||
'pajak',
|
||||
'total',
|
||||
'metode_pembayaran',
|
||||
'status_pembayaran',
|
||||
'voucher_kode',
|
||||
'voucher_amount',
|
||||
'unit_piutang',
|
||||
'jumlah_bayar',
|
||||
'kembalian',
|
||||
'sisa_piutang',
|
||||
];
|
||||
|
||||
public function barang()
|
||||
{
|
||||
return $this->hasMany(PenjualanBarang::class, 'penjualan_id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
24
app/Models/PenjualanBarang.php
Normal file
24
app/Models/PenjualanBarang.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\Produk;
|
||||
|
||||
class PenjualanBarang extends Model
|
||||
{
|
||||
protected $table = 'penjualan_barang';
|
||||
|
||||
protected $fillable = [
|
||||
'penjualan_id',
|
||||
'produk_id',
|
||||
'jumlah',
|
||||
'harga',
|
||||
'total'
|
||||
];
|
||||
|
||||
public function produk()
|
||||
{
|
||||
return $this->belongsTo(Produk::class, 'produk_id');
|
||||
}
|
||||
}
|
||||
40
app/Models/PergerakanStok.php
Normal file
40
app/Models/PergerakanStok.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PergerakanStok extends Model
|
||||
{
|
||||
protected $table = 'pergerakan_stok';
|
||||
|
||||
protected $fillable = [
|
||||
'waktu',
|
||||
'produk_id',
|
||||
'dari_lokasi_id',
|
||||
'ke_lokasi_id',
|
||||
'jenis',
|
||||
'jumlah',
|
||||
'unit',
|
||||
'qty_input',
|
||||
'multiplier',
|
||||
'catatan',
|
||||
'referensi_tipe',
|
||||
'referensi_id'
|
||||
];
|
||||
|
||||
public function produk()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Produk::class, 'produk_id');
|
||||
}
|
||||
|
||||
public function dariLokasi()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Lokasi::class, 'dari_lokasi_id');
|
||||
}
|
||||
|
||||
public function keLokasi()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Lokasi::class, 'ke_lokasi_id');
|
||||
}
|
||||
}
|
||||
20
app/Models/PiutangPayment.php
Normal file
20
app/Models/PiutangPayment.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PiutangPayment extends Model
|
||||
{
|
||||
protected $table = 'piutang_payments';
|
||||
|
||||
protected $fillable = [
|
||||
'penjualan_id',
|
||||
'jumlah',
|
||||
'metode',
|
||||
'catatan',
|
||||
'user_id',
|
||||
'sisa_before',
|
||||
'sisa_after',
|
||||
];
|
||||
}
|
||||
22
app/Models/ProductUnit.php
Normal file
22
app/Models/ProductUnit.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProductUnit extends Model
|
||||
{
|
||||
protected $table = 'produk_unit';
|
||||
|
||||
protected $fillable = [
|
||||
'produk_id',
|
||||
'nama_unit',
|
||||
'multiplier',
|
||||
'is_base',
|
||||
];
|
||||
|
||||
public function produk()
|
||||
{
|
||||
return $this->belongsTo(Produk::class);
|
||||
}
|
||||
}
|
||||
27
app/Models/Produk.php
Normal file
27
app/Models/Produk.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\ProductUnit;
|
||||
|
||||
class Produk extends Model
|
||||
{
|
||||
protected $table = 'produk';
|
||||
|
||||
protected $fillable = [
|
||||
'sku',
|
||||
'nama',
|
||||
'barcode',
|
||||
'harga_beli',
|
||||
'harga_jual',
|
||||
'is_aktif',
|
||||
];
|
||||
|
||||
public function units() {
|
||||
return $this->hasMany(ProductUnit::class, 'produk_id');
|
||||
}
|
||||
public function baseUnit() {
|
||||
return $this->hasOne(ProductUnit::class, 'produk_id')->where('is_base', true);
|
||||
}
|
||||
}
|
||||
15
app/Models/Setting.php
Normal file
15
app/Models/Setting.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
protected $table = 'settings';
|
||||
|
||||
protected $fillable = [
|
||||
'key',
|
||||
'value',
|
||||
];
|
||||
}
|
||||
62
app/Models/User.php
Normal file
62
app/Models/User.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
'role',
|
||||
'nip',
|
||||
'pegawai_id',
|
||||
];
|
||||
|
||||
public const ROLE_ADMIN = 'admin';
|
||||
public const ROLE_KASIR = 'kasir';
|
||||
public const ROLE_GUDANG = 'gudang';
|
||||
|
||||
public function isAdmin(): bool
|
||||
{
|
||||
return $this->role === self::ROLE_ADMIN;
|
||||
}
|
||||
|
||||
public function pegawai()
|
||||
{
|
||||
return $this->belongsTo(Pegawai::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
25
app/Models/Voucher.php
Normal file
25
app/Models/Voucher.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Voucher extends Model
|
||||
{
|
||||
protected $table = 'vouchers';
|
||||
|
||||
protected $fillable = [
|
||||
'pegawai_id',
|
||||
'kode',
|
||||
'saldo',
|
||||
'aktif',
|
||||
'catatan',
|
||||
'created_by',
|
||||
];
|
||||
|
||||
public function pegawai(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Pegawai::class, 'pegawai_id');
|
||||
}
|
||||
}
|
||||
22
app/Models/VoucherHistory.php
Normal file
22
app/Models/VoucherHistory.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class VoucherHistory extends Model
|
||||
{
|
||||
protected $table = 'voucher_histories';
|
||||
|
||||
protected $fillable = [
|
||||
'voucher_id',
|
||||
'kode',
|
||||
'tipe',
|
||||
'jumlah',
|
||||
'saldo_before',
|
||||
'saldo_after',
|
||||
'penjualan_id',
|
||||
'user_id',
|
||||
'catatan',
|
||||
];
|
||||
}
|
||||
24
app/Providers/AppServiceProvider.php
Normal file
24
app/Providers/AppServiceProvider.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
26
app/Providers/AuthServiceProvider.php
Normal file
26
app/Providers/AuthServiceProvider.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
// use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The model to policy mappings for the application.
|
||||
*
|
||||
* @var array<class-string, class-string>
|
||||
*/
|
||||
protected $policies = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any authentication / authorization services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
19
app/Providers/BroadcastServiceProvider.php
Normal file
19
app/Providers/BroadcastServiceProvider.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Broadcast;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class BroadcastServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
Broadcast::routes();
|
||||
|
||||
require base_path('routes/channels.php');
|
||||
}
|
||||
}
|
||||
38
app/Providers/EventServiceProvider.php
Normal file
38
app/Providers/EventServiceProvider.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event to listener mappings for the application.
|
||||
*
|
||||
* @var array<class-string, array<int, class-string>>
|
||||
*/
|
||||
protected $listen = [
|
||||
Registered::class => [
|
||||
SendEmailVerificationNotification::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if events and listeners should be automatically discovered.
|
||||
*/
|
||||
public function shouldDiscoverEvents(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
41
app/Providers/RouteServiceProvider.php
Normal file
41
app/Providers/RouteServiceProvider.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The path to your application's "home" route.
|
||||
*
|
||||
* Typically, users are redirected here after authentication.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
// Setelah login arahkan ke halaman admin (React)
|
||||
public const HOME = '/admin';
|
||||
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, and other route configuration.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
RateLimiter::for('api', function (Request $request) {
|
||||
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
|
||||
});
|
||||
|
||||
$this->routes(function () {
|
||||
Route::middleware('api')
|
||||
->prefix('api')
|
||||
->group(base_path('routes/api.php'));
|
||||
|
||||
Route::middleware('web')
|
||||
->group(base_path('routes/web.php'));
|
||||
});
|
||||
}
|
||||
}
|
||||
17
app/View/Components/AppLayout.php
Normal file
17
app/View/Components/AppLayout.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\View\Component;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class AppLayout extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represents the component.
|
||||
*/
|
||||
public function render(): View
|
||||
{
|
||||
return view('layouts.app');
|
||||
}
|
||||
}
|
||||
17
app/View/Components/GuestLayout.php
Normal file
17
app/View/Components/GuestLayout.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\View\Component;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class GuestLayout extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represents the component.
|
||||
*/
|
||||
public function render(): View
|
||||
{
|
||||
return view('layouts.guest');
|
||||
}
|
||||
}
|
||||
53
artisan
Normal file
53
artisan
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
define('LARAVEL_START', microtime(true));
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register The Auto Loader
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Composer provides a convenient, automatically generated class loader
|
||||
| for our application. We just need to utilize it! We'll require it
|
||||
| into the script here so that we do not have to worry about the
|
||||
| loading of any of our classes manually. It's great to relax.
|
||||
|
|
||||
*/
|
||||
|
||||
require __DIR__.'/vendor/autoload.php';
|
||||
|
||||
$app = require_once __DIR__.'/bootstrap/app.php';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Run The Artisan Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When we run the console application, the current CLI command will be
|
||||
| executed in this console and the response sent back to a terminal
|
||||
| or another output device for the developers. Here goes nothing!
|
||||
|
|
||||
*/
|
||||
|
||||
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
|
||||
|
||||
$status = $kernel->handle(
|
||||
$input = new Symfony\Component\Console\Input\ArgvInput,
|
||||
new Symfony\Component\Console\Output\ConsoleOutput
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Shutdown The Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Once Artisan has finished running, we will fire off the shutdown events
|
||||
| so that any final work may be done by the application before we shut
|
||||
| down the process. This is the last thing to happen to the request.
|
||||
|
|
||||
*/
|
||||
|
||||
$kernel->terminate($input, $status);
|
||||
|
||||
exit($status);
|
||||
55
bootstrap/app.php
Normal file
55
bootstrap/app.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Create The Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The first thing we will do is create a new Laravel application instance
|
||||
| which serves as the "glue" for all the components of Laravel, and is
|
||||
| the IoC container for the system binding all of the various parts.
|
||||
|
|
||||
*/
|
||||
|
||||
$app = new Illuminate\Foundation\Application(
|
||||
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Bind Important Interfaces
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Next, we need to bind some important interfaces into the container so
|
||||
| we will be able to resolve them when needed. The kernels serve the
|
||||
| incoming requests to this application from both the web and CLI.
|
||||
|
|
||||
*/
|
||||
|
||||
$app->singleton(
|
||||
Illuminate\Contracts\Http\Kernel::class,
|
||||
App\Http\Kernel::class
|
||||
);
|
||||
|
||||
$app->singleton(
|
||||
Illuminate\Contracts\Console\Kernel::class,
|
||||
App\Console\Kernel::class
|
||||
);
|
||||
|
||||
$app->singleton(
|
||||
Illuminate\Contracts\Debug\ExceptionHandler::class,
|
||||
App\Exceptions\Handler::class
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Return The Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This script returns the application instance. The instance is given to
|
||||
| the calling script so we can separate the building of the instances
|
||||
| from the actual running of the application and sending responses.
|
||||
|
|
||||
*/
|
||||
|
||||
return $app;
|
||||
2
bootstrap/cache/.gitignore
vendored
Normal file
2
bootstrap/cache/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
67
composer.json
Normal file
67
composer.json
Normal file
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"name": "laravel/laravel",
|
||||
"type": "project",
|
||||
"description": "The skeleton application for the Laravel framework.",
|
||||
"keywords": ["laravel", "framework"],
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": "^8.1",
|
||||
"guzzlehttp/guzzle": "^7.2",
|
||||
"laravel/framework": "^10.10",
|
||||
"laravel/sanctum": "^3.3",
|
||||
"laravel/tinker": "^2.8"
|
||||
},
|
||||
"require-dev": {
|
||||
"fakerphp/faker": "^1.9.1",
|
||||
"laravel/breeze": "^1.29",
|
||||
"laravel/pint": "^1.0",
|
||||
"laravel/sail": "^1.18",
|
||||
"mockery/mockery": "^1.4.4",
|
||||
"nunomaduro/collision": "^7.0",
|
||||
"phpunit/phpunit": "^10.1",
|
||||
"spatie/laravel-ignition": "^2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "app/",
|
||||
"Database\\Factories\\": "database/factories/",
|
||||
"Database\\Seeders\\": "database/seeders/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"post-autoload-dump": [
|
||||
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
|
||||
"@php artisan package:discover --ansi"
|
||||
],
|
||||
"post-update-cmd": [
|
||||
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
|
||||
],
|
||||
"post-root-package-install": [
|
||||
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
|
||||
],
|
||||
"post-create-project-cmd": [
|
||||
"@php artisan key:generate --ansi"
|
||||
]
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"dont-discover": []
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
"preferred-install": "dist",
|
||||
"sort-packages": true,
|
||||
"allow-plugins": {
|
||||
"pestphp/pest-plugin": true,
|
||||
"php-http/discovery": true
|
||||
}
|
||||
},
|
||||
"minimum-stability": "stable",
|
||||
"prefer-stable": true
|
||||
}
|
||||
8268
composer.lock
generated
Normal file
8268
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
188
config/app.php
Normal file
188
config/app.php
Normal file
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value is the name of your application. This value is used when the
|
||||
| framework needs to place the application's name in a notification or
|
||||
| any other location as required by the application or its packages.
|
||||
|
|
||||
*/
|
||||
|
||||
'name' => env('APP_NAME', 'Laravel'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Environment
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value determines the "environment" your application is currently
|
||||
| running in. This may determine how you prefer to configure various
|
||||
| services the application utilizes. Set this in your ".env" file.
|
||||
|
|
||||
*/
|
||||
|
||||
'env' => env('APP_ENV', 'production'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Debug Mode
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When your application is in debug mode, detailed error messages with
|
||||
| stack traces will be shown on every error that occurs within your
|
||||
| application. If disabled, a simple generic error page is shown.
|
||||
|
|
||||
*/
|
||||
|
||||
'debug' => (bool) env('APP_DEBUG', false),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application URL
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This URL is used by the console to properly generate URLs when using
|
||||
| the Artisan command line tool. You should set this to the root of
|
||||
| your application so that it is used when running Artisan tasks.
|
||||
|
|
||||
*/
|
||||
|
||||
'url' => env('APP_URL', 'http://localhost'),
|
||||
|
||||
'asset_url' => env('ASSET_URL'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Timezone
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the default timezone for your application, which
|
||||
| will be used by the PHP date and date-time functions. We have gone
|
||||
| ahead and set this to a sensible default for you out of the box.
|
||||
|
|
||||
*/
|
||||
|
||||
'timezone' => 'UTC',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Locale Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The application locale determines the default locale that will be used
|
||||
| by the translation service provider. You are free to set this value
|
||||
| to any of the locales which will be supported by the application.
|
||||
|
|
||||
*/
|
||||
|
||||
'locale' => 'en',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Fallback Locale
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The fallback locale determines the locale to use when the current one
|
||||
| is not available. You may change the value to correspond to any of
|
||||
| the language folders that are provided through your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'fallback_locale' => 'en',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Faker Locale
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This locale will be used by the Faker PHP library when generating fake
|
||||
| data for your database seeds. For example, this will be used to get
|
||||
| localized telephone numbers, street address information and more.
|
||||
|
|
||||
*/
|
||||
|
||||
'faker_locale' => 'en_US',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Encryption Key
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This key is used by the Illuminate encrypter service and should be set
|
||||
| to a random, 32 character string, otherwise these encrypted strings
|
||||
| will not be safe. Please do this before deploying an application!
|
||||
|
|
||||
*/
|
||||
|
||||
'key' => env('APP_KEY'),
|
||||
|
||||
'cipher' => 'AES-256-CBC',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Maintenance Mode Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These configuration options determine the driver used to determine and
|
||||
| manage Laravel's "maintenance mode" status. The "cache" driver will
|
||||
| allow maintenance mode to be controlled across multiple machines.
|
||||
|
|
||||
| Supported drivers: "file", "cache"
|
||||
|
|
||||
*/
|
||||
|
||||
'maintenance' => [
|
||||
'driver' => 'file',
|
||||
// 'store' => 'redis',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Autoloaded Service Providers
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The service providers listed here will be automatically loaded on the
|
||||
| request to your application. Feel free to add your own services to
|
||||
| this array to grant expanded functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
'providers' => ServiceProvider::defaultProviders()->merge([
|
||||
/*
|
||||
* Package Service Providers...
|
||||
*/
|
||||
|
||||
/*
|
||||
* Application Service Providers...
|
||||
*/
|
||||
App\Providers\AppServiceProvider::class,
|
||||
App\Providers\AuthServiceProvider::class,
|
||||
// App\Providers\BroadcastServiceProvider::class,
|
||||
App\Providers\EventServiceProvider::class,
|
||||
App\Providers\RouteServiceProvider::class,
|
||||
])->toArray(),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Class Aliases
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This array of class aliases will be registered when this application
|
||||
| is started. However, feel free to register as many as you wish as
|
||||
| the aliases are "lazy" loaded so they don't hinder performance.
|
||||
|
|
||||
*/
|
||||
|
||||
'aliases' => Facade::defaultAliases()->merge([
|
||||
// 'Example' => App\Facades\Example::class,
|
||||
])->toArray(),
|
||||
|
||||
];
|
||||
115
config/auth.php
Normal file
115
config/auth.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Defaults
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default authentication "guard" and password
|
||||
| reset options for your application. You may change these defaults
|
||||
| as required, but they're a perfect start for most applications.
|
||||
|
|
||||
*/
|
||||
|
||||
'defaults' => [
|
||||
'guard' => 'web',
|
||||
'passwords' => 'users',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Guards
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Next, you may define every authentication guard for your application.
|
||||
| Of course, a great default configuration has been defined for you
|
||||
| here which uses session storage and the Eloquent user provider.
|
||||
|
|
||||
| All authentication drivers have a user provider. This defines how the
|
||||
| users are actually retrieved out of your database or other storage
|
||||
| mechanisms used by this application to persist your user's data.
|
||||
|
|
||||
| Supported: "session"
|
||||
|
|
||||
*/
|
||||
|
||||
'guards' => [
|
||||
'web' => [
|
||||
'driver' => 'session',
|
||||
'provider' => 'users',
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| User Providers
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| All authentication drivers have a user provider. This defines how the
|
||||
| users are actually retrieved out of your database or other storage
|
||||
| mechanisms used by this application to persist your user's data.
|
||||
|
|
||||
| If you have multiple user tables or models you may configure multiple
|
||||
| sources which represent each model / table. These sources may then
|
||||
| be assigned to any extra authentication guards you have defined.
|
||||
|
|
||||
| Supported: "database", "eloquent"
|
||||
|
|
||||
*/
|
||||
|
||||
'providers' => [
|
||||
'users' => [
|
||||
'driver' => 'eloquent',
|
||||
'model' => App\Models\User::class,
|
||||
],
|
||||
|
||||
// 'users' => [
|
||||
// 'driver' => 'database',
|
||||
// 'table' => 'users',
|
||||
// ],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Resetting Passwords
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| You may specify multiple password reset configurations if you have more
|
||||
| than one user table or model in the application and you want to have
|
||||
| separate password reset settings based on the specific user types.
|
||||
|
|
||||
| The expiry time is the number of minutes that each reset token will be
|
||||
| considered valid. This security feature keeps tokens short-lived so
|
||||
| they have less time to be guessed. You may change this as needed.
|
||||
|
|
||||
| The throttle setting is the number of seconds a user must wait before
|
||||
| generating more password reset tokens. This prevents the user from
|
||||
| quickly generating a very large amount of password reset tokens.
|
||||
|
|
||||
*/
|
||||
|
||||
'passwords' => [
|
||||
'users' => [
|
||||
'provider' => 'users',
|
||||
'table' => 'password_reset_tokens',
|
||||
'expire' => 60,
|
||||
'throttle' => 60,
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Confirmation Timeout
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define the amount of seconds before a password confirmation
|
||||
| times out and the user is prompted to re-enter their password via the
|
||||
| confirmation screen. By default, the timeout lasts for three hours.
|
||||
|
|
||||
*/
|
||||
|
||||
'password_timeout' => 10800,
|
||||
|
||||
];
|
||||
71
config/broadcasting.php
Normal file
71
config/broadcasting.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Broadcaster
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default broadcaster that will be used by the
|
||||
| framework when an event needs to be broadcast. You may set this to
|
||||
| any of the connections defined in the "connections" array below.
|
||||
|
|
||||
| Supported: "pusher", "ably", "redis", "log", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('BROADCAST_DRIVER', 'null'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Broadcast Connections
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define all of the broadcast connections that will be used
|
||||
| to broadcast events to other systems or over websockets. Samples of
|
||||
| each available type of connection are provided inside this array.
|
||||
|
|
||||
*/
|
||||
|
||||
'connections' => [
|
||||
|
||||
'pusher' => [
|
||||
'driver' => 'pusher',
|
||||
'key' => env('PUSHER_APP_KEY'),
|
||||
'secret' => env('PUSHER_APP_SECRET'),
|
||||
'app_id' => env('PUSHER_APP_ID'),
|
||||
'options' => [
|
||||
'cluster' => env('PUSHER_APP_CLUSTER'),
|
||||
'host' => env('PUSHER_HOST') ?: 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com',
|
||||
'port' => env('PUSHER_PORT', 443),
|
||||
'scheme' => env('PUSHER_SCHEME', 'https'),
|
||||
'encrypted' => true,
|
||||
'useTLS' => env('PUSHER_SCHEME', 'https') === 'https',
|
||||
],
|
||||
'client_options' => [
|
||||
// Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
|
||||
],
|
||||
],
|
||||
|
||||
'ably' => [
|
||||
'driver' => 'ably',
|
||||
'key' => env('ABLY_KEY'),
|
||||
],
|
||||
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'connection' => 'default',
|
||||
],
|
||||
|
||||
'log' => [
|
||||
'driver' => 'log',
|
||||
],
|
||||
|
||||
'null' => [
|
||||
'driver' => 'null',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
111
config/cache.php
Normal file
111
config/cache.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Cache Store
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default cache connection that gets used while
|
||||
| using this caching library. This connection is used when another is
|
||||
| not explicitly specified when executing a given caching function.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('CACHE_DRIVER', 'file'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache Stores
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define all of the cache "stores" for your application as
|
||||
| well as their drivers. You may even define multiple stores for the
|
||||
| same cache driver to group types of items stored in your caches.
|
||||
|
|
||||
| Supported drivers: "apc", "array", "database", "file",
|
||||
| "memcached", "redis", "dynamodb", "octane", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'stores' => [
|
||||
|
||||
'apc' => [
|
||||
'driver' => 'apc',
|
||||
],
|
||||
|
||||
'array' => [
|
||||
'driver' => 'array',
|
||||
'serialize' => false,
|
||||
],
|
||||
|
||||
'database' => [
|
||||
'driver' => 'database',
|
||||
'table' => 'cache',
|
||||
'connection' => null,
|
||||
'lock_connection' => null,
|
||||
],
|
||||
|
||||
'file' => [
|
||||
'driver' => 'file',
|
||||
'path' => storage_path('framework/cache/data'),
|
||||
'lock_path' => storage_path('framework/cache/data'),
|
||||
],
|
||||
|
||||
'memcached' => [
|
||||
'driver' => 'memcached',
|
||||
'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
|
||||
'sasl' => [
|
||||
env('MEMCACHED_USERNAME'),
|
||||
env('MEMCACHED_PASSWORD'),
|
||||
],
|
||||
'options' => [
|
||||
// Memcached::OPT_CONNECT_TIMEOUT => 2000,
|
||||
],
|
||||
'servers' => [
|
||||
[
|
||||
'host' => env('MEMCACHED_HOST', '127.0.0.1'),
|
||||
'port' => env('MEMCACHED_PORT', 11211),
|
||||
'weight' => 100,
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'connection' => 'cache',
|
||||
'lock_connection' => 'default',
|
||||
],
|
||||
|
||||
'dynamodb' => [
|
||||
'driver' => 'dynamodb',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
'table' => env('DYNAMODB_CACHE_TABLE', 'cache'),
|
||||
'endpoint' => env('DYNAMODB_ENDPOINT'),
|
||||
],
|
||||
|
||||
'octane' => [
|
||||
'driver' => 'octane',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache Key Prefix
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When utilizing the APC, database, memcached, Redis, or DynamoDB cache
|
||||
| stores there might be other applications using the same cache. For
|
||||
| that reason, you may prefix every cache key to avoid collisions.
|
||||
|
|
||||
*/
|
||||
|
||||
'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache_'),
|
||||
|
||||
];
|
||||
34
config/cors.php
Normal file
34
config/cors.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cross-Origin Resource Sharing (CORS) Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure your settings for cross-origin resource sharing
|
||||
| or "CORS". This determines what cross-origin operations may execute
|
||||
| in web browsers. You are free to adjust these settings as needed.
|
||||
|
|
||||
| To learn more: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
||||
|
|
||||
*/
|
||||
|
||||
'paths' => ['api/*', 'sanctum/csrf-cookie'],
|
||||
|
||||
'allowed_methods' => ['*'],
|
||||
|
||||
'allowed_origins' => ['*'],
|
||||
|
||||
'allowed_origins_patterns' => [],
|
||||
|
||||
'allowed_headers' => ['*'],
|
||||
|
||||
'exposed_headers' => [],
|
||||
|
||||
'max_age' => 0,
|
||||
|
||||
'supports_credentials' => false,
|
||||
|
||||
];
|
||||
151
config/database.php
Normal file
151
config/database.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Database Connection Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify which of the database connections below you wish
|
||||
| to use as your default connection for all database work. Of course
|
||||
| you may use many connections at once using the Database library.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('DB_CONNECTION', 'mysql'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Database Connections
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here are each of the database connections setup for your application.
|
||||
| Of course, examples of configuring each database platform that is
|
||||
| supported by Laravel is shown below to make development simple.
|
||||
|
|
||||
|
|
||||
| All database work in Laravel is done through the PHP PDO facilities
|
||||
| so make sure you have the driver for your particular database of
|
||||
| choice installed on your machine before you begin development.
|
||||
|
|
||||
*/
|
||||
|
||||
'connections' => [
|
||||
|
||||
'sqlite' => [
|
||||
'driver' => 'sqlite',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'database' => env('DB_DATABASE', database_path('database.sqlite')),
|
||||
'prefix' => '',
|
||||
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
|
||||
],
|
||||
|
||||
'mysql' => [
|
||||
'driver' => 'mysql',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
'port' => env('DB_PORT', '3306'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'unix_socket' => env('DB_SOCKET', ''),
|
||||
'charset' => 'utf8mb4',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
'strict' => true,
|
||||
'engine' => null,
|
||||
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
||||
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
|
||||
]) : [],
|
||||
],
|
||||
|
||||
'pgsql' => [
|
||||
'driver' => 'pgsql',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
'port' => env('DB_PORT', '5432'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => 'utf8',
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
'search_path' => 'public',
|
||||
'sslmode' => 'prefer',
|
||||
],
|
||||
|
||||
'sqlsrv' => [
|
||||
'driver' => 'sqlsrv',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'host' => env('DB_HOST', 'localhost'),
|
||||
'port' => env('DB_PORT', '1433'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => 'utf8',
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
// 'encrypt' => env('DB_ENCRYPT', 'yes'),
|
||||
// 'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'),
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Migration Repository Table
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This table keeps track of all the migrations that have already run for
|
||||
| your application. Using this information, we can determine which of
|
||||
| the migrations on disk haven't actually been run in the database.
|
||||
|
|
||||
*/
|
||||
|
||||
'migrations' => 'migrations',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Redis Databases
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Redis is an open source, fast, and advanced key-value store that also
|
||||
| provides a richer body of commands than a typical key-value system
|
||||
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
||||
|
|
||||
*/
|
||||
|
||||
'redis' => [
|
||||
|
||||
'client' => env('REDIS_CLIENT', 'phpredis'),
|
||||
|
||||
'options' => [
|
||||
'cluster' => env('REDIS_CLUSTER', 'redis'),
|
||||
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
|
||||
],
|
||||
|
||||
'default' => [
|
||||
'url' => env('REDIS_URL'),
|
||||
'host' => env('REDIS_HOST', '127.0.0.1'),
|
||||
'username' => env('REDIS_USERNAME'),
|
||||
'password' => env('REDIS_PASSWORD'),
|
||||
'port' => env('REDIS_PORT', '6379'),
|
||||
'database' => env('REDIS_DB', '0'),
|
||||
],
|
||||
|
||||
'cache' => [
|
||||
'url' => env('REDIS_URL'),
|
||||
'host' => env('REDIS_HOST', '127.0.0.1'),
|
||||
'username' => env('REDIS_USERNAME'),
|
||||
'password' => env('REDIS_PASSWORD'),
|
||||
'port' => env('REDIS_PORT', '6379'),
|
||||
'database' => env('REDIS_CACHE_DB', '1'),
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
76
config/filesystems.php
Normal file
76
config/filesystems.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Filesystem Disk
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the default filesystem disk that should be used
|
||||
| by the framework. The "local" disk, as well as a variety of cloud
|
||||
| based disks are available to your application. Just store away!
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('FILESYSTEM_DISK', 'local'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Filesystem Disks
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure as many filesystem "disks" as you wish, and you
|
||||
| may even configure multiple disks of the same driver. Defaults have
|
||||
| been set up for each driver as an example of the required values.
|
||||
|
|
||||
| Supported Drivers: "local", "ftp", "sftp", "s3"
|
||||
|
|
||||
*/
|
||||
|
||||
'disks' => [
|
||||
|
||||
'local' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app'),
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
'public' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app/public'),
|
||||
'url' => env('APP_URL').'/storage',
|
||||
'visibility' => 'public',
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
's3' => [
|
||||
'driver' => 's3',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION'),
|
||||
'bucket' => env('AWS_BUCKET'),
|
||||
'url' => env('AWS_URL'),
|
||||
'endpoint' => env('AWS_ENDPOINT'),
|
||||
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Symbolic Links
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure the symbolic links that will be created when the
|
||||
| `storage:link` Artisan command is executed. The array keys should be
|
||||
| the locations of the links and the values should be their targets.
|
||||
|
|
||||
*/
|
||||
|
||||
'links' => [
|
||||
public_path('storage') => storage_path('app/public'),
|
||||
],
|
||||
|
||||
];
|
||||
54
config/hashing.php
Normal file
54
config/hashing.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Hash Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default hash driver that will be used to hash
|
||||
| passwords for your application. By default, the bcrypt algorithm is
|
||||
| used; however, you remain free to modify this option if you wish.
|
||||
|
|
||||
| Supported: "bcrypt", "argon", "argon2id"
|
||||
|
|
||||
*/
|
||||
|
||||
'driver' => 'bcrypt',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Bcrypt Options
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the configuration options that should be used when
|
||||
| passwords are hashed using the Bcrypt algorithm. This will allow you
|
||||
| to control the amount of time it takes to hash the given password.
|
||||
|
|
||||
*/
|
||||
|
||||
'bcrypt' => [
|
||||
'rounds' => env('BCRYPT_ROUNDS', 12),
|
||||
'verify' => true,
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Argon Options
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the configuration options that should be used when
|
||||
| passwords are hashed using the Argon algorithm. These will allow you
|
||||
| to control the amount of time it takes to hash the given password.
|
||||
|
|
||||
*/
|
||||
|
||||
'argon' => [
|
||||
'memory' => 65536,
|
||||
'threads' => 1,
|
||||
'time' => 4,
|
||||
'verify' => true,
|
||||
],
|
||||
|
||||
];
|
||||
131
config/logging.php
Normal file
131
config/logging.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
use Monolog\Handler\NullHandler;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Handler\SyslogUdpHandler;
|
||||
use Monolog\Processor\PsrLogMessageProcessor;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Log Channel
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option defines the default log channel that gets used when writing
|
||||
| messages to the logs. The name specified in this option should match
|
||||
| one of the channels defined in the "channels" configuration array.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('LOG_CHANNEL', 'stack'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Deprecations Log Channel
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the log channel that should be used to log warnings
|
||||
| regarding deprecated PHP and library features. This allows you to get
|
||||
| your application ready for upcoming major versions of dependencies.
|
||||
|
|
||||
*/
|
||||
|
||||
'deprecations' => [
|
||||
'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'),
|
||||
'trace' => false,
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Log Channels
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure the log channels for your application. Out of
|
||||
| the box, Laravel uses the Monolog PHP logging library. This gives
|
||||
| you a variety of powerful log handlers / formatters to utilize.
|
||||
|
|
||||
| Available Drivers: "single", "daily", "slack", "syslog",
|
||||
| "errorlog", "monolog",
|
||||
| "custom", "stack"
|
||||
|
|
||||
*/
|
||||
|
||||
'channels' => [
|
||||
'stack' => [
|
||||
'driver' => 'stack',
|
||||
'channels' => ['single'],
|
||||
'ignore_exceptions' => false,
|
||||
],
|
||||
|
||||
'single' => [
|
||||
'driver' => 'single',
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'daily' => [
|
||||
'driver' => 'daily',
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'days' => 14,
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'slack' => [
|
||||
'driver' => 'slack',
|
||||
'url' => env('LOG_SLACK_WEBHOOK_URL'),
|
||||
'username' => 'Laravel Log',
|
||||
'emoji' => ':boom:',
|
||||
'level' => env('LOG_LEVEL', 'critical'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'papertrail' => [
|
||||
'driver' => 'monolog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class),
|
||||
'handler_with' => [
|
||||
'host' => env('PAPERTRAIL_URL'),
|
||||
'port' => env('PAPERTRAIL_PORT'),
|
||||
'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'),
|
||||
],
|
||||
'processors' => [PsrLogMessageProcessor::class],
|
||||
],
|
||||
|
||||
'stderr' => [
|
||||
'driver' => 'monolog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'handler' => StreamHandler::class,
|
||||
'formatter' => env('LOG_STDERR_FORMATTER'),
|
||||
'with' => [
|
||||
'stream' => 'php://stderr',
|
||||
],
|
||||
'processors' => [PsrLogMessageProcessor::class],
|
||||
],
|
||||
|
||||
'syslog' => [
|
||||
'driver' => 'syslog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'facility' => LOG_USER,
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'errorlog' => [
|
||||
'driver' => 'errorlog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'null' => [
|
||||
'driver' => 'monolog',
|
||||
'handler' => NullHandler::class,
|
||||
],
|
||||
|
||||
'emergency' => [
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
],
|
||||
],
|
||||
|
||||
];
|
||||
134
config/mail.php
Normal file
134
config/mail.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Mailer
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default mailer that is used to send any email
|
||||
| messages sent by your application. Alternative mailers may be setup
|
||||
| and used as needed; however, this mailer will be used by default.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('MAIL_MAILER', 'smtp'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Mailer Configurations
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure all of the mailers used by your application plus
|
||||
| their respective settings. Several examples have been configured for
|
||||
| you and you are free to add your own as your application requires.
|
||||
|
|
||||
| Laravel supports a variety of mail "transport" drivers to be used while
|
||||
| sending an e-mail. You will specify which one you are using for your
|
||||
| mailers below. You are free to add additional mailers as required.
|
||||
|
|
||||
| Supported: "smtp", "sendmail", "mailgun", "ses", "ses-v2",
|
||||
| "postmark", "log", "array", "failover", "roundrobin"
|
||||
|
|
||||
*/
|
||||
|
||||
'mailers' => [
|
||||
'smtp' => [
|
||||
'transport' => 'smtp',
|
||||
'url' => env('MAIL_URL'),
|
||||
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
|
||||
'port' => env('MAIL_PORT', 587),
|
||||
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
|
||||
'username' => env('MAIL_USERNAME'),
|
||||
'password' => env('MAIL_PASSWORD'),
|
||||
'timeout' => null,
|
||||
'local_domain' => env('MAIL_EHLO_DOMAIN'),
|
||||
],
|
||||
|
||||
'ses' => [
|
||||
'transport' => 'ses',
|
||||
],
|
||||
|
||||
'postmark' => [
|
||||
'transport' => 'postmark',
|
||||
// 'message_stream_id' => null,
|
||||
// 'client' => [
|
||||
// 'timeout' => 5,
|
||||
// ],
|
||||
],
|
||||
|
||||
'mailgun' => [
|
||||
'transport' => 'mailgun',
|
||||
// 'client' => [
|
||||
// 'timeout' => 5,
|
||||
// ],
|
||||
],
|
||||
|
||||
'sendmail' => [
|
||||
'transport' => 'sendmail',
|
||||
'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'),
|
||||
],
|
||||
|
||||
'log' => [
|
||||
'transport' => 'log',
|
||||
'channel' => env('MAIL_LOG_CHANNEL'),
|
||||
],
|
||||
|
||||
'array' => [
|
||||
'transport' => 'array',
|
||||
],
|
||||
|
||||
'failover' => [
|
||||
'transport' => 'failover',
|
||||
'mailers' => [
|
||||
'smtp',
|
||||
'log',
|
||||
],
|
||||
],
|
||||
|
||||
'roundrobin' => [
|
||||
'transport' => 'roundrobin',
|
||||
'mailers' => [
|
||||
'ses',
|
||||
'postmark',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Global "From" Address
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| You may wish for all e-mails sent by your application to be sent from
|
||||
| the same address. Here, you may specify a name and address that is
|
||||
| used globally for all e-mails that are sent by your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'from' => [
|
||||
'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
|
||||
'name' => env('MAIL_FROM_NAME', 'Example'),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Markdown Mail Settings
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If you are using Markdown based email rendering, you may configure your
|
||||
| theme and component paths here, allowing you to customize the design
|
||||
| of the emails. Or, you may simply stick with the Laravel defaults!
|
||||
|
|
||||
*/
|
||||
|
||||
'markdown' => [
|
||||
'theme' => 'default',
|
||||
|
||||
'paths' => [
|
||||
resource_path('views/vendor/mail'),
|
||||
],
|
||||
],
|
||||
|
||||
];
|
||||
109
config/queue.php
Normal file
109
config/queue.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Queue Connection Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Laravel's queue API supports an assortment of back-ends via a single
|
||||
| API, giving you convenient access to each back-end using the same
|
||||
| syntax for every one. Here you may define a default connection.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('QUEUE_CONNECTION', 'sync'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Queue Connections
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure the connection information for each server that
|
||||
| is used by your application. A default configuration has been added
|
||||
| for each back-end shipped with Laravel. You are free to add more.
|
||||
|
|
||||
| Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'connections' => [
|
||||
|
||||
'sync' => [
|
||||
'driver' => 'sync',
|
||||
],
|
||||
|
||||
'database' => [
|
||||
'driver' => 'database',
|
||||
'table' => 'jobs',
|
||||
'queue' => 'default',
|
||||
'retry_after' => 90,
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'beanstalkd' => [
|
||||
'driver' => 'beanstalkd',
|
||||
'host' => 'localhost',
|
||||
'queue' => 'default',
|
||||
'retry_after' => 90,
|
||||
'block_for' => 0,
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'sqs' => [
|
||||
'driver' => 'sqs',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'),
|
||||
'queue' => env('SQS_QUEUE', 'default'),
|
||||
'suffix' => env('SQS_SUFFIX'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'connection' => 'default',
|
||||
'queue' => env('REDIS_QUEUE', 'default'),
|
||||
'retry_after' => 90,
|
||||
'block_for' => null,
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Job Batching
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following options configure the database and table that store job
|
||||
| batching information. These options can be updated to any database
|
||||
| connection and table which has been defined by your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'batching' => [
|
||||
'database' => env('DB_CONNECTION', 'mysql'),
|
||||
'table' => 'job_batches',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Failed Queue Jobs
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These options configure the behavior of failed queue job logging so you
|
||||
| can control which database and table are used to store the jobs that
|
||||
| have failed. You may change them to any database / table you wish.
|
||||
|
|
||||
*/
|
||||
|
||||
'failed' => [
|
||||
'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'),
|
||||
'database' => env('DB_CONNECTION', 'mysql'),
|
||||
'table' => 'failed_jobs',
|
||||
],
|
||||
|
||||
];
|
||||
83
config/sanctum.php
Normal file
83
config/sanctum.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Stateful Domains
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Requests from the following domains / hosts will receive stateful API
|
||||
| authentication cookies. Typically, these should include your local
|
||||
| and production domains which access your API via a frontend SPA.
|
||||
|
|
||||
*/
|
||||
|
||||
'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf(
|
||||
'%s%s',
|
||||
'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1',
|
||||
Sanctum::currentApplicationUrlWithPort()
|
||||
))),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Sanctum Guards
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This array contains the authentication guards that will be checked when
|
||||
| Sanctum is trying to authenticate a request. If none of these guards
|
||||
| are able to authenticate the request, Sanctum will use the bearer
|
||||
| token that's present on an incoming request for authentication.
|
||||
|
|
||||
*/
|
||||
|
||||
'guard' => ['web'],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Expiration Minutes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value controls the number of minutes until an issued token will be
|
||||
| considered expired. This will override any values set in the token's
|
||||
| "expires_at" attribute, but first-party sessions are not affected.
|
||||
|
|
||||
*/
|
||||
|
||||
'expiration' => null,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Token Prefix
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Sanctum can prefix new tokens in order to take advantage of numerous
|
||||
| security scanning initiatives maintained by open source platforms
|
||||
| that notify developers if they commit tokens into repositories.
|
||||
|
|
||||
| See: https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning
|
||||
|
|
||||
*/
|
||||
|
||||
'token_prefix' => env('SANCTUM_TOKEN_PREFIX', ''),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Sanctum Middleware
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When authenticating your first-party SPA with Sanctum you may need to
|
||||
| customize some of the middleware Sanctum uses while processing the
|
||||
| request. You may change the middleware listed below as required.
|
||||
|
|
||||
*/
|
||||
|
||||
'middleware' => [
|
||||
'authenticate_session' => Laravel\Sanctum\Http\Middleware\AuthenticateSession::class,
|
||||
'encrypt_cookies' => App\Http\Middleware\EncryptCookies::class,
|
||||
'verify_csrf_token' => App\Http\Middleware\VerifyCsrfToken::class,
|
||||
],
|
||||
|
||||
];
|
||||
34
config/services.php
Normal file
34
config/services.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Third Party Services
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This file is for storing the credentials for third party services such
|
||||
| as Mailgun, Postmark, AWS and more. This file provides the de facto
|
||||
| location for this type of information, allowing packages to have
|
||||
| a conventional file to locate the various service credentials.
|
||||
|
|
||||
*/
|
||||
|
||||
'mailgun' => [
|
||||
'domain' => env('MAILGUN_DOMAIN'),
|
||||
'secret' => env('MAILGUN_SECRET'),
|
||||
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
|
||||
'scheme' => 'https',
|
||||
],
|
||||
|
||||
'postmark' => [
|
||||
'token' => env('POSTMARK_TOKEN'),
|
||||
],
|
||||
|
||||
'ses' => [
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
],
|
||||
|
||||
];
|
||||
214
config/session.php
Normal file
214
config/session.php
Normal file
@@ -0,0 +1,214 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Session Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default session "driver" that will be used on
|
||||
| requests. By default, we will use the lightweight native driver but
|
||||
| you may specify any of the other wonderful drivers provided here.
|
||||
|
|
||||
| Supported: "file", "cookie", "database", "apc",
|
||||
| "memcached", "redis", "dynamodb", "array"
|
||||
|
|
||||
*/
|
||||
|
||||
'driver' => env('SESSION_DRIVER', 'file'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Lifetime
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the number of minutes that you wish the session
|
||||
| to be allowed to remain idle before it expires. If you want them
|
||||
| to immediately expire on the browser closing, set that option.
|
||||
|
|
||||
*/
|
||||
|
||||
'lifetime' => env('SESSION_LIFETIME', 120),
|
||||
|
||||
'expire_on_close' => false,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Encryption
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option allows you to easily specify that all of your session data
|
||||
| should be encrypted before it is stored. All encryption will be run
|
||||
| automatically by Laravel and you can use the Session like normal.
|
||||
|
|
||||
*/
|
||||
|
||||
'encrypt' => false,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session File Location
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the native session driver, we need a location where session
|
||||
| files may be stored. A default has been set for you but a different
|
||||
| location may be specified. This is only needed for file sessions.
|
||||
|
|
||||
*/
|
||||
|
||||
'files' => storage_path('framework/sessions'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Database Connection
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the "database" or "redis" session drivers, you may specify a
|
||||
| connection that should be used to manage these sessions. This should
|
||||
| correspond to a connection in your database configuration options.
|
||||
|
|
||||
*/
|
||||
|
||||
'connection' => env('SESSION_CONNECTION'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Database Table
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the "database" session driver, you may specify the table we
|
||||
| should use to manage the sessions. Of course, a sensible default is
|
||||
| provided for you; however, you are free to change this as needed.
|
||||
|
|
||||
*/
|
||||
|
||||
'table' => 'sessions',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cache Store
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| While using one of the framework's cache driven session backends you may
|
||||
| list a cache store that should be used for these sessions. This value
|
||||
| must match with one of the application's configured cache "stores".
|
||||
|
|
||||
| Affects: "apc", "dynamodb", "memcached", "redis"
|
||||
|
|
||||
*/
|
||||
|
||||
'store' => env('SESSION_STORE'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Sweeping Lottery
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Some session drivers must manually sweep their storage location to get
|
||||
| rid of old sessions from storage. Here are the chances that it will
|
||||
| happen on a given request. By default, the odds are 2 out of 100.
|
||||
|
|
||||
*/
|
||||
|
||||
'lottery' => [2, 100],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may change the name of the cookie used to identify a session
|
||||
| instance by ID. The name specified here will get used every time a
|
||||
| new session cookie is created by the framework for every driver.
|
||||
|
|
||||
*/
|
||||
|
||||
'cookie' => env(
|
||||
'SESSION_COOKIE',
|
||||
Str::slug(env('APP_NAME', 'laravel'), '_').'_session'
|
||||
),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The session cookie path determines the path for which the cookie will
|
||||
| be regarded as available. Typically, this will be the root path of
|
||||
| your application but you are free to change this when necessary.
|
||||
|
|
||||
*/
|
||||
|
||||
'path' => '/',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Domain
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may change the domain of the cookie used to identify a session
|
||||
| in your application. This will determine which domains the cookie is
|
||||
| available to in your application. A sensible default has been set.
|
||||
|
|
||||
*/
|
||||
|
||||
'domain' => env('SESSION_DOMAIN'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| HTTPS Only Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| By setting this option to true, session cookies will only be sent back
|
||||
| to the server if the browser has a HTTPS connection. This will keep
|
||||
| the cookie from being sent to you when it can't be done securely.
|
||||
|
|
||||
*/
|
||||
|
||||
'secure' => env('SESSION_SECURE_COOKIE'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| HTTP Access Only
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Setting this value to true will prevent JavaScript from accessing the
|
||||
| value of the cookie and the cookie will only be accessible through
|
||||
| the HTTP protocol. You are free to modify this option if needed.
|
||||
|
|
||||
*/
|
||||
|
||||
'http_only' => true,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Same-Site Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option determines how your cookies behave when cross-site requests
|
||||
| take place, and can be used to mitigate CSRF attacks. By default, we
|
||||
| will set this value to "lax" since this is a secure default value.
|
||||
|
|
||||
| Supported: "lax", "strict", "none", null
|
||||
|
|
||||
*/
|
||||
|
||||
'same_site' => 'lax',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Partitioned Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Setting this value to true will tie the cookie to the top-level site for
|
||||
| a cross-site context. Partitioned cookies are accepted by the browser
|
||||
| when flagged "secure" and the Same-Site attribute is set to "none".
|
||||
|
|
||||
*/
|
||||
|
||||
'partitioned' => false,
|
||||
|
||||
];
|
||||
36
config/view.php
Normal file
36
config/view.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| View Storage Paths
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Most templating systems load templates from disk. Here you may specify
|
||||
| an array of paths that should be checked for your views. Of course
|
||||
| the usual Laravel view path has already been registered for you.
|
||||
|
|
||||
*/
|
||||
|
||||
'paths' => [
|
||||
resource_path('views'),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Compiled View Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option determines where all the compiled Blade templates will be
|
||||
| stored for your application. Typically, this is within the storage
|
||||
| directory. However, as usual, you are free to change this value.
|
||||
|
|
||||
*/
|
||||
|
||||
'compiled' => env(
|
||||
'VIEW_COMPILED_PATH',
|
||||
realpath(storage_path('framework/views'))
|
||||
),
|
||||
|
||||
];
|
||||
1
database/.gitignore
vendored
Normal file
1
database/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.sqlite*
|
||||
44
database/factories/UserFactory.php
Normal file
44
database/factories/UserFactory.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The current password being used by the factory.
|
||||
*/
|
||||
protected static ?string $password;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
32
database/migrations/2014_10_12_000000_create_users_table.php
Normal file
32
database/migrations/2014_10_12_000000_create_users_table.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?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('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
<?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('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
<?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('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
<?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->string('name');
|
||||
$table->string('token', 64)->unique();
|
||||
$table->text('abilities')->nullable();
|
||||
$table->timestamp('last_used_at')->nullable();
|
||||
$table->timestamp('expires_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('personal_access_tokens');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
<?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('lokasi', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('kode')->unique();
|
||||
$table->string('nama');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('lokasi');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
<?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('produk', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('sku')->nullable();
|
||||
$table->string('nama');
|
||||
$table->string('barcode')->unique();
|
||||
$table->unsignedBigInteger('harga_beli')->nullable();
|
||||
$table->unsignedBigInteger('harga_jual');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('produk');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
<?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('penjualan', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->string('nomor_penjualan')->unique();
|
||||
$table->timestamp('waktu')->useCurrent();
|
||||
$table->unsignedBigInteger('subtotal');
|
||||
$table->unsignedBigInteger('diskon')->default(0);
|
||||
$table->unsignedBigInteger('pajak')->default(0);
|
||||
$table->unsignedBigInteger('total');
|
||||
$table->string('metode_pembayaran');
|
||||
$table->unsignedBigInteger('jumlah_bayar');
|
||||
$table->unsignedBigInteger('kembalian')->default(0);
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('penjualan');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
<?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('pergerakan_stok', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->timestamp('waktu')->useCurrent();
|
||||
$table->foreignId('produk_id')->constrained('produk')->cascadeOnDelete();
|
||||
$table->foreignId('dari_lokasi_id')
|
||||
->nullable()
|
||||
->constrained('lokasi')
|
||||
->nullOnDelete();
|
||||
$table->foreignId('ke_lokasi_id')
|
||||
->nullable()
|
||||
->constrained('lokasi')
|
||||
->nullOnDelete();
|
||||
$table->string('jenis');
|
||||
$table->integer('jumlah');
|
||||
$table->string('referensi_tipe')->nullable();
|
||||
$table->unsignedBigInteger('referensi_id')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('pergerakan_stok');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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('penjualan_barang', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('penjualan_id')
|
||||
->constrained('penjualan')
|
||||
->cascadeOnDelete();
|
||||
$table->foreignId('produk_id')
|
||||
->constrained('produk')
|
||||
->cascadeOnDelete();
|
||||
$table->integer('jumlah');
|
||||
$table->unsignedBigInteger('harga');
|
||||
$table->unsignedBigInteger('total');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('penjualan_barang');
|
||||
}
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user