mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE-326): Add ClosingApiService and types for closing sales data
This commit is contained in:
@@ -0,0 +1,163 @@
|
|||||||
|
import { BaseApiService } from './base';
|
||||||
|
import { BaseApiResponse, CreatedUser } from '@/types/api/api-general';
|
||||||
|
import { ClosingSales } from '@/types/api/closing/closing';
|
||||||
|
import { sleep } from '@/lib/helper';
|
||||||
|
|
||||||
|
const adminUser: CreatedUser = {
|
||||||
|
id: 1,
|
||||||
|
id_user: 1,
|
||||||
|
email: 'admin@example.com',
|
||||||
|
name: 'Admin User',
|
||||||
|
};
|
||||||
|
|
||||||
|
const DUMMY_SALES: ClosingSales[] = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
realization_date: '2025-01-15',
|
||||||
|
week_age: 4,
|
||||||
|
age_label: 'Week 4',
|
||||||
|
delivery_order_number: 'DO-2025-001',
|
||||||
|
product: {
|
||||||
|
id: 1,
|
||||||
|
name: 'Ayam Broiler',
|
||||||
|
brand: 'Brand A',
|
||||||
|
sku: 'AYM-001',
|
||||||
|
product_price: 20000,
|
||||||
|
selling_price: 25000,
|
||||||
|
tax: 10,
|
||||||
|
expiry_period: 30,
|
||||||
|
uom: {
|
||||||
|
id: 1,
|
||||||
|
name: 'Kg',
|
||||||
|
created_user: adminUser,
|
||||||
|
created_at: '2025-01-01T00:00:00Z',
|
||||||
|
updated_at: '2025-01-01T00:00:00Z',
|
||||||
|
},
|
||||||
|
product_category: {
|
||||||
|
id: 1,
|
||||||
|
code: 'LC001',
|
||||||
|
name: 'Live Chicken',
|
||||||
|
created_user: adminUser,
|
||||||
|
created_at: '2025-01-01T00:00:00Z',
|
||||||
|
updated_at: '2025-01-01T00:00:00Z',
|
||||||
|
},
|
||||||
|
suppliers: [],
|
||||||
|
flags: [],
|
||||||
|
created_user: adminUser,
|
||||||
|
created_at: '2025-01-01T00:00:00Z',
|
||||||
|
updated_at: '2025-01-01T00:00:00Z',
|
||||||
|
},
|
||||||
|
product_category: {
|
||||||
|
id: 1,
|
||||||
|
code: 'LC001',
|
||||||
|
name: 'Live Chicken',
|
||||||
|
created_user: adminUser,
|
||||||
|
created_at: '2025-01-01T00:00:00Z',
|
||||||
|
updated_at: '2025-01-01T00:00:00Z',
|
||||||
|
},
|
||||||
|
customer: {
|
||||||
|
id: 1,
|
||||||
|
name: 'PT. Bumi Mandiri',
|
||||||
|
pic_id: 1,
|
||||||
|
pic: adminUser,
|
||||||
|
type: 'COMPANY',
|
||||||
|
address: 'Jl. Industri No. 123',
|
||||||
|
phone: '+62-21-1234567',
|
||||||
|
email: 'info@bumimandiri.com',
|
||||||
|
account_number: '1234567890',
|
||||||
|
created_user: adminUser,
|
||||||
|
created_at: '2025-01-01T00:00:00Z',
|
||||||
|
updated_at: '2025-01-01T00:00:00Z',
|
||||||
|
},
|
||||||
|
quantity: 1000,
|
||||||
|
weight: 1850,
|
||||||
|
average: 1.85,
|
||||||
|
price: 25000,
|
||||||
|
total: 25000000,
|
||||||
|
kandang: {
|
||||||
|
id: 1,
|
||||||
|
name: 'Singaparna 1',
|
||||||
|
status: 'ACTIVE',
|
||||||
|
location: {
|
||||||
|
id: 1,
|
||||||
|
name: 'Singaparna',
|
||||||
|
address: 'Jl. Singaparna No. 1',
|
||||||
|
area: {
|
||||||
|
id: 1,
|
||||||
|
name: 'Tasikmalaya',
|
||||||
|
created_user: adminUser,
|
||||||
|
created_at: '2025-01-01T00:00:00Z',
|
||||||
|
updated_at: '2025-01-01T00:00:00Z',
|
||||||
|
},
|
||||||
|
created_user: adminUser,
|
||||||
|
created_at: '2025-01-01T00:00:00Z',
|
||||||
|
updated_at: '2025-01-01T00:00:00Z',
|
||||||
|
},
|
||||||
|
capacity: 1000,
|
||||||
|
pic: {
|
||||||
|
id: 1,
|
||||||
|
id_user: 1,
|
||||||
|
email: 'admin@example.com',
|
||||||
|
name: 'Admin User',
|
||||||
|
},
|
||||||
|
created_user: adminUser,
|
||||||
|
created_at: '2025-01-01T00:00:00Z',
|
||||||
|
updated_at: '2025-01-01T00:00:00Z',
|
||||||
|
},
|
||||||
|
kandang_id: 1,
|
||||||
|
payment_status: 'PAID',
|
||||||
|
created_user: adminUser,
|
||||||
|
created_at: '2025-01-15T10:00:00Z',
|
||||||
|
updated_at: '2025-01-15T10:00:00Z',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export class ClosingApiService extends BaseApiService<
|
||||||
|
ClosingSales,
|
||||||
|
unknown,
|
||||||
|
unknown
|
||||||
|
> {
|
||||||
|
constructor(basePath: string = '') {
|
||||||
|
super(basePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getPenjualan(
|
||||||
|
id: number
|
||||||
|
): Promise<BaseApiResponse<ClosingSales> | undefined> {
|
||||||
|
try {
|
||||||
|
// TODO: Remove dummy data when real API is ready
|
||||||
|
await sleep(750);
|
||||||
|
|
||||||
|
const saleData = DUMMY_SALES.find((sale) => sale.id === id);
|
||||||
|
|
||||||
|
if (!saleData) {
|
||||||
|
return {
|
||||||
|
code: 404,
|
||||||
|
status: 'error',
|
||||||
|
message: 'Sales data not found!',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
code: 200,
|
||||||
|
status: 'success',
|
||||||
|
message: 'Successfully get sales data!',
|
||||||
|
meta: {
|
||||||
|
page: 1,
|
||||||
|
limit: 10,
|
||||||
|
total_pages: 1,
|
||||||
|
total_results: 1,
|
||||||
|
},
|
||||||
|
data: saleData,
|
||||||
|
};
|
||||||
|
|
||||||
|
// const getPenjualanPath = `${this.basePath}/${id}/penjualan`;
|
||||||
|
// return await this.customRequest<BaseApiResponse<ClosingSales>>(getPenjualanPath);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching penjualan:', error);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ClosingApi = new ClosingApiService('/closing');
|
||||||
Vendored
+26
@@ -0,0 +1,26 @@
|
|||||||
|
import { BaseMetadata } from '@/types/api/api-general';
|
||||||
|
import { Kandang } from '@type/api/master-data/kandang';
|
||||||
|
import { Product } from '@type/api/master-data/product';
|
||||||
|
import { ProductCategory } from '@type/api/master-data/product-category';
|
||||||
|
import { Customer } from '@type/api/master-data/customer';
|
||||||
|
|
||||||
|
export type BaseClosingSales = {
|
||||||
|
id: number;
|
||||||
|
realization_date: string;
|
||||||
|
week_age: number;
|
||||||
|
age_label: string;
|
||||||
|
delivery_order_number: string;
|
||||||
|
product: Product;
|
||||||
|
product_category: ProductCategory;
|
||||||
|
customer: Customer;
|
||||||
|
quantity: number;
|
||||||
|
weight: number;
|
||||||
|
average: number;
|
||||||
|
price: number;
|
||||||
|
total: number;
|
||||||
|
kandang: Kandang;
|
||||||
|
kandang_id: number;
|
||||||
|
payment_status: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ClosingSales = BaseMetadata & BaseClosingSales;
|
||||||
Reference in New Issue
Block a user