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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
use crate::com::{FromDispatch, FromDispatchNew, SafeDispatch, SafeVariant};
use crate::errors::SageResult;
use windows::Win32::System::Com::IDispatch;
/// Wrapper pour l'objet Depot de Sage 100c (IBODepot)
///
/// Représente un dépôt de stockage avec ses propriétés et informations.
/// Un dépôt est un lieu physique ou logique où sont stockés les articles.
///
/// # Exemples
///
/// ```no_run
/// # use objets_metier_rs::wrappers::cial::CialApplication;
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// # let cial = CialApplication::new("Objets100c.CIAL")?;
/// # cial.set_name("D:\\Sage\\BIJOU.MAE")?;
/// # cial.open()?;
/// let factory_depot = cial.factory_depot()?;
/// let depot = factory_depot.read_intitule("Principal")?;
/// println!("Dépôt : {}", depot.de_intitule()?);
/// println!("Code : {}", depot.de_code()?);
/// # Ok(())
/// # }
/// ```
pub struct Depot {
pub(crate) dispatch: IDispatch,
}
impl Depot {
/// Crée un SafeDispatch temporaire pour les appels
fn dispatch(&self) -> SafeDispatch<'_> {
SafeDispatch::new(&self.dispatch)
}
// ==================== IDENTIFICATION ====================
/// Obtient l'intitulé du dépôt
///
/// # Exemples
///
/// ```no_run
/// # use objets_metier_rs::wrappers::cial::objects::Depot;
/// # fn example(depot: &Depot) -> Result<(), Box<dyn std::error::Error>> {
/// let intitule = depot.de_intitule()?;
/// println!("Intitulé : {}", intitule);
/// # Ok(())
/// # }
/// ```
pub fn de_intitule(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("DE_Intitule", &[])?
.to_string()
}
/// Définit l'intitulé du dépôt
pub fn set_de_intitule(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("DE_Intitule", &[param])?;
Ok(())
}
/// Obtient le code du dépôt
pub fn de_code(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("DE_Code", &[])?
.to_string()
}
/// Définit le code du dépôt
pub fn set_de_code(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("DE_Code", &[param])?;
Ok(())
}
/// Obtient le compteur interne du dépôt
pub fn de_no(&self) -> SageResult<i32> {
self.dispatch().call_method_by_name("DE_No", &[])?.to_i32()
}
// ==================== ADRESSE ====================
/// Obtient l'adresse du dépôt
pub fn de_adresse(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("DE_Adresse", &[])?
.to_string()
}
/// Définit l'adresse du dépôt
pub fn set_de_adresse(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("DE_Adresse", &[param])?;
Ok(())
}
/// Obtient le complément d'adresse du dépôt
pub fn de_complement(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("DE_Complement", &[])?
.to_string()
}
/// Définit le complément d'adresse du dépôt
pub fn set_de_complement(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch()
.call_property_put("DE_Complement", &[param])?;
Ok(())
}
/// Obtient le code postal du dépôt
pub fn de_code_postal(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("DE_CodePostal", &[])?
.to_string()
}
/// Définit le code postal du dépôt
pub fn set_de_code_postal(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch()
.call_property_put("DE_CodePostal", &[param])?;
Ok(())
}
/// Obtient la ville du dépôt
pub fn de_ville(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("DE_Ville", &[])?
.to_string()
}
/// Définit la ville du dépôt
pub fn set_de_ville(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("DE_Ville", &[param])?;
Ok(())
}
/// Obtient le pays du dépôt
pub fn de_pays(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("DE_Pays", &[])?
.to_string()
}
/// Définit le pays du dépôt
pub fn set_de_pays(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("DE_Pays", &[param])?;
Ok(())
}
// ==================== CONTACT ====================
/// Obtient le contact du dépôt
pub fn de_contact(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("DE_Contact", &[])?
.to_string()
}
/// Définit le contact du dépôt
pub fn set_de_contact(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("DE_Contact", &[param])?;
Ok(())
}
/// Obtient le téléphone du dépôt
pub fn de_telephone(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("DE_Telephone", &[])?
.to_string()
}
/// Définit le téléphone du dépôt
pub fn set_de_telephone(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch()
.call_property_put("DE_Telephone", &[param])?;
Ok(())
}
// ==================== OPTIONS ====================
/// Obtient le type de dépôt (0=Normal, 1=Principal, etc.)
pub fn de_type(&self) -> SageResult<i32> {
self.dispatch()
.call_method_by_name("DE_Type", &[])?
.to_i32()
}
/// Définit le type de dépôt
pub fn set_de_type(&self, value: i32) -> SageResult<()> {
let param = SafeVariant::from_i32(value);
self.dispatch().call_property_put("DE_Type", &[param])?;
Ok(())
}
/// Obtient l'email du dépôt
pub fn de_email(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("DE_EMail", &[])?
.to_string()
}
/// Définit l'email du dépôt
pub fn set_de_email(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch().call_property_put("DE_EMail", &[param])?;
Ok(())
}
/// Obtient le fax du dépôt
pub fn de_telecopie(&self) -> SageResult<String> {
self.dispatch()
.call_method_by_name("DE_Telecopie", &[])?
.to_string()
}
/// Définit le fax du dépôt
pub fn set_de_telecopie(&self, value: &str) -> SageResult<()> {
let param = SafeVariant::from_string(value);
self.dispatch()
.call_property_put("DE_Telecopie", &[param])?;
Ok(())
}
/// Indique si le dépôt est principal
pub fn de_principal(&self) -> SageResult<bool> {
let type_depot = self.de_type()?;
Ok(type_depot == 1)
}
/// Indique si le dépôt est actif
pub fn de_actif(&self) -> SageResult<bool> {
self.dispatch()
.call_method_by_name("DE_Sommeil", &[])?
.to_bool()
.map(|v| !v) // DE_Sommeil = true signifie inactif, donc on inverse
}
/// Active ou désactive le dépôt
pub fn set_de_actif(&self, actif: bool) -> SageResult<()> {
let param = SafeVariant::from_bool(!actif); // Inverse pour DE_Sommeil
self.dispatch().call_property_put("DE_Sommeil", &[param])?;
Ok(())
}
// ==================== MÉTHODES D'ÉCRITURE ====================
/// Enregistre les modifications du dépôt dans la base de données
///
/// # Exemples
///
/// ```no_run
/// # use objets_metier_rs::wrappers::cial::objects::Depot;
/// # fn example(depot: &Depot) -> Result<(), Box<dyn std::error::Error>> {
/// depot.set_de_intitule("Dépôt Sud")?;
/// depot.set_de_ville("Lyon")?;
/// depot.write()?;
/// # Ok(())
/// # }
/// ```
pub fn write(&self) -> SageResult<()> {
self.dispatch().call_method_by_name("Write", &[])?;
Ok(())
}
/// Supprime le dépôt de la base de données
///
/// ⚠️ Attention : Cette opération est irréversible
pub fn remove(&self) -> SageResult<()> {
self.dispatch().call_method_by_name("Remove", &[])?;
Ok(())
}
// ==================== MÉTHODES MÉTIER ====================
/// Obtient l'adresse complète formatée du dépôt
///
/// Retourne une adresse formatée sur plusieurs lignes
pub fn get_adresse_complete(&self) -> SageResult<String> {
let mut adresse = String::new();
let addr = self.de_adresse()?;
if !addr.is_empty() {
adresse.push_str(&addr);
adresse.push('\n');
}
let complement = self.de_complement()?;
if !complement.is_empty() {
adresse.push_str(&complement);
adresse.push('\n');
}
let cp = self.de_code_postal()?;
let ville = self.de_ville()?;
if !cp.is_empty() || !ville.is_empty() {
adresse.push_str(&format!("{} {}\n", cp, ville));
}
let pays = self.de_pays()?;
if !pays.is_empty() {
adresse.push_str(&pays);
}
Ok(adresse.trim().to_string())
}
/// Valide les données du dépôt avant enregistrement
///
/// Vérifie que les champs obligatoires sont remplis
pub fn validate(&self) -> SageResult<bool> {
let intitule = self.de_intitule()?;
if intitule.is_empty() {
return Ok(false);
}
let code = self.de_code()?;
if code.is_empty() {
return Ok(false);
}
Ok(true)
}
/// Obtient le compteur interne (cbMarq) du dépôt
pub fn cbmarq(&self) -> SageResult<i32> {
self.dispatch().call_method_by_name("cbMarq", &[])?.to_i32()
}
}
impl FromDispatch for Depot {
fn from_dispatch(dispatch: IDispatch) -> SageResult<Self> {
Ok(Depot { dispatch })
}
}
impl FromDispatchNew for Depot {
fn from_dispatch_new(dispatch: IDispatch) -> SageResult<Self> {
Ok(Depot { dispatch })
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_depot_structure() {
// Test de documentation vérifiant que la structure compile
// Ne s'exécute pas réellement car nécessite une connexion Sage
}
}