# Introduction

## Policy model

A policy is an entity that represents rules according to which the revenue reports in the club need to be made.
Some stores may be excluded from it.

### Example

```json
{
  "policy": {
    "id": 89,
    "period": "week",
    "closing_day": 5,
    "excluded_store_ids": [3],
    "currency": "nok",
    "created_at": "2021-05-11T02:16:43.113Z",
    "updated_at": "2021-05-11T02:16:43.113Z"
  }
}
```

### Definition

Key | Type | Optional | Description
--------------                 | -------    | --------- | ---------
id                             | integer    | no  |
period                         |   enum: ["day", "week", "month", "quarter]   | no  | unit of the report generation frequency - could be one of `day, week, month, quarter`
closing_day                    | integer    | no  | no. of days after period end when reports are expected to be filled
excluded_store_ids             | array[int] | yes | represents the ids of the stores to which the policy is *NOT* assigned (all others are in by default)
currency                       | string     | no  | represents the currency in which the store policy reporting entries will be reported
created_at                     | datetime   | no  | time of the creation
updated_at                     | datetime   | no  | time of the last update

## Tax Category model

### Example

A revenue reporting tax_category is an entity that represents a category of tax to which a revenue report will be assigned. It comprises of name and tax percentage - the name has to be unique within a loyalty club, but the tax percentage is optional and currently not used anywhere.

```json
{
  "tax_category": {
    "id": 89,
    "name": "Revenue reporting tax_category 1",
    "tax_percentage": 23.8,
    "created_at": "2021-05-11T02:16:43.113Z",
    "updated_at": "2021-05-11T02:16:43.113Z"
  }
}
```

### Definition

Key | Type | Optional | Description
--------------                 | -------    | --------- | ---------
id                             | integer    | no  |
name                           | string     | no  | name of the tax category
tax_percentage                 | double     | yes | tax percentage of the tax category
store_ids                      | array[int] | yes | ids of stores associated to the tax category
created_at                     | datetime   | no  | time of the creation
updated_at                     | datetime   | no  | time of the last update

## Report model

```json
{
  "report": {
    "id": 169,
    "policy_id": 1,
    "tax_category_id": 1,
    "period_unit": "week",
    "period_year": 2021,
    "period_number": 30,
    "day": "2021-07-27",
    "transaction_count": 5,
    "value_cents": 324328,
    "value_currency": "nok",
    "user_id": "c1c31507-fb38-474e-acf3-704032011393",
    "member_id": 46953947,
    "deadline_at": "2021-08-02T21:59:59.999Z",
    "filled_at": "2021-08-06T16:06:38.472Z",
    "created_at": "2021-07-27T14:18:09.548Z",
    "updated_at": "2021-08-06T16:06:38.484Z"
  }
}
```

### Definition

Key | Type | Optional | Description
--------- | --------- | --------- | ---------
id | integer | no |
policy_id | integer | no | see [Policy model](doc-341726#report-model)
tax_category_id | integer | no | see [Tax Category model](doc-341726#tax-category-model)
period_unit |  enum: ["day", "week", "month", "quarter]  | no | Reporting period of the policy the report has been made for
period_year | integer | no | Reporting period year
period_number | integer | no | No. of period in the year. Example: **8**th month, **31**st week of the year
day | date | no | Date of report
transaction_count | integer | no | Total count of the transactions for the given day
value_cents | integer | no | Total value of the transactions for the given day in hundredth units
value_currency | string | no | Currency of `value_cents`
user_id | string | yes | user_id of the tenant that has most recently updated the record
member_id | integer | yes | member_id of the tenant that has most recently updated the record
deadline_at | datetime | no | Time of the deadline by which the report has to be filled
filled_at | datetime | yes | Time when the report has been filled by tenant 
created_at | datetime | no | Time of the report creation
updated_at | datetime | no | Time of the last report update