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

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap demo</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">
    <style>
        @media print {
            body {
                background-color: aqua;
                z-index: 999;
            }

            .kopsur {
                position: fixed;
                /* margin-top: -0px; */
                top: 0;
                left: 0;
                right: 0;
                /* tinggi kop */
                /* padding: 10px 20px; */
                /* background: white; */
                /* z-index: 999; */
            }

            .footer {
                width: 100%;
                position: fixed;
                bottom: 0;
                left: 0;
                right: 0;
                background-color: aqua;
                color: aqua;
            }

            .tglkanan {
                margin-top: 120px;
            }

            .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;
            }

            .isiane table {
                page-break-inside: avoid;
            }

            .isiane th,
            .isiane td {
                border: 1px solid #000;
            }

            .catatan {
                display: flex;
            }

        }
    </style>
</head>

<body onload="window.print()">
    <div class="container-fluid">
        <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="page-header-space"></div>
        <div class="row">
            <div class="tglkanan">
                <?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);

                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>
                <p> Hal : Penawaran Harga</p>
            </div>
        </div>
        <div class="row">
            <div class="desc-atas">
                <table style="width: 100%;">
                    <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>
        </div>
        <br>
        <div class="row">
            <div class="ur1">
                <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>
        <div class="row">
            <div class="isiane">
                <?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 style="width: 100%;">
                        <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 ($d    = mysqli_fetch_array($querygabung)) {
                            ?>
                                <tr>
                                    <?php
                                    if ($noe == 0) {
                                    ?>
                                        <td rowspan="<?php echo $data ?>"><?= $no ?></td>
                                        <td rowspan="<?php echo $data ?>"><?php
                                                                            echo $row['nama_unit'];
                                                                            echo "<br>";
                                                                            echo !empty($row['no_unit']) ? " ({$row['no_unit']})" : "";
                                                                            echo "<br>";
                                                                            echo !empty($row['wo_unit']) ? " ({$row['wo_unit']})" : "";

                                                                            ?></td>
                                    <?php
                                    }
                                    ?>
                                    <td><?php echo $d['kuota'] ?></td>
                                    <td style="text-align: left;">
                                        <div style="text-align:center; font-weight:600;">
                                            <?= htmlspecialchars($d['keterangan']) ?>
                                        </div>
                                        <?php if (!empty($d['kete'])): ?>
                                            <div style="text-align:left; margin-top:6px; line-height:1.5;">
                                                <?= nl2br(htmlspecialchars($d['kete'])) ?>
                                            </div>
                                        <?php endif; ?>
                                    </td>
                                    <td><?php echo $d['harga'] ?></td>
                                    <td><?php echo $d['total'] ?></td>
                                </tr>
                            <?php

                                $noe++;
                            }
                            $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 rowspan="3" colspan="2" style="border-left: none;border-bottom: none;"></td>
                                <td colspan="3" style="font-weight: 700;">Subtotal</td>
                                <th><?php echo $tuotal = $total['grand_total'] ?></th>
                            </tr>
                            <tr style="text-align: center;">
                                <td colspan="3" style="font-weight: 700;">PPN 11%</td>
                                <th><?php echo $ppn = $total['grand_total'] * 0.11 ?></th>
                            </tr>
                            <tr style="text-align: center;">
                                <td colspan="3" style="font-weight: 700;">TOTAL</td>
                                <th><?php echo $kabeh = $ppn + $tuotal ?></th>
                            </tr>
                        </tbody>
                    </table>
                    <br>
                <?php
                    $no++;
                }
                ?>
            </div>
        </div>
        <div class="row">
            <div class="catatan">
                <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="page-footer-space"></div>
        <div class="row">
            <div class="footer" style>
                <p>Tes</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>