Algerian code generator for invoices, quotes or any commercial documents

Overview

Algerian invoice code generator

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:

bindValue(':currentYear', $year->format('Y')); $statement->execute(); $currentCount = $statement->fetchColumn(); $sequentialNumber = $currentCount + 1; return CodeComponents::from($sequentialNumber, $year); } } ">

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.

You might also like...
A simple library for dealing with docx word processed documents

WordCat Limited manipulation of docx word processed documents A simple php library for manipulation of docx word processed document; in particular the

Contracts for Rule Doc Generator. Useful for production code with minimum dependencies.

Rule Doc Generator Contracts Contracts for Rule Doc Generator. Useful for production code with minimum dependencies. Install composer require symplify

Magento 2 Code Generator

Magento 2 Code Generator Created by Orba Inspired by https://github.com/staempfli/magento2-code-generator Purpose In day-to-day Magento 2 development

Code generator for Magento 2
Code generator for Magento 2

Magento 2 Code Generator Tool Installation Option1: Downloading .phar wget https://github.com/staempfli/magento2-code-generator/releases/download/ver

Runtime Code Generator like Lombok for PocketMine-MP
Runtime Code Generator like Lombok for PocketMine-MP

PlumbokPM Runtime Code Generator like Lombok for PocketMine-MP. Code generation starts when additional autoloader detects class uses PlumbokPM annotat

A QR Code generator for PHP7.4+

chillerlan/php-qrcode A PHP 7.4+ QR Code library based on the implementation by Kazuhiko Arase, namespaced, cleaned up, improved and other stuff. Docu

The VarExporter component allows exporting any serializable PHP data structure to plain PHP code.

The VarExporter component allows exporting any serializable PHP data structure to plain PHP code. While doing so, it preserves all the semantics associated with the serialization mechanism of PHP (__wakeup, __sleep, Serializable).

A pure PHP implementation of the open Language Server Protocol. Provides static code analysis for PHP for any IDE.
A pure PHP implementation of the open Language Server Protocol. Provides static code analysis for PHP for any IDE.

A pure PHP implementation of the open Language Server Protocol. Provides static code analysis for PHP for any IDE.

Result of our code-along meetup writing PHP 8.1 code

PHP 8.1 Demo Code This code demonstrates various PHP 8.0 and 8.1 features in a realistic, functional (but incomplete) codebase. The code is part of so

Releases(v0.2.0)
Owner
Hippone Consulting
Software consulting office
Hippone Consulting
Tables migrations seeded with data according to the Algerian education system structure.

Laravel algerian education system structure If you are building a Learning Management System or a School Management System and targeting the Algerian

Elaborate Code 12 Oct 8, 2022
salah eddine bendyab 18 Aug 17, 2021
Track any ip address with IP-Tracer. IP-Tracer is developed for Linux and Termux. you can retrieve any ip address information using IP-Tracer.

IP-Tracer is used to track an ip address. IP-Tracer is developed for Termux and Linux based systems. you can easily retrieve ip address information using IP-Tracer. IP-Tracer use ip-api to track ip address.

Rajkumar Dusad 1.2k Jan 4, 2023
Skosmos is a web-based tool providing services for accessing controlled vocabularies, which are used by indexers describing documents and searchers looking for suitable keywords.

Skosmos is a web-based tool providing services for accessing controlled vocabularies, which are used by indexers describing documents and searchers looking for suitable keywords.

National Library of Finland 195 Dec 24, 2022
A pure PHP library for reading and writing presentations documents

Branch Master : Branch Develop : PHPPresentation is a library written in pure PHP that provides a set of classes to write to different presentation fi

PHPOffice 1.2k Jan 2, 2023
JSONFinder - a library that can find json values in a mixed text or html documents, can filter and search the json tree, and converts php objects to json without 'ext-json' extension.

JSONFinder - a library that can find json values in a mixed text or html documents, can filter and search the json tree, and converts php objects to json without 'ext-json' extension.

Eboubaker Eboubaker 2 Jul 31, 2022
Json-normalizer: Provides generic and vendor-specific normalizers for normalizing JSON documents

json-normalizer Provides generic and vendor-specific normalizers for normalizing JSON documents. Installation Run $ composer require ergebnis/json-nor

null 64 Dec 31, 2022
A PHP wrapper around Libreoffice for converting documents from one format to another.

Document Converter A PHP wrapper around Libreoffice for converting documents from one format to another. For example: Microsoft Word to PDF OpenOffice

Lukas White 0 Jul 28, 2022
A school platform to organize documents and files for students manged by teachers also user role management

A school platform to organize documents and files for students manged by teachers also user role management. The app is developed by the LARAVEL Framework.

med el mobarik 3 Sep 5, 2022