Untitled

 avatar
unknown
plain_text
2 months ago
23 kB
4
Indexable
<script type="text/javascript" src="<?php echo base_url("assets/js/tabulator.min.js"); ?>"></script>
<script type="text/javascript" src="<?php echo base_url("assets/js/moment.min.js"); ?>"></script>
<link href="<?php echo base_url("assets/css/tabulator_bootstrap.min.css"); ?>" rel="stylesheet" type="text/css" />
<link href="<?php echo base_url("assets/css/sipnewui.css"); ?>" rel="stylesheet" type="text/css" />
<style>
	
	.tabulator-menu {
		overflow-y: scroll;
		max-height: 300px;
	}

	.tabulator-header-filter input {
		background-color: #f7f7f7;
		padding: 2px 5px !important;
		color: #6b6363 !important;
		border: 0px;
	}

	.tabulator-headers .tabulator-header-filter input::placeholder {

		margin-left: 0px !important;

		background-color: #f9f9f9 !important;
		border: 0px solid #ddd;
		color: #bbb !important;
		width: 100%;
		text-align: center;
	}

	.menu-header_v2 #tabulator_grid {
		height: 75vh !important;
	}
</style>

<div class="page-breadcrumb new-pagebread">
		<ol class="breadcrumb">
			<!--<li><a href="<?php // echo site_url("dashboard"); 
								?>"><?php //echo _t("Dashboard", $translatedData); 
																		?></a></li>-->
			<li class="breadcrumb-item"><a href="<?php echo site_url("performance-cycle"); ?>"><?php echo _t("Comp Plans", $translatedData); ?></a></li>
			<li class="breadcrumb-item"><a href="<?php echo site_url("sip-rule-list/" . $rule_dtls['performance_cycle_id']); ?>"><?php echo _t("Incentive Rule List ", $translatedData, [], ['%rule_name' => $rule_dtls['sip_rule_name']]); ?></a></li>
			<li class="breadcrumb-item"><a href="<?php echo site_url("sip-rule-process/" . $rule_dtls['performance_cycle_id'] . "/" . $rule_dtls['id']); ?>"><?php echo _t("Process Incentive", $translatedData); ?></a></li>
			<li class="breadcrumb-item active"><?php echo _t("Employees Incentive List", $translatedData); ?></li>
		</ol>
		
		<div class="action-item-btns">
			<?php if (helper_have_rights(CV_LETTER_DOCS_STORAGE, CV_VIEW_RIGHT_NAME) && $rule_dtls['template_id'] && $employee_incentive_cnt &&  $generate_bulk_pdf) { ?>
					<a data-frequencyid="<?php echo $frequency_id; ?>" data-ruleid="<?php echo $rule_dtls["id"]; ?>" data-toggle='tooltip' data-original-title='Generate bulk scorecard in PDF format' data-placement='bottom' class="generate_bulk_pdf breadbtn"> <i class="fa-regular fa-file-pdf" aria-hidden="true"></i> </a>
					<?php if($this->session->userdata('compport_drive_module')){ ?>
						<a href="<?php echo site_url('salary-review-letter') ?>" data-toggle='tooltip' data-original-title="<?php echo _t("Document Storage", $translatedData); ?>" data-placement='bottom' class="breadbtn"> <i class="fa-regular fa-file-text" aria-hidden="true"></i> </a>
       				<?php } ?>
			<?php } ?>
			<?php if ($rule_dtls['config']['integration_outbond'] && $employee_incentive_cnt && helper_have_rights(CV_LETTER_DOCS_STORAGE, CV_INSERT_RIGHT_NAME)) {  ?>
				<a style="padding-right: 8px !important;" data-frequencyid="<?php echo $frequency_id; ?>" data-ruleid="<?php echo $rule_dtls["id"]; ?>" data-toggle='tooltip' data-original-title='Publish the data to outbound integration tasks queue' data-placement='top' class="integration_outbond breadbtn"> <i class="fas fa-file-upload" aria-hidden="true"></i> </a>
			<?php } ?>
			<?php if ($employee_incentive_cnt && $rule_dtls['rule_type'] != 'type_2' && $is_open_frm_hr_side) {  ?>
				<a style="padding-right: 8px !important;" data-frequencyid="<?php echo $frequency_id; ?>" data-ruleid="<?php echo $rule_dtls["id"]; ?>" data-toggle='tooltip' data-original-title='Download Incentive Report' data-placement='top' class="final-process breadbtn"><img alt='filters' src="<?php echo base_url('assets/img/svg/download-new.svg') ?>"> </a>
				<?php if (helper_have_rights(CV_SIP_RELEASE_PG_ID, CV_INSERT_RIGHT_NAME) || $rule_dtls["crdeatedby"] == $this->session->userdata("userid_ses")) { ?>
					<a data-frequencyid="<?php echo $frequency_id; ?>" data-ruleid="<?php echo $rule_dtls["id"]; ?>" data-toggle='tooltip' data-original-title='Download Full Report' data-placement='top' class="download-final-process-data breadbtn"><img alt='filters' src="<?php echo base_url('assets/img/svg/download-new.svg') ?>"> </a>
				<?php  } ?>
			<?php } ?>
		</div>	
