|
25 | 25 | paystubs: (SelectPaystub & { employee: SelectEmployee })[]; |
26 | 26 | }; |
27 | 27 | const cycles = historyCycles as (SelectPayrollCycle & { paystubs: SelectPaystub[] })[]; |
| 28 | + console.log(data); |
28 | 29 | </script> |
29 | 30 |
|
30 | 31 | <svelte:head> |
|
43 | 44 | <div class="px-4 mb-4 text-2xl font-medium">Latest Payroll</div> |
44 | 45 | <div class="flex flex-col md:flex-row md:justify-around"> |
45 | 46 | {#if user && ['org_admin', 'super_admin'].includes(user.profile.role)} |
| 47 | + {#if cycle !== null && cycle.paystubs?.length > 0} |
46 | 48 | <Card size="sm"> |
47 | 49 | <h5 class="mb-4 text-2xl font-medium text-gray-600 dark:text-gray-50"> |
48 | | - {toHumanDate(cycle.paymentDate)} |
| 50 | + {toHumanDate(cycle?.paymentDate)} |
49 | 51 | </h5> |
50 | 52 | <div class="flex items-baseline text-gray-900 dark:text-white"> |
51 | 53 | <ul class="my-7 space-y-4"> |
| 54 | + {#if cycle.paystubs?.length > 0} |
52 | 55 | <li class="flex space-x-2 rtl:space-x-reverse"> |
53 | 56 | <CheckCircleSolid class="w-4 h-4 text-primary-600 dark:text-primary-500" /> |
54 | 57 | <span class="text-xl font-extrabold tracking-tight" |
55 | 58 | >{cycle.paystubs?.length} paystubs</span |
56 | 59 | > |
57 | 60 | </li> |
| 61 | + {/if} |
| 62 | + {#if cycle.paystubs?.length > 0} |
58 | 63 | <li class="flex space-x-2 rtl:space-x-reverse"> |
59 | 64 | <CheckCircleSolid class="w-4 h-4 text-primary-600 dark:text-primary-500" /> |
60 | 65 | <span class="text-xl font-extrabold tracking-tight" |
61 | 66 | >${cycle.paystubs?.reduce((acc, curr) => acc + Number(curr.netPay), 0)}</span |
62 | 67 | > total net |
63 | 68 | </li> |
| 69 | + {/if} |
64 | 70 | </ul> |
65 | 71 | </div> |
66 | 72 | <div class="flex flex-col w-full md:flex-row md:justify-end md:w-auto"> |
67 | | - <Button href={'/app/payroll-cycles/' + cycle.id}>View Details</Button> |
| 73 | + <Button href={'/app/payroll-cycles/' + cycle?.id}>View Details</Button> |
68 | 74 | </div> |
69 | 75 | </Card> |
| 76 | + {/if} |
70 | 77 | <Card size="sm"> |
71 | 78 | <div class="mb-4 text-xl font-medium text-gray-400 dark:text-gray-500"> |
72 | 79 | Top Performers |
73 | 80 | </div> |
74 | 81 | <div class="flex items-baseline text-gray-900 dark:text-white"> |
| 82 | + {#if cycle?.paystubs?.length > 0} |
75 | 83 | {#each cycle?.paystubs as paystub (paystub.id)} |
76 | 84 | <div class="flex flex-col md:flex-row justify-between gap-2 w-full"> |
77 | 85 | <span class="text-xl font-extrabold tracking-tight" |
|
82 | 90 | > |
83 | 91 | </div> |
84 | 92 | {/each} |
| 93 | + {:else} |
| 94 | + <span class="text-xl font-extrabold tracking-tight">No paystubs</span> |
| 95 | + {/if} |
85 | 96 | </div> |
86 | 97 | </Card> |
87 | 98 | {:else} |
|
105 | 116 | <TableHeadCell>Closed</TableHeadCell> |
106 | 117 | </TableHead> |
107 | 118 | <TableBody> |
| 119 | + {#if cycles.length > 0} |
108 | 120 | {#each cycles as cycle (cycle.id)} |
109 | 121 | <TableBodyRow> |
110 | 122 | <TableBodyCell> |
|
121 | 133 | </TableBodyCell> |
122 | 134 | </TableBodyRow> |
123 | 135 | {/each} |
| 136 | + {:else} |
| 137 | + <TableBodyRow> |
| 138 | + <TableBodyCell colSpan={6} class="text-center"> |
| 139 | + No payroll cycles found |
| 140 | + </TableBodyCell> |
| 141 | + </TableBodyRow> |
| 142 | + {/if} |
124 | 143 | </TableBody> |
125 | 144 | </Table> |
126 | 145 | </div> |
|
0 commit comments