mirror of
https://github.com/DRYTRIX/TimeTracker.git
synced 2026-05-24 07:10:21 -05:00
6.7 KiB
6.7 KiB
Project Costs Feature
Overview
The Project Costs feature allows you to track expenses beyond hourly work on projects. This includes costs like travel, materials, third-party services, equipment rentals, software licenses, and other project-related expenses.
Features
1. Cost Management
- Add Costs: Add project costs with description, category, amount, and date
- Edit Costs: Modify cost details (admins and cost creators only)
- Delete Costs: Remove costs that haven't been invoiced yet
- Categories: Organize costs by category (Travel, Materials, Services, Equipment, Software, Other)
- Billable Status: Mark costs as billable or non-billable to clients
- Multiple Currencies: Support for EUR, USD, GBP, CHF
2. Project View Integration
- Cost Summary: View total costs, billable costs, and total project value
- Recent Costs: See the 5 most recent costs in the project overview
- Statistics: Updated project statistics include cost information
- Quick Actions: Add, edit, and delete costs directly from the project page
3. Invoice Integration
- Automatic Inclusion: Include project costs when generating invoices
- Cost Tracking: Track which costs have been invoiced
- Uninvoiced Costs: View all uninvoiced billable costs for a project
- Invoice Items: Costs appear as separate line items on invoices
4. Reporting
- Project Reports: Reports now include project costs in calculations
- Cost Breakdown: View costs by category
- Total Project Value: Combination of billable hours and billable costs
- Date Filtering: Filter costs by date range
Database Schema
The project_costs table includes:
- id: Primary key
- project_id: Foreign key to projects table
- user_id: Foreign key to users table (who added the cost)
- description: Brief description of the cost
- category: Category (travel, materials, services, equipment, software, other)
- amount: Cost amount (Decimal)
- currency_code: Currency code (default: EUR)
- billable: Whether the cost is billable to client
- invoiced: Whether the cost has been invoiced
- invoice_id: Reference to invoice (if invoiced)
- cost_date: Date of the cost
- notes: Additional notes
- receipt_path: Path to uploaded receipt (future enhancement)
- created_at: Timestamp when cost was created
- updated_at: Timestamp when cost was last updated
Usage
Adding a Cost
- Navigate to a project page
- Scroll to the "Project Costs & Expenses" section
- Click "Add Cost"
- Fill in:
- Description (required)
- Category (required)
- Amount (required)
- Date (required)
- Currency (default: EUR)
- Notes (optional)
- Billable checkbox (default: checked)
- Click "Add Cost"
Viewing Costs
- Project Page: Shows the 5 most recent costs
- Statistics Card: Shows total costs and total project value
- Full List: Click "View All Costs" to see all costs for a project
Including Costs in Invoices
- Create or edit an invoice
- Click "Generate from Time Entries"
- Select the costs you want to include along with time entries
- Click "Generate Items"
- Costs will appear as line items in the invoice
- Invoiced costs are automatically marked to prevent double-billing
Project Statistics
The project view now shows:
- Total Hours: All tracked hours
- Billable Hours: Hours marked as billable
- Total Costs: Sum of all project costs
- Budget Used (Hours): Budget consumed by hourly work
- Total Project Value: Billable hours cost + billable costs
API Endpoints
Routes
GET /projects/<id>/costs- List all costs for a projectGET /projects/<id>/costs/add- Show add cost formPOST /projects/<id>/costs/add- Create a new costGET /projects/<id>/costs/<cost_id>/edit- Show edit cost formPOST /projects/<id>/costs/<cost_id>/edit- Update a costPOST /projects/<id>/costs/<cost_id>/delete- Delete a costGET /api/projects/<id>/costs- Get costs as JSON
Project Model Properties
project.total_costs- Total of all costsproject.total_billable_costs- Total of billable costsproject.total_project_value- Billable hours + billable costs
Migration
Database Migration
Using Alembic (recommended):
# The migration script is in migrations/versions/add_project_costs_table.py
alembic upgrade head
Using SQL directly:
psql -U timetracker -d timetracker -f migrations/add_project_costs.sql
Using Python script (Docker):
python docker/migrate-add-project-costs.py
Environment Variables
No new environment variables are required. The feature uses existing database connection settings.
Permissions
- All Users: Can add costs to projects they work on
- Cost Creators: Can edit and delete their own costs (if not invoiced)
- Admins: Can edit and delete any costs (if not invoiced)
- Invoiced Costs: Cannot be deleted to maintain invoice integrity
Future Enhancements
Potential future improvements:
- Receipt Uploads: Upload and store receipt images
- Cost Approval Workflow: Require approval for costs above threshold
- Cost Budgets: Set and track budgets specifically for costs
- Cost Analytics: Advanced analytics and visualizations for costs
- Recurring Costs: Support for recurring project costs
- Multi-currency Conversion: Automatic currency conversion
- Export Costs: Export costs to CSV/PDF
- Cost Templates: Create templates for common costs
Light Look and Feel
The UI maintains the TimeTracker application's light and clean design:
- Clean cards with subtle shadows
- Light color scheme with primary blue accents
- Clear typography and spacing
- Responsive design for mobile devices
- Intuitive icons and badges
- Smooth animations and transitions
Technical Notes
Models
ProjectCostmodel inapp/models/project_cost.py- Relationships with
Project,User, andInvoicemodels - Cascade deletion when parent project or user is deleted
Routes
- Cost management routes in
app/routes/projects.py - Invoice generation updated in
app/routes/invoices.py - Report calculations updated in
app/routes/reports.py
Templates
templates/projects/add_cost.html- Add cost formtemplates/projects/edit_cost.html- Edit cost formtemplates/projects/view.html- Updated with costs section
Support
For issues or questions about the Project Costs feature:
- Check the TimeTracker documentation
- Review the code in the models and routes files
- Check the migration scripts for database setup
- Contact your system administrator
Version History
- v1.0 (2024-01-01): Initial release
- Basic cost tracking
- Invoice integration
- Report integration
- CRUD operations