<?php $__env->startSection('title','Simple Stock'); ?>
<?php $__env->startSection('page_title','ذخیره - Add / Edit'); ?>

<?php $__env->startSection('content'); ?>
<div class="row g-3 mb-3">
    <?php $__currentLoopData = $tanks; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tank): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
    <div class="col-md-4">
        <div class="top-card h-100">
            <div class="d-flex justify-content-between align-items-start">
                <div><h5 class="fw-bold mb-1"><?php echo e($tank->name); ?></h5><span class="stock-pill"><?php echo e($tank->fuelType?->name_ps ?: $tank->fuelType?->name_en); ?></span></div>
                <i class="fa-solid fa-oil-can fs-2 text-success"></i>
            </div>
            <?php $percent = $tank->capacity > 0 ? min(100, ($tank->current_qty / $tank->capacity) * 100) : 0; ?>
            <div class="progress my-3" style="height:14px"><div class="progress-bar bg-success" style="width:<?php echo e($percent); ?>%"></div></div>
            <div class="d-flex justify-content-between"><span>ټوله ذخیره</span><strong><?php echo e(number_format($tank->current_qty,2)); ?></strong></div>
            <div class="d-flex justify-content-between"><span>زموږ مال</span><strong><?php echo e(number_format($tank->own_qty,2)); ?></strong></div>
            <div class="d-flex justify-content-between"><span>د خلکو مال</span><strong><?php echo e(number_format($tank->customer_qty,2)); ?></strong></div>
        </div>
    </div>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</div>

<div class="row g-3">
    <div class="col-lg-6">
        <form method="POST" action="<?php echo e(route('stock.add')); ?>" class="top-card h-100">
            <?php echo csrf_field(); ?>
            <h5 class="fw-bold"><i class="fa-solid fa-circle-plus text-success"></i> ذخیره اضافه کول</h5>
            <p class="mini-help">د شروع ذخیره یا اضافي مال لپاره. عادي خرید لپاره Purchase استعمال کړئ.</p>
            <div class="row g-3">
                <div class="col-md-6"><label class="easy-label required">تاریخ</label><input type="date" name="stock_date" value="<?php echo e(date('Y-m-d')); ?>" class="form-control form-control-lg" required></div>
                <div class="col-md-6"><label class="easy-label required">ټانک</label><select name="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); ?>" <?php if($selectedTankId == $tank->id): echo 'selected'; endif; ?>><?php echo e($tank->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select></div>
                <div class="col-md-6"><label class="easy-label required">مالک</label><select name="owner_type" id="stock_owner_type" class="form-select form-select-lg" onchange="document.getElementById('stock_customer_box').classList.toggle('d-none',this.value!=='customer')"><option value="own">زموږ مال</option><option value="customer">د خلکو/مشتری مال</option></select></div>
                <div class="col-md-6 d-none" id="stock_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-6"><label class="easy-label required">څومره اضافه شي؟</label><input type="number" step="0.001" name="quantity" class="form-control form-control-lg" required></div>
                <div class="col-md-6"><label class="easy-label">یادښت</label><input name="notes" class="form-control form-control-lg" placeholder="سبب"></div>
                <div class="col-12"><button class="btn btn-success btn-lg w-100"><i class="fa-solid fa-save"></i> ذخیره Save کړه</button></div>
            </div>
        </form>
    </div>
    <div class="col-lg-6">
        <form method="POST" action="<?php echo e(route('stock.correct')); ?>" class="top-card h-100">
            <?php echo csrf_field(); ?>
            <h5 class="fw-bold"><i class="fa-solid fa-pen-to-square text-warning"></i> ذخیره سمه کول</h5>
            <p class="mini-help">که په ټانک کې اصلي اندازه فرق ولري، دلته صحیح اندازه ولیکئ.</p>
            <div class="row g-3">
                <div class="col-md-6"><label class="easy-label required">تاریخ</label><input type="date" name="stock_date" value="<?php echo e(date('Y-m-d')); ?>" class="form-control form-control-lg" required></div>
                <div class="col-md-6"><label class="easy-label required">ټانک</label><select name="tank_id" id="manage_correct_tank" class="form-select form-select-lg" required onchange="manageFillCorrectStock()"><?php $__currentLoopData = $tanks; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tank): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($tank->id); ?>" <?php if($selectedTankId == $tank->id): echo 'selected'; endif; ?> data-own="<?php echo e($tank->own_qty); ?>" data-customer="<?php echo e($tank->customer_qty); ?>"><?php echo e($tank->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select></div>
                <div class="col-md-6"><label class="easy-label required">زموږ صحیح اندازه</label><input type="number" step="0.001" name="own_qty" id="manage_correct_own" class="form-control form-control-lg" required></div>
                <div class="col-md-6"><label class="easy-label required">د خلکو صحیح اندازه</label><input type="number" step="0.001" name="customer_qty" id="manage_correct_customer" class="form-control form-control-lg" required></div>
                <div class="col-12"><label class="easy-label">یادښت</label><input name="notes" class="form-control form-control-lg" placeholder="سبب"></div>
                <div class="col-12"><button class="btn btn-warning btn-lg w-100"><i class="fa-solid fa-check"></i> صحیح اندازه Save کړه</button></div>
            </div>
        </form>
    </div>
</div>

<div class="top-card mt-3">
    <h5 class="fw-bold mb-3">وروستي د ذخیرې حرکتونه</h5>
    <div class="table-responsive">
        <table class="table align-middle">
            <thead><tr><th>تاریخ</th><th>ټانک</th><th>داخل</th><th>خارج</th><th>باقي</th><th>یادښت</th></tr></thead>
            <tbody>
                <?php $__empty_1 = true; $__currentLoopData = $recentLedgers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ledger): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr><td><?php echo e($ledger->ledger_date); ?></td><td><?php echo e($ledger->tank?->name); ?></td><td class="text-success fw-bold"><?php echo e(number_format($ledger->qty_in,3)); ?></td><td class="text-danger fw-bold"><?php echo e(number_format($ledger->qty_out,3)); ?></td><td><?php echo e(number_format($ledger->balance,3)); ?></td><td><?php echo e($ledger->notes); ?></td></tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="6" class="text-muted">تر اوسه حرکت نشته.</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('js'); ?>
<script>
function manageFillCorrectStock(){let o=manage_correct_tank.selectedOptions[0];if(o){manage_correct_own.value=parseFloat(o.dataset.own||0).toFixed(3);manage_correct_customer.value=parseFloat(o.dataset.customer||0).toFixed(3)}}
manageFillCorrectStock();
</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/stock/manage.blade.php ENDPATH**/ ?>