金蝶K3系统定制国际销售日报表

销售日报手工输出耗时长、出错概率大,本文章介绍如何从K3后台数据库抽取相关数据自动生成国际销售日报表,释放报表维护人员工作。报表制作人员每天只需要点击刷新数据库按钮即可实现日报的自动更新。

实现逻辑:

1、使用IMS系统做到款确认

2、使用K3系统销售模块单据作为销售报表主数据来源;K3客户资料为客户销售区域、国家数据来源;

3、国际销售日报体现3部分的销售数据:本月全部出库/退库数据+本月部分出库数据中未出库部分+历史未出库数据

 

代码实现:

 
  1. CREATE view [dbo].[outorder]

  2. as

  3. select

  4. t.fbillno 订单号,--订单号

  5. t.FHeadSelfS0155 客户订单号,--客户订单号

  6. --t5.fname 销售区域,--销售区域

  7. t66.fname 国家,--国家

  8. t2.fname 客户名称,--客户名称

  9. t4.fname 业务员,--业务员

  10. case when t.fcurrencyid=1 then 'CNY' when t.fcurrencyid=1000 then 'USD' when t.fcurrencyid=1001 then 'EUR' else '' end 币种,--币别

  11. case when t2.FNumber like '5.%' then t.fdate else t7.FG13l181129246 end 到款日期,--到款日期

  12. case when t2.FNumber like '5.%' then t1.fauxqty*t1.ftaxprice when t7.FG13l181129246 is null then null else t1.fauxqty*t1.ftaxprice end 到款金额原币,--到款金额原币

  13. case when t2.FNumber like '5.%' then null when t7.FG13l181129246 is null then t1.fauxqty*t1.ftaxprice else null end 未到款金额原币,--未到款金额原币

  14. t.fdate 下单日期,--下单日期

  15. T1.FDate 需求日期,--需求日期

  16. null 发货日期,--发货日期

  17. --t8.fmodel 产品型号,--产品型号

  18. t1.fauxqty 下单数量,--下单台数,没有出库时,取订单数

  19. t1.ftaxprice 销售单价,--销售单价

  20. t1.fauxqty*t1.ftaxprice 行业务金额原币,--行业务金额

  21. case when t.fcurrencyid=1 then t1.fauxqty*t1.ftaxprice/1.17 else t1.fauxqty*t1.ftaxprice end 行业务不含税原币,--行业务金额原币不含税

  22. case when t.fcurrencyid=1 then t1.fauxqty*t1.ftaxprice/1.17 else t1.fauxqty*t1.ftaxprice*t11.FExchangeRate end 行业务不含税CNY,--行业务不含税CNY,

  23. 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,

  24. null 已做销售不含税原币,--已做销售不含税原币

  25. null 已做销售CNY,--已做销售CNY,

  26. null 已做销售USD,--已做销售USD,

  27. null 发货台数,--发货台数

  28. t8.fnumber 物料编码,--物料编码

  29. t8.fname 物料名称--物料名称

  30. from [K3].[dbo].seorder t--销售订单

  31. inner join [K3].[dbo].SEOrderEntry T1 ON T1.FinterID=T.finterid and t1.fauxprice>0 and t1.fmrpautoclosed=1 and t1.fstockqty=0--订单行数据

  32. inner join [K3].[dbo].t_organization T2 ON T2.FitemID=T.fcustid --购货单位

  33. inner join [K3].[dbo].t_department T3 ON T3.FitemID=T.fdeptid and T3.FitemID=140 --销售部门

  34. inner join [K3].[dbo].t_Base_Emp T4 ON T4.FitemID=T.fempid--业务员

  35. inner join [K3].[dbo].t_SubMessage T5 ON T5.FinterID=T2.fregionid--购货单位调用销售区域

  36. inner join [K3].[dbo].t_SubMessage T6 ON T6.FinterID=T2.ftypeid--购货单位调用客户类型

  37. 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)--财务到款系统

  38. inner join [K3].[dbo].t_icitem T8 ON T8.FitemID=T1.fitemid--物料表

  39. 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--销售出库表体

  40. left join [K3].[dbo].icstockbill T10 ON T9.FinterID=T10.finterid --and t10.fcheckerid is not null--销售出库表头

  41. inner join [K3].[dbo].t_SubMessage T66 ON T66.FInterID=T.FHeadSelfS0156--购货单位调用国家

  42. 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)

  43. 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)

  44. where t.fcancellation=0 and t.fchangemark=0 and fheadselfs0150<>51249

  45. --以上数据为全部未出库数据

  46.  
  47. union all

  48.  
  49. select

  50. t.fbillno 订单号,--订单号

  51. t.FHeadSelfS0155 客户订单号,--客户订单号

  52. --t5.FName 销售区域,--销售区域

  53. t66.fname 国家,--国家

  54. t2.fname 客户名称,--客户名称

  55. t4.fname 业务员,--业务员

  56. case when t.fcurrencyid=1 then 'CNY' when t.fcurrencyid=1000 then 'USD' when t.fcurrencyid=1001 then 'EUR' else '' end 币种,--币别

  57. case when t2.FNumber like '5.%' then t.fdate else t7.FG13l181129246 end 到款日期,--到款日期

  58. 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 到款金额原币,--到款金额

  59. case when T2.FNumber like '5.%' then null when t7.FG13l181129246 is null then (t1.fauxqty-t1.FStockQty)*t1.ftaxprice else null end 未到款金额原币,--未到款金额

  60. t.fdate 下单日期,--下单日期

  61. T1.FDate 需求日期,--需求日期

  62. null 发货日期,--发货日期

  63. --t8.fmodel 产品型号,--产品型号

  64. t1.fauxqty-t1.FStockQty 下单台数,--下单台数,取订单数-已出库数量

  65. t1.ftaxprice 销售单价,--销售单价

  66. (t1.fauxqty-t1.FStockQty)*t1.ftaxprice 行业务金额原币,--行业务金额

  67. case when t.fcurrencyid=1 then (t1.fauxqty-t1.FStockQty)*t1.ftaxprice/1.17 else (t1.fauxqty-t1.FStockQty)*t1.ftaxprice end 行业务不含税原币,--行业务金额原币不含税

  68. 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,

  69. 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,

  70. null 已做销售不含税原币,--已做销售不含税原币

  71. null 已做销售CNY,--已做销售CNY,

  72. null 已做销售USD,--已做销售USD,

  73. null 发货台数,--发货台数

  74. t8.fnumber 物料编码,--物料编码

  75. t8.fname 物料名称--物料名称

  76. from [K3].[dbo].seorder t--销售订单

  77. 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 --订单行数据

  78. inner join [K3].[dbo].t_organization T2 ON T2.FitemID=T.fcustid --购货单位

  79. inner join [K3].[dbo].t_department T3 ON T3.FitemID=T.fdeptid and T3.FitemID=140--销售部门

  80. inner join [K3].[dbo].t_Base_Emp T4 ON T4.FitemID=T.fempid--业务员

  81. inner join [K3].[dbo].t_SubMessage T5 ON T5.FinterID=T2.fregionid--购货单位调用销售区域

  82. inner join [K3].[dbo].t_SubMessage T6 ON T6.FinterID=T2.ftypeid--购货单位调用客户类型

  83. 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)--财务到款系统

  84. inner join [K3].[dbo].t_icitem T8 ON T8.FitemID=T1.fitemid--物料表

  85. inner join [K3].[dbo].t_SubMessage T66 ON T66.FInterID=T.FHeadSelfS0156--购货单位调用国家

  86. 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)

  87. 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)

  88. where t.fcancellation=0 and t.fchangemark=0 and fheadselfs0150<>51249

  89. --以上语句为部分出库数据中未出库部分

  90.  
  91. union all

  92.  
  93. select

  94. t.forderbillno 订单号,--订单号

  95. t10.FHeadSelfS0155 客户订单号,--客户订单号

  96. --t5.fname 大区,--销售区域

  97. t66.fname 国家,--国家

  98. t2.fname 客户名称,--客户名称

  99. t4.fname 业务员,--业务员

  100. case when t10.fcurrencyid=1 then 'CNY' when t10.fcurrencyid=1000 then 'USD' when t10.fcurrencyid=1001 then 'EUR' else '' end 币种,--币别

  101. case when t7.FG13l181129246 is null then t1.fdate else t7.FG13l181129246 end 到款日期,--到款日期

  102. t.fqty*t9.ftaxprice 到款金额原币,--到款金额

  103. null 未到款金额原币,--未到款金额

  104. t10.fdate 下单日期,--下单日期

  105. T9.FDate 需求日期,--需求日期

  106. t1.fdate 发货日期,--发货日期

  107. --t8.fmodel 产品型号,--产品型号

  108. t.fqty 下单数量,--下单台数,有出库时,取出库数,没有出库时,取订单数

  109. t9.ftaxprice 销售单价,--销售单价原币

  110. t.fqty*t9.ftaxprice 行业务金额原币,--行业务金额原币

  111. case when t10.fcurrencyid=1 then t.fqty*t9.ftaxprice/1.17 else t.fqty*t9.ftaxprice end 行业务不含税原币,--行业务金额原币不含税

  112. case when t10.fcurrencyid=1 then t.fqty*t9.ftaxprice/1.17 else t.fqty*t9.ftaxprice*t11.FExchangeRate end 行业务不含税CNY,--行业务不含税CNY,

  113. 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,

  114. case when t10.fcurrencyid=1 then t.fqty*t9.ftaxprice/1.17 else t.fqty*t9.ftaxprice end 已做销售不含税原币,--已做销售不含税原币

  115. case when t10.fcurrencyid=1 then t.fqty*t9.ftaxprice/1.17 else t.fqty*t9.ftaxprice*t11.FExchangeRate end 已做销售CNY,--已做销售CNY,

  116. 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,

  117. t.fqty 发货数量,--发货台数

  118. t8.fnumber 物料编码,--物料编码

  119. t8.fname 物料名称--物料名称

  120. from [K3].[dbo].icstockbillentry t--销售出库明细

  121. inner join [K3].[dbo].icstockbill T1 ON T1.FinterID=t.finterid --销售出库

  122. inner join [K3].[dbo].t_organization T2 ON T2.FitemID=T1.fsupplyid --购货单位

  123. inner join [K3].[dbo].t_department T3 ON T3.FitemID=T1.fdeptid and T3.FitemID=140 --销售部门

  124. inner join [K3].[dbo].t_Base_Emp T4 ON T4.FitemID=T1.fempid--业务员

  125. inner join [K3].[dbo].t_SubMessage T5 ON T5.FinterID=T2.fregionid--购货单位调用销售区域

  126. inner join [K3].[dbo].t_SubMessage T6 ON T6.FInterID=T2.ftypeid--购货单位调用客户类型

  127. 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)--财务到款系统

  128. inner join [K3].[dbo].t_icitem T8 ON T8.FitemID=T.fitemid--物料表

  129. inner join [K3].[dbo].seorderentry T9 ON T.ForderinterID=T9.finterid and t.forderentryid=t9.fentryid and t9.fauxprice>0--销售出库表体

  130. 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 --销售出库表头

  131. inner join [K3].[dbo].t_SubMessage T66 ON T66.FInterID=T10.FHeadSelfS0156--购货单位调用国家

  132. 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)

  133. 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)

  134. where t.FSEOutinterid>0 and CONVERT(varchar(6),t1.FDate,112)=CONVERT(varchar(6),GETDATE(),112) and t1.fcheckdate is not null

  135. --以上语句为全部出货订单数据,含退库数据,销售出库未审核不计入


Excel调用如上视图即可。不再赘述!可以在Excel里边对明细数据进行汇总等操作。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值