fiscal_core/tax_icms/data.rs
1//! ICMS data structures: IcmsPartData, IcmsStData, IcmsUfDestData.
2
3use crate::newtypes::{Cents, Rate};
4
5/// Data for building the ICMSPart XML group (ICMS partition between states).
6///
7/// Used for interstate operations where the ICMS is split between origin and
8/// destination states.
9#[derive(Debug, Clone)]
10#[non_exhaustive]
11pub struct IcmsPartData {
12 /// Product origin code (`orig`).
13 pub orig: String,
14 /// ICMS CST code.
15 pub cst: String,
16 /// Base calculation modality (`modBC`).
17 pub mod_bc: String,
18 /// ICMS calculation base value (`vBC`).
19 pub v_bc: Cents,
20 /// Base reduction rate (`pRedBC`). Optional.
21 pub p_red_bc: Option<Rate>,
22 /// ICMS rate (`pICMS`).
23 pub p_icms: Rate,
24 /// ICMS value (`vICMS`).
25 pub v_icms: Cents,
26 /// ST base calculation modality (`modBCST`).
27 pub mod_bc_st: String,
28 /// ST added value margin (`pMVAST`). Optional.
29 pub p_mva_st: Option<Rate>,
30 /// ST base reduction rate (`pRedBCST`). Optional.
31 pub p_red_bc_st: Option<Rate>,
32 /// ST calculation base value (`vBCST`).
33 pub v_bc_st: Cents,
34 /// ST rate (`pICMSST`).
35 pub p_icms_st: Rate,
36 /// ST value (`vICMSST`).
37 pub v_icms_st: Cents,
38 /// FCP-ST calculation base (`vBCFCPST`). Optional.
39 pub v_bc_fcp_st: Option<Cents>,
40 /// FCP-ST rate (`pFCPST`). Optional.
41 pub p_fcp_st: Option<Rate>,
42 /// FCP-ST value (`vFCPST`). Optional.
43 pub v_fcp_st: Option<Cents>,
44 /// Partition percentage applied at origin state (`pBCOp`).
45 pub p_bc_op: Rate,
46 /// Destination state abbreviation for ST (`UFST`).
47 pub uf_st: String,
48 /// Desonerated ICMS value (`vICMSDeson`). Optional.
49 pub v_icms_deson: Option<Cents>,
50 /// Reason code for ICMS desoneration (`motDesICMS`). Optional.
51 pub mot_des_icms: Option<String>,
52 /// Indicator whether desoneration is deducted (`indDeduzDeson`). Optional.
53 pub ind_deduz_deson: Option<String>,
54}
55
56impl IcmsPartData {
57 /// Create a new `IcmsPartData` with all required fields.
58 #[allow(clippy::too_many_arguments)]
59 pub fn new(
60 orig: impl Into<String>,
61 cst: impl Into<String>,
62 mod_bc: impl Into<String>,
63 v_bc: Cents,
64 p_icms: Rate,
65 v_icms: Cents,
66 mod_bc_st: impl Into<String>,
67 v_bc_st: Cents,
68 p_icms_st: Rate,
69 v_icms_st: Cents,
70 p_bc_op: Rate,
71 uf_st: impl Into<String>,
72 ) -> Self {
73 Self {
74 orig: orig.into(),
75 cst: cst.into(),
76 mod_bc: mod_bc.into(),
77 v_bc,
78 p_red_bc: None,
79 p_icms,
80 v_icms,
81 mod_bc_st: mod_bc_st.into(),
82 p_mva_st: None,
83 p_red_bc_st: None,
84 v_bc_st,
85 p_icms_st,
86 v_icms_st,
87 v_bc_fcp_st: None,
88 p_fcp_st: None,
89 v_fcp_st: None,
90 p_bc_op,
91 uf_st: uf_st.into(),
92 v_icms_deson: None,
93 mot_des_icms: None,
94 ind_deduz_deson: None,
95 }
96 }
97 /// Set the ICMS base reduction rate (`pRedBC`).
98 pub fn p_red_bc(mut self, v: Rate) -> Self {
99 self.p_red_bc = Some(v);
100 self
101 }
102 /// Set the ST added value margin (`pMVAST`).
103 pub fn p_mva_st(mut self, v: Rate) -> Self {
104 self.p_mva_st = Some(v);
105 self
106 }
107 /// Set the ST base reduction rate (`pRedBCST`).
108 pub fn p_red_bc_st(mut self, v: Rate) -> Self {
109 self.p_red_bc_st = Some(v);
110 self
111 }
112 /// Set the FCP-ST calculation base (`vBCFCPST`).
113 pub fn v_bc_fcp_st(mut self, v: Cents) -> Self {
114 self.v_bc_fcp_st = Some(v);
115 self
116 }
117 /// Set the FCP-ST rate (`pFCPST`).
118 pub fn p_fcp_st(mut self, v: Rate) -> Self {
119 self.p_fcp_st = Some(v);
120 self
121 }
122 /// Set the FCP-ST value (`vFCPST`).
123 pub fn v_fcp_st(mut self, v: Cents) -> Self {
124 self.v_fcp_st = Some(v);
125 self
126 }
127 /// Set the desonerated ICMS value (`vICMSDeson`).
128 pub fn v_icms_deson(mut self, v: Cents) -> Self {
129 self.v_icms_deson = Some(v);
130 self
131 }
132 /// Set the ICMS desoneration reason code (`motDesICMS`).
133 pub fn mot_des_icms(mut self, v: impl Into<String>) -> Self {
134 self.mot_des_icms = Some(v.into());
135 self
136 }
137 /// Set the desoneration deduction indicator (`indDeduzDeson`).
138 pub fn ind_deduz_deson(mut self, v: impl Into<String>) -> Self {
139 self.ind_deduz_deson = Some(v.into());
140 self
141 }
142}
143
144/// Data for building the ICMSST XML group (ST repasse).
145///
146/// Used for CST 41 or 60 operations with ST transfer (`repasse`) between states.
147#[derive(Debug, Clone)]
148#[non_exhaustive]
149pub struct IcmsStData {
150 /// Product origin code (`orig`).
151 pub orig: String,
152 /// ICMS CST code.
153 pub cst: String,
154 /// ST retained calculation base (`vBCSTRet`).
155 pub v_bc_st_ret: Cents,
156 /// ST rate applied at retention (`pST`). Optional.
157 pub p_st: Option<Rate>,
158 /// ICMS value paid by the substitutor (`vICMSSubstituto`). Optional.
159 pub v_icms_substituto: Option<Cents>,
160 /// Retained ST ICMS value (`vICMSSTRet`).
161 pub v_icms_st_ret: Cents,
162 /// FCP-ST retained calculation base (`vBCFCPSTRet`). Optional.
163 pub v_bc_fcp_st_ret: Option<Cents>,
164 /// FCP-ST retained rate (`pFCPSTRet`). Optional.
165 pub p_fcp_st_ret: Option<Rate>,
166 /// FCP-ST retained value (`vFCPSTRet`). Optional.
167 pub v_fcp_st_ret: Option<Cents>,
168 /// ST calculation base for destination state (`vBCSTDest`).
169 pub v_bc_st_dest: Cents,
170 /// ICMS ST value for destination state (`vICMSSTDest`).
171 pub v_icms_st_dest: Cents,
172 /// Effective base reduction rate (`pRedBCEfet`). Optional.
173 pub p_red_bc_efet: Option<Rate>,
174 /// Effective calculation base (`vBCEfet`). Optional.
175 pub v_bc_efet: Option<Cents>,
176 /// Effective ICMS rate (`pICMSEfet`). Optional.
177 pub p_icms_efet: Option<Rate>,
178 /// Effective ICMS value (`vICMSEfet`). Optional.
179 pub v_icms_efet: Option<Cents>,
180}
181
182impl IcmsStData {
183 /// Create a new `IcmsStData` with required fields.
184 #[allow(clippy::too_many_arguments)]
185 pub fn new(
186 orig: impl Into<String>,
187 cst: impl Into<String>,
188 v_bc_st_ret: Cents,
189 v_icms_st_ret: Cents,
190 v_bc_st_dest: Cents,
191 v_icms_st_dest: Cents,
192 ) -> Self {
193 Self {
194 orig: orig.into(),
195 cst: cst.into(),
196 v_bc_st_ret,
197 p_st: None,
198 v_icms_substituto: None,
199 v_icms_st_ret,
200 v_bc_fcp_st_ret: None,
201 p_fcp_st_ret: None,
202 v_fcp_st_ret: None,
203 v_bc_st_dest,
204 v_icms_st_dest,
205 p_red_bc_efet: None,
206 v_bc_efet: None,
207 p_icms_efet: None,
208 v_icms_efet: None,
209 }
210 }
211 /// Set the ST rate at retention (`pST`).
212 pub fn p_st(mut self, v: Rate) -> Self {
213 self.p_st = Some(v);
214 self
215 }
216 /// Set the ICMS value paid by the substitutor (`vICMSSubstituto`).
217 pub fn v_icms_substituto(mut self, v: Cents) -> Self {
218 self.v_icms_substituto = Some(v);
219 self
220 }
221 /// Set the FCP-ST retained calculation base (`vBCFCPSTRet`).
222 pub fn v_bc_fcp_st_ret(mut self, v: Cents) -> Self {
223 self.v_bc_fcp_st_ret = Some(v);
224 self
225 }
226 /// Set the FCP-ST retained rate (`pFCPSTRet`).
227 pub fn p_fcp_st_ret(mut self, v: Rate) -> Self {
228 self.p_fcp_st_ret = Some(v);
229 self
230 }
231 /// Set the FCP-ST retained value (`vFCPSTRet`).
232 pub fn v_fcp_st_ret(mut self, v: Cents) -> Self {
233 self.v_fcp_st_ret = Some(v);
234 self
235 }
236 /// Set the effective base reduction rate (`pRedBCEfet`).
237 pub fn p_red_bc_efet(mut self, v: Rate) -> Self {
238 self.p_red_bc_efet = Some(v);
239 self
240 }
241 /// Set the effective calculation base (`vBCEfet`).
242 pub fn v_bc_efet(mut self, v: Cents) -> Self {
243 self.v_bc_efet = Some(v);
244 self
245 }
246 /// Set the effective ICMS rate (`pICMSEfet`).
247 pub fn p_icms_efet(mut self, v: Rate) -> Self {
248 self.p_icms_efet = Some(v);
249 self
250 }
251 /// Set the effective ICMS value (`vICMSEfet`).
252 pub fn v_icms_efet(mut self, v: Cents) -> Self {
253 self.v_icms_efet = Some(v);
254 self
255 }
256}
257
258/// Data for building the ICMSUFDest XML group (interstate destination).
259///
260/// Represents the ICMS differential (`DIFAL`) owed to the destination state
261/// for interstate B2C operations (EC 87/2015).
262#[derive(Debug, Clone)]
263#[non_exhaustive]
264pub struct IcmsUfDestData {
265 /// ICMS calculation base for destination state (`vBCUFDest`).
266 pub v_bc_uf_dest: Cents,
267 /// FCP calculation base for destination state (`vBCFCPUFDest`). Optional.
268 pub v_bc_fcp_uf_dest: Option<Cents>,
269 /// FCP rate for destination state (`pFCPUFDest`). Optional.
270 pub p_fcp_uf_dest: Option<Rate>,
271 /// Internal ICMS rate for destination state (`pICMSUFDest`).
272 pub p_icms_uf_dest: Rate,
273 /// Interstate ICMS rate (`pICMSInter`).
274 pub p_icms_inter: Rate,
275 /// FCP value for destination state (`vFCPUFDest`). Optional.
276 pub v_fcp_uf_dest: Option<Cents>,
277 /// ICMS value destined to destination state (`vICMSUFDest`).
278 pub v_icms_uf_dest: Cents,
279 /// ICMS value to be paid to origin state (`vICMSUFRemet`). Optional.
280 pub v_icms_uf_remet: Option<Cents>,
281}
282
283impl IcmsUfDestData {
284 /// Create a new `IcmsUfDestData` with required fields.
285 pub fn new(
286 v_bc_uf_dest: Cents,
287 p_icms_uf_dest: Rate,
288 p_icms_inter: Rate,
289 v_icms_uf_dest: Cents,
290 ) -> Self {
291 Self {
292 v_bc_uf_dest,
293 v_bc_fcp_uf_dest: None,
294 p_fcp_uf_dest: None,
295 p_icms_uf_dest,
296 p_icms_inter,
297 v_fcp_uf_dest: None,
298 v_icms_uf_dest,
299 v_icms_uf_remet: None,
300 }
301 }
302 /// Set the FCP base value for destination.
303 pub fn v_bc_fcp_uf_dest(mut self, v: Cents) -> Self {
304 self.v_bc_fcp_uf_dest = Some(v);
305 self
306 }
307 /// Set the FCP rate for destination.
308 pub fn p_fcp_uf_dest(mut self, v: Rate) -> Self {
309 self.p_fcp_uf_dest = Some(v);
310 self
311 }
312 /// Set the FCP value for destination.
313 pub fn v_fcp_uf_dest(mut self, v: Cents) -> Self {
314 self.v_fcp_uf_dest = Some(v);
315 self
316 }
317 /// Set the ICMS value for origin state.
318 pub fn v_icms_uf_remet(mut self, v: Cents) -> Self {
319 self.v_icms_uf_remet = Some(v);
320 self
321 }
322}