# E-Invoice

## E-Invoice's Database

<table><thead><tr><th>UI Name</th><th>Database</th><th width="127.8887939453125">Type</th><th>Remarks</th></tr></thead><tbody><tr><td>Doc No</td><td><pre><code>TBL.DOCNO
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>IV00001</code></td></tr><tr><td>E-Invoice Validated Date</td><td><pre><code>E.TRANSDATETIME
</code></pre></td><td><strong><code>Date</code></strong></td><td>E.g.: <code>2025-01-01</code></td></tr><tr><td>E-Invoice Unique Id</td><td><pre><code>TBL.IRBM_UUID
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>A1B2C3...</code></td></tr><tr><td>E-Invoice Digital Sign Id</td><td><pre><code>TBL.IRBM_LONGID
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>Z9Y8X7...</code></td></tr><tr><td>E-Invoice Validation Link</td><td><pre><code>validation_link
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>https://myinvois.hasil.gov.my/......</code></td></tr><tr><td>E-Invoice Status</td><td><pre><code>E.STATUS
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>Valid</code></td></tr><tr><td>Last Modified</td><td><pre><code>E.TRANSDATETIME
</code></pre></td><td><strong><code>Timestamp</code></strong></td><td>E.g.: <code>2025-01-01T00:00:00.000</code></td></tr></tbody></table>

## E-Invoice's Sample Code

{% hint style="warning" %}
Remember to change to the **correct field** before proceeding to run **ANY** script.
{% endhint %}

{% tabs %}
{% tab title="SQL Script" %}
{% hint style="danger" %}
This is a sample SQL, may not be as same as your database.
{% endhint %}

```sql
SELECT 
    TBL.DOCNO AS DocNo,//IV,CN,DN
    E.TRANSDATETIME AS EInvoiceValidateDate,
    TBL.IRBM_UUID AS EInvoiceUUID,
    TBL.IRBM_LONGID AS EInvoiceLongID,
    E.STATUS AS EInvoiceStatus,
    E.TRANSDATETIME AS LastModified
FROM 
    {YOUR_DOC_TABLE} TBL
JOIN EIV E 
    ON TBL.DOCKEY = E.DOCKEY //MATCH
WHERE 
    E.DOCTYPE = '{YOUR_DOCTYPE}' //IV,CN,DN
    AND E.STATUS = {STATUS_CODE} // 2
    AND E.TRANSDATETIME >{LAST_MODIFIED_DATE_TIME};
```

{% endtab %}

{% tab title="jobs.json" %}
{% hint style="warning" %}
In order to sync, you must include **`LastModified`** in **`SELECT`**
{% endhint %}

<pre class="language-json"><code class="lang-json">"SQLSync": [
<strong>  {
</strong>    "name": "Invoice- EInvoiceSyncBack",
    "enabled": true,
    "server": {
      "db": "{DATABASE_FILENAME}",
      "dcf": "C:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF",
      "username": "ADMIN",
      "password": "ADMIN"
    },
    "from": "sqlaccounting",
    "hook": "https://api.inistate.com/api/automationHook/hook/{MODULE-ID}-{LOGIC-NAME}",
    "sql": "SELECT \r\n    TBL.DOCNO AS DocNo,\r\n    E.TRANSDATETIME AS EInvoiceValidateDate,\r\n    TBL.IRBM_UUID AS EInvoiceUUID,\r\n    TBL.IRBM_LONGID AS EInvoiceLongID,\r\n    E.STATUS AS EInvoiceStatus,\r\n    E.TRANSDATETIME AS LastModified\r\nFROM \r\n    {YOUR_DOC_TABLE} TBL\r\nJOIN EIV E \r\n    ON TBL.DOCKEY = E.DOCKEY\r\nWHERE \r\n    E.DOCTYPE = '{YOUR_DOCTYPE}' \r\n    AND  E.STATUS = {STATUS_CODE} \r\n    AND E.TRANSDATETIME > @date\r\n;\r\n",
    "lastSync": "{LAST-SYNC-DATE-TIME}",
  }
]
</code></pre>

{% endtab %}

{% tab title="Logic Script" %}
{% hint style="info" %}
To find `{fieldName}`, you are required to have access to **Alpha** or use **Network** in Developer Tools `[F12]`.
{% endhint %}

{% code fullWidth="true" %}

```python

moduleName = 'Invoice'
list = inputs["list"]



for item in list:
    entry = Module(moduleName).find({
        'Dynamic.Extension.{keyField}': item['DOCNO']
    })

    form = Module(moduleName).execute('sync', entry)

    if entry:
        # convert time
        dt = DateTime.ParseExact(item['LASTMODIFIED'].ToString(),"d/M/yyyy h:mm:ss tt",None)
        iso_ts = dt.ToString("yyyy-MM-ddTHH:mm:ss")
        form['E-Invoice Validated Date'] = iso_ts
        
        form['E-Invoice Unique Id'] = item['EINVOICEUUID']
        form['E-Invoice Digital Sign Id'] = item['EINVOICELONGID']

        # Always build the validation link using UUID and LongID
        validation_link = "https://myinvois.hasil.gov.my/{0}/share/{1}".format(
            item['EINVOICEUUID'], item['EINVOICELONGID']
        )
        form['E-Invoice Validation Link'] = validation_link

        if item['EINVOICESTATUS'] == {STATUS_CODE}:
            form['E-Invoice Status'] = '{STATUS}'
       

       
        Module(moduleName).submit(entry, form)

```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://inistate.gitbook.io/home/advanced/integration/accounting-2/e-invoice.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
