<?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">Add Product</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">Add Product</li>
            </ol>
          </div>
        </div>
      </div>
    </div>
   
    <section class="content">
      <div class="container-fluid">
      <div class="card">
        <div class="card-body">
        <?php $__currentLoopData = $custd; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $custdata): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
          <div class="row">
          <div class="col-md-4"><label for="">Name&nbsp;&nbsp;: &nbsp;&nbsp;</label><?php echo e($custdata->name); ?></div>
          <div class="col-md-5"><label for="">Address&nbsp;&nbsp;: &nbsp;&nbsp;</label><?php echo e($custdata->address); ?></div>
          <div class="col-md-3"><label for="">Phone Number&nbsp;&nbsp;: &nbsp;&nbsp;</label><?php echo e($custdata->phone); ?></div>

          </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> 
          <br><hr>
          <div class="row">
          <div class="col-md-9"></div>
          <div class="col-md-3" align="right">
          <a class="btn btn-warning btn-xs" onclick="printDiv('printableArea')" ><i class="fas fa-print"></i>&nbsp;Print invoice</a>    
          <button type="button" class="btn btn-sm btn-success btn-xs" data-toggle="modal" data-target="#exampleModalCenter">Add items</button></div>
          </div> <br>
          <div class="row">
            <div class="col-md-12">
 

               
                <div class="here" name="here" id="here">
            <table class="table" id="book-table">
                    <thead>
                          <tr>
                            <th style="width:60px" class="text-center">QTY</th>
                            <th class="text-left">DESCRIPTION</th>
                            <th style="width:140px" class="text-right">UNIT PRICE</th>
                            <th style="width:90px" class="text-right">TOTAL</th>
                            <th style="width:90px" class="text-right"></th>
                            <th style="width:90px" class="text-right"></th>
                          </tr>
                    </thead>
                    <tbody>
                    <?php $__currentLoopData = $item2; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        
                    <tr>
                        <td class="text-center"><?php echo e($data->qty); ?></td>
     
                        <td><?php echo e($data->orders->name); ?>

                        <?php if($data->attribute=="null" or $data->attribute==""): ?>
                        <?php else: ?>
                            <?php $__currentLoopData = json_decode($data->attribute); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $val): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                (<?php echo e($key); ?>:<?php echo e($val); ?>)
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <?php endif; ?>
                            </td>
                        <td class="text-right"><?php echo e($data->pro_amount); ?></td>
                        <td class="text-right">
                        <?php echo e($data->qty * $data->pro_amount); ?>

                        </td>
                        <td class="text-right">
                                <button type="button" class="btn btn-primary btn-xs btn-edit" data-proprice="<?php echo e($data->pro_amount); ?>" data-cid="<?php echo e($data->customerorders->id); ?>" data-id="<?php echo e($data->id); ?>" data-delivery="<?php echo e($data->delivery); ?>" data-proname="<?php echo e($data->item_id); ?>" data-qty="<?php echo e($data->qty); ?>" data-toggle="modal" data-target="#editordermodel">Edit</button>
                        </td>
                        <td class="text-right">                
                            <a href="" data-id="<?php echo e($data->id); ?>" class="btn btn-danger btn-xs button" data-url="">Delete </a>
                        </td>
                    </tr>

                    
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> 
                        
                            <tr>
                            <td colspan="2" rowspan="4">
                            
                            <td class="text-right"><strong>Delivery Charge</strong></td>
                            <td class="text-right"><?php echo e($deli); ?></td>
                            <td></td>
                            <td class="text-right">
                                <button type="button" class="btn btn-primary btn-xs btn-edit" data-id="<?php echo e($cus_id); ?>" data-delivery="<?php echo e($deli); ?>"  data-toggle="modal" data-target="#deliverymodel">Delivery</button>
                            </td>
                        </tr> 
                        <tr>
                            <td class="text-right no-border">
                            <strong>Total</strong>
                            </td>
                            <td class="text-right"><strong><?php echo e($tot + $deli); ?></strong></td>
                        </tr>
                       
                    </tbody>
                </table>
                </div>
                


                <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
                    <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
                        <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="exampleModalLongTitle">Add Items</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <form method="post" action="/addcustomerItems">
                          <?php echo e(csrf_field()); ?>

                        <div class="modal-body">

                            <div class="form-group row">
                                <label for="" class="col-sm-2 col-form-label">Product Name</label>
                                <div class="col-sm-10">
                                <select class="form-control select2" name="nameproduct"  id="nameproduct">
                                    <option selected disabled>Product Name</option>
                                    <?php $__currentLoopData = $item; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($data->id); ?>"><?php echo e($data->name); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> 
                                </select>
                                <script>
                                   $(document).ready(function() {
                                        $('.select2').select2({
                                            dropdownParent: $('#exampleModalCenter')
                                        });
                                    });
                                </script>

                                </div>
                            </div>
                            <div class="applenddata">

                            </div>
                            <div class="form-group row">
                                <label for="" class="col-sm-2 col-form-label">Product Price</label>
                                <div class="col-sm-10">
                                <input type="number" class="form-control" name="product_price" id="product_price" value="0" required>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="" class="col-sm-2 col-form-label">Quantity</label>
                                <div class="col-sm-10">
                                <input type="number" class="form-control" id="quantity" name="quantity" placeholder="Quantity" required>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal" onclick="Reset();">Close</button>
                            <button type="submit" class="btn btn-primary">Save changes</button>
                        </div>
                        </form>
                        </div>
                    </div>
                    </div>
                    <div class="modal fade" id="editordermodel" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
                    <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
                        <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="exampleModalLongTitle">Update Items</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <form method="post" action="/updateitem">
                          <?php echo e(csrf_field()); ?>

                        <div class="modal-body">
                        <div class="form-group row">
                                <label for="" class="col-sm-2 col-form-label">Product Name</label>
                                <div class="col-sm-10">
                                <div class="id_100">
                                <select class="js-example-basic-single" id="nameproduct2" name="nameproduct2">
                                    <!-- <option selected disabled>Product Name</option> -->
                                    <?php $__currentLoopData = $item; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($data->id); ?>"><?php echo e($data->name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> 
                                </select>
                                </div>
                                <script>
                                   $(document).ready(function() {
                                        $('.js-example-basic-single').select2({
                                        dropdownParent: $('#editordermodel')
                                    });
                                    });
                                </script>

                                </div>
                            </div>
                            <div class="applenddata2">

                            </div>
                            <div class="form-group row">
                                <label for="" class="col-sm-2 col-form-label">Product Price</label>
                                <div class="col-sm-10">
                                <input type="number" class="form-control" name="product_price" id="product_price" value="0" required>
                                </div>
                            </div>
                            <input type="hidden" class="form-control" id="id" name="id" placeholder="Quantity" required>
                            <input type="hidden" class="form-control" id="cusid" name="cusid" placeholder="Quantity" required>

                            <div class="form-group row">
                                <label for="" class="col-sm-2 col-form-label">Quantity</label>
                                <div class="col-sm-10">
                                <input type="number" class="form-control" id="quantity" name="quantity" placeholder="Quantity" required>
                                </div>
                            </div>
                            <!-- <div class="form-group row">
                                <label for="" class="col-sm-2 col-form-label">Delivery Charge</label>
                                <div class="col-sm-10">
                                <input type="number" class="form-control" id="Delivery" name="Delivery" placeholder="Delivery Charge" required>
                                </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="deliverymodel" 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">Update Delivery Charge</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <form method="post" id="deliveryupdateform">
                          <?php echo e(csrf_field()); ?>

                        <div class="modal-body">
                            <div class="form-group">
                                <input type="hidden" class="form-control" id="id" name="id" placeholder="" required>
                                <label for="">Delivery Charge</label><input type="number" class="form-control" id="Delivery" name="Delivery" placeholder="Delivery Charge" 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>
          </div>
          </div>
        </div>

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

















  <?php echo $__env->make('dashboard.include.footer', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>;
  <script>
function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

     document.body.innerHTML = printContents;

     window.print();

     document.body.innerHTML = originalContents;
}
</script>


