<?php $__env->startSection('content'); ?>


<div class="row">
<div class="col-md-2"></div>
  <div class="col-md-8">

      <div class="box box-info">
          <div class="box-header">
            <h3 class="box-title">Compined Waste Report</h3>
          </div>
 
            <form   role="form" method="POST" action="<?php echo e(url('/cwaste/create')); ?>">
                        <?php echo e(csrf_field()); ?>

              <div class="box-body">
              <div class="box-body">
              <div class="col-md-12" style="display: flex;flex-flow: row;justify-content: space-around;" >  
                <div class="form-group col-md-6" >
                    <label for="exampleInputPassword1">Date from  </label>
                    <input type="date" id="sanf_report_from" name="from" class="form-control"  placeholder="Date from " required>
                  </div>



                  <div class="form-group col-md-6">
                    <label for="exampleInputPassword1">Date to</label>
                    <input type="date" id="sanf_report_to"  name="to" class="form-control"    placeholder="Date to " required>
                  </div>
                </div>



                 <div class="form-group">
                  <label>Choose Branch - أختر الفرع </label>
                  <select class="form-control select2 select2-hidden-accessible"  onchange="CgetWastes()"  style="width: 100%;" name="branch_id" id="branch_id" required>
                    <?php foreach( $branches as $branche ): ?> 
                    <option value="<?php echo e($branche->id); ?>"  ><?php echo e($branche->name); ?> </option>
                    <?php endforeach; ?>
                  </select>
                </div>


              <div class="form-group">
                <label class="form-label">اسم الصنف</label>
                    <select class="form-control select2 select2-hidden-accessible"  multiple="multiple"  name="wastes[]"   style="width: 100%;text-align:right"    id="wastes" required>
                    <option value="">اختر اسم الصنف</option>    
                     
                    </select>                           
              </div>

               







              
 
                </div> </div>
              <!-- /.box-body -->

              <div class="box-footer">
                <button type="submit" class="btn btn-warning">Create</button>
              </div>
            </form>

            </div>


</div>
      <!-- /.row -->
</div>
<br/><br/><br/>


<script>



	function CgetWastes() {

	
  const formData = {
            from: $('#sanf_report_from').val(),
            to: $('#sanf_report_to').val(),
            branch_id:$('#branch_id').val()
        };

        console.log(formData);
        

	$.ajax({
            url: 'get_wastes',
            type: 'POST',
            data: formData,
            headers: {
                'X-CSRF-TOKEN': "<?php echo e(csrf_token()); ?>"
            },
            success: function(response) {
                if (response.success) {
                    
                  var sel = $('#wastes').empty();
                  var wastes = response.wastes ;
                  sel.append('<option> Choose Items</option>');
                  for (var i = 0; i < wastes.length; ++i) {
                    sel.append('<option value="' + wastes[i].waste.id + '">' + wastes[i].waste.name + '</option>');			
                  } 
                    
                } else {
                    alert('حدث خطأ أثناء الحفظ: ' + response.message);
                }
            },
            error: function(xhr) {
                alert('حدث خطأ في الاتصال بالخادم');
                console.error(xhr.responseText);
            }
        });
  
		 
	}

	function getClients() {

	
  const formData = {
            from: $('#sanf_report_from').val(),
            to: $('#sanf_report_to').val(),
            items: $('#stores').val()
        };

        

	$.ajax({
            url: 'get_clients',
            type: 'POST',
            data: formData,
            headers: {
                'X-CSRF-TOKEN': "<?php echo e(csrf_token()); ?>"
            },
            success: function(response) {
                if (response.success) {
                    
                  var sel = $('#clients').empty();
                  var clients = response.items ;
                  sel.append('<option> Choose Clients</option>');
                  for (var i = 0; i < clients.length; ++i) {
                    sel.append('<option value="' + clients[i].id + '">' + clients[i].name + '</option>');			
                  } 
                    
                } else {
                    alert('حدث خطأ أثناء الحفظ: ' + response.message);
                }
            },
            error: function(xhr) {
                alert('حدث خطأ في الاتصال بالخادم');
                console.error(xhr.responseText);
            }
        });
  
		 
	}
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.master', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>