<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sales Report</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            line-height: 1.6;
            color: #333;
            background: #f5f5f5;
        }

        @media print {
            body {
                background: white;
            }
            .no-print {
                display: none !important;
            }
            .page-break {
                page-break-after: always;
            }
        }

        .report-container {
            max-width: 11in;
            height: 8.5in;
            margin: 20px auto;
            padding: 40px;
            background: white;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        /* Header Section */
        .report-header {
            border-bottom: 3px solid #2c3e50;
            margin-bottom: 20px;
            padding-bottom: 15px;
        }

        .company-logo {
            font-size: 24px;
            font-weight: bold;
            color: #2c3e50;
            margin-bottom: 5px;
        }

        .company-info {
            font-size: 11px;
            color: #666;
            line-height: 1.4;
        }

        .report-title {
            text-align: center;
            font-size: 18px;
            font-weight: bold;
            color: #2c3e50;
            margin-top: 15px;
            margin-bottom: 10px;
        }

        .report-period {
            text-align: center;
            font-size: 12px;
            color: #666;
            margin-bottom: 20px;
        }

        /* Summary Cards */
        .summary-section {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 15px;
            margin-bottom: 20px;
        }

        .summary-card {
            border: 1px solid #ddd;
            padding: 10px;
            border-radius: 4px;
            background: #f9f9f9;
        }

        .summary-card-label {
            font-size: 10px;
            color: #666;
            text-transform: uppercase;
            font-weight: 600;
            margin-bottom: 5px;
        }

        .summary-card-value {
            font-size: 14px;
            font-weight: bold;
            color: #2c3e50;
        }

        /* Table Styling */
        .sales-table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
            font-size: 11px;
        }

        .sales-table thead {
            background: #34495e;
            color: white;
        }

        .sales-table th {
            padding: 10px 8px;
            text-align: left;
            font-weight: 600;
            border: 1px solid #34495e;
        }

        .sales-table td {
            padding: 8px;
            border: 1px solid #ddd;
            border-bottom: 1px solid #e0e0e0;
        }

        .sales-table tbody tr:nth-child(even) {
            background: #f9f9f9;
        }

        .sales-table tbody tr:hover {
            background: #f0f0f0;
        }

        .text-center {
            text-align: center;
        }

        .text-end {
            text-align: right;
        }

        .text-start {
            text-align: left;
        }

        /* Breakdown Tables */
        .breakdown-section {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 20px;
            margin-top: 20px;
        }

        .breakdown-table {
            width: 100%;
            border-collapse: collapse;
            font-size: 11px;
        }

        .breakdown-table thead {
            background: #ecf0f1;
            border-top: 2px solid #34495e;
            border-bottom: 2px solid #34495e;
        }

        .breakdown-table th {
            padding: 8px;
            text-align: left;
            font-weight: 600;
            color: #2c3e50;
        }

        .breakdown-table td {
            padding: 6px 8px;
            border-bottom: 1px solid #e0e0e0;
        }

        .breakdown-table tbody tr:nth-child(even) {
            background: #f9f9f9;
        }

        .breakdown-table tbody tr:last-child {
            border-top: 2px solid #34495e;
            font-weight: bold;
            background: #ecf0f1;
        }

        .section-title {
            font-size: 12px;
            font-weight: bold;
            color: #2c3e50;
            margin-bottom: 8px;
            margin-top: 15px;
            padding-bottom: 5px;
            border-bottom: 2px solid #34495e;
        }

        /* Footer */
        .report-footer {
            margin-top: 30px;
            padding-top: 15px;
            border-top: 1px solid #ddd;
            text-align: center;
            font-size: 10px;
            color: #666;
        }

        .print-button {
            display: inline-block;
            margin: 20px auto;
            padding: 10px 20px;
            background: #3498db;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 12px;
        }

        .print-button:hover {
            background: #2980b9;
        }

        .no-print-container {
            text-align: center;
            margin: 20px 0;
        }

        /* Print specific */
        @media print {
            .report-container {
                box-shadow: none;
                margin: 0;
                padding: 30px;
                max-width: 100%;
            }

            body {
                margin: 0;
                padding: 0;
            }

            .print-button {
                display: none;
            }
        }

        /* Responsive */
        @media (max-width: 768px) {
            .summary-section {
                grid-template-columns: repeat(2, 1fr);
            }

            .breakdown-section {
                grid-template-columns: 1fr;
            }

            .report-container {
                max-width: 100%;
                margin: 0;
                padding: 20px;
            }
        }
    </style>
