Compile function Copy_COMPANY_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given COMPANY record to the MSSQL database.
	
	History
	-------
	04/21/2010    KRF   Original Programmer
\*****************************************************************************/

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

// Parse record into a dimensioned array for speed
Dim Rec(71)
MatParse Record into Rec
					    
// List of key names and their values
Keys = "CO_NO":@VM:SQL_Format(Key, "INT")

// List of data fields and their values
DataFields  = "ENTRY_DATE"              :@VM:SQL_Format(Rec(1),  "DATE"):@FM
DataFields := "ENTRY_ID"                :@VM:SQL_Format(Rec(2),  "STR"):@FM
DataFields := "CATEGORY"                :@VM:SQL_Format(Rec(3),  "STR"):@FM
DataFields := "CO_NAME"                 :@VM:SQL_Format(Rec(4),  "STR"):@FM
DataFields := "CITY"                    :@VM:SQL_Format(Rec(6),  "STR"):@FM
DataFields := "STATE"                   :@VM:SQL_Format(Rec(7),  "STR"):@FM
DataFields := "ZIP"                     :@VM:SQL_Format(Rec(8),  "STR"):@FM
DataFields := "CO_TYPE"                 :@VM:SQL_Format(Rec(14), "STR"):@FM
DataFields := "DIVISION"                :@VM:SQL_Format(Rec(15), "STR"):@FM
DataFields := "TERMS"                   :@VM:SQL_Format(Rec(16), "STR"):@FM
DataFields := "BILL_TO_ATTN"            :@VM:SQL_Format(Rec(18), "STR"):@FM
DataFields := "BILL_TO_CO"              :@VM:SQL_Format(Rec(19), "STR"):@FM
DataFields := "BILL_TO_CITY"            :@VM:SQL_Format(Rec(21), "STR"):@FM
DataFields := "BILL_TO_STATE"           :@VM:SQL_Format(Rec(22), "STR"):@FM
DataFields := "BILL_TO_ZIP"             :@VM:SQL_Format(Rec(23), "STR"):@FM
DataFields := "SHIP_TO_ATTN"            :@VM:SQL_Format(Rec(24), "STR"):@FM
DataFields := "SHIP_TO_CO"              :@VM:SQL_Format(Rec(25), "STR"):@FM
DataFields := "SHIP_TO_CITY"            :@VM:SQL_Format(Rec(27), "STR"):@FM
DataFields := "SHIP_TO_STATE"           :@VM:SQL_Format(Rec(28), "STR"):@FM
DataFields := "SHIP_TO_ZIP"             :@VM:SQL_Format(Rec(29), "STR"):@FM
DataFields := "COUNTRY"                 :@VM:SQL_Format(Rec(30), "STR"):@FM
DataFields := "VREMIT_CITY"             :@VM:SQL_Format(Rec(33), "STR"):@FM
DataFields := "VREMIT_STATE"            :@VM:SQL_Format(Rec(34), "STR"):@FM
DataFields := "VREMIT_ZIP"              :@VM:SQL_Format(Rec(35), "STR"):@FM
DataFields := "VREMIT_PHONE"            :@VM:SQL_Format(Rec(36), "STR"):@FM
DataFields := "VACCT_NO"                :@VM:SQL_Format(Rec(37), "STR"):@FM
DataFields := "VREMIT_PHONE_TYPES"      :@VM:SQL_Format(Rec(38), "STR"):@FM
DataFields := "VREMIT_COMPANY"          :@VM:SQL_Format(Rec(39), "STR"):@FM
DataFields := "INVOICE_NOTES"           :@VM:SQL_Format(Rec(40), "STR"):@FM
DataFields := "SALES_REP"               :@VM:SQL_Format(Rec(41), "STR"):@FM
DataFields := "ABBREV"                  :@VM:SQL_Format(Rec(42), "STR"):@FM
DataFields := "BUSINESS_DESC"           :@VM:SQL_Format(Rec(43), "STR"):@FM
DataFields := "DIRECTIONS"              :@VM:SQL_Format(Rec(44), "STR"):@FM
DataFields := "ACCT_REP"                :@VM:SQL_Format(Rec(48), "STR"):@FM
DataFields := "SALES_OFFICE"            :@VM:SQL_Format(Rec(49), "STR"):@FM
DataFields := "PRODUCT"                 :@VM:SQL_Format(Rec(50), "STR"):@FM
DataFields := "APPLICATION"             :@VM:SQL_Format(Rec(51), "STR"):@FM
DataFields := "INDUSTRY"                :@VM:SQL_Format(Rec(52), "STR"):@FM
DataFields := "ENDUSER_CUST"            :@VM:SQL_Format(Rec(53), "STR"):@FM
DataFields := "CUST_COMPETITION"        :@VM:SQL_Format(Rec(54), "STR"):@FM
DataFields := "OUR_COMPETITION"         :@VM:SQL_Format(Rec(55), "STR"):@FM
DataFields := "MANUF_TYPE"              :@VM:SQL_Format(Rec(56), "STR"):@FM
DataFields := "STATUS"                  :@VM:SQL_Format(Rec(57), "STR"):@FM
DataFields := "ORACLE_SITE_ID"          :@VM:SQL_Format(Rec(58), "INT"):@FM
DataFields := "SHIPPING_EXPORT_TEMPLATE":@VM:SQL_Format(Rec(59), "STR"):@FM
DataFields := "COA_FOLDER"              :@VM:SQL_Format(Rec(60), "STR"):@FM
DataFields := "VISION_CUST_NO"          :@VM:SQL_Format(Rec(61), "STR"):@FM
DataFields := "BILL_TO_CUST_NO"         :@VM:SQL_Format(Rec(62), "STR"):@FM
DataFields := "CAPTIVE"                 :@VM:SQL_Format(Rec(64), "BIT"):@FM
DataFields := "CONSIGNMENT"             :@VM:SQL_Format(Rec(65), "BIT"):@FM
DataFields := "MU_WAFERS"               :@VM:SQL_Format(Rec(66), "BIT"):@FM
DataFields := "REPORT_EXCLUDE"          :@VM:SQL_Format(Rec(67), "BIT"):@FM
DataFields := "INCO_CODE"               :@VM:SQL_Format(Rec(68), "STR"):@FM
DataFields := "SAP_CUST_NO"             :@VM:SQL_Format(Rec(69), "STR"):@FM
DataFields := "VEND_CD"                 :@VM:SQL_Format(Rec(70), "STR")

