V4 - dailySalesDataCollection¶
This workflow collects and stores daily sales data for entrepreneurs, calculating profit margins by combining sales figures with various cost categories and retrieving fixed costs from a user database. It serves as a data collection endpoint that can be called by other workflows to maintain comprehensive business tracking records.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
How It Works¶
- Receives Input Data: The workflow is triggered by another workflow with daily business data including sales figures, costs, and metadata
- Calculates Profit: Automatically computes profit by subtracting all costs (stocking, transport, other, and daily fixed costs) from sales revenue
- Stores in Database: Inserts or updates the daily profit tracking record in PostgreSQL with upsert logic to handle duplicate entries
- Returns Key Metrics: Outputs the calculated profit, business date, and sales figures for use by calling workflows
Workflow Diagram¶
graph TD
A[When Executed by Another Workflow] --> B[Insert rows in a table]
B --> C[Edit Fields]
Trigger¶
Execute Workflow Trigger: This workflow is designed to be called by other workflows, not run independently. It expects the following input parameters:
date(string): Date of business activityphoneNumber(string): Entrepreneur's phone number identifiersales(number): Total sales revenue for the daystockingCost(number): Cost of inventory/stocktransportCost(number): Transportation expensesotherCost(number): Miscellaneous business costsMicro actions(string): Description of micro-actions takenisPractice?(boolean): Flag indicating if this is practice 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 with upsert logic |
| Set | Edit Fields | Formats output data with key metrics (profit, date, sales) |
External Services & Credentials Required¶
- PostgreSQL Database: Requires connection credentials for the database containing:
dailyProfitTrackingtable (main data storage)youthEntrepreneursRealtable (for retrieving daily fixed costs)
Environment Variables¶
No specific environment variables are configured in this workflow. Database connection details are managed through n8n's credential system.
Data Flow¶
Input Data: - Business date and entrepreneur phone number - Sales revenue and cost breakdown (stocking, transport, other) - Micro-actions description and practice flag
Processing: - Retrieves daily fixed costs from entrepreneur profile - Calculates profit: Sales - (Stocking + Transport + Other + Fixed Costs) - Handles data conflicts with upsert logic
Output Data:
- profit: Calculated daily profit
- dateOfBusiness: Business date
- sales: Total sales amount
Error Handling¶
The workflow is configured with an error workflow (ID: cuHEGQjAfvuGwIOD) that will handle any execution failures. The PostgreSQL operation uses upsert logic to gracefully handle duplicate entries by updating existing records instead of failing.
Known Limitations¶
- Phone numbers are trimmed of trailing commas, suggesting potential data quality issues in the source system
- Fixed costs default to 0 if not found in the entrepreneur database
- No validation of negative values or unrealistic cost ratios
Related Workflows¶
This workflow is designed to be called by other workflows in the system. The error handling references workflow ID cuHEGQjAfvuGwIOD for failure management.
Setup Instructions¶
- Import Workflow: Import the JSON into your n8n instance
- Configure PostgreSQL Credentials:
- Set up PostgreSQL connection in n8n credentials
- Ensure access to
dailyProfitTrackingandyouthEntrepreneursRealtables
- Database Schema: Verify the following table structure exists:
1 2 3
-- dailyProfitTracking table should have columns: -- phoneNumber, dateOfBusiness, sales, stockingCost, transportCost, -- otherCost, dailyFixedCost, profit, microActions, isPractice - Error Workflow: Ensure error workflow
cuHEGQjAfvuGwIODexists or update the reference - Test Integration: Call this workflow from another workflow with sample data to verify functionality
- Activate: Enable the workflow once testing is complete
The workflow uses execution order v1 and restricts calls to workflows from the same owner for security.