From 46e072bbcfaf091a9c0fafe30c3504dd95524c7f Mon Sep 17 00:00:00 2001 From: rstubryan Date: Fri, 5 Dec 2025 11:15:41 +0700 Subject: [PATCH] refactor(FE-327): Map Indonesian sales fields and add API sample --- .../pages/closing/sale/SalesReportTable.tsx | 94 ++++++++++++++++--- 1 file changed, 81 insertions(+), 13 deletions(-) diff --git a/src/components/pages/closing/sale/SalesReportTable.tsx b/src/components/pages/closing/sale/SalesReportTable.tsx index ca616107..d93dbf2e 100644 --- a/src/components/pages/closing/sale/SalesReportTable.tsx +++ b/src/components/pages/closing/sale/SalesReportTable.tsx @@ -7,7 +7,7 @@ import Table, { CustomHeaderRow } from '@/components/Table'; import Card from '@/components/Card'; import Badge from '@/components/Badge'; import { formatCurrency, formatNumber, formatDate } from '@/lib/helper'; -import { BaseClosingSales } from '@/types/api/closing/closing'; +import { BaseClosingSales, BaseSales } from '@/types/api/closing/closing'; interface SalesReportTableProps { type?: 'detail'; @@ -110,8 +110,7 @@ const generateCustomHeaders = (template: { }; // TODO: TEMPORARY - Remove this when backend API returns English field names -// eslint-disable-next-line @typescript-eslint/no-explicit-any -const mapIndonesianDataToEnglish = (data: any): BaseClosingSales[] => { +const mapIndonesianDataToEnglish = (data: BaseClosingSales): BaseSales[] => { if (!data || !data.penjualan || !Array.isArray(data.penjualan)) { return []; } @@ -120,11 +119,11 @@ const mapIndonesianDataToEnglish = (data: any): BaseClosingSales[] => { return data.penjualan.map((item: any) => ({ id: item.id, realization_date: item.tanggal_realisasi, + week_age: item.umur_minggu, age_label: item.umur_label, - umur_minggu: item.umur_minggu, delivery_order_number: item.no_do, product: item.produk, - jenis_produk: item.jenis_produk, + product_category: item.jenis_produk, customer: item.customer, quantity: item.qty, weight: item.kg, @@ -132,6 +131,7 @@ const mapIndonesianDataToEnglish = (data: any): BaseClosingSales[] => { price: item.harga, total: item.total, kandang: item.kandang, + kandang_id: item.kandang_id, payment_status: item.status_pembayaran, })); }; @@ -143,16 +143,14 @@ const SalesReportTable = ({ }: SalesReportTableProps) => { const [activeTabId, setActiveTabId] = useState('penjualan'); - const salesBroilerData: BaseClosingSales[] = useMemo(() => { + const salesBroilerData: BaseSales[] = useMemo(() => { if (activeTabId === 'penjualan' && initialValues) { // TODO: TEMPORARY - Remove this when backend API returns English field names - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore if (initialValues.penjualan && Array.isArray(initialValues.penjualan)) { return mapIndonesianDataToEnglish(initialValues); } // END TODO - return [initialValues]; + return []; } return []; }, [initialValues, activeTabId]); @@ -208,7 +206,7 @@ const SalesReportTable = ({ }; }, [salesBroilerData]); - const salesColumns: ColumnDef[] = useMemo( + const salesColumns: ColumnDef[] = useMemo( () => [ { id: 'realization_date', @@ -418,9 +416,7 @@ const SalesReportTable = ({ label: 'Penjualan', content: (
-

- Penjualan {'(diisi dengan jenis penjualan)'} -

+

Penjualan

+
+ +
+            {JSON.stringify(
+              {
+                code: 200,
+                status: 'success',
+                message: 'Retrieved sales report successfully',
+                data: {
+                  project_type: 'GROWING',
+                  flock_id: '1',
+                  period: 10,
+                  sales: [
+                    {
+                      id: 1,
+                      realization_date: '2025-12-05T02:22:17.443165Z',
+                      age: 20,
+                      do_number: 'SO-DO-10001',
+                      product: {
+                        id: 1,
+                        name: 'Laptop Gaming X500',
+                        product_price: 15000000,
+                        selling_price: 16500000.5,
+                        uom: {
+                          id: 1,
+                          name: 'KG',
+                        },
+                        flags: ['Best Seller', 'New Arrival'],
+                        product_category: {
+                          id: 5,
+                          name: 'Elektronik',
+                          code: 'DOC',
+                        },
+                      },
+                      customer: {
+                        id: 12345,
+                        name: 'PT. Solusi Teknologi Nusantara',
+                        type: 'Perusahaan',
+                        account_number: 'ACC1234567890',
+                        balance: 5000000.75,
+                        pic: {
+                          id: 101,
+                          name: 'Budi Santoso',
+                          email: 'budi.santoso@example.com',
+                          role: 'Manajer Akun',
+                        },
+                      },
+                      qty: 6348,
+                      weight: 19142,
+                      avg_weight: 3.02,
+                      price: 26419,
+                      total_price: 505712498,
+                      kandang: {
+                        id: 1,
+                        name: 'cibeber 1',
+                      },
+                      payment_status: 'Paid',
+                    },
+                  ],
+                },
+              },
+              null,
+              2
+            )}
+          
+
+
); };