<script>


$(document).on('click', '.btn-danger', 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 Order Item",
                            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('/deleteitem')); ?>/"+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");
                                            location.reload();
                                        },
                                        error: function (jqXHR, textStatus, errorThrown) {
                                            swal("Warning", "Unable to Process your request", "error");
                                        },
                                    });

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



<?php if(session('success')): ?>
        //swal("Success!","<?php echo e(session('success')); ?>","success");

Swal.fire({
  
  type: 'success',
  title: 'Your work has been saved',
  text: "<?php echo e(session('success')); ?>",
  showConfirmButton: false,
  timer: 1500
});


<?php endif; ?>
<?php if(session('error')): ?>
    swal({
            title: "Error!",
            text: "<?php echo e(session('error')); ?>",
            icon: "error",
            button: "OK",
        });
<?php endif; ?>

</script>


<script type="text/javascript">
    function Reset() {
    $("#nameproduct").val(1).change();
    }

    
</script>


<script>
$('#editordermodel').on('show.bs.modal', function (event) {
     
  var button = $(event.relatedTarget) // Button that triggered the modal
  var recipient = button.data('delivery') 
  var proname = button.data('proname') 
  var qty = button.data('qty') 
  var id = button.data('id') 
  var cid = button.data('cid') 
  var proprice = button.data('proprice') 
  
  var modal = $(this)
//   modal.find('.modal-title').text('New message to ' + recipient)
  modal.find('.modal-body #Delivery').val(recipient)
//   modal.find('.modal-body #nameproduct').val(proname)
  modal.find('.modal-body #quantity').val(qty)
  modal.find('.modal-body #id').val(id)
  modal.find('.modal-body #cusid').val(cid)
  modal.find('.modal-body #product_price').val(proprice)

    $("#nameproduct2").val(proname).change();
})

