
<?php $__env->startSection('content'); ?>
<style>
    .summary-card {
        border-left: 4px solid;
        border-radius: 0;
        transition: all 0.3s ease;
    }
    .summary-card:hover {
        transform: translateY(-5px);
        box-shadow: 0 10px 20px rgba(0,0,0,0.1);
    }
    .summary-card.revenue {
        border-left-color: #28a745;
    }
    .summary-card.expense {
        border-left-color: #dc3545;
    }
    .summary-card.profit {
        border-left-color: #17a2b8;
    }
    .summary-card.balance {
        border-left-color: #6f42c1;
    }
    .chart-container {
        height: 300px;
        position: relative;
    }
    .transaction-table th {
        background-color: #f8f9fa;
    }
    .nav-tabs .nav-link {
        padding: 12px 20px;
        font-weight: 500;
    }
    .progress {
        height: 10px;
    }
</style>

<!-- begin::main content -->
<main class="main-content">
    <div class="container">
        <!-- begin::page header -->
        <div class="page-header">
            <h3>Financial Dashboard</h3>
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="<?php echo e(asset('dashboard')); ?>">Dashboard</a></li>
                    <li class="breadcrumb-item active" aria-current="page">Financial Overview</li>
                </ol>
            </nav>
        </div>
        <!-- end::page header -->

        <div class="row mb-4">
            <div class="col-md-12">
                <button type="button" class="btn border input-group-text filter-company-btn px-4">
                    <i class="ti ti-filter fa-lg"> </i>
                    <?php if(isset($selected_period)): ?>
                        <span class="ml-2">
                            <?php if($selected_period == 'financial_year'): ?>
                                FY <?php echo e($currentFinancialYear); ?>

                            <?php elseif($selected_period == 'this_month'): ?>
                                This Month (<?php echo e(date('M Y', strtotime($start_date))); ?>)
                            <?php elseif($selected_period == 'last_month'): ?>
                                Last Month (<?php echo e(date('M Y', strtotime($start_date))); ?>)
                            <?php elseif($selected_period == 'six_month'): ?>
                                Last 6 Months
                            <?php else: ?>
                                Custom Range
                            <?php endif; ?>
                        </span>
                    <?php endif; ?>
                </button>
                
                <div class="filter-form-box d-none">
                    <div class="diamond"></div>
                    <form method="get" action="<?php echo e(asset('dashboard')); ?>">
                        <div class="form-group">
                            <label>Time Period</label>
                            <select class="form-control" name="time_period">
                                <option value="">Select</option>
                                <option value="this_month" <?php echo e($selected_period == 'this_month' ? 'selected' : ''); ?>>This Month</option>
                                <option value="last_month" <?php echo e($selected_period == 'last_month' ? 'selected' : ''); ?>>Last Month</option>
                                <option value="six_month" <?php echo e($selected_period == 'six_month' ? 'selected' : ''); ?>>Last 6 Months</option>
                                <option value="financial_year" <?php echo e($selected_period == 'financial_year' ? 'selected' : ''); ?>>Financial Year</option>
                            </select>
                        </div>
                        
                        <div class="form-group px-1">
                            <label>Start Date</label>
                            <input type="date" name="start_date" class="form-control" value="<?php echo e(request('start_date')); ?>">
                        </div> 

                        <div class="form-group px-1">
                            <label>End Date</label>
                            <input type="date" name="end_date" class="form-control" value="<?php echo e(request('end_date')); ?>">
                        </div>
                                
                        <div class="row">
                            <div class="form-group col-12 d-flex justify-content-end">
                                <button type="submit" class="btn btn-success mr-5 px-4 apply-button">Apply</button>
                                <a href="<?php echo e(asset('dashboard')); ?>" class="btn btn-primary px-3 text-white">Clear</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>                             
        </div>



        <!-- Summary Cards -->
        <div class="row mb-4">
            <div class="col-md-3">
                <div class="card summary-card revenue">
                    <div class="card-body">
                        <div class="d-flex justify-content-between align-items-center">
                            <div>
                                <h6 class="card-title text-uppercase text-muted">Total Revenue</h6>
                                <h3 class="mb-0">₹<?php echo e(number_format($financialSummary['total_revenue'], 2)); ?></h3>
                            </div>
                            <div class="icon-circle bg-success text-white">
                                <i class="fas fa-rupee-sign"></i>
                            </div>
                        </div>
                        <p class="mt-3 mb-0 text-muted">
                            <span class="text-success mr-2"><?php echo e($financialSummary['revenue_growth']); ?>%</span>
                            <span class="text-nowrap">Since last year</span>
                        </p>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card summary-card expense">
                    <div class="card-body">
                        <div class="d-flex justify-content-between align-items-center">
                            <div>
                                <h6 class="card-title text-uppercase text-muted">Total Expenses</h6>
                                <h3 class="mb-0">₹<?php echo e(number_format($financialSummary['total_expenses'], 2)); ?></h3>
                            </div>
                            <div class="icon-circle bg-danger text-white">
                                <i class="fas fa-money-bill-wave"></i>
                            </div>
                        </div>
                        <p class="mt-3 mb-0 text-muted">
                            <span class="text-danger mr-2"><?php echo e($financialSummary['expense_growth']); ?>%</span>
                            <span class="text-nowrap">Since last year</span>
                        </p>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card summary-card profit">
                    <div class="card-body">
                        <div class="d-flex justify-content-between align-items-center">
                            <div>
                                <h6 class="card-title text-uppercase text-muted">Net Profit</h6>
                                <h3 class="mb-0">₹<?php echo e(number_format($financialSummary['net_profit'], 2)); ?></h3>
                            </div>
                            <div class="icon-circle bg-info text-white">
                                <i class="fas fa-chart-line"></i>
                            </div>
                        </div>
                        <p class="mt-3 mb-0 text-muted">
                            <span class="<?php echo e($financialSummary['profit_growth'] >= 0 ? 'text-success' : 'text-danger'); ?> mr-2"><?php echo e($financialSummary['profit_growth']); ?>%</span>
                            <span class="text-nowrap">Since last year</span>
                        </p>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card summary-card balance">
                    <div class="card-body">
                        <div class="d-flex justify-content-between align-items-center">
                            <div>
                                <h6 class="card-title text-uppercase text-muted">Cash Balance</h6>
                                <h3 class="mb-0">₹<?php echo e($financialSummary['cash_balance']); ?></h3>
                            </div>
                            <div class="icon-circle bg-primary text-white">
                                <i class="fas fa-wallet"></i>
                            </div>
                        </div>
                        <p class="mt-3 mb-0 text-muted">
                            <span class="<?php echo e($financialSummary['balance_growth'] >= 0 ? 'text-success' : 'text-danger'); ?> mr-2"><?php echo e($financialSummary['balance_growth']); ?>%</span>
                            <span class="text-nowrap">Since last year</span>
                        </p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Charts Row -->
        <div class="row mb-4">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">
                        
                        <h5>Revenue vs Expenses (<?php echo e($currentYear); ?>)</h5>
                    </div>
                    <div class="card-body">
                        <div class="chart-container">
                            <canvas id="revenueExpenseChart"></canvas>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="card">
                    <div class="card-header">
                        <h5>Profit & Loss Breakdown</h5>
                    </div>
                    <div class="card-body">
                        <div class="chart-container">
                            <canvas id="profitLossChart"></canvas>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Financial Statements -->
        <div class="row mb-4">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header">
                        <ul class="nav nav-tabs card-header-tabs">
                            <li class="nav-item">
                                <a class="nav-link active" id="balance-sheet-tab" data-toggle="tab" href="#balance-sheet">Balance Sheet</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" id="tax-summary-tab" data-toggle="tab" href="#tax-summary">Tax Summary</a>
                            </li>
                        </ul>
                    </div>
                    <div class="card-body">
                        <div class="tab-content">
                            <!-- Balance Sheet -->
                            <div class="tab-pane fade show active" id="balance-sheet">
                                <div class="row">
                                    <div class="col-md-6">
                                        <h5>Assets</h5>
                                        <table class="table table-sm">
                                            <thead>
                                                <tr>
                                                    <th>Account</th>
                                                    <th class="text-right">Balance</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php $__currentLoopData = $balanceSheet['assets']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $asset): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <tr>
                                                    <td><?php echo e($asset['name']); ?></td>
                                                    <td class="text-right">₹<?php echo e(number_format($asset['balance'], 2)); ?></td>
                                                </tr>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                <tr class="table-active">
                                                    <td><strong>Total Assets</strong></td>
                                                    <td class="text-right"><strong>₹<?php echo e(number_format($balanceSheet['total_assets'], 2)); ?></strong></td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="col-md-6">
                                        <h5>Liabilities & Equity</h5>
                                        <table class="table table-sm">
                                            <thead>
                                                <tr>
                                                    <th>Account</th>
                                                    <th class="text-right">Balance</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php $__currentLoopData = $balanceSheet['liabilities']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $liability): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <tr>
                                                    <td><?php echo e($liability['name']); ?></td>
                                                    <td class="text-right">₹<?php echo e(number_format($liability['balance'], 2)); ?></td>
                                                </tr>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                <tr>
                                                    <td>Retained Earnings</td>
                                                    <td class="text-right">₹<?php echo e(number_format($balanceSheet['retained_earnings'], 2)); ?></td>
                                                </tr>
                                                <tr class="table-active">
                                                    <td><strong>Total Liabilities & Equity</strong></td>
                                                    <td class="text-right"><strong>₹<?php echo e(number_format($balanceSheet['total_liabilities_equity'], 2)); ?></strong></td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>


                            <!-- Tax Summary -->
                            <div class="tab-pane fade" id="tax-summary">
                                <div class="row">
                                    <?php if(isset($taxSummary)): ?>
                                    <?php $__currentLoopData = $taxSummary; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tax): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <div class="col-md-6 mb-4">
                                        <div class="card">
                                            <div class="card-header">
                                                <h5><?php echo e($tax['name']); ?></h5>
                                            </div>
                                            <div class="card-body">
                                                <div class="d-flex justify-content-between mb-3">
                                                    <span>Collected</span>
                                                    <strong>₹<?php echo e(number_format($tax['total'], 2)); ?></strong>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Transactions Overview -->
        <div class="row">
            <div class="col-md-6">
                <div class="card">
                    <div class="card-header">
                        <h5>Recent Sales</h5>
                    </div>
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="table table-sm">
                                <thead>
                                    <tr>
                                        <th>Date</th>
                                        <th>Invoice</th>
                                        <th>Customer</th>
                                        <th class="text-right">Amount</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php if(isset($recentSales)): ?>
                                        <?php $__currentLoopData = $recentSales; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $sales): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <tr>
                                                <td><?php echo e($sales->invoice_date); ?></td>
                                                <td><?php echo e($sales->invoice_number); ?></td>
                                                <td><?php echo e($sales->customer_name); ?></td>
                                                <td>₹<?php echo e($sales->grand_total); ?></td>
                                            </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    <?php endif; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="card">
                    <div class="card-header">
                        <h5>Recent Purchases</h5>
                    </div>
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="table table-sm">
                                <thead>
                                    <tr>
                                        <th>Date</th>
                                        <th>Bill</th>
                                        <th>Vendor</th>
                                        <th class="text-right">Amount</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php if(isset($recentPurchases)): ?>
                                        <?php $__currentLoopData = $recentPurchases; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $sales): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <tr>
                                                <td><?php echo e($sales->bill_date); ?></td>
                                                <td><?php echo e($sales->bill_number); ?></td>
                                                <td><?php echo e($sales->customer_name); ?></td>
                                                <td>₹<?php echo e($sales->grand_total); ?></td>
                                            </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    <?php endif; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>
