1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
use crate::Client;
use crate::ClientResult;
pub struct Payroll {
pub client: Client,
}
impl Payroll {
#[doc(hidden)]
pub fn new(client: Client) -> Self {
Payroll { client }
}
/**
* Get pay periods for a company.
*
* This function performs a `GET` to the `/v1/companies/{company_id_or_uuid}/pay_periods` endpoint.
*
* Pay periods are the foundation of payroll. Compensation, time & attendance, taxes, and expense reports all rely on when they happened. To begin submitting information for a given payroll, we need to agree on the time period.
*
*
* By default, this endpoint returns every current and past pay period for a company. Since companies can process payroll as often as every week, there can be up to 53 pay periods a year. If a company has been running payroll with Gusto for five years, this endpoint could return up to 265 pay periods. Use the `start_date` and `end_date` parameters to reduce the scope of the response.
*
* **Parameters:**
*
* * `start_date: &str`
* * `end_date: &str`
*/
pub async fn get_company_pay_periods(
&self,
company_id_or_uuid: &str,
start_date: &str,
end_date: &str,
) -> ClientResult<crate::Response<Vec<crate::types::PayPeriod>>> {
let mut query_args: Vec<(String, String)> = Default::default();
if !end_date.is_empty() {
query_args.push(("end_date".to_string(), end_date.to_string()));
}
if !start_date.is_empty() {
query_args.push(("start_date".to_string(), start_date.to_string()));
}
let query_ = serde_urlencoded::to_string(&query_args).unwrap();
let url = self.client.url(
&format!(
"/v1/companies/{}/pay_periods?{}",
crate::progenitor_support::encode_path(company_id_or_uuid),
query_
),
None,
);
self.client
.get(
&url,
crate::Message {
body: None,
content_type: None,
},
)
.await
}
/**
* Get pay periods for a company.
*
* This function performs a `GET` to the `/v1/companies/{company_id_or_uuid}/pay_periods` endpoint.
*
* As opposed to `get_company_pay_periods`, this function returns all the pages of the request at once.
*
* Pay periods are the foundation of payroll. Compensation, time & attendance, taxes, and expense reports all rely on when they happened. To begin submitting information for a given payroll, we need to agree on the time period.
*
*
* By default, this endpoint returns every current and past pay period for a company. Since companies can process payroll as often as every week, there can be up to 53 pay periods a year. If a company has been running payroll with Gusto for five years, this endpoint could return up to 265 pay periods. Use the `start_date` and `end_date` parameters to reduce the scope of the response.
*/
pub async fn get_all_company_pay_periods(
&self,
company_id_or_uuid: &str,
start_date: &str,
end_date: &str,
) -> ClientResult<crate::Response<Vec<crate::types::PayPeriod>>> {
let mut query_args: Vec<(String, String)> = Default::default();
if !end_date.is_empty() {
query_args.push(("end_date".to_string(), end_date.to_string()));
}
if !start_date.is_empty() {
query_args.push(("start_date".to_string(), start_date.to_string()));
}
let query_ = serde_urlencoded::to_string(&query_args).unwrap();
let url = self.client.url(
&format!(
"/v1/companies/{}/pay_periods?{}",
crate::progenitor_support::encode_path(company_id_or_uuid),
query_
),
None,
);
self.client
.get_all_pages(
&url,
crate::Message {
body: None,
content_type: None,
},
)
.await
}
/**
* Get all payrolls for a company.
*
* This function performs a `GET` to the `/v1/companies/{company_id_or_uuid}/payrolls` endpoint.
*
* Returns all payrolls, current and past for a company.
*
* Notes:
* * Hour and dollar amounts are returned as string representations of numeric decimals.
* * Hours are represented to the thousands place; dollar amounts are represented to the cent.
* * Every eligible compensation is returned for each employee. If no data has yet be inserted for a given field, it defaults to “0.00” (for fixed amounts) or “0.000” (for hours ).
*
* **Parameters:**
*
* * `processed: bool` -- Whether to return processed or unprocessed payrolls.
* * `include_off_cycle: bool` -- Whether to include off cycle payrolls in the response.
* * `include: &[String]` -- Include the requested attribute in the employee_compensations attribute in the response.
* * `start_date: &str` -- Return payrolls whose pay period is after the start date.
* * `end_date: &str` -- Return payrolls whose pay period is before the end date.
*/
pub async fn get_company(
&self,
company_id_or_uuid: &str,
processed: bool,
include_off_cycle: bool,
include: &[String],
start_date: &str,
end_date: &str,
) -> ClientResult<crate::Response<Vec<crate::types::PayrollData>>> {
let mut query_args: Vec<(String, String)> = Default::default();
if !end_date.is_empty() {
query_args.push(("end_date".to_string(), end_date.to_string()));
}
if !include.is_empty() {
query_args.push(("include".to_string(), include.join(" ")));
}
if include_off_cycle {
query_args.push((
"include_off_cycle".to_string(),
include_off_cycle.to_string(),
));
}
if processed {
query_args.push(("processed".to_string(), processed.to_string()));
}
if !start_date.is_empty() {
query_args.push(("start_date".to_string(), start_date.to_string()));
}
let query_ = serde_urlencoded::to_string(&query_args).unwrap();
let url = self.client.url(
&format!(
"/v1/companies/{}/payrolls?{}",
crate::progenitor_support::encode_path(company_id_or_uuid),
query_
),
None,
);
self.client
.get(
&url,
crate::Message {
body: None,
content_type: None,
},
)
.await
}
/**
* Get all payrolls for a company.
*
* This function performs a `GET` to the `/v1/companies/{company_id_or_uuid}/payrolls` endpoint.
*
* As opposed to `get_company`, this function returns all the pages of the request at once.
*
* Returns all payrolls, current and past for a company.
*
* Notes:
* * Hour and dollar amounts are returned as string representations of numeric decimals.
* * Hours are represented to the thousands place; dollar amounts are represented to the cent.
* * Every eligible compensation is returned for each employee. If no data has yet be inserted for a given field, it defaults to “0.00” (for fixed amounts) or “0.000” (for hours ).
*/
pub async fn get_all_company(
&self,
company_id_or_uuid: &str,
processed: bool,
include_off_cycle: bool,
include: &[String],
start_date: &str,
end_date: &str,
) -> ClientResult<crate::Response<Vec<crate::types::PayrollData>>> {
let mut query_args: Vec<(String, String)> = Default::default();
if !end_date.is_empty() {
query_args.push(("end_date".to_string(), end_date.to_string()));
}
if !include.is_empty() {
query_args.push(("include".to_string(), include.join(" ")));
}
if include_off_cycle {
query_args.push((
"include_off_cycle".to_string(),
include_off_cycle.to_string(),
));
}
if processed {
query_args.push(("processed".to_string(), processed.to_string()));
}
if !start_date.is_empty() {
query_args.push(("start_date".to_string(), start_date.to_string()));
}
let query_ = serde_urlencoded::to_string(&query_args).unwrap();
let url = self.client.url(
&format!(
"/v1/companies/{}/payrolls?{}",
crate::progenitor_support::encode_path(company_id_or_uuid),
query_
),
None,
);
self.client
.get_all_pages(
&url,
crate::Message {
body: None,
content_type: None,
},
)
.await
}
/**
* Create an Off-Cycle Payroll (Beta).
*
* This function performs a `POST` to the `/v1/companies/{company_id_or_uuid}/payrolls` endpoint.
*
* This endpoint is in beta and intended for **[Gusto Embedded Payroll](https://gusto.com/embedded-payroll)** customers. Please [apply for early access](https://gusto-embedded-payroll.typeform.com/to/iomAQIj3?utm_source=docs) if you’d like to learn more and use it for production. Note, this endpoint will require you to enter a different agreement with Gusto.
*
* Creates a new, unprocessed, off-cycle payroll.
*/
pub async fn post_company(
&self,
company_id_or_uuid: &str,
body: &crate::types::PostCompanyPayrollsRequest,
) -> ClientResult<crate::Response<crate::types::PayrollData>> {
let url = self.client.url(
&format!(
"/v1/companies/{}/payrolls",
crate::progenitor_support::encode_path(company_id_or_uuid),
),
None,
);
self.client
.post(
&url,
crate::Message {
body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
content_type: Some("application/json".to_string()),
},
)
.await
}
/**
* Get a single payroll.
*
* This function performs a `GET` to the `/v1/companies/{company_id_or_uuid}/payrolls/{payroll_id_or_uuid}` endpoint.
*
* Returns a payroll.
*
* Notes:
* * Hour and dollar amounts are returned as string representations of numeric decimals.
* * Hours are represented to the thousands place; dollar amounts are represented to the cent.
* * Every eligible compensation is returned for each employee. If no data has yet be inserted for a given field, it defaults to “0.00” (for fixed amounts) or “0.000” (for hours ).
*
* **Parameters:**
*
* * `include: crate::types::GetCompanyPayrollsInclude` -- Include the requested attribute in the employee_compensations attribute in the response.
* * `show_calculation: &str` -- with `include`, shows the tax, and/or benefit, and/or deduction details for a calculated, unprocessed payroll. .
*/
pub async fn get_company_payroll(
&self,
company_id_or_uuid: &str,
payroll_id_or_uuid: &str,
include: crate::types::GetCompanyPayrollsInclude,
show_calculation: &str,
) -> ClientResult<crate::Response<crate::types::PayrollData>> {
let mut query_args: Vec<(String, String)> = Default::default();
if !include.to_string().is_empty() {
query_args.push(("include".to_string(), include.to_string()));
}
if !show_calculation.is_empty() {
query_args.push(("show_calculation".to_string(), show_calculation.to_string()));
}
let query_ = serde_urlencoded::to_string(&query_args).unwrap();
let url = self.client.url(
&format!(
"/v1/companies/{}/payrolls/{}?{}",
crate::progenitor_support::encode_path(company_id_or_uuid),
crate::progenitor_support::encode_path(payroll_id_or_uuid),
query_
),
None,
);
self.client
.get(
&url,
crate::Message {
body: None,
content_type: None,
},
)
.await
}
/**
* Update a payroll by ID.
*
* This function performs a `PUT` to the `/v1/companies/{company_id_or_uuid}/payrolls/{payroll_id_or_uuid}` endpoint.
*
* This endpoint allows you to update information for one or more employees for a specific **unprocessed** payroll.
*/
pub async fn put_company(
&self,
company_id_or_uuid: &str,
payroll_id_or_uuid: &str,
body: &crate::types::PutCompanyPayrollsRequest,
) -> ClientResult<crate::Response<crate::types::PayrollData>> {
let url = self.client.url(
&format!(
"/v1/companies/{}/payrolls/{}",
crate::progenitor_support::encode_path(company_id_or_uuid),
crate::progenitor_support::encode_path(payroll_id_or_uuid),
),
None,
);
self.client
.put(
&url,
crate::Message {
body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
content_type: Some("application/json".to_string()),
},
)
.await
}
/**
* Update a payroll.
*
* This function performs a `PUT` to the `/v1/companies/{company_id_or_uuid}/payrolls/{pay_period_start_date}/{pay_period_end_date}` endpoint.
*
* This endpoint allows you to update information for one or more employees for a specific **unprocessed** payroll.
*
* The payrolls are identified by their pay periods’ start_date and end_date. Both are required and must correspond with an existing, unprocessed payroll. *If the dates do not match, the entire request will be rejected.* This was an explicit design decision to remove any assumptions around the timespan for data sent.
*/
pub async fn put_company_pay_period_start_date_end(
&self,
company_id_or_uuid: &str,
pay_period_start_date: &str,
pay_period_end_date: &str,
body: &crate::types::PutCompanyPayrollsRequest,
) -> ClientResult<crate::Response<crate::types::PayrollData>> {
let url = self.client.url(
&format!(
"/v1/companies/{}/payrolls/{}/{}",
crate::progenitor_support::encode_path(company_id_or_uuid),
crate::progenitor_support::encode_path(pay_period_start_date),
crate::progenitor_support::encode_path(pay_period_end_date),
),
None,
);
self.client
.put(
&url,
crate::Message {
body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
content_type: Some("application/json".to_string()),
},
)
.await
}
/**
* Calculate a Payroll (Beta).
*
* This function performs a `PUT` to the `/v1/companies/{company_id}/payrolls/{payroll_id}/calculate` endpoint.
*
* This endpoint is in beta and intended for **[Gusto Embedded Payroll](https://gusto.com/embedded-payroll)** customers. Please [apply for early access](https://gusto-embedded-payroll.typeform.com/to/iomAQIj3?utm_source=docs) if you’d like to learn more and use it for production. Note, this endpoint will require you to enter a different agreement with Gusto.
*
* Performs calculations for taxes, benefits, and deductions for an unprocessed payroll. The calculated payroll details provide a preview of the actual values that will be used when the payroll is run.
*
* This endpoint is asynchronous and responds with only a 202 HTTP status. To view the details of the calculated payroll, use the GET /v1/companies/{company_id}/payrolls/{payroll_id} endpoint with the *show_calculation=true* and *include=taxes,benefits,deductions* params
*/
pub async fn put_company_calculate(
&self,
company_id: &str,
payroll_id: &str,
) -> ClientResult<crate::Response<()>> {
let url = self.client.url(
&format!(
"/v1/companies/{}/payrolls/{}/calculate",
crate::progenitor_support::encode_path(company_id),
crate::progenitor_support::encode_path(payroll_id),
),
None,
);
self.client
.put(
&url,
crate::Message {
body: None,
content_type: None,
},
)
.await
}
/**
* Submit Payroll (Beta).
*
* This function performs a `PUT` to the `/v1/companies/{company_id}/payrolls/{payroll_Id}/submit` endpoint.
*
* This endpoint is in beta and intended for **[Gusto Embedded Payroll](https://gusto.com/embedded-payroll)** customers. Please [apply for early access](https://gusto-embedded-payroll.typeform.com/to/iomAQIj3?utm_source=docs) if you’d like to learn more and use it for production. Note, this endpoint will require you to enter a different agreement with Gusto.
*
* Submits an unprocessed payroll to be calculated and run. Upon success, transitions the payroll to the `processed` state.
*/
pub async fn put_company_submit(
&self,
company_id: &str,
payroll_id: &str,
) -> ClientResult<crate::Response<()>> {
let url = self.client.url(
&format!(
"/v1/companies/{}/payrolls/{}/submit",
crate::progenitor_support::encode_path(company_id),
crate::progenitor_support::encode_path(payroll_id),
),
None,
);
self.client
.put(
&url,
crate::Message {
body: None,
content_type: None,
},
)
.await
}
/**
* Cancel a Payroll (Beta).
*
* This function performs a `PUT` to the `/v1/companies/{company_id}/payrolls/{payroll_id}/cancel` endpoint.
*
* This endpoint is in beta and intended for **[Gusto Embedded Payroll](https://gusto.com/embedded-payroll)** customers. Please [apply for early access](https://gusto-embedded-payroll.typeform.com/to/iomAQIj3?utm_source=docs) if you’d like to learn more and use it for production. Note, this endpoint will require you to enter a different agreement with Gusto.
*
* Transitions a `processed` payroll back to the `unprocessed` state. A payroll cannot be canceled once it has entered the `funded` state.
*
*/
pub async fn put_company_cancel(
&self,
company_id: &str,
payroll_id: &str,
) -> ClientResult<crate::Response<crate::types::PayrollData>> {
let url = self.client.url(
&format!(
"/v1/companies/{}/payrolls/{}/cancel",
crate::progenitor_support::encode_path(company_id),
crate::progenitor_support::encode_path(payroll_id),
),
None,
);
self.client
.put(
&url,
crate::Message {
body: None,
content_type: None,
},
)
.await
}
/**
* Get approved Payroll Reversals.
*
* This function performs a `GET` to the `/v1/companies/{company_id_or_uuid}/payroll_reversals` endpoint.
*
* Returns all approved Payroll Reversals for a Company.
*/
pub async fn get_company_or_reversals(
&self,
company_id_or_uuid: &str,
) -> ClientResult<crate::Response<crate::types::GetCompanyPayrollReversalsResponse>> {
let url = self.client.url(
&format!(
"/v1/companies/{}/payroll_reversals",
crate::progenitor_support::encode_path(company_id_or_uuid),
),
None,
);
self.client
.get(
&url,
crate::Message {
body: None,
content_type: None,
},
)
.await
}
}