Passed
Pull Request — main (#49)
by Thierry
14:14
created
src/Service/Traits/EventTrait.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -97,13 +97,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
                 }
Please login to merge, or discard this patch.
src/Service/Meeting/Charge/BillService.php 1 patch
Spacing   +2 added lines, -5 removed lines patch added patch discarded remove patch
@@ -93,9 +93,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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)
Please login to merge, or discard this patch.
src/Service/Meeting/Charge/SettlementService.php 1 patch
Spacing   +11 added lines, -13 removed lines patch added patch discarded remove patch
@@ -62,19 +62,19 @@  discard block
 block discarded – undo
62 62
         // The select('bills.*') is important here, otherwise Eloquent overrides the
63 63
         // Bill model id fields with those of another model, then making the dataset incorrect.
64 64
         $query = Bill::select('bills.*');
65
-        if($charge->is_variable)
65
+        if ($charge->is_variable)
66 66
         {
67 67
             return $query->join('libre_bills', 'libre_bills.bill_id', '=', 'bills.id')
68 68
                 ->where('libre_bills.charge_id', $charge->id)
69 69
                 ->where('libre_bills.session_id', $session->id);
70 70
         }
71
-        if($charge->period_session)
71
+        if ($charge->period_session)
72 72
         {
73 73
             return $query->join('session_bills', 'session_bills.bill_id', '=', 'bills.id')
74 74
                 ->where('session_bills.charge_id', $charge->id)
75 75
                 ->where('session_bills.session_id', $session->id);
76 76
         }
