main.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. 'use strict';
  2. angular.module('fehlerberichtApp').filter("euro", function () {
  3. return function (num) {
  4. if (num !== null) {
  5. return num.toFixed(2).toString().replace(".", ",");
  6. }
  7. return "0,00";
  8. };
  9. });
  10. /**
  11. * @ngdoc function
  12. * @name kasseApp.controller:MainCtrl
  13. * @description
  14. * # MainCtrl
  15. * Controller of the kasseApp
  16. */
  17. angular.module('fehlerberichtApp')
  18. .controller('MainCtrl', function ($scope) {
  19. $scope.Produkte = [
  20. {
  21. "Produkt": 0,
  22. "Anzahl": 1,
  23. "Bezeichnung": "Steak mit Pommes",
  24. "Extras": {
  25. "Jaeger": true,
  26. "Zwiebel": false
  27. },
  28. "EP": 5.5
  29. },
  30. {
  31. "Produkt": 1,
  32. "Anzahl": 1,
  33. "Bezeichnung": "Steak mit Brot",
  34. "Extras": {
  35. "Jaeger": true,
  36. "Zwiebel": false
  37. },
  38. "EP": 4.5
  39. },
  40. {
  41. "Produkt": 2,
  42. "Anzahl": 1,
  43. "Bezeichnung": "Hackbraten mit Pommes",
  44. "Extras": {
  45. "Jaeger": false,
  46. "Zwiebel": true
  47. },
  48. "EP": 5.5
  49. },
  50. {
  51. "Produkt": 3,
  52. "Anzahl": 1,
  53. "Bezeichnung": "Hackbraten mit Brot",
  54. "Extras": {
  55. "Jaeger": false,
  56. "Zwiebel": true
  57. },
  58. "EP": 4.5
  59. },
  60. {
  61. "Produkt": 4,
  62. "Anzahl": 1,
  63. "Bezeichnung": "Portion Pommes",
  64. "EP": 3.0
  65. }
  66. ];
  67. $scope.Rechnung = window.localStorage.getItem("Rechnung");
  68. $scope.OffeneBestellungen = window.localStorage.getItem("OffeneBestellungen");
  69. $scope.Bestellung = [];
  70. $scope.Anzahl = function () {
  71. return _.reduce($scope.Bestellung, function (sum, b) { return sum + b.Anzahl; }, 0);
  72. };
  73. $scope.Summe = function () {
  74. return _.reduce($scope.Bestellung, function (sum, b) { return sum + b.Anzahl * b.EP; }, 0);
  75. };
  76. $scope.addItem = function (num) {
  77. $scope.Bestellung.push($.extend(true, {}, $scope.Produkte[num]));
  78. };
  79. $scope.removeItem = function (item) {
  80. $scope.Bestellung = _.without($scope.Bestellung, item);
  81. };
  82. $scope.checkOut = function () {
  83. $scope.OffeneBestellungen.push({ "Rechnung": $scope.Rechnung, "Bestellung": $scope.Bestellung });
  84. $scope.Bestellung = [];
  85. $scope.Rechnung = parseInt($scope.Rechnung, 10) + 1;
  86. window.localStorage.setItem("Rechnung", $scope.Rechnung);
  87. window.localStorage.setItem("OffeneBestellungen", JSON.stringify($scope.OffeneBestellungen));
  88. };
  89. if ($scope.OffeneBestellungen === null) {
  90. $scope.Rechnung = 1;
  91. $scope.OffeneBestellungen = [];
  92. } else {
  93. $scope.OffeneBestellungen = JSON.parse($scope.OffeneBestellungen);
  94. }
  95. });