<?php $__env->startSection('title','New Dispatch (Delivery Note)'); ?>
<?php $__env->startSection('crumbs', '<a href="'.route('delivery-notes.index').'">Dispatch</a> · <b>New</b>'); ?>
<?php $__env->startSection('content'); ?>
<div class="card"><div class="card-h"><h2>New dispatch — posts stockpile issue immediately</h2><div class="sp"><span class="bdg b-info"><?php echo e($docNo); ?></span></div></div>
<div class="card-b"><form method="POST" action="<?php echo e(route('delivery-notes.store')); ?>" data-doc data-tax='{"apply":false}'><?php echo csrf_field(); ?>
<div class="frow">
<div class="fld c4"><label>Sales order</label><select name="sales_order_id" onchange="if(this.value)location='<?php echo e(route('delivery-notes.create')); ?>?from_order='+this.value"><option value="">— Ad-hoc (no order) —</option><?php $__currentLoopData = $orders; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $o): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($o->id); ?>" <?php echo e($record->sales_order_id==$o->id?'selected':''); ?>><?php echo e($o->order_no); ?> — <?php echo e($o->customer->name ?? ''); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select></div>
<div class="fld c4"><label>Customer *</label><select name="customer_id" required><option value="">—</option><?php $__currentLoopData = $customers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $c): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($c->id); ?>" data-defcur="<?php echo e($c->default_currency); ?>" <?php echo e($record->customer_id==$c->id?'selected':''); ?>><?php echo e($c->display_name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select></div>
<div class="fld c2"><label>Date *</label><input type="date" name="dn_date" value="<?php echo e(date('Y-m-d')); ?>" required></div>
<?php echo $__env->make('docs._fxfields', ['record' => $record, 'fx' => $fx, 'isNew' => $isNew], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
<div class="fld c2"><label>Quarry</label><select name="quarry_id"><option value="">—</option><?php $__currentLoopData = $quarries; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $q): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($q->id); ?>" <?php echo e($record->quarry_id==$q->id?'selected':''); ?>><?php echo e($q->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select></div>
<div class="fld c3"><label>Vehicle no.</label><input type="text" name="vehicle_no" style="text-transform:uppercase"></div>
<div class="fld c3"><label>Driver</label><input type="text" name="driver_name"></div>
<div class="fld c3"><label>Transporter</label><select name="transporter_id"><option value="">—</option><?php $__currentLoopData = $transporters; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $t): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($t->id); ?>"><?php echo e($t->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select></div>
<div class="fld c3"><label>Weighbridge ticket</label><select name="weighbridge_ticket_id"><option value="">—</option><?php $__currentLoopData = $tickets; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $t): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($t->id); ?>"><?php echo e($t->ticket_no); ?> — <?php echo e($t->vehicle_no); ?> (<?php echo e(qty($t->net_weight)); ?>t)</option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select></div>
</div>
<?php
$preRows = [];
if(!empty($order)) foreach($order->lines as $l){ $bal = $l->qty_ordered - $l->qty_dispatched; if($bal > 0) $preRows[] = ['product_id'=>$l->product_id,'qty_tonnes'=>$bal,'rate'=>$l->rate,'amount'=>round($bal*$l->rate,2)]; }
?>
<?php echo $__env->make('docs._lines', ['id'=>'dnLines', 'rows'=>$preRows, 'cols'=>[
  ['f'=>'product_id','l'=>'Product *','t'=>'select','o'=>$products->pluck('display_name','id')->all(),'req'=>1],
  ['f'=>'stockpile_id','l'=>'Stockpile','t'=>'select','o'=>$piles->pluck('code','id')->all()],
  ['f'=>'qty_tonnes','l'=>'Qty (t) *','t'=>'number','role'=>'qty','req'=>1,'w'=>'110px'],
  ['f'=>'rate','l'=>'Rate *','t'=>'number','role'=>'rate','req'=>1,'w'=>'120px'],
  ['f'=>'amount','l'=>'Amount','t'=>'number','role'=>'amount','ro'=>1,'w'=>'130px'],
]], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
<?php echo $__env->make('docs._totals', ['tax'=>null], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
<div style="margin-top:12px"><button class="btn btn-pri">🚛 Dispatch now</button> <a class="btn btn-ghost" href="<?php echo e(route('delivery-notes.index')); ?>">Cancel</a></div>
</form></div></div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/user/nowills-sqc-erp/resources/views/docs/delivery/form.blade.php ENDPATH**/ ?>