Skip to content

Instantly share code, notes, and snippets.

#Bis Dezember
bis_dezember = Invoice.where("state = 'r2' AND created_at < '2012-12-01'") #111
@context = Time.now.to_i.to_s
bis_dezember.each{|r| r.updated_at = Date.parse('2012-12-18'); r.save; InvoiceStateTransition.create(:invoice_id => r.id, :event => 'second_inv', :from => 'csv', :to => 'r2', :context => @context)}
# Ab Dezember
ab_dezember = Invoice.where("state = 'r2' AND created_at >= '2012-12-01'") #111
@context = Time.now.to_i.to_s
ab_dezember.each{|r| r.paid; r.reopen}
@airspeed
airspeed / 2_rechnung.rb
Last active December 12, 2015 05:28
Pdf erstellung vom Template über WickedPdf.
def print_invoice(invoice, out)
i = invoice
o = i.order_cart
l = i.customer.lang[0..1].downcase === 'de' ? 'de' : 'en' # unoptimal, reicht aber im Augenblick
params = {:@invoice_address => o.invoice_address, :@order_cart => o, :@shipments => o.shipments, :@invoice => i}
Clixxie::PdfGenerator.from_template "invoice_mailer/invoice_2_#{l}.pdf.erb", out, "#{i.invoice_number}_2r.pdf", params
end
# Usage
# print_invoice(Invoice.last, "mahnung/out")
@airspeed
airspeed / 1_rechnung.rb
Last active December 14, 2015 00:09
Erstellt ein neues Mahndokument - 1. Rechnung
def print_invoice(invoice, out)
i = invoice
o = i.order_cart
l = i.customer.lang[0..1].downcase === 'de' ? 'de' : 'en' # unoptimal, reicht aber im Augenblick
params = {:@invoice_address => o.invoice_address, :@order_cart => o, :@shipments => o.shipments, :@invoice => i, :@filedate => Date.today}
Clixxie::PdfGenerator.from_template "invoice_mailer/invoice_#{l}.pdf.erb", out, "#{i.invoice_number}.pdf", params
end
# Usage
# print_invoice(Invoice.last, "~/Downloads")
@airspeed
airspeed / rubyzip.rb
Last active December 14, 2015 01:08
Tut eine Liste beliebiger Dateien in ein Paket zusammenzippen.
require 'zip/zip'
def zip(zipfile_name, *input_filenames)
Zip::ZipFile.open(zipfile_name, Zip::ZipFile::CREATE) do |zipfile|
input_filenames.each do |filename|
zipfile.add(File.basename(filename), filename)
end
end
end
# usage:
def remove_blanks(filename)
nonblank, ranges, range_first_val, range_last_val = [], [], 0, 0
File.open(filename, "rb") do |io|
reader = PDF::Reader.new(io)
reader.pages.each_with_index do |page, i|
nonblank << (i + 1) unless page.text.length.zero?
end
range_first_val, range_last_val = nonblank.first, nonblank.last
range_first_val = -1 if nonblank.length === reader.pages.length
@airspeed
airspeed / mahnung_1_de.rb
Last active December 14, 2015 07:19
Erstellt das erste Mahndokument auf deutsch.
def print_invoice(invoice, out)
i = invoice
o = i.order_cart
l = i.customer.lang[0..1].downcase === 'de' ? 'de' : 'en' # unoptimal, reicht aber im Augenblick
params = {:@invoice_address => o.invoice_address, :@order_cart => o, :@shipments => o.shipments, :@invoice => i, :@filedate => Date.today}
Clixxie::PdfGenerator.from_template "invoice_mailer/mahnung_1_de.pdf.erb", out, "#{i.invoice_number}_1m.pdf", params
end
@airspeed
airspeed / mahnung_1_en.rb
Last active December 14, 2015 07:19
Erstellt das erste Mahndokument auf englisch.
def print_invoice(invoice, out)
i = invoice
o = i.order_cart
l = i.customer.lang[0..1].downcase === 'de' ? 'de' : 'en' # unoptimal, reicht aber im Augenblick
params = {:@invoice_address => o.invoice_address, :@order_cart => o, :@shipments => o.shipments, :@invoice => i, :@filedate => Date.today}
Clixxie::PdfGenerator.from_template "invoice_mailer/mahnung_1_en.pdf.erb", out, "#{i.invoice_number}_1m.pdf", params
end
@airspeed
airspeed / mahnung_2_en.rb
Created February 27, 2013 17:16
Erstellt das zweite Mahndokument auf englisch.
def print_invoice(invoice, out)
i = invoice
o = i.order_cart
l = i.customer.lang[0..1].downcase === 'de' ? 'de' : 'en' # unoptimal, reicht aber im Augenblick
params = {:@invoice_address => o.invoice_address, :@order_cart => o, :@shipments => o.shipments, :@invoice => i, :@filedate => Date.today}
Clixxie::PdfGenerator.from_template "invoice_mailer/mahnung_2_en.pdf.erb", out, "#{i.invoice_number}_2m.pdf", params
end
@airspeed
airspeed / mahnung_2_de.rb
Last active December 14, 2015 07:19
Erstellt das zweite Mahndokument auf deutsch.
def print_invoice(invoice, out)
i = invoice
o = i.order_cart
l = i.customer.lang[0..1].downcase === 'de' ? 'de' : 'en' # unoptimal, reicht aber im Augenblick
params = {:@invoice_address => o.invoice_address, :@order_cart => o, :@shipments => o.shipments, :@invoice => i, :@filedate => Date.today}
Clixxie::PdfGenerator.from_template "invoice_mailer/mahnung_2_de.pdf.erb", out, "#{i.invoice_number}_2m.pdf", params
end
@airspeed
airspeed / generate_test_order_smart.rb
Last active December 14, 2015 11:49
Packt Daten aus der Produktion und shickt sie auf den Dev-Server drauf.
def generate_test_orders(destination_server, number_of_test_orders)
Settings.crm[:host] = "https://" + destination_server
return 0 if number_of_test_orders.zero?
crm_client = Clixxie::CrmClient::CrmClient.new
orders_stack = Order.last(number_of_test_orders)
number_of_test_orders.times do |i|
crm_client.post_order(orders_stack[i])
end
end