Moved some basic intuit commands to leenooks/intuit

This commit is contained in:
Deon George 2024-08-12 20:58:35 +10:00
parent 5abc07b712
commit bab1f45234
7 changed files with 32 additions and 211 deletions

View File

@ -1,56 +0,0 @@
<?php
namespace App\Console\Commands\Intuit;
use GuzzleHttp\Exception\ConnectException;
use Illuminate\Console\Command;
use Intuit\Exceptions\ConnectionIssueException;
use App\Models\{ProviderOauth,User};
class AccountGet extends Command
{
private const provider = 'intuit';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'intuit:account:get'
.' {id : Account ID}'
.' {user? : User Email}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Get an account from quickbooks';
/**
* Execute the console command.
*
* @return int
*/
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));
try {
$api = $to->API();
dump($api->getAccountQuery($this->argument('id')));
} catch (ConnectException|ConnectionIssueException $e) {
$this->error($e->getMessage());
return self::FAILURE;
}
return self::SUCCESS;
}
}

View File

@ -1,56 +0,0 @@
<?php
namespace App\Console\Commands\Intuit;
use GuzzleHttp\Exception\ConnectException;
use Illuminate\Console\Command;
use Intuit\Exceptions\ConnectionIssueException;
use App\Models\{ProviderOauth,User};
class InvoiceGet extends Command
{
private const provider = 'intuit';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'intuit:invoice:get'
.' {id : Invoice ID}'
.' {user? : User Email}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Get an invoice from the quickbooks';
/**
* Execute the console command.
*
* @return int
*/
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));
try {
$api = $to->API();
dump($api->getInvoiceQuery($this->argument('id')));
} catch (ConnectException|ConnectionIssueException $e) {
$this->error($e->getMessage());
return self::FAILURE;
}
return self::SUCCESS;
}
}

View File

@ -3,13 +3,17 @@
namespace App\Console\Commands\Intuit;
use Illuminate\Console\Command;
use Intuit\Exceptions\NotTokenException;
use Intuit\Traits\ProviderTokenTrait;
use App\Models\{Product,ProviderOauth,User};
use App\Jobs\AccountingItemSync as Job;
use App\Models\Product;
/**
* Return a list of products and their accounting id
*/
class ItemList extends Command
{
private const provider = 'intuit';
use ProviderTokenTrait;
/**
* The name and signature of the console command.
@ -30,16 +34,11 @@ class ItemList 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 (($x=$so->tokens->where('user_id',$uo->id))->count() !== 1)
abort(500,sprintf('Unknown Tokens for [%s]',$uo->email));
$to = $x->pop();
$to = $this->providerToken($this->argument('user'));
// Current Products used by services
$products = Product::select(['products.*'])
@ -48,19 +47,12 @@ class ItemList extends Command
->where('services.active',TRUE)
->get();
$api = $so->API($to,TRUE); // @todo Remove TRUE
$acc = $api->getItems()->pluck('pid','FullyQualifiedName');
foreach ($products as $po) {
if (! $po->accounting)
$this->error(sprintf('Product [%d](%s) doesnt have accounting set',$po->id,$po->name));
elseif ($acc->has($po->accounting) === FALSE)
$this->error(sprintf('Product [%d](%s) accounting [%s] doesnt exist?',$po->id,$po->name,$po->accounting));
if (! $x=$po->provider_ref($to->provider))
$this->error(sprintf('Product [%03d](%s) doesnt have accounting set',$po->id,$po->name));
else
$this->info(sprintf('Product [%d](%s) set to accounting [%s]',$po->id,$po->name,$po->accounting));
$this->info(sprintf('Product [%03d](%s) set to accounting [%s]',$po->id,$po->name,$x));
}
return self::SUCCESS;

View File

@ -1,61 +0,0 @@
<?php
namespace App\Console\Commands\Intuit;
use GuzzleHttp\Exception\ConnectException;
use Illuminate\Console\Command;
use Intuit\Exceptions\ConnectionIssueException;
use App\Jobs\AccountingPaymentSync as Job;
use App\Models\{ProviderOauth,User};
class PaymentGet extends Command
{
private const provider = 'intuit';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'accounting:payment:get'
.' {id : Payment ID}'
.' {user? : User Email}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Get a payment from the accounting provider';
/**
* Execute the console command.
*
* @return int
*/
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));
try {
$api = $to->API();
$acc = $api->getPayment($this->argument('id'));
dump($acc);
} catch (ConnectException|ConnectionIssueException $e) {
$this->error($e->getMessage());
return Command::FAILURE;
}
if ($acc)
Job::dispatchSync($to,$acc);
return self::SUCCESS;
}
}

