<?php echo $__env->make('dashboard.include.header', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

  
  <div class="content-wrapper">
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0"></h1>
            <a href="/supplier">Go Back</a>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="/home">Home</a></li>
              <li class="breadcrumb-item active">Create Supplier</li>
            </ol>
          </div>
        </div>
      </div>
    </div>
   
    <section class="content">
      <div class="container-fluid">
      <!-- <div class="card card-info">
        <div class="card-header">
            <h3 class="card-title">Create Supplier</h3>
        </div>
            <div class="card-body">
            <form class="form-horizontal" method="POST" action="/regsupplier">
                <?php echo e(csrf_field()); ?>

            <div class="row">
                <div class="col-md-3"> 
                    <div class="form-group">
                        <label for="">Name</label><input type="text" class="form-control" name="Name" placeholder="Name" required>
                    </div>
                </div>
                <div class="col-md-2">
                    <div class="form-group">
                        <label for="">Phone Number</label><input type="number" class="form-control" name="Phone_Number" placeholder="Phone Number" required>
                    </div>
                </div>
                <div class="col-md-5"> 
                    <div class="form-group">
                        <label for="">Address</label><input type="text" class="form-control" name="Address" placeholder="Address" required>
                    </div>
                </div>
                <div class="col-md-2" style="padding-top:32px;"><button type="submit" class="btn btn-block btn-primary">Create Supplier</button> </div>
           
            </div> 
            </form>
<hr> <br>
                <div class="row">
                    <div class="col-md-12">
                    <table id="example" class="table table-bordered" style="width:100%">
                        <thead>
                            <tr>
                                <th>Supplier Name</th>
                                <th>Phone Number</th>
                                <th>Address</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                    <?php $__currentLoopData = $item; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td><?php echo e($data->Sname); ?></td>
                            <td><?php echo e($data->Snumber); ?></td>
                            <td class="text-center"><?php echo e($data->Saddress); ?></td>
                            <td class="text-center">
                            <button type="button" class="btn btn-primary btn-xs supmodel" data-id="<?php echo e($data->id); ?>" data-name="<?php echo e($data->Sname); ?>" data-address="<?php echo e($data->Saddress); ?>"  data-number="<?php echo e($data->Snumber); ?>" data-toggle="modal" data-target="#supmodel">Edit</button>
                            <a href="" data-id="<?php echo e($data->id); ?>" class="btn btn-danger btn-xs button deletesupplier" data-url="">Delete </a>
                            <a type="button" class="btn btn-success btn-xs" data-id="<?php echo e($data->id); ?>" href="/supplierdetails/<?php echo e($data->id); ?>">Bank Details</a>
                            </td>                        
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                    </table>
                    
                    </div>
                </div>


            </div>
        </div> -->
        <div class="card card-success">
        <div class="card-header">
            <h3 class="card-title">Add Bank</h3>
        </div>
            <div class="card-body">
            <?php $__currentLoopData = $datas2; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $dadetail): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div class="row">
                <div class="col-md-4"> 
                    <div class="form-group">
                        <label for="">Supplier Name &nbsp;&nbsp;: &nbsp;&nbsp;</label><?php echo e($dadetail->Sname); ?>

                    </div>
                </div>
                <div class="col-md-5"> 
                    <label for="">Address&nbsp;&nbsp; : &nbsp;&nbsp;</label><?php echo e($dadetail->Saddress); ?>

                </div>
                <div class="col-md-3"> 
                    <label for="">Phone Number&nbsp;&nbsp; : &nbsp;&nbsp;</label><?php echo e($dadetail->Snumber); ?>

                </div>
            </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <hr> <br>

            <form class="form-horizontal" method="POST" action="/addbankdetails">
                <?php echo e(csrf_field()); ?>

            <div class="row">
                <div class="col-md-3"> 
                    <div class="form-group">
                    <?php $__currentLoopData = $datas2; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $datad): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><input type="hidden" class="form-control" value="<?php echo e($datad->id); ?>" name="sid" required> <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <label for="">Accont Name</label><input type="text" class="form-control" name="Accont_Name" placeholder="Accont Name" required>
                    </div>
                </div>
                <div class="col-md-2"> 
                    <div class="form-group">
                        <label for="">Bank Name</label><input type="text" class="form-control" name="Bank_Name" placeholder="Bank Name" required>
                    </div>
                </div>
                <div class="col-md-2"> 
                    <div class="form-group">
                        <label for="">Branch</label><input type="text" class="form-control" name="Branch" placeholder="Branch" required>
                    </div>
                </div>
                <div class="col-md-2">
                    <div class="form-group">
                        <label for="">Branch code</label><input type="number" class="form-control" name="Branch_code" placeholder="Branch code" required>
                    </div>
                </div>
                <div class="col-md-2">
                    <div class="form-group">
                        <label for="">Account Number</label><input type="number" class="form-control" name="Account_Number" placeholder="Account Number" required>
                    </div>
                </div>
                <div class="col-md-1" style="padding-top:32px;"><button type="submit" class="btn btn-block btn-primary">Add</button> </div>
           
            </div> 
            </form>
