Skip to content

Instantly share code, notes, and snippets.

transactions_group_by_proforma = Transaction.select('transaction_id as id, count(proforma_id) as proforma_count').group('transaction_id')
transactions = Transaction.where(transaction_id: transactions_group_by_proforma.map(&:id)).where.not(proforma_id: nil).group_by(&:transaction_id)

transactions_group_by_proforma.each do |parent_transaction|
  puts "Root: #{parent_transaction.id}, Proforma: #{parent_transaction.proforma_count}"
  puts "--- Childs ---"
  if transactions[parent_transaction.id.to_i].present?
    transactions[parent_transaction.id.to_i].each.with_index(1) do |child_transaction, index|
      puts "#{index}: #{child_transaction.proforma_no}"
@philiplambok
philiplambok / rake-tasks.rb
Last active May 24, 2022 13:56
Update the legacy invoice to enable manual transfer
# find the service
mekari_pay_addons_service = Service.find_by(name: "Jurnal Pay")
# find the related invoices
invoices = Invoice.where(service: service, status: %i[unpaid, expired], enable_manual_transfer: false)
# enable manual transfer for all the related invoices
invoices.update_all(enable_manual_transfer: true)
# frozen_string_literal: true
class Storage
class InvalidRecord
end
def initialize
@storages = []
end
@philiplambok
philiplambok / core-1.md
Created August 14, 2021 04:12
local vs let vs instance variable
# frozen_string_literal: true

ENV['RAILS_ENV'] ||= 'test'

require 'benchmark/ips'
require File.expand_path('../config/environment', __dir__)
require 'rspec/rails'

RSpec::Core::Runner.autorun
# lib/credit_card__payment_payload.rb
class CreditCardPaymentPayload 
  def initialize(payment)
  end
  
  def record
  end

 def to_json
@philiplambok
philiplambok / settings.json
Last active January 2, 2021 06:23
vs settings
{
"editor.fontFamily": "Jetbrains Mono, Dank Mono, Menlo, Monaco, 'Courier New', monospace",
"workbench.iconTheme": "material-icon-theme",
"workbench.activityBar.visible": false,
"workbench.editor.showTabs": false,
"workbench.statusBar.visible": false,
"editor.minimap.enabled": false,
"window.zoomLevel": 1,
"editor.tabSize": 2,
"ruby.useLanguageServer": true,
expected_response = {
data: [
{
start_date: '2020-01-01',
end_date: '2020-01-01',
total_items: 1,
amount: 40_000,
amount_formatted: 'Rp 40.000,00'
},
{
@philiplambok
philiplambok / webpacker.rb
Created September 7, 2020 04:43
webpacker.rb
# Prolog:
#
# In default rails testing setup we actually will running assets compiling in every thread
# In this case, we doing 8 times compiling assets (becuase we use parallel_test for 8 threads).
# And in some cases (thread) our compiling doesn't work as expected, so, this module will help us
# to only run assets compiling at once.
#
# This code was taken from:
# https://makandracards.com/makandra/46247-how-to-make-webpacker-compile-once-for-parallel-tests-and-only-if-necessary
#
@philiplambok
philiplambok / authenticable.rb
Last active June 25, 2020 04:33
fix-fix-spec
module Web
module JurnalPay
module Authenticable
extend ActiveSupport::Concern
included do
helper_method :current_jurnal_user
def require_authentication
access_token = params[:access_token] || session[:jurnal_pay_access_token]