BillQuery   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 34
c 2
b 0
f 0
dl 0
loc 53
ccs 0
cts 45
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initFrom() 0 11 1
A attributesMap() 0 32 1
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 hiqdev\billing\hiapi\models\Bill;
14
15
class BillQuery extends \hiqdev\yii\DataMapper\query\Query
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $modelClass = Bill::class;
21
22
    protected function attributesMap()
23
    {
24
        return [
25
            'id' => 'zb.obj_id',
26
            'type' => [
27
                'id' => 'zb.type_id',
28
                'name' => 'bt.g2name',
29
            ],
30
            'plan' => [
31
                'id' => 'zb.tariff_id',
32
            ],
33
            'target' => [
34
                'id' => 'zb.object_id',
35
                'type' => 'tt.name',
36
            ],
37
            'customer' => [
38
                'id' => 'zc.obj_id',
39
                'login' => 'zc.login',
40
                'seller' => [
41
                    'id' => 'cr.obj_id',
42
                    'login' => 'cr.login',
43
                ],
44
            ],
45
            'sum' => [
46
                'currency' => 'py.name',
47
                'amount' => 'zb.sum',
48
            ],
49
            'quantity' => [
50
                'unit' => 'qu.name',
51
                'quantity' => 'zb.quantity',
52
            ],
53
            'time' => 'zb.time',
54
        ];
55
    }
56
57
    public function initFrom()
58
    {
59
        return $this->from('zbill   zb')
60
            ->leftJoin('gref        bt', 'bt.obj_id = zb.type_id')
61
            ->leftJoin('obj         tj', 'tj.obj_id = zb.object_id')
62
            ->leftJoin('zref        tt', 'tt.obj_id = tj.class_id')
63
            ->leftJoin('purse       bp', 'bp.obj_id = zb.purse_id')
64
            ->leftJoin('zclient     zc', 'zc.obj_id = bp.client_id')
65
            ->leftJoin('zclient     cr', 'cr.obj_id = zc.seller_id')
66
            ->leftJoin('zref        py', 'py.obj_id = bp.currency_id')
67
            ->leftJoin('zref        qu', 'qu.obj_id = zb.unit_id');
68
    }
69
}
70