# A/P Debit Note

## A/P Debit Note's Database

<table><thead><tr><th>UI Name</th><th>Database</th><th>Type</th><th>Remarks</th></tr></thead><tbody><tr><td>Creditor</td><td><pre><code>creditorCode
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>401-A001</code></td></tr><tr><td>D/N No</td><td><pre><code>docNo
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>DOC123456789</code></td></tr><tr><td>Date</td><td><pre><code>docDate
</code></pre></td><td><strong><code>Date</code></strong></td><td>E.g.: <code>2023-11-01T00:00:00+08:00</code></td></tr><tr><td>Description</td><td><pre><code>description
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>INVOICE - INV123456</code></td></tr><tr><td>Journal Type</td><td><pre><code>journalType
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>EXPENSE</code></td></tr><tr><td>Inclusive</td><td><pre><code>inclusiveTax
</code></pre></td><td><strong><code>Boolean</code></strong></td><td>E.g.: <code>true</code></td></tr><tr><td>Credit Term</td><td><pre><code>displayTerm
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>NET30</code></td></tr><tr><td>Table Item</td><td><pre><code>details
</code></pre></td><td><strong><code>Array</code></strong></td><td><a href="#a-p-debit-notes-table-item">Refer Below</a></td></tr></tbody></table>

## A/P Debit Note's Table Item

<table><thead><tr><th>UI Name</th><th>Database</th><th>Type</th><th>Remarks</th></tr></thead><tbody><tr><td>Item Code</td><td><pre><code>accNo
</code></pre></td><td><code>String</code></td><td>E.g.: <code>700-1234</code></td></tr><tr><td>Description</td><td><pre><code>description
</code></pre></td><td><code>String</code></td><td>E.g.: <code>SHIPPING FEES</code></td></tr><tr><td>Amount</td><td><pre><code>amount
</code></pre></td><td><code>Number</code></td><td>E.g.: <code>150.75</code></td></tr><tr><td>Tax Code</td><td><pre><code>taxCode
</code></pre></td><td><code>String</code></td><td>E.g.: <code>TX-5</code></td></tr></tbody></table>

## A/P Debit Note'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
import clr
clr.AddReference("Newtonsoft.Json")
clr.AddReference("System.Net")
clr.AddReference("System.IO")

from System.Text import *
from Newtonsoft.Json import *
from Newtonsoft.Json.Linq import *
from System import *

clr.AddReference("System.Drawing")
from System.Drawing import Bitmap,Image
from System.Drawing.Imaging import ImageFormat
from System.IO import MemoryStream, StreamWriter
from System.Net import WebClient
import binascii
from System import BitConverter

#search
documentList = Module('{YOUR-MODULE-NAME}').findAll({ 'Audit.UpdatedDate': { '$gt': Inputs['lastSync'] }, 'Audit.UpdatedBy': { "$ne": 'External' } })
debug('documentList', documentList)

resultList = []

def prepareRow(x):
    row = JObject()
    row["accNo"] = x['Item Codes']['{YOUR-ITEM-CODE}']
    row["description"] = x['{YOUR-DESCRIPTION}']
    row["amount"] = x['{YOUR-TOTAL}']
    if x["Tax Code"].Id != 0:
        row["taxCode"] = x['Tax Code']['{YOUR-TAX-CODE}']
        # row["taxRate"] = x['Tax Code']['Percentage'].ToString()
    return row
    
def preparePayload(data):
    payloadData = JObject()
    payloadData["type"] = "APDN"
    payloadData["cancelled"] = data['{YOUR-CANCELLED}']
    payloadData["payload"] = JObject()
    if data['{YOUR-CODE}'] != None and data['{YOUR-CODE}'] != 0:
        payloadData["payload"]["docKey"] = data['{YOUR-CODE}'] 
    payloadData["payload"]["creditorCode"] = data['{YOUR-COMPANY-CODE}']
    payloadData["payload"]["docNo"] = data['{YOUR-SUPPLIER-DEBIT-NOTE-NO}']
    payloadData["payload"]["docDate"] = data['{YOUR-SUPPLIER-DEBIT-NOTE-DATE}']
    payloadData["payload"]["description"] = data['{YOUR-TRANSACTION-DESCRIPTION}']
    payloadData["payload"]["journalType"] = "PURCHASE"
    payloadData["payload"]["inclusiveTax"] = True
    payloadData["payload"]["displayTerm"] = data['{YOUR-TERM}']
    payloadData["payload"]["details"] = JArray.FromObject(data['{YOUR-DETAILS}'].Select(lambda x: prepareRow(x)))
    
    payloadData["LastModified"] = data.UpdatedDate
    return payloadData

#end of added
for entry in documentList:
    payloadData = preparePayload(entry)
    if payloadData["payload"]["creditorCode"] != None and payloadData["payload"]["creditorCode"] != "":
        resultList.append(payloadData)
    #debug('payloadData', payloadData)
    
#debug('done', resultList)

outputs['results'] = JArray.FromObject(resultList)
```

{% 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/a-p-debit-note.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.
