From 1eb46cc6b5f3d817ccd2e299352f2d87547e356b Mon Sep 17 00:00:00 2001 From: farhantock Date: Tue, 5 Dec 2023 13:55:39 +0700 Subject: [PATCH] filter project in report K3 --- src/views/Report/k3/index.js | 51 +++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/src/views/Report/k3/index.js b/src/views/Report/k3/index.js index 75085c3..a6a15ec 100644 --- a/src/views/Report/k3/index.js +++ b/src/views/Report/k3/index.js @@ -13,14 +13,7 @@ import { PRESENSI_SEARCH, PROYEK_SEARCH, USERPROYEK_SEARCH, K3_SEARCH, SIMPRO_BA import { withTranslation } from 'react-i18next'; const { RangePicker } = DatePicker; const { Option } = Select -const token = localStorage.getItem('token'); -const config = { - headers: - { - Authorization: `Bearer ${token}`, - "Content-type": `application/json` - } -}; + const BASE_URL = "" @@ -31,8 +24,33 @@ const momentFormat = 'DD-MM-YY'; const LENGTH_DATA = 10 class index extends Component { + constructor(props) { + + let role_id = '', user_id = '', isLogin = '', token = '', company_id = 0, role_name = '', hierarchy = []; + if (props.location.state && props.location.state.role_id && props.location.state.user_id) { + role_id = props.location.state.role_id; + user_id = props.location.state.user_id; + token = props.location.state.token; + isLogin = props.location.state.isLogin; + company_id = props.location.state.company_id; + role_name = props.location.state.role_name; + hierarchy = props.location.state.hierarchy; + + + } else { + token = window.localStorage.getItem('token'); + role_name = window.localStorage.getItem('role_name'); + company_id = window.localStorage.getItem('company_id'); + hierarchy.push(JSON.parse(localStorage.getItem("hierarchy"))); + } super(props) + this.config = { + headers: { + Authorization: `Bearer ${token}`, + "Content-type": "application/json" + } + }; this.state = { dataTable: [], dataExport: [], @@ -61,7 +79,11 @@ class index extends Component { allUserToProyek: [], proyekIds: [], allDataProyek: [], - finishSetupOption: false + finishSetupOption: false, + company_id: company_id, + role_name: role_name, + role_id: role_id, + hierarchy: hierarchy } } @@ -111,9 +133,14 @@ class index extends Component { "joins": [], "orders": { "columns": ["id"], "ascending": false } } + if (this.state.role_id !== "Super Admin") { + payload.columns.push( + { name: "created_by_id", logic_operator: "IN", value: this.state.hierarchy, operator: "AND" } + ) + } const result = await axios - .post(PROYEK_SEARCH, payload, config) + .post(PROYEK_SEARCH, payload, this.config) .then(res => res) .catch((error) => error.response); @@ -194,7 +221,7 @@ class index extends Component { } const result = await axios - .post(K3_SEARCH, payload, config) + .post(K3_SEARCH, payload, this.config) .then(res => res) .catch((error) => error.response); @@ -394,7 +421,7 @@ class index extends Component { const result = await axios - .post(K3_SEARCH, payload, config) + .post(K3_SEARCH, payload, this.config) .then(res => res) .catch((error) => error.response);