$('#deliverymodel').on('show.bs.modal', function (event) {
     var button = $(event.relatedTarget) // Button that triggered the modal
     var recipient = button.data('delivery') 
     var id = button.data('id') 
     var modal = $(this)
     modal.find('.modal-body #Delivery').val(recipient)
     modal.find('.modal-body #id').val(id)
   })
</script>


    <script type="text/javascript">
    jQuery(document).ready(function ()
    {
            jQuery('select[name="nameproduct"]').on('change',function(){
               var countryID = jQuery(this).val();

    $.ajax({
            url: "<?php echo e(url('/getproductprice')); ?>/"+countryID ,
            method: "get",
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            cache: false,
            contentType: false,
            processData: false,
            dataType: 'JSON',
            data:{
                "id":countryID
            },
            success: function (data) {
                // swal("Done!", "It was successfully deleted!", "success");

                    jQuery.each(data, function(key,value){
                        for(i=0; i<value.length; i++){
                            var rid = value[i].id;
                            $('#product_price').val(value[i].sell_price);

                        }

                    });

            },
            error: function (jqXHR, textStatus, errorThrown) {
                swal("Warning", "Unable to Process your request", "error");
            },
        });


               if(countryID)
               {
                  jQuery.ajax({
                     url : 'dropdownlist/getstates/' +countryID,
                     type : "GET",
                     dataType : "json",
                     success:function(data)
                     {
                        // console.log(data);
                        $('.att-group').remove()
                        
                        jQuery.each(data, function(key,value){
                            

                          $('.applenddata').append('<div class="form-group row att-group"><label for="'+value.attname+'" class="col-sm-2 col-form-label">Select '+value.attname+'</label><div class="col-sm-10"><select class="form-control" id="'+value.attname+'" name="product_properties['+value.attname+']" ></select></div></div>')


                        //   $('.applenddata').append('<div class="form-group att-group"><label for="'+value.attname+'">Select '+value.attname+':</label><select id="'+value.attname+'" name="product_properties['+value.attname+']" class="form-control"style="width:250px"></select></div>')
                          word = value.attributes;

                          result = word.split(","); 
                          // console.log(result);
                          var i;
                          for (i = 0; i < result.length; i++) { 
                            $('#'+value.attname).append('<option value="'+ result[i] +'">'+ result[i] +'</option>');
                          }

                           
                        });
                     }
                  });
               }
               else
               {
                  $('select[name="nameproduct"]').empty();
               }
            });
    });
    </script>


        <script type="text/javascript">
    jQuery(document).ready(function ()
    {
            jQuery('select[name="nameproduct2"]').on('change',function(){
               var countryID = jQuery(this).val();
               if(countryID)
               {
                  jQuery.ajax({
                     url : 'dropdownlist/getstates2/' +countryID,
                     type : "GET",
                     dataType : "json",
                     success:function(data)
                     {
                        // console.log(data);
                        $('.att-group').remove()
                        
                        jQuery.each(data, function(key,value){
                            

                          $('.applenddata2').append('<div class="form-group row att-group"><label for="'+value.attname+'" class="col-sm-2 col-form-label">Select '+value.attname+'</label><div class="col-sm-10"><select class="form-control" id="'+value.attname+'" name="product_properties['+value.attname+']" ></select></div></div>')


                        //   $('.applenddata').append('<div class="form-group att-group"><label for="'+value.attname+'">Select '+value.attname+':</label><select id="'+value.attname+'" name="product_properties['+value.attname+']" class="form-control"style="width:250px"></select></div>')
                          word = value.attributes;

                          result = word.split(","); 
                          // console.log(result);
                          var i;
                          for (i = 0; i < result.length; i++) { 
                            $('#'+value.attname).append('<option value="'+ result[i] +'">'+ result[i] +'</option>');
                          }

                           
                        });
                     }
                  });
               }
               else
               {
                  $('select[name="nameproduct2"]').empty();
               }
            });
    });


    $('#deliveryupdateform').on('submit', function(event){
    let ele = this;
        event.preventDefault();
        var form_data = $(this).serialize();
        $.ajax({
            url:"/deliveryupdateview",
            method:"POST",
            data:form_data,
            dataType:"json",      
            success: function (result, code, ex) {
                // swal("Done!", "It was successfully!", "success");
                $("#deliverymodel").modal('hide');  
                $("#here").load(location.href + " #here");
   
                toastr.success('Delivery Charges Added successfully!')

            },
            error: function (jqXHR, textStatus, errorThrown) {
                swal("Warning", "Unable to Process your request", "error");
            },
            
        })
    });
    </script>

    <div id="printableArea" style="display: none;">
    <?php $__currentLoopData = $custd; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
  
  <div class="row">
    <div class="col-md-6"><h1> Invoice Number : <?php echo DNS1D::getBarcodeSVG($data->id, 'C128',3,33); ?> 
    </h1>
    <p style="margin: -2mm 0mm 0mm 90mm;font-size:12px"><?php echo e($data->id); ?></p>
    </div>
    <div class="col-md-6" align="right"><img src="<?php echo e(url('uploads/'.$data->getpage2->image)); ?>" style="height:111px"  alt="logo"></div>
