# E-Invoice

## E-Invoice Database

<table data-full-width="false"><thead><tr><th width="100">UI Name</th><th width="232.22216796875">Database</th><th width="116.4444580078125">Type</th><th>Remarks</th></tr></thead><tbody><tr><td>Doc Key</td><td><pre><code>DocKey
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>1234567</code></td></tr><tr><td>Doc No</td><td><pre><code>DocNo
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>IV00001</code></td></tr><tr><td>Submit<br>E-Invoice</td><td><pre><code>SubmitEInvoice
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>T</code></td></tr><tr><td>E-Invoice<br>Unique Id</td><td><pre><code>EInvoiceUuid
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>A1B2C3...</code></td></tr><tr><td>EInvoice Validated Date Time</td><td><pre><code>LastModified
</code></pre></td><td><strong><code>Timestamp</code></strong></td><td>E.g.:<br><code>2025-01-01T00:00:00.000</code></td></tr><tr><td>EInvoice<br>Validation Link</td><td><pre><code>EInvoiceValidationLink
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.:<br><code>https://myinvois.hasil.gov.my/......</code></td></tr><tr><td>E-Invoice Status</td><td><pre><code>EInvoiceStatus
</code></pre></td><td><strong><code>String</code></strong></td><td>Sync back the <strong>cancelled</strong> E-Invoice Status<br>E.g.:<br><code>if item['EInvoiceStatus'] == 'Cancelled'</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="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 = '{YOUR-MODULE-NAME}'
list = inputs["list"]

def data_has_change(data, input):
    formatedFormTime = format(data['E-Invoice Validated Date'], "yyyy-MM-ddTHH:mm:ss") if data['E-Invoice Validated Date'] is not None else None;
    formatedInputTime = format(input['LastModified'], "yyyy-MM-ddTHH:mm:ss")
    has_change = (
        formatedFormTime != formatedInputTime or
        data['E-Invoice Unique Id'].ToString() != input['EInvoiceUuid'].ToString() or
        data['E-Invoice Validation Link'].ToString() != input['EInvoiceValidationLink'].ToString() or
        data['E-Invoice Status'].ToString() != input['EInvoiceStatus'].ToString()
        )
    return has_change

for item in list:
    entry = Module(moduleName).find({ 
        'Dynamic.Extension.{keyField}': item['DocNo'] # Running Number
    })
    
    form = Module(moduleName).execute('sync', entry)
    
    if entry and data_has_change(entry,item):
        form['E-Invoice Validated Date'] = item['LastModified']
        form['E-Invoice Unique Id'] = item['EInvoiceUuid']
        if item['EInvoiceValidationLink'] is not None:
            sign_id = item['EInvoiceValidationLink'].ToString().split("/")[-1]
            form['E-Invoice Digital Sign Id'] = sign_id
    
        form['E-Invoice Validation Link'] = item['EInvoiceValidationLink']
        form['E-Invoice Status'] = item['EInvoiceStatus']
        Module(moduleName).submit(entry, form)
        
        if item['EInvoiceStatus'] == 'Cancelled' and entry.State!= 'Cancelled':
            Module(moduleName).submit(entry, 'YOUR-ACTION')
```

{% 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-1/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.
