diff --git a/src/const/CustomFunc.js b/src/const/CustomFunc.js index bf29083..5d151c3 100644 --- a/src/const/CustomFunc.js +++ b/src/const/CustomFunc.js @@ -1,402 +1,398 @@ -export const hideAttr = [ - "geom", - "password", - "id", - "username", - "created_date", - "created_by", - "modified_date", - "modified_by", - "updated_by", - "updated_date", - "updated_at", - "session_login", - "company", - "buffer_radius", - "group_sales", - "OBJECTID", - "fcm_token", - "key", - "planning_id", - "subproyek_id", - "user_id", - "created_at", - "_type", // waspang - "satuan_id", - "m_planning_nama", - "m_planning_target", - "m_satuan_description", - "m_subproyek_akhir_proyek", - "m_subproyek_area_kerja", - "m_subproyek_biaya", - "m_subproyek_biaya_actual", - "m_subproyek_color_progress", - "m_subproyek_jumlah_pekerja", - "m_subproyek_ket_progress", - "m_subproyek_lokasi_kantor", - "m_subproyek_mulai_proyek", - "m_subproyek_nama", - "m_subproyek_persentase_progress_actual", - "m_subproyek_persentase_progress_plan", - "m_users_email", - "m_users_username", - "m_planning_address", - "m_planning_jumlah_titik", - "m_planning_target_planning", - "m_satuan_name", - "m_subproyek_pic", - "m_users_gender", - "m_users_name", - "m_users_phone_number", -]; - -export const salesAttrShow = [ - "id", - "group_sales_name", - "name", - "phone_number", - "email", - "address" -]; - -export const dateColumns = [ - "created_date", - "modified_date", - "birth_date", - "datesend", // last_waypoint_employee - "wptime", // last_waypoint_employee - "tanggal", - "mulai_tugas", - "akhir_tugas" -]; - -export const DATE_TIME_FORMAT = "DD-MM-YYYY"; - -export const COLUMN_DAILY_INFO_TABLE = [ - { - dataField: 'id', - text: 'ID', - hidden: true - }, - { - dataField: 'join.group_employee_name', - text: 'Group Employee' - }, - { - dataField: 'name', - text: 'Name' - }, - { - dataField: 'phone_number', - text: 'Phone Number' - }, - { - dataField: 'email', - text: 'Email' - }, - { - dataField: 'address', - text: 'Address' - }, - { - dataField: 'clock_in', - text: 'Clock In' - }, - { - dataField: 'clock_out', - text: 'Clock Out' - } -] - -export const formatLabel = (label) => { - let output = ""; - - if (label.includes("_")) { - let words = label.split("_"); - for (let i=0; i < words.length; i++) { - words[i] = words[i].charAt(0).toUpperCase() + words[i].substr(1); - } - output = words.join(' '); - } - else { - output = label.charAt(0).toUpperCase() + label.slice(1); - } - return output; -} - -export const QUERY_BUILDER_FIELD_SALES = -{ - "properties->username": { - label: 'Username', - type: 'text', - valueSources: ['value'], - }, - "properties->name": { - label: 'Name', - type: 'text', - valueSources: ['value'], - }, - "properties->email": { - label: 'Email', - type: 'text', - valueSources: ['value'], - }, - "properties->address": { - label: 'Address', - type: 'text', - valueSources: ['value'], - }, - "properties->phone_number": { - label: 'Phone Number', - type: 'number', - valueSources: ['value'], - }, - "properties->type_sales": { - label: 'Type Sales', - type: 'select', - valueSources: ['value'], - fieldSettings: { - listValues: [ - { value: 'B2B', title: 'B2B' }, - { value: 'B2C', title: 'B2C' }, - ], - } - }, -} - -export const checkActMenup = (menuPath, actProp) => { - let foundObj; - let entireObj = JSON.parse(localStorage.getItem("menu_login")); - JSON.stringify(entireObj, (_, nestedValue) => { - if (nestedValue && nestedValue.url === menuPath) { - foundObj = nestedValue; - } - return nestedValue; - }); - - let output = false; - let actValue = actProp.trim().toLowerCase() - switch (actValue) { - case "create": - if (foundObj[actValue] === true) { - output = true; - } else { - output = false; - - } - case "read": - if (foundObj[actValue] === true) { - output = true; - } - case "update": - if (foundObj[actValue] === true) { - output = true; - } - case "delete": - if (foundObj[actValue] === true) { - output = true; - } - // default: - // output = false - } - - return output; - // return foundObj[actProp]; -}; - -export const QUERY_BUILDER_FIELD_CUSTOMER = -{ - "properties->name": { - label: 'Name', - type: 'text', - valueSources: ['value'], - }, - "properties->buffer_radius": { - label: 'Buffer Radius', - type: 'number', - fieldSettings: { - min: 1, - }, - valueSources: ['value'], - }, - "properties->address": { - label: 'Address', - type: 'text', - valueSources: ['value'], - }, - "properties->income": { - label: 'Income', - type: 'number', - valueSources: ['value'], - }, - "properties->store_manager": { - label: 'Store Manager', - type: 'text', - valueSources: ['value'], - }, -} - -export const QUERY_BUILDER_FIELD_OFFICE = -{ - "properties->company": { - label: 'Company', - type: 'text', - valueSources: ['value'], - }, - "properties->name": { - label: 'Name', - type: 'text', - valueSources: ['value'], - }, - "properties->employes": { - label: 'Employe', - type: 'text', - valueSources: ['value'], - }, - "properties->address": { - label: 'Alamat', - type: 'text', - valueSources: ['value'], - }, -} - - -export const getChildrenTree = (data) => - data.map((item, index) => { - if (item.subproyeks && item.subproyeks.length > 0) { - return { - "children": getChildrenTree(item.subproyeks), - "title": item.nama, - "key": Math.random(), - "id": item.id, - ...item - } - } - return { - "title": item.nama, - "key": Math.random(), - ...item - } - }) - -export const formatRupiah = (angka, prefix) => { - 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 prefix == undefined ? rupiah : (rupiah ? 'Rp. ' + rupiah : ''); -} - -export const renderFormatRupiah = (text, prefix) => { - text = text.split('.')[0]; - if (text) { - return formatRupiah(text, prefix) - } else { - return "-" - } -} - -export const formatNumber = (angka) => { - 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 -} - - -export const formatThousand = (x) => { - return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."); -} - -export const formatLargeNumber = (num) => { - const formattedNum = formatThousand(num); - if (num >= 1000000000000) { - return `${(num / 1000000000000).toFixed(1)}T`; - } else if (num >= 1000000000) { - return `${(num / 1000000000).toFixed(1)}M`; - } else if (num >= 1000000) { - return `${(num / 1000000).toFixed(1)}Jt`; - } - return formattedNum; -}; -/* -Using it: -sortBy(data, { - prop: "date", - desc: true, - parser: function (item) { - return item.toUpperCase(); - } -}); -*/ -export const sortBy = (function () { - var toString = Object.prototype.toString, - parse = function (x) { return x; }, - getItem = function (x) { - var isObject = x != null && typeof x === "object"; - var isProp = isObject && this.prop in x; - return this.parser(isProp ? x[this.prop] : x); - }; - - /** - * Sorts an array of elements. - * - * @param {Array} array: the collection to sort - * @param {Object} cfg: the configuration options - * @property {String} cfg.prop: property name (if it is an Array of objects) - * @property {Boolean} cfg.desc: determines whether the sort is descending - * @property {Function} cfg.parser: function to parse the items to expected type - * @return {Array} - */ - return function sortby (array, cfg) { - if (!(array instanceof Array && array.length)) return []; - if (toString.call(cfg) !== "[object Object]") cfg = {}; - if (typeof cfg.parser !== "function") cfg.parser = parse; - cfg.desc = !!cfg.desc ? -1 : 1; - return array.sort(function (a, b) { - a = getItem.call(cfg, a); - b = getItem.call(cfg, b); - return cfg.desc * (a < b ? -1 : +(a > b)); - }); - }; - -}()); - - -export const uniqueKeyValues = (arr, key) => { - return [... new Set(arr.map((obj) => {return obj[key]}))]; -} - -export const renderLabelStatus = (text) => { - let label = text; - if (text === 'fom' || text === 'fot' || text === 'po') { - label = text.toUpperCase(); - } - return label; -} - -export const formatRibuanDecimal = (n) => { - let parts=n.toString().split("."); - return "Rp. " + parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ".") + (parts[1] ? "," + parts[1] : ""); -} - -export const capitalizeFirstLetter = (string) => { - return string.charAt(0).toUpperCase() + string.slice(1); -} +export const hideAttr = [ + "geom", + "password", + "id", + "username", + "created_date", + "created_by", + "modified_date", + "modified_by", + "updated_by", + "updated_date", + "updated_at", + "session_login", + "company", + "buffer_radius", + "group_sales", + "OBJECTID", + "fcm_token", + "key", + "planning_id", + "subproyek_id", + "user_id", + "created_at", + "_type", // waspang + "satuan_id", + "m_planning_nama", + "m_planning_target", + "m_satuan_description", + "m_subproyek_akhir_proyek", + "m_subproyek_area_kerja", + "m_subproyek_biaya", + "m_subproyek_biaya_actual", + "m_subproyek_color_progress", + "m_subproyek_jumlah_pekerja", + "m_subproyek_ket_progress", + "m_subproyek_lokasi_kantor", + "m_subproyek_mulai_proyek", + "m_subproyek_nama", + "m_subproyek_persentase_progress_actual", + "m_subproyek_persentase_progress_plan", + "m_users_email", + "m_users_username", + "m_planning_address", + "m_planning_jumlah_titik", + "m_planning_target_planning", + "m_satuan_name", + "m_subproyek_pic", + "m_users_gender", + "m_users_name", + "m_users_phone_number", +]; + +export const salesAttrShow = [ + "id", + "group_sales_name", + "name", + "phone_number", + "email", + "address" +]; + +export const dateColumns = [ + "created_date", + "modified_date", + "birth_date", + "datesend", // last_waypoint_employee + "wptime", // last_waypoint_employee + "tanggal", + "mulai_tugas", + "akhir_tugas" +]; + +export const DATE_TIME_FORMAT = "DD-MM-YYYY"; + +export const COLUMN_DAILY_INFO_TABLE = [ + { + dataField: 'id', + text: 'ID', + hidden: true + }, + { + dataField: 'join.group_employee_name', + text: 'Group Employee' + }, + { + dataField: 'name', + text: 'Name' + }, + { + dataField: 'phone_number', + text: 'Phone Number' + }, + { + dataField: 'email', + text: 'Email' + }, + { + dataField: 'address', + text: 'Address' + }, + { + dataField: 'clock_in', + text: 'Clock In' + }, + { + dataField: 'clock_out', + text: 'Clock Out' + } +] + +export const formatLabel = (label) => { + let output = ""; + + if (label.includes("_")) { + let words = label.split("_"); + for (let i=0; i < words.length; i++) { + words[i] = words[i].charAt(0).toUpperCase() + words[i].substr(1); + } + output = words.join(' '); + } + else { + output = label.charAt(0).toUpperCase() + label.slice(1); + } + return output; +} + +export const QUERY_BUILDER_FIELD_SALES = +{ + "properties->username": { + label: 'Username', + type: 'text', + valueSources: ['value'], + }, + "properties->name": { + label: 'Name', + type: 'text', + valueSources: ['value'], + }, + "properties->email": { + label: 'Email', + type: 'text', + valueSources: ['value'], + }, + "properties->address": { + label: 'Address', + type: 'text', + valueSources: ['value'], + }, + "properties->phone_number": { + label: 'Phone Number', + type: 'number', + valueSources: ['value'], + }, + "properties->type_sales": { + label: 'Type Sales', + type: 'select', + valueSources: ['value'], + fieldSettings: { + listValues: [ + { value: 'B2B', title: 'B2B' }, + { value: 'B2C', title: 'B2C' }, + ], + } + }, +} + +export const checkActMenup = (menuPath, actProp) => { + let foundObj; + let entireObj = JSON.parse(localStorage.getItem("menu_login")); + JSON.stringify(entireObj, (_, nestedValue) => { + if (nestedValue && nestedValue.url === menuPath) { + foundObj = nestedValue; + } + return nestedValue; + }); + + let output = false; + let actValue = actProp.trim().toLowerCase() + switch (actValue) { + case "create": + if (foundObj[actValue] === true) { + output = true; + } else { + output = false; + + } + case "read": + if (foundObj[actValue] === true) { + output = true; + } + case "update": + if (foundObj[actValue] === true) { + output = true; + } + case "delete": + if (foundObj[actValue] === true) { + output = true; + } + } + return output; +}; + +export const QUERY_BUILDER_FIELD_CUSTOMER = +{ + "properties->name": { + label: 'Name', + type: 'text', + valueSources: ['value'], + }, + "properties->buffer_radius": { + label: 'Buffer Radius', + type: 'number', + fieldSettings: { + min: 1, + }, + valueSources: ['value'], + }, + "properties->address": { + label: 'Address', + type: 'text', + valueSources: ['value'], + }, + "properties->income": { + label: 'Income', + type: 'number', + valueSources: ['value'], + }, + "properties->store_manager": { + label: 'Store Manager', + type: 'text', + valueSources: ['value'], + }, +} + +export const QUERY_BUILDER_FIELD_OFFICE = +{ + "properties->company": { + label: 'Company', + type: 'text', + valueSources: ['value'], + }, + "properties->name": { + label: 'Name', + type: 'text', + valueSources: ['value'], + }, + "properties->employes": { + label: 'Employe', + type: 'text', + valueSources: ['value'], + }, + "properties->address": { + label: 'Alamat', + type: 'text', + valueSources: ['value'], + }, +} + + +export const getChildrenTree = (data) => + data.map((item, index) => { + if (item.subproyeks && item.subproyeks.length > 0) { + return { + "children": getChildrenTree(item.subproyeks), + "title": item.nama, + "key": Math.random(), + "id": item.id, + ...item + } + } + return { + "title": item.nama, + "key": Math.random(), + ...item + } + }) + +export const formatRupiah = (angka, prefix) => { + 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 prefix == undefined ? rupiah : (rupiah ? 'Rp. ' + rupiah : ''); +} + +export const renderFormatRupiah = (text, prefix) => { + text = text.split('.')[0]; + if (text) { + return formatRupiah(text, prefix) + } else { + return "-" + } +} + +export const formatNumber = (angka) => { + 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 +} + + +export const formatThousand = (x) => { + return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."); +} + +export const formatLargeNumber = (num) => { + const formattedNum = formatThousand(num); + if (num >= 1000000000000) { + return `${(num / 1000000000000).toFixed(1)}T`; + } else if (num >= 1000000000) { + return `${(num / 1000000000).toFixed(1)}M`; + } else if (num >= 1000000) { + return `${(num / 1000000).toFixed(1)}Jt`; + } + return formattedNum; +}; +/* +Using it: +sortBy(data, { + prop: "date", + desc: true, + parser: function (item) { + return item.toUpperCase(); + } +}); +*/ +export const sortBy = (function () { + var toString = Object.prototype.toString, + parse = function (x) { return x; }, + getItem = function (x) { + var isObject = x != null && typeof x === "object"; + var isProp = isObject && this.prop in x; + return this.parser(isProp ? x[this.prop] : x); + }; + + /** + * Sorts an array of elements. + * + * @param {Array} array: the collection to sort + * @param {Object} cfg: the configuration options + * @property {String} cfg.prop: property name (if it is an Array of objects) + * @property {Boolean} cfg.desc: determines whether the sort is descending + * @property {Function} cfg.parser: function to parse the items to expected type + * @return {Array} + */ + return function sortby (array, cfg) { + if (!(array instanceof Array && array.length)) return []; + if (toString.call(cfg) !== "[object Object]") cfg = {}; + if (typeof cfg.parser !== "function") cfg.parser = parse; + cfg.desc = !!cfg.desc ? -1 : 1; + return array.sort(function (a, b) { + a = getItem.call(cfg, a); + b = getItem.call(cfg, b); + return cfg.desc * (a < b ? -1 : +(a > b)); + }); + }; + +}()); + + +export const uniqueKeyValues = (arr, key) => { + return [... new Set(arr.map((obj) => {return obj[key]}))]; +} + +export const renderLabelStatus = (text) => { + let label = text; + if (text === 'fom' || text === 'fot' || text === 'po') { + label = text.toUpperCase(); + } + return label; +} + +export const formatRibuanDecimal = (n) => { + let parts=n.toString().split("."); + return "Rp. " + parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ".") + (parts[1] ? "," + parts[1] : ""); +} + +export const capitalizeFirstLetter = (string) => { + return string.charAt(0).toUpperCase() + string.slice(1); +} diff --git a/src/views/Dashboard/DashboardBOD.js b/src/views/Dashboard/DashboardBOD.js index a63d260..b02eb47 100644 --- a/src/views/Dashboard/DashboardBOD.js +++ b/src/views/Dashboard/DashboardBOD.js @@ -521,7 +521,6 @@ const DashboardBOD = (props) => { datasets: [ { label: '', - // data: [COMPANY_CASHFLOW_TOTAL_BUDGET, COMPANY_CASHFLOW_EXPENDITURE, COMPANY_CASHFLOW_INVOICE, COMPANY_CASHFLOW_CASH_IN], data: [ PROJECT_EXPENDITURE && PROJECT_EXPENDITURE.total_budget ? PROJECT_EXPENDITURE.total_budget : 0, PROJECT_EXPENDITURE && PROJECT_EXPENDITURE.total_expenditure ? PROJECT_EXPENDITURE.total_expenditure : 0, @@ -557,10 +556,6 @@ const DashboardBOD = (props) => { backgroundColor="#f3f3f3" foregroundColor="#ecebeb" > - {/* - - - */} @@ -584,7 +579,6 @@ const DashboardBOD = (props) => { datasets: [ { label: "", - // data: [2, 4, 10], data: [ PROJECT_BY_FINANCIAL_HEALTH && PROJECT_BY_FINANCIAL_HEALTH.overrun ? PROJECT_BY_FINANCIAL_HEALTH.overrun : '', PROJECT_BY_FINANCIAL_HEALTH && PROJECT_BY_FINANCIAL_HEALTH.warning ? PROJECT_BY_FINANCIAL_HEALTH.warning : '', @@ -618,7 +612,6 @@ const DashboardBOD = (props) => { datasets: [ { label: "", - // data: [1, 3, 11], data: [ PROJECT_BY_SCHEDULE_HEALTH && PROJECT_BY_SCHEDULE_HEALTH['behind-schedule'] ? PROJECT_BY_SCHEDULE_HEALTH['behind-schedule'] : '', PROJECT_BY_SCHEDULE_HEALTH && PROJECT_BY_SCHEDULE_HEALTH.warning ? PROJECT_BY_SCHEDULE_HEALTH.warning : '', @@ -664,7 +657,6 @@ const DashboardBOD = (props) => { position: 'right', labels: { boxWidth: 10, - // padding: 15, font: { size: 10 } @@ -674,7 +666,6 @@ const DashboardBOD = (props) => { datalabels: { color: '#FFFFFF', formatter: function (value, context) { - // return value ? value : null if (value && value > 0) { return value; } @@ -684,12 +675,10 @@ const DashboardBOD = (props) => { } }} chartData={PROJECT_PER_DIVISION ? { - // labels: [['Telecommunication', 'Solution Service'], ['Telecommunication', 'Solution Product'], 'Energy Solution', 'Constructions'], labels: PROJECT_PER_DIVISION ? PROJECT_PER_DIVISION.map((item, idx) => item.name) : [], datasets: [ { label: "", - // data: [7, 2, 4, 3], data: PROJECT_PER_DIVISION ? PROJECT_PER_DIVISION.map((item, idx) => item.total) : [], borderColor: PROJECT_PER_DIVISION ? PROJECT_PER_DIVISION.map((item, idx) => item.color) : [], backgroundColor: PROJECT_PER_DIVISION ? PROJECT_PER_DIVISION.map((item, idx) => item.color) : [], @@ -720,7 +709,6 @@ const DashboardBOD = (props) => { position: 'right', labels: { boxWidth: 10, - // padding: 15, font: { size: 10 } @@ -730,19 +718,16 @@ const DashboardBOD = (props) => { datalabels: { color: '#FFFFFF', formatter: function (value, context) { - // return value ? toRupiah(value, { useUnit: 'jt' }) : 0 return null; } } } }} chartData={PROJECT_VALUE_PER_DIVISION ? { - // labels: [['Telecommunication', 'Solution Service'], ['Telecommunication', 'Solution Product'], 'Energy Solution', 'Constructions'], labels: PROJECT_VALUE_PER_DIVISION ? PROJECT_VALUE_PER_DIVISION.map((item, idx) => item.name) : [], datasets: [ { label: "", - // data: [50, 120, 72, 60], data: PROJECT_VALUE_PER_DIVISION ? PROJECT_VALUE_PER_DIVISION.map((item, idx) => item.total).filter(value => value !== 0) : [], borderColor: PROJECT_VALUE_PER_DIVISION ? PROJECT_VALUE_PER_DIVISION.map((item, idx) => item.color) : [], backgroundColor: PROJECT_VALUE_PER_DIVISION ? PROJECT_VALUE_PER_DIVISION.map((item, idx) => item.color) : [], @@ -788,7 +773,6 @@ const DashboardBOD = (props) => { } }} data={{ - // labels: ["Initiation", "Planning", "Execution", "Control Monitoring", "Close"], labels: PROJECT_BY_PHASE ? PROJECT_BY_PHASE.map((item, idx) => item.name) : [], datasets: [ { @@ -814,10 +798,6 @@ const DashboardBOD = (props) => { backgroundColor="#f3f3f3" foregroundColor="#ecebeb" > - {/* - - - */} @@ -876,9 +856,7 @@ const DashboardBOD = (props) => { }, datalabels: { color: '#FFFFFF', - // rotation: -90 formatter: function (value, context) { - // return value ? toRupiah(value, { useUnit: 'jt' }) : 0 return null; } } @@ -925,8 +903,6 @@ const DashboardBOD = (props) => { changeMode={(mode) => setHealthPerDivisionMode(mode)} chartType="vertical-bar" chartData={PROJECT_SCHEDULE_HEALTH_PER_DIVISION || PROJECT_BUDGET_HEALTH_PER_DIVISION ? { - // labels: ['Telecommunication Solution Service', 'Telecommunication Solution Product', 'Energy Solution', 'Constructions'], - // labels: [['Telecommunication', 'Solution Service'], ['Telecommunication', 'Solution Product'], 'Energy Solution', 'Constructions'], labels: healthPerDivisionMode === 'schedule' ? PROJECT_SCHEDULE_HEALTH_PER_DIVISION ? PROJECT_SCHEDULE_HEALTH_PER_DIVISION.map((item, idx) => item.name) : []