| Conditions | 18 |
| Paths | 18710 |
| Total Lines | 208 |
| 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 |
||
| 128 | public function store(Request $request) |
||
| 129 | { |
||
| 130 | // Member Model Validation |
||
| 131 | $this->validate($request, ['email' => 'unique:mst_members,email', |
||
| 132 | 'contact' => 'unique:mst_members,contact', |
||
| 133 | 'member_code' => 'unique:mst_members,member_code', ]); |
||
| 134 | |||
| 135 | // Start Transaction |
||
| 136 | DB::beginTransaction(); |
||
| 137 | |||
| 138 | try { |
||
| 139 | // Store member's personal details |
||
| 140 | $memberData = ['name'=>$request->name, |
||
| 141 | 'DOB'=> $request->DOB, |
||
| 142 | 'gender'=> $request->gender, |
||
| 143 | 'contact'=> $request->contact, |
||
| 144 | 'emergency_contact'=> $request->emergency_contact, |
||
| 145 | 'health_issues'=> $request->health_issues, |
||
| 146 | 'email'=> $request->email, |
||
| 147 | 'address'=> $request->address, |
||
| 148 | 'member_id'=> $request->member_id, |
||
| 149 | 'proof_name'=> $request->proof_name, |
||
| 150 | 'member_code'=> $request->member_code, |
||
| 151 | 'status'=> $request->status, |
||
| 152 | 'pin_code'=> $request->pin_code, |
||
| 153 | 'occupation'=> $request->occupation, |
||
| 154 | 'aim'=> $request->aim, |
||
| 155 | 'source'=> $request->source, ]; |
||
| 156 | |||
| 157 | $member = new Member($memberData); |
||
| 158 | $member->createdBy()->associate(Auth::user()); |
||
| 159 | $member->updatedBy()->associate(Auth::user()); |
||
| 160 | $member->save(); |
||
| 161 | |||
| 162 | // Adding media i.e. Profile & proof photo |
||
| 163 | if ($request->hasFile('photo')) { |
||
| 164 | $member->addMedia($request->file('photo'))->usingFileName('profile_'.$member->id.'.'.$request->photo->getClientOriginalExtension())->toCollection('profile'); |
||
| 165 | } |
||
| 166 | |||
| 167 | if ($request->hasFile('proof_photo')) { |
||
| 168 | $member->addMedia($request->file('proof_photo'))->usingFileName('proof_'.$member->id.'.'.$request->proof_photo->getClientOriginalExtension())->toCollection('proof'); |
||
| 169 | } |
||
| 170 | |||
| 171 | // Helper function for calculating payment status |
||
| 172 | $invoice_total = $request->admission_amount + $request->subscription_amount + $request->taxes_amount - $request->discount_amount; |
||
| 173 | $paymentStatus = \constPaymentStatus::Unpaid; |
||
| 174 | $pending = $invoice_total - $request->payment_amount; |
||
| 175 | |||
| 176 | if ($request->mode == 1) { |
||
| 177 | if ($request->payment_amount == $invoice_total) { |
||
| 178 | $paymentStatus = \constPaymentStatus::Paid; |
||
| 179 | } elseif ($request->payment_amount > 0 && $request->payment_amount < $invoice_total) { |
||
| 180 | $paymentStatus = \constPaymentStatus::Partial; |
||
| 181 | } elseif ($request->payment_amount == 0) { |
||
| 182 | $paymentStatus = \constPaymentStatus::Unpaid; |
||
| 183 | } else { |
||
| 184 | $paymentStatus = \constPaymentStatus::Overpaid; |
||
| 185 | } |
||
| 186 | } |
||
| 187 | |||
| 188 | // Storing Invoice |
||
| 189 | $invoiceData = ['invoice_number'=> $request->invoice_number, |
||
| 190 | 'member_id'=> $member->id, |
||
| 191 | 'total'=> $invoice_total, |
||
| 192 | 'status'=> $paymentStatus, |
||
| 193 | 'pending_amount'=> $pending, |
||
| 194 | 'discount_amount'=> $request->discount_amount, |
||
| 195 | 'discount_percent'=> $request->discount_percent, |
||
| 196 | 'discount_note'=> $request->discount_note, |
||
| 197 | 'tax'=> $request->taxes_amount, |
||
| 198 | 'additional_fees'=> $request->additional_fees, |
||
| 199 | 'note'=>' ', ]; |
||
| 200 | |||
| 201 | $invoice = new Invoice($invoiceData); |
||
| 202 | $invoice->createdBy()->associate(Auth::user()); |
||
| 203 | $invoice->updatedBy()->associate(Auth::user()); |
||
| 204 | $invoice->save(); |
||
| 205 | |||
| 206 | // Storing subscription |
||
| 207 | foreach ($request->plan as $plan) { |
||
| 208 | $subscriptionData = ['member_id'=> $member->id, |
||
| 209 | 'invoice_id'=> $invoice->id, |
||
| 210 | 'plan_id'=> $plan['id'], |
||
| 211 | 'start_date'=> $plan['start_date'], |
||
| 212 | 'end_date'=> $plan['end_date'], |
||
| 213 | 'status'=> \constSubscription::onGoing, |
||
| 214 | 'is_renewal'=>'0', ]; |
||
| 215 | |||
| 216 | $subscription = new Subscription($subscriptionData); |
||
| 217 | $subscription->createdBy()->associate(Auth::user()); |
||
| 218 | $subscription->updatedBy()->associate(Auth::user()); |
||
| 219 | $subscription->save(); |
||
| 220 | |||
| 221 | //Adding subscription to invoice(Invoice Details) |
||
| 222 | $detailsData = ['invoice_id'=> $invoice->id, |
||
| 223 | 'plan_id'=> $plan['id'], |
||
| 224 | 'item_amount'=> $plan['price'], ]; |
||
| 225 | |||
| 226 | $invoiceDetails = new InvoiceDetail($detailsData); |
||
| 227 | $invoiceDetails->createdBy()->associate(Auth::user()); |
||
| 228 | $invoiceDetails->updatedBy()->associate(Auth::user()); |
||
| 229 | $invoiceDetails->save(); |
||
| 230 | } |
||
| 231 | |||
| 232 | // Store Payment Details |
||
| 233 | $paymentData = ['invoice_id'=> $invoice->id, |
||
| 234 | 'payment_amount'=> $request->payment_amount, |
||
| 235 | 'mode'=> $request->mode, |
||
| 236 | 'note'=> ' ', ]; |
||
| 237 | |||
| 238 | $paymentDetails = new PaymentDetail($paymentData); |
||
| 239 | $paymentDetails->createdBy()->associate(Auth::user()); |
||
| 240 | $paymentDetails->updatedBy()->associate(Auth::user()); |
||
| 241 | $paymentDetails->save(); |
||
| 242 | |||
| 243 | if ($request->mode == 0) { |
||
| 244 | // Store Cheque Details |
||
| 245 | $chequeData = ['payment_id'=> $paymentDetails->id, |
||
| 246 | 'number'=> $request->number, |
||
| 247 | 'date'=> $request->date, |
||
| 248 | 'status'=> \constChequeStatus::Recieved, ]; |
||
| 249 | |||
| 250 | $cheque_details = new ChequeDetail($chequeData); |
||
| 251 | $cheque_details->createdBy()->associate(Auth::user()); |
||
| 252 | $cheque_details->updatedBy()->associate(Auth::user()); |
||
| 253 | $cheque_details->save(); |
||
| 254 | } |
||
| 255 | |||
| 256 | // On member transfer update enquiry Status |
||
| 257 | if ($request->has('transfer_id')) { |
||
| 258 | $enquiry = Enquiry::findOrFail($request->transfer_id); |
||
| 259 | $enquiry->status = \constEnquiryStatus::Member; |
||
| 260 | $enquiry->updatedBy()->associate(Auth::user()); |
||
| 261 | $enquiry->save(); |
||
| 262 | } |
||
| 263 | |||
| 264 | //Updating Numbering Counters |
||
| 265 | Setting::where('key', '=', 'invoice_last_number')->update(['value' => $request->invoiceCounter]); |
||
| 266 | Setting::where('key', '=', 'member_last_number')->update(['value' => $request->memberCounter]); |
||
| 267 | $sender_id = \Utilities::getSetting('sms_sender_id'); |
||
| 268 | $gym_name = \Utilities::getSetting('gym_name'); |
||
| 269 | |||
| 270 | //SMS Trigger |
||
| 271 | if ($invoice->status == \constPaymentStatus::Paid) { |
||
| 272 | $sms_trigger = SmsTrigger::where('alias', '=', 'member_admission_with_paid_invoice')->first(); |
||
| 273 | $message = $sms_trigger->message; |
||
| 274 | $sms_text = sprintf($message, $member->name, $gym_name, $paymentDetails->payment_amount, $invoice->invoice_number); |
||
| 275 | $sms_status = $sms_trigger->status; |
||
| 276 | |||
| 277 | \Utilities::Sms($sender_id, $member->contact, $sms_text, $sms_status); |
||
| 278 | } elseif ($invoice->status == \constPaymentStatus::Partial) { |
||
| 279 | $sms_trigger = SmsTrigger::where('alias', '=', 'member_admission_with_partial_invoice')->first(); |
||
| 280 | $message = $sms_trigger->message; |
||
| 281 | $sms_text = sprintf($message, $member->name, $gym_name, $paymentDetails->payment_amount, $invoice->invoice_number, $invoice->pending_amount); |
||
| 282 | $sms_status = $sms_trigger->status; |
||
| 283 | |||
| 284 | \Utilities::Sms($sender_id, $member->contact, $sms_text, $sms_status); |
||
| 285 | } elseif ($invoice->status == \constPaymentStatus::Unpaid) { |
||
| 286 | if ($request->mode == 0) { |
||
| 287 | $sms_trigger = SmsTrigger::where('alias', '=', 'payment_with_cheque')->first(); |
||
| 288 | $message = $sms_trigger->message; |
||
| 289 | $sms_text = sprintf($message, $member->name, $paymentDetails->payment_amount, $cheque_details->number, $invoice->invoice_number, $gym_name); |
||
| 290 | $sms_status = $sms_trigger->status; |
||
| 291 | |||
| 292 | \Utilities::Sms($sender_id, $member->contact, $sms_text, $sms_status); |
||
| 293 | } else { |
||
| 294 | $sms_trigger = SmsTrigger::where('alias', '=', 'member_admission_with_unpaid_invoice')->first(); |
||
| 295 | $message = $sms_trigger->message; |
||
| 296 | $sms_text = sprintf($message, $member->name, $gym_name, $invoice->pending_amount, $invoice->invoice_number); |
||
| 297 | $sms_status = $sms_trigger->status; |
||
| 298 | |||
| 299 | \Utilities::Sms($sender_id, $member->contact, $sms_text, $sms_status); |
||
| 300 | } |
||
| 301 | } |
||
| 302 | |||
| 303 | if ($subscription->start_date < $member->created_at) { |
||
| 304 | $member->created_at = $subscription->start_date; |
||
| 305 | $member->updated_at = $subscription->start_date; |
||
| 306 | $member->save(); |
||
| 307 | |||
| 308 | $invoice->created_at = $subscription->start_date; |
||
| 309 | $invoice->updated_at = $subscription->start_date; |
||
| 310 | $invoice->save(); |
||
| 311 | |||
| 312 | foreach ($invoice->invoiceDetails as $invoiceDetail) { |
||
| 313 | $invoiceDetail->created_at = $subscription->start_date; |
||
| 314 | $invoiceDetail->updated_at = $subscription->start_date; |
||
| 315 | $invoiceDetail->save(); |
||
| 316 | } |
||
| 317 | |||
| 318 | $paymentDetails->created_at = $subscription->start_date; |
||
| 319 | $paymentDetails->updated_at = $subscription->start_date; |
||
| 320 | $paymentDetails->save(); |
||
| 321 | |||
| 322 | $subscription->created_at = $subscription->start_date; |
||
| 323 | $subscription->updated_at = $subscription->start_date; |
||
| 324 | $subscription->save(); |
||
| 325 | } |
||
| 326 | |||
| 327 | DB::commit(); |
||
| 328 | flash()->success('Member was successfully created'); |
||
| 329 | |||
| 330 | return redirect(action('MembersController@show', ['id' => $member->id])); |
||
| 331 | } catch (\Exception $e) { |
||
| 332 | DB::rollback(); |
||
| 333 | flash()->error('Error while creating the member'); |
||
| 334 | |||
| 335 | return redirect(action('MembersController@index')); |
||
| 336 | } |
||
| 468 |
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