sp_sys_ERPTrigger_base

USE [GalaxyPointDB24]
GO
/****** Object:  StoredProcedure [dbo].[sp_sys_ERPTrigger_base]    Script Date: 05/05/2015 15:40:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


--功能:BPM数据同步功能测试
--exec sp_sys_ERPTrigger_base 141

ALTER procedure [dbo].[sp_sys_ERPTrigger_base]
@TaskId int                --子流程TaskId
AS
BEGIN
   BEGIN TRY
      BEGIN TRANSACTION
     
      SET NOCOUNT ON;
 
     DECLARE @TC002 nvarchar(50)      --Purchase order Number
     DECLARE @Total_amount decimal(15, 2)    --Total_amount
    
     DECLARE @TC018 int                      --税种
     DECLARE @TC019 decimal(15, 2)           --金额
     DECLARE @TC020 decimal(15, 2)           --税额
    
        SELECT  @TC002 = [TC002] from  ERP_PURTC WHERE [TaskId] = @TaskId
       
        DECLARE @TC001  nvarchar(50)      --单据 Number
        DECLARE @MQ002  nvarchar(50)      --@单据名称

        DECLARE @TC004 nvarchar(50)             --供应商编号
        DECLARE @MA002 nvarchar(50)             --供应商简称
        DECLARE @MA003 nvarchar(100)            --供应商全称
       
        DECLARE @MA008 nvarchar(50)             --供应商 TEL(一)
        DECLARE @MA010 nvarchar(50)             --供应商 FAXNO
        DECLARE @MA013 nvarchar(50)             --供应商 联系人(一)
        DECLARE @MA014 nvarchar(100)            --供应商 联系地址(一)
        DECLARE @MA024 nvarchar(50)             --供应商 结算方式编号
       
        DECLARE @NJ002 nvarchar(100)            --结算方式名称
        DECLARE @tax_type nvarchar(50)          --税种
       
        -- Main bpm
        SELECT @TC001 = [TC001], @TC004 = [TC004], @TC018 = [TC018],
                        @TC019 = [TC019], @TC020 = [TC020]
          from [GalaxyPointDB24].[dbo].[ERP_PURTC] WHERE [TaskId] = @TaskId
 
        -- CMSMQ
        SELECT @MQ002 = [MQ002]
        from [DEMO].[dbo].[CMSMQ] WHERE [MQ001] = @TC001

        -- PURMA
        SELECT @MA002 = [MA002], @MA003 = [MA003],
               @MA008 = [MA008], @MA010 = [MA010],
               @MA013 = [MA013], @MA014 = [MA014],
               @MA024 = [MA024]
        from [DEMO].[dbo].[PURMA] WHERE [MA001] = @TC004
       
        -- CMSNJ
        SELECT @NJ002 = [NJ002]
        from [DEMO].[dbo].[CMSNJ] WHERE [NJ001] = @MA024

        -- Total_amount
        if (@TC018 = 1)
        begin
            --set @Total_amount = (CONVERT (decimal(15,2),@TC019) + CONVERT (decimal(15,2),@TC020))
            set @Total_amount = @TC019 + @TC020
        end
       
        if (@TC018 = 2)
        begin
            --set @Total_amount = (CONVERT (decimal(15,2),@TC019))
            set @Total_amount = @TC019
        end
       
        -- tax_typ
        SET @tax_type =
        (SELECT CASE @TC018
              WHEN '1' THEN  '1.因税内含'
              WHEN '2' THEN  '2.因税外加'
              WHEN '3' THEN  '3.零税率'
              WHEN '4' THEN  '4.免税'
              WHEN '9' THEN  '9.不计税'            
         ELSE '其他' END)


        -- UPDATE
  UPDATE [GalaxyPointDB24].[dbo].[ERP_PURTC]
  SET [MQ002] = @MQ002,
      [MA002] = @MA002, [MA003] = @MA003,
      [MA008] = @MA008, [MA010] = @MA010,
      [MA013] = @MA013, [MA014] = @MA014,
      [NJ002] = @NJ002, [tax_type] =@tax_type,
      [Total_amount] = @Total_amount
  WHERE [TC002] = @TC002
  
  
  COMMIT TRANSACTION
   END TRY
  
   BEGIN CATCH
        --错误处理
       ROLLBACK
       TRANSACTION
       SELECT ERROR_MESSAGE() --turn warning
   END CATCH
 
END

你可能感兴趣的:(trigger)