77
-        if($charge->period_round)
77
+        if ($charge->period_round)
78 78
         {
79 79
             return $query->join('round_bills', 'round_bills.bill_id', '=', 'bills.id')
80 80
                 ->where('round_bills.charge_id', $charge->id);
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
     {
98 98
         $bill = $this->getQuery($charge, $session)->with('settlement')->find($billId);
99 99
         // Return if the bill is not found or the bill is already settled.
100
-        if(!$bill || ($bill->settlement))
100
+        if (!$bill || ($bill->settlement))
101 101
         {
102 102
             throw new MessageException(trans('tontine.bill.errors.not_found'));
103 103
         }
@@ -120,11 +120,11 @@  discard block
 block discarded – undo
120 120
     {
121 121
         $bill = $this->getQuery($charge, $session)->with('settlement')->find($billId);
122 122
         // Return if the bill is not found or the bill is not settled.
123
-        if(!$bill || !($bill->settlement))
123
+        if (!$bill || !($bill->settlement))
124 124
         {
125 125
             throw new MessageException(trans('tontine.bill.errors.not_found'));
126 126
         }
127
-        if(($bill->settlement->online))
127
+        if (($bill->settlement->online))
128 128
         {
129 129
             throw new MessageException(trans('tontine.bill.errors.online'));
130 130
         }
@@ -142,13 +142,13 @@  discard block
 block discarded – undo
142 142
     public function createAllSettlements(Charge $charge, Session $session): void
143 143
     {
144 144
         $bills = $this->getQuery($charge, $session)->whereDoesntHave('settlement')->get();
145
-        if($bills->count() === 0)
145
+        if ($bills->count() === 0)
146 146
         {
147 147
             return;
148 148
         }
149 149
 
150 150
         DB::transaction(function() use($bills, $session) {
151
-            foreach($bills as $bill)
151
+            foreach ($bills as $bill)
152 152
             {
153 153
                 $settlement = new Settlement();
154 154
                 $settlement->bill()->associate($bill);
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
             ->filter(function($bill) {
175 175
                 return !$bill->settlement->online;
176 176
             });
177
-        if($bills->count() === 0)
177
+        if ($bills->count() === 0)
178 178
         {
179 179
             return;
180 180
         }
181 181
         DB::transaction(function() use($bills, $session) {
182
-            foreach($bills as $bill)
182
+            foreach ($bills as $bill)
183 183
             {
184 184
                 $bill->settlement()->where('session_id', $session->id)->delete();
185 185
             }
@@ -194,9 +194,7 @@  discard block
 block discarded – undo
194 194
      */
195 195
     public function getSettlement(Charge $charge, Session $session): object
196 196
     {
197
-        $billTable = $charge->is_variable ? 'libre_bills' :
198
-            ($charge->period_session ? 'session_bills' :
199
-            ($charge->period_round ? 'round_bills' : 'tontine_bills'));
197
+        $billTable = $charge->is_variable ? 'libre_bills' : ($charge->period_session ? 'session_bills' : ($charge->period_round ? 'round_bills' : 'tontine_bills'));
200 198
 
201 199
         return DB::table('settlements')
202 200
             ->select(DB::raw('count(*) as total'), DB::raw('sum(bills.amount) as amount'))
Please login to merge, or discard this patch.
src/Service/Meeting/Charge/LibreFeeService.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -265,12 +265,12 @@  discard block
 block discarded – undo
265 265
         int $memberId, bool $paid, float $amount = 0): void
266 266
     {
267 267
         $member = $this->tenantService->tontine()->members()->find($memberId);
268
-        if(!$member)
268
+        if (!$member)
269 269
         {
270 270
             throw new MessageException(trans('tontine.member.errors.not_found'));
271 271
         }
272 272
 
273
-        if($amount !== 0)
273
+        if ($amount !== 0)
274 274
         {
275 275
             $amount = $this->localeService->convertMoneyToInt($amount);
276 276
         }
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
             $libreBill->session()->associate($session);
288 288
             $libreBill->bill()->associate($bill);
289 289
             $libreBill->save();
290
-            if($paid)
290
+            if ($paid)
291 291
             {
292 292
                 $settlement = new Settlement();
293 293
                 $settlement->bill()->associate($bill);
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
      */
307 307
     public function getBill(Charge $charge, Session $session, int $memberId): ?LibreBill
308 308
     {
309
-        if(!($member = $this->tenantService->tontine()->members()->find($memberId)))
309
+        if (!($member = $this->tenantService->tontine()->members()->find($memberId)))
310 310
         {
311 311
             throw new MessageException(trans('tontine.member.errors.not_found'));
312 312
         }
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
      */
329 329
     public function updateBill(Charge $charge, Session $session, int $memberId, float $amount): void
330 330
     {
331
-        if(!($libreBill = $this->getBill($charge, $session, $memberId)))
331
+        if (!($libreBill = $this->getBill($charge, $session, $memberId)))
332 332
         {
333 333
             return; // throw new MessageException(trans('tontine.bill.errors.not_found'));
334 334
         }
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
      */
348 348
     public function deleteBill(Charge $charge, Session $session, int $memberId): void
349 349
     {
350
-        if(!($libreBill = $this->getBill($charge, $session, $memberId)))
350
+        if (!($libreBill = $this->getBill($charge, $session, $memberId)))
351 351
         {
352 352
             return; // throw new MessageException(trans('tontine.bill.errors.not_found'));
353 353
         }
@@ -355,10 +355,10 @@  discard block
 block discarded – undo
355 355
         DB::transaction(function() use($libreBill, $session) {
356 356
             $bill = $libreBill->bill;
357 357
             $libreBill->delete();
358
-            if($bill !== null)
358
+            if ($bill !== null)
359 359
             {
360 360
                 // Delete the settlement only if it is on the same session
361
-                if($bill->settlement !== null && $bill->settlement->session_id === $session->id)
361
+                if ($bill->settlement !== null && $bill->settlement->session_id === $session->id)
362 362
                 {
363 363
                     $bill->settlement->delete();
364 364
                 }
Please login to merge, or discard this patch.
src/Service/Meeting/SessionService.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
src/Service/Report/SessionService.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
      */
120 120
     public function getDisbursedAmounts(Collection $chargeIds, Collection $sessionIds): Collection
121 121
     {
122
-        if($chargeIds->count() === 0)
122
+        if ($chargeIds->count() === 0)
123 123
         {
124 124
             return collect();
125 125
         }
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
         // value can be retrieved forever, even when the membership will change.
223 223
         $tontine = $this->tenantService->tontine();
224 224
         $round = $this->tenantService->round();
225
-        if($round->property === null)
225
+        if ($round->property === null)
226 226
         {
227 227
             // Create and save the property with the content
228 228
             $memberIds = $tontine->members()->active()->pluck('id')->all();
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
         }
233 233
 
234 234
         $content = $round->property->content;
235
-        if(isset($content['members']) && is_array($content['members']))
235
+        if (isset($content['members']) && is_array($content['members']))
236 236
         {
237 237
             // Return the existing content value
238 238
             return count($content['members']);
@@ -264,12 +264,12 @@  discard block
 block discarded – undo
264 264
         };
265 265
         $bills = $this->getBills($settlementFilter, $member);
266 266
         $disbursements = $this->getDisbursedAmounts($charges->pluck('id'), $sessionIds);
267
-        if($member !== null)
267
+        if ($member !== null)
268 268
         {
269 269
             // The disbursement part of each member id calculated by dividing each amount
270 270
             // by the number of members.
271 271
             $memberCount = $this->countActiveMembers();
272
-            foreach($disbursements as $disbursement)
272
+            foreach ($disbursements as $disbursement)
273 273
             {
274 274
                 $disbursement->total_amount /= $memberCount;
275 275
             }
@@ -297,11 +297,11 @@  discard block
 block discarded – undo
297 297
             ->select(DB::raw("sum($principal) as principal"), DB::raw("sum($interest) as interest"))
298 298
             ->where('loans.session_id', $session->id)
299 299
             ->first();
300
-        if(!$loan->principal)
300
+        if (!$loan->principal)
301 301
         {
302 302
             $loan->principal = 0;
303 303
         }
304
-        if(!$loan->interest)
304
+        if (!$loan->interest)
305 305
         {
306 306
             $loan->interest = 0;
307 307
         }
@@ -323,11 +323,11 @@  discard block
 block discarded – undo
323 323
             ->select(DB::raw("sum($principal) as principal"), DB::raw("sum($interest) as interest"))
324 324
             ->where('refunds.session_id', $session->id)
325 325
             ->first();
326
-        if(!$refund->principal)
326
+        if (!$refund->principal)
327 327
         {
328 328
             $refund->principal = 0;
329 329
         }
330
-        if(!$refund->interest)
330
+        if (!$refund->interest)
331 331
         {
332 332
             $refund->interest = 0;
333 333
         }
@@ -346,11 +346,11 @@  discard block
 block discarded – undo
346 346
             ->select(DB::raw('sum(amount) as total_amount'), DB::raw('count(id) as total_count'))
347 347
             ->where('session_id', $session->id)
348 348
             ->first();
349
-        if(!$funding->total_amount)
349
+        if (!$funding->total_amount)
350 350
         {
351 351
             $funding->total_amount = 0;
352 352
         }
353
-        if(!$funding->total_count)
353
+        if (!$funding->total_count)
354 354
         {
355 355
             $funding->total_count = 0;
356 356
         }
@@ -369,11 +369,11 @@  discard block
 block discarded – undo
369 369
             ->select(DB::raw('sum(amount) as total_amount'), DB::raw('count(id) as total_count'))
370 370
             ->where('session_id', $session->id)
371 371
             ->first();
372
-        if(!$disbursement->total_amount)
372
+        if (!$disbursement->total_amount)
373 373
         {
374 374
             $disbursement->total_amount = 0;
375 375
         }
376
-        if(!$disbursement->total_count)
376
+        if (!$disbursement->total_count)
377 377
         {
378 378
             $disbursement->total_count = 0;
379 379
         }
Please login to merge, or discard this patch.
app/Ajax/Web/Meeting/Charge/Libre/Member.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -145,18 +145,18 @@  discard block
 block discarded – undo
145 145
      */
146 146
     public function addBill(int $memberId, bool $paid, string $amount = '')
147 147
     {
148
-        if($this->session->closed)
148
+        if ($this->session->closed)
149 149
         {
150 150
             $this->notify->warning(trans('meeting.warnings.session.closed'));
151 151
             return $this->response;
152 152
         }
153 153
         $amount = str_replace(',', '.', trim($amount));
154
-        if($amount !== '' && filter_var($amount, FILTER_VALIDATE_FLOAT) === false)
154
+        if ($amount !== '' && filter_var($amount, FILTER_VALIDATE_FLOAT) === false)
155 155
         {
156 156
             $this->notify->error(trans('meeting.errors.amount.invalid', ['amount' => $amount]));
157 157
             return $this->response;
158 158
         }
159
-        $amount = $amount === '' ? 0 : (float)$amount;
159
+        $amount = $amount === '' ? 0 : (float) $amount;
160 160
 
161 161
         $this->feeService->createBill($this->charge, $this->session, $memberId, $paid, $amount);
162 162
 
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
      */
171 171
     public function delBill(int $memberId)
172 172
     {
173
-        if($this->session->closed)
173
+        if ($this->session->closed)
174 174
         {
175 175
             $this->notify->warning(trans('meeting.warnings.session.closed'));
176 176
             return $this->response;
@@ -189,13 +189,13 @@  discard block
 block discarded – undo
189 189
      */
190 190
     public function editBill(int $memberId)
191 191
     {
192
-        if($this->session->closed)
192
+        if ($this->session->closed)
193 193
         {
194 194
             $this->notify->warning(trans('meeting.warnings.session.closed'));
195 195
             return $this->response;
196 196
         }
197 197
         $bill = $this->feeService->getBill($this->charge, $this->session, $memberId);
198
-        if($bill === null || $bill->bill->settlement !== null)
198
+        if ($bill === null || $bill->bill->settlement !== null)
199 199
         {
200 200
             return $this->page();
201 201
         }
@@ -222,21 +222,21 @@  discard block
 block discarded – undo
222 222
      */
223 223
     public function saveBill(int $memberId, string $amount)
224 224
     {
225
-        if($this->session->closed)
225
+        if ($this->session->closed)
226 226
         {
227 227
             $this->notify->warning(trans('meeting.warnings.session.closed'));
228 228
             return $this->response;
229 229
         }
230 230
 
231 231
         $amount = str_replace(',', '.', trim($amount));
232
-        if($amount !== '' && filter_var($amount, FILTER_VALIDATE_FLOAT) === false)
232
+        if ($amount !== '' && filter_var($amount, FILTER_VALIDATE_FLOAT) === false)
233 233
         {
234 234
             $this->notify->error(trans('meeting.errors.amount.invalid', ['amount' => $amount]));
235 235
             return $this->response;
236 236
         }
237
-        $amount = $amount === '' ? 0 : (float)$amount;
237
+        $amount = $amount === '' ? 0 : (float) $amount;
238 238
 
239
-        if(!$amount)
239
+        if (!$amount)
240 240
         {
241 241
             $this->feeService->deleteBill($this->charge, $this->session, $memberId);
242 242
             return $this->page();
Please login to merge, or discard this patch.