booking prices in

This commit is contained in:
Seth Call 2018-01-14 10:12:15 -06:00
parent 2324a5d309
commit d0bbf92dd1
8 changed files with 114 additions and 11 deletions

View File

@ -8,3 +8,7 @@ Immediately the focus is on using active_scaffolding that provides visibility in
Overtime we can add more administrative functions and views, but initially this is one of the easiest ways to give 'powertools' behind the scenes with an entirely separate authentication model. Overtime we can add more administrative functions and views, but initially this is one of the easiest ways to give 'powertools' behind the scenes with an entirely separate authentication model.
Examples of:
Button on Show Page of Item: 'Send Client Update Notice' in jam_ruby_artifact_updates.rb

View File

@ -18,10 +18,8 @@ ActiveAdmin.register JamRuby::ArtifactUpdate, :as => 'Artifacts' do
end end
f.actions f.actions
end end
action_item :only => [:show] do action_item :only => [:show] do
link_to('Send Client Update Notice', send_client_update_notice_admin_artifact_path(resource.id)) link_to('Send Client Update Notice', send_client_update_notice_admin_artifact_path(resource.id))
end end

View File

@ -16,6 +16,18 @@ ActiveAdmin.register JamRuby::LessonSession, :as => 'LessonSessions' do
scope("Missed") { |scope| scope.unscoped.missed.order('created_at desc') } scope("Missed") { |scope| scope.unscoped.missed.order('created_at desc') }
scope("Completed") { |scope| scope.unscoped.completed.order('created_at desc') } scope("Completed") { |scope| scope.unscoped.completed.order('created_at desc') }
action_item :only => [:show] do
link_to('Mark As Success', mark_success_admin_lesson_session_path(resource.id))
end
member_action :mark_success, :method => :get do
if !resource.success
resource.mark_lesson(true, true)
end
redirect_to :back
end
index do index do
column "Actions" do |teacher| column "Actions" do |teacher|
links = ''.html_safe links = ''.html_safe
@ -64,6 +76,11 @@ ActiveAdmin.register JamRuby::LessonSession, :as => 'LessonSessions' do
show do show do
attributes_table do attributes_table do
row "Lesson Booking" do |lesson_session|
span do
link_to "Lesson Booking", lesson_session.lesson_booking.admin_url
end
end
row "App Link" do |lesson_session| row "App Link" do |lesson_session|
lesson_booking = lesson_session.lesson_booking lesson_booking = lesson_session.lesson_booking
span do span do

View File

@ -10,8 +10,8 @@ ActiveAdmin.register JamRuby::Teacher, :as => 'Teachers' do
scope("All", default: true) { |scope| scope.unscoped.order("background_check_at > '#{(Date.today - 365).to_s}}' NULLS FIRST, ready_for_session_at IS NULL DESC") } scope("All", default: true) { |scope| scope.unscoped.order("background_check_at > '#{(Date.today - 365).to_s}}' NULLS FIRST, ready_for_session_at IS NULL DESC") }
scope("All Sorted By Sign Up") { |scope| scope.unscoped.order("teachers.created_at DESC, background_check_at > '#{(Date.today - 365).to_s}}' NULLS FIRST, ready_for_session_at IS NULL DESC") } scope("All Sorted By Sign Up") { |scope| scope.unscoped.order("teachers.created_at DESC, background_check_at > '#{(Date.today - 365).to_s}}' NULLS FIRST, ready_for_session_at IS NULL DESC") }
scope("50% and Session Ready" ) { |scope| scope.unscoped.where('profile_pct >= ?', 50.0).where('ready_for_session_at IS NOT NULL').order("background_check_at > '#{(Date.today - 365).to_s}}' NULLS FIRST, ready_for_session_at IS NULL DESC") } scope("50% and Session Ready") { |scope| scope.unscoped.where('profile_pct >= ?', 50.0).where('ready_for_session_at IS NOT NULL').order("background_check_at > '#{(Date.today - 365).to_s}}' NULLS FIRST, ready_for_session_at IS NULL DESC") }
scope("50% and Not Session Ready" ) { |scope| scope.unscoped.where('profile_pct > ?', 50.0).where('ready_for_session_at IS NULL').order("background_check_at > '#{(Date.today - 365).to_s}}' NULLS FIRST, ready_for_session_at IS NULL DESC") } scope("50% and Not Session Ready") { |scope| scope.unscoped.where('profile_pct > ?', 50.0).where('ready_for_session_at IS NULL').order("background_check_at > '#{(Date.today - 365).to_s}}' NULLS FIRST, ready_for_session_at IS NULL DESC") }
index do index do
column "Name" do |teacher| column "Name" do |teacher|
@ -156,21 +156,25 @@ ActiveAdmin.register JamRuby::Teacher, :as => 'Teachers' do
br br
br br
div do div do
h5 do "Completed Sections" end h5 do
"Completed Sections"
end
teacher.pct_complete.each do |k, v| teacher.pct_complete.each do |k, v|
if k != :pct && v if k != :pct && v
div do div do
k k
end end
end end
end end
br br
br br
h5 do "Uncompleted Sections" end h5 do
"Uncompleted Sections"
end
teacher.pct_complete.each do |k, v| teacher.pct_complete.each do |k, v|
if k != :pct && !v if k != :pct && !v
div do div do
k k
end end
end end
end end
@ -274,6 +278,52 @@ ActiveAdmin.register JamRuby::Teacher, :as => 'Teachers' do
end end
end end
row "Booking Prices" do |teacher|
div do
table = teacher.booking_price_table
if table[:single].length == 0 and table[:monthly].length == 0
'No Pricing'
else
if table[:single].length > 0
div do
span do
'SINGLE'
end
span do
br
end
table[:single].each do |single|
span do
"#{single[:minutes]} min = $#{'%.2f' % (single[:price]/100.0)}"
end
span do
br
end
end
end
end
if table[:monthly].length > 0
div do
span do
'MONTHLY'
end
span do
br
end
table[:monthly].each do |monthly|
span do
"#{monthly[:minutes]} min = $#{'%.2f' % (monthly[:price]/100.0)}"
end
span do
br
end
end
end
end
end
end
end
end end
end end

