MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/.trash/application_bkold/views/shift_import/add.php
<div id="holder" class="form-inline row" style="margin-top:5px;min-height:130px; !important;">
	<!-- <div class="row"> -->
		<div class="col-md-12">
			<div class="form-group">
				<?php
					echo form_input( array('name'=>'prime_shift_import_id', 'id'=>'prime_shift_import_id', 'type'=>'Hidden','value'=> ''));

					$employee_type_list = array(""=>"---- Select Type ----",1=>"Single Employee",2=>"All",3=>"Selective Employee");
					echo form_label('Entry Type', 'employee_type', array('class' => 'required'));
					echo form_dropdown(array( 'name' => 'employee_type', 'id' => 'employee_type', 'class' => 'form-control input-sm select2'), $employee_type_list);
				?>
			</div>
			
			<div class="form-group" style="display: none;">
				<?php
					echo form_label('Employee Code', 'employee_code', array('class' => 'required'));
					echo form_dropdown(array( 'name' => 'employee_code', 'id' => 'employee_code', 'class' => 'form-control input-sm select2'));
				?>
			</div>
			<div class="form-group">
				<?php
					echo form_label('Category', 'category', array('class' => 'required'));
					echo form_dropdown(array( 'name' => 'category', 'id' => 'category', 'class' => 'form-control input-sm select2'), $category_list);
				?>
			</div>
			<!-- SELECTIVE EMPLOYEE INPUT  -->
			<div class="form-group" style="display:none;">
				<?php
					echo form_label('Selective Employee', 'selective_employee', array('class' => 'required'));
					echo form_dropdown(array( 'name' => 'selective_employee', 'multiple id' => 'selective_employee', 'class' => 'form-control input-sm select2'));
				?>
			</div>
			<div class="form-group">
				<?php
					echo form_label('Start Date', 'start_date', array('class' => 'required'));
					echo form_input(array( 'name' => 'start_date', 'id' => 'start_date', 'class' => 'form-control input-sm datepicker', 'placeholder' => 'Select Date'));
				?>
			</div>
			<div class="form-group">
				<?php
					echo form_label('End Date', 'end_date', array('class' => 'required'));
					echo form_input(array( 'name' => 'end_date', 'id' => 'end_date', 'class' => 'form-control input-sm datepicker', 'placeholder' => 'Select Date'));
				?>
			</div>
			
			<div class="form-group">
				<?php
					echo form_label('Shift Name', 'shift_name', array('class' => 'required'));
					echo form_dropdown(array( 'name' => 'shift_name','id' => 'shift_name', 'class' => 'form-control input-sm select2'),$shift_name_list);
				?>
			</div>
			<div class="form-group" id = "filter_component"  style="display:none;">
				<a class="btn btn-sm btn-edit" id="search_filter_id">
					<i class="fa fa-filter" aria-hidden="true"></i> Search filter
					<span class="caret"></span>
				</a>
				<div id="search_filter_div_id" class='search_filter'>
					<div style="max-height:250px;overflow: auto;">
						<?php
							$filter_cond_array = array('' => '--- Select ---','=' => '=','>' => '>','<' => '<','LIKE' => 'LIKE');
							$tr_line = "";
							foreach($fliter_list as $fliter){
								$label_id         = $fliter['label_id'];
								$field_isdefault  = $fliter['field_isdefault'];
								$array_list       = $fliter['array_list'];
								$field_type       = $fliter['field_type'];
								
								$label_name = ucwords(strtolower(str_replace("_"," ",$label_id)));
								$fliter_label = form_input(array('type'=>'hidden','name' => 'fliter_label[]', 'class' => 'form-control input-sm','value' => $label_id));
								$fliter_type  = form_input(array('type'=>'hidden','name' => 'fliter_type[]', 'class' => 'form-control input-sm','value' => $field_isdefault));
								$filter_cond  = form_dropdown(array('name' => 'filter_cond[]','class' => 'form-control input-sm'), $filter_cond_array);
								if($field_type === 4){							
									$fliter_val   = form_input(array( 'name' => 'fliter_val[]', 'class' => 'form-control input-sm datepicker', 'placeholder'=>'Search value','value' => ''));
								}else
								if(((int)$field_type === 5) || ((int)$field_type === 7)){
									$fliter_val  = form_dropdown(array('name' => 'fliter_val[]','class' => 'form-control input-sm'), $array_list);
								}else{
									$fliter_val   = form_input(array( 'name' => 'fliter_val[]', 'class' => 'form-control input-sm', 'placeholder'=>'Search value','value' => ''));
								}						
								$tr_line .= "<tr>
												<td class='search_td'> $label_name $fliter_label $fliter_type</td>
												<td> $filter_cond</td>
												<td> $fliter_val </td>
											</tr>";
							}
							echo "<table style='width:100%;'>$tr_line</table>";
						?>				
					</div>
					<div style="margin-top:8px;">
						<div class="row">
							<div class="col-md-6" style='text-align:left;'>
								<a class="btn btn-xs btn-danger" id="clear_search_id"> Clear / Close</a>
							</div>
							<div class="col-md-6" style='text-align:right;'>	
								<a class="btn btn-xs btn-primary" id="search_submit_id"> Done </a>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="form-group">
				<button class='btn btn-primary btn-sm' id="submit">Submit</button>
			</div>
		</div>

	<!-- </div> -->
