Class: FE::Builder
- Inherits:
-
Object
- Object
- FE::Builder
- Defined in:
- lib/facturacr/builder.rb
Instance Method Summary collapse
- #credit_note(args = {}) ⇒ Object
- #debit_note(args = {}) ⇒ Object
- #fax(args = {}) ⇒ Object
- #id_document(args = {}) ⇒ Object
- #invoice(args = {}) ⇒ Object
- #issuer(args = {}) ⇒ Object
- #item(args = {}) ⇒ Object
- #location(args = {}) ⇒ Object
- #phone(args = {}) ⇒ Object
- #receiver(args = {}) ⇒ Object
- #reference(args = {}) ⇒ Object
- #summary(args = {}) ⇒ Object
Instance Method Details
#credit_note(args = {}) ⇒ Object
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 171 172 173 174 |
# File 'lib/facturacr/builder.rb', line 135 def credit_note(args = {}) if args[:issuer].is_a?(Hash) issuer = self.issuer(args[:issuer]) else issuer = args[:issuer] end if args[:receiver].is_a?(Hash) receiver = self.receiver(args[:receiver]) else receiver = args[:receiver] end if args[:items].is_a?(Array) && args[:items].first.is_a?(Hash) tmp_items = [] args[:items].each do |i| tmp_items << self.item(i) end items = tmp_items else items = args[:items] end if args[:summary].is_a?(Hash) summary = self.summary(args[:summary]) else summary = args[:summary] end if args[:references].is_a?(Array) && args[:references].first.is_a?(Hash) references = [] args[:references].each do |r| references << self.reference(r) end else references = args[:references] end FE::CreditNote.new date: args[:date], issuer: issuer, receiver: receiver, number: args[:number], items: items, condition: args[:condition], credit_term: args[:credit_term], summary: summary, security_code: args[:security_code], document_situation: args[:document_situation], references: references end |
#debit_note(args = {}) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/facturacr/builder.rb', line 176 def debit_note(args = {}) if args[:issuer].is_a?(Hash) issuer = self.issuer(args[:issuer]) else issuer = args[:issuer] end if args[:receiver].is_a?(Hash) receiver = self.receiver(args[:receiver]) else receiver = args[:receiver] end if args[:items].is_a?(Array) && args[:items].first.is_a?(Hash) tmp_items = [] args[:items].each do |i| tmp_items << self.item(i) end items = tmp_items else items = args[:items] end if args[:summary].is_a?(Hash) summary = self.summary(args[:summary]) else summary = args[:summary] end if args[:references].is_a?(Array) && args[:references].first.is_a?(Hash) references = [] args[:references].each do |r| references << self.reference(r) end else references = args[:references] end FE::DebitNote.new date: args[:date], issuer: issuer, receiver: receiver, number: args[:number], items: items, condition: args[:condition], credit_term: args[:credit_term], summary: summary, security_code: args[:security_code], document_situation: args[:document_situation], references: references end |
#fax(args = {}) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/facturacr/builder.rb', line 21 def fax(args = {}) args.reverse_merge!({ country_code: "506" }) FE::Document::Fax.new country_code: args[:country_code], number: args[:number] end |
#id_document(args = {}) ⇒ Object
6 7 8 |
# File 'lib/facturacr/builder.rb', line 6 def id_document(args = {}) FE::Document::IdentificationDocument.new type: args[:type], number: args[:number] end |
#invoice(args = {}) ⇒ Object
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 131 132 133 |
# File 'lib/facturacr/builder.rb', line 104 def invoice(args = {}) if args[:issuer].is_a?(Hash) issuer = self.issuer(args[:issuer]) else issuer = args[:issuer] end if args[:receiver].is_a?(Hash) receiver = self.receiver(args[:receiver]) else receiver = args[:receiver] end if args[:items].is_a?(Array) && args[:items].first.is_a?(Hash) tmp_items = [] args[:items].each do |i| tmp_items << self.item(i) end items = tmp_items else items = args[:items] end if args[:summary].is_a?(Hash) summary = self.summary(args[:summary]) else summary = args[:summary] end FE::Invoice.new date: args[:date], issuer: issuer, receiver: receiver, number: args[:number], items: items, condition: args[:condition], credit_term: args[:credit_term], summary: summary, security_code: args[:security_code], document_situation: args[:document_situation] end |
#issuer(args = {}) ⇒ Object
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 |
# File 'lib/facturacr/builder.rb', line 29 def issuer(args = {}) if args[:identification_document].is_a?(Hash) id_document = self.id_document(args[:identification_document]) else id_document = args[:id_document] end if args[:location].is_a?(Hash) location = self.location(args[:location]) else location = args[:location] end if args[:phone].is_a?(Hash) phone = self.phone(args[:phone]) else phone = args[:phone] end if args[:fax].is_a?(Hash) fax = self.fax(args[:fax]) else fax = args[:fax] end FE::Document::Issuer.new name: args[:name], identification_document: id_document, location: location, phone: phone, fax: fax, email: args[:email] end |
#item(args = {}) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/facturacr/builder.rb', line 90 def item(args={}) txs = args.delete(:taxes) taxes = [] if txs.is_a?(Array) && txs.first.is_a?(Hash) txs.each do |t| taxes << FE::Document::Tax.new(code: "01", rate: 13, total: 13) end else taxes = txs end args[:taxes] = taxes FE::Document::Item.new(args) end |
#location(args = {}) ⇒ Object
10 11 12 |
# File 'lib/facturacr/builder.rb', line 10 def location(args = {}) FE::Document::Location.new province: args[:province],county: args[:county], district: args[:district], others: args[:others] end |
#phone(args = {}) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/facturacr/builder.rb', line 14 def phone(args = {}) args.reverse_merge!({ country_code: "506" }) FE::Document::Phone.new country_code: args[:country_code], number: args[:number] end |
#receiver(args = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/facturacr/builder.rb', line 57 def receiver(args={}) if args[:identification_document].is_a?(Hash) id_document = self.id_document(args[:identification_document]) else id_document = args[:id_document] end if args[:location].is_a?(Hash) location = self.location(args[:location]) else location = args[:location] end if args[:phone].is_a?(Hash) phone = self.phone(args[:phone]) else phone = args[:phone] end if args[:fax].is_a?(Hash) fax = self.fax(args[:fax]) else fax = args[:fax] end FE::Document::Receiver.new name: args[:name], identification_document: id_document, location: location, phone: phone, fax: fax, email: args[:email] end |