Skip to content

Repository files navigation

Sales Management System

A comprehensive Django-based sales and accounting management system with dual department support (Regular & Cash), thermal printing, and advanced reporting capabilities.

πŸ—οΈ Project Structure (ORGANIZED)

Sales_App_Unitary/
β”œβ”€β”€ πŸ“ sales_app/                    # Main sales application
β”œβ”€β”€ πŸ“ accounting_app/               # Accounting & financial reporting
β”œβ”€β”€ πŸ“ core/                        # Shared utilities & base templates
β”œβ”€β”€ πŸ“ sales_management_project/     # Django project settings
β”œβ”€β”€ πŸ“ scripts/                     # πŸ†• Utility scripts (ORGANIZED)
β”‚   β”œβ”€β”€ production/                 #     Production deployment scripts
β”‚   β”œβ”€β”€ data_import/               #     CSV import & data processing
β”‚   └── testing/                   #     Testing & debugging scripts
β”œβ”€β”€ πŸ“ docs/                        # πŸ†• All documentation & guides (ORGANIZED)
β”œβ”€β”€ πŸ“ data/                        # πŸ†• CSV files & data imports
β”œβ”€β”€ πŸ“ sql/                         # πŸ†• SQL scripts & RLS security policies
β”œβ”€β”€ πŸ“ tests/                       # Test files
β”œβ”€β”€ πŸ“ staticfiles/                 # Collected static files (production)
└── πŸ“ node_modules/                # Node.js dependencies

πŸ” CRITICAL: Security Setup Required

⚠️ IMPORTANT: This project now includes Row Level Security (RLS) to protect your database. You MUST complete the security setup:

# 1. Create user groups (Admin, Managers, Cashiers)
python manage.py setup_user_groups

# 2. Assign yourself to Admin group in Django Admin (/admin/)

# 3. Apply database security policies  
python manage.py enable_rls_security

See docs/SECURITY_FIX_WALKTHROUGH.md for complete instructions.

πŸš€ Key Features

πŸ” User Management & Permissions

  • Role-Based Access Control:
    • Admin: Full system access, product management, user management
    • Manager: Sales oversight, reporting, dashboard access, invoice management
    • Cashier: Sales entry and basic invoice operations
  • Secure Authentication: Custom login/logout with automatic role-based redirects
  • Group-Based Navigation: Dynamic menu items based on user permissions

πŸ“Š Sales Management

  • Advanced Sales Entry:

    • Multi-item invoice creation with dynamic row management
    • Real-time price calculation and total computation
    • Stock validation with live inventory checking
    • Customer information management
    • Discount and payment tracking
    • Local storage auto-save to prevent data loss
  • Smart Product Selection:

    • AJAX-powered product search with autocomplete
    • Stock level display during product selection
    • Automatic price population from product database
    • Stock deduction upon sale completion

πŸ“‹ Invoice Management

  • Comprehensive Invoice System:

    • Auto-generated unique invoice numbers
    • Detailed invoice views with item breakdowns
    • Invoice editing capabilities for managers
    • Balance tracking (paid/unpaid/overpaid)
    • Invoice deletion with automatic stock restoration
  • Print & Receipt System:

    • Auto-print functionality on sale completion
    • Professional receipt templates optimized for thermal printers
    • Standard A4 invoice printing for business records
    • Print-friendly layouts with proper formatting

οΏ½ Accounting & Financial Management

  • Comprehensive Financial Dashboard:

    • Monthly revenue and expense tracking
    • Real-time profit & loss calculations
    • Outstanding invoice monitoring
    • Financial KPI cards with visual indicators
    • Quick access to all accounting functions
  • Expense Management:

    • Detailed expense tracking with categories
    • Receipt file upload and storage
    • Vendor and payment method tracking
    • Recurring expense marking
    • Advanced filtering and search capabilities
    • Bulk expense operations
  • Financial Reporting:

    • Profit & Loss Reports: Monthly and annual P&L statements
    • Revenue Analysis: 12-month revenue trends with charts
    • Expense Breakdown: Category-wise expense analysis
    • Outstanding Invoices: Payment status tracking and aging reports
    • Tax Preparation: Automated tax calculations and reporting
  • Audit Trail & Compliance:

    • Complete audit log of all financial activities
    • User action tracking with timestamps
    • IP address logging for security
    • Comprehensive change history
    • Export capabilities for external auditing

πŸ“Š Advanced Search & Filtering

  • Multi-Parameter Search:
    • Customer name search (partial matching)
    • Invoice number search
    • Date range filtering
    • OR-based search logic for flexible results
  • Real-time Search Results:
    • Live filtering with visual feedback
    • Search criteria persistence
    • Results summary with statistics

