
<?php $__env->startSection('title', 'تقرير المشتريات'); ?>

<?php $__env->startPush('css'); ?>
<style>
    #serverSideTable {
        width: 100% !important;
        table-layout: auto !important;
    }

    #serverSideTable th,
    #serverSideTable td {
        vertical-align: middle !important;
    }

    #serverSideTable th.col-index,
    #serverSideTable td.col-index {
        width: 45px !important;
        text-align: center !important;
        white-space: nowrap !important;
    }

    #serverSideTable th.col-branch,
    #serverSideTable td.col-branch {
        width: 13% !important;
        text-align: center !important;
        white-space: nowrap !important;
    }

    #serverSideTable th.col-date,
    #serverSideTable td.col-date {
        width: 12% !important;
        min-width: 110px !important;
        text-align: center !important;
        white-space: nowrap !important;
    }

    #serverSideTable th.col-creator,
    #serverSideTable td.col-creator {
        width: 11% !important;
        text-align: center !important;
        white-space: nowrap !important;
    }

    #serverSideTable th.col-supplier,
    #serverSideTable td.col-supplier {
        width: 16% !important;
        text-align: center !important;
    }

    #serverSideTable th.col-payment,
    #serverSideTable td.col-payment {
        width: 11% !important;
        text-align: center !important;
        white-space: nowrap !important;
    }

    #serverSideTable th.col-total,
    #serverSideTable td.col-total {
        width: 12% !important;
        text-align: center !important;
        white-space: nowrap !important;
        font-weight: bold !important;
    }

    #serverSideTable th.col-paid,
    #serverSideTable td.col-paid {
        width: 12% !important;
        text-align: center !important;
        white-space: nowrap !important;
        font-weight: bold !important;
    }

    #serverSideTable th.col-due,
    #serverSideTable td.col-due {
        width: 13% !important;
        text-align: center !important;
        white-space: nowrap !important;
        font-weight: bold !important;
        border-left: 3px solid #888 !important;
    }

    #serverSideTable.table-bordered > thead > tr > th.col-due,
    #serverSideTable.table-bordered > tbody > tr > td.col-due {
        border-left: 3px solid #888 !important;
    }

    .purchases-summary {
        margin-top: 12px;
        border: 1px solid #d2d6de;
        border-radius: 4px;
        overflow: hidden;
        background: #fff;
    }

    .purchases-summary table {
        width: 100%;
        margin: 0;
        border-collapse: collapse;
        table-layout: fixed;
    }

    .purchases-summary th {
        background: #1a3c5e;
        color: #fff;
        text-align: center;
        padding: 10px 8px;
        font-size: 13px;
        border: 1px solid #0d2a45;
    }

    .purchases-summary td {
        text-align: center;
        padding: 12px 8px;
        font-size: 26px;
        font-weight: bold;
        color: #1a3c5e;
        border: 1px solid #d2d6de;
        background: #f9fbfd;
        white-space: nowrap;
    }

    .purchases-summary td:last-child,
    .purchases-summary th:last-child {
        border-left: 3px solid #888 !important;
    }
