<?php
// https://stackoverflow.com/questions/1328036/php-date-in-foreign-languages-e-g-mar-25-ao%C3%BB-09
// https://www.educative.io/edpresso/how-to-change-the-timezone-in-a-laravel-application
// https://stackoverflow.com/questions/22059495/strftime-for-indonesia-locale
setlocale(LC_TIME, 'IND');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>SURAT PERINTAH KERJA</title>
    <link href="{{ base_path() . '/public/assets/vendor/bootstrap-5.0.2-dist/css/bootstrap.css' }}" rel="stylesheet">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <style>
        @page {
            margin: 0;
        }

        @import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');

        * {
            /* margin: 0; */
            /* line-height: 1.2; */
            line-height: 0.8;
            color: #000;
        }

        /* html { margin: 0} */

        body {
            font-weight: 400;
            margin: 1cm 1cm 1cm 1cm;
            font-family: 'Poppins';
        }

        .table-border-dark th,
        .table-border-dark td,
        {
        border: 1px solid #000;
        }

        .table-padding-paragraph td {
            padding: 0.5rem;
        }

        .word-break {
            word-wrap: break-word;
            overflow-wrap: break-word;
        }

        .page-break {
            page-break-after: always;
        }

        strong {
            font-weight: 1000;
        }

        .general-photo {
            max-width: 600px;
            max-height: 400px;
        }

        .dynamic-photo {
            max-width: 80%;
            max-height: 40%;
        }

        .mx-garis-tepi {
            margin-left: 3.5rem;
            margin-right: 3.5rem;
        }

        .ol-without-left {
            padding-left: 1.5em;
        }
    </style>
</head>

