1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* API for Billing |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/billing-hiapi |
6
|
|
|
* @package billing-hiapi |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2017-2018, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hiqdev\billing\hiapi\bill; |
12
|
|
|
|
13
|
|
|
use DateTime; |
14
|
|
|
use hiqdev\php\billing\bill\BillInterface; |
15
|
|
|
use hiqdev\php\billing\customer\Customer; |
16
|
|
|
use hiqdev\php\billing\target\Target; |
17
|
|
|
use hiqdev\php\billing\type\Type; |
18
|
|
|
use hiqdev\php\units\Quantity; |
19
|
|
|
use hiqdev\yii\DataMapper\expressions\CallExpression; |
20
|
|
|
use hiqdev\yii\DataMapper\expressions\HstoreExpression; |
21
|
|
|
use Money\Currency; |
22
|
|
|
use Money\Money; |
23
|
|
|
use yii\db\Query; |
24
|
|
|
|
25
|
|
|
class BillRepository extends \hiqdev\yii\DataMapper\repositories\BaseRepository |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* XXX TO BE REMOVED. |
29
|
|
|
*/ |
30
|
|
|
public function saveReal(BillInterface $bill) |
31
|
|
|
{ |
32
|
|
|
return $this->save($bill, true); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param BillInterface $bill |
37
|
|
|
* @param bool $isReal XXX TO BE REMOVED |
38
|
|
|
*/ |
39
|
|
|
public function save(BillInterface $bill, $isReal = false) |
40
|
|
|
{ |
41
|
|
|
$hstore = new HstoreExpression([ |
42
|
|
|
'id' => $bill->getId(), |
43
|
|
|
'object_id' => $bill->getTarget()->getId(), |
44
|
|
|
'tariff_id' => $bill->getPlan() ? $bill->getPlan()->getId() : null, |
45
|
|
|
'type_id' => $bill->getType()->getId(), |
46
|
|
|
'type' => $bill->getType()->getName(), |
47
|
|
|
'buyer_id' => $bill->getCustomer()->getId(), |
48
|
|
|
'buyer' => $bill->getCustomer()->getLogin(), |
49
|
|
|
'currency' => $bill->getSum()->getCurrency()->getCode(), |
50
|
|
|
'sum' => $bill->getSum()->getAmount() * -1, |
51
|
|
|
'quantity' => $bill->getQuantity()->getQuantity(), |
52
|
|
|
'time' => $bill->getTime()->format('c'), |
53
|
|
|
'label' => $bill->getComment() ?: null, |
54
|
|
|
'is_finished' => $bill->isFinished(), |
55
|
|
|
'increment' => true, |
56
|
|
|
]); |
57
|
|
|
$call = new CallExpression('set_bill' . ($isReal ? '' : '2'), [$hstore]); |
58
|
|
|
$command = (new Query())->select($call); |
59
|
|
|
$bill->setId($command->scalar($this->db)); |
60
|
|
|
foreach ($bill->getCharges() as $charge) { |
61
|
|
|
$charge->setBill($bill); |
62
|
|
|
$this->em->save($charge); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.