ALTER PROCEDURE dbo.taSopHdrRecalc @I_vSOPTYPE SMALLINT ,@I_vSOPNUMBE CHAR(21) ,@I_vTAXSCHID CHAR(15) = NULL ,@I_vFRTSCHID CHAR(15) = NULL ,@I_vMSCSCHID CHAR(15) = NULL ,@I_vSHIPMTHD CHAR(15) = NULL ,@I_vLOCNCODE CHAR(10) = NULL ,@I_vDOCDATE DATETIME = NULL ,@I_vFREIGHT NUMERIC(19, 5) = NULL ,@I_vMISCAMNT NUMERIC(19, 5) = NULL ,@I_vTRDISAMT NUMERIC(19, 5) = NULL ,@I_vTRADEPCT NUMERIC(19, 2) = NULL ,@I_vDISTKNAM NUMERIC(19, 5) = NULL ,@I_vCUSTNAME CHAR(64) = NULL ,@I_vCSTPONBR CHAR(20) = NULL ,@I_vShipToName CHAR(64) = NULL ,@I_vADDRESS1 CHAR(60) = NULL ,@I_vADDRESS2 CHAR(60) = NULL ,@I_vADDRESS3 CHAR(60) = NULL ,@I_vCNTCPRSN CHAR(60) = NULL ,@I_vFAXNUMBR CHAR(21) = NULL ,@I_vCITY CHAR(35) = NULL ,@I_vSTATE CHAR(29) = NULL ,@I_vZIPCODE CHAR(10) = NULL ,@I_vCOUNTRY CHAR(60) = NULL ,@I_vPHNUMBR1 CHAR(21) = NULL ,@I_vPHNUMBR2 CHAR(21) = NULL ,@I_vPHNUMBR3 CHAR(21) = NULL ,@I_vPrint_Phone_NumberGB SMALLINT = NULL ,@I_vPYMTRCVD NUMERIC(19, 5) = NULL ,@I_vSALSTERR CHAR(15) = NULL ,@I_vSLPRSNID CHAR(15) = NULL ,@I_vUPSZONE CHAR(3) = NULL ,@I_vBACHNUMB CHAR(15) = NULL ,@I_vPRBTADCD CHAR(15) = NULL ,@I_vPRSTADCD CHAR(15) = NULL ,@I_vORDRDATE DATETIME = NULL ,@I_vPYMTRMID CHAR(20) = NULL ,@I_vDUEDATE DATETIME = '' ,@I_vDISCDATE DATETIME = '' ,@I_vREFRENCE CHAR(30) = NULL ,@I_vBatchCHEKBKID CHAR(15) = NULL ,@I_vRECREATECOMM SMALLINT = NULL ,@I_vCOMPRCNT NUMERIC(19, 2) = NULL ,@I_vRECREATEDIST SMALLINT = NULL ,@I_vRECREATETAXES SMALLINT = NULL ,@I_vDEFTAXSCHDS SMALLINT = NULL ,@I_vXCHGRATE NUMERIC(19, 7) = NULL ,@I_vRATETPID CHAR(15) = NULL ,@I_vEXPNDATE DATETIME = NULL ,@I_vEXCHDATE DATETIME = NULL ,@I_vEXGTBDSC CHAR(30) = NULL ,@I_vEXTBLSRC CHAR(50) = NULL ,@I_vRATEEXPR SMALLINT = NULL ,@I_vDYSTINCR SMALLINT = NULL ,@I_vRATEVARC NUMERIC(19, 7) = NULL ,@I_vTRXDTDEF SMALLINT = NULL ,@I_vRTCLCMTD SMALLINT = NULL ,@I_vPRVDSLMT SMALLINT = NULL ,@I_vDATELMTS SMALLINT = NULL ,@I_vTIME1 DATETIME = NULL ,@I_vDISAVAMT NUMERIC(19, 5) = NULL ,@I_vDSCDLRAM NUMERIC(19, 5) = NULL ,@I_vDSCPCTAM NUMERIC(19, 2) = NULL ,@I_vFREIGTBLE INT = NULL ,@I_vMISCTBLE INT = NULL ,@I_vCOMMNTID CHAR(15) = NULL ,@I_vCOMMENT_1 CHAR(50) = NULL ,@I_vCOMMENT_2 CHAR(50) = NULL ,@I_vCOMMENT_3 CHAR(50) = NULL ,@I_vCOMMENT_4 CHAR(50) = NULL ,@I_vGPSFOINTEGRATIONID CHAR(30) = NULL ,@I_vINTEGRATIONSOURCE SMALLINT = NULL ,@I_vINTEGRATIONID CHAR(30) = NULL ,@I_vReqShipDate DATETIME = NULL ,@I_vRequesterTrx SMALLINT = NULL ,@I_vQUOEXPDA DATETIME = NULL ,@I_vQUOTEDAT DATETIME = NULL ,@I_vINVODATE DATETIME = NULL ,@I_vBACKDATE DATETIME = NULL ,@I_vRETUDATE DATETIME = NULL ,@I_vCMMTTEXT VARCHAR(500) = NULL ,@I_vRECALCBTCHTOT INT = 1 ,@I_vCHGAMNT NUMERIC(19, 5) = 0 ,@I_vCKCreditLimit TINYINT = 0 ,@I_vCKHOLD TINYINT = 0 ,@I_vPRCLEVEL CHAR(10) = NULL ,@I_vTAXEXMT1 CHAR(25) = NULL ,@I_vTAXEXMT2 CHAR(25) = NULL ,@I_vTXRGNNUM CHAR(25) = NULL ,@I_vREPTING TINYINT = NULL ,@I_vTRXFREQU SMALLINT = NULL ,@I_vTIMETREP SMALLINT = NULL ,@I_vQUOTEDYSTINCR SMALLINT = NULL ,@I_vNOTETEXT VARCHAR(8000) = NULL ,@I_vUSRDEFND1 CHAR(50) = NULL ,@I_vUSRDEFND2 CHAR(50) = NULL ,@I_vUSRDEFND3 CHAR(50) = NULL ,@I_vUSRDEFND4 VARCHAR(8000) = NULL ,@I_vUSRDEFND5 VARCHAR(8000) = NULL ,@O_iErrorState INT OUTPUT ,@oErrString VARCHAR(255) OUTPUT WITH ENCRYPTION AS SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED SET NOCOUNT ON DECLARE @FRTSCHID CHAR(15) ,@MSCSCHID CHAR(15) ,@OREXTCST NUMERIC(19, 5) ,@ORNCMAMT NUMERIC(19, 5) ,@ORCOSAMT NUMERIC(19, 5) ,@ORREMSUBTO NUMERIC(19, 5) ,@ORACTAMT NUMERIC(19, 5) ,@ORPMTRVD NUMERIC(19, 5) ,@ORTAXAMT NUMERIC(19, 5) ,@OTAXTAMT NUMERIC(19, 5) ,@TXBTXAMT NUMERIC(19, 5) ,@OBTAXAMT NUMERIC(19, 5) ,@ORBKTMSC NUMERIC(19, 5) ,@ORBKTFRT NUMERIC(19, 5) ,@ORMISCAMT NUMERIC(19, 5) ,@ORFRTAMT NUMERIC(19, 5) ,@ORSUBTOT NUMERIC(19, 5) ,@ORTDISAM NUMERIC(19, 5) ,@OCOMMAMT NUMERIC(19, 5) ,@ORMRKDAM NUMERIC(19, 5) ,@ORDATKN NUMERIC(19, 5) ,@ORDDLRAT NUMERIC(19, 5) ,@ORDISTKN NUMERIC(19, 5) ,@ORDAVAMT NUMERIC(19, 5) ,@ORDISRTD NUMERIC(19, 5) ,@ORDAVMSC NUMERIC(19, 5) ,@ORDAVFRT NUMERIC(19, 5) ,@INTERID CHAR(5) ,@CMPANYID SMALLINT ,@FUNLCURR CHAR(15) ,@ISMCTRX INT ,@DTAREF CHAR(25) ,@DECPLCUR INT ,@LOCNCODE CHAR(10) ,@TAXSCHID CHAR(15) ,@STAXSCHD CHAR(15) ,@SHIPTYPE INT ,@USEADVTX INT ,@MS_ITEM_1 INT ,@FUTOTAMT NUMERIC(19, 5) ,@RECALC INT ,@VATEnabled INT ,@ACCTAMNT NUMERIC(19, 5) ,@dtDEFAULT DATETIME ,@iStatus INT ,@CurrTime DATETIME ,@iError INT ,@O_oErrorState INT ,@iUpdtBthErrState INT ,@iUpdDistErrState INT ,@iCustomState INT ,@iCustomErrString VARCHAR(255) ,@iAddShippingErrState INT ,@iAddShippingErrString VARCHAR(255) ,@iCalcDueDateErrState INT ,@iCalcDueDateErrString VARCHAR(255) ,@iCreateBatchErrString VARCHAR(255) ,@taSopTaxEngineErrState INT ,@taSopTaxEngineErrString VARCHAR(255) ,@taMCCurrencyValidateErrState INT ,@taMCCurrencyValidateErrString VARCHAR(255) ,@taCreateSOPDistributionsErrState INT ,@taCreateSOPDistributionsErrString VARCHAR(255) ,@FRTTXAMT NUMERIC(19, 5) ,@ORFRTTAX NUMERIC(19, 5) ,@MSCTXAMT NUMERIC(19, 5) ,@ORMSCTAX NUMERIC(19, 5) ,@UNPSTOCA NUMERIC(19, 5) ,@UNPSTOSA NUMERIC(19, 5) ,@EXTDCOST NUMERIC(19, 5) ,@dDISCDATE DATETIME ,@dDUEDATE DATETIME ,@DAYTOEXP SMALLINT ,@FRGTTXBL SMALLINT ,@MISCTXBL SMALLINT ,@COMMAMNT NUMERIC(19, 5) ,@COMAPPTO SMALLINT ,@CMMSLAMT NUMERIC(19, 5) ,@MRKDNAMT NUMERIC(19, 5) ,@NCOMAMNT NUMERIC(19, 5) ,@SLPR CHAR(15) ,@O_iCommErrorState INT ,@sCommErrString CHAR(255) ,@PostingType SMALLINT ,@DBName CHAR(50) ,@O_iInitErrorState INT ,@oInitErrString VARCHAR(255) ,@TRADEPCT NUMERIC(19, 5) ,@DISCMISC NUMERIC(19, 5) ,@O_iCommentMstErrState INT ,@DECPLUSED INT ,@ExstDOCAMNTNeg NUMERIC(19, 5) ,@BatchCHEKBKID CHAR(15) ,@NewDOCAMNT NUMERIC(19, 5) ,@SOPHdrTbl CHAR(18) ,@oExists INT ,@OInsStatus INT ,@DexLockErrorState INT ,@OldTAXAMNT NUMERIC(19, 5) ,@OldORTAXMNT NUMERIC(19, 5) ,@mylock TINYINT ,@DOCID CHAR(15) ,@iCustomerBalanceErrState INT ,@taCustomerBalanceErrString VARCHAR(255) ,@OverCreditLimit TINYINT ,@CRLMTTYP SMALLINT ,@CurrBalance NUMERIC(19, 5) ,@CRLMTAMT NUMERIC(19, 5) ,@CUSTBLNC NUMERIC(19, 5) ,@UNPSTDSA NUMERIC(19, 5) ,@UNPSTOSA1 NUMERIC(19, 5) ,@ONORDAMT NUMERIC(19, 5) ,@UNPSTDCA NUMERIC(19, 5) ,@UNPSTOCA1 NUMERIC(19, 5) ,@DEPRECV NUMERIC(19, 5) ,@HOLD TINYINT ,@INACTIVE INT ,@CrdChkAmnt NUMERIC(19, 5) ,@FUFILDAT DATETIME ,@ACTLSHIP DATETIME ,@DexRowID INT ,@BACHNUMBSUM NUMERIC(19, 5) ,@DEPOSITS NUMERIC(19, 5) ,@ORDEPOSITS NUMERIC(19, 5) ,@PAYMENTS NUMERIC(19, 5) ,@ORPAYMENTS NUMERIC(19, 5) ,@BackoutTradeDisc NUMERIC(19, 5) ,@OrigBackoutTradeDisc NUMERIC(19, 5) ,@HdrPAYMENTS NUMERIC(19, 5) ,@OrHdrPAYMENTS NUMERIC(19, 5) ,@TRDISAMT NUMERIC(19, 5) ,@TRDISAMTDIF NUMERIC(19, 5) ,@ExstDOCDATE DATETIME ,@ExstQUOTEDAT DATETIME ,@ExstQUOEXPDA DATETIME ,@ExstORDRDATE DATETIME ,@ExstINVODATE DATETIME ,@ExstBACKDATE DATETIME ,@ExstRETUDATE DATETIME ,@ExstReqShipDate DATETIME ,@ExstDISCDATE DATETIME ,@ExstDUEDATE DATETIME ,@ExstDISCFRGT NUMERIC(19, 5) ,@ExstDISCMISC NUMERIC(19, 5) ,@ExstDISCRTND NUMERIC(19, 5) ,@ExstORDISRTD NUMERIC(19, 5) ,@ExstDISTKNAM NUMERIC(19, 5) ,@ExstORDISTKN NUMERIC(19, 5) ,@ExstPRCLEVEL CHAR(10) ,@ExstLOCNCODE CHAR(10) ,@ExstBACHNUMB CHAR(15) ,@ExstCUSTNMBR CHAR(15) ,@ExstCUSTNAME CHAR(64) ,@ExstCSTPONBR CHAR(20) ,@ExstORMRKDAM NUMERIC(19, 5) ,@ExstPRBTADCD CHAR(15) ,@ExstPRSTADCD CHAR(15) ,@ExstCNTCPRSN CHAR(60) ,@ExstShipToName CHAR(64) ,@ExstADDRESS1 CHAR(60) ,@ExstADDRESS2 CHAR(60) ,@ExstADDRESS3 CHAR(60) ,@ExstCITY CHAR(30) ,@ExstSTATE CHAR(29) ,@ExstZIPCODE CHAR(10) ,@ExstCOUNTRY CHAR(60) ,@ExstPHNUMBR1 CHAR(21) ,@ExstPHNUMBR2 CHAR(21) ,@ExstPHONE3 CHAR(21) ,@ExstFAXNUMBR CHAR(21) ,@ExstSHIPMTHD CHAR(15) ,@ExstSUBTOTAL NUMERIC(19, 5) ,@ExstREMSUBTO NUMERIC(19, 5) ,@ExstEXTDCOST NUMERIC(19, 5) ,@ExstFRTAMNT NUMERIC(19, 5) ,@ExstORFRTAMT NUMERIC(19, 5) ,@ExstMISCAMNT NUMERIC(19, 5) ,@ExstORMISCAMT NUMERIC(19, 5) ,@ExstORSUBTOT NUMERIC(19, 5) ,@ExstOREMSUBT NUMERIC(19, 5) ,@ExstORFRTTAX NUMERIC(19, 5) ,@ExstORMSCTAX NUMERIC(19, 5) ,@ExstTAXSCHID CHAR(15) ,@ExstFRTSCHID CHAR(15) ,@ExstFRTTXAMT NUMERIC(19, 5) ,@ExstFRGTTXBL SMALLINT ,@ExstMSCSCHID CHAR(15) ,@ExstMSCTXAMT NUMERIC(19, 5) ,@ExstMISCTXBL SMALLINT ,@ExstBKTFRTAM NUMERIC(19, 5) ,@ExstORBKTFRT NUMERIC(19, 5) ,@ExstBKTMSCAM NUMERIC(19, 5) ,@ExstORBKTMSC NUMERIC(19, 5) ,@ExstBCKTXAMT NUMERIC(19, 5) ,@ExstOBTAXAMT NUMERIC(19, 5) ,@ExstTAXAMNT NUMERIC(19, 5) ,@ExstORTAXAMT NUMERIC(19, 5) ,@ExstDOCAMNT NUMERIC(19, 5) ,@ExstORDOCAMT NUMERIC(19, 5) ,@ExstPYMTRCVD NUMERIC(19, 5) ,@ExstORPMTRVD NUMERIC(19, 5) ,@ExstDEPRECVD NUMERIC(19, 5) ,@ExstORDEPRVD NUMERIC(19, 5) ,@ExstSALSTERR CHAR(15) ,@ExstSLPRSNID CHAR(15) ,@ExstUPSZONE CHAR(3) ,@ExstCURNCYID CHAR(15) ,@ExstCURRNIDX INT ,@ExstRATETPID CHAR(15) ,@ExstEXCHDATE DATETIME ,@ExstDYSTINCR SMALLINT ,@ExstRATEVARC NUMERIC(19, 7) ,@ExstTRXDTDEF SMALLINT ,@ExstRTCLCMTD SMALLINT ,@ExstEXGTBLID CHAR(15) ,@ExstXCHGRATE NUMERIC(19, 7) ,@ExstTIME1 DATETIME ,@ExstCOMMNTID CHAR(15) ,@ExstREFRENCE CHAR(31) ,@ExstPTDUSRID CHAR(15) ,@ExstMODIFDT DATETIME ,@ExstGPSFOINTEGRATIONID CHAR(30) ,@ExstINTEGRATIONSOURCE SMALLINT ,@ExstINTEGRATIONID CHAR(30) ,@ExstCOMAPPTO SMALLINT ,@ExstREPTING TINYINT ,@ExstTRXFREQU SMALLINT ,@ExstTIMETREP SMALLINT ,@ExstQUOTEDYSTINCR SMALLINT ,@ExstFlags TINYINT ,@NewCUSTNAME CHAR(64) ,@NewCSTPONBR CHAR(20) ,@NewFREIGHT NUMERIC(19, 5) ,@NewMISCAMNT NUMERIC(19, 5) ,@NewDISTKNAM NUMERIC(19, 5) ,@NewPYMTRCVD NUMERIC(19, 5) ,@NewDOCDATE DATETIME ,@NewRATETPID CHAR(15) ,@NewEXPNDATE DATETIME ,@NewEXCHDATE DATETIME ,@NewEXGTBDSC CHAR(30) ,@NewEXTBLSRC CHAR(50) ,@NewRATEEXPR SMALLINT ,@NewDYSTINCR SMALLINT ,@NewRATEVARC NUMERIC(19, 7) ,@NewTRXDTDEF SMALLINT ,@NewRTCLCMTD SMALLINT ,@NewPRVDSLMT SMALLINT ,@NewDATELMTS SMALLINT ,@NewTIME1 DATETIME ,@NewXCHGRATE NUMERIC(19, 7) ,@NewTAXSCHID CHAR(15) ,@NewFRTSCHID CHAR(15) ,@NewMSCSCHID CHAR(15) ,@NewLOCNCODE CHAR(10) ,@NewPRCLEVEL CHAR(10) ,@NewFREIGTBLE INT ,@NewMISCTBLE INT ,@NewPRBTADCD CHAR(15) ,@NewDISCRTND NUMERIC(19, 5) ,@NewREPTING TINYINT ,@NewTRXFREQU SMALLINT ,@NewTIMETREP SMALLINT ,@NewQUOTEDYSTINCR SMALLINT ,@ALLREPEA TINYINT ,@DSCLCTYP SMALLINT ,@DSCDLRAM NUMERIC(19, 5) ,@DSCPCTAM NUMERIC(19, 5) ,@SALPURCH SMALLINT ,@DISCNTCB SMALLINT ,@FREIGHT SMALLINT ,@MISC SMALLINT ,@TAX SMALLINT ,@PymtTermAmnt1 NUMERIC(19, 5) ,@PymtTermAmnt2 NUMERIC(19, 5) ,@PymtTermAmnt3 NUMERIC(19, 5) ,@PymtTermAmnt4 NUMERIC(19, 5) ,@PymtTermAmnt5 NUMERIC(19, 5) ,@PymtTermAmnt8 NUMERIC(19, 5) ,@CURRNIDXFun INT ,@lock CHAR(15) ,@BSIVCTTL TINYINT ,@Flags TINYINT ,@PYMTRMID CHAR(20) ,@stoprecalc TINYINT ,@recalcdeposits TINYINT ,@CRLMTPER SMALLINT ,@CRLMTPAM NUMERIC(19, 5) ,@NOTEINDX NUMERIC(19, 5) ,@sCompanyID SMALLINT ,@iGetNextNoteIdxErrState INT ,@ALLOCABY SMALLINT ,@USDOCID1 CHAR(15) ,@USDOCID2 CHAR(15) ,@QUOTOINV SMALLINT ,@QUOTOORD SMALLINT ,@INVTOBAC SMALLINT ,@BACTOINV SMALLINT ,@BACTOORD SMALLINT ,@ORDTOBAC SMALLINT ,@ORIGTYPE SMALLINT ,@USERDEFEXISTS SMALLINT ,@defUPSZONE CHAR(3) ,@defSALSTERR CHAR(15) ,@defSLPRSNID CHAR(15) ,@defSHIPMTHD CHAR(15) ,@CCode CHAR(7) ,@ADDRESS1 CHAR(60) ,@ADDRESS2 CHAR(60) ,@ADDRESS3 CHAR(60) ,@CNTCPRSN CHAR(60) ,@FAXNUMBR CHAR(21) ,@CITY CHAR(30) ,@STATE CHAR(29) ,@ZIPCODE CHAR(10) ,@COUNTRY CHAR(60) ,@PHNUMBR1 CHAR(21) ,@PHNUMBR2 CHAR(21) ,@PHNUMBR3 CHAR(21) ,@NACREDITCHECK TINYINT ,@CPRCSTNM CHAR(15) ,@CUSTNMBR CHAR(15) ,@WORKFLOWENABLED SMALLINT ,@WorkflowApprStatusQuote SMALLINT ,@WorkflowPriorityQuote SMALLINT ,@WorkflowApprStatCreditLm SMALLINT ,@WorkflowPriorityCreditLm SMALLINT ,@USINGNEGATIVES SMALLINT ,@TAXAMNTL NUMERIC(19, 5) ,@STOP INT ,@ExstPrint_Phone_NumberGB SMALLINT ,@NewPrint_Phone_NumberGB SMALLINT ,@NewShipToName CHAR(64) ,@SITEINACTIVE TINYINT ,@ITEMSITEINACTIVE TINYINT SELECT @FRTSCHID = '' ,@MSCSCHID = '' ,@OREXTCST = 0 ,@ORNCMAMT = 0 ,@ORCOSAMT = 0 ,@ORREMSUBTO = 0 ,@ORACTAMT = 0 ,@ORPMTRVD = 0 ,@ORTAXAMT = 0 ,@OTAXTAMT = 0 ,@TXBTXAMT = 0 ,@OBTAXAMT = 0 ,@ORBKTMSC = 0 ,@ORBKTFRT = 0 ,@ORMISCAMT = 0 ,@ORFRTAMT = 0 ,@ORSUBTOT = 0 ,@ORTDISAM = 0 ,@OCOMMAMT = 0 ,@ORMRKDAM = 0 ,@ORDATKN = 0 ,@ORDDLRAT = 0 ,@ORDISTKN = 0 ,@ORDISRTD = 0 ,@ORDAVAMT = 0 ,@ORDAVMSC = 0 ,@ORDAVFRT = 0 ,@ORMSCTAX = 0 ,@ORFRTTAX = 0 ,@EXTDCOST = 0 ,@INTERID = '' ,@CMPANYID = 0 ,@FUNLCURR = '' ,@ISMCTRX = 0 ,@DTAREF = '' ,@DECPLCUR = 0 ,@LOCNCODE = '' ,@TAXSCHID = '' ,@STAXSCHD = '' ,@SHIPTYPE = 10 ,@USEADVTX = 0 ,@MS_ITEM_1 = POWER(2, 24) ,@FUTOTAMT = 0 ,@RECALC = 0 ,@VATEnabled = 0 ,@O_oErrorState = 0 ,@O_iErrorState = 0 ,@iStatus = 0 ,@dDISCDATE = '' ,@dtDEFAULT = '' ,@dDUEDATE = '' ,@DAYTOEXP = 0 ,@ACCTAMNT = 0 ,@oErrString = '' ,@iUpdtBthErrState = 0 ,@iUpdDistErrState = 0 ,@UNPSTOCA = 0 ,@UNPSTOSA = 0 ,@COMMAMNT = 0 ,@COMAPPTO = 0 ,@CMMSLAMT = 0 ,@MRKDNAMT = 0 ,@ORCOSAMT = 0 ,@NCOMAMNT = 0 ,@PostingType = 0 ,@TRADEPCT = 0 ,@DISCMISC = 0 ,@O_iCommentMstErrState = 0 ,@taSopTaxEngineErrState = 0 ,@taSopTaxEngineErrString = '' ,@taMCCurrencyValidateErrState = 0 ,@taMCCurrencyValidateErrString = '' ,@taCreateSOPDistributionsErrState = 0 ,@taCreateSOPDistributionsErrString = '' ,@DECPLUSED = 0 ,@ExstDOCAMNTNeg = 0 ,@ExstORDOCAMT = 0 ,@BatchCHEKBKID = '' ,@NewCUSTNAME = '' ,@NewCSTPONBR = '' ,@NewDOCAMNT = 0 ,@NewFREIGHT = 0 ,@NewMISCAMNT = 0 ,@NewDISTKNAM = 0 ,@NewDOCDATE = '' ,@NewRATETPID = '' ,@NewEXPNDATE = '' ,@NewEXCHDATE = '' ,@NewEXGTBDSC = '' ,@NewEXTBLSRC = '' ,@NewRATEEXPR = - 1 ,@NewDYSTINCR = - 1 ,@NewRATEVARC = 0 ,@NewTRXDTDEF = - 1 ,@NewRTCLCMTD = - 1 ,@NewPRVDSLMT = 0 ,@NewDATELMTS = 0 ,@NewTIME1 = '' ,@NewXCHGRATE = 0 ,@NewTAXSCHID = '' ,@NewFRTSCHID = '' ,@NewMSCSCHID = '' ,@NewLOCNCODE = '' ,@NewPRCLEVEL = '' ,@NewFREIGTBLE = 0 ,@NewMISCTBLE = 0 ,@NewREPTING = 0 ,@NewTRXFREQU = 0 ,@NewTIMETREP = 0 ,@NewQUOTEDYSTINCR = 0 ,@ALLREPEA = 0 ,@SOPHdrTbl = '' ,@DexRowID = 0 ,@oExists = 0 ,@OInsStatus = 0 ,@DexLockErrorState = 0 ,@OldTAXAMNT = 0 ,@OldORTAXMNT = 0 ,@NewDISCRTND = 0 ,@mylock = 0 ,@DOCID = '' ,@iCustomerBalanceErrState = 0 ,@taCustomerBalanceErrString = '' ,@OverCreditLimit = 0 ,@CRLMTTYP = 0 ,@CurrBalance = 0 ,@CRLMTAMT = 0 ,@CUSTBLNC = 0 ,@UNPSTDSA = 0 ,@UNPSTOSA1 = 0 ,@ONORDAMT = 0 ,@UNPSTDCA = 0 ,@UNPSTOCA1 = 0 ,@DEPRECV = 0 ,@HOLD = 0 ,@INACTIVE = 0 ,@CrdChkAmnt = 0 ,@BACHNUMBSUM = 0 ,@FUFILDAT = '' ,@ACTLSHIP = '' ,@DEPOSITS = 0 ,@ORDEPOSITS = 0 ,@PAYMENTS = 0 ,@ORPAYMENTS = 0 ,@BackoutTradeDisc = 0 ,@OrigBackoutTradeDisc = 0 ,@HdrPAYMENTS = 0 ,@OrHdrPAYMENTS = 0 ,@TRDISAMT = 0 ,@TRDISAMTDIF = 0 ,@DSCLCTYP = 0 ,@DSCDLRAM = 0 ,@DSCPCTAM = 0 ,@SALPURCH = 1 ,@DISCNTCB = 1 ,@FREIGHT = 1 ,@MISC = 1 ,@TAX = 1 ,@PymtTermAmnt1 = 0 ,@PymtTermAmnt2 = 0 ,@PymtTermAmnt3 = 0 ,@PymtTermAmnt4 = 0 ,@PymtTermAmnt5 = 0 ,@PymtTermAmnt8 = 0 ,@CURRNIDXFun = 0 ,@lock = '' ,@BSIVCTTL = 0 ,@Flags = 0 ,@PYMTRMID = '' ,@stoprecalc = 0 ,@recalcdeposits = 0 ,@CRLMTPER = 0 ,@CRLMTPAM = 0 ,@NOTEINDX = 0 ,@sCompanyID = 0 ,@iGetNextNoteIdxErrState = 0 ,@ALLOCABY = 0 ,@USDOCID1 = '' ,@USDOCID2 = '' ,@QUOTOINV = 0 ,@QUOTOORD = 0 ,@INVTOBAC = 0 ,@BACTOINV = 0 ,@BACTOORD = 0 ,@ORDTOBAC = 0 ,@ORIGTYPE = 0 ,@USERDEFEXISTS = 0 ,@defUPSZONE = '' ,@defSALSTERR = '' ,@defSLPRSNID = '' ,@defSHIPMTHD = '' ,@CCode = '' ,@ADDRESS1 = '' ,@ADDRESS2 = '' ,@ADDRESS3 = '' ,@CNTCPRSN = '' ,@FAXNUMBR = '' ,@CITY = '' ,@STATE = '' ,@ZIPCODE = '' ,@COUNTRY = '' ,@PHNUMBR1 = '' ,@PHNUMBR2 = '' ,@PHNUMBR3 = '' ,@NACREDITCHECK = 0 ,@CPRCSTNM = '' ,@CUSTNMBR = '' ,@WORKFLOWENABLED = 0 ,@WorkflowApprStatusQuote = 0 ,@WorkflowPriorityQuote = 0 ,@WorkflowApprStatCreditLm = 0 ,@WorkflowPriorityCreditLm = 0 ,@USINGNEGATIVES = 0 ,@TAXAMNTL = 0 ,@STOP = 0 ,@ExstPrint_Phone_NumberGB = 0 ,@NewPrint_Phone_NumberGB = 0 ,@NewShipToName = '' ,@SITEINACTIVE = 0 ,@ITEMSITEINACTIVE = 0 IF (@oErrString IS NULL) BEGIN SELECT @oErrString = '' END SELECT @DBName = DB_NAME() SELECT @I_vSOPNUMBE = UPPER(@I_vSOPNUMBE) ,@I_vTAXSCHID = UPPER(@I_vTAXSCHID) ,@I_vSHIPMTHD = UPPER(@I_vSHIPMTHD) ,@I_vPRCLEVEL = UPPER(@I_vPRCLEVEL) ,@I_vLOCNCODE = UPPER(@I_vLOCNCODE) ,@I_vCSTPONBR = UPPER(@I_vCSTPONBR) ,@I_vSLPRSNID = UPPER(@I_vSLPRSNID) ,@I_vSALSTERR = UPPER(@I_vSALSTERR) ,@I_vBACHNUMB = UPPER(@I_vBACHNUMB) ,@I_vPRBTADCD = UPPER(@I_vPRBTADCD) ,@I_vPRSTADCD = UPPER(@I_vPRSTADCD) ,@I_vFRTSCHID = UPPER(@I_vFRTSCHID) ,@I_vMSCSCHID = UPPER(@I_vMSCSCHID) ,@I_vBatchCHEKBKID = UPPER(@I_vBatchCHEKBKID) ,@I_vRATETPID = UPPER(@I_vRATETPID) ,@I_vCOMMNTID = UPPER(@I_vCOMMNTID) IF ( NOT EXISTS ( SELECT 1 FROM SOP10100(NOLOCK) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE ) ) BEGIN SELECT @O_iErrorState = 1730 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END SELECT @ExstDOCDATE = DOCDATE ,@ExstQUOTEDAT = QUOTEDAT ,@ExstQUOEXPDA = QUOEXPDA ,@ExstORDRDATE = ORDRDATE ,@ExstINVODATE = INVODATE ,@ExstBACKDATE = BACKDATE ,@ExstRETUDATE = RETUDATE ,@ExstReqShipDate = ReqShipDate ,@ExstDISCDATE = DISCDATE ,@ExstDUEDATE = DUEDATE ,@ExstDISCFRGT = DISCFRGT ,@ExstDISCMISC = DISCMISC ,@ExstDISCRTND = DISCRTND ,@ExstORDISRTD = ORDISRTD ,@ExstDISTKNAM = DISTKNAM ,@ExstORDISTKN = ORDISTKN ,@ExstPRCLEVEL = PRCLEVEL ,@ExstLOCNCODE = LOCNCODE ,@ExstBACHNUMB = BACHNUMB ,@ExstCUSTNMBR = CUSTNMBR ,@ExstCUSTNAME = CUSTNAME ,@ExstCSTPONBR = CSTPONBR ,@ExstORMRKDAM = ORMRKDAM ,@ExstPRBTADCD = PRBTADCD ,@ExstPRSTADCD = PRSTADCD ,@ExstCNTCPRSN = CNTCPRSN ,@ExstShipToName = ShipToName ,@ExstADDRESS1 = ADDRESS1 ,@ExstADDRESS2 = ADDRESS2 ,@ExstADDRESS3 = ADDRESS3 ,@ExstCITY = CITY ,@ExstSTATE = STATE ,@ExstZIPCODE = ZIPCODE ,@ExstCOUNTRY = COUNTRY ,@ExstPHNUMBR1 = PHNUMBR1 ,@ExstPHNUMBR2 = PHNUMBR2 ,@ExstPHONE3 = PHONE3 ,@ExstFAXNUMBR = FAXNUMBR ,@ExstCOMAPPTO = COMAPPTO ,@ExstSHIPMTHD = SHIPMTHD ,@ExstSUBTOTAL = SUBTOTAL ,@ExstREMSUBTO = REMSUBTO ,@ExstEXTDCOST = EXTDCOST ,@ExstFRTAMNT = FRTAMNT ,@ExstORFRTAMT = ORFRTAMT ,@ExstMISCAMNT = MISCAMNT ,@ExstORMISCAMT = ORMISCAMT ,@ExstORSUBTOT = ORSUBTOT ,@ExstOREMSUBT = OREMSUBT ,@ExstORFRTTAX = ORFRTTAX ,@ExstORMSCTAX = ORMSCTAX ,@ExstTAXSCHID = TAXSCHID ,@ExstFRTSCHID = FRTSCHID ,@ExstFRTTXAMT = FRTTXAMT ,@ExstFRGTTXBL = FRGTTXBL ,@ExstMSCSCHID = MSCSCHID ,@ExstMSCTXAMT = MSCTXAMT ,@ExstMISCTXBL = MISCTXBL ,@ExstBKTFRTAM = BKTFRTAM ,@ExstORBKTFRT = ORBKTFRT ,@ExstBKTMSCAM = BKTMSCAM ,@ExstORBKTMSC = ORBKTMSC ,@ExstBCKTXAMT = BCKTXAMT ,@ExstOBTAXAMT = OBTAXAMT ,@ExstTAXAMNT = TAXAMNT ,@ExstORTAXAMT = ORTAXAMT ,@ExstDOCAMNT = DOCAMNT ,@ExstORDOCAMT = ORDOCAMT ,@ExstPYMTRCVD = PYMTRCVD ,@ExstORPMTRVD = ORPMTRVD ,@ExstDEPRECVD = DEPRECVD ,@ExstORDEPRVD = ORDEPRVD ,@ExstSALSTERR = SALSTERR ,@ExstSLPRSNID = SLPRSNID ,@ExstUPSZONE = UPSZONE ,@ExstCURNCYID = CURNCYID ,@ExstCURRNIDX = CURRNIDX ,@ExstRATETPID = RATETPID ,@ExstEXCHDATE = EXCHDATE ,@ExstDYSTINCR = DYSTINCR ,@ExstRTCLCMTD = RTCLCMTD ,@ExstEXGTBLID = EXGTBLID ,@ExstXCHGRATE = XCHGRATE ,@ExstTIME1 = TIME1 ,@ExstCOMMNTID = COMMNTID ,@ExstREFRENCE = REFRENCE ,@ExstPTDUSRID = PTDUSRID ,@ExstMODIFDT = MODIFDT ,@ExstGPSFOINTEGRATIONID = GPSFOINTEGRATIONID ,@ExstINTEGRATIONSOURCE = INTEGRATIONSOURCE ,@ExstINTEGRATIONID = INTEGRATIONID ,@DOCID = DOCID ,@ExstREPTING = REPTING ,@ExstTRXFREQU = TRXFREQU ,@ExstTIMETREP = TIMETREP ,@ExstQUOTEDYSTINCR = DYSTINCR ,@ExstFlags = Flags ,@NOTEINDX = NOTEINDX ,@ORIGTYPE = ORIGTYPE ,@ExstPrint_Phone_NumberGB = Print_Phone_NumberGB FROM SOP10100(NOLOCK) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE SELECT @CurrTime = ' ' + SUBSTRING(CONVERT(VARCHAR(25), GETDATE()), 12, 12) IF ( (@I_vSOPTYPE IS NULL) OR (@I_vSOPNUMBE IS NULL) OR (@I_vSOPTYPE = '') OR (@I_vSOPNUMBE = '') ) BEGIN SELECT @O_iErrorState = 1732 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF ( (@I_vSOPTYPE < 1) OR (@I_vSOPTYPE > 6) ) BEGIN SELECT @O_iErrorState = 1733 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF ( (@I_vRECREATECOMM < 0) OR (@I_vRECREATECOMM > 1) ) BEGIN SELECT @O_iErrorState = 2601 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF ( (@I_vRECREATEDIST < 0) OR (@I_vRECREATEDIST > 1) ) BEGIN SELECT @O_iErrorState = 2602 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF ( (@I_vRECREATETAXES < 0) OR (@I_vRECREATETAXES > 1) ) BEGIN SELECT @O_iErrorState = 2603 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF ( (@I_vDEFTAXSCHDS < 0) OR (@I_vDEFTAXSCHDS > 1) ) BEGIN SELECT @O_iErrorState = 2604 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF ( (@I_vFREIGTBLE < 0) OR (@I_vFREIGTBLE > 3) ) BEGIN SELECT @O_iErrorState = 2605 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF ( (@I_vMISCTBLE < 0) OR (@I_vMISCTBLE > 3) ) BEGIN SELECT @O_iErrorState = 2606 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF ( (@I_vCKCreditLimit < 0) OR (@I_vCKCreditLimit > 1) ) BEGIN SELECT @O_iErrorState = 3556 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF ( (@I_vCKHOLD < 0) OR (@I_vCKHOLD > 1) ) BEGIN SELECT @O_iErrorState = 3557 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF ( (@I_vRequesterTrx < 0) OR (@I_vRequesterTrx > 1) ) BEGIN SELECT @O_iErrorState = 2607 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END SELECT @ALLREPEA = ALLREPEA FROM SOP40200(NOLOCK) WHERE SOPTYPE = @I_vSOPTYPE AND DOCID = @DOCID IF (@I_vREPTING < 0) OR (@I_vREPTING > 1) BEGIN SELECT @O_iErrorState = 5645 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF (@I_vTRXFREQU < 0) OR (@I_vTRXFREQU > 7) BEGIN SELECT @O_iErrorState = 5646 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF (@I_vTIMETREP < 0) OR (@I_vTIMETREP > 9999) BEGIN SELECT @O_iErrorState = 5647 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF (@I_vQUOTEDYSTINCR < 0) OR (@I_vQUOTEDYSTINCR > 999) BEGIN SELECT @O_iErrorState = 5648 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF (@I_vRECALCBTCHTOT = 1) BEGIN SELECT @recalcdeposits = 1 ,@stoprecalc = 1 END ELSE BEGIN IF (@I_vRECALCBTCHTOT = 2) BEGIN SELECT @stoprecalc = 0 END ELSE BEGIN IF (@I_vRECALCBTCHTOT = 3) BEGIN SELECT @stoprecalc = 1 END ELSE BEGIN IF (@I_vRECALCBTCHTOT = 4) BEGIN SELECT @stoprecalc = 0 ,@STOP = 1 END ELSE BEGIN IF (@I_vRECALCBTCHTOT = 5) BEGIN SELECT @stoprecalc = 0 ,@STOP = 3 END ELSE BEGIN IF (@I_vRECALCBTCHTOT = 6) BEGIN SELECT @stoprecalc = 0 ,@STOP = 0 END END END END END END IF ( (@I_vFREIGHT < 0) OR (@I_vMISCAMNT < 0) OR (@I_vTRDISAMT < 0) OR (@I_vTRADEPCT < 0) OR (@I_vDISTKNAM < 0) OR (@I_vCOMPRCNT < 0) OR (@I_vXCHGRATE < 0) OR (@I_vDISAVAMT < 0) OR (@I_vDSCDLRAM < 0) OR (@I_vDSCPCTAM < 0) OR (@I_vPYMTRCVD < 0) ) BEGIN SELECT @O_iErrorState = 1734 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END SELECT @TAXSCHID = TAXSCHID ,@FRGTTXBL = FRGTTXBL ,@MISCTXBL = MISCTXBL ,@FRTSCHID = FRTSCHID ,@MSCSCHID = MSCSCHID ,@USEADVTX = USEADVTX FROM SOP40100(NOLOCK) WHERE SETUPKEY = 1 IF (@I_vMISCTBLE IS NULL) BEGIN SELECT @I_vMISCTBLE = 0 END IF (@I_vFREIGTBLE IS NULL) BEGIN SELECT @I_vFREIGTBLE = 0 END IF (@I_vRECREATECOMM IS NULL) BEGIN SELECT @I_vRECREATECOMM = 0 END IF (@I_vRECREATEDIST IS NULL) BEGIN SELECT @I_vRECREATEDIST = 0 END IF (@I_vCOMPRCNT IS NULL) BEGIN SELECT @I_vCOMPRCNT = 0 END IF (@I_vRECREATETAXES IS NULL) BEGIN SELECT @I_vRECREATETAXES = 0 END IF (@I_vDEFTAXSCHDS IS NULL) BEGIN SELECT @I_vDEFTAXSCHDS = 0 END IF (@I_vRequesterTrx IS NULL) BEGIN SELECT @I_vRequesterTrx = 0 END IF (@I_vCUSTNAME IS NULL) SET @NewCUSTNAME = @ExstCUSTNAME ELSE SET @NewCUSTNAME = @I_vCUSTNAME IF (@I_vCSTPONBR IS NULL) SET @NewCSTPONBR = @ExstCSTPONBR ELSE SET @NewCSTPONBR = @I_vCSTPONBR IF (@I_vFREIGHT IS NULL) SET @NewFREIGHT = @ExstORFRTAMT ELSE SET @NewFREIGHT = @I_vFREIGHT IF (@I_vMISCAMNT IS NULL) SET @NewMISCAMNT = @ExstORMISCAMT ELSE SET @NewMISCAMNT = @I_vMISCAMNT IF (@I_vSOPTYPE <> 4) BEGIN IF (@I_vDISTKNAM IS NULL) SET @NewDISTKNAM = @ExstDISTKNAM ELSE SET @NewDISTKNAM = @I_vDISTKNAM END ELSE BEGIN IF (@I_vDISTKNAM IS NULL) SET @NewDISCRTND = @ExstDISCRTND ELSE SET @NewDISCRTND = @I_vDISTKNAM END IF (@I_vPYMTRCVD IS NULL) BEGIN IF ( @I_vSOPTYPE IN ( 3 ,6 ) ) BEGIN SET @NewPYMTRCVD = @ExstORPMTRVD END ELSE BEGIN SET @NewPYMTRCVD = @ExstORPMTRVD + @ExstORDEPRVD END END ELSE BEGIN SET @NewPYMTRCVD = @I_vPYMTRCVD END IF (@I_vDOCDATE IS NULL) SET @NewDOCDATE = @ExstDOCDATE ELSE SET @NewDOCDATE = @I_vDOCDATE IF ( (@I_vRATETPID IS NULL) OR (@I_vRATETPID = '') ) SET @NewRATETPID = @ExstRATETPID ELSE SET @NewRATETPID = @I_vRATETPID IF ( (@I_vEXPNDATE IS NULL) OR (@I_vEXPNDATE = '') ) SET @NewEXPNDATE = '' IF ( (@I_vEXCHDATE IS NULL) OR (@I_vEXCHDATE = '') ) SET @NewEXCHDATE = @ExstEXCHDATE ELSE SET @NewEXCHDATE = @I_vEXCHDATE IF ( (@I_vEXGTBDSC IS NULL) OR (@I_vEXGTBDSC = '') ) SET @NewEXGTBDSC = '' IF ( (@I_vEXTBLSRC IS NULL) OR (@I_vEXTBLSRC = '') ) SET @NewEXTBLSRC = '' IF ( (@I_vRATEEXPR IS NULL) OR (@I_vRATEEXPR = - 1) ) SET @NewRATEEXPR = '' IF ( (@I_vDYSTINCR IS NULL) OR (@I_vDYSTINCR = - 1) ) SET @NewDYSTINCR = @ExstDYSTINCR ELSE SET @NewDYSTINCR = @I_vDYSTINCR IF ( (@I_vRATEVARC IS NULL) OR (@I_vRATEVARC = 0) ) SET @NewRATEVARC = @ExstRATEVARC ELSE SET @NewRATEVARC = @I_vRATEVARC IF ( (@I_vTRXDTDEF IS NULL) OR (@I_vTRXDTDEF = - 1) ) SET @NewTRXDTDEF = @ExstTRXDTDEF ELSE SET @NewTRXDTDEF = @I_vTRXDTDEF IF ( (@I_vRTCLCMTD IS NULL) OR (@I_vRTCLCMTD = - 1) ) SET @NewRTCLCMTD = @ExstRTCLCMTD ELSE SET @NewRTCLCMTD = @I_vRTCLCMTD IF ( (@I_vPRVDSLMT IS NULL) OR (@I_vPRVDSLMT = 0) ) SET @NewPRVDSLMT = 0 IF ( (@I_vDATELMTS IS NULL) OR (@I_vDATELMTS = 0) ) SET @NewDATELMTS = 0 IF ( (@I_vTIME1 IS NULL) OR (@I_vTIME1 = '') ) SET @NewTIME1 = @ExstTIME1 ELSE SET @NewTIME1 = @I_vTIME1 IF ( (@I_vXCHGRATE IS NULL) OR (@I_vXCHGRATE = 0) ) SET @NewXCHGRATE = @ExstXCHGRATE ELSE SET @NewXCHGRATE = @I_vXCHGRATE IF (@I_vPRCLEVEL IS NULL) OR (@I_vPRCLEVEL = '') SET @NewPRCLEVEL = @ExstPRCLEVEL ELSE SET @NewPRCLEVEL = @I_vPRCLEVEL IF (@I_vLOCNCODE IS NULL) SET @NewLOCNCODE = @ExstLOCNCODE ELSE SET @NewLOCNCODE = @I_vLOCNCODE IF (@I_vPRBTADCD IS NULL) SET @NewPRBTADCD = @ExstPRBTADCD ELSE SET @NewPRBTADCD = @I_vPRBTADCD IF ( (@I_vShipToName = '') OR (@I_vShipToName IS NULL) ) SET @NewShipToName = @ExstShipToName ELSE SET @NewShipToName = @I_vShipToName IF (@I_vPrint_Phone_NumberGB IS NULL) SET @NewPrint_Phone_NumberGB = @ExstPrint_Phone_NumberGB ELSE SET @NewPrint_Phone_NumberGB = @I_vPrint_Phone_NumberGB IF ( (@I_vREPTING IS NULL) OR ( @I_vSOPTYPE NOT IN ( 1 ,2 ) ) ) BEGIN SET @NewREPTING = @ExstREPTING END ELSE BEGIN IF (@ALLREPEA = 1) BEGIN SET @NewREPTING = @I_vREPTING END ELSE BEGIN SET @NewREPTING = @ExstREPTING END END IF ( (@I_vTRXFREQU IS NULL) OR ( @I_vSOPTYPE NOT IN ( 1 ,2 ) ) ) BEGIN SET @NewTRXFREQU = @ExstTRXFREQU END ELSE BEGIN IF (@ALLREPEA = 1) BEGIN SET @NewTRXFREQU = @I_vTRXFREQU END ELSE BEGIN SET @NewTRXFREQU = @ExstTRXFREQU END END IF ( (@I_vTIMETREP IS NULL) OR ( @I_vSOPTYPE NOT IN ( 1 ,2 ) ) ) BEGIN SET @NewTIMETREP = @ExstTIMETREP END ELSE BEGIN IF (@ALLREPEA = 1) BEGIN SET @NewTIMETREP = @I_vTIMETREP END ELSE BEGIN SET @NewTIMETREP = @ExstTIMETREP END END IF ( (@I_vQUOTEDYSTINCR IS NULL) OR ( @I_vSOPTYPE NOT IN ( 1 ,2 ) ) ) BEGIN SET @NewQUOTEDYSTINCR = @ExstQUOTEDYSTINCR END ELSE BEGIN IF (@ALLREPEA = 1) BEGIN SET @NewQUOTEDYSTINCR = @I_vQUOTEDYSTINCR END ELSE BEGIN SET @NewQUOTEDYSTINCR = @ExstQUOTEDYSTINCR END END IF ( (@I_vFREIGTBLE = 0) OR (@I_vFREIGTBLE IS NULL) ) BEGIN SET @NewFREIGTBLE = @FRGTTXBL END ELSE BEGIN SET @NewFREIGTBLE = @I_vFREIGTBLE END IF ( (@I_vMISCTBLE = 0) OR (@I_vMISCTBLE IS NULL) ) BEGIN SET @NewMISCTBLE = @MISCTXBL END ELSE BEGIN SET @NewMISCTBLE = @I_vMISCTBLE END IF ( (@I_vTAXSCHID <> '') AND (@I_vTAXSCHID IS NOT NULL) ) BEGIN SELECT @NewTAXSCHID = @I_vTAXSCHID END IF ( (@I_vFRTSCHID <> '') AND (@I_vFRTSCHID IS NOT NULL) ) BEGIN SELECT @NewFRTSCHID = @I_vFRTSCHID END IF ( (@I_vMSCSCHID <> '') AND (@I_vMSCSCHID IS NOT NULL) ) BEGIN SELECT @NewMSCSCHID = @I_vMSCSCHID END SELECT @ExstORDOCAMT = @ExstORSUBTOT + @ExstORFRTAMT + @ExstORMISCAMT + @ExstORTAXAMT SELECT @FUNLCURR = FUNLCURR ,@CURRNIDXFun = FUNCRIDX FROM MC40000(NOLOCK) IF (@FUNLCURR = '') BEGIN SELECT @O_iErrorState = 9310 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END SELECT @DECPLCUR = DECPLCUR - 1 FROM DYNAMICS..MC40200(NOLOCK) WHERE CURNCYID = @FUNLCURR IF (@ExstCURNCYID = '') BEGIN SELECT @ExstCURNCYID = @FUNLCURR END IF ( (@FUNLCURR <> '') OR (@ExstCURNCYID <> '') ) BEGIN IF (@ExstCURNCYID <> '') SELECT @DECPLUSED = DECPLCUR - 1 FROM DYNAMICS..MC40200(NOLOCK) WHERE CURNCYID = @ExstCURNCYID ELSE SELECT @DECPLUSED = DECPLCUR - 1 FROM DYNAMICS..MC40200(NOLOCK) WHERE CURNCYID = @FUNLCURR IF ( (@NewFREIGHT <> ROUND(@NewFREIGHT, @DECPLUSED)) OR (@NewMISCAMNT <> ROUND(@NewMISCAMNT, @DECPLUSED)) OR (@I_vTRDISAMT <> ROUND(@I_vTRDISAMT, @DECPLUSED)) OR (@NewDISTKNAM <> ROUND(@NewDISTKNAM, @DECPLUSED)) OR (@I_vDISAVAMT <> ROUND(@I_vDISAVAMT, @DECPLUSED)) OR (@NewPYMTRCVD <> ROUND(@NewPYMTRCVD, @DECPLUSED)) ) BEGIN SELECT @O_iErrorState = 1735 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END END IF ( (@ExstCURNCYID <> '') AND (@ExstCURNCYID <> @FUNLCURR) ) BEGIN SELECT @ISMCTRX = 1 END IF (@ISMCTRX = 0) BEGIN SELECT @NewRTCLCMTD = - 1 END IF EXISTS ( SELECT 1 FROM SOP10200(NOLOCK) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE AND QUANTITY < 0 ) OR EXISTS ( SELECT 1 FROM SOP10200(NOLOCK) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE AND UNITPRCE < 0 ) BEGIN SELECT @USINGNEGATIVES = 1 END SELECT @INTERID = INTERID ,@VATEnabled = ABS(SIGN(ISNULL(Company_Options, 0) & @MS_ITEM_1)) FROM DYNAMICS..SY01500(NOLOCK) WHERE INTERID = DB_NAME() IF @NewRATETPID <> '' BEGIN IF ( NOT EXISTS ( SELECT 1 FROM MC40100(NOLOCK) WHERE RATETPID = @NewRATETPID ) ) BEGIN SELECT @O_iErrorState = 1736 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END END IF ( (@NewDISTKNAM > 0) AND ( @I_vSOPTYPE NOT IN ( 3 ,4 ,6 ) ) ) BEGIN SELECT @O_iErrorState = 1738 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF ( (@I_vDISAVAMT > 0) AND ( @I_vSOPTYPE NOT IN ( 3 ,6 ) ) ) BEGIN SELECT @O_iErrorState = 1739 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF ( (@I_vBatchCHEKBKID <> '') AND (@I_vBatchCHEKBKID IS NOT NULL) ) BEGIN IF ( NOT EXISTS ( SELECT 1 FROM CM00100(NOLOCK) WHERE CHEKBKID = @I_vBatchCHEKBKID ) ) BEGIN SELECT @O_iErrorState = 1740 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF ( EXISTS ( SELECT 1 FROM CM00100(NOLOCK) WHERE CHEKBKID = @I_vBatchCHEKBKID AND INACTIVE = 1 ) ) BEGIN SELECT @O_iErrorState = 9516 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END END --IF (@I_vSLPRSNID <> '') --BEGIN -- IF ( -- NOT EXISTS ( -- SELECT 1 -- FROM RM00301(NOLOCK) -- WHERE SLPRSNID = @I_vSLPRSNID -- ) -- ) -- BEGIN -- SELECT @O_iErrorState = 1742 -- EXEC @iStatus = taUpdateString @O_iErrorState -- ,@oErrString -- ,@oErrString OUTPUT -- ,@O_oErrorState OUTPUT -- END -- IF ( -- EXISTS ( -- SELECT 1 -- FROM RM00301(NOLOCK) -- WHERE SLPRSNID = @I_vSLPRSNID -- AND INACTIVE = 1 -- ) -- ) -- BEGIN -- SELECT @O_iErrorState = 9539 -- EXEC @iStatus = taUpdateString @O_iErrorState -- ,@oErrString -- ,@oErrString OUTPUT -- ,@O_oErrorState OUTPUT -- END --END IF (@I_vSALSTERR <> '') BEGIN IF ( NOT EXISTS ( SELECT 1 FROM RM00303(NOLOCK) WHERE SALSTERR = @I_vSALSTERR ) ) BEGIN SELECT @O_iErrorState = 1743 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END END IF ( (@I_vXCHGRATE IS NOT NULL) AND (@I_vXCHGRATE <> 0) AND (@I_vXCHGRATE <> @NewXCHGRATE) AND ( (@ExstDEPRECVD > 0) OR (@ExstPYMTRCVD > 0) ) ) BEGIN SELECT @O_iErrorState = 1744 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF (@NewLOCNCODE <> '') BEGIN IF ( NOT EXISTS ( SELECT 1 FROM IV40700(NOLOCK) WHERE LOCNCODE = @NewLOCNCODE ) ) BEGIN SELECT @O_iErrorState = 1745 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END END SELECT @SITEINACTIVE = INACTIVE FROM IV40700(NOLOCK) WHERE LOCNCODE = @NewLOCNCODE IF ( @NewLOCNCODE <> '' AND @SITEINACTIVE = 1 ) BEGIN SELECT @O_iErrorState = 11810 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF (@NewPRCLEVEL <> '') BEGIN IF ( NOT EXISTS ( SELECT 1 FROM IV40800(NOLOCK) WHERE PRCLEVEL = @NewPRCLEVEL ) ) BEGIN SELECT @O_iErrorState = 8124 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END END IF ( ( (@I_vTRDISAMT > 0) AND (@I_vTRADEPCT > 0) ) OR ( (@I_vTRDISAMT IS NOT NULL) AND (@I_vTRADEPCT IS NOT NULL) ) ) BEGIN SELECT @O_iErrorState = 7801 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END SELECT @STAXSCHD = ISNULL(STAXSCHD, '') FROM IV40700(NOLOCK) WHERE LOCNCODE = @NewLOCNCODE SELECT @PYMTRMID = CASE WHEN @I_vSOPTYPE = 4 THEN '' ELSE PYMTRMID END ,@NewCUSTNAME = CASE WHEN @NewCUSTNAME = '' THEN CUSTNAME ELSE @NewCUSTNAME END ,@CPRCSTNM = CPRCSTNM ,@NewPRBTADCD = CASE WHEN @NewPRBTADCD = '' THEN PRBTADCD ELSE @NewPRBTADCD END ,@I_vPRSTADCD = CASE WHEN @I_vPRSTADCD IS NULL THEN PRSTADCD ELSE @I_vPRSTADCD END ,@I_vTAXEXMT1 = CASE WHEN @I_vTAXEXMT1 IS NULL THEN TAXEXMT1 ELSE @I_vTAXEXMT1 END ,@I_vTAXEXMT2 = CASE WHEN @I_vTAXEXMT2 IS NULL THEN TAXEXMT2 ELSE @I_vTAXEXMT2 END ,@I_vTXRGNNUM = CASE WHEN @I_vTXRGNNUM IS NULL THEN TXRGNNUM ELSE @I_vTXRGNNUM END FROM RM00101(NOLOCK) WHERE CUSTNMBR = @ExstCUSTNMBR IF (@NewPRBTADCD <> '') BEGIN IF ( NOT EXISTS ( SELECT 1 FROM RM00102(NOLOCK) WHERE CUSTNMBR = @ExstCUSTNMBR AND ADRSCODE = @NewPRBTADCD ) ) BEGIN SELECT @O_iErrorState = 1748 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END END IF (@I_vPRSTADCD <> '') BEGIN IF ( NOT EXISTS ( SELECT 1 FROM RM00102(NOLOCK) WHERE CUSTNMBR = @ExstCUSTNMBR AND ADRSCODE = @I_vPRSTADCD ) ) BEGIN SELECT @O_iErrorState = 1749 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END ELSE BEGIN IF ( ( (@I_vShipToName = '') OR (@I_vShipToName IS NULL) ) AND ( ( @I_vADDRESS1 = '' OR @I_vADDRESS1 IS NULL ) ) AND ( ( @I_vADDRESS2 = '' OR @I_vADDRESS2 IS NULL ) ) AND ( ( @I_vADDRESS3 = '' OR @I_vADDRESS3 IS NULL ) ) AND ( ( @I_vCNTCPRSN = '' OR @I_vCNTCPRSN IS NULL ) ) AND ( ( @I_vFAXNUMBR = '' OR @I_vFAXNUMBR IS NULL ) ) AND ( ( @I_vCITY = '' OR @I_vCITY IS NULL ) ) AND ( ( @I_vSTATE = '' OR @I_vSTATE IS NULL ) ) AND ( ( @I_vZIPCODE = '' OR @I_vZIPCODE IS NULL ) ) AND ( ( @I_vCOUNTRY = '' OR @I_vCOUNTRY IS NULL ) ) AND ( ( @I_vPHNUMBR1 = '' OR @I_vPHNUMBR1 IS NULL ) ) AND ( ( @I_vPHNUMBR2 = '' OR @I_vPHNUMBR2 IS NULL ) ) AND ( ( @I_vPHNUMBR3 = '' OR @I_vPHNUMBR3 IS NULL ) ) ) BEGIN SELECT @I_vADDRESS1 = ADDRESS1 ,@I_vADDRESS2 = ADDRESS2 ,@I_vADDRESS3 = ADDRESS3 ,@I_vCNTCPRSN = CNTCPRSN ,@I_vCITY = CITY ,@I_vSTATE = STATE ,@I_vZIPCODE = ZIP ,@I_vCOUNTRY = COUNTRY ,@I_vPHNUMBR1 = PHONE1 ,@I_vPHNUMBR2 = PHONE2 ,@I_vPHNUMBR3 = PHONE3 ,@I_vFAXNUMBR = FAX FROM RM00102(NOLOCK) WHERE CUSTNMBR = @ExstCUSTNMBR AND ADRSCODE = @I_vPRSTADCD END ELSE BEGIN SELECT @ADDRESS1 = ADDRESS1 ,@ADDRESS2 = ADDRESS2 ,@ADDRESS3 = ADDRESS3 ,@CNTCPRSN = CNTCPRSN ,@CITY = CITY ,@STATE = STATE ,@ZIPCODE = ZIP ,@COUNTRY = COUNTRY ,@PHNUMBR1 = PHONE1 ,@PHNUMBR2 = PHONE2 ,@PHNUMBR3 = PHONE3 ,@FAXNUMBR = FAX FROM RM00102(NOLOCK) WHERE CUSTNMBR = @ExstCUSTNMBR AND ADRSCODE = @I_vPRSTADCD IF ( (@I_vADDRESS1 <> @ADDRESS1) OR (@I_vADDRESS2 <> @ADDRESS2) OR (@I_vADDRESS3 <> @ADDRESS3) OR (@I_vCNTCPRSN <> @CNTCPRSN) OR (@I_vCITY <> @CITY) OR (@I_vSTATE <> @STATE) OR (@I_vZIPCODE <> @ZIPCODE) OR (@I_vCOUNTRY <> @COUNTRY) OR (@I_vPHNUMBR1 <> @PHNUMBR1) OR (@I_vPHNUMBR2 <> @PHNUMBR2) OR (@I_vPHNUMBR3 <> @PHNUMBR3) OR (@I_vFAXNUMBR <> @FAXNUMBR) ) AND ( ( ( @I_vPHNUMBR1 NOT IN ( '' ,'00000000000000' ) ) OR ( @PHNUMBR1 NOT IN ( '' ,'00000000000000' ) ) ) OR ( ( @I_vPHNUMBR2 NOT IN ( '' ,'00000000000000' ) ) OR ( @PHNUMBR2 NOT IN ( '' ,'00000000000000' ) ) ) OR ( ( @I_vPHNUMBR3 NOT IN ( '' ,'00000000000000' ) ) OR ( @PHNUMBR3 NOT IN ( '' ,'00000000000000' ) ) ) OR ( ( @I_vFAXNUMBR NOT IN ( '' ,'00000000000000' ) ) OR ( @FAXNUMBR NOT IN ( '' ,'00000000000000' ) ) ) ) BEGIN SELECT @Flags = 1 END END END END ELSE BEGIN IF ( @I_vADDRESS1 <> '' OR @I_vADDRESS2 <> '' OR @I_vADDRESS3 <> '' OR @I_vCNTCPRSN <> '' OR @I_vFAXNUMBR <> '' OR @I_vCITY <> '' OR @I_vSTATE <> '' OR @I_vZIPCODE <> '' OR @I_vCOUNTRY <> '' OR @I_vPHNUMBR1 <> '' OR @I_vPHNUMBR2 <> '' OR @I_vPHNUMBR3 <> '' ) BEGIN SELECT @Flags = 1 END END SELECT @defUPSZONE = CASE WHEN @I_vUPSZONE IS NULL THEN UPSZONE ELSE @I_vUPSZONE END ,@defSHIPMTHD = CASE WHEN @I_vSHIPMTHD IS NULL THEN SHIPMTHD ELSE @I_vSHIPMTHD END ,@defSALSTERR = CASE WHEN @I_vSALSTERR IS NULL THEN SALSTERR ELSE @I_vSALSTERR END ,@defSLPRSNID = CASE WHEN @I_vSLPRSNID IS NULL THEN SLPRSNID ELSE @I_vSLPRSNID END ,@CCode = CCode FROM RM00102(NOLOCK) WHERE CUSTNMBR = @ExstCUSTNMBR AND ADRSCODE = @I_vPRSTADCD SELECT @defUPSZONE = CASE WHEN @defUPSZONE = '' THEN UPSZONE ELSE @defUPSZONE END ,@defSHIPMTHD = CASE WHEN @defSHIPMTHD = '' THEN SHIPMTHD ELSE @defSHIPMTHD END ,@defSALSTERR = CASE WHEN @defSALSTERR = '' THEN SALSTERR ELSE @defSALSTERR END ,@defSLPRSNID = CASE WHEN @defSLPRSNID = '' THEN SLPRSNID ELSE @defSLPRSNID END ,@CCode = CASE WHEN @CCode = '' THEN CCode ELSE @CCode END FROM RM00101(NOLOCK) WHERE CUSTNMBR = @ExstCUSTNMBR SELECT @I_vUPSZONE = CASE WHEN @I_vUPSZONE IS NULL THEN @defUPSZONE ELSE @I_vUPSZONE END SELECT @I_vSHIPMTHD = CASE WHEN @I_vSHIPMTHD IS NULL THEN @defSHIPMTHD ELSE @I_vSHIPMTHD END SELECT @I_vSALSTERR = CASE WHEN @I_vSALSTERR IS NULL THEN @defSALSTERR ELSE @I_vSALSTERR END SELECT @I_vSLPRSNID = CASE WHEN @I_vSLPRSNID IS NULL THEN @defSLPRSNID ELSE @I_vSLPRSNID END IF (@I_vCKHOLD = 1) BEGIN SELECT @HOLD = HOLD FROM RM00101(NOLOCK) WHERE CUSTNMBR = @ExstCUSTNMBR IF (@HOLD = 1) BEGIN SELECT @O_iErrorState = 3560 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END END SELECT @INACTIVE = INACTIVE FROM RM00101(NOLOCK) WHERE CUSTNMBR = @ExstCUSTNMBR IF (@INACTIVE = 1) BEGIN SELECT @O_iErrorState = 3561 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF ( (@I_vSHIPMTHD IS NOT NULL) AND (@I_vSHIPMTHD <> '') AND (@I_vSOPTYPE <> 4) ) BEGIN IF ( NOT EXISTS ( SELECT 1 FROM SY03000(NOLOCK) WHERE SHIPMTHD = @I_vSHIPMTHD ) ) BEGIN EXEC @iStatus = taCreateShippingMethod @I_vSHIPMTHD = @I_vSHIPMTHD ,@I_vUpdateIfExists = 0 ,@O_iErrorState = @iAddShippingErrState OUTPUT ,@oErrString = @iAddShippingErrString OUTPUT SELECT @iError = @@error IF ( (@iStatus <> 0) OR (@iAddShippingErrState <> 0) OR (@iError <> 0) ) BEGIN SELECT @oErrString = RTRIM(@oErrString) + ' ' + @iAddShippingErrString SELECT @O_iErrorState = 1750 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END END END SELECT @SHIPTYPE = ISNULL(SHIPTYPE, 10) FROM SY03000(NOLOCK) WHERE SHIPMTHD = @I_vSHIPMTHD IF ( @NewPrint_Phone_NumberGB NOT IN ( 0 ,1 ,2 ,3 ,4 ) ) BEGIN SELECT @O_iErrorState = 11765 EXEC @iStatus = taUpdateString @O_iErrorState ,@iCustomErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF (@NewFRTSCHID <> '') BEGIN IF ( NOT EXISTS ( SELECT 1 FROM TX00102(NOLOCK) WHERE TAXSCHID = @NewFRTSCHID ) ) BEGIN SELECT @O_iErrorState = 1752 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END ELSE BEGIN SELECT @NewFREIGTBLE = 1 END END IF (@NewMSCSCHID <> '') BEGIN IF ( NOT EXISTS ( SELECT 1 FROM TX00102(NOLOCK) WHERE TAXSCHID = @NewMSCSCHID ) ) BEGIN SELECT @O_iErrorState = 1753 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END ELSE BEGIN SELECT @NewMISCTBLE = 1 END END IF (@I_vDEFTAXSCHDS = 1) BEGIN IF ( (@I_vTAXSCHID = '') OR (@I_vTAXSCHID IS NULL) ) BEGIN IF (@VATEnabled = 0) BEGIN SELECT @NewTAXSCHID = TAXSCHID FROM RM00102(NOLOCK) WHERE CUSTNMBR = @ExstCUSTNMBR AND ADRSCODE = @I_vPRSTADCD END ELSE BEGIN IF ( (@USEADVTX = 0) AND ( (@I_vSHIPMTHD IS NOT NULL) OR (@I_vSHIPMTHD <> '') ) ) BEGIN IF ( (@SHIPTYPE = 0) AND (@NewLOCNCODE <> '') AND (@STAXSCHD <> '') ) BEGIN SELECT @NewTAXSCHID = @STAXSCHD END ELSE IF (@SHIPTYPE = 1) BEGIN SELECT @NewTAXSCHID = TAXSCHID FROM RM00102(NOLOCK) WHERE CUSTNMBR = @ExstCUSTNMBR AND ADRSCODE = @I_vPRSTADCD END END ELSE IF (@USEADVTX = 1) BEGIN SELECT @NewTAXSCHID = @TAXSCHID END END END IF ( ( ( (@NewFREIGTBLE = 0) AND (@FRGTTXBL = 1) ) OR (@NewFREIGTBLE = 1) ) AND ( (@I_vFRTSCHID = '') OR (@I_vFRTSCHID IS NULL) ) ) BEGIN SELECT @NewFRTSCHID = @FRTSCHID ,@NewFREIGTBLE = 1 END ELSE BEGIN IF ( ( ( (@NewFREIGTBLE = 0) AND (@FRGTTXBL = 3) ) OR (@NewFREIGTBLE = 3) ) AND ( (@I_vFRTSCHID = '') OR (@I_vFRTSCHID IS NULL) ) ) BEGIN SELECT @NewFRTSCHID = ISNULL(@NewTAXSCHID, '') ,@NewFREIGTBLE = 3 END END IF ( ( ( (@NewMISCTBLE = 0) AND (@MISCTXBL = 1) ) OR (@NewMISCTBLE = 1) ) AND ( (@I_vMSCSCHID = '') OR (@I_vMSCSCHID IS NULL) ) ) BEGIN SELECT @NewMSCSCHID = @MSCSCHID ,@NewMISCTBLE = 1 END ELSE BEGIN IF ( ( ( (@NewMISCTBLE = 0) AND (@MISCTXBL = 3) ) OR (@NewMISCTBLE = 3) ) AND ( (@I_vMSCSCHID = '') OR (@I_vMSCSCHID IS NULL) ) ) BEGIN SELECT @NewMSCSCHID = ISNULL(@NewTAXSCHID, '') ,@NewMISCTBLE = 3 END END END ELSE BEGIN IF ( (@I_vTAXSCHID = '') OR (@I_vTAXSCHID IS NULL) OR (@I_vTAXSCHID = @ExstTAXSCHID) ) BEGIN SET @NewTAXSCHID = @ExstTAXSCHID END ELSE BEGIN SET @NewTAXSCHID = @I_vTAXSCHID END IF ( ( (@I_vFRTSCHID = '') OR @I_vFRTSCHID IS NULL ) OR (@I_vFRTSCHID = @ExstFRTSCHID) ) BEGIN SET @NewFRTSCHID = @ExstFRTSCHID END ELSE BEGIN SET @NewFRTSCHID = @I_vFRTSCHID END IF ( (@I_vMSCSCHID = '') OR (@I_vMSCSCHID IS NULL) OR (@I_vMSCSCHID = @ExstMSCSCHID) ) BEGIN SET @NewMSCSCHID = @ExstMSCSCHID END ELSE BEGIN SET @NewMSCSCHID = @I_vMSCSCHID END END IF (@USEADVTX = 1) BEGIN SELECT @FRGTTXBL = 0 ,@MISCTXBL = 0 ,@NewFRTSCHID = '' ,@NewMSCSCHID = '' END IF (@NewTAXSCHID <> '') BEGIN IF ( NOT EXISTS ( SELECT 1 FROM TX00102(NOLOCK) WHERE TAXSCHID = @NewTAXSCHID ) ) BEGIN SELECT @O_iErrorState = 1751 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END END SELECT @DEPOSITS = ISNULL(SUM(p.OAMNTREM), 0) FROM SOP10103 p(NOLOCK) LEFT OUTER JOIN SY03100 b(NOLOCK) ON p.CARDNAME = b.CARDNAME WHERE p.SOPTYPE = @I_vSOPTYPE AND p.SOPNUMBE = @I_vSOPNUMBE AND ( p.PYMTTYPE IN ( 1 ,2 ,3 ) ) SELECT @PAYMENTS = ISNULL(SUM(p.OAMNTREM), 0) FROM SOP10103 p(NOLOCK) LEFT OUTER JOIN SY03100 b(NOLOCK) ON p.CARDNAME = b.CARDNAME WHERE p.SOPTYPE = @I_vSOPTYPE AND p.SOPNUMBE = @I_vSOPNUMBE AND ( p.PYMTTYPE IN ( 4 ,5 ,6 ) ) IF ( @I_vSOPTYPE IN ( 3 ,6 ) ) BEGIN SELECT @HdrPAYMENTS = ISNULL(SUM(p.OAMTPAID), 0) FROM SOP10103 p(NOLOCK) LEFT OUTER JOIN SY03100 b(NOLOCK) ON p.CARDNAME = b.CARDNAME WHERE p.SOPTYPE = @I_vSOPTYPE AND p.SOPNUMBE = @I_vSOPNUMBE AND ( p.PYMTTYPE IN ( 1 ,2 ,3 ,4 ,5 ,6 ) ) END ELSE BEGIN SELECT @HdrPAYMENTS = @PAYMENTS END IF ( ((@DEPOSITS + @PAYMENTS) <> @NewPYMTRCVD) AND (@I_vPYMTRCVD IS NOT NULL) ) BEGIN SELECT @O_iErrorState = 1189 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF (@I_vSOPTYPE <> 6) BEGIN SELECT @DAYTOEXP = DAYTOEXP FROM SOP40200(NOLOCK) WHERE DOCID = @DOCID AND SOPTYPE = @I_vSOPTYPE END IF (@I_vSOPTYPE = 6) BEGIN SELECT @DAYTOEXP = DAYTOEXP FROM SOP40200(NOLOCK) WHERE DOCID = @DOCID AND SOPTYPE = 3 END IF (@O_iErrorState <> 0) RETURN (@O_iErrorState) SELECT @SOPHdrTbl = RTRIM(DB_NAME()) + '.dbo.SOP10100' SELECT @DexRowID = DEX_ROW_ID FROM SOP10100(NOLOCK) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF ( NOT EXISTS ( SELECT 1 FROM tempdb..DEX_LOCK(NOLOCK) WHERE table_path_name = @SOPHdrTbl AND row_id = @DexRowID AND session_id = @@spid ) ) BEGIN SELECT @mylock = 1 EXEC @iStatus = DYNAMICS..taDEXLOCKS @I_vOperation = 1 ,@I_vtable_path_name = @SOPHdrTbl ,@I_vrow_id = @DexRowID ,@O_oExists = @oExists OUTPUT ,@O_oInsertStatus = @OInsStatus OUTPUT ,@O_iErrorState = @DexLockErrorState OUTPUT SELECT @iError = @@error IF ( (@OInsStatus <> 1) OR (@DexLockErrorState <> 0) OR (@iError <> 0) ) BEGIN IF (@DexLockErrorState <> 0) BEGIN SELECT @oErrString = RTRIM(@oErrString) + ' ' + @DexLockErrorState END SELECT @O_iErrorState = 1754 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END IF ( @I_vSOPTYPE > 0 AND @I_vSOPTYPE < 6 ) BEGIN SELECT @ALLOCABY = ALLOCABY ,@USDOCID1 = USDOCID1 ,@USDOCID2 = USDOCID2 ,@DAYTOEXP = DAYTOEXP ,@QUOTOINV = QUOTOINV ,@QUOTOORD = QUOTOORD ,@INVTOBAC = INVTOBAC ,@BACTOINV = BACTOINV ,@BACTOORD = BACTOORD ,@ORDTOBAC = ORDTOBAC FROM SOP40200 a(NOLOCK) WHERE a.DOCID = @DOCID AND a.SOPTYPE = @I_vSOPTYPE END IF (@I_vSOPTYPE = 6) BEGIN SELECT @ALLOCABY = ALLOCABY ,@USDOCID1 = USDOCID1 ,@USDOCID2 = USDOCID2 ,@DAYTOEXP = DAYTOEXP ,@QUOTOINV = QUOTOINV ,@QUOTOORD = QUOTOORD ,@INVTOBAC = INVTOBAC ,@BACTOINV = BACTOINV ,@BACTOORD = BACTOORD ,@ORDTOBAC = ORDTOBAC FROM SOP40200 a(NOLOCK) WHERE a.DOCID = @DOCID AND a.SOPTYPE = 3 END IF EXISTS ( SELECT TOP 1 1 FROM SOP10200(NOLOCK) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE AND QTYFULFI > 0 ) BEGIN SELECT @ALLOCABY = 1 END IF (@I_vSOPTYPE = 1) BEGIN IF ( ( (@QUOTOORD = 0) AND ( EXISTS ( SELECT 1 FROM SOP10200(NOLOCK) WHERE QTYTORDR > 0 AND SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE AND CMPNTSEQ = 0 ) ) ) AND ( (@QUOTOINV = 0) AND ( EXISTS ( SELECT 1 FROM SOP10200(NOLOCK) WHERE QTYTOINV > 0 AND SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE AND CMPNTSEQ = 0 ) ) ) ) BEGIN SELECT @O_iErrorState = 8163 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END IF (@I_vSOPTYPE = 2) BEGIN IF ( (@ORDTOBAC = 0) AND ( EXISTS ( SELECT 1 FROM SOP10200(NOLOCK) WHERE QTYTBAOR > 0 AND SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE ) ) ) BEGIN SELECT @O_iErrorState = 8164 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END IF ( @I_vSOPTYPE IN ( 3 ,6 ) ) BEGIN IF ( (@INVTOBAC = 0) AND ( EXISTS ( SELECT 1 FROM SOP10200(NOLOCK) WHERE QTYTBAOR > 0 AND SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE ) ) ) BEGIN SELECT @O_iErrorState = 8165 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END IF (@I_vSOPTYPE = 5) BEGIN IF ( ( (@BACTOINV = 0) AND ( EXISTS ( SELECT 1 FROM SOP10200(NOLOCK) WHERE QTYTOINV > 0 AND SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE ) ) ) OR ( (@BACTOORD = 0) AND ( EXISTS ( SELECT 1 FROM SOP10200(NOLOCK) WHERE QTYTORDR > 0 AND SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE ) ) ) ) BEGIN SELECT @O_iErrorState = 8166 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END WHILE (1 = 1) BEGIN SELECT @ExstSUBTOTAL = ROUND(ISNULL(SUM(XTNDPRCE), 0), @DECPLCUR) ,@ExstORSUBTOT = ROUND(ISNULL(SUM(OXTNDPRC), 0), @DECPLUSED) FROM SOP10200(NOLOCK) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF (@I_vTRDISAMT IS NOT NULL) BEGIN SELECT @I_vTRADEPCT = 0 END IF (@I_vTRADEPCT IS NOT NULL) AND (@I_vTRADEPCT <> 0) BEGIN SELECT @I_vTRDISAMT = ROUND(@ExstORSUBTOT * @I_vTRADEPCT / 100.00, @DECPLUSED) END IF (@I_vTRDISAMT IS NULL) AND (@I_vTRADEPCT IS NULL) BEGIN SELECT @I_vTRADEPCT = CAST(CUSTDISC AS NUMERIC(19, 2)) / 100.00 FROM RM00101(NOLOCK) WHERE CUSTNMBR = @ExstCUSTNMBR IF (@I_vTRADEPCT > 0) BEGIN SELECT @I_vTRDISAMT = ROUND(@ExstORSUBTOT * @I_vTRADEPCT / 100.00, @DECPLUSED) END ELSE BEGIN SELECT @I_vTRDISAMT = 0 END END IF (@ExstORSUBTOT <> 0) AND (@I_vTRADEPCT = 0) BEGIN SELECT @TRADEPCT = (@I_vTRDISAMT / @ExstORSUBTOT) * 100 END ELSE BEGIN SELECT @TRADEPCT = @I_vTRADEPCT / 100 END IF (@ExstORSUBTOT <= 0) BEGIN SELECT @I_vTRDISAMT = 0 END IF (@I_vTRDISAMT > @ExstORSUBTOT) AND (@I_vTRDISAMT > 0) BEGIN SELECT @O_iErrorState = 8161 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END IF (@I_vTRDISAMT <> 0) AND (@I_vTRADEPCT = 0) AND (@ExstORSUBTOT > 0) BEGIN UPDATE SOP10200 SET TRDISAMT = ROUND(((OXTNDPRC / @ExstORSUBTOT) * @I_vTRDISAMT), @DECPLUSED) ,ORTDISAM = ROUND(((OXTNDPRC / @ExstORSUBTOT) * @I_vTRDISAMT), @DECPLUSED) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 9237 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END ELSE BEGIN UPDATE SOP10200 SET TRDISAMT = ROUND(((OXTNDPRC) * (@I_vTRADEPCT / 100)), @DECPLUSED) ,ORTDISAM = ROUND(((OXTNDPRC) * (@I_vTRADEPCT / 100)), @DECPLUSED) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 8141 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END IF (@I_vTRDISAMT IS NULL) BEGIN SELECT @I_vTRDISAMT = 0 END SELECT @TRDISAMT = SUM(TRDISAMT) FROM SOP10200(NOLOCK) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE SELECT @TRDISAMTDIF = @I_vTRDISAMT - @TRDISAMT IF (@TRDISAMTDIF <> 0) BEGIN UPDATE b SET TRDISAMT = TRDISAMT + @TRDISAMTDIF ,ORTDISAM = ORTDISAM + @TRDISAMTDIF FROM SOP10200 b ,( SELECT MAX(DEX_ROW_ID) AS Dex FROM SOP10200(NOLOCK) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE ) AS t1 WHERE b.SOPTYPE = @I_vSOPTYPE AND b.SOPNUMBE = @I_vSOPNUMBE AND b.DEX_ROW_ID = t1.Dex IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 5899 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END IF (@ISMCTRX = 1) BEGIN EXEC @iStatus = taMCCurrencyValidate @I_vMASTERID = @ExstCUSTNMBR ,@I_vDOCDATE = @ExstDOCDATE ,@I_vCURNCYID = @ExstCURNCYID ,@I_vEXGTBDSC = @NewEXGTBDSC ,@I_vEXTBLSRC = @NewEXTBLSRC ,@I_vRATEEXPR = @NewRATEEXPR OUTPUT ,@I_vDYSTINCR = @NewDYSTINCR OUTPUT ,@I_vRATEVARC = @NewRATEVARC ,@I_vTRXDTDEF = @NewTRXDTDEF ,@I_vPRVDSLMT = @NewPRVDSLMT ,@I_vDATELMTS = @NewDATELMTS ,@I_vMODULE = 1 ,@I_vEXCHDATE = @NewEXCHDATE OUTPUT ,@I_vTIME1 = @NewTIME1 OUTPUT ,@I_vXCHGRATE = @NewXCHGRATE OUTPUT ,@I_vEXPNDATE = @NewEXPNDATE OUTPUT ,@I_vRATETPID = @NewRATETPID OUTPUT ,@I_vRTCLCMTD = @NewRTCLCMTD OUTPUT ,@I_vEXGTBLID = @ExstEXGTBLID OUTPUT ,@oErrString = @taMCCurrencyValidateErrString OUTPUT ,@O_iErrorState = @taMCCurrencyValidateErrState OUTPUT SELECT @iError = @@error IF ( (@iStatus <> 0) OR (@taMCCurrencyValidateErrState <> 0) OR (@iError <> 0) ) IF (@@error <> 0) BEGIN SELECT @oErrString = RTRIM(@oErrString) + ' ' + @taMCCurrencyValidateErrString SELECT @O_iErrorState = 1760 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END ELSE BEGIN SELECT @ISMCTRX = 0 ,@NewRATEEXPR = 0 ,@NewDYSTINCR = 0 ,@NewRTCLCMTD = - 1 END IF (@NewTIME1 = '') SELECT @NewTIME1 = ' ' + SUBSTRING(CONVERT(VARCHAR(25), GETDATE()), 12, 12) IF (@ISMCTRX = 1) BEGIN IF ( (@NewXCHGRATE IS NOT NULL) OR (@mylock = 0) ) BEGIN IF (@NewRTCLCMTD = 0) BEGIN UPDATE SOP10200 SET XTNDPRCE = CASE WHEN ORUNTPRC = 0 THEN XTNDPRCE ELSE ROUND(OXTNDPRC * @NewXCHGRATE, @DECPLCUR) END ,OXTNDPRC = CASE WHEN ORUNTPRC = 0 THEN ROUND(XTNDPRCE / @NewXCHGRATE, (ODECPLCU - 1)) ELSE OXTNDPRC END ,EXTDCOST = CASE WHEN UNITCOST = 0 THEN ROUND(((ORUNTCST * @NewXCHGRATE) * QUANTITY), @DECPLCUR) ELSE EXTDCOST END ,OREXTCST = CASE WHEN ORUNTCST = 0 THEN ROUND(((ROUND(UNITCOST * QUANTITY, @DECPLCUR) / @NewXCHGRATE)), (ODECPLCU - 1)) ELSE OREXTCST END ,UNITCOST = CASE WHEN UNITCOST = 0 THEN ROUND(ORUNTCST * @NewXCHGRATE, @DECPLCUR) ELSE UNITCOST END ,ORUNTCST = CASE WHEN ORUNTCST = 0 THEN ROUND(UNITCOST / @NewXCHGRATE, (ODECPLCU - 1)) ELSE ORUNTCST END WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 8131 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END ELSE IF (@NewRTCLCMTD = 1) BEGIN UPDATE SOP10200 SET XTNDPRCE = CASE WHEN ORUNTPRC = 0 THEN XTNDPRCE ELSE ROUND(OXTNDPRC / @NewXCHGRATE, @DECPLCUR) END ,OXTNDPRC = CASE WHEN ORUNTPRC = 0 THEN ROUND(XTNDPRCE * @NewXCHGRATE, (ODECPLCU - 1)) ELSE OXTNDPRC END ,EXTDCOST = CASE WHEN UNITCOST = 0 THEN ROUND(((ORUNTCST / @NewXCHGRATE) * QUANTITY), @DECPLCUR) ELSE EXTDCOST END ,OREXTCST = CASE WHEN ORUNTCST = 0 THEN ROUND(((UNITCOST * QUANTITY) * @NewXCHGRATE), (ODECPLCU - 1)) ELSE OREXTCST END ,UNITCOST = CASE WHEN UNITCOST = 0 THEN ROUND(ORUNTCST / @NewXCHGRATE, @DECPLCUR) ELSE UNITCOST END ,ORUNTCST = CASE WHEN ORUNTCST = 0 THEN ROUND(UNITCOST * @NewXCHGRATE, (ODECPLCU - 1)) ELSE ORUNTCST END WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 8132 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END END END IF (@I_vRECREATETAXES = 999) BEGIN SELECT @OldTAXAMNT = @ExstTAXAMNT ,@OldORTAXMNT = @ExstORTAXAMT SELECT @ExstFRTTXAMT = 0 ,@ExstMSCTXAMT = 0 ,@ExstTAXAMNT = 0 ,@ExstBCKTXAMT = 0 ,@ExstBKTFRTAM = 0 ,@ExstBKTMSCAM = 0 EXEC @iStatus = taSopTaxEngine @I_vMSTRTAXSLID = @NewTAXSCHID ,@I_vFREITAXDSLID = @NewFRTSCHID ,@I_vMISCAMTTAXSLID = @NewMSCSCHID ,@I_vDOCTYPE = @I_vSOPTYPE ,@I_vDOCNUMBE = @I_vSOPNUMBE ,@I_vCUSTNMBR = @ExstCUSTNMBR ,@I_vTRADEPCT = @TRADEPCT ,@I_vFRTAMT = @NewFREIGHT ,@I_vMISCAMTAMT = @NewMISCAMNT ,@I_vINVOICETOTAL = @ExstORDOCAMT ,@I_vINVOICETOTTAXABLE = @ExstORDOCAMT ,@I_vDAFRTAMT = @ExstDISCFRGT ,@I_vDAMISCAMT = @DISCMISC ,@I_vSLAMDUNK = @USEADVTX ,@I_vDECIMALPLACES = @DECPLUSED ,@I_vRTCLCMTD = @NewRTCLCMTD ,@I_vXCHGRATE = @NewXCHGRATE ,@I_vVATENABLED = @VATEnabled ,@I_vBACKOSALES = @ExstBCKTXAMT OUTPUT ,@I_vBACKOFREHT = @ExstBKTFRTAM OUTPUT ,@I_vBACKOMISC = @ExstBKTMSCAM OUTPUT ,@I_vRECALC = @RECALC ,@I_vTAXAMNT = @ExstTAXAMNT OUTPUT ,@I_vFUTOTAMT = @FUTOTAMT OUTPUT ,@I_vFRTTXAMT = @ExstFRTTXAMT OUTPUT ,@I_vMSCTXAMT = @ExstMSCTXAMT OUTPUT ,@O_iErrorState = @taSopTaxEngineErrState OUTPUT ,@oErrString = @taSopTaxEngineErrString OUTPUT SELECT @iError = @@error IF ( (@iStatus <> 0) OR (@taSopTaxEngineErrState <> 0) OR (@iError <> 0) ) BEGIN SELECT @oErrString = RTRIM(@oErrString) + ' ' + @taSopTaxEngineErrString SELECT @O_iErrorState = 1758 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END SELECT @ExstTAXAMNT = @ExstTAXAMNT + @ExstFRTTXAMT + @ExstMSCTXAMT ,@ExstORTAXAMT = @ExstTAXAMNT + @ExstFRTTXAMT + @ExstMSCTXAMT SELECT @ExstORDOCAMT = @ExstORDOCAMT + @ExstTAXAMNT - @OldORTAXMNT END --ELSE --BEGIN -- SELECT @TAXAMNTL = ISNULL(SUM(ORSLSTAX + ORFRTTAX + ORMSCTAX), 0.00) -- FROM SOP10105(NOLOCK) -- WHERE SOPTYPE = @I_vSOPTYPE -- AND SOPNUMBE = @I_vSOPNUMBE -- AND LNITMSEQ = 0 -- AND BKOUTTAX = 0 -- IF (@TAXAMNTL <> @ExstORTAXAMT) -- BEGIN -- SELECT @O_iErrorState = 8329 -- EXEC @iStatus = taUpdateString @O_iErrorState -- ,@oErrString -- ,@oErrString OUTPUT -- ,@O_oErrorState OUTPUT -- END --END IF EXISTS ( SELECT 1 FROM SOP10105(NOLOCK) WHERE SOPNUMBE = @I_vSOPNUMBE AND SOPTYPE = @I_vSOPTYPE AND TAXDTLID IN ( SELECT TAXDTLID FROM TX00201(NOLOCK) WHERE ( TXDTQUAL = 3 AND ( TDTABMIN > 0 OR TDTABMAX > 0 ) ) OR ( TDTAXMIN > 0 OR TDTAXMAX > 0 ) ) ) BEGIN SELECT @BSIVCTTL = 1 END IF (@I_vSOPTYPE <> 3) AND (@I_vFREIGHT < 0) BEGIN SELECT @O_iErrorState = 5633 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF (@I_vSOPTYPE <> 3) AND (@I_vMISCAMNT < 0) BEGIN SELECT @O_iErrorState = 5634 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF (@I_vSOPTYPE <> 3) AND (@I_vTRDISAMT < 0) BEGIN SELECT @O_iErrorState = 5635 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF (@I_vSOPTYPE <> 3) AND (@ExstORSUBTOT < 0) AND (@USINGNEGATIVES = 0) BEGIN SELECT @O_iErrorState = 5636 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF (@I_vSOPTYPE <> 3) AND (@ExstORDOCAMT < 0) BEGIN SELECT @O_iErrorState = 5637 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF (@I_vSOPTYPE <> 3) AND (@ExstTAXAMNT < 0) BEGIN SELECT @O_iErrorState = 5638 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF ( @I_vSOPTYPE IN ( 3 ,6 ) ) BEGIN IF (@I_vPYMTRMID IS NULL) BEGIN SELECT @I_vPYMTRMID = @PYMTRMID END SELECT @SALPURCH = SALPURCH ,@DISCNTCB = DISCNTCB ,@FREIGHT = FREIGHT ,@MISC = MISC ,@TAX = TAX FROM SY03300(NOLOCK) WHERE PYMTRMID = @I_vPYMTRMID SELECT @PymtTermAmnt1 = ROUND((@ExstORSUBTOT * @SALPURCH), @DECPLUSED) ,@PymtTermAmnt2 = ROUND((@I_vTRDISAMT * @DISCNTCB), @DECPLUSED) ,@PymtTermAmnt3 = ROUND((@NewFREIGHT * @FREIGHT), @DECPLUSED) ,@PymtTermAmnt4 = ROUND((@NewMISCAMNT * @MISC), @DECPLUSED) ,@PymtTermAmnt5 = ROUND(((@ExstORTAXAMT + @ExstFRTTXAMT + @ExstMSCTXAMT) * @TAX), @DECPLUSED) ,@PymtTermAmnt8 = @PymtTermAmnt1 - @PymtTermAmnt2 + @PymtTermAmnt3 + @PymtTermAmnt4 + @PymtTermAmnt5 IF ( (@I_vPYMTRMID = '') AND (@I_vDISAVAMT IS NULL) AND (@I_vDSCDLRAM IS NULL) AND (@I_vDSCPCTAM IS NULL) ) BEGIN SELECT @I_vDISAVAMT = 0 ,@I_vDSCDLRAM = 0 ,@I_vDSCPCTAM = 0 END IF ( (@I_vDISAVAMT IS NOT NULL) AND ( @I_vDSCDLRAM IS NULL OR @I_vDSCDLRAM <> @I_vDISAVAMT ) ) BEGIN SELECT @I_vDSCDLRAM = 0 END IF ( (@I_vDISAVAMT IS NOT NULL) AND ( @I_vDSCPCTAM IS NULL OR ROUND((@I_vDSCPCTAM / 100) * @PymtTermAmnt8, @DECPLUSED) <> @I_vDISAVAMT ) ) BEGIN SELECT @I_vDSCPCTAM = 0 END IF ( ( @I_vDSCDLRAM IS NOT NULL AND @I_vDSCDLRAM <> 0 ) AND ( @I_vDSCPCTAM IS NOT NULL AND @I_vDSCPCTAM <> 0 ) ) BEGIN SELECT @O_iErrorState = 7029 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF ( (@I_vDSCDLRAM IS NOT NULL) AND (@I_vDISAVAMT IS NULL) ) BEGIN SELECT @I_vDISAVAMT = @I_vDSCDLRAM ,@ORDDLRAT = @I_vDSCDLRAM SELECT @ORDAVAMT = @I_vDISAVAMT ,@I_vDSCPCTAM = 0 END IF ( (@I_vDSCPCTAM IS NOT NULL) AND (@I_vDISAVAMT IS NULL) ) BEGIN SELECT @I_vDISAVAMT = ROUND(((@I_vDSCPCTAM / 100) * @PymtTermAmnt1), @DECPLUSED) SELECT @I_vDISAVAMT = @I_vDISAVAMT - ROUND(((@I_vDSCPCTAM / 100) * @PymtTermAmnt2), @DECPLUSED) SELECT @I_vDISAVAMT = @I_vDISAVAMT + ROUND(((@I_vDSCPCTAM / 100) * @PymtTermAmnt3), @DECPLUSED) SELECT @I_vDISAVAMT = @I_vDISAVAMT + ROUND(((@I_vDSCPCTAM / 100) * @PymtTermAmnt4), @DECPLUSED) SELECT @I_vDISAVAMT = @I_vDISAVAMT + ROUND(((@I_vDSCPCTAM / 100) * @PymtTermAmnt5), @DECPLUSED) SELECT @ORDAVAMT = @I_vDISAVAMT ,@I_vDSCDLRAM = 0 END SELECT @DSCLCTYP = DSCLCTYP ,@DSCDLRAM = DSCDLRAM ,@DSCPCTAM = DSCPCTAM FROM SY03300(NOLOCK) WHERE PYMTRMID = @I_vPYMTRMID IF ( (@I_vPYMTRMID <> '') AND (@I_vDISAVAMT IS NULL) AND (@I_vDSCDLRAM IS NULL) AND (@I_vDSCPCTAM IS NULL) ) BEGIN IF (@DSCLCTYP = 1) BEGIN SELECT @I_vDSCPCTAM = @DSCPCTAM / 100 ,@I_vDSCDLRAM = 0 IF (@ISMCTRX = 1) BEGIN SELECT @ORDAVAMT = ROUND(((@I_vDSCPCTAM / 100) * @PymtTermAmnt1), @DECPLUSED) SELECT @ORDAVAMT = @ORDAVAMT - ROUND(((@I_vDSCPCTAM / 100) * @PymtTermAmnt2), @DECPLUSED) SELECT @ORDAVAMT = @ORDAVAMT + ROUND(((@I_vDSCPCTAM / 100) * @PymtTermAmnt3), @DECPLUSED) SELECT @ORDAVAMT = @ORDAVAMT + ROUND(((@I_vDSCPCTAM / 100) * @PymtTermAmnt4), @DECPLUSED) SELECT @ORDAVAMT = @ORDAVAMT + ROUND(((@I_vDSCPCTAM / 100) * @PymtTermAmnt5), @DECPLUSED) SELECT @ORDDLRAT = 0 SELECT @I_vDISAVAMT = CASE WHEN (@I_vRTCLCMTD = 0) THEN ROUND(@ORDAVAMT * @NewXCHGRATE, @DECPLCUR) WHEN (@I_vRTCLCMTD = 1) THEN ROUND(@ORDAVAMT / @NewXCHGRATE, @DECPLCUR) ELSE 0 END END ELSE BEGIN SELECT @I_vDISAVAMT = ((@I_vDSCPCTAM / 100) * @PymtTermAmnt1) SELECT @I_vDISAVAMT = @I_vDISAVAMT - ((@I_vDSCPCTAM / 100) * @PymtTermAmnt2) SELECT @I_vDISAVAMT = ROUND(@I_vDISAVAMT, @DECPLCUR) SELECT @I_vDISAVAMT = @I_vDISAVAMT + ROUND(((@I_vDSCPCTAM / 100) * @PymtTermAmnt3), @DECPLUSED) SELECT @I_vDISAVAMT = @I_vDISAVAMT + ROUND(((@I_vDSCPCTAM / 100) * @PymtTermAmnt4), @DECPLUSED) SELECT @I_vDISAVAMT = @I_vDISAVAMT + ROUND(((@I_vDSCPCTAM / 100) * @PymtTermAmnt5), @DECPLUSED) SELECT @ORDAVAMT = @I_vDISAVAMT ,@ORDDLRAT = 0 END END ELSE IF (@DSCLCTYP = 2) BEGIN SELECT @I_vDSCPCTAM = 0 IF (@ISMCTRX = 1) BEGIN SELECT @I_vDISAVAMT = @DSCDLRAM ,@I_vDSCDLRAM = @DSCDLRAM SELECT @ORDAVAMT = CASE WHEN (@I_vRTCLCMTD = 0) THEN ROUND(@I_vDISAVAMT / @NewXCHGRATE, @DECPLUSED) WHEN (@I_vRTCLCMTD = 1) THEN ROUND(@I_vDISAVAMT * @NewXCHGRATE, @DECPLUSED) ELSE 0 END SELECT @ORDDLRAT = @ORDAVAMT END ELSE BEGIN SELECT @I_vDSCDLRAM = @DSCDLRAM ,@I_vDISAVAMT = @DSCDLRAM SELECT @ORDDLRAT = @I_vDISAVAMT ,@ORDAVAMT = @I_vDISAVAMT END END END ELSE IF (@ISMCTRX = 1) BEGIN SELECT @ORDAVAMT = @I_vDISAVAMT SELECT @I_vDISAVAMT = CASE WHEN (@I_vRTCLCMTD = 0) THEN ROUND(@ORDAVAMT * @NewXCHGRATE, @DECPLCUR) WHEN (@I_vRTCLCMTD = 1) THEN ROUND(@ORDAVAMT / @NewXCHGRATE, @DECPLCUR) ELSE 0 END SELECT @ORDAVAMT = ROUND(@ORDAVAMT, @DECPLUSED) IF (@I_vDSCPCTAM = 0) BEGIN SELECT @ORDDLRAT = @ORDAVAMT ,@I_vDSCDLRAM = @I_vDISAVAMT END END ELSE BEGIN SELECT @I_vDISAVAMT = ROUND(@I_vDISAVAMT, @DECPLCUR) ,@ORDAVAMT = @I_vDISAVAMT IF (@I_vDSCPCTAM = 0) BEGIN SELECT @I_vDSCDLRAM = @I_vDISAVAMT ,@ORDDLRAT = @I_vDISAVAMT END END END ELSE BEGIN IF (@I_vSOPTYPE = 4) BEGIN SELECT @I_vPYMTRMID = '' ,@I_vDISAVAMT = 0 ,@I_vDSCDLRAM = 0 ,@I_vDSCPCTAM = 0 END ELSE BEGIN IF (@I_vPYMTRMID IS NULL) BEGIN SELECT @I_vPYMTRMID = @PYMTRMID END SELECT @I_vDISAVAMT = 0 SELECT @I_vDSCPCTAM = DSCPCTAM / 100.0 ,@I_vDSCDLRAM = ISNULL(DSCDLRAM, 0) FROM SY03300(NOLOCK) WHERE PYMTRMID = @I_vPYMTRMID SELECT @ORDDLRAT = ISNULL(@I_vDSCDLRAM, 0) SELECT @I_vDSCPCTAM = ISNULL(@I_vDSCPCTAM, 0) ,@I_vDSCDLRAM = ISNULL(@I_vDSCDLRAM, 0) IF (@ISMCTRX = 1) BEGIN SELECT @ORDDLRAT = CASE WHEN (@I_vRTCLCMTD = 0) THEN ROUND(@I_vDSCDLRAM / @I_vXCHGRATE, @DECPLCUR) WHEN (@I_vRTCLCMTD = 1) THEN ROUND(@I_vDSCDLRAM * @I_vXCHGRATE, @DECPLCUR) ELSE 0 END END END END IF (@I_vPYMTRMID <> '') BEGIN IF ( NOT EXISTS ( SELECT 1 FROM SY03300(NOLOCK) WHERE PYMTRMID = @I_vPYMTRMID ) ) BEGIN SELECT @O_iErrorState = 7030 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END IF ( (@I_vSOPTYPE <> 4) AND (@I_vPYMTRMID IS NOT NULL) AND ( ( @I_vDUEDATE = '' OR @I_vDISCDATE = '' ) ) ) BEGIN EXEC @iStatus = taCalcDueDateRM @I_vCUSTNMBR = @ExstCUSTNMBR ,@I_vPYMTRMID = @I_vPYMTRMID ,@I_vDOCDATE = @NewDOCDATE ,@O_dDISCDATE = @dDISCDATE OUTPUT ,@O_dDUEDATE = @dDUEDATE OUTPUT ,@O_iErrorState = @iCalcDueDateErrState OUTPUT ,@oErrString = @iCalcDueDateErrString OUTPUT SELECT @iError = @@error IF ( (@iStatus <> 0) OR (@iCalcDueDateErrState <> 0) OR (@iError <> 0) OR (@dDUEDATE IS NULL) OR (@dDISCDATE IS NULL) ) BEGIN SELECT @oErrString = RTRIM(@oErrString) + ' ' + @iCalcDueDateErrString SELECT @O_iErrorState = 1755 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END IF (@I_vDUEDATE = '') SELECT @I_vDUEDATE = @dDUEDATE IF (@I_vDISCDATE = '') SELECT @I_vDISCDATE = @dDISCDATE END IF (@CPRCSTNM <> '') BEGIN SELECT @NACREDITCHECK = NACREDITCHECK FROM RM00105(NOLOCK) WHERE CPRCSTNM = @CPRCSTNM END IF (@NACREDITCHECK = 1) BEGIN SELECT @CUSTNMBR = @CPRCSTNM END ELSE BEGIN SELECT @CUSTNMBR = @ExstCUSTNMBR END IF (@I_vCKCreditLimit = 1) BEGIN SELECT @CrdChkAmnt = (@I_vFREIGHT - @ExstFRTAMNT) + (@I_vMISCAMNT - @ExstMISCAMNT) + (@ExstTAXAMNT - @OldTAXAMNT) EXEC @iStatus = taCustomerBalance @I_vCUSTNMBR = @CUSTNMBR ,@I_vNewSaleAmt = @CrdChkAmnt ,@O_nOverCreditLimit = @OverCreditLimit OUTPUT ,@O_CRLMTTYP = @CRLMTTYP OUTPUT ,@O_nCurrBalance = @CurrBalance OUTPUT ,@O_nCRLMTAMT = @CRLMTAMT OUTPUT ,@O_CRLMTPER = @CRLMTPER OUTPUT ,@O_nCRLMTPAM = @CRLMTPAM OUTPUT ,@O_nCUSTBLNC = @CUSTBLNC OUTPUT ,@O_nUNPSTDSA = @UNPSTDSA OUTPUT ,@O_nUNPSTOSA = @UNPSTOSA1 OUTPUT ,@O_nONORDAMT = @ONORDAMT OUTPUT ,@O_nUNPSTDCA = @UNPSTDCA OUTPUT ,@O_nUNPSTOCA = @UNPSTOCA1 OUTPUT ,@O_nDEPRECV = @DEPRECV OUTPUT ,@O_iErrorState = @iCustomerBalanceErrState OUTPUT ,@oErrString = @taCustomerBalanceErrString OUTPUT SELECT @iError = @@error IF ( (@iStatus <> 0) OR (@iCustomerBalanceErrState <> 0) OR (@iError <> 0) ) BEGIN SELECT @oErrString = RTRIM(@oErrString) + ' ' + @taCustomerBalanceErrString SELECT @O_iErrorState = 3558 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END IF (@OverCreditLimit = 1) BEGIN SELECT @O_iErrorState = 3559 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END IF (@ISMCTRX = 0) BEGIN SELECT @ORDAVFRT = @ExstDISCFRGT ,@ORDAVMSC = @DISCMISC ,@ORDAVAMT = @I_vDISAVAMT ,@ORDISRTD = CASE WHEN @I_vSOPTYPE = 4 THEN @NewDISCRTND ELSE 0 END ,@ORDISTKN = CASE WHEN @I_vSOPTYPE <> 4 THEN @NewDISTKNAM ELSE 0 END ,@ORTDISAM = @I_vTRDISAMT ,@ORFRTAMT = @NewFREIGHT ,@ORMISCAMT = @NewMISCAMNT ,@ORFRTTAX = @ExstFRTTXAMT ,@ORMSCTAX = @ExstMSCTXAMT ,@ORBKTFRT = @ExstBKTFRTAM ,@ORBKTMSC = @ExstBKTMSCAM ,@OBTAXAMT = @ExstBCKTXAMT ,@ORTAXAMT = @ExstTAXAMNT ,@ORPMTRVD = @NewPYMTRCVD ,@ORPAYMENTS = @PAYMENTS ,@ORDEPOSITS = @DEPOSITS ,@OrHdrPAYMENTS = @HdrPAYMENTS END ELSE BEGIN SELECT @ORDAVFRT = @ExstDISCFRGT ,@ORDAVMSC = @ExstDISCMISC ,@ORDISRTD = CASE WHEN (@I_vDISTKNAM IS NOT NULL) THEN @I_vDISTKNAM ELSE @ExstORDISRTD END ,@ORDISTKN = CASE WHEN (@I_vDISTKNAM IS NOT NULL) THEN @I_vDISTKNAM ELSE @ExstORDISTKN END ,@ORTDISAM = @I_vTRDISAMT ,@ORFRTAMT = CASE WHEN (@I_vFREIGHT IS NOT NULL) THEN @I_vFREIGHT ELSE @ExstORFRTAMT END ,@ORMISCAMT = CASE WHEN (@I_vMISCAMNT IS NOT NULL) THEN @I_vMISCAMNT ELSE @ExstORMISCAMT END ,@ORFRTTAX = CASE WHEN (@I_vRECREATETAXES = 1) THEN @ExstFRTTXAMT ELSE @ExstORFRTTAX END ,@ORMSCTAX = CASE WHEN (@I_vRECREATETAXES = 1) THEN @ExstMSCTXAMT ELSE @ExstORMSCTAX END ,@ORBKTFRT = CASE WHEN (@I_vRECREATETAXES = 1) THEN @ExstBKTFRTAM ELSE @ExstORBKTFRT END ,@ORBKTMSC = CASE WHEN (@I_vRECREATETAXES = 1) THEN @ExstBKTMSCAM ELSE @ExstORBKTMSC END ,@OBTAXAMT = CASE WHEN (@I_vRECREATETAXES = 1) THEN @ExstBCKTXAMT ELSE @ExstOBTAXAMT END ,@ORTAXAMT = CASE WHEN (@I_vRECREATETAXES = 1) THEN @ExstTAXAMNT ELSE @ExstORTAXAMT END ,@ORPMTRVD = @NewPYMTRCVD ,@ORPAYMENTS = @PAYMENTS ,@ORDEPOSITS = @DEPOSITS ,@OrHdrPAYMENTS = @HdrPAYMENTS END SELECT @ExstORDOCAMT = ROUND(ISNULL(SUM(OXTNDPRC), 0) + @ORFRTAMT + @ORMISCAMT + @ORTAXAMT - @ORTDISAM, @DECPLUSED) FROM SOP10200(NOLOCK) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF (@I_vDISAVAMT > @ExstORDOCAMT) AND (@ExstORDOCAMT >= 0) BEGIN SELECT @O_iErrorState = 1737 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END IF (@NewDISTKNAM > @ExstORDOCAMT) AND (@ExstORDOCAMT >= 0) BEGIN SELECT @O_iErrorState = 7123 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END IF (@I_vRECREATECOMM = 1) BEGIN DELETE SOP10101 WHERE SOPNUMBE = @I_vSOPNUMBE AND SOPTYPE = @I_vSOPTYPE IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 1756 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END EXEC @iStatus = taSopCalcCommissions @I_vSOPTYPE = @I_vSOPTYPE ,@I_vSOPNUMBE = @I_vSOPNUMBE ,@I_vCOMPRCNT = @I_vCOMPRCNT ,@I_vDOCAMNT = @ExstORDOCAMT ,@I_vCUSTNMBR = @ExstCUSTNMBR ,@I_vCURNCYID = @ExstCURNCYID ,@O_iErrorState = @O_iCommErrorState OUTPUT ,@oErrString = @sCommErrString OUTPUT SELECT @iError = @@error IF ( (@iStatus <> 0) OR (@O_iCommErrorState <> 0) OR (@iError <> 0) ) BEGIN SELECT @oErrString = RTRIM(@oErrString) + ' ' + @sCommErrString SELECT @O_iErrorState = 1757 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END SELECT DISTINCT @SLPR = SLPRSNID FROM SOP10101(NOLOCK) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF (@@rowcount > 1) SELECT @COMAPPTO = 0 ELSE SELECT @COMAPPTO = ISNULL(COMAPPTO, 0) FROM RM00301(NOLOCK) WHERE SLPRSNID IN ( SELECT DISTINCT (SLPRSNID) FROM SOP10101(NOLOCK) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE ) UPDATE SOP10200 SET SLPRSNID = '' ,SALSTERR = '' WHERE SLPRSNID <> '' AND SALSTERR <> '' AND SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE AND SLPRSNID + SALSTERR NOT IN ( SELECT SLPRSNID + SALSTERR FROM SOP10101 WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE ) IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 8122 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END SELECT @BackoutTradeDisc = ISNULL(SUM(BackoutTradeDisc), 0) ,@OrigBackoutTradeDisc = ISNULL(SUM(OrigBackoutTradeDisc), 0) FROM SOP10200(NOLOCK) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF (@ISMCTRX = 1) BEGIN IF (@NewXCHGRATE = 0) BEGIN SELECT @O_iErrorState = 1762 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END IF (@NewRTCLCMTD = 0) BEGIN SELECT @I_vDISAVAMT = ROUND(@ORDAVAMT * @NewXCHGRATE, @DECPLCUR) ,@NewFREIGHT = ROUND(@ORFRTAMT * @NewXCHGRATE, @DECPLCUR) ,@NewMISCAMNT = ROUND(@ORMISCAMT * @NewXCHGRATE, @DECPLCUR) ,@I_vTRDISAMT = ROUND(@ORTDISAM * @NewXCHGRATE, @DECPLCUR) ,@NewDISCRTND = ROUND(@ORDISRTD * @NewXCHGRATE, @DECPLCUR) ,@NewDISTKNAM = ROUND(@ORDISTKN * @NewXCHGRATE, @DECPLCUR) ,@I_vDSCDLRAM = ROUND(@ORDDLRAT * @NewXCHGRATE, @DECPLCUR) ,@ExstDISCFRGT = ROUND(@ORDAVFRT * @NewXCHGRATE, @DECPLCUR) ,@ExstDISCMISC = ROUND(@ORDAVMSC * @NewXCHGRATE, @DECPLCUR) ,@NewPYMTRCVD = ROUND(@NewPYMTRCVD * @NewXCHGRATE, @DECPLCUR) ,@PAYMENTS = ROUND(@PAYMENTS * @NewXCHGRATE, @DECPLCUR) ,@DEPOSITS = ROUND(@DEPOSITS * @NewXCHGRATE, @DECPLCUR) ,@OrHdrPAYMENTS = ROUND(@HdrPAYMENTS * @NewXCHGRATE, @DECPLCUR) ,@ExstFRTTXAMT = ROUND(@ORFRTTAX * @NewXCHGRATE, @DECPLCUR) ,@ExstMSCTXAMT = ROUND(@ORMSCTAX * @NewXCHGRATE, @DECPLCUR) ,@ExstTAXAMNT = ROUND(@ORTAXAMT * @NewXCHGRATE, @DECPLCUR) ,@ExstBCKTXAMT = ROUND(@OBTAXAMT * @NewXCHGRATE, @DECPLCUR) ,@ExstBKTFRTAM = ROUND(@ORBKTFRT * @NewXCHGRATE, @DECPLCUR) ,@ExstBKTMSCAM = ROUND(@ORBKTMSC * @NewXCHGRATE, @DECPLCUR) ,@NewDOCAMNT = ROUND(@ExstORDOCAMT * @NewXCHGRATE, @DECPLCUR) ,@I_vCHGAMNT = CASE WHEN @STOP = 0 THEN ROUND(@I_vCHGAMNT * @NewXCHGRATE, @DECPLCUR) ELSE @I_vCHGAMNT END END ELSE IF (@NewRTCLCMTD = 1) BEGIN SELECT @I_vDISAVAMT = ROUND(@ORDAVAMT / @NewXCHGRATE, @DECPLCUR) ,@NewFREIGHT = ROUND(@ORFRTAMT / @NewXCHGRATE, @DECPLCUR) ,@NewMISCAMNT = ROUND(@ORMISCAMT / @NewXCHGRATE, @DECPLCUR) ,@I_vTRDISAMT = ROUND(@ORTDISAM / @NewXCHGRATE, @DECPLCUR) ,@NewDISCRTND = ROUND(@ORDISRTD / @NewXCHGRATE, @DECPLCUR) ,@NewDISTKNAM = ROUND(@ORDISTKN / @NewXCHGRATE, @DECPLCUR) ,@I_vDSCDLRAM = ROUND(@ORDDLRAT / @NewXCHGRATE, @DECPLCUR) ,@ExstDISCFRGT = ROUND(@ORDAVFRT / @NewXCHGRATE, @DECPLCUR) ,@ExstDISCMISC = ROUND(@ORDAVMSC / @NewXCHGRATE, @DECPLCUR) ,@NewPYMTRCVD = ROUND(@NewPYMTRCVD / @NewXCHGRATE, @DECPLCUR) ,@PAYMENTS = ROUND(@PAYMENTS / @NewXCHGRATE, @DECPLCUR) ,@DEPOSITS = ROUND(@DEPOSITS / @NewXCHGRATE, @DECPLCUR) ,@OrHdrPAYMENTS = ROUND(@HdrPAYMENTS / @NewXCHGRATE, @DECPLCUR) ,@ExstFRTTXAMT = ROUND(@ORFRTTAX / @NewXCHGRATE, @DECPLCUR) ,@ExstMSCTXAMT = ROUND(@ORMSCTAX / @NewXCHGRATE, @DECPLCUR) ,@ExstTAXAMNT = ROUND(@ORTAXAMT / @NewXCHGRATE, @DECPLCUR) ,@ExstBCKTXAMT = ROUND(@OBTAXAMT / @NewXCHGRATE, @DECPLCUR) ,@ExstBKTFRTAM = ROUND(@ORBKTFRT / @NewXCHGRATE, @DECPLCUR) ,@ExstBKTMSCAM = ROUND(@ORBKTMSC / @NewXCHGRATE, @DECPLCUR) ,@NewDOCAMNT = ROUND(@ExstORDOCAMT / @NewXCHGRATE, @DECPLCUR) ,@I_vCHGAMNT = CASE WHEN @STOP = 0 THEN ROUND(@I_vCHGAMNT / @NewXCHGRATE, @DECPLCUR) ELSE @I_vCHGAMNT END END IF ( (@NewXCHGRATE IS NOT NULL) OR (@mylock = 0) ) BEGIN IF (@NewRTCLCMTD = 0) BEGIN UPDATE SOP10103 SET AMNTREMA = ROUND(OAMNTREM * @NewXCHGRATE, @DECPLCUR) ,AMNTPAID = ROUND(OAMTPAID * @NewXCHGRATE, @DECPLCUR) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 1763 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END UPDATE SOP10200 SET UNITPRCE = CASE WHEN ORUNTPRC = 0 THEN ROUND(ROUND(UNITPRCE / @NewXCHGRATE, (ODECPLCU - 1)) * @NewXCHGRATE, (DECPLCUR - 1)) ELSE ROUND(ORUNTPRC * @NewXCHGRATE, (DECPLCUR - 1)) END ,ORUNTPRC = CASE WHEN ORUNTPRC = 0 THEN ROUND(UNITPRCE / @NewXCHGRATE, (ODECPLCU - 1)) ELSE ORUNTPRC END ,MRKDNAMT = ROUND(ORMRKDAM * @NewXCHGRATE, @DECPLCUR) ,XTNDPRCE = CASE WHEN ORUNTPRC = 0 THEN XTNDPRCE ELSE ROUND(OXTNDPRC * @NewXCHGRATE, @DECPLCUR) END ,OXTNDPRC = CASE WHEN ORUNTPRC = 0 THEN ROUND(XTNDPRCE / @NewXCHGRATE, (ODECPLCU - 1)) ELSE OXTNDPRC END ,REMPRICE = CASE WHEN ORUNTPRC = 0 THEN REMPRICE ELSE ROUND((ROUND((QUANTITY - QTYCANCE) * ORUNTPRC, @DECPLUSED) * @NewXCHGRATE), @DECPLCUR) END ,OREPRICE = CASE WHEN ORUNTPRC = 0 THEN ROUND(REMPRICE / @NewXCHGRATE, (ODECPLCU - 1)) ELSE OREPRICE END ,BKTSLSAM = ROUND(ORBKTSLS * @NewXCHGRATE, @DECPLCUR) ,TAXAMNT = ROUND(ORTAXAMT * @NewXCHGRATE, @DECPLCUR) ,TXBTXAMT = ROUND(OTAXTAMT * @NewXCHGRATE, @DECPLCUR) ,TRDISAMT = ROUND(ORTDISAM * @NewXCHGRATE, @DECPLCUR) ,DISCSALE = ROUND(ORDAVSLS * @NewXCHGRATE, @DECPLCUR) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 1764 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END UPDATE SOP10105 SET STAXAMNT = ROUND(ORSLSTAX * @NewXCHGRATE, @DECPLCUR) ,FRTTXAMT = ROUND(ORFRTTAX * @NewXCHGRATE, @DECPLCUR) ,MSCTXAMT = ROUND(ORMSCTAX * @NewXCHGRATE, @DECPLCUR) ,TAXDTSLS = ROUND(ORTOTSLS * @NewXCHGRATE, @DECPLCUR) ,TDTTXSLS = ROUND(ORTXSLS * @NewXCHGRATE, @DECPLCUR) ,TXDTOTTX = ROUND(OTTAXPON * @NewXCHGRATE, @DECPLCUR) ,CURRNIDX = @ExstCURRNIDX WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 1765 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END UPDATE SOP10102 SET DEBITAMT = ROUND(ORDBTAMT * @NewXCHGRATE, @DECPLCUR) ,CRDTAMNT = ROUND(ORCRDAMT * @NewXCHGRATE, @DECPLCUR) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 1746 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END UPDATE SOP10101 SET COMMAMNT = ROUND(OCOMMAMT * @NewXCHGRATE, @DECPLCUR) ,ACTSLAMT = ROUND(ORSLSAMT * @NewXCHGRATE, @DECPLCUR) ,CMMSLAMT = ROUND(ORCOSAMT * @NewXCHGRATE, @DECPLCUR) ,NCOMAMNT = ROUND(ORNCMAMT * @NewXCHGRATE, @DECPLCUR) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE AND SLPRSNID <> '' IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 1766 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END ELSE IF (@NewRTCLCMTD = 1) BEGIN UPDATE SOP10103 SET AMNTREMA = ROUND(OAMNTREM / @NewXCHGRATE, @DECPLCUR) ,AMNTPAID = ROUND(OAMTPAID / @NewXCHGRATE, @DECPLCUR) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 1767 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END UPDATE SOP10200 SET UNITPRCE = CASE WHEN ORUNTPRC = 0 THEN ROUND(ROUND(UNITPRCE * @NewXCHGRATE, (ODECPLCU - 1)) / @NewXCHGRATE, (DECPLCUR - 1)) ELSE ROUND(ORUNTPRC / @NewXCHGRATE, (DECPLCUR - 1)) END ,ORUNTPRC = CASE WHEN ORUNTPRC = 0 THEN ROUND(UNITPRCE * @NewXCHGRATE, (ODECPLCU - 1)) ELSE ORUNTPRC END ,MRKDNAMT = ROUND(ORMRKDAM / @NewXCHGRATE, @DECPLCUR) ,XTNDPRCE = CASE WHEN ORUNTPRC = 0 THEN XTNDPRCE ELSE ROUND(OXTNDPRC / @NewXCHGRATE, @DECPLCUR) END ,OXTNDPRC = CASE WHEN ORUNTPRC = 0 THEN ROUND(XTNDPRCE * @NewXCHGRATE, (ODECPLCU - 1)) ELSE OXTNDPRC END ,REMPRICE = CASE WHEN ORUNTPRC = 0 THEN REMPRICE ELSE ROUND((ROUND((QUANTITY - QTYCANCE) * ORUNTPRC, @DECPLUSED) / @NewXCHGRATE), @DECPLCUR) END ,OREPRICE = CASE WHEN ORUNTPRC = 0 THEN ROUND(REMPRICE * @NewXCHGRATE, (ODECPLCU - 1)) ELSE OREPRICE END ,BKTSLSAM = ROUND(ORBKTSLS / @NewXCHGRATE, @DECPLCUR) ,TAXAMNT = ROUND(ORTAXAMT / @NewXCHGRATE, @DECPLCUR) ,TXBTXAMT = ROUND(OTAXTAMT / @NewXCHGRATE, @DECPLCUR) ,TRDISAMT = ROUND(ORTDISAM / @NewXCHGRATE, @DECPLCUR) ,DISCSALE = ROUND(ORDAVSLS / @NewXCHGRATE, @DECPLCUR) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 1768 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END UPDATE SOP10105 SET STAXAMNT = ROUND(ORSLSTAX / @NewXCHGRATE, @DECPLCUR) ,FRTTXAMT = ROUND(ORFRTTAX / @NewXCHGRATE, @DECPLCUR) ,MSCTXAMT = ROUND(ORMSCTAX / @NewXCHGRATE, @DECPLCUR) ,TAXDTSLS = ROUND(ORTOTSLS / @NewXCHGRATE, @DECPLCUR) ,TDTTXSLS = ROUND(ORTXSLS / @NewXCHGRATE, @DECPLCUR) ,TXDTOTTX = ROUND(OTTAXPON / @NewXCHGRATE, @DECPLCUR) ,CURRNIDX = @ExstCURRNIDX WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 1769 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END UPDATE SOP10102 SET DEBITAMT = ROUND(ORDBTAMT / @NewXCHGRATE, @DECPLCUR) ,CRDTAMNT = ROUND(ORCRDAMT / @NewXCHGRATE, @DECPLCUR) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 1770 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END UPDATE SOP10101 SET COMMAMNT = ROUND(OCOMMAMT / @NewXCHGRATE, @DECPLCUR) ,ACTSLAMT = ROUND(ORSLSAMT / @NewXCHGRATE, @DECPLCUR) ,CMMSLAMT = ROUND(ORCOSAMT / @NewXCHGRATE, @DECPLCUR) ,NCOMAMNT = ROUND(ORNCMAMT / @NewXCHGRATE, @DECPLCUR) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 1771 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END END IF (@I_vSOPTYPE = 2) BEGIN UPDATE g SET g.CURRNIDX = @ExstCURRNIDX ,g.CURNCYID = @ExstCURNCYID ,g.RATETPID = @NewRATETPID ,g.XCHGRATE = @NewXCHGRATE ,g.EXGTBLID = @ExstEXGTBLID ,g.TIME1 = @NewTIME1 ,g.RTCLCMTD = @NewRTCLCMTD ,g.EXCHDATE = @NewEXCHDATE FROM SOP10103 p(NOLOCK) ,GL10000 g WHERE p.SOPTYPE = @I_vSOPTYPE AND p.SOPNUMBE = @I_vSOPNUMBE AND g.BCHSOURC = 'GL_Normal' AND g.BACHNUMB = p.TRXSORCE AND ( g.ORTRXSRC = p.TRXSORCE AND g.DTAControlNum = @I_vSOPNUMBE AND g.DTATRXType = @I_vSOPTYPE ) IF @@error <> 0 BEGIN SELECT @O_iErrorState = 5376 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END IF (@NewRTCLCMTD = 0) BEGIN UPDATE g SET g.DECPLACS = @DECPLCUR ,g.XCHGRATE = @NewXCHGRATE ,g.RATETPID = @NewRATETPID ,g.EXCHDATE = @NewEXCHDATE ,g.EXGTBLID = @ExstEXGTBLID ,g.TIME1 = @NewTIME1 ,g.RTCLCMTD = @NewRTCLCMTD ,g.CURRNIDX = @CURRNIDXFun ,g.CRDTAMNT = ROUND(ORCRDAMT * @NewXCHGRATE, @DECPLCUR) ,g.DEBITAMT = ROUND(ORDBTAMT * @NewXCHGRATE, @DECPLCUR) FROM SOP10103 p(NOLOCK) ,GL10000 h(NOLOCK) ,GL10001 g WHERE p.SOPTYPE = @I_vSOPTYPE AND p.SOPNUMBE = @I_vSOPNUMBE AND h.BCHSOURC = 'GL_Normal' AND h.BACHNUMB = p.TRXSORCE AND ( h.ORTRXSRC = p.TRXSORCE AND h.DTAControlNum = @I_vSOPNUMBE AND h.DTATRXType = @I_vSOPTYPE AND g.JRNENTRY = h.JRNENTRY AND g.BACHNUMB = p.TRXSORCE ) END ELSE IF (@NewRTCLCMTD = 1) BEGIN UPDATE g SET g.DECPLACS = @DECPLCUR ,g.XCHGRATE = @NewXCHGRATE ,g.RATETPID = @NewRATETPID ,g.EXCHDATE = @NewEXCHDATE ,g.EXGTBLID = @ExstEXGTBLID ,g.TIME1 = @NewTIME1 ,g.RTCLCMTD = @NewRTCLCMTD ,g.CURRNIDX = @CURRNIDXFun ,g.CRDTAMNT = ROUND(ORCRDAMT / @NewXCHGRATE, @DECPLCUR) ,g.DEBITAMT = ROUND(ORDBTAMT / @NewXCHGRATE, @DECPLCUR) FROM SOP10103 p(NOLOCK) ,GL10000 h(NOLOCK) ,GL10001 g WHERE p.SOPTYPE = @I_vSOPTYPE AND p.SOPNUMBE = @I_vSOPNUMBE AND h.BCHSOURC = 'GL_Normal' AND h.BACHNUMB = p.TRXSORCE AND ( h.ORTRXSRC = p.TRXSORCE AND h.DTAControlNum = @I_vSOPNUMBE AND h.DTATRXType = @I_vSOPTYPE AND g.JRNENTRY = h.JRNENTRY AND g.BACHNUMB = p.TRXSORCE ) END IF @@error <> 0 BEGIN SELECT @O_iErrorState = 5375 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END IF (@NewRTCLCMTD = 0) BEGIN UPDATE c SET c.CURRNIDX = @ExstCURRNIDX ,c.CURNCYID = @ExstCURNCYID ,c.DECPLCUR = @DECPLCUR ,c.Checkbook_Amount = ROUND(ORIGAMT * c.XCHGRATE, @DECPLCUR) ,c.RCPTAMT = ROUND(ORIGAMT * @NewXCHGRATE, @DECPLCUR) ,c.RCVGRATETPID = @NewRATETPID ,c.TIME1 = @NewTIME1 ,c.EXCHDATE = @NewEXCHDATE ,c.EXGTBLID = @ExstEXGTBLID ,c.XCHGRATE = c.XCHGRATE FROM CM20300 c ,CM20100 ch(NOLOCK) ,SOP10103 p(NOLOCK) WHERE p.SOPTYPE = @I_vSOPTYPE AND p.SOPNUMBE = @I_vSOPNUMBE AND p.TRXSORCE = ch.AUDITTRAIL AND ch.RecNumControl = c.CMRECNUM END ELSE IF (@NewRTCLCMTD = 1) BEGIN UPDATE c SET c.CURRNIDX = @ExstCURRNIDX ,c.CURNCYID = @ExstCURNCYID ,c.DECPLCUR = @DECPLCUR ,c.Checkbook_Amount = ROUND(ORIGAMT / c.XCHGRATE, @DECPLCUR) ,c.RCPTAMT = ROUND(ORIGAMT / @NewXCHGRATE, @DECPLCUR) ,c.RCVGRATETPID = @NewRATETPID ,c.TIME1 = @NewTIME1 ,c.EXCHDATE = @NewEXCHDATE ,c.EXGTBLID = @ExstEXGTBLID ,c.XCHGRATE = c.XCHGRATE FROM CM20300 c ,CM20100 ch(NOLOCK) ,SOP10103 p(NOLOCK) WHERE p.SOPTYPE = @I_vSOPTYPE AND p.SOPNUMBE = @I_vSOPNUMBE AND p.TRXSORCE = ch.AUDITTRAIL AND ch.RecNumControl = c.CMRECNUM END IF @@error <> 0 BEGIN SELECT @O_iErrorState = 5378 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END IF (@NewRTCLCMTD = 0) BEGIN UPDATE s SET s.CURRNIDX = @ExstCURRNIDX ,s.CURNCYID = @ExstCURNCYID ,s.AMNTPAID = ROUND(s.OAMTPAID * @NewXCHGRATE, @DECPLCUR) ,s.RATETPID = @NewRATETPID ,s.RTCLCMTD = @NewRTCLCMTD ,s.EXCHDATE = @NewEXCHDATE ,s.EXGTBLID = @ExstEXGTBLID ,s.XCHGRATE = @NewXCHGRATE FROM SOP30201 s ,SOP10103 p(NOLOCK) WHERE p.SOPTYPE = @I_vSOPTYPE AND p.SOPNUMBE = @I_vSOPNUMBE AND p.TRXSORCE = s.TRXSORCE END ELSE IF (@NewRTCLCMTD = 1) BEGIN UPDATE s SET s.CURRNIDX = @ExstCURRNIDX ,s.CURNCYID = @ExstCURNCYID ,s.AMNTPAID = ROUND(s.OAMTPAID / @NewXCHGRATE, @DECPLCUR) ,s.RATETPID = @NewRATETPID ,s.RTCLCMTD = @NewRTCLCMTD ,s.EXCHDATE = @NewEXCHDATE ,s.EXGTBLID = @ExstEXGTBLID ,s.XCHGRATE = @NewXCHGRATE FROM SOP30201 s ,SOP10103 p(NOLOCK) WHERE p.SOPTYPE = @I_vSOPTYPE AND p.SOPNUMBE = @I_vSOPNUMBE AND p.TRXSORCE = s.TRXSORCE END IF @@error <> 0 BEGIN SELECT @O_iErrorState = 5377 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END END SELECT @COMMAMNT = ROUND(ISNULL(SUM(COMMAMNT), 0), @DECPLCUR) ,@CMMSLAMT = ROUND(ISNULL(SUM(CMMSLAMT), 0), @DECPLCUR) ,@NCOMAMNT = ROUND(ISNULL(SUM(NCOMAMNT), 0), @DECPLCUR) ,@OCOMMAMT = ROUND(ISNULL(SUM(OCOMMAMT), 0), @DECPLUSED) ,@ORCOSAMT = ROUND(ISNULL(SUM(ORCOSAMT), 0), @DECPLUSED) ,@ORNCMAMT = ROUND(ISNULL(SUM(ORNCMAMT), 0), @DECPLUSED) FROM SOP10101(NOLOCK) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF (@I_vSOPTYPE = 4) BEGIN SELECT @EXTDCOST = ROUND(ISNULL(SUM(EXTDCOST), 0), @DECPLCUR) ,@OREXTCST = ROUND(ISNULL(SUM(OREXTCST), 0), @DECPLUSED) FROM SOP10200 a(NOLOCK) ,IV00101 b(NOLOCK) WHERE a.SOPTYPE = 4 AND a.SOPNUMBE = @I_vSOPNUMBE AND a.ITEMNMBR = b.ITEMNMBR AND b.ITEMTYPE <> 5 END SELECT @TXBTXAMT = ROUND(ISNULL(SUM(TXBTXAMT), 0), @DECPLCUR) ,@OTAXTAMT = ROUND(ISNULL(SUM(OTAXTAMT), 0), @DECPLUSED) ,@ORSUBTOT = ROUND(ISNULL(SUM(OXTNDPRC), 0), @DECPLUSED) ,@MRKDNAMT = CASE WHEN @I_vSOPTYPE IN ( 1 ,2 ,4 ,5 ) THEN ISNULL(SUM(ROUND((MRKDNAMT * QUANTITY), @DECPLCUR)), 0) ELSE ISNULL(SUM(ROUND((MRKDNAMT * (QUANTITY - QTYCANCE)), @DECPLCUR)), 0) END ,@ORMRKDAM = CASE WHEN @I_vSOPTYPE IN ( 1 ,2 ,4 ,5 ) THEN ISNULL(SUM(ROUND((ORMRKDAM * QUANTITY), @DECPLUSED)), 0) ELSE ISNULL(SUM(ROUND((ORMRKDAM * (QUANTITY - QTYCANCE)), @DECPLUSED)), 0) END ,@NewDOCAMNT = CASE WHEN @ISMCTRX = 0 THEN ROUND(ISNULL(SUM(XTNDPRCE), 0) + @NewFREIGHT + @NewMISCAMNT + @ExstTAXAMNT - @I_vTRDISAMT, @DECPLCUR) ELSE @NewDOCAMNT END FROM SOP10200(NOLOCK) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE SELECT @ORREMSUBTO = ISNULL(SUM(ROUND(((ORUNTPRC - ORMRKDAM) * (QUANTITY - QTYCANCE - QTYPRBAC - QTYPRBOO - QTYPRINV - QTYPRORD)), @DECPLUSED)), 0) FROM SOP10200(NOLOCK) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF ( (@I_vSOPTYPE = 4) AND (@NewPYMTRCVD > @ExstORDOCAMT) ) BEGIN SELECT @O_iErrorState = 4613 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END IF (@ISMCTRX = 1) BEGIN IF (@NewRTCLCMTD = 0) BEGIN SELECT @ExstREMSUBTO = ROUND(@ORREMSUBTO * @NewXCHGRATE, @DECPLCUR) ,@ExstSUBTOTAL = ROUND(@ORSUBTOT * @NewXCHGRATE, @DECPLCUR) END ELSE BEGIN SELECT @ExstREMSUBTO = ROUND(@ORREMSUBTO / @NewXCHGRATE, @DECPLCUR) ,@ExstSUBTOTAL = ROUND(@ORSUBTOT / @NewXCHGRATE, @DECPLCUR) END END ELSE BEGIN SELECT @ExstREMSUBTO = @ORREMSUBTO END SELECT @ORACTAMT = @ExstORDOCAMT - @ORPAYMENTS - @ORDEPOSITS - @ORDISTKN - @ORDISRTD IF (@ISMCTRX = 1) BEGIN IF (@NewRTCLCMTD = 0) BEGIN SELECT @ACCTAMNT = ROUND(@ORACTAMT * @NewXCHGRATE, @DECPLCUR) END ELSE BEGIN SELECT @ACCTAMNT = ROUND(@ORACTAMT / @NewXCHGRATE, @DECPLCUR) END END ELSE BEGIN SELECT @ACCTAMNT = @ORACTAMT END IF ( @I_vSOPTYPE IN ( 3 ,6 ) ) BEGIN SELECT @UNPSTOSA = (@NewDOCAMNT - @ExstDOCAMNT) UPDATE RM00103 SET UNPSTOSA = UNPSTOSA + @UNPSTOSA FROM RM00103(UPDLOCK) WHERE CUSTNMBR = @ExstCUSTNMBR IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 1772 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END ELSE BEGIN IF (@I_vSOPTYPE = 4) BEGIN SELECT @UNPSTOSA = (@NewDOCAMNT - @ExstDOCAMNT) * - 1 UPDATE RM00103 SET UNPSTOSA = UNPSTOSA + @UNPSTOSA FROM RM00103(UPDLOCK) WHERE CUSTNMBR = @ExstCUSTNMBR IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 1773 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END ELSE BEGIN IF (@I_vSOPTYPE = 2) BEGIN IF (@STOP = 0) AND (@I_vRECALCBTCHTOT <> 6) BEGIN SELECT @I_vCHGAMNT = @I_vCHGAMNT - @ExstSUBTOTAL END IF (@STOP = 1) BEGIN SELECT @I_vCHGAMNT = @I_vCHGAMNT - ( SELECT XTNDPRCE FROM SOP10200(NOLOCK) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE AND LNITMSEQ = CAST(@I_vUSRDEFND1 AS INT) AND CMPNTSEQ = 0 ) END IF (@stoprecalc = 0) BEGIN UPDATE RM00103 SET ONORDAMT = ONORDAMT - @I_vCHGAMNT FROM RM00103(UPDLOCK) WHERE CUSTNMBR = @ExstCUSTNMBR IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 2619 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END IF (@recalcdeposits = 1) BEGIN UPDATE RM00103 SET DEPRECV = DEPRECV + @DEPOSITS FROM RM00103(UPDLOCK) WHERE CUSTNMBR = @ExstCUSTNMBR IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 8135 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END END END END UPDATE c SET c.Checkbook_Amount = CASE WHEN m.CURNCYID = c.CURNCYID THEN c.ORIGAMT WHEN m.CURNCYID <> c.CURNCYID AND c.CURNCYID = @FUNLCURR AND m.CURNCYID <> '' THEN 0 ELSE c.Checkbook_Amount END FROM CM20300 c ,CM20100 ch WITH (NOLOCK INDEX = AK3CM20100) ,SOP10103 p(NOLOCK) ,CM00100 m WHERE p.SOPTYPE = @I_vSOPTYPE AND p.SOPNUMBE = @I_vSOPNUMBE AND p.TRXSORCE = ch.AUDITTRAIL AND ch.RecNumControl = c.CMRECNUM AND ch.CHEKBKID = m.CHEKBKID IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 5440 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END SELECT @FUFILDAT = ISNULL(MAX(FUFILDAT), '') ,@ACTLSHIP = ISNULL(MAX(ACTLSHIP), '') FROM SOP10200(NOLOCK) WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF ( (@I_vPYMTRMID <> '') AND (@I_vSOPTYPE = 3) AND ( (@I_vDISAVAMT IS NOT NULL) OR (@I_vDSCDLRAM IS NOT NULL) OR (@I_vDSCPCTAM IS NOT NULL) ) ) BEGIN IF ( (@I_vDSCDLRAM <> @DSCDLRAM) OR (@I_vDSCPCTAM <> @DSCPCTAM / 100) ) BEGIN SELECT @I_vPYMTRMID = '' END END IF ( ( (@I_vCOMMNTID = '') OR (@I_vCOMMNTID IS NULL) ) AND ( @I_vCMMTTEXT <> '' OR @I_vCOMMENT_1 <> '' OR @I_vCOMMENT_2 <> '' OR @I_vCOMMENT_3 <> '' OR @I_vCOMMENT_4 <> '' ) ) BEGIN SELECT @Flags = 2 END IF ( (@I_vSOPTYPE = 1) OR (@I_vSOPTYPE = 2) OR (@I_vSOPTYPE = 3) OR (@I_vSOPTYPE = 6) ) BEGIN SELECT @WORKFLOWENABLED = WORKFLOWENABLED FROM DYNAMICS..SY01500 WHERE INTERID = DB_NAME() IF (@I_vSOPTYPE = 1) BEGIN IF (@WORKFLOWENABLED = 1) BEGIN IF ( EXISTS ( SELECT 1 FROM SOP10100 WHERE WorkflowApprStatusQuote = 4 AND SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE ) ) BEGIN SELECT @O_iErrorState = 9004 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END ELSE BEGIN SELECT @WorkflowApprStatusQuote = 1 ,@WorkflowPriorityQuote = 2 END END ELSE BEGIN SELECT @WorkflowApprStatusQuote = 9 ,@WorkflowPriorityQuote = 2 END END ELSE BEGIN IF (@WORKFLOWENABLED = 1) BEGIN IF ( EXISTS ( SELECT 1 FROM SOP10100 WHERE WorkflowApprStatCreditLm = 4 AND SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE ) ) BEGIN SELECT @O_iErrorState = 9005 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END ELSE BEGIN SELECT @WorkflowApprStatCreditLm = 1 ,@WorkflowPriorityCreditLm = 2 END END ELSE BEGIN SELECT @WorkflowApprStatCreditLm = 9 ,@WorkflowPriorityCreditLm = 2 END END END UPDATE SOP10100 SET DOCDATE = @NewDOCDATE ,QUOTEDAT = CASE WHEN ( (@I_vDOCDATE IS NOT NULL) AND (@I_vSOPTYPE = 1) ) THEN @I_vDOCDATE WHEN ( (@I_vSOPTYPE <> 1) AND (@ORIGTYPE <> 1) AND ( (@I_vQUOTEDAT = '') OR (@I_vQUOTEDAT IS NULL) ) ) THEN @dtDEFAULT WHEN ( (@I_vSOPTYPE <> 1) AND ( (@I_vQUOTEDAT <> '') OR (@I_vQUOTEDAT IS NOT NULL) ) ) THEN @I_vQUOTEDAT ELSE @ExstQUOTEDAT END ,QUOEXPDA = CASE WHEN ( (@I_vQUOEXPDA IS NOT NULL) AND (@I_vQUOEXPDA = '') AND (@I_vSOPTYPE = 1) ) THEN @I_vDOCDATE + @DAYTOEXP WHEN ( (@I_vQUOEXPDA <> '') AND (@I_vQUOEXPDA IS NOT NULL) ) THEN @I_vQUOEXPDA ELSE @ExstQUOEXPDA END ,ORDRDATE = CASE WHEN ( (@I_vDOCDATE IS NOT NULL) AND (@I_vSOPTYPE = 2) ) THEN @I_vDOCDATE WHEN ( (@I_vSOPTYPE <> 2) AND ( (@I_vORDRDATE = '') OR (@I_vORDRDATE IS NULL) ) ) THEN @dtDEFAULT WHEN ( (@I_vSOPTYPE <> 2) AND ( (@I_vORDRDATE <> '') OR (@I_vORDRDATE IS NOT NULL) ) ) THEN @I_vORDRDATE ELSE @ExstORDRDATE END ,INVODATE = CASE WHEN ( (@I_vDOCDATE IS NOT NULL) AND ( @I_vSOPTYPE IN ( 3 ,6 ) ) ) THEN @I_vDOCDATE WHEN ( ( @I_vSOPTYPE NOT IN ( 3 ,6 ) ) AND ( (@I_vINVODATE = '') OR (@I_vINVODATE IS NULL) ) ) THEN @dtDEFAULT WHEN ( ( @I_vSOPTYPE NOT IN ( 3 ,6 ) ) AND ( (@I_vINVODATE <> '') OR (@I_vINVODATE IS NOT NULL) ) ) THEN @I_vINVODATE ELSE @ExstINVODATE END ,BACKDATE = CASE WHEN ( (@I_vDOCDATE IS NOT NULL) AND (@I_vSOPTYPE = 5) ) THEN @I_vDOCDATE WHEN ( (@I_vSOPTYPE <> 5) AND ( (@I_vBACKDATE = '') OR (@I_vBACKDATE IS NULL) ) ) THEN @dtDEFAULT WHEN ( (@I_vSOPTYPE <> 5) AND ( (@I_vBACKDATE <> '') OR (@I_vBACKDATE IS NOT NULL) ) ) THEN @I_vBACKDATE ELSE @ExstBACKDATE END ,RETUDATE = CASE WHEN ( (@I_vDOCDATE IS NOT NULL) AND (@I_vSOPTYPE = 4) ) THEN @I_vDOCDATE WHEN ( (@I_vSOPTYPE <> 4) AND ( (@I_vRETUDATE = '') OR (@I_vRETUDATE IS NULL) ) ) THEN @dtDEFAULT WHEN ( (@I_vSOPTYPE <> 4) AND ( (@I_vRETUDATE <> '') OR (@I_vRETUDATE IS NOT NULL) ) ) THEN @I_vRETUDATE ELSE @ExstRETUDATE END ,ReqShipDate = CASE WHEN ( (@I_vSOPTYPE = 1) AND (@I_vReqShipDate = '') ) THEN @dtDEFAULT WHEN ( (@I_vSOPTYPE <> 1) AND (@I_vReqShipDate = '') AND (@I_vDOCDATE IS NOT NULL) ) THEN @I_vDOCDATE WHEN ( (@I_vReqShipDate <> '') AND (@I_vReqShipDate IS NOT NULL) ) THEN @I_vReqShipDate ELSE @ExstReqShipDate END ,FUFILDAT = @FUFILDAT ,ACTLSHIP = @ACTLSHIP ,DISCDATE = CASE WHEN ( ( @I_vSOPTYPE IN ( 3 ,6 ) ) AND (@I_vPYMTRMID IS NOT NULL) ) THEN @I_vDISCDATE ELSE @ExstDISCDATE END ,DUEDATE = CASE WHEN ( ( @I_vSOPTYPE IN ( 3 ,6 ) ) AND (@I_vPYMTRMID IS NOT NULL) ) THEN @I_vDUEDATE ELSE @ExstDUEDATE END ,DISCFRGT = @ExstDISCFRGT ,ORDAVFRT = @ORDAVFRT ,DISCMISC = @ExstDISCMISC ,ORDAVMSC = @ORDAVMSC ,DISAVAMT = @I_vDISAVAMT ,ORDAVAMT = @ORDAVAMT ,DISCRTND = CASE WHEN (@I_vSOPTYPE = 4) THEN @NewDISCRTND ELSE 0 END ,ORDISRTD = CASE WHEN (@I_vSOPTYPE = 4) THEN @ORDISRTD ELSE 0 END ,DISTKNAM = @NewDISTKNAM ,ORDISTKN = @ORDISTKN ,DSCDLRAM = @I_vDSCDLRAM ,ORDDLRAT = @ORDDLRAT ,PYMTRMID = @I_vPYMTRMID ,PRCLEVEL = @NewPRCLEVEL ,LOCNCODE = @NewLOCNCODE ,BACHNUMB = CASE WHEN (@I_vBACHNUMB IS NOT NULL) THEN @I_vBACHNUMB ELSE @ExstBACHNUMB END ,CUSTNAME = @NewCUSTNAME ,CSTPONBR = @NewCSTPONBR ,MRKDNAMT = @MRKDNAMT ,ORMRKDAM = @ORMRKDAM ,PRBTADCD = @NewPRBTADCD ,PRSTADCD = @I_vPRSTADCD ,CNTCPRSN = CASE WHEN (@I_vCNTCPRSN IS NOT NULL) THEN @I_vCNTCPRSN ELSE @ExstCNTCPRSN END ,ShipToName = @NewShipToName ,ADDRESS1 = CASE WHEN (@I_vADDRESS1 IS NOT NULL) THEN @I_vADDRESS1 ELSE @ExstADDRESS1 END ,ADDRESS2 = CASE WHEN (@I_vADDRESS2 IS NOT NULL) THEN @I_vADDRESS2 ELSE @ExstADDRESS2 END ,ADDRESS3 = CASE WHEN (@I_vADDRESS3 IS NOT NULL) THEN @I_vADDRESS3 ELSE @ExstADDRESS3 END ,CITY = CASE WHEN (@I_vCITY IS NOT NULL) THEN @I_vCITY ELSE @ExstCITY END ,STATE = CASE WHEN (@I_vSTATE IS NOT NULL) THEN @I_vSTATE ELSE @ExstSTATE END ,ZIPCODE = CASE WHEN (@I_vZIPCODE IS NOT NULL) THEN @I_vZIPCODE ELSE @ExstZIPCODE END ,COUNTRY = CASE WHEN (@I_vCOUNTRY IS NOT NULL) THEN @I_vCOUNTRY ELSE @ExstCOUNTRY END ,PHNUMBR1 = CASE WHEN (@I_vPHNUMBR1 IS NOT NULL) THEN @I_vPHNUMBR1 ELSE @ExstPHNUMBR1 END ,PHNUMBR2 = CASE WHEN (@I_vPHNUMBR2 IS NOT NULL) THEN @I_vPHNUMBR2 ELSE @ExstPHNUMBR2 END ,PHONE3 = CASE WHEN (@I_vPHNUMBR3 IS NOT NULL) THEN @I_vPHNUMBR3 ELSE @ExstPHONE3 END ,FAXNUMBR = CASE WHEN (@I_vFAXNUMBR IS NOT NULL) THEN @I_vFAXNUMBR ELSE @ExstFAXNUMBR END ,COMAPPTO = CASE WHEN (@I_vRECREATECOMM = 1) THEN @COMAPPTO ELSE @ExstCOMAPPTO END ,COMMAMNT = @COMMAMNT ,OCOMMAMT = @OCOMMAMT ,CMMSLAMT = @CMMSLAMT ,ORCOSAMT = @ORCOSAMT ,NCOMAMNT = @NCOMAMNT ,ORNCMAMT = @ORNCMAMT ,SHIPMTHD = CASE WHEN (@I_vSHIPMTHD IS NOT NULL) THEN @I_vSHIPMTHD ELSE @ExstSHIPMTHD END ,TRDISAMT = @I_vTRDISAMT ,ORTDISAM = @ORTDISAM ,TRDISPCT = CAST(@I_vTRADEPCT * 100 AS INT) ,SUBTOTAL = @ExstSUBTOTAL ,ORSUBTOT = @ORSUBTOT ,REMSUBTO = @ExstREMSUBTO ,OREMSUBT = @ORREMSUBTO ,EXTDCOST = @EXTDCOST ,OREXTCST = @OREXTCST ,FRTAMNT = @NewFREIGHT ,ORFRTAMT = @ORFRTAMT ,MISCAMNT = @NewMISCAMNT ,ORMISCAMT = @ORMISCAMT ,TAXSCHID = @NewTAXSCHID ,BSIVCTTL = @BSIVCTTL ,FRTSCHID = @NewFRTSCHID ,FRTTXAMT = @ExstFRTTXAMT ,ORFRTTAX = @ORFRTTAX ,FRGTTXBL = @NewFREIGTBLE ,MSCSCHID = @NewMSCSCHID ,MSCTXAMT = @ExstMSCTXAMT ,ORMSCTAX = @ORMSCTAX ,MISCTXBL = @NewMISCTBLE ,BKTFRTAM = @ExstBKTFRTAM ,ORBKTFRT = @ORBKTFRT ,BKTMSCAM = @ExstBKTMSCAM ,ORBKTMSC = @ORBKTMSC ,BCKTXAMT = @ExstBCKTXAMT ,OBTAXAMT = @OBTAXAMT ,TXBTXAMT = @TXBTXAMT ,OTAXTAMT = @OTAXTAMT ,TAXAMNT = @ExstTAXAMNT ,ORTAXAMT = @ORTAXAMT ,DOCAMNT = @NewDOCAMNT ,ORDOCAMT = @ExstORDOCAMT ,PYMTRCVD = @OrHdrPAYMENTS ,ORPMTRVD = @HdrPAYMENTS ,DEPRECVD = @DEPOSITS ,ORDEPRVD = @ORDEPOSITS ,ACCTAMNT = @ACCTAMNT ,ORACTAMT = @ORACTAMT ,SALSTERR = @I_vSALSTERR ,SLPRSNID = @I_vSLPRSNID ,UPSZONE = @I_vUPSZONE ,ALLOCABY = @ALLOCABY ,RATETPID = @NewRATETPID ,EXGTBLID = @ExstEXGTBLID ,XCHGRATE = @NewXCHGRATE ,EXCHDATE = @NewEXCHDATE ,RTCLCMTD = CASE WHEN @ISMCTRX = 1 THEN @NewRTCLCMTD ELSE 0 END ,COMMNTID = CASE WHEN (@I_vCOMMNTID IS NOT NULL) THEN @I_vCOMMNTID ELSE @ExstCOMMNTID END ,REFRENCE = CASE WHEN (@I_vREFRENCE IS NOT NULL) THEN @I_vREFRENCE ELSE @ExstREFRENCE END ,MODIFDT = CONVERT(VARCHAR(12), GETDATE()) ,BackoutTradeDisc = @BackoutTradeDisc ,OrigBackoutTradeDisc = @OrigBackoutTradeDisc ,GPSFOINTEGRATIONID = CASE WHEN (@I_vGPSFOINTEGRATIONID IS NOT NULL) THEN @I_vGPSFOINTEGRATIONID ELSE @ExstGPSFOINTEGRATIONID END ,INTEGRATIONSOURCE = CASE WHEN (@I_vINTEGRATIONSOURCE IS NOT NULL) THEN @I_vINTEGRATIONSOURCE ELSE @ExstINTEGRATIONSOURCE END ,INTEGRATIONID = CASE WHEN (@I_vINTEGRATIONID IS NOT NULL) THEN @I_vINTEGRATIONID ELSE @ExstINTEGRATIONID END ,DSCPCTAM = @I_vDSCPCTAM * 100 ,TAXEXMT1 = @I_vTAXEXMT1 ,TAXEXMT2 = @I_vTAXEXMT2 ,TXRGNNUM = @I_vTXRGNNUM ,REPTING = @NewREPTING ,TRXFREQU = @NewTRXFREQU ,TIMETREP = @NewTIMETREP ,DYSTINCR = @NewQUOTEDYSTINCR ,Flags = CASE WHEN @Flags = 0 THEN @ExstFlags ELSE @Flags END ,WorkflowApprStatusQuote = @WorkflowApprStatusQuote ,WorkflowPriorityQuote = @WorkflowPriorityQuote ,WorkflowApprStatCreditLm = @WorkflowApprStatCreditLm ,WorkflowPriorityCreditLm = @WorkflowPriorityCreditLm ,Print_Phone_NumberGB = @NewPrint_Phone_NumberGB WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 1778 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END IF ( (@I_vBACHNUMB IS NOT NULL) AND (@I_vBACHNUMB <> '') AND (@I_vBACHNUMB <> @ExstBACHNUMB) ) BEGIN SELECT @ExstDOCAMNTNeg = (@ExstDOCAMNT * - 1) EXEC @iStatus = taCreateUpdateBatchHeaderRcd @I_vBACHNUMB = @ExstBACHNUMB ,@I_vSERIES = 3 ,@I_vGLPOSTDT = '' ,@I_vBCHSOURC = 'Sales Entry' ,@I_vDOCAMT = @ExstDOCAMNTNeg ,@I_vORIGIN = 1 ,@I_vNUMOFTRX = - 1 ,@I_vCHEKBKID = '' ,@O_iErrorState = @iUpdtBthErrState OUTPUT ,@oErrString = @iCreateBatchErrString OUTPUT SELECT @iError = @@error IF ( (@iStatus <> 0) OR (@iUpdtBthErrState <> 0) OR (@iError <> 0) ) BEGIN SELECT @oErrString = RTRIM(@oErrString) + ' ' + @iCreateBatchErrString SELECT @O_iErrorState = 1775 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END SELECT @BatchCHEKBKID = ISNULL(@I_vBatchCHEKBKID, '') EXEC @iStatus = taCreateUpdateBatchHeaderRcd @I_vBACHNUMB = @I_vBACHNUMB ,@I_vSERIES = 3 ,@I_vGLPOSTDT = @NewDOCDATE ,@I_vBCHSOURC = 'Sales Entry' ,@I_vDOCAMT = @NewDOCAMNT ,@I_vORIGIN = 1 ,@I_vNUMOFTRX = 1 ,@I_vCHEKBKID = @BatchCHEKBKID ,@O_iErrorState = @iUpdtBthErrState OUTPUT ,@oErrString = @iCreateBatchErrString OUTPUT SELECT @iError = @@error IF ( (@iStatus <> 0) OR (@iUpdtBthErrState <> 0) OR (@iError <> 0) ) BEGIN SELECT @oErrString = RTRIM(@oErrString) + ' ' + @iCreateBatchErrString SELECT @O_iErrorState = 1776 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END SELECT @ExstBACHNUMB = @I_vBACHNUMB END SELECT @BACHNUMBSUM = SUM(DOCAMNT) FROM SOP10100(NOLOCK) WHERE BCHSOURC = 'Sales Entry' AND BACHNUMB = @ExstBACHNUMB SELECT @lock = BACHNUMB FROM SY00500(UPDLOCK) WHERE BCHSOURC = 'Sales Entry' AND BACHNUMB = @ExstBACHNUMB UPDATE SY00500 SET BCHTOTAL = @BACHNUMBSUM FROM SY00500(UPDLOCK) WHERE BCHSOURC = 'Sales Entry' AND BACHNUMB = @ExstBACHNUMB IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 1777 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END IF EXISTS ( SELECT 1 FROM SOP10106(NOLOCK) WHERE ( USRDAT01 <> '' OR USRDAT02 <> '' OR USRTAB01 <> '' OR USRTAB09 <> '' OR USRTAB03 <> '' OR USERDEF1 <> '' OR USERDEF2 <> '' OR USRDEF03 <> '' OR USRDEF04 <> '' OR USRDEF05 <> '' ) AND ( SOPNUMBE = @I_vSOPNUMBE AND SOPTYPE = @I_vSOPTYPE ) ) BEGIN SELECT @USERDEFEXISTS = 1 END IF ( @I_vCOMMNTID = '' AND @USERDEFEXISTS = 0 AND @I_vCOMMENT_1 = '' AND @I_vCOMMENT_2 = '' AND @I_vCOMMENT_3 = '' AND @I_vCOMMENT_4 = '' ) BEGIN DELETE SOP10106 WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 8150 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END IF ( (@I_vCOMMNTID IS NOT NULL) AND (@I_vCOMMNTID <> '') ) BEGIN IF ( ( (@I_vCMMTTEXT IS NULL) AND (@I_vCOMMENT_1 IS NULL) AND (@I_vCOMMENT_2 IS NULL) AND (@I_vCOMMENT_3 IS NULL) AND (@I_vCOMMENT_4 IS NULL) ) OR ( (@I_vCMMTTEXT = '') AND (@I_vCOMMENT_1 = '') AND (@I_vCOMMENT_2 = '') AND (@I_vCOMMENT_3 = '') AND (@I_vCOMMENT_4 = '') ) ) BEGIN IF ( EXISTS ( SELECT 1 FROM SY04200(NOLOCK) WHERE COMMNTID = @I_vCOMMNTID ) ) BEGIN SELECT @I_vCMMTTEXT = CMMTTEXT FROM SY04200(NOLOCK) WHERE COMMNTID = @I_vCOMMNTID EXEC @iStatus = taParseCommentText @I_vCMMTTEXT = @I_vCMMTTEXT ,@O_COMMENT_1 = @I_vCOMMENT_1 OUTPUT ,@O_COMMENT_2 = @I_vCOMMENT_2 OUTPUT ,@O_COMMENT_3 = @I_vCOMMENT_3 OUTPUT ,@O_COMMENT_4 = @I_vCOMMENT_4 OUTPUT SELECT @iError = @@error IF ( (@iStatus <> 0) OR (@iError <> 0) ) BEGIN SELECT @O_iErrorState = 2281 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END SELECT @I_vCOMMENT_1 = CASE WHEN @I_vCOMMENT_1 IS NULL THEN '' ELSE @I_vCOMMENT_1 END ,@I_vCOMMENT_2 = CASE WHEN @I_vCOMMENT_2 IS NULL THEN '' ELSE @I_vCOMMENT_2 END ,@I_vCOMMENT_3 = CASE WHEN @I_vCOMMENT_3 IS NULL THEN '' ELSE @I_vCOMMENT_3 END ,@I_vCOMMENT_4 = CASE WHEN @I_vCOMMENT_4 IS NULL THEN '' ELSE @I_vCOMMENT_4 END IF NOT EXISTS ( SELECT 1 FROM SOP10106 WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE ) BEGIN INSERT SOP10106 ( SOPTYPE ,SOPNUMBE ,USRDAT01 ,USRDAT02 ,USRTAB01 ,USRTAB09 ,USRTAB03 ,USERDEF1 ,USERDEF2 ,USRDEF03 ,USRDEF04 ,USRDEF05 ,COMMENT_1 ,COMMENT_2 ,COMMENT_3 ,COMMENT_4 ,CMMTTEXT ) SELECT @I_vSOPTYPE ,@I_vSOPNUMBE ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,@I_vCOMMENT_1 ,@I_vCOMMENT_2 ,@I_vCOMMENT_3 ,@I_vCOMMENT_4 ,@I_vCMMTTEXT END ELSE BEGIN UPDATE SOP10106 SET COMMENT_1 = @I_vCOMMENT_1 ,COMMENT_2 = @I_vCOMMENT_2 ,COMMENT_3 = @I_vCOMMENT_3 ,COMMENT_4 = @I_vCOMMENT_4 ,CMMTTEXT = @I_vCMMTTEXT WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE END IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 1780 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END ELSE BEGIN IF ( (@I_vCMMTTEXT = '') OR (@I_vCMMTTEXT IS NULL) ) BEGIN SELECT @I_vCMMTTEXT = RTRIM(ISNULL(@I_vCOMMENT_1, '')) + CHAR(13) + RTRIM(ISNULL(@I_vCOMMENT_2, '')) + CHAR(13) + RTRIM(ISNULL(@I_vCOMMENT_3, '')) + CHAR(13) + RTRIM(ISNULL(@I_vCOMMENT_4, '')) END EXEC @iStatus = taCreateCommentMaster 3 ,@I_vCOMMNTID ,@I_vCMMTTEXT ,@O_iErrorState = @O_iCommentMstErrState OUTPUT SELECT @iError = @@error IF ( (@iStatus <> 0) OR (@O_iCommentMstErrState <> 0) OR (@iError <> 0) ) BEGIN SELECT @oErrString = RTRIM(@oErrString) + ' ' + @O_iCommentMstErrState SELECT @O_iErrorState = 1781 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END END ELSE BEGIN IF ( (@I_vCMMTTEXT <> '') AND (@I_vCMMTTEXT IS NOT NULL) ) BEGIN EXEC @iStatus = taParseCommentText @I_vCMMTTEXT = @I_vCMMTTEXT ,@O_COMMENT_1 = @I_vCOMMENT_1 OUTPUT ,@O_COMMENT_2 = @I_vCOMMENT_2 OUTPUT ,@O_COMMENT_3 = @I_vCOMMENT_3 OUTPUT ,@O_COMMENT_4 = @I_vCOMMENT_4 OUTPUT SELECT @iError = @@error IF ( (@iStatus <> 0) OR (@iError <> 0) ) BEGIN SELECT @O_iErrorState = 2282 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END END ELSE BEGIN SELECT @I_vCMMTTEXT = RTRIM(ISNULL(@I_vCOMMENT_1, '')) + CHAR(13) + RTRIM(ISNULL(@I_vCOMMENT_2, '')) + CHAR(13) + RTRIM(ISNULL(@I_vCOMMENT_3, '')) + CHAR(13) + RTRIM(ISNULL(@I_vCOMMENT_4, '')) END IF NOT EXISTS ( SELECT 1 FROM SOP10106 WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE ) BEGIN INSERT SOP10106 ( SOPTYPE ,SOPNUMBE ,USRDAT01 ,USRDAT02 ,USRTAB01 ,USRTAB09 ,USRTAB03 ,USERDEF1 ,USERDEF2 ,USRDEF03 ,USRDEF04 ,USRDEF05 ,COMMENT_1 ,COMMENT_2 ,COMMENT_3 ,COMMENT_4 ,CMMTTEXT ) SELECT @I_vSOPTYPE ,@I_vSOPNUMBE ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,@I_vCOMMENT_1 ,@I_vCOMMENT_2 ,@I_vCOMMENT_3 ,@I_vCOMMENT_4 ,@I_vCMMTTEXT END ELSE BEGIN UPDATE SOP10106 SET COMMENT_1 = @I_vCOMMENT_1 ,COMMENT_2 = @I_vCOMMENT_2 ,COMMENT_3 = @I_vCOMMENT_3 ,COMMENT_4 = @I_vCOMMENT_4 ,CMMTTEXT = @I_vCMMTTEXT WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE END IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 1782 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END EXEC @iStatus = taCreateCommentMaster 3 ,@I_vCOMMNTID ,@I_vCMMTTEXT ,@O_iErrorState = @O_iCommentMstErrState OUTPUT SELECT @iError = @@error IF ( (@iStatus <> 0) OR (@O_iCommentMstErrState <> 0) OR (@iError <> 0) ) BEGIN SELECT @oErrString = RTRIM(@oErrString) + ' ' + @O_iCommentMstErrState SELECT @O_iErrorState = 3655 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END END ELSE BEGIN IF ( ( (@I_vCMMTTEXT IS NOT NULL) OR (@I_vCOMMENT_1 IS NOT NULL) OR (@I_vCOMMENT_2 IS NOT NULL) OR (@I_vCOMMENT_3 IS NOT NULL) OR (@I_vCOMMENT_4 IS NOT NULL) ) AND ( (@I_vCMMTTEXT <> '') OR (@I_vCOMMENT_1 <> '') OR (@I_vCOMMENT_2 <> '') OR (@I_vCOMMENT_3 <> '') OR (@I_vCOMMENT_4 <> '') ) ) BEGIN IF ( (@I_vCMMTTEXT <> '') AND (@I_vCMMTTEXT IS NOT NULL) ) BEGIN EXEC @iStatus = taParseCommentText @I_vCMMTTEXT = @I_vCMMTTEXT ,@O_COMMENT_1 = @I_vCOMMENT_1 OUTPUT ,@O_COMMENT_2 = @I_vCOMMENT_2 OUTPUT ,@O_COMMENT_3 = @I_vCOMMENT_3 OUTPUT ,@O_COMMENT_4 = @I_vCOMMENT_4 OUTPUT SELECT @iError = @@error IF ( (@iStatus <> 0) OR (@iError <> 0) ) BEGIN SELECT @O_iErrorState = 2283 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END END ELSE BEGIN SELECT @I_vCMMTTEXT = RTRIM(ISNULL(@I_vCOMMENT_1, '')) + CHAR(13) + RTRIM(ISNULL(@I_vCOMMENT_2, '')) + CHAR(13) + RTRIM(ISNULL(@I_vCOMMENT_3, '')) + CHAR(13) + RTRIM(ISNULL(@I_vCOMMENT_4, '')) END IF NOT EXISTS ( SELECT 1 FROM SOP10106 WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE ) BEGIN INSERT SOP10106 ( SOPTYPE ,SOPNUMBE ,USRDAT01 ,USRDAT02 ,USRTAB01 ,USRTAB09 ,USRTAB03 ,USERDEF1 ,USERDEF2 ,USRDEF03 ,USRDEF04 ,USRDEF05 ,COMMENT_1 ,COMMENT_2 ,COMMENT_3 ,COMMENT_4 ,CMMTTEXT ) SELECT @I_vSOPTYPE ,@I_vSOPNUMBE ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,@I_vCOMMENT_1 ,@I_vCOMMENT_2 ,@I_vCOMMENT_3 ,@I_vCOMMENT_4 ,@I_vCMMTTEXT END ELSE BEGIN UPDATE SOP10106 SET COMMENT_1 = @I_vCOMMENT_1 ,COMMENT_2 = @I_vCOMMENT_2 ,COMMENT_3 = @I_vCOMMENT_3 ,COMMENT_4 = @I_vCOMMENT_4 ,CMMTTEXT = @I_vCMMTTEXT WHERE SOPTYPE = @I_vSOPTYPE AND SOPNUMBE = @I_vSOPNUMBE END IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 1783 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END END IF (@I_vNOTETEXT IS NULL) BEGIN IF (@NOTEINDX <> 0) BEGIN IF ( EXISTS ( SELECT TOP 1 1 FROM SY03900(NOLOCK) WHERE NOTEINDX = @NOTEINDX ) ) BEGIN SELECT @I_vNOTETEXT = TXTFIELD FROM SY03900(NOLOCK) WHERE NOTEINDX = @NOTEINDX END ELSE BEGIN SELECT @I_vNOTETEXT = '' END END ELSE BEGIN SELECT @I_vNOTETEXT = '' END END IF (@I_vNOTETEXT = '') BEGIN DELETE SY03900 WHERE NOTEINDX = @NOTEINDX IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 5871 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END ELSE BEGIN IF (@NOTEINDX = 0) BEGIN EXEC @iStatus = DYNAMICS..tasmGetNextNoteIndex @I_sCompanyID = @sCompanyID ,@I_iSQLSessionID = 0 ,@I_noteincrement = 1 ,@O_mNoteIndex = @NOTEINDX OUTPUT ,@O_iErrorState = @iGetNextNoteIdxErrState OUTPUT SELECT @iError = @@error IF ( (@iStatus <> 0) OR (@iGetNextNoteIdxErrState <> 0) OR (@iError <> 0) ) BEGIN SELECT @oErrString = RTRIM(@oErrString) + ' ' + @iGetNextNoteIdxErrState SELECT @O_iErrorState = 8155 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END IF ( NOT EXISTS ( SELECT 1 FROM SY03900(NOLOCK) WHERE NOTEINDX = @NOTEINDX ) ) BEGIN INSERT SY03900 ( NOTEINDX ,DATE1 ,TIME1 ,TXTFIELD ) SELECT @NOTEINDX ,CONVERT(VARCHAR(12), GETDATE()) ,SUBSTRING(CONVERT(VARCHAR(25), GETDATE()), 12, 12) ,@I_vNOTETEXT IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 8156 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END ELSE BEGIN UPDATE SY03900 SET DATE1 = CONVERT(VARCHAR(12), GETDATE()) ,TIME1 = SUBSTRING(CONVERT(VARCHAR(25), GETDATE()), 12, 12) ,TXTFIELD = @I_vNOTETEXT WHERE NOTEINDX = @NOTEINDX IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 9244 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END END IF (@I_vRECREATEDIST = 1) BEGIN DELETE SOP10102 WHERE SOPNUMBE = @I_vSOPNUMBE AND SOPTYPE = @I_vSOPTYPE IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 1784 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END SELECT @DTAREF = RTRIM(@I_vSOPNUMBE) + SPACE(20 - LEN(@I_vSOPNUMBE)) + CAST(@I_vSOPTYPE AS CHAR(1)) IF ( EXISTS ( SELECT 1 FROM DTA10100(NOLOCK) WHERE DTASERIES = 11 AND DTAREF = @DTAREF ) ) BEGIN DELETE DTA10100 WHERE DTASERIES = 11 AND DTAREF = @DTAREF IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 3621 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END IF ( EXISTS ( SELECT 1 FROM DTA10200(NOLOCK) WHERE DTASERIES = 11 AND DTAREF = @DTAREF ) ) BEGIN DELETE DTA10200 WHERE DTASERIES = 11 AND DTAREF = @DTAREF IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 3622 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END END EXEC @iStatus = taCreateSOPDistributions @I_vSOPTYPE = @I_vSOPTYPE ,@I_vSOPNUMBE = @I_vSOPNUMBE ,@I_vCUSTNMBR = @ExstCUSTNMBR ,@I_vCURRNIDX = @ExstCURRNIDX ,@I_vORDOCAMT = @ExstORDOCAMT ,@I_vORACTAMT = @ORACTAMT ,@I_vORMISCAMT = @ORMISCAMT ,@I_vORFRTAMT = @ORFRTAMT ,@I_vORDISTKN = @ORDISTKN ,@I_vORDAVAMT = @ORDAVAMT ,@I_vORDISRTD = @ORDISRTD ,@I_vCURNCYID = @ExstCURNCYID ,@I_vCMPANYID = @CMPANYID ,@I_vINTERID = @INTERID ,@I_vRTCLCMTD = @NewRTCLCMTD ,@I_vXCHGRATE = @NewXCHGRATE ,@I_vTIME1 = @NewTIME1 ,@I_vRATETPID = @NewRATETPID ,@I_vEXGTBLID = @ExstEXGTBLID ,@I_vEXCHDATE = @NewEXCHDATE ,@I_vTRXSORCE = '' ,@I_vCREATEDIST = @I_vRECREATEDIST ,@I_vDECPLCUR = @DECPLCUR ,@I_vORDECPLCUR = @DECPLUSED ,@I_vFNDECPLCUR = @DECPLCUR ,@O_iErrorState = @taCreateSOPDistributionsErrState OUTPUT ,@oErrString = @taCreateSOPDistributionsErrString OUTPUT SELECT @iError = @@error IF ( (@iStatus <> 0) OR (@O_iErrorState <> 0) OR (@iError <> 0) ) BEGIN SELECT @oErrString = RTRIM(@oErrString) + ' ' + @taCreateSOPDistributionsErrString SELECT @O_iErrorState = 1785 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END UPDATE b SET b.BKTSLSAM = 0 ,b.ORBKTSLS = 0 FROM SOP10105 a(NOLOCK) ,SOP10200 b(NOLOCK) ,( SELECT SUM(a.BKOUTTAX) AS BackOutAmt ,a.SOPNUMBE ,a.SOPTYPE ,a.LNITMSEQ FROM SOP10105 a(NOLOCK) ,SOP10200 b(NOLOCK) WHERE a.SOPNUMBE = b.SOPNUMBE AND a.SOPTYPE = b.SOPTYPE AND a.LNITMSEQ = b.LNITMSEQ AND a.SOPNUMBE = @I_vSOPNUMBE AND a.LNITMSEQ <> 0 GROUP BY a.SOPTYPE ,a.SOPNUMBE ,a.LNITMSEQ ) AS t1 WHERE a.SOPNUMBE = b.SOPNUMBE AND a.SOPTYPE = b.SOPTYPE AND a.LNITMSEQ = b.LNITMSEQ AND a.SOPNUMBE = @I_vSOPNUMBE AND a.SOPTYPE = @I_vSOPTYPE AND a.LNITMSEQ <> 0 AND t1.BackOutAmt = 0 AND a.SOPNUMBE = t1.SOPNUMBE AND a.SOPTYPE = t1.SOPTYPE AND a.LNITMSEQ = t1.LNITMSEQ IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 4633 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END IF ( NOT EXISTS ( SELECT 1 FROM SOP10105(NOLOCK) WHERE SOPNUMBE = @I_vSOPNUMBE AND SOPTYPE = @I_vSOPTYPE ) ) BEGIN UPDATE SOP10200 SET BKTSLSAM = 0 ,ORBKTSLS = 0 WHERE SOPNUMBE = @I_vSOPNUMBE AND SOPTYPE = @I_vSOPTYPE IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 5379 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END ELSE BEGIN UPDATE SOP10200 SET BKTSLSAM = 0 ,ORBKTSLS = 0 WHERE SOPNUMBE = @I_vSOPNUMBE AND SOPTYPE = @I_vSOPTYPE AND LNITMSEQ NOT IN ( SELECT LNITMSEQ FROM SOP10105(NOLOCK) WHERE SOPNUMBE = @I_vSOPNUMBE AND SOPTYPE = @I_vSOPTYPE AND BKOUTTAX = 1 ) IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 8125 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END IF (@BSIVCTTL = 1) BEGIN UPDATE SOP10200 SET BSIVCTTL = 1 WHERE SOPNUMBE = @I_vSOPNUMBE AND SOPTYPE = @I_vSOPTYPE AND CMPNTSEQ = 0 AND LNITMSEQ IN ( SELECT LNITMSEQ FROM SOP10105(NOLOCK) WHERE SOPNUMBE = @I_vSOPNUMBE AND SOPTYPE = @I_vSOPTYPE AND TAXDTLID IN ( SELECT TAXDTLID FROM TX00201(NOLOCK) WHERE ( TXDTQUAL = 3 AND ( TDTABMIN > 0 OR TDTABMAX > 0 ) ) OR ( TDTAXMIN > 0 OR TDTAXMAX > 0 ) ) ) IF (@@error <> 0) BEGIN SELECT @O_iErrorState = 8126 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT RETURN (@O_iErrorState) END END END BREAK END IF (@mylock = 1) BEGIN EXEC @iStatus = DYNAMICS..taDEXLOCKS @I_vOperation = 3 ,@I_vtable_path_name = @SOPHdrTbl ,@I_vrow_id = @DexRowID ,@O_oExists = @oExists OUTPUT ,@O_oInsertStatus = @OInsStatus OUTPUT ,@O_iErrorState = @DexLockErrorState OUTPUT SELECT @iError = @@error IF ( (@iStatus <> 0) OR (@DexLockErrorState <> 0) OR (@iError <> 0) ) BEGIN IF (@DexLockErrorState <> 0) BEGIN SELECT @oErrString = RTRIM(@oErrString) + ' ' + @DexLockErrorState END SELECT @O_iErrorState = 2209 EXEC @iStatus = taUpdateString @O_iErrorState ,@oErrString ,@oErrString OUTPUT ,@O_oErrorState OUTPUT END END RETURN (@O_iErrorState) GO