<!DOCTYPE html>
<html lang="ur">
<head>
<meta charset="UTF-8">
<title>SGM Receipt #<?php echo e($gold->id); ?></title>
<style>
* { margin:0; padding:0; box-sizing:border-box; }
body {
    font-family: Arial, sans-serif;
    background: #bbb;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
}

/* ── RECEIPT PAPER ── */
.receipt {
    width: 82mm;
    background: #fff;
    padding: 3mm 3mm 2mm 3mm;
    box-shadow: 0 3px 14px rgba(0,0,0,0.35);
}

/* ── HEADER (outside box) ── */
.hdr { text-align:center; margin-bottom:2mm; }
.hdr .shop  { font-size:20px; font-weight:bold; letter-spacing:1px; }
.hdr .lab   { font-size:12px; font-weight:bold; }
.hdr .addr  { font-size:10px; }
.hdr .phone { font-size:10px; margin-top:1px; }

/* ── OUTER BORDER BOX ── */
.box {
    border: 1.5px solid #000;
    width: 100%;
}

/* ── META ROW inside box ── */
.meta-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2px 4px;
    font-size: 11px;
    border-bottom: 1px solid #000;
}
.meta-row .num  { font-weight:bold; }
.meta-row .lbl  { font-size:10px; }

/* ── WEIGHT TABLE ── */
.wtable {
    width: 100%;
    border-collapse: collapse;
}
.wtable td {
    padding: 1px 3px;
    border-bottom: 1px solid #ddd;
    vertical-align: middle;
}
/* column headers */
.col-hdr {
    font-size: 10px;
    text-align: center;
    border-bottom: 1px solid #000 !important;
    padding: 1px 3px;
}
/* gram integer - big bold */
.g-int  { font-size:18px; font-weight:bold; text-align:center; width:22mm; }
/* milli gram decimal */
.g-dec  { font-size:12px; font-weight:bold; text-align:center; width:18mm; }
/* urdu label right */
.u-lbl  { font-size:12px; text-align:right; direction:rtl; }
/* total weight row - extra bold */
.tot-row .g-int { font-size:22px; }
.tot-row .g-dec { font-size:14px; }

/* ── TOLA BREAKDOWN ── */
.tola-section {
    border-top: 1px solid #000;
    padding: 2px 4px;
}
.tola-hdr {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    margin-bottom: 1px;
}
.tola-val {
    font-size: 17px;
    font-weight: bold;
    text-align: center;
    letter-spacing: 4px;
}

