!!! acc_tax_transaction should have item_id

Overview
Capital Goods = any goods which are capitalized for accounting purposes and written off over several years
* if the capital item is used to make wholly Taxable supplies, GST Input claimable is 100%
* if the capital item is used to make wholly Exempt supplies, GST Input claimable is 0%
* if the capital item is used to make both Taxable and Exempt supplies, GST Input claimable has to be apportioned to IRR

Capital Goods Adjustment
* Is the adjustment that needs to be made to the initial amount of GST Input claimed, during a specific period if there is a change in the proportion of taxable use of the capital goods
* it must be carried out for assets over Rm100,000, which are used for both Taxable and Exempt (mixed) supplies
* it must be carried out for up to 10 intervals for land & building, 5 intervals for other assets. 1 interval = 1 tax year

Assumption
* Fixed Asset = Capital Goods

How Capital Goods should be recorded in EMP going forward?
* Capital Goods acquired should only be recorded through 
	** GRN of Fixed Asset Item
* Tax Code used 
	** TX 	: for normal taxable supply
	** TX-RE 	: for exempt supply
	** TX-CG	: for Capital Goods that will be used for both Exempt and Taxable supplies

How to handle existing transactions in EMP?
* Existing transactions recorded using any of the below methods will not be affected as long as they are not above Rm100k
* Capital Goods acquired can be recorded through
	** GRN of Fixed Asset Item
	** GRN of GL Item with GL’s Tax Return Section = fixedAsset
	** SINV of GL Item with GL’s Tax Return Section = fixedAsset
* Cancellation of Capital Goods can be recorded through
	** PR of Fixed Asset Item
	** PR of GL Item with GL’s Tax Return Section = fixedAsset
	** Cancel SINV of GL Item with GL’s Tax Return Section = fixedAsset
* Tax Code used 
	** TX 	: for normal taxable supply
	** TX-RE 	: for exempt supply

Changes needed for Input Tax Filing
* Do not allow user to file GRN for Capital Goods
	{quote}		
		— GRN for Capital Goods
		SELECT grn_item.* FROM
		( 
			SELECT * FROM supp_grn_item
		) AS grn_item
		INNER JOIN
		(
			SELECT pkid FROM inv_item WHERE inv_type = ‘fixed_asset’
		) AS item
		ON (grn_item.item_id = item.pkid)
	{quote}
* Thus, do not list them here

New columns in acc_tax_transaction
* capital_goods_no_of_intervals 		: integer, default 0
* capital_goods_adjustment_status 	: varchar, default ‘active’
* capital_goods_adjustment_base		: bigDecimal, default 0
* capital_goods_interval_count		: integer, default 0

New function : Tax Filing for Capital Goods > Acquired
* Filters : refer to attached screen shot	
* Listing
	** Format refer to attached xls
	** List GRN for Capital Goods, that match the filters && has not been filed
	** When the list is 1st generated :
		*** IRR = blank
		*** Item Tax Amount = blank
		*** Capital Goods Adjustment Applicable = no default value
		*** Interval = blank
	** Capital Goods Adjustment Applicable?
		*** Put in Yes / No radio buttons for each item
		*** For item which tax code != TX-RE / TX-CG, disable the radio button
		*** When click YES :
			**** auto populate the IRR (refer to IRR explanation below) [use javascript to handle this]
			**** calculate Item Tax Amount to File (Item Tax Amount * IRR)  [use javascript to handle this]
			**** allow user to key in interval if Tax Code = TX-RE / TX-CG [use javascript to handle this]
		*** When click No :
			**** auto populate the IRR = 100% [use javascript to handle this]
			**** calculate Item Tax Amount to File (IRR * Item Tax Amount) [use javascript to handle this]
			**** sets Interval = 0, and DISABLE the field  [use javascript to handle this]
	** IRR
		*** if tax code != TX-RE / TX-CG : IRR = 100%
		*** if tax code = TX-RE / TX-CG : refer to the IRR formula in Tax Filing for Residual Input
		*** IRR is the same for the same Filing Period, thus just need to calculate once
	** Item Tax Amount to File
		*** Item Tax Amount To File = Item Tax Amount * IRR
