92 lines
3.1 KiB
TypeScript
92 lines
3.1 KiB
TypeScript
// types/project.ts
|
|
export type ProjectStatus = '0' | '1' | '2'; // 0: borrador, 1: validado/abierto, 2: cerrado
|
|
|
|
// Interface para los datos crudos que vienen de Dolibarr
|
|
export interface DolibarrProject {
|
|
id: string | number;
|
|
ref: string;
|
|
title: string;
|
|
description: string;
|
|
date_start: number; // timestamp
|
|
date_end: number; // timestamp
|
|
status: string;
|
|
statut: string;
|
|
budget_amount: string;
|
|
opp_amount: string; // opportunity amount (presupuesto estimado)
|
|
opp_percent: string; // porcentaje de progreso
|
|
user_author_id: string | number;
|
|
thirdparty_name?: string;
|
|
socid?: string | number;
|
|
public: string | number;
|
|
usage_opportunity: string | number;
|
|
usage_task: string | number;
|
|
date_c: number; // fecha creación
|
|
date_m: number; // fecha modificación
|
|
}
|
|
|
|
// Interface para usar en la UI (formato normalizado)
|
|
export interface Project {
|
|
id: number;
|
|
ref: string;
|
|
name: string;
|
|
client: string;
|
|
status: ProjectStatus;
|
|
progress: number;
|
|
budget: number;
|
|
spent: number;
|
|
startDate: string;
|
|
endDate: string;
|
|
description: string;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
// Configuración de estados - AHORA CON FUNCIÓN QUE RETORNA LAS CLASES COMPLETAS
|
|
export const STATUS_CONFIG: Record<ProjectStatus, { label: string; getColorClasses: () => string }> = {
|
|
'0': {
|
|
label: "Borrador",
|
|
getColorClasses: () => "bg-gray-100 text-gray-800 border-gray-200"
|
|
},
|
|
'1': {
|
|
label: "Abierto",
|
|
getColorClasses: () => "bg-blue-100 text-blue-800 border-blue-200"
|
|
},
|
|
'2': {
|
|
label: "Cerrado",
|
|
getColorClasses: () => "bg-green-100 text-green-800 border-green-200"
|
|
}
|
|
};
|
|
|
|
// Función helper para obtener las clases de color según el estado
|
|
export function getStatusColorClasses(status: ProjectStatus): string {
|
|
const statusMap: Record<ProjectStatus, string> = {
|
|
'0': 'bg-gray-100 text-gray-800 border-gray-200',
|
|
'1': 'bg-blue-100 text-blue-800 border-blue-200',
|
|
'2': 'bg-green-100 text-green-800 border-green-200'
|
|
};
|
|
|
|
return statusMap[status] || 'bg-gray-100 text-gray-800 border-gray-200';
|
|
}
|
|
|
|
// Función helper para convertir datos de Dolibarr a nuestro formato
|
|
export function mapDolibarrProject(dolibarr: DolibarrProject): Project {
|
|
const budget = parseFloat(dolibarr.budget_amount || '0');
|
|
const oppAmount = parseFloat(dolibarr.opp_amount || '0');
|
|
const progress = parseFloat(dolibarr.opp_percent || '0');
|
|
|
|
return {
|
|
id: typeof dolibarr.id === 'string' ? parseInt(dolibarr.id) : dolibarr.id,
|
|
ref: dolibarr.ref,
|
|
name: dolibarr.title,
|
|
client: dolibarr.thirdparty_name || 'Sin cliente',
|
|
status: (dolibarr.status || dolibarr.statut) as ProjectStatus,
|
|
progress: progress,
|
|
budget: oppAmount || budget,
|
|
spent: (oppAmount || budget) * (progress / 100), // Calcular gastado según progreso
|
|
startDate: new Date(dolibarr.date_start * 1000).toISOString().split('T')[0],
|
|
endDate: new Date(dolibarr.date_end * 1000).toISOString().split('T')[0],
|
|
description: dolibarr.description || '',
|
|
createdAt: new Date(dolibarr.date_c * 1000).toISOString().split('T')[0],
|
|
updatedAt: new Date(dolibarr.date_m * 1000).toISOString().split('T')[0],
|
|
};
|
|
} |