diff --git a/src/containers/DefaultLayout/DefaultLayout.js b/src/containers/DefaultLayout/DefaultLayout.js index 4cdd3cb..abb5cf9 100644 --- a/src/containers/DefaultLayout/DefaultLayout.js +++ b/src/containers/DefaultLayout/DefaultLayout.js @@ -36,18 +36,34 @@ const config = { }; class DefaultLayout extends Component { - constructor(props) { - super(props); - this.state = { - role_id: localStorage.getItem('role_id'), - token: localStorage.getItem('token'), - menu: { items: [] }, - routes2: routes, - finalRoutes: [], - breadrCrumbReady: false, - minimized: true - } - } + constructor(props) { + super(props); + + let role_id = '', token = '', company_id = 0, menu='' + if (props.location.state && props.location.state.role_id) { + role_id = props.location.state.role_id; + token = props.location.state.token; + company_id = props.location.state.company_id; + menu = props.location.state.menu_login; + } else { + role_id = localStorage.getItem("role_id"); + token = localStorage.getItem("token"); + company_id = localStorage.getItem('company_id'); + menu = localStorage.getItem("menu_login"); + } + + this.state = { + role_id: role_id, + token: token, + menu: { items: [] }, + routes2: routes, + finalRoutes: [], + breadrCrumbReady: false, + minimized: true, + company_id: company_id + }; + } + async componentDidMount() { const menu = localStorage.getItem("menu_login") @@ -295,7 +311,20 @@ class DefaultLayout extends Component { exact={route.exact} name={route.name} render={props => ( - + )} /> ) : (null); })} diff --git a/src/views/Dashboard/DashboardBOD.js b/src/views/Dashboard/DashboardBOD.js index 46175ac..1341c88 100644 --- a/src/views/Dashboard/DashboardBOD.js +++ b/src/views/Dashboard/DashboardBOD.js @@ -15,24 +15,19 @@ import { HealthByBudget, HealthBySchedule } from './Components'; import { Link } from 'react-router-dom'; const DashboardBOD = (props) => { - let role_id = '', user_id = '', isLogin = '', token = '', company_id = 0, all_project = ''; - if (props.location.state && props.location.state.role_id && props.location.state.user_id) { - role_id = props.location.state.role_id; - user_id = props.location.state.user_id; - token = props.location.state.token; - isLogin = props.location.state.isLogin; - company_id = props.location.state.company_id; - all_project = props.location.state.all_project; - } else { - role_id = localStorage.getItem("role_id"); - user_id = localStorage.getItem("user_id"); - token = localStorage.getItem("token"); - isLogin = localStorage.getItem("isLogin"); - company_id = localStorage.getItem('company_id'); - all_project = localStorage.getItem('all_project'); - } - let hierarchy = []; - hierarchy.push(JSON.parse(localStorage.getItem("hierarchy"))); + let role_id = 0, user_id = 0, isLogin = false, token = '', company_id = 0, all_project = null, role_name='', hierarchy=[], user_name=''; + if (props && props.role_id && props.user_id) { + role_id = props.role_id; + user_id = props.user_id; + token = props.token; + isLogin = props.isLogin; + company_id = props.company_id; + all_project = props.all_project; + role_name = props.role_name; + isLogin = props.isLogin; + hierarchy = props.hierarchy; + user_name = props.user_name; + } const HEADER = { headers: { "Content-Type": "application/json", diff --git a/src/views/Dashboard/DashboardCustomer.js b/src/views/Dashboard/DashboardCustomer.js index 93b8f86..8f0f5f6 100644 --- a/src/views/Dashboard/DashboardCustomer.js +++ b/src/views/Dashboard/DashboardCustomer.js @@ -26,18 +26,19 @@ const center = { } const DashboardCustomer = (props) => { - let role_id = '', user_id = '', isLogin = '', token = ''; - if (props.location.state && props.location.state.role_id && props.location.state.user_id) { - role_id = props.location.state.role_id; - user_id = props.location.state.user_id; - token = props.location.state.token; - isLogin = props.location.state.isLogin; - } else { - role_id = localStorage.getItem("role_id"); - user_id = localStorage.getItem("user_id"); - token = localStorage.getItem("token"); - isLogin = localStorage.getItem("isLogin"); - } + let role_id = 0, user_id = 0, isLogin = false, token = '', company_id = 0, all_project = null, role_name='', hierarchy=[], user_name=''; + if (props && props.role_id && props.user_id) { + role_id = props.role_id; + user_id = props.user_id; + token = props.token; + isLogin = props.isLogin; + company_id = props.company_id; + all_project = props.all_project; + role_name = props.role_name; + isLogin = props.isLogin; + hierarchy = props.hierarchy; + user_name = props.user_name; + } const HEADER = { headers: { "Content-Type": "application/json", @@ -45,7 +46,7 @@ const DashboardCustomer = (props) => { } } const { PROJECT_ID, GANTT_ID, SCURVE } = useParams(); - const URL_GANTT = `https://konstruksi-gantt.ospro.id/view-mode/index.html?base_url=${BASE_OSPRO}/api&gantt_id=${GANTT_ID}&proyek_id=${PROJECT_ID}&token=${token}&ro=1`; + const URL_GANTT = `https://project-gantt.ospro.id/view-mode/index.html?base_url=${BASE_OSPRO}/api&gantt_id=${GANTT_ID}&proyek_id=${PROJECT_ID}&token=${token}&ro=1`; const mapRef = useRef() const [projectName, setProjectName] = useState(""); const [projectManagerName, setProjectManagerName] = useState(''); diff --git a/src/views/Dashboard/DashboardProject.js b/src/views/Dashboard/DashboardProject.js index be177a7..b70c658 100644 --- a/src/views/Dashboard/DashboardProject.js +++ b/src/views/Dashboard/DashboardProject.js @@ -63,8 +63,22 @@ const center = { lng: 106.816666, }; -const DashboardProject = () => { - const token = localStorage.getItem("token"); +const DashboardProject = (props) => { + + let role_id = 0, user_id = 0, isLogin = false, token = '', company_id = 0, all_project = null, role_name='', hierarchy=[], user_name=''; + if (props && props.role_id && props.user_id) { + role_id = props.role_id; + user_id = props.user_id; + token = props.token; + isLogin = props.isLogin; + company_id = props.company_id; + all_project = props.all_project; + role_name = props.role_name; + isLogin = props.isLogin; + hierarchy = props.hierarchy; + user_name = props.user_name; + } + const HEADER = { headers: { "Content-Type": "application/json", @@ -72,7 +86,7 @@ const DashboardProject = () => { }, }; const { PROJECT_ID, GANTT_ID, SCURVE } = useParams(); - const URL_GANTT = `https://konstruksi-gantt.ospro.id/view-mode/index.html?base_url=${BASE_OSPRO}/api&gantt_id=${GANTT_ID}&proyek_id=${PROJECT_ID}&token=${token}&ro=1`; + const URL_GANTT = `https://project-gantt.ospro.id/view-mode/index.html?base_url=${BASE_OSPRO}/api&gantt_id=${GANTT_ID}&proyek_id=${PROJECT_ID}&token=${token}&ro=1`; const mapRef = useRef(); const [projectName, setProjectName] = useState(""); const [projectManagerName, setProjectManagerName] = useState(""); diff --git a/src/views/Dashboard/DashboardProjectCarousell.js b/src/views/Dashboard/DashboardProjectCarousell.js index 774fd2d..57f35e7 100644 --- a/src/views/Dashboard/DashboardProjectCarousell.js +++ b/src/views/Dashboard/DashboardProjectCarousell.js @@ -69,16 +69,21 @@ const center = { lng: 106.816666, }; -const DashboardProject = (args) => { - let role_id = '', user_id = '', proyek_id = '', isLogin = '', token = '', company_id = 0, all_project = '', hierarchy = []; - role_id = localStorage.getItem("role_id"); - proyek_id = localStorage.getItem("proyek_id"); - user_id = localStorage.getItem("user_id"); - token = localStorage.getItem("token"); - isLogin = localStorage.getItem("isLogin"); - company_id = localStorage.getItem('company_id'); - all_project = localStorage.getItem('all_project'); - hierarchy.push(JSON.parse(localStorage.getItem("hierarchy"))); +const DashboardProject = ({args,...props}) => { + let role_id = 0, user_id = 0, isLogin = false, token = '', company_id = 0, all_project = null, role_name='', hierarchy=[], user_name=''; + if (props && props.role_id && props.user_id) { + role_id = props.role_id; + user_id = props.user_id; + token = props.token; + isLogin = props.isLogin; + company_id = props.company_id; + all_project = props.all_project; + role_name = props.role_name; + isLogin = props.isLogin; + hierarchy = props.hierarchy; + user_name = props.user_name; + } + const HEADER = { headers: { "Content-Type": "application/json", @@ -231,7 +236,7 @@ const DashboardProject = (args) => { let URL_GANTT = ""; let version_gantt = ""; if (item.gantt !== null) { - URL_GANTT = `http://localhost:8444/adw-gantt/view-mode/index.html?base_url=${BASE_OSPRO}/api&gantt_id=${item.gantt.id}&proyek_id=${item.gantt.proyek_id}&token=${token}&ro=1`; + URL_GANTT = `https://project-gantt.ospro.id/view-mode/index.html?base_url=${BASE_OSPRO}/api&gantt_id=${item.gantt.id}&proyek_id=${item.gantt.proyek_id}&token=${token}&ro=1`; version_gantt = item.gantt.name_version } else { URL_GANTT = ""; @@ -803,10 +808,10 @@ const DashboardProject = (args) => { > {slides}
- +
- +
diff --git a/src/views/MapMonitoring/index.js b/src/views/MapMonitoring/index.js index 8df8828..aaa61b5 100644 --- a/src/views/MapMonitoring/index.js +++ b/src/views/MapMonitoring/index.js @@ -28,20 +28,19 @@ import 'leaflet-control-geocoder/dist/Control.Geocoder.js' import moment from 'moment'; import axios from "../../const/interceptorApi"; const MapMonitoring = ({ ...props }) => { - let role_id = '', user_id = '', proyek_id = '', isLogin = '', token = ''; - if (props.location.state && props.location.state.role_id && props.location.state.user_id) { - role_id = props.location.state.role_id; - user_id = props.location.state.user_id; - token = props.location.state.token; - isLogin = props.location.state.isLogin; - - } else { - role_id = localStorage.getItem("role_id"); - proyek_id = localStorage.getItem("proyek_id"); - user_id = localStorage.getItem("user_id"); - token = localStorage.getItem("token"); - isLogin = localStorage.getItem("isLogin"); - } + let role_id = 0, user_id = 0, isLogin = false, token = '', company_id = 0, all_project = null, role_name='', hierarchy=[], user_name=''; + if (props && props.role_id && props.user_id) { + role_id = props.role_id; + user_id = props.user_id; + token = props.token; + isLogin = props.isLogin; + company_id = props.company_id; + all_project = props.all_project; + role_name = props.role_name; + isLogin = props.isLogin; + hierarchy = props.hierarchy; + user_name = props.user_name; + } const HEADER = { headers: { "Content-Type": "application/json", @@ -67,7 +66,7 @@ const MapMonitoring = ({ ...props }) => { let markerCluster = L.markerClusterGroup({ name: "userPointLayer", - // disableClusteringAtZoom: 17, + // disableClusteringAtZoom: 17, showCoverageOnHover: false, // spiderfyOnMaxZoom: false }); @@ -333,4 +332,4 @@ const MapMonitoring = ({ ...props }) => { return MapContent } -export default MapMonitoring; \ No newline at end of file +export default MapMonitoring; diff --git a/src/views/Master/MasterRoles/index.js b/src/views/Master/MasterRoles/index.js index ddd84da..c6fec9d 100644 --- a/src/views/Master/MasterRoles/index.js +++ b/src/views/Master/MasterRoles/index.js @@ -16,21 +16,19 @@ const LENGTH_DATA = 10 class index extends Component { constructor(props) { - let role_id = '', user_id = '', isLogin = '', token = '', company_id = 0, role_name = ''; - if (props.location.state && props.location.state.role_id && props.location.state.user_id) { - role_id = props.location.state.role_id; - user_id = props.location.state.user_id; - token = props.location.state.token; - isLogin = props.location.state.isLogin; - company_id = props.location.state.company_id; - role_name = props.location.state.role_name; - - - } else { - token = window.localStorage.getItem('token'); - role_name = window.localStorage.getItem('role_name'); - company_id = window.localStorage.getItem('company_id'); - } + let role_id = 0, user_id = 0, isLogin = false, token = '', company_id = 0, all_project = null, role_name='', hierarchy=[], user_name=''; + if (props && props.role_id && props.user_id) { + role_id = props.role_id; + user_id = props.user_id; + token = props.token; + isLogin = props.isLogin; + company_id = props.company_id; + all_project = props.all_project; + role_name = props.role_name; + isLogin = props.isLogin; + hierarchy = props.hierarchy; + user_name = props.user_name; + } super(props) this.config = { headers: { diff --git a/src/views/Master/ProjectExpenditure/index.js b/src/views/Master/ProjectExpenditure/index.js index 4dde162..c9b227d 100644 --- a/src/views/Master/ProjectExpenditure/index.js +++ b/src/views/Master/ProjectExpenditure/index.js @@ -12,21 +12,18 @@ import { useTranslation } from 'react-i18next'; const ProjectExpenditure = ({ params, ...props }) => { - let role_id = '', user_id = '', proyek_id = '', isLogin = '', token = '', company_id = 0, role_name = ''; - if (props.location.state && props.location.state.role_id && props.location.state.user_id) { - role_id = props.location.state.role_id; - user_id = props.location.state.user_id; - token = props.location.state.token; - isLogin = props.location.state.isLogin; - role_name = props.location.state.role_name; - } else { - role_id = localStorage.getItem("role_id"); - proyek_id = localStorage.getItem("proyek_id"); - user_id = localStorage.getItem("user_id"); - token = localStorage.getItem("token"); - isLogin = localStorage.getItem("isLogin"); - company_id = localStorage.getItem('company_id'); - role_name = localStorage.getItem('role_name'); + let role_id = 0, user_id = 0, isLogin = false, token = '', company_id = 0, all_project = null, role_name='', hierarchy=[], user_name=''; + if (props && props.role_id && props.user_id) { + role_id = props.role_id; + user_id = props.user_id; + token = props.token; + isLogin = props.isLogin; + company_id = props.company_id; + all_project = props.all_project; + role_name = props.role_name; + isLogin = props.isLogin; + hierarchy = props.hierarchy; + user_name = props.user_name; } const HEADER = { diff --git a/src/views/Master/ProjectFinancialHealth/index.js b/src/views/Master/ProjectFinancialHealth/index.js index bc6b0a3..28f9fcd 100644 --- a/src/views/Master/ProjectFinancialHealth/index.js +++ b/src/views/Master/ProjectFinancialHealth/index.js @@ -12,21 +12,18 @@ import { useTranslation } from 'react-i18next'; const ProjectFinancialHealth = ({ params, ...props }) => { - let role_id = '', user_id = '', proyek_id = '', isLogin = '', token = '', company_id = 0, role_name = ''; - if (props.location.state && props.location.state.role_id && props.location.state.user_id) { - role_id = props.location.state.role_id; - user_id = props.location.state.user_id; - token = props.location.state.token; - isLogin = props.location.state.isLogin; - role_name = props.location.state.role_name; - } else { - role_id = localStorage.getItem("role_id"); - proyek_id = localStorage.getItem("proyek_id"); - user_id = localStorage.getItem("user_id"); - token = localStorage.getItem("token"); - isLogin = localStorage.getItem("isLogin"); - company_id = localStorage.getItem('company_id'); - role_name = localStorage.getItem('role_name'); + let role_id = 0, user_id = 0, isLogin = false, token = '', company_id = 0, all_project = null, role_name='', hierarchy=[], user_name=''; + if (props && props.role_id && props.user_id) { + role_id = props.role_id; + user_id = props.user_id; + token = props.token; + isLogin = props.isLogin; + company_id = props.company_id; + all_project = props.all_project; + role_name = props.role_name; + isLogin = props.isLogin; + hierarchy = props.hierarchy; + user_name = props.user_name; } const HEADER = { diff --git a/src/views/Master/ProjectInvoice/index.js b/src/views/Master/ProjectInvoice/index.js index da213a1..c030d1d 100644 --- a/src/views/Master/ProjectInvoice/index.js +++ b/src/views/Master/ProjectInvoice/index.js @@ -12,21 +12,18 @@ import { useTranslation } from 'react-i18next'; const ProjectInvoice = ({ params, ...props }) => { - let role_id = '', user_id = '', proyek_id = '', isLogin = '', token = '', company_id = 0, role_name = ''; - if (props.location.state && props.location.state.role_id && props.location.state.user_id) { - role_id = props.location.state.role_id; - user_id = props.location.state.user_id; - token = props.location.state.token; - isLogin = props.location.state.isLogin; - role_name = props.location.state.role_name; - } else { - role_id = localStorage.getItem("role_id"); - proyek_id = localStorage.getItem("proyek_id"); - user_id = localStorage.getItem("user_id"); - token = localStorage.getItem("token"); - isLogin = localStorage.getItem("isLogin"); - company_id = localStorage.getItem('company_id'); - role_name = localStorage.getItem('role_name'); + let role_id = 0, user_id = 0, isLogin = false, token = '', company_id = 0, all_project = null, role_name='', hierarchy=[], user_name=''; + if (props && props.role_id && props.user_id) { + role_id = props.role_id; + user_id = props.user_id; + token = props.token; + isLogin = props.isLogin; + company_id = props.company_id; + all_project = props.all_project; + role_name = props.role_name; + isLogin = props.isLogin; + hierarchy = props.hierarchy; + user_name = props.user_name; } const HEADER = { diff --git a/src/views/Master/ProjectPhase/index.js b/src/views/Master/ProjectPhase/index.js index d9bbd17..78b914a 100644 --- a/src/views/Master/ProjectPhase/index.js +++ b/src/views/Master/ProjectPhase/index.js @@ -1,397 +1,394 @@ -import * as XLSX from 'xlsx'; -import DialogForm from './DialogForm'; -import React, { useState, useEffect, useMemo } from 'react'; -import SweetAlert from 'react-bootstrap-sweetalert'; -import axios from "../../../const/interceptorApi" -import moment from 'moment' -import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; -import { NotificationContainer, NotificationManager } from 'react-notifications'; -import { PROJECT_PHASE_ADD, PROJECT_PHASE_EDIT, PROJECT_PHASE_DELETE, PROJECT_PHASE_SEARCH, PROJECT_PHASE_LIST, BASE_OSPRO } from '../../../const/ApiConst'; -import { Pagination, Button, Tooltip, Table } from 'antd'; -import { useTranslation } from 'react-i18next'; - - -const ProjectPhase = ({ params, ...props }) => { - let role_id = '', user_id = '', proyek_id = '', isLogin = '', token = '', company_id = 0, role_name = ''; - if (props.location.state && props.location.state.role_id && props.location.state.user_id) { - role_id = props.location.state.role_id; - user_id = props.location.state.user_id; - token = props.location.state.token; - isLogin = props.location.state.isLogin; - role_name = props.location.state.role_name; - } else { - role_id = localStorage.getItem("role_id"); - proyek_id = localStorage.getItem("proyek_id"); - user_id = localStorage.getItem("user_id"); - token = localStorage.getItem("token"); - isLogin = localStorage.getItem("isLogin"); - company_id = localStorage.getItem('company_id'); - role_name = localStorage.getItem('role_name'); - } - - const HEADER = { - headers: { - "Content-Type": "application/json", - "Authorization": `Bearer ${token}` - } - } - const pageName = params.name; - - const [alertDelete, setAlertDelete] = useState(false) - const [allDataMenu, setAllDataMenu] = useState([]) - const [clickOpenModal, setClickOpenModal] = useState(false) - const [currentPage, setCurrentPage] = useState(1) - const [dataEdit, setDataEdit] = useState([]) - const [dataExport, setDataExport] = useState([]) - const [dataTable, setDatatable] = useState([]) - const [idDelete, setIdDelete] = useState(0) - const [idPhaseProject, setIdPhaseProject] = useState(0) - const [openDialog, setOpenDialog] = useState(false) - const [openDialogIG, setOpenDialogIG] = useState(false) - const [rowsPerPage, setRowsPerPage] = useState(10) - const [search, setSearch] = useState('') - const [totalPage, setTotalPage] = useState(0) - const [typeDialog, setTypeDialog] = useState('Save') - const { t } = useTranslation() - useEffect(() => { - getDataProjectPhase() - }, [currentPage, rowsPerPage, search]) - - useEffect(() => { - const cekData = dataExport || [] - if (cekData.length > 0) { - exportExcel() - } - }, [dataExport]) - - const getDataProjectPhase = async () => { - let start = 0; - if (currentPage !== 1 && currentPage > 1) { - start = (currentPage * rowsPerPage) - rowsPerPage - } - const payload = { - "columns": [ - { - "name": "name", - "logic_operator": "ilike", - "value": search, - "operator": "AND" - } - ], - "orders": { - "ascending": true, - "columns": [ - 'id' - ] - }, - "paging": { - "length": rowsPerPage, - "start": start - } - } - if (role_name !== "Super Admin") { - payload.columns.push( - { "name": "company_id", "logic_operator": "=", "value": company_id, "operator": "AND" }, - ) - } else { - payload.columns.push( - { "name": "company_id", "logic_operator": "is null", "value": "", "operator": "AND" }, - ) - } - const result = await axios - .post(PROJECT_PHASE_SEARCH, payload, HEADER) - .then((res) => res) - .catch((err) => err.response); - - if (result && result.data && result.data.code == 200) { - result.data.data.map((res) => { - res.key = res.id.toString() - }); - setDatatable(result.data.data); - setTotalPage(result.data.totalRecord); - } else { - NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); - } - } - - const handleSearch = e => { - const value = e.target.value - setSearch(value); - setCurrentPage(1) - }; - const handleOpenDialog = (type) => { - setOpenDialog(true) - setTypeDialog(type) - } - - const handleExportExcel = async () => { - let start = 0; - - if (currentPage !== 1 && currentPage > 1) { - start = (currentPage * rowsPerPage) - rowsPerPage - } - - const payload = { - "columns": [ - { - "name": "name", - "logic_operator": "like", - "value": search, - "operator": "AND" - } - ], - "orders": { - "ascending": true, - "columns": [ - 'id' - ] - }, - "paging": { - "length": rowsPerPage, - "start": start - } - } - - const result = await axios - .post(PROJECT_PHASE_SEARCH, payload, HEADER) - .then(res => res) - .catch((error) => error.response); - if (result && result.data && result.data.code == 200) { - let resData = result.data.data; - const excelData = []; - resData.map((val, index) => { - let dataRow = { - "Nama": val.name, - "Color": val.color, - } - excelData.push(dataRow) - }) - await setDataExport(excelData) - } else { - NotificationManager.error('Gagal Export Data!!', 'Failed'); - } - } - - const exportExcel = () => { - const dataExcel = dataExport || []; - const fileName = `Data ${pageName}.xlsx`; - const ws = XLSX.utils.json_to_sheet(dataExcel); - const wb = XLSX.utils.book_new(); - XLSX.utils.book_append_sheet(wb, ws, `Data ${pageName}`); - XLSX.writeFile(wb, fileName); - setDataExport([]) - } - - const handleEdit = (data) => { - setDataEdit(data) - handleOpenDialog('Edit'); - } - - const handleDelete = async (id) => { - await setAlertDelete(true) - await setIdDelete(id) - } - - const handleCloseDialog = (type, data) => { - if (type === "save") { - saveProjectPhase(data); - } else if (type === "edit") { - editMaterialR(data); - } - setDataEdit([]) - setOpenDialog(false) - } - - const saveProjectPhase = async (data) => { - const formData = data - const result = await axios.post(PROJECT_PHASE_ADD, formData, HEADER) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - getDataProjectPhase() - NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!'); - } else { - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - } - - const editMaterialR = async (data) => { - let urlEdit = PROJECT_PHASE_EDIT(data.id) - const formData = data - - const result = await axios.put(urlEdit, formData, HEADER) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - getDataProjectPhase(); - NotificationManager.success(`Data project phase berhasil diedit`, 'Success!!'); - } else { - NotificationManager.error(`Data project phase gagal di edit`, `Failed!!`); - } - } - - const toggleAddDialog = () => { - setOpenDialog(!openDialog) - } - - const handleDialogIg = (id) => { - setIdPhaseProject(id) - setOpenDialogIG(true) - } - - const closeDialogIG = () => { - setIdPhaseProject(0) - setOpenDialogIG(false) - } - - const toggleDialogIG = () => { - if (openDialogIG) { - setIdPhaseProject(0) - } - setOpenDialogIG(!openDialogIG); - } - - const onConfirmDelete = async () => { - let url = PROJECT_PHASE_DELETE(idDelete); - - const result = await axios.delete(url, HEADER) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - getDataProjectPhase() - setIdDelete(0) - setAlertDelete(false) - NotificationManager.success(`Data project phase berhasil dihapus!`, 'Success!!'); - } else { - setIdDelete(0) - setAlertDelete(false) - NotificationManager.error(`Data project phase gagal dihapus!}`, 'Failed!!'); - } - } - - const cancelDelete = () => { - setAlertDelete(false) - setIdDelete(0) - } - - const onShowSizeChange = (current, pageSize) => { - setRowsPerPage(pageSize) - } - - const onPagination = (current, pageSize) => { - setCurrentPage(current) - } - - const dataNotAvailable = () => { - if (dataTable.length === 0) { - return ( - - {t('noData')} - - ) - } - } - - const renderTable = useMemo(() => { - const columns = [ - { - title: t('action'), - dataIndex: '', - key: 'x', - className: 'nowrap', - render: (text, record) => <> - - handleDelete(text.id)}> - - - handleEdit(text)}> - {" "} - , - }, - { title: t('phase'), dataIndex: 'name', key: 'name', className: "nowrap" }, - { - title: t('color'), - dataIndex: 'color', - key: 'color', - render: (text) => <> - - - - , - }, - ]; - return ( - - ) - }, [dataTable]) - - return ( -
- - - {t('deleteMsg')} - - toggleAddDialog} - typeDialog={typeDialog} - dataEdit={dataEdit} - clickOpenModal={clickOpenModal} - dataParent={allDataMenu} - /> - - -

{pageName}

- -
- - - - - - - - - - - - - - {renderTable} - - - - - ) -} - -export default ProjectPhase; +import * as XLSX from 'xlsx'; +import DialogForm from './DialogForm'; +import React, { useState, useEffect, useMemo } from 'react'; +import SweetAlert from 'react-bootstrap-sweetalert'; +import axios from "../../../const/interceptorApi" +import moment from 'moment' +import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; +import { NotificationContainer, NotificationManager } from 'react-notifications'; +import { PROJECT_PHASE_ADD, PROJECT_PHASE_EDIT, PROJECT_PHASE_DELETE, PROJECT_PHASE_SEARCH, PROJECT_PHASE_LIST, BASE_OSPRO } from '../../../const/ApiConst'; +import { Pagination, Button, Tooltip, Table } from 'antd'; +import { useTranslation } from 'react-i18next'; + + +const ProjectPhase = ({ params, ...props }) => { + let role_id = 0, user_id = 0, isLogin = false, token = '', company_id = 0, all_project = null, role_name='', hierarchy=[], user_name=''; + if (props && props.role_id && props.user_id) { + role_id = props.role_id; + user_id = props.user_id; + token = props.token; + isLogin = props.isLogin; + company_id = props.company_id; + all_project = props.all_project; + role_name = props.role_name; + isLogin = props.isLogin; + hierarchy = props.hierarchy; + user_name = props.user_name; + } + + const HEADER = { + headers: { + "Content-Type": "application/json", + "Authorization": `Bearer ${token}` + } + } + const pageName = params.name; + + const [alertDelete, setAlertDelete] = useState(false) + const [allDataMenu, setAllDataMenu] = useState([]) + const [clickOpenModal, setClickOpenModal] = useState(false) + const [currentPage, setCurrentPage] = useState(1) + const [dataEdit, setDataEdit] = useState([]) + const [dataExport, setDataExport] = useState([]) + const [dataTable, setDatatable] = useState([]) + const [idDelete, setIdDelete] = useState(0) + const [idPhaseProject, setIdPhaseProject] = useState(0) + const [openDialog, setOpenDialog] = useState(false) + const [openDialogIG, setOpenDialogIG] = useState(false) + const [rowsPerPage, setRowsPerPage] = useState(10) + const [search, setSearch] = useState('') + const [totalPage, setTotalPage] = useState(0) + const [typeDialog, setTypeDialog] = useState('Save') + const { t } = useTranslation() + useEffect(() => { + getDataProjectPhase() + }, [currentPage, rowsPerPage, search]) + + useEffect(() => { + const cekData = dataExport || [] + if (cekData.length > 0) { + exportExcel() + } + }, [dataExport]) + + const getDataProjectPhase = async () => { + let start = 0; + if (currentPage !== 1 && currentPage > 1) { + start = (currentPage * rowsPerPage) - rowsPerPage + } + const payload = { + "columns": [ + { + "name": "name", + "logic_operator": "ilike", + "value": search, + "operator": "AND" + } + ], + "orders": { + "ascending": true, + "columns": [ + 'id' + ] + }, + "paging": { + "length": rowsPerPage, + "start": start + } + } + if (role_name !== "Super Admin") { + payload.columns.push( + { "name": "company_id", "logic_operator": "=", "value": company_id, "operator": "AND" }, + ) + } else { + payload.columns.push( + { "name": "company_id", "logic_operator": "is null", "value": "", "operator": "AND" }, + ) + } + const result = await axios + .post(PROJECT_PHASE_SEARCH, payload, HEADER) + .then((res) => res) + .catch((err) => err.response); + + if (result && result.data && result.data.code == 200) { + result.data.data.map((res) => { + res.key = res.id.toString() + }); + setDatatable(result.data.data); + setTotalPage(result.data.totalRecord); + } else { + NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); + } + } + + const handleSearch = e => { + const value = e.target.value + setSearch(value); + setCurrentPage(1) + }; + const handleOpenDialog = (type) => { + setOpenDialog(true) + setTypeDialog(type) + } + + const handleExportExcel = async () => { + let start = 0; + + if (currentPage !== 1 && currentPage > 1) { + start = (currentPage * rowsPerPage) - rowsPerPage + } + + const payload = { + "columns": [ + { + "name": "name", + "logic_operator": "like", + "value": search, + "operator": "AND" + } + ], + "orders": { + "ascending": true, + "columns": [ + 'id' + ] + }, + "paging": { + "length": rowsPerPage, + "start": start + } + } + + const result = await axios + .post(PROJECT_PHASE_SEARCH, payload, HEADER) + .then(res => res) + .catch((error) => error.response); + if (result && result.data && result.data.code == 200) { + let resData = result.data.data; + const excelData = []; + resData.map((val, index) => { + let dataRow = { + "Nama": val.name, + "Color": val.color, + } + excelData.push(dataRow) + }) + await setDataExport(excelData) + } else { + NotificationManager.error('Gagal Export Data!!', 'Failed'); + } + } + + const exportExcel = () => { + const dataExcel = dataExport || []; + const fileName = `Data ${pageName}.xlsx`; + const ws = XLSX.utils.json_to_sheet(dataExcel); + const wb = XLSX.utils.book_new(); + XLSX.utils.book_append_sheet(wb, ws, `Data ${pageName}`); + XLSX.writeFile(wb, fileName); + setDataExport([]) + } + + const handleEdit = (data) => { + setDataEdit(data) + handleOpenDialog('Edit'); + } + + const handleDelete = async (id) => { + await setAlertDelete(true) + await setIdDelete(id) + } + + const handleCloseDialog = (type, data) => { + if (type === "save") { + saveProjectPhase(data); + } else if (type === "edit") { + editProjectPhase(data); + } + setDataEdit([]) + setOpenDialog(false) + } + + const saveProjectPhase = async (data) => { + const formData = data + const result = await axios.post(PROJECT_PHASE_ADD, formData, HEADER) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + getDataProjectPhase() + NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!'); + } else { + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + } + + const editProjectPhase = async (data) => { + let urlEdit = PROJECT_PHASE_EDIT(data.id) + const formData = data + + const result = await axios.put(urlEdit, formData, HEADER) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + getDataProjectPhase(); + NotificationManager.success(`Data project phase berhasil diedit`, 'Success!!'); + } else { + NotificationManager.error(`Data project phase gagal di edit`, `Failed!!`); + } + } + + const toggleAddDialog = () => { + setOpenDialog(!openDialog) + } + + const handleDialogIg = (id) => { + setIdPhaseProject(id) + setOpenDialogIG(true) + } + + const closeDialogIG = () => { + setIdPhaseProject(0) + setOpenDialogIG(false) + } + + const toggleDialogIG = () => { + if (openDialogIG) { + setIdPhaseProject(0) + } + setOpenDialogIG(!openDialogIG); + } + + const onConfirmDelete = async () => { + let url = PROJECT_PHASE_DELETE(idDelete); + + const result = await axios.delete(url, HEADER) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + getDataProjectPhase() + setIdDelete(0) + setAlertDelete(false) + NotificationManager.success(`Data project phase berhasil dihapus!`, 'Success!!'); + } else { + setIdDelete(0) + setAlertDelete(false) + NotificationManager.error(`Data project phase gagal dihapus!}`, 'Failed!!'); + } + } + + const cancelDelete = () => { + setAlertDelete(false) + setIdDelete(0) + } + + const onShowSizeChange = (current, pageSize) => { + setRowsPerPage(pageSize) + } + + const onPagination = (current, pageSize) => { + setCurrentPage(current) + } + + const dataNotAvailable = () => { + if (dataTable.length === 0) { + return ( + + + + ) + } + } + + const renderTable = useMemo(() => { + const columns = [ + { + title: t('action'), + dataIndex: '', + key: 'x', + className: 'nowrap', + render: (text, record) => <> + + handleDelete(text.id)}> + + + handleEdit(text)}> + {" "} + , + }, + { title: t('phase'), dataIndex: 'name', key: 'name', className: "nowrap" }, + { + title: t('color'), + dataIndex: 'color', + key: 'color', + render: (text) => <> + + + + , + }, + ]; + return ( +
{t('noData')}
+ ) + }, [dataTable]) + + return ( +
+ + + {t('deleteMsg')} + + toggleAddDialog} + typeDialog={typeDialog} + dataEdit={dataEdit} + clickOpenModal={clickOpenModal} + dataParent={allDataMenu} + /> + + +

{pageName}

+ +
+ + + + + + + + + + + + + + {renderTable} + + + + + ) +} + +export default ProjectPhase; diff --git a/src/views/Master/ProjectScheduleHealth/index.js b/src/views/Master/ProjectScheduleHealth/index.js index ed90090..36bc06f 100644 --- a/src/views/Master/ProjectScheduleHealth/index.js +++ b/src/views/Master/ProjectScheduleHealth/index.js @@ -12,21 +12,18 @@ import { useTranslation } from 'react-i18next'; const ProjectScheduleHealth = ({ params, ...props }) => { - let role_id = '', user_id = '', proyek_id = '', isLogin = '', token = '', company_id = 0, role_name = ''; - if (props.location.state && props.location.state.role_id && props.location.state.user_id) { - role_id = props.location.state.role_id; - user_id = props.location.state.user_id; - token = props.location.state.token; - isLogin = props.location.state.isLogin; - role_name = props.location.state.role_name; - } else { - role_id = localStorage.getItem("role_id"); - proyek_id = localStorage.getItem("proyek_id"); - user_id = localStorage.getItem("user_id"); - token = localStorage.getItem("token"); - isLogin = localStorage.getItem("isLogin"); - company_id = localStorage.getItem('company_id'); - role_name = localStorage.getItem('role_name'); + let role_id = 0, user_id = 0, isLogin = false, token = '', company_id = 0, all_project = null, role_name='', hierarchy=[], user_name=''; + if (props && props.role_id && props.user_id) { + role_id = props.role_id; + user_id = props.user_id; + token = props.token; + isLogin = props.isLogin; + company_id = props.company_id; + all_project = props.all_project; + role_name = props.role_name; + isLogin = props.isLogin; + hierarchy = props.hierarchy; + user_name = props.user_name; } const HEADER = { diff --git a/src/views/Master/RoleProject/index.js b/src/views/Master/RoleProject/index.js index a9e22ae..89d7312 100644 --- a/src/views/Master/RoleProject/index.js +++ b/src/views/Master/RoleProject/index.js @@ -35,18 +35,18 @@ const LENGTH_DATA = 10 class index extends Component { constructor(props) { - let role_id = '', user_id = '', isLogin = '', token = '', company_id = 0, role_name = ''; - if (props.location.state && props.location.state.role_id && props.location.state.user_id) { - role_id = props.location.state.role_id; - user_id = props.location.state.user_id; - token = props.location.state.token; - isLogin = props.location.state.isLogin; - company_id = props.location.state.company_id; - role_name = props.location.state.role_name; - } else { - token = window.localStorage.getItem('token'); - role_name = window.localStorage.getItem('role_name'); - company_id = window.localStorage.getItem('company_id'); + let role_id = 0, user_id = 0, isLogin = false, token = '', company_id = 0, all_project = null, role_name='', hierarchy=[], user_name=''; + if (props && props.role_id && props.user_id) { + role_id = props.role_id; + user_id = props.user_id; + token = props.token; + isLogin = props.isLogin; + company_id = props.company_id; + all_project = props.all_project; + role_name = props.role_name; + isLogin = props.isLogin; + hierarchy = props.hierarchy; + user_name = props.user_name; } super(props) this.state = { @@ -408,4 +408,4 @@ class index extends Component { ) } } -export default withTranslation()(index); \ No newline at end of file +export default withTranslation()(index); diff --git a/src/views/Pages/Login/Login.js b/src/views/Pages/Login/Login.js index 1104ecc..17eb331 100644 --- a/src/views/Pages/Login/Login.js +++ b/src/views/Pages/Login/Login.js @@ -120,7 +120,7 @@ class Login extends Component { } } - getDataMenu = async (token, role_id, user_id, company_id, role_name, all_project) => { + getDataMenu = async (token, role_id, hierarchy, user_id, company_id, role_name, all_project, user_name) => { const config = { headers: { @@ -146,14 +146,36 @@ class Login extends Component { else { this.props.history.push({ pathname: "/dashboard", - state: { role_id: role_id, user_id: user_id, token: token, isLogin: true, company_id: company_id, role_name: role_name, all_project: all_project } + state: { + menu_login: JSON.stringify(resData), + hierarchy, + role_id, + user_id, + token, + isLogin: true, + company_id, + role_name, + all_project, + user_name + } }); } if (this.state.defaultPage) { if (role_id === 44) { this.props.history.push({ pathname: this.state.defaultPage, - state: { role_id: role_id, user_id: user_id, token: token, isLogin: true, company_id: company_id, role_name: role_name, all_project: all_project } + state: { + menu_login: JSON.stringify(resData), + hierarchy, + role_id, + user_id, + token, + isLogin: true, + company_id, + role_name, + all_project, + user_name + } }); } else { this.props.history.push(this.state.defaultPage); @@ -164,7 +186,18 @@ class Login extends Component { else { this.props.history.push({ pathname: "/dashboard", - state: { role_id: role_id, user_id: user_id, token: token, isLogin: true, company_id: company_id, role_name: role_name } + state: { + menu_login: JSON.stringify(resData), + hierarchy, + role_id, + user_id, + token, + isLogin: true, + company_id, + role_name, + all_project, + user_name + } }); } } else { @@ -209,7 +242,7 @@ class Login extends Component { if (doLogin && doLogin.data && doLogin.data.code === 200) { const { access_token, data_user } = doLogin.data.data this.getDataRole(access_token, data_user.role_id) - this.getDataMenu(access_token, data_user.role_id, data_user.id, data_user.company_id, data_user.role.name, data_user.role.all_project) + this.getDataMenu(access_token, data_user.role_id, data_user.hierarchy, data_user.id, data_user.company_id, data_user.role.name, data_user.role.all_project, data_user.user_name) window.localStorage.setItem('isLogin', true); window.localStorage.setItem('token', access_token); window.localStorage.setItem('user_id', data_user.id); diff --git a/src/views/Report/k3/index.js b/src/views/Report/k3/index.js index 36f415a..d967fd9 100644 --- a/src/views/Report/k3/index.js +++ b/src/views/Report/k3/index.js @@ -1,634 +1,629 @@ -import React, { Component } from 'react'; -import { Card, CardBody, CardHeader, Col, Row, Table, Input, InputGroup } from 'reactstrap'; -import { Button } from 'reactstrap'; -import axios from 'axios'; -import moment from 'moment'; -import SweetAlert from 'react-bootstrap-sweetalert'; -import DialogForm from './DialogForm'; -import { NotificationContainer, NotificationManager } from 'react-notifications'; -import { Pagination, Tooltip } from 'antd'; -import { DatePicker, Select } from 'antd'; -import * as XLSX from 'xlsx'; -import { PRESENSI_SEARCH, PROYEK_SEARCH, USERPROYEK_SEARCH, K3_SEARCH, SIMPRO_BASE_IMAGE } from '../../../const/ApiConst.js'; -import { withTranslation } from 'react-i18next'; -const { RangePicker } = DatePicker; -const { Option } = Select - - -const BASE_URL = "" - -const momentFormat = 'DD-MM-YY'; - - - -const LENGTH_DATA = 10 - -class index extends Component { - - constructor(props) { - - let role_id = '', user_id = '', isLogin = '', token = '', company_id = 0, role_name = '', hierarchy = []; - if (props.location.state && props.location.state.role_id && props.location.state.user_id) { - role_id = props.location.state.role_id; - user_id = props.location.state.user_id; - token = props.location.state.token; - isLogin = props.location.state.isLogin; - company_id = props.location.state.company_id; - role_name = props.location.state.role_name; - hierarchy = props.location.state.hierarchy; - - - } else { - token = window.localStorage.getItem('token'); - role_name = window.localStorage.getItem('role_name'); - company_id = window.localStorage.getItem('company_id'); - hierarchy.push(JSON.parse(localStorage.getItem("hierarchy"))); - } - super(props) - this.config = { - headers: { - Authorization: `Bearer ${token}`, - "Content-type": "application/json" - } - }; - this.state = { - dataTable: [], - dataExport: [], - openDialog: false, - dataImage: {}, - typeDialog: 'Save', - dataEdit: null, - alertDelete: false, - idDelete: 0, - dataGs: [], - dataIdHo: [], - search: "", - page: 0, - rowsPerPage: LENGTH_DATA, - currentPage: 1, - totalPage: 0, - tooltipEdit: false, - tooltipDelete: false, - typeClock: "All", - startDate: moment(moment().format("YYYY-M-D")), - endDate: moment(moment().format("YYYY-M-D")), - currentDay: 'today', - tooltipExport: false, - disableProyek: false, - currentProyek: parseInt(localStorage.getItem('role_id')) === 2 ? parseInt(localStorage.getItem('proyek_id')) : null, - allUserToProyek: [], - proyekIds: [], - allDataProyek: [], - finishSetupOption: false, - company_id: company_id, - role_name: role_name, - role_id: role_id, - hierarchy: hierarchy - } - } - - async componentDidMount() { - this.getAllProyek(); - this.setUpFirstProyek(); - } - - async componentDidUpdate(prevProps, prevState) { - const { search, startDate, dataExport, proyekIds, currentProyek } = this.state - if (search !== prevState.search) this.getDataLaporanK3() - if (startDate !== prevState.startDate) this.getDataLaporanK3() - if (dataExport !== prevState.dataExport) { - if (dataExport.length > 0) { - this.exportExcel() - } - } - if (proyekIds !== prevState.proyekIds) { - this.getDataLaporanK3(); - } - - if (currentProyek !== prevState.currentProyek) { - this.getDataLaporanK3(); - } - } - - setUpFirstProyek = () => { - if (parseInt(localStorage.getItem('role_id')) === 2) { - this.setState({ disableProyek: true }); - } else { - this.setState({ currentProyek: null }) - } - } - handleSearch = e => { - const value = e.target.value - this.setState({ search: value, currentPage: 1 }) - }; - - getAllProyek = async () => { - const payload = { - "select": ["id", "nama"], - "paging": { "start": 0, "length": -1 }, - "columns": [ - { "name": "nama", "logic_operator": "ilike", "value": "", "operator": "AND" } - ], - "joins": [], - "orders": { "columns": ["id"], "ascending": false } - } - if (this.state.role_id !== "Super Admin") { - payload.columns.push( - { name: "created_by_id", logic_operator: "IN", value: this.state.hierarchy, operator: "AND" } - ) - } - - const result = await axios - .post(PROYEK_SEARCH, payload, this.config) - .then(res => res) - .catch((error) => error.response); - - - if (result && result.data && result.data.code == 200) { - let resData = result.data.data - - let proyekIds = [] - resData.map((val, index) => { - proyekIds.push(val.id); - }); - this.setState({ allDataProyek: resData, proyekIds: proyekIds }) - } else { - } - } - - getDataLaporanK3 = async () => { - - let start = 0; - if (this.state.currentPage !== 1 && this.state.currentPage > 1) { - start = (this.state.currentPage * this.state.rowsPerPage) - this.state.rowsPerPage - } - - let dateStart = moment(this.state.startDate).format("YYYY-MM-DD 00:00:00"); - let dateEnd = moment(this.state.endDate).format("YYYY-MM-DD 23:59:59"); - let currentProyek = this.state.currentProyek - const payload = { - "paging": { - "start": start, - "length": this.state.rowsPerPage - }, - "filter_columns": [ - { - "name": "name", - "value": "", - "table_name": "m_users" - } - ], - "columns": [ - { "name": "report_date", "logic_operator": "range", "value": dateStart, "value1": dateEnd, "operator": "AND" }, - { "name": "name", "logic_operator": "ilike", "value": this.state.search, "operator": "AND", "table_name": "m_users" } - ], - "joins": [ - { - "name": "m_users", - "column_join": "user_id", - "column_results": [ - "name", - ] - }, - { - "name": "m_proyek", - "column_join": "proyek_id", - "column_results": [ - "nama" - ] - } - ], - "orders": { - "columns": [ - "id" - ], - "ascending": false - }, - "child_data": { - "table_name": "t_report_k3_detail", - "column_table": "report_k3_id", - "column_name": "id" - } - } - - if (currentProyek) { - let proyekPayload = { "name": "proyek_id", "logic_operator": "=", "value": this.state.currentProyek }; - payload.columns.push(proyekPayload) - } else { - let proyekPayload = { "name": "proyek_id", "logic_operator": "in", "value": this.state.proyekIds }; - payload.columns.push(proyekPayload) - } - - const result = await axios - .post(K3_SEARCH, payload, this.config) - .then(res => res) - .catch((error) => error.response); - - - if (result && result.data && result.data.code == 200) { - let resData = result.data.data || [] - this.setState({ dataTable: resData, totalPage: result.data.totalRecord }); - } else { - NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); - } - } - - handleOpenDialog = (type) => { - this.setState({ openDialog: true, typeDialog: type }) - this.showChildDialog(); - } - - handleCloseDialog = (type, data) => { - if (type === "save") { - this.saveDivision(data); - } else if (type === "edit") { - this.editDataDivision(data); - } - - this.setState({ openDialog: false }) - } - - toggleAddDialog = () => { - this.setState({ openDialog: !this.state.openDialog }) - } - - onConfirmDelete = async () => { - const { idDelete } = this.state - let url = BASE_URL + `employee_devision.php?act=delete&id=${idDelete}`; - const result = await axios.post(url) - .then(res => res) - .catch((error) => error.response); - - if (result.message !== undefined) { - if (result.message === "Data Has Been Deleted") { - this.getDataLaporanK3() - this.setState({ idDelete: 0, alertDelete: false }) - NotificationManager.success('Data division berhasil dihapus!!', 'Success!!'); - } else { - this.setState({ idDelete: 0, alertDelete: false }) - NotificationManager.error('Data division gagal dihapus!!', 'Failed!!'); - } - } else { - if (result.data.message === "Data Has Been Deleted") { - this.getDataLaporanK3() - this.setState({ idDelete: 0, alertDelete: false }) - NotificationManager.success('Data division berhasil dihapus!!', 'Success!!'); - } else { - this.setState({ idDelete: 0, alertDelete: false }) - NotificationManager.error('Data division gagal dihapus!!', 'Failed!!'); - } - } - } - - saveDivision = async (data) => { - let url = BASE_URL + "employee_devision.php?act=input"; - - const formData = new FormData() - formData.append('name', data.name); - formData.append('description', data.description); - const result = await axios.post(url, formData) - .then(res => res) - .catch((error) => error.response); - - if (result.message !== undefined) { - if (result.message === "Data Has Been Saved") { - this.getDataLaporanK3(); - NotificationManager.success('Data division berhasil ditambahkan!!', 'Success!!'); - } else { - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - } else { - if (result.data.message === "Data Has Been Saved") { - this.getDataLaporanK3(); - NotificationManager.success('Data division berhasil ditambahkan!!', 'Success!!'); - } else { - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - } - - } - - editDataDivision = async (data) => { - let url = ""; - - const formData = new FormData(); - formData.append('name', data.name); - formData.append('description', data.description); - - const result = await axios.post(url, formData) - .then(res => res) - .catch((error) => error.response); - - if (result.data !== undefined) { - if (result.data.message === "Data Has Been Edited") { - this.getDataLaporanK3(); - NotificationManager.success('Data division berhasil diedit!!', 'Success!!'); - } else { - NotificationManager.error('Data division gagal diedit!!', 'Failed!!'); - } - } - } - - - handleEdit = (data) => { - this.setState({ dataEdit: data }); - this.handleOpenDialog('Edit'); - } - - handleDelete = (id) => { - this.setState({ alertDelete: true, idDelete: id }); - } - - onShowSizeChange = (current, pageSize) => { - this.setState({ rowsPerPage: pageSize }, () => { - this.getDataLaporanK3(); - }) - } - - onPagination = (current, pageSize) => { - this.setState({ currentPage: current, page: (current - 1) * pageSize }, () => { - this.getDataLaporanK3(); - }) - } - - toggle = (param) => { - if (param === "edit") { - this.setState(prevState => ({ tooltipEdit: !prevState.tooltipEdit })) - } else if (param === "delete") { - this.setState(prevState => ({ tooltipDelete: !prevState.tooltipDelete })) - } else if (param === "export") { - this.setState(prevState => ({ tooltipExport: !prevState.tooltipExport })) - } - } - - handleDatePicker = (date, dateString) => { - this.setState({ startDate: date[0], endDate: date[1] }, () => { - this.getDataLaporanK3(); - }) - } - - handleTipe = (e) => { - this.setState({ typeClock: e.target.value }, () => { - this.getDataLaporanK3(); - }); - } - - handleExportExcel = async () => { - let dateStart = moment(this.state.startDate).format("YYYY-MM-DD 00:00:00"); - let dateEnd = moment(this.state.endDate).format("YYYY-MM-DD 23:59:59"); - let currentProyek = this.state.currentProyek - const payload = { - "paging": { - "start": 0, - "length": -1 - }, - "columns": [ - { "name": "report_date", "logic_operator": "range", "value": dateStart, "value1": dateEnd, "operator": "AND" }, - { "name": "name", "logic_operator": "ilike", "value": this.state.search, "operator": "AND", "table_name": "m_users" } - ], - "joins": [ - { - "name": "m_users", - "column_join": "user_id", - "column_results": [ - "name", - ] - } - ], - "orders": { - "columns": [ - "id" - ], - "ascending": false - }, - "child_data": { - "table_name": "t_report_k3_detail", - "column_table": "report_k3_id", - "column_name": "id" - } - } - - if (currentProyek) { - let proyekPayload = { "name": "proyek_id", "logic_operator": "=", "value": this.state.currentProyek }; - payload.columns.push(proyekPayload) - } else { - let proyekPayload = { "name": "proyek_id", "logic_operator": "in", "value": this.state.proyekIds }; - payload.columns.push(proyekPayload) - } - - - - const result = await axios - .post(K3_SEARCH, payload, this.config) - .then(res => res) - .catch((error) => error.response); - - - if (result && result.data && result.data.code == 200) { - let resData = result.data.data || [] - const excelData = []; - - resData.map((n, index) => { - let dataRow = { - "Nama Human Resource": n.join_first_name ? n.join_first_name : "-", - "Tanggal Lapor": n.report_date ? moment(n.report_date).format("DD-MM-YYYY HH:mm:ss") : "-", - "Perlengkapan Dikenakan": n.k3_checked.length ? n.k3_checked.join() : "-", - "Perlengkapan Tidak Dikenakan": n.k3_not_checked.length ? n.k3_not_checked.join() : "-", - "Description": n.description ? n.description : "-" - } - excelData.push(dataRow) - }) - this.setState({ dataExport: excelData }) - } else { - NotificationManager.error('Gagal Export Data!!', 'Failed'); - } - } - - exportExcel = () => { - const dataExcel = this.state.dataExport || []; - const fileName = `Data Laporan K3.xlsx`; - const ws = XLSX.utils.json_to_sheet(dataExcel); - const wb = XLSX.utils.book_new(); - XLSX.utils.book_append_sheet(wb, ws, `Data Laporan K3`); - - XLSX.writeFile(wb, fileName); - this.setState({ dataExport: [] }) - } - - lihatFoto = (data) => { - this.showChildDialog(); - this.setState({ dataImage: data }, () => { - this.setState({ openDialog: true }); - }); - } - - renderTable = () => { - const { t } = this.props; - const dataTable2 = this.state.dataTable || []; - return ( - - {dataTable2.length !== 0 ? dataTable2.map((n) => { - return ( - - - - - - - - - - ) - }) : - - - } - - ) - } - - handleChangeDay = (e) => { - const val = e.target.value; - this.setState({ currentDay: val }); - if (val === "today") { - this.setState({ - startDate: moment(moment().format("YYYY-M-D")), - endDate: moment(moment().format("YYYY-M-D")), - currentPage: 1 - }) - } else if (val === "3 day") { - this.setState({ - startDate: moment(moment().subtract(3, "days").format("YYYY-M-D")), - endDate: moment(moment().format("YYYY-M-D")), - currentPage: 1 - }) - } else if (val === "7 day") { - this.setState({ - startDate: moment(moment().subtract(7, "days").format("YYYY-M-D")), - endDate: moment(moment().format("YYYY-M-D")), - currentPage: 1 - }) - } else { - this.setState({ - startDate: moment(moment().format("YYYY-M-D")), - endDate: moment(moment().format("YYYY-M-D")), - currentPage: 1 - }) - } - } - - setupSelectProyek = () => { - let allDataProyek = this.state.allDataProyek - return ( - <> - {allDataProyek.map((val, index) => { - return ( - - ) - }) - } - - ) - } - - onChangeProyek = (val) => { - this.setState({ currentProyek: val }); - } - - delay = (ms) => new Promise(res => setTimeout(res, ms)); - - render() { - const column = [ - { name: this.props.t('nameHR') }, - { name: this.props.t('projectName') }, - { name: this.props.t('dateReport') }, - { name: this.props.t('gearUse') }, - { name: this.props.t('gearNotUse') }, - { name: this.props.t('description') }, - { name: this.props.t('action') }, - ] - const t = this.props; - const { tooltipExport, dataTable, openDialog, currentPage, rowsPerPage, totalPage, search, tooltipEdit, tooltipDelete } = this.state - return ( -
- - this.setState({ alertDelete: false, idDelete: 0 })} - focusCancelBtn - > - {this.props.t('deleteMsg')} - - this.toggleAddDialog} - dataImage={this.state.dataImage} - showDialog={showDialog => this.showChildDialog = showDialog} - /> - - -

{this.props.params.name}

-
- - - -
-
- -
-
-
- -
-
- this.handleChangeDay(e)} defaultValue={this.state.currentDay}> - - - - -
-
- {' '} - -
-
- -
-
{n.join_first_name ? n.join_first_name : "-"}{n.join_second_nama ? n.join_second_nama : "-"}{n.report_date ? moment(n.report_date).format("DD-MM-YYYY") : "-"}{n.k3_checked.length ? n.k3_checked.join() : "-"}{n.k3_not_checked.length ? n.k3_not_checked.join() : "-"}{n.description ? n.description : "-"} {n.image ? this.lihatFoto(n.image)} className='fa fa-image'> : ""}
{this.props.t('noData')}
- - - {/* */} - {column.map((i, index) => { - return ( - - ) - })} - - - {this.renderTable()} -
Actions{i.name}
- - - - - ) - } -} -export default withTranslation()(index); +import React, { Component } from 'react'; +import { Card, CardBody, CardHeader, Col, Row, Table, Input, InputGroup } from 'reactstrap'; +import { Button } from 'reactstrap'; +import axios from 'axios'; +import moment from 'moment'; +import SweetAlert from 'react-bootstrap-sweetalert'; +import DialogForm from './DialogForm'; +import { NotificationContainer, NotificationManager } from 'react-notifications'; +import { Pagination, Tooltip } from 'antd'; +import { DatePicker, Select } from 'antd'; +import * as XLSX from 'xlsx'; +import { PRESENSI_SEARCH, PROYEK_SEARCH, USERPROYEK_SEARCH, K3_SEARCH, SIMPRO_BASE_IMAGE } from '../../../const/ApiConst.js'; +import { withTranslation } from 'react-i18next'; +const { RangePicker } = DatePicker; +const { Option } = Select + + +const BASE_URL = "" + +const momentFormat = 'DD-MM-YY'; + + + +const LENGTH_DATA = 10 + +class index extends Component { + + constructor(props) { + let role_id = 0, user_id = 0, isLogin = false, token = '', company_id = 0, all_project = null, role_name='', hierarchy=[], user_name=''; + if (props && props.role_id && props.user_id) { + role_id = props.role_id; + user_id = props.user_id; + token = props.token; + isLogin = props.isLogin; + company_id = props.company_id; + all_project = props.all_project; + role_name = props.role_name; + isLogin = props.isLogin; + hierarchy = props.hierarchy; + user_name = props.user_name; + } + super(props) + this.config = { + headers: { + Authorization: `Bearer ${token}`, + "Content-type": "application/json" + } + }; + this.state = { + dataTable: [], + dataExport: [], + openDialog: false, + dataImage: {}, + typeDialog: 'Save', + dataEdit: null, + alertDelete: false, + idDelete: 0, + dataGs: [], + dataIdHo: [], + search: "", + page: 0, + rowsPerPage: LENGTH_DATA, + currentPage: 1, + totalPage: 0, + tooltipEdit: false, + tooltipDelete: false, + typeClock: "All", + startDate: moment(moment().format("YYYY-M-D")), + endDate: moment(moment().format("YYYY-M-D")), + currentDay: 'today', + tooltipExport: false, + disableProyek: false, + currentProyek: parseInt(localStorage.getItem('role_id')) === 2 ? parseInt(localStorage.getItem('proyek_id')) : null, + allUserToProyek: [], + proyekIds: [], + allDataProyek: [], + finishSetupOption: false, + company_id: company_id, + role_name: role_name, + role_id: role_id, + hierarchy: hierarchy + } + } + + async componentDidMount() { + this.getAllProyek(); + this.setUpFirstProyek(); + } + + async componentDidUpdate(prevProps, prevState) { + const { search, startDate, dataExport, proyekIds, currentProyek } = this.state + if (search !== prevState.search) this.getDataLaporanK3() + if (startDate !== prevState.startDate) this.getDataLaporanK3() + if (dataExport !== prevState.dataExport) { + if (dataExport.length > 0) { + this.exportExcel() + } + } + if (proyekIds !== prevState.proyekIds) { + this.getDataLaporanK3(); + } + + if (currentProyek !== prevState.currentProyek) { + this.getDataLaporanK3(); + } + } + + setUpFirstProyek = () => { + if (parseInt(localStorage.getItem('role_id')) === 2) { + this.setState({ disableProyek: true }); + } else { + this.setState({ currentProyek: null }) + } + } + handleSearch = e => { + const value = e.target.value + this.setState({ search: value, currentPage: 1 }) + }; + + getAllProyek = async () => { + const payload = { + "select": ["id", "nama"], + "paging": { "start": 0, "length": -1 }, + "columns": [ + { "name": "nama", "logic_operator": "ilike", "value": "", "operator": "AND" } + ], + "joins": [], + "orders": { "columns": ["id"], "ascending": false } + } + if (this.state.role_id !== "Super Admin") { + payload.columns.push( + { name: "created_by_id", logic_operator: "IN", value: this.state.hierarchy, operator: "AND" } + ) + } + + const result = await axios + .post(PROYEK_SEARCH, payload, this.config) + .then(res => res) + .catch((error) => error.response); + + + if (result && result.data && result.data.code == 200) { + let resData = result.data.data + + let proyekIds = [] + resData.map((val, index) => { + proyekIds.push(val.id); + }); + this.setState({ allDataProyek: resData, proyekIds: proyekIds }) + } else { + } + } + + getDataLaporanK3 = async () => { + + let start = 0; + if (this.state.currentPage !== 1 && this.state.currentPage > 1) { + start = (this.state.currentPage * this.state.rowsPerPage) - this.state.rowsPerPage + } + + let dateStart = moment(this.state.startDate).format("YYYY-MM-DD 00:00:00"); + let dateEnd = moment(this.state.endDate).format("YYYY-MM-DD 23:59:59"); + let currentProyek = this.state.currentProyek + const payload = { + "paging": { + "start": start, + "length": this.state.rowsPerPage + }, + "filter_columns": [ + { + "name": "name", + "value": "", + "table_name": "m_users" + } + ], + "columns": [ + { "name": "report_date", "logic_operator": "range", "value": dateStart, "value1": dateEnd, "operator": "AND" }, + { "name": "name", "logic_operator": "ilike", "value": this.state.search, "operator": "AND", "table_name": "m_users" } + ], + "joins": [ + { + "name": "m_users", + "column_join": "user_id", + "column_results": [ + "name", + ] + }, + { + "name": "m_proyek", + "column_join": "proyek_id", + "column_results": [ + "nama" + ] + } + ], + "orders": { + "columns": [ + "id" + ], + "ascending": false + }, + "child_data": { + "table_name": "t_report_k3_detail", + "column_table": "report_k3_id", + "column_name": "id" + } + } + + if (currentProyek) { + let proyekPayload = { "name": "proyek_id", "logic_operator": "=", "value": this.state.currentProyek }; + payload.columns.push(proyekPayload) + } else { + let proyekPayload = { "name": "proyek_id", "logic_operator": "in", "value": this.state.proyekIds }; + payload.columns.push(proyekPayload) + } + + const result = await axios + .post(K3_SEARCH, payload, this.config) + .then(res => res) + .catch((error) => error.response); + + + if (result && result.data && result.data.code == 200) { + let resData = result.data.data || [] + this.setState({ dataTable: resData, totalPage: result.data.totalRecord }); + } else { + NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); + } + } + + handleOpenDialog = (type) => { + this.setState({ openDialog: true, typeDialog: type }) + this.showChildDialog(); + } + + handleCloseDialog = (type, data) => { + if (type === "save") { + this.saveDivision(data); + } else if (type === "edit") { + this.editDataDivision(data); + } + + this.setState({ openDialog: false }) + } + + toggleAddDialog = () => { + this.setState({ openDialog: !this.state.openDialog }) + } + + onConfirmDelete = async () => { + const { idDelete } = this.state + let url = BASE_URL + `employee_devision.php?act=delete&id=${idDelete}`; + const result = await axios.post(url) + .then(res => res) + .catch((error) => error.response); + + if (result.message !== undefined) { + if (result.message === "Data Has Been Deleted") { + this.getDataLaporanK3() + this.setState({ idDelete: 0, alertDelete: false }) + NotificationManager.success('Data division berhasil dihapus!!', 'Success!!'); + } else { + this.setState({ idDelete: 0, alertDelete: false }) + NotificationManager.error('Data division gagal dihapus!!', 'Failed!!'); + } + } else { + if (result.data.message === "Data Has Been Deleted") { + this.getDataLaporanK3() + this.setState({ idDelete: 0, alertDelete: false }) + NotificationManager.success('Data division berhasil dihapus!!', 'Success!!'); + } else { + this.setState({ idDelete: 0, alertDelete: false }) + NotificationManager.error('Data division gagal dihapus!!', 'Failed!!'); + } + } + } + + saveDivision = async (data) => { + let url = BASE_URL + "employee_devision.php?act=input"; + + const formData = new FormData() + formData.append('name', data.name); + formData.append('description', data.description); + const result = await axios.post(url, formData) + .then(res => res) + .catch((error) => error.response); + + if (result.message !== undefined) { + if (result.message === "Data Has Been Saved") { + this.getDataLaporanK3(); + NotificationManager.success('Data division berhasil ditambahkan!!', 'Success!!'); + } else { + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + } else { + if (result.data.message === "Data Has Been Saved") { + this.getDataLaporanK3(); + NotificationManager.success('Data division berhasil ditambahkan!!', 'Success!!'); + } else { + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + } + + } + + editDataDivision = async (data) => { + let url = ""; + + const formData = new FormData(); + formData.append('name', data.name); + formData.append('description', data.description); + + const result = await axios.post(url, formData) + .then(res => res) + .catch((error) => error.response); + + if (result.data !== undefined) { + if (result.data.message === "Data Has Been Edited") { + this.getDataLaporanK3(); + NotificationManager.success('Data division berhasil diedit!!', 'Success!!'); + } else { + NotificationManager.error('Data division gagal diedit!!', 'Failed!!'); + } + } + } + + + handleEdit = (data) => { + this.setState({ dataEdit: data }); + this.handleOpenDialog('Edit'); + } + + handleDelete = (id) => { + this.setState({ alertDelete: true, idDelete: id }); + } + + onShowSizeChange = (current, pageSize) => { + this.setState({ rowsPerPage: pageSize }, () => { + this.getDataLaporanK3(); + }) + } + + onPagination = (current, pageSize) => { + this.setState({ currentPage: current, page: (current - 1) * pageSize }, () => { + this.getDataLaporanK3(); + }) + } + + toggle = (param) => { + if (param === "edit") { + this.setState(prevState => ({ tooltipEdit: !prevState.tooltipEdit })) + } else if (param === "delete") { + this.setState(prevState => ({ tooltipDelete: !prevState.tooltipDelete })) + } else if (param === "export") { + this.setState(prevState => ({ tooltipExport: !prevState.tooltipExport })) + } + } + + handleDatePicker = (date, dateString) => { + this.setState({ startDate: date[0], endDate: date[1] }, () => { + this.getDataLaporanK3(); + }) + } + + handleTipe = (e) => { + this.setState({ typeClock: e.target.value }, () => { + this.getDataLaporanK3(); + }); + } + + handleExportExcel = async () => { + let dateStart = moment(this.state.startDate).format("YYYY-MM-DD 00:00:00"); + let dateEnd = moment(this.state.endDate).format("YYYY-MM-DD 23:59:59"); + let currentProyek = this.state.currentProyek + const payload = { + "paging": { + "start": 0, + "length": -1 + }, + "columns": [ + { "name": "report_date", "logic_operator": "range", "value": dateStart, "value1": dateEnd, "operator": "AND" }, + { "name": "name", "logic_operator": "ilike", "value": this.state.search, "operator": "AND", "table_name": "m_users" } + ], + "joins": [ + { + "name": "m_users", + "column_join": "user_id", + "column_results": [ + "name", + ] + } + ], + "orders": { + "columns": [ + "id" + ], + "ascending": false + }, + "child_data": { + "table_name": "t_report_k3_detail", + "column_table": "report_k3_id", + "column_name": "id" + } + } + + if (currentProyek) { + let proyekPayload = { "name": "proyek_id", "logic_operator": "=", "value": this.state.currentProyek }; + payload.columns.push(proyekPayload) + } else { + let proyekPayload = { "name": "proyek_id", "logic_operator": "in", "value": this.state.proyekIds }; + payload.columns.push(proyekPayload) + } + + + + const result = await axios + .post(K3_SEARCH, payload, this.config) + .then(res => res) + .catch((error) => error.response); + + + if (result && result.data && result.data.code == 200) { + let resData = result.data.data || [] + const excelData = []; + + resData.map((n, index) => { + let dataRow = { + "Nama Human Resource": n.join_first_name ? n.join_first_name : "-", + "Tanggal Lapor": n.report_date ? moment(n.report_date).format("DD-MM-YYYY HH:mm:ss") : "-", + "Perlengkapan Dikenakan": n.k3_checked.length ? n.k3_checked.join() : "-", + "Perlengkapan Tidak Dikenakan": n.k3_not_checked.length ? n.k3_not_checked.join() : "-", + "Description": n.description ? n.description : "-" + } + excelData.push(dataRow) + }) + this.setState({ dataExport: excelData }) + } else { + NotificationManager.error('Gagal Export Data!!', 'Failed'); + } + } + + exportExcel = () => { + const dataExcel = this.state.dataExport || []; + const fileName = `Data Laporan K3.xlsx`; + const ws = XLSX.utils.json_to_sheet(dataExcel); + const wb = XLSX.utils.book_new(); + XLSX.utils.book_append_sheet(wb, ws, `Data Laporan K3`); + + XLSX.writeFile(wb, fileName); + this.setState({ dataExport: [] }) + } + + lihatFoto = (data) => { + this.showChildDialog(); + this.setState({ dataImage: data }, () => { + this.setState({ openDialog: true }); + }); + } + + renderTable = () => { + const { t } = this.props; + const dataTable2 = this.state.dataTable || []; + return ( + + {dataTable2.length !== 0 ? dataTable2.map((n) => { + return ( + + {n.join_first_name ? n.join_first_name : "-"} + {n.join_second_nama ? n.join_second_nama : "-"} + {n.report_date ? moment(n.report_date).format("DD-MM-YYYY") : "-"} + {n.k3_checked.length ? n.k3_checked.join() : "-"} + {n.k3_not_checked.length ? n.k3_not_checked.join() : "-"} + {n.description ? n.description : "-"} + {n.image ? this.lihatFoto(n.image)} className='fa fa-image'> : ""} + + ) + }) : + {this.props.t('noData')} + + } + + ) + } + + handleChangeDay = (e) => { + const val = e.target.value; + this.setState({ currentDay: val }); + if (val === "today") { + this.setState({ + startDate: moment(moment().format("YYYY-M-D")), + endDate: moment(moment().format("YYYY-M-D")), + currentPage: 1 + }) + } else if (val === "3 day") { + this.setState({ + startDate: moment(moment().subtract(3, "days").format("YYYY-M-D")), + endDate: moment(moment().format("YYYY-M-D")), + currentPage: 1 + }) + } else if (val === "7 day") { + this.setState({ + startDate: moment(moment().subtract(7, "days").format("YYYY-M-D")), + endDate: moment(moment().format("YYYY-M-D")), + currentPage: 1 + }) + } else { + this.setState({ + startDate: moment(moment().format("YYYY-M-D")), + endDate: moment(moment().format("YYYY-M-D")), + currentPage: 1 + }) + } + } + + setupSelectProyek = () => { + let allDataProyek = this.state.allDataProyek + return ( + <> + {allDataProyek.map((val, index) => { + return ( + + ) + }) + } + + ) + } + + onChangeProyek = (val) => { + this.setState({ currentProyek: val }); + } + + delay = (ms) => new Promise(res => setTimeout(res, ms)); + + render() { + const column = [ + { name: this.props.t('nameHR') }, + { name: this.props.t('projectName') }, + { name: this.props.t('dateReport') }, + { name: this.props.t('gearUse') }, + { name: this.props.t('gearNotUse') }, + { name: this.props.t('description') }, + { name: this.props.t('action') }, + ] + const t = this.props; + const { tooltipExport, dataTable, openDialog, currentPage, rowsPerPage, totalPage, search, tooltipEdit, tooltipDelete } = this.state + return ( +
+ + this.setState({ alertDelete: false, idDelete: 0 })} + focusCancelBtn + > + {this.props.t('deleteMsg')} + + this.toggleAddDialog} + dataImage={this.state.dataImage} + showDialog={showDialog => this.showChildDialog = showDialog} + /> + + +

{this.props.params.name}

+
+ + + +
+
+ +
+
+
+ +
+
+ this.handleChangeDay(e)} defaultValue={this.state.currentDay}> + + + + +
+
+ {' '} + +
+
+ +
+ + + + {/* */} + {column.map((i, index) => { + return ( + + ) + })} + + + {this.renderTable()} +
Actions{i.name}
+ +
+
+
+ ) + } +} +export default withTranslation()(index); diff --git a/src/views/SimproV2/CreatedProyek/index.js b/src/views/SimproV2/CreatedProyek/index.js index 30912f9..255e9c3 100644 --- a/src/views/SimproV2/CreatedProyek/index.js +++ b/src/views/SimproV2/CreatedProyek/index.js @@ -85,23 +85,18 @@ const url = ""; const format = "DD-MM-YYYY"; const CreatedProyek = ({ params, ...props }) => { - let role_id = '', user_id = '', proyek_id = '', isLogin = '', token = '', company_id = 0, all_project = ''; - if (props.location.state && props.location.state.role_id && props.location.state.user_id) { - role_id = props.location.state.role_id; - user_id = props.location.state.user_id; - token = props.location.state.token; - isLogin = props.location.state.isLogin; - company_id = props.location.state.company_id; - all_project = props.location.state.all_project; - - } else { - role_id = localStorage.getItem("role_id"); - proyek_id = localStorage.getItem("proyek_id"); - user_id = localStorage.getItem("user_id"); - token = localStorage.getItem("token"); - isLogin = localStorage.getItem("isLogin"); - company_id = localStorage.getItem('company_id'); - all_project = localStorage.getItem('all_project'); + let role_id = 0, user_id = 0, isLogin = false, token = '', company_id = 0, all_project = null, role_name='', hierarchy=[], user_name=''; + if (props && props.role_id && props.user_id) { + role_id = props.role_id; + user_id = props.user_id; + token = props.token; + isLogin = props.isLogin; + company_id = props.company_id; + all_project = props.all_project; + role_name = props.role_name; + isLogin = props.isLogin; + hierarchy = props.hierarchy; + user_name = props.user_name; } const history = useHistory(); const HEADER = { @@ -370,7 +365,6 @@ const CreatedProyek = ({ params, ...props }) => { column_join: "type_proyek_id", column_results: ["name", "description"], }, - // { "name": "subproyeks.m_subproyek", "column_join": "parent_id", "column_results": ["nama", "biaya", "color_progress", "jumlah_pekerja", "pic", "mulai_proyek", "akhir_proyek", "biaya_actual", "persentase_progress_plan", "persentase_progress_actual"] } ], orders: { columns: ["nama"], ascending: true }, paging: { start: start, length: rowsPerPage }, @@ -512,7 +506,6 @@ const CreatedProyek = ({ params, ...props }) => { }; const handleOpenDialogGantt = (data) => { - console.log('data.mulai_proyek', data.mulai_proyek); setDataViewStartDate(data.mulai_proyek) setidTask(data.id); setProyekName(data.nama); @@ -718,7 +711,6 @@ const CreatedProyek = ({ params, ...props }) => { orders: { columns: ["id"], ascending: true }, paging: { start: 0, length: -1 }, }; - // const url = PROJECT_MI(proyek_id) const result = await axios .post(ASSIGN_HR_PROJECT_SEARCH, payload, HEADER) .then((res) => res) @@ -1342,9 +1334,13 @@ const CreatedProyek = ({ params, ...props }) => { orders: { columns: ["id"], ascending: false }, }; - if (parseInt(role_id) !== 1) { + if (all_project !== null && all_project === true) { + payload["columns"] = [ + { name: "company_id", logic_operator: "like", value: company_id, operator: "AND" } + ]; + } else { payload["columns"] = [ - { name: "id", logic_operator: "=", value: proyek_id, operator: "AND" }, + { name: "created_by_id", logic_operator: "IN", value: hierarchy, operator: "AND" } ]; } @@ -2039,7 +2035,6 @@ const CreatedProyek = ({ params, ...props }) => { )} Close} title="Export" trigger="click" placement="leftBottom" @@ -2064,12 +2059,9 @@ const CreatedProyek = ({ params, ...props }) => { } - // visible={visible} - // onVisibleChange={handleVisibleChange} > diff --git a/src/views/SimproV2/Divisi/index.js b/src/views/SimproV2/Divisi/index.js index 9605901..386919d 100644 --- a/src/views/SimproV2/Divisi/index.js +++ b/src/views/SimproV2/Divisi/index.js @@ -17,22 +17,19 @@ const column = [ ] const ProjectType = ({ params, ...props }) => { - let role_id = '', user_id = '', proyek_id = '', isLogin = '', token = '', company_id = 0, role_name = ''; - if (props.location.state && props.location.state.role_id && props.location.state.user_id) { - role_id = props.location.state.role_id; - user_id = props.location.state.user_id; - token = props.location.state.token; - isLogin = props.location.state.isLogin; - role_name = props.location.state.role_name; - } else { - role_id = localStorage.getItem("role_id"); - proyek_id = localStorage.getItem("proyek_id"); - user_id = localStorage.getItem("user_id"); - token = localStorage.getItem("token"); - isLogin = localStorage.getItem("isLogin"); - company_id = localStorage.getItem('company_id'); - role_name = localStorage.getItem('role_name'); - } + let role_id = 0, user_id = 0, isLogin = false, token = '', company_id = 0, all_project = null, role_name='', hierarchy=[], user_name=''; + if (props && props.role_id && props.user_id) { + role_id = props.role_id; + user_id = props.user_id; + token = props.token; + isLogin = props.isLogin; + company_id = props.company_id; + all_project = props.all_project; + role_name = props.role_name; + isLogin = props.isLogin; + hierarchy = props.hierarchy; + user_name = props.user_name; + } const HEADER = { headers: { "Content-Type": "application/json", diff --git a/src/views/SimproV2/Gantt/GanttFrame.js b/src/views/SimproV2/Gantt/GanttFrame.js index de840e7..e7c687f 100644 --- a/src/views/SimproV2/Gantt/GanttFrame.js +++ b/src/views/SimproV2/Gantt/GanttFrame.js @@ -3,22 +3,9 @@ import { useHistory, withRouter } from 'react-router-dom'; import { BASE_SIMPRO_LUMEN } from '../../../const/ApiConst'; const GanttFrame = React.memo((props) => { - let role_id = '', user_id = '', proyek_id = '', isLogin = '', token = ''; - if (props.location.state && props.location.state.role_id && props.location.state.user_id) { - role_id = props.location.state.role_id; - user_id = props.location.state.user_id; - isLogin = props.location.state.isLogin; - token = props.location.state.token; - } else { - role_id = localStorage.getItem("role_id"); - proyek_id = localStorage.getItem("proyek_id"); - user_id = localStorage.getItem("user_id"); - isLogin = localStorage.getItem("isLogin"); - token = localStorage.getItem("token"); - } const history = useHistory(); - const { versionGanttId, idProject, ro, timestamp, dataViewStartDate } = props; - const iframeSrc = `http://localhost:8444/adw-gantt/edit-mode/index.html?base_url=${BASE_SIMPRO_LUMEN}&gantt_id=${versionGanttId}&proyek_id=${idProject}&token=${token}&ro=${ro}×tamp=${timestamp}&start=${dataViewStartDate}`; + const { versionGanttId, idProject, ro, timestamp, dataViewStartDate, token } = props; + const iframeSrc = `https://project-gantt.ospro.id/edit-mode/index.html?base_url=${BASE_SIMPRO_LUMEN}&gantt_id=${versionGanttId}&proyek_id=${idProject}&token=${token}&ro=${ro}×tamp=${timestamp}&start=${dataViewStartDate}`; const [batchEntityData, setBatchEntityData] = useState(null); useEffect(() => { diff --git a/src/views/SimproV2/Gantt/index.js b/src/views/SimproV2/Gantt/index.js index 3dcf7fa..cc7aba0 100644 --- a/src/views/SimproV2/Gantt/index.js +++ b/src/views/SimproV2/Gantt/index.js @@ -15,18 +15,18 @@ import GanttFrame from "./GanttFrame"; let roCount = 0; const Gantt = (props) => { - let role_id = '', userId = '', isLogin = '', token = ''; - if (props.location.state && props.location.state.role_id && props.location.state.user_id) { - role_id = props.location.state.role_id; - userId = props.location.state.user_id; - token = props.location.state.token; - isLogin = props.location.state.isLogin; - } else { - role_id = localStorage.getItem("role_id"); - userId = localStorage.getItem("user_id"); - token = localStorage.getItem("token"); - isLogin = localStorage.getItem("isLogin"); - + let role_id = 0, user_id = 0, isLogin = false, token = '', company_id = 0, all_project = null, role_name='', hierarchy=[], user_name=''; + if (props && props.role_id && props.user_id) { + role_id = props.role_id; + user_id = props.user_id; + token = props.token; + isLogin = props.isLogin; + company_id = props.company_id; + all_project = props.all_project; + role_name = props.role_name; + isLogin = props.isLogin; + hierarchy = props.hierarchy; + user_name = props.user_name; } const HEADER = { headers: { @@ -39,7 +39,6 @@ const Gantt = (props) => { const timestamp = props.match.params.timestamp ? props.match.params.timestamp : 0; - const [ro, setRo] = useState(1); const [listUserGant, setListUserGantt] = useState([]); const [ready, setReady] = useState(false); @@ -93,7 +92,7 @@ const Gantt = (props) => { }; const cekPermission = () => { - let check = listUserGant.includes(parseInt(userId)); + let check = listUserGant.includes(parseInt(user_id)); if (check) { setRo(0); } else { diff --git a/src/views/SimproV2/ProjectType/index.js b/src/views/SimproV2/ProjectType/index.js index 9ca0621..ba95481 100644 --- a/src/views/SimproV2/ProjectType/index.js +++ b/src/views/SimproV2/ProjectType/index.js @@ -13,21 +13,18 @@ import { Pagination, Button, Tooltip, Table } from 'antd'; import { useTranslation } from 'react-i18next'; const ProjectType = ({ params, ...props }) => { - let role_id = '', user_id = '', proyek_id = '', isLogin = '', token = '', company_id = 0, role_name = ''; - if (props.location.state && props.location.state.role_id && props.location.state.user_id) { - role_id = props.location.state.role_id; - user_id = props.location.state.user_id; - token = props.location.state.token; - isLogin = props.location.state.isLogin; - role_name = props.location.state.role_name; - } else { - role_id = localStorage.getItem("role_id"); - proyek_id = localStorage.getItem("proyek_id"); - user_id = localStorage.getItem("user_id"); - token = localStorage.getItem("token"); - isLogin = localStorage.getItem("isLogin"); - company_id = localStorage.getItem('company_id'); - role_name = localStorage.getItem('role_name'); + let role_id = 0, user_id = 0, isLogin = false, token = '', company_id = 0, all_project = null, role_name='', hierarchy=[], user_name=''; + if (props && props.role_id && props.user_id) { + role_id = props.role_id; + user_id = props.user_id; + token = props.token; + isLogin = props.isLogin; + company_id = props.company_id; + all_project = props.all_project; + role_name = props.role_name; + isLogin = props.isLogin; + hierarchy = props.hierarchy; + user_name = props.user_name; } const HEADER = { headers: { diff --git a/src/views/SimproV2/ResourceWorker/index.js b/src/views/SimproV2/ResourceWorker/index.js index ada1de8..cbc0185 100644 --- a/src/views/SimproV2/ResourceWorker/index.js +++ b/src/views/SimproV2/ResourceWorker/index.js @@ -15,21 +15,18 @@ import { import { useTranslation } from 'react-i18next'; const ResourceWorker = ({ params, ...props }) => { - let role_id = '', user_id = '', proyek_id = '', isLogin = '', token = '', company_id = 0, role_name = ''; - if (props.location.state && props.location.state.role_id && props.location.state.user_id) { - role_id = props.location.state.role_id; - user_id = props.location.state.user_id; - token = props.location.state.token; - isLogin = props.location.state.isLogin; - role_name = props.location.state.role_name; - } else { - role_id = localStorage.getItem("role_id"); - proyek_id = localStorage.getItem("proyek_id"); - user_id = localStorage.getItem("user_id"); - token = localStorage.getItem("token"); - isLogin = localStorage.getItem("isLogin"); - company_id = localStorage.getItem('company_id'); - role_name = localStorage.getItem('role_name'); + let role_id = 0, user_id = 0, isLogin = false, token = '', company_id = 0, all_project = null, role_name='', hierarchy=[], user_name=''; + if (props && props.role_id && props.user_id) { + role_id = props.role_id; + user_id = props.user_id; + token = props.token; + isLogin = props.isLogin; + company_id = props.company_id; + all_project = props.all_project; + role_name = props.role_name; + isLogin = props.isLogin; + hierarchy = props.hierarchy; + user_name = props.user_name; } const HEADER = { diff --git a/src/views/SimproV2/Satuan/index.js b/src/views/SimproV2/Satuan/index.js index f849360..3c694bc 100644 --- a/src/views/SimproV2/Satuan/index.js +++ b/src/views/SimproV2/Satuan/index.js @@ -11,22 +11,20 @@ import { useTranslation } from 'react-i18next'; const Satuan = ({ params, ...props }) => { - let role_id = '', user_id = '', proyek_id = '', isLogin = '', token = '', company_id = 0, role_name = ''; - if (props.location.state && props.location.state.role_id && props.location.state.user_id) { - role_id = props.location.state.role_id; - user_id = props.location.state.user_id; - token = props.location.state.token; - isLogin = props.location.state.isLogin; - role_name = props.location.state.role_name; - } else { - role_id = localStorage.getItem("role_id"); - proyek_id = localStorage.getItem("proyek_id"); - user_id = localStorage.getItem("user_id"); - token = localStorage.getItem("token"); - isLogin = localStorage.getItem("isLogin"); - company_id = localStorage.getItem('company_id'); - role_name = localStorage.getItem('role_name'); - } + let role_id = 0, user_id = 0, isLogin = false, token = '', company_id = 0, all_project = null, role_name='', hierarchy=[], user_name=''; + if (props && props.role_id && props.user_id) { + role_id = props.role_id; + user_id = props.user_id; + token = props.token; + isLogin = props.isLogin; + company_id = props.company_id; + all_project = props.all_project; + role_name = props.role_name; + isLogin = props.isLogin; + hierarchy = props.hierarchy; + user_name = props.user_name; + } + const HEADER = { headers: { "Content-Type": "application/json",