Daily Sales Data Collection (Testing)¶
This workflow collects and stores daily business performance data including sales, costs, and calculated profit margins. It serves as a data collection endpoint that can be called by other workflows to record business metrics in a centralized database.
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 that passes in daily business metrics including date, phone number, sales figures, various cost categories, micro actions, and a practice flag
- Calculates Profit: Automatically computes profit by subtracting all costs (stocking, transport, other) from total sales
- Stores in Database: Inserts or updates the daily profit tracking record in PostgreSQL, ensuring no duplicate entries for the same phone number and date
- Returns Summary: Formats and returns key metrics (profit, date, sales) for use by the calling workflow
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 triggered directly. It accepts the following input parameters:
date(string): Business datephoneNumber(string): User identifiersales(number): Total sales amountstockingCost(number): Cost of inventory/stocktransportCost(number): Transportation expensesotherCost(number): Additional business costsMicro actions(string): Business improvement actions takenisPractice?(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 workflow |
| PostgreSQL | Insert rows in a table | Stores business data in dailyProfitTracking table with upsert logic |
| Set | Edit Fields | Formats output data with key metrics |
External Services & Credentials Required¶
PostgreSQL Database¶
- Credential Name: kdpTestEnv
- Required Permissions: INSERT, UPDATE, SELECT on
dailyProfitTrackingtable - Database Schema: Must contain a
dailyProfitTrackingtable with columns for phoneNumber, dateOfBusiness, sales, costs, profit, microActions, and isPractice
Environment Variables¶
No environment variables are used in this workflow. All configuration is handled through n8n credentials.
Data Flow¶
Input¶
1 2 3 4 5 6 7 8 9 10 | |
Output¶
1 2 3 4 5 | |
Database Record Created¶
The workflow creates/updates a record in the dailyProfitTracking table with:
- Calculated profit (sales minus all costs)
- All input data properly typed and stored
- Conflict resolution for duplicate phone number + date combinations
Error Handling¶
This workflow does not implement explicit error handling. Failures will occur if: - Database connection fails - Required input parameters are missing or invalid - Database constraint violations occur - SQL execution errors happen
Known Limitations¶
- No input validation on the workflow level
- No error handling or retry logic
- Depends on external workflows for data input
- Limited to PostgreSQL database backend
Related Workflows¶
This workflow is designed to be called by other workflows that collect daily business data. No specific related workflows are identified in the current documentation.
Setup Instructions¶
-
Import Workflow: Import the workflow JSON into your n8n instance
-
Configure Database Credentials:
- Create a PostgreSQL credential named "kdpTestEnv"
- Ensure connection to database with
dailyProfitTrackingtable
-
Database Schema: Create the required table:
1 2 3 4 5 6 7 8 9 10 11 12
CREATE TABLE "dailyProfitTracking" ( "phoneNumber" TEXT, "dateOfBusiness" DATE, "sales" NUMERIC, "stockingCost" NUMERIC, "transportCost" NUMERIC, "otherCost" NUMERIC, "profit" NUMERIC, "microActions" TEXT, "isPractice" BOOLEAN, PRIMARY KEY ("phoneNumber", "dateOfBusiness") ); -
Test the Workflow: Use the "Execute Workflow" feature with sample data to verify database connectivity and data insertion
-
Integration: Configure other workflows to call this workflow using the Execute Workflow node, passing the required input parameters
-
Activate: Enable the workflow to accept calls from other workflows