1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* WellCommerce Open-Source E-Commerce Platform |
4
|
|
|
* |
5
|
|
|
* This file is part of the WellCommerce package. |
6
|
|
|
* |
7
|
|
|
* (c) Adam Piotrowski <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, |
10
|
|
|
* please view the LICENSE file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace WellCommerce\Bundle\InvoiceBundle\Generator; |
14
|
|
|
|
15
|
|
|
use Carbon\Carbon; |
16
|
|
|
use Symfony\Component\ExpressionLanguage\ExpressionLanguage; |
17
|
|
|
use WellCommerce\Bundle\CoreBundle\Helper\Doctrine\DoctrineHelperInterface; |
18
|
|
|
use WellCommerce\Bundle\InvoiceBundle\Entity\Invoice; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class OrderNumberGenerator |
22
|
|
|
* |
23
|
|
|
* @author Adam Piotrowski <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
final class InvoiceNumberGenerator implements InvoiceNumberGeneratorInterface |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var DoctrineHelperInterface |
29
|
|
|
*/ |
30
|
|
|
private $helper; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private $numberFormat; |
36
|
|
|
|
37
|
|
|
public function __construct(DoctrineHelperInterface $helper, string $numberFormat) |
38
|
|
|
{ |
39
|
|
|
$this->helper = $helper; |
40
|
|
|
$this->numberFormat = $numberFormat; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function generate(Invoice $invoice) |
44
|
|
|
{ |
45
|
|
|
$lastId = $this->getLastId(); |
46
|
|
|
$language = new ExpressionLanguage(); |
47
|
|
|
$number = $language->evaluate( |
48
|
|
|
$this->numberFormat, |
49
|
|
|
[ |
50
|
|
|
'nextId' => $lastId + 1, |
51
|
|
|
'month' => Carbon::instance($invoice->getDate())->format('m'), |
52
|
|
|
'year' => Carbon::instance($invoice->getDate())->format('Y'), |
53
|
|
|
'day' => Carbon::instance($invoice->getDate())->format('d'), |
54
|
|
|
'orderNumber' => $invoice->getOrder()->getNumber(), |
55
|
|
|
] |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
$invoice->setNumber($number); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
private function getLastId(): int |
62
|
|
|
{ |
63
|
|
|
return $this->helper->getEntityManager()->createQueryBuilder() |
64
|
|
|
->select('MAX(i.id)') |
65
|
|
|
->from(Invoice::class, 'i') |
66
|
|
|
->getQuery() |
67
|
|
|
->getSingleScalarResult(); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: