USE [TWO] GO /****** Object: StoredProcedure [dbo].[spcpAvataxPostSave] Script Date: 09/20/2012 07:12:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER procedure [dbo].[spcpAvataxPostSave] @Sales_Doc_Type AS VARCHAR(25), @Sales_Doc_Num AS VARCHAR(50) AS DECLARE @SOPTYPE SMALLINT, @Ship_To_Address_Code VARCHAR(15), @Shipping_Method VARCHAR(15), @Address_Line_1 VARCHAR(61), @Address_Line_2 VARCHAR(61), @Address_Line_3 VARCHAR(61), @City VARCHAR(35), @State VARCHAR(29), @Zip VARCHAR(11), @Country VARCHAR(61), @Phone_1 VARCHAR(21), @Phone_2 VARCHAR(21), @Phone_3 VARCHAR(21), @Fax VARCHAR(21), @Contact_Person VARCHAR(61), @Discount_Amount NUMERIC(19, 5), @Discount_Date DATETIME, @Sales_Person_ID VARCHAR(50), @Payment_Terms VARCHAR(50), @Invodate DATETIME SELECT @SOPTYPE = SOPTYPE FROM spvSalesDocType WHERE Sales_Doc_Type = @Sales_Doc_Type SELECT @Ship_To_Address_Code = Ship_To_Address_Code, @Shipping_Method = Shipping_Method, @Address_Line_1 = Address_Line_1, @Address_Line_2 = Address_Line_2, @Address_Line_3 = Address_Line_3, @City = City, @State = STATE, @Zip = Zip, @Country = Country, @Phone_1 = Phone_1, @Phone_2 = Phone_2, @Phone_3 = Phone_3, @Fax = Fax, @Contact_Person = Contact_Person, @Discount_Amount = Discount, @Sales_Person_Id = Sales_Person_Id, @Payment_Terms = Payment_Terms, @Invodate = Actual_Ship_Date FROM dbo.spv3SalesDocument AS sd(NOLOCK) WHERE sd.Sales_Doc_Num = @Sales_Doc_Num AND sd.Sales_Doc_Type = @Sales_Doc_Type SELECT @Discount_Date = DISCDATE FROM sop10100 AS sd(NOLOCK) WHERE sd.SOPTYPE = @SOPTYPE AND sd.SOPNUMBE = @Sales_Doc_Num IF EXISTS ( SELECT * FROM SOP10100 AS sd JOIN spvSalesDocType AS sdt ON sd.SOPTYPE = sdt.SOPTYPE WHERE ( sd.TAXSCHID = 'AVATAX' OR sd.TAXSCHID = 'SABRIX' OR sd.TAXSCHID LIKE 'CCH%' OR sd.TAXSCHID LIKE 'STO%' OR sd.TAXSCHID LIKE 'VERTEX%' OR sd.TAXSCHID = 'WEBTAXES' ) AND sd.SOPNUMBE = @Sales_Doc_Num AND sdt.Sales_Doc_Type = @Sales_Doc_Type ) BEGIN --HACK TO UPDATE TAX TOTAL TO SKIRT ECONNECT UPDATE sd SET sd.ORDOCAMT = ISNULL(( sd.ORSUBTOT + ( SELECT sum(OTTAXPON) FROM sop10105 AS t WHERE t.SOPNUMBE = @Sales_Doc_Num ) ), 0), sd.ORTAXAMT = ISNULL(( SELECT sum(OTTAXPON) FROM sop10105 AS t WHERE t.SOPNUMBE = @Sales_Doc_Num ), 0), sd.DOCAMNT = ISNULL(( sd.SUBTOTAL + ( SELECT sum(TXDTOTTX) FROM sop10105 AS t WHERE t.SOPNUMBE = @Sales_Doc_Num ) ), 0), sd.TAXAMNT = ISNULL(( SELECT sum(TXDTOTTX) FROM sop10105 AS t WHERE t.SOPNUMBE = @Sales_Doc_Num ), 0) FROM SOP10100 AS sd JOIN spvSalesDocType AS sdt ON sd.SOPTYPE = sdt.SOPTYPE WHERE sd.SOPNUMBE = @Sales_Doc_Num AND sdt.Sales_Doc_Type = @Sales_Doc_Type END