Jump to content

Add Client Via Api Tax Bug


WebhostingNZ.com

Recommended Posts

Hi,

 

Blesta: 3.6.1

 

After adding a VAT / TAX number to a company creating a client without giving a tax number, auto inserts the companies tax number into the client.  This does not happen when using Blesta interface to create the client, only when using the API.  See below the code used to insert the client.

 

$data = array(
   'vars' => array(
   'username' => "$email",
   'new_password' => "$pass",
   'confirm_password' => "$pass",
   'client_group_id' => "6",
   'first_name' => "$fname",
   'last_name' => "$lname",
   'email' => "$email",
   'country' => "UK",
   'send_registration_email' => "true"
   )
);
 
 
 
$response = $api->get("clients", "create", $data);

 

 

In the database if you add via Blesta interface in the table 'client_settings' it will create an entry 'tax_id' with value blank.  Using the API does not create this line and without it the company tax is used, this also stops VAT being charged on invoices without manually editing every client, or running an SQL query to insert the tax_id line for every customer.
 
When a client does not have a tax_id line in the client_settings table it should read that as no tax, not read the company tax line.
 
Looking at what I should be passing to the API it looks like I should be passing a settings array which would include the tax_id.  Should it not then fail if not all required is sent?
Link to comment
Share on other sites

Hi Tyson,

 

Sorry I should have mentioned that.  On the /clients/edit/ page after they have been imported.  I run a query on the database the only time the tax code was mentioned was in company_settings once so I know if it finds no tax_id for the customer, it reads the company one instead if there is one.

 

Steps to test.

 

1) Setup company with company tax number

2) create customer with my above API code, OR create customer with Blesta web interface and delete the database line tax_id for the customer under company_settings in the database.

3) View the edit customer page in Blesta, you will see the company tax ID showing.

 

I have just tested the above creating the customer in Blesta then manually removing the tax_id line and as expected the company tax number shows under the customer.

 

This also affects invoices as I mentioned above.

Link to comment
Share on other sites

Thanks for the information. However, I'm not able to duplicate that behavior. Could you run the following query and let me know the results?

SELECT * FROM `company_settings` WHERE `key` = 'tax_id';

Assuming you only have one company, there should be one record found. What data is contained? Feel free to omit the `value`.

Link to comment
Share on other sites

mysql> SELECT * FROM `company_settings` WHERE `key` = 'tax_id';
+--------+------------+-----------+-----------+---------+
| key    | company_id | value     | encrypted | inherit |
+--------+------------+-----------+-----------+---------+
| tax_id |             1 |               |            0 |         0 |
| tax_id |             2 |               |            0 |         1 |
| tax_id |             3 |               |            0 |         1 |
| tax_id |             4 |               |            0 |         1 |
| tax_id |             5 |               |            0 |         1 |
| tax_id |             6 | 123456789|        0 |         1 |
+--------+------------+-----------+-----------+---------+
6 rows in set (0.00 sec)

 

This is only happening with company 6.  This company tax number is only in one place in the the database as above that is in the company_settings, it's not found in the client_settings anywhere.  But when the key tax_id entry is missing from client_settings for a customer of company 6 it will use the tax_id for the company.

 

I could make a quick video to prove this or I could PM you login details to my install so you can see for yourself if you would like.

Link to comment
Share on other sites

Thanks for listing the data.

 

I could make a quick video to prove this or I could PM you login details to my install so you can see for yourself if you would like.

No, that's not necessary. I believe you.

 

The problem is that company 6 is set to allow inheritance of the tax_id field. Once that is disabled, clients without a tax ID will no longer inherit the company tax ID.

 

mysql> SELECT * FROM `company_settings` WHERE `key` = 'tax_id';
+--------+------------+-----------+-----------+---------+
| key    | company_id | value     | encrypted | inherit |
+--------+------------+-----------+-----------+---------+
| tax_id |             1 |               |            0 |         0 |
| tax_id |             2 |               |            0 |         1 |
| tax_id |             3 |               |            0 |         1 |
| tax_id |             4 |               |            0 |         1 |
| tax_id |             5 |               |            0 |         1 |
| tax_id |             6 | 123456789|        0 |         1 |  <--- should be 0
+--------+------------+-----------+-----------+---------+
6 rows in set (0.00 sec)
 
The issue should be resolved once you run this query:
UPDATE `company_settings` SET `inherit` = 0 WHERE `company_id` = 6 AND `key` = 'tax_id';

The inheritance may not be set correctly when you create a new company by cloning the settings of another, and that's something we can look into and resolve for the next release as apart of CORE-1942.

Link to comment
Share on other sites

  • 2 months later...
Guest
This topic is now closed to further replies.
×
×
  • Create New...