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
use crate::api::*;
use crate::{ApiError, ClientConfig, HttpClient, RequestOptions};
use reqwest::Method;
pub struct FleetClient {
pub http_client: HttpClient,
}
impl FleetClient {
pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
Ok(Self {
http_client: HttpClient::new(config.clone())?,
})
}
/// Register a vehicle. The plate number is stored in upper case and must be unique in the company (409 otherwise); `fixedAssetId` must name an existing fixed asset. Uploaded `documents` are attached to the vehicle.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn vehicles_create(
&self,
request: &VehiclesCreateFleetRequest,
options: Option<RequestOptions>,
) -> Result<VehiclesCreateFleetResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
"v1/fleet/vehicles/create",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// Change a vehicle's details or set its `status` to `active`, `sold` or `scrapped`; omitted fields keep their value. A plate number already used by another vehicle is refused with 409.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn vehicles_update(
&self,
request: &VehiclesUpdateFleetRequest,
options: Option<RequestOptions>,
) -> Result<VehiclesUpdateFleetResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
"v1/fleet/vehicles/update",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// Read one vehicle with its current assignment, when an employee holds it today.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn vehicles_get(
&self,
request: &VehiclesGetFleetRequest,
options: Option<RequestOptions>,
) -> Result<VehiclesGetFleetResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
"v1/fleet/vehicles/get",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// List vehicles with their current assignment. Filterable by `plateNumber`, `make`, `model` and `status`; sortable by `plateNumber`, `make` and `createdAt`.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn vehicles_list(
&self,
request: &VehiclesListFleetRequest,
options: Option<RequestOptions>,
) -> Result<VehiclesListFleetResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
"v1/fleet/vehicles/list",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// Assign a vehicle to an employee from `fromDate`, open-ended or until `toDate`. A period that overlaps another assignment of the same vehicle is refused with 409, a `toDate` before `fromDate` with 422. `privateUse` makes the car a benefit in kind in `fleet/natura/preview`, and `employerPaysFuel` picks its rate.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn assignments_create(
&self,
request: &AssignmentsCreateFleetRequest,
options: Option<RequestOptions>,
) -> Result<AssignmentsCreateFleetResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
"v1/fleet/assignments/create",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// End an open assignment on `toDate`. An assignment that already has an end date is refused with 409, a `toDate` before its `fromDate` with 422.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn assignments_end(
&self,
request: &AssignmentsEndFleetRequest,
options: Option<RequestOptions>,
) -> Result<AssignmentsEndFleetResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
"v1/fleet/assignments/end",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// List vehicle assignments with the plate number and the employee's name. Filterable by `vehicleId`, `employeeId` and `privateUse`; sortable by `fromDate` and `createdAt`.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn assignments_list(
&self,
request: &AssignmentsListFleetRequest,
options: Option<RequestOptions>,
) -> Result<AssignmentsListFleetResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
"v1/fleet/assignments/list",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// Preview the car benefit in kind of a month for a Lithuanian company: every assignment with `privateUse` that overlaps the month is valued at 0.75 % of the vehicle's market value when the employer pays the fuel, else 0.70 %, one row per employee and vehicle, with the total. A company registered in another country is refused with 422. The same amounts are added to a payroll run created with `includeNatura` (`payroll/runs/create`).
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn natura_preview(
&self,
request: &NaturaPreviewFleetRequest,
options: Option<RequestOptions>,
) -> Result<NaturaPreviewFleetResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
"v1/fleet/natura/preview",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
}