;; Sri Ganeshji : Sri Balaji : Sri Pitreshwarji : Sri Durgaji : Sri Venkateshwara

/*
Objective(s) -
-	This code introduces the concept of User Defined Functions with a basic Compound
	Interest Calculation code
*/

;;Compound interest calculator report will be triggered from Gateway of Tally menu
[#Menu: Gateway of Tally]

	Add	: Item	: Before : @@locQuit	: Compound Interest Calculator		: Alter	: Compound Interest Calculator
    	  
[Report: Compound Interest Calculator]

	Form	: Interest Calc
	Auto	: Yes

[Form: Interest Calc]

	Parts	: Form SubTitle, Interest Calc
	Local	: Field	: Form SubTitle		: Info		: "Compound Interest Calculator"   ;; locally set report title
	Width	: 30% Page                ;;; Setting form width to 30% page

[Part: Interest Calc]

	Lines	: Interest Principal, Interest Rate, Interest NoOfYrs, Interest Result

	[Line: Interest Principal]

		Fields	: Medium Prompt, Interest Principal
		Local	: Field	: Medium Prompt	: Info		: "Principal Amount :"

		[Field: Interest Principal]

			Use			: Amount Field

	[Line: Interest Rate]

		Fields	: Medium Prompt, Interest Rate
		Local	: Field	: Medium Prompt	: Info		: "Rate :"

		[Field: Interest Rate]

			Use			: Number Field
			Format		: "No Zero, Percentage"
			Align		: Right
		    Width       : @@AmountWidth

	[Line: Interest NoOfYrs]

		Fields	: Medium Prompt, Interest NoOfYrs
		Local	: Field	: Medium Prompt	: Info		: "Tenure :"

		[Field: Interest NoOfYrs]

			Use			: Number Field
			Format		: "NoZero"
			Align		: Right
		    Width       : @@AmountWidth

	[Line: Interest Result]

		Fields	: Medium Prompt, Interest Result
		Local	: Field	: Medium Prompt		: Info		: "Compound Interest Amount :"
		Local	: Field	: Default			: Inactive	: $$IsEmpty:#InterestPrincipal OR $$IsEmpty:#InterestRate OR $$IsEmpty:#InterestNoOfYrs
		SpaceTop: 1

		[Field: Interest Result]

			Use			: Amount Field
			Set Always	: Yes
			Set As		: $$CIExpCalc:#InterestPrincipal:#InterestRate:#InterestNoOfYrs    ;;;User defined function is called with three parameter

;; Function to calculate Compound Interest

[Function: CIExp Calc]

;; Definition Block

	Parameter	: P			: Amount
	Parameter	: R			: Number
	Parameter	: T			: Number
    
;;Return type of the function is amount
	Returns		: Amount

;;Defining variables in the function
	Variable	: Interest	: Amount
	Variable	: IntPYear	: Amount
	Variable	: Counter	: Number

;; Procedural Block

	01 : SET	: Counter	: 0
	02 : SET	: Interest	: 1
	03 : SET	: Interest	: (1 + (##R/100))
	05 : SET	: Interest	: $$Exponential:##Interest:##T
	06 : SET	: Interest	: (##P * ##Interest) - ##P
	07 : RETURN	: ##Interest

;; Function to calculate Exponential of a Number

[Function: Exponential]

;; Definition Block

	Parameter	: X 		: Amount
	Parameter	: T			: Number
	Returns		: Amount

	Variable	: ExpResult	: Amount
	Variable	: Counter	: Number

;; Procedural Block

	01 : SET 	: Counter	: 0
	02 : SET	: ExpResult	: 1

	03 : WHILE	: (##Counter < ##T)
	04 : 	SET			: ExpResult		: ##ExpResult * ##X
	05 : 	INCREMENT	: Counter
	06 : END WHILE
	
	07 : RETURN	: ##ExpResult

;; End-of-File
