

<?php $__env->startSection('title', 'Salesman Performance Report'); ?>

<?php $__env->startSection('content'); ?>
<?php if (isset($component)) { $__componentOriginalec19dbe11cffb801c43c3ac2f3ecf04f = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalec19dbe11cffb801c43c3ac2f3ecf04f = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.admin.report-page','data' => ['title' => 'Salesman Performance Report','subtitle' => 'POS salesman sales, profit, discounts, and share of total.']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('admin.report-page'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['title' => 'Salesman Performance Report','subtitle' => 'POS salesman sales, profit, discounts, and share of total.']); ?>
     <?php $__env->slot('actions', null, []); ?> 
        <a href="<?php echo e(route('admin.reports.salesman.export-csv', request()->only(['start_date', 'end_date', 'period', 'staff_id', 'location_id']))); ?>" class="ci-btn ci-btn--ghost">
            <i class="bi bi-download"></i> Export CSV
        </a>
        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('reports.profit')): ?>
        <a href="<?php echo e(route('admin.reports.profit')); ?>" class="ci-btn ci-btn--ghost">
            <i class="bi bi-graph-up"></i> Profit Reports
        </a>
        <?php endif; ?>
     <?php $__env->endSlot(); ?>

    <form method="GET" action="<?php echo e(route('admin.reports.salesman')); ?>" class="ci-filters ci-filters--report">
        <?php echo $__env->make('admin.reports.partials.location-filter', ['ci' => true], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
        <div class="ci-filters__field">
            <label for="period">Period</label>
            <select name="period" id="period" onchange="toggleCustomDates()">
                <option value="day" <?php echo e($period === 'day' ? 'selected' : ''); ?>>Today</option>
                <option value="week" <?php echo e($period === 'week' ? 'selected' : ''); ?>>This Week</option>
                <option value="month" <?php echo e($period === 'month' ? 'selected' : ''); ?>>This Month</option>
                <option value="year" <?php echo e($period === 'year' ? 'selected' : ''); ?>>This Year</option>
                <option value="custom" <?php echo e($period === 'custom' ? 'selected' : ''); ?>>Custom Range</option>
            </select>
        </div>

        <div class="ci-filters__field" id="startDateDiv" style="<?php echo e($period === 'custom' ? '' : 'display: none;'); ?>">
            <label for="start_date">Start Date</label>
            <input type="date" name="start_date" id="start_date" value="<?php echo e($startDate); ?>">
        </div>

        <div class="ci-filters__field" id="endDateDiv" style="<?php echo e($period === 'custom' ? '' : 'display: none;'); ?>">
            <label for="end_date">End Date</label>
            <input type="date" name="end_date" id="end_date" value="<?php echo e($endDate); ?>">
        </div>

        <div class="ci-filters__field">
            <label for="staff_id">Salesman</label>
            <select name="staff_id" id="staff_id">
                <option value="">All Salesmen</option>
                <?php $__currentLoopData = $staff; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $member): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($member->id); ?>" <?php echo e($staffId == $member->id ? 'selected' : ''); ?>>
                        <?php echo e($member->name); ?>

                    </option>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
        </div>

        <div class="ci-filters__actions">
            <button type="submit" class="ci-btn ci-btn--primary">
                <i class="bi bi-search"></i> Filter
            </button>
        </div>
    </form>

    <div class="ci-stats">
        <div class="ci-stat">
            <div>
                <p class="ci-stat__label">Total Sales</p>
                <p class="ci-stat__value ci-money">₹<?php echo e(number_format($totalSales, 2)); ?></p>
                <p class="ci-stat__meta"><?php echo e($totalOrders); ?> orders</p>
            </div>
            <span class="ci-stat__icon"><i class="bi bi-currency-rupee"></i></span>
        </div>

        <div class="ci-stat">
            <div>
                <p class="ci-stat__label">Total Profit</p>
                <p class="ci-stat__value ci-money">₹<?php echo e(number_format($totalProfit, 2)); ?></p>
                <p class="ci-stat__meta">
                    <?php if($totalSales > 0): ?>
                        <?php echo e(number_format(($totalProfit / $totalSales) * 100, 1)); ?>% margin
                    <?php else: ?>
                        0% margin
                    <?php endif; ?>
                </p>
            </div>
            <span class="ci-stat__icon"><i class="bi bi-graph-up"></i></span>
        </div>

        <div class="ci-stat">
            <div>
                <p class="ci-stat__label">Total Orders</p>
                <p class="ci-stat__value"><?php echo e(number_format($totalOrders)); ?></p>
                <p class="ci-stat__meta">
                    <?php if($totalOrders > 0): ?>
                        ₹<?php echo e(number_format($totalSales / $totalOrders, 0)); ?> avg
                    <?php else: ?>
                        ₹0 avg
                    <?php endif; ?>
                </p>
            </div>
            <span class="ci-stat__icon"><i class="bi bi-receipt"></i></span>
        </div>

        <div class="ci-stat">
            <div>
                <p class="ci-stat__label">Total Discounts</p>
                <p class="ci-stat__value ci-money">₹<?php echo e(number_format($totalDiscounts, 2)); ?></p>
                <p class="ci-stat__meta">
                    <?php if($totalSales > 0): ?>
                        <?php echo e(number_format(($totalDiscounts / ($totalSales + $totalDiscounts)) * 100, 1)); ?>% of gross
                    <?php else: ?>
                        0% of gross
                    <?php endif; ?>
                </p>
            </div>
            <span class="ci-stat__icon"><i class="bi bi-percent"></i></span>
        </div>
    </div>

    <div class="ci-section">
        <div class="ci-section__head">
            <h5>
                <i class="bi bi-people"></i> Salesman Performance
                <small class="text-muted">(<?php echo e($startDate); ?> to <?php echo e($endDate); ?>)</small>
            </h5>
        </div>
        <div class="ci-section__body--flush">
            <div class="ci-table-card" style="border:0;border-radius:0;box-shadow:none;">
                <div class="ci-table-wrap">
                    <table class="ci-table">
                        <thead>
                            <tr>
                                <th>Salesman</th>
                                <th class="ci-end">Orders</th>
                                <th class="ci-end">Total Sales</th>
                                <th class="ci-end">Total Profit</th>
                                <th class="ci-end">Profit Margin</th>
                                <th class="ci-end">Avg Order Value</th>
                                <th class="ci-end">Total Discounts</th>
                                <th>Performance</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__empty_1 = true; $__currentLoopData = $salesmanData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <tr>
                                    <td>
                                        <div>
                                            <strong><?php echo e($data['staff_name']); ?></strong>
                                            <?php if($data['staff_email']): ?>
                                                <br><small class="text-muted"><?php echo e($data['staff_email']); ?></small>
                                            <?php endif; ?>
                                        </div>
                                    </td>
                                    <td class="ci-end">
                                        <span class="ci-pill ci-pill--count"><?php echo e($data['total_orders']); ?></span>
                                    </td>
                                    <td class="ci-end ci-money">
                                        ₹<?php echo e(number_format($data['total_sales'], 2)); ?>

                                    </td>
                                    <td class="ci-end ci-money" style="color:var(--ci-success);">
                                        ₹<?php echo e(number_format($data['total_profit'], 2)); ?>

                                    </td>
                                    <td class="ci-end">
                                        <?php if($data['profit_margin'] > 0): ?>
                                            <span class="ci-pill ci-pill--success"><?php echo e(number_format($data['profit_margin'], 1)); ?>%</span>
                                        <?php else: ?>
                                            <span class="ci-pill ci-pill--inactive">0%</span>
                                        <?php endif; ?>
                                    </td>
                                    <td class="ci-end ci-money">₹<?php echo e(number_format($data['avg_order_value'], 2)); ?></td>
                                    <td class="ci-end ci-money">₹<?php echo e(number_format($data['total_discounts'], 2)); ?></td>
                                    <td>
                                        <?php
                                            $performance = $totalSales > 0 ? ($data['total_sales'] / $totalSales) * 100 : 0;
                                        ?>
                                        <div class="progress" style="height: 20px;">
                                            <div class="progress-bar
                                                <?php if($performance >= 30): ?> bg-success
                                                <?php elseif($performance >= 15): ?> bg-warning
                                                <?php else: ?> bg-danger
                                                <?php endif; ?>"
                                                role="progressbar"
                                                style="width: <?php echo e(min($performance, 100)); ?>%"
                                                aria-valuenow="<?php echo e($performance); ?>"
                                                aria-valuemin="0"
                                                aria-valuemax="100">
                                                <?php echo e(number_format($performance, 1)); ?>%
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <tr>
                                    <td colspan="8">
                                        <div class="ci-empty">
                                            <i class="bi bi-people"></i>
                                            <h3>No Salesman Data Found</h3>
                                            <p>No POS sales found for the selected period and filters.</p>
                                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('pos_access')): ?>
                                            <a href="<?php echo e(route('admin.pos.index')); ?>" class="ci-btn ci-btn--primary" target="_blank">
                                                <i class="bi bi-cash-stack"></i> Open POS
                                            </a>
                                            <?php endif; ?>
                                        </div>
                                    </td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginalec19dbe11cffb801c43c3ac2f3ecf04f)): ?>
<?php $attributes = $__attributesOriginalec19dbe11cffb801c43c3ac2f3ecf04f; ?>
<?php unset($__attributesOriginalec19dbe11cffb801c43c3ac2f3ecf04f); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalec19dbe11cffb801c43c3ac2f3ecf04f)): ?>
<?php $component = $__componentOriginalec19dbe11cffb801c43c3ac2f3ecf04f; ?>
<?php unset($__componentOriginalec19dbe11cffb801c43c3ac2f3ecf04f); ?>
<?php endif; ?>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
function toggleCustomDates() {
    const period = document.getElementById('period').value;
    const startDateDiv = document.getElementById('startDateDiv');
    const endDateDiv = document.getElementById('endDateDiv');

    if (period === 'custom') {
        startDateDiv.style.display = 'block';
        endDateDiv.style.display = 'block';
    } else {
        startDateDiv.style.display = 'none';
        endDateDiv.style.display = 'none';
    }
}

// Initialize on page load
document.addEventListener('DOMContentLoaded', function() {
    toggleCustomDates();
});
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /var/www/html/shivajewellers_uat/resources/views/admin/reports/salesman.blade.php ENDPATH**/ ?>