Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { api } from '$lib/api';
|
||||
import type { ApiResponse } from '$lib/api';
|
||||
|
||||
// Interfaces
|
||||
export interface DepreciationCatalog {
|
||||
id: number;
|
||||
tenant_id: number;
|
||||
company_id: number;
|
||||
fraction: string;
|
||||
description: string;
|
||||
depreciation_rate: number;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface DepreciationCatalogListResponse {
|
||||
items: DepreciationCatalog[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
pages: number;
|
||||
}
|
||||
|
||||
// API Functions
|
||||
export async function getDepreciationCatalog(
|
||||
page = 1,
|
||||
pageSize = 100,
|
||||
companyId: number,
|
||||
filters: Record<string, any> = {}
|
||||
): Promise<ApiResponse<DepreciationCatalogListResponse>> {
|
||||
const params = new URLSearchParams({
|
||||
company_id: companyId.toString(),
|
||||
page: page.toString(),
|
||||
page_size: pageSize.toString(),
|
||||
...filters
|
||||
});
|
||||
|
||||
return api.get<DepreciationCatalogListResponse>(
|
||||
`/v1/a76/depreciation-catalog/?${params.toString()}`
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { api } from '$lib/api';
|
||||
|
||||
export interface FDACatalog {
|
||||
id: number;
|
||||
fda_key: string;
|
||||
description: string;
|
||||
fda_code?: string;
|
||||
requirements?: string;
|
||||
manufacturer_number?: string;
|
||||
country_of_production?: string;
|
||||
storage_status?: string;
|
||||
warehouse_code?: string;
|
||||
call_atl?: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export async function getFDACatalog(
|
||||
page: number,
|
||||
pageSize: number,
|
||||
companyId: number,
|
||||
filters: any = {}
|
||||
): Promise<any> {
|
||||
try {
|
||||
const queryParams = new URLSearchParams({
|
||||
page: page.toString(),
|
||||
page_size: pageSize.toString(),
|
||||
company_id: companyId.toString()
|
||||
});
|
||||
|
||||
if (filters.search) {
|
||||
queryParams.append('search', filters.search);
|
||||
}
|
||||
|
||||
const response = await api.get(`/v1/a76/fda-catalog/?${queryParams.toString()}`);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error('Error fetching FDA catalog:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import { api } from '$lib/api';
|
||||
import type { ApiResponse } from '$lib/api';
|
||||
|
||||
// Interfaces
|
||||
export interface TariffFraction {
|
||||
id: number;
|
||||
code: string;
|
||||
fraction: string;
|
||||
description: string | null;
|
||||
nico: string | null;
|
||||
umt: string | null;
|
||||
adv_impo: string | null;
|
||||
adv_expo: string | null;
|
||||
created_at: string | null;
|
||||
updated_at: string | null;
|
||||
}
|
||||
|
||||
export interface TariffFractionCreate {
|
||||
code: string;
|
||||
fraction: string;
|
||||
description?: string | null;
|
||||
nico?: string | null;
|
||||
umt?: string | null;
|
||||
adv_impo?: string | null;
|
||||
adv_expo?: string | null;
|
||||
}
|
||||
|
||||
export interface TariffFractionUpdate {
|
||||
fraction?: string;
|
||||
description?: string | null;
|
||||
nico?: string | null;
|
||||
umt?: string | null;
|
||||
adv_impo?: string | null;
|
||||
adv_expo?: string | null;
|
||||
}
|
||||
|
||||
export interface TariffFractionListResponse {
|
||||
items: TariffFraction[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
pages: number;
|
||||
}
|
||||
|
||||
// API Functions
|
||||
export async function getTariffFractions(
|
||||
page = 1,
|
||||
pageSize = 50,
|
||||
companyId: number,
|
||||
filters: Record<string, any> = {}
|
||||
): Promise<ApiResponse<TariffFractionListResponse>> {
|
||||
const queryParams = new URLSearchParams({
|
||||
page: page.toString(),
|
||||
page_size: pageSize.toString(),
|
||||
company_id: companyId.toString(),
|
||||
...filters
|
||||
});
|
||||
return await api.get(`/v1/a76/tariff-fractions/?${queryParams.toString()}`);
|
||||
}
|
||||
|
||||
export async function getTariffFractionById(
|
||||
id: number,
|
||||
companyId: number
|
||||
): Promise<ApiResponse<TariffFraction>> {
|
||||
return await api.get(`/v1/a76/tariff-fractions/${id}/?company_id=${companyId}`);
|
||||
}
|
||||
|
||||
export async function createTariffFraction(
|
||||
data: TariffFractionCreate,
|
||||
companyId: number
|
||||
): Promise<ApiResponse<TariffFraction>> {
|
||||
return await api.post(`/v1/a76/tariff-fractions/?company_id=${companyId}`, data);
|
||||
}
|
||||
|
||||
export async function updateTariffFraction(
|
||||
id: number,
|
||||
data: TariffFractionUpdate,
|
||||
companyId: number
|
||||
): Promise<ApiResponse<TariffFraction>> {
|
||||
return await api.put(`/v1/a76/tariff-fractions/${id}/?company_id=${companyId}`, data);
|
||||
}
|
||||
|
||||
export async function deleteTariffFraction(
|
||||
id: number,
|
||||
companyId: number
|
||||
): Promise<ApiResponse<void>> {
|
||||
return await api.delete(`/v1/a76/tariff-fractions/${id}/?company_id=${companyId}`);
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import { api } from '$lib/api';
|
||||
import type { ApiResponse } from '$lib/api';
|
||||
|
||||
// Interfaces
|
||||
export interface USTariffFraction {
|
||||
id: number;
|
||||
code: string;
|
||||
prefix: string | null;
|
||||
type_code: string | null;
|
||||
ad_valorem: number | null;
|
||||
fixed_cost: number | null;
|
||||
unit_of_measure: string | null;
|
||||
description: string | null;
|
||||
created_at: string | null;
|
||||
updated_at: string | null;
|
||||
}
|
||||
|
||||
export interface USTariffFractionCreate {
|
||||
code: string;
|
||||
prefix?: string | null;
|
||||
type_code?: string | null;
|
||||
ad_valorem?: number | null;
|
||||
fixed_cost?: number | null;
|
||||
unit_of_measure?: string | null;
|
||||
description?: string | null;
|
||||
}
|
||||
|
||||
export interface USTariffFractionUpdate {
|
||||
prefix?: string | null;
|
||||
type_code?: string | null;
|
||||
ad_valorem?: number | null;
|
||||
fixed_cost?: number | null;
|
||||
unit_of_measure?: string | null;
|
||||
description?: string | null;
|
||||
}
|
||||
|
||||
export interface USTariffFractionListResponse {
|
||||
items: USTariffFraction[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
pages: number;
|
||||
}
|
||||
|
||||
// API Functions
|
||||
export async function getUSTariffFractions(
|
||||
page = 1,
|
||||
pageSize = 50,
|
||||
companyId: number,
|
||||
filters: Record<string, any> = {}
|
||||
): Promise<ApiResponse<USTariffFractionListResponse>> {
|
||||
const queryParams = new URLSearchParams({
|
||||
page: page.toString(),
|
||||
page_size: pageSize.toString(),
|
||||
company_id: companyId.toString(),
|
||||
...filters
|
||||
});
|
||||
return await api.get(`/v1/a76/us-tariff-fractions/?${queryParams.toString()}`);
|
||||
}
|
||||
|
||||
export async function getUSTariffFractionById(
|
||||
id: number,
|
||||
companyId: number
|
||||
): Promise<ApiResponse<USTariffFraction>> {
|
||||
return await api.get(`/v1/a76/us-tariff-fractions/${id}/?company_id=${companyId}`);
|
||||
}
|
||||
|
||||
export async function createUSTariffFraction(
|
||||
data: USTariffFractionCreate,
|
||||
companyId: number
|
||||
): Promise<ApiResponse<USTariffFraction>> {
|
||||
return await api.post(`/v1/a76/us-tariff-fractions/?company_id=${companyId}`, data);
|
||||
}
|
||||
|
||||
export async function updateUSTariffFraction(
|
||||
id: number,
|
||||
data: USTariffFractionUpdate,
|
||||
companyId: number
|
||||
): Promise<ApiResponse<USTariffFraction>> {
|
||||
return await api.put(`/v1/a76/us-tariff-fractions/${id}/?company_id=${companyId}`, data);
|
||||
}
|
||||
|
||||
export async function deleteUSTariffFraction(
|
||||
id: number,
|
||||
companyId: number
|
||||
): Promise<ApiResponse<void>> {
|
||||
return await api.delete(`/v1/a76/us-tariff-fractions/${id}/?company_id=${companyId}`);
|
||||
}
|
||||
Reference in New Issue
Block a user