<?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">Product Purchasing</h1> -->
            <a href="/supplierpayment">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">Supplier Payments</li>
            </ol>
          </div>
        </div>
      </div>
    </div>
   
    <section class="content">
      <div class="container-fluid">

      <div class="card">
        <div class="card-body">
        <?php $__currentLoopData = $whol; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <table class="table borderless"  border="0">
            <tbody>
                <tr>
                <td class="text-left"><b>Invoice ID - </b>  <?php echo e($data->id); ?></td>
                <td class="text-center"><b>Supplier Name - </b> <?php echo e($data->getsupplier->Sname); ?></td>
                <td class="text-right"><b></td>
                <td class="text-right"></td>
                </tr>
            </tbody>
        </table> 
        <table class="table borderless"  border="0">
            <tbody>
                <tr>
                <td class="text-left"><b>Cost -</b> <?php echo e($data->cost); ?></td>
                <td class="text-center"><b>Amount paid- </b> <?php echo e($data->amountpaid); ?></td>
                <td class="text-right"><b>Balance - </b> <?php echo e($data->cost - $data->amountpaid); ?> </td>
                <td class="text-right"> </td>
                </tr>
            </tbody>
        </table>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </div>
    </div>



      <div class="card">
        <div class="card-body">
          <table id="example" class="table table-bordered" style="width:100%; font-size: 14px;">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Product Name</th>
                    <th>Quantity</th>
                    <th>Unit Price</th>
                    <th>Total</th>
                </tr>
            </thead>
            <tbody>
        <?php $__currentLoopData = $purce; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <tr>
                <td><?php echo e($data->id); ?></td>
                <td><?php echo e($data->getproduct->name); ?></td>
                <td><?php echo e($data->qty); ?></td>
                <td><?php echo e($data->unitprice); ?> &nbsp;&nbsp;
                <?php $__currentLoopData = $whol; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data22): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <?php if($data22->status=="0"): ?>
                <button type="button" class="btn btn-mute btn-xs button" data-purid="<?php echo e($data->purchesid); ?>" data-id="<?php echo e($data->id); ?>" data-uprice="<?php echo e($data->unitprice); ?>" data-toggle="modal" data-target="#unitpricechange"><i class="far fa-edit"></i></button>
                <?php else: ?>
                <?php endif; ?>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </td>                      
                <td><?php echo e($data->unitprice * $data->qty); ?></td>                      
            </tr>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        <?php $__currentLoopData = $whol; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
              <tr>
                <td colspan="4" align="right">Total</td>                      
                <td><?php echo e($data->cost); ?></td>                      
            </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        <?php $__currentLoopData = $paidp; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $pdata): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
             <tr style="color: red;">
                <td colspan="4">
                <?php if($pdata->paymenttype == "cheque" OR $pdata->paymenttype == "credit"): ?>
                <?php if($pdata->status=='0'): ?>
                <button type="button" class="btn btn-primary btn-xs button" data-payid="<?php echo e($pdata->paymentid); ?>" data-paymenttype="<?php echo e($pdata->paymenttype); ?>" data-id="<?php echo e($pdata->id); ?>"  data-bankid="<?php echo e($pdata->bankid); ?>" data-amount="<?php echo e($pdata->amount); ?>"  data-toggle="modal" data-target="#paymentrecive"><i class="fab fa-amazon-pay"></i></button>
                &nbsp;&nbsp;- &nbsp;&nbsp;
                <?php else: ?>
                <?php endif; ?>
                
                <?php echo e($pdata->paymenttype); ?> &nbsp;&nbsp;- &nbsp;&nbsp;<?php echo e($pdata->ccdate); ?>&nbsp;&nbsp;
                -&nbsp;&nbsp; #<?php echo e($pdata->checkno); ?> &nbsp;&nbsp;- &nbsp;&nbsp;
                <?php if($pdata->status=='0'): ?>
                <span class="badge badge-warning"><?php echo e(\Carbon\Carbon::parse( $pdata->ccdate )->diffInDays( $ldate )); ?> days overdue</span>
                
                <?php else: ?>
                <span class="badge badge-success">paid</span>
                <?php endif; ?>
                
                <?php else: ?>
                <?php if($pdata->status=='0'): ?>
                <button type="button" class="btn btn-primary btn-xs button" data-payid="<?php echo e($pdata->paymentid); ?>" data-paymenttype="<?php echo e($pdata->paymenttype); ?>" data-id="<?php echo e($pdata->id); ?>"  data-bankid="<?php echo e($pdata->bankid); ?>" data-amount="<?php echo e($pdata->amount); ?>"  data-toggle="modal" data-target="#paymentrecive"><i class="fab fa-amazon-pay"></i></button>
                &nbsp;&nbsp;- &nbsp;&nbsp;
                <?php else: ?>
                <?php endif; ?>
                
                <?php echo e($pdata->paymenttype); ?> &nbsp;&nbsp;- &nbsp;&nbsp;<?php echo e($pdata->paiddate); ?>&nbsp;&nbsp;- &nbsp;&nbsp;

                <?php if($pdata->status=='0'): ?>
                <span class="badge badge-warning">Not paid</span>
                <?php else: ?>
                <span class="badge badge-success">paid</span>
                <?php endif; ?>


                <?php endif; ?>
                </td>                      
                <td><?php echo e($pdata->amount); ?></td>                      
            </tr>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        <?php $__currentLoopData = $whol; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
              <tr>
                <td colspan="4" align="right">Balance</td>                      
                <td><?php echo e($data->cost - $data->amountpaid); ?></td>                      
            </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

        </tbody>
        </table>
        </div>
      </div>

      <div class="card">
        <div class="card-body">
        <form method="post" action="/supplierreciptprint">
            <?php echo e(csrf_field()); ?>

            <div class="row">
                <div class="col-md-2">
                <?php $__currentLoopData = $whol; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                  <button type="button" class="btn btn-primary btn-block" data-statuss="<?php echo e($data->status); ?>" data-id="<?php echo e($data->id); ?>" data-amountpaid="<?php echo e($data->amountpaid); ?>" data-cdate="<?php echo e($data->ccdate); ?>" data-pdate="<?php echo e($data->paiddate); ?>" data-id="<?php echo e($data->id); ?>" data-supid="<?php echo e($data->wholesaleuserid); ?>" data-payment="<?php echo e($data->paymentmethod); ?>"  data-toggle="modal" data-target="#supmodel">Make Payment</button>
                  <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>
                <div class="col-md-2">
                <?php $__currentLoopData = $whol; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <input type="hidden" name="wholeid" value="<?php echo e($data->id); ?>">
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <button type="submit" formtarget="_blank" name="invoice" value="invoice" class="btn btn-success btn-block">Print Invoices</button>
                </div>
            </div>
            </form>
        </div>
      </div>



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

   <div class="modal fade" id="unitpricechange" 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">Unit Price 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="/unitpricechangesup">
          <?php echo e(csrf_field()); ?>

      <div class="modal-body"> 
          <input type="hidden" name="unitpid" id="unitpid">   
          <input type="hidden" name="purid" id="purid">   

            <div class="form-group">
                <label for="">Unit Price</label>
                <input type="number" class="form-control" id="uprice" name="uprice" placeholder="Amount" 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="paymentrecive" 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">Payment Status 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="/supplierpaymentrecive">
          <?php echo e(csrf_field()); ?>

      <div class="modal-body"> 
          <input type="hidden" name="id" id="id2">   
          <input type="hidden" name="wholeid" id="wholeid">   
          <input type="hidden" name="bank" id="bank2">   
          <input type="hidden" name="amount" id="amount2">   
          <input type="hidden" name="type" id="type2">   
          <?php $__currentLoopData = $whol; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
          <input type="hidden" name="suppliername" id="suppliername" value="<?php echo e($data->getsupplier->Sname); ?>">   
          <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <div class="form-group">
                <label for="">Paid Status</label>
                <div class="form-check">
                    <input class="form-check-input" type="checkbox" name="paidstatus" value="" id="flexCheckChecked">
                    <label class="form-check-label" for="flexCheckChecked">Paid</label>
                </div>
            </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="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">Make Payment</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="/supplierpaymentadd">
          <?php echo e(csrf_field()); ?>

      <div class="modal-body"> 
          <input type="hidden" name="id" id="id">    
          <input type="hidden" name="total" id="total">   
          <div class="form-group">
                <label>Select bank</label>
                <select class="form-control" name="bank" id="bank" style="width: 100%;" required>
                  <?php $__currentLoopData = $bank; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $bankdata): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($bankdata->id); ?>"><?php echo e($bankdata->accountname); ?>-<?php echo e($bankdata->bank); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>

            <div class="form-group">
                <label>Payment Method</label>
                <select class="form-control" name="payment" id="payment2" style="width: 100%;" required>
                    <option value="cash">Cash</option>
                    <option value="bank transfer">Bank Transfer</option>
                    <option value="cheque">Cheque</option>
                    <option value="credit">Credit</option>
                </select>
            </div>
            <div class="form-group">
            <label id="pdate2">Paid Date</label>
                <div class="input-group date" id="reservationdate2" data-target-input="nearest">
                    <input type="text" class="form-control datetimepicker-input" id="paid_date" name="paid_date" data-target="#reservationdate2"/ required>
                    <div class="input-group-append" data-target="#reservationdate2" data-toggle="datetimepicker">
                        <div class="input-group-text"><i class="fa fa-calendar"></i></div>
                    </div>
                </div>
            </div>
            <div class="form-group ChequeNumber">
                <label for="">Cheque Number</label>
                <input type="text" class="form-control" id="Cheque" name="Cheque" value="-" required>
            </div>
            <div class="form-group">
                <!-- <label for="">Paid Amount</label> -->
                <input type="hidden" class="form-control" id="cost" name="cost" placeholder="Paid Amount" required>
            </div>
            <div class="form-group">
                <label for="">Amount</label>
                <input type="number" class="form-control" id="amount" name="amount" placeholder="Amount" 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() {
$('#flexCheckChecked').change(function() {
    if($(this).is(":checked")) {
        $("#pdate2").html("*Paid Date");
    }
    else{
        var valupricw = $('#payment2').val();
        if(valupricw=="cash"){
        $("#pdate2").html("Paid Date");
        }else if(valupricw=="cheque"){
        $("#pdate2").html("Cheque Date");
        }
        else if(valupricw=="credit"){
        $("#pdate2").html("Credit Date");
        } 
    }

});
});



  $(document).ready(function() {
    $('#example').DataTable();
} );
  

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

