1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 21:52:35 +01:00
invoiceninja/app/Services/Company/CompanyService.php

78 lines
2.1 KiB
PHP
Raw Normal View History

2023-11-24 23:09:17 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Services\Company;
use App\Factory\TaxRateFactory;
2023-11-26 08:41:42 +01:00
use App\Models\Company;
use App\Models\User;
2023-11-24 23:09:17 +01:00
2023-11-26 08:41:42 +01:00
class CompanyService
{
2023-11-24 23:09:17 +01:00
public function __construct(public Company $company)
{
}
public function localizeCompany(User $user)
{
try {
$taxes = [];
switch ($this->company->settings->country_id) {
case '36': // Australia
$taxes[] = ['name' => 'GST', 'rate' => 10];
break;
case '40': // Austria
$taxes[] = ['name' => 'USt', 'rate' => 20];
break;
case '56': // Belgium
$taxes[] = ['name' => 'BTW', 'rate' => 21];
break;
case '100': // Bulgaria
$taxes[] = ['name' => 'ДДС', 'rate' => 20];
break;
case '250': // France
$taxes[] = ['name' => 'TVA', 'rate' => 20];
break;
case '276': // Germany
$taxes[] = ['name' => 'MwSt', 'rate' => 19];
break;
case '554': // New Zealand
$taxes[] = ['name' => 'GST', 'rate' => 15];
break;
case '710': // South Africa
$taxes[] = ['name' => 'VAT', 'rate' => 15];
break;
case '724': // Spain
$taxes[] = ['name' => 'IVA', 'rate' => 21];
break;
default:
return;
}
foreach($taxes as $tax) {
$tax_rate = TaxRateFactory::create($this->company->id, $user->id);
$tax_rate->fill($tax);
$tax_rate->save();
}
2023-11-26 08:41:42 +01:00
} catch(\Exception $e) {
2023-11-24 23:09:17 +01:00
nlog($e->getMessage());
}
}
2023-11-26 08:41:42 +01:00
}