| Total Complexity | 46 |
| Total Lines | 323 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like TaxRatesAndCodeExpiryController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TaxRatesAndCodeExpiryController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 16 | class TaxRatesAndCodeExpiryController extends BaseInvoiceController |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Get tax when enabled. |
||
| 20 | */ |
||
| 21 | public function getTaxWhenEnable($productid, $taxs, $userid) |
||
| 22 | { |
||
| 23 | $rate = $this->getRate($productid, $taxs, $userid); |
||
| 24 | $taxs = ([$rate['taxs']['0']['name'], $rate['taxs']['0']['rate']]); |
||
| 25 | |||
| 26 | return $taxs; |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * GeT Total Rate. |
||
| 31 | */ |
||
| 32 | public function getTotalRate($taxClassId, $productid, $taxs) |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Get Grandtotal. |
||
| 47 | **/ |
||
| 48 | public function getGrandTotal($code, $total, $cost, $productid, $currency) |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Get Message on Invoice Generation. |
||
| 65 | **/ |
||
| 66 | public function getMessage($items, $user_id) |
||
| 76 | } |
||
| 77 | |||
| 78 | public function currency($invoiceid) |
||
| 79 | { |
||
| 80 | $invoice = Invoice::find($invoiceid); |
||
| 81 | $currency_code = $invoice->currency; |
||
| 82 | $cur = ' '; |
||
| 83 | if ($invoice->grand_total == 0) { |
||
| 84 | return $cur; |
||
| 85 | } |
||
| 86 | $currency = Currency::where('code', $currency_code)->first(); |
||
| 87 | if ($currency) { |
||
| 88 | $cur = $currency->symbol; |
||
| 89 | if (!$cur) { |
||
| 90 | $cur = $currency->code; |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | return $cur; |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * get Subtotal. |
||
| 99 | */ |
||
| 100 | public function getSubtotal($user_currency, $cart) |
||
| 101 | { |
||
| 102 | if ($user_currency == 'INR') { |
||
| 103 | $subtotal = \App\Http\Controllers\Front\CartController::rounding($cart->getPriceSumWithConditions()); |
||
| 104 | } else { |
||
| 105 | $subtotal = \App\Http\Controllers\Front\CartController::rounding($cart->getPriceSumWithConditions()); |
||
| 106 | } |
||
| 107 | |||
| 108 | return $subtotal; |
||
| 109 | } |
||
| 110 | |||
| 111 | public function calculateTotal($rate, $total) |
||
| 112 | { |
||
| 113 | try { |
||
| 114 | $rates = explode(',', $rate); |
||
| 115 | $rule = new TaxOption(); |
||
| 116 | $rule = $rule->findOrFail(1); |
||
| 117 | if ($rule->inclusive == 0) { |
||
| 118 | foreach ($rates as $rate1) { |
||
| 119 | if ($rate1 != '') { |
||
| 120 | $rateTotal = str_replace('%', '', $rate1); |
||
| 121 | $total += $total * ($rateTotal / 100); |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | return intval(round($total)); |
||
| 127 | } catch (\Exception $ex) { |
||
| 128 | Bugsnag::notifyException($ex); |
||
| 129 | |||
| 130 | throw new \Exception($ex->getMessage()); |
||
| 131 | } |
||
| 132 | } |
||
| 133 | |||
| 134 | public function getPrice($price, $price_model) |
||
| 135 | { |
||
| 136 | if ($price == '') { |
||
| 137 | $price = $price_model->sales_price; |
||
| 138 | if (!$price) { |
||
| 139 | $price = $price_model->price; |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | return $price; |
||
| 144 | } |
||
| 145 | |||
| 146 | public function checkExecution($invoiceid) |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 169 | public function invoiceContent($invoiceid) |
||
| 170 | { |
||
| 192 | } |
||
| 193 | |||
| 194 | public function sendInvoiceMail($userid, $number, $total, $invoiceid) |
||
| 231 | } |
||
| 232 | |||
| 233 | public function invoiceUrl($invoiceid) |
||
| 238 | } |
||
| 239 | |||
| 240 | public function paymentDeleleById($id) |
||
| 261 | } |
||
| 262 | } |
||
| 263 | |||
| 264 | public function paymentEditById($id) |
||
| 265 | { |
||
| 266 | try { |
||
| 267 | $cltCont = new \App\Http\Controllers\User\ClientController(); |
||
| 268 | $amountReceived = $cltCont->getAmountPaid($id); |
||
| 269 | $payment = Payment::find($id); |
||
| 270 | $clientid = $payment->user_id; |
||
| 271 | $invoice = new Invoice(); |
||
| 272 | $order = new Order(); |
||
| 273 | $invoices = $invoice->where('user_id', $clientid)->where('status', '=', 'pending')->orderBy('created_at', 'desc')->get(); |
||
|
|
|||
| 274 | $cltCont = new \App\Http\Controllers\User\ClientController(); |
||
| 275 | $invoiceSum = $cltCont->getTotalInvoice($invoices); |
||
| 276 | $amountReceived = $cltCont->getAmountPaid($clientid); |
||
| 277 | $pendingAmount = $invoiceSum - $amountReceived; |
||
| 278 | $client = $this->user->where('id', $clientid)->first(); |
||
| 279 | $currency = $client->currency; |
||
| 280 | $orders = $order->where('client', $clientid)->get(); |
||
| 281 | return view('themes.default1.invoice.editPayment',compact('amountReceived','clientid', 'client', 'invoices', 'orders', |
||
| 282 | 'invoiceSum', 'amountReceived', 'pendingAmount', 'currency')); |
||
| 283 | |||
| 284 | |||
| 285 | |||
| 286 | |||
| 287 | |||
| 288 | |||
| 289 | } catch (Exception $e) { |
||
| 290 | Bugsnag::notifyException($e); |
||
| 291 | return redirect()->back()->with('fails', $e->getMessage()); |
||
| 292 | } |
||
| 293 | } |
||
| 294 | |||
| 295 | public function deleleById($id) |
||
| 310 | } |
||
| 311 | } |
||
| 312 | |||
| 313 | public function getPromotionDetails($code) |
||
| 339 | } |
||
| 340 | } |
||
| 341 |
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.