From 03cf1cf98dc89c448a6129a6b1909f4eac34f186 Mon Sep 17 00:00:00 2001 From: Duradundi Hadimani Date: Fri, 14 Nov 2025 17:05:28 +0530 Subject: [PATCH 1/3] Latest Changes --- src/pages/AssetDetail.tsx | 301 ++++++++++++++++++++++++++++++++++- src/services/assetService.ts | 10 ++ 2 files changed, 305 insertions(+), 6 deletions(-) diff --git a/src/pages/AssetDetail.tsx b/src/pages/AssetDetail.tsx index 1eb9f87..fc9d956 100644 --- a/src/pages/AssetDetail.tsx +++ b/src/pages/AssetDetail.tsx @@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react'; import { useParams, useNavigate, useSearchParams } from 'react-router-dom'; import { useAssetDetails, useAssetMutations } from '../hooks/useAsset'; import { FaArrowLeft, FaSave, FaEdit, FaQrcode } from 'react-icons/fa'; -import type { CreateAssetData } from '../services/assetService'; +import type { CreateAssetData, AssetFinanceBookRow } from '../services/assetService'; import LinkField from '../components/LinkField'; import apiService from '../services/apiService'; // ✅ your ApiService @@ -51,6 +51,15 @@ const AssetDetail: React.FC = () => { available_for_use_date: isNewAsset ? new Date().toISOString().split('T')[0] : undefined }); + const emptyFinanceRow = { + finance_book: "", + depreciation_method: "", + total_number_of_depreciations: 0, + frequency_of_depreciation: "", + depreciation_start_date: "", + }; + + // Load user details on mount useEffect(() => { async function loadUserDetails() { @@ -65,6 +74,38 @@ const AssetDetail: React.FC = () => { loadUserDetails(); }, []); + const addFinanceRow = () => { + setFormData(prev => ({ + ...prev, + finance_books: [ + ...(prev.finance_books || []), + { + finance_book: '', + depreciation_method: '', + total_number_of_depreciations: 0, + frequency_of_depreciation: '', + depreciation_start_date: '' + } + ] + })); + }; + + const removeFinanceRow = (index: number) => { + setFormData(prev => { + const rows = [...(prev.finance_books || [])]; + rows.splice(index, 1); + return { ...prev, finance_books: rows }; + }); + }; + + const updateFinanceRow = (index: number, patch: Partial) => { + setFormData(prev => { + const rows = [...(prev.finance_books || [])]; + rows[index] = { ...(rows[index] || {}), ...patch }; + return { ...prev, finance_books: rows }; + }); + }; + // Update department filters when company or userSiteName changes useEffect(() => { const filters: Record = {}; @@ -436,7 +477,8 @@ const AssetDetail: React.FC = () => { -
+
+ {/*
*/} @@ -452,6 +494,22 @@ const AssetDetail: React.FC = () => {

)}
+
+ + +
@@ -619,7 +677,7 @@ const AssetDetail: React.FC = () => { disabled={!isEditing} /> -
+ {/*
@@ -632,9 +690,9 @@ const AssetDetail: React.FC = () => { disabled={!isEditing} className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:bg-gray-100 dark:disabled:bg-gray-700 bg-white dark:bg-gray-700 text-gray-900 dark:text-white" /> -
+
*/} -
+ {/*
@@ -644,7 +702,7 @@ const AssetDetail: React.FC = () => { disabled={!isEditing} className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:bg-gray-100 dark:disabled:bg-gray-700 bg-white dark:bg-gray-700 text-gray-900 dark:text-white" /> -
+
*/}
+ {/* Asset Finance Book child table — shown only when checkbox checked */} + {formData.calculate_depreciation && ( +
+ + {/* Header with Add Row button */} +
+

+ Asset Finance Book +

+ + {isEditing && ( + + )} +
+ + {/* TABLE HEADER */} +
+
Finance Book
+
Depreciation Method
+
Total Depreciations
+
Frequency
+
Start Date
+
Action
+
+ + {/* TABLE ROWS */} +
+ + {(formData.finance_books || []).map((row: AssetFinanceBookRow, idx: number) => ( +
+ {/* Finance Book */} + updateFinanceRow(idx, { finance_book: e.target.value })} + disabled={!isEditing} + className="w-full px-2 py-1 border rounded-md dark:bg-gray-700 dark:text-white" + /> + + {/* Depreciation Method */} + + + {/* Total Depreciations */} + + updateFinanceRow(idx, { + total_number_of_depreciations: Number(e.target.value), + }) + } + disabled={!isEditing} + className="w-full px-2 py-1 border rounded-md dark:bg-gray-700 dark:text-white" + /> + + {/* Frequency */} + + updateFinanceRow(idx, { frequency_of_depreciation: e.target.value }) + } + disabled={!isEditing} + className="w-full px-2 py-1 border rounded-md dark:bg-gray-700 dark:text-white" + /> + + {/* Start Date */} + + updateFinanceRow(idx, { depreciation_start_date: e.target.value }) + } + disabled={!isEditing} + className="w-full px-2 py-1 border rounded-md dark:bg-gray-700 dark:text-white" + /> + + {/* REMOVE BUTTON */} + {isEditing && ( +
+ +
+ )} +
+ ))} + +
+
+ )} + + {/* {formData.calculate_depreciation && ( +
+
+

Asset Finance Book

+ {isEditing && ( + + )} +
+ +
+ {(formData.finance_books || []).length === 0 && ( +
No finance book rows added.
+ )} + + + {(formData.finance_books || []).map((row: AssetFinanceBookRow, idx: number) => ( +
+
+ +
+ + updateFinanceRow(idx, { finance_book: e.target.value })} + disabled={!isEditing} + className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 bg-white dark:bg-gray-700 text-gray-900 dark:text-white" + /> +
+ + +
+ + +
+ + +
+ + updateFinanceRow(idx, { total_number_of_depreciations: Number(e.target.value) })} + disabled={!isEditing} + className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 bg-white dark:bg-gray-700 text-gray-900 dark:text-white" + /> +
+ + +
+ + updateFinanceRow(idx, { frequency_of_depreciation: e.target.value })} + disabled={!isEditing} + placeholder="e.g. Monthly, Yearly" + className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 bg-white dark:bg-gray-700 text-gray-900 dark:text-white" + /> +
+ + +
+ + updateFinanceRow(idx, { depreciation_start_date: e.target.value })} + disabled={!isEditing} + className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 bg-white dark:bg-gray-700 text-gray-900 dark:text-white" + /> +
+
+ + {/* Row actions */} + {/* {isEditing && ( +
+ +
+ )} +
+ ))} +
+
+ )} */} + diff --git a/src/services/assetService.ts b/src/services/assetService.ts index 5aeab11..a56833d 100644 --- a/src/services/assetService.ts +++ b/src/services/assetService.ts @@ -67,6 +67,15 @@ export interface AssetStats { total_amount: number; } +// Add child row type +export interface AssetFinanceBookRow { + finance_book?: string; + depreciation_method?: string; + total_number_of_depreciations?: number; + frequency_of_depreciation?: string; + depreciation_start_date?: string; // YYYY-MM-DD +} + export interface CreateAssetData { asset_name: string; company: string; @@ -87,6 +96,7 @@ export interface CreateAssetData { custom_site_contractor?: string; custom_total_amount?: number; calculate_depreciation?: boolean; + finance_books?: AssetFinanceBookRow[]; [key: string]: any; } From fc091eb6668d423623690aedfc272929e0e29002 Mon Sep 17 00:00:00 2001 From: Duradundi Hadimani Date: Fri, 14 Nov 2025 18:42:25 +0530 Subject: [PATCH 2/3] Updated AssetDetails for adding Depreciation table --- src/pages/AssetDetail.tsx | 509 ++++++++++++++------------------------ 1 file changed, 191 insertions(+), 318 deletions(-) diff --git a/src/pages/AssetDetail.tsx b/src/pages/AssetDetail.tsx index fb59400..16ce0de 100644 --- a/src/pages/AssetDetail.tsx +++ b/src/pages/AssetDetail.tsx @@ -80,17 +80,22 @@ const AssetDetail: React.FC = () => { }, []); const addFinanceRow = () => { + // Get today's date in YYYY-MM-DD format for date input + const today = new Date().toISOString().split('T')[0]; + + const newRow: AssetFinanceBookRow = { + finance_book: 'Depreciation Entries', + depreciation_method: 'Straight Line', + total_number_of_depreciations: 10, + frequency_of_depreciation: 12, + depreciation_start_date: today + }; + setFormData(prev => ({ ...prev, finance_books: [ ...(prev.finance_books || []), - { - finance_book: '', - depreciation_method: '', - total_number_of_depreciations: 0, - frequency_of_depreciation: '', - depreciation_start_date: '' - } + newRow ] })); }; @@ -956,323 +961,191 @@ const AssetDetail: React.FC = () => { - {/* Financial Details */} + {/* Updated Financial Details */}

