From 59a34369e5f150e14f414bcf899d66e13edea017 Mon Sep 17 00:00:00 2001 From: wahyu Date: Wed, 13 Sep 2023 11:24:43 +0700 Subject: [PATCH 1/7] endfile fix --- src/views/SimproV2/CreatedProyek/index.js | 3056 +++++++++++---------- 1 file changed, 1530 insertions(+), 1526 deletions(-) diff --git a/src/views/SimproV2/CreatedProyek/index.js b/src/views/SimproV2/CreatedProyek/index.js index a15ddea..21bfe1d 100644 --- a/src/views/SimproV2/CreatedProyek/index.js +++ b/src/views/SimproV2/CreatedProyek/index.js @@ -1,1526 +1,1530 @@ -import React, { useState, useEffect, useMemo } from "react"; -import { Card, CardBody, CardHeader, Col, Row, Input } from "reactstrap"; -import axios from "../../../const/interceptorApi"; -import jsPDF from "jspdf"; -import autoTable from "jspdf-autotable"; -import * as XLSX from "xlsx"; -import SweetAlert from "react-bootstrap-sweetalert"; -import DialogForm from "./DialogForm"; -import DialogFormProyek from "./DialogFormProyek"; -import { FileExcelOutlined, FilePdfOutlined } from "@ant-design/icons"; -import { - NotificationContainer, - NotificationManager, -} from "react-notifications"; -import { - Pagination, - Table, - Button, - Tooltip, - Popover, - Skeleton, - Spin, -} from "antd"; -import { - PROJECT_APPROVAL_ADD, - PROJECT_APPROVAL_EDIT, - PROJECT_PARTICIPANT_ADD, - PROJECT_PARTICIPANT_EDIT, - PROJECT_MILESTONE_ADD, - PROJECT_MILESTONE_EDIT, - PROJECT_PARTICIPANT_DELETE_BY_PROYEK, - PROJECT_MILESTONE_DELETE_BY_PROYEK, - PROJECT_APPROVAL_DELETE_BY_PROYEK, - USER_LIST, - TYPE_PROYEK, - PROYEK_ADD, - PROYEK_SEARCH, - PROYEK_EDIT, - PROYEK_DELETE, - TOOLS_RESOURCE_SEARCH, - MATERIAL_RESOURCE_SEARCH, - USER_SEARCH, - PROJECT_CHARTER_SEARCH, - HIERARCHY_FTTH_SEARCH, - TOOLS_RESOURCE_LIST, - MATERIAL_RESOURCE_LIST, - PROYEK_GET_ID, - PROJECT_MILESTONE_SEARCH, - PROJECT_PARTICIPANT_SEARCH, - PROJECT_APPROVAL_SEARCH, - CHECKLIST_K3_LIST, - VERSION_GANTT_SEARCH, - PHASE_PROYEK, - DIVISI_LIST, - BASE_OSPRO -} from "../../../const/ApiConst"; -import { - formatNumber, - formatRupiah, - formatThousand, - renderFormatRupiah, -} from "../../../const/CustomFunc"; -import moment from "moment"; -// import DialogFormResource from './DialogFormResource'; -import DialogFormMaterial from "./DataRequestMaterial"; -import DialogTableTools from "./DialogTableTools"; -import DialogDocument from "./DialogDocument"; -import DialogInitDocument from "./DialogInitDocument"; -import DialogGantt from "./DialogGantt"; -import DialogHierarchy from "./DialogHierarchy"; -// import DialogAsignHr from './AsignHrProject'; -import AssignHrProject from "./AsignHrProject"; -import AssignK3Project from "./AssignK3Project"; -import ViewProject from "./ViewProject"; -import { Icon } from "@iconify/react"; -// import { Link } from 'react-router-dom'; -// import SubProyekComp from './SubProyekComp'; -import { Link, useHistory } from "react-router-dom"; - -const url = ""; -const proyek_id = localStorage.getItem("proyek_id"); -const role_id = localStorage.getItem("role_id"); -const format = "DD-MM-YYYY"; - -const CreatedProyek = ({ params, ...props }) => { - const history = useHistory(); - const token = localStorage.getItem("token"); - const HEADER = { - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${token}`, - }, - }; - - const [idTask, setidTask] = useState(0); - const [dataTable, setDatatable] = useState([]); - const [search, setSearch] = useState(""); - const [currentPage, setCurrentPage] = useState(1); - const [totalPage, setTotalPage] = useState(0); - const [openDialog, setOpenDialog] = useState(false); - const [openDialogViewDetail, setOpenDialogViewDetail] = useState(false); - const [openDialogMaterial, setOpenDialogMaterial] = useState(false); - const [openDialogTools, setOpenDialogTools] = useState(false); - const [openDialogGantt, setOpenDialogGantt] = useState(false); - const [openDialogHierarchy, setOpenDialogHierarchy] = useState(false); - const [openDialogAsignHR, setOpenDialogAsignHR] = useState(false); - const [openDialogAssignK3, setOpenDialogAssignK3] = useState(false); - const [dataK3, setDataK3] = useState([]); // transfer list - const [idDelete, setIdDelete] = useState(0); - const [alertDelete, setAlertDelete] = useState(false); - const [rowsPerPage, setRowsPerPage] = useState(10); - const [dataExport, setDataExport] = useState([]); - const [userProyek, setUserProyek] = useState([]); - const [materialProyek, setMaterialProyek] = useState([]); - const [dataCharter, setDataCharter] = useState(null); - const [dataView, setDataView] = useState([]); - const [materialResource, setMaterialResource] = useState([]); - const [toolsResource, setToolsResource] = useState([]); - const [dataTypeProyek, setDataTypeProyek] = useState([]); - const [dataPhaseProject, setDataPhaseProject] = useState([]); - const [dataDivisions, setDataDivisions] = useState([]); - const [dataPm, setDataPM] = useState([]); - const [openDialogDoc, setOpenDialogDoc] = useState(false); - const [proyekName, setProyekName] = useState(""); - const [openDialogProyek, setOpenDialogProyek] = useState(false); - // project charter - const [projectCharter, setProjectCharter] = useState(null); - const [projectParticipant, setProjectParticipant] = useState(null); - const [projectMilestone, setProjectMilestone] = useState(null); - const [projectApproval, setProjectApproval] = useState(null); - - const [loadVersionGantt, setLoadVersionGantt] = useState(false); - const [loadHierarchy, setLoadHierarchy] = useState(false); - const [dataVersionGantt, setDataVersionGantt] = useState([]); - const [dataHierarchy, setDataHierarchy] = useState([]); - const [dataDetail, setDataDetail] = useState(null); - const [loading, setLoading] = useState(true); - - const pageName = params.name; - - useEffect(() => { - if (openDialogMaterial) { - getDataMaterialResource(); - } - }, [openDialogMaterial]); - - useEffect(() => { - if (openDialogTools) { - getDataToolsResource(); - } - }, [openDialogTools]); - - useEffect(() => { - if (openDialogAssignK3) { - getDataK3(); - } - }, [openDialogAssignK3]); - - useEffect(() => { - if (openDialogProyek) { - handleGetTipeProject(); - handleGetPhaseProject(); - handleGetDivisions(); - handleGetDataPm(); - } - }, [openDialogProyek]) - - useEffect(() => { - getDataProyek(); - }, [search, rowsPerPage, currentPage]); - - useEffect(() => { - if (dataExport.length > 0) { - exportExcel(); - } - }, [dataExport]); - - useEffect(() => { - if (!openDialog) { - setidTask(0); - } - }, [openDialogDoc]); - - const handleSearch = (e) => { - const value = e.target.value; - setSearch(value); - setCurrentPage(1); - }; - - const handleGetTipeProject = async () => { - const result = await axios - .get(TYPE_PROYEK, HEADER) - .then((res) => res) - .catch((err) => err.response); - if (result && result.data && result.data.code === 200) { - setDataTypeProyek(result.data.data); - } else { - } - }; - - const handleGetPhaseProject = async () => { - const result = await axios - .get(PHASE_PROYEK, HEADER) - .then((res) => res) - .catch((err) => err.response); - if (result && result.data && result.data.code === 200) { - setDataPhaseProject(result.data.data); - } - }; - - const handleGetDivisions = async () => { - const result = await axios - .get(DIVISI_LIST, HEADER) - .then((res) => res) - .catch((err) => err.response); - if (result && result.data && result.data.code === 200) { - setDataDivisions(result.data.data); - } - }; - - const handleGetDataPm = async () => { - const result = await axios - .get(USER_LIST, HEADER) - .then((res) => res) - .catch((err) => err.response); - if (result && result.data && result.data.code === 200) { - setDataPM(result.data.data); - } else { - } - }; - - const handleDashboard = async (text) => { - const URL = `${BASE_OSPRO}/api/project/detail/${text.id}`; - const result = await axios.get(URL, HEADER).then(res => res).catch(err => err.response) - if (!result) { - NotificationManager.error(`Could not connect to internet.`, "Failed"); - return; - } - - if (result.status !== 200) { - NotificationManager.error(`Get project detail failed, ${result.data.message}`, "Failed"); - return; - } - else if (result.status == 200 && result.data.data) { - history.push(`dashboard-customer/${text.id}/${result.data.gantt.last_gantt_id}/1`); - } - } - - const getDataProyek = async () => { - let start = 0; - - if (currentPage !== 1 && currentPage > 1) { - start = currentPage * rowsPerPage - rowsPerPage; - } - - const payload = { - columns: [ - { - name: "nama", - logic_operator: "ilike", - value: search, - operator: "AND", - }, - ], - select: ["id", "nama", "rencana_biaya", "type_proyek_id", "currency_symbol", "mulai_proyek", "akhir_proyek"], - joins: [ - { - name: "m_users", - column_join: "pm_id", - column_results: ["name", "username"], - }, - { - name: "m_type_proyek", - 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: ["id"], ascending: false }, - paging: { start: start, length: rowsPerPage }, - }; - - if (parseInt(role_id) !== 1) { - payload["columns"] = [ - { name: "id", logic_operator: "=", value: proyek_id, operator: "AND" }, - ]; - } - - - const result = await axios - .post(PROYEK_SEARCH, payload, HEADER) - .then((res) => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code == 200) { - let dataRes = result.data.data || []; - - setDatatable(dataRes); - setTotalPage(result.data.totalRecord); - setLoading(false); - } else { - setLoading(false); - NotificationManager.error("Gagal Mengambil Data!!", "Failed"); - } - }; - - const getDataMaterialResource = async () => { - const result = await axios - .get(MATERIAL_RESOURCE_LIST, HEADER) - .then((res) => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code == 200) { - let dataRes = result.data.data || []; - setMaterialResource(dataRes); - } else { - NotificationManager.error("Gagal Mengambil Data!!", "Failed"); - } - }; - - const getdataGantt = async (idTask) => { - setLoadVersionGantt(true); - const payload = { - select: ["id", "name_version"], - columns: [ - { - name: "proyek_id", - logic_operator: "=", - value: idTask, - operator: "AND", - }, - ], - }; - const result = await axios - .post(VERSION_GANTT_SEARCH, payload, HEADER) - .then((res) => res) - .catch((error) => error.response); - - if (result && result.status == 200) { - setDataVersionGantt(result.data.data); - setLoadVersionGantt(false); - } else { - NotificationManager.error( - `Data gantt project gagal terload silahkan coba lagi!`, - "Failed!!" - ); - } - }; - - const getDataToolsResource = async () => { - const result = await axios - .get(TOOLS_RESOURCE_LIST, HEADER) - .then((res) => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code == 200) { - let dataRes = result.data.data || []; - setToolsResource(dataRes); - } else { - NotificationManager.error("Gagal Mengambil Data!!", "Failed"); - } - }; - - const getDataK3 = async () => { - const result = await axios - .get(CHECKLIST_K3_LIST, HEADER) - .then((res) => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code == 200) { - let dataRes = result.data.data || []; - const finalData = []; - if (dataRes.length > 0) { - dataRes.map((val, index) => { - let data = { - key: val.id, - title: val.name, - }; - finalData.push(data); - }); - } - setDataK3(finalData); - } else { - NotificationManager.error("Gagal Mengambil Data!!", "Failed"); - } - }; - - const handleOpenDialog = (id) => { - setOpenDialog(true); - setidTask(id); - }; - - const handleOpenDialogProyek = (id) => { - setOpenDialogProyek(true); - setidTask(id); - }; - - const handleOpenDialogGantt = (data) => { - setidTask(data.id); - setProyekName(data.nama); - setOpenDialogGantt(true); - }; - - const handleOpenDialogHierarchy = (data) => { - setidTask(data.id); - setProyekName(data.nama); - setOpenDialogHierarchy(true); - }; - - const toggleDialogGantt = () => { - setOpenDialogGantt(!openDialogGantt); - }; - - const closeDialogGantt = () => { - setOpenDialogGantt(false); - }; - - const toggleDialogHierarchy = () => { - setOpenDialogHierarchy(!openDialogHierarchy); - }; - - const closeDialogHierarchy = () => { - setOpenDialogHierarchy(false); - }; - - const handleOpenDialogMaterial = (data) => { - setidTask(data.id); - setProyekName(data.nama); - setOpenDialogMaterial(true); - }; - - const handleOpenAsignHr = (data) => { - setidTask(data.id); - setProyekName(data.nama); - setOpenDialogAsignHR(true); - }; - - const handleOpenAssignK3 = (data) => { - setidTask(data.id); - setProyekName(data.nama); - setOpenDialogAssignK3(true); - }; - - const handleOpenDialogTools = (data) => { - setOpenDialogTools(true); - setidTask(data.id); - setProyekName(data.nama); - setUserProyek(data.user_proyeks); - }; - - const handleOpenDialogViewDetail = async (data) => { - setidTask(data.id); - // setDataView(data) - await getDataProject(data.id); - await getProjectMilestone(data.id); - await getProjectParticipant(data.id); - await getProjectApproval(data.id); - // await getDataProjectCharter(data.id); - setOpenDialogViewDetail(true); - }; - - const getProjectDetail = async (id) => { - const URL = `${BASE_OSPRO}/api/project/detail/${id}`; - const result = await axios.get(URL, HEADER).then(res => res).catch(err => err.response) - if (!result) { - NotificationManager.error(`Could not connect to internet.`, "Failed"); - return; - } - - if (result.status !== 200) { - NotificationManager.error(`Get project detail failed, ${result.data.message}`, "Failed"); - return; - } - else if (result.status == 200 && result.data.data) { - history.push(`/dashboard-project/${id}/${result.data.gantt.last_gantt_id}/1`); - } - } - - const handleSCurve = async (data) => { - getProjectDetail(data.id) - }; - - const getDataProject = async (proyek_id) => { - const url = PROYEK_GET_ID(proyek_id); - const result = await axios - .get(url, HEADER) - .then((res) => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code == 200) { - let dataRes = result.data.data; - setProjectCharter(dataRes); - } else { - NotificationManager.error("Gagal Mengambil Data!!", "Failed"); - } - }; - - const getProjectMilestone = async (id) => { - const payload = { - columns: [{ name: "proyek_id", logic_operator: "=", value: id }], - joins: [], - orders: { columns: ["id"], ascending: true }, - paging: { start: 0, length: -1 }, - }; - // const url = PROJECT_MI(proyek_id) - const result = await axios - .post(PROJECT_MILESTONE_SEARCH, payload, HEADER) - .then((res) => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code == 200) { - let dataRes = result.data.data; - setProjectMilestone(dataRes); - } else { - NotificationManager.error("Gagal Mengambil Data!!", "Failed"); - } - }; - - const getProjectParticipant = async (id) => { - const payload = { - columns: [{ name: "proyek_id", logic_operator: "=", value: id }], - joins: [], - orders: { columns: ["id"], ascending: true }, - paging: { start: 0, length: -1 }, - }; - // const url = PROJECT_MI(proyek_id) - const result = await axios - .post(PROJECT_PARTICIPANT_SEARCH, payload, HEADER) - .then((res) => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code == 200) { - let dataRes = result.data.data; - setProjectParticipant(dataRes); - - } else { - NotificationManager.error("Gagal Mengambil Data!!", "Failed"); - } - }; - - const getProjectApproval = async (id) => { - const payload = { - columns: [{ name: "proyek_id", logic_operator: "=", value: id }], - joins: [], - orders: { columns: ["id"], ascending: true }, - paging: { start: 0, length: -1 }, - }; - // const url = PROJECT_MI(proyek_id) - const result = await axios - .post(PROJECT_APPROVAL_SEARCH, payload, HEADER) - .then((res) => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code == 200) { - let dataRes = result.data.data; - setProjectApproval(dataRes); - } else { - NotificationManager.error("Gagal Mengambil Data!!", "Failed"); - } - }; - - const handleCloseDialog = (type, payload) => { - if (type === "add") saveProyek(payload); - - if (type === "edit") editProyek(payload); - setidTask(0); - setOpenDialog(false); - }; - - const handleCloseDialogProyek = (type, payload) => { - if (type === "add") saveProyek(payload); - - if (type === "edit") editProyek(payload); - setidTask(0); - setOpenDialogProyek(false); - }; - - const handleCloseDialogView = () => { - setProjectApproval(null); - setProjectParticipant(null); - setProjectMilestone(null); - setProjectCharter(null); - setOpenDialogViewDetail(false); - }; - - const toggleAddDialog = () => setOpenDialog(!openDialog); - const toggleAddDialogProyek = () => setOpenDialogProyek(!openDialogProyek); - const toggleAddDialogView = () => { - if (openDialogViewDetail) { - setProjectApproval(null); - setProjectParticipant(null); - setProjectMilestone(null); - setProjectCharter(null); - } - setOpenDialogViewDetail(!openDialogViewDetail); - }; - - const onConfirmDelete = async () => { - let urlDel = PROYEK_DELETE(idDelete); - const result = await axios - .delete(urlDel, HEADER) - .then((res) => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - getDataProyek(); - setIdDelete(0); - setAlertDelete(false); - NotificationManager.success(`Data proyek berhasil dihapus`, "Success!!"); - } else { - setIdDelete(0); - setAlertDelete(false); - NotificationManager.error(`Data proyek gagal dihapus`, "Failed!!"); - } - }; - - const saveProyek = async (data) => { - const formData = data; - - const result = await axios - .post(PROYEK_ADD, formData, HEADER) - .then((res) => res) - .catch((error) => error.response); - if (result && result.data && result.data.code === 200) { - const { participants, milestones, approval } = data.projectCharter; - const resultParticipant = await saveParticipant( - result.data.data_result.id, - participants - ); - const resultMilestone = await saveMilestone( - result.data.data_result.id, - milestones - ); - const resultApproval = await saveApproval( - result.data.data_result.id, - approval - ); - if ( - resultParticipant === "berhasil" && - resultMilestone === "berhasil" && - resultApproval === "berhasil" - ) { - // getDataProyek(); - NotificationManager.success( - `Data proyek berhasil ditambah`, - "Success!!" - ); - } else { - NotificationManager.success(`${result.data.message}`, "Success!!"); - } - - getDataProyek(); - } else { - NotificationManager.error(`${result.data.message}`, "Failed!!"); - } - }; - - const saveParticipant = async (id, data) => { - const request = data.map((res) => { - const payload = { - proyek_id: parseInt(id), - tittle: res.title, - name: res.name, - }; - return axios.post(PROJECT_PARTICIPANT_ADD, payload, HEADER); - }); - const arr = await Promise.all(request) - .then((values) => values) - .catch((err) => err.response); - const result = arr.map((res) => res.data.code == 200); - if (result.length > 0) { - return "gagal"; - } - - return "berhasil"; - }; - - const saveMilestone = async (id, data) => { - const request = data.map((res) => { - const payload = { - proyek_id: parseInt(id), - status: res.status, - due_date: res.due, - deadline: res.deadline, - }; - return axios.post(PROJECT_MILESTONE_ADD, payload, HEADER); - }); - const arr = await Promise.all(request) - .then((values) => values) - .catch((err) => err.response); - const result = arr.map((res) => res.data.code !== 200); - if (result.length > 0) { - return "gagal"; - } - - return "berhasil"; - }; - - const saveApproval = async (id, data) => { - const request = data.map((res) => { - const payload = { - proyek_id: parseInt(id), - tittle: res.title, - name: res.name, - date_approval: res.date, - }; - return axios.post(PROJECT_APPROVAL_ADD, payload, HEADER); - }); - const arr = await Promise.all(request) - .then((values) => values) - .catch((err) => err.response); - const result = arr.map((res) => res.data.code !== 200); - if (result.length > 0) { - return "gagal"; - } - - return "berhasil"; - }; - - const editProyek = async (data) => { - const { participants, milestones, approval } = data.projectCharter; - let urlEdit = PROYEK_EDIT(data.id); - const formData = data; - - const result = await axios - .put(urlEdit, formData, HEADER) - .then((res) => res) - .catch((error) => error.response); - const resultParticipant = await editParticipant(data.id, participants); - const resultMilestone = await editMilestone(data.id, milestones); - const resultApproval = await editApproval(data.id, approval); - if (result && result.status === 200) { - getDataProyek(); - NotificationManager.success(`Data proyek berhasil Ubah`, "Success!!"); - } else { - NotificationManager.error(`${result.data.message}`, "Failed!!"); - } - }; - - const editParticipant = async (id, data) => { - await axios.delete(PROJECT_PARTICIPANT_DELETE_BY_PROYEK(id), HEADER); - // if (restDelete){ - const request = data.map((res) => { - const payload = { - proyek_id: parseInt(id), - tittle: res.tittle ? res.tittle : res.title, - name: res.name, - }; - return axios.post(PROJECT_PARTICIPANT_ADD, payload, HEADER); - }); - const arr = await Promise.all(request) - .then((values) => values) - .catch((err) => err.response); - const result = arr.map((res) => res.data.code !== 200); - if (result.length > 0) { - return "gagal"; - } - - return "berhasil"; - }; - - const editMilestone = async (id, data) => { - await axios.delete(PROJECT_MILESTONE_DELETE_BY_PROYEK(id), HEADER); - const request = data.map((res) => { - const payload = { - proyek_id: parseInt(id), - status: res.status, - due_date: res.due_date ? res.due_date : res.due, - deadline: res.deadline, - }; - return axios.post(PROJECT_MILESTONE_ADD, payload, HEADER); - }); - const arr = await Promise.all(request) - .then((values) => values) - .catch((err) => err.response); - const result = arr.map((res) => res.data.code !== 200); - if (result.length > 0) { - return "gagal"; - } - return "berhasil"; - }; - - const editApproval = async (id, data) => { - await axios.delete(PROJECT_APPROVAL_DELETE_BY_PROYEK(id), HEADER); - const request = data.map((res) => { - const payload = { - proyek_id: parseInt(id), - tittle: res.tittle ? res.tittle : res.title, - name: res.name, - date_approval: res.date ? res.date : res.date_approval, - }; - return axios.post(PROJECT_APPROVAL_ADD, payload, HEADER); - }); - const arr = await Promise.all(request) - .then((values) => values) - .catch((err) => err.response); - // if(arr) - - // const result = arr.map(res => res.data.code !== 200) - // if (result.length > 0) { - // return "gagal" - // } - // return "berhasil" - }; - - const handleDelete = async (id) => { - await setAlertDelete(true); - await setIdDelete(id); - }; - - const onShowSizeChange = (current, pageSize) => { - setRowsPerPage(pageSize); - }; - - const onPagination = (current, pageSize) => { - setCurrentPage(current); - }; - - const handleExportExcel = async () => { - const payload = { - paging: { start: 0, length: -1 }, - joins: [], - orders: { columns: ["id"], ascending: false }, - }; - - if (parseInt(role_id) !== 1) { - payload["columns"] = [ - { name: "id", logic_operator: "=", value: proyek_id, operator: "AND" }, - ]; - } - - const result = await axios - .post(PROYEK_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((n, index) => { - let dataRow = { - Sortname: n.kode_sortname ? n.kode_sortname : "", - "Nama Project": n.nama ? n.nama : "", - "Tanggal Mulai": n.mulai_proyek - ? moment(n.mulai_proyek).format(format) - : "-", - "Tanggal Selesai": n.akhir_proyek - ? moment(n.akhir_proyek).format(format) - : "-", - "Area Kerja": n.area_kerja ? n.area_kerja : "", - Perusahaan: n.company ? n.company : "", - Keterangan: n.keterangan ? n.keterangan : "", - "Dianggap sukses ketika": n.considered_success_when - ? n.considered_success_when - : "", - "Tujuan Proyek": n.project_objectives ? n.project_objectives : "", - "Resiko potensial": n.potential_risk ? n.potential_risk : "", - "Rencana Biaya": n.rencana_biaya - ? formatThousand(n.rencana_biaya) - : "-", - "Testing Environment": n.testing_environment - ? n.testing_environment - : "-", - }; - excelData.push(dataRow); - }); - await setDataExport(excelData); - } else { - NotificationManager.error("Gagal Export Data!!", "Failed"); - } - }; - - const handleExportPdf = async () => { - const doc = new jsPDF(); - - const headers = [ - ["Project Name", "Budget", "Project Type", "PM", "Time Project"], - ]; - const payload = { - columns: [ - { - name: "nama", - logic_operator: "ilike", - value: search, - operator: "AND", - }, - ], - joins: [ - { - name: "m_users", - column_join: "pm_id", - column_results: ["name", "username"], - }, - { - name: "m_type_proyek", - 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: ["id"], ascending: false }, - }; - - const result = await axios - .post(PROYEK_SEARCH, payload, HEADER) - .then((res) => res) - .catch((error) => error.response); - if (result && result.data && result.data.code == 200) { - let resData = result.data.data; - const data = resData.map((elt) => [ - elt.nama, - `Rp. ${formatThousand(elt.rencana_biaya)}`, - elt.join_second_name, - elt.join_first_name, - `${moment(elt.mulai_proyek).format(format)} - ${moment( - elt.akhir_proyek - ).format(format)}`, - ]); - // Or use javascript directly: - doc.text(4, 15, "Project Charter"); - autoTable(doc, { - startY: 20, - margin: { horizontal: 4 }, - styles: { overflow: "linebreak", columnWidth: "auto", fontSize: 8 }, - columnStyles: { text: { columnWidth: "auto" } }, - head: headers, - body: data, - }); - } - doc.save("Project.pdf"); - // const unit = "pt"; - // const size = "A4"; // Use A1, A2, A3 or A4 - // const orientation = "portrait"; // portrait or landscape - - // const marginLeft = 40; - // const doc = new jsPDF(orientation, unit, size); - - // doc.setFontSize(15); - // const dataPeople = [ - // { name: "Keanu Reeves", profession: "Actor" }, - // { name: "Lionel Messi", profession: "Football Player" }, - // { name: "Cristiano Ronaldo", profession: "Football Player" }, - // { name: "Jack Nicklaus", profession: "Golf Player" }, - // ]; - // const title = "My Awesome Report"; - // const headers = [["NAME", "PROFESSION"]]; - - // const data = dataPeople.map((elt) => [elt.name, elt.profession]); - - // let content = { - // startY: 50, - // head: headers, - // body: data, - // }; - - // doc.text(title, marginLeft, 40); - // doc.autoTable(content); - // doc.save("report.pdf"); - }; - - 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 cancelDelete = () => { - setAlertDelete(false); - setIdDelete(0); - }; - - const handleOpenDokumen = async (data) => { - await setidTask(data.id); - setProyekName(data.nama); - setOpenDialogDoc(true); - }; - - const popupMenu = (text, record) => { - return ( -
-
handleOpenDialogViewDetail(text)} - > - - - - Project Charter -
-
handleOpenDokumen(text)}> - - - - Project Documents -
-
handleOpenAsignHr(text)}> - - - - Assign Human Resource -
-
handleOpenAssignK3(text)}> - - - - Assign Checklist K3 -
- {/*
handleOpenDialogMaterial(text)} - > - - - - Request Material Resource -
*/} - {/*
handleOpenDialogTools(text)}> - - - - Request Tools -
*/} - {/* */} -
handleOpenDialogGantt(text)}> - - - - Gantt -
-
handleSCurve(text)}> - - - - S Curve -
- {/* */} -
handleOpenDialogProyek(text.id)} - > - - - - Edit Project -
-
handleDelete(text.id)}> - - - - Delete Project -
-
- ); - }; - - const popupMenuGantt = (text, record) => { - return ( -
- {text.type_proyek_id !== 9 && loadVersionGantt && ( -
- -
- )} - - {(!loadVersionGantt && text.type_proyek_id !== 9) && ( - <> - {dataVersionGantt.slice(0, 8).map((res) => ( - -
- - - - {res.name_version} -
- - ))} - {dataVersionGantt.length > 0 && ( -
- )} - - )} - {text.type_proyek_id == 9 ? -
handleOpenDialogHierarchy(text)} - > - - - - More Hierarchy Menu ... -
: -
handleOpenDialogGantt(text)} - > - - - - More Gantt Menu ... -
} -
- ); - }; - - const RenderTable = useMemo(() => { - const columns = [ - { - title: "Action", - dataIndex: "", - key: "x", - render: (text, record) => ( - role_id == "44" - ? - <> - - - - - : - <> - - - - - { - text.type_proyek_id == 9 ? - : - - } - - - ), - }, - { title: "Project Name", dataIndex: "nama", key: "nama" }, - { - title: "Budget", - dataIndex: "rencana_biaya", - key: "rencana_biaya", - // render: (text, record) => { return renderFormatRupiah(text, "Rp") } - render: (text, record) => { - return record.currency_symbol - ? `${record.currency_symbol} ${formatThousand(text)}` - : `${formatThousand(text)}`; - }, - }, - { - title: "Project Type", - dataIndex: "color_progress", - key: "color_progress", - render: (text, record) => ( - <>{record.join_second_name ? record.join_second_name : "-"} - ), - }, - { - title: "PM", - dataIndex: "pic", - key: "pic", - render: (text, record) => ( - <>{record.join_first_name ? record.join_first_name : "-"} - ), - }, - { - title: "Time Project", - dataIndex: "akhir_proyek", - key: "akhir_proyek", - render: (text, record) => ( - <> - {moment(record.mulai_proyek).format(format)} -{" "} - {moment(record.akhir_proyek).format(format)} - - ), - }, - ]; - - return ( - - ); - }, [dataTable, dataVersionGantt, loadVersionGantt]); - - const handleCloseDialogDoc = () => { - setOpenDialogDoc(false); - setidTask(0); - }; - - const handleCloseDialogAsignHr = () => { - setidTask(0); - setOpenDialogAsignHR(false); - }; - - const handleCloseDialogAssignK3 = (status) => { - if (status == "success") { - NotificationManager.success( - `Assign K3 to Project berhasil disimpan!`, - "Success!!" - ); - } else if (status == "failed") { - NotificationManager.error( - `Assign K3 to Project gagal disimpan!`, - "Failed!!" - ); - } - setidTask(0); - setOpenDialogAssignK3(false); - }; - - const RenderDialogForm = useMemo( - () => ( - toggleAddDialog} - idTask={idTask} - dataTypeProyek={dataTypeProyek} - dataPhaseProject={dataPhaseProject} - dataPM={dataPm} - /> - ), - [openDialog] - ); - - const RenderDialogFormProyek = useMemo( - () => ( - toggleAddDialogProyek} - idTask={idTask} - dataTypeProyek={dataTypeProyek} - dataPhaseProject={dataPhaseProject} - dataDivisions={dataDivisions} - dataPM={dataPm} - /> - ), - [openDialogProyek, dataPm, dataDivisions, dataPhaseProject, dataTypeProyek, idTask] - ); - - const RenderDialogFormMaterial = useMemo( - () => ( - setOpenDialogMaterial(false)} - toggleDialog={() => setOpenDialogMaterial(!openDialogMaterial)} - idTask={idTask} - userProyek={userProyek} - materialProyek={materialProyek} - materialResource={materialResource} - proyekName={proyekName} - /> - ), - [openDialogMaterial, proyekName, materialResource, materialProyek, userProyek, idTask] - ); - - const RenderDialogTableTools = useMemo( - () => ( - setOpenDialogTools(false)} - toggleDialog={() => setOpenDialogTools(!openDialogTools)} - idTask={idTask} - toolsResource={toolsResource} - userProyek={userProyek} - proyekName={proyekName} - /> - ), - [openDialogTools, proyekName, userProyek, toolsResource, idTask] - ); - - // DialogAsignHr - const RenderDialogAsignHr = useMemo( - () => ( - setOpenDialogAsignHR(false)} - toggleDialog={() => setOpenDialogAsignHR(!openDialogAsignHR)} - handleClose={handleCloseDialogAsignHr} - idTask={idTask} - proyekName={proyekName} - /> - ), - [openDialogAsignHR] - ); - - // DialogAssignK3 - const RenderDialogAssignK3 = useMemo( - () => ( - { - if (openDialogAssignK3) { - setidTask(0); - } - setOpenDialogAssignK3(!openDialogAssignK3); - }} - idTask={idTask} - proyekName={proyekName} - dataK3={dataK3} - /> - ), - [openDialogAssignK3, dataK3] - ); - - const RenderDialogDoc = useMemo( - () => ( - setOpenDialogDoc(false)} - toggleDialog={() => setOpenDialogDoc(!openDialogDoc)} - handleClose={handleCloseDialogDoc} - idTask={idTask} - proyekName={proyekName} - /> - ), - [openDialogDoc] - ); - - const ViewProyek = useMemo( - () => ( - - ), - [openDialogViewDetail] - ); - - const renderDialogGantt = useMemo( - () => ( - - ), - [openDialogGantt] - ); - - const renderDialogHierarchy = useMemo( - () => ( - - ), - [openDialogHierarchy] - ); - - return ( -
- - cancelDelete()} - focusCancelBtn - > - Delete this data - - {ViewProyek} - {RenderDialogForm} - {RenderDialogFormProyek} - {RenderDialogFormMaterial} - {RenderDialogTableTools} - {RenderDialogDoc} - {renderDialogGantt} - {renderDialogHierarchy} - {RenderDialogAsignHr} - {RenderDialogAssignK3} - - -

Project Information

- -
- - - - { - role_id == "44" // role kustomer - ? - null - : - - - - } - - Close} - title="Export" - trigger="click" - placement="leftBottom" - content={ - <> - -
- - - } - // visible={visible} - // onVisibleChange={handleVisibleChange} - > - -
-
- - - - - - {RenderTable} - - - - - - - ); -}; - -export default CreatedProyek; +import React, { useState, useEffect, useMemo } from "react"; +import { Card, CardBody, CardHeader, Col, Row, Input } from "reactstrap"; +import axios from "../../../const/interceptorApi"; +import jsPDF from "jspdf"; +import autoTable from "jspdf-autotable"; +import * as XLSX from "xlsx"; +import SweetAlert from "react-bootstrap-sweetalert"; +import DialogForm from "./DialogForm"; +import DialogFormProyek from "./DialogFormProyek"; +import { FileExcelOutlined, FilePdfOutlined } from "@ant-design/icons"; +import { + NotificationContainer, + NotificationManager, +} from "react-notifications"; +import { + Pagination, + Table, + Button, + Tooltip, + Popover, + Skeleton, + Spin, +} from "antd"; +import { + PROJECT_APPROVAL_ADD, + PROJECT_APPROVAL_EDIT, + PROJECT_PARTICIPANT_ADD, + PROJECT_PARTICIPANT_EDIT, + PROJECT_MILESTONE_ADD, + PROJECT_MILESTONE_EDIT, + PROJECT_PARTICIPANT_DELETE_BY_PROYEK, + PROJECT_MILESTONE_DELETE_BY_PROYEK, + PROJECT_APPROVAL_DELETE_BY_PROYEK, + USER_LIST, + TYPE_PROYEK, + PROYEK_ADD, + PROYEK_SEARCH, + PROYEK_EDIT, + PROYEK_DELETE, + TOOLS_RESOURCE_SEARCH, + MATERIAL_RESOURCE_SEARCH, + USER_SEARCH, + PROJECT_CHARTER_SEARCH, + HIERARCHY_FTTH_SEARCH, + TOOLS_RESOURCE_LIST, + MATERIAL_RESOURCE_LIST, + PROYEK_GET_ID, + PROJECT_MILESTONE_SEARCH, + PROJECT_PARTICIPANT_SEARCH, + PROJECT_APPROVAL_SEARCH, + CHECKLIST_K3_LIST, + VERSION_GANTT_SEARCH, + PHASE_PROYEK, + DIVISI_LIST, + BASE_OSPRO +} from "../../../const/ApiConst"; +import { + formatNumber, + formatRupiah, + formatThousand, + renderFormatRupiah, +} from "../../../const/CustomFunc"; +import moment from "moment"; +// import DialogFormResource from './DialogFormResource'; +import DialogFormMaterial from "./DataRequestMaterial"; +import DialogTableTools from "./DialogTableTools"; +import DialogDocument from "./DialogDocument"; +import DialogInitDocument from "./DialogInitDocument"; +import DialogGantt from "./DialogGantt"; +import DialogHierarchy from "./DialogHierarchy"; +// import DialogAsignHr from './AsignHrProject'; +import AssignHrProject from "./AsignHrProject"; +import AssignK3Project from "./AssignK3Project"; +import ViewProject from "./ViewProject"; +import { Icon } from "@iconify/react"; +// import { Link } from 'react-router-dom'; +// import SubProyekComp from './SubProyekComp'; +import { Link, useHistory } from "react-router-dom"; + +const url = ""; +const proyek_id = localStorage.getItem("proyek_id"); +const role_id = localStorage.getItem("role_id"); +const format = "DD-MM-YYYY"; + +const CreatedProyek = ({ params, ...props }) => { + const history = useHistory(); + const token = localStorage.getItem("token"); + const HEADER = { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + }; + + const [idTask, setidTask] = useState(0); + const [dataTable, setDatatable] = useState([]); + const [search, setSearch] = useState(""); + const [currentPage, setCurrentPage] = useState(1); + const [totalPage, setTotalPage] = useState(0); + const [openDialog, setOpenDialog] = useState(false); + const [openDialogViewDetail, setOpenDialogViewDetail] = useState(false); + const [openDialogMaterial, setOpenDialogMaterial] = useState(false); + const [openDialogTools, setOpenDialogTools] = useState(false); + const [openDialogGantt, setOpenDialogGantt] = useState(false); + const [openDialogHierarchy, setOpenDialogHierarchy] = useState(false); + const [openDialogAsignHR, setOpenDialogAsignHR] = useState(false); + const [openDialogAssignK3, setOpenDialogAssignK3] = useState(false); + const [dataK3, setDataK3] = useState([]); // transfer list + const [idDelete, setIdDelete] = useState(0); + const [alertDelete, setAlertDelete] = useState(false); + const [rowsPerPage, setRowsPerPage] = useState(10); + const [dataExport, setDataExport] = useState([]); + const [userProyek, setUserProyek] = useState([]); + const [materialProyek, setMaterialProyek] = useState([]); + const [dataCharter, setDataCharter] = useState(null); + const [dataView, setDataView] = useState([]); + const [materialResource, setMaterialResource] = useState([]); + const [toolsResource, setToolsResource] = useState([]); + const [dataTypeProyek, setDataTypeProyek] = useState([]); + const [dataPhaseProject, setDataPhaseProject] = useState([]); + const [dataDivisions, setDataDivisions] = useState([]); + const [dataPm, setDataPM] = useState([]); + const [openDialogDoc, setOpenDialogDoc] = useState(false); + const [proyekName, setProyekName] = useState(""); + const [openDialogProyek, setOpenDialogProyek] = useState(false); + // project charter + const [projectCharter, setProjectCharter] = useState(null); + const [projectParticipant, setProjectParticipant] = useState(null); + const [projectMilestone, setProjectMilestone] = useState(null); + const [projectApproval, setProjectApproval] = useState(null); + + const [loadVersionGantt, setLoadVersionGantt] = useState(false); + const [loadHierarchy, setLoadHierarchy] = useState(false); + const [dataVersionGantt, setDataVersionGantt] = useState([]); + const [dataHierarchy, setDataHierarchy] = useState([]); + const [dataDetail, setDataDetail] = useState(null); + const [loading, setLoading] = useState(true); + + const pageName = params.name; + + useEffect(() => { + if (openDialogMaterial) { + getDataMaterialResource(); + } + }, [openDialogMaterial]); + + useEffect(() => { + if (openDialogTools) { + getDataToolsResource(); + } + }, [openDialogTools]); + + useEffect(() => { + if (openDialogAssignK3) { + getDataK3(); + } + }, [openDialogAssignK3]); + + useEffect(() => { + if (openDialogProyek) { + handleGetTipeProject(); + handleGetPhaseProject(); + handleGetDivisions(); + handleGetDataPm(); + } + }, [openDialogProyek]) + + useEffect(() => { + getDataProyek(); + }, [search, rowsPerPage, currentPage]); + + useEffect(() => { + if (dataExport.length > 0) { + exportExcel(); + } + }, [dataExport]); + + useEffect(() => { + if (!openDialog) { + setidTask(0); + } + }, [openDialogDoc]); + + const handleSearch = (e) => { + const value = e.target.value; + setSearch(value); + setCurrentPage(1); + }; + + const handleGetTipeProject = async () => { + const result = await axios + .get(TYPE_PROYEK, HEADER) + .then((res) => res) + .catch((err) => err.response); + if (result && result.data && result.data.code === 200) { + setDataTypeProyek(result.data.data); + } else { + } + }; + + const handleGetPhaseProject = async () => { + const result = await axios + .get(PHASE_PROYEK, HEADER) + .then((res) => res) + .catch((err) => err.response); + if (result && result.data && result.data.code === 200) { + setDataPhaseProject(result.data.data); + } + }; + + const handleGetDivisions = async () => { + const result = await axios + .get(DIVISI_LIST, HEADER) + .then((res) => res) + .catch((err) => err.response); + if (result && result.data && result.data.code === 200) { + setDataDivisions(result.data.data); + } + }; + + const handleGetDataPm = async () => { + const result = await axios + .get(USER_LIST, HEADER) + .then((res) => res) + .catch((err) => err.response); + if (result && result.data && result.data.code === 200) { + setDataPM(result.data.data); + } else { + } + }; + + const handleDashboard = async (text) => { + const URL = `${BASE_OSPRO}/api/project/detail/${text.id}`; + const result = await axios.get(URL, HEADER).then(res => res).catch(err => err.response) + if (!result) { + NotificationManager.error(`Could not connect to internet.`, "Failed"); + return; + } + + if (result.status !== 200) { + NotificationManager.error(`Get project detail failed, ${result.data.message}`, "Failed"); + return; + } + else if (result.status == 200 && result.data.data) { + history.push(`dashboard-customer/${text.id}/${result.data.gantt.last_gantt_id}/1`); + } + } + + const getDataProyek = async () => { + let start = 0; + + if (currentPage !== 1 && currentPage > 1) { + start = currentPage * rowsPerPage - rowsPerPage; + } + + const payload = { + columns: [ + { + name: "nama", + logic_operator: "ilike", + value: search, + operator: "AND", + }, + ], + select: ["id", "nama", "rencana_biaya", "type_proyek_id", "currency_symbol", "mulai_proyek", "akhir_proyek"], + joins: [ + { + name: "m_users", + column_join: "pm_id", + column_results: ["name", "username"], + }, + { + name: "m_type_proyek", + 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: ["id"], ascending: false }, + paging: { start: start, length: rowsPerPage }, + }; + + if (parseInt(role_id) !== 1) { + payload["columns"] = [ + { name: "id", logic_operator: "=", value: proyek_id, operator: "AND" }, + ]; + } + + + const result = await axios + .post(PROYEK_SEARCH, payload, HEADER) + .then((res) => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code == 200) { + let dataRes = result.data.data || []; + + setDatatable(dataRes); + setTotalPage(result.data.totalRecord); + setLoading(false); + } else { + setLoading(false); + NotificationManager.error("Gagal Mengambil Data!!", "Failed"); + } + }; + + const getDataMaterialResource = async () => { + const result = await axios + .get(MATERIAL_RESOURCE_LIST, HEADER) + .then((res) => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code == 200) { + let dataRes = result.data.data || []; + setMaterialResource(dataRes); + } else { + NotificationManager.error("Gagal Mengambil Data!!", "Failed"); + } + }; + + const getdataGantt = async (idTask) => { + setLoadVersionGantt(true); + const payload = { + select: ["id", "name_version"], + columns: [ + { + name: "proyek_id", + logic_operator: "=", + value: idTask, + operator: "AND", + }, + ], + }; + const result = await axios + .post(VERSION_GANTT_SEARCH, payload, HEADER) + .then((res) => res) + .catch((error) => error.response); + + if (result && result.status == 200) { + setDataVersionGantt(result.data.data); + setLoadVersionGantt(false); + } else { + NotificationManager.error( + `Data gantt project gagal terload silahkan coba lagi!`, + "Failed!!" + ); + } + }; + + const getDataToolsResource = async () => { + const result = await axios + .get(TOOLS_RESOURCE_LIST, HEADER) + .then((res) => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code == 200) { + let dataRes = result.data.data || []; + setToolsResource(dataRes); + } else { + NotificationManager.error("Gagal Mengambil Data!!", "Failed"); + } + }; + + const getDataK3 = async () => { + const result = await axios + .get(CHECKLIST_K3_LIST, HEADER) + .then((res) => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code == 200) { + let dataRes = result.data.data || []; + const finalData = []; + if (dataRes.length > 0) { + dataRes.map((val, index) => { + let data = { + key: val.id, + title: val.name, + }; + finalData.push(data); + }); + } + setDataK3(finalData); + } else { + NotificationManager.error("Gagal Mengambil Data!!", "Failed"); + } + }; + + const handleOpenDialog = (id) => { + setOpenDialog(true); + setidTask(id); + }; + + const handleOpenDialogProyek = (id) => { + setOpenDialogProyek(true); + setidTask(id); + }; + + const handleOpenDialogGantt = (data) => { + setidTask(data.id); + setProyekName(data.nama); + setOpenDialogGantt(true); + }; + + const handleOpenDialogHierarchy = (data) => { + setidTask(data.id); + setProyekName(data.nama); + setOpenDialogHierarchy(true); + }; + + const toggleDialogGantt = () => { + setOpenDialogGantt(!openDialogGantt); + }; + + const closeDialogGantt = () => { + setOpenDialogGantt(false); + }; + + const toggleDialogHierarchy = () => { + setOpenDialogHierarchy(!openDialogHierarchy); + }; + + const closeDialogHierarchy = () => { + setOpenDialogHierarchy(false); + }; + + const handleOpenDialogMaterial = (data) => { + setidTask(data.id); + setProyekName(data.nama); + setOpenDialogMaterial(true); + }; + + const handleOpenAsignHr = (data) => { + setidTask(data.id); + setProyekName(data.nama); + setOpenDialogAsignHR(true); + }; + + const handleOpenAssignK3 = (data) => { + setidTask(data.id); + setProyekName(data.nama); + setOpenDialogAssignK3(true); + }; + + const handleOpenDialogTools = (data) => { + setOpenDialogTools(true); + setidTask(data.id); + setProyekName(data.nama); + setUserProyek(data.user_proyeks); + }; + + const handleOpenDialogViewDetail = async (data) => { + setidTask(data.id); + // setDataView(data) + await getDataProject(data.id); + await getProjectMilestone(data.id); + await getProjectParticipant(data.id); + await getProjectApproval(data.id); + // await getDataProjectCharter(data.id); + setOpenDialogViewDetail(true); + }; + + const getProjectDetail = async (id) => { + const URL = `${BASE_OSPRO}/api/project/detail/${id}`; + const result = await axios.get(URL, HEADER).then(res => res).catch(err => err.response) + if (!result) { + NotificationManager.error(`Could not connect to internet.`, "Failed"); + return; + } + + if (result.status !== 200) { + NotificationManager.error(`Get project detail failed, ${result.data.message}`, "Failed"); + return; + } + else if (result.status == 200 && result.data.data) { + history.push(`/dashboard-project/${id}/${result.data.gantt.last_gantt_id}/1`); + } + } + + const handleSCurve = async (data) => { + getProjectDetail(data.id) + }; + + const getDataProject = async (proyek_id) => { + const url = PROYEK_GET_ID(proyek_id); + const result = await axios + .get(url, HEADER) + .then((res) => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code == 200) { + let dataRes = result.data.data; + setProjectCharter(dataRes); + } else { + NotificationManager.error("Gagal Mengambil Data!!", "Failed"); + } + }; + + const getProjectMilestone = async (id) => { + const payload = { + columns: [{ name: "proyek_id", logic_operator: "=", value: id }], + joins: [], + orders: { columns: ["id"], ascending: true }, + paging: { start: 0, length: -1 }, + }; + // const url = PROJECT_MI(proyek_id) + const result = await axios + .post(PROJECT_MILESTONE_SEARCH, payload, HEADER) + .then((res) => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code == 200) { + let dataRes = result.data.data; + setProjectMilestone(dataRes); + } else { + NotificationManager.error("Gagal Mengambil Data!!", "Failed"); + } + }; + + const getProjectParticipant = async (id) => { + const payload = { + columns: [{ name: "proyek_id", logic_operator: "=", value: id }], + joins: [], + orders: { columns: ["id"], ascending: true }, + paging: { start: 0, length: -1 }, + }; + // const url = PROJECT_MI(proyek_id) + const result = await axios + .post(PROJECT_PARTICIPANT_SEARCH, payload, HEADER) + .then((res) => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code == 200) { + let dataRes = result.data.data; + setProjectParticipant(dataRes); + + } else { + NotificationManager.error("Gagal Mengambil Data!!", "Failed"); + } + }; + + const getProjectApproval = async (id) => { + const payload = { + columns: [{ name: "proyek_id", logic_operator: "=", value: id }], + joins: [], + orders: { columns: ["id"], ascending: true }, + paging: { start: 0, length: -1 }, + }; + // const url = PROJECT_MI(proyek_id) + const result = await axios + .post(PROJECT_APPROVAL_SEARCH, payload, HEADER) + .then((res) => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code == 200) { + let dataRes = result.data.data; + setProjectApproval(dataRes); + } else { + NotificationManager.error("Gagal Mengambil Data!!", "Failed"); + } + }; + + const handleCloseDialog = (type, payload) => { + if (type === "add") saveProyek(payload); + + if (type === "edit") editProyek(payload); + setidTask(0); + setOpenDialog(false); + }; + + const handleCloseDialogProyek = (type, payload) => { + if (type === "add") saveProyek(payload); + + if (type === "edit") editProyek(payload); + setidTask(0); + setOpenDialogProyek(false); + }; + + const handleCloseDialogView = () => { + setProjectApproval(null); + setProjectParticipant(null); + setProjectMilestone(null); + setProjectCharter(null); + setOpenDialogViewDetail(false); + }; + + const toggleAddDialog = () => setOpenDialog(!openDialog); + const toggleAddDialogProyek = () => setOpenDialogProyek(!openDialogProyek); + const toggleAddDialogView = () => { + if (openDialogViewDetail) { + setProjectApproval(null); + setProjectParticipant(null); + setProjectMilestone(null); + setProjectCharter(null); + } + setOpenDialogViewDetail(!openDialogViewDetail); + }; + + const onConfirmDelete = async () => { + let urlDel = PROYEK_DELETE(idDelete); + const result = await axios + .delete(urlDel, HEADER) + .then((res) => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + getDataProyek(); + setIdDelete(0); + setAlertDelete(false); + NotificationManager.success(`Data proyek berhasil dihapus`, "Success!!"); + } else { + setIdDelete(0); + setAlertDelete(false); + NotificationManager.error(`Data proyek gagal dihapus`, "Failed!!"); + } + }; + + const saveProyek = async (data) => { + const formData = data; + + const result = await axios + .post(PROYEK_ADD, formData, HEADER) + .then((res) => res) + .catch((error) => error.response); + if (result && result.data && result.data.code === 200) { + const { participants, milestones, approval } = data.projectCharter; + const resultParticipant = await saveParticipant( + result.data.data_result.id, + participants + ); + const resultMilestone = await saveMilestone( + result.data.data_result.id, + milestones + ); + const resultApproval = await saveApproval( + result.data.data_result.id, + approval + ); + if ( + resultParticipant === "berhasil" && + resultMilestone === "berhasil" && + resultApproval === "berhasil" + ) { + // getDataProyek(); + NotificationManager.success( + `Data proyek berhasil ditambah`, + "Success!!" + ); + } else { + NotificationManager.success(`${result.data.message}`, "Success!!"); + } + + getDataProyek(); + } else { + NotificationManager.error(`${result.data.message}`, "Failed!!"); + } + }; + + const saveParticipant = async (id, data) => { + const request = data.map((res) => { + const payload = { + proyek_id: parseInt(id), + tittle: res.title, + name: res.name, + }; + return axios.post(PROJECT_PARTICIPANT_ADD, payload, HEADER); + }); + const arr = await Promise.all(request) + .then((values) => values) + .catch((err) => err.response); + const result = arr.map((res) => res.data.code == 200); + if (result.length > 0) { + return "gagal"; + } + + return "berhasil"; + }; + + const saveMilestone = async (id, data) => { + const request = data.map((res) => { + const payload = { + proyek_id: parseInt(id), + status: res.status, + due_date: res.due, + deadline: res.deadline, + }; + return axios.post(PROJECT_MILESTONE_ADD, payload, HEADER); + }); + const arr = await Promise.all(request) + .then((values) => values) + .catch((err) => err.response); + const result = arr.map((res) => res.data.code !== 200); + if (result.length > 0) { + return "gagal"; + } + + return "berhasil"; + }; + + const saveApproval = async (id, data) => { + const request = data.map((res) => { + const payload = { + proyek_id: parseInt(id), + tittle: res.title, + name: res.name, + date_approval: res.date, + }; + return axios.post(PROJECT_APPROVAL_ADD, payload, HEADER); + }); + const arr = await Promise.all(request) + .then((values) => values) + .catch((err) => err.response); + const result = arr.map((res) => res.data.code !== 200); + if (result.length > 0) { + return "gagal"; + } + + return "berhasil"; + }; + + const editProyek = async (data) => { + const { participants, milestones, approval } = data.projectCharter; + let urlEdit = PROYEK_EDIT(data.id); + const formData = data; + + const result = await axios + .put(urlEdit, formData, HEADER) + .then((res) => res) + .catch((error) => error.response); + const resultParticipant = await editParticipant(data.id, participants); + const resultMilestone = await editMilestone(data.id, milestones); + const resultApproval = await editApproval(data.id, approval); + if (result && result.status === 200) { + getDataProyek(); + NotificationManager.success(`Data proyek berhasil Ubah`, "Success!!"); + } else { + NotificationManager.error(`${result.data.message}`, "Failed!!"); + } + }; + + const editParticipant = async (id, data) => { + await axios.delete(PROJECT_PARTICIPANT_DELETE_BY_PROYEK(id), HEADER); + // if (restDelete){ + const request = data.map((res) => { + const payload = { + proyek_id: parseInt(id), + tittle: res.tittle ? res.tittle : res.title, + name: res.name, + }; + return axios.post(PROJECT_PARTICIPANT_ADD, payload, HEADER); + }); + const arr = await Promise.all(request) + .then((values) => values) + .catch((err) => err.response); + const result = arr.map((res) => res.data.code !== 200); + if (result.length > 0) { + return "gagal"; + } + + return "berhasil"; + }; + + const editMilestone = async (id, data) => { + await axios.delete(PROJECT_MILESTONE_DELETE_BY_PROYEK(id), HEADER); + const request = data.map((res) => { + const payload = { + proyek_id: parseInt(id), + status: res.status, + due_date: res.due_date ? res.due_date : res.due, + deadline: res.deadline, + }; + return axios.post(PROJECT_MILESTONE_ADD, payload, HEADER); + }); + const arr = await Promise.all(request) + .then((values) => values) + .catch((err) => err.response); + const result = arr.map((res) => res.data.code !== 200); + if (result.length > 0) { + return "gagal"; + } + return "berhasil"; + }; + + const editApproval = async (id, data) => { + await axios.delete(PROJECT_APPROVAL_DELETE_BY_PROYEK(id), HEADER); + const request = data.map((res) => { + const payload = { + proyek_id: parseInt(id), + tittle: res.tittle ? res.tittle : res.title, + name: res.name, + date_approval: res.date ? res.date : res.date_approval, + }; + return axios.post(PROJECT_APPROVAL_ADD, payload, HEADER); + }); + const arr = await Promise.all(request) + .then((values) => values) + .catch((err) => err.response); + // if(arr) + + // const result = arr.map(res => res.data.code !== 200) + // if (result.length > 0) { + // return "gagal" + // } + // return "berhasil" + }; + + const handleDelete = async (id) => { + await setAlertDelete(true); + await setIdDelete(id); + }; + + const onShowSizeChange = (current, pageSize) => { + setRowsPerPage(pageSize); + }; + + const onPagination = (current, pageSize) => { + setCurrentPage(current); + }; + + const handleExportExcel = async () => { + const payload = { + paging: { start: 0, length: -1 }, + joins: [], + orders: { columns: ["id"], ascending: false }, + }; + + if (parseInt(role_id) !== 1) { + payload["columns"] = [ + { name: "id", logic_operator: "=", value: proyek_id, operator: "AND" }, + ]; + } + + const result = await axios + .post(PROYEK_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((n, index) => { + let dataRow = { + Sortname: n.kode_sortname ? n.kode_sortname : "", + "Nama Project": n.nama ? n.nama : "", + "Tanggal Mulai": n.mulai_proyek + ? moment(n.mulai_proyek).format(format) + : "-", + "Tanggal Selesai": n.akhir_proyek + ? moment(n.akhir_proyek).format(format) + : "-", + "Area Kerja": n.area_kerja ? n.area_kerja : "", + Perusahaan: n.company ? n.company : "", + Keterangan: n.keterangan ? n.keterangan : "", + "Dianggap sukses ketika": n.considered_success_when + ? n.considered_success_when + : "", + "Tujuan Proyek": n.project_objectives ? n.project_objectives : "", + "Resiko potensial": n.potential_risk ? n.potential_risk : "", + "Rencana Biaya": n.rencana_biaya + ? formatThousand(n.rencana_biaya) + : "-", + "Testing Environment": n.testing_environment + ? n.testing_environment + : "-", + }; + excelData.push(dataRow); + }); + await setDataExport(excelData); + } else { + NotificationManager.error("Gagal Export Data!!", "Failed"); + } + }; + + const handleExportPdf = async () => { + const doc = new jsPDF(); + + const headers = [ + ["Project Name", "Budget", "Project Type", "PM", "Time Project"], + ]; + const payload = { + columns: [ + { + name: "nama", + logic_operator: "ilike", + value: search, + operator: "AND", + }, + ], + joins: [ + { + name: "m_users", + column_join: "pm_id", + column_results: ["name", "username"], + }, + { + name: "m_type_proyek", + 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: ["id"], ascending: false }, + }; + + const result = await axios + .post(PROYEK_SEARCH, payload, HEADER) + .then((res) => res) + .catch((error) => error.response); + if (result && result.data && result.data.code == 200) { + let resData = result.data.data; + const data = resData.map((elt) => [ + elt.nama, + `Rp. ${formatThousand(elt.rencana_biaya)}`, + elt.join_second_name, + elt.join_first_name, + `${moment(elt.mulai_proyek).format(format)} - ${moment( + elt.akhir_proyek + ).format(format)}`, + ]); + // Or use javascript directly: + doc.text(4, 15, "Project Charter"); + autoTable(doc, { + startY: 20, + margin: { horizontal: 4 }, + styles: { overflow: "linebreak", columnWidth: "auto", fontSize: 8 }, + columnStyles: { text: { columnWidth: "auto" } }, + head: headers, + body: data, + }); + } + doc.save("Project.pdf"); + // const unit = "pt"; + // const size = "A4"; // Use A1, A2, A3 or A4 + // const orientation = "portrait"; // portrait or landscape + + // const marginLeft = 40; + // const doc = new jsPDF(orientation, unit, size); + + // doc.setFontSize(15); + // const dataPeople = [ + // { name: "Keanu Reeves", profession: "Actor" }, + // { name: "Lionel Messi", profession: "Football Player" }, + // { name: "Cristiano Ronaldo", profession: "Football Player" }, + // { name: "Jack Nicklaus", profession: "Golf Player" }, + // ]; + // const title = "My Awesome Report"; + // const headers = [["NAME", "PROFESSION"]]; + + // const data = dataPeople.map((elt) => [elt.name, elt.profession]); + + // let content = { + // startY: 50, + // head: headers, + // body: data, + // }; + + // doc.text(title, marginLeft, 40); + // doc.autoTable(content); + // doc.save("report.pdf"); + }; + + 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 cancelDelete = () => { + setAlertDelete(false); + setIdDelete(0); + }; + + const handleOpenDokumen = async (data) => { + await setidTask(data.id); + setProyekName(data.nama); + setOpenDialogDoc(true); + }; + + const popupMenu = (text, record) => { + return ( +
+
handleOpenDialogViewDetail(text)} + > + + + + Project Charter +
+
handleOpenDokumen(text)}> + + + + Project Documents +
+
handleOpenAsignHr(text)}> + + + + Assign Human Resource +
+
handleOpenAssignK3(text)}> + + + + Assign Checklist K3 +
+ {/*
handleOpenDialogMaterial(text)} + > + + + + Request Material Resource +
*/} + {/*
handleOpenDialogTools(text)}> + + + + Request Tools +
*/} + {/* */} + { + text.type_proyek_id != 9 ? +
handleOpenDialogGantt(text)}> + + + + Gantt +
+ : null + } +
handleSCurve(text)}> + + + + S Curve +
+ {/* */} +
handleOpenDialogProyek(text.id)} + > + + + + Edit Project +
+
handleDelete(text.id)}> + + + + Delete Project +
+
+ ); + }; + + const popupMenuGantt = (text, record) => { + return ( +
+ {text.type_proyek_id !== 9 && loadVersionGantt && ( +
+ +
+ )} + + {(!loadVersionGantt && text.type_proyek_id !== 9) && ( + <> + {dataVersionGantt.slice(0, 8).map((res) => ( + +
+ + + + {res.name_version} +
+ + ))} + {dataVersionGantt.length > 0 && ( +
+ )} + + )} + {text.type_proyek_id == 9 ? +
handleOpenDialogHierarchy(text)} + > + + + + More Hierarchy Menu ... +
: +
handleOpenDialogGantt(text)} + > + + + + More Gantt Menu ... +
} +
+ ); + }; + + const RenderTable = useMemo(() => { + const columns = [ + { + title: "Action", + dataIndex: "", + key: "x", + render: (text, record) => ( + role_id == "44" + ? + <> + + + + + : + <> + + + + + { + text.type_proyek_id == 9 ? + : + + } + + + ), + }, + { title: "Project Name", dataIndex: "nama", key: "nama" }, + { + title: "Budget", + dataIndex: "rencana_biaya", + key: "rencana_biaya", + // render: (text, record) => { return renderFormatRupiah(text, "Rp") } + render: (text, record) => { + return record.currency_symbol + ? `${record.currency_symbol} ${formatThousand(text)}` + : `${formatThousand(text)}`; + }, + }, + { + title: "Project Type", + dataIndex: "color_progress", + key: "color_progress", + render: (text, record) => ( + <>{record.join_second_name ? record.join_second_name : "-"} + ), + }, + { + title: "PM", + dataIndex: "pic", + key: "pic", + render: (text, record) => ( + <>{record.join_first_name ? record.join_first_name : "-"} + ), + }, + { + title: "Time Project", + dataIndex: "akhir_proyek", + key: "akhir_proyek", + render: (text, record) => ( + <> + {moment(record.mulai_proyek).format(format)} -{" "} + {moment(record.akhir_proyek).format(format)} + + ), + }, + ]; + + return ( +
+ ); + }, [dataTable, dataVersionGantt, loadVersionGantt]); + + const handleCloseDialogDoc = () => { + setOpenDialogDoc(false); + setidTask(0); + }; + + const handleCloseDialogAsignHr = () => { + setidTask(0); + setOpenDialogAsignHR(false); + }; + + const handleCloseDialogAssignK3 = (status) => { + if (status == "success") { + NotificationManager.success( + `Assign K3 to Project berhasil disimpan!`, + "Success!!" + ); + } else if (status == "failed") { + NotificationManager.error( + `Assign K3 to Project gagal disimpan!`, + "Failed!!" + ); + } + setidTask(0); + setOpenDialogAssignK3(false); + }; + + const RenderDialogForm = useMemo( + () => ( + toggleAddDialog} + idTask={idTask} + dataTypeProyek={dataTypeProyek} + dataPhaseProject={dataPhaseProject} + dataPM={dataPm} + /> + ), + [openDialog] + ); + + const RenderDialogFormProyek = useMemo( + () => ( + toggleAddDialogProyek} + idTask={idTask} + dataTypeProyek={dataTypeProyek} + dataPhaseProject={dataPhaseProject} + dataDivisions={dataDivisions} + dataPM={dataPm} + /> + ), + [openDialogProyek, dataPm, dataDivisions, dataPhaseProject, dataTypeProyek, idTask] + ); + + const RenderDialogFormMaterial = useMemo( + () => ( + setOpenDialogMaterial(false)} + toggleDialog={() => setOpenDialogMaterial(!openDialogMaterial)} + idTask={idTask} + userProyek={userProyek} + materialProyek={materialProyek} + materialResource={materialResource} + proyekName={proyekName} + /> + ), + [openDialogMaterial, proyekName, materialResource, materialProyek, userProyek, idTask] + ); + + const RenderDialogTableTools = useMemo( + () => ( + setOpenDialogTools(false)} + toggleDialog={() => setOpenDialogTools(!openDialogTools)} + idTask={idTask} + toolsResource={toolsResource} + userProyek={userProyek} + proyekName={proyekName} + /> + ), + [openDialogTools, proyekName, userProyek, toolsResource, idTask] + ); + + // DialogAsignHr + const RenderDialogAsignHr = useMemo( + () => ( + setOpenDialogAsignHR(false)} + toggleDialog={() => setOpenDialogAsignHR(!openDialogAsignHR)} + handleClose={handleCloseDialogAsignHr} + idTask={idTask} + proyekName={proyekName} + /> + ), + [openDialogAsignHR] + ); + + // DialogAssignK3 + const RenderDialogAssignK3 = useMemo( + () => ( + { + if (openDialogAssignK3) { + setidTask(0); + } + setOpenDialogAssignK3(!openDialogAssignK3); + }} + idTask={idTask} + proyekName={proyekName} + dataK3={dataK3} + /> + ), + [openDialogAssignK3, dataK3] + ); + + const RenderDialogDoc = useMemo( + () => ( + setOpenDialogDoc(false)} + toggleDialog={() => setOpenDialogDoc(!openDialogDoc)} + handleClose={handleCloseDialogDoc} + idTask={idTask} + proyekName={proyekName} + /> + ), + [openDialogDoc] + ); + + const ViewProyek = useMemo( + () => ( + + ), + [openDialogViewDetail] + ); + + const renderDialogGantt = useMemo( + () => ( + + ), + [openDialogGantt] + ); + + const renderDialogHierarchy = useMemo( + () => ( + + ), + [openDialogHierarchy] + ); + + return ( +
+ + cancelDelete()} + focusCancelBtn + > + Delete this data + + {ViewProyek} + {RenderDialogForm} + {RenderDialogFormProyek} + {RenderDialogFormMaterial} + {RenderDialogTableTools} + {RenderDialogDoc} + {renderDialogGantt} + {renderDialogHierarchy} + {RenderDialogAsignHr} + {RenderDialogAssignK3} + + +

