hippone/algerian-invoice-code-generator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hippone/algerian-invoice-code-generator

Composer 安装命令:

composer require hippone/algerian-invoice-code-generator

包简介

README 文档

README

The library is useful to generate code for invoices, quotes or any commercial transaction document.

Goal

Is to provide helpful interface to generate the needed code.

Installation

The recommended (and the best) way to install the library is by using composer:

composer require hippone/algerian-invoice-code-generator

Usage

The Hippone\InvoiceCode\CodeGenerator code is the main component of the library, it implements Hippone\InvoiceCode\CodeGeneratorInterface, this class has one dependency (for now) that implements Hippone\InvoiceCode\Model\IdentifiableProvider to be provided by the client, this dependency is the port to the persistence layer used by the client, an example of a simple implementation which uses PDO with SQLite would be:

<?php
declare(strict_types=1);

namespace MyNamespace\Persistence\SQLite;

use DateTimeImmutable;
use Hippone\InvoiceCode\Model\CodeComponents;
use Hippone\InvoiceCode\Model\IdentifiableProvider;
use PDO;

class SQLiteIdentifiableProvider implements IdentifiableProvider
{
    private PDO $pdo;
    
    public function __construct(PDO $pdo)
    {
        $this->pdo = $pdo;
    }

    public function nextCode(DateTimeImmutable $year): CodeComponents
    {
         $statement = $this->pdo->prepare('
                            SELECT COUNT(*) FROM invoices 
                            AS i 
                            WHERE strftime("%Y", i.created_at) = :currentYear
        ');
        $statement->bindValue(':currentYear', $year->format('Y'));
        $statement->execute();
        $currentCount = $statement->fetchColumn();
        $sequentialNumber = $currentCount + 1;
        return CodeComponents::from($sequentialNumber, $year);
    }
}

Once the Hippone\InvoiceCode\Model\IdentifiableProvider is implemented, the Hippone\InvoiceCode\CodeGenerator class can be instantiated and used like the following:

$codeGenerator = new CodeGenerator(new SQLiteIdentifiableProvider($pdo)); // assume PDO object is instantiated
$codeGenerator->generateForYear(DateTimeImmutable::createFromFormat('Y', '2021')); // replace 2021 by the desired value

License

MIT License.

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固