1(function () { 2 'use strict'; 3 4 angular 5 .module('app.cart') 6 .controller('CartCheckoutController', CartCheckoutController); 7 8 CartCheckoutController.$inject = [ 9 '$state', 10 'bookModels', 'cartDataService', 'accountDataService', 11 'common', 'moment', 'toastr' 12 ]; 13 14 function CartCheckoutController($state, bookModels, cartDataService, accountDataService, common, moment, toastr) { 15 var vm = this; 16 17 vm.isFinalizing = false; 18 19 var leadTraveller = common.storage.get('checkout-lead-traveller'); 20 21 vm.travellerFirstName = leadTraveller ? leadTraveller.firstName : null; 22 vm.travellerLastName = leadTraveller ? leadTraveller.lastName : null; 23 24 vm.chargeTypes = []; 25 26 vm.payment = new bookModels.Payment(); 27 28 vm.relationship = null; 29 30 vm.acceptTerms = false; 31 32 vm.accountIsAgent = false; 33 34 vm.payByCheck = false; 35 36 vm.items = []; 37 vm.itemsPrice = null; 38 39 vm.couponCodeToApply = null; 40 vm.couponCodeInProgress = false; 41 vm.appliedCouponName = null; 42 vm.couponAmount = 0; 43 vm.discountAmount = 0; 44 45 vm.feeToApply = null; 46 vm.feeInProgress = false; 47 vm.feeAmount = 0; 48 vm.totalTax = 0; 49 vm.commissionAmount = 0; 50 vm.totalPrice = 0; 51 52 vm.applyCoupon = applyCoupon; 53 vm.removeCoupon = removeCoupon; 54 vm.applyFee = applyFee; 55 vm.removeFee = removeFee; 56 vm.finalize = finalize; 57 58 vm.bindFirstName = bindFirstName; 59 vm.bindLastName = bindLastName; 60 61 activate();
62 ////////////// 63 64 65 function activate() { 66 getCheckoutCart(); 67 68 if (leadTraveller) { 69 bindFirstName(); 70 bindLastName(); 71 } 72 } 73 74 function getCheckoutCart() { 75 76 return cartDataService.getCart('checkout') 77 .then(success); 78 79 function success(data) { 80 //accountDataService.getAccountStorred() 81 // .then(function (accData) { 82 83 // vm.travellerFirstName = accData.firstName; 84 // vm.travellerLastName = accData.lastName; 85 // vm.payment.firstName = accData.firstName; 86 // vm.payment.lastName = accData.lastName; 87 88 // }); 89 90 vm.chargeTypes = data.chargeTypes; 91 vm.payment.chargeTypeCode = data.chargeTypes[0].code; 92 93 vm.cartItems = data.items; 94 vm.itemsPrice = data.itemsPrice; 95 vm.appliedCouponName = data.couponName; 96 vm.couponAmount = data.couponAmount; 97 vm.discountAmount = data.discountAmount; 98 vm.feeAmount = data.feeAmount; 99 vm.commissionAmount = data.commissionAmount.toFixed(2); 100 vm.totalTax = data.totalTax; 101 vm.totalPrice = data.totalPrice; 102 vm.payByCheck = vm.chargeTypes.filter(function (e) { return e.id === 4; }).length > 0; 103 return data; 104 } 105 } 106 107 function calc(theform) { 108 var num = theform.original.value, rounded = theform.rounded 109 var with2Decimals = num.toString().match(/^-?\d+(?:\.\d{0,2})?/)[0] 110 rounded.value = with2Decimals 111 } 112 113 function applyCoupon() { 114 115 vm.couponCodeInProgress = true; 116 117 return cartDataService.applyCoupon(vm.couponCodeToApply) 118 .then(success) 119 .catch(error); 120 121 function success(data) { 122 123 vm.couponCodeInProgress = false; 124 vm.couponCodeToApply = null; 125 vm.appliedCouponName = data.couponName; 126 127 vm.couponAmount = data.couponAmount; 128 vm.discountAmount = data.discountAmount; 129 vm.commissionAmount = data.commissionAmount.toFixed(2);; 130 vm.totalPrice = data.totalPrice; 131 132 return data; 133 } 134 135 function error() { 136 137 vm.couponCodeInProgress = false; 138 vm.couponCodeToApply = null; 139 } 140 } 141 142 function removeCoupon() { 143 144 vm.couponCodeInProgress = true; 145 146 return cartDataService.removeCoupon() 147 .then(success); 148 149 function success(data) { 150 vm.couponCodeInProgress = false; 151 vm.appliedCouponName = null; 152 vm.couponAmount = 0; 153 vm.discountAmount = 0; 154 vm.commissionAmount = data.commissionAmount.toFixed(2);; 155 vm.totalPrice = data.totalPrice; 156 } 157 158 } 159 160 function applyFee() { 161 162 vm.feeIsAppling = true; 163 164 return cartDataService.applyFee(vm.feeToApply) 165 .then(success); 166 167 function success(data) { 168 169 vm.feeIsAppling = false; 170 vm.feeToApply = null; 171 172 vm.feeAmount = data.feeAmount; 173 vm.commissionAmount = data.commissionAmount.toFixed(2); 174 vm.totalPrice = data.totalPrice; 175 } 176 } 177 178 function removeFee() { 179 180 vm.feeIsAppling = true; 181 182 return cartDataService.removeFee() 183 .then(success); 184 185 function success(data) { 186 vm.feeIsAppling = false; 187 vm.feeAmount = 0; 188 vm.commissionAmount = data.commissionAmount.toFixed(2);; 189 vm.totalPrice = data.totalPrice; 190 } 191 192 } 193 194 function finalize() { 195 196 var params = { 197 travellerFirstName: vm.travellerFirstName, 198 travellerLastName: vm.travellerLastName, 199 relationship: vm.relationship, 200 payment: vm.payment 201 }; 202 203 //return; 204 vm.isFinalizing = true; 205 206 return cartDataService.finalize(params) 207 .then(success) 208 .catch(function () { 209 210 vm.isFinalizing = false; 211 }); 212 213 function success(invoiceId) { 214 215 var cartHasTrains = false; 216 for (var i = 0; i < vm.cartItems.length; i++) { 217 if (vm.cartItems[i].itemType == 'train' || vm.cartItems[i].itemType == 'train-pass') { 218 cartHasTrains = true; 219 break; 220 } 221 } 222 223 //if (cartHasTrains) { 224 // gtag('event', 'conversion', { 'send_to': 'AW-947109011/yryBCOuY0FwQk_nOwwM' }); 225 //} 226 227 $state.go('invoices.main', { invoiceId: invoiceId }); 228 } 229 } 230 231 function bindFirstName() { 232 vm.payment.firstName = vm.travellerFirstName; 233 } 234 235 function bindLastName() { 236 vm.payment.lastName = vm.travellerLastName; 237 } 238 239 240 241 242 } 243 244}());
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.