<?php $__env->startSection('section-title', 'Report'); ?>
<?php $__env->startSection('page-title', 'Purchase 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.purchase')); ?>">
                  <div class="form-row">
                    <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.purchase')); ?>" 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">Purchase 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($purchaseItem)): ?>
                        <table class="table">
                        <thead>
                            <tr class="header_bg">
                                <th class="header_style_left">SL.</th>
                                <th>Date</th>
                                <th>Purchase No</th>
                                <th>Product</th>
                                <th>Quantity</th>
                                <th>Unit Price</th>
                                <th class="header_style_right">Sub Total</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                                $sub_total = 0;
                            ?>
                            <?php $__empty_1 = true; $__currentLoopData = $purchaseItem; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <?php
                                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->subtotal;
                                // 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->purchase->date))); ?></td>
                                <td><?php echo e($data->purchase->purchase_no); ?></td>
                                <td><?php echo e($data->product->name); ?></td>
                                <td><?php echo e($qty); ?></td>
                                <td><?php echo e(number_format($data->rate, 2)); ?> TK</td>
                                <td class="table_data_style_right"><?php echo e(number_format($data->subtotal, 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="5"></td>
                                <td> <strong class="text-white"> Total Price: </strong></td>
                                <td class="header_style_right" 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 D:\laragon\www\new demo\resources\views/backend/pages/report/purchase.blade.php ENDPATH**/ ?>