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

BillQuery::initFrom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
crap 2
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