Skip to content

πŸ‡¬πŸ‡§ Autonomous PHP automation engine for invoicing and revenue tracking (CLI-based) πŸ‡«πŸ‡· Moteur d’automatisation PHP autonome pour la facturation et le suivi des recettes (CLI)

License

Notifications You must be signed in to change notification settings

Palks-Studio/automation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Palks Studio

πŸ‡¬πŸ‡§ English | πŸ‡«πŸ‡· FranΓ§ais

Automation System – Invoicing & Revenue Tracking

This repository contains an invoice and revenue automation system designed to operate:

  • without a CMS
  • without external SaaS services
  • without a database
  • without any exposed web interface

The entire system relies on PHP scripts executed via cron jobs, with a deliberately simple, readable, and auditable architecture.

The system provides:

  • automatic PDF invoice generation (FR / EN)
  • automatic invoice delivery by email
  • per-client revenue tracking (JSON)
  • revenue export to CSV (accounting-ready)
  • reliable yearly invoice numbering

It is not a certified accounting software and does not replace:

  • a certified accountant
  • a regulated accounting software
  • nor any legal tax or reporting obligations

The data produced by this system is intended for internal and operational use only.


What this repository is not

This repository does not provide:

  • a user interface
  • a ready-to-use SaaS product
  • a certified invoicing system
  • an automated payment processing system

It is a documented technical architecture,
designed to illustrate a robust and autonomous automation approach.


Core principles

  • One client = one configuration file
  • No sensitive data exposed on the web
  • No dependency on third-party invoicing services
  • Full traceability (logs, invoices, revenues)
  • CLI-only execution (no browser access)

This system is designed to be:

  • robust
  • predictable
  • maintainable over time
  • understandable without advanced knowledge

Project structure

