-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathBusinessAnalytic.php
122 lines (105 loc) · 3.77 KB
/
BusinessAnalytic.php
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
require_once(__DIR__ . '/vendor/autoload.php');
//Import Facade classes you are going to use here
//For example, if you need to use Customer, add
//use QuickBooksOnline\API\Facades\Customer;
use QuickBooksOnline\API\Core\ServiceContext;
use QuickBooksOnline\API\DataService\DataService;
use QuickBooksOnline\API\PlatformService\PlatformService;
use QuickBooksOnline\API\Core\Http\Serialization\XmlObjectSerializer;
use QuickBooksOnline\API\Facades\Purchase;
use QuickBooksOnline\API\Data\IPPPurchase;
use QuickBooksOnline\API\QueryFilter\QueryMessage;
use QuickBooksOnline\API\ReportService\ReportService;
use QuickBooksOnline\API\ReportService\ReportName;
session_start();
function analyzeBusiness()
{
/*
* Create SDK instance
*/
$config = include('config.php');
$dataService = DataService::Configure(array(
'auth_mode' => 'oauth2',
'ClientID' => $config['client_id'],
'ClientSecret' => $config['client_secret'],
'RedirectURI' => $config['oauth_redirect_uri'],
'scope' => $config['oauth_scope'],
'baseUrl' => "development"
));
/*
* Retrieve the accessToken value from session variable
*/
$accessToken = $_SESSION['sessionAccessToken'];
$dataService->throwExceptionOnError(true);
/*
* Update the OAuth2Token of the dataService object
*/
$dataService->updateOAuth2Token($accessToken);
/*
* Initialize the Report service from the data service context
*/
$serviceContext = $dataService->getServiceContext();
$reportService = new ReportService($serviceContext);
if (!$reportService) {
exit("Problem while initializing ReportService.\n");
}
/*
* Usecase 1
* Choose the reports - Balance Sheet, ProfitAndLoss
*/
$balancesheet = $reportService->executeReport("BalanceSheet");
$profitAndLossReport = $reportService->executeReport("ProfitAndLoss");
/*
* Print the reports
*/
echo("ProfitAndLoss Report Execution Start!" . "\n");
if (!$profitAndLossReport) {
exit("ProfitAndLossReport Is Null.\n");
} else {
$result = json_encode($profitAndLossReport, JSON_PRETTY_PRINT);
print_r($result);
echo("Profit And Loss Report Execution Successful!" . "\n");
}
echo("\nBalanceSheet Execution Start!" . "\n");
if (!$balancesheet) {
exit("BalanceShee Is Null.\n");
} else {
$result = json_encode($balancesheet, JSON_PRETTY_PRINT);
print_r($result);
echo("BalanceSheet Execution Successful!" . "\n");
}
/*
* Usecase 2
* Configure report service to be summarized by Customer
* Report service is default configured for the Current Year end, so no conf needed there
*/
$reportService->setSummarizeColumnBy("Customers");
/*
* Once the report service is configured, Choose the reports - Balance Sheet, ProfitAndLoss
*/
$balancesheet = $reportService->executeReport("BalanceSheet");
$profitAndLossReport = $reportService->executeReport("ProfitAndLoss");
/*
* Print the reports
*/
echo("Year End Profit And Loss Report Summarized by Customers Start!" . "\n");
if (!$profitAndLossReport) {
exit("ProfitAndLossReport Is Null.\n");
} else {
$result = json_encode($profitAndLossReport, JSON_PRETTY_PRINT);
print_r($result);
echo("Year End Profit And Loss Report Summarized by Customers Execution Successful!" . "\n");
}
echo("Year End BalanceSheet Summarized by Customers Start!" . "\n");
if (!$balancesheet) {
exit("BalanceSheet Is Null.\n");
} else {
$result = json_encode($balancesheet, JSON_PRETTY_PRINT);
print_r($result);
echo("BalanceSheet Execution Successful!" . "\n");
}
return;
}
$result = analyzeBusiness();
?>