VRFS-3964 - manage payment features for teacher
This commit is contained in:
parent
fe16d513be
commit
15d968dff5
|
|
@ -928,7 +928,7 @@ module JamRuby
|
|||
@lesson_session = lesson_session
|
||||
|
||||
email = @student.email
|
||||
subject = "You have used #{@student.remaining_test_drives} of 4 TestDrive lesson credits"
|
||||
subject = "You have used #{@student.remaining_test_drives} of #{@student.total_test_drives} TestDrive lesson credits"
|
||||
unique_args = {:type => "student_test_drive_success"}
|
||||
|
||||
sendgrid_category "Notification"
|
||||
|
|
@ -980,7 +980,7 @@ module JamRuby
|
|||
@lesson_session = lesson_session
|
||||
|
||||
email = @student.email
|
||||
subject = "You have used all 4 TestDrive lesson credits"
|
||||
subject = "You have used all TestDrive lesson credits"
|
||||
unique_args = {:type => "student_test_drive_success"}
|
||||
|
||||
sendgrid_category "Notification"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<% provide(:title, "You have used #{@student.remaining_test_drives} of 4 TestDrive lesson credits") %>
|
||||
<% provide(:title, "You have used #{@student.remaining_test_drives} of #{@student.total_test_drives} TestDrive lesson credits") %>
|
||||
<% provide(:photo_url, @teacher.resolved_photo_url) %>
|
||||
|
||||
<% content_for :note do %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
You have used <%= @student.remaining_test_drives %> of 4 TestDrive lesson credits.
|
||||
You have used <%= @student.remaining_test_drives %> of <%= @student.total_test_drives %> TestDrive lesson credits.
|
||||
|
||||
<% if @student.has_rated_teacher(@teacher) %>
|
||||
Also, please rate your teacher at <%= @teacher.ratings_url %> now for today’s lesson to help other students in the community find the best instructors.
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
<% provide(:title, "You have used all 4 TestDrive lesson credits") %>
|
||||
<% provide(:title, "You have used all TestDrive lesson credits") %>
|
||||
|
||||
<p>
|
||||
Hello <%= @student.name %>,
|
||||
</p>
|
||||
|
||||
<p>
|
||||
We hope you enjoyed your JamClass lesson today with <%= @teacher.name %>. You have now used all 4 TestDrive credits.
|
||||
We hope you enjoyed your JamClass lesson today with <%= @teacher.name %>. You have now used all your TestDrive credits.
|
||||
|
||||
<% if !@student.has_rated_teacher(@teacher) %>
|
||||
Please <a href="<%= @teacher.ratings_url %>" style="color:#fc0">rate your teacher</a> now for today’s lesson to
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
You have used all of your 4 TestDrive lesson credits.
|
||||
You have used all of your TestDrive lesson credits.
|
||||
|
||||
<% if @student.has_rated_teacher(@teacher) %>
|
||||
Also, please rate your teacher at <%= @teacher.ratings_url %> now for today’s lesson to help other students in the community find the best instructors.
|
||||
|
|
|
|||
|
|
@ -256,13 +256,13 @@ module JamRuby
|
|||
def test_drive_completed
|
||||
|
||||
distribution = teacher_distribution
|
||||
if distribution # not all lessons/payment charges have a distribution
|
||||
distribution.ready = true
|
||||
distribution.save(validate: false)
|
||||
end
|
||||
|
||||
if !sent_notices
|
||||
if success
|
||||
if distribution # not all lessons/payment charges have a distribution
|
||||
distribution.ready = true
|
||||
distribution.save(validate: false)
|
||||
end
|
||||
student.test_drive_succeeded(self)
|
||||
else
|
||||
student.test_drive_failed(self)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ module JamRuby
|
|||
limit ||= 100
|
||||
limit = limit.to_i
|
||||
|
||||
query = TeacherDistribution.where(teacher_id: current_user.id)
|
||||
query = TeacherDistribution.where(teacher_id: current_user.id).order('created_at desc')
|
||||
|
||||
current_page = params[:page].nil? ? 1 : params[:page].to_i
|
||||
next_page = current_page + 1
|
||||
|
|
@ -31,6 +31,16 @@ module JamRuby
|
|||
end
|
||||
end
|
||||
|
||||
def not_collectable
|
||||
if is_test_drive?
|
||||
false
|
||||
elsif is_normal?
|
||||
!lesson_session.billing_should_retry
|
||||
else
|
||||
! lesson_package_purchase.billing_should_retry
|
||||
end
|
||||
end
|
||||
|
||||
def self.create_for_lesson(lesson_session)
|
||||
distribution = create(lesson_session)
|
||||
distribution.lesson_session = lesson_session
|
||||
|
|
@ -51,6 +61,7 @@ module JamRuby
|
|||
distribution.amount_in_cents = target.lesson_booking.distribution_price_in_cents(target)
|
||||
distribution
|
||||
end
|
||||
|
||||
def amount
|
||||
amount_in_cents / 100.0
|
||||
end
|
||||
|
|
@ -63,7 +74,7 @@ module JamRuby
|
|||
if is_test_drive?
|
||||
0
|
||||
else
|
||||
(amount_in_cents * teacher.jamkazam_rate + 0.03).round
|
||||
(amount_in_cents * teacher.teacher.jamkazam_rate + 0.03).round
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -94,16 +105,16 @@ module JamRuby
|
|||
def description
|
||||
if lesson_session
|
||||
if lesson_session.lesson_booking.is_test_drive?
|
||||
"Test Drive session with #{lesson_session.lesson_booking.student.name} on #{lesson_session.scheduled_start.to_date}"
|
||||
"TestDrive session with #{lesson_session.lesson_booking.student.name} on #{lesson_session.scheduled_start.to_date.strftime('%B %d, %Y')}"
|
||||
elsif lesson_session.lesson_booking.is_normal?
|
||||
if lesson_session.lesson_booking.is_weekly_payment? || lesson_session.lesson_booking.is_monthly_payment?
|
||||
raise "Should not be here"
|
||||
else
|
||||
"A session with #{lesson_session.lesson_booking.student.name} on #{lesson_session.scheduled_start.to_date}"
|
||||
"Lesson with #{lesson_session.lesson_booking.student.name} on #{lesson_session.scheduled_start.to_date.strftime('%B %d, %Y')}"
|
||||
end
|
||||
end
|
||||
else
|
||||
"Monthly session for the month of #{lesson_package_purchase.month_name} with #{lesson_package_purchase.lesson_booking.student.name}"
|
||||
"Lessons for the month of #{lesson_package_purchase.month_name} with #{lesson_package_purchase.lesson_booking.student.name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2058,6 +2058,15 @@ module JamRuby
|
|||
lesson_purchases.where('lesson_package_type_id in (?)', [LessonPackageType.test_drive_package_ids]).order('created_at desc').first
|
||||
end
|
||||
|
||||
def total_test_drives
|
||||
purchase = most_recent_test_drive_purchase
|
||||
if purchase
|
||||
purchase.test_drive_count
|
||||
else
|
||||
0
|
||||
end
|
||||
end
|
||||
|
||||
def test_drive_succeeded(lesson_session)
|
||||
if self.remaining_test_drives <= 0
|
||||
UserMailer.student_test_drive_lesson_done(lesson_session).deliver
|
||||
|
|
@ -2083,7 +2092,7 @@ module JamRuby
|
|||
end
|
||||
|
||||
def used_test_drives
|
||||
4 - remaining_test_drives
|
||||
total_test_drives - remaining_test_drives
|
||||
end
|
||||
|
||||
def has_rated_teacher(teacher)
|
||||
|
|
|
|||
|
|
@ -2446,7 +2446,7 @@
|
|||
|
||||
function listTeacherDistributions(options) {
|
||||
|
||||
if(options) {
|
||||
if(!options) {
|
||||
options = {}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,30 +59,22 @@ profileUtils = context.JK.ProfileUtils
|
|||
@incrementCurrentPage()
|
||||
@refresh()
|
||||
|
||||
activeListItems: () ->
|
||||
tile = @activeTile()
|
||||
if tile == @TILE_PAYMENTS_TO_YOU
|
||||
this.state.teacher_distributions
|
||||
else if tile == @TILE_PAYMENTS_TO_JAMKAZAM
|
||||
this.state.sales
|
||||
else
|
||||
[]
|
||||
|
||||
componentDidUpdate: (prevProps, prevState) ->
|
||||
#@iCheckify()
|
||||
|
||||
if @state.next == null
|
||||
if @currentNext() == null
|
||||
@contentBodyScroller.off('scroll')
|
||||
if @state.salesCurrentPage == 1 and @state.sales.length == 0
|
||||
if @state[@getCurrentPageName()] == 1 and @getCurrentList().length == 0
|
||||
@endOfList.show()
|
||||
logger.debug("PaymentHistoryScreen: empty search")
|
||||
else if @state.salesCurrentPage > 0
|
||||
else if @state[@getCurrentPageName()] > 0
|
||||
logger.debug("end of search")
|
||||
@endOfList.show()
|
||||
else
|
||||
@registerInfiniteScroll(@contentBodyScroller)
|
||||
|
||||
if @activeTile(prevState.selected) != @activeTile()
|
||||
if @activeTile(prevState.selected) != @activeTile() && @getCurrentList().length == 0
|
||||
@refresh()
|
||||
|
||||
checkboxChanged: (e) ->
|
||||
|
|
@ -109,6 +101,8 @@ profileUtils = context.JK.ProfileUtils
|
|||
@refreshTeacherDistributions()
|
||||
else if @activeTile() == @TILE_PAYMENTS_TO_JAMKAZAM
|
||||
@refreshSales()
|
||||
else
|
||||
logger.debug("dropping refresh because no tile match", @activeTile)
|
||||
|
||||
refreshSales: () ->
|
||||
@refreshing = true
|
||||
|
|
@ -124,7 +118,7 @@ profileUtils = context.JK.ProfileUtils
|
|||
|
||||
salesHistoryDone:(response) ->
|
||||
@refreshing = false
|
||||
this.setState({next: response.next, sales: this.state.sales.concat(response.entries)})
|
||||
this.setState({salesNext: response.next, sales: this.state.sales.concat(response.entries)})
|
||||
|
||||
salesHistoryFail:(jqXHR) ->
|
||||
@refreshing = false
|
||||
|
|
@ -132,7 +126,7 @@ profileUtils = context.JK.ProfileUtils
|
|||
|
||||
teacherDistributionsDone:(response) ->
|
||||
@refreshing = false
|
||||
this.setState({next: response.next, distributions: this.state.distributions.concat(response.entries)})
|
||||
this.setState({distributionsNext: response.next, distributions: this.state.distributions.concat(response.entries)})
|
||||
|
||||
teacherDistributionsFail:(jqXHR) ->
|
||||
@refreshing = false
|
||||
|
|
@ -140,18 +134,17 @@ profileUtils = context.JK.ProfileUtils
|
|||
|
||||
|
||||
clearResults:() ->
|
||||
this.setState({salesCurrentPage: 0, sales: [], distributionsCurrentPage: [], distributions: 0, next: null})
|
||||
this.setState({salesCurrentPage: 0, sales: [], distributionsCurrentPage: 0, distributions: [], salesNext: null, distributionsNext: null})
|
||||
|
||||
buildQuery:(page = @getCurrentPage()) ->
|
||||
console.log("PAGE!", page)
|
||||
@currentQuery = this.defaultQuery(page)
|
||||
|
||||
defaultQuery:(page = @getCurrentPage()) ->
|
||||
query =
|
||||
per_page: @LIMIT
|
||||
page: page + 1
|
||||
if this.state.next
|
||||
query.since = this.state.next
|
||||
if @currentNext()
|
||||
query.page = @currentNext()
|
||||
query
|
||||
|
||||
getCurrentPage: () ->
|
||||
|
|
@ -173,16 +166,33 @@ profileUtils = context.JK.ProfileUtils
|
|||
else
|
||||
1
|
||||
|
||||
getCurrentList: () ->
|
||||
if @activeTile() == @TILE_PAYMENTS_TO_JAMKAZAM
|
||||
@state['sales']
|
||||
else if @activeTile() == @TILE_PAYMENTS_TO_YOU
|
||||
@state['distributions']
|
||||
else
|
||||
@state['sales']
|
||||
|
||||
currentNext: () ->
|
||||
if @activeTile() == @TILE_PAYMENTS_TO_JAMKAZAM
|
||||
@state.salesNext
|
||||
else if @activeTile() == @TILE_PAYMENTS_TO_YOU
|
||||
@state.distributionsNext
|
||||
else
|
||||
null
|
||||
|
||||
getInitialState: () ->
|
||||
{
|
||||
user: null,
|
||||
nextPager: null,
|
||||
salesCurrentPage: 0,
|
||||
distributionsCurrentPage: 0
|
||||
next: null,
|
||||
salesNext: null,
|
||||
distributionsNext: null
|
||||
sales: [],
|
||||
distributions: []
|
||||
selected: null
|
||||
selected: 'payments to jamkazam'
|
||||
}
|
||||
|
||||
onCancel: (e) ->
|
||||
|
|
@ -205,7 +215,7 @@ profileUtils = context.JK.ProfileUtils
|
|||
paymentsToYou: () ->
|
||||
rows = []
|
||||
|
||||
for paymentHistory in this.state.sales
|
||||
for paymentHistory in @getCurrentList()
|
||||
paymentMethod = 'Stripe'
|
||||
|
||||
if paymentHistory.distributed
|
||||
|
|
@ -213,10 +223,24 @@ profileUtils = context.JK.ProfileUtils
|
|||
status = 'Paid'
|
||||
else
|
||||
date = paymentHistory.created_at
|
||||
status = 'Collecting'
|
||||
date = context.JK.formatDate(date, true)
|
||||
if paymentHistory.not_collectable
|
||||
status = 'Uncollectible'
|
||||
else if !paymentHistory.teacher?.teacher?.stripe_account_id?
|
||||
status = 'No Stripe Acct'
|
||||
else
|
||||
status = 'Collecting'
|
||||
|
||||
|
||||
date = context.JK.formatDate(date, true)
|
||||
description = paymentHistory.description
|
||||
|
||||
if paymentHistory.teacher_payment?
|
||||
amt = paymentHistory.teacher_payment.real_distribution_in_cents
|
||||
else
|
||||
amt = paymentHistory.real_distribution_in_cents
|
||||
|
||||
displayAmount = ' $' + (amt/100).toFixed(2)
|
||||
|
||||
amountClasses = {status: status}
|
||||
|
||||
row =
|
||||
|
|
@ -259,7 +283,7 @@ profileUtils = context.JK.ProfileUtils
|
|||
paymentsToJamKazam: () ->
|
||||
rows = []
|
||||
|
||||
for paymentHistory in this.state.sales
|
||||
for paymentHistory in @getCurrentList()
|
||||
paymentMethod = 'Credit Card'
|
||||
if paymentHistory.sale?
|
||||
sale = paymentHistory.sale
|
||||
|
|
|
|||
|
|
@ -1,12 +1,18 @@
|
|||
object @teacher_distribution
|
||||
|
||||
attributes :id, :description, :ready, :distributed, :created_at, :amount_in_cents, :real_distribution_in_cents
|
||||
attributes :id, :description, :ready, :distributed, :created_at, :amount_in_cents, :real_distribution_in_cents, :not_collectable
|
||||
|
||||
child(:teacher => :teacher) {
|
||||
child(:teacher => :teacher) {
|
||||
attributes :stripe_account_id
|
||||
}
|
||||
}
|
||||
|
||||
child(:teacher_payment => :teacher_payment) {
|
||||
attributes :real_distribution_in_cents, :created_at
|
||||
|
||||
child(:teacher_payment_charge => :teacher_payment_charge) {
|
||||
attributes: last_billing_attempt_at
|
||||
attributes last_billing_attempt_at
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue