A/P Debit Note

A/P Debit Note's Database

UI Name
Database
Type
Remarks

Creditor

String

E.g.: 401-A001

D/N No

String

E.g.: DOC123456789

Date

Date

E.g.: 2023-11-01T00:00:00+08:00

Description

String

E.g.: INVOICE - INV123456

Journal Type

String

E.g.: EXPENSE

Inclusive

Boolean

E.g.: true

Credit Term

String

E.g.: NET30

Table Item

Array

A/P Debit Note's Table Item

UI Name
Database
Type
Remarks

Item Code

accNo

String

E.g.: 700-1234

Description

description

String

E.g.: SHIPPING FEES

Amount

amount

Number

E.g.: 150.75

Tax Code

taxCode

String

E.g.: TX-5

A/P Debit Note's Sample Code

To find {fieldName}, you are required to have access to Alpha or use Network in Developer Tools [F12].

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)

Last updated