src/InvoiceNumber/IncrementalWithYearInvoice.php
public function calculateNextFreeNumber()
    {
        $year = (new \DateTime())->format('Y');

        /** @var \Railken\Amethyst\Models\InvoiceModel */
        $result = $this->getManager()
            ->getRepository()
            ->newQuery()
            ->where('number', 'like', '%/'.$year)
            ->orderBy(DB::raw("CAST(REPLACE(number, '/{$year}', '') AS DECIMAL(10,2))"), 'desc')
            ->first();

        $number = $result ? intval(str_replace("/{$year}", '', $result->number)) + 1 : 1;

        return $number.'/'.$year;
    }
public function calculateNextFreeNumber()
    {
        $year = (new \DateTime())->format('Y');

        /** @var \Railken\Amethyst\Models\InvoiceModel */
        $result = $this->getManager()
            ->getRepository()
            ->newQuery()
            ->where('number', 'like', '%/'.$year)
            ->orderBy(DB::raw("CAST(REPLACE(number, '/{$year}', '') AS DECIMAL(10,2))"), 'desc')
            ->first();

        $number = $result ? intval(str_replace("/{$year}", '', $result->number)) + 1 : 1;

        return $number.'/'.$year;
    }
public function calculateNextFreeNumber ( ) { $ year = ( new \ DateTime ( ) ) -> format ( 'Y' ) ; /** @var \Railken\Amethyst\Models\InvoiceModel */ $ result = $ this -> getManager ( ) -> getRepository ( ) -> newQuery ( ) -> where ( 'number' , 'like' , '%/' . $ year ) -> orderBy ( DB :: raw ( "CAST(REPLACE(number, '/{$year}', '') AS DECIMAL(10,2))" ) , 'desc' ) -> first ( ) ; $ number = $ result ? intval ( str_replace ( "/{$year}" , '' , $ result -> number ) ) + 1 : 1 ; return $ number . '/' . $ year ; }
Calculate next free number.

@return string
Calculate next free number .