View File

@ -11,6 +11,8 @@ trait ProviderRef
{
public function provider_ref(ProviderOauth $poo): ?string
{
return (($x=$this->providers->where('pivot.provider_oauth_id',$poo->id))->count() === 1) ? $x->pop()->pivot->ref : NULL;
return (($x=$this->providers->where('pivot.provider_oauth_id',$poo->id))->count() === 1)
? $x->pop()->pivot->ref
: NULL;
}
}

View File

@ -16,7 +16,7 @@
"laravel/socialite": "^5.15",
"laravel/ui": "^4.5",
"leenooks/dreamscape": "^0.1.4",
"leenooks/intuit": "^0.1.11",
"leenooks/intuit": "^0.2",
"leenooks/laravel": "^11.1",
"leenooks/passkey": "^0.2",
"paypal/paypal-checkout-sdk": "^1.0",

32
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "72b6dd9641c690d74fbc9885084918d3",
"content-hash": "ae477f3c8e083f7f127d92de0a070e8d",
"packages": [
{
"name": "barryvdh/laravel-snappy",
@ -3021,11 +3021,11 @@
},
{
"name": "leenooks/intuit",
"version": "0.1.11",
"version": "0.2.0",
"source": {
"type": "git",
"url": "https://gitea.dege.au/laravel/intuit.git",
"reference": "c9523f595b0e860ccf8d8be327ad1903fe63c686"
"reference": "0cc4a217bdeabf0ad7973d9d159c823125492174"
},
"require": {
"jenssegers/model": "^1.5"
@ -3055,7 +3055,7 @@
"laravel",
"leenooks"
],
"time": "2024-08-11T11:05:29+00:00"
"time": "2024-08-12T10:55:41+00:00"
},
{
"name": "leenooks/laravel",
@ -4017,16 +4017,16 @@
},
{
"name": "phpseclib/phpseclib",
"version": "3.0.39",
"version": "3.0.41",
"source": {
"type": "git",
"url": "https://github.com/phpseclib/phpseclib.git",
"reference": "211ebc399c6e73c225a018435fe5ae209d1d1485"
"reference": "621c73f7dcb310b61de34d1da4c4204e8ace6ceb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/211ebc399c6e73c225a018435fe5ae209d1d1485",
"reference": "211ebc399c6e73c225a018435fe5ae209d1d1485",
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/621c73f7dcb310b61de34d1da4c4204e8ace6ceb",
"reference": "621c73f7dcb310b61de34d1da4c4204e8ace6ceb",
"shasum": ""
},
"require": {
@ -4107,7 +4107,7 @@
],
"support": {
"issues": "https://github.com/phpseclib/phpseclib/issues",
"source": "https://github.com/phpseclib/phpseclib/tree/3.0.39"
"source": "https://github.com/phpseclib/phpseclib/tree/3.0.41"
},
"funding": [
{
@ -4123,7 +4123,7 @@
"type": "tidelift"
}
],
"time": "2024-06-24T06:27:33+00:00"
"time": "2024-08-12T00:13:54+00:00"
},
{
"name": "psr/clock",
@ -9182,16 +9182,16 @@
},
{
"name": "sebastian/comparator",
"version": "6.0.1",
"version": "6.0.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/comparator.git",
"reference": "131942b86d3587291067a94f295498ab6ac79c20"
"reference": "450d8f237bd611c45b5acf0733ce43e6bb280f81"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/131942b86d3587291067a94f295498ab6ac79c20",
"reference": "131942b86d3587291067a94f295498ab6ac79c20",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/450d8f237bd611c45b5acf0733ce43e6bb280f81",
"reference": "450d8f237bd611c45b5acf0733ce43e6bb280f81",
"shasum": ""
},
"require": {
@ -9247,7 +9247,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/comparator/issues",
"security": "https://github.com/sebastianbergmann/comparator/security/policy",
"source": "https://github.com/sebastianbergmann/comparator/tree/6.0.1"
"source": "https://github.com/sebastianbergmann/comparator/tree/6.0.2"
},
"funding": [
{
@ -9255,7 +9255,7 @@
"type": "github"
}
],
"time": "2024-07-03T04:48:07+00:00"
"time": "2024-08-12T06:07:25+00:00"
},
{
"name": "sebastian/complexity",