Add "produced" field to jobs
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import { useState } from 'react';
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
@@ -6,14 +6,18 @@ import { HoverCard, HoverCardContent, HoverCardTrigger } from '@/components/ui/h
|
|||||||
import { Calendar, Factory, TrendingUp, TrendingDown, Clock, Package, Wrench } from 'lucide-react';
|
import { Calendar, Factory, TrendingUp, TrendingDown, Clock, Package, Wrench } from 'lucide-react';
|
||||||
import { formatISK } from '@/utils/priceUtils';
|
import { formatISK } from '@/utils/priceUtils';
|
||||||
import { IndJob } from '@/lib/types';
|
import { IndJob } from '@/lib/types';
|
||||||
|
import { Input } from '@/components/ui/input';
|
||||||
|
|
||||||
interface JobCardProps {
|
interface JobCardProps {
|
||||||
job: IndJob;
|
job: IndJob;
|
||||||
onEdit: (job: any) => void;
|
onEdit: (job: any) => void;
|
||||||
onDelete: (jobId: string) => void;
|
onDelete: (jobId: string) => void;
|
||||||
|
onUpdateProduced?: (jobId: string, produced: number) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const JobCard: React.FC<JobCardProps> = ({ job, onEdit, onDelete }) => {
|
const JobCard: React.FC<JobCardProps> = ({ job, onEdit, onDelete, onUpdateProduced }) => {
|
||||||
|
const [isEditingProduced, setIsEditingProduced] = useState(false);
|
||||||
|
const [producedValue, setProducedValue] = useState(job.produced?.toString() || '0');
|
||||||
const totalExpenditure = job.expenditures.reduce((sum, tx) => sum + tx.totalPrice, 0);
|
const totalExpenditure = job.expenditures.reduce((sum, tx) => sum + tx.totalPrice, 0);
|
||||||
const totalIncome = job.income.reduce((sum, tx) => sum + tx.totalPrice, 0);
|
const totalIncome = job.income.reduce((sum, tx) => sum + tx.totalPrice, 0);
|
||||||
const profit = totalIncome - totalExpenditure;
|
const profit = totalIncome - totalExpenditure;
|
||||||
@@ -47,6 +51,26 @@ const JobCard: React.FC<JobCardProps> = ({ job, onEdit, onDelete }) => {
|
|||||||
}).replace(',', '');
|
}).replace(',', '');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleProducedUpdate = () => {
|
||||||
|
const newValue = parseInt(producedValue);
|
||||||
|
if (!isNaN(newValue) && onUpdateProduced) {
|
||||||
|
onUpdateProduced(job.id, newValue);
|
||||||
|
setIsEditingProduced(false);
|
||||||
|
} else {
|
||||||
|
setProducedValue(job.produced?.toString() || '0');
|
||||||
|
setIsEditingProduced(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleProducedKeyPress = (e: React.KeyboardEvent) => {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
handleProducedUpdate();
|
||||||
|
} else if (e.key === 'Escape') {
|
||||||
|
setIsEditingProduced(false);
|
||||||
|
setProducedValue(job.produced?.toString() || '0');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="bg-gray-900 border-gray-700 text-white">
|
<Card className="bg-gray-900 border-gray-700 text-white">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
@@ -102,7 +126,35 @@ const JobCard: React.FC<JobCardProps> = ({ job, onEdit, onDelete }) => {
|
|||||||
</HoverCard>
|
</HoverCard>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<p className="text-gray-400">Quantity: {job.outputQuantity.toLocaleString()}</p>
|
<p className="text-gray-400">
|
||||||
|
Quantity: {job.outputQuantity.toLocaleString()}
|
||||||
|
{job.status !== 'Planned' && job.status !== 'Closed' && (
|
||||||
|
<span className="ml-4">
|
||||||
|
Produced: {
|
||||||
|
isEditingProduced ? (
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
value={producedValue}
|
||||||
|
onChange={(e) => setProducedValue(e.target.value)}
|
||||||
|
onBlur={handleProducedUpdate}
|
||||||
|
onKeyDown={handleProducedKeyPress}
|
||||||
|
className="w-24 h-6 px-2 py-1 inline-block bg-gray-800 border-gray-600 text-white"
|
||||||
|
min="0"
|
||||||
|
autoFocus
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<span
|
||||||
|
onClick={() => setIsEditingProduced(true)}
|
||||||
|
className="cursor-pointer hover:text-blue-400"
|
||||||
|
title="Click to edit"
|
||||||
|
>
|
||||||
|
{(job.produced || 0).toLocaleString()}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ export type IndJobRecord = {
|
|||||||
jobStart?: IsoDateString
|
jobStart?: IsoDateString
|
||||||
outputItem: string
|
outputItem: string
|
||||||
outputQuantity: number
|
outputQuantity: number
|
||||||
|
produced?: number
|
||||||
projectedCost?: number
|
projectedCost?: number
|
||||||
projectedRevenue?: number
|
projectedRevenue?: number
|
||||||
saleEnd?: IsoDateString
|
saleEnd?: IsoDateString
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export type IndJob = {
|
|||||||
jobStart?: IsoDateString
|
jobStart?: IsoDateString
|
||||||
outputItem: string
|
outputItem: string
|
||||||
outputQuantity: number
|
outputQuantity: number
|
||||||
|
produced?: number
|
||||||
saleEnd?: IsoDateString
|
saleEnd?: IsoDateString
|
||||||
saleStart?: IsoDateString
|
saleStart?: IsoDateString
|
||||||
status: IndJobStatusOptions
|
status: IndJobStatusOptions
|
||||||
|
|||||||
@@ -169,6 +169,27 @@ const Index = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleUpdateProduced = async (jobId: string, produced: number) => {
|
||||||
|
if (!selectedJob) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const updatedJob = await jobService.updateJob(jobId, { produced });
|
||||||
|
// Update local state
|
||||||
|
const jobWithRelations: IndJob = {
|
||||||
|
...updatedJob,
|
||||||
|
expenditures: selectedJob.expenditures,
|
||||||
|
income: selectedJob.income,
|
||||||
|
billOfMaterials: selectedJob.billOfMaterials,
|
||||||
|
consumedMaterials: selectedJob.consumedMaterials
|
||||||
|
};
|
||||||
|
|
||||||
|
setSelectedJob(jobWithRelations);
|
||||||
|
setJobs(jobs.map(job => job.id === jobId ? jobWithRelations : job));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error updating produced quantity:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const totalJobs = jobs.length;
|
const totalJobs = jobs.length;
|
||||||
const totalProfit = jobs.reduce((sum, job) => {
|
const totalProfit = jobs.reduce((sum, job) => {
|
||||||
const expenditure = job.expenditures.reduce((sum, tx) => sum + tx.totalPrice, 0);
|
const expenditure = job.expenditures.reduce((sum, tx) => sum + tx.totalPrice, 0);
|
||||||
@@ -220,6 +241,7 @@ const Index = () => {
|
|||||||
job={selectedJob}
|
job={selectedJob}
|
||||||
onEdit={handleEditJob}
|
onEdit={handleEditJob}
|
||||||
onDelete={handleDeleteJob}
|
onDelete={handleDeleteJob}
|
||||||
|
onUpdateProduced={handleUpdateProduced}
|
||||||
/>
|
/>
|
||||||
<TransactionForm
|
<TransactionForm
|
||||||
jobId={selectedJob.id}
|
jobId={selectedJob.id}
|
||||||
@@ -325,6 +347,7 @@ const Index = () => {
|
|||||||
job={job}
|
job={job}
|
||||||
onEdit={handleEditJob}
|
onEdit={handleEditJob}
|
||||||
onDelete={handleDeleteJob}
|
onDelete={handleDeleteJob}
|
||||||
|
onUpdateProduced={handleUpdateProduced}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
Reference in New Issue
Block a user