use crate::com::{SafeDispatch, SafeVariant};
use crate::errors::SageResult;
use crate::wrappers::cpta::factories::FactoryEcritureIn;
use crate::wrappers::cpta::objects::{Devise, Journal};
use crate::wrappers::cpta::process::ErrorCollection;
use windows::Win32::System::Com::IDispatch;
pub struct PMEncoder {
pub dispatch: IDispatch,
}
impl PMEncoder {
fn dispatch(&self) -> SafeDispatch<'_> {
SafeDispatch::new(&self.dispatch)
}
pub fn set_analytique_auto(&self, auto: bool) -> SageResult<()> {
let auto_variant = SafeVariant::Bool(auto);
self.dispatch()
.call_property_put("bAnalytiqueAuto", &[auto_variant])?;
Ok(())
}
pub fn analytique_auto(&self) -> SageResult<bool> {
self.dispatch()
.get_property_by_name("bAnalytiqueAuto")?
.to_bool()
}
pub fn set_multi_echeance_auto(&self, auto: bool) -> SageResult<()> {
let auto_variant = SafeVariant::Bool(auto);
self.dispatch()
.call_property_put("bMultiEcheanceAuto", &[auto_variant])?;
Ok(())
}
pub fn multi_echeance_auto(&self) -> SageResult<bool> {
self.dispatch()
.get_property_by_name("bMultiEcheanceAuto")?
.to_bool()
}
pub fn set_journal(&self, journal: &Journal) -> SageResult<()> {
let journal_variant = SafeVariant::from_dispatch(journal.dispatch.clone());
self.dispatch()
.call_property_put("Journal", &[journal_variant])?;
Ok(())
}
pub fn journal(&self) -> SageResult<Journal> {
let variant = self.dispatch().get_property_by_name("Journal")?;
let dispatch = variant.to_dispatch()?;
Ok(Journal { dispatch })
}
pub fn set_date(&self, date: &str) -> SageResult<()> {
let date_variant = SafeVariant::from_string(date);
self.dispatch().call_property_put("Date", &[date_variant])?;
Ok(())
}
pub fn date(&self) -> SageResult<String> {
self.dispatch().get_property_by_name("Date")?.to_string()
}
pub fn set_devise(&self, devise: &Devise) -> SageResult<()> {
let devise_variant = SafeVariant::from_dispatch(devise.dispatch.clone());
self.dispatch()
.call_property_put("Devise", &[devise_variant])?;
Ok(())
}
pub fn set_ec_parite(&self, parite: f64) -> SageResult<()> {
let parite_variant = SafeVariant::R8(parite);
self.dispatch()
.call_property_put("EC_Parite", &[parite_variant])?;
Ok(())
}
pub fn set_ec_intitule(&self, intitule: &str) -> SageResult<()> {
let intitule_variant = SafeVariant::from_string(intitule);
self.dispatch()
.call_property_put("EC_Intitule", &[intitule_variant])?;
Ok(())
}
pub fn set_ec_piece(&self, piece: &str) -> SageResult<()> {
let piece_variant = SafeVariant::from_string(piece);
self.dispatch()
.call_property_put("EC_Piece", &[piece_variant])?;
Ok(())
}
pub fn set_ec_ref_piece(&self, ref_piece: &str) -> SageResult<()> {
let ref_variant = SafeVariant::from_string(ref_piece);
self.dispatch()
.call_property_put("EC_RefPiece", &[ref_variant])?;
Ok(())
}
pub fn set_ec_reference(&self, reference: &str) -> SageResult<()> {
let ref_variant = SafeVariant::from_string(reference);
self.dispatch()
.call_property_put("EC_Reference", &[ref_variant])?;
Ok(())
}
pub fn factory_ecriture_in(&self) -> SageResult<FactoryEcritureIn> {
let factory_variant = self.dispatch().get_property_by_name("FactoryEcritureIn")?;
let factory_dispatch = factory_variant.to_dispatch()?;
Ok(FactoryEcritureIn {
dispatch: factory_dispatch,
})
}
pub fn list_ecritures_out(&self) -> SageResult<SafeVariant> {
self.dispatch().call_method_by_name("ListEcrituresOut", &[])
}
pub fn credit(&self) -> SageResult<f64> {
self.dispatch().get_property_by_name("Credit")?.to_f64()
}
pub fn debit(&self) -> SageResult<f64> {
self.dispatch().get_property_by_name("Debit")?.to_f64()
}
pub fn solde(&self) -> SageResult<f64> {
self.dispatch().get_property_by_name("Solde")?.to_f64()
}
pub fn can_process(&self) -> SageResult<bool> {
self.dispatch()
.call_method_by_name("CanProcess", &[])?
.to_bool()
}
pub fn process(&self) -> SageResult<()> {
self.dispatch().call_method_by_name("Process", &[])?;
Ok(())
}
pub fn errors(&self) -> SageResult<ErrorCollection> {
let errors_variant = self.dispatch().get_property_by_name("Errors")?;
let errors_dispatch = errors_variant.to_dispatch()?;
Ok(ErrorCollection {
dispatch: errors_dispatch,
})
}
pub fn add_tiers_part(&self) -> SageResult<()> {
self.dispatch().call_method_by_name("AddTiersPart", &[])?;
Ok(())
}
pub fn equilibrer(&self) -> SageResult<()> {
self.dispatch().call_method_by_name("Equilibrer", &[])?;
Ok(())
}
}