This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Job1 | |
@queue = :tests | |
def self.perform(msg) | |
puts msg | |
end | |
end | |
#Resque.enqueue(Job1, Time.now.to_i.to_s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def report_per_status(status) | |
include ActionView::Helpers::NumberHelper | |
m2list = Invoice.where(:state => status.to_s) | |
m2list.each do |r| | |
puts r.invoice_number + ";" + I18n.l(r.created_at.to_date) + ";" + number_with_precision(r.order_cart.final_amount) + ";5,00" | |
end | |
end | |
# usage report_per_status(:m2) | |
def ink_report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def trennzeichen(formatted_number) | |
raise ArgumentError unless formatted_number.is_a?(String) | |
return -1 if formatted_number.split(",").count == 1 && formatted_number.split(".").count == 1 # nix | |
return 0 if formatted_number.split(",").count > 1 && formatted_number.split(".").count == 1 # bloß Komma | |
return 1 if formatted_number.split(".").count > 1 && formatted_number.split(",").count == 1 # bloß Punkt | |
# Gibt's beides, ein Komma UND einen Punkt? | |
teile = formatted_number.split(",").map { |teil| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def render_invoice(invoice) | |
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.render_erb "invoice_mailer/invoice_#{l}.pdf.erb", params | |
end | |
# usage render_invoice(Invoice.last) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def perform(timestamp, settings) | |
Dir.glob(Pathname.new(settings["in"]).join(settings["format"]).to_s).each do |filename| | |
xlsx_name = Pathname.new(settings["in"]).join("#{File.basename(filename, ".*")}.xlsx").to_s | |
FileUtils.mv(filename, xlsx_name) | |
xls = Roo::Spreadsheet.open(xlsx_name) | |
sh = xls.sheet(0) | |
CSV.open(filename, "w", {:col_sep => "\t"}) do |csv| | |
(0..sh.last_row).each do |rn| | |
row = sh.row(rn) | |
next if (/\d{4}-\d{2}-\d{2}|Beleg.+/).match(row[0].to_s).nil? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package week5 | |
object higherOrderListFunctions { | |
val l: List[Int] = new Cons[Int](5, Nil) //> l : week5.List[Int] = 5,. | |
l.head //> res0: Int = 5 | |
l.tail //> res1: week5.List[Int] = . | |
l.map(x => x * 2).head //> res2: Int = 10 | |
def squareList1(xs: List[Int]): List[Int] = xs match { | |
case Nil => Nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OrderItem.where(:created_at => Date.parse('2013-04-01')..Date.parse('2013-07-31')).select{|b| b.address.country_code == "CH"}.map(&:quantity).sum | |
# noch flexibler | |
OrderItem.where(:created_at => Date.parse('2013-04-01')..Date.today).select{|b| b.address.country_code == "CH"}.map(&:quantity).sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def t_online(filename) | |
File.foreach(filename) do |f| | |
InvoiceMailer.sent_order_confirmation(Customer.where(:email => f.squish).first.order_carts.last).deliver | |
InvoiceMailer.sent_invoice(Customer.where(:email => f.squish).first.order_carts.last.invoices.last).deliver | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OrderItem.where( :state => Settings.shipping.timeplan.keys, :created_at => Date.today - 1.year .. Date.tomorrow - Settings.shipping.timeplan.values.min ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Shipment.rb | |
InvoiceMailer.sent_invoice(self.order_cart.invoices.last).deliver if self.order_cart.shipments.one?{|s| s.state == 'shipped'} | |
InvoiceMailer.sent_invoice(self.order_cart.invoices.last).deliver if self.order_cart.order_items.one?{|b| b.state == 'done'} |