diff --git a/backend/main.go b/backend/main.go index 3f179b4..82f8547 100644 --- a/backend/main.go +++ b/backend/main.go @@ -108,8 +108,8 @@ func connect() { array2 := []string{} results, err := db.Query(`SELECT IFNULL(o.controlNo, '') AS result, IF(c.firstName IS NULL OR c.firstName = '', c.lastName, CONCAT(c.firstName, ' ', IF(c.middleInitial IS NULL OR c.middleInitial = '', '', CONCAT(c.middleInitial, '. ')), c.lastName) ) AS result2 - FROM occupancy o JOIN customer c ON o.customerid = c.customerid JOIN ref_occupancy_type ot ON o.ref_occupancy_typeid = ot.ref_occupancy_typeid JOIN ref_occupancy ro ON ot.ref_occupancyid = ro.ref_occupancyid JOIN occupancydocflowtxn od ON o.occupancyid = od.occupancyreceivingid - JOIN (SELECT occupancyreceivingid, MAX(occupancydocflowtxnid) AS latest_occupancydocflowtxnid FROM occupancydocflowtxn GROUP BY occupancyreceivingid) latest_doc ON od.occupancyreceivingid = latest_doc.occupancyreceivingid AND od.occupancydocflowtxnid = latest_doc.latest_occupancydocflowtxnid WHERE remarks = ? AND is_approve = 0 ORDER BY od.txndate DESC`, "FOR OCCUPANCY RECOMMENDING APPROVAL") + FROM occupancy o JOIN customer c ON o.customerid = c.customerid JOIN ref_occupancy_type ot ON o.ref_occupancy_typeid = ot.ref_occupancy_typeid JOIN ref_occupancy ro ON ot.ref_occupancyid = ro.ref_occupancyid JOIN occupancydocflowtxn od ON o.occupancyid = od.occupancyreceivingid JOIN (SELECT occupancyreceivingid, MAX(occupancydocflowtxnid) AS latest_occupancydocflowtxnid FROM occupancydocflowtxn GROUP BY occupancyreceivingid) latest_doc ON od.occupancyreceivingid = latest_doc.occupancyreceivingid AND od.occupancydocflowtxnid = latest_doc.latest_occupancydocflowtxnid + WHERE (remarks = "FOR OCCUPANCY RECOMMENDING APPROVAL" OR remarks = "FOR ADDITIONAL ORDER OF PAYMENT RECOMMENDING APPROVAL") AND od.is_approve = 0 ORDER BY od.txndate DESC`) if err != nil { c.AbortWithError(http.StatusBadRequest, err) c.String(http.StatusBadRequest, err.Error()) @@ -137,7 +137,7 @@ func connect() { array2 := []string{} results, err := db.Query(`SELECT IFNULL(e.electricalno, '') AS result, IF(c.firstName IS NULL OR c.firstName = '', c.lastName, CONCAT(c.firstName, ' ', IF(c.middleInitial IS NULL OR c.middleInitial = '', '', CONCAT(c.middleInitial, '. ')), c.lastName) ) AS result2 - FROM iips.electrical e JOIN iips.customer c ON e.customerid = c.customerid JOIN iips.ref_elec_occupancy ec ON e.ref_elec_occupancyid = ec.ref_elec_occupancyid JOIN iips.electricaldocflowtxn ed ON e.electricalid = ed.electricalid JOIN (SELECT electricalid, MAX(electricaldocflowtxnid) AS latest_electricaldocflowtxnid FROM electricaldocflowtxn GROUP BY electricalid) latest_doc ON ed.electricalid = latest_doc.electricalid AND ed.electricaldocflowtxnid = latest_doc.latest_electricaldocflowtxnid WHERE remarks = ? AND is_approve = 0 ORDER BY ed.txndate DESC`, "FOR ELECTRICAL ORDER OF PAYMENT APPROVAL") + FROM iips.electrical e JOIN iips.customer c ON e.customerid = c.customerid JOIN iips.ref_elec_occupancy ec ON e.ref_elec_occupancyid = ec.ref_elec_occupancyid JOIN iips.electricaldocflowtxn ed ON e.electricalid = ed.electricalid JOIN (SELECT electricalid, MAX(electricaldocflowtxnid) AS latest_electricaldocflowtxnid FROM electricaldocflowtxn GROUP BY electricalid) latest_doc ON ed.electricalid = latest_doc.electricalid AND ed.electricaldocflowtxnid = latest_doc.latest_electricaldocflowtxnid WHERE remarks = ? AND is_approve = 0 ORDER BY ed.txndate DESC`, "FOR ELECTRICAL ORDER OF PAYMENT APPROVAL") if err != nil { c.AbortWithError(http.StatusBadRequest, err) c.String(http.StatusBadRequest, err.Error()) @@ -1214,7 +1214,7 @@ func connect() { router.POST("/api/update-docflow-occupancy", middleware.TokenChecker(), func(c *gin.Context) { type UpdateDocflowData struct { - Data int `json:"data"` + Data string `json:"data"` Data2 string `json:"data2"` } var updateDocflowData UpdateDocflowData @@ -1230,7 +1230,7 @@ func connect() { c.Writer.Header().Set("X-Download-Options", "noopen") c.Writer.Header().Set("Referrer-Policy", "no-referrer") - dbpost, err := db.Prepare("UPDATE occupancydocflowtxn SET is_approve = 1 WHERE occupancyreceivingid = ? AND remarks = ?") + dbpost, err := db.Prepare("UPDATE occupancydocflowtxn SET is_approve = 1 WHERE remarks = ? AND occupancyreceivingid = (SELECT occupancyid FROM occupancy WHERE controlNo = ?)") if err != nil { c.AbortWithError(http.StatusInternalServerError, err) c.String(http.StatusInternalServerError, "Internal Server Error") @@ -1261,7 +1261,7 @@ func connect() { router.POST("/api/update-docflow-electrical", middleware.TokenChecker(), func(c *gin.Context) { type UpdateDocflowData struct { - Data int `json:"data"` + Data string `json:"data"` Data2 string `json:"data2"` } var updateDocflowData UpdateDocflowData @@ -1277,7 +1277,7 @@ func connect() { c.Writer.Header().Set("X-Download-Options", "noopen") c.Writer.Header().Set("Referrer-Policy", "no-referrer") - dbpost, err := db.Prepare("UPDATE electricaldocflowtxn SET is_approve = 1 WHERE electricalid = ? AND remarks = ?") + dbpost, err := db.Prepare("UPDATE electricaldocflowtxn SET is_approve = 1 WHERE remarks = ? AND electricalid = (SELECT electricalid FROM electrical WHERE electricalNo = ?)") if err != nil { c.AbortWithError(http.StatusInternalServerError, err) c.String(http.StatusInternalServerError, "Internal Server Error") @@ -1323,7 +1323,7 @@ func connect() { c.Writer.Header().Set("X-Download-Options", "noopen") c.Writer.Header().Set("Referrer-Policy", "no-referrer") - dbpost, err := db.Prepare("UPDATE iips.occupancy_orderofpayment SET popstransmitted = 1, is_release = 1 WHERE occupancyid = ? AND for_approval = 1 AND is_paid = 0 AND is_approve = 1") + dbpost, err := db.Prepare("UPDATE occupancy_orderofpayment SET popstransmitted = 1, is_release = 1 WHERE occupancyid = ? AND for_approval = 1 AND is_paid = 0 AND is_approve = 1") if err != nil { panic(err.Error()) } diff --git a/src/pages/AssessorPage/Assessor.tsx b/src/pages/AssessorPage/Assessor.tsx index d2559ba..584a4cb 100644 --- a/src/pages/AssessorPage/Assessor.tsx +++ b/src/pages/AssessorPage/Assessor.tsx @@ -212,8 +212,6 @@ export default () => { } const printHandler = async (division: string, application: string) => { - let signed: boolean = false - let forprinting: boolean = false let updateOrderofpayment: boolean = false setConnected(await checkConnection()) @@ -222,22 +220,28 @@ export default () => { return } - // signed = await setNewStatus(division, 'ELECTRICAL ORDER OF PAYMENT PRINTED', '171', 'ELECOPPRINTED', 1) - // if (!signed) return - - // forprinting = await setNewStatus(division, 'FOR ELECTRICAL OFFICIAL RECEIPT VALIDATION', '98', 'ELECORVALIDATE', 0) - // if (!forprinting) return - - // updateOrderofpayment = await updateOp(division) - - // if (updateOrderofpayment) { - // postTransaction(application) - setPrintedApplication(application) - setPrinted(true) if (division === 'electrical') { - createPdf() - } else createPdfOccupancy() - // } + await setNewStatus(division, 'ELECTRICAL ORDER OF PAYMENT PRINTED', '171', 'ELECOPPRINTED', 1) + await setNewStatus(division, 'ELECTRICAL ORDERPAYMENT RELEASED', '97', 'ELECRELEASED', 1) + await setNewStatus(division, 'FOR ELECTRICAL OFFICIAL RECEIPT VALIDATION', '98', 'ELECORVALIDATE', 0) + await updateDocflow(division, application, 'FOR ELECTRICAL ORDER OF PAYMENT PRINTING') + } else if (division === 'occupancy') { + await setNewStatus(division, 'OCCUPANCY ORDER OF PAYMENT PRINTED', '173', 'OCCOPPRINTED', 1) + await setNewStatus(division, 'OCCUPANCY ORDER OF PAYMENT RELEASED', '174', 'OCCOPRELEASED', 1) + await setNewStatus(division, 'ORDER OF PAYMENT RELEASE FOR BUREAU OF FIRE', '24', 'OCOOPRELEASE', 0) + await updateDocflow(division, application, 'APPROVED FOR PRINTING OF BUREAU OF FIRE AND ORDER OF PAYMENT') + } + + updateOrderofpayment = await updateOp(division) + + if (updateOrderofpayment) { + postTransaction(application) + setPrintedApplication(application) + setPrinted(true) + if (division === 'electrical') { + createPdf() + } else createPdfOccupancy() + } } const updateOp = async (division: string) => { @@ -254,6 +258,10 @@ export default () => { return post } + const updateDocflow = async (division: string, application: string, status: string) => { + await postApi(`update-docflow-${division}`, { data: status, data2: application }) + } + const getSignatureImage = async (id: number) => { try { const response = await getApi('get-signatureimage', id) @@ -490,7 +498,7 @@ export default () => { @@ -578,7 +586,7 @@ export default () => { diff --git a/src/pages/MainPage/Main.tsx b/src/pages/MainPage/Main.tsx index ceded81..e4aeb5f 100644 --- a/src/pages/MainPage/Main.tsx +++ b/src/pages/MainPage/Main.tsx @@ -166,8 +166,8 @@ export default () => { if (division === 'electrical') { signed = await setNewStatus(division, 'ELECTRICAL ORDER OF PAYMENT APPROVED AND SIGNED', '170', 'ELECOPAPPROVEDSIGNED', 1) - const approvedid = await getIdByApplication(division, application) - updateDocflow(division, approvedid, 'FOR ELECTRICAL ORDER OF PAYMENT APPROVAL') + // const approvedid = await getIdByApplication(division, application) + 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) @@ -183,8 +183,9 @@ export default () => { } } else if (division === 'occupancy') { signed = await setNewStatus(division, 'OCCUPANCY ORDER OF PAYMENT APPROVED AND SIGNED', '172', 'OCCOPAPPROVEDSIGNED', 1) - const approvedid = await getIdByApplication(division, application) - updateDocflow(division, approvedid, 'FOR OCCUPANCY RECOMMENDING APPROVAL') + // const approvedid = await getIdByApplication(division, application) + updateDocflow(division, application, 'FOR OCCUPANCY RECOMMENDING APPROVAL') + 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) @@ -333,23 +334,25 @@ export default () => { await postApi('post-esigntransaction', { data: parseInt(id), data2: approvedApplication(), data3: formatedDate }) } - const updateDocflow = async (division: string, applicationid: number, status: string) => { - if (division === 'electrical') { - await postApi('update-docflow-electrical', { data: parseInt(applicationid.toString()), data2: status }) - } else if (division === 'occupancy') { - await postApi('update-docflow-occupancy', { data: parseInt(applicationid.toString()), data2: status }) - } + const updateDocflow = async (division: string, application: string, status: string) => { + // if (division === 'electrical') { + // await postApi('update-docflow-electrical', { data: parseInt(applicationid.toString()), data2: status }) + // } else if (division === 'occupancy') { + // await postApi('update-docflow-occupancy', { data: parseInt(applicationid.toString()), data2: status }) + // } + + await postApi(`update-docflow-${division}`, { data: status, data2: application }) } - const getIdByApplication = async (division: string, applicationNo: string) => { - let response - if (division === 'electrical') { - response = await getApi('get-idbyapplication-electrical', applicationNo) - } else if (division === 'occupancy') { - response = await getApi('get-idbyapplication-occupancy', applicationNo) - } - return parseInt(response) - } + // const getIdByApplication = async (division: string, applicationNo: string) => { + // let response + // if (division === 'electrical') { + // response = await getApi('get-idbyapplication-electrical', applicationNo) + // } else if (division === 'occupancy') { + // response = await getApi('get-idbyapplication-occupancy', applicationNo) + // } + // return parseInt(response) + // } const refresh = async (division: string) => { if (division === 'electrical') { diff --git a/src/utils/functions/createPdf.ts b/src/utils/functions/createPdf.ts index 9b23f6d..bbcc978 100644 --- a/src/utils/functions/createPdf.ts +++ b/src/utils/functions/createPdf.ts @@ -195,7 +195,7 @@ export default async () => { yPosition = 82 AMOUNTS.forEach((amount) => { - doc.text(`${PESO} ${parseInt(amount).toFixed(2)}`, 122, yPosition) + doc.text(`${PESO} ${parseInt(amount).toLocaleString('en-US', { minimumFractionDigits: 2 })}`, 122, yPosition) yPosition += 4 }) @@ -206,7 +206,7 @@ export default async () => { yPosition = 82 AMOUNTS.forEach((amount) => { - doc.text(`${PESO} ${parseInt(amount).toFixed(2)}`, 156, yPosition) + doc.text(`${PESO} ${parseInt(amount).toLocaleString('en-US', { minimumFractionDigits: 2 })}`, 156, yPosition) yPosition += 4 }) @@ -218,7 +218,7 @@ export default async () => { doc.setFont('arial-bold', 'bold') doc.text('Total :', 146, newYPosition + 4) const totalAmount = AMOUNTS.reduce((sum, amount) => sum + parseFloat(amount), 0) - doc.text(`${PESO} ${totalAmount.toFixed(2)}`, 156, newYPosition + 4) + doc.text(`${PESO} ${totalAmount.toLocaleString('en-US', { minimumFractionDigits: 2 })}`, 156, newYPosition + 4) doc.text('Assessed By :', 16, newYPosition + 12) doc.text('Approved By :', 142, newYPosition + 12)