Skip to content

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

  1. Receives Business Data: The workflow is triggered by another workflow that passes daily business metrics including sales, costs, and operational details
  2. Calculates Profit: Automatically computes daily profit by subtracting all costs (stocking, transport, other, and daily fixed costs) from sales revenue
  3. Stores Records: Inserts or updates the daily profit tracking record in the database, handling duplicate entries gracefully
  4. 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 dailyProfitTracking table for storing daily records
    • Must have read access to youthEntrepreneursReal table for retrieving daily fixed costs

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

This workflow is designed to be called by other workflows in the system. The caller policy is set to "workflowsFromSameOwner" for security.

Setup Instructions

  1. Import the Workflow: Import the JSON into your n8n instance
  2. Configure PostgreSQL Credentials:
    • Create a PostgreSQL credential named "Postgres account"
    • Ensure database access to dailyProfitTracking and youthEntrepreneursReal tables
  3. Database Schema: Ensure the following tables exist:
    • dailyProfitTracking: Main table for storing daily business records
    • youthEntrepreneursReal: Profile table containing daily fixed costs
  4. Error Workflow: Configure the error workflow (cuHEGQjAfvuGwIOD) if needed
  5. Test the Workflow: Use the pinned test data or call from another workflow with sample parameters
  6. 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.