Daily Sales Data Collection - Francis¶
This workflow processes daily business data for young entrepreneurs, calculating profit margins by combining sales figures with various cost categories and storing the results for tracking business performance over time.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
Based on the workflow structure, this appears to serve young entrepreneurs who need to track their daily business performance by recording sales, costs, and calculating profits. The system maintains user configurations including fixed costs and durable stock items, and tracks business progress over consecutive days.
How It Works¶
- Receive Business Data: The workflow is triggered by another workflow that provides daily business metrics including sales, various costs, and operational details
- Fetch User Configuration: Retrieves the entrepreneur's business setup from the database, including daily fixed costs, durable stock items, and current business day
- Calculate Profit: Processes all cost categories (stocking, transport, other costs, fixed costs, and durable item depreciation) to determine net profit
- Store Daily Record: Saves or updates the daily business record in the profit tracking database
- Update User Status: Marks the user as having submitted data for the day and updates their business progress
- Return Results: Provides confirmation with the calculated profit amount
Workflow Diagram¶
graph TD
A[When Executed by Another Workflow] --> B[getUserConfig]
B --> C[calculateProfit]
C --> D[upsertDailyRecord]
D --> E[updateUserState]
E --> F[Edit Fields]
Trigger¶
Execute Workflow Trigger: This workflow is designed to be called by another workflow, receiving the following input parameters:
- date - Business date
- phoneNumber - User identifier
- sales - Daily sales amount (number)
- stockingCost - Cost of inventory (number)
- transportCost - Transportation expenses (number)
- otherCost - Miscellaneous expenses (number)
- Micro actions - Business activities description
- isPractice - Whether this is practice data (boolean)
Nodes Used¶
| Node | Type | Purpose |
|---|---|---|
| When Executed by Another Workflow | Execute Workflow Trigger | Receives input data from calling workflow |
| getUserConfig | PostgreSQL | Retrieves user's business configuration and settings |
| calculateProfit | Code (JavaScript) | Processes costs and calculates net profit |
| upsertDailyRecord | PostgreSQL | Saves daily business record to database |
| updateUserState | PostgreSQL | Updates user's data collection status and progress |
| Edit Fields | Set | Formats output response with profit information |
External Services & Credentials Required¶
- PostgreSQL Database: Requires "PostgresOnSupabase" credential for database operations
- Used for storing user configurations and daily profit records
- Tables:
youthEntrepreneursReal,dailyProfitTracking
Environment Variables¶
No environment variables are explicitly used in this workflow. All configuration is handled through database records and input parameters.
Data Flow¶
Input Data: - Business date and phone number for identification - Sales revenue amount - Cost breakdown: stocking, transport, and other expenses - Micro actions description - Practice mode flag
Processing: - Retrieves user's fixed costs and durable stock depreciation - Calculates total variable costs and daily depreciation - Computes net profit: Sales - (Variable Costs + Fixed Costs + Durable Depreciation)
Output Data: - Calculated profit amount - Confirmation message with date and profit figure - Updated user status in database
Error Handling¶
The workflow includes basic error handling in the JavaScript code: - JSON parsing errors for durable stock items are caught and default to empty array - Numeric conversions use fallback values (0) for missing or invalid data - Database operations use upsert patterns to handle duplicate entries
Known Limitations¶
- No explicit validation of input data ranges or business rules
- Relies on calling workflow to provide properly formatted data
- No rollback mechanism if partial database updates fail
- Practice mode data affects database state but doesn't isolate test data
Related Workflows¶
This workflow is designed to be called by other workflows in the system, likely including: - Data collection interfaces (web forms, chatbots, etc.) - Batch processing workflows for historical data - User onboarding workflows that might submit practice data
Setup Instructions¶
- Import Workflow: Import the JSON into your n8n instance
- Configure Database Credential:
- Create a PostgreSQL credential named "PostgresOnSupabase"
- Configure connection to your Supabase or PostgreSQL instance
- Database Schema: Ensure these tables exist:
youthEntrepreneursReal: User configuration table with columns forphoneNumber,dailyFixedCost,durableStockItems,currentDay,todayDataCollected,lastDataDate,consecutiveMissedDaysdailyProfitTracking: Daily records table with columns for all business metrics and calculated profit
- Test Execution: Create a test workflow that calls this one with sample data to verify database connectivity
- Activate: Enable the workflow once testing is complete
The workflow is currently inactive and may need activation after setup and testing.