




						
# Chit Fund Management System

This is a simple, production‑ready web application for managing a chit fund business. It is built with a LAMP‑style stack using **PHP** (procedural), **MySQL** (with MySQLi), **Bootstrap 5**, **HTML5/CSS3**, **jQuery** and **AJAX**.

## Features

### Authentication

* Secure login with session‑based authentication for two roles: **Admin** and **Member**.
* Passwords are hashed using PHP’s `password_hash()` function and verified with `password_verify()`.
* A default admin account (`admin` / `admin123`) is automatically created on first run if no admin exists.

### Admin Module

* **Dashboard** showing total members, active chits, pending payments and closed chits.
* **Members Management** – add, edit and delete members using AJAX modals. Passwords are stored hashed. Unique usernames enforced.
* **Chit Groups** – create new chit groups, edit existing ones, delete groups and assign members to chits via a multi‑select modal. Chit parameters include total amount, duration, monthly amount and start date.
* **Payments** – view a consolidated list of monthly payments for each chit/member, filter by chit and toggle payment status between **Paid** and **Pending** via AJAX. Updating a payment automatically sets/clears the payment date.
* **Auctions** – record monthly auctions, selecting a chit, month, winner and bid amount. The final payout is calculated automatically (`final_payout = total_amount − bid_amount`). Duplicate auctions for the same chit and month are prevented.
* **Reports** – view all payment transactions with filters for member, chit and month. Amounts and payment dates are clearly displayed, and statuses are colour‑coded.

### Member Module

* **Dashboard** – shows each chit the member is enrolled in, with summary information: total paid amount, remaining balance, months left and current overall payment status (Paid/Pending). Colour‑coded badges indicate outstanding dues.
* **Payment History** – view month‑wise payment history for any chit in a modal popup. Lists month number, amount, status and payment date.
* Members have read‑only access; they cannot add or modify data.

### Security & Best Practices

* All database interactions use prepared statements to prevent SQL injection.
* Input validation and basic sanitisation are performed server‑side.
* User roles are enforced on every API endpoint and page via session checks.
* Sessions are started with custom names and HTTP‑only cookies for extra security.

### Database Schema

The MySQL schema is defined in `database.sql`. Tables include:

* `admins` – stores admin credentials.
* `members` – stores member details and login credentials.
* `chit_groups` – defines each chit with its financial parameters.
* `chit_members` – mapping table linking members to chits with join dates and statuses.
* `payments` – tracks monthly payment records for every member in each chit.
* `auctions` – records monthly auctions (winner, bid amount and final payout).

Sample data is included to get you started: a few members, two chit groups, some payments and an auction. Passwords in the SQL file are plain text by design; they are automatically hashed on first login/edit.

## Running Locally

1. **Install XAMPP or WAMP** on your local machine if you haven’t already.
2. Copy the `chitfund_app` folder to your web server’s document root (e.g. `htdocs` for XAMPP).
3. Create a new MySQL database called `chitfund_db` (or change the name in `includes/config.php`).
4. Import the `database.sql` file into your database. You can use phpMyAdmin or the MySQL CLI:

   ```sh
   mysql -u root -p chitfund_db < database.sql
   ```

5. Edit `includes/config.php` to match your MySQL credentials (host, user, password, database name).
6. Open a browser and navigate to `http://localhost/chitfund_app`. You should see the login page.
7. **Login as Admin** using `admin` as the username and `admin123` as the password. The application will automatically create this account if it doesn’t exist.
8. Explore the admin panel to add members, create chits, record payments, conduct auctions and view reports.
9. For testing the member portal, log in using one of the sample member accounts (e.g. `ravi` / `member123`, `sita` / `member123`, etc.). After first login the passwords will be hashed automatically.

## Deployment

* This application uses only core PHP and MySQLi; it does not depend on any external PHP frameworks.
* Bootstrap and jQuery are loaded from public CDNs for convenience. You may download and serve them locally if internet access is restricted.
* All paths are relative; the project should work on shared hosting (cPanel) without modification as long as PHP 7.4+ and MySQL are available.

## Notes

* The application is intentionally kept simple for ease of understanding and extensibility. You can customise the UI, add more validations or integrate additional features such as notifications or reminders.
* Ensure your server’s `session.save_path` is writable and consider enabling HTTPS in production for added security.

Enjoy managing your chit fund with this lightweight and intui