<?php $__env->startSection('mainContent'); ?>
    <div class="row justify-content-center">
        <div class="col-12">
            <div class="box_header common_table_header">
                <div class="main-title d-md-flex">
                    <?php if(moduleStatusCheck('ExtraUser')): ?>
                        <h3 class="mb-0 mr-30 mb_xs_15px mb_sm_20px"><?php echo e(__('extrauser::extrauser.'.ucfirst($type). ' Sales')); ?></h3>
                    <?php else: ?>
                        <h3 class="mb-0 mr-30 mb_xs_15px mb_sm_20px"><?php echo e(__('sale.Sales')); ?></h3>
                    <?php endif; ?>
                    <?php if(permissionCheck('sale.store')): ?>
                    <ul class="d-flex">
                        <li><a class="primary-btn radius_30px mr-10 fix-gr-bg" href="<?php echo e(route("sale.create")); ?>"><i
                                    class="ti-plus"></i><?php echo e(__('sale.New Sale')); ?></a>
                        </li>
                    </ul>
                    <?php endif; ?>
                </div>
            </div>
        </div>
        <div class="col-lg-12">
            <div class="QA_section QA_section_heading_custom check_box_table">
                <div class="QA_table ">
                    <!-- table-responsive -->
                    <div class="">
                        <table class="table Crm_table_active3">
                            <thead>
                            <tr>
                                <th scope="col"><?php echo e(__('sale.Sl')); ?></th>
                                <th scope="col" width="10%"><?php echo e(__('sale.Date')); ?></th>
                                <th scope="col"><?php echo e(__('sale.Invoice')); ?></th>
                                <th scope="col"><?php echo e(__('sale.User')); ?></th>
                                <th scope="col"><?php echo e(__('common.Customer')); ?></th>
                                <th scope="col"><?php echo e(__('common.Total Amount')); ?></th>
                                <th scope="col"><?php echo e(__('sale.Paid')); ?></th>
                                <th scope="col"><?php echo e(__('sale.Due')); ?></th>
                                <th scope="col"><?php echo e(__('common.Status')); ?></th>
                                <th scope="col"><?php echo e(__('common.Action')); ?></th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php $__currentLoopData = $sales; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=> $sale): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <tr>
                                    <td><?php echo e($key+1); ?></td>
                                    <td><?php echo e(showDate($sale->created_at)); ?></td>
                                    <td><a href="javascript:void(0)" onclick="getDetails(<?php echo e($sale->id); ?>)"><?php echo e($sale->invoice_no); ?></a></td>
                                    <td><?php echo e(@$sale->user->name); ?></td>
                                    <td>
                                        <?php if($sale->customer_id): ?>
                                            <?php echo e(@$sale->customer->name); ?>

                                        <?php else: ?>
                                            <?php echo e(@$sale->agentuser->name); ?>

                                        <?php endif; ?>
                                    </td>
                                    <td><?php echo e(single_price($sale->payable_amount)); ?></td>
                                    <?php
                                        $paid = $sale->payments->sum('amount') + $sale->payments->sum('advance_amount') - $sale->payments->sum('return_amount');
                                    ?>
                                    <td><?php echo e(single_price($paid)); ?></td>
                                    <td><?php echo e((($sale->payable_amount - $paid) > 0) ? single_price($sale->payable_amount - $paid) : single_price(0)); ?></td>
                                    <td>
                                        <?php if($sale->is_approved == 0): ?>
                                            <h6><span class="badge_4"><?php echo e(__('sale.Unapproved')); ?></span></h6>
                                        <?php else: ?>
                                            <h6><span class="badge_1"><?php echo e(__('sale.Approved')); ?></span></h6>
                                        <?php endif; ?>
                                    </td>
                                    <td>
                                        <div class="dropdown CRM_dropdown">
                                            <button class="btn btn-secondary dropdown-toggle" type="button"
                                                    id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true"
                                                    aria-expanded="false"> <?php echo e(__('common.select')); ?>

                                            </button>
                                            <div class="dropdown-menu dropdown-menu-right"
                                                 aria-labelledby="dropdownMenu2">
                                                <?php if($sale->is_approved == 0): ?>
                                                    <?php if(permissionCheck('sale.edit')): ?>

                                                    <a href="<?php echo e(route('sale.edit',$sale->id)); ?>" class="dropdown-item"
                                                       type="button"><?php echo e(__('common.Edit')); ?></a>
                                                       <?php endif; ?>
                                                <?php endif; ?>
                                                <?php if($sale->status != 1 && $sale->is_approved == 1): ?>
                                                    <a href="<?php echo e(route('sale.payment',$sale->id)); ?>" class="dropdown-item"
                                                       type="button"><?php echo e(__('pos.Payment')); ?></a>
                                                <?php endif; ?>
                                                <?php if(permissionCheck('return.sale.approve') && $sale->return_status == 0 && $sale->items->sum('return_quantity') > 0): ?>
                                                    <a onclick="approve_modal('<?php echo e(route('return.sale.approve', $sale->id)); ?>')"
                                                       class="dropdown-item edit_brand"><?php echo e(__('sale.Return Approve')); ?></a>
                                                <?php endif; ?>
                                                <?php if(permissionCheck('sale.return') && $sale->return_status != 1): ?>
                                                    <a href="<?php echo e(route('sale.return',$sale->id)); ?>" class="dropdown-item"
                                                       type="button"><?php echo e(__('sale.Sale Return')); ?></a>
                                                <?php endif; ?>
                                                <?php if(permissionCheck('conditional.sale.approve') && $sale->is_approved == 0): ?>
                                                    <a onclick="approve_modal('<?php echo e(route('conditional.sale.approve', $sale->id)); ?>')"
                                                       class="dropdown-item edit_brand"><?php echo e(__('sale.Approve')); ?></a>
                                                <?php endif; ?>
                                                <?php if($sale->type == 0): ?>
                                                    <a href="javascript:void(0)" onclick="shippingInfo(<?php echo e($sale->id); ?>)"
                                                       data-toggle="modal" data-target="#shipping_details"
                                                       class="dropdown-item"
                                                       type="button"><?php echo e(__('sale.Shipping Details')); ?></a>
                                                <?php endif; ?>
                                                <?php if(permissionCheck('sale.show')): ?>
                                                <a href="<?php echo e(route('sale.show',$sale->id)); ?>" class="dropdown-item"
                                                   type="button"><?php echo e(__('sale.Order Details')); ?></a>
                                                <?php endif; ?>
                                                <a href="<?php echo e(route('sale.pdf',$sale->id)); ?>" class="dropdown-item" type="button"><?php echo e(__('quotation.Download')); ?></a>
                                                <a href="<?php echo e(route('sale.challan_pdf',$sale->id)); ?>" class="dropdown-item" type="button"><?php echo e(__('common.Challan Download')); ?></a>
                                                <a href="<?php echo e(route('sale.clone',$sale->id)); ?>" class="dropdown-item" type="button"><?php echo e(__('sale.Clone to Sale')); ?></a>
                                                <a href="<?php echo e(route('sale.convertTosale', $sale->id)); ?>" class="dropdown-item" type="button"><?php echo e(__('quotation.Clone to Quotation')); ?></a>
                                                 <?php if(permissionCheck('sale.delete') && $sale->is_approved != 1): ?>
                                                     <a onclick="confirm_modal('<?php echo e(route('sale.delete', $sale->id)); ?>')" class="dropdown-item edit_brand"><?php echo e(__('common.Delete')); ?></a>
                                                 <?php endif; ?>
                                                <?php if($sale->is_approved == 1): ?>
                                                    <a href="<?php echo e(route('sale.show',$sale->id)); ?>" class="dropdown-item edit_brand"><?php echo e(__('common.Print')); ?></a>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade admin-query" id="shipping_details">
        <div class="modal-dialog modal_800px modal-dialog-centered">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title"><?php echo e(__('sale.Shipping Info')); ?></h4>
                    <button type="button" class="close " data-dismiss="modal">
                        <i class="ti-close "></i>
                    </button>
                </div>

                <div class="modal-body">
                    <form action="">
                        <div class="row shipping_info">
                            <div class="col-12">
                                <h6><?php echo e(__('sale.Shipping Name')); ?> : <span class="view_shipping_name"></span></h6>
                                <h6><?php echo e(__('sale.Shipping Reference No')); ?> : <span class="view_shipping_ref"></span></h6>
                                <h6><?php echo e(__('sale.Date')); ?> : <span class="view_date"></span></h6>
                                <h6><?php echo e(__('sale.Received By')); ?> : <span class="view_received_by"></span></h6>
                                <h6><?php echo e(__('sale.Received Date')); ?> : <span class="view_received_date"></span></h6>
                            </div>
                        </div>
                    </form>
                </div>

            </div>
        </div>
    </div>
    <div id="getDetails">
    </div>
    <?php echo $__env->make('backEnd.partials.delete_modal', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <?php echo $__env->make('backEnd.partials.approve_modal', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php $__env->stopSection(); ?>
<?php $__env->startPush('scripts'); ?>
    <script>
        function printDiv(divName) {
            var printContents = document.getElementById(divName).innerHTML;
            var originalContents = document.body.innerHTML;
            document.body.innerHTML = printContents;
            window.print();
            document.body.innerHTML = originalContents;
            setTimeout(function(){ window.location.reload(); }, 15000);
        }
        function modal_close() {
            $('#sale_info_modal').remove();
            $('.modal-backdrop').remove();
            window.location.reload();
        }
       /* $(document).on('click', '.show_due', function () {
            alert(true);

        })*/

        function saleInfo(id) {
            let input = '<input type="hidden" name="id" value="' + id + '" "> ';
            $('#delivery_info').append(input);
        }

        function shippingInfo(id) {
            $.ajax({
                method: 'POST',
                url: '<?php echo e(route('sale.shipping_info')); ?>',
                data: {
                    id: id,
                    _token: "<?php echo e(csrf_token()); ?>",
                },
                success: function (result) {
                    $('.view_shipping_name').text(result.shipping_name);
                    $('.view_shipping_ref').text(result.shipping_ref);
                    $('.view_date').text(result.date);
                    $('.view_received_by').text(result.received_by);
                    $('.view_received_date').text(result.received_date);
                }
            })
        }

        function getDetails(el){
            $.post('<?php echo e(route('get_sale_details')); ?>', {_token:'<?php echo e(csrf_token()); ?>', id:el}, function(data){
                $('#getDetails').html(data);
                $('#sale_info_modal').modal('show');
                $('select').niceSelect();
            });
        }
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('backEnd.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/penastud/public_html/InfixBiz/Modules/Sale/Resources/views/sale/index.blade.php ENDPATH**/ ?>