@frontend_royalties
@ows_royalties
@ows_abacus_contract
@ows_payment
@graphql_abacus
@graphql_tax_payment
@lambda_documents
@lambda_documents_payout_all
Feature: Abacus Contract Advances 2

  @TAP-809
  @id_335591a9c4e98adaa8f2036a514bb45f562d3ed3ab8e9854682860f7fc007cb3
  Scenario: Delete pending advance
    Given an orchard employee label_7123_admin_3 for abacus
    When 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
    And I have a new Distribution contract lifecycle created with accounts created for AWAL Recordings America, Inc.
    And I should be able to add pending contract advance with milestone type: Delivery
    Then I should be able to delete pending advance

  @TAP-727
  @id_b003a50f93901b819c2602f76810d91ca27ed905fcae2c5ee3e2e4f459213019
  Scenario: Add contract paid advance
    Given an orchard employee label_7123_admin_3 for abacus
    When 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
    And I have a new Distribution contract lifecycle created with accounts created for AWAL Recordings America, Inc.
    Then I should be able to add paid contract advance

  @TAP-726
  @id_ac5d1788c1ab2c4470003cbcc7fe577bf39963d9cf400227287ede730d94c2aa
  Scenario: contract advance post tax payable amount calculation
    Given an orchard employee label_7123_admin_3 for abacus
    When 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
    And I have a new Distribution contract lifecycle created with accounts created for AWAL Recordings America, Inc.
    Then post tax payable amount calculation should work as expected

  @TAP-781
  @TAP-787
  @id_4d6f496e95d7ebcc463a7c72d6f32030bcc8eadda2d28c0560d144ba92aa51a6
  Scenario: advance paid 'via abacus' should lead to a payment creation and land in queued table
    Given an orchard employee label_7123_admin_3 for abacus
    When 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 active account via API
    And I have a Distribution runcontroller created
    And I have a new Distribution contract lifecycle created with accounts created for AWAL Recordings America, Inc.
    When I create contract advance with method <Payoneer via Abacus>
    When it should lead to a payment creation
    And should land in Queued advances section once payment is created

  @TAP-755
  @id_46eb44b1b459ddb00ba7d9830af52b1fb9f700cc3ae38d456f49a37b9511f5e8
  Scenario: Add specific advance
    Given an orchard employee label_7123_admin_3 for abacus
    When 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 active account via API
    And I have a Distribution runcontroller created
    And I have a new Distribution contract lifecycle created with accounts created for AWAL Recordings America, Inc.
    Then I create contract advance with method <Payoneer via Abacus>
    When I should be able to add advance for a specific contract
    And I should be able to see the advance on payments page -> advances tab

  @TAP-787
  @TAP-728
  @id_ac2ca1393109bc347ce48d9bcb7da79dd872890c333b97e9c3469bd274807809
  Scenario: Contract advance payment detail overview section
    Given an orchard employee label_7123_admin_3 for abacus
    When 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 active account via API
    And I have a Distribution runcontroller created
    And I have a new Distribution contract lifecycle created with accounts created for AWAL Recordings America, Inc.
    Then I create contract advance with method <Payoneer via Abacus>
    When I should be able to add advance for a specific contract
    When I should be able to view contract advance payment detail overview section

  # WIPed: 19.03.2025
  # TODO: un-wip once TAP-2098 is closed
  @wip
  @TAP-782
  @TAP-784
  @TAP-785
  @id_7b10d6da101e0480e41da1cc99ba1e384712d56a791979c0167d40827248f41e
  Scenario: Advance Payment - Contract Admin/Finance Admin/Approve Payment/Send Payment flows
    Given an orchard employee label_7123_admin_3 for abacus
    When 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 active account via API
    And I have a Distribution runcontroller created
    And I have a new Distribution contract lifecycle created with accounts created for AWAL Recordings America, Inc.
    Then I create contract advance with method <Payoneer via Abacus>
    When I should be able to add advance for a specific contract
    And I should be able to approve the advance payment: add salesforceId
    # it should be different user who's reviewing salesforceId correctness
    And an orchard employee label_7123_admin_2 for abacus
    When I log in
    And I should be able to approve the advance payment: review salesforceId
    And I should be able to approve the advance payment: confirm funds
    And I should be able to approve the advance payment: approve payment
    And I should be able to approve the advance payment: verify results

  # WIPed: 19.03.2025
  # TODO: un-wip once TAP-2098 is closed
  @wip
  @TAP-790
  @id_54d90fb1dddaf8baf83cdf3b02722b7f17e7715247c17444a1aa05678b3621bb
  Scenario: Advance Payment - Failure Handling
    Given an orchard employee label_7123_admin_3 for abacus
    When 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 active account via API
    And I have a Distribution runcontroller created
    And I have a new Distribution contract lifecycle created with accounts created for AWAL Recordings America, Inc.
    Then I create contract advance with method <Payoneer via Abacus>
    When I should be able to add advance for a specific contract
    And I should be able to approve advance payment
    # since we're not sending a real payment it ends up in a 'cancelled by payoneer' state
    # in this case user should be able to make corrections and send a new payment
    Then in case of unsuccessful payment I should be able to issue a new payment
    And I should be able to see updated advance payment
    And I should be able to see advance on contract's detail page

  @TAP-782
  @id_b340c0a745f309717e4d1b7c49b803e1f0536ab751574c8e068a4dbb3b32463b
  Scenario: Advance Payment Approval - SalesforceId can't be reused
    Given an orchard employee label_7123_admin_3 for abacus
    When 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 active account via API
    And I have a Distribution runcontroller created
    And I have a new Distribution contract lifecycle created with accounts created for AWAL Recordings America, Inc.
    Then I create contract advance with method <Payoneer via Abacus>
    When I should be able to add advance for a specific contract
    When I should be able to approve the advance payment: add salesforceId
    And I have another contract advance created with method <Payoneer via Abacus>
    Then I should not be able to reuse SalesforceId
