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

77 lines
1.8 KiB
PHP
Raw Normal View History

2023-05-24 14:26:10 +02: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\Jobs\Company;
2023-05-24 15:06:27 +02:00
use App\Models\Client;
2023-05-24 14:26:10 +02:00
use App\Models\Company;
use App\Libraries\MultiDB;
use Illuminate\Bus\Queueable;
2023-05-24 15:06:27 +02:00
use App\Jobs\Client\UpdateTaxData;
2023-05-24 14:26:10 +02:00
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use App\Services\Tax\Providers\TaxProvider;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
2023-05-24 14:40:40 +02:00
use Illuminate\Queue\Middleware\WithoutOverlapping;
2023-05-24 14:26:10 +02:00
class CompanyTaxRate implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
2023-05-24 14:40:40 +02:00
public $tries = 1;
2023-05-24 14:26:10 +02:00
/**
* Create a new job instance.
*
* @param Company $company
*/
public function __construct(public Company $company)
{
}
public function handle()
{
2023-05-24 15:06:27 +02:00
if(!config('services.tax.zip_tax.key')) {
return;
}
2023-05-24 14:26:10 +02:00
MultiDB::setDB($this->company->db);
$tp = new TaxProvider($this->company);
2023-05-24 15:06:27 +02:00
2023-05-24 14:26:10 +02:00
$tp->updateCompanyTaxData();
2023-05-24 15:06:27 +02:00
$tp = null;
Client::query()
->where('company_id', $this->company->id)
->where('is_deleted', false)
->where('country_id', 840)
->whereNotNull('postal_code')
->whereNull('tax_data')
->whereFalse('is_tax_exempt')
->cursor()
->each(function ($client) {
(new UpdateTaxData($client, $this->company))->handle();
});
2023-05-24 14:26:10 +02:00
}
2023-05-24 14:40:40 +02:00
public function middleware()
{
return [new WithoutOverlapping($this->company->id)];
}
2023-05-24 14:26:10 +02:00
}