Skip to content

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

  1. 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
  2. Calculates Profit: Automatically computes profit by subtracting all costs (stocking, transport, other) from total sales
  3. Stores in Database: Inserts or updates the daily profit tracking record in PostgreSQL, ensuring no duplicate entries for the same phone number and date
  4. 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 date
  • phoneNumber (string): User identifier
  • 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 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 dailyProfitTracking table
  • Database Schema: Must contain a dailyProfitTracking table 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
{
  "date": "2026-03-19",
  "phoneNumber": "+1234567890",
  "sales": 1000,
  "stockingCost": 600,
  "transportCost": 50,
  "otherCost": 25,
  "Micro actions": "Improved customer service",
  "isPractice?": false
}

Output

1
2
3
4
5
{
  "profit": 325,
  "dateOfBusiness": "2026-03-19",
  "sales": 1000
}

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

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

  1. Import Workflow: Import the workflow JSON into your n8n instance

  2. Configure Database Credentials:

    • Create a PostgreSQL credential named "kdpTestEnv"
    • Ensure connection to database with dailyProfitTracking table
  3. 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")
    );
    

  4. Test the Workflow: Use the "Execute Workflow" feature with sample data to verify database connectivity and data insertion

  5. Integration: Configure other workflows to call this workflow using the Execute Workflow node, passing the required input parameters

  6. Activate: Enable the workflow to accept calls from other workflows