dsesales.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. define(['app'], function (app) {
  2. app.directive('uploadImgFile', function ($rootScope) {
  3. return {
  4. restrict: 'A',
  5. scope: true,
  6. link: function (scope, element, attr) {
  7. element.on('change', function (event) {
  8. var files = event.target.files;
  9. if ($rootScope.imageFormat.indexOf(files[0].type) != -1) {
  10. $rootScope.prodimage = files[0];
  11. } else {
  12. $rootScope.$apply(function () {
  13. $rootScope.modalShown = true;
  14. $rootScope.message = "Please select Image format only"
  15. angular.element("input[type='file']").val(null);
  16. })
  17. }
  18. })
  19. }
  20. }
  21. })
  22. function readURL(input) {
  23. var num = current_imageObject.attr('data-id');
  24. console.log(num)
  25. if (input.files && input.files[0]) {
  26. var reader = new FileReader();
  27. reader.onload = function (e) {
  28. $('#store_image_' + num)
  29. .attr('src', e.target.result)
  30. .width(119)
  31. .height(112);
  32. }
  33. reader.readAsDataURL(input.files[0]);
  34. }
  35. }
  36. app.directive('thumbUploadFile', function ($rootScope) {
  37. return {
  38. restrict: 'A',
  39. scope: true,
  40. link: function (scope, element, attr) {
  41. element.on('change', function (event) {
  42. var files = event.target.files;
  43. if ($rootScope.imageFormat.indexOf(files[0].type) != -1) {
  44. $rootScope.uploadthumbimage.push(files[0]);
  45. } else {
  46. $rootScope.$apply(function () {
  47. $rootScope.modalShown = true;
  48. $rootScope.message = "Please select CSV format only"
  49. angular.element("input[type='file']").val(null);
  50. })
  51. }
  52. })
  53. }
  54. }
  55. })
  56. app.directive('uploadingFileContent', function ($rootScope) {
  57. return {
  58. restrict: 'A',
  59. scope: true,
  60. link: function (scope, element, attr) {
  61. element.on('change', function (event) {
  62. var files = event.target.files;
  63. console.log(files[0])
  64. console.log($rootScope.file_Format.indexOf(files[0].type))
  65. if ($rootScope.filetype_format == 1) {
  66. } if ($rootScope.file_Format.indexOf(files[0].type) != -1) {
  67. $rootScope.uploadfile.push(files[0]);
  68. // console.log($rootScope.uploadfile.length)
  69. // console.log($rootScope.uploadfile.length)
  70. } else {
  71. $rootScope.$apply(function () {
  72. $rootScope.modalShown = true;
  73. $rootScope.message = "Please select excel file format only"
  74. angular.element("input[type='file']").val(null);
  75. })
  76. }
  77. })
  78. }
  79. }
  80. })
  81. app.service("UploadProdService", function ($http, $rootScope, $timeout) {
  82. var service = {}
  83. service.upload = upload;
  84. var returnfun;
  85. function upload(formData, scope) {
  86. console.log("File : ",formData);
  87. returnfun = scope
  88. $rootScope.loadingCont = true;
  89. var xhr;
  90. if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  91. xhr = new XMLHttpRequest();
  92. } else {// code for IE6, IE5
  93. xhr = new ActiveXObject("Microsoft.XMLHTTP");
  94. }
  95. //this._scope['formLoad'] = false;
  96. xhr.upload.addEventListener("progress", uploadProgress, false)
  97. xhr.addEventListener("load", function (evt) {
  98. returnfun(evt.target.responseText);
  99. }, false)
  100. xhr.addEventListener("error", uploadFailed, false)
  101. xhr.addEventListener("abort", uploadCanceled, false)
  102. xhr.open("POST", "../services/excelupload.php")
  103. $rootScope.progressVisible = true
  104. xhr.send(formData);
  105. }
  106. function uploadProgress(evt) {
  107. $rootScope.$apply(function () {
  108. if (evt.lengthComputable) {
  109. } else {
  110. }
  111. })
  112. }
  113. function uploadComplete(evt) {
  114. }
  115. function uploadFailed(evt) {
  116. $rootScope.$apply(function () {
  117. $rootScope.loadingCont = false;
  118. })
  119. }
  120. function uploadCanceled(evt) {
  121. $rootScope.$apply(function () {
  122. $rootScope.loadingCont = false;
  123. })
  124. }
  125. return service;
  126. })
  127. app.controller('DSESalesCtrl', function ($scope, $rootScope, AppData, $location, UploadProdService) {
  128. //Every module Set Same Variable//
  129. $rootScope.menucont = true;
  130. $rootScope.pageLoadComp = false;
  131. $scope.formLoad = false;
  132. $scope.listFound = false;
  133. $scope.pageData = notificationData[$rootScope.selLanguage];
  134. $scope.formAction = "Add";
  135. $rootScope.sideselect = $scope.pageData.sidemenu[0];
  136. $scope.itemdetail = [];
  137. $scope.selectedIndex = null;
  138. $rootScope.cofirmWindow = false;
  139. $scope.submenu = $scope.pageData.sidemenu;
  140. $scope.tblheading = $rootScope.sideselect.headingText;
  141. $scope.url = "../senddata/log/";
  142. //$scope.pageurl = "../senddata/notification/";
  143. $scope.commonurl = "../senddata/common/";
  144. $scope.cat_error = '';
  145. $scope.topic_error = '';
  146. //filter data
  147. $scope.common_filter = [];
  148. $scope.zonearr = [];
  149. $scope.search_box = true;
  150. $rootScope.modalShown = false;
  151. $rootScope.cofirmWindow = false;
  152. //pagination
  153. $scope.viewby = '10';
  154. $scope.currentPage = 1;
  155. $scope.pageSize = 10;
  156. $scope.maxSize = 5;
  157. $scope.itemsPerPage = $scope.viewby;
  158. $scope.maxSize = 5;
  159. $scope.choice = {};
  160. $scope.choice.filelang = '';
  161. //Check Session//
  162. $scope.formData = {}
  163. $rootScope.formData = {}
  164. $scope.formData.ismenuload = "Yes";
  165. if ($rootScope.items == undefined || $rootScope.items == null) {
  166. $scope.formData.ismenuload = "No";
  167. }
  168. $scope.formData.funName = "checksession";
  169. $scope.formData.lang = $rootScope.selLanguage;
  170. // $scope.formData.start = 0;
  171. // $scope.formData.limit = 2;
  172. $rootScope.file_Format = ["csv","application/vnd.ms-excel" ];
  173. $rootScope.imageFormat = ["image/jpeg", "image/png"];
  174. $rootScope.pdfFormat = ["application/pdf"];
  175. $rootScope.fileFormat = ["video/mp4", "application/pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx"];
  176. $rootScope.docFormat = ["doc", "docx", "xls", "xlsx", "ppt", "pptx"];
  177. $rootScope.prodimage = '';
  178. $rootScope.uploadfile = [];
  179. $rootScope.uploadthumbimage = [];
  180. $scope.enableeditbox = false;
  181. $scope.cat_error = '';
  182. $scope.topic_error = '';
  183. AppData.sendData($scope.url, $scope.formData, function (res) {
  184. if (res.cont) {
  185. if ($rootScope.items == undefined || $rootScope.items == null) {
  186. $rootScope.items = res.item.control;
  187. }
  188. for (var i = 0; i < $rootScope.items.length; i++) {
  189. if ($location.path() == $rootScope.items[i].modulepath) {
  190. $rootScope.modulename = $rootScope.items[i].modulename;
  191. $scope.usercontrol = String($rootScope.items[i].permission).split("|");
  192. }
  193. }
  194. $scope.listFound = true;
  195. $scope.statusobj = res.item.status;
  196. $rootScope.username = res.item.username;
  197. } else {
  198. $location.path("/login");
  199. }
  200. })
  201. $scope.filesubmmit = function () {
  202. if ($scope.fieldValidationTopic()) {
  203. var formData = new FormData();
  204. if ($scope.formData.salesdate == '' || $scope.formData.salesdate == undefined) {
  205. $scope.startMonth = moment($scope.startingMonth).format("M");
  206. $scope.startYear = moment($scope.startingMonth).format("YYYY");
  207. $scope.monthpicker = moment().format("MMM YYYY")
  208. } else {
  209. $scope.monthpicker = moment($scope.formData.salesdate).format("MMM YYYY")
  210. $scope.startMonth = moment($scope.formData.salesdate).format("M");
  211. $scope.startYear = moment($scope.formData.salesdate).format("YYYY");
  212. }
  213. $scope.formData.salesdate=moment($scope.startingMonth).format("YYYY-MM-DD")
  214. console.log($scope.formData.salesdate)
  215. // $scope.formData.funName = "dsesalesdata";
  216. formData.append("funName", "dsesalesdata");
  217. formData.append("salesdate", $scope.formData.salesdate);
  218. if ($rootScope.uploadfile.length != 0) {
  219. formData.append("file", $rootScope.uploadfile[0]);
  220. // console.log($rootScope.uploadfile[0])
  221. }
  222. console.log(formData);
  223. UploadProdService.upload(formData, function (data) {
  224. //console.log(data)
  225. var response = JSON.parse(data)
  226. $scope.$apply(function () {
  227. $scope.formData = {}
  228. $rootScope.modalShown = true;
  229. $rootScope.message = response.mess;
  230. //$scope.filesubmmit();
  231. $scope.formLoad = false;
  232. $rootScope.loadingCont = false;
  233. $rootScope.pageLoadComp = true;
  234. })
  235. });
  236. }
  237. }
  238. $scope.fieldValidationTopic = function () {
  239. $scope.formData.salesdate = $("#salesdate").val();
  240. $scope.date_error = ($scope.formData.salesdate == '' || $scope.formData.salesdate == undefined) ? 'Please select the date' : '';
  241. $scope.topic_image_error = ($rootScope.uploadfile[0] == undefined || $rootScope.uploadfile[0] == '') ? 'Please choose the file' : '';
  242. return ($scope.date_error == '' && $scope.topic_image_error == '') ? true : false;
  243. }
  244. });
  245. });