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
use crate::com::{FromDispatch, FromDispatchNew, SafeDispatch, SafeVariant};
use crate::errors::SageResult;
use windows::Win32::System::Com::IDispatch;
/// Wrapper pour l'objet Collaborateur de Sage 100c (IBOCollaborateur3)
///
/// Représente un collaborateur ou responsable de comptes dans l'entreprise.
/// Les collaborateurs peuvent être affectés aux tiers (clients/fournisseurs)
/// pour le suivi commercial et administratif.
pub struct Collaborateur {
pub dispatch: IDispatch,
}
impl Collaborateur {
/// Crée un SafeDispatch temporaire pour les appels
fn dispatch(&self) -> SafeDispatch<'_> {
SafeDispatch::new(&self.dispatch)
}
// ==================== IDENTIFICATION ====================
/// Obtient le numéro du collaborateur
pub fn co_numero(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("CO_Numero", &[])?
.to_string()
}
/// Définit le numéro du collaborateur
pub fn set_co_numero(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("CO_Numero", &[param])?;
Ok(())
}
/// Obtient l'intitulé/nom complet du collaborateur
pub fn co_intitule(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("CO_Intitule", &[])?
.to_string()
}
/// Définit l'intitulé du collaborateur
pub fn set_co_intitule(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("CO_Intitule", &[param])?;
Ok(())
}
// ==================== IDENTITÉ ====================
/// Obtient le nom du collaborateur
pub fn co_nom(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("CO_Nom", &[])?
.to_string()
}
/// Définit le nom du collaborateur
pub fn set_co_nom(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("CO_Nom", &[param])?;
Ok(())
}
/// Obtient le prénom du collaborateur
pub fn co_prenom(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("CO_Prenom", &[])?
.to_string()
}
/// Définit le prénom du collaborateur
pub fn set_co_prenom(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("CO_Prenom", &[param])?;
Ok(())
}
// ==================== COORDONNÉES ====================
/// Obtient le numéro de téléphone
pub fn co_telephone(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("CO_Telephone", &[])?
.to_string()
}
/// Définit le numéro de téléphone
pub fn set_co_telephone(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch()
.call_property_put("CO_Telephone", &[param])?;
Ok(())
}
/// Obtient le numéro de télécopie/fax
pub fn co_telecopie(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("CO_Telecopie", &[])?
.to_string()
}
/// Définit le numéro de télécopie
pub fn set_co_telecopie(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch()
.call_property_put("CO_Telecopie", &[param])?;
Ok(())
}
/// Obtient l'adresse email
pub fn co_email(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("CO_Email", &[])?
.to_string()
}
/// Définit l'adresse email
pub fn set_co_email(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("CO_Email", &[param])?;
Ok(())
}
// ==================== FONCTION ET SERVICE ====================
/// Obtient la fonction du collaborateur
pub fn co_fonction(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("CO_Fonction", &[])?
.to_string()
}
/// Définit la fonction du collaborateur
pub fn set_co_fonction(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("CO_Fonction", &[param])?;
Ok(())
}
/// Obtient le service du collaborateur
pub fn co_service(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("CO_Service", &[])?
.to_string()
}
/// Définit le service du collaborateur
pub fn set_co_service(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("CO_Service", &[param])?;
Ok(())
}
// ==================== 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 collaborateur
/// Format: "Collaborateur [Numéro] - [Nom] [Prénom]"
pub fn description(&self) -> SageResult<String> {
let numero = self.co_numero()?;
let nom = self.co_nom()?;
let prenom = self.co_prenom().unwrap_or_else(|_| String::new());
let nom_complet = if prenom.is_empty() {
nom
} else {
format!("{} {}", nom, prenom)
};
Ok(format!("Collaborateur {} - {}", numero, nom_complet))
}
/// Retourne les coordonnées formatées du collaborateur
pub fn coordonnees(&self) -> SageResult<String> {
let tel = self.co_telephone().unwrap_or_else(|_| "N/A".to_string());
let email = self.co_email().unwrap_or_else(|_| "N/A".to_string());
Ok(format!("Tél: {} - Email: {}", tel, email))
}
}
impl FromDispatch for Collaborateur {
fn from_dispatch(dispatch: IDispatch) -> SageResult<Self> {
Ok(Collaborateur { dispatch })
}
}
impl FromDispatchNew for Collaborateur {
fn from_dispatch_new(dispatch: IDispatch) -> SageResult<Self> {
Ok(Self { dispatch })
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_collaborateur_documentation() {
// Test de documentation - nécessite un environnement Sage pour s'exécuter
// Utilisation typique :
// let factory = app.factory_collaborateur()?;
// let collab = factory.read_numero("001")?;
//
// println!("Collaborateur: {}", collab.co_intitule()?);
// println!("Nom: {} {}", collab.co_nom()?, collab.co_prenom()?);
// println!("Fonction: {}", collab.co_fonction()?);
// println!("Service: {}", collab.co_service()?);
// println!("Contact: {}", collab.coordonnees()?);
//
// // Création
// let nouveau = factory.create()?;
// nouveau.set_co_numero("005")?;
// nouveau.set_co_nom("Dupont")?;
// nouveau.set_co_prenom("Marie")?;
// nouveau.set_co_email("marie.dupont@entreprise.com")?;
// nouveau.set_co_fonction("Responsable Commercial")?;
// nouveau.write()?;
}
}