</head>
<body>
    <div class="no-print-container no-print">
        <button class="print-button" onclick="window.print()">🖨️ Print Report</button>
    </div>

    <div class="report-container">
        <!-- Report Header -->
        <div class="report-header">
            <div class="company-logo">JANNAT ACCOUNTING SYSTEM</div>
            <div class="company-info">
                Sales Report<br>
                Generated on <?php echo e(now()->format('d M Y, H:i A')); ?>

            </div>
        </div>

        <!-- Report Title -->
        <div class="report-title">SALES REPORT</div>
        <div class="report-period">
            Period: <strong><?php echo e(\Carbon\Carbon::createFromDate($year, $month, 1)->format('F Y')); ?></strong>
        </div>

        <!-- Summary Cards -->
        <div class="summary-section">
            <div class="summary-card">
                <div class="summary-card-label">Total Sales</div>
                <div class="summary-card-value"><?php echo e(number_format($summary['total_sales'], 0)); ?></div>
            </div>
            <div class="summary-card">
                <div class="summary-card-label">Total Paid</div>
                <div class="summary-card-value"><?php echo e(number_format($summary['total_paid'], 0)); ?></div>
            </div>
            <div class="summary-card">
                <div class="summary-card-label">Total Due</div>
                <div class="summary-card-value"><?php echo e(number_format($summary['total_due'], 0)); ?></div>
            </div>
            <div class="summary-card">
                <div class="summary-card-label">Total COGS</div>
                <div class="summary-card-value"><?php echo e(number_format($summary['total_sales'] - $summary['total_profit'], 0)); ?></div>
            </div>
        </div>

        <!-- Sales Details Table -->
        <div class="section-title">Sales Details</div>
        <table class="sales-table">
            <thead>
                <tr>
                    <th style="width: 8%;">Date</th>
                    <th style="width: 10%;">Invoice</th>
                    <th style="width: 18%;">Product</th>
                    <th style="width: 6%;" class="text-center">QTY</th>
                    <th style="width: 10%;" class="text-end">Sales</th>
                    <th style="width: 8%;" class="text-center">Payment</th>
                    <th style="width: 8%;" class="text-end">Due</th>
                    <th style="width: 8%;" class="text-end">COGS</th>
                    <th style="width: 12%;" class="text-end">Profit</th>
                    <th style="width: 6%;" class="text-end">%</th>
                </tr>
            </thead>
            <tbody>
                <?php $__empty_1 = true; $__currentLoopData = $salesLines; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $line): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr>
                        <td class="text-start"><?php echo e($line['date']->format('d/m/y')); ?></td>
                        <td class="text-start fw-bold"><?php echo e($line['invoice_no']); ?></td>
                        <td class="text-start"><?php echo e(substr($line['product_name'], 0, 20)); ?></td>
                        <td class="text-center"><?php echo e($line['qty']); ?></td>
                        <td class="text-end"><?php echo e(number_format($line['total_sales'], 0)); ?></td>
                        <td class="text-center">
                            <?php if($line['payment_method'] === 'Paid'): ?>
                                ✓ Paid
                            <?php elseif($line['payment_method'] === 'Partial'): ?>
                                ◐ Partial
                            <?php else: ?>
                                - Pending
                            <?php endif; ?>
                        </td>
                        <td class="text-end"><?php echo e(number_format($line['due'], 0)); ?></td>
                        <td class="text-end"><?php echo e(number_format($line['cogs'], 0)); ?></td>
                        <td class="text-end"><?php echo e(number_format($line['gross_profit'], 0)); ?></td>
                        <td class="text-end"><?php echo e(number_format($line['percentage'], 1)); ?>%</td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr>
                        <td colspan="10" class="text-center">No sales data found for the selected period.</td>
                    </tr>
                <?php endif; ?>
            </tbody>
        </table>

        <!-- Payment Breakdown and Day-wise Sales -->
        <div class="breakdown-section">
            <!-- Payment Method Breakdown -->
            <div>
                <div class="section-title">Payment Method Breakdown</div>
                <table class="breakdown-table">
                    <thead>
                        <tr>
                            <th>Payment Method</th>
                            <th style="width: 35%;" class="text-end">Amount</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__currentLoopData = $paymentBreakdown; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $method => $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td><?php echo e($method); ?></td>
                                <td class="text-end"><?php echo e(number_format($data['total'], 0)); ?></td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td>Total</td>
                            <td class="text-end"><?php echo e(number_format($summary['total_paid'], 0)); ?></td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <!-- Segment-wise Sales -->
            <div>
                <div class="section-title">Segment-wise Sales</div>
                <table class="breakdown-table">
                    <thead>
                        <tr>
                            <th>Segment</th>
                            <th style="width: 20%;" class="text-center">QTY</th>
                            <th style="width: 35%;" class="text-end">Amount</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                            $hasSegmentData = false;
                            $totalAmount = 0;
                            foreach($segmentWiseSales as $segment) {
                                if($segment['qty'] > 0 || $segment['amount'] > 0) {
                                    $hasSegmentData = true;
                                    $totalAmount += $segment['amount'];
                                }
                            }
                        ?>
                        <?php if($hasSegmentData): ?>
                            <?php $__currentLoopData = $segmentWiseSales; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $segment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php if($segment['qty'] > 0 || $segment['amount'] > 0): ?>
                                    <tr>
                                        <td><?php echo e($segment['segment_name']); ?></td>
                                        <td class="text-center"><?php echo e($segment['qty']); ?></td>
                                        <td class="text-end"><?php echo e(number_format($segment['amount'], 0)); ?></td>
                                    </tr>
                                <?php endif; ?>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td><strong>Total</strong></td>
                                <td class="text-center"><strong>-</strong></td>
                                <td class="text-end"><strong><?php echo e(number_format($summary['total_sales'], 0)); ?></strong></td>
                            </tr>
                        <?php else: ?>
                            <tr>
                                <td colspan="3" class="text-center">No segment data</td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>

        <!-- Footer -->
        <div class="report-footer">
            <p>This is a computer-generated report. No signature required.</p>
            <p>Report Generated on <?php echo e(now()->format('d M Y')); ?> at <?php echo e(now()->format('H:i A')); ?></p>
        </div>
    </div>

    <script>
        // Auto-print if coming from print button
        if (new URLSearchParams(window.location.search).get('autoprint') === '1') {
            setTimeout(() => {
                window.print();
            }, 500);
        }
    </script>
</body>
</html>
<?php /**PATH C:\Users\startup sabbir\Desktop\jannat\accounting-system\resources\views/reports/sales-print.blade.php ENDPATH**/ ?>