REPORTFORM;PL2_1.frf
TITLE;งบดุล แบบละเอียด
SQL;drop table if exists _plcard&
SQL;
SQL;create table _plcard
SQL;SELECT GLTR.GLID, GLMST.GLDESC,GLMST.GLGROUP,GLGROUP.GLGROUPDESC AS GLGDESC,
SQL;SUM(GLTR.DEBIT)-SUM(GLTR.CREDIT)  AS XACC, 
SQL;SUM(GLTR.DEBIT)-SUM(GLTR.CREDIT) AS XFLD2,
SQL;1 AS XLINE
SQL;FROM GLTR LEFT JOIN GLMST ON GLTR.GLID = GLMST.GLID 
SQL;LEFT JOIN GLGROUP ON GLMST.GLGROUP = GLGROUP.GLGROUP
SQL;WHERE  GLTR.DATEDOC <= :m11 AND (LEFT(GLMST.GLGROUP,1)="A")
SQL;GROUP BY GLTR.GLID, GLMST.GLDESC,GLMST.GLGROUP,GLGROUP.GLGROUPDESC
SQL;ORDER BY GLMST.GLGROUP,GLTR.GLID&
SQL;
SQL;insert into _plcard
SQL;SELECT GLTR.GLID, GLMST.GLDESC,GLMST.GLGROUP,GLGROUP.GLGROUPDESC,
SQL;SUM(GLTR.CREDIT) - SUM(GLTR.DEBIT) AS XACC, 
SQL;SUM(GLTR.CREDIT) - SUM(GLTR.DEBIT) AS XFLD2,
SQL;2
SQL;FROM GLTR LEFT JOIN GLMST ON GLTR.GLID = GLMST.GLID 
SQL;LEFT JOIN GLGROUP ON GLMST.GLGROUP = GLGROUP.GLGROUP
SQL;WHERE  GLTR.DATEDOC <= :m11 AND (LEFT(GLMST.GLGROUP,1)="L" OR LEFT(GLMST.GLGROUP,1)="O" )
SQL;GROUP BY GLTR.GLID, GLMST.GLDESC,GLMST.GLGROUP,GLGROUP.GLGROUPDESC
SQL;ORDER BY GLMST.GLGROUP,GLTR.GLID&
SQL; 
SQL;insert into _plcard (GLID, GLDESC, GLGROUP, GLGDESC, XACC, XFLD2, XLINE) VALUES
SQL;('XXXX','กำไรขาดทุนภายในปี','O04','กำไรขาดทุนภายในปี','0','0',2)&
SQL;
SQL;drop table if exists _xgl1&
SQL;create table _xgl1
SQL;SELECT "XXXX" AS GLID,SUM(CREDIT-DEBIT) AS MR
SQL;FROM GLTR LEFT JOIN GLMST ON GLTR.GLID = GLMST.GLID 
SQL;WHERE GLTR.DATEDOC <= :m11 AND (LEFT(GLMST.GLGROUP,1)="R")&
SQL;
SQL;drop table if exists _xgl2&
SQL;create table _xgl2
SQL;SELECT "XXXX" AS GLID,SUM(DEBIT-CREDIT) AS MR2,0000000000.00 as mR
SQL;FROM GLTR LEFT JOIN GLMST ON GLTR.GLID = GLMST.GLID 
SQL;WHERE GLTR.DATEDOC <= :m11 AND (LEFT(GLMST.GLGROUP,1)="E")&
SQL;
SQL;update _xgl2 inner join _xgl1 on _xgl2.GLID = _xgl1.GLID
SQL;set
SQL;_xgl2.MR = _xgl1.mR - _xgl2.MR2
SQL;where _xgl2.GLID = "XXXX"&
SQL;
SQL;UPDATE _plcard inner join _xgl1 on _plcard.GLID = _xgl1.GLID
SQL;SET _plcard.XFLD2 = _xgl1.MR
SQL;where _plcard.GLID = "XXXX"&
SQL;
SQL;UPDATE _plcard inner join _xgl2 on _plcard.GLID = _xgl2.GLID
SQL;SET _plcard.XACC = _xgl2.MR
SQL;where _plcard.GLID = "XXXX"&
SQL;
SQL;UPDATE _PLCARD SET GLGROUP = "O01", GLGDESC = "ส่วนของผู้ถือหุ้น" WHERE LEFT(GLGROUP,1)="O"&
SQL;UPDATE _PLCARD SET GLGROUP = "L01", GLGDESC = "หนี้สิน" WHERE LEFT(GLGROUP,1)="L"&
SQL;
SQL;select GLID,GLDESC,GLGROUP,GLGDESC,
SQL;TRUNCATE(XACC,2) AS XACC,TRUNCATE(XFLD2,2) AS XFLD2,XLINE
SQL;from _plcard
SQL; WHERE (XACC + XFLD2) <> 0
SQL;order by XLINE,GLGROUP,GLID
CONDITION;สิ้นสุด ณ วันที่~GLTR.DATEDOC~Date~1~<=~
USECROSSTAB;N
CROSSTABFRF;N
CROSSTABHEAD;
CROSSTABFIELD;
