diff --git a/client/src/pages/InvoicesBAP.tsx b/client/src/pages/InvoicesBAP.tsx index 2ca74e5..c207afa 100644 --- a/client/src/pages/InvoicesBAP.tsx +++ b/client/src/pages/InvoicesBAP.tsx @@ -37,6 +37,23 @@ import * as XLSX from 'xlsx'; import { toast } from "sonner"; import { useLocation } from "wouter"; +// Helper function to determine field color based on origin +const getFieldColor = (invoice: any, fieldName: string): string => { + try { + const autoFilledFields = invoice.autoFilledFields ? JSON.parse(invoice.autoFilledFields) : []; + if (autoFilledFields.includes(fieldName)) { + return "text-green-600 font-semibold"; // Auto-filled by rules + } + // If field has a value but is not auto-filled, it's manual + if (invoice[fieldName]) { + return "text-blue-600 font-semibold"; // Manually filled + } + } catch (error) { + console.error("Error parsing autoFilledFields:", error); + } + return ""; // No color for empty fields +}; + export default function InvoicesBAP() { const [, setLocation] = useLocation(); const [searchQuery, setSearchQuery] = useState(""); @@ -456,13 +473,19 @@ export default function InvoicesBAP() { setAddDialogOpen(true); e.target.value = invoice.serviceConcerne || ""; } else { + // Remove field from autoFilledFields when manually edited + const autoFilledFields = invoice.autoFilledFields ? JSON.parse(invoice.autoFilledFields) : []; + const updatedAutoFields = autoFilledFields.filter((f: string) => f !== "serviceConcerne"); updateFieldMutation.mutate({ id: invoice.id, - data: { serviceConcerne: e.target.value || undefined }, + data: { + serviceConcerne: e.target.value || undefined, + autoFilledFields: updatedAutoFields.length > 0 ? JSON.stringify(updatedAutoFields) : null + }, }); } }} - className="w-full px-2 py-1 border rounded text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" + className={`w-full px-2 py-1 border rounded text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 ${getFieldColor(invoice, "serviceConcerne")}`} > {departments?.map((dept) => ( @@ -475,12 +498,18 @@ export default function InvoicesBAP() {