Inline-ized ledger add rows
X-Lovable-Edit-ID: edt-0f79cce8-a81a-43c5-84d6-71d5b51d9e32 Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
@@ -381,9 +381,6 @@ export function CollectionDetail({
|
||||
const { user } = useAuth();
|
||||
const [entries, setEntries] = useState<any[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [chargeOpen, setChargeOpen] = useState(false);
|
||||
const [paymentOpen, setPaymentOpen] = useState(false);
|
||||
const [bankOpen, setBankOpen] = useState(false);
|
||||
const [importOpen, setImportOpen] = useState(false);
|
||||
|
||||
// Editable header fields
|
||||
@@ -426,8 +423,8 @@ export function CollectionDetail({
|
||||
}
|
||||
};
|
||||
|
||||
// Insert a blank row at the end (sort_order = max+10)
|
||||
const addBlankRow = async () => {
|
||||
// Insert a new row at the end. Optional preset for transaction_type / description.
|
||||
const addBlankRow = async (preset?: { transaction_type?: string; description?: string }) => {
|
||||
const maxSort = entries.reduce((m: number, e: any) => Math.max(m, Number(e.sort_order) || 0), 0);
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
const { data, error } = await supabase
|
||||
@@ -435,7 +432,8 @@ export function CollectionDetail({
|
||||
.insert({
|
||||
collection_id: collection.id,
|
||||
entry_date: today,
|
||||
transaction_type: "adjustment",
|
||||
transaction_type: preset?.transaction_type ?? "adjustment",
|
||||
description: preset?.description ?? null,
|
||||
sort_order: maxSort + 10,
|
||||
created_by: user?.id,
|
||||
})
|
||||
@@ -813,48 +811,30 @@ export function CollectionDetail({
|
||||
</table>
|
||||
)}
|
||||
|
||||
{/* Quick-add row */}
|
||||
{/* Quick-add row — inline ledger entry shortcuts */}
|
||||
<div className="flex flex-wrap gap-2 p-3 border-t bg-muted/10">
|
||||
<Button variant="outline" size="sm" onClick={() => setChargeOpen(true)}>
|
||||
<Button variant="outline" size="sm" onClick={() => addBlankRow({ transaction_type: "assessment" })}>
|
||||
<Plus className="h-4 w-4 mr-1.5" /> Add Charge (Debit)
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" className="text-emerald-700 border-emerald-200 hover:bg-emerald-50 dark:text-emerald-400 dark:border-emerald-900" onClick={() => setPaymentOpen(true)}>
|
||||
<Button variant="outline" size="sm" className="text-emerald-700 border-emerald-200 hover:bg-emerald-50 dark:text-emerald-400 dark:border-emerald-900" onClick={() => addBlankRow({ transaction_type: "payment" })}>
|
||||
<Plus className="h-4 w-4 mr-1.5" /> Add Payment (AR Credit)
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" className="text-destructive border-destructive/30 hover:bg-destructive/10" onClick={() => setBankOpen(true)}>
|
||||
<Button variant="outline" size="sm" className="text-destructive border-destructive/30 hover:bg-destructive/10" onClick={() => addBlankRow({ transaction_type: "adjustment", description: "Bank fee" })}>
|
||||
<Plus className="h-4 w-4 mr-1.5" /> Add Bank Fee
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" onClick={calcInterestRow} disabled={!effectiveRate || effectiveRate <= 0}>
|
||||
<Calculator className="h-4 w-4 mr-1.5" /> Calculate Interest Row
|
||||
</Button>
|
||||
<Button variant="ghost" size="sm" onClick={addBlankRow}>
|
||||
<Button variant="ghost" size="sm" onClick={() => addBlankRow()}>
|
||||
<Plus className="h-4 w-4 mr-1.5" /> Add Blank Row
|
||||
</Button>
|
||||
<p className="w-full text-[11px] text-muted-foreground mt-1">
|
||||
Tip: click any cell in the new row to enter the date, description, account, or amount directly.
|
||||
</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<AddChargeDialog
|
||||
open={chargeOpen}
|
||||
onOpenChange={setChargeOpen}
|
||||
collectionId={collection.id}
|
||||
userId={user?.id}
|
||||
onSaved={() => { load(); onChange(); }}
|
||||
/>
|
||||
<AddPaymentDialog
|
||||
open={paymentOpen}
|
||||
onOpenChange={setPaymentOpen}
|
||||
collectionId={collection.id}
|
||||
userId={user?.id}
|
||||
onSaved={() => { load(); onChange(); }}
|
||||
/>
|
||||
<AddBankFeeDialog
|
||||
open={bankOpen}
|
||||
onOpenChange={setBankOpen}
|
||||
collectionId={collection.id}
|
||||
userId={user?.id}
|
||||
onSaved={() => { load(); onChange(); }}
|
||||
/>
|
||||
<ImportCsvDialog
|
||||
open={importOpen}
|
||||
onOpenChange={setImportOpen}
|
||||
|
||||
Reference in New Issue
Block a user