</div>
    <div class="row">
        <div class="col-md-6">
        <h5>Issued Date : <?php echo e($ldate); ?></h5>
        <h5>Customer Name : <?php echo e($data->name); ?></h5>
        <h5>Address : <?php echo e($data->address); ?></h5>
        <h5>Phone Number : <?php echo e($data->phone); ?> / <?php echo e($data->secondaryphone); ?></h5>
        </div>  
        <div class="col-md-6" align="right">
            <h5>Vibrant Technologies</h5>
            <h5><?php echo e($data->getpage2->address); ?></h5>
            <h5><?php echo e($data->getpage2->number); ?></h5>
            <h5>support@dailydeals.com</h5>
        </div>    
    </div>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
<br><br>

    <table class="table" id="book-table" name="book-table">
            <thead>
                  <tr>
                    <th style="width:60px" class="text-center">QTY</th>
                    <th class="text-left">DESCRIPTION</th>
                    <th style="width:140px" class="text-right">UNIT PRICE</th>
                    <th style="width:90px" class="text-right">TOTAL</th>
   
                  </tr>
            </thead>
            <tbody>
                    
            <?php $__currentLoopData = $item2; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> 
                    <tr>
                        <td class="text-center"><?php echo e($data->qty); ?></td>
                        <td><?php echo e($data->orders->name); ?>

                        <?php if($data->attribute=="null" or $data->attribute==""): ?>
                        <?php else: ?>
                            <?php $__currentLoopData = json_decode($data->attribute); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $val): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                (<?php echo e($key); ?>:<?php echo e($val); ?>)
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <?php endif; ?>
                        </td>
                        <td class="text-right"><?php echo e($data->pro_amount); ?></td>
                        <td class="text-right"><?php echo e($data->qty * $data->pro_amount); ?>

                        </td>
                        <input type="hidden" value="">
                    </tr>
                    
            
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                            <td colspan="2" rowspan="4">
                             
                              <td class="text-right"><strong>Delivery Charge</strong></td>
                              <td class="text-right"><?php echo e($deli); ?></td>
                          </tr>

                          <tr>
                            <td class="text-right no-border">
                              <strong>Total</strong>
                            </td>
                            <td class="text-right"><strong><?php echo e($deli + $tot); ?></strong></td>
                          </tr>
            </tbody>
        </table>  
        <br>
        <br>
        <br>
      </div>