<?php $__env->startSection('section-title', 'Product'); ?>
<?php $__env->startSection('page-title', 'Pay Supplier'); ?>
<?php if(check_permission('payment.pay-supplier-store')): ?>
    <?php $__env->startSection('action-button'); ?>
    <a href="#" id="modal_btn" class="btn add_list_btn">
        <i class="mr-2 feather icon-plus"></i>
        Pay Supplier
    </a>
    <?php $__env->stopSection(); ?>
<?php endif; ?>
<?php $__env->startSection('content'); ?>
    <div class="row">
        <div class="col-lg-12">
            <div class="card card-body mb-2 card_style" style="margin-top: -5px" id="h-hide">
                <form action="<?php echo e(route('payment.pay-supplier')); ?>">
                    <div class="form-row">
                        <div class="form-group col-md-4">
                            <select class="select2" name="supplier_id">
                                <option selected value="">Select Supplier</option>
                                <?php $__currentLoopData = $suppliers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $supplier): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($supplier->id); ?>"><?php echo e($supplier->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('payment.pay-supplier')); ?>" class="btn cancel_btn">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 card_style">
                <div class="card-body">
                    <div class="table-responsive">
                        <table id="datatable-buttons" class="table table-striped">
                            <thead class="header_bg">
                                <tr>
                                    <th class="header_style_left">#</th>
                                    <th>Date</th>
                                    <th>Wallet Type</th>
                                    <th>Pay Type</th>
                                    <th>Amount</th>
                                    <th>Discount Amount</th>
                                    <th class="header_style_right">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__empty_1 = true; $__currentLoopData = $payment; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <?php
                                    // dd($data->transaction->id);
                                ?>
                                    <tr>
                                        <td class="table_data_style_left"><?php echo e($loop->index + 1); ?></td>
                                        <td><?php echo e(date('d-m-Y',strtotime($data->date))); ?></td>
                                        <td><?php echo e($data->wallet_type); ?></td>
                                        <td><?php echo e($data->pay_type); ?> (<?php echo e($data->transaction?->supplier?->name); ?>)</td>
                                        <td><?php echo e($data->amount); ?></td>
                                        <td>
                                            <?php if($data->discount_amount == null ): ?>
                                                0.00
                                            <?php endif; ?>
                                            <?php if($data->discount_amount != null): ?>
                                            <?php echo e($data->discount_amount); ?>

                                            <?php endif; ?>
                                        </td>
                                        <td class="table_data_style_right">
                                            <div class="dropdown">
                                                <button class="btn add_list_btn btn-sm dropdown-toggle" type="button"
                                                    id="dropdownMenuButton" data-toggle="dropdown">
                                                    Action
                                                </button>
                                                <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">

                                                    
                                                    <?php if(check_permission('payment.supplier-destroy')): ?>
                                                        <a href="#" data-toggle="modal"
                                                            data-target="#deleteModal-<?php echo e($data->id); ?>"
                                                            class="dropdown-item text-danger">
                                                            <i class="feather icon-trash"></i> Delete
                                                        </a>
                                                    <?php endif; ?>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>

                                    
                                    <form action="<?php echo e(route('payment.supplier-destroy', $data->id)); ?>" method="POST">
                                        <?php echo csrf_field(); ?>
                                        <?php if (isset($component)) { $__componentOriginal37b7f052626c638ba0443fdb400d6f57 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal37b7f052626c638ba0443fdb400d6f57 = $attributes; } ?>
<?php $component = App\View\Components\DeleteModal::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('delete-modal'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(App\View\Components\DeleteModal::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['title' => 'Product','id' => ''.e($data->id).'']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal37b7f052626c638ba0443fdb400d6f57)): ?>
<?php $attributes = $__attributesOriginal37b7f052626c638ba0443fdb400d6f57; ?>
<?php unset($__attributesOriginal37b7f052626c638ba0443fdb400d6f57); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal37b7f052626c638ba0443fdb400d6f57)): ?>
<?php $component = $__componentOriginal37b7f052626c638ba0443fdb400d6f57; ?>
<?php unset($__componentOriginal37b7f052626c638ba0443fdb400d6f57); ?>
<?php endif; ?>
                                    </form>

                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                    <tr>
                                        <td colspan="100%" class="text-center no_data_style text-danger">No Data Available</td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="pagination justify-content-center">
                        
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php echo $__env->make('backend.pages.payment.supplier_model', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('js'); ?>
    <script type="text/javascript">
        $("#modal_btn").on("click", function () {
            //show payment_modal
            $("#modal").modal("show");
        });

        $(document).on('change', '.supplier_id', function () {
            let supplier_id = $(this).val(); console.log(supplier_id);
            let url = "<?php echo e(route('supplier-account-balance', 'my_id')); ?>".replace('my_id', supplier_id);
            $.get(url, data => {
                $("#details").show(500);
                $("#account_name").text(data.supplier_name);
                $("#due_purchase").text(data.due_purchase);
                $("#total_purchase_due").text(data.purchase_due);
                $("#wallet_balance").text(data.walletBalance);
                $("#id_hint").html('*** ক্রয় বাবদ দেনা আছে '+Math.abs(data.purchase_due)+' TK ***');

                if(data.walletBalance>=0){
                        $("#wb_hint").html('**** সাপ্লাইয়ারের কাছে জমা আছেঃ '+Math.abs(data.walletBalance)+'TK ****');
                }else{
                        $("#wb_hint").html('**** আপনার থেকে সাপ্লাইয়ার পাবেঃ '+Math.abs(data.walletBalance)+'TK ****');
                }

                //for input
                $(".purchase_due").val(data.purchase_due);
                $(".wallet_balance").val(data.walletBalance);
            });
        });

        $("#supplier_id").change(function(){
            if($(this).val() == '') {
                $("#details").hide(500);
            }
        });

        $("#details").hide();
    </script>

    
    <script type="text/javascript">
        $(document).on('change', '#wallet_type', function(){
          // alert('ok');
          var wallet_type = $(this).val();
          let html = '<option value="">Select Pay Type</option>';
          if(wallet_type == 'Due Adjust'){
            let data = ['Money Payment'];
            $.each(data,function(key,v){
                html +='<option value="'+v+'">'+v+'</option>';
            });
            $('#pay_type').html(html);
            $('#pay_type').trigger('change');
          } else if(wallet_type == 'Balance Adjust'){
            let data = ['Money Payment', 'Money Received'];
            $.each(data,function(key,v){
                html +='<option value="'+v+'">'+v+'</option>';
            });
            $('#pay_type').html(html);
            $('#pay_type').trigger('change');
          } else {
            $('#pay_type').html(html);
            $('#pay_type').trigger('change');
          }
        });
      </script>
<?php $__env->stopPush(); ?>

<?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/payment/supplier_index.blade.php ENDPATH**/ ?>