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.
679 lines
18 KiB
679 lines
18 KiB
import { |
|
API_GEOHR_WAYPOINT_SALES_MONITORING, |
|
API_GEOHR_SALES_MONITORING, |
|
API_GEOHR_OFFICE_MONITORING, |
|
API_GEOHR_CUSTOMER_MONITORING, |
|
API_GEOHR_DAILY_INFO , |
|
API_GEOHR_SALES_SEARCH, |
|
API_GEOHR_EMPLOYEE_MONITORING, |
|
API_GEOHR_WAYPOINT_EMPLOYEE_MONITORING, |
|
API_DAILY_INFO_DETAIL, |
|
USER_TO_PROYEK_SEARCH, |
|
API_SIMPRO_WAYPOINT_WASPANG_MONITORING, |
|
WAYPOINT_SEARCH |
|
} from './ApiConst.js' |
|
import { toast } from 'react-toastify'; |
|
const id_org = window.localStorage.getItem('id_org'); |
|
const roleName = window.localStorage.getItem('role_name'); |
|
export const getSalesRoutingApi = async (salesId, dateString) => { |
|
console.log('[GeohrApiFunc.js] getSalesRoutingApi', salesId, dateString); |
|
|
|
let bodyParam = { |
|
"paging": {"start": 0, "length": -1}, |
|
"columns": [ |
|
{"name":"wptime", "logic_operator": "range", "value": dateString[0], "value1": dateString[1], "operator": "and"} |
|
], |
|
"orders": {"columns": ["wptime"], "ascending": true} |
|
} |
|
|
|
const param = { |
|
method: 'POST', |
|
header: JSON.stringify({'Content-Type': 'application/json'}), |
|
body: JSON.stringify(bodyParam) |
|
} |
|
|
|
try { |
|
const result = await fetch(API_GEOHR_WAYPOINT_SALES_MONITORING(salesId), param).then(response => response.json()).then(res => res); |
|
console.log('getSalesRoutingApi result', result); |
|
if (result.data) { |
|
|
|
let output = { |
|
type: "FeatureCollection", |
|
features: [] |
|
}; |
|
|
|
if (result.data.features && result.data.features.length > 0) { |
|
for (let i=0; i < result.data.features.length; i++) { |
|
if ((result.data.features[i].geometry.coordinates && result.data.features[i].geometry.coordinates.length > 0) && result.data.features[i].geometry.type) { |
|
output.features.push(result.data.features[i]); |
|
} |
|
} |
|
} |
|
|
|
return output; |
|
} |
|
else { |
|
return null; |
|
} |
|
} |
|
catch (e) { |
|
console.log('error getSalesRoutingApi', e); |
|
return null; |
|
} |
|
} |
|
|
|
export const getSalesFeatures = async (filterGroup, salesGroupTree) => { |
|
|
|
const LENGTH_SALES_TREE_CHILDREN = salesGroupTree[0].children.length; |
|
|
|
let bodyParam = { |
|
"paging": {"start": 0, "length": -1}, |
|
"joins": [ |
|
{"name": "group_sales", "column_results": ["name", "description"]} |
|
], |
|
"orders": {"columns": ["name"], "ascending": true} |
|
} |
|
|
|
if (filterGroup.length > 0 && filterGroup.length !== LENGTH_SALES_TREE_CHILDREN) { |
|
console.log('filterrrrr'); |
|
bodyParam["columns"] = []; |
|
|
|
bodyParam.columns.push({"name":"group_sales_id","logic_operator":"in","value":filterGroup.join(),"operator":"and"}); |
|
|
|
console.log('bodyParam', bodyParam); |
|
} |
|
|
|
const param = { |
|
method: 'POST', |
|
header: JSON.stringify({'Content-Type': 'application/json'}), |
|
body: JSON.stringify(bodyParam) |
|
} |
|
|
|
try { |
|
const result = await fetch(API_GEOHR_SALES_MONITORING, param).then(response => response.json()).then(res => res); |
|
console.log('getSalesFeatures result', result); |
|
if (result.data) { |
|
|
|
let output = { |
|
type: "FeatureCollection", |
|
features: [] |
|
}; |
|
|
|
if (result.data.features && result.data.features.length > 0) { |
|
for (let i=0; i < result.data.features.length; i++) { |
|
if (result.data.features[i].geometry.coordinates !== null && result.data.features[i].geometry.type !== null) { |
|
output.features.push(result.data.features[i]); |
|
} |
|
} |
|
} |
|
|
|
return output; |
|
} |
|
else { |
|
return null; |
|
} |
|
} |
|
catch (e) { |
|
console.log('error getSalesFeatures', e); |
|
return null; |
|
} |
|
} |
|
|
|
export const getOfficeFeatures = async () => { |
|
const param = { |
|
method: 'POST', |
|
header: JSON.stringify({'Content-Type': 'application/json'}), |
|
body: JSON.stringify({ |
|
"paging": {"start": 0, "length": -1}, |
|
"columns": [ |
|
{"name":"name", "logic_operator": "ilike", "value": "", "operator": "and"} |
|
], |
|
"orders": {"columns": ["name"], "ascending": true} |
|
}) |
|
} |
|
|
|
try { |
|
const result = await fetch(API_GEOHR_OFFICE_MONITORING, param).then(response => response.json()).then(res => res); |
|
console.log('getOfficeFeatures result', result); |
|
if (result.data) { |
|
return result.data; |
|
} |
|
else { |
|
return null; |
|
} |
|
} |
|
catch (e) { |
|
console.log('error getOfficeFeatures', e); |
|
return null; |
|
} |
|
} |
|
|
|
export const getCustomerFeatures = async () => { |
|
let bodyParam = { |
|
"paging": {"start": 0, "length": -1}, |
|
"columns": [ |
|
{"name":"name", "logic_operator": "ilike", "value": "", "operator": "and"} |
|
], |
|
"orders": {"columns": ["name"], "ascending": true} |
|
} |
|
|
|
const param = { |
|
method: 'POST', |
|
header: JSON.stringify({'Content-Type': 'application/json'}), |
|
body: JSON.stringify(bodyParam) |
|
} |
|
|
|
try { |
|
const result = await fetch(API_GEOHR_CUSTOMER_MONITORING, param).then(response => response.json()).then(res => res); |
|
console.log('getCustomerFeatures result', result); |
|
if (result.data) { |
|
|
|
let output = { |
|
type: "FeatureCollection", |
|
features: [] |
|
}; |
|
|
|
if (result.data.features && result.data.features.length > 0) { |
|
for (let i=0; i < result.data.features.length; i++) { |
|
if (result.data.features[i].geometry.coordinates !== null && result.data.features[i].geometry.type !== null) { |
|
output.features.push(result.data.features[i]); |
|
} |
|
} |
|
} |
|
|
|
return output; |
|
} |
|
else { |
|
return null; |
|
} |
|
} |
|
catch (e) { |
|
console.log('error getCustomerFeatures', e); |
|
return null; |
|
} |
|
} |
|
|
|
|
|
/* |
|
Expected output: |
|
{ |
|
"code": 200, |
|
"data": { |
|
"at_trip": { |
|
"total": 0, |
|
"sales_ids": [] |
|
}, |
|
"at_customer": { |
|
"total": 0, |
|
"sales_ids": [] |
|
}, |
|
"at_office": { |
|
"total": 0, |
|
"sales_ids": [] |
|
}, |
|
"attendance": { |
|
"total": 0, |
|
"sales_ids": [] |
|
}, |
|
"absent": { |
|
"total": 11, |
|
"sales_ids": [ |
|
1, |
|
2, |
|
7, |
|
8, |
|
12, |
|
16, |
|
17, |
|
18, |
|
19, |
|
20, |
|
21 |
|
] |
|
}, |
|
"sales_total": { |
|
"total": 11, |
|
"sales_ids": [ |
|
1, |
|
2, |
|
7, |
|
8, |
|
12, |
|
16, |
|
17, |
|
18, |
|
19, |
|
20, |
|
21 |
|
] |
|
}, |
|
"at_time": "2021-06-18T10:45:26.19278792+07:00" |
|
}, |
|
"executionTime": "23.932818ms", |
|
"message": "OK" |
|
} |
|
*/ |
|
export const getDailyInfoApi = async () => { |
|
|
|
const typeSales = "B2B"; |
|
|
|
const param = { |
|
method: 'GET', |
|
header: JSON.stringify({'Content-Type': 'application/json'}), |
|
} |
|
|
|
try { |
|
const result = await fetch(API_GEOHR_DAILY_INFO, param).then(response => response.json()).then(res => res); |
|
console.log('getDailyInfoApi result', result); |
|
if (result.data) { |
|
|
|
|
|
|
|
|
|
return result.data; |
|
} |
|
else { |
|
return null; |
|
} |
|
} |
|
catch (e) { |
|
console.log('error getDailyInfoApi', e); |
|
return null; |
|
} |
|
} |
|
|
|
/* |
|
export const requestTableDailyInfoApi = async (item) => { |
|
console.log('requestTableDailyInfoApi item', item); |
|
let filterSales = item.sales_ids; |
|
|
|
|
|
if (filterSales && filterSales.length < 1 && item.total === 0) { |
|
return null; // data is empty |
|
} |
|
else { |
|
let bodyParam = { |
|
"paging": {"start": 0, "length": -1}, |
|
"joins": [ |
|
{"name": "group_sales", "column_results": ["name", "description"]} |
|
], |
|
"orders": {"columns": ["name"], "ascending": true} |
|
} |
|
|
|
if (filterSales && filterSales.length > 0) { |
|
bodyParam["columns"] = []; |
|
bodyParam.columns.push({"name":"id","logic_operator":"in","value":filterSales.join(),"operator":"and"}); |
|
} |
|
|
|
const param = { |
|
method: 'POST', |
|
header: JSON.stringify({'Content-Type': 'application/json'}), |
|
body: JSON.stringify(bodyParam) |
|
} |
|
|
|
try { |
|
const result = await fetch(API_GEOHR_SALES_SEARCH, param).then(response => response.json()).then(res => res); |
|
console.log('requestTableDailyInfoApi result', result); |
|
if (result.data) { |
|
return result.data; |
|
} |
|
else { |
|
return null; |
|
} |
|
} |
|
catch (e) { |
|
console.log('error requestTableDailyInfoApi', e); |
|
return null; |
|
} |
|
} |
|
}*/ |
|
|
|
export const requestTableDailyInfoApi = async (param) => { |
|
const formData = new FormData(); |
|
let start = 0; |
|
if (param.currentPage !== 1) { |
|
start = (param.currentPage * param.rowsPerPage) - param.rowsPerPage |
|
} |
|
formData.append('table_type', param.table_type); |
|
formData.append("id_org", id_org); |
|
formData.append('field', param.searchDetailField); |
|
if(param.search!=="" && param.search!==null){ |
|
formData.append('value', param.search); |
|
} |
|
|
|
|
|
const length = param.rowsPerPage; |
|
|
|
const payload = { |
|
method: 'POST', |
|
header: JSON.stringify({'Content-Type': 'multipart/form-data'}), |
|
body: formData |
|
} |
|
|
|
try { |
|
const result = await fetch(API_DAILY_INFO_DETAIL(start,length), payload).then(response => response.json()).then(res => res); |
|
if (result.code_status === 200 && result.data) { |
|
return result; |
|
} |
|
else { |
|
return null; |
|
} |
|
} |
|
catch (e) { |
|
console.log('error get', e); |
|
toast.warn(e.toString()); |
|
return null; |
|
} |
|
} |
|
|
|
export const getEmployeeFeatures = async (filterGroup, employeeDivTree) => { |
|
const LENGTH_EMP_DIV_TREE_CHILDREN = employeeDivTree[0].children.length; |
|
|
|
let bodyParam = { |
|
"paging": {"start": 0, "length": -1}, |
|
"joins": [ |
|
{"name": "employee_division", "column_results": ["name", "description"]} |
|
], |
|
"orders": {"columns": ["name"], "ascending": true} |
|
} |
|
|
|
if (filterGroup.length > 0 && filterGroup.length !== LENGTH_EMP_DIV_TREE_CHILDREN) { |
|
console.log('filterrrrr'); |
|
bodyParam["columns"] = []; |
|
|
|
bodyParam.columns.push({"name":"employee_division_id","logic_operator":"in","value":filterGroup.join(),"operator":"and"}); |
|
|
|
console.log('bodyParam', bodyParam); |
|
} |
|
|
|
const param = { |
|
method: 'POST', |
|
header: JSON.stringify({'Content-Type': 'application/json'}), |
|
body: JSON.stringify(bodyParam) |
|
} |
|
|
|
try { |
|
const result = await fetch(API_GEOHR_EMPLOYEE_MONITORING, param).then(response => response.json()).then(res => res); |
|
console.log('getEmployeeFeatures result', result); |
|
if (result.data) { |
|
|
|
let output = { |
|
type: "FeatureCollection", |
|
features: [] |
|
}; |
|
|
|
if (result.data.features && result.data.features.length > 0) { |
|
for (let i=0; i < result.data.features.length; i++) { |
|
if (result.data.features[i].geometry) { |
|
if (result.data.features[i].geometry.coordinates !== null && result.data.features[i].geometry.type !== null) { |
|
output.features.push(result.data.features[i]); |
|
} |
|
} |
|
} |
|
} |
|
|
|
return output; |
|
} |
|
else { |
|
return null; |
|
} |
|
} |
|
catch (e) { |
|
console.log('error getEmployeeFeatures', e); |
|
return null; |
|
} |
|
} |
|
|
|
export const getEmployeeRoutingApi = async (userId, dateString) => { |
|
console.log('[GeohrApiFunc.js] getEmployeeRoutingApi', userId, dateString); |
|
|
|
let bodyParam = { |
|
"paging": {"start": 0, "length": -1}, |
|
"columns": [ |
|
{"name":"wptime", "logic_operator": "range", "value": dateString[0], "value1": dateString[1], "operator": "and"} |
|
], |
|
"orders": {"columns": ["wptime"], "ascending": true} |
|
} |
|
|
|
const param = { |
|
method: 'POST', |
|
header: JSON.stringify({'Content-Type': 'application/json'}), |
|
body: JSON.stringify(bodyParam) |
|
} |
|
|
|
try { |
|
const result = await fetch(API_GEOHR_WAYPOINT_EMPLOYEE_MONITORING(userId), param).then(response => response.json()).then(res => res); |
|
console.log('getEmployeeRoutingApi result', result); |
|
if (result.data) { |
|
|
|
let output = { |
|
type: "FeatureCollection", |
|
features: [] |
|
}; |
|
|
|
if (result.data.features && result.data.features.length > 0) { |
|
for (let i=0; i < result.data.features.length; i++) { |
|
if ((result.data.features[i].geometry.coordinates && result.data.features[i].geometry.coordinates.length > 0) && result.data.features[i].geometry.type) { |
|
output.features.push(result.data.features[i]); |
|
} |
|
} |
|
} |
|
|
|
return output; |
|
} |
|
else { |
|
return null; |
|
} |
|
} |
|
catch (e) { |
|
console.log('error getEmployeeRoutingApi', e); |
|
return null; |
|
} |
|
} |
|
|
|
|
|
export const getWaspangFeatures = async (proyekIds) => { |
|
|
|
let bodyParam = { |
|
"paging": {"start": 0, "length": -1}, |
|
"joins": [ |
|
{ |
|
"name": "m_proyek", |
|
"column_join": "proyek_id", |
|
"column_results": [ |
|
"nama", |
|
"biaya", |
|
"color_progress", |
|
"jumlah_pekerja", |
|
"pic", |
|
"mulai_proyek", |
|
"akhir_proyek" |
|
] |
|
}, |
|
{ |
|
"name": "m_subproyek", |
|
"column_join": "subproyek_id", |
|
"column_results": [ |
|
"nama", |
|
"biaya", |
|
"color_progress", |
|
"jumlah_pekerja", |
|
"pic", |
|
"mulai_proyek", |
|
"akhir_proyek" |
|
] |
|
}, |
|
{ |
|
"name": "m_users", |
|
"column_join": "user_id", |
|
"column_results": [ |
|
"name", |
|
"username", |
|
"email", |
|
"phone_number", |
|
"gender" |
|
] |
|
} |
|
], |
|
"orders": {"columns": ["id"], "ascending": true} |
|
} |
|
|
|
if (proyekIds.length > 0) { |
|
console.log('filterrrrr'); |
|
bodyParam["columns"] = []; |
|
|
|
bodyParam.columns.push({"name":"proyek_id","logic_operator":"in","value":proyekIds.join(),"operator":"and"}); |
|
|
|
console.log('bodyParam', bodyParam); |
|
} |
|
|
|
const param = { |
|
method: 'POST', |
|
header: JSON.stringify({'Content-Type': 'application/json'}), |
|
body: JSON.stringify(bodyParam) |
|
} |
|
|
|
try { |
|
const result = await fetch(USER_TO_PROYEK_SEARCH, param).then(response => response.json()).then(res => res); |
|
console.log('getWaspangFeatures result', result); |
|
if (result.data) { |
|
|
|
let output = { |
|
type: "FeatureCollection", |
|
features: [] |
|
}; |
|
|
|
if (result.data.features && result.data.features.length > 0) { |
|
for (let i=0; i < result.data.features.length; i++) { |
|
if (result.data.features[i].geometry) { |
|
if (result.data.features[i].geometry.coordinates !== null && result.data.features[i].geometry.type !== null) { |
|
output.features.push(result.data.features[i]); |
|
} |
|
} |
|
} |
|
} |
|
|
|
return output; |
|
} |
|
else { |
|
return null; |
|
} |
|
} |
|
catch (e) { |
|
console.log('error getWaspangFeatures', e); |
|
return null; |
|
} |
|
} |
|
|
|
export const getWaspangRoutingApi = async (userId, dateString) => { |
|
console.log('[GeohrApiFunc.js] getWaspangRoutingApi', userId, dateString); |
|
|
|
let bodyParam = { |
|
"columns": [ |
|
{"name":"wptime", "logic_operator": "range", "value": dateString[0], "value1": dateString[1], "operator": "and"} |
|
], |
|
"orders": {"columns": ["wptime"], "ascending": true} |
|
} |
|
|
|
const param = { |
|
method: 'POST', |
|
headers: { |
|
'Content-Type': 'application/json', |
|
'Authorization': 'Bearer '+window.localStorage.getItem('token') |
|
}, |
|
body: JSON.stringify(bodyParam) |
|
} |
|
|
|
try { |
|
const result = await fetch(API_SIMPRO_WAYPOINT_WASPANG_MONITORING(userId), param).then(response => response.json()).then(res => res); |
|
console.log('getWaspangRoutingApi result', result); |
|
if (result.data) { |
|
|
|
let output = { |
|
type: "FeatureCollection", |
|
features: [] |
|
}; |
|
|
|
if (result.data.features && result.data.features.length > 0) { |
|
for (let i=0; i < result.data.features.length; i++) { |
|
if ((result.data.features[i].geometry.coordinates && result.data.features[i].geometry.coordinates.length > 0) && result.data.features[i].geometry.type) { |
|
output.features.push(result.data.features[i]); |
|
} |
|
} |
|
} |
|
|
|
return output; |
|
} |
|
else { |
|
return null; |
|
} |
|
} |
|
catch (e) { |
|
console.log('error getWaspangRoutingApi', e); |
|
return null; |
|
} |
|
} |
|
|
|
export const getPresensiRoutingApi = async (userId, dateString) => { |
|
console.log('[GeohrApiFunc.js] getPresensiRoutingApi', userId, dateString); |
|
|
|
let bodyParam = { |
|
"paging": {"start": 0, "length": -1}, |
|
"columns": [ |
|
{"name": "user_id", "logic_operator": "=", "value": userId}, |
|
{"name": "wptime", "logic_operator": "range", "value": dateString[0], "value1": dateString[1]} |
|
], |
|
"orders": {"columns": ["wptime"], "ascending": true} |
|
} |
|
|
|
const param = { |
|
method: 'POST', |
|
headers: { |
|
'Content-Type': 'application/json', |
|
'Authorization': 'Bearer '+window.localStorage.getItem('token') |
|
}, |
|
body: JSON.stringify(bodyParam) |
|
} |
|
|
|
try { |
|
const result = await fetch(WAYPOINT_SEARCH, param).then(response => response.json()).then(res => res); |
|
console.log('getPresensiRoutingApi result', result); |
|
if (result.data) { |
|
|
|
let output = { |
|
type: "FeatureCollection", |
|
features: [] |
|
}; |
|
|
|
|
|
|
|
if (result.data.length > 0) { |
|
let features = null; |
|
for (let i=0; i < result.data.length; i++) { |
|
if (result.data[i].lat && result.data[i].lon) { |
|
features = { |
|
"type": "Feature", |
|
"geometry": { |
|
"type": "Point", |
|
"coordinates": [parseFloat(result.data[i].lon), parseFloat(result.data[i].lat)] |
|
}, |
|
"properties": result.data[i] |
|
} |
|
output.features.push(features); |
|
} |
|
} |
|
} |
|
|
|
console.log('routing features', output); |
|
|
|
return output; |
|
} |
|
else { |
|
return null; |
|
} |
|
} |
|
catch (e) { |
|
console.log('error getWaspangRoutingApi', e); |
|
return null; |
|
} |
|
} |