

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 帳單事件資料摘要
<a name="data-feed-billing-event"></a>

此資料摘要提供帳單事件的相關資訊，包括開立發票和支出。

例如，您可以使用此資料摘要來了解買方開立發票的時間和項目。您也可以使用[範例 SQL 查詢](#data-feeds-billing-event-query-examples)來分析來自此資料饋送的資料。

此資料摘要包含與您是記錄賣方的帳單事件相關的資訊。對於透過管道合作夥伴所簽訂的協議，此資料饋送包含製造商與記錄賣方之間帳單事件的相關資訊。

帳單事件資料饋送每 24 小時重新整理一次，因此新資料每天可用。

帳單事件資料不可變。

下表說明資料饋送資料欄的名稱和描述。


| 欄名稱  | Description  | 
| --- | --- | 
| billing\_event\_id | 帳單事件的識別符。此 ID 在賣方環境中是唯一的。 | 
| from\_account\_id | 啟動帳單事件的帳戶。如果 `transaction_type`是 `SELLER_REV_SHARE`，則它是買方的付款人帳戶。這是[帳戶](data-feed-account.md)資料饋送的外部金鑰。<br />可用於加入 `account_id` 欄位上的`Account`資料饋送。 | 
| to\_account\_id | 接收產品交易金額的帳戶。這是帳戶資料饋送的外部金鑰。可用於加入 `account_id` 欄位上的`Account`資料饋送。 | 
| end\_user\_account\_id | 使用產品的 帳戶。此帳戶可能與買方和付款人帳戶不同。可用於加入 `account_id` 欄位上的`Account`資料饋送。 | 
| product\_id | 產品的識別符。這是[產品](data-feed-product.md)資料饋送的外部金鑰。可用於加入 `product_id` 欄位上的`Product`資料饋送。 | 
| 動作 | 此事件的動作類型。可能的值如下：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/marketplace/latest/userguide/data-feed-billing-event.html) | 
| transaction\_type | 交易的類型。如需範例，請參閱 [稅務案例](#data-feeds-billing-event-tax-examples)。可能的值如下：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/marketplace/latest/userguide/data-feed-billing-event.html) | 
| parent\_billing\_event\_id | 當 的值`broker_id`為 時`AWS_INC`， 的值`action`為 `DISBURSED`或 `FORGIVEN`，而 的值`transaction_type`為 時`DISBURSEMENT`， `parent_billing_event_id`是指起始此帳單事件`billing_event_id`的原始 。如果 `action`有另一個值，則此欄位為 null。<br />當 的值`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_tw/marketplace/latest/userguide/data-feed-billing-event.html)<br />當 的值`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_tw/marketplace/latest/userguide/data-feed-billing-event.html)<br />當 的值`broker_id`為 時`AWS_EUROPE`，此欄位在所有剩餘的案例中皆為 null。 | 
| disbursement\_billing\_event\_id | 當 的值`action`為 `DISBURSED`且下列其中一項為 true 時，相關的支出：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/marketplace/latest/userguide/data-feed-billing-event.html)<br />在所有其他情況下，此值為 null。 | 
| amount | 帳單事件金額。 | 
| currency | ISO 639 貨幣代碼。 | 
| disbursement\_amount | 支出金額。對於雙發票案例，此欄位包含支出金額。對於統一發票案例，此欄位為 null。 | 
| disbursement\_currency | 支出金額的 ISO 639 貨幣代碼。對於雙發票案例，此欄位包含支出貨幣代碼。對於統一發票案例，此欄位為 null。 | 
| balance\_impacting | 在計算賣方支出時，是否會考慮金額。值 0 表示金額僅供參考，對餘額沒有影響。值 1 表示此金額在決定賣方支出時已納入考量。 | 
| invoice\_date | 發票建立的日期。 | 
| payment\_due\_date | 當 的值`action`為 時`INVOICED`，發票的到期日。 | 
| usage\_period\_start\_date | 記錄中期間的開始日期。 | 
| usage\_period\_end\_date | 記錄中期間的結束日期。 | 
| invoice\_id |  AWS 發票 ID。 | 
| billing\_address\_id | 地址資料摘要中的付款人帳單地址參考。可用於加入 `address_id` 欄位上的`Address`資料饋送。 | 
| transaction\_reference\_id | 可讓您從下列報告交叉參考資料的識別符：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/marketplace/latest/userguide/data-feed-billing-event.html) | 
| bank\_trace\_id | 對於支出交易 (`transaction_type` =is `DISBURSEMENT`且動作為 `DISBURSED`)，由銀行指派的追蹤 ID。追蹤 ID 可用來與賣方銀行提供的報告建立關聯。 | 
| broker\_id | 促進交易之商業實體的識別符。可能的值如下：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/marketplace/latest/userguide/data-feed-billing-event.html) | 
| buyer\_transaction\_reference\_id | 使用 `GROUP BY`或 SQL 中的視窗函數建構，將帳單摘要中所有相關記錄分組在一起的識別符。這些相關記錄可包含買方發票、賣方發票，以及列出費用的增值稅 VATs)。 | 
| action\_date | 交易事件發生的日期。特定日期取決於動作類型：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/marketplace/latest/userguide/data-feed-billing-event.html) | 
| recipient\_account\_id | 接收摘要中資料的賣方帳戶。<br />可用於加入 `account_id` 欄位上的`Account`資料饋送。 | 
| offer\_id | 與買方發票明細項目相關聯的優惠的易記 ID。<br />可用於加入 `offer_id` 欄位上的`Offer`資料饋送。 | 
| buyer\_invoice\_date | 相關聯買方發票明細項目的發票日期。 | 
| line\_item\_id | 發票明細項目 ID，以支付精細程度表示。 | 
| buyer\_line\_item\_id | 支付精細度的買方發票明細項目 ID。 | 
| charge\_variant | 指出正在購買或銷售的項目。 | 
| charge\_side | 指出賣方是購買還是銷售費用變體。 | 

