

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

        <link href="<?php echo asset('/plugins/bootstrap-material-datetimepicker/css/bootstrap-material-datetimepicker.css'); ?>" rel="stylesheet" />
<!--        <link href="<?php echo asset('/css/calender_style.css'); ?>" rel="stylesheet" />-->





    <style>


        #calendar {
            max-width: 1050px;
            margin: 0 auto;
            background-color: white;
            width: 100%;
        }

        .h2,
        h2 {
            font-size: 1.5rem !important;
        }

        .f-600{
            font-weight: 600;
        }

        .f-13{
            font-size: 13px !important;
        }

        #applyResignationValidationErrors{
            background-color: #eee;
            list-style: disc;
            border: 2px solid red;
            padding: 5px 20px;
            color: darkred;
        }

    </style>
<?php $__env->stopSection(); ?> <?php $__env->startSection('badcome'); ?>

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

    <div class="container">
        <div class="row container_layout">
            <div class="col-md-6">
                <div class="card">
                    <div class="card-header view view-cascade text-center btn-outline-info text-white" style="font-variant: petite-caps;"> APPLY RESIGNATION</div>
                    <div class="card-body">
                        <div id="applyResignationValidation">

                        </div>

                        <form id="applyResignation">
                            <?php echo e(csrf_field()); ?>

                            <input type="hidden" class="form-control" name="notice_period" value="<?php echo e($global_data['config']->service_resign_notice_period); ?>" placeholder="Select Date" id="notice_period"/>
                            
                            <div class="form-group">
                                <label>Date of Resignation</label>
                                <input type="text" class="form-control" name="resign_date" placeholder="Select Date" id="resign_date"/>
                            </div>
                            
                            <div class="form-group notice_period_checkbox_div" style="display:none;">
                                <label>Your Released Date Would Be</label><br>
                                <input type="text" class="form-control" name="release_date" id="release_date"/ disabled>
                            </div>
                            
                            <div class="form-group notice_period_checkbox_div" id="" style="display:none;">
                                <p class="text-info f-600 f-13">Note: According to policy you need to serve <?php echo e($global_data['config']->service_resign_notice_period); ?> days notice period.</p>
                                
                                <label class="checkbox-inline"><input type="checkbox" name="notice_period_ck" id="notice_period_ck" value="N"> No, I do not want to serve the period.</label>
                            </div>
                            
                            <div class="form-group">
                                <label>Document</label>
                                <input type="file" class="form-control" name="resign_doc" required/>
                            </div>
                            
                            <div class="form-group">
                                <label>Remarks</label>
                                <textarea class="form-control" name="resign_remarks" id="resign_remarks" required></textarea>
                            </div>
                            
                            <div class="form-group">
                                <button type="submit" class="btn btn-primary">
                                    Submit
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="card">
                    <div class="card-header view view-cascade text-center btn-outline-secondary  text-white" style="font-variant: petite-caps;"> STATUS</div>

                    <div class="card-body">
                        <?php if($result): ?>
                        <div class="form-group">

                            <?php if($result['status'] == 3): ?>  
                                <p class="text-success f-600 f-13">
                                    Resignation successfully approved.
                                </p>

                           <!--     <button type="button" class="btn btn-primary btn-sm" style="margin:10px 0px"><i class="fa fa-download"></i> Download Experience Letter</button>-->


                            <?php elseif($result['status'] == 4): ?>  
                                <p class="text-danger f-600 f-13">
                                     Resignation successfully cancelled.
                                </p>

                            <?php elseif($result['status'] == 5): ?>  
                                <p class="text-danger f-600 f-13">
                                     Resignation Regected by Higher Authority
                                </p>
                            <?php else: ?>
                                <p class="text-primary f-600 f-13">
                                    Resignation successfully applied and sent for approval.
                                </p>
                                <div class="row">
                                    <button type="button" class="btn btn-info" id="cancel_resignation" style="margin:10px 0px">Cancel Resignation</button>
                                </div>
                            <?php endif; ?>

                            <p>
                                Date of Resignation : <b> <?php echo e(\Carbon\Carbon::parse($result['service_initiate_date'])->format('d-m-Y')); ?></b>
                            </p>

                            <p>
                                 Released Date Would Be : <b>
                                <?php if($result['proposed_released_date']): ?>
                                  <?php echo e(\Carbon\Carbon::parse($result['proposed_released_date'])->format('d-m-Y')); ?>

                                <?php else: ?>
                                  <?php echo e(\Carbon\Carbon::parse($result['service_final_date'])->format('d-m-Y')); ?>

                                <?php endif; ?>
                                </b>
                            </p>
                            <p>
                                 Notice Period: <b> <?php echo e(($result['notice_period'])? $result['notice_period']." Dayes.": "Do not want to serve the Notice Period"); ?></b>
                            </p>
                            <p>
                                Document : <a href="<?php echo e($global_data['config']->image_url); ?><?php echo e($result['file_url']); ?>" target="_blank"><i class="fa fa-eye fa-2x" aria-hidden="true"></i></a>
                            </p>

                            <?php if($result['remarks']): ?>
                            <p>
                                Remarks : <?php echo e($result['remarks']); ?>

                            </p>
                            <?php endif; ?>

                            <p>
                                Status of Resignation :
                                <?php if($result['status'] == 3): ?>  
                                    <span class="badge badge-pill green p10">Approved</span>
                                <?php elseif($result['status'] == 4): ?>  
                                    <span class="badge badge-pill orange p10">Successfully Cancelled</span>
                                <?php elseif($result['status'] == 5): ?>  
                                    <span class="badge badge-pill red p10">Rejected</span>
                                <?php else: ?>
                                    <span class="badge badge-pill blue p10">Pending</span>
                                <?php endif; ?>

                            </p>

                            

                        </div>
                        <?php else: ?>
                        <div class="form-group">
                            <p>
                                <span class="badge badge-pill blue p10">
                                    No data available
                                </span>
                            </p>
                        </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </div>

