added New Expense after Payment Request done
This commit is contained in:
parent
f4838441aa
commit
daaebf919d
@ -298,7 +298,7 @@ const ExpenseList = ({ filters, groupBy = "transactionDate", searchText }) => {
|
|||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
<td className="sticky-action-column bg-white">
|
<td className="sticky-action-column bg-white">
|
||||||
<div className="d-flex justify-content-center gap-2">
|
<div className="d-flex flex-row gap-2">
|
||||||
<i
|
<i
|
||||||
className="bx bx-show text-primary cursor-pointer"
|
className="bx bx-show text-primary cursor-pointer"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
|
|||||||
@ -10,7 +10,7 @@ const ExpenseStatusLogs = ({ data }) => {
|
|||||||
const sortedLogs = useMemo(() => {
|
const sortedLogs = useMemo(() => {
|
||||||
if (!data?.expenseLogs) return [];
|
if (!data?.expenseLogs) return [];
|
||||||
return [...data.expenseLogs].sort(
|
return [...data.expenseLogs].sort(
|
||||||
(a, b) => new Date(b.updatedAt) - new Date(a.updatedAt)
|
(a, b) => new Date(b.updateAt) - new Date(a.updateAt)
|
||||||
);
|
);
|
||||||
}, [data?.expenseLogs]);
|
}, [data?.expenseLogs]);
|
||||||
|
|
||||||
@ -20,11 +20,12 @@ const ExpenseStatusLogs = ({ data }) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const timelineData = useMemo(() => {
|
const timelineData = useMemo(() => {
|
||||||
|
|
||||||
return logsToShow.map((log, index) => ({
|
return logsToShow.map((log, index) => ({
|
||||||
id: index + 1,
|
id: index + 1,
|
||||||
title: log.action || "Status Updated",
|
title: log.action || "Status Updated",
|
||||||
description: log.comment || "",
|
description: log.comment || "",
|
||||||
timeAgo: log.updatedAt,
|
timeAgo: log.updateAt,
|
||||||
color: getColorNameFromHex(log.nextStatus?.color) || "primary",
|
color: getColorNameFromHex(log.nextStatus?.color) || "primary",
|
||||||
users: log.updatedBy
|
users: log.updatedBy
|
||||||
? [
|
? [
|
||||||
@ -44,7 +45,7 @@ const ExpenseStatusLogs = ({ data }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="page-min-h overflow-auto">
|
<div className="page-min-h overflow-auto py-1">
|
||||||
|
|
||||||
|
|
||||||
<Timeline items={timelineData} />
|
<Timeline items={timelineData} />
|
||||||
|
|||||||
@ -13,17 +13,19 @@ const Filelist = ({ files, removeFile, expenseToEdit }) => {
|
|||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
.map((file, idx) => (
|
.map((file, idx) => (
|
||||||
<div className="col-12 col-sm-6 col-md-4 bg-white " key={idx}>
|
<div className="col-12 col-sm-6 col-md-4 mb-2" key={idx}>
|
||||||
<div className="row align-items-center">
|
<div className="d-flex align-items-center justify-content-between bg-white border rounded p-1 ">
|
||||||
{/* File icon and info */}
|
{/* File icon and info */}
|
||||||
<div className="col-10 d-flex align-items-center gap-2">
|
<div className="d-flex align-items-center flex-grow-1 gap-2 overflow-hidden">
|
||||||
<i
|
<i
|
||||||
className={`bx ${getIconByFileType(file?.contentType)} fs-3`}
|
className={`bx ${getIconByFileType(
|
||||||
|
file?.contentType
|
||||||
|
)} fs-3 text-primary`}
|
||||||
style={{ minWidth: "30px" }}
|
style={{ minWidth: "30px" }}
|
||||||
></i>
|
></i>
|
||||||
|
|
||||||
<div className="d-flex flex-column text-truncate">
|
<div className="d-flex flex-column text-truncate">
|
||||||
<span className="fw-medium small text-truncate">
|
<span className="fw-semibold small text-truncate">
|
||||||
{file.fileName}
|
{file.fileName}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-body-secondary small">
|
<span className="text-body-secondary small">
|
||||||
@ -32,19 +34,17 @@ const Filelist = ({ files, removeFile, expenseToEdit }) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="col-2 text-end">
|
{/* Delete icon */}
|
||||||
<Tooltip text={"Remove file"}>
|
<Tooltip text="Remove file">
|
||||||
<i
|
<i
|
||||||
className="bx bx-trash fs-4 cursor-pointer text-danger bx-sm "
|
className="bx bx-sm bx-trash text-danger fs-4 cursor-pointer ms-2"
|
||||||
role="button"
|
role="button"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
debugger;
|
removeFile(expenseToEdit ? file.documentId : idx);
|
||||||
removeFile(expenseToEdit ? file.documentId : idx);
|
}}
|
||||||
}}
|
></i>
|
||||||
></i>
|
</Tooltip>
|
||||||
</Tooltip>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@ -298,35 +298,6 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => {
|
|||||||
</small>
|
</small>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* <div className="col-md-6">
|
|
||||||
<Label htmlFor="paidById" className="form-label" required>
|
|
||||||
Paid By
|
|
||||||
</Label>
|
|
||||||
<select
|
|
||||||
className="form-select form-select-sm"
|
|
||||||
id="paymentModeId"
|
|
||||||
{...register("paidById")}
|
|
||||||
disabled={!selectedproject}
|
|
||||||
>
|
|
||||||
<option value="" disabled>
|
|
||||||
Select Person
|
|
||||||
</option>
|
|
||||||
{EmpLoading ? (
|
|
||||||
<option disabled>Loading...</option>
|
|
||||||
) : (
|
|
||||||
employees?.map((emp) => (
|
|
||||||
<option key={emp.id} value={emp.id}>
|
|
||||||
{`${emp.firstName} ${emp.lastName} `}
|
|
||||||
</option>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</select>
|
|
||||||
{errors.paidById && (
|
|
||||||
<small className="danger-text">{errors.paidById.message}</small>
|
|
||||||
)}
|
|
||||||
</div> */}
|
|
||||||
|
|
||||||
<div className="col-12 col-md-6 text-start">
|
<div className="col-12 col-md-6 text-start">
|
||||||
<label className="form-label">Paid By </label>
|
<label className="form-label">Paid By </label>
|
||||||
<EmployeeSearchInput
|
<EmployeeSearchInput
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import { defaultActionValues, ExpenseActionScheam } from "./ExpenseSchema";
|
|||||||
import { useExpenseContext } from "../../pages/Expense/ExpensePage";
|
import { useExpenseContext } from "../../pages/Expense/ExpensePage";
|
||||||
import {
|
import {
|
||||||
formatCurrency,
|
formatCurrency,
|
||||||
|
formatFigure,
|
||||||
getColorNameFromHex,
|
getColorNameFromHex,
|
||||||
getIconByFileType,
|
getIconByFileType,
|
||||||
localToUtc,
|
localToUtc,
|
||||||
@ -166,7 +167,7 @@ const ViewExpense = ({ ExpenseId }) => {
|
|||||||
<label className="form-label me-2 mb-0 fw-semibold text-start" style={{ minWidth: "130px" }}>
|
<label className="form-label me-2 mb-0 fw-semibold text-start" style={{ minWidth: "130px" }}>
|
||||||
Amount :
|
Amount :
|
||||||
</label>
|
</label>
|
||||||
<div className="text-muted"> {formatCurrency(data.amount,data?.curency?.currencyCode)}</div>
|
<div className="text-muted"> {formatFigure(data?.amount,{type:"currency",currency : data?.currency?.currencyCode ?? "INR"} )}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -294,12 +295,134 @@ const ViewExpense = ({ ExpenseId }) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* ... your remaining conditional sections */}
|
{data.expensesReimburse && (
|
||||||
|
<div className="row text-start mt-2">
|
||||||
|
<div className="col-md-6 mb-sm-0 mb-2">
|
||||||
|
<label className="form-label me-2 mb-0 fw-semibold">
|
||||||
|
Transaction ID :
|
||||||
|
</label>
|
||||||
|
{data.expensesReimburse.reimburseTransactionId || "N/A"}
|
||||||
|
</div>
|
||||||
|
<div className="col-md-6 ">
|
||||||
|
<label className="form-label me-2 mb-0 fw-semibold">
|
||||||
|
Reimburse Date :
|
||||||
|
</label>
|
||||||
|
{formatUTCToLocalTime(data.expensesReimburse.reimburseDate)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{data.expensesReimburse && (
|
||||||
|
<>
|
||||||
|
<div className="col-md-6 d-flex align-items-center">
|
||||||
|
<label className="form-label me-2 mb-0 fw-semibold">
|
||||||
|
Reimburse By :
|
||||||
|
</label>
|
||||||
|
<Avatar
|
||||||
|
size="xs"
|
||||||
|
classAvatar="m-0 me-1"
|
||||||
|
firstName={data?.expensesReimburse?.reimburseBy?.firstName}
|
||||||
|
lastName={data?.expensesReimburse?.reimburseBy?.lastName}
|
||||||
|
/>
|
||||||
|
<span className="text-muted">
|
||||||
|
{`${data?.expensesReimburse?.reimburseBy?.firstName} ${data?.expensesReimburse?.reimburseBy?.lastName}`.trim()}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<hr className="divider my-1 border-2 divider-primary my-2" />
|
||||||
|
|
||||||
|
{Array.isArray(data?.nextStatus) && data.nextStatus.length > 0 && (
|
||||||
|
<>
|
||||||
|
{IsPaymentProcess && nextStatusWithPermission?.length > 0 && (
|
||||||
|
<div className="row">
|
||||||
|
<div className="col-12 col-md-6 text-start">
|
||||||
|
<label className="form-label">Transaction Id </label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="form-control form-control-sm"
|
||||||
|
{...register("reimburseTransactionId")}
|
||||||
|
/>
|
||||||
|
{errors.reimburseTransactionId && (
|
||||||
|
<small className="danger-text">
|
||||||
|
{errors.reimburseTransactionId.message}
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="col-12 col-md-6 text-start">
|
||||||
|
<label className="form-label">Transaction Date </label>
|
||||||
|
<DatePicker
|
||||||
|
name="reimburseDate"
|
||||||
|
control={control}
|
||||||
|
minDate={data?.transactionDate}
|
||||||
|
maxDate={new Date()}
|
||||||
|
/>
|
||||||
|
{errors.reimburseDate && (
|
||||||
|
<small className="danger-text">
|
||||||
|
{errors.reimburseDate.message}
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="col-12 col-md-6 text-start">
|
||||||
|
<label className="form-label">Reimburse By </label>
|
||||||
|
<EmployeeSearchInput
|
||||||
|
control={control}
|
||||||
|
name="reimburseById"
|
||||||
|
projectId={null}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="col-12 mb-3 text-start">
|
||||||
|
{((nextStatusWithPermission.length > 0 && !IsRejectedExpense) ||
|
||||||
|
(IsRejectedExpense && isCreatedBy)) && (
|
||||||
|
<>
|
||||||
|
<Label className="form-label me-2 mb-0" required>
|
||||||
|
Comment
|
||||||
|
</Label>
|
||||||
|
<textarea
|
||||||
|
className="form-control form-control-sm"
|
||||||
|
{...register("comment")}
|
||||||
|
rows="2"
|
||||||
|
/>
|
||||||
|
{errors.comment && (
|
||||||
|
<small className="danger-text">
|
||||||
|
{errors.comment.message}
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{nextStatusWithPermission?.length > 0 &&
|
||||||
|
(!IsRejectedExpense || isCreatedBy) && (
|
||||||
|
<div className="text-end flex-wrap gap-2 my-2 mt-3">
|
||||||
|
{nextStatusWithPermission.map((status, index) => (
|
||||||
|
<button
|
||||||
|
key={status.id || index}
|
||||||
|
type="button"
|
||||||
|
onClick={() => {
|
||||||
|
setClickedStatusId(status.id);
|
||||||
|
setValue("statusId", status.id);
|
||||||
|
handleSubmit(onSubmit)();
|
||||||
|
}}
|
||||||
|
disabled={isPending || isFetching}
|
||||||
|
className="btn btn-primary btn-sm cursor-pointer mx-2 border-0"
|
||||||
|
>
|
||||||
|
{isPending && clickedStatusId === status.id
|
||||||
|
? "Please Wait..."
|
||||||
|
: status.displayName || status.name}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="col-12 col-lg-5 col-xl-4">
|
<div className="col-12 col-lg-5 col-xl-4">
|
||||||
<div className="d-flex align-items-center text-secondary my-2">
|
<div className="d-flex align-items-center text-secondary mb-">
|
||||||
<i className='bx bx-time-five me-2'></i> <p className=" m-0">TimeLine</p>
|
<i className='bx bx-time-five me-2'></i> <p className=" m-0">TimeLine</p>
|
||||||
</div>
|
</div>
|
||||||
<ExpenseStatusLogs data={data} />
|
<ExpenseStatusLogs data={data} />
|
||||||
|
|||||||
247
src/components/PaymentRequest/MakeExpense.jsx
Normal file
247
src/components/PaymentRequest/MakeExpense.jsx
Normal file
@ -0,0 +1,247 @@
|
|||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import React from "react";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import {
|
||||||
|
DefaultRequestedExpense,
|
||||||
|
RequestedExpenseSchema,
|
||||||
|
} from "./PaymentRequestSchema";
|
||||||
|
import Label from "../common/Label";
|
||||||
|
import { usePaymentMode } from "../../hooks/masterHook/useMaster";
|
||||||
|
import { useCreatePaymentRequestExpense, useCreateRecurringExpense } from "../../hooks/useExpense";
|
||||||
|
import Filelist from "../Expenses/Filelist";
|
||||||
|
import { usePaymentRequestContext } from "../../pages/PaymentRequest/PaymentRequestPage";
|
||||||
|
|
||||||
|
const MakeExpense = ({ onClose }) => {
|
||||||
|
const {isExpenseGenerate} = usePaymentRequestContext()
|
||||||
|
const {
|
||||||
|
PaymentModes,
|
||||||
|
loading: PaymentModeLoading,
|
||||||
|
error: PaymentModeError,
|
||||||
|
} = usePaymentMode();
|
||||||
|
|
||||||
|
const {
|
||||||
|
setValue,
|
||||||
|
register,
|
||||||
|
watch,
|
||||||
|
handleSubmit,
|
||||||
|
formState: { errors },
|
||||||
|
} = useForm({
|
||||||
|
resolver: zodResolver(RequestedExpenseSchema),
|
||||||
|
defaultValues: DefaultRequestedExpense,
|
||||||
|
});
|
||||||
|
const files = watch("billAttachments");
|
||||||
|
const onFileChange = async (e) => {
|
||||||
|
const newFiles = Array.from(e.target.files);
|
||||||
|
if (newFiles.length === 0) return;
|
||||||
|
|
||||||
|
const existingFiles = watch("billAttachments") || [];
|
||||||
|
|
||||||
|
const parsedFiles = await Promise.all(
|
||||||
|
newFiles.map(async (file) => {
|
||||||
|
const base64Data = await toBase64(file);
|
||||||
|
return {
|
||||||
|
fileName: file.name,
|
||||||
|
base64Data,
|
||||||
|
contentType: file.type,
|
||||||
|
fileSize: file.size,
|
||||||
|
description: "",
|
||||||
|
isActive: true,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const combinedFiles = [
|
||||||
|
...existingFiles,
|
||||||
|
...parsedFiles.filter(
|
||||||
|
(newFile) =>
|
||||||
|
!existingFiles.some(
|
||||||
|
(f) =>
|
||||||
|
f.fileName === newFile.fileName && f.fileSize === newFile.fileSize
|
||||||
|
)
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
setValue("billAttachments", combinedFiles, {
|
||||||
|
shouldDirty: true,
|
||||||
|
shouldValidate: true,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const toBase64 = (file) =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
reader.onload = () => resolve(reader.result.split(",")[1]);
|
||||||
|
reader.onerror = (error) => reject(error);
|
||||||
|
});
|
||||||
|
const removeFile = (index) => {
|
||||||
|
debugger
|
||||||
|
const newFiles = files.filter((_, i) => i !== index);
|
||||||
|
setValue("billAttachments", newFiles, { shouldValidate: true });
|
||||||
|
};
|
||||||
|
|
||||||
|
const { mutate: CreatedExpense, isPending } = useCreatePaymentRequestExpense(
|
||||||
|
() => {
|
||||||
|
handleClose();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const onSubmit = (formData) => {
|
||||||
|
let payload = {
|
||||||
|
...formData,
|
||||||
|
paymentRequestId:isExpenseGenerate?.requestId
|
||||||
|
}
|
||||||
|
CreatedExpense(payload)
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
onClose();
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<div className="row px-2 py-3">
|
||||||
|
<form id="expenseForm" onSubmit={handleSubmit(onSubmit)}>
|
||||||
|
<h5 className="m-0">
|
||||||
|
Create New Expense
|
||||||
|
</h5>
|
||||||
|
|
||||||
|
<div className="row my-2 text-start">
|
||||||
|
<div className="col-md-6 mb-2">
|
||||||
|
<Label htmlFor="paymentModeId" className="form-label" required>
|
||||||
|
Payment Mode
|
||||||
|
</Label>
|
||||||
|
<select
|
||||||
|
className="form-select form-select-sm"
|
||||||
|
id="paymentModeId"
|
||||||
|
{...register("paymentModeId")}
|
||||||
|
>
|
||||||
|
<option value="" disabled>
|
||||||
|
Select Mode
|
||||||
|
</option>
|
||||||
|
{PaymentModeLoading ? (
|
||||||
|
<option disabled>Loading...</option>
|
||||||
|
) : (
|
||||||
|
PaymentModes?.map((payment) => (
|
||||||
|
<option key={payment.id} value={payment.id}>
|
||||||
|
{payment.name}
|
||||||
|
</option>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</select>
|
||||||
|
{errors.paymentModeId && (
|
||||||
|
<small className="danger-text">
|
||||||
|
{errors.paymentModeId.message}
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="col-md-6">
|
||||||
|
<label htmlFor="statusId" className="form-label ">
|
||||||
|
GST Number
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="gstNumber"
|
||||||
|
className="form-control form-control-sm"
|
||||||
|
min="1"
|
||||||
|
{...register("gstNumber")}
|
||||||
|
/>
|
||||||
|
{errors.gstNumber && (
|
||||||
|
<small className="danger-text">{errors.gstNumber.message}</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="col-md-6 text-start">
|
||||||
|
<Label htmlFor="location" className="form-label" required>
|
||||||
|
Location
|
||||||
|
</Label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="location"
|
||||||
|
className="form-control form-control-sm"
|
||||||
|
{...register("location")}
|
||||||
|
/>
|
||||||
|
{errors.location && (
|
||||||
|
<small className="danger-text">{errors.location.message}</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div className="row my-2 text-start">
|
||||||
|
<div className="col-md-12">
|
||||||
|
<Label className="form-label" required>
|
||||||
|
Upload Bill{" "}
|
||||||
|
</Label>
|
||||||
|
|
||||||
|
<div
|
||||||
|
className="border border-secondary border-dashed rounded p-4 text-center bg-textMuted position-relative"
|
||||||
|
style={{ cursor: "pointer" }}
|
||||||
|
onClick={() => document.getElementById("billAttachments").click()}
|
||||||
|
>
|
||||||
|
<i className="bx bx-cloud-upload d-block bx-lg"> </i>
|
||||||
|
<span className="text-muted d-block">
|
||||||
|
Click to select or click here to browse
|
||||||
|
</span>
|
||||||
|
<small className="text-muted">(PDF, JPG, PNG, max 5MB)</small>
|
||||||
|
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
id="billAttachments"
|
||||||
|
accept=".pdf,.jpg,.jpeg,.png"
|
||||||
|
multiple
|
||||||
|
style={{ display: "none" }}
|
||||||
|
{...register("billAttachments")}
|
||||||
|
onChange={(e) => {
|
||||||
|
onFileChange(e);
|
||||||
|
e.target.value = "";
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{errors.billAttachments && (
|
||||||
|
<small className="danger-text">
|
||||||
|
{errors.billAttachments.message}
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
{files.length > 0 && (
|
||||||
|
<Filelist
|
||||||
|
files={files}
|
||||||
|
removeFile={removeFile}
|
||||||
|
expenseToEdit={false}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{Array.isArray(errors.billAttachments) &&
|
||||||
|
errors.billAttachments.map((fileError, index) => (
|
||||||
|
<div key={index} className="danger-text small mt-1">
|
||||||
|
{
|
||||||
|
(fileError?.fileSize?.message ||
|
||||||
|
fileError?.contentType?.message ||
|
||||||
|
fileError?.base64Data?.message,
|
||||||
|
fileError?.documentId?.message)
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="d-flex justify-content-end gap-3">
|
||||||
|
{" "}
|
||||||
|
<button
|
||||||
|
type="reset"
|
||||||
|
disabled={isPending}
|
||||||
|
onClick={handleClose}
|
||||||
|
className="btn btn-label-secondary btn-sm mt-3"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className="btn btn-primary btn-sm mt-3"
|
||||||
|
disabled={isPending}
|
||||||
|
>
|
||||||
|
{isPending ? "Please Wait..." : "Submit"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MakeExpense;
|
||||||
@ -279,7 +279,7 @@ const PaymentRequestList = ({ filters, groupBy = "submittedBy", search }) => {
|
|||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
<td className="sticky-action-column bg-white">
|
<td className="sticky-action-column bg-white">
|
||||||
<div className="d-flex justify-content-center gap-2">
|
<div className="d-flex flex-row gap-2">
|
||||||
<i
|
<i
|
||||||
className="bx bx-show text-primary cursor-pointer"
|
className="bx bx-show text-primary cursor-pointer"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
|
|||||||
@ -125,8 +125,43 @@ export const PaymentRequestActionScheam = (
|
|||||||
export const defaultPaymentRequestActionValues = {
|
export const defaultPaymentRequestActionValues = {
|
||||||
comment: "",
|
comment: "",
|
||||||
statusId: "",
|
statusId: "",
|
||||||
|
|
||||||
paidTransactionId: null,
|
paidTransactionId: null,
|
||||||
paidAt: null,
|
paidAt: null,
|
||||||
paidById: null,
|
paidById: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export const RequestedExpenseSchema =
|
||||||
|
|
||||||
|
z.object({
|
||||||
|
paymentModeId: z.string().min(1, { message: "Payment mode is required" }),
|
||||||
|
location: z.string().min(1, { message: "Location is required" }),
|
||||||
|
gstNumber: z.string().optional(),
|
||||||
|
billAttachments: z
|
||||||
|
.array(
|
||||||
|
z.object({
|
||||||
|
fileName: z.string().min(1, { message: "Filename is required" }),
|
||||||
|
base64Data: z.string().nullable(),
|
||||||
|
contentType: z
|
||||||
|
.string()
|
||||||
|
.refine((val) => ALLOWED_TYPES.includes(val), {
|
||||||
|
message: "Only PDF, PNG, JPG, or JPEG files are allowed",
|
||||||
|
}),
|
||||||
|
documentId: z.string().optional(),
|
||||||
|
fileSize: z.number().max(MAX_FILE_SIZE, {
|
||||||
|
message: "File size must be less than or equal to 5MB",
|
||||||
|
}),
|
||||||
|
description: z.string().optional(),
|
||||||
|
isActive: z.boolean().default(true),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.nonempty({ message: "At least one file attachment is required" }),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const DefaultRequestedExpense = {
|
||||||
|
paymentModeId:"",
|
||||||
|
location:"",
|
||||||
|
gstNumber:"",
|
||||||
|
// amount:"",
|
||||||
|
billAttachments:[]
|
||||||
|
}
|
||||||
@ -20,6 +20,7 @@ const PaymentStatusLogs = ({ data }) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const timelineData = useMemo(() => {
|
const timelineData = useMemo(() => {
|
||||||
|
console.log(logsToShow)
|
||||||
return logsToShow.map((log, index) => ({
|
return logsToShow.map((log, index) => ({
|
||||||
id: index + 1,
|
id: index + 1,
|
||||||
title: log.nextStatus?.name || "Status Updated",
|
title: log.nextStatus?.name || "Status Updated",
|
||||||
|
|||||||
@ -50,7 +50,7 @@ const ViewPaymentRequest = ({ requestId }) => {
|
|||||||
|
|
||||||
const IsReview = useHasUserPermission(REVIEW_EXPENSE);
|
const IsReview = useHasUserPermission(REVIEW_EXPENSE);
|
||||||
const [imageLoaded, setImageLoaded] = useState({});
|
const [imageLoaded, setImageLoaded] = useState({});
|
||||||
const { setDocumentView, setModalSize } = usePaymentRequestContext();
|
const { setDocumentView, setModalSize,setVieRequest ,setIsExpenseGenerate} = usePaymentRequestContext();
|
||||||
const ActionSchema =
|
const ActionSchema =
|
||||||
PaymentRequestActionScheam(IsPaymentProcess, data?.createdAt) ??
|
PaymentRequestActionScheam(IsPaymentProcess, data?.createdAt) ??
|
||||||
z.object({});
|
z.object({});
|
||||||
@ -118,9 +118,14 @@ const ViewPaymentRequest = ({ requestId }) => {
|
|||||||
const handleImageLoad = (id) => {
|
const handleImageLoad = (id) => {
|
||||||
setImageLoaded((prev) => ({ ...prev, [id]: true }));
|
setImageLoaded((prev) => ({ ...prev, [id]: true }));
|
||||||
};
|
};
|
||||||
|
const handleExpense = ()=>{
|
||||||
|
|
||||||
|
setIsExpenseGenerate({IsOpen:true,requestId:requestId})
|
||||||
|
setVieRequest({IsOpen:true,requestId:requestId})
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form className="container px-3" onSubmit={handleSubmit(onSubmit)}>
|
<form className="container px-3 py-2 py-md-0" onSubmit={handleSubmit(onSubmit)}>
|
||||||
<div className="col-12 mb-2 text-center ">
|
<div className="col-12 mb-2 text-center ">
|
||||||
<h5 className="fw-semibold m-0">Payment Request Details</h5>
|
<h5 className="fw-semibold m-0">Payment Request Details</h5>
|
||||||
</div>
|
</div>
|
||||||
@ -350,7 +355,7 @@ const ViewPaymentRequest = ({ requestId }) => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{Array.isArray(data?.nextStatus) && data?.nextStatus.length > 0 && (
|
{Array.isArray(data?.nextStatus) && data?.nextStatus.length > 0 ? (
|
||||||
<>
|
<>
|
||||||
{IsPaymentProcess && nextStatusWithPermission?.length > 0 && (
|
{IsPaymentProcess && nextStatusWithPermission?.length > 0 && (
|
||||||
<div className="row">
|
<div className="row">
|
||||||
@ -436,11 +441,14 @@ const ViewPaymentRequest = ({ requestId }) => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
):(<div className="text-end flex-wrap gap-2 my-2 mt-3">
|
||||||
|
<button className="btn btn-sm btn-primary" onClick={handleExpense}>Make Expense</button>
|
||||||
|
</div>)}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className=" col-sm-12 my-2 my-md-0 border-top border-md-none col-md-5">
|
<div className=" col-sm-12 my-md-0 border-top border-md-none col-md-5">
|
||||||
<div className="d-flex mb-2">
|
<div className="d-flex mb-2 py-1">
|
||||||
<i className="bx bx-time-five me-2 "></i>{" "}
|
<i className="bx bx-time-five me-2 "></i>{" "}
|
||||||
<p className="fw-medium">TimeLine</p>
|
<p className="fw-medium">TimeLine</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -395,8 +395,27 @@ export const useDeletePaymentRequest = ()=>{
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//#endregion
|
export const useCreatePaymentRequestExpense = (onSuccessCallBack) => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: async (payload) => {
|
||||||
|
await ExpenseRepository.CreatePaymentRequestExpense(payload);
|
||||||
|
},
|
||||||
|
|
||||||
|
onSuccess: (_, variables) => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["Expenses"] });
|
||||||
|
queryClient.invalidateQueries({queryKey:["paymentRequest",variables.paymentRequestId]})
|
||||||
|
showToast("Expense Created Successfully", "success");
|
||||||
|
if (onSuccessCallBack) onSuccessCallBack();
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
showToast(
|
||||||
|
error.message || "Something went wrong please try again !",
|
||||||
|
"error"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
export const usePaymentRequestFilter = () => {
|
export const usePaymentRequestFilter = () => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["PaymentRequestFilter"],
|
queryKey: ["PaymentRequestFilter"],
|
||||||
@ -408,6 +427,9 @@ export const usePaymentRequestFilter = () => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//#region Advance Payment
|
//#region Advance Payment
|
||||||
export const useExpenseTransactions = (employeeId)=>{
|
export const useExpenseTransactions = (employeeId)=>{
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import PaymentRequestFilterPanel from "../../components/PaymentRequest/PaymentRe
|
|||||||
import { defaultPaymentRequestFilter,SearchPaymentRequestSchema } from "../../components/PaymentRequest/PaymentRequestSchema";
|
import { defaultPaymentRequestFilter,SearchPaymentRequestSchema } from "../../components/PaymentRequest/PaymentRequestSchema";
|
||||||
import ViewPaymentRequest from "../../components/PaymentRequest/ViewPaymentRequest";
|
import ViewPaymentRequest from "../../components/PaymentRequest/ViewPaymentRequest";
|
||||||
import PreviewDocument from "../../components/Expenses/PreviewDocument";
|
import PreviewDocument from "../../components/Expenses/PreviewDocument";
|
||||||
|
import MakeExpense from "../../components/PaymentRequest/MakeExpense";
|
||||||
|
|
||||||
export const PaymentRequestContext = createContext();
|
export const PaymentRequestContext = createContext();
|
||||||
export const usePaymentRequestContext = () => {
|
export const usePaymentRequestContext = () => {
|
||||||
@ -30,6 +31,8 @@ const PaymentRequestPage = () => {
|
|||||||
IsOpen: false,
|
IsOpen: false,
|
||||||
Image: null,
|
Image: null,
|
||||||
});
|
});
|
||||||
|
const [isExpenseGenerate,setIsExpenseGenerate] = useState({IsOpen: null,
|
||||||
|
RequestId: null,})
|
||||||
const [modalSize,setModalSize] = useState("md")
|
const [modalSize,setModalSize] = useState("md")
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
|
|
||||||
@ -37,7 +40,9 @@ const PaymentRequestPage = () => {
|
|||||||
setManageRequest,
|
setManageRequest,
|
||||||
setVieRequest,
|
setVieRequest,
|
||||||
setDocumentView,
|
setDocumentView,
|
||||||
setModalSize
|
setModalSize,
|
||||||
|
setIsExpenseGenerate,
|
||||||
|
isExpenseGenerate
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -134,6 +139,15 @@ const PaymentRequestPage = () => {
|
|||||||
<ViewPaymentRequest requestId={ViewRequest?.requestId} />
|
<ViewPaymentRequest requestId={ViewRequest?.requestId} />
|
||||||
</GlobalModel>
|
</GlobalModel>
|
||||||
)}
|
)}
|
||||||
|
{isExpenseGenerate.IsOpen && (
|
||||||
|
<GlobalModel
|
||||||
|
isOpen
|
||||||
|
size="md"
|
||||||
|
closeModal={() => setIsExpenseGenerate({IsOpen:false, requestId: null})}
|
||||||
|
>
|
||||||
|
<MakeExpense onClose={() => setIsExpenseGenerate({IsOpen:false, requestId: null})} />
|
||||||
|
</GlobalModel>
|
||||||
|
)}
|
||||||
|
|
||||||
{ViewDocument.IsOpen && (
|
{ViewDocument.IsOpen && (
|
||||||
<GlobalModel
|
<GlobalModel
|
||||||
|
|||||||
@ -41,6 +41,7 @@ const ExpenseRepository = {
|
|||||||
ActionOnPaymentRequest: (data) =>
|
ActionOnPaymentRequest: (data) =>
|
||||||
api.post("/api/Expense/payment-request/action", data),
|
api.post("/api/Expense/payment-request/action", data),
|
||||||
DeletePaymentRequest:()=>api.get("delete here come"),
|
DeletePaymentRequest:()=>api.get("delete here come"),
|
||||||
|
CreatePaymentRequestExpense:(data)=>api.post('/api/Expense/payment-request/expense/create',data),
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region Recurring Expense
|
//#region Recurring Expense
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user