Moved some basic intuit commands to leenooks/intuit
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user