# Manufacturing App

A comprehensive Django-based manufacturing management application with modern UI, user permissions, and database management capabilities.

## Features

### 🏭 Core Manufacturing
- **Simple Manufacturing Orders**: Input end product results without complex BOM requirements
- **Production Tracking**: Monitor daily, weekly, and monthly production metrics
- **Cost Management**: Track labor and overhead costs for manufacturing orders

### 📦 Inventory Management
- **Product Management**: Complete product catalog with categories, pricing, and stock levels
- **Stock Movements**: Track all inventory movements (in/out, adjustments, sales, purchases)
- **Low Stock Alerts**: Automatic notifications for products below minimum stock levels

### 🛒 Purchase Management
- **Supplier Management**: Comprehensive supplier database with ratings and contact information
- **Purchase Orders**: Create and track purchase orders with multiple items
- **Receipt Management**: Track received goods and update inventory automatically

### 💰 Sales Management
- **Customer Management**: Customer database with different types (retail, wholesale, corporate)
- **Sales Orders**: Create sales orders with discounts and shipping costs
- **Delivery Tracking**: Monitor order status and delivery progress

### 👥 User Management
- **Role-Based Access**: Four user types (Admin, Manager, Operator, Viewer)
- **Permission System**: Granular permissions for different modules
- **User Groups**: Custom permission groups for team management

### 📊 Dashboard & Reporting
- **Real-time Dashboard**: Live production, sales, and purchase statistics
- **Charts & Graphs**: Visual representation of key metrics using Chart.js
- **Profit/Loss Analysis**: Simple profit margin calculations
- **Inventory Turnover**: Track stock movement patterns

### 🗄️ Database Management
- **Backup & Restore**: Full database backup and restoration capabilities
- **Database Duplication**: Create copies for testing and development
- **SQLite Support**: Currently uses SQLite (easily switchable to PostgreSQL)

## Technology Stack

- **Backend**: Django 4.2.7
- **Database**: SQLite (PostgreSQL ready)
- **Frontend**: Bootstrap 5, Chart.js
- **Authentication**: Django's built-in auth with custom user model
- **Forms**: Django Crispy Forms with Bootstrap 5 styling

## Installation & Setup

### Prerequisites
- Python 3.8 or higher
- pip (Python package installer)

### 1. Clone the Repository
```bash
git clone <repository-url>
cd basic_manufacture_app
```

### 2. Create Virtual Environment
```bash
python -m venv venv

# On Windows
venv\Scripts\activate

# On macOS/Linux
source venv/bin/activate
```

### 3. Install Dependencies
```bash
pip install -r requirements.txt
```

### 4. Environment Configuration
Create a `.env` file in the project root:
```env
SECRET_KEY=your-secret-key-here
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1
```

### 5. Database Setup
```bash
# Create database tables
python manage.py makemigrations
python manage.py migrate

# Create superuser
python manage.py createsuperuser
```

### 6. Run the Application
```bash
python manage.py runserver
```

The application will be available at `http://127.0.0.1:8000/`

## User Types & Permissions

### 👑 Administrator
- Full access to all modules
- Database management capabilities
- User and group management
- System configuration

### 👨‍💼 Manager
- Manufacturing, inventory, purchase, and sales access
- User management (limited)
- Reporting and analytics
- Cannot access database management

### 🔧 Operator
- Manufacturing operations
- Inventory management
- Sales operations
- Basic reporting access

### 👁️ Viewer
- Read-only access to reports
- Dashboard viewing
- No modification capabilities

## Database Management

### Backup Database
1. Navigate to Database Management (Admin only)
2. Click "Create Backup"
3. Backup files are saved in the `backups/` folder with timestamps

### Restore Database
1. Select a backup file (.sqlite3 or .db)
2. Confirm the restoration
3. A safety backup is automatically created before restoration

### Duplicate Database
1. Create a copy for testing/development
2. Files are saved with "duplicate" prefix

## Switching to PostgreSQL

To switch from SQLite to PostgreSQL:

1. Install PostgreSQL adapter:
```bash
pip install psycopg2-binary
```

2. Update `settings.py`:
```python
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'your_db_name',
        'USER': 'your_db_user',
        'PASSWORD': 'your_db_password',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}
```

3. Run migrations:
```bash
python manage.py migrate
```

## Project Structure

```
basic_manufacture_app/
├── manufacture_app/          # Main Django project
│   ├── settings.py          # Project settings
│   ├── urls.py              # Main URL configuration
│   └── wsgi.py              # WSGI configuration
├── core/                     # Core app (dashboard, database management)
├── users/                    # User management app
├── inventory/                # Inventory management app
├── manufacture/              # Manufacturing app
├── purchase/                 # Purchase management app
├── sales/                    # Sales management app
├── templates/                # HTML templates
├── static/                   # Static files (CSS, JS, images)
├── requirements.txt          # Python dependencies
└── README.md                # This file
```

## Usage Examples

### Creating a Manufacturing Order
1. Navigate to Manufacturing → New Order
2. Select product and enter quantity
3. Add labor and overhead costs
4. Save the order (automatically updates inventory)

### Managing Inventory
1. Go to Inventory → Products
2. Add new products with categories and pricing
3. Set minimum and maximum stock levels
4. Monitor stock movements and alerts

### Processing Sales
1. Create sales order with customer details
2. Add products with quantities and prices
3. Apply discounts if applicable
4. Update order status as it progresses

## Contributing

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests if applicable
5. Submit a pull request

## License

This project is licensed under the MIT License - see the LICENSE file for details.

## Support

For support and questions:
- Create an issue in the repository
- Contact the development team
- Check the documentation

## Roadmap

- [ ] Advanced BOM (Bill of Materials) support
- [ ] Work order scheduling
- [ ] Quality control management
- [ ] Advanced reporting and analytics
- [ ] Mobile application
- [ ] API endpoints for external integrations
- [ ] Multi-warehouse support
- [ ] Advanced forecasting tools

---

**Note**: This is a basic manufacturing application designed for simplicity and ease of use. For complex manufacturing operations, consider additional features like BOM management, work order scheduling, and quality control systems.
