Applied new api fetching
This commit is contained in:
parent
b8ec4dc246
commit
40f2ad04f4
3 changed files with 353 additions and 290 deletions
|
|
@ -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 () => {
|
|||
</Padding>
|
||||
|
||||
<Row padding="2rem 0 0 0">
|
||||
<Button wide label="Approve" edges="curved" design="bo-primary" onClick={() => approveHandler(item)}></Button>
|
||||
<Button wide label="Approve" edges="curved" design="bo-primary" onClick={() => approveHandler('occupancy', item)}></Button>
|
||||
<span class="modal__cancel">Click anywhere to cancel</span>
|
||||
</Row>
|
||||
</Padding>
|
||||
|
|
@ -560,7 +601,7 @@ export default () => {
|
|||
</Padding>
|
||||
|
||||
<Row padding="2rem 0 0 0">
|
||||
<Button wide label="Approve" edges="curved" design="bo-primary" onClick={() => approveHandler(item)}></Button>
|
||||
<Button wide label="Approve" edges="curved" design="bo-primary" onClick={() => approveHandler('electrical', item)}></Button>
|
||||
<span class="modal__cancel">Click anywhere to cancel</span>
|
||||
</Row>
|
||||
</Padding>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue