【脚本】查看员工绩效发生“遇到0不能除”的问题处理
2018-08-27    
1413 0
由于历史版本的bug导致的部分数据,再查询统计或记录时,直接报错“遇到0不能除”,如果产生此问题,可通过此脚本来完成处理。
  • 执行脚本

    USE EMSXDB
    GO

    IF  EXISTS (SELECT 1 FROM dbo.sysobjects where xtype='FN' AND name ='FUN_GetJobBillDetailInnerCost')
    DROP function FUN_GetJobBillDetailInnerCost
    GO


    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:        <zhangyu>
    -- Create date: <2017-11-13>
    -- Description:    <获取工单明细的内协成本>
    -- =============================================
    CREATE FUNCTION [dbo].[FUN_GetJobBillDetailInnerCost]
    (
        @JobBillCode      nvarchar(100),    --工单编号
        @JobBillDetailId  uniqueidentifier,    --工单明细Id
        @UserExecId          uniqueidentifier  --绩效明细Id
    )
    RETURNS decimal(18,3)
    AS
    BEGIN
        DECLARE @DetailInnerCost decimal(18,4)
        SET @DetailInnerCost=0.0000
        
        --私有变量
        Declare @InnerTotalAmount                decimal(18,2),--工单关联的所有内协成本
                @TotalDetailReceiveAmount    decimal(18,3),--工单明细实收金额总计
                @CurDetailReceiveAmount        decimal(18,3),--当前工单明细的实收金额
                @UserExecNumber                decimal(18, 3),--绩效比例
                @CurDetailNumber            decimal(18,3)--当前工单明细的数量
        
        IF(ISNULL(@JobBillCode,'')<>'' AND @JobBillDetailId IS NOT NULL)
        BEGIN
            --当前工单是否包含内协单才有必要计算
            IF EXISTS(select 1 from PPM_InnerSourcingBill Where SourceJobBill_Code=@JobBillCode and Amount<>0)
            Begin
                --当前工单明细存在有内协标记的
                IF EXISTS(select 1 from PPM_JobBillDetail where ParentBillCode=@JobBillCode and IsInnerSourcing='1')
                Begin
                    --当前明细必须有内协标记
                    IF EXISTS(select 1 from PPM_JobBillDetail where ParentBillCode=@JobBillCode and IsInnerSourcing='1' and Id=@JobBillDetailId)
                    Begin                    
                        --获取工单关联的所有内协成本
                        select @InnerTotalAmount=SUM(Amount) FROM PPM_InnerSourcingBill Where SourceJobBill_Code=@JobBillCode
                        
                        --获取标记内协且选择了绩效的所有实收金额
                        select @TotalDetailReceiveAmount=(SUM(ReceivePrice*Number)) FROM PPM_JobBillDetail where ParentBillCode=@JobBillCode and IsInnerSourcing='1' and Id In(select JobBillDetailId from PPM_JobBillDetailUserExec where ParentBillCode=@JobBillCode)
                        
                        --获取当前明细的实收金额和数量
                        select @CurDetailReceiveAmount=ReceivePrice*Number,@CurDetailNumber=Number FROM PPM_JobBillDetail where ParentBillCode=@JobBillCode and IsInnerSourcing='1' and Id=@JobBillDetailId
                        
                        --获取绩效比例
                        select @UserExecNumber=Number from PPM_JobBillDetailUserExec where JobBillCode=@JobBillCode and JobBillDetailId=@JobBillDetailId and Id=@UserExecId
                        
                        
                        --计算((当前明细(实收单价*数量)/工单实收)*所有内协单金额汇总))*绩效百分比
                        Set @DetailInnerCost=((@CurDetailReceiveAmount/@TotalDetailReceiveAmount)*@InnerTotalAmount)*(@UserExecNumber/@CurDetailNumber)
                    End
                End
                else
                Begin--当前工单明细不存在有内协标记的
                    --获取工单关联的所有内协成本
                    select @InnerTotalAmount=SUM(Amount) FROM PPM_InnerSourcingBill Where SourceJobBill_Code=@JobBillCode
                    
                    --获取选择了绩效的所有实收金额
                    select @TotalDetailReceiveAmount=(SUM(ReceivePrice*Number)) FROM PPM_JobBillDetail where ParentBillCode=@JobBillCode and Id In(select JobBillDetailId from PPM_JobBillDetailUserExec where ParentBillCode=@JobBillCode)
                    
                    --获取当前明细的实收金额和数量
                    select @CurDetailReceiveAmount=ReceivePrice*Number,@CurDetailNumber=Number FROM PPM_JobBillDetail where ParentBillCode=@JobBillCode and Id=@JobBillDetailId
                    
                    --获取绩效比例
                    select @UserExecNumber=Number from PPM_JobBillDetailUserExec where JobBillCode=@JobBillCode and JobBillDetailId=@JobBillDetailId and Id=@UserExecId
                    
                    
                    --计算
                    if(@TotalDetailReceiveAmount=0)
                    begin
                        set @DetailInnerCost=0
                    end
                    else
                    begin
                        Set @DetailInnerCost=((@CurDetailReceiveAmount/@TotalDetailReceiveAmount)*@InnerTotalAmount)*(@UserExecNumber/@CurDetailNumber)
                    end
                End
            End
        END
        RETURN @DetailInnerCost
    END

章节

该文章对您有用吗?

非常感谢,您的反馈对我们很有价值!

客服电话

4006757966

微信公众号

联系我们

印特3系演示版

申请

印特5系演示版

申请

免费试用

印特软件标准演示版下载申请

请您填写您的一些信息,提交您的申请后,我们会在两个工作日内进行处理,并回复您一封邮件,内附下载链接,请您注意查收。
*
请输入正确的公司名称
*
请输入正确的联络人员
*
请输入正确的联络电话
提交申请
关闭