~singpolyma/jmp-pay

a07d5bb0007d71eccf28ad0ee92513b0ccdabe77 — Stephen Paul Weber 3 years ago 2ffb26d
Give everyone $5.0001 to prevent low balance and eat one month

This way they keep most of their activation time, and the side effect of
interest is mitigated.
1 files changed, 3 insertions(+), 3 deletions(-)

M bin/months_to_balance
M bin/months_to_balance => bin/months_to_balance +3 -3
@@ 25,12 25,12 @@ SQL
rows.each do |r|
	cid = r["customer_id"]
	DB.transaction do
		DB.exec(<<~SQL, [cid, "#{cid}-months_to_balance", r["amount"]])
		DB.exec(<<~SQL, [cid, "#{cid}-prevent_low_balance"])
			INSERT INTO transactions (customer_id, transaction_id, amount, note)
			VALUES ($1, $2, $3, 'months_to_balance')
			VALUES ($1, $2, 5.0001, 'Prevent low balance')
		SQL
		DB.exec(<<~SQL, [cid, r["expires_at"]])
			UPDATE plan_log SET date_range = date_range - tsrange(LOCALTIMESTAMP + '1 month' + make_interval(days := (DATE_PART('day', UPPER(date_range)) - DATE_PART('day', LOCALTIMESTAMP))::int), UPPER(date_range))
			UPDATE plan_log SET date_range = date_range - tsrange(UPPER(date_range) - '1 month', UPPER(date_range))
			WHERE customer_id=$1 AND UPPER(date_range)=$2
		SQL
	end