WARNING: If you are interested in using sql_bridge, please contact a sales or implementation consultant at Cyrious.

Cyrious Control's sql_bridge is a collection of SQL Server stored prodedures and functions and external modules that can be called to safely insert or update data into the Control database and notify the CHAPI service that data has been updated. The CHAPI service is a controller program that will then notify the SSLIP and all copies of Control about the changes.

Caution: Use of this feature requires expertise in SQL Server and in the Cyrious database structure. It is very possible to irreversibly damage your Cyrious Control database if you make a mistake. Always develop your tests using a separate database on a separate machine.

Caution: Always wrap multi-record operations with SQL transaction statements. This ensure the integrity of the entire update by preventing partial changes or records from being saved. If you are not familiar with using SQL transactions, STOP! Do not proceed with any database insertions, deletions, or updates until you are.

Example

This example adds a new order with an existing customer with ID 1234. The address and contact information used is the default for the company and contact.

--
-- NOTE:  Not complete.  Still In development
--
-- This example adds a new order with the following characteristics
--      The AccountID is 1234
--      The Default Contact for that comany is used
--      The default invoice and shipping addresses are used.
--      1 line item is added.
--      The MISCELLANEOUS product is used with the following information:
--          Quantity = 5
--          Height = 24 inches
--          Width = 60 inches
--          Description = Grand Openeing
--      Two Labor Parts are added, but only to the TransDetail.PartsXML.  They need not be also added to
--          the TransPart unless/until you are going to add Part Usage.  On edit/save of the order it will
--          go ahead and create these.
--      The subtotal price is $50.00.
--      A flat tax rate of 8% is being inserted, though this will be recomputed on first edit of the order.
--         The order is not being shipped.
--
 
-- Step 1, Fill in initial data.  This could be inserted direclty in the data below
-- but using variables makes for cleaner code
    -- Entered Order Information
    DECLARE @DivisionID           INT = 10;           -- must be an ID from the Division View
    DECLARE @AccountID            INT = 1234;            -- Use the Account.ID, not the Account.CompanyNumber!
    DECLARE @ContactID            INT = NULL;         -- Leave NULL to use the default
    DECLARE @TransactionType     byte = 2;           -- 1 = Order, 2 = Estimate, 6 = Service Ticket
    DECLARE @IsPriceLocked         bit = 1;            -- 0 = Unlocked, 1 = Locked
    DECLARE @OrderDescription          VARCHAR(256) = 'Test Order Inserted By sql_bridge on '+CONVERT(VARCHAR(20), GetDate());
    DECLARE @OrderNotes               VARCHAR(4096) = 'Thank you for your Business!';
    DECLARE @OrderProductionNotes     VARCHAR(4096) = 'It works!!';
    DECLARE @Station                VARCHAR(256) = 'Waiting For Check';
    DECLARE @EnteredByID   INT = 10; -- House Account.  Or select from Employee table
    DECLARE @SalespersonID INT = 10; -- House Account.  Or select from Employee table where IsSalesperson = 1
    DECLARE @PONumber     VARCHAR(16) = '';
    DECLARE @TaxClassID   INT = NULL;        -- Leave NULL use the Account's default.  Note: Control will recompute Taxes on edit!
    -- For the first line item
    DECLARE @ProductName1   INT = __;
    DECLARE @SubTotalPrice1 DOUBLE(18,4) = 50.00
    DECLARE @TaxRate1       DOUBLE(18,4) = 0.08
    -- Declared Variables that are entirely looked up
    DECLARE @CompanyName                  VARCHAR(256);
    DECLARE @OrderDate                    smalldatetime;
    DECLARE @OrderNumber                INT;
    DECLARE @EstimateNumber                INT;
    DECLARE @THID                         INT;
    DECLARE @TVID                         INT;
    DECLARE @TDID1                        INT;
    DECLARE @JournalID                    INT;
    DECLARE @InvoiceAddressID           INT ;
    DECLARE @InvoiceAddressLinkID       INT ;
    DECLARE @ShippingAddressID          INT ;
    DECLARE @ShippingAddressLinkID      INT ;
    DECLARE    @StationID                     INT ;
    DECLARE @TaxAmount1         DOUBLE(18,4);
    DECLARE @ProductID1         INT;
    DECLARE @IsEstimate           bit;
    DECLARE @IsOrder            bit;
    DECLARE @IsServiceTicket    bit;
    DECLARE @IsOrderOrServiceTicket bit;
    -- Look up and Compute Derivative Fields
    SET @OrderDate  = GetDate();
    SET @TaxAmount1 = @TaxRate1 * @SubTotalPrice1;
    SET @ProductID1 = (SELECT ID FROM CustomerGoodsItem WHERE ItemName = @ProductName1);
    SET @IsEstimate           = CASE WHEN @TransactionType = 2 THEN 1 ELSE 0 END;
    SET @IsOrder            = CASE WHEN @TransactionType = 1 THEN 1 ELSE 0 END;
    SET @IsServiceTicket    = CASE WHEN @TransactionType = 6 THEN 1 ELSE 0 END;
    SET @IsOrderOrServiceTicket = CASE WHEN @TransactionType IN (1,6) THEN 1 ELSE 0 END;
    SELECT  TOP 1
            @TaxClassID                 = COALESCE(@TaxClassID, DefaultTaxClassID, 50),
            @CompanyName                 = CompanyName,
            @InvoiceAddressID           =
            @InvoiceAddressLinkID       =
            @ShippingAddressID          =
            @ShippingAddressLinkID      =
    FROM Account
    WHERE ID = @AccountID
    IF (@ContactID IS NULL)
        SET @ContactID = (SELECT top 1 ID FROM AccountContact WHERE AccountID = @AccountID ORDER BY IsPrimaryContact DESC);
    -- Define some error variables in case we need them
    DECLARE @ErrorMessage    VARCHAR(2048);
    DECLARE @ErrorNumber     INT;
    DECLARE @ErrorSeverity   INT;
    DECLARE @ErrorState      INT;
    DECLARE @ErrorLine       INT;
    DECLARE @ErrorProcedure  VARCHAR(200);
    DECLARE @DT              datetime = GetDate();
    DECLARE @NewLine         CHAR(2) =  CHAR(10)+CHAR(13);
