diff --git a/src/pages/MainPage/Main.sass b/src/pages/MainPage/Main.sass index 14ce5d9..e97fdbd 100644 --- a/src/pages/MainPage/Main.sass +++ b/src/pages/MainPage/Main.sass @@ -102,3 +102,14 @@ h1 opacity: 0.6 text-align: center margin: 1rem 0 -0.75rem 0 + +.incomplete + padding: 0.5rem 0 0.5rem 0 + + &__text + padding: 0 0 0.25rem 0 + color: #c85656 + + &__error + color: #c85656 + diff --git a/src/pages/MainPage/Main.tsx b/src/pages/MainPage/Main.tsx index 85f52fb..7216bd6 100644 --- a/src/pages/MainPage/Main.tsx +++ b/src/pages/MainPage/Main.tsx @@ -1,14 +1,13 @@ import { Tabs } from '@kobalte/core/tabs' import { useNavigate } from '@solidjs/router' import dayjs from 'dayjs' -import { FaSolidThumbsUp } from 'solid-icons/fa' +import { FaSolidThumbsUp, FaSolidUserGear } from 'solid-icons/fa' import { FiLogOut } from 'solid-icons/fi' import { VsRefresh } from 'solid-icons/vs' -import { createSignal, onMount, createEffect } from 'solid-js' -import { Box, Button, Clickable, Column, Link, Logo, Modal, ModalButton, Padding, Page, Row, Input } from '../../components/' -import { checkConnection, getApi, getApiMulti, getDateTime, postApi, saveNewName, saveNewPassword, securePassword } from '../../utils/functions' -import { FaSolidUserGear } from 'solid-icons/fa' +import { createEffect, createSignal, onMount } from 'solid-js' import { Show } from 'solid-js/web' +import { Box, Button, Clickable, Column, Input, Link, Logo, Modal, ModalButton, Padding, Page, Row } from '../../components/' +import { checkConnection, deleteApi, getApi, getApiMulti, getDateTime, lockData, postApi, saveNewName, saveNewPassword, securePassword, voidPopsApi } from '../../utils/functions' import './Main.sass' const PESO = import.meta.env.VITE_PESO @@ -131,7 +130,7 @@ export default () => { } const isDetailsComplete = (result: string[], result2: string[], result3: string[], result4: string[], result5: string[], result6: string[]) => { - return result.length > 0 && result2.length > 0 && result3.length > 0 && result4.length > 0 && result5.length > 0 && result6.length > 0 ? false : false + return result.length > 0 && result2.length > 0 && result3.length > 0 && result4.length > 0 && result5.length > 0 && result6.length > 0 ? true : false } const calculateTotal = (list: number[]) => { @@ -139,6 +138,11 @@ export default () => { return total } + // const sample = async () => { + // const data = await lockData('asdasdsadsad') + // console.log(data) + // } + const approveHandler = async (division: string, application: string) => { let signed: boolean = false let forprinting: boolean = false @@ -151,10 +155,12 @@ export default () => { } if (division === 'electrical') { + await voidPopsOp(application) await postPops(division, application) const popsResult = await checkPops(application) + const lockResult = await lockOpData(division, application) - if (popsResult) { + if (popsResult && lockResult) { signed = await setNewStatus(division, 'ELECTRICAL ORDER OF PAYMENT APPROVED AND SIGNED', '170', 'ELECOPAPPROVEDSIGNED', 1) updateDocflow(division, application, 'FOR ELECTRICAL ORDER OF PAYMENT APPROVAL') if (!signed) return @@ -174,17 +180,16 @@ export default () => { setErrorMessage('Error on posting on POPS Server, please try again') return } - } else if (division === 'occupancy') { const additionalResult = await getApi('check-bldgadditional-approval', application) bldgadditional = additionalResult > 0 + await voidPopsOp(application) await postPops(division, application) const popsResult = await checkPops(application) + const lockResult = await lockOpData(division, application) - console.log('popsResult', popsResult) - - if (popsResult) { + if (popsResult && lockResult) { signed = await setNewStatus(division, 'OCCUPANCY ORDER OF PAYMENT APPROVED AND SIGNED', '172', 'OCCOPAPPROVEDSIGNED', 1) updateDocflow(division, application, 'FOR OCCUPANCY RECOMMENDING APPROVAL') if (bldgadditional) { @@ -211,6 +216,54 @@ export default () => { } } + const lockOpData = async (division: string, application: string) => { + const dataToLock = await getApi(`get-opdata-${division}`, application) + const lockedData = await lockData(dataToLock) + const fixedLockedData = lockedData.replace(/\//g, '~') + const saveLockedData = await postApi('save-lockdata', { data: application, data2: fixedLockedData }) + return saveLockedData + } + + const voidPopsOp = async (application: string) => { + const response = await voidPopsApi(application) + if (response.includes('Error')) return false + return true + } + + const returnAssessment = async (division: string, application: string) => { + const id = await getApplicationById(division, application) + setApplicationId(id) + let forassessment + + if (division === 'electrical') { + forassessment = await setNewStatus(division, 'FOR ELECTRICAL ASSESSMENT', '88', 'ELECASSESSMENT', 0) + } else { + forassessment = await setNewStatus(division, 'OCCUPANCY ASSESSMENT', '21', 'OCASSESSMENT', 0) + } + if (!forassessment) return + + if (division === 'electrical') { + updateDocflow(division, application, 'FOR ELECTRICAL ORDER OF PAYMENT APPROVAL') + } else { + updateDocflow(division, application, 'FOR OCCUPANCY RECOMMENDING APPROVAL') + } + + await deleteOrderofPayment(division, id) + await load('all') + } + + const getApplicationById = async (division: string, application: string) => { + const id = await getApi(`get-idbyapplication-${division}`, application) + return parseInt(id) + } + + const deleteOrderofPayment = async (division: string, id: number) => { + const deleteOp = await deleteApi(`delete-orderofpayment-${division}`, { + data: id, + }) + return deleteOp + } + const setNewStatus = async (division: string, status: string, tag: string, tagword: string, approved: number) => { // const today = new Date() const today = await getDateTime() @@ -334,9 +387,9 @@ export default () => { const postTransaction = async () => { const id = await geteSignId() const today = await getDateTime() - const formatedDate = dayjs(today).format('YYYY-MM-DD HH:mm:ss') + const formattedDate = dayjs(today).format('YYYY-MM-DD HH:mm:ss') - await postApi('post-esigntransaction', { data: parseInt(id), data2: approvedApplication(), data3: formatedDate }) + await postApi('post-esigntransaction', { data: parseInt(id), data2: approvedApplication(), data3: formattedDate }) } const updateDocflow = async (division: string, application: string, status: string) => { @@ -375,7 +428,6 @@ export default () => { setConfigError('') encryptNewPassword() } - } else { setConfigError('Invalid Password') setConfigNewEncPassword('') @@ -404,7 +456,7 @@ export default () => { // const saveNewPassword = async (password: string) => { // await postApi('update-password', { // data: parseInt(ID), - // data2: password + // data2: password // }) // } @@ -653,48 +705,76 @@ export default () => { await getopdetails('electrical', item) }} > - - {item} + + + {item} - - - Name of Applicant: - {nameListElectrical()[index]} - + + + + Signing Error + + Missing Data Detected + - - Location: - {location()} - - - - Type: - {type().toUpperCase()} - - - - Assessed By: - {assessor()} - - - - Date Assessed: - {dateOp().toUpperCase()} - - - - Total Fee: - - {PESO} {totalOp()} - - + + + Some required information is missing from the application details + Please return to Assessment to complete the required fields + + + + + returnAssessment('electrical', item)} /> + Click anywhere to cancel + + - - approveHandler('electrical', item)}> - Click anywhere to cancel - - + + + {item} + + + + Name of Applicant: + {nameListElectrical()[index]} + + + + Location: + {location()} + + + + Type: + {type().toUpperCase()} + + + + Assessed By: + {assessor()} + + + + Date Assessed: + {dateOp().toUpperCase()} + + + + Total Fee: + + {PESO} {totalOp()} + + + + + + approveHandler('electrical', item)} /> + Click anywhere to cancel + + + @@ -774,24 +854,24 @@ export default () => { - + - - + + Name: {employeeName()} - - Change Displayed Name - - Leave blank to remain unchanged. + + Change Displayed Name + + Leave blank to remain unchanged. - - Change Password - - + + Change Password + + Current Encrypted Password: @@ -804,18 +884,18 @@ export default () => { {configError()} - setOpenConfig(false)} wide /> + setOpenConfig(false)} wide /> - + - - setOpenConfig(false)} wide /> + + setOpenConfig(false)} wide /> - + @@ -832,7 +912,7 @@ export default () => { - + setPostError(false)}> @@ -856,32 +936,6 @@ export default () => { - - setIsIncomplete(false)}> - - - - - - Incomplete Data - - - - - Some Data were missing - - - - To avoid further error, application will be automatically pushed back on Assessment for correction - - - - Click anywhere to close - - - - - > ) }