1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00

real fix for coupon change slot's original price (reverts cfd92cdc40)

This commit is contained in:
Sylvain 2016-11-24 11:33:45 +01:00
parent 9721872b2a
commit 3dc5f1a0e4
5 changed files with 5 additions and 12 deletions

View File

@ -426,7 +426,6 @@ Application.Controllers.controller "ReserveTrainingController", ["$scope", "$sta
if $scope.ctrl.member
# 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
$scope.coupon.applied = null
if event != $scope.selectedTraining
$scope.selectedTraining = event
$scope.selectedTraining.offered = false
@ -647,7 +646,7 @@ Application.Controllers.controller "ReserveTrainingController", ["$scope", "$sta
# first we check that a user was selected
if Object.keys($scope.ctrl.member).length > 0
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
else
$scope.selectedTrainingAmount = null

View File

@ -5,7 +5,6 @@ Application.Directives.directive 'coupon', [ 'Coupon', 'growl', '_t', (Coupon, g
show: '='
coupon: '='
userId: '@'
hasSelectSlot: '='
templateUrl: '<%= asset_path "shared/_coupon.html" %>'
link: ($scope, element, attributes) ->
@ -19,11 +18,6 @@ Application.Directives.directive 'coupon', [ 'Coupon', 'growl', '_t', (Coupon, g
# Binding for the code inputed
$scope.couponCode = null
$scope.$watch 'hasSelectSlot', (newValue) ->
unless newValue
$scope.coupon = null
$scope.couponCode = null
$scope.code.input = false
##

View File

@ -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>
<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">
<div ng-if="machineSlotsValid() && !ctrl.member.subscribed_plan" ng-show="!plansAreShown">

View File

@ -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>
</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">
<div ng-if="trainingIsValid && !ctrl.member.subscribed_plan" ng-show="!plansIsShow">

View File

@ -1,11 +1,11 @@
class CouponApplyService
def call(total, coupon_code)
def call(total, coupon_code, user_id = nil)
price = total
# if no coupon code or if code does not match, return origin price without change
unless coupon_code.nil?
_coupon = Coupon.find_by(code: coupon_code)
if _coupon
if not _coupon.nil? and _coupon.status(user_id) == 'active'
if _coupon.type == 'percent_off'
price = price - (price * _coupon.percent_off / 100.0)
elsif _coupon.type == 'amount_off'