<?php $__env->startSection('title', 'Detail Transaksi'); ?>
<?php $__env->startSection('active3', 'active'); ?>
<?php $__env->startSection('content'); ?>

    <style>
        .selectpicker {
            width: 50%;
            background-color: blue;
        }
    </style>

    <div class="content-wrapper">
        <div class="container-xxl flex-grow-1 container-p-y">
            <!-- Invoice List Table -->
            <div class="card">
                <div class="header-menu d-flex justify-content-start align-items-center">
                    <a href="<?php echo e(route('transaksi.index')); ?>" class=" ms-5"><i class="bx bx-left-arrow-alt"></i></a>
                    <h4 class="card-header">Detail Transaksi</h4>

                </div>
                <div class="card-body">

                    <div class="row g-0">
                        <!-- Foto Profil -->
                        <div class="col-md-6 ps-4 pe-4">
                            <!-- Card for Each Transaction -->
                            <div class="card card-custom">
                                <!-- Example Image, you can replace with actual laundry photo -->
                                <img src="<?php echo e(asset('laundry2.png')); ?>" alt="Laundry Image" class="card-img-top"
                                    width="100%" height="100" style="object-fit: cover;">
                                <div class="card-body card-body-custom">
                                    <h5 class="card-title">
                                        <i class="bx bx-receipt text-primary"></i>
                                        <span class="text-uppercase"><?php echo e($transaksi->kode_transaksi); ?></span>
                                    </h5>
                                    <hr>
                                    <p class="card-text">
                                        <i class="bx bx-calendar text-muted"></i>
                                        <strong>Tanggal:</strong>
                                        <?php echo e(\Carbon\Carbon::parse($transaksi->tgl_transaksi)->format('d M Y')); ?>

                                    </p>
                                    <p class="card-text">
                                        <i class="bx bx-user text-muted"></i>
                                        <strong>Pelanggan:</strong> <?php echo e($transaksi->pelanggan->nama); ?>

                                    </p>
                                    <p class="card-text">
                                        <i class="bx bx-box text-muted"></i>
                                        <strong style="font-size: 12px">Input oleh:</strong>
                                        <span style="font-size: 12px">
                                            <?php echo e($transaksi->pegawai->nama); ?>

                                        </span>

                                    </p>

                                    <div class="d-flex justify-content-between align-items-center mt-3">

                                        <div class="boxnya d-flex align-items-center justify-content-between">
                                            <span class="card-price text-success">
                                                <i class="bx bx-money"></i> Rp
                                                <?php echo e(number_format($transaksi->total_harga, 0, ',', '.')); ?>

                                            </span>

                                        </div>
                                        <div class="boxnya d-flex align-items-center justify-content-between gap-2">

                                            <a href="<?php echo e(route('transaksi.show', $transaksi->id)); ?>"
                                                class="btn btn-sm btn-warning" data-bs-toggle="modal"
                                                data-bs-target="#staticBackdrop"><?php echo e($transaksi->is_bayar == 0 ? 'Bayar Sekarang' : 'Sudah Bayar'); ?>

                                            </a>
                                            <a href="#" class="btn btn-sm btn-secondary "><i
                                                    class="bx bx-printer"></i>Cetak</a>
                                        </div>


                                    </div>
                                </div>

                            </div>
                        </div>

                        <!-- Modal -->
                        <div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false"
                            tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
                            <div class="modal-dialog modal-md">
                                <div class="modal-content ">
                                    <div class="modal-header">
                                        <h5 class="modal-title" id="staticBackdropLabel">Pembayaran</h5>
                                        <button type="button" class="btn-close" data-bs-dismiss="modal"
                                            aria-label="Close"></button>
                                    </div>
                                    <div class="modal-body">
                                        <form action="<?php echo e(route('parfum.store')); ?>" method="POST"
                                            enctype="multipart/form-data">
                                            <?php echo csrf_field(); ?>
                                            <div class="row">
                                                <!-- Kolom Kiri -->
                                                <div class="col-md-12">

                                                    <div class="mb-3">
                                                        <label for="nama_parfum" class="form-label">Kode Transaksi</label>
                                                        <input type="text" class="form-control" id="nama_parfum"
                                                            name="nama_parfum" placeholder="Masukkan Nama Parfum"
                                                            value="<?php echo e($transaksi->kode_transaksi); ?>" readonly>
                                                    </div>
                                                    <div class="mb-3">
                                                        <label for="nama_parfum" class="form-label">Total Harga</label>
                                                        <input type="text" class="form-control" id="total_harga"
                                                            name="nama_parfum" readonly
                                                            value="<?php echo e($transaksi->total_harga); ?>" required>
                                                    </div>
                                                    <div class="mb-3 d-none" id="nominal_bayar">
                                                        <label for="nama_parfum" class="form-label">Nominal Bayar</label>
                                                        <input type="number" class="form-control" id="nominal_bayar_input"
                                                            name="nominal">
                                                    </div>
                                                    <div class="mb-3 d-none" id="nominal_kembalian">
                                                        <label for="nominal_kembalian" class="form-label">Kembalian</label>
                                                        <input type="number" class="form-control"
                                                            id="nominal_kembalian_input" name="kembalian">
                                                    </div>



                                                    <?php
                                                        $metode = App\Models\Metode_Pembayaran::where(
                                                            'laundry_id',
                                                            $transaksi->laundry_id,
                                                        )->get();
                                                    ?>

                                                    <div class="mb-4" id="metode-pembayaran">
                                                        <label class="form-label mb-2">Metode Pembayaran</label>
                                                        <br>
                                                        <div class="form-check-inline">
                                                            <input class="form-check-input" type="radio" name="is_cash"
                                                                id="cash" value="1">
                                                            <label class="form-check-label" for="flexRadioCash">
                                                                Cash
                                                            </label>
                                                        </div>
                                                        <div class="form-check-inline">
                                                            <input class="form-check-input" type="radio" name="is_cash"
                                                                value="0" id="transfer">
                                                            <label class="form-check-label" for="flexRadioTransfer">
                                                                Transfer
                                                            </label>
                                                        </div>
                                                    </div>

                                                    <div class="mb-4 d-none" id="pilih-pembayaran-transfer">
                                                        <label for="smallSelect" class="form-label">Jenis
                                                            Pembayaran</label>
                                                        <select class="form-select form-select-sm" name="metode_bayar_id">
                                                            <option value="">--Pilih Metode Pembayaran--
                                                            </option>
                                                            <?php if($metode != null): ?>
                                                                <?php $__currentLoopData = $metode; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $metode): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <option value="<?php echo e($metode->id); ?>">
                                                                        <?php echo e($metode->jenis_pembayaran); ?> -
                                                                        <?php echo e($metode->no_rek); ?></option>
                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            <?php endif; ?>
                                                        </select>
                                                    </div>

                                                    <!-- Logo Brand -->
                                                    <div class="mb-3 d-none" id="bukti-bayar">
                                                        <label for="logo_brand" class="form-label">Bukti
                                                            Pembayaran</label>
                                                        <input type="file" class="form-control" id="bukti-bayar"
                                                            name="bukti_bayar">
                                                    </div>


                                                </div>
                                            </div>

                                    </div>

                                    <div class="modal-footer">
                                        
                                        <button type="submit" class="btn btn-primary">Simpan</button>
                                    </div>
                                    </form>
                                </div>
                            </div>
                        </div>


                        
                        <!-- Detail Profil -->
                        <div class="col-md-6">
                            <div class="card ps-4 pb-4">
                                <?php

                                    $kasir = App\Models\Kasir::where('id', $transaksi->kasir_id)->first();
                                ?>

                                <div class="card-body">
                                    <h5 class="card-title p-4">Informasi Kasir</h5>
                                    <div class="row">

                                        <div class="col-md-3">

                                            <div class=" d-flex flex-column align-items-center ">
                                                <?php

                                                    if ($kasir != null) {
                                                        # code...
                                                        $pegawai = App\Models\Pegawai::where(
                                                            'users_id',
                                                            $kasir->users_id,
                                                        )->first();

                                                        // hitung transaksi dari laundry ini
                                                        $total_trx = App\Models\Transaksi::where(
                                                            'laundry_id',
                                                            $kasir->laundry_id,
                                                        )
                                                            ->where('kasir_id', $kasir->id)
                                                            ->count();

                                                        $paid_trx = App\Models\Transaksi::where(
                                                            'laundry_id',
                                                            $kasir->laundry_id,
                                                        )
                                                            ->where('kasir_id', $kasir->id)
                                                            ->where('is_bayar', 1)
                                                            ->count();
                                                        $unpaid_trx = App\Models\Transaksi::where(
                                                            'laundry_id',
                                                            $kasir->laundry_id,
                                                        )
                                                            ->where('kasir_id', $kasir->id)
                                                            ->where('is_bayar', 0)
                                                            ->count();
                                                    } else {
                                                        $pegawai = null;
                                                        $today_trx = null;
                                                        $paid_trx = null;
                                                        $unpaid_trx = null;
                                                    }

                                                ?>

                                                <?php if($kasir != null): ?>
                                                    <img src="<?php echo e(asset('storage/img' . '/' . $pegawai->foto)); ?>" alt
                                                        class=" h-auto" style="width: 100px; object-fit: cover" />
                                                <?php else: ?>
                                                    <img src="<?php echo e(asset('template/assets/img/avatars/1.png')); ?>"
                                                        alt="" class=" h-auto"
                                                        style="width: 150px; object-fit: cover">
                                                <?php endif; ?>
                                                <p class="icon-name text-capitalize text-truncate mt-2">
                                                    <?php echo e($pegawai ? $pegawai->nama : '-'); ?></p>


                                            </div>
                                        </div>
                                        <div class="col-md-9">
                                            <div class="row">
                                                <div class="col-sm-6">
                                                    <div class="mb-1">
                                                        <label for="smallInput" class="form-label">Laundry</label>
                                                        <input type="text" class="form-control form-control-sm"
                                                            placeholder="Laundry"
                                                            value="<?php echo e($pegawai ? $pegawai->laundry->nama_laundry : '-'); ?>"
                                                            readonly>
                                                    </div>
                                                    <div class="mb-1">
                                                        <label for="smallInput" class="form-label">Tgl.
                                                            Buka
                                                            Kasir</label>
                                                        <input type="text" class="form-control form-control-sm"
                                                            placeholder="Tgl. Transaksi"
                                                            value="<?php echo e($kasir ? $kasir->tgl_buka : '-'); ?>" readonly>
                                                    </div>
                                                    <div class="mb-1">
                                                        <label for="smallInput" class="form-label">Jam
                                                            Buka</label>
                                                        <input type="text" class="form-control form-control-sm"
                                                            placeholder="Tgl. Transaksi"
                                                            value="<?php echo e($kasir ? $kasir->jam_buka : '-'); ?>" readonly>
                                                    </div>
                                                </div>
                                                <div class="col-sm-6">
                                                    <div class="mb-1">
                                                        <label for="smallInput" class="form-label">Tgl. Tutup
                                                            Kasir</label>
                                                        <input type="text" class="form-control form-control-sm"
                                                            placeholder="-"
                                                            value="<?php echo e($kasir ? $kasir->tgl_tutup : '-'); ?>" readonly>
                                                    </div>
                                                    <div class="mb-1">
                                                        <label for="smallInput" class="form-label">Jam
                                                            Tutup</label>
                                                        <input type="text" class="form-control form-control-sm"
                                                            placeholder="-"
                                                            value="<?php echo e($kasir ? $kasir->jam_tutup : '-'); ?>" readonly>
                                                    </div>
                                                </div>
                                            </div>


                                        </div>

                                    </div>

                                    

                                </div>
                            </div>

                        </div>

                    </div>

                    <div class="row">
                        <div class="col-md-12">
                            <div class="card-body">
                                <h5 class="card-title">Detail Transaksi</h5>
                                <div class="table-responsive">
                                    <table class="table table-bordered table-hover" id="Mytable">
                                        <thead class="table-primary text-center">
                                            <tr>
                                                <th>Action</th>
                                                <th>Id</th>
                                                <th>Penanggung Jawab</th>
                                                <th>Paket</th>
                                                <th>Qty</th>
                                                <th>Min. Pemakaian Bahan Baku</th>
                                                <th>Harga Satuan</th>
                                                <th>Total Harga</th>
                                                <th>Mesin</th>
                                                
                                                <th>Status</th>
                                            </tr>
                                        </thead>
                                        <tbody>

                                            <?php $__currentLoopData = $detail; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $detail): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <?php
                                                    $pegawai = \App\Models\PegawaiPaket::where(
                                                        'paket_id',
                                                        $detail->paket_id,
                                                    )->get();
                                                ?>
                                                <tr>
                                                    <td>
                                                        <form action="<?php echo e(route('transaksi.update', $detail->id)); ?>"
                                                            method="POST">
                                                            <?php echo csrf_field(); ?>
                                                            <?php echo method_field('POST'); ?>


                                                            <button type="submit" class="btn btn-primary btn-sm"><i
                                                                    class="bx bx-save text-white"></i></button>
                                                            <input type="hidden" name="paket_idnya"
                                                                value="<?php echo e($detail->paket_id); ?>">
                                                            <input type="hidden" name="qty"
                                                                value="<?php echo e($detail->qty); ?>">

                                                            <input type="hidden" name="transaksi_id"
                                                                value="<?php echo e($detail->transaksi_id); ?>">
                                                    </td>
                                                    <td class="text-center"><?php echo e($detail->id); ?></td>
                                                    <td>
                                                        <?php if($detail->pegawai_id == null): ?>
                                                            <select name="pegawai_id" class="js-example-tags" required>
                                                                <option value="">-Pilih Pegawai-</option>
                                                                <?php $__currentLoopData = $pegawai; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <option value="<?php echo e($item->pegawai->id); ?>">
                                                                        <?php echo e($item->pegawai->nama); ?></option>
                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            </select>
                                                        <?php else: ?>
                                                            <?php echo e($detail->pegawai->nama); ?>

                                                        <?php endif; ?>
                                                    </td>
                                                    <td><?php echo e($detail->paket->nama_paket); ?>

                                                        (<?php echo e($detail->paket->satuan); ?>)
                                                    </td>
                                                    <td class="text-center">
                                                        <?php echo e($detail->qty . '' . $detail->paket->satuan); ?></td>

                                                    
                                                    <?php
                                                        $bahan_baku_paket = \App\Models\BahanBakuPaket::where(
                                                            'paket_id',
                                                            $detail->paket_id,
                                                        )->get();
                                                    ?>

                                                    <td>
                                                        <?php $__currentLoopData = $bahan_baku_paket; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $paket): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                            <ul>
                                                                <li style="font-size: 12px">
                                                                    <?php echo e($paket->barang->nama_barang . '(' . $paket->qty * $detail->qty . '' . $paket->barang->satuan . ')'); ?>

                                                                </li>
                                                            </ul>
                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                    </td>



                                                    <td class="text-right">Rp
                                                        <?php echo e(number_format($detail->harga, 0, ',', '.')); ?></td>
                                                    <td class="text-right">Rp
                                                        <?php echo e(number_format($detail->total_harga, 0, ',', '.')); ?></td>
                                                    <?php
                                                        $mesinnya = \App\Models\Mesin::where(
                                                            'laundry_id',
                                                            $transaksi->laundry_id,
                                                        )->get();

                                                        $detail_mesin_trx = \App\Models\DetailTransaksiMesin::where(
                                                            'detail_trx_id',
                                                            $detail->id,
                                                        )->get();

                                                    ?>
                                                    <td>
                                                        <?php if($detail_mesin_trx->isEmpty()): ?>
                                                            <select name="mesin_id[]" class="js-example-tags form-control"
                                                                multiple="multiple" data-width="100%" required>
                                                                <option value="">--Pilih Mesin--</option>
                                                                <?php $__currentLoopData = $mesinnya; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <option value="<?php echo e($item->id); ?>">
                                                                        <?php echo e($item->nama_mesin); ?></option>
                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            </select>
                                                        <?php else: ?>
                                                            <ul>
                                                                <?php $__currentLoopData = $detail_mesin_trx; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $mesin): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <li>
                                                                        <?php echo e($mesin->mesin->nama_mesin); ?>

                                                                    </li>
                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            </ul>
                                                        <?php endif; ?>
                                                        </form>

                                                        <script>
                                                            $(document).ready(function() {
                                                                $(".js-example-tags").select2({
                                                                    tags: true,
                                                                    width: 'resolve'
                                                                });
                                                            });
                                                        </script>

                                                    </td>
                                                    <td class="text-center">
                                                        <?php if($detail->status == 'baru'): ?>
                                                            <span class="badge bg-warning text-dark">Baru</span>
                                                        <?php elseif($detail->status == 'proses'): ?>
                                                            <span class="badge bg-info text-white">Proses</span>
                                                        <?php else: ?>
                                                            <span class="badge bg-success text-white">Selesai</span>
                                                        <?php endif; ?>
                                                    </td>
                                                </tr>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </tbody>
                                    </table>
                                </div>

                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>

