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 delete_all_recurring_invoices | |
progress_bar = ProgressRateLimiter.new(count: Invoice.where(type: "RecurringInvoice").count) | |
Invoice.where(type: "RecurringInvoice").find_each do |recurring_invoice| | |
recurring_invoice.destroy! | |
progress_bar.increment! | |
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
def backfill_recurring_invoice_profile_id | |
ids = RecurringInvoiceProfile.select(:id) | |
progress_bar = ProgressBar.new(ids.count) | |
RecurringInvoiceProfile.select(:id).find_each do |recurring_invoice_profile| | |
Invoice.where(recurring_invoice_id: recurring_invoice_profile.id). | |
update_all(recurring_invoice_profile_id: recurring_invoice_profile.id) | |
progress_bar.increment! |
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
<div class="data-table"> | |
<%= form_with url: search_path, method: :get do |f| %> | |
<div class="data-table_controls"> | |
<div class="data-table_length"> | |
<%= f.label "page_size" do %> | |
Show | |
<%= f.select "page_size", options_for_select([10, 25, 50, 100], @collection.per_page) %> | |
entries | |
<% end %> | |
</div> |
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
require "benchmark" | |
require "perform_on_replica" | |
company = Company.find(126455) | |
class BenchmarkExporter | |
include PerformOnReplica | |
def initialize(company) |
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
switch_to_slave_db | |
companies = Company.joins(:subscription).merge(Subscription.live) | |
companies_count = companies.count | |
progress_bar = ProgressBar.new(companies_count) | |
ProgressBar.new(companies_count) | |
companies.find_each do |company| | |
Rails.logger.info({ | |
event: "COMPANY_OVERDUE_INVOICE_COUNT", |
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
negative_recurring_invoice_profiles = [] | |
count = RecurringInvoiceProfile.active.count | |
progress = ProgressBar.new(count) | |
RecurringInvoiceProfile.includes( | |
:company, | |
:contact, | |
{recurring_invoice_profile_items: [:general_ledger_account, :company]}, | |
).active.find_each do |recurring_invoice_profile| |
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 CompareRecurringInvoiceProfiles | |
def self.perform | |
recurring_invoice_count = RecurringInvoiceProfile.count | |
progress = ProgressBar.new(recurring_invoice_count) | |
RecurringInvoiceProfile.all.find_each do |recurring_invoice_profile| | |
render_and_compare(recurring_invoice_profile.source_recurring_invoice, recurring_invoice_profile) | |
progress.increment! | |
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
def fix_fcb_stock(company) | |
bills = company.bills.in_foreign_currency.where.not(stock_item_id: nil) | |
bills.each do |bill| | |
company.stock_mapper.update_stock_entry(bill, force: true) | |
end | |
stock_transactions = StockTransaction | |
.where(stock_item_id: bills.map(&:stock_item_id)) | |
.where("created_at >= ?", bills.map(&:created_at).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
# This updates any bill that had incorrectly calculated vat effects | |
# when the bill was in foreign currency and was ether ec service or ec goods | |
# To be ran ater Fix PR is deployed https://github.com/fac/freeagent/pull/19751 | |
def fix_fcb_di | |
bills = Bill.in_foreign_currency.where( | |
ec_status: [EcStatus::EC_SERVICES, EcStatus::EC_GOODS] | |
) | |
progress_bar = ProgressBar.new(bills.length) |
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
progress_bar = ProgressBar.new(Company.count) | |
Company.all.find_in_batches.each do |companies| | |
companies.pluck(:id, :native_currency).each do |(company_id, native_currency)| | |
progress_bar.increment! | |
Bill.where(company_id: company_id).update_all(currency: native_currency) | |
end | |
end |