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" }
Instance Attribute Summary collapse
-
#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.
-
#issuer_id_number ⇒ Object
Returns the value of attribute issuer_id_number.
-
#key ⇒ Object
Returns the value of attribute key.
-
#message ⇒ Object
Returns the value of attribute message.
-
#number ⇒ Object
Returns the value of attribute number.
-
#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.
-
#total ⇒ Object
Returns the value of attribute total.
Instance Method Summary collapse
- #api_payload ⇒ Object
- #build_xml ⇒ Object
- #generate ⇒ Object
- #headquarters ⇒ Object
-
#initialize(args = {}) ⇒ ReceptionMessage
constructor
A new instance of ReceptionMessage.
- #sequence ⇒ Object
- #terminal ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ ReceptionMessage
Returns a new instance of ReceptionMessage.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/facturacr/reception_message.rb', line 23 def initialize(args = {}) @key = args[:key] @date = args[:date] @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 = { "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" } end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
12 13 14 |
# File 'lib/facturacr/reception_message.rb', line 12 def date @date end |
#details ⇒ Object
Returns the value of attribute details.
12 13 14 |
# File 'lib/facturacr/reception_message.rb', line 12 def details @details end |
#document_situation ⇒ Object
Returns the value of attribute document_situation.
12 13 14 |
# File 'lib/facturacr/reception_message.rb', line 12 def document_situation @document_situation end |
#issuer_id_number ⇒ Object
Returns the value of attribute issuer_id_number.
12 13 14 |
# File 'lib/facturacr/reception_message.rb', line 12 def issuer_id_number @issuer_id_number end |
#key ⇒ Object
Returns the value of attribute key.
12 13 14 |
# File 'lib/facturacr/reception_message.rb', line 12 def key @key end |
#message ⇒ Object
Returns the value of attribute message.
12 13 14 |
# File 'lib/facturacr/reception_message.rb', line 12 def @message end |
#number ⇒ Object
Returns the value of attribute number.
12 13 14 |
# File 'lib/facturacr/reception_message.rb', line 12 def number @number end |
#receiver_id_number ⇒ Object
Returns the value of attribute receiver_id_number.
12 13 14 |
# File 'lib/facturacr/reception_message.rb', line 12 def receiver_id_number @receiver_id_number end |
#receiver_id_type ⇒ Object
Returns the value of attribute receiver_id_type.
12 13 14 |
# File 'lib/facturacr/reception_message.rb', line 12 def receiver_id_type @receiver_id_type end |
#security_code ⇒ Object
Returns the value of attribute security_code.
12 13 14 |
# File 'lib/facturacr/reception_message.rb', line 12 def security_code @security_code end |
#tax ⇒ Object
Returns the value of attribute tax.
12 13 14 |
# File 'lib/facturacr/reception_message.rb', line 12 def tax @tax end |
#total ⇒ Object
Returns the value of attribute total.
12 13 14 |
# File 'lib/facturacr/reception_message.rb', line 12 def total @total end |
Instance Method Details
#api_payload ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/facturacr/reception_message.rb', line 105 def api_payload payload = {} payload[:clave] = key payload[:fecha] = @date.xmlschema payload[:emisor] = { tipoIdentificacion: @receiver_id_type, numeroIdentificacion: @receiver_id_number } payload end |
#build_xml ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/facturacr/reception_message.rb', line 82 def build_xml raise "Documento inválido: #{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 if @tax xml.TotalFactura @total xml.NumeroCedulaReceptor @receiver_id_number xml.NumConsecutivoReceptor sequence end builder end |
#generate ⇒ Object
101 102 103 |
# File 'lib/facturacr/reception_message.rb', line 101 def generate build_xml.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML) end |
#headquarters ⇒ Object
60 61 62 |
# File 'lib/facturacr/reception_message.rb', line 60 def headquarters @headquarters ||= "001" end |
#sequence ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/facturacr/reception_message.rb', line 68 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 |
#terminal ⇒ Object
64 65 66 |
# File 'lib/facturacr/reception_message.rb', line 64 def terminal @terminal ||= "00001" end |