automation/
β”‚
β”œβ”€β”€ engine/
β”‚   β”œβ”€β”€ run.php                     β†’ Moteur principal d’automatisation (cron / CLI) (FR)
β”‚   β”‚                               β†’ Main automation engine (cron / CLI) (EN)
β”‚   β”‚ 
β”‚   β”œβ”€β”€ export_accounting_year.php  β†’ Export annuel des recettes (FR)
β”‚   β”‚                               β†’ Annual revenue export (EN)
β”‚   β”‚
β”‚   β”œβ”€β”€ billing_rules.php           β†’ RΓ¨gles de facturation et de tarification dynamique (FR)
β”‚   β”‚                               β†’ Billing rules and dynamic pricing logic (EN)
β”‚   β”‚
β”‚   β”œβ”€β”€ run_batch.php               β†’ Moteur d’automatisation BATCH pour la facturation clients (FR)
β”‚   β”‚                               β†’ Batch automation engine for client invoicing (EN)
β”‚   β”‚
β”‚   β”œβ”€β”€ vendor/                     β†’ DΓ©pendances PHP (ex: DomPDF) (FR)
β”‚   β”‚                               β†’ PHP dependencies (e.g. DomPDF) (EN)
β”‚   β”‚
β”‚   β”œβ”€β”€ alerts                      β†’ Gestion des alertes et notifications d’exΓ©cution (FR)
β”‚   β”‚                               β†’ Execution alerts and notifications handling (EN)
β”‚   β”‚
β”‚   β”œβ”€β”€ import_cvs.php              β†’ Import et validation des fichiers CSV clients (FR)
β”‚   β”‚                               β†’ Client CSV import and validation handler (EN)
β”‚   β”‚
β”‚   β”œβ”€β”€ mailer.php                  β†’ Envoi des emails avec facture en piΓ¨ce jointe (FR)
β”‚   β”‚                               β†’ Email sender with invoice attachment (EN)
β”‚   └── templates/
β”‚       β”œβ”€β”€ invoice.html.php        β†’ Template PDF de facture (bilingue FR / EN) (FR)
β”‚       β”‚                           β†’ Invoice PDF template (bilingual FR / EN) (EN)
β”‚       β”‚
β”‚       └── invoices_batch.html.php β†’ Facture CLIENTS (batch) (FR)
β”‚                                   β†’ Client Invoices (Batch) (EN)
β”œβ”€β”€ clients/
β”‚   └── client_xxx.php              β†’ Fiche client (seul fichier Γ  modifier par client) (FR)
β”‚                                   β†’ Client configuration file (only file to edit per client) (EN)
β”œβ”€β”€ batch_clients/
β”‚   └── client_xxx.php              β†’ Configuration batch d’un client final (facturation mensuelle) (FR)
β”‚                                   β†’ Batch configuration for an end client (monthly invoicing) (EN)
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ logs/
β”‚   β”‚   └── xxx.log                 β†’ Logs d’exΓ©cution par client (FR)
β”‚   β”‚                               β†’ Execution logs per client (EN)
β”‚   β”œβ”€β”€ archive_batch/
β”‚   β”‚   └── xxx.csv                 β†’ CSV client archivΓ© (FR)
β”‚   β”‚                               β†’ Archived client CSV (EN)
β”‚   β”œβ”€β”€ usage/
β”‚   β”‚   └── xxx.json                β†’ Suivi d’usage mensuel par client (FR)
β”‚   β”‚                               β†’ Monthly client usage tracking (EN)
β”‚   β”œβ”€β”€ revenues/
β”‚   β”‚   └── xxx.json                β†’ Recettes cumulΓ©es (source comptable interne) (FR)
β”‚   β”‚                               β†’ Cumulative revenues (internal accounting source) (EN)
β”‚   β”œβ”€β”€ payments/
β”‚   β”‚   └── xxx.json                β†’ Paiements reΓ§us du client (virements, montants rΓ©ellement encaissΓ©s) (FR)
β”‚   β”‚                               β†’ Payments received from the client (bank transfers, actually received amounts) (EN)
β”‚   β”œβ”€β”€ balance/
β”‚   β”‚   └── xxx.json                β†’ Solde comptable du client (facturΓ© vs payΓ©, statut payΓ© / impayΓ©) (FR)
β”‚   β”‚                               β†’ Client accounting balance (invoiced vs paid, paid / unpaid status) (EN)
β”‚   β”œβ”€β”€ invoices/
β”‚   β”‚   └── client/                 β†’ Factures de l’activitΓ© principale (facturation directe, usage interne) (FR)
β”‚   β”‚                               β†’ Invoices from the main activity (direct invoicing, internal use) (EN)
β”‚   β”œβ”€β”€ invoices_batch/
β”‚   β”‚   └── client/                 β†’ Factures gΓ©nΓ©rΓ©es dans le cadre du service batch (clients finaux) (FR)
β”‚   β”‚                               β†’ Invoices generated as part of the batch service (end clients) (EN)
β”‚   β”œβ”€β”€ inbox_batch/
β”‚   β”‚   └── batch.csv               β†’ Fichier CSV fourni par le client (source de facturation batch) (FR)
β”‚   β”‚                               β†’ Client-provided CSV file (batch invoicing source) (EN)
β”‚   β”œβ”€β”€ counters/
β”‚   β”‚   └── xxx.json                β†’ Compteur annuel de factures par client (facturation directe) (FR)
β”‚   β”‚                               β†’ Annual invoice counter per client (direct invoicing) (EN)
β”‚   └── counters_batch/
β”‚       └── xxx.json                β†’ Compteur annuel de factures par client (facturation batch) (FR)
β”‚                                   β†’ Annual invoice counter per client (batch invoicing) (EN)
β”œβ”€β”€ docs/
β”‚       └── format_csv.md           β†’ SpΓ©cification officielle du format CSV attendu (FR)
β”‚                                   β†’ Official specification of the expected CSV format (EN)
β”œβ”€β”€ tools/
β”‚   β”œβ”€β”€ update_balances.php         β†’ Met Γ  jour les soldes clients Γ  partir des recettes et des paiements (FR)
β”‚   β”‚                               β†’ Updates client balances based on revenues and payments (EN)
β”‚   β”‚
β”‚   β”œβ”€β”€ purge_log.php               β†’ Script de nettoyage (FR)
β”‚   β”‚                               β†’ Cleanup Script (EN)
β”‚   β”‚
β”‚   └── export_revenues_csv.php     β†’ Script PHP d’export des recettes vers un fichier CSV (comptabilitΓ©) (FR)
β”‚                                   β†’ PHP script to export revenues to a CSV file (accounting) (EN)
β”œβ”€β”€ exports/
β”‚   └── export_revenues.csv         β†’ Fichier CSV contenant les recettes exportΓ©es (donnΓ©es tabulaires) (FR)
β”‚                                   β†’ CSV file containing exported revenues (tabular data) (EN)
β”œβ”€β”€ downloads/
β”‚   └── *.zip                       β†’ Archives ZIP mensuelles par client, contenant les factures PDF gΓ©nΓ©rΓ©es automatiquement (FR)
β”‚                                   β†’ Monthly ZIP archives per client, containing automatically generated PDF invoices (EN)
β”‚
β”œβ”€β”€ LICENSE.md                      β†’ Conditions d’utilisation et cadre lΓ©gal (FR)
β”‚                                   β†’ Terms of use and legal Framework (EN)
β”‚
└── README.md                       β†’ Documentation gΓ©nΓ©rale du systΓ¨me (FR)
                                    β†’ General system documentation (EN)

