1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Finance module for HiPanel |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hipanel-module-finance |
6
|
|
|
* @package hipanel-module-finance |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hipanel\modules\finance\grid; |
12
|
|
|
|
13
|
|
|
use hipanel\modules\finance\assets\PriceEstimator; |
14
|
|
|
use Yii; |
15
|
|
|
use yii\grid\Column; |
16
|
|
|
use yii\helpers\Html; |
17
|
|
|
use yii\helpers\Url; |
18
|
|
|
|
19
|
|
|
class ValueColumn extends Column |
20
|
|
|
{ |
21
|
|
|
public $attribute = 'value'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var integer |
25
|
|
|
*/ |
26
|
|
|
private $planId; |
27
|
|
|
|
28
|
|
|
public function init() |
29
|
|
|
{ |
30
|
|
|
parent::init(); |
31
|
|
|
$this->header = Yii::t('hipanel.finance.plan', 'Estimated value'); |
32
|
|
|
$this->planId = $this->findPlanId(); |
33
|
|
|
$this->registerClientScript(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
protected function renderDataCellContent($model, $key, $index) |
37
|
|
|
{ |
38
|
|
|
$fields = Html::hiddenInput("[{$model->id}]object_id", $model->object_id); |
39
|
|
|
$fields .= Html::hiddenInput("[{$model->id}]type", $model->type); |
40
|
|
|
|
41
|
|
|
return Html::tag('span', Html::tag('span', Html::tag('i', $fields, [ |
42
|
|
|
'class' => 'fa fa-refresh fa-spin fa-fw', |
43
|
|
|
'data' => ['id' => $model->id], |
44
|
|
|
]), ['class' => 'price-estimates']), ['class' => 'price-item', 'data' => ['id' => $model->id]]); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
private function registerClientScript() |
48
|
|
|
{ |
49
|
|
|
$calculateValueUrl = Url::toRoute(['@plan/calculate-values', 'planId' => $this->planId]); |
50
|
|
|
$view = Yii::$app->view; |
51
|
|
|
$view->registerAssetBundle(PriceEstimator::class); |
52
|
|
|
$view->registerJs(/** @lang ECMAScript 6 */ |
53
|
|
|
" |
54
|
|
|
;(function ($, window, document, undefined) { |
55
|
|
|
let Estimator = $('#bulk-plan').priceEstimator({ |
56
|
|
|
url: '${calculateValueUrl}', |
57
|
|
|
estimatePlan: true, |
58
|
|
|
rowSelector: '.price-item', |
59
|
|
|
totalCellSelector: '#plan-monthly-value', |
60
|
|
|
totalPerObjectSelector: '.total-per-object', |
61
|
|
|
}); |
62
|
|
|
Estimator.update(); |
63
|
|
|
})(jQuery, window, document); |
64
|
|
|
"); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
private function findPlanId() |
68
|
|
|
{ |
69
|
|
|
return Yii::$app->request->get('id'); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|