Added Item/Category api queries
This commit is contained in:
parent
1d209fdbdc
commit
179c96ca5d
34
src/API.php
34
src/API.php
@ -161,6 +161,22 @@ final class API
|
|||||||
return new Customer($this->execute('customer/'.$id,$parameters));
|
return new Customer($this->execute('customer/'.$id,$parameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of our classes
|
||||||
|
*
|
||||||
|
* @param array $parameters
|
||||||
|
* @return ListList
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function getClasses(array $parameters=[]): ListList
|
||||||
|
{
|
||||||
|
Log::debug(sprintf('%s:Get a list of classes',static::LOGKEY));
|
||||||
|
$key = 'classes';
|
||||||
|
$parameters['query'] = 'select * from Class';
|
||||||
|
|
||||||
|
return new ListList($this->execute('query',$parameters),$key);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of our clients
|
* Get a list of our clients
|
||||||
*
|
*
|
||||||
@ -193,10 +209,26 @@ final class API
|
|||||||
return new ListList($this->execute('query',$parameters),$key);
|
return new ListList($this->execute('query',$parameters),$key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of our items
|
||||||
|
*
|
||||||
|
* @param array $parameters
|
||||||
|
* @return ListList
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function getItems(array $parameters=[]): ListList
|
||||||
|
{
|
||||||
|
Log::debug(sprintf('%s:Get a list of items',static::LOGKEY));
|
||||||
|
$key = 'items';
|
||||||
|
$parameters['query'] = 'select * from Item';
|
||||||
|
|
||||||
|
return new ListList($this->execute('query',$parameters),$key);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup the API call
|
* Setup the API call
|
||||||
*
|
*
|
||||||
* @param $url
|
* @param string $url
|
||||||
* @param array $parameters
|
* @param array $parameters
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
* @return \CurlHandle
|
* @return \CurlHandle
|
||||||
|
35
src/Models/Category.php
Normal file
35
src/Models/Category.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Intuit\Models;
|
||||||
|
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
use Jenssegers\Model\Model;
|
||||||
|
|
||||||
|
use Intuit\Traits\CompareAttributes;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
+"time": "2022-08-13T21:15:37.254-07:00"
|
||||||
|
*/
|
||||||
|
|
||||||
|
final class Category extends Model
|
||||||
|
{
|
||||||
|
use CompareAttributes;
|
||||||
|
|
||||||
|
public function __get($key) {
|
||||||
|
$keymap = [
|
||||||
|
'id' => 'Id',
|
||||||
|
'synctoken' => 'SyncToken',
|
||||||
|
];
|
||||||
|
|
||||||
|
switch ($key) {
|
||||||
|
case 'created_at':
|
||||||
|
return object_get($this->getAttribute('MetaData'),'CreateTime');
|
||||||
|
case 'updated_at':
|
||||||
|
return object_get($this->getAttribute('MetaData'),'LastUpdatedTime');
|
||||||
|
|
||||||
|
default:
|
||||||
|
return parent::__get(Arr::get($keymap,$key,$key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
77
src/Models/Item.php
Normal file
77
src/Models/Item.php
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Intuit\Models;
|
||||||
|
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
use Jenssegers\Model\Model;
|
||||||
|
|
||||||
|
use Intuit\Traits\CompareAttributes;
|
||||||
|
|
||||||
|
/*
|
||||||
|
{#1927
|
||||||
|
+"Name": "Silver retreat"
|
||||||
|
+"Description": "Retreat - silver level"
|
||||||
|
+"Active": true
|
||||||
|
+"SubItem": true
|
||||||
|
+"ParentRef": {#1928
|
||||||
|
+"value": "25"
|
||||||
|
+"name": "Retreat"
|
||||||
|
}
|
||||||
|
+"Level": 1
|
||||||
|
+"FullyQualifiedName": "Retreat:Silver retreat"
|
||||||
|
+"Taxable": false
|
||||||
|
+"SalesTaxIncluded": false
|
||||||
|
+"UnitPrice": 1000
|
||||||
|
+"Type": "Service"
|
||||||
|
+"IncomeAccountRef": {#1929
|
||||||
|
+"value": "1"
|
||||||
|
+"name": "Services"
|
||||||
|
}
|
||||||
|
+"PurchaseTaxIncluded": false
|
||||||
|
+"PurchaseCost": 0
|
||||||
|
+"ExpenseAccountRef": {#1930
|
||||||
|
+"value": "89"
|
||||||
|
+"name": "Purchases"
|
||||||
|
}
|
||||||
|
+"TrackQtyOnHand": false
|
||||||
|
+"SalesTaxCodeRef": {#1931
|
||||||
|
+"value": "10"
|
||||||
|
+"name": "GST"
|
||||||
|
}
|
||||||
|
+"PurchaseTaxCodeRef": {#1932
|
||||||
|
+"value": "2"
|
||||||
|
+"name": "GST on non-capital"
|
||||||
|
}
|
||||||
|
+"domain": "QBO"
|
||||||
|
+"sparse": false
|
||||||
|
+"Id": "15"
|
||||||
|
+"SyncToken": "1"
|
||||||
|
+"MetaData": {#1933
|
||||||
|
+"CreateTime": "2018-02-21T20:30:11-08:00"
|
||||||
|
+"LastUpdatedTime": "2018-06-15T21:19:52-07:00"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
+"time": "2022-08-13T21:15:37.254-07:00"
|
||||||
|
*/
|
||||||
|
|
||||||
|
final class Item extends Model
|
||||||
|
{
|
||||||
|
use CompareAttributes;
|
||||||
|
|
||||||
|
public function __get($key) {
|
||||||
|
$keymap = [
|
||||||
|
'id' => 'Id',
|
||||||
|
'synctoken' => 'SyncToken',
|
||||||
|
];
|
||||||
|
|
||||||
|
switch ($key) {
|
||||||
|
case 'created_at':
|
||||||
|
return object_get($this->getAttribute('MetaData'),'CreateTime');
|
||||||
|
case 'updated_at':
|
||||||
|
return object_get($this->getAttribute('MetaData'),'LastUpdatedTime');
|
||||||
|
|
||||||
|
default:
|
||||||
|
return parent::__get(Arr::get($keymap,$key,$key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,13 +2,10 @@
|
|||||||
|
|
||||||
namespace Intuit\Response;
|
namespace Intuit\Response;
|
||||||
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Jenssegers\Model\Model;
|
use Jenssegers\Model\Model;
|
||||||
|
|
||||||
use Intuit\Models\Customer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This parent class handles responses received from Intuit
|
* This parent class handles responses received from Intuit
|
||||||
*
|
*
|
||||||
|
@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
namespace Intuit\Response;
|
namespace Intuit\Response;
|
||||||
|
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
use Intuit\Models\{Customer,Invoice};
|
use Intuit\Models\{Category,Customer,Invoice,Item};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a Generic Intuit Response to API calls that produces a list of objects
|
* This is a Generic Intuit Response to API calls that produces a list of objects
|
||||||
@ -22,8 +23,10 @@ class ListList extends Base implements \Countable, \ArrayAccess, \Iterator
|
|||||||
|
|
||||||
private ?int $counter = NULL;
|
private ?int $counter = NULL;
|
||||||
protected const TYPES = [
|
protected const TYPES = [
|
||||||
'customers',
|
'classes' => 'Class',
|
||||||
'invoices',
|
'customers' => 'Customer',
|
||||||
|
'invoices' => 'Invoice',
|
||||||
|
'items' => 'Item',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,7 +40,7 @@ class ListList extends Base implements \Countable, \ArrayAccess, \Iterator
|
|||||||
{
|
{
|
||||||
parent::__construct($response);
|
parent::__construct($response);
|
||||||
|
|
||||||
if (! in_array($type,self::TYPES))
|
if (! in_array($type,array_keys(self::TYPES)))
|
||||||
throw new \Exception('Unknown data type: '.$type);
|
throw new \Exception('Unknown data type: '.$type);
|
||||||
|
|
||||||
if (object_get($response,'time'))
|
if (object_get($response,'time'))
|
||||||
@ -123,13 +126,24 @@ class ListList extends Base implements \Countable, \ArrayAccess, \Iterator
|
|||||||
*/
|
*/
|
||||||
private function data(object $response,string $type): Collection
|
private function data(object $response,string $type): Collection
|
||||||
{
|
{
|
||||||
|
if (! ($x=object_get($response->QueryResponse,Arr::get(self::TYPES,$type))))
|
||||||
|
return collect();
|
||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
case 'classes':
|
||||||
|
$data = collect(Category::hydrate($x));
|
||||||
|
break;
|
||||||
|
|
||||||
case 'customers':
|
case 'customers':
|
||||||
$data = collect(Customer::hydrate($response->QueryResponse->Customer));
|
$data = collect(Customer::hydrate($x));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'invoices':
|
case 'invoices':
|
||||||
$data = collect(Invoice::hydrate($response->QueryResponse->Invoice));
|
$data = collect(Invoice::hydrate($x));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'items':
|
||||||
|
$data = collect(Item::hydrate($x));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: throw new \Exception('Unknown object type: '.$this->_type);
|
default: throw new \Exception('Unknown object type: '.$this->_type);
|
||||||
|
Loading…
Reference in New Issue
Block a user