diff --git a/src/components/JobCard.tsx b/src/components/JobCard.tsx index ecd2ac9..a671197 100644 --- a/src/components/JobCard.tsx +++ b/src/components/JobCard.tsx @@ -29,9 +29,9 @@ const JobCard: React.FC = ({ job, onEdit, onDelete }) => { case 'Planned': return 'bg-gray-600'; case 'Acquisition': return 'bg-yellow-600'; case 'Running': return 'bg-blue-600'; - case 'Done': return 'bg-green-600'; - case 'Selling': return 'bg-purple-600'; - case 'Closed': return 'bg-gray-800'; + case 'Done': return 'bg-purple-600'; + case 'Selling': return 'bg-orange-600'; + case 'Closed': return 'bg-green-600'; default: return 'bg-gray-600'; } }; diff --git a/src/pages/Index.tsx b/src/pages/Index.tsx index 4e0062b..b6080f8 100644 --- a/src/pages/Index.tsx +++ b/src/pages/Index.tsx @@ -2,7 +2,7 @@ import { useState, useEffect } from 'react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Plus, Factory, TrendingUp, Briefcase } from 'lucide-react'; -import { IndTransactionRecordNoId, IndJobRecordNoId, IndTransactionRecord } from '@/lib/pbtypes'; +import { IndTransactionRecordNoId, IndJobRecordNoId, IndTransactionRecord, IndJobStatusOptions } from '@/lib/pbtypes'; import * as jobService from '@/services/jobService'; import * as transactionService from '@/services/transactionService'; import { formatISK } from '@/utils/priceUtils'; @@ -36,6 +36,29 @@ const Index = () => { } }; + // Sort jobs by status priority + const getStatusPriority = (status: IndJobStatusOptions): number => { + switch (status) { + case 'Planned': return 6; + case 'Acquisition': return 1; + case 'Running': return 2; + case 'Done': return 3; + case 'Selling': return 4; + case 'Closed': return 5; + default: return 0; + } + }; + + const sortedJobs = [...jobs].sort((a, b) => { + const priorityA = getStatusPriority(a.status); + const priorityB = getStatusPriority(b.status); + if (priorityA === priorityB) { + // If same status, sort by creation date (newest first) + return new Date(b.created || '').getTime() - new Date(a.created || '').getTime(); + } + return priorityA - priorityB; + }); + const handleCreateJob = async (jobData: IndJobRecordNoId) => { try { const newJob = await createJob(jobData); @@ -296,7 +319,7 @@ const Index = () => { ) : (
- {jobs.map((job) => ( + {sortedJobs.map((job) => (
setSelectedJob(job)} className="cursor-pointer"> { // Remove "ISK" and any extra whitespace const cleanString = iskString.replace(/ISK/gi, '').trim(); - + // Handle negative values const isNegative = cleanString.startsWith('-'); const numberString = cleanString.replace(/^-/, ''); - + // Remove commas and parse const amount = parseFloat(numberString.replace(/,/g, '')); - + return isNegative ? -amount : amount; }; export const formatISK = (amount: number): string => { const absAmount = Math.abs(amount); const sign = amount < 0 ? '-' : ''; - + // Format with commas and appropriate decimal places const formatted = absAmount.toLocaleString('en-US', { minimumFractionDigits: 0, maximumFractionDigits: 2 }); - + return `${sign}${formatted} ISK`; }; @@ -39,23 +39,29 @@ export const parseTransactionLine = (line: string): { } | null => { try { const parts = line.split('\t'); - if (parts.length < 8) return null; - - const [dateStr, quantityStr, itemName, unitPriceStr, totalAmountStr, buyer, location, corporation, wallet] = parts; - + if (parts.length < 6) return null; + + let dateStr, quantityStr, itemName, unitPriceStr, totalAmountStr, buyer, location, corporation, wallet; + if (parts.length === 8) { + [dateStr, quantityStr, itemName, unitPriceStr, totalAmountStr, buyer, location, corporation, wallet] = parts; + } else { + [dateStr, quantityStr, itemName, unitPriceStr, totalAmountStr, buyer, location] = parts; + } + + // Parse date (YYYY.MM.DD HH:mm format) const [datePart, timePart] = dateStr.split(' '); const [year, month, day] = datePart.split('.').map(Number); const [hour, minute] = timePart.split(':').map(Number); const date = new Date(year, month - 1, day, hour, minute); - + // Parse quantity (remove commas) const quantity = parseInt(quantityStr.replace(/,/g, '')); - + // Parse prices const unitPrice = parseISKAmount(unitPriceStr); const totalAmount = parseISKAmount(totalAmountStr); - + return { date, quantity,