Compile function Copy_ORDER_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given ORDER record to the MSSQL database.
	
	History
	-------
	06/14/2010    KRF   Original Programmer
	04/21/2012    KRF   Dropped per David's Request, SQL_MFS Removed so this
	                    won't be called
\*****************************************************************************/

$insert ORDER_EQU

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

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

// List of data fields and their values
DataFields  = "PO"              :@VM:SQL_Format(Rec(ORDER_PO$),               "STR"):@FM
DataFields := "CUST_NO"         :@VM:SQL_Format(Rec(ORDER_CUST_NO$),          "INT"):@FM
DataFields := "NAME_NO"         :@VM:SQL_Format(Rec(ORDER_NAME_NO$),          "INT"):@FM
DataFields := "ENTRY_ID"        :@VM:SQL_Format(Rec(ORDER_ENTRY_ID$),         "STR"):@FM
DataFields := "ENTRY_DATE"      :@VM:SQL_Format(Rec(ORDER_ENTRY_DATE$),       "DATE"):@FM
DataFields := "STATUS"          :@VM:SQL_Format(Rec(ORDER_STATUS$),           "STR"):@FM
DataFields := "CLOSE_DATE"      :@VM:SQL_Format(Rec(ORDER_CLOSE_DATE$),       "DATE"):@FM
DataFields := "TERMS"           :@VM:SQL_Format(Rec(ORDER_TERMS$),            "STR"):@FM
DataFields := "SHIP_VIA"        :@VM:SQL_Format(Rec(ORDER_SHIP_VIA$),         "STR"):@FM
DataFields := "ORDER_NOTES"     :@VM:SQL_Format(Rec(ORDER_ORDER_NOTES$),      "STR"):@FM
DataFields := "INVOICE_NOTES"   :@VM:SQL_Format(Rec(ORDER_INVOICE_NOTES$),    "STR"):@FM
DataFields := "BILL_TO_ATTN"    :@VM:SQL_Format(Rec(ORDER_BILL_TO_ATTN$),     "STR"):@FM
DataFields := "BILL_TO_CITY"    :@VM:SQL_Format(Rec(ORDER_BILL_TO_CITY$),     "STR"):@FM
DataFields := "BILL_TO_STATE"   :@VM:SQL_Format(Rec(ORDER_BILL_TO_STATE$),    "STR"):@FM
DataFields := "BILL_TO_ZIP"     :@VM:SQL_Format(Rec(ORDER_BILL_TO_ZIP$),      "STR"):@FM
DataFields := "SHIP_TO_ATTN"    :@VM:SQL_Format(Rec(ORDER_SHIP_TO_ATTN$),     "STR"):@FM
DataFields := "SHIP_TO_CITY"    :@VM:SQL_Format(Rec(ORDER_SHIP_TO_CITY$),     "STR"):@FM
DataFields := "SHIP_TO_STATE"   :@VM:SQL_Format(Rec(ORDER_SHIP_TO_STATE$),    "STR"):@FM
DataFields := "SHIP_TO_ZIP"     :@VM:SQL_Format(Rec(ORDER_SHIP_TO_ZIP$),      "STR"):@FM
DataFields := "ACCOUNT_NO"      :@VM:SQL_Format(Rec(ORDER_ACCOUNT_NO$),       "STR"):@FM
DataFields := "BILL_TO_COMPANY" :@VM:SQL_Format(Rec(ORDER_BILL_TO_COMPANY$),  "STR"):@FM
DataFields := "SHIP_TO_COMPANY" :@VM:SQL_Format(Rec(ORDER_SHIP_TO_COMPANY$),  "STR"):@FM
DataFields := "AC_ID"           :@VM:SQL_Format(Rec(ORDER_AC_ID$),            "INT"):@FM
DataFields := "BILL_TO_COUNTRY" :@VM:SQL_Format(Rec(ORDER_BILL_TO_COUNTRY$),  "STR"):@FM
DataFields := "SHIP_TO_COUNTRY" :@VM:SQL_Format(Rec(ORDER_SHIP_TO_COUNTRY$),  "STR"):@FM
DataFields := "PO_NO"           :@VM:SQL_Format(Rec(ORDER_PO_NO$),            "STR"):@FM
DataFields := "PO_LINE"         :@VM:SQL_Format(Rec(ORDER_PO_LINE$),          "STR"):@FM
DataFields := "PO_REL"          :@VM:SQL_Format(Rec(ORDER_PO_REL$),           "STR"):@FM
DataFields := "SHIP_ID"         :@VM:SQL_Format(Rec(ORDER_SHIP_ID$),          "STR"):@FM
DataFields := "BILL_TO_CUST_NO" :@VM:SQL_Format(Rec(ORDER_BILL_TO_CUST_NO$),  "STR"):@FM
DataFields := "VISION_ORDER_NO" :@VM:SQL_Format(Rec(ORDER_VISION_ORDER_NO$),  "STR"):@FM
DataFields := "VISION_CUST_NAME":@VM:SQL_Format(Rec(ORDER_VISION_CUST_NAME$), "STR"):@FM
DataFields := "CAPTIVE"         :@VM:SQL_Format(Rec(ORDER_CAPTIVE$),          "BIT"):@FM
DataFields := "CONSIGNMENT"     :@VM:SQL_Format(Rec(ORDER_CONSIGNMENT$),      "BIT"):@FM
DataFields := "INCO_CODE"       :@VM:SQL_Format(Rec(ORDER_INCO_CODE$),        "STR")

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

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