View File

@ -0,0 +1,2 @@
class JsonInput < Formtastic::Inputs::StringInput
end

View File

@ -171,15 +171,16 @@ module JamRuby
end end
end end
# give 2 days to auto-cancel; this lets people just jump in a session and mark it done
def self.auto_cancel def self.auto_cancel
MusicSession.joins(lesson_session: :lesson_booking).where('lesson_sessions.status = ? OR lesson_bookings.status = ?', LessonSession::STATUS_REQUESTED, LessonBooking::STATUS_COUNTERED).where("? > scheduled_start + (INTERVAL '1 minutes' * (duration))", Time.now).each do |music_session| MusicSession.joins(lesson_session: :lesson_booking).where('lesson_sessions.status = ? OR lesson_bookings.status = ?', LessonSession::STATUS_REQUESTED, LessonBooking::STATUS_COUNTERED).where("? > scheduled_start + (INTERVAL '2 days' * (duration))", Time.now).each do |music_session|
lesson_session = music_session.lesson_session lesson_session = music_session.lesson_session
lesson_session.autocancel lesson_session.autocancel
end end
end end
def self.analyse_sessions def self.analyse_sessions
MusicSession.joins(lesson_session: :lesson_booking).where('lesson_sessions.status = ? AND lesson_bookings.status != ?', LessonSession::STATUS_APPROVED, LessonBooking::STATUS_COUNTERED).where("? > scheduled_start + (INTERVAL '1 minutes' * (duration))", Time.now).where('analysed = false').each do |music_session| MusicSession.joins(lesson_session: :lesson_booking).where('(lesson_sessions.status = ? OR lesson_sessions.status = ?) AND lesson_bookings.status != ?', LessonSession::STATUS_APPROVED, LessonBooking::STATUS_REQUESTED, LessonBooking::STATUS_COUNTERED).where("? > scheduled_start + (INTERVAL '1 minutes' * (duration))", Time.now).where('analysed = false').each do |music_session|
lesson_session = music_session.lesson_session lesson_session = music_session.lesson_session
lesson_session.analyse lesson_session.analyse
end end
@ -218,6 +219,12 @@ module JamRuby
end end
def mark_lesson(success, administratively_marked = false) def mark_lesson(success, administratively_marked = false)
if !self.success && (is_requested? || is_unconfirmed?)
# what's going on here is that we will just mark a session as a success if the the people got in in case of requested sessions
# but otherwise, leave it alone, so that the people can after-the-fact reschedule it (don't close it out and treat as a failure)
return
end
self.success = success self.success = success
self.analysed_at = Time.now self.analysed_at = Time.now
self.analysed = true self.analysed = true
@ -576,6 +583,10 @@ module JamRuby
status == STATUS_COUNTERED status == STATUS_COUNTERED
end end
def is_unconfirmed?
status == STATUS_UNCONFIRMED
end
def analysis_json def analysis_json
@parsed_analysis || analysis @parsed_analysis || analysis
end end

View File

@ -327,6 +327,24 @@ module JamRuby
end end
end end
def booking_price_table
table = {single:[], monthly:[]}
durations_allowed = []
[30, 45, 60, 90, 120].each do |i|
durations_allowed << i if self["lesson_duration_#{i}"]
end
durations_allowed.each do |i|
if self["price_per_lesson_#{i}_cents"]
table[:single] << {minutes: i, price: self["price_per_lesson_#{i}_cents"]}
end
if self["price_per_month_#{i}_cents"]
table[:monthly] << {minutes: i, price: self["price_per_month_#{i}_cents"]}
end
end
table
end
def offer_pricing def offer_pricing
unless prices_per_lesson.present? || prices_per_month.present? unless prices_per_lesson.present? || prices_per_month.present?
errors.add(:offer_pricing, "Must choose to price per lesson or per month") errors.add(:offer_pricing, "Must choose to price per lesson or per month")
@ -478,7 +496,7 @@ module JamRuby
elsif instruments.length == 2 elsif instruments.length == 2
return 'Teaches ' + instruments[0].description + ' and ' + instruments[1].description return 'Teaches ' + instruments[0].description + ' and ' + instruments[1].description
else else
return 'Teaches ' + instruments.map {|i| i.description}.join(', ') return 'Teaches ' + instruments.map { |i| i.description }.join(', ')
end end
end end
end end

View File

@ -251,6 +251,9 @@ describe "TestDrive Lesson Flow" do
LessonBooking.bookings(user, teacher_user, nil).count.should eql 1 LessonBooking.bookings(user, teacher_user, nil).count.should eql 1
LessonBooking.engaged_bookings(user, teacher_user, nil).count.should eql 1 LessonBooking.engaged_bookings(user, teacher_user, nil).count.should eql 1
teacher_user.has_booked_test_drive_with_student?(user).should be_true teacher_user.has_booked_test_drive_with_student?(user).should be_true
booking.reload
booking.lesson_sessions.length.should eql 1
end end
it "works using posa card" do it "works using posa card" do