/**
  * Sets the "state" relation with the code specified, model lookup used.
  * @param string $code
  */
 public function setStateCodeAttribute($code)
 {
     if (!($state = State::whereCode($code)->first())) {
         return;
     }
     $this->model->state = $state;
 }
 public function boot()
 {
     $this->app->bind('locationtowns', 'VojtaSvoboda\\LocationTown\\Models\\Town');
     State::extend(function ($model) {
         $model->hasMany['towns'] = 'VojtaSvoboda\\LocationTown\\Models\\Town';
     });
     $this->initMenuItems();
 }
 public function getStateFilterOptions()
 {
     return State::orderBy('name')->lists('name', 'id');
 }
Example #4
0
 public function getDefaultStateOptions()
 {
     return State::getNameList($this->default_country);
 }
Example #5
0
 public function setDefaults()
 {
     if (!$this->country_id) {
         $this->country = Country::first();
     }
     if (!$this->state_id) {
         $this->state = State::first();
     }
     if (!$this->template_id) {
         $this->template_id = InvoiceTemplate::pluck('id');
     }
 }
Example #6
0
 public function getStateOptions()
 {
     return State::getNameList($this->country_id);
 }
Example #7
0
 /**
  * Returns rate information for a given location, optionally ignoring by priority.
  * @param  array $locationInfo
  * @param  array $ignoredPriorities
  * @return object
  */
 protected function getRate($locationInfo, $ignoredPriorities = [])
 {
     $country = Country::find($locationInfo->country_id);
     if (!$country) {
         return null;
     }
     $state = null;
     if (strlen($locationInfo->state_id)) {
         $state = State::find($locationInfo->state_id);
     }
     $countryCode = $country->code;
     $stateCode = $state ? mb_strtoupper($state->code) : '*';
     $zipCode = str_replace(' ', '', trim(strtoupper($locationInfo->zip)));
     if (!strlen($zipCode)) {
         $zipCode = '*';
     }
     $city = str_replace('-', '', str_replace(' ', '', trim(mb_strtoupper($locationInfo->city))));
     if (!strlen($city)) {
         $city = '*';
     }
     $rate = null;
     foreach ($this->rates as $row) {
         $taxPriority = isset($row['priority']) ? $row['priority'] : 1;
         if (in_array($taxPriority, $ignoredPriorities)) {
             continue;
         }
         if ($row['country'] != $countryCode && $row['country'] != '*') {
             continue;
         }
         if (mb_strtoupper($row['state']) != $stateCode && $row['state'] != '*') {
             continue;
         }
         $rowZip = isset($row['zip']) && strlen($row['zip']) ? str_replace(' ', '', $row['zip']) : '*';
         if ($rowZip != $zipCode && $rowZip != '*') {
             continue;
         }
         $rowCity = isset($row['city']) && strlen($row['city']) ? str_replace('-', '', str_replace(' ', '', mb_strtoupper($row['city']))) : '*';
         if ($rowCity != $city && $rowCity != '*') {
             continue;
         }
         $compound = isset($row['compound']) ? $row['compound'] : 0;
         if (preg_match('/^[0-9]+$/', $compound)) {
             $compound = (int) $compound;
         } else {
             $compound = $compound == 'Y' || $compound == 'YES';
         }
         $rateObj = ['rate' => $row['rate'], 'priority' => $taxPriority, 'name' => isset($row['tax_name']) ? $row['tax_name'] : 'TAX', 'compound' => $compound];
         $rate = (object) $rateObj;
         break;
     }
     return $rate;
 }
Example #8
0
 protected function stateInput($country, $state = null)
 {
     $adOptions = $this->property('stdSelect') ? [] : ['class' => 'form-control custom-select'];
     $this->statelist = State::formSelect('state', $country, $state, $adOptions);
     return $this->statelist;
 }