diff --git a/backend/main.go b/backend/main.go index 691ed4c..51b2349 100644 --- a/backend/main.go +++ b/backend/main.go @@ -653,26 +653,67 @@ func connect() { case "get-printdetails-electrical": var result2, result3, result4, result5, result6, result7, result8 string + // array := []string{} + // array2 := []string{} + // array3 := []string{} + // array4 := []string{} + // array5 := []string{} + // array6 := []string{} + // array7 := []string{} + // array8 := []string{} + + err := db.QueryRow(`SELECT DISTINCT IFNULL(el.electricalNo, '') AS result, IFNULL(op.opDate, '') AS result2, IFNULL(el.locationofinstallation, '') AS result3, IFNULL(occ.occupancy, '') AS result4, IFNULL(u.occupancyoruse, '') AS result5, IFNULL(el.noofUnits, '') AS result6, IFNULL(e.employeename, '') AS result7, IF(cu.firstName IS NULL OR cu.firstName = '', cu.lastName, CONCAT(cu.firstName, ' ', IF(cu.middleInitial IS NULL OR cu.middleInitial = '', '', CONCAT(cu.middleInitial, '. ')), cu.lastName) ) AS result8 + FROM electrical el, electrical_orderofpayment_new op, ref_occupancy occ, ref_elec_occupancy u, customer cu, employee e + WHERE el.customerid = cu.customerid AND el.ref_elec_occupancyid = u.ref_elec_occupancyid AND u.ref_occupancyid = occ.ref_occupancyid AND op.assessedbyid = e.employeeid + AND el.electricalid = op.electricalid AND op.is_approve = 0 AND op.for_approval = 1 AND op.is_release = 0 AND is_paid = 0 AND popstransmitted = 0 AND el.electricalid = ?`, data).Scan(&result, &result2, &result3, &result4, &result5, &result6, &result7, &result8) + if err != nil { + c.AbortWithError(http.StatusBadRequest, err) + c.String(http.StatusBadRequest, err.Error()) + return + } + // for results.Next() { + // err = results.Scan(&result, &result2, &result3, &result4, &result5, &result6, &result7, &result8) + // if err != nil { + // c.AbortWithError(http.StatusBadRequest, err) + // c.String(http.StatusBadRequest, err.Error()) + // return + // } + // array = append(array, result) + // array2 = append(array2, result2) + // array3 = append(array3, result3) + // array4 = append(array4, result4) + // array5 = append(array5, result5) + // array6 = append(array6, result6) + // array7 = append(array7, result7) + // array8 = append(array8, result8) + // } + c.JSON(http.StatusOK, gin.H{ + "result": result, + "result2": result2, + "result3": result3, + "result4": result4, + "result5": result5, + "result6": result6, + "result7": result7, + "result8": result8, + }) + + case "get-printdetailsfees-electrical": + var result2, result3 string array := []string{} array2 := []string{} array3 := []string{} - array4 := []string{} - array5 := []string{} - array6 := []string{} - array7 := []string{} - array8 := []string{} - results, err := db.Query(`SELECT DISTINCT IFNULL(el.electricalNo, '') AS result, IFNULL(op.opDate, '') AS result2, IFNULL(el.locationofinstallation, '') AS result3, IFNULL(occ.occupancy, '') AS result4, IFNULL(u.occupancyoruse, '') AS result5, IFNULL(el.noofUnits, '') AS result6, IFNULL(e.employeename, '') AS result7, IF(cu.firstName IS NULL OR cu.firstName = '', cu.lastName, CONCAT(cu.firstName, ' ', IF(cu.middleInitial IS NULL OR cu.middleInitial = '', '', CONCAT(cu.middleInitial, '. ')), cu.lastName) ) AS result8 - FROM electrical el, electrical_orderofpayment_new op, ref_occupancy occ, ref_elec_occupancy u, customer cu, employee e - WHERE el.customerid = cu.customerid AND el.ref_elec_occupancyid = u.ref_elec_occupancyid AND u.ref_occupancyid = occ.ref_occupancyid AND op.assessedbyid = e.employeeid - AND el.electricalid = op.electricalid AND op.is_approve = 0 AND op.for_approval = 1 AND op.is_release = 0 AND is_paid = 0 AND popstransmitted = 0 AND el.electricalid = ?`, data) + results, err := db.Query(`SELECT IFNULL(ref.accountdescription, '') AS result, IFNULL(ref.accountcode, '') AS result2, IFNULL(op.amount, '') AS result3 FROM electrical_orderofpayment_new op, ref_bldgcomputationsheet ref, electrical el + WHERE op.is_approve = 0 AND op.for_approval = 1 AND op.is_release = 0 AND op.is_paid = 0 AND op.popstransmitted = 0 AND op.is_delete <> 1 AND op.ref_bldgcomputationsheetid = ref.ref_bldgcomputationsheetid + AND el.electricalid = op.electricalid AND op.electricalid = ?`, data) if err != nil { c.AbortWithError(http.StatusBadRequest, err) c.String(http.StatusBadRequest, err.Error()) return } for results.Next() { - err = results.Scan(&result, &result2, &result3, &result4, &result5, &result6, &result7, &result8) + err = results.Scan(&result, &result2, &result3) if err != nil { c.AbortWithError(http.StatusBadRequest, err) c.String(http.StatusBadRequest, err.Error()) @@ -681,21 +722,11 @@ func connect() { array = append(array, result) array2 = append(array2, result2) array3 = append(array3, result3) - array4 = append(array4, result4) - array5 = append(array5, result5) - array6 = append(array6, result6) - array7 = append(array7, result7) - array8 = append(array8, result8) } c.JSON(http.StatusOK, gin.H{ "result": array, "result2": array2, "result3": array3, - "result4": array4, - "result5": array5, - "result6": array6, - "result7": array7, - "result8": array8, }) } diff --git a/src/pages/AssessorPage/Assessor.tsx b/src/pages/AssessorPage/Assessor.tsx index 6f632b9..aa76a63 100644 --- a/src/pages/AssessorPage/Assessor.tsx +++ b/src/pages/AssessorPage/Assessor.tsx @@ -9,7 +9,7 @@ import { checkConnection, createPdf } from '../../utils/functions' import { FaSolidThumbsUp } from 'solid-icons/fa' import { _employeeName, _employeeId } from '../../stores/employee' import { useNavigate } from '@solidjs/router' -import { _applicationNo, _date, _optn, _name, _location, _type } from '../../stores/pdfinfo' +import { _applicationNo, _date, _optn, _name, _location, _type, _assessor, _feeList, _codeList, _amountList } from '../../stores/pdfinfo' const API = import.meta.env.VITE_BACKEND const PESO = import.meta.env.VITE_PESO @@ -65,11 +65,12 @@ export default () => { const getPrintDetails = async (id: number) => { const response = await ofetch(API + 'get-printdetails-electrical/' + id) - const applicationno = response.result[0] - const date = response.result2[0] - const location = response.result3[0] - const name = response.result8[0] - const type = `${response.result4[0]} - ${response.result5[0]}` + const applicationno = response.result + const date = response.result2 + const location = response.result3 + const name = response.result8 + const type = `${response.result4} - ${response.result5}` + const assessor = response.result7 _optn.set('M' + applicationno.split('-')[0] + applicationno.split('-')[1]) _applicationNo.set(applicationno) @@ -77,10 +78,18 @@ export default () => { _name.set(name) _location.set(location) _type.set(type) + _assessor.set(assessor) + } - // setDocApplicationNo(applicationno) - // setDocDate(dayjs(date).format('MMMM DD, YYYY')) - // setDocLocation(location) + const getPrintDetailsFees = async (id: number) => { + const response = await ofetch(API + 'get-printdetailsfees-electrical/' + id) + const feeList = response.result + const accountCodeList = response.result2 + const amountList = response.result3 + + _feeList.set(feeList) + _codeList.set(accountCodeList) + _amountList.set(amountList) } // const calculateAmounts = () => { @@ -141,6 +150,7 @@ export default () => { // calculateAmounts() getPrintDetails(op.result11[0]) + getPrintDetailsFees(op.result11[0]) } const calculateTotal = (list: number[]) => { diff --git a/src/stores/pdfinfo.ts b/src/stores/pdfinfo.ts index 2b818bd..345d707 100644 --- a/src/stores/pdfinfo.ts +++ b/src/stores/pdfinfo.ts @@ -7,4 +7,8 @@ export const _name = atom('') export const _location = atom('') export const _type = atom('') export const _code = atom('') +export const _assessor = atom('') +export const _feeList = atom([]) +export const _codeList = atom([]) +export const _amountList = atom([]) diff --git a/src/utils/functions/createPdf.ts b/src/utils/functions/createPdf.ts index f3e0166..7e506a3 100644 --- a/src/utils/functions/createPdf.ts +++ b/src/utils/functions/createPdf.ts @@ -1,9 +1,7 @@ import jsPDF from 'jspdf' // @ts-ignore import jspdfBarcode from 'jspdf-barcode' -// import { ofetch } from 'ofetch' -// import dayjs from 'dayjs' -import { _optn, _applicationNo, _date, _name, _type, _location } from '../../stores/pdfinfo' +import { _optn, _applicationNo, _date, _name, _type, _location, _assessor, _feeList, _codeList, _amountList } from '../../stores/pdfinfo' export default async () => { const PESO = import.meta.env.VITE_PESO @@ -17,9 +15,11 @@ export default async () => { const TYPE = _type.get() const CODE = '40201010-5-3' const AMOUNT = 100 - - // const ASSESSOR = 'ENGR. BATMAN' - // const APPROVER = 'AR. KHASHAYAR L. TOGHYANI' + const ASSESSOR = _assessor.get() + const APPROVER = 'AR. KHASHAYAR L. TOGHYANI' + const FEES = _feeList.get() + const CODES = _codeList.get() + const AMOUNTS = _amountList.get() const doc = new jsPDF({ orientation: 'l', @@ -158,29 +158,53 @@ export default async () => { doc.text('AMOUNT', getTextWidth('ACCOUNT DESCRIPTION', 8) + getTextWidth('ACCOUNT CODE', 8) + 65, 84) doc.setFont('arial', 'normal') - doc.text('SAMPLE FEE', 16, 92) - doc.text('ANOTHER SAMPLE FEE', 16, 96) + // doc.text('SAMPLE FEE', 16, 92) + // doc.text('ANOTHER SAMPLE FEE', 16, 96) - doc.text(CODE, 76, 92) - doc.text(CODE, 76, 96) + let yPosition = 92 + FEES.forEach((fee) => { + doc.text(fee, 16, yPosition) + yPosition += 4 + }) + + yPosition = 92 + CODES.forEach((code) => { + doc.text(code, 76, yPosition) + yPosition += 4 + }) + + yPosition = 92 + AMOUNTS.forEach((amount) => { + doc.text(`${PESO} ${parseInt(amount).toFixed(2)}`, 122, yPosition) + yPosition += 4 + }) - doc.text(`P ${AMOUNT.toFixed(2)}`, 122, 92) - doc.text(`P ${AMOUNT.toFixed(2)}`, 122, 96) doc.text('x1', 140, 92) doc.text('x1', 140, 96) doc.text('=', 148, 92) doc.text('=', 148, 96) - doc.setFont('arial-bold', 'bold') - doc.text(`P ${AMOUNT.toFixed(2)}`, 156, 92) - doc.text(`P ${AMOUNT.toFixed(2)}`, 156, 96) + + yPosition = 92 + AMOUNTS.forEach((amount) => { + doc.text(`${PESO} ${parseInt(amount).toFixed(2)}`, 156, yPosition) + yPosition += 4 + }) doc.setFont('arial-bold', 'bold') doc.text('Assessed By :', 16, 112) doc.text('Approved By :', 142, 112) + + doc.text(ASSESSOR, 16, 128) + doc.text(APPROVER, 142, 128) + + doc.setFont('arial', 'normal') + doc.setFontSize(6) + doc.text('Officer-in-Charge', 154, 132) // doc.text(CODE, 76, 96) - // doc.setFont('arial', 'normal') - doc.text('Please use the OPTN when paying online.', 16, 136) + doc.setFont('arial-bold', 'bold') + doc.setFontSize(7) + doc.text('Please use the OPTN when paying online.', 16, 140) const note = doc.splitTextToSize('Note: The 72 Hours Transaction Policy of the City Mayor, shall commence upon submission of the Bureau of Fire Protection clearance/certificate and other requirement stated in the notice to comply to be issued by this office.', 185) doc.text(note, 16, 144)