V4 - dailySalesDataCollection¶
This workflow collects and processes daily sales data from entrepreneurs, calculating profit margins and storing the information in a PostgreSQL database. It handles both real business data and practice entries, automatically computing profit by factoring in sales revenue against various costs including stocking, transport, and fixed daily expenses.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
This workflow appears to be designed for tracking entrepreneurial business performance on a daily basis. It serves entrepreneurs or business coaches who need to monitor daily sales metrics, costs, and profitability. The system supports both real business tracking and practice mode for training purposes.
How It Works¶
- Data Reception: The workflow receives daily business data including sales figures, various cost categories, and micro-actions taken
- Database Storage: All data is inserted into a PostgreSQL table called
dailyProfitTracking - Profit Calculation: The system automatically calculates profit by subtracting all costs (stocking, transport, other, and daily fixed costs) from sales revenue
- Fixed Cost Lookup: Daily fixed costs are retrieved from a separate
youthEntrepreneursRealtable based on the phone number - Data Formatting: Key metrics (profit, date, sales) are extracted and formatted for downstream use
- Conflict Resolution: If data for the same phone number and date already exists, it updates the existing record
Workflow Diagram¶
graph TD
A[When Executed by Another Workflow] --> B[Insert rows in a table]
B --> C[Edit Fields]
style A fill:#e1f5fe
style B fill:#f3e5f5
style C fill:#e8f5e8
Trigger¶
Execute Workflow Trigger: This workflow is designed to be called by other workflows, not triggered directly. It expects the following input parameters:
date- Business datephoneNumber- Entrepreneur's phone numbersales- Daily sales amount (number)stockingCost- Cost of inventory/stock (number)transportCost- Transportation expenses (number)otherCost- Miscellaneous costs (number)Micro actions- Actions taken during the dayisPractice?- Boolean flag for practice vs. real data
Nodes Used¶
| Node Type | Node Name | Purpose |
|---|---|---|
| Execute Workflow Trigger | When Executed by Another Workflow | Receives input data from calling workflows |
| PostgreSQL | Insert rows in a table | Stores daily sales data and calculates profit |
| Set | Edit Fields | Formats output data with key metrics |
External Services & Credentials Required¶
- PostgreSQL Database: Requires database credentials with read/write access to:
dailyProfitTrackingtable (main data storage)youthEntrepreneursRealtable (for fixed cost lookup)
Environment Variables¶
No specific environment variables are documented in this workflow. Database connection details are handled through n8n's credential system.
Data Flow¶
Input Data¶
1 2 3 4 5 6 7 8 9 10 | |
Output Data¶
1 2 3 4 5 | |
The profit is calculated as: Sales - Stocking Cost - Transport Cost - Other Cost - Daily Fixed Cost
Error Handling¶
The workflow includes an error workflow reference (cuHEGQjAfvuGwIOD) that will be triggered if any node fails during execution. The PostgreSQL node uses COALESCE to handle cases where daily fixed costs might not be found for a phone number, defaulting to 0.
Known Limitations¶
- Phone numbers are trimmed of trailing commas, suggesting potential data quality issues in the source
- The workflow assumes daily fixed costs are stored in a separate table and may not exist for all users
- No validation is performed on input data types or ranges
- The workflow only handles single-day entries, not batch processing
Related Workflows¶
This workflow is designed to be called by other workflows but no specific parent workflows are documented. The error workflow cuHEGQjAfvuGwIOD is referenced for error handling.
Setup Instructions¶
-
Import the Workflow: Import the JSON into your n8n instance
-
Configure PostgreSQL Credentials:
- Create PostgreSQL credentials in n8n
- Ensure access to both
dailyProfitTrackingandyouthEntrepreneursRealtables
-
Database Schema Requirements:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
-- Ensure these tables exist with appropriate columns CREATE TABLE IF NOT EXISTS "dailyProfitTracking" ( "phoneNumber" TEXT, "dateOfBusiness" DATE, "sales" NUMERIC, "stockingCost" NUMERIC, "transportCost" NUMERIC, "otherCost" NUMERIC, "dailyFixedCost" NUMERIC, "profit" NUMERIC, "microActions" TEXT, "isPractice" BOOLEAN, PRIMARY KEY ("phoneNumber", "dateOfBusiness") ); CREATE TABLE IF NOT EXISTS "youthEntrepreneursReal" ( "phoneNumber" TEXT PRIMARY KEY, "dailyFixedCost" NUMERIC ); -
Configure Error Handling: Set up the error workflow referenced in settings
-
Test the Workflow: Create a parent workflow that calls this one with sample data to verify functionality
-
Activate: Set the workflow to active status once testing is complete