/* ── RATTI / KERAT BOX ── */
.rk-row {
    display: flex;
    border-top: 1px solid #000;
    border-bottom: 1px solid #000;
}
.rk-cell {
    flex: 1;
    padding: 3px 5px;
    font-size: 12px;
    font-weight: bold;
    text-align: center;
}
.rk-cell:first-child { border-right: 1px solid #000; }

/* ── RATE ROW ── */
.rate-row {
    display: flex;
    border-bottom: 1px solid #000;
}
.rate-cell {
    flex: 1;
    padding: 2px 5px;
    font-size: 11px;
    text-align: center;
    vertical-align: middle;
}
.rate-cell:first-child { border-right: 1px solid #000; }
.rate-cell .lbl { font-size:10px; direction:rtl; }
.rate-cell .val { font-size:14px; font-weight:bold; }

/* ── PRICE ROW ── */
.price-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 6px;
    direction: rtl;
}
.price-row .lbl { font-size:13px; font-weight:bold; }
.price-row .val { font-size:20px; font-weight:bold; }

/* ── FOOTER (outside box) ── */
.footer {
    margin-top: 2mm;
    font-size: 10px;
    text-align: center;
    direction: rtl;
    line-height: 1.5;
}
.footer .phones {
    direction: ltr;
    font-size: 10px;
    margin-top: 2px;
}
.footer .dev {
    font-size: 9px;
    color: #444;
    direction: rtl;
    margin-top: 1px;
}

/* ── PRINT BUTTONS ── */
.no-print {
    margin-top: 18px;
    display: flex;
    gap: 10px;
}
.no-print button, .no-print a {
    padding: 11px 28px;
    font-size: 14px;
    font-weight: bold;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    color: #fff;
}

@media print {
    body { background:#fff; padding:0; display:block; }
    .receipt { box-shadow:none; width:82mm; }
    .no-print { display:none !important; }
}
</style>
</head>
<body>

<?php
    // ── Calculations ──
    $TOLA = 11.664;

    // Weight integer + decimal parts
    $wInt   = (int) floor($gold->weight);
    $wDec   = '.' . str_pad(round(($gold->weight - floor($gold->weight)) * 1000), 3, '0', STR_PAD_LEFT);

    $impInt = (int) floor($gold->impure_weight);
    $impDec = '.' . str_pad(round(($gold->impure_weight - floor($gold->impure_weight)) * 1000), 3, '0', STR_PAD_LEFT);

    $purInt = (int) floor($gold->pure_weight);
    $purDec = '.' . str_pad(round(($gold->pure_weight - floor($gold->pure_weight)) * 1000), 3, '0', STR_PAD_LEFT);

    // Tola breakdown of pure weight: 1 Tola=16 Aath, 1 Aath=6 Ratti
    // ملاوٹ فی تولہ = RATTI IN ko Pound-Ratti-Cent mein convert karo
    // 1 Pound = 6 Ratti, decimal of ratti = Cent
    $rattiIN_val = round((100 - $gold->laser_points) * 96 / 100, 2);
    $pound = (int) floor($rattiIN_val / 6);
    $remR  = $rattiIN_val - ($pound * 6);
    $rInt  = (int) floor($remR);
    $cent  = (int) round(($remR - $rInt) * 100);

    // Kerat
    $kerat  = number_format(($gold->laser_points / 100) * 24, 2);

    // Charges
    $charges = $gold->ch_charges + $gold->lbr_charges;
?>

<div class="receipt">

    
    <div class="hdr">
        <div class="shop">SGM</div>
        <div class="lab">Gold Testing laboratory</div>
        <div class="addr">Sarafa Bazar</div>
        <div class="phone">0302-3155157 &nbsp;&nbsp; 0306-3108504</div>
    </div>

    
    <div class="box">

        
        <div class="meta-row">
            <span class="num">#<?php echo e(str_pad($gold->id, 5, '0', STR_PAD_LEFT)); ?></span>
            <span class="lbl">LASER</span>
            <span><?php echo e($gold->created_at->format('d-M-Y')); ?><br><?php echo e($gold->created_at->format('h:i:s A')); ?></span>
        </div>

        
        <div class="meta-row">
            <span class="lbl">نام</span>
            <span><?php echo e($gold->customer_name ?? ''); ?></span>
        </div>

        
        <table class="wtable">
            <tr>
                <td class="col-hdr">گرام</td>
                <td class="col-hdr">ملی گرام</td>
                <td class="col-hdr" style="text-align:right;"></td>
            </tr>
            
            <tr class="tot-row" style="border-bottom:1px solid #000;">
                <td class="g-int"><?php echo e($wInt); ?></td>
                <td class="g-dec"><?php echo e($wDec); ?></td>
                <td class="u-lbl">توکل وزن</td>
            </tr>
            
            <tr>
                <td class="g-int" style="font-size:15px;"><?php echo e($impInt); ?></td>
                <td class="g-dec"><?php echo e($impDec); ?></td>
                <td class="u-lbl">ملاوٹ وزن</td>
            </tr>
            
            <tr style="border-top:1px solid #000;">
                <td class="g-int"><?php echo e($purInt); ?></td>
                <td class="g-dec"><?php echo e($purDec); ?></td>
                <td class="u-lbl">خالص وزن</td>
            </tr>
        </table>

        
        <div class="tola-section">
            <div style="display:flex; justify-content:space-between; align-items:center;">
                <span style="font-size:11px;">ملاوٹ فی تولہ</span>
                <table style="border-collapse:collapse;">
                    <tr>
                        <td style="text-align:center; font-size:10px; padding:0 10px;">آنہ</td>
                        <td style="padding:0;"></td>
                        <td style="text-align:center; font-size:10px; padding:0 10px;">رتی</td>
                        <td style="padding:0;"></td>
                        <td style="text-align:center; font-size:10px; padding:0 10px;">پوائنٹ</td>
                    </tr>
                    <!-- <tr>
                        <td style="text-align:center; font-size:18px; font-weight:bold; padding:0 10px;"><?php echo e($cent); ?></td>
                        <td style="font-size:18px; font-weight:bold;">-</td>
                        <td style="text-align:center; font-size:18px; font-weight:bold; padding:0 10px;"><?php echo e($rInt); ?></td>
                        <td style="font-size:18px; font-weight:bold;">-</td>
                        <td style="text-align:center; font-size:18px; font-weight:bold; padding:0 10px;"><?php echo e($pound); ?></td>
                    </tr> -->
                     <tr>
                        <td style="text-align:center; font-size:18px; font-weight:bold; padding:0 10px;"><?php echo e($pound); ?></td>
                        <td style="font-size:18px; font-weight:bold;">-</td>
                        <td style="text-align:center; font-size:18px; font-weight:bold; padding:0 10px;"><?php echo e($rInt); ?></td>
                        <td style="font-size:18px; font-weight:bold;">-</td>
                        <td style="text-align:center; font-size:18px; font-weight:bold; padding:0 10px;"><?php echo e($cent); ?></td>
                    </tr>
                </table>
            </div>
        </div>

        
        <div class="rk-row">
            <div class="rk-cell">RATTI IN: &nbsp; <?php echo e(number_format($gold->ratti_in ?? 0, 2)); ?></div>
            <div class="rk-cell">KERAT: &nbsp; <?php echo e($kerat); ?></div>
        </div>

        
        <div class="rate-row">
            <div class="rate-cell">
                <div class="lbl">فی گرام چارجز</div>
                <div class="val"><?php echo e(number_format($charges, 0)); ?></div>
            </div>
            <div class="rate-cell">
                <div class="lbl">ریٹ / تولہ</div>
                <div class="val"><?php echo e(number_format($gold->rate_per_tola, 0)); ?></div>
            </div>
        </div>

        
        <div class="price-row">
            <span class="lbl">قیمت</span>
            <span class="val"><?php echo e(number_format($gold->total_price, 0)); ?></span>
        </div>

    </div>

    
    <div class="footer">
        <div>اپنا سونا اور کیش کاؤنٹر پر سنبھالیں بعد کی ذمہ داری نہیں ہے</div>
        <div class="phones">0302-3155157 &nbsp;&nbsp;&nbsp; 0306-3108504</div>
        <div class="dev">سافٹ ویئر کے لیے رابطہ کریں: <span style="direction:ltr; unicode-bidi:embed;">0316-6707162</span></div>
    </div>

</div>


<div class="no-print">
    <button onclick="window.print()" style="background:#003d80;">🖨️ Print کریں</button>
    <a href="<?php echo e(route('gold.index')); ?>" style="background:#007733;">+ نئی Entry</a>
    <a href="<?php echo e(route('gold.records')); ?>" style="background:#555;">Records</a>
</div>

<script>
document.addEventListener('keydown', function(e) {
    if (e.key==='p'||e.key==='P') { e.preventDefault(); window.print(); }
    if (e.key==='Escape') { window.location='<?php echo e(route('gold.index')); ?>'; }
});
</script>
</body>
</html>
<?php /**PATH D:\Gold Lab\sgm-gold-lab\resources\views/gold/print.blade.php ENDPATH**/ ?>