Added Checkbox at Advance Payment.
This commit is contained in:
parent
5bf5e18c6b
commit
a8f83571ee
@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect } from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
import { useCurrencies, useProjectName } from '../../hooks/useProjects';
|
import { useCurrencies, useProjectName } from '../../hooks/useProjects';
|
||||||
import Label from '../common/Label';
|
import Label from '../common/Label';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
@ -10,6 +10,7 @@ import { zodResolver } from '@hookform/resolvers/zod';
|
|||||||
import { formatFileSize, localToUtc } from '../../utils/appUtils';
|
import { formatFileSize, localToUtc } from '../../utils/appUtils';
|
||||||
import { defaultPaymentRequest, PaymentRequestSchema } from './PaymentRequestSchema';
|
import { defaultPaymentRequest, PaymentRequestSchema } from './PaymentRequestSchema';
|
||||||
import { INR_CURRENCY_CODE } from '../../utils/constants';
|
import { INR_CURRENCY_CODE } from '../../utils/constants';
|
||||||
|
import { useProfile } from '../../hooks/useProfile';
|
||||||
|
|
||||||
function ManagePaymentRequest({ closeModal, requestToEdit = null }) {
|
function ManagePaymentRequest({ closeModal, requestToEdit = null }) {
|
||||||
const { data, isLoading, isError, error: requestError } = usePaymentRequestDetail(requestToEdit)
|
const { data, isLoading, isError, error: requestError } = usePaymentRequestDetail(requestToEdit)
|
||||||
@ -27,13 +28,15 @@ function ManagePaymentRequest({ closeModal, requestToEdit = null }) {
|
|||||||
error: ExpenseError,
|
error: ExpenseError,
|
||||||
} = useExpenseCategory();
|
} = useExpenseCategory();
|
||||||
|
|
||||||
|
const { profile } = useProfile();
|
||||||
|
|
||||||
const schema = PaymentRequestSchema(ExpenseTypes);
|
const schema = PaymentRequestSchema(ExpenseTypes);
|
||||||
const { register, control, watch, handleSubmit, setValue, reset, formState: { errors }, } = useForm({
|
const { register, control, watch, handleSubmit, setValue, reset, formState: { errors }, } = useForm({
|
||||||
resolver: zodResolver(schema),
|
resolver: zodResolver(schema),
|
||||||
defaultValues: defaultPaymentRequest,
|
defaultValues: defaultPaymentRequest,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [isItself, setisItself] = useState(false);
|
||||||
|
|
||||||
const files = watch("billAttachments");
|
const files = watch("billAttachments");
|
||||||
const onFileChange = async (e) => {
|
const onFileChange = async (e) => {
|
||||||
@ -151,18 +154,23 @@ function ManagePaymentRequest({ closeModal, requestToEdit = null }) {
|
|||||||
}, [currencyData, requestToEdit, setValue]);
|
}, [currencyData, requestToEdit, setValue]);
|
||||||
|
|
||||||
const onSubmit = (fromdata) => {
|
const onSubmit = (fromdata) => {
|
||||||
|
|
||||||
let payload = {
|
let payload = {
|
||||||
...fromdata,
|
...fromdata,
|
||||||
dueDate: localToUtc(fromdata.dueDate),
|
dueDate: localToUtc(fromdata.dueDate),
|
||||||
|
payee:isItself ? profile?.employeeInfo?.id : fromdata.payee
|
||||||
};
|
};
|
||||||
if (requestToEdit) {
|
if (requestToEdit) {
|
||||||
const editPayload = { ...payload, id: data.id };
|
const editPayload = { ...payload, id: data.id, payee:isItself ? profile?.employeeInfo?.id : fromdata.payee };
|
||||||
PaymentRequestUpdate({ id: data.id, payload: editPayload });
|
PaymentRequestUpdate({ id: data.id, payload: editPayload });
|
||||||
} else {
|
} else {
|
||||||
CreatePaymentRequest(payload);
|
CreatePaymentRequest(payload);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const handleSetItSelf=(e)=>{
|
||||||
|
setisItself(e.target.value);
|
||||||
|
setValue('payee',profile?.employeeInfo.id)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container p-3">
|
<div className="container p-3">
|
||||||
@ -313,21 +321,38 @@ function ManagePaymentRequest({ closeModal, requestToEdit = null }) {
|
|||||||
<div className="row my-2 text-start">
|
<div className="row my-2 text-start">
|
||||||
<div className="col-md-6">
|
<div className="col-md-6">
|
||||||
<Label htmlFor="payee" className="form-label" required>
|
<Label htmlFor="payee" className="form-label" required>
|
||||||
Payee(Supplier Name/Transporter Name/Other)
|
Payee (Supplier Name/Transporter Name/Other)
|
||||||
</Label>
|
</Label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
id="payee"
|
id="payee"
|
||||||
className="form-control form-control-sm"
|
className="form-control form-control-sm"
|
||||||
{...register("payee")}
|
{...register("payee")}
|
||||||
|
disabled={isItself}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
{errors.payee && (
|
{errors.payee && (
|
||||||
<small className="danger-text">
|
<small className="danger-text">
|
||||||
{errors.payee.message}
|
{errors.payee.message}
|
||||||
</small>
|
</small>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Checkbox below input */}
|
||||||
|
<div className="form-check mt-2">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id="sameAsSupplier"
|
||||||
|
className="form-check-input"
|
||||||
|
value={isItself}
|
||||||
|
onChange={handleSetItSelf}
|
||||||
|
/>
|
||||||
|
<Label htmlFor="sameAsSupplier" className="form-check-label">
|
||||||
|
Same as Supplier
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div className="col-md-6">
|
<div className="col-md-6">
|
||||||
<Label htmlFor="currencyId" className="form-label" required>
|
<Label htmlFor="currencyId" className="form-label" required>
|
||||||
Currency
|
Currency
|
||||||
|
|||||||
@ -7,7 +7,7 @@ const ALLOWED_TYPES = [
|
|||||||
"image/jpg",
|
"image/jpg",
|
||||||
"image/jpeg",
|
"image/jpeg",
|
||||||
];
|
];
|
||||||
export const PaymentRequestSchema = (expenseTypes) => {
|
export const PaymentRequestSchema = (expenseTypes,isItself) => {
|
||||||
return z
|
return z
|
||||||
.object({
|
.object({
|
||||||
title: z.string().min(1, { message: "Project is required" }),
|
title: z.string().min(1, { message: "Project is required" }),
|
||||||
@ -47,8 +47,11 @@ export const PaymentRequestSchema = (expenseTypes) => {
|
|||||||
description: z.string().optional(),
|
description: z.string().optional(),
|
||||||
isActive: z.boolean().default(true),
|
isActive: z.boolean().default(true),
|
||||||
})
|
})
|
||||||
)
|
).refine((data)=>{
|
||||||
,
|
if(isItself){
|
||||||
|
payee.z.string().optional();
|
||||||
|
}
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user