mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
refactor(FE-326): change SalesReportTable to use BaseClosingSales type and support initial values
This commit is contained in:
@@ -7,25 +7,12 @@ import Table, { CustomHeaderRow } from '@/components/Table';
|
|||||||
import Card from '@/components/Card';
|
import Card from '@/components/Card';
|
||||||
import Badge from '@/components/Badge';
|
import Badge from '@/components/Badge';
|
||||||
import { formatCurrency, formatNumber, formatDate } from '@/lib/helper';
|
import { formatCurrency, formatNumber, formatDate } from '@/lib/helper';
|
||||||
|
import { BaseClosingSales } from '@/types/api/closing/closing';
|
||||||
|
|
||||||
type BaseClosingSales = {
|
interface SalesReportTableProps {
|
||||||
id: number;
|
type?: 'detail';
|
||||||
realization_date: string;
|
initialValues?: BaseClosingSales;
|
||||||
week_age: number;
|
}
|
||||||
age_label: string;
|
|
||||||
delivery_order_number: string;
|
|
||||||
product: string;
|
|
||||||
product_type: string;
|
|
||||||
customer: string;
|
|
||||||
quantity: number;
|
|
||||||
weight: number;
|
|
||||||
average: number;
|
|
||||||
price: number;
|
|
||||||
total: number;
|
|
||||||
kandang: string;
|
|
||||||
kandang_id: number;
|
|
||||||
payment_status: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
const generateCustomHeaders = (template: {
|
const generateCustomHeaders = (template: {
|
||||||
groups: Array<{
|
groups: Array<{
|
||||||
@@ -101,122 +88,18 @@ const generateCustomHeaders = (template: {
|
|||||||
return rows;
|
return rows;
|
||||||
};
|
};
|
||||||
|
|
||||||
const SalesReportTable = () => {
|
const SalesReportTable = ({
|
||||||
|
type = 'detail',
|
||||||
|
initialValues,
|
||||||
|
}: SalesReportTableProps) => {
|
||||||
const [activeTabId, setActiveTabId] = useState<string>('penjualan');
|
const [activeTabId, setActiveTabId] = useState<string>('penjualan');
|
||||||
|
|
||||||
const salesBroilerData: BaseClosingSales[] = useMemo(
|
const salesBroilerData: BaseClosingSales[] = useMemo(() => {
|
||||||
() => [
|
if (activeTabId === 'penjualan' && initialValues) {
|
||||||
{
|
return [initialValues];
|
||||||
id: 1,
|
}
|
||||||
realization_date: '2025-10-02',
|
return [];
|
||||||
week_age: 3,
|
}, [initialValues, activeTabId]);
|
||||||
age_label: '3 Weeks',
|
|
||||||
delivery_order_number: 'DO.MBU.699',
|
|
||||||
product: 'MBU BERLIAN CHICK A',
|
|
||||||
product_type: 'CHICKEN',
|
|
||||||
customer: 'TIAN YUSTIAN',
|
|
||||||
quantity: 1045,
|
|
||||||
weight: 1000,
|
|
||||||
average: 0.96,
|
|
||||||
price: 25300,
|
|
||||||
total: 25300000,
|
|
||||||
kandang: 'ACE AWANG',
|
|
||||||
kandang_id: 1,
|
|
||||||
payment_status: 'Lunas',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
realization_date: '2025-10-07',
|
|
||||||
week_age: 4,
|
|
||||||
age_label: '4 Weeks',
|
|
||||||
delivery_order_number: 'DO.MBU.1037',
|
|
||||||
product: 'MBU BERLIAN CHICK A',
|
|
||||||
product_type: 'CHICKEN',
|
|
||||||
customer: 'ZAENAL MUTAQIN',
|
|
||||||
quantity: 850,
|
|
||||||
weight: 1211.4,
|
|
||||||
average: 1.43,
|
|
||||||
price: 23700,
|
|
||||||
total: 28710180,
|
|
||||||
kandang: 'ACE AWANG',
|
|
||||||
kandang_id: 1,
|
|
||||||
payment_status: 'Lunas',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
realization_date: '2025-10-09',
|
|
||||||
week_age: 4,
|
|
||||||
age_label: '4 Weeks',
|
|
||||||
delivery_order_number: 'DO.MBU.1107',
|
|
||||||
product: 'MBU BERLIAN CHICK A',
|
|
||||||
product_type: 'CHICKEN',
|
|
||||||
customer: 'CORNELIUS TONY KUSTANTO',
|
|
||||||
quantity: 560,
|
|
||||||
weight: 990,
|
|
||||||
average: 1.77,
|
|
||||||
price: 23100,
|
|
||||||
total: 22869000,
|
|
||||||
kandang: 'ACE AWANG',
|
|
||||||
kandang_id: 1,
|
|
||||||
payment_status: 'Lunas',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 4,
|
|
||||||
realization_date: '2025-10-09',
|
|
||||||
week_age: 0,
|
|
||||||
age_label: '',
|
|
||||||
delivery_order_number: 'DO.MBU.1108',
|
|
||||||
product: 'MBU BERLIAN CHICK A',
|
|
||||||
product_type: 'CHICKEN',
|
|
||||||
customer: 'CV. KOPO AB',
|
|
||||||
quantity: 1088,
|
|
||||||
weight: 1934.3,
|
|
||||||
average: 1.78,
|
|
||||||
price: 23100,
|
|
||||||
total: 44682330,
|
|
||||||
kandang: 'ACE AWANG',
|
|
||||||
kandang_id: 1,
|
|
||||||
payment_status: 'Lunas',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 5,
|
|
||||||
realization_date: '2025-10-09',
|
|
||||||
week_age: 0,
|
|
||||||
age_label: '',
|
|
||||||
delivery_order_number: 'DO.MBU.1110',
|
|
||||||
product: 'MBU BERLIAN CHICK A',
|
|
||||||
product_type: 'CHICKEN',
|
|
||||||
customer: 'H. MAMAN ROMANSAH',
|
|
||||||
quantity: 624,
|
|
||||||
weight: 1121.4,
|
|
||||||
average: 1.8,
|
|
||||||
price: 22960,
|
|
||||||
total: 25747344,
|
|
||||||
kandang: 'ACE AWANG',
|
|
||||||
kandang_id: 1,
|
|
||||||
payment_status: 'Lunas',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 6,
|
|
||||||
realization_date: '2025-10-09',
|
|
||||||
week_age: 0,
|
|
||||||
age_label: '',
|
|
||||||
delivery_order_number: 'DO.MBU.1133',
|
|
||||||
product: 'MBU BERLIAN CHICK A',
|
|
||||||
product_type: 'CHICKEN',
|
|
||||||
customer: 'PT. SAMUDERA MULIA LESTARI',
|
|
||||||
quantity: 624,
|
|
||||||
weight: 1102.3,
|
|
||||||
average: 1.77,
|
|
||||||
price: 23100,
|
|
||||||
total: 25463130,
|
|
||||||
kandang: 'ACE AWANG',
|
|
||||||
kandang_id: 1,
|
|
||||||
payment_status: 'Lunas',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
const totals = useMemo(() => {
|
const totals = useMemo(() => {
|
||||||
const totalQuantity = salesBroilerData.reduce(
|
const totalQuantity = salesBroilerData.reduce(
|
||||||
|
|||||||
Reference in New Issue
Block a user