Files
compras/resources/views/sgf-invoices/document-form.blade.php
T
nala 976271f948
tests / ci (push) Canceled after 0s
commit melhorias1
2026-11-10 12:58:19 +02:00

17 lines
3.0 KiB
PHP

@php($doc=old('document',$draft['document']??[]))
<label>Referência de origem<input name="reference" value="{{ old('reference',$draft['reference']??'') }}" required maxlength="120" @readonly(isset($draft))></label>
<input type="hidden" name="connection_id" value="{{ $selection['connection'] }}"><input type="hidden" name="mapping_id" value="{{ $selection['id'] }}">
<p>Mapeamento escolhido: <strong>{{ $selection['label'] }}</strong>; ordem SGF #{{ $selection['mapping']['order_id'] }}; versão {{ $selection['mapping']['version'] }}.</p>
<label>Número do documento recebido<input name="document[number]" value="{{ $doc['number']??'' }}" required maxlength="100"></label>
<label>Data do documento<input type="date" name="document[issued_on]" value="{{ $doc['issued_on']??'' }}" required></label>
@foreach(['subtotal'=>'Base MZN','tax'=>'Imposto documental MZN','total'=>'Total MZN'] as $key=>$label)<label>{{ $label }}<input name="document[{{ $key }}]" value="{{ $doc[$key]??'' }}" required inputmode="decimal" pattern="[0-9]+\.[0-9]{2}" placeholder="0.00"></label>@endforeach
<fieldset><legend>Linhas da fonte — referências explicitamente mapeadas</legend><p>Introduzir as linhas recebidas. Não se convertem unidades ou preços automaticamente.</p>
@php($items=$doc['items']??[['source_line_ref'=>'','quantity'=>'','unit'=>'','unit_price'=>'','tax_rate'=>'']])
<div id="source-lines">@foreach($items as $i=>$item)<fieldset class="source-line"><legend>Linha {{ $loop->iteration }}</legend>
<label>Referência da linha<select name="document[items][{{ $i }}][source_line_ref]" required><option value="">Escolher</option>@foreach($selection['mapping']['lines'] as $ref=>$target)<option value="{{ $ref }}" @selected(($item['source_line_ref']??'')===$ref)>{{ $ref }} → linha SGF #{{ $target }}</option>@endforeach</select></label>
@foreach(['quantity'=>'Quantidade','unit'=>'Unidade','unit_price'=>'Preço unitário','tax_rate'=>'Taxa documental %'] as $key=>$label)<label>{{ $label }}<input name="document[items][{{ $i }}][{{ $key }}]" value="{{ $item[$key]??'' }}" required maxlength="30"></label>@endforeach
<button type="button" onclick="if(this.parentElement.parentElement.children.length>1)this.parentElement.remove()">Retirar linha</button></fieldset>@endforeach</div>
<button type="button" id="add-source-line">Acrescentar linha</button></fieldset>
<label>Fundamento<textarea name="reason" required minlength="10" maxlength="2000">{{ old('reason',$draft['reason']??'') }}</textarea></label>
<script>document.getElementById('add-source-line').addEventListener('click',()=>{const root=document.getElementById('source-lines');if(root.children.length>=50)return;let index=0;root.querySelectorAll('[name]').forEach(e=>{const m=e.name.match(/\[items\]\[(\d+)\]/);if(m)index=Math.max(index,Number(m[1])+1)});const next=root.firstElementChild.cloneNode(true);next.querySelector('legend').textContent='Nova linha';next.querySelectorAll('input,select').forEach(e=>{e.name=e.name.replace(/\[items\]\[\d+\]/,'[items]['+index+']');e.value=''});root.appendChild(next)});</script>