Project Information

+ +
+ + + + { + role_id == "44" // role kustomer + ? + null + : + + + + } + + Close} + title="Export" + trigger="click" + placement="leftBottom" + content={ + <> + +
+ + + } + // visible={visible} + // onVisibleChange={handleVisibleChange} + > + +
+
+ + + + + + {RenderTable} + + + + + + + ); +}; + +export default CreatedProyek; From 2af5856b0f1e7204ac8e12e1174a73ee4241a908 Mon Sep 17 00:00:00 2001 From: wahyu Date: Wed, 13 Sep 2023 11:29:24 +0700 Subject: [PATCH 2/7] fix endline --- src/views/SimproV2/Satuan/index.js | 686 ++++++++++++++--------------- 1 file changed, 343 insertions(+), 343 deletions(-) diff --git a/src/views/SimproV2/Satuan/index.js b/src/views/SimproV2/Satuan/index.js index 5210c75..372ebad 100644 --- a/src/views/SimproV2/Satuan/index.js +++ b/src/views/SimproV2/Satuan/index.js @@ -1,343 +1,343 @@ -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 { Card, CardBody, CardHeader, Col, Row, Input, Table } from 'reactstrap'; -import { NotificationContainer, NotificationManager } from 'react-notifications'; -import { Pagination, Button, Tooltip } from 'antd'; -import { SATUAN_ADD, SATUAN_EDIT, SATUAN_DELETE, SATUAN_SEARCH } from '../../../const/ApiConst'; -import { useTranslation } from 'react-i18next'; - -const token = window.localStorage.getItem('token'); -const config = { - headers: - { - Authorization: `Bearer ${token}`, - "Content-type": `application/json` - } -}; - -const Satuan = ({ params }) => { - const token = localStorage.getItem("token") - 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 [openDialog, setOpenDialog] = 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(() => { - getDataSatuan() - }, [currentPage, rowsPerPage, search]) - - useEffect(() => { - const cekData = dataExport || [] - if (cekData.length > 0) { - exportExcel() - } - }, [dataExport]) - - const column = [ - { name: t('name') }, - { name: t('description') }, - ] - const getDataSatuan = 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" - }, - { - "name": "description", - "logic_operator": "ilike", - "value": search, - "operator": "AND" - } - ], - "orders": { - "ascending": true, - "columns": [ - 'id' - ] - }, - "paging": { - "length": rowsPerPage, - "start": start - } - } - - const result = await axios - .post(SATUAN_SEARCH, payload, config) - .then(res => res) - .catch((error) => error.response); - if (result && result.data && result.data.code == 200) { - 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 () => { - const payload = { - "paging": { "start": 0, "length": -1 }, - "columns": [ - { "name": "name", "logic_operator": "ilike", "value": search, "operator": "AND" } - ], - "orders": { "columns": ["id"], "ascending": false } - } - const result = await axios - .post(SATUAN_SEARCH, payload, 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((val, index) => { - let dataRow = { - "Nama": val.name, - "Deskripsi": val.description, - } - 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") { - saveSatuan(data); - } else if (type === "edit") { - editMaterialR(data); - } - setDataEdit([]) - setOpenDialog(false) - } - - const saveSatuan = async (data) => { - const formData = data - const result = await axios.post(SATUAN_ADD, formData, HEADER) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - getDataSatuan() - NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!'); - } else { - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - } - - const editMaterialR = async (data) => { - let urlEdit = SATUAN_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) { - getDataSatuan(); - NotificationManager.success(`Data project type berhasil diedit`, 'Success!!'); - } else { - NotificationManager.error(`Data project type gagal di edit`, `Failed!!`); - } - } - - const toggleAddDialog = () => { - setOpenDialog(!openDialog) - } - - const onConfirmDelete = async () => { - let url = SATUAN_DELETE(idDelete); - - const result = await axios.delete(url, config) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - getDataSatuan() - setIdDelete(0) - setAlertDelete(false) - NotificationManager.success(`Data project type berhasil dihapus!`, 'Success!!'); - } else { - setIdDelete(0) - setAlertDelete(false) - NotificationManager.error(`Data project type 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 ( - - - - ) - } - } - - return ( -
- - cancelDelete()} - focusCancelBtn - > - {t('deleteMsg')} - - toggleAddDialog} - typeDialog={typeDialog} - dataEdit={dataEdit} - clickOpenModal={clickOpenModal} - dataParent={allDataMenu} - /> - - -

