Class: ACube::Schema::Body
- Inherits:
-
Object
- Object
- ACube::Schema::Body
- Defined in:
- lib/acube/schema/body.rb
Constant Summary collapse
- DOCUMENT_KINDS =
%w[TD01 TD02 TD03 TD04 TD05 TD06 TD16 TD17 TD18 TD19 TD20 TD21 TD22 TD23 TD24 TD25 TD26 TD27 TD28].freeze
- PAYMENT_METHODS =
%w[MP01 MP02 MP03 MP04 MP05 MP06 MP07 MP08 MP09 MP10 MP11 MP12 MP13 MP14 MP15 MP16 MP17 MP18 MP19 MP20 MP21 MP22 MP23].freeze
Instance Attribute Summary collapse
-
#causal ⇒ Object
Returns the value of attribute causal.
-
#connected_progressive ⇒ Object
Returns the value of attribute connected_progressive.
-
#date ⇒ Object
Returns the value of attribute date.
-
#description ⇒ Object
Returns the value of attribute description.
-
#document_kind ⇒ Object
Returns the value of attribute document_kind.
-
#payment_max_date ⇒ Object
Returns the value of attribute payment_max_date.
-
#payment_method ⇒ Object
Returns the value of attribute payment_method.
-
#payment_terms ⇒ Object
Returns the value of attribute payment_terms.
-
#progressive ⇒ Object
readonly
Returns the value of attribute progressive.
-
#quantity ⇒ Object
Returns the value of attribute quantity.
-
#total_price ⇒ Object
Returns the value of attribute total_price.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#causal ⇒ Object
Returns the value of attribute causal.
12 13 14 |
# File 'lib/acube/schema/body.rb', line 12 def causal @causal end |
#connected_progressive ⇒ Object
Returns the value of attribute connected_progressive.
9 10 11 |
# File 'lib/acube/schema/body.rb', line 9 def connected_progressive @connected_progressive end |
#date ⇒ Object
Returns the value of attribute date.
7 8 9 |
# File 'lib/acube/schema/body.rb', line 7 def date @date end |
#description ⇒ Object
Returns the value of attribute description.
10 11 12 |
# File 'lib/acube/schema/body.rb', line 10 def description @description end |
#document_kind ⇒ Object
Returns the value of attribute document_kind.
7 8 9 |
# File 'lib/acube/schema/body.rb', line 7 def document_kind @document_kind end |
#payment_max_date ⇒ Object
Returns the value of attribute payment_max_date.
13 14 15 |
# File 'lib/acube/schema/body.rb', line 13 def payment_max_date @payment_max_date end |
#payment_method ⇒ Object
Returns the value of attribute payment_method.
14 15 16 |
# File 'lib/acube/schema/body.rb', line 14 def payment_method @payment_method end |
#payment_terms ⇒ Object
Returns the value of attribute payment_terms.
14 15 16 |
# File 'lib/acube/schema/body.rb', line 14 def payment_terms @payment_terms end |
#progressive ⇒ Object (readonly)
Returns the value of attribute progressive.
15 16 17 |
# File 'lib/acube/schema/body.rb', line 15 def progressive @progressive end |
#quantity ⇒ Object
Returns the value of attribute quantity.
11 12 13 |
# File 'lib/acube/schema/body.rb', line 11 def quantity @quantity end |
#total_price ⇒ Object
Returns the value of attribute total_price.
8 9 10 |
# File 'lib/acube/schema/body.rb', line 8 def total_price @total_price end |
Class Method Details
.from(invoice) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/acube/schema/body.rb', line 17 def self.from(invoice) new.tap do |body| invoice.transaction_data.each do |key, value| value = value.is_a?(Symbol) ? invoice.send(value) : value body.send("#{key}=", value) end end end |
Instance Method Details
#set_progressive(progressive) ⇒ Object
26 27 28 |
# File 'lib/acube/schema/body.rb', line 26 def set_progressive(progressive) @progressive = progressive end |
#to_xml ⇒ Object
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 70 71 72 73 74 75 76 77 78 |
# File 'lib/acube/schema/body.rb', line 30 def to_xml Nokogiri::XML::Builder.new do |xml| xml.FatturaElettronicaBody { xml.DatiGenerali { xml.DatiGeneraliDocumento { xml.TipoDocumento document_kind xml.Divisa "EUR" xml.Data date.strftime("%Y-%m-%d") xml.Numero progressive xml.ImportoTotaleDocumento total_price xml.Causale causal if causal } if (document_kind == :TD04) xml.DatiFattureCollegate { xml.IdDocumento connected_progressive } end } xml.DatiBeniServizi { xml.DettaglioLinee { xml.NumeroLinea 1 xml.Descrizione description xml.Quantita ("%f" % quantity.to_f) xml.PrezzoUnitario ("%f" % unitary_price.to_f) xml.PrezzoTotale ("%f" % price_no_vat.to_f) xml.AliquotaIVA ("%.2f" % (ACube.vat_amount * 100).to_f) } xml.DatiRiepilogo { xml.AliquotaIVA ("%.2f" % (ACube.vat_amount * 100).to_f) xml.ImponibileImporto ("%f" % price_no_vat.to_f) xml.Imposta ("%f" % vat_amount.to_f) xml.EsigibilitaIVA "I" } } xml.DatiPagamento { xml.CondizioniPagamento payment_terms xml.DettaglioPagamento { xml.ModalitaPagamento payment_method xml.DataScadenzaPagamento payment_max_date.strftime("%Y-%m-%d") xml.ImportoPagamento ("%f" % total_price.to_f) } } } end.to_xml(save_with: 2) end |