</div>

<div id="main-wrapper" class="">
	<div class="col-md-12">
		<div class="mailbox-content white-new-bg" id="newui-formater" style="margin-top:10px;">
			<?php $tbl_exceptional_cell_type = "";
			if (helper_have_rights(CV_SIP_RELEASE_PG_ID, CV_INSERT_RIGHT_NAME)) {
				$tbl_exceptional_cell_type = "input";
			}
			echo $this->session->flashdata('message');
			echo $msg; ?>
			<div class="form-horizontal">
				<div class=" table-scroll11">
					<div id="tabulator_grid" style="height: 600px;" class="ag-theme-alpine"></div>
				</div>
			</div>
		</div>
	</div>
</div>
</div>



<script>

$(document).ready(function() {
    // Enable Bootstrap tooltips for elements with data-toggle="tooltip"
    $('[data-toggle="tooltip"]').tooltip();
});

	//for final rule process and sheet-download
	$(document).on('click', '.final-process', function(e) {
		var rule_id = $(this).data('ruleid');
		var frequency_id = $(this).data('frequencyid'); //use for update
		if (!rule_id || !frequency_id) {
			custom_alert_popup("There seem to be some error.");
			return;
		}
		document.location.href = BASE_URL + 'sip/download_sip_incentives/' + rule_id + '/' + frequency_id;
		return;
	});

	$(document).on('click', '.download-final-process-data', function(e) {
		var rule_id = $(this).data('ruleid');
		var frequency_id = $(this).data('frequencyid');
		if (!rule_id || !frequency_id) {
			custom_alert_popup("There seem to be some error.");
			return;
		}
		document.location.href = BASE_URL + 'sip/sip_download_final_process_data/' + rule_id + '/' + frequency_id;
		return;

	});
	//for final rule process and sheet-download
</script>