{pageName}

- -
- - - - - - - - - - - - - -
{t('noData')}
- - - - {column.map((i, index) => { - return ( - - ) - })} - - - - {dataNotAvailable()} - {dataTable.map((n, index) => { - return ( - - - - - - ) - })} - -
{t('action')}{i.name}
- - - handleDelete(n.id)}> - - - - handleEdit(n)}> - - {n.name}{n.description}
- - - - - ) -} - -export default Satuan; +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 { Card, CardBody, CardHeader, Col, Row, Input, Table } from 'reactstrap'; +import { NotificationContainer, NotificationManager } from 'react-notifications'; +import { Pagination, Button, Tooltip } from 'antd'; +import { SATUAN_ADD, SATUAN_EDIT, SATUAN_DELETE, SATUAN_SEARCH } from '../../../const/ApiConst'; +import { useTranslation } from 'react-i18next'; + +const token = window.localStorage.getItem('token'); +const config = { + headers: + { + Authorization: `Bearer ${token}`, + "Content-type": `application/json` + } +}; + +const Satuan = ({ params }) => { + const token = localStorage.getItem("token") + 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 [openDialog, setOpenDialog] = 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(() => { + getDataSatuan() + }, [currentPage, rowsPerPage, search]) + + useEffect(() => { + const cekData = dataExport || [] + if (cekData.length > 0) { + exportExcel() + } + }, [dataExport]) + + const column = [ + { name: t('name') }, + { name: t('description') }, + ] + const getDataSatuan = 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" + }, + { + "name": "description", + "logic_operator": "ilike", + "value": search, + "operator": "AND" + } + ], + "orders": { + "ascending": true, + "columns": [ + 'id' + ] + }, + "paging": { + "length": rowsPerPage, + "start": start + } + } + + const result = await axios + .post(SATUAN_SEARCH, payload, config) + .then(res => res) + .catch((error) => error.response); + if (result && result.data && result.data.code == 200) { + 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 () => { + const payload = { + "paging": { "start": 0, "length": -1 }, + "columns": [ + { "name": "name", "logic_operator": "ilike", "value": search, "operator": "AND" } + ], + "orders": { "columns": ["id"], "ascending": false } + } + const result = await axios + .post(SATUAN_SEARCH, payload, 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((val, index) => { + let dataRow = { + "Nama": val.name, + "Deskripsi": val.description, + } + 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") { + saveSatuan(data); + } else if (type === "edit") { + editMaterialR(data); + } + setDataEdit([]) + setOpenDialog(false) + } + + const saveSatuan = async (data) => { + const formData = data + const result = await axios.post(SATUAN_ADD, formData, HEADER) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + getDataSatuan() + NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!'); + } else { + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + } + + const editMaterialR = async (data) => { + let urlEdit = SATUAN_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) { + getDataSatuan(); + NotificationManager.success(`Data project type berhasil diedit`, 'Success!!'); + } else { + NotificationManager.error(`Data project type gagal di edit`, `Failed!!`); + } + } + + const toggleAddDialog = () => { + setOpenDialog(!openDialog) + } + + const onConfirmDelete = async () => { + let url = SATUAN_DELETE(idDelete); + + const result = await axios.delete(url, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + getDataSatuan() + setIdDelete(0) + setAlertDelete(false) + NotificationManager.success(`Data project type berhasil dihapus!`, 'Success!!'); + } else { + setIdDelete(0) + setAlertDelete(false) + NotificationManager.error(`Data project type 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')} + + ) + } + } + + return ( +
+ + cancelDelete()} + focusCancelBtn + > + {t('deleteMsg')} + + toggleAddDialog} + typeDialog={typeDialog} + dataEdit={dataEdit} + clickOpenModal={clickOpenModal} + dataParent={allDataMenu} + /> + + +

