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
use crate::com::{FromDispatchNew, SafeDispatch, SafeVariant};
use crate::errors::SageResult;
use windows::Win32::System::Com::IDispatch;
/// Wrapper pour l'objet Nature de Compte de Sage 100c (IBONatureCompte3)
///
/// Les natures de compte permettent de classifier les comptes généraux
/// selon leur nature comptable (Actif, Passif, Charge, Produit, etc.).
/// Utilisées pour la génération des états financiers et bilans.
#[derive(Debug)]
pub struct NatureCompte {
pub dispatch: IDispatch,
}
impl NatureCompte {
/// Crée un SafeDispatch temporaire pour les appels
fn dispatch(&self) -> SafeDispatch<'_> {
SafeDispatch::new(&self.dispatch)
}
// ==================== PROPRIÉTÉS PRINCIPALES ====================
/// Récupère l'intitulé de la nature de compte
pub fn nc_intitule(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("NC_Intitule", &[])?
.to_string()
}
/// Définit l'intitulé de la nature de compte
pub fn set_nc_intitule(&self, intitule: &str) -> SageResult<()> {
let param = SafeVariant::from_string(intitule);
self.dispatch()
.call_method_by_name("SetNC_Intitule", &[param])?;
Ok(())
}
/// Récupère le code de la nature de compte
pub fn nc_code(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("NC_Code", &[])?
.to_string()
}
/// Définit le code de la nature de compte
pub fn set_nc_code(&self, code: &str) -> SageResult<()> {
let param = SafeVariant::from_string(code);
self.dispatch()
.call_method_by_name("SetNC_Code", &[param])?;
Ok(())
}
// ==================== PROPRIÉTÉS DE CLASSIFICATION ====================
/// Récupère le type de nature (0=Bilan, 1=Gestion)
pub fn nc_type(&self) -> SageResult<i32> {
self.dispatch()
.call_method_by_name("NC_Type", &[])?
.to_i32()
}
/// Définit le type de nature
pub fn set_nc_type(&self, type_val: i32) -> SageResult<()> {
let param = SafeVariant::I4(type_val);
self.dispatch()
.call_method_by_name("SetNC_Type", &[param])?;
Ok(())
}
/// Récupère la classe (Actif, Passif, Charge, Produit)
/// 0=Actif, 1=Passif, 2=Charge, 3=Produit
pub fn nc_classe(&self) -> SageResult<i32> {
self.dispatch()
.call_method_by_name("NC_Classe", &[])?
.to_i32()
}
/// Définit la classe
pub fn set_nc_classe(&self, classe: i32) -> SageResult<()> {
let param = SafeVariant::I4(classe);
self.dispatch()
.call_method_by_name("SetNC_Classe", &[param])?;
Ok(())
}
/// Récupère le numéro de nature
pub fn nc_numero(&self) -> SageResult<i32> {
self.dispatch()
.call_method_by_name("NC_Numero", &[])?
.to_i32()
}
/// Définit le numéro de nature
pub fn set_nc_numero(&self, numero: i32) -> SageResult<()> {
let param = SafeVariant::I4(numero);
self.dispatch()
.call_method_by_name("SetNC_Numero", &[param])?;
Ok(())
}
// ==================== PROPRIÉTÉS D'AFFICHAGE ====================
/// Récupère la position d'affichage dans les états
pub fn nc_position(&self) -> SageResult<i32> {
self.dispatch()
.call_method_by_name("NC_Position", &[])?
.to_i32()
}
/// Définit la position d'affichage
pub fn set_nc_position(&self, position: i32) -> SageResult<()> {
let param = SafeVariant::I4(position);
self.dispatch()
.call_method_by_name("SetNC_Position", &[param])?;
Ok(())
}
/// Récupère le niveau hiérarchique
pub fn nc_niveau(&self) -> SageResult<i32> {
self.dispatch()
.call_method_by_name("NC_Niveau", &[])?
.to_i32()
}
/// Définit le niveau hiérarchique
pub fn set_nc_niveau(&self, niveau: i32) -> SageResult<()> {
let param = SafeVariant::I4(niveau);
self.dispatch()
.call_method_by_name("SetNC_Niveau", &[param])?;
Ok(())
}
// ==================== MÉTHODES IBIPersistObject ====================
/// Sauvegarde les modifications de la nature de compte
pub fn write(&self) -> SageResult<()> {
self.dispatch().call_method_by_name("Write", &[])?;
Ok(())
}
/// Supprime la nature de compte
pub fn remove(&self) -> SageResult<()> {
self.dispatch().call_method_by_name("Remove", &[])?;
Ok(())
}
// ==================== MÉTHODES DE DESCRIPTION ====================
/// Retourne une description formatée de la nature de compte
pub fn description(&self) -> SageResult<String> {
let intitule = self.nc_intitule()?;
let type_val = self.nc_type()?;
let classe = self.nc_classe()?;
let type_str = match type_val {
0 => "Bilan",
1 => "Gestion",
_ => "Inconnu",
};
let classe_str = match classe {
0 => "Actif",
1 => "Passif",
2 => "Charge",
3 => "Produit",
_ => "Autre",
};
Ok(format!(
"Nature Compte: {} ({}, {})",
intitule, type_str, classe_str
))
}
}
impl FromDispatchNew for NatureCompte {
fn from_dispatch_new(dispatch: IDispatch) -> SageResult<Self> {
Ok(Self { dispatch })
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_nature_compte_properties() {
// Test de documentation des propriétés disponibles
// Propriétés principales
// nc_intitule() / set_nc_intitule()
// nc_code() / set_nc_code()
// Propriétés de classification
// nc_type() / set_nc_type()
// nc_classe() / set_nc_classe()
// nc_numero() / set_nc_numero()
// Propriétés d'affichage
// nc_position() / set_nc_position()
// nc_niveau() / set_nc_niveau()
// Méthodes
// write() - Sauvegarde
// remove() - Suppression
// description() - Description formatée
}
}