<?php $__env->startSection('content'); ?>
    <?php Fun::lang()?>

    <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_in')); ?></h3>
                            </div>
                            <div class="pull-right">
                                <?php echo $__env->make('administrator.reportpurchases.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 class="col-sm-3 col-md-3">
                            <div class="col-sm-3 col-md-3" style="margin-top: 5px">
                                <?php echo e(__('administrator.supplier')); ?>

                            </div>
                            <div class="form-group col-sm-9 col-md-9">
                                <?php echo Form::select('supplier_id',$supplier , null,array('class' => 'form-control select2 supplier', 'placeholder' =>__('administrator.please_select'))); ?>

                            </div>
                        </div>
                        <div class="col-sm-3 col-md-3">
                            <div class="col-sm-3 col-md-3" style="margin-top: 5px">
                                <?php echo e(__('administrator.type')); ?>

                            </div>
                            <div class="form-group col-sm-9 col-md-9">
                                <?php echo Form::select('type',$type,null, array('class' => 'form-control select2', 'placeholder' =>__('administrator.please_select'))); ?>

                            </div>
                        </div>
                        <div class="col-sm-3 col-md-3">
                            <div class="col-sm-3 col-md-3" style="margin-top: 5px">
                                <?php echo e(__('administrator.from_date')); ?>

                            </div>
                            <div class="form-group col-sm-9 col-md-9">
                                <?php echo Form::text('from_date', null, array('placeholder' => __('administrator.from_date'),'class' => 'form-control date_picker','autocomplete' => 'off','required')); ?>

                            </div>
                        </div>

                        <div class="col-sm-3 col-md-3">
                            <div class="col-sm-3 col-md-3" style="margin-top: 5px">
                                <?php echo e(__('administrator.to_date')); ?>

                            </div>
                            <div class="form-group col-sm-9 col-md-9">
                                <?php echo Form::text('to_date', null, array('placeholder' => __('administrator.to_date'),'class' => 'form-control date_picker','autocomplete' => 'off','required')); ?>

                            </div>
                        </div>
                        <div class="col-sm-offset-6 col-sm-6">
                            <button type="button" class=" button_success pull-right print_button"
                                    data-text="<?php echo e(__('administrator.stock_in_payment')); ?>" onclick="print_report()"
                                    type="button"><i class="fa fa-print"></i> <?php echo e(__('administrator.print')); ?></button>

                            <button class=" button_primary pull-right" id="search"
                                    type="submit"> <?php echo e(__('administrator.search')); ?></button>
                        </div>

                    </div>
                </div>
            </div>
            <div class="wrapper-table">
                <table id="print_table" width="100%" class="table table-striped table-hover ">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th><?php echo e(__('administrator.invoice_number')); ?></th>
                        <th><?php echo e(__('administrator.type')); ?></th>
                        <th><?php echo e(__('administrator.transaction_code')); ?></th>
                        <th><?php echo e(__('administrator.purchase_date')); ?></th>
                        <th><?php echo e(__('administrator.supplier_name')); ?></th>
                        <th><?php echo e(__('administrator.supplier_phone')); ?></th>
                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Show Purchase Item Price')): ?>
                            <th><?php echo e(__('administrator.total')); ?></th>
                        <?php endif; ?>
                    </tr>
                    </thead>
                    <tbody class="tbody">

                    </tbody>
                    <?php $col_span=6;  ?>
                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Show Purchase Item Price')): ?>
                        <?php $col_span++; ?>
                    <?php endif; ?>
                    <tr class="tfoot">
                        <th colspan="<?php echo e($col_span); ?>" class="text-right"><?php echo e(__('administrator.total_amount')); ?></th>
                        <th class="total_amt green">0</th>
                    </tr>
                </table>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
    <script type="text/javascript">
        $(document).ready(function () {
            dataTableFilter()
        });

        function dataTableFilter(supplier_id = '', type = '', start_date = '', end_date = '') {
            $('#print_table').DataTable({
                ordering: false,
                serverSide: true,
                lengthMenu: tbLeng,
                ajax: {
                    url: "<?php echo e(route('dt_seach_reportpurchases')); ?>",
                    data: {
                        supplier_id,
                        type,
                        start_date,
                        end_date,
                    }
                },

                columns:
                    [
                        {data: 'DT_RowIndex', 'searchable': false},
                        {data: 'invoice_number', 'name': 'nso007_purchases.invoice_number'},
                        {data: 'type', 'searchable': false},
                        {data: 'transaction_code', 'name': 'nso007_purchases.transaction_code'},
                        {data: 'purchase_date', 'name': 'nso007_purchases.purchase_date'},
                        {data: 'supplier_name', 'name': 'nso007_suppliers.supplier_name'},
                        {data: 'supplier_phone', 'name': 'nso007_suppliers.supplier_phone'},
                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Show Purchase Item Price')): ?>{data: 'amount', 'searchable': false},<?php endif; ?>
                    ],
                "fnDrawCallback":function () {
                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Show Purchase Item Price')): ?>
                    let tr = $('.tbody tr');
                    let total_usd = 0;
                    let total_riel = 0;
                    let t_r='';
                    let t_u='';
                    $.each(tr,function (ii,vv) {
                        let row = $(this).find('.amount')
                        let amount = row.data('amount');
                        let cur_id = row.data('currency_id');
                        amount = amount?parseFloat(amount):0;
                        console.log(amount)
                        if(cur_id===1){
                            total_riel+=amount;
                        }
                        if(cur_id===2){
                            total_usd+=amount;
                        }
                        t_u = total_usd?('$'+addComma(total_usd.toFixed(2))):'';
                        t_r = total_riel?('៛'+addComma(total_riel.toFixed(2))):'';
                    });
                    $('.tfoot .total_amt').html((t_r?(t_r+'<br>'):'0')+t_u);
                    <?php endif; ?>
                },
            });
        }

        $(document).on('click', '#search', function () {
            let supplier_id = $('select[name="supplier_id"]').val();
            let type = $('select[name="type"]').val();
            let start_date = $('input[name="from_date"]').val();
            let end_date = $('input[name="to_date"]').val();
            $('#print_table').DataTable().destroy();
            dataTableFilter(supplier_id, type, start_date, end_date);
        });

    </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/reportpurchases/index.blade.php ENDPATH**/ ?>