//! PurchaseReceipt DTOs (Data Transfer Objects)
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! DTOs provide a clean separation between domain entities and API
//! representations, with OpenAPI documentation support.
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use chrono::{DateTime, Utc, NaiveDate};
use rust_decimal::Decimal;
#[cfg(feature = "openapi")]
#[cfg(feature = "openapi")]
use utoipa::ToSchema;
use crate::domain::entity::PurchaseReceipt;
use crate::domain::entity::AuditMetadata;
use crate::domain::entity::DocStatus;
use crate::domain::entity::GlPostingState;
// =============================================================================
// Create DTO
// =============================================================================
/// Request DTO for creating a new PurchaseReceipt
///
/// 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))]
#[serde(rename_all = "camelCase")]
pub struct CreatePurchaseReceiptDto {
#[cfg_attr(feature = "openapi", schema(example = "example"))]
#[serde(alias = "receipt_number")]
pub receipt_number: String,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "branch_id")]
pub branch_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(alias = "supplier_id")]
pub supplier_id: Uuid,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "source_po_id")]
pub source_po_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(alias = "warehouse_id")]
pub warehouse_id: Uuid,
#[cfg_attr(feature = "openapi", schema(example = "2024-01-01"))]
#[serde(alias = "posting_date")]
pub posting_date: NaiveDate,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub currency: String,
#[serde(alias = "total_value")]
pub total_value: Decimal,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(alias = "inventory_account_id")]
pub inventory_account_id: Uuid,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(alias = "grir_account_id")]
pub grir_account_id: Uuid,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "transfer_id")]
pub transfer_id: Option<Uuid>,
#[serde(alias = "posting_state")]
pub posting_state: GlPostingState,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "journal_id")]
pub journal_id: Option<Uuid>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "accounting_post_id")]
pub accounting_post_id: Option<Uuid>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "posted_at")]
pub posted_at: Option<DateTime<Utc>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub notes: Option<String>,
}
// =============================================================================
// Update DTO
// =============================================================================
/// Request DTO for full update of a PurchaseReceipt
///
/// 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))]
#[serde(rename_all = "camelCase")]
pub struct UpdatePurchaseReceiptDto {
#[cfg_attr(feature = "openapi", schema(example = "example"))]
#[serde(alias = "receipt_number")]
pub receipt_number: String,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "branch_id")]
pub branch_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(alias = "supplier_id")]
pub supplier_id: Uuid,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "source_po_id")]
pub source_po_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(alias = "warehouse_id")]
pub warehouse_id: Uuid,
#[cfg_attr(feature = "openapi", schema(example = "2024-01-01"))]
#[serde(alias = "posting_date")]
pub posting_date: NaiveDate,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub currency: String,
#[serde(alias = "total_value")]
pub total_value: Decimal,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(alias = "inventory_account_id")]
pub inventory_account_id: Uuid,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(alias = "grir_account_id")]
pub grir_account_id: Uuid,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "transfer_id")]
pub transfer_id: Option<Uuid>,
pub status: DocStatus,
#[serde(alias = "posting_state")]
pub posting_state: GlPostingState,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "journal_id")]
pub journal_id: Option<Uuid>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "accounting_post_id")]
pub accounting_post_id: Option<Uuid>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "posted_at")]
pub posted_at: Option<DateTime<Utc>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub notes: Option<String>,
}
// =============================================================================
// Patch DTO
// =============================================================================
/// Request DTO for partial update of a PurchaseReceipt
///
/// 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))]
#[serde(rename_all = "camelCase")]
pub struct PatchPurchaseReceiptDto {
#[cfg_attr(feature = "openapi", schema(example = "example"))]
#[serde(skip_serializing_if = "Option::is_none", alias = "receipt_number")]
pub receipt_number: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", alias = "branch_id")]
pub branch_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(skip_serializing_if = "Option::is_none", alias = "supplier_id")]
pub supplier_id: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none", alias = "source_po_id")]
pub source_po_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(skip_serializing_if = "Option::is_none", alias = "warehouse_id")]
pub warehouse_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = "2024-01-01"))]
#[serde(skip_serializing_if = "Option::is_none", alias = "posting_date")]
pub posting_date: Option<NaiveDate>,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
#[serde(skip_serializing_if = "Option::is_none")]
pub currency: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", alias = "total_value")]
pub total_value: Option<Decimal>,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(skip_serializing_if = "Option::is_none", alias = "inventory_account_id")]
pub inventory_account_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(skip_serializing_if = "Option::is_none", alias = "grir_account_id")]
pub grir_account_id: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none", alias = "transfer_id")]
pub transfer_id: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<DocStatus>,
#[serde(skip_serializing_if = "Option::is_none", alias = "posting_state")]
pub posting_state: Option<GlPostingState>,
#[serde(skip_serializing_if = "Option::is_none", alias = "journal_id")]
pub journal_id: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none", alias = "accounting_post_id")]
pub accounting_post_id: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none", alias = "posted_at")]
pub posted_at: Option<DateTime<Utc>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub notes: Option<String>,
}
impl PatchPurchaseReceiptDto {
/// Check if any field is set
pub fn has_changes(&self) -> bool {
self.receipt_number.is_some() || self.branch_id.is_some() || self.supplier_id.is_some() || self.source_po_id.is_some() || self.warehouse_id.is_some() || self.posting_date.is_some() || self.currency.is_some() || self.total_value.is_some() || self.inventory_account_id.is_some() || self.grir_account_id.is_some() || self.transfer_id.is_some() || self.status.is_some() || self.posting_state.is_some() || self.journal_id.is_some() || self.accounting_post_id.is_some() || self.posted_at.is_some() || self.notes.is_some()
}
}
// =============================================================================
// Response DTO
// =============================================================================
/// Response DTO for PurchaseReceipt 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 PurchaseReceiptResponseDto {
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
pub id: Uuid,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub receipt_number: String,
pub branch_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
pub supplier_id: Uuid,
pub source_po_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
pub warehouse_id: Uuid,
#[cfg_attr(feature = "openapi", schema(example = "2024-01-01"))]
pub posting_date: NaiveDate,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub currency: String,
pub total_value: Decimal,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
pub inventory_account_id: Uuid,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
pub grir_account_id: Uuid,
pub transfer_id: Option<Uuid>,
pub status: DocStatus,
pub posting_state: GlPostingState,
pub journal_id: Option<Uuid>,
pub accounting_post_id: Option<Uuid>,
pub posted_at: Option<DateTime<Utc>>,
pub notes: Option<String>,
pub metadata: AuditMetadata,
}
// =============================================================================
// List Response DTO
// =============================================================================
/// Paginated list response for PurchaseReceipt 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 PurchaseReceiptListResponseDto {
/// List of items
pub items: Vec<PurchaseReceiptResponseDto>,
/// 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 PurchaseReceiptListResponseDto {
/// Create a new list response from items and pagination info
pub fn new(items: Vec<PurchaseReceiptResponseDto>, 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 PurchaseReceiptSummaryDto {
pub id: Uuid,
pub receipt_number: String,
pub branch_id: Option<Uuid>,
pub supplier_id: Uuid,
pub created_at: Option<DateTime<Utc>>,
}
// =============================================================================
// Conversions
// =============================================================================
impl From<PurchaseReceipt> for PurchaseReceiptResponseDto {
fn from(entity: PurchaseReceipt) -> Self {
Self {
id: entity.id,
receipt_number: entity.receipt_number,
branch_id: entity.branch_id,
supplier_id: entity.supplier_id,
source_po_id: entity.source_po_id,
warehouse_id: entity.warehouse_id,
posting_date: entity.posting_date,
currency: entity.currency,
total_value: entity.total_value,
inventory_account_id: entity.inventory_account_id,
grir_account_id: entity.grir_account_id,
transfer_id: entity.transfer_id,
status: entity.status,
posting_state: entity.posting_state,
journal_id: entity.journal_id,
accounting_post_id: entity.accounting_post_id,
posted_at: entity.posted_at,
notes: entity.notes,
metadata: entity.metadata,
}
}
}
impl From<PurchaseReceipt> for PurchaseReceiptSummaryDto {
fn from(entity: PurchaseReceipt) -> Self {
let created_at = backbone_core::PersistentEntity::created_at(&entity);
Self {
id: entity.id,
receipt_number: entity.receipt_number,
branch_id: entity.branch_id,
supplier_id: entity.supplier_id,
created_at,
}
}
}
impl From<CreatePurchaseReceiptDto> for PurchaseReceipt {
fn from(dto: CreatePurchaseReceiptDto) -> Self {
Self {
id: Uuid::new_v4(),
receipt_number: dto.receipt_number,
branch_id: dto.branch_id,
supplier_id: dto.supplier_id,
source_po_id: dto.source_po_id,
warehouse_id: dto.warehouse_id,
posting_date: dto.posting_date,
currency: dto.currency,
total_value: dto.total_value,
inventory_account_id: dto.inventory_account_id,
grir_account_id: dto.grir_account_id,
transfer_id: dto.transfer_id,
status: DocStatus::Draft,
posting_state: dto.posting_state,
journal_id: dto.journal_id,
accounting_post_id: dto.accounting_post_id,
posted_at: dto.posted_at,
notes: dto.notes,
metadata: AuditMetadata::default(),
}
}
}
impl From<&PurchaseReceipt> for PurchaseReceiptResponseDto {
fn from(entity: &PurchaseReceipt) -> Self {
Self {
id: entity.id.clone(),
receipt_number: entity.receipt_number.clone(),
branch_id: entity.branch_id.clone(),
supplier_id: entity.supplier_id.clone(),
source_po_id: entity.source_po_id.clone(),
warehouse_id: entity.warehouse_id.clone(),
posting_date: entity.posting_date.clone(),
currency: entity.currency.clone(),
total_value: entity.total_value.clone(),
inventory_account_id: entity.inventory_account_id.clone(),
grir_account_id: entity.grir_account_id.clone(),
transfer_id: entity.transfer_id.clone(),
status: entity.status.clone(),
posting_state: entity.posting_state.clone(),
journal_id: entity.journal_id.clone(),
accounting_post_id: entity.accounting_post_id.clone(),
posted_at: entity.posted_at.clone(),
notes: entity.notes.clone(),
metadata: entity.metadata.clone(),
}
}
}
impl backbone_core::FromCreateDto<CreatePurchaseReceiptDto> for PurchaseReceipt {
fn from_create_dto(dto: CreatePurchaseReceiptDto) -> backbone_core::ServiceResult<Self> {
Ok(PurchaseReceipt::from(dto))
}
}
impl backbone_core::ApplyUpdateDto<UpdatePurchaseReceiptDto> for PurchaseReceipt {
fn apply_update(mut self, dto: UpdatePurchaseReceiptDto) -> backbone_core::ServiceResult<Self> {
self.receipt_number = dto.receipt_number;
self.branch_id = dto.branch_id;
self.supplier_id = dto.supplier_id;
self.source_po_id = dto.source_po_id;
self.warehouse_id = dto.warehouse_id;
self.posting_date = dto.posting_date;
self.currency = dto.currency;
self.total_value = dto.total_value;
self.inventory_account_id = dto.inventory_account_id;
self.grir_account_id = dto.grir_account_id;
self.transfer_id = dto.transfer_id;
self.status = dto.status;
self.posting_state = dto.posting_state;
self.journal_id = dto.journal_id;
self.accounting_post_id = dto.accounting_post_id;
self.posted_at = dto.posted_at;
self.notes = dto.notes;
Ok(self)
}
}
// =============================================================================
// Custom DTOs
// =============================================================================
// Add custom DTOs specific to PurchaseReceipt here.
// This section will be preserved during regeneration.
// >>> END CUSTOM DTOs