</div>
<div id="counter"></div>
<!--- html table ----->
<div class="row" style='margin:0px;overflow:auto;'>	
	<div id='table_structure' class='col-md-12' style='padding:2px;max-height: 350px;'>
	</div>
</div>

<style>
.text{
	display: block;
	 cursor: pointer; 
	 text-transform: uppercase; 
	 letter-spacing: 0.2em;
	  font-size: 12px; 
	  font-weight: 300; 
	  color: #74727a; 
	  line-height: 1em; 
	  margin-top: 10px;
}
.count-box{
	margin-right:60px;

}
.text-center{
	padding-bottom: 5px;
}
.successcounter{
	color:green;
}
.errorcounter{
	color:#e64c3d;
}
.count{
	display: inline-block; margin-bottom: 5px; font-size: 40px; font-weight: 600; line-height: 1em; 
}
</style>

<script type="text/javascript">
$(document).ready(function(){
	$("#filter_component").hide();
	
	$("#search_submit_id").click(function(){
		$("#search_filter_div_id").toggle();
	});
	$("#search_filter_div_id").hide();
	$("#search_filter_id").click(function(){
		$("#search_filter_div_id").toggle();
	});
	$("#clear_search_id").click(function(){
		$('#search_filter_div_id').find('input').val('');
		$('#search_filter_div_id option').attr('selected', false);
		$("#search_filter_div_id").toggle();
	});	
	$(function () {
		$(".datepicker").datetimepicker({
			format: 'DD-MM-YYYY',
			//debug: true
		});
		$("#process_month").datetimepicker({
			format: 'MM-YYYY',
			//debug: true
		});
		$(".datepicker_time").datetimepicker({
			format: 'DD-MM-YYYY HH:mm:ss',
			//debug: true
		});
	});
	$('textarea').on('keyup keypress', function(e) {
		if(e.keyCode === 13) {    
			e.stopPropagation();
		}else
		if(e.shiftKey){
			e.stopPropagation();
		}
	});
	$(".number").bind('keyup', function(e) {
		this.value = this.value.replace(/[^0-9_.]/g,'');
	});
	$('.alpha').bind('keypress', function (event) {
		var regex = new RegExp("^[a-zA-Z0-9\-_.@\/\\s]+$");
		var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
		if (!regex.test(key)) {
		   event.preventDefault();
		   return false;
		}
	});

	var employee_type  = parseInt($('#employee_type').val());
	if(employee_type){
		emp_type_wise_hide(employee_type);
	}
	$('#employee_type').change(function(){
		var category       = parseInt($('#category').val());
		var employee_type  = parseInt($('#employee_type').val());
		var start_date     = $('#start_date').val();
		var end_date       = $('#end_date').val();
			if(employee_type){				
				//only for employee wise
				if(employee_type === 1){
					emp_code_list();
				}else
				if(employee_type === 3){
					$('#category').val('');
				}	
				emp_type_wise_hide(employee_type);	
			}
	});

	//employee code based category get and salary start date and end date get
	$('#employee_code').change(function(e){
		var employee_code       = $('#employee_code').val();
		$('#category,#start_date,#end_date').val('');
		if(employee_code){
			emp_category_sal_date(employee_code);
		}
	});
	
	//CATEGORY ON CHANGE PROCESS
	$('#category').change(function(){
		var category          = parseInt($('#category').val());
		var employee_type     = parseInt($('#employee_type').val());
		$('#employee_code,#start_date,#end_date').val('');
		if(category){
			if(employee_type === 3){ //If selective employee
				emp_code_list(category);
			}			
			check_transaction_status(category);
		}
	});

	//Check start date and end date onclick validation
	$('#start_date,#end_date').on('dp.hide',function(){
		var category          = parseInt($('#category').val());
		var employee_type     = parseInt($('#employee_type').val());
		var start_date        = $('#start_date').val();
		var end_date          = $('#end_date').val();
		var employee_code     = $('#employee_code').val();
		var change_id         = $(this).attr('id');
		var start_check_date  = "";
		var end_check_date    = "";
		if(start_date && end_date){
			start_check_date     = moment(start_date, 'DD-MM-YYYY').format('YYYY-MM-DD');
			end_check_date       = moment(end_date, 'DD-MM-YYYY').format('YYYY-MM-DD');
		}
		//FOR SINGLE EMPLOYEE BASED
		if(employee_type === 1){
			if(!employee_code){
				toastr.error('Please Choose Employee Code.!');
				$('#start_date,#end_date').val('');
				return false;
			}
		}
		if(!category){
			toastr.error('Category should not be Empty..?');
			$('#start_date,#end_date').val('');
			return false;
		}
		
		if(change_id === "start_date"){
			if(end_date){
				if(end_check_date < start_check_date){
					toastr.error('Start Date should not be Greater than End Date?');
					$('#end_date').val('');
					return false;
				}
			}
		}else{
			if(start_date){
				if(end_check_date < start_check_date){
					toastr.error('Start Date should not be Greater than End Date?');
					$('#end_date').val('');
					return false;
				}
			}else{
				toastr.error('Start Date should not be Empty..?');
				return false;
			}
		}
	});

	//BULK SHIFT SUBMIT FUNCTION
	$('#submit').on('click',function(e){
		shift_import(data_table_create);
		// ,select_call
	});
	select_call();
});

