
{{-- head start --}}
@php
    use Carbon\Carbon;
    Carbon::setLocale('id');

     // MENGAMBIL PARAMETER DARI URL
    $tampilkanPpn = request()->query('ppn', 'yes') == 'yes'; // Default: 'yes'

    // ASUMSI: $PPN dan $totalBiaya sudah dihitung di Controller.
    // Jika $PPN adalah PPN murni (10%) dan $totalBiaya adalah (Total Harga Pesanan + Ongkir + PPN)

    $ppnDitampilkan = 0;
    $totalAkhir = $totalBiaya; // Asumsi $totalBiaya sudah termasuk PPN

    if (!$tampilkanPpn) {
        // Jika PPN TIDAK ditampilkan, kita kurangi PPN dari total biaya
        $ppnDitampilkan = 0;
        $totalAkhir = $totalBiaya - $PPN;
    } else {
        // Jika PPN ditampilkan, gunakan nilai PPN yang sebenarnya
        $ppnDitampilkan = $PPN;
        $totalAkhir = $totalBiaya;
    }
@endphp

<style>
    .printable-area {
        width: auto; /* Atur lebar sesuai ukuran struk thermal Anda */
        height: auto;
        align-content: center;
        font-family: Arial, Helvetica, sans-serif;
        /* margin: 0 auto; Agar berada di tengah */
    }

    .table-transaksi {
        width: auto;
        page-break-inside: avoid; /* Hindari pemutusan halaman dalam tabel */
    }

    .table-transaksi thead tr th {
        width: auto;
    }

    .table-transaksi tbody tr td {
        font-size: 38px;
    }

    .conten-nota {
        font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
        font-size: px; /* Sesuaikan ukuran font */
        margin: 0; /* Hapus margin untuk menghemat ruang */
    }

    .nota-head {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    /* Tambahkan properti ini untuk memastikan halaman tidak terpisah */
    @media print {
        .printable-area, .table-transaksi, .section_nama_pesanan_qty_harga, .conten-nota {
            page-break-inside: avoid; /* Hindari pemutusan halaman dalam area ini */
            page-break-after: auto; /* Tambahkan properti ini untuk menghindari pemisahan halaman */
            page-break-before: auto; /* Tambahkan properti ini untuk menghindari pemisahan halaman */
        }
        .printable-area {
            break-inside: avoid; /* Untuk mendukung berbagai browser */
        }
    }
</style>

@include('component.head')
{{-- head end --}}

<div class="printable-area">
    <!-- Isi dari nota transaksi yang ingin dicetak -->
    <div style="text-align:center;">
        <img style="width: 45vw; margin: 0 auto;"  src="{{ asset('asset-modified/image/logo-usaha.jpg') }}" alt="img warung makan">
        <p style="font-size: 37px;">Pusat  : Jln. Wahidin II No. 3A Jakarta Pusat Telp. 021-3810137</p>
        <p style="font-size: 37px;">Cabang : Jln. Raya Radar Auri No.63 Cisalak - Depok Telp. 021-8733461 Wa.0857 8888 6617</p></div>
    <h1 style="font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-size:40px;" class="text-center">Nota transaksi</h1>
    <div class="text-center" style="font-size: 50px;">
        @foreach ($transaksiSerupa as $tS )
            <div class="col" style="font-size: 55px;">
            @if ($loop->first || $tS->jenis_pesanan != $transaksiSerupa[$loop->index - 1]->jenis_pesanan)
            <td style="vertical-align:middle;" rowspan="{{ $transaksiSerupa->where('jenis_pesanan', $tS->jenis_pesanan)->count() }}">
                {{ Carbon::parse($tS->created_at)->translatedFormat('l, d F Y') }}
            </td>
            
            @endif
        </div>
        @endforeach
    </div>
    <div class="text-center" style="font-size: 50px;">
        @foreach ($transaksiSerupa as $tS )
            <div class="col" style="font-size: 55px;">
            @if ($loop->first || $tS->jenis_pesanan != $transaksiSerupa[$loop->index - 1]->jenis_pesanan)
            <td style="vertical-align:middle; text-align:center; align-items:center;" rowspan="{{ $transaksiSerupa->where('jenis_pesanan', $tS->jenis_pesanan)->count() }}"> 
                {{ $tS->jenis_pesanan }} 
            </td>
            <br>
            <td style="vertical-align:middle; text-align:center; align-items:center;" rowspan="{{ $transaksiSerupa->where('jenis_pesanan', $tS->jenis_pesanan)->count() }}"> 
                {{ $tS->status_bayar}} 
            </td>
            @endif
        </div>
        @endforeach
    </div>
    
    <h3 class="text-center">----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------</h3>
    
    <div class="row">
        <div class="col" style="text-align: start;">
            <div>
                <h4 style="font-weight: 700; font-size:45px">Kode Pesanan</h4>
            </div>
            @foreach ($transaksiSerupa as $tS )            
                <div style="font-size: 45px;">
                    @if ($loop->first || $tS->kode_pesanan != $transaksiSerupa[$loop->index - 1]->kode_pesanan)
                    <td style="vertical-align:middle; font-size:30px text-align:center; align-items:center;" rowspan="{{ $transaksiSerupa->where('kode_pesanan', $tS->kode_pesanan)->count() }}"> 
                    {{ $tS->kode_pesanan }} 
                    </td>
                    @endif
                </div>
            @endforeach               
            <div>
                <h4 style="font-weight: 700; font-size:45px">Pembayaran</h4>
            </div>
            <div>
                @foreach ($transaksiSerupa as $tS )            
                <div style="font-size: 45px;">
                    @if ($loop->first || $tS->metode_bayar != $transaksiSerupa[$loop->index - 1]->metode_bayar)
                    <td style="vertical-align:middle; color:green; text-align:center; align-items:center;" rowspan="{{ $transaksiSerupa->where('metode_bayar', $tS->metode_bayar)->count() }}"> 
                    {{ $tS->metode_bayar }} 
                    </td>
                    @endif
                </div>
                @endforeach  
            </div>
        </div>
            
        <div class="col" style="text-align: end;">
            <div>
                <h4 style="font-weight: 700; font-size:45px">Kasir</h4>
            </div>
            @foreach ($transaksiSerupa as $tS )
                <div style="font-size: 45px;">
                    @if ($loop->first || $tS->nama_kasir != $transaksiSerupa[$loop->index - 1]->nama_kasir)
                    <td style="vertical-align:middle; font-size:30px text-align:center; align-items:center;" rowspan="{{ $transaksiSerupa->where('nama_kasir', $tS->nama_kasir)->count() }}"> 
                       {{ $tS->nama_kasir }} 
                    </td>
                    @endif
                </div>
            @endforeach
            <div>
                <h4 style="font-weight: 700; font-size:45px">Nama Pemesan</h4>
            </div>
            @foreach ($transaksiSerupa as $tS )
                <div style="font-size: 45px;">
                    @if ($loop->first || $tS->nama_pemesan != $transaksiSerupa[$loop->index - 1]->nama_pemesan)
                    <td style="vertical-align:middle; text-align:center; align-items:center;" rowspan="{{ $transaksiSerupa->where('nama_pemesan', $tS->nama_pemesan)->count() }}"> 
                    {{ $tS->nama_pemesan }} 
                    </td>
                    @endif
                </div>
            @endforeach
        </div>
    </div>
    
    <h1 class="text-center">---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------</h1>
    
    <div class="row section_nama_pesanan_qty_harga">
        <div class="col">
            <table style="width: 100%;">
                @foreach ($transaksiSerupa as $dT)
                    <tr style="font-size:60px;">
                        <td>{{ $dT->pesanan }}</td>
                        <td style="font-size: 30px; text-align: center;">X</td>
                        <td style="text-align: center;">{{ $dT->qty }}</td>
                        <td class="text-center">{{ number_format($dT->harga_pesanan_plus_qty, 0, ',', '.') }}</td>
                    </tr>
                @endforeach
            </table>
        </div>
    </div>
    
    <h1 class="text-center">----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------</h1>
    
    <h1 style="font-size: 45px; font-weight:800;">Payment Details</h1>
    
    <div class="row conten-nota">
        <div class="col">
            <br>
            <div style="font-size: 55px">
                <h1>Total</h1>
            </div>
            <div style="font-size: 55px">
                <h1>Ongkir</h1>
            </div>
        </div>
        <div class="col" style="text-align: end;">
            <div style="font-size: 55px">
                @foreach ($transaksiSerupa as $tS )
                    <div>
                        <td rowspan="{{ $transaksiSerupa->where('total_harga_pesanan', $tS->total_harga_pesanan)->count() }}"> 
                        @if ($loop->first || $tS->total_harga_pesanan != $transaksiSerupa[$loop->index - 1]->total_harga_pesanan)
                        {{ number_format($tS->total_harga_pesanan, 0,',','.') }} 
                        @endif
                        </td>
                    </div>
                @endforeach
            </div>
                <div style="font-size: 55px">
                        @foreach ($transaksiSerupa as $tS )
                            <div>
                                <td style="" rowspan="{{ $transaksiSerupa->where('ongkir', $tS->ongkir)->count() }}"> 
                                @if ($loop->first || $tS->ongkir != $transaksiSerupa[$loop->index - 1]->ongkir)
                                {{ number_format($tS->ongkir, 0,',','.') }} 
                                @endif
                                </td>
                            </div>
                        @endforeach
                    </div>
                </div>
                @if ($tampilkanPpn)
                    <div class="row" style="font-size: 55px" >
                        <div class="col">
                            <th>PPN (10%)</th>
                        </div>
                        <div class="col" style="text-align: end; display:flex; flex-direction:column; margin:0; padding:0;">
                            <td style="text-align: end;">
                                {{ number_format($ppnDitampilkan, 0,',','.') }}
                            </td>
                        </div>
                    </div>
                @endif

                <div class="row" style="font-size: 55px" >
                    <div class="col">
                        <th>Total Harga</th>
                    </div>
                    <div class="col" style="text-align: end; display:flex; flex-direction:column; margin:0; padding:0;">
                        <td style="text-align: end;">
                            {{ number_format($totalAkhir, 0,',','.') }}
                        </td>
                    </div>
                </div>
      </div>
      @if($transaksiSerupa->where('alamat_delivery_order', '!=', null)->isNotEmpty() || $transaksiSerupa->where('no_hp_customer', '!=', null)->isNotEmpty())
      <h1 class="text-center">-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------</h1>
      <h1 style="font-size: 40px; font-weight:600">Detail Delivery Order</h1>
      <p style="font-size: 50px;">
        @foreach ($transaksiSerupa as $tS )
        @if ($loop->first || $tS->alamat_delivery_order != $transaksiSerupa[$loop->index - 1]->alamat_delivery_order)
        <td rowspan="{{ $transaksiSerupa->where('alamat_delivery_order', $tS->alamat_delivery_order)->count() }}"> 
        {{ $tS->alamat_delivery_order }} 
        </td>
        @endif
        @if ($loop->first || $tS->no_hp_customer != $transaksiSerupa[$loop->index - 1]->no_hp_customer)
        <td rowspan="{{ $transaksiSerupa->where('no_hp_customer', $tS->no_hp_customer)->count() }}"> 
        {{ $tS->no_hp_customer }} 
        </td>
        @endif
        @endforeach
      </p>
    @endif
      <br>
      <tfoot class="mt-2">
        <span style="font-size: 35px">Selamat menikmati,</span> <br>
        <span style="font-size: 35px" >Senang melayani anda,</span>
      </tfoot>
</div>

<script type="text/javascript">
    window.onload = function() {
        window.print();
    }
</script>

@include('component.footer-script')

