No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

154 líneas
5.8KB

  1. var selector = '#app-report-index';
  2. if($(selector).length) {
  3. var app = new Vue({
  4. el: selector,
  5. data: {
  6. loading: true,
  7. showLoading: true,
  8. showReport: false,
  9. tableReport: [],
  10. currentSection: 'users',
  11. sections: [
  12. {
  13. name: 'Utilisateurs',
  14. id: 'users',
  15. icon: 'fa-users',
  16. },
  17. {
  18. name: 'Points de vente',
  19. id: 'points-sale',
  20. icon: 'fa-map-marker',
  21. },
  22. {
  23. name: 'Distributions',
  24. id: 'distributions',
  25. icon: 'fa-calendar',
  26. }
  27. ],
  28. termSearchUser: '',
  29. usersArray: [],
  30. pointsSaleArray: [],
  31. distributionYearsArray: [],
  32. distributionYear: null,
  33. distributionsByMonthArray: []
  34. },
  35. mounted: function () {
  36. this.init();
  37. },
  38. methods: {
  39. init: function () {
  40. var app = this;
  41. axios.get("ajax-init", {params: {}})
  42. .then(function (response) {
  43. app.usersArray = response.data.usersArray;
  44. app.pointsSaleArray = response.data.pointsSaleArray;
  45. app.distributionYearsArray = response.data.distributionYearsArray;
  46. app.distributionYear = app.distributionYearsArray[app.distributionYearsArray.length - 1];
  47. app.distributionsByMonthArray = response.data.distributionsByMonthArray;
  48. app.loading = false;
  49. app.showLoading = false;
  50. });
  51. },
  52. changeSection: function (section) {
  53. this.currentSection = section.id;
  54. },
  55. countUsers: function () {
  56. var count = 0;
  57. for (var i = 0; i < this.usersArray.length; i++) {
  58. if (this.usersArray[i].checked) {
  59. count++;
  60. }
  61. }
  62. return count;
  63. },
  64. countPointsSale: function () {
  65. var count = 0;
  66. for (var i = 0; i < this.pointsSaleArray.length; i++) {
  67. if (this.pointsSaleArray[i].checked) {
  68. count++;
  69. }
  70. }
  71. return count;
  72. },
  73. countDistributions: function () {
  74. var count = 0;
  75. for (var i in this.distributionsByMonthArray) {
  76. for (var j = 0; j < this.distributionsByMonthArray[i].distributions.length; j++) {
  77. if (this.distributionsByMonthArray[i].distributions[j].checked) {
  78. count++;
  79. }
  80. }
  81. }
  82. return count;
  83. },
  84. countDistributionsByMonth: function (month) {
  85. var count = 0;
  86. for (var j = 0; j < this.distributionsByMonthArray[month].distributions.length; j++) {
  87. if (this.distributionsByMonthArray[month].distributions[j].checked) {
  88. count++;
  89. }
  90. }
  91. return count;
  92. },
  93. selectDistributions: function (month) {
  94. var countDistributions = this.countDistributionsByMonth(month);
  95. for (var j = 0; j < this.distributionsByMonthArray[month].distributions.length; j++) {
  96. Vue.set(this.distributionsByMonthArray[month].distributions[j], 'checked', countDistributions ? false : true);
  97. }
  98. this.reportChange();
  99. },
  100. generateReport: function (isDownload) {
  101. var app = this;
  102. app.showLoading = true;
  103. var data = new FormData();
  104. var idsUsersArray = [];
  105. for (var i = 0; i < app.usersArray.length; i++) {
  106. if (app.usersArray[i].checked) {
  107. idsUsersArray.push(app.usersArray[i].user_id);
  108. }
  109. }
  110. var idsPointsSaleArray = [];
  111. for (var i = 0; i < app.pointsSaleArray.length; i++) {
  112. if (app.pointsSaleArray[i].checked) {
  113. idsPointsSaleArray.push(app.pointsSaleArray[i].id);
  114. }
  115. }
  116. var idsDistributionsArray = [];
  117. for (var i in this.distributionsByMonthArray) {
  118. for (var j = 0; j < this.distributionsByMonthArray[i].distributions.length; j++) {
  119. if (this.distributionsByMonthArray[i].distributions[j].checked) {
  120. idsDistributionsArray.push(app.distributionsByMonthArray[i].distributions[j].id);
  121. }
  122. }
  123. }
  124. data.append('isDownload', isDownload ? 1 : 0);
  125. data.append('users', idsUsersArray);
  126. data.append('pointsSale', idsPointsSaleArray);
  127. data.append('distributions', idsDistributionsArray);
  128. axios.post("ajax-report", data)
  129. .then(function (response) {
  130. app.showLoading = false;
  131. if(isDownload) {
  132. saveData(response.data, 'rapport.csv');
  133. }
  134. else {
  135. app.tableReport = response.data;
  136. app.showReport = true;
  137. }
  138. });
  139. },
  140. reportChange: function () {
  141. this.showReport = false;
  142. }
  143. }
  144. });
  145. }