Survey various reason depends on quantity low or high and added zone in profile
This commit is contained in:
parent
74191af173
commit
62f7913076
@ -8,6 +8,7 @@ import {
|
|||||||
fetchZeroTargetReasons,
|
fetchZeroTargetReasons,
|
||||||
fetchProducts,
|
fetchProducts,
|
||||||
fetchUnits,
|
fetchUnits,
|
||||||
|
getVariationReasons,
|
||||||
} from '@/services/masters/masterService.js';
|
} from '@/services/masters/masterService.js';
|
||||||
// import { fetchEstablishmentDetail } from '@/services/establishments/establishmentService';
|
// import { fetchEstablishmentDetail } from '@/services/establishments/establishmentService';
|
||||||
import { useLocation } from 'react-router-dom';
|
import { useLocation } from 'react-router-dom';
|
||||||
@ -465,6 +466,7 @@ const ProductData = ({
|
|||||||
const [maxProducts, setMaxProducts] = React.useState(0);
|
const [maxProducts, setMaxProducts] = React.useState(0);
|
||||||
const nextId = React.useRef(products.length + 1);
|
const nextId = React.useRef(products.length + 1);
|
||||||
const [variationReasons, setVariationReasons] = React.useState([]);
|
const [variationReasons, setVariationReasons] = React.useState([]);
|
||||||
|
const [allVariationReasons, setAllVariationReasons] = React.useState([]);
|
||||||
const [isLoadingReasons, setIsLoadingReasons] = React.useState(false);
|
const [isLoadingReasons, setIsLoadingReasons] = React.useState(false);
|
||||||
const [reasonsError, setReasonsError] = React.useState('');
|
const [reasonsError, setReasonsError] = React.useState('');
|
||||||
const [zeroTargetReasons, setZeroTargetReasons] = React.useState([]);
|
const [zeroTargetReasons, setZeroTargetReasons] = React.useState([]);
|
||||||
@ -1330,8 +1332,10 @@ useEffect(() => {
|
|||||||
setIsLoadingReasons(true);
|
setIsLoadingReasons(true);
|
||||||
setReasonsError('');
|
setReasonsError('');
|
||||||
try {
|
try {
|
||||||
|
const reason2 = await getVariationReasons();
|
||||||
const reasons = await fetchVariationReasons({ signal: variationController.signal });
|
const reasons = await fetchVariationReasons({ signal: variationController.signal });
|
||||||
setVariationReasons(reasons || []);
|
setVariationReasons(reasons || []);
|
||||||
|
setAllVariationReasons(reason2.data || []);
|
||||||
setReasonsError('');
|
setReasonsError('');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch variation reasons:', error);
|
console.error('Failed to fetch variation reasons:', error);
|
||||||
@ -2039,7 +2043,7 @@ useEffect(() => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateProductField = (id, field, value, options = null) => {
|
const updateProductField = (id, field, value, options = null,period = null) => {
|
||||||
// Create a copy of the current products array to work with
|
// Create a copy of the current products array to work with
|
||||||
let updatedProducts = [...products];
|
let updatedProducts = [...products];
|
||||||
|
|
||||||
@ -2409,6 +2413,37 @@ useEffect(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onProductsChange(updatedProducts);
|
onProductsChange(updatedProducts);
|
||||||
|
if (field.endsWith('Quantity') && value && value !== '') {
|
||||||
|
let previousTotal = 0;
|
||||||
|
let currentTotal = 0;
|
||||||
|
|
||||||
|
updatedProducts.forEach(p => {
|
||||||
|
if (p.octQuantity) previousTotal += parseFloat(p.octQuantity) || 0;
|
||||||
|
if (p.novQuantity) previousTotal += parseFloat(p.novQuantity) || 0;
|
||||||
|
if (p.decQuantity) previousTotal += parseFloat(p.decQuantity) || 0;
|
||||||
|
if (p.janQuantity) currentTotal += parseFloat(p.janQuantity) || 0;
|
||||||
|
if (p.febQuantity) currentTotal += parseFloat(p.febQuantity) || 0;
|
||||||
|
if (p.marQuantity) currentTotal += parseFloat(p.marQuantity) || 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (previousTotal > currentTotal) {
|
||||||
|
const lowVariationReasons = allVariationReasons
|
||||||
|
.filter(item => item.high_or_low === "Low")
|
||||||
|
.map(item => ({
|
||||||
|
label: item.reason,
|
||||||
|
value: String(item.id)
|
||||||
|
}));
|
||||||
|
setVariationReasons(lowVariationReasons);
|
||||||
|
}else if (currentTotal > previousTotal) {
|
||||||
|
const highVariationReasons = allVariationReasons
|
||||||
|
.filter(item => item.high_or_low === "High")
|
||||||
|
.map(item => ({
|
||||||
|
label: item.reason,
|
||||||
|
value: String(item.id)
|
||||||
|
}));
|
||||||
|
setVariationReasons(highVariationReasons);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleProductSelect = async (productId, establishmentId, id) => {
|
const handleProductSelect = async (productId, establishmentId, id) => {
|
||||||
@ -2951,7 +2986,7 @@ useEffect(() => {
|
|||||||
placeholder="Enter"
|
placeholder="Enter"
|
||||||
value={p.octQuantity || ''}
|
value={p.octQuantity || ''}
|
||||||
error={!!formErrors[`octQuantity_${idx}`]}
|
error={!!formErrors[`octQuantity_${idx}`]}
|
||||||
onChange={(e) => updateProductField(p.id, 'octQuantity', e.target.value)}
|
onChange={(e) => updateProductField(p.id, 'octQuantity', e.target.value,null,'previous') }
|
||||||
/>
|
/>
|
||||||
{formErrors[`octQuantity_${idx}`] && (
|
{formErrors[`octQuantity_${idx}`] && (
|
||||||
<p className="mt-1 text-xs text-red-600">{formErrors[`octQuantity_${idx}`]}</p>
|
<p className="mt-1 text-xs text-red-600">{formErrors[`octQuantity_${idx}`]}</p>
|
||||||
@ -2966,7 +3001,7 @@ useEffect(() => {
|
|||||||
placeholder="Enter"
|
placeholder="Enter"
|
||||||
value={p.novQuantity || ''}
|
value={p.novQuantity || ''}
|
||||||
error={!!formErrors[`novQuantity_${idx}`]}
|
error={!!formErrors[`novQuantity_${idx}`]}
|
||||||
onChange={(e) => updateProductField(p.id, 'novQuantity', e.target.value)}
|
onChange={(e) => updateProductField(p.id, 'novQuantity', e.target.value,null,'previous') }
|
||||||
/>
|
/>
|
||||||
{formErrors[`novQuantity_${idx}`] && (
|
{formErrors[`novQuantity_${idx}`] && (
|
||||||
<p className="mt-1 text-xs text-red-600">{formErrors[`novQuantity_${idx}`]}</p>
|
<p className="mt-1 text-xs text-red-600">{formErrors[`novQuantity_${idx}`]}</p>
|
||||||
@ -2981,7 +3016,7 @@ useEffect(() => {
|
|||||||
placeholder="Enter"
|
placeholder="Enter"
|
||||||
value={p.decQuantity || ''}
|
value={p.decQuantity || ''}
|
||||||
error={!!formErrors[`decQuantity_${idx}`]}
|
error={!!formErrors[`decQuantity_${idx}`]}
|
||||||
onChange={(e) => updateProductField(p.id, 'decQuantity', e.target.value)}
|
onChange={(e) => updateProductField(p.id, 'decQuantity', e.target.value,null,'previous') }
|
||||||
/>
|
/>
|
||||||
{formErrors[`decQuantity_${idx}`] && (
|
{formErrors[`decQuantity_${idx}`] && (
|
||||||
<p className="mt-1 text-xs text-red-600">{formErrors[`decQuantity_${idx}`]}</p>
|
<p className="mt-1 text-xs text-red-600">{formErrors[`decQuantity_${idx}`]}</p>
|
||||||
@ -3060,7 +3095,7 @@ useEffect(() => {
|
|||||||
value={p.janQuantity || ''}
|
value={p.janQuantity || ''}
|
||||||
error={!!formErrors[`janQuantity_${idx}`]}
|
error={!!formErrors[`janQuantity_${idx}`]}
|
||||||
placeholder="Enter"
|
placeholder="Enter"
|
||||||
onChange={(e) => updateProductField(p.id, 'janQuantity', e.target.value)}
|
onChange={(e) => updateProductField(p.id, 'janQuantity', e.target.value,null,'current') }
|
||||||
/>
|
/>
|
||||||
{formErrors[`janQuantity_${idx}`] && (
|
{formErrors[`janQuantity_${idx}`] && (
|
||||||
<p className="mt-1 text-xs text-red-600">{formErrors[`janQuantity_${idx}`]}</p>
|
<p className="mt-1 text-xs text-red-600">{formErrors[`janQuantity_${idx}`]}</p>
|
||||||
@ -3076,7 +3111,7 @@ useEffect(() => {
|
|||||||
value={p.febQuantity || ''}
|
value={p.febQuantity || ''}
|
||||||
error={!!formErrors[`febQuantity_${idx}`]}
|
error={!!formErrors[`febQuantity_${idx}`]}
|
||||||
placeholder="Enter"
|
placeholder="Enter"
|
||||||
onChange={(e) => updateProductField(p.id, 'febQuantity', e.target.value)}
|
onChange={(e) => updateProductField(p.id, 'febQuantity', e.target.value,null,'current') }
|
||||||
/>
|
/>
|
||||||
{formErrors[`febQuantity_${idx}`] && (
|
{formErrors[`febQuantity_${idx}`] && (
|
||||||
<p className="mt-1 text-xs text-red-600">{formErrors[`febQuantity_${idx}`]}</p>
|
<p className="mt-1 text-xs text-red-600">{formErrors[`febQuantity_${idx}`]}</p>
|
||||||
@ -3092,7 +3127,7 @@ useEffect(() => {
|
|||||||
value={p.marQuantity || ''}
|
value={p.marQuantity || ''}
|
||||||
error={!!formErrors[`marQuantity_${idx}`]}
|
error={!!formErrors[`marQuantity_${idx}`]}
|
||||||
placeholder="Enter"
|
placeholder="Enter"
|
||||||
onChange={(e) => updateProductField(p.id, 'marQuantity', e.target.value)}
|
onChange={(e) => updateProductField(p.id, 'marQuantity', e.target.value,null,'current') }
|
||||||
/>
|
/>
|
||||||
{formErrors[`marQuantity_${idx}`] && (
|
{formErrors[`marQuantity_${idx}`] && (
|
||||||
<p className="mt-1 text-xs text-red-600">{formErrors[`marQuantity_${idx}`]}</p>
|
<p className="mt-1 text-xs text-red-600">{formErrors[`marQuantity_${idx}`]}</p>
|
||||||
|
|||||||
@ -29,6 +29,7 @@ const createEmptyProfile = () => ({
|
|||||||
contactEmail: '',
|
contactEmail: '',
|
||||||
contactPostalCode: '',
|
contactPostalCode: '',
|
||||||
contactPoBox: '',
|
contactPoBox: '',
|
||||||
|
zone: '',
|
||||||
contactWebsite: '',
|
contactWebsite: '',
|
||||||
employmentEmiratiMale: 0,
|
employmentEmiratiMale: 0,
|
||||||
employmentEmiratiFemale: 0,
|
employmentEmiratiFemale: 0,
|
||||||
@ -58,6 +59,7 @@ const mapApiEstablishmentToProfile = (apiData) => {
|
|||||||
contactEmail: data.establishment_contact_email || '',
|
contactEmail: data.establishment_contact_email || '',
|
||||||
contactPostalCode: data.establishment_postal_code || '',
|
contactPostalCode: data.establishment_postal_code || '',
|
||||||
contactPoBox: data.establishment_po_box || '',
|
contactPoBox: data.establishment_po_box || '',
|
||||||
|
zone: data.zone || '',
|
||||||
contactWebsite: data.establishment_website || '',
|
contactWebsite: data.establishment_website || '',
|
||||||
employmentEmiratiMale: data.emirati_male || 0,
|
employmentEmiratiMale: data.emirati_male || 0,
|
||||||
employmentEmiratiFemale: data.emirati_female || 0,
|
employmentEmiratiFemale: data.emirati_female || 0,
|
||||||
@ -818,6 +820,7 @@ const EditCompanyProfile = () => {
|
|||||||
establishment_city_town_id: selectedCity ? Number(selectedCity.value) : null,
|
establishment_city_town_id: selectedCity ? Number(selectedCity.value) : null,
|
||||||
establishment_emirate_id: selectedEmirate ? Number(selectedEmirate.value) : null,
|
establishment_emirate_id: selectedEmirate ? Number(selectedEmirate.value) : null,
|
||||||
establishment_postal_code: form.contactPostalCode || "",
|
establishment_postal_code: form.contactPostalCode || "",
|
||||||
|
zone:form.zone|| "",
|
||||||
establishment_po_box: form.contactPoBox || "",
|
establishment_po_box: form.contactPoBox || "",
|
||||||
establishment_makani_number: form.contactMakaniNumber || "",
|
establishment_makani_number: form.contactMakaniNumber || "",
|
||||||
establishment_contact_person_name: form.contactPersonName || "",
|
establishment_contact_person_name: form.contactPersonName || "",
|
||||||
@ -1041,6 +1044,13 @@ const EditCompanyProfile = () => {
|
|||||||
placeholder="Enter Postal Code"
|
placeholder="Enter Postal Code"
|
||||||
width="100%"
|
width="100%"
|
||||||
/>
|
/>
|
||||||
|
<TextField
|
||||||
|
label="Zone (Area Name)"
|
||||||
|
value={form.zone || ""}
|
||||||
|
onChange={(e) => handleFormChange("zone", e.target.value)}
|
||||||
|
placeholder="Enter Zone"
|
||||||
|
width="100%"
|
||||||
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
label="PO Box"
|
label="PO Box"
|
||||||
value={form.contactPoBox || ""}
|
value={form.contactPoBox || ""}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user