Debtor must match existing debtor code, and they must be active state.
E.g.: 400-A001
C/S No
String
Avoid using the same C/S No to prevent overwrite.
E.g.: CSH00001
Date
String
E.g.: 2024-11-27T00:00:00+08:00
Sales Location
String
Must have existing Sales Location in the accounting system.
E.g.: HQ
Credit Term
String
Credit Term must match the same in the accounting system
E.g.: C.O.D.
Description
String
E.g.: CASH SALE
Remark 1
String
E.g.: Sample Text
Table Item
Array
Cash Sale's Table Item
UI Name
Database
Type
Remarks
Item Code
String
E.g.: A001
Description
String
E.g.: PRODUCT - CL14
Location
String
Must have existing Location in the accounting system.
E.g.: HQ
UOM
String
E.g.: UNIT
Qty
Decimal
Value must be number, and value cannot be negative.
E.g.: 10.0
Unit Price
Decimal
Value must be number, and value cannot be negative.
E.g.: 10.0
Cash Sale's Sample Code
Remember to change to the correct field before proceeding to run ANY script.
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"},
"Dynamic.Extension.{fieldName}": {"$ne": None},
}
)
debug("documentList", documentList)
resultList = []
def prepareRow(x):
row = JObject()
row["itemCode"] = x["{YOUR-ITEM-CODE}"]
row["description"] = x["{YOUR-DESCRIPTION}"].ToString()
row["location"] = x["{YOUR-LOCATION}"]
row["uom"] = x["{YOUR-UOM}"]
row["qty"] = x["{YOUR-QTY}"]
row["unitPrice"] = x["{YOUR-UNIT-PRICE}"]
return row
def preparePayload(data):
payloadData = JObject()
payloadData["type"] = "CashSale"
payloadData["payload"] = JObject()
payloadData["payload"]["debtorCode"] = data["{YOUR-DEBTOR-CODE}"]
# payloadData["payload"]["docNo"] = None if data['Running Number'] == "" or data['Running Number'] is None else data['Running Number']
payloadData["payload"]["docNo"] = data.DocumentId
payloadData["payload"]["docDate"] = data["{YOUR-DOC-DATE}"]
payloadData["payload"]["salesLocation"] = data["{YOUR-SALES-LOCATION}"]
payloadData["payload"]["displayTerm"] = "C.O.D."
payloadData["payload"]["description"] = "CASH SALE"
payloadData["payload"]["Remark1"] = data["{YOUR-REMARK1}"]
payloadData["payload"]["details"] = JArray.FromObject(
data["{YOUR-TABLE}"].Select(lambda x: prepareRow(x))
)
payloadData["LastModified"] = data.UpdatedDate
return payloadData
# end of added
for entry in documentList:
payloadData = preparePayload(entry)
if (
payloadData["payload"]["debtorCode"] != None
and payloadData["payload"]["debtorCode"] != ""
):
resultList.append(payloadData)
# debug('payloadData', payloadData)
# debug('done', resultList)
outputs["results"] = JArray.FromObject(resultList)
debug("result", resultList)
moduleName = "{YOUR_MODULE_NAME}"
if inputs is not None and inputs['document'] is not None and inputs['document']['payload'] is not None:
doc = Module(moduleName).find({ 'Document.DocumentId': inputs['document']['payload']['docNo'] })
if doc is not None:
form = Module(moduleName).execute('sync', doc)
form['Error'] = True
form['Error Message'] = inputs['error']
debug("result",form)
Module(moduleName).submit(doc, form)