Implement reporting features

If you want your app to utilize QuickBooks Online reporting features, set up this basic reporting implementation.

Step 1: Learn about basic accounting implementations

For your app’s implementations, make sure you pre-create entities so your app can reference them in transactions.

Transactions in QuickBooks frequently need to reference common entities like account, taxcode, and customer. If you have pre-created versions of common objects and entities, all your app needs to do is reference their IDs while creating transactions like invoices and bills.

If these entities don’t already exist, the transactions your app creates won’t have anything to reference. Referenced entities can’t be created on the fly within a transaction.

Step 2: Code the reporting implementation

This implementation generally does the following:


Reporting implementations

.NET

Java

PHP

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
//Initialize OAuth2RequestValidator and ServiceContext
ServiceContext serviceContext = base.IntializeContext(realmId);
ReportService defaultReportService = new ReportService(serviceContext);

//Query default Profit and loss report
Report defaultPnLReport = defaultReportService.ExecuteReport("ProfitAndLoss");

//Query default BalanceSheet report
Report defaultBalanceSheet = defaultReportService.ExecuteReport("BalanceSheet");

//Run report for a specific time period
defaultReportService.start_date = "2018-01-01";
defaultReportService.end_date = "2018-04-15";
defaultPnLReport = defaultReportService.ExecuteReport("ProfitAndLoss");
defaultBalanceSheet = defaultReportService.ExecuteReport("BalanceSheet");

//Run report summarized by customer
defaultReportService.summarize_column_by = "Customers";
defaultPnLReport = defaultReportService.ExecuteReport("ProfitAndLoss");
defaultBalanceSheet = defaultReportService.ExecuteReport("BalanceSheet");
Tip: Some methods, like creating or querying accounts, are omitted in the sample for brevity. Visit our GitHub to see the complete code.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//create oauth object
OAuth2Authorizer oauth = new OAuth2Authorizer(accessToken);
//create context
Context context = new Context(oauth, ServiceType.QBO, realmId);
//create ReportService
ReportService service = new ReportService(context);

//Query default Profit and loss report
Report defaultPnLReport = service.executeReport(ReportName.PROFITANDLOSS.toString());

//Query default BalanceSheet report
Report defaultBalanceSheet = service.executeReport(ReportName.BALANCESHEET.toString());

//Run report for a specific time period
service.setStart_date("2018-01-01");
service.setEnd_date("2018-04-15");
defaultBalanceSheet = service.executeReport(ReportName.BALANCESHEET.toString());
defaultPnLReport = service.executeReport(ReportName.PROFITANDLOSS.toString());

//Run report summarized by customer
service.setSummarize_column_by("Customers");
defaultBalanceSheet = service.executeReport(ReportName.BALANCESHEET.toString());
defaultPnLReport = service.executeReport(ReportName.PROFITANDLOSS.toString());
Tip: Some methods, like creating or querying accounts, are omitted in the sample for brevity. Visit our GitHub to see the complete code.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<?php
//create dataservice
$dataService->updateOAuth2Token($accessToken);

//Initialize the Report service from the data service context
$serviceContext = $dataService->getServiceContext();
$reportService = new ReportService($serviceContext);

//Query default Profit and loss report
$profitAndLossReport = $reportService->executeReport("ProfitAndLoss");

//Query default BalanceSheet report
$balancesheet = $reportService->executeReport("BalanceSheet");

//Run report summarized by customer
$reportService->setSummarizeColumnBy("Customers");
$profitAndLossReport = $reportService->executeReport("ProfitAndLoss");
$balancesheet = $reportService->executeReport("BalanceSheet");
?>

Tip: Some methods, like creating or querying accounts, are omitted in the sample for brevity. Visit our GitHub to see the complete code.

Feel free to change variables for more relevant reports and items that are relevant to you and your app.

Step 3: Set up other basic implementations

Depending on what basic QuickBooks features you want your app to utilize, you can set up other basic accounting implementations: