
/*
Objective(s) -
-	This code will help to explain how to repeat all the accounting groups of a company and explode the ledger 
	details under each and every accounting group
-   	Explosion of ledger level happens when Shift enter is press on the group line    
*/


[#Menu: Gateway of Tally]

	Add	: Item	: Before : @@locQuit	: My TB Report		: Display	: My TB Report
    
[Report: My TB Report]

    Form        : My TB

[Form: My TB]

	Button      : F2ChangePeriod, ChangeCompany
	Keys        : ChangePeriod
	Parts       : My TB Part

    ;;Report formatting    

    Height      : 100% Page
    Width       : 100% Page
		
[Part: My TB Part]

    Lines       : My TB Title, My TB Details
    BottomLines : My TB Total
    
    ;;Repeat the lines on collection of accounting groups

    Repeat      : My TB Details	: My TB GroupsLedgers
    Total       : My TB Dr Amt Field, My TB Cr Amt Field
    Scroll      : Vertical
    CommonBorder: Yes
		
    [Line: My TB Title]
        
        Use     : My TB Details
        Local   : Field : Default           : Type  : String
        Local   : Field : Default           : Align : Centre		
        Local   : Field : My TB Name Field  : Set as: "Name"
        Local   : Field : My TB ParNameField: Set as: "Parent"
        Local   : Field : My TB Dr Amt Field: Set as: "Debit"
        Local   : Field : My TB Cr Amt Field: Set as: "Credit"
        Border  : Flush Totals

    [Line: My TB Details]

        Fields      : My TB Name Field, My TB ParName Field
        Right Fields: My TB Dr Amt Field, My TB Cr Amt Field
        
        ;;Explode Ledger details after every group which will happen if condition is satisfied
        ;;Condition checks whether it is exploded from group line($$Isgroup) and Key explode is used($$KeyExplode)

        Explode     : My TB Group Explosion : $$IsGroup and $$KeyExplode
		
        [Field: My TB Name Field]

			Use         : Name Field
			Set as      : $Name
			Variable    : MyGroupName1
			                            
        [Field: My TB ParName Field]

			Use         : Name Field
			Set as      : $Parent
			Border      : Thin Left

        [Field: My TB Dr Amt Field]

			Use         : Amount Field
            
            ;;$$IsDr checks whether the closing balance is Debit in nature. If true the set the valuse else zero

		    Set as      : if $$IsDr:$ClosingBalance then $ClosingBalance else 0
		    Border      : Thin Left

        [Field: My TB Cr Amt Field]

            Use         : Amount Field
		    Set as      : if NOT $$IsDr:$ClosingBalance then $ClosingBalance else 0
		    Border      : Thin Left
		    					
    [Line: My TB Total]

        Use     : My TB Details
        Local   : Field : My TB Name Field  : Align : Centre
        Local   : Field : My TB Name Field  : Set as: "TOTAL"
        Local   : Field : My TB Dr Amt Field: Set as: $$Total:MyTBDrAmtField    ;;;$$Total is used to take the total of the field value
        Local   : Field : My TB Cr Amt Field: Set as: $$Total:MyTBCrAmtField
        Border  : Thin Top Bottom

;; Explode Part

[Part: My TB Group Explosion]

    Lines       : My TB Details Explosion
    
    ;;Repeat the line on ledger collection to display the details in the fields

    Repeat      : My TB Details Explosion   : My TB GroupsLedgers
    Scroll      : Vertical
    
    [Line: My TB Details Explosion]
    
        Fields      : My TB Name Field, My TB ParName Field
        Right Fields: My TB Dr Amt Field, My TB Cr Amt Field
        Explode     : My TB Group Explosion : $$IsGroup and $$KeyExplode    
        Indent      : 2  * $$ExplodeLevel   
        Local       : Field     : Default   : Delete: Border

;; Explode Part Ends here

;;ITs a collection of leger and group combined together

[Collection: My TB GroupsLedgers]

    Collection  : My TB Groups, My TB Ledgers

;;Collecction of all the accounting groups

[Collection: My TB Groups]

    Type        : Group
    Child Of    : #MyGroupName1
    Filter      : Zero Filter
    Fetch	: Name, ClosingBalance
    
;;Collecction of all the ledgers

[Collection: My TB Ledgers]

    Type        : Ledger
    Child Of    : #MyGroupName1           ;; child of attribute is used to get all the ledgers made under particular group
    Filter      : Zero Filter             ;; system formulla "Zero filter" is used to get only relevant ledgers
    Fetch	: Name, ClosingBalance
    
;;System formula to check whether the closing value is greater than zero and is a profit ledger

[System: Formula]

    Zero Filter : $ClosingBalance > 0 AND NOT $$IsLedgerProfit
    
;; End-of-File
