use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum CpeTipoAfectacionIgv {
GravadoOperacionOnerosa,
GravadoRetiroPremio,
GravadoRetiroDonacion,
GravadoRetiro,
GravadoRetiroPublicidad,
GravadoBonificaciones,
GravadoRetiroTrabajadores,
GravadoIvap,
ExoneradoOperacionOnerosa,
ExoneradoTransferenciaGratuita,
InafectoOperacionOnerosa,
InafectoRetiroBonificacion,
InafectoRetiro,
InafectoRetiroMuestrasMedicas,
InafectoRetiroConvenioColectivo,
InafectoRetiroPremio,
InafectoRetiroPublicidad,
InafectoTransferenciaGratuita,
Exportacion,
Otro(String),
}
impl CpeTipoAfectacionIgv {
#[must_use]
pub fn codigo(&self) -> &str {
match self {
Self::GravadoOperacionOnerosa => "10",
Self::GravadoRetiroPremio => "11",
Self::GravadoRetiroDonacion => "12",
Self::GravadoRetiro => "13",
Self::GravadoRetiroPublicidad => "14",
Self::GravadoBonificaciones => "15",
Self::GravadoRetiroTrabajadores => "16",
Self::GravadoIvap => "17",
Self::ExoneradoOperacionOnerosa => "20",
Self::ExoneradoTransferenciaGratuita => "21",
Self::InafectoOperacionOnerosa => "30",
Self::InafectoRetiroBonificacion => "31",
Self::InafectoRetiro => "32",
Self::InafectoRetiroMuestrasMedicas => "33",
Self::InafectoRetiroConvenioColectivo => "34",
Self::InafectoRetiroPremio => "35",
Self::InafectoRetiroPublicidad => "36",
Self::InafectoTransferenciaGratuita => "37",
Self::Exportacion => "40",
Self::Otro(c) => c.as_str(),
}
}
#[must_use]
pub fn codigo_tributo_ubl(&self) -> &str {
match self {
Self::GravadoOperacionOnerosa
| Self::GravadoRetiroPremio
| Self::GravadoRetiroDonacion
| Self::GravadoRetiro
| Self::GravadoRetiroPublicidad
| Self::GravadoBonificaciones
| Self::GravadoRetiroTrabajadores
| Self::GravadoIvap => "1000", Self::ExoneradoOperacionOnerosa | Self::ExoneradoTransferenciaGratuita => "9997", Self::InafectoOperacionOnerosa
| Self::InafectoRetiroBonificacion
| Self::InafectoRetiro
| Self::InafectoRetiroMuestrasMedicas
| Self::InafectoRetiroConvenioColectivo
| Self::InafectoRetiroPremio
| Self::InafectoRetiroPublicidad
| Self::InafectoTransferenciaGratuita => "9998", Self::Exportacion => "9995", Self::Otro(_) => "9996", }
}
#[must_use]
pub fn es_operacion_onerosa(&self) -> bool {
matches!(
self,
Self::GravadoOperacionOnerosa
| Self::ExoneradoOperacionOnerosa
| Self::InafectoOperacionOnerosa
| Self::Exportacion
)
}
#[must_use]
pub fn es_gratuita(&self) -> bool {
!self.es_operacion_onerosa()
}
#[must_use]
pub fn desde_codigo(codigo: &str) -> Self {
match codigo.trim() {
"10" => Self::GravadoOperacionOnerosa,
"11" => Self::GravadoRetiroPremio,
"12" => Self::GravadoRetiroDonacion,
"13" => Self::GravadoRetiro,
"14" => Self::GravadoRetiroPublicidad,
"15" => Self::GravadoBonificaciones,
"16" => Self::GravadoRetiroTrabajadores,
"17" => Self::GravadoIvap,
"20" => Self::ExoneradoOperacionOnerosa,
"21" => Self::ExoneradoTransferenciaGratuita,
"30" => Self::InafectoOperacionOnerosa,
"31" => Self::InafectoRetiroBonificacion,
"32" => Self::InafectoRetiro,
"33" => Self::InafectoRetiroMuestrasMedicas,
"34" => Self::InafectoRetiroConvenioColectivo,
"35" => Self::InafectoRetiroPremio,
"36" => Self::InafectoRetiroPublicidad,
"37" => Self::InafectoTransferenciaGratuita,
"40" => Self::Exportacion,
otro => Self::Otro(otro.to_string()),
}
}
}
impl fmt::Display for CpeTipoAfectacionIgv {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.codigo())
}
}