@@ -212,12 +212,19 @@ impl AccountFormState {
212212 let account_type = self . selected_account_type ( ) ;
213213
214214 let balance_str = self . balance_input . value ( ) . trim ( ) ;
215- let starting_balance = if balance_str. is_empty ( ) {
215+ let mut starting_balance = if balance_str. is_empty ( ) {
216216 Money :: zero ( )
217217 } else {
218218 Money :: parse ( balance_str) . map_err ( |_| "Invalid balance" ) ?
219219 } ;
220220
221+ // For liability accounts (credit cards, lines of credit), balances represent
222+ // debt owed and should be stored as negative values. Users naturally enter
223+ // positive numbers when specifying debt, so we negate them.
224+ if account_type. is_liability ( ) && starting_balance. cents ( ) > 0 {
225+ starting_balance = Money :: from_cents ( -starting_balance. cents ( ) ) ;
226+ }
227+
221228 let mut account = Account :: with_starting_balance ( name, account_type, starting_balance) ;
222229 account. on_budget = self . on_budget ;
223230
@@ -602,12 +609,18 @@ fn save_account(app: &mut App) -> Result<(), String> {
602609
603610 // Update starting balance
604611 let balance_str = app. account_form . balance_input . value ( ) . trim ( ) ;
605- existing . starting_balance = if balance_str. is_empty ( ) {
612+ let mut new_balance = if balance_str. is_empty ( ) {
606613 Money :: zero ( )
607614 } else {
608615 Money :: parse ( balance_str) . map_err ( |_| "Invalid balance" ) ?
609616 } ;
610617
618+ // For liability accounts, negate positive balances (debt is stored as negative)
619+ if existing. account_type . is_liability ( ) && new_balance. cents ( ) > 0 {
620+ new_balance = Money :: from_cents ( -new_balance. cents ( ) ) ;
621+ }
622+ existing. starting_balance = new_balance;
623+
611624 existing. updated_at = chrono:: Utc :: now ( ) ;
612625
613626 let account_name = existing. name . clone ( ) ;
0 commit comments