API to get a list of invoices
This commit is contained in:
parent
59302bd3e8
commit
1d209fdbdc
18
src/API.php
18
src/API.php
@ -164,8 +164,6 @@ final class API
|
||||
/**
|
||||
* Get a list of our clients
|
||||
*
|
||||
* select * from Account where Metadata.CreateTime > '2014-12-31'
|
||||
*
|
||||
* @param array $parameters
|
||||
* @return ListList
|
||||
* @throws \Exception
|
||||
@ -179,6 +177,22 @@ final class API
|
||||
return new ListList($this->execute('query',$parameters),$key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of our invoices
|
||||
*
|
||||
* @param array $parameters
|
||||
* @return ListList
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getInvoices(array $parameters=[]): ListList
|
||||
{
|
||||
Log::debug(sprintf('%s:Get a list of invoices',static::LOGKEY));
|
||||
$key = 'invoices';
|
||||
$parameters['query'] = 'select * from Invoice';
|
||||
|
||||
return new ListList($this->execute('query',$parameters),$key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the API call
|
||||
*
|
||||
|
@ -3,9 +3,10 @@
|
||||
namespace Intuit\Models;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Intuit\Traits\CompareAttributes;
|
||||
use Jenssegers\Model\Model;
|
||||
|
||||
use Intuit\Traits\CompareAttributes;
|
||||
|
||||
/*
|
||||
+"Customer": {#1760
|
||||
+"Taxable": false
|
||||
@ -54,11 +55,11 @@ final class Customer extends Model
|
||||
public function __get($key) {
|
||||
$keymap = [
|
||||
'id' => 'Id',
|
||||
'synctoken' => 'SyncToken',
|
||||
'active' => 'Active',
|
||||
'companyname' => 'CompanyName',
|
||||
'fullname' => 'FullyQualifiedName',
|
||||
'ref' => 'ResaleNum',
|
||||
'synctoken' => 'SyncToken',
|
||||
];
|
||||
|
||||
switch ($key) {
|
||||
|
144
src/Models/Invoice.php
Normal file
144
src/Models/Invoice.php
Normal file
@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace Intuit\Models;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Jenssegers\Model\Model;
|
||||
|
||||
use Intuit\Traits\CompareAttributes;
|
||||
|
||||
/*
|
||||
{#5766
|
||||
+"AllowIPNPayment": false
|
||||
+"AllowOnlinePayment": false
|
||||
+"AllowOnlineCreditCardPayment": false
|
||||
+"AllowOnlineACHPayment": false
|
||||
+"domain": "QBO"
|
||||
+"sparse": false
|
||||
+"Id": "192"
|
||||
+"SyncToken": "0"
|
||||
+"MetaData": {#5765
|
||||
+"CreateTime": "2018-06-09T07:41:49-07:00"
|
||||
+"LastUpdatedTime": "2018-06-09T07:41:49-07:00"
|
||||
}
|
||||
+"CustomField": array:1 [
|
||||
0 => {#5764
|
||||
+"DefinitionId": "1"
|
||||
+"Name": "Event Rep"
|
||||
+"Type": "StringType"
|
||||
}
|
||||
]
|
||||
+"DocNumber": "1022"
|
||||
+"TxnDate": "2018-06-10"
|
||||
+"CurrencyRef": {#5763
|
||||
+"value": "AUD"
|
||||
+"name": "Australian Dollar"
|
||||
}
|
||||
+"ExchangeRate": 1
|
||||
+"LinkedTxn": []
|
||||
+"Line": array:2 [
|
||||
0 => {#5762
|
||||
+"Id": "1"
|
||||
+"LineNum": 1
|
||||
+"Description": "Holiday party - gold level"
|
||||
+"Amount": 6000.0
|
||||
+"DetailType": "SalesItemLineDetail"
|
||||
+"SalesItemLineDetail": {#5761
|
||||
+"TaxInclusiveAmt": 6600.0
|
||||
+"ItemRef": {#5760
|
||||
+"value": "7"
|
||||
+"name": "Holiday party:Gold party"
|
||||
}
|
||||
+"UnitPrice": 2000
|
||||
+"Qty": 3
|
||||
+"ItemAccountRef": {#5759
|
||||
+"value": "1"
|
||||
+"name": "Services"
|
||||
}
|
||||
+"TaxCodeRef": {#5758
|
||||
+"value": "10"
|
||||
}
|
||||
}
|
||||
}
|
||||
1 => {#5757
|
||||
+"Amount": 6000.0
|
||||
+"DetailType": "SubTotalLineDetail"
|
||||
+"SubTotalLineDetail": {#5756}
|
||||
}
|
||||
]
|
||||
+"TxnTaxDetail": {#5755
|
||||
+"TotalTax": 600.0
|
||||
+"TaxLine": array:1 [
|
||||
0 => {#5754
|
||||
+"Amount": 600.0
|
||||
+"DetailType": "TaxLineDetail"
|
||||
+"TaxLineDetail": {#5753
|
||||
+"TaxRateRef": {#5752
|
||||
+"value": "20"
|
||||
}
|
||||
+"PercentBased": true
|
||||
+"TaxPercent": 10
|
||||
+"NetAmountTaxable": 6000.0
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
+"RecurDataRef": {#5751
|
||||
+"value": "11"
|
||||
}
|
||||
+"CustomerRef": {#5750
|
||||
+"value": "17"
|
||||
+"name": "Jordan Burgess"
|
||||
}
|
||||
+"CustomerMemo": {#5749
|
||||
+"value": "Thanks for your business! We appreciate referrals!"
|
||||
}
|
||||
+"BillAddr": {#5748
|
||||
+"Id": "15"
|
||||
+"Line1": "1 Success Way"
|
||||
+"City": "Sydney"
|
||||
+"CountrySubDivisionCode": "NSW"
|
||||
+"PostalCode": "2000"
|
||||
+"Lat": "-33.871226"
|
||||
+"Long": "150.897656"
|
||||
}
|
||||
+"FreeFormAddress": false
|
||||
+"SalesTermRef": {#5747
|
||||
+"value": "3"
|
||||
}
|
||||
+"DueDate": "2018-07-10"
|
||||
+"GlobalTaxCalculation": "TaxInclusive"
|
||||
+"TotalAmt": 6600.0
|
||||
+"HomeTotalAmt": 6600.0
|
||||
+"PrintStatus": "NotSet"
|
||||
+"EmailStatus": "NotSet"
|
||||
+"Balance": 6600.0
|
||||
+"HomeBalance": 6600.0
|
||||
}
|
||||
+"time": "2022-08-13T21:15:37.254-07:00"
|
||||
*/
|
||||
|
||||
final class Invoice extends Model
|
||||
{
|
||||
use CompareAttributes;
|
||||
|
||||
public function __get($key) {
|
||||
$keymap = [
|
||||
'id' => 'Id',
|
||||
'synctoken' => 'SyncToken',
|
||||
'invoice_num' => 'DocNumber',
|
||||
'invoice_date' => 'TxnDate',
|
||||
'due_date' => 'DueDate',
|
||||
];
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,8 @@ namespace Intuit\Response;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Intuit\Models\Customer;
|
||||
|
||||
use Intuit\Models\{Customer,Invoice};
|
||||
|
||||
/**
|
||||
* This is a Generic Intuit Response to API calls that produces a list of objects
|
||||
@ -22,6 +23,7 @@ class ListList extends Base implements \Countable, \ArrayAccess, \Iterator
|
||||
private ?int $counter = NULL;
|
||||
protected const TYPES = [
|
||||
'customers',
|
||||
'invoices',
|
||||
];
|
||||
|
||||
/**
|
||||
@ -124,13 +126,18 @@ class ListList extends Base implements \Countable, \ArrayAccess, \Iterator
|
||||
switch ($type) {
|
||||
case 'customers':
|
||||
$data = collect(Customer::hydrate($response->QueryResponse->Customer));
|
||||
$this->startPosition = $response->QueryResponse->startPosition;
|
||||
$this->maxResults = $response->QueryResponse->maxResults;
|
||||
break;
|
||||
|
||||
case 'invoices':
|
||||
$data = collect(Invoice::hydrate($response->QueryResponse->Invoice));
|
||||
break;
|
||||
|
||||
default: throw new \Exception('Unknown object type: '.$this->_type);
|
||||
}
|
||||
|
||||
$this->startPosition = $response->QueryResponse->startPosition;
|
||||
$this->maxResults = $response->QueryResponse->maxResults;
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user