chore: initial commit of existing codebase

This commit is contained in:
ghassan committed 2026-05-19 12:40:08 +03:00
commit 11e94889b2
292 files changed
+38586

No files matched your search

@@ -0,0 +1,196 @@
@extends('layouts.app')
@section('title', 'New Purchase Order')
@section('content')
<div class="mb-6">
<h1 class="page-title">New Purchase Order</h1>
<p class="page-subtitle"><a href="{{ route('purchase.orders.index') }}" class="text-blue-600 hover:underline">Purchase Orders</a> / New</p>
</div>
@if($errors->any())
<div class="mb-4 px-4 py-3 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700">
<ul class="list-disc list-inside space-y-1">
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<form action="{{ route('purchase.orders.store') }}" method="POST">
@csrf
<!-- Header Section -->
<div class="card card-body mb-4">
<h2 class="text-base font-semibold text-gray-700 mb-4">Order Details</h2>
<div class="grid grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-3">
<div>
<label class="form-label">Supplier <span class="text-red-500">*</span></label>
<select name="supplier_id" required class="form-select">
<option value="">-- Select Supplier --</option>
@foreach($suppliers as $supplier)
<option value="{{ $supplier->id }}" {{ old('supplier_id') == $supplier->id ? 'selected' : '' }}>
{{ $supplier->name }}
</option>
@endforeach
</select>
</div>
<div>
<label class="form-label">Purchase Request (optional)</label>
<select name="purchase_request_id" class="form-select">
<option value="">-- None --</option>
@foreach($purchaseRequests as $pr)
<option value="{{ $pr->id }}" {{ old('purchase_request_id') == $pr->id ? 'selected' : '' }}>
{{ $pr->request_number ?? '#' . $pr->id }} - {{ $pr->item->item_name ?? '' }}
</option>
@endforeach
</select>
</div>
<div>
<label class="form-label">PO Date <span class="text-red-500">*</span></label>
<input type="date" name="po_date" value="{{ old('po_date', date('Y-m-d')) }}" required class="form-input">
</div>
<div>
<label class="form-label">Expected Delivery Date</label>
<input type="date" name="expected_delivery_date" value="{{ old('expected_delivery_date') }}" class="form-input">
</div>
<div class="sm:col-span-2">
<label class="form-label">Notes</label>
<textarea name="notes" rows="2" class="form-textarea">{{ old('notes') }}</textarea>
</div>
</div>
</div>
<!-- Items Section -->
<div class="card card-body mb-4">
<div class="flex items-center justify-between mb-4">
<h2 class="text-base font-semibold text-gray-700">Order Items</h2>
<button type="button" onclick="addPORow()" class="btn-primary btn-sm">+ Add Row</button>
</div>
<div class="overflow-x-auto">
<table class="min-w-full text-sm" id="po-items-table">
<thead>
<tr class="border-b border-gray-200">
<th class="pb-2 text-left font-semibold text-gray-600">Item</th>
<th class="pb-2 text-left font-semibold text-gray-600 w-28">Quantity</th>
<th class="pb-2 text-left font-semibold text-gray-600 w-28">Rate</th>
<th class="pb-2 text-left font-semibold text-gray-600 w-28">Total</th>
<th class="pb-2 w-10"></th>
</tr>
</thead>
<tbody id="po-items-body">
<tr class="po-item-row">
<td class="py-1 pr-2">
<select name="items[0][item_id]"
class="w-full border border-gray-300 rounded px-2 py-1.5 text-sm focus:outline-none focus:ring-1 focus:ring-blue-400">
<option value="">-- Select Item --</option>
@foreach($items as $item)
<option value="{{ $item->id }}">{{ $item->item_code }} - {{ $item->item_name }}</option>
@endforeach
</select>
</td>
<td class="py-1 pr-2">
<input type="number" name="items[0][quantity]" placeholder="0"
min="0" step="0.01"
onchange="calcRowTotal(this)"
class="w-full border border-gray-300 rounded px-2 py-1.5 text-sm focus:outline-none focus:ring-1 focus:ring-blue-400 qty-input">
</td>
<td class="py-1 pr-2">
<input type="number" name="items[0][rate]" placeholder="0.00"
min="0" step="0.01"
onchange="calcRowTotal(this)"
class="w-full border border-gray-300 rounded px-2 py-1.5 text-sm focus:outline-none focus:ring-1 focus:ring-blue-400 rate-input">
</td>
<td class="py-1 pr-2">
<input type="number" name="items[0][total]" placeholder="0.00"
readonly
class="w-full border border-gray-200 bg-gray-50 rounded px-2 py-1.5 text-sm row-total">
</td>
<td class="py-1">
<button type="button" onclick="removePORow(this)" class="text-red-400 hover:text-red-600 text-lg leading-none">&times;</button>
</td>
</tr>
</tbody>
</table>
</div>
<div class="mt-3 flex justify-end">
<div class="text-sm font-semibold text-gray-700">
Grand Total: <span id="grand-total" class="text-blue-700">0.00</span>
</div>
</div>
</div>
<div class="flex items-center gap-3">
<button type="submit" class="btn-primary">Create Purchase Order</button>
<a href="{{ route('purchase.orders.index') }}" class="btn-secondary">Cancel</a>
</div>
</form>
<script>
var poRowIndex = 1;
var itemsHtml = `@foreach($items as $item)<option value="{{ $item->id }}">{{ $item->item_code }} - {{ $item->item_name }}</option>@endforeach`;
function addPORow() {
var tbody = document.getElementById('po-items-body');
var row = document.createElement('tr');
row.className = 'po-item-row';
row.innerHTML = `
<td class="py-1 pr-2">
<select name="items[${poRowIndex}][item_id]" class="w-full border border-gray-300 rounded px-2 py-1.5 text-sm focus:outline-none focus:ring-1 focus:ring-blue-400">
<option value="">-- Select Item --</option>
${itemsHtml}
</select>
</td>
<td class="py-1 pr-2">
<input type="number" name="items[${poRowIndex}][quantity]" placeholder="0" min="0" step="0.01"
onchange="calcRowTotal(this)" class="w-full border border-gray-300 rounded px-2 py-1.5 text-sm qty-input">
</td>
<td class="py-1 pr-2">
<input type="number" name="items[${poRowIndex}][rate]" placeholder="0.00" min="0" step="0.01"
onchange="calcRowTotal(this)" class="w-full border border-gray-300 rounded px-2 py-1.5 text-sm rate-input">
</td>
<td class="py-1 pr-2">
<input type="number" name="items[${poRowIndex}][total]" placeholder="0.00" readonly
class="w-full border border-gray-200 bg-gray-50 rounded px-2 py-1.5 text-sm row-total">
</td>
<td class="py-1">
<button type="button" onclick="removePORow(this)" class="text-red-400 hover:text-red-600 text-lg leading-none">&times;</button>
</td>`;
tbody.appendChild(row);
poRowIndex++;
}
function removePORow(btn) {
var rows = document.querySelectorAll('.po-item-row');
if (rows.length > 1) {
btn.closest('tr').remove();
updateGrandTotal();
}
}
function calcRowTotal(input) {
var row = input.closest('tr');
var qty = parseFloat(row.querySelector('.qty-input').value) || 0;
var rate = parseFloat(row.querySelector('.rate-input').value) || 0;
var total = qty * rate;
row.querySelector('.row-total').value = total.toFixed(2);
updateGrandTotal();
}
function updateGrandTotal() {
var totals = document.querySelectorAll('.row-total');
var grand = 0;
totals.forEach(function(t) { grand += parseFloat(t.value) || 0; });
document.getElementById('grand-total').textContent = grand.toFixed(2);
}
</script>
@endsection
@@ -0,0 +1,72 @@
@extends('layouts.app')
@section('title', 'Edit Purchase Order')
@section('content')
<div class="mb-6">
<h1 class="page-title">Edit Purchase Order</h1>
<p class="page-subtitle"><a href="{{ route('purchase.orders.index') }}" class="text-blue-600 hover:underline">Purchase Orders</a> / Edit</p>
</div>
@if($errors->any())
<div class="mb-4 px-4 py-3 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700">
<ul class="list-disc list-inside space-y-1">
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<div class="card card-body max-w-2xl">
<form action="{{ route('purchase.orders.update', $order) }}" method="POST">
@csrf
@method('PUT')
<div class="grid grid-cols-1 gap-5 sm:grid-cols-2">
<div>
<label class="form-label">Supplier <span class="text-red-500">*</span></label>
<select name="supplier_id" required class="form-select">
<option value="">-- Select Supplier --</option>
@foreach($suppliers as $supplier)
<option value="{{ $supplier->id }}" {{ old('supplier_id', $order->supplier_id) == $supplier->id ? 'selected' : '' }}>
{{ $supplier->name }}
</option>
@endforeach
</select>
</div>
<div>
<label class="form-label">PO Date <span class="text-red-500">*</span></label>
<input type="date" name="po_date" value="{{ old('po_date', $order->po_date ? \Carbon\Carbon::parse($order->po_date)->format('Y-m-d') : '') }}" required class="form-input">
</div>
<div>
<label class="form-label">Expected Delivery Date</label>
<input type="date" name="expected_delivery_date" value="{{ old('expected_delivery_date', $order->expected_delivery_date ? \Carbon\Carbon::parse($order->expected_delivery_date)->format('Y-m-d') : '') }}" class="form-input">
</div>
<div>
<label class="form-label">Status</label>
<select name="status" class="form-select">
<option value="draft" {{ old('status', $order->status) === 'draft' ? 'selected' : '' }}>Draft</option>
<option value="sent" {{ old('status', $order->status) === 'sent' ? 'selected' : '' }}>Sent</option>
<option value="received" {{ old('status', $order->status) === 'received' ? 'selected' : '' }}>Received</option>
<option value="cancelled" {{ old('status', $order->status) === 'cancelled' ? 'selected' : '' }}>Cancelled</option>
</select>
</div>
<div class="sm:col-span-2">
<label class="form-label">Notes</label>
<textarea name="notes" rows="3" class="form-textarea">{{ old('notes', $order->notes) }}</textarea>
</div>
</div>
<div class="mt-6 flex items-center gap-3">
<button type="submit" class="btn-primary">Update Order</button>
<a href="{{ route('purchase.orders.show', $order) }}" class="btn-secondary">Cancel</a>
</div>
</form>
</div>
@endsection
@@ -0,0 +1,74 @@
@extends('layouts.app')
@section('title', 'Purchase Orders')
@section('content')
<div class="page-header">
<div>
<h1 class="page-title">Purchase Orders</h1>
<p class="page-subtitle">Manage all purchase orders</p>
</div>
<a href="{{ route('purchase.orders.create') }}" class="btn-primary">
+ New PO
</a>
</div>
<div class="table-wrapper overflow-x-auto">
<table class="table-base">
<thead>
<tr>
<th>PO #</th>
<th>Supplier</th>
<th>Date</th>
<th>Expected Delivery</th>
<th class="text-right">Total Amount</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@forelse($orders as $order)
<tr>
<td class="font-mono text-gray-700">{{ $order->po_number ?? 'PO-' . str_pad($order->id, 5, '0', STR_PAD_LEFT) }}</td>
<td class="text-gray-800">{{ $order->supplier->name ?? '' }}</td>
<td>{{ $order->po_date ? \Carbon\Carbon::parse($order->po_date)->format('d M Y') : '' }}</td>
<td>{{ $order->expected_delivery_date ? \Carbon\Carbon::parse($order->expected_delivery_date)->format('d M Y') : '' }}</td>
<td class="text-right font-medium text-gray-800">{{ number_format($order->total_amount, 2) }}</td>
<td>
@php
$badgeClass = match($order->status ?? 'draft') {
'draft' => 'badge-gray',
'sent' => 'badge-blue',
'received' => 'badge-green',
'cancelled' => 'badge-red',
default => 'badge-gray',
};
@endphp
<span class="{{ $badgeClass }}">{{ ucfirst($order->status ?? 'draft') }}</span>
</td>
<td>
<div class="flex items-center gap-2">
<a href="{{ route('purchase.orders.show', $order) }}" class="btn-primary btn-sm">View</a>
<a href="{{ route('purchase.orders.edit', $order) }}" class="btn-secondary btn-sm">Edit</a>
<form action="{{ route('purchase.orders.destroy', $order) }}" method="POST"
onsubmit="confirmDelete(this,'Delete this purchase order?','This order will be permanently removed.'); return false;">
@csrf
@method('DELETE')
<button type="submit" class="btn-danger btn-sm">Delete</button>
</form>
</div>
</td>
</tr>
@empty
<tr>
<td colspan="7" class="px-4 py-8 text-center text-gray-400">No purchase orders found.</td>
</tr>
@endforelse
</tbody>
</table>
</div>
@if($orders->hasPages())
<div class="mt-4">{{ $orders->links() }}</div>
@endif
@endsection
@@ -0,0 +1,152 @@
@extends('layouts.app')
@section('title', 'Purchase Order')
@section('content')
<div class="page-header">
<div>
<h1 class="page-title">Purchase Order</h1>
<p class="page-subtitle">
<a href="{{ route('purchase.orders.index') }}" class="text-blue-600 hover:underline">Purchase Orders</a>
/ {{ $order->po_number ?? 'PO-' . str_pad($order->id, 5, '0', STR_PAD_LEFT) }}
</p>
</div>
<div class="flex gap-2">
<a href="{{ route('purchase.orders.edit', $order) }}" class="btn-secondary">Edit</a>
<a href="{{ route('purchase.grns.create', ['purchase_order_id' => $order->id]) }}" class="btn-primary">Create GRN</a>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-4 mb-6">
<!-- PO Info -->
<div class="lg:col-span-2 bg-white rounded-xl border border-gray-200 p-6 shadow-sm">
<h2 class="text-sm font-semibold text-gray-500 uppercase tracking-wider mb-4">Order Information</h2>
<dl class="grid grid-cols-2 gap-4 text-sm">
<div>
<dt class="text-gray-500">PO Number</dt>
<dd class="font-semibold text-gray-800 font-mono">{{ $order->po_number ?? 'PO-' . str_pad($order->id, 5, '0', STR_PAD_LEFT) }}</dd>
</div>
<div>
<dt class="text-gray-500">Status</dt>
<dd>
@php
$badgeClass = match($order->status ?? 'draft') {
'draft' => 'badge-gray',
'sent' => 'badge-blue',
'received' => 'badge-green',
'cancelled' => 'badge-red',
default => 'badge-gray',
};
@endphp
<span class="{{ $badgeClass }}">{{ ucfirst($order->status ?? 'draft') }}</span>
</dd>
</div>
<div>
<dt class="text-gray-500">PO Date</dt>
<dd class="font-medium text-gray-800">{{ $order->po_date ? \Carbon\Carbon::parse($order->po_date)->format('d M Y') : '-' }}</dd>
</div>
<div>
<dt class="text-gray-500">Expected Delivery</dt>
<dd class="font-medium text-gray-800">{{ $order->expected_delivery_date ? \Carbon\Carbon::parse($order->expected_delivery_date)->format('d M Y') : '-' }}</dd>
</div>
@if($order->notes)
<div class="col-span-2">
<dt class="text-gray-500">Notes</dt>
<dd class="text-gray-700">{{ $order->notes }}</dd>
</div>
@endif
</dl>
</div>
<!-- Supplier Info -->
<div class="bg-white rounded-xl border border-gray-200 p-6 shadow-sm">
<h2 class="text-sm font-semibold text-gray-500 uppercase tracking-wider mb-4">Supplier</h2>
@if($order->supplier)
<dl class="space-y-2 text-sm">
<div>
<dt class="text-gray-500">Name</dt>
<dd class="font-semibold text-gray-800">{{ $order->supplier->name }}</dd>
</div>
<div>
<dt class="text-gray-500">Contact</dt>
<dd class="text-gray-700">{{ $order->supplier->contact_person }}</dd>
</div>
<div>
<dt class="text-gray-500">Email</dt>
<dd class="text-gray-700">{{ $order->supplier->email }}</dd>
</div>
<div>
<dt class="text-gray-500">Phone</dt>
<dd class="text-gray-700">{{ $order->supplier->phone }}</dd>
</div>
</dl>
@endif
</div>
</div>
<!-- Items Table -->
<div class="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden mb-6">
<div class="px-6 py-4 border-b border-gray-200">
<h2 class="text-base font-semibold text-gray-700">Order Items</h2>
</div>
<table class="table-base">
<thead>
<tr>
<th>Item</th>
<th class="text-right">Quantity</th>
<th class="text-right">Rate</th>
<th class="text-right">Total</th>
</tr>
</thead>
<tbody>
@forelse($order->items as $item)
<tr>
<td class="text-gray-800">{{ $item->item->item_name ?? $item->item_name }}</td>
<td class="text-right text-gray-600">{{ number_format($item->quantity, 2) }}</td>
<td class="text-right text-gray-600">{{ number_format($item->rate, 2) }}</td>
<td class="text-right font-medium text-gray-800">{{ number_format($item->total, 2) }}</td>
</tr>
@empty
<tr><td colspan="4" class="px-4 py-6 text-center text-gray-400">No items.</td></tr>
@endforelse
</tbody>
<tfoot class="bg-gray-50">
<tr>
<td colspan="3" class="px-4 py-3 text-right font-semibold text-gray-700">Total Amount</td>
<td class="px-4 py-3 text-right font-bold text-gray-900">{{ number_format($order->total_amount, 2) }}</td>
</tr>
</tfoot>
</table>
</div>
<!-- GRNs Linked -->
@if($order->goodsReceiptNotes && $order->goodsReceiptNotes->count())
<div class="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden">
<div class="px-6 py-4 border-b border-gray-200">
<h2 class="text-base font-semibold text-gray-700">Goods Receipt Notes</h2>
</div>
<table class="table-base">
<thead>
<tr>
<th>GRN #</th>
<th>Warehouse</th>
<th>Received Date</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($order->goodsReceiptNotes as $grn)
<tr>
<td class="font-mono text-gray-700">{{ $grn->grn_number ?? 'GRN-' . str_pad($grn->id, 5, '0', STR_PAD_LEFT) }}</td>
<td class="text-gray-700">{{ $grn->warehouse->name ?? '' }}</td>
<td>{{ $grn->received_date ? \Carbon\Carbon::parse($grn->received_date)->format('d M Y') : '' }}</td>
<td><span class="badge-green">{{ ucfirst($grn->status ?? 'received') }}</span></td>
<td><a href="{{ route('purchase.grns.show', $grn) }}" class="btn-primary btn-sm">View</a></td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
@endsection