|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace app\modules\v1\controllers; |
|
4
|
|
|
|
|
5
|
|
|
use app\core\exceptions\InternalException; |
|
6
|
|
|
use app\core\exceptions\InvalidArgumentException; |
|
7
|
|
|
use app\core\models\Record; |
|
8
|
|
|
use app\core\traits\ServiceTrait; |
|
9
|
|
|
use app\core\types\RecordSource; |
|
10
|
|
|
use app\core\types\TransactionType; |
|
11
|
|
|
use Exception; |
|
12
|
|
|
use Yii; |
|
13
|
|
|
use yii\base\InvalidConfigException; |
|
14
|
|
|
use yii\data\ActiveDataProvider; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Record controller for the `v1` module |
|
18
|
|
|
*/ |
|
19
|
|
|
class RecordController extends ActiveController |
|
20
|
|
|
{ |
|
21
|
|
|
use ServiceTrait; |
|
22
|
|
|
|
|
23
|
|
|
public $modelClass = Record::class; |
|
24
|
|
|
public $noAuthActions = []; |
|
25
|
|
|
public $partialMatchAttributes = ['name']; |
|
26
|
|
|
public $defaultOrder = ['date' => SORT_DESC, 'id' => SORT_DESC]; |
|
27
|
|
|
public $stringToIntAttributes = ['transaction_type' => TransactionType::class]; |
|
28
|
|
|
public $relations = ['transaction' => []]; |
|
29
|
|
|
|
|
30
|
|
|
public function actions() |
|
31
|
|
|
{ |
|
32
|
|
|
$actions = parent::actions(); |
|
33
|
|
|
unset($actions['create'], $actions['update']); |
|
34
|
|
|
return $actions; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return ActiveDataProvider |
|
40
|
|
|
* @throws InvalidArgumentException |
|
41
|
|
|
* @throws InvalidConfigException |
|
42
|
|
|
* @throws InternalException |
|
43
|
|
|
*/ |
|
44
|
|
|
public function prepareDataProvider() |
|
45
|
|
|
{ |
|
46
|
|
|
$dataProvider = parent::prepareDataProvider(); |
|
47
|
|
|
if ($searchKeywords = trim(request('keyword'))) { |
|
48
|
|
|
$dataProvider->query->andWhere( |
|
|
|
|
|
|
49
|
|
|
"MATCH(`description`, `tags`, `remark`) AGAINST ('*$searchKeywords*' IN BOOLEAN MODE)" |
|
|
|
|
|
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
$dataProvider->setModels($this->transactionService->formatRecords($dataProvider->getModels())); |
|
53
|
|
|
return $dataProvider; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param array $params |
|
58
|
|
|
* @return array |
|
59
|
|
|
* @throws Exception |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function formatParams(array $params) |
|
62
|
|
|
{ |
|
63
|
|
|
if (($date = explode('~', data_get($params, 'date'))) && count($date) == 2) { |
|
|
|
|
|
|
64
|
|
|
$start = $date[0] . ' 00:00:00'; |
|
65
|
|
|
$end = $date[1] . ' 23:59:59'; |
|
66
|
|
|
$params['date'] = "{$start}~{$end}"; |
|
67
|
|
|
} |
|
68
|
|
|
return $params; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return array |
|
73
|
|
|
* @throws Exception |
|
74
|
|
|
*/ |
|
75
|
|
|
public function actionOverview() |
|
76
|
|
|
{ |
|
77
|
|
|
return array_values($this->analysisService->recordOverview); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return array |
|
83
|
|
|
* @throws InvalidArgumentException |
|
84
|
|
|
* @throws Exception |
|
85
|
|
|
*/ |
|
86
|
|
|
public function actionAnalysis() |
|
87
|
|
|
{ |
|
88
|
|
|
$transactionType = request('transaction_type', TransactionType::getName(TransactionType::EXPENSE)); |
|
89
|
|
|
$date = request('date', Yii::$app->formatter->asDatetime('now')); |
|
90
|
|
|
|
|
91
|
|
|
return $this->analysisService->getRecordStatisticalData( |
|
92
|
|
|
$date, |
|
93
|
|
|
TransactionType::toEnumValue($transactionType) |
|
94
|
|
|
); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return array |
|
99
|
|
|
* @throws Exception |
|
100
|
|
|
*/ |
|
101
|
|
|
public function actionSources() |
|
102
|
|
|
{ |
|
103
|
|
|
$items = []; |
|
104
|
|
|
$names = RecordSource::names(); |
|
105
|
|
|
foreach ($names as $key => $name) { |
|
106
|
|
|
$items[] = ['type' => $key, 'name' => $name]; |
|
107
|
|
|
} |
|
108
|
|
|
return $items; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.