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/other_text.rb,
lib/facturacr/document/phone_type.rb,
lib/facturacr/document/regulation.rb,
lib/facturacr/document/exoneration.rb,
lib/facturacr/document/other_charges.rb,
lib/facturacr/document/other_content.rb,
lib/facturacr/document/identification_document.rb,
lib/facturacr/document/other_content/price_smart.rb
Direct Known Subclasses
CreditNote, DebitNote, ExportInvoice, Invoice, PurchaseInvoice, Ticket
Defined Under Namespace
Classes: Exoneration, Fax, IdentificationDocument, Issuer, Item, Location, OtherCharges, OtherContent, OtherText, 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", "07"=>"Cobro a favor de un tercero", "08"=>"Servicios prestados al Estado a crédito ", "09"=>"Pago del servicios prestado al Estado ", "99"=>"Otros" }.freeze
- PAYMENT_TYPES =
{ "01"=>"Efectivo", "02"=>"Tarjeta", "03"=>"Cheque", "04"=>"Transferencia", "05"=>"Recaudado por Terceros", "99"=>"Otros" }.freeze
- 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"=> "Factura Electrónica de compra", "09"=> "Factura Electronica de exportación" }.freeze
- DOCUMENT_SITUATION =
{ "1" => "Normal", "2" => "Contingencia", "3" => "Sin Internet" }.freeze
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.
-
#economic_activity ⇒ Object
Returns the value of attribute economic_activity.
-
#headquarters ⇒ Object
Returns the value of attribute headquarters.
-
#issuer ⇒ Object
Returns the value of attribute issuer.
-
#items ⇒ Object
Returns the value of attribute items.
-
#key ⇒ Object
Returns the value of attribute key.
-
#namespaces ⇒ Object
Returns the value of attribute namespaces.
-
#number ⇒ Object
Returns the value of attribute number.
-
#other_charges ⇒ Object
Returns the value of attribute other_charges.
-
#others ⇒ Object
Returns the value of attribute others.
-
#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.
-
#terminal ⇒ Object
Returns the value of attribute terminal.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #api_payload ⇒ Object
- #build_xml ⇒ Object
- #document_name ⇒ Object
- #generate ⇒ Object
-
#initialize ⇒ Document
constructor
A new instance of Document.
- #sequence ⇒ Object
- #version_42? ⇒ Boolean
- #version_43? ⇒ Boolean
Constructor Details
Instance Attribute Details
#condition ⇒ Object
Returns the value of attribute condition.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def condition @condition end |
#credit_term ⇒ Object
Returns the value of attribute credit_term.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def credit_term @credit_term end |
#date ⇒ Object
Returns the value of attribute date.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def date @date end |
#document_situation ⇒ Object
Returns the value of attribute document_situation.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def document_situation @document_situation end |
#document_type ⇒ Object
Returns the value of attribute document_type.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def document_type @document_type end |
#economic_activity ⇒ Object
Returns the value of attribute economic_activity.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def economic_activity @economic_activity end |
#headquarters ⇒ Object
Returns the value of attribute headquarters.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def headquarters @headquarters end |
#issuer ⇒ Object
Returns the value of attribute issuer.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def issuer @issuer end |
#items ⇒ Object
Returns the value of attribute items.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def items @items end |
#key ⇒ Object
Returns the value of attribute key.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def key @key end |
#namespaces ⇒ Object
Returns the value of attribute namespaces.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def namespaces @namespaces end |
#number ⇒ Object
Returns the value of attribute number.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def number @number end |
#other_charges ⇒ Object
Returns the value of attribute other_charges.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def other_charges @other_charges end |
#others ⇒ Object
Returns the value of attribute others.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def others @others end |
#payment_type ⇒ Object
Returns the value of attribute payment_type.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def payment_type @payment_type end |
#receiver ⇒ Object
Returns the value of attribute receiver.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def receiver @receiver end |
#reference_information ⇒ Object
Returns the value of attribute reference_information.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def reference_information @reference_information end |
#references ⇒ Object
Returns the value of attribute references.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def references @references end |
#regulation ⇒ Object
Returns the value of attribute regulation.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def regulation @regulation end |
#security_code ⇒ Object
Returns the value of attribute security_code.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def security_code @security_code end |
#serial ⇒ Object
Returns the value of attribute serial.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def serial @serial end |
#service_type ⇒ Object
Returns the value of attribute service_type.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def service_type @service_type end |
#summary ⇒ Object
Returns the value of attribute summary.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def summary @summary end |
#terminal ⇒ Object
Returns the value of attribute terminal.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def terminal @terminal end |
#version ⇒ Object
Returns the value of attribute version.
45 46 47 |
# File 'lib/facturacr/document.rb', line 45 def version @version end |
Instance Method Details
#api_payload ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/facturacr/document.rb', line 176 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
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/facturacr/document.rb', line 116 def build_xml raise FE::Error.new "Documento inválido #{errors.}", class: self.class, messages: errors. unless valid? builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') builder.send(document_tag, @namespaces) do |xml| xml.Clave key xml.CodigoActividad @economic_activity if version_43? xml.NumeroConsecutivo sequence xml.FechaEmision @date.xmlschema issuer.build_xml(xml, self) receiver.build_xml(xml,self) if receiver.present? xml.CondicionVenta @condition xml.PlazoCredito @credit_term if @credit_term.present? && @condition.eql?("02") @payment_type.each do |pt| @summary.with_credit_card = true if pt.eql?("02") xml.MedioPago pt end xml.DetalleServicio do |x| @items.each do |item| item.build_xml(x, self) end end if other_charges.present? @other_charges.each do |other_charge| other_charge.build_xml(xml, self) end end #other_charges.build_xml(xml,self) if other_charges.present? && version_43? # see this summary.build_xml(xml, self) if references.present? references.each do |r| r.build_xml(xml, self) end end regulation.build_xml(xml,self) if version_42? if others.any? xml.Otros do |x| @others.each do |o| o.build_xml(x, self) end end end end builder end |
#document_name ⇒ Object
72 73 74 |
# File 'lib/facturacr/document.rb', line 72 def document_name raise FE::Error "Subclasses must implement this method" end |
#generate ⇒ Object
172 173 174 |
# File 'lib/facturacr/document.rb', line 172 def generate build_xml.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML) end |
#sequence ⇒ Object
103 104 105 106 |
# File 'lib/facturacr/document.rb', line 103 def sequence cons = ("%010d" % @number) "#{headquarters}#{terminal}#{@document_type}#{cons}" end |
#version_42? ⇒ Boolean
108 109 110 |
# File 'lib/facturacr/document.rb', line 108 def version_42? @version.eql?("4.2") end |
#version_43? ⇒ Boolean
112 113 114 |
# File 'lib/facturacr/document.rb', line 112 def version_43? @version.eql?("4.3") end |