// ORDER_DETAIL
If Ans EQ "" AND Rec(ORDER_QUOTE_IDS$) NE "" then
    
    // List of data fields and their values
    MvFields  = "QUOTE_IDS"    :@FM:SQL_Format(Rec(ORDER_QUOTE_IDS$),     "INT"):@RM
    MvFields := "PROD_SPEC_IDS":@FM:SQL_Format(Rec(ORDER_PROD_SPEC_IDS$), "INT"):@RM
    MvFields := "SCHEDULE_IDS" :@FM:SQL_Format(Rec(ORDER_SCHEDULE_IDS$),  "INT"):@RM
    MvFields := "WO"           :@FM:SQL_Format(Rec(ORDER_WO$),            "INT"):@RM
    MvFields := "PART_NUM"     :@FM:SQL_Format(Rec(ORDER_PART_NUM$),      "STR"):@RM
    MvFields := "WAF_INV_IDS"  :@FM:SQL_Format(Rec(ORDER_WAF_INV_IDS$),   "INT"):@RM
    MvFields := "SUB_PART_NUM" :@FM:SQL_Format(Rec(ORDER_SUB_PART_NUM$),  "STR"):@RM
    MvFields := "LOT_NUM"      :@FM:SQL_Format(Rec(ORDER_LOT_NUM$),       "STR"):@RM
    MvFields := "SETUP_CHARGE" :@FM:SQL_Format(Rec(ORDER_SETUP_CHARGE$),  "DEC", 2):@RM
    MvFields := "SRP_CHARGE"   :@FM:SQL_Format(Rec(ORDER_SRP_CHARGE$),    "DEC", 2):@RM
    MvFields := "QUANTITY"     :@FM:SQL_Format(Rec(ORDER_QUANTITY$),      "INT"):@RM
    MvFields := "PRICE"        :@FM:SQL_Format(Rec(ORDER_PRICE$),         "DEC", 2)
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "ORDER_TABLE_ORDER_DETAIL", Keys, MvFields);
    
end

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

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

// WO_KEYS
* If Ans EQ "" AND Rec(ORDER_WO_KEYS$) NE "" then
*    
*    Keys  = "SEQ":@VM:SQL_Format(Key,                 "INT"):@FM
*    Keys := "WO" :@VM:SQL_Format(Rec(ORDER_WO_KEYS$), "INT")
*    
*    // Write the data to the SQL database
*    Ans = SQL_Write(Connection, "ORDER_TABLE_WO_KEYS", Keys, "")
*    
* end

// SHIP_CO_CUST_NO
* If Ans EQ "" AND Rec(ORDER_SHIP_TO_CUST_NO$) NE "" then
*    
*    Keys  = "SEQ"    :@VM:SQL_Format(Key,                         "INT"):@FM
*    Keys := "CUST_NO":@VM:SQL_Format(Rec(ORDER_SHIP_TO_CUST_NO$), "INT")
*    
*    // Write the data to the SQL database
*    Ans = SQL_Write(Connection, "ORDER_TABLE_SHIP_TO_CUST_NO", Keys, "")
*    
* end

Return Ans
