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