# Inventory Management System A comprehensive inventory management system built with Vue 3 frontend and PHP backend, featuring inventory tracking, client management, project management, bookkeeping, and authentication. ## 🚀 **Latest Features** ### **Core Inventory Management** - **Item Management** - Full CRUD operations with serial number tracking - **Picture Upload** - Image attachment system for inventory items - **Rental Pricing** - Dynamic pricing with date ranges and client assignments - **Document Attachments** - Multi-format document management (Receipt, Warranty, Other) ### **Advanced Client Management** - **Customer Profiles** - Complete contact information with y-tunnus support - **Contact Persons** - Individual contact management with primary contact designation - **Hourly Rates** - Customer-specific billing rates for project management - **Address Management** - Full address support with international formatting ### **Project & Subproject Management** - **Project Tracking** - Customer project management with status monitoring - **Subproject Breakdown** - Detailed task management within projects - **Progress Monitoring** - Visual progress bars and completion tracking - **Budget Management** - Financial control and cost tracking - **Date Range Management** - Start and end date tracking ### **Financial Management** - **Invoice System** - Complete billing with line items and payment tracking - **Payment Processing** - Multiple payment methods (Cash, Check, Credit Card, Bank Transfer) - **Double-Entry Bookkeeping** - Professional accounting with debit/credit tracking - **Chart of Accounts** - Hierarchical account structure (Assets, Liabilities, Equity, Revenue, Expenses) - **Journal Entries** - Transaction recording with automatic entry numbering ### **Enterprise Security** - **User Authentication** - Secure login with password hashing - **Role-Based Access** - Admin, Manager, User roles - **Session Management** - Secure session handling and automatic cleanup - **API Protection** - Middleware-based endpoint security ## 🏗 **Technology Stack** ### **Frontend** - **Vue 3** - Progressive JavaScript framework - **Axios** - HTTP client for API communication - **Vite** - Fast development server - **TailwindCSS** - Utility-first CSS framework - **Responsive Design** - Mobile-friendly interface ### **Backend** - **PHP 7.4+** - Modern server-side language - **MySQL/MariaDB** - Reliable database system - **RESTful API** - Standard HTTP methods and JSON responses - **PDO** - Secure database connections - **Password Hashing** - PHP's built-in security functions ## 📋 **Database Schema** The system uses a normalized database structure with proper relationships: ### **Core Tables** - **items** - Inventory with serial numbers and pictures - **clients** - Customer management with y-tunnus and hourly rates - **contact_persons** - Individual contacts linked to clients - **rental_prices** - Item pricing with date ranges and client assignments - **attachments** - Document management with categorization ### **Financial Tables** - **invoices** - Billing with line items and payment tracking - **invoice_items** - Detailed invoice line items - **payments** - Transaction recording with multiple payment methods ### **Project Management Tables** - **projects** - Customer project management with status tracking - **subprojects** - Detailed project breakdown and task management ### **Bookkeeping Tables** - **chart_of_accounts** - Hierarchical account structure - **journal_entries** - Double-entry transaction recording - **account_transactions** - Detailed debit/credit tracking ### **Authentication Tables** - **users** - Secure user management with role-based access ## 🚀 **Getting Started** ### **Prerequisites** - PHP 7.4+ with MySQL/MariaDB extension - Node.js 14+ and npm - Modern web browser (Chrome, Firefox, Safari, Edge) - MySQL server or MariaDB ### **Quick Setup** #### **Option 1: Fresh Installation** 1. **Clone the repository:** ```bash git clone cd inventory ``` 2. **Database Setup:** ```bash # Create database and import complete schema mysql -u root -p < backend/migrate_complete.sql # Update database credentials nano backend/config/database.php ``` 3. **Backend Server:** ```bash cd backend php -S localhost:8080 ``` 4. **Frontend Setup:** ```bash cd frontend npm install npm run dev -- --host 0.0.0.0 --port 3000 ``` 5. **Access Application:** - Backend: `http://localhost:8080` (API) - Frontend: `http://localhost:3000` (Web Interface) #### **Option 2: Existing Database Upgrade** 1. **Backup existing database:** ```bash mysqldump -u root -p inventory_db > backup.sql ``` 2. **Run migration script:** ```bash mysql -u root -p inventory_db < backend/migrate_complete.sql ``` 3. **Restart services:** ```bash # Restart PHP server if running sudo systemctl restart apache2 # or sudo systemctl restart nginx ``` ## 🔧 **Configuration** ### **Database Configuration** Update `backend/config/database.php` with your database credentials: ```php host};dbname={$this->db_name}", $this->username, $this->password ); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); return $conn; } catch(PDOException $exception) { echo "Connection error: " . $exception->getMessage(); return null; } } } ?> ``` ### **Environment Variables (Recommended)** Create `.env` file for sensitive configuration: ```env DB_HOST=localhost DB_NAME=inventory_db DB_USER=root DB_PASSWORD=your_password ``` ### **Frontend Configuration** Update `frontend/src/main.js` if needed for different API endpoints: ```javascript axios.defaults.baseURL = 'http://localhost:8000/api'; ``` ## 📚 **API Documentation** ### **Authentication Endpoints** - **POST** `/api/auth.php` - Login, Register, Logout ```json { "action": "login|register|logout", "username": "string", "password": "string", "email": "string", "first_name": "string", "last_name": "string" } ``` - **GET** `/api/auth.php?action=status` - Check authentication status ### **Item Management** - **GET** `/api/items.php` - List all items - **GET** `/api/items.php?id={id}` - Get single item - **POST** `/api/items.php` - Create new item - **PUT** `/api/items.php` - Update existing item - **DELETE** `/api/items.php?id={id}` - Delete item ### **Client Management** - **GET** `/api/clients.php` - List all clients - **GET** `/api/clients.php?id={id}` - Get single client - **GET** `/api/clients.php?search={term}` - Search clients - **POST** `/api/clients.php` - Create new client - **PUT** `/api/clients.php` - Update existing client - **DELETE** `/api/clients.php?id={id}` - Delete client ### **Contact Persons** - **GET** `/api/contact_persons.php?client_id={id}` - Get contact persons for client - **GET** `/api/contact_persons.php?id={id}` - Get single contact person - **POST** `/api/contact_persons.php` - Create new contact person - **PUT** `/api/contact_persons.php` - Update existing contact person - **DELETE** `/api/contact_persons.php?id={id}` - Delete contact person ### **Rental Prices** - **GET** `/api/rental_prices.php?item_id={id}` - Get rental prices for item - **GET** `/api/rental_prices.php?id={id}` - Get single rental price - **POST** `/api/rental_prices.php` - Create new rental price - **PUT** `/api/rental_prices.php` - Update existing rental price - **DELETE** `/api/rental_prices.php?id={id}` - Delete rental price ### **Document Attachments** - **GET** `/api/attachments.php?item_id={id}` - Get attachments for item - **GET** `/api/attachments.php?id={id}` - Get single attachment - **POST** `/api/attachments.php` - Upload attachment file - **DELETE** `/api/attachments.php?id={id}` - Delete attachment ### **File Upload** - **POST** `/api/upload.php` - Upload picture files - Form: `multipart/form-data` - Max size: 5MB ### **Project Management** - **GET** `/api/projects.php` - List all projects - **GET** `/api/projects.php?id={id}` - Get single project - **GET** `/api/projects.php?customer_id={id}` - Get projects for customer - **POST** `/api/projects.php` - Create new project - **PUT** `/api/projects.php` - Update existing project - **DELETE** `/api/projects.php?id={id}` - Delete project ### **Subproject Management** - **GET** `/api/subprojects.php?project_id={id}` - Get subprojects for project - **GET** `/api/subprojects.php?id={id}` - Get single subproject - **POST** `/api/subprojects.php` - Create new subproject - **PUT** `/api/subprojects.php` - Update existing subproject - **DELETE** `/api/subprojects.php?id={id}` - Delete subproject ### **Financial Management** - **GET** `/api/invoices.php` - List all invoices - **GET** `/api/invoices.php?id={id}` - Get single invoice with items and payments - **POST** `/api/invoices.php` - Create new invoice - **PUT** `/api/invoices.php` - Update existing invoice - **DELETE** `/api/invoices.php?id={id}` - Delete invoice ### **Bookkeeping** - **GET** `/api/chart_of_accounts.php` - List chart of accounts - **GET** `/api/chart_of_accounts.php?id={id}` - Get single account - **POST** `/api/chart_of_accounts.php` - Create new account - **PUT** `/api/chart_of_accounts.php` - Update existing account - **DELETE** `/api/chart_of_accounts.php?id={id}` - Delete account - **GET** `/api/journal_entries.php` - List journal entries - **GET** `/api/journal_entries.php?id={id}` - Get single journal entry with transactions - **POST** `/api/journal_entries.php` - Create new journal entry with transactions - **PUT** `/api/journal_entries.php` - Update existing journal entry - **DELETE** `/api/journal_entries.php?id={id}` - Delete journal entry - **GET** `/api/account_transactions.php?journal_entry_id={id}` - Get transactions for journal entry - **GET** `/api/account_transactions.php?id={id}` - Get single transaction - **POST** `/api/account_transactions.php` - Create new transaction - **PUT** `/api/account_transactions.php` - Update existing transaction - **DELETE** `/api/account_transactions.php?id={id}` - Delete transaction ## 🎯 **Usage Examples** ### **Authentication** ```javascript // Login const loginResponse = await axios.post('/api/auth.php', { action: 'login', username: 'admin', password: 'password123' }); // Register const registerResponse = await axios.post('/api/auth.php', { action: 'register', username: 'newuser', email: 'user@example.com', password: 'password123', first_name: 'John', last_name: 'Doe' }); // Check authentication status const authStatus = await axios.get('/api/auth.php?action=status'); ``` ### **Item Management** ```javascript // Get all items const items = await axios.get('/api/items.php'); // Create new item with picture const formData = new FormData(); formData.append('name', 'Laptop'); formData.append('description', 'High-performance laptop'); formData.append('quantity', 10); formData.append('price', 1299.99); formData.append('serial_number', 'LP001'); formData.append('picture', fileInput.files[0]); // File upload const newItem = await axios.post('/api/items.php', formData, { headers: { 'Content-Type': 'multipart/form-data' } }); ``` ### **Client Management** ```javascript // Create new client with y-tunnus const newClient = await axios.post('/api/clients.php', { y_tunnus: '1234567-8', company_name: 'Tech Corp', first_name: 'Jane', last_name: 'Smith', email: 'jane@techcorp.com', hour_price: 150.00, address: '123 Business St', city: 'Helsinki', country: 'Finland' }); // Add contact person const newContact = await axios.post('/api/contact_persons.php', { client_id: 1, first_name: 'John', last_name: 'Doe', email: 'john.doe@techcorp.com', position: 'Project Manager', is_primary: true }); ``` ### **Project Management** ```javascript // Create new project const newProject = await axios.post('/api/projects.php', { customer_id: 1, project_name: 'Website Redesign', description: 'Complete website overhaul project', status: 'planning', start_date: '2024-01-15', end_date: '2024-03-15', budget: 50000.00 }); // Add subproject const newSubproject = await axios.post('/api/subprojects.php', { project_id: 1, subproject_name: 'Frontend Development', description: 'Create responsive frontend design', status: 'in_progress', budget: 15000.00 }); ``` ### **Financial Management** ```javascript // Create invoice with line items const newInvoice = await axios.post('/api/invoices.php', { client_id: 1, invoice_number: 'INV-2024-001', issue_date: '2024-01-15', due_date: '2024-02-15', status: 'sent', subtotal: 10000.00, tax_amount: 2400.00, total_amount: 12400.00, transactions: [ { account_id: 1, // Revenue account debit_amount: 0, credit_amount: 12400.00, description: 'Website redesign services' }, { account_id: 2, // Bank account debit_amount: 12400.00, credit_amount: 0, description: 'Payment received' } ] }); ``` ### **Bookkeeping** ```javascript // Create journal entry with double-entry const newJournalEntry = await axios.post('/api/journal_entries.php', { entry_number: 'JE-2024-001', entry_date: '2024-01-15', description: 'Monthly revenue entry', reference_number: 'REF-001', transactions: [ { account_id: 1, // Revenue account debit_amount: 15000.00, credit_amount: 0, description: 'Service revenue' }, { account_id: 2, // Bank account debit_amount: 0, credit_amount: 15000.00, description: 'Bank deposit' } ] }); ``` ## 🔒 **Security Considerations** ### **Authentication Security** - Password hashing using PHP's `password_hash()` function - Session-based authentication with secure session management - SQL injection prevention with prepared statements - Input sanitization with `htmlspecialchars()` - CORS headers for cross-origin requests ### **API Security** - Request validation and error handling - Role-based access control (Admin, Manager, User) - Secure file upload with file type and size validation - Database transaction integrity with foreign key constraints ## 🎨 **Frontend Features** ### **User Interface** - **Responsive Design** - Mobile-friendly layout - **Real-time Updates** - Live data synchronization - **Modal Dialogs** - User-friendly forms and confirmations - **Search Functionality** - Global search across all entities - **Status Indicators** - Visual badges and progress bars - **Tabbed Navigation** - Organized interface sections ### **Interactive Elements** - **Drag & Drop** - File upload and organization - **Auto-complete** - Smart form suggestions - **Date Pickers** - Calendar-based date selection - **Rich Text Editors** - Enhanced text input areas ## 📊 **Data Management** ### **Import/Export** - CSV export functionality for reports - Data backup and restore capabilities - Bulk operations for efficiency ### **Reporting** - Financial reports with charts and graphs - Inventory reports with stock levels and values - Project progress reports with timelines - Customer activity reports with engagement metrics ## 🚀 **Deployment** ### **Production Setup** 1. **Environment Configuration** ```bash export NODE_ENV=production export DB_HOST=your-production-host ``` 2. **Web Server Configuration** - Apache with mod_rewrite for clean URLs - Nginx with PHP-FPM for performance - SSL/TLS certificates for HTTPS 3. **Database Optimization** - Enable query caching - Configure connection pooling - Set up read replicas for scaling ### **Monitoring** - Application performance monitoring - Database query performance tracking - Error logging and alerting - User activity analytics ## 📄 **License** This project is licensed under the MIT License - feel free to use, modify, and distribute according to your needs. --- **Last Updated:** April 2026 **Version:** 2.0.0 **Compatible with:** PHP 7.4+, MySQL 5.7+, Node.js 14+, Vue 3 ## 🗂 **Project Structure** ``` inventory/ ├── backend/ │ ├── config/ │ │ └── database.php │ ├── models/ │ │ ├── Item.php │ │ ├── RentalPrice.php │ │ ├── Attachment.php │ │ ├── Client.php │ │ ├── ContactPerson.php │ │ ├── Project.php │ │ ├── Subproject.php │ │ ├── ChartOfAccounts.php │ │ ├── JournalEntry.php │ │ ├── AccountTransaction.php │ │ └── User.php │ ├── api/ │ │ ├── items.php │ │ ├── rental_prices.php │ │ ├── attachments.php │ │ ├── clients.php │ │ ├── contact_persons.php │ │ ├── projects.php │ │ ├── subprojects.php │ │ ├── invoices.php │ │ ├── chart_of_accounts.php │ │ ├── journal_entries.php │ │ ├── account_transactions.php │ │ ├── auth.php │ │ └── upload.php │ ├── migrate_complete.sql │ ├── migrate_y_tunnus.sql │ ├── migrate_new_tables.sql │ ├── migrate_clients.sql │ ├── migrate_projects.sql │ ├── migrate_bookkeeping.sql │ └── migrate_auth.sql ├── frontend/ │ ├── src/ │ │ ├── App.vue │ │ └── main.js │ ├── index.html │ ├── package.json │ └── vite.config.js └── README.md ``` ## 🎓 **Support & Maintenance** ### **Regular Updates** - Security patches and updates - Feature enhancements based on user feedback - Performance optimizations - Database maintenance and optimization ### **Backup Strategy** - Automated daily database backups - File system backups - Disaster recovery planning ### **Troubleshooting** - Common issues and solutions - Performance tuning guides - Security best practices - Debugging techniques ## 📄 **Migration Scripts** ### **Complete Migration** For new installations, use the complete migration script: ```bash mysql -u root -p < backend/migrate_complete.sql ``` ### **Individual Migrations** For upgrading existing installations: ```bash # Add y-tunnus and contact persons mysql -u root -p < backend/migrate_y_tunnus.sql # Add rental prices and attachments mysql -u root -p < backend/migrate_new_tables.sql # Add client management mysql -u root -p < backend/migrate_clients.sql # Add project management mysql -u root -p < backend/migrate_projects.sql - `postal_code` - Postal code (optional) - `country` - Country (optional) - `notes` - Additional notes (optional) - `created_at` - Creation timestamp - `updated_at` - Last update timestamp ### Contact Persons Table - `id` - Primary key - `client_id` - Foreign key to clients table - `first_name` - First name (required) - `last_name` - Last name (required) - `email` - Email address (optional) - `phone` - Phone number (optional) - `position` - Job position/title (optional) - `is_primary` - Primary contact flag (boolean) - `created_at` - Creation timestamp - `updated_at` - Last update timestamp ## File Upload ### Pictures - Uploaded to `backend/api/uploads/` directory - Supported formats: JPEG, PNG, GIF, WebP - Maximum file size: 5MB - Files are automatically renamed with unique IDs ### Attachments - Uploaded to `backend/api/attachments/` directory - Supported formats: PDF, DOC, DOCX, TXT, JPEG, PNG, GIF - Maximum file size: 10MB - Files are automatically renamed with unique IDs - Documents are categorized by type (receipt, warranty, other)