# Quotation & Invoice Management System

A comprehensive web-based quotation and invoice management system built with plain PHP, featuring customer management, material inventory, and PDF generation capabilities.

## Features

### 🔐 Authentication
- Secure login system with password encryption
- Session management
- Default admin credentials: `admin` / `admin123`

### 🏠 Dashboard
- Summary metrics (customers, quotations, invoices, materials)
- Recent activity overview
- Quick action buttons
- Modern, responsive design

### 👥 Customer Management
- Add, edit, and delete customers
- Customer information: Name, Contact, Email, Address, GST Number
- Search and filter functionality
- Data validation

### 📑 Quotation System
- Multi-step quotation creation process:
  1. Customer selection
  2. Company details review
  3. Material selection with quantity and pricing
- Auto-calculation of totals
- Quotation numbering system
- Status tracking (Draft, Sent, Accepted, Rejected)
- PDF generation and printing

### 🧾 Invoice Management
- Similar to quotations but with invoice-specific features:
  - Invoice numbering
  - Due date tracking
  - Payment status (Pending, Partial, Paid)
  - Overdue detection
- PDF generation and printing

### 🧱 Material Management
- Add, edit, and delete materials
- Material details: Name, Description, Unit Price, Stock Quantity
- Stock level indicators
- Search functionality

### 📄 PDF Generation
- Professional quotation and invoice templates
- Print-friendly layouts
- Downloadable HTML/PDF files
- Company branding support

## Installation

### Prerequisites
- PHP 7.4 or higher
- MySQL 5.7 or higher
- Web server (Apache/Nginx)
- XAMPP/WAMP/LAMP (for local development)

### Setup Instructions

1. **Clone/Download the project**
   ```bash
   git clone <repository-url>
   # or download and extract the ZIP file
   ```

2. **Database Setup**
   - Create a MySQL database named `quotation_system`
   - Import the database structure (tables will be created automatically on first run)

3. **Configuration**
   - Update database credentials in `config/database.php` if needed:
     ```php
     define('DB_HOST', 'localhost');
     define('DB_USER', 'root');
     define('DB_PASS', '');
     define('DB_NAME', 'quotation_system');
     ```

4. **Web Server Setup**
   - Place the project files in your web server's document root
   - For XAMPP: `C:\xampp\htdocs\quotation`
   - For WAMP: `C:\wamp64\www\quotation`

5. **Access the Application**
   - Open your web browser
   - Navigate to `http://localhost/quotation`
   - Login with default credentials: `admin` / `admin123`

## File Structure

```
quotation/
├── config/
│   ├── database.php          # Database configuration
│   └── session.php           # Session management
├── includes/
│   ├── header.php            # Common header
│   ├── footer.php            # Common footer
│   └── pdf_generator.php     # PDF generation class
├── assets/
│   ├── css/
│   │   └── style.css         # Custom styles
│   └── js/
│       └── script.js         # Custom JavaScript
├── index.php                 # Dashboard
├── login.php                 # Login page
├── logout.php                # Logout handler
├── customers.php             # Customer management
├── quotations.php            # Quotation management
├── invoices.php              # Invoice management
├── materials.php             # Material management
├── view_quotation.php        # Quotation view/print
├── view_invoice.php          # Invoice view/print
├── download_quotation.php    # Quotation PDF download
├── download_invoice.php      # Invoice PDF download
└── README.md                 # This file
```

## Database Schema

The system automatically creates the following tables:

- `users` - User authentication
- `customers` - Customer information
- `materials` - Material inventory
- `quotations` - Quotation headers
- `quotation_items` - Quotation line items
- `invoices` - Invoice headers
- `invoice_items` - Invoice line items

## Usage Guide

### Getting Started
1. **Login**: Use the default admin credentials to access the system
2. **Add Customers**: Go to Customers → Add Customer to create your customer database
3. **Add Materials**: Go to Materials → Add Material to set up your product catalog
4. **Create Quotations**: Go to Quotations → Add Quotation to create professional quotations
5. **Generate Invoices**: Go to Invoices → Add Invoice to create invoices from quotations

### Creating a Quotation
1. Click "Add Quotation"
2. **Step 1**: Select a customer from the dropdown
3. **Step 2**: Review company and customer details
4. **Step 3**: Add materials with quantities and rates
5. Review totals and create the quotation
6. View, print, or download the quotation

### Creating an Invoice
1. Click "Add Invoice"
2. **Step 1**: Select a customer
3. **Step 2**: Set due date and payment status
4. **Step 3**: Add materials and create the invoice
5. Track payment status and overdue invoices

## Customization

### Company Information
Update company details in the PDF generator files:
- `includes/pdf_generator.php` - Company information section
- `view_quotation.php` - Company details display
- `view_invoice.php` - Company details display

### Styling
- Modify `assets/css/style.css` for custom styling
- Update color scheme in CSS variables
- Add your company logo to the header

### Database
- Add custom fields to tables as needed
- Modify validation rules in PHP files
- Update form fields accordingly

## Security Features

- Password hashing using PHP's `password_hash()`
- SQL injection prevention with prepared statements
- XSS protection with `htmlspecialchars()`
- Session management and authentication
- Input validation and sanitization

## Browser Support

- Chrome 70+
- Firefox 65+
- Safari 12+
- Edge 79+
- Mobile responsive design

## Troubleshooting

### Common Issues

1. **Database Connection Error**
   - Check database credentials in `config/database.php`
   - Ensure MySQL service is running
   - Verify database exists

2. **Login Issues**
   - Default credentials: `admin` / `admin123`
   - Check if user exists in database
   - Clear browser cache and cookies

3. **PDF Generation Issues**
   - Ensure proper file permissions
   - Check if download links are working
   - Verify browser popup blockers

4. **Styling Issues**
   - Clear browser cache
   - Check if CSS files are loading
   - Verify file paths are correct

## Support

For support and customization requests, please refer to the documentation or contact the development team.

## License

This project is open source and available under the MIT License.

## Version History

- **v1.0.0** - Initial release with core functionality
  - Customer management
  - Quotation system
  - Invoice system
  - Material management
  - PDF generation
  - Dashboard and reporting