// Write the data to the SQL database
Ans = SQL_Write(Connection, "COMPANY", Keys, DataFields)

//-------------------------------------------------------------------------------------------------
// Multi-valued Fields

// Address Lines
If Ans EQ "" AND Rec(5) NE "" then
    
    // List of data fields and their values
    MvFields = "ADDRESS":@FM:SQL_Format(Rec(5), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "COMPANY_ADDRESS_LINES", Keys, MvFields);
    
end

// Phone Numbers
If Ans EQ "" AND Rec(9) NE "" then
    
    // List of data fields and their values
    MvFields  = "PHONES"     :@FM:SQL_Format(Rec(9),  "STR"):@RM
    MvFields := "PHONE_TYPES":@FM:SQL_Format(Rec(10), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "COMPANY_PHONES", Keys, MvFields);
    
end

// International Phone Numbers
If Ans EQ "" AND Rec(11) NE "" then
    
    // List of data fields and their values
    MvFields  = "INTL_PHONES"     :@FM:SQL_Format(Rec(11), "STR"):@RM
    MvFields := "INTL_PHONE_TYPES":@FM:SQL_Format(Rec(12), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "COMPANY_INTL_PHONES", Keys, MvFields);
    
end

// Notes
If Ans EQ "" AND Rec(13) NE "" then
    
    // List of data fields and their values
    MvFields = "NOTE":@FM:SQL_Format(Rec(13), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "COMPANY_NOTES", Keys, MvFields);
    
end

// Shipper Info
If Ans EQ "" AND (Rec(17) NE "" OR Rec(31) NE "") then
    
    // List of data fields and their values
    MvFields  = "SHIPPER_INFO":@FM:SQL_Format(Rec(17), "STR"):@RM
    MvFields := "ACCOUNT_NO"  :@FM:SQL_Format(Rec(31), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "COMPANY_SHIPPER_INFO", Keys, MvFields);
    
end

// Bill-to Address Lines
If Ans EQ "" AND Rec(20) NE "" then
    
    // List of data fields and their values
    MvFields  = "BILL_TO_ADDRESS":@FM:SQL_Format(Rec(20), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "COMPANY_BILL_TO_ADDRESS_LINES", Keys, MvFields);
    
end

// Ship-to Address Lines
If Ans EQ "" AND Rec(26) NE "" then
    
    // List of data fields and their values
    MvFields  = "SHIP_TO_ADDRESS":@FM:SQL_Format(Rec(26), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "COMPANY_SHIP_TO_ADDRESS_LINES", Keys, MvFields);
    
end

// Remit Address Lines
If Ans EQ "" AND Rec(32) NE "" then
    
    // List of data fields and their values
    MvFields  = "VREMIT_ADDR":@FM:SQL_Format(Rec(32), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "COMPANY_VREMIT_ADDR_LINES", Keys, MvFields);
    
end

// Credit Info
If Ans EQ "" AND Rec(45) NE "" then
    
    // List of data fields and their values
    MvFields  = "CREDIT_LIMIT"      :@FM:SQL_Format(Rec(45), "DEC", 2):@RM
    MvFields := "CREDIT_APPROVED_BY":@FM:SQL_Format(Rec(46), "STR"):@RM
    MvFields := "CREDIT_REVIEW_DATE":@FM:SQL_Format(Rec(47), "DATE")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "COMPANY_CREDIT_INFO", Keys, MvFields);
    
end

// Ship to Customer Numbers
If Ans EQ "" AND Rec(63) NE "" then
    
    // List of data fields and their values
    MvFields = "SHIP_TO_CUST_NO":@FM:SQL_Format(Rec(63), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "COMPANY_SHIP_TO_CUST_NOS", Keys, MvFields);
    
end

Return Ans
