Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sac points tracking system:tm: #1015

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/admin/activities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def activity_post_params
:is_freshmans,
:participant_limit,
:show_participants,
:sac_category,
:_destroy)
end
end
17 changes: 17 additions & 0 deletions app/controllers/admin/members_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ def show
.order(created_at: :desc), items: 10)
end

def sac
data = "name;category;points;date;activity"
member = Member.find params[:member_id]

# Find all activities a members participated in with sac points
sac_eligible = member.activities.filter { |ac| (ac.sac_category? and ac.sac_category > 0) or ac.participants.where(member: member).first.sac_points? }

# Create csv rows for every activity
sac_eligible.each do |ac|
category = SAC_CATEGORIES.find { |c| c[:id] == ac.sac_category }
points = ac.participants.where(member: member).first.sac_points or category[:points]
data += "\n#{ member.name };#{ category[:name] };#{ points };#{ ac.start_date };#{ ac.name }"
end

send_data data, { filename: "data.csv" }
end

def new
@member = Member.new

Expand Down
4 changes: 4 additions & 0 deletions app/controllers/admin/participants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def update

message = 'price'
@participant.update(price: params[:price])
elsif params[:sac_points].present?
raise 'negative sac points' unless params[:sac_points].to_i >= 0

@participant.update(sac_points: params[:sac_points])
end

if @participant.save
Expand Down
139 changes: 75 additions & 64 deletions app/javascript/src/admin/activities.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ function bind_activities() {

// Admin updates participant's price
// [PATCH] participants
$("#participants").find("input.price").on("change", participant.updatePrice);
$("#participants")
.find("input.price")
.on("change", participant.updateValue("price"));
$("#participants")
.find("input.sac")
.on("change", participant.updateValue("sac_points"));
}

