From fc091eb6668d423623690aedfc272929e0e29002 Mon Sep 17 00:00:00 2001 From: Duradundi Hadimani Date: Fri, 14 Nov 2025 18:42:25 +0530 Subject: [PATCH] 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 */}