Description: Extend the payroll items to support one-time performance bonuses separate from the recurring base salary. Bonuses should be included in the same transaction batch but identified separately in reports.
Acceptance Criteria:
- ✅ API supports adding one-time bonus items to a payroll run
- ✅ Audit logs and receipts distinguish between base and bonus
- ✅ Payroll engine correctly aggregates totals
The system already had a comprehensive bonus feature with:
- Database schema with
item_typefield ('base' or 'bonus') - Separate tracking of
total_base_amountandtotal_bonus_amount - API endpoints for adding single/batch bonus items
- Payroll processing engine that handles both types
- Audit logging infrastructure
Files Modified:
backend/src/services/payrollAuditService.tsbackend/src/controllers/payrollBonusController.tsbackend/src/workers/payrollWorker.ts
Changes:
- Added
itemTypeparameter to audit logging methods - Store
item_typein audit log metadata field - Log audit entries when bonus items are added via API
- Log audit entries during transaction processing with item_type
- Track bonus descriptions in metadata
Impact: Audit logs now explicitly distinguish between base salary and bonus payments in the metadata field, making it easy to filter and report on bonus-specific transactions.
Files Modified:
backend/src/services/exportService.tsbackend/src/controllers/exportController.tsbackend/src/services/payrollBonusService.ts
Changes:
- Updated PDF receipt to show "Performance Bonus Payment" vs "Base Salary Payment"
- Added visual indicator (🎉) for bonus payments
- Include bonus description/reason in receipts
- Created
getPayrollItemByTxHash()method to fetch item_type from database - Enrich transaction data with item_type before generating receipt
Impact: Receipts now clearly indicate whether a payment is a bonus or base salary, with bonus-specific formatting and descriptions.
Files Modified:
backend/src/services/exportService.ts
Changes:
- Excel exports now include:
- Separate columns for base/bonus counts and totals in summary sheet
- "Payment Type" column in transaction sheet
- "Description" column for bonus reasons
- CSV exports include:
- "paymentType" column (Base Salary / Bonus)
- "description" column
Impact: All export formats now distinguish between payment types, making it easy to analyze bonus distributions.
Files Created:
backend/src/__tests__/performanceBonusFeature.test.ts
Test Coverage:
- Creating payroll runs with base and bonus items
- Adding single and batch bonus items
- Filtering items by type
- Audit log metadata verification
- Total aggregation accuracy (base, bonus, and combined)
- Bonus history retrieval
Files Created:
backend/PERFORMANCE_BONUS_FEATURE.md- Complete feature documentationIMPLEMENTATION_SUMMARY.md- This file
-- payroll_runs table
total_base_amount DECIMAL(20, 7) DEFAULT 0
total_bonus_amount DECIMAL(20, 7) DEFAULT 0
total_amount DECIMAL(20, 7) DEFAULT 0
-- payroll_items table
item_type VARCHAR(20) NOT NULL CHECK (item_type IN ('base', 'bonus'))
description TEXT
-- payroll_audit_logs table
metadata JSONB DEFAULT '{}' -- Now includes item_typePOST /api/v1/payroll-bonus/items/bonus - Add single bonus
POST /api/v1/payroll-bonus/items/bonus/batch - Add batch bonuses
GET /api/v1/payroll-bonus/runs/{id}/items - Get items (filterable by type)
GET /api/v1/payroll-bonus/bonuses/history - Get bonus history
GET /api/v1/exports/receipt/{txHash}/pdf - Generate receipt (now enhanced)
-
Metadata-based Tracking: Instead of adding a new column to audit_logs, we use the existing JSONB metadata field to store item_type, maintaining backward compatibility.
-
Enrichment Pattern: Transaction data from SDS (Stellar Data Service) is enriched with database information (item_type, description) before generating receipts.
-
Automatic Totals: The
updatePayrollRunTotals()method automatically recalculates base, bonus, and total amounts whenever items are added or removed. -
Audit Trail: Every bonus-related action is logged with full context (actor, IP, user agent, item_type, description).
-
API Testing:
# Add a bonus item curl -X POST http://localhost:4000/api/v1/payroll-bonus/items/bonus \ -H "Content-Type: application/json" \ -d '{"payrollRunId": 1, "employeeId": 1, "amount": "500", "description": "Q1 Bonus"}'
-
Audit Log Verification:
SELECT action, metadata->>'item_type', metadata->>'description' FROM payroll_audit_logs WHERE action = 'item_added';
-
Receipt Generation:
# Generate receipt for a transaction curl http://localhost:4000/api/v1/exports/receipt/{txHash}/pdf -
Run Tests:
cd backend npm test -- performanceBonusFeature
- Single bonus:
POST /api/v1/payroll-bonus/items/bonus - Batch bonuses:
POST /api/v1/payroll-bonus/items/bonus/batch - Filter by type:
GET /api/v1/payroll-bonus/runs/{id}/items?itemType=bonus - Tests:
should add a single bonus item,should add multiple bonus items in batch
- Audit logs include
metadata.item_typefor all payroll actions - Receipts show "Performance Bonus Payment" vs "Base Salary Payment"
- Exports include payment type column
- Tests:
should log bonus item addition with item_type in metadata,should log transaction success with item_type
- Separate tracking:
total_base_amount,total_bonus_amount,total_amount - Automatic recalculation on item add/delete
- Tests:
should calculate correct totals for base and bonus separately,should maintain correct totals after deleting a bonus item
Modified (9 files):
backend/src/services/payrollAuditService.ts- Enhanced audit loggingbackend/src/services/exportService.ts- Updated receipt/export generationbackend/src/services/payrollBonusService.ts- Added getPayrollItemByTxHashbackend/src/controllers/payrollBonusController.ts- Added audit loggingbackend/src/controllers/exportController.ts- Enriched receiptsbackend/src/workers/payrollWorker.ts- Added audit logging during processingbackend/src/controllers/webhook.controller.ts- Fixed merge conflict
Created (3 files):
backend/src/__tests__/performanceBonusFeature.test.ts- Integration testsbackend/PERFORMANCE_BONUS_FEATURE.md- Feature documentationIMPLEMENTATION_SUMMARY.md- This summary
feat: enhance performance bonus feature with audit logs and receipt distinction
- Add item_type (base/bonus) to audit log metadata for all payroll actions
- Update PDF receipts to distinguish between base salary and performance bonuses
- Enhance Excel/CSV exports to include payment type and bonus descriptions
- Add audit logging to payroll worker for transaction success/failure with item_type
- Add audit logging to bonus item addition in controllers
- Create getPayrollItemByTxHash method to enrich receipts with item_type
- Add comprehensive integration tests for all acceptance criteria
- Create feature documentation
Acceptance Criteria Met:
✓ API supports adding one-time bonus items to a payroll run
✓ Audit logs and receipts distinguish between base and bonus
✓ Payroll engine correctly aggregates totals (already implemented)
- Deploy to staging environment
- Run integration tests against staging database
- Verify receipt generation with real transaction data
- Review audit logs for proper item_type tracking
- Update API documentation if needed
- Create PR for review