<?php $__env->startSection('container'); ?>
    <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
        <h1 class="h2">Service</h1>
    </div>

    <div class="row">

        <div class="col-lg-3">
            <form action="<?php echo e(route('cekNota')); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <label for="nopol" class="form-label">Nomor Nota</label>
                <div class="input-group">
                    <input type="text" class="form-control" name="nota">
                    <button class="btn btn-outline-secondary" type="submit">
                        <i class="bi bi-search"></i>
                    </button>
                </div>
            </form>
        </div>
        
        <div class="col-lg-3"> <!-- Adjust the column width as needed -->
            <form method="post" action="/service" class="mb-3">
                <label for="nama" class="form-label">Nama</label>
                <input type="text" class="form-control"
                    <?php if($customers): ?> value="<?php echo e($customers->nama); ?>" <?php endif; ?> id="notelp" name="notelp"
                    disabled>
        </div>

        
        <div class="col-lg-3"> <!-- Adjust the column width as needed -->
            <div class="mb-">
                <label for="notelp" class="form-label">No Telpon</label>
                <input type="text" class="form-control"
                    <?php if($customers): ?> value="<?php echo e($customers->telp); ?>" <?php endif; ?> id="notelp" name="notelp"
                    disabled>

            </div>
        </div>


        
        <div class="col-lg-3"> <!-- Adjust the column width as needed -->
            <label for="jenis" class="form-label">Jenis Mobil</label>
            <input type="text" class="form-control"
                <?php if($customers): ?> value="<?php echo e($customers->type); ?>" <?php endif; ?> id="notelp" name="notelp"
                disabled>
        </div>
    </div>


    <div class="row">
        
        <div class="col-lg-3">
            <form action="<?php echo e(route('cek')); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <label for="nopol" class="form-label">No Polisi</label>
                <div class="input-group">
                    <input type="text" class="form-control <?php $__errorArgs = ['nopol'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" id="nopol"
                        <?php if($customers): ?> value="<?php echo e($customers->no_polisi); ?>" <?php endif; ?> name="nopol" required
                        value="<?php echo e(old('nopol')); ?>">
                    <button class="btn btn-outline-secondary" type="submit">
                        <i class="bi bi-search"></i> <!-- Magnifying glass icon -->
                    </button>
                </div>
                <?php $__errorArgs = ['nopol'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                    <div class="invalid-feedback">
                        <?php echo e($message); ?>

                    </div>
                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
            </form>
        </div>

        
        <div class="col-lg-3">
            <form action="<?php echo e(route('tambahHistory')); ?>" method="POST">
                <?php echo csrf_field(); ?>
            <label for="kilometer" class="form-label">Kilometer</label>
            <input type="text" class="form-control  <?php $__errorArgs = ['kilometer'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" id="kilometer"
                name="kilometer" required value="<?php echo e(old('kilometer')); ?>">
            <?php $__errorArgs = ['kilometer'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                <div class="invalid-feedback">
                    <?php echo e($message); ?>

                </div>
            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
        </div>
        
        <div class="col-lg-3 mb-3">
            <label for="pegawai" class="form-label">Pegawai</label>
            <select class="form-select" name="employee_id" required>
                <option value="">-Pilih Pegawai-</option>
                <?php $__currentLoopData = $pegawai; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($data->id); ?>"><?php echo e($data->nama); ?></option>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
        </div>

        

    </div>
    <div class="row mb-3">
        <div class="col-lg-3">
            <input type="hidden" name="customer_id" <?php if($customers): ?> value="<?php echo e($customers->customer_id); ?>" <?php endif; ?>  id="">
            <input type="hidden" name="no_polisi" <?php if($customers): ?> value="<?php echo e($customers->no_polisi); ?>" <?php endif; ?>  id="">
            <input type="hidden" name="jenis_mobil" <?php if($customers): ?> value="<?php echo e($customers->type); ?>" <?php endif; ?>  id="">
            <button class="btn btn-primary">Simpan</button>
        </form>
        </div>
    </div>

<?php $__env->stopSection(); ?>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<script>
    $(document).ready(function() {
        function calculateTotalHarga() {
            var hargaBarang = parseFloat($('#harga_barang').val());
            var jumlah = parseInt($('#jumlah').val());
            if (!isNaN(hargaBarang) && !isNaN(jumlah)) {
                var totalHarga = hargaBarang * jumlah;
                $('#total_harga').val(totalHarga);
                calculateHargaAkhir(); // Panggil fungsi untuk menghitung harga akhir
            } else {
                $('#total_harga').val('');
            }
        }

        function calculateHargaAkhir() {
            var totalHarga = parseFloat($('#total_harga').val());
            var discount = parseFloat($('#discount').val());
            if (!isNaN(totalHarga) && !isNaN(discount)) {
                var hargaAkhir = totalHarga - (totalHarga * (discount / 100));
                $('#harga_akhir').val(hargaAkhir); // Format ke dua angka di belakang koma
            } else {
                $('#harga_akhir').val('');
            }
        }

        $('#stock_id').change(function() {
            var stockId = $(this).val();
            if (stockId) {
                $.ajax({
                    url: '/get-stock/' + stockId,
                    type: 'GET',
                    dataType: 'json',
                    success: function(data) {
                        if (data.harga_barang !== null) {
                            $('#harga_barang').val(data.harga_barang);
                            calculateTotalHarga();
                        } else {
                            $('#harga_barang').val('');
                            $('#total_harga').val('');
                            $('#harga_akhir').val('');
                        }
                    },
                    error: function() {
                        $('#harga_barang').val('');
                        $('#total_harga').val('');
                        $('#harga_akhir').val('');
                    }
                });
            } else {
                $('#harga_barang').val('');
                $('#total_harga').val('');
                $('#harga_akhir').val('');
            }
        });

        $('#jumlah, #discount').on('input', function() {
            calculateTotalHarga();
        });

        $('#discount').on('input', function() {
            calculateHargaAkhir();
        });
    });
</script>


<?php echo $__env->make('dashboard.layouts.main', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\Coding Skripsi\bengkel\resources\views/service/index.blade.php ENDPATH**/ ?>