diff --git a/src/pages/LoginPage/Login.tsx b/src/pages/LoginPage/Login.tsx
index 3c3db1b..7f164c5 100644
--- a/src/pages/LoginPage/Login.tsx
+++ b/src/pages/LoginPage/Login.tsx
@@ -1,15 +1,13 @@
import './Login.sass'
-import { Logo, Link, Page, Row, Padding, Box, Radio, Combobox, Input, Button, Modal, Column } from '../../components'
+import { Logo, Link, Page, Row, Padding, Box, Radio, Combobox, Input, Button, Modal, Column, Display } from '../../components'
import { IoChevronBack } from 'solid-icons/io'
import { createSignal, Show, createEffect } from 'solid-js'
-import { ofetch } from 'ofetch'
import { SHA1, SHA3 } from 'crypto-js'
import { useNavigate } from '@solidjs/router'
-import { checkConnection } from '../../utils/functions'
+import { checkConnection, getApi } from '../../utils/functions'
import { _employeeId, _employeeName } from '../../stores/employee'
export default () => {
- const API = import.meta.env.VITE_BACKEND
const APPROVERNAME = import.meta.env.VITE_HEAD
const navigate = useNavigate()
const assessors = JSON.parse(sessionStorage.getItem('registered')!)
@@ -29,18 +27,18 @@ export default () => {
return
}
- const employeeid = await ofetch(API + 'get-employeeid/' + name(), { parseResponse: JSON.parse })
- const dbpassword = await ofetch(API + 'get-password/' + employeeid.result, { parseResponse: JSON.parse })
+ const employeeid = await getApi('get-employeeid', name())
+ const dbpassword = await getApi('get-password', employeeid)
const hashPassword = await securePassword()
- if (dbpassword.result === '0') {
+ if (dbpassword === '0') {
setErrorMessage('Not yet registered. Please proceed to Registration.')
} else {
setErrorMessage('Invalid Password, Try again.')
}
- if (dbpassword.result === hashPassword) {
- _employeeId.set(employeeid.result)
+ if (dbpassword === hashPassword) {
+ _employeeId.set(employeeid)
_employeeName.set(name())
saveEmployee()
setLoggedin(2)
@@ -83,83 +81,83 @@ export default () => {
return (
<>
-
-
-
-
-
- OCBO e-Sign
-
-
-
-
-
-
- Back
-
-
-
-
-
-
-
- {/* */}
-
+
+
+
+ Back
+
+
+
+
+
+
+
+ Login
+
+
+
+
+
+
+
+ Name
+
+
+
+
+ {APPROVERNAME}
+
+ Password
+ {
+ if (event.key === 'Enter') login()
+ }}
+ />
+
+
+
+
+
+
+
+
+
+
+ Required password
+
+
+
+
+
+ Required name and password
+
+
+
+
+
+ Required name
+
+
+
+
+
+
-
+
diff --git a/src/pages/MainPage/Main.tsx b/src/pages/MainPage/Main.tsx
index 69e161e..afd92e8 100644
--- a/src/pages/MainPage/Main.tsx
+++ b/src/pages/MainPage/Main.tsx
@@ -5,7 +5,7 @@ import { Tabs } from '@kobalte/core/tabs'
import { ofetch } from 'ofetch'
import { onMount, createSignal } from 'solid-js'
import dayjs from 'dayjs'
-import { checkConnection, createPdf } from '../../utils/functions'
+import { checkConnection, getApi, getApiMulti } from '../../utils/functions'
import { FaSolidThumbsUp } from 'solid-icons/fa'
import { _employeeName } from '../../stores/employee'
import { useNavigate } from '@solidjs/router'
@@ -51,22 +51,18 @@ export default () => {
const [employeeName, setEmployeeName] = createSignal('')
const getListForApproval = async () => {
- try {
- const responseE = await ofetch(API + 'get-listopapproval-electrical', { parseResponse: JSON.parse })
- setApplicationListElectrical(responseE.result)
- setNameListElectrical(responseE.result2)
+ const responseE = await getApiMulti('get-listopapproval-electrical')
+ setApplicationListElectrical(responseE.result)
+ setNameListElectrical(responseE.result2)
- const responseO = await ofetch(API + 'get-listopapproval-occupancy', { parseResponse: JSON.parse })
- setApplicationListOccupancy(responseO.result)
- setNameListOccupancy(responseO.result2)
- } catch (error) {
- console.error(error)
- }
+ const responseO = await getApiMulti('get-listopapproval-occupancy')
+ setApplicationListOccupancy(responseO.result)
+ setNameListOccupancy(responseO.result2)
}
const getListForApprovalElectrical = async () => {
try {
- const responseE = await ofetch(API + 'get-listopapproval-electrical', { parseResponse: JSON.parse })
+ const responseE = await getApiMulti('get-listopapproval-electrical')
setApplicationListElectrical(responseE.result)
setNameListElectrical(responseE.result2)
} catch (error) {
@@ -76,7 +72,7 @@ export default () => {
const getListForApprovalOccupancy = async () => {
try {
- const responseO = await ofetch(API + 'get-listopapproval-occupancy', { parseResponse: JSON.parse })
+ const responseO = await getApiMulti('get-listopapproval-occupancy')
setApplicationListOccupancy(responseO.result)
setNameListOccupancy(responseO.result2)
} catch (error) {
@@ -103,7 +99,7 @@ export default () => {
const getopdetails = async (division: string, applicationNo: string) => {
if (division === 'electrical') {
- const op = await ofetch(API + 'get-opdetails-electrical/' + applicationNo, { parseResponse: JSON.parse })
+ const op = await getApiMulti('get-opdetails-electrical', applicationNo)
setAssessor(op.result7[0])
setLocation(op.result5[0])
setType(op.result6[0])
@@ -111,7 +107,7 @@ export default () => {
setApplicationId(op.result11[0])
setTotalOp(calculateTotal(op.result9))
} else if (division === 'occupancy') {
- const op = await ofetch(API + 'get-opdetails-occupancy/' + applicationNo, { parseResponse: JSON.parse })
+ const op = await getApiMulti('get-opdetails-occupancy', applicationNo)
setAssessor(op.result7[0])
setLocation(op.result5[0])
setType(op.result6[0])
@@ -126,7 +122,36 @@ export default () => {
return total
}
- const approveHandler = async (application: string) => {
+ // const approveHandler = async (application: string) => {
+ // let signed: boolean = false
+ // let forprinting: boolean = false
+ // let updateOrderofpayment: boolean = false
+
+ // setConnected(await checkConnection())
+ // if (connected() === false) {
+ // setErrorMessage('No Connection on Server')
+ // return
+ // }
+
+ // signed = await setNewStatus('ELECTRICAL ORDER OF PAYMENT APPROVED AND SIGNED', '170', 'ELECOPAPPROVEDSIGNED', 1)
+ // const approvedid = await getIdByApplication(application)
+ // updateDocflow(approvedid, 'FOR ELECTRICAL ORDER OF PAYMENT APPROVAL')
+ // if (!signed) return
+
+ // forprinting = await setNewStatus('FOR ELECTRICAL ORDER OF PAYMENT PRINTING', '95', 'ELECOPPRINT', 0)
+ // if (!forprinting) return
+
+ // updateOrderofpayment = await updateOp()
+
+ // if (updateOrderofpayment) {
+ // postTransaction()
+ // postPops(application)
+ // setApprovedApplication(application)
+ // setApproved(true)
+ // }
+ // }
+
+ const approveHandler = async (division: string, application: string) => {
let signed: boolean = false
let forprinting: boolean = false
let updateOrderofpayment: boolean = false
@@ -137,21 +162,33 @@ export default () => {
return
}
- signed = await setNewStatus('ELECTRICAL ORDER OF PAYMENT APPROVED AND SIGNED', '170', 'ELECOPAPPROVEDSIGNED', 1)
- const approvedid = await getIdByApplication(application)
- updateDocflow(approvedid, 'FOR ELECTRICAL ORDER OF PAYMENT APPROVAL')
- if (!signed) return
+ if (division === 'electrical') {
+ signed = await setNewStatus('ELECTRICAL ORDER OF PAYMENT APPROVED AND SIGNED', '170', 'ELECOPAPPROVEDSIGNED', 1)
+ const approvedid = await getIdByApplication(application)
+ updateDocflow(approvedid, 'FOR ELECTRICAL ORDER OF PAYMENT APPROVAL')
+ if (!signed) return
- forprinting = await setNewStatus('FOR ELECTRICAL ORDER OF PAYMENT PRINTING', '95', 'ELECOPPRINT', 0)
- if (!forprinting) return
+ forprinting = await setNewStatus('FOR ELECTRICAL ORDER OF PAYMENT PRINTING', '95', 'ELECOPPRINT', 0)
+ if (!forprinting) return
- updateOrderofpayment = await updateOp()
+ updateOrderofpayment = await updateOp()
- if (updateOrderofpayment) {
- postTransaction()
- postPops(application)
- setApprovedApplication(application)
- setApproved(true)
+ if (updateOrderofpayment) {
+ postTransaction()
+ postPops(division, application)
+ setApprovedApplication(application)
+ setApproved(true)
+ }
+ } else if (division === 'occupancy') {
+ signed = await setNewStatus('OCCUPANCY ORDER OF PAYMENT APPROVED AND SIGNED', '172', 'OCCOPAPPROVEDSIGNED', 1)
+ const approvedid = await getIdByApplication(application)
+ updateDocflow(approvedid, 'FOR OCCUPANCY RECOMMENDING APPROVAL')
+ if (!signed) return
+
+ forprinting = await setNewStatus('APPROVED FOR PRINTING OF BUREAU OF FIRE AND ORDER OF PAYMENT', '23', 'OCORDEROFPAYMENT', 0)
+ if (!forprinting) return
+
+ updateOrderofpayment = await updateOp()
}
}
@@ -202,10 +239,15 @@ export default () => {
// _assessorid.set(employeeId())
// }
- const postPops = async (application: string) => {
- const applicationId = await ofetch(API + 'get-idbyapplication-electrical/' + application, { parseResponse: JSON.parse })
- const response = await ofetch(API + 'get-popsdetails-electrical/' + applicationId.result, { parseResponse: JSON.parse })
- // const applicationNo = response.result[0]
+ const postPops = async (division: string, application: string) => {
+ let response
+
+ if (division === 'electrical') {
+ response = await getApiMulti('get-popsdetails-electrical', application)
+ } else if (division === 'occupancy') {
+ response = await getApiMulti('get-popsdetails-occupancy', application)
+ }
+
const customerid = response.result2[0]
const customerName = response.result3[0]
const location = response.result4[0]
@@ -278,9 +320,8 @@ export default () => {
const geteSignId = async () => {
try {
- const response = await ofetch(API + 'get-esignid/' + ID, { parseResponse: JSON.parse })
- const result = response.result
- return result
+ const response = await getApi('get-esignid', ID)
+ return response
} catch {
return 0
}
@@ -290,6 +331,7 @@ export default () => {
const id = await geteSignId()
const today = new Date()
const formatedDate = dayjs(today).format('YYYY-MM-DD HH:mm:ss')
+
await ofetch(API + 'post-esigntransaction', {
method: 'POST',
body: { data: parseInt(id), data2: approvedApplication(), data3: formatedDate },
@@ -305,9 +347,8 @@ export default () => {
const getIdByApplication = async (applicationNo: string) => {
try {
- const response = await ofetch(API + 'get-idbyapplication-electrical/' + applicationNo, { parseResponse: JSON.parse })
- const result = response.result
- return parseInt(result)
+ const response = await getApi('get-idbyapplication-electrical', applicationNo)
+ return parseInt(response)
} catch {
return 0
}
@@ -473,7 +514,7 @@ export default () => {
-
+
Click anywhere to cancel
@@ -560,7 +601,7 @@ export default () => {
-
+
Click anywhere to cancel
diff --git a/src/pages/RegisterPage/Register.tsx b/src/pages/RegisterPage/Register.tsx
index 4d0d6b3..30244eb 100644
--- a/src/pages/RegisterPage/Register.tsx
+++ b/src/pages/RegisterPage/Register.tsx
@@ -1,5 +1,5 @@
import './Register.sass'
-import { Logo, Link, Page, Row, Padding, Combobox, Box, Button, Modal, Column, QR, Input } from '../../components'
+import { Logo, Link, Page, Row, Padding, Combobox, Box, Button, Modal, Column, QR, Input, Display } from '../../components'
import { IoChevronBack } from 'solid-icons/io'
import { Show, createSignal, createEffect } from 'solid-js'
import { ofetch } from 'ofetch'
@@ -7,6 +7,7 @@ import { SHA3, SHA1 } from 'crypto-js'
import dayjs from 'dayjs'
import { FileField } from '@kobalte/core/file-field'
import { useNavigate } from '@solidjs/router'
+import { checkConnection, getApi } from '../../utils/functions'
export default () => {
const API = import.meta.env.VITE_BACKEND
@@ -19,31 +20,30 @@ export default () => {
const [role, setRole] = createSignal('')
const [name, setName] = createSignal('')
const [password, setPassword] = createSignal('')
- const [hashPassword, setHashPassword] = createSignal('')
- const [id, setId] = createSignal
(0)
const [signature, setSignature] = createSignal('')
const [saved, setSaved] = createSignal(false)
const [file, setFile] = createSignal()
const [base64image, setBase64image] = createSignal('')
const [allow, setAllow] = createSignal(0)
+ const [connected, setConnected] = createSignal(true)
+ const [errorMessage, setErrorMessage] = createSignal('')
+
+ let globalId = 0
+ let globalHashPassword = ''
const getEmployeeId = async (val: string) => {
- try {
- setName(val)
- const id = await ofetch(API + 'get-employeeid/' + val, { parseResponse: JSON.parse })
- setId(parseInt(id.result))
- await checkRegistered()
- } catch {
- setId(0)
- }
+ setName(val)
+ const id = await getApi('get-employeeid', val)
+ globalId = parseInt(id)
+ await checkRegistered(val)
}
const generateSignature = () => {
if (role() === 'APPROVER') {
- setId(276)
+ globalId = 276
setName(APPROVERNAME)
}
- const hash = SHA3(id().toString())
+ const hash = SHA3(globalId.toString())
setSignature(`Use OCBO e-Sign Validator - scanid=${hash.toString()}`)
try {
@@ -56,6 +56,12 @@ export default () => {
}
const register = async () => {
+ setConnected(await checkConnection())
+ if (connected() === false) {
+ setErrorMessage('No Connection on Server')
+ return
+ }
+
await securePassword()
const blob = new Blob(file())
const base64 = await convertBase64(blob)
@@ -63,7 +69,7 @@ export default () => {
await ofetch(API + 'post-registration', {
method: 'POST',
- body: { data: id(), data2: hashPassword(), data3: signature(), data4: base64 },
+ body: { data: globalId, data2: globalHashPassword, data3: signature(), data4: base64 },
})
}
@@ -77,7 +83,7 @@ export default () => {
const firstHashing = SHA1(password())
const secondHashing = SHA3(firstHashing)
const thirdHashing = SHA1(secondHashing)
- setHashPassword(thirdHashing.toString())
+ globalHashPassword = thirdHashing.toString()
}
const convertBase64 = (blob: Blob) => {
@@ -88,12 +94,10 @@ export default () => {
})
}
- const checkRegistered = async () => {
- const employeeid = id()
-
+ const checkRegistered = async (name: string) => {
try {
- const registered = await ofetch(API + 'check-registered/' + employeeid, { parseResponse: JSON.parse })
- if (registered.result > 0) {
+ const registered = await getApi('check-registered', name)
+ if (registered > 0) {
setAllow(1)
} else {
setAllow(2)
@@ -106,13 +110,9 @@ export default () => {
const getAssessors = async (): Promise => {
let assessorsNameList: string[] = []
- try {
- const assessors = await ofetch(API + 'get-list-assessors', { parseResponse: JSON.parse })
- assessorsNameList = [...assessors.result]
- return [...assessorsNameList]
- } catch {
- return []
- }
+ const assessors = await getApi('get-list-assessors')
+ assessorsNameList = [...assessors]
+ return [...assessorsNameList]
}
const updateRegistered = async () => {
@@ -127,8 +127,8 @@ export default () => {
createEffect(async () => {
if (role() === 'APPROVER') {
try {
- const registered = await ofetch(API + 'check-registered/' + 276, { parseResponse: JSON.parse })
- if (registered.result > 0) {
+ const registered = await getApi('check-registered', APPROVERNAME)
+ if (registered > 0) {
setAllow(1)
} else {
setAllow(2)
@@ -142,166 +142,168 @@ export default () => {
return (
<>
-
-
-
-
-
- OCBO e-Sign
-
-
-
-
-
-
- Back
-
-
-
-
-
-
-
-
- Registration
+
+
+
+
+
+
+ OCBO e-Sign
- Role
-
+
-
- List of Assessors
- getEmployeeId(val!)} />
+
+
+
+ Back
+
+
+
+
+
+
+
+
+ Registration
+
+ Role
+
+
+
+ List of Assessors
+ getEmployeeId(val!)} />
+
+
+ Password
+
+ Upload Signature
+ setFile(data)} accept=".jpg, .jpeg, .png, .webp, .avif">
+ Drag and drop or click to upload file
+
+
+ {() => (
+
+
+
+
+ setFile()}>
+ Delete
+
+
+ )}
+
+
+
+
+
+ = 4}>
+
+
+
+
+
+
+
+ Password too short
+
+
+
+
+
+
+ Required password and signature
+
+
+
+
+
+ Required password
+
+
+
+
+
+ Required signature
+
+
+
+
+
+
+
+
+ Already Registered
+
+
+
+
+
+
+ Name of Approver
+ {APPROVERNAME}
-
Password
- Upload Signature
- setFile(data)} accept=".jpg, .jpeg, .png, .webp, .avif">
- Drag and drop or click to upload file
-
-
- {() => (
-
-
-
-
- setFile()}>
- Delete
-
-
- )}
-
-
-
-
- = 4}>
+
+ Upload Signature
+ setFile(data)} accept=".png">
+ Drag and drop or click to upload file
+
+
+ {() => (
+
+
+
+
+ setFile()}>
+ Delete
+
+
+ )}
+
+
+
+
+
-
+
- Password too short
+ Required password
-
-
-
- Required password and signature
-
-
+
+
+ Required signature
+
+
-
-
- Required password
-
-
+
+
+ Required password and signature
+
+
+
+
-
+
+
- Required signature
+ Already Registered
-
-
+
+
-
-
-
-
- Already Registered
-
-
-
-
-
-
- Name of Approver
- {APPROVERNAME}
-
- Password
-
-
-
- Upload Signature
- setFile(data)} accept=".png">
- Drag and drop or click to upload file
-
-
- {() => (
-
-
-
-
- setFile()}>
- Delete
-
-
- )}
-
-
-
-
-
-
-
-
-
-
-
-
- Required password
-
-
-
-
-
- Required signature
-
-
-
-
-
- Required password and signature
-
-
-
-
-
-
-
-
- Already Registered
-
-
-
-
-
-
+
+
+
-
+
@@ -336,6 +338,28 @@ export default () => {
+
+ setConnected(true)}>
+
+
+
+
+
+ Connection Error
+
+
+
+
+ {errorMessage()}
+
+
+
+ Click anywhere to close
+
+
+
+
+
>
)
}