<body>

    @php
        $totCntPage = 1;
        $estPage = count($orders);
        foreach ($orders as $iOrd => $order) {
            if (count($order->adtPoints) > 0) {
                $estPage += round(count($order->adtPoints) / 2);
            }
        }
    @endphp

    <table class="table mb-3">
        <tbody>
            <tr>
                <td class=""><img src="{{ $logo }}" alt="" style="margin:0 1.5rem 0 0; height: 100px"></td>
                {{-- <td class=""><img ssrc="{{ base_path() . '/public/storage/' . $client->c_logo }}" alt="" style="margin:0 1.5rem 0 0; height: 100px"></td> --}}
                <td class="text-end">{{ date('d/m/Y H:i:s') }}</td>
            </tr>
        </tbody>
    </table>

    <div class="mb-4" style="text-align: center;">
        <p class="mb-2" style="font-size: 14px; text-decoration: underline;"><strong>SURAT PERINTAH
                KERJA</strong></p>
        <p class="mb-1" style="font-size: 14px;"><strong>
                @foreach ($orders as $iOrd => $order)
                    {{ $order->ord_code }}
                    @if (count($orders) !== ((int) $iOrd) + 1)
                        ,
                    @endif
                @endforeach
            </strong></p>
    </div>
    <div class="mx-garis-tepi" style="margin-bottom: 1.5rem; font-size: 13px;text-align: justify;">
        <p class="mb-1">{{ $client->c_name }} memberikan tugas pengambilan barang, melakukan
            pengangkutan dan pengiriman barang dengan data-data serta identitas sebagai berikut:</p>
    </div>

    <h1 class="text-danger">{{ base_path() . '/storage' . $client->c_logo }}</h1>

    <div class="mx-garis-tepi" style="margin-bottom: 1.5rem; font-size: 13px;text-align: justify;">
        <p class="mb-0">Penerima Pekerjaan</p>
        <table class="table table-border-dark table-padding-paragraph mb-3">
            <tbody>
                <tr>
                    <td colspan="2">
                        <p class="mb-1"><strong>Nama Pengemudi</strong></p>
                        <div>
                            <ol class="mb-0 ol-without-left">
                                <li>{{ $order->drv_name }}
                                    ({{ implode(' ', str_split('0' . $order->drv_phone_val, 4)) }})</li>
                                <li>{{ $order->drv_name2 }}
                                    ({{ implode(' ', str_split('0' . $order->drv_phone2_val, 4)) }})</li>
                            </ol>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td style="width:50%;">
                        <p class="mb-1"><strong>Nomor Polisi</strong></p>
                        <p class="mb-0">
                            {{ $order->vhc_nopol1 . ' ' . $order->vhc_nopol2 . ' ' . $order->vhc_nopol3 }}</p>
                    </td>
                    <td style="width:50%;">
                        <p class="mb-1"><strong>Tipe Unit</strong></p>
                        <p class="mb-0">{{ $order->prefer_truck_type_name }}
                            @if (isset($order->vhc_brand_name))
                                / {{ $order->vhc_brand_name }}
                            @endif
                        </p>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>

    @foreach ($orders as $iOrd => $order)
        {{-- index kedua dan setiap 2 index berikutnya --}}
        {{-- @if ($iOrd === 1 || ($iOrd % 2 === 0 && $iOrd !== 0)) --}}
        @if ($iOrd === 1 || ($iOrd % 2 === 0 && $iOrd !== 0))
            <table class="table" style="position: absolute; left: 2.3rem; bottom: 1cm; padding-right: 4.5rem;">
                <tbody>
                    <tr>
                        <td class="text-end">{{ $totCntPage }}/{{ $estPage }}</td>
                    </tr>
                </tbody>
            </table>
            <div class="page-break"></div>
            <table class="table mb-3">
                <tbody>
                    <tr>
                        {{-- <td class=""><img src="{{ base_path() . '/public/images/logogram-bonceng.png' }}" alt="NAM Logo" style="margin:0 1.5rem 0 0;"></td> --}}
                        <td class=""><img src="{{ $logo }}" alt="" style="margin:0 1.5rem 0 0; height: 100px"></td>
                        <td class="text-end">{{ date('d/m/Y H:i:s') }}</td>
                    </tr>
                </tbody>
            </table>
            @php
                $totCntPage++;
            @endphp
        @endif
        <div class="mx-garis-tepi" style="margin-bottom: 1.5rem; font-size: 13px;text-align: justify;">
            <p class="mb-0">Pekerjaan</p>
            <table class="table table-border-dark table-padding-paragraph mb-3">
                <tbody>
                    <tr>
                        <td colspan="2">
                            <p class="mb-1"><strong>Pekerjaan</strong></p>
                            <p class="mb-0">Pengiriman Logistik</p>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <p class="mb-1"><strong>Waktu Penjemputan Barang</strong></p>
                            <p class="mb-0">{{ date('d F Y', $order->set_pck_at) }}</p>
                            <p class="mb-0">{{ date('H:i:s', $order->set_pck_at) }} W.I.B</p>
                            {{-- <p class="mb-0">{{ strftime('%d %B %Y %H:%M:%S', $order->set_pck_at) }} W.I.B</p> --}}
                        </td>
                    </tr>
                    {{-- <tr>
                        <td colspan="2">
                            <p class="mb-1"><strong>Client</strong></p>
                            <p class="mb-0">{{ $order->c_pt_name }}</p>
                        </td>
                    </tr> --}}
                    <tr>
                        <td style="width:50%;">
                            <div class="mb-3" style="height:4%;">
                                <p class="mb-1"><strong>Pengirim</strong></p>
                                <p class="mb-0">{{ $order->c_pt_name }}</p>
                            </div>
                            <div class="mb-3" style="height:13%;">
                                <p class="mb-1"><strong>Alamat Penjemputan</strong></p>
                                {{-- <p class="mb-3">{{ $order->pck_ktname }}</p> --}}
                                {{-- <p class="mb-1">{{ $order->pck_name }}</p> --}}
                                <p class="mb-0">{{ $order->pck_addr }}</p>
                            </div>
                            <div class="mb-3" style="height:4%;">
                                <p class="mb-1"><strong>PIC Pengirim</strong></p>
                                <p class="mb-0">{{ $order->pck_pic_name }}</p>
                                <p class="mb-1">({{ implode(' ', str_split('0' . $order->pck_pic_phone_val, 4)) }})</p>
                            </div>

                        </td>
                        <td style="width:50%;">
                            <div class="mb-3" style="height:4%;">
                                <p class="mb-1"><strong>Penerima</strong></p>
                                <p class="mb-0">{{ $order->c_pt_name }}</p>
                            </div>
                            <div class="mb-3" style="height:13%;">
                                <p class="mb-1"><strong>Alamat Pengantaran</strong></p>
                                {{-- <p class="mb-3">{{ $order->drop_ktname }}</p> --}}
                                {{-- <p class="mb-1">{{ $order->drop_name }}</p> --}}
                                <p class="mb-0">{{ $order->drop_addr }}</p>
                            </div>
                            <div class="mb-3" style="height:4%;">
                                <p class="mb-1"><strong>PIC Penerima</strong></p>
                                <p class="mb-0">{{ $order->drop_pic_name }}</p>
                                <p class="mb-1">({{ implode(' ', str_split('0' . $order->drop_pic_phone_val, 4)) }})</p>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <p class="mb-1"><strong>Waktu Pekerjaan</strong></p>
                            <p class="mb-0">{{ date('d F Y', $order->set_pck_at) . ' - ' . date('d F Y', strtotime("+$order->lead_time day", $order->set_pck_at)) }}</p>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>

        <div class="mx-garis-tepi" style="margin-bottom: 1.5rem; font-size: 13px;text-align: justify;">
            <table class="table table-border-dark table-padding-paragraph mb-3">
                <tbody>
                    <tr>
                        <td class="text-center" style="width:50%;">
                            <p class="mb-1"><strong>PIC Pengirim</strong></p>
                            <div class="mb-5 pb-3"></div>
                            <p class="mb-0">{{ $order->pck_pic_name }}</p>
                        </td>
                        <td class="text-center" style="width:50%;">
                            <p class="mb-1"><strong>PIC Penerima</strong></p>
                            <div class="mb-5 pb-3"></div>
                            <p class="mb-0">{{ $order->drop_pic_name }}</p>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>

        @foreach ($order->adtPoints as $i => $adtPoint)
            {{-- index pertama dan setiap 2 index berikutnya --}}
            {{-- @if ($i === 0 || $i % 2 === 1) --}}
            <table class="table" style="position: absolute; left: 2.3rem; bottom: 1cm; padding-right: 4.5rem;">
                <tbody>
                    <tr>
                        <td class="text-end">{{ $totCntPage }}/{{ $estPage }}</td>
                    </tr>
                </tbody>
            </table>
            <div class="page-break"></div>
            <table class="table mb-3">
                <tbody>
                    <tr>
                        {{-- <td class=""><img src="{{ base_path() . '/public/images/bonceng-red.png' }}" alt="PT. BONCENG INDONESIA" style="margin:0 1.5rem 0 0;"></td> --}}
                        <td class=""><img src="{{ $logo }}" alt="" style="margin:0 1.5rem 0 0; height: 100px"></td>
                        <td class="text-end">{{ date('d/m/Y H:i:s') }}</td>
                    </tr>
                </tbody>
            </table>
            @php
                $totCntPage++;
            @endphp
            {{-- @endif --}}
            <div class="mx-garis-tepi" style="margin-bottom: 1.5rem; font-size: 13px;text-align: justify;">
                <p class="mb-0">Pekerjaan</p>
                <table class="table table-border-dark table-padding-paragraph mb-3">
                    <tbody>
                        <tr>
                            <td colspan="2">
                                <p class="mb-1"><strong>Pekerjaan</strong></p>
                                <p class="mb-0">Pengiriman Logistik</p>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <p class="mb-1"><strong>Waktu Penjemputan Barang</strong></p>
                                <p class="mb-0">{{ date('d F Y', $adtPoint->set_pck_at) }}</p>
                                <p class="mb-0">{{ date('H:i:s', $adtPoint->set_pck_at) }} W.I.B</p>
                                {{-- <p class="mb-0">{{ strftime('%d %B %Y %H:%M:%S', $adtPoint->set_pck_at) }} W.I.B</p> --}}
                            </td>
                        </tr>
                        {{-- <tr>
                            <td colspan="2">
                                <p class="mb-1"><strong>Client</strong></p>
                                <p class="mb-0">{{ $adtPoint->c_pt_name }}</p>
                            </td>
                        </tr> --}}
                        <tr>
                            <td style="width:50%;">
                                <div class="mb-3" style="height:4%;">
                                    <p class="mb-1"><strong>Pengirim</strong></p>
                                    <p class="mb-0">{{ $order->c_pt_name }}</p>
                                </div>
                                <div class="mb-3" style="height:13%;">
                                    <p class="mb-1"><strong>Alamat Penjemputan</strong></p>
                                    {{-- <p class="mb-3">{{ $adtPoint->pck_ktname }}</p> --}}
                                    {{-- <p class="mb-1">{{ $adtPoint->pck_name }}</p> --}}
                                    <p class="mb-0">{{ $adtPoint->pck_addr }}</p>
                                </div>
                                <div class="mb-3" style="height:4%;">
                                    <p class="mb-1"><strong>PIC Pengirim</strong></p>
                                    <p class="mb-0">{{ $adtPoint->pck_pic_name }}</p>
                                    <p class="mb-1">({{ implode(' ', str_split('0' . $adtPoint->pck_pic_phone_val, 4)) }})</p>
                                </div>

                            </td>
                            <td style="width:50%;">
                                <div class="mb-3" style="height:4%;">
                                    <p class="mb-1"><strong>Penerima</strong></p>
                                    <p class="mb-0">{{ $order->c_pt_name }}</p>
                                </div>
                                <div class="mb-3" style="height:13%;">
                                    <p class="mb-1"><strong>Alamat Pengantaran</strong></p>
                                    {{-- <p class="mb-3">{{ $adtPoint->drop_ktname }}</p> --}}
                                    {{-- <p class="mb-1">{{ $adtPoint->drop_name }}</p> --}}
                                    <p class="mb-0">{{ $adtPoint->drop_addr }}</p>
                                </div>
                                <div class="mb-3" style="height:4%;">
                                    <p class="mb-1"><strong>PIC Penerima</strong></p>
                                    <p class="mb-0">{{ $adtPoint->drop_pic_name }}</p>
                                    <p class="mb-1">({{ implode(' ', str_split('0' . $adtPoint->drop_pic_phone_val, 4)) }})</p>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <p class="mb-1"><strong>Waktu Pekerjaan</strong></p>
                                <p class="mb-0">{{ date('d F Y', $adtPoint->set_pck_at) . ' - ' . date('d F Y', strtotime("+$adtPoint->lead_time day", $adtPoint->set_pck_at)) }}</p>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <div class="mx-garis-tepi" style="margin-bottom: 1.5rem; font-size: 13px;text-align: justify;">
                <p class="mb-1">Mohon agar {{ $order->c_pt_name }} dapat memberikan izin dan bantuan dalam
                    aktivitas loading
                    barang. Demikian Surat Perintah Kirja ini kami buat untuk dipergunakan sebagaimana
                    mestinya.</p>
            </div>

            <div class="mx-garis-tepi" style="margin-bottom: 1.5rem; font-size: 13px;text-align: justify;">
                <table class="table table-border-dark table-padding-paragraph mb-3">
                    <tbody>
                        <tr>
                            <td class="text-center" style="width:50%;">
                                <p class="mb-1"><strong>PIC Pengirim</strong></p>
                                <div class="mb-5 pb-3"></div>
                                <p class="mb-0">{{ $adtPoint->pck_pic_name }}</p>
                            </td>
                            <td class="text-center" style="width:50%;">
                                <p class="mb-1"><strong>PIC Penerima</strong></p>
                                <div class="mb-5 pb-3"></div>
                                <p class="mb-0">{{ $adtPoint->drop_pic_name }}</p>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        @endforeach
    @endforeach


    <table class="table" style="position: absolute; left: 2.3rem; bottom: 1cm; padding-right: 4.5rem;">
        <tbody>
            <tr>
                {{-- <td class="text-start">1/2</td> --}}
                <td class="text-end">{{ $totCntPage }}/{{ $estPage }}</td>
            </tr>
        </tbody>
    </table>

    {{-- <div class="page-break"></div>

    <table class="table mb-3">
        <tbody>
            <tr>
                <td class=""><img src="{{ base_path() . '/public/images/bonceng-red.png' }}"
                        alt="PT. BONCENG INDONESIA" style="margin:0 1.5rem 0 0;"></td>
                <td class="text-end">{{ date('d/m/Y H:i:s') }}</td>
            </tr>
        </tbody>
    </table> --}}

    {{-- <table class="table" style="position: absolute; left: 2.3rem; bottom: 1cm; padding-right: 4.5rem;">
        <tbody>
            <tr>
                <td class="text-start"></td>
                <td class="text-end">2/2</td>
            </tr>
        </tbody>
    </table> --}}

</body>

</html>
