1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Siak\Tontine\Service\Planning; |
4
|
|
|
|
5
|
|
|
use Siak\Tontine\Model\Pool; |
6
|
|
|
use Siak\Tontine\Service\Traits\ReportTrait; |
7
|
|
|
use stdClass; |
8
|
|
|
|
9
|
|
|
use function compact; |
10
|
|
|
|
11
|
|
|
class SummaryService |
12
|
|
|
{ |
13
|
|
|
use ReportTrait; |
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @param PoolService $poolService |
17
|
|
|
*/ |
18
|
|
|
public function __construct(PoolService $poolService) |
19
|
|
|
{ |
20
|
|
|
$this->poolService = $poolService; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Get the receivables of a given pool. |
25
|
|
|
* |
26
|
|
|
* Will return basic data on subscriptions. |
27
|
|
|
* |
28
|
|
|
* @param Pool $pool |
29
|
|
|
* |
30
|
|
|
* @return array |
31
|
|
|
*/ |
32
|
|
|
public function getReceivables(Pool $pool): array |
33
|
|
|
{ |
34
|
|
|
$sessions = $this->poolService->getActiveSessions($pool); |
35
|
|
|
$subscriptions = $pool->subscriptions()->with(['member'])->get(); |
36
|
|
|
$figures = new stdClass(); |
37
|
|
|
$figures->expected = $this->getExpectedFigures($pool, $sessions); |
38
|
|
|
|
39
|
|
|
return compact('pool', 'sessions', 'subscriptions', 'figures'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Get the payables of a given pool. |
44
|
|
|
* |
45
|
|
|
* @param Pool $pool |
46
|
|
|
* |
47
|
|
|
* @return array |
48
|
|
|
*/ |
49
|
|
|
public function getPayables(Pool $pool): array |
50
|
|
|
{ |
51
|
|
|
$sessions = $this->getActiveSessions($pool, [ |
52
|
|
|
'payables.remitment', |
53
|
|
|
'payables.subscription', |
54
|
|
|
]); |
55
|
|
|
$subscriptions = $pool->subscriptions() |
56
|
|
|
->whereHas('payable') // Always true, normally. |
57
|
|
|
->with(['payable', 'payable.session', 'member']) |
58
|
|
|
->get(); |
59
|
|
|
|
60
|
|
|
$figures = new stdClass(); |
61
|
|
|
// Expected figures only for pools with fixed deposit amount |
62
|
|
|
if($pool->remit_planned) |
63
|
|
|
{ |
64
|
|
|
$figures->expected = $this->getExpectedFigures($pool, $sessions); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return compact('pool', 'sessions', 'subscriptions', 'figures'); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|