File: D:/HostingSpaces/SBogers10/blije-gasten.komma.pro/app/Komma/Shop/Orders/OrderNumberSequence.php
<?php
namespace App\Komma\Shop\Orders;
use App\Komma\Kms\Core\Sequence\Parts\NumberPart;
use App\Komma\Kms\Core\Sequence\Sequence;
use Carbon\Carbon;
/**
* Defines an order number
*/
class OrderNumberSequence extends Sequence
{
public function __construct()
{
parent::__construct();
//Define how an order number looks like
$this->startsWith('O') //O to indicate that it is an order number
->followedBy(new NumberPart(4, 'year'))
->followedBy(new NumberPart(5, 'number'));
//Define its starting number when the orders table is empty
$this->startingAt('O'.Carbon::now()->year.'00000');
//The table and column the in this case "order number" is meant for. Checks uniqueness and starts the sequence from the latest order number if present
$this->uniqueForTable('orders', 'order_number');
//Force the year part to be the current year, even if the latest order for the table is a different year
$this->getPartByName('year')->startingAt(Carbon::now()->year);
}
}