<?php $__env->startSection('section-title', 'Report'); ?>
<?php $__env->startSection('page-title', 'Sale Report'); ?>

<?php $__env->startPush('css'); ?>
<style>
    @media print{
        table,table th,table td {
            color:black !important;
        }

        #h-hide {
            display: none;
        }
    }
</style>
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
    <div class="row">
        <div class="col-lg-12">
            <div class="card card-body card_style mb-2" style="margin-top: -5px;" id="h-hide">
                <form action="<?php echo e(route('report.sale')); ?>">
                    <div class="form-row">
                        <div class="form-group col-md-4">
                            <select class="select2" name="category_id">
                                <option selected value="">Select Category</option>
                                <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($category->id); ?>"><?php echo e($category->name); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                        <div class="form-group col-md-4">
                            <select class="select2" name="product_id">
                                <option selected value="">Select Product</option>
                                <?php $__currentLoopData = $products; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $product): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($product->id); ?>" <?php if(isset($oneProduct)): ?> <?php if($product->id == $oneProduct->id): ?> selected <?php endif; ?> <?php endif; ?>><?php echo e($product->name); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                        <div class="form-group col-md-4">
                            <input type="date" name="start_date" class="form-control" value="<?php echo e((isset($sdate))?date('Y-m-d', strtotime($sdate)):''); ?>">
                        </div>
                        <div class="form-group col-md-4">
                            <input type="date" name="end_date" class="form-control" value="<?php echo e((isset($edate))?date('Y-m-d', strtotime($edate)):''); ?>">
                        </div>
                    </div>
                    <div class="form-row mt-2">
                        <div class="form-group col-12">
                            <button class="btn add_list_btn" type="submit">
                                    <i class="fa fa-sliders"></i> Filter
                            </button>
                            <a href="<?php echo e(route('report.sale')); ?>" class="btn add_list_btn_reset">Reset</a>
                            <a href="" class="btn add_list_btn float-right" onclick="window.print()">Print</a>
                        </div>
                    </div>
                </form>
            </div>
            <div class="card m-b-30 print_area card_style">
                <div class="card-header">
                    <h4 style="text-align: center; font-weight:bold; margin-top:25px;font-size:30px">Sale Report (<?php echo e((isset($sdate))?date('m-d-Y', strtotime($sdate)):''); ?> - <?php echo e((isset($edate))?date('m-d-Y', strtotime($edate)):''); ?>)</h4>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <?php if(isset($invoiceItem)): ?>
                        <table class="table">
                        <thead>
                            <tr class="header_bg">
                                <th class="header_style_left">SL.</th>
                                <th>Date</th>
                                <th>Invoice No</th>
                                <th>Product</th>
                                <th>Product Category</th>
                                <th>Quantity</th>
                                <th>Unit Price</th>
                                <th>Sub Total</th>
                                <th>Discount</th>
                                <th class="header_style_right">Total</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                                $sub_total = 0;
                            ?>
                            <?php $__empty_1 = true; $__currentLoopData = $invoiceItem; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <?php
                                $items = App\Models\InvoiceItem::where('invoice_id',$data->id)->get();
                                // if ($data->product->unit->related_unit  == null) {
                                //     $main_qty = $data->main_qty;
                                //     $qty = $main_qty.' '.$data->product->unit->name;
                                // } else {
                                //     //purchase
                                //     $main_qty = $data->main_qty;
                                //     $pur_total_main = (float)($main_qty*$data->product->unit->related_value);
                                //     $sub_qty = $data->sub_qty;
                                //     $pur_total_qty = (float)($pur_total_main+$sub_qty);
                                //     $total_qty = $pur_total_qty;
                                //     $check = $total_qty/$data->product->unit->related_value;
                                //     if (is_integer($check)) {
                                //         $data['stock_qty'] = $check.' '.$data->product->unit->name.' 0 '.$data->product->unit->related_unit->name;
                                //     } else {
                                //         $main_value = floor($check)*$data->product->unit->related_value;
                                //         $sub_value = $total_qty-$main_value;
                                //         $qty = floor($check).' '.$data->product->unit->name.' '.$sub_value.' '.$data->product->unit->related_unit->name;
                                //     }
                                // }
                                $sub_total += $data->total_amount;
                                // dd($sub_total)
                            ?>
                            <tr>
                                <td class="table_data_style_left"><?php echo e($key+1); ?></td>
                                <td><?php echo e(date('m-d-Y', strtotime($data->date))); ?></td>
                                <td><?php echo e($data->invoice_no); ?></td>
                                <td>
                                    <?php $__currentLoopData = $items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <ul>
                                            <li><?php echo e($item->product?->name); ?></li>
                                        </ul>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </td>
                                <td>
                                    <?php $__currentLoopData = $items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <ul>
                                            <li><?php echo e($item->product?->category?->name); ?></li>
                                        </ul>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </td>
                                <td>
                                    <?php $__currentLoopData = $items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <?php if($item->product->unit?->related_unit == null): ?>
                                        <ul>
                                            <li><?php echo e($item->main_qty.' '.$item->product->unit?->name); ?></li>
                                        </ul>
                                        <?php else: ?>
                                        <ul>
                                            <li><?php echo e($item->main_qty.' '.$item->product->unit->name .' '. $item->sub_qty.' '.$item->product->unit->related_unit->name); ?></li>
                                        </ul>
                                        <?php endif; ?>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </td>
                                <td>
                                    <?php $__currentLoopData = $items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <ul>
                                            <li><?php echo e($item->rate); ?></li>
                                        </ul>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </td>
                                <td><?php echo e(number_format($data->estimated_amount, 2)); ?> TK</td>
                                <td><?php echo e(number_format($data->discount_amount, 2)); ?> TK</td>
                                <td class="table_data_style_right"><?php echo e(number_format($data->total_amount, 2)); ?> TK</td>
                            </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <tr>
                                    <td colspan="10" class="text-center text-danger no_data_style">No Data Found</td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                        <tfooter>
                            <tr class="header_bg" style="font-size: 20px; font-width: 700; font-family:sans-serif">
                                <td class="header_style_left" colspan="6"></td>
                                <td colspan="2"> <strong class="text-white"> Total Price: </strong></td>
                                <td class="header_style_right text-white" colspan="2"><strong> <?php echo e(number_format($sub_total,2)); ?> TK </strong></td>
                            </tr>
                        </tfooter>
                        </table>
                        <?php else: ?>
                        <div class="col-md-12" style="padding-bottom: 30px;">
                            <div class="alert alert-danger text-center" role="alert"> Please Select Start and End Month</div>
                        </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('backend.layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/fastitco/organic-station.fastit.com.bd/resources/views/backend/pages/report/sale.blade.php ENDPATH**/ ?>