import { Tabs } from '@kobalte/core/tabs' import { useNavigate } from '@solidjs/router' import dayjs from 'dayjs' import { BiRegularErrorAlt } from 'solid-icons/bi' import { FaSolidThumbsUp } 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, postApi, saveNewName, saveNewPassword, securePassword } from '../../utils/functions' import { FaSolidUserGear } from 'solid-icons/fa' import { Show } from 'solid-js/web' import './Main.sass' const PESO = import.meta.env.VITE_PESO const ID = import.meta.env.VITE_HEADID // const NAME = import.meta.env.VITE_HEAD const PUBLICIP = import.meta.env.VITE_PUBLICIP export default () => { const navigate = useNavigate() const [totalOp, setTotalOp] = createSignal('') const [assessor, setAssessor] = createSignal('') const [dateOp, setDateOp] = createSignal('') const [location, setLocation] = createSignal('') const [type, setType] = createSignal('') const [applicationId, setApplicationId] = createSignal(0) // const [assessorId, setAssessorId] = createSignal(0) // const [gflgu, setGflgu] = createSignal([]) // const [gfdpwh, setGfdpwh] = createSignal([]) // const [tfbo, setTfbo] = createSignal([]) // const [descriptionList, setDescriptionList] = createSignal([]) // const [amountList, setAmountList] = createSignal([]) // const [dateOpList, setDateOpList] = createSignal([]) const [applicationListElectrical, setApplicationListElectrical] = createSignal([]) const [nameListElectrical, setNameListElectrical] = createSignal([]) const [applicationListOccupancy, setApplicationListOccupancy] = createSignal([]) const [nameListOccupancy, setNameListOccupancy] = createSignal([]) const [errorMessage, setErrorMessage] = createSignal('') const [connected, setConnected] = createSignal(true) const [approved, setApproved] = createSignal(false) const [approvedApplication, setApprovedApplication] = createSignal('') const [employeeId, setEmployeeId] = createSignal(0) const [employeeName, setEmployeeName] = createSignal('') const [apology, setApology] = createSignal(false) const [openConfig, setOpenConfig] = createSignal(false) const [configEncPassword, setConfigEncPassword] = createSignal('') const [configNewName, setConfigNewName] = createSignal('') const [configPassword, setConfigPassword] = createSignal('') const [configNewPassword, setConfigNewPassword] = createSignal('') const [configNewEncPassword, setConfigNewEncPassword] = createSignal('') const [configError, setConfigError] = createSignal('') const [configNotification, setConfigNotification] = createSignal(false) let bldgadditional = false const getListForApproval = async () => { const responseE = await getApiMulti('get-listopapproval-electrical') setApplicationListElectrical(responseE.result) setNameListElectrical(responseE.result2) const responseO = await getApiMulti('get-listopapproval-occupancy') setApplicationListOccupancy(responseO.result) setNameListOccupancy(responseO.result2) } const getListForApprovalElectrical = async () => { const responseE = await getApiMulti('get-listopapproval-electrical') setApplicationListElectrical(responseE.result) setNameListElectrical(responseE.result2) } const getListForApprovalOccupancy = async () => { const responseO = await getApiMulti('get-listopapproval-occupancy') setApplicationListOccupancy(responseO.result) setNameListOccupancy(responseO.result2) } const load = async (division: string) => { setConnected(await checkConnection()) if (connected() === false) { setErrorMessage('Could not gather list of applications') return } await getPassword() if (division === 'electrical') { await getListForApprovalElectrical() } if (division === 'occupancy') { await getListForApprovalOccupancy() } else { await getListForApproval() } } const getopdetails = async (division: string, applicationNo: string) => { let op if (division === 'electrical') { op = await getApiMulti('get-opdetails-electrical', applicationNo) } else if (division === 'occupancy') { op = await getApiMulti('get-opdetails-occupancy', applicationNo) } setLocation(op.result[0]) setType(op.result2[0]) setAssessor(op.result3[0]) const total = calculateTotal(op.result4) const formattedTotal = new Intl.NumberFormat('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2, }).format(total) setTotalOp(formattedTotal) setDateOp(dayjs(op.result5[0]).format('MMMM DD, YYYY')) setApplicationId(op.result6[0]) } const calculateTotal = (list: number[]) => { const total = list.map((item) => parseFloat(item.toString())).reduce((acc, curr) => acc + curr, 0) return total } const approveHandler = async (division: string, 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 } if (division === 'electrical') { 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() postPops(division, application) setApprovedApplication(application) setApproved(true) } } else if (division === 'occupancy') { const additionalResult = await getApi('check-bldgadditional-approval', application) bldgadditional = additionalResult > 0 signed = await setNewStatus(division, 'OCCUPANCY ORDER OF PAYMENT APPROVED AND SIGNED', '172', 'OCCOPAPPROVEDSIGNED', 1) updateDocflow(division, application, 'FOR OCCUPANCY RECOMMENDING APPROVAL') if (bldgadditional) { const neededToUpdate = await checkApproval(application, 'FOR ADDITIONAL ORDER OF PAYMENT RECOMMENDING APPROVAL') if (!neededToUpdate) updateDocflow(division, application, 'FOR ADDITIONAL ORDER OF PAYMENT RECOMMENDING APPROVAL') } if (!signed) return forprinting = await setNewStatus(division, 'APPROVED FOR PRINTING OF BUREAU OF FIRE AND ORDER OF PAYMENT', '23', 'OCORDEROFPAYMENT', 0) if (!forprinting) return updateOrderofpayment = await updateOp(division) if (updateOrderofpayment) { postTransaction() postPops(division, application) setApprovedApplication(application) setApproved(true) } } } const setNewStatus = async (division: string, status: string, tag: string, tagword: string, approved: number) => { const today = new Date() const formattedDate = dayjs(today).format('YYYY-MM-DD HH:mm:ss') const statusid = parseInt(applicationId().toString()) if (division === 'electrical') { return await postApi('post-newstatus-electrical', { data: statusid, data2: formattedDate, data3: status, data4: tag, data5: tagword, data6: parseInt(approved.toString()), data7: parseInt(ID) }) } else { return await postApi('post-newstatus-occupancy', { data: statusid, data2: formattedDate, data3: status, data4: tag, data5: tagword, data6: parseInt(approved.toString()), data7: parseInt(ID) }) } } const updateOp = async (division: string) => { if (division === 'electrical') { return await postApi('update-opapproved-electrical', { data: parseInt(applicationId().toString()) }) } else { const occupancy = await postApi('update-opapproved-occupancy', { data: parseInt(applicationId().toString()) }) if (bldgadditional) await postApi('update-opapproved-bldgadditional', { data: parseInt(applicationId().toString()) }) return occupancy } } 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] const amountList = response.result5 const lguList = response.result6 const dpwhList = response.result7 const boList = response.result8 const codeList = response.result9 const today = new Date() const formattedDate = dayjs(today).format('YYYY-MM-DD') const formattedDatewithTime = dayjs(today).format('YYYY-MM-DD HH:mm:ss') for (let i = 0; i < response.result.length; i++) { await postApi('post-pops', { data: application, data2: formattedDate, data3: customerid, data4: customerName, data5: location, data6: codeList[i], data7: amountList[i], data8: assessor(), data9: formattedDatewithTime, data10: lguList[i], data11: dpwhList[i], data12: boList[i], data13: PUBLICIP }) } } // const calculateAmounts = () => { // const amounts: string[] = amountList() // let gflguList: number[] = [] // let gfdpwhList: number[] = [] // let tfboList: number[] = [] // for (let i = 0; i < amounts.length; i++) { // const gflgu = parseFloat(amounts[i]) * 0.8 // const gfdpwh = parseFloat(amounts[i]) * 0.05 // const tfbo = parseFloat(amounts[i]) * 0.15 // const roundedGflgu = parseFloat(gflgu.toFixed(2)) // const roundedGfdpwh = parseFloat(gfdpwh.toFixed(2)) // const roundedTfbo = parseFloat(tfbo.toFixed(2)) // gflguList.push(roundedGflgu) // gfdpwhList.push(roundedGfdpwh) // tfboList.push(roundedTfbo) // } // setGflgu(gflguList) // setGfdpwh(gfdpwhList) // setTfbo(tfboList) // } const closeNotification = async () => { setApproved(false) await load('all') } const removeEmployee = () => { sessionStorage.removeItem('id') sessionStorage.removeItem('name') } const checkLogged = async () => { const idStore = sessionStorage.getItem('id') const nameStore = sessionStorage.getItem('name') setEmployeeId(parseInt(idStore!)) setEmployeeName(nameStore!) if (employeeId() === 0 || employeeId().toString() === 'NaN') { removeEmployee() navigate('/', { replace: true }) return false } return true } const geteSignId = async () => { try { const response = await getApi('get-esignid', ID) return response } catch { return 0 } } const postTransaction = async () => { const id = await geteSignId() const today = new Date() const formatedDate = dayjs(today).format('YYYY-MM-DD HH:mm:ss') await postApi('post-esigntransaction', { data: parseInt(id), data2: approvedApplication(), data3: formatedDate }) } const updateDocflow = async (division: string, application: string, status: string) => { await postApi(`update-docflow-${division}`, { data: status, data2: application }) } const refresh = async (division: string) => { if (division === 'electrical') { await load('electrical') } else if (division === 'occupancy') { await load('occupancy') } else { await load('all') } } const checkApproval = async (application: string, status: string) => { const response = await getApi('check-approval', status, application) return response } const getPassword = async () => { const response = await getApi('get-password', ID) setConfigEncPassword(response) } const checkCurrentPassword = async () => { const encCurrentPassword = await securePassword(configPassword(), 'v2') if (encCurrentPassword === configEncPassword()) { if (configNewPassword() === '') { setConfigError('New Password not provided') setConfigNewEncPassword('') } else { setConfigError('') encryptNewPassword() } } else { setConfigError('Invalid Password') setConfigNewEncPassword('') } } const encryptNewPassword = async () => { const encNewPassword = await securePassword(configNewPassword(), 'v2') setConfigNewEncPassword(encNewPassword) } const saveConfig = async () => { if (configNewName() !== '') await saveNewName(parseInt(ID), configNewName()) if (configNewPassword() !== '') await saveNewPassword(parseInt(ID), configNewEncPassword()) setConfigNotification(true) } // const saveNewName = async (name: string) => { // await postApi('update-name', { // data: parseInt(ID), // data2: name // }) // } // const saveNewPassword = async (password: string) => { // await postApi('update-password', { // data: parseInt(ID), // data2: password // }) // } const logout = async () => { removeEmployee() navigate('/') } // const gotoProfile = () => { // navigate('/profile') // } onMount(async () => { const logged = await checkLogged() if (logged) { await load('all') } }) createEffect(() => { if (configPassword !== '') { checkCurrentPassword() } if (configNewPassword() !== '') { encryptNewPassword() } else { encryptNewPassword() } }) return ( <>