πŸ“ˆ Manager Dashboard

  • Professional Interface:

    • Modern card-based layout with gradient backgrounds
    • Sales summary cards (Total Sales, Invoice Count, Averages)
    • Real-time statistics and KPI tracking
    • Responsive design for all screen sizes
  • Comprehensive Reporting:

    • Daily sales reports
    • Search result exports
    • Professional print layouts for business documentation
    • Date-specific report generation

πŸ–¨οΈ Advanced Print Functionality

  • Multiple Print Options:

    • Print Today: Current day's invoices in professional format
    • Print Search Results: Export filtered results to print
    • Print Specific Date: Historical date report generation
    • Individual Receipts: Thermal printer-optimized receipts
  • Professional Report Format:

    • Company header and branding
    • Detailed invoice breakdowns with items
    • Summary statistics and totals
    • Print-optimized A4 layouts
    • Auto-generated timestamps and user attribution

πŸ“¦ Inventory Management

  • Real-Time Stock Tracking:

    • Automatic stock deduction on sales
    • Stock restoration on invoice deletion
    • Low stock warnings during sales entry
    • Inventory level validation
  • Product Management (Admin):

    • Add, edit, delete products
    • Price management
    • Stock level tracking
    • Product search and organization

πŸ’Ύ Data Management

  • Auto-Save Technology:

    • Local storage backup during form entry
    • Form restoration on page reload
    • Data persistence across sessions
    • Loss prevention mechanisms
  • Audit Trail:

    • Administrative action logging
    • User activity tracking
    • Stock movement history
    • Invoice modification logs

🎨 User Interface Features

πŸŒ“ Modern Design

  • Tailwind CSS Framework: Clean, responsive, professional design
  • Dark Mode Support: System-responsive dark/light theme switching
  • Mobile Responsive: Optimized for desktop, tablet, and mobile devices
  • Intuitive Navigation: Role-based menu system with clear visual hierarchy

⚑ Enhanced User Experience

  • Real-Time Feedback: Visual indicators for form validation and user actions
  • Keyboard Shortcuts: Enter key support for quick form submission
  • Loading States: Progress indicators for better user experience
  • Error Handling: Comprehensive error messages and validation feedback

πŸ“± Technology Stack

Backend

  • Django 5.2: Modern Python web framework
  • SQLite/PostgreSQL: Flexible database options
  • Django Forms: Advanced form handling and validation
  • Custom Middleware: Security and session management

Frontend

  • Tailwind CSS: Utility-first CSS framework
  • JavaScript ES6+: Modern client-side functionality
  • AJAX: Asynchronous data loading and form submission
  • Local Storage API: Client-side data persistence

Printing & Reports

  • CSS Print Media: Professional print layouts
  • PDF-Ready Formatting: Business-standard report generation
  • Responsive Print Design: Optimized for various paper sizes

πŸ—οΈ Project Architecture

Application Structure

sales_management_project/
β”œβ”€β”€ πŸ“± sales_app/              # Core sales functionality
β”‚   β”œβ”€β”€ 🎨 templates/sales_app/
β”‚   β”‚   β”œβ”€β”€ sales_entry.html    # Advanced sales form with auto-save
β”‚   β”‚   β”œβ”€β”€ manager_dashboard.html # Professional dashboard interface
β”‚   β”‚   β”œβ”€β”€ receipt_print.html  # Thermal printer receipt template
β”‚   β”‚   β”œβ”€β”€ invoices_print.html # A4 business report template
β”‚   β”‚   └── invoice_detail.html # Detailed invoice view
β”‚   β”œβ”€β”€ 🎯 static/sales_app/    # CSS, JS, and assets
β”‚   β”‚   β”œβ”€β”€ css/               # Custom styling and print layouts
β”‚   β”‚   └── js/                # AJAX functionality and form handling
β”‚   β”œβ”€β”€ πŸ”§ models.py           # Database models (Invoice, Sale, Product)
β”‚   β”œβ”€β”€ 🎭 views.py            # Business logic and request handling
β”‚   β”œβ”€β”€ πŸ“ forms.py            # Advanced form definitions
β”‚   └── πŸ”— urls.py             # URL routing and patterns
β”œβ”€β”€ 🏒 accounting_app/         # Financial management (Admin only)
β”‚   β”œβ”€β”€ 🎨 templates/accounting_app/
β”‚   β”‚   β”œβ”€β”€ dashboard.html      # Financial overview dashboard
β”‚   β”‚   β”œβ”€β”€ expense_list.html   # Expense management interface
β”‚   β”‚   β”œβ”€β”€ expense_form.html   # Expense creation/editing form
β”‚   β”‚   β”œβ”€β”€ profit_loss_report.html # P&L statement template
β”‚   β”‚   └── revenue_tracking.html   # Revenue analysis dashboard
β”‚   β”œβ”€β”€ πŸ”§ models.py           # Financial models (Expense, ProfitLoss, etc.)
β”‚   β”œβ”€β”€ 🎭 views.py            # Financial business logic
β”‚   └── πŸ”— urls.py             # Accounting URL patterns
β”œβ”€β”€ 🎨 core/                   # Shared components and utilities
β”‚   β”œβ”€β”€ 🧩 templatetags/       # Custom template filters and tags
β”‚   └── πŸ“‹ templates/core/     # Base templates and navigation
β”œβ”€β”€ βš™οΈ sales_management_project/ # Project configuration
β”œβ”€β”€ πŸ—„οΈ db.sqlite3             # Database file
β”œβ”€β”€ πŸ“¦ requirements.txt        # Python dependencies
β”œβ”€β”€ 🎨 tailwind.config.js      # Tailwind CSS configuration
└── πŸ“– README.md              # This documentation

