in source/web-client/app/scripts/controllers/order-edit.js [40:84]
$scope.saveOrder = function() {
var order = {
order_id: $scope.order.order_id,
productId: $scope.order.productId,
productSKU: $scope.productMap[$scope.order.productId].sku,
productDescription: $scope.productMap[$scope.order.productId].title,
orderedBy: $rootScope.currentUser,
dateOrdered: $scope.order.dateOrdered,
quantity: $scope.order.quantity,
unitCost: $scope.order.unitCost
};
$http.put(Constants.ORDER_MANAGER_URL + '/order', order)
.then(function(response) {
console.log('Order updated');
$location.path('/orders');
})
.catch(function(response) {
$scope.error = "Error updating order: " + response.message;
console.log("Error updating order: " + response.message);
});
if ($scope.order.quantity != $scope.order.originalQantity) {
var product = $scope.productMap[$scope.order.productId];
if ($scope.order.quantity > $scope.order.originalQantity) {
product.numberInStock -= ($scope.order.quantity - $scope.order.originalQantity);
}
else {
product.numberInStock += ($scope.order.originalQantity - $scope.order.quantity);
}
$http.put(Constants.PRODUCT_MANAGER_URL + '/product', product)
.then(function (response) {
console.log('Product inventory updated');
})
.catch(function (response) {
$scope.error = "Error updating product inventory: " + response.message;
console.log("Error updating product inventory: " + response.message);
})
}
$scope.order = {};
$scope.order.quantity = 1;
$route.reload();
};