<?php $__env->startSection('content'); ?>
    <style>
        label.error {
            color: red;
        }
    </style>
    <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
    <div class="common-content">
        <div class="page-content">
            <div class="page-heading">
                <div class="headings">
                    <h6>Manufacturer/Vendor
                    </h6>
                </div>
            </div>
            <div class="dashboard-cnts">
                <button class="barcodeBtn" type="button" id="create_new_department"
                    style="display:block;height: 38px;margin-top: 25px;">
                    Add New Manufacturer/Vendor
                </button>
            </div>
            <table id="example" class="display" cellspacing="0" width="100%">
                <thead>
                    <tr>
                        <th>No:</th>
                        <th>Name</th>
                        <th>Email</th>
                        <th>Phone Number</th>
                        <th>GST</th>
                        <th>Address</th>
                        <th>ZIP Code</th>
                        <th>MAF Doc</th>
                        <th>Role</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $i = 1; ?>
                    <?php $__currentLoopData = $userlist; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $list): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td><?php echo e($i); ?></td>
                            <td>
                                <?php echo e(ucfirst($list->name)); ?>

                            </td>
                            <td>
                                <?php echo e($list->email); ?>

                            </td>
                            <td>
                                <?php echo e($list->phone); ?>

                            </td>
                            <td>
                                <?php echo e($list->gst); ?>

                            </td>
                            <td>
                                <?php echo e($list->address); ?>

                            </td>
                            <td>
                                <?php echo e($list->zip_code); ?>

                            </td>
                            <td>
                                <a href="<?php echo e(url('uploads/maf_docs/' . $list->maf_doc)); ?>"
                                    target="_blank"><?php echo e($list->maf_doc); ?></a>
                            </td>
                            <td>
                                <?php if($list->user_type == '1'): ?>
                                    Buyer
                                <?php elseif($list->user_type == '2'): ?>
                                    Vendor
                                <?php elseif($list->user_type == '3'): ?>
                                    Manufacturer
                                <?php elseif($list->user_type == '4'): ?>
                                    Sub Buyer
                                <?php elseif($list->user_type == '5'): ?>
                                    Procurement
                                <?php elseif($list->user_type == '6'): ?>
                                    Government
                                <?php elseif($list->user_type == '7'): ?>
                                    Group
                                <?php else: ?>
                                <?php endif; ?>
                            </td>
                        </tr>
                        <?php $i++; ?>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
            </table>
        </div>
        <!-- Modal -->
        <div class="modal fade" id="myModalaction" role="dialog">
            <div class="modal-dialog modal-lg cutom-modal">
                <!-- Modal content-->
                <div class="modal-content rounded">
                    <div class="modal-header new-header">
                        <h5 class="modal-title" id="exampleModalLabel">Add Manufacturer/Vendor
                        </h5>
                        <button type="button" class="close close_message" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;
                            </span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <div class="col-sm-12 col-xs-12">
                            <div class="dashboard-cnts">

                                <form id="addManufacturerVendor" class="row" role="form" method="post"
                                    action="<?php echo e(url('buyers/add_user')); ?>" enctype="multipart/form-data">
                                    <?php echo csrf_field(); ?>
                                    <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
                                        <div class="form-inputs">
                                            <div class="form-group">
                                                <?php if($errors->has('gst')): ?>
                                                    <label class="error"><?php echo e($errors->first('gst')); ?>

                                                    </label>
                                                <?php endif; ?>
                                                <input type="text" class="form-control" id="gst"
                                                    value="<?php echo e(old('gst')); ?>" name="gst" required placeholder="GST">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
                                        <div class="form-inputs">
                                            <div class="form-group">
                                                <?php if($errors->has('name')): ?>
                                                    <label class="error"><?php echo e($errors->first('name')); ?>

                                                    </label>
                                                <?php endif; ?>
                                                <input type="text" class="form-control" id="name" name="name"
                                                    value="<?php echo e(old('name')); ?>" required placeholder="Name">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
                                        <div class="form-inputs">
                                            <div class="form-group">
                                                <?php if($errors->has('email')): ?>
                                                    <label class="error"><?php echo e($errors->first('email')); ?>

                                                    </label>
                                                <?php endif; ?>
                                                <input type="email" class="form-control" id="email"
                                                    value="<?php echo e(old('email')); ?>" name="email" required
                                                    placeholder="Email">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
                                        <div class="form-inputs">
                                            <div class="form-group">
                                                <?php if($errors->has('phone')): ?>
                                                    <label class="error"><?php echo e($errors->first('phone')); ?>

                                                    </label>
                                                <?php endif; ?>
                                                <input type="tel" class="form-control" id="phone"
                                                    value="<?php echo e(old('phone')); ?>" name="phone" required
                                                    placeholder="Phone">
                                            </div>
                                        </div>
                                    </div>
                                
                                    <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
                                        <div class="form-inputs">
                                            <div class="form-group">
                                                <?php if($errors->has('zip_code')): ?>
                                                    <label class="error"><?php echo e($errors->first('zip_code')); ?>

                                                    </label>
                                                <?php endif; ?>
                                                <input type="text" class="form-control" id="zip_code"
                                                    value="<?php echo e(old('zip_code')); ?>" name="zip_code" required
                                                    placeholder="ZIP Code">
                                            </div>
                                        </div>
                                    </div>
                                    
                                    <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
                                        <div class="form-inputs">
                                            <div class="form-group">
                                                <?php if($errors->has('user_type')): ?>
                                                    <label class="error">
                                                        <?php echo e($errors->first('user_type')); ?></label>
                                                <?php endif; ?>