{pageName}

+ + + + + + + + + + + + + +
+ + + + + + {column.map((i, index) => { + return ( + + ) + })} + + + + {dataNotAvailable()} + {dataTable.map((n, index) => { + return ( + + + + + + ) + })} + +
{t('action')}{i.name}
+ + + handleDelete(n.id)}> + + + + handleEdit(n)}> + + {n.name}{n.description}
+ +
+
+
+ ) +} + +export default Satuan; From 7c83fd6c4b2bca100f0c029f1d9b0ac5673f3328 Mon Sep 17 00:00:00 2001 From: wahyu Date: Wed, 13 Sep 2023 11:53:27 +0700 Subject: [PATCH 3/7] fix endline --- src/views/SimproV2/Divisi/index.js | 738 ++++++++++++++--------------- 1 file changed, 369 insertions(+), 369 deletions(-) diff --git a/src/views/SimproV2/Divisi/index.js b/src/views/SimproV2/Divisi/index.js index 703f8f2..418f043 100644 --- a/src/views/SimproV2/Divisi/index.js +++ b/src/views/SimproV2/Divisi/index.js @@ -1,369 +1,369 @@ -import * as XLSX from 'xlsx'; -import DialogForm from './DialogForm'; -import React, { useState, useEffect } from 'react'; -import SweetAlert from 'react-bootstrap-sweetalert'; -import axios from "../../../const/interceptorApi" -import { Card, CardBody, CardHeader, Col, Row, Input, Table } from 'reactstrap'; -import { DIVISI_LIST, DIVISI_ADD, DIVISI_EDIT, DIVISI_DELETE, DIVISI_SEARCH } from '../../../const/ApiConst'; -import { NotificationContainer, NotificationManager } from 'react-notifications'; -import { Pagination, Button, Tooltip } from 'antd'; -import { useTranslation } from 'react-i18next'; - -const url = ""; -const proyek_id = localStorage.getItem('proyek_id'); -const role_id = localStorage.getItem('role_id'); -const format = "DD-MM-YYYY"; -const token = window.localStorage.getItem('token'); -const config = { - headers: - { - Authorization: `Bearer ${token}`, - "Content-type": `application/json` - } -}; - -const column = [ - { name: "Nama" }, - { name: "Deskripsi" }, -] - -const ProjectType = ({ params }) => { - const token = localStorage.getItem("token") - 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 [openDialog, setOpenDialog] = useState(false) - const [rowsPerPage, setRowsPerPage] = useState(10) - const [search, setSearch] = useState('') - const [totalPage, setTotalPage] = useState(0) - const [typeDialog, setTypeDialog] = useState('Save') - const [dataDivisions, setDataDivisions] = useState([]) - const { t } = useTranslation() - - useEffect(() => { - getListDivision() - }, []) - - useEffect(() => { - getDataProjectType() - }, [currentPage, rowsPerPage, search]) - - useEffect(() => { - const cekData = dataExport || [] - if (cekData.length > 0) { - exportExcel() - } - }, [dataExport]) - - const getListDivision = async () => { - const listDivions = await axios - .get(DIVISI_LIST, HEADER) - .then(res => res) - .catch((error) => error.response); - - if (listDivions && listDivions.data && listDivions.data.code == 200) { - let arr = [] - for (const v in listDivions.data.data) { - arr.push(listDivions.data.data[v]) - } - setDataDivisions(arr); - } else { - NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); - } - } - const getDataProjectType = 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 - } - } - const result = await axios - .post(DIVISI_SEARCH, payload, HEADER) - .then(res => res) - .catch((error) => error.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 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(DIVISI_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 Divisi": val.name, - "Deskripsi": val.description, - } - 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 handleSearch = e => { - const value = e.target.value - setSearch(value); - setCurrentPage(1) - }; - - const handleOpenDialog = (type) => { - setOpenDialog(true) - setTypeDialog(type) - } - - const handleEdit = (data) => { - setDataEdit(data) - handleOpenDialog('Edit'); - } - - const handleDelete = async (id) => { - await setAlertDelete(true) - await setIdDelete(id) - } - - const handleCloseDialog = (type, data) => { - if (type === "save") { - saveProjectType(data); - } else if (type === "edit") { - editMaterialR(data); - } - setDataEdit([]) - setOpenDialog(false) - } - - const saveProjectType = async (data) => { - const formData = data - const result = await axios.post(DIVISI_ADD, formData, HEADER) - .then(res => res) - .catch((error) => error.response); - if (result && result.data && result.data.code === 200) { - getDataProjectType() - NotificationManager.success(`Data berhasil ditambah`, 'Success!!'); - } else { - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - } - - const editMaterialR = async (data) => { - let urlEdit = DIVISI_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) { - getDataProjectType(); - NotificationManager.success(`Data berhasil diedit`, 'Success!!'); - } else { - NotificationManager.error(`Data gagal di edit`, `Failed!!`); - } - } - - const toggleAddDialog = () => { - setOpenDialog(!openDialog) - } - - const onConfirmDelete = async () => { - let url = DIVISI_DELETE(idDelete); - const result = await axios.delete(url, config) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - getDataProjectType() - setIdDelete(0) - setAlertDelete(false) - NotificationManager.success(`Data berhasil dihapus!`, 'Success!!'); - } else { - setIdDelete(0) - setAlertDelete(false) - NotificationManager.error(`Data 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')} - - ) - } - } - - return ( -
- - - {t('deleteMsg')} - - toggleAddDialog} - typeDialog={typeDialog} - dataEdit={dataEdit} - clickOpenModal={clickOpenModal} - dataParent={allDataMenu} - dataDivisions={dataDivisions} - /> - - -

{pageName}

- - - - - - - - - - - - - -
- - - - - - {column.map((i, index) => { - return ( - - ) - })} - - - - {dataNotAvailable()} - {dataTable.map((n, index) => { - return ( - - - - - - ) - })} - -
Aksi{i.name}
- - handleDelete(n.id)}> - - - handleEdit(n)}> - - {n.name}{n.description}
-
-
-
- ) -} - -export default ProjectType; +import * as XLSX from 'xlsx'; +import DialogForm from './DialogForm'; +import React, { useState, useEffect } from 'react'; +import SweetAlert from 'react-bootstrap-sweetalert'; +import axios from "../../../const/interceptorApi" +import { Card, CardBody, CardHeader, Col, Row, Input, Table } from 'reactstrap'; +import { DIVISI_LIST, DIVISI_ADD, DIVISI_EDIT, DIVISI_DELETE, DIVISI_SEARCH } from '../../../const/ApiConst'; +import { NotificationContainer, NotificationManager } from 'react-notifications'; +import { Pagination, Button, Tooltip } from 'antd'; +import { useTranslation } from 'react-i18next'; + +const url = ""; +const proyek_id = localStorage.getItem('proyek_id'); +const role_id = localStorage.getItem('role_id'); +const format = "DD-MM-YYYY"; +const token = window.localStorage.getItem('token'); +const config = { + headers: + { + Authorization: `Bearer ${token}`, + "Content-type": `application/json` + } +}; + +const column = [ + { name: "Nama" }, + { name: "Deskripsi" }, +] + +const ProjectType = ({ params }) => { + const token = localStorage.getItem("token") + 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 [openDialog, setOpenDialog] = useState(false) + const [rowsPerPage, setRowsPerPage] = useState(10) + const [search, setSearch] = useState('') + const [totalPage, setTotalPage] = useState(0) + const [typeDialog, setTypeDialog] = useState('Save') + const [dataDivisions, setDataDivisions] = useState([]) + const { t } = useTranslation() + + useEffect(() => { + getListDivision() + }, []) + + useEffect(() => { + getDataProjectType() + }, [currentPage, rowsPerPage, search]) + + useEffect(() => { + const cekData = dataExport || [] + if (cekData.length > 0) { + exportExcel() + } + }, [dataExport]) + + const getListDivision = async () => { + const listDivions = await axios + .get(DIVISI_LIST, HEADER) + .then(res => res) + .catch((error) => error.response); + + if (listDivions && listDivions.data && listDivions.data.code == 200) { + let arr = [] + for (const v in listDivions.data.data) { + arr.push(listDivions.data.data[v]) + } + setDataDivisions(arr); + } else { + NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); + } + } + const getDataProjectType = 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 + } + } + const result = await axios + .post(DIVISI_SEARCH, payload, HEADER) + .then(res => res) + .catch((error) => error.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 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(DIVISI_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 Divisi": val.name, + "Deskripsi": val.description, + } + 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 handleSearch = e => { + const value = e.target.value + setSearch(value); + setCurrentPage(1) + }; + + const handleOpenDialog = (type) => { + setOpenDialog(true) + setTypeDialog(type) + } + + const handleEdit = (data) => { + setDataEdit(data) + handleOpenDialog('Edit'); + } + + const handleDelete = async (id) => { + await setAlertDelete(true) + await setIdDelete(id) + } + + const handleCloseDialog = (type, data) => { + if (type === "save") { + saveProjectType(data); + } else if (type === "edit") { + editMaterialR(data); + } + setDataEdit([]) + setOpenDialog(false) + } + + const saveProjectType = async (data) => { + const formData = data + const result = await axios.post(DIVISI_ADD, formData, HEADER) + .then(res => res) + .catch((error) => error.response); + if (result && result.data && result.data.code === 200) { + getDataProjectType() + NotificationManager.success(`Data berhasil ditambah`, 'Success!!'); + } else { + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + } + + const editMaterialR = async (data) => { + let urlEdit = DIVISI_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) { + getDataProjectType(); + NotificationManager.success(`Data berhasil diedit`, 'Success!!'); + } else { + NotificationManager.error(`Data gagal di edit`, `Failed!!`); + } + } + + const toggleAddDialog = () => { + setOpenDialog(!openDialog) + } + + const onConfirmDelete = async () => { + let url = DIVISI_DELETE(idDelete); + const result = await axios.delete(url, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + getDataProjectType() + setIdDelete(0) + setAlertDelete(false) + NotificationManager.success(`Data berhasil dihapus!`, 'Success!!'); + } else { + setIdDelete(0) + setAlertDelete(false) + NotificationManager.error(`Data 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')} + + ) + } + } + + return ( +
+ + + {t('deleteMsg')} + + toggleAddDialog} + typeDialog={typeDialog} + dataEdit={dataEdit} + clickOpenModal={clickOpenModal} + dataParent={allDataMenu} + dataDivisions={dataDivisions} + /> + + +

{pageName}

+ + + + + + + + + + + + + +
+ + + + + + {column.map((i, index) => { + return ( + + ) + })} + + + + {dataNotAvailable()} + {dataTable.map((n, index) => { + return ( + + + + + + ) + })} + +
Aksi{i.name}
+ + handleDelete(n.id)}> + + + handleEdit(n)}> + + {n.name}{n.description}
+
+
+
+ ) +} + +export default ProjectType; From 1a4bcd32d78a3df08ac6b36488f93629c27c0170 Mon Sep 17 00:00:00 2001 From: wahyu Date: Wed, 13 Sep 2023 14:01:28 +0700 Subject: [PATCH 4/7] fix search uom --- src/views/SimproV2/CreatedProyek/index.js | 4 ++-- src/views/SimproV2/Satuan/index.js | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/views/SimproV2/CreatedProyek/index.js b/src/views/SimproV2/CreatedProyek/index.js index 21bfe1d..474ef70 100644 --- a/src/views/SimproV2/CreatedProyek/index.js +++ b/src/views/SimproV2/CreatedProyek/index.js @@ -1028,14 +1028,14 @@ const CreatedProyek = ({ params, ...props }) => { */} {/* */} { - text.type_proyek_id != 9 ? + /*text.type_proyek_id != 9 ?*/
handleOpenDialogGantt(text)}> Gantt
- : null + /*: null*/ }
handleSCurve(text)}> diff --git a/src/views/SimproV2/Satuan/index.js b/src/views/SimproV2/Satuan/index.js index 372ebad..39527fe 100644 --- a/src/views/SimproV2/Satuan/index.js +++ b/src/views/SimproV2/Satuan/index.js @@ -72,12 +72,6 @@ const Satuan = ({ params }) => { "logic_operator": "ilike", "value": search, "operator": "AND" - }, - { - "name": "description", - "logic_operator": "ilike", - "value": search, - "operator": "AND" } ], "orders": { From 078924802ac5afeaa8edd2f6d8ac546e8ca70a07 Mon Sep 17 00:00:00 2001 From: wahyu Date: Fri, 15 Sep 2023 14:30:05 +0700 Subject: [PATCH 5/7] endline fix --- src/views/Master/ConfigAlert/DialogForm.js | 198 ++--- src/views/Master/ConfigAlert/index.js | 344 ++++---- src/views/Master/MasterRoles/index.js | 918 ++++++++++----------- 3 files changed, 730 insertions(+), 730 deletions(-) diff --git a/src/views/Master/ConfigAlert/DialogForm.js b/src/views/Master/ConfigAlert/DialogForm.js index dfbd43b..d5d6081 100644 --- a/src/views/Master/ConfigAlert/DialogForm.js +++ b/src/views/Master/ConfigAlert/DialogForm.js @@ -1,99 +1,99 @@ -import React, { useEffect, useState } from 'react' -import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; -import { Button, Form, FormGroup, Label, Input, Col, Row } from 'reactstrap'; -import { Select } from 'antd'; -import moment from 'moment'; -import 'antd/dist/antd.css'; - -const { Option } = Select - -const DialogForm = ({openDialog, closeDialog, toggleDialog, typeDialog, dataEdit, dataMenu}) => { - const [id, setId] = useState(0) - const [name, setName] = useState('') - const [descripton, setDescription] = useState('') - const [status, setStatus] = useState('') - - - useEffect(()=> { - if(typeDialog==="Edit"){ - console.log("data edit", dataEdit) - setId(dataEdit.id) - setName(dataEdit.nama) - setDescription(dataEdit.keterangan) - setStatus(dataEdit.status) - }else{ - setId(0) - setName('') - setDescription('') - setStatus('') - } - },[dataEdit,openDialog]) - - const handleSave = () => { - let data = ''; - if(typeDialog==="Save"){ - data = { - nama:name, - keterangan:descripton, - status - } - - closeDialog('save', data); - }else{ - data = { - id, - nama:name, - keterangan:descripton, - status - } - - - closeDialog('edit', data); - } - } - - const handleCancel = () => { - closeDialog('cancel', 'none') - setId(0) - setName('') - setDescription('') - setStatus('') - } - - - const renderForm = () => { - return( -
- - - setName(e.target.value)} placeholder={`Waspang tidak sesuai target..`}/> - - - - setDescription(e.target.value)} placeholder={`Rencana vs actual tidak sesuai..`} /> - - - - setStatus(e.target.value)} placeholder={`Warning..`} /> - -
- ) - } - - - return ( - - {typeDialog=="Save" ? `Tambah` : "Edit"} Config Alert - - {renderForm()} - - - {' '} - - - - ) - -} - -export default DialogForm; \ No newline at end of file +import React, { useEffect, useState } from 'react' +import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; +import { Button, Form, FormGroup, Label, Input, Col, Row } from 'reactstrap'; +import { Select } from 'antd'; +import moment from 'moment'; +import 'antd/dist/antd.css'; + +const { Option } = Select + +const DialogForm = ({openDialog, closeDialog, toggleDialog, typeDialog, dataEdit, dataMenu}) => { + const [id, setId] = useState(0) + const [name, setName] = useState('') + const [descripton, setDescription] = useState('') + const [status, setStatus] = useState('') + + + useEffect(()=> { + if(typeDialog==="Edit"){ + console.log("data edit", dataEdit) + setId(dataEdit.id) + setName(dataEdit.nama) + setDescription(dataEdit.keterangan) + setStatus(dataEdit.status) + }else{ + setId(0) + setName('') + setDescription('') + setStatus('') + } + },[dataEdit,openDialog]) + + const handleSave = () => { + let data = ''; + if(typeDialog==="Save"){ + data = { + nama:name, + keterangan:descripton, + status + } + + closeDialog('save', data); + }else{ + data = { + id, + nama:name, + keterangan:descripton, + status + } + + + closeDialog('edit', data); + } + } + + const handleCancel = () => { + closeDialog('cancel', 'none') + setId(0) + setName('') + setDescription('') + setStatus('') + } + + + const renderForm = () => { + return( +
+ + + setName(e.target.value)} placeholder={`Waspang tidak sesuai target..`}/> + + + + setDescription(e.target.value)} placeholder={`Rencana vs actual tidak sesuai..`} /> + + + + setStatus(e.target.value)} placeholder={`Warning..`} /> + +
+ ) + } + + + return ( + + {typeDialog=="Save" ? `Tambah` : "Edit"} Config Alert + + {renderForm()} + + + {' '} + + + + ) + +} + +export default DialogForm; diff --git a/src/views/Master/ConfigAlert/index.js b/src/views/Master/ConfigAlert/index.js index 10a4505..02e13b8 100644 --- a/src/views/Master/ConfigAlert/index.js +++ b/src/views/Master/ConfigAlert/index.js @@ -1,172 +1,172 @@ -import Bell from '@iconify/icons-ion/notifications-outline'; -import BellOff from '@iconify/icons-ion/notifications-off-outline'; -import React, { useState, useEffect } from 'react'; -import axios from 'axios'; -import { CALERTUSER_SEARCH,CONFIGALERT_SEARCH,CALERTUSER_DELETE, CALERTUSER_ADD } from '../../../const/ApiConst.js'; -import { Card as ACard,Row, Col, Switch } from 'antd'; -import { Card, CardBody, CardHeader, Input } from 'reactstrap'; -import { Icon } from '@iconify/react'; -import { NotificationContainer, NotificationManager } from 'react-notifications'; - -const token = window.localStorage.getItem('token'); -const userID = window.localStorage.getItem('user_id'); - -const Index = ({params}) => { - - const [alertUser, setAlertUser] = useState([]) - const [checked, setChecked] = useState({}) - const [dataTable, setDatatable] = useState([]) - const [onSetSwitch, setOnSetSwitch] = useState(false) - const pageName = params.name; - - const config = { - headers: - { - Authorization : `Bearer ${token}`, - "Content-type" : `application/json` - } - }; - - useEffect(()=> { - getDataConfigAlert(); - },[]) - - useEffect(() => { - getDataConfigAlertUser(); - },[dataTable]) - - const getDataConfigAlert = async () => { - const payload = { - "paging": {"start": 0, "length": -1}, - "columns": [ - {"name": "nama", "logic_operator": "ilike", "value": "", "operator": "AND"} - ], - "joins": [], - "orders": {"columns": ["id"], "ascending": false} - } - - const result = await axios - .post(CONFIGALERT_SEARCH, payload, config) - .then(res => res) - .catch((error) => error.response); - - if(result && result.data && result.data.code == 200){ - let resData = result.data.data - let checkedAlert = {} - resData.map((val, index) => { - checkedAlert[val.id] = false - }); - setChecked(checkedAlert); - setDatatable(resData); - }else{ - NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); - } - } - - const getDataConfigAlertUser = async () => { - const payload = { - "paging": {"start": 0, "length": -1}, - "columns": [ - {"name": "user_id", "logic_operator": "=", "value": localStorage.getItem('user_id'), "operator": "AND"} - ], - "joins": [], - "orders": {"columns": ["id"], "ascending": false} - } - - const result = await axios - .post(CALERTUSER_SEARCH, payload, config) - .then(res => res) - .catch((error) => error.response); - - if(result && result.data && result.data.code == 200){ - let resData = result.data.data - let configAlert = []; - resData.map((val, index) => { - configAlert.push(val.config_alert_id); - let indexRes = dataTable.findIndex(x => x.id === val.config_alert_id); - if(indexRes >= 0){ - let id = dataTable[indexRes].id; - let tempChecked = checked; - tempChecked[id] = true; - setChecked(tempChecked); - } - }); - window.localStorage.setItem('userConfigAlert', configAlert.join()); - setOnSetSwitch(false) - setAlertUser(result.data.data); - }else{ - NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); - } - } - - const onChange = (checked, id) => { - setOnSetSwitch(true) - if(checked){ - addConfigAlertUser(id); - }else{ - setDeleteConfigAlertUser(id) - } - } - - const addConfigAlertUser = async (id) => { - const formData = { - "user_id":parseInt(localStorage.getItem('user_id')), - "config_alert_id":id - } - - const result = await axios.post(CALERTUSER_ADD, formData, config) - .then(res => res) - .catch((error) => error.response); - - if(result && result.data && result.data.code===200){ - getDataConfigAlertUser(); - } - } - - const setDeleteConfigAlertUser = async (id) => { - let indexCek = alertUser.findIndex(x => x.user_id === parseInt(localStorage.getItem('user_id')) && x.config_alert_id === id); - if(indexCek >= 0){ - let idAlert = alertUser[indexCek].id - deleteConfigAlertUser(idAlert) - } - } - - const deleteConfigAlertUser = async (id) => { - const url = CALERTUSER_DELETE(id) - const result = await axios.delete(url, config) - .then(res => res) - .catch((error) => error.response); - if (result && result.data && result.data.code === 200) { - getDataConfigAlert(); - } - } - - return ( -
- - - -

{pageName}

-
- - - {dataTable.map((val, index) => ( - - onChange(checked, val.id)} disabled={onSetSwitch} />, - ]}> -
- -

{val.nama}

-
-
- - ))} -
-
-
-
- ) -} - -export default Index; +import Bell from '@iconify/icons-ion/notifications-outline'; +import BellOff from '@iconify/icons-ion/notifications-off-outline'; +import React, { useState, useEffect } from 'react'; +import axios from 'axios'; +import { CALERTUSER_SEARCH,CONFIGALERT_SEARCH,CALERTUSER_DELETE, CALERTUSER_ADD } from '../../../const/ApiConst.js'; +import { Card as ACard,Row, Col, Switch } from 'antd'; +import { Card, CardBody, CardHeader, Input } from 'reactstrap'; +import { Icon } from '@iconify/react'; +import { NotificationContainer, NotificationManager } from 'react-notifications'; + +const token = window.localStorage.getItem('token'); +const userID = window.localStorage.getItem('user_id'); + +const Index = ({params}) => { + + const [alertUser, setAlertUser] = useState([]) + const [checked, setChecked] = useState({}) + const [dataTable, setDatatable] = useState([]) + const [onSetSwitch, setOnSetSwitch] = useState(false) + const pageName = params.name; + + const config = { + headers: + { + Authorization : `Bearer ${token}`, + "Content-type" : `application/json` + } + }; + + useEffect(()=> { + getDataConfigAlert(); + },[]) + + useEffect(() => { + getDataConfigAlertUser(); + },[dataTable]) + + const getDataConfigAlert = async () => { + const payload = { + "paging": {"start": 0, "length": -1}, + "columns": [ + {"name": "nama", "logic_operator": "ilike", "value": "", "operator": "AND"} + ], + "joins": [], + "orders": {"columns": ["id"], "ascending": false} + } + + const result = await axios + .post(CONFIGALERT_SEARCH, payload, config) + .then(res => res) + .catch((error) => error.response); + + if(result && result.data && result.data.code == 200){ + let resData = result.data.data + let checkedAlert = {} + resData.map((val, index) => { + checkedAlert[val.id] = false + }); + setChecked(checkedAlert); + setDatatable(resData); + }else{ + NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); + } + } + + const getDataConfigAlertUser = async () => { + const payload = { + "paging": {"start": 0, "length": -1}, + "columns": [ + {"name": "user_id", "logic_operator": "=", "value": localStorage.getItem('user_id'), "operator": "AND"} + ], + "joins": [], + "orders": {"columns": ["id"], "ascending": false} + } + + const result = await axios + .post(CALERTUSER_SEARCH, payload, config) + .then(res => res) + .catch((error) => error.response); + + if(result && result.data && result.data.code == 200){ + let resData = result.data.data + let configAlert = []; + resData.map((val, index) => { + configAlert.push(val.config_alert_id); + let indexRes = dataTable.findIndex(x => x.id === val.config_alert_id); + if(indexRes >= 0){ + let id = dataTable[indexRes].id; + let tempChecked = checked; + tempChecked[id] = true; + setChecked(tempChecked); + } + }); + window.localStorage.setItem('userConfigAlert', configAlert.join()); + setOnSetSwitch(false) + setAlertUser(result.data.data); + }else{ + NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); + } + } + + const onChange = (checked, id) => { + setOnSetSwitch(true) + if(checked){ + addConfigAlertUser(id); + }else{ + setDeleteConfigAlertUser(id) + } + } + + const addConfigAlertUser = async (id) => { + const formData = { + "user_id":parseInt(localStorage.getItem('user_id')), + "config_alert_id":id + } + + const result = await axios.post(CALERTUSER_ADD, formData, config) + .then(res => res) + .catch((error) => error.response); + + if(result && result.data && result.data.code===200){ + getDataConfigAlertUser(); + } + } + + const setDeleteConfigAlertUser = async (id) => { + let indexCek = alertUser.findIndex(x => x.user_id === parseInt(localStorage.getItem('user_id')) && x.config_alert_id === id); + if(indexCek >= 0){ + let idAlert = alertUser[indexCek].id + deleteConfigAlertUser(idAlert) + } + } + + const deleteConfigAlertUser = async (id) => { + const url = CALERTUSER_DELETE(id) + const result = await axios.delete(url, config) + .then(res => res) + .catch((error) => error.response); + if (result && result.data && result.data.code === 200) { + getDataConfigAlert(); + } + } + + return ( +
+ + + +

{pageName}

+
+ + + {dataTable.map((val, index) => ( + + onChange(checked, val.id)} disabled={onSetSwitch} />, + ]}> +
+ +

{val.nama}

+
+
+ + ))} +
+
+
+
+ ) +} + +export default Index; diff --git a/src/views/Master/MasterRoles/index.js b/src/views/Master/MasterRoles/index.js index 36828aa..f68e362 100644 --- a/src/views/Master/MasterRoles/index.js +++ b/src/views/Master/MasterRoles/index.js @@ -1,459 +1,459 @@ -import * as XLSX from 'xlsx'; -import DialogForm from './DialogForm'; -import DialogMenuRoles from './DialogMenuRoles'; -import React, { Component, useMemo } from 'react'; -import SweetAlert from 'react-bootstrap-sweetalert'; -import axios from 'axios'; -import { Button } from 'reactstrap'; -import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; -import { NotificationContainer, NotificationManager } from 'react-notifications'; -import { Pagination, Tooltip, Table } from 'antd'; -import { ROLE_ADD, ROLE_SEARCH, ROLE_EDIT, ROLE_DELETE, ROLEMENU_ADD, ROLEMENU_SEARCH, ROLEMENU_DELETE_ROLE } from '../../../const/ApiConst.js'; -import { withTranslation } from 'react-i18next'; - -const token = window.localStorage.getItem('token'); - -const BASE_URL = "http://siopas.co.id/custom-php/api/geohr/"; - -const config = { - headers: - { - Authorization: `Bearer ${token}`, - "Content-type": `application/json` - } -}; - -const momentFormat = 'HH:mm'; - -const LENGTH_DATA = 10 - -class index extends Component { - constructor(props) { - super(props) - this.state = { - alertDelete: false, - alertNotDelete: false, - currentPage: 1, - dataEdit: null, - dataExport: [], - dataGs: [], - dataIdHo: [], - dataTable: [], - dialogMenuForm: false, - idDelete: 0, - idRoles: 0, - menuRoles: [], - openDialog: false, - page: 0, - rowsPerPage: LENGTH_DATA, - search: "", - tooltipDelete: false, - tooltipEdit: false, - tooltipExport: false, - tooltipImport: false, - tooltipMenu: false, - tooltipTambah: false, - totalPage: 0, - typeDialog: 'Save', - } - - this.columns = [ - { - title: this.props.t('action'), - dataIndex: '', - key: 'x', - className: 'nowrap', - render: (text, record) => <> - - this.handleMenuRoles(text.id)}> - - - - this.handleDelete(text.id)}> - - - - this.handleEdit(text)}> - - , - }, - { title: this.props.t('nameRole'), dataIndex: 'name', key: 'name', className: "nowrap" }, - { title: this.props.t('description'), dataIndex: 'description', key: 'description' }, - ] - } - - async componentDidMount() { - this.getDataRoles(); - } - - async componentDidUpdate(prevProps, prevState) { - const { search } = this.state - if (search !== prevState.search) this.getDataRoles() - if (prevProps.dataExport !== this.props.dataExport && this.props.dataExport.length > 0) { - this.handleExportExcel(); - } - } - - handleSearch = e => { - const value = e.target.value - this.setState({ search: value, currentPage: 1 }) - }; - - getDataRoles = async () => { - let start = 0; - if (this.state.currentPage !== 1 && this.state.currentPage > 1) { - start = (this.state.currentPage * this.state.rowsPerPage) - this.state.rowsPerPage - } - - const formData = { - "paging": { "start": start, "length": this.state.rowsPerPage }, - "columns": [ - { "name": "name", "logic_operator": "ilike", "value": this.state.search, "operator": "AND" } - ], - "joins": [], - "orders": { "columns": ["id"], "ascending": false } - } - - const result = await axios - .post(ROLE_SEARCH, formData, config) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code == 200) { - this.setState({ dataTable: result.data.data, 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.saveRole(data); - } else if (type === "edit") { - this.editRole(data); - } - this.setState({ openDialog: false }) - } - - handleOpenDialogMr = () => { - this.setState({ dialogMenuForm: true }) - this.showMenuRolesDialog(); - } - - handleCloseDialogMr = (type, data) => { - if (type === "save") { - this.saveMenuRoles(data) - } - this.setState({ dialogMenuForm: false }) - } - - toggleAddDialog = () => { - this.setState({ openDialog: !this.state.openDialog }) - } - - onConfirmDelete = async () => { - const { idDelete } = this.state - const url = ROLE_DELETE(idDelete) - - const result = await axios.delete(url, config) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - this.deleteCurrentRoleMenu(idDelete) - this.getDataRoles() - this.setState({ idDelete: 0, alertDelete: false }) - NotificationManager.success(`Data role berhasil dihapus`, 'Success!!'); - } else { - this.setState({ idDelete: 0, alertDelete: false }) - NotificationManager.error(`Data role gagal dihapus`, 'Failed!!'); - } - } - - saveRole = async (data) => { - - const formData = { - name: data.name, - description: data.description - } - - const result = await axios.post(ROLE_ADD, formData, config) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - this.getDataRoles(); - NotificationManager.success(`Data role berhasil ditambah`, 'Success!!'); - } else { - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - - } - - editRole = async (data) => { - const formData = { - name: data.name, - description: data.description - } - const url = ROLE_EDIT(data.id) - const result = await axios.put(url, formData, config) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - this.getDataRoles(); - NotificationManager.success(`Data role berhasil diedit`, 'Success!!'); - } else { - NotificationManager.error(`Data role gagal di edit`, `Failed!!`); - } - } - - handleEdit = (data) => { - this.setState({ dataEdit: data }); - this.handleOpenDialog('Edit'); - } - - handleDelete = (id) => { - id == '1' ? this.setState({ alertNotDelete: true }) : - this.setState({ alertDelete: true, idDelete: id }); - } - - onShowSizeChange = (current, pageSize) => { - this.setState({ rowsPerPage: pageSize }, () => { - this.getDataRoles(); - }) - } - - onPagination = (current, pageSize) => { - this.setState({ currentPage: current, page: (current - 1) * pageSize }, () => { - this.getDataRoles(); - }) - } - - toggle = (param) => { - if (param === "edit") { - this.setState(prevState => ({ tooltipEdit: !prevState.tooltipEdit })) - } else if (param === "delete") { - this.setState(prevState => ({ tooltipDelete: !prevState.tooltipDelete })) - } else if (param === "menu") { - this.setState(prevState => ({ tooltipMenu: !prevState.tooltipMenu })) - } else if (param === "tambah") { - this.setState(prevState => ({ tooltipTambah: !prevState.tooltipTambah })) - } else if (param === "export") { - this.setState(prevState => ({ tooltipExport: !prevState.tooltipExport })) - } - } - - dataNotAvailable = () => { - if (this.state.dataTable.length === 0) { - return ( - - {this.props.t('noData')} - - ) - } - } - - handleMenuRoles = async (id) => { - const formData = { - "paging": { "start": 0, "length": -1 }, - "columns": [ - { "name": "role_id", "logic_operator": "=", "value": `${id}`, "operator": "AND" } - ], - "joins": [], - "orders": { "columns": ["id"], "ascending": false } - } - - const result = await axios - .post(ROLEMENU_SEARCH, formData, config) - .then(res => res) - .catch((error) => error.response); - if (result && result.data && result.data.code == 200) { - this.setState({ menuRoles: result.data.data, idRoles: id }, () => { - this.handleOpenDialogMr(); - }); - } else { - } - } - - saveMenuRoles = async (dataArray) => { - let payloadArray = dataArray || [] - if (payloadArray.length > 0) { - await this.deleteCurrentRoleMenu(payloadArray[0].roles_id) - } - let promises = [] - let result = [] - dataArray.map((val, index) => { - if (val.checked === true) { - const formData = { - menu_id: val.menu_id, - role_id: val.roles_id - } - promises.push(axios.post(ROLEMENU_ADD, formData, config) - .then(res => result.push(res))) - } - }) - - await Promise.all(promises); - if (result) { - if (result.length > 0) { - if (result[0].data.code === 200) { - this.getDataRoles(); - NotificationManager.success('Data roles berhasil ditambahkan!!', 'Success!!'); - } else { - NotificationManager.error(`${result[0].data.message}`, 'Failed!!'); - } - } - } - } - - deleteCurrentRoleMenu = async (id) => { - let urlDel = ROLEMENU_DELETE_ROLE(id) - const result = await axios.delete(urlDel, config) - .then(res => res) - .catch((error) => error.response); - if (result && result.data && result.data.code === 200) { - return true - } else { - return false - } - } - - handleExportExcel = async () => { - let start = 0; - let end = "ALL"; - const formData = { - "paging": { "start": start, "length": this.state.rowsPerPage }, - "columns": [ - { "name": "name", "logic_operator": "ilike", "value": this.state.search, "operator": "AND" } - ], - "joins": [], - "orders": { "columns": ["id"], "ascending": false } - } - - const result = await axios - .post(ROLE_SEARCH, formData, config) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.statusText == "OK") { - const dataRes = result.data.data || []; - const dataExport = []; - dataRes.map((val, index) => { - let row = { - Nama: val.name, - Deskripsi: val.description - } - dataExport.push(row); - }) - this.setState({ dataExport: dataExport }, () => { - this.exportExcel(); - }); - } else { - NotificationManager.error('Failed retreiving data!!', 'Failed'); - } - } - - exportExcel = () => { - const dataExcel = this.state.dataExport || []; - const fileName = "Data Roles.xlsx"; - const ws = XLSX.utils.json_to_sheet(dataExcel); - const wb = XLSX.utils.book_new(); - XLSX.utils.book_append_sheet(wb, ws, 'Data Roles'); - XLSX.writeFile(wb, fileName); - } - - render() { - const { t } = this.props; - const { tooltipTambah, tooltipExport, dialogMenuForm, dataTable, openDialog, currentPage, rowsPerPage, totalPage, search, tooltipEdit, tooltipDelete, tooltipMenu } = this.state - let noSeq = 0; - return ( -
- - this.setState({ alertDelete: false, idDelete: 0 })} - focusCancelBtn - > - {this.props.t('deleteMsg')} - - this.setState({ alertNotDelete: false })} - > - Data tipe roles tidak dapat di hapus!! - - this.toggleAddDialog} - typeDialog={this.state.typeDialog} - dataEdit={this.state.dataEdit} - showDialog={showDialog => this.showChildDialog = showDialog} - dataHs={this.state.dataIdHo} - /> - this.showMenuRolesDialog = showDialog} - menuRoles={this.state.menuRoles} - /> - - -

