89 lines
3.5 KiB
Transact-SQL
89 lines
3.5 KiB
Transact-SQL
|
|
/****** Object: StoredProcedure [dbo].[hw_get_zpjjmxb] Script Date: 2025/9/26 15:54:09 ******/
|
|
SET ANSI_NULLS ON
|
|
GO
|
|
SET QUOTED_IDENTIFIER ON
|
|
GO
|
|
ALTER PROCEDURE [dbo].[hw_get_zpjjmxb]
|
|
@fdate1 NVARCHAR(20)
|
|
AS
|
|
BEGIN
|
|
|
|
DECLARE @fdate NVARCHAR(20)
|
|
SET @fdate=''''+ @fdate1 + ''''
|
|
|
|
DELETE hw_zpjjmxb where jjdate=@fdate1
|
|
|
|
|
|
--1、取计件人数=总人数-新员工人数+提前转计件的新员工人数
|
|
declare @bzrs nvarchar(max)
|
|
set @bzrs='(select p1.FID,p1.rs-isnull(p2.syqrs,0) as rs from (select t1.FID, count(*) as rs
|
|
from GAT_DAY_ZP t1 join GAT_DAY_jt_ZP jt on t1.fid=jt.fid
|
|
where F_DATE='+@fdate+' group by t1.FID) p1 left outer join
|
|
( select t1.FID, count(*) as syqrs from GAT_DAY_ZP t1 join GAT_DAY_jt_ZP t2 on t1.fid=t2.fid
|
|
join GAT_YGCQs t3 on t2.f_ygno=t3.f_ygnm join GAT_YGCQ t4 on t3.fid=t4.fid and t4.f_date='+@fdate+'
|
|
left outer join hw_xygzjj t5 on t3.F_YGNM=t5.F_YGID and t4.F_DATE>=t5.F_DATE
|
|
where t5.F_YGID is null and t3.f_issyq=''是'' and t1.F_DATE='+@fdate+' group by t1.FID) p2 on p1.fid=p2.FID)'
|
|
|
|
--select @bzrs
|
|
--集体计件(jjDate, ygNo, ygNm, zlNo, cpNm, price, fqty, jtrs, je, bz, zje,jjcsbt,gwbt,jjdh)
|
|
declare @sql nvarchar(max)
|
|
set @sql='insert into hw_zpjjmxb
|
|
select t1.F_DATE,
|
|
yg.FNUMBER,
|
|
ygs.FNAME,
|
|
scdd.FNUMBER,
|
|
scdd.FCPNM,
|
|
t2.F_PRICE,
|
|
case when isnull(rs1.rs,0)=0 then 0 else t2.F_FQTY end,
|
|
rs1.rs,
|
|
case when isnull(rs1.rs,0)=0 then 0 else t2.F_FQTY/rs1.rs end * t2.F_PRICE,
|
|
0,
|
|
case when isnull(rs1.rs,0)=0 then 0 else t2.F_FQTY/rs1.rs end * t2.F_PRICE,0,0,t1.fbillno
|
|
|
|
from GAT_DAY_ZP t1 join GAT_DAY_CP_ZP t2 on t1.FID=t2.FID
|
|
join hw_scdd_select scdd on t2.F_SCNO=scdd.FID
|
|
join GAT_DAY_JT_ZP t3 on t1.FID=t3.FID
|
|
join T_HR_EMPINFO yg on t3.F_YGNO=yg.FID
|
|
join T_HR_EMPINFO_L ygs on yg.FID=ygs.FID
|
|
join '+@bzrs+' rs1 on t1.fid=rs1.fid
|
|
where t1.F_DATE='+@fdate
|
|
|
|
|
|
--select @sql
|
|
exec(@sql)
|
|
|
|
|
|
--个人计件
|
|
insert into hw_zpjjmxb select t1.F_DATE as 计件日期,yg.FNUMBER as 员工代号,ygs.FNAME as 员工姓名, scdd.FNUMBER as 制令单号, scdd.FCPNM as 货品名称,t2.F_PRICE,t2.F_FQTY
|
|
,null as 集体人数,t2.F_JJGZ as 金额,null as 补助,t2.F_JJGZ as 总金额,0,0,t1.fbillno
|
|
from GAT_DAY_ZP t1 join GAT_DAY_GR_ZP t2 on t1.FID=t2.FID
|
|
|
|
join hw_scdd_select scdd on t2.F_SCNO=scdd.FID
|
|
|
|
join T_HR_EMPINFO yg on t2.F_YGNO=yg.FID
|
|
join T_HR_EMPINFO_L ygs on yg.FID=ygs.FID
|
|
where t1.F_DATE=@fdate1
|
|
-----------------------------------------------
|
|
update t1 set bz=t3.F_SYQBT,jjcsbt=t3.F_CSBT,gwbt=t3.F_GWBT from hw_zpjjmxb t1 join GAT_rgz t2 on t1.jjDate=t2.FDATE join GAT_rgzs t3 on t2.fid=t3.fid
|
|
|
|
join T_HR_EMPINFO yg on t3.F_YGNO=yg.FID
|
|
and t1.ygno=yg.FNUMBER where t1.jjDate=@fdate1
|
|
|
|
--反掉重复数据
|
|
update hw_zpjjmxb set bz=0 where bz>0 and jjDate=@fdate1 and FInterID not in (select min(FInterID) from hw_zpjjmxb where jjDate=@fdate1 group by ygno,bz)
|
|
update hw_zpjjmxb set jjcsbt=0 where jjcsbt>0 and jjDate=@fdate1 and FInterID not in (select min(FInterID) from hw_zpjjmxb where jjDate=@fdate1 group by ygno,jjcsbt)
|
|
update hw_zpjjmxb set gwbt=0 where gwbt>0 and jjDate=@fdate1 and FInterID not in (select min(FInterID) from hw_zpjjmxb where jjDate=@fdate1 group by ygno,gwbt)
|
|
|
|
|
|
--重新计算个人金额和总金额
|
|
update hw_zpjjmxb set je=round(price*fqty/case when isnull(jtrs,0)=0 then 1 else jtrs end,2) ,
|
|
zje=round( price*fqty/case when isnull(jtrs,0)=0 then 1 else jtrs end,2)+bz+jjcsbt+gwbt where jjdate=@fdate1
|
|
|
|
--
|
|
DELETE t1 from hw_zpjjmxb t1 join T_HR_EMPINFO yg on t1.ygno=yg.FNUMBER
|
|
|
|
join GAT_YGCQs cqs on yg.FID=cqs.F_YGNM join GAT_YGCQ cq on cqs.fid=cq.fid
|
|
where jjDate=@fdate1 and cq.F_DATE=@fdate1 and cqs.F_ISSYQ='是' and cqs.F_YGNM not in (select f_ygID from hw_xygzjj where f_date<=@fdate1)
|
|
|
|
END |