
<?php $__env->startSection('title','Goods in '); ?>
<?php $__env->startSection('content'); ?>
    <!-- Content Header (Page header) -->
    <div class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1 class="m-0 text-dark">Manage  Goods In </h1>
                </div><!-- /.col -->
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="#">Goods In Management</a></li>
                        <li class="breadcrumb-item active">Add Goods In </li>
                    </ol>
                </div><!-- /.col -->
            </div><!-- /.row -->
        </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->


    <!-- Main content -->
    <section class="content">
        <div class="col-lg-12">
            <div class="row">
                
                <div class="col-lg-12">
                    <div class=" bg-light">
                        <div class="card card-info card-outline">
                            <div class="card-header">
                                <h3 class="card-title">Add Inventory Goods In </h3>
                                <div class="card-tools">
                                    
                                </div>
                            </div> <!-- /.card-header -->

                            <div class="card-body" style="display: block;">
                                <?php echo e(Form::open(['route'=>'goodsin.store','method'=>'post', 'class'=>'form-horizontal'])); ?>

                                <div class="row">
                                    

                                    <div class="col-lg-12">
                                        <h6 class="text-center bg-primary" style="padding:5px 0;font-size: 1.5rem;font-weight: bold;letter-spacing: 10px">GOODS IN</h6>
                                        <hr>
                                        <table class="table-hover table-bordered  table goodsinProList">
                                            <thead>
                                                <tr>
                                                    <th>SL</th>
                                                    <th width="30%">Item</th>
                                                    <th width="15%">Unit</th>
                                                    <th>Qty</th>
                                                    <th>Price</th>
                                                </tr>
                                            </thead>

                                            <tbody class="proList">

                                                <tr>
                                                    <td>1</td>
                                                    <td>
                                                        <select name="item" id="item_id" onchange="setUnit()" class="select2 form-control">
                                                            <option value="" required>Select Item</option>
                                                            <?php $__currentLoopData = $products; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $product): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                            <option value="<?php echo e($product->id); ?>"><?php echo e($product->group->name); ?>- <?php echo e($product->item_code); ?> <?php echo e($product->name); ?></option>
                                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                        </select>
                                                    </td>
                                                    <td>
                                                        <select name="unit_id" id="unit_id" class="select2 form-control">
                                                            <option value="">Select Unit</option>
                                                            <?php $__currentLoopData = $units; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $unit): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                            <option value="<?php echo e($unit->id); ?>"><?php echo e($unit->name); ?></option>
                                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                        </select>
                                                    </td>
                                                    <td><input type="number" required name="qty" class="form-control"></td>
                                                    <td><input type="text" required name="price" class="form-control"></td>
                                                </tr>
                                            </tbody>

                                        </table>
                                    </div>

                                    <div class="col-lg-9"></div>


                                    


                                    <div class="col-lg-5"></div>

                                    <div class="col-lg-2">
                                        <div class="form-group">
                                            <?php echo e(Form::submit('Save Goods In',['class'=>'form-control btn btn-info'])); ?>

                                        </div>
                                    </div>
                                    <div class="col-lg-5"></div>
                                </div>
                                <?php echo e(Form::close()); ?>

                            </div>
                        </div>
                    </div>
                </div>
                



            </div>

        </div>
        <hr>
        
        <div class="modal fade" id="quickViewModal">
            <div class="modal-dialog modal-md">
              <div class="modal-content">
                <div class="modal-header">
                  <h4 class="modal-title" id="quickViewModalTitle">Edit Modal</h4>
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                  </button>
                </div>
                <div class="modal-body" id="quickViewModalBody">
                  
                </div>
                <div class="modal-footer justify-content-between" id="quickViewModalFooter">
                  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                  <button type="submit" class="btn btn-primary">Save changes</button>
                </div>
              </div>
            </div>
        </div>
    </section><!-- /.content -->

<?php $__env->stopSection(); ?>

<?php $__env->startSection('style'); ?>
    <!-- DataTables -->

    <link rel="stylesheet" href="<?php echo e(asset('plugins/datatables/dataTables.bootstrap4.css')); ?>">
    <link href='https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css' rel='stylesheet' type='text/css'>
    <link href='https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.4/jquery-confirm.min.css' rel='stylesheet' type='text/css'>
    
<?php $__env->stopSection(); ?>

