<?php
$ticketing_fields_hide = smc_session()['default_setting']['maintenance_fields_to_hide'] != '' ? explode(",", smc_session()['default_setting']['maintenance_fields_to_hide']) : [];
//echo '<pre>';
//print_r($ticketing_fields_hide);

//print_r($ticketing_status);

//die('ok');
//$t=$edit_arr['main']['ticketing_reply_id'];
//echo "<script>alert('$t');</script>";
 
?>
<link href="<?php echo LIBS_URL; ?>summernote/summernote.css" rel="stylesheet">
<script src="<?php echo LIBS_URL; ?>summernote/summernote.min.js"></script>
<style>
    

    .fa {
        cursor: pointer;
    }
 
</style>
<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title"><?php print $title; ?></div>
        </div>
        <div class="panel-body">
            <div class="row"><?php echo Forms::AlertDiv('ticketing_alert'); ?></div>
            <div hidden id="hide"  class="row"><div class="col-md-12"><div class="alert"  ><p id="alert_id"></p></div></div></div>

            <form method="POST" id="ticketing_form" onsubmit="return false">
                <input type="hidden" id="appointment_id" name="appointment_id" value="<?php echo $appointment_id; ?>" />
                <div class="row form-group">
                <div class="col-md-3">
                        <label><?php echo CommonLanguage::getMessage('event'); ?>
                            <span class="red-star">*</span>

                        </label>
                        <input type="hidden" name="event_id" id="event_id" class="full-width" value="<?php echo $appointment_id  == 0 ? '' :  $edit_arr['main']['event_id']; ?>" data-select-name="<?php echo $appointment_id  == 0 ? '' :  $edit_arr['main']['event_name']; ?>" required />
                    </div>
                     
                    <div class="col-md-3 ">
                    <label><?php echo CommonLanguage::getMessage('customer'); ?>
                            <span class="red-star">*</span>
                            <?php if($permissions->hasPermission('viewCustomer')){?>
                            <span class="fa fa-plus-circle m-l-5 openFrame" data-src="Inventory/CustomerList?is_pop=1&new=1" style="color:#4c0870;cursor:pointer"></span>
                            <?php }?>
                        </label>
                        <input type="hidden" name="customer_id" id="customer_id" class="full-width" value="<?php  echo $appointment_id  ==0 ? '' :  $edit_arr['main']['customer_id'];?>" data-select-name="<?php  echo $appointment_id  ==0 ? '' :  $edit_arr['main']['Customer_Name'];?>" required/>
                    </div>
                    

                    <div id="dev_app_date" class="col-md-3">
                        <label><?php echo CommonLanguage::getMessage('DATE'); ?>
                            <span class="red-star">*</span>
                        </label>
                        <input type="date" name="app_date" id="app_date" class="form-control" value="<?php echo $appointment_id == 0 ? date('Y-m-d') : $edit_arr['main']['app_date']; ?>" required />
                    </div>                
                    <div id="dev_app_time" class="col-md-3">
                        <label><?php echo CommonLanguage::getMessage('your_appointment_time'); ?>
                            <span class="red-star">*</span>
                        </label>
                        <input type="text"  name="app_time" id="app_time" class="form-control" value="<?php echo $appointment_id == 0 ? date('H:i') : $edit_arr['main']['app_time']; ?>" required />
                    </div> 
                </div>
 

                
                
               





            </form>
                 <div class="row">
                    <div class="col-md-3 pull-right">
                        <button id="submit_appointment" class=" btn btn-complete pull-right"><?php echo CommonLanguage::getMessage('Save'); ?></button>
                    </div>
                </div>
 
            <?php echo Forms::ModalLoader('ticketing_loader'); ?>
        </div>
    </div>
</div>
 
<script>
     $(function() {
        
        build_select2($("#customer_id"), 'xhr/customerSearch');
        build_select2($("#event_id"), 'xhr/commonSearch?table=tbl_event&col_id=id&col_name=event_name');
          
         
        $('#app_time').timepicker({
            showMeridian: false
        });
         
 
        $("#event_id").on("change", function() {        
            var event_id =$('#event_id').val();
            
              $.ajax({
                url: "TicketingAjax/get_event",
                data: {event_id:event_id},
                dataType: "JSON",
                complete: function(jqXHR, status) {
                    if (status == 'success') {
                        if (jqXHR.responseJSON[1] == "success") {
                            
                        }
                        $("#app_date").prop('min', jqXHR.responseJSON['data'][0]['from_date']);
                        $("#app_date").prop('max', jqXHR.responseJSON['data'][0]['to_date']);

                      }
                     
                }
            });

         });
         
         
        $("#submit_appointment").on("click", function() {
            //            return;
            if($('#customer_id').val() == '' || $('#event_id').val() == ''){
                AddAlert("#ticketing_alert", "<?php  echo CommonLanguage::getMessage('Required_Fields');?>", "danger");
                $(document.body).animate({scrollTop: 0}, 800)
                return;
            }
            var Data = new FormData(document.getElementById("ticketing_form"));
            Data.append('app_time', $('#app_time').val());
            Data.append('event_id', $('#event_id').val());
            Data.append('book_time', $('#book_time').val());
            Data.append('event_name', $('#event_name').val());

              



  
              $("#ticketing_loader").removeClass('hidden');
            $.ajax({
                url: "TicketingAjax/submit_appointment",
                method: "POST",
                data: Data,
                processData: false,
                contentType: false,
                dataType: "JSON",
                complete: function(jqXHR, status) {
                    if (status == 'success') {
                        if (jqXHR.responseJSON[1] == "success") {
                            $("#submit_appointment").prop('disabled', true);
                        }
                        $(document.body).animate({
                            scrollTop: 0
                        }, 800)
                        AddAlert("#ticketing_alert", jqXHR.responseJSON[0], jqXHR.responseJSON[1]);
                    }
                    $("#ticketing_loader").addClass('hidden');
                }
            });
        });
      
         
         
         
         
    });

     function alert_massage(massage,hide){
         if(hide)
         $("#hide").hide();
         else
        $("#hide").show();
        $("#alert_id").text(massage);
     }
</script>