@hed-hog/operations 0.0.338 → 0.0.347

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.
Files changed (61) hide show
  1. package/dist/controllers/operations-collaborators.controller.d.ts +73 -0
  2. package/dist/controllers/operations-collaborators.controller.d.ts.map +1 -1
  3. package/dist/controllers/operations-collaborators.controller.js +100 -0
  4. package/dist/controllers/operations-collaborators.controller.js.map +1 -1
  5. package/dist/controllers/operations-contracts.controller.d.ts +12 -12
  6. package/dist/controllers/operations-projects.controller.d.ts +3 -0
  7. package/dist/controllers/operations-projects.controller.d.ts.map +1 -1
  8. package/dist/dto/create-collaborator-invoice.dto.d.ts +11 -0
  9. package/dist/dto/create-collaborator-invoice.dto.d.ts.map +1 -0
  10. package/dist/dto/create-collaborator-invoice.dto.js +55 -0
  11. package/dist/dto/create-collaborator-invoice.dto.js.map +1 -0
  12. package/dist/dto/create-collaborator-payment.dto.d.ts +10 -0
  13. package/dist/dto/create-collaborator-payment.dto.d.ts.map +1 -0
  14. package/dist/dto/create-collaborator-payment.dto.js +50 -0
  15. package/dist/dto/create-collaborator-payment.dto.js.map +1 -0
  16. package/dist/dto/list-collaborator-invoice.dto.d.ts +4 -0
  17. package/dist/dto/list-collaborator-invoice.dto.d.ts.map +1 -0
  18. package/dist/dto/list-collaborator-invoice.dto.js +8 -0
  19. package/dist/dto/list-collaborator-invoice.dto.js.map +1 -0
  20. package/dist/dto/list-collaborator-payment.dto.d.ts +4 -0
  21. package/dist/dto/list-collaborator-payment.dto.d.ts.map +1 -0
  22. package/dist/dto/list-collaborator-payment.dto.js +8 -0
  23. package/dist/dto/list-collaborator-payment.dto.js.map +1 -0
  24. package/dist/dto/update-collaborator-invoice.dto.d.ts +6 -0
  25. package/dist/dto/update-collaborator-invoice.dto.d.ts.map +1 -0
  26. package/dist/dto/update-collaborator-invoice.dto.js +9 -0
  27. package/dist/dto/update-collaborator-invoice.dto.js.map +1 -0
  28. package/dist/dto/update-collaborator-payment.dto.d.ts +6 -0
  29. package/dist/dto/update-collaborator-payment.dto.d.ts.map +1 -0
  30. package/dist/dto/update-collaborator-payment.dto.js +9 -0
  31. package/dist/dto/update-collaborator-payment.dto.js.map +1 -0
  32. package/dist/operations.service.d.ts +98 -0
  33. package/dist/operations.service.d.ts.map +1 -1
  34. package/dist/operations.service.js +240 -17
  35. package/dist/operations.service.js.map +1 -1
  36. package/hedhog/data/menu.yaml +32 -11
  37. package/hedhog/data/route.yaml +72 -0
  38. package/hedhog/frontend/app/_components/collaborator-form-screen.tsx.ejs +38 -0
  39. package/hedhog/frontend/app/_components/collaborator-invoices-tab.tsx.ejs +443 -0
  40. package/hedhog/frontend/app/_components/collaborator-payment-history-tab.tsx.ejs +429 -0
  41. package/hedhog/frontend/app/_components/project-assignments-tab.tsx.ejs +212 -10
  42. package/hedhog/frontend/app/_components/project-details-screen.tsx.ejs +673 -16
  43. package/hedhog/frontend/app/_components/project-form-screen.tsx.ejs +192 -38
  44. package/hedhog/frontend/app/_components/task-detail-sheet.tsx.ejs +28 -7
  45. package/hedhog/frontend/app/_lib/api.ts.ejs +151 -0
  46. package/hedhog/frontend/app/_lib/types.ts.ejs +1 -0
  47. package/hedhog/frontend/app/_lib/utils/task-ui.ts.ejs +18 -0
  48. package/hedhog/frontend/app/tasks-gantt/page.tsx.ejs +953 -0
  49. package/hedhog/frontend/messages/en.json +96 -2
  50. package/hedhog/frontend/messages/pt.json +96 -2
  51. package/hedhog/table/operations_collaborator_invoice.yaml +35 -0
  52. package/hedhog/table/operations_collaborator_payment.yaml +32 -0
  53. package/package.json +5 -5
  54. package/src/controllers/operations-collaborators.controller.ts +109 -0
  55. package/src/dto/create-collaborator-invoice.dto.ts +39 -0
  56. package/src/dto/create-collaborator-payment.dto.ts +35 -0
  57. package/src/dto/list-collaborator-invoice.dto.ts +3 -0
  58. package/src/dto/list-collaborator-payment.dto.ts +3 -0
  59. package/src/dto/update-collaborator-invoice.dto.ts +6 -0
  60. package/src/dto/update-collaborator-payment.dto.ts +6 -0
  61. package/src/operations.service.ts +332 -18
