# SAP Sync Contracts

## Description

Sync contracts with SAP in bulk.

[Jira ACC-8634](https://theorchard.atlassian.net/browse/ACC-8634)

## Running in Prod

You may encounter issues reaching prod resources on your local machine, regardless of VPN or other network configurations.

If so, you can [create a dev box](https://www.notion.so/AWS-Dev-Boxes-9736a3abda964fcaa530c9a7b1947df7?source=copy_link#1686b244609447a19cdad3be62b9c90c) or access the shared jump box and run the script there. See [SSH key setup for dev boxes / jump box](https://www.notion.so/SSH-key-setup-for-dev-boxes-jump-box-5689b3c8cb204b63b488a179fecea9d5?source=copy_link) for instructions.

Optional: Once setup, the [Remote - SSH](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh) VS Code extension is useful. It opens a workspace that points to the remote machine, allowing you to develop / run the script the same way you would locally.

## Instructions

1. Get your list of contract IDs. For example:

   ```sql
   -- Get all unsynced Altafonte contract IDs
   SELECT rcc.contract_id
   FROM run_controller_contract AS rcc
       INNER JOIN run_controller AS rc
           ON rcc.run_controller_id = rc.run_controller_id
   WHERE rc.run_controller_name = 'Altafonte'
       AND NOT EXISTS (
           SELECT 1
           FROM abacus_state AS s
           WHERE s.parent_table_id = rcc.contract_id
               AND s.action_name='sap_sync'
       );
   ```

1. Create a JSON file containing the contract IDs (see [input.example.json](./input.example.json))

1. Configure your `.env` file

1. Run
   ```bash
   $ npm start
   ```

1. Review your output (See [output.example.json](./output.example.json))
