Advertisement
Guest User

Untitled

a guest
Nov 9th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 237.27 KB | None | 0 0
  1. 'use strict';
  2. angular.module('ngCart', ['ngCart.directives'])
  3. .config([
  4. function () {
  5.  
  6. }
  7. ])
  8. .provider('$ngCart', function () {
  9. this.$get = function () {
  10. };
  11. })
  12.  
  13. .run(['$rootScope', 'ngCart', 'ngCartItem', 'store', function ($rootScope, ngCart, ngCartItem, store) {
  14.  
  15. $rootScope.$on('ngCart:change', function () {
  16. //debugger
  17. ngCart.$save();
  18. });
  19.  
  20. if (angular.isObject(store.get('cart'))) {
  21. ngCart.$restore(store.get('cart'));
  22.  
  23. } else {
  24. ngCart.init();
  25. }
  26. }
  27. ])
  28. .config(['$httpProvider', function ($httpProvider) {
  29.  
  30. $httpProvider.interceptors.push('myHttpInterceptor');
  31.  
  32. }]).factory('myHttpInterceptor', ['$q', '$rootScope', function ($q, $rootScope) {
  33. var numRequests = 0;
  34. //var ajaxSpinner = $("#ajaxSpinner");
  35. var hide = function (r) {
  36. if (!--numRequests) {
  37. // ajaxSpinner.hide();
  38. $rootScope.disableBtn = true;
  39. }
  40. return r
  41. };
  42.  
  43. return {
  44. 'request': function (config) {
  45. numRequests++;
  46. // ajaxSpinner.show();
  47. $rootScope.disableBtn = false;
  48.  
  49. return config;
  50. },
  51.  
  52. 'response': function (response) {
  53. return hide(response);
  54. },
  55.  
  56. 'responseError': function (response) {
  57. return $q.reject(hide(response));
  58. }
  59. };
  60. }])
  61. .service('ngCart', [
  62. '$rootScope', 'ngCartItem', 'store', 'ngCart.lottoyard.api', 'Products', 'RaffleExpiresInMin', function ($rootScope, ngCartItem, store, LottoYardService, Products, RaffleExpiresInMin) {
  63.  
  64. this.init = function () {
  65. this.$cart = {
  66. shipping: 0,
  67. taxRate: 0,
  68. tax: 0,
  69. paymentMethodId: "",
  70. processor: "",
  71. fastProcessingTax: 0,
  72. amountToPay: 0,
  73. reedemCode: "",
  74. isFastProcessing: false,
  75. phoneOrEmail: "",
  76. iframePaymentMethods: [],
  77. currency: "",
  78. items: [],
  79. bonusAmountToUse: 0,
  80. useBonusmoney: false,
  81. evenLinesOnlyMessage: false
  82. };
  83. };
  84.  
  85. this.addItem = function (id, discount, groupComboBoxSelectionIndex, groupSettingsIndex, groupdiscount, groupnodraws, groupnoshares, grouporiginalprice,
  86. grouptotal, lotteryType, noofdraws, nooflines, numbers, originalprice, personalComboBoxSelectionIndex, personalSettingsIndex, selectedTab, totalCost,
  87. isSubscription, isQuickPick, ticketsNumbers, productType, productExpire, productIdSpecial, quantity, guid, isRaffle, olapCounterGuid, evenNumbersOnly) {
  88. var inCart = this.getItemById(id);
  89. if (typeof inCart === 'object') {
  90. //Update quantity of an item if it's already in the cart
  91. inCart.setQuantity(quantity, false);
  92. } else {
  93. if (this.$cart.items.length === 10) {
  94. //todo remove first element
  95. this.$cart.items.shift();
  96. }
  97.  
  98. discount = parseFloat(discount.toFixed(3));
  99. groupnodraws = parseInt(groupnodraws);
  100. groupnoshares = parseInt(groupnoshares);
  101.  
  102. if (selectedTab === 'single' && (typeof (productType) === 'undefined' || productType === "")) {
  103. productType = 1;
  104. groupSettingsIndex = undefined;
  105. } else if (selectedTab === 'groupselection' || selectedTab === "group") {
  106. productType = 3;
  107. personalSettingsIndex = undefined;
  108. }
  109.  
  110. if (productType === 3) {
  111. numbers = undefined;
  112. }
  113.  
  114. if (selectedTab === 'product' && productType === 3) {
  115. groupnoshares = groupnoshares === 0 ? 1 : groupnoshares;
  116. }
  117.  
  118. if (this.getIsFastProcessing()) {
  119. var isFastProcessing = true;
  120. totalCost = parseFloat(totalCost) + this.getFastProcessingTax();
  121. }
  122.  
  123. if (personalSettingsIndex === 2 || groupSettingsIndex === 2) {
  124. isSubscription = true;
  125. } else {
  126. isSubscription = false;
  127. }
  128.  
  129. quantity = quantity > 0 ? quantity : 1;
  130. var rules;
  131. if (productType === 2 || productType === 4 || productType === 14 || productType === 19) {
  132. //14 and 19
  133. var product = LottoYardService.getProductById(productType);
  134. var productName = product.ProductName;
  135. var productRules = product.ValidLotteries.filter(function (obj) {
  136. if ('LotteryTypeId' in obj && typeof (obj.LotteryTypeId) === 'number' && obj.LotteryTypeId === lotteryType) {
  137. return true;
  138. }
  139. return false;
  140. })[0];
  141.  
  142. if (productType === 2 || productType === 4 || productType === 19) {
  143. if (quantity > 1) {
  144. totalCost = quantity * totalCost;
  145. }
  146. }
  147. if (productType === 2) {
  148. productName = LottoYardService.getLotteryById(lotteryType).LotteryType;
  149. }
  150. if (productType === 14 || productType === 19) {
  151. nooflines = 1;
  152. }
  153. if (productType === 19) {
  154. productName = "247Premium";
  155. }
  156. if (lotteryType === 7) {
  157. rules = {
  158. SelectNumbers: 0,
  159. MinSelectNumber: 0,
  160. MaxSelectNumbers: 0,
  161. ExtraNumbers: 0,
  162. MaxExtraNumbers: 0,
  163. MinExtraNumber: 0,
  164. DrawsPerWeek: 0
  165. };
  166. } else {
  167. rules = LottoYardService.getLotteryById(lotteryType);
  168. }
  169.  
  170. if (productType === 2 || productType === 4) {
  171.  
  172. nooflines = productRules.MinLines;
  173.  
  174. for (var i = 0; i < productRules.MinLines; i++) {
  175. if (i === productRules.MinLines - 1) {
  176. numbers += quickpick(rules);
  177. } else {
  178. numbers += quickpick(rules) + "|";
  179. }
  180. }
  181. }
  182.  
  183. var newItem = new ngCartItem(id, discount, groupComboBoxSelectionIndex, groupSettingsIndex, groupdiscount, groupnodraws, groupnoshares, grouporiginalprice,
  184. grouptotal, lotteryType, noofdraws, nooflines, numbers, originalprice, personalComboBoxSelectionIndex, personalSettingsIndex, selectedTab, totalCost, productName,
  185. rules.SelectNumbers, rules.MinSelectNumber, rules.MaxSelectNumbers, rules.ExtraNumbers, rules.MaxExtraNumbers, rules.MinExtraNumber, productRules.MinLines,
  186. productRules.MaxLines, rules.DrawsPerWeek, product.Draws, isFastProcessing, isSubscription, isQuickPick, ticketsNumbers, productType, productExpire, productIdSpecial, quantity, guid,
  187. isRaffle, olapCounterGuid);
  188.  
  189. } else {
  190. var lotteryname = LottoYardService.getLotteryById(lotteryType).LotteryType;
  191.  
  192. var rules = LottoYardService.getLotteryById(lotteryType);
  193.  
  194. if (selectedTab === 'product' || productType === 3) {
  195.  
  196. groupdiscount = 0;
  197.  
  198. angular.forEach(rules.ProductsDrawOptions, function (item) {
  199. if (item.ProductId === productType && item.IsSubscription === isSubscription) {
  200. angular.forEach(item.MultiDrawOptions, function (drawOpt) {
  201. if (drawOpt.NumberOfDraws === parseInt(groupnodraws)) {
  202. groupdiscount = drawOpt.Discount;
  203. }
  204. });
  205. }
  206. });
  207. }
  208.  
  209. if (productType === 1) {
  210. // debugger;
  211. originalprice = LottoYardService.getProductPriceByIds(productType, 1, lotteryType, 1).Price;
  212. noofdraws = parseInt(noofdraws);
  213. discount = 0;
  214. }
  215.  
  216. //getting MinLines and MaxLines accoring draws
  217.  
  218. //rules.ProductsDrawOptions - productId & IsSubscription
  219. // if (productType === 15 || productType === 24 || productType === 26 || productType === 31 || productType ===33) {
  220. if (typeof (ticketsNumbers) !== 'undefined' && ticketsNumbers.length > 0) {
  221. rules.MinLines = 1;
  222. rules.MaxLines = ticketsNumbers.length;
  223. isRaffle = true;
  224. } else {
  225. numbers = numbers ? linesChecker(numbers) : numbers;
  226. angular.forEach(rules.ProductsDrawOptions, function (item) {
  227. if (item.ProductId === productType && item.IsSubscription === isSubscription) {
  228. angular.forEach(item.MultiDrawOptions, function (drawOpt) {
  229. if (drawOpt.NumberOfDraws === parseInt(noofdraws)) {
  230. discount = drawOpt.Discount;
  231. rules.MinLines = drawOpt.MinLines;
  232. rules.MaxLines = drawOpt.MaxLines;
  233. }
  234. });
  235. }
  236. });
  237. if (productType === 1) {
  238. for (var j = nooflines; j < rules.MinLines; j++) {
  239. numbers += "|" + quickpick(rules);
  240. nooflines++;
  241. }
  242. totalCost = LottoYardService.getProductPriceByIds(productType, noofdraws, lotteryType, nooflines).Price;
  243. }
  244. }
  245.  
  246. var newItem = new ngCartItem(id, discount, groupComboBoxSelectionIndex, groupSettingsIndex, groupdiscount, groupnodraws, groupnoshares, grouporiginalprice,
  247. grouptotal, lotteryType, noofdraws, nooflines, numbers, originalprice, personalComboBoxSelectionIndex, personalSettingsIndex, selectedTab, totalCost, lotteryname,
  248. rules.SelectNumbers, rules.MinSelectNumber, rules.MaxSelectNumbers, rules.ExtraNumbers, rules.MaxExtraNumbers, rules.MinExtraNumber, rules.MinLines, rules.MaxLines, rules.DrawsPerWeek,
  249. rules.ProductsDrawOptions, isFastProcessing, isSubscription, isQuickPick, ticketsNumbers, productType, productExpire, productIdSpecial, quantity, guid, isRaffle, olapCounterGuid, evenNumbersOnly);
  250. }
  251.  
  252. if (newItem.getEvenLinesOnly() && newItem.getNumberOfLines() % 2 == 1) {
  253. sessionStorage.setItem('showEvenLinesOnly', true);
  254. $rootScope.$broadcast('ngCart:change', {});
  255. return;
  256. }
  257.  
  258. var items = this.$cart.items;
  259. var isAddedItem = false;
  260.  
  261. if (productType != 1 && productType != 3) {
  262. items.forEach(function (item) {
  263. if (item.getNumbers() && item.getNumbers() == newItem.getNumbers()) {
  264. isAddedItem = true;
  265. }
  266. })
  267. }
  268.  
  269. if (!isAddedItem) {
  270. this.$cart.items.push(newItem);
  271. }
  272.  
  273. $rootScope.$broadcast('ngCart:itemAdded', newItem);
  274. }
  275.  
  276. $rootScope.$broadcast('ngCart:change', {});
  277.  
  278. };
  279.  
  280.  
  281. this.addItemPredifined = function (productId, lotteryType, lines, draws, amount, guid, selectedNumbers, counterGuid) {
  282. // debugger;
  283. if (this.$cart.items.length === 10) {
  284. this.$cart.items.shift();
  285. }
  286. if (!isNumeric(productId)) {
  287. productId = parseInt(productId);
  288. }
  289.  
  290. if (!isNumeric(lotteryType)) {
  291. lotteryType = parseInt(lotteryType);
  292. }
  293.  
  294. if (!isNumeric(lines)) {
  295. lines = parseInt(lines);
  296. }
  297.  
  298. if (!isNumeric(draws)) {
  299. draws = parseInt(draws);
  300. }
  301.  
  302. if (!isNumeric(amount)) {
  303. amount = parseInt(amount);
  304. }
  305.  
  306. //generating id
  307. var productIdSpecial = 999;
  308. var product = LottoYardService.getProductById(productId);
  309. var productName,
  310. selectedTab,
  311. noofdraws,
  312. nooflines,
  313. rules,
  314. personalComboBoxSelectionIndex,
  315. personalSettingsIndex,
  316. isSubscription,
  317. isFastProcessing,
  318. isQuickPick,
  319. productExpire,
  320. ticketsNumbers,
  321. quanity;
  322.  
  323. var numbers = "";
  324. var quantity = 1;
  325. var isRaffle = false;
  326. productIdSpecial = 999;
  327. guid = guid;
  328.  
  329. if (typeof (product) === 'undefined') {
  330. productName = LottoYardService.getLotteryById(lotteryType).LotteryType;
  331. } else {
  332. productName = product.ProductName;
  333. selectedTab = 'product';
  334. }
  335.  
  336. if (productId === 3) {
  337. selectedTab = 'group';
  338. } else if (productId === 1) {
  339. selectedTab = 'personal';
  340. nooflines = parseInt(lines);
  341. } else if (draws === 0) {
  342. selectedTab = 'raffle';
  343. }
  344.  
  345. noofdraws = parseInt(draws);
  346.  
  347. var discount = 0,
  348. groupComboBoxSelectionIndex = 0,
  349. groupSettingsIndex = 0,
  350. groupdiscount = 0,
  351. groupnodraws = 0,
  352. groupnoshares = 0,
  353. grouporiginalprice = 0,
  354. grouptotal = 0;
  355.  
  356. var productType = productId;
  357. var originalprice = amount;
  358. var totalCost = amount;
  359.  
  360. rules = {
  361. SelectNumbers: 0,
  362. MinSelectNumber: 0,
  363. MaxSelectNumbers: 0,
  364. ExtraNumbers: 0,
  365. MaxExtraNumbers: 0,
  366. MinExtraNumber: 0,
  367. DrawsPerWeek: 0
  368. };
  369.  
  370. switch (selectedTab) {
  371. case 'personal':
  372. if (typeof selectedNumbers !== 'undefined') {
  373. numbers = linesChecker(selectedNumbers);
  374. } else {
  375. //get lottery rules for genereting lines
  376. rules = LottoYardService.getLotteryById(lotteryType);
  377. var minLines = rules.MinLines;
  378. var maxLines = rules.MaxLines;
  379.  
  380. if (nooflines > maxLines || minLines > nooflines) {
  381. throw "Lines can not be greater than max lines or less then defined in rules";
  382. }
  383. for (var i = 0; i < nooflines; i++) {
  384. if (i === nooflines - 1) {
  385. numbers += quickpick(rules);
  386. } else {
  387. numbers += quickpick(rules) + "|";
  388. }
  389. }
  390. }
  391.  
  392. break;
  393. case 'group':
  394. groupnodraws = draws;
  395. groupnoshares = lines;
  396. break;
  397. case 'raffle':
  398. isRaffle = true;
  399. LottoYardService.getRaffleTicket(productId).then(
  400. angular.bind(this, function (resp) {
  401. console.log(resp);
  402.  
  403. //if response is array else throw error
  404. if (!Array.isArray(resp)) {
  405. throw ("OLA: raffle response is not array!: error:" + resp);
  406. }
  407. var ticket = resp[0];
  408. numbers = ticket.Number + "-" + ticket.Seat + "-" + ticket.Ticket;
  409. ticketsNumbers = [ticket.Id];
  410.  
  411. var productExpire = [];
  412. var obj = {};
  413. var navidadExpiration = new Date();
  414. navidadExpiration.setMinutes(navidadExpiration.getMinutes() + RaffleExpiresInMin);
  415. obj.id = ticket.Id;
  416. obj.exp = navidadExpiration;
  417. productExpire.push(obj);
  418.  
  419. nooflines = shares;
  420.  
  421. var newItem = new ngCartItem(0, discount, groupComboBoxSelectionIndex, groupSettingsIndex, groupdiscount, groupnodraws, groupnoshares, grouporiginalprice,
  422. grouptotal, lotteryType, noofdraws, nooflines, numbers, originalprice, personalComboBoxSelectionIndex, personalSettingsIndex, selectedTab, totalCost, productName,
  423. rules.SelectNumbers, rules.MinSelectNumber, rules.MaxSelectNumbers, rules.ExtraNumbers, rules.MaxExtraNumbers, rules.MinExtraNumber, productRules.MinLines, productRules.MaxLines,
  424. rules.DrawsPerWeek, noofdraws, isFastProcessing, isSubscription, isQuickPick, ticketsNumbers, productType, productExpire, productIdSpecial, quantity, guid, isRaffle, counterGuid);
  425.  
  426. this.$cart.items.push(newItem);
  427.  
  428. $rootScope.$broadcast('ngCart:itemAdded', newItem);
  429.  
  430. $rootScope.$broadcast('ngCart:change', {});
  431.  
  432. }));
  433. return;
  434. case "product":
  435. switch (productType) {
  436. case 4:
  437. quanity = 1;
  438. noofdraws = draws;
  439. nooflines = 1;
  440. numbers = linesChecker(selectedNumbers);
  441. break;
  442.  
  443. case 14:
  444. quanity = 1;
  445. noofdraws = draws;
  446.  
  447. break;
  448.  
  449. default:
  450. }
  451.  
  452. break;
  453. default:
  454. }
  455.  
  456. var newItem = new ngCartItem(0, discount, groupComboBoxSelectionIndex, groupSettingsIndex, groupdiscount, groupnodraws, groupnoshares, grouporiginalprice,
  457. grouptotal, lotteryType, noofdraws, nooflines, numbers, originalprice, personalComboBoxSelectionIndex, personalSettingsIndex, selectedTab, totalCost, productName,
  458. rules.SelectNumbers, rules.MinSelectNumber, rules.MaxSelectNumbers, rules.ExtraNumbers, rules.MaxExtraNumbers, rules.MinExtraNumber, rules.MinLines, rules.MaxLines,
  459. rules.DrawsPerWeek, noofdraws, isFastProcessing, isSubscription, isQuickPick, ticketsNumbers, productType, productExpire, productIdSpecial, quantity, guid, isRaffle, counterGuid);
  460.  
  461. this.$cart.items.push(newItem);
  462.  
  463. $rootScope.$broadcast('ngCart:itemAdded', newItem);
  464.  
  465. $rootScope.$broadcast('ngCart:change', {});
  466. }
  467.  
  468. function quickpick(rules) {
  469. // debugger;
  470. var generatedNumbers = [];
  471. var generatedExtraNumbers = [];
  472. var line = "";
  473.  
  474. var maxSelectExtraNumbers = rules.MaxExtraNumbers; // kolko extra number to generate
  475.  
  476. var startNumber = rules.MinSelectNumber; //otkolko da startirame chislata
  477. var endNumber = rules.SelectNumbers;
  478.  
  479. var maxSelectNumbers = rules.MaxSelectNumbers; //kolko chisla da se generirat
  480.  
  481. var startExtraNumber = rules.MinExtraNumber;
  482. var endExtraNumbers = rules.ExtraNumbers;
  483.  
  484. while (generatedNumbers.length < maxSelectNumbers) {
  485. var number = getRandomInt(startNumber, endNumber);
  486. if (generatedNumbers.indexOf(number) === -1) {
  487. generatedNumbers.push(number);
  488. console.log(number);
  489. }
  490. }
  491. line += generatedNumbers.join(',');
  492.  
  493. if (maxSelectExtraNumbers > 0) {
  494. while (generatedExtraNumbers.length < maxSelectExtraNumbers) {
  495. var number = getRandomInt(startExtraNumber, endExtraNumbers);
  496. if (generatedExtraNumbers.indexOf(number) === -1) {
  497. generatedExtraNumbers.push(number);
  498. console.log(number);
  499. }
  500. }
  501.  
  502. line += '#' + generatedExtraNumbers.join(',');
  503. }
  504. return line;
  505.  
  506. function getRandomInt(min, max) {
  507. return Math.floor(Math.random() * (max - min + 1)) + min;
  508. };
  509. };
  510.  
  511. function isNumeric(n) {
  512. return !isNaN(parseFloat(n)) && isFinite(n);
  513. };
  514.  
  515. function linesChecker(numbers) {
  516. var numberSeperator = ',';
  517. var linesSeperator = '|';
  518. var specialNumberSeperator = "#";
  519.  
  520. var arrLength = numbers.length;
  521.  
  522. var numbersSanitized = "";
  523. var currentNumbersInline = 1;
  524.  
  525. for (var i = 0; i < arrLength; i++) {
  526. var currentElement = numbers[i];
  527. var nextElement = numbers[i + 1];
  528.  
  529. if (i === 0) {
  530. if (isNumeric(currentElement)) {
  531. numbersSanitized += currentElement;
  532. currentNumbersInline++;
  533. continue;
  534. } else {
  535. continue;
  536. }
  537. }
  538.  
  539. if (isNumeric(currentElement)) {
  540. numbersSanitized += currentElement;
  541. currentNumbersInline++;
  542. continue;
  543. }
  544.  
  545. if (currentElement === numberSeperator || currentElement === linesSeperator || currentElement === specialNumberSeperator) {
  546. if (typeof nextElement !== 'undefined') {
  547. if (isNumeric(nextElement)) {
  548. numbersSanitized += currentElement;
  549. continue;
  550. }
  551. }
  552. }
  553. }
  554.  
  555. function isNumeric(n) {
  556. return !isNaN(parseFloat(n)) && isFinite(n);
  557. };
  558. console.log(numbersSanitized);
  559. return numbersSanitized;
  560.  
  561. }
  562.  
  563. this.getItemById = function (itemId) {
  564. var items = this.getCart().items;
  565. var build = false;
  566.  
  567. angular.forEach(items, function (item) {
  568. if (item.getId() === itemId) {
  569. build = item;
  570. }
  571. });
  572. return build;
  573. };
  574.  
  575. this.setShipping = function (shipping) {
  576. this.$cart.shipping = shipping;
  577. return this.getShipping();
  578. };
  579.  
  580. this.getShipping = function () {
  581. if (this.getCart().items.length === 0) return 0;
  582. return this.getCart().shipping;
  583. };
  584.  
  585. this.setTaxRate = function (taxRate) {
  586. this.$cart.taxRate = +parseFloat(taxRate).toFixed(2);
  587. return this.getTaxRate();
  588. };
  589.  
  590. this.getTaxRate = function () {
  591. return this.getCart().taxRate;
  592. };
  593.  
  594. this.getTax = function () {
  595. return +parseFloat(((this.getSubTotal() / 100) * this.getCart().taxRate)).toFixed(2);
  596. };
  597.  
  598. this.setCart = function (cart) {
  599. this.$cart = cart;
  600. return this.getCart();
  601. };
  602.  
  603. this.getCart = function () {
  604. return this.$cart;
  605. };
  606.  
  607. this.getItems = function () {
  608. return this.getCart().items;
  609. };
  610.  
  611. this.setItems = function (items) {
  612. this.$cart.items = items;
  613. };
  614.  
  615. this.getTopNItems = function (n) {
  616. return this.getCart().items.slice(0, n);
  617. };
  618.  
  619. this.getTotalItems = function () {
  620. var count = 0;
  621. var items = this.getItems();
  622. angular.forEach(items, function (item) {
  623. count += item.getQuantity();
  624. });
  625. return count;
  626. };
  627.  
  628. this.getTotalUniqueItems = function () {
  629. return this.getCart().items.length;
  630. };
  631.  
  632. this.getSubTotal = function () {
  633. var total = 0;
  634. angular.forEach(this.getCart().items, function (item) {
  635. total += item.getTotal();
  636. });
  637. return +parseFloat(total).toFixed(2);
  638. };
  639.  
  640. this.totalCost = function () {
  641. return +parseFloat(this.getSubTotal() + this.getShipping() + this.getTax()).toFixed(2);
  642. };
  643.  
  644. this.setAmountToPay = function (price) {
  645. this.$cart.amountToPay = price;
  646. };
  647.  
  648. this.getAmountToPay = function () {
  649. if (this.$cart.amountToPay >= 0) {
  650. return this.$cart.amountToPay;
  651. }
  652. return this.totalCost();
  653. };
  654.  
  655. this.removeItem = function (index) {
  656. this.$cart.items.splice(index, 1);
  657. $rootScope.$broadcast('ngCart:itemRemoved', {});
  658. $rootScope.$broadcast('ngCart:change', {});
  659.  
  660. };
  661.  
  662. this.removeItemById = function (id) {
  663. var cart = this.getCart();
  664. angular.forEach(cart.items, function (item, index) {
  665. if (item.getId() === id) {
  666. cart.items.splice(index, 1);
  667. }
  668. });
  669. this.setCart(cart);
  670. $rootScope.$broadcast('ngCart:itemRemoved', {});
  671. $rootScope.$broadcast('ngCart:change', {});
  672. };
  673.  
  674. this.empty = function () {
  675. $rootScope.$broadcast('ngCart:change', {});
  676. this.$cart.items = [];
  677. store.emptyCart();
  678. };
  679.  
  680. this.isEmpty = function () {
  681. return (this.$cart.items.length > 0 ? false : true);
  682. };
  683.  
  684. this.setIframePaymentMethods = function (iframePaymentMethods) {
  685. this.$cart.iframePaymentMethods = iframePaymentMethods;
  686. return this.getIframePaymentMethods();
  687. };
  688.  
  689. this.getIframePaymentMethods = function () {
  690. return this.$cart.iframePaymentMethods;
  691. };
  692.  
  693. this.setPaymentMethodId = function (paymentMethodId) {
  694. this.$cart.paymentMethodId = paymentMethodId;
  695. return this.getPaymentMethodId();
  696. };
  697.  
  698. this.getPhoneOrEmail = function () {
  699. return this.$cart.phoneOrEmail;
  700. };
  701.  
  702. this.setPhoneOrEmail = function (phoneOrEmail) {
  703. this.$cart.phoneOrEmail = phoneOrEmail;
  704. };
  705.  
  706. this.getPaymentMethodId = function () {
  707. return this.$cart.paymentMethodId;
  708. };
  709.  
  710. this.setProcessor = function (processor) {
  711. this.$cart.processor = processor;
  712. };
  713.  
  714. this.getProcessor = function () {
  715. return this.$cart.processor;
  716. };
  717.  
  718. this.setReedemCode = function (reedem) {
  719. //debugger
  720. this.$cart.reedemCode = reedem;
  721. return this.getReedemCode();
  722. };
  723.  
  724. this.getReedemCode = function () {
  725. return this.$cart.reedemCode;
  726. };
  727.  
  728. this.setReedemBonusAmount = function (reedemBonusAmount) {
  729. this.$cart.reedemBonusAmount = reedemBonusAmount;
  730. return this.getReedemBonusAmount();
  731. };
  732.  
  733. this.getReedemBonusAmount = function () {
  734. if (this.$cart.reedemBonusAmount < 0) {
  735. return 0;
  736. } else {
  737. return this.$cart.reedemBonusAmount;
  738. }
  739.  
  740. };
  741.  
  742. this.setAffiliateCode = function (aff) {
  743. this.$cart.affiliateCode = aff;
  744. return this.getAffiliateCode();
  745. };
  746.  
  747. this.getAffiliateCode = function () {
  748. return this.$cart.affiliateCode;
  749. };
  750.  
  751. this.setOlapAffiliateCode = function (aff) {
  752. this.$cart.olapAffiliateCode = aff;
  753. return this.getOlapAffiliateCode();
  754. };
  755.  
  756. this.getOlapAffiliateCode = function () {
  757. return this.$cart.olapAffiliateCode;
  758. };
  759.  
  760. this.setIsFastProcessing = function (isFastProcessing) {
  761. this.$cart.isFastProcessing = isFastProcessing;
  762. return this.getIsFastProcessing();
  763. };
  764.  
  765. this.getIsFastProcessing = function () {
  766. return this.$cart.isFastProcessing;
  767. };
  768.  
  769. this.setFastProcessingTax = function (fastProcessingTax) {
  770. this.$cart.fastProcessingTax = fastProcessingTax;
  771. return this.getFastProcessingTax();
  772. };
  773.  
  774. this.getFastProcessingTax = function () {
  775. return this.$cart.fastProcessingTax;
  776. };
  777.  
  778. this.setCurrency = function (currency) {
  779. this.$cart.currency = currency;
  780. return this.getCurrency();
  781. };
  782.  
  783. this.getCurrency = function () {
  784. return this.$cart.currency;
  785. };
  786.  
  787. this.getBonusAmountToUse = function () {
  788. return this.$cart.bonusAmountToUse;
  789. }
  790.  
  791. this.setBonusAmountToUse = function (bonusAmountToUse) {
  792. this.$cart.bonusAmountToUse = bonusAmountToUse;
  793. }
  794.  
  795. this.getUseBonusmoney = function () {
  796. return this.$cart.useBonusmoney;
  797. }
  798.  
  799. this.setUseBonusmoney = function (isUsingBonusmoney) {
  800. this.$cart.useBonusmoney = isUsingBonusmoney;
  801. }
  802.  
  803.  
  804. //this.getEvenLinesOnlyMessage = function () {
  805. // return this.$cart.evenLinesOnlyMessage;
  806. //}
  807.  
  808. //this.setEvenLinesOnlyMessage = function (evenLinesOnlyMessage) {
  809. // this.$cart.evenLinesOnlyMessage = evenLinesOnlyMessage;
  810. //}
  811.  
  812. this.toObject = function () {
  813. if (this.getItems().length === 0) return false;
  814. console.log(items);
  815. //var items = [];
  816. //angular.forEach(this.getItems(), function (item) {
  817. // items.push(item.toObject());
  818. //});
  819.  
  820. //return {
  821. // shipping: this.getShipping(),
  822. // tax: this.getTax(),
  823. // taxRate: this.getTaxRate(),
  824. // subTotal: this.getSubTotal(),_evenLinesOnly
  825. // totalCost: this.totalCost(),
  826. // items: items
  827. //}
  828. return items;
  829. };
  830.  
  831. this.$restore = function (storedCart) {
  832. // debugger
  833. var _self = this;
  834. _self.init();
  835. _self.$cart.shipping = storedCart.shipping;
  836. _self.$cart.tax = storedCart.tax;
  837. _self.$cart.iframePaymentMethods = storedCart.iframePaymentMethods;
  838. _self.$cart.paymentMethodId = storedCart.paymentMethodId;
  839. _self.$cart.processor = storedCart.processor;
  840. _self.$cart.fastProcessingTax = storedCart.fastProcessingTax;
  841. _self.$cart.amountToPay = storedCart.amountToPay;
  842. _self.$cart.phoneOrEmail = storedCart.phoneOrEmail;
  843. _self.$cart.reedemCode = storedCart.reedemCode;
  844. _self.$cart.isFastProcessing = storedCart.isFastProcessing;
  845. _self.$cart.affiliateCode = storedCart.affiliateCode;
  846. _self.$cart.reedemBonusAmount = storedCart.reedemBonusAmount;
  847. _self.$cart.olapAffiliateCode = storedCart.olapAffiliateCode;
  848. _self.$cart.currency = storedCart.currency;
  849. _self.$cart.bonusAmountToUse = storedCart.bonusAmountToUse;
  850. _self.$cart.useBonusmoney = storedCart.useBonusmoney;
  851. _self.$cart.evenLinesOnlyMessage = storedCart.evenLinesOnlyMessage;
  852.  
  853. angular.forEach(storedCart.items, function (item) {
  854. _self.$cart.items.push(new ngCartItem(item._id, item._discount, item._groupComboBoxSelectionIndex, item._groupSettingsIndex, item._groupdiscount, item._groupnodraws, item._groupnoshares, item._grouporiginalprice,
  855. item._grouptotal, item._lotteryType, item._noofdraws, item._nooflines, item._numbers, item._originalprice, item._personalComboBoxSelectionIndex, item._personalSettingsIndex, item._selectedTab, item._totalCost, item._lotteryName,
  856. item._selectNumbers, item._minselectNumbers, item._maxselectNumbers, item._extraNumbers, item._maxExtraNumbers, item._minExtraNumber, item._minLines, item._maxLines, item._drawsPerWeek, item._productsDrawOptions, item._isFastProcessing,
  857. item._isSubscription, item._isQuickPick, item._ticketsNumbersId, item._productType, item._productExpire, item._productIdSpecial, item._quantity, item._guid, item._isRaffle, item._counterGuid, item._evenLinesOnly));
  858. });
  859. this.$save();
  860. };
  861.  
  862. this.$save = function () {
  863. var r = this.getCart();
  864. var test = store.set('cart', JSON.stringify(this.getCart()));
  865.  
  866. return store.set('cart', JSON.stringify(this.getCart()));
  867. }
  868.  
  869. this.isContainOlapProduct = function () {
  870. var cartLength = this.$cart.items.length;
  871.  
  872. for (var i = 0, len = cartLength; i < len; i++) {
  873. if (this.$cart.items[i].getProductIdSpecial() === 999) {
  874. return true;
  875. }
  876. }
  877. return false;
  878. };
  879. }
  880. ])
  881. .factory('ngCartItem', [
  882. '$rootScope', '$log', '$timeout', function ($rootScope, $log) {
  883.  
  884. var item = function (id, discount, groupComboBoxSelectionIndex, groupSettingsIndex, groupdiscount, groupnodraws, groupnoshares, grouporiginalprice,
  885. grouptotal, lotteryType, noofdraws, nooflines, numbers, originalprice, personalComboBoxSelectionIndex, personalSettingsIndex, selectedTab, totalCost, lotteryname,
  886. selectNumbers, minSelectNumber, maxSelectNumbers, extraNumbers, maxExtraNumbers, minExtraNumber, minLines, maxLines, drawsPerWeek, productsDrawOptions, isFastProcessing,
  887. isSubscription, isQuickPick, ticketsNumbers, productType, productExpire, productIdSpecial, quantity, guid, isRaffle, counterGuid, evenLinesOnly) {
  888. this.setId(id);
  889. this.setDiscount(discount);
  890. this.setGroupComboBoxSelectionIndex(groupComboBoxSelectionIndex);
  891. this.setGroupSettingsIndex(groupSettingsIndex);
  892. this.setGroupdiscount(groupdiscount);
  893. this.setGroupnodraws(groupnodraws);
  894. this.setGroupnoshares(groupnoshares);
  895. this.setGrouporiginalprice(grouporiginalprice);
  896. this.setGroupTotal(grouptotal);
  897. this.setLotteryType(lotteryType);
  898. this.setNumberOfDraws(noofdraws);
  899. this.setNumberOfLines(nooflines);
  900. this.setNumbers(numbers);
  901. this.setOriginalPrice(originalprice);
  902. this.setPersonalComboBoxSelectionIndex(personalComboBoxSelectionIndex);
  903. this.setPersonalSettingsIndex(personalSettingsIndex);
  904. this.setSelectedTab(selectedTab);
  905. this.setTotalCost(totalCost);
  906. this.setTotalDiscount();
  907. this.setNumbersSantized(numbers);
  908. this.setLotteryType(lotteryType);
  909. this.setLotteryName(lotteryname);
  910. this.setProductType(productType);
  911. this.setProductExpire(productExpire);
  912.  
  913. //lottery rules
  914. this.setSelectNumbers(selectNumbers);
  915. this.setMinSelectNumbers(minSelectNumber);
  916. this.setMaxSelectNumbers(maxSelectNumbers);
  917. this.setExtraNumbers(extraNumbers);
  918. this.setMaxExtraNumbers(maxExtraNumbers);
  919. this.setMinExtraNumber(minExtraNumber);
  920. this.setMinLines(minLines);
  921. this.setMaxLines(maxLines);
  922. this.setDrawsPerWeek(drawsPerWeek);
  923. this.setProductsDrawOptions(productsDrawOptions);
  924. this.setIsFastProcessing(isFastProcessing);
  925. this.setIsSubscription(isSubscription);
  926. this.setIsQuickPick(isQuickPick);
  927. this.setTicketsNumbersId(ticketsNumbers);
  928.  
  929. //counterGuid
  930. this.setCounterGuid(counterGuid);
  931. //isRaffle
  932. this.setIsRaffle(isRaffle);
  933. this.setProductIdSpecial(productIdSpecial);
  934. this.setGuid(guid);
  935.  
  936. if (!evenLinesOnly && lotteryType == 14) {
  937. evenLinesOnly = true;
  938. }
  939.  
  940. this.setEvenLinesOnly(evenLinesOnly)
  941.  
  942. //this.setPrice(price);
  943. //this.setQuantity(quantity);
  944. this.setQuantity(quantity);
  945.  
  946.  
  947. };
  948.  
  949. item.prototype.setId = function (id) {
  950. if (id) this._id = id;
  951. else {
  952. this._id = generateUid();
  953. $log.info('An ID is auto generated:' + this._id);
  954. }
  955. };
  956.  
  957. item.prototype.getId = function () {
  958. return this._id;
  959. };
  960.  
  961. item.prototype.setDiscount = function (discount) {
  962. this._discount = (discount);
  963. };
  964.  
  965. item.prototype.getDiscount = function () {
  966. if (this._productType === 1) {
  967. return this._discount.toFixed(3);
  968. } else {
  969. return this._groupdiscount.toFixed(2);
  970. }
  971. };
  972.  
  973. item.prototype.setGroupComboBoxSelectionIndex = function (groupComboBoxSelectionIndex) {
  974. this._groupComboBoxSelectionIndex = (groupComboBoxSelectionIndex);
  975. };
  976.  
  977. item.prototype.getGroupComboBoxSelectionIndex = function () {
  978. return this._groupComboBoxSelectionIndex;
  979. };
  980.  
  981. item.prototype.setGroupSettingsIndex = function (groupSettingsIndex) {
  982. this._groupSettingsIndex = (groupSettingsIndex);
  983. };
  984.  
  985. item.prototype.getGroupSettingsIndex = function () {
  986. return this._groupSettingsIndex;
  987. };
  988.  
  989. item.prototype.setGroupdiscount = function (groupdiscount) {
  990. //todo check is group then should not be 0
  991. this._groupdiscount = (groupdiscount);
  992. };
  993.  
  994. item.prototype.getGroupdiscount = function () {
  995. return this._groupdiscount;
  996. };
  997.  
  998. item.prototype.setGroupnodraws = function (groupnodraws) {
  999. this._groupnodraws = parseInt(groupnodraws);
  1000. };
  1001.  
  1002. item.prototype.getGroupnodraws = function () {
  1003. return this._groupnodraws;
  1004. };
  1005.  
  1006. item.prototype.setGroupnoshares = function (groupnoshares) {
  1007. this._groupnoshares = parseInt(groupnoshares);
  1008. };
  1009.  
  1010. item.prototype.getGroupnoshares = function () {
  1011. return this._groupnoshares;
  1012. };
  1013.  
  1014. item.prototype.setGrouporiginalprice = function (grouporiginalprice) {
  1015. this._grouporiginalprice = (grouporiginalprice);
  1016. };
  1017.  
  1018. item.prototype.getGrouporiginalprice = function () {
  1019. return this._grouporiginalprice;
  1020. };
  1021.  
  1022. item.prototype.setGroupTotal = function (grouptotal) {
  1023. this._grouptotal = (grouptotal);
  1024. };
  1025.  
  1026. item.prototype.getGroupTotal = function () {
  1027. return this._grouptotal;
  1028. };
  1029.  
  1030. item.prototype.setLotteryType = function (lotteryType) {
  1031. if (lotteryType) {
  1032. if (lotteryType <= 0) {
  1033. $log.error('A lotteryType must be over 0');
  1034. } else {
  1035. this._lotteryType = (lotteryType);
  1036. }
  1037. } else {
  1038. $log.error('A lotteryType must be provided');
  1039. }
  1040. };
  1041.  
  1042. item.prototype.getLotteryType = function () {
  1043. return this._lotteryType;
  1044. };
  1045.  
  1046. item.prototype.setLotteryName = function (lotteryname) {
  1047. if (lotteryname === 'NavidadPersonal') {
  1048. this._lotteryName = 'Navidad';
  1049. } else {
  1050. this._lotteryName = lotteryname;
  1051. }
  1052.  
  1053. };
  1054.  
  1055. item.prototype.getLotteryName = function () {
  1056. return this._lotteryName;
  1057. };
  1058.  
  1059. item.prototype.setNumberOfDraws = function (noofdraws) {
  1060. this._noofdraws = (noofdraws);
  1061. };
  1062.  
  1063. item.prototype.getNumberOfDraws = function () {
  1064. if (this._selectedTab === 'groupselection' || this._productType === 3) {
  1065. return this._groupnodraws;
  1066. }
  1067. return this._noofdraws;
  1068. };
  1069.  
  1070. item.prototype.getNumberOfLinesOrShares = function () {
  1071. if (this._productType !== 1) {
  1072. return this._groupnoshares;
  1073. }
  1074. return this._nooflines;
  1075. };
  1076.  
  1077. item.prototype.setNumberOfLines = function (nooflines) {
  1078. this._nooflines = (nooflines);
  1079. };
  1080.  
  1081. item.prototype.getNumberOfLines = function () {
  1082. return this._nooflines;
  1083. };
  1084.  
  1085. item.prototype.setNumbers = function (numbers) {
  1086. // debugger;
  1087. var newNumbers;
  1088. var currentLines;
  1089. if (typeof (numbers) !== 'undefined' && numbers !== "") {
  1090. newNumbers = "";
  1091. currentLines = 1;
  1092. for (var i = 0, len = numbers.length; i < len; i++) {
  1093. var pattern = '|';
  1094. var currentChar = numbers[i];
  1095. var nextChar = numbers[i + 1];
  1096.  
  1097. if (currentChar !== pattern) {
  1098. newNumbers += currentChar;
  1099. } else {
  1100.  
  1101. if (nextChar === pattern || typeof (nextChar) === 'undefined') {
  1102. continue;
  1103. }
  1104.  
  1105. currentLines++;
  1106. newNumbers += pattern;
  1107. }
  1108. }
  1109.  
  1110. if (currentLines !== this._nooflines) {
  1111. console.warn('mismatching lines in numebrs');
  1112. }
  1113. }
  1114.  
  1115. this._numbers = newNumbers;
  1116. };
  1117.  
  1118. item.prototype.getNumbers = function () {
  1119. return this._numbers;
  1120. };
  1121.  
  1122. item.prototype.setNumbersSantized = function (numbers) {
  1123. //debugger;
  1124. if (typeof (numbers) !== 'undefined') {
  1125. if (numbers.indexOf(',') !== -1) {
  1126. if (numbers.length > 0) {
  1127. var lines = numbers.split('|');
  1128. lines = lines.filter(function (e) { return e.replace(/(\r\n|\n|\r)/gm, "") });
  1129. this._numbersSantized = lines;
  1130. } else {
  1131. this._numbersSantized = [];
  1132. }
  1133. } else {
  1134. this._numbersSantized = [];
  1135. this._numbersSantized.push(numbers);
  1136. }
  1137. } else {
  1138. this._numbersSantized = [];
  1139. this._numbersSantized.push(numbers);
  1140. }
  1141. };
  1142.  
  1143. item.prototype.getNumbersSantized = function () {
  1144. return this._numbersSantized;
  1145. };
  1146.  
  1147. item.prototype.getLinesNumbers = function (line) {
  1148. // debugger;
  1149. if (this._lotteryType === 13) {
  1150. return line;
  1151. }
  1152. var lines = this._numbersSantized[line];
  1153. var numberslines = lines.split(',');
  1154.  
  1155. if (lines.indexOf('#') !== -1) {
  1156. numberslines = lines.split('#')[0].split(',');
  1157. }
  1158. return numberslines;
  1159.  
  1160.  
  1161. };
  1162.  
  1163. item.prototype.getLinesSpecialNumbers = function (line) {
  1164. //todo check if okay
  1165. var lines = this._numbersSantized[line];
  1166.  
  1167. if (lines.indexOf('#') !== -1) {
  1168. return lines.split('#')[1].split(',');
  1169. }
  1170. return 0;
  1171. };
  1172.  
  1173. item.prototype.setOriginalPrice = function (originalprice) {
  1174. this._originalprice = (originalprice);
  1175. };
  1176.  
  1177. item.prototype.getOriginalPrice = function () {
  1178. return this._originalprice;
  1179. };
  1180.  
  1181. item.prototype.setPersonalComboBoxSelectionIndex = function (personalComboBoxSelectionIndex) {
  1182.  
  1183. this._personalComboBoxSelectionIndex = (personalComboBoxSelectionIndex);
  1184.  
  1185. };
  1186.  
  1187. item.prototype.getPersonalComboBoxSelectionIndex = function () {
  1188. return this._personalComboBoxSelectionIndex;
  1189. };
  1190.  
  1191. item.prototype.setPersonalSettingsIndex = function (personalSettingsIndex) {
  1192.  
  1193. this._personalSettingsIndex = personalSettingsIndex;
  1194.  
  1195. };
  1196.  
  1197. item.prototype.getPersonalSettingsIndex = function () {
  1198. return this._personalSettingsIndex;
  1199. };
  1200.  
  1201. item.prototype.setSelectedTab = function (selectedTab) {
  1202. this._selectedTab = (selectedTab);
  1203. }
  1204.  
  1205. item.prototype.getSelectedTab = function () {
  1206. return this._selectedTab;
  1207. };
  1208.  
  1209. item.prototype.setTotalCost = function (totalCost) {
  1210. this._totalCost = parseFloat(totalCost);
  1211. };
  1212.  
  1213. item.prototype.getTotalCost = function () {
  1214. return this._totalCost;
  1215. };
  1216.  
  1217. item.prototype.setTotalDiscount = function (dis) {
  1218. //debugger
  1219. if (typeof (dis) === 'undefined') {
  1220. if (this._groupdiscount > 0) {
  1221. var price = this._totalCost + ((this._totalCost / (1 - this._groupdiscount)) * this._groupdiscount);
  1222. this._totalDiscount = this._groupdiscount * price;
  1223. } else {
  1224. var price = this._totalCost;
  1225. this._totalDiscount = this._groupdiscount * price;
  1226. }
  1227. } else {
  1228. this._totalDiscount = dis;
  1229. }
  1230. };
  1231.  
  1232. item.prototype.getTotalDiscount = function () {
  1233. // debugger;
  1234. if (this._productType === 1) {
  1235. return ((this._nooflines * this._originalprice * parseInt(this._noofdraws)) * this._discount).toFixed(2);
  1236. } else {
  1237. //debugger;
  1238. return this._totalDiscount;
  1239. }
  1240. };
  1241.  
  1242. item.prototype.removeLastLine = function () {
  1243. var lastLine = this._numbers.lastIndexOf('|');
  1244.  
  1245.  
  1246. var newNumbers = this._numbers.substring(0, lastLine);
  1247. this._numbers = newNumbers;
  1248.  
  1249. this.setNumbersSantized(newNumbers);
  1250.  
  1251. $rootScope.$broadcast('ngCart:change', {});
  1252. };
  1253.  
  1254. item.prototype.updateSantizedLine = function (numbers, line) {
  1255. if (this._numbersSantized.length < line) {
  1256. console.log('new line');
  1257. this._numbers += '|' + numbers;
  1258. this._numbersSantized.push(numbers);
  1259. this._nooflines++;
  1260. } else {
  1261. this._numbersSantized[line - 1] = numbers;
  1262. var splited = this._numbers.split('|');
  1263. splited[line - 1] = numbers;
  1264. this._numbers = splited.join('|');
  1265. }
  1266.  
  1267. $rootScope.$broadcast('ngCart:change', {});
  1268. }
  1269.  
  1270. item.prototype.setProductType = function (productType) {
  1271. this._productType = productType;
  1272. };
  1273.  
  1274. item.prototype.getProductType = function () {
  1275. return this._productType;
  1276. };
  1277.  
  1278. item.prototype.getLineOrShareText = function () {
  1279. if (this._productType === 1) {
  1280. return "Line";
  1281. }
  1282. return "Share";
  1283. }
  1284.  
  1285. //lottery rules properties
  1286. item.prototype.getSelectNumbers = function () {
  1287. return this._selectNumbers;
  1288. };
  1289.  
  1290. item.prototype.setSelectNumbers = function (selectNumbers) {
  1291. this._selectNumbers = selectNumbers;
  1292. };
  1293.  
  1294. item.prototype.getMinSelectNumbers = function () {
  1295. return this._minselectNumbers;
  1296. };
  1297.  
  1298. item.prototype.setMinSelectNumbers = function (minselectNumbers) {
  1299. this._minselectNumbers = minselectNumbers;
  1300. };
  1301.  
  1302. item.prototype.getMaxSelectNumbers = function () {
  1303. return this._maxselectNumbers;
  1304. };
  1305.  
  1306. item.prototype.setMaxSelectNumbers = function (maxselectNumbers) {
  1307. this._maxselectNumbers = maxselectNumbers;
  1308. };
  1309.  
  1310. item.prototype.getExtraNumbers = function () {
  1311. return this._extraNumbers;
  1312. };
  1313.  
  1314. item.prototype.setExtraNumbers = function (extraNumbers) {
  1315. this._extraNumbers = extraNumbers;
  1316. };
  1317.  
  1318. item.prototype.getMaxExtraNumbers = function () {
  1319. return this._maxExtraNumbers;
  1320. };
  1321.  
  1322. item.prototype.setMaxExtraNumbers = function (maxExtraNumbers) {
  1323. this._maxExtraNumbers = maxExtraNumbers;
  1324. };
  1325.  
  1326. item.prototype.getMinExtraNumber = function () {
  1327. return this._minExtraNumber;
  1328. };
  1329.  
  1330. item.prototype.setMinExtraNumber = function (minExtraNumber) {
  1331. this._minExtraNumber = minExtraNumber;
  1332. };
  1333.  
  1334. item.prototype.getMinLines = function () {
  1335.  
  1336. return this._minLines;
  1337. };
  1338.  
  1339. item.prototype.setMinLines = function (minLines) {
  1340. this._minLines = minLines;
  1341. };
  1342.  
  1343. item.prototype.getMaxLines = function () {
  1344. return this._maxLines;
  1345. };
  1346.  
  1347. item.prototype.setMaxLines = function (maxLines) {
  1348. this._maxLines = maxLines;
  1349. };
  1350.  
  1351. item.prototype.getDrawsPerWeek = function () {
  1352. return this._drawsPerWeek;
  1353. };
  1354.  
  1355. item.prototype.setDrawsPerWeek = function (drawsPerWeek) {
  1356. this._drawsPerWeek = drawsPerWeek;
  1357. };
  1358.  
  1359. item.prototype.setProductsDrawOptions = function (productsDrawOptions) {
  1360. this._productsDrawOptions = productsDrawOptions;
  1361. };
  1362.  
  1363. item.prototype.getProductsDrawOptions = function () {
  1364. //check what type is single or group
  1365. var toReturn = [];
  1366. var self = this;
  1367. if (this._productType === 1) {
  1368.  
  1369. angular.forEach(this._productsDrawOptions, function (value, key) {
  1370. if (value.ProductId === 1 && value.IsSubscription === self._isSubscription) {
  1371. toReturn = value.MultiDrawOptions;
  1372. }
  1373. });
  1374.  
  1375. } else if (this._productType === 3 || (this._selectedTab === "product" && this._productType === 3)) {
  1376. angular.forEach(this._productsDrawOptions, function (value, key) {
  1377. if (value.ProductId === 3 && value.IsSubscription === self._isSubscription) {
  1378. toReturn = value.MultiDrawOptions;
  1379. }
  1380. });
  1381. } else if (this._selectedTab === "product") {
  1382. //debugger;
  1383.  
  1384. var refactoredArray = [];
  1385. angular.forEach(this._productsDrawOptions, function (value, key) {
  1386. refactoredArray.push({
  1387. Discount: 0,
  1388. NumberOfDraws: value
  1389. });
  1390. });
  1391.  
  1392. return refactoredArray;
  1393. }
  1394.  
  1395. return toReturn;
  1396. };
  1397.  
  1398. item.prototype.getProductsSubscriptionOptions = function () {
  1399. //check what type is single or group
  1400. var toReturn = [];
  1401.  
  1402. if (this._productType === 1) {
  1403.  
  1404. angular.forEach(this._productsDrawOptions, function (value, key) {
  1405. if (value.ProductId === 1 && value.IsSubscription) {
  1406. toReturn = value.MultiDrawOptions;
  1407. }
  1408. });
  1409.  
  1410. } else {
  1411. angular.forEach(this._productsDrawOptions, function (value, key) {
  1412. if (value.ProductId === 3 && value.IsSubscription) {
  1413. toReturn = value.MultiDrawOptions;
  1414. }
  1415. });
  1416. }
  1417.  
  1418. return toReturn;
  1419. };
  1420.  
  1421. item.prototype.setProductExpire = function (productExpire) {
  1422. // console.log(productExpire);
  1423. this._productExpire = productExpire;
  1424. };
  1425.  
  1426. item.prototype.getProductExpire = function () {
  1427. if (typeof this._productExpire !== "undefined" && this._productExpire !== null && this._productExpire.length > 0) {
  1428. var countDown = this._productExpire[0].exp;
  1429. var future = new Date(countDown);
  1430. var diff = Math.floor((future.getTime() - new Date().getTime()) / 1000);
  1431.  
  1432. return diff;
  1433. } else {
  1434. return 0;
  1435. }
  1436.  
  1437. };
  1438.  
  1439. item.prototype.getNavidadTickets = function (counter) {
  1440. var arr = this._numbers.split('|')
  1441. if (typeof counter === 'undefined') {
  1442. return arr;
  1443. } else {
  1444. return arr.slice(0, counter);
  1445. }
  1446. };
  1447.  
  1448. item.prototype.getNavidadTicket = function (line) {
  1449. return this._numbers.split('|')[line].split("-");
  1450. };
  1451.  
  1452. item.prototype.setQuantity = function (qty) {
  1453. this._quantity = qty;
  1454. };
  1455.  
  1456. item.prototype.getQuantity = function () {
  1457. return this._quantity;
  1458. };
  1459.  
  1460. item.prototype.setTicketsNumbersId = function (ticketsNumbers) {
  1461. this._ticketsNumbersId = ticketsNumbers;
  1462. };
  1463.  
  1464. item.prototype.getTicketsNumbersId = function () {
  1465. return this._ticketsNumbersId;
  1466. };
  1467.  
  1468. item.prototype.getTotal = function () {
  1469. return +parseFloat(this.getTotalCost()).toFixed(2);
  1470. };
  1471.  
  1472. item.prototype.setIsFastProcessing = function (isFastProcessing) {
  1473. if (typeof (isFastProcessing) === 'undefined') {
  1474. isFastProcessing = false;
  1475. }
  1476. this._isFastProcessing = isFastProcessing;
  1477. };
  1478.  
  1479. item.prototype.getIsFastProcessing = function () {
  1480. return this._isFastProcessing;
  1481. };
  1482.  
  1483. item.prototype.setIsSubscription = function (isSubscription) {
  1484. if (typeof (isSubscription) === 'undefined') {
  1485. isSubscription = false;
  1486. }
  1487. this._isSubscription = isSubscription;
  1488. };
  1489.  
  1490. item.prototype.getIsSubscription = function () {
  1491. return this._isSubscription;
  1492. };
  1493.  
  1494. item.prototype.setIsQuickPick = function (isQuickPick) {
  1495. if (typeof (isQuickPick) === 'undefined') {
  1496. isQuickPick = false;
  1497. }
  1498. this._isQuickPick = isQuickPick;
  1499. };
  1500.  
  1501. item.prototype.getIsQuickPick = function () {
  1502. return this._isQuickPick;
  1503. };
  1504.  
  1505. item.prototype.setProductIdSpecial = function (productIdSpecial) {
  1506. this._productIdSpecial = productIdSpecial;
  1507. }
  1508.  
  1509. item.prototype.getProductIdSpecial = function () {
  1510. return this._productIdSpecial;
  1511. }
  1512.  
  1513. item.prototype.setIsRaffle = function (isRaffle) {
  1514. this._isRaffle = isRaffle;
  1515. }
  1516.  
  1517. item.prototype.getIsRaffle = function () {
  1518. return this._isRaffle;
  1519. };
  1520. item.prototype.setCounterGuid = function (counterGuid) {
  1521. this._counterGuid = counterGuid;
  1522. }
  1523.  
  1524. item.prototype.getCounterGuid = function () {
  1525. return this._counterGuid;
  1526. };
  1527. item.prototype.setGuid = function (guid) {
  1528. this._guid = guid;
  1529. }
  1530.  
  1531. item.prototype.getGuid = function () {
  1532. return this._guid;
  1533. }
  1534.  
  1535. item.prototype.setEvenLinesOnly = function (evenLinesOnly) {
  1536. return this._evenLinesOnly = evenLinesOnly;
  1537. }
  1538.  
  1539. item.prototype.getEvenLinesOnly = function () {
  1540. return this._evenLinesOnly;
  1541. }
  1542.  
  1543. item.prototype.toObject = function () {
  1544.  
  1545. return {
  1546. id: this.getId(),
  1547. lines: this.getNumberOfLines(),
  1548. draws: this.getNumberOfDraws(),
  1549. // name: this.getName(),
  1550. // price: this.getPrice(),
  1551. // quantity: this.getQuantity(),
  1552. // data: this.getData(),
  1553. total: this.getTotalCost()
  1554. }
  1555. };
  1556.  
  1557. function generateUid() {
  1558. return ("0000" + (Math.random() * Math.pow(36, 4) << 0).toString(36)).slice(-4);
  1559. }
  1560.  
  1561. return item;
  1562.  
  1563. }
  1564. ])
  1565. .service('store', [
  1566. '$window', 'CacheFactory', function ($window, CacheFactory) {
  1567.  
  1568. var dataCache = CacheFactory('cart', {
  1569. maxAge: 60 * 60 * 1000, // Items added to this cache expire after 60 minutes
  1570. // cacheFlushInterval: 60 * 60 * 1000, // This cache will clear itself every 60 minutes
  1571. deleteOnExpire: 'aggressive', // Items will be deleted from this cache when they expire
  1572. storageMode: 'localStorage' // This cache will use `localStorage`.
  1573. });
  1574.  
  1575. return {
  1576. get: function (key) {
  1577. if (dataCache.get(key)) {
  1578. var cart = angular.fromJson(dataCache.get(key));
  1579. return JSON.parse(cart);
  1580. }
  1581. //if ($window.localStorage[key]) {
  1582. // var cart = angular.fromJson($window.localStorage[key]);
  1583. // return JSON.parse(cart);
  1584. //}
  1585. return false;
  1586.  
  1587. },
  1588.  
  1589. set: function (key, val) {
  1590.  
  1591. if (val === undefined) {
  1592. //$window.localStorage.removeItem(key);
  1593. dataCache.remove(key);
  1594. } else {
  1595. dataCache.put(key, angular.toJson(val));
  1596. //$window.localStorage[key] = angular.toJson(val);
  1597. }
  1598. //return $window.localStorage[key];
  1599. return dataCache.get(key);
  1600. },
  1601.  
  1602. emptyCart: function () {
  1603. CacheFactory.destroy('cart');
  1604. }
  1605. }
  1606. }
  1607. ])
  1608. .controller('CartController', [
  1609. '$scope', 'ngCart', 'ngDialog', '$controller', '$rootScope', 'ngCart.lottoyard.api', '$location', 'PaymentSystems', 'ngCart.GetCountryByIpService', 'ngCart.translationService', '$window',
  1610. function ($scope, ngCart, ngDialog, $controller, $rootScope, LottoyardService, $location, PaymentSystems, GetCountryByIpService, translationService, $window) {
  1611. $scope.ngCart = ngCart;
  1612. $scope.allItems = ngCart.getItems();
  1613. $scope.isFirstTimePurchase = $rootScope.isFirstTimePurchase;
  1614. $scope.isAuthenticated = $rootScope.isAuthenticated;
  1615. $scope.paymentSystems = PaymentSystems;
  1616. $scope.extraInfo = "creditcard";
  1617. $scope.promoCode = "";
  1618. $scope.creditcard = {};
  1619. $scope.paymentMethodError = false;
  1620. $scope.country_code = '';
  1621. $scope.signup = { phoneNumber: "", fullname: "", email: "", password: "", mobileNumber: "" };
  1622. $scope.terms = false;
  1623. $scope.fastProcessing = ngCart.getIsFastProcessing();
  1624. $scope.section = { selectionPaymentTemplate: "" };
  1625. $scope.country_codes = CountryCodeNames;
  1626. $scope.country_prefixes = CountryCodePrefixes;
  1627. $scope.language = $rootScope.language;
  1628. $scope.redeemCodeOk = false;
  1629. $scope.redeemCodeWrong = false;
  1630. $scope.showFreeTicket = false;
  1631. $scope.hideEmptyCart = false;
  1632. //$scope.promoCode = ngCart.getReedemCode();
  1633. var currentYear = new Date().getFullYear();
  1634. var legalAgeOfPlay = currentYear - 18;
  1635. $scope.currentYear = currentYear;
  1636. $scope.creditCardExpirationYears = new Array(11).join().split(',').map(function (item, index) { return (index === 0 ? $scope.currentYear : ++$scope.currentYear); });
  1637. $scope.creditCardExpirationMonths = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
  1638. $scope.vipPoints = $rootScope.vipPoints;
  1639. $scope.bonusMoney = $rootScope.bonusMoney;
  1640. $scope.InvalidPhoneErrorMessageSignUp = { display: 'none' };
  1641. $scope.InvalidPasswordErrorMessageSignUp = { display: 'none' };
  1642. $scope.InvalidEmailErrorMessageSignUp = { display: 'none' };
  1643. $scope.InvalidFullnameErrorMessageSignUp = { display: 'none' };
  1644. $scope.InvalidPasswordErrorMessage = { display: 'none' };
  1645. $scope.InvalidEmailErrorMessage = { display: 'none' };
  1646. $scope.phoneInputSignup = "";
  1647. $scope.passwordInputSignup = "";
  1648. $scope.emailInputSignup = "";
  1649. $scope.fullnameInputSignup = "";
  1650. $scope.passwordInputSignin = "";
  1651. $scope.emailInputSignin = "";
  1652. $scope.signupNumberIsChanged = true;
  1653. $scope.birthdayYears = new Array(90).join().split(',').map(function (item, index) { return (legalAgeOfPlay - index); });
  1654. $scope.user = {};
  1655. $scope.user.birthday = {};
  1656. $scope.user.birthday.day = 1;
  1657. $scope.user.birthday.month = $scope.creditCardExpirationMonths[0];
  1658. $scope.user.birthday.year = $scope.birthdayYears[0];
  1659. $scope.daysInMonth = makeArrayOfNumbers(daysInMonth(1, currentYear));
  1660. $scope.toShowAddressFields = false;
  1661. $scope.subtotal = ngCart.totalCost() - ngCart.getReedemBonusAmount();
  1662. $scope.model = {
  1663. isUsingBonusMoney: true
  1664. };
  1665.  
  1666. $scope.cart = {};
  1667. $scope.cart.promoCode = ngCart.getReedemCode();
  1668. $scope.$watch('cart.promoCode', function (newValue, oldValue) {
  1669. if (validatePromoCode(newValue)) {
  1670. ngCart.setReedemCode(newValue);
  1671. }
  1672.  
  1673. getPromoCodeTotal();
  1674. });
  1675.  
  1676. if (ngCart.getProcessor() == "") {
  1677. ngCart.setProcessor("CreditCard");
  1678. }
  1679.  
  1680. $scope.$watch('cart.isCheckedPromoCode', function (newValue, oldValue) {
  1681. if (newValue && validatePromoCode($scope.cart.promoCode)) {
  1682. ngCart.setReedemCode($scope.cart.promoCode);
  1683. } else if (ngCart.getReedemCode() && typeof newValue == "undefined") {
  1684. $scope.cart.isCheckedPromoCode = true;
  1685. } else {
  1686. ngCart.setReedemCode();
  1687. }
  1688.  
  1689. getPromoCodeTotal();
  1690. });
  1691.  
  1692. function setTotalCost() {
  1693. if (!$scope.model.isUsingBonusMoney) {
  1694. $scope.total = ngCart.totalCost() - ngCart.getReedemBonusAmount() < 0 ? 0 : ngCart.totalCost() - ngCart.getReedemBonusAmount();
  1695. } else if ($scope.model.isUsingBonusMoney) {
  1696. $scope.total = ngCart.totalCost() - ngCart.getBonusAmountToUse() - ngCart.getReedemBonusAmount() < 0 ? 0 : ngCart.totalCost() - ngCart.getBonusAmountToUse() - ngCart.getReedemBonusAmount();
  1697. }
  1698. };
  1699.  
  1700. function getPromoCodeTotal() {
  1701. var mapper = new Mapper(ngCart.getCart());
  1702. var data = mapper.PrepareOrder();
  1703.  
  1704. LottoyardService.prepareOrder(data).then(function (resp) {
  1705. prepareOrderResponse(resp);
  1706. setTotalCost();
  1707. }, function (error) {
  1708. console.log(error);
  1709. })
  1710. }
  1711.  
  1712. function validatePromoCode(code) {
  1713. var regex = new RegExp(/[A-z]+-[A-z0-9]+-[A-z0-9]+/);
  1714. return regex.test(code);
  1715. }
  1716.  
  1717. translationService.getTranslation($scope, $rootScope.language);
  1718.  
  1719. $scope.$watch('model.isUsingBonusMoney', function (newValue, oldValue) {
  1720. $scope.ngCart.setUseBonusmoney(newValue);
  1721. var mapper = new Mapper(ngCart.getCart());
  1722. var data = mapper.PrepareOrder();
  1723. LottoyardService.prepareOrder(data).then(function (resp) {
  1724. prepareOrderResponse(resp);
  1725. ngCart.setBonusAmountToUse(resp.BonusAmountAvailable);
  1726. $scope.subtotal = ngCart.totalCost() - ngCart.getReedemBonusAmount();
  1727. $scope.bonus = ngCart.getUseBonusmoney() ? ngCart.getBonusAmountToUse() : 0;
  1728. setTotalCost();
  1729. });
  1730. });
  1731.  
  1732.  
  1733.  
  1734. $scope.$watch(function () {
  1735. return $rootScope.disableBtn;
  1736. }, function () {
  1737. $scope.disableBtn = $rootScope.disableBtn;
  1738. }, true);
  1739.  
  1740. $scope.$watch(function () {
  1741. return $rootScope.progress;
  1742. }, function () {
  1743. $scope.progress = $rootScope.progress;
  1744. }, true);
  1745.  
  1746. if ($scope.isAuthenticated && $scope.isFirstTimePurchase) {
  1747. $scope.showFreeTicket = true;
  1748. $scope.hideEmptyCart = true;
  1749. } else if ($scope.isAuthenticated && !$scope.isFirstTimePurchase) {
  1750. $scope.showFreeTicket = false;
  1751. $scope.hideEmptyCart = false;
  1752. } else {
  1753. $scope.showFreeTicket = false;
  1754. $scope.hideEmptyCart = true;
  1755. }
  1756.  
  1757. if (typeof $rootScope.language === 'undefined' || $rootScope.language === '') {
  1758. $rootScope.language = 'en';
  1759. }
  1760.  
  1761. console.log('lang:', $rootScope.language);
  1762.  
  1763. if (!$scope.isAuthenticated) {
  1764. clearPersonalInfo();
  1765. }
  1766.  
  1767. $scope.redirectToCart = function ($event) {
  1768. $event.preventDefault();
  1769. window.location = '/' + $scope.language + '/cart/';
  1770. }
  1771.  
  1772. $scope.redirectToPlayPageTopJackpot = function () {
  1773. window.location = '/' + $scope.language + '/lottery-ticket/' + $rootScope.topJacktop.LotteryName + '/';
  1774. }
  1775.  
  1776. $scope.initCart = function () {
  1777. //$scope.evenLinesOnlyMessage = ngCart.getEvenLinesOnlyMessage();
  1778. $scope.evenLinesOnlyMessage = JSON.parse(sessionStorage.getItem('showEvenLinesOnly'));
  1779. sessionStorage.setItem('showEvenLinesOnly', false)
  1780.  
  1781. if ($scope.isAuthenticated) {
  1782. LottoyardService.getPersonalDetailsByMemberId(JSON.stringify({ MemberId: "{0}" })).then(function (resp) {
  1783. if (resp.City === "" || resp.Address === "" || resp.ZipCode === "") {
  1784. $scope.toShowAddressFields = true;
  1785. }
  1786.  
  1787. $scope.user.city = resp.City == "" ? $scope.user.city : resp.City;
  1788. $scope.user.address = resp.Address == "" ? $scope.user.address : resp.Address;
  1789. $scope.user.postalCode = resp.ZipCode == "" ? $scope.user.postalCode : resp.ZipCode;
  1790. $scope.creditcard.CardHolderName = resp.FirstName + " " + resp.LastName;
  1791.  
  1792. var birthdayDateApi = new Date(resp.DateOfBirth);
  1793. if (validateEighteenYearsAge(birthdayDateApi)) {
  1794. $scope.user.birthday.day = birthdayDateApi.getDate();
  1795. $scope.user.birthday.month = (birthdayDateApi.getMonth().toString().length === 1 && birthdayDateApi.getMonth() < 9) ? "0" + (birthdayDateApi.getMonth() + 1) : (birthdayDateApi.getMonth() + 1).toString();
  1796. $scope.user.birthday.year = birthdayDateApi.getFullYear();
  1797. $scope.daysInMonth = makeArrayOfNumbers(daysInMonth(parseInt($scope.user.birthday.month), currentYear));
  1798. }
  1799. });
  1800. if (ngCart.getItems().length > 0) {
  1801. var mapper = new Mapper(ngCart.getCart());
  1802. var data = mapper.PrepareOrder();
  1803. LottoyardService.prepareOrder(data).then(function (resp) {
  1804. prepareOrderResponse(resp);
  1805. if (resp.BonusAmountAvailable > ngCart.totalCost()) {
  1806. ngCart.setBonusAmountToUse(ngCart.totalCost());
  1807. } else {
  1808. ngCart.setBonusAmountToUse(resp.BonusAmountAvailable);
  1809. }
  1810.  
  1811. var res = ngCart.getItems();
  1812. res.forEach(function (item) {
  1813. var test = item.getIsSubscription();
  1814. item.Checked = item.getIsSubscription();
  1815. })
  1816.  
  1817. if (ngCart.getTotalItems() > 0 && $scope.isAuthenticated && (ngCart.getIframePaymentMethods().length === 0 || $scope.extraInfo != 'creditcard' || $scope.creditCard == false)) {
  1818. $scope.section.selectionPaymentTemplate = 'new';
  1819. } else if (ngCart.getTotalItems() > 0 && $scope.isAuthenticated && ngCart.getIframePaymentMethods().length > 0) {
  1820. $scope.section.selectionPaymentTemplate = 'exist';
  1821. }
  1822.  
  1823. setTotalCost();
  1824. });
  1825. }
  1826. } else {
  1827.  
  1828. if (ngCart.getTotalItems() > 0) {
  1829. var res = ngCart.getItems();
  1830. debugger
  1831. res.forEach(function (item) {
  1832. item.Checked = item.getIsSubscription();
  1833. })
  1834.  
  1835. $scope.section.selectionPaymentTemplate = 'signup';
  1836. if (validatePromoCode($scope.cart.promoCode)) {
  1837. var mapper = new Mapper(ngCart.getCart());
  1838. var data = mapper.PrepareOrder();
  1839. LottoyardService.prepareOrder(data).then(function (resp) {
  1840. prepareOrderResponse(resp);
  1841. })
  1842. }
  1843.  
  1844. setTotalCost();
  1845. }
  1846. }
  1847. };
  1848.  
  1849. $scope.removeItem = function (itemId) {
  1850. var item = itemId;
  1851. if (typeof itemId !== "object") {
  1852. item = ngCart.getItemById(itemId);
  1853. }
  1854.  
  1855. if ((typeof item === "object") && (item !== null)) {
  1856. var guid = item.getGuid();
  1857. if (typeof guid !== 'undefined') {
  1858. var items = ngCart.getItems();
  1859. var itemToRemove = [];
  1860. angular.forEach(items, function (item) {
  1861. if (item.getGuid() === guid) {
  1862. itemToRemove.push(item.getId());
  1863. }
  1864. });
  1865. for (var i = 0; i < itemToRemove.length; i++) {
  1866. ngCart.removeItemById(itemToRemove[i]);
  1867. }
  1868. } else {
  1869. ngCart.removeItemById(item.getId());
  1870. }
  1871. }
  1872.  
  1873. var allGroup = ngCart.getItems().filter(function (item) {
  1874. return item.getProductType() == 3;
  1875. });
  1876.  
  1877. if (allGroup.length == 0) {
  1878. ngCart.setUseBonusmoney(false);
  1879. $scope.model.isUsingBonusMoney = false;
  1880. }
  1881.  
  1882. $scope.initCart();
  1883. };
  1884.  
  1885. $scope.initSignUp = function () {
  1886. console.log('init');
  1887.  
  1888. GetCountryByIpService.getCountryCodeByIp().then(function (data) {
  1889. $scope.signup.countryPhonePrefix = $scope.country_prefixes[data];
  1890. $scope.signup.phoneNumber = $scope.country_prefixes[data];
  1891. $scope.signup.mobileNumber = $scope.country_prefixes[data];
  1892. $scope.signup.countryCode = data;
  1893. $scope.country_code = CountryCodeNames.filter(function (v) { return v.code === data })[0];
  1894. });
  1895. };
  1896.  
  1897. $scope.setPrefix = function (code) {
  1898. $scope.phone_prefix = $scope.country_prefixes[code];
  1899. $scope.signup.phoneNumber = $scope.phone_prefix;
  1900. $scope.signup.mobileNumber = $scope.phone_prefix;
  1901. };
  1902.  
  1903. $scope.beforeCheckOutCall = beforeCheckOutCall;
  1904.  
  1905. $scope.editPaymentMethods = function () {
  1906. $scope.creditCard = false;
  1907. $scope.section.selectionPaymentTemplate = 'new';
  1908. }
  1909.  
  1910. $scope.signin = function ($event, user) {
  1911. $event.preventDefault();
  1912. $scope.signinErrorText = [];
  1913. $scope.InvalidEmailErrorMessage = { display: 'none' };
  1914. $scope.InvalidPasswordErrorMessage = { display: 'none' };
  1915.  
  1916. if (typeof (user) === 'undefined' || user === "") {
  1917. $scope.signinError = true;
  1918. $scope.signinErrorText.push({ ErrorMessage: "Login failed" });
  1919. return;
  1920. } else if (typeof (user.email) === 'undefined' || user.email === "") {
  1921. $scope.signinError = true;
  1922. $scope.signinErrorText.push({ ErrorMessage: "Login failed" });
  1923. return;
  1924. } else if (typeof (user.password) === 'undefined' || user.password === "") {
  1925. $scope.signinError = true;
  1926. $scope.signinErrorText.push({ ErrorMessage: "Login failed" });
  1927. return;
  1928. }
  1929.  
  1930. $scope.signinError = false;
  1931. $scope.errorText = "";
  1932.  
  1933. LottoyardService.signIn(user).then(function (resp) {
  1934. console.log(resp);
  1935. if (resp === "Login failed") {
  1936. $scope.signinError = true;
  1937. $scope.signinErrorText.push({ ErrorMessage: resp });
  1938. } else {
  1939. clearPersonalInfo();
  1940.  
  1941. //GTM functions for tracking.
  1942. GTM_login(resp.MemberId);
  1943.  
  1944. window.location.href = $rootScope.cartUrlWithLang + "?sessionId=" + resp.UserSessionId + "&bta=" + $rootScope.affiliateId;
  1945. }
  1946. });
  1947. }
  1948.  
  1949. $scope.numberChanged = function (e) {
  1950. if (e.phoneNumber != e.countryPhonePrefix) {
  1951. $scope.signupNumberIsChanged = false;
  1952. }
  1953. }
  1954.  
  1955. $scope.passwordFocusIn = function () {
  1956. $scope.signinError = false;
  1957. var email = $scope.emailInputSignin;
  1958. if (email.trim() === '') {
  1959. $scope.InvalidEmailErrorMessage = { display: 'none' };
  1960. return;
  1961. }
  1962.  
  1963. var emailRegex = new RegExp(/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/);
  1964. var isValidEmail = email.match(emailRegex)
  1965. if (!isValidEmail) {
  1966. $scope.InvalidEmailErrorMessage = { display: 'block' };
  1967. } else {
  1968. $scope.InvalidEmailErrorMessage = { display: 'none' };
  1969. }
  1970. }
  1971.  
  1972. $scope.emailFocusOut = function (e) {
  1973. $scope.emailInputSignin = e.currentTarget.value.toString();
  1974. }
  1975.  
  1976. $scope.emailFocusIn = function () {
  1977. $scope.signinError = false;
  1978. var password = $scope.passwordInputSignin;
  1979. if (password.trim() === '') {
  1980. $scope.InvalidPasswordErrorMessage = { display: 'none' };
  1981. return;
  1982. }
  1983.  
  1984. if (password.length < 7 || password.length > 20) {
  1985. $scope.InvalidPasswordErrorMessage = { display: 'block' };
  1986. } else {
  1987. $scope.InvalidPasswordErrorMessage = { display: 'none' };
  1988. }
  1989. }
  1990.  
  1991. $scope.passwordFocusOut = function (e) {
  1992. $scope.passwordInputSignin = e.currentTarget.value.toString();
  1993. }
  1994.  
  1995. $scope.phoneFocusInSignUp = function () {
  1996. $scope.signupError = false;
  1997. _passwordValidation($scope.passwordInputSignup);
  1998. _fullnameValidation($scope.fullnameInputSignup);
  1999. _emailValidation($scope.emailInputSignup);
  2000. }
  2001.  
  2002. $scope.phoneFocusOutSignUp = function (e) {
  2003. $scope.phoneInputSignup = e.currentTarget.value.toString();
  2004. }
  2005.  
  2006. $scope.passwordFocusInSignUp = function () {
  2007. $scope.signupError = false;
  2008. _phoneValidation($scope.phoneInputSignup);
  2009. _fullnameValidation($scope.fullnameInputSignup);
  2010. _emailValidation($scope.emailInputSignup);
  2011. }
  2012.  
  2013. $scope.passwordFocusOutSignUp = function (e) {
  2014. $scope.passwordInputSignup = e.currentTarget.value.toString();
  2015. }
  2016.  
  2017. $scope.fullnameFocusInSignUp = function () {
  2018. $scope.signupError = false;
  2019. _phoneValidation($scope.phoneInputSignup);
  2020. _passwordValidation($scope.passwordInputSignup);
  2021. _emailValidation($scope.emailInputSignup);
  2022. }
  2023.  
  2024. $scope.fullnameFocusOutSignUp = function (e) {
  2025. $scope.fullnameInputSignup = e.currentTarget.value.toString();
  2026. }
  2027.  
  2028. $scope.emailFocusInSignUp = function () {
  2029. $scope.signupError = false;
  2030. _phoneValidation($scope.phoneInputSignup);
  2031. _passwordValidation($scope.passwordInputSignup);
  2032. _fullnameValidation($scope.fullnameInputSignup);
  2033. }
  2034.  
  2035. $scope.emailFocusOutSignUp = function (e) {
  2036. $scope.emailInputSignup = e.currentTarget.value.toString();
  2037. }
  2038.  
  2039. $scope.signUp = function ($event, user) {
  2040. $scope.signupErrorText = [];
  2041. $event.preventDefault();
  2042. $scope.InvalidPhoneErrorMessageSignUp = { display: 'none' };
  2043. $scope.InvalidPasswordErrorMessageSignUp = { display: 'none' };
  2044. $scope.InvalidEmailErrorMessageSignUp = { display: 'none' };
  2045. $scope.InvalidFullnameErrorMessageSignUp = { display: 'none' };
  2046.  
  2047. if (typeof (user) === 'undefined') {
  2048. $scope.signupError = true;
  2049. $scope.signupErrorText.push("Error");
  2050. return;
  2051. }
  2052.  
  2053. if (!user.fullname || user.fullname === "") {
  2054. $scope.signupError = true;
  2055. $scope.signupErrorText.push({ ErrorMessage: "Please insert valid full name" });
  2056. return;
  2057. }
  2058.  
  2059. var fullnameRegex = new RegExp(/^[a-zа-я ]{2,20}$/ig);
  2060. if (!user.fullname.match(fullnameRegex)) {
  2061. $scope.signupError = true;
  2062. $scope.signupErrorText.push({ ErrorMessage: "Name must not include numbers and be 2-20 characters" });
  2063. return;
  2064. }
  2065.  
  2066. var emailRegex = new RegExp(/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/);
  2067. if (!user.email || !user.email.match(emailRegex)) {
  2068. $scope.signupError = true;
  2069. $scope.signupErrorText.push({ ErrorMessage: "Please insert valid email" });
  2070. return;
  2071. }
  2072.  
  2073. if (!user.password || user.password === "") {
  2074. $scope.signupError = true;
  2075. $scope.signupErrorText.push({ ErrorMessage: "Please insert valid password" });
  2076. return;
  2077. }
  2078.  
  2079. if (user.password.length < 7 || user.password.length > 20) {
  2080. $scope.signupError = true;
  2081. $scope.signupErrorText.push({ ErrorMessage: "Password length must be between 7 to 20 characters" });
  2082. return;
  2083. }
  2084.  
  2085. var phoneRegex = new RegExp(/^[0-9]{6,25}$/);
  2086. var firstInputNumber = user.phoneNumber.match(phoneRegex);
  2087. var secondInputNumber = user.mobileNumber.match(phoneRegex);
  2088. if ((!firstInputNumber && !secondInputNumber) || (!user.phoneNumber && !user.mobileNumber)) {
  2089. $scope.signupError = true;
  2090. $scope.signupErrorText.push({ ErrorMessage: "Please insert valid phone number" });
  2091. return;
  2092. }
  2093.  
  2094. $scope.signupError = false;
  2095. user.CountryCode = $scope.signup.countryCode;
  2096.  
  2097. var splitedName = user.fullname.split(' ');
  2098. user.firstName = splitedName[0];
  2099. if (splitedName.length > 1) {
  2100. user.lastName = splitedName.slice(1).join(' ');
  2101. }
  2102. user.email = user.email.trim();
  2103. user.affiliateId = $rootScope.affiliateId;
  2104. if (!$scope.signupError) {
  2105. LottoyardService.signUp(user).then(function (resp) {
  2106. console.log(resp);
  2107. if (typeof (resp.UserSessionId) !== 'undefined') {
  2108. clearPersonalInfo();
  2109. sessionStorage.setItem('firepixel', 'https://go.icelotto.com/dynamicpixels/LeadRegistered/?userId=' + resp.MemberId + '&IsoCountry=' + resp.isoCountry);
  2110.  
  2111. //GTM functions for tracking.
  2112. GTM_signup(resp.MemberId);
  2113.  
  2114. window.location.href = $rootScope.cartUrlWithLang + "?sessionId=" + resp.UserSessionId + "&bta=" + $rootScope.affiliateId;
  2115. } else {
  2116. $scope.signupError = true;
  2117. if (Array.isArray(resp)) {
  2118. $scope.signupErrorText = resp;
  2119. } else {
  2120. var err = { ErrorMessage: resp };
  2121. $scope.signupErrorText.push(err);
  2122. }
  2123. }
  2124. });
  2125. }
  2126. }
  2127.  
  2128. $scope.paymentSelect = function (payment) {
  2129. console.log(payment);
  2130.  
  2131. if (($scope.creditCard == true || typeof $scope.creditCard === 'undefined') && ngCart.getIframePaymentMethods().length > 0 && payment.name == 'creditcard') {
  2132. $scope.section.selectionPaymentTemplate = "exist";
  2133. } else {
  2134. $scope.section.selectionPaymentTemplate = "new";
  2135. }
  2136.  
  2137. ngCart.setProcessor(payment.processor);
  2138.  
  2139. if (payment.needmoreinfo) {
  2140. //load div
  2141.  
  2142. if ((ngCart.getAmountToPay() < 2) && (payment.name != "creditcard")) {
  2143. paymentSelect();
  2144. }
  2145. $scope.extraInfo = payment.name;
  2146. return;
  2147. }
  2148. paymentSelect();
  2149. }
  2150.  
  2151. $scope.paymentSelectMoreInfo = function ($event, phoneOrEmail) {
  2152. $event.preventDefault();
  2153. //debugger;
  2154. var test = ngCart.getProcessor();
  2155. console.log(phoneOrEmail);
  2156. ngCart.setPhoneOrEmail(phoneOrEmail);
  2157.  
  2158. paymentSelect();
  2159.  
  2160. }
  2161.  
  2162. $scope.submitOrderNewCreditCard = function (creditcard, user) {
  2163. $scope.creditCardErrorArr = [];
  2164. $scope.creditCard = false;
  2165. var birthday = new Date(Date.UTC(user.birthday.year, (parseInt(user.birthday.month) - 1), user.birthday.day));
  2166.  
  2167. if (typeof (creditcard) === 'undefined') {
  2168. $scope.creditCard = true;
  2169. return;
  2170. }
  2171. if (!creditcard.terms) {
  2172. $scope.creditCard = true;
  2173. $scope.creditCardErrorArr.push({ ErrorMessage: "Please accept our Terms and Conditions" });
  2174. return;
  2175. }
  2176. if (typeof (creditcard.CardHolderName) === 'undefined' || creditcard.CardHolderName.length < 2) {
  2177. $scope.creditCard = true;
  2178. $scope.creditCardErrorArr.push({ ErrorMessage: "Please type your full name" });
  2179. return;
  2180. }
  2181.  
  2182. if (typeof (creditcard.CreditCardNumber) === 'undefined' || creditcard.CreditCardNumber.length == 0) {
  2183. $scope.creditCard = true;
  2184. $scope.creditCardErrorArr.push({ ErrorMessage: "MissingCreditCard" });
  2185. return false;
  2186. }
  2187.  
  2188. if (typeof (creditcard.CreditCardNumber) === 'undefined' || creditcard.CreditCardNumber.length < 10) {
  2189. $scope.creditCard = true;
  2190. $scope.creditCardErrorArr.push({ ErrorMessage: "Credit card number length is invalid" });
  2191. return;
  2192. }
  2193. if (typeof (creditcard.expiration) === 'undefined') {
  2194. $scope.creditCard = true;
  2195. $scope.creditCardErrorArr.push({ ErrorMessage: "Please insert Expiration Date" });
  2196. return;
  2197. }
  2198. if (typeof (creditcard.expiration.year) === 'undefined') {
  2199. $scope.creditCard = true;
  2200. $scope.creditCardErrorArr.push({ ErrorMessage: "Please insert Expiration Year" });
  2201. return;
  2202. }
  2203. if (typeof (creditcard.expiration.month) === 'undefined') {
  2204. $scope.creditCard = true;
  2205. $scope.creditCardErrorArr.push({ ErrorMessage: "Please insert Expiration Month" });
  2206. return;
  2207. }
  2208. if (typeof (creditcard.Cvv) === 'undefined' || creditcard.Cvv.length < 2) {
  2209. $scope.creditCard = true;
  2210. $scope.creditCardErrorArr.push({ ErrorMessage: "Please insert your cvv number" });
  2211. return;
  2212. }
  2213.  
  2214. var lastDay = new Date(parseInt(creditcard.expiration.year), parseInt(creditcard.expiration.month), 0).getDate();
  2215. var expirationDate = creditcard.expiration.year + "-" + creditcard.expiration.month + "-" + lastDay;
  2216.  
  2217. var today = new Date();
  2218. today.setHours(0, 0, 0, 0);
  2219. var creditCardDate = new Date(expirationDate);
  2220. creditCardDate.setHours(0, 0, 0, 0);
  2221.  
  2222. if (creditCardDate < today) {
  2223. $scope.creditCard = true;
  2224. $scope.creditCardErrorArr.push({ ErrorMessage: "Please enter valid card expiration date" });
  2225. return;
  2226. }
  2227.  
  2228. var creditCardForSend = {
  2229. CardHolderName: creditcard.CardHolderName,
  2230. CreditCardNumber: creditcard.CreditCardNumber,
  2231. Cvv: creditcard.Cvv,
  2232. ExpirationDate: expirationDate
  2233. };
  2234.  
  2235. if (!validateAddressFields(user, birthday)) {
  2236. return;
  2237. }
  2238. console.log(creditCardForSend);
  2239.  
  2240. ngCart.setProcessor("CreditCard");
  2241.  
  2242.  
  2243. var mapper = new Mapper(ngCart.getCart(), creditCardForSend);
  2244. var data = mapper.ConfirmOrder();
  2245.  
  2246. //updatePersonalDetails
  2247. var personalDetails = {
  2248. MemberId: "{0}",
  2249. DateOfBirth: birthday,
  2250. Address: user.address,
  2251. City: user.city,
  2252. ZipCode: user.postalCode
  2253. };
  2254.  
  2255. LottoyardService.updatePersonalDetails(JSON.stringify(personalDetails)).then(function (resp) {
  2256. if (resp.Result === "Personal details updated") {
  2257.  
  2258. LottoyardService.submitOrder(data).then(function (resp) {
  2259. console.log(resp);
  2260.  
  2261. if (resp.IsSuccess) {
  2262. window.location = '/' + $rootScope.language + '/ThankYou2/Purchase/' + resp.Pmc + "/" + $rootScope.sessionId + "/" + 1 + "/";
  2263. } else {
  2264. $scope.creditCard = true;
  2265. $scope.creditCardErrorArr.push({ ErrorMessage: resp.ErrorMessage });
  2266. return;
  2267. }
  2268. });
  2269. } else {
  2270. $scope.creditCard = true;
  2271. $scope.creditCardErrorArr.push({ ErrorMessage: resp.ErrorMessage });
  2272. return;
  2273. }
  2274. });
  2275. }
  2276.  
  2277. $scope.submitOrder = function (selectedMethod, terms, user) {
  2278. $scope.creditCardErrorArr = [];
  2279.  
  2280. if (typeof user.birthday === 'undefined' && (typeof user.birthday.day === 'undefined' || typeof user.birthday.month === 'undefined' || typeof user.birthday.year === 'undefined')) {
  2281. $scope.creditCard = true;
  2282. $scope.creditCardErrorArr.push({
  2283. ErrorMessage: "Please insert valid date of birth"
  2284. });
  2285. return;
  2286. }
  2287. var birthday = new Date(Date.UTC(user.birthday.year, (parseInt(user.birthday.month) - 1), user.birthday.day));
  2288.  
  2289.  
  2290. if (!terms) {
  2291. $scope.creditCard = true;
  2292. $scope.creditCardErrorArr.push({ ErrorMessage: "Please accept our Terms and Conditions" });
  2293.  
  2294. return;
  2295. }
  2296. if (typeof (selectedMethod) === 'undefined' || selectedMethod.MethodId === '') {
  2297. $scope.creditCard = true;
  2298. $scope.creditCardErrorArr.push({ ErrorMessage: "Please select a payment method" });
  2299. return;
  2300. }
  2301.  
  2302. if (ngCart.getItems().length === 0) {
  2303. return;
  2304. }
  2305.  
  2306. if (!validateAddressFields(user, birthday)) {
  2307. return;
  2308. }
  2309.  
  2310. console.log('submit order', ngCart);
  2311.  
  2312. var mapper = new Mapper(ngCart.getCart(), "");
  2313. var data = mapper.ConfirmOrder();
  2314.  
  2315. console.log(data);
  2316.  
  2317. var personalDetails = {
  2318. MemberId: "{0}",
  2319. DateOfBirth: birthday,
  2320. Address: user.address,
  2321. City: user.city,
  2322. ZipCode: user.postalCode
  2323. };
  2324.  
  2325. if ($scope.toShowAddressFields) {
  2326. LottoyardService.updatePersonalDetails(JSON.stringify(personalDetails)).then(function (resp) {
  2327. if (resp.Result === "Personal details updated") {
  2328. submitOrder();
  2329. }
  2330. else {
  2331. $scope.creditCard = true;
  2332. $scope.creditCardErrorArr.push({
  2333. ErrorMessage: resp
  2334. });
  2335. }
  2336. });
  2337. } else {
  2338. submitOrder();
  2339. }
  2340.  
  2341. function submitOrder() {
  2342. LottoyardService.submitOrder(data).then(function (resp) {
  2343. $scope.creditCardErrorArr = [];
  2344. // ngCart.setBonusAmountToUse(0);
  2345. console.log(resp);
  2346. if (resp.IsSuccess) {
  2347. if (ngCart.getProcessor() !== 'CreditCard') {
  2348. if (resp.StatusCode === 0) {
  2349. $("#hiddenclicker").attr("href", resp.Url);
  2350. $("#hiddenclicker").fancybox(
  2351. {
  2352. 'width': '95%',
  2353. 'height': '95%',
  2354. 'autoScale': true,
  2355. 'transitionIn': 'elastic',
  2356. 'transitionOut': 'elastic',
  2357. 'speedIn': 600,
  2358. 'speedOut': 200,
  2359. 'type': 'iframe'
  2360. }).trigger("click");
  2361. } else {
  2362. $scope.creditCard = true;
  2363. if (Array.isArray(resp)) {
  2364. $scope.creditCardErrorArr.push({
  2365. ErrorMessage: resp.ErrorMessage
  2366. });
  2367. } else {
  2368. if (typeof resp.Status !== 'undefined') {
  2369. $scope.creditCardErrorArr.push({
  2370. ErrorMessage: resp.ErrorMessage
  2371. });
  2372. } else {
  2373. $scope.creditCardErrorArr.push({
  2374. ErrorMessage: resp
  2375. });
  2376. }
  2377. }
  2378. }
  2379. } else {
  2380. $rootScope.progress = true;
  2381. window.location = '/' + $rootScope.language + '/ThankYou2/Purchase/' + resp.Pmc + "/" + $rootScope.sessionId + "/" + 1 + "/";
  2382. }
  2383. } else {
  2384. if (resp.StatusCode === 0) {
  2385. $("#hiddenclicker").attr("href", resp.Url);
  2386. $("#hiddenclicker").fancybox(
  2387. {
  2388. 'width': '95%',
  2389. 'height': '95%',
  2390. 'autoScale': true,
  2391. 'transitionIn': 'elastic',
  2392. 'transitionOut': 'elastic',
  2393. 'speedIn': 600,
  2394. 'speedOut': 200,
  2395. 'type': 'iframe'
  2396. }).trigger("click");
  2397. } else {
  2398. $scope.creditCard = true;
  2399. if (Array.isArray(resp)) {
  2400. $scope.creditCardErrorArr.push({
  2401. ErrorMessage: resp[0].ErrorMessage
  2402. });
  2403. } else {
  2404. if (typeof resp.Status !== 'undefined') {
  2405. $scope.creditCardErrorArr.push({
  2406. ErrorMessage: resp.ErrorMessage
  2407. });
  2408. } else {
  2409. $scope.creditCardErrorArr.push({
  2410. ErrorMessage: resp
  2411. });
  2412. }
  2413. }
  2414. }
  2415. }
  2416. });
  2417. }
  2418. }
  2419.  
  2420. $scope.paymentMethodSelected = function paymentMethodSelected(_methodId, _processor) {
  2421. if (typeof (_methodId) !== 'undefined' && typeof (_processor) !== 'undefined') {
  2422. ngCart.setPaymentMethodId(_methodId);
  2423. ngCart.setProcessor(_processor);
  2424.  
  2425. $rootScope.$broadcast('ngCart:change', {});
  2426. console.log('methodId', _methodId);
  2427. }
  2428. }
  2429.  
  2430. $scope.subscriptionChanged = function (_id) {
  2431. var item = ngCart.getItemById(_id);
  2432. if (item.getIsSubscription()) {
  2433. item.setIsSubscription(false);
  2434. } else {
  2435. item.setIsSubscription(true);
  2436. }
  2437.  
  2438. $rootScope.$broadcast('ngCart:change', {});
  2439.  
  2440. $scope.$broadcast('ngCart:itemSubscriptionChanged', { itemid: _id });
  2441. console.log(ngCart);
  2442. }
  2443.  
  2444. $scope.fastProcessingChanged = function () {
  2445. ngCart.setIsFastProcessing(!ngCart.getIsFastProcessing());
  2446. $scope.fastProcessing = ngCart.getIsFastProcessing();
  2447. var items = ngCart.getItems();
  2448. angular.forEach(items, function (item) {
  2449. item.setIsFastProcessing(ngCart.getIsFastProcessing());
  2450. if (ngCart.getIsFastProcessing()) {
  2451. item.setTotalCost(item.getTotalCost() + ngCart.getFastProcessingTax());
  2452. if (ngCart.getAmountToPay() > 0) {
  2453. ngCart.setAmountToPay(ngCart.getAmountToPay() + ngCart.getFastProcessingTax());
  2454. }
  2455. } else {
  2456. item.setTotalCost(item.getTotalCost() - ngCart.getFastProcessingTax());
  2457. if (ngCart.getAmountToPay() > 0) {
  2458. ngCart.setAmountToPay(ngCart.getAmountToPay() - ngCart.getFastProcessingTax());
  2459. }
  2460. }
  2461.  
  2462. var mapper = new Mapper(ngCart.getCart());
  2463. var data = mapper.PrepareOrder();
  2464. LottoyardService.prepareOrder(data).then(function (resp) {
  2465. debugger;
  2466. if (resp.BonusAmountAvailable < ngCart.totalCost()) {
  2467. ngCart.setBonusAmountToUse(resp.BonusAmountAvailable);
  2468. } else {
  2469. ngCart.setBonusAmountToUse(ngCart.totalCost());
  2470. }
  2471. });
  2472. });
  2473.  
  2474. $rootScope.$broadcast('ngCart:change', {});
  2475. console.log(ngCart);
  2476. }
  2477.  
  2478. $scope.beforeCheckout = function ($event) {
  2479. $event.preventDefault();
  2480.  
  2481. console.log('before checkout');
  2482. beforeCheckOutCall();
  2483.  
  2484. window.location = $rootScope.cartUrlWithLang;
  2485.  
  2486. }
  2487.  
  2488. $scope.getRandomInt = getRandomInt;
  2489.  
  2490. $scope.addQuantity = function addQuantity(item) {
  2491. if (item.getQuantity() < 1) {
  2492. return;
  2493. }
  2494.  
  2495. item.setQuantity(item.getQuantity() + 1); //service.getProductPriceById = function (productId, draws, lotteryType
  2496.  
  2497. var priceForDraws = LottoyardService.getProductPriceById(item.getProductType(), item.getNumberOfDraws(), item.getLotteryType()).Price;
  2498. var price = priceForDraws * item.getQuantity();
  2499. var discount = 0;
  2500.  
  2501. item.setTotalCost(price - discount);
  2502. //discounts
  2503. item.setTotalDiscount();
  2504.  
  2505. $scope.initCart();
  2506. console.log(ngCart.getAmountToPay());
  2507. //$rootScope.$broadcast('ngCart:change', {});
  2508. }
  2509.  
  2510. $scope.removeQuantity = function removeQuantity(item) {
  2511. if (item.getQuantity() <= 1) {
  2512. return;
  2513. }
  2514. item.setQuantity(item.getQuantity() - 1);
  2515.  
  2516. var priceForDraws = LottoyardService.getProductPriceById(item.getProductType(), item.getNumberOfDraws(), item.getLotteryType()).Price;
  2517. var price = priceForDraws * item.getQuantity();
  2518. var discount = 0;
  2519.  
  2520. //var price = parseFloat(item.getOriginalPrice() * item.getQuantity() * item.getNumberOfDraws()).toFixed(2);
  2521. //var discount = parseFloat(price * item.getDiscount()).toFixed(2);
  2522.  
  2523. item.setTotalCost(price - discount);
  2524. //discounts
  2525. item.setTotalDiscount();
  2526.  
  2527. $scope.initCart();
  2528.  
  2529. // $rootScope.$broadcast('ngCart:change', {});
  2530. }
  2531.  
  2532. $scope.addShare = function addShare(item) {
  2533. if (item.getGroupnoshares() < 150) {
  2534. var currentShares = item.getGroupnoshares();
  2535. item.setGroupnoshares(currentShares + 1);
  2536. //calculate price
  2537.  
  2538. var data = LottoyardService.getProductPriceById(item.getProductType(), item.getGroupnodraws(), item.getLotteryType());
  2539.  
  2540. if (item.getGroupdiscount() > 0) {
  2541. var price = item.getGroupnoshares() * (data.Price + ((data.Price / (1 - item.getGroupdiscount())) * item.getGroupdiscount()));
  2542. var discount = item.getGroupdiscount() * price;
  2543. } else {
  2544. var price = item.getGroupnoshares() * data.Price;
  2545. var discount = item.getGroupdiscount() * price;
  2546. }
  2547.  
  2548. if (ngCart.getIsFastProcessing()) {
  2549. price += (data.Vip);
  2550. }
  2551. item.setTotalCost(price);
  2552.  
  2553. if ($scope.isAuthenticated && ngCart.getBonusAmountToUse() > 0) {
  2554. var bonus = getBonus();
  2555. ngCart.setBonusAmountToUse(bonus);
  2556. }
  2557. }
  2558.  
  2559. //discounts
  2560. item.setTotalDiscount(discount);
  2561. if (ngCart.getAmountToPay() == 0) {
  2562. ngCart.setAmountToPay(ngCart.totalCost());
  2563. }
  2564.  
  2565. $scope.initCart();
  2566. $rootScope.$broadcast('ngCart:change', {});
  2567. }
  2568.  
  2569. $scope.removeShare = function removeShare(item) {
  2570. if (item.getGroupnoshares() > 1) {
  2571. var currentShares = item.getGroupnoshares();
  2572. item.setGroupnoshares(currentShares - 1);
  2573.  
  2574. //calculate price
  2575. var data = LottoyardService.getProductPriceById(item.getProductType(), item.getGroupnodraws(), item.getLotteryType());
  2576.  
  2577. if (item.getGroupdiscount() > 0) {
  2578. var price = item.getGroupnoshares() * (data.Price + ((data.Price / (1 - item.getGroupdiscount())) * item.getGroupdiscount()));
  2579. var discount = item.getGroupdiscount() * price;
  2580. } else {
  2581. var price = item.getGroupnoshares() * data.Price;
  2582. var discount = item.getGroupdiscount() * price;
  2583. }
  2584.  
  2585. if (ngCart.getIsFastProcessing()) {
  2586. price += (data.Vip);
  2587. }
  2588. item.setTotalCost(price);
  2589.  
  2590. var bonus = getBonus();
  2591. ngCart.setBonusAmountToUse(bonus);
  2592.  
  2593. //discounts
  2594. item.setTotalDiscount(discount);
  2595. if (ngCart.getAmountToPay() == 0) {
  2596. ngCart.setAmountToPay(ngCart.totalCost());
  2597. }
  2598. }
  2599.  
  2600. $scope.initCart();
  2601.  
  2602. $rootScope.$broadcast('ngCart:change', {});
  2603. }
  2604.  
  2605.  
  2606.  
  2607. $scope.initpopuppromo = function (promo) {
  2608. if (promo) {
  2609. $scope.promoactive = true;
  2610. }
  2611. }
  2612.  
  2613. $scope.addLine = function addLine(item, lines, isInitCartCall) {
  2614.  
  2615. if (typeof lines === 'undefined') {
  2616. if (item.getEvenLinesOnly()) {
  2617. lines = item.getNumberOfLines() + 2;
  2618. } else {
  2619. lines = item.getNumberOfLines() + 1;
  2620. }
  2621. }
  2622.  
  2623. if (typeof isInitCartCall === 'undefined') {
  2624. isInitCartCall = true;
  2625. }
  2626.  
  2627. if (item.getMaxLines() > item.getNumberOfLines()) {
  2628. //generate random numbers
  2629. var generatedNumbers = [];
  2630. var generatedExtraNumbers = [];
  2631. var maxSelectNumber = item.getSelectNumbers();
  2632. var minSelectNumber = item.getMinSelectNumbers();
  2633. var minSelectExtraNumber = item.getExtraNumbers();
  2634. var maxSelectExtraNumber = item.getMaxExtraNumbers();
  2635.  
  2636. var itemToGenerate = item.getMaxSelectNumbers();
  2637.  
  2638. for (var i = item.getNumberOfLines() ; i < lines; i++) {
  2639. generatedNumbers = [];
  2640. while (generatedNumbers.length < itemToGenerate) {
  2641. var randomnumber = getRandomInt(minSelectNumber, maxSelectNumber);
  2642. var found = false;
  2643. for (var k = 0; k < generatedNumbers.length; k++) {
  2644. if (generatedNumbers[k] === randomnumber) {
  2645. found = true;
  2646. break;
  2647. }
  2648. }
  2649. if (!found) generatedNumbers[generatedNumbers.length] = randomnumber;
  2650. }
  2651.  
  2652. console.log('generatedNumbers', generatedNumbers);
  2653.  
  2654. //check if there are special numbers
  2655.  
  2656. //this is elgordo special numebr must be same
  2657. if (item.getLotteryType() === 10) {
  2658. var getFirstLine = item.getNumbersSantized()[0];
  2659. generatedExtraNumbers.push(getFirstLine.split('#')[1]);
  2660. } else {
  2661.  
  2662. if (item.getMaxExtraNumbers() > 0) {
  2663. var extraNumbersToGenerate = item.getMaxExtraNumbers();
  2664.  
  2665. while (generatedExtraNumbers.length < extraNumbersToGenerate) {
  2666. var randomnumber = getRandomInt(minSelectExtraNumber, maxSelectExtraNumber);
  2667. var found = false;
  2668. for (var k = 0; k < generatedExtraNumbers.length; k++) {
  2669. if (generatedExtraNumbers[k] === randomnumber) {
  2670. found = true;
  2671. break;
  2672. }
  2673. }
  2674. if (!found) generatedExtraNumbers[generatedExtraNumbers.length] = randomnumber;
  2675. }
  2676. }
  2677.  
  2678. console.log('generatedExtraNumbers', generatedExtraNumbers);
  2679. }
  2680. //store it to item
  2681.  
  2682. var newLinesToStore = item.getNumbers() + '|' + generatedNumbers.join(',');
  2683.  
  2684. if (generatedExtraNumbers.length > 0) {
  2685. newLinesToStore += '#' + generatedExtraNumbers.join(',');
  2686. }
  2687.  
  2688. console.log('newLinesToStore', newLinesToStore);
  2689.  
  2690. item.setNumberOfLines(item.getNumberOfLines() + 1);
  2691.  
  2692. //if is navidad - ignore it
  2693. if (item.getProductType() !== 15) {
  2694. item.setNumbers(newLinesToStore);
  2695. item.setNumbersSantized(newLinesToStore);
  2696. }
  2697. }
  2698.  
  2699. console.log(ngCart);
  2700. //calcualte prices
  2701. var data = LottoyardService.getProductPriceByIds(item.getProductType(), item.getNumberOfDraws(), item.getLotteryType(), item.getNumberOfLines());
  2702.  
  2703. if (item.getDiscount() > 0) {
  2704. var price = data.Price + ((data.Price / (1 - item.getDiscount())) * item.getDiscount());
  2705. var discount = item.getDiscount() * price;
  2706. } else {
  2707. var price = data.Price;
  2708. var discount = item.getDiscount() * price;
  2709. }
  2710.  
  2711. item.setTotalCost(price - discount);
  2712. //discounts
  2713. item.setTotalDiscount();
  2714. }
  2715. if (isInitCartCall) {
  2716. $scope.initCart();
  2717. }
  2718.  
  2719. $rootScope.$broadcast('ngCart:change', {});
  2720. }
  2721.  
  2722. $scope.removeLine = function removeLine(item) {
  2723. if (item.getMinLines() !== item.getNumberOfLines()) {
  2724.  
  2725. var lines = item._evenLinesOnly ? 2 : 1;
  2726.  
  2727. item.setNumberOfLines(item.getNumberOfLines() - lines);
  2728.  
  2729. for (var i = 0; i < lines; i++) {
  2730. item.removeLastLine();
  2731. }
  2732.  
  2733. //calculate prices
  2734. var data = LottoyardService.getProductPriceByIds(item.getProductType(), item.getNumberOfDraws(), item.getLotteryType(), item.getNumberOfLines());
  2735.  
  2736. if (item.getDiscount() > 0) {
  2737. var price = data.Price + ((data.Price / (1 - item.getDiscount())) * item.getDiscount());
  2738. var discount = item.getDiscount() * price;
  2739. } else {
  2740. var price = data.Price;
  2741. var discount = item.getDiscount() * price;
  2742. }
  2743.  
  2744.  
  2745. //var price = parseFloat(item.getOriginalPrice() * item.getNumberOfLines() * parseInt(item.getNumberOfDraws())).toFixed(2);
  2746. //var discount = parseFloat(price * item.getDiscount()).toFixed(2);
  2747. item.setTotalCost(price - discount);
  2748. } else if (item.getMinLines() === item.getNumberOfLines()) {
  2749. return;
  2750. }
  2751.  
  2752. $scope.initCart();
  2753.  
  2754. $rootScope.$broadcast('ngCart:change', {});
  2755. }
  2756.  
  2757. $scope.addDraw = function (item) {
  2758. var drawOptions = item.getProductsDrawOptions();
  2759.  
  2760. var currentDraw = 0;
  2761. if (item.getProductType() === 3) {
  2762. currentDraw = item.getGroupnodraws();
  2763. } else {
  2764. currentDraw = item.getNumberOfDraws();
  2765. }
  2766.  
  2767. var nextDraws = drawOptions.filter(function (obj) {
  2768. if ('NumberOfDraws' in obj && typeof (obj.NumberOfDraws) === 'number' && !isNaN(obj.NumberOfDraws) && obj.NumberOfDraws > currentDraw) {
  2769. return true;
  2770. } else {
  2771. return false;
  2772. }
  2773. });
  2774. var nextDraw = nextDraws[0];
  2775. addDraw(item, nextDraw);
  2776. }
  2777.  
  2778. $scope.removeDraw = function removeDraw(item) {
  2779.  
  2780. var drawOptionsNormal = item.getProductsDrawOptions();
  2781. var drawOptions = cleanArray(reverse(drawOptionsNormal));
  2782.  
  2783. var currentDraw = 0;
  2784.  
  2785. if (item.getSelectedTab() === "groupselection" || item.getProductType() === 3) {
  2786. currentDraw = item.getGroupnodraws();
  2787. } else {
  2788. currentDraw = item.getNumberOfDraws();
  2789. }
  2790.  
  2791. var nextDraws = drawOptions.filter(function (obj) {
  2792. if ('NumberOfDraws' in obj && typeof (obj.NumberOfDraws) === 'number' && !isNaN(obj.NumberOfDraws) && obj.NumberOfDraws < currentDraw) {
  2793. return true;
  2794. } else {
  2795. return false;
  2796. }
  2797. });
  2798.  
  2799. if (nextDraws.length > 1) {
  2800. nextDraws = nextDraws.sort(dynamicSortDescending('NumberOfDraws'));
  2801. }
  2802.  
  2803. var nextDraw = nextDraws[0];
  2804.  
  2805. if (typeof nextDraw !== 'undefined' && typeof (nextDraw.MinLines) !== 'undefined' && typeof (nextDraw.MaxLines) !== 'undefined') {
  2806. item.setMinLines(nextDraw.MinLines);
  2807. item.setMaxLines(nextDraw.MaxLines);
  2808. }
  2809.  
  2810. if (item.getProductType() !== 3) {
  2811. if (item.getMinLines() > item.getNumberOfLines()) {
  2812. console.log('generating new lines - remove draw');
  2813. if (item.getMinLines() > item.getNumberOfLines()) {
  2814. $scope.addLine(item, item.getMinLines(), false);
  2815. }
  2816. }
  2817.  
  2818.  
  2819. }
  2820.  
  2821. if (typeof nextDraw !== 'undefined') {
  2822.  
  2823. var price = 0;
  2824. var discount = 0;
  2825.  
  2826. if (item.getProductType() === 3) {
  2827. item.setGroupnodraws(nextDraw.NumberOfDraws);
  2828.  
  2829. var data = LottoyardService.getProductPriceById(item.getProductType(), nextDraw.NumberOfDraws, item.getLotteryType());
  2830.  
  2831. if (nextDraw.Discount > 0) {
  2832. price = item.getGroupnoshares() * (data.Price + ((data.Price / (1 - nextDraw.Discount)) * nextDraw.Discount));
  2833. discount = nextDraw.Discount * price;
  2834. } else {
  2835. price = item.getGroupnoshares() * data.Price;
  2836. discount = nextDraw.Discount * data.Price;
  2837. }
  2838.  
  2839. item.setGroupdiscount(nextDraw.Discount);
  2840.  
  2841. if ($scope.isAuthenticated) {
  2842. var bonus = getBonus();
  2843. ngCart.setBonusAmountToUse(bonus);
  2844. }
  2845.  
  2846. } else if (item.getProductType() === 2 || item.getProductType() === 4 || item.getProductType() === 14) {
  2847. //productId, draws, lotteryType
  2848. item.setNumberOfDraws(nextDraw.NumberOfDraws);
  2849.  
  2850. var data = LottoyardService.getProductPriceById(item.getProductType(), nextDraw.NumberOfDraws, item.getLotteryType());
  2851.  
  2852. price = data.Price * item.getQuantity();
  2853. discount = 0;
  2854.  
  2855. item.setDiscount(nextDraw.Discount);
  2856.  
  2857. } else if (item.getProductType() === 1) {
  2858. item.setNumberOfDraws(nextDraw.NumberOfDraws);
  2859.  
  2860. var data = LottoyardService.getProductPriceByIds(item.getProductType(), item.getNumberOfDraws(), item.getLotteryType(), item.getNumberOfLines());
  2861.  
  2862. if (nextDraw.Discount > 0) {
  2863. var price = data.Price + ((data.Price / (1 - nextDraw.Discount)) * nextDraw.Discount);
  2864. var discount = nextDraw.Discount * price;
  2865. } else {
  2866. var price = data.Price;
  2867. var discount = nextDraw.Discount * price;
  2868. }
  2869. item.setDiscount(nextDraw.Discount);
  2870. }
  2871.  
  2872. item.setTotalCost(price - discount);
  2873. item.setTotalDiscount(discount);
  2874. $scope.initCart();
  2875.  
  2876. $rootScope.$broadcast('ngCart:change', {});
  2877. }
  2878. }
  2879.  
  2880. $scope.addShareNavidad = function (item) {
  2881. if (item.getMaxLines() > item.getNumberOfLines()) {
  2882.  
  2883. item.setNumberOfLines(item.getNumberOfLines() + 1);
  2884. var price = item.getNumberOfLines() * item.getOriginalPrice();
  2885. var discount = item.getDiscount() * price;
  2886.  
  2887. item.setTotalCost(price - discount);
  2888.  
  2889. $scope.initCart();
  2890.  
  2891. $rootScope.$broadcast('ngCart:change', {});
  2892. }
  2893. }
  2894.  
  2895. $scope.removeShareNavidad = function (item) {
  2896. if (item.getMinLines() !== item.getNumberOfLines()) {
  2897. item.setNumberOfLines(item.getNumberOfLines() - 1);
  2898.  
  2899. var price = item.getNumberOfLines() * item.getOriginalPrice();
  2900. var discount = item.getDiscount() * price;
  2901.  
  2902. item.setTotalCost(price - discount);
  2903.  
  2904. $scope.initCart();
  2905.  
  2906. $rootScope.$broadcast('ngCart:change', {});
  2907. }
  2908. }
  2909.  
  2910. $scope.editLine = function editLine(index, item) {
  2911. $scope.ngDialogData = {
  2912. item: item,
  2913. line: index
  2914. };
  2915. ngDialog.open({
  2916. template: '/template/ngcart/addnumbers.html',
  2917. scope: $scope,
  2918. controller: $controller('EditLineDialogController', {
  2919. $scope: $scope
  2920. })
  2921. });
  2922.  
  2923. console.log(index, " ", item);
  2924. }
  2925.  
  2926. $scope.popuppromo = function () {
  2927. if ($scope.promoactive !== true) {
  2928. $scope.promoactive = true;
  2929. } else {
  2930. $scope.promoactive = false;
  2931. }
  2932. }
  2933.  
  2934. $scope.promoCodeValidator = function ($event) {
  2935. var key = $event.charCode || $event.keyCode || 0;
  2936. // Auto-format- do not expose the mask as the user begins to type
  2937. if (key !== 8 && key !== 9) {
  2938.  
  2939. if (typeof ($scope.promoCode) !== 'undefined' && $scope.promoCode !== null && $scope.promoCode.length === 3) {
  2940. $scope.promoCode += '-';
  2941. }
  2942. if (typeof ($scope.promoCode) !== 'undefined' && $scope.promoCode !== null && $scope.promoCode.length === 7) {
  2943. $scope.promoCode += '-';
  2944. }
  2945. }
  2946. }
  2947.  
  2948. $scope.showDetail = function (_id) {
  2949. if ($scope.active !== _id) {
  2950. $scope.active = _id;
  2951. } else {
  2952. $scope.active = null;
  2953. }
  2954. };
  2955.  
  2956. $scope.showthetooltip = function (_id) {
  2957. if ($scope.tooltipshown !== _id) {
  2958. $scope.tooltipshown = _id;
  2959. } else {
  2960. $scope.tooltipshown = null;
  2961. }
  2962. };
  2963.  
  2964. $scope.hidethetooltip = function (_id) {
  2965. $scope.tooltipshown = null;
  2966. };
  2967.  
  2968. $scope.showtooltipcart = function (_id) {
  2969. if ($scope.tooltipcart !== _id) {
  2970. $scope.tooltipcart = _id;
  2971. } else {
  2972. $scope.tooltipcart = null;
  2973. }
  2974. };
  2975.  
  2976. $scope.hidetooltipcart = function (_id) {
  2977. $scope.tooltipcart = null;
  2978. };
  2979.  
  2980. $scope.showtooltippay = function (_id) {
  2981. if ($scope.paycart !== _id) {
  2982. $scope.paycart = _id;
  2983. } else {
  2984. $scope.paycart = null;
  2985. }
  2986. };
  2987.  
  2988. $scope.hidetooltippay = function (_id) {
  2989. $scope.paycart = null;
  2990. };
  2991.  
  2992. $scope.submitPromoCode = function ($event, promoCode) {
  2993. $event.preventDefault();
  2994. //$scope.promoCode = null;
  2995. ngCart.setReedemCode(promoCode);
  2996. beforeCheckOutCall();
  2997. }
  2998.  
  2999. $scope.removePromoCode = function () {
  3000. ngCart.setReedemCode("");
  3001. beforeCheckOutCall();
  3002. $scope.popuppromo();
  3003. }
  3004.  
  3005. $scope.updateDaysInMonth = function (month, year) {
  3006. var daysInMonthValue = daysInMonth(parseInt(month), year);
  3007. if ($scope.user.birthday.day > daysInMonthValue) {
  3008. $scope.user.birthday.day = daysInMonthValue;
  3009. }
  3010. $scope.daysInMonth = makeArrayOfNumbers(daysInMonthValue);
  3011. }
  3012.  
  3013. //events
  3014. $scope.$on('ngCart:itemSubscriptionChanged', function (event, data) {
  3015. //get item
  3016. var item = ngCart.getItemById(data.itemid);
  3017. //get draw option
  3018. var drawOptions = item.getProductsDrawOptions();
  3019.  
  3020. //get current draw
  3021. var currentDraw = 0;
  3022. if (item.getSelectedTab() === 'groupselection' || item.getProductType() === 3) {
  3023. currentDraw = item.getGroupnodraws();
  3024. } else {
  3025. currentDraw = item.getNumberOfDraws();
  3026. }
  3027.  
  3028. //get nearest draw option in new subscription type
  3029. var drawOnlyArray = [];
  3030. angular.forEach(drawOptions, function (item) {
  3031. drawOnlyArray.push(item.NumberOfDraws);
  3032. });
  3033.  
  3034. var nextDrawOnly = closest(currentDraw, drawOnlyArray);
  3035.  
  3036. var nextDraw = drawOptions.filter(function (value) {
  3037. if (value.NumberOfDraws === nextDrawOnly) {
  3038. return true;
  3039. }
  3040. });
  3041.  
  3042. addDraw(item, nextDraw[0]);
  3043. console.log(data);
  3044. });
  3045.  
  3046. //private function
  3047. function _phoneValidation(phone) {
  3048. if (phone.trim() === '' || $scope.signupNumberIsChanged) {
  3049. $scope.InvalidPhoneErrorMessageSignUp = { display: 'none' };
  3050. return;
  3051. }
  3052.  
  3053. var phoneRegex = new RegExp(/^[0-9]{6,25}$/);
  3054. var isValidPhone = phone.match(phoneRegex)
  3055. if (!isValidPhone) {
  3056. $scope.InvalidPhoneErrorMessageSignUp = { display: 'block' };
  3057. } else {
  3058. $scope.InvalidPhoneErrorMessageSignUp = { display: 'none' };
  3059. }
  3060. }
  3061.  
  3062. function _passwordValidation(password) {
  3063. if (password.length == 0) {
  3064. $scope.InvalidPasswordErrorMessageSignUp = { display: 'none' };
  3065. return;
  3066. }
  3067.  
  3068. if (password.length < 7 || password.length > 20) {
  3069. $scope.InvalidPasswordErrorMessageSignUp = { display: 'block' };
  3070. } else {
  3071. $scope.InvalidPasswordErrorMessageSignUp = { display: 'none' };
  3072. }
  3073. }
  3074.  
  3075. function _fullnameValidation(fullname) {
  3076. if (fullname.trim() === '') {
  3077. $scope.InvalidFullnameErrorMessageSignUp = { display: 'none' };
  3078. return;
  3079. }
  3080.  
  3081. var fullnameRegex = new RegExp(/^[a-zа-я ]{2,20}$/ig);
  3082. var isValidFullname = fullname.match(fullnameRegex);
  3083. if (!isValidFullname) {
  3084. $scope.InvalidFullnameErrorMessageSignUp = { display: 'block' };
  3085. } else {
  3086. $scope.InvalidFullnameErrorMessageSignUp = { display: 'none' };
  3087. }
  3088. }
  3089.  
  3090. function _emailValidation(email) {
  3091. if (email.trim() === '') {
  3092. $scope.InvalidEmailErrorMessageSignUp = { display: 'none' };
  3093. return;
  3094. }
  3095.  
  3096. var emailRegex = new RegExp(/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/);
  3097. var isValidEmail = email.match(emailRegex)
  3098. if (!isValidEmail) {
  3099. $scope.InvalidEmailErrorMessageSignUp = { display: 'block' };
  3100. } else {
  3101. $scope.InvalidEmailErrorMessageSignUp = { display: 'none' };
  3102. }
  3103. }
  3104.  
  3105. function prepareOrderResponse(resp) {
  3106.  
  3107. ngCart.setIframePaymentMethods(resp.IframePaymentMethods);
  3108. //setting up default method id for drop down
  3109. if (resp.IframePaymentMethods.length > 0 && $scope.extraInfo == 'creditcard') {
  3110. $scope.selectedmethod = resp.IframePaymentMethods[0];
  3111. ngCart.setPaymentMethodId(resp.IframePaymentMethods[0].MethodId);
  3112. ngCart.setProcessor(resp.IframePaymentMethods[0].Processor);
  3113. }
  3114.  
  3115. var totalAmount = ngCart.totalCost();
  3116. if (totalAmount !== resp.AmountToPay) {
  3117. var amount = resp.AmountToPay < 0 ? 0 : resp.AmountToPay;
  3118. ngCart.setAmountToPay(amount);
  3119. console.log("warning prices missmatch!");
  3120. } else {
  3121. var amount = resp.AmountToPay < 0 ? 0 : resp.AmountToPay;
  3122. var bonusAmount = ngCart.getBonusAmountToUse();
  3123. var bonusRedeemCode = ngCart.getReedemBonusAmount();
  3124. if (amount > 0 && bonusAmount > 0 && $scope.model.isUsingBonusMoney) {
  3125. amount = amount - bonusAmount - bonusRedeemCode;
  3126. }
  3127. ngCart.setAmountToPay(amount);
  3128. }
  3129.  
  3130. //setting ReedemBonusAmount
  3131. ngCart.setReedemBonusAmount(resp.ReedemBonusAmount);
  3132. if (resp.ReedemBonusAmount > 0) {
  3133. $scope.redeemCodeOk = true;
  3134. $scope.redeemCodeWrong = false;
  3135.  
  3136. } else {
  3137. $scope.redeemCodeWrong = true;
  3138. $scope.redeemCodeOk = false;
  3139. }
  3140.  
  3141. $rootScope.$broadcast('ngCart:change', {});
  3142. console.log(ngCart);
  3143. }
  3144.  
  3145. function getBonus() {
  3146. var allPrices = ngCart.getItems().filter(function (item) {
  3147. return item.getProductType() == 3;
  3148. });
  3149.  
  3150. var total = 0;
  3151.  
  3152. allPrices.forEach(function (item) {
  3153. total += item.getTotalCost();
  3154. })
  3155.  
  3156. var bonus;
  3157.  
  3158. if (total <= ngCart.getBonusAmountToUse()) {
  3159. bonus = total;
  3160. }
  3161. else {
  3162. bonus = ngCart.getBonusAmountToUse();
  3163. }
  3164.  
  3165. if (bonus < 0) {
  3166. bonus = 0;
  3167. }
  3168.  
  3169. return bonus;
  3170. }
  3171.  
  3172. function clearPersonalInfo() {
  3173. ngCart.setAmountToPay(0);
  3174. ngCart.setIframePaymentMethods("");
  3175. ngCart.setIsFastProcessing(false);
  3176. ngCart.setPaymentMethodId("");
  3177. ngCart.setPhoneOrEmail("");
  3178. ngCart.setProcessor("");
  3179. ngCart.setBonusAmountToUse(0);
  3180. ngCart.setUseBonusmoney(false);
  3181.  
  3182. $rootScope.$broadcast('ngCart:change', {});
  3183. };
  3184.  
  3185. function closest(num, arr) {
  3186. var curr = arr[0];
  3187. var diff = Math.abs(num - curr);
  3188. for (var val = 0; val < arr.length; val++) {
  3189. var newdiff = Math.abs(num - arr[val]);
  3190. if (newdiff < diff) {
  3191. diff = newdiff;
  3192. curr = arr[val];
  3193. }
  3194. }
  3195. return curr;
  3196. }
  3197.  
  3198. function addDraw(item, nextDraw) {
  3199.  
  3200. if (typeof nextDraw !== 'undefined') {
  3201. var price = 0;
  3202. var discount = 0;
  3203. if (item.getSelectedTab() === "groupselection" || item.getProductType() === 3) {
  3204. item.setGroupnodraws(nextDraw.NumberOfDraws);
  3205. //calculate price
  3206. var data = LottoyardService.getProductPriceById(item.getProductType(), nextDraw.NumberOfDraws, item.getLotteryType());
  3207.  
  3208. if (nextDraw.Discount > 0) {
  3209. var test = item.getGroupnoshares();
  3210. price = item.getGroupnoshares() * (data.Price + ((data.Price / (1 - nextDraw.Discount)) * nextDraw.Discount));
  3211. discount = nextDraw.Discount * price;
  3212. } else {
  3213. price = item.getGroupnoshares() * data.Price;
  3214. discount = nextDraw.Discount * price;
  3215. }
  3216.  
  3217. item.setGroupdiscount(nextDraw.Discount);
  3218.  
  3219. if ($scope.isAuthenticated && ngCart.getBonusAmountToUse() > 0) {
  3220. var bonus = getBonus();
  3221. ngCart.setBonusAmountToUse(bonus);
  3222. }
  3223. } else if (item.getProductType() === 2 || item.getProductType() === 4 || item.getProductType() === 14) {
  3224. //productId, draws, lotteryType
  3225. var data = LottoyardService.getProductPriceById(item.getProductType(), nextDraw.NumberOfDraws, item.getLotteryType());
  3226. item.setNumberOfDraws(nextDraw.NumberOfDraws);
  3227.  
  3228. price = data.Price * item.getQuantity();
  3229. discount = 0;
  3230.  
  3231. item.setDiscount(nextDraw.Discount);
  3232.  
  3233. } else if (item.getProductType() === 1) {
  3234. item.setNumberOfDraws(nextDraw.NumberOfDraws);
  3235.  
  3236. //additional check for min lines according subscription rules
  3237. if (nextDraw.MinLines > item.getNumberOfLines()) {
  3238. $scope.addLine(item, nextDraw.MinLines, false);
  3239. }
  3240.  
  3241. //calculate price
  3242.  
  3243. var data = LottoyardService.getProductPriceByIds(item.getProductType(), item.getNumberOfDraws(), item.getLotteryType(), item.getNumberOfLines());
  3244.  
  3245. if (nextDraw.Discount > 0) {
  3246. var price = data.Price + ((data.Price / (1 - nextDraw.Discount)) * nextDraw.Discount);
  3247. var discount = nextDraw.Discount * price;
  3248. } else {
  3249. var price = data.Price;
  3250. var discount = nextDraw.Discount * price;
  3251. }
  3252.  
  3253. item.setDiscount(nextDraw.Discount);
  3254. }
  3255.  
  3256. item.setMinLines(nextDraw.MinLines);
  3257. item.setMaxLines(nextDraw.MaxLines);
  3258.  
  3259. item.setTotalCost(price - discount);
  3260.  
  3261. item.setTotalDiscount(discount);
  3262.  
  3263. $scope.initCart();
  3264.  
  3265. $rootScope.$broadcast('ngCart:change', {});
  3266. }
  3267. }
  3268.  
  3269. function beforeCheckOutCall() {
  3270. if (ngCart.getItems().length > 0) {
  3271. var data;
  3272.  
  3273. if ($scope.isAuthenticated) {
  3274. var mapper = new Mapper(ngCart.getCart());
  3275. data = mapper.PrepareOrder();
  3276. } else {
  3277. data = getPrepareOrderNotAutorizedUser();
  3278. }
  3279.  
  3280. LottoyardService.prepareOrder(data).then(function (resp) {
  3281. //setting up payment methods
  3282. prepareOrderResponse(resp);
  3283.  
  3284. $rootScope.$broadcast('ngCart:change', {});
  3285. });
  3286. }
  3287. }
  3288.  
  3289. function reverse(array) {
  3290. var result = [];
  3291. var i = null;
  3292. var arrLength = array.length;
  3293. for (i = arrLength - 1; i >= 0; i -= 1) {
  3294. result.push(array[i]);
  3295. }
  3296.  
  3297. return result;
  3298. }
  3299.  
  3300. function cleanArray(actual) {
  3301. var newArray = new Array();
  3302. for (var i = 0; i < actual.length; i++) {
  3303. if (actual[i]) {
  3304. newArray.push(actual[i]);
  3305. }
  3306. }
  3307. return newArray;
  3308. }
  3309.  
  3310. function paymentSelect() {
  3311. var mapper = new Mapper(ngCart.getCart());
  3312. var mappedCart = mapper.ConfirmOrder();
  3313. console.log('mappedCart', mappedCart);
  3314.  
  3315. LottoyardService.submitOrder(mappedCart).then(function (resp) {
  3316. console.log(resp);
  3317. if (resp.IsSuccess) {
  3318. $scope.progress = false;
  3319. window.location = '/' + $rootScope.language + '/ThankYou2/Purchase/' + resp.Pmc + "/" + $rootScope.sessionId + "/" + 1 + "/";
  3320.  
  3321. } else {
  3322. if (resp.StatusCode === 0 && resp.Status === 0) {
  3323. if (ngCart.getProcessor() === 'PayboutiqueYandex') {
  3324. $scope.status = false;
  3325. $window.open(resp.Url, '_blank');
  3326.  
  3327. } else {
  3328. $("#hiddenclicker").attr("href", resp.Url);
  3329. $("#hiddenclicker").fancybox(
  3330. {
  3331. 'width': '95%',
  3332. 'height': '95%',
  3333. 'autoScale': true,
  3334. 'transitionIn': 'elastic',
  3335. 'transitionOut': 'elastic',
  3336. 'speedIn': 600,
  3337. 'speedOut': 200,
  3338. 'type': 'iframe'
  3339. }).trigger("click");
  3340. }
  3341. } else {
  3342. $scope.creditCard = true;
  3343. $scope.creditCardError = resp.ErrorMessage;
  3344. $scope.paymentMethodError = true;
  3345. $scope.paymentMethodErrorText = resp.ErrorMessage;
  3346. }
  3347.  
  3348. }
  3349. });
  3350. };
  3351.  
  3352. function getRandomInt(min, max) {
  3353. return Math.floor(Math.random() * (max - min + 1)) + min;
  3354. };
  3355.  
  3356. function dynamicSortDescending(property) {
  3357. var sortOrder = 1;
  3358. if (property[0] === "-") {
  3359. sortOrder = -1;
  3360. property = property.substr(1);
  3361. }
  3362. return function (a, b) {
  3363. var result = (a[property] > b[property]) ? -1 : (a[property] < b[property]) ? 1 : 0;
  3364. return result * sortOrder;
  3365. }
  3366. }
  3367.  
  3368. function daysInMonth(month, year) {
  3369. return new Date(year, month, 0).getDate();
  3370. }
  3371.  
  3372. function makeArrayOfNumbers(numbers) {
  3373. return new Array(numbers).join().split(',').map(function (item, index) { return (index === 0 ? 1 : ++index); });
  3374. }
  3375.  
  3376. function validateEighteenYearsAge(date) {
  3377. var currentDate = new Date();
  3378. var dateToCheck = new Date(date);
  3379.  
  3380. //checking years
  3381. if ((currentDate.getFullYear() - dateToCheck.getFullYear()) > 18) {
  3382. return true;
  3383. }
  3384. if ((currentDate.getFullYear() - dateToCheck.getFullYear()) === 18) {
  3385. if (dateToCheck.getMonth() < currentDate.getMonth()) {
  3386. return true;
  3387. }
  3388. if (dateToCheck.getMonth() === currentDate.getMonth()) {
  3389. if ((currentDate.getDate() >= dateToCheck.getDate())) {
  3390. return true;
  3391. }
  3392. }
  3393. }
  3394.  
  3395. return false;
  3396. }
  3397.  
  3398. function validateAddressFields(user, birthday) {
  3399. if (typeof user === 'undefined') {
  3400. $scope.creditCard = true;
  3401. $scope.creditCardErrorArr.push({ ErrorMessage: "Enter additional data" });
  3402. return false;
  3403. }
  3404.  
  3405. if (typeof user.birthday === 'undefined' && (typeof user.birthday.day === 'undefined' || typeof user.birthday.month === 'undefined' || typeof user.birthday.year === 'undefined')) {
  3406. $scope.creditCard = true;
  3407. $scope.creditCardErrorArr.push({ ErrorMessage: "Please insert valid date of birth" });
  3408. return false;
  3409. }
  3410.  
  3411. if (!validateEighteenYearsAge(birthday)) {
  3412. $scope.creditCard = true;
  3413. $scope.creditCardErrorArr.push({ ErrorMessage: "TransactionDeclinedMustOver18" });
  3414. return false;
  3415. }
  3416.  
  3417. if (typeof user.city === 'undefined' || user.city.length < 3 || user.city.length > 35) {
  3418. $scope.creditCard = true;
  3419. $scope.creditCardErrorArr.push({ ErrorMessage: "Please insert valid city" });
  3420. return false;
  3421. }
  3422.  
  3423. if (typeof user.address === 'undefined' || user.address.length < 4 || user.address.length > 35) {
  3424. $scope.creditCard = true;
  3425. $scope.creditCardErrorArr.push({ ErrorMessage: "Please insert valid address" });
  3426. return false;
  3427. }
  3428.  
  3429. if (typeof user.postalCode === 'undefined' || user.postalCode.length < 3 || user.postalCode.length > 12) {
  3430. $scope.creditCard = true;
  3431. $scope.creditCardErrorArr.push({ ErrorMessage: "Please insert valid postal code" });
  3432. return false;
  3433. }
  3434. return true;
  3435. }
  3436.  
  3437. console.log(ngCart);
  3438. }
  3439. ])
  3440. .controller('RaffleController', [
  3441. '$rootScope', '$scope', 'ngCart', '$timeout', function ($rootScope, $scope, ngCart, $timeout) {
  3442.  
  3443. function Countdown(scope, item) {
  3444. var timer,
  3445. itemId = item.getId(),
  3446. instance = this,
  3447.  
  3448. counterEnd = function () {
  3449. $timeout(function () {
  3450. ngCart.removeItemById(itemId);
  3451.  
  3452. //var
  3453.  
  3454. $scope.initCart();
  3455. //angular.element('#navidad' + itemId).click();
  3456. }, 100);
  3457. };
  3458.  
  3459. function decrementCounter() {
  3460. if (scope.seconds <= 0) {
  3461. counterEnd();
  3462. instance.stop();
  3463. return;
  3464. }
  3465. scope.seconds--;
  3466. if (scope.seconds === 0) {
  3467. scope.isRefreshing = true;
  3468. }
  3469.  
  3470. angular.element('#timer' + itemId).text(convertDate(scope.seconds));
  3471. scope.$apply(); //update the view bindings
  3472. }
  3473.  
  3474. this.start = function () {
  3475. clearInterval(timer);
  3476. if (item.getProductExpire() === 0) {
  3477. return;
  3478. }
  3479. scope.seconds = item.getProductExpire();
  3480.  
  3481. angular.element('#timer' + itemId).text(convertDate(scope.seconds));
  3482.  
  3483. timer = setInterval(decrementCounter.bind(this.timer), 1000);
  3484. };
  3485.  
  3486. this.stop = function () {
  3487. clearInterval(timer);
  3488. }
  3489. }
  3490.  
  3491. var ct;
  3492. $scope.init = function (id) {
  3493. console.log("raffle counter init id:", id);
  3494. var itemCart = ngCart.getItemById(id);
  3495. //create a new event timer and start counting down
  3496. ct = new Countdown($scope, itemCart);
  3497. ct.start();
  3498. };
  3499.  
  3500. function convertDate(t) {
  3501. var days, hours, minutes, seconds;
  3502. //days = Math.floor(t / 86400);
  3503. //t -= days * 86400;
  3504. //hours = Math.floor(t / 3600) % 24;
  3505. //t -= hours * 3600;
  3506. minutes = Math.floor(t / 60) % 60;
  3507. t -= minutes * 60;
  3508. seconds = t % 60;
  3509. return [
  3510. //days + 'd',
  3511. //hours + 'h',
  3512. minutes + 'm',
  3513. seconds + 's'
  3514. ].join(' ');
  3515. };
  3516. }
  3517. ])
  3518. .controller('DepositController', [
  3519. '$rootScope', '$scope', 'ngCart', 'ngCart.lottoyard.api', 'ngCart.translationService', 'PaymentSystems', '$window', function ($rootScope, $scope, ngCart, LottoyardService, translationService, PaymentSystems, $window) {
  3520. $scope.ngCart = ngCart;
  3521. $scope.depositAmount = 0;
  3522. $scope.paymentSystems = PaymentSystems;
  3523. $scope.terms = false;
  3524. $scope.status = "";
  3525. $scope.statusclass = "";
  3526. $scope.section = { selectionPaymentTemplate: "" };
  3527. $scope.extraInfo = "creditcard";
  3528. $scope.promoCode = "";
  3529. $scope.creditcard = {};
  3530. var currentYear = new Date().getFullYear();
  3531. var legalAgeOfPlay = currentYear - 18;
  3532. $scope.currentYear = currentYear;
  3533. $scope.creditCardExpirationYears = new Array(11).join().split(',').map(function (item, index) { return (index === 0 ? $scope.currentYear : ++$scope.currentYear); });
  3534. $scope.creditCardExpirationMonths = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
  3535. $scope.birthdayYears = new Array(90).join().split(',').map(function (item, index) { return (legalAgeOfPlay - index); });
  3536. $scope.updatePaymentMethod = false;
  3537. $scope.methodId = 0;
  3538. $scope.user = {};
  3539. $scope.user.birthday = {};
  3540. $scope.user.birthday.day = 1;
  3541. $scope.user.birthday.month = $scope.creditCardExpirationMonths[0];
  3542. $scope.user.birthday.year = $scope.birthdayYears[0];
  3543. $scope.daysInMonth = makeArrayOfNumbers(daysInMonth(1, currentYear));
  3544. $scope.toShowAddressFields = false;
  3545.  
  3546. translationService.getTranslation($scope, $rootScope.language);
  3547.  
  3548. $scope.initDepositPage = function () {
  3549.  
  3550. if ($scope.isAuthenticated) {
  3551.  
  3552. var data = JSON.stringify({ MemberId: "{0}" });
  3553.  
  3554. LottoyardService.getPersonalDetailsByMemberId(data).then(function (resp) {
  3555. if (resp.City === "" || resp.Address === "" || resp.ZipCode === "") {
  3556. $scope.toShowAddressFields = true;
  3557. }
  3558. $scope.user.city = resp.City;
  3559. $scope.user.address = resp.Address;
  3560. $scope.user.postalCode = resp.ZipCode;
  3561.  
  3562. var birthdayDateApi = new Date(resp.DateOfBirth);
  3563. if (validateEighteenYearsAge(birthdayDateApi)) {
  3564. $scope.user.birthday.day = birthdayDateApi.getDate();
  3565. $scope.user.birthday.month = (birthdayDateApi.getMonth().toString().length === 1 && birthdayDateApi.getMonth() < 9) ? "0" + (birthdayDateApi.getMonth() + 1) : (birthdayDateApi.getMonth() + 1).toString();
  3566. $scope.user.birthday.year = birthdayDateApi.getFullYear();
  3567. $scope.daysInMonth = makeArrayOfNumbers(daysInMonth(parseInt($scope.user.birthday.month), currentYear));
  3568. }
  3569. });
  3570.  
  3571. LottoyardService.getMemberPaymentMethods(data).then(function (resp) {
  3572. ngCart.setIframePaymentMethods(resp);
  3573. //setting up default method id for drop down
  3574. if (resp.length > 0) {
  3575. $scope.selectedmethod = resp[0];
  3576. ngCart.setPaymentMethodId(resp[0].MethodId);
  3577. ngCart.setProcessor(resp[0].Processor);
  3578. }
  3579.  
  3580. if ($scope.isAuthenticated && ngCart.getIframePaymentMethods().length === 0) {
  3581. $scope.section.selectionPaymentTemplate = 'new';
  3582. } else if ($scope.isAuthenticated && ngCart.getIframePaymentMethods().length > 0) {
  3583. $scope.section.selectionPaymentTemplate = 'exist';
  3584. }
  3585. });
  3586. } else {
  3587. $scope.section.selectionPaymentTemplate = 'signup';
  3588. }
  3589. };
  3590.  
  3591. $rootScope.initPaymentUpdate = function (methodId) {
  3592. $scope.methodId = methodId;
  3593. var data = JSON.stringify({ MemberId: "{0}" });
  3594.  
  3595. LottoyardService.getPaymentMethod(data).then(function (resp) {
  3596. ngCart.setIframePaymentMethods(resp);
  3597. if (resp.length > 0) {
  3598. $scope.setPaymentMethod(resp, methodId);
  3599. }
  3600.  
  3601.  
  3602. });
  3603. };
  3604.  
  3605. $scope.deletePaymentMethod = function (memberId, processorId) {
  3606.  
  3607. var data = {
  3608. Id: memberId,
  3609. SessionId: "{0}",
  3610. MemberId: "{0}",
  3611. ProcessorApi: ngCart.getProcessor()
  3612. };
  3613.  
  3614. LottoyardService.deletePaymentMethod(JSON.stringify(data)).then(function (resp) {
  3615. console.log(resp);
  3616. if (resp.hasOwnProperty("Result")) {
  3617. window.location.replace('/my-account/paymentmethods');
  3618. } else {
  3619. return;
  3620. }
  3621. });
  3622.  
  3623. };
  3624.  
  3625. $scope.addPaymentMethod = function (creditcard) {
  3626. $scope.creditCardErrorArr = [];
  3627. $scope.creditCard = false;
  3628. // debugger;
  3629. if (!validateCreditCard(creditcard)) {
  3630. return;
  3631. }
  3632.  
  3633. var lastDay = new Date(parseInt(creditcard.expiration.year), parseInt(creditcard.expiration.month), 0).getDate();
  3634. var expirationDate = creditcard.expiration.year + "-" + creditcard.expiration.month + "-" + lastDay;
  3635.  
  3636. var data = {
  3637. Id: $scope.updatePaymentMethod ? $scope.methodId : 0,
  3638. SessionId: "{0}",
  3639. MemberId: "{0}",
  3640. ProcessorApi: ngCart.getProcessor(),
  3641. CardType: _getCreditCardType(creditcard.CreditCardNumber),
  3642. CreditCardNumber: $scope.updatePaymentMethod ? null : creditcard.CreditCardNumber,
  3643. Cvv: creditcard.Cvv,
  3644. ExpirationDate: expirationDate,
  3645. CardHolderName: creditcard.CardHolderName
  3646.  
  3647. };
  3648.  
  3649. LottoyardService.addPaymentMethod(JSON.stringify(data)).then(function (resp) {
  3650. console.log(resp);
  3651. if (resp.hasOwnProperty("Result")) {
  3652. window.location.replace('/my-account/paymentmethods');
  3653. } else {
  3654. $scope.creditCard = true;
  3655. $scope.creditCardErrorArr.push({ ErrorMessage: resp[0].ErrorMessage });
  3656. return;
  3657. }
  3658. });
  3659. };
  3660.  
  3661. $scope.setPaymentMethod = function (response, methodId) {
  3662. //debugger;
  3663. angular.forEach(response, function (obj, index) {
  3664. if (obj.Id == methodId) {
  3665. $scope.updatePaymentMethod = true;
  3666. $scope.creditcard.expiration = {};
  3667. $scope.creditcard.CardHolderName = obj.CardHolderName;
  3668. $scope.creditcard.CreditCardNumber = "************" + obj.CreditCardNumber;
  3669. $scope.creditcard.ExpirationDate = obj.ExpirationDate;
  3670. var date = new Date(obj.ExpirationDate);
  3671. $scope.creditcard.expiration.year = date.getFullYear();
  3672. $scope.creditcard.expiration.month = ("0" + (date.getMonth() + 1)).slice(-2);
  3673. $scope.creditcard.Cvv = obj.Cvv;
  3674. }
  3675. });
  3676. };
  3677.  
  3678. $scope.paymentMethodSelected = function (_methodId, _processor) {
  3679. ngCart.setPaymentMethodId(_methodId);
  3680. ngCart.setProcessor(_processor);
  3681.  
  3682. $rootScope.$broadcast('ngCart:change', {});
  3683. console.log('methodId', _methodId);
  3684. };
  3685.  
  3686. $scope.showtooltippay = function (_id) {
  3687. if ($scope.paycart !== _id) {
  3688. $scope.paycart = _id;
  3689. } else {
  3690. $scope.paycart = null;
  3691. }
  3692. };
  3693.  
  3694. $scope.hidetooltippay = function (_id) {
  3695. $scope.paycart = null;
  3696. };
  3697.  
  3698. $scope.depositFunds = function (selectedMethod, depositAmount, terms, user) {
  3699. $scope.creditCard = false;
  3700. $scope.creditCardErrorArr = [];
  3701.  
  3702. if (typeof user.birthday === 'undefined' && (typeof user.birthday.day === 'undefined' || typeof user.birthday.month === 'undefined' || typeof user.birthday.year === 'undefined')) {
  3703. $scope.creditCard = true;
  3704. $scope.creditCardErrorArr.push({ ErrorMessage: "Please insert valid date of birth" });
  3705. return;
  3706. }
  3707. var birthday = new Date(Date.UTC(user.birthday.year, (parseInt(user.birthday.month) - 1), user.birthday.day));
  3708.  
  3709. if (!terms) {
  3710. $scope.creditCard = true;
  3711. $scope.statusclass = "error";
  3712. $scope.creditCardErrorArr.push({ ErrorMessage: "Please accept our Terms and Conditions" });
  3713. return;
  3714. }
  3715.  
  3716. if (typeof (selectedMethod) === 'undefined' || selectedMethod.MethodId === '') {
  3717. $scope.creditCard = true;
  3718. $scope.statusclass = "error";
  3719. $scope.creditCardErrorArr.push({ ErrorMessage: "Please select a payment method!" });
  3720. return;
  3721. }
  3722.  
  3723. if (!isNumeric(depositAmount) || depositAmount < 5.00) {
  3724. $scope.creditCard = true;
  3725. $scope.statusclass = "error";
  3726. $scope.creditCardErrorArr.push({
  3727. ErrorMessage: "The Min Deposit Is 5.00EUR"
  3728. });
  3729. return;
  3730. }
  3731.  
  3732. if (!validateAddressFields(user, birthday)) {
  3733. $scope.statusclass = "error";
  3734. return;
  3735. }
  3736.  
  3737. var paymentMethodId = ngCart.getPaymentMethodId();
  3738.  
  3739. if (typeof (paymentMethodId) === 'undefined' || paymentMethodId == null || paymentMethodId === "") paymentMethodId = 0;
  3740.  
  3741. var data = {
  3742. SessionId: "{0}",
  3743. MemberId: "{0}",
  3744. PaymentMethodId: paymentMethodId,
  3745. Amount: depositAmount,
  3746. ProcessorApi: ngCart.getProcessor()
  3747. };
  3748. //updatePersonalDetails
  3749. var personalDetails = {
  3750. MemberId: "{0}",
  3751. DateOfBirth: birthday,
  3752. Address: user.address,
  3753. City: user.city,
  3754. ZipCode: user.postalCode
  3755. };
  3756. if ($scope.toShowAddressFields) {
  3757. LottoyardService.updatePersonalDetails(JSON.stringify(personalDetails)).then(function (resp) {
  3758. if (resp.Result === "Personal details updated") {
  3759. deposit();
  3760. } else {
  3761. $scope.statusclass = "error";
  3762. $scope.creditCard = true;
  3763. $scope.creditCardErrorArr.push({
  3764. ErrorMessage: resp.ErrorMessage
  3765. });
  3766. }
  3767. });
  3768. } else {
  3769. deposit();
  3770. }
  3771.  
  3772. function deposit() {
  3773. LottoyardService.depositFunds(JSON.stringify(data)).then(function (resp) {
  3774. console.log(resp);
  3775. if (resp.IsSuccess) {
  3776. $scope.status = resp.Status;
  3777. $scope.status = "Thank you , your deposit was successful!";
  3778. $scope.statusclass = "ok";
  3779. if (ngCart.getProcessor() !== 'CreditCard') {
  3780.  
  3781. $("#hiddenclicker").attr("href", resp.Url);
  3782. $("#hiddenclicker").fancybox(
  3783. {
  3784. 'width': '95%',
  3785. 'height': '95%',
  3786. 'autoScale': true,
  3787. 'transitionIn': 'elastic',
  3788. 'transitionOut': 'elastic',
  3789. 'speedIn': 600,
  3790. 'speedOut': 200,
  3791. 'type': 'iframe'
  3792. }).trigger("click");
  3793. } else {
  3794. $rootScope.progress = true;
  3795. sessionStorage.setItem("depositAmount", depositAmount);
  3796. window.location = '/' + $rootScope.language + '/ThankYou2/Purchase/' + 0 + "/" + $rootScope.sessionId + "/" + 1 + "/";
  3797. }
  3798.  
  3799. } else {
  3800. $scope.statusclass = "error";
  3801. $scope.creditCard = true;
  3802. if (Array.isArray(resp)) {
  3803. $scope.creditCardErrorArr.push({
  3804. ErrorMessage: resp[0].ErrorMessage
  3805. });
  3806. } else {
  3807. $scope.creditCardErrorArr.push({
  3808. ErrorMessage: resp.ErrorMessage
  3809. });
  3810. }
  3811.  
  3812. }
  3813. });
  3814. }
  3815. };
  3816.  
  3817. $scope.paymentSelect = function (payment) {
  3818. if ($scope.isAuthenticated && payment.name == 'creditcard' && ($scope.creditCard == true || typeof $scope.creditCard == "undefined")) {
  3819. $scope.section.selectionPaymentTemplate = 'exist';
  3820. } else if ($scope.isAuthenticated) {
  3821. $scope.section.selectionPaymentTemplate = 'new';
  3822. }
  3823. console.log(payment);
  3824. ngCart.setProcessor(payment.processor);
  3825. $scope.status = "";
  3826. $scope.extraInfo = payment.name;
  3827. }
  3828.  
  3829. $scope.submitOrderNewCreditCard = function (creditcard, depositAmount, user) {
  3830. $scope.creditCardError = "";
  3831. $scope.creditCardErrorArr = [];
  3832. $scope.creditCard = false;
  3833.  
  3834. if (typeof user.birthday === 'undefined' && (typeof user.birthday.day === 'undefined' || typeof user.birthday.month === 'undefined' || typeof user.birthday.year === 'undefined')) {
  3835. $scope.creditCard = true;
  3836. $scope.creditCardErrorArr.push({
  3837. ErrorMessage: "Please insert valid date of birth"
  3838. });
  3839. return;
  3840. }
  3841. var birthday = new Date(Date.UTC(user.birthday.year, (parseInt(user.birthday.month) - 1), user.birthday.day));
  3842.  
  3843. if (!validateCreditCard(creditcard)) {
  3844. return;
  3845. }
  3846.  
  3847. if (!validateAddressFields(user, birthday)) {
  3848. return;
  3849. }
  3850. if (!isNumeric(depositAmount)) {
  3851. $scope.creditCard = true;
  3852. $scope.creditCardErrorArr.push({
  3853. ErrorMessage: "The Min Deposit Is 5.00EUR"
  3854. });
  3855. return;
  3856. }
  3857. var lastDay = new Date(parseInt(creditcard.expiration.year), parseInt(creditcard.expiration.month), 0).getDate();
  3858. var expirationDate = creditcard.expiration.year + "-" + creditcard.expiration.month + "-" + lastDay;
  3859. creditcard.ExpirationDate = expirationDate;
  3860. ngCart.setProcessor("CreditCard");
  3861. console.log(creditcard);
  3862.  
  3863. var data = {
  3864. SessionId: "{0}",
  3865. MemberId: "{0}",
  3866. Amount: depositAmount,
  3867. ProcessorApi: ngCart.getProcessor(),
  3868. CreditCard: {
  3869. CardType: _getCreditCardType(creditcard.CreditCardNumber),
  3870. CreditCardNumber: creditcard.CreditCardNumber,
  3871. Cvv: creditcard.Cvv,
  3872. ExpirationDate: expirationDate,
  3873. CardHolderName: creditcard.CardHolderName
  3874. }
  3875. };
  3876. //updatePersonalDetails
  3877. var personalDetails = {
  3878. MemberId: "{0}",
  3879. DateOfBirth: birthday,
  3880. Address: user.address,
  3881. City: user.city,
  3882. ZipCode: user.postalCode
  3883. };
  3884.  
  3885. LottoyardService.updatePersonalDetails(JSON.stringify(personalDetails)).then(function (resp) {
  3886. //debugger;
  3887. if (resp.Result === "Personal details updated") {
  3888.  
  3889. LottoyardService.depositFunds(JSON.stringify(data)).then(function (resp) {
  3890. //debugger;
  3891. if (resp.IsSuccess) {
  3892.  
  3893. window.location = '/' + $rootScope.language + '/ThankYou2/Purchase/' + 0 + "/" + $rootScope.sessionId + "/" + 1 + "/";
  3894. } else {
  3895. $scope.creditCard = true;
  3896. $scope.creditCardErrorArr.push({ ErrorMessage: resp.ErrorMessage });
  3897. return;
  3898. }
  3899. });
  3900. } else {
  3901. $scope.creditCard = true;
  3902. $scope.creditCardErrorArr.push({ ErrorMessage: resp.ErrorMessage });
  3903. return;
  3904. }
  3905. });
  3906. }
  3907.  
  3908. $scope.paymentSelectMoreInfo = function ($event, phoneOrEmail, amountToDeposit) {
  3909. $event.preventDefault();
  3910. //debugger;
  3911. console.log(phoneOrEmail);
  3912.  
  3913. ngCart.setPhoneOrEmail(phoneOrEmail);
  3914.  
  3915. paymentSelect(amountToDeposit);
  3916.  
  3917. }
  3918.  
  3919. $scope.editPaymentMethods = function () {
  3920. $scope.creditCard = false;
  3921. $scope.section.selectionPaymentTemplate = 'new';
  3922. }
  3923.  
  3924. $scope.updateDaysInMonth = function (month, year) {
  3925. var daysInMonthValue = daysInMonth(parseInt(month), year);
  3926. if ($scope.user.birthday.day > daysInMonthValue) {
  3927. $scope.user.birthday.day = daysInMonthValue;
  3928. }
  3929. $scope.daysInMonth = makeArrayOfNumbers(daysInMonthValue);
  3930. }
  3931.  
  3932. function daysInMonth(month, year) {
  3933. return new Date(year, month, 0).getDate();
  3934. }
  3935.  
  3936. function makeArrayOfNumbers(numbers) {
  3937. return new Array(numbers).join().split(',').map(function (item, index) { return (index === 0 ? 1 : ++index); });
  3938. }
  3939.  
  3940. function validateEighteenYearsAge(date) {
  3941. // debugger;
  3942. var currentDate = new Date();
  3943. var dateToCheck = new Date(date);
  3944.  
  3945. //checking years
  3946. if ((currentDate.getFullYear() - dateToCheck.getFullYear()) > 18) {
  3947. return true;
  3948. }
  3949. if ((currentDate.getFullYear() - dateToCheck.getFullYear()) === 18) {
  3950. if (dateToCheck.getMonth() < currentDate.getMonth()) {
  3951. return true;
  3952. }
  3953. if (dateToCheck.getMonth() === currentDate.getMonth()) {
  3954. if ((currentDate.getDate() >= dateToCheck.getDate())) {
  3955. return true;
  3956. }
  3957. }
  3958. }
  3959.  
  3960. return false;
  3961. }
  3962.  
  3963. function validateCreditCard(creditcard, expirationDate) {
  3964. if (typeof (creditcard) === 'undefined') {
  3965. $scope.creditCard = true;
  3966. $scope.creditCardErrorArr.push({ ErrorMessage: "MissingCreditCard" });
  3967. return false;
  3968. }
  3969.  
  3970. if (!$scope.updatePaymentMethod) {
  3971.  
  3972. if (!creditcard.terms) {
  3973. $scope.creditCard = true;
  3974. $scope.creditCardErrorArr.push({ ErrorMessage: "Please accept our Terms and Conditions" });
  3975. return false;
  3976. }
  3977.  
  3978. if (typeof (creditcard.CreditCardNumber) === 'undefined' || creditcard.CreditCardNumber.length == 0) {
  3979. $scope.creditCard = true;
  3980. $scope.creditCardErrorArr.push({ ErrorMessage: "MissingCreditCard" });
  3981. return false;
  3982. }
  3983.  
  3984. if (typeof (creditcard.CreditCardNumber) === 'undefined' || creditcard.CreditCardNumber.length < 10) {
  3985. $scope.creditCard = true;
  3986. $scope.creditCardErrorArr.push({ ErrorMessage: "Credit card number length is invalid" });
  3987. return false;
  3988. }
  3989. }
  3990.  
  3991. if (typeof (creditcard.CardHolderName) === 'undefined' || creditcard.CardHolderName.length < 2) {
  3992. $scope.creditCard = true;
  3993. $scope.creditCardErrorArr.push({ ErrorMessage: "Please type your full name" });
  3994. return false;
  3995. }
  3996.  
  3997. if (typeof (creditcard.expiration) === 'undefined') {
  3998. $scope.creditCard = true;
  3999. $scope.creditCardErrorArr.push({ ErrorMessage: "Please insert Expiration Date" });
  4000. return false;
  4001. }
  4002.  
  4003. if (typeof (creditcard.expiration.year) === 'undefined') {
  4004. $scope.creditCard = true;
  4005. $scope.creditCardErrorArr.push({ ErrorMessage: "Please insert Expiration Year" });
  4006. return false;
  4007. }
  4008.  
  4009. if (typeof (creditcard.expiration.month) === 'undefined') {
  4010. $scope.creditCard = true;
  4011. $scope.creditCardErrorArr.push({ ErrorMessage: "Please insert Expiration Month" });
  4012. return false;
  4013. }
  4014.  
  4015. if (typeof (creditcard.Cvv) === 'undefined' || creditcard.Cvv.length < 2) {
  4016. $scope.creditCard = true;
  4017. $scope.creditCardErrorArr.push({ ErrorMessage: "Please insert your cvv number" });
  4018. return false;
  4019. }
  4020.  
  4021. var lastDay = new Date(parseInt(creditcard.expiration.year), parseInt(creditcard.expiration.month), 0).getDate();
  4022. var expirationDate = creditcard.expiration.year + "-" + creditcard.expiration.month + "-" + lastDay;
  4023.  
  4024. var today = new Date();
  4025. today.setHours(0, 0, 0, 0);
  4026.  
  4027. var creditCardDate = new Date(expirationDate);
  4028. creditCardDate.setHours(0, 0, 0, 0);
  4029.  
  4030. if (creditCardDate < today) {
  4031. $scope.creditCard = true;
  4032. $scope.creditCardErrorArr.push({ ErrorMessage: "Please enter valid card expiration date" });
  4033. return false;
  4034. }
  4035. return true;
  4036. }
  4037.  
  4038. function isNumeric(obj) {
  4039. return !isNaN(parseFloat(obj)) && isFinite(obj);
  4040. }
  4041.  
  4042. function paymentSelect(amountToDeposit) {
  4043.  
  4044. if (typeof (amountToDeposit) === 'undefined') {
  4045. amountToDeposit = 0;
  4046. }
  4047.  
  4048. var paymentMethodId = ngCart.getPaymentMethodId();
  4049.  
  4050. if (typeof (paymentMethodId) === 'undefined' || paymentMethodId == null || paymentMethodId === "") paymentMethodId = 0;
  4051.  
  4052. var data = {
  4053. SessionId: "{0}",
  4054. MemberId: "{0}",
  4055. PaymentMethodId: paymentMethodId,
  4056. Amount: amountToDeposit,
  4057. ProcessorApi: ngCart.getProcessor(),
  4058. PhoneOrEmail: ngCart.getPhoneOrEmail()
  4059. };
  4060.  
  4061. LottoyardService.depositFunds(JSON.stringify(data)).then(function (resp) {
  4062. $scope.status = false;
  4063. $scope.statusArr = [];
  4064. if (resp.IsSuccess) {
  4065. $scope.status = true;
  4066. if (Array.isArray(resp.Status)) {
  4067. $scope.statusArr = resp.Status;
  4068. } else {
  4069. $scope.statusArr.push({ ErrorMessage: resp.Status });
  4070. }
  4071. if (ngCart.getProcessor() === 'PayboutiqueYandex') {
  4072. $scope.status = false;
  4073. $window.open(resp.Url, '_blank');
  4074.  
  4075. } else if (ngCart.getProcessor() !== 'CreditCard') {
  4076. $scope.status = false;
  4077. $("#hiddenclicker").attr("href", resp.Url);
  4078. $("#hiddenclicker").fancybox(
  4079. {
  4080. 'width': '95%',
  4081. 'height': '95%',
  4082. 'autoScale': true,
  4083. 'transitionIn': 'elastic',
  4084. 'transitionOut': 'elastic',
  4085. 'speedIn': 600,
  4086. 'speedOut': 200,
  4087. 'type': 'iframe'
  4088. }).trigger("click");
  4089. } else {
  4090. window.location = '/' + $rootScope.language + '/ThankYou2/Purchase/' + 0 + "/" + $rootScope.sessionId + "/" + 1 + "/";
  4091. }
  4092.  
  4093. } else {
  4094. $scope.status = true;
  4095. if (Array.isArray(resp.Status)) {
  4096. $scope.statusArr = resp.ErrorMessage;
  4097. } else {
  4098. $scope.statusArr.push({ ErrorMessage: resp.ErrorMessage });
  4099. }
  4100. }
  4101. });
  4102. };
  4103.  
  4104. function validateAddressFields(user, birthday) {
  4105.  
  4106. if (typeof user === 'undefined') {
  4107. $scope.creditCard = true;
  4108. $scope.creditCardErrorArr.push({ ErrorMessage: "Enter additional data" });
  4109. return false;
  4110. }
  4111.  
  4112. if (typeof user.birthday === 'undefined' && (typeof user.birthday.day === 'undefined' || typeof user.birthday.month === 'undefined' || typeof user.birthday.year === 'undefined')) {
  4113. $scope.creditCard = true;
  4114. $scope.creditCardErrorArr.push({ ErrorMessage: "Please insert valid date of birth" });
  4115. return false;
  4116. }
  4117.  
  4118. if (!validateEighteenYearsAge(birthday)) {
  4119. $scope.creditCard = true;
  4120. $scope.creditCardErrorArr.push({ ErrorMessage: "TransactionDeclinedMustOver18" });
  4121. return false;
  4122. }
  4123.  
  4124. if (typeof user.city === 'undefined' || user.city.length < 3 || user.city.length > 35) {
  4125. $scope.creditCard = true;
  4126. $scope.creditCardErrorArr.push({ ErrorMessage: "Please insert valid city" });
  4127. return false;
  4128. }
  4129.  
  4130. if (typeof user.address === 'undefined' || user.address.length < 4 || user.address.length > 35) {
  4131. $scope.creditCard = true;
  4132. $scope.creditCardErrorArr.push({ ErrorMessage: "Please insert valid address" });
  4133. return false;
  4134. }
  4135.  
  4136. if (typeof user.postalCode === 'undefined' || user.postalCode.length < 3 || user.postalCode.length > 12) {
  4137. $scope.creditCard = true;
  4138. $scope.creditCardErrorArr.push({ ErrorMessage: "Please insert valid postal code" });
  4139. return false;
  4140. }
  4141.  
  4142. return true;
  4143. }
  4144.  
  4145. }
  4146. ])
  4147. .controller('EditLineDialogController', [
  4148. '$scope', function ($scope) {
  4149. // debugger;
  4150. var item = $scope.ngDialogData.item;
  4151. var line = $scope.ngDialogData.line;
  4152. $scope.isValidSelectLine = true;
  4153. $scope.isValidExtraLine = true;
  4154.  
  4155. console.log('line', line);
  4156. line++;
  4157. $scope.line = line;
  4158. $scope.item = item;
  4159. console.log('line', line);
  4160. console.log('$scope.line', $scope.line);
  4161.  
  4162. $scope.clickNumber = function (number) {
  4163. // debugger;
  4164.  
  4165. var minSelectNumbers = item.getMinSelectNumbers();
  4166. var maxSelectNumbers = item.getMaxSelectNumbers();
  4167.  
  4168. var totalSelectNumbers = countSelectedNumbersInArray($scope.selectedNumbers);
  4169.  
  4170. console.log('totalSelectNumbers', totalSelectNumbers);
  4171.  
  4172. if (totalSelectNumbers < maxSelectNumbers) {
  4173. if (number.isSelected) {
  4174. number.isSelected = 0;
  4175. } else {
  4176. number.isSelected = 1;
  4177. }
  4178. } else {
  4179. if (number.isSelected) {
  4180. number.isSelected = 0;
  4181. }
  4182. }
  4183.  
  4184. totalSelectNumbers = countSelectedNumbersInArray($scope.selectedNumbers);
  4185.  
  4186. if (totalSelectNumbers < minSelectNumbers) {
  4187. $scope.isValidSelectLine = false;
  4188. } else {
  4189. $scope.isValidSelectLine = true;
  4190. }
  4191. }
  4192.  
  4193. $scope.clickNumberExtra = function (number) {
  4194. //debugger;
  4195. $scope.isValidExtraLine = true;
  4196. var minExtraSelectNumbers = item.getMinExtraNumber();
  4197. var maxExtraSelectNumbers = item.getMaxExtraNumbers();
  4198.  
  4199. var totalExtraSelectNumbers = countSelectedNumbersInArray($scope.selectedNumbersExtra);
  4200.  
  4201. console.log('totalExtraSelectNumbers', totalExtraSelectNumbers);
  4202.  
  4203. if (totalExtraSelectNumbers < maxExtraSelectNumbers) {
  4204. if (number.isSelected) {
  4205. number.isSelected = 0;
  4206. } else {
  4207. number.isSelected = 1;
  4208. }
  4209. } else {
  4210. if (number.isSelected) {
  4211. number.isSelected = 0;
  4212. }
  4213. }
  4214.  
  4215. totalExtraSelectNumbers = countSelectedNumbersInArray($scope.selectedNumbersExtra);
  4216.  
  4217. if (minExtraSelectNumbers !== 0) {
  4218. if (totalExtraSelectNumbers === 0) {
  4219. $scope.isValidExtraLine = false;
  4220. } else if (minExtraSelectNumbers > totalExtraSelectNumbers || totalExtraSelectNumbers < maxExtraSelectNumbers) {
  4221. $scope.isValidExtraLine = false;
  4222. }
  4223. }
  4224.  
  4225.  
  4226. //$scope.isValidLine = true;
  4227. console.log('totalExtraSelectNumbers', totalExtraSelectNumbers);
  4228. }
  4229.  
  4230. function countSelectedNumbersInArray(arr) {
  4231. var totalSelectNumbers = 0;
  4232. arr.filter(function (value) {
  4233. if (value.isSelected) {
  4234. totalSelectNumbers++;
  4235. return false;
  4236. } else {
  4237. return true;
  4238. }
  4239. });
  4240.  
  4241. return totalSelectNumbers;
  4242. }
  4243.  
  4244. function clearSelectedNumbersInArray(arr) {
  4245. return arr.filter(function (value) {
  4246. if (value.isSelected) {
  4247. value.isSelected = 0;
  4248. return false;
  4249. } else {
  4250. return true;
  4251. }
  4252. });
  4253. }
  4254.  
  4255. $scope.checkInput = function (_line) {
  4256. console.log('checkInput');
  4257. //debugger;
  4258. //imame item i line
  4259. var selectedNumbers = countSelectedNumbersInArray($scope.selectedNumbers);
  4260. var selectedExtraNumbers = countSelectedNumbersInArray($scope.selectedNumbersExtra);
  4261. var maxSelectNumbers = item.getMaxSelectNumbers();
  4262.  
  4263. if (selectedNumbers !== maxSelectNumbers) {
  4264. $scope.isValidSelectLine = false;
  4265. return false;
  4266. }
  4267.  
  4268. //todo check if there is extra numvbers
  4269. if (selectedExtraNumbers > 0 || selectedExtraNumbers !== item.getMaxExtraNumbers()) {
  4270. if (selectedExtraNumbers !== item.getMaxExtraNumbers()) {
  4271. $scope.isValidExtraLine = false;
  4272. return false;
  4273. }
  4274. }
  4275.  
  4276. if ($scope.isValidSelectLine && $scope.isValidExtraLine) {
  4277. var currentLineToUpdate = item.getNumbersSantized()[_line];
  4278. console.log(currentLineToUpdate);
  4279.  
  4280. var newLine = [];
  4281.  
  4282. $scope.selectedNumbers.filter(function (value) {
  4283. if (value.isSelected) {
  4284. newLine.push(value.id);
  4285. return false;
  4286. } else {
  4287. return true;
  4288. }
  4289.  
  4290. });
  4291.  
  4292. var newLineToUpdate = newLine.join(',');
  4293.  
  4294. if ($scope.selectedNumbersExtra.length > 0) {
  4295. var newExtraLine = [];
  4296.  
  4297. $scope.selectedNumbersExtra.filter(function (value) {
  4298. if (value.isSelected) {
  4299. newExtraLine.push(value.id);
  4300. return false;
  4301. } else {
  4302. return true;
  4303. }
  4304.  
  4305. });
  4306.  
  4307. newLineToUpdate += '#' + newExtraLine.join(',');
  4308.  
  4309. //elgordo update all lines with same special numbers
  4310. if (item.getLotteryType() === 10) {
  4311. var allLines = item.getNumbersSantized();
  4312.  
  4313. angular.forEach(allLines, function (line, index) {
  4314.  
  4315. var splittedLine = line.split('#');
  4316. var oldLine = splittedLine[0];
  4317. var extraNumber = newExtraLine[0];
  4318. var lineToUpdate = oldLine + '#' + extraNumber;
  4319.  
  4320. item.updateSantizedLine(lineToUpdate, index + 1);
  4321.  
  4322. });
  4323. }
  4324. }
  4325.  
  4326. console.log(newLineToUpdate);
  4327. item.updateSantizedLine(newLineToUpdate, _line);
  4328. }
  4329. return true;
  4330. }
  4331.  
  4332. $scope.clearLine = function () {
  4333. clearSelectedNumbersInArray($scope.selectedNumbers);
  4334. clearSelectedNumbersInArray($scope.selectedNumbersExtra);
  4335.  
  4336. $scope.isValidSelectLine = false;
  4337. }
  4338.  
  4339. $scope.quickpick = function (line) {
  4340. // debugger;
  4341. clearSelectedNumbersInArray($scope.selectedNumbers);
  4342. clearSelectedNumbersInArray($scope.selectedNumbersExtra);
  4343.  
  4344. var maxSelectNumbers = item.getMaxSelectNumbers();
  4345. var maxSelectExtraNumbers = item.getMaxExtraNumbers();
  4346. var startNumber = item.getMinSelectNumbers();
  4347. var startExtraNumber = item.getMinExtraNumber();
  4348. var endNumber = item.getSelectNumbers();
  4349. var endExtraNumbers = item.getExtraNumbers();
  4350.  
  4351. while (countSelectedNumbersInArray($scope.selectedNumbers) < maxSelectNumbers) {
  4352. var number = $scope.getRandomInt(startNumber, endNumber - 1);
  4353.  
  4354. var objNumber = {
  4355. id: 1,
  4356. isSelected: 0
  4357. }
  4358. objNumber.id = number;
  4359. objNumber.isSelected = 1;
  4360. console.log(objNumber);
  4361. console.log('number', number);
  4362. $scope.selectedNumbers[number - 1] = objNumber;
  4363. }
  4364.  
  4365.  
  4366. if (maxSelectExtraNumbers > 0) {
  4367. while (countSelectedNumbersInArray($scope.selectedNumbersExtra) < maxSelectExtraNumbers) {
  4368. var numberExtra = $scope.getRandomInt(startExtraNumber, endExtraNumbers - 1);
  4369.  
  4370. var objNumberExtra = {
  4371. id: 1,
  4372. isSelected: 0
  4373. }
  4374. objNumberExtra.id = numberExtra;
  4375. objNumberExtra.isSelected = 1;
  4376. console.log(objNumberExtra);
  4377. console.log('numberExtra', numberExtra);
  4378. if (item.getLotteryType() === 10) {
  4379. $scope.selectedNumbersExtra[numberExtra] = objNumberExtra;
  4380. } else {
  4381. $scope.selectedNumbersExtra[numberExtra - 1] = objNumberExtra;
  4382. }
  4383.  
  4384. }
  4385. }
  4386. console.log($scope.selectedNumbers);
  4387. console.log($scope.selectedNumbersExtra);
  4388.  
  4389. var selectedNumbers = countSelectedNumbersInArray($scope.selectedNumbers);
  4390. var selectedExtraNumbers = countSelectedNumbersInArray($scope.selectedNumbersExtra);
  4391.  
  4392. if (selectedNumbers === maxSelectNumbers) {
  4393. $scope.isValidSelectLine = true;
  4394. }
  4395. if (selectedExtraNumbers === maxSelectExtraNumbers) {
  4396. $scope.isValidExtraLine = true;
  4397. }
  4398. }
  4399. //debugger;
  4400. line -= 1;
  4401. var selectNumbers = item.getSelectNumbers()
  4402. var selectNumbersExtra = item.getExtraNumbers();
  4403.  
  4404. var selectNumberArray = [];
  4405. var selectNumberExtraArray = [];
  4406. var currentLine = item.getNumbersSantized()[line];
  4407.  
  4408. var emptyLine = false;
  4409.  
  4410. if (typeof currentLine === 'undefined') {
  4411. emptyLine = true;
  4412. }
  4413.  
  4414. var specialNumbers = '';
  4415.  
  4416. if (!emptyLine) {
  4417. var indexOfStartSpecialNumber = currentLine.indexOf('#');
  4418. if (indexOfStartSpecialNumber !== -1) {
  4419. console.log(currentLine);
  4420. specialNumbers = currentLine.substr(parseInt(currentLine.indexOf(('#')) + 1));
  4421.  
  4422. specialNumbers = specialNumbers.split(',');
  4423. console.log(specialNumbers);
  4424. specialNumbers = specialNumbers.map(function (x) { return parseInt(x); });
  4425. }
  4426. var currentLineSplited;
  4427. if (indexOfStartSpecialNumber === -1) {
  4428. currentLineSplited = currentLine.split(',');
  4429. } else {
  4430. currentLineSplited = currentLine.slice(0, indexOfStartSpecialNumber).split(',');
  4431. }
  4432.  
  4433. currentLineSplited = currentLineSplited.map(function (x) { return parseInt(x); });
  4434.  
  4435. console.log(currentLineSplited);
  4436. }
  4437.  
  4438. var startNumber = item.getMinSelectNumbers();
  4439.  
  4440. for (var i = startNumber; i <= selectNumbers; i++) {
  4441. var n = {
  4442. id: i,
  4443. isSelected: 0
  4444. };
  4445. if (!emptyLine) {
  4446. if (currentLineSplited.indexOf(i) >= 0) {
  4447. n.isSelected = 1;
  4448. }
  4449. }
  4450.  
  4451. selectNumberArray.push(n);
  4452. }
  4453.  
  4454. // var startExtraNumber = item.getMinExtraNumber();
  4455. var startExtraNumber = item.getMinExtraNumber();
  4456. //id 10 is Elgordo
  4457. if (item.getMaxExtraNumbers() > 0) {
  4458. for (var j = startExtraNumber; j <= selectNumbersExtra; j++) {
  4459. var extra = {
  4460. id: j,
  4461. isSelected: 0
  4462. };
  4463. if (!emptyLine) {
  4464. if (specialNumbers.indexOf(j) >= 0) {
  4465. extra.isSelected = 1;
  4466. }
  4467. }
  4468.  
  4469. selectNumberExtraArray.push(extra);
  4470. }
  4471. }
  4472. console.log(selectNumberArray);
  4473. $scope.selectedNumbers = selectNumberArray;
  4474. $scope.selectedNumbersExtra = selectNumberExtraArray;
  4475. }
  4476. ])
  4477. .value('version', '1.0.0');
  4478.  
  4479. angular.module('ngCart.directives', ['ngCart.fulfilment'])
  4480. .controller('CartController', ['$scope', 'ngCart', function ($scope, ngCart) {
  4481. $scope.ngCart = ngCart;
  4482.  
  4483. }])
  4484. .directive('ngcartAddtocart', ['ngCart', function (ngCart) {
  4485. return {
  4486. restrict: 'E',
  4487. controller: 'CartController',
  4488. scope: {
  4489. id: '@',
  4490. name: '@',
  4491. quantity: '@',
  4492. quantityMax: '@',
  4493. price: '@',
  4494. data: '='
  4495. },
  4496. transclude: true,
  4497. templateUrl: function (element, attrs) {
  4498. if (typeof attrs.templateUrl == 'undefined') {
  4499. return '/template/ngCart/addtocart.html';
  4500. } else {
  4501. return attrs.templateUrl;
  4502. }
  4503. },
  4504. link: function (scope, element, attrs) {
  4505. scope.attrs = attrs;
  4506. scope.inCart = function () {
  4507. return ngCart.getItemById(attrs.id);
  4508. };
  4509.  
  4510. if (scope.inCart()) {
  4511. scope.q = ngCart.getItemById(attrs.id).getQuantity();
  4512. } else {
  4513. scope.q = parseInt(scope.quantity);
  4514. }
  4515.  
  4516. scope.qtyOpt = [];
  4517. for (var i = 1; i <= scope.quantityMax; i++) {
  4518. scope.qtyOpt.push(i);
  4519. }
  4520. }
  4521.  
  4522. };
  4523. }])
  4524. .directive('ngcartCart', ['$rootScope', function ($rootScope) {
  4525. return {
  4526. restrict: 'E',
  4527. controller: 'CartController',
  4528. scope: {},
  4529. templateUrl: function (element, attrs) {
  4530. if (typeof attrs.templateUrl == 'undefined') {
  4531. return '/template/ngCart/cart.html';
  4532. } else {
  4533. return attrs.templateUrl;
  4534. }
  4535. },
  4536. link: function (scope, element, attrs) {
  4537. // scope.beforeCheckOutCall();
  4538. }
  4539. };
  4540. }])
  4541. .directive('ngcartPayment', ['ngCart', function (ngCart) {
  4542. return {
  4543. restrict: 'E',
  4544. controller: 'CartController',
  4545. scope: {},
  4546. templateUrl: function (element, attrs) {
  4547. return '/template/ngCart/paymentexist.html';
  4548. },
  4549. link: function (scope, element, attrs) {
  4550. }
  4551. };
  4552. }])
  4553. .directive('ngcartPaymentNew', ['ngCart', function (ngCart) {
  4554. return {
  4555. restrict: 'E',
  4556. controller: 'CartController',
  4557. scope: {},
  4558. templateUrl: function (element, attrs) {
  4559. return '/template/ngCart/paymentnew.html';
  4560. },
  4561. link: function (scope, element, attrs) {
  4562. }
  4563. };
  4564. }])
  4565. .directive('amountTabs', ['ngCart', function (ngCart) {
  4566. return {
  4567. restrict: 'E',
  4568. controller: 'CartController',
  4569. scope: {
  4570. isVisible: '=isvisible',
  4571. text: '=text'
  4572. },
  4573. templateUrl: function (element, attrs) {
  4574. return '/template/deposit/amountTabs.html';
  4575. },
  4576. link: function (scope, element, attrs) {
  4577. }
  4578. };
  4579.  
  4580. }])
  4581. .directive('ngcartSignup', ['ngCart', function (ngCart) {
  4582. return {
  4583. restrict: 'E',
  4584. controller: 'CartController',
  4585. scope: {},
  4586. templateUrl: function (element, attrs) {
  4587. //debugger;
  4588. return '/template/ngCart/signup.html';
  4589. },
  4590. link: function (scope, element, attrs) {
  4591. }
  4592. };
  4593. }])
  4594. .directive('ngcartSummary', [function () {
  4595. return {
  4596. restrict: 'E',
  4597. controller: 'CartController',
  4598. scope: {},
  4599. transclude: true,
  4600. templateUrl: function (element, attrs) {
  4601. if (typeof attrs.templateUrl == 'undefined') {
  4602. return '/template/ngCart/summary.html';
  4603. } else {
  4604. return attrs.templateUrl;
  4605. }
  4606. }
  4607. };
  4608. }])
  4609. .directive('ngcartCheckout', [function () {
  4610. return {
  4611. restrict: 'E',
  4612. controller: ('CartController', ['$rootScope', '$scope', 'ngCart', 'fulfilmentProvider', 'ngCart.lottoyard.api', function ($rootScope, $scope, ngCart, fulfilmentProvider, apiService) {
  4613. $scope.ngCart = ngCart;
  4614.  
  4615. $scope.checkout = function ($event) {
  4616. $event.preventDefault();
  4617. // debugger;
  4618. fulfilmentProvider.setService($scope.service);
  4619. fulfilmentProvider.setSettings($scope.settings);
  4620. fulfilmentProvider.checkout()
  4621. .success(function (data, status, headers, config) {
  4622. console.log(data);
  4623. $rootScope.$broadcast('ngCart:checkout_succeeded', data);
  4624. })
  4625. .error(function (data, status, headers, config) {
  4626. $rootScope.$broadcast('ngCart:checkout_failed', {
  4627. statusCode: status,
  4628. error: data
  4629. });
  4630. });
  4631. }
  4632. }]),
  4633. scope: {
  4634. service: '@',
  4635. settings: '='
  4636. },
  4637. transclude: true,
  4638. templateUrl: function (element, attrs) {
  4639. if (typeof attrs.templateUrl == 'undefined') {
  4640. return '/template/ngCart/checkout.html';
  4641. } else {
  4642. return attrs.templateUrl;
  4643. }
  4644. }
  4645. };
  4646. }]);
  4647. angular.module('ngCart.fulfilment', ['lottoYardCacheModule'])
  4648. .run([
  4649. '$rootScope', '$http', function ($rootScope, $http) {
  4650.  
  4651. $http.defaults.transformRequest.push(function (data) {
  4652. $rootScope.progress = true;
  4653. return data;
  4654. });
  4655. $http.defaults.transformResponse.push(function (data) {
  4656. $rootScope.progress = false;
  4657. return data;
  4658. });
  4659. }
  4660. ])
  4661. .service('fulfilmentProvider', [
  4662. '$injector', function ($injector) {
  4663.  
  4664. this._obj = {
  4665. service: undefined,
  4666. settings: undefined
  4667. };
  4668.  
  4669. this.setService = function (service) {
  4670. this._obj.service = service;
  4671. };
  4672.  
  4673. this.setSettings = function (settings) {
  4674. this._obj.settings = settings;
  4675. };
  4676.  
  4677. this.checkout = function () {
  4678.  
  4679. var provider = $injector.get('ngCart.fulfilment.' + this._obj.service);
  4680. return provider.checkout(this._obj.settings);
  4681. }
  4682. }
  4683. ])
  4684. .factory('ngCart.lottoyard.api', [
  4685. '$q', '$log', '$http', 'CacheFactory', 'RESTApiUrl', 'Products', '$timeout', '$interval', 'lottoYardCacheFactory', function ($q, $log, $http, CacheFactory, RESTApiUrl, Products, $timeout, $interval, dataCache) {
  4686.  
  4687. var service = {};
  4688.  
  4689. var MAX_REQUESTS = 5;
  4690. var counterAllLotteriesRules = 1;
  4691. var countergetAllProductsRules = 1;
  4692. var counterProductPrices = 1;
  4693. var counterAllBrandDraws = 1;
  4694.  
  4695. var getAllLotteriesRulesCompleted = false;
  4696. var getAllProductsRulesCompleted = false;
  4697. var getProductPricesCompleted = false;
  4698.  
  4699. function getLotteryFromArrayById(array, id) {
  4700. if (!Array.isArray(array)) {
  4701. array = JSON.parse(array);
  4702. }
  4703. var lottery = array.filter(function (obj) {
  4704. if ('LotteryTypeId' in obj && typeof (obj.LotteryTypeId) === 'number' && obj.LotteryTypeId === id) {
  4705. return true;
  4706. }
  4707. return false;
  4708. });
  4709.  
  4710. return lottery;
  4711. }
  4712.  
  4713. function getProductFromArrayById(array, id) {
  4714. if (!Array.isArray(array)) {
  4715. array = JSON.parse(array);
  4716. }
  4717. var lottery = array.filter(function (obj) {
  4718. if ('ProductId' in obj && typeof (obj.ProductId) === 'number' && obj.ProductId === id) {
  4719. return true;
  4720. }
  4721. return false;
  4722. });
  4723.  
  4724. return lottery;
  4725. }
  4726.  
  4727. function getProductPriceFromArrayById(array, productId, draws, lotteryType) {
  4728. if (!Array.isArray(array)) {
  4729. array = JSON.parse(array);
  4730. }
  4731. return array.filter(function (x) {
  4732. if (x.ProductId === productId && x.NumOfDraws === draws && x.LotteryId === lotteryType) {
  4733. return true;
  4734. } else {
  4735. return false;
  4736. }
  4737. });
  4738. }
  4739.  
  4740. function getProductPriceFromArrayByIds(array, productId, draws, lotteryType, lines) {
  4741. if (!Array.isArray(array)) {
  4742. array = JSON.parse(array);
  4743. }
  4744. return array.filter(function (x) {
  4745. if (x.ProductId === productId && x.NumOfDraws === draws && x.LotteryId === lotteryType && x.Lines === lines) {
  4746. return true;
  4747. } else {
  4748. return false;
  4749. }
  4750. });
  4751. }
  4752.  
  4753. service.getLotteryById = function getLotteryById(id) {
  4754. var idcache = 'lottery-rules';
  4755.  
  4756. if (dataCache.get(idcache)) {
  4757. var cached = dataCache.get(idcache);
  4758. if (!Array.isArray(cached)) {
  4759. cached = JSON.parse(cached);
  4760. }
  4761. //debugger;
  4762. return getLotteryFromArrayById(cached, id)[0];
  4763. } else {
  4764. this.getAllLotteriesRules().then(function (resp) {
  4765. return getLotteryFromArrayById(resp, id)[0];
  4766. });
  4767. }
  4768.  
  4769. };
  4770.  
  4771. service.getProductById = function getLotteryById(id) {
  4772. var idcache = 'product-rules';
  4773.  
  4774. if (dataCache.get(idcache)) {
  4775. var cached = dataCache.get(idcache);
  4776. if (!Array.isArray(cached)) {
  4777. cached = JSON.parse(cached);
  4778. }
  4779. return getProductFromArrayById(cached, id)[0];
  4780. } else {
  4781. this.getAllProductsRules().then(function (resp) {
  4782. return getProductFromArrayById(resp, id)[0];
  4783. });
  4784. }
  4785. };
  4786.  
  4787. service.getAllLotteriesRules = function getAllLotteriesRules() {
  4788.  
  4789. var id = 'lottery-rules';
  4790.  
  4791. var deffered = $q.defer();
  4792.  
  4793. if (dataCache.get(id)) {
  4794. var cached = dataCache.get(id);
  4795. if (!Array.isArray(cached)) {
  4796. cached = JSON.parse(cached);
  4797. }
  4798. deffered.resolve(cached);
  4799. }
  4800. //else {
  4801. // $http({
  4802. // method: 'POST',
  4803. // cache: CacheFactory.get('cachelottoyard'),
  4804. // url: RESTApiUrl,
  4805. // timeout: 2500,
  4806.  
  4807. // data: { action: "globalinfo/lottery-rules", data: "" }
  4808. // }).success(function (data) {
  4809. // var resp;
  4810. // getAllLotteriesRulesCompleted = true;
  4811.  
  4812. // try {
  4813. // resp = JSON.parse(data.d);
  4814.  
  4815. // } catch (e) {
  4816. // console.error('Parsing globalinfo/lottery-rules Error: %s Response: %s', e, data.d);
  4817. // deffered.reject('There was an error');
  4818. // }
  4819.  
  4820. // dataCache.put(id, resp);
  4821.  
  4822. // deffered.resolve(resp);
  4823.  
  4824. // }).error(function (response) {
  4825. // if (counterAllLotteriesRules < MAX_REQUESTS) {
  4826. // $timeout(function () {
  4827. // getAllLotteriesRules();
  4828. // console.log("globalinfo/lottery-rules");
  4829. // }, 2500);
  4830.  
  4831. // counterAllLotteriesRules++;
  4832. // } else {
  4833. // console.warn("Error in getAllProductsRulesCompleted: " + response);
  4834. // deffered.reject('There was an error');
  4835. // }
  4836.  
  4837. // });
  4838. //}
  4839.  
  4840. return deffered.promise;
  4841. };
  4842.  
  4843. service.getAllProductsRules = function getAllProductsRules() {
  4844.  
  4845. var id = 'product-rules';
  4846.  
  4847. var deffered = $q.defer();
  4848.  
  4849. if (dataCache.get(id)) {
  4850. var cached = dataCache.get(id);
  4851. if (!Array.isArray(cached)) {
  4852. cached = JSON.parse(cached);
  4853. }
  4854. deffered.resolve(cached);
  4855. }
  4856. // else {
  4857. // $http({
  4858. // method: 'POST',
  4859. // cache: CacheFactory.get('cachelottoyard'),
  4860. // url: RESTApiUrl,
  4861. // timeout: 2500,
  4862.  
  4863. // data: { action: "globalinfo/product-rules", data: "" }
  4864. // }).success(function (data) {
  4865.  
  4866. // getAllProductsRulesCompleted = true;
  4867. // var resp;
  4868. // try {
  4869. // resp = JSON.parse(data.d);
  4870. // } catch (e) {
  4871. // console.error("Parsing globalinfo/product-rules Error: %s Response: %s ", e, data.d);
  4872. // deffered.reject('There was an error');
  4873. // }
  4874. // dataCache.put(id, resp);
  4875.  
  4876. // deffered.resolve(resp);
  4877.  
  4878. // }).error(function (response) {
  4879. // if (countergetAllProductsRules < MAX_REQUESTS) {
  4880. // console.log('countergetAllProductsRules:' + countergetAllProductsRules);
  4881. // $timeout(function () {
  4882. // service.getAllProductsRules();
  4883. // }, 2500);
  4884.  
  4885. // countergetAllProductsRules++;
  4886. // } else {
  4887. // console.warn("Error in getAllProductsRulesCompleted" + response);
  4888. // deffered.reject('There was an error:');
  4889. // }
  4890.  
  4891. // });
  4892. //}
  4893.  
  4894. return deffered.promise;
  4895. };
  4896.  
  4897. service.getFreeTicket = function getFreeTicket() {
  4898.  
  4899. var id = 'free-ticket';
  4900.  
  4901. var data = JSON.stringify({ MemberId: "{0}" });
  4902.  
  4903. var deffered = $q.defer();
  4904.  
  4905. if (dataCache.get(id)) {
  4906. deffered.resolve(dataCache.get(id));
  4907. } else {
  4908. $http({
  4909. method: 'POST',
  4910. cache: CacheFactory.get('cachelottoyard'),
  4911. url: RESTApiUrl,
  4912. timeout: 2000,
  4913.  
  4914. data: {
  4915. action: "playlottery/get-member-free-ticket",
  4916. data: data
  4917. }
  4918. }).success(function (data) {
  4919.  
  4920. //getAllProductsRulesCompleted = true;
  4921.  
  4922. dataCache.put(id, JSON.parse(data.d));
  4923.  
  4924. deffered.resolve(JSON.parse(data.d));
  4925.  
  4926. }).error(function (response) {
  4927. if (countergetAllProductsRules < MAX_REQUESTS) {
  4928. console.log('countergetAllProductsRules:' + countergetAllProductsRules);
  4929. $timeout(service.getAllProductsRules(), 2500);
  4930.  
  4931. countergetAllProductsRules++;
  4932. } else {
  4933. console.warn("Error in getAllProductsRulesCompleted" + response);
  4934. deffered.reject('There was an error:');
  4935. }
  4936.  
  4937. });
  4938. }
  4939.  
  4940. return deffered.promise;
  4941. };
  4942.  
  4943. service.prepareOrder = function (data) {
  4944. console.log(RESTApiUrl);
  4945.  
  4946. var deffered = $q.defer();
  4947. console.log(data);
  4948. $http({
  4949. method: 'POST',
  4950. url: RESTApiUrl,
  4951. data: {
  4952. action: "cashier/prepare-order",
  4953. data: data
  4954. }
  4955. }).success(function (resp) {
  4956. var parsedResp;
  4957. try {
  4958. parsedResp = JSON.parse(resp.d);
  4959. } catch (e) {
  4960. // console.error("Parsing cashier/prepare-order Error: %s Response: %s", e, resp.d);
  4961. deffered.reject('There was an error');
  4962. }
  4963.  
  4964. console.log(parsedResp);
  4965.  
  4966. deffered.resolve(parsedResp);
  4967.  
  4968. }).error(function () {
  4969. deffered.reject();
  4970. });
  4971.  
  4972. return deffered.promise;
  4973. }
  4974.  
  4975. service.submitOrder = function (data) {
  4976. var deffered = $q.defer();
  4977.  
  4978. $http({
  4979. method: 'POST',
  4980. url: RESTApiUrl,
  4981.  
  4982. data: {
  4983. action: "cashier/processor-confirm-order",
  4984. data: data
  4985. }
  4986. }).success(function (dataResp) {
  4987. var resp;
  4988. try {
  4989. resp = JSON.parse(dataResp.d);
  4990. } catch (e) {
  4991. console.error("Parsing cashier/processor-confirm-order Error: %s Response: %s", e, dataResp.d);
  4992. deffered.reject('There was an error');
  4993. }
  4994. console.log(resp);
  4995.  
  4996. deffered.resolve(resp);
  4997.  
  4998. }).error(function () {
  4999.  
  5000. deffered.reject('There was an error');
  5001. });
  5002.  
  5003.  
  5004. return deffered.promise;
  5005. };
  5006.  
  5007. service.getMemberPaymentMethods = function (data) {
  5008.  
  5009. var deffered = $q.defer();
  5010.  
  5011. $http({
  5012. method: 'POST',
  5013. url: RESTApiUrl,
  5014.  
  5015. data: {
  5016. action: "cashier/get-member-payment-methods",
  5017. data: data
  5018. }
  5019. }).success(function (data) {
  5020. var resp;
  5021. try {
  5022. resp = JSON.parse(data.d);
  5023. } catch (e) {
  5024. console.error("Parsing cashier/get-member-payment-methods Error: %s Response: %s", e, data.d);
  5025. deffered.reject('There was an error');
  5026. }
  5027. console.log(resp);
  5028.  
  5029. deffered.resolve(resp);
  5030.  
  5031. }).error(function () {
  5032.  
  5033. deffered.reject('There was an error');
  5034. });
  5035.  
  5036.  
  5037. return deffered.promise;
  5038. };
  5039.  
  5040. service.updatePersonalDetails = function (data) {
  5041. var deffered = $q.defer();
  5042. console.log(RESTApiUrl);
  5043.  
  5044. $http({
  5045. method: 'POST',
  5046. url: RESTApiUrl,
  5047. data: {
  5048. action: "userinfo/update-personal-details",
  5049. data: data
  5050. }
  5051. }).success(function (data) {
  5052. var resp;
  5053. try {
  5054. resp = JSON.parse(data.d);
  5055. } catch (e) {
  5056. console.error("Parsing cashier/deposit-fundss Error: %s Response: %s", e, data);
  5057. deffered.reject('There was an error');
  5058. }
  5059. console.log(resp);
  5060.  
  5061. deffered.resolve(resp);
  5062.  
  5063. }).error(function () {
  5064.  
  5065. deffered.reject('There was an error');
  5066. });
  5067.  
  5068.  
  5069. return deffered.promise;
  5070. };
  5071.  
  5072. service.getPersonalDetailsByMemberId = function (data) {
  5073. var deffered = $q.defer();
  5074.  
  5075. $http({
  5076. method: 'POST',
  5077. url: RESTApiUrl,
  5078. data: {
  5079. action: "userinfo/get-personal-details-by-memberid ",
  5080. data: data
  5081. }
  5082. }).success(function (data) {
  5083. var resp;
  5084. try {
  5085. resp = JSON.parse(data.d);
  5086. } catch (e) {
  5087. console.error("Parsing cashier/deposit-fundss Error: %s Response: %s", e, data);
  5088. deffered.reject('There was an error');
  5089. }
  5090. console.log(resp);
  5091.  
  5092. deffered.resolve(resp);
  5093.  
  5094. }).error(function () {
  5095.  
  5096. deffered.reject('There was an error');
  5097. });
  5098.  
  5099. return deffered.promise;
  5100. };
  5101.  
  5102. service.depositFunds = function (data) {
  5103. var deffered = $q.defer();
  5104.  
  5105. $http({
  5106. method: 'POST',
  5107. url: RESTApiUrl,
  5108. data: {
  5109. action: "cashier/deposit-funds",
  5110. data: data
  5111. }
  5112. }).success(function (data) {
  5113. var resp;
  5114. try {
  5115. resp = JSON.parse(data.d);
  5116. } catch (e) {
  5117. console.error("Parsing cashier/deposit-fundss Error: %s Response: %s", e, data);
  5118. deffered.reject('There was an error');
  5119. }
  5120. console.log(resp);
  5121.  
  5122. deffered.resolve(resp);
  5123.  
  5124. }).error(function () {
  5125.  
  5126. deffered.reject('There was an error');
  5127. });
  5128.  
  5129.  
  5130. return deffered.promise;
  5131. };
  5132.  
  5133. service.signIn = function (data) {
  5134. data = JSON.stringify(data);
  5135. var deffered = $q.defer();
  5136.  
  5137. $http({
  5138. method: 'POST',
  5139. url: RESTApiUrl,
  5140.  
  5141. data: {
  5142. action: "signup/login-internal",
  5143. data: data
  5144. }
  5145. }).success(function (resp) {
  5146. var parsedResp;
  5147. try {
  5148. parsedResp = JSON.parse(resp.d);
  5149. } catch (e) {
  5150. console.error("Parsing cashier/deposit-fundss Error: %s Response: %s", e, resp.d);
  5151. deffered.reject('There was an error');
  5152. }
  5153. console.log(parsedResp);
  5154.  
  5155. deffered.resolve(parsedResp);
  5156.  
  5157. }).error(function () {
  5158. deffered.reject();
  5159. });
  5160.  
  5161. return deffered.promise;
  5162. }
  5163.  
  5164. //here we are adding products support
  5165. if (typeof (Products) !== 'undefined' && Products.length > 0) {
  5166. service.getProductPrices = function getProductPrices() {
  5167. var id = 'product-prices';
  5168. var products = "";
  5169.  
  5170. angular.forEach(Products, function (item) {
  5171. products += item.id + ',';
  5172. });
  5173.  
  5174. var objToSend = JSON.stringify({ ProductIds: products });
  5175.  
  5176. var deffered = $q.defer();
  5177. if (dataCache.get(id)) {
  5178. var cached = dataCache.get(id);
  5179. if (!Array.isArray(cached)) {
  5180. cached = JSON.parse(cached);
  5181. }
  5182. deffered.resolve(cached);
  5183. }
  5184. //else {
  5185. // $http({
  5186. // method: 'POST',
  5187. // cache: CacheFactory.get('cachelottoyard'),
  5188. // url: RESTApiUrl,
  5189. // timeout: 2500,
  5190.  
  5191. // data: { action: "globalinfo/get-prices-by-brand-and-productid", data: objToSend }
  5192. // }).success(function (data) {
  5193. // var resp;
  5194. // try {
  5195. // resp = JSON.parse(data.d);
  5196. // } catch (e) {
  5197. // console.error("Parsing globalinfo/get-prices-by-brand-and-productid Error: %s Response: %s", e, data.d);
  5198. // deffered.reject('There was an error');
  5199. // }
  5200. // getProductPricesCompleted = true;
  5201.  
  5202. // dataCache.put(id, resp);
  5203.  
  5204. // deffered.resolve(resp);
  5205.  
  5206. // console.log(JSON.parse(data.d));
  5207.  
  5208. // }).error(function (response) {
  5209.  
  5210. // if (counterProductPrices < MAX_REQUESTS) {
  5211. // console.log('counterProductPrices:' + counterProductPrices);
  5212.  
  5213. // $timeout(function () {
  5214. // service.getProductPrices();
  5215. // }, 2500);
  5216.  
  5217. // //getProductPrices();
  5218. // counterProductPrices++;
  5219. // } else {
  5220. // console.warn("Error in getProductPricesCompleted: " + response);
  5221. // deffered.reject('There was an error');
  5222. // }
  5223.  
  5224. // });
  5225. //}
  5226.  
  5227. return deffered.promise;
  5228. }
  5229.  
  5230. service.getProductPriceById = function (productId, draws, lotteryType) {
  5231. var idcache = 'product-prices';
  5232. if (dataCache.get(idcache)) {
  5233. var cached = dataCache.get(idcache);
  5234. if (!Array.isArray(cached)) {
  5235. cached = JSON.parse(cached);
  5236. }
  5237. return getProductPriceFromArrayById(cached, productId, draws, lotteryType)[0];
  5238. } else {
  5239. this.getProductPrices().then(function (resp) {
  5240.  
  5241. return getProductPriceFromArrayById(resp, productId, draws, lotteryType)[0];
  5242. });
  5243. }
  5244. };
  5245.  
  5246. service.getProductPriceByIds = function (productId, draws, lotteryType, lines) {
  5247. var idcache = 'product-prices';
  5248.  
  5249. if (dataCache.get(idcache)) {
  5250. var cached = dataCache.get(idcache);
  5251. if (!Array.isArray(cached)) {
  5252. // debugger;
  5253. cached = JSON.parse(cached);
  5254. }
  5255. return getProductPriceFromArrayByIds(cached, productId, draws, lotteryType, lines)[0];
  5256. } else {
  5257. this.getProductPrices().then(function (resp) {
  5258. return getProductPriceFromArrayByIds(resp, productId, draws, lotteryType, lines)[0];
  5259. });
  5260. }
  5261. };
  5262. }
  5263. //signUp
  5264. service.signUp = function (data) {
  5265. data = JSON.stringify(data);
  5266. var deffered = $q.defer();
  5267. console.log(data);
  5268. $http({
  5269. method: 'POST',
  5270. url: RESTApiUrl,
  5271.  
  5272. data: {
  5273. action: "signup/signup-internal",
  5274. data: data
  5275. }
  5276. }).success(function (resp) {
  5277. var parsedResp = null;
  5278. try {
  5279. parsedResp = JSON.parse(resp.d);
  5280. } catch (e) {
  5281. console.error("Parsing signup/signup-internal Error: %s Response: %s", e, resp);
  5282. }
  5283. // console.log(parsedResp);
  5284.  
  5285. deffered.resolve(parsedResp);
  5286.  
  5287. }).error(function () {
  5288. deffered.reject();
  5289. });
  5290.  
  5291. return deffered.promise;
  5292. }
  5293. //get lotteries jackpots
  5294. //get-all-brand-draws
  5295. service.getAllBrandDraws = function getAllBrandDraws() {
  5296. var id = 'get-all-brand-draws';
  5297. var deffered = $q.defer();
  5298.  
  5299. if (dataCache.get(id)) {
  5300. var cached = dataCache.get(id);
  5301. if (!Array.isArray(cached)) {
  5302. cached = JSON.parse(cached);
  5303. }
  5304. deffered.resolve(cached);
  5305. } else {
  5306. $http({
  5307. method: 'POST',
  5308. cache: CacheFactory.get('cachelottoyard'),
  5309. url: RESTApiUrl,
  5310. timeout: 2500,
  5311. data: {
  5312. action: "globalinfo/get-all-brand-draws",
  5313. data: ""
  5314. }
  5315. }).success(function (data) {
  5316. var resp = null;
  5317. try {
  5318. resp = JSON.parse(data.d);
  5319. } catch (e) {
  5320. console.error("Parsing globalinfo/get-all-brand-draws Error: %s Response: %s", e, data.d);
  5321. deffered.reject('There was an error');
  5322. }
  5323. getProductPricesCompleted = true;
  5324.  
  5325. dataCache.put(id, resp);
  5326.  
  5327. deffered.resolve(resp);
  5328.  
  5329. }).error(function (response) {
  5330.  
  5331. if (counterAllBrandDraws < MAX_REQUESTS) {
  5332. console.log('counterAllBrandDraws:' + counterAllBrandDraws);
  5333. $timeout(function () {
  5334. service.getAllBrandDraws();
  5335. }, 2500);
  5336. //getAllBrandDraws();
  5337. counterAllBrandDraws++;
  5338. } else {
  5339. console.warn("Error in counterAllBrandDraws: " + response);
  5340. deffered.reject('There was an error');
  5341. }
  5342. });
  5343. }
  5344.  
  5345. return deffered.promise;
  5346. }
  5347.  
  5348. service.getRaffleTicket = function getRaffleTicket(productId) {
  5349.  
  5350. var deffered = $q.defer();
  5351. var data = JSON.stringify({
  5352. ProductId: productId
  5353. });
  5354.  
  5355. $http({
  5356. method: 'POST',
  5357. url: RESTApiUrl,
  5358. data: {
  5359. action: "playlottery/get-navidad-numbers",
  5360. data: data
  5361. }
  5362. }).success(function (data) {
  5363.  
  5364. deffered.resolve(JSON.parse(data.d));
  5365.  
  5366. }).error(function (response) {
  5367. console.warn("Error in playlottery/get-navidad-numbers" + response);
  5368. deffered.reject('There was an error:');
  5369. });
  5370.  
  5371. return deffered.promise;
  5372. };
  5373.  
  5374. service.getPaymentMethod = function getPaymentMethod(data) {
  5375. var deffered = $q.defer();
  5376.  
  5377. $http({
  5378. method: 'POST',
  5379. url: RESTApiUrl,
  5380. data: {
  5381. action: "userinfo/get-credit-card-methods-by-memberid",
  5382. data: data
  5383. }
  5384. }).success(function (data) {
  5385.  
  5386. deffered.resolve(JSON.parse(data.d));
  5387.  
  5388. }).error(function (response) {
  5389. console.warn("Error in userinfo/get-credit-card-methods-by-memberid" + response);
  5390. deffered.reject('There was an error:');
  5391. });
  5392.  
  5393. return deffered.promise;
  5394. };
  5395.  
  5396. service.deletePaymentMethod = function deletePaymentMethod(data) {
  5397. var deffered = $q.defer();
  5398.  
  5399. $http({
  5400. method: 'POST',
  5401. url: RESTApiUrl,
  5402. data: {
  5403. action: "userinfo/delete-credit-card",
  5404. data: data
  5405. }
  5406. }).success(function (data) {
  5407. var resp;
  5408. try {
  5409. resp = JSON.parse(data.d);
  5410. } catch (e) {
  5411. console.error("Parsing Api delete payment Error: %s Response: %s", e, data);
  5412. deffered.reject('There was an error');
  5413. }
  5414. console.log(resp);
  5415.  
  5416. deffered.resolve(resp);
  5417.  
  5418. }).error(function () {
  5419.  
  5420. deffered.reject('There was an error');
  5421. });
  5422.  
  5423.  
  5424. return deffered.promise;
  5425. };
  5426.  
  5427. service.addPaymentMethod = function addPaymentMethod(data) {
  5428. var deffered = $q.defer();
  5429.  
  5430. $http({
  5431. method: 'POST',
  5432. url: RESTApiUrl,
  5433. data: {
  5434. action: "userinfo/add-update-credit-card",
  5435. data: data
  5436. }
  5437. }).success(function (data) {
  5438. var resp;
  5439. try {
  5440. resp = JSON.parse(data.d);
  5441. } catch (e) {
  5442. console.error("Parsing Api add payment Error: %s Response: %s", e, data);
  5443. deffered.reject('There was an error');
  5444. }
  5445. console.log(resp);
  5446.  
  5447. deffered.resolve(resp);
  5448.  
  5449. }).error(function () {
  5450.  
  5451. deffered.reject('There was an error');
  5452. });
  5453.  
  5454.  
  5455. return deffered.promise;
  5456. };
  5457.  
  5458. return service;
  5459.  
  5460. }
  5461. ])
  5462. .service('ngCart.fulfilment.log', [
  5463. '$q', '$log', 'ngCart', function ($q, $log, ngCart) {
  5464.  
  5465. this.checkout = function () {
  5466.  
  5467. var deferred = $q.defer();
  5468.  
  5469. $log.info(ngCart.toObject());
  5470. deferred.resolve({
  5471. cart: ngCart.toObject()
  5472. });
  5473.  
  5474. return deferred.promise;
  5475.  
  5476. }
  5477.  
  5478. }
  5479. ])
  5480. .service('ngCart.fulfilment.http', [
  5481. '$http', 'ngCart', function ($http, ngCart) {
  5482.  
  5483. this.checkout = function (settings) {
  5484. return $http.post(settings.url,
  5485. {
  5486. data: ngCart.toObject(),
  5487. options: settings.options
  5488. });
  5489. }
  5490. }
  5491. ])
  5492. .service('ngCart.translationService', [
  5493. 'ngCart', '$resource', '$http', function (ngCart, $resource, $http) {
  5494.  
  5495. this.getTranslation = function ($scope, language) {
  5496. var service = this;
  5497. var request = $http({
  5498. method: "GET",
  5499. url: '/Scripts/cartjs/translations/translation_' + language + '.json',
  5500. });
  5501.  
  5502. request.then(function (resp) {
  5503. $scope.translation = resp.data;
  5504. }, function (resp) {
  5505. if (resp.status === 404) {
  5506. service.getTranslation($scope, 'en');
  5507. }
  5508. });
  5509. //var languageFilePath = '/Scripts/cartjs/translations/translation_' + language + '.json';
  5510. //$resource(languageFilePath).get().$promise.then(function (data) {
  5511. // debugger;
  5512. // $scope.translation = data;
  5513. //});
  5514. };
  5515. }
  5516. ])
  5517. .service('ngCart.fulfilment.lottoyard', [
  5518. '$http', 'ngCart', function ($http, ngCart) {
  5519.  
  5520. //debugger;
  5521. var restApiUrl = "/APIConnector/APIConnector.asmx/Send";
  5522.  
  5523. this.checkout = function (settings) {
  5524. var data = ngCart.toObject();
  5525.  
  5526. return $http({
  5527. method: 'POST',
  5528. url: restApiUrl,
  5529. headers: {
  5530. 'Content-Type': 'application/x-www-form-urlencoded'
  5531. },
  5532. data: 'action=cashier/prepare-order&data=' + encodeURIComponent(data)
  5533. });
  5534. //var deffered = $q.defer();
  5535.  
  5536. // $http({
  5537. // method: 'POST',
  5538. // url: restApiUrl,
  5539. // headers: {
  5540. // 'Content-Type': 'application/x-www-form-urlencoded'
  5541. // },
  5542. // data: 'action=cashier/prepare-order&data=' + ngCart.toObject()
  5543. // }).success(function(data) {
  5544.  
  5545. // console.log(data);
  5546.  
  5547.  
  5548. // deffered.resolve(data);
  5549.  
  5550. // }).error(function() {
  5551.  
  5552. // deffered.reject('There was an error');
  5553. // });
  5554.  
  5555. // return deffered.promise;
  5556. }
  5557.  
  5558. }
  5559. ])
  5560. .factory('ngCart.GetCountryByIpService', [
  5561. '$http', '$q', function ($http, $q) {
  5562. var service = {};
  5563.  
  5564. function getFromFreeGeoIp() {
  5565. var deffered = $q.defer();
  5566. $http({
  5567. url: 'https://freegeoip.net/json/',
  5568. timeout: 500
  5569. }).success(function (location) {
  5570. if (location.country_code == null || location.country_code == undefined || location.country_code == 'undefined') {
  5571. return;
  5572. }
  5573. console.log("freegeoip.net success");
  5574. deffered.resolve(location.country_code);
  5575.  
  5576. }).error(function () {
  5577.  
  5578. deffered.reject('There was an error');
  5579. });
  5580.  
  5581. return deffered.promise;
  5582. }
  5583.  
  5584. function getFromIp2c() {
  5585. var deffered = $q.defer();
  5586. $http({
  5587. url: 'http://ip-api.com/json',
  5588. timeout: 500
  5589. }).success(function (location) {
  5590. console.log("ip-api.com success");
  5591. deffered.resolve(location.countryCode);
  5592.  
  5593. }).error(function () {
  5594. deffered.reject('There was an error');
  5595. });
  5596.  
  5597. return deffered.promise;
  5598. }
  5599.  
  5600. function getFromMaxMind() {
  5601. var deffered = $q.defer();
  5602.  
  5603. //debugger;
  5604. deffered.resolve(getCookie("maxMindCountryCode"));
  5605.  
  5606. return deffered.promise;
  5607. }
  5608.  
  5609. service.getCountryCodeByIp = function () {
  5610.  
  5611. var deffered = $q.defer();
  5612. var resultOfFreeSerice = [];
  5613.  
  5614. function toStartPaidService() {
  5615. console.log(resultOfFreeSerice);
  5616. if (resultOfFreeSerice.length === 2) {
  5617. if (resultOfFreeSerice.every(function (value, index, ar) {
  5618. if (value) {
  5619. return false;
  5620. } else {
  5621. return true;
  5622. }
  5623. })) {
  5624. console.log("starting paid service");
  5625.  
  5626. $q.when(getFromMaxMind(), (function (data) {
  5627. console.log(data);
  5628. deffered.resolve(data);
  5629. }));
  5630. } else if (resultOfFreeSerice.length === 2) {
  5631. console.log("fail");
  5632. }
  5633. }
  5634. }
  5635.  
  5636. $q.when(getFromMaxMind(), (function (data) {
  5637. console.log(data);
  5638. deffered.resolve(data);
  5639. }));
  5640.  
  5641. //$q.when(getFromFreeGeoIp(), (function (data) {
  5642. // console.log("freegeoip " + data);
  5643. // deffered.resolve(data);
  5644.  
  5645. //}), function () {
  5646. // console.log("freegeoip failed");
  5647. // resultOfFreeSerice.push(false);
  5648. // toStartPaidService();
  5649. //});
  5650.  
  5651. //$q.when(getFromIp2c(), (function (data) {
  5652. // console.log("ip2c.org " + data);
  5653. // deffered.resolve(data);
  5654.  
  5655. //}), function () {
  5656. // console.log("ip2c failed");
  5657. // resultOfFreeSerice.push(false);
  5658. // toStartPaidService();
  5659. //});
  5660.  
  5661.  
  5662. return deffered.promise;
  5663. }
  5664.  
  5665. return service;
  5666. }
  5667. ])
  5668. .filter('floor', function () {
  5669. return function (input) {
  5670. return Math.floor(input);
  5671. };
  5672. })
  5673. .filter('round', function () {
  5674. return function (input) {
  5675. return Math.round(input);
  5676. };
  5677. })
  5678. .directive('validNumber', function () {
  5679. return {
  5680. require: '?ngModel',
  5681. link: function (scope, element, attrs, ngModelCtrl) {
  5682. if (!ngModelCtrl) {
  5683. return;
  5684. }
  5685.  
  5686. ngModelCtrl.$parsers.push(function (val) {
  5687. if (angular.isUndefined(val)) {
  5688. var val = '';
  5689. }
  5690. var clean = val.replace(/[^0-9]+/g, '');
  5691. if (val !== clean) {
  5692. ngModelCtrl.$setViewValue(clean);
  5693. ngModelCtrl.$render();
  5694. }
  5695. return clean;
  5696. });
  5697.  
  5698. element.bind('keyup keydown', function (event) {
  5699. if (event.keyCode === 32) {
  5700. event.preventDefault();
  5701. }
  5702. });
  5703. }
  5704. };
  5705. })
  5706. .directive('validNumberDecimal', function () {
  5707. return {
  5708. require: '?ngModel',
  5709. link: function (scope, element, attrs, ngModelCtrl) {
  5710. if (!ngModelCtrl) {
  5711. return;
  5712. }
  5713.  
  5714. ngModelCtrl.$parsers.push(function (val) {
  5715. if (angular.isUndefined(val)) {
  5716. var val = '';
  5717. }
  5718. var clean = val.replace(/[^0-9\.]/g, '');
  5719. var decimalCheck = clean.split('.');
  5720.  
  5721. if (!angular.isUndefined(decimalCheck[1])) {
  5722. decimalCheck[1] = decimalCheck[1].slice(0, 2);
  5723. clean = decimalCheck[0] + '.' + decimalCheck[1];
  5724. }
  5725. if (val !== clean) {
  5726. ngModelCtrl.$setViewValue(clean);
  5727. ngModelCtrl.$render();
  5728. }
  5729. return clean;
  5730. });
  5731.  
  5732. element.bind('keyup keydown', function (event) {
  5733. if (event.keyCode === 32) {
  5734. event.preventDefault();
  5735. }
  5736. });
  5737. }
  5738. };
  5739. })
  5740. .filter('translate', [
  5741. '$rootScope', 'ErrorMessages', function ($rootScope, ErrorMessages) {
  5742. return function (items) {
  5743. var filtered = [];
  5744. var currentLangErrorsArr = ErrorMessages[$rootScope.language];
  5745. if (typeof currentLangErrorsArr === 'undefined') {
  5746. currentLangErrorsArr = ErrorMessages["en"];
  5747. }
  5748. if (items !== null && typeof (items) !== "undefined" && items.length > 0) {
  5749.  
  5750. for (var i = 0; i < items.length; i++) {
  5751. var item = items[i];
  5752.  
  5753. if (item.ErrorMessage[item.ErrorMessage.length - 1] === ".")
  5754. item.ErrorMessage = item.ErrorMessage.slice(0, -1);
  5755. var err = currentLangErrorsArr.filter(function (x) {
  5756. if (x.error === item.ErrorMessage) {
  5757. return true;
  5758. } else {
  5759. return false;
  5760. }
  5761. });
  5762. if (err.length > 0) {
  5763. filtered.push(err[0].text);
  5764. } else {
  5765.  
  5766. filtered.push(item.ErrorMessage);
  5767. }
  5768. }
  5769. } else {
  5770. return items;
  5771. }
  5772.  
  5773. return filtered;
  5774. };
  5775. }
  5776. ])
  5777. .directive('onlyAlphabetsAndNumbers', function () {
  5778. return {
  5779. require: '?ngModel',
  5780. link: function (scope, element, attrs, ngModelCtrl) {
  5781. if (!ngModelCtrl) {
  5782. return;
  5783. }
  5784. ngModelCtrl.$parsers.push(function (val) {
  5785. if (angular.isUndefined(val)) {
  5786. var val = '';
  5787. }
  5788. var transformedInput = val.replace(/[^а-яА-ЯёЁa-zA-Z-0-9,.№-\s-]+/, '');
  5789. if (transformedInput !== val) {
  5790. ngModelCtrl.$setViewValue(transformedInput);
  5791. ngModelCtrl.$render();
  5792. }
  5793. return transformedInput;
  5794. });
  5795. }
  5796. };
  5797. })
  5798. .directive('onlyAlphabets', function () {
  5799. return {
  5800. require: '?ngModel',
  5801. link: function (scope, element, attrs, ngModelCtrl) {
  5802. if (!ngModelCtrl) {
  5803. return;
  5804. }
  5805.  
  5806. ngModelCtrl.$parsers.push(function (val) {
  5807. if (angular.isUndefined(val)) {
  5808. var val = '';
  5809. }
  5810. var transformedInput = val.replace(/([^а-яА-ЯёЁ |a-zA-Z-_]+$)/, '');
  5811. if (transformedInput !== val) {
  5812. ngModelCtrl.$setViewValue(transformedInput);
  5813. ngModelCtrl.$render();
  5814. }
  5815. return transformedInput;
  5816. });
  5817. }
  5818. };
  5819. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement