PageSourceSearch

https://wlivestock.com/app/views/account/manage/accountManageInvoicesController.js?v=buster20250808

js wlivestock.com collected 2026-10-04 06:05:17 UTC 12,340 bytes, 298 lines download raw bytes

1app.controller('accountManageInvoicesController', ['$scope', '$state', '$timeout', '$interval', '$q', '$location', 'localStorageService', 'permissionsService', 'authenticationService', 'invoicesService', 'lists',
2    function ($scope, $state, $timeout, $interval, $q, $location, localStorageService, permissionsService, authenticationService, invoicesService, lists) {
3
4        $scope.initializePage = function () {
5            $scope.$parent.activeChildView = $state.current.name.replace('accountManage.', '');
6
7            // Check to make sure they are logged in as a user        
8            permissionsService.isAuthenticated().then(function (results) {
9                if (!results.data) {
10                    popMessage("error", "Not Authorized", "You are not authorized to view this page. Please login to continue.");
11                    authenticationService.logout();
12                    $state.go('accountLogin');
13                } else {
14
15                    // Create an interval to check if the user has access with the environment vars
16                    $scope.checkEnvironmentVars = $interval(function () {
17                        if ($scope.settings.environment.allowInvoicing != null) {
18                            $interval.cancel($scope.checkEnvironmentVars);
19                            if ($scope.settings.environment.allowInvoicing == 'False') {
20                                // Check to see if the user has access
21                                popMessage("error", "Not Authorized", "You are not authorized to view this page. Please login to continue.");
22                                authenticationService.logout();
23                                $state.go('accountLogin');
24                            }
25                        }
26                    }, 250);
27
28                    $scope.getInvoices();
29
30                }
31            }, function (error) {
32                popApiErrorMessage(error);
33            });
34        };
35
36        $scope.getInvoices = function () {
37
38            $scope.isSearchInProgress = true;
39
40            var deferred = $q.defer();
41
42            var filterText = "";
43            if ($scope.filter.text && $scope.filter.text.length > 0) {
44                filterText = '%' + $scope.filter.text + '%';
45            }
46
47            var filterStatus = "";
48            if ($scope.filter.status && $scope.filter.status.length > 0) {
49                if ($scope.filter.status != "All") {
50                    filterStatus = $scope.filter.status;
51                }
52            }
53
54            invoicesService.getInvoicesByUser(filterText, filterStatus, $scope.sortField, $scope.sortDirection, $scope.pageNumber, $scope.pageSize).then(function (results) {
55
56                $scope.invoices = results.data.invoices;
57                $scope.totalItems = results.data.totalRows[0].totalRows;
58
59                $scope.pageIsLoaded = true;
60                $scope.isSearchInProgress = false;
61
62                deferred.resolve();
63
64            }, function (error) {
65                popApiErrorMessage(error);
66                $scope.isSearchInProgress = false;
67                deferred.resolve();
68            });
69
70            return deferred.promise;
71        };
72
73        $scope.toggleExpanded = function (invoice) {
74
75            if (invoice.isExpanded == null || invoice.isExpanded == false) {
76
77                invoice.isExpanded = true;
78                invoice.gettingInvoiceLineItems = true;
79
80                invoicesService.getInvoiceLineItemsByInvoiceId(invoice.invoiceId).then(function (results) {
81                    invoice.invoiceLineItems = results.data.invoiceLineItems;
82                    invoice.gettingInvoiceLineItems = false;
83                }, function (error) {
84                    popApiErrorMessage(error);
85                    invoice.gettingInvoiceLineItems = false;
86                });
87            } else {
88                invoice.isExpanded = false;
89            }
90
91        };
92        
93        $scope.formatDateAsUtc = function (dateToFormat) {
94            return formatDateOrDateStringAsUtcDate(dateToFormat);
95        };
96
97        $scope.viewInvoice = function (invoice) {
98            var deferred = $q.defer();
99
100            var invoiceId = null;
101
102            if (invoice != null) {
103                invoiceId = invoice.invoiceId;
104            }
105
106            invoicesService.downloadInvoices(invoice.auctionId, invoiceId).then(function (results) {
107
108                // Create the invoice(s) file name
109                var fileName = 'invoice';
110                if (invoice != null) {
111                    fileName += '_number_' + invoice.invoiceId;
112                } else {
113                    fileName += 's_for_auction_' + $scope.auction.auctionId;
114                }
115                fileName += '.pdf';
116
117                var ieEDGE = navigator.userAgent.match(/Edge/g);
118                var ie = navigator.userAgent.match(/.NET/g); // IE 11+
119                var oldIE = navigator.userAgent.match(/MSIE/g);
120
121                var blob = new window.Blob([results.data], { type: 'application/pdf' });
122
123                if (ie || oldIE || ieEDGE) {
124                    window.navigator.msSaveBlob(blob, fileName);
125                } else {
126
127                    //var objectUrl = (window.URL ? URL : webkitURL).createObjectURL(blob);
128                    //window.open(objectUrl, '_blank');
129
130                    var url = window.URL.createObjectURL(blob);
131                    var linkElement = document.createElement('a');
132                    linkElement.setAttribute('href', url);
133                    linkElement.setAttribute("download", fileName);
134
135                    //Force a download
136                    var clickEvent = new MouseEvent("click", {
137                        "view": window,
138                        "bubbles": true,
139                        "cancelable": false
140                    });
141                    linkElement.dispatchEvent(clickEvent);
142
143                }
144
145                deferred.resolve();
146
147            }, function (error) {
148                popApiErrorMessage(error);
149                $scope.isSearchInProgress = false;
150                deferred.resolve();
151            });
152            return deferred.promise;
153        };
154
155        $scope.adjustmentsFilter = function (lineItem) {
156            return lineItem.invoiceLineTypeId == 2 || lineItem.invoiceLineTypeId == 3;
157        };
158
159        $scope.addonsFilter = function (lineItem) {
160            return lineItem.invoiceLineTypeId == 4 || lineItem.invoiceLineTypeId == 5;
161        };
162
163        /***********************************************************************************************************************
164
165        Table sorting and paging methods
166
167        */
168
169        $scope.setSort = function (newSortField) {
170            // If the sort field is the same
171            if (newSortField == $scope.sortField) {
172                // set the sort direction to opposite of what it currently is
173                $scope.sortDirection == 'ASC' ? $scope.sortDirection = 'DESC' : $scope.sortDirection = 'ASC';
174            } else {
175                // Set the sort field as the new field and set the sort direction
176                $scope.sortField = newSortField;
177                $scope.sortDirection = 'ASC';
178            }
179
180            // Set the values in the query string
181            $scope.setQueryStringSearchParams();
182
183            // Re-get the data
184            $scope.getInvoices();  // CUSTOM PER CONTROLLER
185        };
186
187        $scope.pageResults = function (pagination) {
188            $scope.pageNumber = pagination.page;
189
190            // Set the values in the query string
191            $scope.setQueryStringSearchParams();
192
193            // Re-get the data
194            $scope.getInvoices();  // CUSTOM PER CONTROLLER
195        };
196
197        $scope.pageSizeChange = function (newpageSize) {
198            $scope.pageSize = newpageSize;
199
200            if ($scope.pageNumber * $scope.pageSize > $scope.totalItems && $scope.totalItems > 0) {
201                $scope.pageNumber = Math.ceil($scope.totalItems / $scope.pageSize);
202            }
203
204            // Set the values in the query string
205            $scope.setQueryStringSearchParams();
206
207            // Re-get the data
208            $scope.getInvoices();  // CUSTOM PER CONTROLLER
209        };
210
211        $scope.setQueryStringSearchParams = function () {
212
213            $location.search($scope.queryStringPrefix + "ft", $scope.filter.text);  // CUSTOM PER CONTROLLER
214            $location.search($scope.queryStringPrefix + "fs", $scope.filter.status);  // CUSTOM PER CONTROLLER
215
216            $location.search($scope.queryStringPrefix + "p", $scope.pageNumber);
217            $location.search($scope.queryStringPrefix + "ps", $scope.pageSize);
218            $location.search($scope.queryStringPrefix + "s", $scope.sortField);
219            $location.search($scope.queryStringPrefix + "sd", $scope.sortDirection);
220        };
221
222        $scope.getQueryStringSearchParams = function () {
223
224            var getAuctionsSinceFiltersHaveBeenApplied = false;
225
226            if (getParameterByName($scope.queryStringPrefix + "ft").length > 0) { // CUSTOM PER CONTROLLER
227                $scope.filter.text = getParameterByName($scope.queryStringPrefix + "ft");
228                getAuctionsSinceFiltersHaveBeenApplied = true;
229            }
230            if (getParameterByName($scope.queryStringPrefix + "fs").length > 0) { // CUSTOM PER CONTROLLER
231                $scope.filter.status = getParameterByName($scope.queryStringPrefix + "fs");
232                getAuctionsSinceFiltersHaveBeenApplied = true;
233            }
234
235            if (getParameterByName($scope.queryStringPrefix + "p").length > 0) {
236                $scope.pageNumber = Number(getParameterByName($scope.queryStringPrefix + "p"));
237                getAuctionsSinceFiltersHaveBeenApplied = true;
238            }
239            if (getParameterByName($scope.queryStringPrefix + "ps").length > 0) {
240                $scope.pageSize = Number(getParameterByName($scope.queryStringPrefix + "ps"));
241                getAuctionsSinceFiltersHaveBeenApplied = true;
242            }
243            if (getParameterByName($scope.queryStringPrefix + "s").length > 0) {
244                $scope.sortField = getParameterByName($scope.queryStringPrefix + "s");
245                getAuctionsSinceFiltersHaveBeenApplied = true;
246            }
247            if (getParameterByName($scope.queryStringPrefix + "sd").length > 0) {
248                $scope.sortDirection = getParameterByName($scope.queryStringPrefix + "sd");
249                getAuctionsSinceFiltersHaveBeenApplied = true;
250            }
251
252            if (getAuctionsSinceFiltersHaveBeenApplied) {
253                // Re-get the data since it isn't gathered when entering the page
254                $scope.getInvoices();  // CUSTOM PER CONTROLLER
255            }
256
257        };
258
259        // Set the default variables
260        $scope.availablePageSizes = lists.availablePageSizes;
261
262        $scope.queryStringPrefix = 'ami-';  // CUSTOM PER CONTROLLER
263
264        $scope.sortField = 'i.CreatedDate';  // CUSTOM PER CONTROLLER
265        $scope.sortDirection = 'ASC';
266        $scope.pageNumber = 1;
267        $scope.pageSize = 10;
268        $scope.totalItems = 0;
269
270        $scope.filter = {
271            text: null,
272            status: 'Unpaid'
273        };  // CUSTOM PER CONTROLLER        
274
275        $scope.isSearchInProgress = false;
276
277        // Check to see if any values got passed in the query string
278        $scope.getQueryStringSearchParams();
279
280        /*
281    
282        End table sorting and paging methods
283    
284        ***********************************************************************************************************************/
285
286        //initialize variables
287        $scope.user = localStorageService.get('AuthData');
288        
289        $scope.pageIsLoaded = false;
290
291        //If the page hasn't loaded after 1 second, signal that the ui can show the loading animation
292        $scope.canShowPageLoading = false;
293        $timeout(function () { $scope.canShowPageLoading = true; }, 1000);
294
295        //initialize Page
296        $scope.initializePage();
297    }
298]);

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.