-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrailBalanceReport.php
130 lines (106 loc) · 4.67 KB
/
TrailBalanceReport.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
123
124
125
126
127
128
129
130
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script type="text/javascript" src="https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js"></script>
</head>
<body>
<?php
require_once('../v3-php-sdk-2.0.5/config.php');
require_once(PATH_SDK_ROOT . 'Core/ServiceContext.php');
require_once(PATH_SDK_ROOT . 'PlatformService/PlatformService.php');
require_once(PATH_SDK_ROOT . 'Utility/Configuration/ConfigurationManager.php');
require_once(PATH_SDK_ROOT . 'Core/CoreHelper.php');
require_once(PATH_SDK_ROOT . 'DataService/Batch.php');
require_once(PATH_SDK_ROOT . 'DataService/IntuitCDCResponse.php');
require_once(PATH_SDK_ROOT . 'Data/IntuitRestServiceDef/IPPAttachableResponse.php');
require_once(PATH_SDK_ROOT . 'Data/IntuitRestServiceDef/IPPFault.php');
require_once(PATH_SDK_ROOT . 'Data/IntuitRestServiceDef/IPPError.php');
require_once('RestServiceHandler.php');
// Echo some formatted output
echo '<a href="javascript:void(0)" onclick="goHome()">Home</a>';
echo ' ';
echo '<a href="javascript:void(0)" onclick="return intuit.ipp.anywhere.logout(function () { window.location.href = \'http://localhost/PHPSample/index.php\'; });">Sign Out</a>';
echo ' ';
echo '<a target="_blank" href="http://localhost/PHPSample/ReadMe.htm">Read Me</a><br />';
//Specify QBO or QBD
$serviceType = IntuitServicesType::QBO;
// Get App Config
$realmId = ConfigurationManager::AppSettings('RealmID');
if (!$realmId)
exit("Please add realm to App.Config before running this sample.\n");
// Prep Service Context
$requestValidator = new OAuthRequestValidator(ConfigurationManager::AppSettings('AccessToken'),
ConfigurationManager::AppSettings('AccessTokenSecret'),
ConfigurationManager::AppSettings('ConsumerKey'),
ConfigurationManager::AppSettings('ConsumerSecret'));
$serviceContext = new ServiceContext($realmId, $serviceType, $requestValidator);
if (!$serviceContext)
exit("Problem while initializing ServiceContext.\n");
$serviceContext->IppConfiguration->Logger->RequestLog->Log(TraceLevel::Info, "Going to fetch report data.");
//$query = "entities=" . $entityString . "&changedSince=" . $formattedChangedSince;
$queryParamValue="This Fiscal Year-to-date";
$query = "date_macro='".$queryParamValue."'";
$query=urlencode($query);
//$uri = "company/{1}/cdc?{2}";
$uri = "company/{1}/reports/TrialBalance?{2}";
//$uri = str_replace("{0}", CoreConstants::VERSION, $uri);
$uri = str_replace("{1}", $serviceContext->realmId, $uri);
$uri = str_replace("{2}", $query, $uri);
// Creates request parameters
$requestParameters = new RequestParameters($uri, 'GET', CoreConstants::CONTENTTYPE_APPLICATIONJSON, NULL);
//var_dump($requestParameters);
$restRequestHandler = new RestServiceHandler($serviceContext);
try
{
// gets response
list($responseCode,$responseBody) = $restRequestHandler->GetReportsResponse($requestParameters, NULL, NULL);
//CoreHelper::CheckNullResponseAndThrowException($responseBody);
/*echo "response code is:".$responseCode."<br />";
echo "response body is:".$responseBody."<br />";
var_dump($responseCode);
var_dump($responseBody);*/
$responseArray = json_decode($responseBody, true);
ConstructReportUI($responseArray);
}
catch (Exception $e)
{
echo"There is an exception";
}
function ConstructReportUI($responseArray)
{
echo "<h3>Trial Balance as of ".$responseArray['Header']['EndPeriod']."</h3>";
echo "From Date:".$responseArray['Header']['StartPeriod']." To Date:".$responseArray['Header']['EndPeriod']."<br />";
echo '<table width="1000" cellspacing="5" cellpadding="5">';
echo '<tr> <th></th> <th> Debit </th> <th>Credit</th> </tr>';
if (!$responseArray || (0==count($responseArray)))
return;
$count = count($responseArray['Rows']['Row']);
$i = 1;
foreach($responseArray['Rows']['Row'] as $oneArray)
{
if ($i < $count)
{
echo "<tr>";
echo "<td align='center'>{$oneArray['ColData'][0]['value']}</td>";
echo "<td align='center'>{$oneArray['ColData'][1]['value']}</td>";
echo "<td align='center'>{$oneArray['ColData'][2]['value']}</td>";
}
else
{
echo "<td align='center'><b>{$oneArray['Summary']['ColData'][0]['value']}</b></td>";
echo "<td align='center'><b>{$oneArray['Summary']['ColData'][1]['value']}</b></td>";
echo "<td align='center'><b>{$oneArray['Summary']['ColData'][2]['value']}</b></td>";
}
echo'</tr>';
$i++;
}
}
?>
<script type="text/javascript">
function goHome(){
window.location.href = "http://localhost/PHPSample/SampleAppHomePage.php";
}
</script>
</body>
</html>