backbone-payroll 0.3.47

Payroll: salary structures, payroll runs and computed salary slips over effective-dated statutory tables, plus compensation changes
Documentation
use serde::{Deserialize, Serialize};
use sqlx::Type;
use std::str::FromStr;
#[cfg(feature = "openapi")]
use utoipa::ToSchema;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Type)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "snake_case")]
#[sqlx(type_name = "payroll_status", rename_all = "snake_case")]
pub enum PayrollStatus {
    Draft,
    Processed,
    Posted,
    Cancelled,
}

impl std::fmt::Display for PayrollStatus {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Draft => write!(f, "draft"),
            Self::Processed => write!(f, "processed"),
            Self::Posted => write!(f, "posted"),
            Self::Cancelled => write!(f, "cancelled"),
        }
    }
}

impl FromStr for PayrollStatus {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s.to_lowercase().as_str() {
            "draft" => Ok(Self::Draft),
            "processed" => Ok(Self::Processed),
            "posted" => Ok(Self::Posted),
            "cancelled" => Ok(Self::Cancelled),
            _ => Err(format!("Unknown PayrollStatus variant: {}", s)),
        }
    }
}

impl Default for PayrollStatus {
    fn default() -> Self {
        Self::Draft
    }
}