Class: FE::Document
- Inherits:
-
Object
- Object
- FE::Document
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/facturacr/document.rb,
lib/facturacr/document/fax.rb,
lib/facturacr/document/tax.rb,
lib/facturacr/document/item.rb,
lib/facturacr/document/phone.rb,
lib/facturacr/document/issuer.rb,
lib/facturacr/document/summary.rb,
lib/facturacr/document/location.rb,
lib/facturacr/document/receiver.rb,
lib/facturacr/document/reference.rb,
lib/facturacr/document/phone_type.rb,
lib/facturacr/document/regulation.rb,
lib/facturacr/document/exoneration.rb,
lib/facturacr/document/identification_document.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Exoneration, Fax, IdentificationDocument, Issuer, Item, Location, Phone, PhoneType, Receiver, Reference, Regulation, Summary, Tax
Constant Summary collapse
- CONDITIONS =
{ "01"=>"Contado", "02"=>"Crédito", "03"=>"Consignación", "04"=>"Apartado", "05"=>"Arrendamiento con Opción de Compra", "06"=>"Arrendamiento en Función Financiera", "99"=>"Otros" }
- PAYMENT_TYPES =
{ "01"=>"Efectivo", "02"=>"Tarjeta", "03"=>"Cheque", "04"=>"Transferencia", "05"=>"Recaudado por Terceros", "99"=>"Otros" }
- DOCUMENT_TYPES =
{ "01"=> "Factura Electronica", "02"=> "Nota de débito", "03"=> "Nota de crédito", "04"=> "Tiquete Electrónico", "05"=> "Nota de despacho", "06"=> "Contrato", "07"=> "Procedimiento", "08"=> "Comprobante Emitido en Contingencia", "99"=> "Otros" }
- DOCUMENT_SITUATION =
{ "1" => "Normal", "2" => "Contingencia", "3" => "Sin Internet" }
Instance Attribute Summary collapse
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#credit_term ⇒ Object
Returns the value of attribute credit_term.
-
#date ⇒ Object
Returns the value of attribute date.
-
#document_situation ⇒ Object
Returns the value of attribute document_situation.
-
#document_type ⇒ Object
Returns the value of attribute document_type.
-
#issuer ⇒ Object
Returns the value of attribute issuer.
-
#items ⇒ Object
Returns the value of attribute items.
-
#namespaces ⇒ Object
Returns the value of attribute namespaces.
-
#number ⇒ Object
Returns the value of attribute number.
-
#payment_type ⇒ Object
Returns the value of attribute payment_type.
-
#receiver ⇒ Object
Returns the value of attribute receiver.
-
#reference_information ⇒ Object
Returns the value of attribute reference_information.
-
#references ⇒ Object
Returns the value of attribute references.
-
#regulation ⇒ Object
Returns the value of attribute regulation.
-
#security_code ⇒ Object
Returns the value of attribute security_code.
-
#serial ⇒ Object
Returns the value of attribute serial.
-
#service_type ⇒ Object
Returns the value of attribute service_type.
-
#summary ⇒ Object
Returns the value of attribute summary.
Instance Method Summary collapse
- #api_payload ⇒ Object
- #build_xml ⇒ Object
- #document_name ⇒ Object
- #generate ⇒ Object
- #headquarters ⇒ Object
-
#initialize ⇒ Document
constructor
A new instance of Document.
- #key ⇒ Object
- #sequence ⇒ Object
- #terminal ⇒ Object
Constructor Details
#initialize ⇒ Document
Returns a new instance of Document.
61 62 63 |
# File 'lib/facturacr/document.rb', line 61 def initialize raise "Subclasses must implement this method" end |
Instance Attribute Details
#condition ⇒ Object
Returns the value of attribute condition.
42 43 44 |
# File 'lib/facturacr/document.rb', line 42 def condition @condition end |
#credit_term ⇒ Object
Returns the value of attribute credit_term.
42 43 44 |
# File 'lib/facturacr/document.rb', line 42 def credit_term @credit_term end |
#date ⇒ Object
Returns the value of attribute date.
42 43 44 |
# File 'lib/facturacr/document.rb', line 42 def date @date end |
#document_situation ⇒ Object
Returns the value of attribute document_situation.
42 43 44 |
# File 'lib/facturacr/document.rb', line 42 def document_situation @document_situation end |
#document_type ⇒ Object
Returns the value of attribute document_type.
42 43 44 |
# File 'lib/facturacr/document.rb', line 42 def document_type @document_type end |
#issuer ⇒ Object
Returns the value of attribute issuer.
42 43 44 |
# File 'lib/facturacr/document.rb', line 42 def issuer @issuer end |
#items ⇒ Object
Returns the value of attribute items.
42 43 44 |
# File 'lib/facturacr/document.rb', line 42 def items @items end |
#namespaces ⇒ Object
Returns the value of attribute namespaces.
42 43 44 |
# File 'lib/facturacr/document.rb', line 42 def namespaces @namespaces end |
#number ⇒ Object
Returns the value of attribute number.
42 43 44 |
# File 'lib/facturacr/document.rb', line 42 def number @number end |
#payment_type ⇒ Object
Returns the value of attribute payment_type.
42 43 44 |
# File 'lib/facturacr/document.rb', line 42 def payment_type @payment_type end |
#receiver ⇒ Object
Returns the value of attribute receiver.
42 43 44 |
# File 'lib/facturacr/document.rb', line 42 def receiver @receiver end |
#reference_information ⇒ Object
Returns the value of attribute reference_information.
42 43 44 |
# File 'lib/facturacr/document.rb', line 42 def reference_information @reference_information end |
#references ⇒ Object
Returns the value of attribute references.
42 43 44 |
# File 'lib/facturacr/document.rb', line 42 def references @references end |
#regulation ⇒ Object
Returns the value of attribute regulation.
42 43 44 |
# File 'lib/facturacr/document.rb', line 42 def regulation @regulation end |
#security_code ⇒ Object
Returns the value of attribute security_code.
42 43 44 |
# File 'lib/facturacr/document.rb', line 42 def security_code @security_code end |
#serial ⇒ Object
Returns the value of attribute serial.
42 43 44 |
# File 'lib/facturacr/document.rb', line 42 def serial @serial end |
#service_type ⇒ Object
Returns the value of attribute service_type.
42 43 44 |
# File 'lib/facturacr/document.rb', line 42 def service_type @service_type end |
#summary ⇒ Object
Returns the value of attribute summary.
42 43 44 |
# File 'lib/facturacr/document.rb', line 42 def summary @summary end |
Instance Method Details
#api_payload ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/facturacr/document.rb', line 136 def api_payload payload = {} payload[:clave] = key payload[:fecha] = @date.xmlschema payload[:emisor] = { tipoIdentificacion: @issuer.identification_document.document_type, numeroIdentificacion: @issuer.identification_document.id_number } if @receiver.identification_document.present? payload[:receptor] = { tipoIdentificacion: @receiver.identification_document.document_type, numeroIdentificacion: @receiver.identification_document.id_number } end payload end |
#build_xml ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/facturacr/document.rb', line 99 def build_xml raise "Documento inválido: #{errors.}" unless valid? builder = Nokogiri::XML::Builder.new builder.send(document_tag, @namespaces) do |xml| xml.Clave key xml.NumeroConsecutivo sequence xml.FechaEmision @date.xmlschema issuer.build_xml(xml) receiver.build_xml(xml) if receiver.present? xml.CondicionVenta @condition xml.PlazoCredito @credit_term if @credit_term.present? && @condition.eql?("02") xml.MedioPago @payment_type xml.DetalleServicio do |x| @items.each do |item| item.build_xml(x) end end summary.build_xml(xml) if references.present? references.each do |r| r.build_xml(xml) end end regulation.build_xml(xml) end builder end |
#document_name ⇒ Object
65 66 67 |
# File 'lib/facturacr/document.rb', line 65 def document_name raise "Subclasses must implement this method" end |
#generate ⇒ Object
132 133 134 |
# File 'lib/facturacr/document.rb', line 132 def generate build_xml.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML) end |
#headquarters ⇒ Object
86 87 88 |
# File 'lib/facturacr/document.rb', line 86 def headquarters @headquarters ||= "001" end |
#key ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/facturacr/document.rb', line 69 def key raise "Documento inválido: #{errors.}" unless valid? country = "506" day = "%02d" % @date.day month = "%02d" % @date.month year = "%02d" % (@date.year - 2000) id_number = @issuer.identification_document.id_number type = @document_situation security_code = @security_code result = "#{country}#{day}#{month}#{year}#{id_number}#{sequence}#{type}#{security_code}" raise "The key is invalid: #{result}" unless result.length.eql?(50) result end |
#sequence ⇒ Object
94 95 96 97 |
# File 'lib/facturacr/document.rb', line 94 def sequence cons = ("%010d" % @number) "#{headquarters}#{terminal}#{@document_type}#{cons}" end |
#terminal ⇒ Object
90 91 92 |
# File 'lib/facturacr/document.rb', line 90 def terminal @terminal ||= "00001" end |