<!--                                                <label for="user_type">User Type:</label>-->

                                                <select class="form-control" name="user_type" id="user_type" required>
                                                    <option value="">Choose user type</option>
                                                    
                                                    <option value="2"
                                                        <?php echo e(old('user_type') == '2' ? 'selected' : ''); ?>>Vendor</option>
                                                    <option value="3"
                                                        <?php echo e(old('user_type') == '3' ? 'selected' : ''); ?>>Manufacturer
                                                    </option>
                                                    
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-lg-12 col-md-6 col-sm-12 col-xs-12">
                                        <div class="form-inputs">
                                            <div class="form-group">
                                                <?php if($errors->has('address')): ?>
                                                    <label class="error">
                                                        <?php echo e($errors->first('address')); ?></label>
                                                <?php endif; ?>
                                                 <textarea class="form-control" value="<?php echo e(old('address')); ?>" required placeholder="Address" id="address" name="address" rows="3"></textarea>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-lg-12 col-md-6 col-sm-12 col-xs-12">
                                        <div class="form-inputs">
                                            <div class="form-group">
                                                <?php if($errors->has('maf_doc')): ?>
                                                    <label class="error"><?php echo e($errors->first('maf_doc')); ?>

                                                    </label>
                                                <?php endif; ?>
                                                <input type="file" class="form-control" id="maf_doc" name="maf_doc"
                                                    required placeholder="MAF Document">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
                                        <div class="form-inputs">
                                            <div class="form-group">
                                                
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                      <div class="d-flex align-items-center justify-content-end w-100">
<!--                           <button style="min-width: 120px;" data-dismiss="modal" class="btn medd-buttons medd-blue rounded">OK</button>-->
                          <button style="min-width: 120px;" type="submit" class="form-btn btn medd-buttons medd-blue rounded" id="cf-submit" name="submit">Submit</button>
                      </div>
                  </div>
                </div>
            </div>
        </div>
        <!-- Modal -->
    <?php $__env->stopSection(); ?>
    <?php $__env->startSection('scripts'); ?>
        <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
        <script src="<?php echo e(URL::to('assets/js/buyernew.js')); ?>"></script>

        <script>
            $(function() {
                $(".invoiceselect").select2();
            });
            <?php if($errors->any()): ?>
                $(document).ready(function() {
                    $('#create_new_department').trigger('click');
                });
            <?php endif; ?>
            $(document).ready(function() {
                $('#example').DataTable();
                $('#example1').DataTable();
            });
            <?php if(Session::has('message')): ?>
                swal({
                    title: "",
                    text: "<?php echo e(Session::get('message')); ?>",
                    type: "success",
                    showCancelButton: false,
                    dangerMode: false,
                    confirmButtonText: 'OK',
                });
            <?php endif; ?>
            <?php if(Session::has('errormessage')): ?>
                swal({
                    title: "",
                    text: "<?php echo e(Session::get('errormessage')); ?>",
                    type: "error",
                    showCancelButton: false,
                    dangerMode: true,
                    confirmButtonText: 'OK',
                });
            <?php endif; ?>
            $("#addManufacturerVendor").validate({
                rules: {
                    email: {
                        required: true,
                        email: true,
                    }
                },
                submitHandler: function(form, e) {
                    var data = {
                        _token: $(".token_user").val(),
                        email: $("#email").val(),
                        phone: $("#phone").val(),
                    };
                    $.ajax({
                        url: "https://www.meddbot.com/emailexist",
                        type: "POST",
                        data: data,
                        success: function(res) {
                            var obj = jQuery.parseJSON(res);

                            console.log(res);
                            if (res == 1) {
                                swal("", "Email Id already exist", "warning");
                            } else if (res == 2) {
                                swal("", "Phone No already exist", "warning");
                            } else {
                                form.submit();
                            }
                        },
                    });
                },
            });
        </script>


