0

如果您的發票擡頭包含多個值(發票編號,日期,位置)和具有多個值(產品,價格,稅額)的未知數量的發票行,是否有辦法將這些數據平鋪到一行,這在發票行數量因發票而異的情況下得以延長?在水壺中使用發票行拼合發票擡頭


輸入例 -

{"InvoiceRecords": [{ 
    "InvoiceDate": "8/9/2017 12:00:00 AM", 
    "InvoiceLocation": "002", 
    "InvoiceNumber": "2004085", 
    "InvoiceRecordHeaderDetails": [{ 
     "InvNum": "2004085", 
     "Location": "002", 
     "InvDate": "8/9/2017 12:00:00 AM" 
    }], 
    "InvoiceRecordLineItemDetails": [{ 
     "UniqueID": "3939934", 
     "InvNum": "2004085", 
     "LINEITEM": "1", 
     "CUSTID": "PREAA", 
     "DEPTID": "320306", 
     "PRODID": "088856", 
     "ProdDesc": "STATE UST", 
     "Unitprice": "0.003", 
     "QuantShare": "237.5", 
     "TaxRate": "7.25", 
     "taxamount": "0.05" 
    }], 
    "InvoiceTaxCodeDetails": [{ 
     "InvNum": "2004085", 
     "LineItem": "1", 
     "UniqueID": "34", 
     "taxCode": "SALES TAX", 
     "taxrate": "7.25", 
     "maxtax": "0" 
    }] 
}]} 

我需要在同一行中的所有項目(允許有更比一個行項目和/或在給定的發票超過一個稅法的項目。記錄


輸出示例(注意:在參考「_n」下面的發票行和稅行可能未定量):

{"InvoiceRecords": [{ 
    "InvoiceDate": "8/9/2017 12:00:00 AM", 
    "InvoiceLocation": "002", 
    "InvoiceNumber": "2004085", 
    "InvoiceRecordHeaderDetailsInvNum": "2004085", 
    "InvoiceRecordHeaderDetailsInvNumLocation": "002", 
    "InvoiceRecordHeaderDetailsInvNumInvDate": "8/9/2017 12:00:00 AM", 
    "InvoiceRecordLineItemDetailsUniqueID_1": "3939934", 
    "InvoiceRecordLineItemDetailsInvNum_1": "2004085", 
    "InvoiceRecordLineItemDetailsLINEITEM_1": "1", 
    "InvoiceRecordLineItemDetailsCUSTID_1": "PREAA", 
    "InvoiceRecordLineItemDetailsDEPTID_1": "320306", 
    "InvoiceRecordLineItemDetailsPRODID_1": "088856", 
    "InvoiceRecordLineItemDetailsProdDesc_1": "STATE UST", 
    "InvoiceRecordLineItemDetailsUnitprice_1": "0.003", 
    "InvoiceRecordLineItemDetailsQuantShare_1": "237.5", 
    "InvoiceRecordLineItemDetailsTaxRate_1": "7.25", 
    "InvoiceRecordLineItemDetailstaxamount_1": "0.05", 
    "InvoiceTaxCodeDetailsInvNum_1": "2004085", 
    "InvoiceTaxCodeDetailsLineItem_1": "1", 
    "InvoiceTaxCodeDetailsUniqueID_1": "34", 
    "InvoiceTaxCodeDetailstaxCode_1": "SALES TAX", 
    "InvoiceTaxCodeDetailstaxrate_1": "7.25", 
    "InvoiceTaxCodeDetailsmaxtax_1": "0", 
    "InvoiceRecordLineItemDetailsUniqueID_n": "3939934", 
    "InvoiceRecordLineItemDetailsInvNum_n": "2004085", 
    "InvoiceRecordLineItemDetailsLINEITEM_n": "1", 
    "InvoiceRecordLineItemDetailsCUSTID_n": "PREAA", 
    "InvoiceRecordLineItemDetailsDEPTID_n": "320306", 
    "InvoiceRecordLineItemDetailsPRODID_n": "088856", 
    "InvoiceRecordLineItemDetailsProdDesc_n": "STATE UST", 
    "InvoiceRecordLineItemDetailsUnitprice_n": "0.003", 
    "InvoiceRecordLineItemDetailsQuantShare_n": "237.5", 
    "InvoiceRecordLineItemDetailsTaxRate_n": "7.25", 
    "InvoiceRecordLineItemDetailstaxamount_n": "0.05", 
    "InvoiceTaxCodeDetailsInvNum_n": "2004085", 
    "InvoiceTaxCodeDetailsLineItem_n": "1", 
    "InvoiceTaxCodeDetailsUniqueID_n": "34", 
    "InvoiceTaxCodeDetailstaxCode_n": "SALES TAX", 
    "InvoiceTaxCodeDetailstaxrate_n": "7.25", 
    "InvoiceTaxCodeDetailsmaxtax_n": "0" 
}]} 

謝謝!

+0

三行示例將非常受歡迎! – AlainD

+0

當然有。問題在於它們有很多,取決於數據的形狀。對於輸入,你有一行後面是任意數量的行。對於您希望每張發票只有一行的輸出。你想要哪種類型的數據你的lineitem數據:一個字符串?數組?一個XML?一個JSON? – AlainD

+0

@AlainD,我發表了一個例子。謝謝! – jag959

回答

0

你有一個samples目錄中類似問題的例子,它位於你的spoon.bat附近。看一下samples/transformation/XML Add並且在第一個choc中生存:他們做更復雜的事情,只是爲了展示所有可能的事情。

在你的情況下,分割爲Switch/Case,輸入流在標題,項目,並設法保持每個發票號碼(稍後更多)。將三個流轉換爲JSON(使用JSON輸出,或者更簡單,使用Javascript)。然後你通過發票號碼Group by項目。通過InvoiceNumber加入三個流程,爲此我建議在頁眉流中輸入lookup stream,然後在頁腳流中輸入其他lookup stream。使用另一個javascript並將數據視爲字符串,可以使用格式爲{header,[item],footer}的格式構建JSON行,您可以將Group by連接爲只有一行。

一些工作,但標準,除了棘手的部分獲取物品和頁腳上的發票號碼,因爲他們已從流中消失。爲此,您可以使用javascript保留值的事實,除非重新定義。添加一個新的啓動腳本[右鍵單擊標籤頂部的Script1,添加一個副本,右鍵單擊剛創建的Script1_0,並將其定義爲啓動腳本]。

在此啓動腳本:

var PrevInvoiceNumber = -1; 

在主腳本:

if(InvoiceNumber && PrevInvoiceNumber!=InvoiceNumber) 
    PrevInvoiceNumber = InvoiceNumber 

那麼你應該看到的數據,每行的PrevInvoiceNumber等於發票的預期InvoiceNumber 。 enter image description here

+0

我認爲這是錯誤問題的正確答案。而且我想你更喜歡我糾正你解決問題的答案。但是我遲到了,你必須等待明天。基本上,它是相同的,除了你閱讀3 JSON輸入(頭,項目,頁腳)的數據,並保持InvoiceNr(這是可能的JSON輸入)。使用序列號生成_n,設置鍵值對,將字段拆分爲行,對它們進行排序並將它們分組到一個輸出中。 – AlainD