use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum CpeTipoNotaCredito {
AnulacionOperacion,
AnulacionPorErrorEnRuc,
CorreccionPorErrorEnDescripcion,
DescuentoGlobal,
DescuentoPorItem,
DevolucionTotal,
DevolucionPorItem,
Bonificacion,
DisminucionEnValor,
OtrosConceptos,
AjustesExportacion,
AjustesIvap,
CorreccionMontoNetoOFechasPago,
Otro(String),
}
impl CpeTipoNotaCredito {
#[must_use]
pub fn codigo(&self) -> &str {
match self {
Self::AnulacionOperacion => "01",
Self::AnulacionPorErrorEnRuc => "02",
Self::CorreccionPorErrorEnDescripcion => "03",
Self::DescuentoGlobal => "04",
Self::DescuentoPorItem => "05",
Self::DevolucionTotal => "06",
Self::DevolucionPorItem => "07",
Self::Bonificacion => "08",
Self::DisminucionEnValor => "09",
Self::OtrosConceptos => "10",
Self::AjustesExportacion => "11",
Self::AjustesIvap => "12",
Self::CorreccionMontoNetoOFechasPago => "13",
Self::Otro(c) => c.as_str(),
}
}
#[must_use]
pub fn descripcion(&self) -> &str {
match self {
Self::AnulacionOperacion => "Anulación de la operación",
Self::AnulacionPorErrorEnRuc => "Anulación por error en el RUC",
Self::CorreccionPorErrorEnDescripcion => "Corrección por error en la descripción",
Self::DescuentoGlobal => "Descuento global",
Self::DescuentoPorItem => "Descuento por ítem",
Self::DevolucionTotal => "Devolución total",
Self::DevolucionPorItem => "Devolución por ítem",
Self::Bonificacion => "Bonificación",
Self::DisminucionEnValor => "Disminución en el valor",
Self::OtrosConceptos => "Otros Conceptos",
Self::AjustesExportacion => "Ajustes de operaciones de exportación",
Self::AjustesIvap => "Ajustes afectos al IVAP",
Self::CorreccionMontoNetoOFechasPago => {
"Corrección del monto neto pendiente de pago y/o fechas de cuotas"
}
Self::Otro(_) => "Otro motivo de Nota de Crédito",
}
}
#[must_use]
pub fn desde_codigo(codigo: &str) -> Self {
match codigo.trim() {
"01" => Self::AnulacionOperacion,
"02" => Self::AnulacionPorErrorEnRuc,
"03" => Self::CorreccionPorErrorEnDescripcion,
"04" => Self::DescuentoGlobal,
"05" => Self::DescuentoPorItem,
"06" => Self::DevolucionTotal,
"07" => Self::DevolucionPorItem,
"08" => Self::Bonificacion,
"09" => Self::DisminucionEnValor,
"10" => Self::OtrosConceptos,
"11" => Self::AjustesExportacion,
"12" => Self::AjustesIvap,
"13" => Self::CorreccionMontoNetoOFechasPago,
otro => Self::Otro(otro.to_string()),
}
}
}
impl fmt::Display for CpeTipoNotaCredito {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.codigo())
}
}