<commit_before>app.controller('sales_new_ctrl', function ($scope, ajaxService) {

	$scope.customers = [];
	$scope.selected = undefined;
	$scope.reference = [];

	$scope.init = function() {
		ajaxService.get("customers.json", "").then(function(data) {
			var customer = data.customers;
			$scope.customer = customer;
		});		
	};

	$scope.type_ahead_customer = function (item, model, label) {		
	    $('#sale_customer_id').val(item.id);
	    for (var i = 0; i < $scope.customer.length; i++) {
	    	if ($scope.customer[i].id == item.id) {
	    		$scope.reference = $scope.customer[i].contacts;
	    		$('#sale_payment_term').val($scope.customer[i].payment_term);
	    	}
	    }
	};

	$scope.type_ahead_customer_reference = function (item, model, label) {
	    $('#sale_contact_name').val(item.name); 
	    $('#sale_contact_email').val(item.email); 
	};

});

app.controller('sale_items_new_ctrl', function ($scope) {
	$scope.batch = {};
	$scope.options = {};
	$scope.show_batch = false;
	
	var bch_id = $('#sale_item_batch_id').val();
	var item_id = $('#sale_item_item_id').val();

	$scope.item_id = item_id;
	$scope.batch.id = bch_id;

	$scope.init = function() {
		$scope.item_changed();
		alert(JSON.stringify(gon.products[0]));
		$scope.product_value = gon.products[0].value;
	};
	$scope.product_changed = function() {
		var dPrice = 0;		
		var rPrice = 0;
		$('#sale_item_price').val(0);
		var reseller = $('#sale_customer_reseller').is(":checked");
		for (var x=0; x < gon.products.length; x++) {
			if (gon.products[x].value == $scope.product_value) {
				//Set prices
				//alert(JSON.stringify(gon.products[x]));
				dPrice = gon.products[x].distributor_price;
				rPrice = gon.products[x].retail_price;
			};

			if (reseller) {
				$('#sale_item_price').val(dPrice);
			}
			else  {
				$('#sale_item_price').val(rPrice);
			};
		}
	};

	$scope.select_quantity = function() {
		for (i=0; i< gon.products.length; i++) {
			if (gon.products[i].value == $scope.product_value) {
				if ($scope.quantity > gon.products[i].available_quantity)
					alert("Kvantitet överstiger lagrets " + gon.products[i].available_quantity);
			}
		}
	}
});
<commit_msg>javascript clean up<commit_after>app.controller('sales_new_ctrl', function ($scope, ajaxService) {

	$scope.customers = [];
	$scope.selected = undefined;
	$scope.reference = [];

	$scope.init = function() {
		ajaxService.get("customers.json", "").then(function(data) {
			var customer = data.customers;
			$scope.customer = customer;
		});		
	};

	$scope.type_ahead_customer = function (item, model, label) {		
	    $('#sale_customer_id').val(item.id);
	    for (var i = 0; i < $scope.customer.length; i++) {
	    	if ($scope.customer[i].id == item.id) {
	    		$scope.reference = $scope.customer[i].contacts;
	    		$('#sale_payment_term').val($scope.customer[i].payment_term);
	    	}
	    }
	};

	$scope.type_ahead_customer_reference = function (item, model, label) {
	    $('#sale_contact_name').val(item.name); 
	    $('#sale_contact_email').val(item.email); 
	};

});

app.controller('sale_items_new_ctrl', function ($scope) {

	$scope.init = function() {
		$scope.product_value = gon.products[0].value;
	};

	$scope.product_changed = function() {
		var dPrice = 0;		
		var rPrice = 0;
		$('#sale_item_price').val(0);
		var reseller = $('#sale_customer_reseller').is(":checked");
		for (var x=0; x < gon.products.length; x++) {
			if (gon.products[x].value == $scope.product_value) {
				//Set prices
				//alert(JSON.stringify(gon.products[x]));
				dPrice = gon.products[x].distributor_price;
				rPrice = gon.products[x].retail_price;
			};

			if (reseller) {
				$('#sale_item_price').val(dPrice);
			}
			else  {
				$('#sale_item_price').val(rPrice);
			};
		}
	};

	$scope.select_quantity = function() {
		for (i=0; i< gon.products.length; i++) {
			if (gon.products[i].value == $scope.product_value) {
				if ($scope.quantity > gon.products[i].available_quantity)
					alert("Kvantitet överstiger lagrets " + gon.products[i].available_quantity);
			}
		}
	}
});

{'fraction_non_alphanumeric': 0.19216464170592612, 'fraction_numerical': 0.0037193156459211507, 'mean_word_length': 3.7570754716981134, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1054810', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1444, 'n_words': 218}