Metadata-Version: 2.4
Name: ebia
Version: 0.2.0
Summary: EquipeBaie Invoice Automation
Author: AAH
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: pdfplumber
Requires-Dist: openpyxl
Provides-Extra: app
Requires-Dist: customtkinter>=5.2.0; extra == "app"
Requires-Dist: Pillow>=10.0.0; extra == "app"
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: pytest-cov>=5.0; extra == "dev"
Requires-Dist: pytest-mock>=3.12; extra == "dev"
Requires-Dist: ruff>=0.4; extra == "dev"
Requires-Dist: mypy>=1.10; extra == "dev"

# Equipe Baie — Invoice Automation

Automated invoicing pipeline that parses PDF invoices, enriches them with client accounting references, and generates Excel accounting exports — with a desktop UI for day-to-day operation.

---

## Project structure

```
EquipeBaie_Freelance-project/
├── src/
│   ├── ebia/                  # Core library (published to PyPI)
│   │   ├── parser.py          # PDF invoice parser
│   │   ├── xls_generator.py   # Excel (.xlsx) generator
│   │   └── cli.py             # CLI entry point
│   └── ebia_ui/               # Desktop application (not on PyPI)
│       ├── core/
│       │   ├── config_manager.py   # Persistent JSON config
│       │   ├── client_manager.py   # Client reference registry
│       │   ├── engine.py           # Orchestration layer (RunEngine)
│       │   └── manifest.py         # Processed-file tracking (SHA-256)
│       ├── ui/
│       │   ├── main_window.py
│       │   ├── components/    # Reusable widgets, sidebar
│       │   └── views/         # Run, Config, Client, About pages
│       ├── assets/            # logo.png, logo.ico
│       ├── logging_config.py  # App-wide logging setup
│       └── main.py            # Application entry point
├── tests/
│   ├── unit/                  # Pure-function tests, no I/O
│   ├── integration/           # Real PDF/Excel tests
│   └── e2e/                   # CLI subprocess tests
├── scripts/
│   └── build_exe.py           # PyInstaller Windows exe build
├── reports/                   # Generated .xlsx files (git-ignored)
│   └── processed.json         # Manifest of already-processed PDFs
└── pyproject.toml
```

---

## Components

### `ebia` — core library

Stateless, no side effects. Can be used standalone via CLI or imported directly.

- **`parser.py`** — extracts `Client`, `date`, `total_ttc` from a French-format PDF invoice using `pdfplumber`
- **`xls_generator.py`** — generates one `.xlsx` per month with one sheet per day; 3 accounting rows per invoice (411 / 44571 / 701)

### `ebia_ui` — desktop application

Built with `customtkinter`. Requires Python + display (not headless).

- **Run view** — manual trigger + recurring scheduler (daily / weekly / monthly)
- **Config view** — VAT rate, working folder path, document ID start
- **Client view** — client reference registry (accounting code ↔ client name)
- **Manifest** — SHA-256 based deduplication: already-processed PDFs are skipped on subsequent runs; only recorded after successful Excel generation

---

## Installation

### Library only (CLI usage)

```bash
pip install ebia
```

### Development (library + UI + tests)

```bash
git clone https://github.com/Alamajdoub9/EquipeBaie_Freelance-project.git
cd EquipeBaie_Freelance-project

python -m venv .venv
source .venv/bin/activate          # Linux / macOS
# .venv\Scripts\Activate.ps1       # Windows PowerShell

pip install -e ".[dev,app]"
```

---

## Running the application

```bash
ebia-ui
# or
python -m ebia_ui.main
```

Configuration and client data are stored in `~/.equipe_baie/`.
Generated Excel files are written to `reports/` at the project root.

---

## CLI usage (library only)

```bash
# Parse a single PDF and print extracted fields
ebia --path facture.pdf

# Generate Excel from a folder of PDFs
ebia --path ./invoices --out ./output/result.xlsx --start-piece 1 --start-document 1
```

---

## Running tests

```bash
# All tests
pytest

# By level
pytest -m unit
pytest -m integration
pytest -m e2e

# With coverage
pytest --cov=src/ebia --cov=src/ebia_ui/core --cov-report=term-missing
```

**Test matrix:**

| Suite | What it covers |
|---|---|
| `unit/test_parser.py` | PDF field extraction logic |
| `unit/test_generator.py` | Excel row generation and formatting |
| `unit/test_manifest.py` | SHA-256 manifest: load, save, deduplication |
| `unit/test_ebia_ui_core.py` | ConfigManager, ClientManager, RunEngine error paths |
| `integration/test_engine.py` | Full pipeline: PDFs → parse → enrich → xlsx |
| `integration/test_generator_xlsx.py` | Multi-month/multi-day workbook structure |
| `integration/test_parser_pdf.py` | Real PDF corpus parsing |
| `e2e/test_cli.py` | CLI invoked as subprocess |

---

## Delivery

The project has two independent deliverables:

### 1. `ebia` PyPI package

Published automatically on every release via `release.yml`:

```bash
# Trigger from GitHub Actions UI
# → tags the commit, builds the wheel, publishes to PyPI, creates GitHub Release
```

The `ebia_ui` package is **excluded** from the PyPI wheel (internal app, not a public library).

### 2. Windows desktop application (`.exe`)

Built via PyInstaller on a Windows runner:

```bash
python scripts/build_exe.py
# produces: dist/EquipeBaie.exe
```

The `.exe` is attached to the GitHub Release alongside the wheel. Users on Windows can run it with no Python installation required.

> **Linux / macOS**: run from source with `ebia-ui` (see above). The system tray / background scheduler feature is planned for a future release.

---

## Application data locations

| Data | Location |
|---|---|
| Config (VAT rate, folder path, etc.) | `~/.equipe_baie/config.json` |
| Client reference registry | `~/.equipe_baie/clients.json` |
| Processed-file manifest | `~/.equipe_baie/processed.json` |
| Application logs | `~/.equipe_baie/logs/ebia.log` (5 MB × 3 rotating backups) |
| Generated Excel files | `~/Documents/Equipe_Baie/Rapports/` (Windows & Linux) |

---

## Requirements

- Python >= 3.10
- Library deps: `pdfplumber`, `openpyxl`
- UI extra deps: `customtkinter >= 5.2.0`, `Pillow >= 10.0.0`
- Dev deps: `pytest`, `pytest-cov`, `pytest-mock`, `ruff`, `mypy`
