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 "perform_on_replica" | |
def find_duplicate_references | |
PerformOnReplica.perform_on_replica do | |
companies = Company.all | |
progress_bar = ProgressBar.new(companies.count) | |
companies.includes(:subscription).find_each do |company| | |
references = company.invoices. | |
group(:reference). |
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
def set_rates(end_date) | |
us_rates = [ | |
{base_currency: "GBP", counter_currency: "USD", rate: BigDecimal("1.5480658613")}, | |
{base_currency: "GBP", counter_currency: "USD", rate: BigDecimal("1.5522279056")}, | |
{base_currency: "GBP", counter_currency: "USD", rate: BigDecimal("1.5473")}, | |
{base_currency: "GBP", counter_currency: "USD", rate: BigDecimal("1.5474")}, | |
{base_currency: "GBP", counter_currency: "USD", rate: BigDecimal("1.5535749501")}, | |
{base_currency: "GBP", counter_currency: "USD", rate: BigDecimal("1.5484416182")}, | |
{base_currency: "GBP", counter_currency: "USD", rate: BigDecimal("1.5566405175")}, | |
{base_currency: "GBP", counter_currency: "USD", rate: BigDecimal("1.5520790022")}, |