From 41530a4691272d68f21f0f34a2c91ec8dd655fe7 Mon Sep 17 00:00:00 2001 From: sazzadulalambd Date: Sat, 16 May 2026 12:36:00 +0600 Subject: [PATCH] feat: add manual BMS data refresh functionality and expand battery purchase form with accounting fields --- src/app/admin/batteries/[id]/page.tsx | 45 +++++++++++++++++++++++---- src/app/admin/batteries/page.tsx | 45 +++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 6 deletions(-) diff --git a/src/app/admin/batteries/[id]/page.tsx b/src/app/admin/batteries/[id]/page.tsx index 468a854..0ec033d 100644 --- a/src/app/admin/batteries/[id]/page.tsx +++ b/src/app/admin/batteries/[id]/page.tsx @@ -4,7 +4,8 @@ import { useState, use } from 'react'; import Link from 'next/link'; import { Battery, ArrowLeft, X, BatteryCharging, Activity, Gauge, MapPin, Bike, User, History, - Calendar, DollarSign, CheckCircle, Clock, ArrowRightLeft, Handshake, TrendingUp, Edit + Calendar, DollarSign, CheckCircle, Clock, ArrowRightLeft, Handshake, TrendingUp, Edit, + RefreshCw } from 'lucide-react'; interface BMSData { @@ -127,12 +128,37 @@ export default function BatteryDetailPage({ params }: { params: Promise<{ id: st const [battery, setBattery] = useState(mockBattery); const [activeTab, setActiveTab] = useState<'info' | 'bms' | 'history' | 'rent'>('info'); const [showEditModal, setShowEditModal] = useState(false); + const [refreshing, setRefreshing] = useState(false); const handleSaveEdit = (updatedBattery: Battery) => { setBattery(updatedBattery); setShowEditModal(false); }; + const handleRefreshBMS = () => { + if (!battery.bmsData) return; + setRefreshing(true); + setTimeout(() => { + const bms = battery.bmsData!; + setBattery({ + ...battery, + bmsData: { + ...bms, + voltage: Math.round((60 + Math.random() * 10) * 10) / 10, + current: Math.round((-3 + Math.random() * 4) * 10) / 10, + soc: Math.floor(Math.random() * 40) + 60, + temperature: 25 + Math.floor(Math.random() * 15), + cycles: bms.cycles + 1, + health: Math.max(70, Math.min(100, bms.health + (Math.random() > 0.7 ? 1 : 0))), + timestamp: new Date().toISOString().replace('T', ' ').substring(0, 19) + }, + currentSoc: Math.floor(Math.random() * 40) + 60, + health: Math.max(70, Math.min(100, battery.health + (Math.random() > 0.7 ? 1 : 0))) + }); + setRefreshing(false); + }, 1000); + }; + return (
@@ -192,11 +218,18 @@ export default function BatteryDetailPage({ params }: { params: Promise<{ id: st {battery.bmsData && (
-
- - Live BMS Data - Real-time - +
+
+ + Live BMS Data + Real-time +
+
+ Updated: {battery.bmsData.timestamp} + +
diff --git a/src/app/admin/batteries/page.tsx b/src/app/admin/batteries/page.tsx index 7b5a9e3..2a9e0d0 100644 --- a/src/app/admin/batteries/page.tsx +++ b/src/app/admin/batteries/page.tsx @@ -44,6 +44,9 @@ interface Battery { voltage: number; purchaseDate: string; purchasePrice: number; + transactionMethod?: 'cash' | 'bank_transfer' | 'mobile_banking' | 'cheque' | 'credit' | 'other'; + autoJournal?: boolean; + autoJournalSource?: 'supplier' | 'import' | 'internal' | 'transfer' | 'other'; warrantyExpiry: string; status: 'available' | 'in-use' | 'maintenance' | 'retired' | 'charging'; currentSoc: number; @@ -879,6 +882,48 @@ function BatteryForm({ battery, onSave, onCancel }: { battery: Battery | null; o className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-accent" />
+
+ + +
+
+ +
+ {formData.autoJournal && ( +
+ + +
+ )}