var button = $(event.relatedTarget) // Button that triggered the modal
var recipient = button.data('id') 
var type = button.data('paymenttype') 
var bank = button.data('bankid') 
var amoun = button.data('amount') 
var payid = button.data('payid') 


var modal = $(this)
modal.find('.modal-body #id2').val(recipient)
modal.find('.modal-body #bank2').val(bank)
modal.find('.modal-body #amount2').val(amoun)
modal.find('.modal-body #type2').val(type)
modal.find('.modal-body #wholeid').val(payid)

})

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

var button = $(event.relatedTarget) // Button that triggered the modal
var recipient = button.data('id') 
var uprice = button.data('uprice') 
var purid = button.data('purid') 

var modal = $(this)
modal.find('.modal-body #unitpid').val(recipient)
modal.find('.modal-body #uprice').val(uprice)
modal.find('.modal-body #purid').val(purid)
})


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

var button = $(event.relatedTarget) // Button that triggered the modal
var recipient = button.data('id') 
var supplier = button.data('supid') 
var product = button.data('proid') 
var qty1 = button.data('qtyss') 
var paymethod = button.data('payment') 
var paiddate = button.data('pdate') 
var cccdate = button.data('cdate') 
var cost1 = button.data('amountpaid') 
var staa = button.data('statuss') 
var bank = button.data('bank') 
var wholename = button.data('wholename') 
var total = button.data('total') 


