You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 line
5.0KB

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