<?php $__env->startSection('content_header'); ?>
    <?php echo notifyCss(); ?>
    <?php echo notifyJs(); ?>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
    <div class="row">
      <div class="col-12">
        <div class="card card-primary">
          <div class="card-header">
              <h3 class="card-title">Training Schedule</h3>
          </div>
          <?php echo $__env->make('notify::messages', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
          <!-- /.card-header -->
          <div class="card-body">
            <ul class="nav nav-tabs">
                <li class="nav-item"><a class="nav-link active" data-toggle="pill" href="#organisation_form"><b>Add Training Schedule</b></a></li>
                <li class="nav-item"><a class="nav-link" data-toggle="pill" href="#listorgdata"><b>View Training Schedule</b></a></li>
            </ul>
            <div class="tab-content">
              <div id="organisation_form" class="tab-pane fade active show">
                <!-- form start -->
                <form id="userregform" class="form-horizontal" action="<?php echo e(URL::to('/schedule_post')); ?>" method="post" autocomplete="off" enctype="multipart/form-data">
                    <?php echo e(csrf_field()); ?>

                    <div class="card-body">
                        <div class="col-12">
                            <div class="form-group row">
                                <div class="col-3">
                                    <label for="exampleInputEmail1">Organisation</label>
                                    <select name="organisation_id" id="organisation_id" class="form-control" required onchange="load_department(this.value);load_material_type(this.value);">
                                        <option value="">Select Organisation</option>
                                        <?php $__currentLoopData = $organisations; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $organisation): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($organisation->id); ?>"><?php echo e($organisation->organisation_name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                                <div class="col-3">
                                    <label for="exampleInputEmail1">Department</label>
                                    <select name="department_id" id="department_id" class="form-control" onchange="load_section(this.value)">
                                        <option value="">Select Department</option>
                                    </select>
                                </div>
                                <div class="col-3">
                                    <label for="exampleInputEmail1">Section</label>
                                    <select name="section_id" id="section_id" class="form-control">
                                        <option value="">Select Section</option>
                                    </select>
                                </div>
                                <div class="col-3">
                                    <label for="exampleInputEmail1">Material Type</label>
                                    <select name="material_type_id" id="material_type_id" class="form-control" required>
                                        <option value=""> Select Material Type</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-3">
                                    <label for="exampleInputEmail1">Roles</label>
                                    <select name="role_id[]" id="role_id" class="form-control" required multiple="multiple" data-placeholder="Select Roles">
                                        <?php $__currentLoopData = $roles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $role): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($role->id); ?>"><?php echo e($role->name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                                <div class="col-3">
                                    <label for="exampleInputEmail1">Training Title</label>
                                    <input type="text" name="training_title" id="training_title" class="form-control" required placeholder="Enter Training Title">
                                </div>
                                <div class="col-3">
                                    <label for="exampleInputEmail1">Venue</label>
                                    <input type="text" name="venue" id="venue" class="form-control" required placeholder="Enter venue">
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-3">
                                    <label for="exampleInputEmail1">Period From</label>
                                    <input type="date" name="period_from" id="period_from" class="form-control" required min="1930-01-01" onblur="checkDates(this,document.getElementById('period_to'))">
                                </div>
                                <div class="col-3">
                                    <label for="exampleInputEmail1">Period To</label>
                                    <input type="date" name="period_to" id="period_to" class="form-control" required min="1930-01-01" onblur="checkDates(document.getElementById('period_from'),this)">
                                </div>
                                <div class="col-3">
                                    <label for="exampleInputEmail1">Minimum Seats Needed for Training</label>
                                    <input type="text" name="min_seat_training" id="min_seat_training" class="form-control" placeholder="Enter Minimum Seats Needed for Training" maxlength="4">
                                </div>
                                <div class="col-3">
                                    <label for="exampleInputEmail1">Maximum Seats Possible for Training</label>
                                    <input type="text" name="max_seat_training" id="max_seat_training" class="form-control" placeholder="Enter Maximum Seats Needed for Training" maxlength="4">
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-3">
                                    <label for="exampleInputEmail1">Whether Registration is Needed?</label><br>
                                    <input type="checkbox" checked="checked" name="registration_status" id="registration_status" data-toggle="toggle" data-on="Yes" data-off="No" data-onstyle="success" data-offstyle="danger" data-size="small" data-style="ios" value="1">
                                </div>
                                <div class="col-3">
                                    <label for="exampleInputEmail1">Question and Answers for Training</label><br>
                                    <input type="checkbox" checked="checked" name="question_answer_status" id="question_answer_status" data-toggle="toggle" data-on="Yes" data-off="No" data-onstyle="success" data-offstyle="danger" data-size="small" data-style="ios" value="1">
                                </div>
                                <div class="col-3">
                                    <label for="exampleInputEmail1">Reviews and Feedback Needed?</label><br>
                                    <input type="checkbox" checked="checked" name="review_status" id="review_status" data-toggle="toggle" data-on="Yes" data-off="No" data-onstyle="success" data-offstyle="danger" data-size="small" data-style="ios" value="1">
                                </div>
                                <div class="col-3">
                                    <label for="exampleInputEmail1">Training Certificates Needed?</label><br>
                                    <input type="checkbox" checked="checked" name="certificate_status" id="certificate_status" data-toggle="toggle" data-on="Yes" data-off="No" data-onstyle="success" data-offstyle="danger" data-size="small" data-style="ios" value="1">
                                </div>
                            </div>
                            <div class="form-group row">                                   
                                <div class="col-3">
                                    <label for="exampleInputEmail1">Training Fees</label>
                                    <input type="text" name="training_fees" id="training_fees" class="form-control floating" placeholder="EnterTraining Fees" required>
                                </div>
                                <div class="col-3">
                                    <label for="exampleInputEmail1">Training Allowance</label>
                                    <input type="text" name="training_allowance" id="training_allowance" class="form-control floating" placeholder="Enter Training Allowance" required>
                                </div>
                                <div class="col-3">
                                    <label for="exampleInputEmail1">Remarks</label>
                                    <textarea name="remarks" id="remarks" class="form-control" required></textarea>
                                </div>
                            </div>                                
                        </div>
                    </div>
                    <!-- /.card-body -->

                    <div class="card-footer">
                      <button type="submit" class="btn btn-primary">Submit</button>
                    </div>
                </form>
              </div>
              <div id="listorgdata" class="tab-pane fade" style="padding: 10px;">
                <table class="table table-hover table-bordered table-striped datatable" id="dept_details" width="100%">
                    <thead>
                        <tr>
                          <th>Slno</th>
                          <th>Organisation</th>
                          <th>Roles</th>
                          <th>Training Title</th>
                          <th>Training Period</th>
                          <th>Actions</th>
                        </tr>
                    </thead>
                </table>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#role_id").select2({
                columns: 1,
                placeholder : "Select Roles",
                allowClear: true,
                search: true,
                selectAll: true
            });
        });
        $(document).ready(function () 
        {
            $('#dept_details').DataTable({
                "buttons" : ['excelHtml5', 'excel', 'pdf', 'print', 'reset', 'reload'],
                "processing": true,
                "serverSide": true,
                "ajax":{

                         "url": "<?php echo e(url('get_schedule_details')); ?>",
                         "dataType": "json",
                         "type": "POST",
                         "data":{ _token: "<?php echo e(csrf_token()); ?>"}
                       },
                "columns": [
                    { "data": "DT_RowIndex" },
                    { "data": "org_name" },
                    { "data": "roles" },
                    { "data": "title" },
                    { "data": "training_period"},
                    { "data": "action" }
                ], 
                
                "order": [[1, 'asc']]
            });      
        });
        function load_department(organisation_id)
        {
            $.ajax({
               type:'GET',
               url: "<?php echo url('get_department/"+organisation_id+"'); ?>",
               success:function(data)
               {
                  $('#department_id').empty();
                  $('#department_id').append("<option value=''>Select Department</option>");
                  $.each(data, function(key, element) {
                      $('#department_id').append("<option value='" + key +"'>" + element + "</option>");
                  }); 
               }
            });
        }
        function load_section(department_id)
        {
            $.ajax({
               type:'GET',
               url: "<?php echo url('get_section/"+department_id+"'); ?>",
               success:function(data)
               {
                  $('#section_id').empty();
                  $('#section_id').append("<option value=''>Select Section</option>");
                  $.each(data, function(key, element) {
                      $('#section_id').append("<option value='" + key +"'>" + element + "</option>");
                  }); 
               }
            });
        }
        function load_material_type(organisation_id)
        {
            $.ajax({
               type:'GET',
               url: "<?php echo url('get_materialtype/"+organisation_id+"'); ?>",
               success:function(data)
               {
                  $('#material_type_id').empty();
                  $('#material_type_id').append("<option value=''>Select Material Type</option>");
                  $.each(data, function(key, element) {
                      $('#material_type_id').append("<option value='" + key +"'>" + element + "</option>");
                  }); 
               }
            });
        }
        
        (function($) {
          $.fn.inputFilter = function(inputFilter) {
            return this.on("input keydown keyup mousedown mouseup select contextmenu drop", function() {
              if (inputFilter(this.value)) {
                this.oldValue = this.value;
                this.oldSelectionStart = this.selectionStart;
                this.oldSelectionEnd = this.selectionEnd;
              } else if (this.hasOwnProperty("oldValue")) {
                this.value = this.oldValue;
                this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
              }
            });
          };
        }(jQuery));

        $(".positiveinteger").inputFilter(function(value) {
          return /^\d*$/.test(value); });

        $(".floating").inputFilter(function(value) {
          return /^-?\d*[.]?\d*$/.test(value); });

        $(".currency").inputFilter(function(value) {
          return /^-?\d*[.]?\d{0,2}$/.test(value); });

        function checkDates(date1,date2)
        {
            var fromDate = date1.value;
            var toDate = date2.value;
            if(fromDate&&toDate)
            {
                //Detailed check for valid date ranges
                //if your date is like 09-09-2012
                var frommonthfield = fromDate.split("-")[1];
                var fromdayfield = fromDate.split("-")[2];
                var fromyearfield = fromDate.split("-")[0];

                var tomonthfield = toDate.split("-")[1];
                var todayfield = toDate.split("-")[2];
                var toyearfield = toDate.split("-")[0];

                var fromDate = new Date(fromyearfield, frommonthfield-1, fromdayfield);
                //alert(fromDate);
                var toDate = new Date(toyearfield, tomonthfield-1, todayfield);

                if(fromDate.getTime() > toDate.getTime())
                {

                    date1.value="";
                    date1.focus();
                    alert("Period To should be greated than Period From");
                    return false;       
                }
            }  
        }
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('adminlte::page', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH E:\xampp7.3\htdocs\kmportal\resources\views/Training/schedule.blade.php ENDPATH**/ ?>