-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathquery.php
More file actions
77 lines (65 loc) · 3.12 KB
/
query.php
File metadata and controls
77 lines (65 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* Copyright 2020 Sage Intacct, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "LICENSE" file accompanying this file. This file is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
require __DIR__ . '/bootstrap.php';
use Intacct\Functions\Common\NewQuery\Query;
use Intacct\Functions\Common\NewQuery\QueryFilter\Filter;
use Intacct\Functions\Common\NewQuery\QueryFilter\OrOperator;
use Intacct\Functions\Common\NewQuery\QueryOrderBy\OrderBuilder;
use Intacct\Functions\Common\NewQuery\QuerySelect\SelectBuilder;
try {
$filter = new OrOperator([ ( new Filter('CUSTOMERID') )->like('c%'),
( new Filter('CUSTOMERID') )->like('1%') ]);
$order = ( new OrderBuilder())->descending('CUSTOMERID')->getOrders();
$fields = ( new SelectBuilder() )->fields([ 'CUSTOMERID', 'CUSTOMERNAME' ])
->sum('TOTALDUE')
->getFields();
$res = ( new Query() )->select($fields)
->from('ARINVOICE')
->filter($filter) // Comment out this line to see all invoices without any filtering
->caseInsensitive(true)
->pageSize('100')
->orderBy($order);
$logger->info('Executing query to Intacct API');
$response = $client->execute($res);
$result = $response->getResult();
$json_data = json_decode(json_encode($result->getData()), 1);
if ( $json_data && (is_array($json_data)) && (count($json_data) >= 1)) {
echo "Success! Total number of results: " . $result->getTotalCount() . PHP_EOL . PHP_EOL;
echo "First ARINVOICE result found: " . PHP_EOL;
foreach ( $json_data[0] as $key => $value ) {
echo " '$key' => '$value'" . PHP_EOL;
}
echo "See the log file (logs/intacct.html) for the complete list of results." . PHP_EOL;
echo "" . PHP_EOL;
} else {
echo "The query executed, but no ARINVOICE objects met the query criteria." . PHP_EOL;
echo "Either modify the filter or comment it out from the query." . PHP_EOL;
echo "See the log file (logs/intacct.html) for the XML request." . PHP_EOL;
}
$logger->debug('Query successful', [
'Company ID' => $response->getAuthentication()->getCompanyId(),
'User ID' => $response->getAuthentication()->getUserId(),
'Request control ID' => $response->getControl()->getControlId(),
'Function control ID' => $result->getControlId(),
'Total count' => $result->getTotalCount(),
'Data' => $json_data,
]);
} catch (Exception $ex) {
$logger->error('An exception was thrown', [
get_class($ex) => $ex->getMessage(),
]);
echo get_class($ex) . ': ' . $ex->getMessage();
}