diff --git a/src/components/pages/finance/add/FormFinanceAdd.tsx b/src/components/pages/finance/add/FormFinanceAdd.tsx
index 168d306a..29e311cc 100644
--- a/src/components/pages/finance/add/FormFinanceAdd.tsx
+++ b/src/components/pages/finance/add/FormFinanceAdd.tsx
@@ -54,9 +54,6 @@ const FormFinanceAdd = ({
}: FormFinanceAddProps) => {
const router = useRouter();
const [serverErrorMessage, setServerErrorMessage] = useState('');
- const [isSupplier, setIsSupplier] = useState(
- initialValues?.party?.type === 'SUPPLIER'
- );
// ===== Formik =====
const formikInitialValues = useMemo((): FinanceFormValues => {
@@ -215,7 +212,7 @@ const FormFinanceAdd = ({
? formik.errors.party_type_option
: ''
}
- isDisabled={type === 'edit' || isSupplier}
+ isDisabled={type === 'edit'}
required
isClearable
/>
@@ -254,7 +251,11 @@ const FormFinanceAdd = ({
}
required
isClearable
- isDisabled={!formik.values.party_type_option?.value || isSupplier}
+ isDisabled={
+ !formik.values.party_type_option?.value ||
+ (type === 'edit' &&
+ formik.values.party_type_option.value == 'SUPPLIER')
+ }
/>
{serverErrorMessage && (
@@ -433,7 +427,7 @@ const FormFinanceAdd = ({
diff --git a/src/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance.tsx b/src/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance.tsx
index cb46c0e1..a63caa94 100644
--- a/src/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance.tsx
+++ b/src/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance.tsx
@@ -396,7 +396,7 @@ const FormFinanceAddInitialBalance = ({
diff --git a/src/components/pages/finance/add/injection/FormFinanceInjection.tsx b/src/components/pages/finance/add/injection/FormFinanceInjection.tsx
index d685619d..ff49005c 100644
--- a/src/components/pages/finance/add/injection/FormFinanceInjection.tsx
+++ b/src/components/pages/finance/add/injection/FormFinanceInjection.tsx
@@ -257,7 +257,7 @@ const FormFinanceInjection = ({
diff --git a/src/components/pages/marketing/form/repeater/delivery-order/DeliverOrderProduct.tsx b/src/components/pages/marketing/form/repeater/delivery-order/DeliverOrderProduct.tsx
index 56f00135..cd6368e0 100644
--- a/src/components/pages/marketing/form/repeater/delivery-order/DeliverOrderProduct.tsx
+++ b/src/components/pages/marketing/form/repeater/delivery-order/DeliverOrderProduct.tsx
@@ -143,11 +143,13 @@ const DeliveryOrderProductForm = ({
// ===== SOURCE FIELDS =====
case 'qty': {
if (avgWeight > 0) {
- formik.setFieldValue('total_weight', roundWeight(qty * avgWeight));
- }
+ const tw = roundWeight(qty * avgWeight);
+ formik.setFieldValue('total_weight', tw);
- if (unitPrice > 0) {
- formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
+ // Hitung total_price berdasarkan unit_price × total_weight
+ if (unitPrice > 0) {
+ formik.setFieldValue('total_price', roundPrice(unitPrice * tw));
+ }
}
break;
}
@@ -157,16 +159,21 @@ const DeliveryOrderProductForm = ({
const tw = roundWeight(qty * avgWeight);
formik.setFieldValue('total_weight', tw);
+ // Hitung total_price berdasarkan unit_price × total_weight
if (unitPrice > 0) {
- formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
+ formik.setFieldValue('total_price', roundPrice(unitPrice * tw));
}
}
break;
}
case 'unit_price': {
- if (unitPrice > 0) {
- formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
+ if (unitPrice > 0 && totalWeight > 0) {
+ // Hitung total_price berdasarkan unit_price × total_weight
+ formik.setFieldValue(
+ 'total_price',
+ roundPrice(unitPrice * totalWeight)
+ );
}
break;
}
@@ -175,13 +182,25 @@ const DeliveryOrderProductForm = ({
case 'total_weight': {
if (totalWeight > 0) {
formik.setFieldValue('avg_weight', roundWeight(totalWeight / qty));
+
+ // Hitung ulang total_price berdasarkan unit_price × total_weight
+ if (unitPrice > 0) {
+ formik.setFieldValue(
+ 'total_price',
+ roundPrice(unitPrice * totalWeight)
+ );
+ }
}
break;
}
case 'total_price': {
- if (totalPrice > 0) {
- formik.setFieldValue('unit_price', roundPrice(totalPrice / qty));
+ if (totalPrice > 0 && totalWeight > 0) {
+ // Hitung unit_price berdasarkan total_price / total_weight
+ formik.setFieldValue(
+ 'unit_price',
+ roundPrice(totalPrice / totalWeight)
+ );
}
break;
}
@@ -382,7 +401,7 @@ const DeliveryOrderProductForm = ({
/>
{
diff --git a/src/components/pages/marketing/form/repeater/sales-order/SalesOrderProductForm.tsx b/src/components/pages/marketing/form/repeater/sales-order/SalesOrderProductForm.tsx
index 8bea75c4..767cd9b3 100644
--- a/src/components/pages/marketing/form/repeater/sales-order/SalesOrderProductForm.tsx
+++ b/src/components/pages/marketing/form/repeater/sales-order/SalesOrderProductForm.tsx
@@ -49,17 +49,6 @@ const SalesOrderProductForm = ({
const [selectedProductWarehouse, setSelectedProductWarehouse] =
useState(null);
- // ============ Fetch Data ============
- const { data: productData } = useSWR(
- selectedProductWarehouse?.product_id
- ? ProductApi.basePath + '/' + selectedProductWarehouse?.product_id
- : null,
- () =>
- selectedProductWarehouse?.product_id
- ? ProductApi.getSingle(selectedProductWarehouse?.product_id)
- : undefined
- );
-
// ============ Formik ============
const formik = useFormik({
enableReinitialize: true,
@@ -174,15 +163,28 @@ const SalesOrderProductForm = ({
if (qty <= 0) return;
+ // Cek apakah produk memiliki flag OVK atau PAKAN
+ const productFlags = selectedProductWarehouse?.product?.flags || [];
+ const isOvkOrPakan =
+ productFlags.includes('OVK') || productFlags.includes('PAKAN');
+
switch (field) {
// ===== SOURCE FIELDS =====
case 'qty': {
if (avgWeight > 0) {
- formik.setFieldValue('total_weight', roundWeight(qty * avgWeight));
- }
+ const tw = roundWeight(qty * avgWeight);
+ formik.setFieldValue('total_weight', tw);
- if (unitPrice > 0) {
- formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
+ // Hitung total_price berdasarkan flag produk
+ if (unitPrice > 0) {
+ if (isOvkOrPakan) {
+ // Untuk OVK/PAKAN: total_price = qty × unit_price
+ formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
+ } else {
+ // Untuk produk lain: total_price = unit_price × total_weight
+ formik.setFieldValue('total_price', roundPrice(unitPrice * tw));
+ }
+ }
}
break;
}
@@ -192,8 +194,15 @@ const SalesOrderProductForm = ({
const tw = roundWeight(qty * avgWeight);
formik.setFieldValue('total_weight', tw);
+ // Hitung total_price berdasarkan flag produk
if (unitPrice > 0) {
- formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
+ if (isOvkOrPakan) {
+ // Untuk OVK/PAKAN: total_price = qty × unit_price
+ formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
+ } else {
+ // Untuk produk lain: total_price = unit_price × total_weight
+ formik.setFieldValue('total_price', roundPrice(unitPrice * tw));
+ }
}
}
break;
@@ -201,7 +210,16 @@ const SalesOrderProductForm = ({
case 'unit_price': {
if (unitPrice > 0) {
- formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
+ if (isOvkOrPakan) {
+ // Untuk OVK/PAKAN: total_price = qty × unit_price
+ formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
+ } else if (totalWeight > 0) {
+ // Untuk produk lain: total_price = unit_price × total_weight
+ formik.setFieldValue(
+ 'total_price',
+ roundPrice(unitPrice * totalWeight)
+ );
+ }
}
break;
}
@@ -210,13 +228,36 @@ const SalesOrderProductForm = ({
case 'total_weight': {
if (totalWeight > 0) {
formik.setFieldValue('avg_weight', roundWeight(totalWeight / qty));
+
+ // Hitung ulang total_price berdasarkan flag produk
+ if (unitPrice > 0) {
+ if (isOvkOrPakan) {
+ // Untuk OVK/PAKAN: total_price = qty × unit_price
+ formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
+ } else {
+ // Untuk produk lain: total_price = unit_price × total_weight
+ formik.setFieldValue(
+ 'total_price',
+ roundPrice(unitPrice * totalWeight)
+ );
+ }
+ }
}
break;
}
case 'total_price': {
if (totalPrice > 0) {
- formik.setFieldValue('unit_price', roundPrice(totalPrice / qty));
+ if (isOvkOrPakan && qty > 0) {
+ // Untuk OVK/PAKAN: unit_price = total_price / qty
+ formik.setFieldValue('unit_price', roundPrice(totalPrice / qty));
+ } else if (totalWeight > 0) {
+ // Untuk produk lain: unit_price = total_price / total_weight
+ formik.setFieldValue(
+ 'unit_price',
+ roundPrice(totalPrice / totalWeight)
+ );
+ }
}
break;
}
@@ -232,7 +273,7 @@ const SalesOrderProductForm = ({
handleBlurField(currentInput);
formik.setFieldValue(
'uom',
- isResponseSuccess(productData) ? productData?.data?.uom.name : ''
+ selectedProductWarehouse?.product?.uom?.name
);
},
}
@@ -330,9 +371,7 @@ const SalesOrderProductForm = ({
endAdornment={
- {isResponseSuccess(productData)
- ? productData?.data?.uom.name
- : ''}
+ {selectedProductWarehouse?.product?.uom?.name}
}
@@ -343,17 +382,13 @@ const SalesOrderProductForm = ({
warehouseSourceRawData?.data?.find(
(item) => item.id === formik.values.product_warehouse_id
)?.quantity ?? 0
- )} ${
- isResponseSuccess(productData)
- ? productData?.data?.uom.name
- : ''
- }`
+ )} ${selectedProductWarehouse?.product?.uom?.name}`
: ''
}
/>
{
diff --git a/src/components/pages/production/recording/RecordingTable.tsx b/src/components/pages/production/recording/RecordingTable.tsx
index 8d8caad1..cd98b597 100644
--- a/src/components/pages/production/recording/RecordingTable.tsx
+++ b/src/components/pages/production/recording/RecordingTable.tsx
@@ -1,6 +1,12 @@
'use client';
-import React, { useCallback, useState, useMemo, useEffect } from 'react';
+import React, {
+ useCallback,
+ useState,
+ useMemo,
+ useEffect,
+ useRef,
+} from 'react';
import { RefObject } from 'react';
import useSWR from 'swr';
import { Icon } from '@iconify/react';
@@ -28,6 +34,7 @@ import { useTableFilter } from '@/services/hooks/useTableFilter';
import toast from 'react-hot-toast';
import Badge from '@/components/Badge';
import CheckboxInput from '@/components/input/CheckboxInput';
+import { useUiStore } from '@/stores/ui/ui.store';
import { BaseApproval, BaseApiResponse } from '@/types/api/api-general';
const RowOptionsMenu = ({
@@ -344,6 +351,9 @@ const ApprovalHistoryModal = ({
};
const RecordingTable = () => {
+ const { searchValue, setSearchValue, resetSearchValue } = useUiStore();
+ const previousPathRef = useRef(null);
+
const {
state: tableFilterState,
updateFilter,
@@ -352,7 +362,7 @@ const RecordingTable = () => {
toQueryString: getTableFilterQueryString,
} = useTableFilter({
initial: {
- search: '',
+ search: searchValue,
areaFilter: '',
locationFilter: '',
kandangFilter: '',
@@ -403,12 +413,35 @@ const RecordingTable = () => {
);
}, []);
+ useEffect(() => {
+ // Store current path on mount
+ previousPathRef.current = window.location.pathname;
+
+ return () => {
+ const currentPath = window.location.pathname;
+
+ // if both paths are within /production/recording module
+ const isCurrentPathRecording = currentPath.includes(
+ '/production/recording'
+ );
+ const isPreviousPathRecording = previousPathRef.current?.includes(
+ '/production/recording'
+ );
+
+ // reset if we outside recording module entirely
+ if (isPreviousPathRecording && !isCurrentPathRecording) {
+ resetSearchValue();
+ }
+ };
+ }, [resetSearchValue]);
+
const searchChangeHandler = useCallback(
(e: React.ChangeEvent) => {
updateFilter('search', e.target.value);
+ setSearchValue(e.target.value);
setPage(1);
},
- [updateFilter, setPage]
+ [updateFilter, setSearchValue, setPage]
);
const pageSizeChangeHandler = useCallback(
diff --git a/src/components/pages/production/recording/form/RecordingForm.tsx b/src/components/pages/production/recording/form/RecordingForm.tsx
index 7365c6ca..a000f4a3 100644
--- a/src/components/pages/production/recording/form/RecordingForm.tsx
+++ b/src/components/pages/production/recording/form/RecordingForm.tsx
@@ -23,6 +23,7 @@ import ConfirmationModalWithNotes from '@/components/modal/ConfirmationModalWith
import Modal, { useModal } from '@/components/Modal';
import AlertErrorList from '@/components/helper/form/FormErrors';
import Table from '@/components/Table';
+import Tooltip from '@/components/Tooltip';
import { type ColumnDef } from '@tanstack/react-table';
import {
@@ -197,6 +198,11 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
const router = useRouter();
// ===== STATE MANAGEMENT =====
+ const [selectedRecordDate, setSelectedRecordDate] = useState(
+ initialValues?.record_datetime
+ ? new Date(initialValues.record_datetime).toISOString().split('T')[0]
+ : new Date().toISOString().split('T')[0]
+ );
const [selectedStocks, setSelectedStocks] = useState([]);
const [selectedDepletions, setSelectedDepletions] = useState([]);
const [selectedEggs, setSelectedEggs] = useState([]);
@@ -911,6 +917,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
baseValues = getRecordingGrowingFormInitialValues(initialValues);
}
+ baseValues.record_date = selectedRecordDate;
+
if (type === 'add') {
baseValues.location = selectedLocation
? {
@@ -967,13 +975,22 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
}
return baseValues;
- }, [initialValues, isLayingCategory, projectFlockKandangDetail, type]);
+ }, [
+ initialValues,
+ isLayingCategory,
+ projectFlockKandangDetail,
+ type,
+ selectedRecordDate,
+ selectedLocation,
+ selectedProjectFlock,
+ selectedKandang,
+ ]);
const formik = useFormik<
RecordingGrowingFormValues | RecordingLayingFormValues
>({
initialValues: formikInitialValues,
- enableReinitialize: true,
+ enableReinitialize: false,
validationSchema: (() => {
let schema;
if (isLayingCategory) {
@@ -1333,6 +1350,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
(e: React.ChangeEvent) => {
const newDate = e.target.value;
formik.setFieldValue('record_date', newDate);
+ setSelectedRecordDate(newDate);
setCurrentRecordDate(newDate);
if (duplicateErrorShown) {
toast.dismiss();
@@ -2799,7 +2817,23 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
)}
Kondisi Telur |
Jumlah |
- Total Berat (Kilogram) |
+
+ Total Berat (Kilogram)
+
+
+
+ |
{(type as 'add' | 'edit' | 'detail') !== 'detail' && (
Action |
)}
@@ -2905,7 +2939,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
value={egg.weight ?? ''}
onChange={handleEggWeightChangeWrapper(idx)}
onBlur={formik.handleBlur}
- decimalScale={0}
+ decimalScale={3}
allowNegative={false}
thousandSeparator=','
decimalSeparator='.'
diff --git a/src/components/pages/report/finance/tab/DebtSupplierTab.tsx b/src/components/pages/report/finance/tab/DebtSupplierTab.tsx
index 14fccffa..c5065d29 100644
--- a/src/components/pages/report/finance/tab/DebtSupplierTab.tsx
+++ b/src/components/pages/report/finance/tab/DebtSupplierTab.tsx
@@ -678,7 +678,13 @@ const DebtSupplierTab = () => {
placeholder='Pilih Supplier'
isMulti
options={supplierOptions}
- value={formik.values.supplierIds || []}
+ value={
+ (formik.values.supplierIds as
+ | { value: number; label: string }
+ | { value: number; label: string }[]
+ | null
+ | undefined) || []
+ }
onChange={(val) => {
formik.setFieldValue(
'supplierIds',
@@ -702,7 +708,13 @@ const DebtSupplierTab = () => {
label='Filter Berdasarkan'
placeholder='Pilih Filter Berdasarkan'
options={dataTypeOptions}
- value={formik.values.filterBy || null}
+ value={
+ (formik.values.filterBy as
+ | { value: string; label: string }
+ | { value: string; label: string }[]
+ | null
+ | undefined) || null
+ }
onChange={(val) => {
formik.setFieldValue(
'filterBy',
diff --git a/src/lib/helper.ts b/src/lib/helper.ts
index dcd56e16..665c81f1 100644
--- a/src/lib/helper.ts
+++ b/src/lib/helper.ts
@@ -32,6 +32,11 @@ export const formatNumber = (
}).format(value);
};
+export const safeRound = (num: number, decimals: number) => {
+ const factor = 10 ** decimals;
+ return Math.round((num + Number.EPSILON) * factor) / factor;
+};
+
export const formatTitleCase = (value: string) => {
return value
.toLowerCase()
diff --git a/src/services/api/report/production-result.ts b/src/services/api/report/production-result.ts
index 251e3eb4..43417aff 100644
--- a/src/services/api/report/production-result.ts
+++ b/src/services/api/report/production-result.ts
@@ -1,6 +1,6 @@
import * as XLSX from 'xlsx';
import toast from 'react-hot-toast';
-import { formatDate } from '@/lib/helper';
+import { formatDate, safeRound } from '@/lib/helper';
import { isResponseSuccess } from '@/lib/api-helper';
import { BaseApiService } from '@/services/api/base';
import { httpClient, httpClientFetcher } from '@/services/http/client';
@@ -32,21 +32,21 @@ export class ProductionResultReportApiService extends BaseApiService<
const mappedProductionResults: {
projectFlockKandang: BaseProjectFlockKandang;
productionResult: ProductionResult[] | null;
- }[] = [];
+ }[] = await Promise.all(
+ (projectFlockKandangs || []).map(async (projectFlockKandang) => {
+ const getProductionResultPath = `${this.basePath}/${projectFlockKandang.id}?page=1&limit=99999999`;
+ const getProductionResultRes = await httpClient<
+ BaseApiResponse
+ >(getProductionResultPath);
- projectFlockKandangs?.forEach(async (projectFlockKandang) => {
- const getProductionResultPath = `${this.basePath}/${projectFlockKandang.id}?page=1&limit=99999999`;
- const getProductionResultRes = await httpClient<
- BaseApiResponse
- >(getProductionResultPath);
-
- mappedProductionResults.push({
- projectFlockKandang,
- productionResult: isResponseSuccess(getProductionResultRes)
- ? getProductionResultRes.data
- : null,
- });
- });
+ return {
+ projectFlockKandang,
+ productionResult: isResponseSuccess(getProductionResultRes)
+ ? getProductionResultRes.data
+ : null,
+ };
+ })
+ );
const rows = mappedProductionResults;
if (!rows || rows.length === 0) {
@@ -68,44 +68,46 @@ export class ProductionResultReportApiService extends BaseApiService<
row.productionResult?.forEach((productionResult) => {
groupedData[kandangName].push({
- woa: productionResult.woa,
- bw: productionResult.bw,
- std_bw: productionResult.std_bw,
- uniformity: productionResult.uniformity,
+ woa: safeRound(productionResult.woa, 2),
+ bw: safeRound(productionResult.bw, 2),
+ std_bw: safeRound(productionResult.std_bw, 2),
+ uniformity: safeRound(productionResult.uniformity, 2),
std_uniformity: productionResult.std_uniformity,
- dep_kum: productionResult.dep_kum,
- dep_std: productionResult.dep_std,
- butiran_utuh: productionResult.butiran_utuh,
- butiran_putih: productionResult.butiran_putih,
- butiran_retak: productionResult.butiran_retak,
- butiran_pecah: productionResult.butiran_pecah,
- butiran_jumlah: productionResult.butiran_jumlah,
- total_butir: productionResult.total_butir,
- kg_utuh: productionResult.kg_utuh,
- kg_putih: productionResult.kg_putih,
- kg_retak: productionResult.kg_retak,
- kg_pecah: productionResult.kg_pecah,
- kg_jumlah: productionResult.kg_jumlah,
- total_kg: productionResult.total_kg,
- persen_utuh: productionResult.persen_utuh,
- persen_putih: productionResult.persen_putih,
- persen_retak: productionResult.persen_retak,
- persen_pecah: productionResult.persen_pecah,
- hd: productionResult.hd,
- hd_std: productionResult.hd_std,
- fi: productionResult.fi,
- fi_std: productionResult.fi_std,
- em: productionResult.em,
- em_std: productionResult.em_std,
- ew: productionResult.ew,
- ew_std: productionResult.ew_std,
- fcr: productionResult.fcr,
- fcr_std: productionResult.fcr_std,
- hh: productionResult.hh,
- hh_std: productionResult.hh_std,
- project_flock_name: productionResult.project_flock.name,
- project_flock_category: productionResult.project_flock.category,
- kandang_name: productionResult.project_flock.kandang.name,
+ dep_kum: safeRound(productionResult.dep_kum, 2),
+ dep_std: safeRound(productionResult.dep_std, 2),
+ butiran_utuh: safeRound(productionResult.butiran_utuh, 2),
+ butiran_putih: safeRound(productionResult.butiran_putih, 2),
+ butiran_retak: safeRound(productionResult.butiran_retak, 2),
+ butiran_pecah: safeRound(productionResult.butiran_pecah, 2),
+ butiran_jumlah: safeRound(productionResult.butiran_jumlah, 2),
+ total_butir: safeRound(productionResult.total_butir, 2),
+ kg_utuh: safeRound(productionResult.kg_utuh, 2),
+ kg_putih: safeRound(productionResult.kg_putih, 2),
+ kg_retak: safeRound(productionResult.kg_retak, 2),
+ kg_pecah: safeRound(productionResult.kg_pecah, 2),
+ kg_jumlah: safeRound(productionResult.kg_jumlah, 2),
+ total_kg: safeRound(productionResult.total_kg, 2),
+ persen_utuh: safeRound(productionResult.persen_utuh, 2),
+ persen_putih: safeRound(productionResult.persen_putih, 2),
+ persen_retak: safeRound(productionResult.persen_retak, 2),
+ persen_pecah: safeRound(productionResult.persen_pecah, 2),
+ hd: safeRound(productionResult.hd, 2),
+ hd_std: safeRound(productionResult.hd_std, 2),
+ fi: safeRound(productionResult.fi, 2),
+ fi_std: safeRound(productionResult.fi_std, 2),
+ em: safeRound(productionResult.em, 2),
+ em_std: safeRound(productionResult.em_std, 2),
+ ew: safeRound(productionResult.ew, 2),
+ ew_std: safeRound(productionResult.ew_std, 2),
+ fcr: safeRound(productionResult.fcr, 2),
+ fcr_std: safeRound(productionResult.fcr_std, 2),
+ hh: safeRound(productionResult.hh, 2),
+ hh_std: safeRound(productionResult.hh_std, 2),
+ project_flock_name:
+ row.projectFlockKandang.project_flock.flock_name,
+ project_flock_category:
+ row.projectFlockKandang.project_flock.category,
+ kandang_name: row.projectFlockKandang.kandang.name,
created_at: formatDate(productionResult.created_at, 'YYYY-MM-DD'),
updated_at: formatDate(productionResult.updated_at, 'YYYY-MM-DD'),
});
diff --git a/src/stores/ui/slices/table.slice.ts b/src/stores/ui/slices/table.slice.ts
new file mode 100644
index 00000000..eb6e7cc2
--- /dev/null
+++ b/src/stores/ui/slices/table.slice.ts
@@ -0,0 +1,28 @@
+import { StateCreator } from 'zustand';
+
+export interface TableState {
+ searchValue: string;
+}
+
+export interface TableUISlice {
+ searchValue: string;
+ setSearchValue: (value: string) => void;
+ resetSearchValue: () => void;
+}
+
+export const createTableUISlice: StateCreator<
+ TableUISlice,
+ [],
+ [],
+ TableUISlice
+> = (set) => ({
+ // Initial state
+ searchValue: '',
+
+ // Actions
+ setSearchValue: (value) => set({ searchValue: value }),
+
+ resetSearchValue: () => {
+ return set({ searchValue: '' });
+ },
+});
diff --git a/src/stores/ui/ui.store.ts b/src/stores/ui/ui.store.ts
index cbc5785d..05adbb9b 100644
--- a/src/stores/ui/ui.store.ts
+++ b/src/stores/ui/ui.store.ts
@@ -1,18 +1,28 @@
'use client';
import { create } from 'zustand';
-import { devtools } from 'zustand/middleware';
+import { devtools, persist } from 'zustand/middleware';
import { UIStore } from '@/types/stores';
import { createMainUiSlice } from '@/stores/ui/slices/main.slice';
import { createDrawerUISlice } from '@/stores/ui/slices/drawer.slice';
+import { createTableUISlice } from '@/stores/ui/slices/table.slice';
export const useUiStore = create()(
devtools(
- (...args) => ({
- ...createMainUiSlice(...args),
- ...createDrawerUISlice(...args),
- }),
+ persist(
+ (...args) => ({
+ ...createMainUiSlice(...args),
+ ...createDrawerUISlice(...args),
+ ...createTableUISlice(...args),
+ }),
+ {
+ name: 'ui-cache',
+ partialize: (state) => ({
+ searchValue: state.searchValue,
+ }),
+ }
+ ),
{
name: 'UIStore',
}
diff --git a/src/types/api/closing.d.ts b/src/types/api/closing.d.ts
index 8135c013..31a0248d 100644
--- a/src/types/api/closing.d.ts
+++ b/src/types/api/closing.d.ts
@@ -17,6 +17,7 @@ export type BaseSales = {
id: number;
realization_date: string;
age: number;
+ week: number;
do_number: string;
product: Product;
customer: Customer;
diff --git a/src/types/stores.d.ts b/src/types/stores.d.ts
index 528309c7..5b0be6f3 100644
--- a/src/types/stores.d.ts
+++ b/src/types/stores.d.ts
@@ -26,7 +26,13 @@ type DrawerUISlice = {
setIsNextStep: (v: boolean) => void;
};
-export type UIStore = MainUiSlice & DrawerUISlice;
+type TableUISlice = {
+ searchValue: string;
+ setSearchValue: (value: string) => void;
+ resetSearchValue: () => void;
+};
+
+export type UIStore = MainUiSlice & DrawerUISlice & TableUISlice;
type ProductionStandardFormSlice = {
formData: {