<?php $__env->stopSection(); ?>

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

		<script type="text/javascript" src="http://momentjs.com/downloads/moment-with-locales.min.js"></script>
		<script type="text/javascript" src="<?php echo e(asset('js/lib/bootstrap-material-datetimepicker.js')); ?>"></script>

    <script>
/*        $('#notice_period_date').bootstrapMaterialDatePicker();
        
       
      $('#resign_date').bootstrapMaterialDatePicker
			({
				time: false,
				clearButton: false
			});*/
        $('#notice_period_date').bootstrapMaterialDatePicker({weekStart:0, time:false});
        $('#resign_date').bootstrapMaterialDatePicker({weekStart:0, minDate:"<?php echo e(\Carbon\Carbon::now()->format('Y-m-d')); ?>" ,time:false});
        
        $("#applyResignation").validate({
            rules: {
                resign_date: {
                    required: true,
                },
                resign_doc: {
                    required: true,
                }
            },
            messages: {

            }
        });

        $('#applyResignation').on('submit',function(e){
            e.preventDefault();

            $('#applyResignationValidation').empty();

            if($("#applyResignation").valid()){
                $('.page-loader-wrapper').fadeIn();
                $.ajax({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    type: "POST",
                    url: "<?php echo e(route('saveapplyresignation')); ?>",
                    dataType: "json",
                    data: new FormData(this),
                    contentType: false,
                    cache: false,
                    processData: false,
                    success: function (data) {
                        if (data.msgType == true) {
                            Swal.fire({
                              title: 'Success',
                              text: data.msg,
                              type: 'success',
                              showCancelButton: false,
                              confirmButtonColor: '#3085d6',
                              cancelButtonColor: '#d33',
                              confirmButtonText: 'Ok'
                            }).then((result) => {
                              if (result.value) {
                                location.reload();
                              }
                            })
                            
                        }else{

                            if(data.msg=="VE"){
                                $('#applyResignationValidation').append('<ul class="form-group f-600 f-13" id="applyResignationValidationErrors"></ul>');

                                $.each(data.errors, function( index, value ) {
                                    $('#applyResignationValidationErrors').append('<li>'+value+'</li>');
                                });
                            }else{
                       
                               Swal.fire({
                                  title: 'Error',
                                  text: data.msg,
                                  type: 'error',
                                  showCancelButton: false,
                                  confirmButtonColor: '#3085d6',
                                  cancelButtonColor: '#d33',
                                  confirmButtonText: 'Ok'
                                }).then((result) => {
                                  if (result.value) {
                                    
                                  }
                                })
                            }
                        }
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
                    },
                    complete: function (data) {
                        $('.page-loader-wrapper').fadeOut();
                    }
                });

            }
        });

        
       $('#cancel_resignation').on('click',function(e){
           e.preventDefault();
           Swal.fire({
              title: 'Are you sure?',
              text: "You want to cancel your resignation.!",
              type: 'warning',
              showCancelButton: true,
              confirmButtonColor: '#3085d6',
              cancelButtonColor: '#d33',
              confirmButtonText: 'Yes'
            }).then((result) => {
              if (result.value) {
                    (async () => {

                    const { value: text } = await Swal.fire({
                      input: 'textarea',
                      inputPlaceholder: 'Type your reason why you want to cancel your resignation.',
                      inputAttributes: {
                        'aria-label': 'Type your message here'
                      },
                      showCancelButton: true,
                      inputValidator: (value) => {
                        return !value && 'You need to write something!'
                      },
                      showCancelButton: true,
                      confirmButtonColor: '#3085d6',
                      cancelButtonColor: '#d33',
                      confirmButtonText: 'Submit'
                    })

                    if (text) {
                         swal.resetValidationError();
              
                         $('.page-loader-wrapper').fadeIn();
                         $.ajax({
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            },
                            type: "POST",
                            url: "<?php echo e(route('cancelresignation')); ?>",
                            data:{'remarks':text},
                            dataType: "json",
                            success: function (data) {
                               if (data.msgType == true) {
                                    Swal.fire({
                                      title: 'Success',
                                      text: data.msg,
                                      type: 'success',
                                      showCancelButton: false,
                                      confirmButtonColor: '#3085d6',
                                      cancelButtonColor: '#d33',
                                      confirmButtonText: 'Ok'
                                    }).then((result) => {
                                      if (result.value) {
                                        location.reload();
                                      }
                                    })

                                }else{  
                                       Swal.fire({
                                          title: 'Error',
                                          text: data.msg,
                                          type: 'error',
                                          showCancelButton: false,
                                          confirmButtonColor: '#3085d6',
                                          cancelButtonColor: '#d33',
                                          confirmButtonText: 'Ok'
                                        }).then((result) => {
                                          if (result.value) {

                                          }
                                        })
                                }
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
                            },
                            complete: function (data) {
                                $('.page-loader-wrapper').fadeOut();
                            }
                        });
                    }else{
                          swal.showValidationError(
                            'please enter a refund amount.'
                          )
                    }

                    })()
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
/*                 $('.page-loader-wrapper').fadeIn();
                 $.ajax({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    type: "POST",
                    url: "<?php echo e(route('cancelresignation')); ?>",
                    dataType: "json",
                    success: function (data) {
                       if (data.msgType == true) {
                            Swal.fire({
                              title: 'Success',
                              text: data.msg,
                              type: 'success',
                              showCancelButton: false,
                              confirmButtonColor: '#3085d6',
                              cancelButtonColor: '#d33',
                              confirmButtonText: 'Ok'
                            }).then((result) => {
                              if (result.value) {
                                location.reload();
                              }
                            })
                            
                        }else{  
                               Swal.fire({
                                  title: 'Error',
                                  text: data.msg,
                                  type: 'error',
                                  showCancelButton: false,
                                  confirmButtonColor: '#3085d6',
                                  cancelButtonColor: '#d33',
                                  confirmButtonText: 'Ok'
                                }).then((result) => {
                                  if (result.value) {
                                    
                                  }
                                })
                        }
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
                    },
                    complete: function (data) {
                        $('.page-loader-wrapper').fadeOut();
                    }
                });*/
                
              }
            })
       }) 
        
        
        
        $('#resign_date').on('change', function(e){
            e.preventDefault();
            var resign_date= $('#resign_date').val();
            var notice_period=$('#notice_period').val();
            var releasing_date=get_releasing_date(resign_date,notice_period);
            $('#release_date').val(releasing_date);
            $('.notice_period_checkbox_div').show();
        });

        
        $('#notice_period_ck').on('click', function(e){
            var resign_date= $('#resign_date').val();
            var notice_period=$('#notice_period').val();
            if($('#notice_period_ck').is(':checked')){
               var releasing_date=get_releasing_date(resign_date,0);
               $('#release_date').val(releasing_date);
            }else{
                var releasing_date=get_releasing_date(resign_date,notice_period);
                 $('#release_date').val(releasing_date);
            }
        });
        
        
        
        
       function get_releasing_date(resign_date,notice_period){
           
            var date = new Date(resign_date),
            days = parseInt(notice_period);

            date.setDate(date.getDate() + days);
           
            var date_text=date.getFullYear() + '-' +((date.getMonth() > 8) ? (date.getMonth() + 1) : ('0' + (date.getMonth() + 1)))+ '-' +((date.getDate() > 9) ? date.getDate() : ('0' + date.getDate()));
           return date_text;
       } 
        
        

    </script>

<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.appuser', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>