# sales\_receipt\_edits

## Model

This model is exactly same as the sales\_receipt modal, the only difference is that it has two additional fields.

<table><thead><tr><th>Field</th><th>Type</th><th data-type="checkbox">Nullable</th><th>Constraints</th></tr></thead><tbody><tr><td>id</td><td>int4</td><td>false</td><td>Primary key</td></tr><tr><td>sale_receipt_id</td><td>int4</td><td>false</td><td><p>Foreign key</p><p>(sale receipts)</p></td></tr><tr><td>mandi_id</td><td>int4</td><td>false</td><td>Foreign Key (mandi)</td></tr><tr><td>mandi_name</td><td>varchar</td><td>true</td><td></td></tr><tr><td>mandi_name_hi</td><td>varchar</td><td>true</td><td></td></tr><tr><td>crop_id</td><td>int4</td><td>false</td><td>Foreign Key (crop)</td></tr><tr><td>crop_name</td><td>varchar</td><td>true</td><td></td></tr><tr><td>crop_name_hi</td><td>varchar</td><td>true</td><td></td></tr><tr><td>receipt_date</td><td>timestamp</td><td>false</td><td></td></tr><tr><td>quantity</td><td>float8</td><td>false</td><td></td></tr><tr><td>price</td><td>float8</td><td>false</td><td></td></tr><tr><td>user_id</td><td>int4</td><td>false</td><td>Foreign Key (person_table)</td></tr><tr><td>booklet_number</td><td>text</td><td>false</td><td></td></tr><tr><td>receipt_image_url</td><td>varchar</td><td>false</td><td></td></tr><tr><td>is_approved</td><td>bool</td><td>true</td><td></td></tr><tr><td>created_at</td><td>timestamp</td><td>true</td><td></td></tr><tr><td>updated_at</td><td>timestamp</td><td>true</td><td></td></tr><tr><td>promised_token</td><td>int4</td><td>false</td><td></td></tr><tr><td>token_amount</td><td>int4</td><td>true</td><td></td></tr><tr><td>receipt_owner_id</td><td>int4</td><td>true</td><td>Foreign Key (person_table)</td></tr><tr><td>receipt_owner_phone_number</td><td>varchar</td><td>true</td><td></td></tr><tr><td>validated_by</td><td>int4</td><td>true</td><td>Foreign Key (person_table)</td></tr><tr><td>validated_on</td><td>timestamp</td><td>true</td><td></td></tr><tr><td>rejection_reason_ids</td><td>_int4</td><td>true</td><td></td></tr><tr><td>edited_by</td><td>int4</td><td>true</td><td></td></tr><tr><td>receipt_type</td><td>varchar</td><td>true</td><td>Default: "handwritten"</td></tr></tbody></table>

## Description of fields

This table has same fields as of the sales\_receipt table, other than the following two:

### sales\_receipt\_id

this is the primary key of the sales\_receipt table and tells us about which entry is edited.

### edited\_by

the user\_id of the team member who edited the receipt.

{% hint style="info" %}
This field was added in early Jan 2024, and may be empty for rows before that.&#x20;
{% endhint %}

## How do we make sense of this table?

This table is linked to the sales\_receipt table. Whenever a row is edited in the sales\_receipt, a new entry is made in this table. On the admin portal, a data validator has an option to edit the details of a sales receipt if the user who uploaded the receipt has not correctly entered the data.

![](https://archbee-image-uploads.s3.amazonaws.com/WPhORIY5wbVXcAz9WLeSH/-Hq6NULIwusoWzy0muL-2_screenshot-2024-01-09-at-82633-am.png)

When the data validator clicks on the edit button, a pop-up comes and provides them options to edit any of the following six fields:

1. mandi
2. crop
3. booklet\_number
4. receipt\_number
5. price
6. quantity
7. Validation status: approved or rejected

![](https://archbee-image-uploads.s3.amazonaws.com/WPhORIY5wbVXcAz9WLeSH/fl9rWGQdc23uLAftB3on7_screenshot-2024-01-09-at-82801-am.png)

Upon edit, an entry of the older data is made in the the sale\_receipt\_edits table. The same receipt if edited again, a new entry is made in the sale\_receipt\_edits table.

{% hint style="info" %}
The sales\_receipt\_edit table can have multiple entries for a single sales receipt. If sorted by the created\_at timestamp, we can get the different versions of the sales receipt data.
{% endhint %}

In the Admin Portal, there is a feature to view the different versions of a sale receipt entry that is edited multiple times. It shows the list of all the past versions. It does not show the current version.

![](https://archbee-image-uploads.s3.amazonaws.com/WPhORIY5wbVXcAz9WLeSH/LsrxmJIpkxoIt1mZLMkJZ_screenshot-2024-01-09-at-94728-am.png)
