Daily Sales Data Collection¶
This workflow processes daily business data from entrepreneurs, calculating profits and storing comprehensive sales records in a PostgreSQL database. It handles sales figures, various cost categories, and micro-actions while automatically computing daily profits based on fixed costs from user profiles.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
How It Works¶
- Receives Business Data: The workflow is triggered by another workflow that passes daily business metrics including sales, costs, and operational details
- Calculates Profit: Automatically computes daily profit by subtracting all costs (stocking, transport, other, and daily fixed costs) from sales revenue
- Stores Records: Inserts or updates the daily profit tracking record in the database, handling duplicate entries gracefully
- Returns Summary: Outputs key metrics including 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 called by other workflows and expects the following input parameters:
- date (string): Business date
- phoneNumber (string): Entrepreneur's phone number
- sales (number): Total sales amount
- stockingCost (number): Cost of inventory/stock
- transportCost (number): Transportation expenses
- otherCost (number): Additional business costs
- Micro actions (string): Business improvement actions taken
- isPractice? (boolean): Whether this is practice data or real business data
Nodes Used¶
| Node Type | Node Name | Purpose |
|---|---|---|
| Execute Workflow Trigger | When Executed by Another Workflow | Receives input parameters from calling workflows |
| PostgreSQL | Insert rows in a table | Stores daily business data and calculates profit |
| Set | Edit Fields | Formats output data with key business metrics |
External Services & Credentials Required¶
- PostgreSQL Database: Requires "Postgres account" credentials to access the business data tables
- Must have access to
dailyProfitTrackingtable for storing daily records - Must have read access to
youthEntrepreneursRealtable for retrieving daily fixed costs
- Must have access to
Environment Variables¶
No environment variables are used in this workflow. All configuration is handled through n8n credentials and node parameters.
Data Flow¶
Input Data: - Business date and entrepreneur phone number - Sales revenue and cost breakdown (stocking, transport, other) - Micro-actions taken and practice/real data flag
Processing: - Retrieves daily fixed costs from entrepreneur profile - Calculates profit: Sales - (Stocking + Transport + Other + Daily Fixed Costs) - Handles data conflicts with upsert operation
Output Data:
- profit (number): Calculated daily profit
- dateOfBusiness (string): Business date
- sales (number): Total sales amount
Error Handling¶
The workflow includes an error workflow configuration (cuHEGQjAfvuGwIOD) that will handle any execution failures. The PostgreSQL operation uses an upsert pattern (INSERT ... ON CONFLICT DO UPDATE) to gracefully handle duplicate entries for the same phone number and date combination.
Known Limitations¶
- Phone numbers are cleaned by trimming trailing commas, which may not handle all formatting issues
- Daily fixed costs default to 0 if not found in the entrepreneur profile
- No validation of input data ranges or business logic constraints
Related Workflows¶
This workflow is designed to be called by other workflows in the system. The caller policy is set to "workflowsFromSameOwner" for security.
Setup Instructions¶
- Import the Workflow: Import the JSON into your n8n instance
- Configure PostgreSQL Credentials:
- Create a PostgreSQL credential named "Postgres account"
- Ensure database access to
dailyProfitTrackingandyouthEntrepreneursRealtables
- Database Schema: Ensure the following tables exist:
dailyProfitTracking: Main table for storing daily business recordsyouthEntrepreneursReal: Profile table containing daily fixed costs
- Error Workflow: Configure the error workflow (
cuHEGQjAfvuGwIOD) if needed - Test the Workflow: Use the pinned test data or call from another workflow with sample parameters
- Activate: Enable the workflow to start accepting calls from other workflows
The workflow is ready to use once the database connection is established and the required tables are in place.