<hr> <br>
            <table id="example2" class="table table-bordered" style="width:100%">
                        <thead>
                            <tr>
                                <th>Account Name</th>
                                <th>Bank Name</th>
                                <th>Branch</th>
                                <th>#Branch</th>
                                <th>Account No</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                    <?php $__currentLoopData = $supdata; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $supdatad): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td><?php echo e($supdatad->Supname); ?></td>
                            <td><?php echo e($supdatad->bankname); ?></td>
                            <td><?php echo e($supdatad->branch); ?></td>
                            <td><?php echo e($supdatad->branchcode); ?></td>
                            <td><?php echo e($supdatad->accountNo); ?></td>
                            <td class="text-center">
                            <button type="button" class="btn btn-primary btn-xs" data-supllierid="<?php echo e($supdatad->Sid); ?>" data-branchcode="<?php echo e($supdatad->branchcode); ?>" data-account="<?php echo e($supdatad->accountNo); ?>" data-id="<?php echo e($supdatad->id); ?>" data-name="<?php echo e($supdatad->Supname); ?>" data-branchname="<?php echo e($supdatad->bankname); ?>"  data-branch="<?php echo e($supdatad->branch); ?>" data-toggle="modal" data-target="#bankmodel">Edit</button>
                                <a href="" data-supllierid="<?php echo e($supdatad->Sid); ?>" data-id="<?php echo e($supdatad->id); ?>" class="btn btn-danger btn-xs button bankdetailsdelete" data-url="">Delete </a>
                            </td>                        
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                    </table>
            </div>
        </div>
      </div>
    </section>
  </div>


  <div class="modal fade" id="supmodel" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
        <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLongTitle">Supplier Details Change</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
            </button>
        </div>
        <form class="form-horizontal" method="POST" action="/supplierupdate">
            <?php echo e(csrf_field()); ?>

        <div class="modal-body"> 
            <input type="hidden" name="id" id="id">    
            <div class="form-group">
                <label for="">Name</label><input type="text" class="form-control" id="Name" name="Name"  required>
            </div>
            <div class="form-group">
                <label for="">Phone Number</label><input type="number" class="form-control" id="Phone_Number" name="Phone_Number"  required>
            </div>
            <div class="form-group">
                <label for="">Address</label><input type="text" class="form-control" id="Address" name="Address" required>
            </div>   

        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            <button type="submit" class="btn btn-primary">Save changes</button>
        </div>
        </form>
        </div>
    </div>
</div>

  <div class="modal fade" id="bankmodel" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered " role="document">
        <div class="modal-content">
        <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLongTitle">Supplier Bank Details Change</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
            </button>
        </div>
        <form class="form-horizontal" method="POST" action="/supplierbankupdate">
            <?php echo e(csrf_field()); ?>

        <div class="modal-body">  
            <input type="hidden" name="id" id="id">    
            <input type="hidden" name="supid" id="supid">    
            <div class="form-group">
                <label for="">Accont Name</label><input type="text" class="form-control" name="Accont_Name" id="Accont_Name" placeholder="Accont Name" required>
            </div>
            <div class="form-group">
                <label for="">Bank Name</label><input type="text" class="form-control" name="Bank_Name" id="Bank_Name" placeholder="Bank Name" required>
            </div>
            <div class="form-group">
                <label for="">Branch</label><input type="text" class="form-control" name="Branch" id="Branch" placeholder="Branch" required>
            </div>
            <div class="form-group">
                <label for="">Branch code</label><input type="number" class="form-control" id="Branch_code" name="Branch_code" placeholder="Branch code" required>
            </div>
            <div class="form-group">
                <label for="">Account Number</label><input type="number" class="form-control" id="Account_Number" name="Account_Number" placeholder="Account Number" required>
            </div> 

        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            <button type="submit" class="btn btn-primary">Save changes</button>
        </div>
        </form>
        </div>
    </div>
