nystronsolar/electric-bill-extractor
Composer 安装命令:
composer require nystronsolar/electric-bill-extractor
包简介
Extract the data from an Electric Bill
README 文档
README
Logo made with Canva
Getting Started
First, instal the package with composer:
composer require nystronsolar/electric-bill-extractor
Next, extract the data from an electric bill:
<?php use NystronSolar\ElectricBillExtractor\ExtractorFactory; require_once __DIR__.'/vendor/autoload.php'; $bill = ExtractorFactory::extractFromFile('bill.pdf');
How the library works?
The Extractors
Each type of bill needs to have a custom extractor. Each extractor extends the Extractor Abstract Class, which when instantiating, you need to provide the parsed content of an bill. After it, you can extract its content by using the extract() method, that it will returns a bill object or false in case of error.
List of all Extractors
| Name | Class | Example |
|---|---|---|
| Extractor V2 RGE | NystronSolar\ElectricBillExtractor\Extractor\ExtractorV2RGE |
From Official RGE Website |
| Extractor V3 RGE | NystronSolar\ElectricBillExtractor\Extractor\ExtractorV3RGE |
From Official RGE Website |
The Extractor Factory
The Extractor Factory is a class that helps creating extractors
With the Extractor Factory, you can:
- Identify the extractor class from an string content or file path with the
identifyExtractorClassFromContent()oridentifyExtractorClassFromFile()methods - Instantiate the extractor class from an string content or file path with the
instantiateExtractorClassFromFile()andinstantiateExtractorClassFromFile()methods - Extract the bill from an string content or file path with the
extractFromFile()andextractFromFile()methods
<?php use NystronSolar\ElectricBillExtractor\ExtractorFactory; require_once __DIR__.'/vendor/autoload.php'; // Returns an class-string of an extractor that can be used or false ExtractorFactory::identifyExtractorClassFromFile('bill.pdf'); ExtractorFactory::identifyExtractorClassFromContent('An parsed bill content'); // Return an new extractor instance or false ExtractorFactory::instantiateExtractorFromFile('bill.pdf'); ExtractorFactory::instantiateExtractorFromContent('An parsed bill content'); // Extract an Bill - Return an bill object or false ExtractorFactory::extractFromFile('bill.pdf'); ExtractorFactory::extractFromContent('An parsed bill content');
Tests
The tests for the Electric Bill Extractor are pretty!
Content
To test an File Extractor library, we need to have many files to extract and check the results. And that's because, in the Electric Bill Extractor, under the tests/Content/bills/ folder, you can find many .txt files that represents many fake bills, following the pattern for each extractor.
And to compare the results by the extractor and the actual bills, you can find .json files in tests/Content/expected/ that when the tests run, it will compare the expected (json) with the actual bills (txt)
Why not use PDF files?
In most real-cases, projects will extract the data from an PDF file. In that approach, the Electric Bill Extractor Factory will parse the PDF file into text, using the https://github.com/smalot/pdfparser.
After the parsing, the library will use the text returned from the Parser and extract all the data for the bill.
But in tests, we can skip all the parsing. And that's because we use .txt instead of .pdf
The Test Case
Since the extractor have this "strange" way to assert the classes, we built the Extractor Test Case, which is a Custom PHPUnit Test Case. This test case have an assertByContentFolder method, which you need to provide the folder name and the extractor class.
Uploading a new Test Bill
The bills under tests/Content/bills are usually real bills, but with some values changed. If you found an error with your bill and wan't to upload it to the repository, it's extremely important to change some values, such as real name, CPF, installation code, etc, since this project is Open Source, so anyone can see the bills.
You can use the command composer upload-bill to help you adding a new bill, but you still have to remove all the secrets and fill the JSON expected file.
Here you can see all the values that must have to be changed in all bills.
RGE V3
Values are named in Portuguese, in order.
- Nome
- Rua e Número
- Bairro
- Cep, Cidade e Estado
- Lote
- Endereço de Leitura
- N° do Medidor
- CPF
- Código de Instalação
- Nota Fiscal
- Chave de Acesso Nota Fiscal QRCode
- Protocolo de Autorização Nota Fiscal
- Valores secretos dentro da caixa "Aviso Importante"
- Medidor
- Conta de Energia Elétrica (Número ID)
- Código de Débito Automático do Banco
RGE V2
Values are named in Portuguese, in order.
-
Nome
-
Rua e Número
-
Bairro
-
Cep, Cidade e Estado
-
Nota Fiscal - Ato Declaratório
-
Conta de Energia Elétrica (Número ID) e Série
-
Conta Contrato
-
Lote
-
Roteiro de Leitura
-
N° do Medidor
-
PN
-
Valores secretos dentro da caixa "PREZADO(A) CLIENTE"
-
RG
-
Código de Instalação
-
Código
-
Descrição da Operação
-
CPF
-
Código de Instalação
-
Nota Fiscal
-
Chave de Acesso Nota Fiscal QRCode
-
Protocolo de Autorização Nota Fiscal
-
Valores secretos dentro da caixa "Aviso Importante"
-
Medidor
-
Código de Débito Automático do Banco
nystronsolar/electric-bill-extractor 适用场景与选型建议
nystronsolar/electric-bill-extractor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 61 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 08 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 nystronsolar/electric-bill-extractor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nystronsolar/electric-bill-extractor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 61
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-09