@hasna/microservices 0.0.16 → 0.0.17
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/README.md +143 -23
- package/bin/index.js +711 -13998
- package/bin/mcp.js +228 -10987
- package/dist/index.js +166 -10056
- package/package.json +25 -25
- package/microservices/microservice-ads/package.json +0 -28
- package/microservices/microservice-ads/src/cli/index.ts +0 -605
- package/microservices/microservice-ads/src/db/campaigns.ts +0 -797
- package/microservices/microservice-ads/src/db/database.ts +0 -91
- package/microservices/microservice-ads/src/db/migrations.ts +0 -60
- package/microservices/microservice-ads/src/index.ts +0 -39
- package/microservices/microservice-ads/src/mcp/index.ts +0 -480
- package/microservices/microservice-analytics/package.json +0 -28
- package/microservices/microservice-analytics/src/cli/index.ts +0 -373
- package/microservices/microservice-analytics/src/db/analytics.ts +0 -564
- package/microservices/microservice-analytics/src/db/database.ts +0 -91
- package/microservices/microservice-analytics/src/db/migrations.ts +0 -50
- package/microservices/microservice-analytics/src/index.ts +0 -37
- package/microservices/microservice-analytics/src/mcp/index.ts +0 -334
- package/microservices/microservice-assets/package.json +0 -28
- package/microservices/microservice-assets/src/cli/index.ts +0 -375
- package/microservices/microservice-assets/src/db/assets.ts +0 -370
- package/microservices/microservice-assets/src/db/database.ts +0 -91
- package/microservices/microservice-assets/src/db/migrations.ts +0 -51
- package/microservices/microservice-assets/src/index.ts +0 -32
- package/microservices/microservice-assets/src/mcp/index.ts +0 -346
- package/microservices/microservice-bookkeeping/package.json +0 -28
- package/microservices/microservice-bookkeeping/src/cli/index.ts +0 -386
- package/microservices/microservice-bookkeeping/src/db/bookkeeping.ts +0 -591
- package/microservices/microservice-bookkeeping/src/db/database.ts +0 -91
- package/microservices/microservice-bookkeeping/src/db/migrations.ts +0 -52
- package/microservices/microservice-bookkeeping/src/index.ts +0 -32
- package/microservices/microservice-bookkeeping/src/mcp/index.ts +0 -284
- package/microservices/microservice-calendar/package.json +0 -28
- package/microservices/microservice-calendar/src/cli/index.ts +0 -287
- package/microservices/microservice-calendar/src/db/calendar.ts +0 -328
- package/microservices/microservice-calendar/src/db/database.ts +0 -91
- package/microservices/microservice-calendar/src/db/migrations.ts +0 -47
- package/microservices/microservice-calendar/src/index.ts +0 -24
- package/microservices/microservice-calendar/src/mcp/index.ts +0 -226
- package/microservices/microservice-company/package.json +0 -28
- package/microservices/microservice-company/src/cli/index.ts +0 -1126
- package/microservices/microservice-company/src/db/company.ts +0 -854
- package/microservices/microservice-company/src/db/database.ts +0 -91
- package/microservices/microservice-company/src/db/migrations.ts +0 -214
- package/microservices/microservice-company/src/db/workflow-migrations.ts +0 -44
- package/microservices/microservice-company/src/index.ts +0 -60
- package/microservices/microservice-company/src/lib/audit.ts +0 -168
- package/microservices/microservice-company/src/lib/finance.ts +0 -299
- package/microservices/microservice-company/src/lib/settings.ts +0 -85
- package/microservices/microservice-company/src/lib/workflows.ts +0 -698
- package/microservices/microservice-company/src/mcp/index.ts +0 -991
- package/microservices/microservice-compliance/package.json +0 -28
- package/microservices/microservice-compliance/src/cli/index.ts +0 -467
- package/microservices/microservice-compliance/src/db/compliance.ts +0 -633
- package/microservices/microservice-compliance/src/db/database.ts +0 -91
- package/microservices/microservice-compliance/src/db/migrations.ts +0 -63
- package/microservices/microservice-compliance/src/index.ts +0 -46
- package/microservices/microservice-compliance/src/mcp/index.ts +0 -438
- package/microservices/microservice-contacts/package.json +0 -28
- package/microservices/microservice-contacts/src/cli/index.ts +0 -393
- package/microservices/microservice-contacts/src/db/companies.ts +0 -167
- package/microservices/microservice-contacts/src/db/contacts.ts +0 -249
- package/microservices/microservice-contacts/src/db/database.ts +0 -91
- package/microservices/microservice-contacts/src/db/migrations.ts +0 -71
- package/microservices/microservice-contacts/src/db/relationships.ts +0 -53
- package/microservices/microservice-contacts/src/index.ts +0 -42
- package/microservices/microservice-contacts/src/mcp/index.ts +0 -303
- package/microservices/microservice-contracts/package.json +0 -28
- package/microservices/microservice-contracts/src/cli/index.ts +0 -770
- package/microservices/microservice-contracts/src/db/contracts.ts +0 -925
- package/microservices/microservice-contracts/src/db/database.ts +0 -91
- package/microservices/microservice-contracts/src/db/migrations.ts +0 -141
- package/microservices/microservice-contracts/src/index.ts +0 -43
- package/microservices/microservice-contracts/src/mcp/index.ts +0 -617
- package/microservices/microservice-crm/package.json +0 -28
- package/microservices/microservice-crm/src/cli/index.ts +0 -396
- package/microservices/microservice-crm/src/db/database.ts +0 -91
- package/microservices/microservice-crm/src/db/migrations.ts +0 -66
- package/microservices/microservice-crm/src/db/pipeline.ts +0 -397
- package/microservices/microservice-crm/src/index.ts +0 -34
- package/microservices/microservice-crm/src/mcp/index.ts +0 -294
- package/microservices/microservice-documents/package.json +0 -28
- package/microservices/microservice-documents/src/cli/index.ts +0 -246
- package/microservices/microservice-documents/src/db/database.ts +0 -91
- package/microservices/microservice-documents/src/db/documents.ts +0 -316
- package/microservices/microservice-documents/src/db/migrations.ts +0 -49
- package/microservices/microservice-documents/src/index.ts +0 -24
- package/microservices/microservice-documents/src/mcp/index.ts +0 -202
- package/microservices/microservice-domains/package.json +0 -28
- package/microservices/microservice-domains/src/cli/index.ts +0 -1111
- package/microservices/microservice-domains/src/db/database.ts +0 -91
- package/microservices/microservice-domains/src/db/domains.ts +0 -1164
- package/microservices/microservice-domains/src/db/migrations.ts +0 -60
- package/microservices/microservice-domains/src/index.ts +0 -65
- package/microservices/microservice-domains/src/lib/brandsight.ts +0 -350
- package/microservices/microservice-domains/src/lib/godaddy.ts +0 -338
- package/microservices/microservice-domains/src/lib/namecheap.ts +0 -262
- package/microservices/microservice-domains/src/lib/registrar.ts +0 -355
- package/microservices/microservice-domains/src/mcp/index.ts +0 -781
- package/microservices/microservice-expenses/package.json +0 -28
- package/microservices/microservice-expenses/src/cli/index.ts +0 -267
- package/microservices/microservice-expenses/src/db/database.ts +0 -91
- package/microservices/microservice-expenses/src/db/expenses.ts +0 -345
- package/microservices/microservice-expenses/src/db/migrations.ts +0 -45
- package/microservices/microservice-expenses/src/index.ts +0 -25
- package/microservices/microservice-expenses/src/mcp/index.ts +0 -196
- package/microservices/microservice-habits/package.json +0 -28
- package/microservices/microservice-habits/src/cli/index.ts +0 -315
- package/microservices/microservice-habits/src/db/database.ts +0 -91
- package/microservices/microservice-habits/src/db/habits.ts +0 -451
- package/microservices/microservice-habits/src/db/migrations.ts +0 -46
- package/microservices/microservice-habits/src/index.ts +0 -31
- package/microservices/microservice-habits/src/mcp/index.ts +0 -313
- package/microservices/microservice-health/package.json +0 -28
- package/microservices/microservice-health/src/cli/index.ts +0 -484
- package/microservices/microservice-health/src/db/database.ts +0 -91
- package/microservices/microservice-health/src/db/health.ts +0 -708
- package/microservices/microservice-health/src/db/migrations.ts +0 -70
- package/microservices/microservice-health/src/index.ts +0 -63
- package/microservices/microservice-health/src/mcp/index.ts +0 -437
- package/microservices/microservice-hiring/package.json +0 -28
- package/microservices/microservice-hiring/src/cli/index.ts +0 -741
- package/microservices/microservice-hiring/src/db/database.ts +0 -91
- package/microservices/microservice-hiring/src/db/hiring.ts +0 -1085
- package/microservices/microservice-hiring/src/db/migrations.ts +0 -89
- package/microservices/microservice-hiring/src/index.ts +0 -80
- package/microservices/microservice-hiring/src/lib/scoring.ts +0 -206
- package/microservices/microservice-hiring/src/mcp/index.ts +0 -709
- package/microservices/microservice-inventory/package.json +0 -28
- package/microservices/microservice-inventory/src/cli/index.ts +0 -365
- package/microservices/microservice-inventory/src/db/database.ts +0 -91
- package/microservices/microservice-inventory/src/db/inventory.ts +0 -393
- package/microservices/microservice-inventory/src/db/migrations.ts +0 -54
- package/microservices/microservice-inventory/src/index.ts +0 -28
- package/microservices/microservice-inventory/src/mcp/index.ts +0 -250
- package/microservices/microservice-invoices/dashboard/index.html +0 -12
- package/microservices/microservice-invoices/dashboard/package.json +0 -29
- package/microservices/microservice-invoices/dashboard/tsconfig.json +0 -14
- package/microservices/microservice-invoices/dashboard/vite.config.ts +0 -15
- package/microservices/microservice-invoices/package.json +0 -31
- package/microservices/microservice-invoices/src/cli/index.ts +0 -308
- package/microservices/microservice-invoices/src/db/business.ts +0 -241
- package/microservices/microservice-invoices/src/db/clients.ts +0 -127
- package/microservices/microservice-invoices/src/db/database.ts +0 -91
- package/microservices/microservice-invoices/src/db/invoices.ts +0 -345
- package/microservices/microservice-invoices/src/db/migrations.ts +0 -184
- package/microservices/microservice-invoices/src/index.ts +0 -56
- package/microservices/microservice-invoices/src/mcp/index.ts +0 -242
- package/microservices/microservice-invoices/src/server/index.ts +0 -162
- package/microservices/microservice-leads/package.json +0 -28
- package/microservices/microservice-leads/src/cli/index.ts +0 -596
- package/microservices/microservice-leads/src/db/database.ts +0 -91
- package/microservices/microservice-leads/src/db/leads.ts +0 -520
- package/microservices/microservice-leads/src/db/lists.ts +0 -151
- package/microservices/microservice-leads/src/db/migrations.ts +0 -93
- package/microservices/microservice-leads/src/index.ts +0 -65
- package/microservices/microservice-leads/src/lib/enrichment.ts +0 -202
- package/microservices/microservice-leads/src/lib/scoring.ts +0 -134
- package/microservices/microservice-leads/src/mcp/index.ts +0 -533
- package/microservices/microservice-notes/package.json +0 -28
- package/microservices/microservice-notes/src/cli/index.ts +0 -63
- package/microservices/microservice-notes/src/db/database.ts +0 -91
- package/microservices/microservice-notes/src/db/migrations.ts +0 -40
- package/microservices/microservice-notes/src/db/notes.ts +0 -114
- package/microservices/microservice-notes/src/index.ts +0 -2
- package/microservices/microservice-notes/src/mcp/index.ts +0 -37
- package/microservices/microservice-notifications/package.json +0 -28
- package/microservices/microservice-notifications/src/cli/index.ts +0 -349
- package/microservices/microservice-notifications/src/db/database.ts +0 -91
- package/microservices/microservice-notifications/src/db/migrations.ts +0 -62
- package/microservices/microservice-notifications/src/db/notifications.ts +0 -509
- package/microservices/microservice-notifications/src/index.ts +0 -41
- package/microservices/microservice-notifications/src/mcp/index.ts +0 -422
- package/microservices/microservice-payments/package.json +0 -28
- package/microservices/microservice-payments/src/cli/index.ts +0 -609
- package/microservices/microservice-payments/src/db/database.ts +0 -91
- package/microservices/microservice-payments/src/db/migrations.ts +0 -81
- package/microservices/microservice-payments/src/db/payments.ts +0 -1204
- package/microservices/microservice-payments/src/index.ts +0 -51
- package/microservices/microservice-payments/src/mcp/index.ts +0 -683
- package/microservices/microservice-payroll/package.json +0 -28
- package/microservices/microservice-payroll/src/cli/index.ts +0 -643
- package/microservices/microservice-payroll/src/db/database.ts +0 -91
- package/microservices/microservice-payroll/src/db/migrations.ts +0 -95
- package/microservices/microservice-payroll/src/db/payroll.ts +0 -1377
- package/microservices/microservice-payroll/src/index.ts +0 -48
- package/microservices/microservice-payroll/src/mcp/index.ts +0 -666
- package/microservices/microservice-products/package.json +0 -28
- package/microservices/microservice-products/src/cli/index.ts +0 -416
- package/microservices/microservice-products/src/db/categories.ts +0 -154
- package/microservices/microservice-products/src/db/database.ts +0 -91
- package/microservices/microservice-products/src/db/migrations.ts +0 -58
- package/microservices/microservice-products/src/db/pricing-tiers.ts +0 -66
- package/microservices/microservice-products/src/db/products.ts +0 -452
- package/microservices/microservice-products/src/index.ts +0 -53
- package/microservices/microservice-products/src/mcp/index.ts +0 -453
- package/microservices/microservice-projects/package.json +0 -28
- package/microservices/microservice-projects/src/cli/index.ts +0 -480
- package/microservices/microservice-projects/src/db/database.ts +0 -91
- package/microservices/microservice-projects/src/db/migrations.ts +0 -65
- package/microservices/microservice-projects/src/db/projects.ts +0 -715
- package/microservices/microservice-projects/src/index.ts +0 -57
- package/microservices/microservice-projects/src/mcp/index.ts +0 -501
- package/microservices/microservice-proposals/package.json +0 -28
- package/microservices/microservice-proposals/src/cli/index.ts +0 -400
- package/microservices/microservice-proposals/src/db/database.ts +0 -91
- package/microservices/microservice-proposals/src/db/migrations.ts +0 -52
- package/microservices/microservice-proposals/src/db/proposals.ts +0 -532
- package/microservices/microservice-proposals/src/index.ts +0 -37
- package/microservices/microservice-proposals/src/mcp/index.ts +0 -375
- package/microservices/microservice-reading/package.json +0 -28
- package/microservices/microservice-reading/src/cli/index.ts +0 -464
- package/microservices/microservice-reading/src/db/database.ts +0 -91
- package/microservices/microservice-reading/src/db/migrations.ts +0 -59
- package/microservices/microservice-reading/src/db/reading.ts +0 -524
- package/microservices/microservice-reading/src/index.ts +0 -51
- package/microservices/microservice-reading/src/mcp/index.ts +0 -368
- package/microservices/microservice-shipping/package.json +0 -28
- package/microservices/microservice-shipping/src/cli/index.ts +0 -606
- package/microservices/microservice-shipping/src/db/database.ts +0 -91
- package/microservices/microservice-shipping/src/db/migrations.ts +0 -69
- package/microservices/microservice-shipping/src/db/shipping.ts +0 -1093
- package/microservices/microservice-shipping/src/index.ts +0 -53
- package/microservices/microservice-shipping/src/mcp/index.ts +0 -533
- package/microservices/microservice-social/package.json +0 -29
- package/microservices/microservice-social/src/cli/index.ts +0 -1583
- package/microservices/microservice-social/src/db/database.ts +0 -91
- package/microservices/microservice-social/src/db/migrations.ts +0 -160
- package/microservices/microservice-social/src/db/social.ts +0 -1076
- package/microservices/microservice-social/src/index.ts +0 -46
- package/microservices/microservice-social/src/lib/audience.ts +0 -353
- package/microservices/microservice-social/src/lib/content-ai.ts +0 -278
- package/microservices/microservice-social/src/lib/media.ts +0 -311
- package/microservices/microservice-social/src/lib/mentions.ts +0 -434
- package/microservices/microservice-social/src/lib/metrics-sync.ts +0 -264
- package/microservices/microservice-social/src/lib/publisher.ts +0 -377
- package/microservices/microservice-social/src/lib/scheduler.ts +0 -229
- package/microservices/microservice-social/src/lib/sentiment.ts +0 -256
- package/microservices/microservice-social/src/lib/threads.ts +0 -291
- package/microservices/microservice-social/src/mcp/index.ts +0 -1425
- package/microservices/microservice-social/src/server/index.ts +0 -441
- package/microservices/microservice-subscriptions/package.json +0 -28
- package/microservices/microservice-subscriptions/src/cli/index.ts +0 -715
- package/microservices/microservice-subscriptions/src/db/database.ts +0 -91
- package/microservices/microservice-subscriptions/src/db/migrations.ts +0 -125
- package/microservices/microservice-subscriptions/src/db/subscriptions.ts +0 -1256
- package/microservices/microservice-subscriptions/src/index.ts +0 -41
- package/microservices/microservice-subscriptions/src/mcp/index.ts +0 -631
- package/microservices/microservice-timesheets/package.json +0 -28
- package/microservices/microservice-timesheets/src/cli/index.ts +0 -373
- package/microservices/microservice-timesheets/src/db/database.ts +0 -91
- package/microservices/microservice-timesheets/src/db/locale.ts +0 -217
- package/microservices/microservice-timesheets/src/db/migrations.ts +0 -74
- package/microservices/microservice-timesheets/src/db/timesheets.ts +0 -447
- package/microservices/microservice-timesheets/src/index.ts +0 -44
- package/microservices/microservice-timesheets/src/mcp/index.ts +0 -269
- package/microservices/microservice-transcriber/package.json +0 -29
- package/microservices/microservice-transcriber/src/cli/index.ts +0 -1593
- package/microservices/microservice-transcriber/src/db/annotations.ts +0 -37
- package/microservices/microservice-transcriber/src/db/comments.ts +0 -166
- package/microservices/microservice-transcriber/src/db/database.ts +0 -91
- package/microservices/microservice-transcriber/src/db/migrations.ts +0 -118
- package/microservices/microservice-transcriber/src/db/proofread.ts +0 -119
- package/microservices/microservice-transcriber/src/db/transcripts.ts +0 -395
- package/microservices/microservice-transcriber/src/index.ts +0 -43
- package/microservices/microservice-transcriber/src/lib/config.ts +0 -77
- package/microservices/microservice-transcriber/src/lib/diff.ts +0 -91
- package/microservices/microservice-transcriber/src/lib/downloader.ts +0 -638
- package/microservices/microservice-transcriber/src/lib/feeds.ts +0 -62
- package/microservices/microservice-transcriber/src/lib/live.ts +0 -94
- package/microservices/microservice-transcriber/src/lib/notion.ts +0 -129
- package/microservices/microservice-transcriber/src/lib/proofread.ts +0 -296
- package/microservices/microservice-transcriber/src/lib/providers.ts +0 -713
- package/microservices/microservice-transcriber/src/lib/summarizer.ts +0 -147
- package/microservices/microservice-transcriber/src/lib/translator.ts +0 -75
- package/microservices/microservice-transcriber/src/lib/webhook.ts +0 -37
- package/microservices/microservice-transcriber/src/mcp/index.ts +0 -1330
- package/microservices/microservice-transcriber/src/server/index.ts +0 -199
- package/microservices/microservice-travel/package.json +0 -28
- package/microservices/microservice-travel/src/cli/index.ts +0 -505
- package/microservices/microservice-travel/src/db/database.ts +0 -91
- package/microservices/microservice-travel/src/db/migrations.ts +0 -77
- package/microservices/microservice-travel/src/db/travel.ts +0 -802
- package/microservices/microservice-travel/src/index.ts +0 -60
- package/microservices/microservice-travel/src/mcp/index.ts +0 -495
- package/microservices/microservice-wiki/package.json +0 -28
- package/microservices/microservice-wiki/src/cli/index.ts +0 -345
- package/microservices/microservice-wiki/src/db/database.ts +0 -91
- package/microservices/microservice-wiki/src/db/migrations.ts +0 -55
- package/microservices/microservice-wiki/src/db/wiki.ts +0 -395
- package/microservices/microservice-wiki/src/index.ts +0 -32
- package/microservices/microservice-wiki/src/mcp/index.ts +0 -344
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
|
|
3
|
-
import { Command } from "commander";
|
|
4
|
-
import {
|
|
5
|
-
createProject,
|
|
6
|
-
getProject,
|
|
7
|
-
listProjects,
|
|
8
|
-
updateProject,
|
|
9
|
-
deleteProject,
|
|
10
|
-
logTime,
|
|
11
|
-
getEntry,
|
|
12
|
-
listEntries,
|
|
13
|
-
updateEntry,
|
|
14
|
-
deleteEntry,
|
|
15
|
-
getProjectSummary,
|
|
16
|
-
getWeeklySummary,
|
|
17
|
-
getClientSummary,
|
|
18
|
-
} from "../db/timesheets.js";
|
|
19
|
-
|
|
20
|
-
const program = new Command();
|
|
21
|
-
|
|
22
|
-
program
|
|
23
|
-
.name("microservice-timesheets")
|
|
24
|
-
.description("Timesheet management microservice")
|
|
25
|
-
.version("0.0.1");
|
|
26
|
-
|
|
27
|
-
// --- Projects ---
|
|
28
|
-
|
|
29
|
-
const projectCmd = program
|
|
30
|
-
.command("project")
|
|
31
|
-
.description("Project management");
|
|
32
|
-
|
|
33
|
-
projectCmd
|
|
34
|
-
.command("add")
|
|
35
|
-
.description("Add a new project")
|
|
36
|
-
.requiredOption("--name <name>", "Project name")
|
|
37
|
-
.option("--client <client>", "Client name")
|
|
38
|
-
.option("--rate <rate>", "Hourly rate", "0")
|
|
39
|
-
.option("--budget <hours>", "Budget hours", "0")
|
|
40
|
-
.option("--status <status>", "Status: active|completed|archived", "active")
|
|
41
|
-
.option("--json", "Output as JSON", false)
|
|
42
|
-
.action((opts) => {
|
|
43
|
-
const project = createProject({
|
|
44
|
-
name: opts.name,
|
|
45
|
-
client: opts.client,
|
|
46
|
-
hourly_rate: parseFloat(opts.rate),
|
|
47
|
-
budget_hours: parseFloat(opts.budget),
|
|
48
|
-
status: opts.status,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
if (opts.json) {
|
|
52
|
-
console.log(JSON.stringify(project, null, 2));
|
|
53
|
-
} else {
|
|
54
|
-
console.log(`Created project: ${project.name} (${project.id})`);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
projectCmd
|
|
59
|
-
.command("get")
|
|
60
|
-
.description("Get a project by ID")
|
|
61
|
-
.argument("<id>", "Project ID")
|
|
62
|
-
.option("--json", "Output as JSON", false)
|
|
63
|
-
.action((id, opts) => {
|
|
64
|
-
const project = getProject(id);
|
|
65
|
-
if (!project) {
|
|
66
|
-
console.error(`Project '${id}' not found.`);
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (opts.json) {
|
|
71
|
-
console.log(JSON.stringify(project, null, 2));
|
|
72
|
-
} else {
|
|
73
|
-
console.log(`${project.name}`);
|
|
74
|
-
console.log(` Status: ${project.status}`);
|
|
75
|
-
if (project.client) console.log(` Client: ${project.client}`);
|
|
76
|
-
if (project.hourly_rate) console.log(` Rate: $${project.hourly_rate}/hr`);
|
|
77
|
-
if (project.budget_hours) console.log(` Budget: ${project.budget_hours} hrs`);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
projectCmd
|
|
82
|
-
.command("list")
|
|
83
|
-
.description("List projects")
|
|
84
|
-
.option("--status <status>", "Filter by status")
|
|
85
|
-
.option("--client <client>", "Filter by client")
|
|
86
|
-
.option("--limit <n>", "Limit results")
|
|
87
|
-
.option("--json", "Output as JSON", false)
|
|
88
|
-
.action((opts) => {
|
|
89
|
-
const projects = listProjects({
|
|
90
|
-
status: opts.status,
|
|
91
|
-
client: opts.client,
|
|
92
|
-
limit: opts.limit ? parseInt(opts.limit) : undefined,
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
if (opts.json) {
|
|
96
|
-
console.log(JSON.stringify(projects, null, 2));
|
|
97
|
-
} else {
|
|
98
|
-
if (projects.length === 0) {
|
|
99
|
-
console.log("No projects found.");
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
for (const p of projects) {
|
|
103
|
-
const client = p.client ? ` (${p.client})` : "";
|
|
104
|
-
const rate = p.hourly_rate ? ` $${p.hourly_rate}/hr` : "";
|
|
105
|
-
console.log(` ${p.name}${client}${rate} [${p.status}]`);
|
|
106
|
-
}
|
|
107
|
-
console.log(`\n${projects.length} project(s)`);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
projectCmd
|
|
112
|
-
.command("update")
|
|
113
|
-
.description("Update a project")
|
|
114
|
-
.argument("<id>", "Project ID")
|
|
115
|
-
.option("--name <name>", "Project name")
|
|
116
|
-
.option("--client <client>", "Client name")
|
|
117
|
-
.option("--rate <rate>", "Hourly rate")
|
|
118
|
-
.option("--budget <hours>", "Budget hours")
|
|
119
|
-
.option("--status <status>", "Status")
|
|
120
|
-
.option("--json", "Output as JSON", false)
|
|
121
|
-
.action((id, opts) => {
|
|
122
|
-
const input: Record<string, unknown> = {};
|
|
123
|
-
if (opts.name !== undefined) input.name = opts.name;
|
|
124
|
-
if (opts.client !== undefined) input.client = opts.client;
|
|
125
|
-
if (opts.rate !== undefined) input.hourly_rate = parseFloat(opts.rate);
|
|
126
|
-
if (opts.budget !== undefined) input.budget_hours = parseFloat(opts.budget);
|
|
127
|
-
if (opts.status !== undefined) input.status = opts.status;
|
|
128
|
-
|
|
129
|
-
const project = updateProject(id, input);
|
|
130
|
-
if (!project) {
|
|
131
|
-
console.error(`Project '${id}' not found.`);
|
|
132
|
-
process.exit(1);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (opts.json) {
|
|
136
|
-
console.log(JSON.stringify(project, null, 2));
|
|
137
|
-
} else {
|
|
138
|
-
console.log(`Updated: ${project.name}`);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
projectCmd
|
|
143
|
-
.command("delete")
|
|
144
|
-
.description("Delete a project")
|
|
145
|
-
.argument("<id>", "Project ID")
|
|
146
|
-
.action((id) => {
|
|
147
|
-
const deleted = deleteProject(id);
|
|
148
|
-
if (deleted) {
|
|
149
|
-
console.log(`Deleted project ${id}`);
|
|
150
|
-
} else {
|
|
151
|
-
console.error(`Project '${id}' not found.`);
|
|
152
|
-
process.exit(1);
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
// --- Time Entries ---
|
|
157
|
-
|
|
158
|
-
program
|
|
159
|
-
.command("log")
|
|
160
|
-
.description("Log a time entry")
|
|
161
|
-
.requiredOption("--project <id>", "Project ID")
|
|
162
|
-
.requiredOption("--description <text>", "Description of work")
|
|
163
|
-
.requiredOption("--hours <hours>", "Hours worked")
|
|
164
|
-
.option("--date <date>", "Date (YYYY-MM-DD)")
|
|
165
|
-
.option("--no-billable", "Mark as non-billable")
|
|
166
|
-
.option("--tags <tags>", "Comma-separated tags")
|
|
167
|
-
.option("--json", "Output as JSON", false)
|
|
168
|
-
.action((opts) => {
|
|
169
|
-
const entry = logTime({
|
|
170
|
-
project_id: opts.project,
|
|
171
|
-
description: opts.description,
|
|
172
|
-
hours: parseFloat(opts.hours),
|
|
173
|
-
date: opts.date,
|
|
174
|
-
billable: opts.billable,
|
|
175
|
-
tags: opts.tags ? opts.tags.split(",").map((t: string) => t.trim()) : undefined,
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
if (opts.json) {
|
|
179
|
-
console.log(JSON.stringify(entry, null, 2));
|
|
180
|
-
} else {
|
|
181
|
-
const billable = entry.billable ? "" : " (non-billable)";
|
|
182
|
-
console.log(`Logged ${entry.hours}h: ${entry.description}${billable} [${entry.date}]`);
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
program
|
|
187
|
-
.command("get")
|
|
188
|
-
.description("Get a time entry by ID")
|
|
189
|
-
.argument("<id>", "Entry ID")
|
|
190
|
-
.option("--json", "Output as JSON", false)
|
|
191
|
-
.action((id, opts) => {
|
|
192
|
-
const entry = getEntry(id);
|
|
193
|
-
if (!entry) {
|
|
194
|
-
console.error(`Entry '${id}' not found.`);
|
|
195
|
-
process.exit(1);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (opts.json) {
|
|
199
|
-
console.log(JSON.stringify(entry, null, 2));
|
|
200
|
-
} else {
|
|
201
|
-
const billable = entry.billable ? "billable" : "non-billable";
|
|
202
|
-
console.log(`${entry.description}`);
|
|
203
|
-
console.log(` Date: ${entry.date}`);
|
|
204
|
-
console.log(` Hours: ${entry.hours} (${billable})`);
|
|
205
|
-
console.log(` Project: ${entry.project_id}`);
|
|
206
|
-
if (entry.tags.length) console.log(` Tags: ${entry.tags.join(", ")}`);
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
program
|
|
211
|
-
.command("list")
|
|
212
|
-
.description("List time entries")
|
|
213
|
-
.option("--project <id>", "Filter by project ID")
|
|
214
|
-
.option("--from <date>", "From date (YYYY-MM-DD)")
|
|
215
|
-
.option("--to <date>", "To date (YYYY-MM-DD)")
|
|
216
|
-
.option("--billable", "Show only billable entries")
|
|
217
|
-
.option("--non-billable", "Show only non-billable entries")
|
|
218
|
-
.option("--limit <n>", "Limit results")
|
|
219
|
-
.option("--json", "Output as JSON", false)
|
|
220
|
-
.action((opts) => {
|
|
221
|
-
let billable: boolean | undefined;
|
|
222
|
-
if (opts.billable) billable = true;
|
|
223
|
-
if (opts.nonBillable) billable = false;
|
|
224
|
-
|
|
225
|
-
const entries = listEntries({
|
|
226
|
-
project_id: opts.project,
|
|
227
|
-
from_date: opts.from,
|
|
228
|
-
to_date: opts.to,
|
|
229
|
-
billable,
|
|
230
|
-
limit: opts.limit ? parseInt(opts.limit) : undefined,
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
if (opts.json) {
|
|
234
|
-
console.log(JSON.stringify(entries, null, 2));
|
|
235
|
-
} else {
|
|
236
|
-
if (entries.length === 0) {
|
|
237
|
-
console.log("No entries found.");
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
for (const e of entries) {
|
|
241
|
-
const b = e.billable ? "" : " (nb)";
|
|
242
|
-
const tags = e.tags.length ? ` [${e.tags.join(", ")}]` : "";
|
|
243
|
-
console.log(` ${e.date} ${String(e.hours).padEnd(5)}h ${e.description}${b}${tags}`);
|
|
244
|
-
}
|
|
245
|
-
const total = entries.reduce((sum, e) => sum + e.hours, 0);
|
|
246
|
-
console.log(`\n${entries.length} entry/entries, ${total}h total`);
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
program
|
|
251
|
-
.command("update")
|
|
252
|
-
.description("Update a time entry")
|
|
253
|
-
.argument("<id>", "Entry ID")
|
|
254
|
-
.option("--project <id>", "Project ID")
|
|
255
|
-
.option("--description <text>", "Description")
|
|
256
|
-
.option("--date <date>", "Date")
|
|
257
|
-
.option("--hours <hours>", "Hours")
|
|
258
|
-
.option("--billable <bool>", "Billable (true/false)")
|
|
259
|
-
.option("--tags <tags>", "Comma-separated tags")
|
|
260
|
-
.option("--json", "Output as JSON", false)
|
|
261
|
-
.action((id, opts) => {
|
|
262
|
-
const input: Record<string, unknown> = {};
|
|
263
|
-
if (opts.project !== undefined) input.project_id = opts.project;
|
|
264
|
-
if (opts.description !== undefined) input.description = opts.description;
|
|
265
|
-
if (opts.date !== undefined) input.date = opts.date;
|
|
266
|
-
if (opts.hours !== undefined) input.hours = parseFloat(opts.hours);
|
|
267
|
-
if (opts.billable !== undefined) input.billable = opts.billable === "true";
|
|
268
|
-
if (opts.tags !== undefined) input.tags = opts.tags.split(",").map((t: string) => t.trim());
|
|
269
|
-
|
|
270
|
-
const entry = updateEntry(id, input);
|
|
271
|
-
if (!entry) {
|
|
272
|
-
console.error(`Entry '${id}' not found.`);
|
|
273
|
-
process.exit(1);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
if (opts.json) {
|
|
277
|
-
console.log(JSON.stringify(entry, null, 2));
|
|
278
|
-
} else {
|
|
279
|
-
console.log(`Updated: ${entry.description} (${entry.hours}h on ${entry.date})`);
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
program
|
|
284
|
-
.command("delete")
|
|
285
|
-
.description("Delete a time entry")
|
|
286
|
-
.argument("<id>", "Entry ID")
|
|
287
|
-
.action((id) => {
|
|
288
|
-
const deleted = deleteEntry(id);
|
|
289
|
-
if (deleted) {
|
|
290
|
-
console.log(`Deleted entry ${id}`);
|
|
291
|
-
} else {
|
|
292
|
-
console.error(`Entry '${id}' not found.`);
|
|
293
|
-
process.exit(1);
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
// --- Summaries ---
|
|
298
|
-
|
|
299
|
-
program
|
|
300
|
-
.command("project-summary")
|
|
301
|
-
.description("Get project summary with hours and value")
|
|
302
|
-
.argument("<id>", "Project ID")
|
|
303
|
-
.option("--json", "Output as JSON", false)
|
|
304
|
-
.action((id, opts) => {
|
|
305
|
-
const summary = getProjectSummary(id);
|
|
306
|
-
if (!summary) {
|
|
307
|
-
console.error(`Project '${id}' not found.`);
|
|
308
|
-
process.exit(1);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
if (opts.json) {
|
|
312
|
-
console.log(JSON.stringify(summary, null, 2));
|
|
313
|
-
} else {
|
|
314
|
-
console.log(`\n Project: ${summary.project_name}`);
|
|
315
|
-
if (summary.client) console.log(` Client: ${summary.client}`);
|
|
316
|
-
console.log(` Total Hours: ${summary.total_hours}`);
|
|
317
|
-
console.log(` Billable Hours: ${summary.billable_hours}`);
|
|
318
|
-
console.log(` Non-Billable: ${summary.non_billable_hours}`);
|
|
319
|
-
console.log(` Total Value: $${summary.total_value.toFixed(2)}`);
|
|
320
|
-
if (summary.budget_hours > 0) {
|
|
321
|
-
console.log(` Budget: ${summary.budget_hours}h`);
|
|
322
|
-
console.log(` Remaining: ${summary.budget_remaining}h`);
|
|
323
|
-
}
|
|
324
|
-
console.log();
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
program
|
|
329
|
-
.command("weekly")
|
|
330
|
-
.description("Get weekly summary")
|
|
331
|
-
.argument("<week-start>", "Week start date (YYYY-MM-DD, typically Monday)")
|
|
332
|
-
.option("--json", "Output as JSON", false)
|
|
333
|
-
.action((weekStart, opts) => {
|
|
334
|
-
const summary = getWeeklySummary(weekStart);
|
|
335
|
-
|
|
336
|
-
if (opts.json) {
|
|
337
|
-
console.log(JSON.stringify(summary, null, 2));
|
|
338
|
-
} else {
|
|
339
|
-
console.log(`\n Week of ${summary.week_start}`);
|
|
340
|
-
for (const day of summary.days) {
|
|
341
|
-
const bar = "#".repeat(Math.round(day.hours));
|
|
342
|
-
const label = day.hours > 0 ? `${day.hours}h (${day.entries} entries)` : "-";
|
|
343
|
-
console.log(` ${day.date} ${label.padEnd(20)} ${bar}`);
|
|
344
|
-
}
|
|
345
|
-
console.log(`\n Total: ${summary.total_hours}h across ${summary.total_entries} entries`);
|
|
346
|
-
console.log();
|
|
347
|
-
}
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
program
|
|
351
|
-
.command("client-summary")
|
|
352
|
-
.description("Get summary by client")
|
|
353
|
-
.option("--json", "Output as JSON", false)
|
|
354
|
-
.action((opts) => {
|
|
355
|
-
const summaries = getClientSummary();
|
|
356
|
-
|
|
357
|
-
if (opts.json) {
|
|
358
|
-
console.log(JSON.stringify(summaries, null, 2));
|
|
359
|
-
} else {
|
|
360
|
-
if (summaries.length === 0) {
|
|
361
|
-
console.log("No data found.");
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
console.log("\n Client Summary");
|
|
365
|
-
for (const s of summaries) {
|
|
366
|
-
console.log(` ${s.client}`);
|
|
367
|
-
console.log(` Projects: ${s.projects} Hours: ${s.total_hours} Billable: ${s.billable_hours} Value: $${s.total_value.toFixed(2)}`);
|
|
368
|
-
}
|
|
369
|
-
console.log();
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
program.parse(process.argv);
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Database connection for microservice-timesheets
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { SqliteAdapter } from "@hasna/cloud";
|
|
6
|
-
import type { Database } from "bun:sqlite";
|
|
7
|
-
import { existsSync, mkdirSync, cpSync } from "node:fs";
|
|
8
|
-
import { dirname, join, resolve } from "node:path";
|
|
9
|
-
import { MIGRATIONS } from "./migrations.js";
|
|
10
|
-
|
|
11
|
-
let _db: Database | null = null;
|
|
12
|
-
|
|
13
|
-
function getDbPath(): string {
|
|
14
|
-
const explicit = process.env["HASNA_MICROSERVICES_DIR"] ?? process.env["MICROSERVICES_DIR"];
|
|
15
|
-
if (explicit) {
|
|
16
|
-
return join(explicit, "microservice-timesheets", "data.db");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
let dir = resolve(process.cwd());
|
|
20
|
-
while (true) {
|
|
21
|
-
const msDir = join(dir, ".microservices");
|
|
22
|
-
if (existsSync(msDir)) return join(msDir, "microservice-timesheets", "data.db");
|
|
23
|
-
const parent = dirname(dir);
|
|
24
|
-
if (parent === dir) break;
|
|
25
|
-
dir = parent;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
|
|
29
|
-
const newDir = join(home, ".hasna", "microservices");
|
|
30
|
-
const oldDir = join(home, ".microservices");
|
|
31
|
-
if (!existsSync(newDir) && existsSync(oldDir)) {
|
|
32
|
-
mkdirSync(join(home, ".hasna"), { recursive: true });
|
|
33
|
-
cpSync(oldDir, newDir, { recursive: true });
|
|
34
|
-
}
|
|
35
|
-
return join(newDir, "microservice-timesheets", "data.db");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function getDatabase(): Database {
|
|
39
|
-
if (_db) return _db;
|
|
40
|
-
|
|
41
|
-
const dbPath = getDbPath();
|
|
42
|
-
const dir = dirname(resolve(dbPath));
|
|
43
|
-
if (!existsSync(dir)) {
|
|
44
|
-
mkdirSync(dir, { recursive: true });
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const adapter = new SqliteAdapter(dbPath);
|
|
48
|
-
_db = adapter.raw;
|
|
49
|
-
// SqliteAdapter already sets WAL and foreign_keys
|
|
50
|
-
|
|
51
|
-
_db.exec(`
|
|
52
|
-
CREATE TABLE IF NOT EXISTS _migrations (
|
|
53
|
-
id INTEGER PRIMARY KEY,
|
|
54
|
-
name TEXT NOT NULL,
|
|
55
|
-
applied_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
56
|
-
)
|
|
57
|
-
`);
|
|
58
|
-
|
|
59
|
-
const applied = _db
|
|
60
|
-
.query("SELECT id FROM _migrations ORDER BY id")
|
|
61
|
-
.all() as { id: number }[];
|
|
62
|
-
const appliedIds = new Set(applied.map((r) => r.id));
|
|
63
|
-
|
|
64
|
-
for (const migration of MIGRATIONS) {
|
|
65
|
-
if (appliedIds.has(migration.id)) continue;
|
|
66
|
-
|
|
67
|
-
_db.exec("BEGIN");
|
|
68
|
-
try {
|
|
69
|
-
_db.exec(migration.sql);
|
|
70
|
-
_db.prepare("INSERT INTO _migrations (id, name) VALUES (?, ?)").run(
|
|
71
|
-
migration.id,
|
|
72
|
-
migration.name
|
|
73
|
-
);
|
|
74
|
-
_db.exec("COMMIT");
|
|
75
|
-
} catch (error) {
|
|
76
|
-
_db.exec("ROLLBACK");
|
|
77
|
-
throw new Error(
|
|
78
|
-
`Migration ${migration.id} (${migration.name}) failed: ${error instanceof Error ? error.message : String(error)}`
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return _db;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function closeDatabase(): void {
|
|
87
|
-
if (_db) {
|
|
88
|
-
_db.close();
|
|
89
|
-
_db = null;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Locale and country-specific settings for timesheets
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { getDatabase } from "./database.js";
|
|
6
|
-
|
|
7
|
-
export interface CountryDefaults {
|
|
8
|
-
currency: string;
|
|
9
|
-
max_daily_hours: number;
|
|
10
|
-
max_weekly_hours: number;
|
|
11
|
-
overtime_multiplier: number;
|
|
12
|
-
date_format: string;
|
|
13
|
-
locale: string;
|
|
14
|
-
week_start: "monday" | "sunday";
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Country-specific defaults for work hours and formatting
|
|
19
|
-
*/
|
|
20
|
-
export const COUNTRY_DEFAULTS: Record<string, CountryDefaults> = {
|
|
21
|
-
// Romania
|
|
22
|
-
RO: {
|
|
23
|
-
currency: "RON",
|
|
24
|
-
max_daily_hours: 8,
|
|
25
|
-
max_weekly_hours: 40,
|
|
26
|
-
overtime_multiplier: 1.75, // Romanian labor code: 75% bonus for first 2h overtime, 100% after
|
|
27
|
-
date_format: "DD.MM.YYYY",
|
|
28
|
-
locale: "ro-RO",
|
|
29
|
-
week_start: "monday",
|
|
30
|
-
},
|
|
31
|
-
// United States
|
|
32
|
-
US: {
|
|
33
|
-
currency: "USD",
|
|
34
|
-
max_daily_hours: 8,
|
|
35
|
-
max_weekly_hours: 40,
|
|
36
|
-
overtime_multiplier: 1.5, // FLSA: time and a half
|
|
37
|
-
date_format: "MM/DD/YYYY",
|
|
38
|
-
locale: "en-US",
|
|
39
|
-
week_start: "sunday",
|
|
40
|
-
},
|
|
41
|
-
// United Kingdom
|
|
42
|
-
GB: {
|
|
43
|
-
currency: "GBP",
|
|
44
|
-
max_daily_hours: 8,
|
|
45
|
-
max_weekly_hours: 48, // UK Working Time Regulations
|
|
46
|
-
overtime_multiplier: 1.5,
|
|
47
|
-
date_format: "DD/MM/YYYY",
|
|
48
|
-
locale: "en-GB",
|
|
49
|
-
week_start: "monday",
|
|
50
|
-
},
|
|
51
|
-
// Germany
|
|
52
|
-
DE: {
|
|
53
|
-
currency: "EUR",
|
|
54
|
-
max_daily_hours: 8,
|
|
55
|
-
max_weekly_hours: 48, // can extend to 10h/day if averaged to 8h over 6 months
|
|
56
|
-
overtime_multiplier: 1.25,
|
|
57
|
-
date_format: "DD.MM.YYYY",
|
|
58
|
-
locale: "de-DE",
|
|
59
|
-
week_start: "monday",
|
|
60
|
-
},
|
|
61
|
-
// France
|
|
62
|
-
FR: {
|
|
63
|
-
currency: "EUR",
|
|
64
|
-
max_daily_hours: 7, // 35h/week standard
|
|
65
|
-
max_weekly_hours: 35,
|
|
66
|
-
overtime_multiplier: 1.25, // 25% first 8h, 50% after
|
|
67
|
-
date_format: "DD/MM/YYYY",
|
|
68
|
-
locale: "fr-FR",
|
|
69
|
-
week_start: "monday",
|
|
70
|
-
},
|
|
71
|
-
// Netherlands
|
|
72
|
-
NL: {
|
|
73
|
-
currency: "EUR",
|
|
74
|
-
max_daily_hours: 8,
|
|
75
|
-
max_weekly_hours: 40,
|
|
76
|
-
overtime_multiplier: 1.5,
|
|
77
|
-
date_format: "DD-MM-YYYY",
|
|
78
|
-
locale: "nl-NL",
|
|
79
|
-
week_start: "monday",
|
|
80
|
-
},
|
|
81
|
-
// Italy
|
|
82
|
-
IT: {
|
|
83
|
-
currency: "EUR",
|
|
84
|
-
max_daily_hours: 8,
|
|
85
|
-
max_weekly_hours: 40,
|
|
86
|
-
overtime_multiplier: 1.25,
|
|
87
|
-
date_format: "DD/MM/YYYY",
|
|
88
|
-
locale: "it-IT",
|
|
89
|
-
week_start: "monday",
|
|
90
|
-
},
|
|
91
|
-
// Spain
|
|
92
|
-
ES: {
|
|
93
|
-
currency: "EUR",
|
|
94
|
-
max_daily_hours: 8,
|
|
95
|
-
max_weekly_hours: 40,
|
|
96
|
-
overtime_multiplier: 1.25,
|
|
97
|
-
date_format: "DD/MM/YYYY",
|
|
98
|
-
locale: "es-ES",
|
|
99
|
-
week_start: "monday",
|
|
100
|
-
},
|
|
101
|
-
// Poland
|
|
102
|
-
PL: {
|
|
103
|
-
currency: "PLN",
|
|
104
|
-
max_daily_hours: 8,
|
|
105
|
-
max_weekly_hours: 40,
|
|
106
|
-
overtime_multiplier: 1.5,
|
|
107
|
-
date_format: "DD.MM.YYYY",
|
|
108
|
-
locale: "pl-PL",
|
|
109
|
-
week_start: "monday",
|
|
110
|
-
},
|
|
111
|
-
// Hungary
|
|
112
|
-
HU: {
|
|
113
|
-
currency: "HUF",
|
|
114
|
-
max_daily_hours: 8,
|
|
115
|
-
max_weekly_hours: 40,
|
|
116
|
-
overtime_multiplier: 1.5,
|
|
117
|
-
date_format: "YYYY.MM.DD",
|
|
118
|
-
locale: "hu-HU",
|
|
119
|
-
week_start: "monday",
|
|
120
|
-
},
|
|
121
|
-
// Sweden
|
|
122
|
-
SE: {
|
|
123
|
-
currency: "SEK",
|
|
124
|
-
max_daily_hours: 8,
|
|
125
|
-
max_weekly_hours: 40,
|
|
126
|
-
overtime_multiplier: 1.5,
|
|
127
|
-
date_format: "YYYY-MM-DD",
|
|
128
|
-
locale: "sv-SE",
|
|
129
|
-
week_start: "monday",
|
|
130
|
-
},
|
|
131
|
-
// Bulgaria
|
|
132
|
-
BG: {
|
|
133
|
-
currency: "BGN",
|
|
134
|
-
max_daily_hours: 8,
|
|
135
|
-
max_weekly_hours: 40,
|
|
136
|
-
overtime_multiplier: 1.5,
|
|
137
|
-
date_format: "DD.MM.YYYY",
|
|
138
|
-
locale: "bg-BG",
|
|
139
|
-
week_start: "monday",
|
|
140
|
-
},
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Get defaults for a country, falling back to US
|
|
145
|
-
*/
|
|
146
|
-
export function getCountryDefaults(country: string): CountryDefaults {
|
|
147
|
-
return COUNTRY_DEFAULTS[country.toUpperCase()] || COUNTRY_DEFAULTS["US"];
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* List all supported countries
|
|
152
|
-
*/
|
|
153
|
-
export function listSupportedCountries(): { code: string; defaults: CountryDefaults }[] {
|
|
154
|
-
return Object.entries(COUNTRY_DEFAULTS).map(([code, defaults]) => ({ code, defaults }));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// --- Settings ---
|
|
158
|
-
|
|
159
|
-
export function getSetting(key: string): string | null {
|
|
160
|
-
const db = getDatabase();
|
|
161
|
-
const row = db.prepare("SELECT value FROM settings WHERE key = ?").get(key) as { value: string } | null;
|
|
162
|
-
return row?.value || null;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export function setSetting(key: string, value: string): void {
|
|
166
|
-
const db = getDatabase();
|
|
167
|
-
db.prepare(
|
|
168
|
-
"INSERT INTO settings (key, value, updated_at) VALUES (?, ?, datetime('now')) ON CONFLICT(key) DO UPDATE SET value = ?, updated_at = datetime('now')"
|
|
169
|
-
).run(key, value, value);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export function getAllSettings(): Record<string, string> {
|
|
173
|
-
const db = getDatabase();
|
|
174
|
-
const rows = db.prepare("SELECT key, value FROM settings").all() as { key: string; value: string }[];
|
|
175
|
-
const settings: Record<string, string> = {};
|
|
176
|
-
for (const row of rows) settings[row.key] = row.value;
|
|
177
|
-
return settings;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Format currency amount according to locale
|
|
182
|
-
*/
|
|
183
|
-
export function formatCurrency(amount: number, currency: string, locale?: string): string {
|
|
184
|
-
const loc = locale || getSetting("locale") || "en-US";
|
|
185
|
-
return new Intl.NumberFormat(loc, {
|
|
186
|
-
style: "currency",
|
|
187
|
-
currency,
|
|
188
|
-
minimumFractionDigits: 2,
|
|
189
|
-
}).format(amount);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Check if hours exceed daily/weekly limits for a country
|
|
194
|
-
*/
|
|
195
|
-
export function checkOvertimeStatus(
|
|
196
|
-
dailyHours: number,
|
|
197
|
-
weeklyHours: number,
|
|
198
|
-
country: string
|
|
199
|
-
): {
|
|
200
|
-
daily_overtime: boolean;
|
|
201
|
-
weekly_overtime: boolean;
|
|
202
|
-
daily_excess: number;
|
|
203
|
-
weekly_excess: number;
|
|
204
|
-
overtime_rate: number;
|
|
205
|
-
} {
|
|
206
|
-
const defaults = getCountryDefaults(country);
|
|
207
|
-
const dailyExcess = Math.max(0, dailyHours - defaults.max_daily_hours);
|
|
208
|
-
const weeklyExcess = Math.max(0, weeklyHours - defaults.max_weekly_hours);
|
|
209
|
-
|
|
210
|
-
return {
|
|
211
|
-
daily_overtime: dailyExcess > 0,
|
|
212
|
-
weekly_overtime: weeklyExcess > 0,
|
|
213
|
-
daily_excess: dailyExcess,
|
|
214
|
-
weekly_excess: weeklyExcess,
|
|
215
|
-
overtime_rate: defaults.overtime_multiplier,
|
|
216
|
-
};
|
|
217
|
-
}
|