</div>


  <?php echo $__env->make('dashboard.include.footer', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>;

<script>
$(document).ready(function() {
    $('#example').DataTable();
    $('#example2').DataTable();
} );
</script>
<script>
$(document).on('click', '.deletesupplier', function (e) {
    e.preventDefault();
    var id = $(this).data('id');
    let ele = this;
    console.log(id);

                swal({
                title: "Are you sure?",
                text: "Are you Sure to Remove Supplier",
                icon: "warning",
                showCancelButton: true,
    confirmButtonColor: '#3085d6',
    cancelButtonColor: '#d33',
    confirmButtonText: 'Yes, delete it!',
                dangerMode: true,
            }).then(function(isConfirm) {
                
                if (isConfirm.value===true) {

                        $.ajax({
                            url: "<?php echo e(url('/deletesup')); ?>/"+id ,
                            method: "POST",
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            },
                            cache: false,
                            contentType: false,
                            processData: false,
                            dataType: 'JSON',
                            data:{
                                "id":id
                            },
                            success: function (result, code, ex) {
                                // swal("Done!", "It was successfully deleted!", "success");
                                // $(ele).closest('tr').hide();
                                // $("#here").load(location.href + " #here");
                                window.location.href = "/supplier";
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                swal("Warning", "Unable to Process your request", "error");
                            },
                        });

                } else {
                    swal("Cancelled", "No Removed", "error");
                }
            })
});


$(document).on('click', '.bankdetailsdelete', function (e) {
    e.preventDefault();
    var id = $(this).data('id');
    var supid = $(this).data('supllierid');
    let ele = this;
    console.log(id);

                swal({
                title: "Are you sure?",
                text: "Are you Sure to Remove this Bank Account",
                icon: "warning",
                showCancelButton: true,
    confirmButtonColor: '#3085d6',
    cancelButtonColor: '#d33',
    confirmButtonText: 'Yes, delete it!',
                dangerMode: true,
            }).then(function(isConfirm) {
                
                if (isConfirm.value===true) {

                        $.ajax({
                            url: "<?php echo e(url('/deletebankdetails')); ?>/"+id ,
                            method: "POST",
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            },
                            cache: false,
                            contentType: false,
                            processData: false,
                            dataType: 'JSON',
                            data:{
                                "id":id
                            },
                            success: function (result, code, ex) {
                                // swal("Done!", "It was successfully deleted!", "success");
                                // $(ele).closest('tr').hide();
                                // $("#here").load(location.href + " #here");
                                window.location.href = "/supplierdetails/"+supid;
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                swal("Warning", "Unable to Process your request", "error");
                            },
                        });

                } else {
                    swal("Cancelled", "No Removed", "error");
                }
            })
});





$('#supmodel').on('show.bs.modal', function (event) {

var button = $(event.relatedTarget) // Button that triggered the modal
var recipient = button.data('id') 
var name = button.data('name') 
var address = button.data('address') 
var number = button.data('number') 

var modal = $(this)
modal.find('.modal-body #id').val(recipient)
modal.find('.modal-body #Name').val(name)
modal.find('.modal-body #Phone_Number').val(number)
modal.find('.modal-body #Address').val(address)
})

      
$('#bankmodel').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var supid = button.data('supllierid') 
var id = button.data('id') 
var Bcode1 = button.data('branchcode') 
var account = button.data('account') 
var name = button.data('name') 
var branchname = button.data('branchname') 
var branch = button.data('branch') 


var modal = $(this)
modal.find('.modal-body #id').val(id)
modal.find('.modal-body #supid').val(supid)
modal.find('.modal-body #Accont_Name').val(name)
modal.find('.modal-body #Bank_Name').val(branchname)
modal.find('.modal-body #Branch_code').val(Bcode1)
modal.find('.modal-body #Account_Number').val(account)
modal.find('.modal-body #Branch').val(branch)

})
// Accont_Name Bank_Name Branch Branch_code Account_Number
</script>