1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateReceiptError {
22 Status400(crate::models::BadRequestError),
23 Status401(crate::models::UnauthorizedError),
24 Status403(crate::models::ForbiddenError),
25 Status500(crate::models::InternalServerError),
26 UnknownValue(serde_json::Value),
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum DestroyReceiptError {
33 Status400(crate::models::BadRequestError),
34 Status401(crate::models::UnauthorizedError),
35 Status403(crate::models::ForbiddenError),
36 Status404(crate::models::BadRequestNotFoundError),
37 Status500(crate::models::InternalServerError),
38 UnknownValue(serde_json::Value),
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(untagged)]
44pub enum DownloadReceiptError {
45 Status400(crate::models::BadRequestError),
46 Status401(crate::models::UnauthorizedError),
47 Status403(crate::models::ForbiddenError),
48 Status404(crate::models::BadRequestNotFoundError),
49 Status500(crate::models::InternalServerError),
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetReceiptError {
57 Status400(crate::models::BadRequestError),
58 Status401(crate::models::UnauthorizedError),
59 Status403(crate::models::ForbiddenError),
60 Status404(crate::models::BadRequestNotFoundError),
61 Status500(crate::models::InternalServerError),
62 UnknownValue(serde_json::Value),
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
67#[serde(untagged)]
68pub enum GetReceiptsError {
69 Status400(crate::models::BadRequestError),
70 Status401(crate::models::UnauthorizedError),
71 Status403(crate::models::ForbiddenError),
72 Status500(crate::models::InternalServerError),
73 UnknownValue(serde_json::Value),
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum UpdateReceiptError {
80 Status400(crate::models::BadRequestError),
81 Status401(crate::models::UnauthorizedError),
82 Status403(crate::models::ForbiddenError),
83 Status404(crate::models::BadRequestNotFoundError),
84 Status500(crate::models::InternalServerError),
85 UnknownValue(serde_json::Value),
86}
87
88
89pub async fn create_receipt(configuration: &configuration::Configuration, company_id: i32, receipt: std::path::PathBuf, description: Option<&str>, issue_date: Option<&str>, receipt_metadatum_partner_name: Option<&str>, receipt_metadatum_issue_date: Option<&str>, receipt_metadatum_amount: Option<i64>, qualified_invoice: Option<&str>, document_type: Option<&str>) -> Result<crate::models::ReceiptResponse, Error<CreateReceiptError>> {
91 let local_var_configuration = configuration;
92
93 let local_var_client = &local_var_configuration.client;
94
95 let local_var_uri_str = format!("{}/api/1/receipts", local_var_configuration.base_path);
96 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
97
98 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
99 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
100 }
101 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
102 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
103 };
104 let mut local_var_form = reqwest::multipart::Form::new();
105 local_var_form = local_var_form.text("company_id", company_id.to_string());
106 if let Some(local_var_param_value) = description {
107 local_var_form = local_var_form.text("description", local_var_param_value.to_string());
108 }
109 if let Some(local_var_param_value) = issue_date {
110 local_var_form = local_var_form.text("issue_date", local_var_param_value.to_string());
111 }
112 if let Some(local_var_param_value) = receipt_metadatum_partner_name {
114 local_var_form = local_var_form.text("receipt_metadatum_partner_name", local_var_param_value.to_string());
115 }
116 if let Some(local_var_param_value) = receipt_metadatum_issue_date {
117 local_var_form = local_var_form.text("receipt_metadatum_issue_date", local_var_param_value.to_string());
118 }
119 if let Some(local_var_param_value) = receipt_metadatum_amount {
120 local_var_form = local_var_form.text("receipt_metadatum_amount", local_var_param_value.to_string());
121 }
122 if let Some(local_var_param_value) = qualified_invoice {
123 local_var_form = local_var_form.text("qualified_invoice", local_var_param_value.to_string());
124 }
125 if let Some(local_var_param_value) = document_type {
126 local_var_form = local_var_form.text("document_type", local_var_param_value.to_string());
127 }
128 local_var_req_builder = local_var_req_builder.multipart(local_var_form);
129
130 let local_var_req = local_var_req_builder.build()?;
131 let local_var_resp = local_var_client.execute(local_var_req).await?;
132
133 let local_var_status = local_var_resp.status();
134 let local_var_content = local_var_resp.text().await?;
135
136 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
137 serde_json::from_str(&local_var_content).map_err(Error::from)
138 } else {
139 let local_var_entity: Option<CreateReceiptError> = serde_json::from_str(&local_var_content).ok();
140 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
141 Err(Error::ResponseError(local_var_error))
142 }
143}
144
145pub async fn destroy_receipt(configuration: &configuration::Configuration, id: i32, company_id: i32) -> Result<(), Error<DestroyReceiptError>> {
147 let local_var_configuration = configuration;
148
149 let local_var_client = &local_var_configuration.client;
150
151 let local_var_uri_str = format!("{}/api/1/receipts/{id}", local_var_configuration.base_path, id=id);
152 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
153
154 local_var_req_builder = local_var_req_builder.query(&[("company_id", &company_id.to_string())]);
155 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
156 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
157 }
158 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
159 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
160 };
161
162 let local_var_req = local_var_req_builder.build()?;
163 let local_var_resp = local_var_client.execute(local_var_req).await?;
164
165 let local_var_status = local_var_resp.status();
166 let local_var_content = local_var_resp.text().await?;
167
168 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
169 Ok(())
170 } else {
171 let local_var_entity: Option<DestroyReceiptError> = serde_json::from_str(&local_var_content).ok();
172 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
173 Err(Error::ResponseError(local_var_error))
174 }
175}
176
177pub async fn download_receipt(configuration: &configuration::Configuration, id: i32, company_id: i32) -> Result<String, Error<DownloadReceiptError>> {
179 let local_var_configuration = configuration;
180
181 let local_var_client = &local_var_configuration.client;
182
183 let local_var_uri_str = format!("{}/api/1/receipts/{id}/download", local_var_configuration.base_path, id=id);
184 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
185
186 local_var_req_builder = local_var_req_builder.query(&[("company_id", &company_id.to_string())]);
187 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
188 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
189 }
190 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
191 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
192 };
193
194 let local_var_req = local_var_req_builder.build()?;
195 let local_var_resp = local_var_client.execute(local_var_req).await?;
196
197 let local_var_status = local_var_resp.status();
198 let local_var_content = local_var_resp.text().await?;
199
200 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
201 serde_json::from_str(&local_var_content).map_err(Error::from)
202 } else {
203 let local_var_entity: Option<DownloadReceiptError> = serde_json::from_str(&local_var_content).ok();
204 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
205 Err(Error::ResponseError(local_var_error))
206 }
207}
208
209pub async fn get_receipt(configuration: &configuration::Configuration, id: i32, company_id: i32) -> Result<crate::models::ReceiptResponse, Error<GetReceiptError>> {
211 let local_var_configuration = configuration;
212
213 let local_var_client = &local_var_configuration.client;
214
215 let local_var_uri_str = format!("{}/api/1/receipts/{id}", local_var_configuration.base_path, id=id);
216 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
217
218 local_var_req_builder = local_var_req_builder.query(&[("company_id", &company_id.to_string())]);
219 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
220 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
221 }
222 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
223 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
224 };
225
226 let local_var_req = local_var_req_builder.build()?;
227 let local_var_resp = local_var_client.execute(local_var_req).await?;
228
229 let local_var_status = local_var_resp.status();
230 let local_var_content = local_var_resp.text().await?;
231
232 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
233 serde_json::from_str(&local_var_content).map_err(Error::from)
234 } else {
235 let local_var_entity: Option<GetReceiptError> = serde_json::from_str(&local_var_content).ok();
236 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
237 Err(Error::ResponseError(local_var_error))
238 }
239}
240
241pub async fn get_receipts(configuration: &configuration::Configuration, company_id: i32, start_date: &str, end_date: &str, user_name: Option<&str>, number: Option<i32>, comment_type: Option<&str>, comment_important: Option<bool>, category: Option<&str>, offset: Option<i64>, limit: Option<i32>) -> Result<crate::models::GetReceipts200Response, Error<GetReceiptsError>> {
243 let local_var_configuration = configuration;
244
245 let local_var_client = &local_var_configuration.client;
246
247 let local_var_uri_str = format!("{}/api/1/receipts", local_var_configuration.base_path);
248 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
249
250 local_var_req_builder = local_var_req_builder.query(&[("company_id", &company_id.to_string())]);
251 local_var_req_builder = local_var_req_builder.query(&[("start_date", &start_date.to_string())]);
252 local_var_req_builder = local_var_req_builder.query(&[("end_date", &end_date.to_string())]);
253 if let Some(ref local_var_str) = user_name {
254 local_var_req_builder = local_var_req_builder.query(&[("user_name", &local_var_str.to_string())]);
255 }
256 if let Some(ref local_var_str) = number {
257 local_var_req_builder = local_var_req_builder.query(&[("number", &local_var_str.to_string())]);
258 }
259 if let Some(ref local_var_str) = comment_type {
260 local_var_req_builder = local_var_req_builder.query(&[("comment_type", &local_var_str.to_string())]);
261 }
262 if let Some(ref local_var_str) = comment_important {
263 local_var_req_builder = local_var_req_builder.query(&[("comment_important", &local_var_str.to_string())]);
264 }
265 if let Some(ref local_var_str) = category {
266 local_var_req_builder = local_var_req_builder.query(&[("category", &local_var_str.to_string())]);
267 }
268 if let Some(ref local_var_str) = offset {
269 local_var_req_builder = local_var_req_builder.query(&[("offset", &local_var_str.to_string())]);
270 }
271 if let Some(ref local_var_str) = limit {
272 local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
273 }
274 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
275 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
276 }
277 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
278 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
279 };
280
281 let local_var_req = local_var_req_builder.build()?;
282 let local_var_resp = local_var_client.execute(local_var_req).await?;
283
284 let local_var_status = local_var_resp.status();
285 let local_var_content = local_var_resp.text().await?;
286
287 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
288 serde_json::from_str(&local_var_content).map_err(Error::from)
289 } else {
290 let local_var_entity: Option<GetReceiptsError> = serde_json::from_str(&local_var_content).ok();
291 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
292 Err(Error::ResponseError(local_var_error))
293 }
294}
295
296pub async fn update_receipt(configuration: &configuration::Configuration, id: i32, receipt_update_params: crate::models::ReceiptUpdateParams) -> Result<crate::models::ReceiptResponse, Error<UpdateReceiptError>> {
298 let local_var_configuration = configuration;
299
300 let local_var_client = &local_var_configuration.client;
301
302 let local_var_uri_str = format!("{}/api/1/receipts/{id}", local_var_configuration.base_path, id=id);
303 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
304
305 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
306 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
307 }
308 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
309 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
310 };
311 local_var_req_builder = local_var_req_builder.json(&receipt_update_params);
312
313 let local_var_req = local_var_req_builder.build()?;
314 let local_var_resp = local_var_client.execute(local_var_req).await?;
315
316 let local_var_status = local_var_resp.status();
317 let local_var_content = local_var_resp.text().await?;
318
319 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
320 serde_json::from_str(&local_var_content).map_err(Error::from)
321 } else {
322 let local_var_entity: Option<UpdateReceiptError> = serde_json::from_str(&local_var_content).ok();
323 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
324 Err(Error::ResponseError(local_var_error))
325 }
326}
327