SDK Live: Difference between revisions

From eStream Software
 
(102 intermediate revisions by the same user not shown)
Line 31: Line 31:
==Documentation==
==Documentation==
* [https://www.sql.com.my/document/SQLLink/SQLSDK.zip SQLSDK.zip]
* [https://www.sql.com.my/document/SQLLink/SQLSDK.zip SQLSDK.zip]
* [https://www.sql.com.my/document/SQLLink/Video-SDK.exe Video-SDK.exe]
* [https://download.sql.com.my/customer/Fairy/Steps-SDK.gif Steps-SDK.gif]


==Linking Flow==
==Linking Flow==
Line 44: Line 44:
:* The SDK can be build in in your system or a Standalone windows Application(Middle Application).
:* The SDK can be build in in your system or a Standalone windows Application(Middle Application).
:* If you build in your system then it can be sync anytime either by a special interface with parameter (eg Date From, Date To & etc) or each transaction after post(not recommended)
:* If you build in your system then it can be sync anytime either by a special interface with parameter (eg Date From, Date To & etc) or each transaction after post(not recommended)
:* If you create a Standalone windows Application(Middle Application) you can make use the windows schedule to sync or call from you system to execute/run the Standalone windows Application(Middle Application).
:* If you create a Standalone windows Application(Middle Application) you can make use the <span style="color:#0000ff">Windows Schedule</span> to sync or call from you system to execute/run the Standalone windows Application(Middle Application).


<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>
Line 78: Line 78:
|}
|}
:::----------------------------------------------------------------------------------------------------------------------------------------------------
:::----------------------------------------------------------------------------------------------------------------------------------------------------
<div style="float: right;">  [[#top|[top]]]</div>
==Available Programming Language==
* [[#VB._Net| VB. Net]]
* [[#C_Sharp| C Sharp]]
* [[#ASP.Net_C_Sharp| ASP.Net C Sharp]]
* [[#Python| Python]]
* [[#PHP|PHP]]
* [[#Node_JS| Node JS]]
* [[#VB_Script| VB Script]]
* [[#JScript/JavaScript| JavaScript]]
* [[#Delphi| Delphi]]


<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>
Line 83: Line 96:
==Example External Program==
==Example External Program==
===VB. Net===
===VB. Net===
* Example [https://download.sql.com.my/customer/Fairy/VBDotNet.zip VBDotNet-20220614]
* Example [https://download.sql.com.my/customer/Fairy/VBDotNet.zip VBDotNet-20230819]


===C Sharp===
===C Sharp===
* Example [https://download.sql.com.my/customer/Fairy/CSharp.zip CSharp-20220614]
* Example [https://download.sql.com.my/customer/Fairy/CSharp.zip CSharp-20230819]


===Steps (C Sharp & VB.Net Only)===
===Steps (C Sharp & VB.Net Only)===
Line 110: Line 123:
:- Customer Aging - Customer.Aging.RO
:- Customer Aging - Customer.Aging.RO
:- Get Sales Invoice Listing - Sales.IV.RO
:- Get Sales Invoice Listing - Sales.IV.RO
:- Stock Item List Filter by Supplier Item
:- Stock Item List
:- Add SKU with Edit SKU - ST_ITEM
:- Add SKU with Edit SKU - ST_ITEM
:- Del SKU - ST_ITEM
:- Del SKU - ST_ITEM
Line 143: Line 156:
:- Add GL Ledger RO
:- Add GL Ledger RO
:- AR Statement
:- AR Statement
:- Add Add/Edit AR PM
:- Add LogInOut (For Testing purpose)


<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


===History - C Sharp & VB.Net===
===History - C Sharp & VB.Net===
:Coming soon...
:19 Aug 2023...
::- Add Add/Edit AR PM
::- Add Add/Edit AR PM
::- Add LogInOut (For Testing purpose)


:14 Jun 2022
:14 Jun 2022
Line 293: Line 309:
:- pypiwin32 (Mandatory) -> pip install pypiwin32
:- pypiwin32 (Mandatory) -> pip install pypiwin32
:- Pillow (Optional for Picture) -> pip install Pillow
:- Pillow (Optional for Picture) -> pip install Pillow
:- striprtf (Optional for Rich Text to Text) -> pip install striprtf


====Example-Get Agent====
====Common====
* Common.py file for example code
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Get Agent Script 
! Common Function
|-
|-
|  
|  
<syntaxhighlight lang="Python">
<syntaxhighlight lang="Python">
#Updated 17 Oct 2019
#Updated 03 Oct 2023
import win32com.client
import win32com.client
import Common
import os
from time import sleep


ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
def KillApp():
    os.system('cmd /c "taskkill /IM "SQLACC.exe" /F"')
    sleep(2) #sleep 2 sec


def CheckLogin():
def CheckLogin():
    global ComServer
    ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
     B = ComServer.IsLogin
     B = ComServer.IsLogin
     if B == True:
     if B == True:
         ComServer.Logout()
         ComServer.Logout()
     ComServer.Login("ADMIN", "ADMIN", #UserName, Password
        KillApp()
                    "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                    "ACC-0081.FDB") #Database Name
     ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
    try:   
        ComServer.Login("ADMIN", "ADMIN", #UserName, Password
                        "D:\\Happy\\DB\\Default.DCF",
                        #"C:\\eStream\\SQLAccounting\\Share\\Default.DCF",  #DCF file
                        "ACC-0015.FDB") #Database Name
    except Exception as e:
        print("Oops !", e)
 


def GetData():
def ShowResult(ADataset):
     lSQL = "SELECT * FROM AGENT  "
     if ADataset.RecordCount > 0:
    lSQL = lSQL + "WHERE CODE='FAIRY' "
        while not ADataset.eof:
   
            fc = ADataset.Fields.Count
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
            for x in range(fc):
   
                fn = ADataset.Fields.Items(x).FieldName
    if lDataSet.RecordCount > 0:
                fv = ADataset.FindField(fn).AsString
        print(lDataSet.FindField('Description').AsString)
                lresult = "Index : "+ str(x) + " FieldName : " + fn + " Value : " + fv
                print (lresult)
            print("====")
            ADataset.Next()
     else:
     else:
      print ("Record Not Found")
        print ("Record Not Found")
   
       
try:
       
    CheckLogin()    
def QuotedStr(ACode):
    GetData()
     return "'" + ACode.replace("'", "''") + "'"
finally:
 
     ComServer.Logout()
    ComServer = None   
</syntaxhighlight>
</syntaxhighlight>
|}
|}
Line 336: Line 371:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Add & Edit Agent====
====Agent====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Add & Edit Agent Script   
! Agent Script   
|-
|-
|  
|  
<syntaxhighlight lang="Python">
<syntaxhighlight lang="Python">
#Updated 17 Oct 2019
#Updated 22 Jul 2023
import win32com.client
import Common
 
     
ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
def GetListData():
 
     lSQL = "SELECT * FROM AGENT "
def CheckLogin():
     lSQL = lSQL + "WHERE ISACTIVE='T' "
     B = ComServer.IsLogin
    lSQL = lSQL + "ORDER BY CODE "
     if B == True:
   
        ComServer.Logout()
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
     ComServer.Login("ADMIN", "ADMIN", #UserName, Password
       
                    "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
     Common.ShowResult(lDataSet)
                    "ACC-0104.FDB") #Database Name   


def PostData():
def PostData():
     BizObject = ComServer.BizObjects.Find("Agent")
     BizObject = ComServer.BizObjects.Find("Agent")
     lMain = BizObject.DataSets.Find("MainDataSet")
     lMain = BizObject.DataSets.Find("MainDataSet")  
      
      
     lDocKey = BizObject.FindKeyByRef("CODE", "FAIRY")
     lDocKey = BizObject.FindKeyByRef("CODE", "FAIRY")
Line 365: Line 399:
         lMain.FindField("CODE").value = "FAIRY"
         lMain.FindField("CODE").value = "FAIRY"
         lMain.FindField("DESCRIPTION").value = "FAIRY TAIL"
         lMain.FindField("DESCRIPTION").value = "FAIRY TAIL"
     else:
     else:
         BizObject.Params.Find("CODE").Value = lDocKey
         BizObject.Params.Find("Code").Value = lDocKey
         BizObject.Open()
         BizObject.Open()
         BizObject.Edit()
         BizObject.Edit()
         lMain.FindField("DESCRIPTION").value = "FAIRY TAIL WIZARD"
         lMain.FindField("DESCRIPTION").value = "FAIRY TAIL WIZARD"
       
           
     try:
     try:
         BizObject.Save()
         BizObject.Save()        
     except Exception as e:
     except Exception as e:
         print("Oops!", e)     
         print("Oops!", e)     
     print ("Done")
    BizObject.Close()
     print ("Posting/Update Done")
 
def DelData():
    #Deleting only work if the record never use in other document
    BizObject = ComServer.BizObjects.Find("Agent")
      
      
    lDocKey = BizObject.FindKeyByRef("CODE", "FAIRY")
       
    if lDocKey is None:
        print ("Record Not Found")
    else:
        BizObject.Params.Find("CODE").Value = lDocKey
        BizObject.Open()
        BizObject.Delete()       
        print ("Deleting Done")
try:
try:
     CheckLogin()
     Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
    GetListData()
     PostData()
     PostData()
   
    answer = input("Continue To delete?")
    if answer.lower() in ["y","yes"]:
        DelData()
    elif answer.lower() in ["n","no"]:
        print ("Deleting Aborted")
    else:
      print ("Invalid Input")
    ComServer.Logout()
finally:
finally:
    ComServer.Logout()
     ComServer = None
     ComServer = None
    Common.KillApp()
</syntaxhighlight>
</syntaxhighlight>
|}
|}
Line 388: Line 452:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Delete Agent====
====Get Company Profile====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Delete Agent Script 
! Get Company Profile
|-
|-
|  
|  
<syntaxhighlight lang="Python">
<syntaxhighlight lang="Python">
#Updated 17 Oct 2019
#Updated 22 Jul 2023
import win32com.client
import Common


ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
def GetData():
 
     lSQL = "SELECT COMPANYNAME, REMARK, BRN, BRN2, GSTNO, "
def CheckLogin():
     lSQL = lSQL + "SALESTAXNO, SERVICETAXNO, "
     B = ComServer.IsLogin
    lSQL = lSQL + "ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS4 FROM SY_PROFILE "
     if B == True:
   
        ComServer.Logout()
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
    ComServer.Login("ADMIN", "ADMIN", #UserName, Password
      
                    "C:\eStream\SQLAccounting\Share\Default.DCF", #DCF file
    Common.ShowResult(lDataSet)
                    "ACC-0016.FDB") #Database Name
 
def PostData():
     BizObject = ComServer.BizObjects.Find("Agent")
      
      
     lDocKey = BizObject.FindKeyByRef("CODE", "FAIRY")
try:
       
     Common.CheckLogin()
     if lDocKey is None:
     global ComServer
        print ("Record Not Found")
     ComServer = Common.ComServer     
     else:
     GetData()
        BizObject.Params.Find("CODE").Value = lDocKey
     ComServer.Logout()
        BizObject.Open()
        BizObject.Delete()       
        print ("Done")
 
try:   
     CheckLogin()
     PostData()
finally:
finally:
    ComServer.Logout()
     ComServer = None
     ComServer = None
    Common.KillApp()
</syntaxhighlight>
</syntaxhighlight>
|}
|}
Line 431: Line 484:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Complete Post====
====Complete Post====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! SL_CS, AR_PM, SL_CN & AR_CN Script  
! SL_CS, AR_PM, SL_CN & AR_CN Script  
Line 437: Line 490:
|  
|  
<syntaxhighlight lang="Python">
<syntaxhighlight lang="Python">
#Updated 17 Oct 2019
#Updated 19 Jul 2023
#This will doing following posting
#This will doing following posting
#01. Cash Sales
#01. Cash Sales
Line 444: Line 497:
#04. Edit Credit Note Posted in Step 02 & Knock Off
#04. Edit Credit Note Posted in Step 02 & Knock Off
#05. Customer Refund to Knock off Credit Note
#05. Customer Refund to Knock off Credit Note
import win32com.client
import Common
import datetime
import datetime
ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
def CheckLogin():
    B = ComServer.IsLogin
    if B == True:
        ComServer.Logout()
    ComServer.Login("ADMIN", "ADMIN", #UserName, Password
                    "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                    "ACC-0016.FDB") #Database Name


def PostDataCS():     
def PostDataCS():     
Line 462: Line 505:
     lDetail = BizObject.DataSets.Find("cdsDocDetail") #lDetail contains detail data
     lDetail = BizObject.DataSets.Find("cdsDocDetail") #lDetail contains detail data
      
      
     lDate = datetime.datetime(2018, 2, 22, 13, 0)
     lDate = datetime.datetime(2023, 2, 22, 13, 0)
     lDate.strftime('%m/%d/%Y')
     lDate.strftime('%m/%d/%Y')
      
      
     BizObject.New();
     BizObject.New();
    lMain.FindField("DocKey").value = -1
     lMain.FindField("DocNo").AsString = "--IV Test--"
     lMain.FindField("DocNo").AsString = "--IV Test--"
     lMain.FindField("DocDate").value = lDate
     lMain.FindField("DocDate").value = lDate
Line 482: Line 524:
     #For Tax Inclusive = True with override Tax Amount
     #For Tax Inclusive = True with override Tax Amount
     lDetail.Append()
     lDetail.Append()
    lDetail.FindField("DtlKey").value = -1
    lDetail.FindField("DocKey").value = -1
     lDetail.FindField("Seq").value = 1
     lDetail.FindField("Seq").value = 1
     lDetail.FindField("Account").AsString = "500-000" #Sales Account
     lDetail.FindField("Account").AsString = "500-000" #Sales Account
Line 489: Line 529:
     lDetail.FindField("Description3").AsString = ("Item A Line 1" + ("\r" + "Item A Line 2"))
     lDetail.FindField("Description3").AsString = ("Item A Line 1" + ("\r" + "Item A Line 2"))
     lDetail.FindField("Qty").AsFloat = 1
     lDetail.FindField("Qty").AsFloat = 1
     lDetail.FindField("Tax").AsString = "SR"
     lDetail.FindField("Tax").AsString = "SV"
     lDetail.FindField("TaxRate").AsString = "6%"
     lDetail.FindField("TaxRate").AsString = "6%"
     lDetail.FindField("TaxInclusive").value = 0
     lDetail.FindField("TaxInclusive").value = 0
Line 504: Line 544:
     #For Tax Inclusive = False with override Tax Amount
     #For Tax Inclusive = False with override Tax Amount
     lDetail.Append()
     lDetail.Append()
    lDetail.FindField("DtlKey").value = -1
    lDetail.FindField("DocKey").value = -1
     lDetail.FindField("Seq").value = 2
     lDetail.FindField("Seq").value = 2
     lDetail.FindField("Account").AsString = "500-000"
     lDetail.FindField("Account").AsString = "500-000"
     lDetail.FindField("Description").AsString = "Sales Item B"
     lDetail.FindField("Description").AsString = "Sales Item B"
     lDetail.FindField("Qty").AsFloat = 1
     lDetail.FindField("Qty").AsFloat = 1
     lDetail.FindField("Tax").AsString = "SR"
     lDetail.FindField("Tax").AsString = "SV"
     lDetail.FindField("TaxRate").AsString = "6%"
     lDetail.FindField("TaxRate").AsString = "6%"
     lDetail.FindField("TaxInclusive").value = 0
     lDetail.FindField("TaxInclusive").value = 0
Line 520: Line 558:
     #For With Item Code
     #For With Item Code
     lDetail.Append()
     lDetail.Append()
    lDetail.FindField("DtlKey").value = -1
    lDetail.FindField("DocKey").value = -1
     lDetail.FindField("Seq").value = 3
     lDetail.FindField("Seq").value = 3
     lDetail.FindField("ItemCode").AsString = "ANT"
     lDetail.FindField("ItemCode").AsString = "ANT"
Line 529: Line 565:
     lDetail.FindField("UOM").AsString = "UNIT"
     lDetail.FindField("UOM").AsString = "UNIT"
     #lDetail.FindField("DISC").AsString        = "5%+3" #Optional(eg 5% plus 3 Discount)
     #lDetail.FindField("DISC").AsString        = "5%+3" #Optional(eg 5% plus 3 Discount)
     lDetail.FindField("Tax").AsString = "SR"
     lDetail.FindField("Tax").AsString = "SV"
     lDetail.FindField("TaxRate").AsString = "6%"
     lDetail.FindField("TaxRate").AsString = "6%"
     lDetail.FindField("TaxInclusive").value = 0
     lDetail.FindField("TaxInclusive").value = 0
Line 545: Line 581:
     lDetail = BizObject.DataSets.Find("cdsKnockOff") #lDetail contains detail data
     lDetail = BizObject.DataSets.Find("cdsKnockOff") #lDetail contains detail data
      
      
     lDate = datetime.datetime(2018, 2, 22, 13, 0)
     lDate = datetime.datetime(2023, 2, 22, 13, 0)
     lDate.strftime('%m/%d/%Y')
     lDate.strftime('%m/%d/%Y')
      
      
     BizObject.New()
     BizObject.New()
    lMain.FindField("DOCKEY").Value = -1
     lMain.FindField("DocNo").AsString = "--PM Test--"
     lMain.FindField("DocNo").AsString = "--PM Test--"
     lMain.FindField("CODE").AsString = "300-C0001" #Customer Account
     lMain.FindField("CODE").AsString = "300-C0001" #Customer Account
Line 578: Line 613:
     lDetail = BizObject.DataSets.Find("cdsDocDetail") #lDetail contains detail data
     lDetail = BizObject.DataSets.Find("cdsDocDetail") #lDetail contains detail data
      
      
     lDate = datetime.datetime(2018, 2, 22, 13, 0)
     lDate = datetime.datetime(2023, 2, 22, 13, 0)
     lDate.strftime('%m/%d/%Y')
     lDate.strftime('%m/%d/%Y')
      
      
     BizObject.New()
     BizObject.New()
    lMain.FindField("DocKey").value = -1
     lMain.FindField("DocNo").AsString = "--CN Test--"
     lMain.FindField("DocNo").AsString = "--CN Test--"
     lMain.FindField("DocDate").value = lDate
     lMain.FindField("DocDate").value = lDate
Line 597: Line 631:
     #For With Item Code
     #For With Item Code
     lDetail.Append()
     lDetail.Append()
    lDetail.FindField("DtlKey").value = -1
    lDetail.FindField("DocKey").value = -1
     lDetail.FindField("ItemCode").AsString = "ANT"
     lDetail.FindField("ItemCode").AsString = "ANT"
     lDetail.FindField("Description").AsString = "Sales Item B"
     lDetail.FindField("Description").AsString = "Sales Item B"
Line 605: Line 637:
     lDetail.FindField("Remark2").AsString = "01 Jan 2017"  #Invoice Date
     lDetail.FindField("Remark2").AsString = "01 Jan 2017"  #Invoice Date
     lDetail.FindField("Qty").AsFloat = 1
     lDetail.FindField("Qty").AsFloat = 1
     lDetail.FindField("Tax").AsString = "SR"
     lDetail.FindField("Tax").AsString = "SV"
     lDetail.FindField("TaxRate").AsString = "6%"
     lDetail.FindField("TaxRate").AsString = "6%"
     lDetail.FindField("TaxInclusive").value = 0
     lDetail.FindField("TaxInclusive").value = 0
Line 649: Line 681:
     lDetail = BizObject.DataSets.Find("cdsKnockOff") #lDetail contains detail data
     lDetail = BizObject.DataSets.Find("cdsKnockOff") #lDetail contains detail data
      
      
     lDate = datetime.datetime(2018, 2, 22, 13, 0)
     lDate = datetime.datetime(2023, 2, 22, 13, 0)
     lDate.strftime('%m/%d/%Y')
     lDate.strftime('%m/%d/%Y')
      
      
     BizObject.New()
     BizObject.New()
    lMain.FindField("DOCKEY").Value = -1
     lMain.FindField("DocNo").AsString = "--CF Test--"
     lMain.FindField("DocNo").AsString = "--CF Test--"
     lMain.FindField("CODE").AsString = "300-C0001" #Customer Account
     lMain.FindField("CODE").AsString = "300-C0001" #Customer Account
Line 678: Line 709:


try:
try:
     CheckLogin()
     Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
     print ("Posting Cash Sales")
     print ("Posting Cash Sales")
     PostDataCS()
     PostDataCS()
Line 690: Line 723:
     PostDataCF()
     PostDataCF()
     print ("Done")
     print ("Done")
    ComServer.Logout()
finally:
finally:
    ComServer.Logout()
     ComServer = None
     ComServer = None
    Common.KillApp()
</syntaxhighlight>
</syntaxhighlight>
|}
|}
Line 698: Line 732:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Get Picture & Description3(Rich Text)====
====Get Picture & Description3(Rich Text)====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Get Picture & Description3(Rich Text) Script  
! Get Picture & Description3(Rich Text) Script  
Line 704: Line 738:
|  
|  
<syntaxhighlight lang="Python">
<syntaxhighlight lang="Python">
#Updated 17 Oct 2019
#Updated 02 Aug 2023
import win32com.client
import os, sys
import Common
from io import BytesIO
from io import BytesIO
from PIL import Image
from PIL import Image
from striprtf.striprtf import rtf_to_text
ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
def CheckLogin():
    B = ComServer.IsLogin
    if B == True:
        ComServer.Logout()
    ComServer.Login("ADMIN", "ADMIN", #UserName, Password
                    "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                    "ACC-0081.FDB") #Database Name


def GetData():
def GetData():
Line 728: Line 752:
     dt = Image.open(imgdata)
     dt = Image.open(imgdata)
     dt.save("test.jpg")
     dt.save("test.jpg")
     print ("Done Export out...")
     print ("Done Export Picture file...")
    #print (lDataSet.FindField('Picture').Value)
      
      
     rtf = lDataSet.FindField('Description3').AsString
     rtf = lDataSet.FindField('Description3').AsString
     txt = rtf_to_text(rtf)
    print (rtf)
   
    with open('out.rtf', 'w') as output:
        output.write(rtf)
        output.close()
    print ("Done Export RTF file...")
   
     txt = ComServer.Utility.RichTextToPlainText(rtf)
     print (txt)
     print (txt)
      
      
try:
try:
     CheckLogin()    
     Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer   
     GetData()
     GetData()
finally:
     ComServer.Logout()
     ComServer.Logout()
finally:   
     ComServer = None
     ComServer = None
 
    Common.KillApp()
</syntaxhighlight>
</syntaxhighlight>
|}
|}
Line 746: Line 780:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Get Invoice Next Number====
====Get Invoice Next Number====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Get Invoice Next Number Script  
! Get Invoice Next Number Script  
Line 752: Line 786:
|  
|  
<syntaxhighlight lang="Python">
<syntaxhighlight lang="Python">
#Updated 17 Oct 2019
#Updated 19 Jul 2023
import win32com.client
import Common
 
ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
 
def CheckLogin():
    B = ComServer.IsLogin
    if B == True:
        ComServer.Logout()
    ComServer.Login("ADMIN", "ADMIN", #UserName, Password
                    "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                    "ACC-0081.FDB") #Database Name


def GetData():
def GetData():
Line 779: Line 803:
      
      
try:
try:
     CheckLogin()    
     Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer     
     GetData()
     GetData()
    ComServer.Logout()
finally:
finally:
    ComServer.Logout()
     ComServer = None
     ComServer = None
    Common.KillApp()
</syntaxhighlight>
</syntaxhighlight>
|}
|}


<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>
====Example-Add & Edit Stock Item====
 
====Stock Item====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Add & Edit Stock Item Script  
! Stock Item Script  
|-
|-
|  
|  
<syntaxhighlight lang="Python">
<syntaxhighlight lang="Python">
#Updated 16 Sep 2020
#Updated 21 Dec 2023
import win32com.client
import Common
 
     
ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
def GetListData():
 
     lSQL = "SELECT A.*, B.UOM, B.RATE, B.REFCOST, B.REFPRICE, B.ISBASE FROM ST_ITEM A "
def CheckLogin():
     lSQL = lSQL + "INNER JOIN ST_ITEM_UOM B ON (A.CODE=B.CODE) "
     B = ComServer.IsLogin
     lSQL = lSQL + "WHERE A.ISACTIVE='T' "
     if B == True:
    lSQL = lSQL + "ORDER BY A.CODE, B.RATE"  
        ComServer.Logout()
   
     ComServer.Login("ADMIN", "ADMIN", #UserName, Password
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
                    "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
       
                    "ACC-0015.FDB") #Database Name
    Common.ShowResult(lDataSet)


def PostData():
def PostData():
Line 862: Line 890:
         lDtl.FindField("RefCost").AsFloat = 22.3
         lDtl.FindField("RefCost").AsFloat = 22.3
         lDtl.FindField("RefPrice").AsFloat = 52
         lDtl.FindField("RefPrice").AsFloat = 52
        lDtl.FindField("ISBASE").AsFloat = 1
         lDtl.Post();
         lDtl.Post();


Line 869: Line 898:
         lDtl.FindField("RefCost").AsFloat = 102.5
         lDtl.FindField("RefCost").AsFloat = 102.5
         lDtl.FindField("RefPrice").AsFloat = 260.45
         lDtl.FindField("RefPrice").AsFloat = 260.45
        lDtl.FindField("ISBASE").AsFloat = 0
         lDtl.Post()
         lDtl.Post()
      
      
Line 889: Line 919:
         print("Oops!", e)     
         print("Oops!", e)     
     BizObject.Close()
     BizObject.Close()
     print ("Done")
     print ("Posting/Update Done")
 
def DelData():
    #Deleting only work if the record never use in other document
    BizObject = ComServer.BizObjects.Find("ST_ITEM")
      
      
    lDocKey = BizObject.FindKeyByRef("CODE", "FAIRY")
       
    if lDocKey is None:
        print ("Record Not Found")
    else:
        BizObject.Params.Find("Dockey").Value = lDocKey
        BizObject.Open()
        BizObject.Delete()       
        print ("Deleting Done")
try:
try:
     CheckLogin()
     Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
    GetListData()
     PostData()
     PostData()
   
    answer = input("Continue To delete?")
    if answer.lower() in ["y","yes"]:
        DelData()
    elif answer.lower() in ["n","no"]:
        print ("Deleting Aborted")
    else:
      print ("Invalid Input")
    ComServer.Logout()
finally:
finally:
    ComServer.Logout()
     ComServer = None
     ComServer = None
    Common.KillApp()
</syntaxhighlight>
</syntaxhighlight>
|}
|}
Line 902: Line 958:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Delete Stock Item====
====AR_Customer====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Delete Stock Item Script  
! AR_Customer Script  
|-
|-
|  
|  
<syntaxhighlight lang="Python">
<syntaxhighlight lang="Python">
#Updated 19 Oct 2019
#Updated 22 Jul 2023
import win32com.client
import Common
     
def GetListData():
    lSQL = "SELECT A.*, B.BRANCHTYPE, B.BRANCHNAME, B.ADDRESS1, B.ADDRESS2, B.ADDRESS3, B.ADDRESS4, "
    lSQL = lSQL + "B.GEOLAT, B.GEOLONG, B.ATTENTION, B.PHONE1, B.PHONE2, B.MOBILE, B.FAX1, B.FAX2, B.EMAIL "
    lSQL = lSQL + "FROM AR_CUSTOMER A "
    lSQL = lSQL + "INNER JOIN AR_CUSTOMERBRANCH B ON (A.CODE=B.CODE) "
    lSQL = lSQL + "WHERE A.STATUS='A' "
    lSQL = lSQL + "ORDER BY A.CODE, B.BRANCHTYPE "
   
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
       
    Common.ShowResult(lDataSet)


ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
def PostData():
 
def CheckLogin():
    B = ComServer.IsLogin
    if B == True:
        ComServer.Logout()
    ComServer.Login("ADMIN", "ADMIN", #UserName, Password
                    "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                    "ACC-0104.FDB") #Database Name
 
def PostData():
    BizObject = ComServer.BizObjects.Find("ST_ITEM")   
    lDocKey = BizObject.FindKeyByRef("CODE", "ANT")
       
    if lDocKey is None:
        print ("SKU Not Found...")
    else:
        try:
            BizObject.Params.Find("Dockey").Value = lDocKey           
            BizObject.Open()
            BizObject.Delete()
        except Exception as e:
            print("Oops!", e)
    BizObject.Close()   
    print ("Done")
   
try:
    CheckLogin()
    PostData()
finally:
    ComServer.Logout()
    ComServer = None
 
</syntaxhighlight>
|}
 
<div style="float: right;">  [[#top|[top]]]</div>
 
====Example-Add & Update AR_Customer====
{| class="mw-collapsible mw-collapsed wikitable"
! Add & Update AR_Customer Script
|-
|
<syntaxhighlight lang="Python">
#Updated 17 Apr 2020
import win32com.client
 
ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
 
def CheckLogin():
    B = ComServer.IsLogin
    if B == True:
        ComServer.Logout()
    ComServer.Login("ADMIN", "ADMIN", #UserName, Password
                    "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                    "ACC-0072.FDB") #Database Name
 
def PostData():
     BizObject = ComServer.BizObjects.Find("AR_CUSTOMER")
     BizObject = ComServer.BizObjects.Find("AR_CUSTOMER")
     lMain = BizObject.DataSets.Find("MainDataSet")
     lMain = BizObject.DataSets.Find("MainDataSet")
Line 1,014: Line 1,025:


         #Insert back with new Information
         #Insert back with new Information
         lDtl.Edit() #For 1St Branch
         lDtl.Append() #For 1St Branch
        lDtl.FindField("BranchType").AsString  = "B"
         lDtl.FindField("BranchName").AsString  = "BILLING" #Make sure this always same as b4 delete data
         lDtl.FindField("BranchName").AsString  = "BILLING" #Make sure this always same as b4 delete data
         lDtl.FindField("Address1").AsString    = "New Address1"
         lDtl.FindField("Address1").AsString    = "New Address1"
Line 1,027: Line 1,039:


         lDtl.Append() #For 2nd Branch
         lDtl.Append() #For 2nd Branch
        lDtl.FindField("BranchType").AsString  = "D"
         lDtl.FindField("BranchName").AsString  = "Branch1" #Make sure this always same as b4 delete data
         lDtl.FindField("BranchName").AsString  = "Branch1" #Make sure this always same as b4 delete data
         lDtl.FindField("Address1").AsString    = "New DAddress1"
         lDtl.FindField("Address1").AsString    = "New DAddress1"
Line 1,043: Line 1,056:
         print("Oops!", e)     
         print("Oops!", e)     
     BizObject.Close()
     BizObject.Close()
     print ("Done")
     print ("Posting/Update Done")
 
def DelData():
    #Deleting only work if the record never use in other document
    BizObject = ComServer.BizObjects.Find("AR_CUSTOMER")
      
      
    lDocKey = BizObject.FindKeyByRef("CODE", "FAIRY")
       
    if lDocKey is None:
        print ("Record Not Found")
    else:
        BizObject.Params.Find("CODE").Value = lDocKey
        BizObject.Open()
        BizObject.Delete()       
        print ("Deleting Done")
try:
try:
     CheckLogin()
     Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
    GetListData()
     PostData()
     PostData()
   
    answer = input("Continue To delete?")
    if answer.lower() in ["y","yes"]:
        DelData()
    elif answer.lower() in ["n","no"]:
        print ("Deleting Aborted")
    else:
      print ("Invalid Input")
    ComServer.Logout() 
finally:
finally:
    ComServer.Logout()
     ComServer = None
     ComServer = None
 
    Common.KillApp()
</syntaxhighlight>
</syntaxhighlight>
|}
|}
Line 1,057: Line 1,095:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Edit SL_CS====
====Sales Invoice====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Edit SL_CS Script
! SL_IV
|-
|-
|  
|  
<syntaxhighlight lang="Python">
<syntaxhighlight lang="Python">
#Updated 29 May 2020
#Updated 08 Jan 2024
import win32com.client
import Common
import datetime
     
def GetListData():
    lSQL = "SELECT A.DOCNO, A.DOCDATE, A.CODE, A.COMPANYNAME, A.DESCRIPTION, A.DOCAMT, "
    lSQL = lSQL + "A.AGENT, A.AREA, "
    lSQL = lSQL + "B.ITEMCODE, B.DESCRIPTION ITEMDESC, B.QTY, B.UOM, B.UNITPRICE, B.DISC,  "
    lSQL = lSQL + "B.TAX, B.TAXRATE, B.TAXAMT, B.TAXINCLUSIVE, B.AMOUNT "
    lSQL = lSQL + "FROM SL_IV A "
    lSQL = lSQL + "INNER JOIN SL_IVDTL B ON (A.DOCKEY=B.DOCKEY) "
    lSQL = lSQL + "WHERE A.CODE='300-A0002' "
    lSQL = lSQL + "AND A.CANCELLED='F' "
   
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
       
    Common.ShowResult(lDataSet)


ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
def PostData():
    BizObject = ComServer.BizObjects.Find("SL_IV")
    lMain = BizObject.DataSets.Find("MainDataSet") #lMain contains master data
    lDetail = BizObject.DataSets.Find("cdsDocDetail") #lDetail contains detail data
   
    lDate = datetime.datetime(2023, 2, 22, 13, 0)
    lDate.strftime('%m/%d/%Y')
   
    lDocKey = BizObject.FindKeyByRef("DocNo", "--IV Test--")
       
    if lDocKey is None:
        BizObject.New()
        lMain.FindField("DocNo").AsString = "--IV Test--"
        lMain.FindField("DocDate").value = lDate
        lMain.FindField("PostDate").value = lDate
        lMain.FindField("Code").AsString = "300-C0001" #Customer Account
        lMain.FindField("CompanyName").AsString = "Cash Sales"
        lMain.FindField("Address1").AsString = "" #Optional
        lMain.FindField("Address2").AsString = "" #Optional
        lMain.FindField("Address3").AsString = "" #Optional
        lMain.FindField("Address4").AsString = "" #Optional
        lMain.FindField("Phone1").AsString = ""  #Optional
        lMain.FindField("Description").AsString = "Sales"


def CheckLogin():
        #Insert Data - Detail
    B = ComServer.IsLogin
        #For Tax Inclusive = True with override Tax Amount
    if B == True:
        lDetail.Append()
         ComServer.Logout()
        lDetail.FindField("Seq").value = 1
    ComServer.Login("ADMIN", "ADMIN", #UserName, Password
        lDetail.FindField("Account").AsString = "500-000" #Sales Account
                    "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
        lDetail.FindField("Description").AsString = "Sales Item A"
                    "ACC-0091.FDB") #Database Name
        lDetail.FindField("Description3").AsString = ("Item A Line 1" + ("\r" + "Item A Line 2"))
         lDetail.FindField("Qty").AsFloat = 1
        lDetail.FindField("Tax").AsString = "SV"
        lDetail.FindField("TaxRate").AsString = "6%"
        lDetail.FindField("TaxInclusive").value = 0
        lDetail.FindField("UnitPrice").AsFloat = 435
        lDetail.FindField("Amount").AsFloat = 410.37 #Exclding GST Amt
        lDetail.FindField("TaxAmt").AsFloat = 24.63


def PostData():
        lDetail.DisableControls()
    lSQL = "SELECT Dockey FROM SL_CS "
        lDetail.FindField("TaxInclusive").value = 1
    lSQL = lSQL + "WHERE DocNo='--CS Test--' "
        lDetail.EnableControls()
    lSQL = lSQL + " AND Code='300-K0001' "
      
      
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
        lDetail.Post()
 
        #For Tax Inclusive = False with override Tax Amount
        lDetail.Append()
        lDetail.FindField("Seq").value = 2
        lDetail.FindField("Account").AsString = "500-000"
        lDetail.FindField("Description").AsString = "Sales Item B"
        lDetail.FindField("Qty").AsFloat = 1
        lDetail.FindField("Tax").AsString = "SV"
        lDetail.FindField("TaxRate").AsString = "6%"
        lDetail.FindField("TaxInclusive").value = 0
        lDetail.FindField("UnitPrice").AsFloat = 94.43
        lDetail.FindField("Amount").AsFloat = 94.43
        lDetail.FindField("TaxAmt").AsFloat = 5.66
        lDetail.Post()
      
      
     BizObject = ComServer.BizObjects.Find("SL_CS")
        #For With Item Code
    lMain = BizObject.DataSets.Find("MainDataSet")
        lDetail.Append()
    lDtl = BizObject.DataSets.Find("cdsDocDetail")
        lDetail.FindField("Seq").value = 3
        lDetail.FindField("ItemCode").AsString = "ANT"
        lDetail.FindField("Description").AsString = "Sales Item B"
        #lDetail.FindField("Account").AsString     = "500-000" #If you wanted override the Sales Account Code
        lDetail.FindField("Qty").AsFloat = 2
        lDetail.FindField("UOM").AsString = "UNIT"
        #lDetail.FindField("DISC").AsString        = "5%+3" #Optional(eg 5% plus 3 Discount)
        lDetail.FindField("Tax").AsString = "SV"
        lDetail.FindField("TaxRate").AsString = "6%"
        lDetail.FindField("TaxInclusive").value = 0
        lDetail.FindField("UnitPrice").AsFloat = 100
        lDetail.FindField("Amount").AsFloat = 200
        lDetail.FindField("TaxAmt").AsFloat = 12
        lDetail.Post()
      
      
     
     else:
     if lDataSet.RecordCount > 0:
         BizObject.Params.Find("Dockey").Value = lDocKey
        lDataSet.First()       
         BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString
         BizObject.Open()
         BizObject.Open()
         BizObject.Edit()
         BizObject.Edit()
         lMain.Edit()
         lMain.Edit()
         lMain.FindField("Description").AsString = "Edited Description 123"
         lMain.FindField("Description").AsString = "Edited Description 123 的第一 🐱"


         #Delete all Detail
         #Delete all Detail
         while lDtl.RecordCount != 0:
         while lDetail.RecordCount != 0:
             lDtl.First()
             lDetail.Last()
             lDtl.Delete()
             lDetail.Delete()
              
              
         #Append Detail
         #Append Detail
         lDtl.Append()
         lDetail.Append()
         lDtl.FindField("DtlKey").value = -1
         #lDetail.FindField("Account").value = "500-000"
         lDtl.FindField("Account").value = "500-0000"
         lDetail.FindField("Description").AsString = "Item A  的第一"
         lDtl.FindField("Description").value = "Item A"
         lDetail.FindField("Description3").AsString = ComServer.Utility.PlainTextToRichText("More description  的第一 🐱")
         lDtl.FindField("Tax").value = ""
         lDetail.FindField("Tax").value = ""
         lDtl.FindField("TaxInclusive").value = 0
         lDetail.FindField("TaxInclusive").value = 0
         lDtl.FindField("Amount").value = 410.37
         lDetail.FindField("Amount").value = 410.37
         lDtl.FindField("TaxAmt").value = 0
         lDetail.FindField("TaxAmt").value = 0
         lDtl.Post()
         lDetail.Post()
   
       
     try:
     try:
         BizObject.Save()           
         BizObject.Save()           
Line 1,117: Line 1,223:
         print("Oops!", e)     
         print("Oops!", e)     
     BizObject.Close()
     BizObject.Close()
     print ("Done")
     print ("Posting/Update Done")
 
def DelData():
    #Deleting only work if the record never not knock off by Payment or Credit Note
    BizObject = ComServer.BizObjects.Find("SL_IV")
      
      
    lDocKey = BizObject.FindKeyByRef("DocNo", "--IV Test--")
       
    if lDocKey is None:
        print ("Record Not Found")
    else:
        BizObject.Params.Find("Dockey").Value = lDocKey
        BizObject.Open()
        BizObject.Delete()       
        print ("Deleting Done")
try:
try:
     CheckLogin()
     Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
    GetListData()
     PostData()
     PostData()
   
    answer = input("Continue To delete?")
    if answer.lower() in ["y","yes"]:
        DelData()
    elif answer.lower() in ["n","no"]:
        print ("Deleting Aborted")
    else:
      print ("Invalid Input")
     
    ComServer.Logout() 
finally:
finally:
    ComServer.Logout()
     ComServer = None
     ComServer = None
 
    Common.KillApp()
</syntaxhighlight>
</syntaxhighlight>
|}
|}


<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>
====Example-GL Ledger====
 
====Purchase Invoice====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! GL Ledger Script
! PH_PI
|-
|-
|  
|  
<syntaxhighlight lang="Python">
<syntaxhighlight lang="Python">
#Updated 17 Aug 2020
#Updated 08 Jan 2024
import win32com.client
import Common
import datetime
     
def GetListData():
    lSQL = "SELECT A.DOCNO, A.DOCDATE, A.CODE, A.COMPANYNAME, A.DESCRIPTION, A.DOCAMT, "
    lSQL = lSQL + "A.AGENT, A.AREA, "
    lSQL = lSQL + "B.ITEMCODE, B.DESCRIPTION ITEMDESC, B.QTY, B.UOM, B.UNITPRICE, B.DISC,  "
    lSQL = lSQL + "B.TAX, B.TAXRATE, B.TAXAMT, B.TAXINCLUSIVE, B.AMOUNT "
    lSQL = lSQL + "FROM PH_PI A "
    lSQL = lSQL + "INNER JOIN PH_PIDTL B ON (A.DOCKEY=B.DOCKEY) "
    lSQL = lSQL + "WHERE A.CODE='400-L0001' "
    lSQL = lSQL + "AND A.CANCELLED='F' "
   
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
       
    Common.ShowResult(lDataSet)


ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
def PostData():
    BizObject = ComServer.BizObjects.Find("PH_PI")
    lMain = BizObject.DataSets.Find("MainDataSet") #lMain contains master data
    lDetail = BizObject.DataSets.Find("cdsDocDetail") #lDetail contains detail data
   
    lDate = datetime.datetime(2023, 2, 22, 13, 0)
    lDate.strftime('%m/%d/%Y')
   
    V = ["--PI Test--", "400-W0001"]  #DocNo, Code
   
    lDocKey = BizObject.FindKeyByRef("DocNo;Code", V)
       
    if lDocKey is None:
        BizObject.New()
        lMain.FindField("DocNo").AsString = "--PI Test--"
        lMain.FindField("DocDate").value = lDate
        lMain.FindField("PostDate").value = lDate
        lMain.FindField("Code").AsString = "400-W0001" #Supplier Account
        lMain.FindField("CompanyName").AsString = "WORLDLINE COMMUNICATION SDN BHD"
        #lMain.FindField("Address1").AsString = "" #Optional
        #lMain.FindField("Address2").AsString = "" #Optional
        #lMain.FindField("Address3").AsString = "" #Optional
        #lMain.FindField("Address4").AsString = "" #Optional
        #lMain.FindField("Phone1").AsString = ""  #Optional
        lMain.FindField("Description").AsString = "Purchase Invoice"
 
        #Insert Data - Detail   
        lDetail.Append()
        lDetail.FindField("Seq").value = 1
        lDetail.FindField("ItemCode").AsString = "ANT"
        lDetail.FindField("Description").AsString = "Item B"
        #lDetail.FindField("Account").AsString    = "600-000" #If you wanted override the Purchase Account Code
        lDetail.FindField("Qty").AsFloat = 2
        lDetail.FindField("UOM").AsString = "UNIT"
        #lDetail.FindField("DISC").AsString        = "5%+3" #Optional(eg 5% plus 3 Discount)
        lDetail.FindField("Tax").AsString = ""
        lDetail.FindField("TaxRate").AsString = ""
        lDetail.FindField("TaxInclusive").value = 0
        lDetail.FindField("UnitPrice").AsFloat = 80
        lDetail.FindField("Amount").AsFloat = 160
        lDetail.FindField("TaxAmt").AsFloat = 0
        lDetail.Post()
       
        lDetail.Append()
        lDetail.FindField("Seq").value = 2
        lDetail.FindField("ItemCode").AsString = "HFK"
        lDetail.FindField("Description").AsString = "HANDS FREE KITS"
        #lDetail.FindField("Account").AsString    = "600-000" #If you wanted override the Purchase Account Code
        lDetail.FindField("Qty").AsFloat = 3
        lDetail.FindField("UOM").AsString = "UNIT"
        #lDetail.FindField("DISC").AsString        = "5%+3" #Optional(eg 5% plus 3 Discount)
        lDetail.FindField("Tax").AsString = ""
        lDetail.FindField("TaxRate").AsString = ""
        lDetail.FindField("TaxInclusive").value = 0
        lDetail.FindField("UnitPrice").AsFloat = 50
        lDetail.FindField("Amount").AsFloat = 150
        lDetail.FindField("TaxAmt").AsFloat = 0
        lDetail.Post()       
   
    else:
        BizObject.Params.Find("Dockey").Value = lDocKey
        BizObject.Open()
        BizObject.Edit()
        lMain.Edit()
        lMain.FindField("Description").AsString = "Edited Description 123 的第一 🐱"


def CheckLogin():
        #Delete all Detail
    B = ComServer.IsLogin
        while lDetail.RecordCount != 0:
    if B == True:
            lDetail.Last()
         ComServer.Logout()
            lDetail.Delete()
    ComServer.Login("ADMIN", "ADMIN", #UserName, Password
           
                    "C:\\eStream\\SQLAccounting\\Share\\Default.DCF", #DCF file
        #Append Detail
                    "ACC-0081.FDB") #Database Name
        lDetail.Append()
        #lDetail.FindField("Account").value = "600-000"
        lDetail.FindField("Description").AsString = "Item A  的第一"
         lDetail.FindField("Description3").AsString = ComServer.Utility.PlainTextToRichText("More description  的第一 🐱")
        lDetail.FindField("Tax").value = ""
        lDetail.FindField("TaxInclusive").value = 0
        lDetail.FindField("Amount").value = 410.37
        lDetail.FindField("TaxAmt").value = 0
        lDetail.Post()
       
    try:
        BizObject.Save()         
    except Exception as e:
        print("Oops!", e)   
    BizObject.Close()
    print ("Posting/Update Done")


def GetData():
def DelData():
     lSQL = "SELECT A.CODE, B.DESCRIPTION ACCDESC, A.DOCDATE, A.POSTDATE, A.DESCRIPTION, A.DESCRIPTION2,  "
     #Deleting only work if the record never not knock off by Payment or Credit Note
     lSQL = lSQL + "A.LOCALDR, A.LOCALCR, A.REF1, A.REF2 FROM GL_TRANS A "
     BizObject = ComServer.BizObjects.Find("PH_PI")
    lSQL = lSQL + "INNER JOIN GL_ACC B ON (A.CODE=B.CODE) "
    lSQL = lSQL + "WHERE A.CANCELLED='F' "
    lSQL = lSQL + "AND A.POSTDATE BETWEEN '01 JAN 2018'  "
    lSQL = lSQL + "AND '31 DEC 2018' "
    lSQL = lSQL + "AND A.CODE='500-2000' "
    lSQL = lSQL + "ORDER BY A.CODE, A.POSTDATE "
      
      
     lDataSet = ComServer.DBManager.NewDataSet(lSQL)
     V = ["--PI Test--", "400-W0001"]  #DocNo, Code
      
      
     if lDataSet.RecordCount > 0:
     lDocKey = BizObject.FindKeyByRef("DocNo;Code", V)  
        while not lDataSet.eof:
       
            print(lDataSet.FindField('CODE').AsString)
    if lDocKey is None:
            print(lDataSet.FindField('ACCDESC').AsString)
        print ("Record Not Found")
            print(lDataSet.FindField('Description').AsString)
            print(lDataSet.FindField('REF1').AsString)
            print(lDataSet.FindField('LOCALDR').AsString)
            print(lDataSet.FindField('LOCALCR').AsString)
            print("===")
            lDataSet.Next()
     else:
     else:
         print ("Record Not Found")
        BizObject.Params.Find("Dockey").Value = lDocKey
   
        BizObject.Open()
        BizObject.Delete()       
         print ("Deleting Done")
 
try:
try:
     CheckLogin()    
     Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
    GetListData()
    PostData()
   
    answer = input("Continue To delete?")
    if answer.lower() in ["y","yes"]:
        DelData()
    elif answer.lower() in ["n","no"]:
        print ("Deleting Aborted")
    else:
      print ("Invalid Input")
     
    ComServer.Logout() 
finally:
    ComServer = None
    Common.KillApp()
</syntaxhighlight>
|}
 
<div style="float: right;">  [[#top|[top]]]</div>
 
====GL Ledger====
{| class="mw-collapsible mw-collapsed wikitable"
! GL Ledger Script
|-
|
<syntaxhighlight lang="Python">
#Updated 24 Jul 2023
import Common
 
def GetData():
    lSQL = "SELECT A.CODE, B.DESCRIPTION ACCDESC, A.DOCDATE, A.POSTDATE, A.DESCRIPTION, A.DESCRIPTION2,  "
    lSQL = lSQL + "A.LOCALDR, A.LOCALCR, A.REF1, A.REF2 FROM GL_TRANS A "
    lSQL = lSQL + "INNER JOIN GL_ACC B ON (A.CODE=B.CODE) "
    lSQL = lSQL + "WHERE A.CANCELLED='F' "
    lSQL = lSQL + "AND A.POSTDATE BETWEEN '01 JAN 2023'  "
    lSQL = lSQL + "AND '31 DEC 2023' "
    lSQL = lSQL + "AND A.CODE='310-000' "
    lSQL = lSQL + "ORDER BY A.CODE, A.POSTDATE "
   
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
   
    Common.ShowResult(lDataSet)
   
try:
    Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer     
     GetData()
     GetData()
finally:
     ComServer.Logout()
     ComServer.Logout()
finally:   
     ComServer = None
     ComServer = None
 
    Common.KillApp()
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-GL Trial Balance====
====GL Trial Balance====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! GL Trial Balance Script  
! GL Trial Balance Script  
Line 1,191: Line 1,458:
|  
|  
<syntaxhighlight lang="Python">
<syntaxhighlight lang="Python">
#Updated 17 Aug 2020
#Updated 25 Jul 2023
import win32com.client
import Common
import datetime
import datetime
ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
def CheckLogin():
    B = ComServer.IsLogin
    if B == True:
        ComServer.Logout()
    ComServer.Login("ADMIN", "ADMIN", #UserName, Password
                    "C:\\eStream\\SQLAccounting\\Share\\Default.DCF",  #DCF file
                    "ACC-0081.FDB") #Database Name


def GetData():
def GetData():
Line 1,234: Line 1,491:
     lDataSet2 = RptObject.DataSets.Find("cdsGLAccount") #For Account List
     lDataSet2 = RptObject.DataSets.Find("cdsGLAccount") #For Account List
      
      
    if lDataSet2.RecordCount > 0:
        while not lDataSet2.eof:
            print(lDataSet2.FindField('CODE').AsString)
            print(lDataSet2.FindField('DESCRIPTION').AsString)
            print("===")
            lDataSet2.Next()
           
     if lDataSet.RecordCount > 0:
     if lDataSet.RecordCount > 0:
         while not lDataSet.eof:
         while not lDataSet.eof:
Line 1,250: Line 1,514:
      
      
try:
try:
     CheckLogin()    
     Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer     
     GetData()
     GetData()
finally:
     ComServer.Logout()
     ComServer.Logout()
finally:   
     ComServer = None
     ComServer = None
    Common.KillApp()
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Get AR_Customer List====
====Terms====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Get AR_Customer List Script
! Terms
|-
|-
|  
|  
<syntaxhighlight lang="Python">
<syntaxhighlight lang="Python">
#Updated 25 Aug 2020
#Updated 25 Jul 2023
import win32com.client
import Common
 
     
ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
def GetListData():
 
     lSQL = "SELECT * FROM TERMS "
def CheckLogin():
     lSQL = lSQL + "WHERE ISACTIVE='T' "
    B = ComServer.IsLogin
     lSQL = lSQL + "ORDER BY CODE "
    if B == True:
        ComServer.Logout()
    ComServer.Login("ADMIN", "ADMIN", #UserName, Password
                    "C:\\eStream\\SQLAccounting\\Share\\Default.DCF",  #DCF file
                    "ACC-0112.FDB") #Database Name
 
def GetData():
     lSQL = "SELECT A.*, B.BRANCHTYPE, B.BRANCHNAME, B.ADDRESS1, B.ADDRESS2, B.ADDRESS3, B.ADDRESS4, "
    lSQL = lSQL + "B.GEOLAT, B.GEOLONG, B.ATTENTION, B.PHONE1, B.PHONE2, B.MOBILE, B.FAX1, B.FAX2, B.EMAIL "
    lSQL = lSQL + "FROM AR_CUSTOMER A "
    lSQL = lSQL + "INNER JOIN AR_CUSTOMERBRANCH B ON (A.CODE=B.CODE) "
     lSQL = lSQL + "WHERE A.STATUS='A' "
     lSQL = lSQL + "ORDER BY A.CODE, B.BRANCHTYPE "
      
      
     lDataSet = ComServer.DBManager.NewDataSet(lSQL)
     lDataSet = ComServer.DBManager.NewDataSet(lSQL)
          
          
     while not lDataSet.eof:
     Common.ShowResult(lDataSet)
        fc = lDataSet.Fields.Count
 
        for x in range(fc):
            fn = lDataSet.Fields.Items(x).FieldName
            fv = lDataSet.FindField(fn).AsString
            lresult = "Index : "+ str(x) + " FieldName : " + fn + " Value : " + fv
            print (lresult)
        print("====")
        lDataSet.Next()
try:
    CheckLogin()     
    GetData()
finally:
    ComServer.Logout()
    ComServer = None
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>
 
====Example-Add & Edit Terms====
{| class="mw-collapsible mw-collapsed wikitable"
! Add & Edit Terms Script
|-
|
<syntaxhighlight lang="Python">
#Updated 12 Oct 2020
import win32com.client
 
ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
 
def CheckLogin():
    B = ComServer.IsLogin
    if B == True:
        ComServer.Logout()
    ComServer.Login("ADMIN", "ADMIN", #UserName, Password
                    "C:\\eStream\\SQLAccounting\\Share\\Default.DCF",  #DCF file
                    "ACC-0121.FDB") #Database Name   
 
def PostData():
def PostData():
     BizObject = ComServer.BizObjects.Find("Terms")
     BizObject = ComServer.BizObjects.Find("Terms")
Line 1,346: Line 1,564:
          
          
     try:
     try:
         BizObject.Save()
         BizObject.Save()        
     except Exception as e:
     except Exception as e:
         print("Oops!", e)     
         print("Oops!", e)     
     print ("Done")
    BizObject.Close()
     print ("Posting/Update Done")
 
def DelData():
    #Deleting only work if the record never use in other document
    BizObject = ComServer.BizObjects.Find("Terms")
      
      
    lDocKey = BizObject.FindKeyByRef("CODE", "90 Days")
       
    if lDocKey is None:
        print ("Record Not Found")
    else:
        BizObject.Params.Find("CODE").Value = lDocKey
        BizObject.Open()
        BizObject.Delete()       
        print ("Deleting Done")
try:
try:
     CheckLogin()
     Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
    GetListData()
     PostData()
     PostData()
   
    answer = input("Continue To delete?")
    if answer.lower() in ["y","yes"]:
        DelData()
    elif answer.lower() in ["n","no"]:
        print ("Deleting Aborted")
    else:
      print ("Invalid Input")
     
    ComServer.Logout() 
finally:
finally:
    ComServer.Logout()
     ComServer = None
     ComServer = None
    Common.KillApp()
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Add & Edit Company Category====
====Stock Adjustment====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Add & Edit Company Category Script
! ST_SJ
|-
|-
|  
|  
<syntaxhighlight lang="Python">
<syntaxhighlight lang="Python">
#Updated 12 Oct 2020
#Updated 08 Jan 2024
import win32com.client
import Common
 
import datetime
ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
     
 
def GetListData():
def CheckLogin():
     lSQL = "SELECT A.DOCNO, A.DOCDATE, A.DESCRIPTION, A.DOCAMT, "
     B = ComServer.IsLogin
     lSQL = lSQL + "A.AUTHBY, A.REASON, A.REMARK, "
     if B == True:
    lSQL = lSQL + "B.ITEMCODE, B.DESCRIPTION ITEMDESC, B.QTY, B.UOM, B.UNITCOST, "
        ComServer.Logout()
    lSQL = lSQL + "B.AMOUNT, B.REMARK1, B.REMARK2 "
     ComServer.Login("ADMIN", "ADMIN", #UserName, Password
     lSQL = lSQL + "FROM ST_AJ A "
                    "C:\\eStream\\SQLAccounting\\Share\\Default.DCF",  #DCF file
    lSQL = lSQL + "INNER JOIN ST_AJDTL B ON (A.DOCKEY=B.DOCKEY) "
                    "ACC-0121.FDB") #Database Name   
    lSQL = lSQL + "WHERE A.DocDate='20 Apr 2013' "
    lSQL = lSQL + "AND A.CANCELLED='F' "
   
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
       
    Common.ShowResult(lDataSet)


def PostData():
def PostData():
     BizObject = ComServer.BizObjects.Find("COMPANYCATEGORY")
     BizObject = ComServer.BizObjects.Find("ST_AJ")
     lMain = BizObject.DataSets.Find("MainDataSet")
     lMain = BizObject.DataSets.Find("MainDataSet") #lMain contains master data
    lDetail = BizObject.DataSets.Find("cdsDocDetail") #lDetail contains detail data
      
      
     lDocKey = BizObject.FindKeyByRef("CODE", "FAIRY")
    lDate = datetime.datetime(2023, 2, 22, 13, 0)
    lDate.strftime('%m/%d/%Y')
       
     lDocKey = BizObject.FindKeyByRef("DocNo", "--AJ Test--")
          
          
     if lDocKey is None:
     if lDocKey is None:
         BizObject.New()
         BizObject.New()
         lMain.FindField("CODE").value = "FAIRY"
         lMain.FindField("DocNo").AsString = "--AJ Test--"
         lMain.FindField("DESCRIPTION").value = "FAIRY TAIL"
        lMain.FindField("DocDate").value = lDate
         lMain.FindField("ISACTIVE").value = "T"
        lMain.FindField("PostDate").value = lDate
         lMain.FindField("Description").AsString = "Stock Adjustment"
 
        #Insert Data - Detail - Increase Stock Qty 
        lDetail.Append()
        lDetail.FindField("Seq").value = 1
        lDetail.FindField("ItemCode").AsString = "ANT"
        lDetail.FindField("Description").AsString = "ANTENA"
        lDetail.FindField("Qty").AsFloat = 2
        lDetail.FindField("UOM").AsString = "PCS"
        lDetail.FindField("UnitCOST").AsFloat = 80
        lDetail.FindField("Amount").AsFloat = 160
         lDetail.Post()
       
        #Insert Data - Detail - Reduce Stock Qty
        lDetail.Append()
        lDetail.FindField("Seq").value = 2
        lDetail.FindField("ItemCode").AsString = "HFK"
        lDetail.FindField("Description").AsString = "HANDS FREE KITS"
        lDetail.FindField("Qty").AsFloat = -3
        lDetail.FindField("UOM").AsString = "UNIT"
        lDetail.Post()       
   
     else:
     else:
         BizObject.Params.Find("CODE").Value = lDocKey
         BizObject.Params.Find("Dockey").Value = lDocKey
         BizObject.Open()
         BizObject.Open()
         BizObject.Edit()
         BizObject.Edit()
         lMain.FindField("DESCRIPTION").value = "FAIRY TAIL WIZARD"
         lMain.Edit()
         lMain.FindField("ISACTIVE").value = "F"
        lMain.FindField("Description").AsString = "Edited Description 123 的第一 🐱"
 
        #Delete all Detail
        while lDetail.RecordCount != 0:
            lDetail.Last()
            lDetail.Delete()
           
        #Append Detail
        lDetail.Append()
        lDetail.FindField("Seq").value = 1
        lDetail.FindField("ItemCode").AsString = "BOM"
        lDetail.FindField("Description").AsString = "Bill Of Material"       
        lDetail.FindField("Qty").AsFloat = -1
         lDetail.FindField("UOM").AsString = "UNIT"
        lDetail.Post()
          
          
     try:
     try:
         BizObject.Save()
         BizObject.Save()        
     except Exception as e:
     except Exception as e:
         print("Oops!", e)     
         print("Oops!", e)     
     print ("Done")
    BizObject.Close()
      
     print ("Posting/Update Done")
 
def DelData():
    BizObject = ComServer.BizObjects.Find("ST_AJ")
       
     lDocKey = BizObject.FindKeyByRef("DocNo", "--AJ Test--")   
       
    if lDocKey is None:
        print ("Record Not Found")
    else:
        BizObject.Params.Find("Dockey").Value = lDocKey
        BizObject.Open()
        BizObject.Delete()       
        print ("Deleting Done")
 
try:
try:
     CheckLogin()
     Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
    GetListData()
     PostData()
     PostData()
   
    answer = input("Continue To delete?")
    if answer.lower() in ["y","yes"]:
        DelData()
    elif answer.lower() in ["n","no"]:
        print ("Deleting Aborted")
    else:
      print ("Invalid Input")
     
    ComServer.Logout() 
finally:
finally:
    ComServer.Logout()
     ComServer = None
     ComServer = None
    Common.KillApp()
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Add & Edit ST_AJ====
====Sales Order====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Add & Edit ST_SJ Script
! Sales Order
|-
|-
|  
|  
<syntaxhighlight lang="Python">
<syntaxhighlight lang="Python">
import win32com.client
#Updated 08 Jan 2024
import Common
import datetime
import datetime
 
     
ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
def GetListData():
 
     lSQL = "SELECT A.DOCNO, A.DOCDATE, A.CODE, A.COMPANYNAME, A.DESCRIPTION, A.DOCAMT, "
def CheckLogin():
     lSQL = lSQL + "A.AGENT, A.AREA, "
     B = ComServer.IsLogin
     lSQL = lSQL + "B.ITEMCODE, B.DESCRIPTION ITEMDESC, B.QTY, B.UOM, B.UNITPRICE, B.DISC,  "
     if B == True:
    lSQL = lSQL + "B.TAX, B.TAXRATE, B.TAXAMT, B.TAXINCLUSIVE, B.AMOUNT "
        ComServer.Logout()
    lSQL = lSQL + "FROM SL_SO A "
     ComServer.Login("ADMIN", "ADMIN", #UserName, Password
    lSQL = lSQL + "INNER JOIN SL_SODTL B ON (A.DOCKEY=B.DOCKEY) "
                    "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
    lSQL = lSQL + "WHERE A.CODE='300-A0002' "
                    "ACC-0100.FDB") #Database Name
    lSQL = lSQL + "AND A.CANCELLED='F' "
   
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
       
    Common.ShowResult(lDataSet)


def PostData():
def PostData():
     lSQL = "SELECT Dockey FROM ST_AJ "
     BizObject = ComServer.BizObjects.Find("SL_SO")
     lSQL = lSQL + "WHERE DocNo='--AJ Test--' "
     lMain = BizObject.DataSets.Find("MainDataSet") #lMain contains master data
      
     lDetail = BizObject.DataSets.Find("cdsDocDetail") #lDetail contains detail data
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
      
      
    BizObject = ComServer.BizObjects.Find("ST_AJ")
     lDate = datetime.datetime(2023, 2, 22, 13, 0)
    lMain = BizObject.DataSets.Find("MainDataSet")
    lDtl = BizObject.DataSets.Find("cdsDocDetail")
 
     lDate = datetime.datetime(2020, 2, 22, 13, 0)
     lDate.strftime('%m/%d/%Y')
     lDate.strftime('%m/%d/%Y')
      
      
     if lDataSet.RecordCount > 0:
    lDocKey = BizObject.FindKeyByRef("DocNo", "--SO Test--")
         lDataSet.First()  
       
         BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString
     if lDocKey is None:
        BizObject.New()
        lMain.FindField("DocNo").AsString = "--SO Test--"
        lMain.FindField("DocDate").value = lDate
        lMain.FindField("PostDate").value = lDate
        lMain.FindField("Code").AsString = "300-C0001" #Customer Account
        lMain.FindField("CompanyName").AsString = "Cash Sales"
        #lMain.FindField("Address1").AsString = "" #Optional
        #lMain.FindField("Address2").AsString = "" #Optional
        #lMain.FindField("Address3").AsString = "" #Optional
        #lMain.FindField("Address4").AsString = "" #Optional
        #lMain.FindField("Phone1").AsString = ""  #Optional
        lMain.FindField("Description").AsString = "Sales Order"
 
        #Insert Data - Detail   
        lDetail.Append()
        lDetail.FindField("Seq").value = 1
        lDetail.FindField("ItemCode").AsString = "ANT"
        lDetail.FindField("Description").AsString = "Sales Item B"
        lDetail.FindField("Qty").AsFloat = 2
         lDetail.FindField("UOM").AsString = "UNIT"
         #lDetail.FindField("DISC").AsString        = "5%+3" #Optional(eg 5% plus 3 Discount)
        lDetail.FindField("Tax").AsString = "SV"
        lDetail.FindField("TaxRate").AsString = "6%"
        lDetail.FindField("TaxInclusive").value = 0
        lDetail.FindField("UnitPrice").AsFloat = 100
        lDetail.FindField("Amount").AsFloat = 200
        lDetail.FindField("TaxAmt").AsFloat = 12
        lDetail.Post()
   
    else:
        BizObject.Params.Find("Dockey").Value = lDocKey
         BizObject.Open()
         BizObject.Open()
         BizObject.Edit()
         BizObject.Edit()
         lMain.FindField("Description").AsString = "Edited Description 123"
        lMain.Edit()
       
         lMain.FindField("Description").AsString = "Edited Description 123 的第一 🐱"
        while lDtl.RecordCount != 0:
            lDtl.First()
            lDtl.Delete()


        #Delete all Detail
        while lDetail.RecordCount != 0:
            lDetail.Last()
            lDetail.Delete()
           
         #Append Detail
         #Append Detail
         lDtl.Append()
         lDetail.Append()
         lDtl.FindField("DtlKey").value = -1
         lDetail.FindField("Seq").value = 1
        lDtl.FindField("Seq").value = 1
         lDetail.FindField("ItemCode").AsString = "BOM"
         lDtl.FindField("ItemCode").value = "E-BAT"
         lDetail.FindField("Description").AsString = "Sales Item BOM"
         lDtl.FindField("Description").value = "ERICSSON BATTERY"
         lDetail.FindField("Qty").AsFloat = 1
         lDtl.FindField("Qty").value = 2
         lDetail.FindField("UOM").AsString = "UNIT"
         lDtl.FindField("UOM").value = "UNIT"
         #lDetail.FindField("DISC").AsString       = "5%+3" #Optional(eg 5% plus 3 Discount)
         lDtl.Post()   
         lDetail.FindField("Tax").AsString = "SV"
    else:
         lDetail.FindField("TaxRate").AsString = "6%"
        BizObject.New()
         lDetail.FindField("TaxInclusive").value = 0
        lMain.FindField("DocKey").value = -1
         lDetail.FindField("UnitPrice").AsFloat = 100
        lMain.FindField("DocNo").value = "--AJ Test--"
         lDetail.FindField("Amount").AsFloat = 100
        lMain.FindField("DocDate").value = lDate
         lDetail.FindField("TaxAmt").AsFloat = 6
        lMain.FindField("PostDate").value = lDate        
         lDetail.Post()
        lMain.FindField("Description").value = "Stock Adjustment"
 
        #Insert Data - Detail - Increase Stock Qty
        lDtl.Append()
         lDtl.FindField("DtlKey").value = -1
        lDtl.FindField("Seq").value = 1
         lDtl.FindField("ItemCode").value = "ANT"
         lDtl.FindField("Description").value = "ANTENA"
         lDtl.FindField("Qty").value = 2
         lDtl.FindField("UOM").value = "BOX"
        lDtl.Post()
          
        #Insert Data - Detail - Reduce Stock Qty
        lDtl.Append()
        lDtl.FindField("DtlKey").value = -1
         lDtl.FindField("Seq").value = 1
        lDtl.FindField("ItemCode").value = "N-CHARGER"
        lDtl.FindField("Description").value = "NOKIA CHARGER"
        lDtl.FindField("Qty").value = -5
        lDtl.FindField("UOM").value = "UNIT"
        lDtl.Post()      
          
          
   
     try:
     try:
         BizObject.Save()           
         BizObject.Save()           
Line 1,500: Line 1,829:
         print("Oops!", e)     
         print("Oops!", e)     
     BizObject.Close()
     BizObject.Close()
     print ("Done")
     print ("Posting/Update Done")
 
def DelData():
    BizObject = ComServer.BizObjects.Find("SL_SO")
      
      
    lDocKey = BizObject.FindKeyByRef("DocNo", "--SO Test--")
       
    if lDocKey is None:
        print ("Record Not Found")
    else:
        BizObject.Params.Find("Dockey").Value = lDocKey
        BizObject.Open()
        BizObject.Delete()       
        print ("Deleting Done")
try:
try:
     CheckLogin()
     Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
    GetListData()
     PostData()
     PostData()
   
    answer = input("Continue To delete?")
    if answer.lower() in ["y","yes"]:
        DelData()
    elif answer.lower() in ["n","no"]:
        print ("Deleting Aborted")
    else:
      print ("Invalid Input")
     
    ComServer.Logout() 
finally:
finally:
    ComServer.Logout()
     ComServer = None
     ComServer = None
    Common.KillApp()
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Sales.PriceHistory.RO====
====Sales.PriceHistory.RO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Sales.PriceHistory.RO Script  
! Sales.PriceHistory.RO Script  
Line 1,614: Line 1,969:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Get Edited Sales Invoice List====
====Get Edited Sales Invoice List====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Get Edited Sales Invoice List Script  
! Get Edited Sales Invoice List Script  
Line 1,666: Line 2,021:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-SO to DO====
====SO to DO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Get Outstanding SO by SO Number transfer to DO Script  
! Get Outstanding SO by SO Number transfer to DO Script  
Line 1,766: Line 2,121:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Example-Stock Month End - Weighted Average====
====Stock Month End - Weighted Average====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Example-Stock Month End - Weighted Average Script  
! Stock Month End - Weighted Average Script  
|-
|-
|  
|  
Line 1,837: Line 2,192:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Example-Stock Month End - FIFO====
====Stock Month End - FIFO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Example-Stock Month End - FIFO Script  
! Stock Month End - FIFO Script  
|-
|-
|  
|  
<syntaxhighlight lang="Python">
<syntaxhighlight lang="Python">
#Updated 01 Dec 2021
#Updated 15 Feb 2022
import win32com.client
import win32com.client
import datetime
import datetime
Line 1,854: Line 2,209:
         ComServer.Logout()
         ComServer.Logout()
     ComServer.Login("FAUNG", "ADMIN", #UserName, Password
     ComServer.Login("FAUNG", "ADMIN", #UserName, Password
                     "D:\\Happy\\DB\\Default.DCF",
                     "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                  # "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                     "ACC-0011.FDB") #Database Name
                     "ACC-0011.FDB") #Database Name


def GetData():
def GetData():
     #Accuracy : 90% - Due to the figure is base on last run Costing in SQL Accounting
     #Accuracy : 90% - Due to the figure is base on last run Costing in SQL Accounting      
     lSQL = "SELECT A.ItemCode, A.Location, A.Batch, MAX(B.Seq) AS Seq, 1 AS CostingMethod "
 
     lSQL = lSQL + "FROM ST_TR A INNER JOIN ST_TR_FIFO B ON (A.TRANSNO=B.TRANSNO) "
     lSQL = "SELECT A.TRANSNO, A.ItemCode, A.Location, A.Batch, B.QTY, B.COST FROM ST_TR A "
     lSQL = lSQL + "WHERE A.PostDate<='31 Jul 2020' "
     lSQL = lSQL + "INNER JOIN ST_TR_FIFO B ON (A.TRANSNO=B.TRANSNO) "
     lSQL = lSQL + "AND A.ItemCode ='ANT' "
     lSQL = lSQL + "WHERE B.COSTTYPE='U' "
     lSQL = lSQL + "GROUP BY A.ItemCode, A.Location, A.Batch "
     lSQL = lSQL + "AND A.PostDate<='31 Jul 2022' "
      
     lSQL = lSQL + "AND A.ITEMCODE ='ANT' "
    lDataSet1 = ComServer.DBManager.NewDataSet(lSQL)
     lSQL = lSQL + "AND B.Qty<>0 "
    Seq = ""
    lSQL = lSQL + "AND EXISTS (SELECT MAX(D.Seq) FROM ST_TR C "
    if lDataSet1.RecordCount > 0:
    lSQL = lSQL + "           INNER JOIN ST_TR_FIFO D ON (C.TRANSNO=D.TRANSNO) "
        lDataSet1.First()
    lSQL = lSQL + "           WHERE C.PostDate<='31 Jul 2022' "
        while not lDataSet1.eof:
    lSQL = lSQL + "           AND C.ItemCode ='ANT' "
            Seq = Seq + lDataSet1.FindField("SEQ").AsString + ", "
    lSQL = lSQL + "           GROUP BY C.ItemCode, C.Location, C.Batch "
            lDataSet1.Next()
    lSQL = lSQL + "           HAVING B.SEQ=MAX(D.Seq) "
        Seq = Seq[:-2] #Delete last 2 character
    lSQL = lSQL + "           ) "
        #print(Seq)
    lSQL = lSQL + "ORDER BY A.ItemCode, A.Location, A.BATCH, A.TRANSNO "
       
    print(lSQL)
        if Seq != "": #not empty
    lDataSet2 = ComServer.DBManager.NewDataSet(lSQL)
            lSQL = "SELECT A.TRANSNO, A.ItemCode, A.Location, A.Batch, B.QTY, B.COST FROM ST_TR A "
            lSQL = lSQL + "INNER JOIN ST_TR_FIFO B ON (A.TRANSNO=B.TRANSNO) "
            lSQL = lSQL + "WHERE B.COSTTYPE='U' "
            lSQL = lSQL + "AND A.PostDate<='31 Jul 2020' "
            lSQL = lSQL + "AND B.SEQ IN (" + Seq + ")"
            lSQL = lSQL + " AND A.ITEMCODE ='ANT' "
            lSQL = lSQL + "AND B.Qty<>0 "
            lSQL = lSQL + "ORDER BY A.ItemCode, A.Location, A.BATCH, A.TRANSNO "
              
              
            lDataSet2 = ComServer.DBManager.NewDataSet(lSQL)
    if lDataSet2.RecordCount > 0: #Total Qty & Cost
           
        lDataSet2.First()
            if lDataSet2.RecordCount > 0: #Total Qty & Cost
        while not lDataSet2.eof:
                lDataSet2.First()
            print(" ")
                while not lDataSet2.eof:
            print("TRANSNO = "+lDataSet2.FindField("TRANSNO").AsString)
                    print(" ")
            print("ITEMCODE = "+lDataSet2.FindField("ITEMCODE").AsString)
                    print("TRANSNO = "+lDataSet2.FindField("TRANSNO").AsString)
            print("LOCATION = "+lDataSet2.FindField("LOCATION").AsString)
                    print("ITEMCODE = "+lDataSet2.FindField("ITEMCODE").AsString)
            print("BATCH = "+lDataSet2.FindField("BATCH").AsString)
                    print("LOCATION = "+lDataSet2.FindField("LOCATION").AsString)
            print("QTY = "+lDataSet2.FindField("QTY").AsString)
                    print("BATCH = "+lDataSet2.FindField("BATCH").AsString)
            print("COST = "+lDataSet2.FindField("COST").AsString)
                    print("QTY = "+lDataSet2.FindField("QTY").AsString)
            print("=====")
                    print("COST = "+lDataSet2.FindField("COST").AsString)
            print(" ")
                    print("=====")
            print("===Detail Cost===")
                    print(" ")
            lSQL = "SELECT TRANSNO, ITEMCODE, COSTSEQ, QTY, COST FROM ST_TR_FIFO "
                    print("===Detail Cost===")
            lSQL = lSQL + "WHERE ITEMCODE = '" + lDataSet2.FindField("ITEMCODE").AsString
                    lSQL = "SELECT TRANSNO, ITEMCODE, COSTSEQ, QTY, COST FROM ST_TR_FIFO "
            lSQL = lSQL + "' AND COSTTYPE='B' "
                    lSQL = lSQL + "WHERE ITEMCODE = '" + lDataSet2.FindField("ITEMCODE").AsString
            lSQL = lSQL + "AND TRANSNO="+lDataSet2.FindField("TRANSNO").AsString
                    lSQL = lSQL + "' AND COSTTYPE='B' "
            lSQL = lSQL + " ORDER BY COSTSEQ"
                    lSQL = lSQL + "AND TRANSNO="+lDataSet2.FindField("TRANSNO").AsString
                      
                    lSQL = lSQL + " ORDER BY COSTSEQ"
            lDataSet3 = ComServer.DBManager.NewDataSet(lSQL)
                      
                    lDataSet3 = ComServer.DBManager.NewDataSet(lSQL)


                    if lDataSet3.RecordCount > 0: #Detail Cost
            if lDataSet3.RecordCount > 0: #Detail Cost
                        lDataSet3.First()
                lDataSet3.First()
                        while not lDataSet3.eof:
                while not lDataSet3.eof:
                            print("TRANSNO = "+lDataSet3.FindField("TRANSNO").AsString)
                    print("TRANSNO = "+lDataSet3.FindField("TRANSNO").AsString)
                            print("ITEMCODE = "+lDataSet3.FindField("ITEMCODE").AsString)
                    print("ITEMCODE = "+lDataSet3.FindField("ITEMCODE").AsString)
                            print("COSTSEQ = "+lDataSet3.FindField("COSTSEQ").AsString)
                    print("COSTSEQ = "+lDataSet3.FindField("COSTSEQ").AsString)
                            print("QTY = "+lDataSet3.FindField("QTY").AsString)
                    print("QTY = "+lDataSet3.FindField("QTY").AsString)
                            print("COST = "+lDataSet3.FindField("COST").AsString)
                    print("COST = "+lDataSet3.FindField("COST").AsString)
                            print("D=====")
                    print("D=====")
                            lDataSet3.Next()
                    lDataSet3.Next()
                    lDataSet2.Next()
            lDataSet2.Next()
            else :
                print("Detail Record Not Found")   
     else :
     else :
         print ("Record Not Found")
         print("Detail Record Not Found")
               
try:
try:
     CheckLogin()
     CheckLogin()
Line 1,930: Line 2,273:
     print ("Done")
     print ("Done")
finally:
finally:
     ComServer.Logout()
     #ComServer.Logout()
     ComServer = None
     ComServer = None


</syntaxhighlight>
</syntaxhighlight>
Line 1,937: Line 2,281:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Example-Login 2 Database====
====Login 2 Database====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Example-Login 2 Database  
! Login 2 Database  
|-
|-
|  
|  
Line 2,004: Line 2,348:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Example-Get Stock Qty Balance====
====Get Stock Qty Balance====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Example-Get Stock Qty Balance  
! Get Stock Qty Balance  
|-
|-
|  
|  
<syntaxhighlight lang="Python">
<syntaxhighlight lang="Python">
#Updated 08 Jul 2022
#Updated 18 Jan 2024
import win32com.client
import Common
 
ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
 
def CheckLogin():
    B = ComServer.IsLogin
    if B == True:
        ComServer.Logout()
    ComServer.Login("ADMIN", "ADMIN", #UserName, Password
                    "C:\\eStream\\SQLAccounting\\Share\\Default.DCF",  #DCF file
                    "ACC-0081.FDB") #Database Name


def GetData():
def GetData():
Line 2,043: Line 2,377:
      
      
try:
try:
     CheckLogin()       
     Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer      
     GetData()
     GetData()
finally:
finally:
    ComServer.Logout()
     ComServer = None
     ComServer = None
    Common.KillApp()


</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>
<br>
===PHP===
: Add this in ..\xampp\php\php.ini
[PHP_COM_DOTNET]
extension=php_com_dotnet.dll


====Example-Get Agent====
====Maintain Asset Item====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Get Agent Script 
! Maintain Asset Item
|-
|-
|  
|  
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="Python">
<!DOCTYPE html>
#Updated 03 Oct 2023
<html>
import Common
<body>
import datetime
     
def GetListData():
    lSQL = "SELECT A.DOCNOEX, A.ACQUIREDATE, A.CODE, A.DESCRIPTION, A.ASSETGROUP, "
    lSQL = lSQL + "A.AGENT, A.AREA, A.COST, A.USEFULLIFE, A.DEPRRATE, A.RESIDUAL, "
    lSQL = lSQL + "B.POSTDATE, B.DESCRIPTION HISTORYDESC "
    lSQL = lSQL + "FROM FA_ITEM A "
    lSQL = lSQL + "INNER JOIN FA_ITEM_HISTORY B ON (A.Code=B.Code) "
    lSQL = lSQL + "WHERE A.STATUS=1 " #1 = Active 2 = InActive   
   
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
       
    Common.ShowResult(lDataSet)
 
def GetAutoKey(ACode):
    lSQL = "SELECT AUTOKEY FROM FA_ITEM "
    lSQL = lSQL + "WHERE Code= ' + Common.QuotedStr(ACode)
   
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
    return lDataSet.FindField("AutoKey").AsFloat
 
def PostData():
    BizObject = ComServer.BizObjects.Find("FA.Item.OPF")
    lMain = BizObject.DataSets.Find("Main") #lMain contains master data
    lProj = BizObject.DataSets.Find("Project") #lProj contains Project data
    lDepr = BizObject.DataSets.Find("DeprSche") #lDepr contains Depreciation Scheduler data
    lHist = BizObject.DataSets.Find("History") #lHist contains History data
   
    lDate = datetime.datetime(2023, 2, 22, 13, 0)
    lDate.strftime('%m/%d/%Y')
   
    lDocKey = GetAutoKey("--FA Test--")
       
    if lDocKey == 0:
        BizObject.New()
        lMain.FindField("Code").AsString = "--FA Test--"
        lMain.FindField("Description").AsString = "5ft Banquet Table"
        lMain.FindField("AcquireDate").value = lDate
        lMain.FindField("AssetGroup").AsString = "Default"
        lMain.FindField("Cost").AsFloat = 6190.50
        lMain.FindField("UsefulLife").AsFloat = 3
        lMain.FindField("Residual").AsFloat = 1
        lMain.FindField("DocNoEx").AsString = "IV-321578"
        lMain.FindField("Qty").AsFloat = 100


<h1>SQL Acc SDK in PHP page</h1>
        #Insert Data - Depreciation Schedule
        lDate = datetime.datetime(2024, 9, 3, 13, 0)
        lDate.strftime('%m/%d/%Y')
       
        lDepr.Append()
        lDepr.FindField("SCHEDATE").value      = lDate
        lDepr.FindField("Description").AsString = "Depreciation 1/3"
        lDepr.FindField("AMOUNT").AsFloat      = 2063.17
        lDepr.Post()


<?php
        lDate = datetime.datetime(2025, 9, 3, 13, 0)
echo "Updated 01 May 2020<br>";
        lDate.strftime('%m/%d/%Y')
       
        lDepr.Append()
        lDepr.FindField("SCHEDATE").value      = lDate
        lDepr.FindField("Description").AsString = "Depreciation 2/3"
        lDepr.FindField("AMOUNT").AsFloat      = 2063.17
        lDepr.Post()


$ComServer = null;
        lDate = datetime.datetime(2026, 9, 3, 13, 0)
        lDate.strftime('%m/%d/%Y')


function CheckLogin()
        lDepr.Append()
{
        lDepr.FindField("SCHEDATE").value      = lDate
    global $ComServer;
        lDepr.FindField("Description").AsString = "Depreciation 3/3"
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
        lDepr.FindField("AMOUNT").AsFloat      = 2063.16
    $status = $ComServer->IsLogin();
        lDepr.Post()      


    if ($status == true)
        #Insert Data - Hisory 
    {
        lDate = datetime.datetime(2023, 1, 20, 13, 0)
         $ComServer->Logout();
        lDate.strftime('%m/%d/%Y')
    }
       
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
        lHist.Append()
                      "C:\\eStream\\SQLAccounting\\Share\\Default.DCF",  #DCF file
        lHist.FindField("PostDate").value = lDate
                      "ACC-0082.FDB"); #Database Name
        lHist.FindField("Description").AsString = "Supplier ABC 4 Units"
      
        lHist.Post()
}
       
        lDate = datetime.datetime(2023, 2, 22, 13, 0)
        lDate.strftime('%m/%d/%Y')
       
         lHist.Append()
        lHist.FindField("PostDate").value = lDate
        lHist.FindField("Description").AsString = "Supplier XYZ Sdn Bhd 6 Units"
        lHist.Post()
       
        #Insert Data - Project
        lProj.Edit()
        lProj.FindField("Project").AsString = "KL"
        lProj.FindField("Rate").AsFloat = 40.00
        lProj.Post()
       
        lProj.Append()
        lProj.FindField("Project").AsString = "JB"
        lProj.FindField("Rate").AsFloat = 60.00
        lProj.Post()         
     else:
        BizObject.Params.Find("Autokey").AsString = lDocKey
        BizObject.Open()
        BizObject.Edit()
        lMain.Edit()
        lMain.FindField("Description").AsString = "Edited 5ft Banquet Tables"


function GetData()
        #Delete all Project
{
        while lProj.RecordCount != 0:
    global $ComServer;
            lProj.First()
            lProj.Delete()
           
        lProj.Append()
        lProj.FindField("Project").AsString = "----"
        lProj.FindField("Rate").AsFloat = 10.00
        lProj.Post()
       
        lProj.Append()
        lProj.FindField("Project").AsString = "KL"
        lProj.FindField("Rate").AsFloat = 40.00
        lProj.Post()


    $lSQL = "SELECT * FROM AGENT
        lProj.Append()
        WHERE CODE='HALIM'";
        lProj.FindField("Project").AsString = "JB"
        lProj.FindField("Rate").AsFloat = 50.00
        lProj.Post()     
       
        #Insert Data - Hisory 
        lDate = datetime.datetime(2023, 2, 10, 13, 0)
        lDate.strftime('%m/%d/%Y')
       
        lHist.Append()
        lHist.FindField("PostDate").value = lDate
        lHist.FindField("Description").AsString = "1 of table leg broken"
        lHist.Post()       
    try:
        BizObject.Save()         
    except Exception as e:
        print("Oops!", e)   
    BizObject.Close()
    print ("Posting/Update Done")


     $lDataSet = $ComServer->DBManager->NewDataSet($lSQL);
def DelData():
     BizObject = ComServer.BizObjects.Find("FA.Item.OPF")
   
    lDocKey = GetAutoKey("--FA Test--")
       
    if lDocKey == 0:
        print ("Record Not Found")
    else:
        BizObject.Params.Find("Autokey").AsString = lDocKey
        BizObject.Open()
        BizObject.Delete()       
        print ("Deleting Done")


     if ($lDataSet->RecordCount > 0)
try:
     {
    Common.CheckLogin()
        echo "Result : ";
    global ComServer
         echo $lDataSet->FindField('Description')->AsString() . "<br>";
    ComServer = Common.ComServer
    }
    GetListData()
     else
     PostData()
     {
      
        echo "Record Not Found";
    answer = input("Continue To delete?")
     }
    if answer.lower() in ["y","yes"]:
}
         DelData()
    elif answer.lower() in ["n","no"]:
        print ("Deleting Aborted")
     else:
      print ("Invalid Input")
     
     ComServer.Logout() 
finally:
    ComServer = None
     Common.KillApp()
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>


if (isset($_POST['BtnData']))
====Customer Payment====
{
{| class="mw-collapsible mw-collapsed wikitable"
     try
! AR_PM
     {
|-
        CheckLogin();
|
        GetData();
<syntaxhighlight lang="Python">
        echo date("d M Y h:i:s A") . " - Done";
#Updated 04 Dec 2023
     }
import Common
     finally
import datetime
     {
     
        $ComServer->Logout();
def GetListData():
        #free the object
    lSQL = "SELECT A.DOCNO, A.DOCDATE, A.CODE, B.COMPANYNAME, A.DESCRIPTION, A.DOCAMT, "
         $ComServer = null;
     lSQL = lSQL + "A.AGENT, A.AREA, A.PAYMENTMETHOD "
     }
     lSQL = lSQL + "FROM AR_PM A "
}
    lSQL = lSQL + "INNER JOIN AR_CUSTOMER B ON (A.CODE=B.CODE) "
    lSQL = lSQL + "WHERE A.CODE='300-A0002' "
     lSQL = lSQL + "AND A.CANCELLED='F' "
      
     lDataSet = ComServer.DBManager.NewDataSet(lSQL)
          
     Common.ShowResult(lDataSet)


?>
def PostData():
     <form method="post">         
     BizObject = ComServer.BizObjects.Find("AR_PM")
         <input type="submit" name="BtnData"
    lMain = BizObject.DataSets.Find("MainDataSet") #lMain contains master data
                value="Get Agent"/>
    lDetail = BizObject.DataSets.Find("cdsKnockOff") #lDetail contains detail data
    </form>
   
</body>
    lDate = datetime.datetime(2023, 2, 22, 13, 0)
</html>
    lDate.strftime('%m/%d/%Y')
</syntaxhighlight>
   
|}
    lDocKey = BizObject.FindKeyByRef("DocNo", "--PM Test--")
       
    if lDocKey is None:
        BizObject.New()
         lMain.FindField("DocNo").AsString = "--PM Test--"
        lMain.FindField("DocDate").value = lDate
        lMain.FindField("PostDate").value = lDate
        lMain.FindField("Code").AsString = "300-C0001" #Customer Account
        lMain.FindField("Description").AsString = "Payment for A/c"
        lMain.FindField("PaymentMethod").AsString = "325-000" #Bank or Cash Account
        lMain.FindField("ChequeNumber").AsString = ""
        lMain.FindField("BankCharge").AsFloat = 0
        lMain.FindField("DocAmt").AsFloat = 10000.00
        lMain.FindField("Cancelled").AsString = "F"   


<div style="float: right;">  [[#top|[top]]]</div>
        #Knock Off IV 
        V = ["IV", "--IV Test--"]  #DocType, DocNo
        if (lDetail.Locate("DocType;DocNo", V, False, False)) :
            lDetail.Edit()
            lDetail.FindField("KOAmt").AsFloat = 147.09 #Partial Knock off
            lDetail.FindField("KnockOff").AsString = "T"
            lDetail.Post()
    else:
        BizObject.Params.Find("Dockey").Value = lDocKey
        BizObject.Open()
        BizObject.Edit()
        lMain.Edit()
        lMain.FindField("Description").AsString = "Edited Payment for A/c 的第一 🐱"


====Example-Add & Edit Agent====
        #Knock Off IV 
{| class="mw-collapsible mw-collapsed wikitable"
        V = ["IV", "--IV Test--"]  #DocType, DocNo
! Add & Edit Agent Script   
        if (lDetail.Locate("DocType;DocNo", V, False, False)) :
|-
            lDetail.Edit()
|  
            lDetail.FindField("KOAmt").AsFloat = 200.09 #Partial Knock off
<syntaxhighlight lang="PHP">
            lDetail.FindField("KnockOff").AsString = "T"
<!DOCTYPE html>
            lDetail.Post()
<html>
       
<body>
    try:
        BizObject.Save()         
    except Exception as e:
        print("Oops!", e)   
    BizObject.Close()
    print ("Posting/Update Done")
 
def DelData():
    #Deleting only work if the record never not knock off by Refund
    BizObject = ComServer.BizObjects.Find("AR_PM")
   
    lDocKey = BizObject.FindKeyByRef("DocNo", "--PM Test--")
       
    if lDocKey is None:
        print ("Record Not Found")
    else:
        BizObject.Params.Find("Dockey").Value = lDocKey
        BizObject.Open()
        BizObject.Delete()       
        print ("Deleting Done")
 
try:
    Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
    GetListData()
    PostData()
   
    answer = input("Continue To delete?")
    if answer.lower() in ["y","yes"]:
        DelData()
    elif answer.lower() in ["n","no"]:
        print ("Deleting Aborted")
    else:
      print ("Invalid Input")
     
    ComServer.Logout() 
finally:
    ComServer = None
    Common.KillApp()
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>
<br>
 
===PHP===
* Tested PHP Version : 7.4.3/8.1.10
* Add this in ..\xampp\php\php.ini
<pre>
[PHP_COM_DOTNET]
extension=php_com_dotnet.dll
</pre>
 
* Grid.css file for example code
{| class="mw-collapsible mw-collapsed wikitable"
! Grid.css file
|-
|
<pre>
body
{
  margin: 10;
}
table {
  font-family: arial, sans-serif;
  border: 1px solid black;
  border-collapse: collapse;
  table-layout: auto;
}
 
td, th {
  border: 1px solid black;
  text-align: left;
  padding: 8px;
  white-space: nowrap;
}
 
tr:nth-child(even) {
  background-color: #dddddd;
}
</pre>
|}
 
====Get Agent====
{| class="mw-collapsible mw-collapsed wikitable"
! Get Agent Script   
|-
|  
<syntaxhighlight lang="PHP">
<!DOCTYPE html>
<html>
<body>


<h1>SQL Acc SDK in PHP page</h1>
<h1>SQL Acc SDK in PHP page</h1>
Line 2,173: Line 2,758:
}
}


function PostData(){
function GetData()
global $ComServer;
{
    global $ComServer;
     $BizObject = $ComServer->BizObjects->Find("Agent");
 
     $lMain = $BizObject->DataSets->Find("MainDataSet");
     $lSQL = "SELECT * FROM AGENT
   
        WHERE CODE='HALIM'";
     $lDocKey = $BizObject->FindKeyByRef("CODE", "FAIRY");
 
     $lDataSet = $ComServer->DBManager->NewDataSet($lSQL);
if ($lDocKey == null){
 
        $BizObject->New();
     if ($lDataSet->RecordCount > 0)
        $lMain->FindField("CODE")->value = "FAIRY";
    {
        $lMain->FindField("DESCRIPTION")->value = "FAIRY TAIL";
         echo "Result : ";
} else{
         echo $lDataSet->FindField('Description')->AsString() . "<br>";
         $BizObject->Params->Find("CODE")->Value = $lDocKey;
    }
        $BizObject->Open();
    else
         $BizObject->Edit();
    {
        $lMain->FindField("DESCRIPTION")->value = "FAIRY TAIL WIZARD";
        echo "Record Not Found";
}
    }
try{
$BizObject->Save();
echo "Posting Done <br>";
}catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}
}
}


Line 2,205: Line 2,783:
     {
     {
         CheckLogin();
         CheckLogin();
         PostData();
         GetData();
         echo date("d M Y h:i:s A") . " - Done";
         echo date("d M Y h:i:s A") . " - Done";
     }
     }
Line 2,219: Line 2,797:
     <form method="post">           
     <form method="post">           
         <input type="submit" name="BtnData"
         <input type="submit" name="BtnData"
                 value="Add/Edit Agent"/>  
                 value="Get Agent"/>  
     </form>  
     </form>  
</body>
</body>
Line 2,228: Line 2,806:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Delete Agent====
====Add & Edit Agent====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Delete Agent Script   
! Add & Edit Agent Script   
|-
|-
|  
|  
Line 2,270: Line 2,848:
if ($lDocKey == null){
if ($lDocKey == null){
         echo "Record Not Found";
         $BizObject->New();
        $lMain->FindField("CODE")->value = "FAIRY";
        $lMain->FindField("DESCRIPTION")->value = "FAIRY TAIL";
} else{
} else{
         $BizObject->Params->Find("CODE")->Value = $lDocKey;
         $BizObject->Params->Find("CODE")->Value = $lDocKey;
         $BizObject->Open();
         $BizObject->Open();
         $BizObject->Delete();
         $BizObject->Edit();
         echo "Delete Done<br>";
         $lMain->FindField("DESCRIPTION")->value = "FAIRY TAIL WIZARD";
}
}
try{
$BizObject->Save();
echo "Posting Done <br>";
}catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}
}
}


Line 2,298: Line 2,885:
     <form method="post">           
     <form method="post">           
         <input type="submit" name="BtnData"
         <input type="submit" name="BtnData"
                 value="Delete Agent"/>  
                 value="Add/Edit Agent"/>  
     </form>  
     </form>  
</body>
</body>
Line 2,307: Line 2,894:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Complete Post====
====Delete Agent====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! SL_CS, AR_PM, SL_CN & AR_CN Script  
! Delete Agent Script
|-
|-
|  
|  
Line 2,321: Line 2,908:
<?php
<?php
echo "Updated 01 May 2020<br>";
echo "Updated 01 May 2020<br>";
#This will doing following posting
#01. Cash Sales - SL_CS
#02. Sales Credit Note - SL_CN
#03. Customer Payment With Knock off - AR_PM
#04. Edit Credit Note Posted in Step 02 & Knock Off - AR_CN
#05. Customer Refund to Knock off Credit Note - AR_CF


$ComServer = null;
$ComServer = null;
Line 2,346: Line 2,927:
}
}


function PostDataCS(){
function PostData(){
global $ComServer;
global $ComServer;
$BizObject = $ComServer->BizObjects->Find("SL_CS");
    $BizObject = $ComServer->BizObjects->Find("Agent");
     $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
     $lMain = $BizObject->DataSets->Find("MainDataSet");
     $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
   
     $lDocKey = $BizObject->FindKeyByRef("CODE", "FAIRY");
    $BizObject->New();
if ($lDocKey == null){
    $lMain->FindField("DocKey")->value = -1;
        echo "Record Not Found";
    $lMain->FindField("DocNo")->AsString = "--CS Test--";
} else{
    $lMain->FindField("DocDate")->value = "04/20/2020"; #MM/DD/YYYY
        $BizObject->Params->Find("CODE")->Value = $lDocKey;
    $lMain->FindField("PostDate")->value = "04/20/2020"; #MM/DD/YYYY
        $BizObject->Open();
    $lMain->FindField("Code")->AsString = "300-C0001"; #Customer Account
        $BizObject->Delete();
    $lMain->FindField("CompanyName")->AsString = "Cash Sales";
        echo "Delete Done<br>";
    $lMain->FindField("Address1")->AsString = ""; #Optional
}
    $lMain->FindField("Address2")->AsString = ""; #Optional
}
    $lMain->FindField("Address3")->AsString = ""; #Optional
    $lMain->FindField("Address4")->AsString = ""; #Optional
    $lMain->FindField("Phone1")->AsString = "";  #Optional
    $lMain->FindField("Description")->AsString = "Sales";
    #Insert Data - Detail
    #For Tax Inclusive = True with override Tax Amount
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 1;
    $lDetail->FindField("Account")->AsString = "500-000"; #Sales Account
    $lDetail->FindField("Description")->AsString = "Sales Item A";
$txt = <<<EOT
          Item A Line 1
          Item A Line 2
          EOT;
    $lDetail->FindField("Description3")->AsString = $txt;
    $lDetail->FindField("Qty")->AsFloat = 1;
    $lDetail->FindField("Tax")->AsString = "SV";
    $lDetail->FindField("TaxRate")->AsString = "6%";
    $lDetail->FindField("TaxInclusive")->value = 0;
    $lDetail->FindField("UnitPrice")->AsFloat = 435;
    $lDetail->FindField("Amount")->AsFloat = 410.37; #Exclding GST Amt
    $lDetail->FindField("TaxAmt")->AsFloat = 24.63;


    $lDetail->DisableControls();
if (isset($_POST['BtnData']))
    $lDetail->FindField("TaxInclusive")->value = 1;
{
    $lDetail->EnableControls();   
     try
    $lDetail->Post();
     {
        CheckLogin();
     #For Tax Inclusive = False with override Tax Amount
        PostData();
     $lDetail->Append();
        echo date("d M Y h:i:s A") . " - Done";
    $lDetail->FindField("DtlKey")->value = -1;
     }
    $lDetail->FindField("DocKey")->value = -1;
     finally
    $lDetail->FindField("Seq")->value = 2;
     {
    $lDetail->FindField("Account")->AsString = "500-000";
        $ComServer->Logout();
    $lDetail->FindField("Description")->AsString = "Sales Item B";
        #free the object
    $lDetail->FindField("Qty")->AsFloat = 1;
        $ComServer = null;
    $lDetail->FindField("Tax")->AsString = "SV";
     }
    $lDetail->FindField("TaxRate")->AsString = "6%";
    $lDetail->FindField("TaxInclusive")->value = 0;
    $lDetail->FindField("UnitPrice")->AsFloat = 94.43;
    $lDetail->FindField("Amount")->AsFloat = 94.43;
    $lDetail->FindField("TaxAmt")->AsFloat = 5.66;
     $lDetail->Post();
     #For With Item Code
     $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 3;
    $lDetail->FindField("ItemCode")->AsString = "ANT";
    $lDetail->FindField("Description")->AsString = "Sales Item B";
    #$lDetail->FindField("Account")->AsString = "500-000"; #If you wanted override the Sales Account Code
    $lDetail->FindField("UOM")->AsString = "UNIT";
    $lDetail->FindField("Qty")->AsFloat = 2;
    #$lDetail->FindField("DISC")->AsString = "5%+3"; #Optional(eg 5% plus 3 Discount)
    $lDetail->FindField("Tax")->AsString = "SV";
    $lDetail->FindField("TaxRate")->AsString = "6%";
    $lDetail->FindField("TaxInclusive")->value = 0;
    $lDetail->FindField("UnitPrice")->AsFloat = 100;
    $lDetail->FindField("Amount")->AsFloat = 200;
    $lDetail->FindField("TaxAmt")->AsFloat = 12;
    $lDetail->Post();
     $BizObject->Save();
    $BizObject->Close();
}
}


function PostDataPM(){
?>
global $ComServer;
     <form method="post">          
        <input type="submit" name="BtnData"
     $BizObject = $ComServer->BizObjects->Find("AR_PM");
                value="Delete Agent"/>
    $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
     </form>  
    $lDetail = $BizObject->DataSets->Find("cdsKnockOff"); #lDetail contains detail data
</body>
</html>
     $BizObject->New();
</syntaxhighlight>
    $lMain->FindField("DOCKEY")->Value = -1;
|}
    $lMain->FindField("DocNo")->AsString = "--PM Test--";
 
    $lMain->FindField("CODE")->AsString = "300-C0001"; #Customer Account
<div style="float: right;">   [[#top|[top]]]</div>
    $lMain->FindField("DocDate")->Value = "04/23/2020"; #MM/DD/YYYY
 
    $lMain->FindField("PostDate")->Value = "04/23/2020"; #MM/DD/YYYY
====Complete Post====
    $lMain->FindField("Description")->AsString = "Payment for A/c";
{| class="mw-collapsible mw-collapsed wikitable"
    $lMain->FindField("PaymentMethod")->AsString = "320-000"; #Bank or Cash Account
! SL_CS, AR_PM, SL_CN & AR_CN Script
     $lMain->FindField("ChequeNumber")->AsString = "";
|-
     $lMain->FindField("BankCharge")->AsFloat = 0;
|
    $lMain->FindField("DocAmt")->AsFloat = 200.00;
<syntaxhighlight lang="PHP">
     $lMain->FindField("Cancelled")->AsString = "F";
<!DOCTYPE html>
<html>
<body>
 
<h1>SQL Acc SDK in PHP page</h1>
 
<?php
echo "Updated 01 May 2020<br>";
#This will doing following posting
#01. Cash Sales - SL_CS
#02. Sales Credit Note - SL_CN
#03. Customer Payment With Knock off - AR_PM
#04. Edit Credit Note Posted in Step 02 & Knock Off - AR_CN
#05. Customer Refund to Knock off Credit Note - AR_CF
 
$ComServer = null;
 
function CheckLogin()
{
     global $ComServer;
     $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
     $status = $ComServer->IsLogin();


     #Knock Off IV 
     if ($status == true)
     $V = array("IV", "--CS Test--"); #DocType, DocNo
    {
        $ComServer->Logout();
    }
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\\eStream\\SQLAccounting\\Share\\Default.DCF", #DCF file
                      "ACC-0082.FDB"); #Database Name
      
      
    if ($lDetail->Locate("DocType;DocNo", $V, False, False)) {
        $lDetail->Edit();
        $lDetail->FindField("KOAmt")->AsFloat = 147.09; #Partial Knock off
        $lDetail->FindField("KnockOff")->AsString = "T";
        $lDetail->Post();
}
    $BizObject->Save();
    $BizObject->Close();
}
}


function PostDataCN(){
function PostDataCS(){
global $ComServer;
global $ComServer;
$BizObject = $ComServer->BizObjects->Find("SL_CN");
$BizObject = $ComServer->BizObjects->Find("SL_CS");
     $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
     $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
     $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
     $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
Line 2,476: Line 3,021:
     $BizObject->New();
     $BizObject->New();
     $lMain->FindField("DocKey")->value = -1;
     $lMain->FindField("DocKey")->value = -1;
     $lMain->FindField("DocNo")->AsString = "--CN Test--";
     $lMain->FindField("DocNo")->AsString = "--CS Test--";
     $lMain->FindField("DocDate")->value = "04/23/2020"; #MM/DD/YYYY
     $lMain->FindField("DocDate")->value = "04/20/2020"; #MM/DD/YYYY
     $lMain->FindField("PostDate")->value = "04/23/2020"; #MM/DD/YYYY
     $lMain->FindField("PostDate")->value = "04/20/2020"; #MM/DD/YYYY
     $lMain->FindField("Code")->AsString = "300-C0001";
     $lMain->FindField("Code")->AsString = "300-C0001"; #Customer Account
     $lMain->FindField("CompanyName")->AsString = "Cash Sales";
     $lMain->FindField("CompanyName")->AsString = "Cash Sales";
     $lMain->FindField("Address1")->AsString = "";
     $lMain->FindField("Address1")->AsString = ""; #Optional
     $lMain->FindField("Address2")->AsString = "";
     $lMain->FindField("Address2")->AsString = ""; #Optional
     $lMain->FindField("Address3")->AsString = "";
     $lMain->FindField("Address3")->AsString = ""; #Optional
     $lMain->FindField("Address4")->AsString = "";
     $lMain->FindField("Address4")->AsString = ""; #Optional
     $lMain->FindField("Phone1")->AsString = "";
     $lMain->FindField("Phone1")->AsString = "";   #Optional
     $lMain->FindField("Description")->AsString = "Sales Returned";
     $lMain->FindField("Description")->AsString = "Sales";
    #Insert Data - Detail
    #For Tax Inclusive = True with override Tax Amount
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 1;
    $lDetail->FindField("Account")->AsString = "500-000"; #Sales Account
    $lDetail->FindField("Description")->AsString = "Sales Item A";
$txt = <<<EOT
          Item A Line 1
          Item A Line 2
          EOT;
    $lDetail->FindField("Description3")->AsString = $txt;
    $lDetail->FindField("Qty")->AsFloat = 1;
    $lDetail->FindField("Tax")->AsString = "SV";
    $lDetail->FindField("TaxRate")->AsString = "6%";
    $lDetail->FindField("TaxInclusive")->value = 0;
    $lDetail->FindField("UnitPrice")->AsFloat = 435;
    $lDetail->FindField("Amount")->AsFloat = 410.37; #Exclding GST Amt
    $lDetail->FindField("TaxAmt")->AsFloat = 24.63;
 
    $lDetail->DisableControls();
    $lDetail->FindField("TaxInclusive")->value = 1;
    $lDetail->EnableControls();   
    $lDetail->Post();
     #For With Item Code
     #For Tax Inclusive = False with override Tax Amount
     $lDetail->Append();
     $lDetail->Append();
     $lDetail->FindField("DtlKey")->value = -1;
     $lDetail->FindField("DtlKey")->value = -1;
     $lDetail->FindField("DocKey")->value = -1;
     $lDetail->FindField("DocKey")->value = -1;
     $lDetail->FindField("ItemCode")->AsString = "ANT";
     $lDetail->FindField("Seq")->value = 2;
    $lDetail->FindField("Account")->AsString = "500-000";
     $lDetail->FindField("Description")->AsString = "Sales Item B";
     $lDetail->FindField("Description")->AsString = "Sales Item B";
    $lDetail->FindField("Description2")->AsString = "Product Spoil"; #Reason
    $lDetail->FindField("Remark1")->AsString = "--CS Test--";  #Invoice No
    $lDetail->FindField("Remark2")->AsString = "20 Apr 2020";  #Invoice Date
     $lDetail->FindField("Qty")->AsFloat = 1;
     $lDetail->FindField("Qty")->AsFloat = 1;
     $lDetail->FindField("Tax")->AsString = "SV";
     $lDetail->FindField("Tax")->AsString = "SV";
     $lDetail->FindField("TaxRate")->AsString = "6%";
     $lDetail->FindField("TaxRate")->AsString = "6%";
     $lDetail->FindField("TaxInclusive")->value = 0;
     $lDetail->FindField("TaxInclusive")->value = 0;
     $lDetail->FindField("UnitPrice")->AsFloat = 100;
     $lDetail->FindField("UnitPrice")->AsFloat = 94.43;
     $lDetail->FindField("Amount")->AsFloat = 100;
     $lDetail->FindField("Amount")->AsFloat = 94.43;
     $lDetail->FindField("TaxAmt")->AsFloat = 6;
     $lDetail->FindField("TaxAmt")->AsFloat = 5.66;
     $lDetail->Post();
     $lDetail->Post();
     $BizObject->Save();
    #For With Item Code
     $BizObject->Close();
     $lDetail->Append();
}
     $lDetail->FindField("DtlKey")->value = -1;
 
    $lDetail->FindField("DocKey")->value = -1;
function PostKnockIVCN(){
    $lDetail->FindField("Seq")->value = 3;
global $ComServer;
    $lDetail->FindField("ItemCode")->AsString = "ANT";
    $lDetail->FindField("Description")->AsString = "Sales Item B";
    #$lDetail->FindField("Account")->AsString = "500-000"; #If you wanted override the Sales Account Code
    $lDetail->FindField("UOM")->AsString = "UNIT";
    $lDetail->FindField("Qty")->AsFloat = 2;
    #$lDetail->FindField("DISC")->AsString = "5%+3"; #Optional(eg 5% plus 3 Discount)
    $lDetail->FindField("Tax")->AsString = "SV";
    $lDetail->FindField("TaxRate")->AsString = "6%";
    $lDetail->FindField("TaxInclusive")->value = 0;
    $lDetail->FindField("UnitPrice")->AsFloat = 100;
    $lDetail->FindField("Amount")->AsFloat = 200;
    $lDetail->FindField("TaxAmt")->AsFloat = 12;
    $lDetail->Post();
     $BizObject = $ComServer->BizObjects->Find("AR_CN");
     $BizObject->Save();
    $lMain = $BizObject->DataSets->Find("MainDataSet");
     $BizObject->Close();
    $lDetail = $BizObject->DataSets->Find("cdsKnockOff");
    #Find CN Number
    $lDocNo = "--CN Test--";
    $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
     $BizObject->Params->Find("DocKey")->AsString = $lDocKey;
if ($lDocKey != null){
        $BizObject->Open();
        $BizObject->Edit();
        $lMain->Edit();
       
        #Knock Off IV       
        $V = array("IV", "--CS Test--");  #DocType, DocNo
       
        if ($lDetail->Locate("DocType;DocNo", $V, False, False)){
            $lDetail->Edit();
            $lDetail->FindField("KOAmt")->AsFloat = 100; #Partial Knock off
            $lDetail->FindField("KnockOff")->AsString = "T";
            $lDetail->Post();
}
        $BizObject->Save();
        $BizObject->Close();
}
}
}


function PostDataCF(){
function PostDataPM(){
global $ComServer;
global $ComServer;
     $BizObject = $ComServer->BizObjects->Find("AR_CF");
     $BizObject = $ComServer->BizObjects->Find("AR_PM");
     $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
     $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
     $lDetail = $BizObject->DataSets->Find("cdsKnockOff"); #lDetail contains detail data
     $lDetail = $BizObject->DataSets->Find("cdsKnockOff"); #lDetail contains detail data
Line 2,550: Line 3,109:
     $BizObject->New();
     $BizObject->New();
     $lMain->FindField("DOCKEY")->Value = -1;
     $lMain->FindField("DOCKEY")->Value = -1;
     $lMain->FindField("DocNo")->AsString = "--CF Test--";
     $lMain->FindField("DocNo")->AsString = "--PM Test--";
     $lMain->FindField("CODE")->AsString = "300-C0001"; #Customer Account
     $lMain->FindField("CODE")->AsString = "300-C0001"; #Customer Account
     $lMain->FindField("DocDate")->Value = "04/23/2020"; #MM/DD/YYYY
     $lMain->FindField("DocDate")->Value = "04/23/2020"; #MM/DD/YYYY
Line 2,558: Line 3,117:
     $lMain->FindField("ChequeNumber")->AsString = "";
     $lMain->FindField("ChequeNumber")->AsString = "";
     $lMain->FindField("BankCharge")->AsFloat = 0;
     $lMain->FindField("BankCharge")->AsFloat = 0;
     $lMain->FindField("DocAmt")->AsFloat = 6;
     $lMain->FindField("DocAmt")->AsFloat = 200.00;
     $lMain->FindField("Cancelled")->AsString = "F";
     $lMain->FindField("Cancelled")->AsString = "F";


     #Knock Off CN
     #Knock Off IV 
     $V = array("CN", "--CN Test--");  #DocType, DocNo
     $V = array("IV", "--CS Test--");  #DocType, DocNo
      
      
     if ($lDetail->Locate("DocType;DocNo", $V, False, False)) {
     if ($lDetail->Locate("DocType;DocNo", $V, False, False)) {
         $lDetail->Edit();
         $lDetail->Edit();
         $lDetail->FindField("KOAmt")->AsFloat = 4; #Partial Knock off
         $lDetail->FindField("KOAmt")->AsFloat = 147.09; #Partial Knock off
         $lDetail->FindField("KnockOff")->AsString = "T";
         $lDetail->FindField("KnockOff")->AsString = "T";
         $lDetail->Post();
         $lDetail->Post();
Line 2,574: Line 3,133:
}
}


if (isset($_POST['BtnData']))
function PostDataCN(){
{
global $ComServer;
     try
     {
$BizObject = $ComServer->BizObjects->Find("SL_CN");
        CheckLogin();
    $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
        echo date("d M Y h:i:s A")." - Posting Cash Sales<br>";
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
        PostDataCS();
        echo date("d M Y h:i:s A")." - Posting Customer Payment<br>";
    $BizObject->New();
        PostDataPM();
    $lMain->FindField("DocKey")->value = -1;
        echo date("d M Y h:i:s A")." - Posting Sales Credit Note<br>";
     $lMain->FindField("DocNo")->AsString = "--CN Test--";
        PostDataCN();
     $lMain->FindField("DocDate")->value = "04/23/2020"; #MM/DD/YYYY
        echo date("d M Y h:i:s A")." - Posting Knock Off Sales Credit Note<br>";
    $lMain->FindField("PostDate")->value = "04/23/2020"; #MM/DD/YYYY
        PostKnockIVCN();
    $lMain->FindField("Code")->AsString = "300-C0001";
        echo date("d M Y h:i:s A")." - Posting Customer Refund<br>";
    $lMain->FindField("CompanyName")->AsString = "Cash Sales";
        PostDataCF();
    $lMain->FindField("Address1")->AsString = "";
        echo date("d M Y h:i:s A")." - Posting Done";
    $lMain->FindField("Address2")->AsString = "";
     }
    $lMain->FindField("Address3")->AsString = "";
     finally
    $lMain->FindField("Address4")->AsString = "";
     {
    $lMain->FindField("Phone1")->AsString = "";
        $ComServer->Logout();
    $lMain->FindField("Description")->AsString = "Sales Returned";
        #free the object
        $ComServer = null;
    #For With Item Code
     }
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("ItemCode")->AsString = "ANT";
    $lDetail->FindField("Description")->AsString = "Sales Item B";
    $lDetail->FindField("Description2")->AsString = "Product Spoil"; #Reason
    $lDetail->FindField("Remark1")->AsString = "--CS Test--";   #Invoice No
    $lDetail->FindField("Remark2")->AsString = "20 Apr 2020";  #Invoice Date
    $lDetail->FindField("Qty")->AsFloat = 1;
    $lDetail->FindField("Tax")->AsString = "SV";
    $lDetail->FindField("TaxRate")->AsString = "6%";
    $lDetail->FindField("TaxInclusive")->value = 0;
     $lDetail->FindField("UnitPrice")->AsFloat = 100;
     $lDetail->FindField("Amount")->AsFloat = 100;
     $lDetail->FindField("TaxAmt")->AsFloat = 6;
    $lDetail->Post();
    $BizObject->Save();
     $BizObject->Close();
}
}


?>
function PostKnockIVCN(){
     <form method="post">          
global $ComServer;
        <input type="submit" name="BtnData"
                value="Complete Post"/>
     $BizObject = $ComServer->BizObjects->Find("AR_CN");
     </form>  
    $lMain = $BizObject->DataSets->Find("MainDataSet");
</body>
     $lDetail = $BizObject->DataSets->Find("cdsKnockOff");
</html>
</syntaxhighlight>
    #Find CN Number
|}
    $lDocNo = "--CN Test--";
 
    $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
<div style="float: right;">  [[#top|[top]]]</div>
    $BizObject->Params->Find("DocKey")->AsString = $lDocKey;
 
====Example-Get Invoice Next Number====
if ($lDocKey != null){
{| class="mw-collapsible mw-collapsed wikitable"
        $BizObject->Open();
! Get Invoice Next Number Script
        $BizObject->Edit();
|-
        $lMain->Edit();
|
       
<syntaxhighlight lang="PHP">
        #Knock Off IV       
<!DOCTYPE html>
        $V = array("IV", "--CS Test--"); #DocType, DocNo
<html>
       
<body>
        if ($lDetail->Locate("DocType;DocNo", $V, False, False)){
 
            $lDetail->Edit();
<h1>SQL Acc SDK in PHP page</h1>
            $lDetail->FindField("KOAmt")->AsFloat = 100; #Partial Knock off
 
            $lDetail->FindField("KnockOff")->AsString = "T";
<?php
            $lDetail->Post();
echo "Updated 01 May 2020<br>";
}
#This action to Get Next Number for Customer Invoice
         $BizObject->Save();
 
        $BizObject->Close();
$ComServer = null;
}
 
function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();
 
    if ($status == true)
    {
         $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\\eStream\\SQLAccounting\\Share\\Default.DCF",  #DCF file
                      "ACC-0082.FDB"); #Database Name
   
}
}


function GetData(){
function PostDataCF(){
global $ComServer;
global $ComServer;
     $lSQL = "SELECT A.*, B.NEXTNUMBER FROM SY_DOCNO A
     $BizObject = $ComServer->BizObjects->Find("AR_CF");
        INNER JOIN SY_DOCNO_DTL B ON (A.DOCKEY=B.PARENTKEY)
    $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
WHERE A.DOCTYPE='IV'
    $lDetail = $BizObject->DataSets->Find("cdsKnockOff"); #lDetail contains detail data
AND A.DESCRIPTION='Customer Invoice'
AND A.STATESET=1
";
$lDataSet = $ComServer->DBManager->NewDataSet($lSQL);
    $BizObject->New();
    $lMain->FindField("DOCKEY")->Value = -1;
    $lMain->FindField("DocNo")->AsString = "--CF Test--";
    $lMain->FindField("CODE")->AsString = "300-C0001"; #Customer Account
    $lMain->FindField("DocDate")->Value = "04/23/2020"; #MM/DD/YYYY
    $lMain->FindField("PostDate")->Value = "04/23/2020"; #MM/DD/YYYY
    $lMain->FindField("Description")->AsString = "Payment for A/c";
    $lMain->FindField("PaymentMethod")->AsString = "320-000"; #Bank or Cash Account
    $lMain->FindField("ChequeNumber")->AsString = "";
    $lMain->FindField("BankCharge")->AsFloat = 0;
    $lMain->FindField("DocAmt")->AsFloat = 6;
    $lMain->FindField("Cancelled")->AsString = "F";


     if ($lDataSet->RecordCount > 0) {
    #Knock Off CN
$lDataSet->First();
    $V = array("CN", "--CN Test--");  #DocType, DocNo
         $fmt = $lDataSet->FindField('Format')->AsString();
   
         $NextNo = $lDataSet->FindField('NEXTNUMBER')->AsFloat();
     if ($lDetail->Locate("DocType;DocNo", $V, False, False)) {
        $lDetail->Edit();
        echo date("d M Y h:i:s A")." Format in SQLAcc : " . str_ireplace("d","s", $fmt)."<br>";
         $lDetail->FindField("KOAmt")->AsFloat = 4; #Partial Knock off
        $fmt= str_ireplace(".","'0", $fmt);
         $lDetail->FindField("KnockOff")->AsString = "T";
         echo date("d M Y h:i:s A")." Format in PHP : " . str_ireplace("d","s", $fmt)."<br>";
         $lDetail->Post();
echo date("d M Y h:i:s A")." Output in PHP : " .sprintf($fmt,$NextNo)."<br>";
}
}else {
     $BizObject->Save();
     echo "Record Not Found";
     $BizObject->Close();
     }
}
}


Line 2,676: Line 3,245:
     {
     {
         CheckLogin();
         CheckLogin();
         GetData();
         echo date("d M Y h:i:s A")." - Posting Cash Sales<br>";
         echo date("d M Y h:i:s A")." - Done";
        PostDataCS();
        echo date("d M Y h:i:s A")." - Posting Customer Payment<br>";
        PostDataPM();
        echo date("d M Y h:i:s A")." - Posting Sales Credit Note<br>";
        PostDataCN();
        echo date("d M Y h:i:s A")." - Posting Knock Off Sales Credit Note<br>";
        PostKnockIVCN();
        echo date("d M Y h:i:s A")." - Posting Customer Refund<br>";
        PostDataCF();
         echo date("d M Y h:i:s A")." - Posting Done";
     }
     }
     finally
     finally
Line 2,690: Line 3,268:
     <form method="post">           
     <form method="post">           
         <input type="submit" name="BtnData"
         <input type="submit" name="BtnData"
                 value="Get Doc Number"/>  
                 value="Complete Post"/>  
     </form>  
     </form>  
</body>
</body>
Line 2,699: Line 3,277:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Add & Edit AR_Customer====
====Get Invoice Next Number====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Add & Edit AR_Customer Script  
! Get Invoice Next Number Script  
|-
|-
|  
|  
Line 2,712: Line 3,290:


<?php
<?php
echo "Updated 11 Jun 2020<br>";
echo "Updated 01 May 2020<br>";
#This action to Get Next Number for Customer Invoice


$ComServer = null;
$ComServer = null;
Line 2,727: Line 3,306:
     }
     }
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                       "C:\\eStream\\SQLAccounting\\Share\\Default.DCF", #DCF File
                       "C:\\eStream\\SQLAccounting\\Share\\Default.DCF", #DCF file
                       "ACC-0035.FDB"); #Database Name
                       "ACC-0082.FDB"); #Database Name
      
      
}
}


function PostData(){
function GetData(){
global $ComServer;
global $ComServer;
     $BizObject = $ComServer->BizObjects->Find("AR_Customer");
     $lSQL = "SELECT A.*, B.NEXTNUMBER FROM SY_DOCNO A
    $lMain = $BizObject->DataSets->Find("MainDataSet");
        INNER JOIN SY_DOCNO_DTL B ON (A.DOCKEY=B.PARENTKEY)
$lDtl  = $BizObject->DataSets->Find("cdsBranch");
WHERE A.DOCTYPE='IV'
   
AND A.DESCRIPTION='Customer Invoice'
    $lDocKey = $BizObject->FindKeyByRef("CODE", "FAIRY");
AND A.STATESET=1
";
if ($lDocKey == null){
$lDataSet = $ComServer->DBManager->NewDataSet($lSQL);
        $BizObject->New();
 
         $lMain->FindField("CODE")->value = "FAIRY";
    if ($lDataSet->RecordCount > 0) {
         $lMain->FindField("CompanyName")->value = "FAIRY TAIL";
$lDataSet->First();
         $fmt = $lDataSet->FindField('Format')->AsString();
         $NextNo = $lDataSet->FindField('NEXTNUMBER')->AsFloat();
         $lDtl->Edit(); #For 1St Branch
         echo date("d M Y h:i:s A")." Format in SQLAcc : " . str_ireplace("d","s", $fmt)."<br>";
        $lDtl->FindField("BranchName")->AsString  = "BILLING";
         $fmt= str_ireplace(".","'0", $fmt);
        $lDtl->FindField("Address1")->AsString    = "Address1";
         echo date("d M Y h:i:s A")." Format in PHP : " . str_ireplace("d","s", $fmt)."<br>";
         $lDtl->FindField("Address2")->AsString    = "Address2";
echo date("d M Y h:i:s A")." Output in PHP : " .sprintf($fmt,$NextNo)."<br>";
         $lDtl->FindField("Address3")->AsString    = "Address3";
}else {
        $lDtl->FindField("Address4")->AsString    = "Address4";
    echo "Record Not Found";
        $lDtl->FindField("Attention")->AsString  = "Attention";  
    }
        $lDtl->FindField("Phone1")->AsString      = "Phone1";
}
        $lDtl->FindField("Fax1")->AsString        = "Fax1";
        $lDtl->FindField("Email")->AsString      = "EmailAddress";
        $lDtl->Post();


        $lDtl->Append(); #For 2nd Branch
if (isset($_POST['BtnData']))
        $lDtl->FindField("BranchName")->AsString  = "Branch1";
{
        $lDtl->FindField("Address1")->AsString    = "DAddress1";
     try
        $lDtl->FindField("Address2")->AsString    = "DAddress2";
     {
        $lDtl->FindField("Address3")->AsString    = "DAddress3";
         CheckLogin();
        $lDtl->FindField("Address4")->AsString    = "DAddress4"; 
         GetData();
        $lDtl->FindField("Attention")->AsString  = "DAttention"; 
         echo date("d M Y h:i:s A")." - Done";
        $lDtl->FindField("Phone1")->AsString      = "DPhone1";
        $lDtl->FindField("Fax1")->AsString        = "DFax1";
        $lDtl->FindField("Email")->AsString      = "DEmailAddress";
        $lDtl->Post();
} else{
        $BizObject->Params->Find("CODE")->Value = $lDocKey;
        $BizObject->Open();
        $BizObject->Edit();
        $lMain->FindField("CompanyName")->value = "FAIRY TAIL WIZARD";
$r = $lDtl->RecordCount();
$x = 1;
while ($x <= $r ){
$lDtl->First();
            $lDtl->Delete();
$x++;
}
        #Insert back with new Information
        $lDtl->Edit(); #For 1St Branch
        $lDtl->FindField("BranchName")->AsString  = "BILLING"; #Make sure this always same as b4 delete data
        $lDtl->FindField("Address1")->AsString    = "New Address1";
        $lDtl->FindField("Address2")->AsString    = "New Address2";
        $lDtl->FindField("Address3")->AsString    = "New Address3";
        $lDtl->FindField("Address4")->AsString    = "New Address4"; 
        $lDtl->FindField("Attention")->AsString  = "New Attention"; 
        $lDtl->FindField("Phone1")->AsString      = "New Phone1";
        $lDtl->FindField("Fax1")->AsString        = "New Fax1";
        $lDtl->FindField("Email")->AsString      = "New EmailAddress";
        $lDtl->Post();
 
        $lDtl->Append(); #For 2nd Branch
        $lDtl->FindField("BranchName")->AsString  = "Branch1"; #Make sure this always same as b4 delete data
        $lDtl->FindField("Address1")->AsString    = "New DAddress1";
        $lDtl->FindField("Address2")->AsString    = "New DAddress2";
        $lDtl->FindField("Address3")->AsString    = "New DAddress3";
        $lDtl->FindField("Address4")->AsString    = "New DAddress4";
        $lDtl->FindField("Attention")->AsString  = "New DAttention"; 
        $lDtl->FindField("Phone1")->AsString      = "New DPhone1";
        $lDtl->FindField("Fax1")->AsString        = "New DFax1";
        $lDtl->FindField("Email")->AsString      = "New DEmailAddress";
        $lDtl->Post();
}
try{
$BizObject->Save();
echo "Posting Done <br>";
}catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}
}
 
if (isset($_POST['BtnData']))
{
     try
     {
         CheckLogin();
         PostData();
         echo date("d M Y h:i:s A") . " - Done";
     }
     }
     finally
     finally
Line 2,834: Line 3,353:
}
}


?>
?>  
     <form method="post">           
     <form method="post">           
         <input type="submit" name="BtnData"
         <input type="submit" name="BtnData"
                 value="Add/Edit AR Customer"/>  
                 value="Get Doc Number"/>  
     </form>  
     </form>  
</body>
</body>
</html>
</html>
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>
====Example-Get Stock List====
 
====Add & Edit AR_Customer====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Get Stock List Script  
! Add & Edit AR_Customer Script  
|-
|-
|  
|  
Line 2,853: Line 3,373:
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<html>
<head>
<body>
<link rel="stylesheet" type="text/css" href="css/Grid.css" />
</head>
<body>


<h1>SQL Acc SDK in PHP page</h1>
<h1>SQL Acc SDK in PHP page</h1>


<?php
<?php
echo "Updated 22 Jun 2020<br>";
echo "Updated 11 Jun 2020<br>";
#This action to Get Stock Item List


$ComServer = null;
$ComServer = null;
Line 2,877: Line 3,393:
     }
     }
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                       "C:\eStream\SQLAccounting\Share\Default.DCF", #DCF file
                       "C:\\eStream\\SQLAccounting\\Share\\Default.DCF", #DCF File
                       "ACC-0024.FDB"); #Database Name
                       "ACC-0035.FDB"); #Database Name
      
      
}
}


function GetData(){
function PostData(){
global $ComServer;
global $ComServer;
     $lSQL = "SELECT A.*, B.UOM, B.RATE, B.REFCOST, B.REFPRICE, B.ISBASE FROM ST_ITEM A
     $BizObject = $ComServer->BizObjects->Find("AR_Customer");
        INNER JOIN ST_ITEM_UOM B ON (A.CODE=B.CODE)  
    $lMain = $BizObject->DataSets->Find("MainDataSet");
WHERE A.ISACTIVE='T'
$lDtl  = $BizObject->DataSets->Find("cdsBranch");
";
   
    $lDocKey = $BizObject->FindKeyByRef("CODE", "FAIRY");
$lDataSet = $ComServer->DBManager->NewDataSet($lSQL);
if ($lDocKey == null){
 
        $BizObject->New();
    if ($lDataSet->RecordCount > 0) {
        $lMain->FindField("CODE")->value = "FAIRY";
$lDataSet->First();
        $lMain->FindField("CompanyName")->value = "FAIRY TAIL";
$fc = $lDataSet->Fields->Count-1;
echo "<table>";
echo "<tr>";
for ($x = 0; $x <= $fc; $x++) {
#Insert Header
echo "<td>".$lDataSet->Fields->Items($x)->FieldName()."</td>";
}
echo "</tr>";
#Looping Dataset
        $lDtl->Edit(); #For 1St Branch
while (! $lDataSet->Eof()){
        $lDtl->FindField("BranchName")->AsString  = "BILLING";
echo "<tr>";
        $lDtl->FindField("Address1")->AsString    = "Address1";
    for ($x = 0; $x <= $fc; $x++) {
        $lDtl->FindField("Address2")->AsString    = "Address2";
$lFN = $lDataSet->Fields->Items($x)->FieldName();
        $lDtl->FindField("Address3")->AsString    = "Address3";
    echo "<td>".$lDataSet->FindField($lFN)->AsString()."</td>";  
        $lDtl->FindField("Address4")->AsString    = "Address4";
    }
        $lDtl->FindField("Attention")->AsString  = "Attention";
    echo "</tr>";
        $lDtl->FindField("Phone1")->AsString      = "Phone1";
$lDataSet->Next();
        $lDtl->FindField("Fax1")->AsString        = "Fax1";
}
        $lDtl->FindField("Email")->AsString      = "EmailAddress";
echo "</table>"."<br>";
        $lDtl->Post();
}else {
 
     echo "Record Not Found";
        $lDtl->Append(); #For 2nd Branch
    }
        $lDtl->FindField("BranchName")->AsString  = "Branch1";
}
        $lDtl->FindField("Address1")->AsString    = "DAddress1";
        $lDtl->FindField("Address2")->AsString    = "DAddress2";
        $lDtl->FindField("Address3")->AsString    = "DAddress3";
        $lDtl->FindField("Address4")->AsString    = "DAddress4"; 
        $lDtl->FindField("Attention")->AsString  = "DAttention"; 
        $lDtl->FindField("Phone1")->AsString      = "DPhone1";
        $lDtl->FindField("Fax1")->AsString        = "DFax1";
        $lDtl->FindField("Email")->AsString      = "DEmailAddress";
        $lDtl->Post();
} else{
        $BizObject->Params->Find("CODE")->Value = $lDocKey;
        $BizObject->Open();
        $BizObject->Edit();
        $lMain->FindField("CompanyName")->value = "FAIRY TAIL WIZARD";
$r = $lDtl->RecordCount();
$x = 1;
while ($x <= $r ){
$lDtl->First();
            $lDtl->Delete();
$x++;
}
        #Insert back with new Information
        $lDtl->Edit(); #For 1St Branch
        $lDtl->FindField("BranchName")->AsString  = "BILLING"; #Make sure this always same as b4 delete data
        $lDtl->FindField("Address1")->AsString    = "New Address1";
        $lDtl->FindField("Address2")->AsString    = "New Address2";
        $lDtl->FindField("Address3")->AsString    = "New Address3";
        $lDtl->FindField("Address4")->AsString    = "New Address4"; 
        $lDtl->FindField("Attention")->AsString  = "New Attention"; 
        $lDtl->FindField("Phone1")->AsString      = "New Phone1";
        $lDtl->FindField("Fax1")->AsString        = "New Fax1";
        $lDtl->FindField("Email")->AsString      = "New EmailAddress";
        $lDtl->Post();
 
        $lDtl->Append(); #For 2nd Branch
        $lDtl->FindField("BranchName")->AsString  = "Branch1"; #Make sure this always same as b4 delete data
        $lDtl->FindField("Address1")->AsString    = "New DAddress1";
        $lDtl->FindField("Address2")->AsString    = "New DAddress2";
        $lDtl->FindField("Address3")->AsString    = "New DAddress3";
        $lDtl->FindField("Address4")->AsString   = "New DAddress4";
        $lDtl->FindField("Attention")->AsString  = "New DAttention"; 
        $lDtl->FindField("Phone1")->AsString      = "New DPhone1";
        $lDtl->FindField("Fax1")->AsString        = "New DFax1";
        $lDtl->FindField("Email")->AsString      = "New DEmailAddress";
        $lDtl->Post();
}
try{
$BizObject->Save();
echo "Posting Done <br>";
}catch (Exception $e) {
     echo 'Caught exception: ',  $e->getMessage(), "\n";
}
}


if (isset($_POST['BtnData']))
if (isset($_POST['BtnData']))
Line 2,924: Line 3,489:
     {
     {
         CheckLogin();
         CheckLogin();
         GetData();
         PostData();
         echo date("d M Y h:i:s A")." - Done";
         echo date("d M Y h:i:s A") . " - Done";
     }
     }
     finally
     finally
Line 2,935: Line 3,500:
}
}


?>  
?>
     <form method="post">           
     <form method="post">           
         <input type="submit" name="BtnData"
         <input type="submit" name="BtnData"
                 value="Get Stock list"/>  
                 value="Add/Edit AR Customer"/>  
     </form>  
     </form>  
</body>
</body>
</html>
</html>
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>
 
====Get Stock List====
====Example-AR_IV====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! AR_IV Script  
! Get Stock List Script  
|-
|-
|  
|  
Line 2,962: Line 3,527:


<?php
<?php
echo "Updated 24 Jun 2020<br>";
echo "Updated 22 Jun 2020<br>";
#This action to Post Customer Invoice
#This action to Get Stock Item List


$ComServer = null;
$ComServer = null;
Line 2,979: Line 3,544:
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                       "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                       "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                       "ACC-0070.FDB"); #Database Name
                       "ACC-0024.FDB"); #Database Name
      
      
}
}


function PostData(){
function GetData(){
global $ComServer;
global $ComServer;
$BizObject = $ComServer->BizObjects->Find("AR_IV");
    $lSQL = "SELECT A.*, B.UOM, B.RATE, B.REFCOST, B.REFPRICE, B.ISBASE FROM ST_ITEM A
    $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
        INNER JOIN ST_ITEM_UOM B ON (A.CODE=B.CODE)  
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
WHERE A.ISACTIVE='T'
";
    $BizObject->New();
$lDataSet = $ComServer->DBManager->NewDataSet($lSQL);
    $lMain->FindField("DocKey")->value = -1;
    $lMain->FindField("DocNo")->AsString = "--IV Test--";
    $lMain->FindField("DocDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("PostDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("Code")->AsString = "300-C0001"; #Customer Account
    $lMain->FindField("Description")->AsString = "Sales";
    #Insert Data - Detail
    #For Tax Inclusive = True with override Tax Amount
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 1;
    $lDetail->FindField("Account")->AsString = "500-000"; #Sales Account
    $lDetail->FindField("Description")->AsString = "Sales Item A";
    $lDetail->FindField("Tax")->AsString = "SV";
    $lDetail->FindField("TaxRate")->AsString = "6%";
    $lDetail->FindField("TaxInclusive")->value = 0;
    $lDetail->FindField("Amount")->AsFloat = 410.37; #Exclding GST Amt
    $lDetail->FindField("TaxAmt")->AsFloat = 24.63;


     $lDetail->DisableControls();
     if ($lDataSet->RecordCount > 0) {
    $lDetail->FindField("TaxInclusive")->value = 1;
$lDataSet->First();
    $lDetail->EnableControls();  
$fc = $lDataSet->Fields->Count-1;
    $lDetail->Post();
echo "<table>";
echo "<tr>";
    #For Tax Inclusive = False with override Tax Amount
for ($x = 0; $x <= $fc; $x++) {
    $lDetail->Append();
#Insert Header
    $lDetail->FindField("DtlKey")->value = -1;
echo "<td>".$lDataSet->Fields->Items($x)->FieldName()."</td>";
    $lDetail->FindField("DocKey")->value = -1;
}
    $lDetail->FindField("Seq")->value = 2;
echo "</tr>";
    $lDetail->FindField("Account")->AsString = "500-000";
    $lDetail->FindField("Description")->AsString = "Sales Item B";
#Looping Dataset
    $lDetail->FindField("Tax")->AsString = "SV";
while (! $lDataSet->Eof()){
    $lDetail->FindField("TaxRate")->AsString = "6%";
echo "<tr>";
    $lDetail->FindField("TaxInclusive")->value = 0;
    for ($x = 0; $x <= $fc; $x++) {
    $lDetail->FindField("Amount")->AsFloat = 94.43;
$lFN = $lDataSet->Fields->Items($x)->FieldName();
    $lDetail->FindField("TaxAmt")->AsFloat = 5.66;
    echo "<td>".$lDataSet->FindField($lFN)->AsString()."</td>";  
    $lDetail->Post();
    }
    echo "</tr>";
     $BizObject->Save();
$lDataSet->Next();
     $BizObject->Close();
}
echo "</table>"."<br>";
}else {
     echo "Record Not Found";
     }
}
}


Line 3,040: Line 3,590:
     {
     {
         CheckLogin();
         CheckLogin();
PostData();
        GetData();
         echo date("d M Y h:i:s A")." - Done";
         echo date("d M Y h:i:s A")." - Done";
     }
     }
Line 3,054: Line 3,604:
     <form method="post">           
     <form method="post">           
         <input type="submit" name="BtnData"
         <input type="submit" name="BtnData"
                 value="Post Customer Invoice"/>  
                 value="Get Stock list"/>  
     </form>  
     </form>  
</body>
</body>
Line 3,062: Line 3,612:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Get Outstanding Invoice List====
====AR_IV====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Get Outstanding Invoice List Script  
! AR_IV Script  
|-
|-
|  
|  
Line 3,079: Line 3,629:
<?php
<?php
echo "Updated 24 Jun 2020<br>";
echo "Updated 24 Jun 2020<br>";
#This action to Get Outstanding Invoice List
#This action to Post Customer Invoice


$ComServer = null;
$ComServer = null;
Line 3,095: Line 3,645:
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                       "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                       "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                       "ACC-0024.FDB"); #Database Name
                       "ACC-0070.FDB"); #Database Name
      
      
}
}


function GetData(){
function PostData(){
global $ComServer;
global $ComServer;
     $lSQL = "SELECT A.*, B.COMPANYNAME, (A.DOCAMT-A.PAYMENTAMT) OUTSTANDING  FROM AR_IV A
$BizObject = $ComServer->BizObjects->Find("AR_IV");
        INNER JOIN AR_CUSTOMER B ON (A.CODE=B.CODE)  
     $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
WHERE (A.DOCAMT-A.PAYMENTAMT)<>0
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
AND CANCELLED='F'
";
    $BizObject->New();
    $lMain->FindField("DocKey")->value = -1;
    $lMain->FindField("DocNo")->AsString = "--IV Test--";
    $lMain->FindField("DocDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("PostDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("Code")->AsString = "300-C0001"; #Customer Account
    $lMain->FindField("Description")->AsString = "Sales";
$lDataSet = $ComServer->DBManager->NewDataSet($lSQL);
    #Insert Data - Detail
    #For Tax Inclusive = True with override Tax Amount
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 1;
    $lDetail->FindField("Account")->AsString = "500-000"; #Sales Account
    $lDetail->FindField("Description")->AsString = "Sales Item A";
    $lDetail->FindField("Tax")->AsString = "SV";
    $lDetail->FindField("TaxRate")->AsString = "6%";
    $lDetail->FindField("TaxInclusive")->value = 0;
    $lDetail->FindField("Amount")->AsFloat = 410.37; #Exclding GST Amt
    $lDetail->FindField("TaxAmt")->AsFloat = 24.63;


     if ($lDataSet->RecordCount > 0) {
     $lDetail->DisableControls();
$lDataSet->First();
    $lDetail->FindField("TaxInclusive")->value = 1;
$fc = $lDataSet->Fields->Count-1;
    $lDetail->EnableControls();   
echo "<table>";
    $lDetail->Post();
echo "<tr>";
for ($x = 0; $x <= $fc; $x++) {
    #For Tax Inclusive = False with override Tax Amount
#Insert Header
    $lDetail->Append();
echo "<td>".$lDataSet->Fields->Items($x)->FieldName()."</td>";  
    $lDetail->FindField("DtlKey")->value = -1;
}
    $lDetail->FindField("DocKey")->value = -1;
echo "</tr>";
    $lDetail->FindField("Seq")->value = 2;
    $lDetail->FindField("Account")->AsString = "500-000";
#Looping Dataset
    $lDetail->FindField("Description")->AsString = "Sales Item B";
while (! $lDataSet->Eof()){
    $lDetail->FindField("Tax")->AsString = "SV";
echo "<tr>";
    $lDetail->FindField("TaxRate")->AsString = "6%";
    for ($x = 0; $x <= $fc; $x++) {
    $lDetail->FindField("TaxInclusive")->value = 0;
$lFN = $lDataSet->Fields->Items($x)->FieldName();
    $lDetail->FindField("Amount")->AsFloat = 94.43;
    echo "<td>".$lDataSet->FindField($lFN)->AsString()."</td>";  
    $lDetail->FindField("TaxAmt")->AsFloat = 5.66;
    }
    $lDetail->Post();
    echo "</tr>";
$lDataSet->Next();
    $BizObject->Save();
}
     $BizObject->Close();
echo "</table>"."<br>";
}else {
     echo "Record Not Found";
    }
}
}


Line 3,142: Line 3,706:
     {
     {
         CheckLogin();
         CheckLogin();
        GetData();
PostData();
         echo date("d M Y h:i:s A")." - Done";
         echo date("d M Y h:i:s A")." - Done";
     }
     }
Line 3,156: Line 3,720:
     <form method="post">           
     <form method="post">           
         <input type="submit" name="BtnData"
         <input type="submit" name="BtnData"
                 value="Get Outstanding Invoice List"/>  
                 value="Post Customer Invoice"/>  
     </form>  
     </form>  
</body>
</body>
Line 3,164: Line 3,728:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Stock Month End - Weighted Average====
====Get Outstanding Invoice List====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Stock Month End - Weighted Average Script  
! Get Outstanding Invoice List Script  
|-
|-
|  
|  
Line 3,180: Line 3,744:


<?php
<?php
echo "Updated 01 Dec 2021<br>";
echo "Updated 24 Jun 2020<br>";
 
#This action to Get Outstanding Invoice List


$ComServer = null;
$ComServer = null;
Line 3,202: Line 3,766:


function GetData(){
function GetData(){
#Accuracy : 90% - Due to the figure is base on last run Costing in SQL Accounting
global $ComServer;
global $ComServer;
     $lSQL = "SELECT A.ItemCode, A.Location, A.Batch,  MAX(B.Seq) AS Seq, 2 AS CostingMethod
     $lSQL = "SELECT A.*, B.COMPANYNAME, (A.DOCAMT-A.PAYMENTAMT) OUTSTANDING  FROM AR_IV A
        FROM ST_TR A INNER JOIN ST_TR_WMA B ON (A.TRANSNO=B.TRANSNO)  
        INNER JOIN AR_CUSTOMER B ON (A.CODE=B.CODE)  
WHERE A.PostDate<='31 Jul 2020'
WHERE (A.DOCAMT-A.PAYMENTAMT)<>0
AND A.ITEMCODE='Adj_Voucher'
AND CANCELLED='F'
GROUP BY A.ItemCode, A.Location, A.Batch
";
";
$lDataSet1 = $ComServer->DBManager->NewDataSet($lSQL);
$lDataSet = $ComServer->DBManager->NewDataSet($lSQL);
$Seq = "";
$lDataSet1->First();
while (! $lDataSet1->Eof()){
$Seq = $Seq.$lDataSet1->FindField("SEQ")->AsString .",";
$lDataSet1->Next();
}


    $lSQL = "SELECT A.TRANSNO, A.ItemCode, A.Location, A.Batch, B.UTDQty, B.UTDCost FROM ST_TR A
     if ($lDataSet->RecordCount > 0) {
        INNER JOIN ST_TR_WMA B ON (A.TRANSNO=B.TRANSNO)
$lDataSet->First();
WHERE A.PostDate<='31 Jul 2020'
$fc = $lDataSet->Fields->Count-1;
AND A.ITEMCODE='Adj_Voucher'
AND B.SEQ IN (".substr_replace($Seq ,"",-1).")
AND B.UTDQty<>0
ORDER BY A.ItemCode, A.Location, A.Batch
";
$lDataSet2 = $ComServer->DBManager->NewDataSet($lSQL);
     if ($lDataSet2->RecordCount > 0) {
$lDataSet2->First();
$fc = $lDataSet2->Fields->Count-1;
echo "<table>";
echo "<table>";
echo "<tr>";
echo "<tr>";
for ($x = 0; $x <= $fc; $x++) {
for ($x = 0; $x <= $fc; $x++) {
#Insert Header
#Insert Header
echo "<td>".$lDataSet2->Fields->Items($x)->FieldName()."</td>";  
echo "<td>".$lDataSet->Fields->Items($x)->FieldName()."</td>";  
}
}
echo "</tr>";
echo "</tr>";
#Looping Dataset
#Looping Dataset
while (! $lDataSet2->Eof()){
while (! $lDataSet->Eof()){
echo "<tr>";
echo "<tr>";
    for ($x = 0; $x <= $fc; $x++) {
    for ($x = 0; $x <= $fc; $x++) {
$lFN = $lDataSet2->Fields->Items($x)->FieldName();
$lFN = $lDataSet->Fields->Items($x)->FieldName();
    echo "<td>".$lDataSet2->FindField($lFN)->AsString()."</td>";  
    echo "<td>".$lDataSet->FindField($lFN)->AsString()."</td>";  
    }
    }
    echo "</tr>";
    echo "</tr>";
$lDataSet2->Next();
$lDataSet->Next();
}
}
echo "</table>"."<br>";
echo "</table>"."<br>";
Line 3,278: Line 3,822:
     <form method="post">           
     <form method="post">           
         <input type="submit" name="BtnData"
         <input type="submit" name="BtnData"
                 value="Month End - WA"/>  
                 value="Get Outstanding Invoice List"/>  
     </form>  
     </form>  
</body>
</body>
Line 3,286: Line 3,830:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Stock Month End - FIFO====
====Stock Month End - Weighted Average====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Stock Month End - FIFO Script  
! Stock Month End - Weighted Average Script  
|-
|-
|  
|  
Line 3,302: Line 3,846:


<?php
<?php
echo "Updated 16 Jul 2020<br>";
echo "Updated 01 Dec 2021<br>";
#This action to Get Outstanding Invoice List
 


$ComServer = null;
$ComServer = null;
Line 3,327: Line 3,871:
global $ComServer;
global $ComServer;
     $lSQL = "SELECT A.ItemCode, A.Location, A.Batch, MAX(B.Seq) AS Seq, 1 AS CostingMethod  
     $lSQL = "SELECT A.ItemCode, A.Location, A.Batch, MAX(B.Seq) AS Seq, 2 AS CostingMethod
        FROM ST_TR A INNER JOIN ST_TR_FIFO B ON (A.TRANSNO=B.TRANSNO)  
        FROM ST_TR A INNER JOIN ST_TR_WMA B ON (A.TRANSNO=B.TRANSNO)  
WHERE A.PostDate<='31 Jul 2020'
WHERE A.PostDate<='31 Jul 2020'
AND A.ItemCode IN ('ANT', 'COVER', 'BOM')
AND A.ITEMCODE='Adj_Voucher'
GROUP BY A.ItemCode, A.Location, A.Batch
GROUP BY A.ItemCode, A.Location, A.Batch
";
";
Line 3,343: Line 3,887:
}
}


     $lSQL = "SELECT A.TRANSNO, A.ItemCode, A.Location, A.Batch, B.QTY, B.COST FROM ST_TR A  
     $lSQL = "SELECT A.TRANSNO, A.ItemCode, A.Location, A.Batch, B.UTDQty, B.UTDCost FROM ST_TR A
        INNER JOIN ST_TR_FIFO B ON (A.TRANSNO=B.TRANSNO)  
        INNER JOIN ST_TR_WMA B ON (A.TRANSNO=B.TRANSNO)  
WHERE B.COSTTYPE='U'  
WHERE A.PostDate<='31 Jul 2020'
AND A.PostDate<='31 Jul 2020'
AND A.ITEMCODE='Adj_Voucher'
AND B.SEQ IN (".substr_replace($Seq ,"",-1).")  
AND B.SEQ IN (".substr_replace($Seq ,"",-1).")  
AND A.ItemCode IN ('ANT1.0', 'COVER', 'BOM')
AND B.UTDQty<>0  
AND B.Qty<>0  
ORDER BY A.ItemCode, A.Location, A.Batch
ORDER BY A.ItemCode, A.Location, A.Batch
";
";
$lDataSet2 = $ComServer->DBManager->NewDataSet($lSQL);  
$lDataSet2 = $ComServer->DBManager->NewDataSet($lSQL);  
 
 
Line 3,380: Line 3,923:
     echo "Record Not Found";
     echo "Record Not Found";
     }
     }
}
#FIFO Detail Key to link with $lDataSet2 & $lDataSet3 is TRANSNO
$Seq = "";
$lDataSet2->First();
while (! $lDataSet2->Eof()){
$Seq = $Seq.$lDataSet2->FindField("TRANSNO")->AsString .",";
$lDataSet2->Next();
}
 
    $lSQL = "SELECT  TransNo, Cost, SUM(Qty) AS Qty, MIN(CostSeq) AS Seq FROM ST_TR_FIFO
        WHERE CostType='B'
AND TRANSNO IN (".substr_replace($Seq ,"",-1).")
GROUP BY TransNo, Cost
";
$lDataSet3 = $ComServer->DBManager->NewDataSet($lSQL);
 
    if ($lDataSet3->RecordCount > 0) {
$lDataSet3->First();
$fc = $lDataSet3->Fields->Count-1;
echo "<table>";
echo "<tr>";
for ($x = 0; $x <= $fc; $x++) {
#Insert Header
echo "<td>".$lDataSet3->Fields->Items($x)->FieldName()."</td>";
}
echo "</tr>";
#Looping Dataset
while (! $lDataSet3->Eof()){
echo "<tr>";
    for ($x = 0; $x <= $fc; $x++) {
$lFN = $lDataSet3->Fields->Items($x)->FieldName();
    echo "<td>".$lDataSet3->FindField($lFN)->AsString()."</td>";
    }
    echo "</tr>";
$lDataSet3->Next();
}
echo "</table>"."<br>";
}else {
    echo "Record Not Found";
    }
}


if (isset($_POST['BtnData']))
if (isset($_POST['BtnData']))
Line 3,434: Line 3,935:
     finally
     finally
     {
     {
         #$ComServer->Logout();
         $ComServer->Logout();
         #free the object
         #free the object
         $ComServer = null;
         $ComServer = null;
Line 3,443: Line 3,944:
     <form method="post">           
     <form method="post">           
         <input type="submit" name="BtnData"
         <input type="submit" name="BtnData"
                 value="Month End - FIFO"/>  
                 value="Month End - WA"/>  
     </form>  
     </form>  
</body>
</body>
Line 3,451: Line 3,952:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Add & Edit Stock Item====
====Stock Month End - FIFO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Add & Edit Stock Item Script  
! Stock Month End - FIFO Script  
|-
|-
|  
|  
Line 3,459: Line 3,960:
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/Grid.css" />
</head>
<body>
<body>


Line 3,464: Line 3,968:


<?php
<?php
echo "Updated 05 Aug 2020<br>";
echo "Updated 16 Jul 2020<br>";
#This action to Get Outstanding Invoice List
 
$ComServer = null;
$ComServer = null;


Line 3,483: Line 3,989:
}
}


function PostData(){
function GetData(){
#Accuracy : 90% - Due to the figure is base on last run Costing in SQL Accounting
global $ComServer;
global $ComServer;
$BizObject = $ComServer->BizObjects->Find("ST_ITEM");
    $lSQL = "SELECT  A.ItemCode, A.Location, A.Batch, MAX(B.Seq) AS Seq, 1 AS CostingMethod
    $lMain = $BizObject->DataSets->Find("MainDataSet");
        FROM ST_TR A INNER JOIN ST_TR_FIFO B ON (A.TRANSNO=B.TRANSNO)  
    $lUOM  = $BizObject->DataSets->Find("cdsUOM");  
WHERE A.PostDate<='31 Jul 2020'
$lBarcode = $BizObject->DataSets->Find("cdsBarcode");  
AND A.ItemCode IN ('ANT', 'COVER', 'BOM')
GROUP BY A.ItemCode, A.Location, A.Batch
";
$lDataSet1 = $ComServer->DBManager->NewDataSet($lSQL);
$lDocKey = $BizObject->FindKeyByRef("CODE", "FAIRY-PHP");
$Seq = "";
$lDataSet1->First();
while (! $lDataSet1->Eof()){
$Seq = $Seq.$lDataSet1->FindField("SEQ")->AsString .",";
$lDataSet1->Next();
}


if ($lDocKey == null){
    $lSQL = "SELECT A.TRANSNO, A.ItemCode, A.Location, A.Batch, B.QTY, B.COST FROM ST_TR A
        $BizObject->New();
        INNER JOIN ST_TR_FIFO B ON (A.TRANSNO=B.TRANSNO)  
        $lMain->FindField("CODE")->AsString = "FAIRY-PHP";
WHERE B.COSTTYPE='U'
        $lMain->FindField("DESCRIPTION")->AsString = "FAIRY TAIL";
AND A.PostDate<='31 Jul 2020'
        $lMain->FindField("STOCKGROUP")->AsString = "DEFAULT";
AND B.SEQ IN (".substr_replace($Seq ,"",-1).")  
        $lMain->FindField("STOCKCONTROL")->AsString = "T";
AND A.ItemCode IN ('ANT1.0', 'COVER', 'BOM')
        $lMain->FindField("ISACTIVE")->AsString = "T";
AND B.Qty<>0
 
ORDER BY A.ItemCode, A.Location, A.Batch
        $lUOM->Edit(); #For 1St UOM
";
        $lUOM->FindField("UOM")->AsString = "PCS";
        $lUOM->FindField("Rate")->AsFloat = 1;
$lDataSet2 = $ComServer->DBManager->NewDataSet($lSQL);
        $lUOM->FindField("RefCost")->AsFloat = 10.2;
        $lUOM->FindField("RefPrice")->AsFloat = 25;
    if ($lDataSet2->RecordCount > 0) {
        $lUOM->Post();
$lDataSet2->First();
 
$fc = $lDataSet2->Fields->Count-1;
        $lUOM->Append(); #For 2nd UOM
echo "<table>";
        $lUOM->FindField("UOM")->AsString = "CTN";
echo "<tr>";
        $lUOM->FindField("Rate")->AsFloat = 12;
for ($x = 0; $x <= $fc; $x++) {
        $lUOM->FindField("RefCost")->AsFloat = 102;
#Insert Header
        $lUOM->FindField("RefPrice")->AsFloat = 240;
echo "<td>".$lDataSet2->Fields->Items($x)->FieldName()."</td>";  
        $lUOM->Post();
}
 
echo "</tr>";
        $lBarcode->Append(); #For 1st UOM Barcode
        $lBarcode->FindField("BARCODE")->AsString = "123456789";
$lBarcode->FindField("UOM")->AsString = "PCS";
        $lBarcode->Post();
        $lBarcode->Append(); #For 2nd UOM Barcode
#Looping Dataset
        $lBarcode->FindField("BARCODE")->AsString = "987654321";
while (! $lDataSet2->Eof()){
$lBarcode->FindField("UOM")->AsString = "CTN";
echo "<tr>";
        $lBarcode->Post();
    for ($x = 0; $x <= $fc; $x++) {
} else{
$lFN = $lDataSet2->Fields->Items($x)->FieldName();
        $BizObject->Params->Find("Dockey")->AsString = $lDocKey;
    echo "<td>".$lDataSet2->FindField($lFN)->AsString()."</td>";
        $BizObject->Open();
    }
        $BizObject->Edit();
    echo "</tr>";
        $lMain->FindField("DESCRIPTION")->AsString = "FAIRY TAIL WIZARD";
$lDataSet2->Next();
}
$r = $lUOM->RecordCount();
echo "</table>"."<br>";
$x = 1;
}else {
while ($x <= $r ){
    echo "Record Not Found";
$lUOM->First();
    }
            $lUOM->Delete();
$x++;
#FIFO Detail Key to link with $lDataSet2 & $lDataSet3 is TRANSNO
$Seq = "";
$lDataSet2->First();
while (! $lDataSet2->Eof()){
$Seq = $Seq.$lDataSet2->FindField("TRANSNO")->AsString .",";
$lDataSet2->Next();
}
 
    $lSQL = "SELECT  TransNo, Cost, SUM(Qty) AS Qty, MIN(CostSeq) AS Seq FROM ST_TR_FIFO
        WHERE CostType='B'
AND TRANSNO IN (".substr_replace($Seq ,"",-1).")
GROUP BY TransNo, Cost
";
$lDataSet3 = $ComServer->DBManager->NewDataSet($lSQL);
 
    if ($lDataSet3->RecordCount > 0) {
$lDataSet3->First();
$fc = $lDataSet3->Fields->Count-1;
echo "<table>";
echo "<tr>";
for ($x = 0; $x <= $fc; $x++) {
#Insert Header
echo "<td>".$lDataSet3->Fields->Items($x)->FieldName()."</td>";  
}
}
echo "</tr>";
$r = $lBarcode->RecordCount();
#Looping Dataset
$x = 1;
while (! $lDataSet3->Eof()){
while ($x <= $r ){
echo "<tr>";
$lBarcode->First();
    for ($x = 0; $x <= $fc; $x++) {
            $lBarcode->Delete();
$lFN = $lDataSet3->Fields->Items($x)->FieldName();
$x++;
    echo "<td>".$lDataSet3->FindField($lFN)->AsString()."</td>";  
}
    }
    echo "</tr>";
        $lUOM->Append(); #For 1St UOM
$lDataSet3->Next();
        $lUOM->FindField("UOM")->AsString = "PCS"; #Make sure this always same as b4 delete data
}
        $lUOM->FindField("Rate")->AsFloat = 1; #Make sure this always same as b4 delete data
echo "</table>"."<br>";
        $lUOM->FindField("RefCost")->AsFloat = 22.3;
}else {
        $lUOM->FindField("RefPrice")->AsFloat = 52;
     echo "Record Not Found";
        $lUOM->Post();
 
        $lUOM->Append(); #For 2nd UOM
        $lUOM->FindField("UOM")->AsString = "CTN"; #Make sure this always same as b4 delete data
        $lUOM->FindField("Rate")->AsFloat = 12; #Make sure this always same as b4 delete data
        $lUOM->FindField("RefCost")->AsFloat = 102.5;
        $lUOM->FindField("RefPrice")->AsFloat = 260.45;
        $lUOM->Post();
        $lBarcode->Append(); #For 1st UOM Barcode
        $lBarcode->FindField("BARCODE")->AsString = "456321789";
$lBarcode->FindField("UOM")->AsString = "PCS";
        $lBarcode->Post();
        $lBarcode->Append(); #For 2nd UOM Barcode
        $lBarcode->FindField("BARCODE")->AsString = "321456987";
$lBarcode->FindField("UOM")->AsString = "CTN";
        $lBarcode->Post();
}
try{
        $BizObject->Save();
        $BizObject->Close();
}catch (Exception $e) {
     echo 'Caught exception: ',  $e->getMessage(), "\n";
     }
     }
}
}


if (isset($_POST['BtnData']))
if (isset($_POST['BtnData']))
Line 3,585: Line 4,095:
     {
     {
         CheckLogin();
         CheckLogin();
         echo date("d M Y h:i:s A")." - Begin Posting Stock Item<br>";
         GetData();
         PostData();
         echo date("d M Y h:i:s A")." - Done";
echo date("d M Y h:i:s A")." - Done<br>";
     }
     }
     finally
     finally
     {
     {
         $ComServer->Logout();
         #$ComServer->Logout();
         #free the object
         #free the object
         $ComServer = null;
         $ComServer = null;
Line 3,600: Line 4,109:
     <form method="post">           
     <form method="post">           
         <input type="submit" name="BtnData"
         <input type="submit" name="BtnData"
                 value="Add & Edit Stock Item"/>  
                 value="Month End - FIFO"/>  
     </form>  
     </form>  
</body>
</body>
Line 3,608: Line 4,117:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Add Stock Issue====
====Add & Edit Stock Item====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Add Stock Issue Script  
! Add & Edit Stock Item Script  
|-
|-
|  
|  
Line 3,621: Line 4,130:


<?php
<?php
echo "Updated 21 Oct 2020<br>";
echo "Updated 05 Aug 2020<br>";
$ComServer = null;
$ComServer = null;


Line 3,635: Line 4,144:
     }
     }
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                       "D:\Happy\DB\Default.DCF", #"C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                       "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                       "ACC-0024.FDB"); #Database Name
                       "ACC-0024.FDB"); #Database Name
   
}
function CheckLogin1()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
      
      
}
}
Line 3,650: Line 4,152:
global $ComServer;
global $ComServer;
$BizObject = $ComServer->BizObjects->Find("ST_IS");
$BizObject = $ComServer->BizObjects->Find("ST_ITEM");
     $lMain = $BizObject->DataSets->Find("MainDataSet");  
     $lMain = $BizObject->DataSets->Find("MainDataSet");  
     $lDetail = $BizObject->DataSets->Find("cdsDocDetail");  
     $lUOM  = $BizObject->DataSets->Find("cdsUOM");
$lBarcode = $BizObject->DataSets->Find("cdsBarcode");  
    $BizObject->New();
$lDocKey = $BizObject->FindKeyByRef("CODE", "FAIRY-PHP");
    $lMain->FindField("DocKey")->value = -1;
 
    $lMain->FindField("DocNo")->AsString = "--IS Test--";
if ($lDocKey == null){
    $lMain->FindField("DocDate")->value = "04/20/2020"; #MM/DD/YYYY
        $BizObject->New();
    $lMain->FindField("PostDate")->value = "04/20/2020"; #MM/DD/YYYY
        $lMain->FindField("CODE")->AsString = "FAIRY-PHP";
    $lMain->FindField("Description")->AsString = "Stock Issue";
        $lMain->FindField("DESCRIPTION")->AsString = "FAIRY TAIL";
        $lMain->FindField("STOCKGROUP")->AsString = "DEFAULT";
    #Insert Data - Detail
        $lMain->FindField("STOCKCONTROL")->AsString = "T";
    $lDetail->Append();
        $lMain->FindField("ISACTIVE")->AsString = "T";
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 1;
    $lDetail->FindField("ItemCode")->AsString = "ANT";
    $lDetail->FindField("Description")->AsString = "Sales Item B";
    $lDetail->FindField("Qty")->AsFloat = 2;
    $lDetail->FindField("UOM")->AsString = "BOX";
    $lDetail->Post();


    $lDetail->Append();
        $lUOM->Edit(); #For 1St UOM
    $lDetail->FindField("DtlKey")->value = -1;
        $lUOM->FindField("UOM")->AsString = "PCS";
    $lDetail->FindField("DocKey")->value = -1;
        $lUOM->FindField("Rate")->AsFloat = 1;
    $lDetail->FindField("Seq")->value = 2;
        $lUOM->FindField("RefCost")->AsFloat = 10.2;
    $lDetail->FindField("ItemCode")->AsString = "N-CHARGER";
        $lUOM->FindField("RefPrice")->AsFloat = 25;
    $lDetail->FindField("Description")->AsString = "NOKIA CHARGER";
        $lUOM->Post();
    $lDetail->FindField("Qty")->AsFloat = 5;
    $lDetail->FindField("UOM")->AsString = "UNIT";
    $lDetail->Post();
    $BizObject->Save();
    $BizObject->Close();
try{
        $BizObject->Save();
        $BizObject->Close();
}catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
    }
}


        $lUOM->Append(); #For 2nd UOM
        $lUOM->FindField("UOM")->AsString = "CTN";
        $lUOM->FindField("Rate")->AsFloat = 12;
        $lUOM->FindField("RefCost")->AsFloat = 102;
        $lUOM->FindField("RefPrice")->AsFloat = 240;
        $lUOM->Post();


if (isset($_POST['BtnData']))
        $lBarcode->Append(); #For 1st UOM Barcode
{
        $lBarcode->FindField("BARCODE")->AsString = "123456789";
    try
$lBarcode->FindField("UOM")->AsString = "PCS";
    {
        $lBarcode->Post();
         CheckLogin1();
         echo date("d M Y h:i:s A")." - Begin Posting<br>";
        $lBarcode->Append(); #For 2nd UOM Barcode
         PostData();
        $lBarcode->FindField("BARCODE")->AsString = "987654321";
echo date("d M Y h:i:s A")." - Done<br>";
$lBarcode->FindField("UOM")->AsString = "CTN";
    }
         $lBarcode->Post();
    finally
} else{
    {
         $BizObject->Params->Find("Dockey")->AsString = $lDocKey;
         $ComServer->Logout();
        $BizObject->Open();
         #free the object
         $BizObject->Edit();
         $ComServer = null;
        $lMain->FindField("DESCRIPTION")->AsString = "FAIRY TAIL WIZARD";
    }
}
$r = $lUOM->RecordCount();
$x = 1;
while ($x <= $r ){
$lUOM->First();
            $lUOM->Delete();
$x++;
}
$r = $lBarcode->RecordCount();
$x = 1;
while ($x <= $r ){
$lBarcode->First();
            $lBarcode->Delete();
$x++;
}
         $lUOM->Append(); #For 1St UOM
         $lUOM->FindField("UOM")->AsString = "PCS"; #Make sure this always same as b4 delete data
        $lUOM->FindField("Rate")->AsFloat = 1; #Make sure this always same as b4 delete data
         $lUOM->FindField("RefCost")->AsFloat = 22.3;
        $lUOM->FindField("RefPrice")->AsFloat = 52;
        $lUOM->Post();


?>  
        $lUOM->Append(); #For 2nd UOM
     <form method="post">           
        $lUOM->FindField("UOM")->AsString = "CTN"; #Make sure this always same as b4 delete data
         <input type="submit" name="BtnData"
        $lUOM->FindField("Rate")->AsFloat = 12; #Make sure this always same as b4 delete data
                 value="Add Stock Issue"/>  
        $lUOM->FindField("RefCost")->AsFloat = 102.5;
     </form>  
        $lUOM->FindField("RefPrice")->AsFloat = 260.45;
</body>
        $lUOM->Post();
</html>
</syntaxhighlight>
        $lBarcode->Append(); #For 1st UOM Barcode
|}
        $lBarcode->FindField("BARCODE")->AsString = "456321789";
$lBarcode->FindField("UOM")->AsString = "PCS";
        $lBarcode->Post();
        $lBarcode->Append(); #For 2nd UOM Barcode
        $lBarcode->FindField("BARCODE")->AsString = "321456987";
$lBarcode->FindField("UOM")->AsString = "CTN";
        $lBarcode->Post();
}
try{
        $BizObject->Save();
        $BizObject->Close();
}catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
    }
}
 
 
if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
        echo date("d M Y h:i:s A")." - Begin Posting Stock Item<br>";
        PostData();
echo date("d M Y h:i:s A")." - Done<br>";
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}
 
?>  
     <form method="post">           
         <input type="submit" name="BtnData"
                 value="Add & Edit Stock Item"/>  
     </form>  
</body>
</html>
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Add Points====
====Add Stock Issue====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Add Points Script  
! Add Stock Issue Script  
|-
|-
|  
|  
Line 3,735: Line 4,287:


<?php
<?php
echo "Updated 30 Oct 2020<br>";
echo "Updated 21 Oct 2020<br>";
$ComServer = null;
$ComServer = null;


Line 3,749: Line 4,301:
     }
     }
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                       "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                       "D:\Happy\DB\Default.DCF", #"C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                       "ACC-0024.FDB"); #Database Name
                       "ACC-0024.FDB"); #Database Name
   
}
function CheckLogin1()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
      
      
}
}
Line 3,757: Line 4,316:
global $ComServer;
global $ComServer;
$BizObject = $ComServer->BizObjects->Find("Sales.Points.OPF");
$BizObject = $ComServer->BizObjects->Find("ST_IS");
     $lMain = $BizObject->DataSets->Find("Main"); #lMain contains master data
     $lMain = $BizObject->DataSets->Find("MainDataSet");
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail");  
     $BizObject->New();
     $BizObject->New();
     $lMain->FindField("DocKey")->value = -1;
     $lMain->FindField("DocKey")->value = -1;
     $lMain->FindField("DocNo")->AsString = "--Point Test--";
     $lMain->FindField("DocNo")->AsString = "--IS Test--";
     $lMain->FindField("DocDate")->value = "04/20/2020"; #MM/DD/YYYY
     $lMain->FindField("DocDate")->value = "04/20/2020"; #MM/DD/YYYY
     $lMain->FindField("Code")->AsString = "300-C0001"; #Customer Account
     $lMain->FindField("PostDate")->value = "04/20/2020"; #MM/DD/YYYY
     $lMain->FindField("CompanyName")->AsString = "Cash Sales";
     $lMain->FindField("Description")->AsString = "Stock Issue";
$lMain->FindField("DESCRIPTION")->AsString = "Points Earn";
     $lMain->FindField("FromDocType")->AsString = "CS";
    #Insert Data - Detail
$lMain->FindField("FromDocNo")->AsString = "CS-01234";
    $lDetail->Append();
$lMain->FindField("FROMDOCAMT")->AsFloat = 100.10;
    $lDetail->FindField("DtlKey")->value = -1;
$lMain->FindField("Points")->AsFloat = 10;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 1;
    $lDetail->FindField("ItemCode")->AsString = "ANT";
    $lDetail->FindField("Description")->AsString = "Sales Item B";
     $lDetail->FindField("Qty")->AsFloat = 2;
    $lDetail->FindField("UOM")->AsString = "BOX";
    $lDetail->Post();
 
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 2;
    $lDetail->FindField("ItemCode")->AsString = "N-CHARGER";
    $lDetail->FindField("Description")->AsString = "NOKIA CHARGER";
    $lDetail->FindField("Qty")->AsFloat = 5;
    $lDetail->FindField("UOM")->AsString = "UNIT";
    $lDetail->Post();
    $BizObject->Save();
    $BizObject->Close();
try{
try{
$BizObject->Save();
        $BizObject->Save();
        $BizObject->Close();
}catch (Exception $e) {
}catch (Exception $e) {
echo 'Caught exception: ',  $e->getMessage(), "\n";
    echo 'Caught exception: ',  $e->getMessage(), "\n";
     }
     }
}
}


Line 3,784: Line 4,364:
     try
     try
     {
     {
         CheckLogin();
         CheckLogin1();
         echo date("d M Y h:i:s A")." - Posting Point<br>";
         echo date("d M Y h:i:s A")." - Begin Posting<br>";
         PostData();
         PostData();
echo date("d M Y h:i:s A")." - Done<br>";
     }
     }
     finally
     finally
Line 3,799: Line 4,380:
     <form method="post">           
     <form method="post">           
         <input type="submit" name="BtnData"
         <input type="submit" name="BtnData"
                 value="Post Point"/>  
                 value="Add Stock Issue"/>  
     </form>  
     </form>  
</body>
</body>
Line 3,807: Line 4,388:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-AR_CN====
====Add Points====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! AR_CN Script  
! Add Points Script  
|-
|-
|  
|  
Line 3,815: Line 4,396:
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/Grid.css" />
</head>
<body>
<body>


Line 3,823: Line 4,401:


<?php
<?php
echo "Updated 12 Dec 2020<br>";
echo "Updated 30 Oct 2020<br>";
#This action to Post Customer Credit Note
 
$ComServer = null;
$ComServer = null;


Line 3,840: Line 4,416:
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                       "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                       "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                       "ACC-0040.FDB"); #Database Name
                       "ACC-0024.FDB"); #Database Name
      
      
}
}
Line 3,847: Line 4,423:
global $ComServer;
global $ComServer;
$BizObject = $ComServer->BizObjects->Find("AR_CN");
$BizObject = $ComServer->BizObjects->Find("Sales.Points.OPF");
     $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
     $lMain = $BizObject->DataSets->Find("Main"); #lMain contains master data
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
$lKO = $BizObject->DataSets->Find("cdsKnockOff");
     $BizObject->New();
     $BizObject->New();
     $lMain->FindField("DocKey")->value = -1;
     $lMain->FindField("DocKey")->value = -1;
     $lMain->FindField("DocNo")->AsString = "--CN Test1--";
     $lMain->FindField("DocNo")->AsString = "--Point Test--";
     $lMain->FindField("DocDate")->value = "04/20/2020"; #MM/DD/YYYY
     $lMain->FindField("DocDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("PostDate")->value = "04/20/2020"; #MM/DD/YYYY
     $lMain->FindField("Code")->AsString = "300-C0001"; #Customer Account
     $lMain->FindField("Code")->AsString = "300-C0001"; #Customer Account
     $lMain->FindField("Description")->AsString = "Sales";
     $lMain->FindField("CompanyName")->AsString = "Cash Sales";
$lMain->FindField("DESCRIPTION")->AsString = "Points Earn";
    $lMain->FindField("FromDocType")->AsString = "CS";
$lMain->FindField("FromDocNo")->AsString = "CS-01234";
$lMain->FindField("FROMDOCAMT")->AsFloat = 100.10;
$lMain->FindField("Points")->AsFloat = 10;
    #Insert Data - Detail
try{
    #For Tax Inclusive = True with override Tax Amount
$BizObject->Save();
    $lDetail->Append();
}catch (Exception $e) {
    $lDetail->FindField("DtlKey")->value = -1;
echo 'Caught exception: ',  $e->getMessage(), "\n";
    $lDetail->FindField("DocKey")->value = -1;
     }
    $lDetail->FindField("Seq")->value = 1;
}
    $lDetail->FindField("Account")->AsString = "510-000"; #Sales Return Account
    $lDetail->FindField("Description")->AsString = "Return Item A";
    $lDetail->FindField("Tax")->AsString = "";
    $lDetail->FindField("TaxRate")->AsString = "";
    $lDetail->FindField("TaxInclusive")->value = 0;
    $lDetail->FindField("Amount")->AsFloat = 410.37; #Exclding GST Amt
     $lDetail->FindField("TaxAmt")->AsFloat = 0;
$lDetail->Post();


    $V = array("IV", "IV-00003");  #DocType, DocNo
       
    if ($lKO->Locate("DocType;DocNo", $V, False, False)){
        $lKO->Edit();
        $lKO->FindField("KOAmt")->AsFloat = 100; #Partial Knock off
        $lKO->FindField("KnockOff")->AsString = "T";
        $lKO->Post();
}
    $BizObject->Save();
    $BizObject->Close();
}


if (isset($_POST['BtnData']))
if (isset($_POST['BtnData']))
Line 3,892: Line 4,451:
     {
     {
         CheckLogin();
         CheckLogin();
PostData();
         echo date("d M Y h:i:s A")." - Posting Point<br>";
         echo date("d M Y h:i:s A")." - Done";
        PostData();
     }
     }
     finally
     finally
Line 3,906: Line 4,465:
     <form method="post">           
     <form method="post">           
         <input type="submit" name="BtnData"
         <input type="submit" name="BtnData"
                 value="Post Customer Credit Note"/>  
                 value="Post Point"/>  
     </form>  
     </form>  
</body>
</body>
Line 3,914: Line 4,473:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-SO to DO====
====AR_CN====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! SO to DO Script  
! AR_CN Script  
|-
|-
|  
|  
Line 3,930: Line 4,489:


<?php
<?php
echo "Updated 15 Jan 2021<br>";
echo "Updated 12 Dec 2020<br>";
#This action to  
#This action to Post Customer Credit Note
#01. Get Oustanding SO
#02. Post To DO


$ComServer = null;
$ComServer = null;
Line 3,949: Line 4,506:
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                       "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                       "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                       "ACC-0024.FDB"); #Database Name
                       "ACC-0040.FDB"); #Database Name
      
      
}
}
Line 3,956: Line 4,513:
global $ComServer;
global $ComServer;
     $lSQL = "SELECT Dockey, DocNo,Code, CompanyName, Seq, DtlKey, ItemCode, Qty, UOM, UnitPrice, Disc, Amount,
$BizObject = $ComServer->BizObjects->Find("AR_CN");
            COALESCE(Sum(XFQty),0) XFQty, COALESCE((Qty-Sum(XFQty)), Qty) OSQty FROM (
     $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
            SELECT A.Dockey, A.DocNo, A.Code, A.CompanyName,
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
            B.DtlKey, B.Seq, B.ItemCode, B.Qty, B.UOM, B.UnitPrice, B.Disc, B.Amount,
$lKO = $BizObject->DataSets->Find("cdsKnockOff");
            C.Qty XFQty FROM SL_SO A
            INNER JOIN SL_SODTL B ON (A.DOCKEY=B.DOCKEY)
    $BizObject->New();
            LEFT JOIN ST_XTRANS C ON (A.DOCKEY=C.FROMDOCKEY AND B.DTLKEY=C.FROMDTLKEY
    $lMain->FindField("DocKey")->value = -1;
                                      AND C.FROMDOCTYPE='SO')
    $lMain->FindField("DocNo")->AsString = "--CN Test1--";
            WHERE A.DOCNO='SO-00140')
    $lMain->FindField("DocDate")->value = "04/20/2020"; #MM/DD/YYYY
            GROUP BY Dockey, DocNo, Code, CompanyName, Seq, Dtlkey, ItemCode, Qty, UOM, UnitPrice, Disc, Amount
    $lMain->FindField("PostDate")->value = "04/20/2020"; #MM/DD/YYYY
HAVING COALESCE((Qty-Sum(XFQty)), Qty) >0
    $lMain->FindField("Code")->AsString = "300-C0001"; #Customer Account
";
    $lMain->FindField("Description")->AsString = "Sales";
$lDataSet = $ComServer->DBManager->NewDataSet($lSQL); #Get Oustanding SO Qty
    #Insert Data - Detail
    #For Tax Inclusive = True with override Tax Amount
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 1;
    $lDetail->FindField("Account")->AsString = "510-000"; #Sales Return Account
    $lDetail->FindField("Description")->AsString = "Return Item A";
    $lDetail->FindField("Tax")->AsString = "";
    $lDetail->FindField("TaxRate")->AsString = "";
    $lDetail->FindField("TaxInclusive")->value = 0;
    $lDetail->FindField("Amount")->AsFloat = 410.37; #Exclding GST Amt
    $lDetail->FindField("TaxAmt")->AsFloat = 0;
$lDetail->Post();


     if ($lDataSet->RecordCount > 0) {
     $V = array("IV", "IV-00003"); #DocType, DocNo
$BizObject = $ComServer->BizObjects->Find("SL_DO");
          
        $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
    if ($lKO->Locate("DocType;DocNo", $V, False, False)){
         $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
        $lKO->Edit();
        $lKO->FindField("KOAmt")->AsFloat = 100; #Partial Knock off
$lDataSet->First();
        $lKO->FindField("KnockOff")->AsString = "T";
$BizObject->New();
        $lKO->Post();
$lMain->FindField("DocKey")->value = -1;
}
$lMain->FindField("DocNo")->AsString = "--DO Test--";
    $BizObject->Save();
$lMain->FindField("DocDate")->value = "01/20/2021"; #MM/DD/YYYY
    $BizObject->Close();
$lMain->FindField("PostDate")->value = "01/20/2021"; #MM/DD/YYYY
}
$lMain->FindField("Code")->AsString = $lDataSet->FindField("Code")->AsString;
$lMain->FindField("CompanyName")->AsString = $lDataSet->FindField("CompanyName")->AsString;
$lMain->FindField("Description")->AsString = "Delivery Order";


while (! $lDataSet->Eof()){
if (isset($_POST['BtnData']))
    $lDetail->Append();
{
    $lDetail->FindField("DtlKey")->value = -1;
     try
    $lDetail->FindField("DocKey")->value = -1;
     {
    $lDetail->FindField("ItemCode")->AsString = $lDataSet->FindField("ItemCode")->AsString;
         CheckLogin();
    $lDetail->FindField("UOM")->AsString = $lDataSet->FindField("UOM")->AsString;
PostData();
$lDetail->FindField("Qty")->AsFloat = $lDataSet->FindField("OSQty")->AsFloat;
    $lDetail->FindField("DISC")->value = $lDataSet->FindField("DISC")->value;
    $lDetail->FindField("Tax")->AsString = "";
    $lDetail->FindField("TaxRate")->AsString = "";
    $lDetail->FindField("TaxInclusive")->value = 0;
    $lDetail->FindField("UnitPrice")->AsFloat = $lDataSet->FindField("UnitPrice")->AsFloat;
    $lDetail->FindField("Amount")->AsFloat = $lDataSet->FindField("Amount")->AsFloat;
    $lDetail->FindField("TaxAmt")->AsFloat = 0;
$lDetail->FindField("FromDocType")->AsString = "SO";
$lDetail->FindField("FromDockey")->AsFloat = $lDataSet->FindField("Dockey")->AsFloat;
$lDetail->FindField("FromDtlkey")->AsFloat = $lDataSet->FindField("DtlKey")->AsFloat;
    $lDetail->Post();
$lDataSet->Next();
 
}
        $BizObject->Save();
        $BizObject->Close();
}else {
    echo "Record Not Found";
    }
}
 
if (isset($_POST['BtnData']))
{
     try
     {
         CheckLogin();
PostData();
         echo date("d M Y h:i:s A")." - Done";
         echo date("d M Y h:i:s A")." - Done";
     }
     }
Line 4,033: Line 4,572:
     <form method="post">           
     <form method="post">           
         <input type="submit" name="BtnData"
         <input type="submit" name="BtnData"
                 value="Post SO to DO"/>  
                 value="Post Customer Credit Note"/>  
     </form>  
     </form>  
</body>
</body>
Line 4,041: Line 4,580:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-ST_AJ====
====SO to DO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! ST_AJ Script  
! SO to DO Script  
|-
|-
|  
|  
Line 4,057: Line 4,596:


<?php
<?php
echo "Updated 08 Feb 2021<br>";
echo "Updated 15 Jan 2021<br>";
#This action to
#01. Get Oustanding SO
#02. Post To DO


$ComServer = null;
$ComServer = null;
Line 4,073: Line 4,615:
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                       "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                       "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                       "ACC-0100.FDB"); #Database Name
                       "ACC-0024.FDB"); #Database Name
      
      
}
}
Line 4,080: Line 4,622:
global $ComServer;
global $ComServer;
$BizObject = $ComServer->BizObjects->Find("ST_AJ");
    $lSQL = "SELECT Dockey, DocNo,Code, CompanyName, Seq, DtlKey, ItemCode, Qty, UOM, UnitPrice, Disc, Amount,
    $lMain = $BizObject->DataSets->Find("MainDataSet");
            COALESCE(Sum(XFQty),0) XFQty, COALESCE((Qty-Sum(XFQty)), Qty) OSQty FROM (
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail");  
            SELECT A.Dockey, A.DocNo, A.Code, A.CompanyName,
            B.DtlKey, B.Seq, B.ItemCode, B.Qty, B.UOM, B.UnitPrice, B.Disc, B.Amount,
            C.Qty XFQty FROM SL_SO A
            INNER JOIN SL_SODTL B ON (A.DOCKEY=B.DOCKEY)
            LEFT JOIN ST_XTRANS C ON (A.DOCKEY=C.FROMDOCKEY AND B.DTLKEY=C.FROMDTLKEY
                                      AND C.FROMDOCTYPE='SO')
            WHERE A.DOCNO='SO-00140')
            GROUP BY Dockey, DocNo, Code, CompanyName, Seq, Dtlkey, ItemCode, Qty, UOM, UnitPrice, Disc, Amount
HAVING COALESCE((Qty-Sum(XFQty)), Qty) >0
";
    $BizObject->New();
$lDataSet = $ComServer->DBManager->NewDataSet($lSQL); #Get Oustanding SO Qty
     $lMain->FindField("DocKey")->value = -1;
 
    $lMain->FindField("DocNo")->AsString = "--AJ Test--";
     if ($lDataSet->RecordCount > 0) {
    $lMain->FindField("DocDate")->value = "04/20/2020"; #MM/DD/YYYY
$BizObject = $ComServer->BizObjects->Find("SL_DO");
    $lMain->FindField("PostDate")->value = "04/20/2020"; #MM/DD/YYYY
        $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
    $lMain->FindField("Description")->AsString = "Stock Adjustment";
        $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
    #Insert Data - Detail - Increase Stock Qty
$lDataSet->First();
    $lDetail->Append();
$BizObject->New();
    $lDetail->FindField("DtlKey")->value = -1;
$lMain->FindField("DocKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
$lMain->FindField("DocNo")->AsString = "--DO Test--";
    $lDetail->FindField("Seq")->value = 1;
$lMain->FindField("DocDate")->value = "01/20/2021"; #MM/DD/YYYY
    $lDetail->FindField("ItemCode")->AsString = "ANT";
$lMain->FindField("PostDate")->value = "01/20/2021"; #MM/DD/YYYY
    $lDetail->FindField("Description")->AsString = "ANTENA";
$lMain->FindField("Code")->AsString = $lDataSet->FindField("Code")->AsString;
    $lDetail->FindField("Qty")->AsFloat = 2;
$lMain->FindField("CompanyName")->AsString = $lDataSet->FindField("CompanyName")->AsString;
    $lDetail->FindField("UOM")->AsString = "BOX";
$lMain->FindField("Description")->AsString = "Delivery Order";
    $lDetail->Post();
    #Insert Data - Detail - Reduce Stock Qty
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 2;
    $lDetail->FindField("ItemCode")->AsString = "N-CHARGER";
    $lDetail->FindField("Description")->AsString = "NOKIA CHARGER";
    $lDetail->FindField("Qty")->AsFloat = -5;
    $lDetail->FindField("UOM")->AsString = "UNIT";
    $lDetail->Post();
    $BizObject->Save();
    $BizObject->Close();
try{
        $BizObject->Save();
        $BizObject->Close();
}catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
    }
}


if (isset($_POST['BtnData']))
while (! $lDataSet->Eof()){
{
    $lDetail->Append();
     try
    $lDetail->FindField("DtlKey")->value = -1;
     {
    $lDetail->FindField("DocKey")->value = -1;
         CheckLogin();
    $lDetail->FindField("ItemCode")->AsString = $lDataSet->FindField("ItemCode")->AsString;
PostData();
    $lDetail->FindField("UOM")->AsString = $lDataSet->FindField("UOM")->AsString;
         echo date("d M Y h:i:s A")." - Done";
$lDetail->FindField("Qty")->AsFloat = $lDataSet->FindField("OSQty")->AsFloat;
    $lDetail->FindField("DISC")->value = $lDataSet->FindField("DISC")->value;
    $lDetail->FindField("Tax")->AsString = "";
    $lDetail->FindField("TaxRate")->AsString = "";
    $lDetail->FindField("TaxInclusive")->value = 0;
    $lDetail->FindField("UnitPrice")->AsFloat = $lDataSet->FindField("UnitPrice")->AsFloat;
    $lDetail->FindField("Amount")->AsFloat = $lDataSet->FindField("Amount")->AsFloat;
    $lDetail->FindField("TaxAmt")->AsFloat = 0;
$lDetail->FindField("FromDocType")->AsString = "SO";
$lDetail->FindField("FromDockey")->AsFloat = $lDataSet->FindField("Dockey")->AsFloat;
$lDetail->FindField("FromDtlkey")->AsFloat = $lDataSet->FindField("DtlKey")->AsFloat;
    $lDetail->Post();
$lDataSet->Next();
 
}
        $BizObject->Save();
        $BizObject->Close();
}else {
    echo "Record Not Found";
    }
}
 
if (isset($_POST['BtnData']))
{
     try
     {
         CheckLogin();
PostData();
         echo date("d M Y h:i:s A")." - Done";
     }
     }
     finally
     finally
Line 4,142: Line 4,699:
     <form method="post">           
     <form method="post">           
         <input type="submit" name="BtnData"
         <input type="submit" name="BtnData"
                 value="Post ST_AJ"/>  
                 value="Post SO to DO"/>  
     </form>  
     </form>  
</body>
</body>
Line 4,150: Line 4,707:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Get Stock Serial Number balance====
====ST_AJ====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Get Stock Serial Number Balance List Script  
! ST_AJ Script  
|-
|-
|  
|  
Line 4,166: Line 4,723:


<?php
<?php
echo "Updated 21 May 2021<br>";
echo "Updated 08 Feb 2021<br>";


$ComServer = null;
$ComServer = null;
Line 4,181: Line 4,738:
     }
     }
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                       "D:\Happy\DB\Default.DCF",  #"C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                       "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                       "ACC-0024.FDB"); #Database Name
                       "ACC-0100.FDB"); #Database Name
      
      
}
}


function GetData(){
function PostData(){
global $ComServer;
global $ComServer;
     $lSQL = "SELECT ItemCode, Location, Batch, SerialNumber, SUM(Qty) Qty  FROM ST_TR_SN 
$BizObject = $ComServer->BizObjects->Find("ST_AJ");
        GROUP BY ItemCode, Location, Batch, SerialNumber
     $lMain = $BizObject->DataSets->Find("MainDataSet");
HAVING SUM(Qty) > 0
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail");
";
    $BizObject->New();
    $lMain->FindField("DocKey")->value = -1;
    $lMain->FindField("DocNo")->AsString = "--AJ Test--";
    $lMain->FindField("DocDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("PostDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("Description")->AsString = "Stock Adjustment";
$lDataSet = $ComServer->DBManager->NewDataSet($lSQL);
    #Insert Data - Detail - Increase Stock Qty
 
    $lDetail->Append();
     if ($lDataSet->RecordCount > 0) {
     $lDetail->FindField("DtlKey")->value = -1;
$lDataSet->First();
    $lDetail->FindField("DocKey")->value = -1;
$fc = $lDataSet->Fields->Count-1;
    $lDetail->FindField("Seq")->value = 1;
echo "<table>";
    $lDetail->FindField("ItemCode")->AsString = "ANT";
echo "<tr>";
    $lDetail->FindField("Description")->AsString = "ANTENA";
for ($x = 0; $x <= $fc; $x++) {
    $lDetail->FindField("Qty")->AsFloat = 2;
#Insert Header
    $lDetail->FindField("UOM")->AsString = "BOX";
echo "<td>".$lDataSet->Fields->Items($x)->FieldName()."</td>";  
    $lDetail->Post();
}
    #Insert Data - Detail - Reduce Stock Qty
echo "</tr>";
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
#Looping Dataset
    $lDetail->FindField("DocKey")->value = -1;
while (! $lDataSet->Eof()){
    $lDetail->FindField("Seq")->value = 2;
echo "<tr>";
    $lDetail->FindField("ItemCode")->AsString = "N-CHARGER";
    for ($x = 0; $x <= $fc; $x++) {
    $lDetail->FindField("Description")->AsString = "NOKIA CHARGER";
$lFN = $lDataSet->Fields->Items($x)->FieldName();
    $lDetail->FindField("Qty")->AsFloat = -5;
    echo "<td>".$lDataSet->FindField($lFN)->AsString()."</td>";  
    $lDetail->FindField("UOM")->AsString = "UNIT";
    }
    $lDetail->Post();
    echo "</tr>";
$lDataSet->Next();
    $BizObject->Save();
}
    $BizObject->Close();
echo "</table>"."<br>";
}else {
try{
     echo "Record Not Found";
        $BizObject->Save();
     }
        $BizObject->Close();
}catch (Exception $e) {
     echo 'Caught exception: ',  $e->getMessage(), "\n";
     }
}
}


Line 4,228: Line 4,794:
     {
     {
         CheckLogin();
         CheckLogin();
GetData();
PostData();
         echo date("d M Y h:i:s A")." - Done";
         echo date("d M Y h:i:s A")." - Done";
     }
     }
Line 4,242: Line 4,808:
     <form method="post">           
     <form method="post">           
         <input type="submit" name="BtnData"
         <input type="submit" name="BtnData"
                 value="Get SN Balance"/>  
                 value="Post ST_AJ"/>  
     </form>  
     </form>  
</body>
</body>
Line 4,250: Line 4,816:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-SL_IV-Add, Edit & Delete====
====Get Stock Serial Number balance====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Insert, Edit & Delete Invoice Script  
! Get Stock Serial Number Balance List Script  
|-
|-
|  
|  
Line 4,258: Line 4,824:
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/Grid.css" />
</head>
<body>
<body>


Line 4,263: Line 4,832:


<?php
<?php
echo "Updated 14 Mar 2022<br>";
echo "Updated 21 May 2021<br>";
 
$ComServer = null;
$ComServer = null;


Line 4,277: Line 4,847:
     }
     }
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                       "D:\Happy\DB\Default.DCF", #"C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                       "D:\Happy\DB\Default.DCF", #"C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                       "ACC-0015.FDB"); #Database Name
                       "ACC-0024.FDB"); #Database Name
      
      
}
}


function PostDataIV(){
function GetData(){
global $ComServer;
global $ComServer;
$BizObject = $ComServer->BizObjects->Find("SL_IV");
    $lSQL = "SELECT ItemCode, Location, Batch, SerialNumber, SUM(Qty) Qty  FROM ST_TR_SN 
    $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
        GROUP BY ItemCode, Location, Batch, SerialNumber
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
HAVING SUM(Qty) > 0
";
    #Find IV Number
$lDataSet = $ComServer->DBManager->NewDataSet($lSQL);
    $lDocNo = "--IV Test--";
    $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
if ($lDocKey != null){
        echo "Dockey = ".$lDocKey."<br>";
$BizObject->Params->Find("DocKey")->AsString = $lDocKey;
$BizObject->Open();
        $BizObject->Edit();
        $lMain->Edit();
    $lMain->FindField("DocDate")->value = "02/20/2022"; #MM/DD/YYYY
        $lMain->FindField("PostDate")->value = "02/20/2022"; #MM/DD/YYYY
        $lMain->FindField("CompanyName")->AsString = "Cash Sales-Edited";
        $lMain->FindField("Address1")->AsString = ""; #Optional
        $lMain->FindField("Address2")->AsString = ""; #Optional
        $lMain->FindField("Address3")->AsString = ""; #Optional
        $lMain->FindField("Address4")->AsString = ""; #Optional
        $lMain->FindField("Phone1")->AsString = "";  #Optional
        $lMain->FindField("Description")->AsString = "Sales - Edited";


$r = $lDetail->RecordCount();
    if ($lDataSet->RecordCount > 0) {
$x = 1;
$lDataSet->First();
while ($x <= $r ){
$fc = $lDataSet->Fields->Count-1;
$lDetail->First();
echo "<table>";
            $lDetail->Delete();
echo "<tr>";
$x++;
for ($x = 0; $x <= $fc; $x++) {
#Insert Header
echo "<td>".$lDataSet->Fields->Items($x)->FieldName()."</td>";  
}
}
        $lDetail->Append();
echo "</tr>";
        $lDetail->FindField("ItemCode")->AsString = "COVER";
        $lDetail->FindField("Description")->AsString = "Sales Item Cover";
#Looping Dataset
    $lDetail->FindField("UOM")->AsString = "UNIT";
while (! $lDataSet->Eof()){
        $lDetail->FindField("Qty")->AsFloat = 3;
echo "<tr>";
        $lDetail->FindField("Tax")->AsString = "";
    for ($x = 0; $x <= $fc; $x++) {
        $lDetail->FindField("TaxRate")->AsString = "";
$lFN = $lDataSet->Fields->Items($x)->FieldName();
        $lDetail->FindField("TaxInclusive")->value = 0;
    echo "<td>".$lDataSet->FindField($lFN)->AsString()."</td>";  
        $lDetail->FindField("UnitPrice")->AsFloat = 5.60;
    }
        $lDetail->FindField("Amount")->AsFloat = 16.80;
    echo "</tr>";
        $lDetail->FindField("TaxAmt")->AsFloat = 0;
$lDataSet->Next();
        $lDetail->Post();
}
} else {
echo "</table>"."<br>";
      echo "New Invoice<br>";
}else {
  $BizObject->New();
    echo "Record Not Found";
      $lMain->FindField("DocKey")->value = -1;
    }
      $lMain->FindField("DocNo")->AsString = $lDocNo;
}
  $lMain->FindField("Code")->AsString = "300-C0001"; #Customer Account
  $lMain->FindField("DocDate")->value = "02/18/2022"; #MM/DD/YYYY
      $lMain->FindField("PostDate")->value = "02/18/2022"; #MM/DD/YYYY
      $lMain->FindField("CompanyName")->AsString = "Cash Sales";
      $lMain->FindField("Address1")->AsString = ""; #Optional
      $lMain->FindField("Address2")->AsString = ""; #Optional
      $lMain->FindField("Address3")->AsString = ""; #Optional
      $lMain->FindField("Address4")->AsString = ""; #Optional
      $lMain->FindField("Phone1")->AsString = "";  #Optional
      $lMain->FindField("Description")->AsString = "Sales";
  #$lMain->FindField('DocAmt')->value = $Amt;
      $lDetail->Append();
      $lDetail->FindField("ItemCode")->AsString = "ANT";
      $lDetail->FindField("Description")->AsString = "Sales Item ANT";
  $lDetail->FindField("UOM")->AsString = "UNIT";
      $lDetail->FindField("Qty")->AsFloat = 1;
      $lDetail->FindField("Tax")->AsString = "";
      $lDetail->FindField("TaxRate")->AsString = "";
      $lDetail->FindField("TaxInclusive")->value = 0;
      $lDetail->FindField("UnitPrice")->AsFloat = 100;
      $lDetail->FindField("Amount")->AsFloat = 100;
      $lDetail->FindField("TaxAmt")->AsFloat = 0;
      $lDetail->Post();


 
if (isset($_POST['BtnData']))
      $lDetail->Append();
{
      $lDetail->FindField("ItemCode")->AsString = "BOM";
    try
      $lDetail->FindField("Description")->AsString = "Sales Item BOM";
    {
  $lDetail->FindField("UOM")->AsString = "UNIT";
        CheckLogin();
      $lDetail->FindField("Qty")->AsFloat = 2;
GetData();
      $lDetail->FindField("Tax")->AsString = "";
        echo date("d M Y h:i:s A")." - Done";
      $lDetail->FindField("TaxRate")->AsString = "";
     }
      $lDetail->FindField("TaxInclusive")->value = 0;
    finally
      $lDetail->FindField("UnitPrice")->AsFloat = 150;
    {
      $lDetail->FindField("Amount")->AsFloat = 300;
        $ComServer->Logout();
      $lDetail->FindField("TaxAmt")->AsFloat = 0;
        #free the object
      $lDetail->Post();
        $ComServer = null;
}
    }
    $BizObject->Save();
echo date("d M Y h:i:s A")." - Posting Done<br>";
     $BizObject->Close();
}
}


function PostDelIV(){
?>  
global $ComServer;
     <form method="post">           
         <input type="submit" name="BtnData"
$BizObject = $ComServer->BizObjects->Find("SL_IV");
                 value="Get SN Balance"/>  
    $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
    #Find IV Number
    $lDocNo = "--IV Test--";
    $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
if ($lDocKey != null){
        echo "Dockey = ".$lDocKey."<br>";
$BizObject->Params->Find("DocKey")->AsString = $lDocKey;
$BizObject->Open();
        $BizObject->Delete();
echo date("d M Y h:i:s A")." - Record deleted<br>";
} else {
echo date("d M Y h:i:s A")." - Document Not Found<br>";
}
}
if (isset($_POST['BtnPost']))
{
    try
    {
        CheckLogin();
        echo date("d M Y h:i:s A")." - Begin Posting<br>";
        PostDataIV();
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}
 
if (isset($_POST['BtnDel']))
{
    try
    {
        CheckLogin();
        echo date("d M Y h:i:s A")." - Begin Delete<br>";
        PostDelIV();
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}
 
?>  
     <form method="post">           
         <input type="submit" name="BtnPost"
                value="Post Sales IV"/>
        <input type="submit" name="BtnDel"
                 value="Post Delete IV"/>
     </form>  
     </form>  
</body>
</body>
Line 4,443: Line 4,916:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-GL_PV-Add, Edit & Delete====
====SL_IV-Add, Edit & Delete====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Insert, Edit & Delete Invoice Script  
! Insert, Edit & Delete Invoice Script  
Line 4,456: Line 4,929:


<?php
<?php
echo "Updated 15 Mar 2022<br>";
echo "Updated 14 Mar 2022<br>";
$ComServer = null;
$ComServer = null;


Line 4,475: Line 4,948:
}
}


function PostData(){
function PostDataIV(){
global $ComServer;
global $ComServer;
$BizObject = $ComServer->BizObjects->Find("GL_PV");
$BizObject = $ComServer->BizObjects->Find("SL_IV");
     $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
     $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
     $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
     $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
     #Find PV Number
     #Find IV Number
     $lDocNo = "--PV Test--";
     $lDocNo = "--IV Test--";
     $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
     $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
Line 4,494: Line 4,967:
    $lMain->FindField("DocDate")->value = "02/20/2022"; #MM/DD/YYYY
    $lMain->FindField("DocDate")->value = "02/20/2022"; #MM/DD/YYYY
         $lMain->FindField("PostDate")->value = "02/20/2022"; #MM/DD/YYYY
         $lMain->FindField("PostDate")->value = "02/20/2022"; #MM/DD/YYYY
         $lMain->FindField("Description")->AsString = "Tenaga Malaysia - Edited";
         $lMain->FindField("CompanyName")->AsString = "Cash Sales-Edited";
$lMain->FindField("PaymentMethod")->AsString = "310-001"; #GL Bank/Cash account code
        $lMain->FindField("Address1")->AsString = ""; #Optional
$lMain->FindField("CHEQUENUMBER")->AsString = "MBB 123456"; #Optional
        $lMain->FindField("Address2")->AsString = ""; #Optional
$lMain->FindField("Cancelled")->AsString = "F";
        $lMain->FindField("Address3")->AsString = ""; #Optional
        $lMain->FindField("Address4")->AsString = ""; #Optional
        $lMain->FindField("Phone1")->AsString = "";   #Optional
        $lMain->FindField("Description")->AsString = "Sales - Edited";


$r = $lDetail->RecordCount();
$r = $lDetail->RecordCount();
Line 4,507: Line 4,983:
}
}
         $lDetail->Append();
         $lDetail->Append();
         $lDetail->FindField("Code")->AsString = "907-000";
         $lDetail->FindField("ItemCode")->AsString = "COVER";
         $lDetail->FindField("Description")->AsString = "TNB Bill for Feb 2022 - Edited";
         $lDetail->FindField("Description")->AsString = "Sales Item Cover";
    $lDetail->FindField("UOM")->AsString = "UNIT";
        $lDetail->FindField("Qty")->AsFloat = 3;
         $lDetail->FindField("Tax")->AsString = "";
         $lDetail->FindField("Tax")->AsString = "";
         $lDetail->FindField("TaxRate")->AsString = "";
         $lDetail->FindField("TaxRate")->AsString = "";
         $lDetail->FindField("TaxInclusive")->value = 0;
         $lDetail->FindField("TaxInclusive")->value = 0;
         $lDetail->FindField("Amount")->AsFloat = 168.80;
        $lDetail->FindField("UnitPrice")->AsFloat = 5.60;
         $lDetail->FindField("Amount")->AsFloat = 16.80;
         $lDetail->FindField("TaxAmt")->AsFloat = 0;
         $lDetail->FindField("TaxAmt")->AsFloat = 0;
         $lDetail->Post();
         $lDetail->Post();
} else {
} else {
       echo "New PV<br>";
       echo "New Invoice<br>";
  $BizObject->New();
  $BizObject->New();
       $lMain->FindField("DocKey")->value = -1;
       $lMain->FindField("DocKey")->value = -1;
       $lMain->FindField("DocNo")->AsString = $lDocNo;
       $lMain->FindField("DocNo")->AsString = $lDocNo;
  $lMain->FindField("Code")->AsString = "300-C0001"; #Customer Account
  $lMain->FindField("DocDate")->value = "02/18/2022"; #MM/DD/YYYY
  $lMain->FindField("DocDate")->value = "02/18/2022"; #MM/DD/YYYY
       $lMain->FindField("PostDate")->value = "02/18/2022"; #MM/DD/YYYY
       $lMain->FindField("PostDate")->value = "02/18/2022"; #MM/DD/YYYY
       $lMain->FindField("Description")->AsString = "Tenaga Malaysia";
       $lMain->FindField("CompanyName")->AsString = "Cash Sales";
  $lMain->FindField("PaymentMethod")->AsString = "310-001"; #GL Bank/Cash account code
      $lMain->FindField("Address1")->AsString = ""; #Optional
  $lMain->FindField("CHEQUENUMBER")->AsString = "MBB 123456"; #Optional
      $lMain->FindField("Address2")->AsString = ""; #Optional
  $lMain->FindField("Cancelled")->AsString = "F";
      $lMain->FindField("Address3")->AsString = ""; #Optional
      $lMain->FindField("Address4")->AsString = ""; #Optional
      $lMain->FindField("Phone1")->AsString = "";   #Optional
      $lMain->FindField("Description")->AsString = "Sales";
  #$lMain->FindField('DocAmt')->value = $Amt;
       $lDetail->Append();
       $lDetail->Append();
       $lDetail->FindField("Code")->AsString = "907-000"; #GL Account
       $lDetail->FindField("ItemCode")->AsString = "ANT";
       $lDetail->FindField("Description")->AsString = "TNB Bill for Jan 2022";
       $lDetail->FindField("Description")->AsString = "Sales Item ANT";
  $lDetail->FindField("UOM")->AsString = "UNIT";
      $lDetail->FindField("Qty")->AsFloat = 1;
       $lDetail->FindField("Tax")->AsString = "";
       $lDetail->FindField("Tax")->AsString = "";
       $lDetail->FindField("TaxRate")->AsString = "";
       $lDetail->FindField("TaxRate")->AsString = "";
       $lDetail->FindField("TaxInclusive")->value = 0;
       $lDetail->FindField("TaxInclusive")->value = 0;
       $lDetail->FindField("Amount")->AsFloat = 100.80;
      $lDetail->FindField("UnitPrice")->AsFloat = 100;
       $lDetail->FindField("Amount")->AsFloat = 100;
       $lDetail->FindField("TaxAmt")->AsFloat = 0;
       $lDetail->FindField("TaxAmt")->AsFloat = 0;
       $lDetail->Post();
       $lDetail->Post();


       $lDetail->Append();
       $lDetail->Append();
       $lDetail->FindField("Code")->AsString = "907-000";
       $lDetail->FindField("ItemCode")->AsString = "BOM";
       $lDetail->FindField("Description")->AsString = "TNB Bill for Feb 2022";
       $lDetail->FindField("Description")->AsString = "Sales Item BOM";
  $lDetail->FindField("UOM")->AsString = "UNIT";
      $lDetail->FindField("Qty")->AsFloat = 2;
       $lDetail->FindField("Tax")->AsString = "";
       $lDetail->FindField("Tax")->AsString = "";
       $lDetail->FindField("TaxRate")->AsString = "";
       $lDetail->FindField("TaxRate")->AsString = "";
       $lDetail->FindField("TaxInclusive")->value = 0;
       $lDetail->FindField("TaxInclusive")->value = 0;
       $lDetail->FindField("Amount")->AsFloat = 68.00;
      $lDetail->FindField("UnitPrice")->AsFloat = 150;
       $lDetail->FindField("Amount")->AsFloat = 300;
       $lDetail->FindField("TaxAmt")->AsFloat = 0;
       $lDetail->FindField("TaxAmt")->AsFloat = 0;
       $lDetail->Post();
       $lDetail->Post();
Line 4,553: Line 5,044:
}
}


function DelData(){
function PostDelIV(){
global $ComServer;
global $ComServer;
$BizObject = $ComServer->BizObjects->Find("GL_PV");
$BizObject = $ComServer->BizObjects->Find("SL_IV");
     $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
     $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
     #Find PV Number
     #Find IV Number
     $lDocNo = "--PV Test--";
     $lDocNo = "--IV Test--";
     $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
     $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
Line 4,579: Line 5,070:
         CheckLogin();
         CheckLogin();
         echo date("d M Y h:i:s A")." - Begin Posting<br>";
         echo date("d M Y h:i:s A")." - Begin Posting<br>";
         PostData();
         PostDataIV();
     }
     }
     finally
     finally
Line 4,595: Line 5,086:
         CheckLogin();
         CheckLogin();
         echo date("d M Y h:i:s A")." - Begin Delete<br>";
         echo date("d M Y h:i:s A")." - Begin Delete<br>";
         DelData();
         PostDelIV();
     }
     }
     finally
     finally
Line 4,608: Line 5,099:
     <form method="post">           
     <form method="post">           
         <input type="submit" name="BtnPost"
         <input type="submit" name="BtnPost"
                 value="Post GL PV"/>  
                 value="Post Sales IV"/>  
         <input type="submit" name="BtnDel"
         <input type="submit" name="BtnDel"
                 value="Delete PV"/>
                 value="Post Delete IV"/>
     </form>  
     </form>  
</body>
</body>
Line 4,618: Line 5,109:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-GL_JE-Add, Edit & Delete====
====GL_PV-Add, Edit & Delete====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Insert, Edit & Delete Invoice Script  
! Insert, Edit & Delete Invoice Script  
Line 4,645: Line 5,136:
     }
     }
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                       "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                       "D:\Happy\DB\Default.DCF", #"C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                       "ACC-0015.FDB"); #Database Name
                       "ACC-0015.FDB"); #Database Name
      
      
Line 4,653: Line 5,144:
global $ComServer;
global $ComServer;
$BizObject = $ComServer->BizObjects->Find("GL_JE");
$BizObject = $ComServer->BizObjects->Find("GL_PV");
     $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
     $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
     $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
     $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
     #Find PV Number
     #Find PV Number
     $lDocNo = "--JE Test--";
     $lDocNo = "--PV Test--";
     $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
     $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
Line 4,669: Line 5,160:
    $lMain->FindField("DocDate")->value = "02/20/2022"; #MM/DD/YYYY
    $lMain->FindField("DocDate")->value = "02/20/2022"; #MM/DD/YYYY
         $lMain->FindField("PostDate")->value = "02/20/2022"; #MM/DD/YYYY
         $lMain->FindField("PostDate")->value = "02/20/2022"; #MM/DD/YYYY
         $lMain->FindField("Description")->AsString = "Credit Card Charges - Edited";
         $lMain->FindField("Description")->AsString = "Tenaga Malaysia - Edited";
$lMain->FindField("PaymentMethod")->AsString = "310-001"; #GL Bank/Cash account code
$lMain->FindField("CHEQUENUMBER")->AsString = "MBB 123456"; #Optional
$lMain->FindField("Cancelled")->AsString = "F";
$lMain->FindField("Cancelled")->AsString = "F";


Line 4,680: Line 5,173:
}
}
         $lDetail->Append();
         $lDetail->Append();
         $lDetail->FindField("Code")->AsString = "902-000";
         $lDetail->FindField("Code")->AsString = "907-000";
         $lDetail->FindField("Description")->AsString = "MBB Credit Card Charges - Edited";
         $lDetail->FindField("Description")->AsString = "TNB Bill for Feb 2022 - Edited";
         $lDetail->FindField("Tax")->AsString = "";
         $lDetail->FindField("Tax")->AsString = "";
         $lDetail->FindField("TaxRate")->AsString = "";
         $lDetail->FindField("TaxRate")->AsString = "";
         $lDetail->FindField("TaxInclusive")->value = 0;
         $lDetail->FindField("TaxInclusive")->value = 0;
         $lDetail->FindField("LocalDR")->AsFloat = 78.88;
         $lDetail->FindField("Amount")->AsFloat = 168.80;
$lDetail->FindField("DR")->AsFloat = 78.88; #If Wanted DR <> LocalDR
         $lDetail->FindField("TaxAmt")->AsFloat = 0;
        $lDetail->FindField("LocalTaxAmt")->AsFloat = 0;
         $lDetail->Post();
        $lDetail->Post();
        $lDetail->Append();
        $lDetail->FindField("Code")->AsString = "310-001";
        $lDetail->FindField("Description")->AsString = "MBB Credit Card Charges - Edited";
        $lDetail->FindField("Tax")->AsString = "";
        $lDetail->FindField("TaxRate")->AsString = "";
        $lDetail->FindField("TaxInclusive")->value = 0;
        $lDetail->FindField("LocalCR")->AsFloat = 78.88;
$lDetail->FindField("CR")->AsFloat = 78.88; #If Wanted CR <> LocalCR
         $lDetail->FindField("LocalTaxAmt")->AsFloat = 0;
         $lDetail->Post();
} else {
} else {
       echo "New JE<br>";
       echo "New PV<br>";
  $BizObject->New();
  $BizObject->New();
       $lMain->FindField("DocKey")->value = -1;
       $lMain->FindField("DocKey")->value = -1;
Line 4,707: Line 5,188:
  $lMain->FindField("DocDate")->value = "02/18/2022"; #MM/DD/YYYY
  $lMain->FindField("DocDate")->value = "02/18/2022"; #MM/DD/YYYY
       $lMain->FindField("PostDate")->value = "02/18/2022"; #MM/DD/YYYY
       $lMain->FindField("PostDate")->value = "02/18/2022"; #MM/DD/YYYY
       $lMain->FindField("Description")->AsString = "Credit Card Charges";
       $lMain->FindField("Description")->AsString = "Tenaga Malaysia";
  $lMain->FindField("PaymentMethod")->AsString = "310-001"; #GL Bank/Cash account code
  $lMain->FindField("CHEQUENUMBER")->AsString = "MBB 123456"; #Optional
  $lMain->FindField("Cancelled")->AsString = "F";
  $lMain->FindField("Cancelled")->AsString = "F";
       $lDetail->Append();
       $lDetail->Append();
       $lDetail->FindField("Code")->AsString = "902-000";
       $lDetail->FindField("Code")->AsString = "907-000"; #GL Account
       $lDetail->FindField("Description")->AsString = "MBB Credit Card Charges";
       $lDetail->FindField("Description")->AsString = "TNB Bill for Jan 2022";
       $lDetail->FindField("Tax")->AsString = "";
       $lDetail->FindField("Tax")->AsString = "";
       $lDetail->FindField("TaxRate")->AsString = "";
       $lDetail->FindField("TaxRate")->AsString = "";
       $lDetail->FindField("TaxInclusive")->value = 0;
       $lDetail->FindField("TaxInclusive")->value = 0;
       $lDetail->FindField("LocalDR")->AsFloat = 88.88;
       $lDetail->FindField("Amount")->AsFloat = 100.80;
  $lDetail->FindField("DR")->AsFloat = 88.88; #If Wanted DR <> LocalDR
       $lDetail->FindField("TaxAmt")->AsFloat = 0;
       $lDetail->FindField("LocalTaxAmt")->AsFloat = 0;
       $lDetail->Post();
       $lDetail->Post();
 
       $lDetail->Append();
       $lDetail->Append();
       $lDetail->FindField("Code")->AsString = "310-001";
       $lDetail->FindField("Code")->AsString = "907-000";
       $lDetail->FindField("Description")->AsString = "MBB Credit Card Charges";
       $lDetail->FindField("Description")->AsString = "TNB Bill for Feb 2022";
       $lDetail->FindField("Tax")->AsString = "";
       $lDetail->FindField("Tax")->AsString = "";
       $lDetail->FindField("TaxRate")->AsString = "";
       $lDetail->FindField("TaxRate")->AsString = "";
       $lDetail->FindField("TaxInclusive")->value = 0;
       $lDetail->FindField("TaxInclusive")->value = 0;
       $lDetail->FindField("LocalCR")->AsFloat = 88.88;
       $lDetail->FindField("Amount")->AsFloat = 68.00;
  $lDetail->FindField("CR")->AsFloat = 88.88; #If Wanted CR <> LocalCR
       $lDetail->FindField("TaxAmt")->AsFloat = 0;
       $lDetail->FindField("LocalTaxAmt")->AsFloat = 0;
       $lDetail->Post();
       $lDetail->Post();
}
}
Line 4,741: Line 5,222:
global $ComServer;
global $ComServer;
$BizObject = $ComServer->BizObjects->Find("GL_JE");
$BizObject = $ComServer->BizObjects->Find("GL_PV");
     $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
     $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
     #Find JE Number
     #Find PV Number
     $lDocNo = "--JE Test--";
     $lDocNo = "--PV Test--";
     $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
     $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
Line 4,793: Line 5,274:
     <form method="post">           
     <form method="post">           
         <input type="submit" name="BtnPost"
         <input type="submit" name="BtnPost"
                 value="Post GL JE"/>  
                 value="Post GL PV"/>  
         <input type="submit" name="BtnDel"
         <input type="submit" name="BtnDel"
                 value="Delete JE"/>
                 value="Delete PV"/>
     </form>  
     </form>  
</body>
</body>
Line 4,803: Line 5,284:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Get Outstanding SO List====
====GL_JE-Add, Edit & Delete====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Get Outstanding SO List Script  
! Insert, Edit & Delete Invoice Script  
|-
|-
|  
|  
Line 4,816: Line 5,297:


<?php
<?php
echo "Updated 09 Jun 2022<br>";
echo "Updated 15 Mar 2022<br>";
$ComServer = null;
$ComServer = null;


Line 4,835: Line 5,316:
}
}


function GetData(){
function PostData(){
global $ComServer;
global $ComServer;
    $lSQL = "SELECT Dockey, DocNo,Code, CompanyName, Seq, DtlKey, ItemCode, Qty, UOM, UnitPrice, Disc, Amount,
$BizObject = $ComServer->BizObjects->Find("GL_JE");
            COALESCE(Sum(XFQty),0) XFQty, COALESCE((Qty-Sum(XFQty)), Qty) OSQty FROM (
    $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
            SELECT A.Dockey, A.DocNo, A.Code, A.CompanyName,
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
            B.DtlKey, B.Seq, B.ItemCode, B.Qty, B.UOM, B.UnitPrice, B.Disc, B.Amount,
            C.Qty XFQty FROM SL_SO A
    #Find JE Number
            INNER JOIN SL_SODTL B ON (A.DOCKEY=B.DOCKEY)
    $lDocNo = "--JE Test--";
            LEFT JOIN ST_XTRANS C ON (A.DOCKEY=C.FROMDOCKEY AND B.DTLKEY=C.FROMDTLKEY
    $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
                                      AND C.FROMDOCTYPE='SO')
            WHERE A.Cancelled='F')
            GROUP BY Dockey, DocNo, Code, CompanyName, Seq, Dtlkey, ItemCode, Qty, UOM, UnitPrice, Disc, Amount
            HAVING COALESCE((Qty-Sum(XFQty)), Qty) >0
";
$lDataSet = $ComServer->DBManager->NewDataSet($lSQL);
if ($lDocKey != null){
        echo "Dockey = ".$lDocKey."<br>";
$BizObject->Params->Find("DocKey")->AsString = $lDocKey;
$BizObject->Open();
        $BizObject->Edit();
        $lMain->Edit();
    $lMain->FindField("DocDate")->value = "02/20/2022"; #MM/DD/YYYY
        $lMain->FindField("PostDate")->value = "02/20/2022"; #MM/DD/YYYY
        $lMain->FindField("Description")->AsString = "Credit Card Charges - Edited";
$lMain->FindField("Cancelled")->AsString = "F";


    if ($lDataSet->RecordCount > 0) {
$r = $lDetail->RecordCount();
$lDataSet->First();
$x = 1;
$fc = $lDataSet->Fields->Count-1;
while ($x <= $r ){
echo "<table>";
$lDetail->First();
echo "<tr>";
            $lDetail->Delete();
for ($x = 0; $x <= $fc; $x++) {
$x++;
#Insert Header
echo "<td>".$lDataSet->Fields->Items($x)->FieldName()."</td>";  
}
}
echo "</tr>";
        $lDetail->Append();
        $lDetail->FindField("Code")->AsString = "902-000";
#Looping Dataset
        $lDetail->FindField("Description")->AsString = "MBB Credit Card Charges - Edited";
while (! $lDataSet->Eof()){
        $lDetail->FindField("Tax")->AsString = "";
echo "<tr>";
        $lDetail->FindField("TaxRate")->AsString = "";
    for ($x = 0; $x <= $fc; $x++) {
        $lDetail->FindField("TaxInclusive")->value = 0;
$lFN = $lDataSet->Fields->Items($x)->FieldName();
        $lDetail->FindField("LocalDR")->AsFloat = 78.88;
    echo "<td>".$lDataSet->FindField($lFN)->AsString()."</td>";  
$lDetail->FindField("DR")->AsFloat = 78.88; #If Wanted DR <> LocalDR
    }
        $lDetail->FindField("LocalTaxAmt")->AsFloat = 0;
    echo "</tr>";
        $lDetail->Post();
$lDataSet->Next();
}
        $lDetail->Append();
echo "</table>"."<br>";
        $lDetail->FindField("Code")->AsString = "310-001";
}else {
        $lDetail->FindField("Description")->AsString = "MBB Credit Card Charges - Edited";
    echo "Record Not Found";
        $lDetail->FindField("Tax")->AsString = "";
    }
        $lDetail->FindField("TaxRate")->AsString = "";
}
        $lDetail->FindField("TaxInclusive")->value = 0;
 
        $lDetail->FindField("LocalCR")->AsFloat = 78.88;
if (isset($_POST['BtnData']))
$lDetail->FindField("CR")->AsFloat = 78.88; #If Wanted CR <> LocalCR
{
        $lDetail->FindField("LocalTaxAmt")->AsFloat = 0;
    try
        $lDetail->Post();
    {
} else {
        CheckLogin();
      echo "New JE<br>";
        echo date("d M Y h:i:s A")." - Get Data<br>";
  $BizObject->New();
        GetData();
      $lMain->FindField("DocKey")->value = -1;
echo date("d M Y h:i:s A")." - Done<br>";
      $lMain->FindField("DocNo")->AsString = $lDocNo;
     }
  $lMain->FindField("DocDate")->value = "02/18/2022"; #MM/DD/YYYY
    finally
      $lMain->FindField("PostDate")->value = "02/18/2022"; #MM/DD/YYYY
    {
      $lMain->FindField("Description")->AsString = "Credit Card Charges";
        $ComServer->Logout();
  $lMain->FindField("Cancelled")->AsString = "F";
        #free the object
        $ComServer = null;
      $lDetail->Append();
    }
      $lDetail->FindField("Code")->AsString = "902-000";
}
      $lDetail->FindField("Description")->AsString = "MBB Credit Card Charges";
      $lDetail->FindField("Tax")->AsString = "";
      $lDetail->FindField("TaxRate")->AsString = "";
      $lDetail->FindField("TaxInclusive")->value = 0;
      $lDetail->FindField("LocalDR")->AsFloat = 88.88;
  $lDetail->FindField("DR")->AsFloat = 88.88; #If Wanted DR <> LocalDR
      $lDetail->FindField("LocalTaxAmt")->AsFloat = 0;
      $lDetail->Post();
      $lDetail->Append();
      $lDetail->FindField("Code")->AsString = "310-001";
      $lDetail->FindField("Description")->AsString = "MBB Credit Card Charges";
      $lDetail->FindField("Tax")->AsString = "";
      $lDetail->FindField("TaxRate")->AsString = "";
      $lDetail->FindField("TaxInclusive")->value = 0;
      $lDetail->FindField("LocalCR")->AsFloat = 88.88;
  $lDetail->FindField("CR")->AsFloat = 88.88; #If Wanted CR <> LocalCR
      $lDetail->FindField("LocalTaxAmt")->AsFloat = 0;
      $lDetail->Post();
}
    $BizObject->Save();
echo date("d M Y h:i:s A")." - Posting Done<br>";
     $BizObject->Close();
}


?>  
function DelData(){
     <form method="post">         
global $ComServer;
        <input type="submit" name="BtnData"
                value="Get Outstanding SO List"/>  
$BizObject = $ComServer->BizObjects->Find("GL_JE");
    </form>  
     $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
</body>
</html>
    #Find JE Number
</syntaxhighlight>
    $lDocNo = "--JE Test--";
|}
    $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
<div style="float: right;">  [[#top|[top]]]</div>
<br>
if ($lDocKey != null){
 
        echo "Dockey = ".$lDocKey."<br>";
===VB Script===
$BizObject->Params->Find("DocKey")->AsString = $lDocKey;
====Example-Get Company Profile====
$BizObject->Open();
{| class="mw-collapsible mw-collapsed wikitable"
        $BizObject->Delete();
! Company Profile Script 
echo date("d M Y h:i:s A")." - Record deleted<br>";
|-
} else {
|
echo date("d M Y h:i:s A")." - Document Not Found<br>";
<syntaxhighlight lang="vb">
}
'Copy below script & paste to notepad & name it as eg Common.Agent.RO.vbs
}
Call GetCoInfo
if (isset($_POST['BtnPost']))
{
Function CreateSQLAccServer
    try
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
    {
End Function
        CheckLogin();
        echo date("d M Y h:i:s A")." - Begin Posting<br>";
Function GetCoInfo
        PostData();
Dim ComServer, RptObject, lDataSet
    }
  'Step 1: Create Com Server object
    finally
  Set ComServer = CreateSQLAccServer 'Create Com Server
    {
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
        $ComServer->Logout();
    ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"  
        #free the object
  END IF
        $ComServer = null;
    }
  'Step 2: Find and Create the Report Objects
}
  Set RptObject = ComServer.RptObjects.Find("Common.Agent.RO")  
  'Step 3: Perform Report calculation
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsProfile")


  MsgBox "Count " & lDataSet.RecordCount
if (isset($_POST['BtnDel']))
{
  'Step 5 Retrieve the output
    try
  lDataSet.First
    {
  While (not lDataSet.eof)
        CheckLogin();
MsgBox "Company Name : " & lDataSet.FindField("CompanyName").AsString
        echo date("d M Y h:i:s A")." - Begin Delete<br>";
        DelData();
MsgBox "Remark : " & lDataSet.FindField("Remark").AsString
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}


MsgBox "ROC No : " & lDataSet.FindField("RegisterNo").AsString
?>
 
    <form method="post">         
MsgBox "GST No : " & lDataSet.FindField("GSTNo").AsString
        <input type="submit" name="BtnPost"
                value="Post GL JE"/>
MsgBox "Address 1 : " & lDataSet.FindField("Address1").AsString
        <input type="submit" name="BtnDel"
                value="Delete JE"/>
MsgBox "Address 2 : " & lDataSet.FindField("Address2").AsString
    </form>
</body>
MsgBox "Address 3 : " & lDataSet.FindField("Address3").AsString
</html>
MsgBox "Address 4 : " & lDataSet.FindField("Address4").AsString
MsgBox "Attention : " & lDataSet.FindField("Attention").AsString
MsgBox "Phone : " & lDataSet.FindField("Phone1").AsString
MsgBox "Fax : " & lDataSet.FindField("Fax1").AsString
MsgBox "E-Mail : " & lDataSet.FindField("EMail").AsString
lDataSet.Next
  Wend
 
  'Step 6 : Logout after done 
  ComServer.Logout   
End Function
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Complete Post====
====Get Outstanding SO List====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! SL_CS, AR_PM, SL_CN & AR_CN Script
! Get Outstanding SO List Script  
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="PHP">
'Updated 13 Sep 2018
<!DOCTYPE html>
'Copy below script & paste to notepad & name it as eg SL_CS.vbs
<html>
'This will doing following posting
<body>
'01. Cash Sales
'02. Sales Credit Note
'03. Customer Payment With Knock off
'04. Edit Credit Note Posted in Step 02 & Knock Off
Call CheckLogin
Call InsertData


Dim ComServer
<h1>SQL Acc SDK in PHP page</h1>


Function CreateSQLAccServer
<?php
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
echo "Updated 09 Jun 2022<br>";
End Function
$ComServer = null;


function CheckLogin
function CheckLogin()
  'Step 1: Create Com Server object
{
  Set ComServer = CreateSQLAccServer 'Create Com Server
    global $ComServer;
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
     $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
    $status = $ComServer->IsLogin();
                'UserName, Password, DCF full path, Database filename
  END IF
End Function


Function InsertData
    if ($status == true)
Dim BizObject, lMain, lDetail, lDate
    {
  'Step 2: Find and Create the Biz Objects
        $ComServer->Logout();
  Set BizObject = ComServer.BizObjects.Find("SL_CS")  
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0015.FDB"); #Database Name
   
}
 
function GetData(){
global $ComServer;
    $lSQL = "SELECT Dockey, DocNo,Code, CompanyName, Seq, DtlKey, ItemCode, Qty, UOM, UnitPrice, Disc, Amount,
            COALESCE(Sum(XFQty),0) XFQty, COALESCE((Qty-Sum(XFQty)), Qty) OSQty FROM (
            SELECT A.Dockey, A.DocNo, A.Code, A.CompanyName,
            B.DtlKey, B.Seq, B.ItemCode, B.Qty, B.UOM, B.UnitPrice, B.Disc, B.Amount,
            C.Qty XFQty FROM SL_SO A
            INNER JOIN SL_SODTL B ON (A.DOCKEY=B.DOCKEY)
            LEFT JOIN ST_XTRANS C ON (A.DOCKEY=C.FROMDOCKEY AND B.DTLKEY=C.FROMDTLKEY
                                      AND C.FROMDOCTYPE='SO')
            WHERE A.Cancelled='F')
            GROUP BY Dockey, DocNo, Code, CompanyName, Seq, Dtlkey, ItemCode, Qty, UOM, UnitPrice, Disc, Amount
            HAVING COALESCE((Qty-Sum(XFQty)), Qty) >0
";
$lDataSet = $ComServer->DBManager->NewDataSet($lSQL);


  'Step 3: Set Dataset
    if ($lDataSet->RecordCount > 0) {
  Set lMain  = BizObject.DataSets.Find("MainDataSet") 'lMain contains master data
$lDataSet->First();
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data 
$fc = $lDataSet->Fields->Count-1;
 
echo "<table>";
  'Begin Looping yr data
echo "<tr>";
  'Step 4 : Insert Data - Master
for ($x = 0; $x <= $fc; $x++) {
  lDate = CDate("January 1, 2017")
#Insert Header
  BizObject.New
echo "<td>".$lDataSet->Fields->Items($x)->FieldName()."</td>";
  lMain.FindField("DocKey").value        = -1
}
  lMain.FindField("DocNo").AsString      = "--IV Test--"
echo "</tr>";
  lMain.FindField("DocDate").value        = lDate
  lMain.FindField("PostDate").value      = lDate
#Looping Dataset
  lMain.FindField("Code").AsString        = "300-C0001" 'Customer Account
while (! $lDataSet->Eof()){
  lMain.FindField("CompanyName").AsString = "Cash Sales"
echo "<tr>";
  lMain.FindField("Address1").AsString    = "" 'Optional
    for ($x = 0; $x <= $fc; $x++) {
  lMain.FindField("Address2").AsString    = "" 'Optional
$lFN = $lDataSet->Fields->Items($x)->FieldName();
  lMain.FindField("Address3").AsString    = "" 'Optional
    echo "<td>".$lDataSet->FindField($lFN)->AsString()."</td>";
  lMain.FindField("Address4").AsString    = "" 'Optional
    }
  lMain.FindField("Phone1").AsString      = "" 'Optional
    echo "</tr>";
  lMain.FindField("Description").AsString = "Sales"
$lDataSet->Next();
   
}
  'Step 5: Insert Data - Detail
echo "</table>"."<br>";
  'For Tax Inclusive = True with override Tax Amount
}else {
  lDetail.Append
    echo "Record Not Found";
  lDetail.FindField("DtlKey").value        = -1
    }
  lDetail.FindField("DocKey").value        = -1
}
  lDetail.FindField("Seq").value            = 1
  lDetail.FindField("Account").AsString    = "500-000" 'Sales Account
  lDetail.FindField("Description").AsString = "Sales Item A"
  lDetail.FindField("Qty").AsFloat          = 1
  lDetail.FindField("Tax").AsString        = "SR"
  lDetail.FindField("TaxRate").AsString    = "6%"
  lDetail.FindField("TaxInclusive").value  = 0
  lDetail.FindField("UnitPrice").AsFloat    = 435
  lDetail.FindField("Amount").AsFloat      = 410.37 'Exclding GST Amt
  lDetail.FindField("TaxAmt").AsFloat      = 24.63
 
  lDetail.DisableControls
  lDetail.FindField("TaxInclusive").value  = 1
  lDetail.EnableControls
 
  lDetail.Post
 
  'For Tax Inclusive = False with override Tax Amount
  lDetail.Append
  lDetail.FindField("DtlKey").value        = -1
  lDetail.FindField("DocKey").value        = -1
  lDetail.FindField("Seq").value            = 2
  lDetail.FindField("Account").AsString    = "500-000"
  lDetail.FindField("Description").AsString = "Sales Item B"
  lDetail.FindField("Qty").AsFloat          = 1
  lDetail.FindField("Tax").AsString        = "SR"
  lDetail.FindField("TaxRate").AsString    = "6%"
  lDetail.FindField("TaxInclusive").value  = 0
  lDetail.FindField("UnitPrice").AsFloat    = 94.43
  lDetail.FindField("Amount").AsFloat      = 94.43
  lDetail.FindField("TaxAmt").AsFloat      = 5.66
  lDetail.Post


  'For With Item Code
if (isset($_POST['BtnData']))
  lDetail.Append
{
  lDetail.FindField("DtlKey").value        = -1
    try
  lDetail.FindField("DocKey").value         = -1
    {
  lDetail.FindField("Seq").value            = 3
         CheckLogin();
  lDetail.FindField("ItemCode").AsString    = "ANT"
        echo date("d M Y h:i:s A")." - Get Data<br>";
  lDetail.FindField("Description").AsString = "Sales Item B"
        GetData();
  'lDetail.FindField("Account").AsString    = "500-000" 'If you wanted override the Sales Account Code
echo date("d M Y h:i:s A")." - Done<br>";
  lDetail.FindField("Qty").AsFloat          = 2
    }
  lDetail.FindField("UOM").AsString         = "UNIT"
    finally
  'lDetail.FindField("DISC").AsString        = "5%+3" 'Optional (eg 5% plus 3 Discount)
    {
  lDetail.FindField("Tax").AsString        = "SR"
        $ComServer->Logout();
  lDetail.FindField("TaxRate").AsString     = "6%"
        #free the object
  lDetail.FindField("TaxInclusive").value  = 0
        $ComServer = null;
  lDetail.FindField("UnitPrice").AsFloat    = 100 
    }
  lDetail.FindField("Amount").AsFloat      = 200
}
  lDetail.FindField("TaxAmt").AsFloat      = 12
 
  lDetail.Post
?>
    <form method="post">         
         <input type="submit" name="BtnData"
                value="Get Outstanding SO List"/>
     </form>
</body>
</html>
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>
====Get Stock Item Picture====
{| class="mw-collapsible mw-collapsed wikitable"
! Get Stock Item Picture Script
|-
|
<syntaxhighlight lang="PHP">
<!DOCTYPE html>
<html>
<body>
 
<h1>SQL Acc SDK in PHP page</h1>


  'Step 6: Save Document
<?php
  BizObject.Save
echo "Updated 14 Sep 2022<br>";
  BizObject.Close
 
  'Step 7: Payment
  Call InsertARPM
 
  'Step 8: Credit Note
  Call InsertSLCN
  'End Looping yr data


  'Step 9 : Logout after done 
$ComServer = null;
  'ComServer.Logout
 
  MsgBox "Done" 
End Function


Function InsertARPM
function CheckLogin()
Dim BizObject, lMain, lDetail, lDate, v(1)
{
  'Step 2: Find and Create the Biz Objects
    global $ComServer;
  Set BizObject = ComServer.BizObjects.Find("AR_PM")  
    $ComServer = new COM("SQLAcc.BizApp", null, CP_UTF8) or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();
  'Step 3: Set Dataset
 
  Set lMain = BizObject.DataSets.Find("MainDataSet")   'lMain contains master data
     if ($status == true)
  Set lDetail = BizObject.DataSets.Find("cdsKnockOff") 'lDetail contains detail data 
     {
 
        $ComServer->Logout();
  'Step 4 : Posting
    }
     lDate = CDate("January 23, 2017")
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
     BizObject.New
                      "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
    lMain.FindField("DOCKEY").Value          = -1
                      "ACC-0082.FDB"); #Database Name
     lMain.FindField("DocNo").AsString        = "--PM Test--"  
      
    lMain.FindField("CODE").AsString          = "300-C0001" 'Customer Account
}
    lMain.FindField("DocDate").Value          = lDate
 
     lMain.FindField("PostDate").Value        = lDate
function GetData(){
     lMain.FindField("Description").AsString  = "Payment for A/c"
     global $ComServer;
     lMain.FindField("PaymentMethod").AsString = "320-000" 'Bank or Cash Account
lMain.FindField("ChequeNumber").AsString  = ""
     $lSQL = "SELECT Picture FROM ST_ITEM
lMain.FindField("BankCharge").AsFloat    = 0
            WHERE Code='ANT' ";
     lMain.FindField("DocAmt").AsFloat        = 200.00
    lMain.FindField("Cancelled").AsString    = "F"
    $lDataSet = $ComServer->DBManager->NewDataSet($lSQL);
  'Step 5: Knock Off IV
 
    lIVNO = "--IV Test--"
     if ($lDataSet->RecordCount > 0) {
    v(0) = "IV"
$lDataSet->First();
    v(1) = lIVNO
$raw = $lDataSet->FindField('Picture')->Value();
    if (lDetail.Locate("DocType;DocNo", v, false, false)) then
        $b = [];
      lDetail.Edit
        foreach($raw as $p) {
      lDetail.FindField("KOAmt").AsFloat    = 147.09 'Partial Knock off
            array_push($b, chr($p));
      lDetail.FindField("KnockOff").AsString = "T"
        }
      lDetail.Post
 
End IF 
echo '<img src=data:image/*;base64,'.base64_encode(implode($b)).' alt="My Picture" style="width:128px;height:128px">';
  'Step 6: Save Document
    BizObject.Save
    BizObject.Close
End Function


Function InsertSLCN
}else {
Dim BizObject, lMain, lDetail, lDate
    echo "Record Not Found";
  'Step 2: Find and Create the Biz Objects
    }
  Set BizObject = ComServer.BizObjects.Find("SL_CN")
}


  'Step 3: Set Dataset
if (isset($_POST['BtnData']))
  Set lMain  = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
{
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data 
    try
 
    {
  'Step 4 : Insert Data - Master
        CheckLogin();
  lDate = CDate("January 24, 2017")
        GetData();
  BizObject.New
echo "<br>";
  lMain.FindField("DocKey").value        = -1
        echo date("d M Y h:i:s A")." - Done";
  lMain.FindField("DocNo").AsString      = "--CN Test--"
    }
  lMain.FindField("DocDate").value        = lDate
     finally
  lMain.FindField("PostDate").value      = lDate
     {
  lMain.FindField("Code").AsString        = "300-C0001"
        $ComServer->Logout();
  lMain.FindField("CompanyName").AsString = "Cash Sales"
        #free the object
  lMain.FindField("Address1").AsString    = ""
        $ComServer = null;
  lMain.FindField("Address2").AsString    = ""
     }
  lMain.FindField("Address3").AsString    = ""
}
  lMain.FindField("Address4").AsString    = ""
  lMain.FindField("Phone1").AsString      = "" 
  lMain.FindField("Description").AsString = "Sales Returned"
      
  'For With Item Code
  lDetail.Append
  lDetail.FindField("DtlKey").value          = -1
  lDetail.FindField("DocKey").value          = -1
  lDetail.FindField("ItemCode").AsString     = "ANT"
  lDetail.FindField("Description").AsString  = "Sales Item B"
  lDetail.FindField("Description2").AsString = "Product Spoil" 'Reason
  lDetail.FindField("Remark1").AsString      = "--IV Test--"  'Invoice No
  lDetail.FindField("Remark2").AsString      = "01 Jan 2017"  'Invoice Date
  lDetail.FindField("Qty").AsFloat          = 1
  lDetail.FindField("Tax").AsString          = "SR"
  lDetail.FindField("TaxRate").AsString      = "6%"
  lDetail.FindField("TaxInclusive").value    = 0
  lDetail.FindField("UnitPrice").AsFloat     = 100
  lDetail.FindField("Amount").AsFloat        = 100
  lDetail.FindField("TaxAmt").AsFloat        = 6 
  lDetail.Post


  'Step 6: Save Document
?>
  BizObject.Save
    <form method="post">         
  BizObject.Close
        <input type="submit" name="BtnData"
 
                value="Get Item Picture"/>
  'Step 7: Knock Off Invoice
    </form>
   Call KnockIV
</body>
End Function
</html>
</syntaxhighlight>
|}
<div style="float: right;">   [[#top|[top]]]</div>


Function KnockIV
====Customer.Aging.RO====
Dim BizObject, lMain, lDetail, lDate, v(1)
{| class="mw-collapsible mw-collapsed wikitable"
  'Step 2: Find and Create the Biz Objects
! Customer.Aging.RO Script
  Set BizObject = ComServer.BizObjects.Find("AR_CN")
|-
|
  'Step 3: Set Dataset
<syntaxhighlight lang="PHP">
  Set lMain  = BizObject.DataSets.Find("MainDataSet") 'lMain contains master data
<!DOCTYPE html>
  Set lDetail = BizObject.DataSets.Find("cdsKnockOff") 'lDetail contains Knock off data 
<html>
 
<head>
  'Step 4 : Find CN Number
<link rel="stylesheet" type="text/css" href="css/Grid.css" />
  lDocNo = "--CN Test--"
</head>
  lDocKey = BizObject.FindKeyByRef("DocNo", lDocNo)
<body>
  BizObject.Params.Find("DocKey").Value = lDocKey
 
  If not IsNull(lDocKey) Then
    BizObject.Open
    BizObject.Edit
    lMain.Edit
  'Step 5: Knock Off IV
    lIVNO = "--IV Test--"
    v(0) = "IV"
    v(1) = lIVNO
    if (lDetail.Locate("DocType;DocNo", v, false, false)) then
      lDetail.Edit
      lDetail.FindField("KOAmt").AsFloat    = 106 'Fully Knock off
      lDetail.FindField("KnockOff").AsString = "T"
      lDetail.Post
End IF   
  'Step 6: Save Document
    BizObject.Save
    BizObject.Close
  END IF
End Function
</syntaxhighlight>
|}


<div style="float: right;">   [[#top|[top]]]</div>
<h1>SQL Acc SDK in PHP page</h1>


====Example-AR_IV====
<?php
{| class="mw-collapsible mw-collapsed wikitable"
echo "Updated 26 Sep 2022<br>";
! AR_IV Script 
|-
|
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg AR_IV.vbs
Call InsertARIV


Function CreateSQLAccServer
$ComServer = null;
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function


Function InsertARIV
function CheckLogin()
Dim ComServer, BizObject, lDataSet, lDataSet2, lDate
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp", null, CP_UTF8) or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();


  'Step 1: Create Com Server object
    if ($status == true)
  Set ComServer = CreateSQLAccServer 'Create Com Server
    {
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
        #$ComServer->Logout();
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"  
    }
  END IF
     $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\eStream\SQLAccounting\Share\Default.DCF", #DCF file
                      "ACC-0082.FDB"); #Database Name
   
}
 
function SetGrid($DataSet){
echo "<table>";
echo "<tr>";
    $DataSet->First();
$fc = $DataSet->Fields->Count-1;
for ($x = 0; $x <= $fc; $x++) {
#Insert Header
echo "<td>".$DataSet->Fields->Items($x)->FieldName()."</td>";
}
echo "</tr>";
#Looping Dataset
while (! $DataSet->Eof()){
echo "<tr>";
    for ($x = 0; $x <= $fc; $x++) {
$lFN = $DataSet->Fields->Items($x)->FieldName();
    echo "<td>".$DataSet->FindField($lFN)->AsString()."</td>";
    }
    echo "</tr>";
$DataSet->Next();
}
    echo "</table>"."<br>";
}
 
function GetData(){
global $ComServer;
    $lSQL = '<?xml version="1.0" standalone="yes"?>  <DATAPACKET Version="2.0"><METADATA><FIELDS>
        <FIELD attrname="ColumnNo" fieldtype="i4" required="true"/><FIELD attrname="ColumnType" fieldtype="string" WIDTH="1"/>
            <FIELD attrname="Param1" fieldtype="i4" required="true"/><FIELD attrname="Param2" fieldtype="i4" required="true"/>
            <FIELD attrname="IsLocal" fieldtype="boolean"/><FIELD attrname="HeaderScript" fieldtype="bin.hex" SUBTYPE="Text" WIDTH="1"/>
            </FIELDS><PARAMS/></METADATA><ROWDATA><ROW ColumnNo="0" ColumnType="" Param1="0" Param2="0" IsLocal="FALSE"/>
            <ROW ColumnNo="1" ColumnType="A" Param1="0" Param2="0" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;Current Mth&apos;&#013;end;"/>
            <ROW ColumnNo="2" ColumnType="A" Param1="-1" Param2="-1" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;1 Months&apos;&#013;end;"/>
            <ROW ColumnNo="3" ColumnType="A" Param1="-2" Param2="-2" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;2 Months&apos;&#013;end;"/>
            <ROW ColumnNo="4" ColumnType="A" Param1="-3" Param2="-3" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;3 Months&apos;&#013;end;"/>
            <ROW ColumnNo="5" ColumnType="A" Param1="-4" Param2="-4" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;4 Months&apos;&#013;end;"/>
            <ROW ColumnNo="6" ColumnType="B" Param1="-999999" Param2="-5" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;5 Month &amp; above&apos;&#013;end;"/>
            </ROWDATA></DATAPACKET>';
$lRptVar = $ComServer->RptObjects->Find('Customer.Aging.RO');
$lRptVar->Params->Find('ActualGroupBy')->AsString = 'Code;CompanyName'; #Fixed
# $lRptVar->Params->Find('AgentData')->AsBlob              = ; #Not use if AllAgent is True
    $lRptVar->Params->Find('AgingData')->AsString          = $lSQL;
    $lRptVar->Params->Find('AgingDate')->AsDate            = '23 Sep 2022';
    $lRptVar->Params->Find('AgingOn')->AsString            = 'I'; #Fixed
    $lRptVar->Params->Find('AllAgent')->AsBoolean          = True;
    $lRptVar->Params->Find('AllArea')->AsBoolean            = True;
    $lRptVar->Params->Find('AllCompany')->AsBoolean        = True;
    $lRptVar->Params->Find('AllCompanyCategory')->AsBoolean = True;
    $lRptVar->Params->Find('AllControlAccount')->AsBoolean  = True;
    $lRptVar->Params->Find('AllCurrency')->AsBoolean        = True;
    $lRptVar->Params->Find('AllDocProject')->AsBoolean      = True;
#    $lRptVar->Params->Find('AreaData')->AsBlob            = ; #Not use if AllArea is True
#    $lRptVar->Params->Find('CompanyCategoryData')->AsBlob = ; #Not use if AllCompanyCategory is True
#    $lRptVar->Params->Find('CompanyData')->AsBlob        = ; #Not use if AllCompany is True
#    $lRptVar->Params->Find('ControlAccountData')->AsBlob  = ; #Not use if AllControlAccount is True
#    $lRptVar->Params->Find('CurrencyData')->AsBlob        = ; #Not use if AllCurrency is True
#    $lRptVar->Params->Find('DocProjectData')->AsBlob      = ; #Not use if AllDocProject is True
    $lRptVar->Params->Find('FilterPostDate')->AsBoolean      = True;
#    $lRptVar->Params->Find('GroupBy
    $lRptVar->Params->Find('IncludePDC')->AsBoolean        = False;
    $lRptVar->Params->Find('IncludeZeroBalance')->AsBoolean = False;
    $lRptVar->Params->Find('SortBy')->AsString              = 'Code;CompanyName';
    $lRptVar->Params->Find('DateTo')->AsDate                = '23 Sep 2022';
    $lRptVar->Params->Find('IncludeKnockedOffDetail')->AsBoolean = False;
$lRptVar->CalculateReport();
$lDataSetHdr = $lRptVar->DataSets->Find('cdsAgingHeader');
$lDataSet = $lRptVar->DataSets->Find('cdsMain');
$lDataSet2 = $lRptVar->DataSets->Find('cdsDocument');
$lDataSetCO = $lRptVar->DataSets->Find('cdsCompany');
 
    if ($lDataSet->RecordCount > 0) {
echo "Header"."<br>";
SetGrid($lDataSetHdr);
echo "Main Data"."<br>";
SetGrid($lDataSet);
echo "Detail Invoice"."<br>";
SetGrid($lDataSet2);
 
echo "Company Information"."<br>";
SetGrid($lDataSetCO);


  'Step 2: Find and Create the Biz Objects
}else {
  Set BizObject = ComServer.BizObjects.Find("AR_IV")
    echo "Record Not Found";
    }
}


  'Step 3: Set Dataset
if (isset($_POST['BtnData']))
  Set lMainDataSet = BizObject.DataSets.Find("MainDataSet")    'lMainDataSet contains master data
{
  Set lDetailDataSet = BizObject.DataSets.Find("cdsDocDetail") 'lDetailDataSet contains detail data 
    try
 
     {
  'Step 4 : Insert Data - Master
        CheckLogin();
  lDate = CDate("January 1, 2016")
        GetData();
  BizObject.New
echo "<br>";
  lMainDataSet.FindField("DocKey").value = -1
        echo date("d M Y h:i:s A")." - Done";
  lMainDataSet.FindField("DocNo").value = "--IV Test--"
    }
  lMainDataSet.FindField("DocDate").value = lDate
    finally
  lMainDataSet.FindField("PostDate").value = lDate
    {
  lMainDataSet.FindField("Code").value = "300-A0003"
        #$ComServer->Logout();
  lMainDataSet.FindField("Description").value = "Sales"
        #free the object
      
        $ComServer = null;
  'Step 5: Insert Data - Detail
    }
  'For Tax Inclusive = True with override Tax Amount
}
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
  lDetailDataSet.FindField("Account").value = "500-000"
  lDetailDataSet.FindField("Description").value =  "Sales Item A"
  lDetailDataSet.FindField("Tax").value =  "SR"
  lDetailDataSet.FindField("TaxInclusive").value =  0
  lDetailDataSet.FindField("Amount").value = 410.37
  lDetailDataSet.FindField("TaxAmt").value = 24.63
 
  lDetailDataSet.DisableControls
  lDetailDataSet.FindField("TaxInclusive").value =  1
  lDetailDataSet.EnableControls
 
  lDetailDataSet.FindField("Changed").value = "F"
  lDetailDataSet.Post
 
  'For Tax Inclusive = False with override Tax Amount
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
  lDetailDataSet.FindField("Account").value = "500-000"
  lDetailDataSet.FindField("Description").value = "Sales Item B"
  lDetailDataSet.FindField("Tax").value =  "SR"
  lDetailDataSet.FindField("TaxInclusive").value =  0
  lDetailDataSet.FindField("Amount").value = 94.43
  lDetailDataSet.FindField("TaxAmt").value = 5.66
  lDetailDataSet.FindField("Changed").value = "F"
  lDetailDataSet.Post


  'Step 6: Save Document
?>
  BizObject.Save
    <form method="post">         
  BizObject.Close
        <input type="submit" name="BtnData"
  MsgBox "Done"
                value="Get AR Aging"/>
End Function
    </form>
</body>
</html>
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<br>
===Node JS===
: Module Require in Node JS
:- Winax (Mandatory) -> npm install winax


<div style="float: right;">  [[#top|[top]]]</div>
====Common====
* Common.js file for example code


====Example-AR_IV-Edit====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! AR_IV Edit Script 
! Common Function
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="nodejsrepl">
'Available in Version 5.2018.833.759 & above
/* Updated 31 Jul 2023 */
'Copy below script & paste to notepad & name it as eg AR_IV.vbs
var winax = require('C:\\node_js\\node_modules\\winax'); /* Path where you install winax */
Call CheckLogin
var cp = require('child_process');
Call GetData
Call PostData


Dim ComServer, lDataSet
exports.KillApp = function KillApp(){
cp.exec('start cmd.exe /C "taskkill /IM "SQLACC.exe" /F"');
}


Function CreateSQLAccServer
exports.CreateSQLAccServer = function CreateSQLAccServer() { 
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
  var ComServer;
End Function
   ComServer = new winax.Object('SQLAcc.BizApp');
  if (!ComServer.IsLogin) {          /* check whether user has logon */
    ComServer.Login('ADMIN', 'ADMIN', /* UserName, Password */
/* 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', */
'D:\\Happy\\DB\\DEFAULT.DCF', /* DCF File */
'ACC-0024.FDB'); /* FDB Name */
  }
  return ComServer;
}


function CheckLogin
exports.ShowResult = function ShowResult(ADataset){
   'Step 1: Create Com Server object
   var fc, fn, fv, lresult;
   Set ComServer = CreateSQLAccServer 'Create Com Server
  ADataset.First;
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
   while (!ADataset.Eof){
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
  fc = ADataset.Fields.Count;
                'UserName, Password, DCF full path, Database filename
  for (let i = 0; i < fc; i++) {
   END IF
  fn = ADataset.Fields.Items(i).FieldName;
End Function
          fv = ADataset.FindField(fn).AsString;
  lresult =  "Index : "+ i + " FieldName : " + fn + " Value : " + fv;
  console.log(lresult);
      }
  console.log("====");
      ADataset.Next();  
   }
}


Function GetData
exports.ShowMsg = function ShowMsgShowMsg(AMsg){
Dim lSQL
    try {
  lSQL = "SELECT Dockey FROM AR_IV "
        var WSH = new winax.Object('WScript.Shell');
  lSQL = lSQL & "WHERE DocNo='IV-00002' "
        WSH.popup(AMsg);
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
    } catch (e) {
End Function
        console.log(e);
    }
}


Function PostData
Dim BizObject, lMain, lDetail
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("AR_IV")
  'Step 3: Set Dataset
  Set lMain  = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data 
 
  'Step 4 : Find Doc Number
  If lDataSet.RecordCount > 0 Then 
lDataSet.First
    BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString
 
 
    BizObject.Open
    BizObject.Edit
    lMain.Edit
lMain.FindField("Description").AsString = "Sales - Edited"
 
  'Step 5: Delete all Detail
    While lDetail.RecordCount <> 0
      lDetail.First
  lDetail.Delete
    Wend
  'Step 6: Append Detail
  lDetail.Append 
  lDetail.FindField("DtlKey").value = -1
  lDetail.FindField("Account").value = "500-000"
  lDetail.FindField("Description").value =  "Sales Item A - Edited"
  lDetail.FindField("Tax").value =  "SR"
  lDetail.FindField("TaxRate").value =  "6%"
  lDetail.FindField("TaxInclusive").value =  0
  lDetail.FindField("Amount").value = 100
  lDetail.FindField("TaxAmt").value = 6
 
  lDetail.DisableControls
  lDetail.FindField("TaxInclusive").value =  1
  lDetail.EnableControls
 
  lDetail.FindField("Changed").value = "F"
  lDetail.Post
 
  'Step 7: Save Document
    BizObject.Save
    BizObject.Close
 
  'Step 8 : Logout after done 
    'ComServer.Logout 
    MsgBox "Done"
Else
MsgBox "Record Not Found"
  END IF
End Function
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-AR_PM====
====Get Company Profile====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! AR_PM Script 
! Get Company Profile
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="nodejsrepl">
'Copy below script & paste to notepad & name it as eg AR_PM.vbs
/* Updated 22 Jul 2023 */
Call PostData
var Common = require('./Common');
var ComServer, lDataSet;
Function CreateSQLAccServer
 
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
function GetData() {
End Function
   var lSQL;
   lSQL = "SELECT COMPANYNAME, REMARK, BRN, BRN2, GSTNO, ";
Function PostData
   lSQL = lSQL + "SALESTAXNO, SERVICETAXNO, ";
Dim ComServer, BizObject, lIVNo, v(1), lDate
   lSQL = lSQL + "ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS4 FROM SY_PROFILE ";
   lDataSet = ComServer.DBManager.NewDataSet(lSQL);  
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
  END IF
   'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("AR_PM")
   'Step 3: Set Dataset
  Set lMain = BizObject.DataSets.Find("MainDataSet")    'lMainDataSet contains master data
   Set lDetailDataSet = BizObject.DataSets.Find("cdsKnockOff") 'lDetailDataSet contains detail data  
    
    
   'Step 4 : Posting
   Common.ShowResult(lDataSet);
    lDate = CDate("January 23, 2017")
}
    BizObject.New
 
    lMain.FindField("DOCKEY").Value          = -1
try{
    lMain.FindField("DocNo").AsString        = "--PM Test--"
ComServer = Common.CreateSQLAccServer();
    lMain.FindField("CODE").AsString          = "300-C0001"
GetData();
    lMain.FindField("DocDate").Value          = lDate
ComServer.Logout();
    lMain.FindField("PostDate").Value        = lDate
} catch(e){
    lMain.FindField("Description").AsString  = "Payment for A/c"
console.error(e.message)
    lMain.FindField("PaymentMethod").AsString = "310-000"
} finally {
    lMain.FindField("DocAmt").AsFloat        = 65.57
Common.KillApp();
    lMain.FindField("Cancelled").AsString    = "F"
}
  'Step 5: Knock Off IV
    lIVNO = "--IV Test--"
    v(0) = "IV"
    v(1) = lIVNO
    if (lDetailDataSet.Locate("DocType;DocNo", v, false, false)) then
      lDetailDataSet.Edit
      lDetailDataSet.FindField("KOAmt").value = 65.57
      lDetailDataSet.FindField("KnockOff").AsString = "T"
      lDetailDataSet.Post
End IF 
  'Step 6: Save Document
    BizObject.Save
    BizObject.Close
    MsgBox "Done"
  'END IF
End Function
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-AR_PM-Edit====
====Complete Post====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! AR_PM Edit Script 
! Complete Post
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="nodejsrepl">
'Copy below script & paste to notepad & name it as eg AR_IV.vbs
/* Updated 22 Jul 2023
Call EditARPM
This will doing following posting
01. Cash Sales
Function CreateSQLAccServer
02. Sales Credit Note
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
03. Customer Payment With Knock off
End Function
04. Edit Credit Note Posted in Step 02 & Knock Off
05. Customer Refund to Knock off Credit Note
Function EditARPM
*/
Dim ComServer, BizObject, lDataSet, lDataSet2, lDocKey, lDocNo, lIVNo, v(1)
var Common = require('./Common');
var ComServer;
   'Step 1: Create Com Server object
 
   Set ComServer = CreateSQLAccServer 'Create Com Server
function PostDataCS() {
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
  var BizObject, lMain, lDetail;
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"  
  BizObject = ComServer.BizObjects.Find('SL_CS') ;
   END IF
 
   lMain  = BizObject.DataSets.Find('MainDataSet');  /*lMain contains master data*/
   'Step 2: Find and Create the Biz Objects
   lDetail = BizObject.DataSets.Find('cdsDocDetail'); /*lDetail contains detail data */
   Set BizObject = ComServer.BizObjects.Find("AR_PM")
 
  /*Begin Looping yr data*/
   'Step 3: Set Dataset
  /*Insert Data - Master*/
   Set lMainDataSet = BizObject.DataSets.Find("MainDataSet")    'lMainDataSet contains master data
  BizObject.New();
   Set lDetailDataSet = BizObject.DataSets.Find("cdsKnockOff") 'lDetailDataSet contains detail data 
   lMain.FindField('DocNo').AsString      = "--CS Test--";
  lMain.FindField('DocDate').value        = "20/12/2022";
  lMain.FindField('PostDate').value      = "20/12/2022";
  lMain.FindField('Code').AsString        = "300-C0001"; /*Customer Account*/
  lMain.FindField('CompanyName').AsString = "Cash Sales"
   lMain.FindField('Address1').AsString    = ""; /*Optional*/
   lMain.FindField('Address2').AsString    = ""; /*Optional*/
   lMain.FindField('Address3').AsString    = ""; /*Optional*/
   lMain.FindField('Address4').AsString    = ""; /*Optional*/
   lMain.FindField('Phone1').AsString      = ""; /*Optional*/
   lMain.FindField('Description').AsString = "Sales";
    
    
   'Step 4 : Find OR Number
   /*Insert Data - Detail*/
   lDocNo = "OR-00022"
  /*For Tax Inclusive = True with override Tax Amount*/
   lDocKey = BizObject.FindKeyByRef("DocNo", lDocNo)
  lDetail.Append();
   BizObject.Params.Find("DocKey").Value = lDocKey
  lDetail.FindField('Seq').value            = 1;
   lDetail.FindField('Account').AsString    = "500-000"; /*Sales Account*/
   lDetail.FindField('Description').AsString = "Sales Item A";
  lDetail.FindField('Qty').AsFloat          = 1;
   lDetail.FindField('Tax').AsString        = "SV";
  lDetail.FindField('TaxRate').AsString    = "6%";
  lDetail.FindField('TaxInclusive').value  = 0;
  lDetail.FindField('UnitPrice').AsFloat    = 435;
  lDetail.FindField('Amount').AsFloat      = 410.37; /*Exclding Tax Amt*/
  lDetail.FindField('TaxAmt').AsFloat      = 24.63;
    
    
   If not IsNull(lDocKey) Then
   lDetail.DisableControls();
    BizObject.Open
  lDetail.FindField('TaxInclusive').value  = 1;
    BizObject.Edit
  lDetail.EnableControls();
    lMainDataSet.Edit
 
lMainDataSet.FindField("Description").AsString = "testing"
  lDetail.Post();
   'Step 5: Knock Off IV
 
    lIVNO = "IV-00006"
  /*For Tax Inclusive = False with override Tax Amount*/
    v(0) = "IV"
  lDetail.Append();
    v(1) = lIVNO
  lDetail.FindField('Seq').value            = 2;
  lDetail.FindField('Account').AsString    = "500-000";
    if (lDetailDataSet.Locate("DocType;DocNo", v, false, false)) then
  lDetail.FindField('Description').AsString = "Sales Item B";
      lDetailDataSet.Edit
   lDetail.FindField('Qty').AsFloat          = 1;
      lDetailDataSet.FindField("KOAmt").value = 50.12
  lDetail.FindField('Tax').AsString        = "SV";
      lDetailDataSet.FindField("KnockOff").AsString = "T"
  lDetail.FindField('TaxRate').AsString    = "6%";
      lDetailDataSet.Post
  lDetail.FindField('TaxInclusive').value  = 0;
  MsgBox "yes"
  lDetail.FindField('UnitPrice').AsFloat    = 94.43;
End IF 
  lDetail.FindField('Amount').AsFloat      = 94.43;
   'Step 6: Save Document
  lDetail.FindField('TaxAmt').AsFloat      = 5.66;
    BizObject.Save
  lDetail.Post();
    BizObject.Close
 
    MsgBox "Done"
  /*For With Item Code*/
  END IF
  lDetail.Append();
End Function
  lDetail.FindField('Seq').value            = 3;
</syntaxhighlight>
  lDetail.FindField('ItemCode').AsString    = "ANT";
|}
  lDetail.FindField('Description').AsString = "Sales Item B";
  /*lDetail.FindField('Account').AsString    = "500-000"; If you wanted override the Sales Account Code*/
  lDetail.FindField('Qty').AsFloat          = 2;
  lDetail.FindField('UOM').AsString        = "UNIT";
  /*lDetail.FindField('DISC').AsString       = "5%+3"; Optional (eg 5% plus 3 Discount)*/
  lDetail.FindField('Tax').AsString        = "SV";
  lDetail.FindField('TaxRate').AsString    = "6%";
  lDetail.FindField('TaxInclusive').value  = 0;
  lDetail.FindField('UnitPrice').AsFloat    = 100;
  lDetail.FindField('Amount').AsFloat      = 200;
   lDetail.FindField('TaxAmt').AsFloat      = 12;
  lDetail.Post();
 
  /*Save Document*/
  BizObject.Save();
  BizObject.Close(); 
}


<div style="float: right;">  [[#top|[top]]]</div>
function PostDataPM() {
  var BizObject, lMain, lDetail, v;
   
  BizObject = ComServer.BizObjects.Find('AR_PM') ;


====Example-Customer.RO====
  lMain  = BizObject.DataSets.Find('MainDataSet');  /*lMain contains master data*/
{| class="mw-collapsible mw-collapsed wikitable"
  lDetail = BizObject.DataSets.Find('cdsKnockOff'); /*lDetail contains detail data */
! Customer.RO Report Object Script  
 
|-
  BizObject.New();
|
 
<syntaxhighlight lang="vb">
  lMain.FindField('DocNo').AsString        = "--PM Test--";
'Copy below script & paste to notepad & name it as eg customer_ro.vbs
  lMain.FindField('Code').AsString          = "300-C0001";
Call GetCustomerData
  lMain.FindField('DocDate').value          = "20/12/2022";
 
  lMain.FindField('PostDate').value        = "20/12/2022";
Function CreateSQLAccServer
  lMain.FindField('Description').AsString  = "Payment for A/";
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
  lMain.FindField('PaymentMethod').AsString = "320-000"; /*Bank or Cash Account*/
End Function
  lMain.FindField('ChequeNumber').AsString = "";
  lMain.FindField('BankCharge').AsFloat    = 0;
  lMain.FindField('DocAmt').AsFloat        = 200.00;
  lMain.FindField('Cancelled').AsString    = "F";
 
  v = ComServer.CreateOleVariantArray(2);
  v.SetItem(0, 'IV'); /*Knock Off DocType IV or DN*/
  v.SetItem(1, '--CS Test--'); /*Knock Off DocNo*/
 
  if (lDetail.Locate('DocType;DocNo', v.AsOleVariant(), false, false)){
      lDetail.Edit();
      lDetail.FindField('KOAmt').AsFloat    = "147.09"; /*Partial Knock Off*/  
      lDetail.FindField('KnockOff').AsString = 'T';
      lDetail.Post();
  }
    /* Save document */ 
   BizObject.Save();
  BizObject.Close();
}
 
function PostDataCN() {
  var BizObject, lMain, lDetail;
  BizObject = ComServer.BizObjects.Find('SL_CN') ;


Function GetCustomerData
   lMain   = BizObject.DataSets.Find('MainDataSet');  /*lMain contains master data*/
Dim ComServer, RptObject, lDataSet, lDataSet2, lDateFrom, lDateTo
   lDetail = BizObject.DataSets.Find('cdsDocDetail'); /*lDetail contains detail data */
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"
  END IF


   'Step 2: Find and Create the Report Objects
   /*Begin Looping yr data*/
   Set RptObject = ComServer.RptObjects.Find("Customer.RO")  
  /*Insert Data - Master*/
  BizObject.New();
  lMain.FindField('DocNo').AsString      = "--CN Test--";
   lMain.FindField('DocDate').value        = "21/12/2022";
  lMain.FindField('PostDate').value      = "21/12/2022";
  lMain.FindField('Code').AsString        = "300-C0001"; /*Customer Account*/
  lMain.FindField('CompanyName').AsString = "Cash Sales"
  lMain.FindField('Address1').AsString    = ""; /*Optional*/
  lMain.FindField('Address2').AsString    = ""; /*Optional*/
  lMain.FindField('Address3').AsString    = ""; /*Optional*/
  lMain.FindField('Address4').AsString    = ""; /*Optional*/
  lMain.FindField('Phone1').AsString      = ""; /*Optional*/
  lMain.FindField('Description').AsString = "Sales Returned";
 
  /*Insert Data - Detail*/ 
  /*For With Item Code*/
  lDetail.Append();
  lDetail.FindField('Seq').value            = 1;
  lDetail.FindField('ItemCode').AsString    = "ANT";
  lDetail.FindField('Description').AsString  = "Sales Item B";
  lDetail.FindField('Description2').AsString = "Product Spoil"; /*Reason*/
  lDetail.FindField('Remark1').AsString      = "--IV Test--"; /*Invoice No*/
  lDetail.FindField('Remark2').AsString      = "20 Dec 2022"; /*Invoide Date*/
  lDetail.FindField('Qty').AsFloat          = 1;
  lDetail.FindField('UOM').AsString        = "UNIT";
  lDetail.FindField('Tax').AsString        = "SV";
  lDetail.FindField('TaxRate').AsString    = "6%";
  lDetail.FindField('TaxInclusive').value  = 0;
  lDetail.FindField('UnitPrice').AsFloat    = 100;
  lDetail.FindField('Amount').AsFloat      = 100;
  lDetail.FindField('TaxAmt').AsFloat      = 6;
  lDetail.Post();
 
  /*Save Document*/
  BizObject.Save();
  BizObject.Close(); 
}


  'Step 3: Spool parameters
function PostKnockIVCN() {
  RptObject.Params.Find("AllAgent").Value = true
   var BizObject, lMain, lDetail, v, lDocNo, lDocKey;
   RptObject.Params.Find("AllArea").Value = true
   
  RptObject.Params.Find("AllCompany").Value = false
   BizObject = ComServer.BizObjects.Find('AR_CN') ;
  RptObject.Params.Find("AllCompanyCategory").Value = true
   RptObject.Params.Find("AllCurrency").Value = true
  RptObject.Params.Find("AllTerms").Value = true
  RptObject.Params.Find("SelectDate").Value = true
  RptObject.Params.Find("PrintActive").Value = true
  RptObject.Params.Find("PrintInactive").Value = false
  RptObject.Params.Find("PrintPending").Value = false
  RptObject.Params.Find("PrintProspect").Value = false
  RptObject.Params.Find("PrintSuspend").Value = false
  lDateFrom = CDate("January 1, 2000")
  lDateTo = CDate("December 31, 2014")


   RptObject.Params.Find("DateFrom").Value = lDateFrom
   lMain  = BizObject.DataSets.Find('MainDataSet');  /*lMain contains master data*/
   RptObject.Params.Find("DateTo").Value = lDateTo
   lDetail = BizObject.DataSets.Find('cdsKnockOff'); /*lDetail contains detail data */
   RptObject.Params.Find("CompanyData").Value = "300-A0003"
 
  /* Find CN Number */
  lDocNo = "--CN Test--"
  lDocKey = BizObject.FindKeyByRef('DocNo', lDocNo);
   BizObject.Params.Find('DocKey').Value = lDocKey;
    
    
   'Step 4: Perform Report calculation
   if (lDocKey != null) {
   RptObject.CalculateReport()
  BizObject.Open();
   Set lDataSet = RptObject.DataSets.Find("cdsMain")
  BizObject.Edit();
   Set lDataSet2 = RptObject.DataSets.Find("cdsBranch")
  lMain.Edit();
  MsgBox "Count " & lDataSet.RecordCount
 
  v = ComServer.CreateOleVariantArray(2);
  v.SetItem(0, 'IV'); /*Knock Off DocType IV or DN*/
  v.SetItem(1, '--CS Test--'); /*Knock Off DocNo*/
    
  if (lDetail.Locate('DocType;DocNo', v.AsOleVariant(), false, false)){
  lDetail.Edit();
      lDetail.FindField('KOAmt').AsFloat    = "100"; /*Partial Knock Off*/    
      lDetail.FindField('KnockOff').AsString = 'T';
      lDetail.Post();
  }
    /* Save document */ 
  BizObject.Save();
  BizObject.Close();
  }
}
 
function PostDataCF() {
   var BizObject, lMain, lDetail, v;
   
  BizObject = ComServer.BizObjects.Find('AR_CF') ;


   'Step 5 Retrieve the output
   lMain  = BizObject.DataSets.Find('MainDataSet');  /*lMain contains master data*/
   lDataSet.First
   lDetail = BizObject.DataSets.Find('cdsKnockOff'); /*lDetail contains detail data */
   While (not lDataSet.eof)
 
    MsgBox lDataSet.FindField("Code").AsString & " " & lDataSet.FindField("CompanyName").AsString
   BizObject.New();
lDataSet2.First
 
     While (not lDataSet2.eof)
  lMain.FindField('DocNo').AsString        = "--CF Test--";
  MsgBox lDataSet2.FindField("Address1").AsString
  lMain.FindField('Code').AsString          = "300-C0001";
  lDataSet2.Next
  lMain.FindField('DocDate').value          = "24/12/2022";
     Wend
  lMain.FindField('PostDate').value        = "24/12/2022";
lDataSet.Next
  lMain.FindField('Description').AsString   = "Payment for A/";
  Wend
  lMain.FindField('PaymentMethod').AsString = "320-000"; /*Bank or Cash Account*/
End Function
  lMain.FindField('ChequeNumber').AsString = "";
  lMain.FindField('BankCharge').AsFloat    = 0;
  lMain.FindField('DocAmt').AsFloat        = 6.00;
  lMain.FindField('Cancelled').AsString     = "F";
 
  v = ComServer.CreateOleVariantArray(2);
  v.SetItem(0, 'CN'); /*Knock Off DocType*/
  v.SetItem(1, '--CN Test--'); /*Knock Off DocNo*/
 
  if (lDetail.Locate('DocType;DocNo', v.AsOleVariant(), false, false)){
      lDetail.Edit();
      lDetail.FindField('KOAmt').AsFloat    = "4"; /*Partial Knock Off*/  
      lDetail.FindField('KnockOff').AsString = 'T';
      lDetail.Post();
  }
    /* Save document */ 
  BizObject.Save();
  BizObject.Close();
}
 
try{
ComServer = Common.CreateSQLAccServer();
console.log("Posting Cash Sales");
     PostDataCS();
    console.log("Posting Payment");
    PostDataPM();
    console.log("Posting Sales CN");
    PostDataCN();
    console.log("Posting Knock Off CN");
    PostKnockIVCN();
    console.log("Posting Customer Refund");
    PostDataCF();
    console.log("Done");
ComServer.Logout();
} catch(e){
console.error(e.message)
} finally {
Common.KillApp();
}
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Customer.Statement.RO====
====Get Picture & Description3(Rich Text)====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Customer.Statement.RO  Report Object Script
! Get Picture & Description3(Rich Text) Script  
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="nodejsrepl">
'Copy below script & paste to notepad & name it as eg customer_statement_ro.vbs
/* Updated 31 Jul 2023 */
Call GetCustStatementData
var Common = require('./Common');
var ComServer, lDataSet;
Function CreateSQLAccServer
const fs = require('fs');
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
 
End Function
function saveImage(filename, data){
  var myBuffer = new Buffer.alloc(data.length);
   for (var i = 0; i < data.length; i++) {
      myBuffer[i] = data[i];
  }
  fs.writeFile(filename, myBuffer, function(err) {
      if(err) {
          console.log(err);
      } else {
          console.log("The Image file was saved!");
      }
  });
}


Function GetCustStatementData
function ExpFile(AFName, AData){
Const Quote = """"
const FN = new console.Console(fs.createWriteStream(AFName));
Dim ComServer, RptObject, lDataSet, lDataSet2, lDateFrom, lDateTo, lAgeData
     FN.log(AData);
  'Step 1: Create Com Server object
}
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
     ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"
  END IF


  'Step 2: Find and Create the Report Objects
function GetData() {
  Set RptObject = ComServer.RptObjects.Find("Customer.Statement.RO")  
   var lSQL, txt, rtf;
   lSQL = "SELECT Description3, Picture FROM ST_ITEM ";
   'Step 3: Spool parameters
  lSQL = lSQL + "WHERE Code='ANT' ";
   lAgeData = "<?xml version=" & Quote & "1.0" & Quote & " standalone=" & Quote & "yes" & Quote & "?>  <DATAPACKET Version=" & Quote & "2.0" & Quote & "><METADATA><FIELDS>" &_
  lDataSet = ComServer.DBManager.NewDataSet(lSQL);  
      "<FIELD attrname=" & Quote & "ColumnNo" & Quote & " fieldtype=" & Quote & "i4" & Quote & " required=" & Quote & "true" & Quote & "/><FIELD attrname=" & Quote & "ColumnType" & Quote & " fieldtype=" & Quote & "string" & Quote & " WIDTH=" & Quote & "1" & Quote & "/>" &_
    
      "<FIELD attrname=" & Quote & "Param1" & Quote & " fieldtype=" & Quote & "i4" & Quote & " required=" & Quote & "true" & Quote & "/><FIELD attrname=" & Quote & "Param2" & Quote & " fieldtype=" & Quote & "i4" & Quote & " required=" & Quote & "true" & Quote & "/>" &_
   lDataSet.First;
      "<FIELD attrname=" & Quote & "IsLocal" & Quote & " fieldtype=" & Quote & "boolean" & Quote & "/><FIELD attrname=" & Quote & "HeaderScript" & Quote & " fieldtype=" & Quote & "bin.hex" & Quote & " SUBTYPE=" & Quote & "Text" & Quote & " WIDTH=" & Quote & "1" & Quote & "/>" &_
   rtf = lDataSet.FindField('Description3').AsString;
      "</FIELDS><PARAMS/></METADATA><ROWDATA><ROW ColumnNo=" & Quote & "0" & Quote & " ColumnType=" & Quote & "" & Quote & " Param1=" & Quote & "0" & Quote & " Param2=" & Quote & "0" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & "/>" &_
   console.log(rtf);
      "<ROW ColumnNo=" & Quote & "1" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "0" & Quote & " Param2=" & Quote & "0" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;Current Mth&apos;&#013;end;" & Quote & "/>" &_
    
      "<ROW ColumnNo=" & Quote & "2" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-1" & Quote & " Param2=" & Quote & "-1" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;1 Months&apos;&#013;end;" & Quote & "/>" &_
   ExpFile('./output.rtf', rtf);
      "<ROW ColumnNo=" & Quote & "3" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-2" & Quote & " Param2=" & Quote & "-2" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;2 Months&apos;&#013;end;" & Quote & "/>" &_
    
      "<ROW ColumnNo=" & Quote & "4" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-3" & Quote & " Param2=" & Quote & "-3" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;3 Months&apos;&#013;end;" & Quote & "/>" &_
   txt = ComServer.Utility.RichTextToPlainText(rtf);
      "<ROW ColumnNo=" & Quote & "5" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-4" & Quote & " Param2=" & Quote & "-4" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;4 Months&apos;&#013;end;" & Quote & "/>" &_
   Common.ShowMsg(txt);
      "<ROW ColumnNo=" & Quote & "6" & Quote & " ColumnType=" & Quote & "B" & Quote & " Param1=" & Quote & "-999999" & Quote & " Param2=" & Quote & "-5" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;5 Month &amp; above&apos;&#013;end;" & Quote & "/>" &_
   /* console.log(txt); <= Not support Unicode */
      "</ROWDATA></DATAPACKET>"
    
'  RptObject.Params.Find("AgentData").Value            = 'Not use if AllAgent is True
   ExpFile('./output.txt', txt)
   RptObject.Params.Find("AgingData").Value            = lAgeData 'Fixed
   console.log('Done Export');
   RptObject.Params.Find("AgingOn").Value              = "I" 'Fixed
    
   RptObject.Params.Find("AllAgent").Value            = true
   saveImage("./Pic.jpg", lDataSet.FindField('Picture').Value);
   RptObject.Params.Find("AllArea").Value              = true
}
   RptObject.Params.Find("AllCompany").Value          = false
   RptObject.Params.Find("AllCompanyCategory").Value  = true
  RptObject.Params.Find("AllControlAccount").Value    = true
   RptObject.Params.Find("AllCurrency").Value          = true
   RptObject.Params.Find("AllDocProject").Value        = true
'  RptObject.Params.Find("AreaData").Value            =  'Not use if AllArea is True
'  RptObject.Params.Find("CompanyCategoryData").Value  =  'Not use if AllCompanyCategory is True
   RptObject.Params.Find("CompanyData").Value          = "300-A0001"& vbCRLF & "300-C0001" 'Filter by Customer Code 300-A0001 & 300-C0001
'  RptObject.Params.Find("ControlAccountData").Value   =  'Not use if AllControlAccount is True
'  RptObject.Params.Find("CurrencyData").Value        = 'Not use if AllCurrency is True
   lDateFrom = CDate("August 1, 2016")
   lDateTo = CDate("August 31, 2016")
  RptObject.Params.Find("DateFrom").Value            = lDateFrom
   RptObject.Params.Find("DateTo").Value              = lDateTo
' RptObject.Params.Find("DocProjectData").Value      =  'Not use if AllDocProject is True
  RptObject.Params.Find("IncludeZeroBalance").Value  = false
   RptObject.Params.Find("SelectDate").Value          = true
   RptObject.Params.Find("SortBy").Value              = "CompanyCategory;Code;CompanyName;Agent;Area;CurrencyCode;ControlAccount"
  RptObject.Params.Find("StatementDate").Value        = lDateTo ' Norm same as DateTo
  RptObject.Params.Find("StatementType").Value        = "O" 'O = Open Item, B = B/F
  'Step 4: Perform Report calculation
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsDocument")
  MsgBox "Count " & lDataSet.RecordCount


  'Step 5 Retrieve the output
try{
  lDataSet.First
ComServer = Common.CreateSQLAccServer();
  While (not lDataSet.eof)
GetData();
    MsgBox lDataSet.FindField("Code").AsString & " " & lDataSet.FindField("CompanyName").AsString & " " & lDataSet.FindField("Balance").AsString
ComServer.Logout();
lDataSet2.First
} catch(e){
    While (not lDataSet2.eof)
console.error(e.message)
  MsgBox lDataSet2.FindField("DocNo").AsString
} finally {
  lDataSet2.Next
Common.KillApp();
    Wend
}
lDataSet.Next
  Wend
End Function
</syntaxhighlight>
</syntaxhighlight>
|}
|}


<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>
 
====Get Stock Qty Balance====
====Example-GL.CB.RO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! GL.CB.RO  Report Object Script
! Get Picture & Description3(Rich Text) Script  
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="nodejsrepl">
'Copy below script & paste to notepad & name it as eg GL.CB.RO.vbs
/* Updated 18 Jan 2024 */
Call GetCLCBData
var Common = require('./Common');
var ComServer;
 
function GetListData() {
  var lSQL, lDataSet;
  lSQL = "SELECT  ItemCode, Location, Batch, Sum(Qty) Qty  FROM ST_TR  ";
  lSQL = lSQL + "WHERE PostDate<='31 Dec 2019' ";
  lSQL = lSQL + "AND ITEMCODE ='ANT' ";
  lSQL = lSQL + "GROUP BY ItemCode, Location, Batch ";
 
  lDataSet = ComServer.DBManager.NewDataSet(lSQL);
 
  Common.ShowResult(lDataSet);
}
 
try{
ComServer = Common.CreateSQLAccServer();
GetListData();
ComServer.Logout();
} catch(e){
console.error(e.message)
} finally {
Common.KillApp();
}
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>
 
====SO to DO====
{| class="mw-collapsible mw-collapsed wikitable"
! SO to DO Script
|-
|
<syntaxhighlight lang="nodejsrepl">
/*Updated 26 Apr 2024*/
var Common = require('./Common');
var ComServer;
 
function PostData() {
  var BizObject, lMain, lDetail, lSQL, lDataSet;
 
  lSQL = "SELECT Dockey, DocNo,Code, CompanyName, DocProject, Seq, DtlKey, ItemCode, Description, Qty, UOM, UnitPrice, Disc, Amount, DtlProject, ";
  lSQL = lSQL + "Tax, TaxRate, TaxInclusive, TaxAmt, COALESCE(Sum(XFQty),0) XFQty, COALESCE((Qty-Sum(XFQty)), Qty) OSQty FROM ( ";
  lSQL = lSQL + "SELECT A.Dockey, A.DocNo, A.Code, A.CompanyName, A.Project DocProject, ";
  lSQL = lSQL + "B.DtlKey, B.Seq, B.ItemCode, B.Description, B.Qty, B.UOM, B.UnitPrice, B.Disc, B.Amount, ";
  lSQL = lSQL + "B.Tax, B.TaxRate, B.TaxInclusive, B.TaxAmt, B.Project DtlProject, C.Qty XFQty FROM SL_SO A ";
  lSQL = lSQL + "INNER JOIN SL_SODTL B ON (A.DOCKEY=B.DOCKEY) ";
  lSQL = lSQL + "LEFT JOIN ST_XTRANS C ON (A.DOCKEY=C.FROMDOCKEY AND B.DTLKEY=C.FROMDTLKEY ";
  lSQL = lSQL + "                          AND C.FROMDOCTYPE='SO') ";
  lSQL = lSQL + "WHERE A.DOCNO='SO-00041') ";
  lSQL = lSQL + "GROUP BY Dockey, DocNo, Code, CompanyName, DocProject, Seq, Dtlkey, ItemCode, Description, Qty, UOM, UnitPrice, Disc, ";
  lSQL = lSQL +" Amount, DtlProject, Tax, TaxRate, TaxInclusive, TaxAmt ";
  lSQL = lSQL + "HAVING COALESCE((Qty-Sum(XFQty)), Qty) >0 ";
 
  lDataSet = ComServer.DBManager.NewDataSet(lSQL);
 
  if (lDataSet.RecordCount > 0) {
  BizObject = ComServer.BizObjects.Find('SL_DO') ;  
  lMain  = BizObject.DataSets.Find('MainDataSet');  /*lMain contains master data*/
  lDetail = BizObject.DataSets.Find('cdsDocDetail'); /*lDetail contains detail data */  
 
  BizObject.New();
  lMain.FindField('DocNo').AsString      = "<<New>>";
      lMain.FindField('DocDate').value        = "26/04/2024";
      lMain.FindField('PostDate').value      = "26/04/2024";
      lMain.FindField('Code').AsString        = lDataSet.FindField('Code').AsString; /*Customer Account*/
      lMain.FindField('Description').AsString = "Post from 3rd Party";
 
  lDataSet.First;
  while (!lDataSet.Eof){ 
  lDetail.Append();
          lDetail.FindField('Seq').value            = lDataSet.FindField('Seq').Value;
          lDetail.FindField('ItemCode').AsString    = lDataSet.FindField('ItemCode').AsString;
          lDetail.FindField('Description').AsString = lDataSet.FindField('Description').AsString;
          lDetail.FindField('Qty').AsFloat          = lDataSet.FindField('OSQty').AsFloat;/*Transfer all balance Qty*/
          lDetail.FindField('UOM').AsString        = lDataSet.FindField('UOM').AsString;
          lDetail.FindField('DISC').value          = lDataSet.FindField('DISC').AsString;
          lDetail.FindField('Tax').value            = lDataSet.FindField('Tax').AsString;
          lDetail.FindField('TaxRate').value        = lDataSet.FindField('TaxRate').AsString;
          lDetail.FindField('TaxInclusive').value  = lDataSet.FindField('TaxInclusive').value;
          lDetail.FindField('UnitPrice').AsFloat    = lDataSet.FindField('UnitPrice').AsFloat ;
          lDetail.FindField('Amount').AsFloat      = lDataSet.FindField('Amount').AsFloat;
          lDetail.FindField('TaxAmt').AsFloat      = lDataSet.FindField('TaxAmt').AsFloat;
  lDetail.FindField('FromDocType').AsString = "SO"; /*From Document Type*/
          lDetail.FindField('FromDockey').AsFloat  = lDataSet.FindField('Dockey').AsFloat;
          lDetail.FindField('FromDtlkey').AsFloat  = lDataSet.FindField('DtlKey').AsFloat;
          lDetail.Post();
          lDataSet.Next();
  }
      /*Save Document*/
      BizObject.Save();
  BizObject.Close();
  } else
  console.log("Record Not Found");
}
 
 
 
try{
ComServer = Common.CreateSQLAccServer();
console.log("Posting SO to DO");
    PostData();
    console.log("Done");
ComServer.Logout();
} catch(e){
console.error(e.message)
} finally {
Common.KillApp();
}
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>
<br />
 
===VB Script===
====Get Company Profile====
{| class="mw-collapsible mw-collapsed wikitable"
! Company Profile Script 
|-
|
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg Common.Agent.RO.vbs
Call GetCoInfo
   
   
Function CreateSQLAccServer
Function CreateSQLAccServer
Line 5,704: Line 6,379:
End Function
End Function
   
   
Function GetCLCBData
Function GetCoInfo
Dim ComServer, RptObject, lDataSet, lDataSet2, lDataSet3, lDateFrom, lDateTo
Dim ComServer, RptObject, lDataSet
   'Step 1: Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
Line 5,713: Line 6,388:
   
   
   'Step 2: Find and Create the Report Objects
   'Step 2: Find and Create the Report Objects
   Set RptObject = ComServer.RptObjects.Find("GL.CB.RO")  
   Set RptObject = ComServer.RptObjects.Find("Common.Agent.RO")  
   
   
  'Step 3: Spool parameters
  RptObject.Params.Find("AllCurrency").Value    = true
  RptObject.Params.Find("AllDocProject").Value  = true
  RptObject.Params.Find("AllDocument").Value    = true
  RptObject.Params.Find("AllItemProject").Value = true
  RptObject.Params.Find("AllItemArea").Value    = true
  RptObject.Params.Find("AllItemAgent").Value  = true
  RptObject.Params.Find("AllDocAgent").Value    = true
  RptObject.Params.Find("AllDocArea").Value    = true
  RptObject.Params.Find("AllPaymentMethod").Value = false
  'RptObject.Params.Find("CurrencyData").Value    = 'Not use if AllCurrency is true
 
  lDateFrom = CDate("January 01, 2017")
  lDateTo = CDate("December 31, 2017")
   
   
  'For Post Date From & Date To'
   'Step 3: Perform Report calculation  
  RptObject.Params.Find("DateFrom").Value = lDateFrom
   RptObject.CalculateReport()
  RptObject.Params.Find("DateTo").Value  = lDateTo
   Set lDataSet = RptObject.DataSets.Find("cdsProfile")
 
 
  'RptObject.Params.Find("DocProjectData").Value  = 'Not use if AllDocProject is true
  'RptObject.Params.Find("DocAreaData").Value    = 'Not use if AllDocArea is true
  'RptObject.Params.Find("DocAgentData").Value    = 'Not use if AllDocAgent is true
  'RptObject.Params.Find("ItemAgentData").Value  = 'Not use if AllItemAgent is true
  RptObject.Params.Find("DocType").Value          = "PV" 'PV for Payment Voucher & OR for Official Receipt
  'RptObject.Params.Find("DocumentData").Value    = 'Not use if AllDocument is true
  'RptObject.Params.Find("GroupBy").Value        = 'If you wanted to grouping the data
  RptObject.Params.Find("IncludeCancelled").Value = false
  'RptObject.Params.Find("ItemAreaData").Value    = 'Not use if AllItemArea is true
  'RptObject.Params.Find("ItemProjectData").Value = 'Not use if AllItemProject is true
  RptObject.Params.Find("PaymentMethodData").Value  = "310-001"
  RptObject.Params.Find("PrintDocumentStyle").Value = false
  RptObject.Params.Find("SelectDate").Value        = true 'For Post Date
  'RptObject.Params.Find("SelectDocDate").Value    = 'For Doc Date
  RptObject.Params.Find("SortBy").Value            = "PostDate;DocNo"
   'Step 4: Perform Report calculation  
   RptObject.CalculateReport()
   Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsDetail")
  Set lDataSet3 = RptObject.DataSets.Find("cdsTax")
   MsgBox "Count " & lDataSet.RecordCount
   MsgBox "Count " & lDataSet.RecordCount
   
   
Line 5,760: Line 6,400:
   lDataSet.First
   lDataSet.First
   While (not lDataSet.eof)
   While (not lDataSet.eof)
    MsgBox lDataSet.FindField("DocNo").AsString & " " & lDataSet.FindField("Description").AsString
MsgBox "Company Name : " & lDataSet.FindField("CompanyName").AsString
lDataSet2.First
    While (not lDataSet2.eof)
MsgBox "Remark : " & lDataSet.FindField("Remark").AsString
  MsgBox lDataSet2.FindField("Code").AsString & " " & lDataSet2.FindField("Description").AsString
 
  lDataSet2.Next
MsgBox "ROC No : " & lDataSet.FindField("RegisterNo").AsString
    Wend
 
MsgBox "GST No : " & lDataSet.FindField("GSTNo").AsString
MsgBox "Address 1 : " & lDataSet.FindField("Address1").AsString
MsgBox "Address 2 : " & lDataSet.FindField("Address2").AsString
MsgBox "Address 3 : " & lDataSet.FindField("Address3").AsString
MsgBox "Address 4 : " & lDataSet.FindField("Address4").AsString
MsgBox "Attention : " & lDataSet.FindField("Attention").AsString
MsgBox "Phone : " & lDataSet.FindField("Phone1").AsString
MsgBox "Fax : " & lDataSet.FindField("Fax1").AsString
MsgBox "E-Mail : " & lDataSet.FindField("EMail").AsString
lDataSet.Next
lDataSet.Next
   Wend
   Wend
   'For GST List
 
  MsgBox "GST Code Count " & lDataSet3.RecordCount
   'Step 6 : Logout after done 
  lDataSet3.First
   ComServer.Logout   
   While (not lDataSet3.eof)
    MsgBox lDataSet3.FindField("Code").AsString
lDataSet3.Next
  Wend
End Function
End Function
</syntaxhighlight>
</syntaxhighlight>
Line 5,781: Line 6,434:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-AR_Customer====
====Complete Post====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! AR_Customer - Script   
! SL_CS, AR_PM, SL_CN & AR_CN Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg AR_Customer.vbs
'Updated 13 Sep 2018
'Copy below script & paste to notepad & name it as eg SL_CS.vbs
'This will doing following posting
'01. Cash Sales
'02. Sales Credit Note
'03. Customer Payment With Knock off
'04. Edit Credit Note Posted in Step 02 & Knock Off
Call CheckLogin
Call CheckLogin
Call InsertData
Call InsertData
Line 5,807: Line 6,466:


Function InsertData
Function InsertData
Dim BizObject, lMain, lDetail
Dim BizObject, lMain, lDetail, lDate
   'Step 2: Find and Create the Biz Objects
   'Step 2: Find and Create the Biz Objects
   Set BizObject = ComServer.BizObjects.Find("AR_Customer")  
   Set BizObject = ComServer.BizObjects.Find("SL_CS")  


   'Step 3: Set Dataset
   'Step 3: Set Dataset
   Set lMain  = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
   Set lMain  = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
   Set lDetail = BizObject.DataSets.Find("cdsBranch") 'lDetail contains detail data   
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data   
    
    
   'Begin Looping yr data
   'Begin Looping yr data
   'Step 4 : Insert Data - Master
   'Step 4 : Insert Data - Master
  lDate = CDate("January 1, 2017")
   BizObject.New
   BizObject.New
   lMain.FindField("Code").AsString       = "300-Test"
  lMain.FindField("DocKey").value        = -1
  lMain.FindField("DocNo").AsString      = "--IV Test--"
  lMain.FindField("DocDate").value        = lDate
  lMain.FindField("PostDate").value      = lDate
   lMain.FindField("Code").AsString       = "300-C0001" 'Customer Account
   lMain.FindField("CompanyName").AsString = "Cash Sales"
   lMain.FindField("CompanyName").AsString = "Cash Sales"
  lMain.FindField("Address1").AsString    = "" 'Optional
  lMain.FindField("Address2").AsString    = "" 'Optional
  lMain.FindField("Address3").AsString    = "" 'Optional
  lMain.FindField("Address4").AsString    = "" 'Optional
  lMain.FindField("Phone1").AsString      = "" 'Optional
  lMain.FindField("Description").AsString = "Sales"
      
      
   'Step 5: Insert Data - Detail
   'Step 5: Insert Data - Detail
   'For 1st Branch
   'For Tax Inclusive = True with override Tax Amount
   lDetail.Edit
   lDetail.Append
   lDetail.FindField("BranchName").AsString  = "BILLING"
  lDetail.FindField("DtlKey").value        = -1
   lDetail.FindField("Address1").AsString   = "Address1"
   lDetail.FindField("DocKey").value        = -1
   lDetail.FindField("Address2").AsString   = "Address2"
  lDetail.FindField("Seq").value            = 1
   lDetail.FindField("Address3").AsString    = "Address3"
   lDetail.FindField("Account").AsString     = "500-000" 'Sales Account
   lDetail.FindField("Address4").AsString   = "Address4"
   lDetail.FindField("Description").AsString = "Sales Item A"
   lDetail.FindField("Attention").AsString   = "Attention"
   lDetail.FindField("Qty").AsFloat          = 1
   lDetail.FindField("Phone1").AsString      = "Phone1"
   lDetail.FindField("Tax").AsString         = "SR"
   lDetail.FindField("Fax1").AsString        = "Fax1"
   lDetail.FindField("TaxRate").AsString     = "6%"
   lDetail.FindField("Email").AsString       = "EmailAddress"
   lDetail.FindField("TaxInclusive").value  = 0
  lDetail.FindField("UnitPrice").AsFloat    = 435
   lDetail.FindField("Amount").AsFloat      = 410.37 'Exclding GST Amt
   lDetail.FindField("TaxAmt").AsFloat       = 24.63
 
  lDetail.DisableControls
  lDetail.FindField("TaxInclusive").value  = 1
  lDetail.EnableControls
 
   lDetail.Post
   lDetail.Post
    
    
   'For 2nd Branch
   'For Tax Inclusive = False with override Tax Amount
   lDetail.Append
   lDetail.Append
   lDetail.FindField("BranchName").AsString = "Branch1"
   lDetail.FindField("DtlKey").value        = -1
   lDetail.FindField("Address1").AsString   = "DAddress1"
  lDetail.FindField("DocKey").value        = -1
   lDetail.FindField("Address2").AsString   = "DAddress2"
  lDetail.FindField("Seq").value            = 2
   lDetail.FindField("Address3").AsString    = "DAddress3"
  lDetail.FindField("Account").AsString     = "500-000"
   lDetail.FindField("Address4").AsString    = "DAddress4"
   lDetail.FindField("Description").AsString = "Sales Item B"
   lDetail.FindField("Attention").AsString  = "DAttention"
   lDetail.FindField("Qty").AsFloat          = 1
   lDetail.FindField("Phone1").AsString     = "DPhone1"
  lDetail.FindField("Tax").AsString         = "SR"
   lDetail.FindField("Fax1").AsString        = "DFax1"
   lDetail.FindField("TaxRate").AsString     = "6%"
   lDetail.FindField("Email").AsString      = "DEmailAddress"
  lDetail.FindField("TaxInclusive").value  = 0
  lDetail.FindField("UnitPrice").AsFloat   = 94.43
  lDetail.FindField("Amount").AsFloat      = 94.43
  lDetail.FindField("TaxAmt").AsFloat      = 5.66
  lDetail.Post
 
  'For With Item Code
  lDetail.Append
   lDetail.FindField("DtlKey").value        = -1
  lDetail.FindField("DocKey").value        = -1
  lDetail.FindField("Seq").value            = 3
  lDetail.FindField("ItemCode").AsString    = "ANT"
   lDetail.FindField("Description").AsString = "Sales Item B"
   'lDetail.FindField("Account").AsString    = "500-000" 'If you wanted override the Sales Account Code
  lDetail.FindField("Qty").AsFloat          = 2
   lDetail.FindField("UOM").AsString         = "UNIT"
   'lDetail.FindField("DISC").AsString        = "5%+3" 'Optional (eg 5% plus 3 Discount)
   lDetail.FindField("Tax").AsString         = "SR"
  lDetail.FindField("TaxRate").AsString    = "6%"
  lDetail.FindField("TaxInclusive").value  = 0
  lDetail.FindField("UnitPrice").AsFloat    = 100 
  lDetail.FindField("Amount").AsFloat       = 200
  lDetail.FindField("TaxAmt").AsFloat      = 12
   lDetail.Post
   lDetail.Post


Line 5,851: Line 6,551:
   BizObject.Save
   BizObject.Save
   BizObject.Close
   BizObject.Close
 
  'Step 7: Payment
  Call InsertARPM
 
  'Step 8: Credit Note
  Call InsertSLCN
   'End Looping yr data
   'End Looping yr data


   'Step 7 : Logout after done   
   'Step 9 : Logout after done   
   'ComServer.Logout
   'ComServer.Logout
    
    
   MsgBox "Done"   
   MsgBox "Done"   
End Function
End Function
</syntaxhighlight>
|}


<div style="float: right;">  [[#top|[top]]]</div>
Function InsertARPM
 
Dim BizObject, lMain, lDetail, lDate, v(1)
====Example-AR_Customer-Edit====
  'Step 2: Find and Create the Biz Objects
{| class="mw-collapsible mw-collapsed wikitable"
  Set BizObject = ComServer.BizObjects.Find("AR_PM")
! AR_Customer - Edit Script 
|-
|
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg AR_Customer.vbs
Call EditARCustomer
   
   
Function CreateSQLAccServer
   'Step 3: Set Dataset
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
   Set lMain = BizObject.DataSets.Find("MainDataSet")   'lMain contains master data
End Function
   Set lDetail = BizObject.DataSets.Find("cdsKnockOff") 'lDetail contains detail data   
Function EditARCustomer
Dim ComServer, BizObject, lDataSet, lDataSet2
  'Step 1 Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
  END IF
  'Step 2 Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("AR_Customer")
   'Step 3 Set Dataset
   Set lMainDataSet = BizObject.DataSets.Find("MainDataSet") 'lMainDataSet contains master data
   Set lDetailDataSet = BizObject.DataSets.Find("cdsBranch") 'lDetailDataSet contains detail data   
    
    
   'Step 4 Find Customer Code
   'Step 4 : Posting
  BizObject.Params.Find("Code").Value = "300-Test"
    lDate = CDate("January 23, 2017")
    BizObject.New
    lMain.FindField("DOCKEY").Value           = -1
    lMain.FindField("DocNo").AsString        = "--PM Test--"
    lMain.FindField("CODE").AsString          = "300-C0001" 'Customer Account
    lMain.FindField("DocDate").Value          = lDate
    lMain.FindField("PostDate").Value        = lDate
    lMain.FindField("Description").AsString  = "Payment for A/c"
    lMain.FindField("PaymentMethod").AsString = "320-000" 'Bank or Cash Account
lMain.FindField("ChequeNumber").AsString  = ""
lMain.FindField("BankCharge").AsFloat    = 0
    lMain.FindField("DocAmt").AsFloat        = 200.00
    lMain.FindField("Cancelled").AsString    = "F"
  'Step 5: Knock Off IV
    lIVNO = "--IV Test--"
    v(0) = "IV"
    v(1) = lIVNO
    if (lDetail.Locate("DocType;DocNo", v, false, false)) then
      lDetail.Edit
      lDetail.FindField("KOAmt").AsFloat    = 147.09 'Partial Knock off
      lDetail.FindField("KnockOff").AsString = "T"
      lDetail.Post
End IF 
  'Step 6: Save Document
    BizObject.Save
    BizObject.Close
End Function
 
Function InsertSLCN
Dim BizObject, lMain, lDetail, lDate
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("SL_CN")
 
  'Step 3: Set Dataset
  Set lMain  = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data 
    
    
   BizObject.Open
   'Step 4 : Insert Data - Master
   BizObject.Edit
  lDate = CDate("January 24, 2017")
   lMainDataSet.Edit
   BizObject.New
   lMainDataSet.FindField("CompanyName").value = "Testing 123-Changed"
   lMain.FindField("DocKey").value        = -1
   lMain.FindField("DocNo").AsString      = "--CN Test--"
   'Step 5 For 1st Branch
   lMain.FindField("DocDate").value        = lDate
    v = "BILLING"
  lMain.FindField("PostDate").value      = lDate
  lMain.FindField("Code").AsString       = "300-C0001"
    if (lDetailDataSet.Locate("BranchName", v, false, false)) then
  lMain.FindField("CompanyName").AsString = "Cash Sales"
  lDetailDataSet.Edit
  lMain.FindField("Address1").AsString   = ""
      lDetailDataSet.FindField("Address1").AsString   = "Address1-Changed"
  lMain.FindField("Address2").AsString   = ""
      lDetailDataSet.FindField("Address2").AsString   = "Address2-Changed"
  lMain.FindField("Address3").AsString   = ""
      lDetailDataSet.FindField("Address3").AsString   = "Address3-Changed"
  lMain.FindField("Address4").AsString   = ""
      lDetailDataSet.FindField("Address4").AsString   = "Address4-Changed"
  lMain.FindField("Phone1").AsString     = ""
      lDetailDataSet.FindField("Attention").AsString = "Attention-Changed"
  lMain.FindField("Description").AsString = "Sales Returned"
      lDetailDataSet.FindField("Phone1").AsString     = "Phone1-Changed"
   
      lDetailDataSet.FindField("Fax1").AsString       = "Fax1-Changed"
  'For With Item Code
      lDetailDataSet.FindField("Email").AsString     = "EmailAddress-Changed"
  lDetail.Append
      lDetailDataSet.Post
  lDetail.FindField("DtlKey").value          = -1
end if
  lDetail.FindField("DocKey").value          = -1
'Step 5 For 2nd Branch
  lDetail.FindField("ItemCode").AsString    = "ANT"
    v = "Branch1"
  lDetail.FindField("Description").AsString = "Sales Item B"
  lDetail.FindField("Description2").AsString = "Product Spoil" 'Reason
    if (lDetailDataSet.Locate("BranchName", v, false, false)) then
  lDetail.FindField("Remark1").AsString     = "--IV Test--"   'Invoice No
      lDetailDataSet.Edit
  lDetail.FindField("Remark2").AsString     = "01 Jan 2017"  'Invoice Date
      lDetailDataSet.FindField("Address1").AsString   = "DAddress1-Changed"
   lDetail.FindField("Qty").AsFloat          = 1
      lDetailDataSet.FindField("Address2").AsString   = "DAddress2-Changed"
  lDetail.FindField("Tax").AsString         = "SR"
      lDetailDataSet.FindField("Address3").AsString   = "DAddress3-Changed"
  lDetail.FindField("TaxRate").AsString     = "6%"
      lDetailDataSet.FindField("Address4").AsString  = "DAddress4-Changed"
  lDetail.FindField("TaxInclusive").value    = 0
      lDetailDataSet.FindField("Attention").AsString = "DAttention-Changed"
  lDetail.FindField("UnitPrice").AsFloat    = 100
      lDetailDataSet.FindField("Phone1").AsString     = "DPhone1-Changed"
  lDetail.FindField("Amount").AsFloat        = 100
      lDetailDataSet.FindField("Fax1").AsString      = "DFax1-Changed"
  lDetail.FindField("TaxAmt").AsFloat        = 6 
      lDetailDataSet.FindField("Email").AsString      = "DEmailAddress-Changed"
  lDetail.Post
      lDetailDataSet.Post
 
  end IF
   'Step 6: Save Document
   'Step 6 Save Customer
   BizObject.Save
   BizObject.Save
   BizObject.Close
   BizObject.Close
   MsgBox "Done"
    
  'Step 7: Knock Off Invoice
  Call KnockIV
End Function
 
Function KnockIV
Dim BizObject, lMain, lDetail, lDate, v(1)
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("AR_CN")
  'Step 3: Set Dataset
  Set lMain  = BizObject.DataSets.Find("MainDataSet") 'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsKnockOff") 'lDetail contains Knock off data 
 
  'Step 4 : Find CN Number
  lDocNo = "--CN Test--"
  lDocKey = BizObject.FindKeyByRef("DocNo", lDocNo)
  BizObject.Params.Find("DocKey").Value = lDocKey
 
  If not IsNull(lDocKey) Then
    BizObject.Open
    BizObject.Edit
    lMain.Edit
  'Step 5: Knock Off IV
    lIVNO = "--IV Test--"
    v(0) = "IV"
    v(1) = lIVNO
    if (lDetail.Locate("DocType;DocNo", v, false, false)) then
      lDetail.Edit
      lDetail.FindField("KOAmt").AsFloat    = 106 'Fully Knock off
      lDetail.FindField("KnockOff").AsString = "T"
      lDetail.Post
End IF   
  'Step 6: Save Document
    BizObject.Save
    BizObject.Close
  END IF
End Function
End Function
</syntaxhighlight>
</syntaxhighlight>
Line 5,941: Line 6,694:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-GL.TrialBalance.RO====
====AR_IV====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! GL Trial Balance  Report Object Script   
! AR_IV Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg GL.TrialBalance.RO.vbs
'Copy below script & paste to notepad & name it as eg AR_IV.vbs
Call GetGLTBData
Call InsertARIV
 
Function CreateSQLAccServer
Function CreateSQLAccServer
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
End Function
 
Function GetGLTBData
Function InsertARIV
Dim ComServer, RptObject, lDataSet, lDataSet2, lDateFrom, lDateTo
Dim ComServer, BizObject, lDataSet, lDataSet2, lDate
 
   'Step 1: Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
     ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"  
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"  
   END IF
   END IF
 
   'Step 2: Find and Create the Report Objects
   'Step 2: Find and Create the Biz Objects
   Set RptObject = ComServer.RptObjects.Find("GL.TrialBalance.RO")  
   Set BizObject = ComServer.BizObjects.Find("AR_IV")  
 
   'Step 3: Spool parameters
   'Step 3: Set Dataset
   RptObject.Params.Find("AllProject").Value      = true
   Set lMainDataSet = BizObject.DataSets.Find("MainDataSet")   'lMainDataSet contains master data
   RptObject.Params.Find("AllAgent").Value        = true
   Set lDetailDataSet = BizObject.DataSets.Find("cdsDocDetail") 'lDetailDataSet contains detail data 
   RptObject.Params.Find("AllArea").Value        = true
 
   RptObject.Params.Find("LedgerType").Value      = "G" 'G = Legder, S = Debtor, P = Supplier
  'Step 4 : Insert Data - Master
   'RptObject.Params.Find("ProjectData").Value    = 'Not use if AllArea is true
  lDate = CDate("January 1, 2016")
   RptObject.Params.Find("ShowZeroBalance").Value = false
   BizObject.New
   RptObject.Params.Find("SortBy").Value          = "PostDate;DocNo"  
  lMainDataSet.FindField("DocKey").value = -1
   RptObject.Params.Find("UseDescription2").Value = false
   lMainDataSet.FindField("DocNo").value = "--IV Test--"
 
   lMainDataSet.FindField("DocDate").value = lDate
   lDateFrom = CDate("October 27, 2016")
   lMainDataSet.FindField("PostDate").value = lDate
   lDateTo = CDate("December 31, 2016")
   lMainDataSet.FindField("Code").value = "300-A0003"
   
   lMainDataSet.FindField("Description").value = "Sales"
   'For Post Date From & Date To'
   
  RptObject.Params.Find("DateFrom").Value      = lDateFrom
  'Step 5: Insert Data - Detail
   RptObject.Params.Find("DateTo").Value        = lDateTo
   'For Tax Inclusive = True with override Tax Amount
 
  lDetailDataSet.Append
   'RptObject.Params.Find("AgentData").Value      = 'Not use if AllAgent is true
  lDetailDataSet.FindField("DtlKey").value = -1
   'RptObject.Params.Find("AreaData").Value      = 'Not use if AllArea is true
   lDetailDataSet.FindField("DocKey").value = -1
  lDetailDataSet.FindField("Account").value = "500-000"
  lDetailDataSet.FindField("Description").value = "Sales Item A"
   lDetailDataSet.FindField("Tax").value = "SR"
   lDetailDataSet.FindField("TaxInclusive").value = 0
   lDetailDataSet.FindField("Amount").value = 410.37
   lDetailDataSet.FindField("TaxAmt").value = 24.63
    
    
   RptObject.Params.Find("SortBy").Value          = "Code;Description"
   lDetailDataSet.DisableControls
   lDetailDataSet.FindField("TaxInclusive").value 1
   'Step 4: Perform Report calculation
   lDetailDataSet.EnableControls
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsGLAccount")
 
  MsgBox "Count " & lDataSet.RecordCount
   
   'Step 5 Retrieve the output
  lDataSet.First
  While (not lDataSet.eof)
    MsgBox "Month To Date"
MsgBox lDataSet.FindField("Code").AsString & " DR=>" & lDataSet.FindField("MTDDR").AsString & " CR=>" & lDataSet.FindField("MTDCR").AsString
MsgBox "Year To Date"
MsgBox lDataSet.FindField("Code").AsString & " DR=>" & lDataSet.FindField("YTDDR").AsString & " CR=>" & lDataSet.FindField("YTDCR").AsString
lDataSet.Next
  Wend
    
    
   'For Account List
   lDetailDataSet.FindField("Changed").value = "F"
  lDataSet2.First
  lDetailDataSet.Post
  While (not lDataSet2.eof)
MsgBox lDataSet2.FindField("Code").AsString & " " & lDataSet2.FindField("Description").AsString
lDataSet2.Next
  Wend
    
    
  'For Tax Inclusive = False with override Tax Amount
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
  lDetailDataSet.FindField("Account").value = "500-000"
  lDetailDataSet.FindField("Description").value =  "Sales Item B"
  lDetailDataSet.FindField("Tax").value =  "SR"
  lDetailDataSet.FindField("TaxInclusive").value =  0
  lDetailDataSet.FindField("Amount").value = 94.43
  lDetailDataSet.FindField("TaxAmt").value = 5.66
  lDetailDataSet.FindField("Changed").value = "F"
  lDetailDataSet.Post
  'Step 6: Save Document
  BizObject.Save
  BizObject.Close
  MsgBox "Done"
End Function
End Function
</syntaxhighlight>
</syntaxhighlight>
Line 6,018: Line 6,775:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Customer.Aging.RO====
====AR_IV-Edit====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Customer Aging  Report Object Script   
! AR_IV Edit Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg customer_aging_ro.vbs
'Available in Version 5.2018.833.759 & above
Call GetCustStatementData
'Copy below script & paste to notepad & name it as eg AR_IV.vbs
Call CheckLogin
Call GetData
Call PostData
 
Dim ComServer, lDataSet
 
Function CreateSQLAccServer
Function CreateSQLAccServer
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
End Function


Function GetCustStatementData
function CheckLogin
Const Quote = """"
Dim ComServer, RptObject, lDataSet, lDataSet2, lDateFrom, lDateTo, lAgeData
   'Step 1: Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
     ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"  
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
                'UserName, Password, DCF full path, Database filename
   END IF
   END IF
End Function
Function GetData
Dim lSQL
  lSQL = "SELECT Dockey FROM AR_IV "
  lSQL = lSQL & "WHERE DocNo='IV-00002' "
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
End Function


   'Step 2: Find and Create the Report Objects
Function PostData
   Set RptObject = ComServer.RptObjects.Find("Customer.Aging.RO")  
Dim BizObject, lMain, lDetail
   'Step 2: Find and Create the Biz Objects
   'Step 3: Spool parameters
   Set BizObject = ComServer.BizObjects.Find("AR_IV")  
   lAgeData = "<?xml version=" & Quote & "1.0" & Quote & " standalone=" & Quote & "yes" & Quote & "?> <DATAPACKET Version=" & Quote & "2.0" & Quote & "><METADATA><FIELDS>" &_
 
      "<FIELD attrname=" & Quote & "ColumnNo" & Quote & " fieldtype=" & Quote & "i4" & Quote & " required=" & Quote & "true" & Quote & "/><FIELD attrname=" & Quote & "ColumnType" & Quote & " fieldtype=" & Quote & "string" & Quote & " WIDTH=" & Quote & "1" & Quote & "/>" &_
   'Step 3: Set Dataset
      "<FIELD attrname=" & Quote & "Param1" & Quote & " fieldtype=" & Quote & "i4" & Quote & " required=" & Quote & "true" & Quote & "/><FIELD attrname=" & Quote & "Param2" & Quote & " fieldtype=" & Quote & "i4" & Quote & " required=" & Quote & "true" & Quote & "/>" &_
   Set lMain  = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
      "<FIELD attrname=" & Quote & "IsLocal" & Quote & " fieldtype=" & Quote & "boolean" & Quote & "/><FIELD attrname=" & Quote & "HeaderScript" & Quote & " fieldtype=" & Quote & "bin.hex" & Quote & " SUBTYPE=" & Quote & "Text" & Quote & " WIDTH=" & Quote & "1" & Quote & "/>" &_
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data  
      "</FIELDS><PARAMS/></METADATA><ROWDATA><ROW ColumnNo=" & Quote & "0" & Quote & " ColumnType=" & Quote & "" & Quote & " Param1=" & Quote & "0" & Quote & " Param2=" & Quote & "0" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & "/>" &_
 
      "<ROW ColumnNo=" & Quote & "1" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "0" & Quote & " Param2=" & Quote & "0" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;Current Mth&apos;&#013;end;" & Quote & "/>" &_
  'Step 4 : Find Doc Number
      "<ROW ColumnNo=" & Quote & "2" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-1" & Quote & " Param2=" & Quote & "-1" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;1 Months&apos;&#013;end;" & Quote & "/>" &_
  If lDataSet.RecordCount > 0 Then 
      "<ROW ColumnNo=" & Quote & "3" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-2" & Quote & " Param2=" & Quote & "-2" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;2 Months&apos;&#013;end;" & Quote & "/>" &_
lDataSet.First
      "<ROW ColumnNo=" & Quote & "4" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-3" & Quote & " Param2=" & Quote & "-3" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;3 Months&apos;&#013;end;" & Quote & "/>" &_
    BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString
      "<ROW ColumnNo=" & Quote & "5" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-4" & Quote & " Param2=" & Quote & "-4" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;4 Months&apos;&#013;end;" & Quote & "/>" &_
 
      "<ROW ColumnNo=" & Quote & "6" & Quote & " ColumnType=" & Quote & "B" & Quote & " Param1=" & Quote & "-999999" & Quote & " Param2=" & Quote & "-5" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;5 Month &amp; above&apos;&#013;end;" & Quote & "/>" &_
 
      "</ROWDATA></DATAPACKET>"
    BizObject.Open
   RptObject.Params.Find("ActualGroupBy").Value        = "Code;CompanyName" 'Fixed
    BizObject.Edit
'  RptObject.Params.Find("AgentData").Value            'Not use if AllAgent is True
    lMain.Edit
   RptObject.Params.Find("AgingData").Value            = lAgeData 'Fixed
lMain.FindField("Description").AsString = "Sales - Edited"  
 
  'Step 5: Delete all Detail
    While lDetail.RecordCount <> 0
      lDetail.First
  lDetail.Delete
    Wend
  'Step 6: Append Detail
  lDetail.Append 
  lDetail.FindField("DtlKey").value = -1
  lDetail.FindField("Account").value = "500-000"
  lDetail.FindField("Description").value = "Sales Item A - Edited"
  lDetail.FindField("Tax").value = "SR"
  lDetail.FindField("TaxRate").value = "6%"
  lDetail.FindField("TaxInclusive").value = 0
  lDetail.FindField("Amount").value = 100
   lDetail.FindField("TaxAmt").value = 6
 
  lDetail.DisableControls
  lDetail.FindField("TaxInclusive").value 1
   lDetail.EnableControls
 
  lDetail.FindField("Changed").value = "F"
  lDetail.Post
 
  'Step 7: Save Document
    BizObject.Save
    BizObject.Close
 
  'Step 8 : Logout after done 
    'ComServer.Logout 
    MsgBox "Done"
Else
MsgBox "Record Not Found"
  END IF
End Function
</syntaxhighlight>
|}


  lDateTo = CDate("August 31, 2016")
<div style="float: right;">   [[#top|[top]]]</div>
   RptObject.Params.Find("AgingDate").Value            = lDateTo 


  RptObject.Params.Find("AgingOn").Value              = "I" 'Fixed
====AR_PM====
  RptObject.Params.Find("AllAgent").Value            = true
  RptObject.Params.Find("AllArea").Value              = true
  RptObject.Params.Find("AllCompany").Value          = false
  RptObject.Params.Find("AllCompanyCategory").Value  = true
  RptObject.Params.Find("AllControlAccount").Value    = true
  RptObject.Params.Find("AllCurrency").Value          = true
  RptObject.Params.Find("AllDocProject").Value        = true
'  RptObject.Params.Find("AreaData").Value            =  'Not use if AllArea is True
'  RptObject.Params.Find("CompanyCategoryData").Value  =  'Not use if AllCompanyCategory is True
  RptObject.Params.Find("CompanyData").Value          = "300-A0001"& vbCRLF & "300-C0001" 'Filter by Customer Code 300-A0001 & 300-C0001
'  RptObject.Params.Find("ControlAccountData").Value  =  'Not use if AllControlAccount is True
'  RptObject.Params.Find("CurrencyData").Value        =  'Not use if AllCurrency is True
'  RptObject.Params.Find("DocProjectData").Value      =  'Not use if AllDocProject is True
  RptObject.Params.Find("FilterPostDate").Value        = false
'  RptObject.Params.Find("GroupBy").Value              = 'Not use
  RptObject.Params.Find("IncludePDC").Value        = false
  RptObject.Params.Find("IncludeZeroBalance").Value  = false
  RptObject.Params.Find("SortBy").Value              = "Code;CompanyName"
  RptObject.Params.Find("DateTo").Value              = lDateTo
 
  'Step 4: Perform Report calculation
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsDocument")
  MsgBox "Count " & lDataSet.RecordCount
 
  'Step 5 Retrieve the output
  lDataSet.First
  While (not lDataSet.eof)
    MsgBox lDataSet.FindField("Code").AsString & " " & lDataSet.FindField("CompanyName").AsString & " " & lDataSet.FindField("C1").AsString
lDataSet2.First
    While (not lDataSet2.eof)
  MsgBox lDataSet2.FindField("DocNo").AsString & " " & lDataSet2.FindField("C1").AsString
  lDataSet2.Next
    Wend
lDataSet.Next
  Wend
End Function
</syntaxhighlight>
|}
 
<div style="float: right;">  [[#top|[top]]]</div>
 
====Example-GL.JE.RO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! GL Journal Voucher Report Object Script   
! AR_PM Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg GLJE_ro.vbs
'Copy below script & paste to notepad & name it as eg AR_PM.vbs
Call GetCustomerData
Call PostData
 
Function CreateSQLAccServer
Function CreateSQLAccServer
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
End Function
 
Function GetCustomerData
Function PostData
Dim ComServer, RptObject, lDataSet, lDataSet2, lDateFrom, lDateTo
Dim ComServer, BizObject, lIVNo, v(1), lDate
   'Step 1: Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
     ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"  
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"  
   END IF
   END IF
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("AR_PM")
  'Step 3: Set Dataset
  Set lMain = BizObject.DataSets.Find("MainDataSet")    'lMainDataSet contains master data
  Set lDetailDataSet = BizObject.DataSets.Find("cdsKnockOff") 'lDetailDataSet contains detail data 
 
  'Step 4 : Posting
    lDate = CDate("January 23, 2017")
    BizObject.New
    lMain.FindField("DOCKEY").Value          = -1
    lMain.FindField("DocNo").AsString        = "--PM Test--"
    lMain.FindField("CODE").AsString          = "300-C0001"
    lMain.FindField("DocDate").Value          = lDate
    lMain.FindField("PostDate").Value        = lDate
    lMain.FindField("Description").AsString  = "Payment for A/c"
    lMain.FindField("PaymentMethod").AsString = "310-000"
    lMain.FindField("DocAmt").AsFloat        = 65.57
    lMain.FindField("Cancelled").AsString    = "F"
  'Step 5: Knock Off IV
    lIVNO = "--IV Test--"
    v(0) = "IV"
    v(1) = lIVNO
    if (lDetailDataSet.Locate("DocType;DocNo", v, false, false)) then
      lDetailDataSet.Edit
      lDetailDataSet.FindField("KOAmt").value = 65.57
      lDetailDataSet.FindField("KnockOff").AsString = "T"
      lDetailDataSet.Post
End IF 
  'Step 6: Save Document
    BizObject.Save
    BizObject.Close
    MsgBox "Done"
  'END IF
End Function
</syntaxhighlight>
|}


  'Step 2: Find and Create the Report Objects
<div style="float: right;">  [[#top|[top]]]</div>
  Set RptObject = ComServer.RptObjects.Find("GL.JE.RO")
 
  'Step 3: Spool parameters
  RptObject.Params.Find("AllCurrency").Value = true
  RptObject.Params.Find("AllDocProject").Value = true
  RptObject.Params.Find("AllDocument").Value = true
  RptObject.Params.Find("AllItemProject").Value = true
  RptObject.Params.Find("AllItemArea").Value = true
  RptObject.Params.Find("AllItemAgent").Value = true
  RptObject.Params.Find("AllDocAgent").Value = true
  RptObject.Params.Find("AllDocArea").Value = true
  RptObject.Params.Find("AllPaymentMethod").Value = true
 
  lDateFrom = CDate("December 1, 2017")
  lDateTo = CDate("December 31, 2017")
 
  RptObject.Params.Find("DateFrom").Value = lDateFrom
  RptObject.Params.Find("DocDateFrom").Value = lDateFrom
  RptObject.Params.Find("DateTo").Value = lDateTo
  RptObject.Params.Find("DocDateTo").Value = lDateTo
  RptObject.Params.Find("IncludeCancelled").Value = false
  RptObject.Params.Find("PrintDocumentStyle").Value = false
  RptObject.Params.Find("SelectDate").Value = true 'Post Date
  RptObject.Params.Find("SelectDocDate").Value = false 'Doc Date
 
  'Step 4: Perform Report calculation
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsDetail")
  MsgBox "Count " & lDataSet.RecordCount
 
  'Step 5 Retrieve the output
  lDataSet.First
  While (not lDataSet.eof)
    MsgBox lDataSet.FindField("DocNo").AsString & " " & lDataSet.FindField("Description").AsString
lDataSet2.First
    While (not lDataSet2.eof)
  MsgBox lDataSet2.FindField("Code").AsString & " " & lDataSet2.FindField("Description").AsString
  lDataSet2.Next
    Wend
lDataSet.Next
  Wend
End Function
</syntaxhighlight>
|}
 
<div style="float: right;">  [[#top|[top]]]</div>
 
====Example-SL_CS====
{| class="mw-collapsible mw-collapsed wikitable"
! SL_CS Script 
|-
|
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg SL_CS.vbs
Call InsertData


====AR_PM-Edit====
{| class="mw-collapsible mw-collapsed wikitable"
! AR_PM Edit Script 
|-
|
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg AR_IV.vbs
Call EditARPM
Function CreateSQLAccServer
Function CreateSQLAccServer
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
End Function
 
Function InsertData
Function EditARPM
Dim ComServer, BizObject, lDate
Dim ComServer, BizObject, lDataSet, lDataSet2, lDocKey, lDocNo, lIVNo, v(1)
 
   'Step 1: Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
Line 6,199: Line 6,952:
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"  
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"  
   END IF
   END IF
 
   'Step 2: Find and Create the Biz Objects
   'Step 2: Find and Create the Biz Objects
   Set BizObject = ComServer.BizObjects.Find("SL_CS")  
   Set BizObject = ComServer.BizObjects.Find("AR_PM")  
 
   'Step 3: Set Dataset
   'Step 3: Set Dataset
   Set lMainDataSet = BizObject.DataSets.Find("MainDataSet")    'lMainDataSet contains master data
   Set lMainDataSet = BizObject.DataSets.Find("MainDataSet")    'lMainDataSet contains master data
   Set lDetailDataSet = BizObject.DataSets.Find("cdsDocDetail") 'lDetailDataSet contains detail data   
   Set lDetailDataSet = BizObject.DataSets.Find("cdsKnockOff") 'lDetailDataSet contains detail data   
 
  'Step 4 : Find OR Number
  lDocNo = "OR-00022"
  lDocKey = BizObject.FindKeyByRef("DocNo", lDocNo)
  BizObject.Params.Find("DocKey").Value = lDocKey
    
    
   'Step 4 : Insert Data - Master
   If not IsNull(lDocKey) Then
  lDate = CDate("January 1, 2016")
    BizObject.Open
  BizObject.New
    BizObject.Edit
  lMainDataSet.FindField("DocKey").value = -1
    lMainDataSet.Edit
  lMainDataSet.FindField("DocNo").value = "--IV Test--"
lMainDataSet.FindField("Description").AsString = "testing"
  lMainDataSet.FindField("DocDate").value = lDate
   'Step 5: Knock Off IV
  lMainDataSet.FindField("PostDate").value = lDate
    lIVNO = "IV-00006"
  lMainDataSet.FindField("Code").value = "300-C0001" 'Customer Code
    v(0) = "IV"
  lMainDataSet.FindField("Description").value = "Sales"
    v(1) = lIVNO
   
   'Step 5: Insert Data - Detail
    if (lDetailDataSet.Locate("DocType;DocNo", v, false, false)) then
  'For Tax Inclusive = True with override Tax Amount
      lDetailDataSet.Edit
  lDetailDataSet.Append
      lDetailDataSet.FindField("KOAmt").value = 50.12
  lDetailDataSet.FindField("DtlKey").value = -1
      lDetailDataSet.FindField("KnockOff").AsString = "T"
  lDetailDataSet.FindField("DocKey").value = -1
      lDetailDataSet.Post
  lDetailDataSet.FindField("Account").value = "500-000" 'Sales Account Code  & can ignore if had itemcode
  MsgBox "yes"
  lDetailDataSet.FindField("Description").value = "Sales Item A"
End IF  
  lDetailDataSet.FindField("Qty").value =  1
   'Step 6: Save Document
  lDetailDataSet.FindField("Tax").value =  "SR"
    BizObject.Save
  lDetailDataSet.FindField("TaxInclusive").value =  0
    BizObject.Close
  lDetailDataSet.FindField("UnitPrice").value = 410.37
    MsgBox "Done"
  lDetailDataSet.FindField("Amount").value = 410.37
   END IF
  lDetailDataSet.FindField("TaxAmt").value = 24.63
End Function
 
</syntaxhighlight>
  lDetailDataSet.DisableControls
|}
  lDetailDataSet.FindField("TaxInclusive").value = 1
 
  lDetailDataSet.EnableControls
<div style="float: right;">   [[#top|[top]]]</div>
 
  lDetailDataSet.Post
 
   'For Tax Inclusive = False with override Tax Amount
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
   lDetailDataSet.FindField("Account").value = "500-000"
  lDetailDataSet.FindField("Description").value =  "Sales Item B"
  lDetailDataSet.FindField("Qty").value =  1
  lDetailDataSet.FindField("Tax").value =  "SR"
  lDetailDataSet.FindField("TaxInclusive").value =  0
  lDetailDataSet.FindField("UnitPrice").value = 94.43
  lDetailDataSet.FindField("Amount").value = 94.43
  lDetailDataSet.FindField("TaxAmt").value = 5.66
   lDetailDataSet.Post


  'For With Item Code
====Customer.RO====
  lDetailDataSet.Append
{| class="mw-collapsible mw-collapsed wikitable"
  lDetailDataSet.FindField("DtlKey").value = -1
! Customer.RO Report Object Script   
  lDetailDataSet.FindField("DocKey").value = -1
  lDetailDataSet.FindField("ItemCode").value = "ANT"
  lDetailDataSet.FindField("Description").value =  "Sales Item B"
  lDetailDataSet.FindField("Qty").value =  2
  lDetailDataSet.FindField("Tax").value =  "SR"
  lDetailDataSet.FindField("TaxInclusive").value = 0
  lDetailDataSet.FindField("UnitPrice").value = 100
  lDetailDataSet.FindField("Amount").value = 200
  lDetailDataSet.FindField("TaxAmt").value = 12
  lDetailDataSet.Post
 
  'Step 6: Save Document
  BizObject.Save
  BizObject.Close
  ComServer.Logout
  MsgBox "Done"
End Function
</syntaxhighlight>
|}
 
<div style="float: right;">  [[#top|[top]]]</div>
 
====Example-Customer.PM.RO====
{| class="mw-collapsible mw-collapsed wikitable"
! Customer.PM.RO Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg Customer.PM.RO.vbs
'Copy below script & paste to notepad & name it as eg customer_ro.vbs
Call GetARPMData
Call GetCustomerData
 
Function CreateSQLAccServer
Function CreateSQLAccServer
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
End Function
 
Function GetARPMData
Function GetCustomerData
Dim ComServer, RptObject, lDataSet, lDataSet2, lDataSet3, lDateFrom, lDateTo
Dim ComServer, RptObject, lDataSet, lDataSet2, lDateFrom, lDateTo
   'Step 1: Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
Line 6,296: Line 7,013:
     ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"  
     ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"  
   END IF
   END IF
 
   'Step 2: Find and Create the Report Objects
   'Step 2: Find and Create the Report Objects
   Set RptObject = ComServer.RptObjects.Find("Customer.PM.RO")  
   Set RptObject = ComServer.RptObjects.Find("Customer.RO")  
 
   'Step 3: Spool parameters
   'Step 3: Spool parameters
   'RptObject.Params.Find("AgentData").Value               = 'Not use if AllAgent is true
   RptObject.Params.Find("AllAgent").Value = true
   'RptObject.Params.Find("CompanyCategoryData").Value     = 'Not use if AllCompanyCategory is true
   RptObject.Params.Find("AllArea").Value = true
   RptObject.Params.Find("AllAgent").Value               = true
   RptObject.Params.Find("AllCompany").Value = false
   RptObject.Params.Find("AllCompanyCategory").Value     = true
   RptObject.Params.Find("AllCompanyCategory").Value = true
   RptObject.Params.Find("AllArea").Value                 = true
   RptObject.Params.Find("AllCurrency").Value = true
   RptObject.Params.Find("AllCompany").Value             = true
   RptObject.Params.Find("AllTerms").Value = true
   RptObject.Params.Find("AllCurrency").Value             = true
   RptObject.Params.Find("SelectDate").Value = true
   RptObject.Params.Find("AllDocument").Value             = false
   RptObject.Params.Find("PrintActive").Value = true
   RptObject.Params.Find("AllPaymentMethod").Value       = true
   RptObject.Params.Find("PrintInactive").Value = false
   'RptObject.Params.Find("AreaData").Value               = 'Not use if AllArea is true
   RptObject.Params.Find("PrintPending").Value = false
   'RptObject.Params.Find("CompanyData").Value             = 'Not use if AllCompany is true
   RptObject.Params.Find("PrintProspect").Value = false
   'RptObject.Params.Find("CurrencyData").Value           = 'Not use if AllCurrency is true
   RptObject.Params.Find("PrintSuspend").Value = false
  lDateFrom = CDate("January 1, 2000")
  lDateTo = CDate("December 31, 2014")


  lDateFrom = CDate("January 01, 2017")
   RptObject.Params.Find("DateFrom").Value = lDateFrom
  lDateTo = CDate("December 31, 2017")
   RptObject.Params.Find("DateTo").Value = lDateTo
 
   RptObject.Params.Find("CompanyData").Value = "300-A0003"
   RptObject.Params.Find("DateFrom").Value               = lDateFrom
   RptObject.Params.Find("DateTo").Value                 = lDateTo
   RptObject.Params.Find("DocumentData").Value           = "VCOR-00049"
  'RptObject.Params.Find("GroupBy").Value                = 'If you wanted to grouping the data
  RptObject.Params.Find("IncludeCancelled").Value        = false
  'RptObject.Params.Find("PaymentMethodData").Value      = 'Not use if AllPaymentMethod is true
  RptObject.Params.Find("PrintDocumentStyle").Value      = false
  RptObject.Params.Find("SelectDate").Value              = true
  RptObject.Params.Find("ShowUnappliedAmountOnly").Value = false
  RptObject.Params.Find("SortBy").Value                  = "PostDate;DocNo;Code"
  RptObject.Params.Find("AllDocProject").Value          = true
  RptObject.Params.Find("AllItemProject").Value          = true
  'RptObject.Params.Find("DocProjectData").Value          = 'Not use if AllDocProject is true
  'RptObject.Params.Find("ItemProjectData").Value        = 'Not use if AllItemProject is true 
    
    
   'Step 4: Perform Report calculation  
   'Step 4: Perform Report calculation  
   RptObject.CalculateReport()
   RptObject.CalculateReport()
   Set lDataSet = RptObject.DataSets.Find("cdsMain")
   Set lDataSet = RptObject.DataSets.Find("cdsMain")
   Set lDataSet2 = RptObject.DataSets.Find("cdsKnockOff")
   Set lDataSet2 = RptObject.DataSets.Find("cdsBranch")
  Set lDataSet3 = RptObject.DataSets.Find("cdsKnockOffDetail")
   MsgBox "Count " & lDataSet.RecordCount
   MsgBox "Count " & lDataSet.RecordCount
 
   'Step 5 Retrieve the output  
   'Step 5 Retrieve the output  
   lDataSet.First
   lDataSet.First
   While (not lDataSet.eof)
   While (not lDataSet.eof)
     MsgBox lDataSet.FindField("DocKey").AsString & " " & lDataSet.FindField("DocNo").AsString & " " & lDataSet.FindField("Code").AsString
     MsgBox lDataSet.FindField("Code").AsString & " " & lDataSet.FindField("CompanyName").AsString
MsgBox "cdsKnockOff Count " & lDataSet2.RecordCount
lDataSet2.First
lDataSet2.First
     While (not lDataSet2.eof)
     While (not lDataSet2.eof)
  MsgBox lDataSet2.FindField("FromDocKey").AsString & " " & lDataSet2.FindField("DocNo").AsString & " " & lDataSet2.FindField("KOAmt").AsString
  MsgBox lDataSet2.FindField("Address1").AsString
  lDataSet2.Next
  lDataSet2.Next
     Wend
     Wend
    MsgBox "cdsKnockOffDetail Count " & lDataSet3.RecordCount
lDataSet3.First
    While (not lDataSet3.eof)
      MsgBox lDataSet3.FindField("FromDocKey").AsString & " " & lDataSet3.FindField("DocNo").AsString & " " & lDataSet3.FindField("KOAmt").AsString
    lDataSet3.Next
    Wend
lDataSet.Next
lDataSet.Next
   Wend
   Wend
Line 6,363: Line 7,060:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Sales.IV.RO====
====Customer.Statement.RO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Sales.IV.RO Script   
! Customer.Statement.RO Report Object Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg Sales.IV.RO.vbs
'Copy below script & paste to notepad & name it as eg customer_statement_ro.vbs
Call GetSalesIVData
Call GetCustStatementData
   
   
Function CreateSQLAccServer
Function CreateSQLAccServer
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
End Function
 
Function GetSalesIVData
Function GetCustStatementData
Dim ComServer, RptObject, lDataSet, lDataSet2, lDataSet3, lDateFrom, lDateTo
Const Quote = """"
Dim ComServer, RptObject, lDataSet, lDataSet2, lDateFrom, lDateTo, lAgeData
   'Step 1: Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
Line 6,383: Line 7,081:
     ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"  
     ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"  
   END IF
   END IF
 
   'Step 2: Find and Create the Report Objects
   'Step 2: Find and Create the Report Objects
   Set RptObject = ComServer.RptObjects.Find("Sales.IV.RO")  
   Set RptObject = ComServer.RptObjects.Find("Customer.Statement.RO")  
   
   
   'Step 3: Spool parameters
   'Step 3: Spool parameters
   'RptObject.Params.Find("AgentData").Value             = 'Not use if AllAgent is true
   lAgeData = "<?xml version=" & Quote & "1.0" & Quote & " standalone=" & Quote & "yes" & Quote & "?>  <DATAPACKET Version=" & Quote & "2.0" & Quote & "><METADATA><FIELDS>" &_
   RptObject.Params.Find("AllAgent").Value               = true
      "<FIELD attrname=" & Quote & "ColumnNo" & Quote & " fieldtype=" & Quote & "i4" & Quote & " required=" & Quote & "true" & Quote & "/><FIELD attrname=" & Quote & "ColumnType" & Quote & " fieldtype=" & Quote & "string" & Quote & " WIDTH=" & Quote & "1" & Quote & "/>" &_
   RptObject.Params.Find("AllArea").Value               = true
      "<FIELD attrname=" & Quote & "Param1" & Quote & " fieldtype=" & Quote & "i4" & Quote & " required=" & Quote & "true" & Quote & "/><FIELD attrname=" & Quote & "Param2" & Quote & " fieldtype=" & Quote & "i4" & Quote & " required=" & Quote & "true" & Quote & "/>" &_
   RptObject.Params.Find("AllCompany").Value            = false
      "<FIELD attrname=" & Quote & "IsLocal" & Quote & " fieldtype=" & Quote & "boolean" & Quote & "/><FIELD attrname=" & Quote & "HeaderScript" & Quote & " fieldtype=" & Quote & "bin.hex" & Quote & " SUBTYPE=" & Quote & "Text" & Quote & " WIDTH=" & Quote & "1" & Quote & "/>" &_
   RptObject.Params.Find("AllCurrency").Value           = true
      "</FIELDS><PARAMS/></METADATA><ROWDATA><ROW ColumnNo=" & Quote & "0" & Quote & " ColumnType=" & Quote & "" & Quote & " Param1=" & Quote & "0" & Quote & " Param2=" & Quote & "0" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & "/>" &_
   RptObject.Params.Find("AllDocProject").Value         = true
      "<ROW ColumnNo=" & Quote & "1" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "0" & Quote & " Param2=" & Quote & "0" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;Current Mth&apos;&#013;end;" & Quote & "/>" &_
   RptObject.Params.Find("AllDocument").Value           = true
      "<ROW ColumnNo=" & Quote & "2" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-1" & Quote & " Param2=" & Quote & "-1" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;1 Months&apos;&#013;end;" & Quote & "/>" &_
   RptObject.Params.Find("AllItem").Value               = true
      "<ROW ColumnNo=" & Quote & "3" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-2" & Quote & " Param2=" & Quote & "-2" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;2 Months&apos;&#013;end;" & Quote & "/>" &_
   RptObject.Params.Find("AllItemProject").Value         = true
      "<ROW ColumnNo=" & Quote & "4" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-3" & Quote & " Param2=" & Quote & "-3" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;3 Months&apos;&#013;end;" & Quote & "/>" &_
   RptObject.Params.Find("AllLocation").Value           = true
      "<ROW ColumnNo=" & Quote & "5" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-4" & Quote & " Param2=" & Quote & "-4" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;4 Months&apos;&#013;end;" & Quote & "/>" &_
  RptObject.Params.Find("AllStockGroup").Value         = true
      "<ROW ColumnNo=" & Quote & "6" & Quote & " ColumnType=" & Quote & "B" & Quote & " Param1=" & Quote & "-999999" & Quote & " Param2=" & Quote & "-5" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;5 Month &amp; above&apos;&#013;end;" & Quote & "/>" &_
  RptObject.Params.Find("AllCompanyCategory").Value     = true
      "</ROWDATA></DATAPACKET>"
   RptObject.Params.Find("AllBatch").Value               = true
' RptObject.Params.Find("AgentData").Value           = 'Not use if AllAgent is True
  RptObject.Params.Find("AllTariff").Value             = true 'For Version 776 & above
   RptObject.Params.Find("AgingData").Value           = lAgeData 'Fixed
  'RptObject.Params.Find("TariffData").Value             = 'Not use if TariffData is true - For Version 776 & above
   RptObject.Params.Find("AgingOn").Value             = "I" 'Fixed
   'RptObject.Params.Find("AreaData").Value               = 'Not use if AllArea is true
   RptObject.Params.Find("AllAgent").Value            = true
   'RptObject.Params.Find("CompanyCategoryData").Value   = 'Not use if AllCompanyCategory is true
   RptObject.Params.Find("AllArea").Value             = true
   RptObject.Params.Find("CompanyData").Value           = "300-C0001"
   RptObject.Params.Find("AllCompany").Value           = false
   'RptObject.Params.Find("CurrencyData").Value           = 'Not use if AllCurrency is true
   RptObject.Params.Find("AllCompanyCategory").Value   = true
   RptObject.Params.Find("AllControlAccount").Value   = true
   RptObject.Params.Find("AllCurrency").Value         = true
   RptObject.Params.Find("AllDocProject").Value       = true
RptObject.Params.Find("AreaData").Value             = 'Not use if AllArea is True
RptObject.Params.Find("CompanyCategoryData").Value = 'Not use if AllCompanyCategory is True
   RptObject.Params.Find("CompanyData").Value         = "300-A0001"& vbCRLF & "300-C0001" 'Filter by Customer Code 300-A0001 & 300-C0001
RptObject.Params.Find("ControlAccountData").Value   = 'Not use if AllControlAccount is True
' RptObject.Params.Find("CurrencyData").Value         = 'Not use if AllCurrency is True
  lDateFrom = CDate("August 1, 2016")
  lDateTo = CDate("August 31, 2016")
  RptObject.Params.Find("DateFrom").Value            = lDateFrom
   RptObject.Params.Find("DateTo").Value              = lDateTo
' RptObject.Params.Find("DocProjectData").Value       = 'Not use if AllDocProject is True
  RptObject.Params.Find("IncludeZeroBalance").Value  = false
   RptObject.Params.Find("SelectDate").Value           = true
   RptObject.Params.Find("SortBy").Value               = "CompanyCategory;Code;CompanyName;Agent;Area;CurrencyCode;ControlAccount"
   RptObject.Params.Find("StatementDate").Value        = lDateTo ' Norm same as DateTo
  RptObject.Params.Find("StatementType").Value       = "O" 'O = Open Item, B = B/F
  'Step 4: Perform Report calculation
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsDocument")
  MsgBox "Count " & lDataSet.RecordCount


  lDateFrom = CDate("January 01, 2017")
   'Step 5 Retrieve the output  
  lDateTo = CDate("December 31, 2017")
   lDataSet.First
 
   While (not lDataSet.eof)
  RptObject.Params.Find("DateFrom").Value                = lDateFrom
     MsgBox lDataSet.FindField("Code").AsString & " " & lDataSet.FindField("CompanyName").AsString & " " & lDataSet.FindField("Balance").AsString
  RptObject.Params.Find("DateTo").Value                  = lDateTo
lDataSet2.First
  'RptObject.Params.Find("DocProjectData").Value          = 'Not use if AllDocProject is true
     While (not lDataSet2.eof)
  'RptObject.Params.Find("DocumentData").Value            = 'Not use if AllDocument is true
  MsgBox lDataSet2.FindField("DocNo").AsString
  'RptObject.Params.Find("GroupBy").Value                = 'If you wanted to grouping the data
  'RptObject.Params.Find("CategoryData").Value            = 'Not use if HasCategory is false
  'RptObject.Params.Find("CategoryTpl").Value            = 'For Internal use only
  RptObject.Params.Find("IncludeCancelled").Value        = false
  RptObject.Params.Find("HasCategory").Value            = false
  'RptObject.Params.Find("ItemData").Value                = 'Not use if AllItem is true
  'RptObject.Params.Find("ItemProjectData").Value        = 'Not use if AllItemProject is true
  'RptObject.Params.Find("LocationData").Value            = 'Not use if AllLocation is true
  'RptObject.Params.Find("ItemCategoryData").Value        = 'For Internal use only
  'RptObject.Params.Find("BatchData").Value              = 'Not use if AllBatch is true
  RptObject.Params.Find("PrintDocumentStyle").Value      = false
  RptObject.Params.Find("SelectDate").Value              = true
  RptObject.Params.Find("SortBy").Value                  = "PostDate;DocNo;Code"
  'RptObject.Params.Find("StockGroupData").Value          = 'Not use if AllStockGroup is true
 
 
  'Step 4: Perform Report calculation
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsDocDetail")
  MsgBox "Count " & lDataSet.RecordCount
   'Step 5 Retrieve the output  
   lDataSet.First
   While (not lDataSet.eof)
     MsgBox lDataSet.FindField("DocKey").AsString & " " & lDataSet.FindField("DocNo").AsString & " " & lDataSet.FindField("Code").AsString
MsgBox "cdsDocDetail Count " & lDataSet2.RecordCount
lDataSet2.First
     While (not lDataSet2.eof)
  MsgBox lDataSet2.FindField("DocKey").AsString & " " & lDataSet2.FindField("ItemCode").AsString & " " & lDataSet2.FindField("Amount").AsString
  lDataSet2.Next
  lDataSet2.Next
     Wend
     Wend
lDataSet.Next
lDataSet.Next
   Wend
   Wend
Line 6,455: Line 7,147:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Customer.DueDocument.RO====
====GL.CB.RO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Customer.DueDocument.RO Script   
! GL.CB.RO Report Object Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg Customer.DueDocument.RO.vbs
'Copy below script & paste to notepad & name it as eg GL.CB.RO.vbs
Call GetData
Call GetCLCBData
   
   
Function CreateSQLAccServer
Function CreateSQLAccServer
Line 6,468: Line 7,160:
End Function
End Function
   
   
Function GetData
Function GetCLCBData
Dim ComServer, RptObject, lDataSet, lDateTo
Dim ComServer, RptObject, lDataSet, lDataSet2, lDataSet3, lDateFrom, lDateTo
   'Step 1: Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
Line 6,477: Line 7,169:
   
   
   'Step 2: Find and Create the Report Objects
   'Step 2: Find and Create the Report Objects
   Set RptObject = ComServer.RptObjects.Find("Customer.DueDocument.RO")  
   Set RptObject = ComServer.RptObjects.Find("GL.CB.RO")  
   
   
   'Step 3: Spool parameters
   'Step 3: Spool parameters
   'RptObject.Params.Find("AgentData").Value             = 'Not use if AllAgent is true
   RptObject.Params.Find("AllCurrency").Value   = true
   RptObject.Params.Find("AllAgent").Value               = true
   RptObject.Params.Find("AllDocProject").Value = true
   RptObject.Params.Find("AllArea").Value               = true
   RptObject.Params.Find("AllDocument").Value   = true
   RptObject.Params.Find("AllCompany").Value             = false
   RptObject.Params.Find("AllItemProject").Value = true
  RptObject.Params.Find("AllCompanyCategory").Value    = true
   RptObject.Params.Find("AllItemArea").Value   = true
   RptObject.Params.Find("AllCurrency").Value           = true
   RptObject.Params.Find("AllItemAgent").Value  = true
   RptObject.Params.Find("AllDocProject").Value         = true
   RptObject.Params.Find("AllDocAgent").Value   = true
   RptObject.Params.Find("AllItemProject").Value        = true
   RptObject.Params.Find("AllDocArea").Value     = true
   'RptObject.Params.Find("AreaData").Value             = 'Not use if AllArea is true
   RptObject.Params.Find("AllPaymentMethod").Value = false
   'RptObject.Params.Find("CompanyCategoryData").Value   = 'Not use if AllCompanyCategory is true
   'RptObject.Params.Find("CurrencyData").Value   = 'Not use if AllCurrency is true
   RptObject.Params.Find("CompanyData").Value           = "300-A0003"
   'RptObject.Params.Find("CurrencyData").Value         = 'Not use if AllCurrency is true
  'RptObject.Params.Find("DocProjectData").Value        = 'Not use if AllDocProject is true
  'RptObject.Params.Find("GroupBy").Value              = 'If you wanted to grouping the data
  'RptObject.Params.Find("ItemProjectData").Value      = 'Not use if AllItemProject is true
  RptObject.Params.Find("PrintContra").Value            = true
  RptObject.Params.Find("PrintCreditNote").Value        = true
  RptObject.Params.Find("PrintDebitNote").Value        = true
  RptObject.Params.Find("PrintInvoice").Value          = true
  RptObject.Params.Find("PrintOverDue").Value          = true
  RptObject.Params.Find("PrintUnDue").Value            = true
  RptObject.Params.Find("ShowForeignCurrency").Value    = true
  RptObject.Params.Find("ShowLocalCurrency").Value      = true
  RptObject.Params.Find("SortBy").Value                = "PostDate;DocNo;Code"
    
    
   lDateTo = CDate("April 12, 2018")
  lDateFrom = CDate("January 01, 2017")
   lDateTo = CDate("December 31, 2017")
  'For Post Date From & Date To'
  RptObject.Params.Find("DateFrom").Value = lDateFrom
  RptObject.Params.Find("DateTo").Value  = lDateTo
    
    
   RptObject.Params.Find("DateTo").Value                 = lDateTo
   'RptObject.Params.Find("DocProjectData").Value = 'Not use if AllDocProject is true
   RptObject.Params.Find("IncludePDCheque").Value       = true   
  'RptObject.Params.Find("DocAreaData").Value    = 'Not use if AllDocArea is true
      
  'RptObject.Params.Find("DocAgentData").Value    = 'Not use if AllDocAgent is true
  'RptObject.Params.Find("ItemAgentData").Value  = 'Not use if AllItemAgent is true
  RptObject.Params.Find("DocType").Value          = "PV" 'PV for Payment Voucher & OR for Official Receipt
   'RptObject.Params.Find("DocumentData").Value   = 'Not use if AllDocument is true
  'RptObject.Params.Find("GroupBy").Value        = 'If you wanted to grouping the data
  RptObject.Params.Find("IncludeCancelled").Value = false
  'RptObject.Params.Find("ItemAreaData").Value    = 'Not use if AllItemArea is true
  'RptObject.Params.Find("ItemProjectData").Value = 'Not use if AllItemProject is true
  RptObject.Params.Find("PaymentMethodData").Value = "310-001"
  RptObject.Params.Find("PrintDocumentStyle").Value = false
  RptObject.Params.Find("SelectDate").Value        = true 'For Post Date
  'RptObject.Params.Find("SelectDocDate").Value     = 'For Doc Date
  RptObject.Params.Find("SortBy").Value            = "PostDate;DocNo"
   'Step 4: Perform Report calculation  
   'Step 4: Perform Report calculation  
   RptObject.CalculateReport()
   RptObject.CalculateReport()
   Set lDataSet = RptObject.DataSets.Find("cdsMain")
   Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsDetail")
  Set lDataSet3 = RptObject.DataSets.Find("cdsTax")
   MsgBox "Count " & lDataSet.RecordCount
   MsgBox "Count " & lDataSet.RecordCount
   
   
Line 6,518: Line 7,216:
   lDataSet.First
   lDataSet.First
   While (not lDataSet.eof)
   While (not lDataSet.eof)
     MsgBox "Dockey " & lDataSet.FindField("DocKey").AsString  
     MsgBox lDataSet.FindField("DocNo").AsString & " " & lDataSet.FindField("Description").AsString
MsgBox "DocNo " & lDataSet.FindField("DocNo").AsString  
lDataSet2.First
MsgBox "DocAmt " & lDataSet.FindField("DocAmt").AsString
    While (not lDataSet2.eof)
MsgBox "Outstanding " & lDataSet.FindField("Outstanding").AsString
  MsgBox lDataSet2.FindField("Code").AsString & " " & lDataSet2.FindField("Description").AsString
MsgBox "Code " & lDataSet.FindField("Code").AsString
  lDataSet2.Next
    Wend
lDataSet.Next
lDataSet.Next
  Wend
  'For GST List
  MsgBox "GST Code Count " & lDataSet3.RecordCount
  lDataSet3.First
  While (not lDataSet3.eof)
    MsgBox lDataSet3.FindField("Code").AsString
lDataSet3.Next
   Wend
   Wend
End Function
End Function
Line 6,531: Line 7,237:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Customer.IV.RO====
====AR_Customer====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Customer.IV.RO Script   
! AR_Customer - Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg Customer.IV.RO.vbs
'Copy below script & paste to notepad & name it as eg AR_Customer.vbs
Call GetData
Call CheckLogin
Call InsertData
 
Dim ComServer
 
Function CreateSQLAccServer
Function CreateSQLAccServer
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
End Function
 
Function GetData
function CheckLogin
Dim ComServer, RptObject, lDataSet, lDataSet2, lDataSet3, lDateFrom, lDateTo
   'Step 1: Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
     ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"  
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
                'UserName, Password, DCF full path, Database filename
   END IF
   END IF
End Function
   'Step 2: Find and Create the Report Objects
 
   Set RptObject = ComServer.RptObjects.Find("Customer.IV.RO")  
Function InsertData
Dim BizObject, lMain, lDetail
   'Step 3: Spool parameters
   'Step 2: Find and Create the Biz Objects
   'RptObject.Params.Find("AgentData").Value            = 'Not use if AllAgent is true
   Set BizObject = ComServer.BizObjects.Find("AR_Customer")  
  'RptObject.Params.Find("CompanyCategoryData").Value  = 'Not use if AllCompanyCategory is true
 
   RptObject.Params.Find("AllAgent").Value              = true
   'Step 3: Set Dataset
  RptObject.Params.Find("AllCompanyCategory").Value    = true
   Set lMain   = BizObject.DataSets.Find("MainDataSet") 'lMain contains master data
  RptObject.Params.Find("AllArea").Value                = true
   Set lDetail = BizObject.DataSets.Find("cdsBranch") 'lDetail contains detail data 
  RptObject.Params.Find("AllCompany").Value            = true
  RptObject.Params.Find("AllCurrency").Value            = true
  RptObject.Params.Find("AllDocument").Value            = false
  RptObject.Params.Find("AllPaymentMethod").Value      = true
  'RptObject.Params.Find("AreaData").Value              = 'Not use if AllArea is true
   'RptObject.Params.Find("CompanyData").Value          = 'Not use if AllCompany is true
  'RptObject.Params.Find("CurrencyData").Value          = 'Not use if AllCurrency is true
    
    
   lDateFrom = CDate("January 01, 2017")
   'Begin Looping yr data
   lDateTo = CDate("December 31, 2017")
  'Step 4 : Insert Data - Master
  BizObject.New
  lMain.FindField("Code").AsString      = "300-Test"
  lMain.FindField("CompanyName").AsString = "Cash Sales"
   
   'Step 5: Insert Data - Detail
  'For 1st Branch
  lDetail.Edit
  lDetail.FindField("BranchName").AsString  = "BILLING"
  lDetail.FindField("Address1").AsString    = "Address1"
  lDetail.FindField("Address2").AsString    = "Address2"
  lDetail.FindField("Address3").AsString    = "Address3"
  lDetail.FindField("Address4").AsString    = "Address4" 
  lDetail.FindField("Attention").AsString  = "Attention" 
  lDetail.FindField("Phone1").AsString      = "Phone1"
  lDetail.FindField("Fax1").AsString        = "Fax1"
  lDetail.FindField("Email").AsString      = "EmailAddress"
  lDetail.Post
    
    
   RptObject.Params.Find("DateFrom").Value                = lDateFrom
   'For 2nd Branch
   RptObject.Params.Find("DateTo").Value                  = lDateTo
  lDetail.Append
   RptObject.Params.Find("DocumentData").Value            = "IV-00012"
  lDetail.FindField("BranchName").AsString  = "Branch1"
   'RptObject.Params.Find("GroupBy").Value                = 'If you wanted to grouping the data
   lDetail.FindField("Address1").AsString    = "DAddress1"
  RptObject.Params.Find("IncludeCancelled").Value        = true
   lDetail.FindField("Address2").AsString    = "DAddress2"
   'RptObject.Params.Find("PaymentMethodData").Value      = 'Not use if AllPaymentMethod is true
   lDetail.FindField("Address3").AsString    = "DAddress3"
  RptObject.Params.Find("PrintDocumentStyle").Value      = false
   lDetail.FindField("Address4").AsString    = "DAddress4"
   RptObject.Params.Find("SelectDate").Value              = true
   lDetail.FindField("Attention").AsString  = "DAttention"
  RptObject.Params.Find("ShowUnappliedAmountOnly").Value = true
   lDetail.FindField("Phone1").AsString      = "DPhone1"
   RptObject.Params.Find("SortBy").Value                  = "DocDate;DocNo;Code"
   lDetail.FindField("Fax1").AsString        = "DFax1"
   RptObject.Params.Find("AllDocProject").Value          = true
   lDetail.FindField("Email").AsString      = "DEmailAddress"
   RptObject.Params.Find("AllItemProject").Value          = true
   lDetail.Post
  'RptObject.Params.Find("DocProjectData").Value        = 'Not use if AllDocProject is true
 
   'RptObject.Params.Find("ItemProjectData  ").Value      = 'Not use if AllItemProject is true
   'Step 6: Save Document
   
   BizObject.Save
   'Step 4: Perform Report calculation
   BizObject.Close
   RptObject.CalculateReport()
   Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsDocDetail")
  MsgBox "Count " & lDataSet.RecordCount
   
   
   'Step 5 Retrieve the output
  'End Looping yr data
   lDataSet.First
 
   While (not lDataSet.eof)
   'Step 7 : Logout after done 
    MsgBox "DocNo " & lDataSet.FindField("DocNo").AsString
   'ComServer.Logout
MsgBox "DocAmt " & lDataSet.FindField("DocAmt").AsString
    
MsgBox "PaymentAmt " & lDataSet.FindField("PaymentAmt").AsString
  MsgBox "Done"
MsgBox "cdsDocDetail Count " & lDataSet2.RecordCount
lDataSet2.First
    While (not lDataSet2.eof)
  MsgBox "Account " & lDataSet2.FindField("Account").AsString
  MsgBox "Description " & lDataSet2.FindField("Description").AsString
  MsgBox "Amount " & lDataSet2.FindField("Amount").AsString
  lDataSet2.Next
    Wend
lDataSet.Next
  Wend
End Function
End Function
</syntaxhighlight>
</syntaxhighlight>
Line 6,616: Line 7,320:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Sales.OutstandingSO.RO====
====AR_Customer-Edit====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Sales.OutstandingSO.RO Script   
! AR_Customer - Edit Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg Sales.OutstandingSO.RO.vbs
'Copy below script & paste to notepad & name it as eg AR_Customer.vbs
Call GetData
Call EditARCustomer
   
   
Function CreateSQLAccServer
Function CreateSQLAccServer
Line 6,629: Line 7,333:
End Function
End Function
   
   
Function GetData
Function EditARCustomer
Dim ComServer, RptObject, lDataSet, lDataSet2, lDataSet3, lDateFrom, lDateTo
Dim ComServer, BizObject, lDataSet, lDataSet2
   'Step 1: Create Com Server object
   'Step 1 Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
     ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"  
     ComServer.Login "ADMIN", "ADMIN", "C\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"  
   END IF
   END IF
   
   
   'Step 2: Find and Create the Report Objects
   'Step 2 Find and Create the Biz Objects
   Set RptObject = ComServer.RptObjects.Find("Sales.OutstandingSO.RO")  
   Set BizObject = ComServer.BizObjects.Find("AR_Customer")  
   
   
   'Step 3: Spool parameters
   'Step 3 Set Dataset
   'RptObject.Params.Find("AgentData").Value            = 'Not use if AllAgent is true
   Set lMainDataSet = BizObject.DataSets.Find("MainDataSet") 'lMainDataSet contains master data
  'RptObject.Params.Find("CompanyCategoryData").Value  = 'Not use if AllCompanyCategory is true
   Set lDetailDataSet = BizObject.DataSets.Find("cdsBranch") 'lDetailDataSet contains detail data 
   'RptObject.Params.Find("LocationData").Value        = 'Not use if AllLocation is true
  'RptObject.Params.Find("StockGroupData").Value      = 'Not use if AllStockGroup is true
  RptObject.Params.Find("AllAgent").Value              = true
  RptObject.Params.Find("AllArea").Value              = true
  RptObject.Params.Find("AllCompany").Value            = true
  RptObject.Params.Find("AllDocument").Value          = false
  RptObject.Params.Find("AllItem").Value              = true
  RptObject.Params.Find("AllItemProject").Value        = true
  'RptObject.Params.Find("AreaData").Value              = 'Not use if AllArea is true
  'RptObject.Params.Find("CompanyData").Value          = 'Not use if AllCompany is true
  RptObject.Params.Find("AllTariff").Value              = true 'For Version 776 & above
  'RptObject.Params.Find("TariffData").Value            = 'Not use if TariffData is true - For Version 776 & above
 
    
    
   lDateFrom = CDate("January 01, 2017")
   'Step 4 Find Customer Code
  lDateTo = CDate("December 31, 2017")
  BizObject.Params.Find("Code").Value = "300-Test"
    
    
   'RptObject.Params.Find("DateFrom").Value              = lDateFrom
   BizObject.Open
  'RptObject.Params.Find("DateTo").Value                = lDateTo
   BizObject.Edit
   'RptObject.Params.Find("DeliveryDateFrom").Value      = lDateFrom
   lMainDataSet.Edit
   'RptObject.Params.Find("DeliveryDateTo").Value        = lDateTo
   lMainDataSet.FindField("CompanyName").value = "Testing 123-Changed"
   RptObject.Params.Find("DocumentData").Value          = "SO-00007"& vbCRLF & "SO-00009"
   'RptObject.Params.Find("GroupBy").Value              = 'If you wanted to grouping the data
   'Step 5 For 1st Branch
  RptObject.Params.Find("IncludeCancelled").Value      = false
    v = "BILLING"
  'RptObject.Params.Find("ItemData").Value              = 'Not use if AllItem is true
  RptObject.Params.Find("PrintFulfilledItem").Value    = true 'Print transfered info
    if (lDetailDataSet.Locate("BranchName", v, false, false)) then
  RptObject.Params.Find("PrintOutstandingItem").Value   = true 'Print untransfer info
  lDetailDataSet.Edit
  'RptObject.Params.Find("ItemProjectData").Value       = 'Not use if AllItemProject is true
      lDetailDataSet.FindField("Address1").AsString   = "Address1-Changed"
  RptObject.Params.Find("SelectDate").Value            = false
       lDetailDataSet.FindField("Address2").AsString  = "Address2-Changed"
  RptObject.Params.Find("SelectDeliveryDate").Value    = false
      lDetailDataSet.FindField("Address3").AsString  = "Address3-Changed"
  RptObject.Params.Find("SortBy").Value                = "DocDate;DocNo;Code"
      lDetailDataSet.FindField("Address4").AsString  = "Address4-Changed"
  RptObject.Params.Find("AllDocProject").Value          = true
      lDetailDataSet.FindField("Attention").AsString  = "Attention-Changed"
  RptObject.Params.Find("AllLocation").Value            = true
      lDetailDataSet.FindField("Phone1").AsString    = "Phone1-Changed"
  RptObject.Params.Find("AllCompanyCategory").Value    = true
      lDetailDataSet.FindField("Fax1").AsString      = "Fax1-Changed"
  RptObject.Params.Find("AllBatch").Value              = true
      lDetailDataSet.FindField("Email").AsString     = "EmailAddress-Changed"
  RptObject.Params.Find("HasCategory").Value            = false
      lDetailDataSet.Post
  RptObject.Params.Find("AllStockGroup").Value          = true
end if
  'RptObject.Params.Find("CategoryData").Value          = 'For Internal use only
'Step 5 For 2nd Branch
  'RptObject.Params.Find("CategoryTpl").Value          = 'For Internal use only
    v = "Branch1"
  'RptObject.Params.Find("ItemCategoryData").Value     = 'For Internal use only
  'RptObject.Params.Find("DocProjectData").Value        = 'Not use if AllDocProject is true
  'RptObject.Params.Find("BatchData").Value            = 'Not use if AllBatch is true
  RptObject.Params.Find("TranferDocFilterDate").Value  = false
 
   
  'Step 4: Perform Report calculation
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsTransfer")
  MsgBox "Count " & lDataSet.RecordCount
   
   
  'Step 5 Retrieve the output
    if (lDetailDataSet.Locate("BranchName", v, false, false)) then
  lDataSet.First
      lDetailDataSet.Edit
  While (not lDataSet.eof)
      lDetailDataSet.FindField("Address1").AsString   = "DAddress1-Changed"
    MsgBox "DocKey " & lDataSet.FindField("DocKey").AsString
      lDetailDataSet.FindField("Address2").AsString   = "DAddress2-Changed"
MsgBox "DtlKey " & lDataSet.FindField("Dtlkey").AsString
      lDetailDataSet.FindField("Address3").AsString   = "DAddress3-Changed"
MsgBox "DocNo " & lDataSet.FindField("DocNo").AsString
      lDetailDataSet.FindField("Address4").AsString   = "DAddress4-Changed"
MsgBox "Item Code " & lDataSet.FindField("ItemCode").AsString
      lDetailDataSet.FindField("Attention").AsString = "DAttention-Changed"
MsgBox "Org Qty " & lDataSet.FindField("SQty").AsString
       lDetailDataSet.FindField("Phone1").AsString     = "DPhone1-Changed"
MsgBox "Outstanding Qty " & lDataSet.FindField("OutstandingQty").AsString
      lDetailDataSet.FindField("Fax1").AsString       = "DFax1-Changed"
      lDetailDataSet.FindField("Email").AsString     = "DEmailAddress-Changed"
MsgBox "cdsDocDetail Count " & lDataSet2.RecordCount
      lDetailDataSet.Post 
lDataSet2.First
  end IF
    While (not lDataSet2.eof)
  'Step 6 Save Customer
       MsgBox "FromDocKey " & lDataSet2.FindField("FromDocKey").AsString
  BizObject.Save
  MsgBox "FromDtlKey " & lDataSet2.FindField("FromDtlkey").AsString
  BizObject.Close
  MsgBox "DocType " & lDataSet2.FindField("DocType").AsString
   MsgBox "Done"
  MsgBox "DocNo " & lDataSet2.FindField("DocNo").AsString
  MsgBox "DocDate " & lDataSet2.FindField("DocDate").AsString
  MsgBox "Transfer Qty " & lDataSet2.FindField("TransferQty").AsString
  lDataSet2.Next
    Wend
lDataSet.Next
   Wend
End Function
End Function
</syntaxhighlight>
</syntaxhighlight>
Line 6,723: Line 7,397:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Common.PaymentMethod.RO====
====GL.TrialBalance.RO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Common.PaymentMethod.RO Script   
! GL Trial Balance  Report Object Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg Common.PaymentMethod.RO.vbs
'Copy below script & paste to notepad & name it as eg GL.TrialBalance.RO.vbs
Call GetInfo
Call GetGLTBData
   
   
Function CreateSQLAccServer
Function CreateSQLAccServer
Line 6,736: Line 7,410:
End Function
End Function
   
   
Function GetInfo
Function GetGLTBData
Dim ComServer, RptObject, lDataSet1, lDataSet2
Dim ComServer, RptObject, lDataSet, lDataSet2, lDateFrom, lDateTo
   'Step 1: Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
Line 6,745: Line 7,419:
   
   
   'Step 2: Find and Create the Report Objects
   'Step 2: Find and Create the Report Objects
   Set RptObject = ComServer.RptObjects.Find("Common.PaymentMethod.RO")  
   Set RptObject = ComServer.RptObjects.Find("GL.TrialBalance.RO")
  'Step 3: Spool parameters
  RptObject.Params.Find("AllProject").Value      = true
  RptObject.Params.Find("AllAgent").Value        = true
  RptObject.Params.Find("AllArea").Value        = true
  RptObject.Params.Find("LedgerType").Value      = "G" 'G = Legder, S = Debtor, P = Supplier
  'RptObject.Params.Find("ProjectData").Value    = 'Not use if AllArea is true
  RptObject.Params.Find("ShowZeroBalance").Value = false
  RptObject.Params.Find("SortBy").Value          = "PostDate;DocNo"
  RptObject.Params.Find("UseDescription2").Value = false
 
  lDateFrom = CDate("October 27, 2016")
  lDateTo = CDate("December 31, 2016")
   
   
  'For Post Date From & Date To'
  RptObject.Params.Find("DateFrom").Value      = lDateFrom
  RptObject.Params.Find("DateTo").Value        = lDateTo
  'RptObject.Params.Find("AgentData").Value      = 'Not use if AllAgent is true
  'RptObject.Params.Find("AreaData").Value      = 'Not use if AllArea is true
 
  RptObject.Params.Find("SortBy").Value          = "Code;Description"
   
   
   'Step 3: Perform Report calculation  
   'Step 4: Perform Report calculation  
   RptObject.CalculateReport()
   RptObject.CalculateReport()
   Set lDataSet1 = RptObject.DataSets.Find("cdsMain")
   Set lDataSet = RptObject.DataSets.Find("cdsMain")
   Set lDataSet2 = RptObject.DataSets.Find("cdsPaymentAccount") 'You can link with lDataSet1 using Code to get the description
   Set lDataSet2 = RptObject.DataSets.Find("cdsGLAccount")


   MsgBox "Count " & lDataSet1.RecordCount
   MsgBox "Count " & lDataSet.RecordCount
   
   
   'Step 5 Retrieve the output  
   'Step 5 Retrieve the output  
   lDataSet1.First
   lDataSet.First
   While (not lDataSet1.eof)
   While (not lDataSet.eof)
MsgBox "Code : " & lDataSet1.FindField("Code").AsString  
    MsgBox "Month To Date"
lDataSet1.Next
MsgBox lDataSet.FindField("Code").AsString & " DR=>" & lDataSet.FindField("MTDDR").AsString & " CR=>" & lDataSet.FindField("MTDCR").AsString
  Wend   
 
MsgBox "Year To Date"
  MsgBox "Count " & lDataSet2.RecordCount
MsgBox lDataSet.FindField("Code").AsString & " DR=>" & lDataSet.FindField("YTDDR").AsString & " CR=>" & lDataSet.FindField("YTDCR").AsString
lDataSet.Next
  Wend
    
    
  'For Account List
   lDataSet2.First
   lDataSet2.First
   While (not lDataSet2.eof)
   While (not lDataSet2.eof)
MsgBox "Code : " & lDataSet2.FindField("Code").AsString  
MsgBox lDataSet2.FindField("Code").AsString & " " & lDataSet2.FindField("Description").AsString
MsgBox "Description : " & lDataSet2.FindField("Description").AsString
lDataSet2.Next
lDataSet2.Next
   Wend  
   Wend
 
End Function
End Function
</syntaxhighlight>
</syntaxhighlight>
Line 6,776: Line 7,474:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Common.Agent.RO====
====Customer.Aging.RO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Common.Agent.RO Script   
! Customer Aging  Report Object Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg Common.Agent.RO.vbs
'Copy below script & paste to notepad & name it as eg customer_aging_ro.vbs
Call GetInfo
Call GetCustStatementData
   
   
Function CreateSQLAccServer
Function CreateSQLAccServer
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
End Function
 
Function GetInfo
Function GetCustStatementData
Dim ComServer, RptObject, lDataSet1
Const Quote = """"
Dim ComServer, RptObject, lDataSet, lDataSet2, lDateFrom, lDateTo, lAgeData
   'Step 1: Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
Line 6,796: Line 7,495:
     ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"  
     ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"  
   END IF
   END IF
 
   'Step 2: Find and Create the Report Objects
   'Step 2: Find and Create the Report Objects
   Set RptObject = ComServer.RptObjects.Find("Common.Agent.RO")  
   Set RptObject = ComServer.RptObjects.Find("Customer.Aging.RO")  
   
   
  'Step 3: Spool parameters
  lAgeData = "<?xml version=" & Quote & "1.0" & Quote & " standalone=" & Quote & "yes" & Quote & "?>  <DATAPACKET Version=" & Quote & "2.0" & Quote & "><METADATA><FIELDS>" &_
      "<FIELD attrname=" & Quote & "ColumnNo" & Quote & " fieldtype=" & Quote & "i4" & Quote & " required=" & Quote & "true" & Quote & "/><FIELD attrname=" & Quote & "ColumnType" & Quote & " fieldtype=" & Quote & "string" & Quote & " WIDTH=" & Quote & "1" & Quote & "/>" &_
      "<FIELD attrname=" & Quote & "Param1" & Quote & " fieldtype=" & Quote & "i4" & Quote & " required=" & Quote & "true" & Quote & "/><FIELD attrname=" & Quote & "Param2" & Quote & " fieldtype=" & Quote & "i4" & Quote & " required=" & Quote & "true" & Quote & "/>" &_
      "<FIELD attrname=" & Quote & "IsLocal" & Quote & " fieldtype=" & Quote & "boolean" & Quote & "/><FIELD attrname=" & Quote & "HeaderScript" & Quote & " fieldtype=" & Quote & "bin.hex" & Quote & " SUBTYPE=" & Quote & "Text" & Quote & " WIDTH=" & Quote & "1" & Quote & "/>" &_
      "</FIELDS><PARAMS/></METADATA><ROWDATA><ROW ColumnNo=" & Quote & "0" & Quote & " ColumnType=" & Quote & "" & Quote & " Param1=" & Quote & "0" & Quote & " Param2=" & Quote & "0" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & "/>" &_
      "<ROW ColumnNo=" & Quote & "1" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "0" & Quote & " Param2=" & Quote & "0" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;Current Mth&apos;&#013;end;" & Quote & "/>" &_
      "<ROW ColumnNo=" & Quote & "2" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-1" & Quote & " Param2=" & Quote & "-1" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;1 Months&apos;&#013;end;" & Quote & "/>" &_
      "<ROW ColumnNo=" & Quote & "3" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-2" & Quote & " Param2=" & Quote & "-2" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;2 Months&apos;&#013;end;" & Quote & "/>" &_
      "<ROW ColumnNo=" & Quote & "4" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-3" & Quote & " Param2=" & Quote & "-3" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;3 Months&apos;&#013;end;" & Quote & "/>" &_
      "<ROW ColumnNo=" & Quote & "5" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-4" & Quote & " Param2=" & Quote & "-4" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;4 Months&apos;&#013;end;" & Quote & "/>" &_
      "<ROW ColumnNo=" & Quote & "6" & Quote & " ColumnType=" & Quote & "B" & Quote & " Param1=" & Quote & "-999999" & Quote & " Param2=" & Quote & "-5" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;5 Month &amp; above&apos;&#013;end;" & Quote & "/>" &_
      "</ROWDATA></DATAPACKET>"
  RptObject.Params.Find("ActualGroupBy").Value        = "Code;CompanyName" 'Fixed
'  RptObject.Params.Find("AgentData").Value            =  'Not use if AllAgent is True
  RptObject.Params.Find("AgingData").Value            = lAgeData 'Fixed
  lDateTo = CDate("August 31, 2016")
  RptObject.Params.Find("AgingDate").Value            = lDateTo 
  RptObject.Params.Find("AgingOn").Value              = "I" 'Fixed
  RptObject.Params.Find("AllAgent").Value            = true
  RptObject.Params.Find("AllArea").Value              = true
  RptObject.Params.Find("AllCompany").Value          = false
  RptObject.Params.Find("AllCompanyCategory").Value  = true
  RptObject.Params.Find("AllControlAccount").Value    = true
  RptObject.Params.Find("AllCurrency").Value          = true
  RptObject.Params.Find("AllDocProject").Value        = true
'  RptObject.Params.Find("AreaData").Value            =  'Not use if AllArea is True
'  RptObject.Params.Find("CompanyCategoryData").Value  =  'Not use if AllCompanyCategory is True
  RptObject.Params.Find("CompanyData").Value          = "300-A0001"& vbCRLF & "300-C0001" 'Filter by Customer Code 300-A0001 & 300-C0001
'  RptObject.Params.Find("ControlAccountData").Value  =  'Not use if AllControlAccount is True
'  RptObject.Params.Find("CurrencyData").Value        =  'Not use if AllCurrency is True
'  RptObject.Params.Find("DocProjectData").Value      =  'Not use if AllDocProject is True
  RptObject.Params.Find("FilterPostDate").Value        = false
'  RptObject.Params.Find("GroupBy").Value              = 'Not use
  RptObject.Params.Find("IncludePDC").Value        = false
  RptObject.Params.Find("IncludeZeroBalance").Value  = false
  RptObject.Params.Find("SortBy").Value              = "Code;CompanyName"
  RptObject.Params.Find("DateTo").Value              = lDateTo
   
   
   'Step 3: Perform Report calculation  
   'Step 4: Perform Report calculation  
   RptObject.CalculateReport()
   RptObject.CalculateReport()
   Set lDataSet1 = RptObject.DataSets.Find("cdsMain")
   Set lDataSet = RptObject.DataSets.Find("cdsMain")
    
   Set lDataSet2 = RptObject.DataSets.Find("cdsDocument")
   MsgBox "Count " & lDataSet1.RecordCount
   MsgBox "Count " & lDataSet.RecordCount
 
   'Step 5 Retrieve the output  
   'Step 5 Retrieve the output  
   lDataSet1.First
   lDataSet.First
   While (not lDataSet1.eof)
   While (not lDataSet.eof)
MsgBox "Code : " & lDataSet1.FindField("Code").AsString  
    MsgBox lDataSet.FindField("Code").AsString & " " & lDataSet.FindField("CompanyName").AsString & " " & lDataSet.FindField("C1").AsString
MsgBox "Description : " & lDataSet1.FindField("Description").AsString  
lDataSet2.First
lDataSet1.Next
    While (not lDataSet2.eof)
   Wend    
  MsgBox lDataSet2.FindField("DocNo").AsString & " " & lDataSet2.FindField("C1").AsString
  lDataSet2.Next
    Wend
lDataSet.Next
   Wend
End Function
End Function
</syntaxhighlight>
</syntaxhighlight>
Line 6,820: Line 7,564:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Stock.Item.RO====
====GL.JE.RO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Stock.Item.RO Script   
! GL Journal Voucher Report Object Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg Stock.Item.RO.vbs
'Copy below script & paste to notepad & name it as eg GLJE_ro.vbs
Call GetInfo
Call GetCustomerData
 
Function CreateSQLAccServer
Function CreateSQLAccServer
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
End Function
 
Function GetInfo
Function GetCustomerData
Dim ComServer, RptObject, lDataSet1, lDataSet2, lDateFrom, lDateTo
Dim ComServer, RptObject, lDataSet, lDataSet2, lDateFrom, lDateTo
   'Step 1 Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
     ComServer.Login "ADMIN", "ADMIN", "C\DB\SQLAcc.DCF", "ACC-0002.FDB"  
     ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"  
   END IF
   END IF
 
   'Step 2 Find and Create the Report Objects
   'Step 2: Find and Create the Report Objects
   Set RptObject = ComServer.RptObjects.Find("Stock.Item.RO")  
   Set RptObject = ComServer.RptObjects.Find("GL.JE.RO")  
 
   'Step 3 Spool parameters
   'Step 3: Spool parameters
    RptObject.Params.Find("AllItem").AsBoolean              = true
  RptObject.Params.Find("AllCurrency").Value = true
    RptObject.Params.Find("AllStockGroup").AsBoolean        = true
  RptObject.Params.Find("AllDocProject").Value = true
    RptObject.Params.Find("AllCustomerPriceTag").AsBoolean  = true
  RptObject.Params.Find("AllDocument").Value = true
    RptObject.Params.Find("AllSupplierPriceTag").AsBoolean  = true
  RptObject.Params.Find("AllItemProject").Value = true
    'RptObject.Params.Find("CategoryData").AsBlob            = 'Not use
  RptObject.Params.Find("AllItemArea").Value = true
    'RptObject.Params.Find("CategoryTpl").AsBlob            = 'Not use
  RptObject.Params.Find("AllItemAgent").Value = true
    'RptObject.Params.Find("CustomerPriceTagData").AsBlob    = 'Not use if AllCustomerPriceTag is True
  RptObject.Params.Find("AllDocAgent").Value = true
    'RptObject.Params.Find("SupplierPriceTagData").AsBlob    = 'Not use if AllSupplierPriceTag is True
  RptObject.Params.Find("AllDocArea").Value = true
  RptObject.Params.Find("AllPaymentMethod").Value = true
    lDateFrom = CDate("January 01, 2017")
 
    lDateTo = CDate("December 31, 2017")
  lDateFrom = CDate("December 1, 2017")
  lDateTo = CDate("December 31, 2017")
 
  RptObject.Params.Find("DateFrom").Value = lDateFrom
  RptObject.Params.Find("DocDateFrom").Value = lDateFrom
  RptObject.Params.Find("DateTo").Value = lDateTo
  RptObject.Params.Find("DocDateTo").Value = lDateTo
  RptObject.Params.Find("IncludeCancelled").Value = false
  RptObject.Params.Find("PrintDocumentStyle").Value = false
  RptObject.Params.Find("SelectDate").Value = true 'Post Date
  RptObject.Params.Find("SelectDocDate").Value = false 'Doc Date
    
    
    'RptObject.Params.Find("DateFrom").AsDate                = lDateFrom 'Not use if SelectDate is False
   'Step 4: Perform Report calculation  
    'RptObject.Params.Find("DateTo").AsDate                  = lDateTo
    RptObject.Params.Find("HasAltStockItem").AsBoolean      = false
    RptObject.Params.Find("HasBarcode").AsBoolean          = false
    RptObject.Params.Find("HasBOM").AsBoolean              = false
    RptObject.Params.Find("HasCategory").AsBoolean          = false
    RptObject.Params.Find("HasCustomerItem").AsBoolean      = false
    RptObject.Params.Find("HasOpeningBalance").AsBoolean    = false
    RptObject.Params.Find("HasPurchasePrice").AsBoolean    = false
    RptObject.Params.Find("HasSellingPrice").AsBoolean      = false
    RptObject.Params.Find("HasSupplierItem").AsBoolean      = false
    'RptObject.Params.Find("ItemData").AsBlob                = 'Not use if AllItem is True
    'RptObject.Params.Find("ItemCategoryData").AsBlob        = 'Not use if SelectCategory is False
    RptObject.Params.Find("PrintActive").AsBoolean          = true
    RptObject.Params.Find("PrintInActive").AsBoolean        = true
    RptObject.Params.Find("PrintNonStockControl").AsBoolean = true
    RptObject.Params.Find("PrintStockControl").AsBoolean    = true
    RptObject.Params.Find("SelectCategory").AsBoolean      = false
    RptObject.Params.Find("SelectDate").AsBoolean          = false
    RptObject.Params.Find("SortBy").AsString                  = "Code"
    'RptObject.Params.Find("StockGroupData").AsBlob        =  'Not use if AllStockGroup is True 
   
   'Step 4 Perform Report calculation  
   RptObject.CalculateReport()
   RptObject.CalculateReport()
   Set lDataSet1 = RptObject.DataSets.Find("cdsMain")
   Set lDataSet = RptObject.DataSets.Find("cdsMain")
   Set lDataSet2 = RptObject.DataSets.Find("cdsUOM") ' To link Master Data use Code
   Set lDataSet2 = RptObject.DataSets.Find("cdsDetail")
   MsgBox "Count " & lDataSet1.RecordCount
   MsgBox "Count " & lDataSet.RecordCount
 
   'Step 5 Retrieve the output  
   'Step 5 Retrieve the output  
   lDataSet1.First
   lDataSet.First
   While (not lDataSet1.eof)
   While (not lDataSet.eof)
     MsgBox "Code " & lDataSet1.FindField("Code").AsString  
     MsgBox lDataSet.FindField("DocNo").AsString & " " & lDataSet.FindField("Description").AsString
    MsgBox "Description " & lDataSet1.FindField("Description").AsString  
lDataSet2.First
     MsgBox "Balance Qty " & lDataSet1.FindField("BalSQty").AsString  
     While (not lDataSet2.eof)
     lDataSet1.Next
  MsgBox lDataSet2.FindField("Code").AsString & " " & lDataSet2.FindField("Description").AsString
  lDataSet2.Next
     Wend
lDataSet.Next
   Wend
   Wend
End Function
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>


  MsgBox "Count " & lDataSet2.RecordCount
====SL_CS====
  lDataSet2.First
  While (not lDataSet2.eof)
    MsgBox "Code " & lDataSet2.FindField("Code").AsString
MsgBox "UOM " & lDataSet2.FindField("UOM").AsString
MsgBox "Rate " & lDataSet2.FindField("Rate").AsString
MsgBox "RefPrice " & lDataSet2.FindField("RefPrice").AsString
    lDataSet2.Next
  Wend
End Function
</syntaxhighlight>
|}
 
<div style="float: right;">  [[#top|[top]]]</div>
 
====Example-Stock Item Balance====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Get Stock Item Balance Script   
! SL_CS Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Available in Version 5.2018.833.759 & above
'Copy below script & paste to notepad & name it as eg SL_CS.vbs
'Copy below script & paste to notepad & name it as eg ItemBalance.vbs
Call InsertData
Call CheckLogin
Call GetData
 
Dim ComServer


Function CreateSQLAccServer
Function CreateSQLAccServer
Line 6,926: Line 7,647:
End Function
End Function


function CheckLogin
Function InsertData
Dim ComServer, BizObject, lDate
 
   'Step 1: Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"  
                'UserName, Password, DCF full path, Database filename
   END IF
   END IF
End Function


Function GetData
  'Step 2: Find and Create the Biz Objects
Dim lDataSet, lSQL
   Set BizObject = ComServer.BizObjects.Find("SL_CS")  
   lSQL = "SELECT A.Location, A.Batch, A.ItemCode, B.Description, Sum(A.Qty) Qty FROM ST_TR A "
 
  lSQL = lSQL & "INNER JOIN ST_ITEM B ON (A.ITEMCODE=B.CODE) "
   'Step 3: Set Dataset
   lSQL = lSQL & "WHERE B.IsActive='T' "
   Set lMainDataSet = BizObject.DataSets.Find("MainDataSet")    'lMainDataSet contains master data
   lSQL = lSQL & "AND A.PostDate <= '31 Dec 2017' "
   Set lDetailDataSet = BizObject.DataSets.Find("cdsDocDetail") 'lDetailDataSet contains detail data 
  lSQL = lSQL & "AND A.ItemCode= 'ANT' "
  lSQL = lSQL & "GROUP by A.Location, A.Batch, A.ItemCode, B.Description"
   Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
    
    
   lDataSet.First
   'Step 4 : Insert Data - Master
   While (not lDataSet.eof)
  lDate = CDate("January 1, 2016")
     MsgBox "Location : " & lDataSet.FindField("Location").AsString
  BizObject.New
    MsgBox "Batch : " & lDataSet.FindField("Batch").AsString
   lMainDataSet.FindField("DocKey").value = -1
    MsgBox "Item Code : " & lDataSet.FindField("ItemCode").AsString
  lMainDataSet.FindField("DocNo").value = "--IV Test--"
MsgBox "Item Description : " & lDataSet.FindField("Description").AsString
  lMainDataSet.FindField("DocDate").value = lDate
MsgBox "Balance Qty : " & lDataSet.FindField("Qty").AsString
  lMainDataSet.FindField("PostDate").value = lDate
lDataSet.Next
  lMainDataSet.FindField("Code").value = "300-C0001" 'Customer Code
   Wend
  lMainDataSet.FindField("Description").value = "Sales"
End Function
      
</syntaxhighlight>
  'Step 5: Insert Data - Detail
  'For Tax Inclusive = True with override Tax Amount
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
  lDetailDataSet.FindField("Account").value = "500-000" 'Sales Account Code  & can ignore if had itemcode
  lDetailDataSet.FindField("Description").value =  "Sales Item A"
  lDetailDataSet.FindField("Qty").value =  1
  lDetailDataSet.FindField("Tax").value =  "SR"
  lDetailDataSet.FindField("TaxInclusive").value =  0
  lDetailDataSet.FindField("UnitPrice").value = 410.37
  lDetailDataSet.FindField("Amount").value = 410.37
  lDetailDataSet.FindField("TaxAmt").value = 24.63
 
  lDetailDataSet.DisableControls
  lDetailDataSet.FindField("TaxInclusive").value =  1
  lDetailDataSet.EnableControls
 
  lDetailDataSet.Post
 
  'For Tax Inclusive = False with override Tax Amount
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
  lDetailDataSet.FindField("Account").value = "500-000"
  lDetailDataSet.FindField("Description").value =  "Sales Item B"
  lDetailDataSet.FindField("Qty").value =  1
  lDetailDataSet.FindField("Tax").value =  "SR"
  lDetailDataSet.FindField("TaxInclusive").value =  0
  lDetailDataSet.FindField("UnitPrice").value = 94.43
  lDetailDataSet.FindField("Amount").value = 94.43
  lDetailDataSet.FindField("TaxAmt").value = 5.66
  lDetailDataSet.Post
 
  'For With Item Code
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
  lDetailDataSet.FindField("ItemCode").value = "ANT"
  lDetailDataSet.FindField("Description").value =  "Sales Item B"
  lDetailDataSet.FindField("Qty").value =  2
  lDetailDataSet.FindField("Tax").value =  "SR"
  lDetailDataSet.FindField("TaxInclusive").value =  0
  lDetailDataSet.FindField("UnitPrice").value = 100
  lDetailDataSet.FindField("Amount").value = 200
  lDetailDataSet.FindField("TaxAmt").value = 12
  lDetailDataSet.Post
 
   'Step 6: Save Document
  BizObject.Save
  BizObject.Close
  ComServer.Logout
  MsgBox "Done"
End Function
</syntaxhighlight>
|}
|}


<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-ST_IS====
====Customer.PM.RO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! ST_IS Script   
! Customer.PM.RO Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg StockIssue.vbs
'Copy below script & paste to notepad & name it as eg Customer.PM.RO.vbs
Call CheckLogin
Call GetARPMData
Call InsertData
 
Dim ComServer
 
Function CreateSQLAccServer
Function CreateSQLAccServer
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
End Function
 
function CheckLogin
Function GetARPMData
Dim ComServer, RptObject, lDataSet, lDataSet2, lDataSet3, lDateFrom, lDateTo
   'Step 1: Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
     ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"  
                'UserName, Password, DCF full path, Database filename
   END IF
   END IF
End Function
  'Step 2: Find and Create the Report Objects
  Set RptObject = ComServer.RptObjects.Find("Customer.PM.RO")
  'Step 3: Spool parameters
  'RptObject.Params.Find("AgentData").Value              = 'Not use if AllAgent is true
  'RptObject.Params.Find("CompanyCategoryData").Value    = 'Not use if AllCompanyCategory is true
  RptObject.Params.Find("AllAgent").Value                = true
  RptObject.Params.Find("AllCompanyCategory").Value      = true
  RptObject.Params.Find("AllArea").Value                = true
  RptObject.Params.Find("AllCompany").Value              = true
  RptObject.Params.Find("AllCurrency").Value            = true
  RptObject.Params.Find("AllDocument").Value            = false
  RptObject.Params.Find("AllPaymentMethod").Value        = true
  'RptObject.Params.Find("AreaData").Value                = 'Not use if AllArea is true
  'RptObject.Params.Find("CompanyData").Value            = 'Not use if AllCompany is true
  'RptObject.Params.Find("CurrencyData").Value            = 'Not use if AllCurrency is true


Function InsertData
   lDateFrom = CDate("January 01, 2017")
Dim BizObject, lMain, lDetail, lDate
   lDateTo = CDate("December 31, 2017")
  'Step 2: Find and Create the Biz Objects
   Set BizObject = ComServer.BizObjects.Find("ST_IS")
 
  'Step 3: Set Dataset
  Set lMain  = BizObject.DataSets.Find("MainDataSet") 'lMain contains master data
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data 
    
    
   'Step 4 : Insert Data - Master
   RptObject.Params.Find("DateFrom").Value                = lDateFrom
  lDate = CDate("January 1, 2017")
   RptObject.Params.Find("DateTo").Value                  = lDateTo
   BizObject.New
   RptObject.Params.Find("DocumentData").Value            = "VCOR-00049"
  lMain.FindField("DocKey").value        = -1
   'RptObject.Params.Find("GroupBy").Value                = 'If you wanted to grouping the data
   lMain.FindField("DocNo").AsString      = "--IS Test--"
   RptObject.Params.Find("IncludeCancelled").Value        = false
   lMain.FindField("DocDate").value        = lDate
   'RptObject.Params.Find("PaymentMethodData").Value      = 'Not use if AllPaymentMethod is true
   lMain.FindField("PostDate").value      = lDate
   RptObject.Params.Find("PrintDocumentStyle").Value      = false
   lMain.FindField("Description").AsString = "Stock Issue"
   RptObject.Params.Find("SelectDate").Value              = true
   
   RptObject.Params.Find("ShowUnappliedAmountOnly").Value = false
  'Step 5: Insert Data - Detail
   RptObject.Params.Find("SortBy").Value                  = "PostDate;DocNo;Code"
   lDetail.Append
   RptObject.Params.Find("AllDocProject").Value          = true
   lDetail.FindField("DtlKey").value        = -1
  RptObject.Params.Find("AllItemProject").Value          = true
   lDetail.FindField("DocKey").value        = -1
   'RptObject.Params.Find("DocProjectData").Value         = 'Not use if AllDocProject is true
   lDetail.FindField("ItemCode").AsString    = "ANT"
   'RptObject.Params.Find("ItemProjectData").Value        = 'Not use if AllItemProject is true 
   lDetail.FindField("Description").AsString = "Issue out Item A"
 
   lDetail.FindField("Qty").AsFloat         = 2
  'Step 4: Perform Report calculation
   lDetail.Post
   RptObject.CalculateReport()
 
   Set lDataSet = RptObject.DataSets.Find("cdsMain")
   lDetail.Append
  Set lDataSet2 = RptObject.DataSets.Find("cdsKnockOff")
   lDetail.FindField("DtlKey").value        = -1
  Set lDataSet3 = RptObject.DataSets.Find("cdsKnockOffDetail")
   lDetail.FindField("DocKey").value        = -1
  MsgBox "Count " & lDataSet.RecordCount
  lDetail.FindField("ItemCode").AsString   = "E-BAT"
  lDetail.FindField("Description").AsString = "Issue out Item A"
  'Step 5 Retrieve the output
  lDetail.FindField("Qty").AsFloat          = 4
  lDataSet.First
  lDetail.Post 
   While (not lDataSet.eof)
  'Step 6: Save Document
    MsgBox lDataSet.FindField("DocKey").AsString & " " &  lDataSet.FindField("DocNo").AsString & " " & lDataSet.FindField("Code").AsString
  BizObject.Save
MsgBox "cdsKnockOff Count " & lDataSet2.RecordCount
  BizObject.Close
lDataSet2.First
      
    While (not lDataSet2.eof)
  ComServer.Logout 'Logout after done
  MsgBox lDataSet2.FindField("FromDocKey").AsString & " " & lDataSet2.FindField("DocNo").AsString & " " & lDataSet2.FindField("KOAmt").AsString
  MsgBox "Done"
  lDataSet2.Next
    Wend
    MsgBox "cdsKnockOffDetail Count " & lDataSet3.RecordCount
lDataSet3.First
     While (not lDataSet3.eof)
      MsgBox lDataSet3.FindField("FromDocKey").AsString & " " & lDataSet3.FindField("DocNo").AsString & " " & lDataSet3.FindField("KOAmt").AsString
    lDataSet3.Next
    Wend
lDataSet.Next
  Wend
End Function
End Function
</syntaxhighlight>
</syntaxhighlight>
Line 7,031: Line 7,819:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-ST_RC====
====Sales.IV.RO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! ST_RC Script   
! Sales.IV.RO Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg StockReceived.vbs
'Copy below script & paste to notepad & name it as eg Sales.IV.RO.vbs
Call CheckLogin
Call GetSalesIVData
Call InsertData
 
Dim ComServer
 
Function CreateSQLAccServer
Function CreateSQLAccServer
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
End Function
 
function CheckLogin
Function GetSalesIVData
Dim ComServer, RptObject, lDataSet, lDataSet2, lDataSet3, lDateFrom, lDateTo
   'Step 1: Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
     ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"  
                'UserName, Password, DCF full path, Database filename
   END IF
   END IF
End Function
  'Step 2: Find and Create the Report Objects
  Set RptObject = ComServer.RptObjects.Find("Sales.IV.RO")
  'Step 3: Spool parameters
  'RptObject.Params.Find("AgentData").Value              = 'Not use if AllAgent is true
  RptObject.Params.Find("AllAgent").Value              = true
  RptObject.Params.Find("AllArea").Value                = true
  RptObject.Params.Find("AllCompany").Value            = false
  RptObject.Params.Find("AllCurrency").Value            = true
  RptObject.Params.Find("AllDocProject").Value          = true
  RptObject.Params.Find("AllDocument").Value            = true
  RptObject.Params.Find("AllItem").Value                = true
  RptObject.Params.Find("AllItemProject").Value        = true
  RptObject.Params.Find("AllLocation").Value            = true
  RptObject.Params.Find("AllStockGroup").Value          = true
  RptObject.Params.Find("AllCompanyCategory").Value    = true
  RptObject.Params.Find("AllBatch").Value              = true
  RptObject.Params.Find("AllTariff").Value              = true 'For Version 776 & above
  'RptObject.Params.Find("TariffData").Value            = 'Not use if TariffData is true - For Version 776 & above
  'RptObject.Params.Find("AreaData").Value              = 'Not use if AllArea is true
  'RptObject.Params.Find("CompanyCategoryData").Value    = 'Not use if AllCompanyCategory is true
  RptObject.Params.Find("CompanyData").Value            = "300-C0001"
  'RptObject.Params.Find("CurrencyData").Value          = 'Not use if AllCurrency is true


Function InsertData
   lDateFrom = CDate("January 01, 2017")
Dim BizObject, lMain, lDetail, lDate
   lDateTo = CDate("December 31, 2017")
  'Step 2: Find and Create the Biz Objects
   Set BizObject = ComServer.BizObjects.Find("ST_RC")
 
  'Step 3: Set Dataset
  Set lMain  = BizObject.DataSets.Find("MainDataSet") 'lMain contains master data
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data 
    
    
   'Step 4 : Insert Data - Master
   RptObject.Params.Find("DateFrom").Value                = lDateFrom
   lDate = CDate("January 1, 2017")
   RptObject.Params.Find("DateTo").Value                  = lDateTo
   BizObject.New
  'RptObject.Params.Find("DocProjectData").Value          = 'Not use if AllDocProject is true
   lMain.FindField("DocKey").value        = -1
   'RptObject.Params.Find("DocumentData").Value            = 'Not use if AllDocument is true
   lMain.FindField("DocNo").AsString      = "--RC Test--"
   'RptObject.Params.Find("GroupBy").Value                = 'If you wanted to grouping the data
   lMain.FindField("DocDate").value       = lDate
   'RptObject.Params.Find("CategoryData").Value            = 'Not use if HasCategory is false
   lMain.FindField("PostDate").value      = lDate
  'RptObject.Params.Find("CategoryTpl").Value            = 'For Internal use only
   lMain.FindField("Description").AsString = "Stock Received"
   RptObject.Params.Find("IncludeCancelled").Value       = false
   
   RptObject.Params.Find("HasCategory").Value            = false
   'Step 5: Insert Data - Detail
   'RptObject.Params.Find("ItemData").Value                = 'Not use if AllItem is true
   lDetail.Append
  'RptObject.Params.Find("ItemProjectData").Value        = 'Not use if AllItemProject is true
   lDetail.FindField("DtlKey").value        = -1
   'RptObject.Params.Find("LocationData").Value            = 'Not use if AllLocation is true
   lDetail.FindField("DocKey").value        = -1
   'RptObject.Params.Find("ItemCategoryData").Value        = 'For Internal use only
   lDetail.FindField("ItemCode").AsString    = "ANT"
   'RptObject.Params.Find("BatchData").Value              = 'Not use if AllBatch is true
   lDetail.FindField("Description").AsString = "Received Item A"
   RptObject.Params.Find("PrintDocumentStyle").Value      = false
   lDetail.FindField("Qty").AsFloat         = 2
   RptObject.Params.Find("SelectDate").Value              = true
   lDetail.FindField("UnitCost").AsFloat    = 25.15
   RptObject.Params.Find("SortBy").Value                  = "PostDate;DocNo;Code"
   lDetail.Post
   'RptObject.Params.Find("StockGroupData").Value         = 'Not use if AllStockGroup is true
 
 
   lDetail.Append
 
   lDetail.FindField("DtlKey").value        = -1
  'Step 4: Perform Report calculation
  lDetail.FindField("DocKey").value        = -1
   RptObject.CalculateReport()
  lDetail.FindField("ItemCode").AsString   = "E-BAT"
  Set lDataSet = RptObject.DataSets.Find("cdsMain")
  lDetail.FindField("Description").AsString = "Received Item A"
  Set lDataSet2 = RptObject.DataSets.Find("cdsDocDetail")
  lDetail.FindField("Qty").AsFloat          = 4
   MsgBox "Count " & lDataSet.RecordCount
  lDetail.FindField("UnitCost").AsFloat    = 54
  lDetail.Post 
   'Step 5 Retrieve the output
  'Step 6: Save Document
  lDataSet.First
  BizObject.Save
   While (not lDataSet.eof)
  BizObject.Close
    MsgBox lDataSet.FindField("DocKey").AsString & " " &  lDataSet.FindField("DocNo").AsString & " " & lDataSet.FindField("Code").AsString
      
MsgBox "cdsDocDetail Count " & lDataSet2.RecordCount
  ComServer.Logout 'Logout after done
lDataSet2.First
   MsgBox "Done" 
    While (not lDataSet2.eof)
  MsgBox lDataSet2.FindField("DocKey").AsString & " " & lDataSet2.FindField("ItemCode").AsString & " " & lDataSet2.FindField("Amount").AsString
  lDataSet2.Next
     Wend
lDataSet.Next
   Wend
End Function
End Function
</syntaxhighlight>
</syntaxhighlight>
Line 7,104: Line 7,911:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-ST_AJ====
====Customer.DueDocument.RO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! ST_AJ Script   
! Customer.DueDocument.RO Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg StockAdjustment.vbs
'Copy below script & paste to notepad & name it as eg Customer.DueDocument.RO.vbs
Call CheckLogin
Call GetData
Call InsertData
 
Dim ComServer
 
Function CreateSQLAccServer
Function CreateSQLAccServer
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
End Function
 
function CheckLogin
Function GetData
Dim ComServer, RptObject, lDataSet, lDateTo
   'Step 1: Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
     ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"  
                'UserName, Password, DCF full path, Database filename
   END IF
   END IF
End Function
 
   'Step 2: Find and Create the Report Objects
Function InsertData
   Set RptObject = ComServer.RptObjects.Find("Customer.DueDocument.RO")  
Dim BizObject, lMain, lDetail, lDate
   'Step 2: Find and Create the Biz Objects
   'Step 3: Spool parameters
   Set BizObject = ComServer.BizObjects.Find("ST_AJ")  
  'RptObject.Params.Find("AgentData").Value              = 'Not use if AllAgent is true
 
  RptObject.Params.Find("AllAgent").Value              = true
   'Step 3: Set Dataset
  RptObject.Params.Find("AllArea").Value                = true
   Set lMain   = BizObject.DataSets.Find("MainDataSet") 'lMain contains master data
  RptObject.Params.Find("AllCompany").Value            = false
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data
  RptObject.Params.Find("AllCompanyCategory").Value    = true
  RptObject.Params.Find("AllCurrency").Value            = true
  RptObject.Params.Find("AllDocProject").Value          = true
  RptObject.Params.Find("AllItemProject").Value        = true
  'RptObject.Params.Find("AreaData").Value              = 'Not use if AllArea is true
   'RptObject.Params.Find("CompanyCategoryData").Value  = 'Not use if AllCompanyCategory is true
   RptObject.Params.Find("CompanyData").Value            = "300-A0003"
  'RptObject.Params.Find("CurrencyData").Value          = 'Not use if AllCurrency is true
   'RptObject.Params.Find("DocProjectData").Value        = 'Not use if AllDocProject is true
  'RptObject.Params.Find("GroupBy").Value              = 'If you wanted to grouping the data
  'RptObject.Params.Find("ItemProjectData").Value      = 'Not use if AllItemProject is true
  RptObject.Params.Find("PrintContra").Value            = true
  RptObject.Params.Find("PrintCreditNote").Value        = true
  RptObject.Params.Find("PrintDebitNote").Value        = true
  RptObject.Params.Find("PrintInvoice").Value          = true
  RptObject.Params.Find("PrintOverDue").Value          = true
  RptObject.Params.Find("PrintUnDue").Value            = true
  RptObject.Params.Find("ShowForeignCurrency").Value    = true
  RptObject.Params.Find("ShowLocalCurrency").Value      = true
  RptObject.Params.Find("SortBy").Value                = "PostDate;DocNo;Code"
 
  lDateTo = CDate("April 12, 2018")
    
    
   'Step 4 : Insert Data - Master
   RptObject.Params.Find("DateTo").Value                = lDateTo
  lDate = CDate("January 1, 2017")
   RptObject.Params.Find("IncludePDCheque").Value       = true 
  BizObject.New
  lMain.FindField("DocKey").value        = -1
   lMain.FindField("DocNo").AsString      = "--AJ Test--"
  lMain.FindField("DocDate").value       = lDate
  lMain.FindField("PostDate").value      = lDate
  lMain.FindField("Description").AsString = "Stock Adjustment"
      
      
   'Step 5: Insert Data - Detail
   'Step 4: Perform Report calculation
  lDetail.Append
   RptObject.CalculateReport()
   lDetail.FindField("DtlKey").value        = -1
   Set lDataSet = RptObject.DataSets.Find("cdsMain")
   lDetail.FindField("DocKey").value        = -1
   MsgBox "Count " & lDataSet.RecordCount
  lDetail.FindField("ItemCode").AsString    = "ANT"
   lDetail.FindField("Description").AsString = "Adjust IN Item A"
   'Step 5 Retrieve the output
  lDetail.FindField("Qty").AsFloat          = 2
   lDataSet.First
   lDetail.FindField("UnitCost").AsFloat    = 25.15 'Only IN need UnitCost
   While (not lDataSet.eof)
   lDetail.Post
    MsgBox "Dockey " & lDataSet.FindField("DocKey").AsString
 
MsgBox "DocNo " & lDataSet.FindField("DocNo").AsString
   lDetail.Append
MsgBox "DocAmt " & lDataSet.FindField("DocAmt").AsString
  lDetail.FindField("DtlKey").value        = -1
MsgBox "Outstanding " & lDataSet.FindField("Outstanding").AsString
  lDetail.FindField("DocKey").value        = -1
MsgBox "Code " & lDataSet.FindField("Code").AsString
  lDetail.FindField("ItemCode").AsString   = "E-BAT"
lDataSet.Next
  lDetail.FindField("Description").AsString = "Adjust OUT Item A"
   Wend
  lDetail.FindField("Qty").AsFloat          = -4
  lDetail.Post 
   'Step 6: Save Document
  BizObject.Save
  BizObject.Close
   
  ComServer.Logout 'Logout after done
  MsgBox "Done" 
End Function
End Function
</syntaxhighlight>
</syntaxhighlight>
Line 7,176: Line 7,987:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-ST_XF====
====Customer.IV.RO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! ST_XF Script   
! Customer.IV.RO Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg ST_XF.vbs
'Copy below script & paste to notepad & name it as eg Customer.IV.RO.vbs
Call CheckLogin
Call GetData
Call InsertData
 
Dim ComServer
 
Function CreateSQLAccServer
Function CreateSQLAccServer
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
End Function
 
function CheckLogin
Function GetData
Dim ComServer, RptObject, lDataSet, lDataSet2, lDataSet3, lDateFrom, lDateTo
   'Step 1: Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
     ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"  
                'UserName, Password, DCF full path, Database filename
   END IF
   END IF
End Function
 
   'Step 2: Find and Create the Report Objects
Function InsertData
   Set RptObject = ComServer.RptObjects.Find("Customer.IV.RO")  
Dim BizObject, lMain, lDetail, lDate
   'Step 2: Find and Create the Biz Objects
   'Step 3: Spool parameters
   Set BizObject = ComServer.BizObjects.Find("ST_XF")  
  'RptObject.Params.Find("AgentData").Value            = 'Not use if AllAgent is true
 
  'RptObject.Params.Find("CompanyCategoryData").Value  = 'Not use if AllCompanyCategory is true
   'Step 3: Set Dataset
  RptObject.Params.Find("AllAgent").Value              = true
   Set lMain   = BizObject.DataSets.Find("MainDataSet") 'lMain contains master data
  RptObject.Params.Find("AllCompanyCategory").Value    = true
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data 
  RptObject.Params.Find("AllArea").Value                = true
  RptObject.Params.Find("AllCompany").Value            = true
  RptObject.Params.Find("AllCurrency").Value            = true
   RptObject.Params.Find("AllDocument").Value            = false
   RptObject.Params.Find("AllPaymentMethod").Value      = true
  'RptObject.Params.Find("AreaData").Value              = 'Not use if AllArea is true
   'RptObject.Params.Find("CompanyData").Value          = 'Not use if AllCompany is true
  'RptObject.Params.Find("CurrencyData").Value          = 'Not use if AllCurrency is true
    
    
   'Begin Looping yr data
   lDateFrom = CDate("January 01, 2017")
   'Step 4 : Insert Data - Master
   lDateTo = CDate("December 31, 2017")
  lDate = CDate("January 1, 2017")
    
   BizObject.New
  RptObject.Params.Find("DateFrom").Value                = lDateFrom
   lMain.FindField("DocKey").value        = -1
   RptObject.Params.Find("DateTo").Value                  = lDateTo
   lMain.FindField("DocNo").AsString      = "--XF Test--"
   RptObject.Params.Find("DocumentData").Value            = "IV-00012"
   lMain.FindField("DocDate").value       = lDate
  'RptObject.Params.Find("GroupBy").Value                = 'If you wanted to grouping the data
   lMain.FindField("PostDate").value      = lDate
   RptObject.Params.Find("IncludeCancelled").Value       = true
   lMain.FindField("Code").AsString        = "300-C0001" 'Customer Account - Optional
  'RptObject.Params.Find("PaymentMethodData").Value      = 'Not use if AllPaymentMethod is true
   lMain.FindField("CompanyName").AsString = "Cash Sales" 'Optional
   RptObject.Params.Find("PrintDocumentStyle").Value      = false
   lMain.FindField("Description").AsString = "Stock Transfer"
   RptObject.Params.Find("SelectDate").Value              = true
  RptObject.Params.Find("ShowUnappliedAmountOnly").Value = true
  RptObject.Params.Find("SortBy").Value                  = "DocDate;DocNo;Code"
   RptObject.Params.Find("AllDocProject").Value          = true
  RptObject.Params.Find("AllItemProject").Value          = true
   'RptObject.Params.Find("DocProjectData").Value        = 'Not use if AllDocProject is true
  'RptObject.Params.Find("ItemProjectData  ").Value      = 'Not use if AllItemProject is true
      
      
   'Step 5: Insert Data - Detail
   'Step 4: Perform Report calculation
   lDetail.Append
   RptObject.CalculateReport()
   lDetail.FindField("DtlKey").value          = -1
   Set lDataSet = RptObject.DataSets.Find("cdsMain")
   lDetail.FindField("DocKey").value          = -1
   Set lDataSet2 = RptObject.DataSets.Find("cdsDocDetail")
   lDetail.FindField("ItemCode").AsString     = "ANT"
  MsgBox "Count " & lDataSet.RecordCount
  lDetail.FindField("Description").AsString = "Transfer Item A"
  lDetail.FindField("Qty").AsFloat          = 10
  'Step 5 Retrieve the output
  lDetail.FindField("UOM").AsString         = "UNIT"
  lDataSet.First
  lDetail.FindField("FromLocation").AsString = "----"
   While (not lDataSet.eof)
  lDetail.FindField("ToLocation").AsString  = "BALAKONG"
    MsgBox "DocNo " & lDataSet.FindField("DocNo").AsString
  lDetail.Post
MsgBox "DocAmt " & lDataSet.FindField("DocAmt").AsString
MsgBox "PaymentAmt " & lDataSet.FindField("PaymentAmt").AsString
MsgBox "cdsDocDetail Count " & lDataSet2.RecordCount
lDataSet2.First
    While (not lDataSet2.eof)
  MsgBox "Account " & lDataSet2.FindField("Account").AsString
  MsgBox "Description " & lDataSet2.FindField("Description").AsString
  MsgBox "Amount " & lDataSet2.FindField("Amount").AsString
  lDataSet2.Next
    Wend
lDataSet.Next
   Wend
End Function
</syntaxhighlight>
|}


  lDetail.Append
<div style="float: right;">   [[#top|[top]]]</div>
  lDetail.FindField("DtlKey").value          = -1
  lDetail.FindField("DocKey").value          = -1
  lDetail.FindField("ItemCode").AsString    = "HFK"
  lDetail.FindField("Description").AsString  = "Transfer Item B"
  lDetail.FindField("Qty").AsFloat          = 5
  lDetail.FindField("UOM").AsString          = "UNIT"
  lDetail.FindField("FromLocation").AsString = "----"
  lDetail.FindField("ToLocation").AsString  = "BALAKONG"
   lDetail.Post


  'Step 6: Save Document
====Sales.OutstandingSO.RO====
  BizObject.Save
  BizObject.Close
 
  'Step 7 : Logout after done 
  'ComServer.Logout
 
  MsgBox "Done" 
End Function
</syntaxhighlight>
|}
 
<div style="float: right;">  [[#top|[top]]]</div>
 
====Example-AP_PI-Edit====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! AP_PI Edit Script   
! Sales.OutstandingSO.RO Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Available in Version 5.2018.833.759 & above
'Copy below script & paste to notepad & name it as eg Sales.OutstandingSO.RO.vbs
'Copy below script & paste to notepad & name it as eg AP_PI.vbs
Call CheckLogin
Call GetData
Call GetData
Call PostData
 
Dim ComServer, lDataSet
 
Function CreateSQLAccServer
Function CreateSQLAccServer
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
End Function
 
function CheckLogin
Function GetData
Dim ComServer, RptObject, lDataSet, lDataSet2, lDataSet3, lDateFrom, lDateTo
   'Step 1: Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
     ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"  
                'UserName, Password, DCF full path, Database filename
   END IF
   END IF
End Function
  'Step 2: Find and Create the Report Objects
  Set RptObject = ComServer.RptObjects.Find("Sales.OutstandingSO.RO")
  'Step 3: Spool parameters
  'RptObject.Params.Find("AgentData").Value            = 'Not use if AllAgent is true
  'RptObject.Params.Find("CompanyCategoryData").Value  = 'Not use if AllCompanyCategory is true
  'RptObject.Params.Find("LocationData").Value        = 'Not use if AllLocation is true
  'RptObject.Params.Find("StockGroupData").Value      = 'Not use if AllStockGroup is true
  RptObject.Params.Find("AllAgent").Value              = true
  RptObject.Params.Find("AllArea").Value              = true
  RptObject.Params.Find("AllCompany").Value            = true
  RptObject.Params.Find("AllDocument").Value          = false
  RptObject.Params.Find("AllItem").Value              = true
  RptObject.Params.Find("AllItemProject").Value        = true
  'RptObject.Params.Find("AreaData").Value              = 'Not use if AllArea is true
  'RptObject.Params.Find("CompanyData").Value          = 'Not use if AllCompany is true
  RptObject.Params.Find("AllTariff").Value              = true 'For Version 776 & above
  'RptObject.Params.Find("TariffData").Value            = 'Not use if TariffData is true - For Version 776 & above


Function GetData
Dim lSQL
  lSQL = "SELECT Dockey FROM AP_PI "
  lSQL = lSQL & "WHERE DocNo='PI-00001' "
  lSQL = lSQL & "AND Code='400-D0001' "
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
End Function
Function PostData
Dim BizObject, lMain, lDetail
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("AP_PI")
  'Step 3: Set Dataset
  Set lMain  = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data 
    
    
   'Step 4 : Find Doc Number
   lDateFrom = CDate("January 01, 2017")
   If lDataSet.RecordCount > 0 Then    
   lDateTo = CDate("December 31, 2017")
lDataSet.First
    
    BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString
  'RptObject.Params.Find("DateFrom").Value              = lDateFrom
    
  'RptObject.Params.Find("DateTo").Value               = lDateTo
    
  'RptObject.Params.Find("DeliveryDateFrom").Value      = lDateFrom
    BizObject.Open
   'RptObject.Params.Find("DeliveryDateTo").Value        = lDateTo
    BizObject.Edit
   RptObject.Params.Find("DocumentData").Value          = "SO-00007"& vbCRLF & "SO-00009"
    lMain.Edit
  'RptObject.Params.Find("GroupBy").Value              = 'If you wanted to grouping the data
lMain.FindField("Description").AsString = "testing"  
  RptObject.Params.Find("IncludeCancelled").Value      = false
    
   'RptObject.Params.Find("ItemData").Value              = 'Not use if AllItem is true
   'Step 5: Delete all Detail
   RptObject.Params.Find("PrintFulfilledItem").Value    = true 'Print transfered info
    While lDetail.RecordCount <> 0
  RptObject.Params.Find("PrintOutstandingItem").Value  = true 'Print untransfer info
      lDetail.First
   'RptObject.Params.Find("ItemProjectData").Value      = 'Not use if AllItemProject is true
  lDetail.Delete
  RptObject.Params.Find("SelectDate").Value            = false
    Wend
  RptObject.Params.Find("SelectDeliveryDate").Value    = false
   'Step 6: Append Detail
  RptObject.Params.Find("SortBy").Value                = "DocDate;DocNo;Code"
    lDetail.Append
  RptObject.Params.Find("AllDocProject").Value          = true
    lDetail.FindField("DtlKey").value = -1
  RptObject.Params.Find("AllLocation").Value            = true
    lDetail.FindField("Account").value = "610-2000"
  RptObject.Params.Find("AllCompanyCategory").Value    = true
    lDetail.FindField("Description").value = "Purchase Item A"
  RptObject.Params.Find("AllBatch").Value              = true
    lDetail.FindField("Tax").value = ""
  RptObject.Params.Find("HasCategory").Value            = false
    lDetail.FindField("TaxInclusive").value = 0
  RptObject.Params.Find("AllStockGroup").Value          = true
    lDetail.FindField("Amount").value = 410.37
   'RptObject.Params.Find("CategoryData").Value          = 'For Internal use only
    lDetail.FindField("TaxAmt").value = 0
   'RptObject.Params.Find("CategoryTpl").Value          = 'For Internal use only
    lDetail.Post
   'RptObject.Params.Find("ItemCategoryData").Value      = 'For Internal use only
    
   'RptObject.Params.Find("DocProjectData").Value        = 'Not use if AllDocProject is true
   'Step 7: Save Document
  'RptObject.Params.Find("BatchData").Value            = 'Not use if AllBatch is true
    BizObject.Save
  RptObject.Params.Find("TranferDocFilterDate").Value   = false
    BizObject.Close
    
   'Step 8 : Logout after done 
    'ComServer.Logout 
    MsgBox "Done"  
Else
MsgBox "Record Not Found"  
   END IF
    
    
   
  'Step 4: Perform Report calculation
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsTransfer")
  MsgBox "Count " & lDataSet.RecordCount
  'Step 5 Retrieve the output
  lDataSet.First
  While (not lDataSet.eof)
    MsgBox "DocKey " & lDataSet.FindField("DocKey").AsString
MsgBox "DtlKey " & lDataSet.FindField("Dtlkey").AsString
MsgBox "DocNo " & lDataSet.FindField("DocNo").AsString
MsgBox "Item Code " & lDataSet.FindField("ItemCode").AsString
MsgBox "Org Qty " & lDataSet.FindField("SQty").AsString
MsgBox "Outstanding Qty " & lDataSet.FindField("OutstandingQty").AsString
MsgBox "cdsDocDetail Count " & lDataSet2.RecordCount
lDataSet2.First
    While (not lDataSet2.eof)
      MsgBox "FromDocKey " & lDataSet2.FindField("FromDocKey").AsString
  MsgBox "FromDtlKey " & lDataSet2.FindField("FromDtlkey").AsString
  MsgBox "DocType " & lDataSet2.FindField("DocType").AsString
  MsgBox "DocNo " & lDataSet2.FindField("DocNo").AsString
  MsgBox "DocDate " & lDataSet2.FindField("DocDate").AsString
  MsgBox "Transfer Qty " & lDataSet2.FindField("TransferQty").AsString
  lDataSet2.Next
    Wend
lDataSet.Next
  Wend
End Function
End Function
</syntaxhighlight>
</syntaxhighlight>
Line 7,347: Line 8,179:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-SL_DO to SL_IV====
====Common.PaymentMethod.RO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! SL_DO to SL_IV Script   
! Common.PaymentMethod.RO Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Updated 26 Oct 2018
'Copy below script & paste to notepad & name it as eg Common.PaymentMethod.RO.vbs
'Copy below script & paste to notepad & name it as eg SL_IV.vbs
Call GetInfo
Call CheckLogin
Call InsertData1
Call InsertData2
 
Dim ComServer
 
Function CreateSQLAccServer
Function CreateSQLAccServer
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
End Function
 
function CheckLogin
Function GetInfo
Dim ComServer, RptObject, lDataSet1, lDataSet2
   'Step 1: Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
     ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"  
                'UserName, Password, DCF full path, Database filename
   END IF
   END IF
  'Step 2: Find and Create the Report Objects
  Set RptObject = ComServer.RptObjects.Find("Common.PaymentMethod.RO")
  'Step 3: Perform Report calculation
  RptObject.CalculateReport()
  Set lDataSet1 = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsPaymentAccount") 'You can link with lDataSet1 using Code to get the description
  MsgBox "Count " & lDataSet1.RecordCount
  'Step 5 Retrieve the output
  lDataSet1.First
  While (not lDataSet1.eof)
MsgBox "Code : " & lDataSet1.FindField("Code").AsString
lDataSet1.Next
  Wend   
 
  MsgBox "Count " & lDataSet2.RecordCount
 
  lDataSet2.First
  While (not lDataSet2.eof)
MsgBox "Code : " & lDataSet2.FindField("Code").AsString
MsgBox "Description : " & lDataSet2.FindField("Description").AsString
lDataSet2.Next
  Wend   
End Function
End Function
</syntaxhighlight>
|}


Function InsertData1
<div style="float: right;">  [[#top|[top]]]</div>
Dim BizObject, lMain, lDetail, lDate
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("SL_DO")


   'Step 3: Set Dataset
====Common.Agent.RO====
   Set lMain  = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
{| class="mw-collapsible mw-collapsed wikitable"
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data 
! Common.Agent.RO Script 
|-
|
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg Common.Agent.RO.vbs
Call GetInfo
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
Function GetInfo
Dim ComServer, RptObject, lDataSet1
   'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB"
  END IF
  'Step 2: Find and Create the Report Objects
   Set RptObject = ComServer.RptObjects.Find("Common.Agent.RO")  
   
  'Step 3: Perform Report calculation
  RptObject.CalculateReport()
   Set lDataSet1 = RptObject.DataSets.Find("cdsMain")
    
    
   'Begin Looping yr data
   MsgBox "Count " & lDataSet1.RecordCount
  'Step 4 : Insert Data - Master
  lDate = CDate("January 1, 2017")
   'Step 5 Retrieve the output
  BizObject.New
   lDataSet1.First
  lMain.FindField("DocKey").value        = -1
   While (not lDataSet1.eof)
  lMain.FindField("DocNo").AsString      = "--DO Test--"
MsgBox "Code : " & lDataSet1.FindField("Code").AsString  
  lMain.FindField("DocDate").value        = lDate
MsgBox "Description : " & lDataSet1.FindField("Description").AsString  
  lMain.FindField("PostDate").value      = lDate
lDataSet1.Next
  lMain.FindField("Code").AsString        = "300-C0001" 'Customer Account
   Wend     
  lMain.FindField("CompanyName").AsString = "Cash Sales"
  'lMain.FindField("Address1").AsString    = "" 'Optional
  'lMain.FindField("Address2").AsString    = "" 'Optional
  'lMain.FindField("Address3").AsString    = "" 'Optional
  'lMain.FindField("Address4").AsString    = "" 'Optional
  'lMain.FindField("Phone1").AsString      = "" 'Optional
  lMain.FindField("Description").AsString = "Delivery Order"
   
   'Step 5: Insert Data - Detail
   lDetail.Append
   lDetail.FindField("DtlKey").value        = -1
  lDetail.FindField("DocKey").value        = -1
  lDetail.FindField("Seq").value            = 1
  lDetail.FindField("ItemCode").AsString   = "ANT"
  lDetail.FindField("Description").AsString = "Sales Item A"
  lDetail.FindField("UOM").AsString        = "BOX"
  lDetail.FindField("Qty").AsFloat          = 2
  'lDetail.FindField("DISC").AsString        = "5%+3" 'Optional (eg 5% plus 3 Discount)
  lDetail.FindField("Tax").AsString        = "SR"
  lDetail.FindField("TaxRate").AsString    = "6%"
  lDetail.FindField("TaxInclusive").value  = 0
  lDetail.FindField("UnitPrice").AsFloat    = 100 
  lDetail.FindField("Amount").AsFloat      = 200
  lDetail.FindField("TaxAmt").AsFloat      = 12
  lDetail.Post
 
  lDetail.Append
  lDetail.FindField("DtlKey").value        = -1
  lDetail.FindField("DocKey").value        = -1
  lDetail.FindField("Seq").value            = 2
  lDetail.FindField("ItemCode").AsString    = "COVER"
  lDetail.FindField("Description").AsString = "Sales Item B"
  lDetail.FindField("UOM").AsString        = "UNIT"
   lDetail.FindField("Qty").AsFloat          = 3
  lDetail.FindField("Tax").AsString        = "SR"
  lDetail.FindField("TaxRate").AsString    = "6%"
  lDetail.FindField("TaxInclusive").value  = 0
  lDetail.FindField("UnitPrice").AsFloat    = 10 
  lDetail.FindField("Amount").AsFloat      = 30
  lDetail.FindField("TaxAmt").AsFloat      = 1.80
  lDetail.Post 
  'Step 6: Save Document
  BizObject.Save
  BizObject.Close
  MsgBox "DO Posting Done" 
End Function
End Function
</syntaxhighlight>
|}


Function InsertData2
<div style="float: right;">   [[#top|[top]]]</div>
Dim BizObject, lMain, lDetail, lDate, lDODtl, lxFer, lSQL, v(2)
  'Step 1: Check Is transtered or not
  lSQL = "SELECT DocKey FROM SL_IVDTL "
   lSQL = lSQL & "WHERE FromDockey=(SELECT DocKey FROM SL_DO "
  lSQL = lSQL & "WHERE DocNo='--DO Test--') "
  Set lxFer = ComServer.DBManager.NewDataSet(lSQL)


   if lxFer.RecordCount = 0 then
====Stock.Item.RO====
     'Step 2: Get DO Information
{| class="mw-collapsible mw-collapsed wikitable"
    lSQL = "SELECT * FROM SL_DODTL "
! Stock.Item.RO Script 
     lSQL = lSQL & "WHERE Dockey=(SELECT DocKey FROM SL_DO "  
|-
     lSQL = lSQL & "WHERE DocNo='--DO Test--') "
|
     Set lDODtl = ComServer.DBManager.NewDataSet(lSQL)     
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg Stock.Item.RO.vbs
Call GetInfo
Function CreateSQLAccServer
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
Function GetInfo
Dim ComServer, RptObject, lDataSet1, lDataSet2, lDateFrom, lDateTo
  'Step 1 Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
     ComServer.Login "ADMIN", "ADMIN", "C\DB\SQLAcc.DCF", "ACC-0002.FDB"
  END IF
  'Step 2 Find and Create the Report Objects
  Set RptObject = ComServer.RptObjects.Find("Stock.Item.RO")
  'Step 3 Spool parameters
     RptObject.Params.Find("AllItem").AsBoolean              = true
    RptObject.Params.Find("AllStockGroup").AsBoolean        = true
    RptObject.Params.Find("AllCustomerPriceTag").AsBoolean  = true
     RptObject.Params.Find("AllSupplierPriceTag").AsBoolean  = true
    'RptObject.Params.Find("CategoryData").AsBlob            = 'Not use
    'RptObject.Params.Find("CategoryTpl").AsBlob            =  'Not use
    'RptObject.Params.Find("CustomerPriceTagData").AsBlob    =  'Not use if AllCustomerPriceTag is True
     'RptObject.Params.Find("SupplierPriceTagData").AsBlob   =  'Not use if AllSupplierPriceTag is True
'Step 3: Find and Create the Biz Objects
     lDateFrom = CDate("January 01, 2017")
    Set BizObject = ComServer.BizObjects.Find("SL_IV")
     lDateTo = CDate("December 31, 2017")
 
    'Step 4: Set Dataset
     Set lMain  = BizObject.DataSets.Find("MainDataSet") 'lMain contains master data
     Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data 
    
    
     'Step 5 : Insert Data - Master
     'RptObject.Params.Find("DateFrom").AsDate                = lDateFrom 'Not use if SelectDate is False
     lDate = CDate("January 1, 2017")
     'RptObject.Params.Find("DateTo").AsDate                  = lDateTo
     BizObject.New
     RptObject.Params.Find("HasAltStockItem").AsBoolean      = false
     lMain.FindField("DocKey").value        = -1
     RptObject.Params.Find("HasBarcode").AsBoolean          = false
     lMain.FindField("DocNo").AsString      = "--IV Test--"
     RptObject.Params.Find("HasBOM").AsBoolean              = false
     lMain.FindField("DocDate").value        = lDate
    RptObject.Params.Find("HasCategory").AsBoolean          = false
     lMain.FindField("PostDate").value      = lDate
     RptObject.Params.Find("HasCustomerItem").AsBoolean      = false
     lMain.FindField("Code").AsString        = "300-C0001" 'Customer Account
     RptObject.Params.Find("HasOpeningBalance").AsBoolean    = false
     lMain.FindField("CompanyName").AsString = "Cash Sales"
     RptObject.Params.Find("HasPurchasePrice").AsBoolean    = false
     'lMain.FindField("Address1").AsString    = "" 'Optional
    RptObject.Params.Find("HasSellingPrice").AsBoolean      = false
     'lMain.FindField("Address2").AsString    = "" 'Optional
     RptObject.Params.Find("HasSupplierItem").AsBoolean      = false
     'lMain.FindField("Address3").AsString   = "" 'Optional
    'RptObject.Params.Find("ItemData").AsBlob                = 'Not use if AllItem is True
     'lMain.FindField("Address4").AsString    = "" 'Optional
     'RptObject.Params.Find("ItemCategoryData").AsBlob        = 'Not use if SelectCategory is False
     'lMain.FindField("Phone1").AsString     = "" 'Optional
    RptObject.Params.Find("PrintActive").AsBoolean          = true
     lMain.FindField("Description").AsString = "Sales"
     RptObject.Params.Find("PrintInActive").AsBoolean        = true
    RptObject.Params.Find("PrintNonStockControl").AsBoolean = true
     RptObject.Params.Find("PrintStockControl").AsBoolean   = true
    RptObject.Params.Find("SelectCategory").AsBoolean      = false
     RptObject.Params.Find("SelectDate").AsBoolean          = false
     RptObject.Params.Find("SortBy").AsString                 = "Code"
     'RptObject.Params.Find("StockGroupData").AsBlob        = 'Not use if AllStockGroup is True 
      
      
    'Step 6: Insert Data - Detail
  'Step 4 Perform Report calculation
    v(0) = "COVER"
  RptObject.CalculateReport()
    v(1) = "UNIT"
  Set lDataSet1 = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsUOM") ' To link Master Data use Code
    if (lDODtl.Locate("ItemCode;UOM", v, false, false)) then
  MsgBox "Count " & lDataSet1.RecordCount
      lDetail.Append
      lDetail.FindField("DtlKey").value        = -1
   'Step 5 Retrieve the output
      lDetail.FindField("DocKey").value        = -1
   lDataSet1.First
      lDetail.FindField("Seq").value            = 1
   While (not lDataSet1.eof)
      lDetail.FindField("ItemCode").AsString    = lDODtl.FindField("ItemCode").AsString
     MsgBox "Code " & lDataSet1.FindField("Code").AsString  
      lDetail.FindField("Description").AsString = lDODtl.FindField("Description").AsString
    MsgBox "Description " & lDataSet1.FindField("Description").AsString  
      'lDetail.FindField("Account").AsString    = "500-000" 'If you wanted override the Sales Account Code
     MsgBox "Balance Qty " & lDataSet1.FindField("BalSQty").AsString  
      lDetail.FindField("UOM").AsString        = lDODtl.FindField("UOM").AsString
    lDataSet1.Next
  lDetail.FindField("Qty").AsFloat          = lDODtl.FindField("Qty").AsFloat
  Wend
      lDetail.FindField("DISC").AsString        = lDODtl.FindField("Disc").AsString
 
      lDetail.FindField("Tax").AsString        = lDODtl.FindField("Tax").AsString
  MsgBox "Count " & lDataSet2.RecordCount
      lDetail.FindField("TaxRate").AsString    = lDODtl.FindField("TaxRate").AsString
   lDataSet2.First
      lDetail.FindField("TaxInclusive").value   = lDODtl.FindField("TaxInclusive").Value
  While (not lDataSet2.eof)
      lDetail.FindField("UnitPrice").AsFloat    = lDODtl.FindField("UnitPrice").AsFloat
    MsgBox "Code " & lDataSet2.FindField("Code").AsString
      lDetail.FindField("Amount").AsFloat      = lDODtl.FindField("Amount").AsFloat
MsgBox "UOM " & lDataSet2.FindField("UOM").AsString  
      lDetail.FindField("TaxAmt").AsFloat      = lDODtl.FindField("TaxAmt").AsFloat
MsgBox "Rate " & lDataSet2.FindField("Rate").AsString
  lDetail.FindField("FromDocType").AsString = "DO"
MsgBox "RefPrice " & lDataSet2.FindField("RefPrice").AsString
  lDetail.FindField("FromDockey").AsFloat   = lDODtl.FindField("DocKey").AsFloat
     lDataSet2.Next
  lDetail.FindField("FromDtlkey").AsFloat   = lDODtl.FindField("DtlKey").AsFloat
   Wend
      lDetail.Post
End IF 
    v(0) = "ANT"
     v(1) = "BOX"
    if (lDODtl.Locate("ItemCode;UOM", v, false, false)) then
      lDetail.Append
      lDetail.FindField("DtlKey").value        = -1
      lDetail.FindField("DocKey").value        = -1
      lDetail.FindField("Seq").value            = 2
      lDetail.FindField("ItemCode").AsString    = lDODtl.FindField("ItemCode").AsString
      lDetail.FindField("Description").AsString = lDODtl.FindField("Description").AsString
      'lDetail.FindField("Account").AsString     = "500-000" 'If you wanted override the Sales Account Code
      lDetail.FindField("UOM").AsString        = lDODtl.FindField("UOM").AsString
  lDetail.FindField("Qty").AsFloat          = lDODtl.FindField("Qty").AsFloat
      lDetail.FindField("DISC").AsString        = lDODtl.FindField("Disc").AsString
      lDetail.FindField("Tax").AsString        = lDODtl.FindField("Tax").AsString
      lDetail.FindField("TaxRate").AsString    = lDODtl.FindField("TaxRate").AsString
      lDetail.FindField("TaxInclusive").value   = lDODtl.FindField("TaxInclusive").Value
      lDetail.FindField("UnitPrice").AsFloat    = lDODtl.FindField("UnitPrice").AsFloat
      lDetail.FindField("Amount").AsFloat      = lDODtl.FindField("Amount").AsFloat
      lDetail.FindField("TaxAmt").AsFloat      = lDODtl.FindField("TaxAmt").AsFloat
  lDetail.FindField("FromDocType").AsString = "DO"
  lDetail.FindField("FromDockey").AsFloat  = lDODtl.FindField("DocKey").AsFloat
  lDetail.FindField("FromDtlkey").AsFloat  = lDODtl.FindField("DtlKey").AsFloat
      lDetail.Post
End IF 
  'Step 7: Save Document
    BizObject.Save
     BizObject.Close
 
  'Step 8 : Logout after done 
  'ComServer.Logout
 
  MsgBox "Posting IV Done"
  else MsgBox "--DO Test-- had been transfered. Posting IV aborted" 
   End IF
End Function
End Function
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-SL_IV-Edit====
====Stock Item Balance====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! SL_IV-Edit Script   
! Get Stock Item Balance Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Available in Version 5.2018.833.759 & above
'Available in Version 5.2018.833.759 & above
'Copy below script & paste to notepad & name it as eg SL_IV.vbs
'Copy below script & paste to notepad & name it as eg ItemBalance.vbs
Call CheckLogin
Call CheckLogin
Call GetData
Call GetData
Call PostData


Dim ComServer, lDataSet
Dim ComServer


Function CreateSQLAccServer
Function CreateSQLAccServer
Line 7,571: Line 8,392:


Function GetData
Function GetData
Dim lSQL
Dim lDataSet, lSQL
   lSQL = "SELECT Dockey FROM SL_IV "
   lSQL = "SELECT A.Location, A.Batch, A.ItemCode, B.Description, Sum(A.Qty) Qty FROM ST_TR A "
   lSQL = lSQL & "WHERE DocNo='IV-00010' "
  lSQL = lSQL & "INNER JOIN ST_ITEM B ON (A.ITEMCODE=B.CODE) "  
   lSQL = lSQL & "WHERE B.IsActive='T' "
  lSQL = lSQL & "AND A.PostDate <= '31 Dec 2017' "
  lSQL = lSQL & "AND A.ItemCode= 'ANT' "
  lSQL = lSQL & "GROUP by A.Location, A.Batch, A.ItemCode, B.Description"
   Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
   Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
End Function
    
 
   lDataSet.First
Function PostData
   While (not lDataSet.eof)
Dim BizObject, lMain, lDetail
     MsgBox "Location : " & lDataSet.FindField("Location").AsString
   'Step 2: Find and Create the Biz Objects
     MsgBox "Batch : " & lDataSet.FindField("Batch").AsString
   Set BizObject = ComServer.BizObjects.Find("SL_IV")
     MsgBox "Item Code : " & lDataSet.FindField("ItemCode").AsString
 
MsgBox "Item Description : " & lDataSet.FindField("Description").AsString
   'Step 3: Set Dataset
MsgBox "Balance Qty : " & lDataSet.FindField("Qty").AsString
  Set lMain  = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
lDataSet.Next
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data 
   Wend
 
  'Step 4 : Find Doc Number
  If lDataSet.RecordCount > 0 Then 
lDataSet.First
     BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString
 
 
     BizObject.Open
    BizObject.Edit
    lMain.Edit
lMain.FindField("Description").AsString = "Sales - Edited"  
 
  'Step 5: Delete all Detail
    While lDetail.RecordCount <> 0
      lDetail.First
  lDetail.Delete
    Wend
  'Step 6: Append Detail
    lDetail.Append
    lDetail.FindField("DtlKey").value = -1
    lDetail.FindField("Account").value = "500-000"
     lDetail.FindField("Description").value =  "Edited Item A"
    lDetail.FindField("Tax").value =  ""
    lDetail.FindField("TaxInclusive").value =  0
    lDetail.FindField("Amount").value = 410.37
    lDetail.FindField("TaxAmt").value = 0
    lDetail.Post
    
  'Step 7: Save Document
    BizObject.Save
    BizObject.Close
 
  'Step 8 : Logout after done 
    'ComServer.Logout 
    MsgBox "Done"
Else
MsgBox "Record Not Found"
  END IF
End Function
End Function
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-GL_JE====
====ST_IS====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! GL_JE Script   
! ST_IS Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg GL_JE.vbs
'Copy below script & paste to notepad & name it as eg StockIssue.vbs
Call InsertGLJE
Call CheckLogin
Call InsertData
 
Dim ComServer
 
Function CreateSQLAccServer
Function CreateSQLAccServer
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
End Function
 
Function InsertGLJE
function CheckLogin
Dim ComServer, BizObject, lDataSet, lDataSet2, lDate
   'Step 1: Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"  
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
                'UserName, Password, DCF full path, Database filename
   END IF
   END IF
End Function
 
Function InsertData
Dim BizObject, lMain, lDetail, lDate
   'Step 2: Find and Create the Biz Objects
   'Step 2: Find and Create the Biz Objects
   Set BizObject = ComServer.BizObjects.Find("GL_JE")  
   Set BizObject = ComServer.BizObjects.Find("ST_IS")  
 
   'Step 3: Set Dataset
   'Step 3: Set Dataset
   Set lMainDataSet = BizObject.DataSets.Find("MainDataSet")   'lMainDataSet contains master data
   Set lMain  = BizObject.DataSets.Find("MainDataSet") 'lMain contains master data
   Set lDetailDataSet = BizObject.DataSets.Find("cdsDocDetail") 'lDetailDataSet contains detail data   
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data   
    
    
   'Step 4 : Insert Data - Master
   'Step 4 : Insert Data - Master
   lDate = CDate("January 23, 2017")
   lDate = CDate("January 1, 2017")
   BizObject.New
   BizObject.New
   lMainDataSet.FindField("DocKey").value = -1
   lMain.FindField("DocKey").value         = -1
   lMainDataSet.FindField("DocNo").value = "--JV Test--"
   lMain.FindField("DocNo").AsString      = "--IS Test--"
   lMainDataSet.FindField("DocDate").value = lDate
   lMain.FindField("DocDate").value       = lDate
   lMainDataSet.FindField("PostDate").value = lDate
   lMain.FindField("PostDate").value       = lDate
   lMainDataSet.FindField("Description").value = "testing desc header"
   lMain.FindField("Description").AsString = "Stock Issue"
  lMainDataSet.Post
   
 
   'Step 5: Insert Data - Detail
   'Step 5: Insert Data - Detail
   'For Tax Inclusive
   lDetail.Append
  lDetailDataSet.Append
   lDetail.FindField("DtlKey").value         = -1
   lDetailDataSet.FindField("DtlKey").value = -1
   lDetail.FindField("DocKey").value         = -1
   lDetailDataSet.FindField("DocKey").value = -1
   lDetail.FindField("ItemCode").AsString    = "ANT"
   lDetailDataSet.FindField("SEQ").value = 1
   lDetail.FindField("Description").AsString = "Issue out Item A"
  lDetailDataSet.FindField("Code").value = "610-1000"
   lDetail.FindField("Qty").AsFloat          = 2
   lDetailDataSet.FindField("Project").value = "----"
   lDetail.Post
  lDetailDataSet.FindField("Description").value =  "testing desc1"
 
  lDetailDataSet.FindField("Tax").value =  "TX"
   lDetail.Append
  'lDetailDataSet.FindField("LOCALTAXAMT").value = 17.32 //For JE you can't override (i.e. system auto calc)
   lDetail.FindField("DtlKey").value         = -1
  lDetailDataSet.FindField("TaxInclusive").Value = 1
   lDetail.FindField("DocKey").value         = -1
  lDetailDataSet.FindField("LocalDR").value = 306 '//Including GST if TAXINCLUSIVE = 1
   lDetail.FindField("ItemCode").AsString    = "E-BAT"
  lDetailDataSet.FindField("DR").value = 306 '//If wanted DR <> LocalDR
   lDetail.FindField("Description").AsString = "Issue out Item A"
 
   lDetail.FindField("Qty").AsFloat          = 4
  'For Tax Exclusive
   lDetail.Post  
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
   lDetailDataSet.FindField("SEQ").value = 2
   lDetailDataSet.FindField("Code").value = "605-200"
  lDetailDataSet.FindField("Project").value = "----"
  lDetailDataSet.FindField("Description").value = "testing desc2"
  lDetailDataSet.FindField("Tax").value =  "TX"
  lDetailDataSet.FindField("TaxInclusive").value =  0
  lDetailDataSet.FindField("LocalCR").value = 100
  lDetailDataSet.Post  
 
   'For No GST
  lDetailDataSet.Append
   lDetailDataSet.FindField("DtlKey").value = -1
   lDetailDataSet.FindField("DocKey").value = -1
   lDetailDataSet.FindField("SEQ").value = 3
  lDetailDataSet.FindField("Code").value = "610-002"
  lDetailDataSet.FindField("Project").value = "----"
   lDetailDataSet.FindField("Description").value = "testing desc3"
   lDetailDataSet.FindField("Tax").value = ""
   lDetailDataSet.FindField("TaxInclusive").value = 0
  lDetailDataSet.FindField("LocalCR").value = 200
  lDetailDataSet.Post
   'Step 6: Save Document
   'Step 6: Save Document
   BizObject.Save
   BizObject.Save
   BizObject.Close
   BizObject.Close
   MsgBox "Done"
   
  ComServer.Logout 'Logout after done
   MsgBox "Done"
End Function
End Function
</syntaxhighlight>
</syntaxhighlight>
Line 7,717: Line 8,487:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-GL_JE-Edit====
====ST_RC====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! GL_JE-Edit Script   
! ST_RC Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Available in Version 5.2018.833.759 & above
'Copy below script & paste to notepad & name it as eg StockReceived.vbs
'Copy below script & paste to notepad & name it as eg GL_JE.vbs
Call CheckLogin
Call CheckLogin
Call GetData
Call InsertData
Call PostData


Dim ComServer, lDataSet
Dim ComServer


Function CreateSQLAccServer
Function CreateSQLAccServer
Line 7,744: Line 8,512:
End Function
End Function


Function GetData
Function InsertData
Dim lSQL
Dim BizObject, lMain, lDetail, lDate
  lSQL = "SELECT Dockey FROM GL_JE "
  lSQL = lSQL & "WHERE DocNo='JV-00002' "
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
End Function
 
Function PostData
Dim BizObject, lMain, lDetail
   'Step 2: Find and Create the Biz Objects
   'Step 2: Find and Create the Biz Objects
   Set BizObject = ComServer.BizObjects.Find("GL_JE")  
   Set BizObject = ComServer.BizObjects.Find("ST_RC")  


   'Step 3: Set Dataset
   'Step 3: Set Dataset
Line 7,760: Line 8,521:
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data   
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data   
    
    
   'Step 4 : Find Doc Number
   'Step 4 : Insert Data - Master
   If lDataSet.RecordCount > 0 Then    
   lDate = CDate("January 1, 2017")
lDataSet.First
   BizObject.New
    BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString
  lMain.FindField("DocKey").value        = -1
    
  lMain.FindField("DocNo").AsString       = "--RC Test--"
 
   lMain.FindField("DocDate").value        = lDate
    BizObject.Open
  lMain.FindField("PostDate").value      = lDate
    BizObject.Edit
  lMain.FindField("Description").AsString = "Stock Received"
    lMain.Edit
   
lMain.FindField("Description").AsString = "Journal - Edited"  
   'Step 5: Insert Data - Detail
 
   'Step 5: Delete all Detail
    While lDetail.RecordCount <> 0
      lDetail.First
  lDetail.Delete
    Wend
  'Step 6: Append Detail
   lDetail.Append
   lDetail.Append
   lDetail.FindField("DtlKey").value = -1
   lDetail.FindField("DtlKey").value         = -1
   lDetail.FindField("Code").value = "610-000"
   lDetail.FindField("DocKey").value         = -1
   lDetail.FindField("Description").value = "testing desc1"
   lDetail.FindField("ItemCode").AsString    = "ANT"
   lDetail.FindField("Project").value = "P12W1"
   lDetail.FindField("Description").AsString = "Received Item A"
  lDetail.FindField("Tax").value = ""
   lDetail.FindField("Qty").AsFloat          = 2
   lDetail.FindField("TaxInclusive").value = 0
   lDetail.FindField("UnitCost").AsFloat    = 25.15
   lDetail.FindField("LocalDR").value = 200
   lDetail.Post
  lDetail.FindField("DR").value = 200
   lDetail.Post  


   lDetail.Append
   lDetail.Append
   lDetail.FindField("DtlKey").value = -1
   lDetail.FindField("DtlKey").value         = -1
   lDetail.FindField("Code").value = "531-000"
   lDetail.FindField("DocKey").value         = -1
   lDetail.FindField("Description").value = "testing desc2"
   lDetail.FindField("ItemCode").AsString    = "E-BAT"
   lDetail.FindField("Project").value = "P13W1"
   lDetail.FindField("Description").AsString = "Received Item A"
   lDetail.FindField("Tax").value = ""
   lDetail.FindField("Qty").AsFloat          = 4
   lDetail.FindField("TaxInclusive").value = 0
   lDetail.FindField("UnitCost").AsFloat    = 54
  lDetail.FindField("LocalCR").value = 200
   lDetail.Post
  lDetail.FindField("CR").value = 200
   'Step 6: Save Document
   lDetail.Post  
  BizObject.Save
 
  BizObject.Close
   'Step 7: Save Document
   
    BizObject.Save
   ComServer.Logout 'Logout after done
    BizObject.Close
  MsgBox "Done"
 
End Function
   'Step 8 : Logout after done
</syntaxhighlight>
    'ComServer.Logout 
|}
    MsgBox "Done"  
 
Else
MsgBox "Record Not Found"
  END IF
End Function
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-GL_JE-Delete====
====ST_AJ====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! GL_JE-Delete Script   
! ST_AJ Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Available in Version 5.2018.833.759 & above
'Copy below script & paste to notepad & name it as eg StockAdjustment.vbs
'Copy below script & paste to notepad & name it as eg GL_JE.vbs
Call CheckLogin
Call CheckLogin
Call GetData
Call InsertData
Call DelData


Dim ComServer, lDataSet
Dim ComServer


Function CreateSQLAccServer
Function CreateSQLAccServer
Line 7,841: Line 8,585:
End Function
End Function


Function GetData
Function InsertData
Dim lSQL
Dim BizObject, lMain, lDetail, lDate
   lSQL = "SELECT Dockey FROM GL_JE "
   'Step 2: Find and Create the Biz Objects
  lSQL = lSQL & "WHERE DocNo='JV-00002' "
   Set BizObject = ComServer.BizObjects.Find("ST_AJ")  
   Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
End Function


Function DelData
   'Step 3: Set Dataset
Dim BizObject
   Set lMain  = BizObject.DataSets.Find("MainDataSet") 'lMain contains master data
   'Step 2: Find and Create the Biz Objects
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data 
   Set BizObject = ComServer.BizObjects.Find("GL_JE")  
  'Step 3 : Find Doc Number
   If lDataSet.RecordCount > 0 Then
lDataSet.First
    BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString
    BizObject.Open
    BizObject.Delete
    BizObject.Close
    
    
   'Step 4 : Logout after done 
   'Step 4 : Insert Data - Master
     'ComServer.Logout 
  lDate = CDate("January 1, 2017")
     MsgBox "Done"  
  BizObject.New
Else
  lMain.FindField("DocKey").value        = -1
MsgBox "Record Not Found"  
  lMain.FindField("DocNo").AsString      = "--AJ Test--"
   END IF
  lMain.FindField("DocDate").value        = lDate
End Function
  lMain.FindField("PostDate").value      = lDate
</syntaxhighlight>
  lMain.FindField("Description").AsString = "Stock Adjustment"
|}
      
<div style="float: right;">  [[#top|[top]]]</div>
  'Step 5: Insert Data - Detail
 
  lDetail.Append
====Example-Get Invoice Next Number====
  lDetail.FindField("DtlKey").value        = -1
{| class="mw-collapsible mw-collapsed wikitable"
  lDetail.FindField("DocKey").value        = -1
! Get Invoice Next Number Script   
  lDetail.FindField("ItemCode").AsString    = "ANT"
  lDetail.FindField("Description").AsString = "Adjust IN Item A"
  lDetail.FindField("Qty").AsFloat          = 2
  lDetail.FindField("UnitCost").AsFloat     = 25.15 'Only IN need UnitCost
  lDetail.Post
 
  lDetail.Append
  lDetail.FindField("DtlKey").value        = -1
  lDetail.FindField("DocKey").value        = -1
  lDetail.FindField("ItemCode").AsString    = "E-BAT"
  lDetail.FindField("Description").AsString = "Adjust OUT Item A"
  lDetail.FindField("Qty").AsFloat          = -4
  lDetail.Post 
  'Step 6: Save Document
  BizObject.Save
  BizObject.Close
   
  ComServer.Logout 'Logout after done
   MsgBox "Done" 
End Function
</syntaxhighlight>
|}
 
<div style="float: right;">  [[#top|[top]]]</div>
 
====ST_XF====
{| class="mw-collapsible mw-collapsed wikitable"
! ST_XF Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Available in Version 5.2018.833.759 & above
'Copy below script & paste to notepad & name it as eg ST_XF.vbs
'Copy below script & paste to notepad & name it as eg GetNextNo.vbs
Call CheckLogin
Call CheckLogin
Call GetData
Call InsertData
Call ShowNextNo


Dim ComServer, lDataSet
Dim ComServer


Function CreateSQLAccServer
Function CreateSQLAccServer
Line 7,898: Line 8,657:
End Function
End Function


Function GetData
Function InsertData
Dim lSQL
Dim BizObject, lMain, lDetail, lDate
  lSQL = "SELECT A.*, B.NEXTNUMBER FROM SY_DOCNO A "
   'Step 2: Find and Create the Biz Objects
  lSQL = lSQL & "INNER JOIN SY_DOCNO_DTL B ON (A.DOCKEY=B.PARENTKEY) "
   Set BizObject = ComServer.BizObjects.Find("ST_XF")  
  lSQL = lSQL & "WHERE A.DOCTYPE='IV' "
   lSQL = lSQL & "AND A.DESCRIPTION='Customer Invoice' "
  lSQL = lSQL & "AND A.STATESET=1 "
   Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
End Function


Function ShowNextNo
  'Step 3: Set Dataset
Dim Desc, Fmt, NextNo, lResult, sb
  Set lMain  = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
   set sb = CreateObject("System.Text.StringBuilder")
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data 
   'Step 2 : Find Doc Number
 
   If lDataSet.RecordCount > 0 Then    
  'Begin Looping yr data
lDataSet.First
  'Step 4 : Insert Data - Master
     Desc = lDataSet.FindField("Description").AsString
  lDate = CDate("January 1, 2017")
Fmt  = lDataSet.FindField("Format").AsString
  BizObject.New
NextNo = lDataSet.FindField("NEXTNUMBER").Value
  lMain.FindField("DocKey").value        = -1
  lMain.FindField("DocNo").AsString      = "--XF Test--"
'Convert from IV-%.5d to IV-{0:d5}
  lMain.FindField("DocDate").value        = lDate
sb.Append_3 Fmt
   lMain.FindField("PostDate").value      = lDate
sb.Replace "d", ""
  lMain.FindField("Code").AsString        = "300-C0001" 'Customer Account - Optional
sb.Replace "%.","{0:d"
  lMain.FindField("CompanyName").AsString = "Cash Sales" 'Optional
Fmt = sb.ToString & "}"
  lMain.FindField("Description").AsString = "Stock Transfer"
   
sb.Length = 0 'clear sb list
   'Step 5: Insert Data - Detail
sb.AppendFormat Fmt, NextNo
   lDetail.Append
   lDetail.FindField("DtlKey").value          = -1
lResult = sb.ToString
  lDetail.FindField("DocKey").value          = -1
    MsgBox Desc
  lDetail.FindField("ItemCode").AsString     = "ANT"
MsgBox Fmt
  lDetail.FindField("Description").AsString = "Transfer Item A"
MsgBox NextNo
  lDetail.FindField("Qty").AsFloat          = 10
MsgBox lResult
  lDetail.FindField("UOM").AsString         = "UNIT"
Else
  lDetail.FindField("FromLocation").AsString = "----"
MsgBox "Record Not Found"  
  lDetail.FindField("ToLocation").AsString  = "BALAKONG"
  END IF   
  lDetail.Post
 
  lDetail.Append
  lDetail.FindField("DtlKey").value          = -1
  lDetail.FindField("DocKey").value          = -1
  lDetail.FindField("ItemCode").AsString    = "HFK"
  lDetail.FindField("Description").AsString  = "Transfer Item B"
  lDetail.FindField("Qty").AsFloat          = 5
  lDetail.FindField("UOM").AsString          = "UNIT"
  lDetail.FindField("FromLocation").AsString = "----"
  lDetail.FindField("ToLocation").AsString  = "BALAKONG"
  lDetail.Post
 
  'Step 6: Save Document
  BizObject.Save
  BizObject.Close
 
  'Step 7 : Logout after done 
  'ComServer.Logout
 
  MsgBox "Done"
End Function
End Function
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Auto Run Doc. Number====
====AP_PI-Edit====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Sales Order Auto Run Doc Number Script   
! AP_PI Edit Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg SL_SO.vbs
'Available in Version 5.2018.833.759 & above
'If had prompt Set Default - Just click Yes to avoid keep prompt
'Copy below script & paste to notepad & name it as eg AP_PI.vbs
Call CheckLogin
Call CheckLogin
Call GetData
Call GetData
Call InsertData
Call PostData


Dim ComServer, lDataSet
Dim ComServer, lDataSet
Line 7,969: Line 8,744:
Function GetData
Function GetData
Dim lSQL
Dim lSQL
   lSQL = "SELECT * FROM SY_DOCNO "
   lSQL = "SELECT Dockey FROM AP_PI "
   lSQL = lSQL & "WHERE DESCRIPTION='Customer Sales Order 2' "
   lSQL = lSQL & "WHERE DocNo='PI-00001' "
  lSQL = lSQL & "AND Code='400-D0001' "
   Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
   Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
End Function
End Function


 
Function PostData
Function InsertData
Dim BizObject, lMain, lDetail
Dim BizObject, lMain, lDetail, lDate
   'Step 2: Find and Create the Biz Objects
   'Step 2: Find and Create the Biz Objects
   Set BizObject = ComServer.BizObjects.Find("SL_SO")  
   Set BizObject = ComServer.BizObjects.Find("AP_PI")  


   'Step 3: Set Dataset
   'Step 3: Set Dataset
Line 7,984: Line 8,759:
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data   
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data   
    
    
  'Begin Looping yr data
   'Step 4 : Find Doc Number
   'Step 4 : Insert Data - Master
   If lDataSet.RecordCount > 0 Then    
   lDate = CDate("January 1, 2019")
lDataSet.First
  BizObject.New
     BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString
  lMain.FindField("DocKey").value        = -1
  lMain.FindField("DocNo").AsString      = "<<New>>"
  lMain.FindField("DocDate").value        = lDate
  lMain.FindField("PostDate").value      = lDate
  lMain.FindField("Code").AsString        = "300-C0001" 'Customer Account
  lMain.FindField("CompanyName").AsString = "Cash Sales"
  lMain.FindField("Address1").AsString    = "" 'Optional
  lMain.FindField("Address2").AsString    = "" 'Optional
  lMain.FindField("Address3").AsString    = "" 'Optional
  lMain.FindField("Address4").AsString    = "" 'Optional
  lMain.FindField("Phone1").AsString      = "" 'Optional
   lMain.FindField("Description").AsString = "Sales Order"
  lMain.FindField("DocNoSetKey").value    = lDataSet.FindField("DocKey").value
      
  'Step 5: Insert Data - Detail
  'For With Item Code
  lDetail.Append
  lDetail.FindField("DtlKey").value        = -1
  lDetail.FindField("DocKey").value        = -1
  lDetail.FindField("Seq").value            = 3
  lDetail.FindField("ItemCode").AsString    = "ANT"
  lDetail.FindField("Description").AsString = "Sales Item B"
  lDetail.FindField("Qty").AsFloat          = 2
  lDetail.FindField("UOM").AsString        = "UNIT"
  'lDetail.FindField("DISC").AsString        = "5%+3" 'Optional (eg 5% plus 3 Discount)
  lDetail.FindField("Tax").AsString        = ""
  lDetail.FindField("TaxRate").AsString     = ""
  lDetail.FindField("TaxInclusive").value  = 0
  lDetail.FindField("UnitPrice").AsFloat    = 100 
  lDetail.FindField("Amount").AsFloat      = 200
  lDetail.FindField("TaxAmt").AsFloat      = 0
  lDetail.Post
 
  'Step 6: Save Document
  BizObject.Save
  BizObject.Close
    
    
  'Step 7 : Logout after done 
  'ComServer.Logout
    
    
   MsgBox "Done"
    BizObject.Open
    BizObject.Edit
    lMain.Edit
lMain.FindField("Description").AsString = "testing"
 
  'Step 5: Delete all Detail
    While lDetail.RecordCount <> 0
      lDetail.First
  lDetail.Delete
    Wend
  'Step 6: Append Detail
    lDetail.Append
    lDetail.FindField("DtlKey").value = -1
    lDetail.FindField("Account").value = "610-2000"
    lDetail.FindField("Description").value =  "Purchase Item A"
    lDetail.FindField("Tax").value =  ""
    lDetail.FindField("TaxInclusive").value =  0
    lDetail.FindField("Amount").value = 410.37
    lDetail.FindField("TaxAmt").value = 0
    lDetail.Post
 
   'Step 7: Save Document
    BizObject.Save
    BizObject.Close
 
  'Step 8 : Logout after done 
    'ComServer.Logout 
    MsgBox "Done"  
Else
MsgBox "Record Not Found"
  END IF
 
End Function
End Function
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-GL_PV====
====SL_DO to SL_IV====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Cash Book PV Script   
! SL_DO to SL_IV Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg AR_PM.vbs
'Updated 26 Oct 2018
Call PostData
'Copy below script & paste to notepad & name it as eg SL_IV.vbs
Call CheckLogin
Call InsertData1
Call InsertData2
 
Dim ComServer
 
Function CreateSQLAccServer
Function CreateSQLAccServer
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
End Function
 
Function PostData
function CheckLogin
Dim ComServer, BizObject, lIVNo, lDate
   'Step 1: Create Com Server object
   'Step 1: Create Com Server object
   Set ComServer = CreateSQLAccServer 'Create Com Server
   Set ComServer = CreateSQLAccServer 'Create Com Server
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"  
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
                'UserName, Password, DCF full path, Database filename
   END IF
   END IF
End Function
 
Function InsertData1
Dim BizObject, lMain, lDetail, lDate
   'Step 2: Find and Create the Biz Objects
   'Step 2: Find and Create the Biz Objects
   Set BizObject = ComServer.BizObjects.Find("GL_PV")  
   Set BizObject = ComServer.BizObjects.Find("SL_DO")  
 
   'Step 3: Set Dataset
   'Step 3: Set Dataset
   Set lMain = BizObject.DataSets.Find("MainDataSet")   'lMainDataSet contains master data
   Set lMain   = BizObject.DataSets.Find("MainDataSet") 'lMain contains master data
   Set lDetailDataSet = BizObject.DataSets.Find("cdsDocDetail") 'lDetailDataSet contains detail data   
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data   
    
    
   'Step 4 : Posting
  'Begin Looping yr data
    lDate = CDate("January 23, 2020")
   'Step 4 : Insert Data - Master
    BizObject.New
  lDate = CDate("January 1, 2017")
    lMain.FindField("DOCKEY").Value          = -1
  BizObject.New
    lMain.FindField("DocNo").AsString         = "--CB PV Test--"  
  lMain.FindField("DocKey").value        = -1
    lMain.FindField("DocDate").Value          = lDate
  lMain.FindField("DocNo").AsString       = "--DO Test--"
    lMain.FindField("PostDate").Value        = lDate
  lMain.FindField("DocDate").value        = lDate
    lMain.FindField("Description").AsString  = "Compacc System"
  lMain.FindField("PostDate").value      = lDate
    lMain.FindField("PaymentMethod").AsString = "310-001"
  lMain.FindField("Code").AsString       = "300-C0001" 'Customer Account
lMain.FindField("CHEQUENUMBER").AsString = "MBB 213245"
   lMain.FindField("CompanyName").AsString = "Cash Sales"
    lMain.FindField("DocAmt").AsFloat        = 2019.57
  'lMain.FindField("Address1").AsString   = "" 'Optional
    lMain.FindField("Cancelled").AsString     = "F"
  'lMain.FindField("Address2").AsString   = "" 'Optional
lMain.Post
  'lMain.FindField("Address3").AsString    = "" 'Optional
    
  'lMain.FindField("Address4").AsString    = "" 'Optional
    lDetailDataSet.Append
  'lMain.FindField("Phone1").AsString     = "" 'Optional
    lDetailDataSet.FindField("DTLKEY").value = -1
  lMain.FindField("Description").AsString = "Delivery Order"
lDetailDataSet.FindField("DOCKEY").value = -1
   
lDetailDataSet.FindField("Code").AsString = "200-300"
   'Step 5: Insert Data - Detail
    lDetailDataSet.FindField("DESCRIPTION").AsString = "Maybank - Asus A555LD-xx313H"
  lDetail.Append
lDetailDataSet.FindField("TAX").AsString = ""
  lDetail.FindField("DtlKey").value         = -1
lDetailDataSet.FindField("TAXAMT").AsFloat = 0
  lDetail.FindField("DocKey").value         = -1
lDetailDataSet.FindField("TAXINCLUSIVE").AsFloat = 0
  lDetail.FindField("Seq").value            = 1
lDetailDataSet.FindField("AMOUNT").AsFloat = 2019.57
  lDetail.FindField("ItemCode").AsString   = "ANT"
    lDetailDataSet.Post
  lDetail.FindField("Description").AsString = "Sales Item A"
  lDetail.FindField("UOM").AsString         = "BOX"
  lDetail.FindField("Qty").AsFloat         = 2
  'lDetail.FindField("DISC").AsString        = "5%+3" 'Optional (eg 5% plus 3 Discount)
  lDetail.FindField("Tax").AsString        = "SR"
  lDetail.FindField("TaxRate").AsString    = "6%"
  lDetail.FindField("TaxInclusive").value  = 0
  lDetail.FindField("UnitPrice").AsFloat   = 100 
  lDetail.FindField("Amount").AsFloat       = 200
  lDetail.FindField("TaxAmt").AsFloat      = 12
  lDetail.Post


   'Step 5: Save Document
  lDetail.Append
    BizObject.Save
  lDetail.FindField("DtlKey").value        = -1
    BizObject.Close
  lDetail.FindField("DocKey").value        = -1
    MsgBox "Done"
  lDetail.FindField("Seq").value            = 2
  lDetail.FindField("ItemCode").AsString    = "COVER"
  lDetail.FindField("Description").AsString = "Sales Item B"
  lDetail.FindField("UOM").AsString        = "UNIT"
  lDetail.FindField("Qty").AsFloat          = 3
  lDetail.FindField("Tax").AsString        = "SR"
  lDetail.FindField("TaxRate").AsString    = "6%"
  lDetail.FindField("TaxInclusive").value  = 0
  lDetail.FindField("UnitPrice").AsFloat    = 10 
  lDetail.FindField("Amount").AsFloat      = 30
  lDetail.FindField("TaxAmt").AsFloat      = 1.80
  lDetail.Post 
   'Step 6: Save Document
  BizObject.Save
  BizObject.Close
  MsgBox "DO Posting Done"
End Function
End Function
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>
====Example-ST_Item with Opening====
{| class="mw-collapsible mw-collapsed wikitable"
! ST_Item with Opening Script 
|-
|
<syntaxhighlight lang="vb">
'Copy below script & paste to notepad & name it as eg ST_XF.vbs
Call CheckLogin
Call InsertData


Dim ComServer
Function InsertData2
Dim BizObject, lMain, lDetail, lDate, lDODtl, lxFer, lSQL, v(2)
  'Step 1: Check Is transtered or not
  lSQL = "SELECT DocKey FROM SL_IVDTL "
  lSQL = lSQL & "WHERE FromDockey=(SELECT DocKey FROM SL_DO "
  lSQL = lSQL & "WHERE DocNo='--DO Test--') "
  Set lxFer = ComServer.DBManager.NewDataSet(lSQL)


Function CreateSQLAccServer
   if lxFer.RecordCount = 0 then
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
     'Step 2: Get DO Information
End Function
    lSQL = "SELECT * FROM SL_DODTL "
 
    lSQL = lSQL & "WHERE Dockey=(SELECT DocKey FROM SL_DO "  
function CheckLogin
    lSQL = lSQL & "WHERE DocNo='--DO Test--') "
  'Step 1: Create Com Server object
    Set lDODtl = ComServer.DBManager.NewDataSet(lSQL)  
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
'Step 3: Find and Create the Biz Objects
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
    Set BizObject = ComServer.BizObjects.Find("SL_IV")  
                'UserName, Password, DCF full path, Database filename
  END IF
End Function
 
Function InsertData
Dim BizObject, lMain, lDtl, lOpn
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("ST_ITEM")
 
  'Step 3: Set Dataset
  Set lMain = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDtl = BizObject.DataSets.Find("cdsUOM") 'lDetail contains detail data 
  Set lOpn = BizObject.DataSets.Find("cdsOpeningBalance") 'lDetail contains detail data 
 
  'Begin Looping yr data
  'Step 4 : Insert Data - Master
  BizObject.New
  lMain.FindField("CODE").value = "==Test New Item Code=="
  lMain.FindField("DESCRIPTION").value = "Item Description 123"
  lMain.FindField("STOCKGROUP").value = "DEFAULT"
  lMain.FindField("STOCKCONTROL").value = "T"
  lMain.FindField("ISACTIVE").value = "T"
   
  'Step 5: Insert Data - Detail
  lDtl.Edit 'For 1St UOM
  lDtl.FindField("UOM").AsString = "PCS"
  lDtl.FindField("Rate").AsFloat = 1
  lDtl.FindField("RefCost").AsFloat = 10.2
  lDtl.FindField("RefPrice").AsFloat = 25
  lDtl.Post
 
  lDtl.Append 'For 2nd UOM
  lDtl.FindField("UOM").AsString = "CTN"
  lDtl.FindField("Rate").AsFloat = 12
  lDtl.FindField("RefCost").AsFloat = 102
  lDtl.FindField("RefPrice").AsFloat = 240
  lDtl.Post
 
  'Step 6: Insert Data - Opening
  lOpn.Append
  lOpn.FindField("LOCATION").AsString = "----"
  lOpn.FindField("Qty").AsFloat = 10 'in smallest UOM'
  lOpn.FindField("COST").AsFloat = 10.2
  lOpn.Post


    'Step 4: Set Dataset
    Set lMain  = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
    Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data 
 
    'Step 5 : Insert Data - Master
    lDate = CDate("January 1, 2017")
    BizObject.New
    lMain.FindField("DocKey").value        = -1
    lMain.FindField("DocNo").AsString      = "--IV Test--"
    lMain.FindField("DocDate").value        = lDate
    lMain.FindField("PostDate").value      = lDate
    lMain.FindField("Code").AsString        = "300-C0001" 'Customer Account
    lMain.FindField("CompanyName").AsString = "Cash Sales"
    'lMain.FindField("Address1").AsString    = "" 'Optional
    'lMain.FindField("Address2").AsString    = "" 'Optional
    'lMain.FindField("Address3").AsString    = "" 'Optional
    'lMain.FindField("Address4").AsString    = "" 'Optional
    'lMain.FindField("Phone1").AsString      = "" 'Optional
    lMain.FindField("Description").AsString = "Sales"
   
    'Step 6: Insert Data - Detail
    v(0) = "COVER"
    v(1) = "UNIT"
    if (lDODtl.Locate("ItemCode;UOM", v, false, false)) then
      lDetail.Append
      lDetail.FindField("DtlKey").value        = -1
      lDetail.FindField("DocKey").value        = -1
      lDetail.FindField("Seq").value            = 1
      lDetail.FindField("ItemCode").AsString    = lDODtl.FindField("ItemCode").AsString
      lDetail.FindField("Description").AsString = lDODtl.FindField("Description").AsString
      'lDetail.FindField("Account").AsString    = "500-000" 'If you wanted override the Sales Account Code
      lDetail.FindField("UOM").AsString        = lDODtl.FindField("UOM").AsString
  lDetail.FindField("Qty").AsFloat          = lDODtl.FindField("Qty").AsFloat
      lDetail.FindField("DISC").AsString        = lDODtl.FindField("Disc").AsString
      lDetail.FindField("Tax").AsString        = lDODtl.FindField("Tax").AsString
      lDetail.FindField("TaxRate").AsString    = lDODtl.FindField("TaxRate").AsString
      lDetail.FindField("TaxInclusive").value  = lDODtl.FindField("TaxInclusive").Value
      lDetail.FindField("UnitPrice").AsFloat    = lDODtl.FindField("UnitPrice").AsFloat
      lDetail.FindField("Amount").AsFloat      = lDODtl.FindField("Amount").AsFloat
      lDetail.FindField("TaxAmt").AsFloat      = lDODtl.FindField("TaxAmt").AsFloat
  lDetail.FindField("FromDocType").AsString = "DO"
  lDetail.FindField("FromDockey").AsFloat  = lDODtl.FindField("DocKey").AsFloat
  lDetail.FindField("FromDtlkey").AsFloat  = lDODtl.FindField("DtlKey").AsFloat
      lDetail.Post
End IF 
    v(0) = "ANT"
    v(1) = "BOX"
    if (lDODtl.Locate("ItemCode;UOM", v, false, false)) then
      lDetail.Append
      lDetail.FindField("DtlKey").value        = -1
      lDetail.FindField("DocKey").value        = -1
      lDetail.FindField("Seq").value            = 2
      lDetail.FindField("ItemCode").AsString    = lDODtl.FindField("ItemCode").AsString
      lDetail.FindField("Description").AsString = lDODtl.FindField("Description").AsString
      'lDetail.FindField("Account").AsString    = "500-000" 'If you wanted override the Sales Account Code
      lDetail.FindField("UOM").AsString        = lDODtl.FindField("UOM").AsString
  lDetail.FindField("Qty").AsFloat          = lDODtl.FindField("Qty").AsFloat
      lDetail.FindField("DISC").AsString        = lDODtl.FindField("Disc").AsString
      lDetail.FindField("Tax").AsString        = lDODtl.FindField("Tax").AsString
      lDetail.FindField("TaxRate").AsString    = lDODtl.FindField("TaxRate").AsString
      lDetail.FindField("TaxInclusive").value  = lDODtl.FindField("TaxInclusive").Value
      lDetail.FindField("UnitPrice").AsFloat    = lDODtl.FindField("UnitPrice").AsFloat
      lDetail.FindField("Amount").AsFloat      = lDODtl.FindField("Amount").AsFloat
      lDetail.FindField("TaxAmt").AsFloat      = lDODtl.FindField("TaxAmt").AsFloat
  lDetail.FindField("FromDocType").AsString = "DO"
  lDetail.FindField("FromDockey").AsFloat  = lDODtl.FindField("DocKey").AsFloat
  lDetail.FindField("FromDtlkey").AsFloat  = lDODtl.FindField("DtlKey").AsFloat
      lDetail.Post
End IF 
   'Step 7: Save Document
   'Step 7: Save Document
  BizObject.Save
    BizObject.Save
  BizObject.Close
    BizObject.Close
    
    
   'Step 8 : Logout after done   
   'Step 8 : Logout after done   
   'ComServer.Logout
   'ComServer.Logout
    
    
   MsgBox "Done"   
   MsgBox "Posting IV Done"
  else MsgBox "--DO Test-- had been transfered. Posting IV aborted"   
  End IF
End Function
End Function
</syntaxhighlight>
</syntaxhighlight>
Line 8,175: Line 8,999:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-GL Stock Value-Insert,Edit & Delete====
====SL_IV-Edit====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! GL Stock Value Insert, Edit & Delete Script   
! SL_IV-Edit Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Available in Version 5.2018.833.759 & above
'Available in Version 5.2018.833.759 & above
'Copy below script & paste to notepad & name it as eg GLStockValue.vbs
'Copy below script & paste to notepad & name it as eg SL_IV.vbs
Call CheckLogin
Call CheckLogin
Call GetData
Call GetData
'Call InsertValue
Call PostData
'Call UpdateValue
Call DeleteValue


Dim ComServer, lDataSet
Dim ComServer, lDataSet
Line 8,206: Line 9,028:
Function GetData
Function GetData
Dim lSQL
Dim lSQL
   lSQL = "SELECT Dockey FROM GL_STOCK "
   lSQL = "SELECT Dockey FROM SL_IV "
   lSQL = lSQL & "WHERE BalanceStock='330-000' "
   lSQL = lSQL & "WHERE DocNo='IV-00010' "
   Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
   Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
End Function
End Function


Function InsertValue
Function PostData
Dim BizObject, lMain, lDetail
Dim BizObject, lMain, lDetail
   'Step 2: Find and Create the Biz Objects
   'Step 2: Find and Create the Biz Objects
   Set BizObject = ComServer.BizObjects.Find("GL_STOCK")  
   Set BizObject = ComServer.BizObjects.Find("SL_IV")  


   'Step 3: Set Dataset
   'Step 3: Set Dataset
Line 8,220: Line 9,042:
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data   
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data   
    
    
   'Step 4 : Find Dockey Record
   'Step 4 : Find Doc Number
   If lDataSet.RecordCount > 0 Then   
   If lDataSet.RecordCount > 0 Then   
lDataSet.First
lDataSet.First
     BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString
     BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString
 
 
     BizObject.Open
     BizObject.Open
     BizObject.Edit
     BizObject.Edit
    lMain.Edit
lMain.FindField("Description").AsString = "Sales - Edited"
 
  'Step 5: Delete all Detail
    While lDetail.RecordCount <> 0
      lDetail.First
  lDetail.Delete
    Wend
  'Step 6: Append Detail
     lDetail.Append
     lDetail.Append
     lDetail.FindField("Project").value = "----"
     lDetail.FindField("DtlKey").value = -1
lDetail.FindField("SYear").value = 2021
    lDetail.FindField("Account").value = "500-000"
lDetail.FindField("SMonth").value = 4
    lDetail.FindField("Description").value =  "Edited Item A"
lDetail.FindField("Amount").value = 423.00
    lDetail.FindField("Tax").value = ""
    lDetail.FindField("TaxInclusive").value = 0
    lDetail.FindField("Amount").value = 410.37
    lDetail.FindField("TaxAmt").value = 0
     lDetail.Post
     lDetail.Post
 
   'Step 6: Save Document
   'Step 7: Save Document
     BizObject.Save
     BizObject.Save
     BizObject.Close
     BizObject.Close
     MsgBox "Done"
 
   END IF
  'Step 8 : Logout after done 
    'ComServer.Logout 
     MsgBox "Done"
Else
MsgBox "Record Not Found"  
   END IF  
End Function
End Function
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>


Function UpdateValue
====GL_JE====
Dim BizObject, lMain, lDetail, v(2)
{| class="mw-collapsible mw-collapsed wikitable"
  'Step 2: Find and Create the Biz Objects
! GL_JE Script 
  Set BizObject = ComServer.BizObjects.Find("GL_STOCK")
|-
 
|
  'Step 3: Set Dataset
<syntaxhighlight lang="vb">
  Set lMain  = BizObject.DataSets.Find("MainDataSet") 'lMain contains master data
'Copy below script & paste to notepad & name it as eg GL_JE.vbs
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data  
Call InsertGLJE
 
   
   'Step 4 : Find Dockey Record
Function CreateSQLAccServer
   If lDataSet.RecordCount > 0 Then  
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
lDataSet.First
End Function
     BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString 
   
Function InsertGLJE
    BizObject.Open
Dim ComServer, BizObject, lDataSet, lDataSet2, lDate
    BizObject.Edit
 
   'Step 1: Create Com Server object
    v(0) = "----" 'Project Code
  Set ComServer = CreateSQLAccServer 'Create Com Server
    v(1) = "2021" 'Year
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
v(2) = "3" 'Month to update
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"  
   END IF
if (lDetail.Locate("Project;SYear;SMonth", v, false, false)) then
      lDetail.Edit
      lDetail.FindField("Amount").value = 333.12     
      lDetail.Post
End IF
  'Step 6: Save Document
    BizObject.Save
    BizObject.Close
    MsgBox "Done"
   END IF
End Function
 
Function DeleteValue
Dim BizObject, lMain, lDetail, v(2)
   'Step 2: Find and Create the Biz Objects
   'Step 2: Find and Create the Biz Objects
   Set BizObject = ComServer.BizObjects.Find("GL_STOCK")  
   Set BizObject = ComServer.BizObjects.Find("GL_JE")  
 
   'Step 3: Set Dataset
   'Step 3: Set Dataset
   Set lMain  = BizObject.DataSets.Find("MainDataSet") 'lMain contains master data
   Set lMainDataSet = BizObject.DataSets.Find("MainDataSet")   'lMainDataSet contains master data
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data   
   Set lDetailDataSet = BizObject.DataSets.Find("cdsDocDetail") 'lDetailDataSet contains detail data   
 
  'Step 4 : Insert Data - Master
  lDate = CDate("January 23, 2017")
  BizObject.New
  lMainDataSet.FindField("DocKey").value = -1
  lMainDataSet.FindField("DocNo").value = "--JV Test--"
  lMainDataSet.FindField("DocDate").value = lDate
  lMainDataSet.FindField("PostDate").value = lDate
  lMainDataSet.FindField("Description").value = "testing desc header"
  lMainDataSet.Post
    
    
   'Step 4 : Find Dockey Record
   'Step 5: Insert Data - Detail
   If lDataSet.RecordCount > 0 Then    
  'For Tax Inclusive
lDataSet.First
   lDetailDataSet.Append
    BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString 
   lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
    BizObject.Open
  lDetailDataSet.FindField("SEQ").value = 1
    BizObject.Edit
  lDetailDataSet.FindField("Code").value = "610-1000"
 
  lDetailDataSet.FindField("Project").value = "----"
    v(0) = "----" 'Project Code
  lDetailDataSet.FindField("Description").value =  "testing desc1"
    v(1) = "2021" 'Year
  lDetailDataSet.FindField("Tax").value =  "TX"
v(2) = "4" 'Month to update
  'lDetailDataSet.FindField("LOCALTAXAMT").value = 17.32 //For JE you can't override (i.e. system auto calc)
  lDetailDataSet.FindField("TaxInclusive").Value = 1
if (lDetail.Locate("Project;SYear;SMonth", v, false, false)) then
  lDetailDataSet.FindField("LocalDR").value = 306 '//Including GST if TAXINCLUSIVE = 1
      lDetail.Delete
  lDetailDataSet.FindField("DR").value = 306 '//If wanted DR <> LocalDR
End IF
 
  'For Tax Exclusive
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
  lDetailDataSet.FindField("SEQ").value = 2
  lDetailDataSet.FindField("Code").value = "605-200"
  lDetailDataSet.FindField("Project").value = "----"
  lDetailDataSet.FindField("Description").value = "testing desc2"
  lDetailDataSet.FindField("Tax").value =  "TX"
  lDetailDataSet.FindField("TaxInclusive").value =  0
  lDetailDataSet.FindField("LocalCR").value = 100
  lDetailDataSet.Post
 
  'For No GST
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
  lDetailDataSet.FindField("SEQ").value = 3
  lDetailDataSet.FindField("Code").value = "610-002"
  lDetailDataSet.FindField("Project").value = "----"
  lDetailDataSet.FindField("Description").value =  "testing desc3"
  lDetailDataSet.FindField("Tax").value =  ""
  lDetailDataSet.FindField("TaxInclusive").value =  0
  lDetailDataSet.FindField("LocalCR").value = 200
  lDetailDataSet.Post
   'Step 6: Save Document
   'Step 6: Save Document
    BizObject.Save
  BizObject.Save
    BizObject.Close
  BizObject.Close
    MsgBox "Done"
  MsgBox "Done"
  END IF
End Function
End Function
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Stock Item Template to SL_IV====
====GL_JE-Edit====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Stock Item Template to SL_IV Script   
! GL_JE-Edit Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vb">
'Updated 03 Sep 2021
'Available in Version 5.2018.833.759 & above
'Copy below script & paste to notepad & name it as eg SL_IV.vbs
'Copy below script & paste to notepad & name it as eg GL_JE.vbs
Call CheckLogin
Call CheckLogin
Call InsertData1
Call GetData
Call InsertData2
Call PostData


Dim ComServer
Dim ComServer, lDataSet


Function CreateSQLAccServer
Function CreateSQLAccServer
Line 8,336: Line 9,200:
End Function
End Function


Function InsertData1
Function GetData
Dim BizObject, lMain, lDetail, lDate
Dim lSQL
  lSQL = "SELECT Dockey FROM GL_JE "
  lSQL = lSQL & "WHERE DocNo='JV-00002' "
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
End Function
 
Function PostData
Dim BizObject, lMain, lDetail
   'Step 2: Find and Create the Biz Objects
   'Step 2: Find and Create the Biz Objects
   Set BizObject = ComServer.BizObjects.Find("ST_ITEM_TPL")  
   Set BizObject = ComServer.BizObjects.Find("GL_JE")  


   'Step 3: Set Dataset
   'Step 3: Set Dataset
   Set lMain  = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
   Set lMain  = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
   Set lDetail = BizObject.DataSets.Find("cdsItemTplDtl") 'lDetail contains detail data   
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data   
 
  'Step 4 : Find Doc Number
  If lDataSet.RecordCount > 0 Then 
lDataSet.First
    BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString
 
 
    BizObject.Open
    BizObject.Edit
    lMain.Edit
lMain.FindField("Description").AsString = "Journal - Edited"
    
    
  'Begin Looping yr data
   'Step 5: Delete all Detail
   'Step 4 : Insert Data - Master
    While lDetail.RecordCount <> 0
  BizObject.New
      lDetail.First
  lMain.FindField("Code").AsString        = "--TPL Test--"
  lDetail.Delete
  lMain.FindField("Description").AsString = "Template formt 1"
     Wend
  lMain.FindField("RefPrice").AsFloat    = 299.15
   'Step 6: Append Detail
      
   'Step 5: Insert Data - Detail
   lDetail.Append
   lDetail.Append
   lDetail.FindField("DtlKey").value         = -1
   lDetail.FindField("DtlKey").value = -1
   lDetail.FindField("Code").AsString        = "--TPL Test--"
   lDetail.FindField("Code").value = "610-000"
   lDetail.FindField("Seq").value           = 1
   lDetail.FindField("Description").value = "testing desc1"
  lDetail.FindField("ItemCode").AsString    = "ANT"
   lDetail.FindField("Project").value = "P12W1"
   lDetail.FindField("Description").AsString = "Sales Item A"
   lDetail.FindField("Tax").value = ""
   lDetail.FindField("UOM").AsString        = "BOX"
   lDetail.FindField("TaxInclusive").value 0
   lDetail.FindField("Qty").AsFloat          = 2
   lDetail.FindField("LocalDR").value = 200
  'lDetail.FindField("DISC").AsString        = "5%+3" 'Optional (eg 5% plus 3 Discount)
   lDetail.FindField("DR").value = 200
  lDetail.FindField("UNITAMOUNT").AsFloat    = 100  
   lDetail.Post  
   lDetail.FindField("Amount").AsFloat      = 200
   lDetail.FindField("PRINTABLE").AsString  = "T"
   lDetail.Post


   lDetail.Append
   lDetail.Append
   lDetail.FindField("DtlKey").value         = -1
   lDetail.FindField("DtlKey").value = -1
   lDetail.FindField("Code").AsString        = "--TPL Test--"  
   lDetail.FindField("Code").value = "531-000"
   lDetail.FindField("Seq").value           = 2
   lDetail.FindField("Description").value = "testing desc2"
  lDetail.FindField("ItemCode").AsString    = "COVER"
   lDetail.FindField("Project").value = "P13W1"
   lDetail.FindField("Description").AsString = "Sales Item B"
   lDetail.FindField("Tax").value = ""
   lDetail.FindField("UOM").AsString        = "UNIT"
   lDetail.FindField("TaxInclusive").value = 0
   lDetail.FindField("Qty").AsFloat          = 3
   lDetail.FindField("LocalCR").value = 200
   'lDetail.FindField("DISC").AsString        = "5%+3" 'Optional (eg 5% plus 3 Discount)
   lDetail.FindField("CR").value = 200
   lDetail.FindField("UNITAMOUNT").AsFloat    = 10 
   lDetail.Post
   lDetail.FindField("Amount").AsFloat      = 30
    
   lDetail.FindField("PRINTABLE").AsString  = "T"
   'Step 7: Save Document
  lDetail.Post 
    BizObject.Save
   'Step 6: Save Document
    BizObject.Close
  BizObject.Save
    
  BizObject.Close
  'Step 8 : Logout after done 
   MsgBox "Template Posting Done"
    'ComServer.Logout 
    MsgBox "Done"  
Else
MsgBox "Record Not Found"
  END IF
End Function
End Function
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>


Function InsertData2
====GL_JE-Delete====
Dim BizObject, lMain, lDetail, lDate, lDODtl, lSQL, v(2)
{| class="mw-collapsible mw-collapsed wikitable"
  'Step 1: Get Template Information
! GL_JE-Delete Script 
  lSQL = "SELECT * FROM ST_ITEM_TPLDTL "
|-
  lSQL = lSQL & "WHERE Code='--TPL Test--' "
|
  Set lDODtl = ComServer.DBManager.NewDataSet(lSQL)
<syntaxhighlight lang="vb">
'Available in Version 5.2018.833.759 & above
'Copy below script & paste to notepad & name it as eg GL_JE.vbs
Call CheckLogin
Call GetData
Call DelData
 
Dim ComServer, lDataSet


   if lDODtl.RecordCount > 0 then
Function CreateSQLAccServer
'Step 2: Find and Create the Biz Objects
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
    Set BizObject = ComServer.BizObjects.Find("SL_IV")  
End Function


    'Step 3: Set Dataset
function CheckLogin
    Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  'Step 1: Create Com Server object
    Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data 
   Set ComServer = CreateSQLAccServer 'Create Com Server
    
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    'Step 4 : Insert Data - Master
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
    lDate = CDate("January 1, 2021")
                'UserName, Password, DCF full path, Database filename
    BizObject.New
   END IF
    lMain.FindField("DocKey").value        = -1
    lMain.FindField("DocNo").AsString      = "--IV Test--"
    lMain.FindField("DocDate").value        = lDate
    lMain.FindField("PostDate").value      = lDate
    lMain.FindField("Code").AsString        = "300-C0001" 'Customer Account
    lMain.FindField("CompanyName").AsString = "Cash Sales"
    'lMain.FindField("Address1").AsString    = "" 'Optional
     'lMain.FindField("Address2").AsString    = "" 'Optional
    'lMain.FindField("Address3").AsString    = "" 'Optional
    'lMain.FindField("Address4").AsString    = "" 'Optional
    'lMain.FindField("Phone1").AsString      = "" 'Optional
    lMain.FindField("Description").AsString = "Sales"
   
    'Step 6: Insert Data - Detail
lDODtl.First
    While not lDODtl.Eof
      lDetail.Append
      lDetail.FindField("DtlKey").value        = -1
      lDetail.FindField("DocKey").value        = -1
      lDetail.FindField("Seq").value            = 1
      lDetail.FindField("ItemCode").AsString    = lDODtl.FindField("ItemCode").AsString
      lDetail.FindField("Description").AsString = lDODtl.FindField("Description").AsString
      lDetail.FindField("UOM").AsString        = lDODtl.FindField("UOM").AsString
      lDetail.FindField("Qty").AsFloat          = lDODtl.FindField("Qty").AsFloat
      lDetail.FindField("DISC").AsString        = lDODtl.FindField("Disc").AsString
      lDetail.FindField("UnitPrice").AsFloat    = lDODtl.FindField("UnitAmount").AsFloat
      lDetail.FindField("Amount").AsFloat      = lDODtl.FindField("Amount").AsFloat
      lDetail.FindField("PRINTABLE").AsString  = lDODtl.FindField("PRINTABLE").AsString
      lDetail.Post
  lDODtl.Next
Wend
  'Step 7: Save Document
    BizObject.Save
    BizObject.Close
 
  'Step 8 : Logout after done 
  'ComServer.Logout
 
  MsgBox "Posting IV Done"
  else MsgBox "--No Template found. Posting IV aborted" 
   End IF
End Function
End Function
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>
<br />


===JScript/JavaScript===
Function GetData
This Script only can run using Internet Explorer (till IE 11)
Dim lSQL
  lSQL = "SELECT Dockey FROM GL_JE "
  lSQL = lSQL & "WHERE DocNo='JV-00002' "
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
End Function


====Example-AR_IV====
Function DelData
{| class="mw-collapsible mw-collapsed wikitable"
Dim BizObject
! AR_IV Script   
  'Step 2: Find and Create the Biz Objects
|-
  Set BizObject = ComServer.BizObjects.Find("GL_JE")
  'Step 3 : Find Doc Number
  If lDataSet.RecordCount > 0 Then
lDataSet.First
    BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString
    BizObject.Open
    BizObject.Delete
    BizObject.Close
 
  'Step 4 : Logout after done 
    'ComServer.Logout 
    MsgBox "Done"
Else
MsgBox "Record Not Found"
  END IF
End Function
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>
 
====Get Invoice Next Number====
{| class="mw-collapsible mw-collapsed wikitable"
! Get Invoice Next Number Script   
|-
|  
|  
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="vb">
<html>
'Available in Version 5.2018.833.759 & above
<head>
'Copy below script & paste to notepad & name it as eg GetNextNo.vbs
<title>Add Customer Invoice</title>
Call CheckLogin
<script language="JScript">
Call GetData
var ComServer;
Call ShowNextNo
 
function CreateSQLAccServer() {
Dim ComServer, lDataSet
  ComServer = new ActiveXObject('SQLAcc.BizApp');
  if (!ComServer.IsLogin) {            /* check whether user has logon */
    ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
/* UserName, Password */
  }
}
function AutoInvoice() {
  var BizObject, lMainDataSet, lDetailDataSet;
  CreateSQLAccServer();
  BizObject = ComServer.BizObjects.Find('AR_IV');
  lMainDataSet = BizObject.DataSets.Find('MainDataSet');
  lDetailDataSet = BizObject.DataSets.Find('cdsDocDetail');
  BizObject.New();
  lMainDataSet.FindField('DocKey').value = -1;
  lMainDataSet.FindField('DocNo').value = "--IV Test--";
  lMainDataSet.FindField('DocDate').value = "01/10/2016";
  lMainDataSet.FindField('PostDate').value = "01/10/2016";
  lMainDataSet.FindField('Code').value = "300-A0003";
  lMainDataSet.FindField('Description').value = "Sales";


  /*For Tax Inclusive = True with override Tax Amount*/
Function CreateSQLAccServer
  lDetailDataSet.Append();
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
  lDetailDataSet.FindField('DtlKey').value = -1;
End Function
  lDetailDataSet.FindField('DocKey').value = -1;
   lDetailDataSet.FindField('Account').value = "500-000";
  lDetailDataSet.FindField('Description').value =  "Sales Item A";
  lDetailDataSet.FindField('Tax').value =  "SR";
  lDetailDataSet.FindField('TaxInclusive').value =  0;
  lDetailDataSet.FindField('Amount').value = 410.37;
  lDetailDataSet.FindField('TaxAmt').value = 24.63;
  lDetailDataSet.DisableControls();
  lDetailDataSet.FindField('TaxInclusive').value =  1;
  lDetailDataSet.EnableControls();
  lDetailDataSet.FindField('Changed').value = "F";
  lDetailDataSet.Post();


  /*For Tax Inclusive = False with override Tax Amount*/
function CheckLogin
   lDetailDataSet.Append();
   'Step 1: Create Com Server object
  lDetailDataSet.FindField('DtlKey').value = -1;
   Set ComServer = CreateSQLAccServer 'Create Com Server
   lDetailDataSet.FindField('DocKey').value = -1;
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
   lDetailDataSet.FindField('Account').value = "500-000";
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
  lDetailDataSet.FindField('Description').value =  "Sales Item B";
                'UserName, Password, DCF full path, Database filename
  lDetailDataSet.FindField('Tax').value =  "SR";
   END IF
  lDetailDataSet.FindField('TaxInclusive').value =  0;
End Function
  lDetailDataSet.FindField('Amount').value = 94.43;
  lDetailDataSet.FindField('TaxAmt').value = 5.66;
   lDetailDataSet.FindField('Changed').value = "F";
  lDetailDataSet.Post();


   /* Save document */ 
Function GetData
    BizObject.Save();
Dim lSQL
    BizObject.Close();
   lSQL = "SELECT A.*, B.NEXTNUMBER FROM SY_DOCNO A "
    alert('Customer Invoice - has been saved.');
  lSQL = lSQL & "INNER JOIN SY_DOCNO_DTL B ON (A.DOCKEY=B.PARENTKEY) "
}
  lSQL = lSQL & "WHERE A.DOCTYPE='IV' "
</script>
  lSQL = lSQL & "AND A.DESCRIPTION='Customer Invoice' "
</head>
  lSQL = lSQL & "AND A.STATESET=1 "
<body>
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
<input type="submit" value="SYNC" name="btnSubmit" onclick="AutoInvoice()">
End Function
</body>
</html>
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>


====Example-SL_CS====
Function ShowNextNo
{| class="mw-collapsible mw-collapsed wikitable"
Dim Desc, Fmt, NextNo, lResult, sb
! SL_CS Script   
  set sb = CreateObject("System.Text.StringBuilder")
|-
  'Step 2 : Find Doc Number
  If lDataSet.RecordCount > 0 Then 
lDataSet.First
    Desc = lDataSet.FindField("Description").AsString
Fmt  = lDataSet.FindField("Format").AsString
NextNo = lDataSet.FindField("NEXTNUMBER").Value
'Convert from IV-%.5d to IV-{0:d5}
sb.Append_3 Fmt
sb.Replace "d", ""
sb.Replace "%.","{0:d"
Fmt = sb.ToString & "}"
sb.Length = 0 'clear sb list
sb.AppendFormat Fmt, NextNo
lResult = sb.ToString
    MsgBox Desc
MsgBox Fmt
MsgBox NextNo
MsgBox lResult
Else
MsgBox "Record Not Found"
  END IF   
End Function
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>
 
====Auto Run Doc. Number====
{| class="mw-collapsible mw-collapsed wikitable"
! Sales Order Auto Run Doc Number Script   
|-
|  
|  
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="vb">
<html>
'Copy below script & paste to notepad & name it as eg SL_SO.vbs
<head>
'If had prompt Set Default - Just click Yes to avoid keep prompt
<title>Add Cash Sales</title>
Call CheckLogin
<script language="JScript">
Call GetData
var ComServer;
Call InsertData


function CreateSQLAccServer() {
Dim ComServer, lDataSet
  ComServer = new ActiveXObject('SQLAcc.BizApp');
  if (!ComServer.IsLogin) {            /* check whether user has logon */
    ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
/* UserName, Password */
  }
}


function InsertData() {
Function CreateSQLAccServer
  var BizObject, lMain, lDetail;
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
 
End Function
   CreateSQLAccServer();


   /*Step 2: Find and Create the Biz Objects*/
function CheckLogin
   BizObject = ComServer.BizObjects.Find('SL_CS') ;
   'Step 1: Create Com Server object
 
  Set ComServer = CreateSQLAccServer 'Create Com Server
   /*Step 3: Set Dataset*/
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
   lMain  = BizObject.DataSets.Find('MainDataSet'); /*lMain contains master data*/
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
   lDetail = BizObject.DataSets.Find('cdsDocDetail'); /*lDetail contains detail data */  
                'UserName, Password, DCF full path, Database filename
  END IF
End Function
 
Function GetData
Dim lSQL
  lSQL = "SELECT * FROM SY_DOCNO "
  lSQL = lSQL & "WHERE DESCRIPTION='Customer Sales Order 2' "
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
End Function
 
 
Function InsertData
Dim BizObject, lMain, lDetail, lDate
  'Step 2: Find and Create the Biz Objects
   Set BizObject = ComServer.BizObjects.Find("SL_SO")  
 
   'Step 3: Set Dataset
   Set lMain  = BizObject.DataSets.Find("MainDataSet"'lMain contains master data
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data   
    
    
   /*Begin Looping yr data*/
   'Begin Looping yr data
   /*Step 4 : Insert Data - Master*/
   'Step 4 : Insert Data - Master
   BizObject.New();
  lDate = CDate("January 1, 2019")
   lMain.FindField('DocKey').value        = -1;
   BizObject.New
   lMain.FindField('DocNo').AsString      = "--IV Test--";
   lMain.FindField("DocKey").value        = -1
   lMain.FindField('DocDate').value        = "20/12/2017";
   lMain.FindField("DocNo").AsString      = "<<New>>"
   lMain.FindField('PostDate').value      = "20/12/2017";
   lMain.FindField("DocDate").value        = lDate
   lMain.FindField('Code').AsString        = "300-C0001"; /*Customer Account*/
   lMain.FindField("PostDate").value      = lDate
   lMain.FindField('CompanyName').AsString = "Cash Sales"
   lMain.FindField("Code").AsString        = "300-C0001" 'Customer Account
   lMain.FindField('Address1').AsString    = ""; /*Optional*/
   lMain.FindField("CompanyName").AsString = "Cash Sales"
   lMain.FindField('Address2').AsString    = ""; /*Optional*/
   lMain.FindField("Address1").AsString    = "" 'Optional
   lMain.FindField('Address3').AsString    = ""; /*Optional*/
   lMain.FindField("Address2").AsString    = "" 'Optional
   lMain.FindField('Address4').AsString    = ""; /*Optional*/
   lMain.FindField("Address3").AsString    = "" 'Optional
   lMain.FindField('Phone1').AsString      = ""; /*Optional*/
   lMain.FindField("Address4").AsString    = "" 'Optional
   lMain.FindField('Description').AsString = "Sales";
   lMain.FindField("Phone1").AsString      = "" 'Optional
   lMain.FindField("Description").AsString = "Sales Order"
  lMain.FindField("DocNoSetKey").value    = lDataSet.FindField("DocKey").value
      
      
   /*Step 5: Insert Data - Detail*/
   'Step 5: Insert Data - Detail
   /*For Tax Inclusive = True with override Tax Amount*/
   'For With Item Code
   lDetail.Append();
   lDetail.Append
   lDetail.FindField('DtlKey').value        = -1;
   lDetail.FindField("DtlKey").value        = -1
   lDetail.FindField('DocKey').value        = -1;
   lDetail.FindField("DocKey").value        = -1
   lDetail.FindField('Seq').value            = 1;
   lDetail.FindField("Seq").value            = 3
   lDetail.FindField('Account').AsString     = "500-000"; /*Sales Account*/
   lDetail.FindField("ItemCode").AsString   = "ANT"
   lDetail.FindField('Description').AsString = "Sales Item A";
   lDetail.FindField("Description").AsString = "Sales Item B"
   lDetail.FindField('Qty').AsFloat          = 1;
   lDetail.FindField("Qty").AsFloat          = 2
   lDetail.FindField('Tax').AsString        = "SR";
  lDetail.FindField("UOM").AsString        = "UNIT"
   lDetail.FindField('TaxRate').AsString    = "6%";
   'lDetail.FindField("DISC").AsString        = "5%+3" 'Optional (eg 5% plus 3 Discount)
   lDetail.FindField('TaxInclusive').value  = 0;
  lDetail.FindField("Tax").AsString        = ""
   lDetail.FindField('UnitPrice').AsFloat    = 435;
   lDetail.FindField("TaxRate").AsString    = ""
   lDetail.FindField('Amount').AsFloat      = 410.37; /*Exclding GST Amt*/
   lDetail.FindField("TaxInclusive").value  = 0
   lDetail.FindField('TaxAmt').AsFloat      = 24.63;
   lDetail.FindField("UnitPrice").AsFloat    = 100 
   lDetail.FindField("Amount").AsFloat      = 200
   lDetail.FindField("TaxAmt").AsFloat      = 0
  lDetail.Post
 
  'Step 6: Save Document
  BizObject.Save
  BizObject.Close
    
    
   lDetail.DisableControls();
   'Step 7 : Logout after done 
   lDetail.FindField('TaxInclusive').value  = 1;
   'ComServer.Logout
  lDetail.EnableControls();
    
    
   lDetail.Post();
   MsgBox "Done" 
 
End Function
  /*For Tax Inclusive = False with override Tax Amount*/
</syntaxhighlight>
  lDetail.Append();
|}
  lDetail.FindField('DtlKey').value        = -1;
<div style="float: right;">   [[#top|[top]]]</div>
  lDetail.FindField('DocKey').value        = -1;
  lDetail.FindField('Seq').value            = 2;
  lDetail.FindField('Account').AsString    = "500-000";
  lDetail.FindField('Description').AsString = "Sales Item B";
   lDetail.FindField('Qty').AsFloat          = 1;
  lDetail.FindField('Tax').AsString        = "SR";
  lDetail.FindField('TaxRate').AsString    = "6%";
  lDetail.FindField('TaxInclusive').value  = 0;
  lDetail.FindField('UnitPrice').AsFloat    = 94.43;
  lDetail.FindField('Amount').AsFloat      = 94.43;
  lDetail.FindField('TaxAmt').AsFloat      = 5.66;
  lDetail.Post();


   /*For With Item Code*/
====GL_PV====
   lDetail.Append();
{| class="mw-collapsible mw-collapsed wikitable"
   lDetail.FindField('DtlKey').value        = -1;
! Cash Book PV Script 
  lDetail.FindField('DocKey').value         = -1;
|-
  lDetail.FindField('Seq').value            = 3;
|
  lDetail.FindField('ItemCode').AsString   = "ANT";
<syntaxhighlight lang="vb">
  lDetail.FindField('Description').AsString = "Sales Item B";
'Copy below script & paste to notepad & name it as eg AR_PM.vbs
  /*lDetail.FindField('Account').AsString     = "500-000"; If you wanted override the Sales Account Code*/
Call PostData
  lDetail.FindField('Qty').AsFloat         = 2;
  lDetail.FindField('UOM').AsString         = "UNIT";
Function CreateSQLAccServer
   /*lDetail.FindField('DISC').AsString        = "5%+3"; Optional (eg 5% plus 3 Discount)*/
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
  lDetail.FindField('Tax').AsString         = "SR";
End Function
  lDetail.FindField('TaxRate').AsString     = "6%";
  lDetail.FindField('TaxInclusive').value  = 0;
Function PostData
  lDetail.FindField('UnitPrice').AsFloat   = 100;
Dim ComServer, BizObject, lIVNo, lDate
  lDetail.FindField('Amount').AsFloat       = 200;
  lDetail.FindField('TaxAmt').AsFloat       = 12;
  'Step 1: Create Com Server object
  lDetail.Post();
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
  END IF
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("GL_PV")
  'Step 3: Set Dataset
   Set lMain = BizObject.DataSets.Find("MainDataSet")   'lMainDataSet contains master data
   Set lDetailDataSet = BizObject.DataSets.Find("cdsDocDetail") 'lDetailDataSet contains detail data 
 
  'Step 4 : Posting
    lDate = CDate("January 23, 2020")
    BizObject.New
    lMain.FindField("DOCKEY").Value          = -1
    lMain.FindField("DocNo").AsString         = "--CB PV Test--"
    lMain.FindField("DocDate").Value          = lDate
    lMain.FindField("PostDate").Value        = lDate
    lMain.FindField("Description").AsString   = "Compacc System"
    lMain.FindField("PaymentMethod").AsString = "310-001"
lMain.FindField("CHEQUENUMBER").AsString = "MBB 213245"
    lMain.FindField("DocAmt").AsFloat         = 2019.57
    lMain.FindField("Cancelled").AsString     = "F"
lMain.Post
    
    lDetailDataSet.Append
    lDetailDataSet.FindField("DTLKEY").value = -1
lDetailDataSet.FindField("DOCKEY").value = -1
lDetailDataSet.FindField("Code").AsString = "200-300"
    lDetailDataSet.FindField("DESCRIPTION").AsString = "Maybank - Asus A555LD-xx313H"
lDetailDataSet.FindField("TAX").AsString = ""
lDetailDataSet.FindField("TAXAMT").AsFloat = 0
lDetailDataSet.FindField("TAXINCLUSIVE").AsFloat = 0
lDetailDataSet.FindField("AMOUNT").AsFloat = 2019.57
    lDetailDataSet.Post


   /*Step 6: Save Document*/
   'Step 5: Save Document
  BizObject.Save();
    BizObject.Save
  BizObject.Close();
    BizObject.Close
     alert('Document has been saved.');
     MsgBox "Done"
}
End Function
</script>
</head>
<body>
<input type="submit" value="SYNC" name="btnSubmit" onclick="InsertData()">
</body>
</html>
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>
 
====ST_Item with Opening====
====Example-AR_PM====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! AR_PM Script   
! ST_Item with Opening Script   
|-
|-
|  
|  
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="vb">
<html>
'Copy below script & paste to notepad & name it as eg ST_XF.vbs
<head>
Call CheckLogin
<title>Add Customer Payment</title>
Call InsertData
<script language="JScript">
 
var ComServer;
Dim ComServer


function CreateSQLAccServer() {
Function CreateSQLAccServer
   ComServer = new ActiveXObject("SQLAcc.BizApp");
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
  if (!ComServer.IsLogin) {            /* check whether user has logon */
End Function
    ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
/* UserName, Password */
  }
}


function AutoPayment() {
function CheckLogin
   var BizObject, lMainDataSet, lKnockOffDataSet, V;
   'Step 1: Create Com Server object
    
  Set ComServer = CreateSQLAccServer 'Create Com Server
  CreateSQLAccServer();
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
                'UserName, Password, DCF full path, Database filename
   END IF
End Function


  BizObject = ComServer.BizObjects.Find('AR_PM');
Function InsertData
   lMainDataSet = BizObject.DataSets.Find('MainDataSet');
Dim BizObject, lMain, lDtl, lOpn
  lKnockOffDataSet = BizObject.DataSets.Find('cdsKnockOff');
   'Step 2: Find and Create the Biz Objects
   BizObject.New();
   Set BizObject = ComServer.BizObjects.Find("ST_ITEM")  
 
  lMainDataSet.FindField('DocKey').value = -1;
  lMainDataSet.FindField('DocNo').value = "Test";
  lMainDataSet.FindField('Code').value = "888";
  lMainDataSet.FindField('DocDate').value = "01/09/2015";
  lMainDataSet.FindField('PostDate').value = "01/09/2015";
  lMainDataSet.FindField('Project').value = "----";
 
  lMainDataSet.FindField('Description').value = "";
  lMainDataSet.FindField('PaymentMethod').value = "320-000";
  lMainDataSet.FindField('Journal').value = "CASH";
  lMainDataSet.FindField('ChequeNumber').value = "";
  lMainDataSet.FindField('CurrencyCode').value = "----";
  lMainDataSet.FindField('CurrencyRate').value = "1.0000000000";
  lMainDataSet.FindField('DocAmt').value = "106.00";
  lMainDataSet.FindField('BankCharge').value = "0";
  lMainDataSet.FindField('UnappliedAmt').value = "0";
  lMainDataSet.FindField('Cancelled').value = 'F';
 
  v = ComServer.CreateOleVariantArray(2);
  v.SetItem(0, 'IV'); /*Knock Off DocType*/
  v.SetItem(1, 'IV-00111'); /*Knock Off DocNo*/


   if (lKnockOffDataSet.Locate('DocType;DocNo', v.AsOleVariant(), false, false)){
   'Step 3: Set Dataset
          lKnockOffDataSet.Edit();
  Set lMain = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
          lKnockOffDataSet.FindField('DocAmt').value = "106";  
  Set lDtl = BizObject.DataSets.Find("cdsUOM") 'lDetail contains detail data 
          lKnockOffDataSet.FindField('KnockOff').AsString = 'T';
  Set lOpn = BizObject.DataSets.Find("cdsOpeningBalance") 'lDetail contains detail data 
          lKnockOffDataSet.Post(); }
 
    /* Save document */ 
  'Begin Looping yr data
    BizObject.Save();
  'Step 4 : Insert Data - Master
    BizObject.Close();
  BizObject.New
    alert("Customer Payment - has been saved.");
  lMain.FindField("CODE").value = "==Test New Item Code=="
}
  lMain.FindField("DESCRIPTION").value = "Item Description 123"
</script>
  lMain.FindField("STOCKGROUP").value = "DEFAULT"
</head>
  lMain.FindField("STOCKCONTROL").value = "T"
<body>
  lMain.FindField("ISACTIVE").value = "T"
<input type="submit" value="SYNC" name="btnSubmit" onclick="AutoPayment()">
   
</body>
  'Step 5: Insert Data - Detail
</html>
  lDtl.Edit 'For 1St UOM
  lDtl.FindField("UOM").AsString = "PCS"
  lDtl.FindField("Rate").AsFloat = 1
  lDtl.FindField("RefCost").AsFloat = 10.2
  lDtl.FindField("RefPrice").AsFloat = 25
  lDtl.Post
 
  lDtl.Append 'For 2nd UOM
  lDtl.FindField("UOM").AsString = "CTN"
  lDtl.FindField("Rate").AsFloat = 12
  lDtl.FindField("RefCost").AsFloat = 102
  lDtl.FindField("RefPrice").AsFloat = 240
  lDtl.Post
 
  'Step 6: Insert Data - Opening
  lOpn.Append
  lOpn.FindField("LOCATION").AsString = "----"
  lOpn.FindField("Qty").AsFloat = 10 'in smallest UOM'
  lOpn.FindField("COST").AsFloat = 10.2
  lOpn.Post
 
  'Step 7: Save Document
  BizObject.Save
  BizObject.Close
 
  'Step 8 : Logout after done 
  'ComServer.Logout
 
  MsgBox "Done" 
End Function
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Customer.IV.RO====
====GL Stock Value-Insert,Edit & Delete====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Customer.IV.RO Report Object Script   
! GL Stock Value Insert, Edit & Delete Script   
|-
|-
|  
|  
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="vb">
<html>
'Available in Version 5.2018.833.759 & above
   <head>
'Copy below script & paste to notepad & name it as eg GLStockValue.vbs
     <title>Customer.IV.RO</title>
Call CheckLogin
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
Call GetData
    <script type="text/javascript">
'Call InsertValue
var ComServer;
'Call UpdateValue
Call DeleteValue
 
Dim ComServer, lDataSet
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
 
function CheckLogin
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
                'UserName, Password, DCF full path, Database filename
  END IF
End Function
 
Function GetData
Dim lSQL
  lSQL = "SELECT Dockey FROM GL_STOCK "
  lSQL = lSQL & "WHERE BalanceStock='330-000' "
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
End Function


function CreateSQLAccServer() {
Function InsertValue
   ComServer = new ActiveXObject("SQLAcc.BizApp");
Dim BizObject, lMain, lDetail
   if (!ComServer.IsLogin) {            /* check whether user has logon */
   'Step 2: Find and Create the Biz Objects
    ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
   Set BizObject = ComServer.BizObjects.Find("GL_STOCK")  
/* UserName, Password */
  }
}     


function GetData() {  
  'Step 3: Set Dataset
   var lMain, lDetail, lRptVar, lDateFrom, lDateTo;
  Set lMain  = BizObject.DataSets.Find("MainDataSet"'lMain contains master data
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data 
    
    
   elem = document.getElementById('txt1');
   'Step 4 : Find Dockey Record
    
   If lDataSet.RecordCount > 0 Then    
   CreateSQLAccServer();
lDataSet.First
 
    BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString 
  lDateFrom = new Date("January 1 2015");
  lDateTo = new Date("December 31, 2015");
    BizObject.Open
 
    BizObject.Edit
  lRptVar = ComServer.RptObjects.Find('Customer.IV.RO');
  lRptVar.Params.Find('SelectDate').Value           = true;
    lDetail.Append
  lRptVar.Params.Find('DateFrom').Value            = lDateFrom.valueOf();
    lDetail.FindField("Project").value = "----"
  lRptVar.Params.Find('DateTo').Value              = lDateTo.valueOf();
lDetail.FindField("SYear").value = 2021
  lRptVar.Params.Find('AllAgent').Value            = false;
lDetail.FindField("SMonth").value = 4
  lRptVar.Params.Find('AgentData').Value            = "----\nLF"; /*Filter by Agent code ---- & HALIM */
lDetail.FindField("Amount").value = 423.00
  lRptVar.Params.Find('AllArea').Value              = true;
    lDetail.Post
  lRptVar.Params.Find('AllCompany').Value          = true;
  lRptVar.Params.Find('AllCurrency').Value          = true;
   'Step 6: Save Document
   lRptVar.Params.Find('AllDocProject').Value        = true;
    BizObject.Save
   lRptVar.Params.Find('AllCompanyCategory').Value  = true;
    BizObject.Close
   lRptVar.Params.Find('AllDocument').Value          = true;
    MsgBox "Done"
   lRptVar.Params.Find('IncludeCancelled').Value  = false;
   END IF
   lRptVar.Params.Find('PrintDocumentStyle').Value = false;
End Function
   lRptVar.Params.Find('AllItemProject').Value    = true;
 
   lRptVar.Params.Find('AllPaymentMethod').Value  = true;
Function UpdateValue
  lRptVar.CalculateReport();  
Dim BizObject, lMain, lDetail, v(2)
   'Step 2: Find and Create the Biz Objects
   Set BizObject = ComServer.BizObjects.Find("GL_STOCK")  
 
   'Step 3: Set Dataset
   Set lMain  = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data  
    
    
   lMain   = lRptVar.DataSets.Find('cdsMain');
   'Step 4 : Find Dockey Record
  lDetail = lRptVar.DataSets.Find('cdsDocDetail');
   If lDataSet.RecordCount > 0 Then 
  /*alert("Count -" + lRptVar.DataSets.Find('cdsDocDetail').RecordCount);*/
lDataSet.First
  elem.innerHTML += 'From Main'+'\n';
    BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString 
      
  lMain.First();
    BizObject.Open
  while (!lMain.eof) {
     BizObject.Edit
     elem.innerHTML += lMain.FindField('DocKey').AsString + ' ' +
 
                  lMain.FindField('DocNo').AsString + ' ' + lMain.FindField('DocDate').AsString + ' '+
    v(0) = "----" 'Project Code
                      lMain.FindField('CompanyName').AsString + ' ' + lMain.FindField('DocAmt').AsString + '\n';
     v(1) = "2021" 'Year
lMain.Next()
v(2) = "3" 'Month to update
   }
   elem.innerHTML += 'End Main'+'\n\n';
if (lDetail.Locate("Project;SYear;SMonth", v, false, false)) then
 
      lDetail.Edit
   elem.innerHTML += 'From Detail'+'\n';
      lDetail.FindField("Amount").value = 333.12     
   lDetail.First();
      lDetail.Post
   while (!lDetail.eof) {
End IF
    elem.innerHTML += lDetail.FindField('Dockey').AsString + ' ' + lDetail.FindField('Account').AsString + ' ' +
  'Step 6: Save Document
                  lDetail.FindField('Description').AsString + ' ' + lDetail.FindField('Amount').AsString + '\n';
    BizObject.Save
lDetail.Next(); 
    BizObject.Close
  } 
    MsgBox "Done"
  elem.innerHTML += 'End Detail'+'\n\n';
  END IF
}
End Function
 
 
     </script>
Function DeleteValue
  </head>
Dim BizObject, lMain, lDetail, v(2)
  <body>
   'Step 2: Find and Create the Biz Objects
     <form>
   Set BizObject = ComServer.BizObjects.Find("GL_STOCK")
      <textarea id="txt1" rows="30" cols="116"></textarea>
 
      <input type="button" value="Calculate" onclick="GetData()">
   'Step 3: Set Dataset
     </form>
   Set lMain  = BizObject.DataSets.Find("MainDataSet") 'lMain contains master data
   </body>
   Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data 
</html>
 
  'Step 4 : Find Dockey Record
  If lDataSet.RecordCount > 0 Then 
lDataSet.First
    BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString
    BizObject.Open
     BizObject.Edit
 
     v(0) = "----" 'Project Code
    v(1) = "2021" 'Year
v(2) = "4" 'Month to update
if (lDetail.Locate("Project;SYear;SMonth", v, false, false)) then
      lDetail.Delete
End IF
  'Step 6: Save Document
    BizObject.Save
    BizObject.Close
     MsgBox "Done"
   END IF
End Function
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Customer.RO====
====Stock Item Template to SL_IV====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Customer.RO Report Object Script   
! Stock Item Template to SL_IV Script   
|-
|-
|  
|  
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="vb">
<html>
'Updated 03 Sep 2021
<head>
'Copy below script & paste to notepad & name it as eg SL_IV.vbs
<title>Add Customer Invoice</title>
Call CheckLogin
<script language='JScript'>
Call InsertData1
var ComServer;
Call InsertData2
 
function CreateSQLAccServer() {
Dim ComServer
   ComServer = new ActiveXObject('SQLAcc.BizApp');
 
   if (!ComServer.IsLogin) {            /* check whether user has logon */
Function CreateSQLAccServer
     ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
   Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
/* UserName, Password */
End Function
   }
 
}
function CheckLogin
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
   If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
     ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
                'UserName, Password, DCF full path, Database filename
  END IF
End Function
 
Function InsertData1
Dim BizObject, lMain, lDetail, lDate
   'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("ST_ITEM_TPL")


function GetCustomerData() {
  'Step 3: Set Dataset
   var RptObject, lDataSet, lDataSet2;
   Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
   edOutput.value = '';
   Set lDetail = BizObject.DataSets.Find("cdsItemTplDtl") 'lDetail contains detail data 
   edOutput2.value = '';
  //Step 1: Create Com Server object
  CreateSQLAccServer();
    
    
   //Step 2: Find and Create the Report Objects
   'Begin Looping yr data
   RptObject = ComServer.RptObjects.Find('Customer.RO');
   'Step 4 : Insert Data - Master
 
   BizObject.New
  //Step 3: Spool parameters
  lMain.FindField("Code").AsString        = "--TPL Test--"
   RptObject.Params.Find('AllAgent').Value = true;
   lMain.FindField("Description").AsString = "Template formt 1"
   RptObject.Params.Find('AllArea').Value = true;
   lMain.FindField("RefPrice").AsFloat    = 299.15
   RptObject.Params.Find('AllCompany').Value = true;
   
   RptObject.Params.Find('AllCompanyCategory').Value = true;
   'Step 5: Insert Data - Detail
   RptObject.Params.Find('AllCurrency').Value = true;
  lDetail.Append
   RptObject.Params.Find('AllTerms').Value = true;
  lDetail.FindField("DtlKey").value        = -1
   RptObject.Params.Find('SelectDate').Value = true;
   lDetail.FindField("Code").AsString        = "--TPL Test--"
   RptObject.Params.Find('PrintActive').Value = true;
   lDetail.FindField("Seq").value            = 1
   RptObject.Params.Find('PrintInactive').Value = false;
   lDetail.FindField("ItemCode").AsString    = "ANT"
   RptObject.Params.Find('PrintPending').Value = false;
   lDetail.FindField("Description").AsString = "Sales Item A"
   RptObject.Params.Find('PrintProspect').Value = false;
   lDetail.FindField("UOM").AsString        = "BOX"
   RptObject.Params.Find('PrintSuspend').Value = false;
   lDetail.FindField("Qty").AsFloat          = 2
   //RptObject.Params.Find('CompanyData').Value = '300-A0003';
   'lDetail.FindField("DISC").AsString        = "5%+3" 'Optional (eg 5% plus 3 Discount)
 
   lDetail.FindField("UNITAMOUNT").AsFloat    = 100 
  //Step 4: Perform Report calculation
   lDetail.FindField("Amount").AsFloat      = 200
   RptObject.CalculateReport();
   lDetail.FindField("PRINTABLE").AsString   = "T"
  lDataSet = RptObject.DataSets.Find('cdsMain');
   lDetail.Post
   lDataSet2 = RptObject.DataSets.Find('cdsBranch');
 
   //alert('Count ' + lDataSet.RecordCount);


   //Step 5 Retrieve the output
   lDetail.Append
   lDataSet.First;
   lDetail.FindField("DtlKey").value         = -1
  while  (!lDataSet.eof){
  lDetail.FindField("Code").AsString       = "--TPL Test--"
    edOutput.value = edOutput.value +
  lDetail.FindField("Seq").value            = 2
                'Code : ' + lDataSet.FindField('Code').AsString + '\n' +
   lDetail.FindField("ItemCode").AsString    = "COVER"
                'Company Name : ' + lDataSet.FindField('CompanyName').AsString +'\n\n';
  lDetail.FindField("Description").AsString = "Sales Item B"
lDataSet.Next();
  lDetail.FindField("UOM").AsString         = "UNIT"
  }
  lDetail.FindField("Qty").AsFloat          = 3
   lDataSet2.First();
  'lDetail.FindField("DISC").AsString       = "5%+3" 'Optional (eg 5% plus 3 Discount)
  while (!lDataSet2.eof){
  lDetail.FindField("UNITAMOUNT").AsFloat    = 10 
  edOutput2.value = edOutput2.value +
  lDetail.FindField("Amount").AsFloat      = 30
                  'Code : '+ lDataSet2.FindField('Code').AsString + '\n' +
  lDetail.FindField("PRINTABLE").AsString   = "T"
  'Branch Name : '+ lDataSet2.FindField('BranchName').AsString + '\n' +
  lDetail.Post  
                  'Address 1 : '+ lDataSet2.FindField('Address1').AsString + '\n' +
  'Step 6: Save Document
  'Address 2 : '+ lDataSet2.FindField('Address2').AsString + '\n' +
  BizObject.Save
  'Address 3 : '+ lDataSet2.FindField('Address3').AsString + '\n' +
  BizObject.Close
  'Address 4 : '+ lDataSet2.FindField('Address4').AsString + '\n' +
  MsgBox "Template Posting Done" 
  'Phone 1 : '+ lDataSet2.FindField('Phone1').AsString  +'\n\n';
End Function
  lDataSet2.Next();
    }
}


</script>
Function InsertData2
</head>
Dim BizObject, lMain, lDetail, lDate, lDODtl, lSQL, v(2)
<body>
  'Step 1: Get Template Information
   <table>
   lSQL = "SELECT * FROM ST_ITEM_TPLDTL "
    <tr>
   lSQL = lSQL & "WHERE Code='--TPL Test--' "
      <th>Main Table</th>
  Set lDODtl = ComServer.DBManager.NewDataSet(lSQL)
      <th>Branch Branch</th>
    </tr>
    <tr>
      <td>
        <TEXTAREA rows=15 cols=75 name="edOutput"></TEXTAREA>
  </td>
      <td>
        <TEXTAREA rows=15 cols=75 name="edOutput2"></TEXTAREA>
  </td>
    </tr>
  </table>
   <table width="83%">
<tr>
  <td align="center">
<input type='submit' value='Sync Data' name='btnSubmit' onclick='GetCustomerData()'>
  </td>
</tr>
  </table>
</body>
</html>
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Get Next IV Number====
  if lDODtl.RecordCount > 0 then
{| class="mw-collapsible mw-collapsed wikitable"
'Step 2: Find and Create the Biz Objects
! Get Next IV Number Script 
    Set BizObject = ComServer.BizObjects.Find("SL_IV")
|-
|
<syntaxhighlight lang="javascript">
<html>
<head>
<title>Add Cash Sales</title>
<script language="JScript">
var ComServer, lDataSet;


function CreateSQLAccServer() {
    'Step 3: Set Dataset
   ComServer = new ActiveXObject('SQLAcc.BizApp');
    Set lMain  = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  if (!ComServer.IsLogin) {            /* check whether user has logon */
    Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data 
     ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
    
/* UserName, Password */
    'Step 4 : Insert Data - Master
  }
    lDate = CDate("January 1, 2021")
}
    BizObject.New
 
    lMain.FindField("DocKey").value        = -1
function zeroPad(num, places) {
    lMain.FindField("DocNo").AsString      = "--IV Test--"
  var zero = places - num.toString().length + 1;
    lMain.FindField("DocDate").value        = lDate
  return Array(+(zero > 0 && zero)).join("0") + num;
    lMain.FindField("PostDate").value      = lDate
  /*zeroPad(5, 2); // "05"*/
    lMain.FindField("Code").AsString        = "300-C0001" 'Customer Account
}
    lMain.FindField("CompanyName").AsString = "Cash Sales"
 
     'lMain.FindField("Address1").AsString    = "" 'Optional
function GetData() {
    'lMain.FindField("Address2").AsString    = "" 'Optional
  var lSQL;
    'lMain.FindField("Address3").AsString    = "" 'Optional
  lSQL = "SELECT A.*, B.NEXTNUMBER FROM SY_DOCNO A ";
    'lMain.FindField("Address4").AsString    = "" 'Optional
  lSQL = lSQL + "INNER JOIN SY_DOCNO_DTL B ON (A.DOCKEY=B.PARENTKEY) ";
    'lMain.FindField("Phone1").AsString      = "" 'Optional
  lSQL = lSQL + "WHERE A.DOCTYPE='IV' ";
    lMain.FindField("Description").AsString = "Sales"
  lSQL = lSQL + "AND A.DESCRIPTION='Customer Invoice' ";
   
  lSQL = lSQL + "AND A.STATESET=1 ";
    'Step 6: Insert Data - Detail
   lDataSet = ComServer.DBManager.NewDataSet(lSQL)
lDODtl.First
}
    While not lDODtl.Eof
 
      lDetail.Append
function ShowNextNo() {
      lDetail.FindField("DtlKey").value        = -1
   var Desc, Fmt, NextNo, lResult, lPad;
      lDetail.FindField("DocKey").value        = -1
      lDetail.FindField("Seq").value            = 1
      lDetail.FindField("ItemCode").AsString    = lDODtl.FindField("ItemCode").AsString
      lDetail.FindField("Description").AsString = lDODtl.FindField("Description").AsString
      lDetail.FindField("UOM").AsString        = lDODtl.FindField("UOM").AsString
      lDetail.FindField("Qty").AsFloat          = lDODtl.FindField("Qty").AsFloat
      lDetail.FindField("DISC").AsString        = lDODtl.FindField("Disc").AsString
      lDetail.FindField("UnitPrice").AsFloat    = lDODtl.FindField("UnitAmount").AsFloat
      lDetail.FindField("Amount").AsFloat      = lDODtl.FindField("Amount").AsFloat
      lDetail.FindField("PRINTABLE").AsString   = lDODtl.FindField("PRINTABLE").AsString
      lDetail.Post
  lDODtl.Next
Wend
  'Step 7: Save Document
    BizObject.Save
    BizObject.Close
 
  'Step 8 : Logout after done 
   'ComServer.Logout
    
    
   CreateSQLAccServer()
   MsgBox "Posting IV Done"
   GetData();
  else MsgBox "--No Template found. Posting IV aborted" 
  End IF
End Function
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>
====AR_CN====
{| class="mw-collapsible mw-collapsed wikitable"
! AR_CN Script 
|-
|
<syntaxhighlight lang="vb">
'Updated 24 Feb 2023
'Copy below script & paste to notepad & name it as eg AR_CN.vbs
Call InsertData
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
 
Function InsertData
Dim ComServer, BizObject, lDate, lIVNO, v(1)
 
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
  END IF
 
  'Step 2: Find and Create the Biz Objects
   Set BizObject = ComServer.BizObjects.Find("AR_CN")  


   if (lDataSet.RecordCount > 0) {    
   'Step 3: Set Dataset
    lDataSet.First;
  Set lMainDataSet = BizObject.DataSets.Find("MainDataSet")    'lMainDataSet contains master data
    Desc = lDataSet.FindField("Description").AsString;
  Set lDetailDataSet = BizObject.DataSets.Find("cdsDocDetail") 'lDetailDataSet contains detail data 
Fmt  = lDataSet.FindField("Format").AsString;
  Set lKO = BizObject.DataSets.Find("cdsKnockOff") 'Contains IV/DN to knock off data 
NextNo = lDataSet.FindField("NEXTNUMBER").Value;
 
     alert(Desc);
  'Step 4 : Insert Data - Master
alert(Fmt);
   lDate = CDate("January 1, 2023")
alert(NextNo);
  BizObject.New
  lMainDataSet.FindField("DocKey").value = -1
lPad = Fmt.substr(5, 1);
  lMainDataSet.FindField("DocNo").value = "--CN Test--"
lPad = zeroPad(NextNo, lPad)
  lMainDataSet.FindField("DocDate").value = lDate
Desc = Fmt.substr(0, 3);
  lMainDataSet.FindField("PostDate").value = lDate
alert(Desc + lPad);
  lMainDataSet.FindField("Code").value = "300-A0001"
   }
  lMainDataSet.FindField("Description").value = "Credit Note"
}
      
</script>
  'Step 5: Insert Data - Detail
</head>
  'For Tax Inclusive = True with override Tax Amount
<body>
  lDetailDataSet.Append
<input type="submit" value="Show Next No" name="btnSubmit" onclick="ShowNextNo()">
  lDetailDataSet.FindField("DtlKey").value = -1
</body>
  lDetailDataSet.FindField("DocKey").value = -1
</html>
  lDetailDataSet.FindField("Account").value = "510-2000"
</syntaxhighlight>
  lDetailDataSet.FindField("Description").value =  "Sales Item A"
|}
  lDetailDataSet.FindField("Tax").value =  "SV"
<div style="float: right;">  [[#top|[top]]]</div>
  lDetailDataSet.FindField("TaxInclusive").value =  0
====Example-Customer & Supplier Contra====
  lDetailDataSet.FindField("Amount").value = 410.37
{| class="mw-collapsible mw-collapsed wikitable"
  lDetailDataSet.FindField("TaxAmt").value = 24.63
! Customer & Supplier Contra Script   
 
|-
  lDetailDataSet.DisableControls
|  
  lDetailDataSet.FindField("TaxInclusive").value = 1
<syntaxhighlight lang="javascript">
  lDetailDataSet.EnableControls
<html>
 
<head>
  lDetailDataSet.FindField("Changed").value = "F"
  lDetailDataSet.Post
 
  'For Tax Inclusive = False with override Tax Amount
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
   lDetailDataSet.FindField("Account").value = "510-2000"
  lDetailDataSet.FindField("Description").value =  "Sales Item B"
  lDetailDataSet.FindField("Tax").value =  "SV"
  lDetailDataSet.FindField("TaxInclusive").value =  0
  lDetailDataSet.FindField("Amount").value = 94.43
  lDetailDataSet.FindField("TaxAmt").value = 5.66
  lDetailDataSet.FindField("Changed").value = "F"
  lDetailDataSet.Post
 
  'Step 7: Knock Off IV
    lIVNO = "--IV Test--"
    v(0) = "IV"
    v(1) = lIVNO
    if (lKO.Locate("DocType;DocNo", v, false, false)) then
      lKO.Edit
      lKO.FindField("KOAmt").value = 65.57
      lKO.FindField("KnockOff").AsString = "T"
      lKO.Post
End IF 
 
  'Step 7: Save Document
  BizObject.Save
  BizObject.Close
  MsgBox "Done"
End Function
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>
<br />
 
===JScript/JavaScript===
This Script only can run using Internet Explorer (till IE 11)
 
====AR_IV====
{| class="mw-collapsible mw-collapsed wikitable"
! AR_IV Script   
|-
|  
<syntaxhighlight lang="javascript">
<html>
<head>
<title>Add Customer Invoice</title>
<title>Add Customer Invoice</title>
<script language="JScript">
<script language="JScript">
Line 9,007: Line 10,023:
}
}
   
   
function PostARCT() {
function AutoInvoice() {
   var BizObject, lMain, lKO, V;
   var BizObject, lMainDataSet, lDetailDataSet;
   
   
   CreateSQLAccServer();
   CreateSQLAccServer();
   
   
   BizObject = ComServer.BizObjects.Find('AR_CT');
   BizObject = ComServer.BizObjects.Find('AR_IV');
   lMain = BizObject.DataSets.Find('MainDataSet');
   lMainDataSet = BizObject.DataSets.Find('MainDataSet');
   lKO = BizObject.DataSets.Find('cdsKnockOff');
   lDetailDataSet = BizObject.DataSets.Find('cdsDocDetail');
   BizObject.New();
   BizObject.New();
   
   
   lMain.FindField('DocKey').value = -1;
   lMainDataSet.FindField('DocKey').value = -1;
   lMain.FindField('DocNo').value = "--CT Test--";
   lMainDataSet.FindField('DocNo').value = "--IV Test--";
   lMain.FindField('DocDate').value = "01/10/2020";
   lMainDataSet.FindField('DocDate').value = "01/10/2016";
   lMain.FindField('PostDate').value = "01/10/2020";
   lMainDataSet.FindField('PostDate').value = "01/10/2016";
   lMain.FindField('Code').value = "300-A0002";
   lMainDataSet.FindField('Code').value = "300-A0003";
   lMain.FindField('Description').value = "Contra";
   lMainDataSet.FindField('Description').value = "Sales";
  lMain.FindField('DocAmt').value = "100.00";
  //lMain.FindField('UnappliedAmt').value = "0";


   v = ComServer.CreateOleVariantArray(2);
   /*For Tax Inclusive = True with override Tax Amount*/
   v.SetItem(0, 'IV'); /*Knock Off DocType*/
  lDetailDataSet.Append();
   v.SetItem(1, 'IV-00021'); /*Knock Off DocNo*/
  lDetailDataSet.FindField('DtlKey').value = -1;
  lDetailDataSet.FindField('DocKey').value = -1;
   lDetailDataSet.FindField('Account').value = "500-000";
  lDetailDataSet.FindField('Description').value =  "Sales Item A";
  lDetailDataSet.FindField('Tax').value =  "SR";
  lDetailDataSet.FindField('TaxInclusive').value =  0;
  lDetailDataSet.FindField('Amount').value = 410.37;
  lDetailDataSet.FindField('TaxAmt').value = 24.63;
  lDetailDataSet.DisableControls();
   lDetailDataSet.FindField('TaxInclusive').value =  1;
  lDetailDataSet.EnableControls();
  lDetailDataSet.FindField('Changed').value = "F";
  lDetailDataSet.Post();


   if (lKO.Locate('DocType;DocNo', v.AsOleVariant(), false, false)){
   /*For Tax Inclusive = False with override Tax Amount*/
          lKO.Edit();
  lDetailDataSet.Append();
          lKO.FindField('DocAmt').value = "100";  
  lDetailDataSet.FindField('DtlKey').value = -1;
          lKO.FindField('KnockOff').AsString = 'T';
  lDetailDataSet.FindField('DocKey').value = -1;
          lKO.Post(); }
  lDetailDataSet.FindField('Account').value = "500-000";
  lDetailDataSet.FindField('Description').value =  "Sales Item B";
  lDetailDataSet.FindField('Tax').value =  "SR";
  lDetailDataSet.FindField('TaxInclusive').value =  0;
  lDetailDataSet.FindField('Amount').value = 94.43;
  lDetailDataSet.FindField('TaxAmt').value = 5.66;
  lDetailDataSet.FindField('Changed').value = "F";
  lDetailDataSet.Post();


   /* Save document */   
   /* Save document */   
     BizObject.Save();
     BizObject.Save();
     BizObject.Close();
     BizObject.Close();
     alert('Customer Contra - has been saved.');
     alert('Customer Invoice - has been saved.');
}
}
</script>
</head>
<body>
<input type="submit" value="SYNC" name="btnSubmit" onclick="AutoInvoice()">
</body>
</html>
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>


function PostAPST() {
====SL_CS====
  var BizObject, lMain, lKO, V, lDocNo, lDocKey;
{| class="mw-collapsible mw-collapsed wikitable"
! SL_CS Script   
  CreateSQLAccServer();
|-
|  
  BizObject = ComServer.BizObjects.Find('AP_ST');
<syntaxhighlight lang="javascript">
  lMain = BizObject.DataSets.Find('MainDataSet');
  lKO = BizObject.DataSets.Find('cdsKnockOff');
 
  lDocNo = "--CT Test--"
  lDocKey = BizObject.FindKeyByRef("DocNo", lDocNo)
  BizObject.Params.Find("DocKey").Value = lDocKey 
 
  if (lDocKey != null) {
    BizObject.Open();
BizObject.Edit();
lMain.FindField('Code').value = "400-C0001";
lMain.FindField('DocAmt').value = "100.00";
  //lMain.FindField('UnappliedAmt').value = "0";
 
  v = ComServer.CreateOleVariantArray(2);
  v.SetItem(0, 'PI'); /*Knock Off DocType*/
  v.SetItem(1, 'PI-00001'); /*Knock Off DocNo*/
 
    if (lKO.Locate('DocType;DocNo', v.AsOleVariant(), false, false)){
          lKO.Edit();
          lKO.FindField('DocAmt').value = "100";  
          lKO.FindField('KnockOff').AsString = 'T';
          lKO.Post(); }
 
  /* Save document */ 
    BizObject.Save(); 
    BizObject.Close();
    alert('Supplier Contra - has been Updated.');
  }
}
</script>
</head>
<body>
<button onclick="javascript:PostARCT();">PostARCT</button>&nbsp;&nbsp;
<button onclick="javascript:PostAPST();">PostAPST</button>&nbsp;&nbsp;
</body>
</html>
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>
 
====Example-Add Stock Item====
{| class="mw-collapsible mw-collapsed wikitable"
! Add ST_Item Script   
|-
|  
<syntaxhighlight lang="javascript">
<html>
<html>
<head>
<head>
<title>Add Stock Item</title>
<title>Add Cash Sales</title>
<script language="JScript">
<script language="JScript">
var ComServer;
var ComServer;
Line 9,115: Line 10,112:


   /*Step 2: Find and Create the Biz Objects*/
   /*Step 2: Find and Create the Biz Objects*/
   BizObject = ComServer.BizObjects.Find('ST_ITEM') ;
   BizObject = ComServer.BizObjects.Find('SL_CS') ;


   /*Step 3: Set Dataset*/
   /*Step 3: Set Dataset*/
   lMain  = BizObject.DataSets.Find('MainDataSet');  /*lMain contains master data*/
   lMain  = BizObject.DataSets.Find('MainDataSet');  /*lMain contains master data*/
   lUOM = BizObject.DataSets.Find('cdsUOM'); /*lDetail contains detail data */   
   lDetail = BizObject.DataSets.Find('cdsDocDetail'); /*lDetail contains detail data */   
    
    
   /*Begin Looping yr data*/
   /*Begin Looping yr data*/
   /*Step 4 : Insert Data - Master*/
   /*Step 4 : Insert Data - Master*/
   BizObject.New();
   BizObject.New();
   lMain.FindField('Code').AsString        = "Code JScript";
  lMain.FindField('DocKey').value        = -1;
   lMain.FindField('DESCRIPTION').AsString = "Post from JScript"
  lMain.FindField('DocNo').AsString      = "--IV Test--";
   lMain.FindField('STOCKGROUP').AsString    = "DEFAULT"; /*Optional*/
  lMain.FindField('DocDate').value        = "20/12/2017";
   lMain.FindField('STOCKCONTROL').AsString    = "T"; /*Optional*/
  lMain.FindField('PostDate').value      = "20/12/2017";
   lMain.FindField('ISACTIVE').AsString    = "T"; /*Optional*/
   lMain.FindField('Code').AsString        = "300-C0001"; /*Customer Account*/
      
   lMain.FindField('CompanyName').AsString = "Cash Sales"
   /*Step 5: Insert Data - UOM*/
  lMain.FindField('Address1').AsString    = ""; /*Optional*/
   lUOM.Edit(); /*For 1St UOM*/
   lMain.FindField('Address2').AsString    = ""; /*Optional*/
   lUOM.FindField('UOM').AsString = "PCS";
   lMain.FindField('Address3').AsString    = ""; /*Optional*/
   lUOM.FindField('Rate').AsFloat = 1;
   lMain.FindField('Address4').AsString    = ""; /*Optional*/
   lUOM.FindField('RefCost').AsFloat = 10.2;
  lMain.FindField('Phone1').AsString      = ""; /*Optional*/
   lUOM.FindField('RefPrice').AsFloat = 25;
  lMain.FindField('Description').AsString = "Sales";
   lUOM.Post();
      
   /*Step 5: Insert Data - Detail*/
   /*For Tax Inclusive = True with override Tax Amount*/
  lDetail.Append();
  lDetail.FindField('DtlKey').value        = -1;
  lDetail.FindField('DocKey').value        = -1;
  lDetail.FindField('Seq').value            = 1;
  lDetail.FindField('Account').AsString    = "500-000"; /*Sales Account*/
  lDetail.FindField('Description').AsString = "Sales Item A";
  lDetail.FindField('Qty').AsFloat          = 1;
  lDetail.FindField('Tax').AsString        = "SR";
  lDetail.FindField('TaxRate').AsString    = "6%";
  lDetail.FindField('TaxInclusive').value  = 0;
  lDetail.FindField('UnitPrice').AsFloat    = 435;
  lDetail.FindField('Amount').AsFloat      = 410.37; /*Exclding GST Amt*/
  lDetail.FindField('TaxAmt').AsFloat      = 24.63;
 
  lDetail.DisableControls();
  lDetail.FindField('TaxInclusive').value  = 1;
  lDetail.EnableControls();
 
  lDetail.Post();
 
  /*For Tax Inclusive = False with override Tax Amount*/
   lDetail.Append();
  lDetail.FindField('DtlKey').value        = -1;
  lDetail.FindField('DocKey').value        = -1;
  lDetail.FindField('Seq').value            = 2;
  lDetail.FindField('Account').AsString    = "500-000";
  lDetail.FindField('Description').AsString = "Sales Item B";
   lDetail.FindField('Qty').AsFloat         = 1;
   lDetail.FindField('Tax').AsString        = "SR";
  lDetail.FindField('TaxRate').AsString    = "6%";
  lDetail.FindField('TaxInclusive').value  = 0;
  lDetail.FindField('UnitPrice').AsFloat   = 94.43;
  lDetail.FindField('Amount').AsFloat      = 94.43;
   lDetail.FindField('TaxAmt').AsFloat       = 5.66;
   lDetail.Post();


   lUOM.Append(); /*For 2nd UOM*/
   /*For With Item Code*/
   lUOM.FindField('UOM').AsString = "CTN";
  lDetail.Append();
   lUOM.FindField('Rate').AsFloat = 12;
  lDetail.FindField('DtlKey').value        = -1;
   lUOM.FindField('RefCost').AsFloat = 102;
  lDetail.FindField('DocKey').value        = -1;
   lUOM.FindField('RefPrice').AsFloat = 240;
  lDetail.FindField('Seq').value            = 3;
   lUOM.Post();
  lDetail.FindField('ItemCode').AsString    = "ANT";
 
  lDetail.FindField('Description').AsString = "Sales Item B";
   /*Step 6: Save*/
  /*lDetail.FindField('Account').AsString    = "500-000"; If you wanted override the Sales Account Code*/
  lDetail.FindField('Qty').AsFloat          = 2;
  lDetail.FindField('UOM').AsString        = "UNIT";
  /*lDetail.FindField('DISC').AsString        = "5%+3"; Optional (eg 5% plus 3 Discount)*/
   lDetail.FindField('Tax').AsString        = "SR";
  lDetail.FindField('TaxRate').AsString     = "6%";
   lDetail.FindField('TaxInclusive').value  = 0;
  lDetail.FindField('UnitPrice').AsFloat   = 100;
   lDetail.FindField('Amount').AsFloat       = 200;
   lDetail.FindField('TaxAmt').AsFloat       = 12;
   lDetail.Post();
 
   /*Step 6: Save Document*/
   BizObject.Save();
   BizObject.Save();
   BizObject.Close();
   BizObject.Close();
     alert('Item has been saved.');
     alert('Document has been saved.');
}
}
</script>
</script>
Line 9,159: Line 10,205:
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>
<br />


===Delphi===
====AR_PM====
The below example is assuming after you had check the login status.
====Example-GL_JE====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! GL_JE Script   
! AR_PM Script   
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="javascript">
procedure TfmMain.dxbb_GL_JEClick(Sender: TObject);
<html>
var BizApp, lMain, lDtl, lBizObj, lDocKey : Variant;
<head>
    i : integer;
<title>Customer Payment</title>
begin
<script language="JScript">
  BizApp := CreateOleObject('SQLAcc.BizApp');
<html>
  try
<head>
    lBizObj := BizApp.BizObjects.Find('GL_JE');
<title>Add Customer Payment</title>
    lMain   := lBizObj.DataSets.Find('MainDataSet');
<script language="JScript">
    lDtl    := lBizObj.DataSets.Find('cdsDocDetail');
var ComServer;
    lBizObj.New;
 
    lMain.FindField('DOCKEY').Value        := -1;
function CreateSQLAccServer() {
    lMain.FindField('DocNo').Value        := '--JE Test--';
   ComServer = new ActiveXObject("SQLAcc.BizApp");
     lMain.FindField('DocDate').Value      := '28 Aug 2017';
  if (!ComServer.IsLogin) {            /* check whether user has logon */
    lMain.FindField('PostDate').Value      := '28 Aug 2017';
     ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
    lMain.FindField('TAXDATE').Value      := '28 Aug 2017';
/* UserName, Password */
    lMain.FindField('Description').Value  := 'Postage';
   }
    lMain.FindField('Cancelled').Value    := 'F';
}
    lMain.FindField('DOCNOSETKEY').Value   := 0;
    lMain.Post;


    //For Tax Inclusive
function AddPayment() {
    lDtl.Append;
  var BizObject, lMainDataSet, lKnockOffDataSet, V;
    lDtl.FindField('DTLKEY').Value      := -1;
 
    lDtl.FindField('DOCKEY').Value      := -1;
  CreateSQLAccServer();
    lDtl.FindField('SEQ').Value          := 1;
    lDtl.FindField('CODE').Value        := '610-1000';
    lDtl.FindField('DESCRIPTION').Value  := 'Item Desc 1';
    lDtl.FindField('TAX').Value          := 'TX';
//    lDtl.FindField('LOCALTAXAMT').AsFloat := 17.32;//For JE you can't override (i.e. system auto calc)
    lDtl.FindField('TAXINCLUSIVE').Value  := 1;
    lDtl.FindField('LocalDR').AsFloat    := 306;//Including GST if TAXINCLUSIVE = 1
    lDtl.FindField('DR').AsFloat          := 306;//if wanted DR <> LocalDR
    lDtl.FindField('CHANGED').Value      := 'F';
    lDtl.Post;


    //For Tax Exclusive
  BizObject = ComServer.BizObjects.Find('AR_PM');
    lDtl.Append;
  lMainDataSet = BizObject.DataSets.Find('MainDataSet');
    lDtl.FindField('DTLKEY').Value      := -1;
  lKnockOffDataSet = BizObject.DataSets.Find('cdsKnockOff');
    lDtl.FindField('DOCKEY').Value      := -1;
  BizObject.New();
    lDtl.FindField('SEQ').Value          := 2;
 
    lDtl.FindField('CODE').Value        := '605-200';
  lMainDataSet.FindField('DocKey').value = -1;
    lDtl.FindField('DESCRIPTION').Value  := 'Item Desc 2';
  lMainDataSet.FindField('DocNo').value = "--OR Test--";
    lDtl.FindField('TAX').Value          := 'TX';
  lMainDataSet.FindField('Code').value = "300-C0001";
    lDtl.FindField('TAXINCLUSIVE').Value := 0;
  lMainDataSet.FindField('DocDate').value = "10/10/2023";
    lDtl.FindField('LocalCR').AsFloat   := 100;
  lMainDataSet.FindField('PostDate').value = "10/10/2023";
    lDtl.FindField('CHANGED').Value      := 'F';
  lMainDataSet.FindField('Description').value = "Payment for Account";
    lDtl.Post;
  lMainDataSet.FindField('PaymentMethod').value = "310-001";
  lMainDataSet.FindField('ChequeNumber').value = "";
  lMainDataSet.FindField('DocAmt').AsFloat = 106.10;
  lMainDataSet.FindField('BankCharge').AsFloat = 0;
  lMainDataSet.FindField('UnappliedAmt').AsFloat = 0;
  lMainDataSet.FindField('Cancelled').value = 'F';
 
  v = ComServer.CreateOleVariantArray(2);
  v.SetItem(0, 'IV'); /*Knock Off DocType*/
  v.SetItem(1, 'IV-00172'); /*Knock Off DocNo*/


    //For No GST
  if (lKnockOffDataSet.Locate('DocType;DocNo', v.AsOleVariant(), false, false)){
    lDtl.Append;
          lKnockOffDataSet.Edit();
    lDtl.FindField('DTLKEY').Value      := -1;
          lKnockOffDataSet.FindField('KOAmt').AsFloat = 106.10;  
    lDtl.FindField('DOCKEY').Value      := -1;
          lKnockOffDataSet.FindField('KnockOff').AsString = 'T';
    lDtl.FindField('SEQ').Value          := 3;
          lKnockOffDataSet.Post(); }
    lDtl.FindField('CODE').Value        := '610-002';
     /* Save document */  
    lDtl.FindField('DESCRIPTION').Value  := 'Item Desc 3';
     BizObject.Save();
    lDtl.FindField('TAX').Value          := '';
     BizObject.Close();
     lDtl.FindField('TAXINCLUSIVE').Value := 0;
     alert("Customer Payment - has been saved.");
     lDtl.FindField('LocalCR').AsFloat    := 200;
}
     lDtl.FindField('CHANGED').Value      := 'F';
     lDtl.Post;


    lBizObj.Save;
function EditPayment(){
    MessageDlg('GL_JE-DocNo : ''--JE Test--'' Posted...', mtInformation, [mbOK],0);
  var BizObject, lMainDataSet, lKnockOffDataSet, V, lDocNo, lDocKey;
   finally
    
    lBizObj.Close;
   CreateSQLAccServer();
   end;
end;
</syntaxhighlight>
|}


  BizObject = ComServer.BizObjects.Find('AR_PM');
  lMainDataSet = BizObject.DataSets.Find('MainDataSet');
  lKnockOffDataSet = BizObject.DataSets.Find('cdsKnockOff');
 
  lDocNo = "--OR Test--"
  lDocKey = BizObject.FindKeyByRef('DocNo', lDocNo);
  BizObject.Params.Find('DocKey').Value = lDocKey;
 
  if (lDocKey != null) {
    BizObject.Open();
    BizObject.Edit();
    lMainDataSet.FindField('Description').value = "Payment for Account-Edited";
    lMainDataSet.FindField('PaymentMethod').value = "310-001";
    lMainDataSet.FindField('ChequeNumber').value = "";
    lMainDataSet.FindField('DocAmt').AsFloat = 200.00;
    lMainDataSet.FindField('BankCharge').AsFloat = 0;
    lMainDataSet.FindField('UnappliedAmt').AsFloat = 0;
    lMainDataSet.FindField('Cancelled').value = 'F';
 
    v = ComServer.CreateOleVariantArray(2);
    v.SetItem(0, 'IV'); /*Knock Off DocType*/
    v.SetItem(1, 'IV-00172'); /*Knock Off DocNo*/
    if (lKnockOffDataSet.Locate('DocType;DocNo', v.AsOleVariant(), false, false)){
          lKnockOffDataSet.Edit();
          lKnockOffDataSet.FindField('KOAmt').AsFloat = 200;  
          lKnockOffDataSet.FindField('KnockOff').AsString = 'T';
          lKnockOffDataSet.Post(); }
    /* Save document */ 
      BizObject.Save();
      BizObject.Close();
      alert("Customer Payment - has been Edited & saved.");
  }
}
function DelPayment(){
  var BizObject, lMainDataSet, lKnockOffDataSet, V, lDocNo, lDocKey;
 
  CreateSQLAccServer();
  BizObject = ComServer.BizObjects.Find('AR_PM');
  lMainDataSet = BizObject.DataSets.Find('MainDataSet');
  lKnockOffDataSet = BizObject.DataSets.Find('cdsKnockOff');
 
  lDocNo = "--OR Test--"
  lDocKey = BizObject.FindKeyByRef('DocNo', lDocNo);
  BizObject.Params.Find('DocKey').Value = lDocKey;
 
  if (lDocKey != null) {
    BizObject.Open();
    BizObject.Delete();
    BizObject.Close();
    alert("Customer Payment - has been Deleted.");
  }
}
</script>
</head>
<body>
<input type="submit" value="Add Payment" name="btnSubmit" onclick="AddPayment()">
<input type="submit" value="Edit Payment" name="btnSubmit" onclick="EditPayment()">
<input type="submit" value="Delete Payment" name="btnSubmit" onclick="DelPayment()">
</body>
</html>
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-GL_PV====
====Customer.IV.RO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! GL_PV Script   
! Customer.IV.RO Report Object Script   
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="javascript">
procedure TfmMain.dxbb_GLPVClick(Sender: TObject);
<html>
var lMain, lDtl, lBizObj, BizApp : Variant;
   <head>
    lTime : TDateTime;
     <title>Customer.IV.RO</title>
begin
     <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   lTime := Now;
     <script type="text/javascript">
  BizApp := CreateOleObject('SQLAcc.BizApp');
var ComServer;
  try
 
     lBizObj := BizApp.BizObjects.Find('GL_PV');
function CreateSQLAccServer() {
     lMain  := lBizObj.DataSets.Find('MainDataSet');
  ComServer = new ActiveXObject("SQLAcc.BizApp");
    lDtl    := lBizObj.DataSets.Find('cdsDocDetail');
  if (!ComServer.IsLogin) {            /* check whether user has logon */
    lBizObj.New;
     ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
    lMain.FindField('DOCKEY').Value          := -1;
/* UserName, Password */
     lMain.FindField('DocNo').AsString        := '--CB PV Test1--';
  }
    lMain.FindField('DocDate').Value          := '18 Aug 2015';
}     
    lMain.FindField('PostDate').Value        := '18 Aug 2015';
    lMain.FindField('TAXDATE').Value          := '18 Aug 2015';
     lMain.FindField('Description').AsString  := 'Compacc System';
    lMain.FindField('PAYMENTMETHOD').AsString := '310-001';
    lMain.FindField('CHEQUENUMBER').AsString  := 'MBB 213245';
    lMain.FindField('DocAmt').AsFloat        := 2019;
    lMain.FindField('Cancelled').AsString    := 'F';
    lMain.FindField('CHANGED').AsString      := 'F';
    lMain.Post;


    lDtl.Append;
function GetData() { 
    lDtl.FindField('DTLKEY').Value         := -1;
  var lMain, lDetail, lRptVar, lDateFrom, lDateTo;
    lDtl.FindField('DOCKEY').Value         := -1;
 
    lDtl.FindField('Code').AsString        := '200-300';
  elem = document.getElementById('txt1');
    lDtl.FindField('DESCRIPTION').AsString := 'Maybank - Asus A555LD-xx313H';
 
    lDtl.FindField('TAX').AsString        := 'TX';
  CreateSQLAccServer();
    lDtl.FindField('TAXAMT').AsFloat      := 114.28;
 
    lDtl.FindField('TAXINCLUSIVE').Value  := 1;
  lDateFrom = new Date("January 1 2015");
    lDtl.FindField('AMOUNT').AsFloat      := 2019;
  lDateTo = new Date("December 31, 2015");
    lDtl.FindField('CHANGED').AsString     := 'F';
 
    lDtl.Post;
  lRptVar = ComServer.RptObjects.Find('Customer.IV.RO');
    lBizObj.Save;
  lRptVar.Params.Find('SelectDate').Value           = true;
    lTime := Now - lTime;
  lRptVar.Params.Find('DateFrom').Value             = lDateFrom.valueOf();
     MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
  lRptVar.Params.Find('DateTo').Value              = lDateTo.valueOf();
              mtInformation, [mbOk], 0);
  lRptVar.Params.Find('AllAgent').Value            = false;
   finally
  lRptVar.Params.Find('AgentData').Value            = "----\nLF"; /*Filter by Agent code ---- & HALIM */
     lBizObj.Close;
  lRptVar.Params.Find('AllArea').Value              = true;
   end;
  lRptVar.Params.Find('AllCompany').Value          = true;
end;
  lRptVar.Params.Find('AllCurrency').Value          = true;
</syntaxhighlight>
  lRptVar.Params.Find('AllDocProject').Value        = true;
|}
  lRptVar.Params.Find('AllCompanyCategory').Value  = true;
 
  lRptVar.Params.Find('AllDocument').Value          = true;
<div style="float: right;">  [[#top|[top]]]</div>
  lRptVar.Params.Find('IncludeCancelled').Value  = false;
 
  lRptVar.Params.Find('PrintDocumentStyle').Value = false;
====Example-AR_Customer====
  lRptVar.Params.Find('AllItemProject').Value     = true;
{| class="mw-collapsible mw-collapsed wikitable"
  lRptVar.Params.Find('AllPaymentMethod').Value  = true;
! AR_Customer Script   
  lRptVar.CalculateReport();
|-
 
  lMain  = lRptVar.DataSets.Find('cdsMain');
  lDetail = lRptVar.DataSets.Find('cdsDocDetail');
  /*alert("Count -" + lRptVar.DataSets.Find('cdsDocDetail').RecordCount);*/
  elem.innerHTML += 'From Main'+'\n';
      
  lMain.First();
  while (!lMain.eof) {
    elem.innerHTML += lMain.FindField('DocKey').AsString + ' ' +
                  lMain.FindField('DocNo').AsString + ' ' + lMain.FindField('DocDate').AsString + ' '+
                      lMain.FindField('CompanyName').AsString + ' ' + lMain.FindField('DocAmt').AsString + '\n';
lMain.Next()
  }
  elem.innerHTML += 'End Main'+'\n\n';
 
  elem.innerHTML += 'From Detail'+'\n';
  lDetail.First();  
   while (!lDetail.eof) {
     elem.innerHTML += lDetail.FindField('Dockey').AsString + ' ' + lDetail.FindField('Account').AsString + ' ' +
                  lDetail.FindField('Description').AsString + ' ' + lDetail.FindField('Amount').AsString + '\n';
lDetail.Next();
  } 
   elem.innerHTML += 'End Detail'+'\n\n';
}
 
    </script>
  </head>
  <body>
    <form>
      <textarea id="txt1" rows="30" cols="116"></textarea>
      <input type="button" value="Calculate" onclick="GetData()">
    </form>
  </body>
</html>
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>
 
====Customer.RO====
{| class="mw-collapsible mw-collapsed wikitable"
! Customer.RO Report Object Script   
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="javascript">
procedure TfmMain.dxbb_CustomerClick(Sender: TObject);
<html>
var lMain, lDtl, lBizObj, lBizApp : Variant;
<head>
    lTime : TDateTime;
<title>Add Customer Invoice</title>
begin
<script language='JScript'>
   lTime := Now;
var ComServer;
   lBizApp := CreateOleObject('SQLAcc.BizApp');
function CreateSQLAccServer() {
   ComServer = new ActiveXObject('SQLAcc.BizApp');
   if (!ComServer.IsLogin) {            /* check whether user has logon */
    ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
/* UserName, Password */
  }
}


   lBizObj := lBizApp.BizObjects.Find('AR_Customer');
function GetCustomerData() {
   lMain   := lBizObj.DataSets.Find('MainDataSet');
  var RptObject, lDataSet, lDataSet2;
   lDtl    := lBizObj.DataSets.Find('cdsBranch');
  edOutput.value = '';
  edOutput2.value = '';
   //Step 1: Create Com Server object
  CreateSQLAccServer();
 
  //Step 2: Find and Create the Report Objects
  RptObject = ComServer.RptObjects.Find('Customer.RO');
    
   //Step 3: Spool parameters
  RptObject.Params.Find('AllAgent').Value = true;
  RptObject.Params.Find('AllArea').Value = true;
  RptObject.Params.Find('AllCompany').Value = true;
  RptObject.Params.Find('AllCompanyCategory').Value = true;
  RptObject.Params.Find('AllCurrency').Value = true;
  RptObject.Params.Find('AllTerms').Value = true;
  RptObject.Params.Find('SelectDate').Value = true;
  RptObject.Params.Find('PrintActive').Value = true;
  RptObject.Params.Find('PrintInactive').Value = false;
  RptObject.Params.Find('PrintPending').Value = false;
  RptObject.Params.Find('PrintProspect').Value = false;
  RptObject.Params.Find('PrintSuspend').Value = false;
  //RptObject.Params.Find('CompanyData').Value = '300-A0003';
 
  //Step 4: Perform Report calculation
  RptObject.CalculateReport();
  lDataSet = RptObject.DataSets.Find('cdsMain');
   lDataSet2 = RptObject.DataSets.Find('cdsBranch');
 
  //alert('Count ' + lDataSet.RecordCount);


   try
   //Step 5 Retrieve the output
    lBizObj.New;
  lDataSet.First;
     lMain.FindField('Code').value       := '300-Test';
  while  (!lDataSet.eof){
    lMain.FindField('CompanyName').value := 'Testing 123';
     edOutput.value = edOutput.value +
                'Code : ' + lDataSet.FindField('Code').AsString + '\n' +
                'Company Name : ' + lDataSet.FindField('CompanyName').AsString +'\n\n';
lDataSet.Next();
  }
  lDataSet2.First();
  while (!lDataSet2.eof){
  edOutput2.value = edOutput2.value +
                  'Code : '+ lDataSet2.FindField('Code').AsString + '\n' +
  'Branch Name : '+ lDataSet2.FindField('BranchName').AsString + '\n' +
                  'Address 1 : '+ lDataSet2.FindField('Address1').AsString + '\n' +
  'Address 2 : '+ lDataSet2.FindField('Address2').AsString + '\n' +
  'Address 3 : '+ lDataSet2.FindField('Address3').AsString + '\n' +
  'Address 4 : '+ lDataSet2.FindField('Address4').AsString + '\n' +
  'Phone 1 : '+ lDataSet2.FindField('Phone1').AsString  +'\n\n';
  lDataSet2.Next();
    }
}


    lDtl.Edit; //For 1st Branch
</script>
    lDtl.FindField('BranchName').AsString := 'BILLING';
</head>
    lDtl.FindField('Address1').AsString   := 'Address1';
<body>
     lDtl.FindField('Address2').AsString  := 'Address2';
   <table>
    lDtl.FindField('Address3').AsString  := 'Address3';
     <tr>
    lDtl.FindField('Address4').AsString  := 'Address4';
      <th>Main Table</th>
     lDtl.FindField('Attention').AsString  := 'Attention';
      <th>Branch Branch</th>
     lDtl.FindField('Phone1').AsString    := 'Phone1';
     </tr>
    lDtl.FindField('Fax1').AsString       := 'Fax1';
     <tr>
    lDtl.FindField('Email').AsString      := 'EmailAddress';
       <td>
    lDtl.Post;
        <TEXTAREA rows=15 cols=75 name="edOutput"></TEXTAREA>
 
  </td>
    lDtl.Append; //For 2nd Branch
      <td>
     lDtl.FindField('BranchName').AsString := 'Branch1';
        <TEXTAREA rows=15 cols=75 name="edOutput2"></TEXTAREA>
    lDtl.FindField('Address1').AsString   := 'DAddress1';
  </td>
    lDtl.FindField('Address2').AsString   := 'DAddress2';
     </tr>
    lDtl.FindField('Address3').AsString  := 'DAddress3';
   </table>
    lDtl.FindField('Address4').AsString  := 'DAddress4';
    lDtl.FindField('Attention').AsString  := 'DAttention';
   <table width="83%">
    lDtl.FindField('Phone1').AsString    := 'DPhone1';
<tr>
    lDtl.FindField('Fax1').AsString      := 'DFax1';
  <td align="center">
    lDtl.FindField('Email').AsString      := 'DEmailAddress';
<input type='submit' value='Sync Data' name='btnSubmit' onclick='GetCustomerData()'>
    lDtl.Post;
  </td>
    lBizObj.Save;
</tr>
 
   </table>
    lTime := Now - lTime;
</body>
    MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
</html>
              mtInformation, [mbOk], 0);
   finally
    lBizObj.Close;
  end;
end;
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-AR_PM====
====Get Next IV Number====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! AR_PM Script   
! Get Next IV Number Script   
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="javascript">
procedure TfmMain.dxbb_ARPMClick(Sender: TObject);
<html>
var lMain, lKO, lBizApp, lBizObj, V : Variant;
<head>
begin
<title>Add Cash Sales</title>
  lBizApp := CreateOleObject('SQLAcc.BizApp');
<script language="JScript">
  try
var ComServer, lDataSet;
    lBizObj := lBizApp.BizObjects.Find('AR_PM');
    lMain  := lBizObj.DataSets.Find('MainDataSet');
    lKO    := lBizObj.DataSets.Find('cdsKnockOff');


    lBizObj.New;
function CreateSQLAccServer() {
    lMain.FindField('DOCKEY').Value          := -1;
  ComServer = new ActiveXObject('SQLAcc.BizApp');
    lMain.FindField('DocNo').AsString        := '--PM Test--'; //Payment Document Number
  if (!ComServer.IsLogin) {            /* check whether user has logon */
    lMain.FindField('CODE').AsString          := '300-A0001';
     ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
    lMain.FindField('DocDate').Value          := '28 Aug 2016';
/* UserName, Password */
    lMain.FindField('PostDate').Value        := '28 Aug 2016';
  }
    lMain.FindField('Description').AsString  := 'Payment for A/c';
}
     lMain.FindField('PaymentMethod').AsString := '320-000';
    lMain.FindField('DocAmt').AsFloat        := 1060;
    lMain.FindField('Cancelled').AsString    := 'F';
    lMain.FindField('CHANGED').AsString      := 'F';


    V := lBizApp.CreateOleVariantArray(2);
function zeroPad(num, places) {
    V.SetItem(0, 'IV'); //Document Type is either is IV or DN for Sales & PI or SD for Purchase
  var zero = places - num.toString().length + 1;
    V.SetItem(1, '--IV Test--'); //Invoice Document Number
  return Array(+(zero > 0 && zero)).join("0") + num;
  /*zeroPad(5, 2); // "05"*/
}


    if lKO.Locate('DocType;DocNo', V.AsOleVariant, False, False) then
function GetData() {
      begin
  var lSQL;
        lKO.Edit;
  lSQL = "SELECT A.*, B.NEXTNUMBER FROM SY_DOCNO A ";
        lKO.FindField('KOAmt').ASFloat    := 500;
  lSQL = lSQL + "INNER JOIN SY_DOCNO_DTL B ON (A.DOCKEY=B.PARENTKEY) ";
        lKO.FindField('KnockOff').AsString := 'T';
  lSQL = lSQL + "WHERE A.DOCTYPE='IV' ";
        lKO.Post;
  lSQL = lSQL + "AND A.DESCRIPTION='Customer Invoice' ";
      end;
  lSQL = lSQL + "AND A.STATESET=1 ";
  lDataSet = ComServer.DBManager.NewDataSet(lSQL);
}


    lBizObj.Save;
function ShowNextNo() {
    MessageDlg('AR_PM-DocNo : ''--PM Test--'' Posted...', mtInformation, [mbOK],0);
  var Desc, Fmt, NextNo, lResult, lPad;
   finally
    
    lBizObj.Close;
  CreateSQLAccServer();
   end;
   GetData();
end;
</syntaxhighlight>
|}


<div style="float: right;">  [[#top|[top]]]</div>
  if (lDataSet.RecordCount > 0) { 
 
    lDataSet.First;
====Example-AR_PM-Edit====
    Desc = lDataSet.FindField("Description").AsString;
{| class="mw-collapsible mw-collapsed wikitable"
Fmt  = lDataSet.FindField("Format").AsString;
! AR_PM Script   
NextNo = lDataSet.FindField("NEXTNUMBER").Value;
    alert(Desc);
alert(Fmt);
alert(NextNo);
lPad = Fmt.substr(5, 1);
lPad = zeroPad(NextNo, lPad)
Desc = Fmt.substr(0, 3);
alert(Desc + lPad);
  }
}
</script>
</head>
<body>
<input type="submit" value="Show Next No" name="btnSubmit" onclick="ShowNextNo()">
</body>
</html>
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>
====Customer & Supplier Contra====
{| class="mw-collapsible mw-collapsed wikitable"
! Customer & Supplier Contra Script   
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="javascript">
procedure TfmMain.dxbb_ARPMClick(Sender: TObject);
<html>
var lMain, lKO, lBizApp, lBizObj, V : Variant;
<head>
begin
<title>Add Customer Invoice</title>
   lBizApp := CreateOleObject('SQLAcc.BizApp');
<script language="JScript">
   try
var ComServer;
    lBizObj := lBizApp.BizObjects.Find('AR_PM');
    lMain   := lBizObj.DataSets.Find('MainDataSet');
function CreateSQLAccServer() {
    lKO     := lBizObj.DataSets.Find('cdsKnockOff');
  ComServer = new ActiveXObject('SQLAcc.BizApp');
  if (!ComServer.IsLogin) {            /* check whether user has logon */
    ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
/* UserName, Password */
  }
}
function PostARCT() {
  var BizObject, lMain, lKO, V;
   CreateSQLAccServer();
   BizObject = ComServer.BizObjects.Find('AR_CT');
  lMain = BizObject.DataSets.Find('MainDataSet');
  lKO = BizObject.DataSets.Find('cdsKnockOff');
  BizObject.New();
  lMain.FindField('DocKey').value = -1;
  lMain.FindField('DocNo').value = "--CT Test--";
  lMain.FindField('DocDate').value = "01/10/2020";
  lMain.FindField('PostDate').value = "01/10/2020";
  lMain.FindField('Code').value = "300-A0002";
  lMain.FindField('Description').value = "Contra";
  lMain.FindField('DocAmt').value = "100.00";
  //lMain.FindField('UnappliedAmt').value = "0";


    lDocKey := lBizObj.FindKeyByRef('DocNo', '--PM Test--');
  v = ComServer.CreateOleVariantArray(2);
    lBizObj.Params.Find('DocKey').Value := VarToStr(lDocKey);
  v.SetItem(0, 'IV'); /*Knock Off DocType*/
  v.SetItem(1, 'IV-00021'); /*Knock Off DocNo*/
 
  if (lKO.Locate('DocType;DocNo', v.AsOleVariant(), false, false)){
          lKO.Edit();
          lKO.FindField('DocAmt').value = "100";  
          lKO.FindField('KnockOff').AsString = 'T';
          lKO.Post(); }


    If not VarIsNull(lDocKey) Then begin
   /* Save document */ 
      lBizObj.Open;
    BizObject.Save();
      lBizObj.Edit;
    BizObject.Close();
      lMain.FindField('DOCKEY').Value          := -1;
    alert('Customer Contra - has been saved.');
      lMain.FindField('DocDate').Value          := '28 Aug 2016';
}
      lMain.FindField('PostDate').Value        := '28 Aug 2016';
      lMain.FindField('Description').AsString   := 'Payment for A/c';
      lMain.FindField('PaymentMethod').AsString := '310-000';
      lMain.FindField('DocAmt').AsFloat        := 800.28;
      lMain.FindField('UnappliedAmt').AsFloat  := 100.28;
      lMain.FindField('Cancelled').AsString    := 'F';
      lMain.FindField('CHANGED').AsString      := 'F';


      V := lBizApp.CreateOleVariantArray(2);
function PostAPST() {
      V.SetItem(0, 'IV'); //Document Type is either is IV or DN for Sales & PI or SD for Purchase
  var BizObject, lMain, lKO, V, lDocNo, lDocKey;
      V.SetItem(1, '--IV Test--'); //Document Number
  CreateSQLAccServer();
  BizObject = ComServer.BizObjects.Find('AP_ST');
  lMain = BizObject.DataSets.Find('MainDataSet');
  lKO = BizObject.DataSets.Find('cdsKnockOff');
 
  lDocNo = "--CT Test--"
  lDocKey = BizObject.FindKeyByRef("DocNo", lDocNo)
  BizObject.Params.Find("DocKey").Value = lDocKey 
 
  if (lDocKey != null) {
    BizObject.Open();
BizObject.Edit();
lMain.FindField('Code').value = "400-C0001";
lMain.FindField('DocAmt').value = "100.00";
  //lMain.FindField('UnappliedAmt').value = "0";


      if lKO.Locate('DocType;DocNo', V.AsOleVariant, False, False) then
  v = ComServer.CreateOleVariantArray(2);
        begin
  v.SetItem(0, 'PI'); /*Knock Off DocType*/
          lKO.Edit;
  v.SetItem(1, 'PI-00001'); /*Knock Off DocNo*/
          lKO.FindField('KOAmt').AsFloat    := 700.28; // IV Knock Off/Offset Amount
          lKO.FindField('KnockOff').AsString := 'T';
          lKO.Post;
        end;


      lBizObj.Save;
    if (lKO.Locate('DocType;DocNo', v.AsOleVariant(), false, false)){
      MessageDlg('AR_PM-DocNo : ''--PM Test--'' Updated...', mtInformation, [mbOK],0);
          lKO.Edit();
     end;
          lKO.FindField('DocAmt').value = "100";  
  finally
          lKO.FindField('KnockOff').AsString = 'T';
     lBizObj.Close;
          lKO.Post(); }
   end;
 
end;
  /* Save document */ 
     BizObject.Save();
    BizObject.Close();
     alert('Supplier Contra - has been Updated.');
   }
}
</script>
</head>
<body>
<button onclick="javascript:PostARCT();">PostARCT</button>&nbsp;&nbsp;
<button onclick="javascript:PostAPST();">PostAPST</button>&nbsp;&nbsp;
</body>
</html>
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-ST_Item====
====Add Stock Item====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! ST_Item Script   
! Add ST_Item Script   
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="javascript">
procedure TfmMain.dxbb_ST_ItemClick(Sender: TObject);
<html>
var lMain, lDtl, lBizObj, lBizApp : Variant;
<head>
    lTime : TDateTime;
<title>Add Stock Item</title>
begin
<script language="JScript">
  lTime := Now;
var ComServer;
  lBizApp := CreateOleObject('SQLAcc.BizApp');
  lBizObj := lBizApp.BizObjects.Find('ST_ITEM');
  lMain  := lBizObj.DataSets.Find('MainDataSet');
  lDtl    := lBizObj.DataSets.Find('cdsUOM');


   try
function CreateSQLAccServer() {
    lBizObj.New;
   ComServer = new ActiveXObject('SQLAcc.BizApp');
     lMain.FindField('Code').AsString        := 'Test-1';
  if (!ComServer.IsLogin) {            /* check whether user has logon */
    lMain.FindField('Description').AsString := 'Testing - Description';
     ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
/* UserName, Password */
  }
}


    lDtl.Edit; //For 1st UOM
function InsertData() {
    lDtl.FindField('UOM').AsString    := 'PCS';
  var BizObject, lMain, lDetail;
    lDtl.FindField('Rate').AsFloat    := 1;
 
    lDtl.FindField('RefCost').AsFloat  := 10.20;
  CreateSQLAccServer();
    lDtl.FindField('RefPrice').AsFloat := 25.00;
    lDtl.Post;


     lDtl.Append; //For 2nd UOM
  /*Step 2: Find and Create the Biz Objects*/
    lDtl.FindField('UOM').AsString     := 'CTN';
  BizObject = ComServer.BizObjects.Find('ST_ITEM') ;
    lDtl.FindField('Rate').AsFloat     := 12;
 
    lDtl.FindField('RefCost').AsFloat := 102.00;
  /*Step 3: Set Dataset*/
    lDtl.FindField('RefPrice').AsFloat := 240.00;
  lMain  = BizObject.DataSets.Find('MainDataSet');  /*lMain contains master data*/
    lDtl.Post;
  lUOM = BizObject.DataSets.Find('cdsUOM'); /*lDetail contains detail data */ 
    lBizObj.Save;
 
  /*Begin Looping yr data*/
  /*Step 4 : Insert Data - Master*/
  BizObject.New();
  lMain.FindField('Code').AsString        = "Code JScript";
  lMain.FindField('DESCRIPTION').AsString = "Post from JScript"
  lMain.FindField('STOCKGROUP').AsString    = "DEFAULT"; /*Optional*/
  lMain.FindField('STOCKCONTROL').AsString    = "T"; /*Optional*/
  lMain.FindField('ISACTIVE').AsString    = "T"; /*Optional*/
      
  /*Step 5: Insert Data - UOM*/
  lUOM.Edit(); /*For 1St UOM*/
  lUOM.FindField('UOM').AsString = "PCS";
  lUOM.FindField('Rate').AsFloat = 1;
  lUOM.FindField('RefCost').AsFloat = 10.2;
  lUOM.FindField('RefPrice').AsFloat = 25;
  lUOM.Post();
 
  lUOM.Append(); /*For 2nd UOM*/
  lUOM.FindField('UOM').AsString = "CTN";
  lUOM.FindField('Rate').AsFloat = 12;
  lUOM.FindField('RefCost').AsFloat = 102;
  lUOM.FindField('RefPrice').AsFloat = 240;
  lUOM.Post();


    lTime := Now - lTime;
  /*Step 6: Save*/
     MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
  BizObject.Save();
              mtInformation, [mbOk], 0);
  BizObject.Close();
  finally
     alert('Item has been saved.');
    lBizObj.Close;
}
  end;
</script>
end;
</head>
<body>
<input type="submit" value="SYNC" name="btnSubmit" onclick="InsertData()">
</body>
</html>
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-ST_Item-Edit====
====Get Company Profile====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! ST_Item Script   
! Get Company Profile Script   
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="javascript">
procedure TfmMain.dxbb_ST_ItemClick(Sender: TObject);
<html>
var lMain, lDtl, lBizObj, lBizApp, lDocKey, V : Variant;
<head>
begin
<title>Add Cash Sales</title>
  lBizApp := CreateOleObject('SQLAcc.BizApp');
<script language="JScript">
  lBizObj := lBizApp.BizObjects.Find('ST_ITEM');
var ComServer, lDataSet;
  lMain  := lBizObj.DataSets.Find('MainDataSet');
  lDtl    := lBizObj.DataSets.Find('cdsUOM');


   lDocKey := lBizObj.FindKeyByRef('Code', '--Stock Item Test--');
function CreateSQLAccServer() {
   lBizObj.Params.Find('DocKey').Value := VarToStr(lDocKey);
   ComServer = new ActiveXObject('SQLAcc.BizApp');
   try
   if (!ComServer.IsLogin) {            /* check whether user has logon */
    ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
/* UserName, Password */
   }
}


    If not VarIsNull(lDocKey) Then begin
function zeroPad(num, places) {
      lBizObj.Open;
  var zero = places - num.toString().length + 1;
      lBizObj.Edit;
  return Array(+(zero > 0 && zero)).join("0") + num;
      lMain.FindField('Description').value := 'Testing - Description';
  /*zeroPad(5, 2); // "05"*/
}


      V := lBizApp.CreateOleVariantArray(2);
function GetData() {
      V.SetItem(0, 'CTN'); //UOM
  var lSQL;
      V.SetItem(1, '12');  //Rate
  lSQL = "SELECT COMPANYNAME, REMARK, BRN, BRN2, GSTNO, ";
  lSQL = lSQL + "SALESTAXNO, SERVICETAXNO, ";
  lSQL = lSQL + "ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS4 FROM SY_PROFILE ";
  lDataSet = ComServer.DBManager.NewDataSet(lSQL);   
}


      if lDtl.Locate('UOM;Rate', V.AsOleVariant, False, False) then
function ShowCoProfile() {
        begin
  var CoName, Rmk, BRN;
          lDtl.Edit;
 
          lDtl.FindField('RefCost').AsFloat := 10.20;
  CreateSQLAccServer();  
          lDtl.FindField('RefPrice').AsFloat := 25.00;
  GetData();
          lDtl.Post;
        end;
      lBizObj.Save;


      MessageDlg('ST_Item-ItemCode : ''--Stock Item Test--'' Updated...', mtInformation, [mbOK],0);
  if (lDataSet.RecordCount > 0) { 
    end;
    lDataSet.First;
  finally
    CoName = lDataSet.FindField("COMPANYNAME").AsString;
     lBizObj.Close;
Rmk  = lDataSet.FindField("REMARK").AsString;
  end;
BRN = lDataSet.FindField("BRN").Value;
end;
     alert(CoName);
alert(Rmk);
alert(BRN);
  }
}
</script>
</head>
<body>
<input type="submit" value="Show Co Profile" name="btnSubmit" onclick="ShowCoProfile()">
</body>
</html>
</syntaxhighlight>
</syntaxhighlight>
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>
<br />


====Example-SL_IV====
===Delphi===
The below example is assuming after you had check the login status.
====GL_JE====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! SL_IV Script   
! GL_JE Script   
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="delphi">
procedure TfmMain.dxbb_SL_IVClick(Sender: TObject);
procedure TfmMain.dxbb_GL_JEClick(Sender: TObject);
var lMain, lDtl, lSN, lBizObj, lBizApp : Variant;
var BizApp, lMain, lDtl, lBizObj, lDocKey : Variant;
     lTime : TDateTime;
     i : integer;
begin
begin
   lTime := Now;
   BizApp := CreateOleObject('SQLAcc.BizApp');
  lBizApp := CreateOleObject('SQLAcc.BizApp');
  lBizObj := lBizApp.BizObjects.Find('SL_IV');
  lMain  := lBizObj.DataSets.Find('MainDataSet');
  lDtl    := lBizObj.DataSets.Find('cdsDocDetail');
  lSN    := lBizObj.DataSets.Find('cdsSerialNumber');
 
   try
   try
    lBizObj := BizApp.BizObjects.Find('GL_JE');
    lMain  := lBizObj.DataSets.Find('MainDataSet');
    lDtl    := lBizObj.DataSets.Find('cdsDocDetail');
     lBizObj.New;
     lBizObj.New;
     lMain.FindField('DOCKEY').Value         := -1;
     lMain.FindField('DOCKEY').Value       := -1;
     lMain.FindField('DocNo').AsString      := '--IV Test--';
     lMain.FindField('DocNo').Value        := '--JE Test--';
     lMain.FindField('CODE').AsString        := '300-A0001';
     lMain.FindField('DocDate').Value      := '28 Aug 2017';
     lMain.FindField('DocDate').Value       := '28 Aug 2020';
     lMain.FindField('PostDate').Value     := '28 Aug 2017';
     lMain.FindField('PostDate').Value      := '28 Aug 2020';
     lMain.FindField('TAXDATE').Value      := '28 Aug 2017';
     lMain.FindField('TAXDATE').Value       := '28 Aug 2020';
     lMain.FindField('Description').Value   := 'Postage';
     lMain.FindField('Description').AsString := 'Sales';
     lMain.FindField('Cancelled').Value    := 'F';
     lMain.FindField('Cancelled').AsString   := 'F';
     lMain.FindField('DOCNOSETKEY').Value   := 0;
     lMain.Post;
     lMain.Post;


     lDtl.Append; // For Tax Inclusive = True with override Tax Amount
     //For Tax Inclusive
     lDtl.FindField('DTLKEY').Value         := -1;
    lDtl.Append;
     lDtl.FindField('DOCKEY').Value         := -1;
     lDtl.FindField('DTLKEY').Value       := -1;
     lDtl.FindField('SEQ').Value           := 1;
     lDtl.FindField('DOCKEY').Value       := -1;
     lDtl.FindField('ItemCode').AsString    := 'ITEM A';
     lDtl.FindField('SEQ').Value         := 1;
     lDtl.FindField('ACCOUNT').AsString    := '500-000'; //GL Sales Account
     lDtl.FindField('CODE').Value        := '610-1000';
     lDtl.FindField('DESCRIPTION').AsString := 'Sales Item A';
     lDtl.FindField('DESCRIPTION').Value  := 'Item Desc 1';
    lDtl.FindField('QTY').AsFloat         := 1;
     lDtl.FindField('TAX').Value          := 'TX';
    lDtl.FindField('TAX').AsString        := 'SV';
//    lDtl.FindField('LOCALTAXAMT').AsFloat := 17.32;//For JE you can't override (i.e. system auto calc)
     lDtl.FindField('TAXINCLUSIVE').Value   := 0;
     lDtl.FindField('TAXINCLUSIVE').Value := 1;
     lDtl.FindField('UNITPRICE').AsFloat   := 435;//Including GST UnitPrice
     lDtl.FindField('LocalDR').AsFloat     := 306;//Including GST if TAXINCLUSIVE = 1
     lDtl.FindField('AMOUNT').AsFloat       := 410.37; //Must Excluding GST (Qty * UnitPrice) // Less 0.01
     lDtl.FindField('DR').AsFloat         := 306;//if wanted DR <> LocalDR
     lDtl.FindField('TAXAMT').AsFloat       := 24.63; //Extra 0.01
     lDtl.FindField('CHANGED').Value       := 'F';
 
    lDtl.DisableControls; //For Tax Inclusive Only where TaxAmt is not as Calc
    try
      lDtl.FindField('TAXINCLUSIVE').Value := 1;
    finally
      lDtl.EnableControls;
    end;
     lDtl.Post;
     lDtl.Post;


     lDtl.Append; // For Tax Inclusive = False with override Tax Amount
    //For Tax Exclusive
     lDtl.FindField('DTLKEY').Value         := -1;
     lDtl.Append;
     lDtl.FindField('DOCKEY').Value         := -1;
     lDtl.FindField('DTLKEY').Value       := -1;
     lDtl.FindField('SEQ').Value           := 2;
     lDtl.FindField('DOCKEY').Value       := -1;
     lDtl.FindField('ItemCode').AsString    := 'ITEM B';
     lDtl.FindField('SEQ').Value         := 2;
    lDtl.FindField('ACCOUNT').AsString    := '500-000';
     lDtl.FindField('CODE').Value        := '605-200';
     lDtl.FindField('DESCRIPTION').AsString := 'Sales Item B';
     lDtl.FindField('DESCRIPTION').Value  := 'Item Desc 2';
     lDtl.FindField('QTY').AsFloat         := 1;
     lDtl.FindField('TAX').Value         := 'TX';
    lDtl.FindField('TAX').AsString        := 'SV';
     lDtl.FindField('TAXINCLUSIVE').Value := 0;
     lDtl.FindField('TAXINCLUSIVE').Value   := 0;
     lDtl.FindField('LocalCR').AsFloat    := 100;
     lDtl.FindField('UNITPRICE').AsFloat    := 94.43;
     lDtl.FindField('CHANGED').Value      := 'F';
     lDtl.FindField('AMOUNT').AsFloat      := 94.43;
    lDtl.FindField('TAXAMT').AsFloat      := 5.66; //Less 0.01
     lDtl.Post;
     lDtl.Post;


     lDtl.Append; // For Serial Number
    //For No GST
     lDtl.FindField('DTLKEY').Value         := -1;
     lDtl.Append;
     lDtl.FindField('DOCKEY').Value         := -1;
     lDtl.FindField('DTLKEY').Value       := -1;
     lDtl.FindField('SEQ').Value           := 3;
     lDtl.FindField('DOCKEY').Value       := -1;
     lDtl.FindField('ItemCode').AsString    := 'SN1';
     lDtl.FindField('SEQ').Value         := 3;
    lDtl.FindField('ACCOUNT').AsString    := '500-000';
     lDtl.FindField('CODE').Value        := '610-002';
     lDtl.FindField('DESCRIPTION').AsString := 'Sales Serial Number Item';
     lDtl.FindField('DESCRIPTION').Value  := 'Item Desc 3';
 
     lDtl.FindField('TAX').Value          := '';
    lSN.Append;
     lDtl.FindField('TAXINCLUSIVE').Value := 0;
    lSN.FindField('SERIALNUMBER').AsString  := 'SN-00001';
     lDtl.FindField('LocalCR').AsFloat     := 200;
    lSN.Post;
     lDtl.FindField('CHANGED').Value      := 'F';
 
    lSN.Append;
    lSN.FindField('SERIALNUMBER').AsString  := 'SN-00002';
    lSN.Post;
 
    lDtl.FindField('QTY').AsFloat        := 2;
     lDtl.FindField('TAX').AsString      := 'SR';
     lDtl.FindField('TAXINCLUSIVE').Value := 0;
     lDtl.FindField('UNITPRICE').AsFloat := 94.43;
     lDtl.FindField('TAXAMT').AsFloat    := 11.33;
     lDtl.Post;
     lDtl.Post;


     lBizObj.Save;
     lBizObj.Save;
 
     MessageDlg('GL_JE-DocNo : ''--JE Test--'' Posted...', mtInformation, [mbOK],0);
    lTime := Now - lTime;
     MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
              mtInformation, [mbOk], 0);
   finally
   finally
     lBizObj.Close;
     lBizObj.Close;
    lMain := null;
    lDtl := null;
    lSN := null;
    lBizObj := null;
    lBizApp := null;
   end;
   end;
end;
end;
Line 9,662: Line 10,913:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Customer.IV.RO====
====GL_PV====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Customer.IV.RO Report Object Script   
! GL_PV Script   
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="delphi">
procedure TfmMain.dxbb_RptObjClick(Sender: TObject);
procedure TfmMain.dxbb_GLPVClick(Sender: TObject);
var lBizApp, lRptVar : Variant;
var lMain, lDtl, lBizObj, BizApp : Variant;
     lTime : TDateTime;
     lTime : TDateTime;
    cdsMain, cdsDtl : TClientDataset;
begin
begin
   lTime := Now;
   lTime := Now;
   cdsMain := TClientDataset.Create(nil);
   BizApp := CreateOleObject('SQLAcc.BizApp');
  cdsDtl  := TClientDataset.Create(nil);
  lBizApp := CreateOleObject('SQLAcc.BizApp');
   try
   try
     lRptVar := null;
     lBizObj := BizApp.BizObjects.Find('GL_PV');
    lRptVar := lBizApp.RptObjects.Find('Customer.IV.RO');
     lMain  := lBizObj.DataSets.Find('MainDataSet');
     lRptVar.Params.Find('SelectDate').AsBoolean          := True;
     lDtl    := lBizObj.DataSets.Find('cdsDocDetail');
     lRptVar.Params.Find('DateFrom').AsDate                := '01/01/2015';
     lBizObj.New;
     lRptVar.Params.Find('DateTo').AsDate                  := '31/12/2015';
     lMain.FindField('DOCKEY').Value          := -1;
     lRptVar.Params.Find('AllAgent').AsBoolean            := False;
     lMain.FindField('DocNo').AsString        := '--CB PV Test1--';
     lRptVar.Params.Find('AgentData').AsBlob              := '----'#13#10'HALIM'; //Filter by Agent code ---- & HALIM
     lMain.FindField('DocDate').Value          := '18 Aug 2015';
     lRptVar.Params.Find('AllArea').AsBoolean              := True;
     lMain.FindField('PostDate').Value        := '18 Aug 2015';
//    lRptVar.Params.Find('AreaData').AsBlob                := ; //Not use if AllArea is True
     lMain.FindField('TAXDATE').Value         := '18 Aug 2015';
     lRptVar.Params.Find('AllCompany').AsBoolean          := True;
     lMain.FindField('Description').AsString  := 'Compacc System';
//    lRptVar.Params.Find('CompanyData').AsBlob            := ; //Not use if AllCompany is True
     lMain.FindField('PAYMENTMETHOD').AsString := '310-001';
     lRptVar.Params.Find('AllCurrency').AsBoolean         := True;
     lMain.FindField('CHEQUENUMBER').AsString  := 'MBB 213245';
//    lRptVar.Params.Find('CurrencyData').AsBlob            := ; //Not use if AllCurrenty is True
     lMain.FindField('DocAmt').AsFloat        := 2019;
     lRptVar.Params.Find('AllDocProject').AsBoolean        := True;
     lMain.FindField('Cancelled').AsString    := 'F';
//    lRptVar.Params.Find('DocProjectData').AsBlob          := ; //Not use if AllDocProject is True
     lMain.FindField('CHANGED').AsString      := 'F';
     lRptVar.Params.Find('AllCompanyCategory').AsBoolean  := True;
     lMain.Post;
//    lRptVar.Params.Find('CompanyCategoryData').AsBlob    := ; //Not use if AllCompanyCategory is True
     lRptVar.Params.Find('AllDocument').AsBoolean          := True;
//    lRptVar.Params.Find('DocumentData').AsBlob            := ; //Not use if AllDocument is True
     lRptVar.Params.Find('IncludeCancelled').AsBoolean  := True;
     lRptVar.Params.Find('PrintDocumentStyle').AsBoolean := False;
     lRptVar.Params.Find('AllItemProject').AsBoolean    := True;
    lRptVar.Params.Find('AllPaymentMethod').AsBoolean  := True;
     lRptVar.CalculateReport;


     cdsMain.XMLData := lRptVar.DataSets.Find('cdsMain').XMLData;     //Master Data
     lDtl.Append;
     cdsDtl.XMLData  := lRptVar.DataSets.Find('cdsDocDetail').XMLData; //Detail Data - To link Master Data use Dockey field
    lDtl.FindField('DTLKEY').Value        := -1;
 
    lDtl.FindField('DOCKEY').Value        := -1;
     cdsMain.SaveToFile('C:\Temp\_ListM.xml'); //Export To XML file
    lDtl.FindField('Code').AsString        := '200-300';
     cdsDtl.SaveToFile('C:\Temp\_ListD.xml'); //Export To XML file
     lDtl.FindField('DESCRIPTION').AsString := 'Maybank - Asus A555LD-xx313H';
 
    lDtl.FindField('TAX').AsString        := 'TX';
     lTime := Now - lTime;
     lDtl.FindField('TAXAMT').AsFloat      := 114.28;
    lDtl.FindField('TAXINCLUSIVE').Value  := 1;
     lDtl.FindField('AMOUNT').AsFloat      := 2019;
    lDtl.FindField('CHANGED').AsString    := 'F';
    lDtl.Post;
    lBizObj.Save;
     lTime := Now - lTime;
     MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
     MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
               mtInformation, [mbOk], 0);
               mtInformation, [mbOk], 0);
   finally
   finally
     lRptVar := null;
     lBizObj.Close;
    cdsMain.Free;
    cdsDtl.Free;
   end;
   end;
end;
end;
Line 9,723: Line 10,967:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Stock.Item.RO====
====AR_Customer====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Stock.Item.RO Report Object Script   
! AR_Customer Script   
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="delphi">
procedure TfmMain.dxbb_ST_ITEM_ROClick(Sender: TObject);
procedure TfmMain.dxbb_CustomerClick(Sender: TObject);
var lBizApp, lRptVar : Variant;
var lMain, lDtl, lBizObj, lBizApp : Variant;
     lTime : TDateTime;
     lTime : TDateTime;
    cdsMain, cdsDtl, cdsCat : TClientDataset;
    lSQL : string;
begin
begin
   lTime   := Now;
   lTime := Now;
  cdsMain  := TClientDataset.Create(nil);
  cdsDtl  := TClientDataset.Create(nil);
  cdsCat  := TClientDataset.Create(nil);
 
   lBizApp := CreateOleObject('SQLAcc.BizApp');
   lBizApp := CreateOleObject('SQLAcc.BizApp');


   lSQL := 'SELECT * FROM ST_ITEM_CATEGORY ' +
   lBizObj := lBizApp.BizObjects.Find('AR_Customer');
          'WHERE Category IN (''B-MOTOLORA'',''B-MAXIS'')';
  lMain  := lBizObj.DataSets.Find('MainDataSet');
   cdsCat.Data := lBizApp.DBManager.Execute(lSQL); //For filtering Category only
   lDtl    := lBizObj.DataSets.Find('cdsBranch');


   try
   try
     lRptVar := null;
     lBizObj.New;
    lRptVar := lBizApp.RptObjects.Find('Stock.Item.RO');
     lMain.FindField('Code').value       := '300-Test';
     lRptVar.Params.Find('AllItem').AsBoolean              := True;
     lMain.FindField('CompanyName').value := 'Testing 123';
    lRptVar.Params.Find('AllStockGroup').AsBoolean        := True;
    lRptVar.Params.Find('AllCustomerPriceTag').AsBoolean  := True;
    lRptVar.Params.Find('AllSupplierPriceTag').AsBoolean  := True;
//    lRptVar.Params.Find('CategoryData').AsBlob            := ; //Not use
//    lRptVar.Params.Find('CategoryTpl').AsBlob            := ; //Not use
//    lRptVar.Params.Find('CustomerPriceTagData').AsBlob    := ; //Not use if AllCustomerPriceTag is True
//    lRptVar.Params.Find('SupplierPriceTagData').AsBlob    := ; //Not use if AllSupplierPriceTag is True
//    lRptVar.Params.Find('DateFrom').AsDate                := '01/01/2015'; //Not use if SelectDate is False
//    lRptVar.Params.Find('DateTo').AsDate                  := '31/12/2015';
    lRptVar.Params.Find('HasAltStockItem').AsBoolean      := False;
    lRptVar.Params.Find('HasBarcode').AsBoolean          := False;
    lRptVar.Params.Find('HasBOM').AsBoolean              := False;
    lRptVar.Params.Find('HasCategory').AsBoolean          := False;
    lRptVar.Params.Find('HasCustomerItem').AsBoolean      := False;
    lRptVar.Params.Find('HasOpeningBalance').AsBoolean    := False;
    lRptVar.Params.Find('HasPurchasePrice').AsBoolean    := False;
    lRptVar.Params.Find('HasSellingPrice').AsBoolean      := False;
    lRptVar.Params.Find('HasSupplierItem').AsBoolean      := False;
//    lRptVar.Params.Find('ItemData').AsBlob                := 'ANT 1.0'#13#10'COVER'; //Filter by Item code ANT 1.0 & COVER
//    lRptVar.Params.Find('ItemCategoryData').AsBlob       := cdsCat.XMLData; //Not use if SelectCategory is False
    lRptVar.Params.Find('PrintActive').AsBoolean          := True;
    lRptVar.Params.Find('PrintInActive').AsBoolean        := True;
    lRptVar.Params.Find('PrintNonStockControl').AsBoolean := True;
     lRptVar.Params.Find('PrintStockControl').AsBoolean    := True;
    lRptVar.Params.Find('SelectCategory').AsBoolean      := False;
    lRptVar.Params.Find('SelectDate').AsBoolean          := False;
    lRptVar.Params.Find('SortBy').AsString                  := 'Code';
//    lRptVar.Params.Find('StockGroupData').AsBlob        := ; //Not use if AllStockGroup is True
    lRptVar.CalculateReport;


     cdsMain.XMLData := lRptVar.DataSets.Find('cdsMain').XMLData; //Master Data
     lDtl.Edit; //For 1st Branch
     cdsDtl.XMLData := lRptVar.DataSets.Find('cdsUOM').XMLData; //Detail Data - To link Master Data use Code field
    lDtl.FindField('BranchName').AsString := 'BILLING';
    lDtl.FindField('Address1').AsString  := 'Address1';
    lDtl.FindField('Address2').AsString  := 'Address2';
    lDtl.FindField('Address3').AsString  := 'Address3';
    lDtl.FindField('Address4').AsString  := 'Address4';
     lDtl.FindField('Attention').AsString := 'Attention';
    lDtl.FindField('Phone1').AsString    := 'Phone1';
    lDtl.FindField('Fax1').AsString      := 'Fax1';
    lDtl.FindField('Email').AsString      := 'EmailAddress';
    lDtl.Post;


     cdsMain.SaveToFile('C:\Temp\_ListM.xml'); //Export To XML file
     lDtl.Append; //For 2nd Branch
     cdsDtl.SaveToFile('C:\Temp\_ListD.xml');  //Export To XML file
    lDtl.FindField('BranchName').AsString := 'Branch1';
    lDtl.FindField('Address1').AsString  := 'DAddress1';
    lDtl.FindField('Address2').AsString  := 'DAddress2';
     lDtl.FindField('Address3').AsString  := 'DAddress3';
    lDtl.FindField('Address4').AsString  := 'DAddress4';
    lDtl.FindField('Attention').AsString := 'DAttention';
    lDtl.FindField('Phone1').AsString    := 'DPhone1';
    lDtl.FindField('Fax1').AsString      := 'DFax1';
    lDtl.FindField('Email').AsString      := 'DEmailAddress';
    lDtl.Post;
    lBizObj.Save;


     lTime := Now - lTime;
     lTime := Now - lTime;
Line 9,790: Line 11,018:
               mtInformation, [mbOk], 0);
               mtInformation, [mbOk], 0);
   finally
   finally
     lRptVar := null;
     lBizObj.Close;
    cdsMain.Free;
    cdsDtl.Free;
    cdsCat.Free;
   end;
   end;
end;
end;
Line 9,801: Line 11,026:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Customer.Statement.RO====
====AR_PM====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Customer.Statement.RO Report Object Script   
! AR_PM Script   
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="delphi">
procedure TfmMain.dxbb_StatementClick(Sender: TObject);
procedure TfmMain.dxbb_ARPMClick(Sender: TObject);
var lBizApp, lRptVar : Variant;
var lMain, lKO, lBizApp, lBizObj, V : Variant;
    lTime : TDateTime;
    cdsMain, cdsDtl : TClientDataset;
    s : string;
begin
begin
  lTime := Now;
  cdsMain := TClientDataset.Create(nil);
  cdsDtl  := TClientDataset.Create(nil);
   lBizApp := CreateOleObject('SQLAcc.BizApp');
   lBizApp := CreateOleObject('SQLAcc.BizApp');
  s := '<?xml version="1.0" standalone="yes"?>  <DATAPACKET Version="2.0"><METADATA><FIELDS>'+
      '<FIELD attrname="ColumnNo" fieldtype="i4" required="true"/><FIELD attrname="ColumnType" fieldtype="string" WIDTH="1"/>'+
      '<FIELD attrname="Param1" fieldtype="i4" required="true"/><FIELD attrname="Param2" fieldtype="i4" required="true"/>'+
      '<FIELD attrname="IsLocal" fieldtype="boolean"/><FIELD attrname="HeaderScript" fieldtype="bin.hex" SUBTYPE="Text" WIDTH="1"/>'+
      '</FIELDS><PARAMS/></METADATA><ROWDATA><ROW ColumnNo="0" ColumnType="" Param1="0" Param2="0" IsLocal="FALSE"/>'+
      '<ROW ColumnNo="1" ColumnType="A" Param1="0" Param2="0" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;Current Mth&apos;&#013;end;"/>'+
      '<ROW ColumnNo="2" ColumnType="A" Param1="-1" Param2="-1" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;1 Months&apos;&#013;end;"/>'+
      '<ROW ColumnNo="3" ColumnType="A" Param1="-2" Param2="-2" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;2 Months&apos;&#013;end;"/>'+
      '<ROW ColumnNo="4" ColumnType="A" Param1="-3" Param2="-3" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;3 Months&apos;&#013;end;"/>'+
      '<ROW ColumnNo="5" ColumnType="A" Param1="-4" Param2="-4" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;4 Months&apos;&#013;end;"/>'+
      '<ROW ColumnNo="6" ColumnType="B" Param1="-999999" Param2="-5" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;5 Month &amp; above&apos;&#013;end;"/>'+
      '</ROWDATA></DATAPACKET>';
   try
   try
     lRptVar := null;
     lBizObj := lBizApp.BizObjects.Find('AR_PM');
    lRptVar := lBizApp.RptObjects.Find('Customer.Statement.RO');
     lMain  := lBizObj.DataSets.Find('MainDataSet');
//  lRptVar.Params.Find('AgentData').AsBlob              := ; //Not use if AllAgent is True
     lKO     := lBizObj.DataSets.Find('cdsKnockOff');
     lRptVar.Params.Find('AgingData').AsString          := s; //Fixed
 
    lRptVar.Params.Find('AgingOn').AsString            := 'I'; //Fixed
     lBizObj.New;
     lRptVar.Params.Find('AllAgent').AsBoolean          := True;
     lMain.FindField('DOCKEY').Value          := -1;
     lRptVar.Params.Find('AllArea').AsBoolean            := True;
     lMain.FindField('DocNo').AsString        := '--PM Test--'; //Payment Document Number
    lRptVar.Params.Find('AllCompany').AsBoolean        := False;
     lMain.FindField('CODE').AsString          := '300-A0001';
    lRptVar.Params.Find('AllCompanyCategory').AsBoolean := True;
    lMain.FindField('DocDate').Value         := '28 Aug 2016';
     lRptVar.Params.Find('AllControlAccount').AsBoolean  := True;
     lMain.FindField('PostDate').Value        := '28 Aug 2016';
     lRptVar.Params.Find('AllCurrency').AsBoolean        := True;
     lMain.FindField('Description').AsString  := 'Payment for A/c';
     lRptVar.Params.Find('AllDocProject').AsBoolean      := True;
     lMain.FindField('PaymentMethod').AsString := '320-000';
//    lRptVar.Params.Find('AreaData').AsBlob              := ; //Not use if AllArea is True
     lMain.FindField('DocAmt').AsFloat         := 1060;
//    lRptVar.Params.Find('CompanyCategoryData').AsBlob  := ; //Not use if AllCompanyCategory is True
     lMain.FindField('Cancelled').AsString     := 'F';
     lRptVar.Params.Find('CompanyData').AsBlob          := '300-A0001'#13#10'300-C0001'; //Filter by Customer Code 300-A0001 & 300-C0001
//    lRptVar.Params.Find('ControlAccountData').AsBlob    := ; //Not use if AllControlAccount is True
//    lRptVar.Params.Find('CurrencyData').AsBlob         := ; //Not use if AllCurrency is True
    lRptVar.Params.Find('DateFrom').AsDate              := '01 Aug 2016';
     lRptVar.Params.Find('DateTo').AsDate                := '31 Aug 2016';
//    lRptVar.Params.Find('DocProjectData').AsBlob        := ; //Not use if AllDocProject is True
     lRptVar.Params.Find('IncludeZeroBalance').AsBoolean := False;
    lRptVar.Params.Find('SelectDate').AsBoolean        := True;
     lRptVar.Params.Find('SortBy').AsString             := 'CompanyCategory;Code;CompanyName;Agent;Area;CurrencyCode;ControlAccount';
     lRptVar.Params.Find('StatementDate').AsDate         := '31 Aug 2016'; // Norm same as DateTo
     lRptVar.Params.Find('StatementType').AsString       := 'O'; //O := Open Item, B := B/F


     lRptVar.CalculateReport;
     V := lBizApp.CreateOleVariantArray(2);
    V.SetItem(0, 'IV'); //Document Type is either is IV or DN for Sales & PI or SD for Purchase
    V.SetItem(1, '--IV Test--');  //Invoice Document Number


     cdsMain.XMLData := lRptVar.DataSets.Find('cdsMain').XMLData;      //Master Data
     if lKO.Locate('DocType;DocNo', V.AsOleVariant, False, False) then
     cdsDtl.XMLData  := lRptVar.DataSets.Find('cdsDocument').XMLData; //Detail Data - To link Master Data use Code field
      begin
        lKO.Edit;
        lKO.FindField('KOAmt').ASFloat     := 500;
        lKO.FindField('KnockOff').AsString := 'T';
        lKO.Post;
      end;


     cdsMain.SaveToFile('C:\Temp\_ListM.xml'); //Export To XML file
     lBizObj.Save;
     cdsDtl.SaveToFile('C:\Temp\_ListD.xml');  //Export To XML file
     MessageDlg('AR_PM-DocNo : ''--PM Test--'' Posted...', mtInformation, [mbOK],0);
 
    lTime := Now - lTime;
    MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
              mtInformation, [mbOk], 0);
   finally
   finally
     lRptVar := null;
     lBizObj.Close;
    cdsMain.Free;
    cdsDtl.Free;
   end;
   end;
end;
end;
Line 9,878: Line 11,075:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-GL Account List For Sales & Purchase 1====
====AR_PM-Edit====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! GL_Acc Object Script   
! AR_PM Script   
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="delphi">
procedure TfmMain.dxbb_GLAccClick(Sender: TObject);
procedure TfmMain.dxbb_ARPMClick(Sender: TObject);
var BizApp : Variant;
var lMain, lKO, lBizApp, lBizObj, V : Variant;
    lDataSet : TClientDataSet;
    ASQL : String;
begin
begin
   //For Debtor List => SpecialAccType = DR
   lBizApp := CreateOleObject('SQLAcc.BizApp');
  //For Creditor List => SpecialAccType = CR
  BizApp := CreateOleObject('SQLAcc.BizApp');
  lDataSet := TClientDataSet.Create(Self);
   try
   try
    ASQL := 'SELECT A.Code, A.Description FROM GL_ACC A '+
    lBizObj := lBizApp.BizObjects.Find('AR_PM');
            'LEFT OUTER JOIN GL_ACC B ON (A.Dockey=B.Parent) '+
    lMain  := lBizObj.DataSets.Find('MainDataSet');
            'WHERE A.Parent<>-1 ' +
    lKO    := lBizObj.DataSets.Find('cdsKnockOff');
            'AND B.Dockey IS NULL ' +
 
            'AND A.SpecialAccType = '''' '+
    lDocKey := lBizObj.FindKeyByRef('DocNo', '--PM Test--');
            'ORDER BY A.CODE ';
    lBizObj.Params.Find('DocKey').Value := VarToStr(lDocKey);
    lDataSet.Data := BizApp.DBManager.Execute(ASQL);
 
    lDataset.SaveToFile('C:\Temp\_List.xml', dfXML); //Export To XML file
    If not VarIsNull(lDocKey) Then begin
      lBizObj.Open;
      lBizObj.Edit;
      lMain.FindField('DOCKEY').Value          := -1;
      lMain.FindField('DocDate').Value          := '28 Aug 2016';
      lMain.FindField('PostDate').Value        := '28 Aug 2016';
      lMain.FindField('Description').AsString  := 'Payment for A/c';
      lMain.FindField('PaymentMethod').AsString := '310-000';
      lMain.FindField('DocAmt').AsFloat        := 800.28;
      lMain.FindField('UnappliedAmt').AsFloat  := 100.28;
      lMain.FindField('Cancelled').AsString    := 'F';
      lMain.FindField('CHANGED').AsString      := 'F';
 
      V := lBizApp.CreateOleVariantArray(2);
      V.SetItem(0, 'IV'); //Document Type is either is IV or DN for Sales & PI or SD for Purchase
      V.SetItem(1, '--IV Test--');  //Document Number
 
      if lKO.Locate('DocType;DocNo', V.AsOleVariant, False, False) then
        begin
          lKO.Edit;
          lKO.FindField('KOAmt').AsFloat    := 700.28; // IV Knock Off/Offset Amount
          lKO.FindField('KnockOff').AsString := 'T';
          lKO.Post;
        end;
 
      lBizObj.Save;
      MessageDlg('AR_PM-DocNo : ''--PM Test--'' Updated...', mtInformation, [mbOK],0);
    end;
   finally
   finally
     lDataSet.Free;
     lBizObj.Close;
   end;
   end;
end;
end;
Line 9,911: Line 11,130:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-GL Account List For Sales & Purchase 2====
====ST_Item====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! GL_Acc Object Script   
! ST_Item Script   
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="delphi">
procedure TfmMain.dxbb_GLAccClick(Sender: TObject);
procedure TfmMain.dxbb_ST_ItemClick(Sender: TObject);
var BizApp, BizObj : Variant;
var lMain, lDtl, lBizObj, lBizApp : Variant;
     lDataSet1, lDataSet2 : TClientDataSet;
     lTime : TDateTime;
    ASQL : String;
begin
begin
   //For Debtor List => SpecialAccType = DR
   lTime := Now;
   //For Creditor List => SpecialAccType = CR
   lBizApp := CreateOleObject('SQLAcc.BizApp');
  BizApp := CreateOleObject('SQLAcc.BizApp');
   lBizObj := lBizApp.BizObjects.Find('ST_ITEM');
   BizObj := BizApp.BizObjects.Find('GL_Acc');
  lMain  := lBizObj.DataSets.Find('MainDataSet');
  lDtl    := lBizObj.DataSets.Find('cdsUOM');


  lDataSet1 := TClientDataSet.Create(Self);
  lDataSet2 := TClientDataSet.Create(Self);
   try
   try
     ASQL :='Parent<>-1 ' +
     lBizObj.New;
          'AND (SpecialAccType IS NULL OR SpecialAccType = '''' ' +
    lMain.FindField('Code').AsString        := 'Test-1';
          'OR SpecialAccType = '''') ';
    lMain.FindField('Description').AsString := 'Testing - Description';
     lDataSet1.XMLData:= BizObj.Select('Dockey,Code,Description', ASQL, 'Code', 'SX', '', '');
 
    lDtl.Edit; //For 1st UOM
    lDtl.FindField('UOM').AsString    := 'PCS';
    lDtl.FindField('Rate').AsFloat    := 1;
     lDtl.FindField('RefCost').AsFloat  := 10.20;
    lDtl.FindField('RefPrice').AsFloat := 25.00;
    lDtl.Post;


     lDataSet2.XMLData:= BizObj.Select('Parent', '', 'Code', 'SX', '', '');
     lDtl.Append; //For 2nd UOM
    lDtl.FindField('UOM').AsString    := 'CTN';
    lDtl.FindField('Rate').AsFloat    := 12;
    lDtl.FindField('RefCost').AsFloat  := 102.00;
    lDtl.FindField('RefPrice').AsFloat := 240.00;
    lDtl.Post;
    lBizObj.Save;


     lDataset2.First; // Remove Parent Account
     lTime := Now - lTime;
     while not lDataset2.Eof do begin
     MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
      if lDataset1.Locate('Dockey', lDataSet2.FindField('Parent').AsString, []) then
              mtInformation, [mbOk], 0);
        lDataset1.Delete;
      lDataset2.Next;
    end;
    lDataset1.MergeChangeLog;
    lDataset1.SaveToFile('C:\Temp\_List.xml', dfXML); //Export To XML file
   finally
   finally
     lDataSet1.Free;
     lBizObj.Close;
    lDataSet2.Free;
   end;
   end;
end;
end;
Line 9,955: Line 11,178:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Customer.Aging.RO====
====ST_Item-Edit====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Customer Aging Report Object Script   
! ST_Item Script   
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="delphi">
procedure TfmMain.dxbb_AgingClick(Sender: TObject);
procedure TfmMain.dxbb_ST_ItemClick(Sender: TObject);
var lBizApp, lRptVar : Variant;
var lMain, lDtl, lBizObj, lBizApp, lDocKey, V : Variant;
    lTime : TDateTime;
    cdsMain, cdsDtl : TClientDataset;
    s : string;
begin
begin
  lTime := Now;
  cdsMain := TClientDataset.Create(nil);
  cdsDtl  := TClientDataset.Create(nil);
   lBizApp := CreateOleObject('SQLAcc.BizApp');
   lBizApp := CreateOleObject('SQLAcc.BizApp');
  lBizObj := lBizApp.BizObjects.Find('ST_ITEM');
  lMain  := lBizObj.DataSets.Find('MainDataSet');
  lDtl    := lBizObj.DataSets.Find('cdsUOM');


   s := '<?xml version="1.0" standalone="yes"?>  <DATAPACKET Version="2.0"><METADATA><FIELDS>'+
   lDocKey := lBizObj.FindKeyByRef('Code', '--Stock Item Test--');
      '<FIELD attrname="ColumnNo" fieldtype="i4" required="true"/><FIELD attrname="ColumnType" fieldtype="string" WIDTH="1"/>'+
  lBizObj.Params.Find('DocKey').Value := VarToStr(lDocKey);
      '<FIELD attrname="Param1" fieldtype="i4" required="true"/><FIELD attrname="Param2" fieldtype="i4" required="true"/>'+
      '<FIELD attrname="IsLocal" fieldtype="boolean"/><FIELD attrname="HeaderScript" fieldtype="bin.hex" SUBTYPE="Text" WIDTH="1"/>'+
      '</FIELDS><PARAMS/></METADATA><ROWDATA><ROW ColumnNo="0" ColumnType="" Param1="0" Param2="0" IsLocal="FALSE"/>'+
      '<ROW ColumnNo="1" ColumnType="A" Param1="0" Param2="0" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;Current Mth&apos;&#013;end;"/>'+
      '<ROW ColumnNo="2" ColumnType="A" Param1="-1" Param2="-1" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;1 Months&apos;&#013;end;"/>'+
      '<ROW ColumnNo="3" ColumnType="A" Param1="-2" Param2="-2" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;2 Months&apos;&#013;end;"/>'+
      '<ROW ColumnNo="4" ColumnType="A" Param1="-3" Param2="-3" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;3 Months&apos;&#013;end;"/>'+
      '<ROW ColumnNo="5" ColumnType="A" Param1="-4" Param2="-4" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;4 Months&apos;&#013;end;"/>'+
      '<ROW ColumnNo="6" ColumnType="B" Param1="-999999" Param2="-5" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;5 Month &amp; above&apos;&#013;end;"/>'+
      '</ROWDATA></DATAPACKET>';
   try
   try
    lRptVar := null;
    lRptVar := lBizApp.RptObjects.Find('Customer.Aging.RO');
    lRptVar.Params.Find('ActualGroupBy').AsString      := 'Code;CompanyName'; //Fixed
//    lRptVar.Params.Find('AgentData').AsBlob              := ; //Not use if AllAgent is True
    lRptVar.Params.Find('AgingData').AsString          := s;
    lRptVar.Params.Find('AgingDate').AsDate            := '31 Aug 2016';
    lRptVar.Params.Find('AgingOn').AsString            := 'I'; //Fixed
    lRptVar.Params.Find('AllAgent').AsBoolean          := True;
    lRptVar.Params.Find('AllArea').AsBoolean            := True;
    lRptVar.Params.Find('AllCompany').AsBoolean        := True;
    lRptVar.Params.Find('AllCompanyCategory').AsBoolean := True;
    lRptVar.Params.Find('AllControlAccount').AsBoolean  := True;
    lRptVar.Params.Find('AllCurrency').AsBoolean        := True;
    lRptVar.Params.Find('AllDocProject').AsBoolean      := True;
//    lRptVar.Params.Find('AreaData').AsBlob            := ; //Not use if AllArea is True
//    lRptVar.Params.Find('CompanyCategoryData').AsBlob := ; //Not use if AllCompanyCategory is True
//    lRptVar.Params.Find('CompanyData').AsBlob        := ; //Not use if AllCompany is True
//    lRptVar.Params.Find('ControlAccountData').AsBlob  := ; //Not use if AllControlAccount is True
//    lRptVar.Params.Find('CurrencyData').AsBlob        := ; //Not use if AllCurrency is True
//    lRptVar.Params.Find('DocProjectData').AsBlob      := ; //Not use if AllDocProject is True
    lRptVar.Params.Find('FilterPostDate').AsBoolean      := True;
//    lRptVar.Params.Find('GroupBy
    lRptVar.Params.Find('IncludePDC').AsBoolean        := False;
    lRptVar.Params.Find('IncludeZeroBalance').AsBoolean := False;
    lRptVar.Params.Find('SortBy').AsString              := 'Code;CompanyName';
    lRptVar.Params.Find('DateTo').AsDate                := '31 Aug 2016';
    lRptVar.Params.Find('IncludeKnockedOffDetail').AsBoolean := False;


     lRptVar.CalculateReport;
     If not VarIsNull(lDocKey) Then begin
      lBizObj.Open;
      lBizObj.Edit;
      lMain.FindField('Description').value := 'Testing - Description';


    cdsMain.XMLData := lRptVar.DataSets.Find('cdsMain').XMLData;     //Master Data
      V := lBizApp.CreateOleVariantArray(2);
    cdsDtl.XMLData  := lRptVar.DataSets.Find('cdsDocument').XMLData; //Detail Data - To link Master Data use Code field
      V.SetItem(0, 'CTN'); //UOM
      V.SetItem(1, '12'); //Rate


    cdsMain.SaveToFile('C:\Temp\_ListM.xml'); //Export To XML file
      if lDtl.Locate('UOM;Rate', V.AsOleVariant, False, False) then
    cdsDtl.SaveToFile('C:\Temp\_ListD.xml'); //Export To XML file
        begin
          lDtl.Edit;
          lDtl.FindField('RefCost').AsFloat  := 10.20;
          lDtl.FindField('RefPrice').AsFloat := 25.00;
          lDtl.Post;
        end;
      lBizObj.Save;


    lTime := Now - lTime;
      MessageDlg('ST_Item-ItemCode : ''--Stock Item Test--'' Updated...', mtInformation, [mbOK],0);
    MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
    end;
              mtInformation, [mbOk], 0);
   finally
   finally
     lRptVar := null;
     lBizObj.Close;
    cdsMain.Free;
    cdsDtl.Free;
   end;
   end;
end;
end;
Line 10,035: Line 11,225:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-GL.CB.RO====
====SL_IV====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! GL Cash Book Report Object Script   
! SL_IV Script   
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="delphi">
procedure TfmMain.dxBB_CBClick(Sender: TObject);
procedure TfmMain.dxbb_SL_IVClick(Sender: TObject);
var lBizApp, lRptVar : Variant;
var lMain, lDtl, lSN, lBizObj, lBizApp : Variant;
     lTime : TDateTime;
     lTime : TDateTime;
    cdsMain, cdsDtl, cdsTax : TClientDataset;
begin
begin
   lTime := Now;
   lTime := Now;
   cdsMain := TClientDataset.Create(nil);
   lBizApp := CreateOleObject('SQLAcc.BizApp');
   cdsDtl  := TClientDataset.Create(nil);
  lBizObj := lBizApp.BizObjects.Find('SL_IV');
   cdsTax  := TClientDataset.Create(nil);
   lMain  := lBizObj.DataSets.Find('MainDataSet');
   lBizApp := CreateOleObject('SQLAcc.BizApp');
   lDtl    := lBizObj.DataSets.Find('cdsDocDetail');
   lSN    := lBizObj.DataSets.Find('cdsSerialNumber');
 
   try
   try
     lRptVar := null;
     lBizObj.New;
     lRptVar := lBizApp.RptObjects.Find('GL.CB.RO');
    lMain.FindField('DOCKEY').Value        := -1;
     lRptVar.Params.Find('AllCurrency').AsBoolean          := True;
     lMain.FindField('DocNo').AsString      := '--IV Test--';
     lRptVar.Params.Find('AllDocProject').AsBoolean       := True;
    lMain.FindField('CODE').AsString        := '300-A0001';
     lRptVar.Params.Find('AllDocument').AsBoolean          := True;
    lMain.FindField('DocDate').Value        := '28 Aug 2020';
     lRptVar.Params.Find('AllItemProject').AsBoolean      := True;
     lMain.FindField('PostDate').Value      := '28 Aug 2020';
     lRptVar.Params.Find('AllItemArea').AsBoolean          := True;
     lMain.FindField('TAXDATE').Value       := '28 Aug 2020';
     lRptVar.Params.Find('AllItemAgent').AsBoolean        := True;
     lMain.FindField('Description').AsString := 'Sales';
     lRptVar.Params.Find('AllDocAgent').AsBoolean         := True;
    lMain.FindField('Cancelled').AsString  := 'F';
     lRptVar.Params.Find('AllDocArea').AsBoolean          := True;
     lMain.Post;
     lRptVar.Params.Find('AllPaymentMethod').AsBoolean    := False;
 
//   lRptVar.Params.Find('CurrencyData').AsBlob            := 'Not use if AllCurrency is true
    lDtl.Append; // For Tax Inclusive = True with override Tax Amount
    lDtl.FindField('DTLKEY').Value        := -1;
     lDtl.FindField('DOCKEY').Value        := -1;
    lDtl.FindField('SEQ').Value            := 1;
     lDtl.FindField('ItemCode').AsString    := 'ITEM A';
    lDtl.FindField('ACCOUNT').AsString    := '500-000'; //GL Sales Account
     lDtl.FindField('DESCRIPTION').AsString := 'Sales Item A';
    lDtl.FindField('QTY').AsFloat         := 1;
     lDtl.FindField('TAX').AsString        := 'SV';
    lDtl.FindField('TAXINCLUSIVE').Value  := 0;
     lDtl.FindField('UNITPRICE').AsFloat    := 435;//Including GST UnitPrice
    lDtl.FindField('AMOUNT').AsFloat      := 410.37; //Must Excluding GST (Qty * UnitPrice) // Less 0.01
    lDtl.FindField('TAXAMT').AsFloat      := 24.63; //Extra 0.01


// For Post Date From & Date To'
    lDtl.DisableControls; //For Tax Inclusive Only where TaxAmt is not as Calc
     lRptVar.Params.Find('DateFrom').AsDate                := '01/01/2017';
     try
     lRptVar.Params.Find('DateTo').AsDate                  := '31/12/2017';
      lDtl.FindField('TAXINCLUSIVE').Value := 1;
     finally
      lDtl.EnableControls;
    end;
    lDtl.Post;


//   lRptVar.Params.Find('DocProjectData').AsBlob          := //'Not use if AllDocProject is true
    lDtl.Append; // For Tax Inclusive = False with override Tax Amount
//    lRptVar.Params.Find('DocAreaData').AsBlob            := //Not use if AllDocArea is true
    lDtl.FindField('DTLKEY').Value        := -1;
//    lRptVar.Params.Find('DocAgentData').AsBlob           := //Not use if AllDocAgent is true
    lDtl.FindField('DOCKEY').Value        := -1;
//   lRptVar.Params.Find('ItemAgentData').AsBlob          := //Not use if AllItemAgent is true
    lDtl.FindField('SEQ').Value           := 2;
     lRptVar.Params.Find('DocType').AsString               := 'PV'; //'PV for Payment Voucher & OR for Official Receipt
    lDtl.FindField('ItemCode').AsString   := 'ITEM B';
//    lRptVar.Params.Find('DocumentData').AsBlob            := //Not use if AllDocument is true
    lDtl.FindField('ACCOUNT').AsString    := '500-000';
//    lRptVar.Params.Find('GroupBy').AsBlob                := //If you wanted to grouping the data
    lDtl.FindField('DESCRIPTION').AsString := 'Sales Item B';
     lRptVar.Params.Find('IncludeCancelled').AsBoolean    := False;
     lDtl.FindField('QTY').AsFloat          := 1;
//    lRptVar.Params.Find('ItemAreaData').AsBlob            := //Not use if AllItemArea is true
    lDtl.FindField('TAX').AsString         := 'SV';
//   lRptVar.Params.Find('ItemProjectData').AsBlob         := //Not use if AllItemProject is true
    lDtl.FindField('TAXINCLUSIVE').Value  := 0;
     lRptVar.Params.Find('PaymentMethodData').AsBlob      := '310-001';
    lDtl.FindField('UNITPRICE').AsFloat    := 94.43;
     lRptVar.Params.Find('PrintDocumentStyle').AsBoolean  := True;
     lDtl.FindField('AMOUNT').AsFloat      := 94.43;
     lRptVar.Params.Find('SelectDate').AsBoolean          := True; //For Post Date
    lDtl.FindField('TAXAMT').AsFloat      := 5.66; //Less 0.01
//  lRptVar.Params.Find('SelectDocDate').AsBoolean  := True; 'For Doc Date
    lDtl.Post;
     lRptVar.Params.Find('SortBy').AsString               := 'PostDate;DocNo';
 
    lDtl.Append; // For Serial Number
    lDtl.FindField('DTLKEY').Value         := -1;
     lDtl.FindField('DOCKEY').Value        := -1;
    lDtl.FindField('SEQ').Value            := 3;
     lDtl.FindField('ItemCode').AsString    := 'SN1';
     lDtl.FindField('ACCOUNT').AsString    := '500-000';
    lDtl.FindField('DESCRIPTION').AsString := 'Sales Serial Number Item';
 
     lSN.Append;
    lSN.FindField('SERIALNUMBER').AsString := 'SN-00001';
    lSN.Post;


     lRptVar.CalculateReport;
     lSN.Append;
    lSN.FindField('SERIALNUMBER').AsString  := 'SN-00002';
    lSN.Post;


     cdsMain.XMLData := lRptVar.DataSets.Find('cdsMain').XMLData;     //Master Data
     lDtl.FindField('QTY').AsFloat        := 2;
     cdsDtl.XMLData  := lRptVar.DataSets.Find('cdsDetail').XMLData; //Detail Data - To link Master Data use Dockey field
    lDtl.FindField('TAX').AsString      := 'SR';
     cdsTax.XMLData := lRptVar.DataSets.Find('cdsTax').XMLData; //Tax List
     lDtl.FindField('TAXINCLUSIVE').Value := 0;
     lDtl.FindField('UNITPRICE').AsFloat := 94.43;
    lDtl.FindField('TAXAMT').AsFloat    := 11.33;
    lDtl.Post;


     cdsMain.SaveToFile('C:\Temp\_ListM.xml'); //Export To XML file
     lBizObj.Save;
    cdsDtl.SaveToFile('C:\Temp\_ListD.xml');  //Export To XML file
    cdsTax.SaveToFile('C:\Temp\_ListT.xml'); //Export To XML file


     lTime := Now - lTime;
     lTime := Now - lTime;
Line 10,099: Line 11,320:
               mtInformation, [mbOk], 0);
               mtInformation, [mbOk], 0);
   finally
   finally
     lRptVar := null;
     lBizObj.Close;
     cdsMain.Free;
    lMain := null;
     cdsDtl.Free;
    lDtl := null;
    lSN := null;
     lBizObj := null;
     lBizApp := null;
   end;
   end;
end;
end;
Line 10,109: Line 11,333:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-AR_DP====
====Customer.IV.RO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Customer Deposit Script   
! Customer.IV.RO Report Object Script   
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="delphi">
procedure TForm1.Button1Click(Sender: TObject);
procedure TfmMain.dxbb_RptObjClick(Sender: TObject);
var lMain, lBizObj, lBizApp : Variant;
var lBizApp, lRptVar : Variant;
    lTime : TDateTime;
    cdsMain, cdsDtl : TClientDataset;
begin
begin
  lTime := Now;
  cdsMain := TClientDataset.Create(nil);
  cdsDtl  := TClientDataset.Create(nil);
   lBizApp := CreateOleObject('SQLAcc.BizApp');
   lBizApp := CreateOleObject('SQLAcc.BizApp');
   lBizApp.Login('ADMIN', 'ADMIN', 'D:\Happy\DB\Default.DCF', 'ACC-0110.FDB');
   try
    lRptVar := null;
    lRptVar := lBizApp.RptObjects.Find('Customer.IV.RO');
    lRptVar.Params.Find('SelectDate').AsBoolean          := True;
    lRptVar.Params.Find('DateFrom').AsDate                := '01/01/2015';
    lRptVar.Params.Find('DateTo').AsDate                  := '31/12/2015';
    lRptVar.Params.Find('AllAgent').AsBoolean            := False;
    lRptVar.Params.Find('AgentData').AsBlob              := '----'#13#10'HALIM'; //Filter by Agent code ---- & HALIM
    lRptVar.Params.Find('AllArea').AsBoolean              := True;
//    lRptVar.Params.Find('AreaData').AsBlob                := ; //Not use if AllArea is True
    lRptVar.Params.Find('AllCompany').AsBoolean          := True;
//    lRptVar.Params.Find('CompanyData').AsBlob            := ; //Not use if AllCompany is True
    lRptVar.Params.Find('AllCurrency').AsBoolean          := True;
//    lRptVar.Params.Find('CurrencyData').AsBlob            := ; //Not use if AllCurrenty is True
    lRptVar.Params.Find('AllDocProject').AsBoolean        := True;
//    lRptVar.Params.Find('DocProjectData').AsBlob          := ; //Not use if AllDocProject is True
    lRptVar.Params.Find('AllCompanyCategory').AsBoolean  := True;
//    lRptVar.Params.Find('CompanyCategoryData').AsBlob    := ; //Not use if AllCompanyCategory is True
    lRptVar.Params.Find('AllDocument').AsBoolean          := True;
//    lRptVar.Params.Find('DocumentData').AsBlob            := ; //Not use if AllDocument is True
    lRptVar.Params.Find('IncludeCancelled').AsBoolean  := True;
    lRptVar.Params.Find('PrintDocumentStyle').AsBoolean := False;
    lRptVar.Params.Find('AllItemProject').AsBoolean    := True;
    lRptVar.Params.Find('AllPaymentMethod').AsBoolean  := True;
    lRptVar.CalculateReport;


  lBizObj := lBizApp.BizObjects.Find('AR_DP');
    cdsMain.XMLData := lRptVar.DataSets.Find('cdsMain').XMLData;     //Master Data
  lMain  := lBizObj.DataSets.Find('MainDataSet');
    cdsDtl.XMLData  := lRptVar.DataSets.Find('cdsDocDetail').XMLData; //Detail Data - To link Master Data use Dockey field


  try
     cdsMain.SaveToFile('C:\Temp\_ListM.xml'); //Export To XML file
     lBizObj.New;
     cdsDtl.SaveToFile('C:\Temp\_ListD.xml');  //Export To XML file
    lMain.FindField('DOCKEY').Value        := -1;
    lMain.FindField('DocNo').AsString      := '--DP Test--';
     lMain.FindField('CODE').AsString        := '300-C0001';
    lMain.FindField('DocDate').Value        := '28 Oct 2019';
    lMain.FindField('PostDate').Value      := '28 Oct 2019';
    lMain.FindField('TAXDATE').Value        := '28 Oct 2019';
    lMain.FindField('DEPOSITACCOUNT').AsString := 'PREPAYMENT';
    lMain.FindField('PaymentMethod').AsString := '320-000'; //Bank or Cash account
    lMain.FindField('Description').AsString    := 'Deposit For Account';
    lMain.FindField('ChequeNumber').AsString  := '';
    lMain.FindField('BankCharge').AsFloat      := 0;
    lMain.FindField('DocAmt').AsFloat          := 1000.00;
    lMain.FindField('Cancelled').AsString      := 'F';


     try
     lTime := Now - lTime;
      lBizObj.Save;
     MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
     except
              mtInformation, [mbOk], 0);
      on E: Exception do
        Memo1.Lines.Append(E.Message);
    end;
    lBizObj.Close;
    Memo1.Lines.Append('Done');
//    MessageDlg('Done', mtInformation, [mbOk], 0);
   finally
   finally
     lMain := Null;
     lRptVar := null;
     lBizObj := Null;
     cdsMain.Free;
     lBizApp.Logout;
     cdsDtl.Free;
    lBizApp := Null;
   end;
   end;
end;
end;
Line 10,161: Line 11,394:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-Customer Deposit to Customer Payment====
====Stock.Item.RO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Customer Deposit to Customer Payment Script   
! Stock.Item.RO Report Object Script   
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="delphi">
procedure TForm1.Button2Click(Sender: TObject);
procedure TfmMain.dxbb_ST_ITEM_ROClick(Sender: TObject);
var lMain, lKO, lBizApp, lBizObj, V : Variant;
var lBizApp, lRptVar : Variant;
     cdsTmp : TClientDataset;
     lTime : TDateTime;
     lSQL : String;
    cdsMain, cdsDtl, cdsCat : TClientDataset;
     lSQL : string;
begin
begin
   cdsTmp := TClientDataset.Create(nil);
   lTime    := Now;
  cdsMain := TClientDataset.Create(nil);
  cdsDtl  := TClientDataset.Create(nil);
  cdsCat  := TClientDataset.Create(nil);
 
   lBizApp := CreateOleObject('SQLAcc.BizApp');
   lBizApp := CreateOleObject('SQLAcc.BizApp');
   lBizApp.Login('ADMIN', 'ADMIN', 'D:\Happy\DB\Default.DCF', 'ACC-0110.FDB');
 
   lSQL := 'SELECT * FROM ST_ITEM_CATEGORY ' +
          'WHERE Category IN (''B-MOTOLORA'',''B-MAXIS'')';
  cdsCat.Data := lBizApp.DBManager.Execute(lSQL); //For filtering Category only


   try
   try
     lSQL := 'SELECT DOCKEY FROM AR_DP ' +
     lRptVar := null;
             'WHERE DOCNO=''--DP Test--'' ';
    lRptVar := lBizApp.RptObjects.Find('Stock.Item.RO');
     cdsTmp.Data := lBizApp.DBManager.Execute(lSQL);
    lRptVar.Params.Find('AllItem').AsBoolean              := True;
    lRptVar.Params.Find('AllStockGroup').AsBoolean        := True;
    lRptVar.Params.Find('AllCustomerPriceTag').AsBoolean  := True;
    lRptVar.Params.Find('AllSupplierPriceTag').AsBoolean  := True;
//    lRptVar.Params.Find('CategoryData').AsBlob            := ; //Not use
//    lRptVar.Params.Find('CategoryTpl').AsBlob             := ; //Not use
//    lRptVar.Params.Find('CustomerPriceTagData').AsBlob    := ; //Not use if AllCustomerPriceTag is True
//    lRptVar.Params.Find('SupplierPriceTagData').AsBlob    := ; //Not use if AllSupplierPriceTag is True
//    lRptVar.Params.Find('DateFrom').AsDate                := '01/01/2015'; //Not use if SelectDate is False
//    lRptVar.Params.Find('DateTo').AsDate                  := '31/12/2015';
    lRptVar.Params.Find('HasAltStockItem').AsBoolean      := False;
    lRptVar.Params.Find('HasBarcode').AsBoolean          := False;
    lRptVar.Params.Find('HasBOM').AsBoolean              := False;
    lRptVar.Params.Find('HasCategory').AsBoolean          := False;
    lRptVar.Params.Find('HasCustomerItem').AsBoolean      := False;
    lRptVar.Params.Find('HasOpeningBalance').AsBoolean    := False;
    lRptVar.Params.Find('HasPurchasePrice').AsBoolean    := False;
    lRptVar.Params.Find('HasSellingPrice').AsBoolean      := False;
    lRptVar.Params.Find('HasSupplierItem').AsBoolean      := False;
//    lRptVar.Params.Find('ItemData').AsBlob                := 'ANT 1.0'#13#10'COVER'; //Filter by Item code ANT 1.0 & COVER
//    lRptVar.Params.Find('ItemCategoryData').AsBlob        := cdsCat.XMLData; //Not use if SelectCategory is False
    lRptVar.Params.Find('PrintActive').AsBoolean          := True;
    lRptVar.Params.Find('PrintInActive').AsBoolean        := True;
    lRptVar.Params.Find('PrintNonStockControl').AsBoolean := True;
    lRptVar.Params.Find('PrintStockControl').AsBoolean    := True;
    lRptVar.Params.Find('SelectCategory').AsBoolean      := False;
    lRptVar.Params.Find('SelectDate').AsBoolean          := False;
    lRptVar.Params.Find('SortBy').AsString                  := 'Code';
//    lRptVar.Params.Find('StockGroupData').AsBlob        := ; //Not use if AllStockGroup is True
    lRptVar.CalculateReport;
 
     cdsMain.XMLData := lRptVar.DataSets.Find('cdsMain').XMLData; //Master Data
    cdsDtl.XMLData  := lRptVar.DataSets.Find('cdsUOM').XMLData; //Detail Data - To link Master Data use Code field


     if cdsTmp.RecordCount > 0 then begin
     cdsMain.SaveToFile('C:\Temp\_ListM.xml'); //Export To XML file
      lBizObj := lBizApp.BizObjects.Find('AR_PM');
     cdsDtl.SaveToFile('C:\Temp\_ListD.xml'); //Export To XML file
      lMain  := lBizObj.DataSets.Find('MainDataSet');
      lKO     := lBizObj.DataSets.Find('cdsKnockOff');


      lBizObj.New;
    lTime := Now - lTime;
      lMain.FindField('DOCKEY').Value          := -1;
    MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
      lMain.FindField('DocNo').AsString        := '--PM Test--'; //Payment Document Number
              mtInformation, [mbOk], 0);
      lMain.FindField('CODE').AsString          := '300-C0001';
      lMain.FindField('DocDate').Value          := '29 Oct 2019';
      lMain.FindField('PostDate').Value        := '29 Oct 2019';
      lMain.FindField('Description').AsString  := 'Payment for A/c';
      lMain.FindField('PaymentMethod').AsString := 'PREPAYMENT';
      lMain.FindField('DocAmt').AsFloat        := 200;
      lMain.FindField('FROMDOCTYPE').AsString  := 'DP'; //Transfer from Deposit
      lMain.FindField('FROMDOCKEY').Value      := cdsTmp.FindField('Dockey').AsFloat; //Transfer from Deposit
      lMain.FindField('Cancelled').AsString    := 'F';
      lMain.FindField('CHANGED').AsString      := 'F';
 
      V := lBizApp.CreateOleVariantArray(2);
      V.SetItem(0, 'IV'); //Document Type is either is IV or DN for Sales & PI or SD for Purchase
      V.SetItem(1, 'IV-00003');  //Invoice Document Number
 
      if lKO.Locate('DocType;DocNo', V.AsOleVariant, False, False) then
        begin
          lKO.Edit;
          lKO.FindField('KOAmt').ASFloat    := 200;
          lKO.FindField('KnockOff').AsString := 'T';
          lKO.Post;
        end;
 
      try
        lBizObj.Save;
      except
        on E: Exception do
          Memo1.Lines.Append(E.Message);
      end;
        lBizObj.Close;
        Memo1.Lines.Append('Done');
      //MessageDlg('AR_PM-DocNo : ''--PM Test--'' Posted...', mtInformation, [mbOK],0);
    end else
      Memo1.Lines.Append('Deposit No. Not found');
   finally
   finally
     cdsTmp.Free;
     lRptVar := null;
     lBizApp.Logout;
     cdsMain.Free;
     lMain := Null;
     cdsDtl.Free;
     lBizObj := Null;
     cdsCat.Free;
    lBizApp := Null;
   end;
   end;
end;
end;
Line 10,236: Line 11,472:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-AR_DPDTL_REFUND====
====Customer.Statement.RO====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Customer Deposit Refund Script   
! Customer.Statement.RO Report Object Script   
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="delphi">
procedure TForm1.Button3Click(Sender: TObject);
procedure TfmMain.dxbb_StatementClick(Sender: TObject);
var lMain, lBizApp, lBizObj : Variant;
var lBizApp, lRptVar : Variant;
     cdsTmp : TClientDataset;
     lTime : TDateTime;
     lSQL : String;
    cdsMain, cdsDtl : TClientDataset;
     s : string;
begin
begin
   cdsTmp := TClientDataset.Create(nil);
   lTime := Now;
  cdsMain := TClientDataset.Create(nil);
  cdsDtl := TClientDataset.Create(nil);
   lBizApp := CreateOleObject('SQLAcc.BizApp');
   lBizApp := CreateOleObject('SQLAcc.BizApp');
   lBizApp.Login('ADMIN', 'ADMIN', 'D:\Happy\DB\Default.DCF', 'ACC-0110.FDB');
   s := '<?xml version="1.0" standalone="yes"?>  <DATAPACKET Version="2.0"><METADATA><FIELDS>'+
      '<FIELD attrname="ColumnNo" fieldtype="i4" required="true"/><FIELD attrname="ColumnType" fieldtype="string" WIDTH="1"/>'+
      '<FIELD attrname="Param1" fieldtype="i4" required="true"/><FIELD attrname="Param2" fieldtype="i4" required="true"/>'+
      '<FIELD attrname="IsLocal" fieldtype="boolean"/><FIELD attrname="HeaderScript" fieldtype="bin.hex" SUBTYPE="Text" WIDTH="1"/>'+
      '</FIELDS><PARAMS/></METADATA><ROWDATA><ROW ColumnNo="0" ColumnType="" Param1="0" Param2="0" IsLocal="FALSE"/>'+
      '<ROW ColumnNo="1" ColumnType="A" Param1="0" Param2="0" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;Current Mth&apos;&#013;end;"/>'+
      '<ROW ColumnNo="2" ColumnType="A" Param1="-1" Param2="-1" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;1 Months&apos;&#013;end;"/>'+
      '<ROW ColumnNo="3" ColumnType="A" Param1="-2" Param2="-2" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;2 Months&apos;&#013;end;"/>'+
      '<ROW ColumnNo="4" ColumnType="A" Param1="-3" Param2="-3" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;3 Months&apos;&#013;end;"/>'+
      '<ROW ColumnNo="5" ColumnType="A" Param1="-4" Param2="-4" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;4 Months&apos;&#013;end;"/>'+
      '<ROW ColumnNo="6" ColumnType="B" Param1="-999999" Param2="-5" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;5 Month &amp; above&apos;&#013;end;"/>'+
      '</ROWDATA></DATAPACKET>';
  try
    lRptVar := null;
    lRptVar := lBizApp.RptObjects.Find('Customer.Statement.RO');
//  lRptVar.Params.Find('AgentData').AsBlob              := ; //Not use if AllAgent is True
    lRptVar.Params.Find('AgingData').AsString          := s; //Fixed
    lRptVar.Params.Find('AgingOn').AsString            := 'I'; //Fixed
    lRptVar.Params.Find('AllAgent').AsBoolean          := True;
    lRptVar.Params.Find('AllArea').AsBoolean            := True;
    lRptVar.Params.Find('AllCompany').AsBoolean        := False;
    lRptVar.Params.Find('AllCompanyCategory').AsBoolean := True;
    lRptVar.Params.Find('AllControlAccount').AsBoolean  := True;
    lRptVar.Params.Find('AllCurrency').AsBoolean        := True;
    lRptVar.Params.Find('AllDocProject').AsBoolean      := True;
//    lRptVar.Params.Find('AreaData').AsBlob              := ; //Not use if AllArea is True
//    lRptVar.Params.Find('CompanyCategoryData').AsBlob  := ; //Not use if AllCompanyCategory is True
    lRptVar.Params.Find('CompanyData').AsBlob          := '300-A0001'#13#10'300-C0001'; //Filter by Customer Code 300-A0001 & 300-C0001
//    lRptVar.Params.Find('ControlAccountData').AsBlob    := ; //Not use if AllControlAccount is True
//    lRptVar.Params.Find('CurrencyData').AsBlob          := ; //Not use if AllCurrency is True
    lRptVar.Params.Find('DateFrom').AsDate              := '01 Aug 2016';
    lRptVar.Params.Find('DateTo').AsDate                := '31 Aug 2016';
//    lRptVar.Params.Find('DocProjectData').AsBlob        := ; //Not use if AllDocProject is True
    lRptVar.Params.Find('IncludeZeroBalance').AsBoolean := False;
    lRptVar.Params.Find('SelectDate').AsBoolean        := True;
    lRptVar.Params.Find('SortBy').AsString              := 'CompanyCategory;Code;CompanyName;Agent;Area;CurrencyCode;ControlAccount';
    lRptVar.Params.Find('StatementDate').AsDate        := '31 Aug 2016'; // Norm same as DateTo
    lRptVar.Params.Find('StatementType').AsString      := 'O'; //O := Open Item, B := B/F


  try
     lRptVar.CalculateReport;
     lSQL := 'SELECT DOCKEY FROM AR_DP ' +
            'WHERE DOCNO=''--DP Test--'' ';
    cdsTmp.Data := lBizApp.DBManager.Execute(lSQL);


     if cdsTmp.RecordCount > 0 then begin
     cdsMain.XMLData := lRptVar.DataSets.Find('cdsMain').XMLData;     //Master Data
      lBizObj := lBizApp.BizObjects.Find('AR_DPDTL_REFUND');
    cdsDtl.XMLData  := lRptVar.DataSets.Find('cdsDocument').XMLData; //Detail Data - To link Master Data use Code field
      lMain  := lBizObj.DataSets.Find('MainDataSet');


      lBizObj.New;
    cdsMain.SaveToFile('C:\Temp\_ListM.xml'); //Export To XML file
      lMain.FindField('DOCKEY').Value          := cdsTmp.FindField('Dockey').AsFloat;
    cdsDtl.SaveToFile('C:\Temp\_ListD.xml');  //Export To XML file
      lMain.FindField('Account').AsString      := '320-000'; //Bank or Cash account
      lMain.FindField('DocDate').Value        := '28 Oct 2019';
      lMain.FindField('PostDate').Value        := '28 Oct 2019';
      lMain.FindField('Description').AsString := 'Deposit Refund';
      lMain.FindField('ChequeNumber').AsString := '';
      lMain.FindField('BankCharge').AsFloat    := 0;
      lMain.FindField('PAYMENTAMOUNT').AsFloat := 500.00;


      try
    lTime := Now - lTime;
        lBizObj.Save;
    MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
      except
              mtInformation, [mbOk], 0);
        on E: Exception do
          Memo1.Lines.Append(E.Message);
      end;
      lBizObj.Close;
      Memo1.Lines.Append('Done');
  //    MessageDlg('Done', mtInformation, [mbOk], 0);
    end else
      Memo1.Lines.Append('Deposit No. Not Found');
   finally
   finally
     cdsTmp.Free;
     lRptVar := null;
    lMain := Null;
     cdsMain.Free;
     lBizObj := Null;
     cdsDtl.Free;
     lBizApp.Logout;
    lBizApp := Null;
   end;
   end;
end;
end;
Line 10,294: Line 11,549:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


====Example-AR_DPDTL_FORFEIT====
====GL Account List For Sales & Purchase 1====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Customer Deposit Forfeit Script   
! GL_Acc Object Script   
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="delphi">
procedure TForm1.Button4Click(Sender: TObject);
procedure TfmMain.dxbb_GLAccClick(Sender: TObject);
var lMain, lBizApp, lBizObj : Variant;
var BizApp : Variant;
     cdsTmp : TClientDataset;
     lDataSet : TClientDataSet;
     lSQL : String;
     ASQL : String;
begin
begin
   cdsTmp  := TClientDataset.Create(nil);
   //For Debtor List => SpecialAccType = DR
   lBizApp := CreateOleObject('SQLAcc.BizApp');
  //For Creditor List => SpecialAccType = CR
   lBizApp.Login('ADMIN', 'ADMIN', 'D:\Happy\DB\Default.DCF', 'ACC-0110.FDB');
   BizApp := CreateOleObject('SQLAcc.BizApp');
 
   lDataSet := TClientDataSet.Create(Self);
   try
   try
    lSQL := 'SELECT DOCKEY FROM AR_DP ' +
    ASQL := 'SELECT A.Code, A.Description FROM GL_ACC A '+
            'WHERE DOCNO=''--DP Test--'' ';
            'LEFT OUTER JOIN GL_ACC B ON (A.Dockey=B.Parent) '+
    cdsTmp.Data := lBizApp.DBManager.Execute(lSQL);
            'WHERE A.Parent<>-1 ' +
            'AND B.Dockey IS NULL ' +
            'AND A.SpecialAccType = '''' '+
            'ORDER BY A.CODE ';
    lDataSet.Data := BizApp.DBManager.Execute(ASQL);
    lDataset.SaveToFile('C:\Temp\_List.xml', dfXML); //Export To XML file
  finally
    lDataSet.Free;
  end;
end;
</syntaxhighlight>
|}


    if cdsTmp.RecordCount > 0 then begin
<div style="float: right;">   [[#top|[top]]]</div>
      lBizObj := lBizApp.BizObjects.Find('AR_DPDTL_FORFEIT');
      lMain   := lBizObj.DataSets.Find('MainDataSet');


      lBizObj.New;
====GL Account List For Sales & Purchase 2====
      lMain.FindField('DOCKEY').Value          := cdsTmp.FindField('Dockey').AsFloat;
{| class="mw-collapsible mw-collapsed wikitable"
      lMain.FindField('Account').AsString      := '532-000'; //Forfeit account
! GL_Acc Object Script 
      lMain.FindField('DocDate').Value        := '28 Oct 2019';
|-
      lMain.FindField('PostDate').Value        := '28 Oct 2019';
|
      lMain.FindField('Description').AsString  := 'Deposit Forfeit';
<syntaxhighlight lang="delphi">
      lMain.FindField('Amount').AsFloat        := 150.00;
procedure TfmMain.dxbb_GLAccClick(Sender: TObject);
var BizApp, BizObj : Variant;
    lDataSet1, lDataSet2 : TClientDataSet;
    ASQL : String;
begin
  //For Debtor List => SpecialAccType = DR
  //For Creditor List => SpecialAccType = CR
  BizApp := CreateOleObject('SQLAcc.BizApp');
  BizObj := BizApp.BizObjects.Find('GL_Acc');
 
  lDataSet1 := TClientDataSet.Create(Self);
  lDataSet2 := TClientDataSet.Create(Self);
  try
    ASQL :='Parent<>-1 ' +
          'AND (SpecialAccType IS NULL OR SpecialAccType = '''' ' +
          'OR SpecialAccType = '''') ';
    lDataSet1.XMLData:= BizObj.Select('Dockey,Code,Description', ASQL, 'Code', 'SX', '', '');
 
    lDataSet2.XMLData:= BizObj.Select('Parent', '', 'Code', 'SX', '', '');


      try
    lDataset2.First; // Remove Parent Account
        lBizObj.Save;
    while not lDataset2.Eof do begin
      except
       if lDataset1.Locate('Dockey', lDataSet2.FindField('Parent').AsString, []) then
        on E: Exception do
        lDataset1.Delete;
          Memo1.Lines.Append(E.Message);
      lDataset2.Next;
       end;
     end;
      lBizObj.Close;
    lDataset1.MergeChangeLog;
      Memo1.Lines.Append('Done');
    lDataset1.SaveToFile('C:\Temp\_List.xml', dfXML); //Export To XML file
  //    MessageDlg('Done', mtInformation, [mbOk], 0);
     end else
      Memo1.Lines.Append('Deposit No. Not Found');
   finally
   finally
     cdsTmp.Free;
     lDataSet1.Free;
     lMain := Null;
     lDataSet2.Free;
    lBizObj := Null;
    lBizApp.Logout;
    lBizApp := Null;
   end;
   end;
end;
end;
Line 10,350: Line 11,626:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


==FAQ==
====Customer.Aging.RO====
===Problem with opening CHM Help files?===
{| class="mw-collapsible mw-collapsed wikitable"
# Right click the chm file & select Properties
! Customer Aging Report Object Script 
# At General tab Click Unblock button.
|-
# Click Apply | Ok.
|  
 
<syntaxhighlight lang="delphi">
<div style="float: right;">   [[#top|[top]]]</div>
procedure TfmMain.dxbb_AgingClick(Sender: TObject);
var lBizApp, lRptVar : Variant;
    lTime : TDateTime;
    cdsMain, cdsDtl : TClientDataset;
    s : string;
begin
  lTime := Now;
  cdsMain := TClientDataset.Create(nil);
  cdsDtl  := TClientDataset.Create(nil);
   lBizApp := CreateOleObject('SQLAcc.BizApp');


===Still can't open CHM file?===
  s := '<?xml version="1.0" standalone="yes"?>  <DATAPACKET Version="2.0"><METADATA><FIELDS>'+
# Login SQL Accounting
      '<FIELD attrname="ColumnNo" fieldtype="i4" required="true"/><FIELD attrname="ColumnType" fieldtype="string" WIDTH="1"/>'+
# Click Tools | Options
      '<FIELD attrname="Param1" fieldtype="i4" required="true"/><FIELD attrname="Param2" fieldtype="i4" required="true"/>'+
# Click Register & follow wizard
      '<FIELD attrname="IsLocal" fieldtype="boolean"/><FIELD attrname="HeaderScript" fieldtype="bin.hex" SUBTYPE="Text" WIDTH="1"/>'+
# Exit SQL Accounting
      '</FIELDS><PARAMS/></METADATA><ROWDATA><ROW ColumnNo="0" ColumnType="" Param1="0" Param2="0" IsLocal="FALSE"/>'+
# Login SQL Accounting
      '<ROW ColumnNo="1" ColumnType="A" Param1="0" Param2="0" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;Current Mth&apos;&#013;end;"/>'+
# Run CHM File
      '<ROW ColumnNo="2" ColumnType="A" Param1="-1" Param2="-1" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;1 Months&apos;&#013;end;"/>'+
      '<ROW ColumnNo="3" ColumnType="A" Param1="-2" Param2="-2" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;2 Months&apos;&#013;end;"/>'+
      '<ROW ColumnNo="4" ColumnType="A" Param1="-3" Param2="-3" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;3 Months&apos;&#013;end;"/>'+
      '<ROW ColumnNo="5" ColumnType="A" Param1="-4" Param2="-4" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;4 Months&apos;&#013;end;"/>'+
      '<ROW ColumnNo="6" ColumnType="B" Param1="-999999" Param2="-5" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;5 Month &amp; above&apos;&#013;end;"/>'+
      '</ROWDATA></DATAPACKET>';
  try
    lRptVar := null;
    lRptVar := lBizApp.RptObjects.Find('Customer.Aging.RO');
    lRptVar.Params.Find('ActualGroupBy').AsString      := 'Code;CompanyName'; //Fixed
//    lRptVar.Params.Find('AgentData').AsBlob              := ; //Not use if AllAgent is True
    lRptVar.Params.Find('AgingData').AsString          := s;
    lRptVar.Params.Find('AgingDate').AsDate            := '31 Aug 2016';
    lRptVar.Params.Find('AgingOn').AsString            := 'I'; //Fixed
    lRptVar.Params.Find('AllAgent').AsBoolean          := True;
    lRptVar.Params.Find('AllArea').AsBoolean            := True;
    lRptVar.Params.Find('AllCompany').AsBoolean        := True;
    lRptVar.Params.Find('AllCompanyCategory').AsBoolean := True;
    lRptVar.Params.Find('AllControlAccount').AsBoolean  := True;
    lRptVar.Params.Find('AllCurrency').AsBoolean        := True;
    lRptVar.Params.Find('AllDocProject').AsBoolean      := True;
//    lRptVar.Params.Find('AreaData').AsBlob            := ; //Not use if AllArea is True
//    lRptVar.Params.Find('CompanyCategoryData').AsBlob := ; //Not use if AllCompanyCategory is True
//    lRptVar.Params.Find('CompanyData').AsBlob        := ; //Not use if AllCompany is True
//    lRptVar.Params.Find('ControlAccountData').AsBlob  := ; //Not use if AllControlAccount is True
//    lRptVar.Params.Find('CurrencyData').AsBlob        := ; //Not use if AllCurrency is True
//    lRptVar.Params.Find('DocProjectData').AsBlob      := ; //Not use if AllDocProject is True
    lRptVar.Params.Find('FilterPostDate').AsBoolean      := True;
//    lRptVar.Params.Find('GroupBy
    lRptVar.Params.Find('IncludePDC').AsBoolean        := False;
    lRptVar.Params.Find('IncludeZeroBalance').AsBoolean := False;
    lRptVar.Params.Find('SortBy').AsString              := 'Code;CompanyName';
    lRptVar.Params.Find('DateTo').AsDate                := '31 Aug 2016';
    lRptVar.Params.Find('IncludeKnockedOffDetail').AsBoolean := False;


<div style="float: right;">  [[#top|[top]]]</div>
    lRptVar.CalculateReport;


===Why when I compile my program with stated unknown method or unknown identifier?===
    cdsMain.XMLData := lRptVar.DataSets.Find('cdsMain').XMLData;      //Master Data
:If you compiler had error may try add the '''esfw10.dll''' file under the SQL Accounting\bin folder
    cdsDtl.XMLData  := lRptVar.DataSets.Find('cdsDocument').XMLData; //Detail Data - To link Master Data use Code field


<div style="float: right;">  [[#top|[top]]]</div>
    cdsMain.SaveToFile('C:\Temp\_ListM.xml'); //Export To XML file
    cdsDtl.SaveToFile('C:\Temp\_ListD.xml');  //Export To XML file


===How to make sure I login to correct database?===
    lTime := Now - lTime;
* Can use the '''Common.Agent.RO''' Report Objects to get the Profile info.
    MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
* Then use the cdsProfile Dataset
              mtInformation, [mbOk], 0);
: - CompanyName Field
  finally
: - Remark Field
    lRptVar := null;
* Refer to [https://www.estream.com.my/wiki/SDK_Live#Example-Get_Company_Profile Example - Get Company Profile]
    cdsMain.Free;
 
    cdsDtl.Free;
<div style="float: right;">  [[#top|[top]]]</div>
   end;
 
end;
===Why after post to SQL Accounting the Description3 (More Description)/Notes field it show like this "M y  D e s c r i p t i o n" instead of "My Description"?===
</syntaxhighlight>
:Make sure you use '''.AsString''' in your code (see example below)
{| class="mw-collapsible mw-collapsed wikitable"
! Description3 Field Script/Code 
|-
|
 
...
   lDtl.FindField('DESCRIPTION3').'''AsString'''  := 'Sales Item A More Description'+ #13 + 'I in 2nd line';
...
|}
|}


<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


===Can I Ignore Doc No Field & let SQL Accounting to Auto Assign?===
====GL.CB.RO====
:Yes but we not recommended as you will lost track when user wanted to know which Doc No in SQL Acc is posted.
: To Set Auto Assign set it as below
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! DocNo Field Script/Code  
! GL Cash Book Report Object Script   
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
procedure TfmMain.dxBB_CBClick(Sender: TObject);
var lBizApp, lRptVar : Variant;
    lTime : TDateTime;
    cdsMain, cdsDtl, cdsTax : TClientDataset;
begin
  lTime := Now;
  cdsMain := TClientDataset.Create(nil);
  cdsDtl  := TClientDataset.Create(nil);
  cdsTax  := TClientDataset.Create(nil);
  lBizApp := CreateOleObject('SQLAcc.BizApp');
  try
    lRptVar := null;
    lRptVar := lBizApp.RptObjects.Find('GL.CB.RO');
    lRptVar.Params.Find('AllCurrency').AsBoolean          := True;
    lRptVar.Params.Find('AllDocProject').AsBoolean        := True;
    lRptVar.Params.Find('AllDocument').AsBoolean          := True;
    lRptVar.Params.Find('AllItemProject').AsBoolean      := True;
    lRptVar.Params.Find('AllItemArea').AsBoolean          := True;
    lRptVar.Params.Find('AllItemAgent').AsBoolean        := True;
    lRptVar.Params.Find('AllDocAgent').AsBoolean          := True;
    lRptVar.Params.Find('AllDocArea').AsBoolean          := True;
    lRptVar.Params.Find('AllPaymentMethod').AsBoolean    := False;
//    lRptVar.Params.Find('CurrencyData').AsBlob            := 'Not use if AllCurrency is true


...
//  For Post Date From & Date To'
  lMain.FindField('DocNo').'''AsString'''  := '<<New>>';
    lRptVar.Params.Find('DateFrom').AsDate                := '01/01/2017';
...
    lRptVar.Params.Find('DateTo').AsDate                  := '31/12/2017';
|}


<div style="float: right;">   [[#top|[top]]]</div>
//    lRptVar.Params.Find('DocProjectData').AsBlob          := //'Not use if AllDocProject is true
//    lRptVar.Params.Find('DocAreaData').AsBlob            := //Not use if AllDocArea is true
//    lRptVar.Params.Find('DocAgentData').AsBlob            := //Not use if AllDocAgent is true
//    lRptVar.Params.Find('ItemAgentData').AsBlob          := //Not use if AllItemAgent is true
    lRptVar.Params.Find('DocType').AsString              := 'PV'; //'PV for Payment Voucher & OR for Official Receipt
//    lRptVar.Params.Find('DocumentData').AsBlob            := //Not use if AllDocument is true
//    lRptVar.Params.Find('GroupBy').AsBlob                := //If you wanted to grouping the data
    lRptVar.Params.Find('IncludeCancelled').AsBoolean    := False;
//    lRptVar.Params.Find('ItemAreaData').AsBlob            := //Not use if AllItemArea is true
//    lRptVar.Params.Find('ItemProjectData').AsBlob        := //Not use if AllItemProject is true
    lRptVar.Params.Find('PaymentMethodData').AsBlob      := '310-001';
    lRptVar.Params.Find('PrintDocumentStyle').AsBoolean   := True;
    lRptVar.Params.Find('SelectDate').AsBoolean          := True; //For Post Date
// lRptVar.Params.Find('SelectDocDate').AsBoolean  := True; 'For Doc Date
    lRptVar.Params.Find('SortBy').AsString                := 'PostDate;DocNo';
 
    lRptVar.CalculateReport;


===Can I Auto Login & Logout SQL Accounting when doing & after Posting?===
    cdsMain.XMLData := lRptVar.DataSets.Find('cdsMain').XMLData;      //Master Data
: Yes can below is example script
    cdsDtl.XMLData  := lRptVar.DataSets.Find('cdsDetail').XMLData; //Detail Data - To link Master Data use Dockey field
: Only work if that PC is no once is using SQL Accounting
    cdsTax.XMLData  := lRptVar.DataSets.Find('cdsTax').XMLData; //Tax List
 
    cdsMain.SaveToFile('C:\Temp\_ListM.xml'); //Export To XML file
    cdsDtl.SaveToFile('C:\Temp\_ListD.xml');  //Export To XML file
    cdsTax.SaveToFile('C:\Temp\_ListT.xml');  //Export To XML file
 
    lTime := Now - lTime;
    MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
              mtInformation, [mbOk], 0);
  finally
    lRptVar := null;
    cdsMain.Free;
    cdsDtl.Free;
  end;
end;
</syntaxhighlight>
|}
 
<div style="float: right;">  [[#top|[top]]]</div>
 
====AR_DP====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! C Sharp  
! Customer Deposit Script  
|-
|-
|  
|  
<syntaxhighlight lang="C#">
<syntaxhighlight lang="delphi">
Int32 lBuildNo;
procedure TForm1.Button1Click(Sender: TObject);
dynamic ComServer;
var lMain, lBizObj, lBizApp : Variant;
begin
public void CheckLogin()
  lBizApp := CreateOleObject('SQLAcc.BizApp');
{           
  lBizApp.Login('ADMIN', 'ADMIN', 'D:\Happy\DB\Default.DCF', 'ACC-0110.FDB');
    lBizType = Type.GetTypeFromProgID("SQLAcc.BizApp");
 
    ComServer = Activator.CreateInstance(lBizType);
  lBizObj := lBizApp.BizObjects.Find('AR_DP');
           
  lMain  := lBizObj.DataSets.Find('MainDataSet');
    if (!ComServer.IsLogin)
 
    {
  try
        try
    lBizObj.New;
        {
    lMain.FindField('DOCKEY').Value        := -1;
            ComServer.Login(edUN.Text, edPW.Text, edDCF.Text, edDB.Text);
    lMain.FindField('DocNo').AsString      := '--DP Test--';
            ComServer.Minimize();
    lMain.FindField('CODE').AsString        := '300-C0001';
        }
    lMain.FindField('DocDate').Value        := '28 Oct 2019';
        catch(Exception ex)
    lMain.FindField('PostDate').Value      := '28 Oct 2019';
        {
    lMain.FindField('TAXDATE').Value        := '28 Oct 2019';
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    lMain.FindField('DEPOSITACCOUNT').AsString := 'PREPAYMENT';
            FreeBiz(ComServer);
    lMain.FindField('PaymentMethod').AsString  := '320-000'; //Bank or Cash account
        }
     lMain.FindField('Description').AsString    := 'Deposit For Account';
     }
     lMain.FindField('ChequeNumber').AsString  := '';
    if (ComServer.IsLogin)
     lMain.FindField('BankCharge').AsFloat      := 0;
    {
    lMain.FindField('DocAmt').AsFloat          := 1000.00;
        lBuildNo = ComServer.BuildNo;
     lMain.FindField('Cancelled').AsString      := 'F';
     }
}
public void FreeBiz(object AbizObj)
{
     System.Runtime.InteropServices.Marshal.ReleaseComObject(AbizObj);
}
private void btnExport_Click(object sender, EventArgs e)
{
     dynamic BizObject, lMain, lDocKey;


     CheckLogin();
     try
     //'Step 2: Find and Create the Biz Objects
      lBizObj.Save;
     BizObject = ComServer.BizObjects.Find("Agent");
    except
      on E: Exception do
        Memo1.Lines.Append(E.Message);
     end;
    lBizObj.Close;
    Memo1.Lines.Append('Done');
//     MessageDlg('Done', mtInformation, [mbOk], 0);
  finally
    lMain := Null;
     lBizObj := Null;
    lBizApp.Logout;
    lBizApp := Null;
  end;
end;
</syntaxhighlight>
|}


    //Step 3: Set Dataset
<div style="float: right;">  [[#top|[top]]]</div>
    lMain = BizObject.DataSets.Find("MainDataSet");    //lMain contains master data


    //Step 4: Search
====Customer Deposit to Customer Payment====
    lDocKey = BizObject.FindKeyByRef("CODE", edCode.Text);
{| class="mw-collapsible mw-collapsed wikitable"
    try
! Customer Deposit to Customer Payment Script  
    {
        try
        {
            //Step 5 : Insert or Update
            if (Convert.IsDBNull(lDocKey))
            {
                BizObject.New();
                lMain.FindField("CODE").value = edCode.Text;
                lMain.FindField("DESCRIPTION").value = edDesc.Text;
            }
            else
            {//Edit Data if found
                BizObject.Params.Find("CODE").Value = lDocKey;
                BizObject.Open();
                BizObject.Edit();
                lMain.FindField("DESCRIPTION").value = edDesc.Text;
            }
            //Step 6: Save & Close
            BizObject.Save();
            MessageBox.Show("Done", "Status", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
    }
    finally
    {
        BizObject.Close();
 
        //Step 7 : Logout after done           
        FreeBiz(BizObject);
        ComServer.Logout();
        FreeBiz(ComServer);
    }           
}
</syntaxhighlight>
|}
 
{| class="mw-collapsible mw-collapsed wikitable"
! Delphi  
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="delphi">
....
procedure TForm1.Button2Click(Sender: TObject);
  public
var lMain, lKO, lBizApp, lBizObj, V : Variant;
    { Public declarations }
    cdsTmp : TClientDataset;
    lBizApp : variant;
    lSQL : String;
  end;
....
 
procedure TForm1.CheckLogin;
begin
begin
   lBizApp := null;
   cdsTmp  := TClientDataset.Create(nil);
   lBizApp := CreateOleObject('SQLAcc.BizApp');
   lBizApp := CreateOleObject('SQLAcc.BizApp');
  lBizApp.Login('ADMIN', 'ADMIN', 'D:\Happy\DB\Default.DCF', 'ACC-0110.FDB');


   if not lBizApp.IsLogin then begin
   try
     lBizApp.Login(edUN.Text, edPW.Text, edDCF.Text, edDB.Text); //Login with preset setting
    lSQL := 'SELECT DOCKEY FROM AR_DP ' +
     lBizApp.Minimize; //Mininise the SQLAccounting
            'WHERE DOCNO=''--DP Test--'' ';
    cdsTmp.Data := lBizApp.DBManager.Execute(lSQL);
 
    if cdsTmp.RecordCount > 0 then begin
      lBizObj := lBizApp.BizObjects.Find('AR_PM');
      lMain  := lBizObj.DataSets.Find('MainDataSet');
      lKO    := lBizObj.DataSets.Find('cdsKnockOff');
 
      lBizObj.New;
      lMain.FindField('DOCKEY').Value          := -1;
      lMain.FindField('DocNo').AsString        := '--PM Test--'; //Payment Document Number
      lMain.FindField('CODE').AsString          := '300-C0001';
      lMain.FindField('DocDate').Value          := '29 Oct 2019';
      lMain.FindField('PostDate').Value        := '29 Oct 2019';
      lMain.FindField('Description').AsString  := 'Payment for A/c';
      lMain.FindField('PaymentMethod').AsString := 'PREPAYMENT';
      lMain.FindField('DocAmt').AsFloat        := 200;
      lMain.FindField('FROMDOCTYPE').AsString  := 'DP'; //Transfer from Deposit
      lMain.FindField('FROMDOCKEY').Value      := cdsTmp.FindField('Dockey').AsFloat; //Transfer from Deposit
      lMain.FindField('Cancelled').AsString     := 'F';
      lMain.FindField('CHANGED').AsString      := 'F';
 
      V := lBizApp.CreateOleVariantArray(2);
      V.SetItem(0, 'IV'); //Document Type is either is IV or DN for Sales & PI or SD for Purchase
      V.SetItem(1, 'IV-00003');  //Invoice Document Number
 
      if lKO.Locate('DocType;DocNo', V.AsOleVariant, False, False) then
        begin
          lKO.Edit;
          lKO.FindField('KOAmt').ASFloat    := 200;
          lKO.FindField('KnockOff').AsString := 'T';
          lKO.Post;
        end;
 
      try
        lBizObj.Save;
      except
        on E: Exception do
          Memo1.Lines.Append(E.Message);
      end;
        lBizObj.Close;
        Memo1.Lines.Append('Done');
      //MessageDlg('AR_PM-DocNo : ''--PM Test--'' Posted...', mtInformation, [mbOK],0);
    end else
      Memo1.Lines.Append('Deposit No. Not found');
  finally
    cdsTmp.Free;
     lBizApp.Logout;
    lMain := Null;
    lBizObj := Null;
    lBizApp := Null;
   end;
   end;
end;
end;
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>


procedure TForm1.Button2Click(Sender: TObject);
====AR_DPDTL_REFUND====
var BizObject, lMain : Variant;
{| class="mw-collapsible mw-collapsed wikitable"
! Customer Deposit Refund Script 
|-
|
<syntaxhighlight lang="delphi">
procedure TForm1.Button3Click(Sender: TObject);
var lMain, lBizApp, lBizObj : Variant;
    cdsTmp : TClientDataset;
    lSQL : String;
begin
begin
  cdsTmp  := TClientDataset.Create(nil);
  lBizApp := CreateOleObject('SQLAcc.BizApp');
  lBizApp.Login('ADMIN', 'ADMIN', 'D:\Happy\DB\Default.DCF', 'ACC-0110.FDB');
   try
   try
     //Begin Loop your data
     lSQL := 'SELECT DOCKEY FROM AR_DP ' +
     try
            'WHERE DOCNO=''--DP Test--'' ';
      CheckLogin;
     cdsTmp.Data := lBizApp.DBManager.Execute(lSQL);
       BizObject := lBizApp.BizObjects.Find('Agent');
 
       lMain     := BizObject.DataSets.Find('MainDataSet');
    if cdsTmp.RecordCount > 0 then begin
       BizObject.New;
       lBizObj := lBizApp.BizObjects.Find('AR_DPDTL_REFUND');
       lMain.FindField('CODE').AsString := 'HALIM';
       lMain   := lBizObj.DataSets.Find('MainDataSet');
       lMain.FindField('Description').AsString := 'HALIM 123';
 
       BizObject.save;
       lBizObj.New;
    except
       lMain.FindField('DOCKEY').Value          := cdsTmp.FindField('Dockey').AsFloat;
      on E: Exception do
      lMain.FindField('Account').AsString     := '320-000'; //Bank or Cash account
        MmLog.Lines.Append(E.Message);
      lMain.FindField('DocDate').Value        := '28 Oct 2019';
    end;
      lMain.FindField('PostDate').Value        := '28 Oct 2019';
    //
       lMain.FindField('Description').AsString  := 'Deposit Refund';
      lMain.FindField('ChequeNumber').AsString := '';
       lMain.FindField('BankCharge').AsFloat    := 0;
      lMain.FindField('PAYMENTAMOUNT').AsFloat := 500.00;
 
      try
        lBizObj.Save;
      except
        on E: Exception do
          Memo1.Lines.Append(E.Message);
      end;
      lBizObj.Close;
      Memo1.Lines.Append('Done');
  //     MessageDlg('Done', mtInformation, [mbOk], 0);
    end else
      Memo1.Lines.Append('Deposit No. Not Found');
   finally
   finally
     BizObject.close;
     cdsTmp.Free;
     BizObject := null;
     lMain := Null;
    lBizObj := Null;
     lBizApp.Logout;
     lBizApp.Logout;
     lBizApp := null;
     lBizApp := Null;
   end;
   end;
end;
end;
Line 10,555: Line 11,963:
|}
|}


<div style="float: right;">  [[#top|[top]]]</div>
====AR_DPDTL_FORFEIT====
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! VB Script   
! Customer Deposit Forfeit Script   
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="delphi">
'Copy below script & paste to notepad & name it as eg Agent.vbs
procedure TForm1.Button4Click(Sender: TObject);
Call PostData
var lMain, lBizApp, lBizObj : Variant;
    cdsTmp : TClientDataset;
Function CreateSQLAccServer
    lSQL : String;
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
begin
End Function
   cdsTmp  := TClientDataset.Create(nil);
   lBizApp := CreateOleObject('SQLAcc.BizApp');
Function PostData
   lBizApp.Login('ADMIN', 'ADMIN', 'D:\Happy\DB\Default.DCF', 'ACC-0110.FDB');
Dim ComServer, BizObject
   'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
    
  Set WScr = CreateObject("WScript.Shell")
   WScript.Sleep 1000 '//Wait 1 second for system loading before proceed


   'Step 2: Force Logout to make sure login correct database
   try
  If ComServer.IsLogin Then 'if user hasn't logon to SQL application
    lSQL := 'SELECT DOCKEY FROM AR_DP ' +
     ComServer.Logout
            'WHERE DOCNO=''--DP Test--'' ';
  END IF
     cdsTmp.Data := lBizApp.DBManager.Execute(lSQL);
  'Step 3: Login
  ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0015.FDB"


  'Step 4: Find and Create the Biz Objects
    if cdsTmp.RecordCount > 0 then begin
  Set BizObject = ComServer.BizObjects.Find("Agent")  
      lBizObj := lBizApp.BizObjects.Find('AR_DPDTL_FORFEIT');
      lMain   := lBizObj.DataSets.Find('MainDataSet');
   'Step 5: Set Dataset
  Set lMain = BizObject.DataSets.Find("MainDataSet")   'lMainDataSet contains master data


 
      lBizObj.New;
  'Step 6 : Posting
      lMain.FindField('DOCKEY').Value          := cdsTmp.FindField('Dockey').AsFloat;
    BizObject.New
      lMain.FindField('Account').AsString      := '532-000'; //Forfeit account
    lMain.FindField("CODE").AsString          = "_Test_"
      lMain.FindField('DocDate').Value        := '28 Oct 2019';
    lMain.FindField("Description").AsString   = "Testing 123"
      lMain.FindField('PostDate').Value        := '28 Oct 2019';
      lMain.FindField('Description').AsString := 'Deposit Forfeit';
      lMain.FindField('Amount').AsFloat        := 150.00;


   'Step 7: Save Document
      try
     BizObject.Save
        lBizObj.Save;
     BizObject.Close
      except
        on E: Exception do
  'Step 8: Logout
          Memo1.Lines.Append(E.Message);
     ComServer.Logout
      end;
MsgBox "Done"
      lBizObj.Close;
End Function
      Memo1.Lines.Append('Done');
   //    MessageDlg('Done', mtInformation, [mbOk], 0);
     end else
      Memo1.Lines.Append('Deposit No. Not Found');
  finally
     cdsTmp.Free;
    lMain := Null;
    lBizObj := Null;
     lBizApp.Logout;
    lBizApp := Null;
  end;
end;
</syntaxhighlight>
</syntaxhighlight>
|}
|}
Line 10,608: Line 12,021:
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


===When Post System Prompt Operation aborted Error===
==FAQ==
: This happen when the Login User ID don't had the to '''Override Sales Min/Max Price''' &
===Problem with opening CHM Help files?===
: Use '''Last Price XXX''' (In Tools | Options | Unit Price) &
# Right click the chm file & select Properties
: 1 of record is below Min Price.
# At General tab Click Unblock button.
'''Solution'''
# Click Apply | Ok.
: Can try change the Posting Seq like below (UOM then Qty)
 
<div style="float: right;">  [[#top|[top]]]</div>
 
===Still can't open CHM file?===
# Login SQL Accounting
# Click Tools | Options
# Click Register & follow wizard
# Exit SQL Accounting
# Login SQL Accounting
# Run CHM File
 
<div style="float: right;">  [[#top|[top]]]</div>
 
===Why when I compile my program with stated unknown method or unknown identifier?===
:If you compiler had error may try add the '''esfw10.dll''' file under the SQL Accounting\bin folder
 
<div style="float: right;">  [[#top|[top]]]</div>
 
===How to make sure I login to correct database?===
* Can use the '''Common.Agent.RO''' Report Objects to get the Profile info.
* Then use the cdsProfile Dataset
: - CompanyName Field
: - Remark Field
* Refer to [https://wiki.sql.com.my/wiki/SDK_Live#Get_Company_Profile Get Company Profile]
 
<div style="float: right;">  [[#top|[top]]]</div>
 
===Why after post to SQL Accounting the Description3 (More Description)/Notes field it show like this "M y  D e s c r i p t i o n" instead of "My Description"?===
:Make sure you use '''.AsString''' in your code (see example below)
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Sequence Field Script/Code   
! Description3 Field Script/Code   
|-
|-
|  
|  


...
...
    lDetail.Append();
  lDtl.FindField('DESCRIPTION3').'''AsString''' := 'Sales Item A More Description'+ #13 + 'I in 2nd line';
    lDetail.FindField("DtlKey").value = -1;
...
    lDetail.FindField("DocKey").value = -1;
|}
    lDetail.FindField("Seq").value = 3;
 
    lDetail.FindField("ItemCode").AsString = "ANT";
<div style="float: right;">  [[#top|[top]]]</div>
    lDetail.FindField("Description").AsString = "Sales Item B";
 
    //lDetail.FindField("Account").AsString = "500-000"; To override the Sales Account Code
===Can I Ignore Doc No Field & let SQL Accounting to Auto Assign?===
    '''lDetail.FindField("UOM").AsString = "UNIT";'''
:Yes but we not recommended as you will lost track when user wanted to know which Doc No in SQL Acc is posted.  
    '''lDetail.FindField("Qty").AsFloat = 2;'''
: To Set Auto Assign set it as below
    //lDetail.FindField("DISC").AsString = "5%+3"; //Optional(eg 5% plus 3 Discount)
    lDetail.FindField("Tax").AsString = "SR";
    lDetail.FindField("TaxRate").AsString = "6%";
    lDetail.FindField("TaxInclusive").value = 0;
    lDetail.FindField("UnitPrice").AsFloat = 100;
    lDetail.FindField("Amount").AsFloat = 200;
    lDetail.FindField("TaxAmt").AsFloat = 12;
    lDetail.Post();
...
|}
<div style="float: right;">  [[#top|[top]]]</div>
 
===How do my system know there is a changes or update in SQLAccounting?===
'''Data Entry'''<br>
: In all Document it had a field call <span style="color:#0000ff">UPDATECOUNT</span>.
: Default is null & each changes will +1.
: So if you see 2 meaning it had being update 2 times
 
'''Master Data'''
: Only available in  
:* Version 842.765 & above
:* AP_SUPPLIER (Maintain Supplier)
:* AR_CUSTOMER (Maintain Customer)
:* ST_GROUP (Maintain Stock Group)
:* ST_ITEM (Maintain Stock Item)
:* ST_ITEM_TPL (Maintain Item Template)
:* ST_PRICETAG (Maintain Price Tag)
:* TAX (Maintain Tax)
: In Each table it had a field call <span style="color:#0000ff">LASTMODIFIED</span>.
: The value is '''Epoch Time''' or '''Unix Time'''
 
You can use below function to get the field
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! vbs  
! DocNo Field Script/Code  
|-
|-
|  
|  
<syntaxhighlight lang="vbs">
 
...
...
Function GetData
   lMain.FindField('DocNo').'''AsString'''  := '<<New>>';
Dim lDataSet, lSQL
   lSQL = "SELECT DOCNO, UPDATECOUNT FROM SL_CS "
  lSQL = lSQL & "WHERE UPDATECOUNT IS NOT NULL "
  lSQL = lSQL & "ORDER BY DOCNO "
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
 
  lDataSet.First
  While (not lDataSet.eof)
    MsgBox "DocNo : " & lDataSet.FindField("DocNo").AsString
    MsgBox "UpdateCount : " & lDataSet.FindField("UPDATECOUNT").AsString
    lDataSet.Next
  Wend
End Function
...
...
</syntaxhighlight>
lDocNo := lMain.FindField('DocNo').AsString; //To Get docno after post
|}
|}


<div style="float: right;">  [[#top|[top]]]</div>
===Can I Auto Login & Logout SQL Accounting when doing & after Posting?===
: Yes can below is example script
: Only work if that PC is no once is using SQL Accounting
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Delphi
! C Sharp 
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="C#">
...  
Int32 lBuildNo;
procedure TfmMain.dxbb_GetFieldClick(Sender: TObject);
dynamic ComServer;
var BizApp : Variant;
     lDataSet : TClientDataSet;
public void CheckLogin()
     ASQL : String;
{           
begin
    lBizType = Type.GetTypeFromProgID("SQLAcc.BizApp");
  BizApp := CreateOleObject('SQLAcc.BizApp');
    ComServer = Activator.CreateInstance(lBizType);
  lDataSet := TClientDataSet.Create(Self);
           
  try
    if (!ComServer.IsLogin)
    ASQL := 'SELECT DOCNO, UPDATECOUNT FROM SL_CS ' +
    {
            'WHERE UPDATECOUNT IS NOT NULL ' +
        try
            'ORDER BY DOCNO ';
        {
    lDataSet.Data := BizApp.DBManager.Execute(ASQL);
            ComServer.Login(edUN.Text, edPW.Text, edDCF.Text, edDB.Text);
    lDataset.SaveToFile('C:\Temp\_List.xml', dfXML); //Export To XML file
            ComServer.Minimize();
  finally
        }
     lDataSet.Free;
        catch(Exception ex)
  end;
        {
end;
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
...
            FreeBiz(ComServer);
</syntaxhighlight>
        }
|}
    }
<div style="float: right;">  [[#top|[top]]]</div>
    if (ComServer.IsLogin)
    {
        lBuildNo = ComServer.BuildNo;
    }
}
public void FreeBiz(object AbizObj)
{
    System.Runtime.InteropServices.Marshal.ReleaseComObject(AbizObj);
}
private void btnExport_Click(object sender, EventArgs e)
{
    dynamic BizObject, lMain, lDocKey;
 
     CheckLogin();
     //'Step 2: Find and Create the Biz Objects
    BizObject = ComServer.BizObjects.Find("Agent");
 
    //Step 3: Set Dataset
    lMain = BizObject.DataSets.Find("MainDataSet");   //lMain contains master data
 
    //Step 4: Search
    lDocKey = BizObject.FindKeyByRef("CODE", edCode.Text);
    try
    {
        try
        {
            //Step 5 : Insert or Update
            if (Convert.IsDBNull(lDocKey))
            {
                BizObject.New();
                lMain.FindField("CODE").value = edCode.Text;
                lMain.FindField("DESCRIPTION").value = edDesc.Text;
            }
            else
            {//Edit Data if found
                BizObject.Params.Find("CODE").Value = lDocKey;
                BizObject.Open();
                BizObject.Edit();
                lMain.FindField("DESCRIPTION").value = edDesc.Text;
            }
            //Step 6: Save & Close
            BizObject.Save();
            MessageBox.Show("Done", "Status", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
    }
    finally
     {
        BizObject.Close();
 
        //Step 7 : Logout after done           
        FreeBiz(BizObject);
        ComServer.Logout();
        FreeBiz(ComServer);
    }           
}
</syntaxhighlight>
|}


===Can I control my Stock when I link with other Application?===
: Yes. We suggest to use Stock Transfer to (eg Location call <span style="color:#0000ff">MOBILE</span>) transfer stock as Reserve to avoid stock over deduct in SQL Accounting
: When other Application post to SQL Accounting they just need set the Location to the Reserve Location (eg <span style="color:#0000ff">MOBILE</span>)
: Below is example posting with location
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Post Location Field Script/Code  
! Delphi  
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
....
  public
    { Public declarations }
    lBizApp : variant;
  end;
....


...
procedure TForm1.CheckLogin;
   lDtl.FindField('UOM').AsString      := 'CTN';
begin
   lDtl.FindField('QTY').AsFloat        := 6;
   lBizApp := null;
  lDtl.FindField('Location').AsString  := 'MOBILE';
   lBizApp := CreateOleObject('SQLAcc.BizApp');
...
|}


<div style="float: right;">   [[#top|[top]]]</div>
  if not lBizApp.IsLogin then begin
    lBizApp.Login(edUN.Text, edPW.Text, edDCF.Text, edDB.Text); //Login with preset setting
    lBizApp.Minimize; //Mininise the SQLAccounting
   end;
end;


===Where to Check the SQL Accounting DCF Path, FileName & FDB FileName?===
procedure TForm1.Button2Click(Sender: TObject);
: In Login Screen Click 3 Dot Button then you can see the information
var BizObject, lMain : Variant;
[[File:SDK-FAQ-01.jpg|center]]
begin
[[File:SDK-FAQ-02.jpg|554px|center]]
  try
<div style="float: right;">   [[#top|[top]]]</div>
    //Begin Loop your data
    try
      CheckLogin;
      BizObject := lBizApp.BizObjects.Find('Agent');
      lMain    := BizObject.DataSets.Find('MainDataSet');
      BizObject.New;
      lMain.FindField('CODE').AsString := 'HALIM';
      lMain.FindField('Description').AsString := 'HALIM 123';
      BizObject.save;
    except
      on E: Exception do
        MmLog.Lines.Append(E.Message);
    end;
    //
  finally
    BizObject.close;
    BizObject := null;
    lBizApp.Logout;
    lBizApp := null;
   end;
end;
</syntaxhighlight>
|}


===How to check & What is the value for Advance Credit Control in Maintain Customer===
{| class="mw-collapsible mw-collapsed wikitable"
: You can use <span style="color:#0000ff">ComServer.DBManager.NewDataSet(lSQL)</span> function to Query the information
! VB Script 
: lSQL = SELECT * FROM AR_CUSTOMERCRCTRL
: You may refer to <span style="color:#0000ff">ControlType</span> column
 
{| class="wikitable" style="margin: 1em auto 1em auto;"
|-
|-
! ControlType !! Exceed Credit Limit !! Exceed OverDue Limit
|  
|-
<syntaxhighlight lang="vb">
| align="center" | 0 || UnBlock || UnBlock
'Copy below script & paste to notepad & name it as eg Agent.vbs
|-
Call PostData
| align="center" | 1 || UnBlock || Block
|-
Function CreateSQLAccServer
| align="center" | 2|| UnBlock || Override
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
|-
End Function
| align="center" |  3|| Block || UnBlock
|-
Function PostData
| align="center" | 4|| Block || Block
Dim ComServer, BizObject
|-
| align="center" | 5|| Block || Override
  'Step 1: Create Com Server object
|-
  Set ComServer = CreateSQLAccServer 'Create Com Server
| align="center" | 6|| Override || UnBlock
 
|-
  Set WScr = CreateObject("WScript.Shell")
| align="center" | 7|| Override || Block
  WScript.Sleep 1000 '//Wait 1 second for system loading before proceed
|-
 
| align="center" | 8|| Override || Override
  'Step 2: Force Logout to make sure login correct database
|-
  If ComServer.IsLogin Then 'if user hasn't logon to SQL application
| align="center" | 9|| align="center" colspan="2"| Suspended
    ComServer.Logout
  END IF
  'Step 3: Login
  ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0015.FDB"  
 
  'Step 4: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("Agent")
  'Step 5: Set Dataset
  Set lMain = BizObject.DataSets.Find("MainDataSet")    'lMainDataSet contains master data
 
 
  'Step 6 : Posting
    BizObject.New
    lMain.FindField("CODE").AsString          = "_Test_"
    lMain.FindField("Description").AsString  = "Testing 123"
 
  'Step 7: Save Document
    BizObject.Save
    BizObject.Close
  'Step 8: Logout
    ComServer.Logout
MsgBox "Done"
End Function
</syntaxhighlight>
|}
|}


<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


===How to get Error/Exception Message Return from SQL Accounting?===
===When Post System Prompt Operation aborted Error===
: This happen when the Login User ID don't had the to '''Override Sales Min/Max Price''' &
: Use '''Last Price XXX''' (In Tools | Options | Unit Price) &
: 1 of record is below Min Price.
'''Solution'''
: Can try change the Posting Seq like below (UOM then Qty)
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! C Sharp  
! Sequence Field Script/Code  
|-
|-
|  
|  
<syntaxhighlight lang="C#">
 
try
...
{
    lDetail.Append();
  BizObject.New();
    lDetail.FindField("DtlKey").value = -1;
....
    lDetail.FindField("DocKey").value = -1;
  BizObject.Save();
    lDetail.FindField("Seq").value = 3;
}
    lDetail.FindField("ItemCode").AsString = "ANT";
catch (Exception ex)
    lDetail.FindField("Description").AsString = "Sales Item B";
{
    //lDetail.FindField("Account").AsString = "500-000"; To override the Sales Account Code
     MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    '''lDetail.FindField("UOM").AsString = "UNIT";'''
}
    '''lDetail.FindField("Qty").AsFloat = 2;'''
</syntaxhighlight>
    //lDetail.FindField("DISC").AsString = "5%+3"; //Optional(eg 5% plus 3 Discount)
    lDetail.FindField("Tax").AsString = "SR";
    lDetail.FindField("TaxRate").AsString = "6%";
     lDetail.FindField("TaxInclusive").value = 0;
    lDetail.FindField("UnitPrice").AsFloat = 100;
    lDetail.FindField("Amount").AsFloat = 200;
    lDetail.FindField("TaxAmt").AsFloat = 12;
    lDetail.Post();
...
|}
|}
<div style="float: right;">  [[#top|[top]]]</div>


{| class="mw-collapsible mw-collapsed wikitable"
===How do my system know there is a changes or update in SQLAccounting?===
! Python 
'''Data Entry'''<br>
|-
: In all Document it had a field call <span style="color:#0000ff">UPDATECOUNT</span>.
|
: Default is null & each changes will +1.
    try:
: So if you see 2 meaning it had being update 2 times
        BizObject.Save()         
    except Exception as e:
        print("Oops!", e) 


|}
'''Master Data'''
: Only available in
:* Version 842.765 & above
:* AP_SUPPLIER (Maintain Supplier)
:* AR_CUSTOMER (Maintain Customer)
:* ST_GROUP (Maintain Stock Group)
:* ST_ITEM (Maintain Stock Item)
:* ST_ITEM_TPL (Maintain Item Template)
:* ST_PRICETAG (Maintain Price Tag)
:* TAX (Maintain Tax)
: In Each table it had a field call <span style="color:#0000ff">LASTMODIFIED</span>.
: The value is '''Epoch Time''' or '''Unix Time'''


You can use below function to get the field
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! VB.Net  
! vbs  
|-
|-
|  
|  
<syntaxhighlight lang="vb">
<syntaxhighlight lang="vbs">
Try
...
   BizObject.[New]
Function GetData
Dim lDataSet, lSQL
  lSQL = "SELECT DOCNO, UPDATECOUNT FROM SL_CS "
   lSQL = lSQL & "WHERE UPDATECOUNT IS NOT NULL "
  lSQL = lSQL & "ORDER BY DOCNO "
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
 
  lDataSet.First
  While (not lDataSet.eof)
    MsgBox "DocNo : " & lDataSet.FindField("DocNo").AsString
    MsgBox "UpdateCount : " & lDataSet.FindField("UPDATECOUNT").AsString
    lDataSet.Next
  Wend
End Function
...
...
  BizObject.Save
Catch ex As Exception
  MsgBox(ex.Message, MsgBoxStyle.Exclamation)
End Try
</syntaxhighlight>
</syntaxhighlight>
|}
|}


{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"
! Delphi  
! Delphi
|-
|-
|  
|  
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="delphi">
try
... 
   lBizObj.New;
procedure TfmMain.dxbb_GetFieldClick(Sender: TObject);
....
var BizApp : Variant;
  lBizObj.Save;
    lDataSet : TClientDataSet;
except
    ASQL : String;
   on E: Exception do
begin
     Memo1.Lines.Text := E.Message;
   BizApp := CreateOleObject('SQLAcc.BizApp');
  lDataSet := TClientDataSet.Create(Self);
  try
    ASQL := 'SELECT DOCNO, UPDATECOUNT FROM SL_CS ' +
            'WHERE UPDATECOUNT IS NOT NULL ' +
            'ORDER BY DOCNO ';
    lDataSet.Data := BizApp.DBManager.Execute(ASQL);
    lDataset.SaveToFile('C:\Temp\_List.xml', dfXML); //Export To XML file
   finally
     lDataSet.Free;
  end;
end;
end;
...
</syntaxhighlight>
</syntaxhighlight>
|}
<div style="float: right;">  [[#top|[top]]]</div>
===Can I control my Stock when I link with other Application?===
: Yes. We suggest to use Stock Transfer to (eg Location call <span style="color:#0000ff">MOBILE</span>) transfer stock as Reserve to avoid stock over deduct in SQL Accounting
: When other Application post to SQL Accounting they just need set the Location to the Reserve Location (eg <span style="color:#0000ff">MOBILE</span>)
: Below is example posting with location
{| class="mw-collapsible mw-collapsed wikitable"
! Post Location Field Script/Code 
|-
|
...
  lDtl.FindField('UOM').AsString      := 'CTN';
  lDtl.FindField('QTY').AsFloat        := 6;
  lDtl.FindField('Location').AsString  := 'MOBILE';
...
|}
|}


<div style="float: right;">  [[#top|[top]]]</div>


===Where to Check the SQL Accounting DCF Path, FileName & FDB FileName?===
: In Login Screen Click 3 Dot Button then you can see the information
: For SQL Accounting Version 5.2023.957.831 and below
[[File:SDK-FAQ-01.jpg|center]]
: For SQL Accounting Version 5.2023.958.832 and above
[[File:SDK-FAQ-03.jpg|800px|center]]
[[File:SDK-FAQ-02.jpg|554px|center]]
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


===Why Post to SQL Accounting sometime prompt Catastrophic failure Error?===
===How to check & What is the value for Advance Credit Control in Maintain Customer===
'''Possible Problem 1'''
: You can use <span style="color:#0000ff">ComServer.DBManager.NewDataSet(lSQL)</span> function to Query the information
: Make sure you code don't cross over Call action during posting
: lSQL = SELECT * FROM AR_CUSTOMERCRCTRL
: Eg Posing SL_SO Header partly then suddenly call other object example Check Customer Code Validity
: You may refer to <span style="color:#0000ff">ControlType</span> column
: Summary action (Correct Steps)
::01. Do Verify 1st (eg Check Customer Code Validity & etc)
::02. Post Transactions


'''Possible Problem 2'''
{| class="wikitable" style="margin: 1em auto 1em auto;"
:Keep Login & Logout till windows not enough time to response
|-
: Summary action (Correct Steps)
! ControlType !! Exceed Credit Limit !! Exceed OverDue Limit
::01. Pull Data from Your application/web
|-
::02. Login SQL Accounting 1 time (Auto Login)
| align="center" | 0 || UnBlock || UnBlock
::03. Do all your requirement actions (eg. verify, query & posting)
|-
::04. Logout SQL Accounting 1 time (Auto Logout)
| align="center" | 1 || UnBlock || Block
::05. Push Data to Your application/web (if any)
|-
 
| align="center" | 2|| UnBlock || Override
'''Possible Problem 3'''
|-
: Company Profile Logo format had problem.
| align="center" |  3|| Block || UnBlock
: Solution
|-
::01. Click File | Company Profile
| align="center" | 4|| Block || Block
::02. Export out the Logo by right Click the Company Logo
|-
::03. Open the Exported Logo with Photo Editor
| align="center" | 5|| Block || Override
::04. Just Click File | Save again as jpg.
|-
::05. Load Back the Save Logo by right Click the Company Logo
| align="center" | 6|| Override || UnBlock
::06. Click Save
|-
| align="center" | 7|| Override || Block
|-
| align="center" | 8|| Override || Override
|-
| align="center" | 9|| align="center" colspan="2"| Suspended
|}


<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


===How to Get the GL Account List for Sales & Purchase?===
===How to get Error/Exception Message Return from SQL Accounting?===
: You can use the function <span style="color:#0000ff">ComServer.DBManager.NewDataSet(lSQL)</span> with the following SQL
{| class="mw-collapsible mw-collapsed wikitable"
<pre>
! C Sharp 
SELECT Code, Description, Description2 FROM GL_ACC A
|-
WHERE (A.Parent<>-1
|
AND NOT (EXISTS (SELECT Parent FROM GL_ACC B
<syntaxhighlight lang="C#">
                WHERE A.DocKey=B.Parent))
try
AND (A.SpecialAccType IS NULL OR A.SpecialAccType IN ('', 'AD')))
{
ORDER BY Code
  BizObject.New();
</pre>
....
<div style="float: right;">  [[#top|[top]]]</div>
  BizObject.Save();
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
</syntaxhighlight>
|}
 
{| class="mw-collapsible mw-collapsed wikitable"
! Python  
|-
|
    try:
        BizObject.Save()         
    except Exception as e:
        print("Oops!", e) 
 
|}
 
{| class="mw-collapsible mw-collapsed wikitable"
! VB.Net 
|-
|
<syntaxhighlight lang="vb">
Try
  BizObject.[New]
...
  BizObject.Save
Catch ex As Exception
  MsgBox(ex.Message, MsgBoxStyle.Exclamation)
End Try
</syntaxhighlight>
|}
 
{| class="mw-collapsible mw-collapsed wikitable"
! Delphi
|-
|
<syntaxhighlight lang="delphi">
try
   lBizObj.New;
....
  lBizObj.Save;
except
  on E: Exception do
    Memo1.Lines.Text := E.Message;
end;
</syntaxhighlight>
|}


===Can I setup a testing/Staging environment for SQL Accounting?===
:Yes can, you can self setup or we can help you to setup.
:There are 4 types of Testing/Staging
:01. Install the Testing SQL Accounting version & Testing Database in the developer PC
:02. Install the Live SQL Accounting version & User Backup Database in the developer PC
::- Require User Permission for Backup
:03. Setup at User PC/Server & using User Backup Database
::- Require User Permission for Backup & PC/Server setup
:04. Setup at User PC/Server & using Testing Database
::- Require User Permission for PC/Server setup


<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>


===How to Loop & post SQL Accounting?===
===Why Post to SQL Accounting sometime prompt Catastrophic failure Error?===
'''Possible Problem 1'''
: Make sure you code don't cross over Call action during posting
: Eg Posing SL_SO Header partly then suddenly call other object example Check Customer Code Validity
: Summary action (Correct Steps)
::01. Do Verify 1st (eg Check Customer Code Validity & etc)
::02. Post Transactions
 
'''Possible Problem 2'''
:Keep Login & Logout till windows not enough time to response
: Summary action (Correct Steps)
::01. Pull Data from Your application/web
::02. Login SQL Accounting 1 time (Auto Login)
::03. Do all your requirement actions (eg. verify, query & posting)
<pre>
    eg Posting Cash Sales & Customer Payment
begin looping
  BizObject = ComServer.BizObjects.Find("SL_CS")
  ....
  BizObject.Save
  BizObject.Close
  FreeBiz(BizObject)
 
  BizObject = ComServer.BizObjects.Find("AR_PM")
  ....
  BizObject.Save
  BizObject.Close
  FreeBiz(BizObject)
 
  Next Record
End looping
</pre>
::04. Logout SQL Accounting 1 time (Auto Logout)
::05. Push Data to Your application/web (if any)
 
'''Possible Problem 3'''
: Company Profile Logo format had problem.
: Solution
::01. Click File | Company Profile
::02. Export out the Logo by right Click the Company Logo
::03. Open the Exported Logo with Photo Editor
::04. Just Click File | Save again as jpg.
::05. Load Back the Save Logo by right Click the Company Logo
::06. Click Save
 
<div style="float: right;">  [[#top|[top]]]</div>
 
===How to Get the GL Account List for Sales & Purchase?===
: You can use the function <span style="color:#0000ff">ComServer.DBManager.NewDataSet(lSQL)</span> with the following SQL
<pre>
SELECT  Code, Description, Description2 FROM GL_ACC A
WHERE (A.Parent<>-1
AND NOT (EXISTS (SELECT Parent FROM GL_ACC B
                WHERE A.DocKey=B.Parent))
AND (A.SpecialAccType IS NULL OR A.SpecialAccType IN ('', 'AD')))
ORDER BY Code
</pre>
<div style="float: right;">  [[#top|[top]]]</div>
 
===Can I setup a testing/Staging environment for SQL Accounting?===
:Yes can, you can self setup or we can help you to setup.
:There are 4 types of Testing/Staging
:01. Install the Testing SQL Accounting version & Testing Database in the developer PC
:02. Install the Live SQL Accounting version & User Backup Database in the developer PC
::- Require User Permission for Backup
:03. Setup at User PC/Server & using User Backup Database
::- Require User Permission for Backup & PC/Server setup
:04. Setup at User PC/Server & using Testing Database
::- Require User Permission for PC/Server setup
 
<div style="float: right;">  [[#top|[top]]]</div>
 
===How to Loop & post SQL Accounting?===
:Below summary how to loop
:Below summary how to loop
:01. Call ComServer
:01. Call ComServer
Line 10,899: Line 12,592:
:09. Free ComServer
:09. Free ComServer


<div style="float: right;">  [[#top|[top]]]</div>
===How to post Description3 with Unicode?===
:You have to convert it to rtf format before set to Description3 field
{| class="mw-collapsible mw-collapsed wikitable"
! C Sharp 
|-
|
<pre>
private static string FormatAsRTF(string DirtyText)
{
    System.Windows.Forms.RichTextBox rtf = new System.Windows.Forms.RichTextBox();
    rtf.Text = DirtyText;
    return rtf.Rtf;
}
....
lDtl.FindField("DESCRIPTION3").AsString  = FormatAsRTF("ANTENNA ???");
...
</pre>
|}
{| class="mw-collapsible mw-collapsed wikitable"
! VB.Net 
|-
|
<pre>
Private Shared Function FormatAsRTF(ByVal DirtyText As String) As String
    Dim rtf As System.Windows.Forms.RichTextBox = New System.Windows.Forms.RichTextBox()
    rtf.Text = DirtyText
    Return rtf.Rtf
End Function
....
lDtl.FindField("DESCRIPTION3").AsString  = FormatAsRTF("ANTENNA ???")
...
</pre>
|}
{| class="mw-collapsible mw-collapsed wikitable"
! Delphi
|-
|
<pre>
function TfmMain.PlainTxtToRTF(const AValue:String):String;
var R:TRichEdit;
    M : TStringStream;
begin
  R := TRichEdit.CreateParented(HWND_MESSAGE);
  M := TStringStream.Create('');
  try
    R.WordWrap := False;
    R.Lines.Add(AValue);
    R.Lines.SaveToStream(M);
    Result := M.DataString;
  finally
    R.Free;
    M.Free;
  end;
end;
....
lDtl.FindField('DESCRIPTION3').AsString  := PlainTxtToRTF('ANTENNA ???');
...
</pre>
|}
:or Can use our build in Utility function (only available from 5.2022.941.822 & above)
<pre>
....
lDtl.FindField("Description3").AsString = ComServer.Utility.PlainTextToRichText("ANTENNA ??? ??")
...
</pre>
{| class="mw-collapsible mw-collapsed wikitable"
! PHP 
|-
|
<pre>
<!DOCTYPE html>
<html>
<body>
<h1>SQL Acc SDK in PHP page</h1>
<?php
echo "Updated 14 Sep 2022<br>";
#This action to show & post Description3 with unicode
$ComServer = null;
function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp", null, CP_UTF8) or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();
    if ($status == true)
    {
        #$ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0082.FDB"); #Database Name
   
}
function GetData(){
    global $ComServer;
    $lSQL = "SELECT Description3 FROM ST_ITEM
    WHERE Code='ANT' ";
    $lDataSet = $ComServer->DBManager->NewDataSet($lSQL);
    if ($lDataSet->RecordCount > 0) {
$lDataSet->First();
$rtf = $lDataSet->FindField('Description3')->AsString();
        echo $rtf;
echo "<br>== <br>";
echo "<br>Result after RTF: <br>";
$txt = $ComServer->Utility->RichTextToPlainText($rtf);
echo "<TEXTAREA rows=10 cols=80 id='edResult1' >".$txt. "</TEXTAREA>";
echo "<br>== <br>";
echo "??? ??";
}else {
    echo "Record Not Found";
    }
}
function PostData(){
global $ComServer;
$BizObject = $ComServer->BizObjects->Find("ST_AJ");
    $lMain = $BizObject->DataSets->Find("MainDataSet");
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail");
    $BizObject->New();
    $lMain->FindField("DocKey")->value = -1;
    $lMain->FindField("DocNo")->AsString = "<<New>>";
    $lMain->FindField("DocDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("PostDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("Description")->AsString = "Stock Adjustment";
    #Insert Data - Detail - Increase Stock Qty
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 1;
    $lDetail->FindField("ItemCode")->AsString = "ANT";
    $lDetail->FindField("Description")->AsString = "Sales Item B";
    $lDetail->FindField("Qty")->AsFloat = 2;
    $lDetail->FindField("UOM")->AsString = "UNIT";
    $lDetail->Post();
    #Insert Data - Detail - Reduce Stock Qty
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 2;
    $lDetail->FindField("ItemCode")->AsString = "ANT";
    $lDetail->FindField("Description")->AsString = "NOKIA CHARGER  ???";
$lDetail->FindField("Description3")->AsString = $ComServer->Utility->PlainTextToRichText("NOKIA CHARGER ??? ??");
    $lDetail->FindField("Qty")->AsFloat = -5;
    $lDetail->FindField("UOM")->AsString = "UNIT";
    $lDetail->Post();
    $BizObject->Save();
    $BizObject->Close();
try{
        $BizObject->Save();
        $BizObject->Close();
}catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
    }
}
if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
        GetData();
echo "<br>";
        echo date("d M Y h:i:s A")." - Done";
PostData();
echo "<br>";
        echo date("d M Y h:i:s A")." - Done ST_AJ";
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}
?>
    <form method="post">         
        <input type="submit" name="BtnData"
                value="Get RTF n Post RTF"/>
    </form>
</body>
</html>
</pre>
|}
<div style="float: right;">  [[#top|[top]]]</div>
<div style="float: right;">  [[#top|[top]]]</div>



Latest revision as of 09:54, 26 April 2024

Introduction

This is the "Bridge" direct live linking between External Program with SQL Accounting

Pros

  1. Can Live or Batch Update.
  2. Can do action such as New, Edit & Delete.
  3. About 95% of modules is covered.
  4. Can direct Retrieve/Get Information From Connected Database.
  5. Able to do Automation (i.e. auto login & update data).
  6. Support GST & SST.
  7. Free of Charge (Freeware) for End User on SDK Linking.

Cons

  1. Must had programming knowledge.
  2. Must had SQL Accounting installed & running.
  3. Must self do checking else error prompt will unable to “capture”.
  4. Only supported in IE for JScript

Requirement

  • Microsoft Windows 8.1 and above (recommended with 64 bits windows)
  • Intel i5, i7 and above computer.
  • 8 GB of RAM (recommended 12 GB and above).
  • Firebird (For Automatic Login & Logout Only)
  • SQL Accounting
  • Windows Scheduler (For Automatic Login & Logout Only)

Documentation

Linking Flow

  • Highlight in Yellow Color is the Windows base Application/Function you need to Develop/Create.

Example 1 - POS System

LinkFlow-Example01.jpg

Example 2 - Cloud/Mobile System

LinkFlow-Example02.jpg
  • The SDK can be build in in your system or a Standalone windows Application(Middle Application).
  • If you build in your system then it can be sync anytime either by a special interface with parameter (eg Date From, Date To & etc) or each transaction after post(not recommended)
  • If you create a Standalone windows Application(Middle Application) you can make use the Windows Schedule to sync or call from you system to execute/run the Standalone windows Application(Middle Application).

Steps

CHM File

  1. Install SQL Accounting Click here
  2. Create Sample Data
  3. Login (username & password is Admin)
  4. Double click the SQLSDK.chm file
  5. Click Application Object | Business Objects
  6. Click the word "here"
  7. Click Yes
  8. In the list Look for (example)
- AR_IV -> Customer Invoice
- AR_CN -> Customer Credit Note
- AP_PI -> Supplier Invoice
- SL_IV -> Sales Invoice
- PH_PI -> Purchase Invoice
- ST_AJ -> Stock Adjustment

External Application Linking

  1. Login SQL Accounting
  2. Login External Application
  3. Click Post to SQL Accounting button or Click Save button from External Application.
----------------------------------------------------------------------------------------------------------------------------------------------------
Template.Tips-01.jpg
Can try start with Add Agent under the SDK file to make sure you
Application can communicate with SQL Accounting
----------------------------------------------------------------------------------------------------------------------------------------------------

Available Programming Language

Example External Program

VB. Net

C Sharp

Steps (C Sharp & VB.Net Only)

The example video is how to

01. Open DCF in D:\Happy\DB\Default.DCF
02. Datatabase is ACC-0008.FDB
03. Click Complete Post button
04. Where to check in SQL accounting after Post (Steps-2.gif)

Available Function

- Complete Post - SL_CS, SL_CN, AR_PM, AR_CN & AR_CF
- Batch Post - Cash Sales - SL_CS
- Batch Post...2 DB
- Batch Post...2 DCF
- Add Stock Assembly with Override Raw Materials - ST_AS
- Add Stock Job Order to Stock Assembly with Override Raw Materials - PD_JO & ST_AS
- Add Agent - Agent
- Get Agent Description
- Add Journal Voucher - Add GL JE
- Edit GL Journal Voucher - Edit GL_JE
- Edit Sales Cash Sales - SL_CS
- Delete Cash Sales - Del SL CS - SL_CS
- Customer Aging - Customer.Aging.RO
- Get Sales Invoice Listing - Sales.IV.RO
- Stock Item List
- Add SKU with Edit SKU - ST_ITEM
- Del SKU - ST_ITEM
- Get DCF Database List
- Month End - FIFO
- Month End - WA (Weighted Average)
- Get Options...(Perform Tax / Local Amount Rounding, 5 Cents Rounding (Sales Invoice) & 5 Cents Rounding (Cash Sales)
- Get Next Invoice No.
- Is Valid ST_Item
- Is Valid GL_Acc
- Outstanding SO - Sales.OutstandingSO.RO
- Read RTF n Picture Data...
- Get Customer List - AR_Customer
- Add Customer with Edit Customer - AR_Customer
- Del Customer - AR_Customer
- Add GL Payment Voucher - Add GL_PV
- Transfer Document - DO to SL_IV
- Get Transfer Info. 1 - At Invoice Find DO Number & Date
- Get Transfer Info. 2 - At DO Find Invoice Number & Date
- GL Ledger
- Add Stock Transfer - Add ST XF
- Add Stock Adjustment - Add ST AJ
- Get Serial Number Balance - Serial No. Bal.
- Add Customer Deposit - Deposit
- Transfer Customer Deposit to Payment - Deposit to PM
- Refund Deposit - Deposit Refund
- Forfeit Deposit - Deposit Forfeit
- Enable Support DocNo Format with Month & Year Format
- Add AR IV
- Add AR CN
- Add AR PM Bounce Chq
- Add GL Ledger RO
- AR Statement
- Add Add/Edit AR PM
- Add LogInOut (For Testing purpose)

History - C Sharp & VB.Net

19 Aug 2023...
- Add Add/Edit AR PM
- Add LogInOut (For Testing purpose)
14 Jun 2022
- Add AR Statement
- Fix Error when click 2nd time for Report.
27 Apr 2022
- Add/Edit Location
- Rename Caption for Add Customer to Add/Edit Cust
- Rename Caption for Add Agent to Add/Edit Agent
- Add Reconnect
- Add/Edit ST_Batch
- Fix bug on KillApp should Sleep 2 seconds after run the KillApp
18 Mar 2021
- Enable Support DocNo Format with Month & Year Format
- Add AR IV
- Add AR CN
- Add AR PM Bounce Chq
- Add GL Ledger RO
22 May 2020
- Fix Complete Post Action cause SQLAcc still not exit after logout
- Add/Edit Customer Contra
28 Mar 2020
- SL DO to SL IV button - Check Transfer Status should excluded Cancelled
- Add Get Transfer Info. 1 - At Invoice Find DO Number & Date
- Add Get Transfer Info. 2 - At DO Find Invoice Number & Date
04 Mar 2020
- Add Post with Serial Number for Complete Post
- Fix Posting Seq Error on Complete Post
- Add GL JE
- Add GL_PV
- Add Additional Note for Outstanding SO button
05 Feb 2020
- Add Customer Deposit
- Add Customer Deposit to PM
- Add Customer Deposit Refund
- Add Customer Deposit Forfeit
- Add SL DO to SL IV
- Add 12 Months Aging Parameter for Customer.Aging.RO
- Add Add ST AJ - Stock Adjustment
- Add Add ST XF - Stock Transfer
22 Oct 2019
- Add GL Ledger function
- Add Cust. IV Listing function
- Add Serial No. Bal function
- Fixed Error on Auto Logout Error when using ComServer.DBManager.NewDataSet(lSQL)
23 Aug 2019
- Add Del SKU function
- Add Customer List... function
- Add Add Customer function
- Add Del Customer function
- Add Del SL CS function
31 Jul 2019
- Add Read RTF n Picture Data... function.
10 Jul 2019
- Fixed KillApp function not working in some situation.
11 Jun 2019
- Fixed Auto Logout Prompt Error.
- Fixed SQLAcc not Fully Exit when Call Auto Logout.
- Fixed Batch Post 2 DB error for CSharp
06 Jun 2019
- Fixed unable to Update Stock Item for Add SKU.
- Add Update UOM for Add SKU.
- Add C Sharp Coding
23 May 2019
- Update Complete Post - Add Description3 (More Description)
- Fixed Batch Post.. keep login when looping
- Add Get Outstanding SO - Sales.OutstandingSO.RO
05 May 2019
- Add Condition for Stock Item List only filter if edCode is not empty
- Add Prompt Message If Login Fail
- Add SQLAcc Build No Condition for Get Sales Invoice Listing to support version 776 & above
- Add SKU - ST_ITEM



ASP.Net C Sharp

01. Make sure Enabled the following function in IIS Manager - Sites - YourSiteName - Authentication

- Anonymous Authentication
- ASP.Net Impersonation (Make sure set Specific user (Windows Login User & Password))

02 Make sure the Windows user set in ASP.Net Impersonation is Login

Available Function

- Get Agent Description
- New & Update Customer/Supplier Info.
- Edit Cash Sales
- Edit Purchase Invoice
- Complete Post
- GL PV
- Add Add/Edit Agent
- Add Add/Edit Terms
- Add Add/Edit ST Item
- Delete Cash Sales
- Add SL SO

History

16 Aug 2021
- Add SL SO
19 Feb 2021
- Delete Cash Sales
16 Sep 2020
- Add Add/Edit ST Item
- Fix some comment note error
23 Jun 2020
- Add Add/Edit Agent
- Add Add/Edit Terms
22 May 2020
- Add Edit Purchase Invoice
- Add Complete Post
- Add GL PV
06 Dec 2019
- Add Edit Cash Sales
- Enable Run Time Set User Name, Password, DCF & FDB


Python

Module Require in Python
- pypiwin32 (Mandatory) -> pip install pypiwin32
- Pillow (Optional for Picture) -> pip install Pillow

Common

  • Common.py file for example code
Common Function
#Updated 03 Oct 2023
import win32com.client
import Common
import os
from time import sleep

ComServer = win32com.client.Dispatch("SQLAcc.BizApp")

def KillApp():
    os.system('cmd /c "taskkill /IM "SQLACC.exe" /F"')
    sleep(2) #sleep 2 sec


def CheckLogin():
    global ComServer
    ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
    B = ComServer.IsLogin
    if B == True:
        ComServer.Logout()
        KillApp()
 
    ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
    try:    
        ComServer.Login("ADMIN", "ADMIN", #UserName, Password
                        "D:\\Happy\\DB\\Default.DCF",
                        #"C:\\eStream\\SQLAccounting\\Share\\Default.DCF",  #DCF file
                        "ACC-0015.FDB") #Database Name
    except Exception as e:
        print("Oops !", e)


def ShowResult(ADataset):
    if ADataset.RecordCount > 0:
        while not ADataset.eof:
            fc = ADataset.Fields.Count
            for x in range(fc):
                fn = ADataset.Fields.Items(x).FieldName
                fv = ADataset.FindField(fn).AsString
                lresult = "Index : "+ str(x) + " FieldName : " + fn + " Value : " + fv
                print (lresult)
            print("====")
            ADataset.Next()
    else:
        print ("Record Not Found")
        
        
def QuotedStr(ACode):
    return "'" + ACode.replace("'", "''") + "'"

Agent

Agent Script
#Updated 22 Jul 2023
import Common
       
def GetListData():
    lSQL = "SELECT * FROM AGENT "
    lSQL = lSQL + "WHERE ISACTIVE='T' "
    lSQL = lSQL + "ORDER BY CODE "
    
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
        
    Common.ShowResult(lDataSet)

def PostData():
    BizObject = ComServer.BizObjects.Find("Agent")
    lMain = BizObject.DataSets.Find("MainDataSet")    
    
    lDocKey = BizObject.FindKeyByRef("CODE", "FAIRY")
        
    if lDocKey is None:
        BizObject.New()
        lMain.FindField("CODE").value = "FAIRY"
        lMain.FindField("DESCRIPTION").value = "FAIRY TAIL"

    else:
        BizObject.Params.Find("Code").Value = lDocKey
        BizObject.Open()
        BizObject.Edit()
        lMain.FindField("DESCRIPTION").value = "FAIRY TAIL WIZARD"
            
    try:
        BizObject.Save()          
    except Exception as e:
        print("Oops!", e)    
    BizObject.Close()
    print ("Posting/Update Done")

def DelData():
    #Deleting only work if the record never use in other document
    BizObject = ComServer.BizObjects.Find("Agent")
    
    lDocKey = BizObject.FindKeyByRef("CODE", "FAIRY")
        
    if lDocKey is None:
        print ("Record Not Found")
    else:
        BizObject.Params.Find("CODE").Value = lDocKey
        BizObject.Open()
        BizObject.Delete()        
        print ("Deleting Done")

try:
    Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
    GetListData()
    PostData()
    
    answer = input("Continue To delete?")
    if answer.lower() in ["y","yes"]:
        DelData()
    elif answer.lower() in ["n","no"]:
        print ("Deleting Aborted")
    else:
       print ("Invalid Input")

    ComServer.Logout()
finally:
    ComServer = None
    Common.KillApp()

Get Company Profile

Get Company Profile
#Updated 22 Jul 2023
import Common

def GetData():
    lSQL = "SELECT COMPANYNAME, REMARK, BRN, BRN2, GSTNO, "
    lSQL = lSQL + "SALESTAXNO, SERVICETAXNO, "
    lSQL = lSQL + "ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS4 FROM SY_PROFILE "
    
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
    
    Common.ShowResult(lDataSet)
    
try:
    Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer       
    GetData()
    ComServer.Logout()
finally:
    ComServer = None
    Common.KillApp()

Complete Post

SL_CS, AR_PM, SL_CN & AR_CN Script
#Updated 19 Jul 2023
#This will doing following posting
#01. Cash Sales
#02. Sales Credit Note
#03. Customer Payment With Knock off
#04. Edit Credit Note Posted in Step 02 & Knock Off
#05. Customer Refund to Knock off Credit Note
import Common
import datetime

def PostDataCS():    
    BizObject = ComServer.BizObjects.Find("SL_CS")
    lMain = BizObject.DataSets.Find("MainDataSet") #lMain contains master data
    lDetail = BizObject.DataSets.Find("cdsDocDetail") #lDetail contains detail data
    
    lDate = datetime.datetime(2023, 2, 22, 13, 0)
    lDate.strftime('%m/%d/%Y')
    
    BizObject.New();
    lMain.FindField("DocNo").AsString = "--IV Test--"
    lMain.FindField("DocDate").value = lDate
    lMain.FindField("PostDate").value = lDate
    lMain.FindField("Code").AsString = "300-C0001" #Customer Account
    lMain.FindField("CompanyName").AsString = "Cash Sales"
    lMain.FindField("Address1").AsString = "" #Optional
    lMain.FindField("Address2").AsString = "" #Optional
    lMain.FindField("Address3").AsString = "" #Optional
    lMain.FindField("Address4").AsString = "" #Optional
    lMain.FindField("Phone1").AsString = ""   #Optional
    lMain.FindField("Description").AsString = "Sales"

    #Insert Data - Detail
    #For Tax Inclusive = True with override Tax Amount
    lDetail.Append()
    lDetail.FindField("Seq").value = 1
    lDetail.FindField("Account").AsString = "500-000" #Sales Account
    lDetail.FindField("Description").AsString = "Sales Item A"
    lDetail.FindField("Description3").AsString = ("Item A Line 1" + ("\r" + "Item A Line 2"))
    lDetail.FindField("Qty").AsFloat = 1
    lDetail.FindField("Tax").AsString = "SV"
    lDetail.FindField("TaxRate").AsString = "6%"
    lDetail.FindField("TaxInclusive").value = 0
    lDetail.FindField("UnitPrice").AsFloat = 435
    lDetail.FindField("Amount").AsFloat = 410.37 #Exclding GST Amt
    lDetail.FindField("TaxAmt").AsFloat = 24.63

    lDetail.DisableControls()
    lDetail.FindField("TaxInclusive").value = 1
    lDetail.EnableControls()
    
    lDetail.Post()

    #For Tax Inclusive = False with override Tax Amount
    lDetail.Append()
    lDetail.FindField("Seq").value = 2
    lDetail.FindField("Account").AsString = "500-000"
    lDetail.FindField("Description").AsString = "Sales Item B"
    lDetail.FindField("Qty").AsFloat = 1
    lDetail.FindField("Tax").AsString = "SV"
    lDetail.FindField("TaxRate").AsString = "6%"
    lDetail.FindField("TaxInclusive").value = 0
    lDetail.FindField("UnitPrice").AsFloat = 94.43
    lDetail.FindField("Amount").AsFloat = 94.43
    lDetail.FindField("TaxAmt").AsFloat = 5.66
    lDetail.Post()
    
    #For With Item Code
    lDetail.Append()
    lDetail.FindField("Seq").value = 3
    lDetail.FindField("ItemCode").AsString = "ANT"
    lDetail.FindField("Description").AsString = "Sales Item B"
    #lDetail.FindField("Account").AsString     = "500-000" #If you wanted override the Sales Account Code
    lDetail.FindField("Qty").AsFloat = 2
    lDetail.FindField("UOM").AsString = "UNIT"
    #lDetail.FindField("DISC").AsString        = "5%+3" #Optional(eg 5% plus 3 Discount)
    lDetail.FindField("Tax").AsString = "SV"
    lDetail.FindField("TaxRate").AsString = "6%"
    lDetail.FindField("TaxInclusive").value = 0
    lDetail.FindField("UnitPrice").AsFloat = 100
    lDetail.FindField("Amount").AsFloat = 200
    lDetail.FindField("TaxAmt").AsFloat = 12
    lDetail.Post()    
    
    BizObject.Save()
    BizObject.Close()

def PostDataPM():       
    BizObject = ComServer.BizObjects.Find("AR_PM")
    lMain = BizObject.DataSets.Find("MainDataSet") #lMain contains master data
    lDetail = BizObject.DataSets.Find("cdsKnockOff") #lDetail contains detail data
    
    lDate = datetime.datetime(2023, 2, 22, 13, 0)
    lDate.strftime('%m/%d/%Y')
    
    BizObject.New()
    lMain.FindField("DocNo").AsString = "--PM Test--"
    lMain.FindField("CODE").AsString = "300-C0001" #Customer Account
    lMain.FindField("DocDate").Value = lDate
    lMain.FindField("PostDate").Value = lDate
    lMain.FindField("Description").AsString = "Payment for A/c"
    lMain.FindField("PaymentMethod").AsString = "320-000" #Bank or Cash Account
    lMain.FindField("ChequeNumber").AsString = ""
    lMain.FindField("BankCharge").AsFloat = 0
    lMain.FindField("DocAmt").AsFloat = 200.00
    lMain.FindField("Cancelled").AsString = "F"    
    
    #Knock Off IV  
    V = ["IV", "--IV Test--"]  #DocType, DocNo
    
    if (lDetail.Locate("DocType;DocNo", V, False, False)) :
        lDetail.Edit()
        lDetail.FindField("KOAmt").AsFloat = 147.09 #Partial Knock off
        lDetail.FindField("KnockOff").AsString = "T"
        lDetail.Post()
        
    BizObject.Save()
    BizObject.Close()
    
def PostDataCN():   
    BizObject = ComServer.BizObjects.Find("SL_CN")
    lMain = BizObject.DataSets.Find("MainDataSet") #lMain contains master data
    lDetail = BizObject.DataSets.Find("cdsDocDetail") #lDetail contains detail data
    
    lDate = datetime.datetime(2023, 2, 22, 13, 0)
    lDate.strftime('%m/%d/%Y')
    
    BizObject.New()
    lMain.FindField("DocNo").AsString = "--CN Test--"
    lMain.FindField("DocDate").value = lDate
    lMain.FindField("PostDate").value = lDate
    lMain.FindField("Code").AsString = "300-C0001"
    lMain.FindField("CompanyName").AsString = "Cash Sales"
    lMain.FindField("Address1").AsString = ""
    lMain.FindField("Address2").AsString = ""
    lMain.FindField("Address3").AsString = ""
    lMain.FindField("Address4").AsString = ""
    lMain.FindField("Phone1").AsString = ""
    lMain.FindField("Description").AsString = "Sales Returned"

    #For With Item Code
    lDetail.Append()
    lDetail.FindField("ItemCode").AsString = "ANT"
    lDetail.FindField("Description").AsString = "Sales Item B"
    lDetail.FindField("Description2").AsString = "Product Spoil" #Reason
    lDetail.FindField("Remark1").AsString = "--IV Test--"   #Invoice No
    lDetail.FindField("Remark2").AsString = "01 Jan 2017"   #Invoice Date
    lDetail.FindField("Qty").AsFloat = 1
    lDetail.FindField("Tax").AsString = "SV"
    lDetail.FindField("TaxRate").AsString = "6%"
    lDetail.FindField("TaxInclusive").value = 0
    lDetail.FindField("UnitPrice").AsFloat = 100
    lDetail.FindField("Amount").AsFloat = 100
    lDetail.FindField("TaxAmt").AsFloat = 6
    lDetail.Post()

    #Save Document
    BizObject.Save()
    BizObject.Close()    
    
def PostKnockIVCN():
    BizObject = ComServer.BizObjects.Find("AR_CN")
    lMain = BizObject.DataSets.Find("MainDataSet")
    lDetail = BizObject.DataSets.Find("cdsKnockOff")
    
    #Find CN Number
    lDocNo = "--CN Test--"
    lDocKey = BizObject.FindKeyByRef("DocNo", lDocNo)
    BizObject.Params.Find("DocKey").Value = lDocKey
    
    if lDocKey is not None:
        BizObject.Open()
        BizObject.Edit()
        lMain.Edit()
        
        #Knock Off IV        
        V = ["IV", "--IV Test--"]  #DocType, DocNo
        
        if (lDetail.Locate("DocType;DocNo", V, False, False)) :
            lDetail.Edit()
            lDetail.FindField("KOAmt").AsFloat = 100 #Partial Knock off
            lDetail.FindField("KnockOff").AsString = "T"
            lDetail.Post()
        
    BizObject.Save()
    BizObject.Close()        

def PostDataCF():       
    BizObject = ComServer.BizObjects.Find("AR_CF")
    lMain = BizObject.DataSets.Find("MainDataSet") #lMain contains master data
    lDetail = BizObject.DataSets.Find("cdsKnockOff") #lDetail contains detail data
    
    lDate = datetime.datetime(2023, 2, 22, 13, 0)
    lDate.strftime('%m/%d/%Y')
    
    BizObject.New()
    lMain.FindField("DocNo").AsString = "--CF Test--"
    lMain.FindField("CODE").AsString = "300-C0001" #Customer Account
    lMain.FindField("DocDate").Value = lDate
    lMain.FindField("PostDate").Value = lDate
    lMain.FindField("Description").AsString = "Payment for A/c"
    lMain.FindField("PaymentMethod").AsString = "320-000" #Bank or Cash Account
    lMain.FindField("ChequeNumber").AsString = ""
    lMain.FindField("BankCharge").AsFloat = 0
    lMain.FindField("DocAmt").AsFloat = 6
    lMain.FindField("Cancelled").AsString = "F"    
    
    #Knock Off Credit Note  
    V = ["CN", "--CN Test--"]  #DocType, DocNo
    
    if (lDetail.Locate("DocType;DocNo", V, False, False)) :
        lDetail.Edit()
        lDetail.FindField("KOAmt").AsFloat = 4 #Partial Knock off
        lDetail.FindField("KnockOff").AsString = "T"
        lDetail.Post()
        
    BizObject.Save()
    BizObject.Close()

try:
    Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
    print ("Posting Cash Sales")
    PostDataCS()
    print ("Posting Payment")
    PostDataPM()
    print ("Posting Sales CN")
    PostDataCN()
    print ("Posting Knock Off CN")
    PostKnockIVCN()
    print ("Posting Customer Refund")
    PostDataCF()
    print ("Done")
    ComServer.Logout()
finally:
    ComServer = None
    Common.KillApp()

Get Picture & Description3(Rich Text)

Get Picture & Description3(Rich Text) Script
#Updated 02 Aug 2023
import os, sys
import Common
from io import BytesIO
from PIL import Image

def GetData():
    lSQL = "SELECT Description3, Picture FROM ST_ITEM "
    lSQL = lSQL + "WHERE Code='ANT' "
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)

    imgdata = BytesIO(lDataSet.FindField('Picture').Value)
    dt = Image.open(imgdata)
    dt.save("test.jpg")
    print ("Done Export Picture file...")
    #print (lDataSet.FindField('Picture').Value)
    
    rtf = lDataSet.FindField('Description3').AsString
    print (rtf)
    
    with open('out.rtf', 'w') as output:
        output.write(rtf)
        output.close()
    print ("Done Export RTF file...")
    
    txt = ComServer.Utility.RichTextToPlainText(rtf)
    print (txt)
    
try:
    Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer    
    GetData()
    ComServer.Logout()
finally:    
    ComServer = None
    Common.KillApp()

Get Invoice Next Number

Get Invoice Next Number Script
#Updated 19 Jul 2023
import Common

def GetData():
    lSQL = "SELECT A.*, B.NEXTNUMBER FROM SY_DOCNO A "
    lSQL = lSQL + "INNER JOIN SY_DOCNO_DTL B ON (A.DOCKEY=B.PARENTKEY) "
    lSQL = lSQL + "WHERE A.DOCTYPE='IV' "
    lSQL = lSQL + "AND A.DESCRIPTION='Customer Invoice' "
    lSQL = lSQL + "AND A.STATESET=1 "
    
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
    
    fmt = lDataSet.FindField('Format').AsString
    NextNo = lDataSet.FindField('NEXTNUMBER').AsFloat
    print (fmt % NextNo)
    
try:
    Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer       
    GetData()
    ComServer.Logout()
finally:
    ComServer = None
    Common.KillApp()

Stock Item

Stock Item Script
#Updated 21 Dec 2023
import Common
       
def GetListData():
    lSQL = "SELECT A.*, B.UOM, B.RATE, B.REFCOST, B.REFPRICE, B.ISBASE FROM ST_ITEM A "
    lSQL = lSQL + "INNER JOIN ST_ITEM_UOM B ON (A.CODE=B.CODE) "
    lSQL = lSQL + "WHERE A.ISACTIVE='T' "
    lSQL = lSQL + "ORDER BY A.CODE, B.RATE" 
    
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
        
    Common.ShowResult(lDataSet)

def PostData():
    BizObject = ComServer.BizObjects.Find("ST_ITEM")
    lMain = BizObject.DataSets.Find("MainDataSet")
    lDtl = BizObject.DataSets.Find("cdsUOM")
    LBar = BizObject.DataSets.Find("cdsBarcode")
    
    lDocKey = BizObject.FindKeyByRef("CODE", "FAIRY")
        
    if lDocKey is None:
        BizObject.New()
        lMain.FindField("CODE").value = "FAIRY"
        lMain.FindField("DESCRIPTION").value = "FAIRY TAIL"
        lMain.FindField("STOCKGROUP").value = "DEFAULT";
        lMain.FindField("STOCKCONTROL").value = "T";
        lMain.FindField("ISACTIVE").value = "T";

        lDtl.Edit() #For 1St UOM
        lDtl.FindField("UOM").AsString = "PCS"
        lDtl.FindField("Rate").AsFloat = 1
        lDtl.FindField("RefCost").AsFloat = 10.2
        lDtl.FindField("RefPrice").AsFloat = 25
        lDtl.Post()

        lDtl.Append() #For 2nd UOM
        lDtl.FindField("UOM").AsString = "CTN"
        lDtl.FindField("Rate").AsFloat = 12
        lDtl.FindField("RefCost").AsFloat = 102
        lDtl.FindField("RefPrice").AsFloat = 240
        lDtl.Post()
        
        LBar.Append() #For 1St UOM Barcode
        LBar.FindField("Barcode").AsString = "123456"
        LBar.FindField("UOM").AsString = "PCS"
        LBar.Post()

        LBar.Append() #For 2nd UOM Barcode
        LBar.FindField("Barcode").AsString = "7890123"
        LBar.FindField("UOM").AsString = "CTN"
        LBar.Post()
    else:
        BizObject.Params.Find("Dockey").Value = lDocKey
        BizObject.Open()
        BizObject.Edit()
        lMain.FindField("DESCRIPTION").value = "FAIRY TAIL WIZARD"
        
        while lDtl.RecordCount > 0:
            lDtl.First()
            lDtl.Delete()

        #Insert back with new Price
        lDtl.Append() #For 1St UOM
        lDtl.FindField("UOM").AsString = "PCS" #Make sure this always same as b4 delete data
        lDtl.FindField("Rate").AsFloat = 1     #Make sure this always same as b4 delete data
        lDtl.FindField("RefCost").AsFloat = 22.3
        lDtl.FindField("RefPrice").AsFloat = 52
        lDtl.FindField("ISBASE").AsFloat = 1 
        lDtl.Post();

        lDtl.Append()  #For 2nd UOM
        lDtl.FindField("UOM").AsString = "CTN" #Make sure this always same as b4 delete data
        lDtl.FindField("Rate").AsFloat = 12    #Make sure this always same as b4 delete data
        lDtl.FindField("RefCost").AsFloat = 102.5
        lDtl.FindField("RefPrice").AsFloat = 260.45
        lDtl.FindField("ISBASE").AsFloat = 0 
        lDtl.Post()
    
        while LBar.RecordCount > 0:
            LBar.First()
            LBar.Delete()    

        LBar.Append() #For 1St UOM Barcode
        LBar.FindField("Barcode").AsString = "888888"
        LBar.FindField("UOM").AsString = "PCS"
        LBar.Post()

        LBar.Append() #For 2nd UOM Barcode
        LBar.FindField("Barcode").AsString = "999999"
        LBar.FindField("UOM").AsString = "CTN"
        LBar.Post()
    try:
        BizObject.Save()          
    except Exception as e:
        print("Oops!", e)    
    BizObject.Close()
    print ("Posting/Update Done")

def DelData():
    #Deleting only work if the record never use in other document
    BizObject = ComServer.BizObjects.Find("ST_ITEM")
    
    lDocKey = BizObject.FindKeyByRef("CODE", "FAIRY")
        
    if lDocKey is None:
        print ("Record Not Found")
    else:
        BizObject.Params.Find("Dockey").Value = lDocKey
        BizObject.Open()
        BizObject.Delete()        
        print ("Deleting Done")

try:
    Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
    GetListData()
    PostData()
    
    answer = input("Continue To delete?")
    if answer.lower() in ["y","yes"]:
        DelData()
    elif answer.lower() in ["n","no"]:
        print ("Deleting Aborted")
    else:
       print ("Invalid Input")
    ComServer.Logout()
finally:
    ComServer = None
    Common.KillApp()

AR_Customer

AR_Customer Script
#Updated 22 Jul 2023
import Common
       
def GetListData():
    lSQL = "SELECT A.*, B.BRANCHTYPE, B.BRANCHNAME, B.ADDRESS1, B.ADDRESS2, B.ADDRESS3, B.ADDRESS4, "
    lSQL = lSQL + "B.GEOLAT, B.GEOLONG, B.ATTENTION, B.PHONE1, B.PHONE2, B.MOBILE, B.FAX1, B.FAX2, B.EMAIL "
    lSQL = lSQL + "FROM AR_CUSTOMER A "
    lSQL = lSQL + "INNER JOIN AR_CUSTOMERBRANCH B ON (A.CODE=B.CODE) "
    lSQL = lSQL + "WHERE A.STATUS='A' "
    lSQL = lSQL + "ORDER BY A.CODE, B.BRANCHTYPE "
    
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
        
    Common.ShowResult(lDataSet)

def PostData():
    BizObject = ComServer.BizObjects.Find("AR_CUSTOMER")
    lMain = BizObject.DataSets.Find("MainDataSet")
    lDtl = BizObject.DataSets.Find("cdsBranch")
    
    lDocKey = BizObject.FindKeyByRef("CODE", "FAIRY")
        
    if lDocKey is None:
        BizObject.New()
        lMain.FindField("CODE").value = "FAIRY"
        lMain.FindField("CompanyName").value = "FAIRY TAIL"

        lDtl.Edit() #For 1St Branch
        lDtl.FindField("BranchName").AsString  = "BILLING"
        lDtl.FindField("Address1").AsString    = "Address1"
        lDtl.FindField("Address2").AsString    = "Address2"
        lDtl.FindField("Address3").AsString    = "Address3"
        lDtl.FindField("Address4").AsString    = "Address4"  
        lDtl.FindField("Attention").AsString   = "Attention"  
        lDtl.FindField("Phone1").AsString      = "Phone1"
        lDtl.FindField("Fax1").AsString        = "Fax1"
        lDtl.FindField("Email").AsString       = "EmailAddress"
        lDtl.Post()

        lDtl.Append() #For 2nd Branch
        lDtl.FindField("BranchName").AsString  = "Branch1"
        lDtl.FindField("Address1").AsString    = "DAddress1"
        lDtl.FindField("Address2").AsString    = "DAddress2"
        lDtl.FindField("Address3").AsString    = "DAddress3"
        lDtl.FindField("Address4").AsString    = "DAddress4"  
        lDtl.FindField("Attention").AsString   = "DAttention"  
        lDtl.FindField("Phone1").AsString      = "DPhone1"
        lDtl.FindField("Fax1").AsString        = "DFax1"
        lDtl.FindField("Email").AsString       = "DEmailAddress"
        lDtl.Post()
    else:
        BizObject.Params.Find("Code").Value = "FAIRY"
        BizObject.Open()
        BizObject.Edit()
        lMain.FindField("CompanyName").value = "FAIRY TAIL WIZARD"
        
        while lDtl.RecordCount > 0:
            lDtl.First()
            lDtl.Delete()

        #Insert back with new Information
        lDtl.Append() #For 1St Branch
        lDtl.FindField("BranchType").AsString  = "B" 
        lDtl.FindField("BranchName").AsString  = "BILLING" #Make sure this always same as b4 delete data
        lDtl.FindField("Address1").AsString    = "New Address1"
        lDtl.FindField("Address2").AsString    = "New Address2"
        lDtl.FindField("Address3").AsString    = "New Address3"
        lDtl.FindField("Address4").AsString    = "New Address4"  
        lDtl.FindField("Attention").AsString   = "New Attention"  
        lDtl.FindField("Phone1").AsString      = "New Phone1"
        lDtl.FindField("Fax1").AsString        = "New Fax1"
        lDtl.FindField("Email").AsString       = "New EmailAddress"
        lDtl.Post()

        lDtl.Append() #For 2nd Branch
        lDtl.FindField("BranchType").AsString  = "D" 
        lDtl.FindField("BranchName").AsString  = "Branch1" #Make sure this always same as b4 delete data
        lDtl.FindField("Address1").AsString    = "New DAddress1"
        lDtl.FindField("Address2").AsString    = "New DAddress2"
        lDtl.FindField("Address3").AsString    = "New DAddress3"
        lDtl.FindField("Address4").AsString    = "New DAddress4"  
        lDtl.FindField("Attention").AsString   = "New DAttention"  
        lDtl.FindField("Phone1").AsString      = "New DPhone1"
        lDtl.FindField("Fax1").AsString        = "New DFax1"
        lDtl.FindField("Email").AsString       = "New DEmailAddress"
        lDtl.Post()
    
    try:
        BizObject.Save()          
    except Exception as e:
        print("Oops!", e)    
    BizObject.Close()
    print ("Posting/Update Done")

def DelData():
    #Deleting only work if the record never use in other document
    BizObject = ComServer.BizObjects.Find("AR_CUSTOMER")
    
    lDocKey = BizObject.FindKeyByRef("CODE", "FAIRY")
        
    if lDocKey is None:
        print ("Record Not Found")
    else:
        BizObject.Params.Find("CODE").Value = lDocKey
        BizObject.Open()
        BizObject.Delete()        
        print ("Deleting Done")

try:
    Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
    GetListData()
    PostData()
    
    answer = input("Continue To delete?")
    if answer.lower() in ["y","yes"]:
        DelData()
    elif answer.lower() in ["n","no"]:
        print ("Deleting Aborted")
    else:
       print ("Invalid Input") 
    ComServer.Logout()   
finally:
    ComServer = None
    Common.KillApp()

Sales Invoice

SL_IV
#Updated 08 Jan 2024
import Common
import datetime
       
def GetListData():
    lSQL = "SELECT A.DOCNO, A.DOCDATE, A.CODE, A.COMPANYNAME, A.DESCRIPTION, A.DOCAMT, "
    lSQL = lSQL + "A.AGENT, A.AREA, "
    lSQL = lSQL + "B.ITEMCODE, B.DESCRIPTION ITEMDESC, B.QTY, B.UOM, B.UNITPRICE, B.DISC,  "
    lSQL = lSQL + "B.TAX, B.TAXRATE, B.TAXAMT, B.TAXINCLUSIVE, B.AMOUNT "
    lSQL = lSQL + "FROM SL_IV A "
    lSQL = lSQL + "INNER JOIN SL_IVDTL B ON (A.DOCKEY=B.DOCKEY) "
    lSQL = lSQL + "WHERE A.CODE='300-A0002' "
    lSQL = lSQL + "AND A.CANCELLED='F' "
    
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
        
    Common.ShowResult(lDataSet)

def PostData():
    BizObject = ComServer.BizObjects.Find("SL_IV")
    lMain = BizObject.DataSets.Find("MainDataSet") #lMain contains master data
    lDetail = BizObject.DataSets.Find("cdsDocDetail") #lDetail contains detail data
    
    lDate = datetime.datetime(2023, 2, 22, 13, 0)
    lDate.strftime('%m/%d/%Y')
    
    lDocKey = BizObject.FindKeyByRef("DocNo", "--IV Test--")
        
    if lDocKey is None:
        BizObject.New()
        lMain.FindField("DocNo").AsString = "--IV Test--"
        lMain.FindField("DocDate").value = lDate
        lMain.FindField("PostDate").value = lDate
        lMain.FindField("Code").AsString = "300-C0001" #Customer Account
        lMain.FindField("CompanyName").AsString = "Cash Sales"
        lMain.FindField("Address1").AsString = "" #Optional
        lMain.FindField("Address2").AsString = "" #Optional
        lMain.FindField("Address3").AsString = "" #Optional
        lMain.FindField("Address4").AsString = "" #Optional
        lMain.FindField("Phone1").AsString = ""   #Optional
        lMain.FindField("Description").AsString = "Sales"

        #Insert Data - Detail
        #For Tax Inclusive = True with override Tax Amount
        lDetail.Append()
        lDetail.FindField("Seq").value = 1
        lDetail.FindField("Account").AsString = "500-000" #Sales Account
        lDetail.FindField("Description").AsString = "Sales Item A"
        lDetail.FindField("Description3").AsString = ("Item A Line 1" + ("\r" + "Item A Line 2"))
        lDetail.FindField("Qty").AsFloat = 1
        lDetail.FindField("Tax").AsString = "SV"
        lDetail.FindField("TaxRate").AsString = "6%"
        lDetail.FindField("TaxInclusive").value = 0
        lDetail.FindField("UnitPrice").AsFloat = 435
        lDetail.FindField("Amount").AsFloat = 410.37 #Exclding GST Amt
        lDetail.FindField("TaxAmt").AsFloat = 24.63

        lDetail.DisableControls()
        lDetail.FindField("TaxInclusive").value = 1
        lDetail.EnableControls()
    
        lDetail.Post()

        #For Tax Inclusive = False with override Tax Amount
        lDetail.Append()
        lDetail.FindField("Seq").value = 2
        lDetail.FindField("Account").AsString = "500-000"
        lDetail.FindField("Description").AsString = "Sales Item B"
        lDetail.FindField("Qty").AsFloat = 1
        lDetail.FindField("Tax").AsString = "SV"
        lDetail.FindField("TaxRate").AsString = "6%"
        lDetail.FindField("TaxInclusive").value = 0
        lDetail.FindField("UnitPrice").AsFloat = 94.43
        lDetail.FindField("Amount").AsFloat = 94.43
        lDetail.FindField("TaxAmt").AsFloat = 5.66
        lDetail.Post()
    
        #For With Item Code
        lDetail.Append()
        lDetail.FindField("Seq").value = 3
        lDetail.FindField("ItemCode").AsString = "ANT"
        lDetail.FindField("Description").AsString = "Sales Item B"
        #lDetail.FindField("Account").AsString     = "500-000" #If you wanted override the Sales Account Code
        lDetail.FindField("Qty").AsFloat = 2
        lDetail.FindField("UOM").AsString = "UNIT"
        #lDetail.FindField("DISC").AsString        = "5%+3" #Optional(eg 5% plus 3 Discount)
        lDetail.FindField("Tax").AsString = "SV"
        lDetail.FindField("TaxRate").AsString = "6%"
        lDetail.FindField("TaxInclusive").value = 0
        lDetail.FindField("UnitPrice").AsFloat = 100
        lDetail.FindField("Amount").AsFloat = 200
        lDetail.FindField("TaxAmt").AsFloat = 12
        lDetail.Post()
    
    else:
        BizObject.Params.Find("Dockey").Value = lDocKey
        BizObject.Open()
        BizObject.Edit()
        lMain.Edit()
        lMain.FindField("Description").AsString = "Edited Description 123 的第一 🐱"

        #Delete all Detail
        while lDetail.RecordCount != 0:
            lDetail.Last()
            lDetail.Delete()
            
        #Append Detail
        lDetail.Append()
        #lDetail.FindField("Account").value = "500-000"
        lDetail.FindField("Description").AsString = "Item A  的第一"
        lDetail.FindField("Description3").AsString = ComServer.Utility.PlainTextToRichText("More description  的第一 🐱")
        lDetail.FindField("Tax").value = ""
        lDetail.FindField("TaxInclusive").value = 0
        lDetail.FindField("Amount").value = 410.37
        lDetail.FindField("TaxAmt").value = 0
        lDetail.Post()
        
    try:
        BizObject.Save()          
    except Exception as e:
        print("Oops!", e)    
    BizObject.Close()
    print ("Posting/Update Done")

def DelData():
    #Deleting only work if the record never not knock off by Payment or Credit Note
    BizObject = ComServer.BizObjects.Find("SL_IV")
    
    lDocKey = BizObject.FindKeyByRef("DocNo", "--IV Test--")
        
    if lDocKey is None:
        print ("Record Not Found")
    else:
        BizObject.Params.Find("Dockey").Value = lDocKey
        BizObject.Open()
        BizObject.Delete()        
        print ("Deleting Done")

try:
    Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
    GetListData()
    PostData()
    
    answer = input("Continue To delete?")
    if answer.lower() in ["y","yes"]:
        DelData()
    elif answer.lower() in ["n","no"]:
        print ("Deleting Aborted")
    else:
       print ("Invalid Input")
       
    ComServer.Logout()   
finally:
    ComServer = None
    Common.KillApp()

Purchase Invoice

PH_PI
#Updated 08 Jan 2024
import Common
import datetime
       
def GetListData():
    lSQL = "SELECT A.DOCNO, A.DOCDATE, A.CODE, A.COMPANYNAME, A.DESCRIPTION, A.DOCAMT, "
    lSQL = lSQL + "A.AGENT, A.AREA, "
    lSQL = lSQL + "B.ITEMCODE, B.DESCRIPTION ITEMDESC, B.QTY, B.UOM, B.UNITPRICE, B.DISC,  "
    lSQL = lSQL + "B.TAX, B.TAXRATE, B.TAXAMT, B.TAXINCLUSIVE, B.AMOUNT "
    lSQL = lSQL + "FROM PH_PI A "
    lSQL = lSQL + "INNER JOIN PH_PIDTL B ON (A.DOCKEY=B.DOCKEY) "
    lSQL = lSQL + "WHERE A.CODE='400-L0001' "
    lSQL = lSQL + "AND A.CANCELLED='F' "
    
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
        
    Common.ShowResult(lDataSet)

def PostData():
    BizObject = ComServer.BizObjects.Find("PH_PI")
    lMain = BizObject.DataSets.Find("MainDataSet") #lMain contains master data
    lDetail = BizObject.DataSets.Find("cdsDocDetail") #lDetail contains detail data
    
    lDate = datetime.datetime(2023, 2, 22, 13, 0)
    lDate.strftime('%m/%d/%Y')
    
    V = ["--PI Test--", "400-W0001"]  #DocNo, Code
    
    lDocKey = BizObject.FindKeyByRef("DocNo;Code", V)
        
    if lDocKey is None:
        BizObject.New()
        lMain.FindField("DocNo").AsString = "--PI Test--"
        lMain.FindField("DocDate").value = lDate
        lMain.FindField("PostDate").value = lDate
        lMain.FindField("Code").AsString = "400-W0001" #Supplier Account
        lMain.FindField("CompanyName").AsString = "WORLDLINE COMMUNICATION SDN BHD"
        #lMain.FindField("Address1").AsString = "" #Optional
        #lMain.FindField("Address2").AsString = "" #Optional
        #lMain.FindField("Address3").AsString = "" #Optional
        #lMain.FindField("Address4").AsString = "" #Optional
        #lMain.FindField("Phone1").AsString = ""   #Optional
        lMain.FindField("Description").AsString = "Purchase Invoice"

        #Insert Data - Detail    
        lDetail.Append()
        lDetail.FindField("Seq").value = 1
        lDetail.FindField("ItemCode").AsString = "ANT"
        lDetail.FindField("Description").AsString = "Item B"
        #lDetail.FindField("Account").AsString     = "600-000" #If you wanted override the Purchase Account Code
        lDetail.FindField("Qty").AsFloat = 2
        lDetail.FindField("UOM").AsString = "UNIT"
        #lDetail.FindField("DISC").AsString        = "5%+3" #Optional(eg 5% plus 3 Discount)
        lDetail.FindField("Tax").AsString = ""
        lDetail.FindField("TaxRate").AsString = ""
        lDetail.FindField("TaxInclusive").value = 0
        lDetail.FindField("UnitPrice").AsFloat = 80
        lDetail.FindField("Amount").AsFloat = 160
        lDetail.FindField("TaxAmt").AsFloat = 0
        lDetail.Post()
        
        lDetail.Append()
        lDetail.FindField("Seq").value = 2
        lDetail.FindField("ItemCode").AsString = "HFK"
        lDetail.FindField("Description").AsString = "HANDS FREE KITS"
        #lDetail.FindField("Account").AsString     = "600-000" #If you wanted override the Purchase Account Code
        lDetail.FindField("Qty").AsFloat = 3
        lDetail.FindField("UOM").AsString = "UNIT"
        #lDetail.FindField("DISC").AsString        = "5%+3" #Optional(eg 5% plus 3 Discount)
        lDetail.FindField("Tax").AsString = ""
        lDetail.FindField("TaxRate").AsString = ""
        lDetail.FindField("TaxInclusive").value = 0
        lDetail.FindField("UnitPrice").AsFloat = 50
        lDetail.FindField("Amount").AsFloat = 150
        lDetail.FindField("TaxAmt").AsFloat = 0
        lDetail.Post()        
    
    else:
        BizObject.Params.Find("Dockey").Value = lDocKey
        BizObject.Open()
        BizObject.Edit()
        lMain.Edit()
        lMain.FindField("Description").AsString = "Edited Description 123 的第一 🐱"

        #Delete all Detail
        while lDetail.RecordCount != 0:
            lDetail.Last()
            lDetail.Delete()
            
        #Append Detail
        lDetail.Append()
        #lDetail.FindField("Account").value = "600-000"
        lDetail.FindField("Description").AsString = "Item A  的第一"
        lDetail.FindField("Description3").AsString = ComServer.Utility.PlainTextToRichText("More description  的第一 🐱")
        lDetail.FindField("Tax").value = ""
        lDetail.FindField("TaxInclusive").value = 0
        lDetail.FindField("Amount").value = 410.37
        lDetail.FindField("TaxAmt").value = 0
        lDetail.Post()
        
    try:
        BizObject.Save()          
    except Exception as e:
        print("Oops!", e)    
    BizObject.Close()
    print ("Posting/Update Done")

def DelData():
    #Deleting only work if the record never not knock off by Payment or Credit Note
    BizObject = ComServer.BizObjects.Find("PH_PI")
    
    V = ["--PI Test--", "400-W0001"]  #DocNo, Code
    
    lDocKey = BizObject.FindKeyByRef("DocNo;Code", V)    
        
    if lDocKey is None:
        print ("Record Not Found")
    else:
        BizObject.Params.Find("Dockey").Value = lDocKey
        BizObject.Open()
        BizObject.Delete()        
        print ("Deleting Done")

try:
    Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
    GetListData()
    PostData()
    
    answer = input("Continue To delete?")
    if answer.lower() in ["y","yes"]:
        DelData()
    elif answer.lower() in ["n","no"]:
        print ("Deleting Aborted")
    else:
       print ("Invalid Input")
       
    ComServer.Logout()   
finally:
    ComServer = None
    Common.KillApp()

GL Ledger

GL Ledger Script
#Updated 24 Jul 2023
import Common

def GetData():
    lSQL = "SELECT A.CODE, B.DESCRIPTION ACCDESC, A.DOCDATE, A.POSTDATE, A.DESCRIPTION, A.DESCRIPTION2,  "
    lSQL = lSQL + "A.LOCALDR, A.LOCALCR, A.REF1, A.REF2 FROM GL_TRANS A "
    lSQL = lSQL + "INNER JOIN GL_ACC B ON (A.CODE=B.CODE) "
    lSQL = lSQL + "WHERE A.CANCELLED='F' "
    lSQL = lSQL + "AND A.POSTDATE BETWEEN '01 JAN 2023'  "
    lSQL = lSQL + "AND '31 DEC 2023' "
    lSQL = lSQL + "AND A.CODE='310-000' "
    lSQL = lSQL + "ORDER BY A.CODE, A.POSTDATE "
    
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
    
    Common.ShowResult(lDataSet)
    
try:
    Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer       
    GetData()
    ComServer.Logout()
finally:    
    ComServer = None
    Common.KillApp()

GL Trial Balance

GL Trial Balance Script
#Updated 25 Jul 2023
import Common
import datetime

def GetData():
    RptObject = ComServer.RptObjects.Find('GL.TrialBalance.RO')
    
    RptObject.Params.Find("AllProject").Value      = True
    RptObject.Params.Find("AllAgent").Value        = True
    RptObject.Params.Find("AllArea").Value         = True
    RptObject.Params.Find("LedgerType").Value      = "G" #G = Legder, S = Debtor, P = Supplier
    #RptObject.Params.Find("ProjectData").Value    = #Not use if AllArea is true
    RptObject.Params.Find("ShowZeroBalance").Value = False
    RptObject.Params.Find("SortBy").Value          = "PostDate;DocNo" 
    RptObject.Params.Find("UseDescription2").Value = False
    
    lDateFrom = datetime.datetime(2018, 1, 1, 13, 0)
    lDateFrom.strftime('%m/%d/%Y')
    lDateTo = datetime.datetime(2018, 12, 31, 13, 0)
    lDateTo.strftime('%m/%d/%Y')
    
    RptObject.Params.Find("DateFrom").Value       = lDateFrom
    RptObject.Params.Find("DateTo").Value         = lDateTo

    #RptObject.Params.Find("AgentData").Value      = 'Not use if AllAgent is true
    #RptObject.Params.Find("AreaData").Value       = 'Not use if AllArea is true
  
    RptObject.Params.Find("SortBy").Value          = "Code;Description"
    RptObject.CalculateReport()

    lDataSet = RptObject.DataSets.Find("cdsMain")
    lDataSet2 = RptObject.DataSets.Find("cdsGLAccount") #For Account List
    
    if lDataSet2.RecordCount > 0:
        while not lDataSet2.eof:
            print(lDataSet2.FindField('CODE').AsString)
            print(lDataSet2.FindField('DESCRIPTION').AsString)
            print("===")
            lDataSet2.Next()
            
    if lDataSet.RecordCount > 0:
        while not lDataSet.eof:
            print("Month To Date")
            print(lDataSet.FindField('CODE').AsString)
            print(lDataSet.FindField('MTDDR').AsString)            
            print(lDataSet.FindField('MTDCR').AsString)
            print("Year To Date")
            print(lDataSet.FindField('CODE').AsString)
            print(lDataSet.FindField('YTDDR').AsString)
            print(lDataSet.FindField('YTDCR').AsString)
            print("===")
            lDataSet.Next()
    else:
        print ("Record Not Found")
    
try:
    Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer       
    GetData()
    ComServer.Logout()
finally:    
    ComServer = None
    Common.KillApp()

Terms

Terms
#Updated 25 Jul 2023
import Common
       
def GetListData():
    lSQL = "SELECT * FROM TERMS "
    lSQL = lSQL + "WHERE ISACTIVE='T' "
    lSQL = lSQL + "ORDER BY CODE "
    
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
        
    Common.ShowResult(lDataSet)

def PostData():
    BizObject = ComServer.BizObjects.Find("Terms")
    lMain = BizObject.DataSets.Find("MainDataSet")
    
    lDocKey = BizObject.FindKeyByRef("CODE", "90 Days")
        
    if lDocKey is None:
        BizObject.New()
        lMain.FindField("CODE").value = "90 Days"
        lMain.FindField("DESCRIPTION").value = "Net 90 Days"
        lMain.FindField("TermDay").value = 90
        lMain.FindField("ISACTIVE").value = "T"
    else:
        BizObject.Params.Find("CODE").Value = lDocKey
        BizObject.Open()
        BizObject.Edit()
        lMain.FindField("DESCRIPTION").value = "Net 90 Days - Edited"
        lMain.FindField("ISACTIVE").value = "F"
        
    try:
        BizObject.Save()          
    except Exception as e:
        print("Oops!", e)    
    BizObject.Close()
    print ("Posting/Update Done")

def DelData():
    #Deleting only work if the record never use in other document
    BizObject = ComServer.BizObjects.Find("Terms")
    
    lDocKey = BizObject.FindKeyByRef("CODE", "90 Days")
        
    if lDocKey is None:
        print ("Record Not Found")
    else:
        BizObject.Params.Find("CODE").Value = lDocKey
        BizObject.Open()
        BizObject.Delete()        
        print ("Deleting Done")

try:
    Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
    GetListData()
    PostData()
    
    answer = input("Continue To delete?")
    if answer.lower() in ["y","yes"]:
        DelData()
    elif answer.lower() in ["n","no"]:
        print ("Deleting Aborted")
    else:
       print ("Invalid Input")
       
    ComServer.Logout()   
finally:
    ComServer = None
    Common.KillApp()

Stock Adjustment

ST_SJ
#Updated 08 Jan 2024
import Common
import datetime
       
def GetListData():
    lSQL = "SELECT A.DOCNO, A.DOCDATE, A.DESCRIPTION, A.DOCAMT, "
    lSQL = lSQL + "A.AUTHBY, A.REASON, A.REMARK, "
    lSQL = lSQL + "B.ITEMCODE, B.DESCRIPTION ITEMDESC, B.QTY, B.UOM, B.UNITCOST, "
    lSQL = lSQL + "B.AMOUNT, B.REMARK1, B.REMARK2 "
    lSQL = lSQL + "FROM ST_AJ A "
    lSQL = lSQL + "INNER JOIN ST_AJDTL B ON (A.DOCKEY=B.DOCKEY) "
    lSQL = lSQL + "WHERE A.DocDate='20 Apr 2013' "
    lSQL = lSQL + "AND A.CANCELLED='F' "
    
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
        
    Common.ShowResult(lDataSet)

def PostData():
    BizObject = ComServer.BizObjects.Find("ST_AJ")
    lMain = BizObject.DataSets.Find("MainDataSet") #lMain contains master data
    lDetail = BizObject.DataSets.Find("cdsDocDetail") #lDetail contains detail data
    
    lDate = datetime.datetime(2023, 2, 22, 13, 0)
    lDate.strftime('%m/%d/%Y')
        
    lDocKey = BizObject.FindKeyByRef("DocNo", "--AJ Test--")
        
    if lDocKey is None:
        BizObject.New()
        lMain.FindField("DocNo").AsString = "--AJ Test--"
        lMain.FindField("DocDate").value = lDate
        lMain.FindField("PostDate").value = lDate
        lMain.FindField("Description").AsString = "Stock Adjustment"

        #Insert Data - Detail - Increase Stock Qty   
        lDetail.Append()
        lDetail.FindField("Seq").value = 1
        lDetail.FindField("ItemCode").AsString = "ANT"
        lDetail.FindField("Description").AsString = "ANTENA"
        lDetail.FindField("Qty").AsFloat = 2
        lDetail.FindField("UOM").AsString = "PCS"
        lDetail.FindField("UnitCOST").AsFloat = 80
        lDetail.FindField("Amount").AsFloat = 160
        lDetail.Post()
        
        #Insert Data - Detail - Reduce Stock Qty
        lDetail.Append()
        lDetail.FindField("Seq").value = 2
        lDetail.FindField("ItemCode").AsString = "HFK"
        lDetail.FindField("Description").AsString = "HANDS FREE KITS"
        lDetail.FindField("Qty").AsFloat = -3
        lDetail.FindField("UOM").AsString = "UNIT"
        lDetail.Post()        
    
    else:
        BizObject.Params.Find("Dockey").Value = lDocKey
        BizObject.Open()
        BizObject.Edit()
        lMain.Edit()
        lMain.FindField("Description").AsString = "Edited Description 123 的第一 🐱"

        #Delete all Detail
        while lDetail.RecordCount != 0:
            lDetail.Last()
            lDetail.Delete()
            
        #Append Detail
        lDetail.Append()
        lDetail.FindField("Seq").value = 1
        lDetail.FindField("ItemCode").AsString = "BOM"
        lDetail.FindField("Description").AsString = "Bill Of Material"        
        lDetail.FindField("Qty").AsFloat = -1
        lDetail.FindField("UOM").AsString = "UNIT"
        lDetail.Post()
        
    try:
        BizObject.Save()          
    except Exception as e:
        print("Oops!", e)    
    BizObject.Close()
    print ("Posting/Update Done")

def DelData():
    BizObject = ComServer.BizObjects.Find("ST_AJ")
        
    lDocKey = BizObject.FindKeyByRef("DocNo", "--AJ Test--")    
        
    if lDocKey is None:
        print ("Record Not Found")
    else:
        BizObject.Params.Find("Dockey").Value = lDocKey
        BizObject.Open()
        BizObject.Delete()        
        print ("Deleting Done")

try:
    Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
    GetListData()
    PostData()
    
    answer = input("Continue To delete?")
    if answer.lower() in ["y","yes"]:
        DelData()
    elif answer.lower() in ["n","no"]:
        print ("Deleting Aborted")
    else:
       print ("Invalid Input")
       
    ComServer.Logout()   
finally:
    ComServer = None
    Common.KillApp()

Sales Order

Sales Order
#Updated 08 Jan 2024
import Common
import datetime
       
def GetListData():
    lSQL = "SELECT A.DOCNO, A.DOCDATE, A.CODE, A.COMPANYNAME, A.DESCRIPTION, A.DOCAMT, "
    lSQL = lSQL + "A.AGENT, A.AREA, "
    lSQL = lSQL + "B.ITEMCODE, B.DESCRIPTION ITEMDESC, B.QTY, B.UOM, B.UNITPRICE, B.DISC,  "
    lSQL = lSQL + "B.TAX, B.TAXRATE, B.TAXAMT, B.TAXINCLUSIVE, B.AMOUNT "
    lSQL = lSQL + "FROM SL_SO A "
    lSQL = lSQL + "INNER JOIN SL_SODTL B ON (A.DOCKEY=B.DOCKEY) "
    lSQL = lSQL + "WHERE A.CODE='300-A0002' "
    lSQL = lSQL + "AND A.CANCELLED='F' "
    
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
        
    Common.ShowResult(lDataSet)

def PostData():
    BizObject = ComServer.BizObjects.Find("SL_SO")
    lMain = BizObject.DataSets.Find("MainDataSet") #lMain contains master data
    lDetail = BizObject.DataSets.Find("cdsDocDetail") #lDetail contains detail data
    
    lDate = datetime.datetime(2023, 2, 22, 13, 0)
    lDate.strftime('%m/%d/%Y')
    
    lDocKey = BizObject.FindKeyByRef("DocNo", "--SO Test--")
        
    if lDocKey is None:
        BizObject.New()
        lMain.FindField("DocNo").AsString = "--SO Test--"
        lMain.FindField("DocDate").value = lDate
        lMain.FindField("PostDate").value = lDate
        lMain.FindField("Code").AsString = "300-C0001" #Customer Account
        lMain.FindField("CompanyName").AsString = "Cash Sales"
        #lMain.FindField("Address1").AsString = "" #Optional
        #lMain.FindField("Address2").AsString = "" #Optional
        #lMain.FindField("Address3").AsString = "" #Optional
        #lMain.FindField("Address4").AsString = "" #Optional
        #lMain.FindField("Phone1").AsString = ""   #Optional
        lMain.FindField("Description").AsString = "Sales Order"

        #Insert Data - Detail    
        lDetail.Append()
        lDetail.FindField("Seq").value = 1
        lDetail.FindField("ItemCode").AsString = "ANT"
        lDetail.FindField("Description").AsString = "Sales Item B"
        lDetail.FindField("Qty").AsFloat = 2
        lDetail.FindField("UOM").AsString = "UNIT"
        #lDetail.FindField("DISC").AsString        = "5%+3" #Optional(eg 5% plus 3 Discount)
        lDetail.FindField("Tax").AsString = "SV"
        lDetail.FindField("TaxRate").AsString = "6%"
        lDetail.FindField("TaxInclusive").value = 0
        lDetail.FindField("UnitPrice").AsFloat = 100
        lDetail.FindField("Amount").AsFloat = 200
        lDetail.FindField("TaxAmt").AsFloat = 12
        lDetail.Post()
    
    else:
        BizObject.Params.Find("Dockey").Value = lDocKey
        BizObject.Open()
        BizObject.Edit()
        lMain.Edit()
        lMain.FindField("Description").AsString = "Edited Description 123 的第一 🐱"

        #Delete all Detail
        while lDetail.RecordCount != 0:
            lDetail.Last()
            lDetail.Delete()
            
        #Append Detail
        lDetail.Append()
        lDetail.FindField("Seq").value = 1
        lDetail.FindField("ItemCode").AsString = "BOM"
        lDetail.FindField("Description").AsString = "Sales Item BOM"
        lDetail.FindField("Qty").AsFloat = 1
        lDetail.FindField("UOM").AsString = "UNIT"
        #lDetail.FindField("DISC").AsString        = "5%+3" #Optional(eg 5% plus 3 Discount)
        lDetail.FindField("Tax").AsString = "SV"
        lDetail.FindField("TaxRate").AsString = "6%"
        lDetail.FindField("TaxInclusive").value = 0
        lDetail.FindField("UnitPrice").AsFloat = 100
        lDetail.FindField("Amount").AsFloat = 100
        lDetail.FindField("TaxAmt").AsFloat = 6
        lDetail.Post()
        
    try:
        BizObject.Save()          
    except Exception as e:
        print("Oops!", e)    
    BizObject.Close()
    print ("Posting/Update Done")

def DelData():
    BizObject = ComServer.BizObjects.Find("SL_SO")
    
    lDocKey = BizObject.FindKeyByRef("DocNo", "--SO Test--")
        
    if lDocKey is None:
        print ("Record Not Found")
    else:
        BizObject.Params.Find("Dockey").Value = lDocKey
        BizObject.Open()
        BizObject.Delete()        
        print ("Deleting Done")

try:
    Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
    GetListData()
    PostData()
    
    answer = input("Continue To delete?")
    if answer.lower() in ["y","yes"]:
        DelData()
    elif answer.lower() in ["n","no"]:
        print ("Deleting Aborted")
    else:
       print ("Invalid Input")
       
    ComServer.Logout()   
finally:
    ComServer = None
    Common.KillApp()

Sales.PriceHistory.RO

Sales.PriceHistory.RO Script
#Updated 01 Apr 2021
import win32com.client
import datetime

ComServer = win32com.client.Dispatch("SQLAcc.BizApp")

def CheckLogin():
    B = ComServer.IsLogin
    if B == True:
        ComServer.Logout()
    ComServer.Login("ADMIN", "ADMIN", #UserName, Password
                    "C:\\eStream\\SQLAccounting\\Share\\Default.DCF",  #DCF file
                    "ACC-0081.FDB") #Database Name

def GetData():
    RptObject = ComServer.RptObjects.Find('Sales.PriceHistory.RO')
    
    #RptObject.Params.Find("AgentData").Value            = #Not use if AllAgent is true
    #RptObject.Params.Find("TaxData").Value              = #Not use if AllTax is true
    #RptObject.Params.Find("CompanyCategoryData").Value  = #Not use if AllCompanyCategory is true
    RptObject.Params.Find("AllAgent").Value              = True
    RptObject.Params.Find("AllTax").Value                = True
    RptObject.Params.Find("AllShipper").Value            = True
    RptObject.Params.Find("AllArea").Value               = True
    RptObject.Params.Find("AllCompany").Value            = True
    RptObject.Params.Find("AllDocProject").Value         = True
    RptObject.Params.Find("AllItem").Value               = False
    RptObject.Params.Find("AllItemProject").Value        = True
    RptObject.Params.Find("AllLocation").Value           = True
    RptObject.Params.Find("AllCompanyCategory").Value    = True
    RptObject.Params.Find("AllBatch").Value              = True
    RptObject.Params.Find("AllTariff").Value             = True
    RptObject.Params.Find("AllStockGroup").Value         = True
    #RptObject.Params.Find("AreaData").Value             = #Not use if AllArea is true
    #RptObject.Params.Find("CategoryData").Value         = #Not use if AllTax is true
    #RptObject.Params.Find("CategoryTpl").Value          = #Not use if AllTax is true
    #RptObject.Params.Find("CompanyData").Value          = #Not use if AllTax is true
       
    lDateFrom = datetime.datetime(2021, 3, 1, 13, 0)
    lDateFrom.strftime('%m/%d/%Y')
    lDateTo = datetime.datetime(2021, 3, 31, 13, 0)
    lDateTo.strftime('%m/%d/%Y')
    
    RptObject.Params.Find("DateFrom").Value         = lDateFrom
    RptObject.Params.Find("DateTo").Value           = lDateTo

    RptObject.Params.Find("DoCN_SC").Value          = False #Include Credit Note
    #RptObject.Params.Find("DocProjectData").Value  = #Not use if AllDocProject is true
    RptObject.Params.Find("DoCS_CP").Value          = True #Include Cash Sales
    RptObject.Params.Find("DoDN_SD").Value          = False #Include Debit Note
    RptObject.Params.Find("DoDO_GR").Value          = False #Include Delivery Order
    RptObject.Params.Find("DoED_EG").Value          = False #Include Extra Delivery Order
    RptObject.Params.Find("DoIV_PI").Value          = False #Include Invoice
    RptObject.Params.Find("DoQT_PQ").Value          = False #Include Quotation
    RptObject.Params.Find("DoSO_PO").Value          = False #Include Sales Order
    #RptObject.Params.Find("ItemCode").Value        = #For Internal use only
    RptObject.Params.Find("ItemData").Value         = "ANT" + "\r" + "BOM"
    #RptObject.Params.Find("ItemProjectData").Value  = #Not use if AllItemProject is true
    #RptObject.Params.Find("LocationData").Value     = #Not use if AllLocation is true
    #RptObject.Params.Find("MaxRecords").Value       = #Not use if SelectMaxRecords is False
    RptObject.Params.Find("SelectDate").Value        = True
    RptObject.Params.Find("SelectMaxRecords").Value  = False
    #RptObject.Params.Find("GroupBy").Value          = #Only use if wanted to grouping
    RptObject.Params.Find("HasCategory").Value       = False
    #RptObject.Params.Find("ItemCategoryData").Value = #Not use if HasCategory is False
    #RptObject.Params.Find("BatchData").Value        = #Not use if AllBatch is true
    #RptObject.Params.Find("TariffData").Value       = #Not use if AllTariff is true
    #RptObject.Params.Find("ShipperData").Value      = #Not use if AllShipper is true
    RptObject.Params.Find("SortBy").Value            = "DocDate;DocNo"
    #RptObject.Params.Find("StockGroupData").Value   = #Not use if AllStockGroup is true
    #RptObject.Params.Find("SummaryInterval  
    
    RptObject.CalculateReport()

    lDataSet = RptObject.DataSets.Find("cdsMain")
        
    if lDataSet.RecordCount > 0:
        while not lDataSet.eof:
            for idx in range(lDataSet.Fields.Count):
                LFld = lDataSet.Fields.Items(idx).FieldName 
                print(LFld + " :"+ lDataSet.FindField(LFld).AsString)
            print("===")
            lDataSet.Next()
    else:
        print ("Record Not Found")
    
try:
    CheckLogin()      
    GetData()
finally:
    ComServer.Logout()
    ComServer = None

Get Edited Sales Invoice List

Get Edited Sales Invoice List Script
#Updated 19 Jul 2021
import win32com.client

ComServer = win32com.client.Dispatch("SQLAcc.BizApp")

def CheckLogin():
    B = ComServer.IsLogin
    if B == True:
        ComServer.Logout()
    ComServer.Login("ADMIN", "ADMIN", #UserName, Password
                    "C:\\eStream\\SQLAccounting\\Share\\Default.DCF",  #DCF file
                    "ACC-0081.FDB") #Database Name

def GetData():
    lSQL = "SELECT REFERENCE FROM AUDIT "
    lSQL = lSQL + "WHERE REF LIKE 'SL_IV%' "
    lSQL = lSQL + "AND UPDATEKIND='E' "
    lSQL = lSQL + "AND CAST(DOCDATETIME AS DATE) = '10 JUN 2021' "
    
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)

    if lDataSet.RecordCount > 0:
        while not lDataSet.eof:
            DocNo = lDataSet.FindField('REFERENCE').AsString
            DocNo = DocNo.split(',')[0]
            DocNo = DocNo.split(':')[1]
    
            print(DocNo)
            print("===")
            lDataSet.Next()
    else:
        print ("Record Not Found")


    
try:
    CheckLogin()      
    GetData()
finally:
    ComServer.Logout()
    ComServer = None

SO to DO

Get Outstanding SO by SO Number transfer to DO Script
#Updated 29 Nov 2021
import win32com.client
import datetime

ComServer = win32com.client.Dispatch("SQLAcc.BizApp")

def CheckLogin():
    B = ComServer.IsLogin
    if B == True:
        ComServer.Logout()
    ComServer.Login("FAUNG", "ADMIN", #UserName, Password
                    "D:\\Happy\\DB\\Default.DCF",
                   # "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                    "ACC-0011.FDB") #Database Name

def PostData():
    lSQL = "SELECT Dockey, DocNo,Code, CompanyName, DocProject, Seq, DtlKey, ItemCode, Qty, UOM, UnitPrice, Disc, Amount, DtlProject, "
    lSQL = lSQL + "Tax, TaxRate, TaxInclusive, TaxAmt, COALESCE(Sum(XFQty),0) XFQty, COALESCE((Qty-Sum(XFQty)), Qty) OSQty FROM ( "
    lSQL = lSQL + "SELECT A.Dockey, A.DocNo, A.Code, A.CompanyName, A.Project DocProject, "
    lSQL = lSQL + "B.DtlKey, B.Seq, B.ItemCode, B.Qty, B.UOM, B.UnitPrice, B.Disc, B.Amount, "
    lSQL = lSQL + "B.Tax, B.TaxRate, B.TaxInclusive, B.TaxAmt, B.Project DtlProject, C.Qty XFQty FROM SL_SO A "
    lSQL = lSQL + "INNER JOIN SL_SODTL B ON (A.DOCKEY=B.DOCKEY) "
    lSQL = lSQL + "LEFT JOIN ST_XTRANS C ON (A.DOCKEY=C.FROMDOCKEY AND B.DTLKEY=C.FROMDTLKEY "
    lSQL = lSQL + "                          AND C.FROMDOCTYPE='SO') "
    lSQL = lSQL + "WHERE A.DOCNO='SO-00044') "
    lSQL = lSQL + "GROUP BY Dockey, DocNo, Code, CompanyName, DocProject, Seq, Dtlkey, ItemCode, Qty, UOM, UnitPrice, Disc, "
    lSQL = lSQL +" Amount, DtlProject, Tax, TaxRate, TaxInclusive, TaxAmt "
    lSQL = lSQL + "HAVING COALESCE((Qty-Sum(XFQty)), Qty) >0 "
    
    lDataSet = ComServer.DBManager.NewDataSet(lSQL) #Get Outstanding Qty for each itemcode
    #print("==="+ str(lDataSet.RecordCount))
    if lDataSet.RecordCount > 0:
        BizObject = ComServer.BizObjects.Find("SL_DO")
        lMain = BizObject.DataSets.Find("MainDataSet") #lMain contains master data
        lDetail = BizObject.DataSets.Find("cdsDocDetail") #lDetail contains detail data
    
        lDate = datetime.datetime(2021, 11, 29, 13, 0)
        lDate.strftime('%m/%d/%Y')
    
        BizObject.New();
        lMain.FindField("DocKey").value = -1
        lMain.FindField("DocNo").AsString = "--DO Test--"
        lMain.FindField("DocDate").value = lDate
        lMain.FindField("PostDate").value = lDate
        lMain.FindField("Code").AsString = lDataSet.FindField("Code").AsString #Customer Account
        lMain.FindField("CompanyName").AsString = lDataSet.FindField("CompanyName").AsString
        #lMain.FindField("Address1").AsString = "" #Optional
        #lMain.FindField("Address2").AsString = "" #Optional
        #lMain.FindField("Address3").AsString = "" #Optional
        #lMain.FindField("Address4").AsString = "" #Optional
        #lMain.FindField("Phone1").AsString = ""   #Optional
        lMain.FindField("Project").AsString = lDataSet.FindField("DocProject").AsString
        lMain.FindField("Description").AsString = "Delivery Order"

        #Insert Data - Detail
        while not lDataSet.eof:
            lDetail.Append()
            lDetail.FindField("DtlKey").value = -1
            lDetail.FindField("DocKey").value = -1
            lDetail.FindField("Seq").value = lDataSet.FindField("Seq").Value
            lDetail.FindField("ItemCode").AsString = lDataSet.FindField("ItemCode").AsString
            lDetail.FindField("UOM").AsString = lDataSet.FindField("UOM").AsString
            lDetail.FindField("Qty").AsFloat = lDataSet.FindField("OSQty").AsFloat # Transfer all balance Qty
            lDetail.FindField("DISC").AsString = lDataSet.FindField("DISC").AsString
            lDetail.FindField("Tax").AsString = lDataSet.FindField("Tax").AsString
            lDetail.FindField("TaxRate").AsString = lDataSet.FindField("TaxRate").AsString
            lDetail.FindField("TaxInclusive").value = lDataSet.FindField("TaxInclusive").value 
            lDetail.FindField("UnitPrice").AsFloat = lDataSet.FindField("UnitPrice").AsFloat 
            lDetail.FindField("Amount").AsFloat = lDataSet.FindField("Amount").AsFloat 
            lDetail.FindField("TaxAmt").AsFloat = lDataSet.FindField("TaxAmt").AsFloat
            lDetail.FindField("Project").AsString = lDataSet.FindField("DtlProject").AsString
            lDetail.FindField("FromDocType").AsString = "SO"; #From Document Type
            lDetail.FindField("FromDockey").AsFloat = lDataSet.FindField("Dockey").AsFloat;
            lDetail.FindField("FromDtlkey").AsFloat = lDataSet.FindField("DtlKey").AsFloat;
            lDetail.Post()
            lDataSet.Next()
    
        BizObject.Save()
        BizObject.Close()
    else :
        print ("Record Not Found")
try:
    CheckLogin()
    print ("Posting SO to DO")
    PostData()
    print ("Done")
finally:
    ComServer.Logout()
    ComServer = None

Stock Month End - Weighted Average

Stock Month End - Weighted Average Script
#Updated 30 Nov 2021
import win32com.client
import datetime

ComServer = win32com.client.Dispatch("SQLAcc.BizApp")

def CheckLogin():
    B = ComServer.IsLogin
    if B == True:
        ComServer.Logout()
    ComServer.Login("FAUNG", "ADMIN", #UserName, Password
                    "D:\\Happy\\DB\\Default.DCF",
                   # "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                    "ACC-0011.FDB") #Database Name

def GetData():
    #Accuracy : 90% - Due to the figure is base on last run Costing in SQL Accounting
    lSQL = "SELECT A.ItemCode, A.Location, A.Batch,  MAX(B.Seq) AS Seq, 2 AS CostingMethod "
    lSQL = lSQL + "FROM ST_TR A INNER JOIN ST_TR_WMA B ON (A.TRANSNO=B.TRANSNO) "
    lSQL = lSQL + "WHERE A.PostDate<='31 Jul 2020' "
    lSQL = lSQL + "GROUP BY A.ItemCode, A.Location, A.Batch "
    
    lDataSet1 = ComServer.DBManager.NewDataSet(lSQL) 

    if lDataSet1.RecordCount > 0:
        lDataSet1.First()
        while not lDataSet1.eof:
            lSQL = "SELECT A.TRANSNO, A.ItemCode, A.Location, A.Batch, B.UTDQty, B.UTDCost FROM ST_TR A "
            lSQL = lSQL + "INNER JOIN ST_TR_WMA B ON (A.TRANSNO=B.TRANSNO) "
            lSQL = lSQL + "WHERE A.ITEMCODE= '" + lDataSet1.FindField("ItemCode").AsString + "' "
            lSQL = lSQL + "AND B.SEQ= " + lDataSet1.FindField("Seq").AsString
            lSQL = lSQL + " AND A.LOCATION='" + lDataSet1.FindField("Location").AsString + "' "
            lSQL = lSQL + " AND A.BATCH='" + lDataSet1.FindField("Batch").AsString + "' "
            lSQL = lSQL + "AND B.UTDQty<>0 "
            lSQL = lSQL + "ORDER BY A.ItemCode, A.Location, A.Batch "
            
            #print(lSQL)
            lDataSet2 = ComServer.DBManager.NewDataSet(lSQL)
            if lDataSet2.RecordCount > 0:
                lDataSet2.First()
                print("ITEMCODE = "+lDataSet2.FindField("ITEMCODE").AsString)
                print("LOCATION = "+lDataSet2.FindField("LOCATION").AsString)
                print("BATCH = "+lDataSet2.FindField("BATCH").AsString)
                print("UTDQTY = "+lDataSet2.FindField("UTDQTY").AsString)
                print("UTDCOST = "+lDataSet2.FindField("UTDCOST").AsString)
                print("=====")
            else :
                print ("Detail Record Not Found")
            lDataSet1.Next()
            
    else :
        print ("Record Not Found")
try:
    CheckLogin()
    print ("Month End - WA")
    GetData()
    print ("Done")
finally:
    ComServer.Logout()
    ComServer = None

Stock Month End - FIFO

Stock Month End - FIFO Script
#Updated 15 Feb 2022
import win32com.client
import datetime

ComServer = win32com.client.Dispatch("SQLAcc.BizApp")

def CheckLogin():
    B = ComServer.IsLogin
    if B == True:
        ComServer.Logout()
    ComServer.Login("FAUNG", "ADMIN", #UserName, Password
                    "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                    "ACC-0011.FDB") #Database Name

def GetData():
    #Accuracy : 90% - Due to the figure is base on last run Costing in SQL Accounting        

    lSQL = "SELECT A.TRANSNO, A.ItemCode, A.Location, A.Batch, B.QTY, B.COST FROM ST_TR A "
    lSQL = lSQL + "INNER JOIN ST_TR_FIFO B ON (A.TRANSNO=B.TRANSNO) "
    lSQL = lSQL + "WHERE B.COSTTYPE='U' "
    lSQL = lSQL + "AND A.PostDate<='31 Jul 2022' "
    lSQL = lSQL + "AND A.ITEMCODE ='ANT' "
    lSQL = lSQL + "AND B.Qty<>0 "
    lSQL = lSQL + "AND EXISTS (SELECT MAX(D.Seq) FROM ST_TR C "
    lSQL = lSQL + "            INNER JOIN ST_TR_FIFO D ON (C.TRANSNO=D.TRANSNO) "
    lSQL = lSQL + "            WHERE C.PostDate<='31 Jul 2022' "
    lSQL = lSQL + "            AND C.ItemCode ='ANT' "
    lSQL = lSQL + "            GROUP BY C.ItemCode, C.Location, C.Batch "
    lSQL = lSQL + "            HAVING B.SEQ=MAX(D.Seq) "
    lSQL = lSQL + "            ) "
    lSQL = lSQL + "ORDER BY A.ItemCode, A.Location, A.BATCH, A.TRANSNO "
    print(lSQL)
    lDataSet2 = ComServer.DBManager.NewDataSet(lSQL)
            
    if lDataSet2.RecordCount > 0: #Total Qty & Cost
        lDataSet2.First()
        while not lDataSet2.eof:
            print(" ")
            print("TRANSNO = "+lDataSet2.FindField("TRANSNO").AsString)
            print("ITEMCODE = "+lDataSet2.FindField("ITEMCODE").AsString)
            print("LOCATION = "+lDataSet2.FindField("LOCATION").AsString)
            print("BATCH = "+lDataSet2.FindField("BATCH").AsString)
            print("QTY = "+lDataSet2.FindField("QTY").AsString)
            print("COST = "+lDataSet2.FindField("COST").AsString)
            print("=====")
            print(" ")
            print("===Detail Cost===")
            lSQL = "SELECT TRANSNO, ITEMCODE, COSTSEQ, QTY, COST FROM ST_TR_FIFO "
            lSQL = lSQL + "WHERE ITEMCODE = '" + lDataSet2.FindField("ITEMCODE").AsString
            lSQL = lSQL + "' AND COSTTYPE='B' "
            lSQL = lSQL + "AND TRANSNO="+lDataSet2.FindField("TRANSNO").AsString
            lSQL = lSQL + " ORDER BY COSTSEQ"
                    
            lDataSet3 = ComServer.DBManager.NewDataSet(lSQL)

            if lDataSet3.RecordCount > 0: #Detail Cost
                lDataSet3.First()
                while not lDataSet3.eof:
                    print("TRANSNO = "+lDataSet3.FindField("TRANSNO").AsString)
                    print("ITEMCODE = "+lDataSet3.FindField("ITEMCODE").AsString)
                    print("COSTSEQ = "+lDataSet3.FindField("COSTSEQ").AsString)
                    print("QTY = "+lDataSet3.FindField("QTY").AsString)
                    print("COST = "+lDataSet3.FindField("COST").AsString)
                    print("D=====")
                    lDataSet3.Next()
            lDataSet2.Next()
    else :
        print("Detail Record Not Found")
                
try:
    CheckLogin()
    print ("Month End - FIFO")
    GetData()
    print ("Done")
finally:
    #ComServer.Logout()
    ComServer = None

Login 2 Database

Login 2 Database
#Updated 17 Mar 2022
import win32com.client
import datetime

ComServer = win32com.client.Dispatch("SQLAcc.BizApp")

def CheckLogin1():
    ComServer = None
    ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
    B = ComServer.IsLogin
    if B == True:
        ComServer.Logout()
    ComServer.Login("FAUNG", "ADMIN", #UserName, Password
                    "C:\\eStream\\SQLAccounting\\Share\\Default.DCF",  #DCF file
                    "ACC-0024.FDB") #Database Name


def CheckLogin2():
    ComServer = None
    ComServer = win32com.client.Dispatch("SQLAcc.BizApp")
    B = ComServer.IsLogin
    if B == True:
        ComServer.Logout()
    ComServer.Login("FAUNG", "ADMIN", #UserName, Password
                    "C:\\eStream\\SQLAccounting\\Share\\Default.DCF",  #DCF file
                    "ACC-0015.FDB") #Database Name
        
def GetData():    
    lSQL = "SELECT COUNT(*) Nos FROM AR_CUSTOMER A WHERE A.CODE LIKE '%300%' "
    
    try:
        lDataSet1 = ComServer.DBManager.NewDataSet(lSQL) 
        Seq = 0
        if lDataSet1.RecordCount > 0:
            lDataSet1.First()
            Seq = lDataSet1.FindField("Nos").Value
            print(Seq)
        else :
            print ("Record Not Found")
        
    finally:
        lDataSet1 = None

    
try:
    print ("Login 1st DB")
    CheckLogin1()
    GetData()
    print ("Done 1st DB")
    print ("Login 2nd DB")
    CheckLogin2()
    GetData()
    print ("Done 2nd DB")    
finally:
    ComServer.Logout()
    ComServer = None
    print ("Done...")

Get Stock Qty Balance

Get Stock Qty Balance
#Updated 18 Jan 2024
import Common

def GetData():
    lSQL = "SELECT  ItemCode, Location, Batch, Sum(Qty) Qty  FROM ST_TR   "
    lSQL = lSQL + "WHERE PostDate<='31 Dec 2019' "
    lSQL = lSQL + "AND ITEMCODE ='ANT' "
    lSQL = lSQL + "GROUP BY ItemCode, Location, Batch "
    
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
    
    if lDataSet.RecordCount > 0:
        while not lDataSet.eof:
            print(lDataSet.FindField('ItemCode').AsString)
            print(lDataSet.FindField('Location').AsString)
            print(lDataSet.FindField('Batch').AsString)
            print(lDataSet.FindField('Qty').AsString)
            print("===")
            lDataSet.Next()
    else:
        print ("Record Not Found")
    
try:
    Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer      
    GetData()
finally:
    ComServer = None
    Common.KillApp()

Maintain Asset Item

Maintain Asset Item
#Updated 03 Oct 2023
import Common
import datetime
       
def GetListData():
    lSQL = "SELECT A.DOCNOEX, A.ACQUIREDATE, A.CODE, A.DESCRIPTION, A.ASSETGROUP, "
    lSQL = lSQL + "A.AGENT, A.AREA, A.COST, A.USEFULLIFE, A.DEPRRATE, A.RESIDUAL, "
    lSQL = lSQL + "B.POSTDATE, B.DESCRIPTION HISTORYDESC "
    lSQL = lSQL + "FROM FA_ITEM A "
    lSQL = lSQL + "INNER JOIN FA_ITEM_HISTORY B ON (A.Code=B.Code) "
    lSQL = lSQL + "WHERE A.STATUS=1 " #1 = Active 2 = InActive    
    
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
        
    Common.ShowResult(lDataSet)

def GetAutoKey(ACode):
    lSQL = "SELECT AUTOKEY FROM FA_ITEM "
    lSQL = lSQL + "WHERE Code= ' + Common.QuotedStr(ACode)
    
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
    return lDataSet.FindField("AutoKey").AsFloat

def PostData():
    BizObject = ComServer.BizObjects.Find("FA.Item.OPF")
    lMain = BizObject.DataSets.Find("Main") #lMain contains master data
    lProj = BizObject.DataSets.Find("Project") #lProj contains Project data
    lDepr = BizObject.DataSets.Find("DeprSche") #lDepr contains Depreciation Scheduler data
    lHist = BizObject.DataSets.Find("History") #lHist contains History data
    
    lDate = datetime.datetime(2023, 2, 22, 13, 0)
    lDate.strftime('%m/%d/%Y')
    
    lDocKey = GetAutoKey("--FA Test--")
        
    if lDocKey == 0:
        BizObject.New()
        lMain.FindField("Code").AsString = "--FA Test--"
        lMain.FindField("Description").AsString = "5ft Banquet Table"
        lMain.FindField("AcquireDate").value = lDate
        lMain.FindField("AssetGroup").AsString = "Default"
        lMain.FindField("Cost").AsFloat = 6190.50
        lMain.FindField("UsefulLife").AsFloat = 3
        lMain.FindField("Residual").AsFloat = 1
        lMain.FindField("DocNoEx").AsString = "IV-321578"
        lMain.FindField("Qty").AsFloat = 100

        #Insert Data - Depreciation Schedule
        lDate = datetime.datetime(2024, 9, 3, 13, 0)
        lDate.strftime('%m/%d/%Y')
        
        lDepr.Append()
        lDepr.FindField("SCHEDATE").value       = lDate
        lDepr.FindField("Description").AsString = "Depreciation 1/3"
        lDepr.FindField("AMOUNT").AsFloat       = 2063.17
        lDepr.Post()

        lDate = datetime.datetime(2025, 9, 3, 13, 0)
        lDate.strftime('%m/%d/%Y')
        
        lDepr.Append()
        lDepr.FindField("SCHEDATE").value       = lDate
        lDepr.FindField("Description").AsString = "Depreciation 2/3"
        lDepr.FindField("AMOUNT").AsFloat       = 2063.17
        lDepr.Post()

        lDate = datetime.datetime(2026, 9, 3, 13, 0)
        lDate.strftime('%m/%d/%Y')

        lDepr.Append()
        lDepr.FindField("SCHEDATE").value       = lDate
        lDepr.FindField("Description").AsString = "Depreciation 3/3"
        lDepr.FindField("AMOUNT").AsFloat       = 2063.16
        lDepr.Post()        

        #Insert Data - Hisory   
        lDate = datetime.datetime(2023, 1, 20, 13, 0)
        lDate.strftime('%m/%d/%Y')
        
        lHist.Append()
        lHist.FindField("PostDate").value = lDate
        lHist.FindField("Description").AsString = "Supplier ABC 4 Units"
        lHist.Post()
        
        lDate = datetime.datetime(2023, 2, 22, 13, 0)
        lDate.strftime('%m/%d/%Y')
        
        lHist.Append()
        lHist.FindField("PostDate").value = lDate
        lHist.FindField("Description").AsString = "Supplier XYZ Sdn Bhd 6 Units"
        lHist.Post()
        
        #Insert Data - Project
        lProj.Edit()
        lProj.FindField("Project").AsString = "KL"
        lProj.FindField("Rate").AsFloat = 40.00
        lProj.Post()
        
        lProj.Append()
        lProj.FindField("Project").AsString = "JB"
        lProj.FindField("Rate").AsFloat = 60.00
        lProj.Post()           
    else:
        BizObject.Params.Find("Autokey").AsString = lDocKey
        BizObject.Open()
        BizObject.Edit()
        lMain.Edit()
        lMain.FindField("Description").AsString = "Edited 5ft Banquet Tables"

        #Delete all Project
        while lProj.RecordCount != 0:
            lProj.First()
            lProj.Delete()
            
        lProj.Append()
        lProj.FindField("Project").AsString = "----"
        lProj.FindField("Rate").AsFloat = 10.00
        lProj.Post()
        
        lProj.Append()
        lProj.FindField("Project").AsString = "KL"
        lProj.FindField("Rate").AsFloat = 40.00
        lProj.Post()

        lProj.Append()
        lProj.FindField("Project").AsString = "JB"
        lProj.FindField("Rate").AsFloat = 50.00
        lProj.Post()      
        
        #Insert Data - Hisory   
        lDate = datetime.datetime(2023, 2, 10, 13, 0)
        lDate.strftime('%m/%d/%Y')
        
        lHist.Append()
        lHist.FindField("PostDate").value = lDate
        lHist.FindField("Description").AsString = "1 of table leg broken"
        lHist.Post()        
    try:
        BizObject.Save()          
    except Exception as e:
        print("Oops!", e)    
    BizObject.Close()
    print ("Posting/Update Done")

def DelData():
    BizObject = ComServer.BizObjects.Find("FA.Item.OPF")
    
    lDocKey = GetAutoKey("--FA Test--")
        
    if lDocKey == 0:
        print ("Record Not Found")
    else:
        BizObject.Params.Find("Autokey").AsString = lDocKey
        BizObject.Open()
        BizObject.Delete()        
        print ("Deleting Done")

try:
    Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
    GetListData()
    PostData()
    
    answer = input("Continue To delete?")
    if answer.lower() in ["y","yes"]:
        DelData()
    elif answer.lower() in ["n","no"]:
        print ("Deleting Aborted")
    else:
       print ("Invalid Input")
       
    ComServer.Logout()   
finally:
    ComServer = None
    Common.KillApp()

Customer Payment

AR_PM
#Updated 04 Dec 2023
import Common
import datetime
       
def GetListData():
    lSQL = "SELECT A.DOCNO, A.DOCDATE, A.CODE, B.COMPANYNAME, A.DESCRIPTION, A.DOCAMT, "
    lSQL = lSQL + "A.AGENT, A.AREA, A.PAYMENTMETHOD "
    lSQL = lSQL + "FROM AR_PM A "
    lSQL = lSQL + "INNER JOIN AR_CUSTOMER B ON (A.CODE=B.CODE) "
    lSQL = lSQL + "WHERE A.CODE='300-A0002' "
    lSQL = lSQL + "AND A.CANCELLED='F' "
    
    lDataSet = ComServer.DBManager.NewDataSet(lSQL)
        
    Common.ShowResult(lDataSet)

def PostData():
    BizObject = ComServer.BizObjects.Find("AR_PM")
    lMain = BizObject.DataSets.Find("MainDataSet") #lMain contains master data
    lDetail = BizObject.DataSets.Find("cdsKnockOff") #lDetail contains detail data
    
    lDate = datetime.datetime(2023, 2, 22, 13, 0)
    lDate.strftime('%m/%d/%Y')
    
    lDocKey = BizObject.FindKeyByRef("DocNo", "--PM Test--")
        
    if lDocKey is None:
        BizObject.New()
        lMain.FindField("DocNo").AsString = "--PM Test--"
        lMain.FindField("DocDate").value = lDate
        lMain.FindField("PostDate").value = lDate
        lMain.FindField("Code").AsString = "300-C0001" #Customer Account
        lMain.FindField("Description").AsString = "Payment for A/c"
        lMain.FindField("PaymentMethod").AsString = "325-000" #Bank or Cash Account
        lMain.FindField("ChequeNumber").AsString = ""
        lMain.FindField("BankCharge").AsFloat = 0
        lMain.FindField("DocAmt").AsFloat = 10000.00
        lMain.FindField("Cancelled").AsString = "F"    

        #Knock Off IV  
        V = ["IV", "--IV Test--"]  #DocType, DocNo
        if (lDetail.Locate("DocType;DocNo", V, False, False)) :
            lDetail.Edit()
            lDetail.FindField("KOAmt").AsFloat = 147.09 #Partial Knock off
            lDetail.FindField("KnockOff").AsString = "T"
            lDetail.Post()
    else:
        BizObject.Params.Find("Dockey").Value = lDocKey
        BizObject.Open()
        BizObject.Edit()
        lMain.Edit()
        lMain.FindField("Description").AsString = "Edited Payment for A/c 的第一 🐱"

        #Knock Off IV  
        V = ["IV", "--IV Test--"]  #DocType, DocNo
        if (lDetail.Locate("DocType;DocNo", V, False, False)) :
            lDetail.Edit()
            lDetail.FindField("KOAmt").AsFloat = 200.09 #Partial Knock off
            lDetail.FindField("KnockOff").AsString = "T"
            lDetail.Post()
        
    try:
        BizObject.Save()          
    except Exception as e:
        print("Oops!", e)    
    BizObject.Close()
    print ("Posting/Update Done")

def DelData():
    #Deleting only work if the record never not knock off by Refund
    BizObject = ComServer.BizObjects.Find("AR_PM")
    
    lDocKey = BizObject.FindKeyByRef("DocNo", "--PM Test--")
        
    if lDocKey is None:
        print ("Record Not Found")
    else:
        BizObject.Params.Find("Dockey").Value = lDocKey
        BizObject.Open()
        BizObject.Delete()        
        print ("Deleting Done")

try:
    Common.CheckLogin()
    global ComServer
    ComServer = Common.ComServer
    GetListData()
    PostData()
    
    answer = input("Continue To delete?")
    if answer.lower() in ["y","yes"]:
        DelData()
    elif answer.lower() in ["n","no"]:
        print ("Deleting Aborted")
    else:
       print ("Invalid Input")
       
    ComServer.Logout()   
finally:
    ComServer = None
    Common.KillApp()


PHP

  • Tested PHP Version : 7.4.3/8.1.10
  • Add this in ..\xampp\php\php.ini
 [PHP_COM_DOTNET]
 extension=php_com_dotnet.dll
  • Grid.css file for example code
Grid.css file
body 
{
  margin: 10;
}
table {
  font-family: arial, sans-serif;
  border: 1px solid black;
  border-collapse: collapse;
  table-layout: auto;
}

td, th {
  border: 1px solid black;
  text-align: left;
  padding: 8px;
  white-space: nowrap;
}

tr:nth-child(even) {
  background-color: #dddddd;
}

Get Agent

Get Agent Script
<!DOCTYPE html>
<html>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 01 May 2020<br>";

$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\\eStream\\SQLAccounting\\Share\\Default.DCF",  #DCF file
                      "ACC-0082.FDB"); #Database Name
    
}

function GetData()
{
    global $ComServer;

    $lSQL = "SELECT * FROM AGENT 
	         WHERE CODE='HALIM'";

    $lDataSet = $ComServer->DBManager->NewDataSet($lSQL);

    if ($lDataSet->RecordCount > 0)
    {
        echo "Result : ";
        echo $lDataSet->FindField('Description')->AsString() . "<br>";
    }
    else
    {
        echo "Record Not Found";
    }
}

if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
        GetData();
        echo date("d M Y h:i:s A") . " - Done";
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?>
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Get Agent"/> 
    </form> 
</body>
</html>

Add & Edit Agent

Add & Edit Agent Script
<!DOCTYPE html>
<html>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 01 May 2020<br>";

$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\\eStream\\SQLAccounting\\Share\\Default.DCF",  #DCF file
                      "ACC-0082.FDB"); #Database Name
    
}

function PostData(){
	global $ComServer;
	
    $BizObject = $ComServer->BizObjects->Find("Agent");
    $lMain = $BizObject->DataSets->Find("MainDataSet");
    
    $lDocKey = $BizObject->FindKeyByRef("CODE", "FAIRY");
	
	if ($lDocKey == null){
        $BizObject->New();
        $lMain->FindField("CODE")->value = "FAIRY";
        $lMain->FindField("DESCRIPTION")->value = "FAIRY TAIL";
	} else{
        $BizObject->Params->Find("CODE")->Value = $lDocKey;
        $BizObject->Open();
        $BizObject->Edit();
        $lMain->FindField("DESCRIPTION")->value = "FAIRY TAIL WIZARD";
	}
	try{
		$BizObject->Save();
		echo "Posting Done <br>";
	}catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}
	
}

if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
        PostData();
        echo date("d M Y h:i:s A") . " - Done";
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?>
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Add/Edit Agent"/> 
    </form> 
</body>
</html>

Delete Agent

Delete Agent Script
<!DOCTYPE html>
<html>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 01 May 2020<br>";

$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\\eStream\\SQLAccounting\\Share\\Default.DCF",  #DCF file
                      "ACC-0082.FDB"); #Database Name
    
}

function PostData(){
	global $ComServer;
	
    $BizObject = $ComServer->BizObjects->Find("Agent");
    $lMain = $BizObject->DataSets->Find("MainDataSet");
    
    $lDocKey = $BizObject->FindKeyByRef("CODE", "FAIRY");
	
	if ($lDocKey == null){
        echo "Record Not Found";
	} else{
        $BizObject->Params->Find("CODE")->Value = $lDocKey;
        $BizObject->Open();
        $BizObject->Delete();
        echo "Delete Done<br>";
	}	
}

if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
        PostData();
        echo date("d M Y h:i:s A") . " - Done";
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?>
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Delete Agent"/> 
    </form> 
</body>
</html>

Complete Post

SL_CS, AR_PM, SL_CN & AR_CN Script
<!DOCTYPE html>
<html>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 01 May 2020<br>";
#This will doing following posting
#01. Cash Sales - SL_CS
#02. Sales Credit Note - SL_CN
#03. Customer Payment With Knock off - AR_PM
#04. Edit Credit Note Posted in Step 02 & Knock Off - AR_CN
#05. Customer Refund to Knock off Credit Note - AR_CF

$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\\eStream\\SQLAccounting\\Share\\Default.DCF",  #DCF file
                      "ACC-0082.FDB"); #Database Name
    
}

function PostDataCS(){
	global $ComServer;
	
	$BizObject = $ComServer->BizObjects->Find("SL_CS");
    $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
	
    $BizObject->New();
    $lMain->FindField("DocKey")->value = -1;
    $lMain->FindField("DocNo")->AsString = "--CS Test--";
    $lMain->FindField("DocDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("PostDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("Code")->AsString = "300-C0001"; #Customer Account
    $lMain->FindField("CompanyName")->AsString = "Cash Sales";
    $lMain->FindField("Address1")->AsString = ""; #Optional
    $lMain->FindField("Address2")->AsString = ""; #Optional
    $lMain->FindField("Address3")->AsString = ""; #Optional
    $lMain->FindField("Address4")->AsString = ""; #Optional
    $lMain->FindField("Phone1")->AsString = "";   #Optional
    $lMain->FindField("Description")->AsString = "Sales";
	
    #Insert Data - Detail
    #For Tax Inclusive = True with override Tax Amount
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 1;
    $lDetail->FindField("Account")->AsString = "500-000"; #Sales Account
    $lDetail->FindField("Description")->AsString = "Sales Item A";
	
	$txt = <<<EOT
           Item A Line 1
           Item A Line 2
           EOT;
	
    $lDetail->FindField("Description3")->AsString = $txt;
    $lDetail->FindField("Qty")->AsFloat = 1;
    $lDetail->FindField("Tax")->AsString = "SV";
    $lDetail->FindField("TaxRate")->AsString = "6%";
    $lDetail->FindField("TaxInclusive")->value = 0;
    $lDetail->FindField("UnitPrice")->AsFloat = 435;
    $lDetail->FindField("Amount")->AsFloat = 410.37; #Exclding GST Amt
    $lDetail->FindField("TaxAmt")->AsFloat = 24.63;

    $lDetail->DisableControls();
    $lDetail->FindField("TaxInclusive")->value = 1;
    $lDetail->EnableControls();    
    $lDetail->Post();
	
    #For Tax Inclusive = False with override Tax Amount
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 2;
    $lDetail->FindField("Account")->AsString = "500-000";
    $lDetail->FindField("Description")->AsString = "Sales Item B";
    $lDetail->FindField("Qty")->AsFloat = 1;
    $lDetail->FindField("Tax")->AsString = "SV";
    $lDetail->FindField("TaxRate")->AsString = "6%";
    $lDetail->FindField("TaxInclusive")->value = 0;
    $lDetail->FindField("UnitPrice")->AsFloat = 94.43;
    $lDetail->FindField("Amount")->AsFloat = 94.43;
    $lDetail->FindField("TaxAmt")->AsFloat = 5.66;
    $lDetail->Post();
	
    #For With Item Code
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 3;
    $lDetail->FindField("ItemCode")->AsString = "ANT";
    $lDetail->FindField("Description")->AsString = "Sales Item B";
    #$lDetail->FindField("Account")->AsString = "500-000"; #If you wanted override the Sales Account Code
    $lDetail->FindField("UOM")->AsString = "UNIT";
    $lDetail->FindField("Qty")->AsFloat = 2;
    #$lDetail->FindField("DISC")->AsString = "5%+3"; #Optional(eg 5% plus 3 Discount)
    $lDetail->FindField("Tax")->AsString = "SV";
    $lDetail->FindField("TaxRate")->AsString = "6%";
    $lDetail->FindField("TaxInclusive")->value = 0;
    $lDetail->FindField("UnitPrice")->AsFloat = 100;
    $lDetail->FindField("Amount")->AsFloat = 200;
    $lDetail->FindField("TaxAmt")->AsFloat = 12;
    $lDetail->Post();
	
    $BizObject->Save();
    $BizObject->Close();	
}

function PostDataPM(){
	global $ComServer;
	
    $BizObject = $ComServer->BizObjects->Find("AR_PM");
    $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
    $lDetail = $BizObject->DataSets->Find("cdsKnockOff"); #lDetail contains detail data
	
    $BizObject->New();
    $lMain->FindField("DOCKEY")->Value = -1;
    $lMain->FindField("DocNo")->AsString = "--PM Test--";
    $lMain->FindField("CODE")->AsString = "300-C0001"; #Customer Account
    $lMain->FindField("DocDate")->Value = "04/23/2020"; #MM/DD/YYYY
    $lMain->FindField("PostDate")->Value = "04/23/2020"; #MM/DD/YYYY
    $lMain->FindField("Description")->AsString = "Payment for A/c";
    $lMain->FindField("PaymentMethod")->AsString = "320-000"; #Bank or Cash Account
    $lMain->FindField("ChequeNumber")->AsString = "";
    $lMain->FindField("BankCharge")->AsFloat = 0;
    $lMain->FindField("DocAmt")->AsFloat = 200.00;
    $lMain->FindField("Cancelled")->AsString = "F";

    #Knock Off IV  
    $V = array("IV", "--CS Test--");  #DocType, DocNo
    
    if ($lDetail->Locate("DocType;DocNo", $V, False, False)) {
        $lDetail->Edit();
        $lDetail->FindField("KOAmt")->AsFloat = 147.09; #Partial Knock off
        $lDetail->FindField("KnockOff")->AsString = "T";
        $lDetail->Post();
	}	
    $BizObject->Save();
    $BizObject->Close();
}

function PostDataCN(){
	global $ComServer;
	
	$BizObject = $ComServer->BizObjects->Find("SL_CN");
    $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
	
    $BizObject->New();
    $lMain->FindField("DocKey")->value = -1;
    $lMain->FindField("DocNo")->AsString = "--CN Test--";
    $lMain->FindField("DocDate")->value = "04/23/2020"; #MM/DD/YYYY
    $lMain->FindField("PostDate")->value = "04/23/2020"; #MM/DD/YYYY
    $lMain->FindField("Code")->AsString = "300-C0001";
    $lMain->FindField("CompanyName")->AsString = "Cash Sales";
    $lMain->FindField("Address1")->AsString = "";
    $lMain->FindField("Address2")->AsString = "";
    $lMain->FindField("Address3")->AsString = "";
    $lMain->FindField("Address4")->AsString = "";
    $lMain->FindField("Phone1")->AsString = "";
    $lMain->FindField("Description")->AsString = "Sales Returned";
	
    #For With Item Code
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("ItemCode")->AsString = "ANT";
    $lDetail->FindField("Description")->AsString = "Sales Item B";
    $lDetail->FindField("Description2")->AsString = "Product Spoil"; #Reason
    $lDetail->FindField("Remark1")->AsString = "--CS Test--";   #Invoice No
    $lDetail->FindField("Remark2")->AsString = "20 Apr 2020";   #Invoice Date
    $lDetail->FindField("Qty")->AsFloat = 1;
    $lDetail->FindField("Tax")->AsString = "SV";
    $lDetail->FindField("TaxRate")->AsString = "6%";
    $lDetail->FindField("TaxInclusive")->value = 0;
    $lDetail->FindField("UnitPrice")->AsFloat = 100;
    $lDetail->FindField("Amount")->AsFloat = 100;
    $lDetail->FindField("TaxAmt")->AsFloat = 6;
    $lDetail->Post();
	
    $BizObject->Save();
    $BizObject->Close();	
}

function PostKnockIVCN(){
	global $ComServer;
	
    $BizObject = $ComServer->BizObjects->Find("AR_CN");
    $lMain = $BizObject->DataSets->Find("MainDataSet");
    $lDetail = $BizObject->DataSets->Find("cdsKnockOff");
	
    #Find CN Number
    $lDocNo = "--CN Test--";
    $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
    $BizObject->Params->Find("DocKey")->AsString = $lDocKey;
	
	if ($lDocKey != null){
        $BizObject->Open();
        $BizObject->Edit();
        $lMain->Edit();
        
        #Knock Off IV        
        $V = array("IV", "--CS Test--");  #DocType, DocNo
        
        if ($lDetail->Locate("DocType;DocNo", $V, False, False)){
            $lDetail->Edit();
            $lDetail->FindField("KOAmt")->AsFloat = 100; #Partial Knock off
            $lDetail->FindField("KnockOff")->AsString = "T";
            $lDetail->Post();
		}
        $BizObject->Save();
        $BizObject->Close();		
	}
}

function PostDataCF(){
	global $ComServer;
	
    $BizObject = $ComServer->BizObjects->Find("AR_CF");
    $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
    $lDetail = $BizObject->DataSets->Find("cdsKnockOff"); #lDetail contains detail data
	
    $BizObject->New();
    $lMain->FindField("DOCKEY")->Value = -1;
    $lMain->FindField("DocNo")->AsString = "--CF Test--";
    $lMain->FindField("CODE")->AsString = "300-C0001"; #Customer Account
    $lMain->FindField("DocDate")->Value = "04/23/2020"; #MM/DD/YYYY
    $lMain->FindField("PostDate")->Value = "04/23/2020"; #MM/DD/YYYY
    $lMain->FindField("Description")->AsString = "Payment for A/c";
    $lMain->FindField("PaymentMethod")->AsString = "320-000"; #Bank or Cash Account
    $lMain->FindField("ChequeNumber")->AsString = "";
    $lMain->FindField("BankCharge")->AsFloat = 0;
    $lMain->FindField("DocAmt")->AsFloat = 6;
    $lMain->FindField("Cancelled")->AsString = "F";

    #Knock Off CN 
    $V = array("CN", "--CN Test--");  #DocType, DocNo
    
    if ($lDetail->Locate("DocType;DocNo", $V, False, False)) {
        $lDetail->Edit();
        $lDetail->FindField("KOAmt")->AsFloat = 4; #Partial Knock off
        $lDetail->FindField("KnockOff")->AsString = "T";
        $lDetail->Post();
	}	
    $BizObject->Save();
    $BizObject->Close();
}

if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
        echo date("d M Y h:i:s A")." - Posting Cash Sales<br>";
        PostDataCS();
        echo date("d M Y h:i:s A")." - Posting Customer Payment<br>";
        PostDataPM();
        echo date("d M Y h:i:s A")." - Posting Sales Credit Note<br>";
        PostDataCN();
        echo date("d M Y h:i:s A")." - Posting Knock Off Sales Credit Note<br>";
        PostKnockIVCN();
        echo date("d M Y h:i:s A")." - Posting Customer Refund<br>";
        PostDataCF();
        echo date("d M Y h:i:s A")." - Posting Done";
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Complete Post"/> 
    </form> 
</body>
</html>

Get Invoice Next Number

Get Invoice Next Number Script
<!DOCTYPE html>
<html>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 01 May 2020<br>";
#This action to Get Next Number for Customer Invoice

$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\\eStream\\SQLAccounting\\Share\\Default.DCF",  #DCF file
                      "ACC-0082.FDB"); #Database Name
    
}

function GetData(){
	global $ComServer;
	
    $lSQL = "SELECT A.*, B.NEXTNUMBER FROM SY_DOCNO A 
	         INNER JOIN SY_DOCNO_DTL B ON (A.DOCKEY=B.PARENTKEY)
			 WHERE A.DOCTYPE='IV'
			 AND A.DESCRIPTION='Customer Invoice'
			 AND A.STATESET=1
			 ";
	
	$lDataSet = $ComServer->DBManager->NewDataSet($lSQL);

    if ($lDataSet->RecordCount > 0) {
		$lDataSet->First();
        $fmt = $lDataSet->FindField('Format')->AsString();
        $NextNo = $lDataSet->FindField('NEXTNUMBER')->AsFloat();
		
        echo date("d M Y h:i:s A")." Format in SQLAcc : " . str_ireplace("d","s", $fmt)."<br>";
        $fmt= str_ireplace(".","'0", $fmt);
        echo date("d M Y h:i:s A")." Format in PHP : " . str_ireplace("d","s", $fmt)."<br>";
		echo date("d M Y h:i:s A")." Output in PHP : " .sprintf($fmt,$NextNo)."<br>";
	}else {
    echo "Record Not Found";
    }
}

if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
        GetData();
        echo date("d M Y h:i:s A")." - Done";
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Get Doc Number"/> 
    </form> 
</body>
</html>

Add & Edit AR_Customer

Add & Edit AR_Customer Script
<!DOCTYPE html>
<html>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 11 Jun 2020<br>";

$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\\eStream\\SQLAccounting\\Share\\Default.DCF", #DCF File 
                      "ACC-0035.FDB"); #Database Name
    
}

function PostData(){
	global $ComServer;
	
    $BizObject = $ComServer->BizObjects->Find("AR_Customer");
    $lMain = $BizObject->DataSets->Find("MainDataSet");
	$lDtl  = $BizObject->DataSets->Find("cdsBranch");
    
    $lDocKey = $BizObject->FindKeyByRef("CODE", "FAIRY");
	
	if ($lDocKey == null){
        $BizObject->New();
        $lMain->FindField("CODE")->value = "FAIRY";
        $lMain->FindField("CompanyName")->value = "FAIRY TAIL";
		
        $lDtl->Edit(); #For 1St Branch
        $lDtl->FindField("BranchName")->AsString  = "BILLING";
        $lDtl->FindField("Address1")->AsString    = "Address1";
        $lDtl->FindField("Address2")->AsString    = "Address2";
        $lDtl->FindField("Address3")->AsString    = "Address3";
        $lDtl->FindField("Address4")->AsString    = "Address4"; 
        $lDtl->FindField("Attention")->AsString   = "Attention"; 
        $lDtl->FindField("Phone1")->AsString      = "Phone1";
        $lDtl->FindField("Fax1")->AsString        = "Fax1";
        $lDtl->FindField("Email")->AsString       = "EmailAddress";
        $lDtl->Post();

        $lDtl->Append(); #For 2nd Branch
        $lDtl->FindField("BranchName")->AsString  = "Branch1";
        $lDtl->FindField("Address1")->AsString    = "DAddress1";
        $lDtl->FindField("Address2")->AsString    = "DAddress2";
        $lDtl->FindField("Address3")->AsString    = "DAddress3";
        $lDtl->FindField("Address4")->AsString    = "DAddress4";  
        $lDtl->FindField("Attention")->AsString   = "DAttention";  
        $lDtl->FindField("Phone1")->AsString      = "DPhone1";
        $lDtl->FindField("Fax1")->AsString        = "DFax1";
        $lDtl->FindField("Email")->AsString       = "DEmailAddress";
        $lDtl->Post();	
	} else{
        $BizObject->Params->Find("CODE")->Value = $lDocKey;
        $BizObject->Open();
        $BizObject->Edit();
        $lMain->FindField("CompanyName")->value = "FAIRY TAIL WIZARD";
		
		$r = $lDtl->RecordCount();
		$x = 1;
		while ($x <= $r ){
			$lDtl->First();
            $lDtl->Delete();
			$x++;
		}
		
        #Insert back with new Information
        $lDtl->Edit(); #For 1St Branch
        $lDtl->FindField("BranchName")->AsString  = "BILLING"; #Make sure this always same as b4 delete data
        $lDtl->FindField("Address1")->AsString    = "New Address1";
        $lDtl->FindField("Address2")->AsString    = "New Address2";
        $lDtl->FindField("Address3")->AsString    = "New Address3";
        $lDtl->FindField("Address4")->AsString    = "New Address4";  
        $lDtl->FindField("Attention")->AsString   = "New Attention";  
        $lDtl->FindField("Phone1")->AsString      = "New Phone1";
        $lDtl->FindField("Fax1")->AsString        = "New Fax1";
        $lDtl->FindField("Email")->AsString       = "New EmailAddress";
        $lDtl->Post();

        $lDtl->Append(); #For 2nd Branch
        $lDtl->FindField("BranchName")->AsString  = "Branch1"; #Make sure this always same as b4 delete data
        $lDtl->FindField("Address1")->AsString    = "New DAddress1";
        $lDtl->FindField("Address2")->AsString    = "New DAddress2";
        $lDtl->FindField("Address3")->AsString    = "New DAddress3";
        $lDtl->FindField("Address4")->AsString    = "New DAddress4"; 
        $lDtl->FindField("Attention")->AsString   = "New DAttention";  
        $lDtl->FindField("Phone1")->AsString      = "New DPhone1";
        $lDtl->FindField("Fax1")->AsString        = "New DFax1";
        $lDtl->FindField("Email")->AsString       = "New DEmailAddress";
        $lDtl->Post();	
	
	}
	try{
		$BizObject->Save();
		echo "Posting Done <br>";
	}catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}
	
}

if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
        PostData();
        echo date("d M Y h:i:s A") . " - Done";
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?>
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Add/Edit AR Customer"/> 
    </form> 
</body>
</html>

Get Stock List

Get Stock List Script
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/Grid.css" />
</head>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 22 Jun 2020<br>";
#This action to Get Stock Item List

$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0024.FDB"); #Database Name
    
}

function GetData(){
	global $ComServer;
	
    $lSQL = "SELECT A.*, B.UOM, B.RATE, B.REFCOST, B.REFPRICE, B.ISBASE FROM ST_ITEM A 
	         INNER JOIN ST_ITEM_UOM B ON (A.CODE=B.CODE) 
			 WHERE A.ISACTIVE='T'
			 ";
	
	$lDataSet = $ComServer->DBManager->NewDataSet($lSQL);

    if ($lDataSet->RecordCount > 0) {
		$lDataSet->First();
		$fc = $lDataSet->Fields->Count-1;
		echo "<table>";
		echo "<tr>";
		for ($x = 0; $x <= $fc; $x++) {
			#Insert Header
			echo "<td>".$lDataSet->Fields->Items($x)->FieldName()."</td>"; 
		}
		echo "</tr>";
		
		#Looping Dataset
		while (! $lDataSet->Eof()){
			echo "<tr>";
		    for ($x = 0; $x <= $fc; $x++) {
				$lFN = $lDataSet->Fields->Items($x)->FieldName();
			    echo "<td>".$lDataSet->FindField($lFN)->AsString()."</td>"; 
		    }
		    echo "</tr>";
			$lDataSet->Next();
		}	
		echo "</table>"."<br>";		
	}else {
    echo "Record Not Found";
    }
}

if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
        GetData();
        echo date("d M Y h:i:s A")." - Done";
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Get Stock list"/> 
    </form> 
</body>
</html>

AR_IV

AR_IV Script
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/Grid.css" />
</head>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 24 Jun 2020<br>";
#This action to Post Customer Invoice

$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0070.FDB"); #Database Name
    
}

function PostData(){
	global $ComServer;
	
	$BizObject = $ComServer->BizObjects->Find("AR_IV");
    $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
	
    $BizObject->New();
    $lMain->FindField("DocKey")->value = -1;
    $lMain->FindField("DocNo")->AsString = "--IV Test--";
    $lMain->FindField("DocDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("PostDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("Code")->AsString = "300-C0001"; #Customer Account
    $lMain->FindField("Description")->AsString = "Sales";
	
    #Insert Data - Detail
    #For Tax Inclusive = True with override Tax Amount
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 1;
    $lDetail->FindField("Account")->AsString = "500-000"; #Sales Account
    $lDetail->FindField("Description")->AsString = "Sales Item A";
    $lDetail->FindField("Tax")->AsString = "SV";
    $lDetail->FindField("TaxRate")->AsString = "6%";
    $lDetail->FindField("TaxInclusive")->value = 0;
    $lDetail->FindField("Amount")->AsFloat = 410.37; #Exclding GST Amt
    $lDetail->FindField("TaxAmt")->AsFloat = 24.63;

    $lDetail->DisableControls();
    $lDetail->FindField("TaxInclusive")->value = 1;
    $lDetail->EnableControls();    
    $lDetail->Post();
	
    #For Tax Inclusive = False with override Tax Amount
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 2;
    $lDetail->FindField("Account")->AsString = "500-000";
    $lDetail->FindField("Description")->AsString = "Sales Item B";
    $lDetail->FindField("Tax")->AsString = "SV";
    $lDetail->FindField("TaxRate")->AsString = "6%";
    $lDetail->FindField("TaxInclusive")->value = 0;
    $lDetail->FindField("Amount")->AsFloat = 94.43;
    $lDetail->FindField("TaxAmt")->AsFloat = 5.66;
    $lDetail->Post();
	
    $BizObject->Save();
    $BizObject->Close();	
}

if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
		PostData();
        echo date("d M Y h:i:s A")." - Done";
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Post Customer Invoice"/> 
    </form> 
</body>
</html>

Get Outstanding Invoice List

Get Outstanding Invoice List Script
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/Grid.css" />
</head>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 24 Jun 2020<br>";
#This action to Get Outstanding Invoice List

$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0024.FDB"); #Database Name
    
}

function GetData(){
	global $ComServer;
	
    $lSQL = "SELECT A.*, B.COMPANYNAME, (A.DOCAMT-A.PAYMENTAMT) OUTSTANDING  FROM AR_IV A
	         INNER JOIN AR_CUSTOMER B ON (A.CODE=B.CODE) 
			 WHERE (A.DOCAMT-A.PAYMENTAMT)<>0
			 AND CANCELLED='F'
			 ";
	
	$lDataSet = $ComServer->DBManager->NewDataSet($lSQL);

    if ($lDataSet->RecordCount > 0) {
		$lDataSet->First();
		$fc = $lDataSet->Fields->Count-1;
		echo "<table>";
		echo "<tr>";
		for ($x = 0; $x <= $fc; $x++) {
			#Insert Header
			echo "<td>".$lDataSet->Fields->Items($x)->FieldName()."</td>"; 
		}
		echo "</tr>";
		
		#Looping Dataset
		while (! $lDataSet->Eof()){
			echo "<tr>";
		    for ($x = 0; $x <= $fc; $x++) {
				$lFN = $lDataSet->Fields->Items($x)->FieldName();
			    echo "<td>".$lDataSet->FindField($lFN)->AsString()."</td>"; 
		    }
		    echo "</tr>";
			$lDataSet->Next();
		}	
		echo "</table>"."<br>";		
	}else {
    echo "Record Not Found";
    }
}

if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
        GetData();
        echo date("d M Y h:i:s A")." - Done";
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Get Outstanding Invoice List"/> 
    </form> 
</body>
</html>

Stock Month End - Weighted Average

Stock Month End - Weighted Average Script
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/Grid.css" />
</head>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 01 Dec 2021<br>";


$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0024.FDB"); #Database Name
    
}

function GetData(){
	#Accuracy : 90% - Due to the figure is base on last run Costing in SQL Accounting
	global $ComServer;
	
    $lSQL = "SELECT A.ItemCode, A.Location, A.Batch,  MAX(B.Seq) AS Seq, 2 AS CostingMethod
	         FROM ST_TR A INNER JOIN ST_TR_WMA B ON (A.TRANSNO=B.TRANSNO) 
			 WHERE A.PostDate<='31 Jul 2020'
			 AND A.ITEMCODE='Adj_Voucher'
			 GROUP BY A.ItemCode, A.Location, A.Batch
			 ";
	
	$lDataSet1 = $ComServer->DBManager->NewDataSet($lSQL);
	
	$Seq = "";
	$lDataSet1->First();
	while (! $lDataSet1->Eof()){
		$Seq = $Seq.$lDataSet1->FindField("SEQ")->AsString .",";
		$lDataSet1->Next();
	}

    $lSQL = "SELECT A.TRANSNO, A.ItemCode, A.Location, A.Batch, B.UTDQty, B.UTDCost FROM ST_TR A
	         INNER JOIN ST_TR_WMA B ON (A.TRANSNO=B.TRANSNO) 
			 WHERE A.PostDate<='31 Jul 2020'
			 AND A.ITEMCODE='Adj_Voucher'
			 AND B.SEQ IN (".substr_replace($Seq ,"",-1).") 
			 AND B.UTDQty<>0 
			 ORDER BY A.ItemCode, A.Location, A.Batch
			 ";
		 
	$lDataSet2 = $ComServer->DBManager->NewDataSet($lSQL);		 
			 
    if ($lDataSet2->RecordCount > 0) {
		$lDataSet2->First();
		$fc = $lDataSet2->Fields->Count-1;
		echo "<table>";
		echo "<tr>";
		for ($x = 0; $x <= $fc; $x++) {
			#Insert Header
			echo "<td>".$lDataSet2->Fields->Items($x)->FieldName()."</td>"; 
		}
		echo "</tr>";
		
		#Looping Dataset
		while (! $lDataSet2->Eof()){
			echo "<tr>";
		    for ($x = 0; $x <= $fc; $x++) {
				$lFN = $lDataSet2->Fields->Items($x)->FieldName();
			    echo "<td>".$lDataSet2->FindField($lFN)->AsString()."</td>"; 
		    }
		    echo "</tr>";
			$lDataSet2->Next();
		}	
		echo "</table>"."<br>";		
	}else {
    echo "Record Not Found";
    }
}

if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
        GetData();
        echo date("d M Y h:i:s A")." - Done";
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Month End - WA"/> 
    </form> 
</body>
</html>

Stock Month End - FIFO

Stock Month End - FIFO Script
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/Grid.css" />
</head>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 16 Jul 2020<br>";
#This action to Get Outstanding Invoice List

$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0024.FDB"); #Database Name
    
}

function GetData(){
	#Accuracy : 90% - Due to the figure is base on last run Costing in SQL Accounting
	global $ComServer;
	
    $lSQL = "SELECT  A.ItemCode, A.Location, A.Batch, MAX(B.Seq) AS Seq, 1 AS CostingMethod 
	         FROM ST_TR A INNER JOIN ST_TR_FIFO B ON (A.TRANSNO=B.TRANSNO) 
			 WHERE A.PostDate<='31 Jul 2020'
			 AND A.ItemCode IN ('ANT', 'COVER', 'BOM')
			 GROUP BY A.ItemCode, A.Location, A.Batch
			 ";
	
	$lDataSet1 = $ComServer->DBManager->NewDataSet($lSQL);
	
	$Seq = "";
	$lDataSet1->First();
	while (! $lDataSet1->Eof()){
		$Seq = $Seq.$lDataSet1->FindField("SEQ")->AsString .",";
		$lDataSet1->Next();
	}

    $lSQL = "SELECT A.TRANSNO, A.ItemCode, A.Location, A.Batch, B.QTY, B.COST FROM ST_TR A 
	         INNER JOIN ST_TR_FIFO B ON (A.TRANSNO=B.TRANSNO) 
			 WHERE B.COSTTYPE='U' 
			 AND A.PostDate<='31 Jul 2020'
			 AND B.SEQ IN (".substr_replace($Seq ,"",-1).") 
			 AND A.ItemCode IN ('ANT1.0', 'COVER', 'BOM')
			 AND B.Qty<>0 
			 ORDER BY A.ItemCode, A.Location, A.Batch
			 ";
	 
	$lDataSet2 = $ComServer->DBManager->NewDataSet($lSQL);		 
			 
    if ($lDataSet2->RecordCount > 0) {
		$lDataSet2->First();
		$fc = $lDataSet2->Fields->Count-1;
		echo "<table>";
		echo "<tr>";
		for ($x = 0; $x <= $fc; $x++) {
			#Insert Header
			echo "<td>".$lDataSet2->Fields->Items($x)->FieldName()."</td>"; 
		}
		echo "</tr>";
		
		#Looping Dataset
		while (! $lDataSet2->Eof()){
			echo "<tr>";
		    for ($x = 0; $x <= $fc; $x++) {
				$lFN = $lDataSet2->Fields->Items($x)->FieldName();
			    echo "<td>".$lDataSet2->FindField($lFN)->AsString()."</td>"; 
		    }
		    echo "</tr>";
			$lDataSet2->Next();
		}	
		echo "</table>"."<br>";		
	}else {
    echo "Record Not Found";
    }
	
	#FIFO Detail Key to link with $lDataSet2 & $lDataSet3 is TRANSNO
	$Seq = "";
	$lDataSet2->First();
	while (! $lDataSet2->Eof()){
		$Seq = $Seq.$lDataSet2->FindField("TRANSNO")->AsString .",";
		$lDataSet2->Next();
	}

    $lSQL = "SELECT  TransNo, Cost, SUM(Qty) AS Qty, MIN(CostSeq) AS Seq FROM ST_TR_FIFO 
	         WHERE CostType='B' 
			 AND TRANSNO IN (".substr_replace($Seq ,"",-1).") 
			 GROUP BY TransNo, Cost
			 ";
	 
	$lDataSet3 = $ComServer->DBManager->NewDataSet($lSQL);

    if ($lDataSet3->RecordCount > 0) {
		$lDataSet3->First();
		$fc = $lDataSet3->Fields->Count-1;
		echo "<table>";
		echo "<tr>";
		for ($x = 0; $x <= $fc; $x++) {
			#Insert Header
			echo "<td>".$lDataSet3->Fields->Items($x)->FieldName()."</td>"; 
		}
		echo "</tr>";
		
		#Looping Dataset
		while (! $lDataSet3->Eof()){
			echo "<tr>";
		    for ($x = 0; $x <= $fc; $x++) {
				$lFN = $lDataSet3->Fields->Items($x)->FieldName();
			    echo "<td>".$lDataSet3->FindField($lFN)->AsString()."</td>"; 
		    }
		    echo "</tr>";
			$lDataSet3->Next();
		}	
		echo "</table>"."<br>";		
	}else {
    echo "Record Not Found";
    }	
}

if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
        GetData();
        echo date("d M Y h:i:s A")." - Done";
    }
    finally
    {
        #$ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Month End - FIFO"/> 
    </form> 
</body>
</html>

Add & Edit Stock Item

Add & Edit Stock Item Script
<!DOCTYPE html>
<html>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 05 Aug 2020<br>";
$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0024.FDB"); #Database Name
    
}

function PostData(){
	global $ComServer;
	
	$BizObject = $ComServer->BizObjects->Find("ST_ITEM");
    $lMain = $BizObject->DataSets->Find("MainDataSet"); 
    $lUOM  = $BizObject->DataSets->Find("cdsUOM"); 
	$lBarcode = $BizObject->DataSets->Find("cdsBarcode"); 
	
	$lDocKey = $BizObject->FindKeyByRef("CODE", "FAIRY-PHP");

	if ($lDocKey == null){
        $BizObject->New();
        $lMain->FindField("CODE")->AsString = "FAIRY-PHP";
        $lMain->FindField("DESCRIPTION")->AsString = "FAIRY TAIL";
        $lMain->FindField("STOCKGROUP")->AsString = "DEFAULT";
        $lMain->FindField("STOCKCONTROL")->AsString = "T";
        $lMain->FindField("ISACTIVE")->AsString = "T";

        $lUOM->Edit(); #For 1St UOM
        $lUOM->FindField("UOM")->AsString = "PCS";
        $lUOM->FindField("Rate")->AsFloat = 1;
        $lUOM->FindField("RefCost")->AsFloat = 10.2;
        $lUOM->FindField("RefPrice")->AsFloat = 25;
        $lUOM->Post();

        $lUOM->Append(); #For 2nd UOM
        $lUOM->FindField("UOM")->AsString = "CTN";
        $lUOM->FindField("Rate")->AsFloat = 12;
        $lUOM->FindField("RefCost")->AsFloat = 102;
        $lUOM->FindField("RefPrice")->AsFloat = 240;
        $lUOM->Post();

        $lBarcode->Append(); #For 1st UOM Barcode
        $lBarcode->FindField("BARCODE")->AsString = "123456789";
		$lBarcode->FindField("UOM")->AsString = "PCS";
        $lBarcode->Post();
		
        $lBarcode->Append(); #For 2nd UOM Barcode
        $lBarcode->FindField("BARCODE")->AsString = "987654321";
		$lBarcode->FindField("UOM")->AsString = "CTN";
        $lBarcode->Post();		
	} else{
        $BizObject->Params->Find("Dockey")->AsString = $lDocKey;
        $BizObject->Open();
        $BizObject->Edit();
        $lMain->FindField("DESCRIPTION")->AsString = "FAIRY TAIL WIZARD";
		
		$r = $lUOM->RecordCount();
		$x = 1;
		while ($x <= $r ){
			$lUOM->First();
            $lUOM->Delete();
			$x++;
		}
		
		$r = $lBarcode->RecordCount();
		$x = 1;
		while ($x <= $r ){
			$lBarcode->First();
            $lBarcode->Delete();
			$x++;
		}
		
        $lUOM->Append(); #For 1St UOM
        $lUOM->FindField("UOM")->AsString = "PCS"; #Make sure this always same as b4 delete data
        $lUOM->FindField("Rate")->AsFloat = 1; #Make sure this always same as b4 delete data
        $lUOM->FindField("RefCost")->AsFloat = 22.3;
        $lUOM->FindField("RefPrice")->AsFloat = 52;
        $lUOM->Post();

        $lUOM->Append(); #For 2nd UOM
        $lUOM->FindField("UOM")->AsString = "CTN"; #Make sure this always same as b4 delete data
        $lUOM->FindField("Rate")->AsFloat = 12; #Make sure this always same as b4 delete data
        $lUOM->FindField("RefCost")->AsFloat = 102.5;
        $lUOM->FindField("RefPrice")->AsFloat = 260.45;
        $lUOM->Post();	
		
        $lBarcode->Append(); #For 1st UOM Barcode
        $lBarcode->FindField("BARCODE")->AsString = "456321789";
		$lBarcode->FindField("UOM")->AsString = "PCS";
        $lBarcode->Post();
		
        $lBarcode->Append(); #For 2nd UOM Barcode
        $lBarcode->FindField("BARCODE")->AsString = "321456987";
		$lBarcode->FindField("UOM")->AsString = "CTN";
        $lBarcode->Post();			
	}
	
	try{
        $BizObject->Save();
        $BizObject->Close();
	}catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
    }	
}


if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
        echo date("d M Y h:i:s A")." - Begin Posting Stock Item<br>";
        PostData();
		echo date("d M Y h:i:s A")." - Done<br>";
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Add & Edit Stock Item"/> 
    </form> 
</body>
</html>

Add Stock Issue

Add Stock Issue Script
<!DOCTYPE html>
<html>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 21 Oct 2020<br>";
$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "D:\Happy\DB\Default.DCF", #"C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0024.FDB"); #Database Name
    
}

function CheckLogin1()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    
}

function PostData(){
	global $ComServer;
	
	$BizObject = $ComServer->BizObjects->Find("ST_IS");
    $lMain = $BizObject->DataSets->Find("MainDataSet"); 
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); 
	
    $BizObject->New();
    $lMain->FindField("DocKey")->value = -1;
    $lMain->FindField("DocNo")->AsString = "--IS Test--";
    $lMain->FindField("DocDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("PostDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("Description")->AsString = "Stock Issue";
	
    #Insert Data - Detail	
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 1;
    $lDetail->FindField("ItemCode")->AsString = "ANT";
    $lDetail->FindField("Description")->AsString = "Sales Item B";
    $lDetail->FindField("Qty")->AsFloat = 2;
    $lDetail->FindField("UOM")->AsString = "BOX";
    $lDetail->Post();

    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 2;
    $lDetail->FindField("ItemCode")->AsString = "N-CHARGER";
    $lDetail->FindField("Description")->AsString = "NOKIA CHARGER";
    $lDetail->FindField("Qty")->AsFloat = 5;
    $lDetail->FindField("UOM")->AsString = "UNIT";
    $lDetail->Post();
	
    $BizObject->Save();
    $BizObject->Close();
	
	try{
        $BizObject->Save();
        $BizObject->Close();
	}catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
    }	
}


if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin1();
        echo date("d M Y h:i:s A")." - Begin Posting<br>";
        PostData();
		echo date("d M Y h:i:s A")." - Done<br>";
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Add Stock Issue"/> 
    </form> 
</body>
</html>

Add Points

Add Points Script
<!DOCTYPE html>
<html>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 30 Oct 2020<br>";
$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0024.FDB"); #Database Name
    
}

function PostData(){
	global $ComServer;
	
	$BizObject = $ComServer->BizObjects->Find("Sales.Points.OPF");
    $lMain = $BizObject->DataSets->Find("Main"); #lMain contains master data
	
    $BizObject->New();
    $lMain->FindField("DocKey")->value = -1;
    $lMain->FindField("DocNo")->AsString = "--Point Test--";
    $lMain->FindField("DocDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("Code")->AsString = "300-C0001"; #Customer Account
    $lMain->FindField("CompanyName")->AsString = "Cash Sales";
	$lMain->FindField("DESCRIPTION")->AsString = "Points Earn";
    $lMain->FindField("FromDocType")->AsString = "CS";
	$lMain->FindField("FromDocNo")->AsString = "CS-01234";
	$lMain->FindField("FROMDOCAMT")->AsFloat = 100.10;
	$lMain->FindField("Points")->AsFloat = 10;
	
	try{
		$BizObject->Save();
	}catch (Exception $e) {
		echo 'Caught exception: ',  $e->getMessage(), "\n";
    }
}


if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
        echo date("d M Y h:i:s A")." - Posting Point<br>";
        PostData();
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Post Point"/> 
    </form> 
</body>
</html>

AR_CN

AR_CN Script
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/Grid.css" />
</head>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 12 Dec 2020<br>";
#This action to Post Customer Credit Note

$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0040.FDB"); #Database Name
    
}

function PostData(){
	global $ComServer;
	
	$BizObject = $ComServer->BizObjects->Find("AR_CN");
    $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
	$lKO = $BizObject->DataSets->Find("cdsKnockOff");
	
    $BizObject->New();
    $lMain->FindField("DocKey")->value = -1;
    $lMain->FindField("DocNo")->AsString = "--CN Test1--";
    $lMain->FindField("DocDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("PostDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("Code")->AsString = "300-C0001"; #Customer Account
    $lMain->FindField("Description")->AsString = "Sales";
	
    #Insert Data - Detail
    #For Tax Inclusive = True with override Tax Amount
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 1;
    $lDetail->FindField("Account")->AsString = "510-000"; #Sales Return Account
    $lDetail->FindField("Description")->AsString = "Return Item A";
    $lDetail->FindField("Tax")->AsString = "";
    $lDetail->FindField("TaxRate")->AsString = "";
    $lDetail->FindField("TaxInclusive")->value = 0;
    $lDetail->FindField("Amount")->AsFloat = 410.37; #Exclding GST Amt
    $lDetail->FindField("TaxAmt")->AsFloat = 0;
	$lDetail->Post();

    $V = array("IV", "IV-00003");  #DocType, DocNo
        
    if ($lKO->Locate("DocType;DocNo", $V, False, False)){
        $lKO->Edit();
        $lKO->FindField("KOAmt")->AsFloat = 100; #Partial Knock off
        $lKO->FindField("KnockOff")->AsString = "T";
        $lKO->Post();
	}	
    $BizObject->Save();
    $BizObject->Close();	
}

if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
		PostData();
        echo date("d M Y h:i:s A")." - Done";
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Post Customer Credit Note"/> 
    </form> 
</body>
</html>

SO to DO

SO to DO Script
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/Grid.css" />
</head>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 15 Jan 2021<br>";
#This action to 
#01. Get Oustanding SO
#02. Post To DO

$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0024.FDB"); #Database Name
    
}

function PostData(){
	global $ComServer;
	
    $lSQL = "SELECT Dockey, DocNo,Code, CompanyName, Seq, DtlKey, ItemCode, Qty, UOM, UnitPrice, Disc, Amount, 
             COALESCE(Sum(XFQty),0) XFQty, COALESCE((Qty-Sum(XFQty)), Qty) OSQty FROM (
             SELECT A.Dockey, A.DocNo, A.Code, A.CompanyName,
             B.DtlKey, B.Seq, B.ItemCode, B.Qty, B.UOM, B.UnitPrice, B.Disc, B.Amount, 
             C.Qty XFQty FROM SL_SO A
             INNER JOIN SL_SODTL B ON (A.DOCKEY=B.DOCKEY)
             LEFT JOIN ST_XTRANS C ON (A.DOCKEY=C.FROMDOCKEY AND B.DTLKEY=C.FROMDTLKEY
                                       AND C.FROMDOCTYPE='SO')
             WHERE A.DOCNO='SO-00140')
             GROUP BY Dockey, DocNo, Code, CompanyName, Seq, Dtlkey, ItemCode, Qty, UOM, UnitPrice, Disc, Amount
			 HAVING COALESCE((Qty-Sum(XFQty)), Qty) >0
			 ";	
	
	$lDataSet = $ComServer->DBManager->NewDataSet($lSQL); #Get Oustanding SO Qty

    if ($lDataSet->RecordCount > 0) {
		$BizObject = $ComServer->BizObjects->Find("SL_DO");
        $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
        $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data	
		
		$lDataSet->First();
		$BizObject->New();
		$lMain->FindField("DocKey")->value = -1;
		$lMain->FindField("DocNo")->AsString = "--DO Test--";
		$lMain->FindField("DocDate")->value = "01/20/2021"; #MM/DD/YYYY
		$lMain->FindField("PostDate")->value = "01/20/2021"; #MM/DD/YYYY
		$lMain->FindField("Code")->AsString = $lDataSet->FindField("Code")->AsString;
		$lMain->FindField("CompanyName")->AsString = $lDataSet->FindField("CompanyName")->AsString;
		$lMain->FindField("Description")->AsString = "Delivery Order";		

		while (! $lDataSet->Eof()){
    		$lDetail->Append();
    		$lDetail->FindField("DtlKey")->value = -1;
    		$lDetail->FindField("DocKey")->value = -1;
    		$lDetail->FindField("ItemCode")->AsString = $lDataSet->FindField("ItemCode")->AsString;
    		$lDetail->FindField("UOM")->AsString = $lDataSet->FindField("UOM")->AsString;
		$lDetail->FindField("Qty")->AsFloat = $lDataSet->FindField("OSQty")->AsFloat;
    		$lDetail->FindField("DISC")->value = $lDataSet->FindField("DISC")->value;
    		$lDetail->FindField("Tax")->AsString = "";
    		$lDetail->FindField("TaxRate")->AsString = "";
    		$lDetail->FindField("TaxInclusive")->value = 0;
    		$lDetail->FindField("UnitPrice")->AsFloat = $lDataSet->FindField("UnitPrice")->AsFloat;
    		$lDetail->FindField("Amount")->AsFloat = $lDataSet->FindField("Amount")->AsFloat;
    		$lDetail->FindField("TaxAmt")->AsFloat = 0;
		$lDetail->FindField("FromDocType")->AsString = "SO";
		$lDetail->FindField("FromDockey")->AsFloat = $lDataSet->FindField("Dockey")->AsFloat;
		$lDetail->FindField("FromDtlkey")->AsFloat = $lDataSet->FindField("DtlKey")->AsFloat;
    		$lDetail->Post();
		$lDataSet->Next();

		}
        $BizObject->Save();
        $BizObject->Close();			
	}else {
    echo "Record Not Found";
    }
}

if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
		PostData();
        echo date("d M Y h:i:s A")." - Done";
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Post SO to DO"/> 
    </form> 
</body>
</html>

ST_AJ

ST_AJ Script
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/Grid.css" />
</head>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 08 Feb 2021<br>";

$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0100.FDB"); #Database Name
    
}

function PostData(){
	global $ComServer;
	
	$BizObject = $ComServer->BizObjects->Find("ST_AJ");
    $lMain = $BizObject->DataSets->Find("MainDataSet"); 
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); 
	
    $BizObject->New();
    $lMain->FindField("DocKey")->value = -1;
    $lMain->FindField("DocNo")->AsString = "--AJ Test--";
    $lMain->FindField("DocDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("PostDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("Description")->AsString = "Stock Adjustment";
	
    #Insert Data - Detail - Increase Stock Qty
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 1;
    $lDetail->FindField("ItemCode")->AsString = "ANT";
    $lDetail->FindField("Description")->AsString = "ANTENA";
    $lDetail->FindField("Qty")->AsFloat = 2;
    $lDetail->FindField("UOM")->AsString = "BOX";
    $lDetail->Post();
    #Insert Data - Detail - Reduce Stock Qty
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 2;
    $lDetail->FindField("ItemCode")->AsString = "N-CHARGER";
    $lDetail->FindField("Description")->AsString = "NOKIA CHARGER";
    $lDetail->FindField("Qty")->AsFloat = -5;
    $lDetail->FindField("UOM")->AsString = "UNIT";
    $lDetail->Post();
	
    $BizObject->Save();
    $BizObject->Close();
	
	try{
        $BizObject->Save();
        $BizObject->Close();
	}catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
    }	
}

if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
		PostData();
        echo date("d M Y h:i:s A")." - Done";
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Post ST_AJ"/> 
    </form> 
</body>
</html>

Get Stock Serial Number balance

Get Stock Serial Number Balance List Script
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/Grid.css" />
</head>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 21 May 2021<br>";

$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "D:\Happy\DB\Default.DCF",  #"C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0024.FDB"); #Database Name
    
}

function GetData(){
	global $ComServer;
	
    $lSQL = "SELECT ItemCode, Location, Batch, SerialNumber, SUM(Qty) Qty  FROM ST_TR_SN  
	         GROUP BY ItemCode, Location, Batch, SerialNumber 
			 HAVING SUM(Qty) > 0
			 ";
	
	$lDataSet = $ComServer->DBManager->NewDataSet($lSQL);

    if ($lDataSet->RecordCount > 0) {
		$lDataSet->First();
		$fc = $lDataSet->Fields->Count-1;
		echo "<table>";
		echo "<tr>";
		for ($x = 0; $x <= $fc; $x++) {
			#Insert Header
			echo "<td>".$lDataSet->Fields->Items($x)->FieldName()."</td>"; 
		}
		echo "</tr>";
		
		#Looping Dataset
		while (! $lDataSet->Eof()){
			echo "<tr>";
		    for ($x = 0; $x <= $fc; $x++) {
				$lFN = $lDataSet->Fields->Items($x)->FieldName();
			    echo "<td>".$lDataSet->FindField($lFN)->AsString()."</td>"; 
		    }
		    echo "</tr>";
			$lDataSet->Next();
		}	
		echo "</table>"."<br>";		
	}else {
    echo "Record Not Found";
    }
}

if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
		GetData();
        echo date("d M Y h:i:s A")." - Done";
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Get SN Balance"/> 
    </form> 
</body>
</html>

SL_IV-Add, Edit & Delete

Insert, Edit & Delete Invoice Script
<!DOCTYPE html>
<html>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 14 Mar 2022<br>";
$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "D:\Happy\DB\Default.DCF", #"C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0015.FDB"); #Database Name
    
}

function PostDataIV(){
	global $ComServer;
	
	$BizObject = $ComServer->BizObjects->Find("SL_IV");
    $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
	
    #Find IV Number
    $lDocNo = "--IV Test--";
    $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
	
	if ($lDocKey != null){
        echo "Dockey = ".$lDocKey."<br>";
		$BizObject->Params->Find("DocKey")->AsString = $lDocKey;
		$BizObject->Open();
        $BizObject->Edit();
        $lMain->Edit();
	    $lMain->FindField("DocDate")->value = "02/20/2022"; #MM/DD/YYYY
        $lMain->FindField("PostDate")->value = "02/20/2022"; #MM/DD/YYYY
        $lMain->FindField("CompanyName")->AsString = "Cash Sales-Edited";
        $lMain->FindField("Address1")->AsString = ""; #Optional
        $lMain->FindField("Address2")->AsString = ""; #Optional
        $lMain->FindField("Address3")->AsString = ""; #Optional
        $lMain->FindField("Address4")->AsString = ""; #Optional
        $lMain->FindField("Phone1")->AsString = "";   #Optional
        $lMain->FindField("Description")->AsString = "Sales - Edited";

		$r = $lDetail->RecordCount();
		$x = 1;
		while ($x <= $r ){
			$lDetail->First();
            $lDetail->Delete();
			$x++;
		}
        $lDetail->Append();
        $lDetail->FindField("ItemCode")->AsString = "COVER";
        $lDetail->FindField("Description")->AsString = "Sales Item Cover";
	    $lDetail->FindField("UOM")->AsString = "UNIT";
        $lDetail->FindField("Qty")->AsFloat = 3;
        $lDetail->FindField("Tax")->AsString = "";
        $lDetail->FindField("TaxRate")->AsString = "";
        $lDetail->FindField("TaxInclusive")->value = 0;
        $lDetail->FindField("UnitPrice")->AsFloat = 5.60;
        $lDetail->FindField("Amount")->AsFloat = 16.80;
        $lDetail->FindField("TaxAmt")->AsFloat = 0;
        $lDetail->Post();		
	} else {
      echo "New Invoice<br>";
	  $BizObject->New();
      $lMain->FindField("DocKey")->value = -1;
      $lMain->FindField("DocNo")->AsString = $lDocNo;
	  $lMain->FindField("Code")->AsString = "300-C0001"; #Customer Account
	  $lMain->FindField("DocDate")->value = "02/18/2022"; #MM/DD/YYYY
      $lMain->FindField("PostDate")->value = "02/18/2022"; #MM/DD/YYYY
      $lMain->FindField("CompanyName")->AsString = "Cash Sales";
      $lMain->FindField("Address1")->AsString = ""; #Optional
      $lMain->FindField("Address2")->AsString = ""; #Optional
      $lMain->FindField("Address3")->AsString = ""; #Optional
      $lMain->FindField("Address4")->AsString = ""; #Optional
      $lMain->FindField("Phone1")->AsString = "";   #Optional
      $lMain->FindField("Description")->AsString = "Sales";
	  #$lMain->FindField('DocAmt')->value = $Amt;
	
      $lDetail->Append();
      $lDetail->FindField("ItemCode")->AsString = "ANT";
      $lDetail->FindField("Description")->AsString = "Sales Item ANT";
	  $lDetail->FindField("UOM")->AsString = "UNIT";
      $lDetail->FindField("Qty")->AsFloat = 1;
      $lDetail->FindField("Tax")->AsString = "";
      $lDetail->FindField("TaxRate")->AsString = "";
      $lDetail->FindField("TaxInclusive")->value = 0;
      $lDetail->FindField("UnitPrice")->AsFloat = 100;
      $lDetail->FindField("Amount")->AsFloat = 100;
      $lDetail->FindField("TaxAmt")->AsFloat = 0;
      $lDetail->Post();


      $lDetail->Append();
      $lDetail->FindField("ItemCode")->AsString = "BOM";
      $lDetail->FindField("Description")->AsString = "Sales Item BOM";
	  $lDetail->FindField("UOM")->AsString = "UNIT";
      $lDetail->FindField("Qty")->AsFloat = 2;
      $lDetail->FindField("Tax")->AsString = "";
      $lDetail->FindField("TaxRate")->AsString = "";
      $lDetail->FindField("TaxInclusive")->value = 0;
      $lDetail->FindField("UnitPrice")->AsFloat = 150;
      $lDetail->FindField("Amount")->AsFloat = 300;
      $lDetail->FindField("TaxAmt")->AsFloat = 0;
      $lDetail->Post();
	}
    $BizObject->Save();
	
	echo date("d M Y h:i:s A")." - Posting Done<br>";
    $BizObject->Close();	
}

function PostDelIV(){
	global $ComServer;
	
	$BizObject = $ComServer->BizObjects->Find("SL_IV");
    $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
	
    #Find IV Number
    $lDocNo = "--IV Test--";
    $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
	
	if ($lDocKey != null){
        echo "Dockey = ".$lDocKey."<br>";
		$BizObject->Params->Find("DocKey")->AsString = $lDocKey;
		$BizObject->Open();
        $BizObject->Delete();
		echo date("d M Y h:i:s A")." - Record deleted<br>";
	} else {
		echo date("d M Y h:i:s A")." - Document Not Found<br>";
	}		
}
if (isset($_POST['BtnPost']))
{
    try
    {
        CheckLogin();
        echo date("d M Y h:i:s A")." - Begin Posting<br>";
        PostDataIV();	
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

if (isset($_POST['BtnDel']))
{
    try
    {
        CheckLogin();
        echo date("d M Y h:i:s A")." - Begin Delete<br>";
        PostDelIV();	
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnPost"
                value="Post Sales IV"/> 
        <input type="submit" name="BtnDel"
                value="Post Delete IV"/>
    </form> 
</body>
</html>

GL_PV-Add, Edit & Delete

Insert, Edit & Delete Invoice Script
<!DOCTYPE html>
<html>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 15 Mar 2022<br>";
$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "D:\Happy\DB\Default.DCF", #"C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0015.FDB"); #Database Name
    
}

function PostData(){
	global $ComServer;
	
	$BizObject = $ComServer->BizObjects->Find("GL_PV");
    $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
	
    #Find PV Number
    $lDocNo = "--PV Test--";
    $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
	
	if ($lDocKey != null){
        echo "Dockey = ".$lDocKey."<br>";
		$BizObject->Params->Find("DocKey")->AsString = $lDocKey;
		$BizObject->Open();
        $BizObject->Edit();
        $lMain->Edit();
	    $lMain->FindField("DocDate")->value = "02/20/2022"; #MM/DD/YYYY
        $lMain->FindField("PostDate")->value = "02/20/2022"; #MM/DD/YYYY
        $lMain->FindField("Description")->AsString = "Tenaga Malaysia - Edited";
		$lMain->FindField("PaymentMethod")->AsString = "310-001"; #GL Bank/Cash account code
		$lMain->FindField("CHEQUENUMBER")->AsString = "MBB 123456"; #Optional
		$lMain->FindField("Cancelled")->AsString = "F";

		$r = $lDetail->RecordCount();
		$x = 1;
		while ($x <= $r ){
			$lDetail->First();
            $lDetail->Delete();
			$x++;
		}
        $lDetail->Append();
        $lDetail->FindField("Code")->AsString = "907-000";
        $lDetail->FindField("Description")->AsString = "TNB Bill for Feb 2022 - Edited";
        $lDetail->FindField("Tax")->AsString = "";
        $lDetail->FindField("TaxRate")->AsString = "";
        $lDetail->FindField("TaxInclusive")->value = 0;
        $lDetail->FindField("Amount")->AsFloat = 168.80;
        $lDetail->FindField("TaxAmt")->AsFloat = 0;
        $lDetail->Post();		
	} else {
      echo "New PV<br>";
	  $BizObject->New();
      $lMain->FindField("DocKey")->value = -1;
      $lMain->FindField("DocNo")->AsString = $lDocNo;
	  $lMain->FindField("DocDate")->value = "02/18/2022"; #MM/DD/YYYY
      $lMain->FindField("PostDate")->value = "02/18/2022"; #MM/DD/YYYY
      $lMain->FindField("Description")->AsString = "Tenaga Malaysia";
	  $lMain->FindField("PaymentMethod")->AsString = "310-001"; #GL Bank/Cash account code
	  $lMain->FindField("CHEQUENUMBER")->AsString = "MBB 123456"; #Optional
	  $lMain->FindField("Cancelled")->AsString = "F";
		
      $lDetail->Append();
      $lDetail->FindField("Code")->AsString = "907-000"; #GL Account
      $lDetail->FindField("Description")->AsString = "TNB Bill for Jan 2022";
      $lDetail->FindField("Tax")->AsString = "";
      $lDetail->FindField("TaxRate")->AsString = "";
      $lDetail->FindField("TaxInclusive")->value = 0;
      $lDetail->FindField("Amount")->AsFloat = 100.80;
      $lDetail->FindField("TaxAmt")->AsFloat = 0;
      $lDetail->Post();

      $lDetail->Append();
      $lDetail->FindField("Code")->AsString = "907-000";
      $lDetail->FindField("Description")->AsString = "TNB Bill for Feb 2022";
      $lDetail->FindField("Tax")->AsString = "";
      $lDetail->FindField("TaxRate")->AsString = "";
      $lDetail->FindField("TaxInclusive")->value = 0;
      $lDetail->FindField("Amount")->AsFloat = 68.00;
      $lDetail->FindField("TaxAmt")->AsFloat = 0;
      $lDetail->Post();
	}
    $BizObject->Save();
	
	echo date("d M Y h:i:s A")." - Posting Done<br>";
    $BizObject->Close();	
}

function DelData(){
	global $ComServer;
	
	$BizObject = $ComServer->BizObjects->Find("GL_PV");
    $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
	
    #Find PV Number
    $lDocNo = "--PV Test--";
    $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
	
	if ($lDocKey != null){
        echo "Dockey = ".$lDocKey."<br>";
		$BizObject->Params->Find("DocKey")->AsString = $lDocKey;
		$BizObject->Open();
        $BizObject->Delete();
		echo date("d M Y h:i:s A")." - Record deleted<br>";
	} else {
		echo date("d M Y h:i:s A")." - Document Not Found<br>";
	}		
}
if (isset($_POST['BtnPost']))
{
    try
    {
        CheckLogin();
        echo date("d M Y h:i:s A")." - Begin Posting<br>";
        PostData();	
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

if (isset($_POST['BtnDel']))
{
    try
    {
        CheckLogin();
        echo date("d M Y h:i:s A")." - Begin Delete<br>";
        DelData();	
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnPost"
                value="Post GL PV"/> 
        <input type="submit" name="BtnDel"
                value="Delete PV"/>
    </form> 
</body>
</html>

GL_JE-Add, Edit & Delete

Insert, Edit & Delete Invoice Script
<!DOCTYPE html>
<html>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 15 Mar 2022<br>";
$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0015.FDB"); #Database Name
    
}

function PostData(){
	global $ComServer;
	
	$BizObject = $ComServer->BizObjects->Find("GL_JE");
    $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); #lDetail contains detail data
	
    #Find JE Number
    $lDocNo = "--JE Test--";
    $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
	
	if ($lDocKey != null){
        echo "Dockey = ".$lDocKey."<br>";
		$BizObject->Params->Find("DocKey")->AsString = $lDocKey;
		$BizObject->Open();
        $BizObject->Edit();
        $lMain->Edit();
	    $lMain->FindField("DocDate")->value = "02/20/2022"; #MM/DD/YYYY
        $lMain->FindField("PostDate")->value = "02/20/2022"; #MM/DD/YYYY
        $lMain->FindField("Description")->AsString = "Credit Card Charges - Edited";
		$lMain->FindField("Cancelled")->AsString = "F";

		$r = $lDetail->RecordCount();
		$x = 1;
		while ($x <= $r ){
			$lDetail->First();
            $lDetail->Delete();
			$x++;
		}
        $lDetail->Append();
        $lDetail->FindField("Code")->AsString = "902-000";
        $lDetail->FindField("Description")->AsString = "MBB Credit Card Charges - Edited";
        $lDetail->FindField("Tax")->AsString = "";
        $lDetail->FindField("TaxRate")->AsString = "";
        $lDetail->FindField("TaxInclusive")->value = 0;
        $lDetail->FindField("LocalDR")->AsFloat = 78.88;
		$lDetail->FindField("DR")->AsFloat = 78.88; #If Wanted DR <> LocalDR
        $lDetail->FindField("LocalTaxAmt")->AsFloat = 0;
        $lDetail->Post();
		
        $lDetail->Append();
        $lDetail->FindField("Code")->AsString = "310-001";
        $lDetail->FindField("Description")->AsString = "MBB Credit Card Charges - Edited";
        $lDetail->FindField("Tax")->AsString = "";
        $lDetail->FindField("TaxRate")->AsString = "";
        $lDetail->FindField("TaxInclusive")->value = 0;
        $lDetail->FindField("LocalCR")->AsFloat = 78.88;
		$lDetail->FindField("CR")->AsFloat = 78.88; #If Wanted CR <> LocalCR
        $lDetail->FindField("LocalTaxAmt")->AsFloat = 0;
        $lDetail->Post();			
	} else {
      echo "New JE<br>";
	  $BizObject->New();
      $lMain->FindField("DocKey")->value = -1;
      $lMain->FindField("DocNo")->AsString = $lDocNo;
	  $lMain->FindField("DocDate")->value = "02/18/2022"; #MM/DD/YYYY
      $lMain->FindField("PostDate")->value = "02/18/2022"; #MM/DD/YYYY
      $lMain->FindField("Description")->AsString = "Credit Card Charges";
	  $lMain->FindField("Cancelled")->AsString = "F";
		
      $lDetail->Append();
      $lDetail->FindField("Code")->AsString = "902-000";
      $lDetail->FindField("Description")->AsString = "MBB Credit Card Charges";
      $lDetail->FindField("Tax")->AsString = "";
      $lDetail->FindField("TaxRate")->AsString = "";
      $lDetail->FindField("TaxInclusive")->value = 0;
      $lDetail->FindField("LocalDR")->AsFloat = 88.88;
	  $lDetail->FindField("DR")->AsFloat = 88.88; #If Wanted DR <> LocalDR
      $lDetail->FindField("LocalTaxAmt")->AsFloat = 0;
      $lDetail->Post();
		
      $lDetail->Append();
      $lDetail->FindField("Code")->AsString = "310-001";
      $lDetail->FindField("Description")->AsString = "MBB Credit Card Charges";
      $lDetail->FindField("Tax")->AsString = "";
      $lDetail->FindField("TaxRate")->AsString = "";
      $lDetail->FindField("TaxInclusive")->value = 0;
      $lDetail->FindField("LocalCR")->AsFloat = 88.88;
	  $lDetail->FindField("CR")->AsFloat = 88.88; #If Wanted CR <> LocalCR
      $lDetail->FindField("LocalTaxAmt")->AsFloat = 0;
      $lDetail->Post();
	}
    $BizObject->Save();
	
	echo date("d M Y h:i:s A")." - Posting Done<br>";
    $BizObject->Close();	
}

function DelData(){
	global $ComServer;
	
	$BizObject = $ComServer->BizObjects->Find("GL_JE");
    $lMain = $BizObject->DataSets->Find("MainDataSet"); #lMain contains master data
	
    #Find JE Number
    $lDocNo = "--JE Test--";
    $lDocKey = $BizObject->FindKeyByRef("DocNo", $lDocNo);
	
	if ($lDocKey != null){
        echo "Dockey = ".$lDocKey."<br>";
		$BizObject->Params->Find("DocKey")->AsString = $lDocKey;
		$BizObject->Open();
        $BizObject->Delete();
		echo date("d M Y h:i:s A")." - Record deleted<br>";
	} else {
		echo date("d M Y h:i:s A")." - Document Not Found<br>";
	}		
}
if (isset($_POST['BtnPost']))
{
    try
    {
        CheckLogin();
        echo date("d M Y h:i:s A")." - Begin Posting<br>";
        PostData();	
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

if (isset($_POST['BtnDel']))
{
    try
    {
        CheckLogin();
        echo date("d M Y h:i:s A")." - Begin Delete<br>";
        DelData();	
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnPost"
                value="Post GL JE"/> 
        <input type="submit" name="BtnDel"
                value="Delete JE"/>
    </form> 
</body>
</html>

Get Outstanding SO List

Get Outstanding SO List Script
<!DOCTYPE html>
<html>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 09 Jun 2022<br>";
$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp") or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0015.FDB"); #Database Name
    
}

function GetData(){
	global $ComServer;
	
    $lSQL = "SELECT Dockey, DocNo,Code, CompanyName, Seq, DtlKey, ItemCode, Qty, UOM, UnitPrice, Disc, Amount, 
             COALESCE(Sum(XFQty),0) XFQty, COALESCE((Qty-Sum(XFQty)), Qty) OSQty FROM (
             SELECT A.Dockey, A.DocNo, A.Code, A.CompanyName,
             B.DtlKey, B.Seq, B.ItemCode, B.Qty, B.UOM, B.UnitPrice, B.Disc, B.Amount, 
             C.Qty XFQty FROM SL_SO A
             INNER JOIN SL_SODTL B ON (A.DOCKEY=B.DOCKEY)
             LEFT JOIN ST_XTRANS C ON (A.DOCKEY=C.FROMDOCKEY AND B.DTLKEY=C.FROMDTLKEY
                                       AND C.FROMDOCTYPE='SO')
             WHERE A.Cancelled='F')
             GROUP BY Dockey, DocNo, Code, CompanyName, Seq, Dtlkey, ItemCode, Qty, UOM, UnitPrice, Disc, Amount
             HAVING COALESCE((Qty-Sum(XFQty)), Qty) >0
			 ";
	
	$lDataSet = $ComServer->DBManager->NewDataSet($lSQL);

    if ($lDataSet->RecordCount > 0) {
		$lDataSet->First();
		$fc = $lDataSet->Fields->Count-1;
		echo "<table>";
		echo "<tr>";
		for ($x = 0; $x <= $fc; $x++) {
			#Insert Header
			echo "<td>".$lDataSet->Fields->Items($x)->FieldName()."</td>"; 
		}
		echo "</tr>";
		
		#Looping Dataset
		while (! $lDataSet->Eof()){
			echo "<tr>";
		    for ($x = 0; $x <= $fc; $x++) {
				$lFN = $lDataSet->Fields->Items($x)->FieldName();
			    echo "<td>".$lDataSet->FindField($lFN)->AsString()."</td>"; 
		    }
		    echo "</tr>";
			$lDataSet->Next();
		}	
		echo "</table>"."<br>";		
	}else {
    echo "Record Not Found";
    }
}

if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
        echo date("d M Y h:i:s A")." - Get Data<br>";
        GetData();
		echo date("d M Y h:i:s A")." - Done<br>";
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Get Outstanding SO List"/> 
    </form> 
</body>
</html>

Get Stock Item Picture

Get Stock Item Picture Script
<!DOCTYPE html>
<html>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 14 Sep 2022<br>";

$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp", null, CP_UTF8) or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        $ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0082.FDB"); #Database Name
    
}

function GetData(){
    global $ComServer;
	
    $lSQL = "SELECT Picture FROM ST_ITEM 
             WHERE Code='ANT' ";
	
    $lDataSet = $ComServer->DBManager->NewDataSet($lSQL);

    if ($lDataSet->RecordCount > 0) {
	$lDataSet->First();
		
	$raw = $lDataSet->FindField('Picture')->Value();
	
        $b = [];
        foreach($raw as $p) {
            array_push($b, chr($p));
        }

	echo '<img src=data:image/*;base64,'.base64_encode(implode($b)).' alt="My Picture" style="width:128px;height:128px">';

	}else {
    echo "Record Not Found";
    }
}

if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
        GetData();
	echo "<br>";
        echo date("d M Y h:i:s A")." - Done";	
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Get Item Picture"/> 
    </form> 
</body>
</html>

Customer.Aging.RO

Customer.Aging.RO Script
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/Grid.css" />
</head>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 26 Sep 2022<br>";

$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp", null, CP_UTF8) or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        #$ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0082.FDB"); #Database Name
    
}

function SetGrid($DataSet){
	echo "<table>";
	echo "<tr>";	
    $DataSet->First();
	$fc = $DataSet->Fields->Count-1;
	for ($x = 0; $x <= $fc; $x++) {
		#Insert Header
		echo "<td>".$DataSet->Fields->Items($x)->FieldName()."</td>"; 
	}
	echo "</tr>";
		
	#Looping Dataset
	while (! $DataSet->Eof()){
		echo "<tr>";
	    for ($x = 0; $x <= $fc; $x++) {
			$lFN = $DataSet->Fields->Items($x)->FieldName();
		    echo "<td>".$DataSet->FindField($lFN)->AsString()."</td>"; 
	    }
	    echo "</tr>";
		$DataSet->Next();
	}
    echo "</table>"."<br>";		
}

function GetData(){
	global $ComServer;
	
    $lSQL = '<?xml version="1.0" standalone="yes"?>  <DATAPACKET Version="2.0"><METADATA><FIELDS>
	         <FIELD attrname="ColumnNo" fieldtype="i4" required="true"/><FIELD attrname="ColumnType" fieldtype="string" WIDTH="1"/>
             <FIELD attrname="Param1" fieldtype="i4" required="true"/><FIELD attrname="Param2" fieldtype="i4" required="true"/>
             <FIELD attrname="IsLocal" fieldtype="boolean"/><FIELD attrname="HeaderScript" fieldtype="bin.hex" SUBTYPE="Text" WIDTH="1"/>
             </FIELDS><PARAMS/></METADATA><ROWDATA><ROW ColumnNo="0" ColumnType="" Param1="0" Param2="0" IsLocal="FALSE"/>
             <ROW ColumnNo="1" ColumnType="A" Param1="0" Param2="0" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;Current Mth&apos;&#013;end;"/>
             <ROW ColumnNo="2" ColumnType="A" Param1="-1" Param2="-1" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;1 Months&apos;&#013;end;"/>
             <ROW ColumnNo="3" ColumnType="A" Param1="-2" Param2="-2" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;2 Months&apos;&#013;end;"/>
             <ROW ColumnNo="4" ColumnType="A" Param1="-3" Param2="-3" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;3 Months&apos;&#013;end;"/>
             <ROW ColumnNo="5" ColumnType="A" Param1="-4" Param2="-4" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;4 Months&apos;&#013;end;"/>
             <ROW ColumnNo="6" ColumnType="B" Param1="-999999" Param2="-5" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;5 Month &amp; above&apos;&#013;end;"/>
             </ROWDATA></DATAPACKET>';
	
	$lRptVar = $ComServer->RptObjects->Find('Customer.Aging.RO');
	$lRptVar->Params->Find('ActualGroupBy')->AsString = 'Code;CompanyName'; #Fixed
#	$lRptVar->Params->Find('AgentData')->AsBlob               = ; #Not use if AllAgent is True
    $lRptVar->Params->Find('AgingData')->AsString           = $lSQL;
    $lRptVar->Params->Find('AgingDate')->AsDate             = '23 Sep 2022';
    $lRptVar->Params->Find('AgingOn')->AsString             = 'I'; #Fixed
    $lRptVar->Params->Find('AllAgent')->AsBoolean           = True;
    $lRptVar->Params->Find('AllArea')->AsBoolean            = True;
    $lRptVar->Params->Find('AllCompany')->AsBoolean         = True;
    $lRptVar->Params->Find('AllCompanyCategory')->AsBoolean = True;
    $lRptVar->Params->Find('AllControlAccount')->AsBoolean  = True;
    $lRptVar->Params->Find('AllCurrency')->AsBoolean        = True;
    $lRptVar->Params->Find('AllDocProject')->AsBoolean      = True;
#    $lRptVar->Params->Find('AreaData')->AsBlob            = ; #Not use if AllArea is True
#    $lRptVar->Params->Find('CompanyCategoryData')->AsBlob = ; #Not use if AllCompanyCategory is True
#    $lRptVar->Params->Find('CompanyData')->AsBlob         = ; #Not use if AllCompany is True
#    $lRptVar->Params->Find('ControlAccountData')->AsBlob  = ; #Not use if AllControlAccount is True
#    $lRptVar->Params->Find('CurrencyData')->AsBlob        = ; #Not use if AllCurrency is True
#    $lRptVar->Params->Find('DocProjectData')->AsBlob      = ; #Not use if AllDocProject is True
    $lRptVar->Params->Find('FilterPostDate')->AsBoolean      = True;
#    $lRptVar->Params->Find('GroupBy
    $lRptVar->Params->Find('IncludePDC')->AsBoolean         = False;
    $lRptVar->Params->Find('IncludeZeroBalance')->AsBoolean = False;
    $lRptVar->Params->Find('SortBy')->AsString              = 'Code;CompanyName';
    $lRptVar->Params->Find('DateTo')->AsDate                = '23 Sep 2022';
    $lRptVar->Params->Find('IncludeKnockedOffDetail')->AsBoolean = False;
	
	$lRptVar->CalculateReport();
	$lDataSetHdr = $lRptVar->DataSets->Find('cdsAgingHeader');
	$lDataSet = $lRptVar->DataSets->Find('cdsMain');
	$lDataSet2 = $lRptVar->DataSets->Find('cdsDocument');
	$lDataSetCO = $lRptVar->DataSets->Find('cdsCompany');

    if ($lDataSet->RecordCount > 0) {
		echo "Header"."<br>";	
		SetGrid($lDataSetHdr);
						
		echo "Main Data"."<br>";
		SetGrid($lDataSet);
		
		echo "Detail Invoice"."<br>";
		SetGrid($lDataSet2);

		echo "Company Information"."<br>";
		SetGrid($lDataSetCO);

	}else {
    echo "Record Not Found";
    }
}

if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
        GetData();
		echo "<br>";
        echo date("d M Y h:i:s A")." - Done";	
    }
    finally
    {
        #$ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Get AR Aging"/> 
    </form> 
</body>
</html>


Node JS

Module Require in Node JS
- Winax (Mandatory) -> npm install winax

Common

  • Common.js file for example code
Common Function
/* Updated 31 Jul 2023 */
var winax = require('C:\\node_js\\node_modules\\winax'); /* Path where you install winax */
var cp = require('child_process'); 

exports.KillApp = function KillApp(){
	cp.exec('start cmd.exe /C "taskkill /IM "SQLACC.exe" /F"');
}

exports.CreateSQLAccServer = function CreateSQLAccServer() {  
  var ComServer;
  ComServer = new winax.Object('SQLAcc.BizApp');
  if (!ComServer.IsLogin) {           /* check whether user has logon */
    ComServer.Login('ADMIN', 'ADMIN', /* UserName, Password */
	/* 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', */
	'D:\\Happy\\DB\\DEFAULT.DCF', /* DCF File */
	'ACC-0024.FDB'); /* FDB Name */
  }
  return ComServer;
}

exports.ShowResult = function ShowResult(ADataset){
  var fc, fn, fv, lresult;
  ADataset.First;
  while (!ADataset.Eof){
	  fc = ADataset.Fields.Count;
	  for (let i = 0; i < fc; i++) {
		  fn = ADataset.Fields.Items(i).FieldName;
          fv = ADataset.FindField(fn).AsString;
		  lresult =  "Index : "+ i + " FieldName : " + fn + " Value : " + fv;
		  console.log(lresult);
      }
	  console.log("====");
      ADataset.Next();	  
  }
}

exports.ShowMsg = function ShowMsgShowMsg(AMsg){
    try {
        var WSH = new winax.Object('WScript.Shell');
        WSH.popup(AMsg);
    } catch (e) {
        console.log(e);
    }	
}

Get Company Profile

Get Company Profile
/* Updated 22 Jul 2023 */
var Common = require('./Common'); 
var ComServer, lDataSet;

function GetData() {
  var lSQL;
  lSQL = "SELECT COMPANYNAME, REMARK, BRN, BRN2, GSTNO, ";
  lSQL = lSQL + "SALESTAXNO, SERVICETAXNO, ";
  lSQL = lSQL + "ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS4 FROM SY_PROFILE ";
  lDataSet = ComServer.DBManager.NewDataSet(lSQL);  
  
  Common.ShowResult(lDataSet);
}

try{
	ComServer = Common.CreateSQLAccServer();
	GetData();
	ComServer.Logout();
} catch(e){
	console.error(e.message)
} finally {
	Common.KillApp();
}

Complete Post

Complete Post
/* Updated 22 Jul 2023 
This will doing following posting
01. Cash Sales
02. Sales Credit Note
03. Customer Payment With Knock off
04. Edit Credit Note Posted in Step 02 & Knock Off
05. Customer Refund to Knock off Credit Note
*/
var Common = require('./Common'); 
var ComServer;

function PostDataCS() {
  var BizObject, lMain, lDetail;
  BizObject = ComServer.BizObjects.Find('SL_CS') ;

  lMain   = BizObject.DataSets.Find('MainDataSet');  /*lMain contains master data*/
  lDetail = BizObject.DataSets.Find('cdsDocDetail'); /*lDetail contains detail data */ 

  /*Begin Looping yr data*/
  /*Insert Data - Master*/ 
  BizObject.New();
  lMain.FindField('DocNo').AsString       = "--CS Test--";
  lMain.FindField('DocDate').value        = "20/12/2022";
  lMain.FindField('PostDate').value       = "20/12/2022";
  lMain.FindField('Code').AsString        = "300-C0001"; /*Customer Account*/
  lMain.FindField('CompanyName').AsString = "Cash Sales"
  lMain.FindField('Address1').AsString    = ""; /*Optional*/
  lMain.FindField('Address2').AsString    = ""; /*Optional*/
  lMain.FindField('Address3').AsString    = ""; /*Optional*/
  lMain.FindField('Address4').AsString    = ""; /*Optional*/
  lMain.FindField('Phone1').AsString      = ""; /*Optional*/
  lMain.FindField('Description').AsString = "Sales";
  
  /*Insert Data - Detail*/
  /*For Tax Inclusive = True with override Tax Amount*/
  lDetail.Append();
  lDetail.FindField('Seq').value            = 1;
  lDetail.FindField('Account').AsString     = "500-000"; /*Sales Account*/
  lDetail.FindField('Description').AsString = "Sales Item A";
  lDetail.FindField('Qty').AsFloat          = 1;
  lDetail.FindField('Tax').AsString         = "SV";
  lDetail.FindField('TaxRate').AsString     = "6%";
  lDetail.FindField('TaxInclusive').value   = 0;
  lDetail.FindField('UnitPrice').AsFloat    = 435;
  lDetail.FindField('Amount').AsFloat       = 410.37; /*Exclding Tax Amt*/
  lDetail.FindField('TaxAmt').AsFloat       = 24.63;
  
  lDetail.DisableControls();
  lDetail.FindField('TaxInclusive').value   = 1;
  lDetail.EnableControls();
  
  lDetail.Post();
  
  /*For Tax Inclusive = False with override Tax Amount*/
  lDetail.Append();
  lDetail.FindField('Seq').value            = 2;
  lDetail.FindField('Account').AsString     = "500-000";
  lDetail.FindField('Description').AsString = "Sales Item B";
  lDetail.FindField('Qty').AsFloat          = 1;
  lDetail.FindField('Tax').AsString         = "SV";
  lDetail.FindField('TaxRate').AsString     = "6%";
  lDetail.FindField('TaxInclusive').value   = 0;
  lDetail.FindField('UnitPrice').AsFloat    = 94.43;
  lDetail.FindField('Amount').AsFloat       = 94.43;
  lDetail.FindField('TaxAmt').AsFloat       = 5.66;
  lDetail.Post();  
  
  /*For With Item Code*/
  lDetail.Append();
  lDetail.FindField('Seq').value            = 3;
  lDetail.FindField('ItemCode').AsString    = "ANT";
  lDetail.FindField('Description').AsString = "Sales Item B";
  /*lDetail.FindField('Account').AsString     = "500-000"; If you wanted override the Sales Account Code*/
  lDetail.FindField('Qty').AsFloat          = 2;
  lDetail.FindField('UOM').AsString         = "UNIT";
  /*lDetail.FindField('DISC').AsString        = "5%+3"; Optional (eg 5% plus 3 Discount)*/
  lDetail.FindField('Tax').AsString         = "SV";
  lDetail.FindField('TaxRate').AsString     = "6%";
  lDetail.FindField('TaxInclusive').value   = 0;
  lDetail.FindField('UnitPrice').AsFloat    = 100;
  lDetail.FindField('Amount').AsFloat       = 200;
  lDetail.FindField('TaxAmt').AsFloat       = 12;
  lDetail.Post();
  
  /*Save Document*/
  BizObject.Save();
  BizObject.Close();  
}

function PostDataPM() {
  var BizObject, lMain, lDetail, v;
    
  BizObject = ComServer.BizObjects.Find('AR_PM') ;

  lMain   = BizObject.DataSets.Find('MainDataSet');  /*lMain contains master data*/
  lDetail = BizObject.DataSets.Find('cdsKnockOff'); /*lDetail contains detail data */
  
  BizObject.New();
  
  lMain.FindField('DocNo').AsString         = "--PM Test--";
  lMain.FindField('Code').AsString          = "300-C0001";
  lMain.FindField('DocDate').value          = "20/12/2022";
  lMain.FindField('PostDate').value         = "20/12/2022";
  lMain.FindField('Description').AsString   = "Payment for A/";
  lMain.FindField('PaymentMethod').AsString = "320-000"; /*Bank or Cash Account*/
  lMain.FindField('ChequeNumber').AsString  = "";
  lMain.FindField('BankCharge').AsFloat     = 0;
  lMain.FindField('DocAmt').AsFloat         = 200.00;
  lMain.FindField('Cancelled').AsString     = "F";
  
  v = ComServer.CreateOleVariantArray(2);
  v.SetItem(0, 'IV'); /*Knock Off DocType IV or DN*/
  v.SetItem(1, '--CS Test--'); /*Knock Off DocNo*/ 
  
  if (lDetail.Locate('DocType;DocNo', v.AsOleVariant(), false, false)){
      lDetail.Edit();
      lDetail.FindField('KOAmt').AsFloat     = "147.09";	/*Partial Knock Off*/	  
      lDetail.FindField('KnockOff').AsString = 'T';
      lDetail.Post();
	  }
    /* Save document */  
  BizObject.Save();
  BizObject.Close();
}

function PostDataCN() {
  var BizObject, lMain, lDetail;
  BizObject = ComServer.BizObjects.Find('SL_CN') ;

  lMain   = BizObject.DataSets.Find('MainDataSet');  /*lMain contains master data*/
  lDetail = BizObject.DataSets.Find('cdsDocDetail'); /*lDetail contains detail data */ 

  /*Begin Looping yr data*/
  /*Insert Data - Master*/ 
  BizObject.New();
  lMain.FindField('DocNo').AsString       = "--CN Test--";
  lMain.FindField('DocDate').value        = "21/12/2022";
  lMain.FindField('PostDate').value       = "21/12/2022";
  lMain.FindField('Code').AsString        = "300-C0001"; /*Customer Account*/
  lMain.FindField('CompanyName').AsString = "Cash Sales"
  lMain.FindField('Address1').AsString    = ""; /*Optional*/
  lMain.FindField('Address2').AsString    = ""; /*Optional*/
  lMain.FindField('Address3').AsString    = ""; /*Optional*/
  lMain.FindField('Address4').AsString    = ""; /*Optional*/
  lMain.FindField('Phone1').AsString      = ""; /*Optional*/
  lMain.FindField('Description').AsString = "Sales Returned";
  
  /*Insert Data - Detail*/  
  /*For With Item Code*/
  lDetail.Append();
  lDetail.FindField('Seq').value             = 1;
  lDetail.FindField('ItemCode').AsString     = "ANT";
  lDetail.FindField('Description').AsString  = "Sales Item B";
  lDetail.FindField('Description2').AsString = "Product Spoil"; /*Reason*/
  lDetail.FindField('Remark1').AsString      = "--IV Test--"; /*Invoice No*/
  lDetail.FindField('Remark2').AsString      = "20 Dec 2022"; /*Invoide Date*/
  lDetail.FindField('Qty').AsFloat          = 1;
  lDetail.FindField('UOM').AsString         = "UNIT";
  lDetail.FindField('Tax').AsString         = "SV";
  lDetail.FindField('TaxRate').AsString     = "6%";
  lDetail.FindField('TaxInclusive').value   = 0;
  lDetail.FindField('UnitPrice').AsFloat    = 100;
  lDetail.FindField('Amount').AsFloat       = 100;
  lDetail.FindField('TaxAmt').AsFloat       = 6;
  lDetail.Post();
  
  /*Save Document*/
  BizObject.Save();
  BizObject.Close();  
}

function PostKnockIVCN() {
  var BizObject, lMain, lDetail, v, lDocNo, lDocKey;
    
  BizObject = ComServer.BizObjects.Find('AR_CN') ;

  lMain   = BizObject.DataSets.Find('MainDataSet');  /*lMain contains master data*/
  lDetail = BizObject.DataSets.Find('cdsKnockOff'); /*lDetail contains detail data */
  
  /* Find CN Number */
  lDocNo = "--CN Test--"
  lDocKey = BizObject.FindKeyByRef('DocNo', lDocNo);
  BizObject.Params.Find('DocKey').Value = lDocKey;
  
  if (lDocKey != null) {
	  BizObject.Open();
	  BizObject.Edit();
	  lMain.Edit();
	  
	  v = ComServer.CreateOleVariantArray(2);
	  v.SetItem(0, 'IV'); /*Knock Off DocType IV or DN*/
	  v.SetItem(1, '--CS Test--'); /*Knock Off DocNo*/ 
  
	  if (lDetail.Locate('DocType;DocNo', v.AsOleVariant(), false, false)){
		  lDetail.Edit();
	      lDetail.FindField('KOAmt').AsFloat     = "100";	/*Partial Knock Off*/	  
	      lDetail.FindField('KnockOff').AsString = 'T';
	      lDetail.Post();
	  }
    /* Save document */  
	  BizObject.Save();
	  BizObject.Close();
  }
}

function PostDataCF() {
  var BizObject, lMain, lDetail, v;
    
  BizObject = ComServer.BizObjects.Find('AR_CF') ;

  lMain   = BizObject.DataSets.Find('MainDataSet');  /*lMain contains master data*/
  lDetail = BizObject.DataSets.Find('cdsKnockOff'); /*lDetail contains detail data */
  
  BizObject.New();
  
  lMain.FindField('DocNo').AsString         = "--CF Test--";
  lMain.FindField('Code').AsString          = "300-C0001";
  lMain.FindField('DocDate').value          = "24/12/2022";
  lMain.FindField('PostDate').value         = "24/12/2022";
  lMain.FindField('Description').AsString   = "Payment for A/";
  lMain.FindField('PaymentMethod').AsString = "320-000"; /*Bank or Cash Account*/
  lMain.FindField('ChequeNumber').AsString  = "";
  lMain.FindField('BankCharge').AsFloat     = 0;
  lMain.FindField('DocAmt').AsFloat         = 6.00;
  lMain.FindField('Cancelled').AsString     = "F";
  
  v = ComServer.CreateOleVariantArray(2);
  v.SetItem(0, 'CN'); /*Knock Off DocType*/
  v.SetItem(1, '--CN Test--'); /*Knock Off DocNo*/ 
  
  if (lDetail.Locate('DocType;DocNo', v.AsOleVariant(), false, false)){
      lDetail.Edit();
      lDetail.FindField('KOAmt').AsFloat     = "4";	/*Partial Knock Off*/	  
      lDetail.FindField('KnockOff').AsString = 'T';
      lDetail.Post();
	  }
    /* Save document */  
  BizObject.Save();
  BizObject.Close();
}

try{
	ComServer = Common.CreateSQLAccServer();
	console.log("Posting Cash Sales");
    PostDataCS();
    console.log("Posting Payment");
    PostDataPM();
    console.log("Posting Sales CN");
    PostDataCN();
    console.log("Posting Knock Off CN");
    PostKnockIVCN();
    console.log("Posting Customer Refund");
    PostDataCF();
    console.log("Done");
	ComServer.Logout();
} catch(e){
	console.error(e.message)
} finally {
	Common.KillApp();
}

Get Picture & Description3(Rich Text)

Get Picture & Description3(Rich Text) Script
/* Updated 31 Jul 2023 */
var Common = require('./Common'); 
var ComServer, lDataSet;
const fs = require('fs');

function saveImage(filename, data){
  var myBuffer = new Buffer.alloc(data.length);
  for (var i = 0; i < data.length; i++) {
      myBuffer[i] = data[i];
  }
  fs.writeFile(filename, myBuffer, function(err) {
      if(err) {
          console.log(err);
      } else {
          console.log("The Image file was saved!");
      }
  });
}

function ExpFile(AFName, AData){
	const FN = new console.Console(fs.createWriteStream(AFName));
    FN.log(AData);
}

function GetData() {
  var lSQL, txt, rtf;
  lSQL = "SELECT Description3, Picture FROM ST_ITEM ";
  lSQL = lSQL + "WHERE Code='ANT' ";
  lDataSet = ComServer.DBManager.NewDataSet(lSQL);  
  
  lDataSet.First;
  rtf = lDataSet.FindField('Description3').AsString;
  console.log(rtf);
  
  ExpFile('./output.rtf', rtf);
  
  txt = ComServer.Utility.RichTextToPlainText(rtf);
  Common.ShowMsg(txt);
  /* console.log(txt); <= Not support Unicode */
  
  ExpFile('./output.txt', txt);  
  console.log('Done Export');
  
  saveImage("./Pic.jpg", lDataSet.FindField('Picture').Value);
}

try{
	ComServer = Common.CreateSQLAccServer();
	GetData();
	ComServer.Logout();
} catch(e){
	console.error(e.message)
} finally {
	Common.KillApp();
}

Get Stock Qty Balance

Get Picture & Description3(Rich Text) Script
/* Updated 18 Jan 2024 */
var Common = require('./Common'); 
var ComServer;

function GetListData() {
  var lSQL, lDataSet;
  lSQL = "SELECT  ItemCode, Location, Batch, Sum(Qty) Qty  FROM ST_TR   ";
  lSQL = lSQL + "WHERE PostDate<='31 Dec 2019' ";
  lSQL = lSQL + "AND ITEMCODE ='ANT' ";
  lSQL = lSQL + "GROUP BY ItemCode, Location, Batch ";
  
  lDataSet = ComServer.DBManager.NewDataSet(lSQL);
  
  Common.ShowResult(lDataSet);
}

try{
	ComServer = Common.CreateSQLAccServer();
	GetListData();
	ComServer.Logout();
} catch(e){
	console.error(e.message)
} finally {
	Common.KillApp();
}

SO to DO

SO to DO Script
/*Updated 26 Apr 2024*/
var Common = require('./Common'); 
var ComServer;

function PostData() {
  var BizObject, lMain, lDetail, lSQL, lDataSet;
  
  lSQL = "SELECT Dockey, DocNo,Code, CompanyName, DocProject, Seq, DtlKey, ItemCode, Description, Qty, UOM, UnitPrice, Disc, Amount, DtlProject, ";
  lSQL = lSQL + "Tax, TaxRate, TaxInclusive, TaxAmt, COALESCE(Sum(XFQty),0) XFQty, COALESCE((Qty-Sum(XFQty)), Qty) OSQty FROM ( ";
  lSQL = lSQL + "SELECT A.Dockey, A.DocNo, A.Code, A.CompanyName, A.Project DocProject, ";
  lSQL = lSQL + "B.DtlKey, B.Seq, B.ItemCode, B.Description, B.Qty, B.UOM, B.UnitPrice, B.Disc, B.Amount, ";
  lSQL = lSQL + "B.Tax, B.TaxRate, B.TaxInclusive, B.TaxAmt, B.Project DtlProject, C.Qty XFQty FROM SL_SO A ";
  lSQL = lSQL + "INNER JOIN SL_SODTL B ON (A.DOCKEY=B.DOCKEY) ";
  lSQL = lSQL + "LEFT JOIN ST_XTRANS C ON (A.DOCKEY=C.FROMDOCKEY AND B.DTLKEY=C.FROMDTLKEY ";
  lSQL = lSQL + "                          AND C.FROMDOCTYPE='SO') ";
  lSQL = lSQL + "WHERE A.DOCNO='SO-00041') ";
  lSQL = lSQL + "GROUP BY Dockey, DocNo, Code, CompanyName, DocProject, Seq, Dtlkey, ItemCode, Description, Qty, UOM, UnitPrice, Disc, ";
  lSQL = lSQL +" Amount, DtlProject, Tax, TaxRate, TaxInclusive, TaxAmt ";
  lSQL = lSQL + "HAVING COALESCE((Qty-Sum(XFQty)), Qty) >0 ";
  
  lDataSet = ComServer.DBManager.NewDataSet(lSQL); 
  
  if (lDataSet.RecordCount > 0) {
	  BizObject = ComServer.BizObjects.Find('SL_DO') ;	  
	  lMain   = BizObject.DataSets.Find('MainDataSet');  /*lMain contains master data*/
	  lDetail = BizObject.DataSets.Find('cdsDocDetail'); /*lDetail contains detail data */	  

	  BizObject.New();
	  lMain.FindField('DocNo').AsString       = "<<New>>";
      lMain.FindField('DocDate').value        = "26/04/2024";
      lMain.FindField('PostDate').value       = "26/04/2024";
      lMain.FindField('Code').AsString        = lDataSet.FindField('Code').AsString; /*Customer Account*/
      lMain.FindField('Description').AsString = "Post from 3rd Party";
	  
	  lDataSet.First;
	  while (!lDataSet.Eof){  
		  lDetail.Append();
          lDetail.FindField('Seq').value            = lDataSet.FindField('Seq').Value;
          lDetail.FindField('ItemCode').AsString    = lDataSet.FindField('ItemCode').AsString;
          lDetail.FindField('Description').AsString = lDataSet.FindField('Description').AsString;
          lDetail.FindField('Qty').AsFloat          = lDataSet.FindField('OSQty').AsFloat;/*Transfer all balance Qty*/
          lDetail.FindField('UOM').AsString         = lDataSet.FindField('UOM').AsString;
          lDetail.FindField('DISC').value           = lDataSet.FindField('DISC').AsString;
          lDetail.FindField('Tax').value            = lDataSet.FindField('Tax').AsString;
          lDetail.FindField('TaxRate').value        = lDataSet.FindField('TaxRate').AsString;
          lDetail.FindField('TaxInclusive').value   = lDataSet.FindField('TaxInclusive').value;
          lDetail.FindField('UnitPrice').AsFloat    = lDataSet.FindField('UnitPrice').AsFloat ;
          lDetail.FindField('Amount').AsFloat       = lDataSet.FindField('Amount').AsFloat;
          lDetail.FindField('TaxAmt').AsFloat       = lDataSet.FindField('TaxAmt').AsFloat;
		  lDetail.FindField('FromDocType').AsString = "SO"; /*From Document Type*/
          lDetail.FindField('FromDockey').AsFloat   = lDataSet.FindField('Dockey').AsFloat;
          lDetail.FindField('FromDtlkey').AsFloat   = lDataSet.FindField('DtlKey').AsFloat;
          lDetail.Post();
          lDataSet.Next();
	  }
      /*Save Document*/
      BizObject.Save();
	  BizObject.Close(); 
  } else
	  console.log("Record Not Found");
}



try{
	ComServer = Common.CreateSQLAccServer();
	console.log("Posting SO to DO");
    PostData();
    console.log("Done");
	ComServer.Logout();
} catch(e){
	console.error(e.message)
} finally {
	Common.KillApp();
}


VB Script

Get Company Profile

Company Profile Script
'Copy below script & paste to notepad & name it as eg Common.Agent.RO.vbs
Call GetCoInfo
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
 
Function GetCoInfo
Dim ComServer, RptObject, lDataSet
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB" 
  END IF
 
  'Step 2: Find and Create the Report Objects
  Set RptObject = ComServer.RptObjects.Find("Common.Agent.RO") 
 
 
  'Step 3: Perform Report calculation 
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsProfile")

  MsgBox "Count " & lDataSet.RecordCount
 
  'Step 5 Retrieve the output 
  lDataSet.First
  While (not lDataSet.eof)
	MsgBox "Company Name : " & lDataSet.FindField("CompanyName").AsString 
	
	MsgBox "Remark : " & lDataSet.FindField("Remark").AsString

	MsgBox "ROC No : " & lDataSet.FindField("RegisterNo").AsString

	MsgBox "GST No : " & lDataSet.FindField("GSTNo").AsString
	
	MsgBox "Address 1 : " & lDataSet.FindField("Address1").AsString
	
	MsgBox "Address 2 : " & lDataSet.FindField("Address2").AsString
	
	MsgBox "Address 3 : " & lDataSet.FindField("Address3").AsString
	
	MsgBox "Address 4 : " & lDataSet.FindField("Address4").AsString
	
	MsgBox "Attention : " & lDataSet.FindField("Attention").AsString
	
	MsgBox "Phone : " & lDataSet.FindField("Phone1").AsString
	
	MsgBox "Fax : " & lDataSet.FindField("Fax1").AsString
	
	MsgBox "E-Mail : " & lDataSet.FindField("EMail").AsString
	lDataSet.Next
  Wend

  'Step 6 : Logout after done  
  ComServer.Logout    
End Function

Complete Post

SL_CS, AR_PM, SL_CN & AR_CN Script
'Updated 13 Sep 2018
'Copy below script & paste to notepad & name it as eg SL_CS.vbs
'This will doing following posting
'01. Cash Sales
'02. Sales Credit Note
'03. Customer Payment With Knock off
'04. Edit Credit Note Posted in Step 02 & Knock Off
Call CheckLogin
Call InsertData

Dim ComServer

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

function CheckLogin
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
	                'UserName, Password, DCF full path, Database filename
  END IF
End Function

Function InsertData
Dim BizObject, lMain, lDetail, lDate
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("SL_CS") 

  'Step 3: Set Dataset
  Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data  
  
  'Begin Looping yr data
  'Step 4 : Insert Data - Master
  lDate = CDate("January 1, 2017")
  BizObject.New
  lMain.FindField("DocKey").value         = -1
  lMain.FindField("DocNo").AsString       = "--IV Test--"
  lMain.FindField("DocDate").value        = lDate
  lMain.FindField("PostDate").value       = lDate
  lMain.FindField("Code").AsString        = "300-C0001" 'Customer Account
  lMain.FindField("CompanyName").AsString = "Cash Sales"
  lMain.FindField("Address1").AsString    = "" 'Optional
  lMain.FindField("Address2").AsString    = "" 'Optional
  lMain.FindField("Address3").AsString    = "" 'Optional
  lMain.FindField("Address4").AsString    = "" 'Optional
  lMain.FindField("Phone1").AsString      = "" 'Optional
  lMain.FindField("Description").AsString = "Sales"
    
  'Step 5: Insert Data - Detail
  'For Tax Inclusive = True with override Tax Amount
  lDetail.Append
  lDetail.FindField("DtlKey").value         = -1
  lDetail.FindField("DocKey").value         = -1
  lDetail.FindField("Seq").value            = 1
  lDetail.FindField("Account").AsString     = "500-000" 'Sales Account
  lDetail.FindField("Description").AsString = "Sales Item A"
  lDetail.FindField("Qty").AsFloat          = 1
  lDetail.FindField("Tax").AsString         = "SR"
  lDetail.FindField("TaxRate").AsString     = "6%"
  lDetail.FindField("TaxInclusive").value   = 0
  lDetail.FindField("UnitPrice").AsFloat    = 435
  lDetail.FindField("Amount").AsFloat       = 410.37 'Exclding GST Amt
  lDetail.FindField("TaxAmt").AsFloat       = 24.63
  
  lDetail.DisableControls
  lDetail.FindField("TaxInclusive").value   = 1
  lDetail.EnableControls
  
  lDetail.Post
  
  'For Tax Inclusive = False with override Tax Amount
  lDetail.Append
  lDetail.FindField("DtlKey").value         = -1
  lDetail.FindField("DocKey").value         = -1
  lDetail.FindField("Seq").value            = 2
  lDetail.FindField("Account").AsString     = "500-000"
  lDetail.FindField("Description").AsString = "Sales Item B"
  lDetail.FindField("Qty").AsFloat          = 1
  lDetail.FindField("Tax").AsString         = "SR"
  lDetail.FindField("TaxRate").AsString     = "6%"
  lDetail.FindField("TaxInclusive").value   = 0
  lDetail.FindField("UnitPrice").AsFloat    = 94.43
  lDetail.FindField("Amount").AsFloat       = 94.43
  lDetail.FindField("TaxAmt").AsFloat       = 5.66
  lDetail.Post

  'For With Item Code
  lDetail.Append
  lDetail.FindField("DtlKey").value         = -1
  lDetail.FindField("DocKey").value         = -1
  lDetail.FindField("Seq").value            = 3
  lDetail.FindField("ItemCode").AsString    = "ANT"
  lDetail.FindField("Description").AsString = "Sales Item B"
  'lDetail.FindField("Account").AsString     = "500-000" 'If you wanted override the Sales Account Code
  lDetail.FindField("Qty").AsFloat          = 2
  lDetail.FindField("UOM").AsString         = "UNIT"
  'lDetail.FindField("DISC").AsString        = "5%+3" 'Optional (eg 5% plus 3 Discount)
  lDetail.FindField("Tax").AsString         = "SR"
  lDetail.FindField("TaxRate").AsString     = "6%"
  lDetail.FindField("TaxInclusive").value   = 0
  lDetail.FindField("UnitPrice").AsFloat    = 100  
  lDetail.FindField("Amount").AsFloat       = 200
  lDetail.FindField("TaxAmt").AsFloat       = 12
  lDetail.Post

  'Step 6: Save Document
  BizObject.Save
  BizObject.Close
  
  'Step 7: Payment
  Call InsertARPM
  
  'Step 8: Credit Note
  Call InsertSLCN
  'End Looping yr data

  'Step 9 : Logout after done  
  'ComServer.Logout
  
  MsgBox "Done"  
End Function

Function InsertARPM
Dim BizObject, lMain, lDetail, lDate, v(1)
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("AR_PM") 
 
  'Step 3: Set Dataset
  Set lMain = BizObject.DataSets.Find("MainDataSet")   'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsKnockOff") 'lDetail contains detail data  
  
  'Step 4 : Posting
    lDate = CDate("January 23, 2017")
    BizObject.New
    lMain.FindField("DOCKEY").Value           = -1
    lMain.FindField("DocNo").AsString         = "--PM Test--" 
    lMain.FindField("CODE").AsString          = "300-C0001" 'Customer Account
    lMain.FindField("DocDate").Value          = lDate
    lMain.FindField("PostDate").Value         = lDate
    lMain.FindField("Description").AsString   = "Payment for A/c"
    lMain.FindField("PaymentMethod").AsString = "320-000" 'Bank or Cash Account
	lMain.FindField("ChequeNumber").AsString  = ""
	lMain.FindField("BankCharge").AsFloat     = 0
    lMain.FindField("DocAmt").AsFloat         = 200.00
    lMain.FindField("Cancelled").AsString     = "F"
  'Step 5: Knock Off IV
    lIVNO = "--IV Test--"
    v(0) = "IV"
    v(1) = lIVNO
	
    if (lDetail.Locate("DocType;DocNo", v, false, false)) then
      lDetail.Edit
      lDetail.FindField("KOAmt").AsFloat     = 147.09 'Partial Knock off
      lDetail.FindField("KnockOff").AsString = "T"
      lDetail.Post
	End IF  
  'Step 6: Save Document
    BizObject.Save
    BizObject.Close
End Function

Function InsertSLCN
Dim BizObject, lMain, lDetail, lDate
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("SL_CN") 

  'Step 3: Set Dataset
  Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data  
  
  'Step 4 : Insert Data - Master
  lDate = CDate("January 24, 2017")
  BizObject.New
  lMain.FindField("DocKey").value         = -1
  lMain.FindField("DocNo").AsString       = "--CN Test--"
  lMain.FindField("DocDate").value        = lDate
  lMain.FindField("PostDate").value       = lDate
  lMain.FindField("Code").AsString        = "300-C0001"
  lMain.FindField("CompanyName").AsString = "Cash Sales"
  lMain.FindField("Address1").AsString    = ""
  lMain.FindField("Address2").AsString    = ""
  lMain.FindField("Address3").AsString    = ""
  lMain.FindField("Address4").AsString    = ""
  lMain.FindField("Phone1").AsString      = ""  
  lMain.FindField("Description").AsString = "Sales Returned"
    
  'For With Item Code
  lDetail.Append
  lDetail.FindField("DtlKey").value          = -1
  lDetail.FindField("DocKey").value          = -1
  lDetail.FindField("ItemCode").AsString     = "ANT"
  lDetail.FindField("Description").AsString  = "Sales Item B"
  lDetail.FindField("Description2").AsString = "Product Spoil" 'Reason
  lDetail.FindField("Remark1").AsString      = "--IV Test--"   'Invoice No
  lDetail.FindField("Remark2").AsString      = "01 Jan 2017"   'Invoice Date
  lDetail.FindField("Qty").AsFloat           = 1
  lDetail.FindField("Tax").AsString          = "SR"
  lDetail.FindField("TaxRate").AsString      = "6%"
  lDetail.FindField("TaxInclusive").value    = 0
  lDetail.FindField("UnitPrice").AsFloat     = 100
  lDetail.FindField("Amount").AsFloat        = 100
  lDetail.FindField("TaxAmt").AsFloat        = 6  
  lDetail.Post

  'Step 6: Save Document
  BizObject.Save
  BizObject.Close
  
  'Step 7: Knock Off Invoice
  Call KnockIV
End Function

Function KnockIV
Dim BizObject, lMain, lDetail, lDate, v(1)
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("AR_CN") 
 
  'Step 3: Set Dataset
  Set lMain   = BizObject.DataSets.Find("MainDataSet") 'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsKnockOff") 'lDetail contains Knock off data  
  
  'Step 4 : Find CN Number
  lDocNo = "--CN Test--"
  lDocKey = BizObject.FindKeyByRef("DocNo", lDocNo)
  BizObject.Params.Find("DocKey").Value = lDocKey
  
  If not IsNull(lDocKey) Then 
    BizObject.Open
    BizObject.Edit
    lMain.Edit
  'Step 5: Knock Off IV
    lIVNO = "--IV Test--"
    v(0) = "IV"
    v(1) = lIVNO
	
    if (lDetail.Locate("DocType;DocNo", v, false, false)) then
      lDetail.Edit
      lDetail.FindField("KOAmt").AsFloat     = 106 'Fully Knock off
      lDetail.FindField("KnockOff").AsString = "T"
      lDetail.Post
	End IF    
  'Step 6: Save Document
    BizObject.Save
    BizObject.Close
  END IF	
End Function

AR_IV

AR_IV Script
'Copy below script & paste to notepad & name it as eg AR_IV.vbs
Call InsertARIV

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

Function InsertARIV
Dim ComServer, BizObject, lDataSet, lDataSet2, lDate

  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB" 
  END IF

  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("AR_IV") 

  'Step 3: Set Dataset
  Set lMainDataSet = BizObject.DataSets.Find("MainDataSet")    'lMainDataSet contains master data
  Set lDetailDataSet = BizObject.DataSets.Find("cdsDocDetail") 'lDetailDataSet contains detail data  
  
  'Step 4 : Insert Data - Master
  lDate = CDate("January 1, 2016")
  BizObject.New
  lMainDataSet.FindField("DocKey").value = -1
  lMainDataSet.FindField("DocNo").value = "--IV Test--"
  lMainDataSet.FindField("DocDate").value = lDate
  lMainDataSet.FindField("PostDate").value = lDate
  lMainDataSet.FindField("Code").value = "300-A0003"
  lMainDataSet.FindField("Description").value = "Sales"
    
  'Step 5: Insert Data - Detail
  'For Tax Inclusive = True with override Tax Amount
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
  lDetailDataSet.FindField("Account").value = "500-000"
  lDetailDataSet.FindField("Description").value =  "Sales Item A"
  lDetailDataSet.FindField("Tax").value =  "SR"
  lDetailDataSet.FindField("TaxInclusive").value =  0
  lDetailDataSet.FindField("Amount").value = 410.37
  lDetailDataSet.FindField("TaxAmt").value = 24.63
  
  lDetailDataSet.DisableControls
  lDetailDataSet.FindField("TaxInclusive").value =  1
  lDetailDataSet.EnableControls
  
  lDetailDataSet.FindField("Changed").value = "F"
  lDetailDataSet.Post
  
  'For Tax Inclusive = False with override Tax Amount
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
  lDetailDataSet.FindField("Account").value = "500-000"
  lDetailDataSet.FindField("Description").value =  "Sales Item B"
  lDetailDataSet.FindField("Tax").value =  "SR"
  lDetailDataSet.FindField("TaxInclusive").value =  0
  lDetailDataSet.FindField("Amount").value = 94.43
  lDetailDataSet.FindField("TaxAmt").value = 5.66
  lDetailDataSet.FindField("Changed").value = "F"
  lDetailDataSet.Post

  'Step 6: Save Document
  BizObject.Save
  BizObject.Close
  MsgBox "Done"
End Function

AR_IV-Edit

AR_IV Edit Script
'Available in Version 5.2018.833.759 & above
'Copy below script & paste to notepad & name it as eg AR_IV.vbs
Call CheckLogin
Call GetData
Call PostData

Dim ComServer, lDataSet

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

function CheckLogin
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
	                'UserName, Password, DCF full path, Database filename
  END IF
End Function

Function GetData
Dim lSQL
  lSQL = "SELECT Dockey FROM AR_IV "
  lSQL = lSQL & "WHERE DocNo='IV-00002' "
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
End Function

Function PostData
Dim BizObject, lMain, lDetail
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("AR_IV") 

  'Step 3: Set Dataset
  Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data  
  
  'Step 4 : Find Doc Number
  If lDataSet.RecordCount > 0 Then   
	lDataSet.First
    BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString
  
  
    BizObject.Open
    BizObject.Edit
    lMain.Edit
	lMain.FindField("Description").AsString = "Sales - Edited" 
  
  'Step 5: Delete all Detail
    While lDetail.RecordCount <> 0
      lDetail.First
	  lDetail.Delete
    Wend
  'Step 6: Append Detail
  lDetail.Append  
  lDetail.FindField("DtlKey").value = -1
  lDetail.FindField("Account").value = "500-000"
  lDetail.FindField("Description").value =  "Sales Item A - Edited"
  lDetail.FindField("Tax").value =  "SR"
  lDetail.FindField("TaxRate").value =  "6%"
  lDetail.FindField("TaxInclusive").value =  0
  lDetail.FindField("Amount").value = 100
  lDetail.FindField("TaxAmt").value = 6
  
  lDetail.DisableControls
  lDetail.FindField("TaxInclusive").value =  1
  lDetail.EnableControls
  
  lDetail.FindField("Changed").value = "F"
  lDetail.Post
  
  'Step 7: Save Document
    BizObject.Save
    BizObject.Close
  
  'Step 8 : Logout after done  
    'ComServer.Logout  
    MsgBox "Done" 
	Else
	MsgBox "Record Not Found" 
  END IF 
End Function

AR_PM

AR_PM Script
'Copy below script & paste to notepad & name it as eg AR_PM.vbs
Call PostData
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
 
Function PostData
Dim ComServer, BizObject, lIVNo, v(1), lDate
 
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB" 
  END IF
 
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("AR_PM") 
 
  'Step 3: Set Dataset
  Set lMain = BizObject.DataSets.Find("MainDataSet")    'lMainDataSet contains master data
  Set lDetailDataSet = BizObject.DataSets.Find("cdsKnockOff") 'lDetailDataSet contains detail data  
  
  'Step 4 : Posting
    lDate = CDate("January 23, 2017")
    BizObject.New
    lMain.FindField("DOCKEY").Value           = -1
    lMain.FindField("DocNo").AsString         = "--PM Test--" 
    lMain.FindField("CODE").AsString          = "300-C0001"
    lMain.FindField("DocDate").Value          = lDate
    lMain.FindField("PostDate").Value         = lDate
    lMain.FindField("Description").AsString   = "Payment for A/c"
    lMain.FindField("PaymentMethod").AsString = "310-000"
    lMain.FindField("DocAmt").AsFloat         = 65.57
    lMain.FindField("Cancelled").AsString     = "F"
  'Step 5: Knock Off IV
    lIVNO = "--IV Test--"
    v(0) = "IV"
    v(1) = lIVNO
	
    if (lDetailDataSet.Locate("DocType;DocNo", v, false, false)) then
      lDetailDataSet.Edit
      lDetailDataSet.FindField("KOAmt").value = 65.57
      lDetailDataSet.FindField("KnockOff").AsString = "T"
      lDetailDataSet.Post
	End IF  
  'Step 6: Save Document
    BizObject.Save
    BizObject.Close
    MsgBox "Done"
  'END IF
End Function

AR_PM-Edit

AR_PM Edit Script
'Copy below script & paste to notepad & name it as eg AR_IV.vbs
Call EditARPM
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
 
Function EditARPM
Dim ComServer, BizObject, lDataSet, lDataSet2, lDocKey, lDocNo, lIVNo, v(1)
 
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB" 
  END IF
 
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("AR_PM") 
 
  'Step 3: Set Dataset
  Set lMainDataSet = BizObject.DataSets.Find("MainDataSet")    'lMainDataSet contains master data
  Set lDetailDataSet = BizObject.DataSets.Find("cdsKnockOff") 'lDetailDataSet contains detail data  
  
  'Step 4 : Find OR Number
  lDocNo = "OR-00022"
  lDocKey = BizObject.FindKeyByRef("DocNo", lDocNo)
  BizObject.Params.Find("DocKey").Value = lDocKey
  
  If not IsNull(lDocKey) Then 
    BizObject.Open
    BizObject.Edit
    lMainDataSet.Edit
	lMainDataSet.FindField("Description").AsString = "testing"
  'Step 5: Knock Off IV
    lIVNO = "IV-00006"
    v(0) = "IV"
    v(1) = lIVNO
	
    if (lDetailDataSet.Locate("DocType;DocNo", v, false, false)) then
      lDetailDataSet.Edit
      lDetailDataSet.FindField("KOAmt").value = 50.12
      lDetailDataSet.FindField("KnockOff").AsString = "T"
      lDetailDataSet.Post
	  MsgBox "yes"
	End IF  
  'Step 6: Save Document
    BizObject.Save
    BizObject.Close
    MsgBox "Done"
  END IF
End Function

Customer.RO

Customer.RO Report Object Script
'Copy below script & paste to notepad & name it as eg customer_ro.vbs
Call GetCustomerData

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

Function GetCustomerData
Dim ComServer, RptObject, lDataSet, lDataSet2, lDateFrom, lDateTo
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB" 
  END IF

  'Step 2: Find and Create the Report Objects
  Set RptObject = ComServer.RptObjects.Find("Customer.RO") 

  'Step 3: Spool parameters
  RptObject.Params.Find("AllAgent").Value = true
  RptObject.Params.Find("AllArea").Value = true
  RptObject.Params.Find("AllCompany").Value = false
  RptObject.Params.Find("AllCompanyCategory").Value = true
  RptObject.Params.Find("AllCurrency").Value = true
  RptObject.Params.Find("AllTerms").Value = true
  RptObject.Params.Find("SelectDate").Value = true
  RptObject.Params.Find("PrintActive").Value = true
  RptObject.Params.Find("PrintInactive").Value = false
  RptObject.Params.Find("PrintPending").Value = false
  RptObject.Params.Find("PrintProspect").Value = false
  RptObject.Params.Find("PrintSuspend").Value = false
  lDateFrom = CDate("January 1, 2000")
  lDateTo = CDate("December 31, 2014")

  RptObject.Params.Find("DateFrom").Value = lDateFrom
  RptObject.Params.Find("DateTo").Value = lDateTo
  RptObject.Params.Find("CompanyData").Value = "300-A0003"
  
  'Step 4: Perform Report calculation 
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsBranch")
  MsgBox "Count " & lDataSet.RecordCount

  'Step 5 Retrieve the output 
  lDataSet.First
  While (not lDataSet.eof)
    MsgBox lDataSet.FindField("Code").AsString & " " & lDataSet.FindField("CompanyName").AsString
	lDataSet2.First
    While (not lDataSet2.eof)
	  MsgBox lDataSet2.FindField("Address1").AsString
	  lDataSet2.Next
    Wend
	lDataSet.Next
  Wend
End Function

Customer.Statement.RO

Customer.Statement.RO Report Object Script
'Copy below script & paste to notepad & name it as eg customer_statement_ro.vbs
Call GetCustStatementData
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

Function GetCustStatementData
Const Quote = """"
Dim ComServer, RptObject, lDataSet, lDataSet2, lDateFrom, lDateTo, lAgeData
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB" 
  END IF

  'Step 2: Find and Create the Report Objects
  Set RptObject = ComServer.RptObjects.Find("Customer.Statement.RO") 
 
  'Step 3: Spool parameters
  lAgeData = "<?xml version=" & Quote & "1.0" & Quote & " standalone=" & Quote & "yes" & Quote & "?>  <DATAPACKET Version=" & Quote & "2.0" & Quote & "><METADATA><FIELDS>" &_
       "<FIELD attrname=" & Quote & "ColumnNo" & Quote & " fieldtype=" & Quote & "i4" & Quote & " required=" & Quote & "true" & Quote & "/><FIELD attrname=" & Quote & "ColumnType" & Quote & " fieldtype=" & Quote & "string" & Quote & " WIDTH=" & Quote & "1" & Quote & "/>" &_
       "<FIELD attrname=" & Quote & "Param1" & Quote & " fieldtype=" & Quote & "i4" & Quote & " required=" & Quote & "true" & Quote & "/><FIELD attrname=" & Quote & "Param2" & Quote & " fieldtype=" & Quote & "i4" & Quote & " required=" & Quote & "true" & Quote & "/>" &_
       "<FIELD attrname=" & Quote & "IsLocal" & Quote & " fieldtype=" & Quote & "boolean" & Quote & "/><FIELD attrname=" & Quote & "HeaderScript" & Quote & " fieldtype=" & Quote & "bin.hex" & Quote & " SUBTYPE=" & Quote & "Text" & Quote & " WIDTH=" & Quote & "1" & Quote & "/>" &_
       "</FIELDS><PARAMS/></METADATA><ROWDATA><ROW ColumnNo=" & Quote & "0" & Quote & " ColumnType=" & Quote & "" & Quote & " Param1=" & Quote & "0" & Quote & " Param2=" & Quote & "0" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & "/>" &_
       "<ROW ColumnNo=" & Quote & "1" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "0" & Quote & " Param2=" & Quote & "0" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;Current Mth&apos;&#013;end;" & Quote & "/>" &_
       "<ROW ColumnNo=" & Quote & "2" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-1" & Quote & " Param2=" & Quote & "-1" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;1 Months&apos;&#013;end;" & Quote & "/>" &_
       "<ROW ColumnNo=" & Quote & "3" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-2" & Quote & " Param2=" & Quote & "-2" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;2 Months&apos;&#013;end;" & Quote & "/>" &_
       "<ROW ColumnNo=" & Quote & "4" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-3" & Quote & " Param2=" & Quote & "-3" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;3 Months&apos;&#013;end;" & Quote & "/>" &_
       "<ROW ColumnNo=" & Quote & "5" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-4" & Quote & " Param2=" & Quote & "-4" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;4 Months&apos;&#013;end;" & Quote & "/>" &_
       "<ROW ColumnNo=" & Quote & "6" & Quote & " ColumnType=" & Quote & "B" & Quote & " Param1=" & Quote & "-999999" & Quote & " Param2=" & Quote & "-5" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;5 Month &amp; above&apos;&#013;end;" & Quote & "/>" &_
       "</ROWDATA></DATAPACKET>"
'  RptObject.Params.Find("AgentData").Value            =  'Not use if AllAgent is True
  RptObject.Params.Find("AgingData").Value            = lAgeData 'Fixed
  RptObject.Params.Find("AgingOn").Value              = "I" 'Fixed
  RptObject.Params.Find("AllAgent").Value             = true
  RptObject.Params.Find("AllArea").Value              = true
  RptObject.Params.Find("AllCompany").Value           = false
  RptObject.Params.Find("AllCompanyCategory").Value   = true
  RptObject.Params.Find("AllControlAccount").Value    = true
  RptObject.Params.Find("AllCurrency").Value          = true
  RptObject.Params.Find("AllDocProject").Value        = true
'  RptObject.Params.Find("AreaData").Value             =  'Not use if AllArea is True
'  RptObject.Params.Find("CompanyCategoryData").Value  =  'Not use if AllCompanyCategory is True
  RptObject.Params.Find("CompanyData").Value          = "300-A0001"& vbCRLF & "300-C0001" 'Filter by Customer Code 300-A0001 & 300-C0001
'  RptObject.Params.Find("ControlAccountData").Value   =  'Not use if AllControlAccount is True
'  RptObject.Params.Find("CurrencyData").Value         =  'Not use if AllCurrency is True
  lDateFrom = CDate("August 1, 2016")
  lDateTo = CDate("August 31, 2016")
  RptObject.Params.Find("DateFrom").Value             = lDateFrom
  RptObject.Params.Find("DateTo").Value               = lDateTo
'  RptObject.Params.Find("DocProjectData").Value       =  'Not use if AllDocProject is True
  RptObject.Params.Find("IncludeZeroBalance").Value   = false
  RptObject.Params.Find("SelectDate").Value           = true
  RptObject.Params.Find("SortBy").Value               = "CompanyCategory;Code;CompanyName;Agent;Area;CurrencyCode;ControlAccount"
  RptObject.Params.Find("StatementDate").Value        = lDateTo ' Norm same as DateTo
  RptObject.Params.Find("StatementType").Value        = "O" 'O = Open Item, B = B/F
 
  'Step 4: Perform Report calculation 
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsDocument")
  MsgBox "Count " & lDataSet.RecordCount

  'Step 5 Retrieve the output 
  lDataSet.First
  While (not lDataSet.eof)
    MsgBox lDataSet.FindField("Code").AsString & " " & lDataSet.FindField("CompanyName").AsString & " " & lDataSet.FindField("Balance").AsString
	lDataSet2.First
    While (not lDataSet2.eof)
	  MsgBox lDataSet2.FindField("DocNo").AsString
	  lDataSet2.Next
    Wend
	lDataSet.Next
  Wend
End Function

GL.CB.RO

GL.CB.RO Report Object Script
'Copy below script & paste to notepad & name it as eg GL.CB.RO.vbs
Call GetCLCBData
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
 
Function GetCLCBData
Dim ComServer, RptObject, lDataSet, lDataSet2, lDataSet3, lDateFrom, lDateTo
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB" 
  END IF
 
  'Step 2: Find and Create the Report Objects
  Set RptObject = ComServer.RptObjects.Find("GL.CB.RO") 
 
  'Step 3: Spool parameters
  RptObject.Params.Find("AllCurrency").Value    = true
  RptObject.Params.Find("AllDocProject").Value  = true
  RptObject.Params.Find("AllDocument").Value    = true
  RptObject.Params.Find("AllItemProject").Value = true
  RptObject.Params.Find("AllItemArea").Value    = true
  RptObject.Params.Find("AllItemAgent").Value   = true
  RptObject.Params.Find("AllDocAgent").Value    = true
  RptObject.Params.Find("AllDocArea").Value     = true
  RptObject.Params.Find("AllPaymentMethod").Value = false
  'RptObject.Params.Find("CurrencyData").Value    = 'Not use if AllCurrency is true
  
  lDateFrom = CDate("January 01, 2017")
  lDateTo = CDate("December 31, 2017")
 
  'For Post Date From & Date To'
  RptObject.Params.Find("DateFrom").Value = lDateFrom 
  RptObject.Params.Find("DateTo").Value   = lDateTo
  
  'RptObject.Params.Find("DocProjectData").Value  = 'Not use if AllDocProject is true
  'RptObject.Params.Find("DocAreaData").Value     = 'Not use if AllDocArea is true
  'RptObject.Params.Find("DocAgentData").Value    = 'Not use if AllDocAgent is true
  'RptObject.Params.Find("ItemAgentData").Value   = 'Not use if AllItemAgent is true
  RptObject.Params.Find("DocType").Value          = "PV" 'PV for Payment Voucher & OR for Official Receipt
  'RptObject.Params.Find("DocumentData").Value    = 'Not use if AllDocument is true
  'RptObject.Params.Find("GroupBy").Value         = 'If you wanted to grouping the data
  RptObject.Params.Find("IncludeCancelled").Value = false
  'RptObject.Params.Find("ItemAreaData").Value    = 'Not use if AllItemArea is true
  'RptObject.Params.Find("ItemProjectData").Value = 'Not use if AllItemProject is true
  RptObject.Params.Find("PaymentMethodData").Value  = "310-001"
  RptObject.Params.Find("PrintDocumentStyle").Value = false
  RptObject.Params.Find("SelectDate").Value         = true 'For Post Date
  'RptObject.Params.Find("SelectDocDate").Value     = 'For Doc Date
  RptObject.Params.Find("SortBy").Value             = "PostDate;DocNo" 
 
  'Step 4: Perform Report calculation 
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsDetail")
  Set lDataSet3 = RptObject.DataSets.Find("cdsTax")
  MsgBox "Count " & lDataSet.RecordCount
 
  'Step 5 Retrieve the output 
  lDataSet.First
  While (not lDataSet.eof)
    MsgBox lDataSet.FindField("DocNo").AsString & " " & lDataSet.FindField("Description").AsString
	lDataSet2.First
    While (not lDataSet2.eof)
	  MsgBox lDataSet2.FindField("Code").AsString & " " & lDataSet2.FindField("Description").AsString
	  lDataSet2.Next
    Wend
	lDataSet.Next
  Wend
  'For GST List
  MsgBox "GST Code Count " & lDataSet3.RecordCount
  lDataSet3.First
  While (not lDataSet3.eof)
    MsgBox lDataSet3.FindField("Code").AsString
	lDataSet3.Next
  Wend
End Function

AR_Customer

AR_Customer - Script
'Copy below script & paste to notepad & name it as eg AR_Customer.vbs
Call CheckLogin
Call InsertData

Dim ComServer

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

function CheckLogin
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
	                'UserName, Password, DCF full path, Database filename
  END IF
End Function

Function InsertData
Dim BizObject, lMain, lDetail
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("AR_Customer") 

  'Step 3: Set Dataset
  Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsBranch") 'lDetail contains detail data  
  
  'Begin Looping yr data
  'Step 4 : Insert Data - Master
  BizObject.New
  lMain.FindField("Code").AsString       = "300-Test"
  lMain.FindField("CompanyName").AsString = "Cash Sales"
    
  'Step 5: Insert Data - Detail
  'For 1st Branch
  lDetail.Edit
  lDetail.FindField("BranchName").AsString  = "BILLING"
  lDetail.FindField("Address1").AsString    = "Address1"
  lDetail.FindField("Address2").AsString    = "Address2"
  lDetail.FindField("Address3").AsString    = "Address3"
  lDetail.FindField("Address4").AsString    = "Address4"  
  lDetail.FindField("Attention").AsString   = "Attention"  
  lDetail.FindField("Phone1").AsString      = "Phone1"
  lDetail.FindField("Fax1").AsString        = "Fax1"
  lDetail.FindField("Email").AsString       = "EmailAddress"
  lDetail.Post
  
  'For 2nd Branch
  lDetail.Append
  lDetail.FindField("BranchName").AsString  = "Branch1"
  lDetail.FindField("Address1").AsString    = "DAddress1"
  lDetail.FindField("Address2").AsString    = "DAddress2"
  lDetail.FindField("Address3").AsString    = "DAddress3"
  lDetail.FindField("Address4").AsString    = "DAddress4"  
  lDetail.FindField("Attention").AsString   = "DAttention"  
  lDetail.FindField("Phone1").AsString      = "DPhone1"
  lDetail.FindField("Fax1").AsString        = "DFax1"
  lDetail.FindField("Email").AsString       = "DEmailAddress"
  lDetail.Post

  'Step 6: Save Document
  BizObject.Save
  BizObject.Close
 
  'End Looping yr data

  'Step 7 : Logout after done  
  'ComServer.Logout
  
  MsgBox "Done"  
End Function

AR_Customer-Edit

AR_Customer - Edit Script
'Copy below script & paste to notepad & name it as eg AR_Customer.vbs
Call EditARCustomer
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
 
Function EditARCustomer
Dim ComServer, BizObject, lDataSet, lDataSet2
 
  'Step 1 Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB" 
  END IF
 
  'Step 2 Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("AR_Customer") 
 
  'Step 3 Set Dataset
  Set lMainDataSet = BizObject.DataSets.Find("MainDataSet") 'lMainDataSet contains master data
  Set lDetailDataSet = BizObject.DataSets.Find("cdsBranch") 'lDetailDataSet contains detail data  
  
  'Step 4 Find Customer Code
  BizObject.Params.Find("Code").Value = "300-Test"
  
  BizObject.Open
  BizObject.Edit
  lMainDataSet.Edit
  lMainDataSet.FindField("CompanyName").value = "Testing 123-Changed"
 
  'Step 5 For 1st Branch
    v = "BILLING"
 
    if (lDetailDataSet.Locate("BranchName", v, false, false)) then
	  lDetailDataSet.Edit 
      lDetailDataSet.FindField("Address1").AsString   = "Address1-Changed"
      lDetailDataSet.FindField("Address2").AsString   = "Address2-Changed"
      lDetailDataSet.FindField("Address3").AsString   = "Address3-Changed"
      lDetailDataSet.FindField("Address4").AsString   = "Address4-Changed"
      lDetailDataSet.FindField("Attention").AsString  = "Attention-Changed"
      lDetailDataSet.FindField("Phone1").AsString     = "Phone1-Changed"
      lDetailDataSet.FindField("Fax1").AsString       = "Fax1-Changed"
      lDetailDataSet.FindField("Email").AsString      = "EmailAddress-Changed"
      lDetailDataSet.Post
	end if
 'Step 5 For 2nd Branch
    v = "Branch1"
 
    if (lDetailDataSet.Locate("BranchName", v, false, false)) then 
      lDetailDataSet.Edit
      lDetailDataSet.FindField("Address1").AsString   = "DAddress1-Changed"
      lDetailDataSet.FindField("Address2").AsString   = "DAddress2-Changed"
      lDetailDataSet.FindField("Address3").AsString   = "DAddress3-Changed"
      lDetailDataSet.FindField("Address4").AsString   = "DAddress4-Changed"
      lDetailDataSet.FindField("Attention").AsString  = "DAttention-Changed"
      lDetailDataSet.FindField("Phone1").AsString     = "DPhone1-Changed"
      lDetailDataSet.FindField("Fax1").AsString       = "DFax1-Changed"
      lDetailDataSet.FindField("Email").AsString      = "DEmailAddress-Changed"
      lDetailDataSet.Post  
   end IF 
  'Step 6 Save Customer
  BizObject.Save
  BizObject.Close
  MsgBox "Done"
End Function

GL.TrialBalance.RO

GL Trial Balance Report Object Script
'Copy below script & paste to notepad & name it as eg GL.TrialBalance.RO.vbs
Call GetGLTBData
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
 
Function GetGLTBData
Dim ComServer, RptObject, lDataSet, lDataSet2, lDateFrom, lDateTo
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB" 
  END IF
 
  'Step 2: Find and Create the Report Objects
  Set RptObject = ComServer.RptObjects.Find("GL.TrialBalance.RO") 
 
  'Step 3: Spool parameters
  RptObject.Params.Find("AllProject").Value      = true
  RptObject.Params.Find("AllAgent").Value        = true
  RptObject.Params.Find("AllArea").Value         = true
  RptObject.Params.Find("LedgerType").Value      = "G" 'G = Legder, S = Debtor, P = Supplier
  'RptObject.Params.Find("ProjectData").Value    = 'Not use if AllArea is true
  RptObject.Params.Find("ShowZeroBalance").Value = false
  RptObject.Params.Find("SortBy").Value          = "PostDate;DocNo" 
  RptObject.Params.Find("UseDescription2").Value = false
   
  lDateFrom = CDate("October 27, 2016")
  lDateTo = CDate("December 31, 2016")
 
  'For Post Date From & Date To'
  RptObject.Params.Find("DateFrom").Value       = lDateFrom 
  RptObject.Params.Find("DateTo").Value         = lDateTo

  'RptObject.Params.Find("AgentData").Value      = 'Not use if AllAgent is true
  'RptObject.Params.Find("AreaData").Value       = 'Not use if AllArea is true
  
  RptObject.Params.Find("SortBy").Value          = "Code;Description" 
 
  'Step 4: Perform Report calculation 
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsGLAccount")

  MsgBox "Count " & lDataSet.RecordCount
 
  'Step 5 Retrieve the output 
  lDataSet.First
  While (not lDataSet.eof)
    MsgBox "Month To Date"
	MsgBox lDataSet.FindField("Code").AsString & " DR=>" & lDataSet.FindField("MTDDR").AsString & " CR=>" &	lDataSet.FindField("MTDCR").AsString
	
	MsgBox "Year To Date"
	MsgBox lDataSet.FindField("Code").AsString & " DR=>" & lDataSet.FindField("YTDDR").AsString & " CR=>" &	lDataSet.FindField("YTDCR").AsString
	lDataSet.Next
  Wend
  
  'For Account List
  lDataSet2.First
  While (not lDataSet2.eof)
	MsgBox lDataSet2.FindField("Code").AsString & " " & lDataSet2.FindField("Description").AsString
	lDataSet2.Next
  Wend
  
End Function

Customer.Aging.RO

Customer Aging Report Object Script
'Copy below script & paste to notepad & name it as eg customer_aging_ro.vbs
Call GetCustStatementData
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

Function GetCustStatementData
Const Quote = """"
Dim ComServer, RptObject, lDataSet, lDataSet2, lDateFrom, lDateTo, lAgeData
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB" 
  END IF

  'Step 2: Find and Create the Report Objects
  Set RptObject = ComServer.RptObjects.Find("Customer.Aging.RO") 
 
  'Step 3: Spool parameters
  lAgeData = "<?xml version=" & Quote & "1.0" & Quote & " standalone=" & Quote & "yes" & Quote & "?>  <DATAPACKET Version=" & Quote & "2.0" & Quote & "><METADATA><FIELDS>" &_
       "<FIELD attrname=" & Quote & "ColumnNo" & Quote & " fieldtype=" & Quote & "i4" & Quote & " required=" & Quote & "true" & Quote & "/><FIELD attrname=" & Quote & "ColumnType" & Quote & " fieldtype=" & Quote & "string" & Quote & " WIDTH=" & Quote & "1" & Quote & "/>" &_
       "<FIELD attrname=" & Quote & "Param1" & Quote & " fieldtype=" & Quote & "i4" & Quote & " required=" & Quote & "true" & Quote & "/><FIELD attrname=" & Quote & "Param2" & Quote & " fieldtype=" & Quote & "i4" & Quote & " required=" & Quote & "true" & Quote & "/>" &_
       "<FIELD attrname=" & Quote & "IsLocal" & Quote & " fieldtype=" & Quote & "boolean" & Quote & "/><FIELD attrname=" & Quote & "HeaderScript" & Quote & " fieldtype=" & Quote & "bin.hex" & Quote & " SUBTYPE=" & Quote & "Text" & Quote & " WIDTH=" & Quote & "1" & Quote & "/>" &_
       "</FIELDS><PARAMS/></METADATA><ROWDATA><ROW ColumnNo=" & Quote & "0" & Quote & " ColumnType=" & Quote & "" & Quote & " Param1=" & Quote & "0" & Quote & " Param2=" & Quote & "0" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & "/>" &_
       "<ROW ColumnNo=" & Quote & "1" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "0" & Quote & " Param2=" & Quote & "0" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;Current Mth&apos;&#013;end;" & Quote & "/>" &_
       "<ROW ColumnNo=" & Quote & "2" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-1" & Quote & " Param2=" & Quote & "-1" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;1 Months&apos;&#013;end;" & Quote & "/>" &_
       "<ROW ColumnNo=" & Quote & "3" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-2" & Quote & " Param2=" & Quote & "-2" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;2 Months&apos;&#013;end;" & Quote & "/>" &_
       "<ROW ColumnNo=" & Quote & "4" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-3" & Quote & " Param2=" & Quote & "-3" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;3 Months&apos;&#013;end;" & Quote & "/>" &_
       "<ROW ColumnNo=" & Quote & "5" & Quote & " ColumnType=" & Quote & "A" & Quote & " Param1=" & Quote & "-4" & Quote & " Param2=" & Quote & "-4" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;4 Months&apos;&#013;end;" & Quote & "/>" &_
       "<ROW ColumnNo=" & Quote & "6" & Quote & " ColumnType=" & Quote & "B" & Quote & " Param1=" & Quote & "-999999" & Quote & " Param2=" & Quote & "-5" & Quote & " IsLocal=" & Quote & "FALSE" & Quote & " HeaderScript=" & Quote & "ObjectPascal&#013;begin&#013;Value:= &apos;5 Month &amp; above&apos;&#013;end;" & Quote & "/>" &_
       "</ROWDATA></DATAPACKET>"
  RptObject.Params.Find("ActualGroupBy").Value         = "Code;CompanyName" 'Fixed
'  RptObject.Params.Find("AgentData").Value            =  'Not use if AllAgent is True
  RptObject.Params.Find("AgingData").Value            = lAgeData 'Fixed

  lDateTo = CDate("August 31, 2016")
  RptObject.Params.Find("AgingDate").Value            = lDateTo  

  RptObject.Params.Find("AgingOn").Value              = "I" 'Fixed
  RptObject.Params.Find("AllAgent").Value             = true
  RptObject.Params.Find("AllArea").Value              = true
  RptObject.Params.Find("AllCompany").Value           = false
  RptObject.Params.Find("AllCompanyCategory").Value   = true
  RptObject.Params.Find("AllControlAccount").Value    = true
  RptObject.Params.Find("AllCurrency").Value          = true
  RptObject.Params.Find("AllDocProject").Value        = true
'  RptObject.Params.Find("AreaData").Value             =  'Not use if AllArea is True
'  RptObject.Params.Find("CompanyCategoryData").Value  =  'Not use if AllCompanyCategory is True
  RptObject.Params.Find("CompanyData").Value          = "300-A0001"& vbCRLF & "300-C0001" 'Filter by Customer Code 300-A0001 & 300-C0001
'  RptObject.Params.Find("ControlAccountData").Value   =  'Not use if AllControlAccount is True
'  RptObject.Params.Find("CurrencyData").Value         =  'Not use if AllCurrency is True
'  RptObject.Params.Find("DocProjectData").Value       =  'Not use if AllDocProject is True
  RptObject.Params.Find("FilterPostDate").Value        = false
'  RptObject.Params.Find("GroupBy").Value               = 'Not use 
  RptObject.Params.Find("IncludePDC").Value        = false
  RptObject.Params.Find("IncludeZeroBalance").Value   = false
  RptObject.Params.Find("SortBy").Value               = "Code;CompanyName"
  RptObject.Params.Find("DateTo").Value               = lDateTo

 
  'Step 4: Perform Report calculation 
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsDocument")
  MsgBox "Count " & lDataSet.RecordCount

  'Step 5 Retrieve the output 
  lDataSet.First
  While (not lDataSet.eof)
    MsgBox lDataSet.FindField("Code").AsString & " " & lDataSet.FindField("CompanyName").AsString & " " & lDataSet.FindField("C1").AsString
	lDataSet2.First
    While (not lDataSet2.eof)
	  MsgBox lDataSet2.FindField("DocNo").AsString & " " & lDataSet2.FindField("C1").AsString
	  lDataSet2.Next
    Wend
	lDataSet.Next
  Wend
End Function

GL.JE.RO

GL Journal Voucher Report Object Script
'Copy below script & paste to notepad & name it as eg GLJE_ro.vbs
Call GetCustomerData

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

Function GetCustomerData
Dim ComServer, RptObject, lDataSet, lDataSet2, lDateFrom, lDateTo
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB" 
  END IF

  'Step 2: Find and Create the Report Objects
  Set RptObject = ComServer.RptObjects.Find("GL.JE.RO") 

  'Step 3: Spool parameters
  RptObject.Params.Find("AllCurrency").Value = true
  RptObject.Params.Find("AllDocProject").Value = true
  RptObject.Params.Find("AllDocument").Value = true
  RptObject.Params.Find("AllItemProject").Value = true
  RptObject.Params.Find("AllItemArea").Value = true
  RptObject.Params.Find("AllItemAgent").Value = true
  RptObject.Params.Find("AllDocAgent").Value = true
  RptObject.Params.Find("AllDocArea").Value = true
  RptObject.Params.Find("AllPaymentMethod").Value = true

  lDateFrom = CDate("December 1, 2017")
  lDateTo = CDate("December 31, 2017")

  RptObject.Params.Find("DateFrom").Value = lDateFrom
  RptObject.Params.Find("DocDateFrom").Value = lDateFrom
  RptObject.Params.Find("DateTo").Value = lDateTo
  RptObject.Params.Find("DocDateTo").Value = lDateTo
  RptObject.Params.Find("IncludeCancelled").Value = false
  RptObject.Params.Find("PrintDocumentStyle").Value = false
  RptObject.Params.Find("SelectDate").Value = true 'Post Date
  RptObject.Params.Find("SelectDocDate").Value = false 'Doc Date
  
  'Step 4: Perform Report calculation 
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsDetail")
  MsgBox "Count " & lDataSet.RecordCount

  'Step 5 Retrieve the output 
  lDataSet.First
  While (not lDataSet.eof)
    MsgBox lDataSet.FindField("DocNo").AsString & " " & lDataSet.FindField("Description").AsString
	lDataSet2.First
    While (not lDataSet2.eof)
	  MsgBox lDataSet2.FindField("Code").AsString & " " & lDataSet2.FindField("Description").AsString
	  lDataSet2.Next
    Wend
	lDataSet.Next
  Wend
End Function

SL_CS

SL_CS Script
'Copy below script & paste to notepad & name it as eg SL_CS.vbs
Call InsertData

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

Function InsertData
Dim ComServer, BizObject, lDate

  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB" 
  END IF

  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("SL_CS") 

  'Step 3: Set Dataset
  Set lMainDataSet = BizObject.DataSets.Find("MainDataSet")    'lMainDataSet contains master data
  Set lDetailDataSet = BizObject.DataSets.Find("cdsDocDetail") 'lDetailDataSet contains detail data  
  
  'Step 4 : Insert Data - Master
  lDate = CDate("January 1, 2016")
  BizObject.New
  lMainDataSet.FindField("DocKey").value = -1
  lMainDataSet.FindField("DocNo").value = "--IV Test--"
  lMainDataSet.FindField("DocDate").value = lDate
  lMainDataSet.FindField("PostDate").value = lDate
  lMainDataSet.FindField("Code").value = "300-C0001" 'Customer Code
  lMainDataSet.FindField("Description").value = "Sales"
    
  'Step 5: Insert Data - Detail
  'For Tax Inclusive = True with override Tax Amount
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
  lDetailDataSet.FindField("Account").value = "500-000" 'Sales Account Code  & can ignore if had itemcode
  lDetailDataSet.FindField("Description").value =  "Sales Item A"
  lDetailDataSet.FindField("Qty").value =  1
  lDetailDataSet.FindField("Tax").value =  "SR"
  lDetailDataSet.FindField("TaxInclusive").value =  0
  lDetailDataSet.FindField("UnitPrice").value = 410.37
  lDetailDataSet.FindField("Amount").value = 410.37
  lDetailDataSet.FindField("TaxAmt").value = 24.63
  
  lDetailDataSet.DisableControls
  lDetailDataSet.FindField("TaxInclusive").value =  1
  lDetailDataSet.EnableControls
  
  lDetailDataSet.Post
  
  'For Tax Inclusive = False with override Tax Amount
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
  lDetailDataSet.FindField("Account").value = "500-000"
  lDetailDataSet.FindField("Description").value =  "Sales Item B"
  lDetailDataSet.FindField("Qty").value =  1
  lDetailDataSet.FindField("Tax").value =  "SR"
  lDetailDataSet.FindField("TaxInclusive").value =  0
  lDetailDataSet.FindField("UnitPrice").value = 94.43
  lDetailDataSet.FindField("Amount").value = 94.43
  lDetailDataSet.FindField("TaxAmt").value = 5.66
  lDetailDataSet.Post

  'For With Item Code
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
  lDetailDataSet.FindField("ItemCode").value = "ANT"
  lDetailDataSet.FindField("Description").value =  "Sales Item B"
  lDetailDataSet.FindField("Qty").value =  2
  lDetailDataSet.FindField("Tax").value =  "SR"
  lDetailDataSet.FindField("TaxInclusive").value =  0
  lDetailDataSet.FindField("UnitPrice").value = 100
  lDetailDataSet.FindField("Amount").value = 200
  lDetailDataSet.FindField("TaxAmt").value = 12
  lDetailDataSet.Post

  'Step 6: Save Document
  BizObject.Save
  BizObject.Close
  ComServer.Logout
  MsgBox "Done"
End Function

Customer.PM.RO

Customer.PM.RO Script
'Copy below script & paste to notepad & name it as eg Customer.PM.RO.vbs
Call GetARPMData
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
 
Function GetARPMData
Dim ComServer, RptObject, lDataSet, lDataSet2, lDataSet3, lDateFrom, lDateTo
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB" 
  END IF
 
  'Step 2: Find and Create the Report Objects
  Set RptObject = ComServer.RptObjects.Find("Customer.PM.RO") 
 
  'Step 3: Spool parameters
  'RptObject.Params.Find("AgentData").Value               = 'Not use if AllAgent is true
  'RptObject.Params.Find("CompanyCategoryData").Value     = 'Not use if AllCompanyCategory is true
  RptObject.Params.Find("AllAgent").Value                = true
  RptObject.Params.Find("AllCompanyCategory").Value      = true
  RptObject.Params.Find("AllArea").Value                 = true
  RptObject.Params.Find("AllCompany").Value              = true
  RptObject.Params.Find("AllCurrency").Value             = true
  RptObject.Params.Find("AllDocument").Value             = false
  RptObject.Params.Find("AllPaymentMethod").Value        = true
  'RptObject.Params.Find("AreaData").Value                = 'Not use if AllArea is true
  'RptObject.Params.Find("CompanyData").Value             = 'Not use if AllCompany is true
  'RptObject.Params.Find("CurrencyData").Value            = 'Not use if AllCurrency is true

  lDateFrom = CDate("January 01, 2017")
  lDateTo = CDate("December 31, 2017")
  
  RptObject.Params.Find("DateFrom").Value                = lDateFrom
  RptObject.Params.Find("DateTo").Value                  = lDateTo
  RptObject.Params.Find("DocumentData").Value            = "VCOR-00049"
  'RptObject.Params.Find("GroupBy").Value                 = 'If you wanted to grouping the data
  RptObject.Params.Find("IncludeCancelled").Value        = false
  'RptObject.Params.Find("PaymentMethodData").Value       = 'Not use if AllPaymentMethod is true
  RptObject.Params.Find("PrintDocumentStyle").Value      = false
  RptObject.Params.Find("SelectDate").Value              = true
  RptObject.Params.Find("ShowUnappliedAmountOnly").Value = false
  RptObject.Params.Find("SortBy").Value                  = "PostDate;DocNo;Code"
  RptObject.Params.Find("AllDocProject").Value           = true
  RptObject.Params.Find("AllItemProject").Value          = true
  'RptObject.Params.Find("DocProjectData").Value          = 'Not use if AllDocProject is true
  'RptObject.Params.Find("ItemProjectData").Value         = 'Not use if AllItemProject is true  
  
  'Step 4: Perform Report calculation 
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsKnockOff")
  Set lDataSet3 = RptObject.DataSets.Find("cdsKnockOffDetail")
  MsgBox "Count " & lDataSet.RecordCount
 
  'Step 5 Retrieve the output 
  lDataSet.First
  While (not lDataSet.eof)
    MsgBox lDataSet.FindField("DocKey").AsString & " " &  lDataSet.FindField("DocNo").AsString & " " & lDataSet.FindField("Code").AsString
	MsgBox "cdsKnockOff Count " & lDataSet2.RecordCount
	lDataSet2.First
    While (not lDataSet2.eof)
	  MsgBox lDataSet2.FindField("FromDocKey").AsString & " " & lDataSet2.FindField("DocNo").AsString & " " & lDataSet2.FindField("KOAmt").AsString
	  lDataSet2.Next
    Wend
    MsgBox "cdsKnockOffDetail Count " & lDataSet3.RecordCount
	lDataSet3.First
    While (not lDataSet3.eof)
      MsgBox lDataSet3.FindField("FromDocKey").AsString & " " & lDataSet3.FindField("DocNo").AsString & " " & lDataSet3.FindField("KOAmt").AsString
  	  lDataSet3.Next
    Wend	
	lDataSet.Next
  Wend
End Function

Sales.IV.RO

Sales.IV.RO Script
'Copy below script & paste to notepad & name it as eg Sales.IV.RO.vbs
Call GetSalesIVData
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
 
Function GetSalesIVData
Dim ComServer, RptObject, lDataSet, lDataSet2, lDataSet3, lDateFrom, lDateTo
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB" 
  END IF
 
  'Step 2: Find and Create the Report Objects
  Set RptObject = ComServer.RptObjects.Find("Sales.IV.RO") 
 
  'Step 3: Spool parameters
  'RptObject.Params.Find("AgentData").Value              = 'Not use if AllAgent is true
  RptObject.Params.Find("AllAgent").Value               = true
  RptObject.Params.Find("AllArea").Value                = true
  RptObject.Params.Find("AllCompany").Value             = false
  RptObject.Params.Find("AllCurrency").Value            = true
  RptObject.Params.Find("AllDocProject").Value          = true
  RptObject.Params.Find("AllDocument").Value            = true
  RptObject.Params.Find("AllItem").Value                = true
  RptObject.Params.Find("AllItemProject").Value         = true
  RptObject.Params.Find("AllLocation").Value            = true
  RptObject.Params.Find("AllStockGroup").Value          = true
  RptObject.Params.Find("AllCompanyCategory").Value     = true
  RptObject.Params.Find("AllBatch").Value               = true
  RptObject.Params.Find("AllTariff").Value              = true 'For Version 776 & above
  'RptObject.Params.Find("TariffData").Value             = 'Not use if TariffData is true - For Version 776 & above
  'RptObject.Params.Find("AreaData").Value               = 'Not use if AllArea is true
  'RptObject.Params.Find("CompanyCategoryData").Value    = 'Not use if AllCompanyCategory is true
  RptObject.Params.Find("CompanyData").Value            = "300-C0001"
  'RptObject.Params.Find("CurrencyData").Value           = 'Not use if AllCurrency is true

  lDateFrom = CDate("January 01, 2017")
  lDateTo = CDate("December 31, 2017")
  
  RptObject.Params.Find("DateFrom").Value                = lDateFrom
  RptObject.Params.Find("DateTo").Value                  = lDateTo
  'RptObject.Params.Find("DocProjectData").Value          = 'Not use if AllDocProject is true
  'RptObject.Params.Find("DocumentData").Value            = 'Not use if AllDocument is true
  'RptObject.Params.Find("GroupBy").Value                 = 'If you wanted to grouping the data
  'RptObject.Params.Find("CategoryData").Value            = 'Not use if HasCategory is false
  'RptObject.Params.Find("CategoryTpl").Value             = 'For Internal use only
  RptObject.Params.Find("IncludeCancelled").Value        = false
  RptObject.Params.Find("HasCategory").Value             = false
  'RptObject.Params.Find("ItemData").Value                = 'Not use if AllItem is true
  'RptObject.Params.Find("ItemProjectData").Value         = 'Not use if AllItemProject is true
  'RptObject.Params.Find("LocationData").Value            = 'Not use if AllLocation is true
  'RptObject.Params.Find("ItemCategoryData").Value        = 'For Internal use only
  'RptObject.Params.Find("BatchData").Value               = 'Not use if AllBatch is true
  RptObject.Params.Find("PrintDocumentStyle").Value      = false
  RptObject.Params.Find("SelectDate").Value              = true
  RptObject.Params.Find("SortBy").Value                  = "PostDate;DocNo;Code"
  'RptObject.Params.Find("StockGroupData").Value          = 'Not use if AllStockGroup is true
  
  
  'Step 4: Perform Report calculation 
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsDocDetail")
  MsgBox "Count " & lDataSet.RecordCount
 
  'Step 5 Retrieve the output 
  lDataSet.First
  While (not lDataSet.eof)
    MsgBox lDataSet.FindField("DocKey").AsString & " " &  lDataSet.FindField("DocNo").AsString & " " & lDataSet.FindField("Code").AsString
	MsgBox "cdsDocDetail Count " & lDataSet2.RecordCount
	lDataSet2.First
    While (not lDataSet2.eof)
	  MsgBox lDataSet2.FindField("DocKey").AsString & " " & lDataSet2.FindField("ItemCode").AsString & " " & lDataSet2.FindField("Amount").AsString
	  lDataSet2.Next
    Wend	
	lDataSet.Next
  Wend
End Function

Customer.DueDocument.RO

Customer.DueDocument.RO Script
'Copy below script & paste to notepad & name it as eg Customer.DueDocument.RO.vbs
Call GetData
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
 
Function GetData
Dim ComServer, RptObject, lDataSet, lDateTo
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB" 
  END IF
 
  'Step 2: Find and Create the Report Objects
  Set RptObject = ComServer.RptObjects.Find("Customer.DueDocument.RO") 
 
  'Step 3: Spool parameters
  'RptObject.Params.Find("AgentData").Value              = 'Not use if AllAgent is true
  RptObject.Params.Find("AllAgent").Value               = true
  RptObject.Params.Find("AllArea").Value                = true
  RptObject.Params.Find("AllCompany").Value             = false
  RptObject.Params.Find("AllCompanyCategory").Value     = true
  RptObject.Params.Find("AllCurrency").Value            = true
  RptObject.Params.Find("AllDocProject").Value          = true
  RptObject.Params.Find("AllItemProject").Value         = true
  'RptObject.Params.Find("AreaData").Value              = 'Not use if AllArea is true
  'RptObject.Params.Find("CompanyCategoryData").Value   = 'Not use if AllCompanyCategory is true
  RptObject.Params.Find("CompanyData").Value            = "300-A0003"
  'RptObject.Params.Find("CurrencyData").Value          = 'Not use if AllCurrency is true
  'RptObject.Params.Find("DocProjectData").Value        = 'Not use if AllDocProject is true
  'RptObject.Params.Find("GroupBy").Value               = 'If you wanted to grouping the data
  'RptObject.Params.Find("ItemProjectData").Value       = 'Not use if AllItemProject is true
  RptObject.Params.Find("PrintContra").Value            = true
  RptObject.Params.Find("PrintCreditNote").Value        = true
  RptObject.Params.Find("PrintDebitNote").Value         = true
  RptObject.Params.Find("PrintInvoice").Value           = true
  RptObject.Params.Find("PrintOverDue").Value           = true
  RptObject.Params.Find("PrintUnDue").Value             = true
  RptObject.Params.Find("ShowForeignCurrency").Value    = true
  RptObject.Params.Find("ShowLocalCurrency").Value      = true
  RptObject.Params.Find("SortBy").Value                 = "PostDate;DocNo;Code"
  
  lDateTo = CDate("April 12, 2018")
  
  RptObject.Params.Find("DateTo").Value                 = lDateTo
  RptObject.Params.Find("IncludePDCheque").Value        = true  
    
  'Step 4: Perform Report calculation 
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsMain")
  MsgBox "Count " & lDataSet.RecordCount
 
  'Step 5 Retrieve the output 
  lDataSet.First
  While (not lDataSet.eof)
    MsgBox "Dockey " & lDataSet.FindField("DocKey").AsString 
	MsgBox "DocNo " & lDataSet.FindField("DocNo").AsString 
	MsgBox "DocAmt " & lDataSet.FindField("DocAmt").AsString
	MsgBox "Outstanding " & lDataSet.FindField("Outstanding").AsString
	MsgBox "Code " & lDataSet.FindField("Code").AsString
	lDataSet.Next
  Wend
End Function

Customer.IV.RO

Customer.IV.RO Script
'Copy below script & paste to notepad & name it as eg Customer.IV.RO.vbs
Call GetData
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
 
Function GetData
Dim ComServer, RptObject, lDataSet, lDataSet2, lDataSet3, lDateFrom, lDateTo
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB" 
  END IF
 
  'Step 2: Find and Create the Report Objects
  Set RptObject = ComServer.RptObjects.Find("Customer.IV.RO") 
 
  'Step 3: Spool parameters
  'RptObject.Params.Find("AgentData").Value             = 'Not use if AllAgent is true
  'RptObject.Params.Find("CompanyCategoryData").Value   = 'Not use if AllCompanyCategory is true
  RptObject.Params.Find("AllAgent").Value               = true
  RptObject.Params.Find("AllCompanyCategory").Value     = true
  RptObject.Params.Find("AllArea").Value                = true
  RptObject.Params.Find("AllCompany").Value             = true
  RptObject.Params.Find("AllCurrency").Value            = true
  RptObject.Params.Find("AllDocument").Value            = false
  RptObject.Params.Find("AllPaymentMethod").Value       = true
  'RptObject.Params.Find("AreaData").Value              = 'Not use if AllArea is true
  'RptObject.Params.Find("CompanyData").Value           = 'Not use if AllCompany is true
  'RptObject.Params.Find("CurrencyData").Value          = 'Not use if AllCurrency is true
  
  lDateFrom = CDate("January 01, 2017")
  lDateTo = CDate("December 31, 2017")
  
  RptObject.Params.Find("DateFrom").Value                = lDateFrom
  RptObject.Params.Find("DateTo").Value                  = lDateTo
  RptObject.Params.Find("DocumentData").Value            =  "IV-00012"
  'RptObject.Params.Find("GroupBy").Value                = 'If you wanted to grouping the data
  RptObject.Params.Find("IncludeCancelled").Value        = true
  'RptObject.Params.Find("PaymentMethodData").Value      = 'Not use if AllPaymentMethod is true
  RptObject.Params.Find("PrintDocumentStyle").Value      = false
  RptObject.Params.Find("SelectDate").Value              = true
  RptObject.Params.Find("ShowUnappliedAmountOnly").Value = true
  RptObject.Params.Find("SortBy").Value                  = "DocDate;DocNo;Code"
  RptObject.Params.Find("AllDocProject").Value           = true
  RptObject.Params.Find("AllItemProject").Value          = true
  'RptObject.Params.Find("DocProjectData").Value         = 'Not use if AllDocProject is true
  'RptObject.Params.Find("ItemProjectData  ").Value      = 'Not use if AllItemProject is true
    
  'Step 4: Perform Report calculation 
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsDocDetail")
  MsgBox "Count " & lDataSet.RecordCount
 
  'Step 5 Retrieve the output 
  lDataSet.First
  While (not lDataSet.eof)
    MsgBox "DocNo " & lDataSet.FindField("DocNo").AsString
	MsgBox "DocAmt " & lDataSet.FindField("DocAmt").AsString
	MsgBox "PaymentAmt " & lDataSet.FindField("PaymentAmt").AsString
	
	MsgBox "cdsDocDetail Count " & lDataSet2.RecordCount
	lDataSet2.First
    While (not lDataSet2.eof)
	  MsgBox "Account " & lDataSet2.FindField("Account").AsString
	  MsgBox "Description " & lDataSet2.FindField("Description").AsString
	  MsgBox "Amount " & lDataSet2.FindField("Amount").AsString
	  lDataSet2.Next
    Wend	
	lDataSet.Next
  Wend
End Function

Sales.OutstandingSO.RO

Sales.OutstandingSO.RO Script
'Copy below script & paste to notepad & name it as eg Sales.OutstandingSO.RO.vbs
Call GetData
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
 
Function GetData
Dim ComServer, RptObject, lDataSet, lDataSet2, lDataSet3, lDateFrom, lDateTo
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB" 
  END IF
 
  'Step 2: Find and Create the Report Objects
  Set RptObject = ComServer.RptObjects.Find("Sales.OutstandingSO.RO") 
 
  'Step 3: Spool parameters
  'RptObject.Params.Find("AgentData").Value            = 'Not use if AllAgent is true
  'RptObject.Params.Find("CompanyCategoryData").Value  = 'Not use if AllCompanyCategory is true
  'RptObject.Params.Find("LocationData").Value         = 'Not use if AllLocation is true
  'RptObject.Params.Find("StockGroupData").Value       = 'Not use if AllStockGroup is true
  RptObject.Params.Find("AllAgent").Value              = true
  RptObject.Params.Find("AllArea").Value               = true
  RptObject.Params.Find("AllCompany").Value            = true
  RptObject.Params.Find("AllDocument").Value           = false
  RptObject.Params.Find("AllItem").Value               = true
  RptObject.Params.Find("AllItemProject").Value        = true
  'RptObject.Params.Find("AreaData").Value              = 'Not use if AllArea is true
  'RptObject.Params.Find("CompanyData").Value           = 'Not use if AllCompany is true
  RptObject.Params.Find("AllTariff").Value              = true 'For Version 776 & above
  'RptObject.Params.Find("TariffData").Value             = 'Not use if TariffData is true - For Version 776 & above

  
  lDateFrom = CDate("January 01, 2017")
  lDateTo = CDate("December 31, 2017") 
  
  'RptObject.Params.Find("DateFrom").Value              = lDateFrom
  'RptObject.Params.Find("DateTo").Value                = lDateTo
  'RptObject.Params.Find("DeliveryDateFrom").Value      = lDateFrom
  'RptObject.Params.Find("DeliveryDateTo").Value        = lDateTo
  RptObject.Params.Find("DocumentData").Value           = "SO-00007"& vbCRLF & "SO-00009"
  'RptObject.Params.Find("GroupBy").Value               = 'If you wanted to grouping the data
  RptObject.Params.Find("IncludeCancelled").Value       = false
  'RptObject.Params.Find("ItemData").Value               = 'Not use if AllItem is true
  RptObject.Params.Find("PrintFulfilledItem").Value     = true 'Print transfered info
  RptObject.Params.Find("PrintOutstandingItem").Value   = true 'Print untransfer info
  'RptObject.Params.Find("ItemProjectData").Value       = 'Not use if AllItemProject is true
  RptObject.Params.Find("SelectDate").Value             = false
  RptObject.Params.Find("SelectDeliveryDate").Value     = false
  RptObject.Params.Find("SortBy").Value                 = "DocDate;DocNo;Code"
  RptObject.Params.Find("AllDocProject").Value          = true
  RptObject.Params.Find("AllLocation").Value            = true
  RptObject.Params.Find("AllCompanyCategory").Value     = true
  RptObject.Params.Find("AllBatch").Value               = true
  RptObject.Params.Find("HasCategory").Value            = false
  RptObject.Params.Find("AllStockGroup").Value          = true
  'RptObject.Params.Find("CategoryData").Value          = 'For Internal use only
  'RptObject.Params.Find("CategoryTpl").Value           = 'For Internal use only
  'RptObject.Params.Find("ItemCategoryData").Value      = 'For Internal use only
  'RptObject.Params.Find("DocProjectData").Value        = 'Not use if AllDocProject is true
  'RptObject.Params.Find("BatchData").Value             = 'Not use if AllBatch is true
  RptObject.Params.Find("TranferDocFilterDate").Value   = false
   
    
  'Step 4: Perform Report calculation 
  RptObject.CalculateReport()
  Set lDataSet = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsTransfer")
  MsgBox "Count " & lDataSet.RecordCount
 
  'Step 5 Retrieve the output 
  lDataSet.First
  While (not lDataSet.eof)
    MsgBox "DocKey " & lDataSet.FindField("DocKey").AsString
	MsgBox "DtlKey " & lDataSet.FindField("Dtlkey").AsString
	MsgBox "DocNo " & lDataSet.FindField("DocNo").AsString
	MsgBox "Item Code " & lDataSet.FindField("ItemCode").AsString
	MsgBox "Org Qty " & lDataSet.FindField("SQty").AsString
	MsgBox "Outstanding Qty " & lDataSet.FindField("OutstandingQty").AsString
	
	MsgBox "cdsDocDetail Count " & lDataSet2.RecordCount
	lDataSet2.First
    While (not lDataSet2.eof)
      MsgBox "FromDocKey " & lDataSet2.FindField("FromDocKey").AsString
	  MsgBox "FromDtlKey " & lDataSet2.FindField("FromDtlkey").AsString
	  MsgBox "DocType " & lDataSet2.FindField("DocType").AsString
	  MsgBox "DocNo " & lDataSet2.FindField("DocNo").AsString
	  MsgBox "DocDate " & lDataSet2.FindField("DocDate").AsString
	  MsgBox "Transfer Qty " & lDataSet2.FindField("TransferQty").AsString
	  lDataSet2.Next
    Wend	
	lDataSet.Next
  Wend
End Function

Common.PaymentMethod.RO

Common.PaymentMethod.RO Script
'Copy below script & paste to notepad & name it as eg Common.PaymentMethod.RO.vbs
Call GetInfo
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
 
Function GetInfo
Dim ComServer, RptObject, lDataSet1, lDataSet2
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB" 
  END IF
 
  'Step 2: Find and Create the Report Objects
  Set RptObject = ComServer.RptObjects.Find("Common.PaymentMethod.RO") 
 
 
  'Step 3: Perform Report calculation 
  RptObject.CalculateReport()
  Set lDataSet1 = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsPaymentAccount") 'You can link with lDataSet1 using Code to get the description

  MsgBox "Count " & lDataSet1.RecordCount
 
  'Step 5 Retrieve the output 
  lDataSet1.First
  While (not lDataSet1.eof)
	MsgBox "Code : " & lDataSet1.FindField("Code").AsString 
	lDataSet1.Next
  Wend    
  
  MsgBox "Count " & lDataSet2.RecordCount
  
  lDataSet2.First
  While (not lDataSet2.eof)
	MsgBox "Code : " & lDataSet2.FindField("Code").AsString 
	MsgBox "Description : " & lDataSet2.FindField("Description").AsString
	lDataSet2.Next
  Wend    
End Function

Common.Agent.RO

Common.Agent.RO Script
'Copy below script & paste to notepad & name it as eg Common.Agent.RO.vbs
Call GetInfo
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
 
Function GetInfo
Dim ComServer, RptObject, lDataSet1
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\DB\SQLAcc.DCF", "ACC-0002.FDB" 
  END IF
 
  'Step 2: Find and Create the Report Objects
  Set RptObject = ComServer.RptObjects.Find("Common.Agent.RO") 
 
 
  'Step 3: Perform Report calculation 
  RptObject.CalculateReport()
  Set lDataSet1 = RptObject.DataSets.Find("cdsMain")
  
  MsgBox "Count " & lDataSet1.RecordCount
 
  'Step 5 Retrieve the output 
  lDataSet1.First
  While (not lDataSet1.eof)
	MsgBox "Code : " & lDataSet1.FindField("Code").AsString 
	MsgBox "Description : " & lDataSet1.FindField("Description").AsString 
	lDataSet1.Next
  Wend      
End Function

Stock.Item.RO

Stock.Item.RO Script
'Copy below script & paste to notepad & name it as eg Stock.Item.RO.vbs
Call GetInfo
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
 
Function GetInfo
Dim ComServer, RptObject, lDataSet1, lDataSet2, lDateFrom, lDateTo
  'Step 1 Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C\DB\SQLAcc.DCF", "ACC-0002.FDB" 
  END IF
 
  'Step 2 Find and Create the Report Objects
  Set RptObject = ComServer.RptObjects.Find("Stock.Item.RO") 
 
  'Step 3 Spool parameters
    RptObject.Params.Find("AllItem").AsBoolean              = true
    RptObject.Params.Find("AllStockGroup").AsBoolean        = true
    RptObject.Params.Find("AllCustomerPriceTag").AsBoolean  = true
    RptObject.Params.Find("AllSupplierPriceTag").AsBoolean  = true
    'RptObject.Params.Find("CategoryData").AsBlob            =  'Not use
    'RptObject.Params.Find("CategoryTpl").AsBlob             =  'Not use
    'RptObject.Params.Find("CustomerPriceTagData").AsBlob    =  'Not use if AllCustomerPriceTag is True
    'RptObject.Params.Find("SupplierPriceTagData").AsBlob    =  'Not use if AllSupplierPriceTag is True
	
    lDateFrom = CDate("January 01, 2017")
    lDateTo = CDate("December 31, 2017")
  
    'RptObject.Params.Find("DateFrom").AsDate                = lDateFrom 'Not use if SelectDate is False
    'RptObject.Params.Find("DateTo").AsDate                  = lDateTo
    RptObject.Params.Find("HasAltStockItem").AsBoolean      = false
    RptObject.Params.Find("HasBarcode").AsBoolean           = false
    RptObject.Params.Find("HasBOM").AsBoolean               = false
    RptObject.Params.Find("HasCategory").AsBoolean          = false
    RptObject.Params.Find("HasCustomerItem").AsBoolean      = false
    RptObject.Params.Find("HasOpeningBalance").AsBoolean    = false
    RptObject.Params.Find("HasPurchasePrice").AsBoolean     = false
    RptObject.Params.Find("HasSellingPrice").AsBoolean      = false
    RptObject.Params.Find("HasSupplierItem").AsBoolean      = false
    'RptObject.Params.Find("ItemData").AsBlob                = 'Not use if AllItem is True
    'RptObject.Params.Find("ItemCategoryData").AsBlob        = 'Not use if SelectCategory is False
    RptObject.Params.Find("PrintActive").AsBoolean          = true
    RptObject.Params.Find("PrintInActive").AsBoolean        = true
    RptObject.Params.Find("PrintNonStockControl").AsBoolean = true
    RptObject.Params.Find("PrintStockControl").AsBoolean    = true
    RptObject.Params.Find("SelectCategory").AsBoolean       = false
    RptObject.Params.Find("SelectDate").AsBoolean           = false
    RptObject.Params.Find("SortBy").AsString                  = "Code"
    'RptObject.Params.Find("StockGroupData").AsBlob        =  'Not use if AllStockGroup is True  
    
  'Step 4 Perform Report calculation 
  RptObject.CalculateReport()
  Set lDataSet1 = RptObject.DataSets.Find("cdsMain")
  Set lDataSet2 = RptObject.DataSets.Find("cdsUOM") ' To link Master Data use Code
  MsgBox "Count " & lDataSet1.RecordCount
 
  'Step 5 Retrieve the output 
  lDataSet1.First
  While (not lDataSet1.eof)
    MsgBox "Code " & lDataSet1.FindField("Code").AsString 
    MsgBox "Description " & lDataSet1.FindField("Description").AsString 
    MsgBox "Balance Qty " & lDataSet1.FindField("BalSQty").AsString 
    lDataSet1.Next
  Wend

  MsgBox "Count " & lDataSet2.RecordCount
  lDataSet2.First
  While (not lDataSet2.eof)
    MsgBox "Code " & lDataSet2.FindField("Code").AsString 
	MsgBox "UOM " & lDataSet2.FindField("UOM").AsString 
	MsgBox "Rate " & lDataSet2.FindField("Rate").AsString 
	MsgBox "RefPrice " & lDataSet2.FindField("RefPrice").AsString
    lDataSet2.Next
  Wend	
End Function

Stock Item Balance

Get Stock Item Balance Script
'Available in Version 5.2018.833.759 & above
'Copy below script & paste to notepad & name it as eg ItemBalance.vbs
Call CheckLogin
Call GetData

Dim ComServer

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

function CheckLogin
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
	                'UserName, Password, DCF full path, Database filename
  END IF
End Function

Function GetData
Dim lDataSet, lSQL
  lSQL = "SELECT A.Location, A.Batch, A.ItemCode, B.Description, Sum(A.Qty) Qty FROM ST_TR A "
  lSQL = lSQL & "INNER JOIN ST_ITEM B ON (A.ITEMCODE=B.CODE) " 
  lSQL = lSQL & "WHERE B.IsActive='T' "
  lSQL = lSQL & "AND A.PostDate <= '31 Dec 2017' "
  lSQL = lSQL & "AND A.ItemCode= 'ANT' "
  lSQL = lSQL & "GROUP by A.Location, A.Batch, A.ItemCode, B.Description"
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
  
  lDataSet.First
  While (not lDataSet.eof)
    MsgBox "Location : " & lDataSet.FindField("Location").AsString
    MsgBox "Batch : " & lDataSet.FindField("Batch").AsString
    MsgBox "Item Code : " & lDataSet.FindField("ItemCode").AsString
	MsgBox "Item Description : " & lDataSet.FindField("Description").AsString
	MsgBox "Balance Qty : " & lDataSet.FindField("Qty").AsString
	lDataSet.Next
  Wend
End Function

ST_IS

ST_IS Script
'Copy below script & paste to notepad & name it as eg StockIssue.vbs
Call CheckLogin
Call InsertData

Dim ComServer

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

function CheckLogin
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
	                'UserName, Password, DCF full path, Database filename
  END IF
End Function

Function InsertData
Dim BizObject, lMain, lDetail, lDate
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("ST_IS") 

  'Step 3: Set Dataset
  Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data  
  
  'Step 4 : Insert Data - Master
  lDate = CDate("January 1, 2017")
  BizObject.New
  lMain.FindField("DocKey").value         = -1
  lMain.FindField("DocNo").AsString       = "--IS Test--"
  lMain.FindField("DocDate").value        = lDate
  lMain.FindField("PostDate").value       = lDate
  lMain.FindField("Description").AsString = "Stock Issue"
    
  'Step 5: Insert Data - Detail
  lDetail.Append
  lDetail.FindField("DtlKey").value         = -1
  lDetail.FindField("DocKey").value         = -1
  lDetail.FindField("ItemCode").AsString    = "ANT"
  lDetail.FindField("Description").AsString = "Issue out Item A"
  lDetail.FindField("Qty").AsFloat          = 2
  lDetail.Post

  lDetail.Append
  lDetail.FindField("DtlKey").value         = -1
  lDetail.FindField("DocKey").value         = -1
  lDetail.FindField("ItemCode").AsString    = "E-BAT"
  lDetail.FindField("Description").AsString = "Issue out Item A"
  lDetail.FindField("Qty").AsFloat          = 4
  lDetail.Post  
  'Step 6: Save Document
  BizObject.Save
  BizObject.Close
    
  ComServer.Logout 'Logout after done
  MsgBox "Done"  
End Function

ST_RC

ST_RC Script
'Copy below script & paste to notepad & name it as eg StockReceived.vbs
Call CheckLogin
Call InsertData

Dim ComServer

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

function CheckLogin
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
	                'UserName, Password, DCF full path, Database filename
  END IF
End Function

Function InsertData
Dim BizObject, lMain, lDetail, lDate
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("ST_RC") 

  'Step 3: Set Dataset
  Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data  
  
  'Step 4 : Insert Data - Master
  lDate = CDate("January 1, 2017")
  BizObject.New
  lMain.FindField("DocKey").value         = -1
  lMain.FindField("DocNo").AsString       = "--RC Test--"
  lMain.FindField("DocDate").value        = lDate
  lMain.FindField("PostDate").value       = lDate
  lMain.FindField("Description").AsString = "Stock Received"
    
  'Step 5: Insert Data - Detail
  lDetail.Append
  lDetail.FindField("DtlKey").value         = -1
  lDetail.FindField("DocKey").value         = -1
  lDetail.FindField("ItemCode").AsString    = "ANT"
  lDetail.FindField("Description").AsString = "Received Item A"
  lDetail.FindField("Qty").AsFloat          = 2
  lDetail.FindField("UnitCost").AsFloat     = 25.15
  lDetail.Post

  lDetail.Append
  lDetail.FindField("DtlKey").value         = -1
  lDetail.FindField("DocKey").value         = -1
  lDetail.FindField("ItemCode").AsString    = "E-BAT"
  lDetail.FindField("Description").AsString = "Received Item A"
  lDetail.FindField("Qty").AsFloat          = 4
  lDetail.FindField("UnitCost").AsFloat     = 54
  lDetail.Post  
  'Step 6: Save Document
  BizObject.Save
  BizObject.Close
    
  ComServer.Logout 'Logout after done
  MsgBox "Done"  
End Function

ST_AJ

ST_AJ Script
'Copy below script & paste to notepad & name it as eg StockAdjustment.vbs
Call CheckLogin
Call InsertData

Dim ComServer

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

function CheckLogin
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
	                'UserName, Password, DCF full path, Database filename
  END IF
End Function

Function InsertData
Dim BizObject, lMain, lDetail, lDate
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("ST_AJ") 

  'Step 3: Set Dataset
  Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data  
  
  'Step 4 : Insert Data - Master
  lDate = CDate("January 1, 2017")
  BizObject.New
  lMain.FindField("DocKey").value         = -1
  lMain.FindField("DocNo").AsString       = "--AJ Test--"
  lMain.FindField("DocDate").value        = lDate
  lMain.FindField("PostDate").value       = lDate
  lMain.FindField("Description").AsString = "Stock Adjustment"
    
  'Step 5: Insert Data - Detail
  lDetail.Append
  lDetail.FindField("DtlKey").value         = -1
  lDetail.FindField("DocKey").value         = -1
  lDetail.FindField("ItemCode").AsString    = "ANT"
  lDetail.FindField("Description").AsString = "Adjust IN Item A"
  lDetail.FindField("Qty").AsFloat          = 2
  lDetail.FindField("UnitCost").AsFloat     = 25.15 'Only IN need UnitCost
  lDetail.Post

  lDetail.Append
  lDetail.FindField("DtlKey").value         = -1
  lDetail.FindField("DocKey").value         = -1
  lDetail.FindField("ItemCode").AsString    = "E-BAT"
  lDetail.FindField("Description").AsString = "Adjust OUT Item A"
  lDetail.FindField("Qty").AsFloat          = -4
  lDetail.Post  
  'Step 6: Save Document
  BizObject.Save
  BizObject.Close
    
  ComServer.Logout 'Logout after done
  MsgBox "Done"  
End Function

ST_XF

ST_XF Script
'Copy below script & paste to notepad & name it as eg ST_XF.vbs
Call CheckLogin
Call InsertData

Dim ComServer

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

function CheckLogin
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
	                'UserName, Password, DCF full path, Database filename
  END IF
End Function

Function InsertData
Dim BizObject, lMain, lDetail, lDate
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("ST_XF") 

  'Step 3: Set Dataset
  Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data  
  
  'Begin Looping yr data
  'Step 4 : Insert Data - Master
  lDate = CDate("January 1, 2017")
  BizObject.New
  lMain.FindField("DocKey").value         = -1
  lMain.FindField("DocNo").AsString       = "--XF Test--"
  lMain.FindField("DocDate").value        = lDate
  lMain.FindField("PostDate").value       = lDate
  lMain.FindField("Code").AsString        = "300-C0001" 'Customer Account - Optional
  lMain.FindField("CompanyName").AsString = "Cash Sales" 'Optional
  lMain.FindField("Description").AsString = "Stock Transfer"
    
  'Step 5: Insert Data - Detail
  lDetail.Append
  lDetail.FindField("DtlKey").value          = -1
  lDetail.FindField("DocKey").value          = -1
  lDetail.FindField("ItemCode").AsString     = "ANT"
  lDetail.FindField("Description").AsString  = "Transfer Item A"
  lDetail.FindField("Qty").AsFloat           = 10
  lDetail.FindField("UOM").AsString          = "UNIT"
  lDetail.FindField("FromLocation").AsString = "----"
  lDetail.FindField("ToLocation").AsString   = "BALAKONG"
  lDetail.Post

  lDetail.Append
  lDetail.FindField("DtlKey").value          = -1
  lDetail.FindField("DocKey").value          = -1
  lDetail.FindField("ItemCode").AsString     = "HFK"
  lDetail.FindField("Description").AsString  = "Transfer Item B"
  lDetail.FindField("Qty").AsFloat           = 5
  lDetail.FindField("UOM").AsString          = "UNIT"
  lDetail.FindField("FromLocation").AsString = "----"
  lDetail.FindField("ToLocation").AsString   = "BALAKONG"
  lDetail.Post

  'Step 6: Save Document
  BizObject.Save
  BizObject.Close
  
  'Step 7 : Logout after done  
  'ComServer.Logout
  
  MsgBox "Done"  
End Function

AP_PI-Edit

AP_PI Edit Script
'Available in Version 5.2018.833.759 & above
'Copy below script & paste to notepad & name it as eg AP_PI.vbs
Call CheckLogin
Call GetData
Call PostData

Dim ComServer, lDataSet

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

function CheckLogin
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
	                'UserName, Password, DCF full path, Database filename
  END IF
End Function

Function GetData
Dim lSQL
  lSQL = "SELECT Dockey FROM AP_PI "
  lSQL = lSQL & "WHERE DocNo='PI-00001' "
  lSQL = lSQL & "AND Code='400-D0001' "
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
End Function

Function PostData
Dim BizObject, lMain, lDetail
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("AP_PI") 

  'Step 3: Set Dataset
  Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data  
  
  'Step 4 : Find Doc Number
  If lDataSet.RecordCount > 0 Then   
	lDataSet.First
    BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString
  
  
    BizObject.Open
    BizObject.Edit
    lMain.Edit
	lMain.FindField("Description").AsString = "testing" 
  
  'Step 5: Delete all Detail
    While lDetail.RecordCount <> 0
      lDetail.First
	  lDetail.Delete
    Wend
  'Step 6: Append Detail
    lDetail.Append
    lDetail.FindField("DtlKey").value = -1
    lDetail.FindField("Account").value = "610-2000"
    lDetail.FindField("Description").value =  "Purchase Item A"
    lDetail.FindField("Tax").value =  ""
    lDetail.FindField("TaxInclusive").value =  0
    lDetail.FindField("Amount").value = 410.37
    lDetail.FindField("TaxAmt").value = 0
    lDetail.Post
  
  'Step 7: Save Document
    BizObject.Save
    BizObject.Close
  
  'Step 8 : Logout after done  
    'ComServer.Logout  
    MsgBox "Done" 
	Else
	MsgBox "Record Not Found" 
  END IF 
   
End Function

SL_DO to SL_IV

SL_DO to SL_IV Script
'Updated 26 Oct 2018
'Copy below script & paste to notepad & name it as eg SL_IV.vbs
Call CheckLogin
Call InsertData1
Call InsertData2

Dim ComServer

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

function CheckLogin
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
	                'UserName, Password, DCF full path, Database filename
  END IF
End Function

Function InsertData1
Dim BizObject, lMain, lDetail, lDate
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("SL_DO") 

  'Step 3: Set Dataset
  Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data  
  
  'Begin Looping yr data
  'Step 4 : Insert Data - Master
  lDate = CDate("January 1, 2017")
  BizObject.New
  lMain.FindField("DocKey").value         = -1
  lMain.FindField("DocNo").AsString       = "--DO Test--"
  lMain.FindField("DocDate").value        = lDate
  lMain.FindField("PostDate").value       = lDate
  lMain.FindField("Code").AsString        = "300-C0001" 'Customer Account
  lMain.FindField("CompanyName").AsString = "Cash Sales"
  'lMain.FindField("Address1").AsString    = "" 'Optional
  'lMain.FindField("Address2").AsString    = "" 'Optional
  'lMain.FindField("Address3").AsString    = "" 'Optional
  'lMain.FindField("Address4").AsString    = "" 'Optional
  'lMain.FindField("Phone1").AsString      = "" 'Optional
  lMain.FindField("Description").AsString = "Delivery Order"
    
  'Step 5: Insert Data - Detail
  lDetail.Append
  lDetail.FindField("DtlKey").value         = -1
  lDetail.FindField("DocKey").value         = -1
  lDetail.FindField("Seq").value            = 1
  lDetail.FindField("ItemCode").AsString    = "ANT"
  lDetail.FindField("Description").AsString = "Sales Item A"
  lDetail.FindField("UOM").AsString         = "BOX"
  lDetail.FindField("Qty").AsFloat          = 2
  'lDetail.FindField("DISC").AsString        = "5%+3" 'Optional (eg 5% plus 3 Discount)
  lDetail.FindField("Tax").AsString         = "SR"
  lDetail.FindField("TaxRate").AsString     = "6%"
  lDetail.FindField("TaxInclusive").value   = 0
  lDetail.FindField("UnitPrice").AsFloat    = 100  
  lDetail.FindField("Amount").AsFloat       = 200
  lDetail.FindField("TaxAmt").AsFloat       = 12
  lDetail.Post

  lDetail.Append
  lDetail.FindField("DtlKey").value         = -1
  lDetail.FindField("DocKey").value         = -1
  lDetail.FindField("Seq").value            = 2
  lDetail.FindField("ItemCode").AsString    = "COVER"
  lDetail.FindField("Description").AsString = "Sales Item B"
  lDetail.FindField("UOM").AsString         = "UNIT"
  lDetail.FindField("Qty").AsFloat          = 3
  lDetail.FindField("Tax").AsString         = "SR"
  lDetail.FindField("TaxRate").AsString     = "6%"
  lDetail.FindField("TaxInclusive").value   = 0
  lDetail.FindField("UnitPrice").AsFloat    = 10  
  lDetail.FindField("Amount").AsFloat       = 30
  lDetail.FindField("TaxAmt").AsFloat       = 1.80
  lDetail.Post  
  'Step 6: Save Document
  BizObject.Save
  BizObject.Close
  MsgBox "DO Posting Done"  
End Function

Function InsertData2
Dim BizObject, lMain, lDetail, lDate, lDODtl, lxFer, lSQL, v(2)
  'Step 1: Check Is transtered or not
  lSQL = "SELECT DocKey FROM SL_IVDTL "
  lSQL = lSQL & "WHERE FromDockey=(SELECT DocKey FROM SL_DO " 
  lSQL = lSQL & "WHERE DocNo='--DO Test--') "
  Set lxFer = ComServer.DBManager.NewDataSet(lSQL)

  if lxFer.RecordCount = 0 then
    'Step 2: Get DO Information
    lSQL = "SELECT * FROM SL_DODTL "
    lSQL = lSQL & "WHERE Dockey=(SELECT DocKey FROM SL_DO " 
    lSQL = lSQL & "WHERE DocNo='--DO Test--') "
    Set lDODtl = ComServer.DBManager.NewDataSet(lSQL)    
	
	'Step 3: Find and Create the Biz Objects
    Set BizObject = ComServer.BizObjects.Find("SL_IV") 

    'Step 4: Set Dataset
    Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
    Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data  
  
    'Step 5 : Insert Data - Master
    lDate = CDate("January 1, 2017")
    BizObject.New
    lMain.FindField("DocKey").value         = -1
    lMain.FindField("DocNo").AsString       = "--IV Test--"
    lMain.FindField("DocDate").value        = lDate
    lMain.FindField("PostDate").value       = lDate
    lMain.FindField("Code").AsString        = "300-C0001" 'Customer Account
    lMain.FindField("CompanyName").AsString = "Cash Sales"
    'lMain.FindField("Address1").AsString    = "" 'Optional
    'lMain.FindField("Address2").AsString    = "" 'Optional
    'lMain.FindField("Address3").AsString    = "" 'Optional
    'lMain.FindField("Address4").AsString    = "" 'Optional
    'lMain.FindField("Phone1").AsString      = "" 'Optional
    lMain.FindField("Description").AsString = "Sales"
    
    'Step 6: Insert Data - Detail	
    v(0) = "COVER"
    v(1) = "UNIT"
	
    if (lDODtl.Locate("ItemCode;UOM", v, false, false)) then
      lDetail.Append
      lDetail.FindField("DtlKey").value         = -1
      lDetail.FindField("DocKey").value         = -1
      lDetail.FindField("Seq").value            = 1
      lDetail.FindField("ItemCode").AsString    = lDODtl.FindField("ItemCode").AsString
      lDetail.FindField("Description").AsString = lDODtl.FindField("Description").AsString
      'lDetail.FindField("Account").AsString     = "500-000" 'If you wanted override the Sales Account Code
      lDetail.FindField("UOM").AsString         = lDODtl.FindField("UOM").AsString
	  lDetail.FindField("Qty").AsFloat          = lDODtl.FindField("Qty").AsFloat
      lDetail.FindField("DISC").AsString        = lDODtl.FindField("Disc").AsString
      lDetail.FindField("Tax").AsString         = lDODtl.FindField("Tax").AsString
      lDetail.FindField("TaxRate").AsString     = lDODtl.FindField("TaxRate").AsString
      lDetail.FindField("TaxInclusive").value   = lDODtl.FindField("TaxInclusive").Value
      lDetail.FindField("UnitPrice").AsFloat    = lDODtl.FindField("UnitPrice").AsFloat
      lDetail.FindField("Amount").AsFloat       = lDODtl.FindField("Amount").AsFloat
      lDetail.FindField("TaxAmt").AsFloat       = lDODtl.FindField("TaxAmt").AsFloat
	  lDetail.FindField("FromDocType").AsString = "DO"
	  lDetail.FindField("FromDockey").AsFloat   = lDODtl.FindField("DocKey").AsFloat
	  lDetail.FindField("FromDtlkey").AsFloat   = lDODtl.FindField("DtlKey").AsFloat
      lDetail.Post
	End IF  
    v(0) = "ANT"
    v(1) = "BOX"
	
    if (lDODtl.Locate("ItemCode;UOM", v, false, false)) then
      lDetail.Append
      lDetail.FindField("DtlKey").value         = -1
      lDetail.FindField("DocKey").value         = -1
      lDetail.FindField("Seq").value            = 2
      lDetail.FindField("ItemCode").AsString    = lDODtl.FindField("ItemCode").AsString
      lDetail.FindField("Description").AsString = lDODtl.FindField("Description").AsString
      'lDetail.FindField("Account").AsString     = "500-000" 'If you wanted override the Sales Account Code
      lDetail.FindField("UOM").AsString         = lDODtl.FindField("UOM").AsString
	  lDetail.FindField("Qty").AsFloat          = lDODtl.FindField("Qty").AsFloat
      lDetail.FindField("DISC").AsString        = lDODtl.FindField("Disc").AsString
      lDetail.FindField("Tax").AsString         = lDODtl.FindField("Tax").AsString
      lDetail.FindField("TaxRate").AsString     = lDODtl.FindField("TaxRate").AsString
      lDetail.FindField("TaxInclusive").value   = lDODtl.FindField("TaxInclusive").Value
      lDetail.FindField("UnitPrice").AsFloat    = lDODtl.FindField("UnitPrice").AsFloat
      lDetail.FindField("Amount").AsFloat       = lDODtl.FindField("Amount").AsFloat
      lDetail.FindField("TaxAmt").AsFloat       = lDODtl.FindField("TaxAmt").AsFloat
	  lDetail.FindField("FromDocType").AsString = "DO"
	  lDetail.FindField("FromDockey").AsFloat   = lDODtl.FindField("DocKey").AsFloat
	  lDetail.FindField("FromDtlkey").AsFloat   = lDODtl.FindField("DtlKey").AsFloat
      lDetail.Post
	End IF  
  'Step 7: Save Document
    BizObject.Save
    BizObject.Close
  
  'Step 8 : Logout after done  
  'ComServer.Logout
  
  MsgBox "Posting IV Done"
  else MsgBox "--DO Test-- had been transfered. Posting IV aborted"  
  End IF
End Function

SL_IV-Edit

SL_IV-Edit Script
'Available in Version 5.2018.833.759 & above
'Copy below script & paste to notepad & name it as eg SL_IV.vbs
Call CheckLogin
Call GetData
Call PostData

Dim ComServer, lDataSet

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

function CheckLogin
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
	                'UserName, Password, DCF full path, Database filename
  END IF
End Function

Function GetData
Dim lSQL
  lSQL = "SELECT Dockey FROM SL_IV "
  lSQL = lSQL & "WHERE DocNo='IV-00010' "
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
End Function

Function PostData
Dim BizObject, lMain, lDetail
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("SL_IV") 

  'Step 3: Set Dataset
  Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data  
  
  'Step 4 : Find Doc Number
  If lDataSet.RecordCount > 0 Then   
	lDataSet.First
    BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString
  
  
    BizObject.Open
    BizObject.Edit
    lMain.Edit
	lMain.FindField("Description").AsString = "Sales - Edited" 
  
  'Step 5: Delete all Detail
    While lDetail.RecordCount <> 0
      lDetail.First
	  lDetail.Delete
    Wend
  'Step 6: Append Detail
    lDetail.Append
    lDetail.FindField("DtlKey").value = -1
    lDetail.FindField("Account").value = "500-000"
    lDetail.FindField("Description").value =  "Edited Item A"
    lDetail.FindField("Tax").value =  ""
    lDetail.FindField("TaxInclusive").value =  0
    lDetail.FindField("Amount").value = 410.37
    lDetail.FindField("TaxAmt").value = 0
    lDetail.Post
  
  'Step 7: Save Document
    BizObject.Save
    BizObject.Close
  
  'Step 8 : Logout after done  
    'ComServer.Logout  
    MsgBox "Done" 
	Else
	MsgBox "Record Not Found" 
  END IF 
End Function

GL_JE

GL_JE Script
'Copy below script & paste to notepad & name it as eg GL_JE.vbs
Call InsertGLJE
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
 
Function InsertGLJE
Dim ComServer, BizObject, lDataSet, lDataSet2, lDate
 
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB" 
  END IF
 
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("GL_JE") 
 
  'Step 3: Set Dataset
  Set lMainDataSet = BizObject.DataSets.Find("MainDataSet")    'lMainDataSet contains master data
  Set lDetailDataSet = BizObject.DataSets.Find("cdsDocDetail") 'lDetailDataSet contains detail data  
  
  'Step 4 : Insert Data - Master
  lDate = CDate("January 23, 2017")
  BizObject.New
  lMainDataSet.FindField("DocKey").value = -1
  lMainDataSet.FindField("DocNo").value = "--JV Test--"
  lMainDataSet.FindField("DocDate").value = lDate
  lMainDataSet.FindField("PostDate").value = lDate
  lMainDataSet.FindField("Description").value = "testing desc header"
  lMainDataSet.Post
  
  'Step 5: Insert Data - Detail
  'For Tax Inclusive
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
  lDetailDataSet.FindField("SEQ").value = 1
  lDetailDataSet.FindField("Code").value = "610-1000"
  lDetailDataSet.FindField("Project").value = "----"
  lDetailDataSet.FindField("Description").value =  "testing desc1"
  lDetailDataSet.FindField("Tax").value =  "TX"
  'lDetailDataSet.FindField("LOCALTAXAMT").value = 17.32 //For JE you can't override (i.e. system auto calc)
  lDetailDataSet.FindField("TaxInclusive").Value = 1
  lDetailDataSet.FindField("LocalDR").value = 306 '//Including GST if TAXINCLUSIVE = 1
  lDetailDataSet.FindField("DR").value = 306 '//If wanted DR <> LocalDR
  
  'For Tax Exclusive 
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
  lDetailDataSet.FindField("SEQ").value = 2
  lDetailDataSet.FindField("Code").value = "605-200"
  lDetailDataSet.FindField("Project").value = "----"
  lDetailDataSet.FindField("Description").value = "testing desc2"
  lDetailDataSet.FindField("Tax").value =  "TX"
  lDetailDataSet.FindField("TaxInclusive").value =  0
  lDetailDataSet.FindField("LocalCR").value = 100
  lDetailDataSet.Post 

  'For No GST
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
  lDetailDataSet.FindField("SEQ").value = 3
  lDetailDataSet.FindField("Code").value = "610-002"
  lDetailDataSet.FindField("Project").value = "----"
  lDetailDataSet.FindField("Description").value =  "testing desc3"
  lDetailDataSet.FindField("Tax").value =  ""
  lDetailDataSet.FindField("TaxInclusive").value =  0
  lDetailDataSet.FindField("LocalCR").value = 200
  lDetailDataSet.Post 
  'Step 6: Save Document
  BizObject.Save
  BizObject.Close
  MsgBox "Done"
End Function

GL_JE-Edit

GL_JE-Edit Script
'Available in Version 5.2018.833.759 & above
'Copy below script & paste to notepad & name it as eg GL_JE.vbs
Call CheckLogin
Call GetData
Call PostData

Dim ComServer, lDataSet

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

function CheckLogin
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
	                'UserName, Password, DCF full path, Database filename
  END IF
End Function

Function GetData
Dim lSQL
  lSQL = "SELECT Dockey FROM GL_JE "
  lSQL = lSQL & "WHERE DocNo='JV-00002' "
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
End Function

Function PostData
Dim BizObject, lMain, lDetail
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("GL_JE") 

  'Step 3: Set Dataset
  Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data  
  
  'Step 4 : Find Doc Number
  If lDataSet.RecordCount > 0 Then   
	lDataSet.First
    BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString
  
  
    BizObject.Open
    BizObject.Edit
    lMain.Edit
	lMain.FindField("Description").AsString = "Journal - Edited" 
  
  'Step 5: Delete all Detail
    While lDetail.RecordCount <> 0
      lDetail.First
	  lDetail.Delete
    Wend
  'Step 6: Append Detail
  lDetail.Append
  lDetail.FindField("DtlKey").value = -1
  lDetail.FindField("Code").value = "610-000"
  lDetail.FindField("Description").value =  "testing desc1"
  lDetail.FindField("Project").value = "P12W1"
  lDetail.FindField("Tax").value =  ""
  lDetail.FindField("TaxInclusive").value =  0
  lDetail.FindField("LocalDR").value = 200
  lDetail.FindField("DR").value = 200
  lDetail.Post 

  lDetail.Append
  lDetail.FindField("DtlKey").value = -1
  lDetail.FindField("Code").value = "531-000"
  lDetail.FindField("Description").value =  "testing desc2"
  lDetail.FindField("Project").value = "P13W1"
  lDetail.FindField("Tax").value =  ""
  lDetail.FindField("TaxInclusive").value =  0
  lDetail.FindField("LocalCR").value = 200
  lDetail.FindField("CR").value = 200
  lDetail.Post 
  
  'Step 7: Save Document
    BizObject.Save
    BizObject.Close
  
  'Step 8 : Logout after done  
    'ComServer.Logout  
    MsgBox "Done" 
	Else
	MsgBox "Record Not Found" 
  END IF 
End Function

GL_JE-Delete

GL_JE-Delete Script
'Available in Version 5.2018.833.759 & above
'Copy below script & paste to notepad & name it as eg GL_JE.vbs
Call CheckLogin
Call GetData
Call DelData

Dim ComServer, lDataSet

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

function CheckLogin
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
	                'UserName, Password, DCF full path, Database filename
  END IF
End Function

Function GetData
Dim lSQL
  lSQL = "SELECT Dockey FROM GL_JE "
  lSQL = lSQL & "WHERE DocNo='JV-00002' "
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
End Function

Function DelData
Dim BizObject
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("GL_JE") 
  'Step 3 : Find Doc Number
  If lDataSet.RecordCount > 0 Then 
	lDataSet.First
    BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString
    BizObject.Open
    BizObject.Delete
    BizObject.Close
  
  'Step 4 : Logout after done  
    'ComServer.Logout  
    MsgBox "Done" 
	Else
	MsgBox "Record Not Found" 
  END IF 	
End Function

Get Invoice Next Number

Get Invoice Next Number Script
'Available in Version 5.2018.833.759 & above
'Copy below script & paste to notepad & name it as eg GetNextNo.vbs
Call CheckLogin
Call GetData
Call ShowNextNo

Dim ComServer, lDataSet

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

function CheckLogin
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
	                'UserName, Password, DCF full path, Database filename
  END IF
End Function

Function GetData
Dim lSQL
  lSQL = "SELECT A.*, B.NEXTNUMBER FROM SY_DOCNO A "
  lSQL = lSQL & "INNER JOIN SY_DOCNO_DTL B ON (A.DOCKEY=B.PARENTKEY) "
  lSQL = lSQL & "WHERE A.DOCTYPE='IV' "
  lSQL = lSQL & "AND A.DESCRIPTION='Customer Invoice' "
  lSQL = lSQL & "AND A.STATESET=1 "
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
End Function

Function ShowNextNo 
Dim Desc, Fmt, NextNo, lResult, sb
  set sb = CreateObject("System.Text.StringBuilder")
  'Step 2 : Find Doc Number
  If lDataSet.RecordCount > 0 Then   
	lDataSet.First
    Desc = lDataSet.FindField("Description").AsString
	Fmt  = lDataSet.FindField("Format").AsString
	NextNo = lDataSet.FindField("NEXTNUMBER").Value
	
	'Convert from IV-%.5d to IV-{0:d5}
	sb.Append_3 Fmt
	sb.Replace "d", ""
	sb.Replace "%.","{0:d"
	Fmt = sb.ToString & "}"
	
	sb.Length = 0 'clear sb list
	sb.AppendFormat Fmt, NextNo
	
	lResult = sb.ToString
    MsgBox Desc
	MsgBox Fmt
	MsgBox NextNo
	MsgBox lResult
	Else
	MsgBox "Record Not Found" 
  END IF    
End Function

Auto Run Doc. Number

Sales Order Auto Run Doc Number Script
'Copy below script & paste to notepad & name it as eg SL_SO.vbs
'If had prompt Set Default - Just click Yes to avoid keep prompt
Call CheckLogin
Call GetData
Call InsertData

Dim ComServer, lDataSet

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

function CheckLogin
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
	                'UserName, Password, DCF full path, Database filename
  END IF
End Function

Function GetData
Dim lSQL
  lSQL = "SELECT * FROM SY_DOCNO "
  lSQL = lSQL & "WHERE DESCRIPTION='Customer Sales Order 2' "
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
End Function


Function InsertData
Dim BizObject, lMain, lDetail, lDate
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("SL_SO") 

  'Step 3: Set Dataset
  Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data  
  
  'Begin Looping yr data
  'Step 4 : Insert Data - Master
  lDate = CDate("January 1, 2019")
  BizObject.New
  lMain.FindField("DocKey").value         = -1
  lMain.FindField("DocNo").AsString       = "<<New>>"
  lMain.FindField("DocDate").value        = lDate
  lMain.FindField("PostDate").value       = lDate
  lMain.FindField("Code").AsString        = "300-C0001" 'Customer Account
  lMain.FindField("CompanyName").AsString = "Cash Sales"
  lMain.FindField("Address1").AsString    = "" 'Optional
  lMain.FindField("Address2").AsString    = "" 'Optional
  lMain.FindField("Address3").AsString    = "" 'Optional
  lMain.FindField("Address4").AsString    = "" 'Optional
  lMain.FindField("Phone1").AsString      = "" 'Optional
  lMain.FindField("Description").AsString = "Sales Order"
  lMain.FindField("DocNoSetKey").value    = lDataSet.FindField("DocKey").value
    
  'Step 5: Insert Data - Detail
  'For With Item Code
  lDetail.Append
  lDetail.FindField("DtlKey").value         = -1
  lDetail.FindField("DocKey").value         = -1
  lDetail.FindField("Seq").value            = 3
  lDetail.FindField("ItemCode").AsString    = "ANT"
  lDetail.FindField("Description").AsString = "Sales Item B"
  lDetail.FindField("Qty").AsFloat          = 2
  lDetail.FindField("UOM").AsString         = "UNIT"
  'lDetail.FindField("DISC").AsString        = "5%+3" 'Optional (eg 5% plus 3 Discount)
  lDetail.FindField("Tax").AsString         = ""
  lDetail.FindField("TaxRate").AsString     = ""
  lDetail.FindField("TaxInclusive").value   = 0
  lDetail.FindField("UnitPrice").AsFloat    = 100  
  lDetail.FindField("Amount").AsFloat       = 200
  lDetail.FindField("TaxAmt").AsFloat       = 0
  lDetail.Post

  'Step 6: Save Document
  BizObject.Save
  BizObject.Close
  
  'Step 7 : Logout after done  
  'ComServer.Logout
  
  MsgBox "Done"  
End Function

GL_PV

Cash Book PV Script
'Copy below script & paste to notepad & name it as eg AR_PM.vbs
Call PostData
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
 
Function PostData
Dim ComServer, BizObject, lIVNo, lDate
 
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB" 
  END IF
 
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("GL_PV") 
 
  'Step 3: Set Dataset
  Set lMain = BizObject.DataSets.Find("MainDataSet")    'lMainDataSet contains master data
  Set lDetailDataSet = BizObject.DataSets.Find("cdsDocDetail") 'lDetailDataSet contains detail data  
  
  'Step 4 : Posting
    lDate = CDate("January 23, 2020")
    BizObject.New
    lMain.FindField("DOCKEY").Value           = -1
    lMain.FindField("DocNo").AsString         = "--CB PV Test--" 
    lMain.FindField("DocDate").Value          = lDate
    lMain.FindField("PostDate").Value         = lDate
    lMain.FindField("Description").AsString   = "Compacc System"
    lMain.FindField("PaymentMethod").AsString = "310-001"
	lMain.FindField("CHEQUENUMBER").AsString = "MBB 213245"
    lMain.FindField("DocAmt").AsFloat         = 2019.57
    lMain.FindField("Cancelled").AsString     = "F"
	lMain.Post
  
    lDetailDataSet.Append
    lDetailDataSet.FindField("DTLKEY").value = -1
	lDetailDataSet.FindField("DOCKEY").value = -1
	lDetailDataSet.FindField("Code").AsString = "200-300"
    lDetailDataSet.FindField("DESCRIPTION").AsString = "Maybank - Asus A555LD-xx313H"
	lDetailDataSet.FindField("TAX").AsString = ""
	lDetailDataSet.FindField("TAXAMT").AsFloat = 0
	lDetailDataSet.FindField("TAXINCLUSIVE").AsFloat = 0
	lDetailDataSet.FindField("AMOUNT").AsFloat = 2019.57
    lDetailDataSet.Post

  'Step 5: Save Document
    BizObject.Save
    BizObject.Close
    MsgBox "Done"
End Function

ST_Item with Opening

ST_Item with Opening Script
'Copy below script & paste to notepad & name it as eg ST_XF.vbs
Call CheckLogin
Call InsertData

Dim ComServer

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

function CheckLogin
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
	                'UserName, Password, DCF full path, Database filename
  END IF
End Function

Function InsertData
Dim BizObject, lMain, lDtl, lOpn
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("ST_ITEM") 

  'Step 3: Set Dataset
  Set lMain = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDtl = BizObject.DataSets.Find("cdsUOM") 'lDetail contains detail data  
  Set lOpn = BizObject.DataSets.Find("cdsOpeningBalance") 'lDetail contains detail data  
  
  'Begin Looping yr data
  'Step 4 : Insert Data - Master
  BizObject.New
  lMain.FindField("CODE").value = "==Test New Item Code=="
  lMain.FindField("DESCRIPTION").value = "Item Description 123"
  lMain.FindField("STOCKGROUP").value = "DEFAULT"
  lMain.FindField("STOCKCONTROL").value = "T"
  lMain.FindField("ISACTIVE").value = "T"
			    
  'Step 5: Insert Data - Detail
  lDtl.Edit 'For 1St UOM
  lDtl.FindField("UOM").AsString = "PCS"
  lDtl.FindField("Rate").AsFloat = 1
  lDtl.FindField("RefCost").AsFloat = 10.2
  lDtl.FindField("RefPrice").AsFloat = 25
  lDtl.Post

  lDtl.Append 'For 2nd UOM
  lDtl.FindField("UOM").AsString = "CTN"
  lDtl.FindField("Rate").AsFloat = 12
  lDtl.FindField("RefCost").AsFloat = 102
  lDtl.FindField("RefPrice").AsFloat = 240
  lDtl.Post
  
  'Step 6: Insert Data - Opening
  lOpn.Append 
  lOpn.FindField("LOCATION").AsString = "----"
  lOpn.FindField("Qty").AsFloat = 10 'in smallest UOM'
  lOpn.FindField("COST").AsFloat = 10.2
  lOpn.Post

  'Step 7: Save Document
  BizObject.Save
  BizObject.Close
  
  'Step 8 : Logout after done  
  'ComServer.Logout
  
  MsgBox "Done"  
End Function

GL Stock Value-Insert,Edit & Delete

GL Stock Value Insert, Edit & Delete Script
'Available in Version 5.2018.833.759 & above
'Copy below script & paste to notepad & name it as eg GLStockValue.vbs
Call CheckLogin
Call GetData
'Call InsertValue
'Call UpdateValue
Call DeleteValue

Dim ComServer, lDataSet

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

function CheckLogin
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
	                'UserName, Password, DCF full path, Database filename
  END IF
End Function

Function GetData
Dim lSQL
  lSQL = "SELECT Dockey FROM GL_STOCK "
  lSQL = lSQL & "WHERE BalanceStock='330-000' "
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
End Function

Function InsertValue
Dim BizObject, lMain, lDetail
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("GL_STOCK") 

  'Step 3: Set Dataset
  Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data  
  
  'Step 4 : Find Dockey Record
  If lDataSet.RecordCount > 0 Then   
	lDataSet.First
    BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString  
	
    BizObject.Open
    BizObject.Edit
	
    lDetail.Append
    lDetail.FindField("Project").value = "----"
	lDetail.FindField("SYear").value = 2021
	lDetail.FindField("SMonth").value = 4
	lDetail.FindField("Amount").value = 423.00
    lDetail.Post
	
  'Step 6: Save Document
    BizObject.Save
    BizObject.Close
    MsgBox "Done"
  END IF	
End Function

Function UpdateValue
Dim BizObject, lMain, lDetail, v(2)
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("GL_STOCK") 

  'Step 3: Set Dataset
  Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data  
  
  'Step 4 : Find Dockey Record
  If lDataSet.RecordCount > 0 Then   
	lDataSet.First
    BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString  
	
    BizObject.Open
    BizObject.Edit

    v(0) = "----" 'Project Code
    v(1) = "2021" 'Year
	v(2) = "3" 'Month to update
	
	if (lDetail.Locate("Project;SYear;SMonth", v, false, false)) then
      lDetail.Edit
      lDetail.FindField("Amount").value = 333.12      
      lDetail.Post
	End IF 
  'Step 6: Save Document
    BizObject.Save
    BizObject.Close
    MsgBox "Done"
  END IF	
End Function

Function DeleteValue
Dim BizObject, lMain, lDetail, v(2)
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("GL_STOCK") 

  'Step 3: Set Dataset
  Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data  
  
  'Step 4 : Find Dockey Record
  If lDataSet.RecordCount > 0 Then   
	lDataSet.First
    BizObject.Params.Find("DocKey").Value = lDataSet.FindField("DocKey").AsString  
	
    BizObject.Open
    BizObject.Edit

    v(0) = "----" 'Project Code
    v(1) = "2021" 'Year
	v(2) = "4" 'Month to update
	
	if (lDetail.Locate("Project;SYear;SMonth", v, false, false)) then
      lDetail.Delete
	End IF 
  'Step 6: Save Document
    BizObject.Save
    BizObject.Close
    MsgBox "Done"
  END IF	
End Function

Stock Item Template to SL_IV

Stock Item Template to SL_IV Script
'Updated 03 Sep 2021
'Copy below script & paste to notepad & name it as eg SL_IV.vbs
Call CheckLogin
Call InsertData1
Call InsertData2

Dim ComServer

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

function CheckLogin
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB"
	                'UserName, Password, DCF full path, Database filename
  END IF
End Function

Function InsertData1
Dim BizObject, lMain, lDetail, lDate
  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("ST_ITEM_TPL") 

  'Step 3: Set Dataset
  Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
  Set lDetail = BizObject.DataSets.Find("cdsItemTplDtl") 'lDetail contains detail data  
  
  'Begin Looping yr data
  'Step 4 : Insert Data - Master
  BizObject.New
  lMain.FindField("Code").AsString        = "--TPL Test--"
  lMain.FindField("Description").AsString = "Template formt 1"
  lMain.FindField("RefPrice").AsFloat     = 299.15
    
  'Step 5: Insert Data - Detail
  lDetail.Append
  lDetail.FindField("DtlKey").value         = -1
  lDetail.FindField("Code").AsString        = "--TPL Test--"
  lDetail.FindField("Seq").value            = 1
  lDetail.FindField("ItemCode").AsString    = "ANT"
  lDetail.FindField("Description").AsString = "Sales Item A"
  lDetail.FindField("UOM").AsString         = "BOX"
  lDetail.FindField("Qty").AsFloat          = 2
  'lDetail.FindField("DISC").AsString        = "5%+3" 'Optional (eg 5% plus 3 Discount)
  lDetail.FindField("UNITAMOUNT").AsFloat    = 100  
  lDetail.FindField("Amount").AsFloat       = 200
  lDetail.FindField("PRINTABLE").AsString   = "T"
  lDetail.Post

  lDetail.Append
  lDetail.FindField("DtlKey").value         = -1
  lDetail.FindField("Code").AsString        = "--TPL Test--" 
  lDetail.FindField("Seq").value            = 2
  lDetail.FindField("ItemCode").AsString    = "COVER"
  lDetail.FindField("Description").AsString = "Sales Item B"
  lDetail.FindField("UOM").AsString         = "UNIT"
  lDetail.FindField("Qty").AsFloat          = 3
  'lDetail.FindField("DISC").AsString        = "5%+3" 'Optional (eg 5% plus 3 Discount)
  lDetail.FindField("UNITAMOUNT").AsFloat    = 10  
  lDetail.FindField("Amount").AsFloat       = 30
  lDetail.FindField("PRINTABLE").AsString   = "T"
  lDetail.Post  
  'Step 6: Save Document
  BizObject.Save
  BizObject.Close
  MsgBox "Template Posting Done"  
End Function

Function InsertData2
Dim BizObject, lMain, lDetail, lDate, lDODtl, lSQL, v(2)
  'Step 1: Get Template Information
  lSQL = "SELECT * FROM ST_ITEM_TPLDTL "
  lSQL = lSQL & "WHERE Code='--TPL Test--' "
  Set lDODtl = ComServer.DBManager.NewDataSet(lSQL)

  if lDODtl.RecordCount > 0 then	
	'Step 2: Find and Create the Biz Objects
    Set BizObject = ComServer.BizObjects.Find("SL_IV") 

    'Step 3: Set Dataset
    Set lMain   = BizObject.DataSets.Find("MainDataSet")  'lMain contains master data
    Set lDetail = BizObject.DataSets.Find("cdsDocDetail") 'lDetail contains detail data  
  
    'Step 4 : Insert Data - Master
    lDate = CDate("January 1, 2021")
    BizObject.New
    lMain.FindField("DocKey").value         = -1
    lMain.FindField("DocNo").AsString       = "--IV Test--"
    lMain.FindField("DocDate").value        = lDate
    lMain.FindField("PostDate").value       = lDate
    lMain.FindField("Code").AsString        = "300-C0001" 'Customer Account
    lMain.FindField("CompanyName").AsString = "Cash Sales"
    'lMain.FindField("Address1").AsString    = "" 'Optional
    'lMain.FindField("Address2").AsString    = "" 'Optional
    'lMain.FindField("Address3").AsString    = "" 'Optional
    'lMain.FindField("Address4").AsString    = "" 'Optional
    'lMain.FindField("Phone1").AsString      = "" 'Optional
    lMain.FindField("Description").AsString = "Sales"
    
    'Step 6: Insert Data - Detail	
	lDODtl.First
    While not lDODtl.Eof
      lDetail.Append
      lDetail.FindField("DtlKey").value         = -1
      lDetail.FindField("DocKey").value         = -1
      lDetail.FindField("Seq").value            = 1
      lDetail.FindField("ItemCode").AsString    = lDODtl.FindField("ItemCode").AsString
      lDetail.FindField("Description").AsString = lDODtl.FindField("Description").AsString
      lDetail.FindField("UOM").AsString         = lDODtl.FindField("UOM").AsString
      lDetail.FindField("Qty").AsFloat          = lDODtl.FindField("Qty").AsFloat
      lDetail.FindField("DISC").AsString        = lDODtl.FindField("Disc").AsString
      lDetail.FindField("UnitPrice").AsFloat    = lDODtl.FindField("UnitAmount").AsFloat
      lDetail.FindField("Amount").AsFloat       = lDODtl.FindField("Amount").AsFloat
      lDetail.FindField("PRINTABLE").AsString   = lDODtl.FindField("PRINTABLE").AsString
      lDetail.Post
	  lDODtl.Next
	Wend
  'Step 7: Save Document
    BizObject.Save
    BizObject.Close
  
  'Step 8 : Logout after done  
  'ComServer.Logout
  
  MsgBox "Posting IV Done"
  else MsgBox "--No Template found. Posting IV aborted"  
  End IF
End Function

AR_CN

AR_CN Script
'Updated 24 Feb 2023
'Copy below script & paste to notepad & name it as eg AR_CN.vbs
Call InsertData

Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function

Function InsertData
Dim ComServer, BizObject, lDate, lIVNO, v(1)

  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  If not ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0020.FDB" 
  END IF

  'Step 2: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("AR_CN") 

  'Step 3: Set Dataset
  Set lMainDataSet = BizObject.DataSets.Find("MainDataSet")    'lMainDataSet contains master data
  Set lDetailDataSet = BizObject.DataSets.Find("cdsDocDetail") 'lDetailDataSet contains detail data  
  Set lKO = BizObject.DataSets.Find("cdsKnockOff") 'Contains IV/DN to knock off data  
  
  'Step 4 : Insert Data - Master
  lDate = CDate("January 1, 2023")
  BizObject.New
  lMainDataSet.FindField("DocKey").value = -1
  lMainDataSet.FindField("DocNo").value = "--CN Test--"
  lMainDataSet.FindField("DocDate").value = lDate
  lMainDataSet.FindField("PostDate").value = lDate
  lMainDataSet.FindField("Code").value = "300-A0001"
  lMainDataSet.FindField("Description").value = "Credit Note"
    
  'Step 5: Insert Data - Detail
  'For Tax Inclusive = True with override Tax Amount
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
  lDetailDataSet.FindField("Account").value = "510-2000"
  lDetailDataSet.FindField("Description").value =  "Sales Item A"
  lDetailDataSet.FindField("Tax").value =  "SV"
  lDetailDataSet.FindField("TaxInclusive").value =  0
  lDetailDataSet.FindField("Amount").value = 410.37
  lDetailDataSet.FindField("TaxAmt").value = 24.63
  
  lDetailDataSet.DisableControls
  lDetailDataSet.FindField("TaxInclusive").value =  1
  lDetailDataSet.EnableControls
  
  lDetailDataSet.FindField("Changed").value = "F"
  lDetailDataSet.Post
  
  'For Tax Inclusive = False with override Tax Amount
  lDetailDataSet.Append
  lDetailDataSet.FindField("DtlKey").value = -1
  lDetailDataSet.FindField("DocKey").value = -1
  lDetailDataSet.FindField("Account").value = "510-2000"
  lDetailDataSet.FindField("Description").value =  "Sales Item B"
  lDetailDataSet.FindField("Tax").value =  "SV"
  lDetailDataSet.FindField("TaxInclusive").value =  0
  lDetailDataSet.FindField("Amount").value = 94.43
  lDetailDataSet.FindField("TaxAmt").value = 5.66
  lDetailDataSet.FindField("Changed").value = "F"
  lDetailDataSet.Post

  'Step 7: Knock Off IV
    lIVNO = "--IV Test--"
    v(0) = "IV"
    v(1) = lIVNO
	
    if (lKO.Locate("DocType;DocNo", v, false, false)) then
      lKO.Edit
      lKO.FindField("KOAmt").value = 65.57
      lKO.FindField("KnockOff").AsString = "T"
      lKO.Post
	End IF  

  'Step 7: Save Document
  BizObject.Save
  BizObject.Close
  MsgBox "Done"
End Function


JScript/JavaScript

This Script only can run using Internet Explorer (till IE 11)

AR_IV

AR_IV Script
<html>
<head>
<title>Add Customer Invoice</title>
<script language="JScript">
var ComServer;
 
function CreateSQLAccServer() {
  ComServer = new ActiveXObject('SQLAcc.BizApp');
  if (!ComServer.IsLogin) {            /* check whether user has logon */
    ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
 /* UserName, Password */
  }
}
 
function AutoInvoice() {
  var BizObject, lMainDataSet, lDetailDataSet;
 
  CreateSQLAccServer();
 
  BizObject = ComServer.BizObjects.Find('AR_IV');
  lMainDataSet = BizObject.DataSets.Find('MainDataSet');
  lDetailDataSet = BizObject.DataSets.Find('cdsDocDetail');
  BizObject.New();
 
  lMainDataSet.FindField('DocKey').value = -1;
  lMainDataSet.FindField('DocNo').value = "--IV Test--";
  lMainDataSet.FindField('DocDate').value = "01/10/2016";
  lMainDataSet.FindField('PostDate').value = "01/10/2016";
  lMainDataSet.FindField('Code').value = "300-A0003";
  lMainDataSet.FindField('Description').value = "Sales";

  /*For Tax Inclusive = True with override Tax Amount*/
  lDetailDataSet.Append();
  lDetailDataSet.FindField('DtlKey').value = -1;
  lDetailDataSet.FindField('DocKey').value = -1;
  lDetailDataSet.FindField('Account').value = "500-000";
  lDetailDataSet.FindField('Description').value =  "Sales Item A";
  lDetailDataSet.FindField('Tax').value =  "SR";
  lDetailDataSet.FindField('TaxInclusive').value =  0;
  lDetailDataSet.FindField('Amount').value = 410.37;
  lDetailDataSet.FindField('TaxAmt').value = 24.63;
 
  lDetailDataSet.DisableControls();
  lDetailDataSet.FindField('TaxInclusive').value =  1;
  lDetailDataSet.EnableControls();
 
  lDetailDataSet.FindField('Changed').value = "F";
  lDetailDataSet.Post();

  /*For Tax Inclusive = False with override Tax Amount*/
  lDetailDataSet.Append();
  lDetailDataSet.FindField('DtlKey').value = -1;
  lDetailDataSet.FindField('DocKey').value = -1;
  lDetailDataSet.FindField('Account').value = "500-000";
  lDetailDataSet.FindField('Description').value =  "Sales Item B";
  lDetailDataSet.FindField('Tax').value =  "SR";
  lDetailDataSet.FindField('TaxInclusive').value =  0;
  lDetailDataSet.FindField('Amount').value = 94.43;
  lDetailDataSet.FindField('TaxAmt').value = 5.66;
  lDetailDataSet.FindField('Changed').value = "F";
  lDetailDataSet.Post();

  /* Save document */  
    BizObject.Save();
    BizObject.Close();
    alert('Customer Invoice - has been saved.');
}
</script>
</head>
<body>
<input type="submit" value="SYNC" name="btnSubmit" onclick="AutoInvoice()">
</body>
</html>

SL_CS

SL_CS Script
<html>
<head>
<title>Add Cash Sales</title>
<script language="JScript">
var ComServer;

function CreateSQLAccServer() {
  ComServer = new ActiveXObject('SQLAcc.BizApp');
  if (!ComServer.IsLogin) {            /* check whether user has logon */
    ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
 /* UserName, Password */
  }
}

function InsertData() {
  var BizObject, lMain, lDetail;
  
  CreateSQLAccServer();

  /*Step 2: Find and Create the Biz Objects*/
  BizObject = ComServer.BizObjects.Find('SL_CS') ;

  /*Step 3: Set Dataset*/
  lMain   = BizObject.DataSets.Find('MainDataSet');  /*lMain contains master data*/
  lDetail = BizObject.DataSets.Find('cdsDocDetail'); /*lDetail contains detail data */  
  
  /*Begin Looping yr data*/
  /*Step 4 : Insert Data - Master*/
  BizObject.New();
  lMain.FindField('DocKey').value         = -1;
  lMain.FindField('DocNo').AsString       = "--IV Test--";
  lMain.FindField('DocDate').value        = "20/12/2017";
  lMain.FindField('PostDate').value       = "20/12/2017";
  lMain.FindField('Code').AsString        = "300-C0001"; /*Customer Account*/
  lMain.FindField('CompanyName').AsString = "Cash Sales"
  lMain.FindField('Address1').AsString    = ""; /*Optional*/
  lMain.FindField('Address2').AsString    = ""; /*Optional*/
  lMain.FindField('Address3').AsString    = ""; /*Optional*/
  lMain.FindField('Address4').AsString    = ""; /*Optional*/
  lMain.FindField('Phone1').AsString      = ""; /*Optional*/
  lMain.FindField('Description').AsString = "Sales";
    
  /*Step 5: Insert Data - Detail*/
  /*For Tax Inclusive = True with override Tax Amount*/
  lDetail.Append();
  lDetail.FindField('DtlKey').value         = -1;
  lDetail.FindField('DocKey').value         = -1;
  lDetail.FindField('Seq').value            = 1;
  lDetail.FindField('Account').AsString     = "500-000"; /*Sales Account*/
  lDetail.FindField('Description').AsString = "Sales Item A";
  lDetail.FindField('Qty').AsFloat          = 1;
  lDetail.FindField('Tax').AsString         = "SR";
  lDetail.FindField('TaxRate').AsString     = "6%";
  lDetail.FindField('TaxInclusive').value   = 0;
  lDetail.FindField('UnitPrice').AsFloat    = 435;
  lDetail.FindField('Amount').AsFloat       = 410.37; /*Exclding GST Amt*/
  lDetail.FindField('TaxAmt').AsFloat       = 24.63;
  
  lDetail.DisableControls();
  lDetail.FindField('TaxInclusive').value   = 1;
  lDetail.EnableControls();
  
  lDetail.Post();
  
  /*For Tax Inclusive = False with override Tax Amount*/
  lDetail.Append();
  lDetail.FindField('DtlKey').value         = -1;
  lDetail.FindField('DocKey').value         = -1;
  lDetail.FindField('Seq').value            = 2;
  lDetail.FindField('Account').AsString     = "500-000";
  lDetail.FindField('Description').AsString = "Sales Item B";
  lDetail.FindField('Qty').AsFloat          = 1;
  lDetail.FindField('Tax').AsString         = "SR";
  lDetail.FindField('TaxRate').AsString     = "6%";
  lDetail.FindField('TaxInclusive').value   = 0;
  lDetail.FindField('UnitPrice').AsFloat    = 94.43;
  lDetail.FindField('Amount').AsFloat       = 94.43;
  lDetail.FindField('TaxAmt').AsFloat       = 5.66;
  lDetail.Post();

  /*For With Item Code*/
  lDetail.Append();
  lDetail.FindField('DtlKey').value         = -1;
  lDetail.FindField('DocKey').value         = -1;
  lDetail.FindField('Seq').value            = 3;
  lDetail.FindField('ItemCode').AsString    = "ANT";
  lDetail.FindField('Description').AsString = "Sales Item B";
  /*lDetail.FindField('Account').AsString     = "500-000"; If you wanted override the Sales Account Code*/
  lDetail.FindField('Qty').AsFloat          = 2;
  lDetail.FindField('UOM').AsString         = "UNIT";
  /*lDetail.FindField('DISC').AsString        = "5%+3"; Optional (eg 5% plus 3 Discount)*/
  lDetail.FindField('Tax').AsString         = "SR";
  lDetail.FindField('TaxRate').AsString     = "6%";
  lDetail.FindField('TaxInclusive').value   = 0;
  lDetail.FindField('UnitPrice').AsFloat    = 100;
  lDetail.FindField('Amount').AsFloat       = 200;
  lDetail.FindField('TaxAmt').AsFloat       = 12;
  lDetail.Post();

  /*Step 6: Save Document*/
  BizObject.Save();
  BizObject.Close();
    alert('Document has been saved.');
}
</script>
</head>
<body>
<input type="submit" value="SYNC" name="btnSubmit" onclick="InsertData()">
</body>
</html>

AR_PM

AR_PM Script
<html>
<head>
<title>Customer Payment</title>
<script language="JScript">
<html>
<head>
<title>Add Customer Payment</title>
<script language="JScript">
var ComServer;

function CreateSQLAccServer() {
  ComServer = new ActiveXObject("SQLAcc.BizApp");
  if (!ComServer.IsLogin) {            /* check whether user has logon */
    ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
 /* UserName, Password */
  }
}

function AddPayment() {
  var BizObject, lMainDataSet, lKnockOffDataSet, V;
  
  CreateSQLAccServer();

  BizObject = ComServer.BizObjects.Find('AR_PM');
  lMainDataSet = BizObject.DataSets.Find('MainDataSet');
  lKnockOffDataSet = BizObject.DataSets.Find('cdsKnockOff');
  BizObject.New();
  
  lMainDataSet.FindField('DocKey').value = -1;
  lMainDataSet.FindField('DocNo').value = "--OR Test--";
  lMainDataSet.FindField('Code').value = "300-C0001";
  lMainDataSet.FindField('DocDate').value = "10/10/2023";
  lMainDataSet.FindField('PostDate').value = "10/10/2023";  
  lMainDataSet.FindField('Description').value = "Payment for Account";
  lMainDataSet.FindField('PaymentMethod').value = "310-001";
  lMainDataSet.FindField('ChequeNumber').value = "";
  lMainDataSet.FindField('DocAmt').AsFloat = 106.10;
  lMainDataSet.FindField('BankCharge').AsFloat = 0;
  lMainDataSet.FindField('UnappliedAmt').AsFloat = 0;
  lMainDataSet.FindField('Cancelled').value = 'F';
  
  v = ComServer.CreateOleVariantArray(2);
  v.SetItem(0, 'IV'); /*Knock Off DocType*/
  v.SetItem(1, 'IV-00172'); /*Knock Off DocNo*/

  if (lKnockOffDataSet.Locate('DocType;DocNo', v.AsOleVariant(), false, false)){ 
          lKnockOffDataSet.Edit();
          lKnockOffDataSet.FindField('KOAmt').AsFloat = 106.10;		  
          lKnockOffDataSet.FindField('KnockOff').AsString = 'T';
          lKnockOffDataSet.Post(); }
    /* Save document */  
    BizObject.Save();
    BizObject.Close();
    alert("Customer Payment - has been saved.");
}

function EditPayment(){
  var BizObject, lMainDataSet, lKnockOffDataSet, V, lDocNo, lDocKey;
  
  CreateSQLAccServer();

  BizObject = ComServer.BizObjects.Find('AR_PM');
  lMainDataSet = BizObject.DataSets.Find('MainDataSet');
  lKnockOffDataSet = BizObject.DataSets.Find('cdsKnockOff');
  
  lDocNo = "--OR Test--"
  lDocKey = BizObject.FindKeyByRef('DocNo', lDocNo);
  BizObject.Params.Find('DocKey').Value = lDocKey;
  
  if (lDocKey != null) {
    BizObject.Open();
    BizObject.Edit();
    lMainDataSet.FindField('Description').value = "Payment for Account-Edited";
    lMainDataSet.FindField('PaymentMethod').value = "310-001";
    lMainDataSet.FindField('ChequeNumber').value = "";
    lMainDataSet.FindField('DocAmt').AsFloat = 200.00;
    lMainDataSet.FindField('BankCharge').AsFloat = 0;
    lMainDataSet.FindField('UnappliedAmt').AsFloat = 0;
    lMainDataSet.FindField('Cancelled').value = 'F';
  
    v = ComServer.CreateOleVariantArray(2);
    v.SetItem(0, 'IV'); /*Knock Off DocType*/
    v.SetItem(1, 'IV-00172'); /*Knock Off DocNo*/

    if (lKnockOffDataSet.Locate('DocType;DocNo', v.AsOleVariant(), false, false)){ 
          lKnockOffDataSet.Edit();
          lKnockOffDataSet.FindField('KOAmt').AsFloat = 200;		  
          lKnockOffDataSet.FindField('KnockOff').AsString = 'T';
          lKnockOffDataSet.Post(); }
    /* Save document */  
      BizObject.Save();
      BizObject.Close();
      alert("Customer Payment - has been Edited & saved.");
   }
}

function DelPayment(){
  var BizObject, lMainDataSet, lKnockOffDataSet, V, lDocNo, lDocKey;
  
  CreateSQLAccServer();

  BizObject = ComServer.BizObjects.Find('AR_PM');
  lMainDataSet = BizObject.DataSets.Find('MainDataSet');
  lKnockOffDataSet = BizObject.DataSets.Find('cdsKnockOff');
  
  lDocNo = "--OR Test--"
  lDocKey = BizObject.FindKeyByRef('DocNo', lDocNo);
  BizObject.Params.Find('DocKey').Value = lDocKey;
  
  if (lDocKey != null) {
    BizObject.Open();
    BizObject.Delete();

    BizObject.Close();
    alert("Customer Payment - has been Deleted.");
   }
}
</script>
</head>
<body>
<input type="submit" value="Add Payment" name="btnSubmit" onclick="AddPayment()">
<input type="submit" value="Edit Payment" name="btnSubmit" onclick="EditPayment()">
<input type="submit" value="Delete Payment" name="btnSubmit" onclick="DelPayment()">
</body>
</html>

Customer.IV.RO

Customer.IV.RO Report Object Script
<html>
  <head>
    <title>Customer.IV.RO</title>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <script type="text/javascript">
var ComServer;

function CreateSQLAccServer() {
  ComServer = new ActiveXObject("SQLAcc.BizApp");
  if (!ComServer.IsLogin) {            /* check whether user has logon */
    ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
 /* UserName, Password */
  }
}      

function GetData() {  
  var lMain, lDetail, lRptVar, lDateFrom, lDateTo;
  
  elem = document.getElementById('txt1');
  
  CreateSQLAccServer();
   
  lDateFrom = new Date("January 1 2015");
  lDateTo = new Date("December 31, 2015"); 
  
  lRptVar = ComServer.RptObjects.Find('Customer.IV.RO');
  lRptVar.Params.Find('SelectDate').Value           = true;
  lRptVar.Params.Find('DateFrom').Value             = lDateFrom.valueOf();
  lRptVar.Params.Find('DateTo').Value               = lDateTo.valueOf();
  lRptVar.Params.Find('AllAgent').Value             = false;
  lRptVar.Params.Find('AgentData').Value            = "----\nLF"; /*Filter by Agent code ---- & HALIM */
  lRptVar.Params.Find('AllArea').Value              = true;
  lRptVar.Params.Find('AllCompany').Value           = true;
  lRptVar.Params.Find('AllCurrency').Value          = true;
  lRptVar.Params.Find('AllDocProject').Value        = true;
  lRptVar.Params.Find('AllCompanyCategory').Value   = true;
  lRptVar.Params.Find('AllDocument').Value          = true;
  lRptVar.Params.Find('IncludeCancelled').Value   = false;
  lRptVar.Params.Find('PrintDocumentStyle').Value = false;
  lRptVar.Params.Find('AllItemProject').Value     = true;
  lRptVar.Params.Find('AllPaymentMethod').Value   = true;
  lRptVar.CalculateReport();  
  
  lMain   = lRptVar.DataSets.Find('cdsMain');
  lDetail = lRptVar.DataSets.Find('cdsDocDetail');
  /*alert("Count -" + lRptVar.DataSets.Find('cdsDocDetail').RecordCount);*/
  elem.innerHTML += 'From Main'+'\n';
    
  lMain.First(); 
  while (!lMain.eof) {
    elem.innerHTML += lMain.FindField('DocKey').AsString + ' ' +
	                  lMain.FindField('DocNo').AsString + ' ' + lMain.FindField('DocDate').AsString + ' '+
                      lMain.FindField('CompanyName').AsString + ' ' + lMain.FindField('DocAmt').AsString + '\n';
	lMain.Next();  
  }
  elem.innerHTML += 'End Main'+'\n\n';
  
  elem.innerHTML += 'From Detail'+'\n';
  lDetail.First(); 
  while (!lDetail.eof) {
    elem.innerHTML += lDetail.FindField('Dockey').AsString + ' ' + lDetail.FindField('Account').AsString + ' ' + 
	                  lDetail.FindField('Description').AsString + ' ' + lDetail.FindField('Amount').AsString + '\n';
	lDetail.Next();  
  }  
  elem.innerHTML += 'End Detail'+'\n\n';
}
	  
    </script>
  </head>
  <body>
    <form>
      <textarea id="txt1" rows="30" cols="116"></textarea>
      <input type="button" value="Calculate" onclick="GetData()">
    </form>
  </body>
</html>

Customer.RO

Customer.RO Report Object Script
<html>
<head>
<title>Add Customer Invoice</title>
<script language='JScript'>
var ComServer;
 
function CreateSQLAccServer() {
  ComServer = new ActiveXObject('SQLAcc.BizApp');
  if (!ComServer.IsLogin) {            /* check whether user has logon */
    ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
 /* UserName, Password */
  }
}

function GetCustomerData() {
  var RptObject, lDataSet, lDataSet2;
  edOutput.value = '';
  edOutput2.value = '';
  //Step 1: Create Com Server object
  CreateSQLAccServer();
  
  //Step 2: Find and Create the Report Objects
  RptObject = ComServer.RptObjects.Find('Customer.RO');
  
  //Step 3: Spool parameters
  RptObject.Params.Find('AllAgent').Value = true;
  RptObject.Params.Find('AllArea').Value = true;
  RptObject.Params.Find('AllCompany').Value = true;
  RptObject.Params.Find('AllCompanyCategory').Value = true;
  RptObject.Params.Find('AllCurrency').Value = true;
  RptObject.Params.Find('AllTerms').Value = true;
  RptObject.Params.Find('SelectDate').Value = true;
  RptObject.Params.Find('PrintActive').Value = true;
  RptObject.Params.Find('PrintInactive').Value = false;
  RptObject.Params.Find('PrintPending').Value = false;
  RptObject.Params.Find('PrintProspect').Value = false;
  RptObject.Params.Find('PrintSuspend').Value = false;
  //RptObject.Params.Find('CompanyData').Value = '300-A0003';
  
  //Step 4: Perform Report calculation 
  RptObject.CalculateReport();
  lDataSet = RptObject.DataSets.Find('cdsMain');
  lDataSet2 = RptObject.DataSets.Find('cdsBranch');
  
  //alert('Count ' + lDataSet.RecordCount);

  //Step 5 Retrieve the output 
  lDataSet.First;
  while  (!lDataSet.eof){
    edOutput.value = edOutput.value + 
	                'Code : ' + lDataSet.FindField('Code').AsString + '\n' + 
	                'Company Name : ' + lDataSet.FindField('CompanyName').AsString +'\n\n';
	lDataSet.Next();
  }
  lDataSet2.First();
  while (!lDataSet2.eof){
	  edOutput2.value = edOutput2.value + 
	                   'Code : '+ lDataSet2.FindField('Code').AsString + '\n' + 
					   'Branch Name : '+ lDataSet2.FindField('BranchName').AsString + '\n' + 
	                   'Address 1 : '+ lDataSet2.FindField('Address1').AsString + '\n' + 
					   'Address 2 : '+ lDataSet2.FindField('Address2').AsString + '\n' + 
					   'Address 3 : '+ lDataSet2.FindField('Address3').AsString + '\n' + 
					   'Address 4 : '+ lDataSet2.FindField('Address4').AsString + '\n' + 
					   'Phone 1 : '+ lDataSet2.FindField('Phone1').AsString  +'\n\n';
	  lDataSet2.Next();
    }
	
}

</script>
</head>
<body>
  <table>
    <tr>
      <th>Main Table</th>
      <th>Branch Branch</th>
    </tr>
    <tr>
      <td>
        <TEXTAREA rows=15 cols=75 name="edOutput"></TEXTAREA>
	  </td>
      <td>
        <TEXTAREA rows=15 cols=75 name="edOutput2"></TEXTAREA>
	  </td>
    </tr>		
  </table>
		
  <table width="83%">
	<tr>
	  <td align="center">
		<input type='submit' value='Sync Data' name='btnSubmit' onclick='GetCustomerData()'>
	  </td>
	</tr>
  </table>
</body>
</html>

Get Next IV Number

Get Next IV Number Script
<html>
<head>
<title>Add Cash Sales</title>
<script language="JScript">
var ComServer, lDataSet;

function CreateSQLAccServer() {
  ComServer = new ActiveXObject('SQLAcc.BizApp');
  if (!ComServer.IsLogin) {            /* check whether user has logon */
    ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
 /* UserName, Password */
  }
}

function zeroPad(num, places) {
  var zero = places - num.toString().length + 1;
  return Array(+(zero > 0 && zero)).join("0") + num;
  /*zeroPad(5, 2); // "05"*/
}

function GetData() {
  var lSQL;
  lSQL = "SELECT A.*, B.NEXTNUMBER FROM SY_DOCNO A ";
  lSQL = lSQL + "INNER JOIN SY_DOCNO_DTL B ON (A.DOCKEY=B.PARENTKEY) ";
  lSQL = lSQL + "WHERE A.DOCTYPE='IV' ";
  lSQL = lSQL + "AND A.DESCRIPTION='Customer Invoice' ";
  lSQL = lSQL + "AND A.STATESET=1 ";
  lDataSet = ComServer.DBManager.NewDataSet(lSQL);  
}

function ShowNextNo() {
  var Desc, Fmt, NextNo, lResult, lPad;
  
  CreateSQLAccServer();  
  GetData();

  if (lDataSet.RecordCount > 0) {   
    lDataSet.First;
    Desc = lDataSet.FindField("Description").AsString;
	Fmt  = lDataSet.FindField("Format").AsString;
	NextNo = lDataSet.FindField("NEXTNUMBER").Value;
    alert(Desc);
	alert(Fmt);
	alert(NextNo);
	
	lPad = Fmt.substr(5, 1);
	lPad = zeroPad(NextNo, lPad)
	Desc = Fmt.substr(0, 3);
	alert(Desc + lPad);
  }	
}
</script>
</head>
<body>
<input type="submit" value="Show Next No" name="btnSubmit" onclick="ShowNextNo()">
</body>
</html>

Customer & Supplier Contra

Customer & Supplier Contra Script
<html>
<head>
<title>Add Customer Invoice</title>
<script language="JScript">
var ComServer;
 
function CreateSQLAccServer() {
  ComServer = new ActiveXObject('SQLAcc.BizApp');
  if (!ComServer.IsLogin) {            /* check whether user has logon */
    ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
 /* UserName, Password */
  }
}
 
function PostARCT() {
  var BizObject, lMain, lKO, V;
 
  CreateSQLAccServer();
 
  BizObject = ComServer.BizObjects.Find('AR_CT');
  lMain = BizObject.DataSets.Find('MainDataSet');
  lKO = BizObject.DataSets.Find('cdsKnockOff');
  BizObject.New();
 
  lMain.FindField('DocKey').value = -1;
  lMain.FindField('DocNo').value = "--CT Test--";
  lMain.FindField('DocDate').value = "01/10/2020";
  lMain.FindField('PostDate').value = "01/10/2020";
  lMain.FindField('Code').value = "300-A0002";
  lMain.FindField('Description').value = "Contra";
  lMain.FindField('DocAmt').value = "100.00";
  //lMain.FindField('UnappliedAmt').value = "0";

  v = ComServer.CreateOleVariantArray(2);
  v.SetItem(0, 'IV'); /*Knock Off DocType*/
  v.SetItem(1, 'IV-00021'); /*Knock Off DocNo*/

  if (lKO.Locate('DocType;DocNo', v.AsOleVariant(), false, false)){ 
          lKO.Edit();
          lKO.FindField('DocAmt').value = "100";		  
          lKO.FindField('KnockOff').AsString = 'T';
          lKO.Post(); }

  /* Save document */  
    BizObject.Save();
    BizObject.Close();
    alert('Customer Contra - has been saved.');
}

function PostAPST() {
  var BizObject, lMain, lKO, V, lDocNo, lDocKey;
 
  CreateSQLAccServer();
 
  BizObject = ComServer.BizObjects.Find('AP_ST');
  lMain = BizObject.DataSets.Find('MainDataSet');
  lKO = BizObject.DataSets.Find('cdsKnockOff');
  
  lDocNo = "--CT Test--"
  lDocKey = BizObject.FindKeyByRef("DocNo", lDocNo)
  BizObject.Params.Find("DocKey").Value = lDocKey  
  
  if (lDocKey != null) {
    BizObject.Open();
	BizObject.Edit();
	lMain.FindField('Code').value = "400-C0001";
	lMain.FindField('DocAmt').value = "100.00";
  //lMain.FindField('UnappliedAmt').value = "0";

   v = ComServer.CreateOleVariantArray(2);
   v.SetItem(0, 'PI'); /*Knock Off DocType*/
   v.SetItem(1, 'PI-00001'); /*Knock Off DocNo*/

    if (lKO.Locate('DocType;DocNo', v.AsOleVariant(), false, false)){ 
          lKO.Edit();
          lKO.FindField('DocAmt').value = "100";		  
          lKO.FindField('KnockOff').AsString = 'T';
          lKO.Post(); }

  /* Save document */  
    BizObject.Save();  
    BizObject.Close();
    alert('Supplier Contra - has been Updated.');	
  }
}
</script>
</head>
<body>
<button onclick="javascript:PostARCT();">PostARCT</button>&nbsp;&nbsp;
<button onclick="javascript:PostAPST();">PostAPST</button>&nbsp;&nbsp;
</body>
</html>

Add Stock Item

Add ST_Item Script
<html>
<head>
<title>Add Stock Item</title>
<script language="JScript">
var ComServer;

function CreateSQLAccServer() {
  ComServer = new ActiveXObject('SQLAcc.BizApp');
  if (!ComServer.IsLogin) {            /* check whether user has logon */
    ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
 /* UserName, Password */
  }
}

function InsertData() {
  var BizObject, lMain, lDetail;
  
  CreateSQLAccServer();

  /*Step 2: Find and Create the Biz Objects*/
  BizObject = ComServer.BizObjects.Find('ST_ITEM') ;

  /*Step 3: Set Dataset*/
  lMain   = BizObject.DataSets.Find('MainDataSet');  /*lMain contains master data*/
  lUOM = BizObject.DataSets.Find('cdsUOM'); /*lDetail contains detail data */  
  
  /*Begin Looping yr data*/
  /*Step 4 : Insert Data - Master*/
  BizObject.New();
  lMain.FindField('Code').AsString        = "Code JScript";
  lMain.FindField('DESCRIPTION').AsString = "Post from JScript"
  lMain.FindField('STOCKGROUP').AsString    = "DEFAULT"; /*Optional*/
  lMain.FindField('STOCKCONTROL').AsString    = "T"; /*Optional*/
  lMain.FindField('ISACTIVE').AsString    = "T"; /*Optional*/
    
  /*Step 5: Insert Data - UOM*/
  lUOM.Edit(); /*For 1St UOM*/
  lUOM.FindField('UOM').AsString = "PCS";
  lUOM.FindField('Rate').AsFloat = 1;
  lUOM.FindField('RefCost').AsFloat = 10.2;
  lUOM.FindField('RefPrice').AsFloat = 25;
  lUOM.Post();

  lUOM.Append(); /*For 2nd UOM*/
  lUOM.FindField('UOM').AsString = "CTN";
  lUOM.FindField('Rate').AsFloat = 12;
  lUOM.FindField('RefCost').AsFloat = 102;
  lUOM.FindField('RefPrice').AsFloat = 240;
  lUOM.Post();

  /*Step 6: Save*/
  BizObject.Save();
  BizObject.Close();
    alert('Item has been saved.');
}
</script>
</head>
<body>
<input type="submit" value="SYNC" name="btnSubmit" onclick="InsertData()">
</body>
</html>

Get Company Profile

Get Company Profile Script
<html>
<head>
<title>Add Cash Sales</title>
<script language="JScript">
var ComServer, lDataSet;

function CreateSQLAccServer() {
  ComServer = new ActiveXObject('SQLAcc.BizApp');
  if (!ComServer.IsLogin) {            /* check whether user has logon */
    ComServer.Login('ADMIN', 'ADMIN', 'C\:\\eStream\\SQLAccounting\\Share\\DEFAULT.DCF', 'SAMPLE.FDB');
 /* UserName, Password */
  }
}

function zeroPad(num, places) {
  var zero = places - num.toString().length + 1;
  return Array(+(zero > 0 && zero)).join("0") + num;
  /*zeroPad(5, 2); // "05"*/
}

function GetData() {
  var lSQL;
  lSQL = "SELECT COMPANYNAME, REMARK, BRN, BRN2, GSTNO, ";
  lSQL = lSQL + "SALESTAXNO, SERVICETAXNO, ";
  lSQL = lSQL + "ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS4 FROM SY_PROFILE ";
  lDataSet = ComServer.DBManager.NewDataSet(lSQL);  
}

function ShowCoProfile() {
  var CoName, Rmk, BRN;
  
  CreateSQLAccServer();  
  GetData();

  if (lDataSet.RecordCount > 0) {   
    lDataSet.First;
    CoName = lDataSet.FindField("COMPANYNAME").AsString;
	Rmk  = lDataSet.FindField("REMARK").AsString;
	BRN = lDataSet.FindField("BRN").Value;
    alert(CoName);
	alert(Rmk);
	alert(BRN);
  }	
}
</script>
</head>
<body>
<input type="submit" value="Show Co Profile" name="btnSubmit" onclick="ShowCoProfile()">
</body>
</html>


Delphi

The below example is assuming after you had check the login status.

GL_JE

GL_JE Script
procedure TfmMain.dxbb_GL_JEClick(Sender: TObject);
var BizApp, lMain, lDtl, lBizObj, lDocKey : Variant;
    i : integer;
begin
  BizApp := CreateOleObject('SQLAcc.BizApp');
  try
    lBizObj := BizApp.BizObjects.Find('GL_JE');
    lMain   := lBizObj.DataSets.Find('MainDataSet');
    lDtl    := lBizObj.DataSets.Find('cdsDocDetail');
    lBizObj.New;
    lMain.FindField('DOCKEY').Value        := -1;
    lMain.FindField('DocNo').Value         := '--JE Test--';
    lMain.FindField('DocDate').Value       := '28 Aug 2017';
    lMain.FindField('PostDate').Value      := '28 Aug 2017';
    lMain.FindField('TAXDATE').Value       := '28 Aug 2017';
    lMain.FindField('Description').Value   := 'Postage';
    lMain.FindField('Cancelled').Value     := 'F';
    lMain.FindField('DOCNOSETKEY').Value   := 0;
    lMain.Post;

    //For Tax Inclusive
    lDtl.Append;
    lDtl.FindField('DTLKEY').Value       := -1;
    lDtl.FindField('DOCKEY').Value       := -1;
    lDtl.FindField('SEQ').Value          := 1;
    lDtl.FindField('CODE').Value         := '610-1000';
    lDtl.FindField('DESCRIPTION').Value  := 'Item Desc 1';
    lDtl.FindField('TAX').Value          := 'TX';
//    lDtl.FindField('LOCALTAXAMT').AsFloat := 17.32;//For JE you can't override (i.e. system auto calc)
    lDtl.FindField('TAXINCLUSIVE').Value  := 1;
    lDtl.FindField('LocalDR').AsFloat     := 306;//Including GST if TAXINCLUSIVE = 1
    lDtl.FindField('DR').AsFloat          := 306;//if wanted DR <> LocalDR
    lDtl.FindField('CHANGED').Value       := 'F';
    lDtl.Post;

    //For Tax Exclusive
    lDtl.Append;
    lDtl.FindField('DTLKEY').Value       := -1;
    lDtl.FindField('DOCKEY').Value       := -1;
    lDtl.FindField('SEQ').Value          := 2;
    lDtl.FindField('CODE').Value         := '605-200';
    lDtl.FindField('DESCRIPTION').Value  := 'Item Desc 2';
    lDtl.FindField('TAX').Value          := 'TX';
    lDtl.FindField('TAXINCLUSIVE').Value := 0;
    lDtl.FindField('LocalCR').AsFloat    := 100;
    lDtl.FindField('CHANGED').Value      := 'F';
    lDtl.Post;

    //For No GST
    lDtl.Append;
    lDtl.FindField('DTLKEY').Value       := -1;
    lDtl.FindField('DOCKEY').Value       := -1;
    lDtl.FindField('SEQ').Value          := 3;
    lDtl.FindField('CODE').Value         := '610-002';
    lDtl.FindField('DESCRIPTION').Value  := 'Item Desc 3';
    lDtl.FindField('TAX').Value          := '';
    lDtl.FindField('TAXINCLUSIVE').Value  := 0;
    lDtl.FindField('LocalCR').AsFloat     := 200;
    lDtl.FindField('CHANGED').Value       := 'F';
    lDtl.Post;

    lBizObj.Save;
    MessageDlg('GL_JE-DocNo : ''--JE Test--'' Posted...', mtInformation, [mbOK],0);
  finally
    lBizObj.Close;
  end;
end;

GL_PV

GL_PV Script
procedure TfmMain.dxbb_GLPVClick(Sender: TObject);
var lMain, lDtl, lBizObj, BizApp : Variant;
    lTime : TDateTime;
begin
  lTime := Now;
  BizApp := CreateOleObject('SQLAcc.BizApp');
  try
    lBizObj := BizApp.BizObjects.Find('GL_PV');
    lMain   := lBizObj.DataSets.Find('MainDataSet');
    lDtl    := lBizObj.DataSets.Find('cdsDocDetail');
    lBizObj.New;
    lMain.FindField('DOCKEY').Value           := -1;
    lMain.FindField('DocNo').AsString         := '--CB PV Test1--';
    lMain.FindField('DocDate').Value          := '18 Aug 2015';
    lMain.FindField('PostDate').Value         := '18 Aug 2015';
    lMain.FindField('TAXDATE').Value          := '18 Aug 2015';
    lMain.FindField('Description').AsString   := 'Compacc System';
    lMain.FindField('PAYMENTMETHOD').AsString := '310-001';
    lMain.FindField('CHEQUENUMBER').AsString  := 'MBB 213245';
    lMain.FindField('DocAmt').AsFloat         := 2019;
    lMain.FindField('Cancelled').AsString     := 'F';
    lMain.FindField('CHANGED').AsString       := 'F';
    lMain.Post;

    lDtl.Append;
    lDtl.FindField('DTLKEY').Value         := -1;
    lDtl.FindField('DOCKEY').Value         := -1;
    lDtl.FindField('Code').AsString        := '200-300';
    lDtl.FindField('DESCRIPTION').AsString := 'Maybank - Asus A555LD-xx313H';
    lDtl.FindField('TAX').AsString         := 'TX';
    lDtl.FindField('TAXAMT').AsFloat       := 114.28;
    lDtl.FindField('TAXINCLUSIVE').Value   := 1;
    lDtl.FindField('AMOUNT').AsFloat       := 2019;
    lDtl.FindField('CHANGED').AsString     := 'F';
    lDtl.Post;
    lBizObj.Save;
    lTime := Now - lTime;
    MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
               mtInformation, [mbOk], 0);
  finally
    lBizObj.Close;
  end;
end;

AR_Customer

AR_Customer Script
procedure TfmMain.dxbb_CustomerClick(Sender: TObject);
var lMain, lDtl, lBizObj, lBizApp : Variant;
    lTime : TDateTime;
begin
  lTime := Now;
  lBizApp := CreateOleObject('SQLAcc.BizApp');

  lBizObj := lBizApp.BizObjects.Find('AR_Customer');
  lMain   := lBizObj.DataSets.Find('MainDataSet');
  lDtl    := lBizObj.DataSets.Find('cdsBranch');

  try
    lBizObj.New;
    lMain.FindField('Code').value        := '300-Test';
    lMain.FindField('CompanyName').value := 'Testing 123';

    lDtl.Edit; //For 1st Branch
    lDtl.FindField('BranchName').AsString := 'BILLING';
    lDtl.FindField('Address1').AsString   := 'Address1';
    lDtl.FindField('Address2').AsString   := 'Address2';
    lDtl.FindField('Address3').AsString   := 'Address3';
    lDtl.FindField('Address4').AsString   := 'Address4';
    lDtl.FindField('Attention').AsString  := 'Attention';
    lDtl.FindField('Phone1').AsString     := 'Phone1';
    lDtl.FindField('Fax1').AsString       := 'Fax1';
    lDtl.FindField('Email').AsString      := 'EmailAddress';
    lDtl.Post;

    lDtl.Append; //For 2nd Branch
    lDtl.FindField('BranchName').AsString := 'Branch1';
    lDtl.FindField('Address1').AsString   := 'DAddress1';
    lDtl.FindField('Address2').AsString   := 'DAddress2';
    lDtl.FindField('Address3').AsString   := 'DAddress3';
    lDtl.FindField('Address4').AsString   := 'DAddress4';
    lDtl.FindField('Attention').AsString  := 'DAttention';
    lDtl.FindField('Phone1').AsString     := 'DPhone1';
    lDtl.FindField('Fax1').AsString       := 'DFax1';
    lDtl.FindField('Email').AsString      := 'DEmailAddress';
    lDtl.Post;
    lBizObj.Save;

    lTime := Now - lTime;
    MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
               mtInformation, [mbOk], 0);
  finally
    lBizObj.Close;
  end;
end;

AR_PM

AR_PM Script
procedure TfmMain.dxbb_ARPMClick(Sender: TObject);
var lMain, lKO, lBizApp, lBizObj, V : Variant;
begin
  lBizApp := CreateOleObject('SQLAcc.BizApp');
  try
    lBizObj := lBizApp.BizObjects.Find('AR_PM');
    lMain   := lBizObj.DataSets.Find('MainDataSet');
    lKO     := lBizObj.DataSets.Find('cdsKnockOff');

    lBizObj.New;
    lMain.FindField('DOCKEY').Value           := -1;
    lMain.FindField('DocNo').AsString         := '--PM Test--'; //Payment Document Number
    lMain.FindField('CODE').AsString          := '300-A0001';
    lMain.FindField('DocDate').Value          := '28 Aug 2016';
    lMain.FindField('PostDate').Value         := '28 Aug 2016';
    lMain.FindField('Description').AsString   := 'Payment for A/c';
    lMain.FindField('PaymentMethod').AsString := '320-000';
    lMain.FindField('DocAmt').AsFloat         := 1060;
    lMain.FindField('Cancelled').AsString     := 'F';

    V := lBizApp.CreateOleVariantArray(2);
    V.SetItem(0, 'IV'); //Document Type is either is IV or DN for Sales & PI or SD for Purchase
    V.SetItem(1, '--IV Test--');  //Invoice Document Number

    if lKO.Locate('DocType;DocNo', V.AsOleVariant, False, False) then
      begin
        lKO.Edit;
        lKO.FindField('KOAmt').ASFloat     := 500;
        lKO.FindField('KnockOff').AsString := 'T';
        lKO.Post;
      end;

    lBizObj.Save;
    MessageDlg('AR_PM-DocNo : ''--PM Test--'' Posted...', mtInformation, [mbOK],0);
  finally
    lBizObj.Close;
  end;
end;

AR_PM-Edit

AR_PM Script
procedure TfmMain.dxbb_ARPMClick(Sender: TObject);
var lMain, lKO, lBizApp, lBizObj, V : Variant;
begin
  lBizApp := CreateOleObject('SQLAcc.BizApp');
  try
    lBizObj := lBizApp.BizObjects.Find('AR_PM');
    lMain   := lBizObj.DataSets.Find('MainDataSet');
    lKO     := lBizObj.DataSets.Find('cdsKnockOff');

    lDocKey := lBizObj.FindKeyByRef('DocNo', '--PM Test--');
    lBizObj.Params.Find('DocKey').Value := VarToStr(lDocKey);

    If not VarIsNull(lDocKey) Then begin
      lBizObj.Open;
      lBizObj.Edit;
      lMain.FindField('DOCKEY').Value           := -1;
      lMain.FindField('DocDate').Value          := '28 Aug 2016';
      lMain.FindField('PostDate').Value         := '28 Aug 2016';
      lMain.FindField('Description').AsString   := 'Payment for A/c';
      lMain.FindField('PaymentMethod').AsString := '310-000';
      lMain.FindField('DocAmt').AsFloat         := 800.28;
      lMain.FindField('UnappliedAmt').AsFloat   := 100.28;
      lMain.FindField('Cancelled').AsString     := 'F';
      lMain.FindField('CHANGED').AsString       := 'F';

      V := lBizApp.CreateOleVariantArray(2);
      V.SetItem(0, 'IV'); //Document Type is either is IV or DN for Sales & PI or SD for Purchase
      V.SetItem(1, '--IV Test--');  //Document Number

      if lKO.Locate('DocType;DocNo', V.AsOleVariant, False, False) then
        begin
          lKO.Edit;
          lKO.FindField('KOAmt').AsFloat     := 700.28; // IV Knock Off/Offset Amount
          lKO.FindField('KnockOff').AsString := 'T';
          lKO.Post;
        end;

      lBizObj.Save;
      MessageDlg('AR_PM-DocNo : ''--PM Test--'' Updated...', mtInformation, [mbOK],0);
    end;
  finally
    lBizObj.Close;
  end;
end;

ST_Item

ST_Item Script
procedure TfmMain.dxbb_ST_ItemClick(Sender: TObject);
var lMain, lDtl, lBizObj, lBizApp : Variant;
    lTime : TDateTime;
begin
  lTime := Now;
  lBizApp := CreateOleObject('SQLAcc.BizApp');
  lBizObj := lBizApp.BizObjects.Find('ST_ITEM');
  lMain   := lBizObj.DataSets.Find('MainDataSet');
  lDtl    := lBizObj.DataSets.Find('cdsUOM');

  try
    lBizObj.New;
    lMain.FindField('Code').AsString        := 'Test-1';
    lMain.FindField('Description').AsString := 'Testing - Description';

    lDtl.Edit; //For 1st UOM
    lDtl.FindField('UOM').AsString     := 'PCS';
    lDtl.FindField('Rate').AsFloat     := 1;
    lDtl.FindField('RefCost').AsFloat  := 10.20;
    lDtl.FindField('RefPrice').AsFloat := 25.00;
    lDtl.Post;

    lDtl.Append; //For 2nd UOM
    lDtl.FindField('UOM').AsString     := 'CTN';
    lDtl.FindField('Rate').AsFloat     := 12;
    lDtl.FindField('RefCost').AsFloat  := 102.00;
    lDtl.FindField('RefPrice').AsFloat := 240.00;
    lDtl.Post;
    lBizObj.Save;

    lTime := Now - lTime;
    MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
               mtInformation, [mbOk], 0);
  finally
    lBizObj.Close;
  end;
end;

ST_Item-Edit

ST_Item Script
procedure TfmMain.dxbb_ST_ItemClick(Sender: TObject);
var lMain, lDtl, lBizObj, lBizApp, lDocKey, V : Variant;
begin
  lBizApp := CreateOleObject('SQLAcc.BizApp');
  lBizObj := lBizApp.BizObjects.Find('ST_ITEM');
  lMain   := lBizObj.DataSets.Find('MainDataSet');
  lDtl    := lBizObj.DataSets.Find('cdsUOM');

  lDocKey := lBizObj.FindKeyByRef('Code', '--Stock Item Test--');
  lBizObj.Params.Find('DocKey').Value := VarToStr(lDocKey);
  try

    If not VarIsNull(lDocKey) Then begin
      lBizObj.Open;
      lBizObj.Edit;
      lMain.FindField('Description').value := 'Testing - Description';

      V := lBizApp.CreateOleVariantArray(2);
      V.SetItem(0, 'CTN'); //UOM
      V.SetItem(1, '12');  //Rate

      if lDtl.Locate('UOM;Rate', V.AsOleVariant, False, False) then
        begin
          lDtl.Edit;
          lDtl.FindField('RefCost').AsFloat  := 10.20;
          lDtl.FindField('RefPrice').AsFloat := 25.00;
          lDtl.Post;
        end;
      lBizObj.Save;

      MessageDlg('ST_Item-ItemCode : ''--Stock Item Test--'' Updated...', mtInformation, [mbOK],0);
    end;
  finally
    lBizObj.Close;
  end;
end;

SL_IV

SL_IV Script
procedure TfmMain.dxbb_SL_IVClick(Sender: TObject);
var lMain, lDtl, lSN, lBizObj, lBizApp : Variant;
    lTime : TDateTime;
begin
  lTime := Now;
  lBizApp := CreateOleObject('SQLAcc.BizApp');
  lBizObj := lBizApp.BizObjects.Find('SL_IV');
  lMain   := lBizObj.DataSets.Find('MainDataSet');
  lDtl    := lBizObj.DataSets.Find('cdsDocDetail');
  lSN     := lBizObj.DataSets.Find('cdsSerialNumber');

  try
    lBizObj.New;
    lMain.FindField('DOCKEY').Value         := -1;
    lMain.FindField('DocNo').AsString       := '--IV Test--';
    lMain.FindField('CODE').AsString        := '300-A0001';
    lMain.FindField('DocDate').Value        := '28 Aug 2020';
    lMain.FindField('PostDate').Value       := '28 Aug 2020';
    lMain.FindField('TAXDATE').Value        := '28 Aug 2020';
    lMain.FindField('Description').AsString := 'Sales';
    lMain.FindField('Cancelled').AsString   := 'F';
    lMain.Post;

    lDtl.Append; // For Tax Inclusive = True with override Tax Amount
    lDtl.FindField('DTLKEY').Value         := -1;
    lDtl.FindField('DOCKEY').Value         := -1;
    lDtl.FindField('SEQ').Value            := 1;
    lDtl.FindField('ItemCode').AsString    := 'ITEM A';
    lDtl.FindField('ACCOUNT').AsString     := '500-000'; //GL Sales Account
    lDtl.FindField('DESCRIPTION').AsString := 'Sales Item A';
    lDtl.FindField('QTY').AsFloat          := 1;
    lDtl.FindField('TAX').AsString         := 'SV';
    lDtl.FindField('TAXINCLUSIVE').Value   := 0;
    lDtl.FindField('UNITPRICE').AsFloat    := 435;//Including GST UnitPrice
    lDtl.FindField('AMOUNT').AsFloat       := 410.37; //Must Excluding GST (Qty * UnitPrice) // Less 0.01
    lDtl.FindField('TAXAMT').AsFloat       := 24.63; //Extra 0.01

    lDtl.DisableControls; //For Tax Inclusive Only where TaxAmt is not as Calc
    try
      lDtl.FindField('TAXINCLUSIVE').Value := 1;
    finally
      lDtl.EnableControls;
    end;
    lDtl.Post;

    lDtl.Append; // For Tax Inclusive = False with override Tax Amount
    lDtl.FindField('DTLKEY').Value         := -1;
    lDtl.FindField('DOCKEY').Value         := -1;
    lDtl.FindField('SEQ').Value            := 2;
    lDtl.FindField('ItemCode').AsString    := 'ITEM B';
    lDtl.FindField('ACCOUNT').AsString     := '500-000';
    lDtl.FindField('DESCRIPTION').AsString := 'Sales Item B';
    lDtl.FindField('QTY').AsFloat          := 1;
    lDtl.FindField('TAX').AsString         := 'SV';
    lDtl.FindField('TAXINCLUSIVE').Value   := 0;
    lDtl.FindField('UNITPRICE').AsFloat    := 94.43;
    lDtl.FindField('AMOUNT').AsFloat       := 94.43;
    lDtl.FindField('TAXAMT').AsFloat       := 5.66; //Less 0.01
    lDtl.Post;

    lDtl.Append; // For Serial Number
    lDtl.FindField('DTLKEY').Value         := -1;
    lDtl.FindField('DOCKEY').Value         := -1;
    lDtl.FindField('SEQ').Value            := 3;
    lDtl.FindField('ItemCode').AsString    := 'SN1';
    lDtl.FindField('ACCOUNT').AsString     := '500-000';
    lDtl.FindField('DESCRIPTION').AsString := 'Sales Serial Number Item';

    lSN.Append;
    lSN.FindField('SERIALNUMBER').AsString  := 'SN-00001';
    lSN.Post;

    lSN.Append;
    lSN.FindField('SERIALNUMBER').AsString  := 'SN-00002';
    lSN.Post;

    lDtl.FindField('QTY').AsFloat        := 2;
    lDtl.FindField('TAX').AsString       := 'SR';
    lDtl.FindField('TAXINCLUSIVE').Value := 0;
    lDtl.FindField('UNITPRICE').AsFloat  := 94.43;
    lDtl.FindField('TAXAMT').AsFloat     := 11.33;
    lDtl.Post;

    lBizObj.Save;

    lTime := Now - lTime;
    MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
               mtInformation, [mbOk], 0);
  finally
    lBizObj.Close;
    lMain := null;
    lDtl := null;
    lSN := null;
    lBizObj := null;
    lBizApp := null;
  end;
end;

Customer.IV.RO

Customer.IV.RO Report Object Script
procedure TfmMain.dxbb_RptObjClick(Sender: TObject);
var lBizApp, lRptVar : Variant;
    lTime : TDateTime;
    cdsMain, cdsDtl : TClientDataset;
begin
  lTime := Now;
  cdsMain := TClientDataset.Create(nil);
  cdsDtl  := TClientDataset.Create(nil);
  lBizApp := CreateOleObject('SQLAcc.BizApp');
  try
    lRptVar := null;
    lRptVar := lBizApp.RptObjects.Find('Customer.IV.RO');
    lRptVar.Params.Find('SelectDate').AsBoolean           := True;
    lRptVar.Params.Find('DateFrom').AsDate                := '01/01/2015';
    lRptVar.Params.Find('DateTo').AsDate                  := '31/12/2015';
    lRptVar.Params.Find('AllAgent').AsBoolean             := False;
    lRptVar.Params.Find('AgentData').AsBlob               := '----'#13#10'HALIM'; //Filter by Agent code ---- & HALIM
    lRptVar.Params.Find('AllArea').AsBoolean              := True;
//    lRptVar.Params.Find('AreaData').AsBlob                := ; //Not use if AllArea is True
    lRptVar.Params.Find('AllCompany').AsBoolean           := True;
//    lRptVar.Params.Find('CompanyData').AsBlob             := ; //Not use if AllCompany is True
    lRptVar.Params.Find('AllCurrency').AsBoolean          := True;
//    lRptVar.Params.Find('CurrencyData').AsBlob            := ; //Not use if AllCurrenty is True
    lRptVar.Params.Find('AllDocProject').AsBoolean        := True;
//    lRptVar.Params.Find('DocProjectData').AsBlob          := ; //Not use if AllDocProject is True
    lRptVar.Params.Find('AllCompanyCategory').AsBoolean   := True;
//    lRptVar.Params.Find('CompanyCategoryData').AsBlob     := ; //Not use if AllCompanyCategory is True
    lRptVar.Params.Find('AllDocument').AsBoolean          := True;
//    lRptVar.Params.Find('DocumentData').AsBlob            := ; //Not use if AllDocument is True
    lRptVar.Params.Find('IncludeCancelled').AsBoolean   := True;
    lRptVar.Params.Find('PrintDocumentStyle').AsBoolean := False;
    lRptVar.Params.Find('AllItemProject').AsBoolean     := True;
    lRptVar.Params.Find('AllPaymentMethod').AsBoolean   := True;
    lRptVar.CalculateReport;

    cdsMain.XMLData := lRptVar.DataSets.Find('cdsMain').XMLData;      //Master Data
    cdsDtl.XMLData  := lRptVar.DataSets.Find('cdsDocDetail').XMLData; //Detail Data - To link Master Data use Dockey field

    cdsMain.SaveToFile('C:\Temp\_ListM.xml'); //Export To XML file
    cdsDtl.SaveToFile('C:\Temp\_ListD.xml');  //Export To XML file

    lTime := Now - lTime;
    MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
               mtInformation, [mbOk], 0);
  finally
    lRptVar := null;
    cdsMain.Free;
    cdsDtl.Free;
  end;
end;

Stock.Item.RO

Stock.Item.RO Report Object Script
procedure TfmMain.dxbb_ST_ITEM_ROClick(Sender: TObject);
var lBizApp, lRptVar : Variant;
    lTime : TDateTime;
    cdsMain, cdsDtl, cdsCat : TClientDataset;
    lSQL : string;
begin
  lTime    := Now;
  cdsMain  := TClientDataset.Create(nil);
  cdsDtl   := TClientDataset.Create(nil);
  cdsCat   := TClientDataset.Create(nil);

  lBizApp := CreateOleObject('SQLAcc.BizApp');

  lSQL := 'SELECT * FROM ST_ITEM_CATEGORY ' +
          'WHERE Category IN (''B-MOTOLORA'',''B-MAXIS'')';
  cdsCat.Data := lBizApp.DBManager.Execute(lSQL); //For filtering Category only

  try
    lRptVar := null;
    lRptVar := lBizApp.RptObjects.Find('Stock.Item.RO');
    lRptVar.Params.Find('AllItem').AsBoolean              := True;
    lRptVar.Params.Find('AllStockGroup').AsBoolean        := True;
    lRptVar.Params.Find('AllCustomerPriceTag').AsBoolean  := True;
    lRptVar.Params.Find('AllSupplierPriceTag').AsBoolean  := True;
//    lRptVar.Params.Find('CategoryData').AsBlob            := ; //Not use
//    lRptVar.Params.Find('CategoryTpl').AsBlob             := ; //Not use
//    lRptVar.Params.Find('CustomerPriceTagData').AsBlob    := ; //Not use if AllCustomerPriceTag is True
//    lRptVar.Params.Find('SupplierPriceTagData').AsBlob    := ; //Not use if AllSupplierPriceTag is True
//    lRptVar.Params.Find('DateFrom').AsDate                := '01/01/2015'; //Not use if SelectDate is False
//    lRptVar.Params.Find('DateTo').AsDate                  := '31/12/2015';
    lRptVar.Params.Find('HasAltStockItem').AsBoolean      := False;
    lRptVar.Params.Find('HasBarcode').AsBoolean           := False;
    lRptVar.Params.Find('HasBOM').AsBoolean               := False;
    lRptVar.Params.Find('HasCategory').AsBoolean          := False;
    lRptVar.Params.Find('HasCustomerItem').AsBoolean      := False;
    lRptVar.Params.Find('HasOpeningBalance').AsBoolean    := False;
    lRptVar.Params.Find('HasPurchasePrice').AsBoolean     := False;
    lRptVar.Params.Find('HasSellingPrice').AsBoolean      := False;
    lRptVar.Params.Find('HasSupplierItem').AsBoolean      := False;
//    lRptVar.Params.Find('ItemData').AsBlob                := 'ANT 1.0'#13#10'COVER'; //Filter by Item code ANT 1.0 & COVER
//    lRptVar.Params.Find('ItemCategoryData').AsBlob        := cdsCat.XMLData; //Not use if SelectCategory is False
    lRptVar.Params.Find('PrintActive').AsBoolean          := True;
    lRptVar.Params.Find('PrintInActive').AsBoolean        := True;
    lRptVar.Params.Find('PrintNonStockControl').AsBoolean := True;
    lRptVar.Params.Find('PrintStockControl').AsBoolean    := True;
    lRptVar.Params.Find('SelectCategory').AsBoolean       := False;
    lRptVar.Params.Find('SelectDate').AsBoolean           := False;
    lRptVar.Params.Find('SortBy').AsString                  := 'Code';
//    lRptVar.Params.Find('StockGroupData').AsBlob        := ; //Not use if AllStockGroup is True
    lRptVar.CalculateReport;

    cdsMain.XMLData := lRptVar.DataSets.Find('cdsMain').XMLData; //Master Data
    cdsDtl.XMLData  := lRptVar.DataSets.Find('cdsUOM').XMLData;  //Detail Data - To link Master Data use Code field

    cdsMain.SaveToFile('C:\Temp\_ListM.xml'); //Export To XML file
    cdsDtl.SaveToFile('C:\Temp\_ListD.xml');  //Export To XML file

    lTime := Now - lTime;
    MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
               mtInformation, [mbOk], 0);
  finally
    lRptVar := null;
    cdsMain.Free;
    cdsDtl.Free;
    cdsCat.Free;
  end;
end;

Customer.Statement.RO

Customer.Statement.RO Report Object Script
procedure TfmMain.dxbb_StatementClick(Sender: TObject);
var lBizApp, lRptVar : Variant;
    lTime : TDateTime;
    cdsMain, cdsDtl : TClientDataset;
    s : string;
begin
  lTime := Now;
  cdsMain := TClientDataset.Create(nil);
  cdsDtl  := TClientDataset.Create(nil);
  lBizApp := CreateOleObject('SQLAcc.BizApp');
  s := '<?xml version="1.0" standalone="yes"?>  <DATAPACKET Version="2.0"><METADATA><FIELDS>'+
       '<FIELD attrname="ColumnNo" fieldtype="i4" required="true"/><FIELD attrname="ColumnType" fieldtype="string" WIDTH="1"/>'+
       '<FIELD attrname="Param1" fieldtype="i4" required="true"/><FIELD attrname="Param2" fieldtype="i4" required="true"/>'+
       '<FIELD attrname="IsLocal" fieldtype="boolean"/><FIELD attrname="HeaderScript" fieldtype="bin.hex" SUBTYPE="Text" WIDTH="1"/>'+
       '</FIELDS><PARAMS/></METADATA><ROWDATA><ROW ColumnNo="0" ColumnType="" Param1="0" Param2="0" IsLocal="FALSE"/>'+
       '<ROW ColumnNo="1" ColumnType="A" Param1="0" Param2="0" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;Current Mth&apos;&#013;end;"/>'+
       '<ROW ColumnNo="2" ColumnType="A" Param1="-1" Param2="-1" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;1 Months&apos;&#013;end;"/>'+
       '<ROW ColumnNo="3" ColumnType="A" Param1="-2" Param2="-2" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;2 Months&apos;&#013;end;"/>'+
       '<ROW ColumnNo="4" ColumnType="A" Param1="-3" Param2="-3" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;3 Months&apos;&#013;end;"/>'+
       '<ROW ColumnNo="5" ColumnType="A" Param1="-4" Param2="-4" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;4 Months&apos;&#013;end;"/>'+
       '<ROW ColumnNo="6" ColumnType="B" Param1="-999999" Param2="-5" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;5 Month &amp; above&apos;&#013;end;"/>'+
       '</ROWDATA></DATAPACKET>';
  try
    lRptVar := null;
    lRptVar := lBizApp.RptObjects.Find('Customer.Statement.RO');
//  lRptVar.Params.Find('AgentData').AsBlob               := ; //Not use if AllAgent is True
    lRptVar.Params.Find('AgingData').AsString           := s; //Fixed
    lRptVar.Params.Find('AgingOn').AsString             := 'I'; //Fixed
    lRptVar.Params.Find('AllAgent').AsBoolean           := True;
    lRptVar.Params.Find('AllArea').AsBoolean            := True;
    lRptVar.Params.Find('AllCompany').AsBoolean         := False;
    lRptVar.Params.Find('AllCompanyCategory').AsBoolean := True;
    lRptVar.Params.Find('AllControlAccount').AsBoolean  := True;
    lRptVar.Params.Find('AllCurrency').AsBoolean        := True;
    lRptVar.Params.Find('AllDocProject').AsBoolean      := True;
//    lRptVar.Params.Find('AreaData').AsBlob              := ; //Not use if AllArea is True
//    lRptVar.Params.Find('CompanyCategoryData').AsBlob   := ; //Not use if AllCompanyCategory is True
    lRptVar.Params.Find('CompanyData').AsBlob           := '300-A0001'#13#10'300-C0001'; //Filter by Customer Code 300-A0001 & 300-C0001
//    lRptVar.Params.Find('ControlAccountData').AsBlob    := ; //Not use if AllControlAccount is True
//    lRptVar.Params.Find('CurrencyData').AsBlob          := ; //Not use if AllCurrency is True
    lRptVar.Params.Find('DateFrom').AsDate              := '01 Aug 2016';
    lRptVar.Params.Find('DateTo').AsDate                := '31 Aug 2016';
//    lRptVar.Params.Find('DocProjectData').AsBlob        := ; //Not use if AllDocProject is True
    lRptVar.Params.Find('IncludeZeroBalance').AsBoolean := False;
    lRptVar.Params.Find('SelectDate').AsBoolean         := True;
    lRptVar.Params.Find('SortBy').AsString              := 'CompanyCategory;Code;CompanyName;Agent;Area;CurrencyCode;ControlAccount';
    lRptVar.Params.Find('StatementDate').AsDate         := '31 Aug 2016'; // Norm same as DateTo
    lRptVar.Params.Find('StatementType').AsString       := 'O'; //O := Open Item, B := B/F

    lRptVar.CalculateReport;

    cdsMain.XMLData := lRptVar.DataSets.Find('cdsMain').XMLData;      //Master Data
    cdsDtl.XMLData  := lRptVar.DataSets.Find('cdsDocument').XMLData; //Detail Data - To link Master Data use Code field

    cdsMain.SaveToFile('C:\Temp\_ListM.xml'); //Export To XML file
    cdsDtl.SaveToFile('C:\Temp\_ListD.xml');  //Export To XML file

    lTime := Now - lTime;
    MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
               mtInformation, [mbOk], 0);
  finally
    lRptVar := null;
    cdsMain.Free;
    cdsDtl.Free;
  end;
end;

GL Account List For Sales & Purchase 1

GL_Acc Object Script
procedure TfmMain.dxbb_GLAccClick(Sender: TObject);
var BizApp : Variant;
    lDataSet : TClientDataSet;
    ASQL : String;
begin
  //For Debtor List => SpecialAccType = DR 
  //For Creditor List => SpecialAccType = CR 
  BizApp := CreateOleObject('SQLAcc.BizApp');
  lDataSet := TClientDataSet.Create(Self);
  try
     ASQL := 'SELECT A.Code, A.Description FROM GL_ACC A '+
             'LEFT OUTER JOIN GL_ACC B ON (A.Dockey=B.Parent) '+
             'WHERE A.Parent<>-1 ' +
             'AND B.Dockey IS NULL ' +
             'AND A.SpecialAccType = '''' '+
             'ORDER BY A.CODE ';
     lDataSet.Data := BizApp.DBManager.Execute(ASQL);
     lDataset.SaveToFile('C:\Temp\_List.xml', dfXML); //Export To XML file
  finally
    lDataSet.Free;
  end;
end;

GL Account List For Sales & Purchase 2

GL_Acc Object Script
procedure TfmMain.dxbb_GLAccClick(Sender: TObject);
var BizApp, BizObj : Variant;
    lDataSet1, lDataSet2 : TClientDataSet;
    ASQL : String;
begin
  //For Debtor List => SpecialAccType = DR 
  //For Creditor List => SpecialAccType = CR 
  BizApp := CreateOleObject('SQLAcc.BizApp');
  BizObj := BizApp.BizObjects.Find('GL_Acc');

  lDataSet1 := TClientDataSet.Create(Self);
  lDataSet2 := TClientDataSet.Create(Self);
  try
    ASQL :='Parent<>-1 ' +
           'AND (SpecialAccType IS NULL OR SpecialAccType = '''' ' +
           'OR SpecialAccType = '''') ';
    lDataSet1.XMLData:= BizObj.Select('Dockey,Code,Description', ASQL, 'Code', 'SX', '', '');

    lDataSet2.XMLData:= BizObj.Select('Parent', '', 'Code', 'SX', '', '');

    lDataset2.First; // Remove Parent Account
    while not lDataset2.Eof do begin
      if lDataset1.Locate('Dockey', lDataSet2.FindField('Parent').AsString, []) then
        lDataset1.Delete;
      lDataset2.Next;
    end;
    lDataset1.MergeChangeLog;
    lDataset1.SaveToFile('C:\Temp\_List.xml', dfXML); //Export To XML file 
  finally
    lDataSet1.Free;
    lDataSet2.Free;
  end;
end;

Customer.Aging.RO

Customer Aging Report Object Script
procedure TfmMain.dxbb_AgingClick(Sender: TObject);
var lBizApp, lRptVar : Variant;
    lTime : TDateTime;
    cdsMain, cdsDtl : TClientDataset;
    s : string;
begin
  lTime := Now;
  cdsMain := TClientDataset.Create(nil);
  cdsDtl  := TClientDataset.Create(nil);
  lBizApp := CreateOleObject('SQLAcc.BizApp');

  s := '<?xml version="1.0" standalone="yes"?>  <DATAPACKET Version="2.0"><METADATA><FIELDS>'+
       '<FIELD attrname="ColumnNo" fieldtype="i4" required="true"/><FIELD attrname="ColumnType" fieldtype="string" WIDTH="1"/>'+
       '<FIELD attrname="Param1" fieldtype="i4" required="true"/><FIELD attrname="Param2" fieldtype="i4" required="true"/>'+
       '<FIELD attrname="IsLocal" fieldtype="boolean"/><FIELD attrname="HeaderScript" fieldtype="bin.hex" SUBTYPE="Text" WIDTH="1"/>'+
       '</FIELDS><PARAMS/></METADATA><ROWDATA><ROW ColumnNo="0" ColumnType="" Param1="0" Param2="0" IsLocal="FALSE"/>'+
       '<ROW ColumnNo="1" ColumnType="A" Param1="0" Param2="0" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;Current Mth&apos;&#013;end;"/>'+
       '<ROW ColumnNo="2" ColumnType="A" Param1="-1" Param2="-1" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;1 Months&apos;&#013;end;"/>'+
       '<ROW ColumnNo="3" ColumnType="A" Param1="-2" Param2="-2" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;2 Months&apos;&#013;end;"/>'+
       '<ROW ColumnNo="4" ColumnType="A" Param1="-3" Param2="-3" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;3 Months&apos;&#013;end;"/>'+
       '<ROW ColumnNo="5" ColumnType="A" Param1="-4" Param2="-4" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;4 Months&apos;&#013;end;"/>'+
       '<ROW ColumnNo="6" ColumnType="B" Param1="-999999" Param2="-5" IsLocal="FALSE" HeaderScript="ObjectPascal&#013;begin&#013;Value:= &apos;5 Month &amp; above&apos;&#013;end;"/>'+
       '</ROWDATA></DATAPACKET>';
  try
    lRptVar := null;
    lRptVar := lBizApp.RptObjects.Find('Customer.Aging.RO');
    lRptVar.Params.Find('ActualGroupBy').AsString       := 'Code;CompanyName'; //Fixed
//    lRptVar.Params.Find('AgentData').AsBlob               := ; //Not use if AllAgent is True
    lRptVar.Params.Find('AgingData').AsString           := s;
    lRptVar.Params.Find('AgingDate').AsDate             := '31 Aug 2016';
    lRptVar.Params.Find('AgingOn').AsString             := 'I'; //Fixed
    lRptVar.Params.Find('AllAgent').AsBoolean           := True;
    lRptVar.Params.Find('AllArea').AsBoolean            := True;
    lRptVar.Params.Find('AllCompany').AsBoolean         := True;
    lRptVar.Params.Find('AllCompanyCategory').AsBoolean := True;
    lRptVar.Params.Find('AllControlAccount').AsBoolean  := True;
    lRptVar.Params.Find('AllCurrency').AsBoolean        := True;
    lRptVar.Params.Find('AllDocProject').AsBoolean      := True;
//    lRptVar.Params.Find('AreaData').AsBlob            := ; //Not use if AllArea is True
//    lRptVar.Params.Find('CompanyCategoryData').AsBlob := ; //Not use if AllCompanyCategory is True
//    lRptVar.Params.Find('CompanyData').AsBlob         := ; //Not use if AllCompany is True
//    lRptVar.Params.Find('ControlAccountData').AsBlob  := ; //Not use if AllControlAccount is True
//    lRptVar.Params.Find('CurrencyData').AsBlob        := ; //Not use if AllCurrency is True
//    lRptVar.Params.Find('DocProjectData').AsBlob      := ; //Not use if AllDocProject is True
    lRptVar.Params.Find('FilterPostDate').AsBoolean      := True;
//    lRptVar.Params.Find('GroupBy
    lRptVar.Params.Find('IncludePDC').AsBoolean         := False;
    lRptVar.Params.Find('IncludeZeroBalance').AsBoolean := False;
    lRptVar.Params.Find('SortBy').AsString              := 'Code;CompanyName';
    lRptVar.Params.Find('DateTo').AsDate                := '31 Aug 2016';
    lRptVar.Params.Find('IncludeKnockedOffDetail').AsBoolean := False;

    lRptVar.CalculateReport;

    cdsMain.XMLData := lRptVar.DataSets.Find('cdsMain').XMLData;      //Master Data
    cdsDtl.XMLData  := lRptVar.DataSets.Find('cdsDocument').XMLData; //Detail Data - To link Master Data use Code field

    cdsMain.SaveToFile('C:\Temp\_ListM.xml'); //Export To XML file
    cdsDtl.SaveToFile('C:\Temp\_ListD.xml');  //Export To XML file

    lTime := Now - lTime;
    MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
               mtInformation, [mbOk], 0);
  finally
    lRptVar := null;
    cdsMain.Free;
    cdsDtl.Free;
  end;
end;

GL.CB.RO

GL Cash Book Report Object Script
procedure TfmMain.dxBB_CBClick(Sender: TObject);
var lBizApp, lRptVar : Variant;
    lTime : TDateTime;
    cdsMain, cdsDtl, cdsTax : TClientDataset;
begin
  lTime := Now;
  cdsMain := TClientDataset.Create(nil);
  cdsDtl  := TClientDataset.Create(nil);
  cdsTax  := TClientDataset.Create(nil);
  lBizApp := CreateOleObject('SQLAcc.BizApp');
  try
    lRptVar := null;
    lRptVar := lBizApp.RptObjects.Find('GL.CB.RO');
    lRptVar.Params.Find('AllCurrency').AsBoolean          := True;
    lRptVar.Params.Find('AllDocProject').AsBoolean        := True;
    lRptVar.Params.Find('AllDocument').AsBoolean          := True;
    lRptVar.Params.Find('AllItemProject').AsBoolean       := True;
    lRptVar.Params.Find('AllItemArea').AsBoolean          := True;
    lRptVar.Params.Find('AllItemAgent').AsBoolean         := True;
    lRptVar.Params.Find('AllDocAgent').AsBoolean          := True;
    lRptVar.Params.Find('AllDocArea').AsBoolean           := True;
    lRptVar.Params.Find('AllPaymentMethod').AsBoolean     := False;
//    lRptVar.Params.Find('CurrencyData').AsBlob            := 'Not use if AllCurrency is true

//  For Post Date From & Date To'
    lRptVar.Params.Find('DateFrom').AsDate                := '01/01/2017';
    lRptVar.Params.Find('DateTo').AsDate                  := '31/12/2017';

//    lRptVar.Params.Find('DocProjectData').AsBlob          := //'Not use if AllDocProject is true
//    lRptVar.Params.Find('DocAreaData').AsBlob             := //Not use if AllDocArea is true
//    lRptVar.Params.Find('DocAgentData').AsBlob            := //Not use if AllDocAgent is true
//    lRptVar.Params.Find('ItemAgentData').AsBlob           := //Not use if AllItemAgent is true
    lRptVar.Params.Find('DocType').AsString               := 'PV'; //'PV for Payment Voucher & OR for Official Receipt
//    lRptVar.Params.Find('DocumentData').AsBlob            := //Not use if AllDocument is true
//    lRptVar.Params.Find('GroupBy').AsBlob                 := //If you wanted to grouping the data
    lRptVar.Params.Find('IncludeCancelled').AsBoolean     := False;
//    lRptVar.Params.Find('ItemAreaData').AsBlob            := //Not use if AllItemArea is true
//    lRptVar.Params.Find('ItemProjectData').AsBlob         := //Not use if AllItemProject is true
    lRptVar.Params.Find('PaymentMethodData').AsBlob       := '310-001';
    lRptVar.Params.Find('PrintDocumentStyle').AsBoolean   := True;
    lRptVar.Params.Find('SelectDate').AsBoolean           := True; //For Post Date
//  lRptVar.Params.Find('SelectDocDate').AsBoolean   := True; 'For Doc Date
    lRptVar.Params.Find('SortBy').AsString                := 'PostDate;DocNo';

    lRptVar.CalculateReport;

    cdsMain.XMLData := lRptVar.DataSets.Find('cdsMain').XMLData;      //Master Data
    cdsDtl.XMLData  := lRptVar.DataSets.Find('cdsDetail').XMLData; //Detail Data - To link Master Data use Dockey field
    cdsTax.XMLData  := lRptVar.DataSets.Find('cdsTax').XMLData; //Tax List

    cdsMain.SaveToFile('C:\Temp\_ListM.xml'); //Export To XML file
    cdsDtl.SaveToFile('C:\Temp\_ListD.xml');  //Export To XML file
    cdsTax.SaveToFile('C:\Temp\_ListT.xml');  //Export To XML file

    lTime := Now - lTime;
    MessageDlg(Format('[Elapsed Time: %s ]',[FormatDateTime ('hh:nn:ss:zzz', lTime)]),
               mtInformation, [mbOk], 0);
  finally
    lRptVar := null;
    cdsMain.Free;
    cdsDtl.Free;
  end;
end;

AR_DP

Customer Deposit Script
procedure TForm1.Button1Click(Sender: TObject);
var lMain, lBizObj, lBizApp : Variant;
begin
  lBizApp := CreateOleObject('SQLAcc.BizApp');
  lBizApp.Login('ADMIN', 'ADMIN', 'D:\Happy\DB\Default.DCF', 'ACC-0110.FDB');

  lBizObj := lBizApp.BizObjects.Find('AR_DP');
  lMain   := lBizObj.DataSets.Find('MainDataSet');

  try
    lBizObj.New;
    lMain.FindField('DOCKEY').Value         := -1;
    lMain.FindField('DocNo').AsString       := '--DP Test--';
    lMain.FindField('CODE').AsString        := '300-C0001';
    lMain.FindField('DocDate').Value        := '28 Oct 2019';
    lMain.FindField('PostDate').Value       := '28 Oct 2019';
    lMain.FindField('TAXDATE').Value        := '28 Oct 2019';
    lMain.FindField('DEPOSITACCOUNT').AsString := 'PREPAYMENT';
    lMain.FindField('PaymentMethod').AsString  := '320-000'; //Bank or Cash account
    lMain.FindField('Description').AsString    := 'Deposit For Account';
    lMain.FindField('ChequeNumber').AsString   := '';
    lMain.FindField('BankCharge').AsFloat      := 0;
    lMain.FindField('DocAmt').AsFloat          := 1000.00;
    lMain.FindField('Cancelled').AsString      := 'F';

    try
      lBizObj.Save;
    except
      on E: Exception do
        Memo1.Lines.Append(E.Message);
    end;
     lBizObj.Close;
     Memo1.Lines.Append('Done');
//     MessageDlg('Done', mtInformation, [mbOk], 0);
  finally
    lMain := Null;
    lBizObj := Null;
    lBizApp.Logout;
    lBizApp := Null;
  end;
end;

Customer Deposit to Customer Payment

Customer Deposit to Customer Payment Script
procedure TForm1.Button2Click(Sender: TObject);
var lMain, lKO, lBizApp, lBizObj, V : Variant;
    cdsTmp : TClientDataset;
    lSQL : String;
begin
  cdsTmp  := TClientDataset.Create(nil);
  lBizApp := CreateOleObject('SQLAcc.BizApp');
  lBizApp.Login('ADMIN', 'ADMIN', 'D:\Happy\DB\Default.DCF', 'ACC-0110.FDB');

  try
    lSQL := 'SELECT DOCKEY FROM AR_DP ' +
            'WHERE DOCNO=''--DP Test--'' ';
    cdsTmp.Data := lBizApp.DBManager.Execute(lSQL);

    if cdsTmp.RecordCount > 0 then begin
      lBizObj := lBizApp.BizObjects.Find('AR_PM');
      lMain   := lBizObj.DataSets.Find('MainDataSet');
      lKO     := lBizObj.DataSets.Find('cdsKnockOff');

      lBizObj.New;
      lMain.FindField('DOCKEY').Value           := -1;
      lMain.FindField('DocNo').AsString         := '--PM Test--'; //Payment Document Number
      lMain.FindField('CODE').AsString          := '300-C0001';
      lMain.FindField('DocDate').Value          := '29 Oct 2019';
      lMain.FindField('PostDate').Value         := '29 Oct 2019';
      lMain.FindField('Description').AsString   := 'Payment for A/c';
      lMain.FindField('PaymentMethod').AsString := 'PREPAYMENT';
      lMain.FindField('DocAmt').AsFloat         := 200;
      lMain.FindField('FROMDOCTYPE').AsString   := 'DP'; //Transfer from Deposit
      lMain.FindField('FROMDOCKEY').Value       := cdsTmp.FindField('Dockey').AsFloat; //Transfer from Deposit
      lMain.FindField('Cancelled').AsString     := 'F';
      lMain.FindField('CHANGED').AsString       := 'F';

      V := lBizApp.CreateOleVariantArray(2);
      V.SetItem(0, 'IV'); //Document Type is either is IV or DN for Sales & PI or SD for Purchase
      V.SetItem(1, 'IV-00003');  //Invoice Document Number

      if lKO.Locate('DocType;DocNo', V.AsOleVariant, False, False) then
        begin
          lKO.Edit;
          lKO.FindField('KOAmt').ASFloat     := 200;
          lKO.FindField('KnockOff').AsString := 'T';
          lKO.Post;
        end;

      try
        lBizObj.Save;
      except
        on E: Exception do
          Memo1.Lines.Append(E.Message);
      end;
        lBizObj.Close;
        Memo1.Lines.Append('Done');
      //MessageDlg('AR_PM-DocNo : ''--PM Test--'' Posted...', mtInformation, [mbOK],0);
    end else
       Memo1.Lines.Append('Deposit No. Not found');
  finally
    cdsTmp.Free;
    lBizApp.Logout;
    lMain := Null;
    lBizObj := Null;
    lBizApp := Null;
  end;
end;

AR_DPDTL_REFUND

Customer Deposit Refund Script
procedure TForm1.Button3Click(Sender: TObject);
var lMain, lBizApp, lBizObj : Variant;
    cdsTmp : TClientDataset;
    lSQL : String;
begin
  cdsTmp  := TClientDataset.Create(nil);
  lBizApp := CreateOleObject('SQLAcc.BizApp');
  lBizApp.Login('ADMIN', 'ADMIN', 'D:\Happy\DB\Default.DCF', 'ACC-0110.FDB');

  try
    lSQL := 'SELECT DOCKEY FROM AR_DP ' +
            'WHERE DOCNO=''--DP Test--'' ';
    cdsTmp.Data := lBizApp.DBManager.Execute(lSQL);

    if cdsTmp.RecordCount > 0 then begin
      lBizObj := lBizApp.BizObjects.Find('AR_DPDTL_REFUND');
      lMain   := lBizObj.DataSets.Find('MainDataSet');

      lBizObj.New;
      lMain.FindField('DOCKEY').Value          := cdsTmp.FindField('Dockey').AsFloat;
      lMain.FindField('Account').AsString      := '320-000'; //Bank or Cash account
      lMain.FindField('DocDate').Value         := '28 Oct 2019';
      lMain.FindField('PostDate').Value        := '28 Oct 2019';
      lMain.FindField('Description').AsString  := 'Deposit Refund';
      lMain.FindField('ChequeNumber').AsString := '';
      lMain.FindField('BankCharge').AsFloat    := 0;
      lMain.FindField('PAYMENTAMOUNT').AsFloat := 500.00;

      try
        lBizObj.Save;
      except
        on E: Exception do
          Memo1.Lines.Append(E.Message);
      end;
       lBizObj.Close;
       Memo1.Lines.Append('Done');
  //     MessageDlg('Done', mtInformation, [mbOk], 0);
    end else
      Memo1.Lines.Append('Deposit No. Not Found');
  finally
    cdsTmp.Free;
    lMain := Null;
    lBizObj := Null;
    lBizApp.Logout;
    lBizApp := Null;
  end;
end;

AR_DPDTL_FORFEIT

Customer Deposit Forfeit Script
procedure TForm1.Button4Click(Sender: TObject);
var lMain, lBizApp, lBizObj : Variant;
    cdsTmp : TClientDataset;
    lSQL : String;
begin
  cdsTmp  := TClientDataset.Create(nil);
  lBizApp := CreateOleObject('SQLAcc.BizApp');
  lBizApp.Login('ADMIN', 'ADMIN', 'D:\Happy\DB\Default.DCF', 'ACC-0110.FDB');

  try
    lSQL := 'SELECT DOCKEY FROM AR_DP ' +
            'WHERE DOCNO=''--DP Test--'' ';
    cdsTmp.Data := lBizApp.DBManager.Execute(lSQL);

    if cdsTmp.RecordCount > 0 then begin
      lBizObj := lBizApp.BizObjects.Find('AR_DPDTL_FORFEIT');
      lMain   := lBizObj.DataSets.Find('MainDataSet');

      lBizObj.New;
      lMain.FindField('DOCKEY').Value          := cdsTmp.FindField('Dockey').AsFloat;
      lMain.FindField('Account').AsString      := '532-000'; //Forfeit account
      lMain.FindField('DocDate').Value         := '28 Oct 2019';
      lMain.FindField('PostDate').Value        := '28 Oct 2019';
      lMain.FindField('Description').AsString  := 'Deposit Forfeit';
      lMain.FindField('Amount').AsFloat        := 150.00;

      try
        lBizObj.Save;
      except
        on E: Exception do
          Memo1.Lines.Append(E.Message);
      end;
       lBizObj.Close;
       Memo1.Lines.Append('Done');
  //     MessageDlg('Done', mtInformation, [mbOk], 0);
    end else
      Memo1.Lines.Append('Deposit No. Not Found');
  finally
    cdsTmp.Free;
    lMain := Null;
    lBizObj := Null;
    lBizApp.Logout;
    lBizApp := Null;
  end;
end;

FAQ

Problem with opening CHM Help files?

  1. Right click the chm file & select Properties
  2. At General tab Click Unblock button.
  3. Click Apply | Ok.

Still can't open CHM file?

  1. Login SQL Accounting
  2. Click Tools | Options
  3. Click Register & follow wizard
  4. Exit SQL Accounting
  5. Login SQL Accounting
  6. Run CHM File

Why when I compile my program with stated unknown method or unknown identifier?

If you compiler had error may try add the esfw10.dll file under the SQL Accounting\bin folder

How to make sure I login to correct database?

  • Can use the Common.Agent.RO Report Objects to get the Profile info.
  • Then use the cdsProfile Dataset
- CompanyName Field
- Remark Field

Why after post to SQL Accounting the Description3 (More Description)/Notes field it show like this "M y D e s c r i p t i o n" instead of "My Description"?

Make sure you use .AsString in your code (see example below)
Description3 Field Script/Code

...

 lDtl.FindField('DESCRIPTION3').AsString  := 'Sales Item A More Description'+ #13 + 'I in 2nd line';

...

Can I Ignore Doc No Field & let SQL Accounting to Auto Assign?

Yes but we not recommended as you will lost track when user wanted to know which Doc No in SQL Acc is posted.
To Set Auto Assign set it as below
DocNo Field Script/Code

...

 lMain.FindField('DocNo').AsString  := '<<New>>';

...

lDocNo := lMain.FindField('DocNo').AsString; //To Get docno after post 

Can I Auto Login & Logout SQL Accounting when doing & after Posting?

Yes can below is example script
Only work if that PC is no once is using SQL Accounting
C Sharp
Int32 lBuildNo;
dynamic ComServer;
		
public void CheckLogin()
{            
    lBizType = Type.GetTypeFromProgID("SQLAcc.BizApp");
    ComServer = Activator.CreateInstance(lBizType);
            
    if (!ComServer.IsLogin)
    {
        try
        {
            ComServer.Login(edUN.Text, edPW.Text, edDCF.Text, edDB.Text);
            ComServer.Minimize();
        }
        catch(Exception ex)
        {
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            FreeBiz(ComServer);
        }
    }
    if (ComServer.IsLogin)
    {
        lBuildNo = ComServer.BuildNo;
    }
}
		
public void FreeBiz(object AbizObj)
{
    System.Runtime.InteropServices.Marshal.ReleaseComObject(AbizObj);
}
		
private void btnExport_Click(object sender, EventArgs e)
{
    dynamic BizObject, lMain, lDocKey;

    CheckLogin();
    //'Step 2: Find and Create the Biz Objects
    BizObject = ComServer.BizObjects.Find("Agent");

    //Step 3: Set Dataset
    lMain = BizObject.DataSets.Find("MainDataSet");    //lMain contains master data

    //Step 4: Search
    lDocKey = BizObject.FindKeyByRef("CODE", edCode.Text);
    try
    {
        try
        {
            //Step 5 : Insert or Update
            if (Convert.IsDBNull(lDocKey))
            {
                BizObject.New();
                lMain.FindField("CODE").value = edCode.Text;
                lMain.FindField("DESCRIPTION").value = edDesc.Text;
            }
            else
            {//Edit Data if found
                BizObject.Params.Find("CODE").Value = lDocKey;
                BizObject.Open();
                BizObject.Edit();
                lMain.FindField("DESCRIPTION").value = edDesc.Text;
            }
            //Step 6: Save & Close
            BizObject.Save();
            MessageBox.Show("Done", "Status", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
    }
    finally
    {
        BizObject.Close();

        //Step 7 : Logout after done             
        FreeBiz(BizObject);
        ComServer.Logout();
        FreeBiz(ComServer);
    }            
}
Delphi
....
  public
    { Public declarations }
    lBizApp : variant;
  end;
....

procedure TForm1.CheckLogin;
begin
  lBizApp := null;
  lBizApp := CreateOleObject('SQLAcc.BizApp');

  if not lBizApp.IsLogin then begin
    lBizApp.Login(edUN.Text, edPW.Text, edDCF.Text, edDB.Text); //Login with preset setting
    lBizApp.Minimize; //Mininise the SQLAccounting
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var BizObject, lMain : Variant;
begin
  try
    //Begin Loop your data
    try
      CheckLogin;
      BizObject := lBizApp.BizObjects.Find('Agent');
      lMain     := BizObject.DataSets.Find('MainDataSet');
      BizObject.New;
      lMain.FindField('CODE').AsString := 'HALIM';
      lMain.FindField('Description').AsString := 'HALIM 123';	
      BizObject.save;
    except
      on E: Exception do
        MmLog.Lines.Append(E.Message);
    end;
    //
  finally
    BizObject.close;
    BizObject := null;
    lBizApp.Logout;
    lBizApp := null;
  end;
end;
VB Script
'Copy below script & paste to notepad & name it as eg Agent.vbs
Call PostData
 
Function CreateSQLAccServer
  Set CreateSQLAccServer = CreateObject("SQLAcc.BizApp")
End Function
 
Function PostData
Dim ComServer, BizObject
 
  'Step 1: Create Com Server object
  Set ComServer = CreateSQLAccServer 'Create Com Server
  
  Set WScr = CreateObject("WScript.Shell")
  WScript.Sleep 1000 '//Wait 1 second for system loading before proceed

  'Step 2: Force Logout to make sure login correct database
  If ComServer.IsLogin Then 'if user hasn't logon to SQL application
    ComServer.Logout
  END IF
  'Step 3: Login 
  ComServer.Login "ADMIN", "ADMIN", "C:\estream\SQLAccounting\Share\Default.DCF", "ACC-0015.FDB" 

  'Step 4: Find and Create the Biz Objects
  Set BizObject = ComServer.BizObjects.Find("Agent") 
 
  'Step 5: Set Dataset
  Set lMain = BizObject.DataSets.Find("MainDataSet")    'lMainDataSet contains master data

  
  'Step 6 : Posting
    BizObject.New
    lMain.FindField("CODE").AsString          = "_Test_"
    lMain.FindField("Description").AsString   = "Testing 123"

  'Step 7: Save Document
    BizObject.Save
    BizObject.Close
	
  'Step 8: Logout	
    ComServer.Logout
	MsgBox "Done"
End Function

When Post System Prompt Operation aborted Error

This happen when the Login User ID don't had the to Override Sales Min/Max Price &
Use Last Price XXX (In Tools | Options | Unit Price) &
1 of record is below Min Price.

Solution

Can try change the Posting Seq like below (UOM then Qty)
Sequence Field Script/Code

...

   lDetail.Append();
   lDetail.FindField("DtlKey").value = -1;
   lDetail.FindField("DocKey").value = -1;
   lDetail.FindField("Seq").value = 3;
   lDetail.FindField("ItemCode").AsString = "ANT";
   lDetail.FindField("Description").AsString = "Sales Item B";
   //lDetail.FindField("Account").AsString = "500-000"; To override the Sales Account Code
   lDetail.FindField("UOM").AsString = "UNIT";
   lDetail.FindField("Qty").AsFloat = 2;
   //lDetail.FindField("DISC").AsString = "5%+3"; //Optional(eg 5% plus 3 Discount)
   lDetail.FindField("Tax").AsString = "SR";
   lDetail.FindField("TaxRate").AsString = "6%";
   lDetail.FindField("TaxInclusive").value = 0;
   lDetail.FindField("UnitPrice").AsFloat = 100;
   lDetail.FindField("Amount").AsFloat = 200;
   lDetail.FindField("TaxAmt").AsFloat = 12;
   lDetail.Post();

...

How do my system know there is a changes or update in SQLAccounting?

Data Entry

In all Document it had a field call UPDATECOUNT.
Default is null & each changes will +1.
So if you see 2 meaning it had being update 2 times

Master Data

Only available in
  • Version 842.765 & above
  • AP_SUPPLIER (Maintain Supplier)
  • AR_CUSTOMER (Maintain Customer)
  • ST_GROUP (Maintain Stock Group)
  • ST_ITEM (Maintain Stock Item)
  • ST_ITEM_TPL (Maintain Item Template)
  • ST_PRICETAG (Maintain Price Tag)
  • TAX (Maintain Tax)
In Each table it had a field call LASTMODIFIED.
The value is Epoch Time or Unix Time

You can use below function to get the field

vbs
...
Function GetData
Dim lDataSet, lSQL
  lSQL = "SELECT DOCNO, UPDATECOUNT FROM SL_CS "
  lSQL = lSQL & "WHERE UPDATECOUNT IS NOT NULL " 
  lSQL = lSQL & "ORDER BY DOCNO "
  Set lDataSet = ComServer.DBManager.NewDataSet(lSQL)
  
  lDataSet.First
  While (not lDataSet.eof)
    MsgBox "DocNo : " & lDataSet.FindField("DocNo").AsString
    MsgBox "UpdateCount : " & lDataSet.FindField("UPDATECOUNT").AsString
    lDataSet.Next
  Wend
End Function
...
Delphi
...   
procedure TfmMain.dxbb_GetFieldClick(Sender: TObject);
var BizApp : Variant;
    lDataSet : TClientDataSet;
    ASQL : String;
begin
  BizApp := CreateOleObject('SQLAcc.BizApp');
  lDataSet := TClientDataSet.Create(Self);
  try
     ASQL := 'SELECT DOCNO, UPDATECOUNT FROM SL_CS ' +
             'WHERE UPDATECOUNT IS NOT NULL ' +
             'ORDER BY DOCNO ';
     lDataSet.Data := BizApp.DBManager.Execute(ASQL);
     lDataset.SaveToFile('C:\Temp\_List.xml', dfXML); //Export To XML file
  finally
    lDataSet.Free;
  end;
end;
...

Can I control my Stock when I link with other Application?

Yes. We suggest to use Stock Transfer to (eg Location call MOBILE) transfer stock as Reserve to avoid stock over deduct in SQL Accounting
When other Application post to SQL Accounting they just need set the Location to the Reserve Location (eg MOBILE)
Below is example posting with location
Post Location Field Script/Code

...

 lDtl.FindField('UOM').AsString       := 'CTN';
 lDtl.FindField('QTY').AsFloat        := 6;
 lDtl.FindField('Location').AsString  := 'MOBILE';

...

Where to Check the SQL Accounting DCF Path, FileName & FDB FileName?

In Login Screen Click 3 Dot Button then you can see the information
For SQL Accounting Version 5.2023.957.831 and below
SDK-FAQ-01.jpg
For SQL Accounting Version 5.2023.958.832 and above
SDK-FAQ-03.jpg
SDK-FAQ-02.jpg

How to check & What is the value for Advance Credit Control in Maintain Customer

You can use ComServer.DBManager.NewDataSet(lSQL) function to Query the information
lSQL = SELECT * FROM AR_CUSTOMERCRCTRL
You may refer to ControlType column
ControlType Exceed Credit Limit Exceed OverDue Limit
0 UnBlock UnBlock
1 UnBlock Block
2 UnBlock Override
3 Block UnBlock
4 Block Block
5 Block Override
6 Override UnBlock
7 Override Block
8 Override Override
9 Suspended

How to get Error/Exception Message Return from SQL Accounting?

C Sharp
try
{
   BizObject.New();
....
   BizObject.Save();
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
Python
   try:
       BizObject.Save()          
   except Exception as e:
       print("Oops!", e)   
VB.Net
Try
  BizObject.[New]
...
  BizObject.Save
Catch ex As Exception
  MsgBox(ex.Message, MsgBoxStyle.Exclamation)
End Try
Delphi
try
  lBizObj.New;
....
  lBizObj.Save;
except
  on E: Exception do
    Memo1.Lines.Text := E.Message;
end;


Why Post to SQL Accounting sometime prompt Catastrophic failure Error?

Possible Problem 1

Make sure you code don't cross over Call action during posting
Eg Posing SL_SO Header partly then suddenly call other object example Check Customer Code Validity
Summary action (Correct Steps)
01. Do Verify 1st (eg Check Customer Code Validity & etc)
02. Post Transactions

Possible Problem 2

Keep Login & Logout till windows not enough time to response
Summary action (Correct Steps)
01. Pull Data from Your application/web
02. Login SQL Accounting 1 time (Auto Login)
03. Do all your requirement actions (eg. verify, query & posting)
    eg Posting Cash Sales & Customer Payment
begin looping
  BizObject = ComServer.BizObjects.Find("SL_CS")
  ....
  BizObject.Save
  BizObject.Close
  FreeBiz(BizObject)
  
  BizObject = ComServer.BizObjects.Find("AR_PM")
  ....
  BizObject.Save
  BizObject.Close
  FreeBiz(BizObject)
  
  Next Record
End looping
04. Logout SQL Accounting 1 time (Auto Logout)
05. Push Data to Your application/web (if any)

Possible Problem 3

Company Profile Logo format had problem.
Solution
01. Click File | Company Profile
02. Export out the Logo by right Click the Company Logo
03. Open the Exported Logo with Photo Editor
04. Just Click File | Save again as jpg.
05. Load Back the Save Logo by right Click the Company Logo
06. Click Save

How to Get the GL Account List for Sales & Purchase?

You can use the function ComServer.DBManager.NewDataSet(lSQL) with the following SQL
SELECT  Code, Description, Description2 FROM GL_ACC A
WHERE (A.Parent<>-1
AND NOT (EXISTS (SELECT Parent FROM GL_ACC B
                 WHERE A.DocKey=B.Parent))
AND (A.SpecialAccType IS NULL OR A.SpecialAccType IN ('', 'AD')))
ORDER BY Code

Can I setup a testing/Staging environment for SQL Accounting?

Yes can, you can self setup or we can help you to setup.
There are 4 types of Testing/Staging
01. Install the Testing SQL Accounting version & Testing Database in the developer PC
02. Install the Live SQL Accounting version & User Backup Database in the developer PC
- Require User Permission for Backup
03. Setup at User PC/Server & using User Backup Database
- Require User Permission for Backup & PC/Server setup
04. Setup at User PC/Server & using Testing Database
- Require User Permission for PC/Server setup

How to Loop & post SQL Accounting?

Below summary how to loop
01. Call ComServer
02. Check Login
03. Call BizObject (eg SL_CS)
04. Begin Loop you data
05. Call Close BizObject (eg BizObject.Close)
06. Continue Call other BizObject (eg AR_PM)
07. Repeat Steps 4 & 5
08. Call Logout
09. Free ComServer

How to post Description3 with Unicode?

You have to convert it to rtf format before set to Description3 field
C Sharp
private static string FormatAsRTF(string DirtyText)
{
    System.Windows.Forms.RichTextBox rtf = new System.Windows.Forms.RichTextBox();
    rtf.Text = DirtyText;
    return rtf.Rtf;
}

....
 lDtl.FindField("DESCRIPTION3").AsString  = FormatAsRTF("ANTENNA ???");
...
VB.Net
Private Shared Function FormatAsRTF(ByVal DirtyText As String) As String
    Dim rtf As System.Windows.Forms.RichTextBox = New System.Windows.Forms.RichTextBox()
    rtf.Text = DirtyText
    Return rtf.Rtf
End Function

....
 lDtl.FindField("DESCRIPTION3").AsString  = FormatAsRTF("ANTENNA ???")
...
Delphi
function TfmMain.PlainTxtToRTF(const AValue:String):String;
var R:TRichEdit;
    M : TStringStream;
begin
  R := TRichEdit.CreateParented(HWND_MESSAGE);
  M := TStringStream.Create('');
  try
    R.WordWrap := False;
    R.Lines.Add(AValue);
    R.Lines.SaveToStream(M);
    Result := M.DataString;
  finally
    R.Free;
    M.Free;
  end;
end;

....
 lDtl.FindField('DESCRIPTION3').AsString  := PlainTxtToRTF('ANTENNA ???');
...
or Can use our build in Utility function (only available from 5.2022.941.822 & above)
....
 lDtl.FindField("Description3").AsString = ComServer.Utility.PlainTextToRichText("ANTENNA ??? ??")
...
PHP
<!DOCTYPE html>
<html>
<body>

<h1>SQL Acc SDK in PHP page</h1>

<?php
echo "Updated 14 Sep 2022<br>";
#This action to show & post Description3 with unicode

$ComServer = null;

function CheckLogin()
{
    global $ComServer;
    $ComServer = new COM("SQLAcc.BizApp", null, CP_UTF8) or die("Could not initialise SQLAcc.BizApp object.");
    $status = $ComServer->IsLogin();

    if ($status == true)
    {
        #$ComServer->Logout();
    }
    $ComServer->Login("ADMIN", "ADMIN", #UserName, Password
                      "C:\eStream\SQLAccounting\Share\Default.DCF",  #DCF file
                      "ACC-0082.FDB"); #Database Name
    
}

function GetData(){
    global $ComServer;
	
    $lSQL = "SELECT Description3 FROM ST_ITEM 
	     WHERE Code='ANT' ";
	
    $lDataSet = $ComServer->DBManager->NewDataSet($lSQL);

    if ($lDataSet->RecordCount > 0) {
	$lDataSet->First();
		
	$rtf = $lDataSet->FindField('Description3')->AsString();
		
        echo $rtf;		
	echo "<br>== <br>";
	echo "<br>Result after RTF: <br>";
	$txt = $ComServer->Utility->RichTextToPlainText($rtf);
	echo "<TEXTAREA rows=10 cols=80 id='edResult1' >".$txt. "</TEXTAREA>";
	echo "<br>== <br>";
	echo "??? ??";
	}else {
    echo "Record Not Found";
    }
}

function PostData(){
	global $ComServer;
	
	$BizObject = $ComServer->BizObjects->Find("ST_AJ");
    $lMain = $BizObject->DataSets->Find("MainDataSet"); 
    $lDetail = $BizObject->DataSets->Find("cdsDocDetail"); 
	
    $BizObject->New();
    $lMain->FindField("DocKey")->value = -1;
    $lMain->FindField("DocNo")->AsString = "<<New>>";
    $lMain->FindField("DocDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("PostDate")->value = "04/20/2020"; #MM/DD/YYYY
    $lMain->FindField("Description")->AsString = "Stock Adjustment";
	
    #Insert Data - Detail - Increase Stock Qty
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 1;
    $lDetail->FindField("ItemCode")->AsString = "ANT";
    $lDetail->FindField("Description")->AsString = "Sales Item B";
    $lDetail->FindField("Qty")->AsFloat = 2;
    $lDetail->FindField("UOM")->AsString = "UNIT";
    $lDetail->Post();
    #Insert Data - Detail - Reduce Stock Qty
    $lDetail->Append();
    $lDetail->FindField("DtlKey")->value = -1;
    $lDetail->FindField("DocKey")->value = -1;
    $lDetail->FindField("Seq")->value = 2;
    $lDetail->FindField("ItemCode")->AsString = "ANT";
    $lDetail->FindField("Description")->AsString = "NOKIA CHARGER  ???";
	$lDetail->FindField("Description3")->AsString = $ComServer->Utility->PlainTextToRichText("NOKIA CHARGER ??? ??");
    $lDetail->FindField("Qty")->AsFloat = -5;
    $lDetail->FindField("UOM")->AsString = "UNIT";
    $lDetail->Post();
	
    $BizObject->Save();
    $BizObject->Close();
	
	try{
        $BizObject->Save();
        $BizObject->Close();
	}catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
    }	
}

if (isset($_POST['BtnData']))
{
    try
    {
        CheckLogin();
        GetData();
	echo "<br>";
        echo date("d M Y h:i:s A")." - Done";
	PostData();
	echo "<br>";
        echo date("d M Y h:i:s A")." - Done ST_AJ";			
    }
    finally
    {
        $ComServer->Logout();
        #free the object
        $ComServer = null;
    }
}

?> 
    <form method="post">           
        <input type="submit" name="BtnData"
                value="Get RTF n Post RTF"/> 
    </form> 
</body>
</html>

See also

  • Need assistance? May email to support@sql.com.my