Class: FE::CLI::Generate
- Inherits:
-
Thor
- Object
- Thor
- FE::CLI::Generate
- Defined in:
- lib/facturacr/cli/generate.rb
Instance Method Summary collapse
- #credit_note ⇒ Object
- #debit_note ⇒ Object
- #invoice ⇒ Object
- #reception_message ⇒ Object
- #ticket ⇒ Object
Instance Method Details
#credit_note ⇒ Object
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 |
# File 'lib/facturacr/cli/generate.rb', line 47 def credit_note data = YAML.load_file([:data_path]).with_indifferent_access builder = FE::Builder.new credit_note = builder.credit_note(data[:document]) if [:invoice_number].present? date = DateTime.parse([:invoice_date]) credit_note.references = [FE::Document::Reference.new(document_type: "01", code: "01", reason: "Anula documento", number: [:invoice_number], date: date)] end credit_note.date = Time.now credit_note.number = [:number].to_i if [:number].present? if [:output_path] output_path = [:output_path] else output_path = "tmp/#{credit_note.key}.xml" end write(credit_note, output_path) print_details(credit_note) sign(output_path, ) if [:sign] send_document("#{output_path}.signed.xml") if [:sign] && [:send] end |
#debit_note ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/facturacr/cli/generate.rb', line 82 def debit_note data = YAML.load_file([:data_path]).with_indifferent_access builder = FE::Builder.new debit_note = builder.debit_note(data[:document]) if [:invoice_number].present? date = DateTime.parse([:invoice_date]) debit_note.references = [FE::Document::Reference.new(document_type: "01", code: "01", reason: "Anula documento", number: [:invoice_number], date: date)] end debit_note.date = Time.now debit_note.number = [:number].to_i if [:number].present? if [:output_path] output_path = [:output_path] else output_path = "tmp/#{debit_note.key}.xml" end write(debit_note, output_path) print_details(debit_note) sign(output_path, ) if [:sign] send_document("#{output_path}.signed.xml") if [:sign] && [:send] end |
#invoice ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/facturacr/cli/generate.rb', line 13 def invoice start = Time.now data = YAML.load_file([:data_path]).with_indifferent_access builder = FE::Builder.new invoice = builder.invoice(data[:document]) invoice.date = Time.now invoice.number = [:number].to_i if [:number].present? if [:output_path] output_path = [:output_path] else output_path = "tmp/#{invoice.key}.xml" end write(invoice, output_path) print_details(invoice) sign(output_path, ) if [:sign] end_at = Time.now puts "Total Time: #{end_at - start} sec." send_document("#{output_path}.signed.xml") if [:sign] && [:send] end |
#reception_message ⇒ Object
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 175 176 177 178 179 180 181 182 |
# File 'lib/facturacr/cli/generate.rb', line 145 def doc = XmlDocument.new(DataProvider.new(:file, [:xml_in])) builder = FE::Builder.new # Roles of receiver and issuer are inverted because they are extracted from the document. # The ISSUER of the reception message is the RECEIVER of the document = builder.({ key: doc.document.key, date: doc.document.date, number: [:number], issuer_id_number: doc.document.issuer.identification_document.id_number, issuer_id_type: doc.document.issuer.identification_document.document_type, receiver_id_number: doc.document.receiver.identification_document.id_number, receiver_id_type: doc.document.receiver.identification_document.document_type, message: [:action], tax: doc.document.summary.tax_total, total: doc.document.summary.net_total, document_situation: [:document_situation] }) .security_code = 8.times.map{ rand(0..9) }.join if [:output_path] output_path = [:output_path] else output_path = "tmp/msj-receptor-#{.key}.xml" end write(, output_path) puts "Mensaje Receptor" puts "Accion: #{FE::ReceptionMessage::MESSAGE_TYPES[.]}" puts "Factura: #{doc.document.key}" puts "Ced. Receptor: #{.receiver_id_number}" puts "Ced. Emisor: #{.issuer_id_number}" sign(output_path, ) if [:sign] send_document("#{output_path}.signed.xml") if [:sign] && [:send] end |
#ticket ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/facturacr/cli/generate.rb', line 115 def ticket data = YAML.load_file([:data_path]).with_indifferent_access builder = FE::Builder.new ticket = builder.ticket(data[:document]) ticket.date = Time.now ticket.number = [:number].to_i if [:number].present? if [:output_path] output_path = [:output_path] else output_path = "tmp/#{ticket.key}.xml" end write(ticket, output_path) print_details(ticket) sign(output_path, ) if [:sign] send_document("#{output_path}.signed.xml") if [:sign] && [:send] end |