<!-- end::main content -->
<?php $__env->stopSection(); ?>

<?php $__env->startPush('footer-script'); ?>
<!-- Chart.js -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
    $(document).ready(function() {
        // Revenue vs Expense Chart
        const revenueExpenseCtx = document.getElementById('revenueExpenseChart').getContext('2d');
        const revenueExpenseChart = new Chart(revenueExpenseCtx, {
            type: 'bar',
            data: {
                labels: <?php echo json_encode($monthLabels, 15, 512) ?>,
                datasets: [
                    {
                        label: 'Revenue',
                        data: <?php echo json_encode(array_values($monthlyRevenue), 15, 512) ?>,
                        backgroundColor: 'rgba(40, 167, 69, 0.7)',
                        borderColor: 'rgba(40, 167, 69, 1)',
                        borderWidth: 1
                    },
                    {
                        label: 'Expenses',
                        data: <?php echo json_encode(array_values($monthlyExpenses), 15, 512) ?>,
                        backgroundColor: 'rgba(220, 53, 69, 0.7)',
                        borderColor: 'rgba(220, 53, 69, 1)',
                        borderWidth: 1
                    }
                ]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                scales: {
                    y: {
                        beginAtZero: true
                    }
                }
            }
        });

        // Profit & Loss Chart
        const profitLossCtx = document.getElementById('profitLossChart').getContext('2d');
        const profitLossChart = new Chart(profitLossCtx, {
            type: 'doughnut',
            data: {
                labels: ['Revenue', 'Expenses', 'Tax', 'Profit'],
                datasets: [{
                    data: <?php echo json_encode($pochart, 15, 512) ?>,
                    backgroundColor: [
                        'rgba(250, 173, 7, 0.7)',
                        'rgba(8, 100, 238, 0.7)',
                        'rgba(243, 97, 12, 0.7)',
                        'rgba(8, 133, 243, 0.7)',
                        'rgba(6, 240, 131, 0.7)'
                    ],
                    borderColor: [
                        'rgba(250, 173, 7, 0.7)',
                        'rgba(8, 100, 238, 0.7)',
                        'rgba(243, 97, 12, 0.7)',
                        'rgba(8, 133, 243, 0.7)',
                        'rgba(6, 240, 131, 0.7)'
                    ],
                    borderWidth: 1
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                plugins: {
                    legend: {
                        position: 'bottom',
                    }
                }
            }
        });

        $(".filter-company-btn").click(function(){
            
            if($(".filter-form-box").hasClass("d-none"))
            {
                $(".filter-form-box").removeClass("d-none");
            }
            else
            {
                $(".filter-form-box").addClass("d-none");
            }
        });
        
    });
</script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('layout', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /var/www/peoplebee.in/account/resources/views/dashboard/dashboard.blade.php ENDPATH**/ ?>