From 40812f9142cc6504f887631f4317606a7e678690 Mon Sep 17 00:00:00 2001 From: wahyun Date: Tue, 14 May 2024 14:49:45 +0700 Subject: [PATCH] feat: add type paket in company management --- src/views/Master/MasterCompany/DialogForm.js | 36 +++++- src/views/Master/MasterCompany/index.js | 129 +++++++++++-------- 2 files changed, 110 insertions(+), 55 deletions(-) diff --git a/src/views/Master/MasterCompany/DialogForm.js b/src/views/Master/MasterCompany/DialogForm.js index 33149f0..40d0578 100644 --- a/src/views/Master/MasterCompany/DialogForm.js +++ b/src/views/Master/MasterCompany/DialogForm.js @@ -23,7 +23,7 @@ const config = { "Content-type": `application/json` } }; -const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, companyID, companyNameProp, dataEditCompany, imageHeader, imageFavIcon, imageLogin, imageSlider, lastIdCompany }) => { +const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, companyID, companyNameProp, transaction, dataEditCompany, imageHeader, imageFavIcon, imageLogin, imageSlider, lastIdCompany }) => { const { Option } = Select const { t } = useTranslation() const [registrationnumber, setRegistrationNumber] = useState('') @@ -44,6 +44,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company const [baseUrl, setBaseUrl] = useState([]) const [statusCompany, setStatusCompany] = useState(true) const [template, setTemplate] = useState('') + const [typePaket, setTypePaket] = useState('') const [lastIdxURL, setLastIdxURL] = useState(0); const [availableUrl, setAvailableBaseUrl] = useState(false); const [id, setId] = useState(0) @@ -96,6 +97,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company setHtmlTitle(dataEditCompany.html_title) setStatusCompany(dataEditCompany.is_active) setTemplate(dataEditCompany.template_id) + setTypePaket(transaction ? transaction?.type_paket : '') setBaseUrl(dataEditCompany.base_url ? dataEditCompany.base_url : []) if (dataEditCompany.base_url) { setAvailableBaseUrl(true) @@ -114,6 +116,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company setHtmlTitle('') setStatusCompany('') setTemplate('') + setTypePaket('') setLogoLogin(null) setLogoHeader(null) setSliderLogin(null) @@ -377,6 +380,26 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company alert("Please input the name"); return; } + if (!statusCompany && statusCompany === "") { + alert("Please select the company status"); + return; + } + if (!template && template === "") { + alert("Please select the template company"); + return; + } + if (!template && template === "") { + alert("Please select the template company"); + return; + } + if (!typeAccount && typeAccount === "") { + alert("Please select the type account"); + return; + } + if (!typePaket && typePaket === "") { + alert("Please select the type paket"); + return; + } if (typeDialog === "Save") { data = { @@ -394,6 +417,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company is_active: statusCompany, template_id: parseInt(template), type_account: typeAccount, + type_paket: typePaket, date_register: moment() } data.imageLogin = logoLogin ? logoLogin : null; @@ -419,6 +443,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company is_active: statusCompany, template_id: parseInt(template), type_account: typeAccount, + type_paket: typePaket } data.imageLogin = logoLogin ? logoLogin : null; data.imageHeader = logoHeader ? logoHeader : null; @@ -723,6 +748,15 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company + + + + + + diff --git a/src/views/Master/MasterCompany/index.js b/src/views/Master/MasterCompany/index.js index 9c5c9b5..3c99106 100644 --- a/src/views/Master/MasterCompany/index.js +++ b/src/views/Master/MasterCompany/index.js @@ -6,7 +6,8 @@ import DialogForm from './DialogForm' import { NotificationContainer, NotificationManager } from 'react-notifications'; import { Pagination, Table, Button, Tooltip, Spin } from 'antd'; import { - COMPANY_MANAGEMENT_SEARCH, COMPANY_MANAGEMENT_ADD, COMPANY_MANAGEMENT_EDIT, COMPANY_MANAGEMENT_DELETE, IMAGE_UPLOAD, IMAGE_MULTIPLE_UPLOAD, IMAGE_MULTIPLE_DELETE, IMAGE_GET_BY_ID, IMAGE_DELETE, IMAGE_SEARCH + COMPANY_MANAGEMENT_SEARCH, COMPANY_MANAGEMENT_ADD, COMPANY_MANAGEMENT_EDIT, COMPANY_MANAGEMENT_DELETE, IMAGE_UPLOAD, IMAGE_MULTIPLE_UPLOAD, IMAGE_MULTIPLE_DELETE, IMAGE_GET_BY_ID, IMAGE_DELETE, IMAGE_SEARCH, + TRANSACTION_SEARCH } from '../../../const/ApiConst'; import { useTranslation } from 'react-i18next'; const token = window.localStorage.getItem('token'); @@ -19,12 +20,8 @@ const config = { }; const MasterCompany = ({ params }) => { - const token = localStorage.getItem("token") - let company_id = ''; - const role = window.localStorage.getItem('role_name'); - if(role != 'Super Admin') { - company_id = localStorage.getItem("company_id"); - } + const token = localStorage.getItem("token"); + const HEADER = { headers: { "Content-Type": "application/json", @@ -54,13 +51,11 @@ const MasterCompany = ({ params }) => { const [imageSlider, setProjectImageSlider] = useState([]); const [imageFavIcon, setProjectImageFavicon] = useState(null); const [lastIdCompany,setLastCompanyId] = useState(''); + const [transaction, setTransaction] = useState([]); const [loading, setLoading] = useState(true); const pageName = params.name; const { t } = useTranslation(); - let configApp = ''; - if (role !== 'Super Admin') { - configApp = JSON.parse(window.localStorage.getItem('configApp')); - } + useEffect(() => { setLoading(true) getDataCompany() @@ -192,6 +187,33 @@ const MasterCompany = ({ params }) => { } } + const getDataTransaction = async (company_id) => { + const formData = { + "paging": {"start": 0, "length": 1}, + "columns": [ + {"name": "company_id", "logic_operator": "=", "value": parseInt(company_id), "operator": "AND"} + ], + "select": [ + "company_id", + "type_paket", + "amount", + "exp_ospro", + "pay_date", + "created_at" + ] + } + const result = await axios + .post(TRANSACTION_SEARCH, formData, config) + .then(res => res) + .catch((error) => error.response ); + if (result && result.data && result.data.code == 200) { + let dataRes = result.data.data[0]; + setTransaction(dataRes); + } else { + NotificationManager.error("Gagal Mengambil Data!!", "Failed"); + } + } + const handleSearch = e => { const value = e.target.value setSearch(value); @@ -201,11 +223,13 @@ const MasterCompany = ({ params }) => { const handleOpenDialog = async (type) => { await setTypeDialog(type) setOpenDialog(true) - } const handleEdit = async (data) => { setDataEdit(data); + setCompanyID(data.id); + getDataTransaction(data.id); + setCompanyName(data.company_name); await getProjectImageHeader(data.id); await getProjectImageSlider(data.id); await getProjectImageLogin(data.id); @@ -228,9 +252,11 @@ const MasterCompany = ({ params }) => { } - const handleDelete = async (id) => { - await setAlertDelete(true) - await setIdDelete(id) + const handleDelete = async (data) => { + setCompanyID(data.id); + setCompanyName(data.company_name); + await setAlertDelete(true); + await setIdDelete(data.id); } const handleCloseDialog = (type, data) => { @@ -247,7 +273,7 @@ const MasterCompany = ({ params }) => { setOpenDialog(false) } - const packFiles = (id, files) => { + const packFiles = (id, files, company_name) => { const data = new FormData(); for (let i = 0; i < files.length; i++) { @@ -256,11 +282,10 @@ const MasterCompany = ({ params }) => { data.append('ref_id', id); data.append('category', 'company_slider_login'); - + data.append('company_name', company_name) return data; }; - const saveCompany = async (data) => { const formData = data const result = await axios.post(COMPANY_MANAGEMENT_ADD, formData, HEADER) @@ -272,26 +297,31 @@ const MasterCompany = ({ params }) => { const logoLogin = data.imageLogin; const favIcon = data.imageFavicon; const slider = data.imageSlider; + const resultData = result.data.data; + setCompanyName(resultData.company_name); if (logoHeader) { await saveImageHeader( - result.data.data.id, - logoHeader + resultData.id, + logoHeader, + resultData.company_name ); } if (logoLogin) { await saveImageLogin( - result.data.data.id, - logoLogin + resultData.id, + logoLogin, + resultData.company_name ); } if (favIcon) { await saveFavIcon( - result.data.data.id, - favIcon + resultData.id, + favIcon, + resultData.company_name ); } if(slider) { - const dataPack = packFiles(result.data.data.id,slider) + const dataPack = packFiles(resultData.id, slider, resultData.company_name) await saveSliderLogin(dataPack) } getDataCompany(); @@ -304,7 +334,6 @@ const MasterCompany = ({ params }) => { } const editCompany = async (data) => { - let urlEdit = COMPANY_MANAGEMENT_EDIT(data.id) const logoHeader = data.imageHeader; const logoLogin = data.imageLogin; @@ -321,7 +350,8 @@ const MasterCompany = ({ params }) => { ); await saveImageHeader( data.id, - logoHeader + logoHeader, + companyName ); } if (logoLogin) { @@ -330,7 +360,8 @@ const MasterCompany = ({ params }) => { ); await saveImageLogin( data.id, - logoLogin + logoLogin, + companyName ); } if (favIcon) { @@ -339,14 +370,15 @@ const MasterCompany = ({ params }) => { ); await saveFavIcon( data.id, - favIcon + favIcon, + companyName ); } if(slider) { await deleteImageSlider( data.id ); - const dataPack = packFiles(data.id,slider) + const dataPack = packFiles(data.id, slider, companyName) await saveSliderLogin(dataPack) } if (result && result.data && result.data.code === 200) { @@ -359,14 +391,12 @@ const MasterCompany = ({ params }) => { } } // Save Image Function - const saveImageHeader = async (id, data) => { + const saveImageHeader = async (id, data, company_name) => { const formData = new FormData; formData.append('ref_id', id); formData.append('category', 'company_logo_header'); formData.append('files', data); - if(role != 'Super Admin') { - formData.append('company_name',configApp.company_name); - } + formData.append('company_name', company_name); await axios .post(IMAGE_UPLOAD, formData, HEADER_MULTIPART) @@ -375,14 +405,12 @@ const MasterCompany = ({ params }) => { return "berhasil"; }; - const saveImageLogin = async (id, data) => { + const saveImageLogin = async (id, data, company_name) => { const formData = new FormData; formData.append('ref_id', id); formData.append('category', 'company_logo_login'); formData.append('files', data); - if(role != 'Super Admin') { - formData.append('company_name',configApp.company_name); - } + formData.append('company_name', company_name); await axios .post(IMAGE_UPLOAD, formData, HEADER_MULTIPART) @@ -391,14 +419,12 @@ const MasterCompany = ({ params }) => { return "berhasil"; }; - const saveFavIcon = async (id, data) => { + const saveFavIcon = async (id, data, company_name) => { const formData = new FormData; formData.append('ref_id', id); formData.append('category', 'company_favicon'); formData.append('files', data); - if(role != 'Super Admin') { - formData.append('company_name',configApp.company_name); - } + formData.append('company_name', company_name); await axios .post(IMAGE_UPLOAD, formData, HEADER_MULTIPART) @@ -408,7 +434,6 @@ const MasterCompany = ({ params }) => { }; const saveSliderLogin = async (data) => { - data.company_name = configApp.company_name; await axios .post(IMAGE_MULTIPLE_UPLOAD, data, HEADER_MULTIPART) .then(res => res) @@ -418,7 +443,7 @@ const MasterCompany = ({ params }) => { // Delete Image Function const deleteImageHeader = async (id) => { - const URL = IMAGE_DELETE(id, 'company_logo_header', company_id != '' ? company_id : 'undifined'); + const URL = IMAGE_DELETE(id, 'company_logo_header', companyID != '' ? companyID : 'undifined'); await axios .delete(URL, HEADER) .then(res => res) @@ -427,7 +452,7 @@ const MasterCompany = ({ params }) => { }; const deleteImageLogin = async (id) => { - const URL = IMAGE_DELETE(id, 'company_logo_login', company_id != '' ? company_id : 'undifined'); + const URL = IMAGE_DELETE(id, 'company_logo_login', companyID != '' ? companyID : 'undifined'); await axios .delete(URL, HEADER) .then(res => res) @@ -436,7 +461,7 @@ const MasterCompany = ({ params }) => { }; const deleteImageFavicon = async (id) => { - const URL = IMAGE_DELETE(id, 'company_favicon', company_id != '' ? company_id : 'undifined'); + const URL = IMAGE_DELETE(id, 'company_favicon', companyID != '' ? companyID : 'undifined'); await axios .delete(URL, HEADER) .then(res => res) @@ -445,7 +470,7 @@ const MasterCompany = ({ params }) => { }; const deleteImageSlider = async (id) => { - const URL = IMAGE_MULTIPLE_DELETE(id, 'company_slider_login', company_id != '' ? company_id : 'undifined'); + const URL = IMAGE_MULTIPLE_DELETE(id, 'company_slider_login', companyID != '' ? companyID : 'undifined'); await axios .delete(URL, HEADER) .then(res => res) @@ -458,18 +483,13 @@ const MasterCompany = ({ params }) => { } const onConfirmDelete = async () => { - let url = COMPANY_MANAGEMENT_DELETE(idDelete); - + const url = COMPANY_MANAGEMENT_DELETE(idDelete); const result = await axios.delete(url, config) .then(res => res) .catch((error) => error.response); if (result && result.data && result.data.code === 200) { getDataCompany() - deleteImageHeader(idDelete) - deleteImageLogin(idDelete) - deleteImageFavicon(idDelete) - deleteImageSlider(idDelete) setIdDelete(0) setAlertDelete(false) setLoading(false) @@ -498,7 +518,7 @@ const MasterCompany = ({ params }) => { - + @@ -554,6 +574,7 @@ const MasterCompany = ({ params }) => { imageFavIcon={imageFavIcon} imageSlider={imageSlider} imageLogin={imageLogin} + transaction={transaction} lastIdCompany={lastIdCompany} />