org.notima.fortnox.command.ShowChartOfAccounts Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fortnoxAdapter Show documentation
Show all versions of fortnoxAdapter Show documentation
Adapter to convert Fortnox data to the common format found on
https://github.com/notima/businessobjects
The newest version!
package org.notima.fortnox.command;
import java.util.ArrayList;
import java.util.List;
import org.apache.karaf.shell.api.action.Action;
import org.apache.karaf.shell.api.action.Argument;
import org.apache.karaf.shell.api.action.Command;
import org.apache.karaf.shell.api.action.Completion;
import org.apache.karaf.shell.api.action.Option;
import org.apache.karaf.shell.api.action.lifecycle.Reference;
import org.apache.karaf.shell.api.action.lifecycle.Service;
import org.apache.karaf.shell.api.console.Session;
import org.notima.api.fortnox.FortnoxClient3;
import org.notima.api.fortnox.entities3.Account;
import org.notima.api.fortnox.entities3.AccountSubset;
import org.notima.api.fortnox.entities3.Accounts;
import org.notima.fortnox.command.completer.FortnoxTenantCompleter;
import org.notima.fortnox.command.table.AccountTable;
import org.notima.generic.businessobjects.AccountClass;
import org.notima.generic.businessobjects.BasicAccountingReportProvider;
@Command(scope = "fortnox", name = "show-fortnox-coa", description = "List chart of accounts for given client.")
@Service
public class ShowChartOfAccounts extends FortnoxCommand implements Action {
@Reference
Session sess;
@Option(name = "--all", description = "Include in active accounts", required = false, multiValued = false)
private boolean showInactive;
@Option(name = "--balances", description = "Include balances (takes longer time)", required = false, multiValued = false)
private boolean showBalances;
@Option(name = "--only-with-balances", description = "Include only accounts with balances (implicits --balances)", required = false, multiValued = false)
private boolean onlyWithBalances;
@Option(name = "--only-with-vatcodes", description = "Include only accounts with VAT-codes (implicits --include-pl-accounts)", required = false, multiValued = false)
private boolean onlyWithVatCodes;
@Option(name = "--yearId", description = "Show COA for specific yearId", required = false, multiValued = false)
private Integer yearId;
@Option(name = "--include-pl-accounts", description = "Include P/L accounts (not just balance sheet accounts)", required = false, multiValued = false)
private boolean includePlAccounts;
@Argument(index = 0, name = "orgNo", description ="The orgno of the client", required = true, multiValued = false)
@Completion(FortnoxTenantCompleter.class)
private String orgNo = "";
private BasicAccountingReportProvider barp = new BasicAccountingReportProvider();
@Override
public Object execute() throws Exception {
FortnoxClient3 fc = getFortnoxClient(orgNo);
if (fc == null) {
sess.getConsole().println("Can't get client for " + orgNo);
return null;
}
if (yearId==null) {
yearId = fc.getFinancialYear(null).getId();
}
Accounts accts = fc.getAccounts(yearId);
if (accts==null) {
sess.getConsole().println("No chart of accounts found for yearId " + yearId);
return null;
}
Account acct;
String acctNo;
if (onlyWithVatCodes) {
includePlAccounts = true;
}
List