Compile function Copy_INVOICE_Record_To_SQL(Connection, Key, Record)

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

$insert INVOICE_EQU

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

// Parse record into a dimensioned array for speed
Dim Rec(49)
MatParse Record into Rec
					    
// List of key names and their values
Keys  = "INV_NO":@VM:SQL_Format(Field(Key, "*", 1), "STR")

// List of data fields and their values
DataFields  = "ORDER_NO"       :@VM:SQL_Format(Rec(INVOICE_ORDER_NO$),        "INT"):@FM
DataFields := "CUST_NO"        :@VM:SQL_Format(Rec(INVOICE_CUST_NO$),         "INT"):@FM
DataFields := "PO"             :@VM:SQL_Format(Rec(INVOICE_PO$),              "STR"):@FM
DataFields := "ENTRY_ID"       :@VM:SQL_Format(Rec(INVOICE_ENTRY_ID$),        "STR"):@FM
DataFields := "ENTRY_DATE"     :@VM:SQL_Format(Rec(INVOICE_ENTRY_DATE$),      "DATE"):@FM
DataFields := "SHIP_DATE"      :@VM:SQL_Format(Rec(INVOICE_SHIP_DATE$),       "DATE"):@FM
DataFields := "DUE_DATE"       :@VM:SQL_Format(Rec(INVOICE_DUE_DATE$),        "DATE"):@FM
DataFields := "STATUS"         :@VM:SQL_Format(Rec(INVOICE_STATUS$),          "STR"):@FM
DataFields := "BILL_TO_ATTN"   :@VM:SQL_Format(Rec(INVOICE_BILL_TO_ATTN$),    "STR"):@FM
DataFields := "BILL_TO_CITY"   :@VM:SQL_Format(Rec(INVOICE_BILL_TO_CITY$),    "STR"):@FM
DataFields := "BILL_TO_STATE"  :@VM:SQL_Format(Rec(INVOICE_BILL_TO_STATE$),   "STR"):@FM
DataFields := "BILL_TO_ZIP"    :@VM:SQL_Format(Rec(INVOICE_BILL_TO_ZIP$),     "STR"):@FM
DataFields := "SHIP_TO_ATTN"   :@VM:SQL_Format(Rec(INVOICE_SHIP_TO_ATTN$),    "STR"):@FM
DataFields := "SHIP_TO_CITY"   :@VM:SQL_Format(Rec(INVOICE_SHIP_TO_CITY$),    "STR"):@FM
DataFields := "SHIP_TO_STATE"  :@VM:SQL_Format(Rec(INVOICE_SHIP_TO_STATE$),   "STR"):@FM
DataFields := "SHIP_TO_ZIP"    :@VM:SQL_Format(Rec(INVOICE_SHIP_TO_ZIP$),     "STR"):@FM
DataFields := "TERMS"          :@VM:SQL_Format(Rec(INVOICE_TERMS$),           "STR"):@FM
DataFields := "SHIP_VIA"       :@VM:SQL_Format(Rec(INVOICE_SHIP_VIA$),        "STR"):@FM
DataFields := "ACCOUNT_NO"     :@VM:SQL_Format(Rec(INVOICE_ACCOUNT_NO$),      "STR"):@FM
DataFields := "INVOICE_NOTES"  :@VM:SQL_Format(Rec(INVOICE_INVOICE_NOTES$),   "STR"):@FM
DataFields := "OTHER_NOTES"    :@VM:SQL_Format(Rec(INVOICE_OTHER_NOTES$),     "STR"):@FM
DataFields := "DISCOUNT_AMOUNT":@VM:SQL_Format(Rec(INVOICE_DISCOUNT_AMOUNT$), "STR"):@FM
DataFields := "FREIGHT_AMOUNT" :@VM:SQL_Format(Rec(INVOICE_FREIGHT_AMOUNT$),  "STR"):@FM
DataFields := "BOX_CNT"        :@VM:SQL_Format(Rec(INVOICE_BOX_CNT$),         "INT"):@FM
DataFields := "BILL_TO_COMPANY":@VM:SQL_Format(Rec(INVOICE_BILL_TO_COMPANY$), "STR"):@FM
DataFields := "SHIP_TO_COMPANY":@VM:SQL_Format(Rec(INVOICE_SHIP_TO_COMPANY$), "STR"):@FM
DataFields := "PLANT"          :@VM:SQL_Format(Rec(INVOICE_PLANT$),           "STR"):@FM
DataFields := "SHIP_NO"        :@VM:SQL_Format(Rec(INVOICE_SHIP_NO$),         "STR")

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

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

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

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

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

// INVOICE_CHECK_INFO
If Ans EQ "" AND Rec(INVOICE_CHECK_NO$) NE "" then
    
    // List of data fields and their values
    MvFields  = "CHECK_NO"    :@FM:SQL_Format(Rec(INVOICE_CHECK_NO$),     "STR"):@RM
    MvFields := "CHECK_DATE"  :@FM:SQL_Format(Rec(INVOICE_CHECK_DATE$),   "DATE"):@RM
    MvFields := "CHECK_AMOUNT":@FM:SQL_Format(Rec(INVOICE_CHECK_AMOUNT$), "DEC", 2)
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "INVOICE_CHECK_INFO", Keys, MvFields);
    
end

// INVOICE_DETAIL
If Ans EQ "" AND Rec(INVOICE_ORDER_LINE_ITEM$) NE "" then
    
    // List of data fields and their values
    MvFields  = "ORDER_LINE_ITEM":@FM:SQL_Format(Rec(INVOICE_ORDER_LINE_ITEM$), "INT"):@RM
    MvFields := "QUOTE_IDS"      :@FM:SQL_Format(Rec(INVOICE_QUOTE_IDS$),       "STR"):@RM
    MvFields := "SCHEDULE_IDS"   :@FM:SQL_Format(Rec(INVOICE_SCHEDULE_IDS$),    "STR"):@RM
    MvFields := "WO"             :@FM:SQL_Format(Rec(INVOICE_WO$),              "INT"):@RM
    MvFields := "PART_NUM"       :@FM:SQL_Format(Rec(INVOICE_PART_NUM$),        "STR"):@RM
    MvFields := "LOT_NUM"        :@FM:SQL_Format(Rec(INVOICE_LOT_NUM$),         "STR"):@RM
    MvFields := "GL_ACCT"        :@FM:SQL_Format(Rec(INVOICE_GL_ACCT$),         "STR"):@RM
    MvFields := "SETUP_CHARGE"   :@FM:SQL_Format(Rec(INVOICE_SETUP_CHARGE$),    "DEC", 2):@RM
    MvFields := "SRP_CHARGE"     :@FM:SQL_Format(Rec(INVOICE_SRP_CHARGE$),      "DEC", 2):@RM
    MvFields := "QUANTITY"       :@FM:SQL_Format(Rec(INVOICE_QUANTITY$),        "INT"):@RM
    MvFields := "REJECTS"        :@FM:SQL_Format(Rec(INVOICE_REJECTS$),         "INT"):@RM
    MvFields := "UNPROCESSED"    :@FM:SQL_Format(Rec(INVOICE_UNPROCESSED$),     "INT"):@RM
    MvFields := "PRICE"          :@FM:SQL_Format(Rec(INVOICE_PRICE$),           "DEC", 2):@RM
    MvFields := "OD_ITEM_NO"     :@FM:SQL_Format(Rec(INVOICE_OD_ITEM_NO$),      "INT")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "INVOICE_DETAIL", Keys, MvFields);
    
end

Return Ans
