
/*
Objective(s)  
- 	This program demonstrates the usage of Search Key for identifying the Line 
Objects
-	The report uses the same Itemwise Partywise Sales Report and the default Line 
removal behavior using Alt + R/Alt + U has become possible by assigning an unique
Object Identifier using Search Key

Syntax -
-	Usage of Collection Attribute Search Key as a unique object identifier 
to remove/Unremove Lines

	Search Key : Method-Name [+ Method-Name ....]

*/ 

[#Menu: Gateway of Tally]
    
    Add : 	Key Item	: "Object Identifier with Search Key"	: C : Display	: TSPL Smp CFBK Rep Search Key	: NOT $$IsEmpty:$$SelectedCmps
    
[Report: TSPL Smp CFBK Rep Search Key]
	
	Use		: TSPL Smp CFBK Rep
	
;; The below Search Key with the Collection 'TSPL Smp Stock Item' sets Method 'IName'
;; as the Object Identifier
	Local	: Collection	: TSPL Smp Stock Item		: Search Key	: $IName
	Title	: "Object Identifier with Search Key"

	Local	: Form	: TSPL Smp CFBK Rep	: Local	: Part	: TSPL Smp Info	: Local	: Line	: Info	: Local	: Field	: Info Field	: Info	: "Aggregated Objects where no identifier is available in Line Object, using Search Key as Stock Item, the object identifier is introduced such that Remove/Unremove Lines will work in this Report"
	Local	: Part	: TSPL Smp Info		: Local	: Line	: Info	: Local	: Field	: Info Field	: Lines	: 0
	
[Report: TSPL Smp CFBK Rep]

	Use			: DSP Template
	Form		: TSPL Smp CFBK Rep
	Title		: "Field Repeat over Collection"

[Form: TSPL Smp CFBK Rep]

	Use			: DSP Template
	Keys		: Form Remove Line, Form Show Last Removed Line
	Parts		: TSPL Smp Info, TSPL Smp CFBK Rep
	Background 	: White, Light Orange
	Bottom Toolbar Buttons 	: BottomToolBarBtn8, BottomToolBarBtn9, BottomToolBarBtn10, BottomToolBarBtn11, BottomToolBarBtn12
	
	Local: Part	: TSPL Smp Info	: Local	: Line	: Info	: Local	: Field	: Info Field	: Info	: "Sample 'Itemwise Partywise Sales' rewritten using Enhanced Columnar Capability where Field is repeated over a Collection"

[Part: TSPL Smp CFBK Rep]

	Lines		: TSPL Smp CFBK Rep Title, TSPL Smp CFBK Rep SubTitle, TSPL Smp CFBK Rep Details
	Repeat		: TSPL Smp CFBK Rep Details		: TSPL Smp Stock Item
	Scroll		: Vertical
	CommonBorder: Yes

	[Line: TSPL Smp CFBK Rep Title]

		Use		: TSPL Smp CFBK Rep Details

		Local	: Field	: Default						: Type		: String
		Local	: Field	: Default						: Align		: Center

		Local	: Field	: TSPL Smp CFBK Rep Name		: Set as	: "Particulars"
		Local	: Field	: TSPL Smp CFBK Rep Name		: Widespaced: Yes
		Local	: Field	: TSPL Smp CFBK Rep Party		: Delete	: Fields
;; Since Field 'Smp CFBK Rep Party' is repeated over Collection of Party Ledgers,
;; the current Object context is available and hence the Method 'PName' returns
;; the Party Name
		Local	: Field	: TSPL Smp CFBK Rep Party		: Set as	: $PName
		Local	: Field	: TSPL Smp CFBK Rep Party		: Lines		: 0
		Local	: Field	: TSPL Smp CFBK Rep Party		: SubTitle	: Yes
		Local	: Field	: TSPL Smp CFBK Rep ColTotal	: Set as	: "Total"
		Border	: Thin Top

	[Line: TSPL Smp CFBK Rep Sub Title]

		Use		: TSPL Smp CFBK Rep Details

		Local	: Field	: Default						: Type		: String
		Local	: Field	: Default						: Align		: Center

		Local	: Field	: TSPL Smp CFBK Rep Name		: Set as	: ""
		Local	: Field	: TSPL Smp CFBK Rep Party 		: Border	: Thin Top
		Local	: Field	: TSPL Smp CFBK Rep Party Qty	: Set as	: "Quantity"
		Local	: Field	: TSPL Smp CFBK Rep Party Amt	: Set as	: "Amount"
		Local	: Field	: TSPL Smp CFBK Rep ColTotal	: Set as	: ""
		Border	: Thin Bottom

[Part: TSPL Smp Info]
	
	Lines	: Info
	Local	: Line	: Info	: Local		: Field	: Info Field: Info	: "The Walkex Attribute walks all sub object paths of the source object within a single pass, hence all Ledgers and Stock Items of the same voucher appear together"

    [Line: Info]

        Fields: Info Field
        Local: Field: Info Field	: Info		: "Collection Name evaluated dynamically"
        Local: Field: Info Field	: FullWidth	: Yes
        Local: Field: Info Field	: Align		: Center
        Local: Field: Info Field	: Border	: Thin Bottom
        Local: Field: Info Field	: Style		: Normal Italic
        Space Bottom: 1

	[Line: TSPL Smp CFBK Rep Details]

		Fields	: TSPL Smp CFBK Rep Name, TSPL Smp CFBK Rep Party
		Repeat	: TSPL Smp CFBK Rep Party		: TSPL Smp CFBK Party
		
;; Field 'TSPL Smp CFBK Rep Party' is repeated over the Collection 'TSPL Smp CFBK Party'
;; which creates columns for Party Ledgers
		Total	: TSPL Smp CFBK Rep Party

		[Field: TSPL Smp CFBK Rep Name]

			Use			: Name Field
			Set as		: $IName
			Display		: Stock Vouchers
			Variable	: Stock Item Name

		[Field: TSPL Smp CFBK Rep Party]

			Use			: Name Field
			Fields		: TSPL Smp CFBK Rep Party Qty, TSPL Smp CFBK Rep Party Amt
						
			[Field: TSPL Smp CFBK Rep Party Qty]

				Use			: Qty Primary Field
				Set as		: $$ReportObject:$$CollectionFieldByKey:$BilledQty:@SKFormula:TSPLSmpCFBKSummVoucher
				SKFormula	: $PName + #TSPLSmpCFBKRepName
				Format		: "NoZero"
				Border		: Thin Left

			[Field: TSPL Smp CFBK Rep Party Amt]
				
				Use			: Amount Forex Field
				Set as		: $$ReportObject:$$CollectionFieldByKey:$Amount:@SKFormula:TSPLSmpCFBKSummVoucher
				SKFormula	: $PName + #TSPLSmpCFBKRepName
				Format		: "NoZero"
				Border		: Thin Left

;; Collection Definition

[Collection: TSPL Smp CFBK Voucher]

	Type		: Voucher
	Filter		: TSPL Smp IsSalesVT

[Collection: TSPL Smp Stock Item]

	Source Collection	: TSPL Smp CFBK Voucher

	Walk				: Inventory Entries
	By					: IName			: $StockItemName
	Aggr Compute		: BilledQty		: SUM	: $BilledQty

	Filter				: TSPL Smp NonEmptyQty
	Keep Source			: ().
	
[Collection: TSPL Smp CFBK Party]

	Source Collection	: TSPL Smp CFBK Voucher

	Walk				: Inventory Entries
	By					: PName			: $PartyLedgerName
	Aggr Compute		: BilledQty		: SUM	: $BilledQty

	Keep Source			: ().
	Filter				: TSPL Smp NonEmptyQty

[Collection: TSPL Smp CFBK Summ Voucher]

	Source Collection	: TSPL Smp CFBK Voucher

	Walk				: Inventory Entries
	By					: PName			: $PartyLedgerName
	By					: IName			: $StockItemName
	Aggr Compute		: BilledQty		: SUM	: $BilledQty
	Aggr Compute		: Amount		: SUM	: $Amount

	Keep Source			: ().
	Search Key			: $PName + $IName

;; System Formula

[System: Formula]

	TSPL Smp IsSalesVT	: $$IsSales:$VoucherTypeName
	TSPL Smp NonEmptyQty: NOT $$IsEmpty:$BilledQty

;; End-of-File
