@extends('layouts.app')
@section('title','Chart of Accounts')
@section('content')
<div class="page-head"><div><h1>Chart of accounts</h1><p>Saudi trading company structure used by automatic postings and manual journals.</p></div><button class="btn btn-primary btn-dense" data-bs-toggle="modal" data-bs-target="#accountModal"><i class="bi bi-plus-lg me-1"></i>New account</button></div>
<div class="card-erp"><div class="table-responsive"><table class="table table-dense"><thead><tr><th>Code</th><th>Account</th><th>Arabic</th><th>Type</th><th>Parent</th><th>Control</th><th>Manual posting</th><th>Status</th></tr></thead><tbody>@foreach($accounts as $a)<tr><td class="fw-bold text-accent">{{ $a->code }}</td><td class="{{ $a->is_control_account?'fw-bold':'' }}">{{ $a->name_en }}</td><td dir="rtl">{{ $a->name_ar }}</td><td>{{ strtoupper($a->type) }}</td><td>{{ $a->parent?->name_en?:'—' }}</td><td>{{ $a->is_control_account?'Yes':'No' }}</td><td>{{ $a->allow_manual_posting?'Allowed':'Automatic only' }}</td><td><span class="badge status-{{ $a->status }}">{{ strtoupper($a->status) }}</span></td></tr>@endforeach</tbody></table></div></div>
<div class="modal fade" id="accountModal"><div class="modal-dialog"><form method="POST" action="{{ route('accounts.chart.store') }}" class="modal-content">@csrf<div class="modal-header"><h5 class="modal-title">New account</h5><button class="btn-close" data-bs-dismiss="modal"></button></div><div class="modal-body"><div class="row g-2"><div class="col-4"><label class="form-label">Code</label><input name="code" class="form-control" required></div><div class="col-8"><label class="form-label">English name</label><input name="name_en" class="form-control" required></div><div class="col-12"><label class="form-label">Arabic name</label><input name="name_ar" class="form-control" dir="rtl"></div><div class="col-6"><label class="form-label">Type</label><select name="type" class="form-select">@foreach(['asset','liability','equity','income','cogs','expense'] as $t)<option>{{ $t }}</option>@endforeach</select></div><div class="col-6"><label class="form-label">Parent</label><select name="parent_id" class="form-select"><option value="">None</option>@foreach($accounts->where('is_control_account',true) as $a)<option value="{{ $a->id }}">{{ $a->code }} · {{ $a->name_en }}</option>@endforeach</select></div><div class="col-12 form-check mt-3 ms-1"><input type="hidden" name="allow_manual_posting" value="0"><input type="checkbox" class="form-check-input" name="allow_manual_posting" value="1" checked><label class="form-check-label">Allow manual journal posting</label></div></div></div><div class="modal-footer"><button type="button" class="btn btn-light border" data-bs-dismiss="modal">Cancel</button><button class="btn btn-primary">Create account</button></div></form></div></div>
@endsection
