File size: 2,733 Bytes
b3787d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
'use strict';

// Checkouts controller
angular.module('checkouts').controller('CheckoutsController', ['$scope', '$stateParams','$window', '$location', 'Authentication', 'Checkouts',
	function($scope, $stateParams, $window, $location, Authentication, Checkouts) {
		$scope.authentication = Authentication;
		$scope.currentPage = 1;
		$scope.pageSize = 10;
		$scope.offset = 0;
		$scope.uname = user.username;
		$scope.foo = '';

		// Page changed handler
		$scope.pageChanged = function () {
			$scope.offset = ($scope.currentPage - 1) * $scope.pageSize;
		};

		// Create new Checkout
		$scope.create = function () {
			// Create new Checkout object
			var checkout = new Checkouts({
				PartNumber: this.PartNumber,
				PartType: this.PartType,
				Ecode: this.Ecode,
				Description:this.Description,
				Qty: this.Qty,
				Vendor: this.Vendor,
				Cost: this.Cost,
				RefDes: this.RefDes
			});

			// Redirect after save
			checkout.$save(function (response) {
				$location.path('checkouts/' + response._id);

				// Clear form fields
				$scope.name = '';
			}, function (errorResponse) {
				$scope.error = errorResponse.data.message;
			});
		};

		// Remove existing Checkout
		$scope.remove = function (checkout) {
			if (checkout) {
				checkout.$remove();

				for (var i in $scope.checkouts) {
					if ($scope.checkouts [i] === checkout) {
						$scope.checkouts.splice(i, 1);
					}
				}
			} else {
				$scope.checkout.$remove(function () {
					$location.path('checkouts');
				});
			}
		};

		// Update existing Checkout
		$scope.update = function () {
			var checkout = $scope.checkout;

			checkout.$update(function () {
				$location.path('carts/create');
			}, function (errorResponse) {
				$scope.error = errorResponse.data.message;
			});
		};

		// Find a list of Checkouts
		$scope.find = function () {
			$scope.checkouts = Checkouts.query();
		};

		// Find existing Checkout
		$scope.findOne = function () {
			$scope.checkout = Checkouts.get({
				checkoutId: $stateParams.checkoutId
			});
		};

		// Search for a checkout
		$scope.checkoutSearch = function (product) {
			$location.path('checkouts/' + product._id);
		};

		//update with user checkout
		$scope.cqty = "";
		$scope.console = function () {
			if($scope.checkout.Cost >= 100 && user.roles != 'edit'){
				alert('Contact Manager');
				$location.path('/');
				return true;
			};
			localStorage.setItem('qty', $scope.cqty);
			var adjqty = ($scope.checkout.Qty - $scope.cqty);
			$scope.checkout.Qty = adjqty;
			localStorage.setItem('pnum', $scope.checkout.PartNumber);
			$scope.update();
			//$window.open("#!/carts/create", "_self");
		};

		$scope.capture = function () {
			localStorage.setItem('snum', $scope.foo);
		};
	}
]);