Class: DtefacilXmlBuilder::DteBuilder
- Inherits:
-
Object
- Object
- DtefacilXmlBuilder::DteBuilder
- Defined in:
- lib/dtefacil_xml_builder/dte_builder.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_actividades_economicas(actividades_economicas) ⇒ Object
- #create_detalles(detalles, descuento) ⇒ Object
- #create_emisor(nombre) ⇒ Object
- #create_receptor(receptor) ⇒ Object
Class Method Details
.gen_xml(invoice, payment, client) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dtefacil_xml_builder/dte_builder.rb', line 31 def self.gen_xml invoice, payment, client xml = Builder::XmlMarkup.new xml.instruct!(:xml, version: "1.0", encoding: "ISO-8859-1") xml.facturaElectronica(xmlns: "http://dtefacil.cl/1.2"){ |fac| fac.actividadEconomica 1234; #actividad economica de Acid fac.receptor { |rec| rec.rut client.rut.first(client.rut.size - 1) + "-" + client.rut.last rec.razonSocial client.name; rec.giro client.giro; rec.ubicacion { |ub| ub.direccion client.adress; #address feo feo feo ub.comuna client.comuna; ub.ciudad client.ciudad; } } fac.detalles { |dets| dets.detalle { |det| det.nombre payment.name; det.cantidad 1; det.precioUnitario invoice.amount; } } } end |
Instance Method Details
#create_actividades_economicas(actividades_economicas) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/dtefacil_xml_builder/dte_builder.rb', line 6 def create_actividades_economicas actividades_economicas builder = Builder::XmlMarkup.new actividades_economicas.each do |act| #builder.actividadEconomica "asdfasdf" puts "asdfasf" end #builder.actividadEconomica "asdfas" end |
#create_detalles(detalles, descuento) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/dtefacil_xml_builder/dte_builder.rb', line 62 def create_detalles detalles, descuento builder = Builder::XmlMarkup.new builder.detalles { |d| if descuento d.descuento{ |desc| desc.porcentaje(descuento) } end detalles.each do |detalle| d.detalle{ |det| det.nombre(detalle.nombre) det.cantidad(detalle.cantidad) det.precioUnitario(detalle.precio_unitario) if detalle.unidad det.unidad(detalle.unidad) end if detalle.descuento det.descuento{ |desc_det| desc_det.porcentaje(detalle.descuento) } end if detalle.exento det.observaciones{ |obs| obs.exento } end } end } end |
#create_emisor(nombre) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dtefacil_xml_builder/dte_builder.rb', line 15 def create_emisor nombre builder = Builder::XmlMarkup.new :target => STDOUT builder.instruct!(:xml, version: "1.0", encoding: "ISO-8859-1") builder.usuario(tipo: "emisor", xmlns: "http://dtefacil.cl/1.2"){ |u| u.nombre nombre; u.clave "123456"; u.sucursal{ |s| s.nombre "primera"; s.codigo 4; } } end |
#create_receptor(receptor) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/dtefacil_xml_builder/dte_builder.rb', line 102 def create_receptor receptor builder = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2) builder.receptor { |r| r.rut(receptor.rut) r.razonSocial(receptor.) r.giro(receptor.giro) r.ubicacion{ |u| u.direccion(receptor.direccion) u.comuna(receptor.comuna) u.ciudad(receptor.ciudad) } } end |