Conditions | 7 |
Paths | 146 |
Total Lines | 78 |
Code Lines | 48 |
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 |
||
54 | public function store(Request $request) |
||
55 | { |
||
56 | DB::beginTransaction(); |
||
57 | try |
||
58 | { |
||
59 | // Storing Payment Details |
||
60 | $payment_detail = new Payment_detail($request->all()); |
||
61 | $payment_detail->createdBy()->associate(Auth::user()); |
||
62 | $payment_detail->updatedBy()->associate(Auth::user()); |
||
63 | $payment_detail->save(); |
||
64 | |||
65 | if($request->mode == \constPaymentMode::Cheque) |
||
66 | { |
||
67 | // Store Cheque Details |
||
68 | $chequeData = array('payment_id'=> $payment_detail->id, |
||
69 | 'number'=> $request->number, |
||
70 | 'date'=> $request->date, |
||
71 | 'status'=> \constChequeStatus::Recieved); |
||
72 | |||
73 | $cheque_details = new Cheque_detail($chequeData); |
||
74 | $cheque_details->createdBy()->associate(Auth::user()); |
||
75 | $cheque_details->updatedBy()->associate(Auth::user()); |
||
76 | $cheque_details->save(); |
||
77 | } |
||
78 | |||
79 | elseif($request->mode == \constPaymentMode::Cash) |
||
80 | { |
||
81 | // Updating Invoice Status and amounts |
||
82 | $invoice_total = $payment_detail->invoice->total; |
||
|
|||
83 | $payment_total = Payment_detail::where('invoice_id',$payment_detail->invoice_id)->sum('payment_amount'); |
||
84 | $amount_due = $invoice_total - $payment_total; |
||
85 | |||
86 | $payment_detail->invoice->pending_amount = $amount_due; |
||
87 | $payment_detail->invoice->status = \Utilities::setInvoiceStatus($amount_due,$invoice_total); |
||
88 | $payment_detail->invoice->save(); |
||
89 | } |
||
90 | |||
91 | //If cheque reissued , set the status of the previous cheque detail to Reissued |
||
92 | if($request->has('previousPayment')) |
||
93 | { |
||
94 | $cheque_detail = Cheque_detail::where('payment_id',$request->previousPayment)->first(); |
||
95 | $cheque_detail->status = \constChequeStatus::Reissued; |
||
96 | $cheque_detail->save(); |
||
97 | } |
||
98 | |||
99 | // SMS Trigger |
||
100 | $sender_id = \Utilities::getSetting('sms_sender_id'); |
||
101 | $gym_name = \Utilities::getSetting('gym_name'); |
||
102 | |||
103 | if($request->mode == \constPaymentMode::Cash) |
||
104 | { |
||
105 | $sms_trigger = Sms_trigger::where('alias','=','payment_recieved')->first(); |
||
106 | $message = $sms_trigger->message; |
||
107 | $sms_text = sprintf($message,$payment_detail->invoice->member->name,$payment_detail->payment_amount,$payment_detail->invoice->invoice_number); |
||
108 | $sms_status = $sms_trigger->status; |
||
109 | $sender_id = \Utilities::getSetting('sms_sender_id'); |
||
110 | |||
111 | \Utilities::Sms($sender_id,$payment_detail->invoice->member->contact,$sms_text,$sms_status); |
||
112 | } |
||
113 | elseif($request->mode == \constPaymentMode::Cheque) |
||
114 | { |
||
115 | $sms_trigger = Sms_trigger::where('alias','=','payment_with_cheque')->first(); |
||
116 | $message = $sms_trigger->message; |
||
117 | $sms_text = sprintf($message,$payment_detail->invoice->member->name,$payment_detail->payment_amount,$cheque_details->number,$payment_detail->invoice->invoice_number,$gym_name); |
||
118 | $sms_status = $sms_trigger->status; |
||
119 | |||
120 | \Utilities::Sms($sender_id,$payment_detail->invoice->member->contact,$sms_text,$sms_status); |
||
121 | } |
||
122 | |||
123 | DB::commit(); |
||
124 | flash()->success('Payment Details were successfully stored'); |
||
125 | return redirect (action('InvoicesController@show', ['id' => $payment_detail->invoice_id])); |
||
126 | } |
||
127 | catch (Exception $e) |
||
128 | { |
||
129 | DB::rollback(); |
||
130 | flash()->error('Payment Details weren\'t stored succesfully' ); |
||
131 | return redirect('payments/all'); |
||
132 | } |
||
293 |