Database Models

  • Product: Inventory items with pricing and stock levels
  • Invoice: Main sales record with customer and payment info (enhanced with status tracking)
  • Sale: Individual line items within invoices
  • AdminLog: Audit trail for administrative actions
  • StockMovement: Inventory change tracking
  • ExpenseCategory: Categorization for business expenses
  • Expense: Detailed expense records with receipts and vendor info
  • ProfitLossSnapshot: Monthly financial performance snapshots
  • TaxSettings: Configurable tax rates and calculations
  • AccountingAuditLog: Comprehensive audit trail for financial operations

πŸš€ Installation & Setup

Prerequisites

  • Python 3.8+
  • Node.js 14+ (for Tailwind CSS)
  • Git

Quick Start

  1. Clone the Repository:

    git clone https://github.com/akyensamuel/Sales-App.git
    cd Sales-App/sales_management_project
  2. Create Virtual Environment:

    python -m venv virtual
    # On Windows:
    virtual\Scripts\activate
    # On macOS/Linux:
    source virtual/bin/activate
  3. Install Python Dependencies:

    pip install -r requirements.txt
  4. Install Node.js Dependencies:

    npm install
  5. Database Setup:

    python manage.py migrate
    python manage.py createsuperuser
  6. Create User Groups:

    python manage.py shell
    from django.contrib.auth.models import Group
    Group.objects.create(name='Admin')
    Group.objects.create(name='Managers') 
    Group.objects.create(name='Cashiers')
    exit()
  7. Run Development Server:

    python manage.py runserver
  8. Access the Application:

    • Open browser to http://127.0.0.1:8000/
    • Login with superuser credentials
    • Access Django admin at http://127.0.0.1:8000/admin/ to assign users to groups

πŸ‘₯ User Management

Setting Up User Roles:

  1. Access Django Admin: /admin/
  2. Create Users: Add users in the Users section
  3. Assign Groups: Add users to appropriate groups (Admin/Managers/Cashiers)
  4. Test Access: Login as different users to verify permissions

Role Capabilities:

Feature Admin Manager Cashier
Sales Entry βœ… βœ… βœ…
Manager Dashboard βœ… βœ… ❌
Invoice Editing βœ… βœ… ❌
Invoice Deletion βœ… βœ… ❌
Print Reports βœ… βœ… ❌
Product Management βœ… ❌ ❌
User Management βœ… ❌ ❌
Accounting Dashboard βœ… ❌ ❌
Expense Management βœ… ❌ ❌
Financial Reports βœ… ❌ ❌
P&L Analysis βœ… ❌ ❌
Revenue Tracking βœ… ❌ ❌
Audit Logs βœ… ❌ ❌
Accounting Dashboard βœ… ❌ ❌

πŸ–¨οΈ Print Setup & Configuration

Thermal Printer Setup:

  1. Configure receipt printer for 58mm or 80mm paper
  2. Set printer to auto-cut after printing
  3. Test with receipt_print template

A4 Business Reports:

  1. Use landscape orientation for better table layouts
  2. Enable background graphics for professional appearance
  3. Set margins to 0.5 inches for optimal content fit

πŸ”§ Configuration Options

Environment Variables:

Create a .env file in the project root:

SECRET_KEY=your-secret-key-here
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1
DATABASE_URL=sqlite:///db.sqlite3

Production Deployment:

  • Set DEBUG=False
  • Configure proper database (PostgreSQL recommended)
  • Set up static file serving with WhiteNoise
  • Use environment variables for sensitive settings
  • Enable SSL/HTTPS for security

🎯 Usage Guide

