<!doctype html>
<html lang="en">

<head>
    <style>
    .kop-surat {
        font-family: Arial, Helvetica, sans-serif;
        color: #000;
        line-height: 1.3;
        margin-left: -10px;
        border-bottom: 1px solid black;
    }

    .kop-surat h1 {
        font-size: 20px;
        font-weight: bold;
        margin: 0 0 4px 0;
    }

    .kop-surat p {
        margin: 0;
        font-size: 12px;
    }

    .kop-surat .tagline {
        font-weight: bold;
    }

    .kop-surat .alamat,
    .kop-surat .kontak,
    .kop-surat .email {
        font-size: 11px;
    }

    table {
        width: 100%;
        margin-left: 11px
    }

    .table {
        border: 1px solid #000;
    }

    tr,
    td {
        border: 1px solid #000;
    }

    @media print {

        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 15px;
            page-break-inside: avoid;
        }

        thead {
            display: table-header-group;
        }

        tr,
        td,
        th {
            border: 1px solid #000;
            page-break-inside: avoid;
        }

        .unit-table {
            page-break-inside: avoid;
        }
    }
    </style>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Print RaxiPS</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB" crossorigin="anonymous">
</head>

<body onload="window.print()">
    <div class="container-fluid">
        <?php
        include "koneksi.php";
        $nofile = $_GET['nofile'];
        $sqle = mysqli_query($konek, "SELECT r.idraxips,u.nama_unit,c.pic,c.telp,c.email,c.bu,c.alamat,r.nofile_raxips,r.checker,c.nama_customer,r.tgl_raxips,r.status_checkraxips,r.checker FROM raxi_ps r INNER JOIN customer c ON r.idcustomer = c.idcustomer INNER JOIN detail_raxips d ON d.idraxips = r.idraxips INNER JOIN unit u ON d.idunit = u.idunit WHERE nofile_raxips = '$nofile'");
        $rows = mysqli_fetch_assoc($sqle);
        ?>
        <div class="row">
            <div class="kopsur" style="display: flex;gap: 20px;">
                <div class="gkiri">
                    <img src="asset/gambar/logo-raxprint.png" alt="" width="200px">
                </div>
                <div class="gkanan">
                    <div class="kop-surat">
                        <h1>PT. RAXI INDONESIA</h1>

                        <p class="tagline">
                            Material Handling Equipment | Sale | Rent | Service | www.materialhandling.co.id
                        </p>

                        <p class="alamat">
                            Surabaya : Gedung Graha Pena Jawa Pos Lantai 5, Jl. Ahmad Yani No. 88 RT 007 RW 003,
                            Ketintang, Gayungan, Kota Surabaya, Jawa Timur | 031-30008273
                        </p>

                        <p class="kontak">
                            Jakarta : Menara Rajawali Level 7 Jl. DR. Ide Anak Agung Gde Agung, Jakarta Selatan |
                            021-29490627
                        </p>
                        <p class="kontak">
                            Tangerang : Jl. Raya Cibar Baro No.9C, BSD Serpong, Tangerang Selatan | 021-75671297
                        </p>

                        <p class="email">
                            sales@materialhandling.co.id | marketing@raxi.co.id | sb@raxi.co.id | jkt@raxi.co.id
                        </p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <?php
            if (str_contains($nofile, "SV-TG")) {
                $cabang = "Tanggerang";
            } elseif (str_contains($nofile, "SV-SB")) {
                $cabang = "Surabaya";
            }
            $tanggal = $rows['tgl_raxips'];

            $bulan = [
                1 => 'Januari',
                'Februari',
                'Maret',
                'April',
                'Mei',
                'Juni',
                'Juli',
                'Agustus',
                'September',
                'Oktober',
                'November',
                'Desember'
            ];

            $t = strtotime($tanggal);
            $tanggal = date('j', $t) . ' ' . $bulan[(int)date('n', $t)] . ' ' . date('Y', $t);

            ?>
            <p style="text-align: right;"><?= $cabang ?>, <?= $tanggal ?></p>
        </div>
        <div class="row">
            <p> Hal : Penawaran Harga</p>
        </div>
        <div class="row">
            <table>
                <tr>
                    <th>No file</th>
                    <td>:</td>
                    <td><?= $rows['nofile_raxips'] ?></td>
                    <th>Up</th>
                    <td>:</td>
                    <td><?= $rows['pic'] ?></td>
                </tr>
                <tr>
                    <th>Kepada</th>
                    <td>:</td>
                    <td><?= $rows['bu'] . $rows['nama_customer'] ?></td>
                    <th>Telp / Hp</th>
                    <td>:</td>
                    <td><?= $rows['telp'] ?? '-' ?></td>
                </tr>
                <tr>
                    <th>Alamat</th>
                    <td>:</td>
                    <td><?= $rows['alamat'] ?></td>
                    <th>Email</th>
                    <td>:</td>
                    <td><?= $rows['email'] ?></td>
                </tr>
            </table>
        </div>
        <br>
        <div class="row">
            <p>Dengan Hormat,</p>
            <p>Bersama ini kami PT. RAXI INDONESIA bergerak di bidang Penjualan, Sewa, serta Perbaikan Material Handling
                di Indonesia bermaksud menawarkan harga sebagai berikut:</p>
        </div>
        <div class="row">
            <div class="iki-tabel">
                <?php
                $cridrps = mysqli_query($konek, "select idraxips from raxi_ps where nofile_raxips='$nofile'");
                $cridrps = mysqli_fetch_array($cridrps);
                $idraxips = $cridrps["idraxips"] ?? "";

                // echo $iddraxips;


                $no = 1;
                $sql = mysqli_query($konek, "SELECT d.iddetail_raxips,u.nama_unit,d.no_unit,d.wo_unit FROM detail_raxips d INNER JOIN unit u ON d.idunit=u.idunit WHERE idraxips='$idraxips'");
                while ($row = mysqli_fetch_array($sql)) {
                ?>
                <table class="table">
                    <thead>
                        <tr style="text-align: center;">
                            <th scope="col">No</th>
                            <th scope="col">Uraian</th>
                            <th scope="col" style="width: 5px;">QTY</th>
                            <th scope="col">Keterangan</th>
                            <th scope="col">Harga Satuan</th>
                            <th scope="col">Harga</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                            $iddraxips = $row['iddetail_raxips'];
                            $querygabung = mysqli_query(
                                $konek,
                                "SELECT s.jenis_service AS keterangan,j.harga_serviceraxi AS harga,j.qty_service AS kuota,j.totalservice_raxi AS total,j.keterangan AS kete FROM uraianraxips_service j INNER JOIN jenis_service s ON j.idjenis_service=s.idjenis_service WHERE j.iddetail_raxips = '$iddraxips'
                                        UNION ALL
                                        SELECT b.nama_barang AS keterangan,ub.harga_barangraxi AS harga,ub.qty AS kuota,ub.totalbarang_raxi AS total,ub.keterangan AS kete FROM uraianraxips_barang ub INNER JOIN barang b ON ub.idbarang=b.idbarang WHERE ub.iddetail_raxips = '$iddraxips'"
                            );
                            $data = mysqli_num_rows($querygabung);
                            $noe = 0;
                            while ($datae = mysqli_fetch_array($querygabung)) {
                            ?>
                        <tr style="text-align: center;">
                            <td><?= $no ?></td>
                            <td><?= $row['nama_unit'] ?></td>
                            <td><?= $datae['kuota'] ?></td>
                            <td style="text-align: left;">
                                <div style="text-align:center; font-weight:600;">
                                    <?= htmlspecialchars($datae['keterangan']) ?>
                                </div>
                                <?php if (!empty($datae['kete'])): ?>
                                <div style="text-align:left; margin-top:6px; line-height:1.5;">
                                    <?= nl2br(htmlspecialchars($datae['kete'])) ?>
                                </div>
                                <?php endif; ?>
                            </td>
                            <td><?= $datae['harga'] ?></td>
                            <td><?= $datae['total'] ?></td>
                        </tr>
                        <?php
                            }
                            $query_total = mysqli_query($konek, "
                                    SELECT SUM(total) AS grand_total
                                    FROM (
                                        SELECT totalservice_raxi AS total
                                        FROM uraianraxips_service
                                        WHERE iddetail_raxips = '$iddraxips'

                                        UNION ALL

                                        SELECT totalbarang_raxi AS total
                                        FROM uraianraxips_barang
                                        WHERE iddetail_raxips = '$iddraxips'
                                    ) AS total_all
                                ");

                            $total = mysqli_fetch_assoc($query_total);
                            ?>
                        <tr style="text-align: center;">
                            <td colspan="2"></td>
                            <td colspan="3">SUB TOTAL</td>
                            <td><?= $tuotal = $total['grand_total'] ?></td>
                        </tr>
                        <tr style="text-align: center;">
                            <td colspan="2"></td>
                            <td colspan="3">PPN 11%</td>
                            <td><?= $ppn = $total['grand_total'] * 0.11 ?></td>
                        </tr>
                        <tr style="text-align: center;">
                            <td colspan="2"></td>
                            <td colspan="3">TOTAL</td>
                            <td><?= $kabeh = $ppn + $tuotal ?></td>
                        </tr>
                    </tbody>
                </table>
                <?php
                }
                ?>
            </div>
        </div>
        <div class="row">
            <div class="catatan" style="display: flex;">
                <p style="font-weight: 700;">Note : </p>
                <?php
                if ($rows['status_checkraxips'] == "Belum") {
                ?>
                <p style="margin-left: 5px;"><?= $rows['nama_unit'] . " " . $rows['status_checkraxips'] ?> dilakukan
                    pengecekan oleh teknisi PT Raxi Indonesia inisial</p>
                <?php
                } else {
                ?>
                <p style="margin-left: 5px;"><?= $rows['nama_unit'] . " " . $rows['status_checkraxips'] ?> dilakukan
                    pengecekan oleh teknisi PT Raxi Indonesia inisial
                    (<?php echo substr($rows['checker'] ?? '-', 0, 2) ?>)</p>
                <?php
                }
                ?>
            </div>
        </div>
        <div class="row">
            <div class="keterangan">
                <p style="font-weight: 700;">Keterangan :</p>
                <ul>
                    <li>Gratis biaya pengiriman Ke Surabaya</li>
                </ul>
            </div>
        </div>
        <div class="row">
            <div class="demikian">
                <p>Demikian surat penawaran ini, apabila kurang jelas dapat ditanyakan langsung kepada kami dan kami
                    tunggu kepastian ordernya. Atas perhatian dan kerjasamanya, terima kasih.</p>
            </div>
        </div>
        <div class="row">
            <div class="ttd">
                <p>Hormat Kami,</p>
                <p style="font-weight: 700;margin-top: -20px;">Marketing Division PT. RAXI INDONESIA</p>
                <img src="asset/gambar/ttd ditya kusuma (raxi sv sby).png" alt="" width="200"
                    style="margin-top: -35px;margin-bottom: -20px;">
                <p style="font-weight: 700;text-decoration: underline;">Ditya Kusuma Putri</p>
                <p style="margin-top: -20px;">0812 2430 2982</p>
            </div>
        </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-FKyoEForCGlyvwx9Hj09JcYn3nv7wiPVlz7YYwJrWVcXK/BmnVDxM+D2scQbITxI" crossorigin="anonymous">
    </script>
</body>

</html>