<?php $__env->startSection('content'); ?>
 <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-lg-2">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <span class="label label-info pull-right"><?php echo e($total_sales_today); ?></span>
                        <h5>Today</h5>
                    </div>
                    <div class="ibox-content">
                        <h4 class="no-margins"><?php echo e($today); ?></h4>
                    </div>
                </div>
            </div>
            <div class="col-lg-2">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <span class="label label-info pull-right"><?php echo e($total_sales_yesterday); ?></span>
                        <h5>Yesterday</h5>
                    </div>
                    <div class="ibox-content">
                        <h4 class="no-margins"><?php echo e($yesterday); ?></h4>
                        
                    </div>
                </div>
            </div>

			
			 <div class="col-lg-2">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
					<span class="label label-info pull-right"><?php echo e($total_sales_last_week); ?></span>
                        <h5>Last 7 Days</h5>
                    </div>
                    <div class="ibox-content">
                        <h4 class="no-margins"><?php echo e($last_week); ?></h4>
                       
                    </div>
                </div>
            </div>

			
			 <div class="col-lg-2">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
					<span class="label label-info pull-right"><?php echo e($total_sales_last_month); ?></span>
                         <h5>Last 30 Days</h5>
                    </div>
                    <div class="ibox-content">
                        <h4 class="no-margins"><?php echo e($last_month); ?></h4>
                        <!--<div class="stat-percent font-bold text-info">20% <i class="fa fa-level-up"></i></div>
                        <small>New orders</small> -->
                    </div>
                </div>
            </div>
			
			<div class="col-lg-4">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <span class="label label-info pull-right"><?php echo e($total_sales); ?> </span>
                        <h5>Total Sales</h5>
                    </div>
                    <div class="ibox-content">
                        <h4 class="no-margins"><?php echo e($total_earning); ?></h4>                        
                    </div>
                </div>
            </div>
			
			
            
        </div>
		<?php if(!empty($sales_by_product)) { ?>
		 <div class="row">
                <div class="col-lg-8">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>Best Sales Items All Time</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            
                        </div>
                    </div>
                    <div class="ibox-content">
                            <div class="flot-chart">
                                <div class="flot-chart-content" id="flot-bar-chart"></div>
                            </div>
                    </div>
                </div>
            </div>
            <div class="col-lg-4">
                <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <h5>Top 5 Sales Items</h5>
                            <div class="ibox-tools">
                                <a class="collapse-link">
                                    <i class="fa fa-chevron-up"></i>
                                </a>
                               
                                
                            </div>
                        </div>
                        <div class="ibox-content">
                            <div class="flot-chart">
                                <div class="flot-chart-pie-content" id="flot-pie-chart"></div>
                            </div>
                        </div>
                    </div>
            </div>
            </div>
			
		<?php } ?>

        <div class="row">

        <div class="col-lg-12">
        <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5> Last 10 Sales </h5>
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
            </div>
        </div>
        <div class="ibox-content">
           
            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Cashier</th>
                            <th>Customer</th>
                            <th>Sales Date</th>
                            <th>Status</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php if(!empty($sales)): ?>
                        <?php $__empty_1 = true; $__currentLoopData = $sales; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $sale): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr>
                                <td><?php echo e($key + 1); ?></td>
                               <td><?php echo e($sale->cashier['name']); ?></td>
                               <td><?php echo e($sale->customer['name']); ?></td>
                                <td><?php echo e($sale->created_at->format('d F Y')); ?></td>
								<?php if($sale->status == 1): ?>  
								<td>
                                    <a href="javascript:void(0)" class="btn btn-primary btn-xs ">Completed</a>
                                </td>
									<?php else: ?>
								<td>
                                    <a href="javascript:void(0)" class="btn btn-danger btn-xs">Canceled</a>
                                </td>
									<?php endif; ?>
									
							
								
                                <td>
								  <a target="_blank" href="<?php echo e(url('sales/receipt/' . $sale->id)); ?>" class="btn btn-primary btn-xs pull-right">Show</a>
									
                                </td>
								
								
								
								
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                          <tr> 
						  <td colspan="5">
								  No Record Found
									
                                </td>
								</tr>
                        <?php endif; ?>
                    <?php endif; ?>
                    </tbody>
                </table>
            </div>

        </div>
        </div>
        </div>
		
		

        </div>


        </div>
		<?php if(!empty($sales_by_product)) { ?>
	<script src="<?php echo e(url('assets/js/plugins/flot/jquery.flot.js')); ?>"></script>
    <script src="<?php echo e(url('assets/js/plugins/flot/jquery.flot.tooltip.min.js')); ?>"></script>
    <script src="<?php echo e(url('assets/js/plugins/flot/jquery.flot.resize.js')); ?>"></script>
    <script src="<?php echo e(url('assets/js/plugins/flot/jquery.flot.pie.js')); ?>"></script>
    <script src="<?php echo e(url('assets/js/plugins/flot/jquery.flot.time.js')); ?>"></script>
		
		<script> 
		$(function() {
    var barOptions = {
        series: {
            bars: {
                show: true,
                barWidth: 0.4,
                fill: true,
                fillColor: {
                    colors: [{
                        opacity: 0.8
                    }, {
                        opacity: 0.8
                    }]
                }
            }
        },
        xaxis: {
            tickDecimals: 0
        },
        colors: ["#1ab394"],
        grid: {
            color: "#999999",
            hoverable: true,
            clickable: true,
            tickColor: "#D4D4D4",
            borderWidth:0
        },
        legend: {
            show: false
        },
        tooltip: true,
        tooltipOpts: {
            content: "x: %x, y: %y"
        }
    };
    var barData = {
        label: "bar",
        data: [
			<?php if(!empty($sales_by_product)) { foreach($sales_by_product as $sale) { ?>
            ["<?php echo $sale->product_id; ?>", <?php echo $sale->total_sales; ?>],
			<?php } } ?>
        ]
    };
    $.plot($("#flot-bar-chart"), [barData], barOptions);

});


//Flot Pie Chart
$(function() {
var myArray = ['#617EBB', '#48C2A9' , '#2c2ccc' , '#2ccc47','#48C2A9','#e5dd42'];   
    var data = [
	<?php if(!empty($sales_by_product)) { foreach($sales_by_product as $sale) { ?>
            
			{
        label: "<?php echo $sale->product_name; ?>",
        data: <?php echo $sale->total_sales; ?>,
        color: myArray[Math.floor(Math.random() * myArray.length)],
    },<?php } } ?> ];

    var plotObj = $.plot($("#flot-pie-chart"), data, {
        series: {
            pie: {
                show: true
            }
        },
        grid: {
            hoverable: true
        },
        tooltip: true,
        tooltipOpts: {
            content: "%p.0%, %s", // show percentages, rounding to 2 decimal places
            shifts: {
                x: 20,
                y: 0
            },
            defaultTheme: false
        }
    });

});

</script>
		<?php } ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>