Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ For ease of use save your OnAir credentials.

Your OnAir API key and Company ID are found in the bottom left of the settings page in the OnAir client. The world name is 'cumulus', 'stratus', or 'thunder'. Use 'stratus' for Clear Sky server.

If you are a member of a Virtual Airline (VA), you can also add your VA ID. This can be found in the Manage VA options screen.

`onair-cli set-creds --apiKey=[API_KEY] --world=[WORLD] --companyId=[COMPANY_ID] --vaId=[VIRTUAL_AIRLINE_ID]`

## Commands

### Aircraft
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "onair-cli",
"description": "A CLI to display information from OnAir Airline Manager",
"version": "1.4.1",
"version": "1.5.0-alpha.1",
"main": "bin/index.js",
"author": {
"name": "Will Kelly",
Expand Down
25 changes: 22 additions & 3 deletions src/commands/company.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import yargs, { BuilderCallback, CommandModule } from 'yargs';
import chalk from 'chalk';
import OnAirApi, { OnAirApiConfig, Company, Aircraft, Flight, Fbo, Job } from 'onair-api';
import OnAirApi, { OnAirApiConfig, Company, Aircraft, Flight, Fbo, Job, IncomeStatement } from 'onair-api';

import { CommonConfig } from '../utils/commonTypes';
import { logFlights } from '../loggers/logFlights';
import { logCompany } from '../loggers/logCompany';
import { logCompanyFleet } from '../loggers/logCompanyFleet';
import { logCompanyFbos } from '../loggers/logCompanyFbos';
import { logCompanyJobs } from '../loggers/logCompanyJobs';
import { logCompanyIncome } from '../loggers/logCompanyIncome';

const log = console.log;

Expand All @@ -16,19 +17,25 @@ const builder = (yargs: yargs.Argv<CommonConfig>) => {
.positional('action', {
describe: 'Optional info to lookup from your company',
type: 'string',
choices: ['fleet', 'flights', 'fbos', 'jobs'],
choices: ['fleet', 'flights', 'fbos', 'jobs', 'income'],
})
.option('page', {
'describe': 'Page number (flights only)',
'type': 'number',
'alias': 'p',
})
.option('days', {
'describe': 'Days to display (Income statement only)',
'type': 'number',
})
.example('$0 company','Get summary information for your company')
.example('$0 company fleet','List your aircraft')
.example('$0 company flights','List your flights')
.example('$0 company flights -p=2','List your flights, showing page 2')
.example('$0 company fbos', 'List your FBOs')
.example('$0 company jobs', 'List your pending jobs');
.example('$0 company jobs', 'List your pending jobs')
.example('$0 company income', 'Display your company income statement summary')
.example('$0 company income --days=30', 'Display your statement summary for the last 30 days');
}

type CompanyCommand = (typeof builder) extends BuilderCallback<CommonConfig, infer R> ? CommandModule<CommonConfig, R> : never;
Expand Down Expand Up @@ -109,6 +116,18 @@ export const companyCommand: CompanyCommand = {
}
break;
}

case 'income': {
const daysToDisplay =
typeof argv['days'] === 'undefined' || argv['days'] < 1 || argv['days'] > 30
? 7 : argv['days'];
const currentDate = new Date();
const currentDateStr = currentDate.toISOString();
const priorDate = new Date().setDate(currentDate.getDate() - daysToDisplay);
const priorDateStr = new Date(priorDate).toISOString();
const income: IncomeStatement = await api.getCompanyIncomeStatement(priorDateStr, currentDateStr);
logCompanyIncome(income, daysToDisplay);
}
}
}

Expand Down
48 changes: 48 additions & 0 deletions src/loggers/logCompanyIncome.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import chalk from "chalk";
import { IncomeStatement, Account } from "onair-api";

const log = console.log;

const logAccounts = (account: Account[], cols: number): void => {
account.forEach((ISAccount) => {
const amount = ISAccount.Amount.toLocaleString('en-GB');
const paddingCount = cols - ISAccount.Name.length - amount.length;
log(ISAccount.Name + chalk.gray('.'.repeat(paddingCount)) + amount);
});
}

export const logCompanyIncome = (income: IncomeStatement, daysToDisplay: number, cols:number = 80): void => {


const lengthLabel = daysToDisplay > 1 ? daysToDisplay + ' days' : 'day';

log(chalk.greenBright.bold(`Your income statement summary for the last ${lengthLabel}\n`));

const revLabel = 'Revenues';
const revAmountLabel = income.REVAmount.toLocaleString('en-GB') + ' 💰';
const revPaddingCount = cols - revLabel.length - revAmountLabel.length;

log(chalk.cyanBright(revLabel) + ' '.repeat(revPaddingCount) + revAmountLabel + '\n');

const headersPaddingCount = cols - 'Name'.length - 'Amount'.length;

log(chalk.green('Name') + ' '.repeat(headersPaddingCount) + chalk.green('Amount'));

logAccounts(income.REVAccounts, cols);

const expLabel = 'Expenses';
const expAmountLabel = income.EXPAmount.toLocaleString('en-GB') + ' 💰';
const expPaddingCount = cols - expLabel.length - expAmountLabel.length;

log('\n' + chalk.cyanBright(expLabel) + ' '.repeat(expPaddingCount) + expAmountLabel + '\n');

log(chalk.green('Name') + ' '.repeat(headersPaddingCount) + chalk.green('Amount'));

logAccounts(income.EXPAccounts, cols);

const netIncomeLabel = 'Net income for the period';
const netIncomeAmountLabel = income.NetIncomeAmount.toLocaleString('en-GB') + ' 💰';
const netIncomePaddingCount = cols - netIncomeLabel.length - netIncomeAmountLabel.length;

log('\n' + chalk.cyanBright(netIncomeLabel) + ' '.repeat(netIncomePaddingCount) + netIncomeAmountLabel);
}