<?php $__env->startSection('content'); ?>
<div class="common-content">
          <div class="page-content">
                <div class="page-heading">
                    <div class="headings">
                        <h6><?php echo e($title); ?></h6>
                    </div>
                </div>
                
              <div class="boxings">
                  <form method="POST" id="buyer_register" action="<?php echo e(url('vendors/register_manufacturer')); ?>" enctype="multipart/form-data">
              <?php echo csrf_field(); ?>

                  <div class="row">

                       <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12">
                        <div class="form-inputs">
                             <div class="form-group">
                                <label>GST No / VAT <sup>*</sup></label>
                                <input  type="text" id="gst_no" class="form-control " name="gst_no" value=""  autocomplete="gst_no" autofocus>
                              </div>
                        </div>
                      </div>

                    <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12">
                        <div class="form-inputs">
                             <div class="form-group">
                                <label>Email Id<sup>*</sup></label>
                              <input  class="form-control" id="email" name="email" value="" required autocomplete="email" autofocus>
                              </div>
                        </div>
                      </div>

                      <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12">
                        <div class="form-inputs">
                             <div class="form-group">
                                <label>Contact Person Name<sup>*</sup></label>
                              <input  class="form-control" id="contact_name" name="contact_name" value="" required autocomplete="contact_name" autofocus>
                              </div>
                        </div>
                      </div>

                      <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12">
                        <div class="form-inputs">
                             <div class="form-group">
                                <label>Contact Person Mobile No<sup>*</sup></label>
                                <input type="number" id="contact_phone_no" class="form-control" name="contact_phone_no"   minlength="10" maxlength="10"  autocomplete="contact_phone_no" autofocus>
                              
                              </div>
                        </div>
                      </div>

                      <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12">
                                <div class="form-inputs">
                                     <div class="form-group">
                                        <label>Name<sup>*</sup></label>
                                        <input type="text" class="form-control " name="name" id="name" value="" required autocomplete="name"  autofocus>

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

                        <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12">
                                <div class="form-inputs">
                                     <div class="form-group">
                                        <label>Address<sup>*</sup></label>
                                        <input type="text" class="form-control " id="address" name="address" value="" required autocomplete="address"  autofocus>

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

                              <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12">
                                <div class="form-inputs">
                                     <div class="form-group">
                                        <label>Zipcode<sup>*</sup></label>
                                        <input type="text" class="form-control" id="zipcode" name="zipcode" value="" required autocomplete="zipcode"  autofocus>

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

                              <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12">
                                <div class="form-inputs">
                                     <div class="form-group">
                                        <label>MAF Document<sup>*</sup></label>
                                        <input type="file" class="form-control" id="document" name="document" value="" required autocomplete="zipcode" accept=".docx,.doc,.pdf"  autofocus>

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


              </div>
                  <div class="row">
                     <div class="col-12">
                        <div class="green-button green-button2">
                            <button id="create">Register with Manufacturer</button>
                         </div>
                     </div>
                  </div>
                </form>
          </div>

</div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('scripts'); ?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.23/js/jquery.dataTables.js"></script>
<script type="text/javascript">
jQuery.validator.addMethod("nameval", function(value, element) {
    //test user value with the regex
    return this.optional(element) || /^[a-zA-Z\s]+$/.test(value);
  }, "Enter only Albhabets");
$(".js-example-basic-multiple").select2({
  placeholder: "Select a Manufacturer"
});
</script>

<script>
<?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; ?>
</script>
<script>
$(document).ready(function() {
    $('#example').DataTable();
} );
</script>
<script>
    jQuery.validator.addMethod("noLeadingZeros", function(value, element) {
    return this.optional(element) || /^[1-9]\d*$/.test(value);
}, "Please enter a valid number without leading zeros");

document.getElementById('contact_phone_no').addEventListener('input', function (event) {
            let input = event.target;
            if (input.value.length > 10) {
                input.value = input.value.slice(0, 10);
            }
        });

$("#document").change(function() {

if(this.val!=''){
  $('label[for="document"]').hide();
}
else{

  $('label[for="document"]').show();
}
});



$("#create").click(function(){
    //alert("bbbb");
	$("#buyer_register").validate({
        rules: {
            "email": {
                required: true,
                email:true
            },
            "gst_no": {
                required: true,
               
            },
            "name": {
                required: true,
                nameval:true
            },
            "contact_name": {
                required: true,
                nameval:true
            },
            "contact_phone_no": {
                required: true,
                digits: true,
                noLeadingZeros: true,
            },
            "document": {
                required: true
            },
        },
        submitHandler: function(form, e) {
             $(".pageloader").show();
            $(".pageloader").delay(5000).fadeOut("slow");
		   form.submit();
        }
    });
});
$(function(){
    $('#buyer_register').on('submit', function(event){
        event.preventDefault();

    });
});

</script>
<script>
    $(document).ready(function() {
   $('#gst_no').focusout(function() {
        var gst_no = $('#gst_no').val();
        if($('#gst_no').val() != ""){
                var gst_no = $('#gst_no').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);
                            //alert(res);
                            if(res !== null && res !== ''){
                                if(res.user_type == '1'){
                                    alert('This Gst No is already registered as a buyer.You cannot add as a Manufacturer');
                                }else if(res.user_type == '2'){
                                    alert('This Gst No is already registered as a Vendor.You cannot add as a Manufacturer');
                                }else{
                                    $('#email').val('');
                                    $('#name').val('');
                                    $('#address').val('');
                                    $('#zipcode').val('');
                                    $('#contact_name').val('');
                                    $('#contact_phone_no').val('');
                                    //console.log(res);
                                    var email = res.email;
                                    var name = res.name;
                                    var address = res.address;
                                    var zipcode = res.zipcode;
                                    $('#email').val(email);
                                    $('#name').val(name);
                                    $('#address').val(address);
                                    $('#zipcode').val(zipcode);
                                    $('#contact_name').val(res.contact_name);
                                    $('#contact_phone_no').val(res.contact_phone_no);
                                }

                            }else{
                                //alert(' NULL')
                                 $('#email').val('');
                                $('#name').val('');
                                $('#address').val('');
                                $('#zipcode').val('');
                                $('#contact_name').val('');
                                $('#contact_phone_no').val('');

                                    var APP_URL = <?php echo json_encode(url('/getgstdetails')); ?> ;
                                    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) {
                                            var res = JSON.parse(resultData);
                                            console.log(res);
                                            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;
                                            $('#name').val(name);
                                            $('#address').val(address);
                                            $('#zipcode').val(pncd);
                                        }
                                    });

                            }


                    }
                });
                $(".pageloader").show();
                $(".pageloader").delay(5000).fadeOut("slow");
        }
    });
});
</script>
<?php $__env->stopSection(); ?>

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