backbone-payroll 0.3.49

Payroll: salary structures, payroll runs and computed salary slips over effective-dated statutory tables, plus compensation changes
Documentation
//! SalarySlip DTOs (Data Transfer Objects)
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! DTOs provide a clean separation between domain entities and API
//! representations, with validation and OpenAPI documentation support.

use serde::{Deserialize, Serialize};
use uuid::Uuid;
use chrono::{DateTime, Utc};
use rust_decimal::Decimal;

#[cfg(feature = "openapi")]
#[cfg(feature = "openapi")]
use utoipa::ToSchema;

#[cfg(feature = "validation")]
use validator::Validate;

use crate::domain::entity::SalarySlip;
use crate::domain::entity::AuditMetadata;

// =============================================================================
// Create DTO
// =============================================================================

/// Request DTO for creating a new SalarySlip
///
/// Used in POST requests to create new entities.
/// Excludes auto-generated fields (id, created_at, updated_at, deleted_at).
#[derive(Debug, Clone, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct CreateSalarySlipDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "payroll_entry_id")]
    pub payroll_entry_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "employee_id")]
    pub employee_id: Uuid,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "structure_id")]
    pub structure_id: Option<Uuid>,
    #[serde(alias = "working_days")]
    pub working_days: Decimal,
    #[serde(alias = "unpaid_days")]
    pub unpaid_days: Decimal,
    #[serde(alias = "gross_pay")]
    pub gross_pay: Decimal,
    #[serde(alias = "total_deductions")]
    pub total_deductions: Decimal,
    #[serde(alias = "net_pay")]
    pub net_pay: Decimal,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "overtime_hours")]
    pub overtime_hours: Option<Decimal>,
    #[cfg_attr(feature = "validation", validate(length(max = 20)))]
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "tax_method")]
    pub tax_method: Option<String>,
}

// =============================================================================
// Update DTO
// =============================================================================

/// Request DTO for full update of a SalarySlip
///
/// Used in PUT requests for full entity replacement.
/// All fields are required (except auto-generated ones).
#[derive(Debug, Clone, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct UpdateSalarySlipDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "payroll_entry_id")]
    pub payroll_entry_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "employee_id")]
    pub employee_id: Uuid,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "structure_id")]
    pub structure_id: Option<Uuid>,
    #[serde(alias = "working_days")]
    pub working_days: Decimal,
    #[serde(alias = "unpaid_days")]
    pub unpaid_days: Decimal,
    #[serde(alias = "gross_pay")]
    pub gross_pay: Decimal,
    #[serde(alias = "total_deductions")]
    pub total_deductions: Decimal,
    #[serde(alias = "net_pay")]
    pub net_pay: Decimal,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "overtime_hours")]
    pub overtime_hours: Option<Decimal>,
    #[cfg_attr(feature = "validation", validate(length(max = 20)))]
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "tax_method")]
    pub tax_method: Option<String>,
}

// =============================================================================
// Patch DTO
// =============================================================================

/// Request DTO for partial update of a SalarySlip
///
/// Used in PATCH requests for partial updates.
/// All fields are optional - only provided fields will be updated.
#[derive(Debug, Clone, Default, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct PatchSalarySlipDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "payroll_entry_id")]
    pub payroll_entry_id: Option<Uuid>,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "employee_id")]
    pub employee_id: Option<Uuid>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "structure_id")]
    pub structure_id: Option<Uuid>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "working_days")]
    pub working_days: Option<Decimal>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "unpaid_days")]
    pub unpaid_days: Option<Decimal>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "gross_pay")]
    pub gross_pay: Option<Decimal>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "total_deductions")]
    pub total_deductions: Option<Decimal>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "net_pay")]
    pub net_pay: Option<Decimal>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "overtime_hours")]
    pub overtime_hours: Option<Decimal>,
    #[cfg_attr(feature = "validation", validate(length(max = 20)))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "tax_method")]
    pub tax_method: Option<String>,
}

impl PatchSalarySlipDto {
    /// Check if any field is set
    pub fn has_changes(&self) -> bool {
        self.payroll_entry_id.is_some() || self.employee_id.is_some() || self.structure_id.is_some() || self.working_days.is_some() || self.unpaid_days.is_some() || self.gross_pay.is_some() || self.total_deductions.is_some() || self.net_pay.is_some() || self.overtime_hours.is_some() || self.tax_method.is_some()
    }
}

// =============================================================================
// Response DTO
// =============================================================================

/// Response DTO for SalarySlip entity
///
/// Used in API responses for single entity.
/// Includes all fields including metadata.
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct SalarySlipResponseDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    pub id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    pub payroll_entry_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    pub employee_id: Uuid,
    pub structure_id: Option<Uuid>,
    pub working_days: Decimal,
    pub unpaid_days: Decimal,
    pub gross_pay: Decimal,
    pub total_deductions: Decimal,
    pub net_pay: Decimal,
    pub overtime_hours: Option<Decimal>,
    pub tax_method: Option<String>,
    pub metadata: AuditMetadata,
}

// =============================================================================
// List Response DTO
// =============================================================================

