Skip to content

Commit

Permalink
ppr purchased and receipts submitted
Browse files Browse the repository at this point in the history
  • Loading branch information
victorzheng02 committed Aug 29, 2023
1 parent 224dbe2 commit a7b2ae9
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/auth/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const authenticateUser = async (req, res, next) => {
switch (baseUrl) {
case TICKET_ENDPOINTS.UPR:
reporter_id = (await getUWFinancePurchase(itemId))
.reporter_id
?.reporter_id
break
case TICKET_ENDPOINTS.FI:
reporter_id = (await getFundingItem(itemId)).reporter_id
Expand Down
20 changes: 20 additions & 0 deletions backend/emails/emails.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,25 @@ const sendEmailUPRApprovedToCoordinator = async (upr) => {
})
}

const sendEmailPPRPurchasedAndReceiptsSubmittedToCoordinator = async (ppr) => {
const Subject = `[Purchased And Receipts Submitted] ${ppr.codename}`
const HTMLPart =
getMainMessageHTML(
`Item ${ppr.codename} has been purchased and receipts have been submitted! Please review the expense claim form and reimburse the reporter out of WATonomous' cash account.`
) +
(await getUPRTicketInfoHTML(ppr)) +
getTicketLinkHTML(ppr.path)
const To = await getEmailToSection(ppr.reporter_id, [
EMAIL_RECIPIENTS.finance,
EMAIL_RECIPIENTS.coordinator,
])
await sendEmail({
Subject,
HTMLPart,
To,
})
}

const PurchaseRequestInvalidated = (purchaseRequestDetails) => {
const { issue, reporter } = purchaseRequestDetails

Expand Down Expand Up @@ -544,6 +563,7 @@ module.exports = {
sendEmailUPRPurchasedToCoordinator,
sendEmailPPRApprovedToReporter,
sendEmailPPRCreatedToApprovers,
sendEmailPPRPurchasedAndReceiptsSubmittedToCoordinator,
PurchaseRequestInvalidated,
PersonalPurchaseApproved,
UWFinancePurchaseApproved,
Expand Down
12 changes: 10 additions & 2 deletions backend/service/personalpurchases.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
const {
sendEmailPPRCreatedToApprovers,
sendEmailPPRApprovedToReporter,
sendEmailPPRPurchasedAndReceiptsSubmittedToCoordinator,
} = require('../emails/emails')

const getAllPersonalPurchases = () => {
Expand All @@ -30,10 +31,17 @@ const createPersonalPurchase = async (body) => {
return annotatedPPR
}

const updatePersonalPurchase = (id, body) => {
return PersonalPurchase.findByIdAndUpdate(id, body, {
const updatePersonalPurchase = async (id, body) => {
// READY_TO_BUY -> PURCHASED_AND_RECEIPTS_SUBMITTED
const newPurchaseTicket = PersonalPurchase.findByIdAndUpdate(id, body, {
new: true,
})
if (body?.status === 'PURCHASED_AND_RECEIPTS_SUBMITTED') {
const annotatedPPR = await getPersonalPurchase(id)
console.log(annotatedPPR)
sendEmailPPRPurchasedAndReceiptsSubmittedToCoordinator(annotatedPPR)
}
return newPurchaseTicket
}

const updateFILinkPersonalPurchase = async (id, new_fi_link) => {
Expand Down
52 changes: 52 additions & 0 deletions frontend/src/components/TicketContent/PPRReporterTable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Button, Center, Heading, Tooltip, VStack } from '@chakra-ui/react'
import React from 'react'
import { useSetRecoilState } from 'recoil'
import { allTicketsState } from '../../state/atoms'
import { axiosPreset } from '../../axiosConfig'
import { TICKET_ENDPOINTS } from '../../constants'
import { getAllTickets } from '../../utils/globalSetters'

const PPRReporterTable = ({ currentTicket, supportingDocuments }) => {
const setAllTickets = useSetRecoilState(allTicketsState)

const transitionToPurchasedAndReceiptsSubmitted = async () => {
const payload = {
status: 'PURCHASED_AND_RECEIPTS_SUBMITTED',
}
await axiosPreset.patch(
`${TICKET_ENDPOINTS.PPR}/${currentTicket._id}`,
payload
)
await getAllTickets(setAllTickets)
}

return (
<VStack
border="1px solid black"
borderRadius="8px"
padding="8px"
mb="30px"
>
<Heading size="md">Reporter View</Heading>
<Center pb="7px">
<Tooltip
hasArrow
label="Please upload at least one supporting document before requesting reimbursement."
isDisabled={supportingDocuments.length !== 0}
>
<Button
colorScheme="blue"
size="sm"
mr="20px"
onClick={transitionToPurchasedAndReceiptsSubmitted}
disabled={supportingDocuments.length === 0}
>
Confirm Item(s) Purchased and Request Reimbursement
</Button>
</Tooltip>
</Center>
</VStack>
)
}

export default PPRReporterTable
13 changes: 13 additions & 0 deletions frontend/src/pages/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import PPRAdminContentTable from '../components/TicketContent/PPRAdminContentTab
import FIAdminContentTable from '../components/TicketContent/FIAdminContentTable'
import { getAllTickets } from '../utils/globalSetters'
import FileViewer from '../components/FileViewer'
import PPRReporterTable from '../components/TicketContent/PPRReporterTable'

const Dashboard = () => {
const navigate = useNavigate()
const location = useLocation()
Expand Down Expand Up @@ -103,6 +105,10 @@ const Dashboard = () => {
fetchData()
}, [setAllTickets])

const isReporter = () => {
return auth.currentUser.uid === currentTicket.reporter_id
}

const getUploadedFiles = useCallback(async () => {
if (!currentTicket?.code) {
return
Expand Down Expand Up @@ -178,6 +184,13 @@ const Dashboard = () => {
return (
<>
{auth.isAdmin && <PPRAdminContentTable />}
{isReporter() &&
currentTicket.status === 'READY_TO_BUY' && (
<PPRReporterTable
supportingDocuments={supportingDocuments}
currentTicket={currentTicket}
/>
)}
<PPRContentTable />
</>
)
Expand Down

0 comments on commit a7b2ae9

Please sign in to comment.