Completed
Push — master ( e918d3...e1c7ce )
by Andrii
01:58
created

BillQuery   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 50
ccs 0
cts 34
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B attributesMap() 0 29 1
A initFrom() 0 12 1
1
<?php
2
3
namespace hiqdev\billing\hiapi\query;
4
5
use hiqdev\billing\hiapi\models\Bill;
6
use yii\db\Expression;
7
8
class BillQuery extends \hiapi\query\Query
9
{
10
    protected $modelClass = Bill::class;
11
12
    public function initFrom()
13
    {
14
        return $this->from('zbill   zb')
15
            ->leftJoin('zref        bt', 'bt.obj_id = zb.type_id')
16
            ->leftJoin('purse       zp', 'zp.obj_id = zb.purse_id')
17
            ->leftJoin('zclient     zc', 'zc.obj_id = zp.client_id')
18
            ->leftJoin('zclient     cr', 'cr.obj_id = zc.seller_id')
19
            ->leftJoin('zref        cu', 'cu.obj_id = zp.currency_id')
20
            ->leftJoin('obj         zo', 'zo.obj_id = zb.object_id')
21
            ->leftJoin('zref        oc', 'oc.obj_id = zo.class_id')
22
        ;
23
    }
24
25
    /**
26
     * @return mixed
27
     */
28
    protected function attributesMap()
29
    {
30
        return [
31
            'id' => 'zb.obj_id',
32
            'time' => new Expression("date_trunc('second', zb.time) as time"),
33
            'quantity' => [
34
                'quantity' => 'zb.quantity',
35
            ],
36
            'sum' => [
37
                'currency' => 'cu.name',
38
                'amount' => 'zb.sum',
39
            ],
40
            'type' => [
41
                'name' => 'bt.name',
42
            ],
43
            'customer' => [
44
                'id' => 'zc.obj_id',
45
                'login' => 'zc.login',
46
                'seller' => [
47
                    'id' => 'cr.obj_id',
48
                    'login' => 'cr.login',
49
                ],
50
            ],
51
            'target' => [
52
                'id' => 'zb.object_id',
53
                'type' => 'oc.name',
54
            ],
55
        ];
56
    }
57
}
58