//---------------- FUNCTION MODE START -----------------------------
//EMPLOYEE TYPE WISE INPUT HIDE AND SHOW
function emp_type_wise_hide(employee_type){
	if(employee_type === 1){
		$('#employee_code,#category,#start_date,#end_date').val('');
		$('#employee_code').parent().show();
		$("#filter_component").hide();
		$('#selective_employee').parent().hide();
		$("#category").attr("readonly","readonly");

	}else if(employee_type === 3){
		$('#selective_employee,#category,#start_date,#end_date').val('');
		$('#selective_employee').parent().show();
		$("#filter_component").hide();
		$('#employee_code').parent().hide();
		$("#category").attr("readonly",false);
	}
	else{
		$('#employee_code,#category,#start_date,#end_date').val('');
		$('#employee_code').parent().hide();
		$('#selective_employee').parent().hide();
		$("#filter_component").show();
		$("#category").attr("readonly",false);
	}
	select_call();
}

//FUNCTION TO GET A EMPLOYEE CODE AND NAME FOR SINGLE EMPLOYEE AND SELECTIVE EMPLOYEE INPUT. 
function emp_code_list(category) {
	if(category){
		var id = 'selective_employee';
	}else{
		var id = 'employee_code';
	}
    var send_url = '<?php echo site_url("$controller_name/emp_code_list");?>';
    $.ajax({
        type: 'POST',
        url: send_url,
        data: {category: category},
        beforeSend: function() {        	
           $('#'+id).next('span').attr('id', id+'_span');
           $('#'+id+'_span').html('<span style="color:#CC3366;"><i class="fa fa-spinner fa-spin fa-2x fa-fw"></i><br/>Loading...</span>');
        },
        success: function(response) {
            var result = JSON.parse(response);
            if(result.success){         	
                $('#'+id).html(result.emp_list);	
                //$('#'+id).show();			
            }else{
                toastr.error(result.message);
            }
        }
    });
}


//EMPLOYEE CODE BASED CATEGORY AND SALARY DATE GET 
function emp_category_sal_date(employee_code){
	var send_url     = '<?php echo site_url("$controller_name/emp_category_sal_date");?>';
	var employee_code    = $('#employee_code').val();
	$.ajax({
		type: 'POST',
		url: send_url,
		data: {employee_code:employee_code},
		success: function(response){
			var result = JSON.parse(response);
			if(result.success){
				$("#category").val(result.category);
				select_call();
				//DATE PROCESS
				min_max_date_set(result.salary_start_date,result.salary_end_date);
			}else{
				toastr.error(result.message);
			}
		}
	});
}
//FUNCTION FOR SET MIN AND MAX DATE
function min_max_date_set(salary_start_date,salary_end_date){
	$("#start_date,#end_date").val('');
	$("#start_date,#end_date").datetimepicker();
	$("#start_date,#end_date").datetimepicker("destroy");
	var start_date   = moment(salary_start_date, 'DD-MM-YYYY').format('YYYY-MM-DD');
	var end_date     = moment(salary_end_date, 'DD-MM-YYYY').format('YYYY-MM-DD');
	$("#start_date,#end_date").datetimepicker({
		format: 'DD-MM-YYYY',
		minDate: moment(start_date),
		maxDate: moment(end_date),
		//debug: true
	});
}