@@ -1462,6 +1462,172 @@ let OperationsService = OperationsService_1 = class OperationsService {
1462
1462
  WHERE h.collaborator_id = $1
1463
1463
  ORDER BY h.created_at DESC`, [collaboratorId]);
1464
1464
  }
1465
+ async getCollaboratorPaymentHistory(userId, collaboratorId) {
1466
+ const actor = await this.getActorContext(userId);
1467
+ this.ensureDirector(actor);
1468
+ await this.getCollaboratorById(collaboratorId);
1469
+ const rows = await this.prisma.operations_collaborator_payment.findMany({
1470
+ where: { collaborator_id: collaboratorId },
1471
+ orderBy: { payment_date: 'desc' },
1472
+ });
1473
+ return rows.map((r) => ({
1474
+ id: r.id,
1475
+ collaboratorId: r.collaborator_id,
1476
+ amount: r.amount.toString(),
1477
+ paymentDate: r.payment_date,
1478
+ referenceMonth: r.reference_month,
1479
+ paymentMethod: r.payment_method,
1480
+ notes: r.notes,
1481
+ createdAt: r.created_at,
1482
+ }));
1483
+ }
1484
+ async getCollaboratorInvoices(userId, collaboratorId) {
1485
+ const actor = await this.getActorContext(userId);
1486
+ this.ensureDirector(actor);
1487
+ await this.getCollaboratorById(collaboratorId);
1488
+ const rows = await this.prisma.operations_collaborator_invoice.findMany({
1489
+ where: { collaborator_id: collaboratorId },
1490
+ orderBy: { issue_date: 'desc' },
1491
+ });
1492
+ return rows.map((r) => ({
1493
+ id: r.id,
1494
+ collaboratorId: r.collaborator_id,
1495
+ invoiceNumber: r.invoice_number,
1496
+ amount: r.amount.toString(),
1497
+ issueDate: r.issue_date,
1498
+ dueDate: r.due_date,
1499
+ status: r.status,
1500
+ description: r.description,
1501
+ createdAt: r.created_at,
1502
+ }));
1503
+ }
1504
+ async createCollaboratorPayment(userId, collaboratorId, data) {
1505
+ var _a, _b, _c;
1506
+ const actor = await this.getActorContext(userId);
1507
+ this.ensureDirector(actor);
1508
+ await this.getCollaboratorById(collaboratorId);
1509
+ const created = await this.prisma.operations_collaborator_payment.create({
1510
+ data: {
1511
+ collaborator_id: collaboratorId,
1512
+ amount: data.amount,
1513
+ payment_date: new Date(data.paymentDate),
1514
+ reference_month: (_a = data.referenceMonth) !== null && _a !== void 0 ? _a : null,
1515
+ payment_method: ((_b = data.paymentMethod) !== null && _b !== void 0 ? _b : 'pix'),
1516
+ notes: (_c = data.notes) !== null && _c !== void 0 ? _c : null,
1517
+ },
1518
+ });
1519
+ return {
1520
+ id: created.id,
1521
+ collaboratorId: created.collaborator_id,
1522
+ amount: created.amount.toString(),
1523
+ paymentDate: created.payment_date,
1524
+ referenceMonth: created.reference_month,
1525
+ paymentMethod: created.payment_method,
1526
+ notes: created.notes,
1527
+ createdAt: created.created_at,
1528
+ };
1529
+ }
1530
+ async updateCollaboratorPayment(userId, collaboratorId, paymentId, data) {
1531
+ const actor = await this.getActorContext(userId);
1532
+ this.ensureDirector(actor);
1533
+ const payment = await this.prisma.operations_collaborator_payment.findFirst({
1534
+ where: { id: paymentId, collaborator_id: collaboratorId },
1535
+ });
1536
+ if (!payment)
1537
+ throw new common_1.NotFoundException('Payment record not found.');
1538
+ const updated = await this.prisma.operations_collaborator_payment.update({
1539
+ where: { id: paymentId },
1540
+ data: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (data.amount !== undefined && { amount: data.amount })), (data.paymentDate !== undefined && { payment_date: new Date(data.paymentDate) })), ('referenceMonth' in data && { reference_month: data.referenceMonth })), (data.paymentMethod !== undefined && { payment_method: data.paymentMethod })), ('notes' in data && { notes: data.notes })),
1541
+ });
1542
+ return {
1543
+ id: updated.id,
1544
+ collaboratorId: updated.collaborator_id,
1545
+ amount: updated.amount.toString(),
1546
+ paymentDate: updated.payment_date,
1547
+ referenceMonth: updated.reference_month,
1548
+ paymentMethod: updated.payment_method,
1549
+ notes: updated.notes,
1550
+ createdAt: updated.created_at,
1551
+ };
1552
+ }
1553
+ async deleteCollaboratorPayment(userId, collaboratorId, paymentId) {
1554
+ const actor = await this.getActorContext(userId);
1555
+ this.ensureDirector(actor);
1556
+ const payment = await this.prisma.operations_collaborator_payment.findFirst({
1557
+ where: { id: paymentId, collaborator_id: collaboratorId },
1558
+ });
1559
+ if (!payment)
1560
+ throw new common_1.NotFoundException('Payment record not found.');
1561
+ await this.prisma.operations_collaborator_payment.delete({
1562
+ where: { id: paymentId },
1563
+ });
1564
+ return { success: true };
1565
+ }
1566
+ async createCollaboratorInvoice(userId, collaboratorId, data) {
1567
+ var _a, _b, _c;
1568
+ const actor = await this.getActorContext(userId);
1569
+ this.ensureDirector(actor);
1570
+ await this.getCollaboratorById(collaboratorId);
1571
+ const created = await this.prisma.operations_collaborator_invoice.create({
1572
+ data: {
1573
+ collaborator_id: collaboratorId,
1574
+ invoice_number: (_a = data.invoiceNumber) !== null && _a !== void 0 ? _a : null,
1575
+ amount: data.amount,
1576
+ issue_date: new Date(data.issueDate),
1577
+ due_date: data.dueDate ? new Date(data.dueDate) : null,
1578
+ status: ((_b = data.status) !== null && _b !== void 0 ? _b : 'pending'),
1579
+ description: (_c = data.description) !== null && _c !== void 0 ? _c : null,
1580
+ },
1581
+ });
1582
+ return {
1583
+ id: created.id,
1584
+ collaboratorId: created.collaborator_id,
1585
+ invoiceNumber: created.invoice_number,
1586
+ amount: created.amount.toString(),
1587
+ issueDate: created.issue_date,
1588
+ dueDate: created.due_date,
1589
+ status: created.status,
1590
+ description: created.description,
1591
+ createdAt: created.created_at,
1592
+ };
1593
+ }
1594
+ async updateCollaboratorInvoice(userId, collaboratorId, invoiceId, data) {
1595
+ const actor = await this.getActorContext(userId);
1596
+ this.ensureDirector(actor);
1597
+ const invoice = await this.prisma.operations_collaborator_invoice.findFirst({
1598
+ where: { id: invoiceId, collaborator_id: collaboratorId },
1599
+ });
1600
+ if (!invoice)
1601
+ throw new common_1.NotFoundException('Invoice not found.');
1602
+ const updated = await this.prisma.operations_collaborator_invoice.update({
1603
+ where: { id: invoiceId },
1604
+ data: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, ('invoiceNumber' in data && { invoice_number: data.invoiceNumber })), (data.amount !== undefined && { amount: data.amount })), (data.issueDate !== undefined && { issue_date: new Date(data.issueDate) })), ('dueDate' in data && { due_date: data.dueDate ? new Date(data.dueDate) : null })), (data.status !== undefined && { status: data.status })), ('description' in data && { description: data.description })),
1605
+ });
1606
+ return {
1607
+ id: updated.id,
1608
+ collaboratorId: updated.collaborator_id,
1609
+ invoiceNumber: updated.invoice_number,
1610
+ amount: updated.amount.toString(),
1611
+ issueDate: updated.issue_date,
1612
+ dueDate: updated.due_date,
1613
+ status: updated.status,
1614
+ description: updated.description,
1615
+ createdAt: updated.created_at,
1616
+ };
1617
+ }
1618
+ async deleteCollaboratorInvoice(userId, collaboratorId, invoiceId) {
1619
+ const actor = await this.getActorContext(userId);
1620
+ this.ensureDirector(actor);
1621
+ const invoice = await this.prisma.operations_collaborator_invoice.findFirst({
1622
+ where: { id: invoiceId, collaborator_id: collaboratorId },
1623
+ });
1624
+ if (!invoice)
1625
+ throw new common_1.NotFoundException('Invoice not found.');
1626
+ await this.prisma.operations_collaborator_invoice.delete({
1627
+ where: { id: invoiceId },
1628
+ });
1629
+ return { success: true };
1630
+ }
1465
1631
  async listDepartments(userId, filters = {}) {
1466
1632
  var _a, _b;
1467
1633
  const actor = await this.getActorContext(userId);
@@ -1746,6 +1912,17 @@ let OperationsService = OperationsService_1 = class OperationsService {
1746
1912
  AND LOWER(TRIM(p2.name)) = LOWER(TRIM(p.client_name))
1747
1913
  LIMIT 1)
1748
1914
  ) AS "clientAvatarId",
1915
+ COALESCE(
1916
+ client_user.photo_id,
1917
+ (SELECT u2.photo_id
1918
+ FROM person p2
1919
+ JOIN person_user pu2 ON pu2.person_id = p2.id
1920
+ JOIN "user" u2 ON u2.id = pu2.user_id
1921
+ WHERE p.client_person_id IS NULL
1922
+ AND LOWER(TRIM(p2.name)) = LOWER(TRIM(p.client_name))
1923
+ ORDER BY pu2.id ASC
1924
+ LIMIT 1)
1925
+ ) AS "clientUserPhotoId",
1749
1926
  p.summary,
1750
1927
  p.status,
1751
1928
  p.progress_percent AS "progressPercent",
@@ -1761,15 +1938,23 @@ let OperationsService = OperationsService_1 = class OperationsService {
1761
1938
  COUNT(DISTINCT pa.id)::int AS "teamSize"
1762
1939
  FROM operations_project p
1763
1940
  LEFT JOIN operations_contract c ON c.id = p.contract_id
1764
- LEFT JOIN operations_collaborator m ON m.id = p.manager_collaborator_id
1765
- LEFT JOIN person cp ON cp.id = p.client_person_id
1766
- LEFT JOIN person mp ON mp.id = m.person_id
1767
- LEFT JOIN operations_project_assignment pa
1768
- ON pa.project_id = p.id
1769
- AND pa.deleted_at IS NULL
1770
- AND pa.status IN ('planned', 'active')
1941
+ LEFT JOIN operations_collaborator m ON m.id = p.manager_collaborator_id
1942
+ LEFT JOIN person cp ON cp.id = p.client_person_id
1943
+ LEFT JOIN person mp ON mp.id = m.person_id
1944
+ LEFT JOIN LATERAL (
1945
+ SELECT u.photo_id
1946
+ FROM person_user pu
1947
+ JOIN "user" u ON u.id = pu.user_id
1948
+ WHERE pu.person_id = p.client_person_id
1949
+ ORDER BY pu.id ASC
1950
+ LIMIT 1
1951
+ ) client_user ON TRUE
1952
+ LEFT JOIN operations_project_assignment pa
1953
+ ON pa.project_id = p.id
1954
+ AND pa.deleted_at IS NULL
1955
+ AND pa.status IN ('planned', 'active')
1771
1956
  WHERE ${whereClause}
1772
- GROUP BY p.id, c.id, m.id, cp.id, mp.id`;
1957
+ GROUP BY p.id, c.id, m.id, cp.id, mp.id, client_user.photo_id`;
1773
1958
  if (!pagination) {
1774
1959
  return this.queryRows(`${baseQuery} ORDER BY p.name ASC`, params);
1775
1960
  }
@@ -5195,6 +5380,17 @@ let OperationsService = OperationsService_1 = class OperationsService {
5195
5380
  AND LOWER(TRIM(p2.name)) = LOWER(TRIM(p.client_name))
5196
5381
  LIMIT 1)
5197
5382
  ) AS "clientAvatarId",
5383
+ COALESCE(
5384
+ client_user.photo_id,
5385
+ (SELECT u2.photo_id
5386
+ FROM person p2
5387
+ JOIN person_user pu2 ON pu2.person_id = p2.id
5388
+ JOIN "user" u2 ON u2.id = pu2.user_id
5389
+ WHERE p.client_person_id IS NULL
5390
+ AND LOWER(TRIM(p2.name)) = LOWER(TRIM(p.client_name))
5391
+ ORDER BY pu2.id ASC
5392
+ LIMIT 1)
5393
+ ) AS "clientUserPhotoId",
5198
5394
  p.code,
5199
5395
  p.name,
5200
5396
  p.client_name AS "clientName",
@@ -5212,13 +5408,21 @@ let OperationsService = OperationsService_1 = class OperationsService {
5212
5408
  MAX(CASE WHEN pa.collaborator_id = $2 THEN pa.id END)::int AS "myAssignmentId",
5213
5409
  MAX(CASE WHEN pa.collaborator_id = $2 THEN COALESCE(project_role_locale.name, pa.role_label) END) AS "myRoleLabel",
5214
5410
  COUNT(DISTINCT pa.id)::int AS "teamSize"
5215
- FROM operations_project p
5216
- LEFT JOIN operations_contract c ON c.id = p.contract_id
5217
- LEFT JOIN operations_collaborator m ON m.id = p.manager_collaborator_id
5218
- LEFT JOIN person client_person ON client_person.id = p.client_person_id
5219
- LEFT JOIN operations_project_assignment pa
5220
- ON pa.project_id = p.id
5221
- AND pa.deleted_at IS NULL
5411
+ FROM operations_project p
5412
+ LEFT JOIN operations_contract c ON c.id = p.contract_id
5413
+ LEFT JOIN operations_collaborator m ON m.id = p.manager_collaborator_id
5414
+ LEFT JOIN person client_person ON client_person.id = p.client_person_id
5415
+ LEFT JOIN LATERAL (
5416
+ SELECT u.photo_id
5417
+ FROM person_user pu
5418
+ JOIN "user" u ON u.id = pu.user_id
5419
+ WHERE pu.person_id = p.client_person_id
5420
+ ORDER BY pu.id ASC
5421
+ LIMIT 1
5422
+ ) client_user ON TRUE
5423
+ LEFT JOIN operations_project_assignment pa
5424
+ ON pa.project_id = p.id
5425
+ AND pa.deleted_at IS NULL
5222
5426
  LEFT JOIN operations_project_role project_role
5223
5427
  ON project_role.id = pa.project_role_id
5224
5428
  AND project_role.deleted_at IS NULL
@@ -5231,7 +5435,7 @@ let OperationsService = OperationsService_1 = class OperationsService {
5231
5435
  ) project_role_locale ON TRUE
5232
5436
  WHERE p.id = $1
5233
5437
  AND p.deleted_at IS NULL
5234
- GROUP BY p.id, c.id, m.id, client_person.id`, [projectId, actorCollaboratorId !== null && actorCollaboratorId !== void 0 ? actorCollaboratorId : null]);
5438
+ GROUP BY p.id, c.id, m.id, client_person.id, client_user.photo_id`, [projectId, actorCollaboratorId !== null && actorCollaboratorId !== void 0 ? actorCollaboratorId : null]);
5235
5439
  if (!project) {
5236
5440
  throw new common_1.NotFoundException("Project not found.");
5237
5441
  }
@@ -7783,6 +7987,17 @@ let OperationsService = OperationsService_1 = class OperationsService {
7783
7987
  AND LOWER(TRIM(p2.name)) = LOWER(TRIM(p.client_name))
7784
7988
  LIMIT 1)
7785
7989
  ) AS "clientAvatarId",
7990
+ COALESCE(
7991
+ client_user.photo_id,
7992
+ (SELECT u2.photo_id
7993
+ FROM person p2
7994
+ JOIN person_user pu2 ON pu2.person_id = p2.id
7995
+ JOIN "user" u2 ON u2.id = pu2.user_id
7996
+ WHERE p.client_person_id IS NULL
7997
+ AND LOWER(TRIM(p2.name)) = LOWER(TRIM(p.client_name))
7998
+ ORDER BY pu2.id ASC
7999
+ LIMIT 1)
8000
+ ) AS "clientUserPhotoId",
7786
8001
  p.summary,
7787
8002
  p.status,
7788
8003
  p.progress_percent AS "progressPercent",
@@ -7796,12 +8011,20 @@ let OperationsService = OperationsService_1 = class OperationsService {
7796
8011
  LEFT JOIN operations_contract c ON c.id = p.contract_id
7797
8012
  LEFT JOIN operations_collaborator m ON m.id = p.manager_collaborator_id
7798
8013
  LEFT JOIN person cp ON cp.id = p.client_person_id
8014
+ LEFT JOIN LATERAL (
8015
+ SELECT u.photo_id
8016
+ FROM person_user pu
8017
+ JOIN "user" u ON u.id = pu.user_id
8018
+ WHERE pu.person_id = p.client_person_id
8019
+ ORDER BY pu.id ASC
8020
+ LIMIT 1
8021
+ ) client_user ON TRUE
7799
8022
  LEFT JOIN operations_project_assignment pa
7800
8023
  ON pa.project_id = p.id
7801
8024
  AND pa.deleted_at IS NULL
7802
8025
  AND pa.status IN ('planned', 'active')
7803
8026
  WHERE ${whereClause}
7804
- GROUP BY p.id, c.id, m.id, cp.id`;
8027
+ GROUP BY p.id, c.id, m.id, cp.id, client_user.photo_id`;
7805
8028
  if (!pagination) {
7806
8029
  return this.queryRows(`${baseQuery} ORDER BY p.name ASC`, params);
7807
8030
  }