Making a Sale:

  1. Navigate to Sales Entry
  2. Enter customer information
  3. Add products using the search feature
  4. Verify stock availability
  5. Calculate totals and enter payment
  6. Choose "Save" or "Save and Print"

Managing Invoices:

  1. Access Manager Dashboard
  2. Use search filters to find specific invoices
  3. Click invoice rows for detailed views
  4. Edit or delete as needed
  5. Print reports for record-keeping

Generating Reports:

  1. Use date filters to select reporting period
  2. Apply customer or invoice filters if needed
  3. Click appropriate print button
  4. Review report in new tab before printing

Using the Accounting Module:

  1. Access Accounting Dashboard (Admin only)
  2. View financial overview and KPIs
  3. Add expenses with categories and receipts
  4. Generate P&L reports for any period
  5. Track revenue trends and payment status
  6. Monitor outstanding invoices

πŸ’° Accounting Module Guide

Financial Dashboard:

  • Overview Cards: Monthly revenue, expenses, profit, and outstanding amounts
  • Quick Actions: Direct access to expense creation and management
  • Recent Activity: Latest expenses and financial transactions
  • Navigation: Easy access to all accounting features

Expense Management:

  1. Adding Expenses:

    • Choose existing category or create new one
    • Enter amount, date, and description
    • Add vendor and payment method information
    • Include reference numbers and notes
    • Mark recurring expenses for tracking
  2. Expense Categories:

    • Office Supplies, Travel & Transport, Marketing
    • Utilities, Professional Services, Equipment
    • Rent & Facilities, Insurance, Training
    • Customizable categories for specific business needs
  3. Filtering & Search:

    • Filter by category, date range, payment method
    • Search descriptions, vendors, and notes
    • Export filtered results for analysis

Financial Reports:

  1. Profit & Loss Reports:

    • Monthly or annual P&L statements
    • Revenue vs. expense breakdowns
    • Profit margin calculations
    • Category-wise expense analysis
    • Printable professional format
  2. Revenue Analysis:

    • 12-month revenue trend charts
    • Payment status overview
    • Outstanding invoice tracking
    • Collection aging reports

Audit & Compliance:

  • Complete audit trail of all financial activities
  • User action logging with timestamps
  • Change history tracking
  • Export capabilities for external auditing
  • IP address logging for security

πŸ” Search Features Guide

The advanced search system supports multiple search strategies:

  • Customer Search: Partial name matching (case-insensitive)
  • Invoice Search: Partial invoice number matching
  • Date Filtering: Single date or date range selection
  • Combined Search: Multiple criteria with OR logic
  • Quick Filters: Today's sales, specific date ranges

πŸ“Š Reporting Features

Available Reports:

  • Daily Sales Report: All invoices for a specific date
  • Search Results Report: Filtered invoice data
  • Customer Reports: Sales by customer (via search)
  • Period Reports: Date range analysis

Report Contents:

  • Invoice summary with totals
  • Detailed item breakdowns
  • Payment status indicators
  • Customer information
  • Sales representative tracking
  • Generation timestamps

πŸ› οΈ Troubleshooting

Common Issues:

  1. Print not working: Check popup blockers and printer connections
  2. Search not returning results: Verify date formats and search criteria
  3. Stock validation errors: Check product inventory levels
  4. Permission denied: Verify user group assignments
  5. Auto-save not working: Check browser local storage settings

Performance Tips:

  • Regular database cleanup of old invoices
  • Optimize large product catalogs with pagination
  • Use date filters for large datasets
  • Clear browser cache if experiencing loading issues

🀝 Contributing

Development Workflow:

  1. Fork the repository
  2. Create feature branch: git checkout -b feature-name
  3. Make changes and test thoroughly
  4. Commit with descriptive messages
  5. Push and create pull request

Code Standards:

  • Follow Django best practices
  • Use Tailwind CSS for styling
  • Write descriptive comments
  • Test all user roles and permissions
  • Ensure responsive design compatibility

πŸ“ License

MIT License - see LICENSE file for details

πŸš€ Future Enhancements

Sales & Inventory:

  • PDF export functionality
  • Email invoice delivery
  • Advanced inventory management
  • Barcode scanning integration
  • Multi-location support

Accounting & Finance:

  • Automated tax calculations and filing
  • Bank integration for transaction import
  • Advanced financial forecasting
  • Budget planning and variance analysis
  • Integration with accounting software (QuickBooks, Xero)
  • Automated recurring expense handling
  • Advanced financial dashboards with charts
  • Cash flow analysis and projections

System & Integration:

  • Customer relationship management
  • API development for integrations
  • Advanced analytics and dashboards
  • Multi-currency support
  • Cloud deployment options

Version: 2.0.0
Last Updated: August 2025
Maintainer: Akyen Samuel Status: Production Ready

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages