

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 账单事件数据源
<a name="data-feed-billing-event"></a>

此数据源提供有关账单事件的信息，包括开发票和付款。

例如，您可以使用此数据源来了解为买家开发票的时间和内容。您还可以使用[示例 SQL 查询](#data-feeds-billing-event-query-examples)来分析来自此数据源的数据。

此数据源包含与您作为其记录卖家的账单事件相关的信息。对于通过渠道合作伙伴达成的协议，此数据源包含有关制造商和记录卖家之间的账单事件的信息。

账单事件数据源每 24 小时刷新一次，因此每天提供的都是新数据。

账单事件数据是不可变的。

下表说明了数据源列的名称和说明。


| 列名称  | 说明  | 
| --- | --- | 
| billing\$1event\$1id | 账单事件的标识符。此 ID 在卖家的环境中是唯一的。 | 
| from\$1account\$1id |  启动账单事件的账户。如果 `transaction_type` 为 `SELLER_REV_SHARE`，则它是买家的付款人账户。这是[账户](data-feed-account.md)数据源的外键。 可用于连接 `account_id` 数据源的 `Account` 字段。  | 
| to\$1account\$1id | 接收产品的交易金额的账户。这是账户数据源的外键。可用于连接 `account_id` 数据源的 `Account` 字段。 | 
| end\$1user\$1account\$1id | 使用产品的账户。此账户可能与买家账户和付款人账户不同。可用于连接 `account_id` 数据源的 `Account` 字段。 | 
| product\$1id | 产品的标识符。这是[产品](data-feed-product.md)数据源的外键。可用于连接 `product_id` 数据源的 `Product` 字段。 | 
| action |  此事件的操作类型。可能值如下所示： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/data-feed-billing-event.html)  | 
| transaction\$1type |  交易的类型。有关示例，请参阅 [征税方案](#data-feeds-billing-event-tax-examples)。可能值如下所示： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/data-feed-billing-event.html)  | 
| parent\$1billing\$1event\$1id |  如果 `broker_id` 的值为 `AWS_INC`，`action` 的值为 `DISBURSED` 或 `FORGIVEN`，`transaction_type` 的值为 `DISBURSEMENT`，则 `parent_billing_event_id` 表示发起此账单事件的原始 `billing_event_id`。如果 `action` 具有其他值，则此字段为空。 当 `broker_id` 的值为 `AWS_EUROPE` 时，`parent_billing_event_id` 表示在以下情况下启动此账单事件的原始 `billing_event_id`： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/data-feed-billing-event.html) 当 `broker_id` 的值为 `AWS_EUROPE`，则 `parent_billing_event_id` 表示在以下情景中上一次成功的支付账单事件的原始 `billing_event_id`： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/data-feed-billing-event.html) 当 `broker_id` 的值为 `AWS_EUROPE` 时，对于所有剩余情景，此字段均为空。  | 
| disbursement\$1billing\$1event\$1id |  `action` 的值为 `DISBURSED` 且以下参数之一为 True 时的相关支付： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/data-feed-billing-event.html) 其他所有情景下，此值为 Null。  | 
| 量 | 账单事件金额。 | 
| currency | ISO 639 币种代码。 | 
| disbursement\$1amount | 付款金额。对于双重开票场景，此字段显示付款金额。对于统一开票场景，此字段为空。 | 
| disbursement\$1currency | 付款金额对应的 ISO 639 货币代码。对于双重开票场景，此字段显示付款货币代码。对于统一开票场景，此字段为空。 | 
| balance\$1impacting | 在计算卖家付款时是否考虑该金额。值为 0 指示显示该金额以供参考，对余额没有影响。值为 1 指示在确定卖家付款时考虑该金额。 | 
| invoice\$1date | 创建发票的日期。 | 
| payment\$1due\$1date |  如果 `action` 的值为 `INVOICED`，则为发票的到期日期。  | 
| usage\$1period\$1start\$1date | 记录中期间的开始日期。 | 
| usage\$1period\$1end\$1date | 记录中期间的结束日期。 | 
| invoice\$1id |  发 AWS 票编号。  | 
| billing\$1address\$1id | 地址数据源中的付款人账单地址参考。可用于连接 `address_id` 数据源的 `Address` 字段。 | 
| transaction\$1reference\$1id |  允许您交叉引用以下报告中的数据的标识符： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/data-feed-billing-event.html)  | 
| bank\$1trace\$1id |  对于支付交易（`transaction_type` = `DISBURSEMENT` 且操作为`DISBURSED`），是银行分配的追踪 ID。追踪 ID 可用于关联卖家银行提供的银行报告。  | 
| broker\$1id |  为交易提供便利的商业实体的标识符。可能值如下所示： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/data-feed-billing-event.html)  | 
| buyer\$1transaction\$1reference\$1id |  一种标识符，它使用 `GROUP BY` 或在 SQL 中构造的窗口函数对账单源中的所有相关记录进行分组。这些相关记录可以包含买家发票、卖家发票和上市费的增值税 (VATs)。  | 
| 操作日期 |  交易事件发生的日期。具体日期取决于操作类型： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/data-feed-billing-event.html)  | 
| 收件人\$1账号\$1id | 在上传数据中接收数据的卖家账户。可用于连接 `account_id` 数据源的 `Account` 字段。 | 
| offer\$1id | 与买家发票单项关联的报价的友好编号。可用于连接 `offer_id` 数据源的 `Offer` 字段。 | 
| 买家发票日期 | 关联的买家发票明细项目的发票日期。 | 
| line\$1item\$1id | 按支出粒度分列的发票明细项目编号。 | 
| buyer\$1line\$1item\$1id | 按支付粒度划分的买家发票单项编号。 | 
| 冲锋变体 | 表示正在买入或卖出什么。 | 
| charge\$1side | 指明卖家是买入还是卖出费用变体。 | 

