@open-mercato/core 0.6.4-develop.4217.1.c9aa050183 → 0.6.4-develop.4236.1.9fa6806b34

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 (370) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/dist/generated/entities/staff_time_entry/index.js +37 -0
  3. package/dist/generated/entities/staff_time_entry/index.js.map +7 -0
  4. package/dist/generated/entities/staff_time_entry_segment/index.js +23 -0
  5. package/dist/generated/entities/staff_time_entry_segment/index.js.map +7 -0
  6. package/dist/generated/entities/staff_time_project/index.js +35 -0
  7. package/dist/generated/entities/staff_time_project/index.js.map +7 -0
  8. package/dist/generated/entities/staff_time_project_member/index.js +29 -0
  9. package/dist/generated/entities/staff_time_project_member/index.js.map +7 -0
  10. package/dist/generated/entities.ids.generated.js +5 -1
  11. package/dist/generated/entities.ids.generated.js.map +2 -2
  12. package/dist/generated/entity-fields-registry.js +64 -0
  13. package/dist/generated/entity-fields-registry.js.map +2 -2
  14. package/dist/helpers/integration/timesheetFixtures.js +50 -0
  15. package/dist/helpers/integration/timesheetFixtures.js.map +7 -0
  16. package/dist/modules/attachments/api/library/[id]/route.js +20 -16
  17. package/dist/modules/attachments/api/library/[id]/route.js.map +2 -2
  18. package/dist/modules/attachments/api/route.js +18 -14
  19. package/dist/modules/attachments/api/route.js.map +2 -2
  20. package/dist/modules/auth/api/roles/acl/route.js +10 -4
  21. package/dist/modules/auth/api/roles/acl/route.js.map +2 -2
  22. package/dist/modules/auth/api/sidebar/preferences/route.js +27 -20
  23. package/dist/modules/auth/api/sidebar/preferences/route.js.map +2 -2
  24. package/dist/modules/auth/api/users/acl/route.js +16 -11
  25. package/dist/modules/auth/api/users/acl/route.js.map +2 -2
  26. package/dist/modules/auth/commands/users.js +87 -71
  27. package/dist/modules/auth/commands/users.js.map +2 -2
  28. package/dist/modules/auth/services/sidebarPreferencesService.js +39 -30
  29. package/dist/modules/auth/services/sidebarPreferencesService.js.map +2 -2
  30. package/dist/modules/catalog/commands/categories.js +61 -12
  31. package/dist/modules/catalog/commands/categories.js.map +2 -2
  32. package/dist/modules/catalog/commands/products.js +79 -54
  33. package/dist/modules/catalog/commands/products.js.map +2 -2
  34. package/dist/modules/catalog/commands/variants.js +29 -16
  35. package/dist/modules/catalog/commands/variants.js.map +2 -2
  36. package/dist/modules/currencies/commands/currencies.js +15 -8
  37. package/dist/modules/currencies/commands/currencies.js.map +2 -2
  38. package/dist/modules/customer_accounts/api/admin/users.js +27 -26
  39. package/dist/modules/customer_accounts/api/admin/users.js.map +2 -2
  40. package/dist/modules/customer_accounts/api/password/reset-confirm.js +5 -5
  41. package/dist/modules/customer_accounts/api/password/reset-confirm.js.map +2 -2
  42. package/dist/modules/customer_accounts/api/portal/users/[id]/roles.js +11 -10
  43. package/dist/modules/customer_accounts/api/portal/users/[id]/roles.js.map +2 -2
  44. package/dist/modules/customers/commands/addresses.js +35 -21
  45. package/dist/modules/customers/commands/addresses.js.map +2 -2
  46. package/dist/modules/customers/commands/companies.js +163 -162
  47. package/dist/modules/customers/commands/companies.js.map +2 -2
  48. package/dist/modules/customers/commands/deals.js +3 -4
  49. package/dist/modules/customers/commands/deals.js.map +2 -2
  50. package/dist/modules/customers/commands/interactions.js +19 -22
  51. package/dist/modules/customers/commands/interactions.js.map +2 -2
  52. package/dist/modules/customers/commands/people.js +18 -15
  53. package/dist/modules/customers/commands/people.js.map +2 -2
  54. package/dist/modules/customers/commands/personCompanyLinks.js +105 -94
  55. package/dist/modules/customers/commands/personCompanyLinks.js.map +2 -2
  56. package/dist/modules/customers/commands/pipeline-stages.js +30 -23
  57. package/dist/modules/customers/commands/pipeline-stages.js.map +2 -2
  58. package/dist/modules/customers/commands/pipelines.js +27 -20
  59. package/dist/modules/customers/commands/pipelines.js.map +2 -2
  60. package/dist/modules/customers/commands/tags.js +13 -5
  61. package/dist/modules/customers/commands/tags.js.map +2 -2
  62. package/dist/modules/dashboards/api/users/widgets/route.js +0 -1
  63. package/dist/modules/dashboards/api/users/widgets/route.js.map +2 -2
  64. package/dist/modules/dashboards/api/widgets/data/route.js +29 -1
  65. package/dist/modules/dashboards/api/widgets/data/route.js.map +2 -2
  66. package/dist/modules/data_sync/lib/sync-engine.js +4 -4
  67. package/dist/modules/data_sync/lib/sync-engine.js.map +2 -2
  68. package/dist/modules/data_sync/lib/sync-run-service.js +51 -27
  69. package/dist/modules/data_sync/lib/sync-run-service.js.map +2 -2
  70. package/dist/modules/directory/commands/organizations.js +192 -158
  71. package/dist/modules/directory/commands/organizations.js.map +3 -3
  72. package/dist/modules/inbox_ops/api/emails/[id]/reprocess/route.js +22 -16
  73. package/dist/modules/inbox_ops/api/emails/[id]/reprocess/route.js.map +2 -2
  74. package/dist/modules/messages/commands/messages.js +77 -75
  75. package/dist/modules/messages/commands/messages.js.map +2 -2
  76. package/dist/modules/messages/commands/shared.js +132 -132
  77. package/dist/modules/messages/commands/shared.js.map +2 -2
  78. package/dist/modules/perspectives/api/[tableId]/route.js +37 -26
  79. package/dist/modules/perspectives/api/[tableId]/route.js.map +2 -2
  80. package/dist/modules/resources/commands/resources.js +125 -117
  81. package/dist/modules/resources/commands/resources.js.map +2 -2
  82. package/dist/modules/resources/commands/tags.js +7 -3
  83. package/dist/modules/resources/commands/tags.js.map +2 -2
  84. package/dist/modules/sales/api/quotes/send/route.js +12 -11
  85. package/dist/modules/sales/api/quotes/send/route.js.map +2 -2
  86. package/dist/modules/sales/commands/documents.js +629 -478
  87. package/dist/modules/sales/commands/documents.js.map +2 -2
  88. package/dist/modules/sales/commands/payments.js +146 -146
  89. package/dist/modules/sales/commands/payments.js.map +2 -2
  90. package/dist/modules/sales/commands/returns.js +68 -60
  91. package/dist/modules/sales/commands/returns.js.map +2 -2
  92. package/dist/modules/staff/acl.js +10 -1
  93. package/dist/modules/staff/acl.js.map +2 -2
  94. package/dist/modules/staff/analytics.js +33 -0
  95. package/dist/modules/staff/analytics.js.map +7 -0
  96. package/dist/modules/staff/api/guards.js +31 -0
  97. package/dist/modules/staff/api/guards.js.map +7 -0
  98. package/dist/modules/staff/api/interceptors.js +96 -0
  99. package/dist/modules/staff/api/interceptors.js.map +7 -0
  100. package/dist/modules/staff/api/timesheets/my-projects/[projectId]/route.js +170 -0
  101. package/dist/modules/staff/api/timesheets/my-projects/[projectId]/route.js.map +7 -0
  102. package/dist/modules/staff/api/timesheets/my-projects/route.js +103 -0
  103. package/dist/modules/staff/api/timesheets/my-projects/route.js.map +7 -0
  104. package/dist/modules/staff/api/timesheets/projects/kpis/route.js +147 -0
  105. package/dist/modules/staff/api/timesheets/projects/kpis/route.js.map +7 -0
  106. package/dist/modules/staff/api/timesheets/time-entries/[id]/segments/[segmentId]/route.js +171 -0
  107. package/dist/modules/staff/api/timesheets/time-entries/[id]/segments/[segmentId]/route.js.map +7 -0
  108. package/dist/modules/staff/api/timesheets/time-entries/[id]/segments/route.js +180 -0
  109. package/dist/modules/staff/api/timesheets/time-entries/[id]/segments/route.js.map +7 -0
  110. package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-start/route.js +155 -0
  111. package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-start/route.js.map +7 -0
  112. package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-stop/route.js +173 -0
  113. package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-stop/route.js.map +7 -0
  114. package/dist/modules/staff/api/timesheets/time-entries/bulk/route.js +260 -0
  115. package/dist/modules/staff/api/timesheets/time-entries/bulk/route.js.map +7 -0
  116. package/dist/modules/staff/api/timesheets/time-entries/route.js +188 -0
  117. package/dist/modules/staff/api/timesheets/time-entries/route.js.map +7 -0
  118. package/dist/modules/staff/api/timesheets/time-projects/[id]/employees/route.js +159 -0
  119. package/dist/modules/staff/api/timesheets/time-projects/[id]/employees/route.js.map +7 -0
  120. package/dist/modules/staff/api/timesheets/time-projects/route.js +230 -0
  121. package/dist/modules/staff/api/timesheets/time-projects/route.js.map +7 -0
  122. package/dist/modules/staff/backend/staff/timesheets/page.js +710 -0
  123. package/dist/modules/staff/backend/staff/timesheets/page.js.map +7 -0
  124. package/dist/modules/staff/backend/staff/timesheets/page.meta.js +22 -0
  125. package/dist/modules/staff/backend/staff/timesheets/page.meta.js.map +7 -0
  126. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.js +125 -0
  127. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.js.map +7 -0
  128. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.meta.js +16 -0
  129. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.meta.js.map +7 -0
  130. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/page.js +418 -0
  131. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/page.js.map +7 -0
  132. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/page.meta.js +16 -0
  133. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/page.meta.js.map +7 -0
  134. package/dist/modules/staff/backend/staff/timesheets/projects/create/page.js +79 -0
  135. package/dist/modules/staff/backend/staff/timesheets/projects/create/page.js.map +7 -0
  136. package/dist/modules/staff/backend/staff/timesheets/projects/create/page.meta.js +16 -0
  137. package/dist/modules/staff/backend/staff/timesheets/projects/create/page.meta.js.map +7 -0
  138. package/dist/modules/staff/backend/staff/timesheets/projects/page.js +602 -0
  139. package/dist/modules/staff/backend/staff/timesheets/projects/page.js.map +7 -0
  140. package/dist/modules/staff/backend/staff/timesheets/projects/page.meta.js +25 -0
  141. package/dist/modules/staff/backend/staff/timesheets/projects/page.meta.js.map +7 -0
  142. package/dist/modules/staff/backend/staff/timesheets/projects/projectFormConfig.js +123 -0
  143. package/dist/modules/staff/backend/staff/timesheets/projects/projectFormConfig.js.map +7 -0
  144. package/dist/modules/staff/cli.js +38 -1
  145. package/dist/modules/staff/cli.js.map +2 -2
  146. package/dist/modules/staff/commands/index.js +2 -0
  147. package/dist/modules/staff/commands/index.js.map +2 -2
  148. package/dist/modules/staff/commands/leave-requests.js +30 -28
  149. package/dist/modules/staff/commands/leave-requests.js.map +3 -3
  150. package/dist/modules/staff/commands/team-members.js +21 -20
  151. package/dist/modules/staff/commands/team-members.js.map +2 -2
  152. package/dist/modules/staff/commands/timesheets-entries.js +409 -0
  153. package/dist/modules/staff/commands/timesheets-entries.js.map +7 -0
  154. package/dist/modules/staff/commands/timesheets-projects.js +618 -0
  155. package/dist/modules/staff/commands/timesheets-projects.js.map +7 -0
  156. package/dist/modules/staff/data/enrichers.js +104 -0
  157. package/dist/modules/staff/data/enrichers.js.map +7 -0
  158. package/dist/modules/staff/data/entities.js +226 -1
  159. package/dist/modules/staff/data/entities.js.map +2 -2
  160. package/dist/modules/staff/data/validators.js +113 -1
  161. package/dist/modules/staff/data/validators.js.map +2 -2
  162. package/dist/modules/staff/events.js +13 -1
  163. package/dist/modules/staff/events.js.map +2 -2
  164. package/dist/modules/staff/lib/crud.js +7 -1
  165. package/dist/modules/staff/lib/crud.js.map +2 -2
  166. package/dist/modules/staff/lib/staffMemberResolver.js +15 -0
  167. package/dist/modules/staff/lib/staffMemberResolver.js.map +7 -0
  168. package/dist/modules/staff/lib/timesheets-projects/computeProjectHoursTrend.js +60 -0
  169. package/dist/modules/staff/lib/timesheets-projects/computeProjectHoursTrend.js.map +7 -0
  170. package/dist/modules/staff/lib/timesheets-projects/computeProjectsKpis.js +260 -0
  171. package/dist/modules/staff/lib/timesheets-projects/computeProjectsKpis.js.map +7 -0
  172. package/dist/modules/staff/lib/timesheets-projects/dateBuckets.js +41 -0
  173. package/dist/modules/staff/lib/timesheets-projects/dateBuckets.js.map +7 -0
  174. package/dist/modules/staff/lib/timesheets-projects/initials.js +10 -0
  175. package/dist/modules/staff/lib/timesheets-projects/initials.js.map +7 -0
  176. package/dist/modules/staff/lib/timesheets-projects/kpiMath.js +12 -0
  177. package/dist/modules/staff/lib/timesheets-projects/kpiMath.js.map +7 -0
  178. package/dist/modules/staff/lib/timesheets-projects/listProjectMembersPreview.js +55 -0
  179. package/dist/modules/staff/lib/timesheets-projects/listProjectMembersPreview.js.map +7 -0
  180. package/dist/modules/staff/lib/timesheets-projects-ui/HoursSparkline.js +66 -0
  181. package/dist/modules/staff/lib/timesheets-projects-ui/HoursSparkline.js.map +7 -0
  182. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectCard.js +81 -0
  183. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectCard.js.map +7 -0
  184. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectMembersAvatarStack.js +58 -0
  185. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectMembersAvatarStack.js.map +7 -0
  186. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectsKpiStrip.js +152 -0
  187. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectsKpiStrip.js.map +7 -0
  188. package/dist/modules/staff/lib/timesheets-projects-ui/SavedViewTabs.js +37 -0
  189. package/dist/modules/staff/lib/timesheets-projects-ui/SavedViewTabs.js.map +7 -0
  190. package/dist/modules/staff/lib/timesheets-projects-ui/ViewModeToggle.js +57 -0
  191. package/dist/modules/staff/lib/timesheets-projects-ui/ViewModeToggle.js.map +7 -0
  192. package/dist/modules/staff/lib/timesheets-projects-ui/useProjectsViewMode.js +50 -0
  193. package/dist/modules/staff/lib/timesheets-projects-ui/useProjectsViewMode.js.map +7 -0
  194. package/dist/modules/staff/lib/timesheets-ui/AddRowDropdown.js +163 -0
  195. package/dist/modules/staff/lib/timesheets-ui/AddRowDropdown.js.map +7 -0
  196. package/dist/modules/staff/lib/timesheets-ui/CalendarPicker.js +209 -0
  197. package/dist/modules/staff/lib/timesheets-ui/CalendarPicker.js.map +7 -0
  198. package/dist/modules/staff/lib/timesheets-ui/ColorPicker.js +52 -0
  199. package/dist/modules/staff/lib/timesheets-ui/ColorPicker.js.map +7 -0
  200. package/dist/modules/staff/lib/timesheets-ui/CreateProjectDialog.js +77 -0
  201. package/dist/modules/staff/lib/timesheets-ui/CreateProjectDialog.js.map +7 -0
  202. package/dist/modules/staff/lib/timesheets-ui/ListView.js +173 -0
  203. package/dist/modules/staff/lib/timesheets-ui/ListView.js.map +7 -0
  204. package/dist/modules/staff/lib/timesheets-ui/ProjectColorDot.js +32 -0
  205. package/dist/modules/staff/lib/timesheets-ui/ProjectColorDot.js.map +7 -0
  206. package/dist/modules/staff/lib/timesheets-ui/TimerBar.js +270 -0
  207. package/dist/modules/staff/lib/timesheets-ui/TimerBar.js.map +7 -0
  208. package/dist/modules/staff/lib/timesheets-ui/ViewSwitcher.js +57 -0
  209. package/dist/modules/staff/lib/timesheets-ui/ViewSwitcher.js.map +7 -0
  210. package/dist/modules/staff/lib/timesheets-ui/colors.js +43 -0
  211. package/dist/modules/staff/lib/timesheets-ui/colors.js.map +7 -0
  212. package/dist/modules/staff/migrations/Migration20260326135612.js +24 -0
  213. package/dist/modules/staff/migrations/Migration20260326135612.js.map +7 -0
  214. package/dist/modules/staff/migrations/Migration20260413102715.js +23 -0
  215. package/dist/modules/staff/migrations/Migration20260413102715.js.map +7 -0
  216. package/dist/modules/staff/migrations/Migration20260413111602.js +13 -0
  217. package/dist/modules/staff/migrations/Migration20260413111602.js.map +7 -0
  218. package/dist/modules/staff/migrations/Migration20260511112759.js +19 -0
  219. package/dist/modules/staff/migrations/Migration20260511112759.js.map +7 -0
  220. package/dist/modules/staff/search.js +35 -0
  221. package/dist/modules/staff/search.js.map +2 -2
  222. package/dist/modules/staff/setup.js +15 -1
  223. package/dist/modules/staff/setup.js.map +2 -2
  224. package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/config.js +16 -0
  225. package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/config.js.map +7 -0
  226. package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.client.js +126 -0
  227. package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.client.js.map +7 -0
  228. package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.js +26 -0
  229. package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.js.map +7 -0
  230. package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/config.js +15 -0
  231. package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/config.js.map +7 -0
  232. package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.client.js +238 -0
  233. package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.client.js.map +7 -0
  234. package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.js +26 -0
  235. package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.js.map +7 -0
  236. package/dist/modules/staff/widgets/injection/timer-sidebar-indicator/widget.js +145 -0
  237. package/dist/modules/staff/widgets/injection/timer-sidebar-indicator/widget.js.map +7 -0
  238. package/dist/modules/staff/widgets/injection-table.js +12 -0
  239. package/dist/modules/staff/widgets/injection-table.js.map +7 -0
  240. package/dist/modules/sync_excel/api/import/route.js +19 -17
  241. package/dist/modules/sync_excel/api/import/route.js.map +2 -2
  242. package/dist/modules/translations/commands/translations.js +22 -19
  243. package/dist/modules/translations/commands/translations.js.map +2 -2
  244. package/generated/entities/staff_time_entry/index.ts +17 -0
  245. package/generated/entities/staff_time_entry_segment/index.ts +10 -0
  246. package/generated/entities/staff_time_project/index.ts +16 -0
  247. package/generated/entities/staff_time_project_member/index.ts +13 -0
  248. package/generated/entities.ids.generated.ts +5 -1
  249. package/generated/entity-fields-registry.ts +64 -0
  250. package/package.json +7 -7
  251. package/src/helpers/integration/timesheetFixtures.ts +61 -0
  252. package/src/modules/attachments/api/library/[id]/route.ts +24 -17
  253. package/src/modules/attachments/api/route.ts +20 -14
  254. package/src/modules/auth/api/roles/acl/route.ts +11 -5
  255. package/src/modules/auth/api/sidebar/preferences/route.ts +33 -24
  256. package/src/modules/auth/api/users/acl/route.ts +17 -12
  257. package/src/modules/auth/commands/users.ts +96 -80
  258. package/src/modules/auth/services/sidebarPreferencesService.ts +40 -32
  259. package/src/modules/catalog/commands/categories.ts +61 -12
  260. package/src/modules/catalog/commands/products.ts +93 -60
  261. package/src/modules/catalog/commands/variants.ts +29 -16
  262. package/src/modules/currencies/commands/currencies.ts +27 -14
  263. package/src/modules/customer_accounts/api/admin/users.ts +31 -26
  264. package/src/modules/customer_accounts/api/password/reset-confirm.ts +5 -6
  265. package/src/modules/customer_accounts/api/portal/users/[id]/roles.ts +14 -13
  266. package/src/modules/customers/commands/addresses.ts +35 -23
  267. package/src/modules/customers/commands/companies.ts +166 -165
  268. package/src/modules/customers/commands/deals.ts +2 -4
  269. package/src/modules/customers/commands/interactions.ts +20 -26
  270. package/src/modules/customers/commands/people.ts +18 -15
  271. package/src/modules/customers/commands/personCompanyLinks.ts +109 -100
  272. package/src/modules/customers/commands/pipeline-stages.ts +31 -27
  273. package/src/modules/customers/commands/pipelines.ts +29 -23
  274. package/src/modules/customers/commands/tags.ts +13 -5
  275. package/src/modules/dashboards/api/users/widgets/route.ts +0 -1
  276. package/src/modules/dashboards/api/widgets/data/route.ts +36 -1
  277. package/src/modules/data_sync/lib/sync-engine.ts +4 -5
  278. package/src/modules/data_sync/lib/sync-run-service.ts +57 -28
  279. package/src/modules/directory/commands/organizations.ts +203 -166
  280. package/src/modules/inbox_ops/api/emails/[id]/reprocess/route.ts +26 -18
  281. package/src/modules/messages/commands/messages.ts +82 -80
  282. package/src/modules/messages/commands/shared.ts +138 -133
  283. package/src/modules/perspectives/api/[tableId]/route.ts +38 -27
  284. package/src/modules/resources/commands/resources.ts +127 -117
  285. package/src/modules/resources/commands/tags.ts +7 -3
  286. package/src/modules/sales/api/quotes/send/route.ts +17 -12
  287. package/src/modules/sales/commands/documents.ts +673 -481
  288. package/src/modules/sales/commands/payments.ts +158 -152
  289. package/src/modules/sales/commands/returns.ts +74 -63
  290. package/src/modules/staff/acl.ts +11 -0
  291. package/src/modules/staff/analytics.ts +30 -0
  292. package/src/modules/staff/api/guards.ts +59 -0
  293. package/src/modules/staff/api/interceptors.ts +122 -0
  294. package/src/modules/staff/api/timesheets/my-projects/[projectId]/route.ts +191 -0
  295. package/src/modules/staff/api/timesheets/my-projects/route.ts +115 -0
  296. package/src/modules/staff/api/timesheets/projects/kpis/route.ts +159 -0
  297. package/src/modules/staff/api/timesheets/time-entries/[id]/segments/[segmentId]/route.ts +187 -0
  298. package/src/modules/staff/api/timesheets/time-entries/[id]/segments/route.ts +191 -0
  299. package/src/modules/staff/api/timesheets/time-entries/[id]/timer-start/route.ts +168 -0
  300. package/src/modules/staff/api/timesheets/time-entries/[id]/timer-stop/route.ts +191 -0
  301. package/src/modules/staff/api/timesheets/time-entries/bulk/route.ts +292 -0
  302. package/src/modules/staff/api/timesheets/time-entries/route.ts +193 -0
  303. package/src/modules/staff/api/timesheets/time-projects/[id]/employees/route.ts +167 -0
  304. package/src/modules/staff/api/timesheets/time-projects/route.ts +244 -0
  305. package/src/modules/staff/backend/staff/timesheets/page.meta.ts +20 -0
  306. package/src/modules/staff/backend/staff/timesheets/page.tsx +899 -0
  307. package/src/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.meta.ts +12 -0
  308. package/src/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.tsx +141 -0
  309. package/src/modules/staff/backend/staff/timesheets/projects/[id]/page.meta.ts +12 -0
  310. package/src/modules/staff/backend/staff/timesheets/projects/[id]/page.tsx +579 -0
  311. package/src/modules/staff/backend/staff/timesheets/projects/create/page.meta.ts +12 -0
  312. package/src/modules/staff/backend/staff/timesheets/projects/create/page.tsx +90 -0
  313. package/src/modules/staff/backend/staff/timesheets/projects/page.meta.ts +23 -0
  314. package/src/modules/staff/backend/staff/timesheets/projects/page.tsx +765 -0
  315. package/src/modules/staff/backend/staff/timesheets/projects/projectFormConfig.ts +138 -0
  316. package/src/modules/staff/cli.ts +40 -1
  317. package/src/modules/staff/commands/index.ts +2 -0
  318. package/src/modules/staff/commands/leave-requests.ts +37 -29
  319. package/src/modules/staff/commands/team-members.ts +25 -20
  320. package/src/modules/staff/commands/timesheets-entries.ts +504 -0
  321. package/src/modules/staff/commands/timesheets-projects.ts +699 -0
  322. package/src/modules/staff/data/enrichers.ts +134 -0
  323. package/src/modules/staff/data/entities.ts +198 -0
  324. package/src/modules/staff/data/validators.ts +129 -0
  325. package/src/modules/staff/events.ts +13 -0
  326. package/src/modules/staff/i18n/de.json +209 -1
  327. package/src/modules/staff/i18n/en.json +209 -1
  328. package/src/modules/staff/i18n/es.json +209 -1
  329. package/src/modules/staff/i18n/pl.json +209 -1
  330. package/src/modules/staff/lib/crud.ts +8 -0
  331. package/src/modules/staff/lib/staffMemberResolver.ts +22 -0
  332. package/src/modules/staff/lib/timesheets-projects/computeProjectHoursTrend.ts +89 -0
  333. package/src/modules/staff/lib/timesheets-projects/computeProjectsKpis.ts +311 -0
  334. package/src/modules/staff/lib/timesheets-projects/dateBuckets.ts +37 -0
  335. package/src/modules/staff/lib/timesheets-projects/initials.ts +6 -0
  336. package/src/modules/staff/lib/timesheets-projects/kpiMath.ts +8 -0
  337. package/src/modules/staff/lib/timesheets-projects/listProjectMembersPreview.ts +83 -0
  338. package/src/modules/staff/lib/timesheets-projects-ui/HoursSparkline.tsx +75 -0
  339. package/src/modules/staff/lib/timesheets-projects-ui/ProjectCard.tsx +110 -0
  340. package/src/modules/staff/lib/timesheets-projects-ui/ProjectMembersAvatarStack.tsx +73 -0
  341. package/src/modules/staff/lib/timesheets-projects-ui/ProjectsKpiStrip.tsx +185 -0
  342. package/src/modules/staff/lib/timesheets-projects-ui/SavedViewTabs.tsx +53 -0
  343. package/src/modules/staff/lib/timesheets-projects-ui/ViewModeToggle.tsx +63 -0
  344. package/src/modules/staff/lib/timesheets-projects-ui/useProjectsViewMode.ts +63 -0
  345. package/src/modules/staff/lib/timesheets-ui/AddRowDropdown.tsx +188 -0
  346. package/src/modules/staff/lib/timesheets-ui/CalendarPicker.tsx +229 -0
  347. package/src/modules/staff/lib/timesheets-ui/ColorPicker.tsx +65 -0
  348. package/src/modules/staff/lib/timesheets-ui/CreateProjectDialog.tsx +99 -0
  349. package/src/modules/staff/lib/timesheets-ui/ListView.tsx +230 -0
  350. package/src/modules/staff/lib/timesheets-ui/ProjectColorDot.tsx +40 -0
  351. package/src/modules/staff/lib/timesheets-ui/TimerBar.tsx +327 -0
  352. package/src/modules/staff/lib/timesheets-ui/ViewSwitcher.tsx +60 -0
  353. package/src/modules/staff/lib/timesheets-ui/colors.ts +58 -0
  354. package/src/modules/staff/migrations/.snapshot-open-mercato.json +1148 -0
  355. package/src/modules/staff/migrations/Migration20260326135612.ts +26 -0
  356. package/src/modules/staff/migrations/Migration20260413102715.ts +25 -0
  357. package/src/modules/staff/migrations/Migration20260413111602.ts +13 -0
  358. package/src/modules/staff/migrations/Migration20260511112759.ts +21 -0
  359. package/src/modules/staff/search.ts +35 -0
  360. package/src/modules/staff/setup.ts +15 -0
  361. package/src/modules/staff/widgets/dashboard/timesheets-hours-by-project/config.ts +17 -0
  362. package/src/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.client.tsx +158 -0
  363. package/src/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.ts +25 -0
  364. package/src/modules/staff/widgets/dashboard/timesheets-time-reporting/config.ts +15 -0
  365. package/src/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.client.tsx +297 -0
  366. package/src/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.ts +25 -0
  367. package/src/modules/staff/widgets/injection/timer-sidebar-indicator/widget.tsx +161 -0
  368. package/src/modules/staff/widgets/injection-table.ts +10 -0
  369. package/src/modules/sync_excel/api/import/route.ts +23 -18
  370. package/src/modules/translations/commands/translations.ts +49 -41
