@include('dashboard.include.header')

  
  <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">Products</h1>
          </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">Products</li>
            </ol>
          </div>
        </div>
      </div>
    </div>
   
    <section class="content">
      <div class="container-fluid">
      <div class="card">
        <div class="card-body">
          <div class="row">
            <div class="col-md-12">
            <table id="example1" class="table table-bordered" style="width:100%">
                <thead>
                    <tr>
                        <th>Id</th>
                        <th>Product Name</th>
                        <th>Reseller Sell Price</th>
                        <th>Dropshipping Price</th>
                        <th>Stock</th>
                        <th>Weight (KG)</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                @foreach($product as $data)
                @foreach($getstock as $sdata)
                @if($sdata->id == $data->pro_id AND $sdata->seller == "yes")
                    <tr>
                        <td>{{$data->id}}</td>
                        <td>{{$data->pro_name}}</td>
                        <td>{{$data->sell_price}}</td>
                        <td>{{$data->cost}}</td>                
                        <td>
                        @foreach($getstock as $sdata)
                            @if($sdata->id == $data->pro_id)
                            {{ $sdata->stock }}
                            @break;
                            @endif
                        @endforeach
                        </td>           
                        <td>{{$data->weight}}</td>     
                        <td class="text-center"> 
                        <button type="button" data-id="{{$data->id}}'" data-price="{{$data->sell_price}}"  class="btn btn-warning btn-xs" data-toggle="modal" data-target="#editordermodelphone">Edit</button>                          
                            <a data-id="{{$data->id}}" class="btn btn-primary btn-xs" target="_blank" href="productdescription/{{$data->pro_id}}">View Details</a>
                        </td>      
              
                    </tr>
                    @endif
                @endforeach 
                @endforeach 
                </tbody>
                <tfoot>
                    <tr>
                        <th>Id</th>
                        <th>Product Name</th>
                        <th>Reseller Sell Price</th>
                        <th>Dropshipping Price</th>
                        <th>Stock</th>
                        <th>Weight (KG)</th>
                        <th>Action</th>
                    </tr>
                </tfoot>
            </table>
            
            </div>
          </div>
          </div>
        </div>
      </div>
    </section>
  </div>
 

<div class="modal fade" id="editordermodelphone" role="dialog">
        <div class="modal-dialog">
        
          <!-- Modal content-->
          <div class="modal-content">
            <div class="modal-header">
                    <h4 class="modal-title">Sell Price Update</h4>
              <button type="button" class="close" data-dismiss="modal">&times;</button>
              
            </div>
            
            <form method="post" enctype="multipart/form-data" id="myform">
            {{csrf_field()}}
                <div class="modal-body">
                <input type="hidden" id="id" name="id">

               <div class="form-group">
                    <label>Sell Price :</label>
                    <input type="number" class="form-control" name="price" id="price">
                </div> 

                    
                </div>
                  
            <div class="modal-footer">
            <input type="submit" name="btnform1" id="action" class="btn btn-primary right" value="Submit"/>
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
            </form>
          </div>
          
        </div>

</div>

  @include('dashboard.include.footer');

<script>
$('#editordermodelphone').on('show.bs.modal', function (event) {

var button = $(event.relatedTarget) // Button that triggered the modal

var id = button.data('id') 
var price = button.data('price') 

var modal = $(this)
//   modal.find('.modal-title').text('New message to ' + recipient)
modal.find('.modal-body #id').val(id)
modal.find('.modal-body #price').val(price)

})


$('#myform').on('submit', function(event){
    let ele = this;
        event.preventDefault();
        var form_data = $(this).serialize();
        $.ajax({
            url:"/resellersellup",
            method:"POST",
            data:form_data,
            dataType:"json",      
            success: function (result, code, ex) {
                // swal("Done!", "It was successfully!", "success");
                $("#editordermodelphone").modal('hide');  
                location.reload();
            },
            error: function (jqXHR, textStatus, errorThrown) {
                swal("Warning", "Unable to Process your request", "error");
            },
            
        })
    });



$(function () {
    $("#example1").DataTable({
      "responsive": true, "lengthChange": true, "autoWidth": false,"order": [[ 0, "asc" ]],
      "buttons": [ "colvis", "excel"]
    }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');
  });
</script>

