# Contracts as documents

> Draw a contract as a PDF from a template, send it by email, have both sides sign it, and change its terms later by an amendment that takes effect from a date: versions with their file and hash, supplier contracts made from a file, contract templates with placeholders, and a notice before a contract ends.

Source: /help/en/documents/contracts-as-documents

A contract in Alya Books is a record that bills: its lines, its schedule and its invoices are described in [Contract billing and revenue recognition](/help/en/invoices/contract-billing-and-revenue-recognition). This page is about the same contract as a document. The contract is drawn as a PDF from a template, kept as a **version** with the hash of its bytes, sent, signed by both sides and changed later by an **amendment**.

A version is a snapshot of the record that bills. What was agreed and what is invoiced are therefore the same figures.

## Before you start

- **Settings → Accounting → Modules → Contracts** must be **Enabled** (Professional and above).
- Owners, admins and accountants create versions, render, send, request signatures and amend.
- An organisation created before this release applies the country pack's upgrade first, under **Settings → Accounting**. Until then **Contract templates** lists no default template and the rule template **Contract ending in 30 days** is not offered.
- A counterparty signs in your portal. The portal must be open to customers or to suppliers under **Settings → Workspace → Portal** (see [The customer portal](/help/en/portal/customer-portal) and [The supplier portal](/help/en/portal/supplier-portal)). Without the portal a contract is still sent by email and marked signed outside the app.
- The contract's page has three tabs: **Contract** (the record), **Document** and **Versions**.

## Walkthrough: from the template to a signed contract, then a new price

Golden Trading maintains the lifts of Marina Towers for AED 1,000.00 a month. The contract is in Arabic, a member of Golden Trading signs first, and the customer signs in the portal.

### Render the contract from the template

1. **Contracts → New contract**: side *Customer*, the **Contact**, the **Name**, the dates and the payment terms as for any contract. In the same form choose the **Template** (*The default template* takes the country pack's template of the side) and the **Document language** (*The contact's language*, *English* or *Arabic*).
2. Tick **Signature required**: the contract starts, and an amendment applies, only when its version is signed. Tick **A member signs first** when a member of your organisation signs before the counterparty. **Create contract**.
3. Add the line under **Lines → Add line**: `Lift maintenance`, **Billing model** *Subscription*, **Quantity** `1`, **Unit price** `1000`, **Frequency** *Monthly*.
4. Open the **Document** tab. It reads *This contract has no version yet. Create version 1 to draw it from its template.* Click **Create version 1**. The toast reads *Version 1 created*.
5. The card now reads **Version 1** with the status **Draft** and *This version has no PDF yet. Render it to draw the contract from its template.* Click **Render**. The toast reads *PDF rendered*; the page shows the PDF, the **Template**, the **Language** and the **SHA-256** of the file.

The record reads **Signature** *Required, a member signs first*. **Render again** draws the file anew while the version is a draft or sent and no signature request is open on it.

### Send it

