> For the complete documentation index, see [llms.txt](https://gramhal.gitbook.io/bolbhav/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gramhal.gitbook.io/bolbhav/chapter-1-database/user-contributed-data/sales_receipt.md).

# sales\_receipt

When a user contributes the price data, it is stored in the sales\_receipt table. Each row is data about a single crop sale.

## Model

<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></td></tr><tr><td>receipt_id</td><td>int4</td><td>false</td><td></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></tbody></table>

## Description of fields

### id

The primary key of the row.

### user\_id

It tells about the user who uploaded the receipt and is mapped to the person table.

### receipt\_owner\_number and receipt\_owner\_id

It tells about the phone number of the person, who is the owner of the receipt. Receipt\_owner\_id is mapped to the person table.

{% hint style="info" %}

1. It is an optional field.
2. In case a person uploads their own receipt, the user\_id and receipt\_owner\_id will be same, else it would be different.
3. In case the receipt\_owner\_number is not an existing user, then a new user is created in the person\_table.
4. We cannot check whether the person uploading the receipt has provided the correct information about the receipt\_owner.
5. We are collecting this information as it may help us in growth. We can send the receipt\_owner a notification to download the application.
6. Rewards are allocated to receipt owner wallet when a receipt is uploaded.
   {% endhint %}

### validated\_by

Provides the user\_id of the team member who validated the receipt. It is a foreign key referencing to the person table.

Each submitted receipt remains in a pending state until a data validator approves or rejects it. No receipt is shown to a user in the frontend until it is approved by a data validator.

### receipt\_id and booklet\_number

These are unique identifiers of a sales receipt.

{% hint style="info" %}
In a mandi multiple auctions are happening simultaneoulsly and each staff member carries a booklet with them to record the auction results. They tear one copy of the sales receipt and give it to the seller. Therefore, the booklet number and the receipt number within that booklet together can uniquely identify a sales receipt.
{% endhint %}

{% hint style="warning" %}
In a mandi thousands of auctions happen each day. Hence, tens of booklets are finsihed each day. There may be a case that same combination of booklet\_number and receipt\_id in used in the same mandi a few weeks down the line. Similarly, it is possible that the same booklet\_number and receipt\_id is used in a different mandi on the same day. Thus, to make a unique combination we must use four parameters:

1. booklet\_number
2. receipt\_id
3. mandi\_id
4. receipt\_date

This is based on the assumption that within a mandi, in a same day, the combination of booklet\_number and receipt\_id will not be repeated.&#x20;
{% endhint %}

### mandi\_id, mandi\_name, mandi\_name\_hi

All are unique identifiers of a mandi and are mapped to the [mandi](docId:UZRTT1SApJu6VvYFI6T4y) table.

### crop\_id, crop\_name, crop\_name\_hi

All are unique identifiers of a crop and are mapped to the [crop](docId:gC1BcH4-OO2Y-3nYvXHIU) table.

### quantity

Is used to store the quantity of the crop sold. Currently, all quantities are stored in quintals.

### price

Is used to store the price received in auction. Currently, all prices are stored in per quintal unit and the default currency is INR.

### receipt\_date

Is the date written on the sales receipt.

{% hint style="info" %}
The receipt\_date can be different from the date on which the receipt is uploaded to Bolbhav.
{% endhint %}

### receipt\_image\_url

Each uploaded image of the sales receipt is stored in AWS S3, and a unique link is generated.

{% hint style="info" %}
The name given to the url should be unique otherwise, it will start overwriting the previous files in S3. Currently, we follow this naming convention of url.\
\
How are buckets maintained in S3?
{% endhint %}

### created\_at

Timestamp on which the data is submitted and the row is added.

### promised\_token

When a user submits a receipt, they are promised some tokens, which is a virtual currency of Bolbhav. These are payable only if the receipt is approved after validation.

{% hint style="warning" %}
Add logic to explain how promised tokens are calculated (or link)
{% endhint %}

### token\_amount

These are the actual tokens that are credited to a user's wallet after the submitted receipt is validated.

If a receipt is rejected, then the token\_amount is changed to zero, and no entry is made in a user's wallet.

### is\_approved

It tells about the validation status of a receipt. It has three values:

1. `null` - for pending approval/rejection
2. `true`  - for approved
3. `false` - for rejected

### validated\_on

When the data validators take any action on the is\_approved field, this timestamp is set.

{% hint style="info" %}
Does it record the first validation or the latest validation timestamp?
{% endhint %}

### receipt\_rejection\_reasons

It stores a list of reasons for which a particular receipt is rejected. It is mapped to receipt\_rejections\_reasons table.

### updated\_at

timestamp that tells when the last time any field is edited.

{% hint style="info" %}
It is different from validated\_on, which changes only when the status is\_approved is changed.
{% endhint %}
