Page 1 of 1

SCRIPT TEMPLATE: Parse Customer Transactions

Posted: Fri Sep 29, 2017 10:20 am
by COBS Tech Support
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]