
<?php $__env->startSection('content'); ?>
    <?php
    Fun::lang();
    $arr_size = [];
    $arr_code = [];

    $from_date = @$_GET['from_date'];
    $from_date = $from_date ? date('Y-m-d', strtotime($from_date)) : date('Y-m-d');
    $to_date = @$_GET['to_date'];
    $to_date = $to_date ? date('Y-m-d', strtotime($to_date)) : date('Y-m-d');

    $sale_size = DB::table('nso007_sale_details')
        ->join('nso007_sales', 'nso007_sales.id', 'nso007_sale_details.sale_id')
        ->where(function ($query) use ($from_date, $to_date) {
            if ($from_date && $to_date) {
                $query->whereBetween('nso007_sales.sale_date', [$from_date . ' 00:00:00', $to_date . ' 23:59:59']);
            }
        })
        ->where('nso007_sales.sale_type', 'product')
        ->groupBy('nso007_sale_details.size_id')
        ->pluck('nso007_sale_details.size_id');
    $sale_size = DB::table('nso007_product_size')->whereIn('id', $sale_size)->pluck('size', 'id');

    $sale_code = DB::table('nso007_sale_details')
        ->join('nso007_sales', 'nso007_sales.id', 'nso007_sale_details.sale_id')
        ->where(function ($query) use ($from_date, $to_date) {
            if ($from_date && $to_date) {
                $query->whereBetween('nso007_sales.sale_date', [$from_date . ' 00:00:00', $to_date . ' 23:59:59']);
            }
        })
        ->where('nso007_sales.sale_type', 'product')
        ->groupBy('nso007_sale_details.barcode')
        ->pluck('nso007_sale_details.barcode');

    $tran_code = DB::table('nso007_transfer_stock_detail')
        ->join('nso007_transfer_stock', 'nso007_transfer_stock.id', 'nso007_transfer_stock_detail.transfer_id')
        ->where(function ($query) use ($from_date, $to_date) {
            if ($from_date && $to_date) {
                $query->whereBetween('nso007_transfer_stock.date', [$from_date, $to_date]);
            }
        })
        ->where('nso007_transfer_stock.type', 'item')
        ->groupBy('nso007_transfer_stock_detail.barcode')
        ->pluck('nso007_transfer_stock_detail.barcode');
    $tran_size = DB::table('nso007_transfer_stock_detail')
        ->join('nso007_transfer_stock', 'nso007_transfer_stock.id', 'nso007_transfer_stock_detail.transfer_id')
        ->where(function ($query) use ($from_date, $to_date) {
            if ($from_date && $to_date) {
                $query->whereBetween('nso007_transfer_stock.date', [$from_date, $to_date]);
            }
        })
        ->where('nso007_transfer_stock.type', 'item')
        ->orderBy('nso007_transfer_stock.created_at', 'DESC')
        ->groupBy('nso007_transfer_stock_detail.size_id')
        ->pluck('nso007_transfer_stock_detail.size_id');
    $tran_size = DB::table('nso007_product_size')->whereIn('id', $tran_size)->pluck('size', 'id');

    foreach ($sale_size as $key => $row) {
        $arr_size[$key] = $row;
    }
    foreach ($tran_size as $key => $row) {
        $arr_size[$key] = $row;
    }

    foreach ($sale_code as $key => $row) {
        $arr_code[$key] = $row;
    }
    foreach ($tran_code as $key => $row) {
        $arr_code[$key] = $row;
    }

    $arr_total_item = [];
    ?>
    <style>
        #print_table_report tfoot th{
            border: 1px solid #ddd;
        }
        @media  print {
            #print_table_report tfoot th{
                border: 1px solid #ddd;
            }
        }
    </style>
    <div class="page">
        <div class=container-fluid>
            <div class="top-content">
                <div class="row">
                    <div class="col-sm-12 col-xs-12 form-group">
                        <div class="title-add">
                            <div class="pull-left">
                                <h3><?php echo e(__('administrator.stock_out_item_daily_report')); ?></h3>
                            </div>
                            <div class="pull-right">
                                <?php echo $__env->make('administrator.report-stock.sub-menu', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="top-content">
                <div class="row">
                    <div class="col-sm-12 col-xs-12 form-group padding-0">
                        <div>
                            <?php echo Form::open(['method'=>'get']); ?>

                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3">
                                    <?php echo e(__('administrator.from_date')); ?>

                                </div>
                                <div class="form-group col-sm-9 col-md-9">
                                    <?php echo Form::text('from_date', @$_GET['from_date'], array('class' => 'form-control date_picker', 'placeholder' =>  __('administrator.from_date'))); ?>

                                </div>
                            </div>
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3">
                                    <?php echo e(__('administrator.to_date')); ?>

                                </div>
                                <div class="form-group col-sm-9 col-md-9">
                                    <?php echo Form::text('to_date', @$_GET['to_date'], array('class' => 'form-control date_picker', 'placeholder' =>  __('administrator.to_date'))); ?>

                                </div>
                            </div>
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3">
                                    <button class="button_info"><?php echo e(__('administrator.search')); ?></button>
                                </div>
                            </div>
                            <?php echo Form::close(); ?>


                            <div class="col-sm-offset-6 col-sm-6">
                                <button class=" button_success pull-right print_button" type="button"
                                        data-text="<?php echo e(__('administrator.stock_out_item_by_branch_report')); ?>"><i
                                            class="fa fa-print"></i> <?php echo e(__('administrator.print')); ?></button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="wrapper-table">
                <table id="print_table_report" class="table table-striped table-hover" width="100%">
                    <thead>
                    <tr>
                        <th rowspan="2">#</th>
                        <th rowspan="2"><?php echo e(__('administrator.barcode')); ?></th>
                        <th rowspan="2"><?php echo e(__('administrator.item_name')); ?></th>
                        <th colspan="<?php echo e(count($arr_size)); ?>"><?php echo e(__('administrator.size')); ?></th>
                    </tr>
                    <tr>
                        <?php $__currentLoopData = $arr_size; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <th><?php echo e($row); ?></th>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tr>
                    </thead>
                    <tbody class="tbody">
                    <?php $__currentLoopData = $arr_code; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key_code=>$row_code): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php
                            $product = findProductUnitByCode($row_code,'product');
                            if($product){
                            $product = getProductById($product->product_id);
                            }
                        ?>
                        <tr>
                            <td><?php echo e($key_code+1); ?></td>
                            <td><?php echo e($row_code); ?></td>
                            <td><?php echo e($product?$product->product_name:''); ?></td>
                            <?php $__currentLoopData = $arr_size; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key_size=>$row_size): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php
                                    $sale_size_qty = DB::table('nso007_sales')->where('sale_type', 'product')
                                     ->where(function ($query) use ($from_date, $to_date) {
                                            if($from_date&&$to_date){
                                                $query->whereBetween('nso007_sales.sale_date', [$from_date.' 00:00:00',$to_date.' 23:59:59'] );
                                            }
                                    })
                                    ->pluck('id');
                                    $sale_size_qty = DB::table('nso007_sale_details')
                                    ->selectRaw('SUM(qty) as in_qty')
                                    ->where('barcode',$row_code)
                                    ->where('size_id',$key_size)
                                    ->whereIn('sale_id',$sale_size_qty)->first();

                                    $tran_size_qty = DB::table('nso007_transfer_stock')
                                    ->where('type', 'item')
                                     ->where(function ($query) use ($from_date, $to_date) {
                                            if($from_date&&$to_date){
                                                $query->whereBetween('nso007_transfer_stock.date', [$from_date,$to_date] );
                                            }
                                    })
                                    ->pluck('id');

                                    $tran_size_qty = DB::table('nso007_transfer_stock_detail')
                                    ->selectRaw('SUM(qty) as in_qty')
                                    ->where('barcode',$row_code)
                                   ->where('size_id',$key_size)
                                    ->whereIn('transfer_id',$tran_size_qty)->first();
                                    $arr_total_item[$key_size] = (@$arr_total_item[$key_size]?$arr_total_item[$key_size]:0)+$sale_size_qty->in_qty+$tran_size_qty->in_qty;
                                ?>
                                <td class="data_warehouse" data-id="<?php echo e($key_size); ?>"
                                    data-qty="<?php echo e($sale_size_qty->in_qty+$tran_size_qty->in_qty); ?>"><?php echo e($sale_size_qty->in_qty+$tran_size_qty->in_qty); ?></td>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                    <tfoot>
                    <tr>
                        <th colspan="3" class="text-right"><?php echo e(__('administrator.total')); ?></th>
                        <?php $__currentLoopData = $arr_size; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <th class="total_item<?php echo e($key); ?>"><?php echo e($arr_total_item[$key]); ?></th>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
    <script type="text/javascript">
        function getTable(warehouse = '') {
            $('#print_table_report').DataTable({
                "oLanguage": {
                    "sSearch": "<?php echo e(__('administrator.search')); ?>:",
                    "sLengthMenu": "<?php echo e(__('administrator.display')); ?> _MENU_ <?php echo e(__('administrator.record_per_page')); ?>",
                    "sZeroRecords": "<?php echo e(__('administrator.Nothing_foundsorry')); ?>",
                    "sInfo": "<?php echo e(__('administrator.showing')); ?> _START_ <?php echo e(__('administrator.to')); ?> _END_ <?php echo e(__('administrator.of')); ?> _TOTAL_ <?php echo e(__('administrator.record')); ?>",
                    "sInfoEmpty": "<?php echo e(__('administrator.showing')); ?> 0 <?php echo e(__('administrator.to')); ?> 0 <?php echo e(__('administrator.of')); ?> 0 <?php echo e(__('administrator.record')); ?>",
                    "sInfoFiltered": "(<?php echo e(__('administrator.filter_form')); ?> _MAX_ <?php echo e(__('administrator.total_records')); ?>)",
                    "oPaginate": {
                        "sFirst": "<?php echo e(__('administrator.first')); ?>",
                        "sLast": "<?php echo e(__('administrator.last')); ?>",
                        "sNext": "<?php echo e(__('administrator.next')); ?>",
                        "sPrevious": "<?php echo e(__('administrator.previous')); ?>"
                    },
                },
                ordering: true,
                lengthMenu: [[20, 30, 50, 100, 200, 500, 1000], [20, 30, 50, 100, 200, 500, 1000]],
                "fnDrawCallback": function () {
                    let table = $('#print_table_report tr');
                    let total_item = [];
                    $.each(table, function (ii, vv) {
                        $.each($(this).find('.data_warehouse'), function (jj, uu) {
                            total_item[$(this).data('id')] = (total_item[$(this).data('id')] ? total_item[$(this).data('id')] : 0) + parseFloat($(this).data('qty'));
                        });
                    });
                    <?php $__currentLoopData = $arr_size; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    $('tfoot tr ').find('.total_item<?php echo e($key); ?>').html(total_item['<?php echo e($key); ?>']);
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                }
            });
        }
        $(document).ready(function () {
            getTable();
        });
    </script>
<?php $__env->stopSection(); ?>




<?php echo $__env->make(branchMenu(), \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/nsowos/public_html/shr-brand/resources/views/administrator/report-stock/new-stock-report/stock-out-daily.blade.php ENDPATH**/ ?>