
<?php $cur = old('currency_code', $record->currency_code ?? 'GHS'); $rt = old('exchange_rate', $record->exchange_rate ?? null); ?>
<div class="fld c2"><label>Currency *</label>
<select name="currency_code" data-fx-cur <?php echo e((!empty($lockFx) || !empty($lockCur)) ? 'disabled' : ''); ?> required>
<?php $__currentLoopData = $fx; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $code => $c): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($code); ?>" data-rate="<?php echo e($c->rate_to_ghs); ?>" data-sym="<?php echo e($c->symbol ?: $code); ?>" <?php echo e($cur===$code?'selected':''); ?>><?php echo e($code); ?> — <?php echo e($c->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</select>
<?php if(!empty($lockFx) || !empty($lockCur)): ?><input type="hidden" name="currency_code" value="<?php echo e($cur); ?>"><?php endif; ?>
</div>
<div class="fld c2"><label>Rate → GHS *</label>
<input type="number" step="0.000001" min="0.000001" name="exchange_rate" data-fx-rate value="<?php echo e($rt ?? ($fx[$cur]->rate_to_ghs ?? 1)); ?>" <?php echo e(!empty($lockFx) ? 'readonly' : ''); ?> required>
<small class="muted" data-fx-hint></small>
</div>
<script>
(function(){
  var cur = document.querySelector('[data-fx-cur]'), rate = document.querySelector('[data-fx-rate]'), hint = document.querySelector('[data-fx-hint]');
  function opt(){ return cur.options[cur.selectedIndex]; }
  function paint(){
    var r = parseFloat(opt().dataset.rate || '1');
    document.querySelectorAll('[data-fx-sym]').forEach(function(el){ el.textContent = opt().dataset.sym || cur.value; });
    if (hint) hint.textContent = cur.value === 'GHS' ? 'Base currency' : ('1 ' + cur.value + ' = ' + r + ' GHS (master)');
  }
  cur.addEventListener('change', function(){ rate.value = opt().dataset.rate || 1; paint(); });
  <?php if(!empty($isNew)): ?>
  ['customer_id','supplier_id'].forEach(function(nm){
    var ps = document.querySelector('select[name=' + nm + ']');
    if (ps) ps.addEventListener('change', function(){
      var dc = ps.options[ps.selectedIndex].dataset.defcur;
      if (dc && cur.querySelector('option[value=' + dc + ']')) { cur.value = dc; cur.dispatchEvent(new Event('change')); }
    });
  });
  <?php endif; ?>
  paint();
})();
</script>
<?php /**PATH /home/user/nowills-sqc-erp/resources/views/docs/_fxfields.blade.php ENDPATH**/ ?>