Local nbal
If ! Empty(This.parent.contAccount.mActCode.Value)
This.Parent.cmdprint.Enabled = .T.
dt1 = This.Parent.contperiod1.datefromto1._datepicker1.Value
dt2 = This.Parent.contperiod1.datefromto1._datepicker2.Value
mpcode = This.parent.contAccount.mActCode.Value
mfull_name = This.parent.contAccount.mFull_name.Value
Select cReference,cdate,remarks,debit,credit,Cast ( 0 As numeric(15,2)) As balance,;
SPACE(2) As drcr,ccode From actran Where Between(cdate,dt1,dt2) And ccode = mpcode ;
Into Cursor tempec Readwrite nofilter
Index On Dtoc(cdate,1)+ccode Tag cdate
Select actran
Sum debit-credit To opbal For cdate<dt1 And ccode = mpcode
nbal = 0.00
Select tempec
Set Order To cdate
Append Blank
Replace cdate With dt1,remarks With 'Opening Balance'
If opbal > 0
Replace debit With opbal
Else
Replace credit With -(opbal)
Endif
Go Top
Scan
nbal = nbal + debit - credit
Replace balance With nbal In tempec
Replace drcr With Iif(balance>0,'DR','CR')
Endscan
Sum debit,credit To mtotdr,mtotcr
mtotbal = mtotdr-mtotcr
Sum debit,credit To mnetdr,mnetcr For ! Empty(cReference)
mnetbal = mnetdr-mnetcr
This.Parent.contmaincat.totalcontainer.totdr.Value = mtotdr
This.Parent.contmaincat.totalcontainer.totcr.Value = mtotcr
This.Parent.contmaincat.totalcontainer.totbal.Value = mtotbal
This.Parent.contmaincat.totalcontainer.netbal.Value = mnetbal
Do Case
Case mnetbal > 0
This.Parent.contmaincat.totalcontainer.netbal.ForeColor = Rgb(0,0,255)
Case mnetbal < 0
This.Parent.contmaincat.totalcontainer.netbal.ForeColor = Rgb(255,0,0)
Case mnetbal = 0
This.Parent.contmaincat.totalcontainer.netbal.ForeColor = Rgb(0,0,0)
Endcase
Do Case
Case mtotbal > 0
This.Parent.contmaincat.totalcontainer.lbldrcr.Caption = 'Dr'
Case mtotbal < 0
This.Parent.contmaincat.totalcontainer.lbldrcr.Caption = 'Cr'
Endcase
Go Top
This.Parent.contmaincat.Enabled = .T.
This.Parent.contperiod1.Enabled = .F.
This.Enabled = .F.
Select tempec
Go Top
With This.Parent.contmaincat.grid1
.RecordSource = 'Tempec'
.RecordSourceType = 1
.column1.ControlSource = "Tempec.cReference"
.column2.ControlSource = "Tempec.cdate"
.column3.ControlSource = "Tempec.remarks"
.column4.ControlSource = "Tempec.debit"
.column5.ControlSource = "Tempec.credit"
.column6.ControlSource = "Tempec.balance"
.column7.ControlSource = "Tempec.drcr"
Endwith
Else
Messagebox("Please Select Accounts Code Before Proceed",16)
This.parent.contAccount.mActCode.SetFocus
ENDIF