SCRIPT TEMPLATE: Parse Customer Transactions
  • COBS Tech Support
    Posts: 651
    Joined: Fri Sep 09, 2005 8:23 am

    SCRIPT TEMPLATE: Parse Customer Transactions

    by COBS Tech Support » Fri Sep 29, 2017 10:20 am

    This script can be used as the basis for parsing the customer transaction file and saving the resulting data as a .CSV file.

    Code: Select all

    * Sample framework script to parse the customer transaction /
    * invoice file and export data as a CSV file.

    Declare dDateFrom Type Date
    Declare dDateTo   Type Date
    Declare aTran     Type Array
    aTran := {}

    FormCreate()
    FormAdd("Invoices From", Today())
    FormAdd("Invoices To", Today())

    If .Not. FormShow("Create a CSV File For Date Range")
       Return
    Endif

    dDateFrom := FormResult(1)
    dDateTo   := FormResult(2)

    OpenTable("INVOICE")
    INVOICE->(Find(DTOS(dDateFrom), "DATE", TRUE))

    :Loop
       If INVOICE->(EOF()) .OR. INVOICE->Date > dDateTo
          Goto WriteFile
       Endif

       * Export Tran No., date and transaction total
       AADD(aTran, { INVOICE->INVOICENO, INVOICE->DATE, INVOICE->INVTOT } )   

       INVOICE->(Skip())
       Goto Loop


    :WriteFile
    If Len(aTran) = 0
       Echo("Sorry, no transactions were found.")
    Else
       If ExportASCII(aTran, PathProgram() + "NSWHealth.csv", "DEL")
          Echo("File created: " + PathProgram() + "NSWHealth.csv")
       Else
          Echo("Error creating: " + PathProgram() + "NSWHealth.csv " + NTRIM(FError()))
       Endif
    Endif

    CloseTable("INVOICE")
    [/code]

Who is online

Users browsing this forum: No registered users and 0 guests