<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hippone / algerian-invoice-code-generator example snippets
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);
}
}
$codeGenerator = new CodeGenerator(new SQLiteIdentifiableProvider($pdo)); // assume PDO object is instantiated
$codeGenerator->generateForYear(DateTimeImmutable::createFromFormat('Y', '2021')); // replace 2021 by the desired value
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.