Skip to content

Instantly share code, notes, and snippets.

@gtan66
gtan66 / sd_manual_entries.rb
Last active August 29, 2015 14:14
SD manual entries report
def self.export_security_deposit_manual_entries_to_csv
CSV.open("report.csv", "wb") do |csv|
accounts = security_deposit_manual_entries
for acct in accounts do
for sec_deposit in acct.security_deposits do
for journal_entry in sec_deposit.journal_entries.where(entry_item_type: "ManualEntryItem")
csv << [journal_entry.entry_item.created_at, acct.short_code, sec_deposit.location.code,
journal_entry.entry_item.amount.to_f, journal_entry.entry_item.user.try("email"), journal_entry.entry_item.notes]
end
end
@gtan66
gtan66 / gist:7f631126fee7ca9a22b1
Last active August 29, 2015 14:17
Get Move Out info by month for accounting
p = PrimaryReservation.where(move_out_type: "Move Out").where(ended_on: Time.current.beginning_of_month.to_date...1.month.from_now.beginning_of_month.to_date)
def get_moveOut_info(p)
results = p.select{|r| r.reservable.name != "WW Membership"}.map do |p|
account = p.account
account_admin = p.account.account_admin
ach = account.account_admin.ach_profiles.where(location_id: p.location.id).where(move_out_refund: true).last
office = p.reservable
sd = account.reservations.select{|r| r.parent_id==p.id && r.reservable.name == "Security Deposit"}.last
def invoices_for_lon02
Invoice.where(location_id: 37).each do |m|
m.line_items.each do |l|
puts [m.account.name, m.account.short_code, m.started_on, m.name, m.aasm_state, m.amount,m.uuid, l.name, l.uuid, l.amount].join(", ")
end
end
return ""
end
def payments_for_lon02(loc_id)
Invoice.where(location_id: loc_id).each do |m|
m.payments.each do |l|
puts [m.account.name, m.account.short_code, m.started_on, m.name, m.aasm_state, m.amount, m.uuid, l.payment_method, l.status, l.requested_at, l.deposited_at, l.marked_deposited_at, l.amount, l.uuid].join(", ")
end
end
return ""
end
@gtan66
gtan66 / gist:49916a11a37466ac15fa
Last active August 24, 2022 06:33
Tokenizing Tranzila Cards
#Assuming infos is an array of hashes, each having :location ('TLV01' is Herzlyia, 'TLV02' is Dubnov), :code (the member's short code), :exp (expiration), :card, :cvv and :id (should be 'N/A' for int'l cards)
require 'net/http'
require 'uri'
Net::HTTP.get(URI.parse("https://secure5.tranzila.com/cgi-bin/tranzila31cl.cgi?TranzilaPW=#{ENV['TRANZILLA_TOKEN_PW']}&supplier=wework"))
uri = URI.parse('https://secure5.tranzila.com/cgi-bin/tranzila31pan.cgi')
infos.each do |info|
next if info[:id].blank?
#in spaceman
loc = Location.find_by(name: location_name)
floors = Floor.where(location_id: loc.id).where(name: floors)
os = Space.for_location(loc).where(floor_id: floors)
accounts = PrimaryReservation.where(reservable_uuid: os.pluck(:uuid)).where(started_on:Date.new(2015, 9, 1)).map(&:account).uniq
OR
accounts = PrimaryReservation.where(location_id: loc.id).where(started_on:Date.new(2015, 9, 1)).map(&:account).uniq
transfers = accounts.select{|a| a.primary_reservations.any?{ |p| p.started_on < Date.new(2015, 9, 1) } }
@gtan66
gtan66 / gist:bdf61a817d06d5c45c89
Created August 25, 2015 21:54
Fix account in spaceman
account = Account.find_by(uuid: "066c4a44-6eaa-4712-9019-198817c4b2bd")
account_admin = User.find_by(email: "laurao@nothingforgotteninc.com")
account_admin.uuid = "b5465310-e7a0-0132-3401-1e4f0fde60c1"
account_admin.save!
account.name = "Nothing Forgotten"
account.account_admin_id = account_admin.id
account.account_admin_uuid = account_admin.uuid
account.save!
@gtan66
gtan66 / gist:0e778c335c311b127ffe
Last active August 31, 2015 14:50
Update batches that failed to update
batches = [
{batch_number: 14625, location: "South Station" },
{ batch_number: 14626, location: "Chinatown"},
{ batch_number: 14627, location: "Wonder Bread"},
{ batch_number: 14628, location: "Dupont Circle"},
{ batch_number: 14629, location: "Soho West"},
{ batch_number: 14630, location: "Bryant Park"},
{ batch_number: 14631, location: "Park South"},
{ batch_number: 14632, location: "42nd Street"},
{ batch_number: 14633, location: "FiDi"},
@gtan66
gtan66 / gist:0a52e6a5a5c69c134fb1
Created August 26, 2015 18:42
cancel move in with already charged SD
p = PrimaryReservation.where(account_id: 7442, office_num: "1018")
p.started_on = p.started_on.last_month
p.save
ReservationService.new.move_out!(p, Date.now, "Move Out")
i = p.last.invoices.last
i.without_versioning :destroy
i.versions.each(&:delete)
@gtan66
gtan66 / fix_account_admin.rb
Last active August 27, 2015 17:24
Fix account admin
account = Account.find_by(uuid: "4092f3a0-8251-0130-f786-123138068411")
account_admin = User.find_by(email: "mgugerli@generationcitizen.org")
account.account_admin_id = account_admin.id
account.account_admin_uuid = account_admin.uuid
account.save!