Class: Ticketbai::Nodes::BreakdownType

Inherits:
Object
  • Object
show all
Defined in:
lib/ticketbai/nodes/breakdown_type.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ BreakdownType

Type of non-exempt (TipoNoExenta): S1: Sin inversion del sujeto pasivo S2: Con inversion del sujeto pasivo



15
16
17
18
19
20
21
22
# File 'lib/ticketbai/nodes/breakdown_type.rb', line 15

def initialize(args = {})
  @receiver_country = args[:receiver_country]
  @invoice_amount = args[:invoice_amount]
  @invoice_vat = args[:invoice_vat]
  @invoice_vat_total = args[:invoice_vat_total]
  @receiver_in_eu = args[:receiver_in_eu]
  @simplified_invoice = args[:simplified_invoice]
end

Instance Method Details

#build_xml(node) ⇒ Nokogiri::XML::Builder

Returns:

  • (Nokogiri::XML::Builder)


25
26
27
28
29
30
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
60
61
62
63
64
65
66
67
68
69
# File 'lib/ticketbai/nodes/breakdown_type.rb', line 25

def build_xml(node)
  node = Nokogiri::XML::Builder.new if node.nil?
  node.TipoDesglose do |xml|
    if (@receiver_country == 'ES') || (@receiver_country != 'ES' && @simplified_invoice)
      xml.DesgloseFactura do
        xml.Sujeta do
          if (@receiver_country != 'ES') && @simplified_invoice
            xml.Exenta do
              xml.DetalleExenta do
                xml.CausaExencion @receiver_in_eu == true ? 'E6' : 'E2'
                xml.BaseImponible @invoice_amount
              end
            end
          else
            xml.NoExenta do
              xml.DetalleNoExenta do
                xml.TipoNoExenta 'S1'
                xml.DesgloseIVA do
                  xml.DetalleIVA do
                    xml.BaseImponible @invoice_amount
                    xml.TipoImpositivo @invoice_vat
                    xml.CuotaImpuesto @invoice_vat_total
                  end
                end
              end
            end
          end
        end
      end
    else
      xml.DesgloseTipoOperacion do
        xml.PrestacionServicios do
          xml.Sujeta do
            xml.Exenta do
              xml.DetalleExenta do
                xml.CausaExencion @receiver_in_eu == true ? 'E6' : 'E2'
                xml.BaseImponible @invoice_amount
              end
            end
          end
        end
      end
    end
  end
end