initial commit
This commit is contained in:
420
src/types/import.ts
Normal file
420
src/types/import.ts
Normal file
@@ -0,0 +1,420 @@
|
||||
/**
|
||||
* Type definitions for the AI Import Hub API
|
||||
*/
|
||||
|
||||
// ─── Import Data Types ───────────────────────────────────────────────────────
|
||||
|
||||
export type ImportDataType =
|
||||
| "VENDORS"
|
||||
| "CUSTOMERS"
|
||||
| "INVOICES"
|
||||
| "JOURNAL_ENTRIES"
|
||||
| "CHART_OF_ACCOUNTS"
|
||||
| "EMPLOYEES"
|
||||
| "BANK_TRANSACTIONS"
|
||||
| "PAYMENTS"
|
||||
| "FIXED_ASSETS";
|
||||
|
||||
export type ImportStatus =
|
||||
| "ANALYZING"
|
||||
| "MAPPED"
|
||||
| "IMPORTED"
|
||||
| "FAILED"
|
||||
| "ROLLED_BACK";
|
||||
|
||||
export type ConfidenceLevel = "HIGH" | "MEDIUM" | "LOW";
|
||||
|
||||
// ─── Import Records ──────────────────────────────────────────────────────────
|
||||
|
||||
export interface ImportRecord {
|
||||
id: string;
|
||||
fileName: string;
|
||||
fileType: string;
|
||||
fileSize: number;
|
||||
detectedType: ImportDataType;
|
||||
status: ImportStatus;
|
||||
totalRows: number;
|
||||
successCount: number;
|
||||
errorCount: number;
|
||||
columnMappings: Record<string, string>;
|
||||
mappingConfidence: Record<string, ConfidenceLevel>;
|
||||
sampleValues: Record<string, string[]>;
|
||||
errors: ImportError[];
|
||||
createdAt: string;
|
||||
importedAt?: string;
|
||||
rolledBackAt?: string;
|
||||
createdRecordIds?: string[];
|
||||
}
|
||||
|
||||
export interface ImportError {
|
||||
row: number;
|
||||
field: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
// ─── API Request/Response Types ──────────────────────────────────────────────
|
||||
|
||||
export interface AnalyzeImportRequest {
|
||||
fileName: string;
|
||||
fileType?: string;
|
||||
fileSize?: number;
|
||||
fileContent: string | Buffer;
|
||||
}
|
||||
|
||||
export interface AnalyzeImportResponse {
|
||||
importId: string;
|
||||
analysis: ImportAnalysis;
|
||||
}
|
||||
|
||||
export interface ImportAnalysis {
|
||||
fileType: string;
|
||||
detectedType: ImportDataType;
|
||||
columns: string[];
|
||||
sampleRows: Record<string, any>[];
|
||||
rowCount: number;
|
||||
mappings: FieldMapping[];
|
||||
}
|
||||
|
||||
export interface FieldMapping {
|
||||
sourceColumn: string;
|
||||
targetField: string;
|
||||
confidence: ConfidenceLevel;
|
||||
sampleValues: string[];
|
||||
}
|
||||
|
||||
export interface ExecuteImportRequest {
|
||||
columnMappings: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface ExecuteImportResponse {
|
||||
message: string;
|
||||
importRecord: ImportRecord;
|
||||
}
|
||||
|
||||
export interface RollbackImportResponse {
|
||||
message: string;
|
||||
importRecord: ImportRecord;
|
||||
}
|
||||
|
||||
export interface ListImportsResponse {
|
||||
imports: ImportRecord[];
|
||||
total: number;
|
||||
limit: number;
|
||||
offset: number;
|
||||
}
|
||||
|
||||
// ─── Vendor Schema ───────────────────────────────────────────────────────────
|
||||
|
||||
export interface VendorImportData {
|
||||
vendorName: string;
|
||||
vendorCode: string;
|
||||
email?: string;
|
||||
phone?: string;
|
||||
address?: string;
|
||||
city?: string;
|
||||
state?: string;
|
||||
zip?: string;
|
||||
country?: string;
|
||||
taxId?: string;
|
||||
paymentTerms?: string;
|
||||
}
|
||||
|
||||
// ─── Customer Schema ─────────────────────────────────────────────────────────
|
||||
|
||||
export interface CustomerImportData {
|
||||
customerName: string;
|
||||
customerCode: string;
|
||||
email?: string;
|
||||
phone?: string;
|
||||
address?: string;
|
||||
city?: string;
|
||||
state?: string;
|
||||
zip?: string;
|
||||
country?: string;
|
||||
creditLimit?: number;
|
||||
paymentTerms?: string;
|
||||
}
|
||||
|
||||
// ─── Invoice Schema ──────────────────────────────────────────────────────────
|
||||
|
||||
export interface InvoiceImportData {
|
||||
invoiceNumber: string;
|
||||
invoiceDate: string;
|
||||
dueDate?: string;
|
||||
vendorName?: string;
|
||||
customerName?: string;
|
||||
amount: number;
|
||||
tax?: number;
|
||||
total?: number;
|
||||
description?: string;
|
||||
status?: string;
|
||||
poNumber?: string;
|
||||
}
|
||||
|
||||
// ─── Journal Entry Schema ────────────────────────────────────────────────────
|
||||
|
||||
export interface JournalEntryImportData {
|
||||
entryDate: string;
|
||||
accountCode: string;
|
||||
accountName: string;
|
||||
debit?: number;
|
||||
credit?: number;
|
||||
description?: string;
|
||||
reference?: string;
|
||||
}
|
||||
|
||||
// ─── Chart of Accounts Schema ────────────────────────────────────────────────
|
||||
|
||||
export interface ChartOfAccountsImportData {
|
||||
accountCode: string;
|
||||
accountName: string;
|
||||
accountType: string;
|
||||
parentAccount?: string;
|
||||
normalBalance?: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
// ─── Bank Transaction Schema ─────────────────────────────────────────────────
|
||||
|
||||
export interface BankTransactionImportData {
|
||||
date: string;
|
||||
description: string;
|
||||
amount: number;
|
||||
type?: "DEBIT" | "CREDIT";
|
||||
reference?: string;
|
||||
balance?: number;
|
||||
bankAccount?: string;
|
||||
}
|
||||
|
||||
// ─── Payment Schema ──────────────────────────────────────────────────────────
|
||||
|
||||
export interface PaymentImportData {
|
||||
paymentDate: string;
|
||||
paymentNumber: string;
|
||||
vendorName: string;
|
||||
amount: number;
|
||||
method?: string;
|
||||
reference?: string;
|
||||
bankAccount?: string;
|
||||
}
|
||||
|
||||
// ─── Employee Schema ────────────────────────────────────────────────────────
|
||||
|
||||
export interface EmployeeImportData {
|
||||
name: string;
|
||||
employeeId: string;
|
||||
email?: string;
|
||||
phone?: string;
|
||||
department?: string;
|
||||
position?: string;
|
||||
hireDate?: string;
|
||||
salary?: number;
|
||||
}
|
||||
|
||||
// ─── Fixed Asset Schema ─────────────────────────────────────────────────────
|
||||
|
||||
export interface FixedAssetImportData {
|
||||
name: string;
|
||||
category: string;
|
||||
acquisitionDate?: string;
|
||||
acquisitionCost?: number;
|
||||
usefulLife?: number;
|
||||
salvageValue?: number;
|
||||
depreciationMethod?: string;
|
||||
location?: string;
|
||||
}
|
||||
|
||||
// ─── Union Type for All Import Data ─────────────────────────────────────────
|
||||
|
||||
export type ImportDataUnion =
|
||||
| VendorImportData
|
||||
| CustomerImportData
|
||||
| InvoiceImportData
|
||||
| JournalEntryImportData
|
||||
| ChartOfAccountsImportData
|
||||
| BankTransactionImportData
|
||||
| PaymentImportData
|
||||
| EmployeeImportData
|
||||
| FixedAssetImportData;
|
||||
|
||||
// ─── Mapping Configuration ──────────────────────────────────────────────────
|
||||
|
||||
export interface SynonymDictionary {
|
||||
[targetField: string]: string[];
|
||||
}
|
||||
|
||||
export type MappingConfig = {
|
||||
[K in ImportDataType]: SynonymDictionary;
|
||||
};
|
||||
|
||||
// ─── Validation ──────────────────────────────────────────────────────────────
|
||||
|
||||
export interface ValidationResult {
|
||||
isValid: boolean;
|
||||
errors: ImportError[];
|
||||
warnings?: string[];
|
||||
}
|
||||
|
||||
// ─── File Parser Results ─────────────────────────────────────────────────────
|
||||
|
||||
export interface ParsedFileData {
|
||||
columns: string[];
|
||||
rows: Record<string, any>[];
|
||||
rowCount: number;
|
||||
}
|
||||
|
||||
// ─── Type Guards ────────────────────────────────────────────────────────────
|
||||
|
||||
export function isValidImportDataType(value: string): value is ImportDataType {
|
||||
const types: ImportDataType[] = [
|
||||
"VENDORS",
|
||||
"CUSTOMERS",
|
||||
"INVOICES",
|
||||
"JOURNAL_ENTRIES",
|
||||
"CHART_OF_ACCOUNTS",
|
||||
"EMPLOYEES",
|
||||
"BANK_TRANSACTIONS",
|
||||
"PAYMENTS",
|
||||
"FIXED_ASSETS",
|
||||
];
|
||||
return types.includes(value as ImportDataType);
|
||||
}
|
||||
|
||||
export function isValidImportStatus(value: string): value is ImportStatus {
|
||||
const statuses: ImportStatus[] = [
|
||||
"ANALYZING",
|
||||
"MAPPED",
|
||||
"IMPORTED",
|
||||
"FAILED",
|
||||
"ROLLED_BACK",
|
||||
];
|
||||
return statuses.includes(value as ImportStatus);
|
||||
}
|
||||
|
||||
export function isValidConfidenceLevel(value: string): value is ConfidenceLevel {
|
||||
const levels: ConfidenceLevel[] = ["HIGH", "MEDIUM", "LOW"];
|
||||
return levels.includes(value as ConfidenceLevel);
|
||||
}
|
||||
|
||||
// ─── Helper Functions ───────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Get required fields for a data type
|
||||
*/
|
||||
export function getRequiredFieldsForType(type: ImportDataType): string[] {
|
||||
const required: Record<ImportDataType, string[]> = {
|
||||
VENDORS: ["vendorName", "vendorCode"],
|
||||
CUSTOMERS: ["customerName", "customerCode"],
|
||||
INVOICES: ["invoiceNumber", "invoiceDate", "amount"],
|
||||
JOURNAL_ENTRIES: ["entryDate", "accountCode", "debit", "credit"],
|
||||
CHART_OF_ACCOUNTS: ["accountCode", "accountName", "accountType"],
|
||||
EMPLOYEES: ["name", "employeeId"],
|
||||
BANK_TRANSACTIONS: ["date", "description", "amount"],
|
||||
PAYMENTS: ["paymentDate", "paymentNumber", "amount"],
|
||||
FIXED_ASSETS: ["name", "category"],
|
||||
};
|
||||
return required[type];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all target fields for a data type
|
||||
*/
|
||||
export function getAllFieldsForType(type: ImportDataType): string[] {
|
||||
const fields: Record<ImportDataType, string[]> = {
|
||||
VENDORS: [
|
||||
"vendorName",
|
||||
"vendorCode",
|
||||
"email",
|
||||
"phone",
|
||||
"address",
|
||||
"city",
|
||||
"state",
|
||||
"zip",
|
||||
"country",
|
||||
"taxId",
|
||||
"paymentTerms",
|
||||
],
|
||||
CUSTOMERS: [
|
||||
"customerName",
|
||||
"customerCode",
|
||||
"email",
|
||||
"phone",
|
||||
"address",
|
||||
"city",
|
||||
"state",
|
||||
"zip",
|
||||
"country",
|
||||
"creditLimit",
|
||||
"paymentTerms",
|
||||
],
|
||||
INVOICES: [
|
||||
"invoiceNumber",
|
||||
"invoiceDate",
|
||||
"dueDate",
|
||||
"vendorName",
|
||||
"customerName",
|
||||
"amount",
|
||||
"tax",
|
||||
"total",
|
||||
"description",
|
||||
"status",
|
||||
"poNumber",
|
||||
],
|
||||
JOURNAL_ENTRIES: [
|
||||
"entryDate",
|
||||
"accountCode",
|
||||
"accountName",
|
||||
"debit",
|
||||
"credit",
|
||||
"description",
|
||||
"reference",
|
||||
],
|
||||
CHART_OF_ACCOUNTS: [
|
||||
"accountCode",
|
||||
"accountName",
|
||||
"accountType",
|
||||
"parentAccount",
|
||||
"normalBalance",
|
||||
"description",
|
||||
],
|
||||
EMPLOYEES: [
|
||||
"name",
|
||||
"employeeId",
|
||||
"email",
|
||||
"phone",
|
||||
"department",
|
||||
"position",
|
||||
"hireDate",
|
||||
"salary",
|
||||
],
|
||||
BANK_TRANSACTIONS: [
|
||||
"date",
|
||||
"description",
|
||||
"amount",
|
||||
"type",
|
||||
"reference",
|
||||
"balance",
|
||||
"bankAccount",
|
||||
],
|
||||
PAYMENTS: [
|
||||
"paymentDate",
|
||||
"paymentNumber",
|
||||
"vendorName",
|
||||
"amount",
|
||||
"method",
|
||||
"reference",
|
||||
"bankAccount",
|
||||
],
|
||||
FIXED_ASSETS: [
|
||||
"name",
|
||||
"category",
|
||||
"acquisitionDate",
|
||||
"acquisitionCost",
|
||||
"usefulLife",
|
||||
"salvageValue",
|
||||
"depreciationMethod",
|
||||
"location",
|
||||
],
|
||||
};
|
||||
return fields[type];
|
||||
}
|
||||
244
src/types/index.ts
Normal file
244
src/types/index.ts
Normal file
@@ -0,0 +1,244 @@
|
||||
/**
|
||||
* Core TypeScript types and interfaces for the ERP platform
|
||||
*/
|
||||
|
||||
// Module definitions
|
||||
export enum Module {
|
||||
GENERAL_LEDGER = "GENERAL_LEDGER",
|
||||
AP = "AP",
|
||||
AR = "AR",
|
||||
TREASURY = "TREASURY",
|
||||
FPA = "FPA",
|
||||
FORECASTING = "FORECASTING",
|
||||
TAX = "TAX",
|
||||
REPORTING = "REPORTING",
|
||||
SETTINGS = "SETTINGS",
|
||||
}
|
||||
|
||||
// Permission levels
|
||||
export enum PermissionLevel {
|
||||
NONE = 0,
|
||||
VIEW = 1,
|
||||
EDIT = 2,
|
||||
APPROVE = 3,
|
||||
ADMIN = 4,
|
||||
}
|
||||
|
||||
// User role type
|
||||
export type UserRole = "CEO" | "CFO" | "Controller" | "Manager" | "Analyst" | "Clerk" | "Custom";
|
||||
|
||||
// Module access level
|
||||
export interface ModuleAccess {
|
||||
module: Module;
|
||||
permissionLevel: PermissionLevel;
|
||||
}
|
||||
|
||||
// User type
|
||||
export interface User {
|
||||
id: string;
|
||||
email: string;
|
||||
name: string;
|
||||
role: UserRole;
|
||||
moduleAccess: ModuleAccess[];
|
||||
active: boolean;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
// Navigation types
|
||||
export interface SidebarItem {
|
||||
id: string;
|
||||
label: string;
|
||||
module: Module;
|
||||
icon: string;
|
||||
href: string;
|
||||
children?: SidebarItem[];
|
||||
permissionLevel: PermissionLevel;
|
||||
}
|
||||
|
||||
export interface Navigation {
|
||||
items: SidebarItem[];
|
||||
userRole: UserRole;
|
||||
}
|
||||
|
||||
// Dashboard widget types
|
||||
export type WidgetType =
|
||||
| "KPI"
|
||||
| "CHART"
|
||||
| "TABLE"
|
||||
| "TIMELINE"
|
||||
| "METRIC"
|
||||
| "ALERT"
|
||||
| "CUSTOM";
|
||||
|
||||
export type WidgetSize = "small" | "medium" | "large" | "full";
|
||||
|
||||
export interface WidgetPosition {
|
||||
row: number;
|
||||
col: number;
|
||||
}
|
||||
|
||||
export interface WidgetConfig {
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
export interface DashboardWidget {
|
||||
id: string;
|
||||
type: WidgetType;
|
||||
title: string;
|
||||
size: WidgetSize;
|
||||
position: WidgetPosition;
|
||||
config: WidgetConfig;
|
||||
refreshInterval?: number; // in milliseconds
|
||||
}
|
||||
|
||||
export interface Dashboard {
|
||||
id: string;
|
||||
name: string;
|
||||
userId: string;
|
||||
widgets: DashboardWidget[];
|
||||
isDefault: boolean;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
// Financial types
|
||||
export interface Money {
|
||||
amount: number;
|
||||
currency: string; // ISO 4217 code (e.g., "USD", "EUR")
|
||||
}
|
||||
|
||||
export interface DateRange {
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
}
|
||||
|
||||
export interface FiscalPeriod {
|
||||
periodName: string;
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
year: number;
|
||||
quarter?: number;
|
||||
month?: number;
|
||||
isClosed: boolean;
|
||||
}
|
||||
|
||||
// General Ledger types
|
||||
export interface ChartOfAccounts {
|
||||
accountNumber: string;
|
||||
accountName: string;
|
||||
accountType: "ASSET" | "LIABILITY" | "EQUITY" | "REVENUE" | "EXPENSE";
|
||||
subType?: string;
|
||||
isActive: boolean;
|
||||
}
|
||||
|
||||
export interface JournalEntry {
|
||||
id: string;
|
||||
reference: string;
|
||||
date: Date;
|
||||
description: string;
|
||||
fiscalPeriod: FiscalPeriod;
|
||||
lines: JournalEntryLine[];
|
||||
status: "DRAFT" | "POSTED" | "REVERSED";
|
||||
approvedBy?: string;
|
||||
approvedAt?: Date;
|
||||
createdBy: string;
|
||||
createdAt: Date;
|
||||
}
|
||||
|
||||
export interface JournalEntryLine {
|
||||
id: string;
|
||||
accountNumber: string;
|
||||
debit?: Money;
|
||||
credit?: Money;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
// AP/AR types
|
||||
export interface Vendor {
|
||||
id: string;
|
||||
code: string;
|
||||
name: string;
|
||||
email: string;
|
||||
address: string;
|
||||
taxId: string;
|
||||
terms: string;
|
||||
isActive: boolean;
|
||||
}
|
||||
|
||||
export interface Customer {
|
||||
id: string;
|
||||
code: string;
|
||||
name: string;
|
||||
email: string;
|
||||
address: string;
|
||||
taxId: string;
|
||||
creditLimit: Money;
|
||||
terms: string;
|
||||
isActive: boolean;
|
||||
}
|
||||
|
||||
export interface Invoice {
|
||||
id: string;
|
||||
invoiceNumber: string;
|
||||
entityId: string; // vendorId or customerId
|
||||
date: Date;
|
||||
dueDate: Date;
|
||||
amount: Money;
|
||||
description: string;
|
||||
status: "DRAFT" | "SENT" | "PARTIAL" | "PAID" | "OVERDUE" | "CANCELLED";
|
||||
items: InvoiceItem[];
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export interface InvoiceItem {
|
||||
id: string;
|
||||
description: string;
|
||||
quantity: number;
|
||||
unitPrice: Money;
|
||||
amount: Money;
|
||||
glAccount?: string;
|
||||
}
|
||||
|
||||
// API Response wrapper types
|
||||
export interface ApiResponse<T> {
|
||||
success: boolean;
|
||||
data?: T;
|
||||
error?: {
|
||||
code: string;
|
||||
message: string;
|
||||
details?: unknown;
|
||||
};
|
||||
timestamp: Date;
|
||||
}
|
||||
|
||||
export interface PaginatedResponse<T> {
|
||||
data: T[];
|
||||
pagination: {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
total: number;
|
||||
hasNextPage: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ApiError {
|
||||
code: string;
|
||||
message: string;
|
||||
statusCode: number;
|
||||
details?: unknown;
|
||||
}
|
||||
|
||||
// Audit types
|
||||
export interface AuditLog {
|
||||
id: string;
|
||||
userId: string;
|
||||
action: string;
|
||||
module: Module;
|
||||
entityType: string;
|
||||
entityId: string;
|
||||
changes?: Record<string, unknown>;
|
||||
timestamp: Date;
|
||||
ipAddress?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user