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


;;----------------------------Adding Cost Centre Filter Button in Profit and Loss Account------------

[#Report: Group Summary]

	Variable: CostCenterFilterVar

[#Collection: PLDirExpenses]

	Delete	: Collection      : GPCOasExpense

[#Collection: PLInDirExpenses]

	Delete	: Collection      : GPBFAsExpense
	Delete	: Collection      : ProfitAsExpense

[#Collection: PLDirIncome]

	Delete	: Collection      : GPCOasIncome

[#Collection: PLInDirIncome]

	Delete	: Collection      : GPBFAsIncome
    Delete	: Collection      : ProfitAsIncome

[#Report: Profit and Loss]

	Variable: CostCenterFilterVar
	Set		: CostCenterFilterVar 	: $$SysName:AllItems

[#Form: Profit and Loss]

	Add		: Button	: After 	: ChangeValue	: CostCentreButton

[Button:  CostCentreButton]
	
	Title	: "Cost Centre"
	Key		: Alt+S
	Action	: ModifyVariables	: Cost Centre Filter Report
    
[Report: Cost Centre Filter Report]

 	Use     : Modify Variables
    Local   : Part : Modify Variables : Lines          : Cost Centre FilterLine
    Local   : Field: MV Title         : Info           : $$LocaleString:"Cost Centre Filter"
	Title	: $$LocaleString:"Cost Centre Filter"

	[Line: Cost Centre FilterLine]
		
		Fields	: Cost Centre Filter Field

		[Field: Cost Centre Filter Field]

			Use		  	: Name Field
			Table	 	: Cost Centre Table, All Items
			Show Table	: Always
			Modifies 	: CostCenterFilterVar

[Variable: CostCenterFilterVar]
	
	Type	: String

[Collection: Cost Centre Table]

	Title	: $$LocaleString:"List of Cost Centres"
	Type 	: Cost Centre
	Format	: $Name, 15

;;---------------- Source and Summary Collections ------------------------

[#Object: Group]

	BSClosing	: if @@CCFilter then $$AsPositive:$$CCClosing:##CostCenterFilterVar else $$AsPositive:$ClosingBalance

[#Object: Ledger]

	BSClosing	: if @@CCFilter then $$AsPositive:$$CCClosing:##CostCenterFilterVar else $$AsPositive:$ClosingBalance

[#Object: GrossProfitCO]

    Name            : $$LocaleString:"Gross Profit"

    IsGPCOLine      : Yes
    IsPLObject      : Yes
    SortPosition    : 3000
    IsTBalObject    : Yes

    TBalClosing     : @@GPClosingProfit
    BSClosing       : $TBalClosing
    TBalOpening     : $TBalClosing
    BSOpening       : $TBalClosing

[#Object: GrossProfitBF]

    Name            : $$LocaleString:"Gross Profit"

    IsGPBFLine      : Yes
    IsPLObject      : Yes
    SortPosition    : 0
    IsTBalObject    : Yes

    TBalClosing     : $$AsPositive:$$Negative:@@GPClosingProfit
    BSClosing       : $TBalClosing
    TBalOpening     : $TBalClosing
    BSOpening       : $TBalClosing

;;-------------Field Level Change in Profit and Loss Account-------------------------

[System: Formula]

	CCFilter	: if ##CostCenterFilterVar = $$SysName:AllItems then No else Yes

	PLDExpFilt	: $$CollAmtTotal:PLDirExpenses:$BSClosing
	PLDIncFilt	: $$CollAmtTotal:PLDirIncome:$BSClosing

	PLDNett		: if @@PLDExpFilt > @@PLDIncFilt then @@PLDExpFilt else @@PLDIncFilt
	PLD GP		: if @@PLDExpFilt < @@PLDIncFilt then @@PLDExpFilt - @@PLDIncFilt else @@PLDIncFilt - @@PLDExpFilt
	PLD GP Pos	: $$AsPositive:@@PLDGP

;; Net Profit Section

	PLDInExpFilt	: $$CollAmtTotal:PLInDirExpenses:$BSClosing
	PLDInIncFilt	: $$CollAmtTotal:PLInDirIncome:$BSClosing

	PLDInExpFiltWGL	: if @@PLDExpFilt < @@PLDIncFilt then @@PLDInExpFilt - @@PLDGPPOS else @@PLDInExpFilt
	PLDInIncFiltWGP	: if @@PLDExpFilt > @@PLDIncFilt then @@PLDInIncFilt - @@PLDGPPOS else @@PLDInIncFilt

	PLD NettIn		: if @@PLDInExpFiltWGL > @@PLDInIncFiltWGP then @@PLDInExpFiltWGL else @@PLDInIncFiltWGP
	PLD GPIn		: if @@PLDInExpFiltWGL < @@PLDInIncFiltWGP then @@PLDInExpFiltWGL - @@PLDInIncFiltWGP else @@PLDInIncFiltWGP - @@PLDInExpFiltWGL
	PLD GPIn Pos	: $$AsPositive:@@PLDGPIn

[#Part: PLDirExpenses]

	Local	: Field	: BSMainTotal	: Set As	: @@PLDNett
	Add		: Bottom Lines	: At Beginning		: PLD GP

	[Line: PLD GP]

		Fields  : DSP AccName, PLAmt
		Repeat	: PLAmt
		Local	: Field	: DSP DispName	: Set As	: "Gross Profit C/f"
		Local	: Field	: BSMainAmt		: Set As	: @@PLDGPPos
		Local	: Field	: Default		: Inactive	: @@PLDExpFilt > @@PLDIncFilt

[#Part: PLDirIncome]

	Local	: Field	: BSMainTotal		: Set As	: @@PLDNett
	Add		: Bottom Lines	: At Beginning		: PLD GL

	[Line: PLD GL]

		Fields  : DSP AccName, PLAmt
		Repeat	: PLAmt
		Local	: Field	: DSP DispName	: Set As	: "Gross Loss C/f"
		Local	: Field	: BSMainAmt		: Set As	: @@PLDGPPos
		Local	: Field	: Default		: Inactive	: @@PLDExpFilt < @@PLDIncFilt OR @@PLDExpFilt = @@PLDIncFilt

;; P and L

[#Part: PLInDirExpenses]

	Local	: Field	: BSMainTotal		: Set As	: @@PLDNettIn
	Add		: Lines			: At Beginning	: PLD GL
	Add		: Bottom Lines	: At Beginning	: PLD NP
	Local	: Line	: PLD GL: Local		: Field	: Default		: Inactive	: @@PLDExpFilt < @@PLDIncFilt OR @@PLDExpFilt = @@PLDIncFilt
	Local	: Line	: PLD GL: Local		: Field	: DSP DispName	: Set As	: "Gross Loss B/f"

	[Line: PLD NP]

		Fields  : DSP AccName, PLAmt
		Repeat	: PLAmt
		Local	: Field	: DSP DispName	: Set As	: "Net Profit"
		Local	: Field	: BSMainAmt		: Set As	: @@PLDGPInPos
		Local	: Field	: Default		: Inactive	: @@PLDInExpFiltWGL > @@PLDInIncFiltWGP OR @@PLDInExpFiltWGL = @@PLDInIncFiltWGP

[#Part: PLInDirIncome]

	Local	: Field	: BSMainTotal	: Set As	: @@PLDNettIn
	Local	: Field	: BSMainTotal	: Color		: Red
	Add		: Lines			: At Beginning	: PLD GP
	Add		: Bottom Lines	: At Beginning	: PLD NL
	Local	: Line	: PLD GP: Local		: Field	: Default		: Inactive	: @@PLDExpFilt > @@PLDIncFilt OR @@PLDExpFilt = @@PLDIncFilt
	Local	: Line	: PLD GP: Local		: Field	: DSP DispName	: Set As	: "Gross Profit B/f"

	[Line: PLD NL]

		Fields  : DSP AccName, PLAmt
		Repeat	: PLAmt
		Local	: Field	: DSP DispName	: Set As	: "Net Loss"
		Local	: Field	: Default		: Inactive	: @@PLDInExpFiltWGL < @@PLDInIncFiltWGP OR @@PLDInIncFiltWGP = @@PLDInIncFilt
		Local	: Field	: BSMainAmt		: Set As	: @@PLDGPInPos

[#Field: BSMainTotal]

	Set As	: @@PLDNettIn + @@PLDGPPos

;; End-of-File
