diff --git a/ruby/lib/jam_ruby/models/teacher_distribution.rb b/ruby/lib/jam_ruby/models/teacher_distribution.rb index 597cd3107..cec347b37 100644 --- a/ruby/lib/jam_ruby/models/teacher_distribution.rb +++ b/ruby/lib/jam_ruby/models/teacher_distribution.rb @@ -55,6 +55,18 @@ module JamRuby amount_in_cents / 100.0 end + def real_distribution_in_cents + amount_in_cents - calculate_teacher_fee + end + + def calculate_teacher_fee + if is_test_drive? + 0 + else + (amount_in_cents * teacher.jamkazam_rate + 0.03).round + end + end + def student if lesson_session lesson_session.student diff --git a/ruby/lib/jam_ruby/models/teacher_payment.rb b/ruby/lib/jam_ruby/models/teacher_payment.rb index 3ee7ee162..789be57d7 100644 --- a/ruby/lib/jam_ruby/models/teacher_payment.rb +++ b/ruby/lib/jam_ruby/models/teacher_payment.rb @@ -51,15 +51,10 @@ module JamRuby 24 end - def calculate_teacher_fee - if teacher_distribution.is_test_drive? - 0 - else - (amount_in_cents * 0.28).round - end + def real_distribution_in_cents + amount_in_cents - fee_in_cents end - # will find, for a given teacher, an outstading unsuccessful payment or make a new one. # it will then associate a charge with it, and then execute the charge. def self.charge(teacher) @@ -81,7 +76,7 @@ module JamRuby payment.amount_in_cents = payment.teacher_distribution.amount_in_cents - payment.fee_in_cents = payment.calculate_teacher_fee + payment.fee_in_cents = payment.teacher_distribution.calculate_teacher_fee if payment.teacher_payment_charge.nil? charge = TeacherPaymentCharge.new diff --git a/web/app/assets/javascripts/react-components/AccountPaymentHistoryScreen.js.jsx.coffee b/web/app/assets/javascripts/react-components/AccountPaymentHistoryScreen.js.jsx.coffee index 786585d8f..d4b5deeef 100644 --- a/web/app/assets/javascripts/react-components/AccountPaymentHistoryScreen.js.jsx.coffee +++ b/web/app/assets/javascripts/react-components/AccountPaymentHistoryScreen.js.jsx.coffee @@ -24,7 +24,7 @@ profileUtils = context.JK.ProfileUtils TILE_PAYMENT_METHOD: 'payment method' STUDENT_TILES: ['payments to jamkazam', 'payment method'] - TEACHER_TILES: ['payments to you', 'payments to jamkazam'] + TEACHER_TILES: ['payments to jamkazam', 'payments to you'] onAppInit: (@app) -> @app.bindScreen('account/paymentHistory', {beforeShow: @beforeShow, afterShow: @afterShow, beforeHide: @beforeHide}) @@ -68,7 +68,7 @@ profileUtils = context.JK.ProfileUtils else [] - componentDidUpdate: () -> + componentDidUpdate: (prevProps, prevState) -> #@iCheckify() if @state.next == null @@ -82,6 +82,9 @@ profileUtils = context.JK.ProfileUtils else @registerInfiniteScroll(@contentBodyScroller) + if @activeTile(prevState.selected) != @activeTile() + @refresh() + checkboxChanged: (e) -> checked = $(e.target).is(':checked') @@ -200,6 +203,55 @@ profileUtils = context.JK.ProfileUtils @paymentsToJamKazam() paymentsToYou: () -> + rows = [] + + for paymentHistory in this.state.sales + paymentMethod = 'Stripe' + + if paymentHistory.distributed + date = paymentHistory.teacher_payment.teacher_payment_charge.last_billing_attempt_at + status = 'Paid' + else + date = paymentHistory.created_at + status = 'Collecting' + date = context.JK.formatDate(date, true) + + + amountClasses = {status: status} + + row = + ` + {date} + {paymentMethod} + {description} + {status} + {displayAmount} + ` + rows.push(row) + + `
+ + + + + + + + + + + + {rows} + + +
DATEMETHODDESCRIPTIONSTATUSAMOUNT
+ Next +
No more payment history
+
+ BACK +
+
+
` paymentMethod: () -> @@ -268,9 +320,9 @@ profileUtils = context.JK.ProfileUtils e.preventDefault() @setState({selected: selection}) - activeTile: () -> - if this.state.selected? - this.state.selected + activeTile: (selected = this.state.selected) -> + if selected? + selected else @tiles()[0] diff --git a/web/app/assets/javascripts/react-components/BroadcastHolder.js.jsx.coffee b/web/app/assets/javascripts/react-components/BroadcastHolder.js.jsx.coffee index 3232e3444..575432605 100644 --- a/web/app/assets/javascripts/react-components/BroadcastHolder.js.jsx.coffee +++ b/web/app/assets/javascripts/react-components/BroadcastHolder.js.jsx.coffee @@ -13,9 +13,12 @@ BroadcastHolder = React.createClass( if this.state.notification if this.state.notification.isLesson - notification.push(``) + result = `` else - notification.push(``) + result = `` + + if result? + notification.push(result) `
diff --git a/web/app/assets/javascripts/react-components/InLessonBroadcast.js.jsx.coffee b/web/app/assets/javascripts/react-components/InLessonBroadcast.js.jsx.coffee index 1073f830b..fc85530ab 100644 --- a/web/app/assets/javascripts/react-components/InLessonBroadcast.js.jsx.coffee +++ b/web/app/assets/javascripts/react-components/InLessonBroadcast.js.jsx.coffee @@ -77,8 +77,11 @@ context = window

