| 1 | export function classifyInvoices< |
| 2 | T extends |
| 3 | >(invoices: T |
| 4 | const draft: |
| 5 | const sent: |
| 6 | const paid: |
| 7 | const disputed: |
| 8 | const overdue: |
| 9 | const now = |
| 10 | |
| 11 | for (const invoice |
| 12 | switch (invoice.status |
| 13 | case 'draft': |
| 14 | draft.push(invoice |
| 15 | break |
| 16 | case 'sent': |
| 17 | sent.push(invoice |
| 18 | if (invoice.dueDate |
| 19 | overdue.push(invoice |
| 20 | } |
| 21 | break |
| 22 | case 'paid': |
| 23 | paid.push(invoice |
| 24 | break |
| 25 | case 'disputed': |
| 26 | disputed.push(invoice |
| 27 | break |
| 28 | default: |
| 29 | break |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | return { draft, |
| 34 | } |
| 35 | |
| 36 | export function classifyMilestones< |
| 37 | T extends |
| 38 | >(milestones: T |
| 39 | const inProgress: |
| 40 | const blocked: |
| 41 | const overdue: |
| 42 | let completed = |
| 43 | let next: |
| 44 | let nextTime = |
| 45 | const now = |
| 46 | |
| 47 | for (const milestone |
| 48 | if (milestone.status |
| 49 | completed++ |
| 50 | continue |
| 51 | } |
| 52 | |
| 53 | if (milestone.status |
| 54 | inProgress.push(milestone |
| 55 | } |
| 56 | if (milestone.status |
| 57 | blocked.push(milestone |
| 58 | } |
| 59 | |
| 60 | if (milestone.dueDate |
| 61 | const dueTime = |
| 62 | if (dueTime < |
| 63 | overdue.push(milestone |
| 64 | } |
| 65 | if (dueTime < |
| 66 | nextTime = dueTime |
| 67 | next = milestone |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | return { |
| 73 | inProgress, |
| 74 | blocked, |
| 75 | overdue, |
| 76 | completed, |
| 77 | next, |
| 78 | completionPercent: milestones.length |
| 79 | ? Math.round(( |
| 80 | : 0, |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | export function summarizeTime<T |
| 85 | entries: T |
| 86 | ) { |
| 87 | const totalMinutes = |
| 88 | return { |
| 89 | hours: Math.floor |
| 90 | minutes: totalMinutes % |
| 91 | entryCount: entries.length, |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | export function summarizeTimeEntries< |
| 96 | T extends |
| 97 | >(entries: T |
| 98 | let totalMinutes = |
| 99 | const pendingApproval: |
| 100 | const rejected: |
| 101 | |
| 102 | for (const entry |
| 103 | totalMinutes += entry. |
| 104 | if (entry.status |
| 105 | pendingApproval.push(entry |
| 106 | } else if (entry |
| 107 | rejected.push(entry |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | return { |
| 112 | hours: Math.floor |
| 113 | minutes: totalMinutes % |
| 114 | pendingApproval, |
| 115 | rejected, |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | export function classifyExpenses< |
| 120 | T extends |
| 121 | >(expenses: T |
| 122 | const pendingAdmin: |
| 123 | const pendingClient: |
| 124 | const billableApproved: |
| 125 | |
| 126 | for (const expense |
| 127 | if (expense.status |
| 128 | pendingAdmin.push(expense |
| 129 | } else if (expense |
| 130 | pendingClient.push(expense |
| 131 | } else if (expense |
| 132 | billableApproved.push(expense |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | return { pendingAdmin, |
| 137 | } |
| 138 | |
| 139 | interface OverdueInvoiceEntry { |
| 140 | currency: string |
| 141 | dueDate: Date |
| 142 | id: string |
| 143 | invoiceNumber: string |
| 144 | projectName?: string |
| 145 | projectSlug: string |
| 146 | totalAmount: string |
| 147 | } |
| 148 | |
| 149 | export function toOverdueInvoiceEntries< |
| 150 | T extends |
| 151 | id: string |
| 152 | invoiceNumber: string |
| 153 | totalAmount: string |
| 154 | currency: string |
| 155 | dueDate: Date |
| 156 | projectId?: string |
| 157 | }, |
| 158 | >( |
| 159 | overdueInvoices: T |
| 160 | resolveProject: |
| 161 | | string |
| 162 | | Map |
| 163 | | ((invoice |
| 164 | ) { |
| 165 | const entries: |
| 166 | |
| 167 | for (const invoice |
| 168 | if (!invoice.dueDate |
| 169 | continue |
| 170 | } |
| 171 | |
| 172 | let project: |
| 173 | if (typeof resolveProject |
| 174 | project = { slug |
| 175 | } else if (resolveProject |
| 176 | project = invoice. |
| 177 | ? resolveProject.get( |
| 178 | : undefined |
| 179 | } else { |
| 180 | project = resolveProject( |
| 181 | } |
| 182 | |
| 183 | if (!project) |
| 184 | continue |
| 185 | } |
| 186 | |
| 187 | entries.push({ |
| 188 | id: invoice.id |
| 189 | invoiceNumber: invoice.invoiceNumber |
| 190 | totalAmount: invoice.totalAmount |
| 191 | currency: invoice.currency |
| 192 | dueDate: new Date |
| 193 | projectSlug: project.slug |
| 194 | projectName: project.name |
| 195 | }) |
| 196 | } |
| 197 | |
| 198 | return entries |
| 199 | } |
| 200 | |
| 201 | export function getGreeting(now |
| 202 | const hour = |
| 203 | if (hour < |
| 204 | return 'Good morning' |
| 205 | } |
| 206 | if (hour < |
| 207 | return 'Good afternoon' |
| 208 | } |
| 209 | return 'Good evening' |
| 210 | } |