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
- #reception_message(args = {}) ⇒ Object
- #reference(args = {}) ⇒ Object
- #summary(args = {}) ⇒ Object
- #ticket(args = {}) ⇒ Object
Instance Method Details
#credit_note(args = {}) ⇒ Object
167 168 169 170 171 172 173 174 175 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 |
# File 'lib/facturacr/builder.rb', line 167 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
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/facturacr/builder.rb', line 208 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 |
#reception_message(args = {}) ⇒ Object
249 250 251 252 253 254 |
# File 'lib/facturacr/builder.rb', line 249 def (args={}) FE::ReceptionMessage.new number: args[:number], date: args[:date], key: args[:key], issuer_id_number: args[:issuer_id_number], issuer_id_type: args[:issuer_id_type], receiver_id_number: args[:receiver_id_number], receiver_id_type: args[:receiver_id_type], message: args[:message], details: args[:details], tax: args[:tax], total: args[:total], security_code: args[:security_code], document_situation: args[:document_situation] end |
#reference(args = {}) ⇒ Object
257 258 259 |
# File 'lib/facturacr/builder.rb', line 257 def reference(args={}) FE::Document::Reference.new args end |
#summary(args = {}) ⇒ Object
86 87 88 |
# File 'lib/facturacr/builder.rb', line 86 def summary(args={}) FE::Document::Summary.new args end |
#ticket(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 |
# File 'lib/facturacr/builder.rb', line 135 def ticket(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::Ticket.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 |