@extends('layouts.app')
@section('title', ($isNew?'New ':'Edit ').'Requisition')
@section('crumbs', '<a href="'.route('purchase-requisitions.index').'">Requisitions</a> · <b>'.($isNew?'New':'Edit').'</b>')
@section('content')
<div class="card"><div class="card-h"><h2>{{ $isNew?'New':'Edit' }} purchase requisition</h2><div class="sp"><span class="bdg b-info">{{ $docNo }}</span></div></div>
<div class="card-b"><form method="POST" action="{{ $isNew?route('purchase-requisitions.store'):route('purchase-requisitions.update',$record->id) }}" data-doc>@csrf @if(!$isNew)@method('PUT')@endif
<div class="frow">
<div class="fld c2"><label>Date *</label><input type="date" name="pr_date" value="{{ old('pr_date',$record->pr_date?->format('Y-m-d') ?? date('Y-m-d')) }}" required></div>
<div class="fld c2"><label>Required by</label><input type="date" name="required_date" value="{{ old('required_date',$record->required_date?->format('Y-m-d')) }}"></div>
<div class="fld c2"><label>Department</label><input type="text" name="department" value="{{ old('department',$record->department) }}"></div>
<div class="fld c3"><label>Quarry</label><select name="quarry_id"><option value="">—</option>@foreach($quarries as $q)<option value="{{ $q->id }}" {{ $record->quarry_id==$q->id?'selected':'' }}>{{ $q->name }}</option>@endforeach</select></div>
<div class="fld c3"><label>Project</label><select name="project_id"><option value="">—</option>@foreach($projects as $p)<option value="{{ $p->id }}" {{ $record->project_id==$p->id?'selected':'' }}>{{ $p->display_name }}</option>@endforeach</select></div>
<div class="fld c12"><label>Purpose</label><input type="text" name="purpose" value="{{ old('purpose',$record->purpose) }}"></div>
</div>
@include('docs._lines', ['id'=>'prLines', 'rows'=>$record->lines ?? [], 'cols'=>[
  ['f'=>'item_id','l'=>'Stock item','t'=>'select','o'=>$items->pluck('display_name','id')->all()],
  ['f'=>'description','l'=>'Description *','t'=>'text','req'=>1],
  ['f'=>'qty','l'=>'Qty *','t'=>'number','req'=>1,'w'=>'110px'],
  ['f'=>'unit_id','l'=>'Unit','t'=>'select','o'=>$units->pluck('symbol','id')->all(),'w'=>'100px'],
  ['f'=>'estimated_rate','l'=>'Est rate','t'=>'number','w'=>'120px'],
]])
<div style="margin-top:12px"><button class="btn btn-pri">Submit for approval</button> <a class="btn btn-ghost" href="{{ route('purchase-requisitions.index') }}">Cancel</a></div>
</form></div></div>
@endsection