## 征税方案
<a name="data-feeds-billing-event-tax-examples"></a>

买家和卖家所在国家/地区和州/省实施的征税模式决定了税款的收取和汇款方式。以下是可能的方案：
+ 税款由收缴和汇出。 AWS在这些情况下，`transaction_type` 为 `AWS_TAX_SHARE`。
+ 税款由卖家收取 AWS，支付给卖家，然后由卖家汇给税务机关。在这些情况下，`transaction_type` 为 `SELLER_TAX_SHARE`。
+ 税款不是由收取的 AWS。卖家必须计算税款并将其汇款给税务机关。在这些情况下， AWS Marketplace 不进行税务计算或接收税务信息。卖家从收入份额中支付税款。

## 账单事件数据源示例
<a name="data-feed-billing-event-sample-scenario"></a>

本部分显示开发票时和一个月之后的账单事件数据期间的示例。对于本部分中的所有表，请注意以下各项：
+ 在数据源中，`billing_event_id` 值为 40 个字符的字母数字字符串。为了便于阅读，它们在这里显示为两个字符的字符串。
+ 在数据源中，此信息以单个表格形式显示。为了便于阅读，数据显示在此处的多个表中，并且不显示所有列。

对于本部分中的示例，假定以下内容：
+ Arnav 是买家。
  + 他的账户 ID 是 `737399998888`。
  + 他位于法国，需要遵守电商平台促进法的规定。有关更多信息，请参阅 [Amazon Web Service 税务帮助](https://aws.amazon.com/tax-help/)。
  + 他购买了 `prod-o4grxfafcxxxx` 并因他每月使用该产品而获得了 120.60 美元的发票。
  + 他在当月内支付了发票。
+ Jane 是制造商。
  + 她的账户 ID 是 `111122223333`。
+ Paulo 是记录卖家。
  + 他的账户 ID 是 `777788889999`。
  + 他住在堪萨斯州，这里不受电商平台促进法约束。

### 记录卖家的账单事件数据源
<a name="billing-event-example-seller-of-record"></a>

作为记录卖家，Paulo 向买家 Arnav 开具发票。

下表显示了在 Paulo 向 Arnav 开发票时其数据源中的相关信息。


| billing\$1event\$1id  | from\$1account\$1id  | to\$1account\$1id  | end\$1user\$1account\$1id | product\$1id | action | transaction\$1type | 
| --- | --- | --- | --- | --- | --- | --- | 
| I0 | 737399998888 | 777788889999 | 737399998888 | prod-o4grxfafcxxxx | INVOICED | SELLER\$1REV\$1SHARE | 
| I1 | 737399998888 | 采买 | 737399998888 | prod-o4grxfafcxxxx | INVOICED | AWS\$1TAX\$1分享 | 
| I2 | 777788889999 | 111122223333 | 737399998888 | prod-o4grxfafcxxxx | INVOICED | SELLER\$1REV\$1SHARE | 
| I3 | 777788889999 | 采买 | 737399998888 | prod-o4grxfafcxxxx | INVOICED | AWS\$1REV\$1分享 | 




| parent\$1billing\$1event\$1id | disbursement\$1billing\$1event\$1id | 量 | currency | invoice\$1date | invoice\$1id | 
| --- | --- | --- | --- | --- | --- | 
|  |  | 100 | USD | 2018-12-31T00:00:00Z | 781216640 | 
|  |  | 20.6 | USD | 2018-12-31T00:00:00Z | 781216640 | 
|  |  | -80 | USD | 2018-12-31T00:04:07Z | 788576665 | 
|  |  | -0.2 | USD | 2018-12-31T00:04:07Z | 788576665 | 

下表显示了在 Arnav 支付发票后，月底时 Paulo 数据源中的相关信息。


| billing\$1event\$1id  | from\$1account\$1id  | to\$1account\$1id  | end\$1user\$1account\$1id | product\$1id | action | transaction\$1type | 
| --- | --- | --- | --- | --- | --- | --- | 
| I10 | 737399998888 | 777788889999 | 737399998888 |  | DISBURSED | SELLER\$1REV\$1SHARE | 
| I12 | 777788889999 | 111122223333 | 737399998888 |  | DISBURSED | SELLER\$1REV\$1SHARE | 
| I13 | 777788889999 | 采买 | 737399998888 | prod-o4grxfafcxxxx | DISBURSED | AWS\$1REV\$1分享 | 
| I14 | 采买 | 777788889999 |  |  | DISBURSED | DISBURSEMENT | 




| parent\$1billing\$1event\$1id | disbursement\$1billing\$1event\$1id | 量 | currency | invoice\$1date | invoice\$1id | 
| --- | --- | --- | --- | --- | --- | 
| I0 | I14 | -100 | USD | 2018-12-31T00:00:00Z | 781216640 | 
| I2 | I14 | 80 | USD | 2018-12-31T00:04:07Z | 788576665 | 
| I3 | I14 | 0.2 | USD | 2018-12-31T00:04:07Z | 788576665 | 
|  |  | 19.8 | USD |  |  | 

### 制造商的账单事件数据源
<a name="billing-event-example-manufacturer"></a>

下表显示了在 Paulo 向 Arnav 开发票时 Jane 数据源中的相关信息。


| billing\$1event\$1id  | from\$1account\$1id  | to\$1account\$1id  | end\$1user\$1account\$1id | product\$1id | action | transaction\$1type | 
| --- | --- | --- | --- | --- | --- | --- | 
| I5 | 777788889999 | 111122223333 |  | prod-o4grxfafcxxxx | INVOICED | SELLER\$1REV\$1SHARE | 
| I6 | 777788889999 | 111122223333 |  | prod-o4grxfafcxxxx | INVOICED | SELLER\$1TAX\$1SHARE | 
| I7 | 111122223333 | 采买 |  | prod-o4grxfafcxxxx | INVOICED | AWS\$1REV\$1分享 | 




| parent\$1billing\$1event\$1id | disbursement\$1billing\$1event\$1id | 量 | currency | invoice\$1date | invoice\$1id | 
| --- | --- | --- | --- | --- | --- | 
|  |  | 73.5 |  | 2018-12-31T00:04:07Z | 788576665 | 
|  |  | 6.5 |  | 2018-12-31T00:04:07Z | 788576665 | 
|  |  | -7.35 |  | 2018-12-31T00:04:07Z | 788576665 | 

下表显示了发票支付发票后，月底时 Jane 数据源中的相关信息。


| billing\$1event\$1id  | from\$1account\$1id  | to\$1account\$1id  | end\$1user\$1account\$1id | product\$1id | action | transaction\$1type | 
| --- | --- | --- | --- | --- | --- | --- | 
| I30 | 777788889999 | 111122223333 |  | prod-o4grxfafcxxxx | DISBURSED | SELLER\$1REV\$1SHARE | 
| I31 | 777788889999 | 111122223333 |  | prod-o4grxfafcxxxx | DISBURSED | SELLER\$1TAX\$1SHARE | 
| I32 | 111122223333 | 采买 |  | prod-o4grxfafcxxxx | DISBURSED | AWS\$1REV\$1分享 | 
| I33 | 采买 | 111122223333 |  |  | DISBURSED | DISBURSEMENT | 




| parent\$1billing\$1event\$1id | disbursement\$1billing\$1event\$1id | 量 | currency | invoice\$1date | invoice\$1id | 
| --- | --- | --- | --- | --- | --- | 
| I5 | I33 | -73.5 | USD |  |  | 
| I6 | I33 | -6.5 | USD |  |  | 
| I7 | I33 | 7.35 | USD |  |  | 
|  |  | 72.65 | USD |  |  | 

## 示例查询
<a name="data-feeds-billing-event-query-examples"></a>

如[使用数据源收集和分析数据](data-feed-using.md)中所述，您可以使用 [Athena](https://docs.aws.amazon.com/athena/latest/ug/what-is.html) 对收集并作为数据源存储在托管的 Amazon 存储桶中的数据运行查询。本部分提供了您执行此操作可能采取的常见方法的一些示例。所有示例都假定使用单一币种。

## 示例 1：开具发票的金额，含税
<a name="data-feed-example-query-tax-invoice"></a>

要了解向买家开具发票的金额（含税），您可以运行查询，如以下示例所示。

```
SELECT sum(amount) FROM billing_event 
WHERE 
  action = 'INVOICED'
  AND
  (
    (transaction_type in ('SELLER_REV_SHARE', 'SELLER_TAX_SHARE')
      -- to discard SELLER_REV_SHARE from Manufacturer to Channel Partner, aka cost of goods
      AND to_account_id='seller-account-id'
    )
  OR transaction_type= 'AWS_TAX_SHARE'
  );
```

## 示例 2：代表卖家向买家开具发票的金额
<a name="data-feed-example-query-invoice-for-seller"></a>

要了解代表卖家向买家开具发票的金额，您可以运行查询，如以下示例所示。

```
SELECT sum(amount) FROM billing_event 
WHERE
  action = 'INVOICED'
  AND transaction_type in ('SELLER_REV_SHARE', 'SELLER_TAX_SHARE')
  AND to_account_id='seller-account-id'
;
```

## 示例 3： AWS 可以代表卖家收取的金额
<a name="data-feed-example-query-aws-collect"></a>

要了解 AWS 可以代表卖家收取的金额（减去任何退款、积分和免除的账户），您可以运行查询，如以下示例所示。

```
SELECT sum(amount) FROM billing_event 
WHERE
  -- what is invoiced on behalf of SELLER, incl. refunds/ credits and cost of goods
  transaction_type like 'SELLER_%' 
  -- FORGIVEN action records will "negate" related INVOICED
  and action in ('INVOICED','FORGIVEN') 
;
```

## 示例 4：卖家可以收取的金额
<a name="data-feed-example-query-seller-collect"></a>

要了解卖家可以收取的金额，您可以运行查询，如以下示例所示。此示例删除了房源费用和收取的 AWS 税费，并添加了任何特殊余额调整。

```
SELECT sum(amount) FROM billing_event
WHERE
  (transaction_type like 'SELLER_%' -- what is invoiced on behalf of SELLER
  or transaction_type like 'AWS_REV_%' -- what is owed to AWS
  or transaction_type = 'BALANCE_ADJUSTMENT' -- exceptionnal case
  )
  and action in ('INVOICED','FORGIVEN')
;
```

您也可以使用以下查询来收集相同的信息，如以下示例所示。

```
SELECT sum(amount) FROM billing_event
WHERE
  balance_impacting = 1
  and action in ('INVOICED','FORGIVEN')
;
```

以下示例显示相同信息，但仅限于 2018 年交易，并假定所有买家都按照发票支付了款项。

```
SELECT sum(amount) FROM billing_event
WHERE
  invoice_date between '2018-01-01' and '2018-12-31'
  and balance_impacting = 1
  and action in ('INVOICED','FORGIVEN')
;
```

## 示例 5：支付金额
<a name="data-feed-example-query-disbursements"></a>

要了解已支付的金额，您可以运行查询，如以下示例所示。

```
select sum(amount) FROM billing_event
WHERE
  action ='DISBURSED'
  and transaction_type like 'DISBURSEMENT%'
;
```

## 示例 6：待支付金额
<a name="data-feed-example-query-pending-disbursement"></a>

要了解待支付的金额，您可以运行查询，如以下示例所示。此查询删除了已付款的金额。

```
SELECT sum(amount) FROM billing_event targeted 
WHERE
   (transaction_type like 'SELLER_%'  -- what is invoiced on behalf of SELLER
    or transaction_type like 'AWS_REV_%'  -- what is owed to AWS
    or transaction_type = 'BALANCE_ADJUSTMENT' -- exceptionnal case
   ) 
  -- DISBURSEMENT action records will "negate" 'INVOICED'
  -- but do not take into account failed disbursements
   AND 
    (not exists
      (select 1 
        from billing_event disbursement
          join billing_event failed_disbursement
           on disbursement.billing_event_id=failed_disbursement.parent_billing_event_id
        where
         disbursement.transaction_type='DISBURSEMENT'
         and failed_disbursement.transaction_type='DISBURSEMENT_FAILURE'
         and targeted.disbursement_billing_event_id=disbursement.billing_event_id
      )
    ) 
;
```

获取相同信息的另一种方法是运行查询来获取卖家余额，如以下示例所示。

```
SELECT sum(amount) FROM billing_event
WHERE
 balance_impacting = 1
;
```

以下查询扩展了我们的示例。它将结果限制为 2018 年交易，并返回有关交易的其他详细信息。

```
select sum(residual_amount_per_transaction)
from
 (SELECT
    max(billed_invoices.amount) invoiced_amount,
    sum(nvl(disbursed_invoices.amount,0)) disbursed_amount,
    -- Exercise left to the reader:
    -- use transaction_type to distinguish listing fee vs seller-owed money
    -- still pending collection
    max(transaction_type) transaction_type,
    max(billed_invoices.amount) 
      + sum(nvl(disbursed_invoices.amount,0)) residual_amount_per_transaction
  FROM billing_event billed_invoices
    -- find related disbursements
    left join billing_event disbursed_invoices
      on disbursed_invoices.action='DISBURSED'
      and disbursed_invoices.parent_billing_event_id=billed_invoices.billing_event_id
  WHERE
    billed_invoices.invoice_date between '2018-01-01' and '2018-12-31'
    and billed_invoices.transaction_type like 'SELLER_%' -- invoiced on behalf of SELLER
    and billed_invoices.action in ('INVOICED','FORGIVEN')
    -- do not take into account failed disbursements
    AND not exists
      (select 1 from billing_event failed_disbursement
       where disbursed_invoices.disbursement_billing_event_id = failed_disbursement.parent_billing_event_id
      )
   GROUP BY billed_invoices.billing_event_id
);
```

## 示例 7：一组发票的余额
<a name="data-feed-example-query-balance-invoice-set"></a>

要了解一组发票的总额，您可以运行查询，如以下示例所示。

```
SELECT invoice_id, sum(amount) FROM billing_event targeted
WHERE
  -- invoice_id is only not null for invoiced records AND disbursed records 
  -- linking them to related disbursement -> no need to filter more precisely
  invoice_id in ('XXX','YYY') 
  -- filter out failed disbursements 
  AND not exists
      (select 1 
        from billing_event disbursement
          join billing_event failed_disbursement
           on disbursement.billing_event_id=failed_disbursement.parent_billing_event_id
        where
         disbursement.transaction_type='DISBURSEMENT'
         and failed_disbursement.transaction_type='DISBURSEMENT_FAILURE'
         and targeted.disbursement_billing_event_id=disbursement.billing_event_id
      ) 
  group by invoice_id;
```