Financial Details

The depreciation method is an accounting method used to allocate the cost of a tangible asset over its useful life.

-
-
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
-
- - setFormData({ - ...formData, - calculate_depreciation: e.target.checked, - }) - } - disabled={!isEditing} - className="h-4 w-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700" - /> - -
- - {/* Asset Finance Book child table — shown only when checkbox checked */} - {formData.calculate_depreciation && ( -
- - {/* Header with Add Row button */} -
-

- Asset Finance Book -

- - {isEditing && ( - - )} -
- - {/* TABLE HEADER */} -
-
Finance Book
-
Depreciation Method
-
Total Depreciations
-
Frequency
-
Start Date
-
Action
-
- - {/* TABLE ROWS */} -
- - {(formData.finance_books || []).map((row: AssetFinanceBookRow, idx: number) => ( -
- {/* Finance Book */} - updateFinanceRow(idx, { finance_book: e.target.value })} - disabled={!isEditing} - className="w-full px-2 py-1 border rounded-md dark:bg-gray-700 dark:text-white" - /> - - {/* Depreciation Method */} - - - {/* Total Depreciations */} - - updateFinanceRow(idx, { - total_number_of_depreciations: Number(e.target.value), - }) - } - disabled={!isEditing} - className="w-full px-2 py-1 border rounded-md dark:bg-gray-700 dark:text-white" - /> - - {/* Frequency */} - - updateFinanceRow(idx, { frequency_of_depreciation: e.target.value }) - } - disabled={!isEditing} - className="w-full px-2 py-1 border rounded-md dark:bg-gray-700 dark:text-white" - /> - - {/* Start Date */} - - updateFinanceRow(idx, { depreciation_start_date: e.target.value }) - } - disabled={!isEditing} - className="w-full px-2 py-1 border rounded-md dark:bg-gray-700 dark:text-white" - /> - - {/* REMOVE BUTTON */} - {isEditing && ( -
- -
- )} -
- ))} - -
-
- )} - - {/* {formData.calculate_depreciation && ( -
-
-

Asset Finance Book

- {isEditing && ( - - )} -
- -
- {(formData.finance_books || []).length === 0 && ( -
No finance book rows added.
- )} - - - {(formData.finance_books || []).map((row: AssetFinanceBookRow, idx: number) => ( -
-
- -
- - updateFinanceRow(idx, { finance_book: e.target.value })} - disabled={!isEditing} - className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 bg-white dark:bg-gray-700 text-gray-900 dark:text-white" - /> -
- - -
- - -
- - -
- - updateFinanceRow(idx, { total_number_of_depreciations: Number(e.target.value) })} - disabled={!isEditing} - className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 bg-white dark:bg-gray-700 text-gray-900 dark:text-white" - /> -
- - -
- - updateFinanceRow(idx, { frequency_of_depreciation: e.target.value })} - disabled={!isEditing} - placeholder="e.g. Monthly, Yearly" - className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 bg-white dark:bg-gray-700 text-gray-900 dark:text-white" - /> -
- - -
- - updateFinanceRow(idx, { depreciation_start_date: e.target.value })} - disabled={!isEditing} - className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 bg-white dark:bg-gray-700 text-gray-900 dark:text-white" - /> -
-
- - {/* Row actions */} - {/* {isEditing && ( -
- -
- )} -
- ))} -
-
- )} */} - + +
+ + setFormData({ + ...formData, + calculate_depreciation: e.target.checked, + }) + } + disabled={!isEditing} + className="h-4 w-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700" + /> +
+ + {/* Asset Finance Book child table — shown only when checkbox checked */} + {formData.calculate_depreciation && ( +
+ {/* Header with Add Row button */} +
+

+ Asset Finance Books +

+ {isEditing && ( + + )} +
+ + {/* Show message if no rows */} + {(!formData.finance_books || formData.finance_books.length === 0) && ( +
+ No finance books added yet. Click "Add Row" to add one. +
+ )} + + {/* TABLE - Full width desktop view with overflow fix */} + {formData.finance_books && formData.finance_books.length > 0 && ( +
+
+ + + + + + + + + {isEditing && ( + + )} + + + + {formData.finance_books.map((row: AssetFinanceBookRow, idx: number) => ( + + {/* Finance Book - with overflow visible */} + + + {/* Depreciation Method */} + + + {/* Total Depreciations */} + + + {/* Frequency */} + + + {/* Start Date */} + + + {/* REMOVE BUTTON */} + {isEditing && ( + + )} + + ))} + +
+ Finance Book + + Depreciation Method* + + Total Depreciations* + + Frequency (Months)* + + Depreciation Posting Date* + + Action +
+
+ updateFinanceRow(idx, { finance_book: val })} + disabled={!isEditing} + /> +
+
+ + + + updateFinanceRow(idx, { + total_number_of_depreciations: Number(e.target.value), + }) + } + disabled={!isEditing} + placeholder="0" + className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:bg-gray-100 dark:disabled:bg-gray-700 bg-white dark:bg-gray-700 text-gray-900 dark:text-white" + /> + + + updateFinanceRow(idx, { + frequency_of_depreciation: Number(e.target.value), + }) + } + disabled={!isEditing} + placeholder="0" + className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:bg-gray-100 dark:disabled:bg-gray-700 bg-white dark:bg-gray-700 text-gray-900 dark:text-white" + /> + + + updateFinanceRow(idx, { depreciation_start_date: e.target.value }) + } + disabled={!isEditing} + className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:bg-gray-100 dark:disabled:bg-gray-700 bg-white dark:bg-gray-700 text-gray-900 dark:text-white" + /> + + +
+
+
+ )} +
+ )}
{/* End-of-Life Details */} From 29ded9f6a696fc1c64495c8a8f4bae085aed00e6 Mon Sep 17 00:00:00 2001 From: Duradundi Hadimani Date: Fri, 14 Nov 2025 18:57:55 +0530 Subject: [PATCH 3/3] Latest Changes of Finance book Table --- src/pages/AssetDetail.tsx | 23 +++++++++++++---------- src/services/assetService.ts | 3 ++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/pages/AssetDetail.tsx b/src/pages/AssetDetail.tsx index 16ce0de..680127d 100644 --- a/src/pages/AssetDetail.tsx +++ b/src/pages/AssetDetail.tsx @@ -26,6 +26,15 @@ const AssetDetail: React.FC = () => { const { asset, loading, error } = useAssetDetails( isDuplicating ? duplicateFromAsset : (isNewAsset ? null : assetName || null) ); + + // Add this after the hook call + useEffect(() => { + if (asset) { + console.log('Full asset object:', asset); + console.log('Finance books:', asset.finance_books); + } + }, [asset]); + const { createAsset, updateAsset, loading: saving } = useAssetMutations(); const [isEditing, setIsEditing] = useState(isNewAsset); @@ -53,17 +62,10 @@ const AssetDetail: React.FC = () => { custom_site_contractor: '', custom_total_amount: 0, calculate_depreciation: false, - available_for_use_date: isNewAsset ? new Date().toISOString().split('T')[0] : undefined + available_for_use_date: isNewAsset ? new Date().toISOString().split('T')[0] : undefined, + finance_books:[] }); - const emptyFinanceRow = { - finance_book: "", - depreciation_method: "", - total_number_of_depreciations: 0, - frequency_of_depreciation: "", - depreciation_start_date: "", - }; - // Load user details on mount useEffect(() => { @@ -171,7 +173,8 @@ const AssetDetail: React.FC = () => { custom_total_amount: asset.custom_total_amount || 0, gross_purchase_amount:asset.gross_purchase_amount || 0, available_for_use_date: asset.available_for_use_date || '', - calculate_depreciation: asset.calculate_depreciation || false + calculate_depreciation: asset.calculate_depreciation || false, + finance_books: asset.finance_books || [] }); } }, [asset, isDuplicating]); diff --git a/src/services/assetService.ts b/src/services/assetService.ts index a56833d..bef3190 100644 --- a/src/services/assetService.ts +++ b/src/services/assetService.ts @@ -30,6 +30,7 @@ export interface Asset { calculate_depreciation?: boolean; gross_purchase_amount?: number; available_for_use_date?:string; + finance_books?: AssetFinanceBookRow[]; } export interface AssetListResponse { @@ -72,7 +73,7 @@ export interface AssetFinanceBookRow { finance_book?: string; depreciation_method?: string; total_number_of_depreciations?: number; - frequency_of_depreciation?: string; + frequency_of_depreciation?: number; depreciation_start_date?: string; // YYYY-MM-DD }