-- Step 2, Lock the Company Record
    -- Lock the Company Record
    BEGIN try
        EXEC dbo.csf_chapi_lock @AccountID, 2000;
    END try
    BEGIN catch
        SET @ErrorMessage = 'Unable to lock record. '+CONVERT(VARCHAR(16), );
        -- Assign variables to error-handling functions that
        -- capture information for RAISERROR.
        SELECT
            @ErrorNumber = ERROR_NUMBER(),
            @ErrorSeverity = ERROR_SEVERITY(),
            @ErrorState = ERROR_STATE(),
            @ErrorLine = ERROR_LINE(),
            @ErrorProcedure = ISNULL(ERROR_PROCEDURE(), '-');
 
        -- Build the message string that will contain original
        -- error information.
        SELECT @ErrorMessage =
            N'Error %d, Level %d, State %d, Procedure %s, Line %d, ' +
                'Message: '+ ERROR_MESSAGE();
 
        -- Raise an error: msg_str parameter of RAISERROR will contain
        -- the original error information.
        RAISERROR
            (
            @ErrorMessage,
            @ErrorSeverity,
            1,
            @ErrorNumber,    -- parameter: original error number.
            @ErrorSeverity,  -- parameter: original error severity.
            @ErrorState,     -- parameter: original error state.
            @ErrorProcedure, -- parameter: original error procedure name.
            @ErrorLine       -- parameter: original error line number.
            );
    END catch;
 
-- Step 3, Request New IDs
 
    SET @AccountID              = (SELECT dbo.csf_chapi_nextid( 2000, 1));
    SET @AddressID              = (SELECT dbo.csf_chapi_nextid( 4001, 1));
    SET @AddressLinkID          = (SELECT dbo.csf_chapi_nextid( 4002, 3)); -- Billing and Shipping for Company and Contact
    SET @PhoneNumberID          = (SELECT dbo.csf_chapi_nextid( 4100, 3)); -- Work for Company and Contact, Mobile for Contact
    SET @JournalID              = (SELECT dbo.csf_chapi_nextid( 20510, 1)); -- Company Activity
    SET @ContactID              = (SELECT dbo.csf_chapi_nextid( 3000, 1));
    SET @CompanyNumber          = (SELECT dbo.csf_chapi_nextnumber( 'CompanyNumber', 1));
 
-- Step 4, Insert the new Records (in a transaction)
 
