Table of Contents

WARNING: This is not kids stuff. 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. If you are interested in using SQL Bridge but are not a SQL guru, please contact a sales or consulting at Cyrious.
Note: This feature requires Control 5.75 or higher .

Overview

The stored procedure can be used to import a part into Control`

You must supply the following values:

You can start with a copy an existing part by specifying one of the following two values

If you don't supply a CopyFromPart, you must supply the following information:

0 = Material 4 = Other
1 = Labor 5 = Freight
2 = Equipment 6 = Location
3 = Outsource

* CategoryID - The ID of the Part Category. Use this value or the CategoryName, but not both.

The following information is optional. If you supply values, it will override the defaulr or the CopyFromPart.

  1. - —————————————————-
  SET @TrackInventory = 0;
  1. - —————————————————-
  1. - Obtain new IDs using SQL Bridge
  1. - —————————————————-
  IF (@PartID IS NULL )  SET @PartID = (SELECT dbo.csf_chapi_nextid( 12014, 1));
  IF (@DisplayUnitID IS NOT NULL AND @DisplayUnitID != @UnitID)
      SET @PartUnitConversionID = (SELECT dbo.csf_chapi_nextid( 12016, 1 ));
  IF (@TrackInventory =1)
  BEGIN
      SET @InventoryID        = (SELECT dbo.csf_chapi_nextid( 12200, @WarehouseCount ));
      SET @InventorySummaryID = (SELECT dbo.csf_chapi_nextid( 12200, @WarehouseGroupCount ));
  END;
  1. - —————————————————-
  1. - Create the Records
  1. - —————————————————-
  BEGIN TRANSACTION
  BEGIN TRY
      INSERT INTO Part
              (ID, StoreID, ClassTypeID, ModifiedByUser, ModifiedByComputer, ModifiedDate, SeqID, IsSystem, IsActive
              , CategoryID, CategoryStoreID, CategoryClassTypeID, ItemName, Description, HelpText, InternalNotes
              , BarCode, SKU, AssetAccountID, ExpenseAccountID, InventoryUnitType, PartType, TrackInventory, QuantityOnHand
              , QuantityReserved, QuantityAvailable, QuantityOnOrder, QuantityExpected, ReOrderPoint, ReOrderQuantity
              , YellowNotificationPoint, RedNotificationPoint, NotificationAddresses, NotifyOtherContacts, UnitID
              , RoundingOption, ScrapFactor, UnitCost, TrackCosts, UnitCostFormula, UseFixedCost, CostMultiplier
              , CostMultiplierType, FixedCostMultiplier, ShowOnProductionSchedule, InstancesAllowedType, InstancesAllowed
              , Vendor, VendorPartNumber, RoundingFactor, StationID, StationClassTypeID, GLDepartmentID, GLDepartmentClassTypeID
              , InventoryID, AccrueCosts, ExpenseAccountClassTypeID, AssetAccountClassTypeID, UseCategoryDefaults
              , ComputedCostAccountID, ComputedCostAccountClassTypeID, LastModifiedDate, UDFLayoutSettings, LocalTags
              , UDFXML, UseInvUnitsForDisplay, DisplayUnitID, DisplayUnitType, DisplayUnitText, DisplayConversionFormula
              , GLDepartmentIDOV, ExpenseAccountIDOV, AssetAccountIDOV, TransferUnitID, TransferUnitQuantity, TransferUnitText
              , ResellProductID, ResellProductIDOV, ResellProductVariableID)
      VALUES (
                @PartID  -- 
              , -1           -- ,
              , 12014         -- ,
              , @ProcName  -- ,
              , @ComputerName -- ,
              , @DT    -- ,
              , 0            -- ,
              , 0            -- ,
              , 1            -- ,
              , @CategoryID    -- 
              , NULL    -- 
              , 12035    -- 
              , @PartName    -- 
              , coalesce(@Description, @PartName)    -- 
              , NULL    -- 
              , NULL    -- 
              , NULL    -- 
              , @SKU    -- 
              , @AccrualAccountID    -- 
              , @ExpenseAccountID    -- 
              , @UnitTypeID    -- 
              , @PartTypeID    --    
              , @TrackInventory    -- 
              , NULL    -- 
              , NULL    -- 
              , NULL    -- 
              , NULL    -- 
              , NULL    -- 
              , NULL    -- 
              , NULL    -- 
              , NULL    -- 
              , NULL    -- 
              , NULL    -- 
              , NULL    -- 
              , @UnitID    -- 
              , (CASE @RoundingFactor 
                      WHEN 1.0 THEN 0 
                      WHEN 0.5 THEN 1
                      WHEN 0.25 THEN 2
                      WHEN 0.20 THEN 3
                      WHEN 0.10 THEN 4
                      WHEN 0.01 THEN 5
                      WHEN 0.001 THEN 6
                      WHEN 0.0001 THEN 7
                      WHEN 0.125 THEN 8
                      WHEN 5.0 THEN 9
                      WHEN 10.0 THEN 10
                      WHEN 25.0 THEN 11
                      WHEN 50.0 THEN 12
                      WHEN 100.0 THEN 13 
                      WHEN 250.0 THEN 14 
                      WHEN 500.0 THEN 15
                      WHEN 1000.0 THEN 16 
                      ELSE 17 -- Custom
                      END )    -- 
              , @ScrapFactor   -- 
              , @UnitCost      -- 
              , @TrackCosts   -- 
              , @UnitCostFormula    -- 
              , ISNUMERIC(@UnitCost)    -- 
              , @CostMultiplierFormula    -- 
              , @MultiplierType    -- 
              , @PriceMultiplierFormula    -- 
              , 0    -- 
              , 0    -- 
              , 1    -- 
              , NULL    -- 
              , NULL    -- 
              , @RoundingFactor    -- 
              , @DefaultStationID    -- 
              , 26100    -- 
              , NULL    -- 
              , NULL    -- 
              , NULL    -- 
              , @AccrueCosts    -- 
              , 8001    -- 
              , 8001    -- 
              , @UseCategoryDefaults    -- 
              , NULL    -- 
              , NULL    -- 
              , @DT    -- 
              , @UDFLayoutSettings    -- 
              , @LocalTags    -- 
              , @UDFXML    -- 
              , (CASE WHEN @DisplayUnitID IS NULL THEN 1 ELSE 0 END)    -- 
              , COALESCE(@DisplayUnitID, @UnitID)    -- 
              , COALESCE(@DisplayUnitTypeID, @UnitTypeID)    -- 
              , COALESCE(@DisplayUnitText, @UnitText)    -- 
              , '1 / '+convert(varchar(18), @DisplayUnitsInUnit)  -- 
              , NULL    -- 
              , NULL    -- 
              , NULL    -- 
              , @UnitID    -- 
              , 1.00    -- 
              , @UnitText    -- 
              , @ResellProductID    -- 
              , (CASE WHEN @ResellProductID IS NULL THEN 0 ELSE 1 END)    -- 
              , @ResellVariableID    -- 
      );
  1. - See if we have alternate display units
      IF (@PartUnitConversionID IS NOT NULL)
          INSERT INTO PartInventoryConversion
                  (ID, StoreID, ClassTypeID, ModifiedByUser, ModifiedByComputer, ModifiedDate, SeqID, IsSystem, IsActive
                  , PartID, IsAutomatic, IsDefault, ConversionFormula, ConsumptionFormula, InclusionFormula, UnitID
                  , UnitType)
          VALUES(
                  @PartUnitConversionID  -- 
                  , -1           -- ,
                  , 12016         -- ,
                  , @ProcName  -- ,
                  , @ComputerName -- ,
                  , @DT    -- ,
                  , 0            -- ,
                  , 0            -- ,
                  , 1            -- ,
                  , @PartID    -- 
                  , 0    -- 
                  , 0    -- 
                  , '1 / '+convert(varchar(18), @DisplayUnitsInUnit)  -- 
                  , '1'    -- 
                  , 'Always'    -- 
                  , @DisplayUnitID    -- 
                  , @DisplayUnitTypeID    -- 
          );
  1. - ——————————————
  1. - Iterate through each Warehouse and Warehouse Groups
  1. - ——————————————
  1. - IF (@TrackInventory = 1)
  1. - BEGIN
  1. - INSERT INTO Inventory
  1. - (ID, StoreID, ClassTypeID, ModifiedByUser, ModifiedByComputer, ModifiedDate, SeqID, IsSystem, IsActive
  1. - , ItemName, PartID, AverageCost, QuantityAvailable, QuantityBilled, QuantityExpected, QuantityOnHand
  1. - , QuantityOnOrder, QuantityReceivedOnly, QuantityReserved, AssetAccountID, AssetAccountIDOV, UnitType
  1. - , UnitID, YellowNotificationPoint, RedNotificationPoint, ReorderPoint, ReOrderQuantity, AssetAccountClassTypeID
  1. - , UseCategoryDefaults, WarehouseID, DivisionID, IsGroup, IsDivisionSummary, GroupID, AlertLevel, Location)
  1. - VALUES(
  1. - –
  1. - , -1 – ,
  1. - , 12200 – ,
  1. - , @ProcName – ,
  1. - , @ComputerName – ,
  1. - , @DT – ,
  1. - , 0 – ,
  1. - , 0 – ,
  1. - , 1 – ,
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - , –
  1. - );
  1. - END;
  1. - Now commit the Transaction
      COMMIT TRANSACTION
  END TRY
  BEGIN CATCH
      ROLLBACK TRANSACTION;
      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;
  1. - ——————————————————–
  1. - Refresh the Part Category
  1. - ———————————————————-
  IF (@RefreshOnSave=1)
  BEGIN
      EXEC dbo.csf_chapi_refresh @PartID, 12014, -1;
      EXEC dbo.csf_chapi_refresh @CategoryID, 12035, -1;
  END;
  1. - ———————————————————-
  1. - Return the New Part ID
  1. - ———————————————————-
  SELECT @PartID, 12035

END;

code

Source

Contributor: Cyrious Software

Date: 9/2016

Version: Control 5.7+

See Also