金蝶K3单据与发票核销关系增强视图
-- 多年前,在需要批量检查与核对K3销售出库与K3销售发票有钩稽关系时,发现K3销售发票有钩稽期间,但已钩稽或已对等核销的K3销售出库单上没有对应的钩稽期间,只能通过【上查】或【下查】功能,查到该张单据对应的钩稽销售发票和对等核销的销售出库单,无法实现批量查询销售出库单及与之对应的钩稽销售发票和对等核销的销售出库单,反馈需求后,也没有在当时的K3版本以及后续的K3版本解决,所以借助SQL语句和视图,写了一个增强型的钩稽关系视图,包括了销售出库单和销售发票以及采购入库单和采购发票的钩稽与核销关系,供有需求的朋友参考。
CREATE VIEW ZZVW_ICHookRelationsplus
AS
----以下是对销售出库单据对等核销的进行对应
SELECT h1.fgroupno,--核销内码
h1.FIBNo AS fbillno_ydhm,--原单据号码
h1.ftrantype AS ftrantype_yd,--原单据类型
h1.FIBInterID AS FIBInterID_yd,--在ICSTOCKBILL中的单据内码
h1.FHookType AS FHookType_yd,--业务类型,0-采购,1-销售
h1.FEquityHook AS FEquityHook_yd,--钩稽类型,0-钩稽,1-对等核销
h1.FYear,--钩稽年度
h1.FPeriod,--钩稽期间
Isnull(h2.fibno, 0) AS fbillno_hxdh,--核销单据号码
h2.ftrantype AS ftrantype_hx,--核销单据类型
h2.FIBInterID AS FIBInterID_hx,--在ICSTOCKBILL中的单据内码
h2.FHookType AS FHookType_hx,--业务类型,0-采购,1-销售
h2.FEquityHook AS FEquityHook_hx--钩稽类型,0-钩稽,1-对等核销
FROM (SELECT DISTINCT fgroupno,--核销内码
FIBNo,--单据号码
FIBInterID,--在ICSTOCKBILL中的单据内码
FHookType,--业务类型,0-采购,1-销售
FEquityHook,--钩稽类型,0-钩稽,1-对等核销
FYear,--钩稽年度
FPeriod,--钩稽期间
ftrantype--原单据类型
FROM ichookrelations h1
WHERE fhooktype = 1--钩稽业务类型:1-销售,0-采购
AND ftrantype = 21--单据类型:21-销售出库单,1-采购入库单,80-销售税票,86-销售普票,75-采购税票,76-采购普票
AND FEquityHook = 1--核销类型:1-对等核销,0-发票钩稽
) h1
LEFT JOIN (SELECT DISTINCT fgroupno,--核销内码
FIBNo,--单据号码
FIBInterID,--在ICSTOCKBILL中的单据内码
FHookType,--业务类型,0-采购,1-销售
FEquityHook,--钩稽类型,0-钩稽,1-对等核销
FYear,--钩稽年度
FPeriod,--钩稽期间
ftrantype--原单据类型
FROM ichookrelations h1
WHERE fhooktype = 1--钩稽业务类型:1-销售,0-采购
AND ftrantype = 21--单据类型:21-销售出库单,1-采购入库单,80-销售税票,86-销售普票,75-采购税票,76-采购普票
AND FEquityHook = 1--核销类型:1-对等核销,0-发票钩稽
) h2
ON h1.fgroupno = h2.fgroupno
AND h1.fibno <> h2.fibno
----以上是对销售出库对等核销进行对应
UNION ALL----以下是对销售出库与销售发票进行对应
SELECT h1.fgroupno,--核销内码
h1.FIBNo AS fbillno_ydhm,--原单据号码
h1.ftrantype AS ftrantype_yd,--原单据类型
h1.FIBInterID AS FIBInterID_yd,--在ICSTOCKBILL中的单据内码
h1.FHookType AS FHookType_yd,--业务类型,0-采购,1-销售
h1.FEquityHook AS FEquityHook_yd,--钩稽类型,0-钩稽,1-对等核销
h1.FYear,--钩稽年度
h1.FPeriod,--钩稽期间
Isnull(h2.fibno, 0) AS fbillno_hxdh,--核销单据号码
h2.ftrantype AS ftrantype_hx,--核销单据类型
h2.FIBInterID AS FIBInterID_hx,--在ICSTOCKBILL中的单据内码
h2.FHookType AS FHookType_hx,--业务类型,0-采购,1-销售
h2.FEquityHook AS FEquityHook_hx--钩稽类型,0-钩稽,1-对等核销
FROM (SELECT DISTINCT fgroupno,--核销内码
FIBNo,--单据号码
FIBInterID,--在ICSTOCKBILL中的单据内码
FHookType,--业务类型,0-采购,1-销售
FEquityHook,--钩稽类型,0-钩稽,1-对等核销
FYear,--钩稽年度
FPeriod,--钩稽期间
ftrantype--原单据类型
FROM ichookrelations h1
WHERE fhooktype = 1--钩稽业务类型:1-销售,0-采购
AND ftrantype = 21--单据类型:21-销售出库单,1-采购入库单,80-销售税票,86-销售普票,75-采购税票,76-采购普票
AND FEquityHook = 0--核销类型:1-对等核销,0-发票钩稽
) h1
LEFT JOIN (SELECT DISTINCT fgroupno,--核销内码
FIBNo,--单据号码
FIBInterID,--在ICSTOCKBILL中的单据内码
FHookType,--业务类型,0-采购,1-销售
FEquityHook,--钩稽类型,0-钩稽,1-对等核销
FYear,--钩稽年度
FPeriod,--钩稽期间
ftrantype--原单据类型
FROM ichookrelations h1
WHERE fhooktype = 1--钩稽业务类型:1-销售,0-采购
AND ftrantype IN ( 80, 86 )--单据类型:21-销售出库单,1-采购入库单,80-销售税票,86-销售普票,75-采购税票,76-采购普票
AND FEquityHook = 0--核销类型:1-对等核销,0-发票钩稽
) h2
ON h1.fgroupno = h2.fgroupno
AND h1.fibno <> h2.fibno
----以上是对销售出库与销售发票进行对应
UNION ALL----以下是对包括采购入库单对等核销的进行对应
SELECT h1.fgroupno,--核销内码
h1.FIBNo AS fbillno_ydhm,--原单据号码
h1.ftrantype AS ftrantype_yd,--原单据类型
h1.FIBInterID AS FIBInterID_yd,--在ICSTOCKBILL中的单据内码
h1.FHookType AS FHookType_yd,--业务类型,0-采购,1-销售
h1.FEquityHook AS FEquityHook_yd,--钩稽类型,0-钩稽,1-对等核销
h1.FYear,--钩稽年度
h1.FPeriod,--钩稽期间
Isnull(h2.fibno, 0) AS fbillno_hxdh,--核销单据号码
h2.ftrantype AS ftrantype_hx,--核销单据类型
h2.FIBInterID AS FIBInterID_hx,--在ICSTOCKBILL中的单据内码
h2.FHookType AS FHookType_hx,--业务类型,0-采购,1-销售
h2.FEquityHook AS FEquityHook_hx--钩稽类型,0-钩稽,1-对等核销
FROM (SELECT DISTINCT fgroupno,--核销内码
FIBNo,--单据号码
FIBInterID,--在ICSTOCKBILL中的单据内码
FHookType,--业务类型,0-采购,1-销售
FEquityHook,--钩稽类型,0-钩稽,1-对等核销
FYear,--钩稽年度
FPeriod,--钩稽期间
ftrantype--原单据类型
FROM ichookrelations h1
WHERE fhooktype = 0--钩稽业务类型:1-销售,0-采购
AND ftrantype = 1--单据类型:21-销售出库单,1-采购入库单,80-销售税票,86-销售普票,75-采购税票,76-采购普票
AND FEquityHook = 1--核销类型:1-对等核销,0-发票钩稽
) h1
LEFT JOIN (SELECT DISTINCT fgroupno,--核销内码
FIBNo,--单据号码
FIBInterID,--在ICSTOCKBILL中的单据内码
FHookType,--业务类型,0-采购,1-销售
FEquityHook,--钩稽类型,0-钩稽,1-对等核销
FYear,--钩稽年度
FPeriod,--钩稽期间
ftrantype--原单据类型
FROM ichookrelations h1
WHERE fhooktype = 0--钩稽业务类型:1-销售,0-采购
AND ftrantype = 1--单据类型:21-销售出库单,1-采购入库单,80-销售税票,86-销售普票,75-采购税票,76-采购普票
AND FEquityHook = 1--核销类型:1-对等核销,0-发票钩稽
) h2
ON h1.fgroupno = h2.fgroupno
AND h1.fibno <> h2.fibno
----以上是对采购入库对等核销进行对应
UNION ALL----以下是对采购入库与采购发票进行对应
SELECT h1.fgroupno,--核销内码
h1.FIBNo AS fbillno_ydhm,--原单据号码
h1.ftrantype AS ftrantype_yd,--原单据类型
h1.FIBInterID AS FIBInterID_yd,--在ICSTOCKBILL中的单据内码
h1.FHookType AS FHookType_yd,--业务类型,0-采购,1-销售
h1.FEquityHook AS FEquityHook_yd,--钩稽类型,0-钩稽,1-对等核销
h1.FYear,--钩稽年度
h1.FPeriod,--钩稽期间
Isnull(h2.fibno, 0) AS fbillno_hxdh,--核销单据号码
h2.ftrantype AS ftrantype_hx,--核销单据类型
h2.FIBInterID AS FIBInterID_hx,--在ICSTOCKBILL中的单据内码
h2.FHookType AS FHookType_hx,--业务类型,0-采购,1-销售
h2.FEquityHook AS FEquityHook_hx--钩稽类型,0-钩稽,1-对等核销
FROM (SELECT DISTINCT fgroupno,--核销内码
FIBNo,--单据号码
FIBInterID,--在ICSTOCKBILL中的单据内码
FHookType,--业务类型,0-采购,1-销售
FEquityHook,--钩稽类型,0-钩稽,1-对等核销
FYear,--钩稽年度
FPeriod,--钩稽期间
ftrantype--原单据类型
FROM ichookrelations h1
WHERE fhooktype = 0--钩稽业务类型:1-销售,0-采购
AND ftrantype = 1--单据类型:21-销售出库单,1-采购入库单,80-销售税票,86-销售普票,75-采购税票,76-采购普票
AND FEquityHook = 0--核销类型:1-对等核销,0-发票钩稽
) h1
LEFT JOIN (SELECT DISTINCT fgroupno,--核销内码
FIBNo,--单据号码
FIBInterID,--在ICSTOCKBILL中的单据内码
FHookType,--业务类型,0-采购,1-销售
FEquityHook,--钩稽类型,0-钩稽,1-对等核销
FYear,--钩稽年度
FPeriod,--钩稽期间
ftrantype--原单据类型
FROM ichookrelations h1
WHERE fhooktype = 0--钩稽业务类型:1-销售,0-采购
AND ftrantype IN ( 75, 76 )--单据类型:21-销售出库单,1-采购入库单,80-销售税票,86-销售普票,75-采购税票,76-采购普票
AND FEquityHook = 0--核销类型:1-对等核销,0-发票钩稽
) h2
ON h1.fgroupno = h2.fgroupno
AND h1.fibno <> h2.fibno
----以上是对采购入库与采购发票进行对应
--***本文档到此结束***
金蝶K3单据与发票核销关系增强视图
本文2024-09-16 15:50:48发表“k3wise知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3wise-5441.html