OCBO e-Sign

{employeeName()} setOpenConfig(true)}> Config Logout
Building Occupancy Electrical {/*

List of Ready to Approve and Sign Building Order of Payments

*/}

Under Development

{/* */}
Application Number Name Show Details

List of Ready to Approve and Sign in Occupancy Order of Payments

{applicationListOccupancy().map((item: string, index: number) => ( ))}
Application Number Name Show Details
{item} {nameListOccupancy()[index]} { // setApology(true) // setErrorMessage('Modification of Occupancy Printing has not yet finished') await getopdetails('occupancy', item) }} > {item} Click anywhere to cancel

List of Ready to Approve and Sign in Electrical Order of Payments

{applicationListElectrical().map((item: string, index: number) => ( ))}
Application Number Name Show Details
{item} {nameListElectrical()[index]} { await getopdetails('electrical', item) }} > {item} Click anywhere to cancel
setApproved(false)}> Approved

{approvedApplication()}

Click anywhere to proceed
Approved

{approvedApplication()}

Click anywhere to proceed
setConnected(true)}>

Connection Error

{errorMessage()}

Click anywhere to close
setApology(false)}>

Delayed Release of Feature

{errorMessage()}

Occupancy Approval is delayed until Occupancy Printing is complete Click anywhere to close
Name: {employeeName()}
Encrypted Password: {configEncPassword()}
Change Displayed Name Leave blank to remain unchanged.
Change Password New Encrypted Password: {configNewEncPassword()}
{configError()}
Approved

{approvedApplication()}

Click anywhere to proceed
) }