|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Ajax\Web\Planning\Subscription; |
|
4
|
|
|
|
|
5
|
|
|
use App\Ajax\CallableClass; |
|
6
|
|
|
use Siak\Tontine\Model\Pool as PoolModel; |
|
7
|
|
|
use Siak\Tontine\Service\LocaleService; |
|
8
|
|
|
use Siak\Tontine\Service\Planning\PoolService; |
|
9
|
|
|
use Siak\Tontine\Service\Planning\SubscriptionService; |
|
10
|
|
|
use Siak\Tontine\Service\Planning\SummaryService; |
|
11
|
|
|
|
|
12
|
|
|
use function Jaxon\jq; |
|
13
|
|
|
use function Jaxon\pm; |
|
14
|
|
|
use function trans; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @databag subscription |
|
18
|
|
|
* @before getPool |
|
19
|
|
|
*/ |
|
20
|
|
|
class Home extends CallableClass |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @di |
|
24
|
|
|
* @var LocaleService |
|
25
|
|
|
*/ |
|
26
|
|
|
protected LocaleService $localeService; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @di |
|
30
|
|
|
* @var PoolService |
|
31
|
|
|
*/ |
|
32
|
|
|
protected PoolService $poolService; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var SummaryService |
|
36
|
|
|
*/ |
|
37
|
|
|
public SummaryService $summaryService; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var SubscriptionService |
|
41
|
|
|
*/ |
|
42
|
|
|
public SubscriptionService $subscriptionService; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var PoolModel|null |
|
46
|
|
|
*/ |
|
47
|
|
|
protected ?PoolModel $pool = null; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @return void |
|
51
|
|
|
*/ |
|
52
|
|
|
protected function getPool() |
|
53
|
|
|
{ |
|
54
|
|
|
if($this->target()->method() === 'home') |
|
55
|
|
|
{ |
|
56
|
|
|
return; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$poolId = $this->target()->method() === 'pool' ? $this->target()->args()[0] : |
|
60
|
|
|
intval($this->bag('subscription')->get('pool.id')); |
|
61
|
|
|
$this->pool = $this->poolService->getPool($poolId); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @before checkGuestAccess ["planning", "subscriptions"] |
|
66
|
|
|
* @before checkRoundPools |
|
67
|
|
|
* @after hideMenuOnMobile |
|
68
|
|
|
*/ |
|
69
|
|
|
public function home() |
|
70
|
|
|
{ |
|
71
|
|
|
$html = $this->renderView('pages.planning.subscription.home'); |
|
72
|
|
|
$this->response->html('section-title', trans('tontine.menus.planning')); |
|
73
|
|
|
$this->response->html('content-home', $html); |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
$poolId = intval($this->bag('subscription')->get('pool.id', 0)); |
|
76
|
|
|
$pools = $this->poolService->getRoundPools(); |
|
77
|
|
|
$pool = $pools->firstWhere('id', $poolId) ?? ($pools->count() > 0 ? $pools[0] : null); |
|
78
|
|
|
if($pool === null) |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->response; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$this->pool = $pool; |
|
84
|
|
|
$this->response->call('setSmScreenHandler', 'pool-subscription-sm-screens'); |
|
85
|
|
|
|
|
86
|
|
|
return $this->pool(); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function pool(int $poolId = 0) |
|
90
|
|
|
{ |
|
91
|
|
|
if($this->pool === null) |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->response; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
$this->bag('subscription')->set('pool.id', $this->pool->id); |
|
97
|
|
|
|
|
98
|
|
|
$this->cl(Member::class)->show($this->pool); |
|
99
|
|
|
$this->cl(Session::class)->show($this->pool); |
|
100
|
|
|
|
|
101
|
|
|
if($poolId > 0) |
|
102
|
|
|
{ |
|
103
|
|
|
$message = trans('tontine.pool.messages.selected', [ |
|
104
|
|
|
'tontine' => $this->pool->title, |
|
105
|
|
|
]); |
|
106
|
|
|
$this->response->dialog->info($message, trans('common.titles.info')); |
|
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
return $this->response; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @di $summaryService |
|
114
|
|
|
*/ |
|
115
|
|
|
public function planning() |
|
116
|
|
|
{ |
|
117
|
|
|
if(!$this->pool || !$this->pool->remit_planned) |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->response; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$receivables = $this->summaryService->getReceivables($this->pool); |
|
123
|
|
|
$this->view()->shareValues($receivables); |
|
124
|
|
|
$html = $this->renderView('pages.planning.subscription.planning', [ |
|
125
|
|
|
'pool' => $this->pool, |
|
126
|
|
|
]); |
|
127
|
|
|
$this->response->html('content-page', $html); |
|
|
|
|
|
|
128
|
|
|
$this->response->call('makeTableResponsive', 'content-page'); |
|
129
|
|
|
|
|
130
|
|
|
$this->jq('#btn-subscription-beneficiaries')->click($this->rq()->beneficiaries()); |
|
131
|
|
|
$this->jq('#btn-subscription-refresh')->click($this->rq()->planning()); |
|
132
|
|
|
$this->jq('#btn-subscription-back')->click($this->rq()->home()); |
|
133
|
|
|
|
|
134
|
|
|
return $this->response; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @di $summaryService |
|
139
|
|
|
* @di $subscriptionService |
|
140
|
|
|
*/ |
|
141
|
|
|
public function beneficiaries() |
|
142
|
|
|
{ |
|
143
|
|
|
if(!$this->pool || !$this->pool->remit_planned) |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->response; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
$this->response->html('section-title', trans('tontine.menus.planning')); |
|
149
|
|
|
$payables = $this->summaryService->getPayables($this->pool); |
|
150
|
|
|
$this->view()->shareValues($payables); |
|
151
|
|
|
$html = $this->renderView('pages.planning.subscription.beneficiaries', [ |
|
152
|
|
|
'pool' => $this->pool, |
|
153
|
|
|
'pools' => $this->subscriptionService->getPools(), |
|
154
|
|
|
]); |
|
155
|
|
|
$this->response->html('content-page', $html); |
|
|
|
|
|
|
156
|
|
|
$this->response->call('makeTableResponsive', 'content-page'); |
|
157
|
|
|
|
|
158
|
|
|
$this->jq('#btn-subscription-planning')->click($this->rq()->planning()); |
|
159
|
|
|
$this->jq('#btn-pool-select')->click($this->rq()->select(pm()->select('select-pool')->toInt())); |
|
160
|
|
|
$this->jq('#btn-subscription-refresh')->click($this->rq()->beneficiaries()); |
|
161
|
|
|
$this->jq('#btn-subscription-back')->click($this->rq()->home()); |
|
162
|
|
|
$this->jq('.select-beneficiary')->change($this->rq() |
|
163
|
|
|
->saveBeneficiary(jq()->attr('data-session-id')->toInt(), jq()->val()->toInt(), |
|
164
|
|
|
jq()->attr('data-subscription-id')->toInt())); |
|
165
|
|
|
|
|
166
|
|
|
return $this->response; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @di $summaryService |
|
171
|
|
|
* @di $subscriptionService |
|
172
|
|
|
*/ |
|
173
|
|
|
public function saveBeneficiary(int $sessionId, int $nextSubscriptionId, int $currSubscriptionId) |
|
174
|
|
|
{ |
|
175
|
|
|
if(!$this->pool || !$this->pool->remit_planned || $this->pool->remit_auction) |
|
176
|
|
|
{ |
|
177
|
|
|
return $this->response; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
if(!$this->subscriptionService->saveBeneficiary($this->pool, $sessionId, |
|
181
|
|
|
$currSubscriptionId, $nextSubscriptionId)) |
|
182
|
|
|
{ |
|
183
|
|
|
$message = trans('tontine.beneficiary.errors.cant_change'); |
|
184
|
|
|
$this->response->dialog->error($message, trans('common.titles.error')); |
|
|
|
|
|
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
return $this->beneficiaries(); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|