</style>
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
    <div class="content-wrapper">
        <section class="content-header">
            <h1>
                تقرير المشتريات
                <a class="btn btn-primary" href="javascript:void(0)" onclick="openReportThemeModal();" style="margin-right:5px;">
                    <i class="fa fa-print"></i> طباعة منسقة
                </a>
            </h1>
        </section>

        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-body">
                            <table id="serverSideTable" class="table table-bordered table-hover">
                                <thead>
                                    <tr>
                                        <th class="col-index">#</th>
                                        <th class="col-branch">الفرع</th>
                                        <th class="col-date">التاريخ</th>
                                        <th class="col-creator">المستخدم</th>
                                        <th class="col-supplier">المورد</th>
                                        <th class="col-payment">طريقة الدفع</th>
                                        <th class="col-total">الإجمالى</th>
                                        <th class="col-paid">المدفوع</th>
                                        <th class="col-due">المتبقى</th>
                                    </tr>
                                </thead>
                                <tbody></tbody>
                            </table>

                            <div class="purchases-summary">
                                <table>
                                    <thead>
                                        <tr>
                                          <th>الإجمالى</th>h>
                                            <th>إجمالي المدفوع</th>
                                            <th>إجمالي المتبقى</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td id="purchases-total-sum">0.00</td>
                                            <td id="purchases-paid-sum">0.00</td>
                                            <td id="purchases-due-sum">0.00</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <div id="report-theme-modal" style="display:none; position:fixed; inset:0; background:rgba(0,0,0,0.55); z-index:9999; align-items:center; justify-content:center;">
            <div style="background:#fff; border-radius:12px; padding:28px 32px; width:480px; max-width:95vw; box-shadow:0 8px 40px rgba(0,0,0,0.25); direction:rtl;">
                <h4 style="margin:0 0 6px 0; font-size:17px; color:#1a3c5e;">اختر تصميم التقرير</h4>
                <p style="margin:0 0 20px 0; font-size:12px; color:#777;">التصميم سيظهر في نافذة الطباعة مع هيدر موحّد</p>

                <div style="display:grid; grid-template-columns:1fr 1fr; gap:12px; margin-bottom:24px;">
                    <div class="report-theme-card" onclick="selectReportTheme('navy')" data-theme="navy"
                         style="border:2px solid #1a3c5e; border-radius:8px; padding:12px; cursor:pointer; text-align:center; background:#f0f4f8;">
                        <div style="height:28px; background:#1a3c5e; border-radius:4px; margin-bottom:8px;"></div>
                        <div style="height:8px; background:#c8960a; border-radius:2px; margin-bottom:6px;"></div>
                        <div style="height:6px; background:#eef2f7; border-radius:2px;"></div>
                        <div style="margin-top:8px; font-size:12px; font-weight:bold; color:#1a3c5e;">كحلي ذهبي</div>
                        <div style="font-size:10px; color:#888;">الافتراضي</div>
                    </div>

                    <div class="report-theme-card" onclick="selectReportTheme('green')" data-theme="green"
                         style="border:2px solid #ddd; border-radius:8px; padding:12px; cursor:pointer; text-align:center; background:#fff;">
                        <div style="height:28px; background:#1b5e38; border-radius:4px; margin-bottom:8px;"></div>
                        <div style="height:8px; background:#4caf50; border-radius:2px; margin-bottom:6px;"></div>
                        <div style="height:6px; background:#e8f5e9; border-radius:2px;"></div>
                        <div style="margin-top:8px; font-size:12px; font-weight:bold; color:#1b5e38;">أخضر</div>
                        <div style="font-size:10px; color:#888;">رسمي هادئ</div>
                    </div>

                    <div class="report-theme-card" onclick="selectReportTheme('gray')" data-theme="gray"
                         style="border:2px solid #ddd; border-radius:8px; padding:12px; cursor:pointer; text-align:center; background:#fff;">
                        <div style="height:28px; background:#37474f; border-radius:4px; margin-bottom:8px;"></div>
                        <div style="height:8px; background:#90a4ae; border-radius:2px; margin-bottom:6px;"></div>
                        <div style="height:6px; background:#eceff1; border-radius:2px;"></div>
                        <div style="margin-top:8px; font-size:12px; font-weight:bold; color:#37474f;">رمادي</div>
                        <div style="font-size:10px; color:#888;">احترافي بسيط</div>
                    </div>

                    <div class="report-theme-card" onclick="selectReportTheme('burgundy')" data-theme="burgundy"
                         style="border:2px solid #ddd; border-radius:8px; padding:12px; cursor:pointer; text-align:center; background:#fff;">
                        <div style="height:28px; background:#6a0f2a; border-radius:4px; margin-bottom:8px;"></div>
                        <div style="height:8px; background:#c0392b; border-radius:2px; margin-bottom:6px;"></div>
                        <div style="height:6px; background:#fdf0f0; border-radius:2px;"></div>
                        <div style="margin-top:8px; font-size:12px; font-weight:bold; color:#6a0f2a;">بردوني</div>
                        <div style="font-size:10px; color:#888;">فخم مميز</div>
                    </div>
                </div>

                <div style="display:flex; gap:10px; justify-content:flex-end;">
                    <button type="button" onclick="closeReportThemeModal()" style="padding:8px 20px; border:1px solid #ddd; border-radius:6px; background:#f5f5f5; cursor:pointer; font-size:13px;">إغلاق</button>
                    <button type="button" onclick="printStyledReport();" style="padding:8px 20px; border:none; border-radius:6px; background:#1a3c5e; color:#fff; cursor:pointer; font-size:13px;">
                        <i class="fa fa-print"></i> طباعة الآن
                    </button>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<script>
    var pageUrl = "<?php echo e(route('report.purchases')); ?>";
    var columns = [];

    function normalizeArabicDigits(str) {
        if (!str) return '';
        return String(str)
            .replace(/[٠-٩]/g, function(d) { return '٠١٢٣٤٥٦٧٨٩'.indexOf(d); })
            .replace(/[۰-۹]/g, function(d) { return '۰۱۲۳۴۵۶۷۸۹'.indexOf(d); });
    }

    function formatDateToDMY(value) {
        if (!value) return '';

        var str = normalizeArabicDigits(String(value).trim());

        if (/^\d{2}\/\d{2}\/\d{4}$/.test(str)) return str;

        if (/^\d{4}-\d{2}-\d{2}$/.test(str)) {
            var a = str.split('-');
            return a[2] + '/' + a[1] + '/' + a[0];
        }

        if (/^\d{4}-\d{2}-\d{2}\s/.test(str)) {
            var b = str.split(' ')[0].split('-');
            return b[2] + '/' + b[1] + '/' + b[0];
        }

        if (/^\d{2}-\d{2}-\d{4}$/.test(str)) {
            var c = str.split('-');
            return c[0] + '/' + c[1] + '/' + c[2];
        }

        var months = {
            'يناير':'01',
            'فبراير':'02',
            'مارس':'03',
            'أبريل':'04',
            'ابريل':'04',
            'مايو':'05',
            'يونيو':'06',
            'يوليو':'07',
            'أغسطس':'08',
            'اغسطس':'08',
            'سبتمبر':'09',
            'أكتوبر':'10',
            'اكتوبر':'10',
            'نوفمبر':'11',
            'ديسمبر':'12'
        };

        var match = str.match(/(\d{1,2})\s+([^\s،,]+)\s+(\d{4})/);
        if (match) {
            var day = ('0' + match[1]).slice(-2);
            var month = months[match[2]] || '';
            var year = match[3];
            if (month) return day + '/' + month + '/' + year;
        }

        return str;
    }

    columns.push(
        {
            data: 'id',
            name: 'id',
            orderable: false,
            searchable: false,
            className: 'col-index'
        },
        {
            data: "branche",
            name: "branche",
            className: 'col-branch'
        },
        {
            data: "post_date",
            name: "post_date",
            className: 'col-date',
            render: function(data) {
                return formatDateToDMY(data);
            }
        },
        {
            data: "creator",
            name: "creator",
            className: 'col-creator'
        },
        {
            data: "supplier",
            name: "supplier",
            className: 'col-supplier'
        },
        {
            data: "payment",
            name: "payment",
            className: 'col-payment'
        },
        {
            data: "total",
            name: "total",
            className: 'col-total'
        },
        {
            data: "total_paid",
            name: "total_paid",
            className: 'col-paid'
        },
        {
            data: "total_due",
            name: "total_due",
            className: 'col-due'
        }
    );
