销售日报手工输出耗时长、出错概率大,本文章介绍如何从K3后台数据库抽取相关数据自动生成国际销售日报表,释放报表维护人员工作。报表制作人员每天只需要点击刷新数据库按钮即可实现日报的自动更新。
实现逻辑:
1、使用IMS系统做到款确认
2、使用K3系统销售模块单据作为销售报表主数据来源;K3客户资料为客户销售区域、国家数据来源;
3、国际销售日报体现3部分的销售数据:本月全部出库/退库数据+本月部分出库数据中未出库部分+历史未出库数据
代码实现:
-
CREATE view [dbo].[outorder]
-
as
-
select
-
t.fbillno 订单号,--订单号
-
t.FHeadSelfS0155 客户订单号,--客户订单号
-
--t5.fname 销售区域,--销售区域
-
t66.fname 国家,--国家
-
t2.fname 客户名称,--客户名称
-
t4.fname 业务员,--业务员
-
case when t.fcurrencyid=1 then 'CNY' when t.fcurrencyid=1000 then 'USD' when t.fcurrencyid=1001 then 'EUR' else '' end 币种,--币别
-
case when t2.FNumber like '5.%' then t.fdate else t7.FG13l181129246 end 到款日期,--到款日期
-
case when t2.FNumber like '5.%' then t1.fauxqty*t1.ftaxprice when t7.FG13l181129246 is null then null else t1.fauxqty*t1.ftaxprice end 到款金额原币,--到款金额原币
-
case when t2.FNumber like '5.%' then null when t7.FG13l181129246 is null then t1.fauxqty*t1.ftaxprice else null end 未到款金额原币,--未到款金额原币
-
t.fdate 下单日期,--下单日期
-
T1.FDate 需求日期,--需求日期
-
null 发货日期,--发货日期
-
--t8.fmodel 产品型号,--产品型号
-
t1.fauxqty 下单数量,--下单台数,没有出库时,取订单数
-
t1.ftaxprice 销售单价,--销售单价
-
t1.fauxqty*t1.ftaxprice 行业务金额原币,--行业务金额
-
case when t.fcurrencyid=1 then t1.fauxqty*t1.ftaxprice/1.17 else t1.fauxqty*t1.ftaxprice end 行业务不含税原币,--行业务金额原币不含税
-
case when t.fcurrencyid=1 then t1.fauxqty*t1.ftaxprice/1.17 else t1.fauxqty*t1.ftaxprice*t11.FExchangeRate end 行业务不含税CNY,--行业务不含税CNY,
-
case when t.fcurrencyid=1 then t1.fauxqty*t1.ftaxprice/1.17/t12.FExchangeRate else t1.fauxqty*t1.ftaxprice*t11.FExchangeRate/t12.FExchangeRate end 行业务不含税USD,--行业务不含税USD,
-
null 已做销售不含税原币,--已做销售不含税原币
-
null 已做销售CNY,--已做销售CNY,
-
null 已做销售USD,--已做销售USD,
-
null 发货台数,--发货台数
-
t8.fnumber 物料编码,--物料编码
-
t8.fname 物料名称--物料名称
-
from [K3].[dbo].seorder t--销售订单
-
inner join [K3].[dbo].SEOrderEntry T1 ON T1.FinterID=T.finterid and t1.fauxprice>0 and t1.fmrpautoclosed=1 and t1.fstockqty=0--订单行数据
-
inner join [K3].[dbo].t_organization T2 ON T2.FitemID=T.fcustid --购货单位
-
inner join [K3].[dbo].t_department T3 ON T3.FitemID=T.fdeptid and T3.FitemID=140 --销售部门
-
inner join [K3].[dbo].t_Base_Emp T4 ON T4.FitemID=T.fempid--业务员
-
inner join [K3].[dbo].t_SubMessage T5 ON T5.FinterID=T2.fregionid--购货单位调用销售区域
-
inner join [K3].[dbo].t_SubMessage T6 ON T6.FinterID=T2.ftypeid--购货单位调用客户类型
-
left join [IMS].[Portal].[dbo].T13T181861x2257 t7 on t7.id=(select top 1 id from [IMS].[Portal].[dbo].T13T181861x2257 as qq where qq.Fs122318127T46=t.fbillno)--财务到款系统
-
inner join [K3].[dbo].t_icitem T8 ON T8.FitemID=T1.fitemid--物料表
-
left join [K3].[dbo].icstockbillentry T9 ON T9.ForderinterID=T1.finterid and t9.forderentryid=t1.fentryid and t9.FSEOutinterid>0 and t9.fqty is null--销售出库表体
-
left join [K3].[dbo].icstockbill T10 ON T9.FinterID=T10.finterid --and t10.fcheckerid is not null--销售出库表头
-
inner join [K3].[dbo].t_SubMessage T66 ON T66.FInterID=T.FHeadSelfS0156--购货单位调用国家
-
left join [K3].[dbo].t_ExchangeRateEntry t11 on t11.FCyTo=T.FCurrencyID and t.FExchangeRateType=1 and CONVERT(varchar(6),t11.FBegDate,112)=CONVERT(varchar(6),GETDATE(),112)
-
left join [K3].[dbo].t_ExchangeRateEntry t12 on t12.FCyTo=1000 and t12.FExchangeRateType=1 and CONVERT(varchar(6),t12.FBegDate,112)=CONVERT(varchar(6),GETDATE(),112)
-
where t.fcancellation=0 and t.fchangemark=0 and fheadselfs0150<>51249
-
--以上数据为全部未出库数据
-
union all
-
select
-
t.fbillno 订单号,--订单号
-
t.FHeadSelfS0155 客户订单号,--客户订单号
-
--t5.FName 销售区域,--销售区域
-
t66.fname 国家,--国家
-
t2.fname 客户名称,--客户名称
-
t4.fname 业务员,--业务员
-
case when t.fcurrencyid=1 then 'CNY' when t.fcurrencyid=1000 then 'USD' when t.fcurrencyid=1001 then 'EUR' else '' end 币种,--币别
-
case when t2.FNumber like '5.%' then t.fdate else t7.FG13l181129246 end 到款日期,--到款日期
-
case when t2.FNumber like '5.%' then (t1.fauxqty-t1.FStockQty)*t1.ftaxprice when t7.FG13l181129246 is null then null else (t1.fauxqty-t1.FStockQty)*t1.ftaxprice end 到款金额原币,--到款金额
-
case when T2.FNumber like '5.%' then null when t7.FG13l181129246 is null then (t1.fauxqty-t1.FStockQty)*t1.ftaxprice else null end 未到款金额原币,--未到款金额
-
t.fdate 下单日期,--下单日期
-
T1.FDate 需求日期,--需求日期
-
null 发货日期,--发货日期
-
--t8.fmodel 产品型号,--产品型号
-
t1.fauxqty-t1.FStockQty 下单台数,--下单台数,取订单数-已出库数量
-
t1.ftaxprice 销售单价,--销售单价
-
(t1.fauxqty-t1.FStockQty)*t1.ftaxprice 行业务金额原币,--行业务金额
-
case when t.fcurrencyid=1 then (t1.fauxqty-t1.FStockQty)*t1.ftaxprice/1.17 else (t1.fauxqty-t1.FStockQty)*t1.ftaxprice end 行业务不含税原币,--行业务金额原币不含税
-
case when t.fcurrencyid=1 then (t1.fauxqty-t1.FStockQty)*t1.ftaxprice/1.17 else (t1.fauxqty-t1.FStockQty)*t1.ftaxprice*t11.FExchangeRate end 行业务不含税CNY,--行业务不含税CNY,
-
case when t.fcurrencyid=1 then (t1.fauxqty-t1.FStockQty)*t1.ftaxprice/1.17/t12.FExchangeRate else (t1.fauxqty-t1.FStockQty)*t1.ftaxprice*t11.FExchangeRate/t12.FExchangeRate end 行业务不含税USD,--行业务不含税USD,
-
null 已做销售不含税原币,--已做销售不含税原币
-
null 已做销售CNY,--已做销售CNY,
-
null 已做销售USD,--已做销售USD,
-
null 发货台数,--发货台数
-
t8.fnumber 物料编码,--物料编码
-
t8.fname 物料名称--物料名称
-
from [K3].[dbo].seorder t--销售订单
-
inner join [K3].[dbo].SEOrderEntry T1 ON T1.FinterID=T.finterid and t1.fauxprice>0 AND t1.fmrpautoclosed=1 and t1.fauxqty-t1.FStockQty>0 and t1.fstockqty>0 --订单行数据
-
inner join [K3].[dbo].t_organization T2 ON T2.FitemID=T.fcustid --购货单位
-
inner join [K3].[dbo].t_department T3 ON T3.FitemID=T.fdeptid and T3.FitemID=140--销售部门
-
inner join [K3].[dbo].t_Base_Emp T4 ON T4.FitemID=T.fempid--业务员
-
inner join [K3].[dbo].t_SubMessage T5 ON T5.FinterID=T2.fregionid--购货单位调用销售区域
-
inner join [K3].[dbo].t_SubMessage T6 ON T6.FinterID=T2.ftypeid--购货单位调用客户类型
-
left join [IMS].[Portal].[dbo].T13T181861x2257 t7 on t7.id=(select top 1 id from [IMS].[Portal].[dbo].T13T181861x2257 as qq where qq.Fs122318127T46=t.fbillno)--财务到款系统
-
inner join [K3].[dbo].t_icitem T8 ON T8.FitemID=T1.fitemid--物料表
-
inner join [K3].[dbo].t_SubMessage T66 ON T66.FInterID=T.FHeadSelfS0156--购货单位调用国家
-
left join [K3].[dbo].t_ExchangeRateEntry t11 on t11.FCyTo=T.FCurrencyID and t.FExchangeRateType=1 and CONVERT(varchar(6),t11.FBegDate,112)=CONVERT(varchar(6),GETDATE(),112)
-
left join [K3].[dbo].t_ExchangeRateEntry t12 on t12.FCyTo=1000 and t12.FExchangeRateType=1 and CONVERT(varchar(6),t12.FBegDate,112)=CONVERT(varchar(6),GETDATE(),112)
-
where t.fcancellation=0 and t.fchangemark=0 and fheadselfs0150<>51249
-
--以上语句为部分出库数据中未出库部分
-
union all
-
select
-
t.forderbillno 订单号,--订单号
-
t10.FHeadSelfS0155 客户订单号,--客户订单号
-
--t5.fname 大区,--销售区域
-
t66.fname 国家,--国家
-
t2.fname 客户名称,--客户名称
-
t4.fname 业务员,--业务员
-
case when t10.fcurrencyid=1 then 'CNY' when t10.fcurrencyid=1000 then 'USD' when t10.fcurrencyid=1001 then 'EUR' else '' end 币种,--币别
-
case when t7.FG13l181129246 is null then t1.fdate else t7.FG13l181129246 end 到款日期,--到款日期
-
t.fqty*t9.ftaxprice 到款金额原币,--到款金额
-
null 未到款金额原币,--未到款金额
-
t10.fdate 下单日期,--下单日期
-
T9.FDate 需求日期,--需求日期
-
t1.fdate 发货日期,--发货日期
-
--t8.fmodel 产品型号,--产品型号
-
t.fqty 下单数量,--下单台数,有出库时,取出库数,没有出库时,取订单数
-
t9.ftaxprice 销售单价,--销售单价原币
-
t.fqty*t9.ftaxprice 行业务金额原币,--行业务金额原币
-
case when t10.fcurrencyid=1 then t.fqty*t9.ftaxprice/1.17 else t.fqty*t9.ftaxprice end 行业务不含税原币,--行业务金额原币不含税
-
case when t10.fcurrencyid=1 then t.fqty*t9.ftaxprice/1.17 else t.fqty*t9.ftaxprice*t11.FExchangeRate end 行业务不含税CNY,--行业务不含税CNY,
-
case when t10.fcurrencyid=1 then t.fqty*t9.ftaxprice/1.17/t12.FExchangeRate else t.fqty*t9.ftaxprice*t11.FExchangeRate/t12.FExchangeRate end 行业务不含税USD,--行业务不含税USD,
-
case when t10.fcurrencyid=1 then t.fqty*t9.ftaxprice/1.17 else t.fqty*t9.ftaxprice end 已做销售不含税原币,--已做销售不含税原币
-
case when t10.fcurrencyid=1 then t.fqty*t9.ftaxprice/1.17 else t.fqty*t9.ftaxprice*t11.FExchangeRate end 已做销售CNY,--已做销售CNY,
-
case when t10.fcurrencyid=1 then t.fqty*t9.ftaxprice/1.17/t12.FExchangeRate else t.fqty*t9.ftaxprice*t11.FExchangeRate/t12.FExchangeRate end 已做销售USD,--已做销售USD,
-
t.fqty 发货数量,--发货台数
-
t8.fnumber 物料编码,--物料编码
-
t8.fname 物料名称--物料名称
-
from [K3].[dbo].icstockbillentry t--销售出库明细
-
inner join [K3].[dbo].icstockbill T1 ON T1.FinterID=t.finterid --销售出库
-
inner join [K3].[dbo].t_organization T2 ON T2.FitemID=T1.fsupplyid --购货单位
-
inner join [K3].[dbo].t_department T3 ON T3.FitemID=T1.fdeptid and T3.FitemID=140 --销售部门
-
inner join [K3].[dbo].t_Base_Emp T4 ON T4.FitemID=T1.fempid--业务员
-
inner join [K3].[dbo].t_SubMessage T5 ON T5.FinterID=T2.fregionid--购货单位调用销售区域
-
inner join [K3].[dbo].t_SubMessage T6 ON T6.FInterID=T2.ftypeid--购货单位调用客户类型
-
left join [IMS].[Portal].[dbo].T13T181861x2257 t7 on t7.id=(select top 1 id from [IMS].[Portal].[dbo].T13T181861x2257 as qq where qq.Fs122318127T46=t.forderbillno)--财务到款系统
-
inner join [K3].[dbo].t_icitem T8 ON T8.FitemID=T.fitemid--物料表
-
inner join [K3].[dbo].seorderentry T9 ON T.ForderinterID=T9.finterid and t.forderentryid=t9.fentryid and t9.fauxprice>0--销售出库表体
-
inner join [K3].[dbo].seorder T10 ON T10.FinterID=T.forderinterid and t10.fdate>'2012-12-31' and t10.fcancellation=0 and t10.fchangemark=0 --销售出库表头
-
inner join [K3].[dbo].t_SubMessage T66 ON T66.FInterID=T10.FHeadSelfS0156--购货单位调用国家
-
left join [K3].[dbo].t_ExchangeRateEntry t11 on t11.FCyTo=T10.FCurrencyID and t11.FExchangeRateType=1 and CONVERT(varchar(6),t11.FBegDate,112)=CONVERT(varchar(6),t1.fdate,112)
-
left join [K3].[dbo].t_ExchangeRateEntry t12 on t12.FCyTo=1000 and t12.FExchangeRateType=1 and CONVERT(varchar(6),t12.FBegDate,112)=CONVERT(varchar(6),t1.fdate,112)
-
where t.FSEOutinterid>0 and CONVERT(varchar(6),t1.FDate,112)=CONVERT(varchar(6),GETDATE(),112) and t1.fcheckdate is not null
-
--以上语句为全部出货订单数据,含退库数据,销售出库未审核不计入
Excel调用如上视图即可。不再赘述!可以在Excel里边对明细数据进行汇总等操作。