@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | $this->target()->args()[0] : $this->bag('meeting')->get('pool.id'); |
| 69 | 69 | $this->pool = $this->depositService->getPool($poolId); |
| 70 | 70 | |
| 71 | - if(!$this->session || !$this->pool || $this->session->disabled($this->pool)) |
|
| 71 | + if (!$this->session || !$this->pool || $this->session->disabled($this->pool)) |
|
| 72 | 72 | { |
| 73 | 73 | $this->notify->error(trans('tontine.session.errors.disabled'), trans('common.titles.error')); |
| 74 | 74 | $this->pool = null; |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | */ |
| 135 | 135 | public function addDeposit(int $receivableId) |
| 136 | 136 | { |
| 137 | - if($this->session->closed) |
|
| 137 | + if ($this->session->closed) |
|
| 138 | 138 | { |
| 139 | 139 | $this->notify->warning(trans('meeting.warnings.session.closed')); |
| 140 | 140 | return $this->response; |
@@ -153,21 +153,20 @@ discard block |
||
| 153 | 153 | */ |
| 154 | 154 | public function editAmount(int $receivableId) |
| 155 | 155 | { |
| 156 | - if($this->session->closed) |
|
| 156 | + if ($this->session->closed) |
|
| 157 | 157 | { |
| 158 | 158 | $this->notify->warning(trans('meeting.warnings.session.closed')); |
| 159 | 159 | return $this->response; |
| 160 | 160 | } |
| 161 | 161 | $receivable = $this->depositService->getReceivable($this->pool, $this->session, $receivableId); |
| 162 | - if(!$receivable || !$receivable->deposit) |
|
| 162 | + if (!$receivable || !$receivable->deposit) |
|
| 163 | 163 | { |
| 164 | 164 | return $this->page(); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | $html = $this->view()->render('tontine.pages.meeting.deposit.libre.edit', [ |
| 168 | 168 | 'id' => $receivable->id, |
| 169 | - 'amount' => !$receivable->deposit ? '' : |
|
| 170 | - $this->localeService->getMoneyValue($receivable->deposit->amount), |
|
| 169 | + 'amount' => !$receivable->deposit ? '' : $this->localeService->getMoneyValue($receivable->deposit->amount), |
|
| 171 | 170 | ]); |
| 172 | 171 | $fieldId = 'receivable-' . $receivable->id; |
| 173 | 172 | $this->response->html($fieldId, $html); |
@@ -188,22 +187,21 @@ discard block |
||
| 188 | 187 | */ |
| 189 | 188 | public function saveAmount(int $receivableId, string $amount) |
| 190 | 189 | { |
| 191 | - if($this->session->closed) |
|
| 190 | + if ($this->session->closed) |
|
| 192 | 191 | { |
| 193 | 192 | $this->notify->warning(trans('meeting.warnings.session.closed')); |
| 194 | 193 | return $this->response; |
| 195 | 194 | } |
| 196 | 195 | $amount = str_replace(',', '.', trim($amount)); |
| 197 | - if($amount !== '' && filter_var($amount, FILTER_VALIDATE_FLOAT) === false) |
|
| 196 | + if ($amount !== '' && filter_var($amount, FILTER_VALIDATE_FLOAT) === false) |
|
| 198 | 197 | { |
| 199 | 198 | $this->notify->error(trans('meeting.errors.amount.invalid', ['amount' => $amount])); |
| 200 | 199 | return $this->response; |
| 201 | 200 | } |
| 202 | - $amount = $amount === '' ? 0 : $this->localeService->convertMoneyToInt((float)$amount); |
|
| 201 | + $amount = $amount === '' ? 0 : $this->localeService->convertMoneyToInt((float) $amount); |
|
| 203 | 202 | |
| 204 | 203 | $amount > 0 ? |
| 205 | - $this->depositService->saveDepositAmount($this->pool, $this->session, $receivableId, $amount): |
|
| 206 | - $this->depositService->deleteDeposit($this->pool, $this->session, $receivableId); |
|
| 204 | + $this->depositService->saveDepositAmount($this->pool, $this->session, $receivableId, $amount) : $this->depositService->deleteDeposit($this->pool, $this->session, $receivableId); |
|
| 207 | 205 | |
| 208 | 206 | return $this->page(); |
| 209 | 207 | } |
@@ -215,7 +213,7 @@ discard block |
||
| 215 | 213 | */ |
| 216 | 214 | public function delDeposit(int $receivableId) |
| 217 | 215 | { |
| 218 | - if($this->session->closed) |
|
| 216 | + if ($this->session->closed) |
|
| 219 | 217 | { |
| 220 | 218 | $this->notify->warning(trans('meeting.warnings.session.closed')); |
| 221 | 219 | return $this->response; |
@@ -231,12 +229,12 @@ discard block |
||
| 231 | 229 | */ |
| 232 | 230 | public function addAllDeposits() |
| 233 | 231 | { |
| 234 | - if($this->session->closed) |
|
| 232 | + if ($this->session->closed) |
|
| 235 | 233 | { |
| 236 | 234 | $this->notify->warning(trans('meeting.warnings.session.closed')); |
| 237 | 235 | return $this->response; |
| 238 | 236 | } |
| 239 | - if(!$this->pool->deposit_fixed) |
|
| 237 | + if (!$this->pool->deposit_fixed) |
|
| 240 | 238 | { |
| 241 | 239 | return $this->response; |
| 242 | 240 | } |
@@ -251,12 +249,12 @@ discard block |
||
| 251 | 249 | */ |
| 252 | 250 | public function delAllDeposits() |
| 253 | 251 | { |
| 254 | - if($this->session->closed) |
|
| 252 | + if ($this->session->closed) |
|
| 255 | 253 | { |
| 256 | 254 | $this->notify->warning(trans('meeting.warnings.session.closed')); |
| 257 | 255 | return $this->response; |
| 258 | 256 | } |
| 259 | - if(!$this->pool->deposit_fixed) |
|
| 257 | + if (!$this->pool->deposit_fixed) |
|
| 260 | 258 | { |
| 261 | 259 | return $this->response; |
| 262 | 260 | } |
@@ -55,26 +55,26 @@ discard block |
||
| 55 | 55 | private function setDistributions(Session $session, Collection $fundings): Collection |
| 56 | 56 | { |
| 57 | 57 | // Set fundings durations and distributions |
| 58 | - foreach($fundings as $funding) |
|
| 58 | + foreach ($fundings as $funding) |
|
| 59 | 59 | { |
| 60 | 60 | $funding->duration = $this->getFundingDuration($session, $funding); |
| 61 | 61 | $funding->distribution = $funding->amount * $funding->duration; |
| 62 | 62 | } |
| 63 | 63 | // Reduce the distributions |
| 64 | - $distributionGcd = (int)$fundings->reduce(function($gcd, $funding) { |
|
| 65 | - if($gcd === 0) |
|
| 64 | + $distributionGcd = (int) $fundings->reduce(function($gcd, $funding) { |
|
| 65 | + if ($gcd === 0) |
|
| 66 | 66 | { |
| 67 | 67 | return $funding->distribution; |
| 68 | 68 | } |
| 69 | - if($funding->duration === 0) |
|
| 69 | + if ($funding->duration === 0) |
|
| 70 | 70 | { |
| 71 | 71 | return $gcd; |
| 72 | 72 | } |
| 73 | 73 | return gmp_gcd($gcd, $funding->distribution); |
| 74 | 74 | }, $fundings->first()->distribution); |
| 75 | - if($distributionGcd > 0) |
|
| 75 | + if ($distributionGcd > 0) |
|
| 76 | 76 | { |
| 77 | - foreach($fundings as $funding) |
|
| 77 | + foreach ($fundings as $funding) |
|
| 78 | 78 | { |
| 79 | 79 | $funding->distribution /= $distributionGcd; |
| 80 | 80 | } |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | ->orderBy('members.name', 'asc') |
| 102 | 102 | ->orderBy('sessions.start_at', 'asc') |
| 103 | 103 | ->with(['session', 'member'])->get(); |
| 104 | - if($fundings->count() === 0) |
|
| 104 | + if ($fundings->count() === 0) |
|
| 105 | 105 | { |
| 106 | 106 | return $fundings; |
| 107 | 107 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | 'amount' => $profitAmount, |
| 149 | 149 | ]; |
| 150 | 150 | $round = $this->tenantService->round(); |
| 151 | - if($round->property !== null) |
|
| 151 | + if ($round->property !== null) |
|
| 152 | 152 | { |
| 153 | 153 | $content = $round->property->content; |
| 154 | 154 | $content['profit'] = $profit; |
@@ -97,13 +97,13 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | protected function chargeCreated(Tontine $tontine, Charge $charge) |
| 99 | 99 | { |
| 100 | - if(!$charge->period_once) |
|
| 100 | + if (!$charge->period_once) |
|
| 101 | 101 | { |
| 102 | 102 | return; |
| 103 | 103 | } |
| 104 | 104 | $today = now(); |
| 105 | 105 | // Create a tontine bill for each member |
| 106 | - foreach($tontine->members()->get() as $member) |
|
| 106 | + foreach ($tontine->members()->get() as $member) |
|
| 107 | 107 | { |
| 108 | 108 | $this->createTontineBill($charge, $member, $today); |
| 109 | 109 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | { |
| 120 | 120 | $today = now(); |
| 121 | 121 | // Create a tontine bill for each charge |
| 122 | - foreach($tontine->charges()->active()->once()->get() as $charge) |
|
| 122 | + foreach ($tontine->charges()->active()->once()->get() as $charge) |
|
| 123 | 123 | { |
| 124 | 124 | $this->createTontineBill($charge, $member, $today); |
| 125 | 125 | } |
@@ -142,14 +142,14 @@ discard block |
||
| 142 | 142 | ])->get(); |
| 143 | 143 | $roundCharges = $tontine->charges()->active()->round()->get(); |
| 144 | 144 | // Create a round bill for each member |
| 145 | - foreach($members as $member) |
|
| 145 | + foreach ($members as $member) |
|
| 146 | 146 | { |
| 147 | - foreach($roundCharges as $charge) |
|
| 147 | + foreach ($roundCharges as $charge) |
|
| 148 | 148 | { |
| 149 | 149 | $count = $member->round_bills->filter(function($bill) use($charge) { |
| 150 | 150 | return $bill->charge_id = $charge->id; |
| 151 | 151 | })->count(); |
| 152 | - if($count === 0) |
|
| 152 | + if ($count === 0) |
|
| 153 | 153 | { |
| 154 | 154 | $this->createRoundBill($charge, $member, $round, $today); |
| 155 | 155 | } |
@@ -157,14 +157,14 @@ discard block |
||
| 157 | 157 | } |
| 158 | 158 | $tontineCharges = $tontine->charges()->active()->once()->get(); |
| 159 | 159 | // Create a tontine bill for each member |
| 160 | - foreach($members as $member) |
|
| 160 | + foreach ($members as $member) |
|
| 161 | 161 | { |
| 162 | - foreach($tontineCharges as $charge) |
|
| 162 | + foreach ($tontineCharges as $charge) |
|
| 163 | 163 | { |
| 164 | 164 | $count = $member->tontine_bills->filter(function($bill) use($charge) { |
| 165 | 165 | return $bill->charge_id = $charge->id; |
| 166 | 166 | })->count(); |
| 167 | - if($count === 0) |
|
| 167 | + if ($count === 0) |
|
| 168 | 168 | { |
| 169 | 169 | $this->createTontineBill($charge, $member, $today); |
| 170 | 170 | } |
@@ -192,14 +192,14 @@ discard block |
||
| 192 | 192 | $sessionCharges = $tontine->charges()->active()->session()->get(); |
| 193 | 193 | |
| 194 | 194 | // Sync the session bills for each member and each session charge |
| 195 | - foreach($sessionCharges as $charge) |
|
| 195 | + foreach ($sessionCharges as $charge) |
|
| 196 | 196 | { |
| 197 | - foreach($members as $member) |
|
| 197 | + foreach ($members as $member) |
|
| 198 | 198 | { |
| 199 | 199 | $count = $member->session_bills->filter(function($bill) use($charge) { |
| 200 | 200 | return $bill->charge_id = $charge->id; |
| 201 | 201 | })->count(); |
| 202 | - if($count === 0) |
|
| 202 | + if ($count === 0) |
|
| 203 | 203 | { |
| 204 | 204 | $this->createSessionBill($charge, $member, $session, $today); |
| 205 | 205 | } |
@@ -207,15 +207,15 @@ discard block |
||
| 207 | 207 | }; |
| 208 | 208 | |
| 209 | 209 | // Sync the receivables for each subscription on each pool |
| 210 | - foreach($session->round->pools as $pool) |
|
| 210 | + foreach ($session->round->pools as $pool) |
|
| 211 | 211 | { |
| 212 | - if($session->enabled($pool)) |
|
| 212 | + if ($session->enabled($pool)) |
|
| 213 | 213 | { |
| 214 | 214 | $subscriptions = $pool->subscriptions() |
| 215 | 215 | ->whereDoesntHave('receivables', function(Builder $query) use($session) { |
| 216 | 216 | return $query->where('session_id', $session->id); |
| 217 | 217 | }); |
| 218 | - foreach($subscriptions->get() as $subscription) |
|
| 218 | + foreach ($subscriptions->get() as $subscription) |
|
| 219 | 219 | { |
| 220 | 220 | $subscription->receivables()->create(['session_id' => $session->id]); |
| 221 | 221 | } |
@@ -93,9 +93,7 @@ discard block |
||
| 93 | 93 | private function getBillRelation(Charge $charge): string |
| 94 | 94 | { |
| 95 | 95 | // The intermediate relation to reach the member model. |
| 96 | - return $charge->is_variable ? 'libre_bill' : |
|
| 97 | - ($charge->period_session ? 'session_bill' : |
|
| 98 | - ($charge->period_round ? 'round_bill' : 'tontine_bill')); |
|
| 96 | + return $charge->is_variable ? 'libre_bill' : ($charge->period_session ? 'session_bill' : ($charge->period_round ? 'round_bill' : 'tontine_bill')); |
|
| 99 | 97 | } |
| 100 | 98 | |
| 101 | 99 | /** |
@@ -111,8 +109,7 @@ discard block |
||
| 111 | 109 | string $search = '', ?bool $onlyPaid = null, int $page = 0): Collection |
| 112 | 110 | { |
| 113 | 111 | $billRelation = $this->getBillRelation($charge); |
| 114 | - $billRelations = !$charge->is_variable ? [$billRelation . '.member', 'settlement'] : |
|
| 115 | - ['libre_bill.session', 'libre_bill.member', 'settlement']; |
|
| 112 | + $billRelations = !$charge->is_variable ? [$billRelation . '.member', 'settlement'] : ['libre_bill.session', 'libre_bill.member', 'settlement']; |
|
| 116 | 113 | $query = $this->getBillsQuery($charge, $session, $billRelation, $search, $onlyPaid); |
| 117 | 114 | |
| 118 | 115 | return $query->with($billRelations) |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public function checkPoolsSubscriptions() |
| 85 | 85 | { |
| 86 | - if($this->tenantService->round()->pools()->whereDoesntHave('subscriptions')->count() > 0) |
|
| 86 | + if ($this->tenantService->round()->pools()->whereDoesntHave('subscriptions')->count() > 0) |
|
| 87 | 87 | { |
| 88 | 88 | throw new MessageException(trans('tontine.errors.action') . |
| 89 | 89 | '<br/>' . trans('tontine.pool.errors.no_subscription')); |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | public function openSession(Session $session) |
| 131 | 131 | { |
| 132 | - if($session->opened) |
|
| 132 | + if ($session->opened) |
|
| 133 | 133 | { |
| 134 | 134 | return; |
| 135 | 135 | } |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | public function addSettlement(int $billId) |
| 118 | 118 | { |
| 119 | - if($this->session->closed) |
|
| 119 | + if ($this->session->closed) |
|
| 120 | 120 | { |
| 121 | 121 | $this->notify->warning(trans('meeting.warnings.session.closed')); |
| 122 | 122 | return $this->response; |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | public function delSettlement(int $billId) |
| 137 | 137 | { |
| 138 | - if($this->session->closed) |
|
| 138 | + if ($this->session->closed) |
|
| 139 | 139 | { |
| 140 | 140 | $this->notify->warning(trans('meeting.warnings.session.closed')); |
| 141 | 141 | return $this->response; |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | public function addSettlement(int $billId) |
| 124 | 124 | { |
| 125 | - if($this->session->closed) |
|
| 125 | + if ($this->session->closed) |
|
| 126 | 126 | { |
| 127 | 127 | $this->notify->warning(trans('meeting.warnings.session.closed')); |
| 128 | 128 | return $this->response; |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | public function delSettlement(int $billId) |
| 146 | 146 | { |
| 147 | - if($this->session->closed) |
|
| 147 | + if ($this->session->closed) |
|
| 148 | 148 | { |
| 149 | 149 | $this->notify->warning(trans('meeting.warnings.session.closed')); |
| 150 | 150 | return $this->response; |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | public function addAllSettlements() |
| 166 | 166 | { |
| 167 | - if($this->session->closed) |
|
| 167 | + if ($this->session->closed) |
|
| 168 | 168 | { |
| 169 | 169 | $this->notify->warning(trans('meeting.warnings.session.closed')); |
| 170 | 170 | return $this->response; |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | public function delAllSettlements() |
| 186 | 186 | { |
| 187 | - if($this->session->closed) |
|
| 187 | + if ($this->session->closed) |
|
| 188 | 188 | { |
| 189 | 189 | $this->notify->warning(trans('meeting.warnings.session.closed')); |
| 190 | 190 | return $this->response; |
@@ -113,13 +113,13 @@ discard block |
||
| 113 | 113 | { |
| 114 | 114 | // When the remitments are planned, don't create a subscription |
| 115 | 115 | // if receivables already exist on the pool. |
| 116 | - if($pool->remit_planned && |
|
| 116 | + if ($pool->remit_planned && |
|
| 117 | 117 | $pool->subscriptions()->whereHas('receivables')->count() > 0) |
| 118 | 118 | { |
| 119 | 119 | throw new MessageException(trans('tontine.subscription.errors.create')); |
| 120 | 120 | } |
| 121 | 121 | // Enforce unique subscription per member in pool with libre deposit amount. |
| 122 | - if(!$pool->deposit_fixed && |
|
| 122 | + if (!$pool->deposit_fixed && |
|
| 123 | 123 | $pool->subscriptions()->where('member_id', $memberId)->count() > 0) |
| 124 | 124 | { |
| 125 | 125 | throw new MessageException(trans('tontine.subscription.errors.create')); |
@@ -149,18 +149,18 @@ discard block |
||
| 149 | 149 | { |
| 150 | 150 | // When the remitments are planned, don't delete a subscription |
| 151 | 151 | // if receivables already exist on the pool. |
| 152 | - if($pool->remit_planned && |
|
| 152 | + if ($pool->remit_planned && |
|
| 153 | 153 | $pool->subscriptions()->whereHas('receivables')->count() > 0) |
| 154 | 154 | { |
| 155 | 155 | throw new MessageException(trans('tontine.subscription.errors.delete')); |
| 156 | 156 | } |
| 157 | 157 | $subscription = $pool->subscriptions()->where('member_id', $memberId) |
| 158 | 158 | ->with(['payable', 'payable.remitment'])->first(); |
| 159 | - if(!$subscription) |
|
| 159 | + if (!$subscription) |
|
| 160 | 160 | { |
| 161 | 161 | throw new MessageException(trans('tontine.subscription.errors.not_found')); |
| 162 | 162 | } |
| 163 | - if($subscription->payable->remitment !== null) |
|
| 163 | + if ($subscription->payable->remitment !== null) |
|
| 164 | 164 | { |
| 165 | 165 | throw new MessageException(trans('tontine.subscription.errors.delete')); |
| 166 | 166 | } |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | public function unsetPayableSession(Subscription $subscription) |
| 206 | 206 | { |
| 207 | - if(($subscription->payable->session_id)) |
|
| 207 | + if (($subscription->payable->session_id)) |
|
| 208 | 208 | { |
| 209 | 209 | $subscription->payable->session()->dissociate(); |
| 210 | 210 | $subscription->payable->save(); |
@@ -226,10 +226,10 @@ discard block |
||
| 226 | 226 | { |
| 227 | 227 | $session = $this->tenantService->getSession($sessionId); |
| 228 | 228 | $currSubscription = null; |
| 229 | - if($currSubscriptionId > 0) |
|
| 229 | + if ($currSubscriptionId > 0) |
|
| 230 | 230 | { |
| 231 | 231 | $currSubscription = $pool->subscriptions()->find($currSubscriptionId); |
| 232 | - if(($currSubscription !== null && $currSubscription->payable !== null && |
|
| 232 | + if (($currSubscription !== null && $currSubscription->payable !== null && |
|
| 233 | 233 | $currSubscription->payable->remitment !== null) || $session->closed) |
| 234 | 234 | { |
| 235 | 235 | // Can't chage the beneficiary if the session is closed or if |
@@ -242,12 +242,12 @@ discard block |
||
| 242 | 242 | |
| 243 | 243 | DB::transaction(function() use($session, $currSubscription, $nextSubscription) { |
| 244 | 244 | // If the beneficiary already has a session assigned, first remove it. |
| 245 | - if($currSubscription !== null) |
|
| 245 | + if ($currSubscription !== null) |
|
| 246 | 246 | { |
| 247 | 247 | $this->unsetPayableSession($currSubscription); |
| 248 | 248 | } |
| 249 | 249 | // If there is a new session assigned to the beneficiary, then save it. |
| 250 | - if($nextSubscription !== null) |
|
| 250 | + if ($nextSubscription !== null) |
|
| 251 | 251 | { |
| 252 | 252 | $this->setPayableSession($nextSubscription, $session); |
| 253 | 253 | } |
@@ -55,12 +55,12 @@ |
||
| 55 | 55 | protected function pageNumber(int $pageNumber, int $itemCount, string $bagName, string $attrName = 'page'): array |
| 56 | 56 | { |
| 57 | 57 | $perPage = 10; |
| 58 | - $pageCount = (int)floor($itemCount / $perPage) + ($itemCount % $perPage > 0 ? 1 : 0); |
|
| 59 | - if($pageNumber < 1) |
|
| 58 | + $pageCount = (int) floor($itemCount / $perPage) + ($itemCount % $perPage > 0 ? 1 : 0); |
|
| 59 | + if ($pageNumber < 1) |
|
| 60 | 60 | { |
| 61 | 61 | $pageNumber = $this->bag($bagName)->get($attrName, 1); |
| 62 | 62 | } |
| 63 | - if($pageNumber > $pageCount) |
|
| 63 | + if ($pageNumber > $pageCount) |
|
| 64 | 64 | { |
| 65 | 65 | $pageNumber = $pageCount; |
| 66 | 66 | } |