//CHECK CATEGORY BASED START AND END DATE VALIDATE
function check_transaction_status(category){
	// ,start_date,end_date
	var send_url     = '<?php echo site_url("$controller_name/check_transaction_status");?>';
	$.ajax({
		type: 'POST',
		url: send_url,
		data: {category:category},
		// ,start_date:start_date,end_date:end_date
		success: function(response){
			var result = JSON.parse(response);
			if(result.success){
				//DATE PROCESS
				min_max_date_set(result.salary_start_date,result.salary_end_date);
			}else{
				toastr.error(result.message);
				$('#start_date').val('');
				$('#end_date').val('');
			}
		},
	});
	select_call();
}

//BULK SHIFT ADD FUNCTION
function shift_import(callBack1){
	// ,callBack2
	var category              = parseInt($('#category').val());
	var employee_type         = parseInt($('#employee_type').val());
	var employee_code         = $('#employee_code').val();
	var selective_employee    = $('#selective_employee').val();
	var start_date            = $('#start_date').val();
	var end_date              = $('#end_date').val();
	var start_check_date      = moment(start_date, 'DD-MM-YYYY').format('YYYY-MM-DD');
	var end_check_date        = moment(end_date, 'DD-MM-YYYY').format('YYYY-MM-DD');
	var shift_name            = $('#shift_name').val();
	var send_url              = '<?php echo site_url("$controller_name/shift_bulk_add");?>'

	if(!category || !employee_type || !shift_name){
		toastr.error('Please Choose all Mandatory Fields.!');
		return false;
	}
	if(employee_type === 1){
		if(!employee_code){
			toastr.error('Please Choose Employee Code.!');
			return false;
		}
	}
	if(end_check_date < start_check_date){
		toastr.error('Start Date Should not be Greater Than End Date?');
		$('#end_date').val('');
		return false;
	}
	if(send_url){
		var fliter_label      =  $("input[name='fliter_label[]']").map(function(){return $(this).val();}).get();
		var fliter_type       =  $("input[name='fliter_type[]']").map(function(){return $(this).val();}).get();
		var input_field_type  =  $("input[name='input_field_type[]']").map(function(){return $(this).val();}).get();
		var filter_cond       =  $("select[name='filter_cond[]']").map(function(){return $(this).val();}).get();
		var fliter_val        =  $("input[name='fliter_val[]'],select[name='fliter_val[]']").map(function(){return $(this).val();}).get();
		var group_by          =  $("select[name='group_by[]']").map(function(){return $(this).val();}).get();
		$("#submit").html("<i class='fa fa-spinner fa-spin'></i> Processing...");
		$('#submit').attr('disabled','disabled');
		$.ajax({
			type: 'POST',
			url: send_url,
			data: {category:category,employee_type:employee_type,employee_code:employee_code,selective_employee:selective_employee,start_date:start_date,end_date:end_date,shift_name:shift_name,fliter_label:fliter_label,fliter_type:fliter_type,input_field_type:input_field_type,filter_cond:filter_cond,fliter_val:fliter_val,group_by:group_by},
			success:function(response){
    			$('#submit').attr('disabled', false);
    			$("#submit").html("Submit");
				var result = JSON.parse(response); 
				if(result.success){
				    toastr.success(result.message);
					var endValue 		 = result.success;  	//success count
					var err_endValue 	 = result.error; 		//error count
					var successTableBody = result.success_info; //success HTML info
        			var errorTableBody	 = result.error_info;   //error HTML info
  					var table_view 		 = $('<div ></div>');
  					//Success && Failed Design HTML

					var tableElement = $('<div class="text-center"><div class="count-box" style="display: inline-block; "><h3 class="count successcounter" >0</h3><a onclick="success_table(\'' + successTableBody.replace(/'/g, "\\'") + '\')" class="text" >Success</a></div><div style="display: inline-block;"><h3 class="count errorcounter" >0</h3><a onclick="err_table_view(\'' + errorTableBody.replace(/'/g, "\\'") + '\')" class="text" >Failed</a></div></div>');
        			//For Counting!! 
 					var valuedisplays 		= tableElement.find(".successcounter");
 					var errorvaluedisplays  = tableElement.find(".errorcounter");		
 					valuedisplays.each(function(){   	 
 					  	var valuedisplay = $(this);
 					  	updateCounter(valuedisplay,endValue);
 					});
  					errorvaluedisplays.each(function(){  
  					  	var err_valuedisplay = $(this);
  					  	updateCounter(err_valuedisplay,err_endValue);
  					});
  					$("#counter").html("");
  					table_view.append(tableElement);
  					$('#counter').append(table_view);		
					disable_val     = result.disable_arr;
					if(disable_val){
						disable_arr = disable_val.split(',');
					}
  				}else{
					toastr.error(result.message);
					callBack1();
				}
			}
		});
	}
}

//success and failed counting function 
function updateCounter(element, endValue) {
  var startValue = 0;
  var interval 	 = 1000;
  if (endValue === 0) {
  	 element.parent().removeAttr('onclick');
    element.text(endValue);
    return;
  }
  var duration = Math.floor(interval / endValue);
  var counting = setInterval(function() {
    startValue += 1;
    element.text(startValue);  
    if (startValue === endValue) {
      clearInterval(counting);
    }
  }, duration);
}
function success_table(tableBody){
  // Function logic for success_table
	 var tableHTML = `<table class="table table-hover" id="success_table" style="white-space: nowrap;"><thead><tr><th>Employee Code</th><th>Shift Date</th><th>Message</th></tr></thead><tbody>${tableBody}</tbody></table>`;
  	$('#table_structure').html(tableHTML);
  	$('#success_table').DataTable(
  		{
  				dom: 'Blfrtip',
				order:true,
				buttons: [
					{ extend: 'excelHtml5', footer: true },
				],
  		});
  	$('input[type=search]').addClass('form-control input-sm');
	$("select[name='table_length']" ).addClass('form-control input-sm');
	$('.dt-button').addClass('btn btn-xs btn-edit');
	$('.btn-edit').removeClass('dt-button buttons-excel buttons-html5');
}
function err_table_view(tableBody) {
	if(tableBody === '' ){
		$('#error_table').hide();
	}else{
  		var tableHTML = `<table class="table table-hover" id="error_table" style="white-space: nowrap;"><thead><tr><th>Employee Code</th><th>Shift Date</th><th>Error Message</th></tr></thead><tbody>${tableBody}</tbody></table>`;
		
  		$('#table_structure').html(tableHTML);
  		$('#error_table').DataTable({
  				dom: 'Blfrtip',
				order:true,
				buttons: [
					{ extend: 'excelHtml5', footer: true },
				],
  		});
  		$('input[type=search]').addClass('form-control input-sm');
		$("select[name='table_length']" ).addClass('form-control input-sm');
		$('.dt-button').addClass('btn btn-xs btn-edit');
		$('.btn-edit').removeClass('dt-button buttons-excel buttons-html5');
	}
}
//CALLBACK FUNCTION FOR DATATABLE CREATE
function data_table_create(){
	$table = $('#error_table').DataTable({
		destroy: true,
		processing: true,
		lengthMenu: [[10],[10]],
		"order": [],
		// scrollX: true,
		fixedheader : true,
		scrollY: 340,
		// 'bSort': false,
		language:{
			lengthMenu:"<span style='margin-top:12px;margin-left:10px;'>Display</span> _MENU_ <span style='margin-top:12px;'>Records</span>",
			searchPlaceholder: "Search records",
			search: "",
		},
		dom: 'Bfrtip',
		buttons: [
			'excelHtml5',
		]
	});
	$('input[type=search]').addClass('form-control input-sm');
	$("select[name='table_length']" ).addClass('form-control input-sm');
}

//Select Call 
function select_call(){
	setTimeout(function(){ 
		$(function(){
			$('.select2').select2({
				placeholder: '---- Select ----',
				allowClear: true,
				dropdownParent: $('.modal-dialog'),
				maximumInputLength : 15
			});
			$('.select2-tags').select2({
				tags: true,
				allowClear: true,
				tokenSeparators: [',']
			});
		});
	}, 200);		
}
//---------------- FUNCTION MODE END -----------------------------
</script>