diff --git a/src/pages/MainPage/Main.sass b/src/pages/MainPage/Main.sass index e97fdbd..4855d51 100644 --- a/src/pages/MainPage/Main.sass +++ b/src/pages/MainPage/Main.sass @@ -113,3 +113,13 @@ h1 &__error color: #c85656 + +.loading-spinner + display: inline-block + animation: rotate 2s linear infinite + +@keyframes rotate + from + transform: rotate(0deg) + to + transform: rotate(360deg) \ No newline at end of file diff --git a/src/pages/MainPage/Main.tsx b/src/pages/MainPage/Main.tsx index 7216bd6..7bbb492 100644 --- a/src/pages/MainPage/Main.tsx +++ b/src/pages/MainPage/Main.tsx @@ -7,12 +7,14 @@ import { VsRefresh } from 'solid-icons/vs' 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 { checkConnection, deleteApi, getApi, getApiMulti, getDateTime, lockData, postApi, saveNewName, saveNewPassword, securePassword, voidPopsApi, voidApi, statusPopsApi } from '../../utils/functions' +import { AiOutlineLoading3Quarters } from 'solid-icons/ai' import './Main.sass' const PESO = import.meta.env.VITE_PESO const ID = sessionStorage.getItem('id')! const PUBLICIP = import.meta.env.VITE_PUBLICIP +const BACKEND = import.meta.env.VITE_BACKEND export default () => { const navigate = useNavigate() @@ -59,6 +61,7 @@ export default () => { const [configNotification, setConfigNotification] = createSignal(false) const [isIncomplete, setIsIncomplete] = createSignal(false) + const [isLoading, setIsLoading] = createSignal(false) let bldgadditional = false @@ -73,15 +76,19 @@ export default () => { } const getListForApprovalElectrical = async () => { + // setIsLoading(true) const responseE = await getApiMulti('get-listopapproval-electrical') setApplicationListElectrical(responseE.result) setNameListElectrical(responseE.result2) + // setIsLoading(false) } const getListForApprovalOccupancy = async () => { + // setIsLoading(true) const responseO = await getApiMulti('get-listopapproval-occupancy') setApplicationListOccupancy(responseO.result) setNameListOccupancy(responseO.result2) + // setIsLoading(false) } const load = async (division: string) => { @@ -90,6 +97,7 @@ export default () => { setErrorMessage('Could not gather list of applications') return } + setIsLoading(true) await getPassword() @@ -101,6 +109,7 @@ export default () => { } else { await getListForApproval() } + setIsLoading(false) } const getopdetails = async (division: string, applicationNo: string) => { @@ -148,6 +157,9 @@ export default () => { let forprinting: boolean = false let updateOrderofpayment: boolean = false + let popsExist: boolean = false + let popsPaid: boolean = false + setConnected(await checkConnection()) if (connected() === false) { setErrorMessage('No Connection on Server') @@ -155,7 +167,35 @@ export default () => { } if (division === 'electrical') { - await voidPopsOp(application) + // const isPaid = BACKEND.includes('localhost') ? await checkStatusPopsLocal(application) : await statusPopsOp(application) + // let isPaid + + if (BACKEND.includes('localhost')) { + const status = await checkStatusPopsLocal(application) + if (status.result > 0) popsExist = true + if (status.result2 > 0) popsPaid = true + } else { + const status = await await statusPopsOp(application) + if (status.message === 'Success') popsExist = true + if (status.pops_paid === true) popsPaid = true + } + + if (popsExist) { + if (popsPaid) { + setPostError(true) + setErrorMessage('Application Already Paid') + return + } else { + const voidOP = BACKEND.includes('localhost') ? await voidPopsOpLocal(application) : await voidPopsOp(application) + + if (!voidOP) { + setPostError(true) + setErrorMessage('POPS Record found but failed to void') + return + } + } + } + await postPops(division, application) const popsResult = await checkPops(application) const lockResult = await lockOpData(division, application) @@ -216,6 +256,37 @@ export default () => { } } + const approveElectrical = async (division: string, application: string) => { + let signed: boolean = false + let forprinting: boolean = false + let updateOrderofpayment: boolean = false + + await postPops(division, application) + const popsResult = await checkPops(application) + const lockResult = await lockOpData(division, application) + + 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 + + forprinting = await setNewStatus(division, 'FOR ELECTRICAL ORDER OF PAYMENT PRINTING', '95', 'ELECOPPRINT', 0) + if (!forprinting) return + + updateOrderofpayment = await updateOp(division) + + if (updateOrderofpayment) { + postTransaction() + setApprovedApplication(application) + setApproved(true) + } + } else { + setPostError(true) + setErrorMessage('Error on posting on POPS Server, please try again') + return + } + } + const lockOpData = async (division: string, application: string) => { const dataToLock = await getApi(`get-opdata-${division}`, application) const lockedData = await lockData(dataToLock) @@ -230,6 +301,21 @@ export default () => { return true } + const voidPopsOpLocal = async (application: string) => { + const response = await voidApi('void-op-local', { data: application }) + return response + } + + const checkStatusPopsLocal = async (application: string) => { + const response = await getApiMulti('check-statuspops-local', application) + return response + } + + const statusPopsOp = async (application: string) => { + const response = await statusPopsApi(application) + return response + } + const returnAssessment = async (division: string, application: string) => { const id = await getApplicationById(division, application) setApplicationId(id) @@ -680,107 +766,117 @@ export default () => { - - - - - - - - - - {applicationListElectrical().map((item: string, index: number) => ( + + + + + Downloading Data + + + + +
Application NumberNameShow Details
+ - - - - + + + - ))} - -
{item}{nameListElectrical()[index]} - { - await getopdetails('electrical', item) - }} - > - - - {item} - - - - -

Signing Error

-
-

Missing Data Detected

-
- -
- - Some required information is missing from the application details - Please return to Assessment to complete the required fields - -
-
- -
Application NumberNameShow Details
+ + + {applicationListElectrical().map((item: string, index: number) => ( + + {item} + {nameListElectrical()[index]} + + + { + await getopdetails('electrical', item) + }} + > + + + {item} + + + + +

Signing Error

+
+

Missing Data Detected

+
+ +
+ + Some required information is missing from the application details + Please return to Assessment to complete the required fields + +
+
+ +