<commit_before>﻿CREATE PROCEDURE [employer_financial].[GetAccountTransferBalance]
	@accountId BIGINT NOT NULL	
AS

SET NOCOUNT ON

	DECLARE @currentDate AS DATETIME = GETDATE()
	DECLARE @currentYear AS INT = DATEPART(year, @currentDate)
	DECLARE @financialYearStartDate AS DATETIME
	DECLARE @financialYearEndDate AS DATETIME

	BEGIN
	IF DATEPART(month, @currentDate) > 4
		BEGIN
			SELECT @financialYearStartDate = CONVERT(datetime, CONCAT(@currentYear - 1, '-04-18 00:00:00')),
			 @financialYearEndDate = CONVERT(datetime, CONCAT(@currentYear, '-03-18 23:59:59'))	
		END
	ELSE
		BEGIN
			SELECT @financialYearStartDate = CONVERT(datetime, CONCAT(@currentYear - 2, '-04-18 00:00:00')),
			 @financialYearEndDate = CONVERT(datetime, CONCAT(@currentYear - 1, '-03-18 23:59:59'))	
		END
	END

	SELECT SUM(Amount) * 0.1 FROM [employer_financial].[TransactionLine] 
	WHERE TransactionDate >= @financialYearStartDate
	AND TransactionDate <= @financialYearEndDate
	AND TransactionType = 1
	AND AccountId = @accountId
<commit_msg>Refactored SQL stored proc to use better date creation code<commit_after>﻿CREATE PROCEDURE [employer_financial].[GetAccountTransferBalance]
	@accountId BIGINT NOT NULL	
AS
	SET NOCOUNT ON

	DECLARE @currentDate AS DATETIME = GETDATE()
	DECLARE @currentYear AS INT = DATEPART(year, @currentDate)
	DECLARE @financialYearStartDate AS DATETIME
	DECLARE @financialYearEndDate AS DATETIME

	BEGIN
		IF DATEPART(month, @currentDate) > 4
			BEGIN
				SELECT @financialYearStartDate = DATEFROMPARTS(@currentYear - 1, 4, 18),
				 @financialYearEndDate = DATEFROMPARTS(@currentYear, 3, 19)
			END
		ELSE
			BEGIN
				SELECT @financialYearStartDate = DATEFROMPARTS(@currentYear - 2, 4, 18),
				 @financialYearEndDate = DATEFROMPARTS(@currentYear - 1, 3, 19)
			END
	END

	SELECT SUM(Amount) * 0.1 FROM [employer_financial].[TransactionLine] 
	WHERE TransactionDate >= @financialYearStartDate
	AND TransactionDate <= @financialYearEndDate
	AND TransactionType = 1
	AND AccountId = @accountId

	GO

{'fraction_non_alphanumeric': 0.0935788949726232, 'fraction_numerical': 0.03285216525634644, 'mean_word_length': 5.261682242990654, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '7664949', 'n_tokens_mistral': 786, 'n_tokens_neox': 638, 'n_words': 172}