<?php $__env->startSection('title','Stock In'); ?>
<?php $__env->startSection('page_title','ذخیره اضافه کول - ساده Purchase'); ?>

<?php $__env->startSection('content'); ?>
<form method="POST" action="<?php echo e(route('purchases.store')); ?>">
<?php echo csrf_field(); ?>
<input type="hidden" name="exchange_rate" value="1">
<div class="row g-3">
    <div class="col-lg-8">
        <div class="top-card">
            <h5 class="fw-bold mb-1"><i class="fa-solid fa-truck-droplet text-success"></i> د سپلایر څخه ذخیره اضافه کول</h5>
            <p class="mini-help mb-3">د خرید قیمت هم له تنظیماتو راځي. که قیمت بدل وي، د Settings څخه یې بدل کړئ.</p>
            <div class="row g-3">
                <div class="col-md-4"><label class="easy-label required">تاریخ</label><input type="date" name="purchase_date" value="<?php echo e(date('Y-m-d')); ?>" class="form-control form-control-lg" required></div>
                <div class="col-md-4"><label class="easy-label required">سپلایر</label><select name="supplier_id" class="form-select form-select-lg" required><?php $__currentLoopData = $suppliers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $supplier): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($supplier->id); ?>"><?php echo e($supplier->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select></div>
                <div class="col-md-4"><label class="easy-label required">کرنسي</label><select name="currency_id" class="form-select form-select-lg" required><?php $__currentLoopData = $currencies; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $currency): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($currency->id); ?>"><?php echo e($currency->code); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select></div>

                <div class="col-md-4"><label class="easy-label required">تیل</label><select name="fuel_type_id" id="purchase_fuel_type" class="form-select form-select-lg" required onchange="fuelChanged()"><?php $__currentLoopData = $fuelTypes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $fuel): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($fuel->id); ?>" data-price="<?php echo e($fuel->purchase_price); ?>" data-unit="<?php echo e($fuel->unit); ?>"><?php echo e($fuel->name_ps ?: $fuel->name_en); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select></div>
                <div class="col-md-4"><label class="easy-label">کیفیت</label><select name="fuel_quality_id" class="form-select form-select-lg"><option value="">Normal</option><?php $__currentLoopData = $qualities; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $quality): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($quality->id); ?>"><?php echo e($quality->name); ?> - <?php echo e($quality->fuelType->name_en ?? ''); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select></div>
                <div class="col-md-4"><label class="easy-label required">ټانک</label><select name="tank_id" id="purchase_tank_id" class="form-select form-select-lg" required><?php $__currentLoopData = $tanks; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tank): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($tank->id); ?>" data-fuel="<?php echo e($tank->fuel_type_id); ?>"><?php echo e($tank->name); ?> | Stock <?php echo e(number_format($tank->current_qty,2)); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select></div>

                <div class="col-md-4"><label class="easy-label required">د مال مالک</label><select name="owner_type" id="owner_type" class="form-select form-select-lg" onchange="document.getElementById('purchase_customer_box').classList.toggle('d-none',this.value!=='customer')"><option value="own">زموږ مال</option><option value="customer">د مشتری/خلکو مال</option></select></div>
                <div class="col-md-4 d-none" id="purchase_customer_box"><label class="easy-label">مالک مشتری</label><select name="customer_id" class="form-select form-select-lg"><option value="">انتخاب</option><?php $__currentLoopData = $customers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $customer): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($customer->id); ?>"><?php echo e($customer->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select></div>
                <div class="col-md-4"><label class="easy-label">ټانکر نمبر</label><input name="tanker_no" class="form-control form-control-lg"></div>

                <div class="col-md-4"><label class="easy-label required">اندازه</label><input type="number" step="0.001" name="quantity" id="pqty" class="form-control form-control-lg" required oninput="pcalc()"></div>
                <div class="col-md-4"><label class="easy-label">تعریف شوی خرید قیمت</label><div class="form-control form-control-lg bg-light fw-bold" id="purchasePriceText">0</div></div>
                <div class="col-md-4"><label class="easy-label required">ورکړل شوې پیسې</label><input type="number" step="0.01" name="paid_amount" id="ppaid" value="0" class="form-control form-control-lg" required oninput="pcalc()"></div>

                <div class="col-md-4"><label class="easy-label">ډرایور</label><input name="driver_name" class="form-control form-control-lg"></div>
                <div class="col-md-8"><label class="easy-label">یادښت</label><input name="notes" class="form-control form-control-lg" placeholder="اختیاري یادښت"></div>
            </div>
        </div>
    </div>
    <div class="col-lg-4">
        <div class="top-card sticky-top" style="top:18px">
            <h5 class="fw-bold"><i class="fa-solid fa-oil-can text-success"></i> حساب</h5>
            <div class="summary-box mt-3">
                <div class="d-flex justify-content-between"><span>ټول مبلغ</span><strong id="ptotalText">0.00</strong></div>
                <div class="d-flex justify-content-between text-danger"><span>باقي</span><strong id="pdueText">0.00</strong></div>
            </div>
            <button class="btn btn-success btn-lg w-100 mt-3"><i class="fa-solid fa-save"></i> Save / Stock زیات کړه</button>
            <a class="btn btn-light btn-lg w-100 mt-2" href="<?php echo e(route('dashboard')); ?>"><i class="fa-solid fa-house"></i> کور پاڼه</a>
            <div class="alert alert-info mt-3 mb-0">Purchase Save شي، ذخیره اتومات زیاتېږي.</div>
        </div>
    </div>
</div>
</form>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('js'); ?>
<script>
let purchaseRate = 0;
function fuelChanged(){
    let fuel = document.getElementById('purchase_fuel_type');
    let opt = fuel.selectedOptions[0];
    purchaseRate = parseFloat(opt.dataset.price || 0);
    document.getElementById('purchasePriceText').innerText = purchaseRate.toFixed(2) + ' / ' + (opt.dataset.unit || '');
    filterPurchaseTanks();
    pcalc();
}
function pcalc(){
    let total = (parseFloat(document.getElementById('pqty').value)||0) * purchaseRate;
    let paid = parseFloat(document.getElementById('ppaid').value)||0;
    document.getElementById('ptotalText').innerText = total.toFixed(2);
    document.getElementById('pdueText').innerText = Math.max(total-paid,0).toFixed(2);
}
function filterPurchaseTanks(){
    let id = document.getElementById('purchase_fuel_type').value;
    let tank = document.getElementById('purchase_tank_id');
    let first = '';
    [...tank.options].forEach(o => { let ok = o.dataset.fuel == id; o.hidden = !ok; if(ok && !first) first = o.value; });
    tank.value = first;
}
fuelChanged();
</script>
<?php $__env->stopPush(); ?>

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