PRINT N'Altering [dbo].[taSopHdrRecalc]' GO 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_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(30), @ExstShipToName char(64), @ExstADDRESS1 char(30), @ExstADDRESS2 char(30), @ExstADDRESS3 char(30), @ExstCITY char(30), @ExstSTATE char(29), @ExstZIPCODE char(10), @ExstCOUNTRY char(20), @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, @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, @SUBTOTALCHG numeric(19, 5), @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(30), @ADDRESS2 char(30), @ADDRESS3 char(30), @CNTCPRSN char(30), @FAXNUMBR char(21), @CITY char(30), @STATE char(29), @ZIPCODE char(10), @COUNTRY char(20), @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 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, @SUBTOTALCHG = 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 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 -- print 'start ---- ' 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, @NOTEINDX = NOTEINDX, @ORIGTYPE = ORIGTYPE from SOP10100 (nolock) where SOPTYPE = @I_vSOPTYPE and SOPNUMBE = @I_vSOPNUMBE --print @ExstTAXAMNT 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 @I_vRECALCBTCHTOT = 1, @stoprecalc = 0 end else begin if ( @I_vRECALCBTCHTOT = 3 ) begin select @I_vRECALCBTCHTOT = 1, @stoprecalc = 1 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_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 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 <> '' AND @I_vSLPRSNID is not null) begin if ( not exists ( select 1 from RM00301 (nolock) where SLPRSNID = @I_vSLPRSNID ) ) begin PRINT 'SALES REP = ' + @I_vSLPRSNID 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 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 if ( @I_vShipToName = '' ) begin select @I_vShipToName = @NewCUSTNAME end 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 ( @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 = 3 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 = 3 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.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 ) ) select @PAYMENTS = 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 ( 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, 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 ( @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 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 = 1 ) begin --print 'recreating taxes' 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 --print 'here' 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 ) 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 ( @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 ( @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 = @ExstCUSTNMBR, @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_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) 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) 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 --print 'hr2' 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 --print 'hr3' 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 --print 'hr4' 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 --print 'hr6' 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 select @SUBTOTALCHG = @I_vCHGAMNT - @ExstSUBTOTAL if ( @stoprecalc = 0 ) begin update RM00103 set ONORDAMT = ONORDAMT - @SUBTOTALCHG 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 is null ) and ( @I_vCMMTTEXT = '' and @I_vCOMMENT_1 = '' and @I_vCOMMENT_2 = '' and @I_vCOMMENT_3 = '' and @I_vCOMMENT_4 = '' ) or ( @I_vCOMMNTID is null ) and ( @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 ) ) begin if ( @I_vSOPTYPE <> 6 ) begin select @I_vCOMMNTID = COMMNTID from SOP40200 (nolock) where SOPTYPE = @I_vSOPTYPE and DOCID = @DOCID end else begin select @I_vCOMMNTID = COMMNTID from SOP40200 (nolock) where SOPTYPE = 3 and DOCID = @DOCID end end else begin select @I_vCOMMNTID = case when @I_vCOMMNTID <> '' then @I_vCOMMNTID else '' end end if ( ( @I_vCOMMNTID = '' ) 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 --print 'hr7 -----' --print @ExstTAXAMNT --print '-------' 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 = case when ( @I_vShipToName is not null ) then @I_vShipToName else @ExstShipToName end, 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, 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 = @Flags, WorkflowApprStatusQuote = @WorkflowApprStatusQuote, WorkflowPriorityQuote = @WorkflowPriorityQuote, WorkflowApprStatCreditLm = @WorkflowApprStatCreditLm, WorkflowPriorityCreditLm = @WorkflowPriorityCreditLm 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 <> '' ) or ( @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 <> '' ) or ( @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