首页 > 数据库 >金蝶K3 SQL报表系列-委外核销检查表

金蝶K3 SQL报表系列-委外核销检查表

时间:2023-05-16 12:14:55浏览次数:45  
标签:检查表 21 委外 decimal u1 K3 -- int

转自:https://blog.csdn.net/mamengna/article/details/111798954

1、创建存储过程:sp_ICStockBill_Check

create procedure [dbo].[sp_ICStockBill_Check]

as

 
set nocount on

declare @currYear int

declare @currPeriod int

 
declare @begindate datetime

declare @enddate datetime

 
--查询期间

 
--select * from t_systemprofile where Fkey='CurrentPeriod' and Fcategory='GL'

 
--select @currYear=Fvalue from t_systemprofile where Fkey='CurrentYear' and Fcategory='IC'

--select @currPeriod=Fvalue from t_systemprofile where Fkey='CurrentPeriod' and Fcategory='IC'

 
--2.取出当前年份

SELECT @currPeriod=FValue FROM t_Systemprofile WHERE FKey='CurrentPeriod' And FCategory='IC'

SELECT @currYear=FValue FROM t_Systemprofile WHERE FKey='CurrentYear' And FCategory='IC'

 
--3.取出当前期间的起始日期

EXECUTE GetPeriodStartEnd 0, @currPeriod, @begindate OUTPUT, @enddate OUTPUT

 
 
 
--委外核销检查表

 
create table #StockBill

(

FInterid int,

FEntryid int,

FOrderInterid int,

ForderEntryid int,

FQty decimal(21,10)

)

 
 
--委外核销材料明细表

create table #icstockbillEntry

(

FStockInterid int,

FStockEntryid int,

FOrderInterid int,

FOrderEntryid int,

FItemid int,

FStarandQty decimal(21,10),

FScrap decimal(21,10),

FQtyMust decimal(21,10),

FQty decimal(21,10)

)

 
--导入委外入库单

--通过此控制委外入库单范围

 
 
insert into #StockBill

(FInterid,FEntryid,FQty,FOrderInterid,ForderEntryid)

select

u1.Finterid,u1.Fentryid,u1.Fqty,u1.FOrderInterID,u1.FOrderEntryID

from ICStockBillEntry u1

inner join ICStockBill t1 on u1.FInterID=t1.FInterID

where t1.FTranType=5 and ISNULL(FCheckerid,0)<>0

--过滤条件

and t1.Fdate>=@begindate and t1.Fdate<=@enddate --

 
 
--生产委外应核销材料明细表

 
insert into #icstockbillEntry

(FStockInterid,FStockEntryid,FOrderInterid,FOrderEntryid,FItemid,FStarandQty,FScrap,FQtyMust)

select

u1.FInterid,u1.FEntryid,u1.FOrderInterid,u1.ForderEntryid,t2.FItemID,t2.FQtyScrap,t2.FScrap,u1.FQty*t2.FQtyScrap*(1+t2.FScrap/100)

from #StockBill u1

inner join PPBOM t1 on u1.FOrderInterid=t1.FICMOInterID and u1.ForderEntryid=t1.FOrderEntryID

inner join PPBOMEntry t2 on t2.FInterID=t1.FInterID

 
 
--委外实际核销未出下在投料单物料

 
insert into #icstockbillEntry

(FStockInterid,FStockEntryid,FOrderInterid,FOrderEntryid,FItemid,FStarandQty,FScrap,FQtyMust)

select

u1.FDInterID,u1.FDEntryID,t2.FOrderInterID,t2.FOrderEntryID,t2.FItemID,0,0,0

from ICClientVer u1

left join #icstockbillEntry t1 on u1.FDInterID=t1.FStockInterid and u1.FDEntryID=t1.FStockEntryid

inner join ICStockBillEntry t2 on t2.FInterID=u1.FSInterID and t2.FEntryID=u1.FSEntryID and t2.FItemID=t1.FItemid

where t1.FStockInterid is null

group by u1.FDInterID,u1.FDEntryID,t2.FOrderInterID,t2.FOrderEntryID,t2.FItemID

 
 
--跟新委外核销数量

 
update u1

set u1.FQty=t1.Fqty

from #icstockbillEntry u1

inner join

(

select

k1.FDInterID,k1.FDEntryID,k3.Fitemid,SUM(k1.Fqty) as FQty

from

ICClientVer k1

inner join ICStockBillEntry k3 on k3.FInterID=k1.FSInterID and k3.FEntryID=k1.FSEntryID

group by k1.FDInterID,k1.FDEntryID,k3.Fitemid

)t1 on t1.FDInterID=u1.FStockInterid and t1.FDEntryID=u1.FStockEntryid and u1.FItemid=t1.FItemID

 
 
 
 
--生成报表

 
 
select

t4.FBillNo 委外入库单号,

v1.FEntryid 入库单行号,

t4.FDate 入库日期,

t3.FBillNo 委外订单号,

t2.FEntryID 订单行号,

t5.FNumber 产品代码,

t5.FName 产品名称,

t5.FModel 产品规格,

t2.FQty 订单数量,

t2.FStockQty 订单入库数量,

t1.FQty 入库数量,

t6.FNumber 材料代码,

t6.FName 材料名称,

t6.FModel 材料规格,