@@ -0,0 +1,710 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { Page, PageBody } from "@open-mercato/ui/backend/Page";
5
+ import { Button } from "@open-mercato/ui/primitives/button";
6
+ import { apiCall, apiCallOrThrow, readApiResultOrThrow } from "@open-mercato/ui/backend/utils/apiCall";
7
+ import { useGuardedMutation } from "@open-mercato/ui/backend/injection/useGuardedMutation";
8
+ import { flash } from "@open-mercato/ui/backend/FlashMessages";
9
+ import { LoadingMessage } from "@open-mercato/ui/backend/detail";
10
+ import { useConfirmDialog } from "@open-mercato/ui/backend/confirm-dialog";
11
+ import { useOrganizationScopeVersion } from "@open-mercato/shared/lib/frontend/useOrganizationScope";
12
+ import { useT } from "@open-mercato/shared/lib/i18n/context";
13
+ import { ChevronLeft, ChevronRight, X } from "lucide-react";
14
+ import Link from "next/link";
15
+ import { ViewSwitcher } from "../../../lib/timesheets-ui/ViewSwitcher.js";
16
+ import { CalendarPicker } from "../../../lib/timesheets-ui/CalendarPicker.js";
17
+ import { ListView } from "../../../lib/timesheets-ui/ListView.js";
18
+ import { TimerBar } from "../../../lib/timesheets-ui/TimerBar.js";
19
+ import { AddRowDropdown } from "../../../lib/timesheets-ui/AddRowDropdown.js";
20
+ import { CreateProjectDialog } from "../../../lib/timesheets-ui/CreateProjectDialog.js";
21
+ import { ProjectColorDot } from "../../../lib/timesheets-ui/ProjectColorDot.js";
22
+ function getMonday(date) {
23
+ const d = new Date(date);
24
+ const day = d.getDay();
25
+ const diff = day === 0 ? -6 : 1 - day;
26
+ d.setDate(d.getDate() + diff);
27
+ d.setHours(0, 0, 0, 0);
28
+ return d;
29
+ }
30
+ function getSunday(monday) {
31
+ const d = new Date(monday);
32
+ d.setDate(d.getDate() + 6);
33
+ return d;
34
+ }
35
+ function getWeekNumber(date) {
36
+ const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
37
+ d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
38
+ const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
39
+ return Math.ceil(((d.getTime() - yearStart.getTime()) / 864e5 + 1) / 7);
40
+ }
41
+ function formatDateKey(date) {
42
+ const y = date.getFullYear();
43
+ const m = String(date.getMonth() + 1).padStart(2, "0");
44
+ const d = String(date.getDate()).padStart(2, "0");
45
+ return `${y}-${m}-${d}`;
46
+ }
47
+ function formatDateKeyFromParts(year, month, day) {
48
+ const m = String(month + 1).padStart(2, "0");
49
+ const d = String(day).padStart(2, "0");
50
+ return `${year}-${m}-${d}`;
51
+ }
52
+ function getDaysInMonth(year, month) {
53
+ return new Date(year, month + 1, 0).getDate();
54
+ }
55
+ function isWeekendDay(date) {
56
+ const d = date.getDay();
57
+ return d === 0 || d === 6;
58
+ }
59
+ function minutesToDecimal(minutes) {
60
+ if (minutes === 0) return "";
61
+ const hours = minutes / 60;
62
+ return hours % 1 === 0 ? String(hours) : hours.toFixed(2).replace(/0+$/, "").replace(/\.$/, "");
63
+ }
64
+ function decimalToMinutes(value) {
65
+ const trimmed = value.trim();
66
+ if (!trimmed) return 0;
67
+ const num = parseFloat(trimmed);
68
+ if (isNaN(num) || num < 0) return 0;
69
+ return Math.min(Math.round(num * 60), 1440);
70
+ }
71
+ function getLocalizedDayName(date) {
72
+ return date.toLocaleDateString(void 0, { weekday: "short" });
73
+ }
74
+ function getWeekDays(weekStart) {
75
+ return Array.from({ length: 7 }, (_, i) => {
76
+ const d = new Date(weekStart);
77
+ d.setDate(d.getDate() + i);
78
+ return d;
79
+ });
80
+ }
81
+ function getMonthDays(year, month) {
82
+ const count = getDaysInMonth(year, month);
83
+ return Array.from({ length: count }, (_, i) => new Date(year, month, i + 1));
84
+ }
85
+ function formatWeekLabel(weekStart) {
86
+ const weekEnd = getSunday(weekStart);
87
+ const weekNum = getWeekNumber(weekStart);
88
+ const startDay = weekStart.getDate();
89
+ const endDay = weekEnd.getDate();
90
+ const startMonth = weekStart.toLocaleString(void 0, { month: "short" });
91
+ const endMonth = weekEnd.toLocaleString(void 0, { month: "short" });
92
+ const year = weekStart.getFullYear();
93
+ const dateRange = weekStart.getMonth() === weekEnd.getMonth() ? `${startDay} - ${endDay} ${startMonth} ${year}` : `${startDay} ${startMonth} - ${endDay} ${endMonth} ${year}`;
94
+ return `${dateRange} \xB7 W${weekNum}`;
95
+ }
96
+ function formatMonthLabel(year, month) {
97
+ const date = new Date(year, month, 1);
98
+ return date.toLocaleString(void 0, { month: "long", year: "numeric" });
99
+ }
100
+ function MyTimesheetsPage() {
101
+ const t = useT();
102
+ const scopeVersion = useOrganizationScopeVersion();
103
+ const { confirm, ConfirmDialogElement } = useConfirmDialog();
104
+ const now = /* @__PURE__ */ new Date();
105
+ const [viewMode, setViewMode] = React.useState("weekly");
106
+ const [viewType, setViewType] = React.useState("timesheet");
107
+ const [weekStart, setWeekStart] = React.useState(() => getMonday(now));
108
+ const [monthYear, setMonthYear] = React.useState(now.getFullYear());
109
+ const [monthIndex, setMonthIndex] = React.useState(now.getMonth());
110
+ const [projects, setProjects] = React.useState([]);
111
+ const [entries, setEntries] = React.useState({});
112
+ const [rawEntries, setRawEntries] = React.useState([]);
113
+ const [dirty, setDirty] = React.useState({});
114
+ const [rawText, setRawText] = React.useState({});
115
+ const [staffMemberId, setStaffMemberId] = React.useState(null);
116
+ const [staffMemberMissing, setStaffMemberMissing] = React.useState(false);
117
+ const [isInitialLoad, setIsInitialLoad] = React.useState(true);
118
+ const [isRefreshing, setIsRefreshing] = React.useState(false);
119
+ const [isSaving, setIsSaving] = React.useState(false);
120
+ const [canManageProjects, setCanManageProjects] = React.useState(false);
121
+ const [createDialogOpen, setCreateDialogOpen] = React.useState(false);
122
+ const [allAssignedProjects, setAllAssignedProjects] = React.useState([]);
123
+ const mutationContextId = React.useMemo(
124
+ () => staffMemberId ? `staff-timesheets:${staffMemberId}` : "staff-timesheets:pending",
125
+ [staffMemberId]
126
+ );
127
+ const { runMutation, retryLastMutation } = useGuardedMutation({
128
+ contextId: mutationContextId,
129
+ blockedMessage: t("ui.forms.flash.saveBlocked", "Save blocked by validation")
130
+ });
131
+ React.useEffect(() => {
132
+ let cancelled = false;
133
+ void (async () => {
134
+ try {
135
+ const res = await apiCall("/api/auth/feature-check", {
136
+ method: "POST",
137
+ headers: { "content-type": "application/json" },
138
+ body: JSON.stringify({ features: ["staff.timesheets.projects.manage"] })
139
+ });
140
+ if (!cancelled) {
141
+ setCanManageProjects(new Set(res.result?.granted ?? []).has("staff.timesheets.projects.manage"));
142
+ }
143
+ } catch {
144
+ }
145
+ })();
146
+ return () => {
147
+ cancelled = true;
148
+ };
149
+ }, []);
150
+ const visibleDays = React.useMemo(() => {
151
+ if (viewMode === "weekly") return getWeekDays(weekStart);
152
+ return getMonthDays(monthYear, monthIndex);
153
+ }, [viewMode, weekStart, monthYear, monthIndex]);
154
+ const dateRange = React.useMemo(() => {
155
+ if (viewMode === "weekly") {
156
+ return { from: formatDateKey(weekStart), to: formatDateKey(getSunday(weekStart)) };
157
+ }
158
+ const daysInMonth = getDaysInMonth(monthYear, monthIndex);
159
+ return {
160
+ from: formatDateKeyFromParts(monthYear, monthIndex, 1),
161
+ to: formatDateKeyFromParts(monthYear, monthIndex, daysInMonth)
162
+ };
163
+ }, [viewMode, weekStart, monthYear, monthIndex]);
164
+ const goToPrev = React.useCallback(() => {
165
+ if (viewMode === "weekly") {
166
+ setWeekStart((prev) => {
167
+ const d = new Date(prev);
168
+ d.setDate(d.getDate() - 7);
169
+ return d;
170
+ });
171
+ } else {
172
+ setMonthIndex((prev) => {
173
+ if (prev === 0) {
174
+ setMonthYear((y) => y - 1);
175
+ return 11;
176
+ }
177
+ return prev - 1;
178
+ });
179
+ }
180
+ }, [viewMode]);
181
+ const goToNext = React.useCallback(() => {
182
+ if (viewMode === "weekly") {
183
+ setWeekStart((prev) => {
184
+ const d = new Date(prev);
185
+ d.setDate(d.getDate() + 7);
186
+ return d;
187
+ });
188
+ } else {
189
+ setMonthIndex((prev) => {
190
+ if (prev === 11) {
191
+ setMonthYear((y) => y + 1);
192
+ return 0;
193
+ }
194
+ return prev + 1;
195
+ });
196
+ }
197
+ }, [viewMode]);
198
+ const navigationLabel = React.useMemo(() => {
199
+ if (viewMode === "weekly") return formatWeekLabel(weekStart);
200
+ return formatMonthLabel(monthYear, monthIndex);
201
+ }, [viewMode, weekStart, monthYear, monthIndex]);
202
+ const isInitialLoadRef = React.useRef(true);
203
+ const loadData = React.useCallback(async () => {
204
+ if (!isInitialLoadRef.current) setIsRefreshing(true);
205
+ try {
206
+ const selfRes = await readApiResultOrThrow(
207
+ "/api/staff/team-members/self",
208
+ void 0,
209
+ { errorMessage: t("staff.timesheets.my.errors.load", "Failed to load timesheets."), fallback: { member: null } }
210
+ );
211
+ const memberId = selfRes.member?.id ?? null;
212
+ setStaffMemberId(memberId);
213
+ if (!memberId) {
214
+ setStaffMemberMissing(true);
215
+ setProjects([]);
216
+ setEntries({});
217
+ setRawEntries([]);
218
+ setIsInitialLoad(false);
219
+ setIsRefreshing(false);
220
+ return;
221
+ }
222
+ setStaffMemberMissing(false);
223
+ const assignmentsRes = await readApiResultOrThrow(
224
+ "/api/staff/timesheets/my-projects?pageSize=100",
225
+ void 0,
226
+ { errorMessage: t("staff.timesheets.my.errors.load", "Failed to load timesheets."), fallback: { items: [] } }
227
+ );
228
+ const assignmentItems = Array.isArray(assignmentsRes.items) ? assignmentsRes.items : [];
229
+ const assignedProjectIds = assignmentItems.map((item) => String(item.time_project_id ?? item.timeProjectId ?? "")).filter((id) => id.length > 0);
230
+ const visibleProjectIdSet = new Set(
231
+ assignmentItems.filter((item) => item.show_in_grid === true || item.showInGrid === true).map((item) => String(item.time_project_id ?? item.timeProjectId ?? "")).filter((id) => id.length > 0)
232
+ );
233
+ const [projectsRes, entriesRes] = await Promise.all([
234
+ assignedProjectIds.length > 0 ? readApiResultOrThrow(
235
+ `/api/staff/timesheets/time-projects?ids=${assignedProjectIds.join(",")}&pageSize=100`,
236
+ void 0,
237
+ { errorMessage: t("staff.timesheets.my.errors.load", "Failed to load timesheets."), fallback: { items: [] } }
238
+ ) : Promise.resolve({ items: [] }),
239
+ readApiResultOrThrow(
240
+ `/api/staff/timesheets/time-entries?pageSize=100&staffMemberId=${memberId}&from=${dateRange.from}&to=${dateRange.to}`,
241
+ void 0,
242
+ { errorMessage: t("staff.timesheets.my.errors.load", "Failed to load timesheets."), fallback: { items: [] } }
243
+ )
244
+ ]);
245
+ const projectItems = Array.isArray(projectsRes.items) ? projectsRes.items : [];
246
+ const mappedProjects = projectItems.map((item) => ({
247
+ id: String(item.id ?? ""),
248
+ name: String(item.name ?? ""),
249
+ code: typeof item.code === "string" ? item.code : null,
250
+ color: typeof item.color === "string" ? item.color : null
251
+ }));
252
+ setAllAssignedProjects(mappedProjects);
253
+ const visibleProjects = mappedProjects.filter((p) => visibleProjectIdSet.has(p.id));
254
+ setProjects(visibleProjects);
255
+ const entryItems = Array.isArray(entriesRes.items) ? entriesRes.items : [];
256
+ setRawEntries(entryItems);
257
+ const map = {};
258
+ for (const item of entryItems) {
259
+ const projectId = String(item.time_project_id ?? item.timeProjectId ?? "");
260
+ const rawDate = String(item.date ?? "");
261
+ const dateKey = rawDate.slice(0, 10);
262
+ const minutes = typeof item.duration_minutes === "number" ? item.duration_minutes : typeof item.durationMinutes === "number" ? item.durationMinutes : 0;
263
+ const entryId = String(item.id ?? "");
264
+ if (!map[projectId]) map[projectId] = {};
265
+ if (!map[projectId][dateKey]) map[projectId][dateKey] = [];
266
+ map[projectId][dateKey].push({ id: entryId || void 0, minutes });
267
+ }
268
+ setEntries(map);
269
+ setDirty({});
270
+ setRawText({});
271
+ } catch (error) {
272
+ console.error("staff.timesheets.my.load", error);
273
+ flash(t("staff.timesheets.my.errors.load", "Failed to load timesheets."), "error");
274
+ } finally {
275
+ isInitialLoadRef.current = false;
276
+ setIsInitialLoad(false);
277
+ setIsRefreshing(false);
278
+ }
279
+ }, [dateRange.from, dateRange.to, t]);
280
+ React.useEffect(() => {
281
+ void loadData();
282
+ }, [loadData, scopeVersion]);
283
+ const handleCellChange = React.useCallback((projectId, dateKey, value) => {
284
+ const sanitized = value.replace(/[^0-9.,]/g, "");
285
+ setRawText((prev) => {
286
+ const projectTexts = { ...prev[projectId] ?? {} };
287
+ projectTexts[dateKey] = sanitized;
288
+ return { ...prev, [projectId]: projectTexts };
289
+ });
290
+ }, []);
291
+ const handleCellBlur = React.useCallback((projectId, dateKey) => {
292
+ const text = rawText[projectId]?.[dateKey];
293
+ if (text === void 0) return;
294
+ const minutes = decimalToMinutes(text);
295
+ const cellEntries = entries[projectId]?.[dateKey] ?? [];
296
+ const existingMinutes = cellEntries.reduce((sum, e) => sum + e.minutes, 0);
297
+ if (minutes !== existingMinutes || cellEntries.length > 0) {
298
+ setDirty((prev) => {
299
+ const projectEntries = { ...prev[projectId] ?? {} };
300
+ const firstId = cellEntries[0]?.id;
301
+ projectEntries[dateKey] = { id: firstId, minutes };
302
+ return { ...prev, [projectId]: projectEntries };
303
+ });
304
+ }
305
+ setRawText((prev) => {
306
+ const projectTexts = { ...prev[projectId] ?? {} };
307
+ delete projectTexts[dateKey];
308
+ const hasKeys = Object.keys(projectTexts).length > 0;
309
+ if (!hasKeys) {
310
+ const next = { ...prev };
311
+ delete next[projectId];
312
+ return next;
313
+ }
314
+ return { ...prev, [projectId]: projectTexts };
315
+ });
316
+ }, [rawText, entries]);
317
+ const getCellValue = React.useCallback((projectId, dateKey) => {
318
+ const dirtyCell = dirty[projectId]?.[dateKey];
319
+ if (dirtyCell !== void 0) return dirtyCell.minutes;
320
+ const cellEntries = entries[projectId]?.[dateKey] ?? [];
321
+ return cellEntries.reduce((sum, e) => sum + e.minutes, 0);
322
+ }, [dirty, entries]);
323
+ const hasChanges = Object.keys(dirty).length > 0 || Object.keys(rawText).length > 0;
324
+ const handleSave = React.useCallback(async () => {
325
+ if (!hasChanges) return;
326
+ const confirmed = await confirm({
327
+ title: t("staff.timesheets.my.confirm_save.title", "Save changes?"),
328
+ text: t("staff.timesheets.my.confirm_save.body", "Your timesheet entries will be saved.")
329
+ });
330
+ if (!confirmed) return;
331
+ setIsSaving(true);
332
+ try {
333
+ const bulkEntries = [];
334
+ for (const [projectId, dateMap] of Object.entries(dirty)) {
335
+ for (const [dateKey, cellValue] of Object.entries(dateMap)) {
336
+ const cell = cellValue;
337
+ const cellEntries = entries[projectId]?.[dateKey] ?? [];
338
+ const firstId = cell.id ?? cellEntries[0]?.id;
339
+ bulkEntries.push({ id: firstId, date: dateKey, timeProjectId: projectId, durationMinutes: cell.minutes });
340
+ }
341
+ }
342
+ if (bulkEntries.length === 0) return;
343
+ const payload = { entries: bulkEntries };
344
+ await runMutation({
345
+ operation: () => apiCallOrThrow("/api/staff/timesheets/time-entries/bulk", {
346
+ method: "POST",
347
+ headers: { "Content-Type": "application/json" },
348
+ body: JSON.stringify(payload)
349
+ }),
350
+ context: {
351
+ formId: mutationContextId,
352
+ resourceKind: "staff.timesheets.time_entry",
353
+ resourceId: staffMemberId ?? void 0,
354
+ staffMemberId,
355
+ retryLastMutation
356
+ },
357
+ mutationPayload: payload
358
+ });
359
+ flash(t("staff.timesheets.my.saved", "Timesheet saved."), "success");
360
+ await loadData();
361
+ } catch (error) {
362
+ console.error("staff.timesheets.my.save", error);
363
+ flash(t("staff.timesheets.my.errors.save", "Failed to save timesheets."), "error");
364
+ } finally {
365
+ setIsSaving(false);
366
+ }
367
+ }, [dirty, entries, hasChanges, confirm, t, loadData, runMutation, mutationContextId, staffMemberId, retryLastMutation]);
368
+ const getRowTotal = React.useCallback((projectId) => {
369
+ let total = 0;
370
+ for (const day of visibleDays) {
371
+ total += getCellValue(projectId, formatDateKey(day));
372
+ }
373
+ return total;
374
+ }, [visibleDays, getCellValue]);
375
+ const getDayTotal = React.useCallback((date) => {
376
+ const dateKey = formatDateKey(date);
377
+ let total = 0;
378
+ for (const project of projects) {
379
+ total += getCellValue(project.id, dateKey);
380
+ }
381
+ return total;
382
+ }, [projects, getCellValue]);
383
+ const grandTotal = React.useMemo(() => {
384
+ let total = 0;
385
+ for (const project of projects) {
386
+ total += getRowTotal(project.id);
387
+ }
388
+ return total;
389
+ }, [projects, getRowTotal]);
390
+ const workingDays = React.useMemo(() => {
391
+ let count = 0;
392
+ for (const day of visibleDays) {
393
+ if (!isWeekendDay(day)) {
394
+ const dateKey = formatDateKey(day);
395
+ for (const project of projects) {
396
+ if (getCellValue(project.id, dateKey) > 0) {
397
+ count++;
398
+ break;
399
+ }
400
+ }
401
+ }
402
+ }
403
+ return count;
404
+ }, [visibleDays, projects, getCellValue]);
405
+ const dailyAverage = React.useMemo(() => {
406
+ if (workingDays === 0) return 0;
407
+ return grandTotal / workingDays;
408
+ }, [grandTotal, workingDays]);
409
+ const listViewEntries = React.useMemo(() => {
410
+ return rawEntries.map((item) => ({
411
+ id: String(item.id ?? ""),
412
+ date: String(item.date ?? "").slice(0, 10),
413
+ durationMinutes: typeof item.duration_minutes === "number" ? item.duration_minutes : typeof item.durationMinutes === "number" ? item.durationMinutes : 0,
414
+ projectId: String(item.time_project_id ?? item.timeProjectId ?? ""),
415
+ projectName: projects.find((p) => p.id === String(item.time_project_id ?? item.timeProjectId ?? ""))?.name ?? "",
416
+ projectCode: projects.find((p) => p.id === String(item.time_project_id ?? item.timeProjectId ?? ""))?.code ?? null,
417
+ projectColor: projects.find((p) => p.id === String(item.time_project_id ?? item.timeProjectId ?? ""))?.color ?? null,
418
+ notes: typeof item.notes === "string" ? item.notes : null,
419
+ source: typeof item.source === "string" ? item.source : "manual",
420
+ startedAt: typeof item.started_at === "string" ? item.started_at : typeof item.startedAt === "string" ? item.startedAt : null,
421
+ endedAt: typeof item.ended_at === "string" ? item.ended_at : typeof item.endedAt === "string" ? item.endedAt : null
422
+ }));
423
+ }, [rawEntries, projects]);
424
+ const handleViewModeChange = React.useCallback((mode) => {
425
+ setViewMode(mode);
426
+ if (mode === "monthly") {
427
+ const thursday = new Date(weekStart);
428
+ thursday.setDate(thursday.getDate() + 3);
429
+ setMonthYear(thursday.getFullYear());
430
+ setMonthIndex(thursday.getMonth());
431
+ } else {
432
+ const midMonth = new Date(monthYear, monthIndex, 15);
433
+ setWeekStart(getMonday(midMonth));
434
+ }
435
+ }, [weekStart, monthYear, monthIndex]);
436
+ const visibleProjectIds = React.useMemo(() => new Set(projects.map((p) => p.id)), [projects]);
437
+ const handleAddProject = React.useCallback(async (project) => {
438
+ try {
439
+ const payload = { showInGrid: true };
440
+ await runMutation({
441
+ operation: () => apiCallOrThrow(`/api/staff/timesheets/my-projects/${project.id}`, {
442
+ method: "PATCH",
443
+ headers: { "Content-Type": "application/json" },
444
+ body: JSON.stringify(payload)
445
+ }),
446
+ context: {
447
+ formId: mutationContextId,
448
+ resourceKind: "staff.timesheets.time_project_member",
449
+ resourceId: project.id,
450
+ staffMemberId,
451
+ retryLastMutation
452
+ },
453
+ mutationPayload: payload
454
+ });
455
+ setProjects((prev) => {
456
+ if (prev.some((p) => p.id === project.id)) return prev;
457
+ return [...prev, project];
458
+ });
459
+ } catch (error) {
460
+ console.error("staff.timesheets.my.addRow", error);
461
+ flash(t("staff.timesheets.my.addRow.error", "Could not add the project. Please try again."), "error");
462
+ }
463
+ }, [t, runMutation, mutationContextId, staffMemberId, retryLastMutation]);
464
+ const handleRemoveProject = React.useCallback(async (project) => {
465
+ const confirmed = await confirm({
466
+ title: t("staff.timesheets.my.removeRow", "Remove from grid"),
467
+ text: t(
468
+ "staff.timesheets.my.removeRow.confirm",
469
+ 'Remove {projectName} from your timesheet grid? You can re-add it anytime via "+ Add row".'
470
+ ).replace("{projectName}", project.name)
471
+ });
472
+ if (!confirmed) return;
473
+ try {
474
+ const payload = { showInGrid: false };
475
+ await runMutation({
476
+ operation: () => apiCallOrThrow(`/api/staff/timesheets/my-projects/${project.id}`, {
477
+ method: "PATCH",
478
+ headers: { "Content-Type": "application/json" },
479
+ body: JSON.stringify(payload)
480
+ }),
481
+ context: {
482
+ formId: mutationContextId,
483
+ resourceKind: "staff.timesheets.time_project_member",
484
+ resourceId: project.id,
485
+ staffMemberId,
486
+ retryLastMutation
487
+ },
488
+ mutationPayload: payload
489
+ });
490
+ setProjects((prev) => prev.filter((p) => p.id !== project.id));
491
+ setDirty((prev) => {
492
+ if (!prev[project.id]) return prev;
493
+ const next = { ...prev };
494
+ delete next[project.id];
495
+ return next;
496
+ });
497
+ setRawText((prev) => {
498
+ if (!prev[project.id]) return prev;
499
+ const next = { ...prev };
500
+ delete next[project.id];
501
+ return next;
502
+ });
503
+ } catch (error) {
504
+ console.error("staff.timesheets.my.removeRow", error);
505
+ flash(t("staff.timesheets.my.removeRow.error", "Could not remove the project. Please try again."), "error");
506
+ }
507
+ }, [confirm, t, runMutation, mutationContextId, staffMemberId, retryLastMutation]);
508
+ const handleProjectCreated = React.useCallback(async (project) => {
509
+ setAllAssignedProjects((prev) => [...prev, project]);
510
+ try {
511
+ const payload = { showInGrid: true };
512
+ await runMutation({
513
+ operation: () => apiCallOrThrow(`/api/staff/timesheets/my-projects/${project.id}`, {
514
+ method: "PATCH",
515
+ headers: { "Content-Type": "application/json" },
516
+ body: JSON.stringify(payload)
517
+ }),
518
+ context: {
519
+ formId: mutationContextId,
520
+ resourceKind: "staff.timesheets.time_project_member",
521
+ resourceId: project.id,
522
+ staffMemberId,
523
+ retryLastMutation
524
+ },
525
+ mutationPayload: payload
526
+ });
527
+ } catch (error) {
528
+ console.error("staff.timesheets.my.createProject.visibility", error);
529
+ }
530
+ setProjects((prev) => [...prev, project]);
531
+ setCreateDialogOpen(false);
532
+ }, [runMutation, mutationContextId, staffMemberId, retryLastMutation]);
533
+ if (isInitialLoad) {
534
+ return /* @__PURE__ */ jsx(Page, { children: /* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsx(LoadingMessage, { label: t("staff.timesheets.my.loading", "Loading timesheets...") }) }) });
535
+ }
536
+ if (staffMemberMissing) {
537
+ return /* @__PURE__ */ jsx(Page, { children: /* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsxs("div", { className: "py-12 text-center", children: [
538
+ /* @__PURE__ */ jsx("p", { className: "text-lg font-semibold mb-2", children: t("staff.timesheets.my.noProfile.title", "Set up your profile to start tracking time") }),
539
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground mb-6", children: t("staff.timesheets.my.noProfile", "You need a Team Member profile to track time.") }),
540
+ /* @__PURE__ */ jsx(Button, { asChild: true, children: /* @__PURE__ */ jsx(Link, { href: "/backend/staff/profile/create", children: t("staff.timesheets.my.createProfile", "Create My Profile") }) })
541
+ ] }) }) });
542
+ }
543
+ return /* @__PURE__ */ jsxs(Page, { children: [
544
+ /* @__PURE__ */ jsxs(PageBody, { children: [
545
+ /* @__PURE__ */ jsx(
546
+ TimerBar,
547
+ {
548
+ projects: allAssignedProjects,
549
+ staffMemberId,
550
+ onTimerStopped: loadData
551
+ }
552
+ ),
553
+ /* @__PURE__ */ jsxs("div", { className: "mb-4 grid grid-cols-1 gap-4 sm:grid-cols-4", children: [
554
+ /* @__PURE__ */ jsxs("div", { className: "rounded-lg border bg-card p-4", children: [
555
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: viewMode === "weekly" ? t("staff.timesheets.my.weekTotal", "Week Total") : t("staff.timesheets.my.total_hours", "Total Hours") }),
556
+ /* @__PURE__ */ jsx("p", { className: "text-2xl font-semibold", children: minutesToDecimal(grandTotal) || "0" })
557
+ ] }),
558
+ /* @__PURE__ */ jsxs("div", { className: "rounded-lg border bg-card p-4", children: [
559
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("staff.timesheets.my.working_days", "Working Days") }),
560
+ /* @__PURE__ */ jsx("p", { className: "text-2xl font-semibold", children: workingDays })
561
+ ] }),
562
+ /* @__PURE__ */ jsxs("div", { className: "rounded-lg border bg-card p-4", children: [
563
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("staff.timesheets.my.daily_average", "Daily Average") }),
564
+ /* @__PURE__ */ jsx("p", { className: "text-2xl font-semibold", children: minutesToDecimal(Math.round(dailyAverage)) || "0" })
565
+ ] }),
566
+ /* @__PURE__ */ jsxs("div", { className: "rounded-lg border bg-card p-4", children: [
567
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("staff.timesheets.my.status", "Status") }),
568
+ /* @__PURE__ */ jsx("p", { className: "text-2xl font-semibold", children: /* @__PURE__ */ jsx("span", { className: "inline-flex items-center rounded-full bg-green-100 px-2.5 py-0.5 text-xs font-medium text-green-800", children: t("staff.timesheets.my.status_open", "Open") }) })
569
+ ] })
570
+ ] }),
571
+ /* @__PURE__ */ jsxs("div", { className: "mb-4 flex flex-wrap items-center justify-between gap-3", children: [
572
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
573
+ /* @__PURE__ */ jsx(Button, { variant: "outline", size: "icon", type: "button", onClick: goToPrev, children: /* @__PURE__ */ jsx(ChevronLeft, { className: "size-4" }) }),
574
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-semibold min-w-[220px] text-center", children: navigationLabel }),
575
+ /* @__PURE__ */ jsx(Button, { variant: "outline", size: "icon", type: "button", onClick: goToNext, children: /* @__PURE__ */ jsx(ChevronRight, { className: "size-4" }) }),
576
+ viewMode === "weekly" && /* @__PURE__ */ jsx(CalendarPicker, { selectedWeekStart: weekStart, onWeekSelect: setWeekStart })
577
+ ] }),
578
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
579
+ /* @__PURE__ */ jsx(
580
+ ViewSwitcher,
581
+ {
582
+ viewMode,
583
+ onViewModeChange: handleViewModeChange,
584
+ viewType,
585
+ onViewTypeChange: setViewType
586
+ }
587
+ ),
588
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
589
+ hasChanges && /* @__PURE__ */ jsx("span", { className: "text-xs text-amber-600 font-medium", children: t("staff.timesheets.my.unsaved", "Unsaved changes") }),
590
+ /* @__PURE__ */ jsx(Button, { size: "sm", type: "button", onClick: handleSave, disabled: !hasChanges || isSaving, children: isSaving ? t("staff.timesheets.my.saving", "Saving...") : t("staff.timesheets.my.save_changes", "Save Changes") })
591
+ ] })
592
+ ] })
593
+ ] }),
594
+ /* @__PURE__ */ jsx("div", { className: isRefreshing ? "opacity-50 pointer-events-none transition-opacity" : "transition-opacity", children: allAssignedProjects.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "py-12 text-center", children: [
595
+ /* @__PURE__ */ jsx("p", { className: "text-lg font-semibold mb-2", children: t("staff.timesheets.my.noProjects.title", "No projects assigned yet") }),
596
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground mb-6", children: canManageProjects ? t("staff.timesheets.my.noProjects.admin", "Create a project and assign yourself to start tracking time.") : t("staff.timesheets.my.noProjects.employee", "Ask your manager to assign you to a project.") }),
597
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-3", children: [
598
+ canManageProjects && /* @__PURE__ */ jsx(Button, { asChild: true, children: /* @__PURE__ */ jsx(Link, { href: "/backend/staff/timesheets/projects/create", children: t("staff.timesheets.my.noProjects.createProject", "Create Project") }) }),
599
+ /* @__PURE__ */ jsx(Button, { variant: "outline", asChild: true, children: /* @__PURE__ */ jsx(Link, { href: "/backend/staff/timesheets/projects", children: t("staff.timesheets.my.noProjects.viewProjects", "View Projects") }) })
600
+ ] })
601
+ ] }) : viewType === "list" ? /* @__PURE__ */ jsx(ListView, { entries: listViewEntries, onEntryUpdated: loadData }) : /* @__PURE__ */ jsx("div", { className: "overflow-x-auto rounded-lg border", children: /* @__PURE__ */ jsxs("table", { className: "w-full text-sm table-fixed", children: [
602
+ /* @__PURE__ */ jsxs("colgroup", { children: [
603
+ /* @__PURE__ */ jsx("col", { className: viewMode === "weekly" ? "w-[35%]" : "w-[140px] min-w-[140px]" }),
604
+ visibleDays.map((date) => /* @__PURE__ */ jsx("col", { className: viewMode === "weekly" ? "" : "w-[36px] min-w-[36px]" }, formatDateKey(date))),
605
+ /* @__PURE__ */ jsx("col", { className: viewMode === "weekly" ? "w-[72px]" : "w-[56px] min-w-[56px]" })
606
+ ] }),
607
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { className: "border-b bg-muted/50", children: [
608
+ /* @__PURE__ */ jsx("th", { className: "sticky left-0 z-10 bg-muted px-3 py-2 text-left font-medium", children: t("staff.timesheets.my.project", "Project") }),
609
+ visibleDays.map((date) => {
610
+ const dayName = getLocalizedDayName(date);
611
+ const weekend = isWeekendDay(date);
612
+ return /* @__PURE__ */ jsxs(
613
+ "th",
614
+ {
615
+ className: `py-2 text-center font-medium px-1 ${weekend ? "bg-muted/80 text-muted-foreground" : ""}`,
616
+ children: [
617
+ /* @__PURE__ */ jsx("div", { className: "text-[10px] uppercase text-muted-foreground", children: dayName }),
618
+ /* @__PURE__ */ jsx("div", { className: "text-xs", children: date.getDate() })
619
+ ]
620
+ },
621
+ formatDateKey(date)
622
+ );
623
+ }),
624
+ /* @__PURE__ */ jsx("th", { className: "px-3 py-2 text-right font-medium", children: t("staff.timesheets.my.total", "Total") })
625
+ ] }) }),
626
+ /* @__PURE__ */ jsxs("tbody", { children: [
627
+ projects.map((project) => /* @__PURE__ */ jsxs("tr", { className: "group border-b hover:bg-muted/30", children: [
628
+ /* @__PURE__ */ jsx("td", { className: "sticky left-0 z-10 bg-background px-3 py-1.5 font-medium text-foreground", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
629
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
630
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 truncate", title: project.name, children: [
631
+ /* @__PURE__ */ jsx(ProjectColorDot, { colorKey: project.color, projectName: project.name, size: "sm" }),
632
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: project.name })
633
+ ] }),
634
+ project.code && /* @__PURE__ */ jsx("div", { className: "text-[10px] text-muted-foreground", children: project.code })
635
+ ] }),
636
+ /* @__PURE__ */ jsx(
637
+ "button",
638
+ {
639
+ type: "button",
640
+ onClick: () => {
641
+ void handleRemoveProject(project);
642
+ },
643
+ "aria-label": t("staff.timesheets.my.removeRow", "Remove from grid"),
644
+ title: t("staff.timesheets.my.removeRow", "Remove from grid"),
645
+ className: "opacity-0 group-hover:opacity-100 focus:opacity-100 inline-flex h-5 w-5 shrink-0 cursor-pointer items-center justify-center rounded text-muted-foreground hover:bg-muted hover:text-foreground transition-opacity",
646
+ children: /* @__PURE__ */ jsx(X, { className: "h-3.5 w-3.5" })
647
+ }
648
+ )
649
+ ] }) }),
650
+ visibleDays.map((date) => {
651
+ const dateKey = formatDateKey(date);
652
+ const weekend = isWeekendDay(date);
653
+ const cellMinutes = getCellValue(project.id, dateKey);
654
+ const isDirty = dirty[project.id]?.[dateKey] !== void 0;
655
+ return /* @__PURE__ */ jsx("td", { className: `px-0.5 py-0.5 ${weekend ? "bg-muted/40" : ""}`, children: weekend ? /* @__PURE__ */ jsx("div", { className: "rounded px-1 py-1 text-center text-xs text-muted-foreground/50", children: "-" }) : /* @__PURE__ */ jsx(
656
+ "input",
657
+ {
658
+ type: "text",
659
+ inputMode: "decimal",
660
+ className: `mx-auto block rounded border text-center tabular-nums transition-colors
661
+ ${viewMode === "weekly" ? "w-12 px-1 py-0.5 text-xs" : "w-8 px-0 py-1 text-[10px]"}
662
+ ${isDirty ? "border-amber-400 bg-amber-50" : "border-muted-foreground/20 bg-transparent"}
663
+ ${cellMinutes > 0 ? "font-semibold" : "text-muted-foreground"}
664
+ hover:border-muted-foreground/40 focus:border-primary focus:bg-background focus:outline-none`,
665
+ value: rawText[project.id]?.[dateKey] ?? minutesToDecimal(cellMinutes),
666
+ onChange: (e) => handleCellChange(project.id, dateKey, e.target.value),
667
+ onBlur: () => handleCellBlur(project.id, dateKey),
668
+ placeholder: t("staff.timesheets.my.durationPlaceholder", "0")
669
+ }
670
+ ) }, dateKey);
671
+ }),
672
+ /* @__PURE__ */ jsx("td", { className: "px-3 py-1.5 text-right font-semibold text-xs tabular-nums", children: minutesToDecimal(getRowTotal(project.id)) || "0" })
673
+ ] }, project.id)),
674
+ /* @__PURE__ */ jsx("tr", { className: "border-b", children: /* @__PURE__ */ jsx("td", { colSpan: visibleDays.length + 2, className: "sticky left-0 bg-background px-1 py-0.5", children: /* @__PURE__ */ jsx(
675
+ AddRowDropdown,
676
+ {
677
+ assignedProjects: allAssignedProjects,
678
+ visibleProjectIds,
679
+ canCreateProject: canManageProjects,
680
+ onAddProject: handleAddProject,
681
+ onCreateProject: () => setCreateDialogOpen(true)
682
+ }
683
+ ) }) })
684
+ ] }),
685
+ /* @__PURE__ */ jsx("tfoot", { children: /* @__PURE__ */ jsxs("tr", { className: "border-t bg-muted/50 font-semibold", children: [
686
+ /* @__PURE__ */ jsx("td", { className: "sticky left-0 z-10 bg-muted px-3 py-2", children: t("staff.timesheets.my.daily_total", "Daily Total") }),
687
+ visibleDays.map((date) => {
688
+ const weekend = isWeekendDay(date);
689
+ const dayMinutes = getDayTotal(date);
690
+ return /* @__PURE__ */ jsx("td", { className: `py-2 text-center text-xs tabular-nums ${weekend ? "text-muted-foreground/50" : ""}`, children: weekend ? "-" : minutesToDecimal(dayMinutes) || "-" }, formatDateKey(date));
691
+ }),
692
+ /* @__PURE__ */ jsx("td", { className: "px-3 py-2 text-right tabular-nums font-semibold", children: minutesToDecimal(grandTotal) || "0" })
693
+ ] }) })
694
+ ] }) }) })
695
+ ] }),
696
+ ConfirmDialogElement,
697
+ /* @__PURE__ */ jsx(
698
+ CreateProjectDialog,
699
+ {
700
+ open: createDialogOpen,
701
+ onOpenChange: setCreateDialogOpen,
702
+ onProjectCreated: handleProjectCreated
703
+ }
704
+ )
705
+ ] });
706
+ }
707
+ export {
708
+ MyTimesheetsPage as default
709
+ };
710
+ //# sourceMappingURL=page.js.map