rust_woocommerce/models/
reports.rs

1use crate::controllers::Entity;
2use chrono::NaiveDate;
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct Report {
7    pub slug: String,
8    pub description: String,
9}
10impl Entity for Report {
11    fn endpoint() -> String {
12        String::from("reports/")
13    }
14
15    fn child_endpoint(parent_id: i32) -> String {
16        let _ = parent_id;
17        String::new()
18    }
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct SaleReport {
23    /// Gross sales in the period.
24    pub total_sales: String,
25    /// Net sales in the period.
26    pub net_sales: String,
27    /// Average net daily sales.
28    pub average_sales: String,
29    /// Total of orders placed.
30    pub total_orders: i32,
31    /// Total of items purchased.
32    pub total_items: i32,
33    /// Total charged for taxes.
34    pub total_tax: String,
35    /// Total charged for shipping.
36    pub total_shipping: String,
37    /// Total of refunded orders.
38    pub total_refunds: i32,
39    /// Total of coupons used.
40    pub total_discount: String,
41    /// Group type.
42    pub totals_grouped_by: String,
43    /// Totals.
44    pub totals: std::collections::HashMap<NaiveDate, Total>,
45    pub total_customers: i32,
46}
47impl Entity for SaleReport {
48    fn endpoint() -> String {
49        String::from("reports/sales/")
50    }
51
52    fn child_endpoint(parent_id: i32) -> String {
53        let _ = parent_id;
54        String::new()
55    }
56}
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct Total {
59    pub sales: String,
60    pub orders: i32,
61    pub items: i32,
62    pub tax: String,
63    pub shipping: String,
64    pub discount: String,
65    pub customers: i32,
66}
67#[derive(Debug, Clone, Serialize, Deserialize)]
68pub struct TopSellersReport {
69    /// Product title.
70    pub name: String,
71    /// Product ID.
72    pub product_id: i32,
73    /// Total number of purchases.
74    pub quantity: i32,
75}
76
77impl Entity for TopSellersReport {
78    fn endpoint() -> String {
79        String::from("reports/top_sellers/")
80    }
81
82    fn child_endpoint(parent_id: i32) -> String {
83        let _ = parent_id;
84        String::new()
85    }
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
89pub struct ReportOrdersTotals {
90    pub slug: String,
91    pub name: String,
92    pub total: i32,
93}
94impl Entity for ReportOrdersTotals {
95    fn endpoint() -> String {
96        String::from("reports/orders/totals/")
97    }
98
99    fn child_endpoint(parent_id: i32) -> String {
100        let _ = parent_id;
101        String::new()
102    }
103}