########## AR INVOICES ########## ar_vouchers = ActiveRecord::Base.connection.select_all("SELECT voucher_number FROM ar_invoices WHERE accounting_date = '2022-10-02'").map { |ar| ar["voucher_number"] } paid_records = [] ar_invoice_records = ArInvoice.where(voucher_number: ar_vouchers) ar_invoice_records.each do |ari| paid_records << ari.id if ari.status == "Paid" ari.update_attributes status: "Approved" ArInvoiceGlPoster.new.post(ari.voucher_number, true) end;nil ArInvoice.where(id: paid_records).update_all status: "Paid"