| Total Complexity | 51 |
| Total Lines | 207 |
| 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 |
||
| 12 | class TaxRatesAndCodeExpiryController extends Controller |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | *Tax When state is not empty. |
||
| 16 | */ |
||
| 17 | public function getTaxWhenState($user_state, $productid, $origin_state) |
||
| 18 | { |
||
| 19 | $cartController = new CartController(); |
||
| 20 | $c_gst = $user_state->c_gst; |
||
| 21 | $s_gst = $user_state->s_gst; |
||
| 22 | $i_gst = $user_state->i_gst; |
||
| 23 | $ut_gst = $user_state->ut_gst; |
||
| 24 | $state_code = $user_state->state_code; |
||
| 25 | if ($state_code == $origin_state) {//If user and origin state are same |
||
| 26 | $taxClassId = TaxClass::where('name', 'Intra State GST')->pluck('id')->toArray(); //Get the class Id of state |
||
| 27 | if ($taxClassId) { |
||
| 28 | $taxes = $cartController->getTaxByPriority($taxClassId); |
||
| 29 | $value = $cartController->getValueForSameState($productid, $c_gst, $s_gst, $taxClassId, $taxes); |
||
| 30 | } else { |
||
| 31 | $taxes = [0]; |
||
| 32 | } |
||
| 33 | } elseif ($state_code != $origin_state && $ut_gst == 'NULL') {//If user is from other state |
||
| 34 | |||
| 35 | $taxClassId = TaxClass::where('name', 'Inter State GST')->pluck('id')->toArray(); //Get the class Id of state |
||
| 36 | if ($taxClassId) { |
||
| 37 | $taxes = $cartController->getTaxByPriority($taxClassId); |
||
| 38 | $value = $cartController->getValueForOtherState($productid, $i_gst, $taxClassId, $taxes); |
||
| 39 | } else { |
||
| 40 | $taxes = [0]; |
||
| 41 | } |
||
| 42 | } elseif ($state_code != $origin_state && $ut_gst != 'NULL') {//if user from Union Territory |
||
| 43 | $taxClassId = TaxClass::where('name', 'Union Territory GST')->pluck('id')->toArray(); //Get the class Id of state |
||
| 44 | if ($taxClassId) { |
||
| 45 | $taxes = $cartController->getTaxByPriority($taxClassId); |
||
| 46 | $value = $cartController->getValueForUnionTerritory($productid, $c_gst, $ut_gst, $taxClassId, $taxes); |
||
| 47 | } else { |
||
| 48 | $taxes = [0]; |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | return ['taxes'=>$taxes, 'value'=>$value]; |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | *Tax When from other Country. |
||
| 57 | */ |
||
| 58 | public function getTaxWhenOtherCountry($geoip_state, $geoip_country, $productid) |
||
| 59 | { |
||
| 60 | $cartController = new CartController(); |
||
| 61 | $taxClassId = Tax::where('state', $geoip_state)->orWhere('country', $geoip_country)->pluck('tax_classes_id')->first(); |
||
| 62 | $value = ''; |
||
| 63 | $rate = ''; |
||
| 64 | if ($taxClassId) { //if state equals the user State |
||
| 65 | |||
| 66 | $taxes = $cartController->getTaxByPriority($taxClassId); |
||
| 67 | |||
| 68 | // $taxes = $this->cartController::getTaxByPriority($taxClassId); |
||
| 69 | $value = $cartController->getValueForOthers($productid, $taxClassId, $taxes); |
||
| 70 | $rate = $value; |
||
| 71 | } else {//if Tax is selected for Any State Any Country |
||
| 72 | $taxClassId = Tax::where('country', '')->where('state', 'Any State')->pluck('tax_classes_id')->first(); |
||
| 73 | if ($taxClassId) { |
||
| 74 | $taxes = $cartController->getTaxByPriority($taxClassId); |
||
| 75 | $value = $cartController->getValueForOthers($productid, $taxClassId, $taxes); |
||
| 76 | $rate = $value; |
||
| 77 | } else { |
||
| 78 | $taxes = [0]; |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | return ['taxes'=>$taxes, 'value'=>$value, 'rate'=>$rate]; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Get tax when enabled. |
||
| 87 | */ |
||
| 88 | public function getTaxWhenEnable($productid, $taxs, $userid) |
||
| 89 | { |
||
| 90 | $rate = $this->getRate($productid, $taxs, $userid); |
||
| 91 | $taxs = ([$rate['taxs']['0']['name'], $rate['taxs']['0']['rate']]); |
||
| 92 | |||
| 93 | return $taxs; |
||
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * GeT Total Rate. |
||
| 98 | */ |
||
| 99 | public function getTotalRate($taxClassId, $productid, $taxs) |
||
| 110 | } |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Get Grandtotal. |
||
| 114 | **/ |
||
| 115 | public function getGrandTotal($code, $total, $cost, $productid, $currency) |
||
| 128 | } |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Get Message on Invoice Generation. |
||
| 132 | **/ |
||
| 133 | public function getMessage($items, $user_id) |
||
| 134 | { |
||
| 135 | if ($items) { |
||
| 136 | $this->sendmailClientAgent($user_id, $items->invoice_id); |
||
| 137 | $result = ['success' => \Lang::get('message.invoice-generated-successfully')]; |
||
| 138 | } else { |
||
| 139 | $result = ['fails' => \Lang::get('message.can-not-generate-invoice')]; |
||
| 140 | } |
||
| 141 | |||
| 142 | return $result; |
||
| 143 | } |
||
| 144 | |||
| 145 | /** |
||
| 146 | * get Subtotal. |
||
| 147 | */ |
||
| 148 | public function getSubtotal($user_currency, $cart) |
||
| 149 | { |
||
| 150 | if ($user_currency == 'INR') { |
||
| 151 | $subtotal = \App\Http\Controllers\Front\CartController::rounding($cart->getPriceSumWithConditions()); |
||
| 152 | } else { |
||
| 153 | $subtotal = \App\Http\Controllers\Front\CartController::rounding($cart->getPriceSumWithConditions()); |
||
| 154 | } |
||
| 155 | |||
| 156 | return $subtotal; |
||
| 157 | } |
||
| 158 | |||
| 159 | public function calculateTotal($rate, $total) |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 182 | |||
| 183 | public function whenDateNotSet($start, $end) |
||
| 189 | } |
||
| 190 | } |
||
| 191 | |||
| 192 | public function whenStartDateSet($start, $end, $now) |
||
| 199 | } |
||
| 200 | } |
||
| 201 | } |
||
| 202 | |||
| 203 | public function whenEndDateSet($start, $end, $now) |
||
| 209 | } |
||
| 210 | } |
||
| 211 | } |
||
| 212 | |||
| 213 | public function whenBothSet($start, $end, $now) |
||
| 223 |