1 | |
2 | type SageIntacct = { |
3 | token: string |
4 | } |
5 | |
6 | * Create a timesheet |
7 | * Creates a new timesheet. |
8 |
|
9 |
|
10 | Permissions and other requirements |
11 |
|
12 | SubscriptionTime & Expenses |
13 | User typeBusiness, Project Manager, or Employee |
14 | PermissionsAdd timesheets |
15 |
|
16 |
|
17 |
|
18 |
|
19 | */ |
20 | export async function main( |
21 | auth: SageIntacct, |
22 | body: { |
23 | key?: string |
24 | id?: string |
25 | href?: string |
26 | beginDate?: string |
27 | endDate?: string |
28 | postingDate?: string |
29 | state?: |
30 | | 'submitted' |
31 | | 'approved' |
32 | | 'partiallyApproved' |
33 | | 'declined' |
34 | | 'draft' |
35 | | 'partiallyDeclined' |
36 | | 'saved' |
37 | unitOfMeasure?: string |
38 | hoursInDay?: number |
39 | description?: string |
40 | calculationMethod?: 'hourly' | 'salary' |
41 | postActualLaborCost?: false | true |
42 | employee?: { key?: string; id?: string; href?: string } |
43 | employeeContact?: { |
44 | key?: string |
45 | id?: string |
46 | firstName?: string |
47 | lastName?: string |
48 | href?: string |
49 | } |
50 | attachment?: { key?: string; id?: string; href?: string } |
51 | lines?: { |
52 | key?: string |
53 | id?: string |
54 | href?: string |
55 | timesheet?: { key?: string; id?: string; href?: string } |
56 | entryDate?: string |
57 | quantity?: number |
58 | lineNumber?: number |
59 | description?: string |
60 | notes?: string |
61 | state?: |
62 | | 'submitted' |
63 | | 'approved' |
64 | | 'partiallyApproved' |
65 | | 'declined' |
66 | | 'draft' |
67 | | 'saved' |
68 | | 'readyForApproval' |
69 | timeType?: { key?: string; id?: string; href?: string } |
70 | isBillable?: false | true |
71 | isBilled?: 'true' | 'false' | 'partial' |
72 | statisticalJournal?: { key?: string; id?: string; href?: string } |
73 | billableUtilizedGLAccount?: { key?: string; id?: string; href?: string } |
74 | nonBillableUtilizedGLAccount?: { |
75 | key?: string |
76 | id?: string |
77 | href?: string |
78 | } |
79 | billableNonUtilizedGLAccount?: { |
80 | key?: string |
81 | id?: string |
82 | href?: string |
83 | } |
84 | nonBillableNonUtilizedGLAccount?: { |
85 | key?: string |
86 | id?: string |
87 | href?: string |
88 | } |
89 | hours?: { |
90 | billable?: number |
91 | nonBillable?: number |
92 | approved?: number |
93 | approvedBillable?: number |
94 | approvedNonBillable?: number |
95 | utilized?: number |
96 | nonUtilized?: number |
97 | approvedUtilized?: number |
98 | approvedNonUtilized?: number |
99 | } |
100 | externalPayroll?: { |
101 | costRate?: number |
102 | billingRate?: number |
103 | amount?: string |
104 | employerTaxes?: number |
105 | fringes?: number |
106 | cashFringes?: number |
107 | } |
108 | laborClass?: { key?: string; id?: string; name?: string; href?: string } |
109 | laborShift?: { key?: string; id?: string; name?: string; href?: string } |
110 | laborUnion?: { key?: string; id?: string; name?: string; href?: string } |
111 | dimensions?: { |
112 | location?: { key?: string; id?: string; name?: string; href?: string } |
113 | department?: { |
114 | key?: string |
115 | id?: string |
116 | name?: string |
117 | href?: string |
118 | } |
119 | employee?: { key?: string; id?: string; name?: string; href?: string } |
120 | project?: { key?: string; id?: string; name?: string; href?: string } |
121 | customer?: { key?: string; id?: string; name?: string; href?: string } |
122 | vendor?: { key?: string; id?: string; name?: string; href?: string } |
123 | item?: { key?: string; id?: string; name?: string; href?: string } |
124 | warehouse?: { key?: string; id?: string; name?: string; href?: string } |
125 | class?: { key?: string; id?: string; name?: string; href?: string } |
126 | task?: { id?: string; key?: string; name?: string; href?: string } |
127 | costType?: { id?: string; key?: string; name?: string; href?: string } |
128 | asset?: { id?: string; key?: string; name?: string; href?: string } |
129 | contract?: { id?: string; key?: string; name?: string; href?: string } |
130 | affiliateEntity?: { |
131 | key?: string |
132 | id?: string |
133 | href?: string |
134 | name?: string |
135 | } |
136 | } & { |
137 | location?: { key?: string; id?: string; name?: string; href?: string } |
138 | department?: { |
139 | key?: string |
140 | id?: string |
141 | name?: string |
142 | href?: string |
143 | } |
144 | } |
145 | audit?: { |
146 | createdDateTime?: string |
147 | modifiedDateTime?: string |
148 | createdBy?: string |
149 | modifiedBy?: string |
150 | } |
151 | }[] |
152 | audit?: { |
153 | createdDateTime?: string |
154 | modifiedDateTime?: string |
155 | createdBy?: string |
156 | modifiedBy?: string |
157 | } |
158 | entity?: { key?: string; id?: string; name?: string; href?: string } |
159 | } & {} |
160 | ) { |
161 | const url = new URL(`https://api.intacct.com/ia/api/v1/objects/time/timesheet`) |
162 |
|
163 | const response = await fetch(url, { |
164 | method: 'POST', |
165 | headers: { |
166 | 'Content-Type': 'application/json', |
167 | Authorization: 'Bearer ' + auth.token |
168 | }, |
169 | body: JSON.stringify(body) |
170 | }) |
171 | if (!response.ok) { |
172 | const text = await response.text() |
173 | throw new Error(`${response.status} ${text}`) |
174 | } |
175 | return await response.json() |
176 | } |
177 |
|