You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

638 lines
15 KiB

2 years ago
function getUrlParameter(sParam) {
2 years ago
var sPageURL = window.location.search.substring(1),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
}
}
return false;
2 years ago
};
const formatNumber = (angka) => {
1 year ago
var number_string = angka.replace(/[^,\d]/g, '').toString(),
split = number_string.split(','),
sisa = split[0].length % 3,
rupiah = split[0].substr(0, sisa),
ribuan = split[0].substr(sisa).match(/\d{3}/gi);
var separator = "";
if (ribuan) {
separator = sisa ? '.' : '';
rupiah += separator + ribuan.join('.');
}
rupiah = split[1] != undefined ? rupiah + ',' + split[1] : rupiah;
return rupiah
}
1 year ago
function getCodeLinkByType(type) {
2 years ago
type = parseInt(type);
switch (type) {
case 1:
return "SS";
break;
case 2:
return "FF";
break;
case 3:
return "SF";
break;
default:
return "FS";
break;
}
2 years ago
}
1 year ago
var getInput = function (node) {
2 years ago
return node.querySelector("input");
2 years ago
};
gantt.config.editor_types.costPlanningEditor = {
2 years ago
show: function (id, column, config, placeholder) {
var min = config.min || 0
var html = "<div><input onkeyup='costPlanningChange(this)' type='text' min='" + min +
"' name='" + column.name + "'></div>";
placeholder.innerHTML = html;
},
hide: function () {
},
set_value: function (value, id, column, node) {
getInput(node).value = value;
},
get_value: function (id, column, node) {
return getInput(node).value || 0;
},
is_changed: function (value, id, column, node) {
var currentValue = this.get_value(id, column, node);
return value !== currentValue;
},
is_valid: function (value, id, column, node) {
return true;
},
focus: function (node) {
var input = getInput(node);
if (!input) {
return;
}
if (input.focus) {
input.focus();
}
if (input.select) {
input.select();
}
}
2 years ago
};
2 years ago
2 years ago
gantt.config.editor_types.progressCustom = {
2 years ago
show: function (id, column, config, placeholder) {
var min = config.min || 0,
max = config.max || 100;
var html = "<div><input type='number' min='" + min +
"' max='" + max + "' name='" + column.name + "'></div>";
placeholder.innerHTML = html;
},
hide: function () {
},
set_value: function (value, id, column, node) {
1 year ago
value = value * 100
2 years ago
getInput(node).value = value;
},
get_value: function (id, column, node) {
return getInput(node).value || 0;
},
is_changed: function (value, id, column, node) {
var currentValue = this.get_value(id, column, node);
return Number(value) !== Number(currentValue);
},
is_valid: function (value, id, column, node) {
return !isNaN(parseInt(value, 10));
},
focus: function (node) {
var input = getInput(node);
if (!input) {
return;
}
if (input.focus) {
input.focus();
}
if (input.select) {
input.select();
}
}
2 years ago
};
1 year ago
function initializationProject() {
2 years ago
let projectId = getUrlParameter("proyek_id");
1 year ago
if (projectId && projectId > 0) {
2 years ago
$.ajax({
url: `${base_url}project/edit/${projectId}`,
1 year ago
type: "GET",
2 years ago
success: function (result) {
let data = result.data;
let projectName = data.nama;
},
error: function (data) {
actionHappen = false;
}
});
}
2 years ago
}
1 year ago
function getSatuan() {
2 years ago
$.ajax({
url: `${base_url}satuan/list`,
1 year ago
type: "GET",
2 years ago
success: function (result) {
let satuanList = [];
let resSatuan = result.data || []
resSatuan.map((val, index) => {
let satuan = {
1 year ago
key: val.id,
label: val.name,
text: val.name
2 years ago
}
satuanList.push(satuan)
});
// Clear the select element before appending new options
$('#uom-req-material').empty();
$('#uom-req-expense').empty();
// Append the new options to the select element
satuanList.forEach((option) => {
let newOption = new Option(option.label, option.label);
$('#uom-req-material').append(newOption);
});
satuanList.forEach((option) => {
let newOption = new Option(option.label, option.label);
$('#uom-req-expense').append(newOption);
});
// Initialize select2 on the select element
$('#uom-req-material').select2({
dropdownParent: materialModal,
placeholder: 'Pilih satuan',
allowClear: true
});
$('#uom-req-expense').select2({
dropdownParent: expenseModal,
placeholder: 'Pilih satuan',
allowClear: true
});
1 year ago
if (satuanList.length > 0) {
2 years ago
gantt.updateCollection("satuan", satuanList);
gantt.refreshData();
gantt.render();
}
},
error: function (data) {
}
});
2 years ago
}
1 year ago
function updateActivity(id) {
2 years ago
$.ajax({
url: `${base_url}task/get-update/${id}`,
1 year ago
type: "GET",
2 years ago
success: function (result) {
let data = result.data;
gantt.getTask(id).assign_hr = data.assign_hr;
gantt.getTask(id).assign_material = data.assign_material;
gantt.getTask(id).assign_tools = data.assign_tools;
gantt.getTask(id).bobot_planning = data.bobot_planning;
gantt.getTask(id).rencana_biaya = data.rencana_biaya;
gantt.getTask(id).biaya_actual = data.biaya_actual;
gantt.getTask(id).progress = data.progress;
gantt.getTask(id).jobs_done = data.jobs_done ? data.jobs_done : 0;
gantt.updateTask(id);
actionHappen = false;
},
error: function (data) {
actionHappen = false;
}
});
2 years ago
}
/* Fungsi format ribuan label*/
2 years ago
function formatRupiah(n) {
1 year ago
var parts = n.toString().split(".");
2 years ago
return parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ".") + (parts[1] ? "," + parts[1] : "");
2 years ago
}
/* Fungsi format ribuan inputan*/
1 year ago
function formatRibuanInput(angka, prefix) {
2 years ago
var number_string = angka.replace(/[^,\d]/g, '').toString(),
1 year ago
split = number_string.split(','),
sisa = split[0].length % 3,
rupiah = split[0].substr(0, sisa),
ribuan = split[0].substr(sisa).match(/\d{3}/gi);
2 years ago
if (ribuan) {
separator = sisa ? '.' : '';
rupiah += separator + ribuan.join('.');
}
rupiah = split[1] != undefined ? rupiah + ',' + split[1] : rupiah;
return prefix == undefined ? rupiah : (rupiah ? 'Rp. ' + rupiah : '');
}
/* Fungsi replace titik, untuk save ke DB*/
1 year ago
function formatReplaceTitikRibuan(param) {
2 years ago
let myStr = param;
let newStr = myStr.replace(/\./g, '');
return newStr;
}
1 year ago
function formatDate(params) {
2 years ago
let today = new Date(params);
let yyyy = today.getFullYear();
let mm = today.getMonth() + 1; // Months start at 0!
let dd = today.getDate();
2 years ago
2 years ago
if (dd < 10) dd = '0' + dd;
if (mm < 10) mm = '0' + mm;
2 years ago
2 years ago
today = dd + '/' + mm + '/' + yyyy;
return today;
2 years ago
}
2 years ago
function roundToTwo(num) {
1 year ago
return +(Math.round(num + "e+2") + "e-2");
2 years ago
}
1 year ago
function initialProperty() {
2 years ago
$.ajax({
url: `${base_url}user-to-version-gantt/get-by-gantt/${ganttId}`,
1 year ago
type: "GET",
2 years ago
success: function (result) {
let data = result.data;
1 year ago
if (data.status && data.status == "not have") {
2 years ago
toggleCollapseTasks();
1 year ago
} else {
if (data.id) {
2 years ago
userToVersionGanttId = data.id
}
1 year ago
if (data.critical_path) {
2 years ago
gantt.config.highlight_critical_path = true;
$("#critalPathBox").prop("checked", true);
}
1 year ago
if (data.auto_schedule) {
2 years ago
gantt.config.auto_schedule = true;
$("#autoSchedule").prop("checked", true);
}
1 year ago
if (data.committed_cost) {
$("#committedCostBox").val(data.committed_cost);
}
1 year ago
if (data.cost_to_complete) {
$("#costToCompleteBox").val(data.cost_to_complete);
}
1 year ago
if (data.zoom) {
2 years ago
gantt.ext.zoom.setLevel(data.zoom);
1 year ago
$('input[value="' + data.zoom + '"]').prop("checked", true);
2 years ago
}
1 year ago
if (data.task_open) {
gantt.eachTask(function (task) {
2 years ago
task.$open = true;
});
toggleTasks = "Collapse";
$("#gantt_toggle_task_btn").prop('title', 'Collapse Activities');
$("#gantt_toggle_task_btn").children().removeClass('fa-expand-alt');
$("#gantt_toggle_task_btn").children().addClass('fa-compress-alt');
1 year ago
} else {
2 years ago
toggleCollapseTasks();
}
gantt.render();
}
},
error: function (data) {
}
});
2 years ago
}
1 year ago
function initializationColumn() {
2 years ago
$.ajax({
url: `${base_url}gantt-show-hide/get-by-gantt/${ganttId}`,
1 year ago
type: "GET",
2 years ago
success: function (result) {
let data = result.data;
1 year ago
if (data.status == "not yet have") {
2 years ago
addShowHideColumn();
1 year ago
} else if (data.status == "not have access") {
2 years ago
1 year ago
} else {
2 years ago
setUpForShowHideColumn(data);
}
},
error: function (data) {
}
});
2 years ago
}
1 year ago
function setGanttOpen() {
let ganttOpen = [];
gantt.eachTask(function (task) {
const existingIndex = ganttOpen.findIndex(item => item.id === task.id);
if (existingIndex !== -1) {
ganttOpen[existingIndex].open = task.$open;
} else {
ganttOpen.push({
"id": task.id,
"open": task.$open
});
}
});
localStorage.setItem('ganttOpen', JSON.stringify(ganttOpen));
}
1 year ago
function getGanttOpen() {
let ganttOpen = localStorage.getItem('ganttOpen');
if (ganttOpen) {
// Parse the stored data into a JavaScript object
ganttOpen = JSON.parse(ganttOpen);
gantt.eachTask(function (task) {
const index = ganttOpen.findIndex(item => item.id == task.id);
if (index !== -1) {
task.$open = ganttOpen[index].open;
} else {
task.$open = false;
}
});
}
}
2 years ago
$(document).ready(function () {
1 year ago
$("#critalPathBox").on("change", function () {
2 years ago
let checked = $(this).is(":checked");
1 year ago
if (checked) {
2 years ago
gantt.config.highlight_critical_path = true;
1 year ago
updateProperty({ critical_path: true })
} else {
2 years ago
gantt.config.highlight_critical_path = false;
1 year ago
updateProperty({ critical_path: false })
2 years ago
}
gantt.render();
});
1 year ago
$("#autoSchedule").on("change", function () {
2 years ago
let checked = $(this).is(":checked");
1 year ago
if (checked) {
2 years ago
gantt.config.auto_schedule = true;
1 year ago
updateProperty({ auto_schedule: true })
} else {
2 years ago
gantt.config.auto_schedule = false;
1 year ago
updateProperty({ auto_schedule: false })
2 years ago
}
gantt.render();
});
2 years ago
});
1 year ago
function linkLagEditor() {
2 years ago
1 year ago
function endPopup() {
2 years ago
modal = null;
editLinkId = null;
}
1 year ago
function cancelEditLink() {
2 years ago
endPopup()
}
1 year ago
function deleteLink() {
2 years ago
gantt.deleteLink(editLinkId);
endPopup()
}
1 year ago
function saveLink() {
2 years ago
var link = gantt.getLink(editLinkId);
var lagValue = modal.querySelector(".lag-input").value;
1 year ago
if (!isNaN(parseInt(lagValue, 10))) {
2 years ago
link.lag = parseInt(lagValue, 10);
}
gantt.updateLink(link.id);
1 year ago
if (gantt.autoSchedule) {
2 years ago
gantt.autoSchedule(link.source);
}
endPopup();
}
var modal;
var editLinkId;
1 year ago
gantt.attachEvent("onLinkDblClick", function (id, e) {
2 years ago
editLinkId = id;
var link = gantt.getLink(id);
var linkTitle;
1 year ago
switch (link.type) {
2 years ago
case gantt.config.links.finish_to_start:
linkTitle = "FS";
break;
case gantt.config.links.finish_to_finish:
linkTitle = "FF";
break;
case gantt.config.links.start_to_start:
linkTitle = "SS";
break;
case gantt.config.links.start_to_finish:
linkTitle = "SF";
break;
}
linkTitle += " " + gantt.getTask(link.source).text + " -> " + gantt.getTask(link.target).text;
modal = gantt.modalbox({
title: linkTitle,
text: "<div>" +
1 year ago
"<label>Lag <input type='number' class='lag-input' /></label>" +
"</div>",
2 years ago
buttons: [
1 year ago
{ label: "Save", css: "link-save-btn", value: "save" },
{ label: "Cancel", css: "link-cancel-btn", value: "cancel" },
{ label: "Delete", css: "link-delete-btn", value: "delete" }
2 years ago
],
width: "500px",
type: "popup-css-class-here",
1 year ago
callback: function (result) {
switch (result) {
2 years ago
case "save":
saveLink();
break;
case "cancel":
cancelEditLink();
break;
case "delete":
deleteLink();
break;
}
}
});
modal.querySelector(".lag-input").value = link.lag || 0;
//any custom logic here
return false;
});
2 years ago
}
1 year ago
function addShowHideColumn() {
2 years ago
let allColumn = [];
1 year ago
allColumns.forEach(function (column) {
2 years ago
allColumn.push(column.name);
});
submitShowHideColumn(allColumn);
2 years ago
}
1 year ago
function submitShowHideColumn(allColumn) {
2 years ago
let payload = {
1 year ago
version_gantt_id: ganttId,
columns: allColumn
2 years ago
}
$.ajax({
1 year ago
data: JSON.stringify(payload),
2 years ago
url: `${base_url}gantt-show-hide/add`,
type: "POST",
processData: false,
contentType: false,
success: function (data) {
},
error: function (data) {
}
});
2 years ago
}
1 year ago
function setUpForShowHideColumn(data) {
2 years ago
let columns = data || []
2 years ago
2 years ago
let configColumn = {}
2 years ago
2 years ago
columns.map((val, index) => {
configColumn[val.column_name] = val.show
});
2 years ago
2 years ago
gantt.config.columns = createColumnsConfig(configColumn);
2 years ago
2 years ago
gantt.render();
2 years ago
}
1 year ago
function updateShowHideColumn(data) {
2 years ago
let payload = {
1 year ago
columns: data
2 years ago
}
$.ajax({
1 year ago
data: JSON.stringify(payload),
2 years ago
url: `${base_url}gantt-show-hide/update/${ganttId}`,
type: "POST",
processData: false,
contentType: false,
success: function (data) {
console.log(data);
},
error: function (data) {
console.log(data);
}
});
2 years ago
}
function colAjaxReq(type) {
let ajx = $.ajax({
url: `${base_url}gantt-show-hide/get-column-by-type/${type}`,
type: "GET",
success: function (data) {
let ganttColumnsByType = data.data;
let isFound = false;
x = gantt.config.columns.filter((val) => {
isFound = ganttColumnsByType.find(obj => {
return obj.column_name == val.name;
});
1 year ago
if (isFound)
return val;
});
gantt.config.columns = x.filter(item => item);
allColumns = gantt.config.columns;
gantt.render();
}
});
}
1 year ago
async function reRenderColumns(type) {
await colAjaxReq(type);
}
1 year ago
function updateProperty(payload) {
if (userToVersionGanttId > 0 && readOnly && parseInt(readOnly) == 0) {
2 years ago
$.ajax({
1 year ago
data: JSON.stringify(payload),
2 years ago
url: `${base_url}user-to-version-gantt/update/${userToVersionGanttId}`,
type: "PUT",
processData: false,
contentType: false,
success: function (data) {
},
error: function (data) {
}
});
}
2 years ago
}
1 year ago
function costPlanningChange(e) {
2 years ago
let value = e.value;
value = replaceAll(value, ".", "")
value = replaceAll(value, ",", ".")
let newValue = formatRupiah(value);
$(e).val(newValue)
2 years ago
}
function escapeRegExp(string) {
2 years ago
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
2 years ago
}
function replaceAll(str, find, replace) {
1 year ago
if (str) {
2 years ago
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}
return str
}
1 year ago
function expandTask() {
gantt.eachTask(function (task) {
task.$open = true;
});
toggleTasks = "Collapse";
$("#gantt_toggle_task_btn").prop('title', 'Collapse Activities');
$("#gantt_toggle_task_btn").children().removeClass('fa-expand-alt');
$("#gantt_toggle_task_btn").children().addClass('fa-compress-alt');
gantt.render();
}
function resetActivity() {
localStorage.setItem('batchEntity', '');
gantt.alert("Actiivity Saved");
}