
<?php $__env->startSection('title', 'Cost of Production History'); ?>

<?php $__env->startSection('content'); ?>
<div class="page-content">
    <div class="row">
        <div class="col-md-12 grid-margin stretch-card">
            <div class="card">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-center mb-4">
                        <h6 class="card-title">Cost of Production History</h6>
                        <a href="<?php echo e(route('manufacturing.cost-of-production.index')); ?>" class="btn btn-primary">
                            <i class="fas fa-calculator me-2"></i>New Calculation
                        </a>
                    </div>

                    <!-- Filters -->
                    <div class="row mb-4">
                        <div class="col-md-12">
                            <form method="GET" action="<?php echo e(route('manufacturing.cost-of-production.history')); ?>">
                                <div class="row g-3">
                                    <div class="col-md-4">
                                        <label for="chart_of_account_id" class="form-label">Chart of Account</label>
                                        <select id="chart_of_account_id" name="chart_of_account_id" class="form-control select2">
                                            <option value="">All Accounts</option>
                                            <?php $__currentLoopData = $chartOfAccounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($account->id); ?>" <?php echo e(request('chart_of_account_id') == $account->id ? 'selected' : ''); ?>>
                                                    <?php echo e($account->name); ?> (<?php echo e($account->code); ?>)
                                                </option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>
                                    </div>

                                    <div class="col-md-3">
                                        <label for="year" class="form-label">Year</label>
                                        <select id="year" name="year" class="form-control select2">
                                            <option value="">All Years</option>
                                            <?php for($i = date('Y') - 2; $i <= date('Y'); $i++): ?>
                                                <option value="<?php echo e($i); ?>" <?php echo e(request('year') == $i ? 'selected' : ''); ?>>
                                                    <?php echo e($i); ?>

                                                </option>
                                            <?php endfor; ?>
                                        </select>
                                    </div>

                                    <div class="col-md-3">
                                        <label for="month" class="form-label">Month</label>
                                        <select id="month" name="month" class="form-control select2">
                                            <option value="">All Months</option>
                                            <?php for($i = 1; $i <= 12; $i++): ?>
                                                <option value="<?php echo e($i); ?>" <?php echo e(request('month') == $i ? 'selected' : ''); ?>>
                                                    <?php echo e(date('F', mktime(0, 0, 0, $i, 1))); ?>

                                                </option>
                                            <?php endfor; ?>
                                        </select>
                                    </div>

                                    <div class="col-md-2">
                                        <label class="form-label">&nbsp;</label>
                                        <div class="d-grid">
                                            <button type="submit" class="btn btn-outline-primary">
                                                <i class="fas fa-search me-1"></i>Filter
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>

                    <!-- Results Table -->
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                                <tr>
                                    <th>Period</th>
                                    <th>Chart of Account</th>
                                    <th>Cost of Production</th>
                                    <th>Total Runs</th>
                                    <th>Total Quantity</th>
                                    <th>Avg Cost/Unit</th>
                                    <th>Created</th>
                                    <th>Actions</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__empty_1 = true; $__currentLoopData = $costRecords; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $record): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <tr>
                                    <td>
                                        <strong><?php echo e($record->for_month->format('M Y')); ?></strong><br>
                                        <small class="text-muted"><?php echo e($record->for_month->format('F Y')); ?></small>
                                    </td>
                                    <td>
                                        <strong><?php echo e($record->chartOfAccount->name); ?></strong><br>
                                        <small class="text-muted"><?php echo e($record->chartOfAccount->code); ?></small>
                                    </td>
                                    <td>
                                        <strong class="text-success">₹<?php echo e(number_format($record->cost_of_production, 2)); ?></strong>
                                    </td>
                                    <td>
                                        <span class="badge bg-info"><?php echo e($record->calculation_data['total_runs'] ?? 0); ?></span>
                                    </td>
                                    <td><?php echo e(number_format($record->calculation_data['total_quantity'] ?? 0, 4)); ?></td>
                                    <td>₹<?php echo e(number_format($record->calculation_data['average_cost_per_unit'] ?? 0, 2)); ?></td>
                                    <td>
                                        <?php echo e($record->created_at->format('M d, Y')); ?><br>
                                        <small class="text-muted"><?php echo e($record->created_at->format('H:i')); ?></small>
                                    </td>
                                    <td>
                                        <button class="btn btn-sm btn-outline-info" onclick="viewDetails(<?php echo e($record->id); ?>)">
                                            <i class="fas fa-eye"></i>
                                        </button>
                                    </td>
                                </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <tr>
                                    <td colspan="8" class="text-center text-muted py-4">
                                        <i class="fas fa-inbox fa-2x mb-2"></i><br>
                                        No cost of production records found
                                    </td>
                                </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>
                    </div>

                    <!-- Pagination -->
                    <?php if($costRecords->hasPages()): ?>
                    <div class="d-flex justify-content-center mt-4">
                        <?php echo e($costRecords->appends(request()->query())->links()); ?>

                    </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Details Modal -->
<div class="modal fade" id="detailsModal" tabindex="-1" aria-labelledby="detailsModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="detailsModalLabel">Calculation Details</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body" id="detailsContent">
                <!-- Content will be loaded here -->
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('plugin-scripts'); ?>
<script src="<?php echo e(asset('theme/vendors/select2/select2.min.js')); ?>"></script>
<?php $__env->stopPush(); ?>

<?php $__env->startPush('custom-scripts'); ?>
<script>
document.addEventListener('DOMContentLoaded', function() {
    // Initialize Select2
    $('.select2').select2({
        theme: 'bootstrap-5',
        placeholder: 'Select an option',
        allowClear: true
    });
});

function viewDetails(recordId) {
    // This would typically make an AJAX call to get detailed data
    // For now, we'll show a placeholder
    document.getElementById('detailsContent').innerHTML = `
        <div class="text-center">
            <i class="fas fa-spinner fa-spin fa-2x mb-3"></i>
            <p>Loading details...</p>
        </div>
    `;

    // Show modal
    const modal = new bootstrap.Modal(document.getElementById('detailsModal'));
    modal.show();

    // In a real implementation, you would make an AJAX call here
    // to fetch the detailed calculation data for the record
}
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\habibcables-ERP\resources\views\manufacturing\cost-of-production\history.blade.php ENDPATH**/ ?>