<?php $__env->stopSection(); ?>


<?php $__env->startPush('js'); ?>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.14.0-beta2/js/bootstrap-select.min.js"></script>


    <script>
        $(document).ready(function() {
            $('.selectpicker').selectpicker({
                width: '50%' // Ensure it's 100% width for responsiveness
            });
        });

        // Optional: Refresh selectpicker on window resize
        $(window).on('resize', function() {
            $('.selectpicker').selectpicker('refresh');
        });

        // jika yang dipilih sudahbayar tarnsfer
        $('#transfer').on('change', function() {
            if ($(this).is(':checked')) {
                $('#pilih-pembayaran-transfer').removeClass('d-none');
                $('#bukti-bayar').removeClass('d-none');
                $('#nominal_bayar').addClass('d-none');
                $('#nominal_kembalian').addClass('d-none');
            } else {
                $('#bukti-bayar').addClass('d-none');
                $('#pilih-pembayaran-transfer').addClass('d-none');
            }
        })

        $('#nominal_bayar').on('keyup', function() {
            var nominal_bayar = parseFloat($('#nominal_bayar_input').val()) || 0; // Default to 0 if empty
            var total_harga = parseFloat($('#total_harga').val()) || 0;
            var nominal_kembalian = nominal_bayar - total_harga;
            $('#nominal_kembalian_input').val(nominal_kembalian); // Format to 2 decimal places
        });


        // jika yang dipilih sudahbayar tunai
        $('#cash').on('change', function() {
            if ($(this).is(':checked')) {
                $('#pilih-pembayaran-transfer').addClass('d-none');
                $('#nominal_bayar').removeClass('d-none');
                $('#nominal_kembalian').removeClass('d-none');
                $('#bukti-bayar').addClass('d-none');
            } else {
                $('#nominal_bayar').addClass('d-none');
                $('#nominal_kembalian').addClass('d-none');
                $('#pilih-pembayaran-transfer').removeClass('d-none');
            }
        })
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('component.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp_2\htdocs\Laundry\resources\views/transaksi/detail.blade.php ENDPATH**/ ?>