paymentlib/enums/
transaction_type.rsuse serde::Deserialize;
use serde::Serialize;
use std::fmt;
use std::fmt::Formatter;
use std::str;
#[cfg(feature = "diesel")]
use {
diesel::backend::Backend,
diesel::deserialize::FromSql,
diesel::pg::Pg,
diesel::serialize::{IsNull, Output, ToSql},
diesel::types::Varchar,
diesel::{deserialize, not_none, serialize},
diesel::{AsExpression, FromSqlRow},
std::io::Write,
};
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "diesel", derive(AsExpression, FromSqlRow))]
#[cfg_attr(feature = "diesel", sql_type = "Varchar")]
pub enum TransactionType {
DayStart,
Sale,
CashDeposit,
CashWithdrawal,
BankDraw,
Refund,
Expense,
Rounding,
Reconciliation,
Exchange,
CheckDeposit,
CheckIssuance,
CheckCashing,
CheckRefund,
CheckClearing,
VoidCheck,
Undefined,
}
impl fmt::Display for TransactionType {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}
impl Default for TransactionType {
fn default() -> Self {
TransactionType::Undefined
}
}
#[cfg(feature = "diesel")]
impl ToSql<Varchar, Pg> for TransactionType {
fn to_sql<W: Write>(&self, out: &mut Output<W, Pg>) -> serialize::Result {
match *self {
TransactionType::DayStart => out.write_all(b"DayStart")?,
TransactionType::Sale => out.write_all(b"Sale")?,
TransactionType::CashDeposit => out.write_all(b"CashDeposit")?,
TransactionType::CashWithdrawal => out.write_all(b"CashWithdrawal")?,
TransactionType::BankDraw => out.write_all(b"BankDraw")?,
TransactionType::Refund => out.write_all(b"Refund")?,
TransactionType::Expense => out.write_all(b"Expense")?,
TransactionType::Rounding => out.write_all(b"Rounding")?,
TransactionType::Reconciliation => out.write_all(b"Reconciliation")?,
TransactionType::Exchange => out.write_all(b"Exchange")?,
TransactionType::CheckDeposit => out.write_all(b"CheckDeposit")?,
TransactionType::CheckIssuance => out.write_all(b"CheckCashing")?,
TransactionType::CheckCashing => out.write_all(b"DayStart")?,
TransactionType::CheckRefund => out.write_all(b"CheckRefund")?,
TransactionType::CheckClearing => out.write_all(b"CheckClearing")?,
TransactionType::VoidCheck => out.write_all(b"VoidCheck")?,
TransactionType::Undefined => out.write_all(b"Undefined")?,
}
Ok(IsNull::No)
}
}
#[cfg(feature = "diesel")]
impl FromSql<Varchar, Pg> for TransactionType {
fn from_sql(bytes: Option<&<Pg as Backend>::RawValue>) -> deserialize::Result<Self> {
match not_none!(bytes) {
b"DayStart" => Ok(TransactionType::DayStart),
b"Sale" => Ok(TransactionType::Sale),
b"CashDeposit" => Ok(TransactionType::CashDeposit),
b"CashWithdrawal" => Ok(TransactionType::CashWithdrawal),
b"BankDraw" => Ok(TransactionType::BankDraw),
b"Refund" => Ok(TransactionType::Refund),
b"Expense" => Ok(TransactionType::Expense),
b"Rounding" => Ok(TransactionType::Rounding),
b"Reconciliation" => Ok(TransactionType::Reconciliation),
b"Exchange" => Ok(TransactionType::Exchange),
b"CheckDeposit" => Ok(TransactionType::CheckDeposit),
b"CheckIssuance" => Ok(TransactionType::CheckIssuance),
b"CheckCashing" => Ok(TransactionType::CheckCashing),
b"CheckRefund" => Ok(TransactionType::CheckRefund),
b"CheckClearing" => Ok(TransactionType::CheckClearing),
b"VoidCheck" => Ok(TransactionType::VoidCheck),
b"Undefined" => Ok(TransactionType::Undefined),
_ => Err("Unrecognized enum variant".into()),
}
}
}