## 稅務案例
<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 Tax Help](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\_event\_id  | from\_account\_id  | to\_account\_id  | end\_user\_account\_id | product\_id | 動作 | transaction\_type | 
| --- | --- | --- | --- | --- | --- | --- | 
| I0 | 737399998888 | 777788889999 | 737399998888 | prod-o4grxfafcxxxx | 已開立發票 | SELLER\_REV\_SHARE | 
| I1 | 737399998888 | AWS | 737399998888 | prod-o4grxfafcxxxx | 已開立發票 | AWS\_TAX\_SHARE | 
| I2 | 777788889999 | 111122223333 | 737399998888 | prod-o4grxfafcxxxx | 已開立發票 | SELLER\_REV\_SHARE | 
| I3 | 777788889999 | AWS | 737399998888 | prod-o4grxfafcxxxx | 已開立發票 | AWS\_REV\_SHARE | 




| parent\_billing\_event\_id | disbursement\_billing\_event\_id | amount | currency | invoice\_date | invoice\_id | 
| --- | --- | --- | --- | --- | --- | 
|  |  | 100 | 美元 | 2018-12-31T00：00：00Z | 781216640 | 
|  |  | 20.6 | 美元 | 2018-12-31T00：00：00Z | 781216640 | 
|  |  | -80 | 美元 | 2018-12-31T00：04：07Z | 788576665 | 
|  |  | -0.2 | 美元 | 2018-12-31T00：04：07Z | 788576665 | 

下表顯示在 Arnav 支付發票之後，月底 Paulo 資料饋送中的相關資訊。


| billing\_event\_id  | from\_account\_id  | to\_account\_id  | end\_user\_account\_id | product\_id | 動作 | transaction\_type | 
| --- | --- | --- | --- | --- | --- | --- | 
| I10 | 737399998888 | 777788889999 | 737399998888 |  | 分發 | SELLER\_REV\_SHARE | 
| I12 | 777788889999 | 111122223333 | 737399998888 |  | 分發 | SELLER\_REV\_SHARE | 
| I13 | 777788889999 | AWS | 737399998888 | prod-o4grxfafcxxxx | 分發 | AWS\_REV\_SHARE | 
| I14 | AWS | 777788889999 |  |  | 分發 | 支出 | 




| parent\_billing\_event\_id | disbursement\_billing\_event\_id | amount | currency | invoice\_date | invoice\_id | 
| --- | --- | --- | --- | --- | --- | 
| I0 | I14 | -100 | 美元 | 2018-12-31T00：00：00Z | 781216640 | 
| I2 | I14 | 80 | 美元 | 2018-12-31T00：04：07Z | 788576665 | 
| I3 | I14 | 0.2 | 美元 | 2018-12-31T00：04：07Z | 788576665 | 
|  |  | 19.8 | 美元 |  |  | 

### 製造商的帳單事件資料摘要
<a name="billing-event-example-manufacturer"></a>

下表顯示 Paulo 發票 Arnav 時 Jane 資料饋送中的相關資訊。


| billing\_event\_id  | from\_account\_id  | to\_account\_id  | end\_user\_account\_id | product\_id | 動作 | transaction\_type | 
| --- | --- | --- | --- | --- | --- | --- | 
| I5 | 777788889999 | 111122223333 |  | prod-o4grxfafcxxxx | 已開立發票 | SELLER\_REV\_SHARE | 
| I6 | 777788889999 | 111122223333 |  | prod-o4grxfafcxxxx | 已開立發票 | SELLER\_TAX\_SHARE | 
| I7 | 111122223333 | AWS |  | prod-o4grxfafcxxxx | 已開立發票 | AWS\_REV\_SHARE | 




| parent\_billing\_event\_id | disbursement\_billing\_event\_id | amount | currency | invoice\_date | invoice\_id | 
| --- | --- | --- | --- | --- | --- | 
|  |  | 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\_event\_id  | from\_account\_id  | to\_account\_id  | end\_user\_account\_id | product\_id | 動作 | transaction\_type | 
| --- | --- | --- | --- | --- | --- | --- | 
| I30 | 777788889999 | 111122223333 |  | prod-o4grxfafcxxxx | 分發 | SELLER\_REV\_SHARE | 
| I31 | 777788889999 | 111122223333 |  | prod-o4grxfafcxxxx | 分發 | SELLER\_TAX\_SHARE | 
| I32 | 111122223333 | AWS |  | prod-o4grxfafcxxxx | 分發 | AWS\_REV\_SHARE | 
| I33 | AWS | 111122223333 |  |  | 分發 | 支出 | 




| parent\_billing\_event\_id | disbursement\_billing\_event\_id | amount | currency | invoice\_date | invoice\_id | 
| --- | --- | --- | --- | --- | --- | 
| I5 | I33 | -73.5 | 美元 |  |  | 
| I6 | I33 | -6.5 | 美元 |  |  | 
| I7 | I33 | 7.35 | 美元 |  |  | 
|  |  | 72.65 | 美元 |  |  | 

## 查詢範例
<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 S3 儲存貯體中收集並儲存為資料饋送的資料執行查詢。本節提供一些您可能這麼做的常見方式範例。所有範例都假設使用單一貨幣。

## 範例 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;
```