Global workflow

1. Client configuration

Each client is defined in a dedicated file:

clients/client_xxx.php

This file contains:

  • client identity
  • billing information
  • currency
  • language (FR / EN)
  • execution mode (test or live)

This is the only file to edit when adding or adjusting a client.


2. Automated execution (cron)

The main script is:

engine/run.php

It is executed via a cron job (daily, monthly, or scheduled as needed).

At each execution:

  • active clients are processed
  • an invoice is generated if applicable
  • the invoice is archived
  • revenues are updated
  • an email is sent to the client
  • execution logs are written

3. PDF invoicing

  • Invoices are generated as PDF files using DomPDF
  • The template supports both French and English
  • The language depends solely on the client configuration
  • Legal mentions (VAT, exemptions, etc.) are handled automatically

Invoices are archived per client in:

data/invoices/{client_id}/

4. Revenues (accounting source)

For each client, a JSON file is maintained:

data/revenues/{client_id}.json

It contains:

  • cumulative total
  • detailed invoice history
  • currency
  • invoice numbers and dates

This file is the internal accounting source of the system.


5. Accounting export (CSV)

An export tool is provided:

tools/export_revenues_csv.php

It generates CSV files usable by:

  • spreadsheets
  • accountants
  • accounting software

CSV files can be deleted and regenerated at any time
(with no impact on source data).


Real monthly cycle (invoicing & payments)

The system operates on a simple and predictable monthly cycle.

Before the 15th of the month

Clients make their payment (bank transfer).
No emails are automatically sent before this date.

On the 13th or 14th of the month (quick manual check)

Check received payments on the bank account.

Update the files in data/payments/:

  • one file per client
  • empty if no payment was received
  • filled if a payment was received

Accounting update

Run the following script from the command line:

php tools/update_balances.php

This script:

  • compares invoiced amounts vs paid amounts
  • computes the balance
  • automatically sets the status to paid or unpaid

The results are written to:

data/balance/{client_id}.json

On the 15th of the month

Invoices are automatically generated.

Emails are sent only if:

  • the client is active
  • options.auto_send = true
  • the script is executed on the 15th

No email is sent outside of this date.


Email sending rules

Invoice email delivery is strictly controlled.

All of the following conditions must be met for an email to be sent:

  • the client is active (active = true)
  • options.auto_send = true
  • the script is executed on the 15th of the month
  • execution is done via CLI (cron)

This rule is deliberately enforced in mailer.php
to prevent any accidental or out-of-cycle email delivery.


Batch invoicing (client service)

The system includes a batch invoicing engine designed for clients who provide their own billing data via CSV files.

How it works:

  • one CSV file per client
  • one CSV row = one PDF invoice
  • automatic invoice generation
  • monthly grouping into a ZIP archive
  • email delivery of the download link (optional)

Related script:

engine/run_batch.php

Important rules:

  • PDF invoices are always generated
  • sending (ZIP + email) depends only on options.auto_send
  • sending is restricted to the 15th of the month
  • one send per client per month (anti-duplicate safeguard)

The expected CSV format is documented in:

docs/format_csv.md

This document is intended for internal use
or for a supervised technical client.


Security

  • The engine refuses execution outside CLI
  • No web endpoint is exposed
  • Data is stored locally on the server
  • No direct browser access is possible

Maintenance & cleanup

  • logs/ and CSV export files can be safely cleaned
  • invoices/, revenues/, and counters/ must never be deleted
  • Invoice numbering is automatic and yearly

Project status

Status: Stable – production-ready.

This system is used in real conditions,
has no critical external dependencies,
and is designed to operate autonomously over the long term.


Β© Palks Studio β€” see LICENSE.md
https://palks-studio.com

About

πŸ‡¬πŸ‡§ Autonomous PHP automation engine for invoicing and revenue tracking (CLI-based) πŸ‡«πŸ‡· Moteur d’automatisation PHP autonome pour la facturation et le suivi des recettes (CLI)

Topics

Resources

License

Stars

Watchers

Forks