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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
use crate::com::{FromDispatch, FromDispatchNew, SafeDispatch, SafeVariant};
use crate::errors::SageResult;
use windows::Win32::System::Com::IDispatch;
/// Wrapper pour l'objet Banque de Sage 100c (IBOBanque3)
///
/// Représente un compte bancaire de l'entreprise avec toutes ses informations
/// (RIB, IBAN, compte général associé, etc.)
pub struct Banque {
pub dispatch: IDispatch,
}
impl Banque {
/// Crée un SafeDispatch temporaire pour les appels
fn dispatch(&self) -> SafeDispatch<'_> {
SafeDispatch::new(&self.dispatch)
}
// ==================== IDENTIFICATION ====================
/// Obtient l'intitulé du compte bancaire
pub fn ba_intitule(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("BA_Intitule", &[])?
.to_string()
}
/// Définit l'intitulé du compte bancaire
pub fn set_ba_intitule(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("BA_Intitule", &[param])?;
Ok(())
}
/// Obtient l'abrégé du compte bancaire
pub fn ba_abrege(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("BA_Abrege", &[])?
.to_string()
}
/// Définit l'abrégé du compte bancaire
pub fn set_ba_abrege(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("BA_Abrege", &[param])?;
Ok(())
}
// ==================== COORDONNÉES BANCAIRES ====================
/// Obtient le code banque
pub fn ba_code_banque(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("BA_CodeBanque", &[])?
.to_string()
}
/// Définit le code banque
pub fn set_ba_code_banque(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch()
.call_property_put("BA_CodeBanque", &[param])?;
Ok(())
}
/// Obtient le code guichet
pub fn ba_code_guichet(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("BA_CodeGuichet", &[])?
.to_string()
}
/// Définit le code guichet
pub fn set_ba_code_guichet(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch()
.call_property_put("BA_CodeGuichet", &[param])?;
Ok(())
}
/// Obtient le numéro de compte
pub fn ba_numero_compte(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("BA_NumeroCompte", &[])?
.to_string()
}
/// Définit le numéro de compte
pub fn set_ba_numero_compte(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch()
.call_property_put("BA_NumeroCompte", &[param])?;
Ok(())
}
/// Obtient la clé RIB
pub fn ba_cle_rib(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("BA_CleRib", &[])?
.to_string()
}
/// Définit la clé RIB
pub fn set_ba_cle_rib(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("BA_CleRib", &[param])?;
Ok(())
}
/// Obtient l'IBAN
pub fn ba_iban(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("BA_IBAN", &[])?
.to_string()
}
/// Définit l'IBAN
pub fn set_ba_iban(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("BA_IBAN", &[param])?;
Ok(())
}
/// Obtient le code SWIFT/BIC
pub fn ba_swift(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("BA_CodeSWIFT", &[])?
.to_string()
}
/// Définit le code SWIFT/BIC
pub fn set_ba_swift(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch()
.call_property_put("BA_CodeSWIFT", &[param])?;
Ok(())
}
// ==================== COMPTABILITÉ ====================
/// Obtient le compte général associé
pub fn ba_compte_g(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("BA_CompteG", &[])?
.to_string()
}
/// Définit le compte général associé
pub fn set_ba_compte_g(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("BA_CompteG", &[param])?;
Ok(())
}
/// Obtient le code journal associé
pub fn ba_journal(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("BA_Journal", &[])?
.to_string()
}
/// Définit le code journal associé
pub fn set_ba_journal(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("BA_Journal", &[param])?;
Ok(())
}
// ==================== INFORMATIONS COMPLÉMENTAIRES ====================
/// Obtient le code devise
pub fn ba_devise(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("BA_Devise", &[])?
.to_string()
}
/// Définit le code devise
pub fn set_ba_devise(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("BA_Devise", &[param])?;
Ok(())
}
/// Obtient le mode de paiement par défaut
pub fn ba_mode_paiement(&self) -> SageResult<i32> {
self.dispatch()
.call_method_by_name("BA_ModePaiement", &[])?
.to_i32()
}
/// Définit le mode de paiement par défaut
pub fn set_ba_mode_paiement(&self, value: i32) -> SageResult<()> {
let param = SafeVariant::from_i32(value);
self.dispatch()
.call_property_put("BA_ModePaiement", &[param])?;
Ok(())
}
/// Obtient le solde du compte bancaire
pub fn ba_solde(&self) -> SageResult<f64> {
self.dispatch()
.call_method_by_name("BA_Solde", &[])?
.to_f64()
}
// Note: BA_Solde est généralement en lecture seule (calculé)
// ==================== MÉTHODES IBIPersistObject ====================
/// Enregistre l'objet dans la base de données
pub fn write(&self) -> SageResult<()> {
self.dispatch().call_method_by_name("Write", &[])?;
Ok(())
}
/// Lit l'objet depuis la base de données
pub fn read(&self) -> SageResult<SafeVariant> {
self.dispatch().call_method_by_name("Read", &[])
}
/// Supprime l'objet de la base de données
pub fn remove(&self) -> SageResult<()> {
self.dispatch().call_method_by_name("Remove", &[])?;
Ok(())
}
// ==================== MÉTHODES UTILITAIRES ====================
/// Retourne une description formatée du compte bancaire
/// Format: "Banque [Intitulé] - IBAN: [IBAN]"
pub fn description(&self) -> SageResult<String> {
let intitule = self.ba_intitule()?;
let iban = self.ba_iban().unwrap_or_else(|_| "N/A".to_string());
Ok(format!("Banque {} - IBAN: {}", intitule, iban))
}
}
impl FromDispatch for Banque {
fn from_dispatch(dispatch: IDispatch) -> SageResult<Self> {
Ok(Banque { dispatch })
}
}
impl FromDispatchNew for Banque {
fn from_dispatch_new(dispatch: IDispatch) -> SageResult<Self> {
Ok(Self { dispatch })
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_banque_documentation() {
// Test de documentation - nécessite un environnement Sage pour s'exécuter
// Utilisation typique :
// let factory = app.factory_banque()?;
// let banque = factory.read_intitule("BNP Paribas")?;
//
// println!("Banque: {}", banque.ba_intitule()?);
// println!("IBAN: {}", banque.ba_iban()?);
// println!("SWIFT: {}", banque.ba_swift()?);
// println!("Compte: {}", banque.ba_compte_g()?);
// println!("Journal: {}", banque.ba_journal()?);
// println!("Solde: {:.2} €", banque.ba_solde()?);
//
// // Modification
// banque.set_ba_intitule("BNP Paribas Pro")?;
// banque.write()?;
}
}