Class: FE::ReceptionMessage
- Inherits:
-
Object
- Object
- FE::ReceptionMessage
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/facturacr/reception_message.rb
Constant Summary collapse
- MESSAGE_TYPES =
{ "1" => "Aceptado", "2" => "Aceptacion Parcial", "3" => "Rechazado" }.freeze
- TAX_CONDITION =
{ "01" => "Genera crédito IVA", "02" => "Genera Crédito parcial del IVA", "03" => "Bienes de Capital", "04" => "Gasto corriente", "05" => "Proporcionalidad" }.freeze
- NAMESPACES =
{ "4.2" => { "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance", "xmlns:xsd"=>"http://www.w3.org/2001/XMLSchema", "xmlns"=>"https://tribunet.hacienda.go.cr/docs/esquemas/2017/v4.2/mensajeReceptor" }, "4.3" => { "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance", "xmlns:xsd"=>"http://www.w3.org/2001/XMLSchema", "xmlns"=>"https://cdn.comprobanteselectronicos.go.cr/xml-schemas/v4.3/mensajeReceptor" } }
Instance Attribute Summary collapse
-
#applicable_expense ⇒ Object
Returns the value of attribute applicable_expense.
-
#creditable_tax ⇒ Object
Returns the value of attribute creditable_tax.
-
#date ⇒ Object
Returns the value of attribute date.
-
#details ⇒ Object
Returns the value of attribute details.
-
#document_situation ⇒ Object
Returns the value of attribute document_situation.
-
#economic_activity ⇒ Object
Returns the value of attribute economic_activity.
- #headquarters ⇒ Object
-
#issuer_id_number ⇒ Object
Returns the value of attribute issuer_id_number.
-
#issuer_id_type ⇒ Object
Returns the value of attribute issuer_id_type.
-
#key ⇒ Object
Returns the value of attribute key.
-
#message ⇒ Object
Returns the value of attribute message.
-
#number ⇒ Object
Returns the value of attribute number.
-
#original_version ⇒ Object
Returns the value of attribute original_version.
-
#receiver_id_number ⇒ Object
Returns the value of attribute receiver_id_number.
-
#receiver_id_type ⇒ Object
Returns the value of attribute receiver_id_type.
-
#security_code ⇒ Object
Returns the value of attribute security_code.
-
#tax ⇒ Object
Returns the value of attribute tax.
-
#tax_condition ⇒ Object
Returns the value of attribute tax_condition.
- #terminal ⇒ Object
-
#total ⇒ Object
Returns the value of attribute total.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #api_payload ⇒ Object
- #build_xml ⇒ Object
- #generate ⇒ Object
- #infer_id_type(id_number) ⇒ Object
-
#initialize(args = {}) ⇒ ReceptionMessage
constructor
A new instance of ReceptionMessage.
- #sequence ⇒ Object
- #version_42? ⇒ Boolean
- #version_43? ⇒ Boolean
Constructor Details
#initialize(args = {}) ⇒ ReceptionMessage
Returns a new instance of ReceptionMessage.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/facturacr/reception_message.rb', line 55 def initialize(args = {}) @version = args[:version] @original_version = args[:original_version] @key = args[:key] @date = args[:date] @issuer_id_type = args[:issuer_id_type] @issuer_id_number = args[:issuer_id_number] @receiver_id_type = args[:receiver_id_type] @receiver_id_number = args[:receiver_id_number] @message = args[:message].to_s @details = args[:details] @tax = args[:tax] @total = args[:total] @number = args[:number].to_i @security_code = args[:security_code] @document_situation = args[:document_situation] @namespaces = NAMESPACES[@version] @tax_condition = args[:tax_condition] @economic_activity = args[:economic_activity] @creditable_tax = args[:creditable_tax] @applicable_expense = args[:applicable_expense] end |
Instance Attribute Details
#applicable_expense ⇒ Object
Returns the value of attribute applicable_expense.
34 35 36 |
# File 'lib/facturacr/reception_message.rb', line 34 def applicable_expense @applicable_expense end |
#creditable_tax ⇒ Object
Returns the value of attribute creditable_tax.
34 35 36 |
# File 'lib/facturacr/reception_message.rb', line 34 def creditable_tax @creditable_tax end |
#date ⇒ Object
Returns the value of attribute date.
34 35 36 |
# File 'lib/facturacr/reception_message.rb', line 34 def date @date end |
#details ⇒ Object
Returns the value of attribute details.
34 35 36 |
# File 'lib/facturacr/reception_message.rb', line 34 def details @details end |
#document_situation ⇒ Object
Returns the value of attribute document_situation.
34 35 36 |
# File 'lib/facturacr/reception_message.rb', line 34 def document_situation @document_situation end |
#economic_activity ⇒ Object
Returns the value of attribute economic_activity.
34 35 36 |
# File 'lib/facturacr/reception_message.rb', line 34 def economic_activity @economic_activity end |
#headquarters ⇒ Object
79 80 81 |
# File 'lib/facturacr/reception_message.rb', line 79 def headquarters @headquarters ||= "001" end |
#issuer_id_number ⇒ Object
Returns the value of attribute issuer_id_number.
34 35 36 |
# File 'lib/facturacr/reception_message.rb', line 34 def issuer_id_number @issuer_id_number end |
#issuer_id_type ⇒ Object
Returns the value of attribute issuer_id_type.
34 35 36 |
# File 'lib/facturacr/reception_message.rb', line 34 def issuer_id_type @issuer_id_type end |
#key ⇒ Object
Returns the value of attribute key.
34 35 36 |
# File 'lib/facturacr/reception_message.rb', line 34 def key @key end |
#message ⇒ Object
Returns the value of attribute message.
34 35 36 |
# File 'lib/facturacr/reception_message.rb', line 34 def @message end |
#number ⇒ Object
Returns the value of attribute number.
34 35 36 |
# File 'lib/facturacr/reception_message.rb', line 34 def number @number end |
#original_version ⇒ Object
Returns the value of attribute original_version.
34 35 36 |
# File 'lib/facturacr/reception_message.rb', line 34 def original_version @original_version end |
#receiver_id_number ⇒ Object
Returns the value of attribute receiver_id_number.
34 35 36 |
# File 'lib/facturacr/reception_message.rb', line 34 def receiver_id_number @receiver_id_number end |
#receiver_id_type ⇒ Object
Returns the value of attribute receiver_id_type.
34 35 36 |
# File 'lib/facturacr/reception_message.rb', line 34 def receiver_id_type @receiver_id_type end |
#security_code ⇒ Object
Returns the value of attribute security_code.
34 35 36 |
# File 'lib/facturacr/reception_message.rb', line 34 def security_code @security_code end |
#tax ⇒ Object
Returns the value of attribute tax.
34 35 36 |
# File 'lib/facturacr/reception_message.rb', line 34 def tax @tax end |
#tax_condition ⇒ Object
Returns the value of attribute tax_condition.
34 35 36 |
# File 'lib/facturacr/reception_message.rb', line 34 def tax_condition @tax_condition end |
#terminal ⇒ Object
83 84 85 |
# File 'lib/facturacr/reception_message.rb', line 83 def terminal @terminal ||= "00001" end |
#total ⇒ Object
Returns the value of attribute total.
34 35 36 |
# File 'lib/facturacr/reception_message.rb', line 34 def total @total end |
#version ⇒ Object
Returns the value of attribute version.
34 35 36 |
# File 'lib/facturacr/reception_message.rb', line 34 def version @version end |
Instance Method Details
#api_payload ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/facturacr/reception_message.rb', line 138 def api_payload payload = {} payload[:clave] = @key payload[:fecha] = @date.xmlschema payload[:emisor] = { tipoIdentificacion: infer_id_type(@issuer_id_number), numeroIdentificacion: @issuer_id_number } payload[:receptor] = { tipoIdentificacion: infer_id_type(@receiver_id_number), numeroIdentificacion: @receiver_id_number } payload[:consecutivoReceptor] = sequence payload end |
#build_xml ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/facturacr/reception_message.rb', line 108 def build_xml raise FE::Error.new "Documento inválido #{errors.}", class: self.class, messages: errors. unless valid? builder = Nokogiri::XML::Builder.new builder.MensajeReceptor(@namespaces) do |xml| xml.Clave @key xml.NumeroCedulaEmisor @issuer_id_number xml.FechaEmisionDoc @date.xmlschema xml.Mensaje @message xml.DetalleMensaje @details if @details xml.MontoTotalImpuesto @tax.to_f if @tax if version_43? && @original_version.eql?("4.3") xml.CodigoActividad @economic_activity if @economic_activity.present? xml.CondicionImpuesto @tax_condition if @tax_condition.present? xml.MontoImpuestoAcreditar @creditable_tax.to_f if @creditable_tax.present? xml.MontoTotalDeGastoAplicable @applicable_expense.to_f if @applicable_expense.present? end xml.TotalFactura @total xml.NumeroCedulaReceptor @receiver_id_number xml.NumeroConsecutivoReceptor sequence end builder end |
#generate ⇒ Object
134 135 136 |
# File 'lib/facturacr/reception_message.rb', line 134 def generate build_xml.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML) end |
#infer_id_type(id_number) ⇒ Object
155 156 157 158 159 160 161 162 163 |
# File 'lib/facturacr/reception_message.rb', line 155 def infer_id_type(id_number) if id_number.to_i.to_s.size == 9 "01" elsif id_number.to_i.to_s.size == 10 "02" elsif id_number.to_i.to_s.size == 11 "03" end end |
#sequence ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/facturacr/reception_message.rb', line 87 def sequence if @message.eql?("1") @document_type = "05" elsif @message.eql?("2") @document_type = "06" elsif @message.eql?("3") @document_type = "07" end cons = ("%010d" % @number) "#{headquarters}#{terminal}#{@document_type}#{cons}" end |
#version_42? ⇒ Boolean
99 100 101 |
# File 'lib/facturacr/reception_message.rb', line 99 def version_42? @version.eql?("4.2") end |
#version_43? ⇒ Boolean
103 104 105 |
# File 'lib/facturacr/reception_message.rb', line 103 def version_43? @version.eql?("4.3") end |