Intuit commands updates

This commit is contained in:
Deon George 2024-08-12 23:31:59 +10:00
parent bab1f45234
commit 1b581e9feb
2 changed files with 15 additions and 19 deletions

View File

@ -3,14 +3,16 @@
namespace App\Console\Commands\Intuit;
use Illuminate\Console\Command;
use Intuit\Exceptions\NotTokenException;
use Intuit\Jobs\AccountingCustomerUpdate;
use Intuit\Models\Customer as AccAccount;
use Intuit\Traits\ProviderTokenTrait;
use App\Models\{Account,ProviderOauth,User};
use App\Models\Account;
class AccountAdd extends Command
{
private const provider = 'intuit';
use ProviderTokenTrait;
/**
* The name and signature of the console command.
@ -32,15 +34,10 @@ class AccountAdd extends Command
* Execute the console command.
*
* @return int
* @throws NotTokenException
*/
public function handle()
{
$uo = User::where('email',$this->argument('user') ?: config('osb.admin'))->singleOrFail();
$so = ProviderOauth::where('name',self::provider)->singleOrFail();
if (! ($to=$so->token($uo)))
abort(500,sprintf('Unknown Tokens for [%s]',$uo->email));
$o = Account::findOrFail($this->argument('id'));
$acc = new AccAccount;
@ -53,6 +50,9 @@ class AccountAdd extends Command
$acc->FullyQualifiedName = $o->name;
$acc->Active = (bool)$o->active;
return AccountingCustomerUpdate::dispatchSync($to,$acc);
return AccountingCustomerUpdate::dispatchSync(
$this->providerToken($this->argument('user')),
$acc
);
}
}

View File

@ -3,16 +3,17 @@
namespace App\Console\Commands\Intuit;
use Illuminate\Console\Command;
use Intuit\Exceptions\NotTokenException;
use Intuit\Traits\ProviderTokenTrait;
use App\Models\{ProviderOauth,User};
use App\Jobs\AccountingAccountSync as Job;
use App\Jobs\AccountingAccountSync;
/**
* Synchronise Customers with Accounts
*/
class AccountSync extends Command
{
private const provider = 'intuit';
use ProviderTokenTrait;
/**
* The name and signature of the console command.
@ -33,16 +34,11 @@ class AccountSync extends Command
* Execute the console command.
*
* @return int
* @throws NotTokenException
*/
public function handle()
{
$uo = User::where('email',$this->argument('user') ?: config('osb.admin'))->singleOrFail();
$so = ProviderOauth::where('name',self::provider)->singleOrFail();
if (! ($to=$so->token($uo)))
abort(500,sprintf('Unknown Tokens for [%s]',$uo->email));
Job::dispatchSync($to);
AccountingAccountSync::dispatchSync($this->providerToken($this->argument('user')));
return self::SUCCESS;
}