var modal = $(this)
modal.find('.modal-body #id').val(recipient)
modal.find('.modal-body #Quantity').val(qty1)
modal.find('.modal-body #cost').val(cost1)
modal.find('.modal-body #wholsesalename').val(wholename)
modal.find('.modal-body #total').val(total)
$("#bank").val(bank).change();
$("#supplier_name").val(supplier).change();
$("#product_name").val(product).change();
$("#payment2").val(paymethod).change();

if(paymethod=="cash"){
    modal.find('.modal-body #paid_date').val(paiddate)
    $("#pdate2").html("Paid Date");
}else if(paymethod=="cheque"){
    modal.find('.modal-body #paid_date').val(cccdate)
    $("#pdate2").html("Cheque Date");
}else{
    modal.find('.modal-body #paid_date').val(cccdate)
    $("#pdate2").html("Credit Date");
}
if(staa==1){
    $( "#flexCheckChecked" ).prop( "checked", true );
}else{
    $( "#flexCheckChecked" ).prop( "checked", false  );
}

})

$('#reservationdate').datetimepicker({
format: 'YYYY-MM-DD HH:mm:ss'
});
$('#reservationdate2').datetimepicker({
format: 'YYYY-MM-DD HH:mm:ss'
});

$('.ChequeNumber').hide();

$('#payment2').on('change', function(){
  var id = $(this).val();

  if(id=="cash"){
    $("#pdate2").html("Paid Date");
    $('.ChequeNumber').hide();
}else if(id=="bank transfer"){
  $("#pdate2").html("Paid Date");
  $('.ChequeNumber').hide();
}
else if(id=="cheque"){
  $("#pdate2").html("Cheque Date");
  $('.ChequeNumber').show();
}
else if(id=="credit"){
  $("#pdate2").html("Credit Date");
  $('.ChequeNumber').hide();
}    
});

$('#Quantity').on('input',function(e){
    var dis = $(this).val();
    var n1 = parseInt($('#Unit_Price').val());
    $('#Total').val(dis*n1);
    
});

$('#Unit_Price').on('input',function(e){
    var dis = $(this).val();
    var n1 = parseInt($('#Quantity').val());
    $('#Total').val(dis*n1);
});
  </script>


