mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-03-01 23:29:23 +01:00
real fix for coupon change slot's original price (reverts cfd92cdc40)
This commit is contained in:
parent
9721872b2a
commit
3dc5f1a0e4
@ -426,7 +426,6 @@ Application.Controllers.controller "ReserveTrainingController", ["$scope", "$sta
|
|||||||
if $scope.ctrl.member
|
if $scope.ctrl.member
|
||||||
# reserve a training if this training will not be reserved and is not about to move and not is completed
|
# reserve a training if this training will not be reserved and is not about to move and not is completed
|
||||||
if !event.is_reserved && !$scope.slotToModify && !event.is_completed
|
if !event.is_reserved && !$scope.slotToModify && !event.is_completed
|
||||||
$scope.coupon.applied = null
|
|
||||||
if event != $scope.selectedTraining
|
if event != $scope.selectedTraining
|
||||||
$scope.selectedTraining = event
|
$scope.selectedTraining = event
|
||||||
$scope.selectedTraining.offered = false
|
$scope.selectedTraining.offered = false
|
||||||
@ -647,7 +646,7 @@ Application.Controllers.controller "ReserveTrainingController", ["$scope", "$sta
|
|||||||
# first we check that a user was selected
|
# first we check that a user was selected
|
||||||
if Object.keys($scope.ctrl.member).length > 0
|
if Object.keys($scope.ctrl.member).length > 0
|
||||||
r = mkReservation($scope.ctrl.member, training) # reservation without any Plan -> we get the training price
|
r = mkReservation($scope.ctrl.member, training) # reservation without any Plan -> we get the training price
|
||||||
Price.compute mkRequestParams(r, $scope.coupon.applied), (res) ->
|
Price.compute mkRequestParams(r), (res) ->
|
||||||
$scope.selectedTrainingAmount = res.price
|
$scope.selectedTrainingAmount = res.price
|
||||||
else
|
else
|
||||||
$scope.selectedTrainingAmount = null
|
$scope.selectedTrainingAmount = null
|
||||||
|
@ -5,7 +5,6 @@ Application.Directives.directive 'coupon', [ 'Coupon', 'growl', '_t', (Coupon, g
|
|||||||
show: '='
|
show: '='
|
||||||
coupon: '='
|
coupon: '='
|
||||||
userId: '@'
|
userId: '@'
|
||||||
hasSelectSlot: '='
|
|
||||||
templateUrl: '<%= asset_path "shared/_coupon.html" %>'
|
templateUrl: '<%= asset_path "shared/_coupon.html" %>'
|
||||||
link: ($scope, element, attributes) ->
|
link: ($scope, element, attributes) ->
|
||||||
|
|
||||||
@ -19,11 +18,6 @@ Application.Directives.directive 'coupon', [ 'Coupon', 'growl', '_t', (Coupon, g
|
|||||||
# Binding for the code inputed
|
# Binding for the code inputed
|
||||||
$scope.couponCode = null
|
$scope.couponCode = null
|
||||||
|
|
||||||
$scope.$watch 'hasSelectSlot', (newValue) ->
|
|
||||||
unless newValue
|
|
||||||
$scope.coupon = null
|
|
||||||
$scope.couponCode = null
|
|
||||||
$scope.code.input = false
|
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -78,7 +78,7 @@
|
|||||||
<div class="clear"><a class="pull-right m-b-sm text-u-l ng-scope m-r-sm" href="#" ng-click="removeMachineSlot(machineSlot, $event)" ng-if="machineSlot.isValid" translate>{{ 'remove_this_slot' }}</a></div>
|
<div class="clear"><a class="pull-right m-b-sm text-u-l ng-scope m-r-sm" href="#" ng-click="removeMachineSlot(machineSlot, $event)" ng-if="machineSlot.isValid" translate>{{ 'remove_this_slot' }}</a></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<coupon show="machineSlotsValid() && (!plansAreShown || selectedPlan)" coupon="coupon.applied" has-select-slot="machineSlotsValid()" user-id="{{ctrl.member.id}}"></coupon>
|
<coupon show="machineSlotsValid() && (!plansAreShown || selectedPlan)" coupon="coupon.applied" user-id="{{ctrl.member.id}}"></coupon>
|
||||||
|
|
||||||
<span ng-hide="fablabWithoutPlans">
|
<span ng-hide="fablabWithoutPlans">
|
||||||
<div ng-if="machineSlotsValid() && !ctrl.member.subscribed_plan" ng-show="!plansAreShown">
|
<div ng-if="machineSlotsValid() && !ctrl.member.subscribed_plan" ng-show="!plansAreShown">
|
||||||
|
@ -82,7 +82,7 @@
|
|||||||
<a class="pull-right m-t-xs text-u-l" href="#" ng-click="removeTraining($event)" ng-if="trainingIsValid" translate>{{ 'remove_this_slot' }}</a>
|
<a class="pull-right m-t-xs text-u-l" href="#" ng-click="removeTraining($event)" ng-if="trainingIsValid" translate>{{ 'remove_this_slot' }}</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<coupon show="trainingIsValid && (!plansIsShow || selectedPlan)" coupon="coupon.applied" has-select-slot="trainingIsValid" user-id="{{ctrl.member.id}}"></coupon>
|
<coupon show="trainingIsValid && (!plansIsShow || selectedPlan)" coupon="coupon.applied" user-id="{{ctrl.member.id}}"></coupon>
|
||||||
|
|
||||||
<span ng-hide="fablabWithoutPlans">
|
<span ng-hide="fablabWithoutPlans">
|
||||||
<div ng-if="trainingIsValid && !ctrl.member.subscribed_plan" ng-show="!plansIsShow">
|
<div ng-if="trainingIsValid && !ctrl.member.subscribed_plan" ng-show="!plansIsShow">
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
class CouponApplyService
|
class CouponApplyService
|
||||||
def call(total, coupon_code)
|
def call(total, coupon_code, user_id = nil)
|
||||||
price = total
|
price = total
|
||||||
|
|
||||||
# if no coupon code or if code does not match, return origin price without change
|
# if no coupon code or if code does not match, return origin price without change
|
||||||
unless coupon_code.nil?
|
unless coupon_code.nil?
|
||||||
_coupon = Coupon.find_by(code: coupon_code)
|
_coupon = Coupon.find_by(code: coupon_code)
|
||||||
if _coupon
|
if not _coupon.nil? and _coupon.status(user_id) == 'active'
|
||||||
if _coupon.type == 'percent_off'
|
if _coupon.type == 'percent_off'
|
||||||
price = price - (price * _coupon.percent_off / 100.0)
|
price = price - (price * _coupon.percent_off / 100.0)
|
||||||
elsif _coupon.type == 'amount_off'
|
elsif _coupon.type == 'amount_off'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user