We apologize for your inconvenience, and we will work to remedy this situation.

` - `
- {content} -
` + if content? + `
+ {content} +
` + else + null }) diff --git a/web/app/assets/javascripts/react-components/stores/BroadcastStore.js.coffee b/web/app/assets/javascripts/react-components/stores/BroadcastStore.js.coffee index 645f7e82b..cbaf025a3 100644 --- a/web/app/assets/javascripts/react-components/stores/BroadcastStore.js.coffee +++ b/web/app/assets/javascripts/react-components/stores/BroadcastStore.js.coffee @@ -76,25 +76,34 @@ BroadcastStore = Reflux.createStore( if !@currentLesson? logger.debug("BroadcastStore: ignoring lessonAnalysisDone") + return + if @analysis.status == 'completed' + logger.debug("BroadcastStore: lesson is over") @currentLesson.completed = true @currentLesson.success = @analysis.success + @clearTimer() @changed() else if @analysis.analysis.reason != 'teacher_fault' + logger.debug("BroadcastStore: not teacher fault; clearing lesson info") @clearLesson() else + logger.debug("BroadcastStore: teacher is at fault") @teacherFault = true + @clearTimer() @changed() clearLesson: () -> if @currentLesson? @currentLesson = null - if @currentLessonTimer? - clearInterval(@currentLessonTimer) - @currentLessonTimer = null + @clearTimer() @teacherFault = false @changed() + clearTimer: () -> + if @currentLessonTimer? + clearInterval(@currentLessonTimer) + @currentLessonTimer = null onSessionChange: (session) -> @session = session diff --git a/web/app/assets/javascripts/react-components/stores/SessionStore.js.coffee b/web/app/assets/javascripts/react-components/stores/SessionStore.js.coffee index 969aa2860..def7bfe56 100644 --- a/web/app/assets/javascripts/react-components/stores/SessionStore.js.coffee +++ b/web/app/assets/javascripts/react-components/stores/SessionStore.js.coffee @@ -1026,6 +1026,11 @@ ConfigureTracksActions = @ConfigureTracksActions @currentSession = sessionData + if context.jamClient.UpdateSessionInfo? + if @currentSession? + context.jamClient.UpdateSessionInfo(@currentSession) + else + context.jamClient.UpdateSessionInfo({}) #logger.debug("session changed") @issueChange() diff --git a/web/app/assets/stylesheets/client/accountPaymentHistory.css.scss b/web/app/assets/stylesheets/client/accountPaymentHistory.css.scss index 0a01d1829..9c3931913 100644 --- a/web/app/assets/stylesheets/client/accountPaymentHistory.css.scss +++ b/web/app/assets/stylesheets/client/accountPaymentHistory.css.scss @@ -80,7 +80,7 @@ .profile-tile { - float: left; + float: right; @include border-box_sizing; height: 90px; position: relative; diff --git a/web/app/controllers/api_lesson_sessions_controller.rb b/web/app/controllers/api_lesson_sessions_controller.rb index ed091c783..6bc84e732 100644 --- a/web/app/controllers/api_lesson_sessions_controller.rb +++ b/web/app/controllers/api_lesson_sessions_controller.rb @@ -24,7 +24,7 @@ class ApiLessonSessionsController < ApiController if @lesson_session.analysed data = JSON.parse(@lesson_session.analysis) else - data = LessonSession.analysis_to_json(LessonSessionAnalyser.analyse(@lesson_session), true) + data = LessonSession.analysis_to_json(LessonSessionAnalyser.analyse(@lesson_session, true), true) end response = { diff --git a/web/app/controllers/api_teacher_distributions_controller.rb b/web/app/controllers/api_teacher_distributions_controller.rb index 30cb4265b..647fc94c0 100644 --- a/web/app/controllers/api_teacher_distributions_controller.rb +++ b/web/app/controllers/api_teacher_distributions_controller.rb @@ -6,7 +6,7 @@ class ApiTeacherDistributionsController < ApiController def index data = TeacherDistribution.index(current_user, params) - @distributions = data[:query] + @teacher_distributions = data[:query] @next = data[:next_page] render "api_teacher_distributions/index", :layout => nil end diff --git a/web/app/views/api_teacher_distributions/show.rabl b/web/app/views/api_teacher_distributions/show.rabl index 2f9ac2d82..f9e70ba3f 100644 --- a/web/app/views/api_teacher_distributions/show.rabl +++ b/web/app/views/api_teacher_distributions/show.rabl @@ -1,4 +1,12 @@ object @teacher_distribution -attributes :id, :description, :ready, :distributed, :created_at +attributes :id, :description, :ready, :distributed, :created_at, :amount_in_cents, :real_distribution_in_cents + +child(:teacher_payment => :teacher_payment) { + attributes :real_distribution_in_cents, :created_at + + child(:teacher_payment_charge => :teacher_payment_charge) { + attributes: last_billing_attempt_at + } +}