<script>
    $(document).ready(function() {
   $('#gst').focusout(function() {

        var gst_no = $('#gst').val();
        if($('#gst').val() != ""){
                var gst_no = $('#gst').val();
                var APP_URL = <?php echo json_encode(url('/getmanufacturedetails')); ?> ;
                var saveData = $.ajax({
                    type: 'GET',
                    url: APP_URL+'/'+gst_no,
                    data: { gst_no: gst_no, _token: '<?php echo e(csrf_token()); ?>' },
                    dataType: "text",
                        success: function(resultData) {
                            console.log(resultData);
                            var res = JSON.parse(resultData);
                            if(res !== null && res !== ''){
                                if(res.user_type == '1'){
                                    alert('This Gst No is already registered as a buyer.');
                                }else if(res.user_type == '2'){
                                    alert('This Gst No is already registered as a Vendor.');
                                }else if(res.user_type == '3'){
                                     alert('This Gst No is already registered as a Manufacturer.');
                                }

                            }else{
                                var gst = $('#gst').val();
                                var APP_URL = <?php echo json_encode(url('/getgstdetails')); ?> ;
                                var saveData = $.ajax({
                                    type: 'GET',
                                    url: APP_URL+'/'+gst,
                                    data: { gst: gst, _token: '<?php echo e(csrf_token()); ?>' },
                                    dataType: "text",
                                        success: function(resultData) {
                                        var res = JSON.parse(resultData);
                                        var name= res.taxpayerInfo.lgnm;
                                            console.log(name);
                                            var dno = res.taxpayerInfo.pradr.addr.bno;
                                            var bnm = res.taxpayerInfo.pradr.addr.bnm;
                                            var st = res.taxpayerInfo.pradr.addr.st;
                                            var loc = res.taxpayerInfo.pradr.addr.loc;
                                            var dst = res.taxpayerInfo.pradr.addr.dst;
                                            var stcd = res.taxpayerInfo.pradr.addr.stcd;
                                            var pncd = res.taxpayerInfo.pradr.addr.pncd;
                                            var address =dno+','+bnm+','+st+','+loc+','+dst+','+stcd+','+pncd;
                                        
                                            var text1 = stcd;
                                            $("#state option").filter(function() {
                                                return this.text == text1; 
                                            }).attr('selected', true);

                                        $('#name').val(name);
                                        $('#address').val(address);
                                        $('#zip_code').val(pncd);
                                        $("#address").css("border-color", "");
                                        $("#zip_code").css("border-color", "");
                                        $("#state").css("border-color", "");
                                    }
                                });
                            }


                    }
                });
                $(".pageloader").show();
                $(".pageloader").delay(5000).fadeOut("slow");
        }
        /*else{
            $('#name').val('');
            $('#address').val('');
            $('#zipcode').val('');

        }*/

        if($("#address").val()!=''){
           $("#address").css("border-color", "");
        }
        else{
          $("#address").css("border-color", "red");
        }

        if($("#zipcode").val()!=''){
            $("#zipcode").css("border-color", "");
         }
        else{
            $("#zipcode").css("border-color", "red");
        }



    });
});
</script>















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

<?php echo $__env->make('layouts.main_assetmanage', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/meddbot/public_html/resources/views/manufacturers/addNewManufacturer.blade.php ENDPATH**/ ?>