/// Paginated list response for SalarySlip entities
///
/// Used in API responses for list endpoints.
/// Includes pagination metadata.
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct SalarySlipListResponseDto {
    /// List of items
    pub items: Vec<SalarySlipResponseDto>,
    /// Total number of items (across all pages)
    pub total: u64,
    /// Current page number (1-indexed)
    pub page: u32,
    /// Number of items per page
    pub per_page: u32,
    /// Total number of pages
    pub total_pages: u32,
    /// Whether there is a next page
    pub has_next: bool,
    /// Whether there is a previous page
    pub has_prev: bool,
}

impl SalarySlipListResponseDto {
    /// Create a new list response from items and pagination info
    pub fn new(items: Vec<SalarySlipResponseDto>, total: u64, page: u32, per_page: u32) -> Self {
        let total_pages = if per_page > 0 {
            ((total as f64) / (per_page as f64)).ceil() as u32
        } else {
            0
        };
        Self {
            items,
            total,
            page,
            per_page,
            total_pages,
            has_next: page < total_pages,
            has_prev: page > 1,
        }
    }
}

/// Summary DTO for list views (compact version)
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct SalarySlipSummaryDto {
    pub id: Uuid,
    pub payroll_entry_id: Uuid,
    pub employee_id: Uuid,
    pub structure_id: Option<Uuid>,
    pub created_at: Option<DateTime<Utc>>,
}

// =============================================================================
// Conversions
// =============================================================================

impl From<SalarySlip> for SalarySlipResponseDto {
    fn from(entity: SalarySlip) -> Self {
        Self {
            id: entity.id,
            payroll_entry_id: entity.payroll_entry_id,
            employee_id: entity.employee_id,
            structure_id: entity.structure_id,
            working_days: entity.working_days,
            unpaid_days: entity.unpaid_days,
            gross_pay: entity.gross_pay,
            total_deductions: entity.total_deductions,
            net_pay: entity.net_pay,
            overtime_hours: entity.overtime_hours,
            tax_method: entity.tax_method,
            metadata: entity.metadata,
        }
    }
}

impl From<SalarySlip> for SalarySlipSummaryDto {
    fn from(entity: SalarySlip) -> Self {
        let created_at = backbone_core::PersistentEntity::created_at(&entity);
        Self {
            id: entity.id,
            payroll_entry_id: entity.payroll_entry_id,
            employee_id: entity.employee_id,
            structure_id: entity.structure_id,
            created_at,
        }
    }
}

impl From<CreateSalarySlipDto> for SalarySlip {
    fn from(dto: CreateSalarySlipDto) -> Self {
        Self {
            id: Uuid::new_v4(),
            payroll_entry_id: dto.payroll_entry_id,
            employee_id: dto.employee_id,
            structure_id: dto.structure_id,
            working_days: dto.working_days,
            unpaid_days: dto.unpaid_days,
            gross_pay: dto.gross_pay,
            total_deductions: dto.total_deductions,
            net_pay: dto.net_pay,
            overtime_hours: dto.overtime_hours,
            tax_method: dto.tax_method,
            metadata: AuditMetadata::default(),
        }
    }
}

impl From<&SalarySlip> for SalarySlipResponseDto {
    fn from(entity: &SalarySlip) -> Self {
        Self {
            id: entity.id.clone(),
            payroll_entry_id: entity.payroll_entry_id.clone(),
            employee_id: entity.employee_id.clone(),
            structure_id: entity.structure_id.clone(),
            working_days: entity.working_days.clone(),
            unpaid_days: entity.unpaid_days.clone(),
            gross_pay: entity.gross_pay.clone(),
            total_deductions: entity.total_deductions.clone(),
            net_pay: entity.net_pay.clone(),
            overtime_hours: entity.overtime_hours.clone(),
            tax_method: entity.tax_method.clone(),
            metadata: entity.metadata.clone(),
        }
    }
}

impl backbone_core::FromCreateDto<CreateSalarySlipDto> for SalarySlip {
    fn from_create_dto(dto: CreateSalarySlipDto) -> backbone_core::ServiceResult<Self> {
        Ok(SalarySlip::from(dto))
    }
}

impl backbone_core::ApplyUpdateDto<UpdateSalarySlipDto> for SalarySlip {
    fn apply_update(mut self, dto: UpdateSalarySlipDto) -> backbone_core::ServiceResult<Self> {
        self.payroll_entry_id = dto.payroll_entry_id;
        self.employee_id = dto.employee_id;
        self.structure_id = dto.structure_id;
        self.working_days = dto.working_days;
        self.unpaid_days = dto.unpaid_days;
        self.gross_pay = dto.gross_pay;
        self.total_deductions = dto.total_deductions;
        self.net_pay = dto.net_pay;
        self.overtime_hours = dto.overtime_hours;
        self.tax_method = dto.tax_method;
        Ok(self)
    }
}

// =============================================================================
// Custom DTOs
// =============================================================================

// <<< CUSTOM DTOs
// Add custom DTOs specific to SalarySlip here.
// This section will be preserved during regeneration.
// >>> END CUSTOM DTOs