{this.props.params.name}

- - - - - - - - - - - - - -
- - - - - - - ) - } -} -export default withTranslation()(index); \ No newline at end of file +import * as XLSX from 'xlsx'; +import DialogForm from './DialogForm'; +import DialogMenuRoles from './DialogMenuRoles'; +import React, { Component, useMemo } from 'react'; +import SweetAlert from 'react-bootstrap-sweetalert'; +import axios from 'axios'; +import { Button } from 'reactstrap'; +import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; +import { NotificationContainer, NotificationManager } from 'react-notifications'; +import { Pagination, Tooltip, Table } from 'antd'; +import { ROLE_ADD, ROLE_SEARCH, ROLE_EDIT, ROLE_DELETE, ROLEMENU_ADD, ROLEMENU_SEARCH, ROLEMENU_DELETE_ROLE } from '../../../const/ApiConst.js'; +import { withTranslation } from 'react-i18next'; + +const token = window.localStorage.getItem('token'); + +const BASE_URL = "http://siopas.co.id/custom-php/api/geohr/"; + +const config = { + headers: + { + Authorization: `Bearer ${token}`, + "Content-type": `application/json` + } +}; + +const momentFormat = 'HH:mm'; + +const LENGTH_DATA = 10 + +class index extends Component { + constructor(props) { + super(props) + this.state = { + alertDelete: false, + alertNotDelete: false, + currentPage: 1, + dataEdit: null, + dataExport: [], + dataGs: [], + dataIdHo: [], + dataTable: [], + dialogMenuForm: false, + idDelete: 0, + idRoles: 0, + menuRoles: [], + openDialog: false, + page: 0, + rowsPerPage: LENGTH_DATA, + search: "", + tooltipDelete: false, + tooltipEdit: false, + tooltipExport: false, + tooltipImport: false, + tooltipMenu: false, + tooltipTambah: false, + totalPage: 0, + typeDialog: 'Save', + } + + this.columns = [ + { + title: this.props.t('action'), + dataIndex: '', + key: 'x', + className: 'nowrap', + render: (text, record) => <> + + this.handleMenuRoles(text.id)}> + + + + this.handleDelete(text.id)}> + + + + this.handleEdit(text)}> + + , + }, + { title: this.props.t('nameRole'), dataIndex: 'name', key: 'name', className: "nowrap" }, + { title: this.props.t('description'), dataIndex: 'description', key: 'description' }, + ] + } + + async componentDidMount() { + this.getDataRoles(); + } + + async componentDidUpdate(prevProps, prevState) { + const { search } = this.state + if (search !== prevState.search) this.getDataRoles() + if (prevProps.dataExport !== this.props.dataExport && this.props.dataExport.length > 0) { + this.handleExportExcel(); + } + } + + handleSearch = e => { + const value = e.target.value + this.setState({ search: value, currentPage: 1 }) + }; + + getDataRoles = async () => { + let start = 0; + if (this.state.currentPage !== 1 && this.state.currentPage > 1) { + start = (this.state.currentPage * this.state.rowsPerPage) - this.state.rowsPerPage + } + + const formData = { + "paging": { "start": start, "length": this.state.rowsPerPage }, + "columns": [ + { "name": "name", "logic_operator": "ilike", "value": this.state.search, "operator": "AND" } + ], + "joins": [], + "orders": { "columns": ["id"], "ascending": false } + } + + const result = await axios + .post(ROLE_SEARCH, formData, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code == 200) { + this.setState({ dataTable: result.data.data, 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.saveRole(data); + } else if (type === "edit") { + this.editRole(data); + } + this.setState({ openDialog: false }) + } + + handleOpenDialogMr = () => { + this.setState({ dialogMenuForm: true }) + this.showMenuRolesDialog(); + } + + handleCloseDialogMr = (type, data) => { + if (type === "save") { + this.saveMenuRoles(data) + } + this.setState({ dialogMenuForm: false }) + } + + toggleAddDialog = () => { + this.setState({ openDialog: !this.state.openDialog }) + } + + onConfirmDelete = async () => { + const { idDelete } = this.state + const url = ROLE_DELETE(idDelete) + + const result = await axios.delete(url, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + this.deleteCurrentRoleMenu(idDelete) + this.getDataRoles() + this.setState({ idDelete: 0, alertDelete: false }) + NotificationManager.success(`Data role berhasil dihapus`, 'Success!!'); + } else { + this.setState({ idDelete: 0, alertDelete: false }) + NotificationManager.error(`Data role gagal dihapus`, 'Failed!!'); + } + } + + saveRole = async (data) => { + + const formData = { + name: data.name, + description: data.description + } + + const result = await axios.post(ROLE_ADD, formData, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + this.getDataRoles(); + NotificationManager.success(`Data role berhasil ditambah`, 'Success!!'); + } else { + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + + } + + editRole = async (data) => { + const formData = { + name: data.name, + description: data.description + } + const url = ROLE_EDIT(data.id) + const result = await axios.put(url, formData, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + this.getDataRoles(); + NotificationManager.success(`Data role berhasil diedit`, 'Success!!'); + } else { + NotificationManager.error(`Data role gagal di edit`, `Failed!!`); + } + } + + handleEdit = (data) => { + this.setState({ dataEdit: data }); + this.handleOpenDialog('Edit'); + } + + handleDelete = (id) => { + id == '1' ? this.setState({ alertNotDelete: true }) : + this.setState({ alertDelete: true, idDelete: id }); + } + + onShowSizeChange = (current, pageSize) => { + this.setState({ rowsPerPage: pageSize }, () => { + this.getDataRoles(); + }) + } + + onPagination = (current, pageSize) => { + this.setState({ currentPage: current, page: (current - 1) * pageSize }, () => { + this.getDataRoles(); + }) + } + + toggle = (param) => { + if (param === "edit") { + this.setState(prevState => ({ tooltipEdit: !prevState.tooltipEdit })) + } else if (param === "delete") { + this.setState(prevState => ({ tooltipDelete: !prevState.tooltipDelete })) + } else if (param === "menu") { + this.setState(prevState => ({ tooltipMenu: !prevState.tooltipMenu })) + } else if (param === "tambah") { + this.setState(prevState => ({ tooltipTambah: !prevState.tooltipTambah })) + } else if (param === "export") { + this.setState(prevState => ({ tooltipExport: !prevState.tooltipExport })) + } + } + + dataNotAvailable = () => { + if (this.state.dataTable.length === 0) { + return ( + + + + ) + } + } + + handleMenuRoles = async (id) => { + const formData = { + "paging": { "start": 0, "length": -1 }, + "columns": [ + { "name": "role_id", "logic_operator": "=", "value": `${id}`, "operator": "AND" } + ], + "joins": [], + "orders": { "columns": ["id"], "ascending": false } + } + + const result = await axios + .post(ROLEMENU_SEARCH, formData, config) + .then(res => res) + .catch((error) => error.response); + if (result && result.data && result.data.code == 200) { + this.setState({ menuRoles: result.data.data, idRoles: id }, () => { + this.handleOpenDialogMr(); + }); + } else { + } + } + + saveMenuRoles = async (dataArray) => { + let payloadArray = dataArray || [] + if (payloadArray.length > 0) { + await this.deleteCurrentRoleMenu(payloadArray[0].roles_id) + } + let promises = [] + let result = [] + dataArray.map((val, index) => { + if (val.checked === true) { + const formData = { + menu_id: val.menu_id, + role_id: val.roles_id + } + promises.push(axios.post(ROLEMENU_ADD, formData, config) + .then(res => result.push(res))) + } + }) + + await Promise.all(promises); + if (result) { + if (result.length > 0) { + if (result[0].data.code === 200) { + this.getDataRoles(); + NotificationManager.success('Data roles berhasil ditambahkan!!', 'Success!!'); + } else { + NotificationManager.error(`${result[0].data.message}`, 'Failed!!'); + } + } + } + } + + deleteCurrentRoleMenu = async (id) => { + let urlDel = ROLEMENU_DELETE_ROLE(id) + const result = await axios.delete(urlDel, config) + .then(res => res) + .catch((error) => error.response); + if (result && result.data && result.data.code === 200) { + return true + } else { + return false + } + } + + handleExportExcel = async () => { + let start = 0; + let end = "ALL"; + const formData = { + "paging": { "start": start, "length": this.state.rowsPerPage }, + "columns": [ + { "name": "name", "logic_operator": "ilike", "value": this.state.search, "operator": "AND" } + ], + "joins": [], + "orders": { "columns": ["id"], "ascending": false } + } + + const result = await axios + .post(ROLE_SEARCH, formData, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.statusText == "OK") { + const dataRes = result.data.data || []; + const dataExport = []; + dataRes.map((val, index) => { + let row = { + Nama: val.name, + Deskripsi: val.description + } + dataExport.push(row); + }) + this.setState({ dataExport: dataExport }, () => { + this.exportExcel(); + }); + } else { + NotificationManager.error('Failed retreiving data!!', 'Failed'); + } + } + + exportExcel = () => { + const dataExcel = this.state.dataExport || []; + const fileName = "Data Roles.xlsx"; + const ws = XLSX.utils.json_to_sheet(dataExcel); + const wb = XLSX.utils.book_new(); + XLSX.utils.book_append_sheet(wb, ws, 'Data Roles'); + XLSX.writeFile(wb, fileName); + } + + render() { + const { t } = this.props; + const { tooltipTambah, tooltipExport, dialogMenuForm, dataTable, openDialog, currentPage, rowsPerPage, totalPage, search, tooltipEdit, tooltipDelete, tooltipMenu } = this.state + let noSeq = 0; + return ( +
+ + this.setState({ alertDelete: false, idDelete: 0 })} + focusCancelBtn + > + {this.props.t('deleteMsg')} + + this.setState({ alertNotDelete: false })} + > + Data tipe roles tidak dapat di hapus!! + + this.toggleAddDialog} + typeDialog={this.state.typeDialog} + dataEdit={this.state.dataEdit} + showDialog={showDialog => this.showChildDialog = showDialog} + dataHs={this.state.dataIdHo} + /> + this.showMenuRolesDialog = showDialog} + menuRoles={this.state.menuRoles} + /> + + +

{this.props.params.name}

+ +
+ + + + + + + + + + + + + +
{this.props.t('noData')}
+ + + + + ) + } +} +export default withTranslation()(index); From dda602ecf0c809b6466b89e1f7a86a8505228025 Mon Sep 17 00:00:00 2001 From: wahyu Date: Wed, 20 Sep 2023 14:01:40 +0700 Subject: [PATCH 6/7] project detail use gantt id --- src/views/Dashboard/DashboardProject.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/views/Dashboard/DashboardProject.js b/src/views/Dashboard/DashboardProject.js index ac105d5..c0ebe00 100644 --- a/src/views/Dashboard/DashboardProject.js +++ b/src/views/Dashboard/DashboardProject.js @@ -268,7 +268,10 @@ const DashboardProject = () => { const getProjectDetail = async () => { setIsReadyProjectDetail(false); - const URL = `${BASE_OSPRO}/api/project/detail/${PROJECT_ID}`; + let URL = `${BASE_OSPRO}/api/project/detail/${PROJECT_ID}`; + if (GANTT_ID) { + URL = `${BASE_OSPRO}/api/project/detail/${PROJECT_ID}/${GANTT_ID}`; + } const result = await axios .get(URL, HEADER) .then((res) => res) From 4c9cafb264859c9a87c72a283f0520d24e1d311f Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 21 Sep 2023 14:21:06 +0700 Subject: [PATCH 7/7] fix schedule dashboard project --- src/views/Dashboard/DashboardProject.js | 19 +++++++++++++++++-- src/views/SimproV2/CreatedProyek/index.js | 4 ++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/views/Dashboard/DashboardProject.js b/src/views/Dashboard/DashboardProject.js index c0ebe00..cabac62 100644 --- a/src/views/Dashboard/DashboardProject.js +++ b/src/views/Dashboard/DashboardProject.js @@ -272,6 +272,9 @@ const DashboardProject = () => { if (GANTT_ID) { URL = `${BASE_OSPRO}/api/project/detail/${PROJECT_ID}/${GANTT_ID}`; } + if (SCURVE) { + URL = `${BASE_OSPRO}/api/project/detail/${PROJECT_ID}/${GANTT_ID}/${SCURVE}`; + } const result = await axios .get(URL, HEADER) .then((res) => res) @@ -301,10 +304,22 @@ const DashboardProject = () => { result.data.data.company ? result.data.data.company : "-" ); setPlannedStart( - result.data.data?.mulai_proyek ? result.data.data.mulai_proyek : null + SCURVE + ? result.data.data.mulai_proyek + ? result.data.data.mulai_proyek + : null + : result.data.data.header?.planned_start + ? result.data.data.header?.planned_start + : null ); setPlannedFinish( - result.data.data?.akhir_proyek ? result.data.data.akhir_proyek : null + SCURVE + ? result.data.data.akhir_proyek + ? result.data.data.akhir_proyek + : null + : result.data.data.header?.planned_end + ? result.data.data.header?.planned_end + : null ); setActualStart( result.data.data.header?.start_date diff --git a/src/views/SimproV2/CreatedProyek/index.js b/src/views/SimproV2/CreatedProyek/index.js index 76b1086..bbe638a 100644 --- a/src/views/SimproV2/CreatedProyek/index.js +++ b/src/views/SimproV2/CreatedProyek/index.js @@ -252,7 +252,7 @@ const CreatedProyek = ({ params, ...props }) => { return; } else if (result.status == 200 && result.data.data) { history.push( - `dashboard-customer/${text.id}/${result.data.gantt.last_gantt_id}/1` + `dashboard-customer/${text.id}/${result.data.gantt}/1` ); } }; @@ -520,7 +520,7 @@ const CreatedProyek = ({ params, ...props }) => { return; } else if (result.status == 200 && result.data.data) { history.push( - `/dashboard-project/${id}/${result.data.gantt.last_gantt_id}/1` + `/dashboard-project/${id}/${result.data.gantt}/1` ); } };