avina_wire/budgeting/
project_budget.rs1use std::fmt::Display;
2
3use chrono::{DateTime, FixedOffset};
4use serde::{Deserialize, Serialize};
5#[cfg(feature = "sqlx")]
6use sqlx::FromRow;
7#[cfg(feature = "tabled")]
8use tabled::Tabled;
9
10use crate::common::is_false;
11
12#[cfg_attr(feature = "sqlx", derive(FromRow))]
13#[cfg_attr(feature = "tabled", derive(Tabled))]
14#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
15pub struct ProjectBudget {
16 #[cfg_attr(feature = "sqlx", sqlx(try_from = "i32"))]
17 pub id: u32,
18 #[cfg_attr(feature = "sqlx", sqlx(try_from = "i32"))]
19 pub project: u32,
20 pub project_name: String,
21 pub year: u32,
22 pub amount: u32,
23}
24
25impl Display for ProjectBudget {
26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27 f.write_str(&format!("ProjectBudget(id={})", self.id))
28 }
29}
30
31#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)]
32pub struct ProjectBudgetListParams {
33 pub user: Option<u32>,
34 pub project: Option<u32>,
35 pub all: Option<bool>,
36 pub year: Option<u32>,
37}
38
39#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)]
40pub struct ProjectBudgetOverParams {
41 pub end: Option<DateTime<FixedOffset>>,
42 pub budget: Option<u32>,
43 pub project: Option<u32>,
44 pub all: Option<bool>,
45 pub detail: Option<bool>,
46}
47
48#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
49pub struct ProjectBudgetCreateData {
50 pub project: u32,
51 #[serde(skip_serializing_if = "Option::is_none")]
52 pub year: Option<u32>,
53 #[serde(skip_serializing_if = "Option::is_none")]
54 pub amount: Option<i64>,
55}
56
57impl ProjectBudgetCreateData {
58 pub fn new(project: u32) -> Self {
59 Self {
60 project,
61 year: None,
62 amount: None,
63 }
64 }
65}
66
67#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
68pub struct ProjectBudgetModifyData {
69 pub id: u32,
70
71 #[serde(skip_serializing_if = "Option::is_none")]
72 pub amount: Option<u32>,
73 #[serde(default, skip_serializing_if = "is_false")]
74 pub force: bool,
75}
76
77impl ProjectBudgetModifyData {
78 pub fn new(id: u32) -> Self {
79 Self {
80 id,
81 amount: None,
82 force: false,
83 }
84 }
85}
86
87#[cfg_attr(feature = "tabled", derive(Tabled))]
88#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
89pub struct ProjectBudgetOverSimple {
90 pub budget_id: u32,
91 pub project_id: u32,
92 pub project_name: String,
93 pub over: bool,
94}
95
96#[cfg_attr(feature = "tabled", derive(Tabled))]
97#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
98pub struct ProjectBudgetOverDetail {
99 pub budget_id: u32,
100 pub project_id: u32,
101 pub project_name: String,
102 pub over: bool,
103 pub cost: f64,
104 pub budget: u32,
105}