/*
Expand Down Expand Up @@ -275,73 +280,79 @@ var participant = {
},

//Admin updates participant's price
updatePrice: function () {
var row = $(this).closest("tr");
var token = encodeURIComponent(
$(this).closest(".page").attr("data-authenticity-token")
);
var price = $(this).val().replace(",", ".");

// If left blank assume 0
if (!price) {
price = 0;
$(this).val(0);
}

// Make it a bit more pretty
if (!isNaN(price)) $(this).val(parseFloat(price).toFixed(2));

$.ajax({
url:
"/activities/" +
row.attr("data-activities-id") +
"/participants/" +
row.attr("data-id"),
type: "PATCH",
data: {
authenticity_token: token,
price: price,
},
})
.done(function (data) {
$(row)
.find("button.unpaid")
.empty()
.addClass("paid btn-warning")
.removeClass("d-none unpaid btn-primary")
.append('<i class="fa fa-fw fa-times"></i>');
$(row).find("button.paid").removeClass("d-none");
$(row).removeClass("in-debt");

if (price > 0) {
$(row).addClass("in-debt");

$("#mail").trigger("recipient_unpayed", [
$(row).attr("data-id"),
$(row).find("a").html(),
$(row).attr("data-email"),
]);
} else {
$(row).find("button.paid").addClass("d-none");
updateValue: (field) =>
function () {
var row = $(this).closest("tr");
var token = encodeURIComponent(
$(this).closest(".page").attr("data-authenticity-token")
);
var value = $(this).val().replace(",", ".");

$("#mail").trigger("recipient_payed", [
$(row).attr("data-id"),
$(row).find("a").html(),
$(row).attr("data-email"),
]);
}
// If left blank assume 0
if (!value) {
value = 0;
$(this).val(0);
}

participant.update_debt_header(
data.activity.paid_sum,
data.activity.price_sum
);
// Make it a bit more pretty
if (field === "price" && !isNaN(value))
$(this).val(parseFloat(value).toFixed(2));

toastr.success(I18n.t("admin.activities.info.price_changed"));
$.ajax({
url:
"/activities/" +
row.attr("data-activities-id") +
"/participants/" +
row.attr("data-id"),
type: "PATCH",
data: {
authenticity_token: token,
[field]: value,
},
})
.fail(function () {
toastr.error(I18n.t("admin.activities.info.price_error"));
});
},
.done(function (data) {
if (field === "price") {
$(row)
.find("button.unpaid")
.empty()
.addClass("paid btn-warning")
.removeClass("d-none unpaid btn-primary")
.append('<i class="fa fa-fw fa-times"></i>');
$(row).find("button.paid").removeClass("d-none");
$(row).removeClass("in-debt");

if (value > 0) {
$(row).addClass("in-debt");

$("#mail").trigger("recipient_unpayed", [
$(row).attr("data-id"),
$(row).find("a").html(),
$(row).attr("data-email"),
]);
} else {
$(row).find("button.paid").addClass("d-none");

$("#mail").trigger("recipient_payed", [
$(row).attr("data-id"),
$(row).find("a").html(),
$(row).attr("data-email"),
]);
}

participant.update_debt_header(
data.activity.paid_sum,
data.activity.price_sum
);

toastr.success(I18n.t("admin.activities.info.price_changed"));
} else {
toastr.success(I18n.t("admin.activities.info.sac_changed"));
}
})
.fail(function () {
toastr.error(I18n.t("admin.activities.info.price_error"));
});
},
};

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

%td.price-input-td{:style => 'padding: 0px; min-width: 10%; width: 10%; text-align:left;' }
%input.price{ :type => 'text', :value => number_to_currency(participant.currency, :unit => ''), :autocomplete=>'off'}
%td.sac-input-td{:style => 'padding: 0px; min-width: 10%; width: 10%; text-align:left;' }
- category = SAC_CATEGORIES.find { |c| c[:id] == @activity.sac_category }
%input.sac{ :type => 'text', :value => (participant.sac_points or (category[:points] if category) or 0), :autocomplete=>'off'}
%td.notes-td
- if participant.notes
= participant.notes
Expand Down
3 changes: 3 additions & 0 deletions app/views/admin/activities/partials/_edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@
.col-lg-6
= f.label :participant_limit
= f.number_field :participant_limit, min: 0, data: {original: @activity.participant_limit}, id: "participant_limit"
.col-lg-6
= f.label :sac_category
= f.select :sac_category, choices: [["None", 0]] + SAC_CATEGORIES.map { |c| [c[:name], c[:id]] }
%hr.my-4
.row
.col-md-4
Expand Down
8 changes: 8 additions & 0 deletions app/views/admin/activities/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
= I18n.t('activerecord.attributes.activity.name')
%td{ :style => 'padding: 0px; min-width: 10%; width: 10%; text-align:left;' }
= I18n.t('activerecord.attributes.activity.price')
%td{ :style => 'padding: 0px; min-width: 10%; width: 10%; text-align:left;' }
= I18n.t('admin.sac.title')
- if !@is_summarized.nil?
%td
= I18n.t('activerecord.attributes.activity.notes')
Expand All @@ -60,6 +62,8 @@

%td.price-input-td{:style => 'padding: 0px; min-width: 10%; width: 10%; text-align:left;' }
%input.price{ :type => 'text', :value => number_to_currency(participant.currency, :unit => ''), :autocomplete=>'off'}
%td.sac-input-td{:style => 'padding: 0px; min-width: 10%; width: 10%; text-align:left;' }
%input.sac{ :type => 'text', :value => (participant.sac_points or @activity.sac_points or 0), :autocomplete=>'off'}
%td.notes-td
%td.buttons
.btn-group
Expand All @@ -79,6 +83,10 @@
%td{ :style => 'text-align: left;' }
- if [email protected]?
%span= number_to_currency(@activity.price, :unit => '€')
%td{ :style => 'text-align: left;' }
- if [email protected]_category.nil?
- category = SAC_CATEGORIES.find { |c| c[:id] == @activity.sac_category }
%span= (category[:points] if category) or 0
%td
%td

Expand Down
25 changes: 25 additions & 0 deletions app/views/admin/members/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,31 @@
%button.btn.btn-default.destroy
%i.fa.fa-fw.fa-trash

.card
.card-header
= I18n.t('admin.sac.title')
= link_to I18n.t("admin.sac.download"), member_sac_path(@member.id)
%table.table.table-striped#sac
%thead
%tr
%th= I18n.t('admin.activities.single')
%th= I18n.t('admin.sac.category')
%th= I18n.t('admin.sac.title')
%tbody
- total = 0
- @activities.select{ |ac| ac.sac_category? or ac.participants.where(:member => @member).first.sac_points?}.each do |activity|
stickyPiston marked this conversation as resolved.
Show resolved Hide resolved
%tr
- category = SAC_CATEGORIES.find {|c| c[:id] == activity.sac_category }
%td= link_to activity.name, activity
%td= category[:name] if activity.sac_category?
- user_points = activity.participants.where(:member => @member).first.sac_points
- points = [user_points, (activity.sac_category? and category[:points]), 0].find{ |n| n.present? }
- total += points if points.present?
%td= points
%tr
%td= I18n.t('admin.sac.total')
%td
%td= total

.card
.card-header
Expand Down
6 changes: 6 additions & 0 deletions config/initializers/sac.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SAC_CATEGORIES = [
stickyPiston marked this conversation as resolved.
Show resolved Hide resolved
{ id: 0, name: "None", points: 0 },
{ id: 1, name: "Category 1", points: 10 },
{ id: 2, name: "Category 2", points: 20 },
{ id: 3, name: "Category 3", points: 30 },
].freeze
6 changes: 6 additions & 0 deletions config/locales/admin.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ en:
already_added: This participant was already added
price_changed: The participants fee has changed
price_error: No connection or not a number
sac_changed: The number of sac points has been changed
new: New activity
remove_participant: Do you want to remove %{user} as participant?
save: Save activity?
Expand Down Expand Up @@ -124,6 +125,11 @@ en:
pay_to: Could you transfer this amount to *NL61INGB0002877106* citing _Outstanding %{member}_?
title: Hey! %{user} from Sticky here :)
total_of: This comes down to a total of *%{amount}*
sac:
category: Category
download: Download report
title: Sac points
total: Total
settings:
action: Action
address: IP address
Expand Down
6 changes: 6 additions & 0 deletions config/locales/admin.nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ nl:
already_added: Deze persoon is al toegevoegd
price_changed: Het deelname bedrag is veranderd
price_error: Geen verbinding of geen nummer
sac_changed: Het aantal sac punten is veranderd
new: Nieuwe activiteit
remove_participant: Deelname van %{user} verwijderen?
save: Activiteit opslaan?
Expand Down Expand Up @@ -124,6 +125,11 @@ nl:
pay_to: Kan je dit overmaken naar *NL61INGB0002877106* onder vermelding van _Openstaand %{member}_?
title: Hey! %{user} van Sticky hier :)
total_of: Dit geeft een totaal van *%{amount}*
sac:
category: Categorie
download: Download rapport
title: Sac punten
total: Totaal
settings:
action: Actie
address: IP-adres
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
scope module: 'admin' do
resources :members do
get 'payment_whatsapp'
get 'sac'
patch 'force_email_change'
post 'email/:type', to: 'members#send_email', as: :mail
patch 'set_card_disabled/:uuid', to: 'members#set_card_disabled', as: 'set_card_disabled'
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20220429070907_add_sac_points.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddSacPoints < ActiveRecord::Migration[6.1]
def change
add_column :activities, :sac_category, :integer
add_column :participants, :sac_points, :integer
end
end
9 changes: 6 additions & 3 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ CREATE TABLE public.activities (
is_payable boolean DEFAULT false,
"VAT" character varying DEFAULT '21'::character varying,
open_date date,
open_time time without time zone
open_time time without time zone,
sac_category integer
);


Expand Down Expand Up @@ -725,7 +726,8 @@ CREATE TABLE public.participants (
created_at timestamp without time zone,
updated_at timestamp without time zone,
reservist boolean DEFAULT false,
notes character varying(30)
notes character varying(30),
sac_points integer
);


Expand Down Expand Up @@ -1668,6 +1670,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20210801152004'),
('20210808184948'),
('20211012104341'),
('20220221195220');
('20220221195220'),
('20220429070907');


Loading