

<?php $__env->startSection('title', 'صلاحية المنتجات '); ?>
<?php $__env->startSection('content-header', 'منتجات صلاحيتها شارفت الانتهاء'); ?>
<?php $__env->startSection('content-actions'); ?>


                <?php 

/*
$expire_date = "18-10-2023";

$expire = strtotime($expire_date. ' - 2 months');

$today = strtotime("today midnight + 3months");


if($expire > $today){
    echo "Active";
} else {
    echo "Expired";
}
*/
                ?>

                <?php
                $today = strtotime("today midnight + 3months");

                $today = date("Y-m-d",$today);



                $order_items = App\Models\OrderItem::where('expire_date','<',$today)
                ->where('type','purchase')
                ->where('expire_status','not_checked')
                ->OrderBy('expire_date','asc')
                ->get();

              //  dd($order_items);
                ?>


<?php $__env->stopSection(); ?>
<?php $__env->startSection('css'); ?>
<link rel="stylesheet" href="<?php echo e(asset('plugins/sweetalert2/sweetalert2.min.css')); ?>">
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>


<div class="card">
    <div class="card-body">
        <table class="table">
            <thead>

                                <?php if(Config::get('app.locale') == "ar"): ?>
                <tr>
                    <th>#</th>
                    <th>الاسم</th>
                    <th style="display: none;">الصورة</th>
                    <th style="display: none;">باركود</th>
                    <th>السعر</th>
                    <th>كمية الطلبية</th>
                    <th>فاتورة الشراء </th>

                    <!--
                    <th>الكمية المتبقية</th>
                    <th>الكمية المباعه</th>
                    <th>الربح</th> 
                    <th>الحالة</th> -->
                    <th>تاريخ  الشراء</th>
                    <th>تاريخ الانتهاء</th>
                    <th>Actions</th>
                </tr>

                                <?php else: ?>
                <tr>
                    <th>ID</th>
                    <th>Name</th>
                    <th style="display: none;">Image</th>
                    <th style="display: none;">Barcode</th>
                    <th>Price</th>
                    <th>Quantity</th>
                    <th>Sold</th>
                    <th>Profit</th>
                    <th>Status</th>
                    <th>Updated At</th>
                    <th>Actions</th>
                </tr>

                        <?php endif; ?>
            </thead>
            <tbody>

                <?php
                foreach($order_items as $r) {

                    $product = \App\Models\Product::where('id',$r->product_id)->first();
                
                
                ?>

                <tr>
                    <td><?php echo e($product->id); ?></td>
                    <td><?php echo e($product->name); ?></td>
                    <td style="display: none;"><img src="<?php echo e(url('storage')); ?>/<?php echo e($product->image); ?>" alt="" width="100"></td>
                    <td style="display: none;"><?php echo e($product->barcode); ?></td>
                    <td><?php echo e($product->price); ?></td>
                    <td><?php echo e($r->quantity); ?></td>
                    <td><a href="#" onclick="window.open('<?php echo url('admin/ticket/'); ?>/<?php echo $r->order_id; ?>','','width=400,height=500');"><?php echo e($r->order_id); ?></a></td>
                 


                    <td><?php echo e($r->created_at); ?></td>
                    <td><?php echo e($r->expire_date); ?></td>

                    <td style="display: none;">
                    <?php 
                        $total_sold = 0;
                    $items = \App\Models\OrderItem::where('product_id',$product->id)
                    ->where('type','sale')
                    ->get('quantity');
                      
                        
                        foreach($items as $r2) {
                            $total_sold = $total_sold + $r2->quantity;
                        }

                        echo $total_sold;



                    ?>

                    </td>


                    <td style="display: none;">
                        <?php echo e(($product->price - $product->buy_price) * $total_sold); ?></td>


                    <td>

                   
                        <a onclick="return confirm('هل أنت متأكد من اجراء  هذه العملية ؟');" 
                        href="<?php echo e(url('expire_checked')); ?>/<?php echo e($r->id); ?>">
                        <span class="right badge badge-success">
                            <i class="fa fa-check"></i> Checked</span>
                        </a>
                    </td>






                </tr>
                <?php } ?>
            </tbody>
        </table>
        <?php echo e($products->render()); ?>

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

<?php $__env->startSection('js'); ?>
<script src="<?php echo e(asset('plugins/sweetalert2/sweetalert2.min.js')); ?>"></script>
<script>
    $(document).ready(function () {
        $(document).on('click', '.btn-delete', function () {
            $this = $(this);
            const swalWithBootstrapButtons = Swal.mixin({
                customClass: {
                    confirmButton: 'btn btn-success',
                    cancelButton: 'btn btn-danger'
                },
                buttonsStyling: false
                })

                swalWithBootstrapButtons.fire({
                title: 'Are you sure?',
                text: "Do you really want to delete this product?",
                icon: 'warning',
                showCancelButton: true,
                confirmButtonText: 'Yes, delete it!',
                cancelButtonText: 'No',
                reverseButtons: true
                }).then((result) => {
                if (result.value) {
                    $.post($this.data('url'), {_method: 'DELETE', _token: '<?php echo e(csrf_token()); ?>'}, function (res) {
                        $this.closest('tr').fadeOut(500, function () {
                            $(this).remove();
                        })
                    })
                }
            })
        })
    })
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\php\pear\~\resources\views/products/expired.blade.php ENDPATH**/ ?>