From 25acefd1134ad488e86702f29d10683334732731 Mon Sep 17 00:00:00 2001 From: Andrew Roth Date: Thu, 12 Dec 2024 18:40:11 -0500 Subject: [PATCH] fix crashes; add counts to initial import --- app/admin/issuances.rb | 20 ++++++++++++++++++++ app/models/issuance.rb | 2 +- import.rb | 4 ++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/admin/issuances.rb b/app/admin/issuances.rb index 99d2916..bf9ec65 100644 --- a/app/admin/issuances.rb +++ b/app/admin/issuances.rb @@ -16,6 +16,21 @@ # permitted # end + filter :creator + filter :issuer + filter :gift_card_type + filter :status + filter :card_amount + filter :quantitiy + filter :begin_use_date + filter :end_use_date + filter :expiration_date + filter :allocated_certificates + filter :numbering + filter :issued_at + filter :created_at + filter :updated_at + index do id_column tag_column :status @@ -31,6 +46,11 @@ column :max_certificate do |issuance| issuance.allocated_certificates.split(Issuance::CERTIFICATE_DISPLAY_SEPARATOR).last end + column :used do |issuance| + used = issuance.gift_cards.where(registrations_available: 0).count + total = issuance.gift_cards.count + raw("#{number_with_delimiter(used)}/#{number_with_delimiter(issuance.gift_cards.count)}
(#{(used / total.to_f * 100).round(1)}%)") + end column :begin_use_date column :end_use_date column :expiration_date diff --git a/app/models/issuance.rb b/app/models/issuance.rb index 0e16be9..1b21454 100644 --- a/app/models/issuance.rb +++ b/app/models/issuance.rb @@ -40,7 +40,7 @@ class Issuance < ApplicationRecord end def to_s - if preview? + if previewing? "Gift Card Issuance (Preview)" elsif issued? "Issuance by #{issuer.full_name} #{created_at}" diff --git a/import.rb b/import.rb index 84a35a5..8fc94aa 100644 --- a/import.rb +++ b/import.rb @@ -136,3 +136,7 @@ end GiftCard.import(batch) + +Issuance.where(quantity: [nil, 0]).each do |i| + i.update(quantity: i.gift_cards.count) +end