PageSourceSearch

https://smartrack.live/js/controller/zee-report-controller.js

js smartrack.live collected 2026-10-02 01:07:01 UTC 9,691 bytes, 287 lines download raw bytes

1angular.module('IotaSmart.controller')
2
3	.controller('zeeReportCtrl', function ($scope, $rootScope, ZeeReportService, $state, $window, LoginService, HomeService, $uibModal, $filter) {
4		$scope.pageTitle = "Zee Report";
5
6		$scope.isZeeReport = true;
7		if (!LoginService.getSession())
8			$rootScope.logout();
9
10		if (!$rootScope.user && $window.localStorage['user'])
11			$rootScope.user = JSON.parse($window.localStorage['user']);
12
13		var setToMidNight = function (date) {
14			date.setHours(0);
15			date.setMinutes(0);
16			date.setSeconds(0);
17		}
18		/*Date Range*/
19		$scope.historyRange = "today";
20		var firstDate = new Date();
21		setToMidNight(firstDate);
22		$scope.date = { fromDate: firstDate, toDate: new Date() };
23		$scope.date.toDate.setHours(23);
24		$scope.date.toDate.setMinutes(59);
25		$scope.date.toDate.setSeconds(59);
26		$scope.date.fromDateString = "From";
27		$scope.date.toDateString = "To";
28
29		$scope.startDateBeforeRender = startDateBeforeRender;
30		$scope.startDateOnSetTime = startDateOnSetTime;
31		$scope.endDateBeforeRender = endDateBeforeRender;
32		$scope.endDateOnSetTime = endDateOnSetTime;
33
34		function startDateOnSetTime() {
35			$scope.$broadcast('start-date-changed');
36			$scope.date.fromDateString = $filter('date')($scope.date.fromDate, $rootScope.dateformat, $rootScope.offset);
37		}
38
39		function endDateOnSetTime() {
40			$scope.$broadcast('end-date-changed');
41			$scope.date.toDate.setHours(23);
42			$scope.date.toDate.setMinutes(59);
43			$scope.date.toDate.setSeconds(59);
44			$scope.date.toDateString = $filter('date')($scope.date.toDate, $rootScope.dateformat, $rootScope.offset);
45
46		}
47		var futureDate = new Date();
48		futureDate.setDate(futureDate.getDate());
49
50		function startDateBeforeRender($dates) {
51			if ($scope.date.toDate) {
52				var activeDate = moment($scope.date.toDate);
53				$dates.filter(function (date) {
54					return date.localDateValue() >= activeDate.valueOf()
55				}
55).forEach(function (date) {
56					date.selectable = false;
57				})
58
59				var disableDate = moment(futureDate);
60				$dates.filter(function (date) {
61					return date.localDateValue() >= disableDate.valueOf()
62				}).forEach(function (date) {
63					date.selectable = false;
64				})
65			}
66		}
67
68		function endDateBeforeRender($view, $dates) {
69			if ($scope.date.fromDate) {
70				var activeDate = moment($scope.date.fromDate).subtract(1, $view).add(1, 'day');
71				$dates.filter(function (date) {
72					return date.localDateValue() < activeDate.valueOf()
73				}).forEach(function (date) {
74					date.selectable = false;
75				})
76				var disableDate = moment(new Date());
77				$dates.filter(function (date) {
78					return date.localDateValue() > disableDate.valueOf()
79				}).forEach(function (date) {
80					date.selectable = false;
81				})
82			}
83		}
84
85		$scope.$on('$viewContentLoaded', function ($evt) {
86			$scope.getReportList();
87		});
88
89		$scope.getReportList = function () {
90			$scope.fileName = $filter('date')(new Date(), $rootScope.fullDateFormat, $rootScope.offset);
91			var firstDate = $scope.date.fromDate.getTime();
92			var lastDate = $scope.date.toDate.getTime();
93			$scope.reportList = [];
94			$scope.downloadList = [];
95			$scope.downloadListPdf = [['SR No', 'Driver Name', 'Car Type', 'Cab NO', 'Opening KM', 'Closing KM', 'Total KM', 'Trip Out Time', 'Trip In Time',
96				'Location', 'Story Covered', 'User Name', 'User Channel Name', 'Remarks']];
97			ZeeReportService.getReportList($rootScope.user.id, firstDate, lastDate)
98				.then(function successCallback(res) {
99					console.log(res);
100					if (res.status == 200 && res.data) {
101						$scope.reportList = res.data;					
102						for (var i = 0; i < $scope.reportList.length; i++) {
103							var report = $scope.reportList[i];
104							report.openingKM = Math.round(report.openingKM / 1000);
105							report.closingKM = Math.round(report.closingKM/1000);
106							report.totalKM = Math.round(report.totalKM/1000);
107							
108							var data = {
109								sNo: i + 1, dName: report.driverName, cType: report.carType,
110								cabNo: report.cabNo, openingKM: report.openingKM, closingKM: report.closingKM, totalKM: report.totalKM,
111								tripOutTime: $filter('date')(report.tripOutTime, $rootScope.fullDateFormat, $rootScope.offset), tripInTime: $filter('date')(report.tripInTime, $rootScope.fullDateFormat, $rootScope.offset),
112								location: report.location, storyCovered: report.storyCovered, remarks: report.remarks, userNames: report.userNames,
113								userChannelName: report.userChannelName
114							}
115							$scope.downloadList.push(data);
116							var pdfData = [data.sNo, data.dName, data.cType, data.cabNo, data.openingKM, data.closingKM, data.totalKM, data.tripOutTime, data.tripInTime,
117							data.location, data.storyCovered, data.userNames, data.userChannelName, data.remarks]
118							$scope.downloadListPdf.push(pdfData);
119						}						
120					}
121
122				})
123		}
124		
125		$scope.goToTrip = function (deviceId) {
126			console.log(deviceId);
127			var index;
128			for (var i = 0; i < $rootScope.deviceList.length; i++) {
129				var dev = $rootScope.deviceList[i];
130				if(dev.id == deviceId){
131					index = i;
132					break;
133				}
134			}
135			
136			$state.go("trip", { deviceIndex: index });
137		}
138
139		$scope.showADForm = function () {
140			var modalInstance = $uibModal.open({
141				animation: true,
142				templateUrl: 'views/modal/add-dutyZee.html',
143				controller: 'addDutyZeeCtrl',
144				backdrop: 'static',
145			});
146			modalInstance.result.finally(function () {
147				$scope.getReportList();
148			});
149		}
150
151		$scope.reloadHistory = function () {
152			$scope.date.fromDateString = "From";
153			$scope.date.toDateString = "To";
154			if ($scope.historyRange == 'today') {
155				var firstDate = new Date();
156				setToMidNight(firstDate);
157				console.log(firstDate);
158				$scope.date.fromDate = firstDate;
159				$scope.date.toDate = new Date();
160				$scope.date.toDate.setHours(23);
161				$scope.date.toDate.setMinutes(59);
162				$scope.date.toDate.setSeconds(0);				
163				$scope.getReportList();
164
165			} else if ($scope.historyRange == 'last24') {
166				var firstDate = new Date();
167				firstDate.setHours(firstDate.getHours() - 24);
168				$scope.date.fromDate = firstDate;
169				$scope.date.toDate = new Date();
170				$scope.getReportList();
171			} else if ($scope.historyRange == 'last7') {
172				var firstDate = new Date();
173				firstDate.setDate(firstDate.getDate() - 7);
174				setToMidNight(firstDate);
175				$scope.date.fromDate = firstDate;
176				$scope.date.toDate = new Date();
177				$scope.getReportList();
178			} else {
179				resetTimeline();
180			}
181		}
182		$scope.applyDate = function () {
183			console.log($scope.date.fromDate);
184			console.log($scope.date.toDate);
185			$scope.getReportList();
186		}
187
188		$scope.pdfReportDownload = function () {
189			var docDefinition = {
190				pageSize: 'A3',
191				content: [{
192					table: {
193						headerRows: 1,
194						body: $scope.downloadListPdf
195					}
196				}]
197			};
198			pdfMake.createPdf(docDefinition).download($filter('date')(new Date(), $rootScope.fullDateFormat, $rootScope.offset));
199		}
200
201
202		var resetTimeline = function () {
203			$scope.downloadList = [];
204			$scope.downloadListPdf = [['SR No', 'Date', 'Driver Name', 'Car Type', 'Cab NO', 'Opening KM', 'Closing KM', 'Total KM',
205				'Trip Out Time', 'Trip In Time', 'Location', 'Story Covered', 'User Name', 'User Channel Name', 'Remarks']]
206		}
207
208	})
209
210	.controller('addDutyZeeCtrl', function ($scope, $timeout, $uibModalInstance, $filter, $rootScope, ZeeReportService, $state, $window, LoginService, HomeService, $uibModal) {
211		$scope.isUpdating = false;
212		$scope.addDMsg = '';
213		$scope.deviceList = $rootScope.deviceList;
214		$scope.addDErr = false;
215		$scope.dutyData = { userId: $rootScope.user.id };
216
217		$scope.cancel = function () {
218			$uibModalInstance.dismiss('cancel');
219		};
220
221		/*Date Range*/
222		$scope.startDateBeforeRender = startDateBeforeRender;
223		$scope.startDateOnSetTime = startDateOnSetTime;
224
225		function startDateOnSetTime() {
226			$scope.$broadcast('start-date-changed');
227		}
228		function startDateBeforeRender($dates) {
229		}
230
231		/*Date Range END*/
232
233		$scope.addDuty = function () {
234			// $scope.isUpdating = true;
235			$scope.dutyData.outDateAndTime = $filter('date')($scope.dutyData.outDateAndTime, 'dd-M
235M-yyyy HH:mm:ss');
236			$scope.dutyData.carType = $scope.dutyData.deviceId.carMake + ' ' + $scope.dutyData.deviceId.carModel;
237			$scope.dutyData.cabNo = $scope.dutyData.deviceId.name;
238			$scope.dutyData.deviceId = $scope.dutyData.deviceId.id;
239			
240
241			console.log($scope.dutyData);
242			ZeeReportService.addDuty($scope.dutyData)
243				.then(function successCallback(res) {
244					$scope.isUpdating = false;
245					if (res.status == 200) {
246
247						alert('Duty added sucessfully!');
248						$uibModalInstance.dismiss('cancel');
249					}
250					else if (res.status == 208) {
251						$scope.addDErr = true;
252						alert('Duty already exists!');
253					}
254					else {
255						$scope.addDErr = true;
256						alert('Unable to add duty! please try again later');
257					}
258//					$timeout(function () {
259//						clearADMessage();
260//					}, 4000);
261				}, function errorCallback(err) {
262					$scope.isUpdating = false;
263					$scope.addDErr = true;
264					alert('Unable to add device! please try again later');
265//					$timeout(function () {
266//						clearADMessage();
267//					}, 2000);
268				});
269		}
270
271		var clearADMessage = function () {
272			$scope.addDMsg = '';
273			$scope.addDErr = '';
274			$scope.dutyData = {
275				userId: $rootScope.user.id,
276				outDateAndTime: new Date(),
277				driverName: '',
278				storyCovered: '',
279				userChannelName: '',
280				userNames: '',
281				remarks: '',
282				deviceId: $scope.deviceList[0],
283				carType: ''
284			}
285		}
286	})
287

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.