</script>

<?php echo $__env->make('_partial.datatable', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

<?php $__env->startPush('js'); ?>
<script>
    var reportThemes = {
        navy:     { primary:'#1a3c5e', primaryDk:'#0d2a45', accent:'#c8960a', accentLt:'#f0b429', rowAlt:'#f4f7fc', lblBg:'#eef2f7' },
        green:    { primary:'#1b5e38', primaryDk:'#144d2c', accent:'#4caf50', accentLt:'#81c784', rowAlt:'#f1f8f2', lblBg:'#e8f5e9' },
        gray:     { primary:'#37474f', primaryDk:'#263238', accent:'#78909c', accentLt:'#b0bec5', rowAlt:'#f5f6f7', lblBg:'#eceff1' },
        burgundy: { primary:'#6a0f2a', primaryDk:'#4a0a1e', accent:'#c0392b', accentLt:'#e57373', rowAlt:'#fdf5f6', lblBg:'#fdf0f0' }
    };

    var currentReportTheme = localStorage.getItem('report_theme') || 'navy';

    var reportSettings = {
        siteName:    <?php echo json_encode($settings['SiteName']    ?? '', 15, 512) ?>,
        siteNameEn:  <?php echo json_encode($settings['SiteNameEn']  ?? '', 15, 512) ?>,
        address:     <?php echo json_encode($settings['Address']     ?? '', 15, 512) ?>,
        addressEn:   <?php echo json_encode($settings['AddressEn']   ?? '', 15, 512) ?>,
        mobile:      <?php echo json_encode($settings['mobile']      ?? '', 15, 512) ?>,
        mobileEn:    <?php echo json_encode($settings['mobileEn']    ?? '', 15, 512) ?>,
        taxNumber:   <?php echo json_encode($settings['taxnumber']   ?? '', 15, 512) ?>,
        taxNumberEn: <?php echo json_encode($settings['taxnumberEn'] ?? '', 15, 512) ?>,
        logo:        <?php echo json_encode(!empty($settings['logo']) ? \Illuminate\Support\Facades\Storage::url('logo/' . $settings['logo']) : '', 15, 512) ?>
    };

    var reportTitle    = <?php echo json_encode('تقرير المشتريات', 15, 512) ?>;
    var reportUserName = <?php echo json_encode(optional($currentUser)->name ?? '', 15, 512) ?>;

    function openReportThemeModal() {
        document.getElementById('report-theme-modal').style.display = 'flex';
        updateThemeCards();
    }

    function closeReportThemeModal() {
        document.getElementById('report-theme-modal').style.display = 'none';
    }

    function updateThemeCards() {
        document.querySelectorAll('.report-theme-card').forEach(function(c) {
            var name   = c.getAttribute('data-theme');
            var t      = reportThemes[name];
            var active = (name === currentReportTheme);
            c.style.border     = active ? '2px solid ' + t.primary : '2px solid #ddd';
            c.style.background = active ? '#f0f4f8' : '#fff';
        });
    }

    function selectReportTheme(name) {
        currentReportTheme = name;
        localStorage.setItem('report_theme', name);
        updateThemeCards();
    }

    function escapeHtml(str) {
        return String(str == null ? '' : str).replace(/[&<>"']/g, function(c) {
            return {'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c];
        });
    }

    function parseNumber(value) {
        if (value === null || value === undefined) return 0;
        var num = parseFloat(String(value).replace(/[^0-9.\-]/g, ''));
        return isNaN(num) ? 0 : num;
    }

    function formatNumber(n) {
        return n.toLocaleString('en-US', {
            minimumFractionDigits: 2,
            maximumFractionDigits: 2
        });
    }

    function updatePurchasesTotals() {
        var dt;
        try {
            dt = $('#serverSideTable').DataTable();
        } catch (e) {
            return;
        }

        var sumTotal = 0;
        var sumPaid  = 0;
        var sumDue   = 0;

        dt.column(6, { search: 'applied' }).data().each(function(value) {
            sumTotal += parseNumber(value);
        });

        dt.column(7, { search: 'applied' }).data().each(function(value) {
            sumPaid += parseNumber(value);
        });

        dt.column(8, { search: 'applied' }).data().each(function(value) {
            sumDue += parseNumber(value);
        });

        $('#purchases-total-sum').text(formatNumber(sumTotal));
        $('#purchases-paid-sum').text(formatNumber(sumPaid));
        $('#purchases-due-sum').text(formatNumber(sumDue));
    }

    function printStyledReport() {
        var t  = reportThemes[currentReportTheme];
        var dt = $('#serverSideTable').DataTable();

        var headers     = [];
        var visibleIdxs = [];
        var totalColPos = -1;
        var paidColPos  = -1;
        var dueColPos   = -1;

        dt.columns().every(function() {
            if (!this.visible()) return;

            var colIdx = this.index();
            var txt = $(this.header()).text().trim();

            headers.push(txt);
            visibleIdxs.push(colIdx);

            if (txt === 'الإجمالى' || txt === 'الإجمالي') totalColPos = headers.length - 1;
            if (txt === 'المدفوع') paidColPos = headers.length - 1;
            if (txt === 'المتبقى' || txt === 'المتبقي') dueColPos = headers.length - 1;
        });

        var rowsHtml = '';
        var rowIter  = 0;
        var sumTotal = 0;
        var sumPaid  = 0;
        var sumDue   = 0;

        var allRows = dt.rows({ search: 'applied' }).nodes();

        $(allRows).each(function() {
            var $tr = $(this);
            if ($tr.find('.dataTables_empty').length) return;

            rowIter++;
            var rowClass = (rowIter % 2 === 0) ? 'row-even' : '';
            var rowHtml  = '<tr class="' + rowClass + '">';

            visibleIdxs.forEach(function(colIdx, posIdx) {
                var cellNode = null;
                try { cellNode = dt.cell($tr.get(0), colIdx).node(); } catch (e) {}
                var text = cellNode ? $(cellNode).text().trim() : '';

                if (headers[posIdx] === 'التاريخ') {
                    text = formatDateToDMY(text);
                }

                rowHtml += '<td class="td-center">' + escapeHtml(text) + '</td>';

                if (posIdx === totalColPos) sumTotal += parseNumber(text);
                if (posIdx === paidColPos)  sumPaid  += parseNumber(text);
                if (posIdx === dueColPos)   sumDue   += parseNumber(text);
            });

            rowHtml += '</tr>';
            rowsHtml += rowHtml;
        });

        if (rowIter === 0) {
            alert('لا توجد بيانات للطباعة');
            return;
        }

        var totalsRow = '<tr class="totals-sum-row">';
        headers.forEach(function(h, idx) {
            if (idx === 0) {
                totalsRow += '<td class="totals-label">المجموع (Total)</td>';
            } else if (idx === totalColPos) {
                totalsRow += '<td class="totals-value">' + formatNumber(sumTotal) + '</td>';
            } else if (idx === paidColPos) {
                totalsRow += '<td class="totals-value">' + formatNumber(sumPaid) + '</td>';
            } else if (idx === dueColPos) {
                totalsRow += '<td class="totals-value">' + formatNumber(sumDue) + '</td>';
            } else {
                totalsRow += '<td></td>';
            }
        });
        totalsRow += '</tr>';
        rowsHtml += totalsRow;

        var now     = new Date();
        var pad     = function(n) { return ('0' + n).slice(-2); };
        var dateStr = now.getFullYear() + '-' + pad(now.getMonth() + 1) + '-' + pad(now.getDate());
        var timeStr = pad(now.getHours()) + ':' + pad(now.getMinutes());

        var headerHtml =
            '<div class="report-header">' +
                '<table style="width:100%; table-layout:fixed; direction:rtl; border-collapse:collapse;">' +
                    '<tr>' +
                        '<td style="width:36%; vertical-align:middle; text-align:right; direction:rtl; padding:0 0 0 10px;">' +
                            '<div style="font-size:16px; font-weight:bold; line-height:1.6; color:var(--theme-primary);">' + escapeHtml(reportSettings.siteName) + '</div>' +
                            (reportSettings.address ? '<div style="font-size:11px; font-weight:bold; line-height:1.5;">' + escapeHtml(reportSettings.address) + '</div>' : '') +
                            (reportSettings.mobile ? '<div style="font-size:11px; font-weight:bold; line-height:1.5;">' + escapeHtml(reportSettings.mobile) + '</div>' : '') +
                            '<div style="font-size:11px; font-weight:bold; line-height:1.5;">الرقم الضريبى: ' + escapeHtml(reportSettings.taxNumber) + '</div>' +
                        '</td>' +
                        '<td style="width:28%; vertical-align:middle; text-align:center; padding:0 8px;">' +
                            (reportSettings.logo ? '<img style="max-height:72px; max-width:100%;" src="' + reportSettings.logo + '">' : '') +
                        '</td>' +
                        '<td style="width:36%; vertical-align:middle; text-align:left; direction:ltr; padding:0 10px 0 0;">' +
                            '<div style="font-size:16px; font-weight:bold; line-height:1.6; color:var(--theme-primary);">' + escapeHtml(reportSettings.siteNameEn) + '</div>' +
                            (reportSettings.addressEn ? '<div style="font-size:11px; font-weight:bold; line-height:1.5;">' + escapeHtml(reportSettings.addressEn) + '</div>' : '') +
                            (reportSettings.mobileEn ? '<div style="font-size:11px; font-weight:bold; line-height:1.5;">' + escapeHtml(reportSettings.mobileEn) + '</div>' : '') +
                            '<div style="font-size:11px; font-weight:bold; line-height:1.5;">Tax Number: ' + escapeHtml(reportSettings.taxNumberEn) + '</div>' +
                        '</td>' +
                    '</tr>' +
                '</table>' +
            '</div>';

        var titleHtml =
            '<div class="inv-title-block">' +
                '<div class="inv-title-ar">' + escapeHtml(reportTitle) + '</div>' +
                '<div class="inv-number">تاريخ الإصدار &nbsp;|&nbsp; Issued: <strong>' + dateStr + ' — ' + timeStr + '</strong></div>' +
            '</div>';

        var metaHtml =
            '<table class="meta-table"><tr>' +
                '<td><span class="meta-lbl">اسم التقرير (Report):</span>' + escapeHtml(reportTitle) + '</td>' +
                '<td><span class="meta-lbl">المستخدم (User):</span>' + escapeHtml(reportUserName) + '</td>' +
                '<td><span class="meta-lbl">عدد السجلات (Count):</span>' + rowIter + '</td>' +
                '<td><span class="meta-lbl">الوقت (Time):</span>' + timeStr + '</td>' +
            '</tr></table>';

        var tableHeadHtml = '<tr class="items-head-row">';
        headers.forEach(function(h) {
            tableHeadHtml += '<th>' + escapeHtml(h) + '</th>';
        });
        tableHeadHtml += '</tr>';

        var tableHtml = '<table class="items-tbl"><thead>' + tableHeadHtml + '</thead><tbody>' + rowsHtml + '</tbody></table>';
        var footerHtml = '<div class="report-footer">© ' + now.getFullYear() + ' ' + escapeHtml(reportSettings.siteName) + '</div>';

        var css = buildReportCSS(t);
        var fullHtml =
            '<!DOCTYPE html>' +
            '<html lang="ar" dir="rtl">' +
            '<head>' +
                '<meta charset="UTF-8">' +
                '<title>' + escapeHtml(reportTitle) + '</title>' +
                '<link href="https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700;900&display=swap" rel="stylesheet">' +
                '<style>' + css + '</style>' +
            '</head>' +
            '<body>' +
                '<div id="printReport">' +
                    headerHtml +
                    titleHtml +
                    metaHtml +
                    tableHtml +
                    footerHtml +
                '</div>' +
                '<script>window.addEventListener("load", function(){ setTimeout(function(){ window.focus(); window.print(); }, 400); });<\/script>' +
            '</body></html>';

        var printWin = window.open('', '_blank', 'width=1200,height=850');
        if (!printWin) {
            alert('يرجى السماح بالنوافذ المنبثقة في المتصفح للطباعة');
            return;
        }

        printWin.document.open();
        printWin.document.write(fullHtml);
        printWin.document.close();

        closeReportThemeModal();
    }

    function buildReportCSS(t) {
        return [
            ':root{',
                '--theme-primary:' + t.primary + ';',
                '--theme-primary-dk:' + t.primaryDk + ';',
                '--theme-accent:' + t.accent + ';',
                '--theme-accent-lt:' + t.accentLt + ';',
                '--theme-row-alt:' + t.rowAlt + ';',
                '--theme-lbl-bg:' + t.lblBg + ';',
            '}',
            '*{box-sizing:border-box;}',
            'html,body{margin:0;padding:0;}',
            'body{font-family:"Tajawal","Segoe UI",Tahoma,Arial,sans-serif;direction:rtl;padding:12px;color:#111;font-size:12px;background:#fff;}',
            '#printReport{width:100%;max-width:100%;margin:0 auto;overflow:hidden;}',
            '.report-header{margin-bottom:10px;padding-bottom:8px;border-bottom:2px solid var(--theme-primary);}',
            '.report-header table{width:100% !important;max-width:100% !important;}',
            '.inv-title-block{text-align:center;border-top:3px solid var(--theme-primary);border-bottom:3px solid var(--theme-primary);padding:8px 0;margin-bottom:8px;forced-color-adjust:none;-webkit-print-color-adjust:exact;print-color-adjust:exact;}',
            '.inv-title-ar{font-size:18px;font-weight:900;color:var(--theme-primary);letter-spacing:1px;}',
            '.inv-number{font-size:12px;color:#555;margin-top:3px;}',
            '.inv-number strong{color:var(--theme-accent);font-size:13px;}',
            '.meta-table{width:100% !important;max-width:100% !important;table-layout:fixed;background:var(--theme-primary);color:#fff;margin-bottom:10px;border-collapse:collapse;border-radius:3px;forced-color-adjust:none;-webkit-print-color-adjust:exact;print-color-adjust:exact;}',
            '.meta-table td{padding:6px 8px;font-size:11px;text-align:center;border:none;vertical-align:middle;word-wrap:break-word;overflow-wrap:break-word;}',
            '.meta-lbl{display:block;color:var(--theme-accent-lt);font-weight:bold;font-size:10px;margin-bottom:2px;}',
            '.items-tbl{width:100% !important;max-width:100% !important;border-collapse:collapse;margin-bottom:10px;table-layout:fixed;border:2px solid #333;}',
            '.items-tbl thead .items-head-row th{background:var(--theme-primary);color:#fff;text-align:center;font-size:11px;font-weight:bold;padding:7px 3px;border:1px solid var(--theme-primary-dk);line-height:1.4;word-wrap:break-word;overflow-wrap:break-word;forced-color-adjust:none;-webkit-print-color-adjust:exact;print-color-adjust:exact;}',
            '.items-tbl tbody tr td{border:1px solid #333;padding:5px 3px;font-size:11px;font-weight:bold;vertical-align:middle;text-align:center;word-wrap:break-word;overflow-wrap:break-word;word-break:break-word;white-space:normal;}',
            '.items-tbl tbody tr.row-even td{background:var(--theme-row-alt);}',
            '.items-tbl tbody tr.totals-sum-row td{background:var(--theme-primary) !important;color:#fff !important;font-size:12px !important;font-weight:bold !important;padding:8px 4px !important;border:1px solid var(--theme-primary-dk) !important;forced-color-adjust:none;-webkit-print-color-adjust:exact;print-color-adjust:exact;}',
            '.items-tbl tbody tr.totals-sum-row td.totals-label{text-align:center;font-size:13px !important;}',
            '.items-tbl tbody tr.totals-sum-row td.totals-value{text-align:center;font-size:13px !important;color:var(--theme-accent-lt) !important;}',
            '.report-footer{text-align:center;font-size:10px;color:#888;margin-top:12px;padding-top:6px;border-top:1px dashed #ccc;}',
            '@media  print{',
                '@page{margin:15mm 12mm;}',
                'html,body{margin:0 !important;padding:0 !important;width:100% !important;}',
                '#printReport{width:100% !important;max-width:100% !important;padding:0 !important;margin:0 !important;}',
                '*{-webkit-print-color-adjust:exact !important;print-color-adjust:exact !important;color-adjust:exact !important;}',
                '.items-tbl{width:100% !important;max-width:100% !important;table-layout:fixed !important;border:2px solid #333 !important;}',
                '.items-tbl tbody tr{page-break-inside:avoid;break-inside:avoid;}',
                '.items-tbl thead{display:table-header-group;}',
                '.report-header,.inv-title-block,.meta-table{page-break-inside:avoid;}',
            '}'
        ].join('');
    }

    $(document).ready(function() {
        setTimeout(function() {
            updateThemeCards();
            $('.dt-buttons .buttons-print').hide();

            var dt;
            try {
                dt = $('#serverSideTable').DataTable();
            } catch (e) {
                return;
            }

            dt.on('draw', function() {
                updatePurchasesTotals();
            });

            updatePurchasesTotals();
        }, 400);
    });

    document.addEventListener('click', function(e) {
        var modal = document.getElementById('report-theme-modal');
        if (e.target === modal) closeReportThemeModal();
    });
</script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('layouts.front', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/mwarsha2023/public_html/test4.mwarsha.com/resources/views/reports/purchases.blade.php ENDPATH**/ ?>