mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-01 12:24:28 +01:00
check cash coupons does not exceed cart amount for events
This commit is contained in:
parent
04e10c8bb6
commit
ff11694e05
@ -154,6 +154,7 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
|
||||
tickets: {}
|
||||
toReserve: false
|
||||
amountTotal : 0
|
||||
totalNoCoupon: 0
|
||||
totalSeats: 0
|
||||
|
||||
## Discount coupon to apply to the basket, if any
|
||||
@ -400,6 +401,7 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
|
||||
r = mkReservation($scope.ctrl.member, $scope.reserve, $scope.event)
|
||||
Price.compute mkRequestParams(r, $scope.coupon.applied), (res) ->
|
||||
$scope.reserve.amountTotal = res.price
|
||||
$scope.reserve.totalNoCoupon = res.price_without_coupon
|
||||
else
|
||||
$scope.reserve.amountTotal = null
|
||||
|
||||
|
@ -4,7 +4,7 @@ Application.Directives.directive 'coupon', [ 'Coupon', 'growl', '_t', (Coupon, g
|
||||
scope:
|
||||
show: '='
|
||||
coupon: '='
|
||||
total: '@'
|
||||
total: '='
|
||||
userId: '@'
|
||||
templateUrl: '<%= asset_path "shared/_coupon.html" %>'
|
||||
link: ($scope, element, attributes) ->
|
||||
@ -19,6 +19,11 @@ Application.Directives.directive 'coupon', [ 'Coupon', 'growl', '_t', (Coupon, g
|
||||
# Binding for the code inputed (see the attached template)
|
||||
$scope.couponCode = null
|
||||
|
||||
# Re-compute if the code can be applied when the total of the cart changes
|
||||
$scope.$watch 'total', (newValue, oldValue) ->
|
||||
if newValue and newValue != oldValue and $scope.couponCode
|
||||
$scope.validateCode()
|
||||
|
||||
##
|
||||
# Callback to validate the code
|
||||
##
|
||||
|
@ -164,7 +164,7 @@
|
||||
|
||||
<button class="btn btn-warning-full rounded btn-block text-sm" ng-click="reserveEvent()" ng-show="event.nb_free_places > 0 && !reserve.toReserve">{{ 'book' | translate }}</button>
|
||||
|
||||
<coupon show="reserve.totalSeats > 0 && ctrl.member" coupon="coupon.applied" user-id="{{ctrl.member.id}}"></coupon>
|
||||
<coupon show="reserve.totalSeats > 0 && ctrl.member" coupon="coupon.applied" total="reserve.totalNoCoupon" user-id="{{ctrl.member.id}}"></coupon>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -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" total="{{totalNoCoupon}}" user-id="{{ctrl.member.id}}"></coupon>
|
||||
<coupon show="machineSlotsValid() && (!plansAreShown || selectedPlan)" coupon="coupon.applied" total="totalNoCoupon" user-id="{{ctrl.member.id}}"></coupon>
|
||||
|
||||
<span ng-hide="fablabWithoutPlans">
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<coupon show="trainingIsValid && (!plansIsShow || selectedPlan)" coupon="coupon.applied" user-id="{{ctrl.member.id}}" total="{{totalNoCoupon}}"></coupon>
|
||||
<coupon show="trainingIsValid && (!plansIsShow || selectedPlan)" coupon="coupon.applied" user-id="{{ctrl.member.id}}" total="totalNoCoupon"></coupon>
|
||||
|
||||
<span ng-hide="fablabWithoutPlans">
|
||||
<div ng-if="trainingIsValid && !ctrl.member.subscribed_plan" ng-show="!plansIsShow">
|
||||
|
@ -30,7 +30,8 @@ class API::CouponsController < API::ApiController
|
||||
_user_id = params[:user_id]
|
||||
end
|
||||
|
||||
status = @coupon.status(_user_id, params[:amount])
|
||||
amount = params[:amount].to_f * 100.0
|
||||
status = @coupon.status(_user_id, amount)
|
||||
if status != 'active'
|
||||
render json: {status: status}, status: :unprocessable_entity
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user