diff --git a/README.md b/README.md index 94d534b..03793f4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package-lock.json b/package-lock.json index 776c624..6327a25 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "onair-cli", - "version": "1.4.1", + "version": "1.5.0-alpha.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "onair-cli", - "version": "1.4.1", + "version": "1.5.0-alpha.1", "license": "MIT", "dependencies": { "axios": "^0.22.0", diff --git a/package.json b/package.json index 30bafc0..9a2748d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/commands/company.ts b/src/commands/company.ts index ddaee9d..a6d7ea1 100644 --- a/src/commands/company.ts +++ b/src/commands/company.ts @@ -1,6 +1,6 @@ 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'; @@ -8,6 +8,7 @@ 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; @@ -16,19 +17,25 @@ const builder = (yargs: yargs.Argv) => { .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 ? CommandModule : never; @@ -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); + } } } diff --git a/src/loggers/logCompanyIncome.ts b/src/loggers/logCompanyIncome.ts new file mode 100644 index 0000000..bb50852 --- /dev/null +++ b/src/loggers/logCompanyIncome.ts @@ -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); +} \ No newline at end of file