| Conditions | 17 |
| Paths | 3195 |
| Total Lines | 198 |
| Code Lines | 121 |
| 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 |
||
| 120 | public function store(Request $request) |
||
| 121 | { |
||
| 122 | |||
| 123 | DB::beginTransaction(); |
||
| 124 | |||
| 125 | try { |
||
| 126 | //Helper function to set Payment status |
||
| 127 | $invoice_total = $request->admission_amount + $request->subscription_amount + $request->taxes_amount - $request->discount_amount; |
||
| 128 | $paymentStatus = \constPaymentStatus::Unpaid; |
||
| 129 | $pending = $invoice_total - $request->payment_amount; |
||
| 130 | |||
| 131 | if($request->mode == 1) |
||
| 132 | { |
||
| 133 | if ($request->payment_amount == $invoice_total) |
||
| 134 | { |
||
| 135 | $paymentStatus = \constPaymentStatus::Paid; |
||
| 136 | } |
||
| 137 | elseif($request->payment_amount > 0 && $request->payment_amount < $invoice_total) |
||
| 138 | { |
||
| 139 | $paymentStatus = \constPaymentStatus::Partial; |
||
| 140 | } |
||
| 141 | elseif($request->payment_amount == 0) |
||
| 142 | { |
||
| 143 | $paymentStatus = \constPaymentStatus::Unpaid; |
||
| 144 | } |
||
| 145 | else |
||
| 146 | { |
||
| 147 | $paymentStatus = \constPaymentStatus::Overpaid; |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | // Storing Invoice |
||
| 152 | $invoiceData = array('invoice_number'=> $request->invoice_number, |
||
| 153 | 'member_id'=> $request->member_id, |
||
| 154 | 'total'=> $invoice_total, |
||
| 155 | 'status'=> $paymentStatus, |
||
| 156 | 'pending_amount'=> $pending, |
||
| 157 | 'discount_amount'=> $request->discount_amount, |
||
| 158 | 'discount_percent'=> $request->discount_percent, |
||
| 159 | 'discount_note'=> $request->discount_note, |
||
| 160 | 'tax'=> $request->taxes_amount, |
||
| 161 | 'additional_fees'=> $request->additional_fees, |
||
| 162 | 'note'=>' '); |
||
| 163 | |||
| 164 | $invoice = new Invoice($invoiceData); |
||
| 165 | $invoice->createdBy()->associate(Auth::user()); |
||
| 166 | $invoice->updatedBy()->associate(Auth::user()); |
||
| 167 | $invoice->save(); |
||
| 168 | |||
| 169 | // Storing subscription |
||
| 170 | foreach($request->plan as $plan) |
||
| 171 | { |
||
| 172 | $subscriptionData = array('member_id'=> $request->member_id, |
||
| 173 | 'invoice_id'=> $invoice->id, |
||
| 174 | 'plan_id'=> $plan['id'], |
||
| 175 | 'start_date'=> $plan['start_date'], |
||
| 176 | 'end_date'=> $plan['end_date'], |
||
| 177 | 'status'=> \constSubscription::onGoing, |
||
| 178 | 'is_renewal'=>'0'); |
||
| 179 | |||
| 180 | $subscription = new Subscription($subscriptionData); |
||
| 181 | $subscription->createdBy()->associate(Auth::user()); |
||
| 182 | $subscription->updatedBy()->associate(Auth::user()); |
||
| 183 | $subscription->save(); |
||
| 184 | |||
| 185 | //Adding subscription to invoice(Invoice Details) |
||
| 186 | $detailsData = array('invoice_id'=> $invoice->id, |
||
| 187 | 'plan_id'=> $plan['id'], |
||
| 188 | 'item_amount'=> $plan['price']); |
||
| 189 | |||
| 190 | $invoice_details = new Invoice_detail($detailsData); |
||
| 191 | $invoice_details->createdBy()->associate(Auth::user()); |
||
| 192 | $invoice_details->updatedBy()->associate(Auth::user()); |
||
| 193 | $invoice_details->save(); |
||
| 194 | } |
||
| 195 | |||
| 196 | //Payment Details |
||
| 197 | $paymentData = array('invoice_id'=> $invoice->id, |
||
| 198 | 'payment_amount'=> $request->payment_amount, |
||
| 199 | 'mode'=> $request->mode, |
||
| 200 | 'note'=> ' '); |
||
| 201 | |||
| 202 | $payment_details = new Payment_detail($paymentData); |
||
| 203 | $payment_details->createdBy()->associate(Auth::user()); |
||
| 204 | $payment_details->updatedBy()->associate(Auth::user()); |
||
| 205 | $payment_details->save(); |
||
| 206 | |||
| 207 | if($request->mode == 0) |
||
| 208 | { |
||
| 209 | // Store Cheque Details |
||
| 210 | $chequeData = array('payment_id'=> $payment_details->id, |
||
| 211 | 'number'=> $request->number, |
||
| 212 | 'date'=> $request->date, |
||
| 213 | 'status'=> \constChequeStatus::Recieved); |
||
| 214 | |||
| 215 | $cheque_details = new Cheque_detail($chequeData); |
||
| 216 | $cheque_details->createdBy()->associate(Auth::user()); |
||
| 217 | $cheque_details->updatedBy()->associate(Auth::user()); |
||
| 218 | $cheque_details->save(); |
||
| 219 | } |
||
| 220 | |||
| 221 | // Set the subscription status of the 'Renewed' subscription to Renew |
||
| 222 | if ($request->has('previousSubscriptions')) |
||
| 223 | { |
||
| 224 | Subscription::where('invoice_id',$invoice->id)->update(['is_renewal' => '1']); |
||
| 225 | |||
| 226 | foreach($request->previousSubscriptions as $subscriptionId) |
||
| 227 | { |
||
| 228 | $oldSubscription=Subscription::findOrFail($subscriptionId); |
||
| 229 | $oldSubscription->status = \constSubscription::renewed; |
||
| 230 | $oldSubscription->updatedBy()->associate(Auth::user()); |
||
| 231 | $oldSubscription->save(); |
||
| 232 | } |
||
| 233 | } |
||
| 234 | |||
| 235 | //Updating Numbering Counters |
||
| 236 | Setting::where('key', '=','invoice_last_number')->update(['value' => $request->invoiceCounter]); |
||
| 237 | $sender_id = \Utilities::getSetting('sms_sender_id'); |
||
| 238 | $gym_name = \Utilities::getSetting('gym_name'); |
||
| 239 | |||
| 240 | //SMS Trigger |
||
| 241 | if ($invoice->status == \constPaymentStatus::Paid) |
||
| 242 | { |
||
| 243 | if($request->mode == 0) |
||
| 244 | { |
||
| 245 | $sms_trigger = Sms_trigger::where('alias','=','payment_with_cheque')->first(); |
||
| 246 | $message = $sms_trigger->message; |
||
| 247 | $sms_text = sprintf($message,$subscription->member->name,$payment_details->payment_amount,$cheque_details->number,$invoice->invoice_number,$gym_name); |
||
| 248 | $sms_status = $sms_trigger->status; |
||
| 249 | |||
| 250 | \Utilities::Sms($sender_id,$subscription->member->contact,$sms_text,$sms_status); |
||
| 251 | } |
||
| 252 | else |
||
| 253 | { |
||
| 254 | $sms_trigger = Sms_trigger::where('alias','=','subscription_renewal_with_paid_invoice')->first(); |
||
| 255 | $message = $sms_trigger->message; |
||
| 256 | $sms_text = sprintf($message,$subscription->member->name,$payment_details->payment_amount,$invoice->invoice_number); |
||
| 257 | $sms_status = $sms_trigger->status; |
||
| 258 | |||
| 259 | \Utilities::Sms($sender_id,$subscription->member->contact,$sms_text,$sms_status); |
||
| 260 | } |
||
| 261 | |||
| 262 | } |
||
| 263 | elseif($invoice->status == \constPaymentStatus::Partial) |
||
| 264 | { |
||
| 265 | if($request->mode == 0) |
||
| 266 | { |
||
| 267 | $sms_trigger = Sms_trigger::where('alias','=','payment_with_cheque')->first(); |
||
| 268 | $message = $sms_trigger->message; |
||
| 269 | $sms_text = sprintf($message,$subscription->member->name,$payment_details->payment_amount,$cheque_details->number,$invoice->invoice_number,$gym_name); |
||
| 270 | $sms_status = $sms_trigger->status; |
||
| 271 | |||
| 272 | \Utilities::Sms($sender_id,$subscription->member->contact,$sms_text,$sms_status); |
||
| 273 | } |
||
| 274 | else |
||
| 275 | { |
||
| 276 | $sms_trigger = Sms_trigger::where('alias','=','subscription_renewal_with_partial_invoice')->first(); |
||
| 277 | $message = $sms_trigger->message; |
||
| 278 | $sms_text = sprintf($message,$subscription->member->name,$payment_details->payment_amount,$invoice->invoice_number,$invoice->pending_amount); |
||
| 279 | $sms_status = $sms_trigger->status; |
||
| 280 | |||
| 281 | \Utilities::Sms($sender_id,$subscription->member->contact,$sms_text,$sms_status); |
||
| 282 | } |
||
| 283 | |||
| 284 | } |
||
| 285 | elseif($invoice->status == \constPaymentStatus::Unpaid) |
||
| 286 | { |
||
| 287 | if($request->mode == 0) |
||
| 288 | { |
||
| 289 | $sms_trigger = Sms_trigger::where('alias','=','payment_with_cheque')->first(); |
||
| 290 | $message = $sms_trigger->message; |
||
| 291 | $sms_text = sprintf($message,$subscription->member->name,$payment_details->payment_amount,$cheque_details->number,$invoice->invoice_number,$gym_name); |
||
| 292 | $sms_status = $sms_trigger->status; |
||
| 293 | |||
| 294 | \Utilities::Sms($sender_id,$subscription->member->contact,$sms_text,$sms_status); |
||
| 295 | } |
||
| 296 | else |
||
| 297 | { |
||
| 298 | $sms_trigger = Sms_trigger::where('alias','=','subscription_renewal_with_unpaid_invoice')->first(); |
||
| 299 | $message = $sms_trigger->message; |
||
| 300 | $sms_text = sprintf($message,$subscription->member->name,$invoice->total,$invoice->invoice_number); |
||
| 301 | $sms_status = $sms_trigger->status; |
||
| 302 | |||
| 303 | \Utilities::Sms($sender_id,$subscription->member->contact,$sms_text,$sms_status); |
||
| 304 | } |
||
| 305 | |||
| 306 | } |
||
| 307 | |||
| 308 | DB::commit(); |
||
| 309 | flash()->success('Subscription was successfully created'); |
||
| 310 | return redirect (action('SubscriptionsController@index')); |
||
| 311 | } |
||
| 312 | |||
| 313 | catch (\Exception $e) |
||
| 314 | { |
||
| 315 | DB::rollback(); |
||
| 316 | flash()->error('Error while creating the Subscription'); |
||
| 317 | return redirect (action('SubscriptionsController@index')); |
||
| 318 | } |
||
| 560 | } |
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