* Filing logic :
	** If Capital Goods Adjustment Applicable = NO : follow the regular Input Tax Filing process depending on the tax code (TX / TX-RE)
	** If Capital Goods Adjustment Applicable = YES : 
		*** If Interval = 0, throw error. Else proceed with below steps.
		*** Update supp_grn_index table, flag it as filed
		*** Insert new record into acc_tax_txn :
			**** amount = Item_Tax_Amount_to_File
			**** tax_code = follow the item tax code
			**** tx_type = GST_CAPITAL_GOODS_ADJUSTMENT
			**** capital_goods_no_of_intervals = the interval specified by user
			**** capital_goods_adjustment_status = ‘active’
			**** capital_goods_interval_count = 0
		*** Create new Journal (1 journal per item) :
			**** doc_ref, doc_key  
			**** Debit 	: Item_Tax_Amount_to_File into gstInputForFilingGL
			**** Credit  :  Item_Tax_Amount into gstInputGL
			**** Credit	: (Item_Tax_Amount - Item_Tax_Amount_to_File) into 
						EMP Configuration > Tax > Input Tax > Expenses incurred from Capital Goods Apportionment (new configuration). 
						If this is null / empty, charge to gstControl 

* Example :
{quote}
	Jtxn created for GRN : Item = officeBuilding, Tax Code = TX-RE, Amount = Rm1.5m
	|		 	| Debit 	| Credit 	|
	| fixedAsset 	| 1.5m 	| 		|
	| payable	 	|	   	| 1.59m	|	
	| gstInput	| 90k   	|		|

	Jtxn create for Capital Goods Adjustment : 1st interval = IRR 70%
	|		 			| Debit 	| Credit 	|
	| gstInputForFiling		| 63k	| 		|
	| gstInput	 		| 	  	| 90k	|	
	| expenses	 		| 27k   	|		|

	Finally, the accounts will be as below
	|		 			| Debit 	| Credit 	|
	| fixedAsset 			| 1.5m 	| 		|	
	| payable				| 	   	| 1.59m	|
	| gstInput 	 		| 	   	| 		|
	| gstInputForFiling  	| 63k   	| 		|
	| expenses  			| 27k   	| 		|
{quote}

New function : Tax Filing for Capital Goods > Adjustment
* Brief explanation : 
	** This adjustment is to be done every end of filing year for 5 / 10 years depending on the number of intervals.
* Filters : refer to attached screen shot.
* Listing
	** Format refer to attached xls
	** List GRN for Capital Goods and Interval still active, that match the filter Branch
		{quote} 	
			— GRN for Capital Goods and Interval still active
			SELECT * FROM acc_tax_transaction WHERE 
			tx_type = ‘GST_CAPITAL_GOODS_ADJUSTMENT’ AND
			capital_goods_adjustment_status = ‘active’ AND
			capital_goods_interval_count = 1
		{quote}
	** CGA Base %
		*** default the value to the Annual IRR of the 1st Interval Tax Year, but allow user to edit
		*** to get the Annual IRR for the 1st Interval Tax Year 
		{quote} 	
			— 1. Get the 1st interval tax period
			acc_tax_transaction.tax_filing_cycle_pkid

			— 2. Get Annual IRR
			SELECT filing_year.annual_irr FROM
			(
				SELEC tax_year_pkid FROM acc_tax_filing_index WHERE pkid = <the_filing_cycle_pkid_above> 
			) AS filing_period
			INNER JOIN
			(
				SELECT pkid, annual_irr FROM acc_tax_year 
			) AS filing_year
			ON (filing_period.tax_year_pkid = filing_year.pkid)
		{quote}
	** Current Annual Partial Exemption % : refer to the formula in Taxable Amount By Tax Code Report > Total > IRR (generate by Tax Year)
		*** As the listing is filtered by Filing Cycle, just need to do this calculation once
	** No of Intervals : acc_tax_transaction.capital_goods_no_of_intervals
	** Last Interval : radio buttons YES / NO. Default to NO
	** Adjustment Amount : default to the following, but allow user to edit
		{quote} 	
			Adjustment Amount = Item Tax Amount * (Current_Annual_Partial_Exemption - CGA_Base) / No_of_Intervals
		{quote}
	** Details : when clicked, popup a dialog box to show all intervals filed. Format refer to attached xls
