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"
}]}

谢谢!

4

1 回答 1

0

samples您在spoon.bat 附近的目录中有一个类似问题的示例。看看samples/transformation/XML Add第一个巧克力并幸存下来:他们做的事情要复杂得多,只是为了展示所有可能的东西。

在您的情况下,使用 a 拆分,Switch/Case标题中的输入流,项目并设法在每个上保留 InvoiceNumber(稍后会详细介绍)。将三个流转换为 JSON(使用 JSON 输出,或者可能更简单,使用 a Javascript)。然后你Group by按 InvoiceNumber 的项目。通过 InvoiceNumber 加入三个流,为此我建议lookup stream在标题流中使用一个,然后lookup stream在页脚流中使用另一个。使用另一个javascript并将数据视为字符串,您可以以 { header, [item], footer} 格式构建 JSON 行,您可以Group by将其连接起来以仅包含一行。

一些工作,但相当标准,除了在项目和页脚上获取 InvoiceNumber 的棘手部分,因为它们已从流程中消失。javascript为此,您可以使用保留值的事实,除非重新定义。添加一个新的启动脚本[右键单击选项卡顶部的Script1,添加一个副本,右键单击刚刚创建的Script1_0,并将其定义为启动脚本]。

在这个启动脚本上:

var PrevInvoiceNumber = -1;

在主脚本上:

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

然后您应该会在每行看到 PrevInvoiceNumber 的数据,它等于发票的预期 InvoiceNumber。在此处输入图像描述

于 2017-10-11T14:29:54.007 回答