@frontend_royalties
@ows_abacus_contract
@ACC-7983
Feature: Abacus Contracts Flowthrough 1

  @id_15e05d9e52b4136f874ea8d29d1c2b691ddf717bc64379eb4ebce7d68d619578
  Scenario Outline: add contract flowthrough
    Given an orchard employee label_7123_admin_2 for abacus
    And I log in
    And I prepare an abacus account data:
      | Key              | Value                   |
      | companyBrandName | awal                    |
      | paidBy           | AWAL-US                 |
      | agreementType    | AWAL Core               |
      | currency         | EUR                     |
      | owner            | awal                    |
      | paymentMinimum   | 123                     |
      | paymentSchedule  | 45 days after month end |
    And I create 1 new account via API
    And I have a Distribution runcontroller created
    When I have a new Distribution contract lifecycle created with accounts created for AWAL Recordings America, Inc.
    And I prepare an abacus contract flowthrough data:
      | Key             | Value             |
      | flowthroughRate | <flowthroughRate> |
      | calculation     | <calculation>     |
      | recoupmentCap   | <recoupmentCap>   |
      | comment         | <comment>         |
    Then I should be able to add Contract Flowthrough
    Then I should be able to see the Contract Flowthrough on contract details page
    Then I should be able to delete the Contract Flowthrough

    Examples:
      | calculation                                | flowthroughRate | recoupmentCap | comment                      |
      | (Net Revenue * FT%) - Expenses             | 10              |               |                              |
      | (Net Revenue - Expenses) * FT%             | 10              |               |                              |
      | Net Revenue * FT%                          | 10              |               |                              |
      | Gross Revenue * FT%                        | 10              |               |                              |
      | Net Revenue + Adjustments - Recoupment Cap |                 | 100           |                              |
      | Manual                                     |                 |               | Manual override test comment |

  @id_c5f54df308a37db5699f86ff37b9c0feb2b16164b8e6c3f433d80a20238ef8d5
  Scenario: edit contract flowthrough
    Given an orchard employee label_7123_admin_2 for abacus
    And I log in
    And I prepare an abacus account data:
      | Key              | Value                   |
      | companyBrandName | awal                    |
      | paidBy           | AWAL-US                 |
      | agreementType    | AWAL Core               |
      | currency         | EUR                     |
      | owner            | awal                    |
      | paymentMinimum   | 123                     |
      | paymentSchedule  | 45 days after month end |
    And I create 1 new account via API
    And I have a Distribution runcontroller created
    When I have a new Distribution contract lifecycle created with accounts created for AWAL Recordings America, Inc.
    And I prepare an abacus contract flowthrough data:
      | Key             | Value                          |
      | flowthroughRate | 3                              |
      | calculation     | (Net Revenue - Expenses) * FT% |
    Then I should be able to add Contract Flowthrough
    Then I should be able to see the Contract Flowthrough on contract details page
    And I should be able to edit Contract Flowthrough

  Rule: Flowthrough defaults
    - flowthrough recoupmentCap is set to null if not provided
    - flowthroughRate can be explicitly set to 0

    @ACC-8687
    @id_ad8dee8c5329c69584e7ceff2ceaff2ecd2f2fb6d6301604947d3806d9c92350
    Scenario: should default recoupmentCap to null and allow flowthroughRate = 0
      Given an orchard employee label_7123_admin_2 for abacus
      And I log in
      And I prepare an abacus account data:
        | Key              | Value                   |
        | companyBrandName | awal                    |
        | paidBy           | AWAL-US                 |
        | agreementType    | AWAL Core               |
        | currency         | EUR                     |
        | owner            | awal                    |
        | paymentMinimum   | 123                     |
        | paymentSchedule  | 45 days after month end |
      And I create 1 new account via API
      And I have a Distribution runcontroller created
      When I have a new Distribution contract lifecycle created with accounts created for AWAL Recordings America, Inc.
      And I prepare an abacus contract flowthrough data:
        | Key             | Value                          |
        | flowthroughRate | 0                              |
        | calculation     | (Net Revenue - Expenses) * FT% |
        | recoupmentCap   |                                |
      Then I should be able to add Contract Flowthrough
      # the check for recoupment cap == null is within contractDetailsPage.checkContractFlowthrough() method
      Then I should be able to see the Contract Flowthrough on contract details page
