mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 05:22:02 +00:00
fix(FE-179): prevent qty input greater than sales order qty
This commit is contained in:
@@ -71,9 +71,8 @@ const InventoryAdjustmentForm = ({
|
||||
Partial<InventoryAdjustmentFormValues>
|
||||
>(() => {
|
||||
return {
|
||||
product_category_id: initialValues?.product_category?.id ?? 0,
|
||||
product_id: initialValues?.product?.id ?? 0,
|
||||
warehouse_id: initialValues?.warehouse?.id ?? 0,
|
||||
product_id: initialValues?.product_warehouse?.product_id ?? 0,
|
||||
warehouse_id: initialValues?.product_warehouse?.warehouse_id ?? 0,
|
||||
product_category: undefined,
|
||||
product: undefined,
|
||||
warehouse: undefined,
|
||||
|
||||
@@ -32,7 +32,7 @@ import { useRouter } from 'next/navigation';
|
||||
import { useState } from 'react';
|
||||
import toast from 'react-hot-toast';
|
||||
import SalesOrderExport from '@/components/pages/marketing/pdf/SalesOrderExport';
|
||||
import DeliveryOrderExport from '../pdf/DeliveryOrderExport';
|
||||
import DeliveryOrderExport from '@/components/pages/marketing/pdf/DeliveryOrderExport';
|
||||
|
||||
const MarketingDetail = ({
|
||||
initialValues,
|
||||
|
||||
+1
-5
@@ -1,9 +1,5 @@
|
||||
import * as Yup from 'yup';
|
||||
import {
|
||||
SalesOrderProductFormValues,
|
||||
SalesOrderProductSchema,
|
||||
} from '../sales-order/SalesOrderProduct.schema';
|
||||
import { de } from 'react-day-picker/locale';
|
||||
import { SalesOrderProductFormValues } from '@/components/pages/marketing/form/repeater/sales-order/SalesOrderProduct.schema';
|
||||
|
||||
type DeliveryOrderProductSchemaType = {
|
||||
id?: number | undefined;
|
||||
|
||||
+26
-5
@@ -10,12 +10,11 @@ import NumberInput from '@/components/input/NumberInput';
|
||||
import PatternInput from '@/components/input/PatternInput';
|
||||
import { formatVechicleNumber } from '@/lib/helper';
|
||||
import DateInput from '@/components/input/DateInput';
|
||||
import TextInput from '@/components/input/TextInput';
|
||||
import SelectInput, { OptionType } from '@/components/input/SelectInput';
|
||||
import { SalesOrderProductFormValues } from '../sales-order/SalesOrderProduct.schema';
|
||||
import { BaseSalesOrder } from '@/types/api/marketing/marketing';
|
||||
import Badge from '@/components/Badge';
|
||||
import { SalesProductToFieldValues } from '../../MarketingForm';
|
||||
import { SalesProductToFieldValues } from '@/components/pages/marketing/form/MarketingForm';
|
||||
import * as Yup from 'yup';
|
||||
|
||||
const DeliveryOrderProductForm = ({
|
||||
formState,
|
||||
@@ -40,13 +39,17 @@ const DeliveryOrderProductForm = ({
|
||||
null
|
||||
);
|
||||
const [currentInput, setCurrentInput] = useState<string>('');
|
||||
const salesOrder = salesOrders.find(
|
||||
(item) => item.id === initialValues?.marketing_product_id
|
||||
);
|
||||
|
||||
const formik = useFormik<DeliveryOrderProductFormValues>({
|
||||
enableReinitialize: true,
|
||||
initialValues: {
|
||||
delivery_date: initialValues?.delivery_date || undefined,
|
||||
vehicle_number: initialValues?.vehicle_number || undefined,
|
||||
marketing_product_id: initialValues?.marketing_product_id || undefined,
|
||||
marketing_product_id:
|
||||
salesOrder?.id || initialValues?.marketing_product_id || undefined,
|
||||
unit_price: initialValues?.unit_price || undefined,
|
||||
total_weight: initialValues?.total_weight || undefined,
|
||||
qty: initialValues?.qty || undefined,
|
||||
@@ -55,7 +58,25 @@ const DeliveryOrderProductForm = ({
|
||||
marketing_product: initialValues?.marketing_product || undefined,
|
||||
},
|
||||
isInitialValid: false,
|
||||
validationSchema: DeliveryOrderProductSchema,
|
||||
validationSchema: Yup.object().shape({
|
||||
...DeliveryOrderProductSchema.fields,
|
||||
|
||||
qty: Yup.lazy((_, context) => {
|
||||
// values diambil aman dari context
|
||||
const { parent } = context;
|
||||
|
||||
const mpId = parent?.marketing_product_id;
|
||||
const selectedSO = salesOrders.find((item) => item.id === mpId);
|
||||
|
||||
const maxQty = selectedSO?.qty ?? Infinity;
|
||||
|
||||
return Yup.number()
|
||||
.min(1, 'Kuantitas wajib diisi!')
|
||||
.max(maxQty, `Maksimal kuantitas adalah ${maxQty}`)
|
||||
.required('Kuantitas wajib diisi!');
|
||||
}),
|
||||
}),
|
||||
validateOnChange: true,
|
||||
validateOnBlur: true,
|
||||
onSubmit: async (values) => {
|
||||
setFormErrorMessage('');
|
||||
|
||||
@@ -20,7 +20,6 @@ import { isResponseSuccess } from '@/lib/api-helper';
|
||||
import { formatVechicleNumber } from '@/lib/helper';
|
||||
import PatternInput from '@/components/input/PatternInput';
|
||||
import Alert from '@/components/Alert';
|
||||
import { ProductCalculationFields, recalculate } from '../../MarketingForm';
|
||||
|
||||
const SalesOrderProductForm = ({
|
||||
initialValues,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Table from '@/components/Table';
|
||||
import { DeliveryOrderProductFormValues } from '../repeater/delivery-order/DeliverOrderProduct.schema';
|
||||
import { DeliveryOrderProductFormValues } from '@/components/pages/marketing/form/repeater/delivery-order/DeliverOrderProduct.schema';
|
||||
import Button from '@/components/Button';
|
||||
import { Icon } from '@iconify/react';
|
||||
import * as TanStack from '@tanstack/react-table';
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
ChickinFormValues,
|
||||
ChickinRequestFormValues,
|
||||
ChickinSchema,
|
||||
} from '../ChickinForm.schema';
|
||||
} from '@/components/pages/production/chickin/form/ChickinForm.schema';
|
||||
import DateInput from '@/components/input/DateInput';
|
||||
import Button from '@/components/Button';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Icon } from '@iconify/react';
|
||||
import Button from '../Button';
|
||||
import Button from '@/components/Button';
|
||||
import RowOptionsMenuWrapper from '@/components/table/RowOptionsMenuWrapper';
|
||||
|
||||
interface TableRowOptionsProps {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import SelectInput from '../input/SelectInput';
|
||||
import SelectInput from '@/components/input/SelectInput';
|
||||
|
||||
export interface OptionType {
|
||||
label: string;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Icon } from '@iconify/react';
|
||||
import Button from '../Button';
|
||||
import DebouncedTextInput from '../input/DebouncedTextInput';
|
||||
import Button from '@/components/Button';
|
||||
import DebouncedTextInput from '@/components/input/DebouncedTextInput';
|
||||
|
||||
interface TableToolbarProps {
|
||||
addButton?: {
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
CreateChickinPayload,
|
||||
UpdateChickinPayload,
|
||||
} from '@/types/api/production/chickin';
|
||||
import { BaseApiService } from '../base';
|
||||
import { BaseApiService } from '@/services/api/base';
|
||||
import { BaseApiResponse } from '@/types/api/api-general';
|
||||
import { httpClient } from '@/services/http/client';
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
ProjectFlock,
|
||||
UpdateProjectFlockPayload,
|
||||
} from '@/types/api/production/project-flock';
|
||||
import { BaseApiService } from '../base';
|
||||
import { BaseApiService } from '@/services/api/base';
|
||||
import {
|
||||
BaseApiResponse,
|
||||
BaseGroupedApproval,
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { Product } from '@/types/api/master-data/product';
|
||||
import { BaseMetadata } from '../base-metadata';
|
||||
import { Warehouse } from '@/types/api/master-data/warehouse';
|
||||
import { BaseMetadata } from '@/types/api/api-general';
|
||||
|
||||
export type BaseInventoryAdjustment = {
|
||||
id: number;
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import {
|
||||
import { ProductWarehouse } from '@/types/api/inventory/product-warehouse';
|
||||
import { Kandang } from '@/types/api/master-data/kandang';
|
||||
import { id } from 'react-day-picker/locale';
|
||||
import { Warehouse } from '../master-data/warehouse';
|
||||
import { Warehouse } from '@/types/api/master-data/warehouse';
|
||||
|
||||
/**
|
||||
* Base Data Response
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
import { Kandang } from '@/type/master-data/kandang';
|
||||
import { ProjectFlock } from '@/types/api/production/project-flock';
|
||||
import { ProductWarehouse } from '@/types/api/inventory/product-warehouse';
|
||||
import { Supplier } from '../master-data/supplier';
|
||||
import { BaseApproval } from '../api-general';
|
||||
import { Supplier } from '@/types/api/master-data/supplier';
|
||||
import { BaseApproval } from '@/types/api/api-general';
|
||||
|
||||
export type BaseProjectFlockKandang = {
|
||||
id: number;
|
||||
|
||||
Reference in New Issue
Block a user