1. On the **Document** tab click **Send**. The dialog **Send contract CT-0007** opens with **To** filled with the contact persons who receive documents (the people marked **Receives invoices** on the contact, the primary one first; the contact's own **Email** when there is none).
2. Add a **Cc** and a **Message** if you wish, or pick one with **Insert template**. An empty message uses the email template of the document type **Contract** under **Settings → Documents → Document dispatch** → **Email templates**. **Send from** picks the sending alias.
3. **Send**. The toast reads *Contract sent to …*, the version reads **Sent** and the delivery is in the delivery log. A version without a PDF is rendered first.

### Both sides sign

1. Click **Request signature**. The dialog **Request signature on version 1** lists the **Signers in order**. With no signer chosen the contract's own order applies: a member first when the contract says so, then the counterparty's portal contact.
2. To name the signers yourself, use **Add a signer**: a member, a portal contact of the counterparty, or one of its contact persons (*invited to sign only*). **Someone else** takes a name and an email address. Drag a signer to change the order. Set **Sign by** and a **Note to the signers** if you wish.
3. **Request signature**. The toast reads *Signature requested*. The **Signature** card shows *0 of 2 signed* with each signer and its status, and the page reads *This contract waits for the signature of version 1: it starts when every signer has signed.*
4. The member signs first: **Open the request** leads to the signing page, where **Sign** asks for the full name and the consent box.
5. The customer's person signs in to the portal. The home shows the card **Contracts** with *1 to sign*. The contract's page shows the document, its versions and the card **Your signature** with **Sign**, which opens the signing page.
6. When the last signer has signed, version 1 reads **Signed** and **In force**, **Open the signed copy** gives the PDF with its certificate page, and the contract reads **Active**. Its schedule is built as on any activation.

Four rules to know:

- **A person without portal access is invited to sign only.** A contact person, or a name and address, who has no portal access gets an invitation whose only permission is **Signatures**: the person reads the contract to sign and nothing else of your organisation. The request names only people who have opened their sign-in link once. When the person was invited now, the toast reads *… invited: ask again once the invitation is opened* and the tab shows *Invited to the portal, the signature request waits* with the person's name and address. Once the person has opened the sign-in link, click **Request signature again**.
- **The portal must be open to the counterparty's side.** While **Customers** (for a customer contract) or **Suppliers** (for a supplier contract) is switched off under **Settings → Workspace → Portal**, a request that names a counterparty's person is refused, and the next step names that switch. Switch it on before the first **Request signature**.
- **A decline leaves the version sent.** The **Signature** card shows *Declined:* with the reason. Click **Request signature again** for a new request, or void the version on the **Versions** tab.
- **A contract that requires a signature cannot be activated by hand.** **Activate** is refused (`signature_required`) until version 1 is signed.

### Signed on paper

**Mark signed outside** on the **Document** tab is for a contract signed on paper or in another system. Pick the signed file from the document hub and confirm **Mark signed**. The version reads **Signed** with *Signed outside the app*, keeps that file as the signed copy and takes effect exactly as a version signed by request does. This cannot be taken back.

### Amend the price from next month

From 1 December the price rises to AED 1,200.00 a month.

1. Open the **Versions** tab and click **Amend**. The dialog **Amend contract CT-0007** shows the **Terms** and the **Lines**.
2. In the line's row type the new **Unit price** `1200`. Set the **Effective date** to `1 December` and write the **Reason**, for instance *Annual price review*.
3. **Preview changes**. The preview lists **What changes** (*Lift maintenance · Unit price: AED 1,000.00 → AED 1,200.00*), the **Monthly value** before and after, and the **Schedule rows**: the planned rows from 1 December are **Removed** at the old price and **Added** at the new one, and a line below says how many rows stay as they are. Nothing is written yet.
4. **Confirm**. The toast reads *Version 2 drafted*. Version 2 is a **Draft** with the reason and the change in the **Changes** column. Nothing has changed on the contract.
5. On the **Document** tab the chips **Open (version 2)** and **In force (version 1)** switch between the two files. **Render** version 2, **Send** it and **Request signature** as before.
6. When every signer has signed, version 2 reads **Signed** and **In force** and version 1 reads **Superseded**. The schedule rows from 1 December carry AED 1,200.00. The rows before that date and every row already invoiced keep AED 1,000.00, and the next invoices are made from the new rows.

On a contract that does not require a signature, a member applies the amendment: the row menu of the version → **Apply** → confirm *Apply version 2?*. The version then reads **In force**. On a contract that requires one, **Apply** is refused (`signature_required`) until the version is signed or marked signed outside.

## What a version is

A version holds the contract's header, lines and schedule as they stood, the template and the language it was drawn with, the PDF in the document hub and the SHA-256 of that file.

| Status | Meaning |
|---|---|
| **Draft** | made, not yet sent; it can be rendered again |
| **Sent** | sent by email or put to signature |
| **Signed** | every signer has signed, or it was marked signed outside |
| **In force** | applied without a signature, on a contract that does not require one: the version the contract runs on |
| **Superseded** | a later version took its place |
| **Void** | withdrawn with a reason; kept for the record, never applied |

- **Version 1** is made when you click **Create version 1**, when the contract is first sent, or when it is activated.
- **In force** marks the version the contract runs on: a badge beside **Signed** on a signed version, and the status itself on a version that was applied without a signature. One amendment at a time may be open (a draft or sent version that has not taken effect): apply it or void it before the next.
- A version without a PDF is not sent and not put to signature (`contract_version_not_rendered`).
- A version that took effect, was signed or is void never changes (`contract_version_locked`).
- **Void** in a version's row menu asks for a reason and withdraws an open signature request on it.
- The **Versions** tab lists every version with its status, the date it takes effect, what it changed, how far its signature is and who made it. A row opens the PDF.

Editing the record after version 1 exists follows the same idea. While version 1 has not taken effect, an edit returns it to a draft with the new terms, without its file and without its open signature request: render it again. Once a signed version is in force, the terms change by an amendment and an edit is refused (`contract_locked`): the record reads *The version in force is signed: the terms of this contract change by an amendment, not by an edit.* with the button **Amend**, and its **Lines** and **Custom fields** cards are read-only. A contract that requires a signature reads the same way from its first version in force. On a contract with an unsigned version in force that does not require signatures, an edit is recorded as a version of its own that takes effect at once. **Issue generated invoices** and the **Reminder sequence** are not terms and can always be edited.

## What an amendment may change

| On | May change | Never changes |
|---|---|---|
| The contract | the name, the end date, the payment terms, the billing day, **Issue generated invoices**, the notes, the custom fields, the retention terms, the reminder sequence | the side, the counterparty, the currency, the start date |
| A line that has been invoiced | the quantity and the unit price of a *Subscription*, *Usage*, *Progress* or *Per transaction* line; the line's end date, when it does not fall before an invoiced period | the billing model, the frequency, the start date |
| A *Flat rate*, *Prepaid commit* or *Milestones* line that has been invoiced | nothing: the dialog reads *An invoiced line of this billing model keeps its quantity and price.* | its quantity and price; add a new line for the difference |

- A new line can be added by an amendment. No line is removed by one.
- The effective date cannot be before the start of the last invoiced period of a line the amendment changes.
- A price or quantity changed by an amendment is a dated term on the same line. The line keeps its identity and its history of invoices. Planned rows are rebuilt from the effective date; rows already invoiced are never touched.
- A change to a line whose revenue recognition has posted is refused (`contract_locked`). See [Revenue recognition](/help/en/invoices/contract-billing-and-revenue-recognition#revenue-recognition).
- A change of side, counterparty, currency or start date makes another contract: end this one and create a new one.

## Supplier contracts from a file

A supplier's contract usually arrives as a file. Upload it to the document hub and click **Read with AI** (see [Document hub and receipts](/help/en/documents/document-hub-and-receipts)). When the file reads as a contract, a rent contract or an insurance policy, the preview offers **Create a contract**.

- The button makes a **supplier contract** in **Draft**: the name, the dates and the currency as read, the amount as one flat line, and the counterparty matched to a contact of yours. When no contact matches, the contract is refused with the name that was read: add the supplier first.
- **The file is version 1.** It is kept as it is and nothing is rendered over it.
- Nothing is activated or posted. Check the draft against the file, then **Mark signed outside** with the signed file.
- The uploaded file's fingerprint is not recorded yet, and the **Document** tab says so. It can be sent as it is. Before it is put to signature click **Render**: it records the fingerprint (SHA-256) of the file and leaves the file itself as it is. The toast reads *The file's fingerprint was recorded; the file stays as it is*, and **Request signature** is offered after that.
- A second contract from the same file is refused. Any other kind of file is refused (`document_not_contract`): create the contract by hand and attach the file.

## A notice before it ends

The rule template **Contract ending in 30 days** tells the owner thirty days before the end date of an active contract. The notification is titled *Contract ending in 30 days* and reads *Contract CT-0007 (Lift maintenance) ends on 30 November 2027.* It is a notification only and nothing changes on the contract.

1. **Settings → Automation** → the **Templates** tab → **Contract ending in 30 days** → **Enable** (owners and admins; Professional and above).
2. The template becomes your own rule. Change the number of days, the condition or who is told as for any rule; see [Workflow rules](/help/en/settings/workflow-rules).

The rule looks once a day, at 06:00 in the organisation's time zone. A rule enabled today looks for the first time tomorrow morning, so no notice arrives on the day you enable it. Its first notices are for the contracts that end thirty days from tomorrow; a contract already inside its last thirty days gets none.

**Contracts** is a record type of the workflow rules: a rule of your own can read a contract's number, name, side, status, contact, start and end dates, currency, payment terms, **Issue generated invoices** and **Signature required**.

## Contract templates

**Settings → Documents → Contract templates** lists the documents a contract is drawn from. The country pack ships a default for each side in English and Arabic: **Customer contract** and **Supplier contract**. The **Source** column reads **Country pack** or **Your copy**.

A template is a list of blocks in order:

| Kind | Holds |
|---|---|
| **Heading**, **Clause** | a title and a text you write, with placeholders |
| **Lines table** | the contract's lines, drawn from the record |
| **Schedule table** | the invoice schedule, drawn from the record |
| **Custom fields** | the contract's custom fields marked **Print on PDF** |
| **Signature boxes** | the two parties and, once a request exists, its signers |

The four kinds drawn from the record carry a title only.

### Change the default

A pack template is read-only: its editor reads *This template comes with the country pack and is read-only. Save a copy to change it for your organisation.* Open it and click **Save as your copy**. The copy has the same key and replaces the pack's template for your organisation from the next render. **Delete** on your copy brings the pack's template back. Versions already drawn keep their PDF.

A pack template you did not copy follows the pack: when the pack changes it, your next render uses the new text.

### A template of your own

1. **New template**: the **Key** (lower-case letters, digits and underscores), the **Name** and **Name (Arabic)**, the **Side** and the **Language**.
2. **Add block**, choose the **Kind**, and write the **Title** and the **Text**. Drag a block to change the order.
3. Click into a title or a text, then click a chip under **Placeholders** to insert it at the cursor.
4. **Save template**. A placeholder that does not exist is refused when you save (`unknown_placeholder`).

### Placeholders

| Placeholder | Filled with |
|---|---|
| `{{contract_number}}`, `{{contract_name}}`, `{{version_no}}` | the contract's number and name, the version's number |
| `{{effective_date}}`, `{{today}}`, `{{start_date}}`, `{{end_date}}` | the date the version takes effect, the day it is rendered, the contract's dates |
| `{{currency}}`, `{{payment_terms}}`, `{{total_value}}`, `{{monthly_value}}`, `{{retention_percent}}` | the currency, the payment terms in days, the total and monthly values, the retention percentage |
| `{{notes}}` | the contract's notes |
| `{{organization_name}}`, `{{organization_trn}}`, `{{organization_address}}` | your organisation |
| `{{counterparty_name}}`, `{{counterparty_trn}}`, `{{counterparty_address}}` | the customer or the supplier |
| `{{custom.<key>}}` | a contract custom field, by its key |

Dates and amounts are written in the language of the document. See [Custom fields and templates](/help/en/settings/custom-fields#on-a-contracts-pdf) for the custom fields.

## In the portal

A customer's or a supplier's person whose access includes **Signatures** sees **Contracts** in the portal: every contract of their company that has a sent or signed version, the ones to sign first. The list names the version in force with the badge **In force**, and an amendment that still waits on a line of its own. What the person sees is described in [The customer portal](/help/en/portal/customer-portal#contracts) and [The supplier portal](/help/en/portal/supplier-portal#contracts).

## API and assistant

- REST: `GET` and `POST /contracts/templates`, `PATCH` and `DELETE /contracts/templates/{id}`, `GET /contracts/templates/placeholders`; `GET` and `POST /contracts/{id}/versions`, `GET /contracts/{id}/versions/{versionId}`; `POST /contracts/{id}/amend` (`patch`, `effectiveDate`, `reason`; `preview` `true` writes nothing); `POST /contracts/{id}/versions/{versionId}/render`, `/apply`, `/sign-request`, `/signed-outside` and `/void`; `POST /contracts/{id}/send`; `POST /contracts/from-document` (`fileId`).
- Assistant tools: `list_contract_versions`, `amend_contract`, `send_contract`, `request_contract_signature` and `create_contract_from_document`. The four that write ask for your confirmation first. No tool signs.
- The webhooks `signature.signed` and `signature.declined` tell your endpoints when a contract's request is signed or declined; see [Signatures and approvals](/help/en/documents/signatures-and-approvals).

## Related

- [Contract billing and revenue recognition](/help/en/invoices/contract-billing-and-revenue-recognition)
- [Signatures and approvals](/help/en/documents/signatures-and-approvals)
- [Custom fields and templates](/help/en/settings/custom-fields)
- [Workflow rules](/help/en/settings/workflow-rules)
- [The customer portal](/help/en/portal/customer-portal)
- [The supplier portal](/help/en/portal/supplier-portal)
