Table of Contents

{$page}

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

Overview

Cyrious Control's SQLBridge 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.

code_formatsql

– 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

  1. - 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!
  1. - For the first line item
  DECLARE @ProductName1   int = __;
  DECLARE @SubTotalPrice1 double(18,4) = 50.00
  DECLARE @TaxRate1       double(18,4) = 0.08
  1. - 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;
  1. - 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);
  1. - 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

  1. - 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), );
  1. - Assign variables to error-handling functions that
  1. - capture information for RAISERROR.
      SELECT 
          @ErrorNumber = ERROR_NUMBER(),
          @ErrorSeverity = ERROR_SEVERITY(),
          @ErrorState = ERROR_STATE(),
          @ErrorLine = ERROR_LINE(),
          @ErrorProcedure = ISNULL(ERROR_PROCEDURE(), '-');
  1. - Build the message string that will contain original
  1. - error information.
      SELECT @ErrorMessage = 
          N'Error %d, Level %d, State %d, Procedure %s, Line %d, ' + 
              'Message: '+ ERROR_MESSAGE();
  1. - Raise an error: msg_str parameter of RAISERROR will contain
  1. - 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
  1. - 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    -- ,
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      ,      --  
      )
      );
  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    -- ,
  1. - put your own UDF values here
      );
  1. - 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    -- ,
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      ,       --  
      );
  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    -- ,
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      ,          -- 
      );
  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  -- )
      );
  1. - Now commit the Transaction
      COMMIT TRANSACTION
  END TRY
  BEGIN CATCH
      ROLLBACK TRANSACTION;
      SELECT @ErrorMessage = ERROR_MESSAGE(),
             @ErrorSeverity = ERROR_SEVERITY(),
             @ErrorState = ERROR_STATE();
  1. - Use RAISERROR inside the CATCH block to return
  1. - error information about the original error that
  1. - 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;

code

Source

Contributor: Cyrious Software

Date: 4/2014

Version: Control 5.1

See Also