Uploaded image for project: 'Blesta Core'
  1. Blesta Core
  2. CORE-4237

Vat tax exempt status not always set properly

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.1.0-b1
    • Component/s: None
    • Labels:
      None

      Description

      To reproduce:

      • Enable vat validation
      • Create a client without a vat id
      • Edit the client to use a valid vat id and a different country than the one they were created with
      • Revisit the edit page and see that the client is not marked as tax exempt

      The reason this bug occurs is that the Clients model looks at the client's country to validate the tax_id setting, but it does so while in a transaction and thus fetches the previous country and not the newly submitted one. To fix this we'll need to resave the tax_id after the country change has been commited.

      To resolve:

      In Clients::setSettings() change

              if (
                  $company_settings['enable_eu_vat'] == 'true'
                  && $company_settings['tax_exempt_eu_vat'] == 'true'
                  && isset($vars['tax_exempt'])
                  && isset($vars['tax_id'])
                  && in_array($client->country, $europe_tax->getCountries())
              ) {
      

      To

              if (
                  $company_settings['enable_eu_vat'] == 'true'
                  && $company_settings['tax_exempt_eu_vat'] == 'true'
                  && isset($vars['tax_id'])
                  && in_array($client->country, $europe_tax->getCountries())
              ) {
      

      In AdminClients::edit() change

                      // Success, commit
                      $this->Clients->commit();
      
                      $this->flashMessage('message', Language::_('AdminClients.!success.client_updated', true));
                      $this->redirect($this->base_uri . 'clients/view/' . $client->id . '/');
      

      To

                      // Success, commit
                      $this->Clients->commit();
                      if (isset($settings['tax_id'])) {
                          $this->Clients->setSettings(
                              $client->id,
                              ['tax_id' => $settings['tax_id']],
                              ['tax_id', 'tax_exempt']
                          );
                      }
      
                      $this->flashMessage('message', Language::_('AdminClients.!success.client_updated', true));
                      $this->redirect($this->base_uri . 'clients/view/' . $client->id . '/');
      

      In ClientMain::edit() change

                      // Success, commit
                      $this->Clients->commit();
      
                      $this->flashMessage('message', Language::_('ClientMain.!success.client_updated', true));
                      $this->redirect($this->base_uri);
      

      To

                      // Success, commit
                      $this->Clients->commit();
                      if (isset($new_client_settings['tax_id'])) {
                          $this->Clients->setSettings(
                              $this->client->id,
                              ['tax_id' => $new_client_settings['tax_id']],
                              ['tax_id', 'tax_exempt']
                          );
                      }
      
                      $this->flashMessage('message', Language::_('ClientMain.!success.client_updated', true));
                      $this->redirect($this->base_uri);
      

      In Clients::create() change

                  // Success, commit
                  $this->commit();
      
                  $client = $this->get($client_id);
      

      To

                  // Success, commit
                  $this->commit();
      
                  if (isset($vars['settings']['tax_id'])) {
                      $this->setSettings(
                          $vars['client_id'],
                          ['tax_id' => $vars['settings']['tax_id']],
                          ['tax_id', 'tax_exempt']
                      );
                  }
      
                  $client = $this->get($client_id);
      

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            jonathan Jonathan Reissmueller
            Reporter:
            jonathan Jonathan Reissmueller
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Fix Release Date:
              8/Jun/21

              Time Tracking

              Estimated:
              Original Estimate - Not Specified
              Not Specified
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 16 minutes
              16m

                Agile