u1.FStarandQty 标准用量,

u1.FScrap [损耗(%)],

u1.FQtyMust 应核销数量,

isnull(u1.FQty,0) 实际核销数量,

u1.FQtyMust-isnull(u1.FQty,0) 差异数量

from

#StockBill v1

left join #icstockbillEntry u1 on u1.FStockInterid=v1.FInterid and u1.FStockEntryid=v1.FEntryid

left join ICStockBillEntry t1 on v1.FInterid=t1.FInterID and v1.FEntryid=t1.FEntryID

left join ICStockBill t4 on t4.FInterID=t1.FInterID

left join ICSubContractEntry t2 on t2.FInterID=u1.FOrderInterid and t2.FEntryID=u1.FOrderEntryid

left join ICSubContract t3 on t3.FInterID=t2.FInterID

left join t_ICItem t5 on t5.FItemID=t1.FItemID

left join t_ICItem t6 on t6.FItemID=u1.FItemid

order by u1.FStockInterid,u1.FStockEntryid

 
drop table #icstockbillEntry

drop table #StockBill

2、K3查询分析工具调用:

exec sp_icstockbill_check

 

标签:检查表,21,委外,decimal,u1,K3,--,int
From: https://www.cnblogs.com/a247347515/p/17404524.html

相关文章

  • Rockchip RK3399-官方固件方式加载uboot
    ----------------------------------------------------------------------------------------------------------------------------开发板 :NanoPC-T4开发板eMMC  :16GBLPDDR3:4GB显示屏 :15.6英寸HDMI接口显示屏u-boot  :2017.09---------------------------------------......
  • 迅为RK3588核心板无人机控制解决方案
     迅为RK3588核心板无人机控制解决方案 迅为RK3588核心板是采用高性能处理器,适用于无人机主控系统。以下是基于迅为RK3588核心板的无人机主控方案的介绍: 高性能计算能力:迅为RK3588核心板搭载了强大的CPU和GPU,以及AI加速器, 内置NPU,支持INT4/INT8/INT16/FP16混合运算,运算......
  • 欧姆龙 PLC CP1E 与电子称重仪表“柯力XK3101”Modbus RTU通信,稍微更改下Modbus通信地
    欧姆龙PLCCP1E与电子称重仪表“柯力XK3101”ModbusRTU通信,稍微更改下Modbus通信地址可以跟其他Modbus设备进行通信!YID:5545635998335748......
  • Camera | 9.如何让camera支持闪光灯?-基于rk3568
    一、闪光灯基本原理工作模式Cameraflashled分flash和torch两种模式。flash:拍照时上光灯瞬间亮一下,电流比较大,目前是1000mA,最大电流不能超过led最大承受能力torch:只用于录video或者拿led当手电筒的情况,电流不能太大,flash开启需要先从torch过渡,这样电流可以慢慢增大,减......
  • k3s 证书过期修改
    >作者:[SRE运维博客](https://www.cnsre.cn/)>博客地址:[https://www.cnsre.cn/](https://www.cnsre.cn/)>文章地址:[https://www.cnsre.cn/posts/221207116004/](https://www.cnsre.cn/posts/221207116004/)>相关话题:[https://www.cnsre.cn/tags/k3s/](https://www.cnsre.......
  • 不同应用场景瑞芯微RK3568主板方案定制
    随着物联网和智能设备的迅猛发展,瑞芯微RK3568主板方案作为一种高性能的系统System-on-a-chip(SoC),已经成为嵌入式系统、智能家居设备和工业自动化设备等应用场景的首选方案。定制瑞芯微RK3568主板方案可以满足不同应用场景的需求,同时也为企业提供了更多的商业机会。▎行业应用万象......
  • 瑞芯微RK3568开发板在智慧交通行业中的应用方案
    智能交通安全监测系统是通过利用高性能处理器和先进的图像处理算法,实现对交通场景的实时监测、分析和预警,以提高交通安全水平。以下是基于RK3568处理器的智能交通安全监测系统产品的应用方案:视频采集与处理:     使用RK3568处理器搭配高清摄像头,进行交通场景的视频采集。R......
  • network3D 交互式网络图和桑基图
    networkD3是基于D3JS的R包交互式绘图工具,用于转换R语言生成的图为交互式网页嵌套图。目前支持网络图,桑基图,树枝图等。关于网络图的绘制,我们之前有5篇文章,可点击查看。Cytoscape教程1Cytoscape之操作界面介绍新出炉的Cytoscape视频教程Cytoscape:MCODE增强包的网络模块化分析一文学......
  • Rockchip RK3399 - uboot移植
    ----------------------------------------------------------------------------------------------------------------------------开发板 :NanoPC-T4开发板eMMC  :16GBLPDDR3:4GB显示屏 :15.6英寸HDMI接口显示屏u-boot  :2014.10---------------------------------------......
  • 国产工业级RK3568核心板-AI人脸识别产品方案
     迅为RK3568开发板采用瑞芯微推出的一款高性能、低功耗的RK3568处理器,其拥有强大的AI计算能力和图像处理能力,非常适合用于人脸识别终端产品的设计。针对人脸识别终端产品,可以采用RK3568处理器搭配摄像头模组、LCD显示屏、声音模组等组成系统。具体方案如下:      摄......