<script type="text/javascript" charset="utf-8">
	const rule_id = <?php echo $rule_dtls["id"]; ?>;
	const frequency_id = <?php echo $frequency_id; ?>; //use for update

	Tabulator.prototype.extendModule("format", "formatters", {
		bold: function(cell, formatterParams) {
			return "<strong>" + cell.getValue() + "</strong>"; //make the contents of the cell bold
		},
		uppercase: function(cell, formatterParams) {
			return cell.getValue().toUpperCase(); //make the contents of the cell uppercase
		},
		custom_format: function(cell, formatterParams) {
			var value = cell.getValue();
			//console.log(cell.getField(), value,typeof value);
			if (typeof value == 'undefined' || typeof value == 'object') return '';
			var format = formatterParams.format || 'auto';
			var format_ary = format.split('~');
			if (typeof value != 'string') {
				cell.getElement().style.textAlign = "right";
				var formatter = new Intl.NumberFormat('<?php echo $this->session->userdata('locale'); ?>');
				//var format_ary = format.split('~');
				var max_decimals = format_ary[1] || 0;
				value = Number(Math.round(value + 'e' + max_decimals) + 'e-' + max_decimals).toFixed(max_decimals);
				switch (format_ary[0].toLowerCase()) {
					case 'number_format':
						return formatter.format(value);
						break;
					case 'currency_format':
						return "<currency>" + formatter.format(value) + "</currency>";
						break;
					case 'percentx100':
						value = formatter.format(value * 100);
						return value + '% ';
						break;
					case 'percent':
						value = formatter.format(value);
						return value + '% ';
						break;
					default:
						return value;
				}
			} else if (value != '') {
				if (format_ary[0] == 'currency_format' || format_ary[0] == 'number_format' || format_ary[0] == 'percentx100' || format_ary[0] == 'percent') {
					cell.getElement().style.textAlign = "right";
				}
				switch (format.toLowerCase()) {
					case 'date_format':
						return value;
					case 'capital': //currency
						return value[0].toUpperCase() + value.slice(1);
						break;
					case 'upper':
						return value.toUpperCase();
						break;
					case 'lower':
						return value.toLowerCase();
						break;
					case 'bold':
						return "<strong>" + value + "</strong>"; //make the contents of the cell bold
						break;
					default:
						return value;
						break;
				}
			}
			return value;
		},
	});



	//define column header menu as column visibility toggle
	var headerMenu = function() {
		var menu = [];
		var columns = this.getColumns();
		for (let column of columns) {
			if (column.getField() == 'id' || column.getField() == 'name') continue;
			//create checkbox element using font awesome icons
			let icon = document.createElement("i");
			icon.classList.add("fa");
			icon.classList.add(column.isVisible() ? "fa-check-square" : "fa-square");

			//build label
			let label = document.createElement("span");
			let title = document.createElement("span");

			title.textContent = " " + column.getDefinition().title;

			label.appendChild(icon);
			label.appendChild(title);

			//create menu item
			menu.push({
				label: label,
				action: function(e) {
					//prevent menu closing
					e.stopPropagation();

					//toggle current column visibility
					column.toggle();

					//change menu item icon
					if (column.isVisible()) {
						icon.classList.remove("fa-square");
						icon.classList.add("fa-check-square");
					} else {
						icon.classList.remove("fa-check-square");
						icon.classList.add("fa-square");
					}
				}
			});
		}
		return menu;
	};

	//define print formatter
	function nameFormatter(cell, formatterParams, onRendered) {
		//cell - the cell component
		//formatterParams - parameters set for the column
		//onRendered - function to call when the formatter has been rendered
		//	console.log(cell);
		var row = cell.getData();
		//var emp_url = BASE_URL + "admin-view-sip-incentive/" + row.rule_id + "/" + row.fid + "/" + row.user_id;
		var comment = `<span data-assignment-key="${row.assignment_key}" data-user-id="${row.user_id}" class='badge bg-blue float-end comment-history-structure-data c-badge'><i class='kpi-custom fa-regular fa-comment' aria-hidden='true'></i></span>`;
		var emp_url = "<a style='float:right;' data-toggle='tooltip' data-original-title='View Details' data-placement='bottom' class='badge pull-right bg-blue c-badge' href='" + BASE_URL + "admin-view-sip-incentive/" + rule_id + "/" + frequency_id + "/" + row.user_id + "/" + row.assignment_id + "'><i class='fa-regular fa-eye kpi-inc-list' aria-hidden='true'></i></a></span>";
		var emp_scorecard_pdf = '';
		if (emp_url && <?php echo $rule_dtls['template_id']; ?>) {
			var rule_freq_id = rule_id + "###" + frequency_id + "###" + row.assignment_id;
			var rule_freq_user_id = window.btoa(`${rule_freq_id}/${row.user_id}`);
			var emp_scorecard_pdf_url = '<?php echo $emp_score_card_url; ?>' + `/${rule_freq_user_id}`;
			emp_scorecard_pdf = `<a target="_blank" href='${emp_scorecard_pdf_url}' data-original-title='View scorecard in pdf format'  class='badge bg-blue pull-right scorecard-pdf c-badge'><i class='kpi-custom fa-regular  fa-file-pdf' aria-hidden='true'></i></a>`;
		}

		var assignment_id = row.assignment_id > 0 ? ` [${row.assignment_id}]` : '';
		return cell.getValue() + assignment_id + emp_url + emp_scorecard_pdf + comment;

	}
	var nameMutator = function(value, data, type, params, component) {
		//value - original value of the cell
		//data - the data for the row
		//type - the type of mutation occurring  (data|edit)
		//params - the mutatorParams object from the column definition
		//component - when the "type" argument is "edit", this contains the cell component for the edited cell, otherwise it is the column component for the column

		return value > mutatorParams.threshold; //return the new value for the cell data.
	}

	var cellClick = function(e, cell) {
		cell.getRow().toggleSelect();
	}

	var rowClick = function(e, row) {
		row.toggleSelect();
	}

	var groupHeader = function(value, count, data, group) {
		//value - the value all members of this group share
		//count - the number of rows in this group
		//data - an array of all the row data objects in this group
		//group - the group component for the group
		//console.log(data[0].approval_status);
		//	console.log(data);
		var label = document.createElement("span");
		var checkbox = document.createElement("input");
		checkbox.type = 'checkbox';
		//console.log()
		//checkbox.className  = 'form-check-input';
		checkbox.addEventListener("change", function(e) {
			//console.log(this.checked);
			group.getRows().forEach(row => {
				//	if (row.getData().is_checked == 1) {
				if (this.checked)
					row.select();
				else
					row.deselect();
				//}
			});
		});
		var approval_status = ''; //data[0].currency;
		var cnt_lbl = "<div class='badge bg-blue' style='margin-left:10px;'>" + count + " records</div>";
		var dn_btn = ""; //"<div class='badge bg-blue download-structure-data' style='margin-left:10px; padding:3.5px 10px;'><i class='fa fa-download kpi-custom' aria-hidden='true'></i></div> ";
		var up_btn = "";
		var value = "";
		label.innerHTML = "<span class='wf_group' data-sip-role-id='" + approval_status + "'>" + value + cnt_lbl + dn_btn + up_btn + "</span>";
		label.prepend(checkbox);
		return label;
	}

	var selectboxFormatter = function(cell, formatterParams, onRendered) {
		var _this64 = this;
		var checkbox = document.createElement("input");
		checkbox.type = 'checkbox';
		if (this.table.modExists("selectRow", true)) {

			checkbox.addEventListener("click", function(e) {
				e.stopPropagation();
			});

			if (typeof cell.getRow == 'function') {
				var row = cell.getRow();

				checkbox.addEventListener("change", function(e) {
					row.toggleSelect();
				});

				checkbox.checked = row.isSelected && row.isSelected();
				this.table.modules.selectRow.registerRowSelectCheckbox(row, checkbox);
				//console.log(row.getData().is_checked);
				/*if (row.getData().is_checked == 1) { //row.getData().approval_status == sip_role_id || row.getData().approval_status_name == sip_role_name ||
					checkbox.checked = row.isSelected && row.isSelected();
					this.table.modules.selectRow.registerRowSelectCheckbox(row, checkbox);
				} else {
					checkbox.checked = true;
					checkbox.disabled = true;
					//checkbox='';
				}*/
			} else {
				return '';
				checkbox.addEventListener("change", function(e) {
					if (_this64.table.modules.selectRow.selectedRows.length) {
						_this64.table.deselectRow();
					} else {
						_this64.table.getRows().forEach(row => {
							if (row.getData().approval_status == sip_role_id || row.getData().approval_status_name == sip_role_name) {
								row.select();
							}
						});
						//_this64.table.selectRow(formatterParams.rowRange);
					}
				});
				this.table.modules.selectRow.registerHeaderSelectCheckbox(checkbox);
			}
		}
		return checkbox;
	}

	// specify the columns
	var columnDefs = <?php echo $columnDefs; ?>;

	columnDefs.forEach(element => {
		element.headerFilter = true;
		//element.formatterParams:{format:6}
		//element.headerVertical=true;//"input";
		element.maxWidth = 300;
		switch (element.field) {
			/*case 'id':
				element.formatter = "rowSelection";
				element.titleFormatter = "rowSelection";
				//element.formatter = selectboxFormatter;
				//element.titleFormatter = selectboxFormatter;
				element.hozAlign = "center";
				element.cellClick = cellClick;
				element.headerFilter = false;
				//element.resizable = false;
				element.headerSort = false;
				element.frozen = true;
				//element.headerMenu = headerMenu;
				element.editor = '';
				//element.rowHandle = true;
				//element.minWidth = 50;
				//{rowHandle:true, formatter:"handle", headerSort:false, frozen:true, width:30, minWidth:30},
				//element.width = 50;

				break;*/
			case 'id':
				element.formatter = selectboxFormatter;
				element.titleFormatter = selectboxFormatter;
				element.hozAlign = "center";
				element.cellClick = cellClick;
				element.headerFilter = false;
				//element.resizable = false;
				element.headerSort = false;
				element.frozen = true;
				//element.headerMenu = headerMenu;
				element.editor = '';

				break;
			case 'name':
				//	element.headerContextMenu = headerContextMenu;
				element.width = 350;
				element.maxWidth = 400;
				element.frozen = true;
				element.formatter = nameFormatter;
				element.headerMenu = headerMenu;
				//formatter:"rowSelection", :, :, headerSort:false, cellClick:
				//element.mutator =customMutator;
				//	element.checkboxSelection = checkboxSelection;
				//	element.headerCheckboxSelection = headerCheckboxSelection;
				//	element.resizable = false;

				break;
			case 'exception_incentive':
			case 'exception_reason':
				element.editor = "<?php echo $tbl_exceptional_cell_type; ?>";
				break;

			default:
				break;
		}
		if (element.editor == '') {
			delete element.editor;
		}
		if (element.sorter == 'dateSorter') {
			element.sorter = dateSorter
		}
	});


	function dateSorter(a, b, aRow, bRow, column, dir, sorterParams) {
		a = a ? Math.round(new Date(a)) / 1000 : 0;
		b = b ? Math.round(new Date(b)) / 1000 : 0;
		return a - b;
	}
	//	console.log(columnDefs);

	var table = new Tabulator("#tabulator_grid", {
		height: '68vh', // set height of table (in CSS or here), this enables the Virtual DOM and improves render speed dramatically (can be any valid css height value)
		//data:tabledata, //assign data to table
		ajaxURL: "<?php echo $emp_data_json_url; ?>",
		ajaxProgressiveLoad: "load", // enable progressive loading
		ajaxProgressiveLoadDelay: 200, //wait 200 milliseconds between each request
		/*
		ajaxParams: {
		}, //set any standard parameters to pass with the request
		*/
		ajaxLoader: false,

		//pagination:"local", //enable remote pagination
		paginationInitialPage: 1, //optional parameter to set the initial page to load

		paginationSize: 5000,
		//	ajaxSorting:true, //send sort data to the server instead of processing locally
		//	ajaxFiltering:true,
		//layout:"fitColumns", //fit columns to width of table (optional)
		columns: columnDefs,
		//	autoColumns:true,
		movableColumns: true,
		textDirection: 'auto',

		headerFilterPlaceholder: "filter...", //set column header placeholder text

		resizableRows: true,
		//	groupBy:"currency",
		movableRows: false,
		/*
				persistence: {
					sort: true,
					filter: true,
					columns: true,
				},
				persistenceID: "tabular_sip_emp_inc_list2",*/
		/*rowClick: function(e, row) { //trigger an alert message when the row is clicked
			//	alert("Row " + row.getData().id + " Clicked!!!!");
		},
		ajaxError: function(error) {
			//	alert("An error occurred");
		},*/
		groupBy: ['status'],
		groupToggleElement: "arrow",
		groupHeader: groupHeader,
		cellEdited: function(cell) {
			var row = cell.getRow();
			var param_arr = {
				pk_id: row.getData().id,
				key_nm: cell.getField(),
				key_new_val: cell.getValue(),
				key_old_val: cell.getOldValue()
			};
			if (cell.getValue() != cell.getOldValue() && $.inArray(cell.getField(), ["exception_incentive", "exception_reason"]) !== -1) {
				upd_emp_sip_exceptional_data(param_arr);
			}
		},
	});

	function upd_emp_sip_exceptional_data(param_arr) {
		var csrf_val = $('input[name="<?php echo $this->security->get_csrf_token_name(); ?>"]').val();
		var csrf_name = "<?php echo $this->security->get_csrf_token_name(); ?>";

		var frmData = new FormData();
		var structure_id = "<?php echo $structure_id; ?>";

		frmData.append(csrf_name, csrf_val);
		frmData.append('rule_id', rule_id);
		frmData.append('frequency_id', frequency_id);
		frmData.append('structure_id', structure_id);

		frmData.append('pk_id', param_arr.pk_id);
		frmData.append('key_nm', param_arr.key_nm);
		frmData.append('key_old_val', param_arr.key_old_val);
		frmData.append('key_new_val', param_arr.key_new_val);

		$.ajax({
			type: "post",
			url: BASE_URL + 'sip/upd_emp_sip_exceptional_data',
			processData: false,
			contentType: false,
			data: frmData,
			beforeSend: function() {
				showLoader();
			},
			error: function(jqXHR, textStatus) {
				hideLoader();
			},
			complete: function() {
				hideLoader();
				set_csrf_field();
			},
			success: function(result) {
				try {
					var parseResult = JSON.parse(result);
					if (parseResult.status == true) {
						$.each(parseResult.data, function(index, value) {
							table.updateRow(index, value);
						});
						buildToast('success', parseResult.msg);
					} else {
						buildToast('error', parseResult.msg);
					}
				} catch (e) {
					//console.error(e);
				}
			}
		});
	}

	$(document).on('click', '.generate_bulk_pdf', function() {
		var requestUrl = '<?php echo $generate_bulk_pdf_url; ?>';
		PerformOperation(requestUrl)
	});

	$(document).on('click', '.integration_outbond', function() {
		var requestUrl = '<?php echo $integration_outbond_url; ?>';
		PerformOperation(requestUrl)
	});

	function PerformOperation(requestUrl) {
		var selectedRows = table.getSelectedRows();
		if (!selectedRows.length) {
			buildToast('error', "<?php echo _t("No records selected.", $translatedData); ?>");
			return;
		}
		custom_confirm_popup_callback('<?php echo CV_CONFIRMATION_MESSAGE; ?>', function(result) {

			if (result) {
				var selectedRows = table.getSelectedRows();
				var user_ids = [];
				var assignment_keys = [];
				selectedRows.forEach(function(row) {
					user_ids.push(row.getData().user_id);
					assignment_keys.push(row.getData().assignment_key);
				});
				user_ids = Array.from(new Set(user_ids)); //make it unique
				assignment_keys = Array.from(new Set(assignment_keys));
				if (!assignment_keys.length) {
					buildToast('error', "<?php echo _t("No records selected.", $translatedData); ?>");
					return;
				}
				if (!user_ids.length) {
					buildToast('error', "<?php echo _t("No records selected.", $translatedData); ?>");
					return;
				}

				var csrf_val = $('input[name="<?php echo $this->security->get_csrf_token_name(); ?>"]').val();
				var rule_id = <?php echo $rule_dtls['id']; ?>;
				var frequency_id = <?php echo $frequency_id; ?>; //use for update
				var template_id = $('#TempateID_' + rule_id).val();

				$("#loading").show();
				$.ajax({
					type: "POST",
					url: requestUrl,
					data: {
						assignment_keys: window.btoa(JSON.stringify(assignment_keys)),
						template_id: template_id,
						rule_id: rule_id,
						frequency_id: frequency_id,
						emp: user_ids,
						'<?php echo $this->security->get_csrf_token_name(); ?>': csrf_val
					},
					success: function(data) {
						$("#loading").css('display', 'none');
					},
					beforeSend: function(data) {
						$("#loading").show();
					},
					complete: function(data) {
						//console.log(data);
						//set_csrf_field();
						location.reload(true);
					}
				});

			}

		});
	}
</script>
<?php $this->load->view('sip/sip_emp_comment_popup', ['structure_id' => $structure_id, 'rule_id' => $rule_dtls["id"], 'fid' => $fid, 'comment_type' => 'sip_approval_workflow']); ?>
Editor is loading...
Leave a Comment