BEGIN TRANSACTION
 
   BEGIN TRY
 
        -- Insert TransHeader
        INSERT INTO [dbo].[TransHeader]
            ([ID] ,[StoreID] ,[ClassTypeID] ,[ModifiedByUser] ,[ModifiedByComputer] ,[ModifiedDate] ,[SeqID] ,[IsSystem] ,[IsActive]
            , [TransactionType] , [EstimateNumber] , [OrderNumber] , [OrderTemplateNumber] , [Version] , [Description] , [AccountID] , [AccountStoreID] , [ContactID] , [SalesPerson1ID] , [SalesPerson2ID] , [SalesPerson3ID] , [OrderNotes] , [PONumber] , [ProductionNotes] , [PricingLevel] , [PricingLevelOverridden] , [DiscountLevel] , [DiscountLevelOverridden] , [EstimateCreatedDate] , [OrderCreatedDate] , [BuiltDate] , [SaleDate] , [ClosedDate] , [VoidedDate] , [ConvertedDate] , [RejectedDate] , [DueDate] , [ProofDate] , [LastFinanceChargeDate] , [DispositionID] , [SalesDispositionID] , [EnteredByID] , [HTMLShortFormat] , [HTMLLongFormat] , [BasePrice] , [DiscountPrice] , [ModifierPrice] , [RawSubTotalPrice] , [RoundingPrice] , [SubTotalPrice] , [TaxesPrice] , [TotalPrice] , [SonsBasePrice] , [SonsDiscountPrice] , [SonsModifierPrice] , [SonsRawSubTotalPrice] , [SonsRoundingPrice] , [SonsSubTotalPrice] , [SonsTaxesPrice] , [SonsTotalPrice] , [FinanceChargeAmount] , [BalanceDue] , [PaymentTotal] , [WriteOffAmount] , [StatusID] , [StatusText] , [TaxClassID] , [TaxClassOverridden] , [InvoiceAddressID] , [InvoiceAddressOverridden] , [InvoiceContactID] , [ShippingAddressID] , [ShippingAddressOverridden] , [ShippingContactID] , [InvoiceAddressLinkID] , [ShippingAddressLinkID] , [EstimateGreeting] , [EstimateGreetingTemplate] , [IsTaxExempt] , [TaxNumber] , [OrderOriginID] , [OrderOriginName] , [ManuallyReOpened] , [CreditMemoAmount] , [CreditMemoOrderID] , [NextRefNumber] , [PricingLevelID] , [PromotionID] , [UseTaxLookup] , [TaxItems] , [InvoiceNumber] , [ServiceTicketNumber] , [DivisionID] , [DivisionIDOverridden] , [OrderNotesTemplate] , [ProductionNotesTemplate] , [IsFirmDueDate] , [ShippingCompanyID] , [ShippingCompanyOV] , [ShippingContactOV] , [InvoiceCompanyID] , [InvoiceCompanyOV] , [InvoiceContactOV] , [UseProgressBilling] , [PercentComplete] , [RecurrenceType] , [RecurrenceEndDate] , [LastRecurrence] , [ScheduledPaymentPlanID] , [ScheduledPaymentDate] , [ScheduledPayments] , [ScheduledPaymentIntervals] , [UsePaymentPlan] , [DroppedDate] , [PurchaseOrderNumber] , [POPaymentTermsID] , [POShippingMethodID] , [RequestedDate] , [ApprovedDate] , [OrderedDate] , [ReceivedDate] , [RequestedByID] , [ApprovedByID] , [OrderedByID] , [ReceivedByID] , [ShipFromAddressLinkID] , [ShipFromAddressID] , [ShipFromID] , [IsValidTax] , [TipsAmount] , [TipsPaidOut] , [IsDirty] , [BillNumber] , [ReceivingDocNumber] , [BillDate] , [ShipFromClassTypeID] , [ShipFromAddressOverridden] , [ExpectedPayID] , [ExpectedPayClassTypeID] , [StationID] , [StationClassTypeID] , [SalesStationID] , [SalesStationClassTypeID] , [DefaultOrderID] , [DefaultOrderClassTypeID] , [DefaultOrderItemID] , [DefaultOrderItemClassTypeID] , [TaxablePrice] , [SonsTaxablePrice] , [StationActivityID] , [StationActivityClassTypeID] , [PayrollID] , [PayrollClassTypeID] , [EarlyPaymentDiscountOVAmount] , [IsEarlyPaymentDiscountOV] , [RecurrenceStartDate] , [IsReturnDocument] , [WarehouseID] , [WarehouseIDOV] , [FinanceChargeTaxXML] , [IsPricingLocked] , [ShipFromPhoneNumberID] , [ShipFromEmailAddress] , [UseShippingAccountInfo] , [ShippingAccountNumber] , [ShippingCarrierID] , [ShippingCarrierClassTypeID] , [ShippingAccountPostalCode] , [ShipmentType] , [ShipmentTypeText] , [IsShippingLocked] , [ShipFromCustomerID] , [ShipFromCustomerClassTypeID] , [ShipFromDivisionID] , [ShipFromDivisionClassTypeID] , [OverriddenUserFields] , [EstimatingWarehouseID] , [EstimatingWarehouseIDOV] , [ProductionDivisionID] , [ProductionDivisionIDOverridden] , [IsTaxExemptOV] , [ShipToAddressType]
            )
 
        VALUES
        ( @THID  --
        , -1     -- ,
        , 10000     -- ,
        , 'SQLBridge'     -- ,
        , @@ServerName     -- ,
        , @OrderDate()    -- ,
        , 0    -- ,
        , 0    -- ,
        , 1    -- ,
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        ,      --
        )
        );
        -- Insert TransHeaderUDF (Nothing by default)
        INSERT INTO [dbo].[TransHeadedUserField] ([ID] ,[StoreID] ,[ClassTypeID] ,[ModifiedByUser] ,[ModifiedByComputer] ,[ModifiedDate] ,[SeqID] ,[IsSystem] ,[IsActive] )
 
        VALUES
        ( @THID  --
        , -1     -- ,
        , 10000     -- ,
        , 'SQLBridge'     -- ,
        , @@ServerName     -- ,
        , @OrderDate    -- ,
        , 0    -- ,
        , 0    -- ,
        , 1    -- ,
        -- put your own UDF values here
        );
 
        -- Insert TransVariation
        INSERT INTO [dbo].[TransVariation]
            ([ID] ,[StoreID] ,[ClassTypeID] ,[ModifiedByUser] ,[ModifiedByComputer] ,[ModifiedDate] ,[SeqID] ,[IsSystem] ,[IsActive]
            , [TransactionType] , [ParentID] , [ParentClassTypeID] , [VariationName] , [Notes] , [SortIndex] , [CreatedDate] , [PricingLevel] , [PricingLevelOverridden] , [DiscountLevel] , [DiscountLevelOverridden] , [HTMLShortFormat] , [HTMLLongFormat] , [BasePrice] , [DiscountPrice] , [ModifierPrice] , [RawSubTotalPrice] , [RoundingPrice] , [SubTotalPrice] , [TaxesPrice] , [TotalPrice] , [SonsBasePrice] , [SonsDiscountPrice] , [SonsModifierPrice] , [SonsRawSubTotalPrice] , [SonsRoundingPrice] , [SonsSubTotalPrice] , [SonsTaxesPrice] , [SonsTotalPrice] , [TaxablePrice] , [SonsTaxablePrice]
            )
 
        VALUES
        ( @TVID  --
        , -1     -- ,
        , 10400     -- ,
        , 'SQLBridge'     -- ,
        , @@ServerName     -- ,
        , @OrderDate()    -- ,
        , 0    -- ,
        , 0    -- ,
        , 1    -- ,
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        ,       --
        );
        -- Insert TransDetail
        INSERT INTO [dbo].[TransDetail]
            ([ID] ,[StoreID] ,[ClassTypeID] ,[ModifiedByUser] ,[ModifiedByComputer] ,[ModifiedDate] ,[SeqID] ,[IsSystem] ,[IsActive]
            , [TransactionType] , [ParentID], [ParentClassTypeID] , [TransHeaderID] , [TransHeaderClassTypeID] , [TransHeaderTransNumber] , [GoodsItemID] , [GoodsItemClassTypeID] , [GoodsItemCode] , [PricingLevel] , [PricingLevelOverridden] , [DiscountLevel] , [DiscountLevelOverridden] , [Description] , [Quantity] , [LineItemIndex] , [LineItemNumber] , [HTMLShortFormat] , [HTMLLongFormat] , [BasePrice] , [BaseCalcPrice] , [BaseOverriddenPrice] , [BaseIsOverridden] , [DiscountPrice] , [DiscountCalcPrice] , [DiscountOverriddenPrice] , [DiscountIsOverridden] , [ModifierPrice] , [ModifierCalcPrice] , [ModifierOverriddenPrice] , [ModifierIsOverridden] , [RawSubTotalPrice] , [RawSubTotalCalcPrice] , [RawSubTotalOverriddenPrice] , [RawSubTotalIsOverridden] , [RoundingPrice] , [RoundingCalcPrice] , [RoundingOverriddenPrice] , [RoundingIsOverridden] , [SubTotalPrice] , [SubTotalCalcPrice] , [SubTotalOverriddenPrice] , [SubTotalIsOverridden] , [TaxesPrice] , [TaxesCalcPrice] , [TaxesOverriddenPrice] , [TaxesIsOverridden] , [TotalPrice] , [TotalCalcPrice] , [TotalOverriddenPrice] , [TotalIsOverridden] , [MeAndSonsBasePrice] , [MeAndSonsDiscountPrice] , [MeAndSonsModifierPrice] , [MeAndSonsRawSubTotalPrice] , [MeAndSonsRoundingPrice] , [MeAndSonsSubTotalPrice] , [MeAndSonsTaxesPrice] , [MeAndSonsTotalPrice] , [InternalNotes] , [UnitParamName] , [UnitParamValue] , [VariationID] , [ImageParamID] , [ImageParamStoreID] , [ImageParamClassTypeID] , [StageID] , [StageStoreID] , [StageClassTypeID] , [SaleAccountID] , [SaleAccountStoreID] , [SaleAccountClassTypeID] , [SaleAccountOverridden] , [ChildItemCount] , [ParameterStr] , [ModifierStr] , [PartStr] , [VarGridParam1ID] , [VarGridParam2ID] , [VarGridValues1] , [VarGridValues2] , [VarGridParam1OV] , [VarGridParam2OV] , [TaxItems] , [IsComplete] , [AssignedToID] , [TicketItemNumber] , [ShippingCompanyID] , [ShippingCompanyOV] , [ShippingContactID] , [ShippingContactOV] , [ShippingAddressID] , [ShippingAddressLinkID] , [ShippingAddressOV] , [ShippingTaxClassID] , [ShippingTaxClassOV] , [TotMaterialCost] , [TotLaborCost] , [TotEquipmentCost] , [TotOutSourceCost] , [TotOtherCost] , [TotPartCost] , [HasWorkAssignment] , [WorkAssignmentID] , [WorkAssignmentStoreID] , [WorkAssignmentClassTypeID] , [TotFreightCost] , [PriorityID] , [PriorityStoreID] , [PriorityClassTypeID] , [AssignedToClassTypeID] , [ProofApproved] , [ProofApprovedDate] , [ProofApprovedByID] , [PercentComplete] , [PercentCompleteOV] , [TermID] , [ContractPeriodID] , [ContractStartDate] , [ContractEndDate] , [ShipFromAddressID] , [ShipFromAddressLinkID] , [ShipFromAddressOV] , [IsValidTax] , [IsDirty] , [TaxNumber] , [ShipFromID] , [ShipFromClassTypeID] , [AssemblyIncluded] , [AssemblyIncludedOV] , [AssemblyLocked] , [AssemblyLinkID] , [AssemblyLinkClassTypeID] , [OverriddenAssemblies] , [StationID] , [StationClassTypeID] , [GLDepartmentID] , [GLDepartmentIDOV] , [TaxablePrice] , [MeAndSonsTaxablePrice] , [StationActivityID] , [StationActivityClassTypeID] , [MaterialExpenseID] , [LaborExpenseID] , [EquipmentExpenseID] , [OutsourceExpenseID] , [OtherExpenseID] , [FreightExpenseID] , [LocationExpenseID] , [UseParentExpenseAccounts] , [WarehouseID] , [WarehouseIDOV] , [RanReturnSQLFuncStatements] , [QuantityShipped] , [DueDate] , [DueDateOV] , [ShipFromCustomerID] , [ShipFromCustomerClassTypeID] , [ShowMultipleQuantityGrid] , [MultipleQuantityGridXML] , [OldDescription] , [EstimatingWarehouseID] , [EstimatingWarehouseIDOV] , [ProductionDivisionID] , [ProductionDivisionIDOverridden] )
            )
 
        VALUES
        ( @TDID  --
        , -1     -- ,
        , 10100     -- ,
        , 'SQLBridge'     -- ,
        , @@ServerName     -- ,
        , @OrderDate()    -- ,
        , 0    -- ,
        , 0    -- ,
        , 1    -- ,
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        ,          --
        );
        -- Insert Order Creation into Journal
 
        INSERT INTO [Journal] ([ID], [StoreID], [ClassTypeID] ,[ModifiedByUser] ,[ModifiedByComputer] ,[ModifiedDate] ,[SeqID] ,[IsSystem] ,[IsActive] ,[EmployeeID],[JournalActivityType] ,[JournalActivityText] ,[Description] ,[Notes] ,[StartDateTime] ,[EndDateTime] ,[TotalTime] ,[ScheduledDateTime]  ,[CompletedByID] ,[CompletedDateTime] ,[IsSummary] ,[IsDetail] ,[SummaryID] ,[SummaryClassTypeID] ,[SummaryAmount] ,[DetailAmount] ,[StartGLGroupID]  ,[EndGLGroupID]  ,[AccountID] ,[AccountClassTypeID]  ,[ContactID]  ,[ContactClassTypeID]  ,[TransactionID] ,[TransactionClassTypeID]  ,[IsVoided]  ,[VoidedDateTime]  ,[VoidedEntryID] ,[VoidedEntryClassTypeID]  ,[VoidedReason]  ,[QueryStartDateTime] ,[QueryEndDateTime]  ,[ReminderDateTime]  ,[ReminderPrompt]  ,[PartID]  ,[ActivityType]  ,[ActivityTypeText]  ,[IsBillable] ,[BillableDateTime]  ,[UseActualTime]  ,[BillingNotes]  ,[BillingType]  ,[TotalBilledTime]  ,[RecurringActivityID]  ,[LinkID]  ,[LinkStoreID] ,[LinkClassTypeID] ,[SpecialCode] ,[DivisionID] ,[HasCalendarLinks] ,[TipRecipientID] ,[PartClassTypeID] ,[RecurringClassTypeID] ,[StationID] ,[StationClassTypeID] ,[CurrentState] ,[StageID] ,[StageClassTypeID])
 
        VALUES
            ( @JournalID     -- (
            , -1     -- ,
            , _____     -- ,
            , 'SQLBridge'     -- ,
            , @@ServerName     -- ,
            , @OrderDate    -- ,
            ,  0    -- ,
            ,  0    -- ,
            ,  1    -- ,
           , @EnteredByID  --
           , 6  --
           , 'Company'  --
           , 'Company Created'  --
           , 'Inserted by SQLBridge'  --
           , @OrderDate  --
           , @OrderDate  --
           , NULL  --
           , NULL  --
           , @EnteredByID  --
           , @OrderDate  --
           , 1  --
           , 1  --
           , NULL  --
           , NULL  --
           , NULL  --
           , NULL  --
           , NULL  --
           , NULL  --
           , @AccountID  --
           , 2000  --
           , @ContactID  --
           , 3000  --
           , @THID --
           , 10000 --
           , 0  --
           , NULL  --
           , NULL  --
           , NULL  --
           , NULL  --
           , @OrderDate  --
           , @OrderDate  --
           , NULL  --
           , 0  --
           , NULL  --
           , 0  --
           , NULL  --
           , 0  --
           , NULL  --
           , 0  --
           , NULL  --
           , 0  --
           , 0  --
           , NULL  --
           , NULL  --
           , NULL  --
           , NULL  --
           , NULL  --
           , @DivisionID  --
           , 0  --
           , NULL  --
           , NULL  --
           , NULL  --
           , NULL  --
           , NULL  --
           , NULL  --
           , NULL  --
           , NULL  -- )
        );
 
        -- Now commit the Transaction
        COMMIT TRANSACTION
 
    END TRY
 
    BEGIN CATCH
        ROLLBACK TRANSACTION;
 
        SELECT @ErrorMessage = ERROR_MESSAGE(),
               @ErrorSeverity = ERROR_SEVERITY(),
               @ErrorState = ERROR_STATE();
 
        -- Use RAISERROR inside the CATCH block to return
        -- error information about the original error that
        -- caused execution to jump to the CATCH block.
        RAISERROR (@ErrorMessage, -- Message text.
                   @ErrorSeverity, -- Severity.
                   @ErrorState -- State.
                   );
    END CATCH;
 
-- Step 5, Unlock the Company Record
    EXEC dbo.csf_chapi_unlock @AccountID, 2000;
-- Step 6, Refresh the Customer and Order Record
 
    EXEC dbo.csf_chapi_refresh @THID, 10000, 0;
    EXEC dbo.csf_chapi_refresh @AccountID, 2000, 0;

Contributor: Cyrious Software

Date: 4/2014

Version: Control 5.1

You could leave a comment if you were logged in.