@extends('layouts.app')
@section('title','Contra Settlement')
@section('page_title','Contra Settlement')
@section('content')
<div class="page-head"><div><h1>{{ $contra->exists?'Edit':'Create' }} Contra Settlement</h1><p>AR and AP remain separate until this approved settlement is posted.</p></div><a class="btn btn-secondary" href="{{ $contra->exists?route('contra.show',$contra):route('contra.index') }}">Back</a></div>
<form method="post" action="{{ $contra->exists?route('contra.update',$contra):route('contra.store') }}">@csrf @if($contra->exists)@method('put')@endif<div class="card"><div class="card-body"><div class="form-grid"><div class="field"><label>Branch</label><select class="control" name="branch_id">@foreach($branches as $b)<option value="{{ $b->id }}" @selected(old('branch_id',$contra->branch_id)==$b->id)>{{ $b->code }} - {{ $b->name }}</option>@endforeach</select></div><div class="field"><label>Date</label><input class="control" type="date" name="settlement_date" value="{{ old('settlement_date',optional($contra->settlement_date)->format('Y-m-d')) }}"></div><div class="field"><label>Dual-Role Party</label><select class="control" name="party_id" required><option value="">Select</option>@foreach($parties as $p)<option value="{{ $p->id }}" @selected(old('party_id',$contra->party_id)==$p->id)>{{ $p->legal_name }}</option>@endforeach</select></div><div class="field"><label>Amount</label><input class="control" type="number" step="0.0001" name="amount" value="{{ old('amount',$contra->amount) }}" required></div><div class="field"><label>Customer Invoice</label><select class="control" name="customer_invoice_id" required>@foreach($invoices as $i)<option value="{{ $i->id }}" @selected(old('customer_invoice_id',$contra->customer_invoice_id)==$i->id)>{{ $i->invoice_number }} - {{ $i->party?->legal_name }} · Balance {{ number_format((float)$i->grand_total-(float)$i->paid_total-(float)$i->allocated_total,2) }}</option>@endforeach</select></div><div class="field"><label>Vendor Bill</label><select class="control" name="vendor_bill_id" required>@foreach($bills as $b)<option value="{{ $b->id }}" @selected(old('vendor_bill_id',$contra->vendor_bill_id)==$b->id)>{{ $b->bill_number }} - {{ $b->party?->legal_name }} · Balance {{ number_format((float)$b->grand_total-(float)$b->paid_total-(float)$b->allocated_total,2) }}</option>@endforeach</select></div><div class="field"><label>Accounts Receivable</label><select class="control" name="receivable_account_id">@foreach($accounts as $a)<option value="{{ $a->id }}" @selected(old('receivable_account_id',$contra->receivable_account_id)==$a->id)>{{ $a->code }} - {{ $a->name }}</option>@endforeach</select></div><div class="field"><label>Accounts Payable</label><select class="control" name="payable_account_id">@foreach($accounts as $a)<option value="{{ $a->id }}" @selected(old('payable_account_id',$contra->payable_account_id)==$a->id)>{{ $a->code }} - {{ $a->name }}</option>@endforeach</select></div><div class="field full"><label>Reason</label><textarea class="control" name="reason" required>{{ old('reason',$contra->reason) }}</textarea></div></div></div><div class="card-head" style="justify-content:flex-end"><button class="btn btn-primary">Save Draft</button></div></div></form>
@endsection