<?php $__env->startSection('plugin'); ?>
    <!-- DataTables -->
    <script src="<?php echo e(asset('plugins/datatables/jquery.dataTables.js')); ?>"></script>
    <script src="<?php echo e(asset('plugins/datatables/dataTables.bootstrap4.js')); ?>"></script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js'></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.4/jquery-confirm.min.js"></script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('script'); ?>
    <!-- page script -->
    <script type="text/javascript">
        $('.select2').select2()

        //Initialize Select2 Elements
        $('.select2bs4').select2({
          theme: 'bootstrap4'
        })
        $(document).ready(function () {
            table = $("#goodsinProList").DataTable();
        });
        function Delete(id) {
            $.confirm({
                title: 'Confirm!',
                content: '<hr><strong class="text-danger">Are you sure to delete ?</strong><hr>',
                buttons: {
                    confirm: function () {
                        $.ajax({
                          headers: { 'X-CSRF-TOKEN' : '<?php echo e(csrf_token()); ?>' },
                          url: "<?php echo e(url('add-goodsin')); ?>/"+id+'/delete',
                          type: 'DELETE',
                          dataType: 'json',
                          data: {},
                          success:function(response) {
                            if(response.success){
                              $('#tr-'+id).fadeOut();
                            }else{
                              $.alert({
                                title:"Whoops!",
                                content:"<hr><strong class='text-danger'>Something Went Wrong!</strong><hr>",
                                type:"red"
                              });
                            }
                          }
                        });
                    },
                    cancel: function () {

                    }
                }
            });   
          }

        function editPage(id){
            var modal=$('#quickViewModal');
            var modalTitle=$('#quickViewModalTitle');
            var modalBody=$('#quickViewModalBody');
            var modalFooter=$('#quickViewModalFooter');
            modal.modal('toggle');
            modalFooter.hide();

            //modalBody.html('<center><img src="<?php echo e(url('public/loader.gif')); ?>"></center>');
            $.ajax({
                url: "<?php echo e(url('/add-goodsin')); ?>/"+id+"/edit",
                type: 'GET',
                data: {},
            })
            .done(function(response) {
                modalTitle.html('Edit Goods In');
                modalBody.html(response);
                //modalFooter.show();
            })
            .fail(function() {
                modal.modal('toggle');
            });
        }

        function setUnit(){
            var item_id = $('#item_id').val();
            console.log(item_id)
            if(item_id != null){
                $.ajax({
                    url: '<?php echo e(url('add-goodsin')); ?>/'+item_id+'/set-unit',
                    type: 'GET',
                    dataType: 'json',
                })
                .done(function(response) {
                    $('#unit_id').val(response.item_unit).select2();
                    // data = '<option value="">Select Unit</option>';
                    // selected = '';
                    // $.each(response.units, function(index, val) {
                    //     if(val.id == response.item_unit){
                    //         selected = 'selected';
                    //     }
                    //     data += '<option value='+val.id+' '+selected+'>'+val.name+'</option>';
                    // });
                    // $('#unit_id').html(data);
                });
                
            }else{
                //$('#unit_id').html('');
            }
        }
        var gtable ;

        $(document).ready(function () {
          //  gtable = $(".goodsinProList").DataTable();
        });

        $(document).on('change','.purchase_id',function () {
            var purchase_id = $(this).val();
            var token = '<?php echo e(csrf_token()); ?>';

            if (purchase_id !=''){


               $.ajax({
                   method:"post",
                   url:'<?php echo e(route('purchase.productList')); ?>',
                   data:{purchase_id:purchase_id,_token:token},
                   dataType:'html',
                   success:function (res) {

                        $('.proList').html(res);
                   }
               })
            }

        });


        $(document).on('keyup','.qtyCheck',function () {
            var qty = $(this).attr('data-qty');
            var rcvqty = $(this).val();
            var rowId = $(this).attr('data-rowid');

            if (Number(rcvqty) <= Number(qty)){
                $(this).css({'border':"5px solid #17A05D"});
                balance = Number(qty)-Number(rcvqty);
                $("#rowId"+rowId).html(balance);
            }else{
                $(this).val(0);
                $(this).css({'border':"5px solid #DD5044"});
            }

        });

    </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.fixed', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/welluugs/purchase.wellgrouperp.com/resources/views/inventory/goodsin/add-goodsin.blade.php ENDPATH**/ ?>