Conditions | 18 |
Paths | 18710 |
Total Lines | 232 |
Code Lines | 150 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
161 | public function store(Request $request) |
||
162 | { |
||
163 | // Member Model Validation |
||
164 | $this->validate($request, ['email' => 'unique:mst_members,email', |
||
165 | 'contact' => 'unique:mst_members,contact', |
||
166 | 'member_code' => 'unique:mst_members,member_code']); |
||
167 | |||
168 | // Start Transaction |
||
169 | DB::beginTransaction(); |
||
170 | |||
171 | try { |
||
172 | // Store member's personal details |
||
173 | $memberData = array('name'=>$request->name, |
||
174 | 'DOB'=> $request->DOB, |
||
175 | 'gender'=> $request->gender, |
||
176 | 'contact'=> $request->contact, |
||
177 | 'emergency_contact'=> $request->emergency_contact, |
||
178 | 'health_issues'=> $request->health_issues, |
||
179 | 'email'=> $request->email, |
||
180 | 'address'=> $request->address, |
||
181 | 'member_id'=> $request->member_id, |
||
182 | 'proof_name'=> $request->proof_name, |
||
183 | 'member_code'=> $request->member_code, |
||
184 | 'status'=> $request->status, |
||
185 | 'pin_code'=> $request->pin_code, |
||
186 | 'occupation'=> $request->occupation, |
||
187 | 'aim'=> $request->aim, |
||
188 | 'source'=> $request->source); |
||
189 | |||
190 | $member = new Member($memberData); |
||
191 | $member->createdBy()->associate(Auth::user()); |
||
192 | $member->updatedBy()->associate(Auth::user()); |
||
193 | $member->save(); |
||
194 | |||
195 | // Adding media i.e. Profile & proof photo |
||
196 | if($request->hasFile('photo')) |
||
197 | { |
||
198 | $member->addMedia($request->file('photo'))->usingFileName('profile_'.$member->id.$request->photo->getClientOriginalExtension())->toCollection('profile'); |
||
199 | } |
||
200 | |||
201 | if($request->hasFile('proof_photo')) |
||
202 | { |
||
203 | $member->addMedia($request->file('proof_photo'))->usingFileName('proof_'.$member->id.$request->proof_photo->getClientOriginalExtension())->toCollection('proof'); |
||
204 | } |
||
205 | |||
206 | // Helper function for calculating payment status |
||
207 | $invoice_total = $request->admission_amount + $request->subscription_amount + $request->taxes_amount - $request->discount_amount; |
||
208 | $paymentStatus = \constPaymentStatus::Unpaid; |
||
209 | $pending = $invoice_total - $request->payment_amount; |
||
210 | |||
211 | if($request->mode == 1) |
||
212 | { |
||
213 | if ($request->payment_amount == $invoice_total) |
||
214 | { |
||
215 | $paymentStatus = \constPaymentStatus::Paid; |
||
216 | } |
||
217 | elseif($request->payment_amount > 0 && $request->payment_amount < $invoice_total) |
||
218 | { |
||
219 | $paymentStatus = \constPaymentStatus::Partial; |
||
220 | } |
||
221 | elseif($request->payment_amount == 0) |
||
222 | { |
||
223 | $paymentStatus = \constPaymentStatus::Unpaid; |
||
224 | } |
||
225 | else |
||
226 | { |
||
227 | $paymentStatus = \constPaymentStatus::Overpaid; |
||
228 | } |
||
229 | } |
||
230 | |||
231 | // Storing Invoice |
||
232 | $invoiceData = array('invoice_number'=> $request->invoice_number, |
||
233 | 'member_id'=> $member->id, |
||
234 | 'total'=> $invoice_total, |
||
235 | 'status'=> $paymentStatus, |
||
236 | 'pending_amount'=> $pending, |
||
237 | 'discount_amount'=> $request->discount_amount, |
||
238 | 'discount_percent'=> $request->discount_percent, |
||
239 | 'discount_note'=> $request->discount_note, |
||
240 | 'tax'=> $request->taxes_amount, |
||
241 | 'additional_fees'=> $request->additional_fees, |
||
242 | 'note'=>' '); |
||
243 | |||
244 | $invoice = new Invoice($invoiceData); |
||
245 | $invoice->createdBy()->associate(Auth::user()); |
||
246 | $invoice->updatedBy()->associate(Auth::user()); |
||
247 | $invoice->save(); |
||
248 | |||
249 | // Storing subscription |
||
250 | foreach($request->plan as $plan) |
||
251 | { |
||
252 | $subscriptionData = array('member_id'=> $member->id, |
||
253 | 'invoice_id'=> $invoice->id, |
||
254 | 'plan_id'=> $plan['id'], |
||
255 | 'start_date'=> $plan['start_date'], |
||
256 | 'end_date'=> $plan['end_date'], |
||
257 | 'status'=> \constSubscription::onGoing, |
||
258 | 'is_renewal'=>'0'); |
||
259 | |||
260 | $subscription = new Subscription($subscriptionData); |
||
261 | $subscription->createdBy()->associate(Auth::user()); |
||
262 | $subscription->updatedBy()->associate(Auth::user()); |
||
263 | $subscription->save(); |
||
264 | |||
265 | //Adding subscription to invoice(Invoice Details) |
||
266 | $detailsData = array('invoice_id'=> $invoice->id, |
||
267 | 'plan_id'=> $plan['id'], |
||
268 | 'item_amount'=> $plan['price']); |
||
269 | |||
270 | $invoice_details = new Invoice_detail($detailsData); |
||
271 | $invoice_details->createdBy()->associate(Auth::user()); |
||
272 | $invoice_details->updatedBy()->associate(Auth::user()); |
||
273 | $invoice_details->save(); |
||
274 | } |
||
275 | |||
276 | // Store Payment Details |
||
277 | $paymentData = array('invoice_id'=> $invoice->id, |
||
278 | 'payment_amount'=> $request->payment_amount, |
||
279 | 'mode'=> $request->mode, |
||
280 | 'note'=> ' '); |
||
281 | |||
282 | $payment_details = new Payment_detail($paymentData); |
||
283 | $payment_details->createdBy()->associate(Auth::user()); |
||
284 | $payment_details->updatedBy()->associate(Auth::user()); |
||
285 | $payment_details->save(); |
||
286 | |||
287 | if($request->mode == 0) |
||
288 | { |
||
289 | // Store Cheque Details |
||
290 | $chequeData = array('payment_id'=> $payment_details->id, |
||
291 | 'number'=> $request->number, |
||
292 | 'date'=> $request->date, |
||
293 | 'status'=> \constChequeStatus::Recieved); |
||
294 | |||
295 | $cheque_details = new Cheque_detail($chequeData); |
||
296 | $cheque_details->createdBy()->associate(Auth::user()); |
||
297 | $cheque_details->updatedBy()->associate(Auth::user()); |
||
298 | $cheque_details->save(); |
||
299 | } |
||
300 | |||
301 | // On member transfer update enquiry Status |
||
302 | if ($request->has('transfer_id')) |
||
303 | { |
||
304 | $enquiry=Enquiry::findOrFail($request->transfer_id); |
||
305 | $enquiry->status = \constEnquiryStatus::Member; |
||
306 | $enquiry->updatedBy()->associate(Auth::user()); |
||
307 | $enquiry->save(); |
||
308 | } |
||
309 | |||
310 | //Updating Numbering Counters |
||
311 | Setting::where('key', '=','invoice_last_number')->update(['value' => $request->invoiceCounter]); |
||
312 | Setting::where('key', '=','member_last_number')->update(['value' => $request->memberCounter]); |
||
313 | $sender_id = \Utilities::getSetting('sms_sender_id'); |
||
314 | $gym_name = \Utilities::getSetting('gym_name'); |
||
315 | |||
316 | //SMS Trigger |
||
317 | if ($invoice->status == \constPaymentStatus::Paid) |
||
318 | { |
||
319 | $sms_trigger = Sms_trigger::where('alias','=','member_admission_with_paid_invoice')->first(); |
||
320 | $message = $sms_trigger->message; |
||
321 | $sms_text = sprintf($message,$member->name,$gym_name,$payment_details->payment_amount,$invoice->invoice_number); |
||
322 | $sms_status = $sms_trigger->status; |
||
323 | |||
324 | \Utilities::Sms($sender_id,$member->contact,$sms_text,$sms_status); |
||
325 | } |
||
326 | elseif($invoice->status == \constPaymentStatus::Partial) |
||
327 | { |
||
328 | $sms_trigger = Sms_trigger::where('alias','=','member_admission_with_partial_invoice')->first(); |
||
329 | $message = $sms_trigger->message; |
||
330 | $sms_text = sprintf($message,$member->name,$gym_name,$payment_details->payment_amount,$invoice->invoice_number,$invoice->pending_amount); |
||
331 | $sms_status = $sms_trigger->status; |
||
332 | |||
333 | \Utilities::Sms($sender_id,$member->contact,$sms_text,$sms_status); |
||
334 | } |
||
335 | elseif($invoice->status == \constPaymentStatus::Unpaid) |
||
336 | { |
||
337 | if($request->mode == 0) |
||
338 | { |
||
339 | $sms_trigger = Sms_trigger::where('alias','=','payment_with_cheque')->first(); |
||
340 | $message = $sms_trigger->message; |
||
341 | $sms_text = sprintf($message,$member->name,$payment_details->payment_amount,$cheque_details->number,$invoice->invoice_number,$gym_name); |
||
342 | $sms_status = $sms_trigger->status; |
||
343 | |||
344 | \Utilities::Sms($sender_id,$member->contact,$sms_text,$sms_status); |
||
345 | } |
||
346 | else |
||
347 | { |
||
348 | $sms_trigger = Sms_trigger::where('alias','=','member_admission_with_unpaid_invoice')->first(); |
||
349 | $message = $sms_trigger->message; |
||
350 | $sms_text = sprintf($message,$member->name,$gym_name,$invoice->pending_amount,$invoice->invoice_number); |
||
351 | $sms_status = $sms_trigger->status; |
||
352 | |||
353 | \Utilities::Sms($sender_id,$member->contact,$sms_text,$sms_status); |
||
354 | } |
||
355 | |||
356 | } |
||
357 | |||
358 | if($subscription->start_date < $member->created_at) |
||
359 | { |
||
360 | $member->created_at = $subscription->start_date; |
||
361 | $member->updated_at = $subscription->start_date; |
||
362 | $member->save(); |
||
363 | |||
364 | $invoice->created_at = $subscription->start_date; |
||
365 | $invoice->updated_at = $subscription->start_date; |
||
366 | $invoice->save(); |
||
367 | |||
368 | foreach($invoice->invoice_details as $invoice_detail) |
||
369 | { |
||
370 | $invoice_detail->created_at = $subscription->start_date; |
||
371 | $invoice_detail->updated_at = $subscription->start_date; |
||
372 | $invoice_detail->save(); |
||
373 | } |
||
374 | |||
375 | $payment_details->created_at = $subscription->start_date; |
||
376 | $payment_details->updated_at = $subscription->start_date; |
||
377 | $payment_details->save(); |
||
378 | |||
379 | $subscription->created_at = $subscription->start_date; |
||
380 | $subscription->updated_at = $subscription->start_date; |
||
381 | $subscription->save(); |
||
382 | } |
||
383 | |||
384 | DB::commit(); |
||
385 | flash()->success('Member was successfully created'); |
||
386 | return redirect (action('MembersController@show', ['id' => $member->id])); |
||
387 | } |
||
388 | catch (\Exception $e) |
||
389 | { |
||
390 | DB::rollback(); |
||
391 | flash()->error('Error while creating the member'); |
||
392 | return redirect (action('MembersController@index')); |
||
393 | } |
||
523 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths