USP_DATAFORMTEMPLATE_ADD_MKTPACKAGE
The save procedure used by the add dataform template "Package Add Form".
Parameters
| Parameter | Parameter Type | Mode | Description | 
|---|---|---|---|
| @ID | uniqueidentifier | INOUT | The output parameter indicating the ID of the record added. | 
| @CHANGEAGENTID | uniqueidentifier | IN | Input parameter indicating the ID of the change agent invoking the procedure. | 
| @NAME | nvarchar(100) | IN | Name | 
| @DESCRIPTION | nvarchar(255) | IN | Description | 
| @CODE | nvarchar(10) | IN | Code | 
| @COST | money | IN | Unit cost | 
| @SITEID | uniqueidentifier | IN | Site | 
| @CHANNELCODE | tinyint | IN | Channel | 
| @CATEGORYCODEID | uniqueidentifier | IN | Category | 
| @CODEVALUEID | uniqueidentifier | IN | Code value ID | 
| @CURRENTAPPUSERID | uniqueidentifier | IN | Input parameter indicating the ID of the current user. | 
Definition
 Copy 
                                    
CREATE procedure dbo.[USP_DATAFORMTEMPLATE_ADD_MKTPACKAGE]
(
  @ID uniqueidentifier = null output,
  @CHANGEAGENTID uniqueidentifier = null,
  @NAME nvarchar(100),
  @DESCRIPTION nvarchar(255) = '',
  @CODE nvarchar(10) = '',
  @COST money = 0,
  @SITEID uniqueidentifier = null,
  @CHANNELCODE tinyint = 0,
  @CATEGORYCODEID uniqueidentifier = null,
  @CODEVALUEID uniqueidentifier = null,
  @CURRENTAPPUSERID uniqueidentifier = null
)
as
  set nocount on;
  declare @CURRENTDATE datetime;
  begin try
    if @ID is null
      set @ID = newid();
    if @CHANGEAGENTID is null
      exec dbo.[USP_CHANGEAGENT_GETORCREATECHANGEAGENT] @CHANGEAGENTID output;
    set @CURRENTDATE = getdate();
        declare @BASECURRENCYID uniqueidentifier;
    set @BASECURRENCYID = dbo.[UFN_APPUSER_GETBASECURRENCY](@CURRENTAPPUSERID);
        declare @CURRENCYEXCHANGERATEID uniqueidentifier;
        declare @ORGANIZATIONAMOUNT money;
        declare @ORGANIZATIONCURRENCYID uniqueidentifier;
        set @ORGANIZATIONCURRENCYID = dbo.[UFN_CURRENCY_GETORGANIZATIONCURRENCY]();
        if (@ORGANIZATIONCURRENCYID = @BASECURRENCYID)
        begin
            set @ORGANIZATIONAMOUNT = @COST;
        end
        else
        begin
            set @CURRENCYEXCHANGERATEID = dbo.[UFN_CURRENCYEXCHANGERATE_GETLATEST](@BASECURRENCYID, @ORGANIZATIONCURRENCYID, @CURRENTDATE, 0, null);
            set @ORGANIZATIONAMOUNT = dbo.[UFN_CURRENCY_CONVERT](@COST, @CURRENCYEXCHANGERATEID);
        end
    insert into dbo.[MKTPACKAGE] (
      [ID],
      [NAME],
      [DESCRIPTION],
      [CODE],
      [PARTDEFINITIONVALUESID],
      [CHANNELCODE],
      [PACKAGECATEGORYCODEID],
      [UNITCOST],
      [SITEID],
      [ADDEDBYID],
      [CHANGEDBYID],
      [DATEADDED],
      [DATECHANGED],
      [BASECURRENCYID],
      [ORGANIZATIONUNITCOST],
      [CURRENCYEXCHANGERATEID]
    ) values (
      @ID,
      @NAME,
      @DESCRIPTION,
      @CODE,
      @CODEVALUEID,
      @CHANNELCODE,
      @CATEGORYCODEID,
      @COST,
      @SITEID,
      @CHANGEAGENTID,
      @CHANGEAGENTID,
      @CURRENTDATE,
      @CURRENTDATE,
      @BASECURRENCYID,
      @ORGANIZATIONAMOUNT,
      @CURRENCYEXCHANGERATEID
    );
  end try
  begin catch
    exec dbo.[USP_RAISE_ERROR];
    return 1;
  end catch
  return 0;