Passed
Push — main ( 1074e2...00bd25 )
by Thierry
05:52
created
app/Ajax/Web/Meeting/Credit/PartialRefund.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 
84 84
     public function addRefund()
85 85
     {
86
-        if($this->session->closed)
86
+        if ($this->session->closed)
87 87
         {
88 88
             $this->notify->warning(trans('meeting.warnings.session.closed'));
89 89
             return $this->response;
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
             'title' => trans('common.actions.cancel'),
98 98
             'class' => 'btn btn-tertiary',
99 99
             'click' => 'close',
100
-        ],[
100
+        ], [
101 101
             'title' => trans('common.actions.save'),
102 102
             'class' => 'btn btn-primary',
103 103
             'click' => $this->rq()->createRefund(pm()->form('refund-form')),
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
      */
114 114
     public function createRefund(array $formValues)
115 115
     {
116
-        if($this->session->closed)
116
+        if ($this->session->closed)
117 117
         {
118 118
             $this->notify->warning(trans('meeting.warnings.session.closed'));
119 119
             return $this->response;
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 
122 122
         $values = $this->validator->validateItem($formValues);
123 123
         $debt = $this->refundService->getDebt($values['debt']);
124
-        if(!$debt)
124
+        if (!$debt)
125 125
         {
126 126
             $this->notify->warning(trans('meeting.loan.errors.not_found'));
127 127
             return $this->response;
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 
140 140
     public function editRefund(int $refundId)
141 141
     {
142
-        if($this->session->closed)
142
+        if ($this->session->closed)
143 143
         {
144 144
             $this->notify->warning(trans('meeting.warnings.session.closed'));
145 145
             return $this->response;
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
             'title' => trans('common.actions.cancel'),
156 156
             'class' => 'btn btn-tertiary',
157 157
             'click' => 'close',
158
-        ],[
158
+        ], [
159 159
             'title' => trans('common.actions.save'),
160 160
             'class' => 'btn btn-primary',
161 161
             'click' => $this->rq()->updateRefund($refundId, pm()->form('refund-form')),
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
      */
172 172
     public function updateRefund(int $refundId, array $formValues)
173 173
     {
174
-        if($this->session->closed)
174
+        if ($this->session->closed)
175 175
         {
176 176
             $this->notify->warning(trans('meeting.warnings.session.closed'));
177 177
             return $this->response;
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
      */
196 196
     public function deleteRefund(int $refundId)
197 197
     {
198
-        if($this->session->closed)
198
+        if ($this->session->closed)
199 199
         {
200 200
             $this->notify->warning(trans('meeting.warnings.session.closed'));
201 201
             return $this->response;
Please login to merge, or discard this patch.
src/Service/Meeting/Credit/RefundService.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
      *
46 46
      * @return Builder|Relation
47 47
      */
48
-    private function getDebtsQuery(Session $session, Fund $fund, ?bool $onlyPaid): Builder|Relation
48
+    private function getDebtsQuery(Session $session, Fund $fund, ?bool $onlyPaid): Builder | Relation
49 49
     {
50 50
         $prevSessions = $this->fundService->getFundSessionIds($session, $fund)
51 51
             ->filter(fn(int $sessionId) => $sessionId !== $session->id);
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
                         $query->where('session_id', $session->id);
67 67
                     });
68 68
                 });
69
-                if($prevSessions->count() === 0)
69
+                if ($prevSessions->count() === 0)
70 70
                 {
71 71
                     return;
72 72
                 }
@@ -167,13 +167,13 @@  discard block
 block discarded – undo
167 167
     {
168 168
         // Already refunded
169 169
         // Cannot refund the principal debt in the same session.
170
-        if(!$session->opened || $debt->refund !== null ||
170
+        if (!$session->opened || $debt->refund !== null ||
171 171
             $debt->is_principal && $debt->loan->session->id === $session->id)
172 172
         {
173 173
             return false;
174 174
         }
175 175
         // Cannot refund the interest debt before the principal.
176
-        if($debt->is_interest && !$debt->loan->fixed_interest)
176
+        if ($debt->is_interest && !$debt->loan->fixed_interest)
177 177
         {
178 178
             return $debt->loan->principal_debt->refund !== null;
179 179
         }
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
      */
194 194
     public function createRefund(Debt $debt, Session $session): void
195 195
     {
196
-        if(!$this->canCreateRefund($debt, $session))
196
+        if (!$this->canCreateRefund($debt, $session))
197 197
         {
198 198
             throw new MessageException(trans('meeting.refund.errors.cannot_refund'));
199 199
         }
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
         DB::transaction(function() use($debt, $session, $refund) {
205 205
             $refund->save();
206 206
             // For simple or compound interest, also save the final amount.
207
-            if($debt->is_interest && !$debt->loan->fixed_interest)
207
+            if ($debt->is_interest && !$debt->loan->fixed_interest)
208 208
             {
209 209
                 $debt->amount = $this->debtCalculator->getDebtDueAmount($debt, $session, true);
210 210
                 $debt->save();
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
     private function canDeleteRefund(Debt $debt, Session $session): bool
222 222
     {
223 223
         // A refund can only be deleted in the same session it was created.
224
-        if(!$session->opened || !$debt->refund || $debt->refund->session_id !== $session->id)
224
+        if (!$session->opened || !$debt->refund || $debt->refund->session_id !== $session->id)
225 225
         {
226 226
             return false;
227 227
         }
@@ -239,11 +239,11 @@  discard block
 block discarded – undo
239 239
      */
240 240
     public function deleteRefund(Debt $debt, Session $session): void
241 241
     {
242
-        if(!$this->canDeleteRefund($debt, $session))
242
+        if (!$this->canDeleteRefund($debt, $session))
243 243
         {
244 244
             throw new MessageException(trans('meeting.refund.errors.cannot_refund'));
245 245
         }
246
-        if(!$this->paymentService->isEditable($debt->refund))
246
+        if (!$this->paymentService->isEditable($debt->refund))
247 247
         {
248 248
             throw new MessageException(trans('meeting.refund.errors.cannot_delete'));
249 249
         }
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
     private function canCreatePartialRefund(Debt $debt, Session $session): bool
307 307
     {
308 308
         // Cannot refund the principal debt in the same session.
309
-        if(!$session->opened || $debt->refund !== null ||
309
+        if (!$session->opened || $debt->refund !== null ||
310 310
             ($debt->is_principal && $debt->loan->session->id === $session->id))
311 311
         {
312 312
             return false;
@@ -366,12 +366,12 @@  discard block
 block discarded – undo
366 366
      */
367 367
     public function createPartialRefund(Debt $debt, Session $session, int $amount): void
368 368
     {
369
-        if(!$this->canCreatePartialRefund($debt, $session))
369
+        if (!$this->canCreatePartialRefund($debt, $session))
370 370
         {
371 371
             throw new MessageException(trans('meeting.refund.errors.cannot_delete'));
372 372
         }
373 373
         // A partial refund must not totally refund a debt
374
-        if($amount >= $this->debtCalculator->getDebtPayableAmount($debt, $session))
374
+        if ($amount >= $this->debtCalculator->getDebtPayableAmount($debt, $session))
375 375
         {
376 376
             throw new MessageException(trans('meeting.refund.errors.pr_amount'));
377 377
         }
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
     private function canDeletePartialRefund(PartialRefund $refund, Session $session): bool
393 393
     {
394 394
         // A partial refund cannot be deleted if the debt is already refunded.
395
-        if(!$session->opened || $refund->debt->refund !== null)
395
+        if (!$session->opened || $refund->debt->refund !== null)
396 396
         {
397 397
             return false;
398 398
         }
@@ -412,11 +412,11 @@  discard block
 block discarded – undo
412 412
     {
413 413
         $refund = PartialRefund::where('session_id', $session->id)
414 414
             ->with(['debt.refund'])->find($refundId);
415
-        if(!$refund)
415
+        if (!$refund)
416 416
         {
417 417
             throw new MessageException(trans('meeting.refund.errors.not_found'));
418 418
         }
419
-        if($refund->debt->refund !== null || !$this->paymentService->isEditable($refund))
419
+        if ($refund->debt->refund !== null || !$this->paymentService->isEditable($refund))
420 420
         {
421 421
             throw new MessageException(trans('meeting.refund.errors.cannot_delete'));
422 422
         }
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
     {
437 437
         $refund = $this->getPartialRefund($session, $refundId);
438 438
         // A partial refund must not totally refund a debt
439
-        if($amount >= $this->debtCalculator->getDebtPayableAmount($refund->debt, $session))
439
+        if ($amount >= $this->debtCalculator->getDebtPayableAmount($refund->debt, $session))
440 440
         {
441 441
             throw new MessageException(trans('meeting.refund.errors.pr_amount'));
442 442
         }
Please login to merge, or discard this patch.
src/Service/Meeting/Credit/DebtCalculator.php 1 patch
Spacing   +16 added lines, -19 removed lines patch added patch discarded remove patch
@@ -60,10 +60,10 @@  discard block
 block discarded – undo
60 60
     private function getRefundFilter(Session $current, bool $withCurrent): Closure
61 61
     {
62 62
         return $withCurrent ?
63
-            function(PartialRefund|Refund $refund) use($current) {
63
+            function(PartialRefund | Refund $refund) use($current) {
64 64
                 return $refund->session->start_at <= $current->start_at;
65 65
             } :
66
-            function(PartialRefund|Refund $refund) use($current) {
66
+            function(PartialRefund | Refund $refund) use($current) {
67 67
                 return $refund->session->start_at < $current->start_at;
68 68
             };
69 69
     }
@@ -121,10 +121,10 @@  discard block
 block discarded – undo
121 121
         // Take refunds before the end session and sort by session date.
122 122
         $partialRefunds = $this->getPartialRefunds($principalDebt, $endSession, false)
123 123
             ->sortBy('session.start_at');
124
-        foreach($partialRefunds as $refund)
124
+        foreach ($partialRefunds as $refund)
125 125
         {
126 126
             $sessionCount = $this->getSessionCount($startSession, $refund->session);
127
-            $interestAmount += (int)($loanAmount * $interestRate * $sessionCount);
127
+            $interestAmount += (int) ($loanAmount * $interestRate * $sessionCount);
128 128
             // For the next loop
129 129
             $loanAmount -= $refund->amount;
130 130
             $startSession = $refund->session;
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
         $lastSession = $this->getLastSession($principalDebt, $endSession);
134 134
         $sessionCount = $this->getSessionCount($startSession, $lastSession);
135 135
 
136
-        return $interestAmount + (int)($loanAmount * $interestRate * $sessionCount);
136
+        return $interestAmount + (int) ($loanAmount * $interestRate * $sessionCount);
137 137
     }
138 138
 
139 139
     /**
@@ -158,10 +158,10 @@  discard block
 block discarded – undo
158 158
         // Take refunds before the current session and sort by session date.
159 159
         $partialRefunds = $this->getPartialRefunds($principalDebt, $endSession, false)
160 160
             ->sortBy('session.start_at');
161
-        foreach($partialRefunds as $refund)
161
+        foreach ($partialRefunds as $refund)
162 162
         {
163 163
             $sessionCount = $this->getSessionCount($startSession, $refund->session);
164
-            $interestAmount += (int)($loanAmount * (pow(1 + $interestRate, $sessionCount) - 1));
164
+            $interestAmount += (int) ($loanAmount * (pow(1 + $interestRate, $sessionCount) - 1));
165 165
             // For the next loop
166 166
             $loanAmount -= $refund->amount - $interestAmount;
167 167
             $startSession = $refund->session;
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
         $lastSession = $this->getLastSession($principalDebt, $endSession);
171 171
         $sessionCount = $this->getSessionCount($startSession, $lastSession);
172 172
 
173
-        return $interestAmount + (int)($loanAmount * (pow(1 + $interestRate, $sessionCount) - 1));
173
+        return $interestAmount + (int) ($loanAmount * (pow(1 + $interestRate, $sessionCount) - 1));
174 174
     }
175 175
 
176 176
     /**
@@ -183,14 +183,13 @@  discard block
 block discarded – undo
183 183
      */
184 184
     public function getDebtAmount(Debt $debt, Session $session): int
185 185
     {
186
-        if($debt->is_principal || $debt->refund || $debt->loan->fixed_interest)
186
+        if ($debt->is_principal || $debt->refund || $debt->loan->fixed_interest)
187 187
         {
188 188
             return $debt->amount;
189 189
         }
190 190
 
191 191
         return $debt->loan->simple_interest ?
192
-            $this->getSimpleInterestAmount($debt, $session) :
193
-            $this->getCompoundInterestAmount($debt, $session);
192
+            $this->getSimpleInterestAmount($debt, $session) : $this->getCompoundInterestAmount($debt, $session);
194 193
     }
195 194
 
196 195
     /**
@@ -203,8 +202,7 @@  discard block
 block discarded – undo
203 202
      */
204 203
     public function getDebtPaidAmount(Debt $debt, Session $session): int
205 204
     {
206
-        return $debt->refund !== null ? $debt->amount :
207
-            $this->getPartialRefunds($debt, $session, true)->sum('amount');
205
+        return $debt->refund !== null ? $debt->amount : $this->getPartialRefunds($debt, $session, true)->sum('amount');
208 206
     }
209 207
 
210 208
     /**
@@ -247,13 +245,13 @@  discard block
 block discarded – undo
247 245
      */
248 246
     public function getDebtPayableAmount(Debt $debt, Session $session): int
249 247
     {
250
-        if($debt->refund !== null)
248
+        if ($debt->refund !== null)
251 249
         {
252 250
             return 0;
253 251
         }
254 252
 
255 253
         $partialRefundAmount = $debt->partial_refunds()->sum('amount');
256
-        if($debt->is_principal || $debt->loan->fixed_interest)
254
+        if ($debt->is_principal || $debt->loan->fixed_interest)
257 255
         {
258 256
             return $debt->amount - $partialRefundAmount;
259 257
         }
@@ -262,7 +260,7 @@  discard block
 block discarded – undo
262 260
         // must take into account any partial refund after the current session.
263 261
         $currentDebtAmount = $this->getDebtAmount($debt, $session);
264 262
         $nextPartialRefunds = $this->getNextPartialRefunds($debt, $session);
265
-        if($nextPartialRefunds->count() === 0)
263
+        if ($nextPartialRefunds->count() === 0)
266 264
         {
267 265
             return $currentDebtAmount - $partialRefundAmount;
268 266
         }
@@ -272,8 +270,7 @@  discard block
 block discarded – undo
272 270
         $addedRefund = $nextPartialRefunds->sum('amount');
273 271
 
274 272
         return $addedRefund < $addedDebt ?
275
-            $currentDebtAmount - $partialRefundAmount :
276
-            $currentDebtAmount - $partialRefundAmount - $addedRefund + $addedDebt;
273
+            $currentDebtAmount - $partialRefundAmount : $currentDebtAmount - $partialRefundAmount - $addedRefund + $addedDebt;
277 274
     }
278 275
 
279 276
     /**
@@ -288,7 +285,7 @@  discard block
 block discarded – undo
288 285
     public function getDebtDueAmount(Debt $debt, Session $session, bool $withCurrent): int
289 286
     {
290 287
         $refundFilter = $this->getRefundFilter($session, $withCurrent);
291
-        if($debt->refund !== null && $refundFilter($debt->refund))
288
+        if ($debt->refund !== null && $refundFilter($debt->refund))
292 289
         {
293 290
             return 0; // The debt was refunded before the current session.
294 291
         }
Please login to merge, or discard this patch.
src/Service/Report/ReportService.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -183,7 +183,7 @@
 block discarded – undo
183 183
      */
184 184
     private function setDebtAmount(Loan $loan, Session $session)
185 185
     {
186
-        if(($debt = $loan->i_debt) !== null)
186
+        if (($debt = $loan->i_debt) !== null)
187 187
         {
188 188
             $loan->iDebtAmount = $this->debtCalculator->getDebtAmount($debt, $session);
189 189
         }
Please login to merge, or discard this patch.