Finance Tracking PHP

๐Ÿ“˜ Finance Tracker – Project Documentation

Finance Tracker is a basic PHP-based web application that helps users manage their personal finances by recording income and expenses. This document explains how the application works, its structure, and how the code components interact with each other.

 


๐Ÿ’ก How It Works (Overview)

The Finance Tracker allows users to:

  • Add income and expense transactions
     
  • View a running balance, total income, and total expenses
     
  • Delete specific transactions
     
  • Store all data locally in a JSON file
     

The application is built using:

  • PHP for backend logic and file handling
     
  • HTML & CSS for the frontend and layout
     
  • JSON file as a simple data storage system
     

 


๐Ÿ”ง Main Components Explained

index.php – The Main Interface

This is the main file loaded when you open the app in a browser. It:

  • Loads transaction data from the JSON file
     
  • Displays the current balance, income, and expense summary
     
  • Shows the list of transactions
     
  • Provides a form to add new transactions
     

includes/functions.php – Core Functions

Contains reusable PHP functions such as:

  • getTransactions() – Reads and returns data from the JSON file
     
  • saveTransactions() – Saves the updated data back to the JSON file
     
  • calculateTotals() – Calculates total income, expenses, and balance
     

This file is included in both index.php and other PHP scripts to keep logic organized.

includes/add_transaction.php – Adding Transactions

Handles form submissions when a user adds a new transaction:

  • Validates and sanitizes input (description and amount)
     
  • Loads the existing transaction data
     
  • Appends the new transaction
     
  • Saves everything back to the JSON file
     
  • Redirects the user back to the main page
     

includes/delete_transaction.php – Deleting Transactions

Triggered when a user clicks the "×" button next to a transaction:

  • Gets the transaction ID from the URL
     
  • Loads and filters out the transaction from the JSON file
     
  • Saves the updated list
     
  • Redirects back to index.php
     

data/transactions.json – Data Storage

This is where all transactions are stored:

  • Structured as a JSON array of objects
     
  • Automatically created when the first transaction is added
     
  • Example:
     

json

CopyEdit

[

  {

    "id": 1,

    "description": "Salary",

    "amount": 1000

  },

  {

    "id": 2,

    "description": "Groceries",

    "amount": -150

  }

]

 

css/style.css – Styling the App

Handles the look and feel:

  • Responsive layout for mobile and desktop
     
  • Styles for the transaction list, balance summary, and form
     
  • Visual feedback for income (green) and expenses (red)
     

 


๐Ÿงช How Transactions Are Processed

Adding a Transaction:

  1. User fills in the form
     
  2. Data is sent to add_transaction.php
     
  3. Data is validated, added to JSON file
     
  4. Page redirects back to index.php and displays updated info
     

Deleting a Transaction:

  1. User clicks the delete (×) button
     
  2. Browser sends a GET request with the transaction ID
     
  3. delete_transaction.php removes it from the JSON file
     
  4. User is redirected back to index.php with the updated list
     

 


โœ… Why Use JSON Instead of a Database?

JSON is simple and works well for small apps or demos:

  • Easy to read and edit manually
     
  • No need to install/configure a database
     
  • Great for beginners learning file-based data storage
     

However, for larger or multi-user apps, a database like MySQL would be better for performance and data integrity.

Screenshots::

 



GitHub Url :https://github.com/brahmaputraS/finance-tracking