報表自訂
# 報表自訂
說明: 提供自訂報表新增、查詢及列印功能。
功能: 新增、查詢或列印相關報表。
執行單位: 相關部門人員。
# 操作步驟
進入報表自訂頁面(圖-1)
進入系統主畫面,點擊進入
[提醒]
-[報表自訂]
頁面。新增報表查詢條件: 欄位在
[報表自訂]
頁面,選擇[模組]
,點擊[編輯報表]
。在彈出對話框圖-2。
新增報表: 點擊 圖-2 上部新增按鈕,在彈出對話框 圖-3 。以此輸入各欄位資料。輸入完成後點擊上部保存按鈕。
報表新增查詢條件: 點擊 圖-3 下部新增按鈕,在彈出對話框 圖-4 。
進入報表自訂頁面(圖-5)
進入系統主畫面,點擊進入
[提醒]
-[報表自訂]
-[查詢]
頁面。在
[報表自訂]
頁面,在左側選擇需要列印報表[模組]
,在右側輸入查詢條件,點擊下部[查詢]
,在彈出對話框點擊[預覽]
,可以看到到需要單據資料。
# 欄位説明
[模 組] 下拉選擇中選擇。系統自帶資料。
[項 次] 系統新增自動生成。
[報表標題] 報表具體名稱。用戶手工輸入。
[報 表 檔] 報表在系統後台名稱,系統新增時自動生成,也可以手工輸入。
[SQL 參數] 報表在系統後台參數名稱,系統新增時自動生成,也可以手工輸入,對應的參數為數據庫中的儲存程序。
[說 明] 對報表的備註說明。
[查詢欄位] 欄位具體名稱。用戶手工輸入。
[項 次] 系統新增時自動生成。
[欄位類型] 下拉選擇中選擇。系統自帶資料。它分的類型:1.文字類型、2.日期類型、3.下拉類型
[欄位長度] 用戶可以手工輸入。
[預設值] 欄位類型選擇下拉類型在此定義預設參數,如果勾選預設值是SQL指令,在此手工輸入。SQL指令提供了一個預設參數{companyid}
,儅在SQL指令中填寫了{companyid}
,在運行時會自動替換為實際的公司ID。
[是否隱藏欄位] 若勾選表示此欄位不在前端顯示。否則反之。
[預設值是SQL指令] 若欄位資料需要SQL指令才能查到,在欄位前點擊勾選,並在預設值欄手工輸入SQL指令。
[檢查SQL] 點擊此按鈕後,系統會自動檢查SQL指令輸入是否正確。
# 創建自定報表數據
報表自定的功能實現是通過呼叫儲存程序實現的,呼叫的儲存程序在運行后會返回結果數據集,FastERP2根據返回的結果數據集創建打印的報表。
因此,在報表自定界面中設置完成后,需要同步在數據庫中創建儲存程序,程序的名稱為SQL 參數的名稱,儲存程序的參數要與設定的查詢條件一一對應。執行的儲存程序要能傳回結果數據集。
# 報表公式的引用
會計模組中預置了一部分報表公式,可以根據公式指定的内容設置報表公式,實現統計的功能。
這部分報表公式匯總的功能是在儲存程序中實現的,下面會結合SQL編碼示例進行説明,表示如何使用:
- 資產負債表
自定的資產負債表使用的報表公式為負債設定[1]
、負債設定[2]
。兩者分別代表的是資產類的統計項目,負債與所有者權益項目。如果是要能實時統計查看,且能資產負債平衡的報表,則兩側的報表配平應為 資產= 負債+所有者權益+收入-費用成本
。也就是負債表設定[1]
中應設置資產類科目的報表公式,負債表設定[2]
中應設置負債、所有者權益、收入、費用成本類型的科目。
以下是如何在報表中使用資產負債報表公式的示例:
if @a1='' select @a1=min(fromdate) from spanmon(nolock) where companyid=@companyid--起始日期為空,以開帳日期為準
--負債表設定[1]與負債表設定[2]的項目數量要相等,如果一側的項目數量多,另一側的數量少,則增加少的一側,增加少的數量的項目行。
if (select count(*) from AcCashTotalItem(nolock) where printtype='assetliabilitysheet1' and companyid=@companyid)<>(select count(*) from AcCashTotalItem(nolock) where printtype='assetliabilitysheet2' and companyid=@companyid)
begin
select '負債表兩邊的項次不相等!'
return 0
end
--按會計科目統計期初、上年年末的數據
select a.subjectid,qty=case when isnull(b.isborrow,1)=1 then sum(isnull(a.lendprice,0)-isnull(a.loanprice,0)) else sum(isnull(a.loanprice,0)-isnull(a.lendprice,0)) end into #Report_053536_bef from voucheritem as a(nolock) left join subjectitem as b(nolock) on a.subjectid=b.subjectid where a.companyid=@companyid and a.vouchercode in (select vouchercode from voucher(nolock) where companyid=@companyid and isprocess=1 and left(isnull(vouchertype,''),1)<>'5' and right(vouchercode,4)<>'0000' and year(createdate)<year(convert(datetime,@a1)) ) group by a.subjectid,b.isborrow--期初(年初及上年年末)
--按會計科目統計期末的數據
select a.subjectid,qty=case when isnull(b.isborrow,1)=1 then sum(isnull(a.lendprice,0)-isnull(a.loanprice,0)) else sum(isnull(a.loanprice,0)-isnull(a.lendprice,0)) end into #Report_053536 from voucheritem as a(nolock) left join subjectitem as b(nolock) on a.subjectid=b.subjectid where a.companyid=@companyid and vouchercode in (select vouchercode from voucher(nolock) where companyid=@companyid and isprocess=1 and left(isnull(vouchertype,''),1)<>'5' and right(vouchercode,4)<>'0000' and createdate<=convert(datetime,@a1) ) group by a.subjectid,b.isborrow--期末
--獲取負債表設定[1]中的數據
--獲取報表公式主項目的信息
select * into #CashFlow from AcCashTotalItem(nolock) where printtype='assetliabilitysheet1' and companyid=@companyid order by totalitem
select * into #Report20100610_053536_1 from #Report20100610_053536_11 where 1=2
--依次查找各個主項目
set @id=(select min(id) from #CashFlow)
while @id<=(select max(id) from #CashFlow)
begin
select @oldtotalitem=totalitem from #CashFlow where id=@id
--獲取主項目下的子項目
insert #Report20100610_053536_1(type,totalitem,itemname,formulalevel,isvisible) select '1',totalitem,itemname,formulalevel,isvisible from #CashFlow where id=@id
set @i=(select min(id) from AcCashSubItem(nolock) where printtype='assetliabilitysheet1' and companyid=@companyid and totalitem=@oldtotalitem)
--依次查找各個子項目
while @i<=(select max(id) from AcCashSubItem(nolock) where printtype='assetliabilitysheet1' and companyid=@companyid and totalitem=@oldtotalitem)
begin
select @oldsubitem=subitem from AcCashSubItem(nolock) where printtype='assetliabilitysheet1' and id=@i and companyid=@companyid
insert #Report20100610_053536_1(type,totalitem,subitem,itemname,subitemtype,subisvisible) select '2',totalitem,subitem,' '+itemname,itemtype,isvisible from AcCashSubItem(nolock) where id=@i and companyid=@companyid
--含下級科目
insert #Report20100610_053536_1(type,totalitem,subitem,item,itemname,childitemtype,childisvisible,subjectid,subjectname,sumtype) select '3',a.totalitem,a.subitem,a.item,' '+a.itemname,a.itemtype,a.isvisible,b.subjectid,b.shortname,a.sumtype from AcCashItem as a(nolock) join subjectitem as b(nolock) on a.subjectid=left(b.subjectid,len(a.subjectid)) where a.printtype='assetliabilitysheet1' and a.companyid=@companyid and a.totalitem=@oldtotalitem and a.subitem=@oldsubitem and isnull(a.isparent,0)=1 order by a.item
--不含下級科目
insert #Report20100610_053536_1(type,totalitem,subitem,item,itemname,childitemtype,childisvisible,subjectid,subjectname,sumtype) select '3',a.totalitem,a.subitem,a.item,' '+a.itemname,a.itemtype,a.isvisible,b.subjectid,b.shortname,a.sumtype from AcCashItem as a(nolock) join subjectitem as b(nolock) on a.subjectid=b.subjectid where a.printtype='assetliabilitysheet1' and a.companyid=@companyid and a.totalitem=@oldtotalitem and a.subitem=@oldsubitem and isnull(a.isparent,0)=0 order by a.item
set @i=@i+1
end
set @id=@id+1
end
--先取得最下級的金額(本期)
update #Report20100610_053536_1 set qty=isnull(b.qty,0) from #Report20100610_053536_1 as a,(select sum(isnull(qty,0)) as qty,subjectid from #Report_053536_bef group by subjectid) as b where a.subjectid=b.subjectid and a.type='3' and a.sumtype='1'
update #Report20100610_053536_1 set qty=isnull(a.qty,0)+isnull(b.qty,0) from #Report20100610_053536_1 as a,(select qty=isnull(sum(isnull(qty,0)),0),totalitem,subitem,childitemtype from #Report20100610_053536_1 group by type,totalitem,subitem,childitemtype having type='3' and childitemtype='+') as b where a.totalitem=b.totalitem and a.subitem=b.subitem and a.type='2'
update #Report20100610_053536_1 set qty=isnull(a.qty,0)-isnull(b.qty,0) from #Report20100610_053536_1 as a,(select qty=isnull(sum(isnull(qty,0)),0),totalitem,subitem,childitemtype from #Report20100610_053536_1 group by type,totalitem,subitem,childitemtype having type='3' and childitemtype='-') as b where a.totalitem=b.totalitem and a.subitem=b.subitem and a.type='2'
update #Report20100610_053536_1 set qty=isnull(a.qty,0)+isnull(b.qty,0) from #Report20100610_053536_1 as a,(select qty=isnull(sum(isnull(qty,0)),0),totalitem,subitemtype from #Report20100610_053536_1 group by type,totalitem,subitemtype having type='2' and subitemtype='+') as b where a.totalitem=b.totalitem and a.type='1'
update #Report20100610_053536_1 set qty=isnull(a.qty,0)-isnull(b.qty,0) from #Report20100610_053536_1 as a,(select qty=isnull(sum(isnull(qty,0)),0),totalitem,subitemtype from #Report20100610_053536_1 group by type,totalitem,subitemtype having type='2' and subitemtype='-') as b where a.totalitem=b.totalitem and a.type='1'
--先取得最下級的金額(本期)
update #Report20100610_053536_1 set qty2=isnull(b.qty2,0) from #Report20100610_053536_1 as a,(select sum(isnull(qty,0)) as qty2,subjectid from #Report_053536 group by subjectid) as b where a.subjectid=b.subjectid and a.type='3' and a.sumtype='1'
update #Report20100610_053536_1 set qty2=isnull(a.qty2,0)+isnull(b.qty2,0) from #Report20100610_053536_1 as a,(select qty2=isnull(sum(isnull(qty2,0)),0),totalitem,subitem,childitemtype from #Report20100610_053536_1 group by type,totalitem,subitem,childitemtype having type='3' and childitemtype='+') as b where a.totalitem=b.totalitem and a.subitem=b.subitem and a.type='2'
update #Report20100610_053536_1 set qty2=isnull(a.qty2,0)-isnull(b.qty2,0) from #Report20100610_053536_1 as a,(select qty2=isnull(sum(isnull(qty2,0)),0),totalitem,subitem,childitemtype from #Report20100610_053536_1 group by type,totalitem,subitem,childitemtype having type='3' and childitemtype='-') as b where a.totalitem=b.totalitem and a.subitem=b.subitem and a.type='2'
update #Report20100610_053536_1 set qty2=isnull(a.qty2,0)+isnull(b.qty2,0) from #Report20100610_053536_1 as a,(select qty2=isnull(sum(isnull(qty2,0)),0),totalitem,subitemtype from #Report20100610_053536_1 group by type,totalitem,subitemtype having type='2' and subitemtype='+') as b where a.totalitem=b.totalitem and a.type='1'
update #Report20100610_053536_1 set qty2=isnull(a.qty2,0)-isnull(b.qty2,0) from #Report20100610_053536_1 as a,(select qty2=isnull(sum(isnull(qty2,0)),0),totalitem,subitemtype from #Report20100610_053536_1 group by type,totalitem,subitemtype having type='2' and subitemtype='-') as b where a.totalitem=b.totalitem and a.type='1'
--獲取負債表設定[2]中的數據
--獲取報表公式主項目的信息
select * into #CashFlow2 from AcCashTotalItem(nolock) where printtype='assetliabilitysheet2' and companyid=@companyid order by totalitem
select * into #Report20100610_053536_2 from #Report20100610_053536_21 where 1=2
--依次查找各個主項目
set @id=(select min(id) from #CashFlow2)
while @id<=(select max(id) from #CashFlow2)
begin
select @oldtotalitem=totalitem from #CashFlow2 where id=@id
--獲取主項目下的子項目
insert #Report20100610_053536_2(type,totalitem,itemname,formulalevel,isvisible) select '1',@oldtotalitem,itemname,formulalevel,isvisible from #CashFlow2 where id=@id
set @i=(select min(id) from AcCashSubItem(nolock) where printtype='assetliabilitysheet2' and companyid=@companyid and totalitem=@oldtotalitem)
--依次查找各個子項目
while @i<=(select max(id) from AcCashSubItem(nolock) where printtype='assetliabilitysheet2' and companyid=@companyid and totalitem=@oldtotalitem)
begin
select @oldsubitem=subitem from AcCashSubItem(nolock) where printtype='assetliabilitysheet2' and id=@i and companyid=@companyid
insert #Report20100610_053536_2(type,totalitem,subitem,itemname,subitemtype,subisvisible) select '2',totalitem,subitem,' '+itemname,itemtype,isvisible from AcCashSubItem(nolock) where id=@i and companyid=@companyid
--含下級科目
insert #Report20100610_053536_2(type,totalitem,subitem,item,itemname,childitemtype,childisvisible,subjectid,subjectname,sumtype) select '3',a.totalitem,a.subitem,a.item,' '+a.itemname,a.itemtype,a.isvisible,b.subjectid,b.subjectname,a.sumtype from AcCashItem as a(nolock) join subjectitem as b(nolock) on a.subjectid=left(b.subjectid,len(a.subjectid)) where a.printtype='assetliabilitysheet2' and a.companyid=@companyid and a.totalitem=@oldtotalitem and a.subitem=@oldsubitem and isnull(a.isparent,0)=1 order by a.item
--不含下級科目
insert #Report20100610_053536_2(type,totalitem,subitem,item,itemname,childitemtype,childisvisible,subjectid,subjectname,sumtype) select '3',a.totalitem,a.subitem,a.item,' '+a.itemname,a.itemtype,a.isvisible,b.subjectid,b.subjectname,a.sumtype from AcCashItem as a(nolock) join subjectitem as b(nolock) on a.subjectid=b.subjectid where a.printtype='assetliabilitysheet2' and a.companyid=@companyid and a.totalitem=@oldtotalitem and a.subitem=@oldsubitem and isnull(a.isparent,0)=0 order by a.item
set @i=@i+1
end
set @id=@id+1
end
--先取得最下級的金額(本期)
update #Report20100610_053536_2 set qty=isnull(b.qty,0) from #Report20100610_053536_2 as a,(select sum(isnull(qty,0)) as qty,subjectid from #Report_053536_bef group by subjectid) as b where a.subjectid=b.subjectid and a.type='3' and a.sumtype='1'
update #Report20100610_053536_2 set qty=isnull(a.qty,0)+isnull(b.qty,0) from #Report20100610_053536_2 as a,(select qty=isnull(sum(isnull(qty,0)),0),totalitem,subitem,childitemtype from #Report20100610_053536_2 group by type,totalitem,subitem,childitemtype having type='3' and childitemtype='+') as b where a.totalitem=b.totalitem and a.subitem=b.subitem and a.type='2'
update #Report20100610_053536_2 set qty=isnull(a.qty,0)-isnull(b.qty,0) from #Report20100610_053536_2 as a,(select qty=isnull(sum(isnull(qty,0)),0),totalitem,subitem,childitemtype from #Report20100610_053536_2 group by type,totalitem,subitem,childitemtype having type='3' and childitemtype='-') as b where a.totalitem=b.totalitem and a.subitem=b.subitem and a.type='2'
update #Report20100610_053536_2 set qty=isnull(a.qty,0)+isnull(b.qty,0) from #Report20100610_053536_2 as a,(select qty=isnull(sum(isnull(qty,0)),0),totalitem,subitemtype from #Report20100610_053536_2 group by type,totalitem,subitemtype having type='2' and subitemtype='+') as b where a.totalitem=b.totalitem and a.type='1'
update #Report20100610_053536_2 set qty=isnull(a.qty,0)-isnull(b.qty,0) from #Report20100610_053536_2 as a,(select qty=isnull(sum(isnull(qty,0)),0),totalitem,subitemtype from #Report20100610_053536_2 group by type,totalitem,subitemtype having type='2' and subitemtype='-') as b where a.totalitem=b.totalitem and a.type='1'
--先取得最下級的金額(本期)
update #Report20100610_053536_2 set qty2=isnull(b.qty2,0) from #Report20100610_053536_2 as a,(select sum(isnull(qty,0)) as qty2,subjectid from #Report_053536 group by subjectid) as b where a.subjectid=b.subjectid and a.type='3' and a.sumtype='1'
update #Report20100610_053536_2 set qty2=isnull(a.qty2,0)+isnull(b.qty2,0) from #Report20100610_053536_2 as a,(select qty2=isnull(sum(isnull(qty2,0)),0),totalitem,subitem,childitemtype from #Report20100610_053536_2 group by type,totalitem,subitem,childitemtype having type='3' and childitemtype='+') as b where a.totalitem=b.totalitem and a.subitem=b.subitem and a.type='2'
update #Report20100610_053536_2 set qty2=isnull(a.qty2,0)-isnull(b.qty2,0) from #Report20100610_053536_2 as a,(select qty2=isnull(sum(isnull(qty2,0)),0),totalitem,subitem,childitemtype from #Report20100610_053536_2 group by type,totalitem,subitem,childitemtype having type='3' and childitemtype='-') as b where a.totalitem=b.totalitem and a.subitem=b.subitem and a.type='2'
update #Report20100610_053536_2 set qty2=isnull(a.qty2,0)+isnull(b.qty2,0) from #Report20100610_053536_2 as a,(select qty2=isnull(sum(isnull(qty2,0)),0),totalitem,subitemtype from #Report20100610_053536_2 group by type,totalitem,subitemtype having type='2' and subitemtype='+') as b where a.totalitem=b.totalitem and a.type='1'
update #Report20100610_053536_2 set qty2=isnull(a.qty2,0)-isnull(b.qty2,0) from #Report20100610_053536_2 as a,(select qty2=isnull(sum(isnull(qty2,0)),0),totalitem,subitemtype from #Report20100610_053536_2 group by type,totalitem,subitemtype having type='2' and subitemtype='-') as b where a.totalitem=b.totalitem and a.type='1'
--獲取資產負債設定[1]公式(統計合計項目)
insert #formula(totalitem,formulalevel) select distinct totalitem,formulalevel from #Report20100610_053536_1 where isnull(formulalevel,'')<>'' and type='1' order by formulalevel
set @id=(select min(id) from #formula)
--依次設置統計合計項目
while @id<=(select max(id) from #formula)
begin
select @oldtotalitem=totalitem from #formula where id=@id
update #Report20100610_053536_1 set qty=isnull(b.qty,0)-isnull(c.qty,0) from #Report20100610_053536_1 as a ,
(select qty=sum(isnull(qty,0)) from #Report20100610_053536_1 where type='1' and totalitem in (select distinct item from AcCashItemformula where totalitem=@oldtotalitem and companyid=@companyid and printtype='assetliabilitysheet1' and itemtype='+' ) ) as b,
(select qty=sum(isnull(qty,0)) from #Report20100610_053536_1 where type='1' and totalitem in (select distinct item from AcCashItemformula where totalitem=@oldtotalitem and companyid=@companyid and printtype='assetliabilitysheet1' and itemtype='-' ) ) as c
where a.type='1' and a.totalitem=@oldtotalitem--前期
update #Report20100610_053536_1 set qty2=isnull(b.qty2,0)-isnull(c.qty2,0) from #Report20100610_053536_1 as a ,
(select qty2=sum(isnull(qty2,0)) from #Report20100610_053536_1 where type='1' and totalitem in (select distinct item from AcCashItemformula where totalitem=@oldtotalitem and companyid=@companyid and printtype='assetliabilitysheet1' and itemtype='+' ) ) as b,
(select qty2=sum(isnull(qty2,0)) from #Report20100610_053536_1 where type='1' and totalitem in (select distinct item from AcCashItemformula where totalitem=@oldtotalitem and companyid=@companyid and printtype='assetliabilitysheet1' and itemtype='-' ) ) as c
where a.type='1' and a.totalitem=@oldtotalitem--本期
set @id=@id+1
end
--獲取資產負債設定[2]公式(統計合計項目)
delete #formula
insert #formula(totalitem,formulalevel) select distinct totalitem,formulalevel from #Report20100610_053536_2 where isnull(formulalevel,'')<>'' and type='1' order by formulalevel
set @id=(select min(id) from #formula)
--依次設置統計合計項目
while @id<=(select max(id) from #formula)
begin
select @oldtotalitem=totalitem from #formula where id=@id
update #Report20100610_053536_2 set qty=b.qty from #Report20100610_053536_2 as a ,(select qty=sum(isnull(qty,0)) from #Report20100610_053536_2 where type='1' and totalitem in (select distinct item from AcCashItemformula(nolock) where totalitem=@oldtotalitem and companyid=@companyid and printtype='assetliabilitysheet2' ) ) as b where a.type='1' and a.totalitem=@oldtotalitem
update #Report20100610_053536_2 set qty2=b.qty2 from #Report20100610_053536_2 as a ,(select qty2=sum(isnull(qty2,0)) from #Report20100610_053536_2 where type='1' and totalitem in (select distinct item from AcCashItemformula(nolock) where totalitem=@oldtotalitem and companyid=@companyid and printtype='assetliabilitysheet2' ) ) as b where a.type='1' and a.totalitem=@oldtotalitem
set @id=@id+1
end
--合并左右兩側的數據項目
insert #Report20100610_053536_11(itemname,qty,qty2) select itemname,qty,qty2 from #Report20100610_053536_1 where isnull(isvisible,0)=0 and isnull(subisvisible,0)=0 and isnull(childisvisible,0)=0 order by totalitem,subitem,item
insert #Report20100610_053536_21(itemname,qty,qty2) select itemname,qty,qty2 from #Report20100610_053536_2 where isnull(isvisible,0)=0 and isnull(subisvisible,0)=0 and isnull(childisvisible,0)=0 order by totalitem,subitem,item
if ( select max(id) from #Report20100610_053536_11 )>=( select max(id) from #Report20100610_053536_21 )
begin
insert #Report20100610_053536(subjectname,befprice,price) select itemname,isnull(qty,0),isnull(qty2,0) from #Report20100610_053536_11 order by id
update #Report20100610_053536 set subjectname1=b.itemname,befprice1=b.qty,price1=b.qty2 from #Report20100610_053536 as a,#Report20100610_053536_21 as b where a.id=b.id
end
else
begin
insert #Report20100610_053536(subjectname1,befprice1,price1) select itemname,isnull(qty,0),isnull(qty2,0) from #Report20100610_053536_21 order by id
update #Report20100610_053536 set subjectname=b.subjectname,befprice=b.qty,price=b.qty2 from #Report20100610_053536 as a,#Report20100610_053536_11 as b where a.id=b.id
end
update #Report20100610_053536 set spanid=year(convert(datetime,@a1)),mon=month(convert(datetime,@a1))
select * from #Report20100610_053536
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
其他的會計報表使用報表公式的數據統計方法可以參考上述内容進行編寫。