<?php $__env->startSection('title','Manual Journal'); ?>
<?php $__env->startSection('content'); ?>
<form method="POST" action="<?php echo e(route('accounts.journals.store')); ?>" id="journalForm"><?php echo csrf_field(); ?><div class="page-head"><div><h1>Manual journal entry</h1><p>Debits and credits must balance exactly before posting.</p></div></div><div class="card-erp"><div class="card-erp-body"><div class="row g-2"><div class="col-md-3"><label class="form-label">Entry date</label><input type="date" name="entry_date" class="form-control" value="<?php echo e(now()->toDateString()); ?>" required></div><div class="col-md-9"><label class="form-label">Description</label><input name="description" class="form-control" required></div></div></div><div class="table-responsive"><table class="table table-dense"><thead><tr><th>Account</th><th>Description</th><th style="width:160px">Debit</th><th style="width:160px">Credit</th><th></th></tr></thead><tbody id="journalLines"></tbody><tfoot><tr><th colspan="2" class="text-end">Totals</th><th id="debitTotal">0.00</th><th id="creditTotal">0.00</th><th></th></tr></tfoot></table></div><div class="card-erp-body border-top"><button type="button" class="btn btn-light border" id="addJournalLine"><i class="bi bi-plus"></i>Add line</button></div></div><div class="sticky-actions d-flex justify-content-end gap-2"><a href="<?php echo e(route('accounts.journals')); ?>" class="btn btn-light border">Cancel</a><button class="btn btn-primary">Post journal</button></div></form>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('scripts'); ?><script>let ji=0;const accts=<?php echo json_encode($accounts->map(fn($a)=>['id'=>$a->id, 'label'=>$a->code.' · '.$a->name_en]), 512) ?>;function line(){let tr=document.createElement('tr');tr.innerHTML=`<td><select class="form-select" name="lines[${ji}][account_id]">${accts.map(a=>`<option value="${a.id}">${a.label}</option>`).join('')}</select></td><td><input class="form-control" name="lines[${ji}][description]"></td><td><input class="form-control amount debit" type="number" name="lines[${ji}][debit]" value="0" min="0" step=".01"></td><td><input class="form-control amount credit" type="number" name="lines[${ji}][credit]" value="0" min="0" step=".01"></td><td><button type="button" class="btn btn-link text-danger"><i class="bi bi-x"></i></button></td>`;journalLines.appendChild(tr);tr.querySelectorAll('.amount').forEach(x=>x.oninput=sum);tr.querySelector('button').onclick=()=>{tr.remove();sum()};ji++}function sum(){let d=[...document.querySelectorAll('.debit')].reduce((a,x)=>a+(+x.value||0),0),c=[...document.querySelectorAll('.credit')].reduce((a,x)=>a+(+x.value||0),0);debitTotal.textContent=d.toFixed(2);creditTotal.textContent=c.toFixed(2);debitTotal.className=creditTotal.className=Math.abs(d-c)<.005&&d>0?'text-success':'text-danger'}addJournalLine.onclick=line;line();line();journalForm.onsubmit=e=>{let d=parseFloat(debitTotal.textContent),c=parseFloat(creditTotal.textContent);if(!d||Math.abs(d-c)>.005){e.preventDefault();alert('Journal debits and credits must balance.')}};</script><?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\saudi\resources\views\accounts\journal_create.blade.php ENDPATH**/ ?>