# Closing Balance - Quick Guide
## The Simple Rule
```
Closing Balance = Investment - Book Voucher - Journal Entry
```
## When to Add, When to Subtract?
### Investment (Net Funds Transfer)
Always use as-is:
- ✅ **Positive** = You added money → Balance is positive
- ✅ **Negative** = You withdrew money → Balance is negative
### Book Voucher (Purchases)
Sign determines operation:
- 🔴 **Positive (Debit > Credit)** = You spent money → SUBTRACT → Shows with `-` sign
- 🟢 **Negative (Credit > Debit)** = You got refund → ADD → Shows with `+` sign
### Journal Entry (Internal Adjustments/Charges)
Sign determines operation:
- 🔴 **Positive (Debit > Credit)** = Charge/Fee → SUBTRACT → Shows with `-` sign
- 🟢 **Negative (Credit > Debit)** = Reversal/Credit → ADD → Shows with `+` sign
---
## Visual Examples
### Example 1: Normal Trading
```
You deposited: +₹1,00,000 🟢
You bought stocks (Book Voucher): -₹1,15,220 🔴 (expense)
Brokerage charges (Journal): -₹500 🔴 (charge)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Closing Balance: -₹15,720 🔴 (in deficit)
```
**Meaning:** You spent ₹15,720 more than you deposited.
---
### Example 2: With Refund
```
You deposited: +₹1,00,000 🟢
Book Voucher Net: +₹10,000 🟢 (refund!)
Journal Entry Net: -₹500 🔴 (charge)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Closing Balance: +₹1,09,500 🟢 (surplus)
```
**Meaning:** You have ₹1,09,500 available (deposit + refund - charges).
---
### Example 3: Your Specific Case
```
Bank Receipts:
- Debit: ₹1,50,000
- Credit: ₹0
Net Investment: +₹1,50,000 🟢
Book Voucher:
- Debit: ₹1,15,220.20
- Credit: ₹0
Net: -₹1,15,220.20 🔴 (negative = subtract from balance)
Journal Entry:
- Debit: ₹0
- Credit: ₹0
Net: ₹0
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Closing Balance = 150,000 - 115,220.20 - 0
= +₹34,779.80 🟢 (you have cash available)
```
---
## How It Shows in the UI
### Before (Wrong):
```
Investment: ₹1,50,000
Purchases: ₹1,15,220 ← Always positive (WRONG!)
Charges: ₹0
────────────────────────────
Balance: ₹2,65,220 ← Totally wrong!
```
### After (Correct):
```
Investment: +₹1,50,000 🟢 (green = adding)
Book Voucher: -₹1,15,220 🔴 (red = subtracting)
Journal Entry: -₹0
────────────────────────────
Balance: +₹34,779.80 🟢 (green = positive balance)
```
---
## Color Coding Explained
### 🟢 Green = Increases Your Balance
- Positive investment (deposits)
- Negative Book Voucher (refunds)
- Negative Journal Entry (charge reversals)
- Positive closing balance (surplus)
### 🔴 Red = Decreases Your Balance
- Negative investment (withdrawals)
- Positive Book Voucher (expenses)
- Positive Journal Entry (charges)
- Negative closing balance (deficit)
---
## Common Scenarios
### Scenario A: Normal Month
```
Deposited ₹50,000
Spent ₹40,000 on stocks
Charges ₹200
Balance = 50,000 - 40,000 - 200 = +₹9,800 ✅
```
### Scenario B: Got a Refund
```
Deposited ₹50,000
Net spending ₹30,000 (spent 40k, got 10k refund)
Charges ₹200
Book Voucher shows: -₹30,000 (not 40,000!)
Balance = 50,000 - 30,000 - 200 = +₹19,800 ✅
```
### Scenario C: Withdrew Money
```
Withdrew ₹20,000 (no deposits)
No purchases
No charges
Investment shows: -₹20,000 (red)
Balance = -20,000 - 0 - 0 = -₹20,000 ⚠️
```
---
## Quick Reference Table
| Component | Debit > Credit | Credit > Debit | Impact on Balance |
|-----------|----------------|----------------|-------------------|
| **Investment** | Positive (add funds) | Negative (withdraw) | Adds/subtracts directly |
| **Book Voucher** | Positive (expense) → Subtract | Negative (refund) → Add | `-` for expense, `+` for refund |
| **Journal Entry** | Positive (charge) → Subtract | Negative (reversal) → Add | `-` for charge, `+` for reversal |
---
## What Changed?
### Old Formula (WRONG):
```javascript
Balance = Investment + abs(Purchases) + abs(Charges)
^^^ ^^^
Always adds them (wrong!)
```
### New Formula (CORRECT):
```javascript
Balance = Investment - Purchases - Charges
^ ^
Subtract net expenses
```
**The Key:** When Purchases/Charges are negative (credits > debits), subtracting a negative = adding!
```
Examples:
Balance = 100,000 - (50,000) = 50,000 ← Expense decreases balance
Balance = 100,000 - (-10,000) = 110,000 ← Refund increases balance
```
---
## Need Help?
If your closing balance doesn't look right:
1. ✅ Check Investment is correct (deposits - withdrawals)
2. ✅ Check Book Voucher net (should be positive if you bought stocks)
3. ✅ Check Journal Entry net (should be positive if you paid charges)
4. ✅ Verify the calculation: Investment - BookVoucher - JournalEntry
If still confused, see the detailed guide: `LEDGER_CLOSING_BALANCE_REFACTOR.md`