@invoicer/cli 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +15 -0
- package/config.json +19 -0
- package/data/last.json +11 -0
- package/dist/cli.js +38 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/clients.js +184 -0
- package/dist/commands/clients.js.map +1 -0
- package/dist/commands/generate.js +294 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/timesheet.js +34 -0
- package/dist/commands/timesheet.js.map +1 -0
- package/dist/core/json-store.js +27 -0
- package/dist/core/json-store.js.map +1 -0
- package/dist/core/paths.js +29 -0
- package/dist/core/paths.js.map +1 -0
- package/dist/core/validators.js +131 -0
- package/dist/core/validators.js.map +1 -0
- package/dist/domain/types.js +2 -0
- package/dist/domain/types.js.map +1 -0
- package/dist/services/email.js +32 -0
- package/dist/services/email.js.map +1 -0
- package/dist/services/invoice-number.js +33 -0
- package/dist/services/invoice-number.js.map +1 -0
- package/dist/services/pdf-render.js +69 -0
- package/dist/services/pdf-render.js.map +1 -0
- package/dist/services/timesheet.js +99 -0
- package/dist/services/timesheet.js.map +1 -0
- package/dist/utils/sanitize.js +8 -0
- package/dist/utils/sanitize.js.map +1 -0
- package/index.html +2584 -0
- package/logo.svg +17 -0
- package/package.json +39 -0
- package/scripts/invoice.mjs +23 -0
- package/src/cli.ts +44 -0
- package/src/commands/clients.ts +221 -0
- package/src/commands/generate.ts +379 -0
- package/src/commands/timesheet.ts +47 -0
- package/src/core/json-store.ts +33 -0
- package/src/core/paths.ts +42 -0
- package/src/core/validators.ts +168 -0
- package/src/domain/types.ts +129 -0
- package/src/services/email.ts +40 -0
- package/src/services/invoice-number.ts +46 -0
- package/src/services/pdf-render.ts +95 -0
- package/src/services/timesheet.ts +173 -0
- package/src/utils/sanitize.ts +8 -0
- package/test/cli-wiring.test.ts +25 -0
- package/test/invoice-number.test.ts +45 -0
- package/test/timesheet.test.ts +104 -0
- package/tsconfig.json +17 -0
package/.env.example
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# SMTP Configuration for Email Sending
|
|
2
|
+
# Copy this file to .env and fill in your details
|
|
3
|
+
|
|
4
|
+
SMTP_HOST=smtp.gmail.com
|
|
5
|
+
SMTP_PORT=465
|
|
6
|
+
SMTP_USER=your@email.com
|
|
7
|
+
SMTP_PASS=your_app_password
|
|
8
|
+
INVOICE_FROM="Your Name <your@email.com>"
|
|
9
|
+
|
|
10
|
+
# Gmail App Password Setup:
|
|
11
|
+
# 1. Go to https://myaccount.google.com/security
|
|
12
|
+
# 2. Enable 2-Factor Authentication
|
|
13
|
+
# 3. Go to App Passwords: https://myaccount.google.com/apppasswords
|
|
14
|
+
# 4. Create app password for "Mail" on "Other (Custom name)"
|
|
15
|
+
# 5. Copy the 16-character password and use it as SMTP_PASS
|
package/config.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"client": [
|
|
3
|
+
{
|
|
4
|
+
"address": "",
|
|
5
|
+
"currency": "USD",
|
|
6
|
+
"defaultRate": 40,
|
|
7
|
+
"email": "miladezzat.f+dasix@gmail.com",
|
|
8
|
+
"name": "Dasix Inc.",
|
|
9
|
+
"payPeriodType": "Net 7"
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"defaultDescription": "",
|
|
13
|
+
"from": {
|
|
14
|
+
"address": "Test",
|
|
15
|
+
"email": "miladezzat.f@gmail.com",
|
|
16
|
+
"name": "Milad"
|
|
17
|
+
},
|
|
18
|
+
"invoicePrefix": "INV"
|
|
19
|
+
}
|
package/data/last.json
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "dotenv/config";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { createProjectPaths } from "./core/paths.js";
|
|
6
|
+
import { registerGenerateCommand } from "./commands/generate.js";
|
|
7
|
+
import { registerClientsCommand } from "./commands/clients.js";
|
|
8
|
+
import { registerTimesheetCommand } from "./commands/timesheet.js";
|
|
9
|
+
export function createProgram(paths = createProjectPaths()) {
|
|
10
|
+
const program = new Command();
|
|
11
|
+
program
|
|
12
|
+
.name("invoicer")
|
|
13
|
+
.description("Professional invoice generator with timesheet integration")
|
|
14
|
+
.version("1.0.0");
|
|
15
|
+
registerGenerateCommand(program, paths);
|
|
16
|
+
registerClientsCommand(program, paths);
|
|
17
|
+
registerTimesheetCommand(program, paths);
|
|
18
|
+
return program;
|
|
19
|
+
}
|
|
20
|
+
export async function runCli(argv = process.argv, paths = createProjectPaths()) {
|
|
21
|
+
const program = createProgram(paths);
|
|
22
|
+
await program.parseAsync(argv);
|
|
23
|
+
}
|
|
24
|
+
function isMainModule() {
|
|
25
|
+
const entry = process.argv[1];
|
|
26
|
+
if (!entry) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return import.meta.url === pathToFileURL(entry).href;
|
|
30
|
+
}
|
|
31
|
+
if (isMainModule()) {
|
|
32
|
+
runCli().catch((error) => {
|
|
33
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
34
|
+
console.error(`ā ${message}`);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAqB,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAA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AC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
import { loadJsonFile, writeJsonFile } from "../core/json-store.js";
|
|
3
|
+
import { validateConfig } from "../core/validators.js";
|
|
4
|
+
function loadConfig(paths) {
|
|
5
|
+
return loadJsonFile(paths.configPath, { client: [], from: {} }, validateConfig);
|
|
6
|
+
}
|
|
7
|
+
export function registerClientsCommand(program, paths) {
|
|
8
|
+
program
|
|
9
|
+
.command("clients")
|
|
10
|
+
.description("Manage clients")
|
|
11
|
+
.option("--list", "List all configured clients", false)
|
|
12
|
+
.option("--add", "Add a new client interactively", false)
|
|
13
|
+
.option("--edit <name>", "Edit a client by name")
|
|
14
|
+
.option("--delete <name>", "Delete a client by name")
|
|
15
|
+
.action(async (options) => {
|
|
16
|
+
const cfg = loadConfig(paths);
|
|
17
|
+
if (options.list) {
|
|
18
|
+
if (cfg.client.length === 0) {
|
|
19
|
+
console.log("No clients configured.");
|
|
20
|
+
process.exit(0);
|
|
21
|
+
}
|
|
22
|
+
console.log("\nš Configured Clients:\n");
|
|
23
|
+
cfg.client.forEach((client, index) => {
|
|
24
|
+
console.log(`${index + 1}. ${client.name}`);
|
|
25
|
+
console.log(` Currency: ${client.currency || "USD"}`);
|
|
26
|
+
console.log(` Rate: ${client.defaultRate}/hr`);
|
|
27
|
+
console.log(` Email: ${client.email || "ā"}`);
|
|
28
|
+
if (client.address)
|
|
29
|
+
console.log(` Address: ${client.address}`);
|
|
30
|
+
if (client.payPeriodType)
|
|
31
|
+
console.log(` Terms: ${client.payPeriodType}`);
|
|
32
|
+
console.log();
|
|
33
|
+
});
|
|
34
|
+
process.exit(0);
|
|
35
|
+
}
|
|
36
|
+
if (options.add) {
|
|
37
|
+
const answers = await inquirer.prompt([
|
|
38
|
+
{
|
|
39
|
+
type: "input",
|
|
40
|
+
name: "name",
|
|
41
|
+
message: "Client name:",
|
|
42
|
+
validate: (value) => value.trim().length > 0 || "Name is required",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: "input",
|
|
46
|
+
name: "email",
|
|
47
|
+
message: "Email address:",
|
|
48
|
+
default: "",
|
|
49
|
+
validate: (value) => !value || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value) || "Enter valid email",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
type: "input",
|
|
53
|
+
name: "address",
|
|
54
|
+
message: "Address (optional):",
|
|
55
|
+
default: "",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
type: "list",
|
|
59
|
+
name: "currency",
|
|
60
|
+
message: "Currency:",
|
|
61
|
+
choices: ["USD", "EUR", "GBP", "JPY"],
|
|
62
|
+
default: "USD",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: "number",
|
|
66
|
+
name: "defaultRate",
|
|
67
|
+
message: "Default rate per hour:",
|
|
68
|
+
default: 50,
|
|
69
|
+
validate: (value) => value > 0 || "Rate must be positive",
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
type: "input",
|
|
73
|
+
name: "payPeriodType",
|
|
74
|
+
message: "Payment terms (e.g., Net 30, Due on Receipt):",
|
|
75
|
+
default: "Due on Receipt",
|
|
76
|
+
},
|
|
77
|
+
]);
|
|
78
|
+
const newClient = {
|
|
79
|
+
name: answers.name.trim(),
|
|
80
|
+
email: answers.email.trim(),
|
|
81
|
+
address: answers.address.trim(),
|
|
82
|
+
currency: answers.currency,
|
|
83
|
+
defaultRate: Number(answers.defaultRate),
|
|
84
|
+
payPeriodType: answers.payPeriodType.trim(),
|
|
85
|
+
};
|
|
86
|
+
if (cfg.client.some((client) => client.name === newClient.name)) {
|
|
87
|
+
console.error(`ā Client "${newClient.name}" already exists`);
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
cfg.client.push(newClient);
|
|
91
|
+
writeJsonFile(paths.configPath, cfg);
|
|
92
|
+
console.log(`ā
Client "${newClient.name}" added successfully`);
|
|
93
|
+
process.exit(0);
|
|
94
|
+
}
|
|
95
|
+
if (options.edit) {
|
|
96
|
+
const clientName = options.edit.trim();
|
|
97
|
+
const clientIndex = cfg.client.findIndex((client) => client.name === clientName);
|
|
98
|
+
if (clientIndex === -1) {
|
|
99
|
+
console.error(`ā Client "${clientName}" not found`);
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
const current = cfg.client[clientIndex];
|
|
103
|
+
const answers = await inquirer.prompt([
|
|
104
|
+
{
|
|
105
|
+
type: "input",
|
|
106
|
+
name: "name",
|
|
107
|
+
message: "Client name:",
|
|
108
|
+
default: current.name,
|
|
109
|
+
validate: (value) => value.trim().length > 0 || "Name is required",
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
type: "input",
|
|
113
|
+
name: "email",
|
|
114
|
+
message: "Email:",
|
|
115
|
+
default: current.email || "",
|
|
116
|
+
validate: (value) => !value || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value) || "Enter valid email",
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
type: "input",
|
|
120
|
+
name: "address",
|
|
121
|
+
message: "Address:",
|
|
122
|
+
default: current.address || "",
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
type: "list",
|
|
126
|
+
name: "currency",
|
|
127
|
+
message: "Currency:",
|
|
128
|
+
choices: ["USD", "EUR", "GBP", "JPY"],
|
|
129
|
+
default: current.currency || "USD",
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
type: "number",
|
|
133
|
+
name: "defaultRate",
|
|
134
|
+
message: "Default rate per hour:",
|
|
135
|
+
default: current.defaultRate || 50,
|
|
136
|
+
validate: (value) => value > 0 || "Rate must be positive",
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
type: "input",
|
|
140
|
+
name: "payPeriodType",
|
|
141
|
+
message: "Payment terms:",
|
|
142
|
+
default: current.payPeriodType || "Due on Receipt",
|
|
143
|
+
},
|
|
144
|
+
]);
|
|
145
|
+
cfg.client[clientIndex] = {
|
|
146
|
+
name: answers.name.trim(),
|
|
147
|
+
email: answers.email.trim(),
|
|
148
|
+
address: answers.address.trim(),
|
|
149
|
+
currency: answers.currency,
|
|
150
|
+
defaultRate: Number(answers.defaultRate),
|
|
151
|
+
payPeriodType: answers.payPeriodType.trim(),
|
|
152
|
+
};
|
|
153
|
+
writeJsonFile(paths.configPath, cfg);
|
|
154
|
+
console.log(`ā
Client "${answers.name}" updated successfully`);
|
|
155
|
+
process.exit(0);
|
|
156
|
+
}
|
|
157
|
+
if (options.delete) {
|
|
158
|
+
const clientName = options.delete.trim();
|
|
159
|
+
const clientIndex = cfg.client.findIndex((client) => client.name === clientName);
|
|
160
|
+
if (clientIndex === -1) {
|
|
161
|
+
console.error(`ā Client "${clientName}" not found`);
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
const answer = await inquirer.prompt([
|
|
165
|
+
{
|
|
166
|
+
type: "confirm",
|
|
167
|
+
name: "confirm",
|
|
168
|
+
message: `Delete client "${clientName}"? This cannot be undone.`,
|
|
169
|
+
default: false,
|
|
170
|
+
},
|
|
171
|
+
]);
|
|
172
|
+
if (!answer.confirm) {
|
|
173
|
+
console.log("Cancelled.");
|
|
174
|
+
process.exit(0);
|
|
175
|
+
}
|
|
176
|
+
cfg.client.splice(clientIndex, 1);
|
|
177
|
+
writeJsonFile(paths.configPath, cfg);
|
|
178
|
+
console.log(`ā
Client "${clientName}" deleted`);
|
|
179
|
+
process.exit(0);
|
|
180
|
+
}
|
|
181
|
+
console.log("Usage: invoicer clients [--list | --add | --edit <name> | --delete <name>]");
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=clients.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clients.js","sourceRoot":"","sources":["../../src/commands/clients.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ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from "../core/json-store.js";
|
|
4
|
+
import { validateConfig, validateLastState } from "../core/validators.js";
|
|
5
|
+
import { getDefaultMonth, getInvoiceDate, getInvoicePeriod, resolveInvoiceNumber, validateMonth, } from "../services/invoice-number.js";
|
|
6
|
+
import { hasSmtpConfig, sendInvoiceEmail } from "../services/email.js";
|
|
7
|
+
import { renderInvoicePdf } from "../services/pdf-render.js";
|
|
8
|
+
import { aggregateEntriesByDescription, archiveTimesheetEntries, readTimesheetEntries, } from "../services/timesheet.js";
|
|
9
|
+
function exitWithError(message) {
|
|
10
|
+
console.error(message);
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
function loadConfig(paths) {
|
|
14
|
+
return loadJsonFile(paths.configPath, { client: [], from: {} }, validateConfig);
|
|
15
|
+
}
|
|
16
|
+
function loadLastState(paths) {
|
|
17
|
+
return loadJsonFile(paths.lastPath, { clients: {} }, validateLastState);
|
|
18
|
+
}
|
|
19
|
+
function getCurrency(cfgCurrency) {
|
|
20
|
+
return cfgCurrency?.trim() || "USD";
|
|
21
|
+
}
|
|
22
|
+
async function selectClient(cfg, preferredClientName) {
|
|
23
|
+
if (preferredClientName) {
|
|
24
|
+
const matched = cfg.client.find((client) => client.name === preferredClientName);
|
|
25
|
+
if (!matched) {
|
|
26
|
+
exitWithError(`ā Client "${preferredClientName}" not found in config.json`);
|
|
27
|
+
}
|
|
28
|
+
console.log(`š Using client: ${matched.name}`);
|
|
29
|
+
return matched;
|
|
30
|
+
}
|
|
31
|
+
if (cfg.client.length === 1) {
|
|
32
|
+
const [single] = cfg.client;
|
|
33
|
+
console.log(`š Using client: ${single.name}`);
|
|
34
|
+
return single;
|
|
35
|
+
}
|
|
36
|
+
const clientChoices = cfg.client.map((client, index) => ({
|
|
37
|
+
name: `${client.name} (${getCurrency(client.currency)} ${client.defaultRate}/hr)`,
|
|
38
|
+
value: index,
|
|
39
|
+
}));
|
|
40
|
+
const answer = await inquirer.prompt([
|
|
41
|
+
{
|
|
42
|
+
type: "list",
|
|
43
|
+
name: "clientIndex",
|
|
44
|
+
message: "Select client:",
|
|
45
|
+
choices: clientChoices,
|
|
46
|
+
},
|
|
47
|
+
]);
|
|
48
|
+
return cfg.client[answer.clientIndex];
|
|
49
|
+
}
|
|
50
|
+
async function collectManualLineItems(params) {
|
|
51
|
+
const items = [];
|
|
52
|
+
let addingItems = true;
|
|
53
|
+
let itemIndex = 1;
|
|
54
|
+
while (addingItems) {
|
|
55
|
+
const answer = await inquirer.prompt([
|
|
56
|
+
{
|
|
57
|
+
type: "input",
|
|
58
|
+
name: "description",
|
|
59
|
+
message: `Description (Item ${itemIndex}):`,
|
|
60
|
+
default: itemIndex === 1
|
|
61
|
+
? (params.options.desc || params.cfg.defaultDescription || "Services")
|
|
62
|
+
: "",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: "number",
|
|
66
|
+
name: "hours",
|
|
67
|
+
message: "Hours:",
|
|
68
|
+
default: itemIndex === 1
|
|
69
|
+
? (params.options.hours ? Number(params.options.hours) : Number(params.lastHours ?? 160))
|
|
70
|
+
: undefined,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
type: "number",
|
|
74
|
+
name: "rate",
|
|
75
|
+
message: "Rate per hour:",
|
|
76
|
+
default: itemIndex === 1
|
|
77
|
+
? (params.options.rate ? Number(params.options.rate) : Number(params.lastRate ?? params.defaultRate))
|
|
78
|
+
: params.defaultRate,
|
|
79
|
+
},
|
|
80
|
+
]);
|
|
81
|
+
const hours = Number(answer.hours);
|
|
82
|
+
const rate = Number(answer.rate);
|
|
83
|
+
if (!Number.isFinite(hours) || !Number.isFinite(rate)) {
|
|
84
|
+
exitWithError("ā Hours and rate must be valid numbers");
|
|
85
|
+
}
|
|
86
|
+
const amount = hours * rate;
|
|
87
|
+
items.push({
|
|
88
|
+
description: answer.description,
|
|
89
|
+
hours,
|
|
90
|
+
rate,
|
|
91
|
+
amount,
|
|
92
|
+
});
|
|
93
|
+
console.log(` ā ${answer.description}: ${hours}h Ć ${params.currency}${rate} = ${params.currency}${amount.toFixed(2)}`);
|
|
94
|
+
const addAnotherAnswer = await inquirer.prompt([
|
|
95
|
+
{
|
|
96
|
+
type: "confirm",
|
|
97
|
+
name: "addAnother",
|
|
98
|
+
message: "Add another line item?",
|
|
99
|
+
default: false,
|
|
100
|
+
},
|
|
101
|
+
]);
|
|
102
|
+
addingItems = addAnotherAnswer.addAnother;
|
|
103
|
+
itemIndex += 1;
|
|
104
|
+
}
|
|
105
|
+
return items;
|
|
106
|
+
}
|
|
107
|
+
export async function handleGenerateCommand(options, paths) {
|
|
108
|
+
fs.mkdirSync(paths.outDir, { recursive: true });
|
|
109
|
+
if (!fs.existsSync(paths.configPath)) {
|
|
110
|
+
console.error("ā Missing config.json. Create it first (see README).");
|
|
111
|
+
console.error(` Looked in: ${paths.projectRoot}`);
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
const cfg = loadConfig(paths);
|
|
115
|
+
const last = loadLastState(paths);
|
|
116
|
+
if (cfg.client.length === 0) {
|
|
117
|
+
exitWithError("ā No clients found in config.json");
|
|
118
|
+
}
|
|
119
|
+
const selectedClient = await selectClient(cfg, options.client);
|
|
120
|
+
const clientKey = selectedClient.name;
|
|
121
|
+
const clientHistory = last.clients[clientKey] || {
|
|
122
|
+
lastHours: 160,
|
|
123
|
+
lastRate: selectedClient.defaultRate ?? 0,
|
|
124
|
+
seqByMonth: {},
|
|
125
|
+
};
|
|
126
|
+
const month = options.month || getDefaultMonth();
|
|
127
|
+
if (!validateMonth(month)) {
|
|
128
|
+
exitWithError("ā Month must be in YYYY-MM format");
|
|
129
|
+
}
|
|
130
|
+
let lineItems = [];
|
|
131
|
+
let entryIdsToArchive = [];
|
|
132
|
+
if (options.fromTimesheet) {
|
|
133
|
+
console.log(`\nš Reading timesheet for ${selectedClient.name} (${month})...`);
|
|
134
|
+
const entries = readTimesheetEntries(paths, { client: selectedClient.name, month });
|
|
135
|
+
if (entries.length === 0) {
|
|
136
|
+
console.log(" No unbilled entries found for this period.");
|
|
137
|
+
console.log(" Falling back to manual entry mode.\n");
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
console.log(` Found ${entries.length} unbilled entries.\n`);
|
|
141
|
+
const aggregated = aggregateEntriesByDescription(entries);
|
|
142
|
+
console.log("š Aggregated by service/project:\n");
|
|
143
|
+
aggregated.forEach((group, index) => {
|
|
144
|
+
console.log(` ${index + 1}. ${group.description}`);
|
|
145
|
+
console.log(` ${group.hours}h Ć $${group.rate}/hr = $${group.amount}`);
|
|
146
|
+
if (group.rateVariance) {
|
|
147
|
+
console.log(` ā ļø Rate variance: $${group.minRate}-$${group.maxRate}/hr (using weighted average)`);
|
|
148
|
+
}
|
|
149
|
+
console.log(` Period: ${group.periodFrom} to ${group.periodTo}`);
|
|
150
|
+
console.log(` Based on ${group.entryIds.length} timesheet entries\n`);
|
|
151
|
+
});
|
|
152
|
+
const answer = await inquirer.prompt([
|
|
153
|
+
{
|
|
154
|
+
type: "confirm",
|
|
155
|
+
name: "confirmUse",
|
|
156
|
+
message: "Use these aggregated line items?",
|
|
157
|
+
default: true,
|
|
158
|
+
},
|
|
159
|
+
]);
|
|
160
|
+
if (answer.confirmUse) {
|
|
161
|
+
lineItems = aggregated.map((group) => ({
|
|
162
|
+
description: group.description,
|
|
163
|
+
hours: group.hours,
|
|
164
|
+
rate: group.rate,
|
|
165
|
+
amount: group.amount,
|
|
166
|
+
periodFrom: group.periodFrom,
|
|
167
|
+
periodTo: group.periodTo,
|
|
168
|
+
}));
|
|
169
|
+
entryIdsToArchive = aggregated.flatMap((group) => group.entryIds);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (lineItems.length === 0) {
|
|
174
|
+
lineItems = await collectManualLineItems({
|
|
175
|
+
options,
|
|
176
|
+
cfg,
|
|
177
|
+
currency: getCurrency(selectedClient.currency),
|
|
178
|
+
lastHours: clientHistory.lastHours,
|
|
179
|
+
lastRate: clientHistory.lastRate,
|
|
180
|
+
defaultRate: selectedClient.defaultRate ?? 0,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
const seqByMonth = { ...(clientHistory.seqByMonth || {}) };
|
|
184
|
+
const invoiceNumber = resolveInvoiceNumber({
|
|
185
|
+
month,
|
|
186
|
+
invoicePrefix: cfg.invoicePrefix,
|
|
187
|
+
overrideInvoice: options.invoice,
|
|
188
|
+
seqByMonth,
|
|
189
|
+
});
|
|
190
|
+
const invoiceDate = getInvoiceDate();
|
|
191
|
+
const { periodFrom, periodTo } = getInvoicePeriod(month);
|
|
192
|
+
const currency = getCurrency(selectedClient.currency);
|
|
193
|
+
const total = lineItems.reduce((sum, item) => sum + item.amount, 0);
|
|
194
|
+
console.log(`\nš° Total: ${currency}${total.toFixed(2)}\n`);
|
|
195
|
+
const outPath = await renderInvoicePdf(paths, {
|
|
196
|
+
from: cfg.from || {},
|
|
197
|
+
client: selectedClient,
|
|
198
|
+
currency,
|
|
199
|
+
invoiceNumber,
|
|
200
|
+
invoiceDate,
|
|
201
|
+
periodFrom,
|
|
202
|
+
periodTo,
|
|
203
|
+
lineItems,
|
|
204
|
+
paymentTerms: selectedClient.payPeriodType,
|
|
205
|
+
note: cfg.note,
|
|
206
|
+
}, month);
|
|
207
|
+
if (!last.clients) {
|
|
208
|
+
last.clients = {};
|
|
209
|
+
}
|
|
210
|
+
const firstLineItem = lineItems[0];
|
|
211
|
+
last.clients[clientKey] = {
|
|
212
|
+
lastHours: firstLineItem?.hours ?? clientHistory.lastHours,
|
|
213
|
+
lastRate: firstLineItem?.rate ?? clientHistory.lastRate,
|
|
214
|
+
seqByMonth,
|
|
215
|
+
};
|
|
216
|
+
writeJsonFile(paths.lastPath, last);
|
|
217
|
+
console.log("ā
Invoice generated:", outPath);
|
|
218
|
+
console.log("Invoice #:", invoiceNumber);
|
|
219
|
+
console.log("Total:", `${currency} ${total.toFixed(2)}`);
|
|
220
|
+
if (entryIdsToArchive.length > 0) {
|
|
221
|
+
const answer = await inquirer.prompt([
|
|
222
|
+
{
|
|
223
|
+
type: "confirm",
|
|
224
|
+
name: "confirmArchive",
|
|
225
|
+
message: `Archive ${entryIdsToArchive.length} timesheet entries used in this invoice?`,
|
|
226
|
+
default: true,
|
|
227
|
+
},
|
|
228
|
+
]);
|
|
229
|
+
if (answer.confirmArchive) {
|
|
230
|
+
const archivedCount = archiveTimesheetEntries(paths, entryIdsToArchive, invoiceNumber, month);
|
|
231
|
+
console.log(`ā
Archived ${archivedCount} entries to data/archive.json`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (hasSmtpConfig()) {
|
|
235
|
+
const answer = await inquirer.prompt([
|
|
236
|
+
{
|
|
237
|
+
type: "confirm",
|
|
238
|
+
name: "sendEmail",
|
|
239
|
+
message: "Send invoice via email?",
|
|
240
|
+
default: true,
|
|
241
|
+
},
|
|
242
|
+
]);
|
|
243
|
+
if (answer.sendEmail) {
|
|
244
|
+
const emailAnswer = await inquirer.prompt([
|
|
245
|
+
{
|
|
246
|
+
type: "input",
|
|
247
|
+
name: "clientEmail",
|
|
248
|
+
message: "Client email address:",
|
|
249
|
+
default: selectedClient.email || "",
|
|
250
|
+
validate: (value) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value) || "Enter valid email",
|
|
251
|
+
},
|
|
252
|
+
]);
|
|
253
|
+
try {
|
|
254
|
+
console.log("\nš§ Sending email...");
|
|
255
|
+
await sendInvoiceEmail({
|
|
256
|
+
outPath,
|
|
257
|
+
invoiceNumber,
|
|
258
|
+
clientName: selectedClient.name,
|
|
259
|
+
clientEmail: emailAnswer.clientEmail,
|
|
260
|
+
currency,
|
|
261
|
+
total,
|
|
262
|
+
periodFrom,
|
|
263
|
+
periodTo,
|
|
264
|
+
senderName: cfg.from?.name,
|
|
265
|
+
});
|
|
266
|
+
console.log(`ā
Email sent successfully to ${emailAnswer.clientEmail}`);
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
270
|
+
console.error("ā Failed to send email:", message);
|
|
271
|
+
console.log(" PDF saved locally at:", outPath);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
console.log("\nš” Tip: Configure SMTP in .env to enable email sending");
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
export function registerGenerateCommand(program, paths) {
|
|
280
|
+
program
|
|
281
|
+
.command("generate", { isDefault: true })
|
|
282
|
+
.description("Generate an invoice from manual entry or timesheet")
|
|
283
|
+
.option("--from-timesheet", "Auto-populate from timesheet entries", false)
|
|
284
|
+
.option("--client <name>", "Client name (auto-selected if only one client)")
|
|
285
|
+
.option("--month <YYYY-MM>", "Invoice month (default: current month)")
|
|
286
|
+
.option("--hours <number>", "Hours for first line item")
|
|
287
|
+
.option("--rate <number>", "Rate for first line item")
|
|
288
|
+
.option("--desc <text>", "Description for first line item")
|
|
289
|
+
.option("--invoice <number>", "Custom invoice number")
|
|
290
|
+
.action(async (options) => {
|
|
291
|
+
await handleGenerateCommand(options, paths);
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/commands/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEpE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1E,OAAO,EACL,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,GACd,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,gBAAgB,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AED,MAAM,UAAU,uBAAuB,CAAC,OAAgB,EAAE,KAAmB;IAC3E,OAAO;SACJ,OAAO,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;SACxC,WAAW,CAAC,oDAAoD,CAAC;SACjE,MAAM,CAAC,kBAAkB,EAAE,sCAAsC,EAAE,KAAK,CAAC;SACzE,MAAM,CAAC,iBAAiB,EAAE,gDAAgD,CAAC;SAC3E,MAAM,CAAC,mBAAmB,EAAE,wCAAwC,CAAC;SACrE,MAAM,CAAC,kBAAkB,EAAE,2BAA2B,CAAC;SACvD,MAAM,CAAC,iBAAiB,EAAE,0BAA0B,CAAC;SACrD,MAAM,CAAC,eAAe,EAAE,iCAAiC,CAAC;SAC1D,MAAM,CAAC,oBAAoB,EAAE,uBAAuB,CAAC;SACrD,MAAM,CAAC,KAAK,EAAE,OAAwB,EAAE,EAAE;QACzC,MAAM,qBAAqB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { readArchivedEntries, readTimesheetEntries, toArchiveCsv, toTimesheetCsv, } from "../services/timesheet.js";
|
|
2
|
+
export function registerTimesheetCommand(program, paths) {
|
|
3
|
+
program
|
|
4
|
+
.command("timesheet")
|
|
5
|
+
.description("Manage timesheet data")
|
|
6
|
+
.option("--export <format>", "Export timesheet (csv|json)", "")
|
|
7
|
+
.option("--client <name>", "Filter by client")
|
|
8
|
+
.option("--month <YYYY-MM>", "Filter by month")
|
|
9
|
+
.option("--archive", "Show archived entries", false)
|
|
10
|
+
.action(async (options) => {
|
|
11
|
+
if (options.archive) {
|
|
12
|
+
const archived = readArchivedEntries(paths, {
|
|
13
|
+
client: options.client || "",
|
|
14
|
+
month: options.month || "",
|
|
15
|
+
});
|
|
16
|
+
if (options.export === "csv") {
|
|
17
|
+
console.log(toArchiveCsv(archived));
|
|
18
|
+
process.exit(0);
|
|
19
|
+
}
|
|
20
|
+
console.log(JSON.stringify(archived, null, 2));
|
|
21
|
+
process.exit(0);
|
|
22
|
+
}
|
|
23
|
+
const entries = readTimesheetEntries(paths, {
|
|
24
|
+
client: options.client || "",
|
|
25
|
+
month: options.month || "",
|
|
26
|
+
});
|
|
27
|
+
if (options.export === "csv") {
|
|
28
|
+
console.log(toTimesheetCsv(entries));
|
|
29
|
+
process.exit(0);
|
|
30
|
+
}
|
|
31
|
+
console.log(JSON.stringify(entries, null, 2));
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=timesheet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timesheet.js","sourceRoot":"","sources":["../../src/commands/timesheet.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,cAAc,GACf,MAAM,0BAA0B,CAAC;AAElC,MAAM,UAAU,wBAAwB,CAAC,OAAgB,EAAE,KAAmB;IAC5E,OAAO;SACJ,OAAO,CAAC,WAAW,CAAC;SACpB,WAAW,CAAC,uBAAuB,CAAC;SACpC,MAAM,CAAC,mBAAmB,EAAE,6BAA6B,EAAE,EAAE,CAAC;SAC9D,MAAM,CAAC,iBAAiB,EAAE,kBAAkB,CAAC;SAC7C,MAAM,CAAC,mBAAmB,EAAE,iBAAiB,CAAC;SAC9C,MAAM,CAAC,WAAW,EAAE,uBAAuB,EAAE,KAAK,CAAC;SACnD,MAAM,CAAC,KAAK,EAAE,OAAyB,EAAE,EAAE;QAC1C,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,QAAQ,GAAG,mBAAmB,CAAC,KAAK,EAAE;gBAC1C,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;gBAC5B,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE;aAC3B,CAAC,CAAC;YAEH,IAAI,OAAO,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;gBAC7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