Description

The SQL function is a utility that is used by several SQL import methods. This function may be added and used as needed.

Purpose

This function is used to look up a tax class by name. It is broken out into a different routine in case a company wants to tailor their lookup rules.

Input
  • @TaxLookupValue - The name of the tax class to be looked up.
Output/Results
  • ID - The ID of the tax class to use.
Code

– Author: Cyrious Sofware

– Create date: May-2016

– Description: This function maps a tax class name to a valid

– tax class in Control. The specifics of the tax class

– logic can be customized for each company.

CREATE FUNCTION [dbo].csf_MapTaxClassByName(

  @TaxLookupValue varchar(255)

)

RETURNS INT

BEGIN

  DECLARE @TaxClassID INT;
  1. - Step 1 → See if an exact name match exists in our system
IF (Len(@TaxLookupValue) > 0)
	SET @TaxClassID = (select ID from TaxClass where TaxClassName = @TaxLookupValue and ID>0 );
  1. - Step 2 → If not found, use custom rules
  IF (@TaxClassID IS NULL)
  BEGIN
      DECLARE @FallBackTaxClassID INT = (SELECT TOP(1) COALESCE(DefaultTaxClassID, 50) FROM Store WHERE ID > 0 ORDER BY ID);
  1. - ———————————————————————————————-
  1. - INSERT CUSTOM RULES HERE
  1. - ———————————————————————————————-
  1. - DECLARE @OutOfStateTaxClass INT = 1006;
  1. - SET @TaxClassID =
  1. - ( CASE
  1. - WHEN (@TaxLookupValue = 'Out Of State') THEN @OutOfStateTaxClass
  1. - WHEN (@TaxLookupValue Like '%East Baton Rouge%') THEN @EBRTaxClass
  1. - WHEN (@TaxLookupValue Like '%EBR%') THEN @EBRTaxClass
  1. - WHEN (@TaxLookupValue Like 'LA-%') THEN @LAStateOnly
  1. - ELSE @FallBackTaxClassID
  1. - END
  1. - );
      SET @TaxClassID = @FallBackTaxClassID;
  END;
  RETURN @TaxClassID;

END

code

=Source=

Contributor: Cyrious Software

Date: 5/2016

Version: Control 5.7+

See Also

You could leave a comment if you were logged in.