diff --git a/src/app/api/invoices/actions.ts b/src/app/api/invoices/actions.ts index 65778a0..7194c2c 100644 --- a/src/app/api/invoices/actions.ts +++ b/src/app/api/invoices/actions.ts @@ -8,16 +8,36 @@ export interface InvoiceResult { id: number; projectCode: string; projectName: string; - stage: String; - comingPaymentMileStone: String; - paymentMilestoneDate: String; + stage: string; + comingPaymentMileStone: string; + paymentMilestoneDate: string; resourceUsage: number; unbilledHours: number; - reminder: String; + reminder: string; } export interface CreateInvoiceInputs { id: number; + + // Project Details + projectCode: string; + projectName: string; + stage: string; + comingPaymentMileStone: string; + paymentMilestoneDate: string; + resourceUsage: number; + unbilledHours: number; + + // Invoice Info + client: string; + address: string; + attention: string; + invoiceDate: string; + dueDate: string; + projectRefNo: string; + + // Invoice related Info + reminder: string; amount: number; billHours: number; } @@ -30,16 +50,18 @@ export interface InvoiceInformation{ invoiceDate: string; dueDate: string; projectRefNo: string; + + amount: number; } export const fetchProjectInvoiceById = cache(async (id: number) => { - return serverFetchJson(`${BASE_API_URL}/invoices/getProjectDetailById?id=${id}`, { + return serverFetchJson(`${BASE_API_URL}/invoices/getProjectDetail/${id}`, { next: { tags: ["projectDetailById"] }, }); }) export const fetchInvoiceInfoById = cache(async (id: number) => { - return serverFetchJson(`${BASE_API_URL}/invoices/getInvoiceInfoById?id=${id}`, { + return serverFetchJson(`${BASE_API_URL}/invoices/getInvoiceInfo/${id}`, { next: { tags: ["invoiceInfoById"] }, }); }) \ No newline at end of file diff --git a/src/app/api/invoices/index.ts b/src/app/api/invoices/index.ts index 9ab55fe..6036051 100644 --- a/src/app/api/invoices/index.ts +++ b/src/app/api/invoices/index.ts @@ -8,11 +8,11 @@ export interface InvoiceResult { projectCode: string; projectName: string; stage: String; - comingPaymentMileStone: String; - paymentMilestoneDate: String; + comingPaymentMileStone: string; + paymentMilestoneDate: string; resourceUsage: number; unbilledHours: number; - reminder: String; + reminder: string; } export interface InvoiceInformatio{ diff --git a/src/components/CreateInvoice/CreateInvoice.tsx b/src/components/CreateInvoice/CreateInvoice.tsx index 09c4d2b..f42dd74 100644 --- a/src/components/CreateInvoice/CreateInvoice.tsx +++ b/src/components/CreateInvoice/CreateInvoice.tsx @@ -20,6 +20,9 @@ import { InvoiceResult } from "@/app/api/invoices"; import { InvoiceInformation, fetchInvoiceInfoById, fetchProjectInvoiceById } from "@/app/api/invoices/actions"; import InvoiceDetails from "./InvoiceDetails"; import ProjectDetails from "./ProjectDetails"; +import ProjectTotalFee from "./ProjectTotalFee"; +import { timestampToDateString } from "@/app/utils/formatUtil"; +import dayjs from "dayjs"; const CreateInvoice: React.FC = ({ }) => { @@ -31,13 +34,18 @@ const CreateInvoice: React.FC = ({ const [invoiceDetail, setInvoiceDetail] = useState() const [serverError, setServerError] = useState(""); + // const { getValues } = useForm(); + const fetchProjectDetails = async () =>{ const projectId = searchParams.get("id") try{ if (projectId !== null && parseInt(projectId) > 0) { const projectDetail = await fetchProjectInvoiceById(parseInt(projectId)) - console.log(projectDetail) - setProjectDetail(projectDetail[0]) + // console.log(projectDetail) + const updatedPrijectDetail = projectDetail.map(detail => { + return { ...detail, paymentMilestoneDate: timestampToDateString(detail.paymentMilestoneDate) }; // Update the age of person with id 2 + }); + setProjectDetail(updatedPrijectDetail[0]) } } catch (error){ console.log(error) @@ -51,7 +59,13 @@ const CreateInvoice: React.FC = ({ if (projectId !== null && parseInt(projectId) > 0) { const invoiceInfo = await fetchInvoiceInfoById(parseInt(projectId)) console.log(invoiceInfo) - setInvoiceDetail(invoiceInfo[0]) + const updatedInvoiceInfo = invoiceInfo.map(info => { + return { ...info, + invoiceDate: dayjs.unix(parseFloat(info.invoiceDate)/1000).format('YYYY/MM/DD'), + dueDate: dayjs.unix(parseFloat(info.dueDate)/1000).format('YYYY/MM/DD') + }; + }); + setInvoiceDetail(updatedInvoiceInfo[0]) } } catch (error){ console.log(error) @@ -69,6 +83,7 @@ const CreateInvoice: React.FC = ({ }; const handlePrintout = () => { + // const formData = getValues(); console.log("Printing in Progress") } @@ -114,6 +129,9 @@ const CreateInvoice: React.FC = ({ { invoiceDetail && } + { + + }