| Conditions | 4 |
| Paths | 1 |
| Total Lines | 68 |
| Code Lines | 53 |
| 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 |
||
| 11 | public function getClientInvoice($id) |
||
| 12 | { |
||
| 13 | $invoice = new Invoice(); |
||
| 14 | $client = $this->user->where('id', $id)->first(); |
||
| 15 | $invoices = $invoice->where('user_id', $id)->orderBy('created_at', 'desc')->get(); |
||
| 16 | |||
| 17 | return\ DataTables::of($invoices) |
||
| 18 | ->addColumn('checkbox', function ($model) { |
||
| 19 | return "<input type='checkbox' class='invoice_checkbox' |
||
| 20 | value=".$model->id.' name=select[] id=check>'; |
||
| 21 | }) |
||
| 22 | ->addColumn('date', function ($model) use ($client) { |
||
| 23 | $date1 = new \DateTime($model->date); |
||
| 24 | $tz = $client->timezone()->first()->name; |
||
| 25 | $date1->setTimezone(new \DateTimeZone($tz)); |
||
| 26 | $date = $date1->format('M j, Y, g:i a '); |
||
| 27 | return $date; |
||
| 28 | }) |
||
| 29 | ->addColumn('invoice_no', function ($model) { |
||
| 30 | return '<a href='.url('invoices/show?invoiceid='.$model->id).'>'.$model->number.'</a>'; |
||
| 31 | }) |
||
| 32 | ->addColumn('total', function ($model) use ($client) { |
||
| 33 | return currency_format($model->grand_total, $code =$client->currency); |
||
| 34 | }) |
||
| 35 | ->addColumn('paid', function ($model) use ($client) { |
||
| 36 | $payment = \App\Model\Order\Payment::where('invoice_id', $model->id)->select('amount')->get(); |
||
|
|
|||
| 37 | $c=count($payment); |
||
| 38 | $sum = 0; |
||
| 39 | for ($i=0 ; $i <= $c-1 ; $i++) { |
||
| 40 | $sum = $sum + $payment[$i]->amount; |
||
| 41 | } |
||
| 42 | return currency_format($sum, $code =$client->currency); |
||
| 43 | }) |
||
| 44 | ->addColumn('balance', function ($model) use ($client) { |
||
| 45 | $payment = \App\Model\Order\Payment::where('invoice_id', $model->id)->select('amount')->get(); |
||
| 46 | $c=count($payment); |
||
| 47 | $sum = 0; |
||
| 48 | for ($i=0 ; $i <= $c-1 ; $i++) { |
||
| 49 | $sum = $sum + $payment[$i]->amount; |
||
| 50 | } |
||
| 51 | $pendingAmount = ($model->grand_total)-($sum); |
||
| 52 | return currency_format($pendingAmount, $code =$client->currency); |
||
| 53 | }) |
||
| 54 | ->addColumn('status', function ($model) { |
||
| 55 | return $model->status; |
||
| 56 | }) |
||
| 57 | ->addColumn('action', function ($model) { |
||
| 58 | $action = ''; |
||
| 59 | $cont = new \App\Http\Controllers\Order\TaxRatesAndCodeExpiryController(); |
||
| 60 | $check = $cont->checkExecution($model->id); |
||
| 61 | if ($check == false) { |
||
| 62 | $action = '<a href='.url('order/execute?invoiceid='.$model->id) |
||
| 63 | ." class='btn btn-sm btn-primary btn-xs'> |
||
| 64 | <i class='fa fa-tasks' style='color:white;'> |
||
| 65 | </i> Execute Order</a>"; |
||
| 66 | } |
||
| 67 | $editAction = '<a href='.url('invoices/edit/'.$model->id) |
||
| 68 | ." class='btn btn-sm btn-primary btn-xs'> |
||
| 69 | <i class='fa fa-edit' style='color:white;'> |
||
| 70 | </i> Edit</a>"; |
||
| 71 | |||
| 72 | return '<a href='.url('invoices/show?invoiceid='.$model->id) |
||
| 73 | ." class='btn btn-sm btn-primary btn-xs'><i class='fa fa-eye' |
||
| 74 | style='color:white;'> </i> View</a>" |
||
| 75 | ." $editAction $action"; |
||
| 76 | }) |
||
| 77 | ->rawColumns(['checkbox', 'date', 'invoice_no', 'total', 'paid', 'balance', 'status','action']) |
||
| 78 | ->make(true); |
||
| 79 | } |
||
| 166 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.