* Filing logic :
	** Insert new record into acc_tax_txn :
		*** amount = Adjustment_Amount
		*** tax_code 
			**** if amount >= 0 	: follow the item tax code
			**** else			: ‘DS-RE’
		*** tx_type = GST_CAPITAL_GOODS_ADJUSTMENT
		*** capital_goods_no_of_intervals = No of Intervals
		*** capital_goods_adjustment_status = ‘active’
		*** capital_goods_adjustment_base = CGA Base
		*** capital_goods_interval_count = number_of_intervals_filed + 1 (refer to below on how to get number of intervals filed)
		*** irr = Current Annual Partial Exemption
	** If Last Interval = YES or 
		if number of intervals filed = capital_goods_no_of_intervals, 
		update all intervals capital_goods_adjustment_status = ‘inactive’
		{quote} 	
			— To get number of intervals filed
			SELECT count(*) FROM acc_tax_transaction WHERE 
			doc_item_ref = ’supp_grn_item’ AND
			doc_item_key = XXX AND
			tx_type = ‘GST_CAPITAL_GOODS_ADJUSTMENT’

			— Update all these intervals capital_goods_adjustment_status = ‘inactive’
			SELECT * FROM acc_tax_transaction WHERE 
			doc_item_ref = ’supp_grn_item’ AND
			doc_item_key = XXX AND
			tx_type = ‘GST_CAPITAL_GOODS_ADJUSTMENT’
		{quote}
	** Create new Journal (if amount != 0) :
		*** doc_ref, doc_key 
		*** if amount > 0
			**** Debit	: Adjustment_Amount into gstInputForFilingGL
			**** Credit	: Adjustment_Amount into 
						EMP Configuration > Tax > Input Tax > Expenses incurred from Capital Goods Apportionment (new configuration). 
						If this is null / empty, charge to gstControl 
		*** if amount < 0
			**** Debit	: Adjustment_Amount into gstOutputGL
			**** Credit	: Adjustment_Amount into 
						EMP Configuration > Tax > Input Tax > Expenses incurred from Capital Goods Apportionment (new configuration). 
						If this is null / empty, charge to gstControl 

* Example :
{quote}
	Jtxn created for GRN : Item = officeBuilding, Tax Code = TX-RE, Amount = Rm1.5m
	|		 	| Debit 	| Credit 	|
	| fixedAsset 	| 1.5m 	| 		|
	| payable	 	|	   	| 1.59m	|	
	| gstInput	| 90k   	|		|

	Jtxn create for Capital Goods Acquired : 1st interval, IRR 70%
	|		 		| Debit 	| Credit 	|
	| gstInputForFiling	| 63k	| 		|
	| gstInput	 	| 	  	| 90k	|	
	| expenses	 	| 27k   	|		|

	Jtxn create for Capital Goods Adjustment : 2nd interval = PE 75%
	|		 		| Debit 	| Credit 	|
	| gstInputForFiling	| 450	| 		|	
	| expenses	 	| 	  	| 450	|

	Jtxn create for Capital Goods Adjustment : 3rd interval = PE 69%
	|		 		| Debit 	| Credit 	|
	| gstOutput		| 90	  	| 		|	
	| expenses	 	| 	   	| 90		|

	Finally, the accounts will be as below
	|		 		| Debit 	| Credit 	|
	| fixedAsset 		| 1.5m 	| 		|	
	| payable			| 	   	| 1.59m	|
	| gstInput 	 	| 	   	| 		|
	| gstInputForFiling | 62550   | 		|
	| gstOutput		| 450   	| 		|
	| expenses  		| 27k   	| 		|
{quote}

GST-03 Item 16
* Don’t have to change anything, as it is already querying for both
** item type = fixed asset 
** GL Code Tax Return Section

Store Annual IRR upon LOCKING the last Filing Cycle from Tax Filing Listing
* When click Lock, check if that Filing Period Date End = its Filing Year Date End
	** if YES : after locking the Filing Period, calculate the Annual IRR and store the value into acc_tax_year.annual_irr (new field, bigDecimal)

Capital Goods Adjustment Opening (can be done later)
* For those who migrates to EMP from other system
* A new screen to allow user to :
	* key in Company, Branch, Date
	* add Fixed Asset Item, set Qty, Unit Price (before / after tax depending on Input Tax config), Tax Code
	* set CGA Base, number of intervals
* The information entered by user will be inserted as a new record into acc_tax_transaction
	** tax_filing_cycle_pkid = leave it as default value (so that it will not be reported)
	** tx_type = GST_CAPITAL_GOODS_ADJUSTMENT
	** capital_goods_no_of_intervals = number of intervals
	** capital_goods_adjustment_status = ‘active’
	** capital_goods_adjustment_base = CGA Base
* Once this is done, need to enhance Capital Goods Adjustment’s logic to retrieve CGA Base %. 
	** If the 1st interval’s capital_goods_adjustment_base != 0, use it
	** Else only go retrieve from the Tax Year