Skip to content

Commit

Permalink
stub the invoice manager and invoice command
Browse files Browse the repository at this point in the history
  • Loading branch information
jkdmyrs committed Jun 8, 2024
1 parent 0656f4c commit 2f303a3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 24 deletions.
20 changes: 20 additions & 0 deletions src/core/invoice-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export class InvoiceManager {
public static async CreateAsync(projectId: string) {
// take all shifts for project and user config and create an invoice, create an invoice number
// keep an index of all invoices and whether or not they're paid (INVOICES file)
}

public static async PaidAsync(projectId: string, invoiceNumber: number) {
// mark a specific invoice as paid
}

public static async StatusAsync(projectId: string | null) {
// see all unpaid invoices for
if (projectId) {
// specific project
}
else {
// all projects
}
}
}
15 changes: 15 additions & 0 deletions src/core/shift-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { PUNCHFILE as punchFile } from "./files/punchfile.ts";

export class ShiftManager {
public static async PunchAsync(projectId: string, rate: number) {
const PUNCHFILE = await punchFile.readFileAsync();
if (PUNCHFILE) {
// create the shift
await PUNCHFILE.deleteAsync();
}
else {
const punchId = ""; // generate a GUID
await punchFile.createAsync(projectId, punchId, new Date(), rate);
}
}
}
46 changes: 22 additions & 24 deletions src/core/timeclock.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Configuration } from "./configuration.ts";
import { parseArgs } from "../_lib/cli-parser.ts"
import { PROJECTFILE as projectFile } from "./files/projectfile.ts";
import { PUNCHFILE as punchFile } from "./files/punchfile.ts";
import { ShiftManager } from "./shift-manager.ts";
import { InvoiceManager } from "./invoice-manager.ts";

export class TimeClock {
constructor(private readonly _config: Configuration)
Expand All @@ -10,52 +11,49 @@ export class TimeClock {
public async main() {
const args = parseArgs(Deno.args);
const command = args._[0];
const project = args.p;
const invoiceNumber = args.n;

const PROJECTFILE = await projectFile.readFileAsync();

if (! PROJECTFILE.projectExists(project)) {
await PROJECTFILE.addProjectAsync(project);
if (args.p && ! PROJECTFILE.projectExists(args.p)) {
await PROJECTFILE.addProjectAsync(args.p);
}
const projectId = PROJECTFILE.getProjectId(project);
const projectId = args.p ? PROJECTFILE.getProjectId(args.p) : null;

switch(command) {
case "punch":
{
const PUNCHFILE = await punchFile.readFileAsync();
if (PUNCHFILE) {
// create the shift
await PUNCHFILE.deleteAsync();
if (projectId) {
await ShiftManager.PunchAsync(projectId, this._config.rate);
break;
}
else {
const punchId = ""; // generate a GUID
await punchFile.createAsync(projectId, punchId, new Date(), this._config.rate)
throw "project name must be provided"
}
break;
}
case "invoice":
{
const verb = args._[1];
switch(verb) {
case "create":
// take all shifts for project and user config and create an invoice, create an invoice number
// keep an index of all invoices and whether or not they're paid (INVOICES file)
if (projectId) {
await InvoiceManager.CreateAsync(projectId);
}
else {
throw "project name must be provided"
}
break;
case "paid":
// mark a specific invoice as paid
break;
case "status":
// see all unpaid invoices for
if (args.p) {
// specific project
if (projectId) {
await InvoiceManager.PaidAsync(projectId, args.n);
}
else {
// all projects
throw "project name must be provided"
}
break;
default:
case "status":
await InvoiceManager.StatusAsync(projectId);
break;
default:
throw "invalid verb for invoice command"
}
break;
}
Expand Down

0 comments on commit 2f303a3

Please sign in to comment.